Committed by
Mahesh Poojary Huawei
[ONOS-4164] PCE Store
Change-Id: I2caa918fae0bf635f98976b11ee8a717aba42aac
Showing
10 changed files
with
1193 additions
and
0 deletions
| 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 | + | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 19 | + | ||
| 20 | +import java.util.Objects; | ||
| 21 | + | ||
| 22 | +import org.onosproject.net.DeviceId; | ||
| 23 | +import org.onosproject.net.PortNumber; | ||
| 24 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 25 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * Local node details including IN and OUT labels as well as IN and OUT port details. | ||
| 29 | + */ | ||
| 30 | +public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo { | ||
| 31 | + | ||
| 32 | + private final DeviceId deviceId; | ||
| 33 | + | ||
| 34 | + private final LabelResourceId inLabelId; | ||
| 35 | + | ||
| 36 | + private final LabelResourceId outLabelId; | ||
| 37 | + | ||
| 38 | + private final PortNumber inPort; | ||
| 39 | + | ||
| 40 | + private final PortNumber outPort; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Initialization of member variables. | ||
| 44 | + * | ||
| 45 | + * @param deviceId device id | ||
| 46 | + * @param inLabelId in label id of a node | ||
| 47 | + * @param outLabelId out label id of a node | ||
| 48 | + * @param inPort input port | ||
| 49 | + * @param outPort remote port | ||
| 50 | + */ | ||
| 51 | + private DefaultLspLocalLabelInfo(DeviceId deviceId, | ||
| 52 | + LabelResourceId inLabelId, | ||
| 53 | + LabelResourceId outLabelId, | ||
| 54 | + PortNumber inPort, | ||
| 55 | + PortNumber outPort) { | ||
| 56 | + this.deviceId = deviceId; | ||
| 57 | + this.inLabelId = inLabelId; | ||
| 58 | + this.outLabelId = outLabelId; | ||
| 59 | + this.inPort = inPort; | ||
| 60 | + this.outPort = outPort; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Initialization of member variables for serialization. | ||
| 65 | + */ | ||
| 66 | + private DefaultLspLocalLabelInfo() { | ||
| 67 | + this.deviceId = null; | ||
| 68 | + this.inLabelId = null; | ||
| 69 | + this.outLabelId = null; | ||
| 70 | + this.inPort = null; | ||
| 71 | + this.outPort = null; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public DeviceId deviceId() { | ||
| 76 | + return deviceId; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public LabelResourceId inLabelId() { | ||
| 81 | + return inLabelId; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public LabelResourceId outLabelId() { | ||
| 86 | + return outLabelId; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public PortNumber inPort() { | ||
| 91 | + return inPort; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public PortNumber outPort() { | ||
| 96 | + return outPort; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Override | ||
| 100 | + public int hashCode() { | ||
| 101 | + return Objects.hash(deviceId, inLabelId, outLabelId, inPort, outPort); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + @Override | ||
| 105 | + public boolean equals(Object obj) { | ||
| 106 | + if (this == obj) { | ||
| 107 | + return true; | ||
| 108 | + } | ||
| 109 | + if (obj instanceof LspLocalLabelInfo) { | ||
| 110 | + final DefaultLspLocalLabelInfo other = (DefaultLspLocalLabelInfo) obj; | ||
| 111 | + return Objects.equals(this.deviceId, other.deviceId) && | ||
| 112 | + Objects.equals(this.inLabelId, other.inLabelId) && | ||
| 113 | + Objects.equals(this.outLabelId, other.outLabelId) && | ||
| 114 | + Objects.equals(this.inPort, other.inPort) && | ||
| 115 | + Objects.equals(this.outPort, other.outPort); | ||
| 116 | + } | ||
| 117 | + return false; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Override | ||
| 121 | + public String toString() { | ||
| 122 | + return MoreObjects.toStringHelper(getClass()) | ||
| 123 | + .omitNullValues() | ||
| 124 | + .add("DeviceId", deviceId.toString()) | ||
| 125 | + .add("InLabelId", inLabelId.toString()) | ||
| 126 | + .add("OutLabelId", outLabelId.toString()) | ||
| 127 | + .add("InPort", inPort.toString()) | ||
| 128 | + .add("OutPort", outPort.toString()) | ||
| 129 | + .toString(); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * Creates and returns a new builder instance that clones an existing object. | ||
| 134 | + * | ||
| 135 | + * @param deviceLabelInfo device label information | ||
| 136 | + * @return new builder | ||
| 137 | + */ | ||
| 138 | + public static Builder builder(LspLocalLabelInfo deviceLabelInfo) { | ||
| 139 | + return new Builder(deviceLabelInfo); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * Creates and returns a new builder instance. | ||
| 144 | + * | ||
| 145 | + * @return new builder | ||
| 146 | + */ | ||
| 147 | + public static Builder builder() { | ||
| 148 | + return new Builder(); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + /** | ||
| 152 | + * Builder. | ||
| 153 | + */ | ||
| 154 | + public static final class Builder implements LspLocalLabelInfo.Builder { | ||
| 155 | + | ||
| 156 | + private DeviceId deviceId; | ||
| 157 | + | ||
| 158 | + private LabelResourceId inLabelId; | ||
| 159 | + | ||
| 160 | + private LabelResourceId outLabelId; | ||
| 161 | + | ||
| 162 | + private PortNumber inPort; | ||
| 163 | + | ||
| 164 | + private PortNumber outPort; | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * Constructs default builder. | ||
| 168 | + */ | ||
| 169 | + private Builder() { | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * Initializes member variables with existing object. | ||
| 174 | + */ | ||
| 175 | + private Builder(LspLocalLabelInfo deviceLabelInfo) { | ||
| 176 | + this.deviceId = deviceLabelInfo.deviceId(); | ||
| 177 | + this.inLabelId = deviceLabelInfo.inLabelId(); | ||
| 178 | + this.outLabelId = deviceLabelInfo.outLabelId(); | ||
| 179 | + this.inPort = deviceLabelInfo.inPort(); | ||
| 180 | + this.outPort = deviceLabelInfo.outPort(); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + @Override | ||
| 184 | + public Builder deviceId(DeviceId id) { | ||
| 185 | + this.deviceId = id; | ||
| 186 | + return this; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + @Override | ||
| 190 | + public Builder inLabelId(LabelResourceId id) { | ||
| 191 | + this.inLabelId = id; | ||
| 192 | + return this; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + @Override | ||
| 196 | + public Builder outLabelId(LabelResourceId id) { | ||
| 197 | + this.outLabelId = id; | ||
| 198 | + return this; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + @Override | ||
| 202 | + public Builder inPort(PortNumber port) { | ||
| 203 | + this.inPort = port; | ||
| 204 | + return this; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + @Override | ||
| 208 | + public Builder outPort(PortNumber port) { | ||
| 209 | + this.outPort = port; | ||
| 210 | + return this; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + @Override | ||
| 214 | + public LspLocalLabelInfo build() { | ||
| 215 | + return new DefaultLspLocalLabelInfo(deviceId, inLabelId, outLabelId, inPort, outPort); | ||
| 216 | + } | ||
| 217 | + } | ||
| 218 | +} |
| 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 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.Map; | ||
| 22 | +import java.util.stream.Collectors; | ||
| 23 | + | ||
| 24 | +import org.apache.felix.scr.annotations.Activate; | ||
| 25 | +import org.apache.felix.scr.annotations.Component; | ||
| 26 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 27 | +import org.apache.felix.scr.annotations.Reference; | ||
| 28 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 29 | +import org.apache.felix.scr.annotations.Service; | ||
| 30 | + | ||
| 31 | +import org.onlab.util.KryoNamespace; | ||
| 32 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 33 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 34 | +import org.onosproject.net.DeviceId; | ||
| 35 | +import org.onosproject.net.Link; | ||
| 36 | +import org.onosproject.net.resource.ResourceConsumer; | ||
| 37 | +import org.onosproject.pce.pceservice.TunnelConsumerId; | ||
| 38 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 39 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
| 40 | +import org.onosproject.store.serializers.KryoNamespaces; | ||
| 41 | +import org.onosproject.store.service.ConsistentMap; | ||
| 42 | +import org.onosproject.store.service.Serializer; | ||
| 43 | +import org.onosproject.store.service.StorageService; | ||
| 44 | + | ||
| 45 | +import org.slf4j.Logger; | ||
| 46 | +import org.slf4j.LoggerFactory; | ||
| 47 | + | ||
| 48 | +/** | ||
| 49 | + * Manages the pool of available labels to devices, links and tunnels. | ||
| 50 | + */ | ||
| 51 | +@Component(immediate = true) | ||
| 52 | +@Service | ||
| 53 | +public class DistributedPceStore implements PceStore { | ||
| 54 | + | ||
| 55 | + private static final String DEVICE_ID_NULL = "Device ID cannot be null"; | ||
| 56 | + private static final String LINK_NULL = "LINK cannot be null"; | ||
| 57 | + private static final String TUNNEL_ID_NULL = "Tunnel ID cannot be null"; | ||
| 58 | + private static final String LABEL_RESOURCE_ID_NULL = "Label Resource ID cannot be null"; | ||
| 59 | + private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null"; | ||
| 60 | + private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label info cannot be null"; | ||
| 61 | + private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null"; | ||
| 62 | + | ||
| 63 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 64 | + | ||
| 65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 66 | + protected StorageService storageService; | ||
| 67 | + | ||
| 68 | + // Mapping device with global node label | ||
| 69 | + private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap; | ||
| 70 | + | ||
| 71 | + // Mapping link with adjacency label | ||
| 72 | + private ConsistentMap<Link, LabelResourceId> adjLabelMap; | ||
| 73 | + | ||
| 74 | + // Mapping tunnel with device local info with tunnel consumer id | ||
| 75 | + private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap; | ||
| 76 | + | ||
| 77 | + @Activate | ||
| 78 | + protected void activate() { | ||
| 79 | + globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder() | ||
| 80 | + .withName("onos-pce-globalnodelabelmap") | ||
| 81 | + .withSerializer(Serializer.using( | ||
| 82 | + new KryoNamespace.Builder() | ||
| 83 | + .register(KryoNamespaces.API) | ||
| 84 | + .register(LabelResourceId.class) | ||
| 85 | + .build())) | ||
| 86 | + .build(); | ||
| 87 | + | ||
| 88 | + adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder() | ||
| 89 | + .withName("onos-pce-adjlabelmap") | ||
| 90 | + .withSerializer(Serializer.using( | ||
| 91 | + new KryoNamespace.Builder() | ||
| 92 | + .register(KryoNamespaces.API) | ||
| 93 | + .register(Link.class, | ||
| 94 | + LabelResourceId.class) | ||
| 95 | + .build())) | ||
| 96 | + .build(); | ||
| 97 | + | ||
| 98 | + tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder() | ||
| 99 | + .withName("onos-pce-tunnelinfomap") | ||
| 100 | + .withSerializer(Serializer.using( | ||
| 101 | + new KryoNamespace.Builder() | ||
| 102 | + .register(KryoNamespaces.API) | ||
| 103 | + .register(TunnelId.class, | ||
| 104 | + PceccTunnelInfo.class, | ||
| 105 | + DefaultLspLocalLabelInfo.class, | ||
| 106 | + TunnelConsumerId.class, | ||
| 107 | + LabelResourceId.class) | ||
| 108 | + .build())) | ||
| 109 | + .build(); | ||
| 110 | + | ||
| 111 | + log.info("Started"); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Deactivate | ||
| 115 | + protected void deactivate() { | ||
| 116 | + log.info("Stopped"); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public boolean existsGlobalNodeLabel(DeviceId id) { | ||
| 121 | + checkNotNull(id, DEVICE_ID_NULL); | ||
| 122 | + return globalNodeLabelMap.containsKey(id); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public boolean existsAdjLabel(Link link) { | ||
| 127 | + checkNotNull(link, LINK_NULL); | ||
| 128 | + return adjLabelMap.containsKey(link); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public boolean existsTunnelInfo(TunnelId tunnelId) { | ||
| 133 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 134 | + return tunnelInfoMap.containsKey(tunnelId); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public int getGlobalNodeLabelCount() { | ||
| 139 | + return globalNodeLabelMap.size(); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + @Override | ||
| 143 | + public int getAdjLabelCount() { | ||
| 144 | + return adjLabelMap.size(); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public int getTunnelInfoCount() { | ||
| 149 | + return tunnelInfoMap.size(); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() { | ||
| 154 | + return globalNodeLabelMap.entrySet().stream() | ||
| 155 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value())); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + @Override | ||
| 159 | + public Map<Link, LabelResourceId> getAdjLabels() { | ||
| 160 | + return adjLabelMap.entrySet().stream() | ||
| 161 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value())); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + @Override | ||
| 165 | + public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() { | ||
| 166 | + return tunnelInfoMap.entrySet().stream() | ||
| 167 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value())); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public LabelResourceId getGlobalNodeLabel(DeviceId id) { | ||
| 172 | + checkNotNull(id, DEVICE_ID_NULL); | ||
| 173 | + return globalNodeLabelMap.get(id).value(); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + @Override | ||
| 177 | + public LabelResourceId getAdjLabel(Link link) { | ||
| 178 | + checkNotNull(link, LINK_NULL); | ||
| 179 | + return adjLabelMap.get(link).value(); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + @Override | ||
| 183 | + public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) { | ||
| 184 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 185 | + return tunnelInfoMap.get(tunnelId).value(); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + @Override | ||
| 189 | + public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) { | ||
| 190 | + checkNotNull(deviceId, DEVICE_ID_NULL); | ||
| 191 | + checkNotNull(labelId, LABEL_RESOURCE_ID_NULL); | ||
| 192 | + | ||
| 193 | + globalNodeLabelMap.put(deviceId, labelId); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + @Override | ||
| 197 | + public void addAdjLabel(Link link, LabelResourceId labelId) { | ||
| 198 | + checkNotNull(link, LINK_NULL); | ||
| 199 | + checkNotNull(labelId, LABEL_RESOURCE_ID_NULL); | ||
| 200 | + | ||
| 201 | + adjLabelMap.put(link, labelId); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + @Override | ||
| 205 | + public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) { | ||
| 206 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 207 | + checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL); | ||
| 208 | + | ||
| 209 | + tunnelInfoMap.put(tunnelId, pceccTunnelInfo); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + @Override | ||
| 213 | + public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) { | ||
| 214 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 215 | + checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL); | ||
| 216 | + | ||
| 217 | + if (!tunnelInfoMap.containsKey((tunnelId))) { | ||
| 218 | + log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString()); | ||
| 219 | + return false; | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value(); | ||
| 223 | + tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList); | ||
| 224 | + tunnelInfoMap.put(tunnelId, tunnelInfo); | ||
| 225 | + | ||
| 226 | + return true; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + @Override | ||
| 230 | + public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) { | ||
| 231 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 232 | + checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL); | ||
| 233 | + | ||
| 234 | + if (!tunnelInfoMap.containsKey((tunnelId))) { | ||
| 235 | + log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString()); | ||
| 236 | + return false; | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value(); | ||
| 240 | + tunnelInfo.tunnelConsumerId(tunnelConsumerId); | ||
| 241 | + tunnelInfoMap.put(tunnelId, tunnelInfo); | ||
| 242 | + | ||
| 243 | + return true; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + @Override | ||
| 247 | + public boolean removeGlobalNodeLabel(DeviceId id) { | ||
| 248 | + checkNotNull(id, DEVICE_ID_NULL); | ||
| 249 | + | ||
| 250 | + if (globalNodeLabelMap.remove(id) == null) { | ||
| 251 | + log.error("SR-TE node label deletion for device {} has failed.", id.toString()); | ||
| 252 | + return false; | ||
| 253 | + } | ||
| 254 | + return true; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + @Override | ||
| 258 | + public boolean removeAdjLabel(Link link) { | ||
| 259 | + checkNotNull(link, LINK_NULL); | ||
| 260 | + | ||
| 261 | + if (adjLabelMap.remove(link) == null) { | ||
| 262 | + log.error("Adjacency label deletion for link {} hash failed.", link.toString()); | ||
| 263 | + return false; | ||
| 264 | + } | ||
| 265 | + return true; | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + @Override | ||
| 269 | + public boolean removeTunnelInfo(TunnelId tunnelId) { | ||
| 270 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 271 | + | ||
| 272 | + if (tunnelInfoMap.remove(tunnelId) == null) { | ||
| 273 | + log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString()); | ||
| 274 | + return false; | ||
| 275 | + } | ||
| 276 | + return true; | ||
| 277 | + } | ||
| 278 | +} |
| 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 | + | ||
| 18 | +import java.util.List; | ||
| 19 | +import com.google.common.base.MoreObjects; | ||
| 20 | + | ||
| 21 | +import java.util.Objects; | ||
| 22 | + | ||
| 23 | +import org.onosproject.net.resource.ResourceConsumer; | ||
| 24 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * PCECC tunnel information is used to store | ||
| 28 | + * list of links label information of a path containing IN, OUT label and destination port of a link | ||
| 29 | + * to release label allocation in devices. | ||
| 30 | + * Also storing resource consumer id to release bandwdith of a tunnel. | ||
| 31 | + * The first entry is created with TunnelId and resource consumer id, | ||
| 32 | + * later this entry may be updated to store label information on basic PCECC case. | ||
| 33 | + */ | ||
| 34 | +public final class PceccTunnelInfo { | ||
| 35 | + | ||
| 36 | + private List<LspLocalLabelInfo> lspLocalLabelInfoList; | ||
| 37 | + | ||
| 38 | + private ResourceConsumer tunnelConsumerId; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * Initialization of member variables. | ||
| 42 | + * | ||
| 43 | + * @param lspLocalLabelInfoList list of devices local label info | ||
| 44 | + * @param tunnelConsumerId tunnel consumer id | ||
| 45 | + */ | ||
| 46 | + public PceccTunnelInfo(List<LspLocalLabelInfo> lspLocalLabelInfoList, | ||
| 47 | + ResourceConsumer tunnelConsumerId) { | ||
| 48 | + this.lspLocalLabelInfoList = lspLocalLabelInfoList; | ||
| 49 | + this.tunnelConsumerId = tunnelConsumerId; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Initialization for serialization. | ||
| 54 | + */ | ||
| 55 | + public PceccTunnelInfo() { | ||
| 56 | + this.lspLocalLabelInfoList = null; | ||
| 57 | + this.tunnelConsumerId = null; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Retrieves list of devices local label info. | ||
| 62 | + * | ||
| 63 | + * @return list of devices local label info | ||
| 64 | + */ | ||
| 65 | + public List<LspLocalLabelInfo> lspLocalLabelInfoList() { | ||
| 66 | + return this.lspLocalLabelInfoList; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * Retrieves tunnel consumer id. | ||
| 71 | + * | ||
| 72 | + * @return tunnel consumer id | ||
| 73 | + */ | ||
| 74 | + public ResourceConsumer tunnelConsumerId() { | ||
| 75 | + return this.tunnelConsumerId; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Sets list of local label info of a path. | ||
| 80 | + * | ||
| 81 | + * @param lspLocalLabelInfoList list of devices local label info | ||
| 82 | + */ | ||
| 83 | + public void lspLocalLabelInfoList(List<LspLocalLabelInfo> lspLocalLabelInfoList) { | ||
| 84 | + this.lspLocalLabelInfoList = lspLocalLabelInfoList; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Sets tunnel consumer id. | ||
| 89 | + * | ||
| 90 | + * @param id tunnel consumer id | ||
| 91 | + */ | ||
| 92 | + public void tunnelConsumerId(ResourceConsumer id) { | ||
| 93 | + this.tunnelConsumerId = id; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public int hashCode() { | ||
| 98 | + return Objects.hash(lspLocalLabelInfoList, tunnelConsumerId); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public boolean equals(Object obj) { | ||
| 103 | + if (this == obj) { | ||
| 104 | + return true; | ||
| 105 | + } | ||
| 106 | + if (obj instanceof PceccTunnelInfo) { | ||
| 107 | + final PceccTunnelInfo other = (PceccTunnelInfo) obj; | ||
| 108 | + return Objects.equals(this.lspLocalLabelInfoList, other.lspLocalLabelInfoList) && | ||
| 109 | + Objects.equals(this.tunnelConsumerId, other.tunnelConsumerId); | ||
| 110 | + } | ||
| 111 | + return false; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public String toString() { | ||
| 116 | + return MoreObjects.toStringHelper(getClass()) | ||
| 117 | + .omitNullValues() | ||
| 118 | + .add("DeviceLabelInfoList", lspLocalLabelInfoList.toString()) | ||
| 119 | + .add("TunnelConsumerId", tunnelConsumerId.toString()) | ||
| 120 | + .toString(); | ||
| 121 | + } | ||
| 122 | +} |
| 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.api; | ||
| 17 | + | ||
| 18 | +import org.onosproject.net.DeviceId; | ||
| 19 | +import org.onosproject.net.PortNumber; | ||
| 20 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Abstraction of an entity providing LSP local label information. | ||
| 24 | + */ | ||
| 25 | +public interface LspLocalLabelInfo { | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * Returns device id. | ||
| 29 | + * | ||
| 30 | + * @return device id | ||
| 31 | + */ | ||
| 32 | + DeviceId deviceId(); | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Returns in label id of a device. | ||
| 36 | + * | ||
| 37 | + * @return in label resource id | ||
| 38 | + */ | ||
| 39 | + LabelResourceId inLabelId(); | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Returns out label id of a device. | ||
| 43 | + * | ||
| 44 | + * @return node out label resource id | ||
| 45 | + */ | ||
| 46 | + LabelResourceId outLabelId(); | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Returns in port of an incoming label. | ||
| 50 | + * | ||
| 51 | + * @return in port | ||
| 52 | + */ | ||
| 53 | + PortNumber inPort(); | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * Returns next hop of an outgoing label. | ||
| 57 | + * | ||
| 58 | + * @return out port | ||
| 59 | + */ | ||
| 60 | + PortNumber outPort(); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * LspLocalLabelInfo Builder. | ||
| 64 | + */ | ||
| 65 | + interface Builder { | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Returns builder object of a device id. | ||
| 69 | + * | ||
| 70 | + * @param id device id | ||
| 71 | + * @return builder object of device id | ||
| 72 | + */ | ||
| 73 | + Builder deviceId(DeviceId id); | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * Returns builder object of in label. | ||
| 77 | + * | ||
| 78 | + * @param id in label id | ||
| 79 | + * @return builder object of in label id | ||
| 80 | + */ | ||
| 81 | + Builder inLabelId(LabelResourceId id); | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * Returns builder object of out label. | ||
| 85 | + * | ||
| 86 | + * @param id out label id | ||
| 87 | + * @return builder object of out label id | ||
| 88 | + */ | ||
| 89 | + Builder outLabelId(LabelResourceId id); | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * Returns builder object of in port of an incoming label. | ||
| 93 | + * | ||
| 94 | + * @param port in port | ||
| 95 | + * @return builder object of in port | ||
| 96 | + */ | ||
| 97 | + Builder inPort(PortNumber port); | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * Returns builder object of next hop of an outgoing label. | ||
| 101 | + * | ||
| 102 | + * @param port out port | ||
| 103 | + * @return builder object of out port | ||
| 104 | + */ | ||
| 105 | + Builder outPort(PortNumber port); | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * Builds object of device local label info. | ||
| 109 | + * | ||
| 110 | + * @return object of device local label info. | ||
| 111 | + */ | ||
| 112 | + LspLocalLabelInfo build(); | ||
| 113 | + } | ||
| 114 | +} |
| 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.api; | ||
| 17 | + | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 20 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 21 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 22 | +import org.onosproject.net.DeviceId; | ||
| 23 | +import org.onosproject.net.Link; | ||
| 24 | +import org.onosproject.net.resource.ResourceConsumer; | ||
| 25 | +import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 26 | + | ||
| 27 | +import java.util.Map; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Abstraction of an entity providing pool of available labels to devices, links and tunnels. | ||
| 31 | + */ | ||
| 32 | +public interface PceStore { | ||
| 33 | + /** | ||
| 34 | + * Checks whether device id is present in global node label store. | ||
| 35 | + * | ||
| 36 | + * @param id device id | ||
| 37 | + * @return success of failure | ||
| 38 | + */ | ||
| 39 | + boolean existsGlobalNodeLabel(DeviceId id); | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Checks whether link is present in adjacency label store. | ||
| 43 | + * | ||
| 44 | + * @param link link between devices | ||
| 45 | + * @return success of failure | ||
| 46 | + */ | ||
| 47 | + boolean existsAdjLabel(Link link); | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Checks whether tunnel id is present in tunnel info store. | ||
| 51 | + * | ||
| 52 | + * @param tunnelId tunnel id | ||
| 53 | + * @return success of failure | ||
| 54 | + */ | ||
| 55 | + boolean existsTunnelInfo(TunnelId tunnelId); | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Retrieves the node label count. | ||
| 59 | + * | ||
| 60 | + * @return node label count | ||
| 61 | + */ | ||
| 62 | + int getGlobalNodeLabelCount(); | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * Retrieves the adjacency label count. | ||
| 66 | + * | ||
| 67 | + * @return adjacency label count | ||
| 68 | + */ | ||
| 69 | + int getAdjLabelCount(); | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * Retrieves the tunnel info count. | ||
| 73 | + * | ||
| 74 | + * @return tunnel info count | ||
| 75 | + */ | ||
| 76 | + int getTunnelInfoCount(); | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Retrieves device id and label pairs collection from global node label store. | ||
| 80 | + * | ||
| 81 | + * @return collection of device id and label pairs | ||
| 82 | + */ | ||
| 83 | + Map<DeviceId, LabelResourceId> getGlobalNodeLabels(); | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Retrieves link and label pairs collection from adjacency label store. | ||
| 87 | + * | ||
| 88 | + * @return collection of link and label pairs | ||
| 89 | + */ | ||
| 90 | + Map<Link, LabelResourceId> getAdjLabels(); | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store. | ||
| 94 | + * | ||
| 95 | + * @return collection of tunnel id and pcecc tunnel info pairs | ||
| 96 | + */ | ||
| 97 | + Map<TunnelId, PceccTunnelInfo> getTunnelInfos(); | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * Retrieves node label for specified device id. | ||
| 101 | + * | ||
| 102 | + * @param id device id | ||
| 103 | + * @return node label | ||
| 104 | + */ | ||
| 105 | + LabelResourceId getGlobalNodeLabel(DeviceId id); | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * Retrieves adjacency label for specified link. | ||
| 109 | + * | ||
| 110 | + * @param link between devices | ||
| 111 | + * @return adjacency label | ||
| 112 | + */ | ||
| 113 | + LabelResourceId getAdjLabel(Link link); | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * Retrieves local label info with tunnel consumer id from tunnel info store. | ||
| 117 | + * | ||
| 118 | + * @param tunnelId tunnel id | ||
| 119 | + * @return pcecc tunnel info | ||
| 120 | + */ | ||
| 121 | + PceccTunnelInfo getTunnelInfo(TunnelId tunnelId); | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Stores node label into global node label store. | ||
| 125 | + * | ||
| 126 | + * @param deviceId device id | ||
| 127 | + * @param labelId node label id | ||
| 128 | + */ | ||
| 129 | + void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId); | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * Stores adjacency label into adjacency label store. | ||
| 133 | + * | ||
| 134 | + * @param link link between nodes | ||
| 135 | + * @param labelId link label id | ||
| 136 | + */ | ||
| 137 | + void addAdjLabel(Link link, LabelResourceId labelId); | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id. | ||
| 141 | + * | ||
| 142 | + * @param tunnelId tunnel id | ||
| 143 | + * @param pceccTunnelInfo local label info | ||
| 144 | + */ | ||
| 145 | + void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo); | ||
| 146 | + | ||
| 147 | + /** | ||
| 148 | + * Updates local label info. The first entry is created with TunnelId and TunnelConsumerId. | ||
| 149 | + * Later this entry may be updated to store label information if it is basic PCECC case. | ||
| 150 | + * | ||
| 151 | + * @param tunnelId tunnel id | ||
| 152 | + * @param lspLocalLabelInfoList list of local labels | ||
| 153 | + * @return success or failure | ||
| 154 | + */ | ||
| 155 | + boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList); | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Updates tunnel info map with tunnel consumer id. | ||
| 159 | + * | ||
| 160 | + * @param tunnelId tunnel id | ||
| 161 | + * @param tunnelConsumerId tunnel consumer id | ||
| 162 | + * @return success or failure | ||
| 163 | + */ | ||
| 164 | + boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId); | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * Removes device label from global node label store for specified device id. | ||
| 168 | + * | ||
| 169 | + * @param id device id | ||
| 170 | + * @return success or failure | ||
| 171 | + */ | ||
| 172 | + boolean removeGlobalNodeLabel(DeviceId id); | ||
| 173 | + | ||
| 174 | + /** | ||
| 175 | + * Removes adjacency label from adjacency label store for specified link information. | ||
| 176 | + * | ||
| 177 | + * @param link between nodes | ||
| 178 | + * @return success or failure | ||
| 179 | + */ | ||
| 180 | + boolean removeAdjLabel(Link link); | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id. | ||
| 184 | + * | ||
| 185 | + * @param tunnelId tunnel id | ||
| 186 | + * @return success or failure | ||
| 187 | + */ | ||
| 188 | + boolean removeTunnelInfo(TunnelId tunnelId); | ||
| 189 | +} |
| 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 | + | ||
| 17 | +/** | ||
| 18 | + * PCE store service API. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.pce.pcestore.api; |
| 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 | + | ||
| 17 | +/** | ||
| 18 | + * PCE store application. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.pce.pcestore; |
apps/pce/app/src/test/java/org/onosproject/pce/pcestore/DefaultLspLocalLabelInfoTest.java
0 → 100644
| 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 | + | ||
| 18 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 19 | +import static org.hamcrest.Matchers.is; | ||
| 20 | + | ||
| 21 | +import com.google.common.testing.EqualsTester; | ||
| 22 | + | ||
| 23 | +import org.junit.Test; | ||
| 24 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 25 | +import org.onosproject.net.DeviceId; | ||
| 26 | +import org.onosproject.net.PortNumber; | ||
| 27 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Unit tests for DefaultLspLocalLabelInfo class. | ||
| 31 | + */ | ||
| 32 | +public class DefaultLspLocalLabelInfoTest { | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Checks the operation of equals() methods. | ||
| 36 | + */ | ||
| 37 | + @Test | ||
| 38 | + public void testEquals() { | ||
| 39 | + // create same two objects. | ||
| 40 | + DeviceId deviceId1 = DeviceId.deviceId("foo"); | ||
| 41 | + LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1); | ||
| 42 | + LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2); | ||
| 43 | + PortNumber inPort1 = PortNumber.portNumber(5122); | ||
| 44 | + PortNumber outPort1 = PortNumber.portNumber(5123); | ||
| 45 | + | ||
| 46 | + LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder() | ||
| 47 | + .deviceId(deviceId1) | ||
| 48 | + .inLabelId(inLabelId1) | ||
| 49 | + .outLabelId(outLabelId1) | ||
| 50 | + .inPort(inPort1) | ||
| 51 | + .outPort(outPort1) | ||
| 52 | + .build(); | ||
| 53 | + | ||
| 54 | + // create same object as above object | ||
| 55 | + LspLocalLabelInfo sameLocalLabel1 = DefaultLspLocalLabelInfo.builder() | ||
| 56 | + .deviceId(deviceId1) | ||
| 57 | + .inLabelId(inLabelId1) | ||
| 58 | + .outLabelId(outLabelId1) | ||
| 59 | + .inPort(inPort1) | ||
| 60 | + .outPort(outPort1) | ||
| 61 | + .build(); | ||
| 62 | + | ||
| 63 | + // Create different object. | ||
| 64 | + DeviceId deviceId2 = DeviceId.deviceId("goo"); | ||
| 65 | + LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3); | ||
| 66 | + LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4); | ||
| 67 | + PortNumber inPort2 = PortNumber.portNumber(5124); | ||
| 68 | + PortNumber outPort2 = PortNumber.portNumber(5125); | ||
| 69 | + | ||
| 70 | + LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder() | ||
| 71 | + .deviceId(deviceId2) | ||
| 72 | + .inLabelId(inLabelId2) | ||
| 73 | + .outLabelId(outLabelId2) | ||
| 74 | + .inPort(inPort2) | ||
| 75 | + .outPort(outPort2) | ||
| 76 | + .build(); | ||
| 77 | + | ||
| 78 | + new EqualsTester().addEqualityGroup(lspLocalLabel1, sameLocalLabel1) | ||
| 79 | + .addEqualityGroup(lspLocalLabel2) | ||
| 80 | + .testEquals(); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * Checks the construction of a DefaultLspLocalLabelInfo object. | ||
| 85 | + */ | ||
| 86 | + @Test | ||
| 87 | + public void testConstruction() { | ||
| 88 | + DeviceId deviceId = DeviceId.deviceId("foo"); | ||
| 89 | + LabelResourceId inLabelId = LabelResourceId.labelResourceId(1); | ||
| 90 | + LabelResourceId outLabelId = LabelResourceId.labelResourceId(2); | ||
| 91 | + PortNumber inPort = PortNumber.portNumber(5122); | ||
| 92 | + PortNumber outPort = PortNumber.portNumber(5123); | ||
| 93 | + | ||
| 94 | + LspLocalLabelInfo lspLocalLabel = DefaultLspLocalLabelInfo.builder() | ||
| 95 | + .deviceId(deviceId) | ||
| 96 | + .inLabelId(inLabelId) | ||
| 97 | + .outLabelId(outLabelId) | ||
| 98 | + .inPort(inPort) | ||
| 99 | + .outPort(outPort) | ||
| 100 | + .build(); | ||
| 101 | + | ||
| 102 | + assertThat(deviceId, is(lspLocalLabel.deviceId())); | ||
| 103 | + assertThat(inLabelId, is(lspLocalLabel.inLabelId())); | ||
| 104 | + assertThat(outLabelId, is(lspLocalLabel.outLabelId())); | ||
| 105 | + assertThat(inPort, is(lspLocalLabel.inPort())); | ||
| 106 | + assertThat(outPort, is(lspLocalLabel.outPort())); | ||
| 107 | + } | ||
| 108 | +} |
This diff is collapsed. Click to expand it.
| 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 | + | ||
| 18 | +import java.util.LinkedList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 22 | +import static org.hamcrest.Matchers.is; | ||
| 23 | + | ||
| 24 | +import com.google.common.testing.EqualsTester; | ||
| 25 | + | ||
| 26 | +import org.junit.Test; | ||
| 27 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 28 | +import org.onosproject.net.DeviceId; | ||
| 29 | +import org.onosproject.net.PortNumber; | ||
| 30 | +import org.onosproject.net.resource.ResourceConsumer; | ||
| 31 | +import org.onosproject.pce.pceservice.TunnelConsumerId; | ||
| 32 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 33 | + | ||
| 34 | +/** | ||
| 35 | + * Unit tests for PceccTunnelInfo class. | ||
| 36 | + */ | ||
| 37 | +public class PceccTunnelInfoTest { | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * Checks the operation of equals() methods. | ||
| 41 | + */ | ||
| 42 | + @Test | ||
| 43 | + public void testEquals() { | ||
| 44 | + // create same two objects. | ||
| 45 | + List<LspLocalLabelInfo> lspLocalLabelList1 = new LinkedList<>(); | ||
| 46 | + ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10); | ||
| 47 | + | ||
| 48 | + // create object of DefaultLspLocalLabelInfo | ||
| 49 | + DeviceId deviceId1 = DeviceId.deviceId("foo"); | ||
| 50 | + LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1); | ||
| 51 | + LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2); | ||
| 52 | + PortNumber inPort1 = PortNumber.portNumber(5122); | ||
| 53 | + PortNumber outPort1 = PortNumber.portNumber(5123); | ||
| 54 | + | ||
| 55 | + LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder() | ||
| 56 | + .deviceId(deviceId1) | ||
| 57 | + .inLabelId(inLabelId1) | ||
| 58 | + .outLabelId(outLabelId1) | ||
| 59 | + .inPort(inPort1) | ||
| 60 | + .outPort(outPort1) | ||
| 61 | + .build(); | ||
| 62 | + lspLocalLabelList1.add(lspLocalLabel1); | ||
| 63 | + | ||
| 64 | + PceccTunnelInfo pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1); | ||
| 65 | + | ||
| 66 | + // create same as above object | ||
| 67 | + PceccTunnelInfo samePceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1); | ||
| 68 | + | ||
| 69 | + // Create different object. | ||
| 70 | + List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>(); | ||
| 71 | + ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20); | ||
| 72 | + | ||
| 73 | + // create object of DefaultLspLocalLabelInfo | ||
| 74 | + DeviceId deviceId2 = DeviceId.deviceId("goo"); | ||
| 75 | + LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3); | ||
| 76 | + LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4); | ||
| 77 | + PortNumber inPort2 = PortNumber.portNumber(5124); | ||
| 78 | + PortNumber outPort2 = PortNumber.portNumber(5125); | ||
| 79 | + | ||
| 80 | + LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder() | ||
| 81 | + .deviceId(deviceId2) | ||
| 82 | + .inLabelId(inLabelId2) | ||
| 83 | + .outLabelId(outLabelId2) | ||
| 84 | + .inPort(inPort2) | ||
| 85 | + .outPort(outPort2) | ||
| 86 | + .build(); | ||
| 87 | + lspLocalLabelInfoList2.add(lspLocalLabel2); | ||
| 88 | + | ||
| 89 | + PceccTunnelInfo pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2); | ||
| 90 | + | ||
| 91 | + new EqualsTester().addEqualityGroup(pceccTunnelInfo1, samePceccTunnelInfo1) | ||
| 92 | + .addEqualityGroup(pceccTunnelInfo2) | ||
| 93 | + .testEquals(); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Checks the construction of a PceccTunnelInfo object. | ||
| 98 | + */ | ||
| 99 | + @Test | ||
| 100 | + public void testConstruction() { | ||
| 101 | + List<LspLocalLabelInfo> lspLocalLabelInfoList = new LinkedList<>(); | ||
| 102 | + ResourceConsumer tunnelConsumerId = TunnelConsumerId.valueOf(10); | ||
| 103 | + | ||
| 104 | + // create object of DefaultLspLocalLabelInfo | ||
| 105 | + DeviceId deviceId = DeviceId.deviceId("foo"); | ||
| 106 | + LabelResourceId inLabelId = LabelResourceId.labelResourceId(1); | ||
| 107 | + LabelResourceId outLabelId = LabelResourceId.labelResourceId(2); | ||
| 108 | + PortNumber inPort = PortNumber.portNumber(5122); | ||
| 109 | + PortNumber outPort = PortNumber.portNumber(5123); | ||
| 110 | + | ||
| 111 | + LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 112 | + .deviceId(deviceId) | ||
| 113 | + .inLabelId(inLabelId) | ||
| 114 | + .outLabelId(outLabelId) | ||
| 115 | + .inPort(inPort) | ||
| 116 | + .outPort(outPort) | ||
| 117 | + .build(); | ||
| 118 | + lspLocalLabelInfoList.add(lspLocalLabelInfo); | ||
| 119 | + | ||
| 120 | + PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(lspLocalLabelInfoList, tunnelConsumerId); | ||
| 121 | + | ||
| 122 | + assertThat(lspLocalLabelInfoList, is(pceccTunnelInfo.lspLocalLabelInfoList())); | ||
| 123 | + } | ||
| 124 | +} |
-
Please register or login to post a comment