@Test public void testAllocateNodeLabel() { String lsrId1 = "11.1.1.1"; assertThat(srTeHandler.allocateNodeLabel(D1.deviceId(), lsrId1), is(true)); LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId()); assertThat(labelId, is(notNullValue())); String lsrId2 = "12.1.1.1"; assertThat(srTeHandler.allocateNodeLabel(D2.deviceId(), lsrId2), is(true)); labelId = pceStore.getGlobalNodeLabel(D2.deviceId()); assertThat(labelId, is(notNullValue())); String lsrId3 = "13.1.1.1"; assertThat(srTeHandler.allocateNodeLabel(D3.deviceId(), lsrId3), is(true)); labelId = pceStore.getGlobalNodeLabel(D3.deviceId()); assertThat(labelId, is(notNullValue())); String lsrId4 = "14.1.1.1"; assertThat(srTeHandler.allocateNodeLabel(D4.deviceId(), lsrId4), is(true)); labelId = pceStore.getGlobalNodeLabel(D4.deviceId()); assertThat(labelId, is(notNullValue())); String lsrId5 = "15.1.1.1"; assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true)); labelId = pceStore.getGlobalNodeLabel(D5.deviceId()); assertThat(labelId, is(notNullValue())); }
public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) { long applyNum = 1; LabelResourceId specificLabelId = null; checkNotNull(specificDeviceId, DEVICE_ID_NULL); checkNotNull(specificLsrId, LSR_ID_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) { log.debug("Node label was already configured for device {}.", specificDeviceId.toString()); return false; } Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); if (result.size() > 0) { Iterator<LabelResource> iterator = result.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); specificLabelId = defaultLabelResource.labelResourceId(); if (specificLabelId == null) { log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString()); return false; } } else { log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString()); return false; } pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); advertiseNodeLabelRule(specificDeviceId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { DeviceId otherDevId = element.getKey(); LabelResourceId otherLabelId = element.getValue(); String otherLsrId = getLsrId(otherDevId); if (otherLsrId == null) { log.error("The lsr-id of device id {} is null.", otherDevId.toString()); releaseNodeLabel(specificDeviceId, specificLsrId); return false; } if (!otherDevId.equals(specificDeviceId)) { advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); } } return true; }
PceccSrTeBeHandler { public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) { long applyNum = 1; LabelResourceId specificLabelId = null; checkNotNull(specificDeviceId, DEVICE_ID_NULL); checkNotNull(specificLsrId, LSR_ID_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) { log.debug("Node label was already configured for device {}.", specificDeviceId.toString()); return false; } Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); if (result.size() > 0) { Iterator<LabelResource> iterator = result.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); specificLabelId = defaultLabelResource.labelResourceId(); if (specificLabelId == null) { log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString()); return false; } } else { log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString()); return false; } pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); advertiseNodeLabelRule(specificDeviceId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { DeviceId otherDevId = element.getKey(); LabelResourceId otherLabelId = element.getValue(); String otherLsrId = getLsrId(otherDevId); if (otherLsrId == null) { log.error("The lsr-id of device id {} is null.", otherDevId.toString()); releaseNodeLabel(specificDeviceId, specificLsrId); return false; } if (!otherDevId.equals(specificDeviceId)) { advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); } } return true; } }
PceccSrTeBeHandler { public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) { long applyNum = 1; LabelResourceId specificLabelId = null; checkNotNull(specificDeviceId, DEVICE_ID_NULL); checkNotNull(specificLsrId, LSR_ID_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) { log.debug("Node label was already configured for device {}.", specificDeviceId.toString()); return false; } Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); if (result.size() > 0) { Iterator<LabelResource> iterator = result.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); specificLabelId = defaultLabelResource.labelResourceId(); if (specificLabelId == null) { log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString()); return false; } } else { log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString()); return false; } pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); advertiseNodeLabelRule(specificDeviceId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { DeviceId otherDevId = element.getKey(); LabelResourceId otherLabelId = element.getValue(); String otherLsrId = getLsrId(otherDevId); if (otherLsrId == null) { log.error("The lsr-id of device id {} is null.", otherDevId.toString()); releaseNodeLabel(specificDeviceId, specificLsrId); return false; } if (!otherDevId.equals(specificDeviceId)) { advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); } } return true; } private  PceccSrTeBeHandler(); }
PceccSrTeBeHandler { public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) { long applyNum = 1; LabelResourceId specificLabelId = null; checkNotNull(specificDeviceId, DEVICE_ID_NULL); checkNotNull(specificLsrId, LSR_ID_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) { log.debug("Node label was already configured for device {}.", specificDeviceId.toString()); return false; } Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); if (result.size() > 0) { Iterator<LabelResource> iterator = result.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); specificLabelId = defaultLabelResource.labelResourceId(); if (specificLabelId == null) { log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString()); return false; } } else { log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString()); return false; } pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); advertiseNodeLabelRule(specificDeviceId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { DeviceId otherDevId = element.getKey(); LabelResourceId otherLabelId = element.getValue(); String otherLsrId = getLsrId(otherDevId); if (otherLsrId == null) { log.error("The lsr-id of device id {} is null.", otherDevId.toString()); releaseNodeLabel(specificDeviceId, specificLsrId); return false; } if (!otherDevId.equals(specificDeviceId)) { advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); } } return true; } private  PceccSrTeBeHandler(); static PceccSrTeBeHandler getInstance(); void initialize(LabelResourceAdminService labelRsrcAdminService, LabelResourceService labelRsrcService,
                           FlowObjectiveService flowObjectiveService, ApplicationId appId, PceStore pceStore,
                           DeviceService deviceService); boolean reserveGlobalPool(long beginLabel, long endLabel); String getLsrId(DeviceId deviceId); boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId); boolean releaseNodeLabel(DeviceId specificDeviceId, String specificLsrId); boolean allocateAdjacencyLabel(Link link); boolean releaseAdjacencyLabel(Link link); LabelStack computeLabelStack(Path path); void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, IpPrefix ipPrefix,
                                       Objective.Operation type, boolean bBos); void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, PortNumber srcPortNum,
                                    PortNumber dstPortNum, Objective.Operation type); }
PceccSrTeBeHandler { public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) { long applyNum = 1; LabelResourceId specificLabelId = null; checkNotNull(specificDeviceId, DEVICE_ID_NULL); checkNotNull(specificLsrId, LSR_ID_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) { log.debug("Node label was already configured for device {}.", specificDeviceId.toString()); return false; } Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); if (result.size() > 0) { Iterator<LabelResource> iterator = result.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); specificLabelId = defaultLabelResource.labelResourceId(); if (specificLabelId == null) { log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString()); return false; } } else { log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString()); return false; } pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); advertiseNodeLabelRule(specificDeviceId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) { DeviceId otherDevId = element.getKey(); LabelResourceId otherLabelId = element.getValue(); String otherLsrId = getLsrId(otherDevId); if (otherLsrId == null) { log.error("The lsr-id of device id {} is null.", otherDevId.toString()); releaseNodeLabel(specificDeviceId, specificLsrId); return false; } if (!otherDevId.equals(specificDeviceId)) { advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH), Objective.Operation.ADD, false); } } return true; } private  PceccSrTeBeHandler(); static PceccSrTeBeHandler getInstance(); void initialize(LabelResourceAdminService labelRsrcAdminService, LabelResourceService labelRsrcService,
                           FlowObjectiveService flowObjectiveService, ApplicationId appId, PceStore pceStore,
                           DeviceService deviceService); boolean reserveGlobalPool(long beginLabel, long endLabel); String getLsrId(DeviceId deviceId); boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId); boolean releaseNodeLabel(DeviceId specificDeviceId, String specificLsrId); boolean allocateAdjacencyLabel(Link link); boolean releaseAdjacencyLabel(Link link); LabelStack computeLabelStack(Path path); void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, IpPrefix ipPrefix,
                                       Objective.Operation type, boolean bBos); void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, PortNumber srcPortNum,
                                    PortNumber dstPortNum, Objective.Operation type);  }