Search in sources :

Example 31 with VirtualDevice

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

the class VirtualNetworkLinkManagerTest method testGetLinks.

/**
 * Tests the getLinks(), getActiveLinks(), getLinkCount(), getLink(),
 * getLinks(ConnectPoint), getDeviceLinks(), getDeviceEgressLinks(), getDeviceIngressLinks(),
 * getEgressLinks(), getIngressLinks() methods.
 */
@Test
public void testGetLinks() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice srcVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID2);
    ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork.id(), src.deviceId(), src.port(), new ConnectPoint(srcVirtualDevice.id(), src.port()));
    ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
    manager.createVirtualPort(virtualNetwork.id(), dst.deviceId(), dst.port(), new ConnectPoint(dstVirtualDevice.id(), dst.port()));
    VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst);
    VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), dst, src);
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getLinks() method
    Iterator<Link> it = linkService.getLinks().iterator();
    assertEquals("The link set size did not match.", 2, Iterators.size(it));
    // test the getActiveLinks() method where all links are INACTIVE
    Iterator<Link> it2 = linkService.getActiveLinks().iterator();
    assertEquals("The link set size did not match.", 0, Iterators.size(it2));
    // test the getActiveLinks() method where one link is ACTIVE
    virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
    Iterator<Link> it3 = linkService.getActiveLinks().iterator();
    assertEquals("The link set size did not match.", 1, Iterators.size(it3));
    // test the getLinkCount() method
    assertEquals("The link set size did not match.", 2, linkService.getLinkCount());
    // test the getLink() method
    assertEquals("The expect link did not match.", link1, linkService.getLink(src, dst));
    assertEquals("The expect link did not match.", link2, linkService.getLink(dst, src));
    assertNotEquals("The expect link should not have matched.", link1, linkService.getLink(dst, src));
    // test the getLinks(ConnectPoint) method
    assertEquals("The link set size did not match.", 2, linkService.getLinks(src).size());
    assertEquals("The link set size did not match.", 2, linkService.getLinks(dst).size());
    ConnectPoint connectPoint = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(3));
    assertEquals("The link set size did not match.", 0, linkService.getLinks(connectPoint).size());
    // test the getDeviceLinks() method
    assertEquals("The link set size did not match.", 2, linkService.getDeviceLinks(DID1).size());
    assertEquals("The link set size did not match.", 2, linkService.getDeviceLinks(DID2).size());
    assertEquals("The link set size did not match.", 0, linkService.getDeviceLinks(DID3).size());
    // test the getDeviceEgressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getDeviceEgressLinks(DID1).size());
    assertEquals("The link set size did not match.", 1, linkService.getDeviceEgressLinks(DID2).size());
    assertEquals("The link set size did not match.", 0, linkService.getDeviceEgressLinks(DID3).size());
    // test the getDeviceIngressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getDeviceIngressLinks(DID1).size());
    assertEquals("The link set size did not match.", 1, linkService.getDeviceIngressLinks(DID2).size());
    assertEquals("The link set size did not match.", 0, linkService.getDeviceIngressLinks(DID3).size());
    // test the getEgressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getEgressLinks(src).size());
    assertEquals("The link set size did not match.", 1, linkService.getEgressLinks(dst).size());
    assertEquals("The link set size did not match.", 0, linkService.getEgressLinks(connectPoint).size());
    // test the getIngressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getIngressLinks(src).size());
    assertEquals("The link set size did not match.", 1, linkService.getIngressLinks(dst).size());
    assertEquals("The link set size did not match.", 0, linkService.getIngressLinks(connectPoint).size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) LinkService(org.onosproject.net.link.LinkService) Link(org.onosproject.net.Link) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Test(org.junit.Test)

Example 32 with VirtualDevice

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

the class VirtualNetworkManagerTest method testAddSameVirtualLink.

/**
 * Tests adding the same virtual link twice.
 */
@Test(expected = IllegalStateException.class)
public void testAddSameVirtualLink() {
    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(), src, dst);
}
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) Test(org.junit.Test)

Example 33 with VirtualDevice

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

the class VirtualNetworkManagerTest method setupVirtualNetworkTopology.

/**
 * Method to create the virtual network for {@code tenantIdValue} for further testing.
 */
private VirtualNetwork setupVirtualNetworkTopology(String tenantIdValue) {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue));
    VirtualDevice virtualDevice1 = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice virtualDevice2 = manager.createVirtualDevice(virtualNetwork.id(), DID2);
    VirtualDevice virtualDevice3 = manager.createVirtualDevice(virtualNetwork.id(), DID3);
    VirtualDevice virtualDevice4 = manager.createVirtualDevice(virtualNetwork.id(), DID4);
    VirtualDevice virtualDevice5 = manager.createVirtualDevice(virtualNetwork.id(), DID5);
    ConnectPoint cp1 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), PortNumber.portNumber(1), cp1);
    ConnectPoint cp2 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(2));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), PortNumber.portNumber(2), cp2);
    ConnectPoint cp3 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(3));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), PortNumber.portNumber(3), cp3);
    ConnectPoint cp4 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(4));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), PortNumber.portNumber(4), cp4);
    ConnectPoint cp5 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(5));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), PortNumber.portNumber(5), cp5);
    cp6 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(6));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), PortNumber.portNumber(6), cp6);
    cp7 = new ConnectPoint(virtualDevice4.id(), PortNumber.portNumber(7));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice4.id(), PortNumber.portNumber(7), cp7);
    ConnectPoint cp8 = new ConnectPoint(virtualDevice4.id(), PortNumber.portNumber(8));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice4.id(), PortNumber.portNumber(8), cp8);
    ConnectPoint cp9 = new ConnectPoint(virtualDevice5.id(), PortNumber.portNumber(9));
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice5.id(), PortNumber.portNumber(9), cp9);
    VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3);
    virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
    VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1);
    virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
    VirtualLink link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5);
    virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE);
    VirtualLink link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4);
    virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE);
    VirtualLink link5 = manager.createVirtualLink(virtualNetwork.id(), cp8, cp9);
    virtualNetworkManagerStore.updateLink(link5, link5.tunnelId(), Link.State.ACTIVE);
    VirtualLink link6 = manager.createVirtualLink(virtualNetwork.id(), cp9, cp8);
    virtualNetworkManagerStore.updateLink(link6, link6.tunnelId(), Link.State.ACTIVE);
    topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    topologyProvider = new DefaultVirtualNetworkProvider();
    try {
        TestUtils.setField(topologyProvider, "topologyService", topologyService);
    } catch (TestUtils.TestUtilsException e) {
        e.printStackTrace();
    }
    return virtualNetwork;
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) TestUtils(org.onlab.junit.TestUtils) DefaultVirtualNetworkProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualNetworkProvider) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) TopologyService(org.onosproject.net.topology.TopologyService)

Example 34 with VirtualDevice

use of org.onosproject.incubator.net.virtual.VirtualDevice 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 35 with VirtualDevice

use of org.onosproject.incubator.net.virtual.VirtualDevice 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)

Aggregations

VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)51 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)39 Test (org.junit.Test)29 ConnectPoint (org.onosproject.net.ConnectPoint)27 TopologyService (org.onosproject.net.topology.TopologyService)13 VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)12 Topology (org.onosproject.net.topology.Topology)12 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)11 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)9 DisjointPath (org.onosproject.net.DisjointPath)9 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)7 DeviceService (org.onosproject.net.device.DeviceService)7 HashSet (java.util.HashSet)6 DefaultVirtualDevice (org.onosproject.incubator.net.virtual.DefaultVirtualDevice)6 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)6 DeviceId (org.onosproject.net.DeviceId)6 ArrayList (java.util.ArrayList)5 DefaultVirtualPort (org.onosproject.incubator.net.virtual.DefaultVirtualPort)5 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3