blob: ea5dca015c69f777754784684cfa9bd67c411f7a [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.pce.pcestore;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053020import com.google.common.collect.ImmutableSet;
21
Avantika-Huawei28b53752016-06-23 17:04:49 +053022import java.util.HashMap;
23import java.util.HashSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053024import java.util.List;
25import java.util.Map;
26import java.util.stream.Collectors;
27
28import org.apache.felix.scr.annotations.Activate;
29import org.apache.felix.scr.annotations.Component;
30import org.apache.felix.scr.annotations.Deactivate;
31import org.apache.felix.scr.annotations.Reference;
32import org.apache.felix.scr.annotations.ReferenceCardinality;
33import org.apache.felix.scr.annotations.Service;
34
35import org.onlab.util.KryoNamespace;
36import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053037import org.onosproject.incubator.net.resource.label.LabelResource;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053038import org.onosproject.incubator.net.resource.label.LabelResourceId;
Mahesh Poojary S33536202016-05-30 07:22:36 +053039import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053040import org.onosproject.net.DeviceId;
41import org.onosproject.net.Link;
42import org.onosproject.net.resource.ResourceConsumer;
Priyanka Bcdf9b102016-06-07 20:01:38 +053043import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053044import org.onosproject.pce.pceservice.constraint.CostConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053045import org.onosproject.pce.pceservice.TunnelConsumerId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053046import org.onosproject.pce.pceservice.LspType;
Priyanka B4c3b4512016-07-22 11:41:49 +053047import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053048import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
49import org.onosproject.pce.pcestore.api.PceStore;
50import org.onosproject.store.serializers.KryoNamespaces;
51import org.onosproject.store.service.ConsistentMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053052import org.onosproject.store.service.DistributedSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053053import org.onosproject.store.service.Serializer;
54import org.onosproject.store.service.StorageService;
55
56import org.slf4j.Logger;
57import org.slf4j.LoggerFactory;
58
59/**
60 * Manages the pool of available labels to devices, links and tunnels.
61 */
62@Component(immediate = true)
63@Service
64public class DistributedPceStore implements PceStore {
65
66 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053067 private static final String DEVICE_LABEL_STORE_INFO_NULL = "Device Label Store cannot be null";
68 private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null";
69 private static final String LABEL_RESOURCE_LIST_NULL = "Label Resource List cannot be null";
70 private static final String LABEL_RESOURCE_NULL = "Label Resource cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053071 private static final String LINK_NULL = "LINK cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053072 private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label Info cannot be null";
73 private static final String PATH_INFO_NULL = "Path Info cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053074 private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053075 private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053076 private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null";
77
78 private final Logger log = LoggerFactory.getLogger(getClass());
79
80 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
81 protected StorageService storageService;
82
83 // Mapping device with global node label
84 private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap;
85
86 // Mapping link with adjacency label
87 private ConsistentMap<Link, LabelResourceId> adjLabelMap;
88
89 // Mapping tunnel with device local info with tunnel consumer id
90 private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap;
91
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053092 // List of Failed path info
93 private DistributedSet<PcePathInfo> failedPathSet;
94
Avantika-Huawei28b53752016-06-23 17:04:49 +053095 // Locally maintain LSRID to device id mapping for better performance.
96 private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
97
98 // List of PCC LSR ids whose BGP device information was not available to perform
99 // label db sync.
100 private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet();
101
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530102 @Activate
103 protected void activate() {
104 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
105 .withName("onos-pce-globalnodelabelmap")
106 .withSerializer(Serializer.using(
107 new KryoNamespace.Builder()
108 .register(KryoNamespaces.API)
109 .register(LabelResourceId.class)
110 .build()))
111 .build();
112
113 adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder()
114 .withName("onos-pce-adjlabelmap")
115 .withSerializer(Serializer.using(
116 new KryoNamespace.Builder()
117 .register(KryoNamespaces.API)
118 .register(Link.class,
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530119 LabelResource.class,
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530120 LabelResourceId.class)
121 .build()))
122 .build();
123
124 tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder()
125 .withName("onos-pce-tunnelinfomap")
126 .withSerializer(Serializer.using(
127 new KryoNamespace.Builder()
128 .register(KryoNamespaces.API)
129 .register(TunnelId.class,
130 PceccTunnelInfo.class,
131 DefaultLspLocalLabelInfo.class,
132 TunnelConsumerId.class,
133 LabelResourceId.class)
134 .build()))
135 .build();
136
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530137 failedPathSet = storageService.<PcePathInfo>setBuilder()
138 .withName("failed-path-info")
139 .withSerializer(Serializer.using(
140 new KryoNamespace.Builder()
141 .register(KryoNamespaces.API)
142 .register(PcePathInfo.class,
Mahesh Poojary S33536202016-05-30 07:22:36 +0530143 CostConstraint.class,
144 CostConstraint.Type.class,
145 BandwidthConstraint.class,
Priyanka B4c3b4512016-07-22 11:41:49 +0530146 SharedBandwidthConstraint.class,
Priyanka Bcdf9b102016-06-07 20:01:38 +0530147 CapabilityConstraint.class,
148 CapabilityConstraint.CapabilityType.class,
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530149 LspType.class)
150 .build()))
151
152 .build()
153 .asDistributedSet();
154
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530155 log.info("Started");
156 }
157
158 @Deactivate
159 protected void deactivate() {
160 log.info("Stopped");
161 }
162
163 @Override
164 public boolean existsGlobalNodeLabel(DeviceId id) {
165 checkNotNull(id, DEVICE_ID_NULL);
166 return globalNodeLabelMap.containsKey(id);
167 }
168
169 @Override
170 public boolean existsAdjLabel(Link link) {
171 checkNotNull(link, LINK_NULL);
172 return adjLabelMap.containsKey(link);
173 }
174
175 @Override
176 public boolean existsTunnelInfo(TunnelId tunnelId) {
177 checkNotNull(tunnelId, TUNNEL_ID_NULL);
178 return tunnelInfoMap.containsKey(tunnelId);
179 }
180
181 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530182 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
183 checkNotNull(failedPathInfo, PATH_INFO_NULL);
184 return failedPathSet.contains(failedPathInfo);
185 }
186
187 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530188 public int getGlobalNodeLabelCount() {
189 return globalNodeLabelMap.size();
190 }
191
192 @Override
193 public int getAdjLabelCount() {
194 return adjLabelMap.size();
195 }
196
197 @Override
198 public int getTunnelInfoCount() {
199 return tunnelInfoMap.size();
200 }
201
202 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530203 public int getFailedPathInfoCount() {
204 return failedPathSet.size();
205 }
206
207 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530208 public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
209 return globalNodeLabelMap.entrySet().stream()
210 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
211 }
212
213 @Override
214 public Map<Link, LabelResourceId> getAdjLabels() {
215 return adjLabelMap.entrySet().stream()
216 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
217 }
218
219 @Override
220 public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
221 return tunnelInfoMap.entrySet().stream()
222 .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value()));
223 }
224
225 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530226 public Iterable<PcePathInfo> getFailedPathInfos() {
227 return ImmutableSet.copyOf(failedPathSet);
228 }
229
230 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530231 public LabelResourceId getGlobalNodeLabel(DeviceId id) {
232 checkNotNull(id, DEVICE_ID_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530233 return globalNodeLabelMap.get(id) == null ? null : globalNodeLabelMap.get(id).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530234 }
235
236 @Override
237 public LabelResourceId getAdjLabel(Link link) {
238 checkNotNull(link, LINK_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530239 return adjLabelMap.get(link) == null ? null : adjLabelMap.get(link).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530240 }
241
242 @Override
243 public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
244 checkNotNull(tunnelId, TUNNEL_ID_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530245 return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530246 }
247
248 @Override
249 public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
250 checkNotNull(deviceId, DEVICE_ID_NULL);
251 checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
252
253 globalNodeLabelMap.put(deviceId, labelId);
254 }
255
256 @Override
257 public void addAdjLabel(Link link, LabelResourceId labelId) {
258 checkNotNull(link, LINK_NULL);
259 checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
260
261 adjLabelMap.put(link, labelId);
262 }
263
264 @Override
265 public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
266 checkNotNull(tunnelId, TUNNEL_ID_NULL);
267 checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL);
268
269 tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
270 }
271
272 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530273 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
274 checkNotNull(failedPathInfo, PATH_INFO_NULL);
275 failedPathSet.add(failedPathInfo);
276 }
277
278 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530279 public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
280 checkNotNull(tunnelId, TUNNEL_ID_NULL);
281 checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
282
283 if (!tunnelInfoMap.containsKey((tunnelId))) {
284 log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
285 return false;
286 }
287
288 PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
289 tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
290 tunnelInfoMap.put(tunnelId, tunnelInfo);
291
292 return true;
293 }
294
295 @Override
296 public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
297 checkNotNull(tunnelId, TUNNEL_ID_NULL);
298 checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL);
299
300 if (!tunnelInfoMap.containsKey((tunnelId))) {
301 log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
302 return false;
303 }
304
305 PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
306 tunnelInfo.tunnelConsumerId(tunnelConsumerId);
307 tunnelInfoMap.put(tunnelId, tunnelInfo);
308
309 return true;
310 }
311
312 @Override
313 public boolean removeGlobalNodeLabel(DeviceId id) {
314 checkNotNull(id, DEVICE_ID_NULL);
315
316 if (globalNodeLabelMap.remove(id) == null) {
317 log.error("SR-TE node label deletion for device {} has failed.", id.toString());
318 return false;
319 }
320 return true;
321 }
322
323 @Override
324 public boolean removeAdjLabel(Link link) {
325 checkNotNull(link, LINK_NULL);
326
327 if (adjLabelMap.remove(link) == null) {
328 log.error("Adjacency label deletion for link {} hash failed.", link.toString());
329 return false;
330 }
331 return true;
332 }
333
334 @Override
335 public boolean removeTunnelInfo(TunnelId tunnelId) {
336 checkNotNull(tunnelId, TUNNEL_ID_NULL);
337
338 if (tunnelInfoMap.remove(tunnelId) == null) {
339 log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
340 return false;
341 }
342 return true;
343 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530344
345 @Override
346 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
347 checkNotNull(failedPathInfo, PATH_INFO_NULL);
348
349 if (!failedPathSet.remove(failedPathInfo)) {
350 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
351 return false;
352 }
353 return true;
354 }
Avantika-Huawei28b53752016-06-23 17:04:49 +0530355
356 @Override
357 public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
358 checkNotNull(lsrId);
359 checkNotNull(deviceId);
360
361 lsrIdDeviceIdMap.put(lsrId, deviceId);
362 return true;
363 }
364
365 @Override
366 public boolean removeLsrIdDevice(String lsrId) {
367 checkNotNull(lsrId);
368
369 lsrIdDeviceIdMap.remove(lsrId);
370 return true;
371 }
372
373 @Override
374 public DeviceId getLsrIdDevice(String lsrId) {
375 checkNotNull(lsrId);
376
377 return lsrIdDeviceIdMap.get(lsrId);
378
379 }
380
381 @Override
382 public boolean addPccLsr(DeviceId lsrId) {
383 checkNotNull(lsrId);
384 pendinglabelDbSyncPccMap.add(lsrId);
385 return true;
386 }
387
388 @Override
389 public boolean removePccLsr(DeviceId lsrId) {
390 checkNotNull(lsrId);
391 pendinglabelDbSyncPccMap.remove(lsrId);
392 return true;
393 }
394
395 @Override
396 public boolean hasPccLsr(DeviceId lsrId) {
397 checkNotNull(lsrId);
398 return pendinglabelDbSyncPccMap.contains(lsrId);
399
400 }
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530401}