Search in sources :

Example 71 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testAddRemoveVirtualDevice.

/**
 * Tests add and remove of virtual devices.
 */
@Test
public void testAddRemoveVirtualDevice() {
    List<VirtualNetworkEvent.Type> expectedEventTypes = new ArrayList<>();
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    expectedEventTypes.add(VirtualNetworkEvent.Type.TENANT_REGISTERED);
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    expectedEventTypes.add(VirtualNetworkEvent.Type.NETWORK_ADDED);
    VirtualNetwork virtualNetwork2 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    expectedEventTypes.add(VirtualNetworkEvent.Type.NETWORK_ADDED);
    manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_ADDED);
    manager.createVirtualDevice(virtualNetwork2.id(), DID2);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_ADDED);
    Set<VirtualDevice> virtualDevices1 = manager.getVirtualDevices(virtualNetwork1.id());
    assertNotNull("The virtual device set should not be null", virtualDevices1);
    assertEquals("The virtual device set size did not match.", 1, virtualDevices1.size());
    Set<VirtualDevice> virtualDevices2 = manager.getVirtualDevices(virtualNetwork2.id());
    assertNotNull("The virtual device set should not be null", virtualDevices2);
    assertEquals("The virtual device set size did not match.", 1, virtualDevices2.size());
    for (VirtualDevice virtualDevice : virtualDevices1) {
        manager.removeVirtualDevice(virtualNetwork1.id(), virtualDevice.id());
        expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_REMOVED);
        // attempt to remove the same virtual device again - no event expected.
        manager.removeVirtualDevice(virtualNetwork1.id(), virtualDevice.id());
    }
    virtualDevices1 = manager.getVirtualDevices(virtualNetwork1.id());
    assertTrue("The virtual device set should be empty.", virtualDevices1.isEmpty());
    // Add/remove the virtual device again.
    VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_ADDED);
    manager.removeVirtualDevice(virtualDevice.networkId(), virtualDevice.id());
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_REMOVED);
    virtualDevices1 = manager.getVirtualDevices(virtualNetwork1.id());
    assertTrue("The virtual device set should be empty.", virtualDevices1.isEmpty());
    // Validate that the events were all received in the correct order.
    validateEvents(expectedEventTypes.toArray(new VirtualNetworkEvent.Type[expectedEventTypes.size()]));
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) ArrayList(java.util.ArrayList) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) Test(org.junit.Test)

Example 72 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testCreateVirtualHostWithNoVirtualPort.

/**
 * Tests adding a virtual host where no virtual port exists.
 */
@Test(expected = IllegalStateException.class)
public void testCreateVirtualHostWithNoVirtualPort() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Test(org.junit.Test)

Example 73 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testAddRemoveVirtualLink.

/**
 * Tests add and remove of virtual links.
 */
@Test
public void testAddRemoveVirtualLink() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice srcVirtualDevice = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    VirtualDevice dstVirtualDevice = manager.createVirtualDevice(virtualNetwork1.id(), DID2);
    ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork1.id(), src.deviceId(), src.port(), new ConnectPoint(srcVirtualDevice.id(), src.port()));
    ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
    manager.createVirtualPort(virtualNetwork1.id(), dst.deviceId(), dst.port(), new ConnectPoint(dstVirtualDevice.id(), dst.port()));
    manager.createVirtualLink(virtualNetwork1.id(), src, dst);
    manager.createVirtualLink(virtualNetwork1.id(), dst, src);
    Set<VirtualLink> virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
    assertNotNull("The virtual link set should not be null", virtualLinks);
    assertEquals("The virtual link set size did not match.", 2, virtualLinks.size());
    for (VirtualLink virtualLink : virtualLinks) {
        manager.removeVirtualLink(virtualLink.networkId(), virtualLink.src(), virtualLink.dst());
        // attempt to remove the same virtual link again.
        manager.removeVirtualLink(virtualLink.networkId(), virtualLink.src(), virtualLink.dst());
    }
    virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
    assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty());
    // Add/remove the virtual link again.
    VirtualLink virtualLink = manager.createVirtualLink(virtualNetwork1.id(), src, dst);
    manager.removeVirtualLink(virtualLink.networkId(), virtualLink.src(), virtualLink.dst());
    virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
    assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty());
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Test(org.junit.Test)

Example 74 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testRemoveAllElements.

/**
 * Tests when a virtual element is removed, all the other elements depending on it are also removed.
 */
@Test
public void testRemoveAllElements() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice virtualDevice1 = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    VirtualDevice virtualDevice2 = manager.createVirtualDevice(virtualNetwork1.id(), DID2);
    ConnectPoint src = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork1.id(), src.deviceId(), src.port(), new ConnectPoint(PHYDID1, PortNumber.portNumber(1)));
    ConnectPoint dst = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(2));
    manager.createVirtualPort(virtualNetwork1.id(), dst.deviceId(), dst.port(), new ConnectPoint(PHYDID2, PortNumber.portNumber(2)));
    manager.createVirtualLink(virtualNetwork1.id(), src, dst);
    manager.createVirtualLink(virtualNetwork1.id(), dst, src);
    ConnectPoint hostCp = new ConnectPoint(DID1, P1);
    manager.createVirtualPort(virtualNetwork1.id(), hostCp.deviceId(), hostCp.port(), new ConnectPoint(PHYDID1, P1));
    manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
    // When a virtual port is removed, all virtual links connected to it should also be removed.
    manager.removeVirtualPort(virtualNetwork1.id(), DID1, PortNumber.portNumber(1));
    Set<VirtualLink> virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
    assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty());
    // When a virtual port is removed, all virtual hosts located to it should also be removed.
    manager.removeVirtualPort(virtualNetwork1.id(), DID1, P1);
    Set<VirtualHost> virtualHosts = manager.getVirtualHosts(virtualNetwork1.id());
    assertTrue("The virtual host set should be empty.", virtualHosts.isEmpty());
    manager.createVirtualPort(virtualNetwork1.id(), src.deviceId(), src.port(), new ConnectPoint(PHYDID1, PortNumber.portNumber(1)));
    manager.createVirtualLink(virtualNetwork1.id(), src, dst);
    manager.createVirtualLink(virtualNetwork1.id(), dst, src);
    manager.createVirtualPort(virtualNetwork1.id(), hostCp.deviceId(), hostCp.port(), new ConnectPoint(PHYDID1, P1));
    manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
    // When a virtual device is removed, all virtual ports, hosts and links depended on it should also be removed.
    manager.removeVirtualDevice(virtualNetwork1.id(), DID1);
    Set<VirtualPort> virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), DID1);
    assertTrue("The virtual port set of DID1 should be empty", virtualPorts.isEmpty());
    virtualLinks = manager.getVirtualLinks(virtualNetwork1.id());
    assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty());
    virtualHosts = manager.getVirtualHosts(virtualNetwork1.id());
    assertTrue("The virtual host set should be empty.", virtualHosts.isEmpty());
    // When a tenantId is removed, all the virtual networks belonging to it should also be removed.
    manager.unregisterTenantId(TenantId.tenantId(tenantIdValue1));
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    Set<VirtualNetwork> virtualNetworks = manager.getVirtualNetworks(TenantId.tenantId(tenantIdValue1));
    assertNotNull("The virtual network set should not be null", virtualNetworks);
    assertTrue("The virtual network set should be empty.", virtualNetworks.isEmpty());
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) ConnectPoint(org.onosproject.net.ConnectPoint) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Test(org.junit.Test)

Example 75 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testCreateNullVirtualDevice.

/**
 * Tests adding a null virtual device.
 */
@Test(expected = NullPointerException.class)
public void testCreateNullVirtualDevice() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    manager.createVirtualDevice(virtualNetwork.id(), null);
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) 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