Search in sources :

Example 41 with VirtualNetwork

use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testGetPortDeltaStatistics.

/**
 * Tests querying the port delta statistics of a device by device identifier.
 */
@Test
public void testGetPortDeltaStatistics() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    manager.createVirtualDevice(virtualNetwork.id(), DID2);
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    // test the getPortDeltaStatistics() method
    assertEquals("The port delta statistics set size did not match.", 0, deviceService.getPortDeltaStatistics(DID1).size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

Example 42 with VirtualNetwork

use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testDeviceEventsForAddRemovalDeviceAndPorts.

/**
 * Tests DeviceEvents received during virtual device/port addition and removal.
 */
@Test
public void testDeviceEventsForAddRemovalDeviceAndPorts() throws TestUtils.TestUtilsException {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    // add virtual device before virtual device manager is created
    VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), VDID1);
    // no DeviceEvent expected
    validateEvents();
    testDirectory.add(EventDeliveryService.class, dispatcher);
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    // virtual device manager is created; register DeviceEvent listener
    deviceService.addListener(testListener);
    // list to keep track of expected event types
    List<DeviceEvent.Type> expectedEventTypes = new ArrayList<>();
    // add virtual device
    VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), VDID2);
    expectedEventTypes.add(DeviceEvent.Type.DEVICE_ADDED);
    ConnectPoint cp = new ConnectPoint(PHYDID1, PortNumber.portNumber(1));
    // add 2 virtual ports
    manager.createVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_ADDED);
    manager.createVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(2), cp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_ADDED);
    // verify virtual ports were added
    Set<VirtualPort> virtualPorts = manager.getVirtualPorts(virtualNetwork.id(), device2.id());
    assertNotNull("The virtual port set should not be null", virtualPorts);
    assertEquals("The virtual port set size did not match.", 2, virtualPorts.size());
    virtualPorts.forEach(vp -> assertFalse("Initial virtual port state should be disabled", vp.isEnabled()));
    // verify change state of virtual port (disabled -> enabled)
    manager.updatePortState(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), true);
    Port changedPort = deviceService.getPort(device2.id(), PortNumber.portNumber(1));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be enabled", true, changedPort.isEnabled());
    expectedEventTypes.add(DeviceEvent.Type.PORT_UPDATED);
    // verify change state of virtual port (disabled -> disabled)
    manager.updatePortState(virtualNetwork.id(), device2.id(), PortNumber.portNumber(2), false);
    changedPort = deviceService.getPort(device2.id(), PortNumber.portNumber(2));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be disabled", false, changedPort.isEnabled());
    // remove 2 virtual ports
    for (VirtualPort virtualPort : virtualPorts) {
        manager.removeVirtualPort(virtualNetwork.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
        expectedEventTypes.add(DeviceEvent.Type.PORT_REMOVED);
        // attempt to remove the same virtual port again - no DeviceEvent.Type.PORT_REMOVED expected.
        manager.removeVirtualPort(virtualNetwork.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    }
    // verify virtual ports were removed
    virtualPorts = manager.getVirtualPorts(virtualNetwork.id(), device2.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // Add/remove one virtual port again.
    VirtualPort virtualPort = manager.createVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_ADDED);
    ConnectPoint newCp = new ConnectPoint(PHYDID3, PortNumber.portNumber(2));
    manager.bindVirtualPort(virtualNetwork.id(), device2.id(), PortNumber.portNumber(1), newCp);
    expectedEventTypes.add(DeviceEvent.Type.PORT_UPDATED);
    manager.removeVirtualPort(virtualNetwork.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    expectedEventTypes.add(DeviceEvent.Type.PORT_REMOVED);
    // verify no virtual ports remain
    virtualPorts = manager.getVirtualPorts(virtualNetwork.id(), device2.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // remove virtual device
    manager.removeVirtualDevice(virtualNetwork.id(), device2.id());
    expectedEventTypes.add(DeviceEvent.Type.DEVICE_REMOVED);
    // Validate that the events were all received in the correct order.
    validateEvents((Enum[]) expectedEventTypes.toArray(new DeviceEvent.Type[expectedEventTypes.size()]));
    // cleanup
    deviceService.removeListener(testListener);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DeviceEvent(org.onosproject.net.device.DeviceEvent) Port(org.onosproject.net.Port) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 43 with VirtualNetwork

use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testGetDeviceByNullType.

/**
 * Tests querying for a device using a null device type.
 */
@Test(expected = NullPointerException.class)
public void testGetDeviceByNullType() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    // test the getDevices() method with null type value.
    deviceService.getDevices(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

Example 44 with VirtualNetwork

use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testGetPortsDeltaStatisticsByNullId.

/**
 * Tests querying the port delta statistics of a device by null device identifier.
 */
@Test(expected = NullPointerException.class)
public void testGetPortsDeltaStatisticsByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    // test the getPortDeltaStatistics() method using a null device identifier
    deviceService.getPortDeltaStatistics(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

Example 45 with VirtualNetwork

use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.

the class VirtualNetworkDeviceManagerTest method testGetRole.

/**
 * Tests querying the role of a device by device identifier.
 */
@Test
public void testGetRole() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
    // test the getRole() method
    assertEquals("The expect device role did not match.", MastershipRole.MASTER, deviceService.getRole(DID1));
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

Aggregations

VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)98 Test (org.junit.Test)82 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)38 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)24 ConnectPoint (org.onosproject.net.ConnectPoint)24 TopologyService (org.onosproject.net.topology.TopologyService)24 Topology (org.onosproject.net.topology.Topology)23 DeviceService (org.onosproject.net.device.DeviceService)15 VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)12 DisjointPath (org.onosproject.net.DisjointPath)11 LinkService (org.onosproject.net.link.LinkService)10 ArrayList (java.util.ArrayList)8 HostService (org.onosproject.net.host.HostService)8 TenantId (org.onosproject.net.TenantId)7 Path (org.onosproject.net.Path)6 PathService (org.onosproject.net.topology.PathService)5 TopologyCluster (org.onosproject.net.topology.TopologyCluster)5 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)4 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)4 Link (org.onosproject.net.Link)4