@Test public void testAllocateLabel() { List<LspLocalLabelInfo> lspLocalLabelInfoList; Iterator<LspLocalLabelInfo> iterator; LspLocalLabelInfo lspLocalLabelInfo; DeviceId deviceId; LabelResourceId inLabelId; LabelResourceId outLabelId; PortNumber inPort; PortNumber outPort; assertThat(pceccHandler.allocateLabel(tunnel), is(true)); pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); iterator = lspLocalLabelInfoList.iterator(); lspLocalLabelInfo = iterator.next(); deviceId = lspLocalLabelInfo.deviceId(); inLabelId = lspLocalLabelInfo.inLabelId(); outLabelId = lspLocalLabelInfo.outLabelId(); inPort = lspLocalLabelInfo.inPort(); outPort = lspLocalLabelInfo.outPort(); assertThat(deviceId, is(deviceId5)); assertThat(inLabelId, is(notNullValue())); assertThat(outLabelId, is(nullValue())); assertThat(inPort, is(port5)); assertThat(outPort, is(nullValue())); lspLocalLabelInfo = iterator.next(); deviceId = lspLocalLabelInfo.deviceId(); inLabelId = lspLocalLabelInfo.inLabelId(); outLabelId = lspLocalLabelInfo.outLabelId(); inPort = lspLocalLabelInfo.inPort(); outPort = lspLocalLabelInfo.outPort(); assertThat(deviceId, is(deviceId4)); assertThat(inLabelId, is(notNullValue())); assertThat(outLabelId, is(notNullValue())); assertThat(inPort, is(port4)); assertThat(outPort, is(port5)); lspLocalLabelInfo = iterator.next(); deviceId = lspLocalLabelInfo.deviceId(); inLabelId = lspLocalLabelInfo.inLabelId(); outLabelId = lspLocalLabelInfo.outLabelId(); inPort = lspLocalLabelInfo.inPort(); outPort = lspLocalLabelInfo.outPort(); assertThat(deviceId, is(deviceId3)); assertThat(inLabelId, is(notNullValue())); assertThat(outLabelId, is(notNullValue())); assertThat(inPort, is(port3)); assertThat(outPort, is(port4)); lspLocalLabelInfo = iterator.next(); deviceId = lspLocalLabelInfo.deviceId(); inLabelId = lspLocalLabelInfo.inLabelId(); outLabelId = lspLocalLabelInfo.outLabelId(); inPort = lspLocalLabelInfo.inPort(); outPort = lspLocalLabelInfo.outPort(); assertThat(deviceId, is(deviceId2)); assertThat(inLabelId, is(notNullValue())); assertThat(outLabelId, is(notNullValue())); assertThat(inPort, is(port2)); assertThat(outPort, is(port3)); lspLocalLabelInfo = iterator.next(); deviceId = lspLocalLabelInfo.deviceId(); inLabelId = lspLocalLabelInfo.inLabelId(); outLabelId = lspLocalLabelInfo.outLabelId(); inPort = lspLocalLabelInfo.inPort(); outPort = lspLocalLabelInfo.outPort(); assertThat(deviceId, is(deviceId1)); assertThat(inLabelId, is(nullValue())); assertThat(outLabelId, is(notNullValue())); assertThat(inPort, is(nullValue())); assertThat(outPort, is(port2)); }
public boolean allocateLabel(Tunnel tunnel) { long applyNum = 1; boolean isLastLabelToPush = false; Collection<LabelResource> labelRscList; checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); List<Link> linkList = tunnel.path().links(); if ((linkList != null) && (linkList.size() > 0)) { for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { Link link = iterator.previous(); DeviceId dstDeviceId = link.dst().deviceId(); DeviceId srcDeviceId = link.src().deviceId(); labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); if ((labelRscList != null) && (labelRscList.size() > 0)) { Iterator<LabelResource> labelIterator = labelRscList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); LabelResourceId labelId = defaultLabelResource.labelResourceId(); log.debug("Allocated local label: " + labelId.toString() + "to device: " + defaultLabelResource.deviceId().toString()); PortNumber dstPort = link.dst().port(); if (!iterator.hasPrevious()) { isLastLabelToPush = true; } installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false, Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, tunnel, isLastLabelToPush); } else { log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); releaseLabel(tunnel); return false; } } } else { log.error("Tunnel {} is having empty links.", tunnel.toString()); return false; } return true; }
BasicPceccHandler { public boolean allocateLabel(Tunnel tunnel) { long applyNum = 1; boolean isLastLabelToPush = false; Collection<LabelResource> labelRscList; checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); List<Link> linkList = tunnel.path().links(); if ((linkList != null) && (linkList.size() > 0)) { for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { Link link = iterator.previous(); DeviceId dstDeviceId = link.dst().deviceId(); DeviceId srcDeviceId = link.src().deviceId(); labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); if ((labelRscList != null) && (labelRscList.size() > 0)) { Iterator<LabelResource> labelIterator = labelRscList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); LabelResourceId labelId = defaultLabelResource.labelResourceId(); log.debug("Allocated local label: " + labelId.toString() + "to device: " + defaultLabelResource.deviceId().toString()); PortNumber dstPort = link.dst().port(); if (!iterator.hasPrevious()) { isLastLabelToPush = true; } installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false, Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, tunnel, isLastLabelToPush); } else { log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); releaseLabel(tunnel); return false; } } } else { log.error("Tunnel {} is having empty links.", tunnel.toString()); return false; } return true; } }
BasicPceccHandler { public boolean allocateLabel(Tunnel tunnel) { long applyNum = 1; boolean isLastLabelToPush = false; Collection<LabelResource> labelRscList; checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); List<Link> linkList = tunnel.path().links(); if ((linkList != null) && (linkList.size() > 0)) { for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { Link link = iterator.previous(); DeviceId dstDeviceId = link.dst().deviceId(); DeviceId srcDeviceId = link.src().deviceId(); labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); if ((labelRscList != null) && (labelRscList.size() > 0)) { Iterator<LabelResource> labelIterator = labelRscList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); LabelResourceId labelId = defaultLabelResource.labelResourceId(); log.debug("Allocated local label: " + labelId.toString() + "to device: " + defaultLabelResource.deviceId().toString()); PortNumber dstPort = link.dst().port(); if (!iterator.hasPrevious()) { isLastLabelToPush = true; } installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false, Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, tunnel, isLastLabelToPush); } else { log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); releaseLabel(tunnel); return false; } } } else { log.error("Tunnel {} is having empty links.", tunnel.toString()); return false; } return true; } private  BasicPceccHandler(); }
BasicPceccHandler { public boolean allocateLabel(Tunnel tunnel) { long applyNum = 1; boolean isLastLabelToPush = false; Collection<LabelResource> labelRscList; checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); List<Link> linkList = tunnel.path().links(); if ((linkList != null) && (linkList.size() > 0)) { for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { Link link = iterator.previous(); DeviceId dstDeviceId = link.dst().deviceId(); DeviceId srcDeviceId = link.src().deviceId(); labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); if ((labelRscList != null) && (labelRscList.size() > 0)) { Iterator<LabelResource> labelIterator = labelRscList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); LabelResourceId labelId = defaultLabelResource.labelResourceId(); log.debug("Allocated local label: " + labelId.toString() + "to device: " + defaultLabelResource.deviceId().toString()); PortNumber dstPort = link.dst().port(); if (!iterator.hasPrevious()) { isLastLabelToPush = true; } installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false, Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, tunnel, isLastLabelToPush); } else { log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); releaseLabel(tunnel); return false; } } } else { log.error("Tunnel {} is having empty links.", tunnel.toString()); return false; } return true; } private  BasicPceccHandler(); static BasicPceccHandler getInstance(); void initialize(LabelResourceService labelRsrcService, FlowObjectiveService flowObjectiveService,
                           ApplicationId appId, PceStore pceStore); boolean allocateLabel(Tunnel tunnel); void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId,
                                                PortNumber dstPort, Tunnel tunnel, boolean isLastLabelToPush); void releaseLabel(Tunnel tunnel); }
BasicPceccHandler { public boolean allocateLabel(Tunnel tunnel) { long applyNum = 1; boolean isLastLabelToPush = false; Collection<LabelResource> labelRscList; checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); List<Link> linkList = tunnel.path().links(); if ((linkList != null) && (linkList.size() > 0)) { for (ListIterator<Link> iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { Link link = iterator.previous(); DeviceId dstDeviceId = link.dst().deviceId(); DeviceId srcDeviceId = link.src().deviceId(); labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); if ((labelRscList != null) && (labelRscList.size() > 0)) { Iterator<LabelResource> labelIterator = labelRscList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); LabelResourceId labelId = defaultLabelResource.labelResourceId(); log.debug("Allocated local label: " + labelId.toString() + "to device: " + defaultLabelResource.deviceId().toString()); PortNumber dstPort = link.dst().port(); if (!iterator.hasPrevious()) { isLastLabelToPush = true; } installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), false, Long.valueOf(LabelType.IN_LABEL.value), Objective.Operation.ADD); installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, Long.valueOf(LabelType.OUT_LABEL.value), Objective.Operation.ADD); updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, tunnel, isLastLabelToPush); } else { log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); releaseLabel(tunnel); return false; } } } else { log.error("Tunnel {} is having empty links.", tunnel.toString()); return false; } return true; } private  BasicPceccHandler(); static BasicPceccHandler getInstance(); void initialize(LabelResourceService labelRsrcService, FlowObjectiveService flowObjectiveService,
                           ApplicationId appId, PceStore pceStore); boolean allocateLabel(Tunnel tunnel); void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId,
                                                PortNumber dstPort, Tunnel tunnel, boolean isLastLabelToPush); void releaseLabel(Tunnel tunnel);  }