blob: 1c1aece4daf2daaa52a314b4dfd6efbcfe8194dd [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
Mahesh Poojary Sba827292016-05-09 11:31:12 +053022import java.util.List;
23import java.util.Map;
24import java.util.stream.Collectors;
25
26import org.apache.felix.scr.annotations.Activate;
27import org.apache.felix.scr.annotations.Component;
28import org.apache.felix.scr.annotations.Deactivate;
29import org.apache.felix.scr.annotations.Reference;
30import org.apache.felix.scr.annotations.ReferenceCardinality;
31import org.apache.felix.scr.annotations.Service;
32
33import org.onlab.util.KryoNamespace;
34import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053035import org.onosproject.incubator.net.resource.label.LabelResource;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053036import org.onosproject.incubator.net.resource.label.LabelResourceId;
Mahesh Poojary S33536202016-05-30 07:22:36 +053037import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053038import org.onosproject.net.DeviceId;
39import org.onosproject.net.Link;
40import org.onosproject.net.resource.ResourceConsumer;
Priyanka Bcdf9b102016-06-07 20:01:38 +053041import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053042import org.onosproject.pce.pceservice.constraint.CostConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053043import org.onosproject.pce.pceservice.TunnelConsumerId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053044import org.onosproject.pce.pceservice.LspType;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053045import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
46import org.onosproject.pce.pcestore.api.PceStore;
47import org.onosproject.store.serializers.KryoNamespaces;
48import org.onosproject.store.service.ConsistentMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053049import org.onosproject.store.service.DistributedSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053050import org.onosproject.store.service.Serializer;
51import org.onosproject.store.service.StorageService;
52
53import org.slf4j.Logger;
54import org.slf4j.LoggerFactory;
55
56/**
57 * Manages the pool of available labels to devices, links and tunnels.
58 */
59@Component(immediate = true)
60@Service
61public class DistributedPceStore implements PceStore {
62
63 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053064 private static final String DEVICE_LABEL_STORE_INFO_NULL = "Device Label Store cannot be null";
65 private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null";
66 private static final String LABEL_RESOURCE_LIST_NULL = "Label Resource List cannot be null";
67 private static final String LABEL_RESOURCE_NULL = "Label Resource cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053068 private static final String LINK_NULL = "LINK cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053069 private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label Info cannot be null";
70 private static final String PATH_INFO_NULL = "Path Info cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053071 private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053072 private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053073 private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null";
74
75 private final Logger log = LoggerFactory.getLogger(getClass());
76
77 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 protected StorageService storageService;
79
80 // Mapping device with global node label
81 private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap;
82
83 // Mapping link with adjacency label
84 private ConsistentMap<Link, LabelResourceId> adjLabelMap;
85
86 // Mapping tunnel with device local info with tunnel consumer id
87 private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap;
88
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053089 // List of Failed path info
90 private DistributedSet<PcePathInfo> failedPathSet;
91
Mahesh Poojary Sba827292016-05-09 11:31:12 +053092 @Activate
93 protected void activate() {
94 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
95 .withName("onos-pce-globalnodelabelmap")
96 .withSerializer(Serializer.using(
97 new KryoNamespace.Builder()
98 .register(KryoNamespaces.API)
99 .register(LabelResourceId.class)
100 .build()))
101 .build();
102
103 adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder()
104 .withName("onos-pce-adjlabelmap")
105 .withSerializer(Serializer.using(
106 new KryoNamespace.Builder()
107 .register(KryoNamespaces.API)
108 .register(Link.class,
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530109 LabelResource.class,
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530110 LabelResourceId.class)
111 .build()))
112 .build();
113
114 tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder()
115 .withName("onos-pce-tunnelinfomap")
116 .withSerializer(Serializer.using(
117 new KryoNamespace.Builder()
118 .register(KryoNamespaces.API)
119 .register(TunnelId.class,
120 PceccTunnelInfo.class,
121 DefaultLspLocalLabelInfo.class,
122 TunnelConsumerId.class,
123 LabelResourceId.class)
124 .build()))
125 .build();
126
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530127 failedPathSet = storageService.<PcePathInfo>setBuilder()
128 .withName("failed-path-info")
129 .withSerializer(Serializer.using(
130 new KryoNamespace.Builder()
131 .register(KryoNamespaces.API)
132 .register(PcePathInfo.class,
Mahesh Poojary S33536202016-05-30 07:22:36 +0530133 CostConstraint.class,
134 CostConstraint.Type.class,
135 BandwidthConstraint.class,
Priyanka Bcdf9b102016-06-07 20:01:38 +0530136 CapabilityConstraint.class,
137 CapabilityConstraint.CapabilityType.class,
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530138 LspType.class)
139 .build()))
140
141 .build()
142 .asDistributedSet();
143
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530144 log.info("Started");
145 }
146
147 @Deactivate
148 protected void deactivate() {
149 log.info("Stopped");
150 }
151
152 @Override
153 public boolean existsGlobalNodeLabel(DeviceId id) {
154 checkNotNull(id, DEVICE_ID_NULL);
155 return globalNodeLabelMap.containsKey(id);
156 }
157
158 @Override
159 public boolean existsAdjLabel(Link link) {
160 checkNotNull(link, LINK_NULL);
161 return adjLabelMap.containsKey(link);
162 }
163
164 @Override
165 public boolean existsTunnelInfo(TunnelId tunnelId) {
166 checkNotNull(tunnelId, TUNNEL_ID_NULL);
167 return tunnelInfoMap.containsKey(tunnelId);
168 }
169
170 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530171 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
172 checkNotNull(failedPathInfo, PATH_INFO_NULL);
173 return failedPathSet.contains(failedPathInfo);
174 }
175
176 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530177 public int getGlobalNodeLabelCount() {
178 return globalNodeLabelMap.size();
179 }
180
181 @Override
182 public int getAdjLabelCount() {
183 return adjLabelMap.size();
184 }
185
186 @Override
187 public int getTunnelInfoCount() {
188 return tunnelInfoMap.size();
189 }
190
191 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530192 public int getFailedPathInfoCount() {
193 return failedPathSet.size();
194 }
195
196 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530197 public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() {
198 return globalNodeLabelMap.entrySet().stream()
199 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
200 }
201
202 @Override
203 public Map<Link, LabelResourceId> getAdjLabels() {
204 return adjLabelMap.entrySet().stream()
205 .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value()));
206 }
207
208 @Override
209 public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() {
210 return tunnelInfoMap.entrySet().stream()
211 .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value()));
212 }
213
214 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530215 public Iterable<PcePathInfo> getFailedPathInfos() {
216 return ImmutableSet.copyOf(failedPathSet);
217 }
218
219 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530220 public LabelResourceId getGlobalNodeLabel(DeviceId id) {
221 checkNotNull(id, DEVICE_ID_NULL);
222 return globalNodeLabelMap.get(id).value();
223 }
224
225 @Override
226 public LabelResourceId getAdjLabel(Link link) {
227 checkNotNull(link, LINK_NULL);
228 return adjLabelMap.get(link).value();
229 }
230
231 @Override
232 public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) {
233 checkNotNull(tunnelId, TUNNEL_ID_NULL);
234 return tunnelInfoMap.get(tunnelId).value();
235 }
236
237 @Override
238 public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) {
239 checkNotNull(deviceId, DEVICE_ID_NULL);
240 checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
241
242 globalNodeLabelMap.put(deviceId, labelId);
243 }
244
245 @Override
246 public void addAdjLabel(Link link, LabelResourceId labelId) {
247 checkNotNull(link, LINK_NULL);
248 checkNotNull(labelId, LABEL_RESOURCE_ID_NULL);
249
250 adjLabelMap.put(link, labelId);
251 }
252
253 @Override
254 public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) {
255 checkNotNull(tunnelId, TUNNEL_ID_NULL);
256 checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL);
257
258 tunnelInfoMap.put(tunnelId, pceccTunnelInfo);
259 }
260
261 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530262 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
263 checkNotNull(failedPathInfo, PATH_INFO_NULL);
264 failedPathSet.add(failedPathInfo);
265 }
266
267 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530268 public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) {
269 checkNotNull(tunnelId, TUNNEL_ID_NULL);
270 checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL);
271
272 if (!tunnelInfoMap.containsKey((tunnelId))) {
273 log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
274 return false;
275 }
276
277 PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
278 tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList);
279 tunnelInfoMap.put(tunnelId, tunnelInfo);
280
281 return true;
282 }
283
284 @Override
285 public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
286 checkNotNull(tunnelId, TUNNEL_ID_NULL);
287 checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL);
288
289 if (!tunnelInfoMap.containsKey((tunnelId))) {
290 log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString());
291 return false;
292 }
293
294 PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value();
295 tunnelInfo.tunnelConsumerId(tunnelConsumerId);
296 tunnelInfoMap.put(tunnelId, tunnelInfo);
297
298 return true;
299 }
300
301 @Override
302 public boolean removeGlobalNodeLabel(DeviceId id) {
303 checkNotNull(id, DEVICE_ID_NULL);
304
305 if (globalNodeLabelMap.remove(id) == null) {
306 log.error("SR-TE node label deletion for device {} has failed.", id.toString());
307 return false;
308 }
309 return true;
310 }
311
312 @Override
313 public boolean removeAdjLabel(Link link) {
314 checkNotNull(link, LINK_NULL);
315
316 if (adjLabelMap.remove(link) == null) {
317 log.error("Adjacency label deletion for link {} hash failed.", link.toString());
318 return false;
319 }
320 return true;
321 }
322
323 @Override
324 public boolean removeTunnelInfo(TunnelId tunnelId) {
325 checkNotNull(tunnelId, TUNNEL_ID_NULL);
326
327 if (tunnelInfoMap.remove(tunnelId) == null) {
328 log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
329 return false;
330 }
331 return true;
332 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530333
334 @Override
335 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
336 checkNotNull(failedPathInfo, PATH_INFO_NULL);
337
338 if (!failedPathSet.remove(failedPathInfo)) {
339 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
340 return false;
341 }
342 return true;
343 }
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530344}