blob: 001f74b8e5836b9254439ff4f1d7575682386c66 [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
Priyanka Bbae0eeb12016-11-30 11:59:48 +053022import java.util.List;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053023import 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 S33536202016-05-30 07:22:36 +053035import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053036import org.onosproject.net.resource.ResourceConsumer;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053037import org.onosproject.pce.pceservice.ExplicitPathInfo;
Priyanka Bcdf9b102016-06-07 20:01:38 +053038import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053039import org.onosproject.pce.pceservice.constraint.CostConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053040import org.onosproject.pce.pceservice.TunnelConsumerId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053041import org.onosproject.pce.pceservice.LspType;
Priyanka B4c3b4512016-07-22 11:41:49 +053042import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053043import org.onosproject.pce.pcestore.api.PceStore;
44import org.onosproject.store.serializers.KryoNamespaces;
45import org.onosproject.store.service.ConsistentMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053046import org.onosproject.store.service.DistributedSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053047import org.onosproject.store.service.Serializer;
48import org.onosproject.store.service.StorageService;
49
50import org.slf4j.Logger;
51import org.slf4j.LoggerFactory;
52
53/**
54 * Manages the pool of available labels to devices, links and tunnels.
55 */
56@Component(immediate = true)
57@Service
58public class DistributedPceStore implements PceStore {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053059 private static final String PATH_INFO_NULL = "Path Info cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053060 private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053061 private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053062
63 private final Logger log = LoggerFactory.getLogger(getClass());
64
65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 protected StorageService storageService;
67
Mahesh Poojary Sba827292016-05-09 11:31:12 +053068 // Mapping tunnel with device local info with tunnel consumer id
Avantika-Huawei9e848e82016-09-01 12:12:42 +053069 private ConsistentMap<TunnelId, ResourceConsumer> tunnelInfoMap;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053070
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053071 // List of Failed path info
72 private DistributedSet<PcePathInfo> failedPathSet;
73
Priyanka Bbae0eeb12016-11-30 11:59:48 +053074 // Maintains tunnel name mapped to explicit path info
75 private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap;
76
Priyanka B3fdb9dd2016-08-08 10:47:24 +053077 private static final Serializer SERIALIZER = Serializer
78 .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
79 .register(PcePathInfo.class)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053080 .register(ExplicitPathInfo.class)
81 .register(ExplicitPathInfo.Type.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053082 .register(CostConstraint.class)
83 .register(CostConstraint.Type.class)
84 .register(BandwidthConstraint.class)
85 .register(SharedBandwidthConstraint.class)
86 .register(CapabilityConstraint.class)
87 .register(CapabilityConstraint.CapabilityType.class)
88 .register(LspType.class)
89 .build());
Avantika-Huawei28b53752016-06-23 17:04:49 +053090
Mahesh Poojary Sba827292016-05-09 11:31:12 +053091 @Activate
92 protected void activate() {
Avantika-Huawei9e848e82016-09-01 12:12:42 +053093 tunnelInfoMap = storageService.<TunnelId, ResourceConsumer>consistentMapBuilder()
Mahesh Poojary Sba827292016-05-09 11:31:12 +053094 .withName("onos-pce-tunnelinfomap")
95 .withSerializer(Serializer.using(
96 new KryoNamespace.Builder()
97 .register(KryoNamespaces.API)
98 .register(TunnelId.class,
Avantika-Huawei9e848e82016-09-01 12:12:42 +053099 TunnelConsumerId.class)
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530100 .build()))
101 .build();
102
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530103 failedPathSet = storageService.<PcePathInfo>setBuilder()
104 .withName("failed-path-info")
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530105 .withSerializer(SERIALIZER)
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530106 .build()
107 .asDistributedSet();
108
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530109 tunnelNameExplicitPathInfoMap = storageService.<String, List<ExplicitPathInfo>>consistentMapBuilder()
110 .withName("onos-pce-explicitpathinfo")
111 .withSerializer(Serializer.using(
112 new KryoNamespace.Builder()
113 .register(KryoNamespaces.API)
114 .register(ExplicitPathInfo.class)
115 .register(ExplicitPathInfo.Type.class)
116 .build()))
117 .build();
118
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530119 log.info("Started");
120 }
121
122 @Deactivate
123 protected void deactivate() {
124 log.info("Stopped");
125 }
126
127 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530128 public boolean existsTunnelInfo(TunnelId tunnelId) {
129 checkNotNull(tunnelId, TUNNEL_ID_NULL);
130 return tunnelInfoMap.containsKey(tunnelId);
131 }
132
133 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530134 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
135 checkNotNull(failedPathInfo, PATH_INFO_NULL);
136 return failedPathSet.contains(failedPathInfo);
137 }
138
139 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530140 public int getTunnelInfoCount() {
141 return tunnelInfoMap.size();
142 }
143
144 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530145 public int getFailedPathInfoCount() {
146 return failedPathSet.size();
147 }
148
149 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530150 public Map<TunnelId, ResourceConsumer> getTunnelInfos() {
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530151 return tunnelInfoMap.entrySet().stream()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530152 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value()));
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530153 }
154
155 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530156 public Iterable<PcePathInfo> getFailedPathInfos() {
157 return ImmutableSet.copyOf(failedPathSet);
158 }
159
160 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530161 public ResourceConsumer getTunnelInfo(TunnelId tunnelId) {
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530162 checkNotNull(tunnelId, TUNNEL_ID_NULL);
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530163 return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530164 }
165
166 @Override
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530167 public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530168 checkNotNull(tunnelId, TUNNEL_ID_NULL);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530169 checkNotNull(tunnelConsumerId, PCECC_TUNNEL_INFO_NULL);
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530170
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530171 tunnelInfoMap.put(tunnelId, tunnelConsumerId);
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530172 }
173
174 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530175 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
176 checkNotNull(failedPathInfo, PATH_INFO_NULL);
177 failedPathSet.add(failedPathInfo);
178 }
179
180 @Override
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530181 public boolean removeTunnelInfo(TunnelId tunnelId) {
182 checkNotNull(tunnelId, TUNNEL_ID_NULL);
183
184 if (tunnelInfoMap.remove(tunnelId) == null) {
185 log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
186 return false;
187 }
188 return true;
189 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530190
191 @Override
192 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
193 checkNotNull(failedPathInfo, PATH_INFO_NULL);
194
195 if (!failedPathSet.remove(failedPathInfo)) {
196 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
197 return false;
198 }
199 return true;
200 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530201
202 @Override
203 public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
204 checkNotNull(tunnelName);
205 checkNotNull(explicitPathInfo);
206 return tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo) != null ? true : false;
207 }
208
209 @Override
210 public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
211 checkNotNull(tunnelName);
212 if (tunnelNameExplicitPathInfoMap.get(tunnelName) != null) {
213 return tunnelNameExplicitPathInfoMap.get(tunnelName).value();
214 }
215 return null;
216 }
217
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530218}