Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.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 | } |