blob: 998f87e91d453b5cc621068249d9d802c48e87d4 [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;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053019import org.onlab.util.KryoNamespace;
Satish Kba1c9122017-04-05 15:27:23 +053020import org.onosproject.incubator.net.tunnel.TunnelId;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053021import org.onosproject.pce.pceservice.ExplicitPathInfo;
Satish K2eb5d842017-04-04 16:28:37 +053022import org.onosproject.pce.pceservice.LspType;
Priyanka Bcdf9b102016-06-07 20:01:38 +053023import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053024import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053025import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Priyanka B4c3b4512016-07-22 11:41:49 +053026import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053027import org.onosproject.pce.pcestore.api.PceStore;
28import org.onosproject.store.serializers.KryoNamespaces;
29import org.onosproject.store.service.ConsistentMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053030import org.onosproject.store.service.DistributedSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053031import org.onosproject.store.service.Serializer;
32import org.onosproject.store.service.StorageService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033import org.osgi.service.component.annotations.Activate;
34import org.osgi.service.component.annotations.Component;
35import org.osgi.service.component.annotations.Deactivate;
36import org.osgi.service.component.annotations.Reference;
37import org.osgi.service.component.annotations.ReferenceCardinality;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053038import org.slf4j.Logger;
39import org.slf4j.LoggerFactory;
40
Ray Milkeyd84f89b2018-08-17 14:54:17 -070041import java.util.Arrays;
Satish K2eb5d842017-04-04 16:28:37 +053042import java.util.List;
43
44import static com.google.common.base.Preconditions.checkNotNull;
45
Mahesh Poojary Sba827292016-05-09 11:31:12 +053046/**
47 * Manages the pool of available labels to devices, links and tunnels.
48 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070049@Component(immediate = true, service = PceStore.class)
Mahesh Poojary Sba827292016-05-09 11:31:12 +053050public class DistributedPceStore implements PceStore {
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053051 private static final String PATH_INFO_NULL = "Path Info cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053052 private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null";
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053053 private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null";
Mahesh Poojary Sba827292016-05-09 11:31:12 +053054
55 private final Logger log = LoggerFactory.getLogger(getClass());
56
Ray Milkeyd84f89b2018-08-17 14:54:17 -070057 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Mahesh Poojary Sba827292016-05-09 11:31:12 +053058 protected StorageService storageService;
59
Satish Kba1c9122017-04-05 15:27:23 +053060 //Mapping tunnel name with Disjoint paths
61 private ConsistentMap<String, List<TunnelId>> tunnelNameDisjoinTunnelIdInfo;
62
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053063 // List of Failed path info
64 private DistributedSet<PcePathInfo> failedPathSet;
65
Priyanka Bbae0eeb12016-11-30 11:59:48 +053066 // Maintains tunnel name mapped to explicit path info
67 private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap;
68
Priyanka B3fdb9dd2016-08-08 10:47:24 +053069 private static final Serializer SERIALIZER = Serializer
70 .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
71 .register(PcePathInfo.class)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053072 .register(ExplicitPathInfo.class)
73 .register(ExplicitPathInfo.Type.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053074 .register(CostConstraint.class)
75 .register(CostConstraint.Type.class)
Satish K2eb5d842017-04-04 16:28:37 +053076 .register(PceBandwidthConstraint.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053077 .register(SharedBandwidthConstraint.class)
78 .register(CapabilityConstraint.class)
79 .register(CapabilityConstraint.CapabilityType.class)
80 .register(LspType.class)
81 .build());
Avantika-Huawei28b53752016-06-23 17:04:49 +053082
Mahesh Poojary Sba827292016-05-09 11:31:12 +053083 @Activate
84 protected void activate() {
Mahesh Poojary Sba827292016-05-09 11:31:12 +053085
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053086 failedPathSet = storageService.<PcePathInfo>setBuilder()
87 .withName("failed-path-info")
Priyanka B3fdb9dd2016-08-08 10:47:24 +053088 .withSerializer(SERIALIZER)
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053089 .build()
90 .asDistributedSet();
91
Priyanka Bbae0eeb12016-11-30 11:59:48 +053092 tunnelNameExplicitPathInfoMap = storageService.<String, List<ExplicitPathInfo>>consistentMapBuilder()
93 .withName("onos-pce-explicitpathinfo")
94 .withSerializer(Serializer.using(
95 new KryoNamespace.Builder()
96 .register(KryoNamespaces.API)
97 .register(ExplicitPathInfo.class)
98 .register(ExplicitPathInfo.Type.class)
99 .build()))
100 .build();
101
Satish Kba1c9122017-04-05 15:27:23 +0530102 tunnelNameDisjoinTunnelIdInfo = storageService.<String, List<TunnelId>>consistentMapBuilder()
103 .withName("onos-pce-disjointTunnelIds")
104 .withSerializer(Serializer.using(
105 new KryoNamespace.Builder()
106 .register(KryoNamespaces.API)
107 .register(TunnelId.class)
108 .build()))
109 .build();
110
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530111 log.info("Started");
112 }
113
114 @Deactivate
115 protected void deactivate() {
116 log.info("Stopped");
117 }
118
119 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530120 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
121 checkNotNull(failedPathInfo, PATH_INFO_NULL);
122 return failedPathSet.contains(failedPathInfo);
123 }
124
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530125
126 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530127 public int getFailedPathInfoCount() {
128 return failedPathSet.size();
129 }
130
131 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530132 public Iterable<PcePathInfo> getFailedPathInfos() {
133 return ImmutableSet.copyOf(failedPathSet);
134 }
135
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530136
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530137
138 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530139 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
140 checkNotNull(failedPathInfo, PATH_INFO_NULL);
141 failedPathSet.add(failedPathInfo);
142 }
143
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530144
145 @Override
146 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
147 checkNotNull(failedPathInfo, PATH_INFO_NULL);
148
149 if (!failedPathSet.remove(failedPathInfo)) {
150 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
151 return false;
152 }
153 return true;
154 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530155
156 @Override
157 public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
158 checkNotNull(tunnelName);
159 checkNotNull(explicitPathInfo);
160 return tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo) != null ? true : false;
161 }
162
163 @Override
164 public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
165 checkNotNull(tunnelName);
166 if (tunnelNameExplicitPathInfoMap.get(tunnelName) != null) {
167 return tunnelNameExplicitPathInfoMap.get(tunnelName).value();
168 }
169 return null;
170 }
171
Satish Kba1c9122017-04-05 15:27:23 +0530172/* @Override
173 public DisjointPath getDisjointPaths(String tunnelName) {
174 if (tunnelNameDisjointPathInfo.get(tunnelName) != null) {
175 return tunnelNameDisjointPathInfo.get(tunnelName).value();
176 }
177 return null;
178 }
179
180 @Override
181 public boolean addDisjointPathInfo(String tunnelName, DisjointPath path) {
182 checkNotNull(tunnelName);
183 checkNotNull(path);
184 return tunnelNameDisjointPathInfo.put(tunnelName, path) != null ? true : false;
185 }*/
186
187 @Override
188 public boolean addLoadBalancingTunnelIdsInfo(String tunnelName, TunnelId... tunnelIds) {
189 checkNotNull(tunnelName);
190 checkNotNull(tunnelIds);
191 return tunnelNameDisjoinTunnelIdInfo.put(tunnelName, Arrays.asList(tunnelIds)) != null ? true : false;
192 }
193
194 @Override
195 public List<TunnelId> getLoadBalancingTunnelIds(String tunnelName) {
196 if (tunnelNameDisjoinTunnelIdInfo.get(tunnelName) != null) {
197 return tunnelNameDisjoinTunnelIdInfo.get(tunnelName).value();
198 }
199 return null;
200 }
201
202 @Override
203 public boolean removeLoadBalancingTunnelIdsInfo(String tunnelName) {
204 if (tunnelNameDisjoinTunnelIdInfo.remove(tunnelName) == null) {
205 log.error("Failed to remove entry {} for this tunnelName in DisjointTunnelIdsInfoMap" + tunnelName);
206 return false;
207 }
208 return true;
209 }
210
211 /* @Override
212 public boolean removeDisjointPathInfo(String tunnelName) {
213 if (tunnelNameDisjointPathInfo.remove(tunnelName) == null) {
214 log.error("Failed to remove entry {} for this tunnelName in DisjointPathInfoMap", tunnelName);
215 return false;
216 }
217 return true;
218 }*/
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530219}