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