Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.pce.pcestore; |
| 17 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 19 | import java.util.Arrays; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 26 | import org.onlab.util.KryoNamespace; |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 27 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 28 | import org.onosproject.pce.pceservice.ExplicitPathInfo; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 29 | import org.onosproject.pce.pceservice.LspType; |
Priyanka B | cdf9b10 | 2016-06-07 20:01:38 +0530 | [diff] [blame] | 30 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 31 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 32 | import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint; |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 33 | import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 34 | import org.onosproject.pce.pcestore.api.PceStore; |
| 35 | import org.onosproject.store.serializers.KryoNamespaces; |
| 36 | import org.onosproject.store.service.ConsistentMap; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 37 | import org.onosproject.store.service.DistributedSet; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 38 | import org.onosproject.store.service.Serializer; |
| 39 | import org.onosproject.store.service.StorageService; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 40 | import org.slf4j.Logger; |
| 41 | import org.slf4j.LoggerFactory; |
| 42 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 43 | import java.util.List; |
| 44 | |
| 45 | import static com.google.common.base.Preconditions.checkNotNull; |
| 46 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 47 | /** |
| 48 | * Manages the pool of available labels to devices, links and tunnels. |
| 49 | */ |
| 50 | @Component(immediate = true) |
| 51 | @Service |
| 52 | public class DistributedPceStore implements PceStore { |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 53 | private static final String PATH_INFO_NULL = "Path Info cannot be null"; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 54 | private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null"; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 55 | private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null"; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 56 | |
| 57 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 58 | |
| 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 60 | protected StorageService storageService; |
| 61 | |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 62 | //Mapping tunnel name with Disjoint paths |
| 63 | private ConsistentMap<String, List<TunnelId>> tunnelNameDisjoinTunnelIdInfo; |
| 64 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 65 | // List of Failed path info |
| 66 | private DistributedSet<PcePathInfo> failedPathSet; |
| 67 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 68 | // Maintains tunnel name mapped to explicit path info |
| 69 | private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap; |
| 70 | |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 71 | private static final Serializer SERIALIZER = Serializer |
| 72 | .using(new KryoNamespace.Builder().register(KryoNamespaces.API) |
| 73 | .register(PcePathInfo.class) |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 74 | .register(ExplicitPathInfo.class) |
| 75 | .register(ExplicitPathInfo.Type.class) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 76 | .register(CostConstraint.class) |
| 77 | .register(CostConstraint.Type.class) |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 78 | .register(PceBandwidthConstraint.class) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 79 | .register(SharedBandwidthConstraint.class) |
| 80 | .register(CapabilityConstraint.class) |
| 81 | .register(CapabilityConstraint.CapabilityType.class) |
| 82 | .register(LspType.class) |
| 83 | .build()); |
Avantika-Huawei | 28b5375 | 2016-06-23 17:04:49 +0530 | [diff] [blame] | 84 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 85 | @Activate |
| 86 | protected void activate() { |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 87 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 88 | failedPathSet = storageService.<PcePathInfo>setBuilder() |
| 89 | .withName("failed-path-info") |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 90 | .withSerializer(SERIALIZER) |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 91 | .build() |
| 92 | .asDistributedSet(); |
| 93 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 94 | 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 104 | 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 113 | log.info("Started"); |
| 114 | } |
| 115 | |
| 116 | @Deactivate |
| 117 | protected void deactivate() { |
| 118 | log.info("Stopped"); |
| 119 | } |
| 120 | |
| 121 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 122 | public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) { |
| 123 | checkNotNull(failedPathInfo, PATH_INFO_NULL); |
| 124 | return failedPathSet.contains(failedPathInfo); |
| 125 | } |
| 126 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 127 | |
| 128 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 129 | public int getFailedPathInfoCount() { |
| 130 | return failedPathSet.size(); |
| 131 | } |
| 132 | |
| 133 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 134 | public Iterable<PcePathInfo> getFailedPathInfos() { |
| 135 | return ImmutableSet.copyOf(failedPathSet); |
| 136 | } |
| 137 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 138 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 139 | |
| 140 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 141 | public void addFailedPathInfo(PcePathInfo failedPathInfo) { |
| 142 | checkNotNull(failedPathInfo, PATH_INFO_NULL); |
| 143 | failedPathSet.add(failedPathInfo); |
| 144 | } |
| 145 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 146 | |
| 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 B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 157 | |
| 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 174 | /* @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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 221 | } |