Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 25 | import org.onlab.util.KryoNamespace; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 26 | import org.onosproject.pce.pceservice.ExplicitPathInfo; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame^] | 27 | import org.onosproject.pce.pceservice.LspType; |
Priyanka B | cdf9b10 | 2016-06-07 20:01:38 +0530 | [diff] [blame] | 28 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 29 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame^] | 30 | import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint; |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 31 | import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 32 | import org.onosproject.pce.pcestore.api.PceStore; |
| 33 | import org.onosproject.store.serializers.KryoNamespaces; |
| 34 | import org.onosproject.store.service.ConsistentMap; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 35 | import org.onosproject.store.service.DistributedSet; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 36 | import org.onosproject.store.service.Serializer; |
| 37 | import org.onosproject.store.service.StorageService; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 38 | import org.slf4j.Logger; |
| 39 | import org.slf4j.LoggerFactory; |
| 40 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame^] | 41 | import java.util.List; |
| 42 | |
| 43 | import static com.google.common.base.Preconditions.checkNotNull; |
| 44 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 45 | /** |
| 46 | * Manages the pool of available labels to devices, links and tunnels. |
| 47 | */ |
| 48 | @Component(immediate = true) |
| 49 | @Service |
| 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 | |
| 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 58 | protected StorageService storageService; |
| 59 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 60 | // List of Failed path info |
| 61 | private DistributedSet<PcePathInfo> failedPathSet; |
| 62 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 63 | // Maintains tunnel name mapped to explicit path info |
| 64 | private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap; |
| 65 | |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 66 | private static final Serializer SERIALIZER = Serializer |
| 67 | .using(new KryoNamespace.Builder().register(KryoNamespaces.API) |
| 68 | .register(PcePathInfo.class) |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 69 | .register(ExplicitPathInfo.class) |
| 70 | .register(ExplicitPathInfo.Type.class) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 71 | .register(CostConstraint.class) |
| 72 | .register(CostConstraint.Type.class) |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame^] | 73 | .register(PceBandwidthConstraint.class) |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 74 | .register(SharedBandwidthConstraint.class) |
| 75 | .register(CapabilityConstraint.class) |
| 76 | .register(CapabilityConstraint.CapabilityType.class) |
| 77 | .register(LspType.class) |
| 78 | .build()); |
Avantika-Huawei | 28b5375 | 2016-06-23 17:04:49 +0530 | [diff] [blame] | 79 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 80 | @Activate |
| 81 | protected void activate() { |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 82 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 83 | failedPathSet = storageService.<PcePathInfo>setBuilder() |
| 84 | .withName("failed-path-info") |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 85 | .withSerializer(SERIALIZER) |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 86 | .build() |
| 87 | .asDistributedSet(); |
| 88 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 89 | 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 99 | log.info("Started"); |
| 100 | } |
| 101 | |
| 102 | @Deactivate |
| 103 | protected void deactivate() { |
| 104 | log.info("Stopped"); |
| 105 | } |
| 106 | |
| 107 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 108 | public boolean existsFailedPathInfo(PcePathInfo failedPathInfo) { |
| 109 | checkNotNull(failedPathInfo, PATH_INFO_NULL); |
| 110 | return failedPathSet.contains(failedPathInfo); |
| 111 | } |
| 112 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 113 | |
| 114 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 115 | public int getFailedPathInfoCount() { |
| 116 | return failedPathSet.size(); |
| 117 | } |
| 118 | |
| 119 | @Override |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 120 | public Iterable<PcePathInfo> getFailedPathInfos() { |
| 121 | return ImmutableSet.copyOf(failedPathSet); |
| 122 | } |
| 123 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 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 void addFailedPathInfo(PcePathInfo failedPathInfo) { |
| 128 | checkNotNull(failedPathInfo, PATH_INFO_NULL); |
| 129 | failedPathSet.add(failedPathInfo); |
| 130 | } |
| 131 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 132 | |
| 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 B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 143 | |
| 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 160 | } |