blob: eb6fadd6af2e7044e9f53cc758c15cc55b8621d4 [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
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053018import com.google.common.collect.ImmutableSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053025import org.onlab.util.KryoNamespace;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053026import org.onosproject.pce.pceservice.ExplicitPathInfo;
Satish K2eb5d842017-04-04 16:28:37 +053027import org.onosproject.pce.pceservice.LspType;
Priyanka Bcdf9b102016-06-07 20:01:38 +053028import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
Mahesh Poojary S33536202016-05-30 07:22:36 +053029import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053030import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Priyanka B4c3b4512016-07-22 11:41:49 +053031import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053032import org.onosproject.pce.pcestore.api.PceStore;
33import org.onosproject.store.serializers.KryoNamespaces;
34import org.onosproject.store.service.ConsistentMap;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053035import org.onosproject.store.service.DistributedSet;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053036import org.onosproject.store.service.Serializer;
37import org.onosproject.store.service.StorageService;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053038import org.slf4j.Logger;
39import org.slf4j.LoggerFactory;
40
Satish K2eb5d842017-04-04 16:28:37 +053041import java.util.List;
42
43import static com.google.common.base.Preconditions.checkNotNull;
44
Mahesh Poojary Sba827292016-05-09 11:31:12 +053045/**
46 * Manages the pool of available labels to devices, links and tunnels.
47 */
48@Component(immediate = true)
49@Service
50public 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
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected StorageService storageService;
59
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053060 // List of Failed path info
61 private DistributedSet<PcePathInfo> failedPathSet;
62
Priyanka Bbae0eeb12016-11-30 11:59:48 +053063 // Maintains tunnel name mapped to explicit path info
64 private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap;
65
Priyanka B3fdb9dd2016-08-08 10:47:24 +053066 private static final Serializer SERIALIZER = Serializer
67 .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
68 .register(PcePathInfo.class)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053069 .register(ExplicitPathInfo.class)
70 .register(ExplicitPathInfo.Type.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053071 .register(CostConstraint.class)
72 .register(CostConstraint.Type.class)
Satish K2eb5d842017-04-04 16:28:37 +053073 .register(PceBandwidthConstraint.class)
Priyanka B3fdb9dd2016-08-08 10:47:24 +053074 .register(SharedBandwidthConstraint.class)
75 .register(CapabilityConstraint.class)
76 .register(CapabilityConstraint.CapabilityType.class)
77 .register(LspType.class)
78 .build());
Avantika-Huawei28b53752016-06-23 17:04:49 +053079
Mahesh Poojary Sba827292016-05-09 11:31:12 +053080 @Activate
81 protected void activate() {
Mahesh Poojary Sba827292016-05-09 11:31:12 +053082
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053083 failedPathSet = storageService.<PcePathInfo>setBuilder()
84 .withName("failed-path-info")
Priyanka B3fdb9dd2016-08-08 10:47:24 +053085 .withSerializer(SERIALIZER)
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053086 .build()
87 .asDistributedSet();
88
Priyanka Bbae0eeb12016-11-30 11:59:48 +053089 tunnelNameExplicitPathInfoMap = storageService.<String, List<ExplicitPathInfo>>consistentMapBuilder()
90 .withName("onos-pce-explicitpathinfo")
91 .withSerializer(Serializer.using(
92 new KryoNamespace.Builder()
93 .register(KryoNamespaces.API)
94 .register(ExplicitPathInfo.class)
95 .register(ExplicitPathInfo.Type.class)
96 .build()))
97 .build();
98
Mahesh Poojary Sba827292016-05-09 11:31:12 +053099 log.info("Started");
100 }
101
102 @Deactivate
103 protected void deactivate() {
104 log.info("Stopped");
105 }
106
107 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530108 public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) {
109 checkNotNull(failedPathInfo, PATH_INFO_NULL);
110 return failedPathSet.contains(failedPathInfo);
111 }
112
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530113
114 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530115 public int getFailedPathInfoCount() {
116 return failedPathSet.size();
117 }
118
119 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530120 public Iterable<PcePathInfo> getFailedPathInfos() {
121 return ImmutableSet.copyOf(failedPathSet);
122 }
123
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530124
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530125
126 @Override
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530127 public void addFailedPathInfo(PcePathInfo failedPathInfo) {
128 checkNotNull(failedPathInfo, PATH_INFO_NULL);
129 failedPathSet.add(failedPathInfo);
130 }
131
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530132
133 @Override
134 public boolean removeFailedPathInfo(PcePathInfo failedPathInfo) {
135 checkNotNull(failedPathInfo, PATH_INFO_NULL);
136
137 if (!failedPathSet.remove(failedPathInfo)) {
138 log.error("Failed path info {} deletion has failed.", failedPathInfo.toString());
139 return false;
140 }
141 return true;
142 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530143
144 @Override
145 public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
146 checkNotNull(tunnelName);
147 checkNotNull(explicitPathInfo);
148 return tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo) != null ? true : false;
149 }
150
151 @Override
152 public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
153 checkNotNull(tunnelName);
154 if (tunnelNameExplicitPathInfoMap.get(tunnelName) != null) {
155 return tunnelNameExplicitPathInfoMap.get(tunnelName).value();
156 }
157 return null;
158 }
159
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530160}