blob: c547b3590687ef227f8ee4130c8ea9c0dde54f5d [file] [log] [blame]
Avantika-Huawei9e848e82016-09-01 12:12:42 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Avantika-Huawei9e848e82016-09-01 12:12:42 +05303 *
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 */
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053016package org.onosproject.pcep.server.impl;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053017
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Collection;
21import java.util.Iterator;
22import java.util.List;
23import java.util.ListIterator;
24import java.util.LinkedList;
25
26import org.onlab.packet.Ip4Address;
27import org.onlab.packet.IpAddress;
28import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
29import org.onosproject.incubator.net.resource.label.LabelResource;
30import org.onosproject.incubator.net.resource.label.LabelResourceId;
31import org.onosproject.incubator.net.resource.label.LabelResourceService;
32import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
33import org.onosproject.incubator.net.tunnel.Tunnel;
34import org.onosproject.net.ConnectPoint;
35import org.onosproject.net.Device;
36import org.onosproject.net.DeviceId;
37import org.onosproject.net.PortNumber;
38import org.onosproject.net.device.DeviceService;
39import org.onosproject.pcelabelstore.DefaultLspLocalLabelInfo;
40import org.onosproject.pcelabelstore.PcepLabelOp;
41import org.onosproject.pcelabelstore.api.LspLocalLabelInfo;
42import org.onosproject.pcelabelstore.api.PceLabelStore;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053043import org.onosproject.pcep.server.LspType;
44import org.onosproject.pcep.server.PccId;
45import org.onosproject.pcep.server.PcepAnnotationKeys;
46import org.onosproject.pcep.server.PcepClient;
47import org.onosproject.pcep.server.PcepClientController;
48import org.onosproject.pcep.server.SrpIdGenerators;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053049import org.onosproject.pcepio.exceptions.PcepParseException;
50import org.onosproject.pcepio.protocol.PcepAttribute;
51import org.onosproject.pcepio.protocol.PcepBandwidthObject;
52import org.onosproject.pcepio.protocol.PcepEroObject;
53import org.onosproject.pcepio.protocol.PcepLabelObject;
54import org.onosproject.pcepio.protocol.PcepLabelUpdate;
55import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
56import org.onosproject.pcepio.protocol.PcepLspObject;
57import org.onosproject.pcepio.protocol.PcepMsgPath;
58import org.onosproject.pcepio.protocol.PcepSrpObject;
59import org.onosproject.pcepio.protocol.PcepUpdateMsg;
60import org.onosproject.pcepio.protocol.PcepUpdateRequest;
61import org.onosproject.pcepio.types.IPv4SubObject;
62import org.onosproject.pcepio.types.NexthopIPv4addressTlv;
63import org.onosproject.pcepio.types.PathSetupTypeTlv;
64import org.onosproject.pcepio.types.PcepLabelDownload;
65import org.onosproject.pcepio.types.PcepValueType;
66import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
67import org.onosproject.pcepio.types.SymbolicPathNameTlv;
68import org.onosproject.net.Link;
69import org.onosproject.net.Path;
70import org.slf4j.Logger;
71import org.slf4j.LoggerFactory;
72
73import com.google.common.collect.ArrayListMultimap;
74import com.google.common.collect.Multimap;
75
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053076import static org.onosproject.pcep.server.PcepAnnotationKeys.BANDWIDTH;
77import static org.onosproject.pcep.server.PcepAnnotationKeys.LSP_SIG_TYPE;
78import static org.onosproject.pcep.server.PcepAnnotationKeys.PCE_INIT;
79import static org.onosproject.pcep.server.PcepAnnotationKeys.DELEGATE;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053080
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 */
89public 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
Ray Milkeyef794342016-11-09 16:20:29 -0800127 * @param deviceService device service
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530128 * @param pceStore pce label store
Ray Milkeyef794342016-11-09 16:20:29 -0800129 * @param clientController client controller
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530130 */
131 public void initialize(LabelResourceService labelRsrcService,
132 DeviceService deviceService,
133 PceLabelStore pceStore,
134 PcepClientController clientController) {
135 this.labelRsrcService = labelRsrcService;
136 this.deviceService = deviceService;
137 this.pceStore = pceStore;
138 this.clientController = clientController;
139 }
140
141 /**
142 * Allocates labels from local resource pool and configure these (IN and OUT) labels into devices.
143 *
144 * @param tunnel tunnel between ingress to egress
145 * @return success or failure
146 */
147 public boolean allocateLabel(Tunnel tunnel) {
148 long applyNum = 1;
149 boolean isLastLabelToPush = false;
150 Collection<LabelResource> labelRscList;
151
152 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
153 checkNotNull(pceStore, PCE_STORE_NULL);
154
155 List<Link> linkList = tunnel.path().links();
Jon Hallcbd1b392017-01-18 20:15:44 -0800156 if ((linkList != null) && (!linkList.isEmpty())) {
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530157 // Sequence through reverse order to push local labels into devices
158 // Generation of labels from egress to ingress
159 for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) {
160 Link link = iterator.previous();
161 DeviceId dstDeviceId = link.dst().deviceId();
162 DeviceId srcDeviceId = link.src().deviceId();
163 labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum);
Jon Hallcbd1b392017-01-18 20:15:44 -0800164 if ((labelRscList != null) && (!labelRscList.isEmpty())) {
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530165 // Link label value is taken from destination device local pool.
166 // [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes.
167 // Link label value is used as OUT and IN for both ends
168 // (source and destination devices) of the link.
169 // Currently only one label is allocated to a device (destination device).
170 // So, no need to iterate through list
171 Iterator<LabelResource> labelIterator = labelRscList.iterator();
172 DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next();
173 LabelResourceId labelId = defaultLabelResource.labelResourceId();
174 log.debug("Allocated local label: " + labelId.toString()
175 + "to device: " + defaultLabelResource.deviceId().toString());
176 PortNumber dstPort = link.dst().port();
177
178 // Check whether this is last link label to push
179 if (!iterator.hasPrevious()) {
180 isLastLabelToPush = true;
181 }
182
183 try {
184 // Push into destination device
185 // Destination device IN port is link.dst().port()
186 pushLocalLabels(dstDeviceId, labelId, dstPort, tunnel, false,
187 Long.valueOf(LabelType.IN_LABEL.value), PcepLabelOp.ADD);
188
189 // Push into source device
190 // Source device OUT port will be link.dst().port(). Means its remote port used to send packet.
191 pushLocalLabels(srcDeviceId, labelId, dstPort, tunnel, isLastLabelToPush,
192 Long.valueOf(LabelType.OUT_LABEL.value), PcepLabelOp.ADD);
193 } catch (PcepParseException e) {
194 log.error("Failed to push local label for device {} or {} for tunnel {}.",
195 dstDeviceId.toString(), srcDeviceId.toString(), tunnel.tunnelName().toString());
196 }
197
198 // Add or update pcecc tunnel info in pce store.
199 updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort,
200 tunnel);
201 } else {
202 log.error("Unable to allocate label to device id {}.", dstDeviceId.toString());
203 releaseLabel(tunnel);
204 return false;
205 }
206 }
207 } else {
208 log.error("Tunnel {} is having empty links.", tunnel.toString());
209 return false;
210 }
211 return true;
212 }
213
214 /**
215 * Updates list of local labels of PCECC tunnel info in pce store.
216 *
217 * @param srcDeviceId source device in a link
218 * @param dstDeviceId destination device in a link
219 * @param labelId label id of a link
220 * @param dstPort destination device port number of a link
221 * @param tunnel tunnel
222 */
223 public void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId,
224 PortNumber dstPort, Tunnel tunnel) {
225 // First try to retrieve device from store and update its label id if it is exists,
226 // otherwise add it
227 boolean dstDeviceUpdated = false;
228 boolean srcDeviceUpdated = false;
229
230 List<LspLocalLabelInfo> lspLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
Jon Hallcbd1b392017-01-18 20:15:44 -0800231 if ((lspLabelInfoList != null) && (!lspLabelInfoList.isEmpty())) {
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530232 for (int i = 0; i < lspLabelInfoList.size(); ++i) {
233 LspLocalLabelInfo lspLocalLabelInfo =
234 lspLabelInfoList.get(i);
235 LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null;
236 if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) {
237 lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo);
238 lspLocalLabelInfoBuilder.inLabelId(labelId);
239 // Destination device IN port will be link destination port
240 lspLocalLabelInfoBuilder.inPort(dstPort);
241 dstDeviceUpdated = true;
242 } else if (srcDeviceId.equals(lspLocalLabelInfo.deviceId())) {
243 lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo);
244 lspLocalLabelInfoBuilder.outLabelId(labelId);
245 // Source device OUT port will be link destination (remote) port
246 lspLocalLabelInfoBuilder.outPort(dstPort);
247 srcDeviceUpdated = true;
248 }
249
250 // Update
251 if ((lspLocalLabelInfoBuilder != null) && (dstDeviceUpdated || srcDeviceUpdated)) {
252 lspLabelInfoList.set(i, lspLocalLabelInfoBuilder.build());
253 }
254 }
255 }
256
257 // If it is not found in store then add it to store
258 if (!dstDeviceUpdated || !srcDeviceUpdated) {
259 // If tunnel info itself not available then create new one, otherwise add node to list.
260 if (lspLabelInfoList == null) {
261 lspLabelInfoList = new LinkedList<>();
262 }
263
264 if (!dstDeviceUpdated) {
265 LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
266 .deviceId(dstDeviceId)
267 .inLabelId(labelId)
268 .outLabelId(null)
269 .inPort(dstPort) // Destination device IN port will be link destination port
270 .outPort(null)
271 .build();
272 lspLabelInfoList.add(lspLocalLabelInfo);
273 }
274
275 if (!srcDeviceUpdated) {
276 LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
277 .deviceId(srcDeviceId)
278 .inLabelId(null)
279 .outLabelId(labelId)
280 .inPort(null)
281 .outPort(dstPort) // Source device OUT port will be link destination (remote) port
282 .build();
283 lspLabelInfoList.add(lspLocalLabelInfo);
284 }
285
286 pceStore.addTunnelInfo(tunnel.tunnelId(), lspLabelInfoList);
287 }
288 }
289
290 /**
291 * Deallocates unused labels to device pools.
292 *
293 * @param tunnel tunnel between ingress to egress
294 */
295 public void releaseLabel(Tunnel tunnel) {
296
297 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
298 checkNotNull(pceStore, PCE_STORE_NULL);
299
300 Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create();
301 List<LspLocalLabelInfo> lspLocalLabelInfoList = pceStore.getTunnelInfo(tunnel.tunnelId());
Jon Hallcbd1b392017-01-18 20:15:44 -0800302 if ((lspLocalLabelInfoList != null) && (!lspLocalLabelInfoList.isEmpty())) {
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530303 for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) {
304 LspLocalLabelInfo lspLocalLabelInfo = iterator.next();
305 DeviceId deviceId = lspLocalLabelInfo.deviceId();
306 LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId();
307 LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId();
308 PortNumber inPort = lspLocalLabelInfo.inPort();
309 PortNumber outPort = lspLocalLabelInfo.outPort();
310
311 try {
312 // Push into device
313 if ((outLabelId != null) && (outPort != null)) {
314 pushLocalLabels(deviceId, outLabelId, outPort, tunnel, false,
315 Long.valueOf(LabelType.OUT_LABEL.value), PcepLabelOp.REMOVE);
316 }
317
318 if ((inLabelId != null) && (inPort != null)) {
319 pushLocalLabels(deviceId, inLabelId, inPort, tunnel, false,
320 Long.valueOf(LabelType.IN_LABEL.value), PcepLabelOp.REMOVE);
321 }
322 } catch (PcepParseException e) {
323 log.error("Failed to push local label for device {}for tunnel {}.", deviceId.toString(),
324 tunnel.tunnelName().toString());
325 }
326
327 // List is stored from egress to ingress. So, using IN label id to release.
328 // Only one local label is assigned to device (destination node)
329 // and that is used as OUT label for source node.
330 // No need to release label for last node in the list from pool because label was not allocated to
331 // ingress node (source node).
332 if ((iterator.hasNext()) && (inLabelId != null)) {
333 LabelResource labelRsc = new DefaultLabelResource(deviceId, inLabelId);
334 release.put(deviceId, labelRsc);
335 }
336 }
337 }
338
339 // Release from label pool
340 if (!release.isEmpty()) {
341 labelRsrcService.releaseToDevicePool(release);
342 }
343
344 pceStore.removeTunnelInfo(tunnel.tunnelId());
345 }
346
347 //Pushes local labels to the device which is specific to path [CR-case].
348 private void pushLocalLabels(DeviceId deviceId, LabelResourceId labelId,
349 PortNumber portNum, Tunnel tunnel,
350 Boolean isBos, Long labelType, PcepLabelOp type) throws PcepParseException {
351
352 checkNotNull(deviceId);
353 checkNotNull(labelId);
354 checkNotNull(portNum);
355 checkNotNull(tunnel);
356 checkNotNull(labelType);
357 checkNotNull(type);
358
359 PcepClient pc = getPcepClient(deviceId);
360 if (pc == null) {
361 log.error("PCEP client not found");
362 return;
363 }
364
365 PcepLspObject lspObj;
366 LinkedList<PcepLabelUpdate> labelUpdateList = new LinkedList<>();
367 LinkedList<PcepLabelObject> labelObjects = new LinkedList<>();
368 PcepSrpObject srpObj;
369 PcepLabelDownload labelDownload = new PcepLabelDownload();
370 LinkedList<PcepValueType> optionalTlv = new LinkedList<>();
371
372 long portNo = portNum.toLong();
373 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
374
375 optionalTlv.add(NexthopIPv4addressTlv.of((int) portNo));
376
377 PcepLabelObject labelObj = pc.factory().buildLabelObject()
378 .setOFlag(labelType == OUT_LABEL_TYPE ? true : false)
379 .setOptionalTlv(optionalTlv)
380 .setLabel((int) labelId.labelId())
381 .build();
382
383 /**
384 * Check whether transit node or not. For transit node, label update message should include IN and OUT labels.
385 * Hence store IN label object and next when out label comes add IN and OUT label objects and encode label
386 * update message and send to specified client.
387 */
388 if (!deviceId.equals(tunnel.path().src().deviceId()) && !deviceId.equals(tunnel.path().dst().deviceId())) {
389 //Device is transit node
390 if (labelType == OUT_LABEL_TYPE) {
391 //Store label object having IN label value
392 this.labelObj = labelObj;
393 return;
394 }
395 //Add IN label object
396 labelObjects.add(this.labelObj);
397 }
398
399 //Add OUT label object in case of transit node
400 labelObjects.add(labelObj);
401
402 srpObj = getSrpObject(pc, type, false);
403
404 String lspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID);
405 String plspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID);
406 String tunnelIdentifier = tunnel.annotations().value(PcepAnnotationKeys.PCC_TUNNEL_ID);
407
408 LinkedList<PcepValueType> tlvs = new LinkedList<>();
409 StatefulIPv4LspIdentifiersTlv lspIdTlv = new StatefulIPv4LspIdentifiersTlv(((IpTunnelEndPoint) tunnel.src())
410 .ip().getIp4Address().toInt(), Short.valueOf(lspId), Short.valueOf(tunnelIdentifier),
411 ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt(),
412 ((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt());
413 tlvs.add(lspIdTlv);
414
415 if (tunnel.tunnelName().value() != null) {
416 SymbolicPathNameTlv pathNameTlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
417 tlvs.add(pathNameTlv);
418 }
419
420 boolean delegated = (tunnel.annotations().value(DELEGATE) == null) ? false
421 : Boolean.valueOf(tunnel.annotations()
422 .value(DELEGATE));
423 boolean initiated = (tunnel.annotations().value(PCE_INIT) == null) ? false
424 : Boolean.valueOf(tunnel.annotations()
425 .value(PCE_INIT));
426
427 lspObj = pc.factory().buildLspObject()
428 .setRFlag(false)
429 .setAFlag(true)
430 .setDFlag(delegated)
431 .setCFlag(initiated)
432 .setPlspId(Integer.valueOf(plspId))
433 .setOptionalTlv(tlvs)
434 .build();
435
436 labelDownload.setLabelList(labelObjects);
437 labelDownload.setLspObject(lspObj);
438 labelDownload.setSrpObject(srpObj);
439
440 labelUpdateList.add(pc.factory().buildPcepLabelUpdateObject()
441 .setLabelDownload(labelDownload)
442 .build());
443
444 PcepLabelUpdateMsg labelMsg = pc.factory().buildPcepLabelUpdateMsg()
445 .setPcLabelUpdateList(labelUpdateList)
446 .build();
447
448 pc.sendMessage(labelMsg);
449
450 //If isBos is true, label download is done along the LSP, send PCEP update message.
451 if (isBos) {
452 sendPcepUpdateMsg(pc, lspObj, tunnel);
453 }
454 }
455
456 //Sends PCEP update message.
457 private void sendPcepUpdateMsg(PcepClient pc, PcepLspObject lspObj, Tunnel tunnel) throws PcepParseException {
458 LinkedList<PcepUpdateRequest> updateRequestList = new LinkedList<>();
459 LinkedList<PcepValueType> subObjects = createEroSubObj(tunnel.path());
460
461 if (subObjects == null) {
462 log.error("ERO subjects not present");
463 return;
464 }
465
466 // set PathSetupTypeTlv of SRP object
467 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
468 LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
469 llOptionalTlv.add(new PathSetupTypeTlv(lspSigType.type()));
470
471 PcepSrpObject srpObj = pc.factory().buildSrpObject()
472 .setRFlag(false)
473 .setSrpID(SrpIdGenerators.create())
474 .setOptionalTlv(llOptionalTlv)
475 .build();
476
477 PcepEroObject eroObj = pc.factory().buildEroObject()
478 .setSubObjects(subObjects)
479 .build();
480
481 float iBandwidth = 0;
482 if (tunnel.annotations().value(BANDWIDTH) != null) {
483 //iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH)));
484 iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
485 }
486 // build bandwidth object
487 PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject()
488 .setBandwidth(iBandwidth)
489 .build();
490 // build pcep attribute
491 PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute()
492 .setBandwidthObject(bandwidthObject)
493 .build();
494
495 PcepMsgPath msgPath = pc.factory().buildPcepMsgPath()
496 .setEroObject(eroObj)
497 .setPcepAttribute(pcepAttribute)
498 .build();
499
500 PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest()
501 .setSrpObject(srpObj)
502 .setMsgPath(msgPath)
503 .setLspObject(lspObj)
504 .build();
505
506 updateRequestList.add(updateReq);
507
508 //TODO: P = 1 is it P flag in PCEP obj header
509 PcepUpdateMsg updateMsg = pc.factory().buildUpdateMsg()
510 .setUpdateRequestList(updateRequestList)
511 .build();
512
513 pc.sendMessage(updateMsg);
514 }
515
516 private LinkedList<PcepValueType> createEroSubObj(Path path) {
517 LinkedList<PcepValueType> subObjects = new LinkedList<>();
518 List<Link> links = path.links();
519 ConnectPoint source = null;
520 ConnectPoint destination = null;
521 IpAddress ipDstAddress = null;
522 IpAddress ipSrcAddress = null;
523 PcepValueType subObj = null;
524 long portNo;
525
526 for (Link link : links) {
527 source = link.src();
528 if (!(source.equals(destination))) {
529 //set IPv4SubObject for ERO object
530 portNo = source.port().toLong();
531 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
532 ipSrcAddress = Ip4Address.valueOf((int) portNo);
533 subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
534 subObjects.add(subObj);
535 }
536
537 destination = link.dst();
538 portNo = destination.port().toLong();
539 portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
540 ipDstAddress = Ip4Address.valueOf((int) portNo);
541 subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
542 subObjects.add(subObj);
543 }
544 return subObjects;
545 }
546
547 private PcepSrpObject getSrpObject(PcepClient pc, PcepLabelOp type, boolean bSFlag)
548 throws PcepParseException {
549 PcepSrpObject srpObj;
550 boolean bRFlag = false;
551
552 if (!type.equals(PcepLabelOp.ADD)) {
553 // To cleanup labels, R bit is set
554 bRFlag = true;
555 }
556
557 srpObj = pc.factory().buildSrpObject()
558 .setRFlag(bRFlag)
559 .setSFlag(bSFlag)
560 .setSrpID(SrpIdGenerators.create())
561 .build();
562
563 return srpObj;
564 }
565
566 /**
567 * Returns PCEP client.
568 *
569 * @return PCEP client
570 */
571 private PcepClient getPcepClient(DeviceId deviceId) {
572 Device device = deviceService.getDevice(deviceId);
573
574 // In future projections instead of annotations will be used to fetch LSR ID.
575 String lsrId = device.annotations().value(LSRID);
576 PcepClient pcc = clientController.getClient(PccId.pccId(IpAddress.valueOf(lsrId)));
577 return pcc;
578 }
579}