[ONOS-4164] PceManager device and link event handling
Change-Id: I55d8f60e0fcc0e23f4c14045a8e20bd89f635913
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
index 4b1faaf..602c328 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
@@ -1,12 +1,15 @@
package org.onosproject.pce.pceservice;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
+import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
+import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
import static org.onosproject.net.Link.State.ACTIVE;
import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
-import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
+import static org.onosproject.net.MastershipRole.MASTER;
import static org.onosproject.net.resource.Resources.continuous;
import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
@@ -19,11 +22,11 @@
import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
+import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
-import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
-import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
-import static org.onosproject.net.MastershipRole.MASTER;
+import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
+import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
import java.net.URISyntaxException;
import java.util.Collection;
@@ -51,6 +54,7 @@
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.IdGenerator;
import org.onosproject.event.Event;
+import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
@@ -65,23 +69,25 @@
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultAnnotations.Builder;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Device;
-import org.onosproject.net.DefaultAnnotations.Builder;
-import org.onosproject.net.MastershipRole;
-import org.onosproject.net.device.DeviceServiceAdapter;
-import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.Link;
+import org.onosproject.net.MastershipRole;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.link.LinkEvent;
+import org.onosproject.net.link.LinkListener;
import org.onosproject.net.packet.DefaultInboundPacket;
import org.onosproject.net.packet.DefaultPacketContext;
import org.onosproject.net.packet.InboundPacket;
@@ -106,15 +112,16 @@
import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pcestore.api.PceStore;
+import org.onosproject.pce.util.FlowObjServiceAdapter;
import org.onosproject.pce.util.LabelResourceAdapter;
+import org.onosproject.pce.util.MockDeviceService;
+import org.onosproject.pce.util.MockLinkService;
import org.onosproject.pce.util.PceStoreAdapter;
import org.onosproject.pce.util.TunnelServiceAdapter;
import org.onosproject.pcep.api.DeviceCapability;
-import org.onosproject.pce.util.FlowObjServiceAdapter;
import org.onosproject.store.service.TestStorageService;
import com.google.common.collect.ImmutableSet;
-import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
/**
* Tests the functions of PceManager.
@@ -133,16 +140,22 @@
private PacketService packetService = new MockPacketService();
private MockDeviceService deviceService = new MockDeviceService();
private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
+ private MockLinkService linkService = new MockLinkService();
private MockFlowObjService flowObjectiveService = new MockFlowObjService();
private PceStore pceStore = new PceStoreAdapter();
private LabelResourceService labelResourceService = new LabelResourceAdapter();
+ private LabelResourceAdminService labelRsrcAdminService = new LabelResourceAdapter();
public static ProviderId providerId = new ProviderId("pce", "foo");
private static final String L3 = "L3";
private static final String LSRID = "lsrId";
+ private static final String PCECC_CAPABILITY = "pceccCapability";
+ private static final String SR_CAPABILITY = "srCapability";
+ private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
private TopologyGraph graph = null;
private Device deviceD1, deviceD2, deviceD3, deviceD4;
+ private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
private Link link1, link2, link3, link4;
protected static int flowsDownloaded;
private TunnelListener tunnelListener;
@@ -162,7 +175,9 @@
pceManager.storageService = storageService;
pceManager.packetService = packetService;
pceManager.deviceService = deviceService;
+ pceManager.linkService = linkService;
pceManager.netCfgService = netConfigRegistry;
+ pceManager.labelRsrcAdminService = labelRsrcAdminService;
pceManager.labelRsrcService = labelResourceService;
pceManager.flowObjectiveService = flowObjectiveService;
pceManager.pceStore = pceStore;
@@ -219,6 +234,7 @@
DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
+ // Making L3 devices
builderDev1.set(AnnotationKeys.TYPE, L3);
builderDev1.set(LSRID, "1.1.1.1");
@@ -1254,6 +1270,86 @@
assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
}
+ /*
+ * Tests node label allocation/removal in SR-TE case based on device event.
+ */
+ @Test
+ public void deviceEventTest() {
+ // Make four router topology with SR-TE capabilities.
+ build4RouterTopo(true, false, true, true, 0);
+
+ // Add new L3 device
+ DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
+ builderDev5.set(AnnotationKeys.TYPE, L3);
+ builderDev5.set(LSRID, "5.5.5.5");
+
+ Device dev5 = new MockDevice(DeviceId.deviceId("P005"), builderDev5.build());
+ deviceService.addDevice(dev5);
+
+ // Add capability
+ DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
+ device5Cap.setLabelStackCap(true)
+ .setLocalLabelCap(false)
+ .setSrCap(true)
+ .apply();
+
+ // Get listener
+ DeviceListener listener = deviceService.getListener();
+
+ // Generate Remove events
+ deviceService.removeDevice(dev5);
+ DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, dev5);
+ listener.event(event);
+
+ assertThat(pceStore.getGlobalNodeLabel(dev5.id()), is(nullValue()));
+ }
+
+ /**
+ * Tests adjacency label allocation/removal in SR-TE case based on link event.
+ */
+ @Test
+ public void linkEventTest() {
+ // Make four router topology with SR-TE capabilities.
+ build4RouterTopo(true, false, true, true, 0);
+
+ // Get listener
+ LinkListener listener = linkService.getListener();
+
+ // Adding link3
+ linkService.addLink(link3);
+
+ // Generate events
+ LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link3);
+ listener.event(event);
+
+ assertThat(pceStore.getAdjLabel(link3), is(notNullValue()));
+
+ // Adding link4
+ linkService.addLink(link4);
+
+ event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link4);
+ listener.event(event);
+
+ assertThat(pceStore.getAdjLabel(link4), is(notNullValue()));
+
+ // Remove link3
+ linkService.removeLink(link3);
+
+ // Generate events
+ event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
+ listener.event(event);
+
+ assertThat(pceStore.getAdjLabel(link3), is(nullValue()));
+
+ // Remove link4
+ linkService.removeLink(link4);
+
+ event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
+ listener.event(event);
+
+ assertThat(pceStore.getAdjLabel(link4), is(nullValue()));
+ }
+
@After
public void tearDown() {
pceManager.deactivate();
@@ -1264,6 +1360,9 @@
pceManager.storageService = null;
pceManager.packetService = null;
pceManager.deviceService = null;
+ pceManager.linkService = null;
+ pceManager.netCfgService = null;
+ pceManager.labelRsrcAdminService = null;
pceManager.labelRsrcService = null;
pceManager.flowObjectiveService = null;
pceManager.pceStore = null;
@@ -1441,6 +1540,7 @@
return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
}
+
@Override
public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
List<Tunnel> tunnelList = new LinkedList<>();
@@ -1483,29 +1583,6 @@
}
}
- private class MockDeviceService extends DeviceServiceAdapter {
- List<Device> devices = new LinkedList<>();
-
- private void addDevice(Device dev) {
- devices.add(dev);
- }
-
- @Override
- public Device getDevice(DeviceId deviceId) {
- for (Device dev : devices) {
- if (dev.id().equals(deviceId)) {
- return dev;
- }
- }
- return null;
- }
-
- @Override
- public Iterable<Device> getAvailableDevices() {
- return devices;
- }
- }
-
private PacketProcessor pktProcessor = null;
private class MockPacketService extends PacketServiceAdapter {
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java
index a49bb0b..70f7376 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java
@@ -19,36 +19,44 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-
import static org.onosproject.net.Link.Type.DIRECT;
+import static org.onosproject.pce.pceservice.PathComputationTest.D1;
+import static org.onosproject.pce.pceservice.PathComputationTest.D2;
+import static org.onosproject.pce.pceservice.PathComputationTest.D3;
+import static org.onosproject.pce.pceservice.PathComputationTest.D4;
+import static org.onosproject.pce.pceservice.PathComputationTest.D5;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
import java.util.List;
import java.util.LinkedList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.incubator.net.tunnel.LabelStack;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultPath;
+import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.Path;
+import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pce.util.LabelResourceAdapter;
import org.onosproject.pce.util.PceStoreAdapter;
+import org.onosproject.pce.util.MockDeviceService;
+import org.onosproject.pcep.api.DeviceCapability;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Link;
@@ -59,20 +67,24 @@
public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
+ private static final String L3 = "L3";
+ private static final String LSRID = "lsrId";
private PceccSrTeBeHandler srTeHandler;
- protected LabelResourceAdminService labelRsrcAdminService;
- protected LabelResourceService labelRsrcService;
- protected PceStore pceStore;
- private FlowObjectiveService flowObjectiveService;
private CoreService coreService;
+ private LabelResourceAdminService labelRsrcAdminService;
+ private LabelResourceService labelRsrcService;
+ private PceStore pceStore;
+ private MockDeviceService deviceService;
+ private FlowObjectiveService flowObjectiveService;
+ private MockNetConfigRegistryAdapter netCfgService = new PathComputationTest.MockNetConfigRegistryAdapter();
private ApplicationId appId;
private ProviderId providerId;
- private DeviceId deviceId1;
- private DeviceId deviceId2;
- private DeviceId deviceId3;
- private DeviceId deviceId4;
- private DeviceId deviceId5;
+ private Device deviceD1;
+ private Device deviceD2;
+ private Device deviceD3;
+ private Device deviceD4;
+ private Device deviceD5;
private PortNumber port1;
private PortNumber port2;
private PortNumber port3;
@@ -84,9 +96,6 @@
private Link link4;
private Path path1;
LabelResourceId labelId;
- private LabelResourceId labelId1 = LabelResourceId.labelResourceId(4098);
- private LabelResourceId labelId2 = LabelResourceId.labelResourceId(4099);
- private Map<DeviceId, String> deviceIdLsrIdMap;
@Before
public void setUp() throws Exception {
@@ -98,16 +107,64 @@
coreService = new PceManagerTest.MockCoreService();
appId = coreService.registerApplication("org.onosproject.pce");
pceStore = new PceStoreAdapter();
- srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore);
+ deviceService = new MockDeviceService();
+ srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore,
+ deviceService);
// Creates path
// Creates list of links
providerId = new ProviderId("of", "foo");
- deviceId1 = DeviceId.deviceId("of:A");
- deviceId2 = DeviceId.deviceId("of:B");
- deviceId3 = DeviceId.deviceId("of:C");
- deviceId4 = DeviceId.deviceId("of:D");
- deviceId5 = DeviceId.deviceId("of:E");
+
+ // Devices
+ DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
+ DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
+ DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
+ DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
+ DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
+
+ builderDev1.set(AnnotationKeys.TYPE, L3);
+ builderDev1.set(LSRID, "1.1.1.1");
+
+ builderDev2.set(AnnotationKeys.TYPE, L3);
+ builderDev2.set(LSRID, "2.2.2.2");
+
+ builderDev3.set(AnnotationKeys.TYPE, L3);
+ builderDev3.set(LSRID, "3.3.3.3");
+
+ builderDev4.set(AnnotationKeys.TYPE, L3);
+ builderDev4.set(LSRID, "4.4.4.4");
+
+ builderDev5.set(AnnotationKeys.TYPE, L3);
+ builderDev5.set(LSRID, "5.5.5.5");
+
+ deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
+ deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
+ deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
+ deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
+ deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build());
+
+ deviceService.addDevice(deviceD1);
+ deviceService.addDevice(deviceD2);
+ deviceService.addDevice(deviceD3);
+ deviceService.addDevice(deviceD4);
+ deviceService.addDevice(deviceD5);
+
+ DeviceCapability device1Cap = netCfgService.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
+ device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
+
+ DeviceCapability device2Cap = netCfgService.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
+ device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
+
+ DeviceCapability device3Cap = netCfgService.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
+ device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
+
+ DeviceCapability device4Cap = netCfgService.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
+ device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
+
+ DeviceCapability device5Cap = netCfgService.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
+ device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
+
+ // Port Numbers
port1 = PortNumber.portNumber(1);
port2 = PortNumber.portNumber(2);
port3 = PortNumber.portNumber(3);
@@ -115,41 +172,25 @@
port5 = PortNumber.portNumber(5);
List<Link> linkList = new LinkedList<>();
- link1 = DefaultLink.builder()
- .providerId(providerId)
+ link1 = DefaultLink.builder().providerId(providerId)
.annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
- .src(new ConnectPoint(deviceId1, port1))
- .dst(new ConnectPoint(deviceId2, port2))
- .type(DIRECT)
- .state(Link.State.ACTIVE)
- .build();
+ .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT)
+ .state(Link.State.ACTIVE).build();
linkList.add(link1);
- link2 = DefaultLink.builder()
- .providerId(providerId)
+ link2 = DefaultLink.builder().providerId(providerId)
.annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
- .src(new ConnectPoint(deviceId2, port2))
- .dst(new ConnectPoint(deviceId3, port3))
- .type(DIRECT)
- .state(Link.State.ACTIVE)
- .build();
+ .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT)
+ .state(Link.State.ACTIVE).build();
linkList.add(link2);
- link3 = DefaultLink.builder()
- .providerId(providerId)
+ link3 = DefaultLink.builder().providerId(providerId)
.annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
- .src(new ConnectPoint(deviceId3, port3))
- .dst(new ConnectPoint(deviceId4, port4))
- .type(DIRECT)
- .state(Link.State.ACTIVE)
- .build();
+ .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT)
+ .state(Link.State.ACTIVE).build();
linkList.add(link3);
- link4 = DefaultLink.builder()
- .providerId(providerId)
+ link4 = DefaultLink.builder().providerId(providerId)
.annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
- .src(new ConnectPoint(deviceId4, port4))
- .dst(new ConnectPoint(deviceId5, port5))
- .type(DIRECT)
- .state(Link.State.ACTIVE)
- .build();
+ .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT)
+ .state(Link.State.ACTIVE).build();
linkList.add(link4);
// Path
@@ -174,127 +215,60 @@
*/
@Test
public void testReserveGlobalPool() {
- assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN,
- GLOBAL_LABEL_SPACE_MAX), is(true));
+ assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true));
}
/**
* Checks the operation of allocateNodeLabel() method on node label.
- * Considered some nodes are already available before PceManager came up.
*/
@Test
- public void testAllocateNodeLabel1() {
- // Specific device deviceId1
-
- // Devices mapping with lsr-id
- deviceIdLsrIdMap = new HashMap<>();
+ public void testAllocateNodeLabel() {
+ // Specific device D1.deviceId
//device 1
String lsrId1 = "11.1.1.1";
- deviceIdLsrIdMap.put(deviceId1, lsrId1);
+ // Allocate node label for specific device D1deviceId
+ assertThat(srTeHandler.allocateNodeLabel(D1.deviceId(), lsrId1), is(true));
+ // Retrieve label from store
+ LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
+ // Check whether label is generated for this device D1.deviceId()
+ assertThat(labelId, is(notNullValue()));
// device 2
String lsrId2 = "12.1.1.1";
- deviceIdLsrIdMap.put(deviceId2, lsrId2);
+ // Allocate node label for specific device D2.deviceId()
+ assertThat(srTeHandler.allocateNodeLabel(D2.deviceId(), lsrId2), is(true));
+ // Retrieve label from store
+ labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
+ // Check whether label is generated for this device D2.deviceId()
+ assertThat(labelId, is(notNullValue()));
// device 3
String lsrId3 = "13.1.1.1";
- deviceIdLsrIdMap.put(deviceId3, lsrId3);
+ // Allocate node label for specific device D3.deviceId()
+ assertThat(srTeHandler.allocateNodeLabel(D3.deviceId(), lsrId3), is(true));
+ // Retrieve label from store
+ labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
+ // Check whether label is generated for this device D3.deviceId()
+ assertThat(labelId, is(notNullValue()));
// device 4
String lsrId4 = "14.1.1.1";
- deviceIdLsrIdMap.put(deviceId4, lsrId4);
+ // Allocate node label for specific device D4.deviceId()
+ assertThat(srTeHandler.allocateNodeLabel(D4.deviceId(), lsrId4), is(true));
+ // Retrieve label from store
+ labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
+ // Check whether label is generated for this device D4.deviceId()
+ assertThat(labelId, is(notNullValue()));
// device 5
String lsrId5 = "15.1.1.1";
- deviceIdLsrIdMap.put(deviceId5, lsrId5);
-
- // Considered devices are stored in deviceIdLsrIdMap.
- // Creating temporary tempDeviceIdLsrIdMap to pass to allocateNodeLabel()
- Map<DeviceId, String> tempDeviceIdLsrIdMap = new HashMap<>();
- for (Map.Entry element : deviceIdLsrIdMap.entrySet()) {
- DeviceId devId = (DeviceId) element.getKey();
- String lsrId = (String) element.getValue();
-
- // Allocate node label for specific device devId
- assertThat(srTeHandler.allocateNodeLabel(devId, lsrId, tempDeviceIdLsrIdMap), is(true));
-
- // Retrieve label from store
- LabelResourceId labelId = pceStore.getGlobalNodeLabel(devId);
-
- // Check whether label is generated for this device devId
- assertThat(labelId, is(notNullValue()));
-
- //Now add device to tempDeviceIdLsrIdMap
- tempDeviceIdLsrIdMap.put(devId, lsrId);
- }
- }
-
- /**
- * Checks the operation of allocateNodeLabel() method on node label.
- * Considered initially map is empty and keep on getting new devices from event.
- */
- @Test
- public void testAllocateNodeLabel2() {
- // Specific device deviceId1
-
- // Device-id mapping with lsr-id
- deviceIdLsrIdMap = new HashMap<>();
-
- //device 1
- String lsrId1 = "11.1.1.1";
- // Allocate node label for specific device deviceId1
- assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1, deviceIdLsrIdMap), is(true));
+ // Allocate node label for specific device D5.deviceId()
+ assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true));
// Retrieve label from store
- LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
- // Check whether label is generated for this device deviceId1
+ labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
+ // Check whether label is generated for this device D5.deviceId()
assertThat(labelId, is(notNullValue()));
- //Now add device to deviceIdLsrIdMap
- deviceIdLsrIdMap.put(deviceId1, lsrId1);
-
- // device 2
- String lsrId2 = "12.1.1.1";
- // Allocate node label for specific device deviceId2
- assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2, deviceIdLsrIdMap), is(true));
- // Retrieve label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId2);
- // Check whether label is generated for this device deviceId2
- assertThat(labelId, is(notNullValue()));
- //Now add device to deviceIdLsrIdMap
- deviceIdLsrIdMap.put(deviceId2, lsrId2);
-
- // device 3
- String lsrId3 = "13.1.1.1";
- // Allocate node label for specific device deviceId3
- assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3, deviceIdLsrIdMap), is(true));
- // Retrieve label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId3);
- // Check whether label is generated for this device deviceId3
- assertThat(labelId, is(notNullValue()));
- //Now add device to deviceIdLsrIdMap
- deviceIdLsrIdMap.put(deviceId3, lsrId3);
-
- // device 4
- String lsrId4 = "14.1.1.1";
- // Allocate node label for specific device deviceId4
- assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4, deviceIdLsrIdMap), is(true));
- // Retrieve label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId4);
- // Check whether label is generated for this device deviceId4
- assertThat(labelId, is(notNullValue()));
- //Now add device to deviceIdLsrIdMap
- deviceIdLsrIdMap.put(deviceId4, lsrId4);
-
- // device 5
- String lsrId5 = "15.1.1.1";
- // Allocate node label for specific device deviceId5
- assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5, deviceIdLsrIdMap), is(true));
- // Retrieve label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId5);
- // Check whether label is generated for this device deviceId5
- assertThat(labelId, is(notNullValue()));
- //Now add device to deviceIdLsrIdMap
- deviceIdLsrIdMap.put(deviceId5, lsrId5);
}
/**
@@ -302,69 +276,59 @@
*/
@Test
public void testReleaseNodeLabelSuccess() {
- testAllocateNodeLabel2();
- // Specific device deviceId1
+ testAllocateNodeLabel();
+ // Specific device D1.deviceId()
//device 1
String lsrId1 = "11.1.1.1";
// Check whether successfully released node label
- assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1, deviceIdLsrIdMap), is(true));
+ assertThat(srTeHandler.releaseNodeLabel(D1.deviceId(), lsrId1), is(true));
// Check whether successfully removed label from store
- LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
+ LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
assertThat(labelId, is(nullValue()));
- // Remove released deviceId1
- deviceIdLsrIdMap.remove(deviceId1);
//device 2
String lsrId2 = "12.1.1.1";
// Check whether successfully released node label
- assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2, deviceIdLsrIdMap), is(true));
+ assertThat(srTeHandler.releaseNodeLabel(D2.deviceId(), lsrId2), is(true));
// Check whether successfully removed label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId2);
+ labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
assertThat(labelId, is(nullValue()));
- // Remove released deviceId2
- deviceIdLsrIdMap.remove(deviceId2);
//device 3
String lsrId3 = "13.1.1.1";
// Check whether successfully released node label
- assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3, deviceIdLsrIdMap), is(true));
+ assertThat(srTeHandler.releaseNodeLabel(D3.deviceId(), lsrId3), is(true));
// Check whether successfully removed label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId3);
+ labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
assertThat(labelId, is(nullValue()));
- // Remove released deviceId3
- deviceIdLsrIdMap.remove(deviceId3);
//device 4
String lsrId4 = "14.1.1.1";
// Check whether successfully released node label
- assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4, deviceIdLsrIdMap), is(true));
+ assertThat(srTeHandler.releaseNodeLabel(D4.deviceId(), lsrId4), is(true));
// Check whether successfully removed label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId4);
+ labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
assertThat(labelId, is(nullValue()));
- // Remove released deviceId4
- deviceIdLsrIdMap.remove(deviceId4);
//device 5
String lsrId5 = "15.1.1.1";
// Check whether successfully released node label
- assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5, deviceIdLsrIdMap), is(true));
+ assertThat(srTeHandler.releaseNodeLabel(D5.deviceId(), lsrId5), is(true));
// Check whether successfully removed label from store
- labelId = pceStore.getGlobalNodeLabel(deviceId5);
+ labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
assertThat(labelId, is(nullValue()));
- // Remove released deviceId5
- deviceIdLsrIdMap.remove(deviceId5);
}
@Test
public void testReleaseNodeLabelFailure() {
- testAllocateNodeLabel2();
+ testAllocateNodeLabel();
//device 6
String lsrId6 = "16.1.1.1";
// Check whether successfully released node label
DeviceId deviceId6 = DeviceId.deviceId("foo6");
- assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6, deviceIdLsrIdMap), is(false));
+ assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false));
}
/**
@@ -430,15 +394,15 @@
public void testComputeLabelStack() {
// Allocate node labels to each devices
labelId = LabelResourceId.labelResourceId(4097);
- pceStore.addGlobalNodeLabel(deviceId1, labelId);
+ pceStore.addGlobalNodeLabel(D1.deviceId(), labelId);
labelId = LabelResourceId.labelResourceId(4098);
- pceStore.addGlobalNodeLabel(deviceId2, labelId);
+ pceStore.addGlobalNodeLabel(D2.deviceId(), labelId);
labelId = LabelResourceId.labelResourceId(4099);
- pceStore.addGlobalNodeLabel(deviceId3, labelId);
+ pceStore.addGlobalNodeLabel(D3.deviceId(), labelId);
labelId = LabelResourceId.labelResourceId(4100);
- pceStore.addGlobalNodeLabel(deviceId4, labelId);
+ pceStore.addGlobalNodeLabel(D4.deviceId(), labelId);
labelId = LabelResourceId.labelResourceId(4101);
- pceStore.addGlobalNodeLabel(deviceId5, labelId);
+ pceStore.addGlobalNodeLabel(D5.deviceId(), labelId);
// Allocate adjacency labels to each devices
labelId = LabelResourceId.labelResourceId(5122);
@@ -453,42 +417,48 @@
// Compute label stack
LabelStack labelStack = srTeHandler.computeLabelStack(path1);
- // check node-label of deviceId1
+ // check node-label of D1.deviceId()
List<LabelResourceId> labelList = labelStack.labelResources();
Iterator<LabelResourceId> iterator = labelList.iterator();
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(4097)));
- // check adjacency label of deviceId1
+ // check adjacency label of D1.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(5122)));
- // check node-label of deviceId2
+ // check node-label of D2.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(4098)));
- // check adjacency label of deviceId2
+ // check adjacency label of D2.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(5123)));
- // check node-label of deviceId3
+ // check node-label of D3.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(4099)));
- // check adjacency label of deviceId3
+ // check adjacency label of D3.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(5124)));
- // check node-label of deviceId4
+ // check node-label of D4.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(4100)));
- // check adjacency label of deviceId4
+ // check adjacency label of D4.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(5125)));
- // check node-label of deviceId5
+ // check node-label of D5.deviceId()
labelId = iterator.next();
assertThat(labelId, is(LabelResourceId.labelResourceId(4101)));
}
+
+ private class MockDevice extends DefaultDevice {
+ MockDevice(DeviceId id, Annotations annotations) {
+ super(null, id, null, null, null, null, null, null, annotations);
+ }
+ }
}