Committed by
Gerrit Code Review
Move PCE label handling from APP to protocol.
Change-Id: I26ae21b27ac2dc9ae3302030f6860e0e371c342c
Showing
60 changed files
with
5067 additions
and
3422 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.pceservice; | ||
| 17 | - | ||
| 18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | - | ||
| 20 | -import java.util.Collection; | ||
| 21 | -import java.util.Iterator; | ||
| 22 | -import java.util.List; | ||
| 23 | -import java.util.ListIterator; | ||
| 24 | -import java.util.LinkedList; | ||
| 25 | - | ||
| 26 | -import org.onlab.packet.MplsLabel; | ||
| 27 | -import org.onosproject.core.ApplicationId; | ||
| 28 | -import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 29 | -import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 30 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 31 | -import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 32 | -import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 33 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 34 | -import org.onosproject.net.DeviceId; | ||
| 35 | -import org.onosproject.net.PortNumber; | ||
| 36 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 37 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 38 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 39 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 40 | -import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
| 41 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 42 | -import org.onosproject.net.flowobjective.ForwardingObjective; | ||
| 43 | -import org.onosproject.net.flowobjective.Objective; | ||
| 44 | -import org.onosproject.pce.pcestore.api.PceStore; | ||
| 45 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 46 | -import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 47 | -import org.onosproject.pce.pcestore.DefaultLspLocalLabelInfo; | ||
| 48 | -import org.onosproject.net.Link; | ||
| 49 | - | ||
| 50 | -import org.slf4j.Logger; | ||
| 51 | -import org.slf4j.LoggerFactory; | ||
| 52 | - | ||
| 53 | -import com.google.common.collect.ArrayListMultimap; | ||
| 54 | -import com.google.common.collect.Multimap; | ||
| 55 | - | ||
| 56 | -/** | ||
| 57 | - * Basic PCECC handler. | ||
| 58 | - * In Basic PCECC, after path computation will configure IN and OUT label to nodes. | ||
| 59 | - * [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes. | ||
| 60 | - * For generating labels, will go thorough links in the path from Egress to Ingress. | ||
| 61 | - * In each link, will take label from destination node local pool as IN label, | ||
| 62 | - * and assign this label as OUT label to source node. | ||
| 63 | - */ | ||
| 64 | -public final class BasicPceccHandler { | ||
| 65 | - private static final Logger log = LoggerFactory.getLogger(BasicPceccHandler.class); | ||
| 66 | - | ||
| 67 | - private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null"; | ||
| 68 | - private static final String PCE_STORE_NULL = "PCE Store cannot be null"; | ||
| 69 | - private static BasicPceccHandler crHandlerInstance = null; | ||
| 70 | - private LabelResourceService labelRsrcService; | ||
| 71 | - private PceStore pceStore; | ||
| 72 | - private FlowObjectiveService flowObjectiveService; | ||
| 73 | - private ApplicationId appId; | ||
| 74 | - | ||
| 75 | - /** | ||
| 76 | - * Initializes default values. | ||
| 77 | - */ | ||
| 78 | - private BasicPceccHandler() { | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - /** | ||
| 82 | - * Returns single instance of this class. | ||
| 83 | - * | ||
| 84 | - * @return this class single instance | ||
| 85 | - */ | ||
| 86 | - public static BasicPceccHandler getInstance() { | ||
| 87 | - if (crHandlerInstance == null) { | ||
| 88 | - crHandlerInstance = new BasicPceccHandler(); | ||
| 89 | - } | ||
| 90 | - return crHandlerInstance; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - /** | ||
| 94 | - * Initialization of label manager and pce store. | ||
| 95 | - * | ||
| 96 | - * @param labelRsrcService label resource service | ||
| 97 | - * @param flowObjectiveService flow objective service to push device label information | ||
| 98 | - * @param appId applicaton id | ||
| 99 | - * @param pceStore pce label store | ||
| 100 | - */ | ||
| 101 | - public void initialize(LabelResourceService labelRsrcService, FlowObjectiveService flowObjectiveService, | ||
| 102 | - ApplicationId appId, PceStore pceStore) { | ||
| 103 | - this.labelRsrcService = labelRsrcService; | ||
| 104 | - this.flowObjectiveService = flowObjectiveService; | ||
| 105 | - this.appId = appId; | ||
| 106 | - this.pceStore = pceStore; | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - /** | ||
| 110 | - * Allocates labels from local resource pool and configure these (IN and OUT) labels into devices. | ||
| 111 | - * | ||
| 112 | - * @param tunnel tunnel between ingress to egress | ||
| 113 | - * @return success or failure | ||
| 114 | - */ | ||
| 115 | - public boolean allocateLabel(Tunnel tunnel) { | ||
| 116 | - long applyNum = 1; | ||
| 117 | - boolean isLastLabelToPush = false; | ||
| 118 | - Collection<LabelResource> labelRscList; | ||
| 119 | - | ||
| 120 | - checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 121 | - checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 122 | - | ||
| 123 | - List<Link> linkList = tunnel.path().links(); | ||
| 124 | - if ((linkList != null) && (linkList.size() > 0)) { | ||
| 125 | - // Sequence through reverse order to push local labels into devices | ||
| 126 | - // Generation of labels from egress to ingress | ||
| 127 | - for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { | ||
| 128 | - Link link = iterator.previous(); | ||
| 129 | - DeviceId dstDeviceId = link.dst().deviceId(); | ||
| 130 | - DeviceId srcDeviceId = link.src().deviceId(); | ||
| 131 | - labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); | ||
| 132 | - if ((labelRscList != null) && (labelRscList.size() > 0)) { | ||
| 133 | - // Link label value is taken from destination device local pool. | ||
| 134 | - // [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes. | ||
| 135 | - // Link label value is used as OUT and IN for both ends | ||
| 136 | - // (source and destination devices) of the link. | ||
| 137 | - // Currently only one label is allocated to a device (destination device). | ||
| 138 | - // So, no need to iterate through list | ||
| 139 | - Iterator<LabelResource> labelIterator = labelRscList.iterator(); | ||
| 140 | - DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); | ||
| 141 | - LabelResourceId labelId = defaultLabelResource.labelResourceId(); | ||
| 142 | - log.debug("Allocated local label: " + labelId.toString() | ||
| 143 | - + "to device: " + defaultLabelResource.deviceId().toString()); | ||
| 144 | - PortNumber dstPort = link.dst().port(); | ||
| 145 | - | ||
| 146 | - // Check whether this is last link label to push | ||
| 147 | - if (!iterator.hasPrevious()) { | ||
| 148 | - isLastLabelToPush = true; | ||
| 149 | - } | ||
| 150 | - | ||
| 151 | - // Push into destination device | ||
| 152 | - // Destination device IN port is link.dst().port() | ||
| 153 | - installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false, | ||
| 154 | - Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); | ||
| 155 | - | ||
| 156 | - // Push into source device | ||
| 157 | - // Source device OUT port will be link.dst().port(). Means its remote port used to send packet. | ||
| 158 | - installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, | ||
| 159 | - Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); | ||
| 160 | - | ||
| 161 | - // Add or update pcecc tunnel info in pce store. | ||
| 162 | - updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, | ||
| 163 | - tunnel, isLastLabelToPush); | ||
| 164 | - } else { | ||
| 165 | - log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); | ||
| 166 | - releaseLabel(tunnel); | ||
| 167 | - return false; | ||
| 168 | - } | ||
| 169 | - } | ||
| 170 | - } else { | ||
| 171 | - log.error("Tunnel {} is having empty links.", tunnel.toString()); | ||
| 172 | - return false; | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - return true; | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - /** | ||
| 179 | - * Updates list of local labels of PCECC tunnel info in pce store. | ||
| 180 | - * | ||
| 181 | - * @param srcDeviceId source device in a link | ||
| 182 | - * @param dstDeviceId destination device in a link | ||
| 183 | - * @param labelId label id of a link | ||
| 184 | - * @param dstPort destination device port number of a link | ||
| 185 | - * @param tunnel tunnel | ||
| 186 | - * @param isLastLabelToPush indicates this is the last label to push in Basic PCECC case | ||
| 187 | - */ | ||
| 188 | - public void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId, | ||
| 189 | - PortNumber dstPort, Tunnel tunnel, boolean isLastLabelToPush) { | ||
| 190 | - // First try to retrieve device from store and update its label id if it is exists, | ||
| 191 | - // otherwise add it | ||
| 192 | - boolean dstDeviceUpdated = false; | ||
| 193 | - boolean srcDeviceUpdated = false; | ||
| 194 | - | ||
| 195 | - PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 196 | - List<LspLocalLabelInfo> lspLabelInfoList; | ||
| 197 | - if (pceccTunnelInfo != null) { | ||
| 198 | - lspLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 199 | - if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) { | ||
| 200 | - for (int i = 0; i < lspLabelInfoList.size(); ++i) { | ||
| 201 | - LspLocalLabelInfo lspLocalLabelInfo = | ||
| 202 | - lspLabelInfoList.get(i); | ||
| 203 | - LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null; | ||
| 204 | - if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) { | ||
| 205 | - lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | ||
| 206 | - lspLocalLabelInfoBuilder.inLabelId(labelId); | ||
| 207 | - // Destination device IN port will be link destination port | ||
| 208 | - lspLocalLabelInfoBuilder.inPort(dstPort); | ||
| 209 | - dstDeviceUpdated = true; | ||
| 210 | - } else if (srcDeviceId.equals(lspLocalLabelInfo.deviceId())) { | ||
| 211 | - lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | ||
| 212 | - lspLocalLabelInfoBuilder.outLabelId(labelId); | ||
| 213 | - // Source device OUT port will be link destination (remote) port | ||
| 214 | - lspLocalLabelInfoBuilder.outPort(dstPort); | ||
| 215 | - srcDeviceUpdated = true; | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - // Update | ||
| 219 | - if ((lspLocalLabelInfoBuilder != null) && (dstDeviceUpdated || srcDeviceUpdated)) { | ||
| 220 | - lspLabelInfoList.set(i, lspLocalLabelInfoBuilder.build()); | ||
| 221 | - } | ||
| 222 | - } | ||
| 223 | - } | ||
| 224 | - } | ||
| 225 | - | ||
| 226 | - // If it is not found in store then add it to store | ||
| 227 | - if (!dstDeviceUpdated || !srcDeviceUpdated) { | ||
| 228 | - // If tunnel info itself not available then create new one, otherwise add node to list. | ||
| 229 | - if (pceccTunnelInfo == null) { | ||
| 230 | - pceccTunnelInfo = new PceccTunnelInfo(); | ||
| 231 | - lspLabelInfoList = new LinkedList<>(); | ||
| 232 | - } else { | ||
| 233 | - lspLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 234 | - if (lspLabelInfoList == null) { | ||
| 235 | - lspLabelInfoList = new LinkedList<>(); | ||
| 236 | - } | ||
| 237 | - } | ||
| 238 | - | ||
| 239 | - if (!dstDeviceUpdated) { | ||
| 240 | - LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 241 | - .deviceId(dstDeviceId) | ||
| 242 | - .inLabelId(labelId) | ||
| 243 | - .outLabelId(null) | ||
| 244 | - .inPort(dstPort) // Destination device IN port will be link destination port | ||
| 245 | - .outPort(null) | ||
| 246 | - .build(); | ||
| 247 | - lspLabelInfoList.add(lspLocalLabelInfo); | ||
| 248 | - } | ||
| 249 | - | ||
| 250 | - if (!srcDeviceUpdated) { | ||
| 251 | - LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 252 | - .deviceId(srcDeviceId) | ||
| 253 | - .inLabelId(null) | ||
| 254 | - .outLabelId(labelId) | ||
| 255 | - .inPort(null) | ||
| 256 | - .outPort(dstPort) // Source device OUT port will be link destination (remote) port | ||
| 257 | - .build(); | ||
| 258 | - lspLabelInfoList.add(lspLocalLabelInfo); | ||
| 259 | - } | ||
| 260 | - | ||
| 261 | - pceccTunnelInfo.lspLocalLabelInfoList(lspLabelInfoList); | ||
| 262 | - pceStore.addTunnelInfo(tunnel.tunnelId(), pceccTunnelInfo); | ||
| 263 | - } | ||
| 264 | - } | ||
| 265 | - | ||
| 266 | - /** | ||
| 267 | - * Deallocates unused labels to device pools. | ||
| 268 | - * | ||
| 269 | - * @param tunnel tunnel between ingress to egress | ||
| 270 | - */ | ||
| 271 | - public void releaseLabel(Tunnel tunnel) { | ||
| 272 | - | ||
| 273 | - checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 274 | - checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 275 | - | ||
| 276 | - Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); | ||
| 277 | - PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 278 | - if (pceccTunnelInfo != null) { | ||
| 279 | - List<LspLocalLabelInfo> lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 280 | - if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) { | ||
| 281 | - for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) { | ||
| 282 | - LspLocalLabelInfo lspLocalLabelInfo = iterator.next(); | ||
| 283 | - DeviceId deviceId = lspLocalLabelInfo.deviceId(); | ||
| 284 | - LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 285 | - LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 286 | - PortNumber inPort = lspLocalLabelInfo.inPort(); | ||
| 287 | - PortNumber outPort = lspLocalLabelInfo.outPort(); | ||
| 288 | - | ||
| 289 | - // Push into device | ||
| 290 | - if ((inLabelId != null) && (inPort != null)) { | ||
| 291 | - installLocalLabelRule(deviceId, inLabelId, inPort, tunnel.tunnelId(), false, | ||
| 292 | - Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.REMOVE); | ||
| 293 | - } | ||
| 294 | - | ||
| 295 | - if ((outLabelId != null) && (outPort != null)) { | ||
| 296 | - installLocalLabelRule(deviceId, outLabelId, outPort, tunnel.tunnelId(), false, | ||
| 297 | - Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.REMOVE); | ||
| 298 | - } | ||
| 299 | - | ||
| 300 | - // List is stored from egress to ingress. So, using IN label id to release. | ||
| 301 | - // Only one local label is assigned to device (destination node) | ||
| 302 | - // and that is used as OUT label for source node. | ||
| 303 | - // No need to release label for last node in the list from pool because label was not allocated to | ||
| 304 | - // ingress node (source node). | ||
| 305 | - if ((iterator.hasNext()) && (inLabelId != null)) { | ||
| 306 | - LabelResource labelRsc = new DefaultLabelResource(deviceId, inLabelId); | ||
| 307 | - release.put(deviceId, labelRsc); | ||
| 308 | - } | ||
| 309 | - } | ||
| 310 | - } | ||
| 311 | - | ||
| 312 | - // Release from label pool | ||
| 313 | - if (!release.isEmpty()) { | ||
| 314 | - labelRsrcService.releaseToDevicePool(release); | ||
| 315 | - } | ||
| 316 | - | ||
| 317 | - // Remove tunnel info only if tunnel consumer id is not saved. | ||
| 318 | - // If tunnel consumer id is saved, this tunnel info will be removed during releasing bandwidth. | ||
| 319 | - if (pceccTunnelInfo.tunnelConsumerId() == null) { | ||
| 320 | - pceStore.removeTunnelInfo(tunnel.tunnelId()); | ||
| 321 | - } | ||
| 322 | - } else { | ||
| 323 | - log.error("Unable to find PCECC tunnel info in store for a tunnel {}.", tunnel.toString()); | ||
| 324 | - } | ||
| 325 | - } | ||
| 326 | - | ||
| 327 | - // Install a rule for pushing local labels to the device which is specific to path. | ||
| 328 | - private synchronized void installLocalLabelRule(DeviceId deviceId, LabelResourceId labelId, | ||
| 329 | - PortNumber portNum, TunnelId tunnelId, | ||
| 330 | - Boolean isBos, Long labelType, | ||
| 331 | - Objective.Operation type) { | ||
| 332 | - checkNotNull(flowObjectiveService); | ||
| 333 | - checkNotNull(appId); | ||
| 334 | - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
| 335 | - | ||
| 336 | - selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | ||
| 337 | - selectorBuilder.matchInPort(portNum); | ||
| 338 | - selectorBuilder.matchTunnelId(Long.parseLong(tunnelId.id())); | ||
| 339 | - selectorBuilder.matchMplsBos(isBos); | ||
| 340 | - selectorBuilder.matchMetadata(labelType); | ||
| 341 | - | ||
| 342 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
| 343 | - | ||
| 344 | - ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | ||
| 345 | - .withSelector(selectorBuilder.build()) | ||
| 346 | - .withTreatment(treatment) | ||
| 347 | - .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
| 348 | - .fromApp(appId) | ||
| 349 | - .makePermanent(); | ||
| 350 | - | ||
| 351 | - if (type.equals(Objective.Operation.ADD)) { | ||
| 352 | - flowObjectiveService.forward(deviceId, forwardingObjective.add()); | ||
| 353 | - } else { | ||
| 354 | - flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | ||
| 355 | - } | ||
| 356 | - } | ||
| 357 | -} |
| ... | @@ -19,19 +19,11 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -19,19 +19,11 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | 19 | ||
| 20 | import java.util.Collection; | 20 | import java.util.Collection; |
| 21 | import java.util.Collections; | 21 | import java.util.Collections; |
| 22 | -import java.util.HashMap; | ||
| 23 | import java.util.Iterator; | 22 | import java.util.Iterator; |
| 24 | import java.util.LinkedList; | 23 | import java.util.LinkedList; |
| 25 | import java.util.List; | 24 | import java.util.List; |
| 26 | -import java.util.Map; | ||
| 27 | import java.util.Optional; | 25 | import java.util.Optional; |
| 28 | -import java.util.Map.Entry; | ||
| 29 | import java.util.Set; | 26 | import java.util.Set; |
| 30 | -import java.util.concurrent.ScheduledExecutorService; | ||
| 31 | - | ||
| 32 | -import org.onlab.packet.Ethernet; | ||
| 33 | -import org.onlab.packet.IPv4; | ||
| 34 | - | ||
| 35 | import org.apache.felix.scr.annotations.Activate; | 27 | import org.apache.felix.scr.annotations.Activate; |
| 36 | import org.apache.felix.scr.annotations.Component; | 28 | import org.apache.felix.scr.annotations.Component; |
| 37 | import org.apache.felix.scr.annotations.Deactivate; | 29 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -39,18 +31,12 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -39,18 +31,12 @@ import org.apache.felix.scr.annotations.Reference; |
| 39 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 40 | import org.apache.felix.scr.annotations.Service; | 32 | import org.apache.felix.scr.annotations.Service; |
| 41 | import org.onlab.packet.IpAddress; | 33 | import org.onlab.packet.IpAddress; |
| 42 | -import org.onlab.packet.IpPrefix; | ||
| 43 | -import org.onlab.packet.TCP; | ||
| 44 | import org.onlab.util.Bandwidth; | 34 | import org.onlab.util.Bandwidth; |
| 45 | import org.onosproject.core.ApplicationId; | 35 | import org.onosproject.core.ApplicationId; |
| 46 | import org.onosproject.core.CoreService; | 36 | import org.onosproject.core.CoreService; |
| 47 | -import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 48 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 49 | -import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 50 | import org.onosproject.core.IdGenerator; | 37 | import org.onosproject.core.IdGenerator; |
| 51 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; | 38 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 52 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | 39 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 53 | -import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 54 | import org.onosproject.incubator.net.tunnel.Tunnel; | 40 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 55 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | 41 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
| 56 | import org.onosproject.incubator.net.tunnel.TunnelEvent; | 42 | import org.onosproject.incubator.net.tunnel.TunnelEvent; |
| ... | @@ -59,8 +45,6 @@ import org.onosproject.incubator.net.tunnel.TunnelListener; | ... | @@ -59,8 +45,6 @@ import org.onosproject.incubator.net.tunnel.TunnelListener; |
| 59 | import org.onosproject.incubator.net.tunnel.TunnelName; | 45 | import org.onosproject.incubator.net.tunnel.TunnelName; |
| 60 | import org.onosproject.incubator.net.tunnel.TunnelService; | 46 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 61 | import org.onosproject.mastership.MastershipService; | 47 | import org.onosproject.mastership.MastershipService; |
| 62 | -import org.onosproject.net.config.NetworkConfigEvent; | ||
| 63 | -import org.onosproject.net.config.NetworkConfigListener; | ||
| 64 | import org.onosproject.net.config.NetworkConfigService; | 48 | import org.onosproject.net.config.NetworkConfigService; |
| 65 | import org.onosproject.net.DefaultAnnotations; | 49 | import org.onosproject.net.DefaultAnnotations; |
| 66 | import org.onosproject.net.DefaultAnnotations.Builder; | 50 | import org.onosproject.net.DefaultAnnotations.Builder; |
| ... | @@ -68,16 +52,10 @@ import org.onosproject.net.Device; | ... | @@ -68,16 +52,10 @@ import org.onosproject.net.Device; |
| 68 | import org.onosproject.net.DeviceId; | 52 | import org.onosproject.net.DeviceId; |
| 69 | import org.onosproject.net.Link; | 53 | import org.onosproject.net.Link; |
| 70 | import org.onosproject.net.Path; | 54 | import org.onosproject.net.Path; |
| 71 | -import org.onosproject.net.device.DeviceEvent; | ||
| 72 | -import org.onosproject.net.device.DeviceListener; | ||
| 73 | import org.onosproject.net.device.DeviceService; | 55 | import org.onosproject.net.device.DeviceService; |
| 74 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 75 | -import org.onosproject.net.flowobjective.Objective; | ||
| 76 | import org.onosproject.net.intent.Constraint; | 56 | import org.onosproject.net.intent.Constraint; |
| 77 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 57 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 78 | -import org.onosproject.net.link.LinkListener; | ||
| 79 | import org.onosproject.net.link.LinkEvent; | 58 | import org.onosproject.net.link.LinkEvent; |
| 80 | -import org.onosproject.net.link.LinkService; | ||
| 81 | import org.onosproject.net.MastershipRole; | 59 | import org.onosproject.net.MastershipRole; |
| 82 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; | 60 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; |
| 83 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType; | 61 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType; |
| ... | @@ -97,7 +75,6 @@ import org.onosproject.net.topology.TopologyListener; | ... | @@ -97,7 +75,6 @@ import org.onosproject.net.topology.TopologyListener; |
| 97 | import org.onosproject.net.topology.TopologyService; | 75 | import org.onosproject.net.topology.TopologyService; |
| 98 | import org.onosproject.pce.pceservice.api.PceService; | 76 | import org.onosproject.pce.pceservice.api.PceService; |
| 99 | import org.onosproject.pce.pcestore.PcePathInfo; | 77 | import org.onosproject.pce.pcestore.PcePathInfo; |
| 100 | -import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 101 | import org.onosproject.pce.pcestore.api.PceStore; | 78 | import org.onosproject.pce.pcestore.api.PceStore; |
| 102 | import org.onosproject.pcep.api.DeviceCapability; | 79 | import org.onosproject.pcep.api.DeviceCapability; |
| 103 | import org.onosproject.store.serializers.KryoNamespaces; | 80 | import org.onosproject.store.serializers.KryoNamespaces; |
| ... | @@ -110,14 +87,10 @@ import org.slf4j.LoggerFactory; | ... | @@ -110,14 +87,10 @@ import org.slf4j.LoggerFactory; |
| 110 | import com.google.common.collect.ImmutableList; | 87 | import com.google.common.collect.ImmutableList; |
| 111 | import com.google.common.collect.ImmutableSet; | 88 | import com.google.common.collect.ImmutableSet; |
| 112 | 89 | ||
| 113 | -import static org.onosproject.incubator.net.tunnel.Tunnel.State.ACTIVE; | ||
| 114 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT; | 90 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT; |
| 115 | -import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; | ||
| 116 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; | 91 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; |
| 117 | import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; | 92 | import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; |
| 118 | import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING; | 93 | import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING; |
| 119 | -import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; | ||
| 120 | -import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; | ||
| 121 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.BANDWIDTH; | 94 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.BANDWIDTH; |
| 122 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; | 95 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; |
| 123 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LSP_SIG_TYPE; | 96 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LSP_SIG_TYPE; |
| ... | @@ -127,11 +100,6 @@ import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PCC_TUNNEL_ID; | ... | @@ -127,11 +100,6 @@ import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PCC_TUNNEL_ID; |
| 127 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.DELEGATE; | 100 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.DELEGATE; |
| 128 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.COST_TYPE; | 101 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.COST_TYPE; |
| 129 | 102 | ||
| 130 | -import org.onosproject.net.packet.InboundPacket; | ||
| 131 | -import org.onosproject.net.packet.PacketContext; | ||
| 132 | -import org.onosproject.net.packet.PacketProcessor; | ||
| 133 | -import org.onosproject.net.packet.PacketService; | ||
| 134 | - | ||
| 135 | /** | 103 | /** |
| 136 | * Implementation of PCE service. | 104 | * Implementation of PCE service. |
| 137 | */ | 105 | */ |
| ... | @@ -142,13 +110,10 @@ public class PceManager implements PceService { | ... | @@ -142,13 +110,10 @@ public class PceManager implements PceService { |
| 142 | 110 | ||
| 143 | public static final long GLOBAL_LABEL_SPACE_MIN = 4097; | 111 | public static final long GLOBAL_LABEL_SPACE_MIN = 4097; |
| 144 | public static final long GLOBAL_LABEL_SPACE_MAX = 5121; | 112 | public static final long GLOBAL_LABEL_SPACE_MAX = 5121; |
| 145 | - private static final String DEVICE_NULL = "Device-cannot be null"; | ||
| 146 | - private static final String LINK_NULL = "Link-cannot be null"; | ||
| 147 | public static final String PCE_SERVICE_APP = "org.onosproject.pce"; | 113 | public static final String PCE_SERVICE_APP = "org.onosproject.pce"; |
| 148 | private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id"; | 114 | private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id"; |
| 149 | public static final String DEVICE_TYPE = "type"; | 115 | public static final String DEVICE_TYPE = "type"; |
| 150 | public static final String L3_DEVICE = "L3"; | 116 | public static final String L3_DEVICE = "L3"; |
| 151 | - private static final int PREFIX_LENGTH = 32; | ||
| 152 | 117 | ||
| 153 | private static final String TUNNEL_CONSUMER_ID_GEN_TOPIC = "pcep-tunnel-consumer-id"; | 118 | private static final String TUNNEL_CONSUMER_ID_GEN_TOPIC = "pcep-tunnel-consumer-id"; |
| 154 | private IdGenerator tunnelConsumerIdGen; | 119 | private IdGenerator tunnelConsumerIdGen; |
| ... | @@ -156,16 +121,11 @@ public class PceManager implements PceService { | ... | @@ -156,16 +121,11 @@ public class PceManager implements PceService { |
| 156 | private static final String LSRID = "lsrId"; | 121 | private static final String LSRID = "lsrId"; |
| 157 | private static final String TRUE = "true"; | 122 | private static final String TRUE = "true"; |
| 158 | private static final String FALSE = "false"; | 123 | private static final String FALSE = "false"; |
| 159 | - private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32"; | ||
| 160 | public static final int PCEP_PORT = 4189; | 124 | public static final int PCEP_PORT = 4189; |
| 161 | 125 | ||
| 162 | private IdGenerator localLspIdIdGen; | 126 | private IdGenerator localLspIdIdGen; |
| 163 | protected DistributedSet<Short> localLspIdFreeList; | 127 | protected DistributedSet<Short> localLspIdFreeList; |
| 164 | 128 | ||
| 165 | - // LSR-id and device-id mapping for checking capability if L3 device is not | ||
| 166 | - // having its capability | ||
| 167 | - private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); | ||
| 168 | - | ||
| 169 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 170 | protected CoreService coreService; | 130 | protected CoreService coreService; |
| 171 | 131 | ||
| ... | @@ -185,46 +145,24 @@ public class PceManager implements PceService { | ... | @@ -185,46 +145,24 @@ public class PceManager implements PceService { |
| 185 | protected TunnelService tunnelService; | 145 | protected TunnelService tunnelService; |
| 186 | 146 | ||
| 187 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 147 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 188 | - protected StorageService storageService; | ||
| 189 | - | ||
| 190 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 191 | - protected PacketService packetService; | ||
| 192 | - | ||
| 193 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 194 | protected DeviceService deviceService; | 148 | protected DeviceService deviceService; |
| 195 | 149 | ||
| 196 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 150 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 197 | - protected LinkService linkService; | 151 | + protected StorageService storageService; |
| 198 | 152 | ||
| 199 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 153 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 200 | protected NetworkConfigService netCfgService; | 154 | protected NetworkConfigService netCfgService; |
| 201 | 155 | ||
| 202 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 156 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 203 | - protected LabelResourceAdminService labelRsrcAdminService; | ||
| 204 | - | ||
| 205 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 206 | - protected LabelResourceService labelRsrcService; | ||
| 207 | - | ||
| 208 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 209 | - protected FlowObjectiveService flowObjectiveService; | ||
| 210 | - | ||
| 211 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 212 | protected MastershipService mastershipService; | 157 | protected MastershipService mastershipService; |
| 213 | 158 | ||
| 214 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 159 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 215 | protected TopologyService topologyService; | 160 | protected TopologyService topologyService; |
| 216 | 161 | ||
| 217 | private TunnelListener listener = new InnerTunnelListener(); | 162 | private TunnelListener listener = new InnerTunnelListener(); |
| 218 | - private DeviceListener deviceListener = new InternalDeviceListener(); | ||
| 219 | - private LinkListener linkListener = new InternalLinkListener(); | ||
| 220 | - private InternalConfigListener cfgListener = new InternalConfigListener(); | ||
| 221 | - private BasicPceccHandler crHandler; | ||
| 222 | - private PceccSrTeBeHandler srTeHandler; | ||
| 223 | private ApplicationId appId; | 163 | private ApplicationId appId; |
| 224 | 164 | ||
| 225 | - private final PcepPacketProcessor processor = new PcepPacketProcessor(); | ||
| 226 | private final TopologyListener topologyListener = new InternalTopologyListener(); | 165 | private final TopologyListener topologyListener = new InternalTopologyListener(); |
| 227 | - private ScheduledExecutorService executor; | ||
| 228 | 166 | ||
| 229 | public static final int INITIAL_DELAY = 30; | 167 | public static final int INITIAL_DELAY = 30; |
| 230 | public static final int PERIODIC_DELAY = 30; | 168 | public static final int PERIODIC_DELAY = 30; |
| ... | @@ -238,17 +176,8 @@ public class PceManager implements PceService { | ... | @@ -238,17 +176,8 @@ public class PceManager implements PceService { |
| 238 | @Activate | 176 | @Activate |
| 239 | protected void activate() { | 177 | protected void activate() { |
| 240 | appId = coreService.registerApplication(PCE_SERVICE_APP); | 178 | appId = coreService.registerApplication(PCE_SERVICE_APP); |
| 241 | - crHandler = BasicPceccHandler.getInstance(); | ||
| 242 | - crHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore); | ||
| 243 | - | ||
| 244 | - srTeHandler = PceccSrTeBeHandler.getInstance(); | ||
| 245 | - srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore, | ||
| 246 | - deviceService); | ||
| 247 | 179 | ||
| 248 | tunnelService.addListener(listener); | 180 | tunnelService.addListener(listener); |
| 249 | - deviceService.addListener(deviceListener); | ||
| 250 | - linkService.addListener(linkListener); | ||
| 251 | - netCfgService.addListener(cfgListener); | ||
| 252 | 181 | ||
| 253 | tunnelConsumerIdGen = coreService.getIdGenerator(TUNNEL_CONSUMER_ID_GEN_TOPIC); | 182 | tunnelConsumerIdGen = coreService.getIdGenerator(TUNNEL_CONSUMER_ID_GEN_TOPIC); |
| 254 | localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC); | 183 | localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC); |
| ... | @@ -259,24 +188,14 @@ public class PceManager implements PceService { | ... | @@ -259,24 +188,14 @@ public class PceManager implements PceService { |
| 259 | .build() | 188 | .build() |
| 260 | .asDistributedSet(); | 189 | .asDistributedSet(); |
| 261 | 190 | ||
| 262 | - packetService.addProcessor(processor, PacketProcessor.director(4)); | ||
| 263 | topologyService.addListener(topologyListener); | 191 | topologyService.addListener(topologyListener); |
| 264 | 192 | ||
| 265 | - // Reserve global node pool | ||
| 266 | - if (!srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX)) { | ||
| 267 | - log.debug("Global node pool was already reserved."); | ||
| 268 | - } | ||
| 269 | - | ||
| 270 | log.info("Started"); | 193 | log.info("Started"); |
| 271 | } | 194 | } |
| 272 | 195 | ||
| 273 | @Deactivate | 196 | @Deactivate |
| 274 | protected void deactivate() { | 197 | protected void deactivate() { |
| 275 | tunnelService.removeListener(listener); | 198 | tunnelService.removeListener(listener); |
| 276 | - deviceService.removeListener(deviceListener); | ||
| 277 | - linkService.removeListener(linkListener); | ||
| 278 | - netCfgService.removeListener(cfgListener); | ||
| 279 | - packetService.removeProcessor(processor); | ||
| 280 | topologyService.removeListener(topologyListener); | 199 | topologyService.removeListener(topologyListener); |
| 281 | log.info("Stopped"); | 200 | log.info("Stopped"); |
| 282 | } | 201 | } |
| ... | @@ -401,16 +320,6 @@ public class PceManager implements PceService { | ... | @@ -401,16 +320,6 @@ public class PceManager implements PceService { |
| 401 | annotationBuilder.set(DELEGATE, TRUE); | 320 | annotationBuilder.set(DELEGATE, TRUE); |
| 402 | 321 | ||
| 403 | Path computedPath = computedPathSet.iterator().next(); | 322 | Path computedPath = computedPathSet.iterator().next(); |
| 404 | - LabelStack labelStack = null; | ||
| 405 | - | ||
| 406 | - if (lspType == SR_WITHOUT_SIGNALLING) { | ||
| 407 | - labelStack = srTeHandler.computeLabelStack(computedPath); | ||
| 408 | - // Failed to form a label stack. | ||
| 409 | - if (labelStack == null) { | ||
| 410 | - pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType)); | ||
| 411 | - return false; | ||
| 412 | - } | ||
| 413 | - } | ||
| 414 | 323 | ||
| 415 | if (lspType != WITH_SIGNALLING) { | 324 | if (lspType != WITH_SIGNALLING) { |
| 416 | /* | 325 | /* |
| ... | @@ -423,7 +332,7 @@ public class PceManager implements PceService { | ... | @@ -423,7 +332,7 @@ public class PceManager implements PceService { |
| 423 | // For SR-TE tunnels, call SR manager for label stack and put it inside tunnel. | 332 | // For SR-TE tunnels, call SR manager for label stack and put it inside tunnel. |
| 424 | Tunnel tunnel = new DefaultTunnel(null, srcEndPoint, dstEndPoint, MPLS, INIT, null, null, | 333 | Tunnel tunnel = new DefaultTunnel(null, srcEndPoint, dstEndPoint, MPLS, INIT, null, null, |
| 425 | TunnelName.tunnelName(tunnelName), computedPath, | 334 | TunnelName.tunnelName(tunnelName), computedPath, |
| 426 | - labelStack, annotationBuilder.build()); | 335 | + annotationBuilder.build()); |
| 427 | 336 | ||
| 428 | // Allocate bandwidth. | 337 | // Allocate bandwidth. |
| 429 | TunnelConsumerId consumerId = null; | 338 | TunnelConsumerId consumerId = null; |
| ... | @@ -445,9 +354,8 @@ public class PceManager implements PceService { | ... | @@ -445,9 +354,8 @@ public class PceManager implements PceService { |
| 445 | } | 354 | } |
| 446 | 355 | ||
| 447 | if (consumerId != null) { | 356 | if (consumerId != null) { |
| 448 | - // Store tunnel consumer id in LSP-Label store. | 357 | + // Store tunnel consumer id in LSP store. |
| 449 | - PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(null, consumerId); | 358 | + pceStore.addTunnelInfo(tunnelId, consumerId); |
| 450 | - pceStore.addTunnelInfo(tunnelId, pceccTunnelInfo); | ||
| 451 | } | 359 | } |
| 452 | return true; | 360 | return true; |
| 453 | } | 361 | } |
| ... | @@ -553,7 +461,6 @@ public class PceManager implements PceService { | ... | @@ -553,7 +461,6 @@ public class PceManager implements PceService { |
| 553 | annotationBuilder.set(PCC_TUNNEL_ID, tunnel.annotations().value(PCC_TUNNEL_ID)); | 461 | annotationBuilder.set(PCC_TUNNEL_ID, tunnel.annotations().value(PCC_TUNNEL_ID)); |
| 554 | 462 | ||
| 555 | Path computedPath = computedPathSet.iterator().next(); | 463 | Path computedPath = computedPathSet.iterator().next(); |
| 556 | - LabelStack labelStack = null; | ||
| 557 | TunnelConsumerId consumerId = null; | 464 | TunnelConsumerId consumerId = null; |
| 558 | LspType lspType = LspType.valueOf(lspSigType); | 465 | LspType lspType = LspType.valueOf(lspSigType); |
| 559 | long localLspId = 0; | 466 | long localLspId = 0; |
| ... | @@ -564,19 +471,11 @@ public class PceManager implements PceService { | ... | @@ -564,19 +471,11 @@ public class PceManager implements PceService { |
| 564 | */ | 471 | */ |
| 565 | localLspId = getNextLocalLspId(); | 472 | localLspId = getNextLocalLspId(); |
| 566 | annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(localLspId)); | 473 | annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(localLspId)); |
| 567 | - | ||
| 568 | - if (lspType == SR_WITHOUT_SIGNALLING) { | ||
| 569 | - labelStack = srTeHandler.computeLabelStack(computedPath); | ||
| 570 | - // Failed to form a label stack. | ||
| 571 | - if (labelStack == null) { | ||
| 572 | - return false; | ||
| 573 | - } | ||
| 574 | - } | ||
| 575 | } | 474 | } |
| 576 | 475 | ||
| 577 | Tunnel updatedTunnel = new DefaultTunnel(null, tunnel.src(), tunnel.dst(), MPLS, INIT, null, null, | 476 | Tunnel updatedTunnel = new DefaultTunnel(null, tunnel.src(), tunnel.dst(), MPLS, INIT, null, null, |
| 578 | tunnel.tunnelName(), computedPath, | 477 | tunnel.tunnelName(), computedPath, |
| 579 | - labelStack, annotationBuilder.build()); | 478 | + annotationBuilder.build()); |
| 580 | 479 | ||
| 581 | // Allocate shared bandwidth. | 480 | // Allocate shared bandwidth. |
| 582 | if (bwConstraintValue != 0) { | 481 | if (bwConstraintValue != 0) { |
| ... | @@ -597,20 +496,8 @@ public class PceManager implements PceService { | ... | @@ -597,20 +496,8 @@ public class PceManager implements PceService { |
| 597 | } | 496 | } |
| 598 | 497 | ||
| 599 | if (consumerId != null) { | 498 | if (consumerId != null) { |
| 600 | - // Store tunnel consumer id in LSP-Label store. | 499 | + // Store tunnel consumer id in LSP store. |
| 601 | - PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(null, consumerId); | 500 | + pceStore.addTunnelInfo(updatedTunnelId, consumerId); |
| 602 | - pceStore.addTunnelInfo(updatedTunnelId, pceccTunnelInfo); | ||
| 603 | - } | ||
| 604 | - | ||
| 605 | - // For CR cases, download labels and send update message. | ||
| 606 | - if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) { | ||
| 607 | - Tunnel tunnelForlabelDownload = new DefaultTunnel(null, tunnel.src(), tunnel.dst(), MPLS, INIT, null, | ||
| 608 | - updatedTunnelId, tunnel.tunnelName(), computedPath, | ||
| 609 | - labelStack, annotationBuilder.build()); | ||
| 610 | - | ||
| 611 | - if (!crHandler.allocateLabel(tunnelForlabelDownload)) { | ||
| 612 | - log.error("Unable to allocate labels for the tunnel {}.", tunnel.toString()); | ||
| 613 | - } | ||
| 614 | } | 501 | } |
| 615 | 502 | ||
| 616 | return true; | 503 | return true; |
| ... | @@ -626,12 +513,6 @@ public class PceManager implements PceService { | ... | @@ -626,12 +513,6 @@ public class PceManager implements PceService { |
| 626 | return false; | 513 | return false; |
| 627 | } | 514 | } |
| 628 | 515 | ||
| 629 | - LspType lspType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); | ||
| 630 | - // Release basic PCECC labels. | ||
| 631 | - if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) { | ||
| 632 | - crHandler.releaseLabel(tunnel); | ||
| 633 | - } | ||
| 634 | - | ||
| 635 | // 2. Call tunnel service. | 516 | // 2. Call tunnel service. |
| 636 | return tunnelService.downTunnel(appId, tunnel.tunnelId()); | 517 | return tunnelService.downTunnel(appId, tunnel.tunnelId()); |
| 637 | } | 518 | } |
| ... | @@ -845,19 +726,19 @@ public class PceManager implements PceService { | ... | @@ -845,19 +726,19 @@ public class PceManager implements PceService { |
| 845 | } | 726 | } |
| 846 | } | 727 | } |
| 847 | 728 | ||
| 848 | - if (isLinkShared) { | 729 | + ResourceConsumer tunnelConsumerId = pceStore.getTunnelInfo(tunnel.tunnelId()); |
| 849 | - releaseSharedBandwidth(newTunnel, tunnel); | 730 | + if (tunnelConsumerId == null) { |
| 731 | + //If bandwidth for old tunnel is not allocated i,e 0 then no need to release | ||
| 732 | + log.debug("Bandwidth not allocated (0 bandwidth) for old LSP."); | ||
| 850 | return; | 733 | return; |
| 851 | } | 734 | } |
| 852 | 735 | ||
| 853 | - PceccTunnelInfo tunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | 736 | + if (isLinkShared) { |
| 854 | - if (tunnelInfo == null || tunnelInfo.tunnelConsumerId() == null) { | 737 | + releaseSharedBandwidth(newTunnel, tunnel); |
| 855 | - //If bandwidth for old tunnel is not allocated i,e 0 then no need to release | ||
| 856 | return; | 738 | return; |
| 857 | } | 739 | } |
| 858 | - resourceService.release(tunnelInfo.tunnelConsumerId()); | ||
| 859 | - return; | ||
| 860 | 740 | ||
| 741 | + resourceService.release(tunnelConsumerId); | ||
| 861 | /* | 742 | /* |
| 862 | * Note: Storing of tunnel consumer id is done by caller of bandwidth reservation function. So deleting tunnel | 743 | * Note: Storing of tunnel consumer id is done by caller of bandwidth reservation function. So deleting tunnel |
| 863 | * consumer id should be done by caller of bandwidth releasing function. This will prevent ambiguities related | 744 | * consumer id should be done by caller of bandwidth releasing function. This will prevent ambiguities related |
| ... | @@ -871,16 +752,15 @@ public class PceManager implements PceService { | ... | @@ -871,16 +752,15 @@ public class PceManager implements PceService { |
| 871 | */ | 752 | */ |
| 872 | private synchronized void releaseSharedBandwidth(Tunnel newTunnel, Tunnel oldTunnel) { | 753 | private synchronized void releaseSharedBandwidth(Tunnel newTunnel, Tunnel oldTunnel) { |
| 873 | // 1. Release old tunnel's bandwidth. | 754 | // 1. Release old tunnel's bandwidth. |
| 874 | - resourceService.release(pceStore.getTunnelInfo(oldTunnel.tunnelId()).tunnelConsumerId()); | 755 | + resourceService.release(pceStore.getTunnelInfo(oldTunnel.tunnelId())); |
| 875 | 756 | ||
| 876 | // 2. Release new tunnel's bandwidth, if new tunnel bandwidth is allocated | 757 | // 2. Release new tunnel's bandwidth, if new tunnel bandwidth is allocated |
| 877 | - PceccTunnelInfo tunnelInfo = pceStore.getTunnelInfo(newTunnel.tunnelId()); | 758 | + ResourceConsumer consumer = pceStore.getTunnelInfo(newTunnel.tunnelId()); |
| 878 | - if (tunnelInfo == null || tunnelInfo.tunnelConsumerId() == null) { | 759 | + if (consumer == null) { |
| 879 | //If bandwidth for new tunnel is not allocated i,e 0 then no need to allocate | 760 | //If bandwidth for new tunnel is not allocated i,e 0 then no need to allocate |
| 880 | return; | 761 | return; |
| 881 | } | 762 | } |
| 882 | 763 | ||
| 883 | - ResourceConsumer consumer = tunnelInfo.tunnelConsumerId(); | ||
| 884 | resourceService.release(consumer); | 764 | resourceService.release(consumer); |
| 885 | 765 | ||
| 886 | // 3. Allocate new tunnel's complete bandwidth. | 766 | // 3. Allocate new tunnel's complete bandwidth. |
| ... | @@ -895,245 +775,6 @@ public class PceManager implements PceService { | ... | @@ -895,245 +775,6 @@ public class PceManager implements PceService { |
| 895 | } | 775 | } |
| 896 | } | 776 | } |
| 897 | 777 | ||
| 898 | - /** | ||
| 899 | - * Allocates node label to specific device. | ||
| 900 | - * | ||
| 901 | - * @param specificDevice device to which node label needs to be allocated | ||
| 902 | - */ | ||
| 903 | - public void allocateNodeLabel(Device specificDevice) { | ||
| 904 | - checkNotNull(specificDevice, DEVICE_NULL); | ||
| 905 | - | ||
| 906 | - DeviceId deviceId = specificDevice.id(); | ||
| 907 | - | ||
| 908 | - // Retrieve lsrId of a specific device | ||
| 909 | - if (specificDevice.annotations() == null) { | ||
| 910 | - log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 911 | - return; | ||
| 912 | - } | ||
| 913 | - | ||
| 914 | - String lsrId = specificDevice.annotations().value(LSRID); | ||
| 915 | - if (lsrId == null) { | ||
| 916 | - log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 917 | - return; | ||
| 918 | - } | ||
| 919 | - | ||
| 920 | - // Get capability config from netconfig | ||
| 921 | - DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 922 | - if (cfg == null) { | ||
| 923 | - log.error("Unable to find corresponding capability for a lsrd {} from NetConfig.", lsrId); | ||
| 924 | - // Save info. When PCEP session is comes up then allocate node-label | ||
| 925 | - lsrIdDeviceIdMap.put(lsrId, specificDevice.id()); | ||
| 926 | - return; | ||
| 927 | - } | ||
| 928 | - | ||
| 929 | - // Check whether device has SR-TE Capability | ||
| 930 | - if (cfg.labelStackCap()) { | ||
| 931 | - srTeHandler.allocateNodeLabel(deviceId, lsrId); | ||
| 932 | - } | ||
| 933 | - } | ||
| 934 | - | ||
| 935 | - /** | ||
| 936 | - * Releases node label of a specific device. | ||
| 937 | - * | ||
| 938 | - * @param specificDevice this device label and lsr-id information will be | ||
| 939 | - * released in other existing devices | ||
| 940 | - */ | ||
| 941 | - public void releaseNodeLabel(Device specificDevice) { | ||
| 942 | - checkNotNull(specificDevice, DEVICE_NULL); | ||
| 943 | - | ||
| 944 | - DeviceId deviceId = specificDevice.id(); | ||
| 945 | - | ||
| 946 | - // Retrieve lsrId of a specific device | ||
| 947 | - if (specificDevice.annotations() == null) { | ||
| 948 | - log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 949 | - return; | ||
| 950 | - } | ||
| 951 | - | ||
| 952 | - String lsrId = specificDevice.annotations().value(LSRID); | ||
| 953 | - if (lsrId == null) { | ||
| 954 | - log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 955 | - return; | ||
| 956 | - } | ||
| 957 | - | ||
| 958 | - // Get capability config from netconfig | ||
| 959 | - DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 960 | - if (cfg == null) { | ||
| 961 | - log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId); | ||
| 962 | - return; | ||
| 963 | - } | ||
| 964 | - | ||
| 965 | - // Check whether device has SR-TE Capability | ||
| 966 | - if (cfg.labelStackCap()) { | ||
| 967 | - if (!srTeHandler.releaseNodeLabel(deviceId, lsrId)) { | ||
| 968 | - log.error("Unable to release node label for a device id {}.", deviceId.toString()); | ||
| 969 | - } | ||
| 970 | - } | ||
| 971 | - } | ||
| 972 | - | ||
| 973 | - /** | ||
| 974 | - * Allocates adjacency label for a link. | ||
| 975 | - * | ||
| 976 | - * @param link link | ||
| 977 | - */ | ||
| 978 | - public void allocateAdjacencyLabel(Link link) { | ||
| 979 | - checkNotNull(link, LINK_NULL); | ||
| 980 | - | ||
| 981 | - Device specificDevice = deviceService.getDevice(link.src().deviceId()); | ||
| 982 | - DeviceId deviceId = specificDevice.id(); | ||
| 983 | - | ||
| 984 | - // Retrieve lsrId of a specific device | ||
| 985 | - if (specificDevice.annotations() == null) { | ||
| 986 | - log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 987 | - return; | ||
| 988 | - } | ||
| 989 | - | ||
| 990 | - String lsrId = specificDevice.annotations().value(LSRID); | ||
| 991 | - if (lsrId == null) { | ||
| 992 | - log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 993 | - return; | ||
| 994 | - } | ||
| 995 | - | ||
| 996 | - // Get capability config from netconfig | ||
| 997 | - DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 998 | - if (cfg == null) { | ||
| 999 | - log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId); | ||
| 1000 | - // Save info. When PCEP session comes up then allocate adjacency | ||
| 1001 | - // label | ||
| 1002 | - if (lsrIdDeviceIdMap.get(lsrId) != null) { | ||
| 1003 | - lsrIdDeviceIdMap.put(lsrId, specificDevice.id()); | ||
| 1004 | - } | ||
| 1005 | - return; | ||
| 1006 | - } | ||
| 1007 | - | ||
| 1008 | - // Check whether device has SR-TE Capability | ||
| 1009 | - if (cfg.labelStackCap()) { | ||
| 1010 | - srTeHandler.allocateAdjacencyLabel(link); | ||
| 1011 | - } | ||
| 1012 | - | ||
| 1013 | - return; | ||
| 1014 | - } | ||
| 1015 | - | ||
| 1016 | - /** | ||
| 1017 | - * Releases allocated adjacency label of a link. | ||
| 1018 | - * | ||
| 1019 | - * @param link link | ||
| 1020 | - */ | ||
| 1021 | - public void releaseAdjacencyLabel(Link link) { | ||
| 1022 | - checkNotNull(link, LINK_NULL); | ||
| 1023 | - | ||
| 1024 | - Device specificDevice = deviceService.getDevice(link.src().deviceId()); | ||
| 1025 | - DeviceId deviceId = specificDevice.id(); | ||
| 1026 | - | ||
| 1027 | - // Retrieve lsrId of a specific device | ||
| 1028 | - if (specificDevice.annotations() == null) { | ||
| 1029 | - log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 1030 | - return; | ||
| 1031 | - } | ||
| 1032 | - | ||
| 1033 | - String lsrId = specificDevice.annotations().value(LSRID); | ||
| 1034 | - if (lsrId == null) { | ||
| 1035 | - log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 1036 | - return; | ||
| 1037 | - } | ||
| 1038 | - | ||
| 1039 | - // Get capability config from netconfig | ||
| 1040 | - DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 1041 | - if (cfg == null) { | ||
| 1042 | - log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId); | ||
| 1043 | - return; | ||
| 1044 | - } | ||
| 1045 | - | ||
| 1046 | - // Check whether device has SR-TE Capability | ||
| 1047 | - if (cfg.labelStackCap()) { | ||
| 1048 | - if (!srTeHandler.releaseAdjacencyLabel(link)) { | ||
| 1049 | - log.error("Unable to release adjacency labels for a link {}.", link.toString()); | ||
| 1050 | - return; | ||
| 1051 | - } | ||
| 1052 | - } | ||
| 1053 | - | ||
| 1054 | - return; | ||
| 1055 | - } | ||
| 1056 | - | ||
| 1057 | - /* | ||
| 1058 | - * Handle device events. | ||
| 1059 | - */ | ||
| 1060 | - private class InternalDeviceListener implements DeviceListener { | ||
| 1061 | - @Override | ||
| 1062 | - public void event(DeviceEvent event) { | ||
| 1063 | - Device specificDevice = (Device) event.subject(); | ||
| 1064 | - if (specificDevice == null) { | ||
| 1065 | - log.error("Unable to find device from device event."); | ||
| 1066 | - return; | ||
| 1067 | - } | ||
| 1068 | - | ||
| 1069 | - switch (event.type()) { | ||
| 1070 | - | ||
| 1071 | - case DEVICE_ADDED: | ||
| 1072 | - // Node-label allocation is being done during Label DB Sync. | ||
| 1073 | - // So, when device is detected, no need to do node-label | ||
| 1074 | - // allocation. | ||
| 1075 | - String lsrId = specificDevice.annotations().value(LSRID); | ||
| 1076 | - if (lsrId != null) { | ||
| 1077 | - pceStore.addLsrIdDevice(lsrId, specificDevice.id()); | ||
| 1078 | - | ||
| 1079 | - // Search in failed DB sync store. If found, trigger label DB sync. | ||
| 1080 | - DeviceId pccDeviceId = DeviceId.deviceId(lsrId); | ||
| 1081 | - if (pceStore.hasPccLsr(pccDeviceId)) { | ||
| 1082 | - log.debug("Continue to perform label DB sync for device {}.", pccDeviceId.toString()); | ||
| 1083 | - syncLabelDb(pccDeviceId); | ||
| 1084 | - pceStore.removePccLsr(pccDeviceId); | ||
| 1085 | - } | ||
| 1086 | - } | ||
| 1087 | - break; | ||
| 1088 | - | ||
| 1089 | - case DEVICE_REMOVED: | ||
| 1090 | - // Release node-label | ||
| 1091 | - if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) { | ||
| 1092 | - releaseNodeLabel(specificDevice); | ||
| 1093 | - } | ||
| 1094 | - | ||
| 1095 | - if (specificDevice.annotations().value(LSRID) != null) { | ||
| 1096 | - pceStore.removeLsrIdDevice(specificDevice.annotations().value(LSRID)); | ||
| 1097 | - } | ||
| 1098 | - | ||
| 1099 | - break; | ||
| 1100 | - | ||
| 1101 | - default: | ||
| 1102 | - break; | ||
| 1103 | - } | ||
| 1104 | - } | ||
| 1105 | - } | ||
| 1106 | - | ||
| 1107 | - /* | ||
| 1108 | - * Handle link events. | ||
| 1109 | - */ | ||
| 1110 | - private class InternalLinkListener implements LinkListener { | ||
| 1111 | - @Override | ||
| 1112 | - public void event(LinkEvent event) { | ||
| 1113 | - Link link = (Link) event.subject(); | ||
| 1114 | - | ||
| 1115 | - switch (event.type()) { | ||
| 1116 | - | ||
| 1117 | - case LINK_ADDED: | ||
| 1118 | - // Allocate adjacency label | ||
| 1119 | - if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) { | ||
| 1120 | - allocateAdjacencyLabel(link); | ||
| 1121 | - } | ||
| 1122 | - break; | ||
| 1123 | - | ||
| 1124 | - case LINK_REMOVED: | ||
| 1125 | - // Release adjacency label | ||
| 1126 | - if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) { | ||
| 1127 | - releaseAdjacencyLabel(link); | ||
| 1128 | - } | ||
| 1129 | - break; | ||
| 1130 | - | ||
| 1131 | - default: | ||
| 1132 | - break; | ||
| 1133 | - } | ||
| 1134 | - } | ||
| 1135 | - } | ||
| 1136 | - | ||
| 1137 | // Listens on tunnel events. | 778 | // Listens on tunnel events. |
| 1138 | private class InnerTunnelListener implements TunnelListener { | 779 | private class InnerTunnelListener implements TunnelListener { |
| 1139 | @Override | 780 | @Override |
| ... | @@ -1155,37 +796,16 @@ public class PceManager implements PceService { | ... | @@ -1155,37 +796,16 @@ public class PceManager implements PceService { |
| 1155 | case TUNNEL_ADDED: | 796 | case TUNNEL_ADDED: |
| 1156 | // Allocate bandwidth for non-initiated, delegated LSPs with non-zero bandwidth (learned LSPs). | 797 | // Allocate bandwidth for non-initiated, delegated LSPs with non-zero bandwidth (learned LSPs). |
| 1157 | String pceInit = tunnel.annotations().value(PCE_INIT); | 798 | String pceInit = tunnel.annotations().value(PCE_INIT); |
| 1158 | - if (FALSE.equalsIgnoreCase(pceInit) | 799 | + if (FALSE.equalsIgnoreCase(pceInit) && bwConstraintValue != 0) { |
| 1159 | - && bwConstraintValue != 0) { | 800 | + TunnelConsumerId consumerId = reserveBandwidth(tunnel.path(), bwConstraintValue, null); |
| 1160 | - reserveBandwidth(tunnel.path(), bwConstraintValue, null); | 801 | + if (consumerId != null) { |
| 802 | + // Store tunnel consumer id in LSP store. | ||
| 803 | + pceStore.addTunnelInfo(tunnel.tunnelId(), consumerId); | ||
| 804 | + } | ||
| 1161 | } | 805 | } |
| 1162 | break; | 806 | break; |
| 1163 | 807 | ||
| 1164 | case TUNNEL_UPDATED: | 808 | case TUNNEL_UPDATED: |
| 1165 | - // Allocate/send labels for basic PCECC tunnels. | ||
| 1166 | - if ((tunnel.state() == ESTABLISHED) && (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR) | ||
| 1167 | - && (mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER)) { | ||
| 1168 | - if (!crHandler.allocateLabel(tunnel)) { | ||
| 1169 | - log.error("Unable to allocate labels for a tunnel {}.", tunnel.toString()); | ||
| 1170 | - } | ||
| 1171 | - } | ||
| 1172 | - | ||
| 1173 | - //In CR case, release labels when new tunnel for it is updated. | ||
| 1174 | - if (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR && tunnel.state() == ACTIVE | ||
| 1175 | - && mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) { | ||
| 1176 | - Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst()); | ||
| 1177 | - | ||
| 1178 | - for (Tunnel t : tunnels) { | ||
| 1179 | - if (tunnel.annotations().value(PLSP_ID).equals(t.annotations().value(PLSP_ID)) | ||
| 1180 | - && !tunnel.annotations().value(LOCAL_LSP_ID) | ||
| 1181 | - .equals(t.annotations().value(LOCAL_LSP_ID))) { | ||
| 1182 | - // Release basic PCECC labels. | ||
| 1183 | - crHandler.releaseLabel(t); | ||
| 1184 | - break; | ||
| 1185 | - } | ||
| 1186 | - } | ||
| 1187 | - } | ||
| 1188 | - | ||
| 1189 | if (tunnel.state() == UNSTABLE) { | 809 | if (tunnel.state() == UNSTABLE) { |
| 1190 | /* | 810 | /* |
| 1191 | * During LSP DB sync if PCC doesn't report LSP which was PCE initiated, it's state is turned into | 811 | * During LSP DB sync if PCC doesn't report LSP which was PCE initiated, it's state is turned into |
| ... | @@ -1241,164 +861,6 @@ public class PceManager implements PceService { | ... | @@ -1241,164 +861,6 @@ public class PceManager implements PceService { |
| 1241 | } | 861 | } |
| 1242 | } | 862 | } |
| 1243 | 863 | ||
| 1244 | - private class InternalConfigListener implements NetworkConfigListener { | ||
| 1245 | - | ||
| 1246 | - @Override | ||
| 1247 | - public void event(NetworkConfigEvent event) { | ||
| 1248 | - | ||
| 1249 | - if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) | ||
| 1250 | - && event.configClass().equals(DeviceCapability.class)) { | ||
| 1251 | - | ||
| 1252 | - DeviceId deviceIdLsrId = (DeviceId) event.subject(); | ||
| 1253 | - String lsrId = deviceIdLsrId.toString(); | ||
| 1254 | - DeviceId deviceId = lsrIdDeviceIdMap.get(lsrId); | ||
| 1255 | - if (deviceId == null) { | ||
| 1256 | - log.debug("Unable to find device id for a lsr-id {} from lsr-id and device-id map.", lsrId); | ||
| 1257 | - return; | ||
| 1258 | - } | ||
| 1259 | - | ||
| 1260 | - DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 1261 | - if (cfg == null) { | ||
| 1262 | - log.error("Unable to find corresponding capabilty for a lsrd {}.", lsrId); | ||
| 1263 | - return; | ||
| 1264 | - } | ||
| 1265 | - | ||
| 1266 | - if (cfg.labelStackCap()) { | ||
| 1267 | - if (mastershipService.getLocalRole(deviceId) == MastershipRole.MASTER) { | ||
| 1268 | - // Allocate node-label | ||
| 1269 | - srTeHandler.allocateNodeLabel(deviceId, lsrId); | ||
| 1270 | - | ||
| 1271 | - // Allocate adjacency label to links which are | ||
| 1272 | - // originated from this specific device id | ||
| 1273 | - Set<Link> links = linkService.getDeviceEgressLinks(deviceId); | ||
| 1274 | - for (Link link : links) { | ||
| 1275 | - if (!srTeHandler.allocateAdjacencyLabel(link)) { | ||
| 1276 | - return; | ||
| 1277 | - } | ||
| 1278 | - } | ||
| 1279 | - } | ||
| 1280 | - } | ||
| 1281 | - | ||
| 1282 | - // Remove lsrId info from map | ||
| 1283 | - lsrIdDeviceIdMap.remove(lsrId); | ||
| 1284 | - } | ||
| 1285 | - } | ||
| 1286 | - } | ||
| 1287 | - | ||
| 1288 | - private boolean syncLabelDb(DeviceId deviceId) { | ||
| 1289 | - checkNotNull(deviceId); | ||
| 1290 | - | ||
| 1291 | - DeviceId actualDevcieId = pceStore.getLsrIdDevice(deviceId.toString()); | ||
| 1292 | - if (actualDevcieId == null) { | ||
| 1293 | - log.error("Device not available {}.", deviceId.toString()); | ||
| 1294 | - pceStore.addPccLsr(deviceId); | ||
| 1295 | - return false; | ||
| 1296 | - } | ||
| 1297 | - | ||
| 1298 | - Device specificDevice = deviceService.getDevice(actualDevcieId); | ||
| 1299 | - if (specificDevice == null) { | ||
| 1300 | - log.error("Unable to find device for specific device id {}.", actualDevcieId.toString()); | ||
| 1301 | - return false; | ||
| 1302 | - } | ||
| 1303 | - | ||
| 1304 | - if (pceStore.getGlobalNodeLabel(actualDevcieId) != null) { | ||
| 1305 | - Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels(); | ||
| 1306 | - | ||
| 1307 | - for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) { | ||
| 1308 | - | ||
| 1309 | - // Convert from DeviceId to TunnelEndPoint | ||
| 1310 | - Device srcDevice = deviceService.getDevice(entry.getKey()); | ||
| 1311 | - | ||
| 1312 | - /* | ||
| 1313 | - * If there is a slight difference in timing such that if device subsystem has removed the device but | ||
| 1314 | - * PCE store still has it, just ignore such devices. | ||
| 1315 | - */ | ||
| 1316 | - if (srcDevice == null) { | ||
| 1317 | - continue; | ||
| 1318 | - } | ||
| 1319 | - | ||
| 1320 | - String srcLsrId = srcDevice.annotations().value(LSRID); | ||
| 1321 | - if (srcLsrId == null) { | ||
| 1322 | - continue; | ||
| 1323 | - } | ||
| 1324 | - | ||
| 1325 | - srTeHandler.advertiseNodeLabelRule(actualDevcieId, | ||
| 1326 | - entry.getValue(), | ||
| 1327 | - IpPrefix.valueOf(IpAddress.valueOf(srcLsrId), PREFIX_LENGTH), | ||
| 1328 | - Objective.Operation.ADD, false); | ||
| 1329 | - } | ||
| 1330 | - | ||
| 1331 | - Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels(); | ||
| 1332 | - for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) { | ||
| 1333 | - if (entry.getKey().src().deviceId().equals(actualDevcieId)) { | ||
| 1334 | - srTeHandler.installAdjLabelRule(actualDevcieId, | ||
| 1335 | - entry.getValue(), | ||
| 1336 | - entry.getKey().src().port(), | ||
| 1337 | - entry.getKey().dst().port(), | ||
| 1338 | - Objective.Operation.ADD); | ||
| 1339 | - } | ||
| 1340 | - } | ||
| 1341 | - } | ||
| 1342 | - | ||
| 1343 | - srTeHandler.advertiseNodeLabelRule(actualDevcieId, | ||
| 1344 | - LabelResourceId.labelResourceId(0), | ||
| 1345 | - IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX), | ||
| 1346 | - Objective.Operation.ADD, true); | ||
| 1347 | - | ||
| 1348 | - log.debug("End of label DB sync for device {}", actualDevcieId); | ||
| 1349 | - | ||
| 1350 | - if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) { | ||
| 1351 | - // Allocate node-label to this specific device. | ||
| 1352 | - allocateNodeLabel(specificDevice); | ||
| 1353 | - | ||
| 1354 | - // Allocate adjacency label | ||
| 1355 | - Set<Link> links = linkService.getDeviceEgressLinks(specificDevice.id()); | ||
| 1356 | - if (links != null) { | ||
| 1357 | - for (Link link : links) { | ||
| 1358 | - allocateAdjacencyLabel(link); | ||
| 1359 | - } | ||
| 1360 | - } | ||
| 1361 | - } | ||
| 1362 | - | ||
| 1363 | - return true; | ||
| 1364 | - } | ||
| 1365 | - | ||
| 1366 | - // Process the packet received. | ||
| 1367 | - private class PcepPacketProcessor implements PacketProcessor { | ||
| 1368 | - // Process the packet received and in our case initiates the label DB sync. | ||
| 1369 | - @Override | ||
| 1370 | - public void process(PacketContext context) { | ||
| 1371 | - // Stop processing if the packet has been handled, since we | ||
| 1372 | - // can't do any more to it. | ||
| 1373 | - log.debug("Received trigger for label DB sync."); | ||
| 1374 | - if (context.isHandled()) { | ||
| 1375 | - return; | ||
| 1376 | - } | ||
| 1377 | - | ||
| 1378 | - InboundPacket pkt = context.inPacket(); | ||
| 1379 | - if (pkt == null) { | ||
| 1380 | - return; | ||
| 1381 | - } | ||
| 1382 | - | ||
| 1383 | - Ethernet ethernet = pkt.parsed(); | ||
| 1384 | - if (ethernet == null || ethernet.getEtherType() != Ethernet.TYPE_IPV4) { | ||
| 1385 | - return; | ||
| 1386 | - } | ||
| 1387 | - | ||
| 1388 | - IPv4 ipPacket = (IPv4) ethernet.getPayload(); | ||
| 1389 | - if (ipPacket == null || ipPacket.getProtocol() != IPv4.PROTOCOL_TCP) { | ||
| 1390 | - return; | ||
| 1391 | - } | ||
| 1392 | - | ||
| 1393 | - TCP tcp = (TCP) ipPacket.getPayload(); | ||
| 1394 | - if (tcp == null || tcp.getDestinationPort() != PCEP_PORT) { | ||
| 1395 | - return; | ||
| 1396 | - } | ||
| 1397 | - | ||
| 1398 | - syncLabelDb(pkt.receivedFrom().deviceId()); | ||
| 1399 | - } | ||
| 1400 | - } | ||
| 1401 | - | ||
| 1402 | //Computes path from tunnel store and also path failed to setup. | 864 | //Computes path from tunnel store and also path failed to setup. |
| 1403 | private void callForOptimization() { | 865 | private void callForOptimization() { |
| 1404 | //Recompute the LSPs which it was delegated [LSPs stored in PCE store (failed paths)] | 866 | //Recompute the LSPs which it was delegated [LSPs stored in PCE store (failed paths)] | ... | ... |
| ... | @@ -19,9 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -19,9 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | 19 | ||
| 20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
| 21 | 21 | ||
| 22 | -import java.util.HashMap; | ||
| 23 | -import java.util.HashSet; | ||
| 24 | -import java.util.List; | ||
| 25 | import java.util.Map; | 22 | import java.util.Map; |
| 26 | import java.util.stream.Collectors; | 23 | import java.util.stream.Collectors; |
| 27 | 24 | ||
| ... | @@ -34,18 +31,13 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -34,18 +31,13 @@ import org.apache.felix.scr.annotations.Service; |
| 34 | 31 | ||
| 35 | import org.onlab.util.KryoNamespace; | 32 | import org.onlab.util.KryoNamespace; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelId; | 33 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 37 | -import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 38 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 39 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 34 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 40 | -import org.onosproject.net.DeviceId; | ||
| 41 | -import org.onosproject.net.Link; | ||
| 42 | import org.onosproject.net.resource.ResourceConsumer; | 35 | import org.onosproject.net.resource.ResourceConsumer; |
| 43 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; | 36 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; |
| 44 | import org.onosproject.pce.pceservice.constraint.CostConstraint; | 37 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
| 45 | import org.onosproject.pce.pceservice.TunnelConsumerId; | 38 | import org.onosproject.pce.pceservice.TunnelConsumerId; |
| 46 | import org.onosproject.pce.pceservice.LspType; | 39 | import org.onosproject.pce.pceservice.LspType; |
| 47 | import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; | 40 | import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; |
| 48 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 49 | import org.onosproject.pce.pcestore.api.PceStore; | 41 | import org.onosproject.pce.pcestore.api.PceStore; |
| 50 | import org.onosproject.store.serializers.KryoNamespaces; | 42 | import org.onosproject.store.serializers.KryoNamespaces; |
| 51 | import org.onosproject.store.service.ConsistentMap; | 43 | import org.onosproject.store.service.ConsistentMap; |
| ... | @@ -62,42 +54,21 @@ import org.slf4j.LoggerFactory; | ... | @@ -62,42 +54,21 @@ import org.slf4j.LoggerFactory; |
| 62 | @Component(immediate = true) | 54 | @Component(immediate = true) |
| 63 | @Service | 55 | @Service |
| 64 | public class DistributedPceStore implements PceStore { | 56 | public class DistributedPceStore implements PceStore { |
| 65 | - | ||
| 66 | - private static final String DEVICE_ID_NULL = "Device ID cannot be null"; | ||
| 67 | - private static final String DEVICE_LABEL_STORE_INFO_NULL = "Device Label Store cannot be null"; | ||
| 68 | - private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null"; | ||
| 69 | - private static final String LABEL_RESOURCE_LIST_NULL = "Label Resource List cannot be null"; | ||
| 70 | - private static final String LABEL_RESOURCE_NULL = "Label Resource cannot be null"; | ||
| 71 | - private static final String LINK_NULL = "LINK cannot be null"; | ||
| 72 | - private static final String LSP_LOCAL_LABEL_INFO_NULL = "LSP Local Label Info cannot be null"; | ||
| 73 | private static final String PATH_INFO_NULL = "Path Info cannot be null"; | 57 | private static final String PATH_INFO_NULL = "Path Info cannot be null"; |
| 74 | private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null"; | 58 | private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null"; |
| 75 | private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null"; | 59 | private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null"; |
| 76 | - private static final String TUNNEL_CONSUMER_ID_NULL = "Tunnel consumer Id cannot be null"; | ||
| 77 | 60 | ||
| 78 | private final Logger log = LoggerFactory.getLogger(getClass()); | 61 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 79 | 62 | ||
| 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 63 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 81 | protected StorageService storageService; | 64 | protected StorageService storageService; |
| 82 | 65 | ||
| 83 | - // Mapping device with global node label | ||
| 84 | - private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap; | ||
| 85 | - | ||
| 86 | - // Mapping link with adjacency label | ||
| 87 | - private ConsistentMap<Link, LabelResourceId> adjLabelMap; | ||
| 88 | - | ||
| 89 | // Mapping tunnel with device local info with tunnel consumer id | 66 | // Mapping tunnel with device local info with tunnel consumer id |
| 90 | - private ConsistentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap; | 67 | + private ConsistentMap<TunnelId, ResourceConsumer> tunnelInfoMap; |
| 91 | 68 | ||
| 92 | // List of Failed path info | 69 | // List of Failed path info |
| 93 | private DistributedSet<PcePathInfo> failedPathSet; | 70 | private DistributedSet<PcePathInfo> failedPathSet; |
| 94 | 71 | ||
| 95 | - // Locally maintain LSRID to device id mapping for better performance. | ||
| 96 | - private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); | ||
| 97 | - | ||
| 98 | - // List of PCC LSR ids whose BGP device information was not available to perform | ||
| 99 | - // label db sync. | ||
| 100 | - private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet(); | ||
| 101 | private static final Serializer SERIALIZER = Serializer | 72 | private static final Serializer SERIALIZER = Serializer |
| 102 | .using(new KryoNamespace.Builder().register(KryoNamespaces.API) | 73 | .using(new KryoNamespace.Builder().register(KryoNamespaces.API) |
| 103 | .register(PcePathInfo.class) | 74 | .register(PcePathInfo.class) |
| ... | @@ -112,36 +83,13 @@ public class DistributedPceStore implements PceStore { | ... | @@ -112,36 +83,13 @@ public class DistributedPceStore implements PceStore { |
| 112 | 83 | ||
| 113 | @Activate | 84 | @Activate |
| 114 | protected void activate() { | 85 | protected void activate() { |
| 115 | - globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder() | 86 | + tunnelInfoMap = storageService.<TunnelId, ResourceConsumer>consistentMapBuilder() |
| 116 | - .withName("onos-pce-globalnodelabelmap") | ||
| 117 | - .withSerializer(Serializer.using( | ||
| 118 | - new KryoNamespace.Builder() | ||
| 119 | - .register(KryoNamespaces.API) | ||
| 120 | - .register(LabelResourceId.class) | ||
| 121 | - .build())) | ||
| 122 | - .build(); | ||
| 123 | - | ||
| 124 | - adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder() | ||
| 125 | - .withName("onos-pce-adjlabelmap") | ||
| 126 | - .withSerializer(Serializer.using( | ||
| 127 | - new KryoNamespace.Builder() | ||
| 128 | - .register(KryoNamespaces.API) | ||
| 129 | - .register(Link.class, | ||
| 130 | - LabelResource.class, | ||
| 131 | - LabelResourceId.class) | ||
| 132 | - .build())) | ||
| 133 | - .build(); | ||
| 134 | - | ||
| 135 | - tunnelInfoMap = storageService.<TunnelId, PceccTunnelInfo>consistentMapBuilder() | ||
| 136 | .withName("onos-pce-tunnelinfomap") | 87 | .withName("onos-pce-tunnelinfomap") |
| 137 | .withSerializer(Serializer.using( | 88 | .withSerializer(Serializer.using( |
| 138 | new KryoNamespace.Builder() | 89 | new KryoNamespace.Builder() |
| 139 | .register(KryoNamespaces.API) | 90 | .register(KryoNamespaces.API) |
| 140 | .register(TunnelId.class, | 91 | .register(TunnelId.class, |
| 141 | - PceccTunnelInfo.class, | 92 | + TunnelConsumerId.class) |
| 142 | - DefaultLspLocalLabelInfo.class, | ||
| 143 | - TunnelConsumerId.class, | ||
| 144 | - LabelResourceId.class) | ||
| 145 | .build())) | 93 | .build())) |
| 146 | .build(); | 94 | .build(); |
| 147 | 95 | ||
| ... | @@ -160,18 +108,6 @@ public class DistributedPceStore implements PceStore { | ... | @@ -160,18 +108,6 @@ public class DistributedPceStore implements PceStore { |
| 160 | } | 108 | } |
| 161 | 109 | ||
| 162 | @Override | 110 | @Override |
| 163 | - public boolean existsGlobalNodeLabel(DeviceId id) { | ||
| 164 | - checkNotNull(id, DEVICE_ID_NULL); | ||
| 165 | - return globalNodeLabelMap.containsKey(id); | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - @Override | ||
| 169 | - public boolean existsAdjLabel(Link link) { | ||
| 170 | - checkNotNull(link, LINK_NULL); | ||
| 171 | - return adjLabelMap.containsKey(link); | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - @Override | ||
| 175 | public boolean existsTunnelInfo(TunnelId tunnelId) { | 111 | public boolean existsTunnelInfo(TunnelId tunnelId) { |
| 176 | checkNotNull(tunnelId, TUNNEL_ID_NULL); | 112 | checkNotNull(tunnelId, TUNNEL_ID_NULL); |
| 177 | return tunnelInfoMap.containsKey(tunnelId); | 113 | return tunnelInfoMap.containsKey(tunnelId); |
| ... | @@ -184,16 +120,6 @@ public class DistributedPceStore implements PceStore { | ... | @@ -184,16 +120,6 @@ public class DistributedPceStore implements PceStore { |
| 184 | } | 120 | } |
| 185 | 121 | ||
| 186 | @Override | 122 | @Override |
| 187 | - public int getGlobalNodeLabelCount() { | ||
| 188 | - return globalNodeLabelMap.size(); | ||
| 189 | - } | ||
| 190 | - | ||
| 191 | - @Override | ||
| 192 | - public int getAdjLabelCount() { | ||
| 193 | - return adjLabelMap.size(); | ||
| 194 | - } | ||
| 195 | - | ||
| 196 | - @Override | ||
| 197 | public int getTunnelInfoCount() { | 123 | public int getTunnelInfoCount() { |
| 198 | return tunnelInfoMap.size(); | 124 | return tunnelInfoMap.size(); |
| 199 | } | 125 | } |
| ... | @@ -204,21 +130,9 @@ public class DistributedPceStore implements PceStore { | ... | @@ -204,21 +130,9 @@ public class DistributedPceStore implements PceStore { |
| 204 | } | 130 | } |
| 205 | 131 | ||
| 206 | @Override | 132 | @Override |
| 207 | - public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() { | 133 | + public Map<TunnelId, ResourceConsumer> getTunnelInfos() { |
| 208 | - return globalNodeLabelMap.entrySet().stream() | ||
| 209 | - .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value())); | ||
| 210 | - } | ||
| 211 | - | ||
| 212 | - @Override | ||
| 213 | - public Map<Link, LabelResourceId> getAdjLabels() { | ||
| 214 | - return adjLabelMap.entrySet().stream() | ||
| 215 | - .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue().value())); | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - @Override | ||
| 219 | - public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() { | ||
| 220 | return tunnelInfoMap.entrySet().stream() | 134 | return tunnelInfoMap.entrySet().stream() |
| 221 | - .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue().value())); | 135 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value())); |
| 222 | } | 136 | } |
| 223 | 137 | ||
| 224 | @Override | 138 | @Override |
| ... | @@ -227,45 +141,17 @@ public class DistributedPceStore implements PceStore { | ... | @@ -227,45 +141,17 @@ public class DistributedPceStore implements PceStore { |
| 227 | } | 141 | } |
| 228 | 142 | ||
| 229 | @Override | 143 | @Override |
| 230 | - public LabelResourceId getGlobalNodeLabel(DeviceId id) { | 144 | + public ResourceConsumer getTunnelInfo(TunnelId tunnelId) { |
| 231 | - checkNotNull(id, DEVICE_ID_NULL); | ||
| 232 | - return globalNodeLabelMap.get(id) == null ? null : globalNodeLabelMap.get(id).value(); | ||
| 233 | - } | ||
| 234 | - | ||
| 235 | - @Override | ||
| 236 | - public LabelResourceId getAdjLabel(Link link) { | ||
| 237 | - checkNotNull(link, LINK_NULL); | ||
| 238 | - return adjLabelMap.get(link) == null ? null : adjLabelMap.get(link).value(); | ||
| 239 | - } | ||
| 240 | - | ||
| 241 | - @Override | ||
| 242 | - public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) { | ||
| 243 | checkNotNull(tunnelId, TUNNEL_ID_NULL); | 145 | checkNotNull(tunnelId, TUNNEL_ID_NULL); |
| 244 | return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value(); | 146 | return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value(); |
| 245 | } | 147 | } |
| 246 | 148 | ||
| 247 | @Override | 149 | @Override |
| 248 | - public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) { | 150 | + public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) { |
| 249 | - checkNotNull(deviceId, DEVICE_ID_NULL); | ||
| 250 | - checkNotNull(labelId, LABEL_RESOURCE_ID_NULL); | ||
| 251 | - | ||
| 252 | - globalNodeLabelMap.put(deviceId, labelId); | ||
| 253 | - } | ||
| 254 | - | ||
| 255 | - @Override | ||
| 256 | - public void addAdjLabel(Link link, LabelResourceId labelId) { | ||
| 257 | - checkNotNull(link, LINK_NULL); | ||
| 258 | - checkNotNull(labelId, LABEL_RESOURCE_ID_NULL); | ||
| 259 | - | ||
| 260 | - adjLabelMap.put(link, labelId); | ||
| 261 | - } | ||
| 262 | - | ||
| 263 | - @Override | ||
| 264 | - public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) { | ||
| 265 | checkNotNull(tunnelId, TUNNEL_ID_NULL); | 151 | checkNotNull(tunnelId, TUNNEL_ID_NULL); |
| 266 | - checkNotNull(pceccTunnelInfo, PCECC_TUNNEL_INFO_NULL); | 152 | + checkNotNull(tunnelConsumerId, PCECC_TUNNEL_INFO_NULL); |
| 267 | 153 | ||
| 268 | - tunnelInfoMap.put(tunnelId, pceccTunnelInfo); | 154 | + tunnelInfoMap.put(tunnelId, tunnelConsumerId); |
| 269 | } | 155 | } |
| 270 | 156 | ||
| 271 | @Override | 157 | @Override |
| ... | @@ -275,62 +161,6 @@ public class DistributedPceStore implements PceStore { | ... | @@ -275,62 +161,6 @@ public class DistributedPceStore implements PceStore { |
| 275 | } | 161 | } |
| 276 | 162 | ||
| 277 | @Override | 163 | @Override |
| 278 | - public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) { | ||
| 279 | - checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 280 | - checkNotNull(lspLocalLabelInfoList, LSP_LOCAL_LABEL_INFO_NULL); | ||
| 281 | - | ||
| 282 | - if (!tunnelInfoMap.containsKey((tunnelId))) { | ||
| 283 | - log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString()); | ||
| 284 | - return false; | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | - PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value(); | ||
| 288 | - tunnelInfo.lspLocalLabelInfoList(lspLocalLabelInfoList); | ||
| 289 | - tunnelInfoMap.put(tunnelId, tunnelInfo); | ||
| 290 | - | ||
| 291 | - return true; | ||
| 292 | - } | ||
| 293 | - | ||
| 294 | - @Override | ||
| 295 | - public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) { | ||
| 296 | - checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 297 | - checkNotNull(tunnelConsumerId, TUNNEL_CONSUMER_ID_NULL); | ||
| 298 | - | ||
| 299 | - if (!tunnelInfoMap.containsKey((tunnelId))) { | ||
| 300 | - log.debug("Tunnel info does not exist whose tunnel id is {}.", tunnelId.toString()); | ||
| 301 | - return false; | ||
| 302 | - } | ||
| 303 | - | ||
| 304 | - PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId).value(); | ||
| 305 | - tunnelInfo.tunnelConsumerId(tunnelConsumerId); | ||
| 306 | - tunnelInfoMap.put(tunnelId, tunnelInfo); | ||
| 307 | - | ||
| 308 | - return true; | ||
| 309 | - } | ||
| 310 | - | ||
| 311 | - @Override | ||
| 312 | - public boolean removeGlobalNodeLabel(DeviceId id) { | ||
| 313 | - checkNotNull(id, DEVICE_ID_NULL); | ||
| 314 | - | ||
| 315 | - if (globalNodeLabelMap.remove(id) == null) { | ||
| 316 | - log.error("SR-TE node label deletion for device {} has failed.", id.toString()); | ||
| 317 | - return false; | ||
| 318 | - } | ||
| 319 | - return true; | ||
| 320 | - } | ||
| 321 | - | ||
| 322 | - @Override | ||
| 323 | - public boolean removeAdjLabel(Link link) { | ||
| 324 | - checkNotNull(link, LINK_NULL); | ||
| 325 | - | ||
| 326 | - if (adjLabelMap.remove(link) == null) { | ||
| 327 | - log.error("Adjacency label deletion for link {} hash failed.", link.toString()); | ||
| 328 | - return false; | ||
| 329 | - } | ||
| 330 | - return true; | ||
| 331 | - } | ||
| 332 | - | ||
| 333 | - @Override | ||
| 334 | public boolean removeTunnelInfo(TunnelId tunnelId) { | 164 | public boolean removeTunnelInfo(TunnelId tunnelId) { |
| 335 | checkNotNull(tunnelId, TUNNEL_ID_NULL); | 165 | checkNotNull(tunnelId, TUNNEL_ID_NULL); |
| 336 | 166 | ||
| ... | @@ -351,50 +181,4 @@ public class DistributedPceStore implements PceStore { | ... | @@ -351,50 +181,4 @@ public class DistributedPceStore implements PceStore { |
| 351 | } | 181 | } |
| 352 | return true; | 182 | return true; |
| 353 | } | 183 | } |
| 354 | - | ||
| 355 | - @Override | ||
| 356 | - public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) { | ||
| 357 | - checkNotNull(lsrId); | ||
| 358 | - checkNotNull(deviceId); | ||
| 359 | - | ||
| 360 | - lsrIdDeviceIdMap.put(lsrId, deviceId); | ||
| 361 | - return true; | ||
| 362 | - } | ||
| 363 | - | ||
| 364 | - @Override | ||
| 365 | - public boolean removeLsrIdDevice(String lsrId) { | ||
| 366 | - checkNotNull(lsrId); | ||
| 367 | - | ||
| 368 | - lsrIdDeviceIdMap.remove(lsrId); | ||
| 369 | - return true; | ||
| 370 | - } | ||
| 371 | - | ||
| 372 | - @Override | ||
| 373 | - public DeviceId getLsrIdDevice(String lsrId) { | ||
| 374 | - checkNotNull(lsrId); | ||
| 375 | - | ||
| 376 | - return lsrIdDeviceIdMap.get(lsrId); | ||
| 377 | - | ||
| 378 | - } | ||
| 379 | - | ||
| 380 | - @Override | ||
| 381 | - public boolean addPccLsr(DeviceId lsrId) { | ||
| 382 | - checkNotNull(lsrId); | ||
| 383 | - pendinglabelDbSyncPccMap.add(lsrId); | ||
| 384 | - return true; | ||
| 385 | - } | ||
| 386 | - | ||
| 387 | - @Override | ||
| 388 | - public boolean removePccLsr(DeviceId lsrId) { | ||
| 389 | - checkNotNull(lsrId); | ||
| 390 | - pendinglabelDbSyncPccMap.remove(lsrId); | ||
| 391 | - return true; | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | - @Override | ||
| 395 | - public boolean hasPccLsr(DeviceId lsrId) { | ||
| 396 | - checkNotNull(lsrId); | ||
| 397 | - return pendinglabelDbSyncPccMap.contains(lsrId); | ||
| 398 | - | ||
| 399 | - } | ||
| 400 | } | 184 | } | ... | ... |
| 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 | -import java.util.List; | ||
| 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) | ||
| 119 | - .add("TunnelConsumerId", tunnelConsumerId) | ||
| 120 | - .toString(); | ||
| 121 | - } | ||
| 122 | -} |
| ... | @@ -15,14 +15,8 @@ | ... | @@ -15,14 +15,8 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.pce.pcestore.api; | 16 | package org.onosproject.pce.pcestore.api; |
| 17 | 17 | ||
| 18 | -import java.util.List; | ||
| 19 | - | ||
| 20 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 21 | import org.onosproject.incubator.net.tunnel.TunnelId; | 18 | 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; | 19 | import org.onosproject.net.resource.ResourceConsumer; |
| 25 | -import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 26 | import org.onosproject.pce.pcestore.PcePathInfo; | 20 | import org.onosproject.pce.pcestore.PcePathInfo; |
| 27 | 21 | ||
| 28 | import java.util.Map; | 22 | import java.util.Map; |
| ... | @@ -32,22 +26,6 @@ import java.util.Map; | ... | @@ -32,22 +26,6 @@ import java.util.Map; |
| 32 | */ | 26 | */ |
| 33 | public interface PceStore { | 27 | public interface PceStore { |
| 34 | /** | 28 | /** |
| 35 | - * Checks whether device id is present in global node label store. | ||
| 36 | - * | ||
| 37 | - * @param id device id | ||
| 38 | - * @return success of failure | ||
| 39 | - */ | ||
| 40 | - boolean existsGlobalNodeLabel(DeviceId id); | ||
| 41 | - | ||
| 42 | - /** | ||
| 43 | - * Checks whether link is present in adjacency label store. | ||
| 44 | - * | ||
| 45 | - * @param link link between devices | ||
| 46 | - * @return success of failure | ||
| 47 | - */ | ||
| 48 | - boolean existsAdjLabel(Link link); | ||
| 49 | - | ||
| 50 | - /** | ||
| 51 | * Checks whether tunnel id is present in tunnel info store. | 29 | * Checks whether tunnel id is present in tunnel info store. |
| 52 | * | 30 | * |
| 53 | * @param tunnelId tunnel id | 31 | * @param tunnelId tunnel id |
| ... | @@ -64,20 +42,6 @@ public interface PceStore { | ... | @@ -64,20 +42,6 @@ public interface PceStore { |
| 64 | boolean existsFailedPathInfo(PcePathInfo failedPathInfo); | 42 | boolean existsFailedPathInfo(PcePathInfo failedPathInfo); |
| 65 | 43 | ||
| 66 | /** | 44 | /** |
| 67 | - * Retrieves the node label count. | ||
| 68 | - * | ||
| 69 | - * @return node label count | ||
| 70 | - */ | ||
| 71 | - int getGlobalNodeLabelCount(); | ||
| 72 | - | ||
| 73 | - /** | ||
| 74 | - * Retrieves the adjacency label count. | ||
| 75 | - * | ||
| 76 | - * @return adjacency label count | ||
| 77 | - */ | ||
| 78 | - int getAdjLabelCount(); | ||
| 79 | - | ||
| 80 | - /** | ||
| 81 | * Retrieves the tunnel info count. | 45 | * Retrieves the tunnel info count. |
| 82 | * | 46 | * |
| 83 | * @return tunnel info count | 47 | * @return tunnel info count |
| ... | @@ -92,25 +56,11 @@ public interface PceStore { | ... | @@ -92,25 +56,11 @@ public interface PceStore { |
| 92 | int getFailedPathInfoCount(); | 56 | int getFailedPathInfoCount(); |
| 93 | 57 | ||
| 94 | /** | 58 | /** |
| 95 | - * Retrieves device id and label pairs collection from global node label store. | ||
| 96 | - * | ||
| 97 | - * @return collection of device id and label pairs | ||
| 98 | - */ | ||
| 99 | - Map<DeviceId, LabelResourceId> getGlobalNodeLabels(); | ||
| 100 | - | ||
| 101 | - /** | ||
| 102 | - * Retrieves link and label pairs collection from adjacency label store. | ||
| 103 | - * | ||
| 104 | - * @return collection of link and label pairs | ||
| 105 | - */ | ||
| 106 | - Map<Link, LabelResourceId> getAdjLabels(); | ||
| 107 | - | ||
| 108 | - /** | ||
| 109 | * Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store. | 59 | * Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store. |
| 110 | * | 60 | * |
| 111 | - * @return collection of tunnel id and pcecc tunnel info pairs | 61 | + * @return collection of tunnel id and resource consumer pairs |
| 112 | */ | 62 | */ |
| 113 | - Map<TunnelId, PceccTunnelInfo> getTunnelInfos(); | 63 | + Map<TunnelId, ResourceConsumer> getTunnelInfos(); |
| 114 | 64 | ||
| 115 | /** | 65 | /** |
| 116 | * Retrieves path info collection from failed path info store. | 66 | * Retrieves path info collection from failed path info store. |
| ... | @@ -120,52 +70,20 @@ public interface PceStore { | ... | @@ -120,52 +70,20 @@ public interface PceStore { |
| 120 | Iterable<PcePathInfo> getFailedPathInfos(); | 70 | Iterable<PcePathInfo> getFailedPathInfos(); |
| 121 | 71 | ||
| 122 | /** | 72 | /** |
| 123 | - * Retrieves node label for specified device id. | ||
| 124 | - * | ||
| 125 | - * @param id device id | ||
| 126 | - * @return node label | ||
| 127 | - */ | ||
| 128 | - LabelResourceId getGlobalNodeLabel(DeviceId id); | ||
| 129 | - | ||
| 130 | - /** | ||
| 131 | - * Retrieves adjacency label for specified link. | ||
| 132 | - * | ||
| 133 | - * @param link between devices | ||
| 134 | - * @return adjacency label | ||
| 135 | - */ | ||
| 136 | - LabelResourceId getAdjLabel(Link link); | ||
| 137 | - | ||
| 138 | - /** | ||
| 139 | * Retrieves local label info with tunnel consumer id from tunnel info store. | 73 | * Retrieves local label info with tunnel consumer id from tunnel info store. |
| 140 | * | 74 | * |
| 141 | * @param tunnelId tunnel id | 75 | * @param tunnelId tunnel id |
| 142 | - * @return pcecc tunnel info | 76 | + * @return resource consumer |
| 143 | - */ | ||
| 144 | - PceccTunnelInfo getTunnelInfo(TunnelId tunnelId); | ||
| 145 | - | ||
| 146 | - /** | ||
| 147 | - * Stores node label into global node label store. | ||
| 148 | - * | ||
| 149 | - * @param deviceId device id | ||
| 150 | - * @param labelId node label id | ||
| 151 | - */ | ||
| 152 | - void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId); | ||
| 153 | - | ||
| 154 | - /** | ||
| 155 | - * Stores adjacency label into adjacency label store. | ||
| 156 | - * | ||
| 157 | - * @param link link between nodes | ||
| 158 | - * @param labelId link label id | ||
| 159 | */ | 77 | */ |
| 160 | - void addAdjLabel(Link link, LabelResourceId labelId); | 78 | + ResourceConsumer getTunnelInfo(TunnelId tunnelId); |
| 161 | 79 | ||
| 162 | /** | 80 | /** |
| 163 | * Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id. | 81 | * Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id. |
| 164 | * | 82 | * |
| 165 | * @param tunnelId tunnel id | 83 | * @param tunnelId tunnel id |
| 166 | - * @param pceccTunnelInfo local label info | 84 | + * @param tunnelConsumerId tunnel consumer id |
| 167 | */ | 85 | */ |
| 168 | - void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo); | 86 | + void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId); |
| 169 | 87 | ||
| 170 | /** | 88 | /** |
| 171 | * Stores path information into failed path info store. | 89 | * Stores path information into failed path info store. |
| ... | @@ -175,41 +93,6 @@ public interface PceStore { | ... | @@ -175,41 +93,6 @@ public interface PceStore { |
| 175 | void addFailedPathInfo(PcePathInfo failedPathInfo); | 93 | void addFailedPathInfo(PcePathInfo failedPathInfo); |
| 176 | 94 | ||
| 177 | /** | 95 | /** |
| 178 | - * Updates local label info. The first entry is created with TunnelId and TunnelConsumerId. | ||
| 179 | - * Later this entry may be updated to store label information if it is basic PCECC case. | ||
| 180 | - * | ||
| 181 | - * @param tunnelId tunnel id | ||
| 182 | - * @param lspLocalLabelInfoList list of local labels | ||
| 183 | - * @return success or failure | ||
| 184 | - */ | ||
| 185 | - boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList); | ||
| 186 | - | ||
| 187 | - /** | ||
| 188 | - * Updates tunnel info map with tunnel consumer id. | ||
| 189 | - * | ||
| 190 | - * @param tunnelId tunnel id | ||
| 191 | - * @param tunnelConsumerId tunnel consumer id | ||
| 192 | - * @return success or failure | ||
| 193 | - */ | ||
| 194 | - boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId); | ||
| 195 | - | ||
| 196 | - /** | ||
| 197 | - * Removes device label from global node label store for specified device id. | ||
| 198 | - * | ||
| 199 | - * @param id device id | ||
| 200 | - * @return success or failure | ||
| 201 | - */ | ||
| 202 | - boolean removeGlobalNodeLabel(DeviceId id); | ||
| 203 | - | ||
| 204 | - /** | ||
| 205 | - * Removes adjacency label from adjacency label store for specified link information. | ||
| 206 | - * | ||
| 207 | - * @param link between nodes | ||
| 208 | - * @return success or failure | ||
| 209 | - */ | ||
| 210 | - boolean removeAdjLabel(Link link); | ||
| 211 | - | ||
| 212 | - /** | ||
| 213 | * Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id. | 96 | * Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id. |
| 214 | * | 97 | * |
| 215 | * @param tunnelId tunnel id | 98 | * @param tunnelId tunnel id |
| ... | @@ -224,54 +107,4 @@ public interface PceStore { | ... | @@ -224,54 +107,4 @@ public interface PceStore { |
| 224 | * @return success or failure | 107 | * @return success or failure |
| 225 | */ | 108 | */ |
| 226 | boolean removeFailedPathInfo(PcePathInfo failedPathInfo); | 109 | boolean removeFailedPathInfo(PcePathInfo failedPathInfo); |
| 227 | - | ||
| 228 | - /** | ||
| 229 | - * Adds lsrid to device id mapping. | ||
| 230 | - * | ||
| 231 | - * @param lsrId lsrId of the device | ||
| 232 | - * @param deviceId device id | ||
| 233 | - * @return success or failure | ||
| 234 | - */ | ||
| 235 | - boolean addLsrIdDevice(String lsrId, DeviceId deviceId); | ||
| 236 | - | ||
| 237 | - /** | ||
| 238 | - * Removes lsrid to device id mapping. | ||
| 239 | - * | ||
| 240 | - * @param lsrId lsrId of the device | ||
| 241 | - * @return success or failure | ||
| 242 | - */ | ||
| 243 | - boolean removeLsrIdDevice(String lsrId); | ||
| 244 | - | ||
| 245 | - /** | ||
| 246 | - * Gets lsrid to device id mapping. | ||
| 247 | - * | ||
| 248 | - * @param lsrId lsrId of the device | ||
| 249 | - * @return device id of the lsrId | ||
| 250 | - */ | ||
| 251 | - DeviceId getLsrIdDevice(String lsrId); | ||
| 252 | - | ||
| 253 | - /** | ||
| 254 | - * Adds lsrId of the PCC in form of device id for the PCC for which sync is pending due to non-availability of BGP. | ||
| 255 | - * device. | ||
| 256 | - * | ||
| 257 | - * @param lsrId LSR id of the PCC in form of device id | ||
| 258 | - * @return success or failure | ||
| 259 | - */ | ||
| 260 | - public boolean addPccLsr(DeviceId lsrId); | ||
| 261 | - | ||
| 262 | - /** | ||
| 263 | - * Removes lsrId of the PCC in form of device id for the PCC for which pending sync is done. | ||
| 264 | - * | ||
| 265 | - * @param lsrId LSR id of the PCC in form of device id | ||
| 266 | - * @return success or failure | ||
| 267 | - */ | ||
| 268 | - public boolean removePccLsr(DeviceId lsrId); | ||
| 269 | - | ||
| 270 | - /** | ||
| 271 | - * Gets lsrId of the PCC in form of device id. | ||
| 272 | - * | ||
| 273 | - * @param lsrId LSR id of the PCC in form of device id | ||
| 274 | - * @return success or failure | ||
| 275 | - */ | ||
| 276 | - public boolean hasPccLsr(DeviceId lsrId); | ||
| 277 | } | 110 | } | ... | ... |
| 1 | package org.onosproject.pce.pceservice; | 1 | package org.onosproject.pce.pceservice; |
| 2 | 2 | ||
| 3 | import static org.hamcrest.MatcherAssert.assertThat; | 3 | import static org.hamcrest.MatcherAssert.assertThat; |
| 4 | -import static org.hamcrest.Matchers.notNullValue; | ||
| 5 | -import static org.hamcrest.Matchers.nullValue; | ||
| 6 | import static org.hamcrest.core.Is.is; | 4 | import static org.hamcrest.core.Is.is; |
| 7 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; | 5 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; |
| 8 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; | 6 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; |
| 9 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; | 7 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; |
| 10 | -import static org.onosproject.net.Link.State.ACTIVE; | ||
| 11 | -import static org.onosproject.net.Link.Type.DIRECT; | ||
| 12 | import static org.onosproject.net.MastershipRole.MASTER; | 8 | import static org.onosproject.net.MastershipRole.MASTER; |
| 13 | import static org.onosproject.net.resource.Resources.continuous; | 9 | import static org.onosproject.net.resource.Resources.continuous; |
| 14 | import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; | 10 | import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; |
| ... | @@ -22,13 +18,11 @@ import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1; | ... | @@ -22,13 +18,11 @@ import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1; |
| 22 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2; | 18 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2; |
| 23 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3; | 19 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3; |
| 24 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4; | 20 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4; |
| 25 | -import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT; | ||
| 26 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; | 21 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; |
| 27 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; | 22 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; |
| 28 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; | 23 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; |
| 29 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST; | 24 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST; |
| 30 | 25 | ||
| 31 | -import java.net.URISyntaxException; | ||
| 32 | import java.util.Collection; | 26 | import java.util.Collection; |
| 33 | import java.util.Collections; | 27 | import java.util.Collections; |
| 34 | import java.util.HashMap; | 28 | import java.util.HashMap; |
| ... | @@ -44,9 +38,6 @@ import org.junit.Test; | ... | @@ -44,9 +38,6 @@ import org.junit.Test; |
| 44 | import org.onlab.graph.GraphPathSearch; | 38 | import org.onlab.graph.GraphPathSearch; |
| 45 | import org.onlab.junit.TestUtils; | 39 | import org.onlab.junit.TestUtils; |
| 46 | import org.onlab.junit.TestUtils.TestUtilsException; | 40 | import org.onlab.junit.TestUtils.TestUtilsException; |
| 47 | -import org.onlab.packet.Ethernet; | ||
| 48 | -import org.onlab.packet.IPv4; | ||
| 49 | -import org.onlab.packet.TCP; | ||
| 50 | import org.onlab.util.Bandwidth; | 41 | import org.onlab.util.Bandwidth; |
| 51 | import org.onosproject.common.DefaultTopologyGraph; | 42 | import org.onosproject.common.DefaultTopologyGraph; |
| 52 | import org.onosproject.core.ApplicationId; | 43 | import org.onosproject.core.ApplicationId; |
| ... | @@ -54,9 +45,6 @@ import org.onosproject.core.CoreServiceAdapter; | ... | @@ -54,9 +45,6 @@ import org.onosproject.core.CoreServiceAdapter; |
| 54 | import org.onosproject.core.DefaultApplicationId; | 45 | import org.onosproject.core.DefaultApplicationId; |
| 55 | import org.onosproject.core.IdGenerator; | 46 | import org.onosproject.core.IdGenerator; |
| 56 | import org.onosproject.event.Event; | 47 | import org.onosproject.event.Event; |
| 57 | -import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 58 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 59 | -import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 60 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; | 48 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 61 | import org.onosproject.incubator.net.tunnel.Tunnel; | 49 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 62 | import org.onosproject.incubator.net.tunnel.Tunnel.State; | 50 | import org.onosproject.incubator.net.tunnel.Tunnel.State; |
| ... | @@ -67,34 +55,20 @@ import org.onosproject.incubator.net.tunnel.TunnelListener; | ... | @@ -67,34 +55,20 @@ import org.onosproject.incubator.net.tunnel.TunnelListener; |
| 67 | import org.onosproject.mastership.MastershipServiceAdapter; | 55 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 68 | import org.onosproject.net.AnnotationKeys; | 56 | import org.onosproject.net.AnnotationKeys; |
| 69 | import org.onosproject.net.Annotations; | 57 | import org.onosproject.net.Annotations; |
| 70 | -import org.onosproject.net.ConnectPoint; | ||
| 71 | import org.onosproject.net.DefaultAnnotations; | 58 | import org.onosproject.net.DefaultAnnotations; |
| 72 | import org.onosproject.net.DefaultAnnotations.Builder; | 59 | import org.onosproject.net.DefaultAnnotations.Builder; |
| 73 | import org.onosproject.net.DefaultDevice; | 60 | import org.onosproject.net.DefaultDevice; |
| 74 | -import org.onosproject.net.DefaultLink; | ||
| 75 | import org.onosproject.net.Device; | 61 | import org.onosproject.net.Device; |
| 76 | import org.onosproject.net.DeviceId; | 62 | import org.onosproject.net.DeviceId; |
| 77 | import org.onosproject.net.ElementId; | 63 | import org.onosproject.net.ElementId; |
| 78 | import org.onosproject.net.Link; | 64 | import org.onosproject.net.Link; |
| 79 | import org.onosproject.net.MastershipRole; | 65 | import org.onosproject.net.MastershipRole; |
| 80 | import org.onosproject.net.Path; | 66 | import org.onosproject.net.Path; |
| 81 | -import org.onosproject.net.PortNumber; | ||
| 82 | import org.onosproject.net.SparseAnnotations; | 67 | import org.onosproject.net.SparseAnnotations; |
| 83 | -import org.onosproject.net.device.DeviceEvent; | ||
| 84 | -import org.onosproject.net.device.DeviceListener; | ||
| 85 | -import org.onosproject.net.flowobjective.ForwardingObjective; | ||
| 86 | import org.onosproject.net.intent.Constraint; | 68 | import org.onosproject.net.intent.Constraint; |
| 87 | import org.onosproject.net.intent.IntentId; | 69 | import org.onosproject.net.intent.IntentId; |
| 88 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 70 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 89 | import org.onosproject.net.link.LinkEvent; | 71 | import org.onosproject.net.link.LinkEvent; |
| 90 | -import org.onosproject.net.link.LinkListener; | ||
| 91 | -import org.onosproject.net.packet.DefaultInboundPacket; | ||
| 92 | -import org.onosproject.net.packet.DefaultPacketContext; | ||
| 93 | -import org.onosproject.net.packet.InboundPacket; | ||
| 94 | -import org.onosproject.net.packet.OutboundPacket; | ||
| 95 | -import org.onosproject.net.packet.PacketProcessor; | ||
| 96 | -import org.onosproject.net.packet.PacketService; | ||
| 97 | -import org.onosproject.net.packet.PacketServiceAdapter; | ||
| 98 | import org.onosproject.net.provider.ProviderId; | 72 | import org.onosproject.net.provider.ProviderId; |
| 99 | import org.onosproject.net.resource.Resource; | 73 | import org.onosproject.net.resource.Resource; |
| 100 | import org.onosproject.net.topology.DefaultTopologyEdge; | 74 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| ... | @@ -112,10 +86,7 @@ import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryA | ... | @@ -112,10 +86,7 @@ import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryA |
| 112 | import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService; | 86 | import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService; |
| 113 | import org.onosproject.pce.pceservice.constraint.CostConstraint; | 87 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
| 114 | import org.onosproject.pce.pcestore.api.PceStore; | 88 | import org.onosproject.pce.pcestore.api.PceStore; |
| 115 | -import org.onosproject.pce.util.FlowObjServiceAdapter; | ||
| 116 | -import org.onosproject.pce.util.LabelResourceAdapter; | ||
| 117 | import org.onosproject.pce.util.MockDeviceService; | 89 | import org.onosproject.pce.util.MockDeviceService; |
| 118 | -import org.onosproject.pce.util.MockLinkService; | ||
| 119 | import org.onosproject.pce.util.PceStoreAdapter; | 90 | import org.onosproject.pce.util.PceStoreAdapter; |
| 120 | import org.onosproject.pce.util.TunnelServiceAdapter; | 91 | import org.onosproject.pce.util.TunnelServiceAdapter; |
| 121 | import org.onosproject.pcep.api.DeviceCapability; | 92 | import org.onosproject.pcep.api.DeviceCapability; |
| ... | @@ -137,14 +108,9 @@ public class PceManagerTest { | ... | @@ -137,14 +108,9 @@ public class PceManagerTest { |
| 137 | private MockCoreService coreService = new MockCoreService(); | 108 | private MockCoreService coreService = new MockCoreService(); |
| 138 | private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); | 109 | private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); |
| 139 | private TestStorageService storageService = new TestStorageService(); | 110 | private TestStorageService storageService = new TestStorageService(); |
| 140 | - private PacketService packetService = new MockPacketService(); | ||
| 141 | private MockDeviceService deviceService = new MockDeviceService(); | 111 | private MockDeviceService deviceService = new MockDeviceService(); |
| 142 | private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter(); | 112 | private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter(); |
| 143 | - private MockLinkService linkService = new MockLinkService(); | ||
| 144 | - private MockFlowObjService flowObjectiveService = new MockFlowObjService(); | ||
| 145 | private PceStore pceStore = new PceStoreAdapter(); | 113 | private PceStore pceStore = new PceStoreAdapter(); |
| 146 | - private LabelResourceService labelResourceService = new LabelResourceAdapter(); | ||
| 147 | - private LabelResourceAdminService labelRsrcAdminService = new LabelResourceAdapter(); | ||
| 148 | 114 | ||
| 149 | public static ProviderId providerId = new ProviderId("pce", "foo"); | 115 | public static ProviderId providerId = new ProviderId("pce", "foo"); |
| 150 | private static final String L3 = "L3"; | 116 | private static final String L3 = "L3"; |
| ... | @@ -173,13 +139,8 @@ public class PceManagerTest { | ... | @@ -173,13 +139,8 @@ public class PceManagerTest { |
| 173 | pceManager.tunnelService = tunnelService; | 139 | pceManager.tunnelService = tunnelService; |
| 174 | pceManager.coreService = coreService; | 140 | pceManager.coreService = coreService; |
| 175 | pceManager.storageService = storageService; | 141 | pceManager.storageService = storageService; |
| 176 | - pceManager.packetService = packetService; | ||
| 177 | pceManager.deviceService = deviceService; | 142 | pceManager.deviceService = deviceService; |
| 178 | - pceManager.linkService = linkService; | ||
| 179 | pceManager.netCfgService = netConfigRegistry; | 143 | pceManager.netCfgService = netConfigRegistry; |
| 180 | - pceManager.labelRsrcAdminService = labelRsrcAdminService; | ||
| 181 | - pceManager.labelRsrcService = labelResourceService; | ||
| 182 | - pceManager.flowObjectiveService = flowObjectiveService; | ||
| 183 | pceManager.pceStore = pceStore; | 144 | pceManager.pceStore = pceStore; |
| 184 | pceManager.mastershipService = mastershipService; | 145 | pceManager.mastershipService = mastershipService; |
| 185 | pceManager.activate(); | 146 | pceManager.activate(); |
| ... | @@ -452,29 +413,6 @@ public class PceManagerTest { | ... | @@ -452,29 +413,6 @@ public class PceManagerTest { |
| 452 | } | 413 | } |
| 453 | 414 | ||
| 454 | /** | 415 | /** |
| 455 | - * Tests path setup without failure for LSP with signalling and with bandwidth reservation. | ||
| 456 | - */ | ||
| 457 | - @Test | ||
| 458 | - public void setupPathTest11() { | ||
| 459 | - build4RouterTopo(false, true, true, true, 15); | ||
| 460 | - List<Constraint> constraints = new LinkedList<Constraint>(); | ||
| 461 | - BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0)); | ||
| 462 | - CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
| 463 | - | ||
| 464 | - constraints.add(costConstraint); | ||
| 465 | - constraints.add(bwConstraint); | ||
| 466 | - | ||
| 467 | - LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
| 468 | - LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
| 469 | - | ||
| 470 | - pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
| 471 | - pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
| 472 | - | ||
| 473 | - boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | ||
| 474 | - assertThat(result, is(false)); | ||
| 475 | - } | ||
| 476 | - | ||
| 477 | - /** | ||
| 478 | * Tests path setup without signalling and with bandwidth reservation. | 416 | * Tests path setup without signalling and with bandwidth reservation. |
| 479 | */ | 417 | */ |
| 480 | @Test | 418 | @Test |
| ... | @@ -487,24 +425,6 @@ public class PceManagerTest { | ... | @@ -487,24 +425,6 @@ public class PceManagerTest { |
| 487 | constraints.add(costConstraint); | 425 | constraints.add(costConstraint); |
| 488 | constraints.add(bwConstraint); | 426 | constraints.add(bwConstraint); |
| 489 | 427 | ||
| 490 | - LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
| 491 | - LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
| 492 | - | ||
| 493 | - pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
| 494 | - pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
| 495 | - | ||
| 496 | - LabelResourceId link1Label = LabelResourceId.labelResourceId(5202); | ||
| 497 | - pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
| 498 | - | ||
| 499 | - LabelResourceId link2Label = LabelResourceId.labelResourceId(5203); | ||
| 500 | - pceManager.pceStore.addAdjLabel(link2, link2Label); | ||
| 501 | - | ||
| 502 | - LabelResourceId link3Label = LabelResourceId.labelResourceId(5204); | ||
| 503 | - pceManager.pceStore.addAdjLabel(link3, link3Label); | ||
| 504 | - | ||
| 505 | - LabelResourceId link4Label = LabelResourceId.labelResourceId(5205); | ||
| 506 | - pceManager.pceStore.addAdjLabel(link4, link4Label); | ||
| 507 | - | ||
| 508 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | 428 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); |
| 509 | assertThat(result, is(true)); | 429 | assertThat(result, is(true)); |
| 510 | } | 430 | } |
| ... | @@ -572,24 +492,6 @@ public class PceManagerTest { | ... | @@ -572,24 +492,6 @@ public class PceManagerTest { |
| 572 | CostConstraint costConstraint = new CostConstraint(TE_COST); | 492 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 573 | constraints.add(costConstraint); | 493 | constraints.add(costConstraint); |
| 574 | 494 | ||
| 575 | - LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
| 576 | - LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
| 577 | - | ||
| 578 | - pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
| 579 | - pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
| 580 | - | ||
| 581 | - LabelResourceId link1Label = LabelResourceId.labelResourceId(5202); | ||
| 582 | - pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
| 583 | - | ||
| 584 | - LabelResourceId link2Label = LabelResourceId.labelResourceId(5203); | ||
| 585 | - pceManager.pceStore.addAdjLabel(link2, link2Label); | ||
| 586 | - | ||
| 587 | - LabelResourceId link3Label = LabelResourceId.labelResourceId(5204); | ||
| 588 | - pceManager.pceStore.addAdjLabel(link3, link3Label); | ||
| 589 | - | ||
| 590 | - LabelResourceId link4Label = LabelResourceId.labelResourceId(5205); | ||
| 591 | - pceManager.pceStore.addAdjLabel(link4, link4Label); | ||
| 592 | - | ||
| 593 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); | 495 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING); |
| 594 | assertThat(result, is(true)); | 496 | assertThat(result, is(true)); |
| 595 | 497 | ||
| ... | @@ -685,89 +587,6 @@ public class PceManagerTest { | ... | @@ -685,89 +587,6 @@ public class PceManagerTest { |
| 685 | } | 587 | } |
| 686 | 588 | ||
| 687 | /** | 589 | /** |
| 688 | - * Tests packet in to trigger label DB sync. | ||
| 689 | - */ | ||
| 690 | - @Test | ||
| 691 | - public void packetProcessingTest1() throws URISyntaxException { | ||
| 692 | - | ||
| 693 | - build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc. | ||
| 694 | - | ||
| 695 | - LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
| 696 | - LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
| 697 | - | ||
| 698 | - pceManager.pceStore.addLsrIdDevice(deviceD1.annotations().value(LSRID), deviceD1.id()); | ||
| 699 | - pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
| 700 | - pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
| 701 | - | ||
| 702 | - ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1)); | ||
| 703 | - ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2)); | ||
| 704 | - | ||
| 705 | - Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT) | ||
| 706 | - .providerId(new ProviderId("eth", "1")).build(); | ||
| 707 | - | ||
| 708 | - LabelResourceId link1Label = LabelResourceId.labelResourceId(5204); | ||
| 709 | - pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
| 710 | - | ||
| 711 | - TCP tcp = new TCP(); | ||
| 712 | - tcp.setDestinationPort(PCEP_PORT); | ||
| 713 | - | ||
| 714 | - IPv4 ipv4 = new IPv4(); | ||
| 715 | - ipv4.setProtocol(IPv4.PROTOCOL_TCP); | ||
| 716 | - ipv4.setPayload(tcp); | ||
| 717 | - | ||
| 718 | - Ethernet eth = new Ethernet(); | ||
| 719 | - eth.setEtherType(Ethernet.TYPE_IPV4); | ||
| 720 | - eth.setPayload(ipv4); | ||
| 721 | - | ||
| 722 | - InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(DeviceId.deviceId("1.1.1.1"), | ||
| 723 | - PortNumber.portNumber(PCEP_PORT)), | ||
| 724 | - eth, null); | ||
| 725 | - | ||
| 726 | - pktProcessor.process(new MockPcepPacketContext(inPkt, null)); | ||
| 727 | - assertThat(flowsDownloaded, is(4)); | ||
| 728 | - } | ||
| 729 | - | ||
| 730 | - /** | ||
| 731 | - * Tests faulty packet in to trigger label DB sync. | ||
| 732 | - */ | ||
| 733 | - @Test | ||
| 734 | - public void packetProcessingTest2() throws URISyntaxException { | ||
| 735 | - | ||
| 736 | - build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc. | ||
| 737 | - | ||
| 738 | - LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
| 739 | - LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
| 740 | - | ||
| 741 | - pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
| 742 | - pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
| 743 | - | ||
| 744 | - ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1)); | ||
| 745 | - ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2)); | ||
| 746 | - | ||
| 747 | - Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT) | ||
| 748 | - .providerId(new ProviderId("eth", "1")).build(); | ||
| 749 | - | ||
| 750 | - LabelResourceId link1Label = LabelResourceId.labelResourceId(5204); | ||
| 751 | - pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
| 752 | - | ||
| 753 | - TCP tcp = new TCP(); // Not set the pcep port. | ||
| 754 | - IPv4 ipv4 = new IPv4(); | ||
| 755 | - ipv4.setProtocol(IPv4.PROTOCOL_TCP); | ||
| 756 | - ipv4.setPayload(tcp); | ||
| 757 | - | ||
| 758 | - Ethernet eth = new Ethernet(); | ||
| 759 | - eth.setEtherType(Ethernet.TYPE_IPV4); | ||
| 760 | - eth.setPayload(ipv4); | ||
| 761 | - | ||
| 762 | - InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(), | ||
| 763 | - PortNumber.portNumber(PCEP_PORT)), | ||
| 764 | - eth, null); | ||
| 765 | - | ||
| 766 | - pktProcessor.process(new MockPcepPacketContext(inPkt, null)); | ||
| 767 | - assertThat(flowsDownloaded, is(0)); | ||
| 768 | - } | ||
| 769 | - | ||
| 770 | - /** | ||
| 771 | * Tests tunnel events added and removed. | 590 | * Tests tunnel events added and removed. |
| 772 | */ | 591 | */ |
| 773 | @Test | 592 | @Test |
| ... | @@ -780,24 +599,6 @@ public class PceManagerTest { | ... | @@ -780,24 +599,6 @@ public class PceManagerTest { |
| 780 | constraints.add(costConstraint); | 599 | constraints.add(costConstraint); |
| 781 | constraints.add(bwConstraint); | 600 | constraints.add(bwConstraint); |
| 782 | 601 | ||
| 783 | - LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); | ||
| 784 | - LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); | ||
| 785 | - | ||
| 786 | - pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); | ||
| 787 | - pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); | ||
| 788 | - | ||
| 789 | - LabelResourceId link1Label = LabelResourceId.labelResourceId(5202); | ||
| 790 | - pceManager.pceStore.addAdjLabel(link1, link1Label); | ||
| 791 | - | ||
| 792 | - LabelResourceId link2Label = LabelResourceId.labelResourceId(5203); | ||
| 793 | - pceManager.pceStore.addAdjLabel(link2, link2Label); | ||
| 794 | - | ||
| 795 | - LabelResourceId link3Label = LabelResourceId.labelResourceId(5204); | ||
| 796 | - pceManager.pceStore.addAdjLabel(link3, link3Label); | ||
| 797 | - | ||
| 798 | - LabelResourceId link4Label = LabelResourceId.labelResourceId(5205); | ||
| 799 | - pceManager.pceStore.addAdjLabel(link4, link4Label); | ||
| 800 | - | ||
| 801 | pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING); | 602 | pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING); |
| 802 | assertThat(pceStore.getTunnelInfoCount(), is(1)); | 603 | assertThat(pceStore.getTunnelInfoCount(), is(1)); |
| 803 | 604 | ||
| ... | @@ -1276,86 +1077,6 @@ public class PceManagerTest { | ... | @@ -1276,86 +1077,6 @@ public class PceManagerTest { |
| 1276 | assertThat(pathService.paths().iterator().next().cost(), is((double) 180)); | 1077 | assertThat(pathService.paths().iterator().next().cost(), is((double) 180)); |
| 1277 | } | 1078 | } |
| 1278 | 1079 | ||
| 1279 | - /* | ||
| 1280 | - * Tests node label allocation/removal in SR-TE case based on device event. | ||
| 1281 | - */ | ||
| 1282 | - @Test | ||
| 1283 | - public void deviceEventTest() { | ||
| 1284 | - // Make four router topology with SR-TE capabilities. | ||
| 1285 | - build4RouterTopo(true, false, true, true, 0); | ||
| 1286 | - | ||
| 1287 | - // Add new L3 device | ||
| 1288 | - DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); | ||
| 1289 | - builderDev5.set(AnnotationKeys.TYPE, L3); | ||
| 1290 | - builderDev5.set(LSRID, "5.5.5.5"); | ||
| 1291 | - | ||
| 1292 | - Device dev5 = new MockDevice(DeviceId.deviceId("P005"), builderDev5.build()); | ||
| 1293 | - deviceService.addDevice(dev5); | ||
| 1294 | - | ||
| 1295 | - // Add capability | ||
| 1296 | - DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class); | ||
| 1297 | - device5Cap.setLabelStackCap(true) | ||
| 1298 | - .setLocalLabelCap(false) | ||
| 1299 | - .setSrCap(true) | ||
| 1300 | - .apply(); | ||
| 1301 | - | ||
| 1302 | - // Get listener | ||
| 1303 | - DeviceListener listener = deviceService.getListener(); | ||
| 1304 | - | ||
| 1305 | - // Generate Remove events | ||
| 1306 | - deviceService.removeDevice(dev5); | ||
| 1307 | - DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, dev5); | ||
| 1308 | - listener.event(event); | ||
| 1309 | - | ||
| 1310 | - assertThat(pceStore.getGlobalNodeLabel(dev5.id()), is(nullValue())); | ||
| 1311 | - } | ||
| 1312 | - | ||
| 1313 | - /** | ||
| 1314 | - * Tests adjacency label allocation/removal in SR-TE case based on link event. | ||
| 1315 | - */ | ||
| 1316 | - @Test | ||
| 1317 | - public void linkEventTest() { | ||
| 1318 | - // Make four router topology with SR-TE capabilities. | ||
| 1319 | - build4RouterTopo(true, false, true, true, 0); | ||
| 1320 | - | ||
| 1321 | - // Get listener | ||
| 1322 | - LinkListener listener = linkService.getListener(); | ||
| 1323 | - | ||
| 1324 | - // Adding link3 | ||
| 1325 | - linkService.addLink(link3); | ||
| 1326 | - | ||
| 1327 | - // Generate events | ||
| 1328 | - LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link3); | ||
| 1329 | - listener.event(event); | ||
| 1330 | - | ||
| 1331 | - assertThat(pceStore.getAdjLabel(link3), is(notNullValue())); | ||
| 1332 | - | ||
| 1333 | - // Adding link4 | ||
| 1334 | - linkService.addLink(link4); | ||
| 1335 | - | ||
| 1336 | - event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link4); | ||
| 1337 | - listener.event(event); | ||
| 1338 | - | ||
| 1339 | - assertThat(pceStore.getAdjLabel(link4), is(notNullValue())); | ||
| 1340 | - | ||
| 1341 | - // Remove link3 | ||
| 1342 | - linkService.removeLink(link3); | ||
| 1343 | - | ||
| 1344 | - // Generate events | ||
| 1345 | - event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3); | ||
| 1346 | - listener.event(event); | ||
| 1347 | - | ||
| 1348 | - assertThat(pceStore.getAdjLabel(link3), is(nullValue())); | ||
| 1349 | - | ||
| 1350 | - // Remove link4 | ||
| 1351 | - linkService.removeLink(link4); | ||
| 1352 | - | ||
| 1353 | - event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4); | ||
| 1354 | - listener.event(event); | ||
| 1355 | - | ||
| 1356 | - assertThat(pceStore.getAdjLabel(link4), is(nullValue())); | ||
| 1357 | - } | ||
| 1358 | - | ||
| 1359 | @After | 1080 | @After |
| 1360 | public void tearDown() { | 1081 | public void tearDown() { |
| 1361 | pceManager.deactivate(); | 1082 | pceManager.deactivate(); |
| ... | @@ -1364,13 +1085,8 @@ public class PceManagerTest { | ... | @@ -1364,13 +1085,8 @@ public class PceManagerTest { |
| 1364 | pceManager.tunnelService = null; | 1085 | pceManager.tunnelService = null; |
| 1365 | pceManager.coreService = null; | 1086 | pceManager.coreService = null; |
| 1366 | pceManager.storageService = null; | 1087 | pceManager.storageService = null; |
| 1367 | - pceManager.packetService = null; | ||
| 1368 | pceManager.deviceService = null; | 1088 | pceManager.deviceService = null; |
| 1369 | - pceManager.linkService = null; | ||
| 1370 | pceManager.netCfgService = null; | 1089 | pceManager.netCfgService = null; |
| 1371 | - pceManager.labelRsrcAdminService = null; | ||
| 1372 | - pceManager.labelRsrcService = null; | ||
| 1373 | - pceManager.flowObjectiveService = null; | ||
| 1374 | pceManager.pceStore = null; | 1090 | pceManager.pceStore = null; |
| 1375 | pceManager.topologyService = null; | 1091 | pceManager.topologyService = null; |
| 1376 | pceManager.mastershipService = null; | 1092 | pceManager.mastershipService = null; |
| ... | @@ -1588,31 +1304,4 @@ public class PceManagerTest { | ... | @@ -1588,31 +1304,4 @@ public class PceManagerTest { |
| 1588 | super(null, id, null, null, null, null, null, null, annotations); | 1304 | super(null, id, null, null, null, null, null, null, annotations); |
| 1589 | } | 1305 | } |
| 1590 | } | 1306 | } |
| 1591 | - | ||
| 1592 | - private PacketProcessor pktProcessor = null; | ||
| 1593 | - | ||
| 1594 | - private class MockPacketService extends PacketServiceAdapter { | ||
| 1595 | - @Override | ||
| 1596 | - public void addProcessor(PacketProcessor processor, int priority) { | ||
| 1597 | - pktProcessor = processor; | ||
| 1598 | - } | ||
| 1599 | - } | ||
| 1600 | - | ||
| 1601 | - // Minimal PacketContext to make core and applications happy. | ||
| 1602 | - final class MockPcepPacketContext extends DefaultPacketContext { | ||
| 1603 | - private MockPcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) { | ||
| 1604 | - super(System.currentTimeMillis(), inPkt, outPkt, false); | ||
| 1605 | - } | ||
| 1606 | - | ||
| 1607 | - @Override | ||
| 1608 | - public void send() { | ||
| 1609 | - } | ||
| 1610 | - } | ||
| 1611 | - | ||
| 1612 | - public static class MockFlowObjService extends FlowObjServiceAdapter { | ||
| 1613 | - @Override | ||
| 1614 | - public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { | ||
| 1615 | - ++flowsDownloaded; | ||
| 1616 | - } | ||
| 1617 | - } | ||
| 1618 | } | 1307 | } | ... | ... |
| ... | @@ -30,15 +30,12 @@ import org.junit.BeforeClass; | ... | @@ -30,15 +30,12 @@ import org.junit.BeforeClass; |
| 30 | import org.junit.Test; | 30 | import org.junit.Test; |
| 31 | 31 | ||
| 32 | import org.onlab.util.DataRateUnit; | 32 | import org.onlab.util.DataRateUnit; |
| 33 | -import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 34 | -import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 35 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 33 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelId; | 34 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 37 | import org.onosproject.net.ConnectPoint; | 35 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.DefaultAnnotations; | 36 | import org.onosproject.net.DefaultAnnotations; |
| 39 | import org.onosproject.net.DefaultLink; | 37 | import org.onosproject.net.DefaultLink; |
| 40 | import org.onosproject.net.DeviceId; | 38 | import org.onosproject.net.DeviceId; |
| 41 | -import org.onosproject.net.ElementId; | ||
| 42 | import org.onosproject.net.intent.Constraint; | 39 | import org.onosproject.net.intent.Constraint; |
| 43 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 40 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 44 | import org.onosproject.net.Link; | 41 | import org.onosproject.net.Link; |
| ... | @@ -46,7 +43,6 @@ import org.onosproject.net.PortNumber; | ... | @@ -46,7 +43,6 @@ import org.onosproject.net.PortNumber; |
| 46 | import org.onosproject.net.resource.ResourceConsumer; | 43 | import org.onosproject.net.resource.ResourceConsumer; |
| 47 | import org.onosproject.pce.pceservice.LspType; | 44 | import org.onosproject.pce.pceservice.LspType; |
| 48 | import org.onosproject.pce.pceservice.TunnelConsumerId; | 45 | import org.onosproject.pce.pceservice.TunnelConsumerId; |
| 49 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 50 | import org.onosproject.net.provider.ProviderId; | 46 | import org.onosproject.net.provider.ProviderId; |
| 51 | import org.onosproject.store.service.TestStorageService; | 47 | import org.onosproject.store.service.TestStorageService; |
| 52 | 48 | ||
| ... | @@ -68,24 +64,18 @@ public class DistributedPceStoreTest { | ... | @@ -68,24 +64,18 @@ public class DistributedPceStoreTest { |
| 68 | private PortNumber portNumber2 = PortNumber.portNumber(2); | 64 | private PortNumber portNumber2 = PortNumber.portNumber(2); |
| 69 | private PortNumber portNumber3 = PortNumber.portNumber(3); | 65 | private PortNumber portNumber3 = PortNumber.portNumber(3); |
| 70 | private PortNumber portNumber4 = PortNumber.portNumber(4); | 66 | private PortNumber portNumber4 = PortNumber.portNumber(4); |
| 71 | - private ConnectPoint srcConnectionPoint1 = new ConnectPoint((ElementId) deviceId1, portNumber1); | 67 | + private ConnectPoint srcConnectionPoint1 = new ConnectPoint(deviceId1, portNumber1); |
| 72 | - private ConnectPoint dstConnectionPoint2 = new ConnectPoint((ElementId) deviceId2, portNumber2); | 68 | + private ConnectPoint dstConnectionPoint2 = new ConnectPoint(deviceId2, portNumber2); |
| 73 | - private ConnectPoint srcConnectionPoint3 = new ConnectPoint((ElementId) deviceId3, portNumber3); | 69 | + private ConnectPoint srcConnectionPoint3 = new ConnectPoint(deviceId3, portNumber3); |
| 74 | - private ConnectPoint dstConnectionPoint4 = new ConnectPoint((ElementId) deviceId4, portNumber4); | 70 | + private ConnectPoint dstConnectionPoint4 = new ConnectPoint(deviceId4, portNumber4); |
| 75 | - private LabelResource labelResource1 = new DefaultLabelResource(deviceId1, labelId1); | ||
| 76 | - private LabelResource labelResource2 = new DefaultLabelResource(deviceId2, labelId2); | ||
| 77 | - private LabelResource labelResource3 = new DefaultLabelResource(deviceId3, labelId3); | ||
| 78 | - private LabelResource labelResource4 = new DefaultLabelResource(deviceId4, labelId4); | ||
| 79 | private Link link1; | 71 | private Link link1; |
| 80 | private Link link2; | 72 | private Link link2; |
| 81 | - private List<LabelResource> labelList1 = new LinkedList<>(); | ||
| 82 | - private List<LabelResource> labelList2 = new LinkedList<>(); | ||
| 83 | private TunnelId tunnelId1 = TunnelId.valueOf("1"); | 73 | private TunnelId tunnelId1 = TunnelId.valueOf("1"); |
| 84 | private TunnelId tunnelId2 = TunnelId.valueOf("2"); | 74 | private TunnelId tunnelId2 = TunnelId.valueOf("2"); |
| 85 | private TunnelId tunnelId3 = TunnelId.valueOf("3"); | 75 | private TunnelId tunnelId3 = TunnelId.valueOf("3"); |
| 86 | private TunnelId tunnelId4 = TunnelId.valueOf("4"); | 76 | private TunnelId tunnelId4 = TunnelId.valueOf("4"); |
| 87 | - private PceccTunnelInfo pceccTunnelInfo1; | 77 | + private ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10); |
| 88 | - private PceccTunnelInfo pceccTunnelInfo2; | 78 | + private ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20); |
| 89 | private PcePathInfo failedPathInfo1; | 79 | private PcePathInfo failedPathInfo1; |
| 90 | private PcePathInfo failedPathInfo2; | 80 | private PcePathInfo failedPathInfo2; |
| 91 | private PcePathInfo failedPathInfo3; | 81 | private PcePathInfo failedPathInfo3; |
| ... | @@ -120,44 +110,6 @@ public class DistributedPceStoreTest { | ... | @@ -120,44 +110,6 @@ public class DistributedPceStoreTest { |
| 120 | .type(Link.Type.DIRECT) | 110 | .type(Link.Type.DIRECT) |
| 121 | .state(Link.State.ACTIVE) | 111 | .state(Link.State.ACTIVE) |
| 122 | .build(); | 112 | .build(); |
| 123 | - labelList1.add(labelResource1); | ||
| 124 | - labelList1.add(labelResource2); | ||
| 125 | - labelList2.add(labelResource3); | ||
| 126 | - labelList2.add(labelResource4); | ||
| 127 | - | ||
| 128 | - // Create pceccTunnelInfo1 | ||
| 129 | - List<LspLocalLabelInfo> lspLocalLabelInfoList1 = new LinkedList<>(); | ||
| 130 | - ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10); | ||
| 131 | - | ||
| 132 | - DeviceId deviceId1 = DeviceId.deviceId("foo"); | ||
| 133 | - LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1); | ||
| 134 | - LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2); | ||
| 135 | - | ||
| 136 | - LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder() | ||
| 137 | - .deviceId(deviceId1) | ||
| 138 | - .inLabelId(inLabelId1) | ||
| 139 | - .outLabelId(outLabelId1) | ||
| 140 | - .build(); | ||
| 141 | - lspLocalLabelInfoList1.add(lspLocalLabel1); | ||
| 142 | - | ||
| 143 | - pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelInfoList1, tunnelConsumerId1); | ||
| 144 | - | ||
| 145 | - // Create pceccTunnelInfo2 | ||
| 146 | - List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>(); | ||
| 147 | - ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20); | ||
| 148 | - | ||
| 149 | - DeviceId deviceId2 = DeviceId.deviceId("foo"); | ||
| 150 | - LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3); | ||
| 151 | - LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4); | ||
| 152 | - | ||
| 153 | - LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder() | ||
| 154 | - .deviceId(deviceId2) | ||
| 155 | - .inLabelId(inLabelId2) | ||
| 156 | - .outLabelId(outLabelId2) | ||
| 157 | - .build(); | ||
| 158 | - lspLocalLabelInfoList2.add(lspLocalLabel2); | ||
| 159 | - | ||
| 160 | - pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2); | ||
| 161 | 113 | ||
| 162 | // Creates failedPathInfo1 | 114 | // Creates failedPathInfo1 |
| 163 | DeviceId src1 = DeviceId.deviceId("foo1"); | 115 | DeviceId src1 = DeviceId.deviceId("foo1"); |
| ... | @@ -209,42 +161,6 @@ public class DistributedPceStoreTest { | ... | @@ -209,42 +161,6 @@ public class DistributedPceStoreTest { |
| 209 | } | 161 | } |
| 210 | 162 | ||
| 211 | /** | 163 | /** |
| 212 | - * Checks the operation of addGlobalNodeLabel() method. | ||
| 213 | - */ | ||
| 214 | - @Test | ||
| 215 | - public void testAddGlobalNodeLabel() { | ||
| 216 | - // initialization | ||
| 217 | - distrPceStore.storageService = new TestStorageService(); | ||
| 218 | - distrPceStore.activate(); | ||
| 219 | - | ||
| 220 | - // add device with label | ||
| 221 | - distrPceStore.addGlobalNodeLabel(deviceId1, labelId1); | ||
| 222 | - assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true)); | ||
| 223 | - assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1)); | ||
| 224 | - distrPceStore.addGlobalNodeLabel(deviceId2, labelId2); | ||
| 225 | - assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true)); | ||
| 226 | - assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2)); | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - /** | ||
| 230 | - * Checks the operation of addAdjLabel() method. | ||
| 231 | - */ | ||
| 232 | - @Test | ||
| 233 | - public void testAddAdjLabel() { | ||
| 234 | - // initialization | ||
| 235 | - distrPceStore.storageService = new TestStorageService(); | ||
| 236 | - distrPceStore.activate(); | ||
| 237 | - | ||
| 238 | - // link with list of labels | ||
| 239 | - distrPceStore.addAdjLabel(link1, labelId1); | ||
| 240 | - assertThat(distrPceStore.existsAdjLabel(link1), is(true)); | ||
| 241 | - assertThat(distrPceStore.getAdjLabel(link1), is(labelId1)); | ||
| 242 | - distrPceStore.addAdjLabel(link2, labelId2); | ||
| 243 | - assertThat(distrPceStore.existsAdjLabel(link2), is(true)); | ||
| 244 | - assertThat(distrPceStore.getAdjLabel(link2), is(labelId2)); | ||
| 245 | - } | ||
| 246 | - | ||
| 247 | - /** | ||
| 248 | * Checks the operation of addTunnelInfo() method. | 164 | * Checks the operation of addTunnelInfo() method. |
| 249 | */ | 165 | */ |
| 250 | @Test | 166 | @Test |
| ... | @@ -254,12 +170,12 @@ public class DistributedPceStoreTest { | ... | @@ -254,12 +170,12 @@ public class DistributedPceStoreTest { |
| 254 | distrPceStore.activate(); | 170 | distrPceStore.activate(); |
| 255 | 171 | ||
| 256 | // TunnelId with device label store information | 172 | // TunnelId with device label store information |
| 257 | - distrPceStore.addTunnelInfo(tunnelId1, pceccTunnelInfo1); | 173 | + distrPceStore.addTunnelInfo(tunnelId1, tunnelConsumerId1); |
| 258 | assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); | 174 | assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); |
| 259 | - assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1)); | 175 | + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1)); |
| 260 | - distrPceStore.addTunnelInfo(tunnelId2, pceccTunnelInfo2); | 176 | + distrPceStore.addTunnelInfo(tunnelId2, tunnelConsumerId2); |
| 261 | assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); | 177 | assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); |
| 262 | - assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2)); | 178 | + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2)); |
| 263 | } | 179 | } |
| 264 | 180 | ||
| 265 | /** | 181 | /** |
| ... | @@ -279,30 +195,6 @@ public class DistributedPceStoreTest { | ... | @@ -279,30 +195,6 @@ public class DistributedPceStoreTest { |
| 279 | } | 195 | } |
| 280 | 196 | ||
| 281 | /** | 197 | /** |
| 282 | - * Checks the operation of existsGlobalNodeLabel() method. | ||
| 283 | - */ | ||
| 284 | - @Test | ||
| 285 | - public void testExistsGlobalNodeLabel() { | ||
| 286 | - testAddGlobalNodeLabel(); | ||
| 287 | - | ||
| 288 | - assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true)); | ||
| 289 | - assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true)); | ||
| 290 | - assertThat(distrPceStore.existsGlobalNodeLabel(deviceId3), is(false)); | ||
| 291 | - assertThat(distrPceStore.existsGlobalNodeLabel(deviceId4), is(false)); | ||
| 292 | - } | ||
| 293 | - | ||
| 294 | - /** | ||
| 295 | - * Checks the operation of existsAdjLabel() method. | ||
| 296 | - */ | ||
| 297 | - @Test | ||
| 298 | - public void testExistsAdjLabel() { | ||
| 299 | - testAddAdjLabel(); | ||
| 300 | - | ||
| 301 | - assertThat(distrPceStore.existsAdjLabel(link1), is(true)); | ||
| 302 | - assertThat(distrPceStore.existsAdjLabel(link2), is(true)); | ||
| 303 | - } | ||
| 304 | - | ||
| 305 | - /** | ||
| 306 | * Checks the operation of existsTunnelInfo() method. | 198 | * Checks the operation of existsTunnelInfo() method. |
| 307 | */ | 199 | */ |
| 308 | @Test | 200 | @Test |
| ... | @@ -329,26 +221,6 @@ public class DistributedPceStoreTest { | ... | @@ -329,26 +221,6 @@ public class DistributedPceStoreTest { |
| 329 | } | 221 | } |
| 330 | 222 | ||
| 331 | /** | 223 | /** |
| 332 | - * Checks the operation of getGlobalNodeLabelCount() method. | ||
| 333 | - */ | ||
| 334 | - @Test | ||
| 335 | - public void testGetGlobalNodeLabelCount() { | ||
| 336 | - testAddGlobalNodeLabel(); | ||
| 337 | - | ||
| 338 | - assertThat(distrPceStore.getGlobalNodeLabelCount(), is(2)); | ||
| 339 | - } | ||
| 340 | - | ||
| 341 | - /** | ||
| 342 | - * Checks the operation of getAdjLabelCount() method. | ||
| 343 | - */ | ||
| 344 | - @Test | ||
| 345 | - public void testGetAdjLabelCount() { | ||
| 346 | - testAddAdjLabel(); | ||
| 347 | - | ||
| 348 | - assertThat(distrPceStore.getAdjLabelCount(), is(2)); | ||
| 349 | - } | ||
| 350 | - | ||
| 351 | - /** | ||
| 352 | * Checks the operation of getTunnelInfoCount() method. | 224 | * Checks the operation of getTunnelInfoCount() method. |
| 353 | */ | 225 | */ |
| 354 | @Test | 226 | @Test |
| ... | @@ -369,39 +241,13 @@ public class DistributedPceStoreTest { | ... | @@ -369,39 +241,13 @@ public class DistributedPceStoreTest { |
| 369 | } | 241 | } |
| 370 | 242 | ||
| 371 | /** | 243 | /** |
| 372 | - * Checks the operation of getGlobalNodeLabels() method. | ||
| 373 | - */ | ||
| 374 | - @Test | ||
| 375 | - public void testGetGlobalNodeLabels() { | ||
| 376 | - testAddGlobalNodeLabel(); | ||
| 377 | - | ||
| 378 | - Map<DeviceId, LabelResourceId> nodeLabelMap = distrPceStore.getGlobalNodeLabels(); | ||
| 379 | - assertThat(nodeLabelMap, is(notNullValue())); | ||
| 380 | - assertThat(nodeLabelMap.isEmpty(), is(false)); | ||
| 381 | - assertThat(nodeLabelMap.size(), is(2)); | ||
| 382 | - } | ||
| 383 | - | ||
| 384 | - /** | ||
| 385 | - * Checks the operation of getAdjLabels() method. | ||
| 386 | - */ | ||
| 387 | - @Test | ||
| 388 | - public void testGetAdjLabels() { | ||
| 389 | - testAddAdjLabel(); | ||
| 390 | - | ||
| 391 | - Map<Link, LabelResourceId> adjLabelMap = distrPceStore.getAdjLabels(); | ||
| 392 | - assertThat(adjLabelMap, is(notNullValue())); | ||
| 393 | - assertThat(adjLabelMap.isEmpty(), is(false)); | ||
| 394 | - assertThat(adjLabelMap.size(), is(2)); | ||
| 395 | - } | ||
| 396 | - | ||
| 397 | - /** | ||
| 398 | * Checks the operation of getTunnelInfos() method. | 244 | * Checks the operation of getTunnelInfos() method. |
| 399 | */ | 245 | */ |
| 400 | @Test | 246 | @Test |
| 401 | public void testGetTunnelInfos() { | 247 | public void testGetTunnelInfos() { |
| 402 | testAddTunnelInfo(); | 248 | testAddTunnelInfo(); |
| 403 | 249 | ||
| 404 | - Map<TunnelId, PceccTunnelInfo> tunnelInfoMap = distrPceStore.getTunnelInfos(); | 250 | + Map<TunnelId, ResourceConsumer> tunnelInfoMap = distrPceStore.getTunnelInfos(); |
| 405 | assertThat(tunnelInfoMap, is(notNullValue())); | 251 | assertThat(tunnelInfoMap, is(notNullValue())); |
| 406 | assertThat(tunnelInfoMap.isEmpty(), is(false)); | 252 | assertThat(tunnelInfoMap.isEmpty(), is(false)); |
| 407 | assertThat(tunnelInfoMap.size(), is(2)); | 253 | assertThat(tunnelInfoMap.size(), is(2)); |
| ... | @@ -420,38 +266,6 @@ public class DistributedPceStoreTest { | ... | @@ -420,38 +266,6 @@ public class DistributedPceStoreTest { |
| 420 | } | 266 | } |
| 421 | 267 | ||
| 422 | /** | 268 | /** |
| 423 | - * Checks the operation of getGlobalNodeLabel() method. | ||
| 424 | - */ | ||
| 425 | - @Test | ||
| 426 | - public void testGetGlobalNodeLabel() { | ||
| 427 | - testAddGlobalNodeLabel(); | ||
| 428 | - | ||
| 429 | - // deviceId1 with labelId1 | ||
| 430 | - assertThat(deviceId1, is(notNullValue())); | ||
| 431 | - assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1)); | ||
| 432 | - | ||
| 433 | - // deviceId2 with labelId2 | ||
| 434 | - assertThat(deviceId2, is(notNullValue())); | ||
| 435 | - assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2)); | ||
| 436 | - } | ||
| 437 | - | ||
| 438 | - /** | ||
| 439 | - * Checks the operation of getAdjLabel() method. | ||
| 440 | - */ | ||
| 441 | - @Test | ||
| 442 | - public void testGetAdjLabel() { | ||
| 443 | - testAddAdjLabel(); | ||
| 444 | - | ||
| 445 | - // link1 with labels | ||
| 446 | - assertThat(link1, is(notNullValue())); | ||
| 447 | - assertThat(distrPceStore.getAdjLabel(link1), is(labelId1)); | ||
| 448 | - | ||
| 449 | - // link2 with labels | ||
| 450 | - assertThat(link2, is(notNullValue())); | ||
| 451 | - assertThat(distrPceStore.getAdjLabel(link2), is(labelId2)); | ||
| 452 | - } | ||
| 453 | - | ||
| 454 | - /** | ||
| 455 | * Checks the operation of getTunnelInfo() method. | 269 | * Checks the operation of getTunnelInfo() method. |
| 456 | */ | 270 | */ |
| 457 | @Test | 271 | @Test |
| ... | @@ -460,88 +274,11 @@ public class DistributedPceStoreTest { | ... | @@ -460,88 +274,11 @@ public class DistributedPceStoreTest { |
| 460 | 274 | ||
| 461 | // tunnelId1 with device label store info | 275 | // tunnelId1 with device label store info |
| 462 | assertThat(tunnelId1, is(notNullValue())); | 276 | assertThat(tunnelId1, is(notNullValue())); |
| 463 | - assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1)); | 277 | + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1)); |
| 464 | 278 | ||
| 465 | // tunnelId2 with device label store info | 279 | // tunnelId2 with device label store info |
| 466 | assertThat(tunnelId2, is(notNullValue())); | 280 | assertThat(tunnelId2, is(notNullValue())); |
| 467 | - assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2)); | 281 | + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2)); |
| 468 | - } | ||
| 469 | - | ||
| 470 | - /** | ||
| 471 | - * Checks the operation of updateTunnelInfo() method. | ||
| 472 | - */ | ||
| 473 | - @Test | ||
| 474 | - public void testUpdateTunnelInfo() { | ||
| 475 | - // add tunnel info | ||
| 476 | - testAddTunnelInfo(); | ||
| 477 | - | ||
| 478 | - // new updates | ||
| 479 | - // Create pceccTunnelInfo3 | ||
| 480 | - List<LspLocalLabelInfo> lspLocalLabelInfoList3 = new LinkedList<>(); | ||
| 481 | - ResourceConsumer tunnelConsumerId3 = TunnelConsumerId.valueOf(30); | ||
| 482 | - | ||
| 483 | - DeviceId deviceId3 = DeviceId.deviceId("goo"); | ||
| 484 | - LabelResourceId inLabelId3 = LabelResourceId.labelResourceId(3); | ||
| 485 | - LabelResourceId outLabelId3 = LabelResourceId.labelResourceId(4); | ||
| 486 | - | ||
| 487 | - LspLocalLabelInfo lspLocalLabel3 = DefaultLspLocalLabelInfo.builder() | ||
| 488 | - .deviceId(deviceId3) | ||
| 489 | - .inLabelId(inLabelId3) | ||
| 490 | - .outLabelId(outLabelId3) | ||
| 491 | - .build(); | ||
| 492 | - lspLocalLabelInfoList3.add(lspLocalLabel3); | ||
| 493 | - | ||
| 494 | - PceccTunnelInfo pceccTunnelInfo3 = new PceccTunnelInfo(lspLocalLabelInfoList3, tunnelConsumerId3); | ||
| 495 | - | ||
| 496 | - // Create pceccTunnelInfo4 | ||
| 497 | - List<LspLocalLabelInfo> lspLocalLabelInfoList4 = new LinkedList<>(); | ||
| 498 | - ResourceConsumer tunnelConsumerId4 = TunnelConsumerId.valueOf(40); | ||
| 499 | - | ||
| 500 | - DeviceId deviceId4 = DeviceId.deviceId("goo"); | ||
| 501 | - LabelResourceId inLabelId4 = LabelResourceId.labelResourceId(4); | ||
| 502 | - LabelResourceId outLabelId4 = LabelResourceId.labelResourceId(5); | ||
| 503 | - | ||
| 504 | - LspLocalLabelInfo lspLocalLabel4 = DefaultLspLocalLabelInfo.builder() | ||
| 505 | - .deviceId(deviceId4) | ||
| 506 | - .inLabelId(inLabelId4) | ||
| 507 | - .outLabelId(outLabelId4) | ||
| 508 | - .build(); | ||
| 509 | - lspLocalLabelInfoList4.add(lspLocalLabel4); | ||
| 510 | - | ||
| 511 | - PceccTunnelInfo pceccTunnelInfo4 = new PceccTunnelInfo(lspLocalLabelInfoList4, tunnelConsumerId4); | ||
| 512 | - | ||
| 513 | - // update only lspLocalLabelInfoList | ||
| 514 | - assertThat(distrPceStore.updateTunnelInfo(tunnelId1, lspLocalLabelInfoList3), is(true)); | ||
| 515 | - assertThat(distrPceStore.updateTunnelInfo(tunnelId2, lspLocalLabelInfoList4), is(true)); | ||
| 516 | - | ||
| 517 | - // update only tunnelConsumerId | ||
| 518 | - assertThat(distrPceStore.updateTunnelInfo(tunnelId1, tunnelConsumerId3), is(true)); | ||
| 519 | - assertThat(distrPceStore.updateTunnelInfo(tunnelId2, tunnelConsumerId4), is(true)); | ||
| 520 | - | ||
| 521 | - assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo3)); | ||
| 522 | - assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo4)); | ||
| 523 | - } | ||
| 524 | - | ||
| 525 | - /** | ||
| 526 | - * Checks the operation of removeGlobalNodeLabel() method. | ||
| 527 | - */ | ||
| 528 | - @Test | ||
| 529 | - public void testRemoveGlobalNodeLabel() { | ||
| 530 | - testAddGlobalNodeLabel(); | ||
| 531 | - | ||
| 532 | - assertThat(distrPceStore.removeGlobalNodeLabel(deviceId1), is(true)); | ||
| 533 | - assertThat(distrPceStore.removeGlobalNodeLabel(deviceId2), is(true)); | ||
| 534 | - } | ||
| 535 | - | ||
| 536 | - /** | ||
| 537 | - * Checks the operation of removeAdjLabel() method. | ||
| 538 | - */ | ||
| 539 | - @Test | ||
| 540 | - public void testRemoveAdjLabel() { | ||
| 541 | - testAddAdjLabel(); | ||
| 542 | - | ||
| 543 | - assertThat(distrPceStore.removeAdjLabel(link1), is(true)); | ||
| 544 | - assertThat(distrPceStore.removeAdjLabel(link2), is(true)); | ||
| 545 | } | 282 | } |
| 546 | 283 | ||
| 547 | /** | 284 | /** | ... | ... |
| 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 | -} |
| ... | @@ -22,19 +22,14 @@ import java.util.concurrent.ConcurrentMap; | ... | @@ -22,19 +22,14 @@ import java.util.concurrent.ConcurrentMap; |
| 22 | 22 | ||
| 23 | import java.util.HashMap; | 23 | import java.util.HashMap; |
| 24 | import java.util.HashSet; | 24 | import java.util.HashSet; |
| 25 | -import java.util.List; | ||
| 26 | import java.util.Map; | 25 | import java.util.Map; |
| 27 | import java.util.Set; | 26 | import java.util.Set; |
| 28 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
| 29 | 28 | ||
| 30 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 31 | import org.onosproject.incubator.net.tunnel.TunnelId; | 29 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 32 | import org.onosproject.net.DeviceId; | 30 | import org.onosproject.net.DeviceId; |
| 33 | -import org.onosproject.net.Link; | ||
| 34 | import org.onosproject.net.resource.ResourceConsumer; | 31 | import org.onosproject.net.resource.ResourceConsumer; |
| 35 | -import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 36 | import org.onosproject.pce.pcestore.PcePathInfo; | 32 | import org.onosproject.pce.pcestore.PcePathInfo; |
| 37 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 38 | import org.onosproject.pce.pcestore.api.PceStore; | 33 | import org.onosproject.pce.pcestore.api.PceStore; |
| 39 | 34 | ||
| 40 | /** | 35 | /** |
| ... | @@ -42,14 +37,8 @@ import org.onosproject.pce.pcestore.api.PceStore; | ... | @@ -42,14 +37,8 @@ import org.onosproject.pce.pcestore.api.PceStore; |
| 42 | */ | 37 | */ |
| 43 | public class PceStoreAdapter implements PceStore { | 38 | public class PceStoreAdapter implements PceStore { |
| 44 | 39 | ||
| 45 | - // Mapping device with global node label | ||
| 46 | - private ConcurrentMap<DeviceId, LabelResourceId> globalNodeLabelMap = new ConcurrentHashMap<>(); | ||
| 47 | - | ||
| 48 | - // Mapping link with adjacency label | ||
| 49 | - private ConcurrentMap<Link, LabelResourceId> adjLabelMap = new ConcurrentHashMap<>(); | ||
| 50 | - | ||
| 51 | // Mapping tunnel with device local info with tunnel consumer id | 40 | // Mapping tunnel with device local info with tunnel consumer id |
| 52 | - private ConcurrentMap<TunnelId, PceccTunnelInfo> tunnelInfoMap = new ConcurrentHashMap<>(); | 41 | + private ConcurrentMap<TunnelId, ResourceConsumer> tunnelInfoMap = new ConcurrentHashMap<>(); |
| 53 | 42 | ||
| 54 | // Set of Path info | 43 | // Set of Path info |
| 55 | private Set<PcePathInfo> failedPathInfoSet = new HashSet<>(); | 44 | private Set<PcePathInfo> failedPathInfoSet = new HashSet<>(); |
| ... | @@ -58,16 +47,6 @@ public class PceStoreAdapter implements PceStore { | ... | @@ -58,16 +47,6 @@ public class PceStoreAdapter implements PceStore { |
| 58 | private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); | 47 | private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); |
| 59 | 48 | ||
| 60 | @Override | 49 | @Override |
| 61 | - public boolean existsGlobalNodeLabel(DeviceId id) { | ||
| 62 | - return globalNodeLabelMap.containsKey(id); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - @Override | ||
| 66 | - public boolean existsAdjLabel(Link link) { | ||
| 67 | - return adjLabelMap.containsKey(link); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - @Override | ||
| 71 | public boolean existsTunnelInfo(TunnelId tunnelId) { | 50 | public boolean existsTunnelInfo(TunnelId tunnelId) { |
| 72 | return tunnelInfoMap.containsKey(tunnelId); | 51 | return tunnelInfoMap.containsKey(tunnelId); |
| 73 | } | 52 | } |
| ... | @@ -78,16 +57,6 @@ public class PceStoreAdapter implements PceStore { | ... | @@ -78,16 +57,6 @@ public class PceStoreAdapter implements PceStore { |
| 78 | } | 57 | } |
| 79 | 58 | ||
| 80 | @Override | 59 | @Override |
| 81 | - public int getGlobalNodeLabelCount() { | ||
| 82 | - return globalNodeLabelMap.size(); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - @Override | ||
| 86 | - public int getAdjLabelCount() { | ||
| 87 | - return adjLabelMap.size(); | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - @Override | ||
| 91 | public int getTunnelInfoCount() { | 60 | public int getTunnelInfoCount() { |
| 92 | return tunnelInfoMap.size(); | 61 | return tunnelInfoMap.size(); |
| 93 | } | 62 | } |
| ... | @@ -98,21 +67,9 @@ public class PceStoreAdapter implements PceStore { | ... | @@ -98,21 +67,9 @@ public class PceStoreAdapter implements PceStore { |
| 98 | } | 67 | } |
| 99 | 68 | ||
| 100 | @Override | 69 | @Override |
| 101 | - public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() { | 70 | + public Map<TunnelId, ResourceConsumer> getTunnelInfos() { |
| 102 | - return globalNodeLabelMap.entrySet().stream() | ||
| 103 | - .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue())); | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - @Override | ||
| 107 | - public Map<Link, LabelResourceId> getAdjLabels() { | ||
| 108 | - return adjLabelMap.entrySet().stream() | ||
| 109 | - .collect(Collectors.toMap(Map.Entry::getKey, e -> (LabelResourceId) e.getValue())); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - @Override | ||
| 113 | - public Map<TunnelId, PceccTunnelInfo> getTunnelInfos() { | ||
| 114 | return tunnelInfoMap.entrySet().stream() | 71 | return tunnelInfoMap.entrySet().stream() |
| 115 | - .collect(Collectors.toMap(Map.Entry::getKey, e -> (PceccTunnelInfo) e.getValue())); | 72 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue())); |
| 116 | } | 73 | } |
| 117 | 74 | ||
| 118 | @Override | 75 | @Override |
| ... | @@ -121,33 +78,13 @@ public class PceStoreAdapter implements PceStore { | ... | @@ -121,33 +78,13 @@ public class PceStoreAdapter implements PceStore { |
| 121 | } | 78 | } |
| 122 | 79 | ||
| 123 | @Override | 80 | @Override |
| 124 | - public LabelResourceId getGlobalNodeLabel(DeviceId id) { | 81 | + public ResourceConsumer getTunnelInfo(TunnelId tunnelId) { |
| 125 | - return globalNodeLabelMap.get(id); | ||
| 126 | - } | ||
| 127 | - | ||
| 128 | - @Override | ||
| 129 | - public LabelResourceId getAdjLabel(Link link) { | ||
| 130 | - return adjLabelMap.get(link); | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - @Override | ||
| 134 | - public PceccTunnelInfo getTunnelInfo(TunnelId tunnelId) { | ||
| 135 | return tunnelInfoMap.get(tunnelId); | 82 | return tunnelInfoMap.get(tunnelId); |
| 136 | } | 83 | } |
| 137 | 84 | ||
| 138 | @Override | 85 | @Override |
| 139 | - public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) { | 86 | + public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) { |
| 140 | - globalNodeLabelMap.put(deviceId, labelId); | 87 | + tunnelInfoMap.put(tunnelId, tunnelConsumerId); |
| 141 | - } | ||
| 142 | - | ||
| 143 | - @Override | ||
| 144 | - public void addAdjLabel(Link link, LabelResourceId labelId) { | ||
| 145 | - adjLabelMap.put(link, labelId); | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - @Override | ||
| 149 | - public void addTunnelInfo(TunnelId tunnelId, PceccTunnelInfo pceccTunnelInfo) { | ||
| 150 | - tunnelInfoMap.put(tunnelId, pceccTunnelInfo); | ||
| 151 | } | 88 | } |
| 152 | 89 | ||
| 153 | @Override | 90 | @Override |
| ... | @@ -156,48 +93,6 @@ public class PceStoreAdapter implements PceStore { | ... | @@ -156,48 +93,6 @@ public class PceStoreAdapter implements PceStore { |
| 156 | } | 93 | } |
| 157 | 94 | ||
| 158 | @Override | 95 | @Override |
| 159 | - public boolean updateTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) { | ||
| 160 | - if (!tunnelInfoMap.containsKey((tunnelId))) { | ||
| 161 | - return false; | ||
| 162 | - } | ||
| 163 | - | ||
| 164 | - PceccTunnelInfo labelStoreInfo = tunnelInfoMap.get(tunnelId); | ||
| 165 | - labelStoreInfo.lspLocalLabelInfoList(lspLocalLabelInfoList); | ||
| 166 | - tunnelInfoMap.put(tunnelId, labelStoreInfo); | ||
| 167 | - return true; | ||
| 168 | - } | ||
| 169 | - | ||
| 170 | - @Override | ||
| 171 | - public boolean updateTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) { | ||
| 172 | - if (!tunnelInfoMap.containsKey((tunnelId))) { | ||
| 173 | - return false; | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - PceccTunnelInfo tunnelInfo = tunnelInfoMap.get(tunnelId); | ||
| 177 | - tunnelInfo.tunnelConsumerId(tunnelConsumerId); | ||
| 178 | - tunnelInfoMap.put(tunnelId, tunnelInfo); | ||
| 179 | - return true; | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - @Override | ||
| 183 | - public boolean removeGlobalNodeLabel(DeviceId id) { | ||
| 184 | - globalNodeLabelMap.remove(id); | ||
| 185 | - if (globalNodeLabelMap.containsKey(id)) { | ||
| 186 | - return false; | ||
| 187 | - } | ||
| 188 | - return true; | ||
| 189 | - } | ||
| 190 | - | ||
| 191 | - @Override | ||
| 192 | - public boolean removeAdjLabel(Link link) { | ||
| 193 | - adjLabelMap.remove(link); | ||
| 194 | - if (adjLabelMap.containsKey(link)) { | ||
| 195 | - return false; | ||
| 196 | - } | ||
| 197 | - return true; | ||
| 198 | - } | ||
| 199 | - | ||
| 200 | - @Override | ||
| 201 | public boolean removeTunnelInfo(TunnelId tunnelId) { | 96 | public boolean removeTunnelInfo(TunnelId tunnelId) { |
| 202 | tunnelInfoMap.remove(tunnelId); | 97 | tunnelInfoMap.remove(tunnelId); |
| 203 | if (tunnelInfoMap.containsKey(tunnelId)) { | 98 | if (tunnelInfoMap.containsKey(tunnelId)) { |
| ... | @@ -213,39 +108,4 @@ public class PceStoreAdapter implements PceStore { | ... | @@ -213,39 +108,4 @@ public class PceStoreAdapter implements PceStore { |
| 213 | } | 108 | } |
| 214 | return true; | 109 | return true; |
| 215 | } | 110 | } |
| 216 | - | ||
| 217 | - @Override | ||
| 218 | - public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) { | ||
| 219 | - lsrIdDeviceIdMap.put(lsrId, deviceId); | ||
| 220 | - return true; | ||
| 221 | - } | ||
| 222 | - | ||
| 223 | - @Override | ||
| 224 | - public boolean removeLsrIdDevice(String lsrId) { | ||
| 225 | - lsrIdDeviceIdMap.remove(lsrId); | ||
| 226 | - return true; | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - @Override | ||
| 230 | - public DeviceId getLsrIdDevice(String lsrId) { | ||
| 231 | - return lsrIdDeviceIdMap.get(lsrId); | ||
| 232 | - } | ||
| 233 | - | ||
| 234 | - @Override | ||
| 235 | - public boolean addPccLsr(DeviceId lsrId) { | ||
| 236 | - // TODO Auto-generated method stub | ||
| 237 | - return false; | ||
| 238 | - } | ||
| 239 | - | ||
| 240 | - @Override | ||
| 241 | - public boolean removePccLsr(DeviceId lsrId) { | ||
| 242 | - // TODO Auto-generated method stub | ||
| 243 | - return false; | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | - @Override | ||
| 247 | - public boolean hasPccLsr(DeviceId lsrId) { | ||
| 248 | - // TODO Auto-generated method stub | ||
| 249 | - return false; | ||
| 250 | - } | ||
| 251 | } | 111 | } | ... | ... |
| ... | @@ -16,8 +16,14 @@ | ... | @@ -16,8 +16,14 @@ |
| 16 | package org.onosproject.pcep.controller; | 16 | package org.onosproject.pcep.controller; |
| 17 | 17 | ||
| 18 | import java.util.Collection; | 18 | import java.util.Collection; |
| 19 | +import java.util.LinkedList; | ||
| 19 | 20 | ||
| 21 | +import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | ||
| 22 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 23 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 24 | +import org.onosproject.net.Path; | ||
| 20 | import org.onosproject.pcepio.protocol.PcepMessage; | 25 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 26 | +import org.onosproject.pcepio.types.PcepValueType; | ||
| 21 | 27 | ||
| 22 | /** | 28 | /** |
| 23 | * Abstraction of an Pcep client controller. Serves as a one stop | 29 | * Abstraction of an Pcep client controller. Serves as a one stop |
| ... | @@ -85,20 +91,6 @@ public interface PcepClientController { | ... | @@ -85,20 +91,6 @@ public interface PcepClientController { |
| 85 | void removeNodeListener(PcepNodeListener listener); | 91 | void removeNodeListener(PcepNodeListener listener); |
| 86 | 92 | ||
| 87 | /** | 93 | /** |
| 88 | - * Register a listener for packet events. | ||
| 89 | - * | ||
| 90 | - * @param listener the listener to notify | ||
| 91 | - */ | ||
| 92 | - void addPacketListener(PcepPacketListener listener); | ||
| 93 | - | ||
| 94 | - /** | ||
| 95 | - * Unregister a packet listener. | ||
| 96 | - * | ||
| 97 | - * @param listener the listener to unregister | ||
| 98 | - */ | ||
| 99 | - void removePacketListener(PcepPacketListener listener); | ||
| 100 | - | ||
| 101 | - /** | ||
| 102 | * Send a message to a particular pcc client. | 94 | * Send a message to a particular pcc client. |
| 103 | * | 95 | * |
| 104 | * @param pccId the id of the client to send message. | 96 | * @param pccId the id of the client to send message. |
| ... | @@ -118,4 +110,29 @@ public interface PcepClientController { | ... | @@ -118,4 +110,29 @@ public interface PcepClientController { |
| 118 | * Close all connected PCC clients. | 110 | * Close all connected PCC clients. |
| 119 | */ | 111 | */ |
| 120 | void closeConnectedClients(); | 112 | void closeConnectedClients(); |
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Create label stack from the given path. | ||
| 116 | + * | ||
| 117 | + * @param path from which label stack is to be computed | ||
| 118 | + * @return the label stack | ||
| 119 | + */ | ||
| 120 | + public LabelStack computeLabelStack(Path path); | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * Allocates and downloads local labels for the given LSP. | ||
| 124 | + * | ||
| 125 | + * @param tunnel for which local labels have to be assigned and downloaded | ||
| 126 | + * @return success or failure | ||
| 127 | + */ | ||
| 128 | + public boolean allocateLocalLabel(Tunnel tunnel); | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * Creates label stack for ERO object from network resource. | ||
| 132 | + * | ||
| 133 | + * @param labelStack | ||
| 134 | + * @param path (hop list) | ||
| 135 | + * @return list of ERO sub-objects | ||
| 136 | + */ | ||
| 137 | + public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path); | ||
| 121 | } | 138 | } | ... | ... |
| 1 | COMPILE_DEPS = [ | 1 | COMPILE_DEPS = [ |
| 2 | '//lib:CORE_DEPS', | 2 | '//lib:CORE_DEPS', |
| 3 | + '//incubator/api:onos-incubator-api', | ||
| 3 | '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', | 4 | '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', |
| 4 | '//protocols/pcep/api:onos-protocols-pcep-api', | 5 | '//protocols/pcep/api:onos-protocols-pcep-api', |
| 5 | - '//incubator/api:onos-incubator-api', | 6 | + '//core/store/serializers:onos-core-serializers', |
| 6 | '//apps/pcep-api:onos-apps-pcep-api', | 7 | '//apps/pcep-api:onos-apps-pcep-api', |
| 7 | ] | 8 | ] |
| 8 | 9 | ... | ... |
| ... | @@ -50,6 +50,11 @@ | ... | @@ -50,6 +50,11 @@ |
| 50 | <groupId>org.onosproject</groupId> | 50 | <groupId>org.onosproject</groupId> |
| 51 | <artifactId>onlab-misc</artifactId> | 51 | <artifactId>onlab-misc</artifactId> |
| 52 | </dependency> | 52 | </dependency> |
| 53 | + <dependency> | ||
| 54 | + <groupId>org.onosproject</groupId> | ||
| 55 | + <artifactId>onos-core-serializers</artifactId> | ||
| 56 | + <version>${project.version}</version> | ||
| 57 | + </dependency> | ||
| 53 | </dependencies> | 58 | </dependencies> |
| 54 | 59 | ||
| 55 | <build> | 60 | <build> | ... | ... |
| ... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.pcestore; | 16 | +package org.onosproject.pcelabelstore; |
| 17 | 17 | ||
| 18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
| 19 | 19 | ||
| ... | @@ -21,8 +21,8 @@ import java.util.Objects; | ... | @@ -21,8 +21,8 @@ import java.util.Objects; |
| 21 | 21 | ||
| 22 | import org.onosproject.net.DeviceId; | 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.PortNumber; | 23 | import org.onosproject.net.PortNumber; |
| 24 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; | ||
| 24 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 25 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 25 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * Local node details including IN and OUT labels as well as IN and OUT port details. | 28 | * Local node details including IN and OUT labels as well as IN and OUT port details. |
| ... | @@ -30,13 +30,9 @@ import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ... | @@ -30,13 +30,9 @@ import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; |
| 30 | public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo { | 30 | public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo { |
| 31 | 31 | ||
| 32 | private final DeviceId deviceId; | 32 | private final DeviceId deviceId; |
| 33 | - | ||
| 34 | private final LabelResourceId inLabelId; | 33 | private final LabelResourceId inLabelId; |
| 35 | - | ||
| 36 | private final LabelResourceId outLabelId; | 34 | private final LabelResourceId outLabelId; |
| 37 | - | ||
| 38 | private final PortNumber inPort; | 35 | private final PortNumber inPort; |
| 39 | - | ||
| 40 | private final PortNumber outPort; | 36 | private final PortNumber outPort; |
| 41 | 37 | ||
| 42 | /** | 38 | /** |
| ... | @@ -152,15 +148,10 @@ public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo { | ... | @@ -152,15 +148,10 @@ public final class DefaultLspLocalLabelInfo implements LspLocalLabelInfo { |
| 152 | * Builder. | 148 | * Builder. |
| 153 | */ | 149 | */ |
| 154 | public static final class Builder implements LspLocalLabelInfo.Builder { | 150 | public static final class Builder implements LspLocalLabelInfo.Builder { |
| 155 | - | ||
| 156 | private DeviceId deviceId; | 151 | private DeviceId deviceId; |
| 157 | - | ||
| 158 | private LabelResourceId inLabelId; | 152 | private LabelResourceId inLabelId; |
| 159 | - | ||
| 160 | private LabelResourceId outLabelId; | 153 | private LabelResourceId outLabelId; |
| 161 | - | ||
| 162 | private PortNumber inPort; | 154 | private PortNumber inPort; |
| 163 | - | ||
| 164 | private PortNumber outPort; | 155 | private PortNumber outPort; |
| 165 | 156 | ||
| 166 | /** | 157 | /** | ... | ... |
protocols/pcep/ctl/src/main/java/org/onosproject/pcelabelstore/DistributedPceLabelStore.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.pcelabelstore; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.HashMap; | ||
| 21 | +import java.util.HashSet; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Map; | ||
| 24 | +import java.util.stream.Collectors; | ||
| 25 | + | ||
| 26 | +import org.apache.felix.scr.annotations.Activate; | ||
| 27 | +import org.apache.felix.scr.annotations.Component; | ||
| 28 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 29 | +import org.apache.felix.scr.annotations.Reference; | ||
| 30 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 31 | +import org.apache.felix.scr.annotations.Service; | ||
| 32 | + | ||
| 33 | +import org.onlab.util.KryoNamespace; | ||
| 34 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 35 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 36 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 37 | +import org.onosproject.net.DeviceId; | ||
| 38 | +import org.onosproject.net.Link; | ||
| 39 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; | ||
| 40 | +import org.onosproject.pcelabelstore.api.PceLabelStore; | ||
| 41 | +import org.onosproject.store.serializers.KryoNamespaces; | ||
| 42 | +import org.onosproject.store.service.ConsistentMap; | ||
| 43 | +import org.onosproject.store.service.Serializer; | ||
| 44 | +import org.onosproject.store.service.StorageService; | ||
| 45 | + | ||
| 46 | +import org.slf4j.Logger; | ||
| 47 | +import org.slf4j.LoggerFactory; | ||
| 48 | + | ||
| 49 | +/** | ||
| 50 | + * Manages the pool of available labels to devices, links and tunnels. | ||
| 51 | + */ | ||
| 52 | +@Component(immediate = true) | ||
| 53 | +@Service | ||
| 54 | +public class DistributedPceLabelStore implements PceLabelStore { | ||
| 55 | + | ||
| 56 | + private static final String DEVICE_ID_NULL = "Device ID cannot be null"; | ||
| 57 | + private static final String LABEL_RESOURCE_ID_NULL = "Label Resource Id cannot be null"; | ||
| 58 | + private static final String LINK_NULL = "LINK cannot be null"; | ||
| 59 | + private static final String PCECC_TUNNEL_INFO_NULL = "PCECC Tunnel Info cannot be null"; | ||
| 60 | + private static final String TUNNEL_ID_NULL = "Tunnel Id cannot be null"; | ||
| 61 | + | ||
| 62 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 63 | + | ||
| 64 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 65 | + protected StorageService storageService; | ||
| 66 | + | ||
| 67 | + // Mapping device with global node label | ||
| 68 | + private ConsistentMap<DeviceId, LabelResourceId> globalNodeLabelMap; | ||
| 69 | + | ||
| 70 | + // Mapping link with adjacency label | ||
| 71 | + private ConsistentMap<Link, LabelResourceId> adjLabelMap; | ||
| 72 | + | ||
| 73 | + // Mapping tunnel id with local labels. | ||
| 74 | + private ConsistentMap<TunnelId, List<LspLocalLabelInfo>> tunnelLabelInfoMap; | ||
| 75 | + | ||
| 76 | + // Locally maintain LSRID to device id mapping for better performance. | ||
| 77 | + private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); | ||
| 78 | + | ||
| 79 | + // List of PCC LSR ids whose BGP device information was not available to perform | ||
| 80 | + // label db sync. | ||
| 81 | + private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet<>(); | ||
| 82 | + | ||
| 83 | + @Activate | ||
| 84 | + protected void activate() { | ||
| 85 | + globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder() | ||
| 86 | + .withName("onos-pce-globalnodelabelmap") | ||
| 87 | + .withSerializer(Serializer.using( | ||
| 88 | + new KryoNamespace.Builder() | ||
| 89 | + .register(KryoNamespaces.API) | ||
| 90 | + .register(LabelResourceId.class) | ||
| 91 | + .build())) | ||
| 92 | + .build(); | ||
| 93 | + | ||
| 94 | + adjLabelMap = storageService.<Link, LabelResourceId>consistentMapBuilder() | ||
| 95 | + .withName("onos-pce-adjlabelmap") | ||
| 96 | + .withSerializer(Serializer.using( | ||
| 97 | + new KryoNamespace.Builder() | ||
| 98 | + .register(KryoNamespaces.API) | ||
| 99 | + .register(Link.class, | ||
| 100 | + LabelResource.class, | ||
| 101 | + LabelResourceId.class) | ||
| 102 | + .build())) | ||
| 103 | + .build(); | ||
| 104 | + | ||
| 105 | + tunnelLabelInfoMap = storageService.<TunnelId, List<LspLocalLabelInfo>>consistentMapBuilder() | ||
| 106 | + .withName("onos-pce-tunnellabelinfomap") | ||
| 107 | + .withSerializer(Serializer.using( | ||
| 108 | + new KryoNamespace.Builder() | ||
| 109 | + .register(KryoNamespaces.API) | ||
| 110 | + .register(TunnelId.class, | ||
| 111 | + DefaultLspLocalLabelInfo.class, | ||
| 112 | + LabelResourceId.class, | ||
| 113 | + DeviceId.class) | ||
| 114 | + .build())) | ||
| 115 | + .build(); | ||
| 116 | + | ||
| 117 | + log.info("Started"); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Deactivate | ||
| 121 | + protected void deactivate() { | ||
| 122 | + log.info("Stopped"); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public boolean existsGlobalNodeLabel(DeviceId id) { | ||
| 127 | + checkNotNull(id, DEVICE_ID_NULL); | ||
| 128 | + return globalNodeLabelMap.containsKey(id); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public boolean existsAdjLabel(Link link) { | ||
| 133 | + checkNotNull(link, LINK_NULL); | ||
| 134 | + return adjLabelMap.containsKey(link); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public boolean existsTunnelInfo(TunnelId tunnelId) { | ||
| 139 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 140 | + return tunnelLabelInfoMap.containsKey(tunnelId); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Override | ||
| 144 | + public int getGlobalNodeLabelCount() { | ||
| 145 | + return globalNodeLabelMap.size(); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public int getAdjLabelCount() { | ||
| 150 | + return adjLabelMap.size(); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + @Override | ||
| 154 | + public int getTunnelInfoCount() { | ||
| 155 | + return tunnelLabelInfoMap.size(); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + @Override | ||
| 159 | + public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() { | ||
| 160 | + return globalNodeLabelMap.entrySet().stream() | ||
| 161 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value())); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + @Override | ||
| 165 | + public Map<Link, LabelResourceId> getAdjLabels() { | ||
| 166 | + return adjLabelMap.entrySet().stream() | ||
| 167 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value())); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos() { | ||
| 172 | + return tunnelLabelInfoMap.entrySet().stream() | ||
| 173 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value())); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + @Override | ||
| 177 | + public LabelResourceId getGlobalNodeLabel(DeviceId id) { | ||
| 178 | + checkNotNull(id, DEVICE_ID_NULL); | ||
| 179 | + return globalNodeLabelMap.get(id) == null ? null : globalNodeLabelMap.get(id).value(); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + @Override | ||
| 183 | + public LabelResourceId getAdjLabel(Link link) { | ||
| 184 | + checkNotNull(link, LINK_NULL); | ||
| 185 | + return adjLabelMap.get(link) == null ? null : adjLabelMap.get(link).value(); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + @Override | ||
| 189 | + public List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId) { | ||
| 190 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 191 | + return tunnelLabelInfoMap.get(tunnelId) == null ? null : tunnelLabelInfoMap.get(tunnelId).value(); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + @Override | ||
| 195 | + public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) { | ||
| 196 | + checkNotNull(deviceId, DEVICE_ID_NULL); | ||
| 197 | + checkNotNull(labelId, LABEL_RESOURCE_ID_NULL); | ||
| 198 | + | ||
| 199 | + globalNodeLabelMap.put(deviceId, labelId); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + @Override | ||
| 203 | + public void addAdjLabel(Link link, LabelResourceId labelId) { | ||
| 204 | + checkNotNull(link, LINK_NULL); | ||
| 205 | + checkNotNull(labelId, LABEL_RESOURCE_ID_NULL); | ||
| 206 | + | ||
| 207 | + adjLabelMap.put(link, labelId); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + @Override | ||
| 211 | + public void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) { | ||
| 212 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 213 | + checkNotNull(lspLocalLabelInfoList, PCECC_TUNNEL_INFO_NULL); | ||
| 214 | + | ||
| 215 | + tunnelLabelInfoMap.put(tunnelId, lspLocalLabelInfoList); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + @Override | ||
| 219 | + public boolean removeGlobalNodeLabel(DeviceId id) { | ||
| 220 | + checkNotNull(id, DEVICE_ID_NULL); | ||
| 221 | + | ||
| 222 | + if (globalNodeLabelMap.remove(id) == null) { | ||
| 223 | + log.error("SR-TE node label deletion for device {} has failed.", id.toString()); | ||
| 224 | + return false; | ||
| 225 | + } | ||
| 226 | + return true; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + @Override | ||
| 230 | + public boolean removeAdjLabel(Link link) { | ||
| 231 | + checkNotNull(link, LINK_NULL); | ||
| 232 | + | ||
| 233 | + if (adjLabelMap.remove(link) == null) { | ||
| 234 | + log.error("Adjacency label deletion for link {} hash failed.", link.toString()); | ||
| 235 | + return false; | ||
| 236 | + } | ||
| 237 | + return true; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + @Override | ||
| 241 | + public boolean removeTunnelInfo(TunnelId tunnelId) { | ||
| 242 | + checkNotNull(tunnelId, TUNNEL_ID_NULL); | ||
| 243 | + | ||
| 244 | + if (tunnelLabelInfoMap.remove(tunnelId) == null) { | ||
| 245 | + log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString()); | ||
| 246 | + return false; | ||
| 247 | + } | ||
| 248 | + return true; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + @Override | ||
| 252 | + public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) { | ||
| 253 | + checkNotNull(lsrId); | ||
| 254 | + checkNotNull(deviceId); | ||
| 255 | + | ||
| 256 | + lsrIdDeviceIdMap.put(lsrId, deviceId); | ||
| 257 | + return true; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + @Override | ||
| 261 | + public boolean removeLsrIdDevice(String lsrId) { | ||
| 262 | + checkNotNull(lsrId); | ||
| 263 | + | ||
| 264 | + lsrIdDeviceIdMap.remove(lsrId); | ||
| 265 | + return true; | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + @Override | ||
| 269 | + public DeviceId getLsrIdDevice(String lsrId) { | ||
| 270 | + checkNotNull(lsrId); | ||
| 271 | + | ||
| 272 | + return lsrIdDeviceIdMap.get(lsrId); | ||
| 273 | + | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + @Override | ||
| 277 | + public boolean addPccLsr(DeviceId lsrId) { | ||
| 278 | + checkNotNull(lsrId); | ||
| 279 | + pendinglabelDbSyncPccMap.add(lsrId); | ||
| 280 | + return true; | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + @Override | ||
| 284 | + public boolean removePccLsr(DeviceId lsrId) { | ||
| 285 | + checkNotNull(lsrId); | ||
| 286 | + pendinglabelDbSyncPccMap.remove(lsrId); | ||
| 287 | + return true; | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + @Override | ||
| 291 | + public boolean hasPccLsr(DeviceId lsrId) { | ||
| 292 | + checkNotNull(lsrId); | ||
| 293 | + return pendinglabelDbSyncPccMap.contains(lsrId); | ||
| 294 | + | ||
| 295 | + } | ||
| 296 | +} |
| 1 | +package org.onosproject.pcelabelstore; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Representation of label operation over PCEP. | ||
| 5 | + */ | ||
| 6 | +public enum PcepLabelOp { | ||
| 7 | + /** | ||
| 8 | + * Signifies that the label operation is addition. | ||
| 9 | + */ | ||
| 10 | + ADD, | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * Signifies that the label operation is modification. This is reserved for future. | ||
| 14 | + */ | ||
| 15 | + MODIFY, | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * Signifies that the label operation is deletion. | ||
| 19 | + */ | ||
| 20 | + REMOVE | ||
| 21 | +} |
| ... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.pcestore.api; | 16 | +package org.onosproject.pcelabelstore.api; |
| 17 | 17 | ||
| 18 | import org.onosproject.net.DeviceId; | 18 | import org.onosproject.net.DeviceId; |
| 19 | import org.onosproject.net.PortNumber; | 19 | import org.onosproject.net.PortNumber; | ... | ... |
| 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.pcelabelstore.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 java.util.Map; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Abstraction of an entity providing pool of available labels to devices, links and tunnels. | ||
| 28 | + */ | ||
| 29 | +public interface PceLabelStore { | ||
| 30 | + /** | ||
| 31 | + * Checks whether device id is present in global node label store. | ||
| 32 | + * | ||
| 33 | + * @param id device id | ||
| 34 | + * @return success of failure | ||
| 35 | + */ | ||
| 36 | + boolean existsGlobalNodeLabel(DeviceId id); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Checks whether link is present in adjacency label store. | ||
| 40 | + * | ||
| 41 | + * @param link link between devices | ||
| 42 | + * @return success of failure | ||
| 43 | + */ | ||
| 44 | + boolean existsAdjLabel(Link link); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Checks whether tunnel id is present in tunnel info store. | ||
| 48 | + * | ||
| 49 | + * @param tunnelId tunnel id | ||
| 50 | + * @return success of failure | ||
| 51 | + */ | ||
| 52 | + boolean existsTunnelInfo(TunnelId tunnelId); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Retrieves the node label count. | ||
| 56 | + * | ||
| 57 | + * @return node label count | ||
| 58 | + */ | ||
| 59 | + int getGlobalNodeLabelCount(); | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Retrieves the adjacency label count. | ||
| 63 | + * | ||
| 64 | + * @return adjacency label count | ||
| 65 | + */ | ||
| 66 | + int getAdjLabelCount(); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Retrieves the tunnel info count. | ||
| 70 | + * | ||
| 71 | + * @return tunnel info count | ||
| 72 | + */ | ||
| 73 | + int getTunnelInfoCount(); | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * Retrieves device id and label pairs collection from global node label store. | ||
| 77 | + * | ||
| 78 | + * @return collection of device id and label pairs | ||
| 79 | + */ | ||
| 80 | + Map<DeviceId, LabelResourceId> getGlobalNodeLabels(); | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Retrieves link and label pairs collection from adjacency label store. | ||
| 84 | + * | ||
| 85 | + * @return collection of link and label pairs | ||
| 86 | + */ | ||
| 87 | + Map<Link, LabelResourceId> getAdjLabels(); | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * Retrieves tunnel id and pcecc tunnel info pairs collection from tunnel info store. | ||
| 91 | + * | ||
| 92 | + * @return collection of tunnel id and pcecc tunnel info pairs | ||
| 93 | + */ | ||
| 94 | + Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos(); | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Retrieves node label for specified device id. | ||
| 98 | + * | ||
| 99 | + * @param id device id | ||
| 100 | + * @return node label | ||
| 101 | + */ | ||
| 102 | + LabelResourceId getGlobalNodeLabel(DeviceId id); | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Retrieves adjacency label for specified link. | ||
| 106 | + * | ||
| 107 | + * @param link between devices | ||
| 108 | + * @return adjacency label | ||
| 109 | + */ | ||
| 110 | + LabelResourceId getAdjLabel(Link link); | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * Retrieves local label info with tunnel consumer id from tunnel info store. | ||
| 114 | + * | ||
| 115 | + * @param tunnelId tunnel id | ||
| 116 | + * @return pcecc tunnel info | ||
| 117 | + */ | ||
| 118 | + List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId); | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Stores node label into global node label store. | ||
| 122 | + * | ||
| 123 | + * @param deviceId device id | ||
| 124 | + * @param labelId node label id | ||
| 125 | + */ | ||
| 126 | + void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId); | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * Stores adjacency label into adjacency label store. | ||
| 130 | + * | ||
| 131 | + * @param link link between nodes | ||
| 132 | + * @param labelId link label id | ||
| 133 | + */ | ||
| 134 | + void addAdjLabel(Link link, LabelResourceId labelId); | ||
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * Stores local label info with tunnel consumer id into tunnel info store for specified tunnel id. | ||
| 138 | + * | ||
| 139 | + * @param tunnelId tunnel id | ||
| 140 | + * @param lspLocalLabelInfoList local label info | ||
| 141 | + */ | ||
| 142 | + void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList); | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * Removes device label from global node label store for specified device id. | ||
| 146 | + * | ||
| 147 | + * @param id device id | ||
| 148 | + * @return success or failure | ||
| 149 | + */ | ||
| 150 | + boolean removeGlobalNodeLabel(DeviceId id); | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * Removes adjacency label from adjacency label store for specified link information. | ||
| 154 | + * | ||
| 155 | + * @param link between nodes | ||
| 156 | + * @return success or failure | ||
| 157 | + */ | ||
| 158 | + boolean removeAdjLabel(Link link); | ||
| 159 | + | ||
| 160 | + /** | ||
| 161 | + * Removes local label info with tunnel consumer id from tunnel info store for specified tunnel id. | ||
| 162 | + * | ||
| 163 | + * @param tunnelId tunnel id | ||
| 164 | + * @return success or failure | ||
| 165 | + */ | ||
| 166 | + boolean removeTunnelInfo(TunnelId tunnelId); | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * Adds lsrid to device id mapping. | ||
| 170 | + * | ||
| 171 | + * @param lsrId lsrId of the device | ||
| 172 | + * @param deviceId device id | ||
| 173 | + * @return success or failure | ||
| 174 | + */ | ||
| 175 | + boolean addLsrIdDevice(String lsrId, DeviceId deviceId); | ||
| 176 | + | ||
| 177 | + /** | ||
| 178 | + * Removes lsrid to device id mapping. | ||
| 179 | + * | ||
| 180 | + * @param lsrId lsrId of the device | ||
| 181 | + * @return success or failure | ||
| 182 | + */ | ||
| 183 | + boolean removeLsrIdDevice(String lsrId); | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * Gets lsrid to device id mapping. | ||
| 187 | + * | ||
| 188 | + * @param lsrId lsrId of the device | ||
| 189 | + * @return device id of the lsrId | ||
| 190 | + */ | ||
| 191 | + DeviceId getLsrIdDevice(String lsrId); | ||
| 192 | + | ||
| 193 | + /** | ||
| 194 | + * Adds lsrId of the PCC in form of device id for the PCC for which sync is pending due to non-availability of BGP. | ||
| 195 | + * device. | ||
| 196 | + * | ||
| 197 | + * @param lsrId LSR id of the PCC in form of device id | ||
| 198 | + * @return success or failure | ||
| 199 | + */ | ||
| 200 | + public boolean addPccLsr(DeviceId lsrId); | ||
| 201 | + | ||
| 202 | + /** | ||
| 203 | + * Removes lsrId of the PCC in form of device id for the PCC for which pending sync is done. | ||
| 204 | + * | ||
| 205 | + * @param lsrId LSR id of the PCC in form of device id | ||
| 206 | + * @return success or failure | ||
| 207 | + */ | ||
| 208 | + public boolean removePccLsr(DeviceId lsrId); | ||
| 209 | + | ||
| 210 | + /** | ||
| 211 | + * Gets lsrId of the PCC in form of device id. | ||
| 212 | + * | ||
| 213 | + * @param lsrId LSR id of the PCC in form of device id | ||
| 214 | + * @return success or failure | ||
| 215 | + */ | ||
| 216 | + public boolean hasPccLsr(DeviceId lsrId); | ||
| 217 | +} |
| ... | @@ -13,7 +13,8 @@ | ... | @@ -13,7 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | + | ||
| 16 | /** | 17 | /** |
| 17 | - *Provider that uses PCEP controller as a means to send packets. | 18 | + * PCE store service API. |
| 18 | */ | 19 | */ |
| 19 | -package org.onosproject.provider.pcep.packet.impl; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 20 | +package org.onosproject.pcelabelstore.api; | ... | ... |
| ... | @@ -13,10 +13,8 @@ | ... | @@ -13,10 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pcep.controller; | ||
| 17 | 16 | ||
| 18 | -public interface PcepPacketListener { | 17 | +/** |
| 19 | - | 18 | + * PCE store application. |
| 20 | - void sendPacketIn(PccId pccId); | 19 | + */ |
| 21 | - | 20 | +package org.onosproject.pcelabelstore; |
| 22 | -} | ... | ... |
protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/BasicPceccHandler.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.pcep.controller.impl; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.Collection; | ||
| 21 | +import java.util.Iterator; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.ListIterator; | ||
| 24 | +import java.util.LinkedList; | ||
| 25 | + | ||
| 26 | +import org.onlab.packet.Ip4Address; | ||
| 27 | +import org.onlab.packet.IpAddress; | ||
| 28 | +import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 29 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 30 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 31 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 32 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 33 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 34 | +import org.onosproject.net.ConnectPoint; | ||
| 35 | +import org.onosproject.net.Device; | ||
| 36 | +import org.onosproject.net.DeviceId; | ||
| 37 | +import org.onosproject.net.PortNumber; | ||
| 38 | +import org.onosproject.net.device.DeviceService; | ||
| 39 | +import org.onosproject.pcelabelstore.DefaultLspLocalLabelInfo; | ||
| 40 | +import org.onosproject.pcelabelstore.PcepLabelOp; | ||
| 41 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; | ||
| 42 | +import org.onosproject.pcelabelstore.api.PceLabelStore; | ||
| 43 | +import org.onosproject.pcep.controller.LspType; | ||
| 44 | +import org.onosproject.pcep.controller.PccId; | ||
| 45 | +import org.onosproject.pcep.controller.PcepAnnotationKeys; | ||
| 46 | +import org.onosproject.pcep.controller.PcepClient; | ||
| 47 | +import org.onosproject.pcep.controller.PcepClientController; | ||
| 48 | +import org.onosproject.pcep.controller.SrpIdGenerators; | ||
| 49 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
| 50 | +import org.onosproject.pcepio.protocol.PcepAttribute; | ||
| 51 | +import org.onosproject.pcepio.protocol.PcepBandwidthObject; | ||
| 52 | +import org.onosproject.pcepio.protocol.PcepEroObject; | ||
| 53 | +import org.onosproject.pcepio.protocol.PcepLabelObject; | ||
| 54 | +import org.onosproject.pcepio.protocol.PcepLabelUpdate; | ||
| 55 | +import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; | ||
| 56 | +import org.onosproject.pcepio.protocol.PcepLspObject; | ||
| 57 | +import org.onosproject.pcepio.protocol.PcepMsgPath; | ||
| 58 | +import org.onosproject.pcepio.protocol.PcepSrpObject; | ||
| 59 | +import org.onosproject.pcepio.protocol.PcepUpdateMsg; | ||
| 60 | +import org.onosproject.pcepio.protocol.PcepUpdateRequest; | ||
| 61 | +import org.onosproject.pcepio.types.IPv4SubObject; | ||
| 62 | +import org.onosproject.pcepio.types.NexthopIPv4addressTlv; | ||
| 63 | +import org.onosproject.pcepio.types.PathSetupTypeTlv; | ||
| 64 | +import org.onosproject.pcepio.types.PcepLabelDownload; | ||
| 65 | +import org.onosproject.pcepio.types.PcepValueType; | ||
| 66 | +import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; | ||
| 67 | +import org.onosproject.pcepio.types.SymbolicPathNameTlv; | ||
| 68 | +import org.onosproject.net.Link; | ||
| 69 | +import org.onosproject.net.Path; | ||
| 70 | +import org.slf4j.Logger; | ||
| 71 | +import org.slf4j.LoggerFactory; | ||
| 72 | + | ||
| 73 | +import com.google.common.collect.ArrayListMultimap; | ||
| 74 | +import com.google.common.collect.Multimap; | ||
| 75 | + | ||
| 76 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH; | ||
| 77 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE; | ||
| 78 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT; | ||
| 79 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE; | ||
| 80 | + | ||
| 81 | +/** | ||
| 82 | + * Basic PCECC handler. | ||
| 83 | + * In Basic PCECC, after path computation will configure IN and OUT label to nodes. | ||
| 84 | + * [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes. | ||
| 85 | + * For generating labels, will go thorough links in the path from Egress to Ingress. | ||
| 86 | + * In each link, will take label from destination node local pool as IN label, | ||
| 87 | + * and assign this label as OUT label to source node. | ||
| 88 | + */ | ||
| 89 | +public final class BasicPceccHandler { | ||
| 90 | + private static final Logger log = LoggerFactory.getLogger(BasicPceccHandler.class); | ||
| 91 | + public static final int OUT_LABEL_TYPE = 0; | ||
| 92 | + public static final int IN_LABEL_TYPE = 1; | ||
| 93 | + public static final long IDENTIFIER_SET = 0x100000000L; | ||
| 94 | + public static final long SET = 0xFFFFFFFFL; | ||
| 95 | + private static final String LSRID = "lsrId"; | ||
| 96 | + private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null"; | ||
| 97 | + private static final String PCE_STORE_NULL = "PCE Store cannot be null"; | ||
| 98 | + private static BasicPceccHandler crHandlerInstance = null; | ||
| 99 | + private LabelResourceService labelRsrcService; | ||
| 100 | + private DeviceService deviceService; | ||
| 101 | + private PceLabelStore pceStore; | ||
| 102 | + private PcepClientController clientController; | ||
| 103 | + private PcepLabelObject labelObj; | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * Initializes default values. | ||
| 107 | + */ | ||
| 108 | + private BasicPceccHandler() { | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Returns single instance of this class. | ||
| 113 | + * | ||
| 114 | + * @return this class single instance | ||
| 115 | + */ | ||
| 116 | + public static BasicPceccHandler getInstance() { | ||
| 117 | + if (crHandlerInstance == null) { | ||
| 118 | + crHandlerInstance = new BasicPceccHandler(); | ||
| 119 | + } | ||
| 120 | + return crHandlerInstance; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Initialization of label manager and pce store. | ||
| 125 | + * | ||
| 126 | + * @param labelRsrcService label resource service | ||
| 127 | + * @param pceStore pce label store | ||
| 128 | + */ | ||
| 129 | + public void initialize(LabelResourceService labelRsrcService, | ||
| 130 | + DeviceService deviceService, | ||
| 131 | + PceLabelStore pceStore, | ||
| 132 | + PcepClientController clientController) { | ||
| 133 | + this.labelRsrcService = labelRsrcService; | ||
| 134 | + this.deviceService = deviceService; | ||
| 135 | + this.pceStore = pceStore; | ||
| 136 | + this.clientController = clientController; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * Allocates labels from local resource pool and configure these (IN and OUT) labels into devices. | ||
| 141 | + * | ||
| 142 | + * @param tunnel tunnel between ingress to egress | ||
| 143 | + * @return success or failure | ||
| 144 | + */ | ||
| 145 | + public boolean allocateLabel(Tunnel tunnel) { | ||
| 146 | + long applyNum = 1; | ||
| 147 | + boolean isLastLabelToPush = false; | ||
| 148 | + Collection<LabelResource> labelRscList; | ||
| 149 | + | ||
| 150 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 151 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 152 | + | ||
| 153 | + List<Link> linkList = tunnel.path().links(); | ||
| 154 | + if ((linkList != null) && (linkList.size() > 0)) { | ||
| 155 | + // Sequence through reverse order to push local labels into devices | ||
| 156 | + // Generation of labels from egress to ingress | ||
| 157 | + for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { | ||
| 158 | + Link link = iterator.previous(); | ||
| 159 | + DeviceId dstDeviceId = link.dst().deviceId(); | ||
| 160 | + DeviceId srcDeviceId = link.src().deviceId(); | ||
| 161 | + labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); | ||
| 162 | + if ((labelRscList != null) && (labelRscList.size() > 0)) { | ||
| 163 | + // Link label value is taken from destination device local pool. | ||
| 164 | + // [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes. | ||
| 165 | + // Link label value is used as OUT and IN for both ends | ||
| 166 | + // (source and destination devices) of the link. | ||
| 167 | + // Currently only one label is allocated to a device (destination device). | ||
| 168 | + // So, no need to iterate through list | ||
| 169 | + Iterator<LabelResource> labelIterator = labelRscList.iterator(); | ||
| 170 | + DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); | ||
| 171 | + LabelResourceId labelId = defaultLabelResource.labelResourceId(); | ||
| 172 | + log.debug("Allocated local label: " + labelId.toString() | ||
| 173 | + + "to device: " + defaultLabelResource.deviceId().toString()); | ||
| 174 | + PortNumber dstPort = link.dst().port(); | ||
| 175 | + | ||
| 176 | + // Check whether this is last link label to push | ||
| 177 | + if (!iterator.hasPrevious()) { | ||
| 178 | + isLastLabelToPush = true; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + try { | ||
| 182 | + // Push into destination device | ||
| 183 | + // Destination device IN port is link.dst().port() | ||
| 184 | + pushLocalLabels(dstDeviceId, labelId, dstPort, tunnel, false, | ||
| 185 | + Long.valueOf(LabelType.IN_LABEL.value), PcepLabelOp.ADD); | ||
| 186 | + | ||
| 187 | + // Push into source device | ||
| 188 | + // Source device OUT port will be link.dst().port(). Means its remote port used to send packet. | ||
| 189 | + pushLocalLabels(srcDeviceId, labelId, dstPort, tunnel, isLastLabelToPush, | ||
| 190 | + Long.valueOf(LabelType.OUT_LABEL.value), PcepLabelOp.ADD); | ||
| 191 | + } catch (PcepParseException e) { | ||
| 192 | + log.error("Failed to push local label for device {} or {} for tunnel {}.", | ||
| 193 | + dstDeviceId.toString(), srcDeviceId.toString(), tunnel.tunnelName().toString()); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + // Add or update pcecc tunnel info in pce store. | ||
| 197 | + updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, | ||
| 198 | + tunnel); | ||
| 199 | + } else { | ||
| 200 | + log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); | ||
| 201 | + releaseLabel(tunnel); | ||
| 202 | + return false; | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | + } else { | ||
| 206 | + log.error("Tunnel {} is having empty links.", tunnel.toString()); | ||
| 207 | + return false; | ||
| 208 | + } | ||
| 209 | + return true; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + /** | ||
| 213 | + * Updates list of local labels of PCECC tunnel info in pce store. | ||
| 214 | + * | ||
| 215 | + * @param srcDeviceId source device in a link | ||
| 216 | + * @param dstDeviceId destination device in a link | ||
| 217 | + * @param labelId label id of a link | ||
| 218 | + * @param dstPort destination device port number of a link | ||
| 219 | + * @param tunnel tunnel | ||
| 220 | + */ | ||
| 221 | + public void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId, | ||
| 222 | + PortNumber dstPort, Tunnel tunnel) { | ||
| 223 | + // First try to retrieve device from store and update its label id if it is exists, | ||
| 224 | + // otherwise add it | ||
| 225 | + boolean dstDeviceUpdated = false; | ||
| 226 | + boolean srcDeviceUpdated = false; | ||
| 227 | + | ||
| 228 | + List<LspLocalLabelInfo> lspLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 229 | + if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) { | ||
| 230 | + for (int i = 0; i < lspLabelInfoList.size(); ++i) { | ||
| 231 | + LspLocalLabelInfo lspLocalLabelInfo = | ||
| 232 | + lspLabelInfoList.get(i); | ||
| 233 | + LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null; | ||
| 234 | + if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) { | ||
| 235 | + lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | ||
| 236 | + lspLocalLabelInfoBuilder.inLabelId(labelId); | ||
| 237 | + // Destination device IN port will be link destination port | ||
| 238 | + lspLocalLabelInfoBuilder.inPort(dstPort); | ||
| 239 | + dstDeviceUpdated = true; | ||
| 240 | + } else if (srcDeviceId.equals(lspLocalLabelInfo.deviceId())) { | ||
| 241 | + lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | ||
| 242 | + lspLocalLabelInfoBuilder.outLabelId(labelId); | ||
| 243 | + // Source device OUT port will be link destination (remote) port | ||
| 244 | + lspLocalLabelInfoBuilder.outPort(dstPort); | ||
| 245 | + srcDeviceUpdated = true; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + // Update | ||
| 249 | + if ((lspLocalLabelInfoBuilder != null) && (dstDeviceUpdated || srcDeviceUpdated)) { | ||
| 250 | + lspLabelInfoList.set(i, lspLocalLabelInfoBuilder.build()); | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + // If it is not found in store then add it to store | ||
| 256 | + if (!dstDeviceUpdated || !srcDeviceUpdated) { | ||
| 257 | + // If tunnel info itself not available then create new one, otherwise add node to list. | ||
| 258 | + if (lspLabelInfoList == null) { | ||
| 259 | + lspLabelInfoList = new LinkedList<>(); | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + if (!dstDeviceUpdated) { | ||
| 263 | + LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 264 | + .deviceId(dstDeviceId) | ||
| 265 | + .inLabelId(labelId) | ||
| 266 | + .outLabelId(null) | ||
| 267 | + .inPort(dstPort) // Destination device IN port will be link destination port | ||
| 268 | + .outPort(null) | ||
| 269 | + .build(); | ||
| 270 | + lspLabelInfoList.add(lspLocalLabelInfo); | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + if (!srcDeviceUpdated) { | ||
| 274 | + LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 275 | + .deviceId(srcDeviceId) | ||
| 276 | + .inLabelId(null) | ||
| 277 | + .outLabelId(labelId) | ||
| 278 | + .inPort(null) | ||
| 279 | + .outPort(dstPort) // Source device OUT port will be link destination (remote) port | ||
| 280 | + .build(); | ||
| 281 | + lspLabelInfoList.add(lspLocalLabelInfo); | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | + pceStore.addTunnelInfo(tunnel.tunnelId(), lspLabelInfoList); | ||
| 285 | + } | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + /** | ||
| 289 | + * Deallocates unused labels to device pools. | ||
| 290 | + * | ||
| 291 | + * @param tunnel tunnel between ingress to egress | ||
| 292 | + */ | ||
| 293 | + public void releaseLabel(Tunnel tunnel) { | ||
| 294 | + | ||
| 295 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 296 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 297 | + | ||
| 298 | + Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); | ||
| 299 | + List<LspLocalLabelInfo> lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 300 | + if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) { | ||
| 301 | + for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) { | ||
| 302 | + LspLocalLabelInfo lspLocalLabelInfo = iterator.next(); | ||
| 303 | + DeviceId deviceId = lspLocalLabelInfo.deviceId(); | ||
| 304 | + LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 305 | + LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 306 | + PortNumber inPort = lspLocalLabelInfo.inPort(); | ||
| 307 | + PortNumber outPort = lspLocalLabelInfo.outPort(); | ||
| 308 | + | ||
| 309 | + try { | ||
| 310 | + // Push into device | ||
| 311 | + if ((outLabelId != null) && (outPort != null)) { | ||
| 312 | + pushLocalLabels(deviceId, outLabelId, outPort, tunnel, false, | ||
| 313 | + Long.valueOf(LabelType.OUT_LABEL.value), PcepLabelOp.REMOVE); | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + if ((inLabelId != null) && (inPort != null)) { | ||
| 317 | + pushLocalLabels(deviceId, inLabelId, inPort, tunnel, false, | ||
| 318 | + Long.valueOf(LabelType.IN_LABEL.value), PcepLabelOp.REMOVE); | ||
| 319 | + } | ||
| 320 | + } catch (PcepParseException e) { | ||
| 321 | + log.error("Failed to push local label for device {}for tunnel {}.", deviceId.toString(), | ||
| 322 | + tunnel.tunnelName().toString()); | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + // List is stored from egress to ingress. So, using IN label id to release. | ||
| 326 | + // Only one local label is assigned to device (destination node) | ||
| 327 | + // and that is used as OUT label for source node. | ||
| 328 | + // No need to release label for last node in the list from pool because label was not allocated to | ||
| 329 | + // ingress node (source node). | ||
| 330 | + if ((iterator.hasNext()) && (inLabelId != null)) { | ||
| 331 | + LabelResource labelRsc = new DefaultLabelResource(deviceId, inLabelId); | ||
| 332 | + release.put(deviceId, labelRsc); | ||
| 333 | + } | ||
| 334 | + } | ||
| 335 | + } | ||
| 336 | + | ||
| 337 | + // Release from label pool | ||
| 338 | + if (!release.isEmpty()) { | ||
| 339 | + labelRsrcService.releaseToDevicePool(release); | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + pceStore.removeTunnelInfo(tunnel.tunnelId()); | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + //Pushes local labels to the device which is specific to path [CR-case]. | ||
| 346 | + private void pushLocalLabels(DeviceId deviceId, LabelResourceId labelId, | ||
| 347 | + PortNumber portNum, Tunnel tunnel, | ||
| 348 | + Boolean isBos, Long labelType, PcepLabelOp type) throws PcepParseException { | ||
| 349 | + | ||
| 350 | + checkNotNull(deviceId); | ||
| 351 | + checkNotNull(labelId); | ||
| 352 | + checkNotNull(portNum); | ||
| 353 | + checkNotNull(tunnel); | ||
| 354 | + checkNotNull(labelType); | ||
| 355 | + checkNotNull(type); | ||
| 356 | + | ||
| 357 | + PcepClient pc = getPcepClient(deviceId); | ||
| 358 | + if (pc == null) { | ||
| 359 | + log.error("PCEP client not found"); | ||
| 360 | + return; | ||
| 361 | + } | ||
| 362 | + | ||
| 363 | + PcepLspObject lspObj; | ||
| 364 | + LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); | ||
| 365 | + LinkedList<PcepLabelObject> labelObjects = new LinkedList<>(); | ||
| 366 | + PcepSrpObject srpObj; | ||
| 367 | + PcepLabelDownload labelDownload = new PcepLabelDownload(); | ||
| 368 | + LinkedList<PcepValueType> optionalTlv = new LinkedList<>(); | ||
| 369 | + | ||
| 370 | + long portNo = portNum.toLong(); | ||
| 371 | + portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; | ||
| 372 | + | ||
| 373 | + optionalTlv.add(NexthopIPv4addressTlv.of((int) portNo)); | ||
| 374 | + | ||
| 375 | + PcepLabelObject labelObj = pc.factory().buildLabelObject() | ||
| 376 | + .setOFlag(labelType == OUT_LABEL_TYPE ? true : false) | ||
| 377 | + .setOptionalTlv(optionalTlv) | ||
| 378 | + .setLabel((int) labelId.labelId()) | ||
| 379 | + .build(); | ||
| 380 | + | ||
| 381 | + /** | ||
| 382 | + * Check whether transit node or not. For transit node, label update message should include IN and OUT labels. | ||
| 383 | + * Hence store IN label object and next when out label comes add IN and OUT label objects and encode label | ||
| 384 | + * update message and send to specified client. | ||
| 385 | + */ | ||
| 386 | + if (!deviceId.equals(tunnel.path().src().deviceId()) && !deviceId.equals(tunnel.path().dst().deviceId())) { | ||
| 387 | + //Device is transit node | ||
| 388 | + if (labelType == OUT_LABEL_TYPE) { | ||
| 389 | + //Store label object having IN label value | ||
| 390 | + this.labelObj = labelObj; | ||
| 391 | + return; | ||
| 392 | + } | ||
| 393 | + //Add IN label object | ||
| 394 | + labelObjects.add(this.labelObj); | ||
| 395 | + } | ||
| 396 | + | ||
| 397 | + //Add OUT label object in case of transit node | ||
| 398 | + labelObjects.add(labelObj); | ||
| 399 | + | ||
| 400 | + srpObj = getSrpObject(pc, type, false); | ||
| 401 | + | ||
| 402 | + String lspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID); | ||
| 403 | + String plspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID); | ||
| 404 | + String tunnelIdentifier = tunnel.annotations().value(PcepAnnotationKeys.PCC_TUNNEL_ID); | ||
| 405 | + | ||
| 406 | + LinkedList<PcepValueType> tlvs = new LinkedList<>(); | ||
| 407 | + StatefulIPv4LspIdentifiersTlv lspIdTlv = new StatefulIPv4LspIdentifiersTlv(((IpTunnelEndPoint) tunnel.src()) | ||
| 408 | + .ip().getIp4Address().toInt(), Short.valueOf(lspId), Short.valueOf(tunnelIdentifier), | ||
| 409 | + ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(), | ||
| 410 | + ((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()); | ||
| 411 | + tlvs.add(lspIdTlv); | ||
| 412 | + | ||
| 413 | + if (tunnel.tunnelName().value() != null) { | ||
| 414 | + SymbolicPathNameTlv pathNameTlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); | ||
| 415 | + tlvs.add(pathNameTlv); | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false | ||
| 419 | + : Boolean.valueOf(tunnel.annotations() | ||
| 420 | + .value(DELEGATE)); | ||
| 421 | + boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false | ||
| 422 | + : Boolean.valueOf(tunnel.annotations() | ||
| 423 | + .value(PCE_INIT)); | ||
| 424 | + | ||
| 425 | + lspObj = pc.factory().buildLspObject() | ||
| 426 | + .setRFlag(false) | ||
| 427 | + .setAFlag(true) | ||
| 428 | + .setDFlag(delegated) | ||
| 429 | + .setCFlag(initiated) | ||
| 430 | + .setPlspId(Integer.valueOf(plspId)) | ||
| 431 | + .setOptionalTlv(tlvs) | ||
| 432 | + .build(); | ||
| 433 | + | ||
| 434 | + labelDownload.setLabelList(labelObjects); | ||
| 435 | + labelDownload.setLspObject(lspObj); | ||
| 436 | + labelDownload.setSrpObject(srpObj); | ||
| 437 | + | ||
| 438 | + labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() | ||
| 439 | + .setLabelDownload(labelDownload) | ||
| 440 | + .build()); | ||
| 441 | + | ||
| 442 | + PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() | ||
| 443 | + .setPcLabelUpdateList(labelUpdateList) | ||
| 444 | + .build(); | ||
| 445 | + | ||
| 446 | + pc.sendMessage(labelMsg); | ||
| 447 | + | ||
| 448 | + //If isBos is true, label download is done along the LSP, send PCEP update message. | ||
| 449 | + if (isBos) { | ||
| 450 | + sendPcepUpdateMsg(pc, lspObj, tunnel); | ||
| 451 | + } | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + //Sends PCEP update message. | ||
| 455 | + private void sendPcepUpdateMsg(PcepClient pc, PcepLspObject lspObj, Tunnel tunnel) throws PcepParseException { | ||
| 456 | + LinkedList<PcepUpdateRequest> updateRequestList = new LinkedList<>(); | ||
| 457 | + LinkedList<PcepValueType> subObjects = createEroSubObj(tunnel.path()); | ||
| 458 | + | ||
| 459 | + if (subObjects == null) { | ||
| 460 | + log.error("ERO subjects not present"); | ||
| 461 | + return; | ||
| 462 | + } | ||
| 463 | + | ||
| 464 | + // set PathSetupTypeTlv of SRP object | ||
| 465 | + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | ||
| 466 | + LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); | ||
| 467 | + llOptionalTlv.add(new PathSetupTypeTlv(lspSigType.type())); | ||
| 468 | + | ||
| 469 | + PcepSrpObject srpObj = pc.factory().buildSrpObject() | ||
| 470 | + .setRFlag(false) | ||
| 471 | + .setSrpID(SrpIdGenerators.create()) | ||
| 472 | + .setOptionalTlv(llOptionalTlv) | ||
| 473 | + .build(); | ||
| 474 | + | ||
| 475 | + PcepEroObject eroObj = pc.factory().buildEroObject() | ||
| 476 | + .setSubObjects(subObjects) | ||
| 477 | + .build(); | ||
| 478 | + | ||
| 479 | + float iBandwidth = 0; | ||
| 480 | + if (tunnel.annotations().value(BANDWIDTH) != null) { | ||
| 481 | + //iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH))); | ||
| 482 | + iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH)); | ||
| 483 | + } | ||
| 484 | + // build bandwidth object | ||
| 485 | + PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject() | ||
| 486 | + .setBandwidth(iBandwidth) | ||
| 487 | + .build(); | ||
| 488 | + // build pcep attribute | ||
| 489 | + PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute() | ||
| 490 | + .setBandwidthObject(bandwidthObject) | ||
| 491 | + .build(); | ||
| 492 | + | ||
| 493 | + PcepMsgPath msgPath = pc.factory().buildPcepMsgPath() | ||
| 494 | + .setEroObject(eroObj) | ||
| 495 | + .setPcepAttribute(pcepAttribute) | ||
| 496 | + .build(); | ||
| 497 | + | ||
| 498 | + PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest() | ||
| 499 | + .setSrpObject(srpObj) | ||
| 500 | + .setMsgPath(msgPath) | ||
| 501 | + .setLspObject(lspObj) | ||
| 502 | + .build(); | ||
| 503 | + | ||
| 504 | + updateRequestList.add(updateReq); | ||
| 505 | + | ||
| 506 | + //TODO: P = 1 is it P flag in PCEP obj header | ||
| 507 | + PcepUpdateMsg updateMsg = pc.factory().buildUpdateMsg() | ||
| 508 | + .setUpdateRequestList(updateRequestList) | ||
| 509 | + .build(); | ||
| 510 | + | ||
| 511 | + pc.sendMessage(updateMsg); | ||
| 512 | + } | ||
| 513 | + | ||
| 514 | + private LinkedList<PcepValueType> createEroSubObj(Path path) { | ||
| 515 | + LinkedList<PcepValueType> subObjects = new LinkedList<>(); | ||
| 516 | + List<Link> links = path.links(); | ||
| 517 | + ConnectPoint source = null; | ||
| 518 | + ConnectPoint destination = null; | ||
| 519 | + IpAddress ipDstAddress = null; | ||
| 520 | + IpAddress ipSrcAddress = null; | ||
| 521 | + PcepValueType subObj = null; | ||
| 522 | + long portNo; | ||
| 523 | + | ||
| 524 | + for (Link link : links) { | ||
| 525 | + source = link.src(); | ||
| 526 | + if (!(source.equals(destination))) { | ||
| 527 | + //set IPv4SubObject for ERO object | ||
| 528 | + portNo = source.port().toLong(); | ||
| 529 | + portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; | ||
| 530 | + ipSrcAddress = Ip4Address.valueOf((int) portNo); | ||
| 531 | + subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); | ||
| 532 | + subObjects.add(subObj); | ||
| 533 | + } | ||
| 534 | + | ||
| 535 | + destination = link.dst(); | ||
| 536 | + portNo = destination.port().toLong(); | ||
| 537 | + portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; | ||
| 538 | + ipDstAddress = Ip4Address.valueOf((int) portNo); | ||
| 539 | + subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); | ||
| 540 | + subObjects.add(subObj); | ||
| 541 | + } | ||
| 542 | + return subObjects; | ||
| 543 | + } | ||
| 544 | + | ||
| 545 | + private PcepSrpObject getSrpObject(PcepClient pc, PcepLabelOp type, boolean bSFlag) | ||
| 546 | + throws PcepParseException { | ||
| 547 | + PcepSrpObject srpObj; | ||
| 548 | + boolean bRFlag = false; | ||
| 549 | + | ||
| 550 | + if (!type.equals(PcepLabelOp.ADD)) { | ||
| 551 | + // To cleanup labels, R bit is set | ||
| 552 | + bRFlag = true; | ||
| 553 | + } | ||
| 554 | + | ||
| 555 | + srpObj = pc.factory().buildSrpObject() | ||
| 556 | + .setRFlag(bRFlag) | ||
| 557 | + .setSFlag(bSFlag) | ||
| 558 | + .setSrpID(SrpIdGenerators.create()) | ||
| 559 | + .build(); | ||
| 560 | + | ||
| 561 | + return srpObj; | ||
| 562 | + } | ||
| 563 | + | ||
| 564 | + /** | ||
| 565 | + * Returns PCEP client. | ||
| 566 | + * | ||
| 567 | + * @return PCEP client | ||
| 568 | + */ | ||
| 569 | + private PcepClient getPcepClient(DeviceId deviceId) { | ||
| 570 | + Device device = deviceService.getDevice(deviceId); | ||
| 571 | + | ||
| 572 | + // In future projections instead of annotations will be used to fetch LSR ID. | ||
| 573 | + String lsrId = device.annotations().value(LSRID); | ||
| 574 | + PcepClient pcc = clientController.getClient(PccId.pccId(IpAddress.valueOf(lsrId))); | ||
| 575 | + return pcc; | ||
| 576 | + } | ||
| 577 | +} |
| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | -package org.onosproject.pce.pceservice; | 17 | +package org.onosproject.pcep.controller.impl; |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * Describes about Label type. | 20 | * Describes about Label type. | ... | ... |
| ... | @@ -13,9 +13,11 @@ | ... | @@ -13,9 +13,11 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.pceservice; | 16 | +package org.onosproject.pcep.controller.impl; |
| 17 | 17 | ||
| 18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | +import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; | ||
| 20 | +import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; | ||
| 19 | 21 | ||
| 20 | import java.util.Collection; | 22 | import java.util.Collection; |
| 21 | import java.util.Iterator; | 23 | import java.util.Iterator; |
| ... | @@ -26,9 +28,6 @@ import java.util.Map; | ... | @@ -26,9 +28,6 @@ import java.util.Map; |
| 26 | import java.util.Set; | 28 | import java.util.Set; |
| 27 | 29 | ||
| 28 | import org.onlab.packet.IpAddress; | 30 | import org.onlab.packet.IpAddress; |
| 29 | -import org.onlab.packet.IpPrefix; | ||
| 30 | -import org.onlab.packet.MplsLabel; | ||
| 31 | -import org.onosproject.core.ApplicationId; | ||
| 32 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | 31 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; |
| 33 | import org.onosproject.incubator.net.resource.label.LabelResource; | 32 | import org.onosproject.incubator.net.resource.label.LabelResource; |
| 34 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 33 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| ... | @@ -37,20 +36,24 @@ import org.onosproject.incubator.net.resource.label.LabelResourceService; | ... | @@ -37,20 +36,24 @@ import org.onosproject.incubator.net.resource.label.LabelResourceService; |
| 37 | import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | 36 | import org.onosproject.incubator.net.tunnel.DefaultLabelStack; |
| 38 | import org.onosproject.incubator.net.tunnel.LabelStack; | 37 | import org.onosproject.incubator.net.tunnel.LabelStack; |
| 39 | import org.onosproject.net.device.DeviceService; | 38 | import org.onosproject.net.device.DeviceService; |
| 39 | +import org.onosproject.pcelabelstore.PcepLabelOp; | ||
| 40 | +import org.onosproject.pcelabelstore.api.PceLabelStore; | ||
| 40 | import org.onosproject.net.Device; | 41 | import org.onosproject.net.Device; |
| 41 | import org.onosproject.net.DeviceId; | 42 | import org.onosproject.net.DeviceId; |
| 42 | -import org.onosproject.pce.pcestore.api.PceStore; | ||
| 43 | import org.onosproject.net.Link; | 43 | import org.onosproject.net.Link; |
| 44 | import org.onosproject.net.Path; | 44 | import org.onosproject.net.Path; |
| 45 | -import org.onosproject.net.PortNumber; | 45 | +import org.onosproject.pcep.controller.PccId; |
| 46 | -import org.onosproject.net.flow.DefaultTrafficSelector; | 46 | +import org.onosproject.pcep.controller.PcepClient; |
| 47 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | 47 | +import org.onosproject.pcep.controller.PcepClientController; |
| 48 | -import org.onosproject.net.flow.TrafficSelector; | 48 | +import org.onosproject.pcep.controller.SrpIdGenerators; |
| 49 | -import org.onosproject.net.flow.TrafficTreatment; | 49 | +import org.onosproject.pcepio.exceptions.PcepParseException; |
| 50 | -import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 50 | +import org.onosproject.pcepio.protocol.PcepFecObjectIPv4; |
| 51 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | 51 | +import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; |
| 52 | -import org.onosproject.net.flowobjective.ForwardingObjective; | 52 | +import org.onosproject.pcepio.protocol.PcepLabelObject; |
| 53 | -import org.onosproject.net.flowobjective.Objective; | 53 | +import org.onosproject.pcepio.protocol.PcepLabelUpdate; |
| 54 | +import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; | ||
| 55 | +import org.onosproject.pcepio.protocol.PcepSrpObject; | ||
| 56 | +import org.onosproject.pcepio.types.PcepLabelMap; | ||
| 54 | import org.slf4j.Logger; | 57 | import org.slf4j.Logger; |
| 55 | import org.slf4j.LoggerFactory; | 58 | import org.slf4j.LoggerFactory; |
| 56 | 59 | ||
| ... | @@ -75,14 +78,12 @@ public final class PceccSrTeBeHandler { | ... | @@ -75,14 +78,12 @@ public final class PceccSrTeBeHandler { |
| 75 | private static final String LINK_NULL = "Link cannot be null"; | 78 | private static final String LINK_NULL = "Link cannot be null"; |
| 76 | private static final String PATH_NULL = "Path cannot be null"; | 79 | private static final String PATH_NULL = "Path cannot be null"; |
| 77 | private static final String LSR_ID = "lsrId"; | 80 | private static final String LSR_ID = "lsrId"; |
| 78 | - private static final int PREFIX_LENGTH = 32; | ||
| 79 | private static PceccSrTeBeHandler srTeHandlerInstance = null; | 81 | private static PceccSrTeBeHandler srTeHandlerInstance = null; |
| 80 | private LabelResourceAdminService labelRsrcAdminService; | 82 | private LabelResourceAdminService labelRsrcAdminService; |
| 81 | private LabelResourceService labelRsrcService; | 83 | private LabelResourceService labelRsrcService; |
| 82 | - private FlowObjectiveService flowObjectiveService; | ||
| 83 | private DeviceService deviceService; | 84 | private DeviceService deviceService; |
| 84 | - private PceStore pceStore; | 85 | + private PcepClientController clientController; |
| 85 | - private ApplicationId appId; | 86 | + private PceLabelStore pceStore; |
| 86 | 87 | ||
| 87 | /** | 88 | /** |
| 88 | * Initializes default values. | 89 | * Initializes default values. |
| ... | @@ -107,19 +108,18 @@ public final class PceccSrTeBeHandler { | ... | @@ -107,19 +108,18 @@ public final class PceccSrTeBeHandler { |
| 107 | * | 108 | * |
| 108 | * @param labelRsrcAdminService label resource admin service | 109 | * @param labelRsrcAdminService label resource admin service |
| 109 | * @param labelRsrcService label resource service | 110 | * @param labelRsrcService label resource service |
| 110 | - * @param flowObjectiveService flow objective service to push device label information | ||
| 111 | - * @param appId application id | ||
| 112 | * @param pceStore PCE label store | 111 | * @param pceStore PCE label store |
| 113 | * @param deviceService device service | 112 | * @param deviceService device service |
| 114 | */ | 113 | */ |
| 115 | - public void initialize(LabelResourceAdminService labelRsrcAdminService, LabelResourceService labelRsrcService, | 114 | + public void initialize(LabelResourceAdminService labelRsrcAdminService, |
| 116 | - FlowObjectiveService flowObjectiveService, ApplicationId appId, PceStore pceStore, | 115 | + LabelResourceService labelRsrcService, |
| 116 | + PcepClientController clientController, | ||
| 117 | + PceLabelStore pceStore, | ||
| 117 | DeviceService deviceService) { | 118 | DeviceService deviceService) { |
| 118 | this.labelRsrcAdminService = labelRsrcAdminService; | 119 | this.labelRsrcAdminService = labelRsrcAdminService; |
| 119 | this.labelRsrcService = labelRsrcService; | 120 | this.labelRsrcService = labelRsrcService; |
| 120 | - this.flowObjectiveService = flowObjectiveService; | 121 | + this.clientController = clientController; |
| 121 | this.pceStore = pceStore; | 122 | this.pceStore = pceStore; |
| 122 | - this.appId = appId; | ||
| 123 | this.deviceService = deviceService; | 123 | this.deviceService = deviceService; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| ... | @@ -208,14 +208,20 @@ public final class PceccSrTeBeHandler { | ... | @@ -208,14 +208,20 @@ public final class PceccSrTeBeHandler { |
| 208 | pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); | 208 | pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); |
| 209 | 209 | ||
| 210 | // Push its label information into specificDeviceId | 210 | // Push its label information into specificDeviceId |
| 211 | - advertiseNodeLabelRule(specificDeviceId, specificLabelId, | 211 | + PcepClient pcc = getPcepClient(specificDeviceId); |
| 212 | - IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), | 212 | + try { |
| 213 | - Objective.Operation.ADD, false); | 213 | + pushGlobalNodeLabel(pcc, |
| 214 | + specificLabelId, | ||
| 215 | + IpAddress.valueOf(specificLsrId).getIp4Address().toInt(), | ||
| 216 | + PcepLabelOp.ADD, | ||
| 217 | + false); | ||
| 218 | + } catch (PcepParseException e) { | ||
| 219 | + log.error("Failed to push global node label for LSR {}.", specificLsrId.toString()); | ||
| 220 | + } | ||
| 214 | 221 | ||
| 215 | // Configure (node-label, lsr-id) mapping of each devices into specific device and vice versa. | 222 | // Configure (node-label, lsr-id) mapping of each devices into specific device and vice versa. |
| 216 | for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { | 223 | for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { |
| 217 | DeviceId otherDevId = element.getKey(); | 224 | DeviceId otherDevId = element.getKey(); |
| 218 | - LabelResourceId otherLabelId = element.getValue(); | ||
| 219 | 225 | ||
| 220 | // Get lsr-id of a device | 226 | // Get lsr-id of a device |
| 221 | String otherLsrId = getLsrId(otherDevId); | 227 | String otherLsrId = getLsrId(otherDevId); |
| ... | @@ -228,16 +234,23 @@ public final class PceccSrTeBeHandler { | ... | @@ -228,16 +234,23 @@ public final class PceccSrTeBeHandler { |
| 228 | // Push to device | 234 | // Push to device |
| 229 | // Push label information of specificDeviceId to otherDevId in list and vice versa. | 235 | // Push label information of specificDeviceId to otherDevId in list and vice versa. |
| 230 | if (!otherDevId.equals(specificDeviceId)) { | 236 | if (!otherDevId.equals(specificDeviceId)) { |
| 231 | - advertiseNodeLabelRule(otherDevId, specificLabelId, | 237 | + try { |
| 232 | - IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), | 238 | + pushGlobalNodeLabel(getPcepClient(otherDevId), |
| 233 | - Objective.Operation.ADD, false); | 239 | + specificLabelId, |
| 234 | - | 240 | + IpAddress.valueOf(specificLsrId).getIp4Address().toInt(), |
| 235 | - advertiseNodeLabelRule(specificDeviceId, otherLabelId, | 241 | + PcepLabelOp.ADD, |
| 236 | - IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH), | 242 | + false); |
| 237 | - Objective.Operation.ADD, false); | 243 | + |
| 244 | + pushGlobalNodeLabel(pcc, specificLabelId, | ||
| 245 | + IpAddress.valueOf(otherLsrId).getIp4Address().toInt(), | ||
| 246 | + PcepLabelOp.ADD, | ||
| 247 | + false); | ||
| 248 | + } catch (PcepParseException e) { | ||
| 249 | + log.error("Failed to push global node label for LSR {} or LSR {}.", specificLsrId.toString(), | ||
| 250 | + otherLsrId.toString()); | ||
| 251 | + } | ||
| 238 | } | 252 | } |
| 239 | } | 253 | } |
| 240 | - | ||
| 241 | return true; | 254 | return true; |
| 242 | } | 255 | } |
| 243 | 256 | ||
| ... | @@ -271,9 +284,15 @@ public final class PceccSrTeBeHandler { | ... | @@ -271,9 +284,15 @@ public final class PceccSrTeBeHandler { |
| 271 | // Remove this specific device label information from all other nodes except | 284 | // Remove this specific device label information from all other nodes except |
| 272 | // this specific node where connection already lost. | 285 | // this specific node where connection already lost. |
| 273 | if (!specificDeviceId.equals(otherDevId)) { | 286 | if (!specificDeviceId.equals(otherDevId)) { |
| 274 | - advertiseNodeLabelRule(otherDevId, labelId, | 287 | + try { |
| 275 | - IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), | 288 | + pushGlobalNodeLabel(getPcepClient(otherDevId), |
| 276 | - Objective.Operation.REMOVE, false); | 289 | + labelId, |
| 290 | + IpAddress.valueOf(specificLsrId).getIp4Address().toInt(), | ||
| 291 | + PcepLabelOp.REMOVE, | ||
| 292 | + false); | ||
| 293 | + } catch (PcepParseException e) { | ||
| 294 | + log.error("Failed to push global node label for LSR {}.", specificLsrId.toString()); | ||
| 295 | + } | ||
| 277 | } | 296 | } |
| 278 | } | 297 | } |
| 279 | 298 | ||
| ... | @@ -290,7 +309,6 @@ public final class PceccSrTeBeHandler { | ... | @@ -290,7 +309,6 @@ public final class PceccSrTeBeHandler { |
| 290 | log.error("Unable to remove global node label id {} from store.", labelId.toString()); | 309 | log.error("Unable to remove global node label id {} from store.", labelId.toString()); |
| 291 | retValue = false; | 310 | retValue = false; |
| 292 | } | 311 | } |
| 293 | - | ||
| 294 | return retValue; | 312 | return retValue; |
| 295 | } | 313 | } |
| 296 | 314 | ||
| ... | @@ -335,7 +353,13 @@ public final class PceccSrTeBeHandler { | ... | @@ -335,7 +353,13 @@ public final class PceccSrTeBeHandler { |
| 335 | log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); | 353 | log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); |
| 336 | 354 | ||
| 337 | // Push adjacency label to device | 355 | // Push adjacency label to device |
| 338 | - installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); | 356 | + try { |
| 357 | + pushAdjacencyLabel(getPcepClient(srcDeviceId), labelId, (int) link.src().port().toLong(), | ||
| 358 | + (int) link.dst().port().toLong(), PcepLabelOp.ADD); | ||
| 359 | + } catch (PcepParseException e) { | ||
| 360 | + log.error("Failed to push adjacency label for link {}-{}.", (int) link.src().port().toLong(), | ||
| 361 | + (int) link.dst().port().toLong()); | ||
| 362 | + } | ||
| 339 | 363 | ||
| 340 | // Save in store | 364 | // Save in store |
| 341 | pceStore.addAdjLabel(link, labelId); | 365 | pceStore.addAdjLabel(link, labelId); |
| ... | @@ -365,7 +389,14 @@ public final class PceccSrTeBeHandler { | ... | @@ -365,7 +389,14 @@ public final class PceccSrTeBeHandler { |
| 365 | DeviceId srcDeviceId = link.src().deviceId(); | 389 | DeviceId srcDeviceId = link.src().deviceId(); |
| 366 | 390 | ||
| 367 | // Release adjacency label from device | 391 | // Release adjacency label from device |
| 368 | - installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.REMOVE); | 392 | + try { |
| 393 | + pushAdjacencyLabel(getPcepClient(srcDeviceId), labelId, (int) link.src().port().toLong(), | ||
| 394 | + (int) link.dst().port().toLong(), PcepLabelOp.REMOVE); | ||
| 395 | + } catch (PcepParseException e) { | ||
| 396 | + log.error("Failed to push adjacency label for link {}-{}.", (int) link.src().port().toLong(), | ||
| 397 | + (int) link.dst().port().toLong()); | ||
| 398 | + } | ||
| 399 | + | ||
| 369 | 400 | ||
| 370 | // Release link label from label manager | 401 | // Release link label from label manager |
| 371 | Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); | 402 | Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); |
| ... | @@ -429,98 +460,125 @@ public final class PceccSrTeBeHandler { | ... | @@ -429,98 +460,125 @@ public final class PceccSrTeBeHandler { |
| 429 | return new DefaultLabelStack(labelStack); | 460 | return new DefaultLabelStack(labelStack); |
| 430 | } | 461 | } |
| 431 | 462 | ||
| 432 | - /** | 463 | + //Pushes node labels to the specified device. |
| 433 | - * Install a rule for pushing unique global labels to the device. | 464 | + void pushGlobalNodeLabel(PcepClient pc, LabelResourceId labelId, |
| 434 | - * | 465 | + int labelForNode, PcepLabelOp type, boolean isBos) throws PcepParseException { |
| 435 | - * @param deviceId device to which flow should be pushed | ||
| 436 | - * @param labelId label for the device | ||
| 437 | - * @param type type of operation | ||
| 438 | - */ | ||
| 439 | - private void installNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, Objective.Operation type) { | ||
| 440 | - checkNotNull(flowObjectiveService); | ||
| 441 | - checkNotNull(appId); | ||
| 442 | - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
| 443 | 466 | ||
| 444 | - selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | 467 | + checkNotNull(pc); |
| 468 | + checkNotNull(labelId); | ||
| 469 | + checkNotNull(type); | ||
| 445 | 470 | ||
| 446 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 471 | + LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); |
| 472 | + PcepFecObjectIPv4 fecObject = pc.factory().buildFecObjectIpv4() | ||
| 473 | + .setNodeID(labelForNode) | ||
| 474 | + .build(); | ||
| 447 | 475 | ||
| 448 | - ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | 476 | + boolean bSFlag = false; |
| 449 | - .withSelector(selectorBuilder.build()).withTreatment(treatment) | 477 | + if (pc.labelDbSyncStatus() == IN_SYNC && !isBos) { |
| 450 | - .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent(); | 478 | + // Need to set sync flag in all messages till sync completes. |
| 479 | + bSFlag = true; | ||
| 480 | + } | ||
| 451 | 481 | ||
| 452 | - if (type.equals(Objective.Operation.ADD)) { | 482 | + PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag); |
| 453 | 483 | ||
| 454 | - flowObjectiveService.forward(deviceId, forwardingObjective.add()); | 484 | + //Global NODE-SID as label object |
| 455 | - } else { | 485 | + PcepLabelObject labelObject = pc.factory().buildLabelObject() |
| 456 | - flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | 486 | + .setLabel((int) labelId.labelId()) |
| 487 | + .build(); | ||
| 488 | + | ||
| 489 | + PcepLabelMap labelMap = new PcepLabelMap(); | ||
| 490 | + labelMap.setFecObject(fecObject); | ||
| 491 | + labelMap.setLabelObject(labelObject); | ||
| 492 | + labelMap.setSrpObject(srpObj); | ||
| 493 | + | ||
| 494 | + labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() | ||
| 495 | + .setLabelMap(labelMap) | ||
| 496 | + .build()); | ||
| 497 | + | ||
| 498 | + PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() | ||
| 499 | + .setPcLabelUpdateList(labelUpdateList) | ||
| 500 | + .build(); | ||
| 501 | + pc.sendMessage(labelMsg); | ||
| 502 | + | ||
| 503 | + if (isBos) { | ||
| 504 | + // Sync is completed. | ||
| 505 | + pc.setLabelDbSyncStatus(SYNCED); | ||
| 457 | } | 506 | } |
| 458 | } | 507 | } |
| 459 | 508 | ||
| 460 | - /** | 509 | + //Pushes adjacency labels to the specified device. |
| 461 | - * Install a rule for pushing node labels to the device of other nodes. | 510 | + void pushAdjacencyLabel(PcepClient pc, LabelResourceId labelId, int srcPortNo, |
| 462 | - * | 511 | + int dstPortNo, PcepLabelOp type) |
| 463 | - * @param deviceId device to which flow should be pushed | 512 | + throws PcepParseException { |
| 464 | - * @param labelId label for the device | 513 | + |
| 465 | - * @param ipPrefix device for which label is pushed | 514 | + checkNotNull(pc); |
| 466 | - * @param type type of operation | 515 | + checkNotNull(labelId); |
| 467 | - * @param bBos is this the end of sync push | 516 | + checkNotNull(type); |
| 468 | - */ | 517 | + |
| 469 | - public void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, IpPrefix ipPrefix, | 518 | + LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); |
| 470 | - Objective.Operation type, boolean bBos) { | 519 | + PcepFecObjectIPv4Adjacency fecAdjObject = pc.factory().buildFecIpv4Adjacency() |
| 471 | - checkNotNull(flowObjectiveService); | 520 | + .seRemoteIPv4Address(dstPortNo) |
| 472 | - checkNotNull(appId); | 521 | + .seLocalIPv4Address(srcPortNo) |
| 473 | - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | 522 | + .build(); |
| 523 | + | ||
| 524 | + boolean bSFlag = false; | ||
| 525 | + if (pc.labelDbSyncStatus() == IN_SYNC) { | ||
| 526 | + // Need to set sync flag in all messages till sync completes. | ||
| 527 | + bSFlag = true; | ||
| 528 | + } | ||
| 474 | 529 | ||
| 475 | - selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | 530 | + PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag); |
| 476 | - selectorBuilder.matchIPSrc(ipPrefix); | ||
| 477 | 531 | ||
| 478 | - if (bBos) { | 532 | + //Adjacency label object |
| 479 | - selectorBuilder.matchMplsBos(bBos); | 533 | + PcepLabelObject labelObject = pc.factory().buildLabelObject() |
| 480 | - } | 534 | + .setLabel((int) labelId.labelId()) |
| 535 | + .build(); | ||
| 481 | 536 | ||
| 482 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 537 | + PcepLabelMap labelMap = new PcepLabelMap(); |
| 538 | + labelMap.setFecObject(fecAdjObject); | ||
| 539 | + labelMap.setLabelObject(labelObject); | ||
| 540 | + labelMap.setSrpObject(srpObj); | ||
| 483 | 541 | ||
| 484 | - ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | 542 | + labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() |
| 485 | - .withSelector(selectorBuilder.build()).withTreatment(treatment) | 543 | + .setLabelMap(labelMap) |
| 486 | - .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent(); | 544 | + .build()); |
| 487 | 545 | ||
| 488 | - if (type.equals(Objective.Operation.ADD)) { | 546 | + PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() |
| 489 | - flowObjectiveService.forward(deviceId, forwardingObjective.add()); | 547 | + .setPcLabelUpdateList(labelUpdateList) |
| 490 | - } else { | 548 | + .build(); |
| 491 | - flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | 549 | + pc.sendMessage(labelMsg); |
| 550 | + } | ||
| 551 | + | ||
| 552 | + private PcepSrpObject getSrpObject(PcepClient pc, PcepLabelOp type, boolean bSFlag) | ||
| 553 | + throws PcepParseException { | ||
| 554 | + PcepSrpObject srpObj; | ||
| 555 | + boolean bRFlag = false; | ||
| 556 | + | ||
| 557 | + if (!type.equals(PcepLabelOp.ADD)) { | ||
| 558 | + // To cleanup labels, R bit is set | ||
| 559 | + bRFlag = true; | ||
| 492 | } | 560 | } |
| 561 | + | ||
| 562 | + srpObj = pc.factory().buildSrpObject() | ||
| 563 | + .setRFlag(bRFlag) | ||
| 564 | + .setSFlag(bSFlag) | ||
| 565 | + .setSrpID(SrpIdGenerators.create()) | ||
| 566 | + .build(); | ||
| 567 | + | ||
| 568 | + return srpObj; | ||
| 493 | } | 569 | } |
| 494 | 570 | ||
| 495 | /** | 571 | /** |
| 496 | - * Install a rule for pushing Adjacency labels to the device. | 572 | + * Returns PCEP client. |
| 497 | * | 573 | * |
| 498 | - * @param deviceId device to which flow should be pushed | 574 | + * @return PCEP client |
| 499 | - * @param labelId label for the adjacency | ||
| 500 | - * @param srcPortNum local port of the adjacency | ||
| 501 | - * @param dstPortNum remote port of the adjacency | ||
| 502 | - * @param type type of operation | ||
| 503 | */ | 575 | */ |
| 504 | - public void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, PortNumber srcPortNum, | 576 | + private PcepClient getPcepClient(DeviceId deviceId) { |
| 505 | - PortNumber dstPortNum, Objective.Operation type) { | 577 | + Device device = deviceService.getDevice(deviceId); |
| 506 | - checkNotNull(flowObjectiveService); | ||
| 507 | - checkNotNull(appId); | ||
| 508 | - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
| 509 | - | ||
| 510 | - selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); | ||
| 511 | - selectorBuilder.matchIPSrc(IpPrefix.valueOf((int) srcPortNum.toLong(), 32)); | ||
| 512 | - selectorBuilder.matchIPDst(IpPrefix.valueOf((int) dstPortNum.toLong(), 32)); | ||
| 513 | - | ||
| 514 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
| 515 | - | ||
| 516 | - ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() | ||
| 517 | - .withSelector(selectorBuilder.build()).withTreatment(treatment) | ||
| 518 | - .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent(); | ||
| 519 | 578 | ||
| 520 | - if (type.equals(Objective.Operation.ADD)) { | 579 | + // In future projections instead of annotations will be used to fetch LSR ID. |
| 521 | - flowObjectiveService.forward(deviceId, forwardingObjective.add()); | 580 | + String lsrId = device.annotations().value(LSR_ID); |
| 522 | - } else { | 581 | + PcepClient pcc = clientController.getClient(PccId.pccId(IpAddress.valueOf(lsrId))); |
| 523 | - flowObjectiveService.forward(deviceId, forwardingObjective.remove()); | 582 | + return pcc; |
| 524 | - } | ||
| 525 | } | 583 | } |
| 526 | } | 584 | } | ... | ... |
| ... | @@ -26,6 +26,7 @@ import java.util.List; | ... | @@ -26,6 +26,7 @@ import java.util.List; |
| 26 | import java.util.ListIterator; | 26 | import java.util.ListIterator; |
| 27 | import java.util.Map; | 27 | import java.util.Map; |
| 28 | import java.util.Set; | 28 | import java.util.Set; |
| 29 | +import java.util.Map.Entry; | ||
| 29 | import java.util.concurrent.ConcurrentHashMap; | 30 | import java.util.concurrent.ConcurrentHashMap; |
| 30 | 31 | ||
| 31 | import org.apache.felix.scr.annotations.Activate; | 32 | import org.apache.felix.scr.annotations.Activate; |
| ... | @@ -34,12 +35,40 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -34,12 +35,40 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 34 | import org.apache.felix.scr.annotations.Reference; | 35 | import org.apache.felix.scr.annotations.Reference; |
| 35 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 36 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 36 | import org.apache.felix.scr.annotations.Service; | 37 | import org.apache.felix.scr.annotations.Service; |
| 38 | +import org.onlab.packet.Ip4Address; | ||
| 39 | +import org.onlab.packet.IpAddress; | ||
| 40 | +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 41 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 42 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 43 | +import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | ||
| 44 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
| 37 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | 45 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 46 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 38 | import org.onosproject.incubator.net.tunnel.Tunnel; | 47 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 39 | import org.onosproject.incubator.net.tunnel.TunnelService; | 48 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 40 | import org.onosproject.incubator.net.tunnel.Tunnel.State; | 49 | import org.onosproject.incubator.net.tunnel.Tunnel.State; |
| 50 | +import org.onosproject.mastership.MastershipService; | ||
| 51 | +import org.onosproject.net.DefaultAnnotations; | ||
| 52 | +import org.onosproject.net.DefaultAnnotations.Builder; | ||
| 53 | +import org.onosproject.net.Device; | ||
| 54 | +import org.onosproject.net.DeviceId; | ||
| 55 | +import org.onosproject.net.Link; | ||
| 56 | +import org.onosproject.net.MastershipRole; | ||
| 57 | +import org.onosproject.net.Path; | ||
| 58 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
| 59 | +import org.onosproject.net.config.NetworkConfigListener; | ||
| 60 | +import org.onosproject.net.config.NetworkConfigService; | ||
| 61 | +import org.onosproject.net.device.DeviceEvent; | ||
| 62 | +import org.onosproject.net.device.DeviceListener; | ||
| 41 | import org.onosproject.net.device.DeviceService; | 63 | import org.onosproject.net.device.DeviceService; |
| 64 | +import org.onosproject.net.link.LinkEvent; | ||
| 65 | +import org.onosproject.net.link.LinkListener; | ||
| 66 | +import org.onosproject.net.link.LinkService; | ||
| 67 | +import org.onosproject.pcelabelstore.PcepLabelOp; | ||
| 68 | +import org.onosproject.pcelabelstore.api.PceLabelStore; | ||
| 69 | +import org.onosproject.pcep.api.DeviceCapability; | ||
| 42 | import org.onosproject.pcep.controller.LspKey; | 70 | import org.onosproject.pcep.controller.LspKey; |
| 71 | +import org.onosproject.pcep.controller.LspType; | ||
| 43 | import org.onosproject.pcep.controller.PccId; | 72 | import org.onosproject.pcep.controller.PccId; |
| 44 | import org.onosproject.pcep.controller.PcepClient; | 73 | import org.onosproject.pcep.controller.PcepClient; |
| 45 | import org.onosproject.pcep.controller.PcepClientController; | 74 | import org.onosproject.pcep.controller.PcepClientController; |
| ... | @@ -47,8 +76,6 @@ import org.onosproject.pcep.controller.PcepClientListener; | ... | @@ -47,8 +76,6 @@ import org.onosproject.pcep.controller.PcepClientListener; |
| 47 | import org.onosproject.pcep.controller.PcepEventListener; | 76 | import org.onosproject.pcep.controller.PcepEventListener; |
| 48 | import org.onosproject.pcep.controller.PcepLspStatus; | 77 | import org.onosproject.pcep.controller.PcepLspStatus; |
| 49 | import org.onosproject.pcep.controller.PcepNodeListener; | 78 | import org.onosproject.pcep.controller.PcepNodeListener; |
| 50 | -import org.onosproject.pcep.controller.PcepPacketListener; | ||
| 51 | -import org.onosproject.pcep.controller.PcepSyncStatus; | ||
| 52 | import org.onosproject.pcep.controller.SrpIdGenerators; | 79 | import org.onosproject.pcep.controller.SrpIdGenerators; |
| 53 | import org.onosproject.pcep.controller.driver.PcepAgent; | 80 | import org.onosproject.pcep.controller.driver.PcepAgent; |
| 54 | import org.onosproject.pcepio.exceptions.PcepParseException; | 81 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| ... | @@ -61,10 +88,15 @@ import org.onosproject.pcepio.protocol.PcepFactory; | ... | @@ -61,10 +88,15 @@ import org.onosproject.pcepio.protocol.PcepFactory; |
| 61 | import org.onosproject.pcepio.protocol.PcepInitiateMsg; | 88 | import org.onosproject.pcepio.protocol.PcepInitiateMsg; |
| 62 | import org.onosproject.pcepio.protocol.PcepLspObject; | 89 | import org.onosproject.pcepio.protocol.PcepLspObject; |
| 63 | import org.onosproject.pcepio.protocol.PcepMessage; | 90 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 91 | +import org.onosproject.pcepio.protocol.PcepNai; | ||
| 64 | import org.onosproject.pcepio.protocol.PcepReportMsg; | 92 | import org.onosproject.pcepio.protocol.PcepReportMsg; |
| 65 | import org.onosproject.pcepio.protocol.PcepSrpObject; | 93 | import org.onosproject.pcepio.protocol.PcepSrpObject; |
| 66 | import org.onosproject.pcepio.protocol.PcepStateReport; | 94 | import org.onosproject.pcepio.protocol.PcepStateReport; |
| 95 | +import org.onosproject.pcepio.types.PathSetupTypeTlv; | ||
| 96 | +import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency; | ||
| 97 | +import org.onosproject.pcepio.types.PcepNaiIpv4NodeId; | ||
| 67 | import org.onosproject.pcepio.types.PcepValueType; | 98 | import org.onosproject.pcepio.types.PcepValueType; |
| 99 | +import org.onosproject.pcepio.types.SrEroSubObject; | ||
| 68 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; | 100 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; |
| 69 | import org.onosproject.pcepio.types.SymbolicPathNameTlv; | 101 | import org.onosproject.pcepio.types.SymbolicPathNameTlv; |
| 70 | import org.slf4j.Logger; | 102 | import org.slf4j.Logger; |
| ... | @@ -74,11 +106,23 @@ import com.google.common.collect.Sets; | ... | @@ -74,11 +106,23 @@ import com.google.common.collect.Sets; |
| 74 | import static com.google.common.base.Preconditions.checkNotNull; | 106 | import static com.google.common.base.Preconditions.checkNotNull; |
| 75 | 107 | ||
| 76 | import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; | 108 | import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; |
| 109 | +import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; | ||
| 110 | +import static org.onosproject.pcep.controller.LspType.WITH_SIGNALLING; | ||
| 77 | import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE; | 111 | import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE; |
| 78 | import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE; | 112 | import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE; |
| 79 | import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE; | 113 | import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE; |
| 80 | import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19; | 114 | import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19; |
| 81 | import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5; | 115 | import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5; |
| 116 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH; | ||
| 117 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.LOCAL_LSP_ID; | ||
| 118 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE; | ||
| 119 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCC_TUNNEL_ID; | ||
| 120 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT; | ||
| 121 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.PLSP_ID; | ||
| 122 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE; | ||
| 123 | +import static org.onosproject.pcep.controller.PcepAnnotationKeys.COST_TYPE; | ||
| 124 | +import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; | ||
| 125 | +import static org.onosproject.pcep.controller.PcepSyncStatus.NOT_SYNCED; | ||
| 82 | 126 | ||
| 83 | /** | 127 | /** |
| 84 | * Implementation of PCEP client controller. | 128 | * Implementation of PCEP client controller. |
| ... | @@ -88,10 +132,33 @@ import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5; | ... | @@ -88,10 +132,33 @@ import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5; |
| 88 | public class PcepClientControllerImpl implements PcepClientController { | 132 | public class PcepClientControllerImpl implements PcepClientController { |
| 89 | 133 | ||
| 90 | private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class); | 134 | private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class); |
| 135 | + private static final long IDENTIFIER_SET = 0x100000000L; | ||
| 136 | + private static final long SET = 0xFFFFFFFFL; | ||
| 91 | 137 | ||
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected DeviceService deviceService; | 139 | protected DeviceService deviceService; |
| 94 | 140 | ||
| 141 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 142 | + protected LinkService linkService; | ||
| 143 | + | ||
| 144 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 145 | + protected TunnelService tunnelService; | ||
| 146 | + | ||
| 147 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 148 | + protected NetworkConfigService netCfgService; | ||
| 149 | + | ||
| 150 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 151 | + protected MastershipService mastershipService; | ||
| 152 | + | ||
| 153 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 154 | + protected LabelResourceAdminService labelRsrcAdminService; | ||
| 155 | + | ||
| 156 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 157 | + protected LabelResourceService labelRsrcService; | ||
| 158 | + | ||
| 159 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 160 | + protected PceLabelStore pceStore; | ||
| 161 | + | ||
| 95 | protected ConcurrentHashMap<PccId, PcepClient> connectedClients = | 162 | protected ConcurrentHashMap<PccId, PcepClient> connectedClients = |
| 96 | new ConcurrentHashMap<>(); | 163 | new ConcurrentHashMap<>(); |
| 97 | 164 | ||
| ... | @@ -100,25 +167,44 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -100,25 +167,44 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 100 | 167 | ||
| 101 | protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); | 168 | protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); |
| 102 | protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet(); | 169 | protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet(); |
| 103 | - protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet(); | 170 | + |
| 171 | + // LSR-id and device-id mapping for checking capability if L3 device is not | ||
| 172 | + // having its capability | ||
| 173 | + private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); | ||
| 104 | 174 | ||
| 105 | private final Controller ctrl = new Controller(); | 175 | private final Controller ctrl = new Controller(); |
| 176 | + public static final long GLOBAL_LABEL_SPACE_MIN = 4097; | ||
| 177 | + public static final long GLOBAL_LABEL_SPACE_MAX = 5121; | ||
| 178 | + private static final String LSRID = "lsrId"; | ||
| 179 | + private static final String DEVICE_NULL = "Device-cannot be null"; | ||
| 180 | + private static final String LINK_NULL = "Link-cannot be null"; | ||
| 106 | 181 | ||
| 107 | - public static final String BANDWIDTH = "bandwidth"; | 182 | + private BasicPceccHandler crHandler; |
| 108 | - public static final String LSP_SIG_TYPE = "lspSigType"; | 183 | + private PceccSrTeBeHandler srTeHandler; |
| 109 | - public static final String PCC_TUNNEL_ID = "PccTunnelId"; | ||
| 110 | - public static final String PLSP_ID = "PLspId"; | ||
| 111 | - public static final String LOCAL_LSP_ID = "localLspId"; | ||
| 112 | - public static final String PCE_INIT = "pceInit"; | ||
| 113 | - public static final String COST_TYPE = "costType"; | ||
| 114 | - public static final String DELEGATE = "delegation"; | ||
| 115 | 184 | ||
| 116 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 185 | + private DeviceListener deviceListener = new InternalDeviceListener(); |
| 117 | - protected TunnelService tunnelService; | 186 | + private LinkListener linkListener = new InternalLinkListener(); |
| 187 | + private InternalConfigListener cfgListener = new InternalConfigListener(); | ||
| 118 | 188 | ||
| 119 | @Activate | 189 | @Activate |
| 120 | public void activate() { | 190 | public void activate() { |
| 121 | ctrl.start(agent); | 191 | ctrl.start(agent); |
| 192 | + crHandler = BasicPceccHandler.getInstance(); | ||
| 193 | + crHandler.initialize(labelRsrcService, deviceService, pceStore, this); | ||
| 194 | + | ||
| 195 | + srTeHandler = PceccSrTeBeHandler.getInstance(); | ||
| 196 | + srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, this, pceStore, | ||
| 197 | + deviceService); | ||
| 198 | + | ||
| 199 | + deviceService.addListener(deviceListener); | ||
| 200 | + linkService.addListener(linkListener); | ||
| 201 | + netCfgService.addListener(cfgListener); | ||
| 202 | + | ||
| 203 | + // Reserve global node pool | ||
| 204 | + if (!srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX)) { | ||
| 205 | + log.debug("Global node pool was already reserved."); | ||
| 206 | + } | ||
| 207 | + | ||
| 122 | log.info("Started"); | 208 | log.info("Started"); |
| 123 | } | 209 | } |
| 124 | 210 | ||
| ... | @@ -126,6 +212,9 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -126,6 +212,9 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 126 | public void deactivate() { | 212 | public void deactivate() { |
| 127 | // Close all connected clients | 213 | // Close all connected clients |
| 128 | closeConnectedClients(); | 214 | closeConnectedClients(); |
| 215 | + deviceService.removeListener(deviceListener); | ||
| 216 | + linkService.removeListener(linkListener); | ||
| 217 | + netCfgService.removeListener(cfgListener); | ||
| 129 | ctrl.stop(); | 218 | ctrl.stop(); |
| 130 | log.info("Stopped"); | 219 | log.info("Stopped"); |
| 131 | } | 220 | } |
| ... | @@ -163,16 +252,6 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -163,16 +252,6 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 163 | } | 252 | } |
| 164 | 253 | ||
| 165 | @Override | 254 | @Override |
| 166 | - public void addPacketListener(PcepPacketListener listener) { | ||
| 167 | - pcepPacketListener.add(listener); | ||
| 168 | - } | ||
| 169 | - | ||
| 170 | - @Override | ||
| 171 | - public void removePacketListener(PcepPacketListener listener) { | ||
| 172 | - pcepPacketListener.remove(listener); | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - @Override | ||
| 176 | public void writeMessage(PccId pccId, PcepMessage msg) { | 255 | public void writeMessage(PccId pccId, PcepMessage msg) { |
| 177 | this.getClient(pccId).sendMessage(msg); | 256 | this.getClient(pccId).sendMessage(msg); |
| 178 | } | 257 | } |
| ... | @@ -239,10 +318,10 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -239,10 +318,10 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 239 | PcepStateReport stateRpt = listIterator.next(); | 318 | PcepStateReport stateRpt = listIterator.next(); |
| 240 | PcepLspObject lspObj = stateRpt.getLspObject(); | 319 | PcepLspObject lspObj = stateRpt.getLspObject(); |
| 241 | if (lspObj.getSFlag()) { | 320 | if (lspObj.getSFlag()) { |
| 242 | - if (pc.lspDbSyncStatus() != PcepSyncStatus.IN_SYNC) { | 321 | + if (pc.lspDbSyncStatus() != IN_SYNC) { |
| 243 | log.debug("LSP DB sync started for PCC {}", pc.getPccId().id().toString()); | 322 | log.debug("LSP DB sync started for PCC {}", pc.getPccId().id().toString()); |
| 244 | // Initialize LSP DB sync and temporary cache. | 323 | // Initialize LSP DB sync and temporary cache. |
| 245 | - pc.setLspDbSyncStatus(PcepSyncStatus.IN_SYNC); | 324 | + pc.setLspDbSyncStatus(IN_SYNC); |
| 246 | pc.initializeSyncMsgList(pccId); | 325 | pc.initializeSyncMsgList(pccId); |
| 247 | } | 326 | } |
| 248 | // Store stateRpt in temporary cache. | 327 | // Store stateRpt in temporary cache. |
| ... | @@ -251,18 +330,24 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -251,18 +330,24 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 251 | // Don't send to provider as of now. | 330 | // Don't send to provider as of now. |
| 252 | continue; | 331 | continue; |
| 253 | } else if (lspObj.getPlspId() == 0) { | 332 | } else if (lspObj.getPlspId() == 0) { |
| 254 | - if (pc.lspDbSyncStatus() == PcepSyncStatus.IN_SYNC | 333 | + if (pc.lspDbSyncStatus() == IN_SYNC |
| 255 | - || pc.lspDbSyncStatus() == PcepSyncStatus.NOT_SYNCED) { | 334 | + || pc.lspDbSyncStatus() == NOT_SYNCED) { |
| 256 | // Set end of LSPDB sync. | 335 | // Set end of LSPDB sync. |
| 257 | log.debug("LSP DB sync completed for PCC {}", pc.getPccId().id().toString()); | 336 | log.debug("LSP DB sync completed for PCC {}", pc.getPccId().id().toString()); |
| 258 | - pc.setLspDbSyncStatus(PcepSyncStatus.SYNCED); | 337 | + pc.setLspDbSyncStatus(SYNCED); |
| 259 | 338 | ||
| 260 | // Call packet provider to initiate label DB sync (only if PCECC capable). | 339 | // Call packet provider to initiate label DB sync (only if PCECC capable). |
| 261 | if (pc.capability().pceccCapability()) { | 340 | if (pc.capability().pceccCapability()) { |
| 262 | log.debug("Trigger label DB sync for PCC {}", pc.getPccId().id().toString()); | 341 | log.debug("Trigger label DB sync for PCC {}", pc.getPccId().id().toString()); |
| 263 | pc.setLabelDbSyncStatus(IN_SYNC); | 342 | pc.setLabelDbSyncStatus(IN_SYNC); |
| 264 | - for (PcepPacketListener l : pcepPacketListener) { | 343 | + // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID. |
| 265 | - l.sendPacketIn(pccId); | 344 | + String lsrId = String.valueOf(pccId.ipAddress()); |
| 345 | + DeviceId pccDeviceId = DeviceId.deviceId(lsrId); | ||
| 346 | + try { | ||
| 347 | + syncLabelDb(pccDeviceId); | ||
| 348 | + pc.setLabelDbSyncStatus(SYNCED); | ||
| 349 | + } catch (PcepParseException e) { | ||
| 350 | + log.error("Exception caught in sending label masg to PCC while in sync."); | ||
| 266 | } | 351 | } |
| 267 | } else { | 352 | } else { |
| 268 | // If label db sync is not to be done, handle end of LSPDB sync actions. | 353 | // If label db sync is not to be done, handle end of LSPDB sync actions. |
| ... | @@ -272,6 +357,27 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -272,6 +357,27 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 272 | } | 357 | } |
| 273 | } | 358 | } |
| 274 | 359 | ||
| 360 | + PcepLspStatus pcepLspStatus = PcepLspStatus.values()[lspObj.getOFlag()]; | ||
| 361 | + LspType lspType = getLspType(stateRpt.getSrpObject()); | ||
| 362 | + | ||
| 363 | + // Download (or remove) labels for basic PCECC LSPs. | ||
| 364 | + if (lspType.equals(WITHOUT_SIGNALLING_AND_WITHOUT_SR)) { | ||
| 365 | + boolean isRemove = lspObj.getRFlag(); | ||
| 366 | + Tunnel tunnel = null; | ||
| 367 | + | ||
| 368 | + if (isRemove || pcepLspStatus.equals(PcepLspStatus.GOING_UP)) { | ||
| 369 | + tunnel = getTunnel(lspObj); | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + if (tunnel != null) { | ||
| 373 | + if (isRemove) { | ||
| 374 | + crHandler.releaseLabel(tunnel); | ||
| 375 | + } else { | ||
| 376 | + crHandler.allocateLabel(tunnel); | ||
| 377 | + } | ||
| 378 | + } | ||
| 379 | + } | ||
| 380 | + | ||
| 275 | // It's a usual report message while sync is not undergoing. So process it immediately. | 381 | // It's a usual report message while sync is not undergoing. So process it immediately. |
| 276 | LinkedList<PcepStateReport> llPcRptList = new LinkedList<>(); | 382 | LinkedList<PcepStateReport> llPcRptList = new LinkedList<>(); |
| 277 | llPcRptList.add(stateRpt); | 383 | llPcRptList.add(stateRpt); |
| ... | @@ -300,6 +406,113 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -300,6 +406,113 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 300 | } | 406 | } |
| 301 | } | 407 | } |
| 302 | 408 | ||
| 409 | + private LspType getLspType(PcepSrpObject srpObj) { | ||
| 410 | + LspType lspType = WITH_SIGNALLING; | ||
| 411 | + | ||
| 412 | + if (null != srpObj) { | ||
| 413 | + LinkedList<PcepValueType> llOptionalTlv = srpObj.getOptionalTlv(); | ||
| 414 | + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); | ||
| 415 | + | ||
| 416 | + while (listIterator.hasNext()) { | ||
| 417 | + PcepValueType tlv = listIterator.next(); | ||
| 418 | + switch (tlv.getType()) { | ||
| 419 | + case PathSetupTypeTlv.TYPE: | ||
| 420 | + lspType = LspType.values()[Integer.valueOf(((PathSetupTypeTlv) tlv).getPst())]; | ||
| 421 | + break; | ||
| 422 | + default: | ||
| 423 | + break; | ||
| 424 | + } | ||
| 425 | + } | ||
| 426 | + } | ||
| 427 | + return lspType; | ||
| 428 | + } | ||
| 429 | + | ||
| 430 | + private Tunnel getTunnel(PcepLspObject lspObj) { | ||
| 431 | + ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator(); | ||
| 432 | + StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null; | ||
| 433 | + SymbolicPathNameTlv pathNameTlv = null; | ||
| 434 | + Tunnel tunnel = null; | ||
| 435 | + while (listTlvIterator.hasNext()) { | ||
| 436 | + PcepValueType tlv = listTlvIterator.next(); | ||
| 437 | + switch (tlv.getType()) { | ||
| 438 | + case StatefulIPv4LspIdentifiersTlv.TYPE: | ||
| 439 | + ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv; | ||
| 440 | + break; | ||
| 441 | + case SymbolicPathNameTlv.TYPE: | ||
| 442 | + pathNameTlv = (SymbolicPathNameTlv) tlv; | ||
| 443 | + break; | ||
| 444 | + default: | ||
| 445 | + break; | ||
| 446 | + } | ||
| 447 | + } | ||
| 448 | + /* | ||
| 449 | + * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for | ||
| 450 | + * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory. | ||
| 451 | + */ | ||
| 452 | + if (ipv4LspIdenTlv == null) { | ||
| 453 | + log.error("Stateful IPv4 identifier TLV is null in PCRpt msg."); | ||
| 454 | + return null; | ||
| 455 | + } | ||
| 456 | + IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint | ||
| 457 | + .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4IngressAddress())); | ||
| 458 | + IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint | ||
| 459 | + .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress())); | ||
| 460 | + Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst); | ||
| 461 | + | ||
| 462 | + for (Tunnel tunnelObj : tunnelQueryResult) { | ||
| 463 | + if (tunnelObj.annotations().value(PLSP_ID) == null) { | ||
| 464 | + /* | ||
| 465 | + * PLSP_ID is null while Tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by | ||
| 466 | + * PCC and in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic | ||
| 467 | + * path name must be carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be | ||
| 468 | + * included in the LSP object in the LSP State Report (PCRpt) message when during a given PCEP | ||
| 469 | + * session an LSP is "first" reported to a PCE. | ||
| 470 | + */ | ||
| 471 | + if ((pathNameTlv != null) | ||
| 472 | + && Arrays.equals(tunnelObj.tunnelName().value().getBytes(), pathNameTlv.getValue())) { | ||
| 473 | + tunnel = tunnelObj; | ||
| 474 | + break; | ||
| 475 | + } | ||
| 476 | + continue; | ||
| 477 | + } | ||
| 478 | + if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId())) { | ||
| 479 | + if ((Integer | ||
| 480 | + .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) { | ||
| 481 | + tunnel = tunnelObj; | ||
| 482 | + break; | ||
| 483 | + } | ||
| 484 | + } | ||
| 485 | + } | ||
| 486 | + | ||
| 487 | + if (tunnel == null || tunnel.annotations().value(PLSP_ID) != null) { | ||
| 488 | + return tunnel; | ||
| 489 | + } | ||
| 490 | + | ||
| 491 | + // The returned tunnel is used just for filling values in Label message. So manipulate locally | ||
| 492 | + // and return so that to allocate label, we don't need to wait for the tunnel in the "core" | ||
| 493 | + // to be updated, as that depends on listener mechanism and there may be timing/multi-threading issues. | ||
| 494 | + Builder annotationBuilder = DefaultAnnotations.builder(); | ||
| 495 | + annotationBuilder.set(BANDWIDTH, tunnel.annotations().value(BANDWIDTH)); | ||
| 496 | + annotationBuilder.set(COST_TYPE, tunnel.annotations().value(COST_TYPE)); | ||
| 497 | + annotationBuilder.set(LSP_SIG_TYPE, tunnel.annotations().value(LSP_SIG_TYPE)); | ||
| 498 | + annotationBuilder.set(PCE_INIT, tunnel.annotations().value(PCE_INIT)); | ||
| 499 | + annotationBuilder.set(DELEGATE, tunnel.annotations().value(DELEGATE)); | ||
| 500 | + annotationBuilder.set(PLSP_ID, String.valueOf(lspObj.getPlspId())); | ||
| 501 | + annotationBuilder.set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId())); | ||
| 502 | + annotationBuilder.set(LOCAL_LSP_ID, tunnel.annotations().value(LOCAL_LSP_ID)); | ||
| 503 | + | ||
| 504 | + Tunnel updatedTunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(), | ||
| 505 | + tunnel.dst(), tunnel.type(), | ||
| 506 | + tunnel.state(), tunnel.groupId(), | ||
| 507 | + tunnel.tunnelId(), | ||
| 508 | + tunnel.tunnelName(), | ||
| 509 | + tunnel.path(), | ||
| 510 | + tunnel.resource(), | ||
| 511 | + annotationBuilder.build()); | ||
| 512 | + | ||
| 513 | + return updatedTunnel; | ||
| 514 | + } | ||
| 515 | + | ||
| 303 | @Override | 516 | @Override |
| 304 | public void closeConnectedClients() { | 517 | public void closeConnectedClients() { |
| 305 | PcepClient pc; | 518 | PcepClient pc; |
| ... | @@ -337,6 +550,294 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -337,6 +550,294 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 337 | return errMsg; | 550 | return errMsg; |
| 338 | } | 551 | } |
| 339 | 552 | ||
| 553 | + private boolean syncLabelDb(DeviceId deviceId) throws PcepParseException { | ||
| 554 | + checkNotNull(deviceId); | ||
| 555 | + | ||
| 556 | + DeviceId actualDevcieId = pceStore.getLsrIdDevice(deviceId.toString()); | ||
| 557 | + if (actualDevcieId == null) { | ||
| 558 | + log.error("Device not available {}.", deviceId.toString()); | ||
| 559 | + pceStore.addPccLsr(deviceId); | ||
| 560 | + return false; | ||
| 561 | + } | ||
| 562 | + PcepClient pc = connectedClients.get(PccId.pccId(IpAddress.valueOf(deviceId.toString()))); | ||
| 563 | + | ||
| 564 | + Device specificDevice = deviceService.getDevice(actualDevcieId); | ||
| 565 | + if (specificDevice == null) { | ||
| 566 | + log.error("Unable to find device for specific device id {}.", actualDevcieId.toString()); | ||
| 567 | + return false; | ||
| 568 | + } | ||
| 569 | + | ||
| 570 | + if (pceStore.getGlobalNodeLabel(actualDevcieId) != null) { | ||
| 571 | + Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels(); | ||
| 572 | + | ||
| 573 | + for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) { | ||
| 574 | + | ||
| 575 | + // Convert from DeviceId to TunnelEndPoint | ||
| 576 | + Device srcDevice = deviceService.getDevice(entry.getKey()); | ||
| 577 | + | ||
| 578 | + /* | ||
| 579 | + * If there is a slight difference in timing such that if device subsystem has removed the device but | ||
| 580 | + * PCE store still has it, just ignore such devices. | ||
| 581 | + */ | ||
| 582 | + if (srcDevice == null) { | ||
| 583 | + continue; | ||
| 584 | + } | ||
| 585 | + | ||
| 586 | + String srcLsrId = srcDevice.annotations().value(LSRID); | ||
| 587 | + if (srcLsrId == null) { | ||
| 588 | + continue; | ||
| 589 | + } | ||
| 590 | + | ||
| 591 | + srTeHandler.pushGlobalNodeLabel(pc, entry.getValue(), | ||
| 592 | + IpAddress.valueOf(srcLsrId).getIp4Address().toInt(), | ||
| 593 | + PcepLabelOp.ADD, false); | ||
| 594 | + } | ||
| 595 | + | ||
| 596 | + Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels(); | ||
| 597 | + for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) { | ||
| 598 | + if (entry.getKey().src().deviceId().equals(actualDevcieId)) { | ||
| 599 | + srTeHandler.pushAdjacencyLabel(pc, | ||
| 600 | + entry.getValue(), | ||
| 601 | + (int) entry.getKey().src().port().toLong(), | ||
| 602 | + (int) entry.getKey().dst().port().toLong(), | ||
| 603 | + PcepLabelOp.ADD | ||
| 604 | + ); | ||
| 605 | + } | ||
| 606 | + } | ||
| 607 | + } | ||
| 608 | + | ||
| 609 | + srTeHandler.pushGlobalNodeLabel(pc, LabelResourceId.labelResourceId(0), | ||
| 610 | + 0, PcepLabelOp.ADD, true); | ||
| 611 | + | ||
| 612 | + log.debug("End of label DB sync for device {}", actualDevcieId); | ||
| 613 | + | ||
| 614 | + if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) { | ||
| 615 | + // Allocate node-label to this specific device. | ||
| 616 | + allocateNodeLabel(specificDevice); | ||
| 617 | + | ||
| 618 | + // Allocate adjacency label | ||
| 619 | + Set<Link> links = linkService.getDeviceEgressLinks(specificDevice.id()); | ||
| 620 | + if (links != null) { | ||
| 621 | + for (Link link : links) { | ||
| 622 | + allocateAdjacencyLabel(link); | ||
| 623 | + } | ||
| 624 | + } | ||
| 625 | + } | ||
| 626 | + return true; | ||
| 627 | + } | ||
| 628 | + | ||
| 629 | + /** | ||
| 630 | + * Allocates node label to specific device. | ||
| 631 | + * | ||
| 632 | + * @param specificDevice device to which node label needs to be allocated | ||
| 633 | + */ | ||
| 634 | + public void allocateNodeLabel(Device specificDevice) { | ||
| 635 | + checkNotNull(specificDevice, DEVICE_NULL); | ||
| 636 | + | ||
| 637 | + DeviceId deviceId = specificDevice.id(); | ||
| 638 | + | ||
| 639 | + // Retrieve lsrId of a specific device | ||
| 640 | + if (specificDevice.annotations() == null) { | ||
| 641 | + log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 642 | + return; | ||
| 643 | + } | ||
| 644 | + | ||
| 645 | + String lsrId = specificDevice.annotations().value(LSRID); | ||
| 646 | + if (lsrId == null) { | ||
| 647 | + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 648 | + return; | ||
| 649 | + } | ||
| 650 | + | ||
| 651 | + // Get capability config from netconfig | ||
| 652 | + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 653 | + if (cfg == null) { | ||
| 654 | + log.error("Unable to find corresponding capability for a lsrd {} from NetConfig.", lsrId); | ||
| 655 | + // Save info. When PCEP session is comes up then allocate node-label | ||
| 656 | + lsrIdDeviceIdMap.put(lsrId, specificDevice.id()); | ||
| 657 | + return; | ||
| 658 | + } | ||
| 659 | + | ||
| 660 | + // Check whether device has SR-TE Capability | ||
| 661 | + if (cfg.labelStackCap()) { | ||
| 662 | + srTeHandler.allocateNodeLabel(deviceId, lsrId); | ||
| 663 | + } | ||
| 664 | + } | ||
| 665 | + | ||
| 666 | + /** | ||
| 667 | + * Releases node label of a specific device. | ||
| 668 | + * | ||
| 669 | + * @param specificDevice this device label and lsr-id information will be | ||
| 670 | + * released in other existing devices | ||
| 671 | + */ | ||
| 672 | + public void releaseNodeLabel(Device specificDevice) { | ||
| 673 | + checkNotNull(specificDevice, DEVICE_NULL); | ||
| 674 | + | ||
| 675 | + DeviceId deviceId = specificDevice.id(); | ||
| 676 | + | ||
| 677 | + // Retrieve lsrId of a specific device | ||
| 678 | + if (specificDevice.annotations() == null) { | ||
| 679 | + log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 680 | + return; | ||
| 681 | + } | ||
| 682 | + | ||
| 683 | + String lsrId = specificDevice.annotations().value(LSRID); | ||
| 684 | + if (lsrId == null) { | ||
| 685 | + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 686 | + return; | ||
| 687 | + } | ||
| 688 | + | ||
| 689 | + // Get capability config from netconfig | ||
| 690 | + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 691 | + if (cfg == null) { | ||
| 692 | + log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId); | ||
| 693 | + return; | ||
| 694 | + } | ||
| 695 | + | ||
| 696 | + // Check whether device has SR-TE Capability | ||
| 697 | + if (cfg.labelStackCap()) { | ||
| 698 | + if (!srTeHandler.releaseNodeLabel(deviceId, lsrId)) { | ||
| 699 | + log.error("Unable to release node label for a device id {}.", deviceId.toString()); | ||
| 700 | + } | ||
| 701 | + } | ||
| 702 | + } | ||
| 703 | + | ||
| 704 | + /** | ||
| 705 | + * Allocates adjacency label for a link. | ||
| 706 | + * | ||
| 707 | + * @param link link | ||
| 708 | + */ | ||
| 709 | + public void allocateAdjacencyLabel(Link link) { | ||
| 710 | + checkNotNull(link, LINK_NULL); | ||
| 711 | + | ||
| 712 | + Device specificDevice = deviceService.getDevice(link.src().deviceId()); | ||
| 713 | + | ||
| 714 | + // Retrieve lsrId of a specific device | ||
| 715 | + if (specificDevice.annotations() == null) { | ||
| 716 | + log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 717 | + return; | ||
| 718 | + } | ||
| 719 | + | ||
| 720 | + String lsrId = specificDevice.annotations().value(LSRID); | ||
| 721 | + if (lsrId == null) { | ||
| 722 | + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 723 | + return; | ||
| 724 | + } | ||
| 725 | + | ||
| 726 | + // Get capability config from netconfig | ||
| 727 | + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 728 | + if (cfg == null) { | ||
| 729 | + log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId); | ||
| 730 | + // Save info. When PCEP session comes up then allocate adjacency | ||
| 731 | + // label | ||
| 732 | + if (lsrIdDeviceIdMap.get(lsrId) != null) { | ||
| 733 | + lsrIdDeviceIdMap.put(lsrId, specificDevice.id()); | ||
| 734 | + } | ||
| 735 | + return; | ||
| 736 | + } | ||
| 737 | + | ||
| 738 | + // Check whether device has SR-TE Capability | ||
| 739 | + if (cfg.labelStackCap()) { | ||
| 740 | + srTeHandler.allocateAdjacencyLabel(link); | ||
| 741 | + } | ||
| 742 | + } | ||
| 743 | + | ||
| 744 | + /** | ||
| 745 | + * Releases allocated adjacency label of a link. | ||
| 746 | + * | ||
| 747 | + * @param link link | ||
| 748 | + */ | ||
| 749 | + public void releaseAdjacencyLabel(Link link) { | ||
| 750 | + checkNotNull(link, LINK_NULL); | ||
| 751 | + | ||
| 752 | + Device specificDevice = deviceService.getDevice(link.src().deviceId()); | ||
| 753 | + | ||
| 754 | + // Retrieve lsrId of a specific device | ||
| 755 | + if (specificDevice.annotations() == null) { | ||
| 756 | + log.debug("Device {} does not have annotations.", specificDevice.toString()); | ||
| 757 | + return; | ||
| 758 | + } | ||
| 759 | + | ||
| 760 | + String lsrId = specificDevice.annotations().value(LSRID); | ||
| 761 | + if (lsrId == null) { | ||
| 762 | + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString()); | ||
| 763 | + return; | ||
| 764 | + } | ||
| 765 | + | ||
| 766 | + // Get capability config from netconfig | ||
| 767 | + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 768 | + if (cfg == null) { | ||
| 769 | + log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId); | ||
| 770 | + return; | ||
| 771 | + } | ||
| 772 | + | ||
| 773 | + // Check whether device has SR-TE Capability | ||
| 774 | + if (cfg.labelStackCap()) { | ||
| 775 | + if (!srTeHandler.releaseAdjacencyLabel(link)) { | ||
| 776 | + log.error("Unable to release adjacency labels for a link {}.", link.toString()); | ||
| 777 | + } | ||
| 778 | + } | ||
| 779 | + } | ||
| 780 | + | ||
| 781 | + @Override | ||
| 782 | + public LabelStack computeLabelStack(Path path) { | ||
| 783 | + return srTeHandler.computeLabelStack(path); | ||
| 784 | + } | ||
| 785 | + | ||
| 786 | + @Override | ||
| 787 | + public boolean allocateLocalLabel(Tunnel tunnel) { | ||
| 788 | + return crHandler.allocateLabel(tunnel); | ||
| 789 | + } | ||
| 790 | + | ||
| 791 | + /** | ||
| 792 | + * Creates label stack for ERO object from network resource. | ||
| 793 | + * | ||
| 794 | + * @param labelStack | ||
| 795 | + * @param path (hop list) | ||
| 796 | + * @return list of ERO subobjects | ||
| 797 | + */ | ||
| 798 | + @Override | ||
| 799 | + public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) { | ||
| 800 | + checkNotNull(labelStack); | ||
| 801 | + | ||
| 802 | + LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); | ||
| 803 | + Iterator<Link> links = path.links().iterator(); | ||
| 804 | + LabelResourceId label = null; | ||
| 805 | + Link link = null; | ||
| 806 | + PcepValueType subObj = null; | ||
| 807 | + PcepNai nai = null; | ||
| 808 | + Device dstNode = null; | ||
| 809 | + long srcPortNo, dstPortNo; | ||
| 810 | + | ||
| 811 | + ListIterator<LabelResourceId> labelListIterator = labelStack.labelResources().listIterator(); | ||
| 812 | + while (labelListIterator.hasNext()) { | ||
| 813 | + label = labelListIterator.next(); | ||
| 814 | + link = links.next(); | ||
| 815 | + | ||
| 816 | + srcPortNo = link.src().port().toLong(); | ||
| 817 | + srcPortNo = ((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? srcPortNo & SET : srcPortNo; | ||
| 818 | + | ||
| 819 | + dstPortNo = link.dst().port().toLong(); | ||
| 820 | + dstPortNo = ((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? dstPortNo & SET : dstPortNo; | ||
| 821 | + | ||
| 822 | + nai = new PcepNaiIpv4Adjacency((int) srcPortNo, (int) dstPortNo); | ||
| 823 | + subObj = new SrEroSubObject(PcepNaiIpv4Adjacency.ST_TYPE, false, false, false, true, (int) label.labelId(), | ||
| 824 | + nai); | ||
| 825 | + llSubObjects.add(subObj); | ||
| 826 | + | ||
| 827 | + dstNode = deviceService.getDevice(link.dst().deviceId()); | ||
| 828 | + nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt()); | ||
| 829 | + | ||
| 830 | + if (!labelListIterator.hasNext()) { | ||
| 831 | + log.error("Malformed label stack."); | ||
| 832 | + } | ||
| 833 | + label = labelListIterator.next(); | ||
| 834 | + subObj = new SrEroSubObject(PcepNaiIpv4NodeId.ST_TYPE, false, false, false, true, (int) label.labelId(), | ||
| 835 | + nai); | ||
| 836 | + llSubObjects.add(subObj); | ||
| 837 | + } | ||
| 838 | + return llSubObjects; | ||
| 839 | + } | ||
| 840 | + | ||
| 340 | /** | 841 | /** |
| 341 | * Implementation of an Pcep Agent which is responsible for | 842 | * Implementation of an Pcep Agent which is responsible for |
| 342 | * keeping track of connected clients and the state in which | 843 | * keeping track of connected clients and the state in which |
| ... | @@ -370,7 +871,6 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -370,7 +871,6 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 370 | + "connected client: pccIp {}. Aborting ..", pccId.toString()); | 871 | + "connected client: pccIp {}. Aborting ..", pccId.toString()); |
| 371 | return false; | 872 | return false; |
| 372 | } | 873 | } |
| 373 | - | ||
| 374 | return true; | 874 | return true; |
| 375 | } | 875 | } |
| 376 | 876 | ||
| ... | @@ -479,7 +979,7 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -479,7 +979,7 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 479 | } else if (pathNameTlv != null) { | 979 | } else if (pathNameTlv != null) { |
| 480 | tunnel = preSyncLspDbByName.get(Arrays.toString(pathNameTlv.getValue())); | 980 | tunnel = preSyncLspDbByName.get(Arrays.toString(pathNameTlv.getValue())); |
| 481 | if (tunnel != null) { | 981 | if (tunnel != null) { |
| 482 | - preSyncLspDbByName.remove(tunnel.tunnelName()); | 982 | + preSyncLspDbByName.remove(tunnel.tunnelName().value()); |
| 483 | } | 983 | } |
| 484 | } | 984 | } |
| 485 | 985 | ||
| ... | @@ -566,4 +1066,130 @@ public class PcepClientControllerImpl implements PcepClientController { | ... | @@ -566,4 +1066,130 @@ public class PcepClientControllerImpl implements PcepClientController { |
| 566 | } | 1066 | } |
| 567 | } | 1067 | } |
| 568 | } | 1068 | } |
| 1069 | + | ||
| 1070 | + /* | ||
| 1071 | + * Handle device events. | ||
| 1072 | + */ | ||
| 1073 | + private class InternalDeviceListener implements DeviceListener { | ||
| 1074 | + @Override | ||
| 1075 | + public void event(DeviceEvent event) { | ||
| 1076 | + Device specificDevice = event.subject(); | ||
| 1077 | + if (specificDevice == null) { | ||
| 1078 | + log.error("Unable to find device from device event."); | ||
| 1079 | + return; | ||
| 1080 | + } | ||
| 1081 | + | ||
| 1082 | + switch (event.type()) { | ||
| 1083 | + | ||
| 1084 | + case DEVICE_ADDED: | ||
| 1085 | + // Node-label allocation is being done during Label DB Sync. | ||
| 1086 | + // So, when device is detected, no need to do node-label | ||
| 1087 | + // allocation. | ||
| 1088 | + String lsrId = specificDevice.annotations().value(LSRID); | ||
| 1089 | + if (lsrId != null) { | ||
| 1090 | + pceStore.addLsrIdDevice(lsrId, specificDevice.id()); | ||
| 1091 | + | ||
| 1092 | + // Search in failed DB sync store. If found, trigger label DB sync. | ||
| 1093 | + DeviceId pccDeviceId = DeviceId.deviceId(lsrId); | ||
| 1094 | + if (pceStore.hasPccLsr(pccDeviceId)) { | ||
| 1095 | + log.debug("Continue to perform label DB sync for device {}.", pccDeviceId.toString()); | ||
| 1096 | + try { | ||
| 1097 | + syncLabelDb(pccDeviceId); | ||
| 1098 | + } catch (PcepParseException e) { | ||
| 1099 | + log.error("Exception caught in sending label masg to PCC while in sync."); | ||
| 1100 | + } | ||
| 1101 | + pceStore.removePccLsr(pccDeviceId); | ||
| 1102 | + } | ||
| 1103 | + } | ||
| 1104 | + break; | ||
| 1105 | + | ||
| 1106 | + case DEVICE_REMOVED: | ||
| 1107 | + // Release node-label | ||
| 1108 | + if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) { | ||
| 1109 | + releaseNodeLabel(specificDevice); | ||
| 1110 | + } | ||
| 1111 | + | ||
| 1112 | + if (specificDevice.annotations().value(LSRID) != null) { | ||
| 1113 | + pceStore.removeLsrIdDevice(specificDevice.annotations().value(LSRID)); | ||
| 1114 | + } | ||
| 1115 | + break; | ||
| 1116 | + | ||
| 1117 | + default: | ||
| 1118 | + break; | ||
| 1119 | + } | ||
| 1120 | + } | ||
| 1121 | + } | ||
| 1122 | + | ||
| 1123 | + /* | ||
| 1124 | + * Handle link events. | ||
| 1125 | + */ | ||
| 1126 | + private class InternalLinkListener implements LinkListener { | ||
| 1127 | + @Override | ||
| 1128 | + public void event(LinkEvent event) { | ||
| 1129 | + Link link = event.subject(); | ||
| 1130 | + | ||
| 1131 | + switch (event.type()) { | ||
| 1132 | + | ||
| 1133 | + case LINK_ADDED: | ||
| 1134 | + // Allocate adjacency label | ||
| 1135 | + if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) { | ||
| 1136 | + allocateAdjacencyLabel(link); | ||
| 1137 | + } | ||
| 1138 | + break; | ||
| 1139 | + | ||
| 1140 | + case LINK_REMOVED: | ||
| 1141 | + // Release adjacency label | ||
| 1142 | + if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) { | ||
| 1143 | + releaseAdjacencyLabel(link); | ||
| 1144 | + } | ||
| 1145 | + break; | ||
| 1146 | + | ||
| 1147 | + default: | ||
| 1148 | + break; | ||
| 1149 | + } | ||
| 1150 | + } | ||
| 1151 | + } | ||
| 1152 | + | ||
| 1153 | + private class InternalConfigListener implements NetworkConfigListener { | ||
| 1154 | + | ||
| 1155 | + @Override | ||
| 1156 | + public void event(NetworkConfigEvent event) { | ||
| 1157 | + | ||
| 1158 | + if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) | ||
| 1159 | + && event.configClass().equals(DeviceCapability.class)) { | ||
| 1160 | + | ||
| 1161 | + DeviceId deviceIdLsrId = (DeviceId) event.subject(); | ||
| 1162 | + String lsrId = deviceIdLsrId.toString(); | ||
| 1163 | + DeviceId deviceId = lsrIdDeviceIdMap.get(lsrId); | ||
| 1164 | + if (deviceId == null) { | ||
| 1165 | + log.debug("Unable to find device id for a lsr-id {} from lsr-id and device-id map.", lsrId); | ||
| 1166 | + return; | ||
| 1167 | + } | ||
| 1168 | + | ||
| 1169 | + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class); | ||
| 1170 | + if (cfg == null) { | ||
| 1171 | + log.error("Unable to find corresponding capabilty for a lsrd {}.", lsrId); | ||
| 1172 | + return; | ||
| 1173 | + } | ||
| 1174 | + | ||
| 1175 | + if (cfg.labelStackCap()) { | ||
| 1176 | + if (mastershipService.getLocalRole(deviceId) == MastershipRole.MASTER) { | ||
| 1177 | + // Allocate node-label | ||
| 1178 | + srTeHandler.allocateNodeLabel(deviceId, lsrId); | ||
| 1179 | + | ||
| 1180 | + // Allocate adjacency label to links which are | ||
| 1181 | + // originated from this specific device id | ||
| 1182 | + Set<Link> links = linkService.getDeviceEgressLinks(deviceId); | ||
| 1183 | + for (Link link : links) { | ||
| 1184 | + if (!srTeHandler.allocateAdjacencyLabel(link)) { | ||
| 1185 | + return; | ||
| 1186 | + } | ||
| 1187 | + } | ||
| 1188 | + } | ||
| 1189 | + } | ||
| 1190 | + // Remove lsrId info from map | ||
| 1191 | + lsrIdDeviceIdMap.remove(lsrId); | ||
| 1192 | + } | ||
| 1193 | + } | ||
| 1194 | + } | ||
| 569 | } | 1195 | } | ... | ... |
| ... | @@ -111,13 +111,13 @@ public class PcepControllerImpl implements PcepController { | ... | @@ -111,13 +111,13 @@ public class PcepControllerImpl implements PcepController { |
| 111 | @Override | 111 | @Override |
| 112 | public Boolean deleteTunnel(String id) { | 112 | public Boolean deleteTunnel(String id) { |
| 113 | // TODO Auto-generated method stub | 113 | // TODO Auto-generated method stub |
| 114 | - return null; | 114 | + return false; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | @Override | 117 | @Override |
| 118 | public Boolean updateTunnelBandwidth(String id, long bandwidth) { | 118 | public Boolean updateTunnelBandwidth(String id, long bandwidth) { |
| 119 | // TODO Auto-generated method stub | 119 | // TODO Auto-generated method stub |
| 120 | - return null; | 120 | + return false; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | @Override | 123 | @Override | ... | ... |
| ... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.pcestore; | 16 | +package org.onosproject.pcelabelstore; |
| 17 | 17 | ||
| 18 | import static org.hamcrest.MatcherAssert.assertThat; | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; | 19 | import static org.hamcrest.Matchers.is; |
| ... | @@ -24,7 +24,7 @@ import org.junit.Test; | ... | @@ -24,7 +24,7 @@ import org.junit.Test; |
| 24 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 24 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 25 | import org.onosproject.net.DeviceId; | 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.PortNumber; | 26 | import org.onosproject.net.PortNumber; |
| 27 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | 27 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; |
| 28 | 28 | ||
| 29 | /** | 29 | /** |
| 30 | * Unit tests for DefaultLspLocalLabelInfo class. | 30 | * Unit tests for DefaultLspLocalLabelInfo class. | ... | ... |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/DistributedPceLabelStoreTest.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.pcelabelstore; | ||
| 17 | + | ||
| 18 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 19 | +import static org.hamcrest.Matchers.is; | ||
| 20 | +import static org.hamcrest.Matchers.notNullValue; | ||
| 21 | + | ||
| 22 | +import java.util.LinkedList; | ||
| 23 | +import java.util.List; | ||
| 24 | +import java.util.Map; | ||
| 25 | + | ||
| 26 | +import org.junit.After; | ||
| 27 | +import org.junit.AfterClass; | ||
| 28 | +import org.junit.Before; | ||
| 29 | +import org.junit.BeforeClass; | ||
| 30 | +import org.junit.Test; | ||
| 31 | + | ||
| 32 | +import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 33 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 34 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 35 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 36 | +import org.onosproject.net.ConnectPoint; | ||
| 37 | +import org.onosproject.net.DefaultAnnotations; | ||
| 38 | +import org.onosproject.net.DefaultLink; | ||
| 39 | +import org.onosproject.net.DeviceId; | ||
| 40 | +import org.onosproject.net.Link; | ||
| 41 | +import org.onosproject.net.PortNumber; | ||
| 42 | +import org.onosproject.net.provider.ProviderId; | ||
| 43 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; | ||
| 44 | +import org.onosproject.pcelabelstore.util.TestStorageService; | ||
| 45 | + | ||
| 46 | +/** | ||
| 47 | + * Unit tests for DistributedPceStore class. | ||
| 48 | + */ | ||
| 49 | +public class DistributedPceLabelStoreTest { | ||
| 50 | + | ||
| 51 | + private DistributedPceLabelStore distrPceStore; | ||
| 52 | + private DeviceId deviceId1 = DeviceId.deviceId("foo"); | ||
| 53 | + private DeviceId deviceId2 = DeviceId.deviceId("goo"); | ||
| 54 | + private DeviceId deviceId3 = DeviceId.deviceId("yaa"); | ||
| 55 | + private DeviceId deviceId4 = DeviceId.deviceId("zoo"); | ||
| 56 | + private LabelResourceId labelId1 = LabelResourceId.labelResourceId(1); | ||
| 57 | + private LabelResourceId labelId2 = LabelResourceId.labelResourceId(2); | ||
| 58 | + private LabelResourceId labelId3 = LabelResourceId.labelResourceId(3); | ||
| 59 | + private LabelResourceId labelId4 = LabelResourceId.labelResourceId(4); | ||
| 60 | + private PortNumber portNumber1 = PortNumber.portNumber(1); | ||
| 61 | + private PortNumber portNumber2 = PortNumber.portNumber(2); | ||
| 62 | + private PortNumber portNumber3 = PortNumber.portNumber(3); | ||
| 63 | + private PortNumber portNumber4 = PortNumber.portNumber(4); | ||
| 64 | + private ConnectPoint srcConnectionPoint1 = new ConnectPoint(deviceId1, portNumber1); | ||
| 65 | + private ConnectPoint dstConnectionPoint2 = new ConnectPoint(deviceId2, portNumber2); | ||
| 66 | + private ConnectPoint srcConnectionPoint3 = new ConnectPoint(deviceId3, portNumber3); | ||
| 67 | + private ConnectPoint dstConnectionPoint4 = new ConnectPoint(deviceId4, portNumber4); | ||
| 68 | + private LabelResource labelResource1 = new DefaultLabelResource(deviceId1, labelId1); | ||
| 69 | + private LabelResource labelResource2 = new DefaultLabelResource(deviceId2, labelId2); | ||
| 70 | + private LabelResource labelResource3 = new DefaultLabelResource(deviceId3, labelId3); | ||
| 71 | + private LabelResource labelResource4 = new DefaultLabelResource(deviceId4, labelId4); | ||
| 72 | + private Link link1; | ||
| 73 | + private Link link2; | ||
| 74 | + private List<LabelResource> labelList1 = new LinkedList<>(); | ||
| 75 | + private List<LabelResource> labelList2 = new LinkedList<>(); | ||
| 76 | + private TunnelId tunnelId1 = TunnelId.valueOf("1"); | ||
| 77 | + private TunnelId tunnelId2 = TunnelId.valueOf("2"); | ||
| 78 | + private TunnelId tunnelId3 = TunnelId.valueOf("3"); | ||
| 79 | + private TunnelId tunnelId4 = TunnelId.valueOf("4"); | ||
| 80 | + | ||
| 81 | + List<LspLocalLabelInfo> lspLocalLabelInfoList1 = new LinkedList<>(); | ||
| 82 | + List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>(); | ||
| 83 | + | ||
| 84 | + @BeforeClass | ||
| 85 | + public static void setUpBeforeClass() throws Exception { | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @AfterClass | ||
| 89 | + public static void tearDownAfterClass() throws Exception { | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Before | ||
| 93 | + public void setUp() throws Exception { | ||
| 94 | + distrPceStore = new DistributedPceLabelStore(); | ||
| 95 | + // initialization | ||
| 96 | + distrPceStore.storageService = new TestStorageService(); | ||
| 97 | + distrPceStore.activate(); | ||
| 98 | + | ||
| 99 | + // Initialization of member variables | ||
| 100 | + link1 = DefaultLink.builder() | ||
| 101 | + .providerId(new ProviderId("eth", "1")) | ||
| 102 | + .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) | ||
| 103 | + .src(srcConnectionPoint1) | ||
| 104 | + .dst(dstConnectionPoint2) | ||
| 105 | + .type(Link.Type.DIRECT) | ||
| 106 | + .state(Link.State.ACTIVE) | ||
| 107 | + .build(); | ||
| 108 | + link2 = DefaultLink.builder() | ||
| 109 | + .providerId(new ProviderId("mac", "2")) | ||
| 110 | + .annotations(DefaultAnnotations.builder().set("key2", "google").build()) | ||
| 111 | + .src(srcConnectionPoint3) | ||
| 112 | + .dst(dstConnectionPoint4) | ||
| 113 | + .type(Link.Type.DIRECT) | ||
| 114 | + .state(Link.State.ACTIVE) | ||
| 115 | + .build(); | ||
| 116 | + labelList1.add(labelResource1); | ||
| 117 | + labelList1.add(labelResource2); | ||
| 118 | + labelList2.add(labelResource3); | ||
| 119 | + labelList2.add(labelResource4); | ||
| 120 | + | ||
| 121 | + // Create pceccTunnelInfo1 | ||
| 122 | + DeviceId deviceId1 = DeviceId.deviceId("foo"); | ||
| 123 | + LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1); | ||
| 124 | + LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2); | ||
| 125 | + | ||
| 126 | + LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder() | ||
| 127 | + .deviceId(deviceId1) | ||
| 128 | + .inLabelId(inLabelId1) | ||
| 129 | + .outLabelId(outLabelId1) | ||
| 130 | + .build(); | ||
| 131 | + lspLocalLabelInfoList1.add(lspLocalLabel1); | ||
| 132 | + distrPceStore.addTunnelInfo(tunnelId1, lspLocalLabelInfoList1); | ||
| 133 | + | ||
| 134 | + // Create pceccTunnelInfo2 | ||
| 135 | + DeviceId deviceId2 = DeviceId.deviceId("foo"); | ||
| 136 | + LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3); | ||
| 137 | + LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4); | ||
| 138 | + | ||
| 139 | + LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder() | ||
| 140 | + .deviceId(deviceId2) | ||
| 141 | + .inLabelId(inLabelId2) | ||
| 142 | + .outLabelId(outLabelId2) | ||
| 143 | + .build(); | ||
| 144 | + lspLocalLabelInfoList2.add(lspLocalLabel2); | ||
| 145 | + distrPceStore.addTunnelInfo(tunnelId2, lspLocalLabelInfoList2); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @After | ||
| 149 | + public void tearDown() throws Exception { | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * Checks the operation of addGlobalNodeLabel() method. | ||
| 154 | + */ | ||
| 155 | + @Test | ||
| 156 | + public void testAddGlobalNodeLabel() { | ||
| 157 | + // add device with label | ||
| 158 | + distrPceStore.addGlobalNodeLabel(deviceId1, labelId1); | ||
| 159 | + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true)); | ||
| 160 | + assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1)); | ||
| 161 | + distrPceStore.addGlobalNodeLabel(deviceId2, labelId2); | ||
| 162 | + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true)); | ||
| 163 | + assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2)); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * Checks the operation of addAdjLabel() method. | ||
| 168 | + */ | ||
| 169 | + @Test | ||
| 170 | + public void testAddAdjLabel() { | ||
| 171 | + // link with list of labels | ||
| 172 | + distrPceStore.addAdjLabel(link1, labelId1); | ||
| 173 | + assertThat(distrPceStore.existsAdjLabel(link1), is(true)); | ||
| 174 | + assertThat(distrPceStore.getAdjLabel(link1), is(labelId1)); | ||
| 175 | + distrPceStore.addAdjLabel(link2, labelId2); | ||
| 176 | + assertThat(distrPceStore.existsAdjLabel(link2), is(true)); | ||
| 177 | + assertThat(distrPceStore.getAdjLabel(link2), is(labelId2)); | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + /** | ||
| 181 | + * Checks the operation of addTunnelInfo() method. | ||
| 182 | + */ | ||
| 183 | + @Test | ||
| 184 | + public void testAddTunnelInfo() { | ||
| 185 | + // TunnelId with device label store information | ||
| 186 | + distrPceStore.addTunnelInfo(tunnelId1, lspLocalLabelInfoList1); | ||
| 187 | + assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); | ||
| 188 | + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(lspLocalLabelInfoList1)); | ||
| 189 | + distrPceStore.addTunnelInfo(tunnelId2, lspLocalLabelInfoList2); | ||
| 190 | + assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); | ||
| 191 | + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(lspLocalLabelInfoList2)); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * Checks the operation of existsGlobalNodeLabel() method. | ||
| 196 | + */ | ||
| 197 | + @Test | ||
| 198 | + public void testExistsGlobalNodeLabel() { | ||
| 199 | + testAddGlobalNodeLabel(); | ||
| 200 | + | ||
| 201 | + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true)); | ||
| 202 | + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true)); | ||
| 203 | + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId3), is(false)); | ||
| 204 | + assertThat(distrPceStore.existsGlobalNodeLabel(deviceId4), is(false)); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * Checks the operation of existsAdjLabel() method. | ||
| 209 | + */ | ||
| 210 | + @Test | ||
| 211 | + public void testExistsAdjLabel() { | ||
| 212 | + testAddAdjLabel(); | ||
| 213 | + | ||
| 214 | + assertThat(distrPceStore.existsAdjLabel(link1), is(true)); | ||
| 215 | + assertThat(distrPceStore.existsAdjLabel(link2), is(true)); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + /** | ||
| 219 | + * Checks the operation of existsTunnelInfo() method. | ||
| 220 | + */ | ||
| 221 | + @Test | ||
| 222 | + public void testExistsTunnelInfo() { | ||
| 223 | + testAddTunnelInfo(); | ||
| 224 | + | ||
| 225 | + assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); | ||
| 226 | + assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); | ||
| 227 | + assertThat(distrPceStore.existsTunnelInfo(tunnelId3), is(false)); | ||
| 228 | + assertThat(distrPceStore.existsTunnelInfo(tunnelId4), is(false)); | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + /** | ||
| 232 | + * Checks the operation of getGlobalNodeLabelCount() method. | ||
| 233 | + */ | ||
| 234 | + @Test | ||
| 235 | + public void testGetGlobalNodeLabelCount() { | ||
| 236 | + testAddGlobalNodeLabel(); | ||
| 237 | + | ||
| 238 | + assertThat(distrPceStore.getGlobalNodeLabelCount(), is(2)); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + /** | ||
| 242 | + * Checks the operation of getAdjLabelCount() method. | ||
| 243 | + */ | ||
| 244 | + @Test | ||
| 245 | + public void testGetAdjLabelCount() { | ||
| 246 | + testAddAdjLabel(); | ||
| 247 | + | ||
| 248 | + assertThat(distrPceStore.getAdjLabelCount(), is(2)); | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * Checks the operation of getTunnelInfoCount() method. | ||
| 253 | + */ | ||
| 254 | + @Test | ||
| 255 | + public void testGetTunnelInfoCount() { | ||
| 256 | + testAddTunnelInfo(); | ||
| 257 | + | ||
| 258 | + assertThat(distrPceStore.getTunnelInfoCount(), is(2)); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + /** | ||
| 262 | + * Checks the operation of getGlobalNodeLabels() method. | ||
| 263 | + */ | ||
| 264 | + @Test | ||
| 265 | + public void testGetGlobalNodeLabels() { | ||
| 266 | + testAddGlobalNodeLabel(); | ||
| 267 | + | ||
| 268 | + Map<DeviceId, LabelResourceId> nodeLabelMap = distrPceStore.getGlobalNodeLabels(); | ||
| 269 | + assertThat(nodeLabelMap, is(notNullValue())); | ||
| 270 | + assertThat(nodeLabelMap.isEmpty(), is(false)); | ||
| 271 | + assertThat(nodeLabelMap.size(), is(2)); | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + /** | ||
| 275 | + * Checks the operation of getAdjLabels() method. | ||
| 276 | + */ | ||
| 277 | + @Test | ||
| 278 | + public void testGetAdjLabels() { | ||
| 279 | + testAddAdjLabel(); | ||
| 280 | + | ||
| 281 | + Map<Link, LabelResourceId> adjLabelMap = distrPceStore.getAdjLabels(); | ||
| 282 | + assertThat(adjLabelMap, is(notNullValue())); | ||
| 283 | + assertThat(adjLabelMap.isEmpty(), is(false)); | ||
| 284 | + assertThat(adjLabelMap.size(), is(2)); | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + /** | ||
| 288 | + * Checks the operation of getTunnelInfos() method. | ||
| 289 | + */ | ||
| 290 | + @Test | ||
| 291 | + public void testGetTunnelInfos() { | ||
| 292 | + testAddTunnelInfo(); | ||
| 293 | + | ||
| 294 | + Map<TunnelId, List<LspLocalLabelInfo>> tunnelInfoMap = distrPceStore.getTunnelInfos(); | ||
| 295 | + assertThat(tunnelInfoMap, is(notNullValue())); | ||
| 296 | + assertThat(tunnelInfoMap.isEmpty(), is(false)); | ||
| 297 | + assertThat(tunnelInfoMap.size(), is(2)); | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + /** | ||
| 301 | + * Checks the operation of getGlobalNodeLabel() method. | ||
| 302 | + */ | ||
| 303 | + @Test | ||
| 304 | + public void testGetGlobalNodeLabel() { | ||
| 305 | + testAddGlobalNodeLabel(); | ||
| 306 | + | ||
| 307 | + // deviceId1 with labelId1 | ||
| 308 | + assertThat(deviceId1, is(notNullValue())); | ||
| 309 | + assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1)); | ||
| 310 | + | ||
| 311 | + // deviceId2 with labelId2 | ||
| 312 | + assertThat(deviceId2, is(notNullValue())); | ||
| 313 | + assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2)); | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + /** | ||
| 317 | + * Checks the operation of getAdjLabel() method. | ||
| 318 | + */ | ||
| 319 | + @Test | ||
| 320 | + public void testGetAdjLabel() { | ||
| 321 | + testAddAdjLabel(); | ||
| 322 | + | ||
| 323 | + // link1 with labels | ||
| 324 | + assertThat(link1, is(notNullValue())); | ||
| 325 | + assertThat(distrPceStore.getAdjLabel(link1), is(labelId1)); | ||
| 326 | + | ||
| 327 | + // link2 with labels | ||
| 328 | + assertThat(link2, is(notNullValue())); | ||
| 329 | + assertThat(distrPceStore.getAdjLabel(link2), is(labelId2)); | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + /** | ||
| 333 | + * Checks the operation of getTunnelInfo() method. | ||
| 334 | + */ | ||
| 335 | + @Test | ||
| 336 | + public void testGetTunnelInfo() { | ||
| 337 | + testAddTunnelInfo(); | ||
| 338 | + | ||
| 339 | + // tunnelId1 with device label store info | ||
| 340 | + assertThat(tunnelId1, is(notNullValue())); | ||
| 341 | + assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(lspLocalLabelInfoList1)); | ||
| 342 | + | ||
| 343 | + // tunnelId2 with device label store info | ||
| 344 | + assertThat(tunnelId2, is(notNullValue())); | ||
| 345 | + assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(lspLocalLabelInfoList2)); | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + /** | ||
| 349 | + * Checks the operation of removeGlobalNodeLabel() method. | ||
| 350 | + */ | ||
| 351 | + @Test | ||
| 352 | + public void testRemoveGlobalNodeLabel() { | ||
| 353 | + testAddGlobalNodeLabel(); | ||
| 354 | + | ||
| 355 | + assertThat(distrPceStore.removeGlobalNodeLabel(deviceId1), is(true)); | ||
| 356 | + assertThat(distrPceStore.removeGlobalNodeLabel(deviceId2), is(true)); | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + /** | ||
| 360 | + * Checks the operation of removeAdjLabel() method. | ||
| 361 | + */ | ||
| 362 | + @Test | ||
| 363 | + public void testRemoveAdjLabel() { | ||
| 364 | + testAddAdjLabel(); | ||
| 365 | + | ||
| 366 | + assertThat(distrPceStore.removeAdjLabel(link1), is(true)); | ||
| 367 | + assertThat(distrPceStore.removeAdjLabel(link2), is(true)); | ||
| 368 | + } | ||
| 369 | + | ||
| 370 | + /** | ||
| 371 | + * Checks the operation of removeTunnelInfo() method. | ||
| 372 | + */ | ||
| 373 | + @Test | ||
| 374 | + public void testRemoveTunnelInfo() { | ||
| 375 | + testAddTunnelInfo(); | ||
| 376 | + | ||
| 377 | + assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true)); | ||
| 378 | + assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true)); | ||
| 379 | + } | ||
| 380 | +} |
| ... | @@ -13,14 +13,13 @@ | ... | @@ -13,14 +13,13 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.pceservice; | 16 | +package org.onosproject.pcelabelstore.label; |
| 17 | 17 | ||
| 18 | import static org.hamcrest.MatcherAssert.assertThat; | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; | 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; | 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | import static org.hamcrest.Matchers.nullValue; | 21 | import static org.hamcrest.Matchers.nullValue; |
| 22 | import static org.onosproject.net.Link.Type.DIRECT; | 22 | import static org.onosproject.net.Link.Type.DIRECT; |
| 23 | - | ||
| 24 | import java.util.Iterator; | 23 | import java.util.Iterator; |
| 25 | import java.util.List; | 24 | import java.util.List; |
| 26 | import java.util.LinkedList; | 25 | import java.util.LinkedList; |
| ... | @@ -29,8 +28,6 @@ import org.junit.After; | ... | @@ -29,8 +28,6 @@ import org.junit.After; |
| 29 | import org.junit.Before; | 28 | import org.junit.Before; |
| 30 | import org.junit.Test; | 29 | import org.junit.Test; |
| 31 | import org.onlab.packet.IpAddress; | 30 | import org.onlab.packet.IpAddress; |
| 32 | -import org.onosproject.core.ApplicationId; | ||
| 33 | -import org.onosproject.core.CoreService; | ||
| 34 | import org.onosproject.core.DefaultGroupId; | 31 | import org.onosproject.core.DefaultGroupId; |
| 35 | import org.onosproject.incubator.net.tunnel.Tunnel; | 32 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | 33 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
| ... | @@ -40,19 +37,24 @@ import org.onosproject.incubator.net.tunnel.TunnelId; | ... | @@ -40,19 +37,24 @@ import org.onosproject.incubator.net.tunnel.TunnelId; |
| 40 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; | 37 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 41 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 38 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 42 | import org.onosproject.incubator.net.resource.label.LabelResourceService; | 39 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
| 40 | +import org.onosproject.net.AnnotationKeys; | ||
| 41 | +import org.onosproject.net.Annotations; | ||
| 43 | import org.onosproject.net.ConnectPoint; | 42 | import org.onosproject.net.ConnectPoint; |
| 44 | import org.onosproject.net.DefaultAnnotations; | 43 | import org.onosproject.net.DefaultAnnotations; |
| 44 | +import org.onosproject.net.DefaultDevice; | ||
| 45 | import org.onosproject.net.DefaultPath; | 45 | import org.onosproject.net.DefaultPath; |
| 46 | +import org.onosproject.net.Device; | ||
| 46 | import org.onosproject.net.DeviceId; | 47 | import org.onosproject.net.DeviceId; |
| 47 | import org.onosproject.net.PortNumber; | 48 | import org.onosproject.net.PortNumber; |
| 48 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 49 | import org.onosproject.net.Path; | 49 | import org.onosproject.net.Path; |
| 50 | -import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 51 | -import org.onosproject.pce.pcestore.api.PceStore; | ||
| 52 | -import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 53 | import org.onosproject.net.provider.ProviderId; | 50 | import org.onosproject.net.provider.ProviderId; |
| 54 | -import org.onosproject.pce.util.LabelResourceAdapter; | 51 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; |
| 55 | -import org.onosproject.pce.util.PceStoreAdapter; | 52 | +import org.onosproject.pcelabelstore.api.PceLabelStore; |
| 53 | +import org.onosproject.pcelabelstore.util.LabelResourceAdapter; | ||
| 54 | +import org.onosproject.pcelabelstore.util.MockDeviceService; | ||
| 55 | +import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter; | ||
| 56 | +import org.onosproject.pcep.controller.impl.BasicPceccHandler; | ||
| 57 | +import org.onosproject.pcep.controller.impl.PcepClientControllerImpl; | ||
| 56 | import org.onosproject.net.DefaultLink; | 58 | import org.onosproject.net.DefaultLink; |
| 57 | import org.onosproject.net.Link; | 59 | import org.onosproject.net.Link; |
| 58 | 60 | ||
| ... | @@ -63,13 +65,13 @@ public class BasicPceccHandlerTest { | ... | @@ -63,13 +65,13 @@ public class BasicPceccHandlerTest { |
| 63 | 65 | ||
| 64 | public static final long LOCAL_LABEL_SPACE_MIN = 5122; | 66 | public static final long LOCAL_LABEL_SPACE_MIN = 5122; |
| 65 | public static final long LOCAL_LABEL_SPACE_MAX = 9217; | 67 | public static final long LOCAL_LABEL_SPACE_MAX = 9217; |
| 68 | + private static final String L3 = "L3"; | ||
| 69 | + private static final String LSRID = "lsrId"; | ||
| 66 | 70 | ||
| 67 | private BasicPceccHandler pceccHandler; | 71 | private BasicPceccHandler pceccHandler; |
| 68 | protected LabelResourceService labelRsrcService; | 72 | protected LabelResourceService labelRsrcService; |
| 69 | - protected PceStore pceStore; | 73 | + protected MockDeviceService deviceService; |
| 70 | - private FlowObjectiveService flowObjectiveService; | 74 | + protected PceLabelStore pceStore; |
| 71 | - private CoreService coreService; | ||
| 72 | - private ApplicationId appId; | ||
| 73 | private TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423)); | 75 | private TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423)); |
| 74 | private TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); | 76 | private TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); |
| 75 | private DefaultGroupId groupId = new DefaultGroupId(92034); | 77 | private DefaultGroupId groupId = new DefaultGroupId(92034); |
| ... | @@ -78,7 +80,8 @@ public class BasicPceccHandlerTest { | ... | @@ -78,7 +80,8 @@ public class BasicPceccHandlerTest { |
| 78 | private ProviderId producerName = new ProviderId("producer1", "13"); | 80 | private ProviderId producerName = new ProviderId("producer1", "13"); |
| 79 | private Path path; | 81 | private Path path; |
| 80 | private Tunnel tunnel; | 82 | private Tunnel tunnel; |
| 81 | - private PceccTunnelInfo pceccTunnelInfo; | 83 | + List<LspLocalLabelInfo> lspLocalLabelInfoList; |
| 84 | + private Device deviceD1, deviceD2, deviceD3, deviceD4, deviceD5; | ||
| 82 | private DeviceId deviceId1; | 85 | private DeviceId deviceId1; |
| 83 | private DeviceId deviceId2; | 86 | private DeviceId deviceId2; |
| 84 | private DeviceId deviceId3; | 87 | private DeviceId deviceId3; |
| ... | @@ -94,13 +97,14 @@ public class BasicPceccHandlerTest { | ... | @@ -94,13 +97,14 @@ public class BasicPceccHandlerTest { |
| 94 | public void setUp() throws Exception { | 97 | public void setUp() throws Exception { |
| 95 | pceccHandler = BasicPceccHandler.getInstance(); | 98 | pceccHandler = BasicPceccHandler.getInstance(); |
| 96 | labelRsrcService = new LabelResourceAdapter(); | 99 | labelRsrcService = new LabelResourceAdapter(); |
| 97 | - pceStore = new PceStoreAdapter(); | 100 | + pceStore = new PceLabelStoreAdapter(); |
| 98 | - flowObjectiveService = new PceManagerTest.MockFlowObjService(); | 101 | + deviceService = new MockDeviceService(); |
| 99 | - coreService = new PceManagerTest.MockCoreService(); | 102 | + pceccHandler.initialize(labelRsrcService, |
| 100 | - appId = coreService.registerApplication("org.onosproject.pce"); | 103 | + deviceService, |
| 101 | - pceccHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore); | 104 | + pceStore, |
| 105 | + new PcepClientControllerImpl()); | ||
| 102 | 106 | ||
| 103 | - // Cretae tunnel test | 107 | + // Create tunnel test |
| 104 | // Link | 108 | // Link |
| 105 | ProviderId providerId = new ProviderId("of", "foo"); | 109 | ProviderId providerId = new ProviderId("of", "foo"); |
| 106 | deviceId1 = DeviceId.deviceId("of:A"); | 110 | deviceId1 = DeviceId.deviceId("of:A"); |
| ... | @@ -115,6 +119,41 @@ public class BasicPceccHandlerTest { | ... | @@ -115,6 +119,41 @@ public class BasicPceccHandlerTest { |
| 115 | port5 = PortNumber.portNumber(5); | 119 | port5 = PortNumber.portNumber(5); |
| 116 | List<Link> linkList = new LinkedList<>(); | 120 | List<Link> linkList = new LinkedList<>(); |
| 117 | 121 | ||
| 122 | + // Making L3 devices | ||
| 123 | + DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); | ||
| 124 | + builderDev1.set(AnnotationKeys.TYPE, L3); | ||
| 125 | + builderDev1.set(LSRID, "1.1.1.1"); | ||
| 126 | + deviceD1 = new MockDevice(deviceId1, builderDev1.build()); | ||
| 127 | + deviceService.addDevice(deviceD1); | ||
| 128 | + | ||
| 129 | + // Making L3 devices | ||
| 130 | + DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); | ||
| 131 | + builderDev2.set(AnnotationKeys.TYPE, L3); | ||
| 132 | + builderDev2.set(LSRID, "2.2.2.2"); | ||
| 133 | + deviceD2 = new MockDevice(deviceId2, builderDev2.build()); | ||
| 134 | + deviceService.addDevice(deviceD2); | ||
| 135 | + | ||
| 136 | + // Making L3 devices | ||
| 137 | + DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder(); | ||
| 138 | + builderDev3.set(AnnotationKeys.TYPE, L3); | ||
| 139 | + builderDev3.set(LSRID, "3.3.3.3"); | ||
| 140 | + deviceD3 = new MockDevice(deviceId3, builderDev3.build()); | ||
| 141 | + deviceService.addDevice(deviceD3); | ||
| 142 | + | ||
| 143 | + // Making L3 devices | ||
| 144 | + DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder(); | ||
| 145 | + builderDev4.set(AnnotationKeys.TYPE, L3); | ||
| 146 | + builderDev4.set(LSRID, "4.4.4.4"); | ||
| 147 | + deviceD4 = new MockDevice(deviceId4, builderDev4.build()); | ||
| 148 | + deviceService.addDevice(deviceD4); | ||
| 149 | + | ||
| 150 | + // Making L3 devices | ||
| 151 | + DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); | ||
| 152 | + builderDev5.set(AnnotationKeys.TYPE, L3); | ||
| 153 | + builderDev5.set(LSRID, "5.5.5.5"); | ||
| 154 | + deviceD5 = new MockDevice(deviceId5, builderDev5.build()); | ||
| 155 | + deviceService.addDevice(deviceD5); | ||
| 156 | + | ||
| 118 | Link l1 = DefaultLink.builder() | 157 | Link l1 = DefaultLink.builder() |
| 119 | .providerId(providerId) | 158 | .providerId(providerId) |
| 120 | .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) | 159 | .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) |
| ... | @@ -163,7 +202,6 @@ public class BasicPceccHandlerTest { | ... | @@ -163,7 +202,6 @@ public class BasicPceccHandlerTest { |
| 163 | 202 | ||
| 164 | @After | 203 | @After |
| 165 | public void tearDown() throws Exception { | 204 | public void tearDown() throws Exception { |
| 166 | - PceManagerTest.flowsDownloaded = 0; | ||
| 167 | } | 205 | } |
| 168 | 206 | ||
| 169 | /** | 207 | /** |
| ... | @@ -179,7 +217,6 @@ public class BasicPceccHandlerTest { | ... | @@ -179,7 +217,6 @@ public class BasicPceccHandlerTest { |
| 179 | */ | 217 | */ |
| 180 | @Test | 218 | @Test |
| 181 | public void testAllocateLabel() { | 219 | public void testAllocateLabel() { |
| 182 | - List<LspLocalLabelInfo> lspLocalLabelInfoList; | ||
| 183 | Iterator<LspLocalLabelInfo> iterator; | 220 | Iterator<LspLocalLabelInfo> iterator; |
| 184 | LspLocalLabelInfo lspLocalLabelInfo; | 221 | LspLocalLabelInfo lspLocalLabelInfo; |
| 185 | DeviceId deviceId; | 222 | DeviceId deviceId; |
| ... | @@ -192,8 +229,7 @@ public class BasicPceccHandlerTest { | ... | @@ -192,8 +229,7 @@ public class BasicPceccHandlerTest { |
| 192 | assertThat(pceccHandler.allocateLabel(tunnel), is(true)); | 229 | assertThat(pceccHandler.allocateLabel(tunnel), is(true)); |
| 193 | 230 | ||
| 194 | // Check list of devices with IN and OUT labels whether stored properly in store | 231 | // Check list of devices with IN and OUT labels whether stored properly in store |
| 195 | - pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | 232 | + lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId()); |
| 196 | - lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 197 | iterator = lspLocalLabelInfoList.iterator(); | 233 | iterator = lspLocalLabelInfoList.iterator(); |
| 198 | 234 | ||
| 199 | // Retrieve values and check device5 | 235 | // Retrieve values and check device5 |
| ... | @@ -281,7 +317,13 @@ public class BasicPceccHandlerTest { | ... | @@ -281,7 +317,13 @@ public class BasicPceccHandlerTest { |
| 281 | pceccHandler.releaseLabel(tunnel); | 317 | pceccHandler.releaseLabel(tunnel); |
| 282 | 318 | ||
| 283 | // Retrieve from store. Store should not contain this tunnel info. | 319 | // Retrieve from store. Store should not contain this tunnel info. |
| 284 | - pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | 320 | + lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId()); |
| 285 | - assertThat(pceccTunnelInfo, is(nullValue())); | 321 | + assertThat(lspLocalLabelInfoList, is(nullValue())); |
| 322 | + } | ||
| 323 | + | ||
| 324 | + private class MockDevice extends DefaultDevice { | ||
| 325 | + MockDevice(DeviceId id, Annotations annotations) { | ||
| 326 | + super(null, id, null, null, null, null, null, null, annotations); | ||
| 327 | + } | ||
| 286 | } | 328 | } |
| 287 | } | 329 | } | ... | ... |
| ... | @@ -13,19 +13,13 @@ | ... | @@ -13,19 +13,13 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.pceservice; | 16 | +package org.onosproject.pcelabelstore.label; |
| 17 | 17 | ||
| 18 | import static org.hamcrest.MatcherAssert.assertThat; | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; | 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; | 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | import static org.hamcrest.Matchers.nullValue; | 21 | import static org.hamcrest.Matchers.nullValue; |
| 22 | import static org.onosproject.net.Link.Type.DIRECT; | 22 | import static org.onosproject.net.Link.Type.DIRECT; |
| 23 | -import static org.onosproject.pce.pceservice.PathComputationTest.D1; | ||
| 24 | -import static org.onosproject.pce.pceservice.PathComputationTest.D2; | ||
| 25 | -import static org.onosproject.pce.pceservice.PathComputationTest.D3; | ||
| 26 | -import static org.onosproject.pce.pceservice.PathComputationTest.D4; | ||
| 27 | -import static org.onosproject.pce.pceservice.PathComputationTest.D5; | ||
| 28 | - | ||
| 29 | import java.util.Iterator; | 23 | import java.util.Iterator; |
| 30 | import java.util.List; | 24 | import java.util.List; |
| 31 | import java.util.LinkedList; | 25 | import java.util.LinkedList; |
| ... | @@ -33,9 +27,8 @@ import java.util.LinkedList; | ... | @@ -33,9 +27,8 @@ import java.util.LinkedList; |
| 33 | import org.junit.After; | 27 | import org.junit.After; |
| 34 | import org.junit.Before; | 28 | import org.junit.Before; |
| 35 | import org.junit.Test; | 29 | import org.junit.Test; |
| 30 | +import org.onlab.packet.IpAddress; | ||
| 36 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 31 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 37 | -import org.onosproject.core.ApplicationId; | ||
| 38 | -import org.onosproject.core.CoreService; | ||
| 39 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | 32 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; |
| 40 | import org.onosproject.incubator.net.resource.label.LabelResourceService; | 33 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
| 41 | import org.onosproject.incubator.net.tunnel.LabelStack; | 34 | import org.onosproject.incubator.net.tunnel.LabelStack; |
| ... | @@ -48,15 +41,19 @@ import org.onosproject.net.DefaultPath; | ... | @@ -48,15 +41,19 @@ import org.onosproject.net.DefaultPath; |
| 48 | import org.onosproject.net.Device; | 41 | import org.onosproject.net.Device; |
| 49 | import org.onosproject.net.DeviceId; | 42 | import org.onosproject.net.DeviceId; |
| 50 | import org.onosproject.net.PortNumber; | 43 | import org.onosproject.net.PortNumber; |
| 51 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 52 | import org.onosproject.net.Path; | 44 | import org.onosproject.net.Path; |
| 53 | -import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter; | ||
| 54 | -import org.onosproject.pce.pcestore.api.PceStore; | ||
| 55 | import org.onosproject.net.provider.ProviderId; | 45 | import org.onosproject.net.provider.ProviderId; |
| 56 | -import org.onosproject.pce.util.LabelResourceAdapter; | 46 | +import org.onosproject.pcelabelstore.api.PceLabelStore; |
| 57 | -import org.onosproject.pce.util.PceStoreAdapter; | 47 | +import org.onosproject.pcelabelstore.util.LabelResourceAdapter; |
| 58 | -import org.onosproject.pce.util.MockDeviceService; | 48 | +import org.onosproject.pcelabelstore.util.MockDeviceService; |
| 49 | +import org.onosproject.pcelabelstore.util.MockNetConfigRegistryAdapter; | ||
| 50 | +import org.onosproject.pcelabelstore.util.MockPcepClientController; | ||
| 51 | +import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter; | ||
| 52 | +import org.onosproject.pcelabelstore.util.PcepClientAdapter; | ||
| 59 | import org.onosproject.pcep.api.DeviceCapability; | 53 | import org.onosproject.pcep.api.DeviceCapability; |
| 54 | +import org.onosproject.pcep.controller.PccId; | ||
| 55 | +import org.onosproject.pcep.controller.impl.PceccSrTeBeHandler; | ||
| 56 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
| 60 | import org.onosproject.net.DefaultLink; | 57 | import org.onosproject.net.DefaultLink; |
| 61 | import org.onosproject.net.Link; | 58 | import org.onosproject.net.Link; |
| 62 | 59 | ||
| ... | @@ -71,15 +68,14 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -71,15 +68,14 @@ public class PceccSrTeBeHandlerTest { |
| 71 | private static final String LSRID = "lsrId"; | 68 | private static final String LSRID = "lsrId"; |
| 72 | 69 | ||
| 73 | private PceccSrTeBeHandler srTeHandler; | 70 | private PceccSrTeBeHandler srTeHandler; |
| 74 | - private CoreService coreService; | ||
| 75 | private LabelResourceAdminService labelRsrcAdminService; | 71 | private LabelResourceAdminService labelRsrcAdminService; |
| 76 | private LabelResourceService labelRsrcService; | 72 | private LabelResourceService labelRsrcService; |
| 77 | - private PceStore pceStore; | 73 | + private PceLabelStore pceStore; |
| 78 | private MockDeviceService deviceService; | 74 | private MockDeviceService deviceService; |
| 79 | - private FlowObjectiveService flowObjectiveService; | 75 | + private MockNetConfigRegistryAdapter netCfgService = new MockNetConfigRegistryAdapter(); |
| 80 | - private MockNetConfigRegistryAdapter netCfgService = new PathComputationTest.MockNetConfigRegistryAdapter(); | 76 | + private MockPcepClientController clientController = new MockPcepClientController(); |
| 81 | - private ApplicationId appId; | ||
| 82 | private ProviderId providerId; | 77 | private ProviderId providerId; |
| 78 | + private DeviceId deviceId1, deviceId2, deviceId3, deviceId4, deviceId5; | ||
| 83 | private Device deviceD1; | 79 | private Device deviceD1; |
| 84 | private Device deviceD2; | 80 | private Device deviceD2; |
| 85 | private Device deviceD3; | 81 | private Device deviceD3; |
| ... | @@ -103,18 +99,52 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -103,18 +99,52 @@ public class PceccSrTeBeHandlerTest { |
| 103 | srTeHandler = PceccSrTeBeHandler.getInstance(); | 99 | srTeHandler = PceccSrTeBeHandler.getInstance(); |
| 104 | labelRsrcService = new LabelResourceAdapter(); | 100 | labelRsrcService = new LabelResourceAdapter(); |
| 105 | labelRsrcAdminService = new LabelResourceAdapter(); | 101 | labelRsrcAdminService = new LabelResourceAdapter(); |
| 106 | - flowObjectiveService = new PceManagerTest.MockFlowObjService(); | 102 | + pceStore = new PceLabelStoreAdapter(); |
| 107 | - coreService = new PceManagerTest.MockCoreService(); | ||
| 108 | - appId = coreService.registerApplication("org.onosproject.pce"); | ||
| 109 | - pceStore = new PceStoreAdapter(); | ||
| 110 | deviceService = new MockDeviceService(); | 103 | deviceService = new MockDeviceService(); |
| 111 | - srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore, | 104 | + |
| 105 | + srTeHandler.initialize(labelRsrcAdminService, | ||
| 106 | + labelRsrcService, | ||
| 107 | + clientController, | ||
| 108 | + pceStore, | ||
| 112 | deviceService); | 109 | deviceService); |
| 113 | 110 | ||
| 114 | // Creates path | 111 | // Creates path |
| 115 | // Creates list of links | 112 | // Creates list of links |
| 116 | providerId = new ProviderId("of", "foo"); | 113 | providerId = new ProviderId("of", "foo"); |
| 117 | 114 | ||
| 115 | + PccId pccId1 = PccId.pccId(IpAddress.valueOf("11.1.1.1")); | ||
| 116 | + PccId pccId2 = PccId.pccId(IpAddress.valueOf("12.1.1.1")); | ||
| 117 | + PccId pccId3 = PccId.pccId(IpAddress.valueOf("13.1.1.1")); | ||
| 118 | + PccId pccId4 = PccId.pccId(IpAddress.valueOf("14.1.1.1")); | ||
| 119 | + PccId pccId5 = PccId.pccId(IpAddress.valueOf("15.1.1.1")); | ||
| 120 | + | ||
| 121 | + PcepClientAdapter pc1 = new PcepClientAdapter(); | ||
| 122 | + pc1.init(pccId1, PcepVersion.PCEP_1); | ||
| 123 | + | ||
| 124 | + PcepClientAdapter pc2 = new PcepClientAdapter(); | ||
| 125 | + pc2.init(pccId2, PcepVersion.PCEP_1); | ||
| 126 | + | ||
| 127 | + PcepClientAdapter pc3 = new PcepClientAdapter(); | ||
| 128 | + pc3.init(pccId3, PcepVersion.PCEP_1); | ||
| 129 | + | ||
| 130 | + PcepClientAdapter pc4 = new PcepClientAdapter(); | ||
| 131 | + pc4.init(pccId4, PcepVersion.PCEP_1); | ||
| 132 | + | ||
| 133 | + PcepClientAdapter pc5 = new PcepClientAdapter(); | ||
| 134 | + pc5.init(pccId5, PcepVersion.PCEP_1); | ||
| 135 | + | ||
| 136 | + clientController.addClient(pccId1, pc1); | ||
| 137 | + clientController.addClient(pccId2, pc2); | ||
| 138 | + clientController.addClient(pccId3, pc3); | ||
| 139 | + clientController.addClient(pccId4, pc4); | ||
| 140 | + clientController.addClient(pccId5, pc5); | ||
| 141 | + | ||
| 142 | + deviceId1 = DeviceId.deviceId("11.1.1.1"); | ||
| 143 | + deviceId2 = DeviceId.deviceId("12.1.1.1"); | ||
| 144 | + deviceId3 = DeviceId.deviceId("13.1.1.1"); | ||
| 145 | + deviceId4 = DeviceId.deviceId("14.1.1.1"); | ||
| 146 | + deviceId5 = DeviceId.deviceId("15.1.1.1"); | ||
| 147 | + | ||
| 118 | // Devices | 148 | // Devices |
| 119 | DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); | 149 | DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); |
| 120 | DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); | 150 | DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); |
| ... | @@ -123,25 +153,25 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -123,25 +153,25 @@ public class PceccSrTeBeHandlerTest { |
| 123 | DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); | 153 | DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); |
| 124 | 154 | ||
| 125 | builderDev1.set(AnnotationKeys.TYPE, L3); | 155 | builderDev1.set(AnnotationKeys.TYPE, L3); |
| 126 | - builderDev1.set(LSRID, "1.1.1.1"); | 156 | + builderDev1.set(LSRID, "11.1.1.1"); |
| 127 | 157 | ||
| 128 | builderDev2.set(AnnotationKeys.TYPE, L3); | 158 | builderDev2.set(AnnotationKeys.TYPE, L3); |
| 129 | - builderDev2.set(LSRID, "2.2.2.2"); | 159 | + builderDev2.set(LSRID, "12.1.1.1"); |
| 130 | 160 | ||
| 131 | builderDev3.set(AnnotationKeys.TYPE, L3); | 161 | builderDev3.set(AnnotationKeys.TYPE, L3); |
| 132 | - builderDev3.set(LSRID, "3.3.3.3"); | 162 | + builderDev3.set(LSRID, "13.1.1.1"); |
| 133 | 163 | ||
| 134 | builderDev4.set(AnnotationKeys.TYPE, L3); | 164 | builderDev4.set(AnnotationKeys.TYPE, L3); |
| 135 | - builderDev4.set(LSRID, "4.4.4.4"); | 165 | + builderDev4.set(LSRID, "14.1.1.1"); |
| 136 | 166 | ||
| 137 | builderDev5.set(AnnotationKeys.TYPE, L3); | 167 | builderDev5.set(AnnotationKeys.TYPE, L3); |
| 138 | - builderDev5.set(LSRID, "5.5.5.5"); | 168 | + builderDev5.set(LSRID, "15.1.1.1"); |
| 139 | 169 | ||
| 140 | - deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build()); | 170 | + deviceD1 = new MockDevice(deviceId1, builderDev1.build()); |
| 141 | - deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build()); | 171 | + deviceD2 = new MockDevice(deviceId2, builderDev2.build()); |
| 142 | - deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build()); | 172 | + deviceD3 = new MockDevice(deviceId3, builderDev3.build()); |
| 143 | - deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build()); | 173 | + deviceD4 = new MockDevice(deviceId4, builderDev4.build()); |
| 144 | - deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build()); | 174 | + deviceD5 = new MockDevice(deviceId5, builderDev5.build()); |
| 145 | 175 | ||
| 146 | deviceService.addDevice(deviceD1); | 176 | deviceService.addDevice(deviceD1); |
| 147 | deviceService.addDevice(deviceD2); | 177 | deviceService.addDevice(deviceD2); |
| ... | @@ -149,19 +179,19 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -149,19 +179,19 @@ public class PceccSrTeBeHandlerTest { |
| 149 | deviceService.addDevice(deviceD4); | 179 | deviceService.addDevice(deviceD4); |
| 150 | deviceService.addDevice(deviceD5); | 180 | deviceService.addDevice(deviceD5); |
| 151 | 181 | ||
| 152 | - DeviceCapability device1Cap = netCfgService.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); | 182 | + DeviceCapability device1Cap = netCfgService.addConfig(deviceId1, DeviceCapability.class); |
| 153 | device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); | 183 | device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 154 | 184 | ||
| 155 | - DeviceCapability device2Cap = netCfgService.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); | 185 | + DeviceCapability device2Cap = netCfgService.addConfig(deviceId2, DeviceCapability.class); |
| 156 | device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); | 186 | device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 157 | 187 | ||
| 158 | - DeviceCapability device3Cap = netCfgService.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); | 188 | + DeviceCapability device3Cap = netCfgService.addConfig(deviceId3, DeviceCapability.class); |
| 159 | device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); | 189 | device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 160 | 190 | ||
| 161 | - DeviceCapability device4Cap = netCfgService.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); | 191 | + DeviceCapability device4Cap = netCfgService.addConfig(deviceId4, DeviceCapability.class); |
| 162 | device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); | 192 | device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 163 | 193 | ||
| 164 | - DeviceCapability device5Cap = netCfgService.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class); | 194 | + DeviceCapability device5Cap = netCfgService.addConfig(deviceId5, DeviceCapability.class); |
| 165 | device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); | 195 | device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 166 | 196 | ||
| 167 | // Port Numbers | 197 | // Port Numbers |
| ... | @@ -199,7 +229,6 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -199,7 +229,6 @@ public class PceccSrTeBeHandlerTest { |
| 199 | 229 | ||
| 200 | @After | 230 | @After |
| 201 | public void tearDown() throws Exception { | 231 | public void tearDown() throws Exception { |
| 202 | - PceManagerTest.flowsDownloaded = 0; | ||
| 203 | } | 232 | } |
| 204 | 233 | ||
| 205 | /** | 234 | /** |
| ... | @@ -228,45 +257,45 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -228,45 +257,45 @@ public class PceccSrTeBeHandlerTest { |
| 228 | //device 1 | 257 | //device 1 |
| 229 | String lsrId1 = "11.1.1.1"; | 258 | String lsrId1 = "11.1.1.1"; |
| 230 | // Allocate node label for specific device D1deviceId | 259 | // Allocate node label for specific device D1deviceId |
| 231 | - assertThat(srTeHandler.allocateNodeLabel(D1.deviceId(), lsrId1), is(true)); | 260 | + assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1), is(true)); |
| 232 | // Retrieve label from store | 261 | // Retrieve label from store |
| 233 | - LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId()); | 262 | + LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); |
| 234 | // Check whether label is generated for this device D1.deviceId() | 263 | // Check whether label is generated for this device D1.deviceId() |
| 235 | assertThat(labelId, is(notNullValue())); | 264 | assertThat(labelId, is(notNullValue())); |
| 236 | 265 | ||
| 237 | // device 2 | 266 | // device 2 |
| 238 | String lsrId2 = "12.1.1.1"; | 267 | String lsrId2 = "12.1.1.1"; |
| 239 | // Allocate node label for specific device D2.deviceId() | 268 | // Allocate node label for specific device D2.deviceId() |
| 240 | - assertThat(srTeHandler.allocateNodeLabel(D2.deviceId(), lsrId2), is(true)); | 269 | + assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2), is(true)); |
| 241 | // Retrieve label from store | 270 | // Retrieve label from store |
| 242 | - labelId = pceStore.getGlobalNodeLabel(D2.deviceId()); | 271 | + labelId = pceStore.getGlobalNodeLabel(deviceId2); |
| 243 | // Check whether label is generated for this device D2.deviceId() | 272 | // Check whether label is generated for this device D2.deviceId() |
| 244 | assertThat(labelId, is(notNullValue())); | 273 | assertThat(labelId, is(notNullValue())); |
| 245 | 274 | ||
| 246 | // device 3 | 275 | // device 3 |
| 247 | String lsrId3 = "13.1.1.1"; | 276 | String lsrId3 = "13.1.1.1"; |
| 248 | // Allocate node label for specific device D3.deviceId() | 277 | // Allocate node label for specific device D3.deviceId() |
| 249 | - assertThat(srTeHandler.allocateNodeLabel(D3.deviceId(), lsrId3), is(true)); | 278 | + assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3), is(true)); |
| 250 | // Retrieve label from store | 279 | // Retrieve label from store |
| 251 | - labelId = pceStore.getGlobalNodeLabel(D3.deviceId()); | 280 | + labelId = pceStore.getGlobalNodeLabel(deviceId3); |
| 252 | // Check whether label is generated for this device D3.deviceId() | 281 | // Check whether label is generated for this device D3.deviceId() |
| 253 | assertThat(labelId, is(notNullValue())); | 282 | assertThat(labelId, is(notNullValue())); |
| 254 | 283 | ||
| 255 | // device 4 | 284 | // device 4 |
| 256 | String lsrId4 = "14.1.1.1"; | 285 | String lsrId4 = "14.1.1.1"; |
| 257 | // Allocate node label for specific device D4.deviceId() | 286 | // Allocate node label for specific device D4.deviceId() |
| 258 | - assertThat(srTeHandler.allocateNodeLabel(D4.deviceId(), lsrId4), is(true)); | 287 | + assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4), is(true)); |
| 259 | // Retrieve label from store | 288 | // Retrieve label from store |
| 260 | - labelId = pceStore.getGlobalNodeLabel(D4.deviceId()); | 289 | + labelId = pceStore.getGlobalNodeLabel(deviceId4); |
| 261 | // Check whether label is generated for this device D4.deviceId() | 290 | // Check whether label is generated for this device D4.deviceId() |
| 262 | assertThat(labelId, is(notNullValue())); | 291 | assertThat(labelId, is(notNullValue())); |
| 263 | 292 | ||
| 264 | // device 5 | 293 | // device 5 |
| 265 | String lsrId5 = "15.1.1.1"; | 294 | String lsrId5 = "15.1.1.1"; |
| 266 | // Allocate node label for specific device D5.deviceId() | 295 | // Allocate node label for specific device D5.deviceId() |
| 267 | - assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true)); | 296 | + assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5), is(true)); |
| 268 | // Retrieve label from store | 297 | // Retrieve label from store |
| 269 | - labelId = pceStore.getGlobalNodeLabel(D5.deviceId()); | 298 | + labelId = pceStore.getGlobalNodeLabel(deviceId5); |
| 270 | // Check whether label is generated for this device D5.deviceId() | 299 | // Check whether label is generated for this device D5.deviceId() |
| 271 | assertThat(labelId, is(notNullValue())); | 300 | assertThat(labelId, is(notNullValue())); |
| 272 | } | 301 | } |
| ... | @@ -282,41 +311,41 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -282,41 +311,41 @@ public class PceccSrTeBeHandlerTest { |
| 282 | //device 1 | 311 | //device 1 |
| 283 | String lsrId1 = "11.1.1.1"; | 312 | String lsrId1 = "11.1.1.1"; |
| 284 | // Check whether successfully released node label | 313 | // Check whether successfully released node label |
| 285 | - assertThat(srTeHandler.releaseNodeLabel(D1.deviceId(), lsrId1), is(true)); | 314 | + assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1), is(true)); |
| 286 | // Check whether successfully removed label from store | 315 | // Check whether successfully removed label from store |
| 287 | - LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId()); | 316 | + LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); |
| 288 | assertThat(labelId, is(nullValue())); | 317 | assertThat(labelId, is(nullValue())); |
| 289 | 318 | ||
| 290 | //device 2 | 319 | //device 2 |
| 291 | String lsrId2 = "12.1.1.1"; | 320 | String lsrId2 = "12.1.1.1"; |
| 292 | // Check whether successfully released node label | 321 | // Check whether successfully released node label |
| 293 | - assertThat(srTeHandler.releaseNodeLabel(D2.deviceId(), lsrId2), is(true)); | 322 | + assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2), is(true)); |
| 294 | // Check whether successfully removed label from store | 323 | // Check whether successfully removed label from store |
| 295 | - labelId = pceStore.getGlobalNodeLabel(D2.deviceId()); | 324 | + labelId = pceStore.getGlobalNodeLabel(deviceId2); |
| 296 | assertThat(labelId, is(nullValue())); | 325 | assertThat(labelId, is(nullValue())); |
| 297 | 326 | ||
| 298 | //device 3 | 327 | //device 3 |
| 299 | String lsrId3 = "13.1.1.1"; | 328 | String lsrId3 = "13.1.1.1"; |
| 300 | // Check whether successfully released node label | 329 | // Check whether successfully released node label |
| 301 | - assertThat(srTeHandler.releaseNodeLabel(D3.deviceId(), lsrId3), is(true)); | 330 | + assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3), is(true)); |
| 302 | // Check whether successfully removed label from store | 331 | // Check whether successfully removed label from store |
| 303 | - labelId = pceStore.getGlobalNodeLabel(D3.deviceId()); | 332 | + labelId = pceStore.getGlobalNodeLabel(deviceId3); |
| 304 | assertThat(labelId, is(nullValue())); | 333 | assertThat(labelId, is(nullValue())); |
| 305 | 334 | ||
| 306 | //device 4 | 335 | //device 4 |
| 307 | String lsrId4 = "14.1.1.1"; | 336 | String lsrId4 = "14.1.1.1"; |
| 308 | // Check whether successfully released node label | 337 | // Check whether successfully released node label |
| 309 | - assertThat(srTeHandler.releaseNodeLabel(D4.deviceId(), lsrId4), is(true)); | 338 | + assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4), is(true)); |
| 310 | // Check whether successfully removed label from store | 339 | // Check whether successfully removed label from store |
| 311 | - labelId = pceStore.getGlobalNodeLabel(D4.deviceId()); | 340 | + labelId = pceStore.getGlobalNodeLabel(deviceId4); |
| 312 | assertThat(labelId, is(nullValue())); | 341 | assertThat(labelId, is(nullValue())); |
| 313 | 342 | ||
| 314 | //device 5 | 343 | //device 5 |
| 315 | String lsrId5 = "15.1.1.1"; | 344 | String lsrId5 = "15.1.1.1"; |
| 316 | // Check whether successfully released node label | 345 | // Check whether successfully released node label |
| 317 | - assertThat(srTeHandler.releaseNodeLabel(D5.deviceId(), lsrId5), is(true)); | 346 | + assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5), is(true)); |
| 318 | // Check whether successfully removed label from store | 347 | // Check whether successfully removed label from store |
| 319 | - labelId = pceStore.getGlobalNodeLabel(D5.deviceId()); | 348 | + labelId = pceStore.getGlobalNodeLabel(deviceId5); |
| 320 | assertThat(labelId, is(nullValue())); | 349 | assertThat(labelId, is(nullValue())); |
| 321 | } | 350 | } |
| 322 | 351 | ||
| ... | @@ -394,15 +423,15 @@ public class PceccSrTeBeHandlerTest { | ... | @@ -394,15 +423,15 @@ public class PceccSrTeBeHandlerTest { |
| 394 | public void testComputeLabelStack() { | 423 | public void testComputeLabelStack() { |
| 395 | // Allocate node labels to each devices | 424 | // Allocate node labels to each devices |
| 396 | labelId = LabelResourceId.labelResourceId(4097); | 425 | labelId = LabelResourceId.labelResourceId(4097); |
| 397 | - pceStore.addGlobalNodeLabel(D1.deviceId(), labelId); | 426 | + pceStore.addGlobalNodeLabel(deviceId1, labelId); |
| 398 | labelId = LabelResourceId.labelResourceId(4098); | 427 | labelId = LabelResourceId.labelResourceId(4098); |
| 399 | - pceStore.addGlobalNodeLabel(D2.deviceId(), labelId); | 428 | + pceStore.addGlobalNodeLabel(deviceId2, labelId); |
| 400 | labelId = LabelResourceId.labelResourceId(4099); | 429 | labelId = LabelResourceId.labelResourceId(4099); |
| 401 | - pceStore.addGlobalNodeLabel(D3.deviceId(), labelId); | 430 | + pceStore.addGlobalNodeLabel(deviceId3, labelId); |
| 402 | labelId = LabelResourceId.labelResourceId(4100); | 431 | labelId = LabelResourceId.labelResourceId(4100); |
| 403 | - pceStore.addGlobalNodeLabel(D4.deviceId(), labelId); | 432 | + pceStore.addGlobalNodeLabel(deviceId4, labelId); |
| 404 | labelId = LabelResourceId.labelResourceId(4101); | 433 | labelId = LabelResourceId.labelResourceId(4101); |
| 405 | - pceStore.addGlobalNodeLabel(D5.deviceId(), labelId); | 434 | + pceStore.addGlobalNodeLabel(deviceId5, labelId); |
| 406 | 435 | ||
| 407 | // Allocate adjacency labels to each devices | 436 | // Allocate adjacency labels to each devices |
| 408 | labelId = LabelResourceId.labelResourceId(5122); | 437 | labelId = LabelResourceId.labelResourceId(5122); | ... | ... |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/ConsistentMapAdapter.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015-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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.Collection; | ||
| 19 | +import java.util.Map; | ||
| 20 | +import java.util.Set; | ||
| 21 | +import java.util.concurrent.Executor; | ||
| 22 | +import java.util.function.BiFunction; | ||
| 23 | +import java.util.function.Function; | ||
| 24 | +import java.util.function.Predicate; | ||
| 25 | + | ||
| 26 | +import org.onosproject.store.service.ConsistentMap; | ||
| 27 | +import org.onosproject.store.service.DistributedPrimitive; | ||
| 28 | +import org.onosproject.store.service.MapEventListener; | ||
| 29 | +import org.onosproject.store.service.Versioned; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Testing adapter for the consistent map. | ||
| 33 | + */ | ||
| 34 | +public class ConsistentMapAdapter<K, V> implements ConsistentMap<K, V> { | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public String name() { | ||
| 38 | + return null; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public DistributedPrimitive.Type primitiveType() { | ||
| 43 | + return DistributedPrimitive.Type.CONSISTENT_MAP; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public int size() { | ||
| 48 | + return 0; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public boolean isEmpty() { | ||
| 53 | + return false; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public boolean containsKey(K key) { | ||
| 58 | + return false; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public boolean containsValue(V value) { | ||
| 63 | + return false; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public Versioned<V> get(K key) { | ||
| 68 | + return null; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public Versioned<V> computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) { | ||
| 73 | + return null; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public Versioned<V> compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | ||
| 83 | + return null; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @Override | ||
| 87 | + public Versioned<V> computeIf(K key, Predicate<? super V> condition, | ||
| 88 | + BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | ||
| 89 | + return null; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Override | ||
| 93 | + public Versioned<V> put(K key, V value) { | ||
| 94 | + return null; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public Versioned<V> putAndGet(K key, V value) { | ||
| 99 | + return null; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public Versioned<V> remove(K key) { | ||
| 104 | + return null; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public void clear() { | ||
| 109 | + | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @Override | ||
| 113 | + public Set<K> keySet() { | ||
| 114 | + return null; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @Override | ||
| 118 | + public Collection<Versioned<V>> values() { | ||
| 119 | + return null; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @Override | ||
| 123 | + public Set<Map.Entry<K, Versioned<V>>> entrySet() { | ||
| 124 | + return null; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public Versioned<V> putIfAbsent(K key, V value) { | ||
| 129 | + return null; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public boolean remove(K key, V value) { | ||
| 134 | + return false; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public boolean remove(K key, long version) { | ||
| 139 | + return false; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + @Override | ||
| 143 | + public Versioned replace(K key, V value) { | ||
| 144 | + return null; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public boolean replace(K key, V oldValue, V newValue) { | ||
| 149 | + return false; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public boolean replace(K key, long oldVersion, V newValue) { | ||
| 154 | + return false; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + @Override | ||
| 158 | + public void addListener(MapEventListener<K, V> listener, Executor executor) { | ||
| 159 | + | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + @Override | ||
| 163 | + public void removeListener(MapEventListener<K, V> listener) { | ||
| 164 | + | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + @Override | ||
| 168 | + public Map<K, V> asJavaMap() { | ||
| 169 | + return null; | ||
| 170 | + } | ||
| 171 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/DistributedSetAdapter.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 | + | ||
| 17 | +package org.onosproject.pcelabelstore.util; | ||
| 18 | + | ||
| 19 | +import java.util.Collection; | ||
| 20 | +import java.util.Set; | ||
| 21 | +import java.util.concurrent.CompletableFuture; | ||
| 22 | + | ||
| 23 | +import org.onosproject.store.service.AsyncDistributedSet; | ||
| 24 | +import org.onosproject.store.service.SetEventListener; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Testing adapter for the distributed set. | ||
| 28 | + */ | ||
| 29 | +public class DistributedSetAdapter<E> implements AsyncDistributedSet<E> { | ||
| 30 | + @Override | ||
| 31 | + public CompletableFuture<Void> addListener(SetEventListener<E> listener) { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public CompletableFuture<Void> removeListener(SetEventListener<E> listener) { | ||
| 37 | + return null; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public CompletableFuture<Boolean> add(E element) { | ||
| 42 | + return null; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public CompletableFuture<Boolean> remove(E element) { | ||
| 47 | + return null; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public CompletableFuture<Integer> size() { | ||
| 52 | + return null; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public CompletableFuture<Boolean> isEmpty() { | ||
| 57 | + return null; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public CompletableFuture<Void> clear() { | ||
| 62 | + return null; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public CompletableFuture<Boolean> contains(E element) { | ||
| 67 | + return null; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public CompletableFuture<Boolean> addAll(Collection<? extends E> c) { | ||
| 72 | + return null; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + public CompletableFuture<Boolean> containsAll(Collection<? extends E> c) { | ||
| 77 | + return null; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public CompletableFuture<Boolean> retainAll(Collection<? extends E> c) { | ||
| 82 | + return null; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public CompletableFuture<Boolean> removeAll(Collection<? extends E> c) { | ||
| 87 | + return null; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public CompletableFuture<? extends Set<E>> getAsImmutableSet() { | ||
| 92 | + return null; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public String name() { | ||
| 97 | + return null; | ||
| 98 | + } | ||
| 99 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015-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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.Collection; | ||
| 19 | +import java.util.Map; | ||
| 20 | +import java.util.Set; | ||
| 21 | +import java.util.concurrent.CompletableFuture; | ||
| 22 | +import java.util.function.BiFunction; | ||
| 23 | + | ||
| 24 | +import org.onosproject.store.service.EventuallyConsistentMap; | ||
| 25 | +import org.onosproject.store.service.EventuallyConsistentMapListener; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * Testing adapter for EventuallyConsistentMap. | ||
| 29 | + */ | ||
| 30 | +public class EventuallyConsistentMapAdapter<K, V> implements EventuallyConsistentMap<K, V> { | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public String name() { | ||
| 34 | + return null; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public Type primitiveType() { | ||
| 39 | + return Type.EVENTUALLY_CONSISTENT_MAP; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public int size() { | ||
| 44 | + return 0; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public boolean isEmpty() { | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public boolean containsKey(K key) { | ||
| 54 | + return false; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public boolean containsValue(V value) { | ||
| 59 | + return false; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public V get(K key) { | ||
| 64 | + return null; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public void put(K key, V value) { | ||
| 69 | + | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public V remove(K key) { | ||
| 74 | + return null; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public void remove(K key, V value) { | ||
| 79 | + | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public V compute(K key, BiFunction<K, V, V> recomputeFunction) { | ||
| 84 | + return null; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public void putAll(Map<? extends K, ? extends V> m) { | ||
| 89 | + | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Override | ||
| 93 | + public void clear() { | ||
| 94 | + | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public Set<K> keySet() { | ||
| 99 | + return null; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public Collection<V> values() { | ||
| 104 | + return null; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public Set<Map.Entry<K, V>> entrySet() { | ||
| 109 | + return null; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @Override | ||
| 113 | + public void addListener(EventuallyConsistentMapListener<K, V> listener) { | ||
| 114 | + | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @Override | ||
| 118 | + public void removeListener(EventuallyConsistentMapListener<K, V> listener) { | ||
| 119 | + | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @Override | ||
| 123 | + public CompletableFuture<Void> destroy() { | ||
| 124 | + return CompletableFuture.completedFuture(null); | ||
| 125 | + } | ||
| 126 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/LabelResourceAdapter.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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.Collection; | ||
| 21 | +import java.util.LinkedList; | ||
| 22 | +import java.util.Random; | ||
| 23 | +import java.util.Set; | ||
| 24 | + | ||
| 25 | +import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 26 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 27 | +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 28 | +import org.onosproject.incubator.net.resource.label.LabelResourceDelegate; | ||
| 29 | +import org.onosproject.incubator.net.resource.label.LabelResourceEvent; | ||
| 30 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 31 | +import org.onosproject.incubator.net.resource.label.LabelResourceListener; | ||
| 32 | +import org.onosproject.incubator.net.resource.label.LabelResourcePool; | ||
| 33 | +import org.onosproject.incubator.net.resource.label.LabelResourceProvider; | ||
| 34 | +import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistry; | ||
| 35 | +import org.onosproject.incubator.net.resource.label.LabelResourceProviderService; | ||
| 36 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 37 | +import org.onosproject.net.Device; | ||
| 38 | +import org.onosproject.net.DeviceId; | ||
| 39 | +import org.onosproject.net.device.DeviceEvent; | ||
| 40 | +import org.onosproject.net.device.DeviceEvent.Type; | ||
| 41 | +import org.onosproject.net.device.DeviceListener; | ||
| 42 | +import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
| 43 | +import org.onosproject.net.provider.AbstractProviderService; | ||
| 44 | + | ||
| 45 | +import com.google.common.collect.Multimap; | ||
| 46 | + | ||
| 47 | +/** | ||
| 48 | + * Provides test implementation of class LabelResourceService. | ||
| 49 | + */ | ||
| 50 | +public class LabelResourceAdapter | ||
| 51 | + extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener, | ||
| 52 | + LabelResourceProvider, LabelResourceProviderService> | ||
| 53 | + implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry { | ||
| 54 | + public static final long GLOBAL_LABEL_SPACE_MIN = 4097; | ||
| 55 | + public static final long GLOBAL_LABEL_SPACE_MAX = 5121; | ||
| 56 | + public static final long LOCAL_LABEL_SPACE_MIN = 5122; | ||
| 57 | + public static final long LOCAL_LABEL_SPACE_MAX = 9217; | ||
| 58 | + | ||
| 59 | + private Random random = new Random(); | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public boolean createDevicePool(DeviceId deviceId, | ||
| 63 | + LabelResourceId beginLabel, | ||
| 64 | + LabelResourceId endLabel) { | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public boolean createGlobalPool(LabelResourceId beginLabel, | ||
| 70 | + LabelResourceId endLabel) { | ||
| 71 | + return true; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public boolean destroyDevicePool(DeviceId deviceId) { | ||
| 76 | + return true; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public boolean destroyGlobalPool() { | ||
| 81 | + return true; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public long getLabelId(long min, long max) { | ||
| 85 | + return random.nextInt((int) max - (int) min + 1) + (int) min; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId, | ||
| 90 | + long applyNum) { | ||
| 91 | + Collection<LabelResource> labelList = new LinkedList<>(); | ||
| 92 | + LabelResource label = new DefaultLabelResource(deviceId, | ||
| 93 | + LabelResourceId.labelResourceId( | ||
| 94 | + getLabelId(LOCAL_LABEL_SPACE_MIN, LOCAL_LABEL_SPACE_MAX))); | ||
| 95 | + labelList.add(label); | ||
| 96 | + return labelList; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Override | ||
| 100 | + public Collection<LabelResource> applyFromGlobalPool(long applyNum) { | ||
| 101 | + Collection<LabelResource> labelList = new LinkedList<>(); | ||
| 102 | + LabelResource label = new DefaultLabelResource(DeviceId.deviceId("foo"), | ||
| 103 | + LabelResourceId.labelResourceId( | ||
| 104 | + getLabelId(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX))); | ||
| 105 | + labelList.add(label); | ||
| 106 | + return labelList; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) { | ||
| 111 | + return true; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public boolean releaseToGlobalPool(Set<LabelResourceId> release) { | ||
| 116 | + return true; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public boolean isDevicePoolFull(DeviceId deviceId) { | ||
| 121 | + return false; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Override | ||
| 125 | + public boolean isGlobalPoolFull() { | ||
| 126 | + return false; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + @Override | ||
| 130 | + public long getFreeNumOfDevicePool(DeviceId deviceId) { | ||
| 131 | + return 4; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + @Override | ||
| 135 | + public long getFreeNumOfGlobalPool() { | ||
| 136 | + return 4; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @Override | ||
| 140 | + public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) { | ||
| 141 | + return null; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public LabelResourcePool getGlobalLabelResourcePool() { | ||
| 146 | + return null; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + private class InternalLabelResourceDelegate implements LabelResourceDelegate { | ||
| 150 | + @Override | ||
| 151 | + public void notify(LabelResourceEvent event) { | ||
| 152 | + post(event); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + private class InternalDeviceListener implements DeviceListener { | ||
| 158 | + @Override | ||
| 159 | + public void event(DeviceEvent event) { | ||
| 160 | + Device device = event.subject(); | ||
| 161 | + if (Type.DEVICE_REMOVED.equals(event.type())) { | ||
| 162 | + destroyDevicePool(device.id()); | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + private class InternalLabelResourceProviderService | ||
| 168 | + extends AbstractProviderService<LabelResourceProvider> | ||
| 169 | + implements LabelResourceProviderService { | ||
| 170 | + | ||
| 171 | + protected InternalLabelResourceProviderService(LabelResourceProvider provider) { | ||
| 172 | + super(provider); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + @Override | ||
| 176 | + public void deviceLabelResourcePoolDetected(DeviceId deviceId, | ||
| 177 | + LabelResourceId beginLabel, | ||
| 178 | + LabelResourceId endLabel) { | ||
| 179 | + checkNotNull(deviceId, "deviceId is not null"); | ||
| 180 | + checkNotNull(beginLabel, "beginLabel is not null"); | ||
| 181 | + checkNotNull(endLabel, "endLabel is not null"); | ||
| 182 | + createDevicePool(deviceId, beginLabel, endLabel); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 186 | + public void deviceLabelResourcePoolDestroyed(DeviceId deviceId) { | ||
| 187 | + checkNotNull(deviceId, "deviceId is not null"); | ||
| 188 | + destroyDevicePool(deviceId); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + @Override | ||
| 194 | + protected LabelResourceProviderService createProviderService(LabelResourceProvider provider) { | ||
| 195 | + return null; | ||
| 196 | + } | ||
| 197 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/MockDeviceService.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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.LinkedList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +import org.onosproject.net.device.DeviceListener; | ||
| 22 | +import org.onosproject.net.device.PortStatistics; | ||
| 23 | +import org.onosproject.net.Device; | ||
| 24 | +import org.onosproject.net.Device.Type; | ||
| 25 | +import org.onosproject.net.DeviceId; | ||
| 26 | +import org.onosproject.net.MastershipRole; | ||
| 27 | +import org.onosproject.net.Port; | ||
| 28 | +import org.onosproject.net.PortNumber; | ||
| 29 | +import org.onosproject.net.device.DeviceService; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Test fixture for the device service. | ||
| 33 | + */ | ||
| 34 | +public class MockDeviceService implements DeviceService { | ||
| 35 | + private List<Device> devices = new LinkedList<>(); | ||
| 36 | + private DeviceListener listener; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Adds a new device. | ||
| 40 | + * | ||
| 41 | + * @param dev device to be added | ||
| 42 | + */ | ||
| 43 | + public void addDevice(Device dev) { | ||
| 44 | + devices.add(dev); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Removes the specified device. | ||
| 49 | + * | ||
| 50 | + * @param dev device to be removed | ||
| 51 | + */ | ||
| 52 | + public void removeDevice(Device dev) { | ||
| 53 | + devices.remove(dev); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public Device getDevice(DeviceId deviceId) { | ||
| 58 | + for (Device dev : devices) { | ||
| 59 | + if (dev.id().equals(deviceId)) { | ||
| 60 | + return dev; | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + return null; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public Iterable<Device> getAvailableDevices() { | ||
| 68 | + return devices; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void addListener(DeviceListener listener) { | ||
| 73 | + this.listener = listener; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Get the listener. | ||
| 78 | + */ | ||
| 79 | + public DeviceListener getListener() { | ||
| 80 | + return listener; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public void removeListener(DeviceListener listener) { | ||
| 85 | + // TODO Auto-generated method stub | ||
| 86 | + | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public int getDeviceCount() { | ||
| 91 | + // TODO Auto-generated method stub | ||
| 92 | + return 0; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public Iterable<Device> getDevices() { | ||
| 97 | + // TODO Auto-generated method stub | ||
| 98 | + return null; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public Iterable<Device> getDevices(Type type) { | ||
| 103 | + // TODO Auto-generated method stub | ||
| 104 | + return null; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public Iterable<Device> getAvailableDevices(Type type) { | ||
| 109 | + // TODO Auto-generated method stub | ||
| 110 | + return null; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + @Override | ||
| 114 | + public MastershipRole getRole(DeviceId deviceId) { | ||
| 115 | + // TODO Auto-generated method stub | ||
| 116 | + return null; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public List<Port> getPorts(DeviceId deviceId) { | ||
| 121 | + // TODO Auto-generated method stub | ||
| 122 | + return null; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public List<PortStatistics> getPortStatistics(DeviceId deviceId) { | ||
| 127 | + // TODO Auto-generated method stub | ||
| 128 | + return null; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) { | ||
| 133 | + // TODO Auto-generated method stub | ||
| 134 | + return null; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public Port getPort(DeviceId deviceId, PortNumber portNumber) { | ||
| 139 | + // TODO Auto-generated method stub | ||
| 140 | + return null; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Override | ||
| 144 | + public boolean isAvailable(DeviceId deviceId) { | ||
| 145 | + // TODO Auto-generated method stub | ||
| 146 | + return false; | ||
| 147 | + } | ||
| 148 | +} |
| 1 | +package org.onosproject.pcelabelstore.util; | ||
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.Map; | ||
| 5 | +import java.util.Set; | ||
| 6 | + | ||
| 7 | +import org.onosproject.net.DeviceId; | ||
| 8 | +import org.onosproject.net.config.Config; | ||
| 9 | +import org.onosproject.net.config.ConfigApplyDelegate; | ||
| 10 | +import org.onosproject.net.config.ConfigFactory; | ||
| 11 | +import org.onosproject.net.config.NetworkConfigListener; | ||
| 12 | +import org.onosproject.net.config.NetworkConfigRegistry; | ||
| 13 | +import org.onosproject.net.config.NetworkConfigService; | ||
| 14 | +import org.onosproject.net.config.SubjectFactory; | ||
| 15 | +import org.onosproject.pcep.api.DeviceCapability; | ||
| 16 | + | ||
| 17 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 18 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 19 | +import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
| 20 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 21 | + | ||
| 22 | +/* Mock test for network config registry. */ | ||
| 23 | +public class MockNetConfigRegistryAdapter implements NetworkConfigService, NetworkConfigRegistry { | ||
| 24 | + private ConfigFactory cfgFactory; | ||
| 25 | + private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>(); | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public void registerConfigFactory(ConfigFactory configFactory) { | ||
| 29 | + cfgFactory = configFactory; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public void unregisterConfigFactory(ConfigFactory configFactory) { | ||
| 34 | + cfgFactory = null; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) { | ||
| 39 | + if (configClass == DeviceCapability.class) { | ||
| 40 | + DeviceCapability devCap = new DeviceCapability(); | ||
| 41 | + classConfig.put((DeviceId) subject, devCap); | ||
| 42 | + | ||
| 43 | + JsonNode node = new ObjectNode(new MockJsonNode()); | ||
| 44 | + ObjectMapper mapper = new ObjectMapper(); | ||
| 45 | + ConfigApplyDelegate delegate = new InternalApplyDelegate(); | ||
| 46 | + devCap.init((DeviceId) subject, null, node, mapper, delegate); | ||
| 47 | + return (C) devCap; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + return null; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) { | ||
| 55 | + classConfig.remove(subject); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { | ||
| 60 | + if (configClass == DeviceCapability.class) { | ||
| 61 | + return (C) classConfig.get(subject); | ||
| 62 | + } | ||
| 63 | + return null; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + private class MockJsonNode extends JsonNodeFactory { | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + // Auxiliary delegate to receive notifications about changes applied to | ||
| 70 | + // the network configuration - by the apps. | ||
| 71 | + private class InternalApplyDelegate implements ConfigApplyDelegate { | ||
| 72 | + @Override | ||
| 73 | + public void onApply(Config config) { | ||
| 74 | + //configs.put(config.subject(), config.node()); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public void addListener(NetworkConfigListener listener) { | ||
| 80 | + // TODO Auto-generated method stub | ||
| 81 | + | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public void removeListener(NetworkConfigListener listener) { | ||
| 86 | + // TODO Auto-generated method stub | ||
| 87 | + | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public Set<ConfigFactory> getConfigFactories() { | ||
| 92 | + // TODO Auto-generated method stub | ||
| 93 | + return null; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public <S, C extends Config<S>> Set<ConfigFactory<S, C>> getConfigFactories(Class<S> subjectClass) { | ||
| 98 | + // TODO Auto-generated method stub | ||
| 99 | + return null; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) { | ||
| 104 | + // TODO Auto-generated method stub | ||
| 105 | + return null; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + @Override | ||
| 109 | + public Set<Class> getSubjectClasses() { | ||
| 110 | + // TODO Auto-generated method stub | ||
| 111 | + return null; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public SubjectFactory getSubjectFactory(String subjectClassKey) { | ||
| 116 | + // TODO Auto-generated method stub | ||
| 117 | + return null; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Override | ||
| 121 | + public SubjectFactory getSubjectFactory(Class subjectClass) { | ||
| 122 | + // TODO Auto-generated method stub | ||
| 123 | + return null; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + @Override | ||
| 127 | + public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) { | ||
| 128 | + // TODO Auto-generated method stub | ||
| 129 | + return null; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public <S> Set<S> getSubjects(Class<S> subjectClass) { | ||
| 134 | + // TODO Auto-generated method stub | ||
| 135 | + return null; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + @Override | ||
| 139 | + public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) { | ||
| 140 | + // TODO Auto-generated method stub | ||
| 141 | + return null; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public <S> Set<? extends Config<S>> getConfigs(S subject) { | ||
| 146 | + // TODO Auto-generated method stub | ||
| 147 | + return null; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @Override | ||
| 151 | + public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { | ||
| 152 | + // TODO Auto-generated method stub | ||
| 153 | + return null; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + @Override | ||
| 157 | + public <S, C extends Config<S>> C applyConfig(String subjectClassKey, S subject, String configKey, JsonNode json) { | ||
| 158 | + // TODO Auto-generated method stub | ||
| 159 | + return null; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + @Override | ||
| 163 | + public <S> void removeConfig(String subjectClassKey, S subject, String configKey) { | ||
| 164 | + // TODO Auto-generated method stub | ||
| 165 | + | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + @Override | ||
| 169 | + public <S> void removeConfig(S subject) { | ||
| 170 | + // TODO Auto-generated method stub | ||
| 171 | + | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + @Override | ||
| 175 | + public <S> void removeConfig() { | ||
| 176 | + // TODO Auto-generated method stub | ||
| 177 | + | ||
| 178 | + } | ||
| 179 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/MockPcepClientController.java
0 → 100644
| 1 | +package org.onosproject.pcelabelstore.util; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.HashMap; | ||
| 5 | +import java.util.LinkedList; | ||
| 6 | +import java.util.Map; | ||
| 7 | + | ||
| 8 | +import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | ||
| 9 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 10 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 11 | +import org.onosproject.net.Path; | ||
| 12 | +import org.onosproject.pcep.controller.PccId; | ||
| 13 | +import org.onosproject.pcep.controller.PcepClient; | ||
| 14 | +import org.onosproject.pcep.controller.PcepClientController; | ||
| 15 | +import org.onosproject.pcep.controller.PcepClientListener; | ||
| 16 | +import org.onosproject.pcep.controller.PcepEventListener; | ||
| 17 | +import org.onosproject.pcep.controller.PcepNodeListener; | ||
| 18 | +import org.onosproject.pcepio.protocol.PcepMessage; | ||
| 19 | +import org.onosproject.pcepio.types.PcepValueType; | ||
| 20 | + | ||
| 21 | +public class MockPcepClientController implements PcepClientController { | ||
| 22 | + | ||
| 23 | + Map<PccId, PcepClient> clientMap = new HashMap<>(); | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public Collection<PcepClient> getClients() { | ||
| 27 | + // TODO Auto-generated method stub | ||
| 28 | + return null; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void addClient(PccId pccId, PcepClient pc) { | ||
| 32 | + clientMap.put(pccId, pc); | ||
| 33 | + return; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public PcepClient getClient(PccId pccId) { | ||
| 38 | + return clientMap.get(pccId); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public void addListener(PcepClientListener listener) { | ||
| 43 | + // TODO Auto-generated method stub | ||
| 44 | + | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void removeListener(PcepClientListener listener) { | ||
| 49 | + // TODO Auto-generated method stub | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public void addEventListener(PcepEventListener listener) { | ||
| 55 | + // TODO Auto-generated method stub | ||
| 56 | + | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public void removeEventListener(PcepEventListener listener) { | ||
| 61 | + // TODO Auto-generated method stub | ||
| 62 | + | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public void addNodeListener(PcepNodeListener listener) { | ||
| 67 | + // TODO Auto-generated method stub | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void removeNodeListener(PcepNodeListener listener) { | ||
| 73 | + // TODO Auto-generated method stub | ||
| 74 | + | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public void writeMessage(PccId pccId, PcepMessage msg) { | ||
| 79 | + // TODO Auto-generated method stub | ||
| 80 | + | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public void processClientMessage(PccId pccId, PcepMessage msg) { | ||
| 85 | + // TODO Auto-generated method stub | ||
| 86 | + | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public void closeConnectedClients() { | ||
| 91 | + // TODO Auto-generated method stub | ||
| 92 | + | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public LabelStack computeLabelStack(Path path) { | ||
| 97 | + // TODO Auto-generated method stub | ||
| 98 | + return null; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) { | ||
| 103 | + // TODO Auto-generated method stub | ||
| 104 | + return null; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public boolean allocateLocalLabel(Tunnel tunnel) { | ||
| 109 | + // TODO Auto-generated method stub | ||
| 110 | + return false; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/PceLabelStoreAdapter.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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 19 | +import java.util.concurrent.ConcurrentMap; | ||
| 20 | + | ||
| 21 | +import java.util.HashMap; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Map; | ||
| 24 | +import java.util.stream.Collectors; | ||
| 25 | + | ||
| 26 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 27 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 28 | +import org.onosproject.net.DeviceId; | ||
| 29 | +import org.onosproject.net.Link; | ||
| 30 | +import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; | ||
| 31 | +import org.onosproject.pcelabelstore.api.PceLabelStore; | ||
| 32 | + | ||
| 33 | +/** | ||
| 34 | + * Provides test implementation of PceStore. | ||
| 35 | + */ | ||
| 36 | +public class PceLabelStoreAdapter implements PceLabelStore { | ||
| 37 | + | ||
| 38 | + // Mapping device with global node label | ||
| 39 | + private ConcurrentMap<DeviceId, LabelResourceId> globalNodeLabelMap = new ConcurrentHashMap<>(); | ||
| 40 | + | ||
| 41 | + // Mapping link with adjacency label | ||
| 42 | + private ConcurrentMap<Link, LabelResourceId> adjLabelMap = new ConcurrentHashMap<>(); | ||
| 43 | + | ||
| 44 | + // Mapping tunnel with device local info with tunnel consumer id | ||
| 45 | + private ConcurrentMap<TunnelId, List<LspLocalLabelInfo>> tunnelInfoMap = new ConcurrentHashMap<>(); | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + // Locally maintain LSRID to device id mapping for better performance. | ||
| 49 | + private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>(); | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public boolean existsGlobalNodeLabel(DeviceId id) { | ||
| 53 | + return globalNodeLabelMap.containsKey(id); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public boolean existsAdjLabel(Link link) { | ||
| 58 | + return adjLabelMap.containsKey(link); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public boolean existsTunnelInfo(TunnelId tunnelId) { | ||
| 63 | + return tunnelInfoMap.containsKey(tunnelId); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public int getGlobalNodeLabelCount() { | ||
| 68 | + return globalNodeLabelMap.size(); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public int getAdjLabelCount() { | ||
| 73 | + return adjLabelMap.size(); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public int getTunnelInfoCount() { | ||
| 78 | + return tunnelInfoMap.size(); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public boolean removeTunnelInfo(TunnelId tunnelId) { | ||
| 83 | + tunnelInfoMap.remove(tunnelId); | ||
| 84 | + if (tunnelInfoMap.containsKey(tunnelId)) { | ||
| 85 | + return false; | ||
| 86 | + } | ||
| 87 | + return true; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public Map<DeviceId, LabelResourceId> getGlobalNodeLabels() { | ||
| 92 | + return globalNodeLabelMap.entrySet().stream() | ||
| 93 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue())); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public Map<Link, LabelResourceId> getAdjLabels() { | ||
| 98 | + return adjLabelMap.entrySet().stream() | ||
| 99 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue())); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public LabelResourceId getGlobalNodeLabel(DeviceId id) { | ||
| 104 | + return globalNodeLabelMap.get(id); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + @Override | ||
| 108 | + public LabelResourceId getAdjLabel(Link link) { | ||
| 109 | + return adjLabelMap.get(link); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @Override | ||
| 113 | + public List<LspLocalLabelInfo> getTunnelInfo(TunnelId tunnelId) { | ||
| 114 | + return tunnelInfoMap.get(tunnelId); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + @Override | ||
| 118 | + public void addGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId) { | ||
| 119 | + globalNodeLabelMap.put(deviceId, labelId); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @Override | ||
| 123 | + public void addAdjLabel(Link link, LabelResourceId labelId) { | ||
| 124 | + adjLabelMap.put(link, labelId); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public void addTunnelInfo(TunnelId tunnelId, List<LspLocalLabelInfo> lspLocalLabelInfoList) { | ||
| 129 | + tunnelInfoMap.put(tunnelId, lspLocalLabelInfoList); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public boolean removeGlobalNodeLabel(DeviceId id) { | ||
| 134 | + globalNodeLabelMap.remove(id); | ||
| 135 | + if (globalNodeLabelMap.containsKey(id)) { | ||
| 136 | + return false; | ||
| 137 | + } | ||
| 138 | + return true; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + @Override | ||
| 142 | + public boolean removeAdjLabel(Link link) { | ||
| 143 | + adjLabelMap.remove(link); | ||
| 144 | + if (adjLabelMap.containsKey(link)) { | ||
| 145 | + return false; | ||
| 146 | + } | ||
| 147 | + return true; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @Override | ||
| 151 | + public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) { | ||
| 152 | + // TODO Auto-generated method stub | ||
| 153 | + return false; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + @Override | ||
| 157 | + public boolean removeLsrIdDevice(String lsrId) { | ||
| 158 | + // TODO Auto-generated method stub | ||
| 159 | + return false; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + @Override | ||
| 163 | + public DeviceId getLsrIdDevice(String lsrId) { | ||
| 164 | + // TODO Auto-generated method stub | ||
| 165 | + return null; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + @Override | ||
| 169 | + public boolean addPccLsr(DeviceId lsrId) { | ||
| 170 | + // TODO Auto-generated method stub | ||
| 171 | + return false; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + @Override | ||
| 175 | + public boolean removePccLsr(DeviceId lsrId) { | ||
| 176 | + // TODO Auto-generated method stub | ||
| 177 | + return false; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + @Override | ||
| 181 | + public boolean hasPccLsr(DeviceId lsrId) { | ||
| 182 | + // TODO Auto-generated method stub | ||
| 183 | + return false; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + @Override | ||
| 187 | + public Map<TunnelId, List<LspLocalLabelInfo>> getTunnelInfos() { | ||
| 188 | + return tunnelInfoMap.entrySet().stream() | ||
| 189 | + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue())); | ||
| 190 | + } | ||
| 191 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/PcepClientAdapter.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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import static org.junit.Assert.assertNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.HashMap; | ||
| 21 | +import java.util.List; | ||
| 22 | +import java.util.Map; | ||
| 23 | +import java.util.concurrent.RejectedExecutionException; | ||
| 24 | + | ||
| 25 | +import org.jboss.netty.channel.Channel; | ||
| 26 | +import org.onosproject.pcep.controller.ClientCapability; | ||
| 27 | +import org.onosproject.pcep.controller.PccId; | ||
| 28 | +import org.onosproject.pcep.controller.LspKey; | ||
| 29 | +import org.onosproject.pcep.controller.PcepClient; | ||
| 30 | +import org.onosproject.pcep.controller.PcepSyncStatus; | ||
| 31 | +import org.onosproject.pcepio.protocol.PcepFactories; | ||
| 32 | +import org.onosproject.pcepio.protocol.PcepFactory; | ||
| 33 | +import org.onosproject.pcepio.protocol.PcepMessage; | ||
| 34 | +import org.onosproject.pcepio.protocol.PcepStateReport; | ||
| 35 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | + * Representation of PCEP client adapter. | ||
| 39 | + */ | ||
| 40 | +public class PcepClientAdapter implements PcepClient { | ||
| 41 | + | ||
| 42 | + private Channel channel; | ||
| 43 | + protected String channelId; | ||
| 44 | + | ||
| 45 | + private boolean connected; | ||
| 46 | + private PccId pccId; | ||
| 47 | + private ClientCapability capability; | ||
| 48 | + | ||
| 49 | + private PcepVersion pcepVersion; | ||
| 50 | + private PcepSyncStatus lspDbSyncStatus; | ||
| 51 | + private PcepSyncStatus labelDbSyncStatus; | ||
| 52 | + private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>(); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Initialize instance with specified parameters. | ||
| 56 | + * | ||
| 57 | + * @param pccId PCC id | ||
| 58 | + * @param pcepVersion PCEP message version | ||
| 59 | + */ | ||
| 60 | + public void init(PccId pccId, PcepVersion pcepVersion) { | ||
| 61 | + this.pccId = pccId; | ||
| 62 | + this.pcepVersion = pcepVersion; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public final void disconnectClient() { | ||
| 67 | + this.channel.close(); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public final void sendMessage(PcepMessage m) { | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public final void sendMessage(List<PcepMessage> msgs) { | ||
| 76 | + try { | ||
| 77 | + PcepMessage pcepMsg = msgs.get(0); | ||
| 78 | + assertNotNull("PCEP MSG should be created.", pcepMsg); | ||
| 79 | + } catch (RejectedExecutionException e) { | ||
| 80 | + throw e; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public final boolean isConnected() { | ||
| 86 | + return this.connected; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public String channelId() { | ||
| 91 | + return channelId; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public final PccId getPccId() { | ||
| 96 | + return this.pccId; | ||
| 97 | + }; | ||
| 98 | + | ||
| 99 | + @Override | ||
| 100 | + public final String getStringId() { | ||
| 101 | + return this.pccId.toString(); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + @Override | ||
| 105 | + public final void handleMessage(PcepMessage m) { | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + @Override | ||
| 109 | + public boolean isOptical() { | ||
| 110 | + return false; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + @Override | ||
| 114 | + public PcepFactory factory() { | ||
| 115 | + return PcepFactories.getFactory(pcepVersion); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + @Override | ||
| 119 | + public void setLspDbSyncStatus(PcepSyncStatus syncStatus) { | ||
| 120 | + this.lspDbSyncStatus = syncStatus; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + @Override | ||
| 124 | + public PcepSyncStatus lspDbSyncStatus() { | ||
| 125 | + return lspDbSyncStatus; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + @Override | ||
| 129 | + public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) { | ||
| 130 | + this.labelDbSyncStatus = syncStatus; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + @Override | ||
| 134 | + public PcepSyncStatus labelDbSyncStatus() { | ||
| 135 | + return labelDbSyncStatus; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + @Override | ||
| 139 | + public void setCapability(ClientCapability capability) { | ||
| 140 | + this.capability = capability; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Override | ||
| 144 | + public ClientCapability capability() { | ||
| 145 | + return capability; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public void addNode(PcepClient pc) { | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public void deleteNode(PccId pccId) { | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + @Override | ||
| 157 | + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) { | ||
| 158 | + lspDelegationInfo.put(lspKey, dFlag); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + @Override | ||
| 162 | + public Boolean delegationInfo(LspKey lspKey) { | ||
| 163 | + return lspDelegationInfo.get(lspKey); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + @Override | ||
| 167 | + public void initializeSyncMsgList(PccId pccId) { | ||
| 168 | + // TODO Auto-generated method stub | ||
| 169 | + | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + @Override | ||
| 173 | + public List<PcepStateReport> getSyncMsgList(PccId pccId) { | ||
| 174 | + // TODO Auto-generated method stub | ||
| 175 | + return null; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + @Override | ||
| 179 | + public void removeSyncMsgList(PccId pccId) { | ||
| 180 | + // TODO Auto-generated method stub | ||
| 181 | + | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + @Override | ||
| 185 | + public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) { | ||
| 186 | + // TODO Auto-generated method stub | ||
| 187 | + | ||
| 188 | + } | ||
| 189 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/StorageServiceAdapter.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015-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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import org.onosproject.store.service.AtomicCounterBuilder; | ||
| 19 | +import org.onosproject.store.service.AtomicValueBuilder; | ||
| 20 | +import org.onosproject.store.service.ConsistentMapBuilder; | ||
| 21 | +import org.onosproject.store.service.ConsistentTreeMapBuilder; | ||
| 22 | +import org.onosproject.store.service.DistributedSetBuilder; | ||
| 23 | +import org.onosproject.store.service.EventuallyConsistentMapBuilder; | ||
| 24 | +import org.onosproject.store.service.LeaderElectorBuilder; | ||
| 25 | +import org.onosproject.store.service.Serializer; | ||
| 26 | +import org.onosproject.store.service.StorageService; | ||
| 27 | +import org.onosproject.store.service.Topic; | ||
| 28 | +import org.onosproject.store.service.TransactionContextBuilder; | ||
| 29 | +import org.onosproject.store.service.WorkQueue; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Adapter for the storage service. | ||
| 33 | + */ | ||
| 34 | +public class StorageServiceAdapter implements StorageService { | ||
| 35 | + @Override | ||
| 36 | + public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() { | ||
| 37 | + return null; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public <K, V> ConsistentMapBuilder<K, V> consistentMapBuilder() { | ||
| 42 | + return null; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public <E> DistributedSetBuilder<E> setBuilder() { | ||
| 47 | + return null; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public AtomicCounterBuilder atomicCounterBuilder() { | ||
| 52 | + return null; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public <V> AtomicValueBuilder<V> atomicValueBuilder() { | ||
| 57 | + return null; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public TransactionContextBuilder transactionContextBuilder() { | ||
| 62 | + return null; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public LeaderElectorBuilder leaderElectorBuilder() { | ||
| 67 | + return null; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public <E> WorkQueue<E> getWorkQueue(String name, Serializer serializer) { | ||
| 72 | + return null; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + public <T> Topic<T> getTopic(String name, Serializer serializer) { | ||
| 77 | + // TODO Auto-generated method stub | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public <V> ConsistentTreeMapBuilder<V> consistentTreeMapBuilder() { | ||
| 83 | + // TODO Auto-generated method stub | ||
| 84 | + return null; | ||
| 85 | + } | ||
| 86 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/TestAtomicCounter.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015-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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.concurrent.CompletableFuture; | ||
| 19 | +import java.util.concurrent.atomic.AtomicLong; | ||
| 20 | + | ||
| 21 | +import org.onosproject.store.service.AsyncAtomicCounter; | ||
| 22 | +import org.onosproject.store.service.AtomicCounterBuilder; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * Test implementation of atomic counter. | ||
| 26 | + */ | ||
| 27 | +public final class TestAtomicCounter implements AsyncAtomicCounter { | ||
| 28 | + final AtomicLong value; | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public String name() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + private TestAtomicCounter() { | ||
| 36 | + value = new AtomicLong(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public CompletableFuture<Long> incrementAndGet() { | ||
| 41 | + return CompletableFuture.completedFuture(value.incrementAndGet()); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + public CompletableFuture<Long> getAndIncrement() { | ||
| 46 | + return CompletableFuture.completedFuture(value.getAndIncrement()); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public CompletableFuture<Long> getAndAdd(long delta) { | ||
| 51 | + return CompletableFuture.completedFuture(value.getAndAdd(delta)); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public CompletableFuture<Long> addAndGet(long delta) { | ||
| 56 | + return CompletableFuture.completedFuture(value.addAndGet(delta)); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public CompletableFuture<Void> set(long value) { | ||
| 61 | + this.value.set(value); | ||
| 62 | + return CompletableFuture.completedFuture(null); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public CompletableFuture<Boolean> compareAndSet(long expectedValue, long updateValue) { | ||
| 67 | + return CompletableFuture.completedFuture(value.compareAndSet(expectedValue, updateValue)); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public CompletableFuture<Long> get() { | ||
| 72 | + return CompletableFuture.completedFuture(value.get()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public static AtomicCounterBuilder builder() { | ||
| 76 | + return new Builder(); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public static class Builder extends AtomicCounterBuilder { | ||
| 80 | + @Override | ||
| 81 | + public AsyncAtomicCounter build() { | ||
| 82 | + return new TestAtomicCounter(); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/TestConsistentMap.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015-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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.Collection; | ||
| 19 | +import java.util.HashMap; | ||
| 20 | +import java.util.LinkedList; | ||
| 21 | +import java.util.List; | ||
| 22 | +import java.util.Map; | ||
| 23 | +import java.util.Set; | ||
| 24 | +import java.util.concurrent.atomic.AtomicBoolean; | ||
| 25 | +import java.util.concurrent.atomic.AtomicLong; | ||
| 26 | +import java.util.concurrent.atomic.AtomicReference; | ||
| 27 | +import java.util.function.BiFunction; | ||
| 28 | +import java.util.function.Function; | ||
| 29 | +import java.util.function.Predicate; | ||
| 30 | +import java.util.stream.Collectors; | ||
| 31 | + | ||
| 32 | +import org.onosproject.store.primitives.ConsistentMapBackedJavaMap; | ||
| 33 | +import org.onosproject.store.service.AsyncConsistentMap; | ||
| 34 | +import org.onosproject.store.service.ConsistentMap; | ||
| 35 | +import org.onosproject.store.service.ConsistentMapBuilder; | ||
| 36 | +import org.onosproject.store.service.MapEvent; | ||
| 37 | +import org.onosproject.store.service.MapEventListener; | ||
| 38 | +import org.onosproject.store.service.Versioned; | ||
| 39 | + | ||
| 40 | +import com.google.common.base.Objects; | ||
| 41 | + | ||
| 42 | +/** | ||
| 43 | + * Test implementation of the consistent map. | ||
| 44 | + */ | ||
| 45 | +public final class TestConsistentMap<K, V> extends ConsistentMapAdapter<K, V> { | ||
| 46 | + | ||
| 47 | + private final List<MapEventListener<K, V>> listeners; | ||
| 48 | + private final Map<K, Versioned<V>> map; | ||
| 49 | + private final String mapName; | ||
| 50 | + private final AtomicLong counter = new AtomicLong(0); | ||
| 51 | + | ||
| 52 | + private TestConsistentMap(String mapName) { | ||
| 53 | + map = new HashMap<>(); | ||
| 54 | + listeners = new LinkedList<>(); | ||
| 55 | + this.mapName = mapName; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + private Versioned<V> version(V v) { | ||
| 59 | + return new Versioned<>(v, counter.incrementAndGet(), System.currentTimeMillis()); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Notify all listeners of an event. | ||
| 64 | + */ | ||
| 65 | + private void notifyListeners(String mapName, | ||
| 66 | + K key, Versioned<V> newvalue, Versioned<V> oldValue) { | ||
| 67 | + MapEvent<K, V> event = new MapEvent<>(mapName, key, newvalue, oldValue); | ||
| 68 | + listeners.forEach( | ||
| 69 | + listener -> listener.event(event) | ||
| 70 | + ); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public int size() { | ||
| 75 | + return map.size(); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public boolean isEmpty() { | ||
| 80 | + return map.isEmpty(); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public boolean containsKey(K key) { | ||
| 85 | + return map.containsKey(key); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public boolean containsValue(V value) { | ||
| 90 | + return map.containsValue(value); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public Versioned<V> get(K key) { | ||
| 95 | + return map.get(key); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + @Override | ||
| 99 | + public Versioned<V> computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) { | ||
| 100 | + AtomicBoolean updated = new AtomicBoolean(false); | ||
| 101 | + Versioned<V> result = map.compute(key, (k, v) -> { | ||
| 102 | + if (v == null) { | ||
| 103 | + updated.set(true); | ||
| 104 | + return version(mappingFunction.apply(key)); | ||
| 105 | + } | ||
| 106 | + return v; | ||
| 107 | + }); | ||
| 108 | + if (updated.get()) { | ||
| 109 | + notifyListeners(mapName, key, result, null); | ||
| 110 | + } | ||
| 111 | + return result; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public Versioned<V> compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | ||
| 116 | + AtomicBoolean updated = new AtomicBoolean(false); | ||
| 117 | + AtomicReference<Versioned<V>> previousValue = new AtomicReference<>(); | ||
| 118 | + Versioned<V> result = map.compute(key, (k, v) -> { | ||
| 119 | + updated.set(true); | ||
| 120 | + previousValue.set(v); | ||
| 121 | + return version(remappingFunction.apply(k, Versioned.valueOrNull(v))); | ||
| 122 | + }); | ||
| 123 | + if (updated.get()) { | ||
| 124 | + notifyListeners(mapName, key, result, previousValue.get()); | ||
| 125 | + } | ||
| 126 | + return result; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + @Override | ||
| 130 | + public Versioned<V> computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | ||
| 131 | + AtomicBoolean updated = new AtomicBoolean(false); | ||
| 132 | + AtomicReference<Versioned<V>> previousValue = new AtomicReference<>(); | ||
| 133 | + Versioned<V> result = map.compute(key, (k, v) -> { | ||
| 134 | + if (v != null) { | ||
| 135 | + updated.set(true); | ||
| 136 | + previousValue.set(v); | ||
| 137 | + return version(remappingFunction.apply(k, v.value())); | ||
| 138 | + } | ||
| 139 | + return v; | ||
| 140 | + }); | ||
| 141 | + if (updated.get()) { | ||
| 142 | + notifyListeners(mapName, key, result, previousValue.get()); | ||
| 143 | + } | ||
| 144 | + return result; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public Versioned<V> computeIf(K key, Predicate<? super V> condition, | ||
| 149 | + BiFunction<? super K, ? super V, ? extends V> remappingFunction) { | ||
| 150 | + AtomicBoolean updated = new AtomicBoolean(false); | ||
| 151 | + AtomicReference<Versioned<V>> previousValue = new AtomicReference<>(); | ||
| 152 | + Versioned<V> result = map.compute(key, (k, v) -> { | ||
| 153 | + if (condition.test(Versioned.valueOrNull(v))) { | ||
| 154 | + previousValue.set(v); | ||
| 155 | + updated.set(true); | ||
| 156 | + return version(remappingFunction.apply(k, Versioned.valueOrNull(v))); | ||
| 157 | + } | ||
| 158 | + return v; | ||
| 159 | + }); | ||
| 160 | + if (updated.get()) { | ||
| 161 | + notifyListeners(mapName, key, result, previousValue.get()); | ||
| 162 | + } | ||
| 163 | + return result; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + @Override | ||
| 167 | + public Versioned<V> put(K key, V value) { | ||
| 168 | + Versioned<V> newValue = version(value); | ||
| 169 | + Versioned<V> previousValue = map.put(key, newValue); | ||
| 170 | + notifyListeners(mapName, key, newValue, previousValue); | ||
| 171 | + return previousValue; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + @Override | ||
| 175 | + public Versioned<V> putAndGet(K key, V value) { | ||
| 176 | + Versioned<V> newValue = version(value); | ||
| 177 | + Versioned<V> previousValue = map.put(key, newValue); | ||
| 178 | + notifyListeners(mapName, key, newValue, previousValue); | ||
| 179 | + return newValue; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + @Override | ||
| 183 | + public Versioned<V> remove(K key) { | ||
| 184 | + Versioned<V> result = map.remove(key); | ||
| 185 | + notifyListeners(mapName, key, null, result); | ||
| 186 | + return result; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + @Override | ||
| 190 | + public void clear() { | ||
| 191 | + map.keySet().forEach(this::remove); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + @Override | ||
| 195 | + public Set<K> keySet() { | ||
| 196 | + return map.keySet(); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + @Override | ||
| 200 | + public Collection<Versioned<V>> values() { | ||
| 201 | + return map.values() | ||
| 202 | + .stream() | ||
| 203 | + .collect(Collectors.toList()); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + @Override | ||
| 207 | + public Set<Map.Entry<K, Versioned<V>>> entrySet() { | ||
| 208 | + return map.entrySet(); | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + @Override | ||
| 212 | + public Versioned<V> putIfAbsent(K key, V value) { | ||
| 213 | + Versioned<V> newValue = version(value); | ||
| 214 | + Versioned<V> result = map.putIfAbsent(key, newValue); | ||
| 215 | + if (result == null) { | ||
| 216 | + notifyListeners(mapName, key, newValue, result); | ||
| 217 | + } | ||
| 218 | + return result; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + @Override | ||
| 222 | + public boolean remove(K key, V value) { | ||
| 223 | + Versioned<V> existingValue = map.get(key); | ||
| 224 | + if (Objects.equal(Versioned.valueOrNull(existingValue), value)) { | ||
| 225 | + map.remove(key); | ||
| 226 | + notifyListeners(mapName, key, null, existingValue); | ||
| 227 | + return true; | ||
| 228 | + } | ||
| 229 | + return false; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + @Override | ||
| 233 | + public boolean remove(K key, long version) { | ||
| 234 | + Versioned<V> existingValue = map.get(key); | ||
| 235 | + if (existingValue == null) { | ||
| 236 | + return false; | ||
| 237 | + } | ||
| 238 | + if (existingValue.version() == version) { | ||
| 239 | + map.remove(key); | ||
| 240 | + notifyListeners(mapName, key, null, existingValue); | ||
| 241 | + return true; | ||
| 242 | + } | ||
| 243 | + return false; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + @Override | ||
| 247 | + public Versioned<V> replace(K key, V value) { | ||
| 248 | + Versioned<V> existingValue = map.get(key); | ||
| 249 | + if (existingValue == null) { | ||
| 250 | + return null; | ||
| 251 | + } | ||
| 252 | + Versioned<V> newValue = version(value); | ||
| 253 | + Versioned<V> result = map.put(key, newValue); | ||
| 254 | + notifyListeners(mapName, key, newValue, result); | ||
| 255 | + return result; | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + @Override | ||
| 259 | + public boolean replace(K key, V oldValue, V newValue) { | ||
| 260 | + Versioned<V> existingValue = map.get(key); | ||
| 261 | + if (existingValue == null || !existingValue.value().equals(oldValue)) { | ||
| 262 | + return false; | ||
| 263 | + } | ||
| 264 | + Versioned<V> value = version(newValue); | ||
| 265 | + Versioned<V> result = map.put(key, value); | ||
| 266 | + notifyListeners(mapName, key, value, result); | ||
| 267 | + return true; | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + @Override | ||
| 271 | + public boolean replace(K key, long oldVersion, V newValue) { | ||
| 272 | + Versioned<V> existingValue = map.get(key); | ||
| 273 | + if (existingValue == null || existingValue.version() != oldVersion) { | ||
| 274 | + return false; | ||
| 275 | + } | ||
| 276 | + Versioned<V> value = version(newValue); | ||
| 277 | + Versioned<V> result = map.put(key, value); | ||
| 278 | + notifyListeners(mapName, key, value, result); | ||
| 279 | + return true; | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + @Override | ||
| 283 | + public void addListener(MapEventListener<K, V> listener) { | ||
| 284 | + listeners.add(listener); | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + @Override | ||
| 288 | + public void removeListener(MapEventListener<K, V> listener) { | ||
| 289 | + listeners.remove(listener); | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + @Override | ||
| 293 | + public Map<K, V> asJavaMap() { | ||
| 294 | + return new ConsistentMapBackedJavaMap<>(this); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + public static Builder builder() { | ||
| 298 | + return new Builder(); | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + public static class Builder<K, V> extends ConsistentMapBuilder<K, V> { | ||
| 302 | + | ||
| 303 | + @Override | ||
| 304 | + public ConsistentMap<K, V> build() { | ||
| 305 | + return new TestConsistentMap<>(name()); | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + @Override | ||
| 309 | + public AsyncConsistentMap<K, V> buildAsyncMap() { | ||
| 310 | + return null; | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/TestDistributedSet.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 | + | ||
| 17 | +package org.onosproject.pcelabelstore.util; | ||
| 18 | + | ||
| 19 | +import com.google.common.collect.ImmutableSet; | ||
| 20 | +import com.google.common.collect.Sets; | ||
| 21 | +import org.onosproject.store.primitives.DefaultDistributedSet; | ||
| 22 | +import org.onosproject.store.service.AsyncDistributedSet; | ||
| 23 | +import org.onosproject.store.service.DistributedSet; | ||
| 24 | +import org.onosproject.store.service.DistributedSetBuilder; | ||
| 25 | +import org.onosproject.store.service.SetEvent; | ||
| 26 | +import org.onosproject.store.service.SetEventListener; | ||
| 27 | + | ||
| 28 | +import java.util.Collection; | ||
| 29 | +import java.util.HashSet; | ||
| 30 | +import java.util.LinkedList; | ||
| 31 | +import java.util.List; | ||
| 32 | +import java.util.Set; | ||
| 33 | +import java.util.concurrent.CompletableFuture; | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + * Test implementation of the distributed set. | ||
| 37 | + */ | ||
| 38 | +public final class TestDistributedSet<E> extends DistributedSetAdapter<E> { | ||
| 39 | + private final List<SetEventListener<E>> listeners; | ||
| 40 | + private final Set<E> set; | ||
| 41 | + private final String setName; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Public constructor. | ||
| 45 | + * | ||
| 46 | + * @param setName name to be assigned to this set | ||
| 47 | + */ | ||
| 48 | + public TestDistributedSet(String setName) { | ||
| 49 | + set = new HashSet<>(); | ||
| 50 | + listeners = new LinkedList<>(); | ||
| 51 | + this.setName = setName; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Notify all listeners of a set event. | ||
| 56 | + * | ||
| 57 | + * @param event the SetEvent | ||
| 58 | + */ | ||
| 59 | + private void notifyListeners(SetEvent<E> event) { | ||
| 60 | + listeners.forEach( | ||
| 61 | + listener -> listener.event(event) | ||
| 62 | + ); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public CompletableFuture<Void> addListener(SetEventListener<E> listener) { | ||
| 67 | + listeners.add(listener); | ||
| 68 | + return CompletableFuture.completedFuture(null); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public CompletableFuture<Void> removeListener(SetEventListener<E> listener) { | ||
| 73 | + listeners.remove(listener); | ||
| 74 | + return CompletableFuture.completedFuture(null); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public CompletableFuture<Boolean> add(E element) { | ||
| 79 | + SetEvent<E> event = | ||
| 80 | + new SetEvent<>(setName, SetEvent.Type.ADD, element); | ||
| 81 | + notifyListeners(event); | ||
| 82 | + return CompletableFuture.completedFuture(set.add(element)); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public CompletableFuture<Boolean> remove(E element) { | ||
| 87 | + SetEvent<E> event = | ||
| 88 | + new SetEvent<>(setName, SetEvent.Type.REMOVE, element); | ||
| 89 | + notifyListeners(event); | ||
| 90 | + return CompletableFuture.completedFuture(set.remove(element)); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public CompletableFuture<Integer> size() { | ||
| 95 | + return CompletableFuture.completedFuture(set.size()); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + @Override | ||
| 99 | + public CompletableFuture<Boolean> isEmpty() { | ||
| 100 | + return CompletableFuture.completedFuture(set.isEmpty()); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + @Override | ||
| 104 | + public CompletableFuture<Void> clear() { | ||
| 105 | + removeAll(ImmutableSet.copyOf(set)); | ||
| 106 | + return CompletableFuture.completedFuture(null); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + public CompletableFuture<Boolean> contains(E element) { | ||
| 111 | + return CompletableFuture.completedFuture(set.contains(element)); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public CompletableFuture<Boolean> addAll(Collection<? extends E> c) { | ||
| 116 | + c.forEach(this::add); | ||
| 117 | + return CompletableFuture.completedFuture(true); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Override | ||
| 121 | + public CompletableFuture<Boolean> containsAll(Collection<? extends E> c) { | ||
| 122 | + return CompletableFuture.completedFuture(set.containsAll(c)); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public CompletableFuture<Boolean> retainAll(Collection<? extends E> c) { | ||
| 127 | + Set notInSet2; | ||
| 128 | + notInSet2 = Sets.difference(set, (Set<?>) c); | ||
| 129 | + return removeAll(ImmutableSet.copyOf(notInSet2)); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public CompletableFuture<Boolean> removeAll(Collection<? extends E> c) { | ||
| 134 | + c.forEach(this::remove); | ||
| 135 | + return CompletableFuture.completedFuture(true); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + @Override | ||
| 139 | + public CompletableFuture<? extends Set<E>> getAsImmutableSet() { | ||
| 140 | + return CompletableFuture.completedFuture(ImmutableSet.copyOf(set)); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + @Override | ||
| 144 | + public String name() { | ||
| 145 | + return this.setName; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public DistributedSet<E> asDistributedSet() { | ||
| 150 | + return new DefaultDistributedSet<>(this, 0); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + @Override | ||
| 154 | + public DistributedSet<E> asDistributedSet(long timeoutMillis) { | ||
| 155 | + return new DefaultDistributedSet<>(this, timeoutMillis); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * Returns a new Builder instance. | ||
| 160 | + * | ||
| 161 | + * @return Builder | ||
| 162 | + **/ | ||
| 163 | + public static Builder builder() { | ||
| 164 | + return new Builder(); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + /** | ||
| 168 | + * Builder constructor that instantiates a TestDistributedSet. | ||
| 169 | + * | ||
| 170 | + * @param <E> | ||
| 171 | + */ | ||
| 172 | + public static class Builder<E> extends DistributedSetBuilder<E> { | ||
| 173 | + @Override | ||
| 174 | + public AsyncDistributedSet<E> build() { | ||
| 175 | + return new TestDistributedSet(name()); | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | +} |
protocols/pcep/ctl/src/test/java/org/onosproject/pcelabelstore/util/TestEventuallyConsistentMap.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015-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.pcelabelstore.util; | ||
| 17 | + | ||
| 18 | +import java.util.Collection; | ||
| 19 | +import java.util.HashMap; | ||
| 20 | +import java.util.LinkedList; | ||
| 21 | +import java.util.List; | ||
| 22 | +import java.util.Map; | ||
| 23 | +import java.util.Set; | ||
| 24 | +import java.util.concurrent.ExecutorService; | ||
| 25 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 26 | +import java.util.concurrent.TimeUnit; | ||
| 27 | +import java.util.function.BiFunction; | ||
| 28 | + | ||
| 29 | +import org.onlab.util.KryoNamespace; | ||
| 30 | +import org.onosproject.cluster.NodeId; | ||
| 31 | +import org.onosproject.store.Timestamp; | ||
| 32 | +import org.onosproject.store.service.EventuallyConsistentMap; | ||
| 33 | +import org.onosproject.store.service.EventuallyConsistentMapBuilder; | ||
| 34 | +import org.onosproject.store.service.EventuallyConsistentMapEvent; | ||
| 35 | +import org.onosproject.store.service.EventuallyConsistentMapListener; | ||
| 36 | + | ||
| 37 | +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; | ||
| 38 | +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; | ||
| 39 | + | ||
| 40 | +/** | ||
| 41 | + * Testing version of an Eventually Consistent Map. | ||
| 42 | + */ | ||
| 43 | + | ||
| 44 | +public final class TestEventuallyConsistentMap<K, V> extends EventuallyConsistentMapAdapter<K, V> { | ||
| 45 | + | ||
| 46 | + private final HashMap<K, V> map; | ||
| 47 | + private final String mapName; | ||
| 48 | + private final List<EventuallyConsistentMapListener<K, V>> listeners; | ||
| 49 | + private final BiFunction<K, V, Collection<NodeId>> peerUpdateFunction; | ||
| 50 | + | ||
| 51 | + private TestEventuallyConsistentMap(String mapName, | ||
| 52 | + BiFunction<K, V, Collection<NodeId>> peerUpdateFunction) { | ||
| 53 | + map = new HashMap<>(); | ||
| 54 | + listeners = new LinkedList<>(); | ||
| 55 | + this.mapName = mapName; | ||
| 56 | + this.peerUpdateFunction = peerUpdateFunction; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Notify all listeners of an event. | ||
| 61 | + */ | ||
| 62 | + private void notifyListeners(EventuallyConsistentMapEvent<K, V> event) { | ||
| 63 | + listeners.forEach( | ||
| 64 | + listener -> listener.event(event) | ||
| 65 | + ); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public int size() { | ||
| 70 | + return map.size(); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public boolean isEmpty() { | ||
| 75 | + return map.isEmpty(); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public boolean containsKey(K key) { | ||
| 80 | + return map.containsKey(key); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public boolean containsValue(V value) { | ||
| 85 | + return map.containsValue(value); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public V get(K key) { | ||
| 90 | + return map.get(key); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public void put(K key, V value) { | ||
| 95 | + map.put(key, value); | ||
| 96 | + EventuallyConsistentMapEvent<K, V> addEvent = | ||
| 97 | + new EventuallyConsistentMapEvent<>(mapName, PUT, key, value); | ||
| 98 | + notifyListeners(addEvent); | ||
| 99 | + if (peerUpdateFunction != null) { | ||
| 100 | + peerUpdateFunction.apply(key, value); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + @Override | ||
| 105 | + public V remove(K key) { | ||
| 106 | + V result = map.remove(key); | ||
| 107 | + if (result != null) { | ||
| 108 | + EventuallyConsistentMapEvent<K, V> removeEvent = | ||
| 109 | + new EventuallyConsistentMapEvent<>(mapName, REMOVE, | ||
| 110 | + key, map.get(key)); | ||
| 111 | + notifyListeners(removeEvent); | ||
| 112 | + } | ||
| 113 | + return result; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + @Override | ||
| 117 | + public void remove(K key, V value) { | ||
| 118 | + boolean removed = map.remove(key, value); | ||
| 119 | + if (removed) { | ||
| 120 | + EventuallyConsistentMapEvent<K, V> removeEvent = | ||
| 121 | + new EventuallyConsistentMapEvent<>(mapName, REMOVE, key, value); | ||
| 122 | + notifyListeners(removeEvent); | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + @Override | ||
| 127 | + public V compute(K key, BiFunction<K, V, V> recomputeFunction) { | ||
| 128 | + return map.compute(key, recomputeFunction); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public void putAll(Map<? extends K, ? extends V> m) { | ||
| 133 | + map.putAll(m); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @Override | ||
| 137 | + public void clear() { | ||
| 138 | + map.clear(); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + @Override | ||
| 142 | + public Set<K> keySet() { | ||
| 143 | + return map.keySet(); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + @Override | ||
| 147 | + public Collection<V> values() { | ||
| 148 | + return map.values(); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + @Override | ||
| 152 | + public Set<Map.Entry<K, V>> entrySet() { | ||
| 153 | + return map.entrySet(); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public static <K, V> Builder<K, V> builder() { | ||
| 157 | + return new Builder<>(); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + @Override | ||
| 161 | + public void addListener(EventuallyConsistentMapListener<K, V> listener) { | ||
| 162 | + listeners.add(listener); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + @Override | ||
| 166 | + public void removeListener(EventuallyConsistentMapListener<K, V> listener) { | ||
| 167 | + listeners.remove(listener); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public static class Builder<K, V> implements EventuallyConsistentMapBuilder<K, V> { | ||
| 171 | + private String name; | ||
| 172 | + private BiFunction<K, V, Collection<NodeId>> peerUpdateFunction; | ||
| 173 | + | ||
| 174 | + @Override | ||
| 175 | + public EventuallyConsistentMapBuilder<K, V> withName(String name) { | ||
| 176 | + this.name = name; | ||
| 177 | + return this; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + @Override | ||
| 181 | + public EventuallyConsistentMapBuilder<K, V> withSerializer(KryoNamespace.Builder serializerBuilder) { | ||
| 182 | + return this; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 186 | + public EventuallyConsistentMapBuilder<K, V> withSerializer(KryoNamespace serializer) { | ||
| 187 | + return this; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + @Override | ||
| 191 | + public EventuallyConsistentMapBuilder<K, V> | ||
| 192 | + withTimestampProvider(BiFunction<K, V, Timestamp> timestampProvider) { | ||
| 193 | + return this; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + @Override | ||
| 197 | + public EventuallyConsistentMapBuilder<K, V> withEventExecutor(ExecutorService executor) { | ||
| 198 | + return this; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + @Override | ||
| 202 | + public EventuallyConsistentMapBuilder<K, V> withCommunicationExecutor(ExecutorService executor) { | ||
| 203 | + return this; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + @Override | ||
| 207 | + public EventuallyConsistentMapBuilder<K, V> withBackgroundExecutor(ScheduledExecutorService executor) { | ||
| 208 | + return this; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + @Override | ||
| 212 | + public EventuallyConsistentMapBuilder<K, V> | ||
| 213 | + withPeerUpdateFunction(BiFunction<K, V, Collection<NodeId>> peerUpdateFunction) { | ||
| 214 | + this.peerUpdateFunction = peerUpdateFunction; | ||
| 215 | + return this; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + @Override | ||
| 219 | + public EventuallyConsistentMapBuilder<K, V> withTombstonesDisabled() { | ||
| 220 | + return this; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + @Override | ||
| 224 | + public EventuallyConsistentMapBuilder<K, V> withAntiEntropyPeriod(long period, TimeUnit unit) { | ||
| 225 | + return this; | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + @Override | ||
| 229 | + public EventuallyConsistentMapBuilder<K, V> withFasterConvergence() { | ||
| 230 | + return this; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + @Override | ||
| 234 | + public EventuallyConsistentMapBuilder<K, V> withPersistence() { | ||
| 235 | + return this; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + @Override | ||
| 239 | + public EventuallyConsistentMap<K, V> build() { | ||
| 240 | + if (name == null) { | ||
| 241 | + name = "test"; | ||
| 242 | + } | ||
| 243 | + return new TestEventuallyConsistentMap<>(name, peerUpdateFunction); | ||
| 244 | + } | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | +} | ||
| 248 | + |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2016-present Open Networking Laboratory | 2 | + * Copyright 2015-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -13,58 +13,45 @@ | ... | @@ -13,58 +13,45 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.pce.util; | 16 | +package org.onosproject.pcelabelstore.util; |
| 17 | 17 | ||
| 18 | -import java.util.List; | 18 | +import org.onosproject.store.service.AtomicCounterBuilder; |
| 19 | -import com.google.common.collect.ImmutableList; | 19 | +import org.onosproject.store.service.AtomicValueBuilder; |
| 20 | -import org.onosproject.net.DeviceId; | 20 | +import org.onosproject.store.service.ConsistentMapBuilder; |
| 21 | -import org.onosproject.net.flowobjective.FilteringObjective; | 21 | +import org.onosproject.store.service.DistributedSetBuilder; |
| 22 | -import org.onosproject.net.flowobjective.FlowObjectiveService; | 22 | +import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
| 23 | -import org.onosproject.net.flowobjective.ForwardingObjective; | 23 | +import org.onosproject.store.service.TransactionContextBuilder; |
| 24 | -import org.onosproject.net.flowobjective.NextObjective; | ||
| 25 | 24 | ||
| 26 | -/** | 25 | +public class TestStorageService extends StorageServiceAdapter { |
| 27 | - * Test implementation of FlowObjectiveService. | ||
| 28 | - */ | ||
| 29 | -public class FlowObjServiceAdapter implements FlowObjectiveService { | ||
| 30 | - | ||
| 31 | - private ForwardingObjective forwardingObjective; | ||
| 32 | - @Override | ||
| 33 | - public void filter(DeviceId deviceId, FilteringObjective filteringObjective) { | ||
| 34 | 26 | ||
| 35 | - } | ||
| 36 | 27 | ||
| 37 | @Override | 28 | @Override |
| 38 | - public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { | 29 | + public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() { |
| 39 | - this.forwardingObjective = forwardingObjective; | 30 | + return TestEventuallyConsistentMap.builder(); |
| 40 | } | 31 | } |
| 41 | 32 | ||
| 42 | @Override | 33 | @Override |
| 43 | - public void next(DeviceId deviceId, NextObjective nextObjective) { | 34 | + public <K, V> ConsistentMapBuilder<K, V> consistentMapBuilder() { |
| 44 | - | 35 | + return TestConsistentMap.builder(); |
| 45 | } | 36 | } |
| 46 | 37 | ||
| 47 | @Override | 38 | @Override |
| 48 | - public int allocateNextId() { | 39 | + public <E> DistributedSetBuilder<E> setBuilder() { |
| 49 | - return 0; | 40 | + return TestDistributedSet.builder(); |
| 50 | } | 41 | } |
| 51 | 42 | ||
| 52 | @Override | 43 | @Override |
| 53 | - public void initPolicy(String policy) { | 44 | + public AtomicCounterBuilder atomicCounterBuilder() { |
| 54 | - | 45 | + return TestAtomicCounter.builder(); |
| 55 | - } | ||
| 56 | - | ||
| 57 | - public ForwardingObjective forwardingObjective() { | ||
| 58 | - return forwardingObjective; | ||
| 59 | } | 46 | } |
| 60 | 47 | ||
| 61 | @Override | 48 | @Override |
| 62 | - public List<String> getNextMappings() { | 49 | + public <V> AtomicValueBuilder<V> atomicValueBuilder() { |
| 63 | - return ImmutableList.of(); | 50 | + throw new UnsupportedOperationException("atomicValueBuilder"); |
| 64 | } | 51 | } |
| 65 | 52 | ||
| 66 | @Override | 53 | @Override |
| 67 | - public List<String> getPendingNexts() { | 54 | + public TransactionContextBuilder transactionContextBuilder() { |
| 68 | - return ImmutableList.of(); | 55 | + throw new UnsupportedOperationException("transactionContextBuilder"); |
| 69 | } | 56 | } |
| 70 | } | 57 | } | ... | ... |
| ... | @@ -366,7 +366,6 @@ public class PcepLspObjectVer1 implements PcepLspObject { | ... | @@ -366,7 +366,6 @@ public class PcepLspObjectVer1 implements PcepLspObject { |
| 366 | default: | 366 | default: |
| 367 | // Skip the unknown TLV. | 367 | // Skip the unknown TLV. |
| 368 | cb.skipBytes(hLength); | 368 | cb.skipBytes(hLength); |
| 369 | - tlv = null; | ||
| 370 | log.info("Received unsupported TLV type :" + hType + " in LSP object."); | 369 | log.info("Received unsupported TLV type :" + hType + " in LSP object."); |
| 371 | } | 370 | } |
| 372 | // Check for the padding | 371 | // Check for the padding | ... | ... |
| ... | @@ -22,6 +22,15 @@ | ... | @@ -22,6 +22,15 @@ |
| 22 | <artifact>mvn:${project.groupId}/onos-bgpio/${project.version}</artifact> | 22 | <artifact>mvn:${project.groupId}/onos-bgpio/${project.version}</artifact> |
| 23 | <artifact>mvn:${project.groupId}/onos-bgp-api/${project.version}</artifact> | 23 | <artifact>mvn:${project.groupId}/onos-bgp-api/${project.version}</artifact> |
| 24 | <artifact>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</artifact> | 24 | <artifact>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</artifact> |
| 25 | + <artifact>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</artifact> | ||
| 25 | <artifact>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</artifact> | 26 | <artifact>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</artifact> |
| 26 | <artifact>mvn:${project.groupId}/onos-bgp-provider-cfg/${project.version}</artifact> | 27 | <artifact>mvn:${project.groupId}/onos-bgp-provider-cfg/${project.version}</artifact> |
| 28 | + <artifact>mvn:${project.groupId}/onos-pcepio/${project.version}</artifact> | ||
| 29 | + <artifact>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</artifact> | ||
| 30 | + <artifact>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</artifact> | ||
| 31 | + <artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact> | ||
| 32 | + <artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact> | ||
| 33 | + <artifact>mvn:${project.groupId}/onos-app-pce/${project.version}</artifact> | ||
| 34 | + <artifact>mvn:${project.groupId}/onos-app-pceweb/${project.version}</artifact> | ||
| 35 | + <artifact>mvn:${project.groupId}/onos-app-pcerest/${project.version}</artifact> | ||
| 27 | </app> | 36 | </app> | ... | ... |
| ... | @@ -21,7 +21,16 @@ | ... | @@ -21,7 +21,16 @@ |
| 21 | <bundle>mvn:${project.groupId}/onos-bgpio/${project.version}</bundle> | 21 | <bundle>mvn:${project.groupId}/onos-bgpio/${project.version}</bundle> |
| 22 | <bundle>mvn:${project.groupId}/onos-bgp-api/${project.version}</bundle> | 22 | <bundle>mvn:${project.groupId}/onos-bgp-api/${project.version}</bundle> |
| 23 | <bundle>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</bundle> | 23 | <bundle>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</bundle> |
| 24 | + <bundle>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</bundle> | ||
| 24 | <bundle>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</bundle> | 25 | <bundle>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</bundle> |
| 25 | <bundle>mvn:${project.groupId}/onos-bgp-provider-cfg/${project.version}</bundle> | 26 | <bundle>mvn:${project.groupId}/onos-bgp-provider-cfg/${project.version}</bundle> |
| 27 | + <bundle>mvn:${project.groupId}/onos-pcepio/${project.version}</bundle> | ||
| 28 | + <bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle> | ||
| 29 | + <bundle>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</bundle> | ||
| 30 | + <bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle> | ||
| 31 | + <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle> | ||
| 32 | + <bundle>mvn:${project.groupId}/onos-app-pce/${project.version}</bundle> | ||
| 33 | + <bundle>mvn:${project.groupId}/onos-app-pceweb/${project.version}</bundle> | ||
| 34 | + <bundle>mvn:${project.groupId}/onos-app-pcerest/${project.version}</bundle> | ||
| 26 | </feature> | 35 | </feature> |
| 27 | </features> | 36 | </features> | ... | ... |
| ... | @@ -46,5 +46,20 @@ | ... | @@ -46,5 +46,20 @@ |
| 46 | <artifactId>onos-bgp-provider-topology</artifactId> | 46 | <artifactId>onos-bgp-provider-topology</artifactId> |
| 47 | <version>${project.version}</version> | 47 | <version>${project.version}</version> |
| 48 | </dependency> | 48 | </dependency> |
| 49 | + <dependency> | ||
| 50 | + <groupId>org.onosproject</groupId> | ||
| 51 | + <artifactId>onos-app-pce</artifactId> | ||
| 52 | + <version>${project.version}</version> | ||
| 53 | + </dependency> | ||
| 54 | + <dependency> | ||
| 55 | + <groupId>org.onosproject</groupId> | ||
| 56 | + <artifactId>onos-app-pceweb</artifactId> | ||
| 57 | + <version>${project.version}</version> | ||
| 58 | + </dependency> | ||
| 59 | + <dependency> | ||
| 60 | + <groupId>org.onosproject</groupId> | ||
| 61 | + <artifactId>onos-app-pcerest</artifactId> | ||
| 62 | + <version>${project.version}</version> | ||
| 63 | + </dependency> | ||
| 49 | </dependencies> | 64 | </dependencies> |
| 50 | </project> | 65 | </project> | ... | ... |
| ... | @@ -10,7 +10,6 @@ BUNDLES = [ | ... | @@ -10,7 +10,6 @@ BUNDLES = [ |
| 10 | '//protocols/pcep/ctl:onos-protocols-pcep-ctl', | 10 | '//protocols/pcep/ctl:onos-protocols-pcep-ctl', |
| 11 | '//providers/pcep/topology:onos-providers-pcep-topology', | 11 | '//providers/pcep/topology:onos-providers-pcep-topology', |
| 12 | '//providers/pcep/tunnel:onos-providers-pcep-tunnel', | 12 | '//providers/pcep/tunnel:onos-providers-pcep-tunnel', |
| 13 | - '//providers/pcep/packet:onos-providers-pcep-packet', | ||
| 14 | '//providers/bgpcep/flow:onos-providers-bgpcep-flow', | 13 | '//providers/bgpcep/flow:onos-providers-bgpcep-flow', |
| 15 | '//apps/pce/app:onos-apps-pce-app', | 14 | '//apps/pce/app:onos-apps-pce-app', |
| 16 | '//apps/pce/pceweb:onos-apps-pce-pceweb', | 15 | '//apps/pce/pceweb:onos-apps-pce-pceweb', | ... | ... |
| ... | @@ -30,7 +30,6 @@ | ... | @@ -30,7 +30,6 @@ |
| 30 | <artifact>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</artifact> | 30 | <artifact>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</artifact> |
| 31 | <artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact> | 31 | <artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact> |
| 32 | <artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact> | 32 | <artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact> |
| 33 | - <artifact>mvn:${project.groupId}/onos-pcep-provider-packet/${project.version}</artifact> | ||
| 34 | <artifact>mvn:${project.groupId}/onos-bgpcep-provider-flow/${project.version}</artifact> | 33 | <artifact>mvn:${project.groupId}/onos-bgpcep-provider-flow/${project.version}</artifact> |
| 35 | <artifact>mvn:${project.groupId}/onos-app-pce/${project.version}</artifact> | 34 | <artifact>mvn:${project.groupId}/onos-app-pce/${project.version}</artifact> |
| 36 | <artifact>mvn:${project.groupId}/onos-app-pceweb/${project.version}</artifact> | 35 | <artifact>mvn:${project.groupId}/onos-app-pceweb/${project.version}</artifact> | ... | ... |
| ... | @@ -31,7 +31,6 @@ | ... | @@ -31,7 +31,6 @@ |
| 31 | <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle> | 31 | <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle> |
| 32 | <bundle>mvn:${project.groupId}/onos-app-pce/${project.version}</bundle> | 32 | <bundle>mvn:${project.groupId}/onos-app-pce/${project.version}</bundle> |
| 33 | <bundle>mvn:${project.groupId}/onos-app-pceweb/${project.version}</bundle> | 33 | <bundle>mvn:${project.groupId}/onos-app-pceweb/${project.version}</bundle> |
| 34 | - <bundle>mvn:${project.groupId}/onos-pcep-provider-packet/${project.version}</bundle> | ||
| 35 | <bundle>mvn:${project.groupId}/onos-bgpcep-provider-flow/${project.version}</bundle> | 34 | <bundle>mvn:${project.groupId}/onos-bgpcep-provider-flow/${project.version}</bundle> |
| 36 | <bundle>mvn:${project.groupId}/onos-app-pcerest/${project.version}</bundle> | 35 | <bundle>mvn:${project.groupId}/onos-app-pcerest/${project.version}</bundle> |
| 37 | </feature> | 36 | </feature> | ... | ... |
| ... | @@ -15,95 +15,22 @@ | ... | @@ -15,95 +15,22 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.bgpcep.flow.impl; | 16 | package org.onosproject.provider.bgpcep.flow.impl; |
| 17 | 17 | ||
| 18 | -import java.util.ArrayList; | ||
| 19 | -import java.util.Collection; | ||
| 20 | -import java.util.Collections; | ||
| 21 | -import java.util.LinkedList; | ||
| 22 | -import java.util.List; | ||
| 23 | - | ||
| 24 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Component; | 19 | import org.apache.felix.scr.annotations.Component; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 27 | import org.apache.felix.scr.annotations.Reference; | 21 | import org.apache.felix.scr.annotations.Reference; |
| 28 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 29 | -import org.onlab.packet.Ip4Address; | ||
| 30 | -import org.onlab.packet.IpAddress; | ||
| 31 | -import org.onlab.packet.IpPrefix; | ||
| 32 | -import org.onlab.packet.MplsLabel; | ||
| 33 | -import org.onosproject.bgp.controller.BgpController; | ||
| 34 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
| 35 | -import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 36 | -import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 37 | -import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 38 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 39 | -import org.onosproject.incubator.net.tunnel.TunnelService; | ||
| 40 | -import org.onosproject.net.ConnectPoint; | ||
| 41 | -import org.onosproject.net.Device; | ||
| 42 | -import org.onosproject.net.DeviceId; | ||
| 43 | -import org.onosproject.net.Link; | ||
| 44 | -import org.onosproject.net.Path; | ||
| 45 | -import org.onosproject.net.PortNumber; | ||
| 46 | -import org.onosproject.net.device.DeviceService; | ||
| 47 | -import org.onosproject.net.flow.CompletedBatchOperation; | ||
| 48 | -import org.onosproject.net.flow.DefaultFlowEntry; | ||
| 49 | -import org.onosproject.net.flow.FlowEntry; | ||
| 50 | import org.onosproject.net.flow.FlowRule; | 24 | import org.onosproject.net.flow.FlowRule; |
| 51 | -import org.onosproject.net.flow.FlowRuleBatchEntry; | ||
| 52 | import org.onosproject.net.flow.FlowRuleBatchOperation; | 25 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 53 | import org.onosproject.net.flow.FlowRuleProvider; | 26 | import org.onosproject.net.flow.FlowRuleProvider; |
| 54 | import org.onosproject.net.flow.FlowRuleProviderRegistry; | 27 | import org.onosproject.net.flow.FlowRuleProviderRegistry; |
| 55 | import org.onosproject.net.flow.FlowRuleProviderService; | 28 | import org.onosproject.net.flow.FlowRuleProviderService; |
| 56 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 57 | -import org.onosproject.net.flow.FlowEntry.FlowEntryState; | ||
| 58 | -import org.onosproject.net.flow.criteria.Criterion; | ||
| 59 | -import org.onosproject.net.flow.criteria.IPCriterion; | ||
| 60 | -import org.onosproject.net.flow.criteria.MetadataCriterion; | ||
| 61 | -import org.onosproject.net.flow.criteria.MplsBosCriterion; | ||
| 62 | -import org.onosproject.net.flow.criteria.MplsCriterion; | ||
| 63 | -import org.onosproject.net.flow.criteria.PortCriterion; | ||
| 64 | -import org.onosproject.net.flow.criteria.TunnelIdCriterion; | ||
| 65 | import org.onosproject.net.provider.AbstractProvider; | 29 | import org.onosproject.net.provider.AbstractProvider; |
| 66 | import org.onosproject.net.provider.ProviderId; | 30 | import org.onosproject.net.provider.ProviderId; |
| 67 | -import org.onosproject.net.resource.ResourceService; | ||
| 68 | -import org.onosproject.pcep.controller.PccId; | ||
| 69 | -import org.onosproject.pcep.controller.PcepClient; | ||
| 70 | -import org.onosproject.pcep.controller.PcepClientController; | ||
| 71 | -import org.onosproject.pcepio.exceptions.PcepParseException; | ||
| 72 | -import org.onosproject.pcepio.protocol.PcepEroObject; | ||
| 73 | -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4; | ||
| 74 | -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; | ||
| 75 | -import org.onosproject.pcepio.protocol.PcepLabelObject; | ||
| 76 | -import org.onosproject.pcepio.protocol.PcepLabelUpdate; | ||
| 77 | -import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; | ||
| 78 | -import org.onosproject.pcepio.protocol.PcepLspObject; | ||
| 79 | -import org.onosproject.pcepio.protocol.PcepMsgPath; | ||
| 80 | -import org.onosproject.pcepio.protocol.PcepSrpObject; | ||
| 81 | -import org.onosproject.pcepio.protocol.PcepUpdateMsg; | ||
| 82 | -import org.onosproject.pcepio.protocol.PcepUpdateRequest; | ||
| 83 | -import org.onosproject.pcepio.types.IPv4SubObject; | ||
| 84 | -import org.onosproject.pcepio.types.NexthopIPv4addressTlv; | ||
| 85 | -import org.onosproject.pcepio.types.PathSetupTypeTlv; | ||
| 86 | -import org.onosproject.pcepio.types.PcepLabelDownload; | ||
| 87 | -import org.onosproject.pcepio.types.PcepLabelMap; | ||
| 88 | -import org.onosproject.pcepio.types.PcepValueType; | ||
| 89 | -import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; | ||
| 90 | -import org.onosproject.pcepio.types.SymbolicPathNameTlv; | ||
| 91 | -import org.onosproject.pcep.controller.LspType; | ||
| 92 | -import org.onosproject.pcepio.protocol.PcepAttribute; | ||
| 93 | -import org.onosproject.pcepio.protocol.PcepBandwidthObject; | ||
| 94 | -import org.onosproject.pcep.controller.SrpIdGenerators; | ||
| 95 | -import org.onosproject.pcep.controller.PcepAnnotationKeys; | ||
| 96 | import org.osgi.service.component.ComponentContext; | 31 | import org.osgi.service.component.ComponentContext; |
| 97 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
| 98 | 33 | ||
| 99 | -import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH; | ||
| 100 | -import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE; | ||
| 101 | -import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE; | ||
| 102 | -import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT; | ||
| 103 | -import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; | ||
| 104 | -import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; | ||
| 105 | -import static org.onosproject.net.flow.criteria.Criterion.Type.EXTENSION; | ||
| 106 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
| 107 | import static org.slf4j.LoggerFactory.getLogger; | 34 | import static org.slf4j.LoggerFactory.getLogger; |
| 108 | 35 | ||
| 109 | /** | 36 | /** |
| ... | @@ -118,34 +45,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider | ... | @@ -118,34 +45,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider |
| 118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 119 | protected FlowRuleProviderRegistry providerRegistry; | 46 | protected FlowRuleProviderRegistry providerRegistry; |
| 120 | 47 | ||
| 121 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 122 | - protected BgpController bgpController; | ||
| 123 | - | ||
| 124 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 125 | - protected PcepClientController pcepController; | ||
| 126 | - | ||
| 127 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 128 | - protected ResourceService resourceService; | ||
| 129 | - | ||
| 130 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 131 | - protected TunnelService tunnelService; | ||
| 132 | - | ||
| 133 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 134 | - protected DeviceService deviceService; | ||
| 135 | - | ||
| 136 | private FlowRuleProviderService providerService; | 48 | private FlowRuleProviderService providerService; |
| 137 | - private PcepLabelObject labelObj; | ||
| 138 | - public static final int OUT_LABEL_TYPE = 0; | ||
| 139 | - public static final int IN_LABEL_TYPE = 1; | ||
| 140 | - public static final long IDENTIFIER_SET = 0x100000000L; | ||
| 141 | - public static final long SET = 0xFFFFFFFFL; | ||
| 142 | - private static final String LSRID = "lsrId"; | ||
| 143 | - | ||
| 144 | - private enum PcepFlowType { | ||
| 145 | - ADD, | ||
| 146 | - MODIFY, | ||
| 147 | - REMOVE | ||
| 148 | - } | ||
| 149 | 49 | ||
| 150 | /** | 50 | /** |
| 151 | * Creates a BgpFlow host provider. | 51 | * Creates a BgpFlow host provider. |
| ... | @@ -169,469 +69,25 @@ public class BgpcepFlowRuleProvider extends AbstractProvider | ... | @@ -169,469 +69,25 @@ public class BgpcepFlowRuleProvider extends AbstractProvider |
| 169 | 69 | ||
| 170 | @Override | 70 | @Override |
| 171 | public void applyFlowRule(FlowRule... flowRules) { | 71 | public void applyFlowRule(FlowRule... flowRules) { |
| 172 | - for (FlowRule flowRule : flowRules) { | 72 | + // TODO Auto-generated method stub |
| 173 | - processRule(flowRule, PcepFlowType.ADD); | 73 | + |
| 174 | - } | ||
| 175 | } | 74 | } |
| 176 | 75 | ||
| 177 | @Override | 76 | @Override |
| 178 | public void removeFlowRule(FlowRule... flowRules) { | 77 | public void removeFlowRule(FlowRule... flowRules) { |
| 179 | - for (FlowRule flowRule : flowRules) { | 78 | + // TODO Auto-generated method stub |
| 180 | - processRule(flowRule, PcepFlowType.REMOVE); | ||
| 181 | - } | ||
| 182 | - } | ||
| 183 | - | ||
| 184 | - private void processRule(FlowRule flowRule, PcepFlowType type) { | ||
| 185 | - MplsLabel mplsLabel = null; | ||
| 186 | - IpPrefix ip4PrefixSrc = null; | ||
| 187 | - IpPrefix ip4PrefixDst = null; | ||
| 188 | - PortNumber port = null; | ||
| 189 | - TunnelId tunnelId = null; | ||
| 190 | - long labelType = 0; | ||
| 191 | - boolean bottomOfStack = false; | ||
| 192 | - | ||
| 193 | - TrafficSelector selector = flowRule.selector(); | ||
| 194 | - for (Criterion c : selector.criteria()) { | ||
| 195 | - switch (c.type()) { | ||
| 196 | - case MPLS_LABEL: | ||
| 197 | - MplsCriterion lc = (MplsCriterion) c; | ||
| 198 | - mplsLabel = lc.label(); | ||
| 199 | - break; | ||
| 200 | - case IPV4_SRC: | ||
| 201 | - IPCriterion ipCriterion = (IPCriterion) c; | ||
| 202 | - ip4PrefixSrc = ipCriterion.ip().getIp4Prefix(); | ||
| 203 | - break; | ||
| 204 | - case IPV4_DST: | ||
| 205 | - ipCriterion = (IPCriterion) c; | ||
| 206 | - ip4PrefixDst = ipCriterion.ip().getIp4Prefix(); | ||
| 207 | - break; | ||
| 208 | - case IN_PORT: | ||
| 209 | - PortCriterion inPort = (PortCriterion) c; | ||
| 210 | - port = inPort.port(); | ||
| 211 | - break; | ||
| 212 | - case TUNNEL_ID: | ||
| 213 | - TunnelIdCriterion tc = (TunnelIdCriterion) c; | ||
| 214 | - tunnelId = TunnelId.valueOf(String.valueOf(tc.tunnelId())); | ||
| 215 | - break; | ||
| 216 | - case METADATA: | ||
| 217 | - MetadataCriterion metadata = (MetadataCriterion) c; | ||
| 218 | - labelType = metadata.metadata(); | ||
| 219 | - break; | ||
| 220 | - case MPLS_BOS: | ||
| 221 | - MplsBosCriterion mplsBos = (MplsBosCriterion) c; | ||
| 222 | - bottomOfStack = mplsBos.mplsBos(); | ||
| 223 | - break; | ||
| 224 | - default: | ||
| 225 | - break; | ||
| 226 | - } | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - checkNotNull(mplsLabel); | ||
| 230 | - LabelResourceId label = LabelResourceId.labelResourceId(mplsLabel.toInt()); | ||
| 231 | - | ||
| 232 | - try { | ||
| 233 | - if (tunnelId != null) { | ||
| 234 | - pushLocalLabels(flowRule.deviceId(), label, port, tunnelId, bottomOfStack, labelType, type); | ||
| 235 | - return; | ||
| 236 | - } | ||
| 237 | - | ||
| 238 | - if (ip4PrefixDst != null) { | ||
| 239 | - pushAdjacencyLabel(flowRule.deviceId(), label, ip4PrefixSrc, ip4PrefixDst, type); | ||
| 240 | - return; | ||
| 241 | - } | ||
| 242 | - | ||
| 243 | - pushGlobalNodeLabel(flowRule.deviceId(), label, ip4PrefixSrc, type, bottomOfStack); | ||
| 244 | - | ||
| 245 | - } catch (PcepParseException e) { | ||
| 246 | - log.error("Exception occured while sending label message to PCC {}", e.getMessage()); | ||
| 247 | - } | ||
| 248 | - | ||
| 249 | - } | ||
| 250 | - | ||
| 251 | - /** | ||
| 252 | - * Returns PCEP client. | ||
| 253 | - * | ||
| 254 | - * @return PCEP client | ||
| 255 | - */ | ||
| 256 | - private PcepClient getPcepClient(DeviceId deviceId) { | ||
| 257 | - Device device = deviceService.getDevice(deviceId); | ||
| 258 | - | ||
| 259 | - // In future projections instead of annotations will be used to fetch LSR ID. | ||
| 260 | - String lsrId = device.annotations().value(LSRID); | ||
| 261 | - | ||
| 262 | - PcepClient pcc = pcepController.getClient(PccId.pccId(IpAddress.valueOf(lsrId))); | ||
| 263 | - return pcc; | ||
| 264 | - } | ||
| 265 | - | ||
| 266 | - //Pushes node labels to the specified device. | ||
| 267 | - private void pushGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId, | ||
| 268 | - IpPrefix ipPrefix, PcepFlowType type, boolean isBos) throws PcepParseException { | ||
| 269 | - | ||
| 270 | - checkNotNull(deviceId); | ||
| 271 | - checkNotNull(labelId); | ||
| 272 | - checkNotNull(type); | ||
| 273 | - | ||
| 274 | - PcepClient pc = getPcepClient(deviceId); | ||
| 275 | - if (pc == null) { | ||
| 276 | - log.error("PCEP client not found"); | ||
| 277 | - return; | ||
| 278 | - } | ||
| 279 | - | ||
| 280 | - LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); | ||
| 281 | - | ||
| 282 | - if (ipPrefix == null) { | ||
| 283 | - // Pushing self node label to device. | ||
| 284 | - ipPrefix = IpPrefix.valueOf(pc.getPccId().ipAddress(), 32); | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | - PcepFecObjectIPv4 fecObject = pc.factory().buildFecObjectIpv4() | ||
| 288 | - .setNodeID(ipPrefix.address().getIp4Address().toInt()) | ||
| 289 | - .build(); | ||
| 290 | - | ||
| 291 | - boolean bSFlag = false; | ||
| 292 | - if (pc.labelDbSyncStatus() == IN_SYNC && !isBos) { | ||
| 293 | - // Need to set sync flag in all messages till sync completes. | ||
| 294 | - bSFlag = true; | ||
| 295 | - } | ||
| 296 | - | ||
| 297 | - PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag); | ||
| 298 | - | ||
| 299 | - //Global NODE-SID as label object | ||
| 300 | - PcepLabelObject labelObject = pc.factory().buildLabelObject() | ||
| 301 | - .setLabel((int) labelId.labelId()) | ||
| 302 | - .build(); | ||
| 303 | 79 | ||
| 304 | - PcepLabelMap labelMap = new PcepLabelMap(); | ||
| 305 | - labelMap.setFecObject(fecObject); | ||
| 306 | - labelMap.setLabelObject(labelObject); | ||
| 307 | - labelMap.setSrpObject(srpObj); | ||
| 308 | - | ||
| 309 | - labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() | ||
| 310 | - .setLabelMap(labelMap) | ||
| 311 | - .build()); | ||
| 312 | - | ||
| 313 | - PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() | ||
| 314 | - .setPcLabelUpdateList(labelUpdateList) | ||
| 315 | - .build(); | ||
| 316 | - | ||
| 317 | - pc.sendMessage(labelMsg); | ||
| 318 | - | ||
| 319 | - if (isBos) { | ||
| 320 | - // Sync is completed. | ||
| 321 | - pc.setLabelDbSyncStatus(SYNCED); | ||
| 322 | - } | ||
| 323 | - } | ||
| 324 | - | ||
| 325 | - private PcepSrpObject getSrpObject(PcepClient pc, PcepFlowType type, boolean bSFlag) | ||
| 326 | - throws PcepParseException { | ||
| 327 | - PcepSrpObject srpObj; | ||
| 328 | - boolean bRFlag = false; | ||
| 329 | - | ||
| 330 | - if (!type.equals(PcepFlowType.ADD)) { | ||
| 331 | - // To cleanup labels, R bit is set | ||
| 332 | - bRFlag = true; | ||
| 333 | - } | ||
| 334 | - | ||
| 335 | - srpObj = pc.factory().buildSrpObject() | ||
| 336 | - .setRFlag(bRFlag) | ||
| 337 | - .setSFlag(bSFlag) | ||
| 338 | - .setSrpID(SrpIdGenerators.create()) | ||
| 339 | - .build(); | ||
| 340 | - | ||
| 341 | - return srpObj; | ||
| 342 | - } | ||
| 343 | - | ||
| 344 | - //Pushes adjacency labels to the specified device. | ||
| 345 | - private void pushAdjacencyLabel(DeviceId deviceId, LabelResourceId labelId, IpPrefix ip4PrefixSrc, | ||
| 346 | - IpPrefix ip4PrefixDst, PcepFlowType type) | ||
| 347 | - throws PcepParseException { | ||
| 348 | - | ||
| 349 | - checkNotNull(deviceId); | ||
| 350 | - checkNotNull(labelId); | ||
| 351 | - checkNotNull(ip4PrefixSrc); | ||
| 352 | - checkNotNull(ip4PrefixDst); | ||
| 353 | - checkNotNull(type); | ||
| 354 | - | ||
| 355 | - PcepClient pc = getPcepClient(deviceId); | ||
| 356 | - if (pc == null) { | ||
| 357 | - log.error("PCEP client not found"); | ||
| 358 | - return; | ||
| 359 | - } | ||
| 360 | - | ||
| 361 | - LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); | ||
| 362 | - | ||
| 363 | - int srcPortNo = ip4PrefixSrc.address().getIp4Address().toInt(); | ||
| 364 | - int dstPortNo = ip4PrefixDst.address().getIp4Address().toInt(); | ||
| 365 | - | ||
| 366 | - PcepFecObjectIPv4Adjacency fecAdjObject = pc.factory().buildFecIpv4Adjacency() | ||
| 367 | - .seRemoteIPv4Address(dstPortNo) | ||
| 368 | - .seLocalIPv4Address(srcPortNo) | ||
| 369 | - .build(); | ||
| 370 | - | ||
| 371 | - boolean bSFlag = false; | ||
| 372 | - if (pc.labelDbSyncStatus() == IN_SYNC) { | ||
| 373 | - // Need to set sync flag in all messages till sync completes. | ||
| 374 | - bSFlag = true; | ||
| 375 | - } | ||
| 376 | - | ||
| 377 | - PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag); | ||
| 378 | - | ||
| 379 | - //Adjacency label object | ||
| 380 | - PcepLabelObject labelObject = pc.factory().buildLabelObject() | ||
| 381 | - .setLabel((int) labelId.labelId()) | ||
| 382 | - .build(); | ||
| 383 | - | ||
| 384 | - PcepLabelMap labelMap = new PcepLabelMap(); | ||
| 385 | - labelMap.setFecObject(fecAdjObject); | ||
| 386 | - labelMap.setLabelObject(labelObject); | ||
| 387 | - labelMap.setSrpObject(srpObj); | ||
| 388 | - | ||
| 389 | - labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() | ||
| 390 | - .setLabelMap(labelMap) | ||
| 391 | - .build()); | ||
| 392 | - | ||
| 393 | - PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() | ||
| 394 | - .setPcLabelUpdateList(labelUpdateList) | ||
| 395 | - .build(); | ||
| 396 | - | ||
| 397 | - pc.sendMessage(labelMsg); | ||
| 398 | - } | ||
| 399 | - | ||
| 400 | - //Pushes local labels to the device which is specific to path [CR-case]. | ||
| 401 | - private void pushLocalLabels(DeviceId deviceId, LabelResourceId labelId, | ||
| 402 | - PortNumber portNum, TunnelId tunnelId, | ||
| 403 | - Boolean isBos, Long labelType, PcepFlowType type) throws PcepParseException { | ||
| 404 | - | ||
| 405 | - checkNotNull(deviceId); | ||
| 406 | - checkNotNull(labelId); | ||
| 407 | - checkNotNull(portNum); | ||
| 408 | - checkNotNull(tunnelId); | ||
| 409 | - checkNotNull(labelType); | ||
| 410 | - checkNotNull(type); | ||
| 411 | - | ||
| 412 | - PcepClient pc = getPcepClient(deviceId); | ||
| 413 | - if (pc == null) { | ||
| 414 | - log.error("PCEP client not found"); | ||
| 415 | - return; | ||
| 416 | - } | ||
| 417 | - | ||
| 418 | - PcepLspObject lspObj; | ||
| 419 | - LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>(); | ||
| 420 | - LinkedList<PcepLabelObject> labelObjects = new LinkedList<>(); | ||
| 421 | - PcepSrpObject srpObj; | ||
| 422 | - PcepLabelDownload labelDownload = new PcepLabelDownload(); | ||
| 423 | - LinkedList<PcepValueType> optionalTlv = new LinkedList<>(); | ||
| 424 | - | ||
| 425 | - long portNo = portNum.toLong(); | ||
| 426 | - portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; | ||
| 427 | - | ||
| 428 | - optionalTlv.add(NexthopIPv4addressTlv.of((int) portNo)); | ||
| 429 | - | ||
| 430 | - Tunnel tunnel = tunnelService.queryTunnel(tunnelId); | ||
| 431 | - | ||
| 432 | - PcepLabelObject labelObj = pc.factory().buildLabelObject() | ||
| 433 | - .setOFlag(labelType == OUT_LABEL_TYPE) | ||
| 434 | - .setOptionalTlv(optionalTlv) | ||
| 435 | - .setLabel((int) labelId.labelId()) | ||
| 436 | - .build(); | ||
| 437 | - | ||
| 438 | - /** | ||
| 439 | - * Check whether transit node or not. For transit node, label update message should include IN and OUT labels. | ||
| 440 | - * Hence store IN label object and next when out label comes add IN and OUT label objects and encode label | ||
| 441 | - * update message and send to specified client. | ||
| 442 | - */ | ||
| 443 | - if (!deviceId.equals(tunnel.path().src().deviceId()) && !deviceId.equals(tunnel.path().dst().deviceId())) { | ||
| 444 | - //Device is transit node | ||
| 445 | - if (labelType == IN_LABEL_TYPE) { | ||
| 446 | - //Store label object having IN label value | ||
| 447 | - this.labelObj = labelObj; | ||
| 448 | - return; | ||
| 449 | - } | ||
| 450 | - //Add IN label object | ||
| 451 | - labelObjects.add(this.labelObj); | ||
| 452 | - } | ||
| 453 | - | ||
| 454 | - //Add OUT label object in case of transit node | ||
| 455 | - labelObjects.add(labelObj); | ||
| 456 | - | ||
| 457 | - srpObj = getSrpObject(pc, type, false); | ||
| 458 | - | ||
| 459 | - String lspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID); | ||
| 460 | - String plspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID); | ||
| 461 | - String tunnelIdentifier = tunnel.annotations().value(PcepAnnotationKeys.PCC_TUNNEL_ID); | ||
| 462 | - | ||
| 463 | - LinkedList<PcepValueType> tlvs = new LinkedList<>(); | ||
| 464 | - StatefulIPv4LspIdentifiersTlv lspIdTlv = new StatefulIPv4LspIdentifiersTlv(((IpTunnelEndPoint) tunnel.src()) | ||
| 465 | - .ip().getIp4Address().toInt(), Short.valueOf(lspId), Short.valueOf(tunnelIdentifier), | ||
| 466 | - ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(), | ||
| 467 | - ((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()); | ||
| 468 | - tlvs.add(lspIdTlv); | ||
| 469 | - | ||
| 470 | - if (tunnel.tunnelName().value() != null) { | ||
| 471 | - SymbolicPathNameTlv pathNameTlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); | ||
| 472 | - tlvs.add(pathNameTlv); | ||
| 473 | - } | ||
| 474 | - | ||
| 475 | - boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false | ||
| 476 | - : Boolean.valueOf(tunnel.annotations() | ||
| 477 | - .value(DELEGATE)); | ||
| 478 | - boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false | ||
| 479 | - : Boolean.valueOf(tunnel.annotations() | ||
| 480 | - .value(PCE_INIT)); | ||
| 481 | - | ||
| 482 | - lspObj = pc.factory().buildLspObject() | ||
| 483 | - .setRFlag(false) | ||
| 484 | - .setAFlag(true) | ||
| 485 | - .setDFlag(delegated) | ||
| 486 | - .setCFlag(initiated) | ||
| 487 | - .setPlspId(Integer.valueOf(plspId)) | ||
| 488 | - .setOptionalTlv(tlvs) | ||
| 489 | - .build(); | ||
| 490 | - | ||
| 491 | - labelDownload.setLabelList(labelObjects); | ||
| 492 | - labelDownload.setLspObject(lspObj); | ||
| 493 | - labelDownload.setSrpObject(srpObj); | ||
| 494 | - | ||
| 495 | - labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject() | ||
| 496 | - .setLabelDownload(labelDownload) | ||
| 497 | - .build()); | ||
| 498 | - | ||
| 499 | - PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg() | ||
| 500 | - .setPcLabelUpdateList(labelUpdateList) | ||
| 501 | - .build(); | ||
| 502 | - | ||
| 503 | - pc.sendMessage(labelMsg); | ||
| 504 | - | ||
| 505 | - //If isBos is true, label download is done along the LSP, send PCEP update message. | ||
| 506 | - if (isBos) { | ||
| 507 | - sendPcepUpdateMsg(pc, lspObj, tunnel); | ||
| 508 | - } | ||
| 509 | - } | ||
| 510 | - | ||
| 511 | - //Sends PCEP update message. | ||
| 512 | - private void sendPcepUpdateMsg(PcepClient pc, PcepLspObject lspObj, Tunnel tunnel) throws PcepParseException { | ||
| 513 | - LinkedList<PcepUpdateRequest> updateRequestList = new LinkedList<>(); | ||
| 514 | - LinkedList<PcepValueType> subObjects = createEroSubObj(tunnel.path()); | ||
| 515 | - | ||
| 516 | - if (subObjects == null) { | ||
| 517 | - log.error("ERO subjects not present"); | ||
| 518 | - return; | ||
| 519 | - } | ||
| 520 | - | ||
| 521 | - // set PathSetupTypeTlv of SRP object | ||
| 522 | - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | ||
| 523 | - LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); | ||
| 524 | - llOptionalTlv.add(new PathSetupTypeTlv(lspSigType.type())); | ||
| 525 | - | ||
| 526 | - PcepSrpObject srpObj = pc.factory().buildSrpObject() | ||
| 527 | - .setRFlag(false) | ||
| 528 | - .setSrpID(SrpIdGenerators.create()) | ||
| 529 | - .setOptionalTlv(llOptionalTlv) | ||
| 530 | - .build(); | ||
| 531 | - | ||
| 532 | - PcepEroObject eroObj = pc.factory().buildEroObject() | ||
| 533 | - .setSubObjects(subObjects) | ||
| 534 | - .build(); | ||
| 535 | - | ||
| 536 | - float iBandwidth = 0; | ||
| 537 | - if (tunnel.annotations().value(BANDWIDTH) != null) { | ||
| 538 | - //iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH))); | ||
| 539 | - iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH)); | ||
| 540 | - } | ||
| 541 | - // build bandwidth object | ||
| 542 | - PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject() | ||
| 543 | - .setBandwidth(iBandwidth) | ||
| 544 | - .build(); | ||
| 545 | - // build pcep attribute | ||
| 546 | - PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute() | ||
| 547 | - .setBandwidthObject(bandwidthObject) | ||
| 548 | - .build(); | ||
| 549 | - | ||
| 550 | - PcepMsgPath msgPath = pc.factory().buildPcepMsgPath() | ||
| 551 | - .setEroObject(eroObj) | ||
| 552 | - .setPcepAttribute(pcepAttribute) | ||
| 553 | - .build(); | ||
| 554 | - | ||
| 555 | - PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest() | ||
| 556 | - .setSrpObject(srpObj) | ||
| 557 | - .setMsgPath(msgPath) | ||
| 558 | - .setLspObject(lspObj) | ||
| 559 | - .build(); | ||
| 560 | - | ||
| 561 | - updateRequestList.add(updateReq); | ||
| 562 | - | ||
| 563 | - //TODO: P = 1 is it P flag in PCEP obj header | ||
| 564 | - PcepUpdateMsg updateMsg = pc.factory().buildUpdateMsg() | ||
| 565 | - .setUpdateRequestList(updateRequestList) | ||
| 566 | - .build(); | ||
| 567 | - | ||
| 568 | - pc.sendMessage(updateMsg); | ||
| 569 | - } | ||
| 570 | - | ||
| 571 | - private LinkedList<PcepValueType> createEroSubObj(Path path) { | ||
| 572 | - LinkedList<PcepValueType> subObjects = new LinkedList<>(); | ||
| 573 | - List<Link> links = path.links(); | ||
| 574 | - ConnectPoint source = null; | ||
| 575 | - ConnectPoint destination = null; | ||
| 576 | - IpAddress ipDstAddress = null; | ||
| 577 | - IpAddress ipSrcAddress = null; | ||
| 578 | - PcepValueType subObj = null; | ||
| 579 | - long portNo; | ||
| 580 | - | ||
| 581 | - for (Link link : links) { | ||
| 582 | - source = link.src(); | ||
| 583 | - if (!(source.equals(destination))) { | ||
| 584 | - //set IPv4SubObject for ERO object | ||
| 585 | - portNo = source.port().toLong(); | ||
| 586 | - portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; | ||
| 587 | - ipSrcAddress = Ip4Address.valueOf((int) portNo); | ||
| 588 | - subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); | ||
| 589 | - subObjects.add(subObj); | ||
| 590 | - } | ||
| 591 | - | ||
| 592 | - destination = link.dst(); | ||
| 593 | - portNo = destination.port().toLong(); | ||
| 594 | - portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; | ||
| 595 | - ipDstAddress = Ip4Address.valueOf((int) portNo); | ||
| 596 | - subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); | ||
| 597 | - subObjects.add(subObj); | ||
| 598 | - } | ||
| 599 | - return subObjects; | ||
| 600 | } | 80 | } |
| 601 | 81 | ||
| 602 | @Override | 82 | @Override |
| 603 | public void removeRulesById(ApplicationId id, FlowRule... flowRules) { | 83 | public void removeRulesById(ApplicationId id, FlowRule... flowRules) { |
| 604 | - // TODO | 84 | + // TODO Auto-generated method stub |
| 605 | - removeFlowRule(flowRules); | 85 | + |
| 606 | } | 86 | } |
| 607 | 87 | ||
| 608 | @Override | 88 | @Override |
| 609 | public void executeBatch(FlowRuleBatchOperation batch) { | 89 | public void executeBatch(FlowRuleBatchOperation batch) { |
| 610 | - Collection<FlowEntry> flowEntries = new ArrayList<>(); | 90 | + // TODO Auto-generated method stub |
| 611 | - | ||
| 612 | - for (FlowRuleBatchEntry fbe : batch.getOperations()) { | ||
| 613 | - Criterion criteria = fbe.target().selector().getCriterion(EXTENSION); | ||
| 614 | - | ||
| 615 | - switch (fbe.operator()) { | ||
| 616 | - case ADD: | ||
| 617 | - if (criteria == null) { | ||
| 618 | - processRule(fbe.target(), PcepFlowType.ADD); | ||
| 619 | - flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.ADDED, 0, 0, 0)); | ||
| 620 | - } | ||
| 621 | - break; | ||
| 622 | - case REMOVE: | ||
| 623 | - if (criteria == null) { | ||
| 624 | - processRule(fbe.target(), PcepFlowType.REMOVE); | ||
| 625 | - flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.REMOVED, 0, 0, 0)); | ||
| 626 | - } | ||
| 627 | - break; | ||
| 628 | - default: | ||
| 629 | - log.error("Unknown flow operation: {}", fbe); | ||
| 630 | - } | ||
| 631 | - } | ||
| 632 | 91 | ||
| 633 | - CompletedBatchOperation status = new CompletedBatchOperation(true, Collections.emptySet(), batch.deviceId()); | ||
| 634 | - providerService.batchOperationCompleted(batch.id(), status); | ||
| 635 | - providerService.pushFlowMetrics(batch.deviceId(), flowEntries); | ||
| 636 | } | 92 | } |
| 637 | } | 93 | } | ... | ... |
| ... | @@ -5,7 +5,6 @@ BUNDLES = [ | ... | @@ -5,7 +5,6 @@ BUNDLES = [ |
| 5 | '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', | 5 | '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', |
| 6 | '//protocols/pcep/ctl:onos-protocols-pcep-ctl', | 6 | '//protocols/pcep/ctl:onos-protocols-pcep-ctl', |
| 7 | '//apps/pcep-api:onos-apps-pcep-api', | 7 | '//apps/pcep-api:onos-apps-pcep-api', |
| 8 | - '//providers/pcep/packet:onos-providers-pcep-packet', | ||
| 9 | ] | 8 | ] |
| 10 | 9 | ||
| 11 | onos_app ( | 10 | onos_app ( | ... | ... |
providers/pcep/packet/BUCK
deleted
100644 → 0
providers/pcep/packet/pom.xml
deleted
100644 → 0
| 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 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 17 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 18 | - <modelVersion>4.0.0</modelVersion> | ||
| 19 | - <parent> | ||
| 20 | - <groupId>org.onosproject</groupId> | ||
| 21 | - <artifactId>onos-pcep-providers</artifactId> | ||
| 22 | - <version>1.7.0-SNAPSHOT</version> | ||
| 23 | - </parent> | ||
| 24 | - <artifactId>onos-pcep-provider-packet</artifactId> | ||
| 25 | - <packaging>bundle</packaging> | ||
| 26 | - <description>PCEP packet provider</description> | ||
| 27 | - <dependencies> | ||
| 28 | - <dependency> | ||
| 29 | - <groupId>org.onosproject</groupId> | ||
| 30 | - <artifactId>onos-pcep-controller-api</artifactId> | ||
| 31 | - </dependency> | ||
| 32 | - </dependencies> | ||
| 33 | -</project> |
| 1 | -package org.onosproject.provider.pcep.packet.impl; | ||
| 2 | - | ||
| 3 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 4 | - | ||
| 5 | -import org.apache.felix.scr.annotations.Activate; | ||
| 6 | -import org.apache.felix.scr.annotations.Component; | ||
| 7 | -import org.apache.felix.scr.annotations.Deactivate; | ||
| 8 | -import org.apache.felix.scr.annotations.Reference; | ||
| 9 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 10 | -import org.apache.felix.scr.annotations.Service; | ||
| 11 | -import org.onlab.packet.Ethernet; | ||
| 12 | -import org.onlab.packet.IPv4; | ||
| 13 | -import org.onlab.packet.MacAddress; | ||
| 14 | -import org.onlab.packet.TCP; | ||
| 15 | -import org.onosproject.net.ConnectPoint; | ||
| 16 | -import org.onosproject.net.DeviceId; | ||
| 17 | -import org.onosproject.net.PortNumber; | ||
| 18 | -import org.onosproject.net.device.DeviceService; | ||
| 19 | -import org.onosproject.net.packet.DefaultInboundPacket; | ||
| 20 | -import org.onosproject.net.packet.DefaultPacketContext; | ||
| 21 | -import org.onosproject.net.packet.InboundPacket; | ||
| 22 | -import org.onosproject.net.packet.OutboundPacket; | ||
| 23 | -import org.onosproject.net.packet.PacketProvider; | ||
| 24 | -import org.onosproject.net.packet.PacketProviderRegistry; | ||
| 25 | -import org.onosproject.net.packet.PacketProviderService; | ||
| 26 | -import org.onosproject.net.provider.AbstractProvider; | ||
| 27 | -import org.onosproject.net.provider.ProviderId; | ||
| 28 | -import org.onosproject.pcep.controller.PccId; | ||
| 29 | -import org.onosproject.pcep.controller.PcepClientController; | ||
| 30 | -import org.onosproject.pcep.controller.PcepPacketListener; | ||
| 31 | -import org.slf4j.Logger; | ||
| 32 | - | ||
| 33 | -/** | ||
| 34 | - * Provider which uses an PCEP controller to process packets. | ||
| 35 | - */ | ||
| 36 | -@Component(immediate = true) | ||
| 37 | -@Service | ||
| 38 | -public class PcepPacketProvider extends AbstractProvider implements PacketProvider { | ||
| 39 | - | ||
| 40 | - private static final Logger log = getLogger(PcepPacketProvider.class); | ||
| 41 | - static final String PROVIDER_ID = "org.onosproject.provider.packet.pcep"; | ||
| 42 | - | ||
| 43 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 44 | - protected PacketProviderRegistry packetProviderRegistry; | ||
| 45 | - | ||
| 46 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 47 | - protected PcepClientController pcepClientController; | ||
| 48 | - | ||
| 49 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 50 | - protected DeviceService deviceService; | ||
| 51 | - | ||
| 52 | - PacketProviderService packetProviderService; | ||
| 53 | - | ||
| 54 | - private InnerPacketProvider listener = new InnerPacketProvider(); | ||
| 55 | - public static final String LSRID = "lsrId"; | ||
| 56 | - public static final int PCEP_PORT = 4189; | ||
| 57 | - | ||
| 58 | - /** | ||
| 59 | - * Creates a Packet provider. | ||
| 60 | - */ | ||
| 61 | - public PcepPacketProvider() { | ||
| 62 | - super(new ProviderId("pcep", PROVIDER_ID)); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - @Activate | ||
| 66 | - public void activate() { | ||
| 67 | - packetProviderService = packetProviderRegistry.register(this); | ||
| 68 | - pcepClientController.addPacketListener(listener); | ||
| 69 | - log.info("Started"); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - @Deactivate | ||
| 73 | - public void deactivate() { | ||
| 74 | - packetProviderRegistry.unregister(this); | ||
| 75 | - pcepClientController.removePacketListener(listener); | ||
| 76 | - log.info("Stopped"); | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - private class InnerPacketProvider implements PcepPacketListener { | ||
| 80 | - @Override | ||
| 81 | - public void sendPacketIn(PccId pccId) { | ||
| 82 | - TCP tcp = new TCP(); | ||
| 83 | - // Set the well known PCEP port. To be used to decide to process/discard the packet while processing. | ||
| 84 | - tcp.setDestinationPort(PCEP_PORT); | ||
| 85 | - | ||
| 86 | - IPv4 ipv4 = new IPv4(); | ||
| 87 | - ipv4.setProtocol(IPv4.PROTOCOL_TCP); | ||
| 88 | - ipv4.setPayload(tcp); | ||
| 89 | - | ||
| 90 | - Ethernet eth = new Ethernet(); | ||
| 91 | - eth.setEtherType(Ethernet.TYPE_IPV4); | ||
| 92 | - eth.setDestinationMACAddress(MacAddress.NONE); | ||
| 93 | - eth.setPayload(ipv4); | ||
| 94 | - | ||
| 95 | - // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID. | ||
| 96 | - String lsrId = String.valueOf(pccId.ipAddress()); | ||
| 97 | - DeviceId pccDeviceId = DeviceId.deviceId(lsrId); | ||
| 98 | - | ||
| 99 | - InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(pccDeviceId, | ||
| 100 | - PortNumber.portNumber(PCEP_PORT)), | ||
| 101 | - eth, null); | ||
| 102 | - | ||
| 103 | - packetProviderService.processPacket(new PcepPacketContext(inPkt, null)); | ||
| 104 | - } | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - // Minimal PacketContext to make core and applications happy. | ||
| 108 | - private final class PcepPacketContext extends DefaultPacketContext { | ||
| 109 | - private PcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) { | ||
| 110 | - super(System.currentTimeMillis(), inPkt, outPkt, false); | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - @Override | ||
| 114 | - public void send() { | ||
| 115 | - // We don't send anything out. | ||
| 116 | - } | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - @Override | ||
| 120 | - public void emit(OutboundPacket packet) { | ||
| 121 | - // Nothing to emit | ||
| 122 | - } | ||
| 123 | -} |
| ... | @@ -27,6 +27,5 @@ | ... | @@ -27,6 +27,5 @@ |
| 27 | <module>topology</module> | 27 | <module>topology</module> |
| 28 | <module>tunnel</module> | 28 | <module>tunnel</module> |
| 29 | <module>app</module> | 29 | <module>app</module> |
| 30 | - <module>packet</module> | ||
| 31 | </modules> | 30 | </modules> |
| 32 | </project> | 31 | </project> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | COMPILE_DEPS = [ | 1 | COMPILE_DEPS = [ |
| 2 | '//lib:CORE_DEPS', | 2 | '//lib:CORE_DEPS', |
| 3 | + '//incubator/api:onos-incubator-api', | ||
| 3 | '//protocols/ovsdb/api:onos-protocols-ovsdb-api', | 4 | '//protocols/ovsdb/api:onos-protocols-ovsdb-api', |
| 4 | '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc', | 5 | '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc', |
| 5 | '//apps/pcep-api:onos-apps-pcep-api', | 6 | '//apps/pcep-api:onos-apps-pcep-api', | ... | ... |
| ... | @@ -25,6 +25,10 @@ import java.util.concurrent.ConcurrentHashMap; | ... | @@ -25,6 +25,10 @@ import java.util.concurrent.ConcurrentHashMap; |
| 25 | import org.apache.felix.scr.annotations.Activate; | 25 | import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; | 26 | import org.apache.felix.scr.annotations.Deactivate; |
| 27 | import org.onlab.packet.IpAddress; | 27 | import org.onlab.packet.IpAddress; |
| 28 | +import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | ||
| 29 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 30 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 31 | +import org.onosproject.net.Path; | ||
| 28 | import org.onosproject.pcep.controller.ClientCapability; | 32 | import org.onosproject.pcep.controller.ClientCapability; |
| 29 | import org.onosproject.pcep.controller.PccId; | 33 | import org.onosproject.pcep.controller.PccId; |
| 30 | import org.onosproject.pcep.controller.PcepClient; | 34 | import org.onosproject.pcep.controller.PcepClient; |
| ... | @@ -32,7 +36,6 @@ import org.onosproject.pcep.controller.PcepClientController; | ... | @@ -32,7 +36,6 @@ import org.onosproject.pcep.controller.PcepClientController; |
| 32 | import org.onosproject.pcep.controller.PcepClientListener; | 36 | import org.onosproject.pcep.controller.PcepClientListener; |
| 33 | import org.onosproject.pcep.controller.PcepEventListener; | 37 | import org.onosproject.pcep.controller.PcepEventListener; |
| 34 | import org.onosproject.pcep.controller.PcepNodeListener; | 38 | import org.onosproject.pcep.controller.PcepNodeListener; |
| 35 | -import org.onosproject.pcep.controller.PcepPacketListener; | ||
| 36 | import org.onosproject.pcep.controller.driver.PcepAgent; | 39 | import org.onosproject.pcep.controller.driver.PcepAgent; |
| 37 | import org.onosproject.pcepio.protocol.PcepError; | 40 | import org.onosproject.pcepio.protocol.PcepError; |
| 38 | import org.onosproject.pcepio.protocol.PcepErrorInfo; | 41 | import org.onosproject.pcepio.protocol.PcepErrorInfo; |
| ... | @@ -41,6 +44,7 @@ import org.onosproject.pcepio.protocol.PcepErrorObject; | ... | @@ -41,6 +44,7 @@ import org.onosproject.pcepio.protocol.PcepErrorObject; |
| 41 | import org.onosproject.pcepio.protocol.PcepFactory; | 44 | import org.onosproject.pcepio.protocol.PcepFactory; |
| 42 | import org.onosproject.pcepio.protocol.PcepMessage; | 45 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 43 | import org.onosproject.pcepio.protocol.PcepVersion; | 46 | import org.onosproject.pcepio.protocol.PcepVersion; |
| 47 | +import org.onosproject.pcepio.types.PcepValueType; | ||
| 44 | 48 | ||
| 45 | import com.google.common.collect.Sets; | 49 | import com.google.common.collect.Sets; |
| 46 | 50 | ||
| ... | @@ -290,14 +294,20 @@ public class PcepClientControllerAdapter implements PcepClientController { | ... | @@ -290,14 +294,20 @@ public class PcepClientControllerAdapter implements PcepClientController { |
| 290 | } | 294 | } |
| 291 | 295 | ||
| 292 | @Override | 296 | @Override |
| 293 | - public void addPacketListener(PcepPacketListener listener) { | 297 | + public LabelStack computeLabelStack(Path path) { |
| 294 | // TODO Auto-generated method stub | 298 | // TODO Auto-generated method stub |
| 295 | - | 299 | + return null; |
| 296 | } | 300 | } |
| 297 | 301 | ||
| 298 | @Override | 302 | @Override |
| 299 | - public void removePacketListener(PcepPacketListener listener) { | 303 | + public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) { |
| 300 | // TODO Auto-generated method stub | 304 | // TODO Auto-generated method stub |
| 305 | + return null; | ||
| 306 | + } | ||
| 301 | 307 | ||
| 308 | + @Override | ||
| 309 | + public boolean allocateLocalLabel(Tunnel tunnel) { | ||
| 310 | + // TODO Auto-generated method stub | ||
| 311 | + return false; | ||
| 302 | } | 312 | } |
| 303 | } | 313 | } | ... | ... |
| ... | @@ -100,7 +100,6 @@ import org.onosproject.pcepio.protocol.PcepLspObject; | ... | @@ -100,7 +100,6 @@ import org.onosproject.pcepio.protocol.PcepLspObject; |
| 100 | import org.onosproject.pcepio.protocol.PcepMessage; | 100 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 101 | import org.onosproject.pcepio.protocol.PcepMetricObject; | 101 | import org.onosproject.pcepio.protocol.PcepMetricObject; |
| 102 | import org.onosproject.pcepio.protocol.PcepMsgPath; | 102 | import org.onosproject.pcepio.protocol.PcepMsgPath; |
| 103 | -import org.onosproject.pcepio.protocol.PcepNai; | ||
| 104 | import org.onosproject.pcepio.protocol.PcepReportMsg; | 103 | import org.onosproject.pcepio.protocol.PcepReportMsg; |
| 105 | import org.onosproject.pcepio.protocol.PcepSrpObject; | 104 | import org.onosproject.pcepio.protocol.PcepSrpObject; |
| 106 | import org.onosproject.pcepio.protocol.PcepStateReport; | 105 | import org.onosproject.pcepio.protocol.PcepStateReport; |
| ... | @@ -109,7 +108,6 @@ import org.onosproject.pcepio.protocol.PcepUpdateRequest; | ... | @@ -109,7 +108,6 @@ import org.onosproject.pcepio.protocol.PcepUpdateRequest; |
| 109 | import org.onosproject.pcepio.types.IPv4SubObject; | 108 | import org.onosproject.pcepio.types.IPv4SubObject; |
| 110 | import org.onosproject.pcepio.types.PathSetupTypeTlv; | 109 | import org.onosproject.pcepio.types.PathSetupTypeTlv; |
| 111 | import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency; | 110 | import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency; |
| 112 | -import org.onosproject.pcepio.types.PcepNaiIpv4NodeId; | ||
| 113 | import org.onosproject.pcepio.types.PcepValueType; | 111 | import org.onosproject.pcepio.types.PcepValueType; |
| 114 | import org.onosproject.pcepio.types.SrEroSubObject; | 112 | import org.onosproject.pcepio.types.SrEroSubObject; |
| 115 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; | 113 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; |
| ... | @@ -124,7 +122,6 @@ import java.util.Collection; | ... | @@ -124,7 +122,6 @@ import java.util.Collection; |
| 124 | import java.util.Collections; | 122 | import java.util.Collections; |
| 125 | import java.util.Dictionary; | 123 | import java.util.Dictionary; |
| 126 | import java.util.HashMap; | 124 | import java.util.HashMap; |
| 127 | -import java.util.Iterator; | ||
| 128 | import java.util.LinkedList; | 125 | import java.util.LinkedList; |
| 129 | import java.util.List; | 126 | import java.util.List; |
| 130 | import java.util.ListIterator; | 127 | import java.util.ListIterator; |
| ... | @@ -280,7 +277,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -280,7 +277,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 280 | collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency)); | 277 | collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency)); |
| 281 | log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency); | 278 | log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency); |
| 282 | } | 279 | } |
| 283 | - | ||
| 284 | } | 280 | } |
| 285 | 281 | ||
| 286 | @Override | 282 | @Override |
| ... | @@ -318,8 +314,27 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -318,8 +314,27 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 318 | //TODO: tunnel which is passed doesn't have tunnelID | 314 | //TODO: tunnel which is passed doesn't have tunnelID |
| 319 | if (tunnel.annotations().value(PLSP_ID) != null) { | 315 | if (tunnel.annotations().value(PLSP_ID) != null) { |
| 320 | if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITHOUT_SIGNALLING_AND_WITHOUT_SR) { | 316 | if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITHOUT_SIGNALLING_AND_WITHOUT_SR) { |
| 321 | - // For CR LSPs, BGP flow provider will send update message after pushing labels. | ||
| 322 | updateTunnel(tunnel, path); | 317 | updateTunnel(tunnel, path); |
| 318 | + } else { | ||
| 319 | + // Download labels and send update message. | ||
| 320 | + // To get new tunnel ID (modified tunnel ID) | ||
| 321 | + Collection<Tunnel> tunnels = tunnelService.queryTunnel(tunnel.src(), tunnel.dst()); | ||
| 322 | + for (Tunnel t : tunnels) { | ||
| 323 | + if (t.state().equals(INIT) && t.tunnelName().equals(tunnel.tunnelName())) { | ||
| 324 | + tunnel = new DefaultTunnel(tunnel.providerId(), tunnel.src(), | ||
| 325 | + tunnel.dst(), tunnel.type(), | ||
| 326 | + t.state(), tunnel.groupId(), | ||
| 327 | + t.tunnelId(), | ||
| 328 | + tunnel.tunnelName(), | ||
| 329 | + tunnel.path(), | ||
| 330 | + tunnel.resource(), | ||
| 331 | + tunnel.annotations()); | ||
| 332 | + break; | ||
| 333 | + } | ||
| 334 | + } | ||
| 335 | + if (!pcepClientController.allocateLocalLabel(tunnel)) { | ||
| 336 | + log.error("Unable to allocate labels for the tunnel {}.", tunnel.toString()); | ||
| 337 | + } | ||
| 323 | } | 338 | } |
| 324 | return; | 339 | return; |
| 325 | } | 340 | } |
| ... | @@ -806,13 +821,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -806,13 +821,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 806 | extendAnnotations); | 821 | extendAnnotations); |
| 807 | 822 | ||
| 808 | } | 823 | } |
| 809 | - TunnelDescription tunnel = new DefaultTunnelDescription( | 824 | + TunnelDescription tunnel = new DefaultTunnelDescription(tunnelId, |
| 810 | - tunnelId, | ||
| 811 | srcPoint, | 825 | srcPoint, |
| 812 | dstPoint, | 826 | dstPoint, |
| 813 | tunnelType, | 827 | tunnelType, |
| 814 | - new DefaultGroupId( | 828 | + new DefaultGroupId(0), |
| 815 | - 0), | ||
| 816 | id(), name, | 829 | id(), name, |
| 817 | path, | 830 | path, |
| 818 | annotations); | 831 | annotations); |
| ... | @@ -904,55 +917,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -904,55 +917,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 904 | } | 917 | } |
| 905 | 918 | ||
| 906 | /** | 919 | /** |
| 907 | - * Creates label stack for ERO object from network resource. | ||
| 908 | - * | ||
| 909 | - * @param labelStack | ||
| 910 | - * @param path (hop list) | ||
| 911 | - * @return list of ERO subobjects | ||
| 912 | - */ | ||
| 913 | - private LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) { | ||
| 914 | - checkNotNull(labelStack); | ||
| 915 | - | ||
| 916 | - LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); | ||
| 917 | - Iterator<Link> links = path.links().iterator(); | ||
| 918 | - LabelResourceId label = null; | ||
| 919 | - Link link = null; | ||
| 920 | - PcepValueType subObj = null; | ||
| 921 | - PcepNai nai = null; | ||
| 922 | - Device dstNode = null; | ||
| 923 | - long srcPortNo, dstPortNo; | ||
| 924 | - | ||
| 925 | - ListIterator<LabelResourceId> labelListIterator = labelStack.labelResources().listIterator(); | ||
| 926 | - while (labelListIterator.hasNext()) { | ||
| 927 | - label = labelListIterator.next(); | ||
| 928 | - link = links.next(); | ||
| 929 | - | ||
| 930 | - srcPortNo = link.src().port().toLong(); | ||
| 931 | - srcPortNo = ((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? srcPortNo & SET : srcPortNo; | ||
| 932 | - | ||
| 933 | - dstPortNo = link.dst().port().toLong(); | ||
| 934 | - dstPortNo = ((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? dstPortNo & SET : dstPortNo; | ||
| 935 | - | ||
| 936 | - nai = new PcepNaiIpv4Adjacency((int) srcPortNo, (int) dstPortNo); | ||
| 937 | - subObj = new SrEroSubObject(PcepNaiIpv4Adjacency.ST_TYPE, false, false, false, true, (int) label.labelId(), | ||
| 938 | - nai); | ||
| 939 | - llSubObjects.add(subObj); | ||
| 940 | - | ||
| 941 | - dstNode = deviceService.getDevice(link.dst().deviceId()); | ||
| 942 | - nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt()); | ||
| 943 | - | ||
| 944 | - if (!labelListIterator.hasNext()) { | ||
| 945 | - log.error("Malformed label stack."); | ||
| 946 | - } | ||
| 947 | - label = labelListIterator.next(); | ||
| 948 | - subObj = new SrEroSubObject(PcepNaiIpv4NodeId.ST_TYPE, false, false, false, true, (int) label.labelId(), | ||
| 949 | - nai); | ||
| 950 | - llSubObjects.add(subObj); | ||
| 951 | - } | ||
| 952 | - return llSubObjects; | ||
| 953 | - } | ||
| 954 | - | ||
| 955 | - /** | ||
| 956 | * Creates PcInitiated lsp request list for setup tunnel. | 920 | * Creates PcInitiated lsp request list for setup tunnel. |
| 957 | * | 921 | * |
| 958 | * @param tunnel mpls tunnel | 922 | * @param tunnel mpls tunnel |
| ... | @@ -967,10 +931,18 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -967,10 +931,18 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 967 | throws PcepParseException { | 931 | throws PcepParseException { |
| 968 | PcepValueType tlv; | 932 | PcepValueType tlv; |
| 969 | LinkedList<PcepValueType> llSubObjects = null; | 933 | LinkedList<PcepValueType> llSubObjects = null; |
| 934 | + LspType lspType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); | ||
| 970 | 935 | ||
| 971 | - NetworkResource labelStack = tunnel.resource(); | 936 | + if (lspType == SR_WITHOUT_SIGNALLING) { |
| 972 | - if (labelStack != null && labelStack instanceof DefaultLabelStack) { | 937 | + NetworkResource labelStack = tunnel.resource(); |
| 973 | - llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path); | 938 | + if (labelStack == null || !(labelStack instanceof DefaultLabelStack)) { |
| 939 | + labelStack = pcepClientController.computeLabelStack(tunnel.path()); | ||
| 940 | + if (labelStack == null) { | ||
| 941 | + log.error("Unable to create label stack."); | ||
| 942 | + return null; | ||
| 943 | + } | ||
| 944 | + } | ||
| 945 | + llSubObjects = pcepClientController.createPcepLabelStack((DefaultLabelStack) labelStack, path); | ||
| 974 | } else { | 946 | } else { |
| 975 | llSubObjects = createPcepPath(path); | 947 | llSubObjects = createPcepPath(path); |
| 976 | } | 948 | } |
| ... | @@ -983,7 +955,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -983,7 +955,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 983 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | 955 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); |
| 984 | 956 | ||
| 985 | // set PathSetupTypeTlv of SRP object | 957 | // set PathSetupTypeTlv of SRP object |
| 986 | - tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)).type()); | 958 | + tlv = new PathSetupTypeTlv(lspType.type()); |
| 987 | llOptionalTlv.add(tlv); | 959 | llOptionalTlv.add(tlv); |
| 988 | 960 | ||
| 989 | // build SRP object | 961 | // build SRP object |
| ... | @@ -1115,7 +1087,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1115,7 +1087,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1115 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, DELETE); | 1087 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, DELETE); |
| 1116 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); | 1088 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); |
| 1117 | int srpId = SrpIdGenerators.create(); | 1089 | int srpId = SrpIdGenerators.create(); |
| 1118 | - TunnelId tunnelId = tunnel.tunnelId(); | ||
| 1119 | 1090 | ||
| 1120 | PcepValueType tlv; | 1091 | PcepValueType tlv; |
| 1121 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | 1092 | LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); |
| ... | @@ -1193,14 +1164,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1193,14 +1164,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1193 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, UPDATE); | 1164 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, UPDATE); |
| 1194 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); | 1165 | pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData); |
| 1195 | int srpId = SrpIdGenerators.create(); | 1166 | int srpId = SrpIdGenerators.create(); |
| 1196 | - TunnelId tunnelId = tunnel.tunnelId(); | ||
| 1197 | PcepValueType tlv; | 1167 | PcepValueType tlv; |
| 1198 | - int plspId = 0; | ||
| 1199 | 1168 | ||
| 1200 | LinkedList<PcepValueType> llSubObjects = null; | 1169 | LinkedList<PcepValueType> llSubObjects = null; |
| 1201 | - NetworkResource labelStack = tunnel.resource(); | 1170 | + LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); |
| 1202 | - if (labelStack != null && labelStack instanceof DefaultLabelStack) { | 1171 | + |
| 1203 | - llSubObjects = createPcepLabelStack((DefaultLabelStack) labelStack, path); | 1172 | + if (lspSigType == SR_WITHOUT_SIGNALLING) { |
| 1173 | + NetworkResource labelStack = tunnel.resource(); | ||
| 1174 | + if (labelStack == null || !(labelStack instanceof DefaultLabelStack)) { | ||
| 1175 | + labelStack = pcepClientController.computeLabelStack(tunnel.path()); | ||
| 1176 | + if (labelStack == null) { | ||
| 1177 | + log.error("Unable to create label stack."); | ||
| 1178 | + return; | ||
| 1179 | + } | ||
| 1180 | + } | ||
| 1181 | + llSubObjects = pcepClientController.createPcepLabelStack((DefaultLabelStack) labelStack, path); | ||
| 1204 | } else { | 1182 | } else { |
| 1205 | llSubObjects = createPcepPath(path); | 1183 | llSubObjects = createPcepPath(path); |
| 1206 | } | 1184 | } |
| ... | @@ -1209,7 +1187,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1209,7 +1187,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1209 | LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>(); | 1187 | LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>(); |
| 1210 | 1188 | ||
| 1211 | // set PathSetupTypeTlv of SRP object | 1189 | // set PathSetupTypeTlv of SRP object |
| 1212 | - LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)); | ||
| 1213 | tlv = new PathSetupTypeTlv(lspSigType.type()); | 1190 | tlv = new PathSetupTypeTlv(lspSigType.type()); |
| 1214 | llOptionalTlv.add(tlv); | 1191 | llOptionalTlv.add(tlv); |
| 1215 | 1192 | ||
| ... | @@ -1285,8 +1262,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1285,8 +1262,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1285 | } | 1262 | } |
| 1286 | } | 1263 | } |
| 1287 | 1264 | ||
| 1288 | - | ||
| 1289 | - | ||
| 1290 | private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener { | 1265 | private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener { |
| 1291 | 1266 | ||
| 1292 | @Override | 1267 | @Override |
| ... | @@ -1302,7 +1277,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1302,7 +1277,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1302 | } | 1277 | } |
| 1303 | 1278 | ||
| 1304 | TunnelId tunnelId = getTunnelId(tunnelKey); | 1279 | TunnelId tunnelId = getTunnelId(tunnelKey); |
| 1305 | - | ||
| 1306 | tunnel = buildOpticalTunnel(pcepTunnel, tunnelId); | 1280 | tunnel = buildOpticalTunnel(pcepTunnel, tunnelId); |
| 1307 | 1281 | ||
| 1308 | OperationType operType = pcepTunnel.getOperationType(); | 1282 | OperationType operType = pcepTunnel.getOperationType(); |
| ... | @@ -1737,7 +1711,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1737,7 +1711,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1737 | private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations, | 1711 | private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations, |
| 1738 | DefaultTunnelDescription td, ProviderId providerId, State tunnelState, | 1712 | DefaultTunnelDescription td, ProviderId providerId, State tunnelState, |
| 1739 | StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) { | 1713 | StatefulIPv4LspIdentifiersTlv ipv4LspIdentifiersTlv) { |
| 1740 | - //Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID | 1714 | + // Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID |
| 1741 | 1715 | ||
| 1742 | /* | 1716 | /* |
| 1743 | * If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while | 1717 | * If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while |
| ... | @@ -1891,14 +1865,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -1891,14 +1865,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
| 1891 | 1865 | ||
| 1892 | 1866 | ||
| 1893 | if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) { | 1867 | if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) { |
| 1894 | - | ||
| 1895 | // Send PCInit msg again after global reoptimization. | 1868 | // Send PCInit msg again after global reoptimization. |
| 1896 | tunnelUpdated(td, UNSTABLE); | 1869 | tunnelUpdated(td, UNSTABLE); |
| 1897 | 1870 | ||
| 1898 | - // To remove the old tunnel from store whose PLSPID is not | 1871 | + // To remove the old tunnel from store whose PLSPID is not recognized by ingress PCC. |
| 1899 | - // recognized by ingress PCC. | ||
| 1900 | tunnelRemoved(td); | 1872 | tunnelRemoved(td); |
| 1901 | - | ||
| 1902 | } else if (endOfSyncAction == REMOVE) { | 1873 | } else if (endOfSyncAction == REMOVE) { |
| 1903 | tunnelRemoved(td); | 1874 | tunnelRemoved(td); |
| 1904 | } | 1875 | } | ... | ... |
| ... | @@ -24,13 +24,16 @@ import java.util.concurrent.ConcurrentHashMap; | ... | @@ -24,13 +24,16 @@ import java.util.concurrent.ConcurrentHashMap; |
| 24 | 24 | ||
| 25 | import org.apache.felix.scr.annotations.Activate; | 25 | import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; | 26 | import org.apache.felix.scr.annotations.Deactivate; |
| 27 | +import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | ||
| 28 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 29 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 30 | +import org.onosproject.net.Path; | ||
| 27 | import org.onosproject.pcep.controller.PccId; | 31 | import org.onosproject.pcep.controller.PccId; |
| 28 | import org.onosproject.pcep.controller.PcepClient; | 32 | import org.onosproject.pcep.controller.PcepClient; |
| 29 | import org.onosproject.pcep.controller.PcepClientController; | 33 | import org.onosproject.pcep.controller.PcepClientController; |
| 30 | import org.onosproject.pcep.controller.PcepClientListener; | 34 | import org.onosproject.pcep.controller.PcepClientListener; |
| 31 | import org.onosproject.pcep.controller.PcepEventListener; | 35 | import org.onosproject.pcep.controller.PcepEventListener; |
| 32 | import org.onosproject.pcep.controller.PcepNodeListener; | 36 | import org.onosproject.pcep.controller.PcepNodeListener; |
| 33 | -import org.onosproject.pcep.controller.PcepPacketListener; | ||
| 34 | import org.onosproject.pcep.controller.driver.PcepAgent; | 37 | import org.onosproject.pcep.controller.driver.PcepAgent; |
| 35 | import org.onosproject.pcepio.protocol.PcepError; | 38 | import org.onosproject.pcepio.protocol.PcepError; |
| 36 | import org.onosproject.pcepio.protocol.PcepErrorInfo; | 39 | import org.onosproject.pcepio.protocol.PcepErrorInfo; |
| ... | @@ -39,6 +42,7 @@ import org.onosproject.pcepio.protocol.PcepErrorObject; | ... | @@ -39,6 +42,7 @@ import org.onosproject.pcepio.protocol.PcepErrorObject; |
| 39 | import org.onosproject.pcepio.protocol.PcepFactory; | 42 | import org.onosproject.pcepio.protocol.PcepFactory; |
| 40 | import org.onosproject.pcepio.protocol.PcepMessage; | 43 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 41 | import org.onosproject.pcepio.protocol.PcepVersion; | 44 | import org.onosproject.pcepio.protocol.PcepVersion; |
| 45 | +import org.onosproject.pcepio.types.PcepValueType; | ||
| 42 | 46 | ||
| 43 | import com.google.common.collect.Sets; | 47 | import com.google.common.collect.Sets; |
| 44 | 48 | ||
| ... | @@ -58,7 +62,6 @@ public class PcepClientControllerAdapter implements PcepClientController { | ... | @@ -58,7 +62,6 @@ public class PcepClientControllerAdapter implements PcepClientController { |
| 58 | 62 | ||
| 59 | protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); | 63 | protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); |
| 60 | public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet(); | 64 | public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet(); |
| 61 | - protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet(); | ||
| 62 | 65 | ||
| 63 | @Activate | 66 | @Activate |
| 64 | public void activate() { | 67 | public void activate() { |
| ... | @@ -118,16 +121,6 @@ public class PcepClientControllerAdapter implements PcepClientController { | ... | @@ -118,16 +121,6 @@ public class PcepClientControllerAdapter implements PcepClientController { |
| 118 | } | 121 | } |
| 119 | 122 | ||
| 120 | @Override | 123 | @Override |
| 121 | - public void addPacketListener(PcepPacketListener listener) { | ||
| 122 | - pcepPacketListener.add(listener); | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - @Override | ||
| 126 | - public void removePacketListener(PcepPacketListener listener) { | ||
| 127 | - pcepPacketListener.remove(listener); | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - @Override | ||
| 131 | public void writeMessage(PccId pccId, PcepMessage msg) { | 124 | public void writeMessage(PccId pccId, PcepMessage msg) { |
| 132 | this.getClient(pccId).sendMessage(msg); | 125 | this.getClient(pccId).sendMessage(msg); |
| 133 | } | 126 | } |
| ... | @@ -292,4 +285,22 @@ public class PcepClientControllerAdapter implements PcepClientController { | ... | @@ -292,4 +285,22 @@ public class PcepClientControllerAdapter implements PcepClientController { |
| 292 | return false; | 285 | return false; |
| 293 | } | 286 | } |
| 294 | } | 287 | } |
| 288 | + | ||
| 289 | + @Override | ||
| 290 | + public LabelStack computeLabelStack(Path path) { | ||
| 291 | + // TODO Auto-generated method stub | ||
| 292 | + return null; | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + @Override | ||
| 296 | + public LinkedList<PcepValueType> createPcepLabelStack(DefaultLabelStack labelStack, Path path) { | ||
| 297 | + // TODO Auto-generated method stub | ||
| 298 | + return null; | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + @Override | ||
| 302 | + public boolean allocateLocalLabel(Tunnel tunnel) { | ||
| 303 | + // TODO Auto-generated method stub | ||
| 304 | + return false; | ||
| 305 | + } | ||
| 295 | } | 306 | } | ... | ... |
-
Please register or login to post a comment