@Test public void testAllocateAdjacencyLabel() { assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); LabelResourceId labelId = pceStore.getAdjLabel(link1); assertThat(labelId, is(notNullValue())); assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); labelId = pceStore.getAdjLabel(link2); assertThat(labelId, is(notNullValue())); assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true)); labelId = pceStore.getAdjLabel(link3); assertThat(labelId, is(notNullValue())); assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true)); labelId = pceStore.getAdjLabel(link4); assertThat(labelId, is(notNullValue())); }
public boolean allocateAdjacencyLabel(Link link) { long applyNum = 1; DeviceId srcDeviceId = link.src().deviceId(); Collection<LabelResource> labelList; checkNotNull(link, LINK_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); LabelResourceId labelId = pceStore.getAdjLabel(link); if (labelId != null) { log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString()); return false; } labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); if (labelList.size() <= 0) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } Iterator<LabelResource> iterator = labelList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); labelId = defaultLabelResource.labelResourceId(); if (labelId == null) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); pceStore.addAdjLabel(link, labelId); return true; }
PceccSrTeBeHandler { public boolean allocateAdjacencyLabel(Link link) { long applyNum = 1; DeviceId srcDeviceId = link.src().deviceId(); Collection<LabelResource> labelList; checkNotNull(link, LINK_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); LabelResourceId labelId = pceStore.getAdjLabel(link); if (labelId != null) { log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString()); return false; } labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); if (labelList.size() <= 0) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } Iterator<LabelResource> iterator = labelList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); labelId = defaultLabelResource.labelResourceId(); if (labelId == null) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); pceStore.addAdjLabel(link, labelId); return true; } }
PceccSrTeBeHandler { public boolean allocateAdjacencyLabel(Link link) { long applyNum = 1; DeviceId srcDeviceId = link.src().deviceId(); Collection<LabelResource> labelList; checkNotNull(link, LINK_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); LabelResourceId labelId = pceStore.getAdjLabel(link); if (labelId != null) { log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString()); return false; } labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); if (labelList.size() <= 0) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } Iterator<LabelResource> iterator = labelList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); labelId = defaultLabelResource.labelResourceId(); if (labelId == null) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); pceStore.addAdjLabel(link, labelId); return true; } private  PceccSrTeBeHandler(); }
PceccSrTeBeHandler { public boolean allocateAdjacencyLabel(Link link) { long applyNum = 1; DeviceId srcDeviceId = link.src().deviceId(); Collection<LabelResource> labelList; checkNotNull(link, LINK_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); LabelResourceId labelId = pceStore.getAdjLabel(link); if (labelId != null) { log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString()); return false; } labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); if (labelList.size() <= 0) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } Iterator<LabelResource> iterator = labelList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); labelId = defaultLabelResource.labelResourceId(); if (labelId == null) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); pceStore.addAdjLabel(link, labelId); 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 allocateAdjacencyLabel(Link link) { long applyNum = 1; DeviceId srcDeviceId = link.src().deviceId(); Collection<LabelResource> labelList; checkNotNull(link, LINK_NULL); checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); checkNotNull(pceStore, PCE_STORE_NULL); LabelResourceId labelId = pceStore.getAdjLabel(link); if (labelId != null) { log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString()); return false; } labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); if (labelList.size() <= 0) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } Iterator<LabelResource> iterator = labelList.iterator(); DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); labelId = defaultLabelResource.labelResourceId(); if (labelId == null) { log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); return false; } log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString()); installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); pceStore.addAdjLabel(link, labelId); 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);  }