blob: 91923ab53b281e09a91ad83d74f80c27acfef053 [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Sba827292016-05-09 11:31:12 +05303 *
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
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053018import com.google.common.collect.ImmutableSet;
Satish Kba1c9122017-04-05 15:27:23 +053019import java.util.Arrays;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053026import org.onlab.util.KryoNamespace;
Satish Kba1c9122017-04-05 15:27:23 +053027import org.onosproject.incubator.net.tunnel.TunnelId;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053028import org.onosproject.pce.pceservice.ExplicitPathInfo;
Satish K2eb5d842017-04-04 16:28:37 +053029import org.onosproject.pce.pceservice.LspType;
Priyanka Bcdf9b102016-06-07 20:01:38 +053030import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053031import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053032import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Priyanka B4c3b4512016-07-22 11:41:49 +053033import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053034import org.onosproject.pce.pcestore.api.PceStore;
35import org.onosproject.store.serializers.KryoNamespaces;
36import org.onosproject.store.service.ConsistentMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053037import org.onosproject.store.service.DistributedSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053038import org.onosproject.store.service.Serializer;
39import org.onosproject.store.service.StorageService;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053040import org.slf4j.Logger;
41import org.slf4j.LoggerFactory;
42
Satish K2eb5d842017-04-04 16:28:37 +053043import java.util.List;
44
45import static com.google.common.base.Preconditions.checkNotNull;
46
Mahesh Poojary Sba827292016-05-09 11:31:12 +053047/**
48 * Manages the pool of available labels to devices, links and tunnels.
49 */
50@Component(immediate = true)
51@Service
52public class DistributedPceStore implements PceStore {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053053 private static final String PATH_INFO_NULL = "Path Info cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053054 private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053055 private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053056
57 private final Logger log = LoggerFactory.getLogger(getClass());
58
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected StorageService storageService;
61
Satish Kba1c9122017-04-05 15:27:23 +053062 //Mapping tunnel name with Disjoint paths
63 private ConsistentMap<String, List<TunnelId>> tunnelNameDisjoinTunnelIdInfo;
64
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053065 // List of Failed path info
66 private DistributedSet<PcePathInfo> failedPathSet;
67
Priyanka Bbae0eeb12016-11-30 11:59:48 +053068 // Maintains tunnel name mapped to explicit path info
69 private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap;
70
Priyanka B3fdb9dd2016-08-08 10:47:24 +053071 private static final Serializer SERIALIZER = Serializer
72 .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
73 .register(PcePathInfo.class)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053074 .register(ExplicitPathInfo.class)
75 .register(ExplicitPathInfo.Type.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053076 .register(CostConstraint.class)
77 .register(CostConstraint.Type.class)
Satish K2eb5d842017-04-04 16:28:37 +053078 .register(PceBandwidthConstraint.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053079 .register(SharedBandwidthConstraint.class)
80 .register(CapabilityConstraint.class)
81 .register(CapabilityConstraint.CapabilityType.class)
82 .register(LspType.class)
83 .build());
Avantika-Huawei28b53752016-06-23 17:04:49 +053084
Mahesh Poojary Sba827292016-05-09 11:31:12 +053085 @Activate
86 protected void activate() {
Mahesh Poojary Sba827292016-05-09 11:31:12 +053087
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053088 failedPathSet = storageService.<PcePathInfo>setBuilder()
89 .withName("failed-path-info")
Priyanka B3fdb9dd2016-08-08 10:47:24 +053090 .withSerializer(SERIALIZER)
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053091 .build()
92 .asDistributedSet();
93
Priyanka Bbae0eeb12016-11-30 11:59:48 +053094 tunnelNameExplicitPathInfoMap = storageService.<String, List<ExplicitPathInfo>>consistentMapBuilder()
95 .withName("onos-pce-explicitpathinfo")
96 .withSerializer(Serializer.using(
97 new KryoNamespace.Builder()
98 .register(KryoNamespaces.API)
99 .register(ExplicitPathInfo.class)
100 .register(ExplicitPathInfo.Type.class)
101 .build()))
102 .build();
103
Satish Kba1c9122017-04-05 15:27:23 +0530104 tunnelNameDisjoinTunnelIdInfo = storageService.<String, List<TunnelId>>consistentMapBuilder()
105 .withName("onos-pce-disjointTunnelIds")
106 .withSerializer(Serializer.using(
107 new KryoNamespace.Builder()
108 .register(KryoNamespaces.API)
109 .register(TunnelId.class)
110 .build()))
111 .build();
112
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530113 log.info("Started");
114 }
115
116 @Deactivate
117 protected void deactivate() {
118 log.info("Stopped");
119 }
120
121 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530122 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
123 checkNotNull(failedPathInfo, PATH_INFO_NULL);
124 return failedPathSet.contains(failedPathInfo);
125 }
126
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530127
128 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530129 public int getFailedPathInfoCount() {
130 return failedPathSet.size();
131 }
132
133 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530134 public Iterable<PcePathInfo> getFailedPathInfos() {
135 return ImmutableSet.copyOf(failedPathSet);
136 }
137
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530138
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530139
140 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530141 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
142 checkNotNull(failedPathInfo, PATH_INFO_NULL);
143 failedPathSet.add(failedPathInfo);
144 }
145
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530146
147 @Override
148 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
149 checkNotNull(failedPathInfo, PATH_INFO_NULL);
150
151 if (!failedPathSet.remove(failedPathInfo)) {
152 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
153 return false;
154 }
155 return true;
156 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530157
158 @Override
159 public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
160 checkNotNull(tunnelName);
161 checkNotNull(explicitPathInfo);
162 return tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo) != null ? true : false;
163 }
164
165 @Override
166 public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
167 checkNotNull(tunnelName);
168 if (tunnelNameExplicitPathInfoMap.get(tunnelName) != null) {
169 return tunnelNameExplicitPathInfoMap.get(tunnelName).value();
170 }
171 return null;
172 }
173
Satish Kba1c9122017-04-05 15:27:23 +0530174/* @Override
175 public DisjointPath getDisjointPaths(String tunnelName) {
176 if (tunnelNameDisjointPathInfo.get(tunnelName) != null) {
177 return tunnelNameDisjointPathInfo.get(tunnelName).value();
178 }
179 return null;
180 }
181
182 @Override
183 public boolean addDisjointPathInfo(String tunnelName, DisjointPath path) {
184 checkNotNull(tunnelName);
185 checkNotNull(path);
186 return tunnelNameDisjointPathInfo.put(tunnelName, path) != null ? true : false;
187 }*/
188
189 @Override
190 public boolean addLoadBalancingTunnelIdsInfo(String tunnelName, TunnelId... tunnelIds) {
191 checkNotNull(tunnelName);
192 checkNotNull(tunnelIds);
193 return tunnelNameDisjoinTunnelIdInfo.put(tunnelName, Arrays.asList(tunnelIds)) != null ? true : false;
194 }
195
196 @Override
197 public List<TunnelId> getLoadBalancingTunnelIds(String tunnelName) {
198 if (tunnelNameDisjoinTunnelIdInfo.get(tunnelName) != null) {
199 return tunnelNameDisjoinTunnelIdInfo.get(tunnelName).value();
200 }
201 return null;
202 }
203
204 @Override
205 public boolean removeLoadBalancingTunnelIdsInfo(String tunnelName) {
206 if (tunnelNameDisjoinTunnelIdInfo.remove(tunnelName) == null) {
207 log.error("Failed to remove entry {} for this tunnelName in DisjointTunnelIdsInfoMap" + tunnelName);
208 return false;
209 }
210 return true;
211 }
212
213 /* @Override
214 public boolean removeDisjointPathInfo(String tunnelName) {
215 if (tunnelNameDisjointPathInfo.remove(tunnelName) == null) {
216 log.error("Failed to remove entry {} for this tunnelName in DisjointPathInfoMap", tunnelName);
217 return false;
218 }
219 return true;
220 }*/
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530221}