blob: 47f1c46c0565ee2f812127885ae833e051d9a66e [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();
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530101 private static final Serializer SERIALIZER = Serializer
102 .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
103 .register(PcePathInfo.class)
104 .register(CostConstraint.class)
105 .register(CostConstraint.Type.class)
106 .register(BandwidthConstraint.class)
107 .register(SharedBandwidthConstraint.class)
108 .register(CapabilityConstraint.class)
109 .register(CapabilityConstraint.CapabilityType.class)
110 .register(LspType.class)
111 .build());
Avantika-Huawei28b53752016-06-23 17:04:49 +0530112
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530113 @Activate
114 protected void activate() {
115 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
116 .withName("onos-pce-globalnodelabelmap")
117 .withSerializer(Serializer.using(
118 new KryoNamespace.Builder()
119 .register(KryoNamespaces.API)
120 .register(LabelResourceId.class)
121 .build()))
122 .build();
123
124 adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder()
125 .withName("onos-pce-adjlabelmap")
126 .withSerializer(Serializer.using(
127 new KryoNamespace.Builder()
128 .register(KryoNamespaces.API)
129 .register(Link.class,
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530130 LabelResource.class,
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530131 LabelResourceId.class)
132 .build()))
133 .build();
134
135 tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder()
136 .withName("onos-pce-tunnelinfomap")
137 .withSerializer(Serializer.using(
138 new KryoNamespace.Builder()
139 .register(KryoNamespaces.API)
140 .register(TunnelId.class,
141 PceccTunnelInfo.class,
142 DefaultLspLocalLabelInfo.class,
143 TunnelConsumerId.class,
144 LabelResourceId.class)
145 .build()))
146 .build();
147
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530148 failedPathSet = storageService.<PcePathInfo>setBuilder()
149 .withName("failed-path-info")
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530150 .withSerializer(SERIALIZER)
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530151 .build()
152 .asDistributedSet();
153
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530154 log.info("Started");
155 }
156
157 @Deactivate
158 protected void deactivate() {
159 log.info("Stopped");
160 }
161
162 @Override
163 public boolean existsGlobalNodeLabel(DeviceId id) {
164 checkNotNull(id, DEVICE_ID_NULL);
165 return globalNodeLabelMap.containsKey(id);
166 }
167
168 @Override
169 public boolean existsAdjLabel(Link link) {
170 checkNotNull(link, LINK_NULL);
171 return adjLabelMap.containsKey(link);
172 }
173
174 @Override
175 public boolean existsTunnelInfo(TunnelId tunnelId) {
176 checkNotNull(tunnelId, TUNNEL_ID_NULL);
177 return tunnelInfoMap.containsKey(tunnelId);
178 }
179
180 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530181 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
182 checkNotNull(failedPathInfo, PATH_INFO_NULL);
183 return failedPathSet.contains(failedPathInfo);
184 }
185
186 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530187 public int getGlobalNodeLabelCount() {
188 return globalNodeLabelMap.size();
189 }
190
191 @Override
192 public int getAdjLabelCount() {
193 return adjLabelMap.size();
194 }
195
196 @Override
197 public int getTunnelInfoCount() {
198 return tunnelInfoMap.size();
199 }
200
201 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530202 public int getFailedPathInfoCount() {
203 return failedPathSet.size();
204 }
205
206 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530207 public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
208 return globalNodeLabelMap.entrySet().stream()
209 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
210 }
211
212 @Override
213 public Map<Link, LabelResourceId> getAdjLabels() {
214 return adjLabelMap.entrySet().stream()
215 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
216 }
217
218 @Override
219 public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
220 return tunnelInfoMap.entrySet().stream()
221 .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value()));
222 }
223
224 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530225 public Iterable<PcePathInfo> getFailedPathInfos() {
226 return ImmutableSet.copyOf(failedPathSet);
227 }
228
229 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530230 public LabelResourceId getGlobalNodeLabel(DeviceId id) {
231 checkNotNull(id, DEVICE_ID_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530232 return globalNodeLabelMap.get(id) == null ? null : globalNodeLabelMap.get(id).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530233 }
234
235 @Override
236 public LabelResourceId getAdjLabel(Link link) {
237 checkNotNull(link, LINK_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530238 return adjLabelMap.get(link) == null ? null : adjLabelMap.get(link).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530239 }
240
241 @Override
242 public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
243 checkNotNull(tunnelId, TUNNEL_ID_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530244 return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530245 }
246
247 @Override
248 public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
249 checkNotNull(deviceId, DEVICE_ID_NULL);
250 checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
251
252 globalNodeLabelMap.put(deviceId, labelId);
253 }
254
255 @Override
256 public void addAdjLabel(Link link, LabelResourceId labelId) {
257 checkNotNull(link, LINK_NULL);
258 checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
259
260 adjLabelMap.put(link, labelId);
261 }
262
263 @Override
264 public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
265 checkNotNull(tunnelId, TUNNEL_ID_NULL);
266 checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL);
267
268 tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
269 }
270
271 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530272 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
273 checkNotNull(failedPathInfo, PATH_INFO_NULL);
274 failedPathSet.add(failedPathInfo);
275 }
276
277 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530278 public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
279 checkNotNull(tunnelId, TUNNEL_ID_NULL);
280 checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
281
282 if (!tunnelInfoMap.containsKey((tunnelId))) {
283 log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
284 return false;
285 }
286
287 PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
288 tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
289 tunnelInfoMap.put(tunnelId, tunnelInfo);
290
291 return true;
292 }
293
294 @Override
295 public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
296 checkNotNull(tunnelId, TUNNEL_ID_NULL);
297 checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL);
298
299 if (!tunnelInfoMap.containsKey((tunnelId))) {
300 log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
301 return false;
302 }
303
304 PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
305 tunnelInfo.tunnelConsumerId(tunnelConsumerId);
306 tunnelInfoMap.put(tunnelId, tunnelInfo);
307
308 return true;
309 }
310
311 @Override
312 public boolean removeGlobalNodeLabel(DeviceId id) {
313 checkNotNull(id, DEVICE_ID_NULL);
314
315 if (globalNodeLabelMap.remove(id) == null) {
316 log.error("SR-TE node label deletion for device {} has failed.", id.toString());
317 return false;
318 }
319 return true;
320 }
321
322 @Override
323 public boolean removeAdjLabel(Link link) {
324 checkNotNull(link, LINK_NULL);
325
326 if (adjLabelMap.remove(link) == null) {
327 log.error("Adjacency label deletion for link {} hash failed.", link.toString());
328 return false;
329 }
330 return true;
331 }
332
333 @Override
334 public boolean removeTunnelInfo(TunnelId tunnelId) {
335 checkNotNull(tunnelId, TUNNEL_ID_NULL);
336
337 if (tunnelInfoMap.remove(tunnelId) == null) {
338 log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
339 return false;
340 }
341 return true;
342 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530343
344 @Override
345 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
346 checkNotNull(failedPathInfo, PATH_INFO_NULL);
347
348 if (!failedPathSet.remove(failedPathInfo)) {
349 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
350 return false;
351 }
352 return true;
353 }
Avantika-Huawei28b53752016-06-23 17:04:49 +0530354
355 @Override
356 public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
357 checkNotNull(lsrId);
358 checkNotNull(deviceId);
359
360 lsrIdDeviceIdMap.put(lsrId, deviceId);
361 return true;
362 }
363
364 @Override
365 public boolean removeLsrIdDevice(String lsrId) {
366 checkNotNull(lsrId);
367
368 lsrIdDeviceIdMap.remove(lsrId);
369 return true;
370 }
371
372 @Override
373 public DeviceId getLsrIdDevice(String lsrId) {
374 checkNotNull(lsrId);
375
376 return lsrIdDeviceIdMap.get(lsrId);
377
378 }
379
380 @Override
381 public boolean addPccLsr(DeviceId lsrId) {
382 checkNotNull(lsrId);
383 pendinglabelDbSyncPccMap.add(lsrId);
384 return true;
385 }
386
387 @Override
388 public boolean removePccLsr(DeviceId lsrId) {
389 checkNotNull(lsrId);
390 pendinglabelDbSyncPccMap.remove(lsrId);
391 return true;
392 }
393
394 @Override
395 public boolean hasPccLsr(DeviceId lsrId) {
396 checkNotNull(lsrId);
397 return pendinglabelDbSyncPccMap.contains(lsrId);
398
399 }
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530400}