Search in sources :

Example 16 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testCreateVirtualDeviceWithNoNetwork.

/**
 * Tests adding a virtual device where no virtual network exists.
 */
@Test(expected = IllegalStateException.class)
public void testCreateVirtualDeviceWithNoNetwork() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = new DefaultVirtualNetwork(NetworkId.NONE, TenantId.tenantId(tenantIdValue1));
    manager.createVirtualDevice(virtualNetwork.id(), DID1);
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) Test(org.junit.Test)

Example 17 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testGetPhysicalDevices.

/**
 * Tests getting a collection of physical device identifier corresponding to
 * the specified virtual device.
 */
@Test
public void testGetPhysicalDevices() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    manager.registerTenantId(TenantId.tenantId(tenantIdValue2));
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork2 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue2));
    // two virtual device in first virtual network
    VirtualDevice vDevice1InVnet1 = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    VirtualDevice vDevice2InVnet1 = manager.createVirtualDevice(virtualNetwork1.id(), DID2);
    // Two virtual device in second virtual network
    VirtualDevice vDevice1InVnet2 = manager.createVirtualDevice(virtualNetwork2.id(), DID1);
    VirtualDevice vDevice2InVnet2 = manager.createVirtualDevice(virtualNetwork2.id(), DID2);
    // Connection Point from each physical device
    // Virtual network 1
    ConnectPoint cp1InVnet1 = new ConnectPoint(PHYDID1, PortNumber.portNumber(10));
    ConnectPoint cp2InVnet1 = new ConnectPoint(PHYDID2, PortNumber.portNumber(20));
    ConnectPoint cp3InVnet1 = new ConnectPoint(PHYDID3, PortNumber.portNumber(30));
    ConnectPoint cp4InVnet1 = new ConnectPoint(PHYDID4, PortNumber.portNumber(40));
    // Virtual network 2
    ConnectPoint cp1InVnet2 = new ConnectPoint(PHYDID1, PortNumber.portNumber(10));
    ConnectPoint cp2InVnet2 = new ConnectPoint(PHYDID2, PortNumber.portNumber(20));
    ConnectPoint cp3InVnet2 = new ConnectPoint(PHYDID3, PortNumber.portNumber(30));
    ConnectPoint cp4InVnet2 = new ConnectPoint(PHYDID4, PortNumber.portNumber(40));
    // Make simple BigSwitch by mapping two phyDevice to one vDevice
    // First vDevice in first virtual network
    manager.createVirtualPort(virtualNetwork1.id(), vDevice1InVnet1.id(), PortNumber.portNumber(1), cp1InVnet1);
    manager.createVirtualPort(virtualNetwork1.id(), vDevice1InVnet1.id(), PortNumber.portNumber(2), cp2InVnet1);
    // Second vDevice in first virtual network
    manager.createVirtualPort(virtualNetwork1.id(), vDevice2InVnet1.id(), PortNumber.portNumber(1), cp3InVnet1);
    manager.createVirtualPort(virtualNetwork1.id(), vDevice2InVnet1.id(), PortNumber.portNumber(2), cp4InVnet1);
    // First vDevice in second virtual network
    manager.createVirtualPort(virtualNetwork2.id(), vDevice1InVnet2.id(), PortNumber.portNumber(1), cp1InVnet2);
    manager.createVirtualPort(virtualNetwork2.id(), vDevice1InVnet2.id(), PortNumber.portNumber(2), cp2InVnet2);
    // Second vDevice in second virtual network
    manager.createVirtualPort(virtualNetwork2.id(), vDevice2InVnet2.id(), PortNumber.portNumber(1), cp3InVnet2);
    manager.createVirtualPort(virtualNetwork2.id(), vDevice2InVnet2.id(), PortNumber.portNumber(2), cp4InVnet2);
    Set<DeviceId> physicalDeviceSet;
    Set<DeviceId> testSet = new HashSet<>();
    physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork1.id(), vDevice1InVnet1.id());
    testSet.add(PHYDID1);
    testSet.add(PHYDID2);
    assertEquals("The physical devices 1 did not match", testSet, physicalDeviceSet);
    testSet.clear();
    physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork1.id(), vDevice2InVnet1.id());
    testSet.add(PHYDID3);
    testSet.add(PHYDID4);
    assertEquals("The physical devices 2 did not match", testSet, physicalDeviceSet);
    testSet.clear();
    physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork2.id(), vDevice1InVnet2.id());
    testSet.add(PHYDID1);
    testSet.add(PHYDID2);
    assertEquals("The physical devices 1 did not match", testSet, physicalDeviceSet);
    testSet.clear();
    physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork2.id(), vDevice2InVnet2.id());
    testSet.add(PHYDID3);
    testSet.add(PHYDID4);
    assertEquals("The physical devices 2 did not match", testSet, physicalDeviceSet);
    testSet.clear();
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DeviceId(org.onosproject.net.DeviceId) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testAddRemoveVirtualPort.

/**
 * Tests add, bind and remove of virtual ports.
 */
@Test
public void testAddRemoveVirtualPort() {
    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);
    VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_DEVICE_ADDED);
    ConnectPoint cp = new ConnectPoint(virtualDevice.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED);
    manager.createVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(2), cp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED);
    Set<VirtualPort> virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), virtualDevice.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(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), true);
    VirtualPort changedPort = getPort(virtualNetwork1.id(), virtualDevice.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(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED);
    // verify change state of virtual port (disabled -> disabled)
    manager.updatePortState(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(2), false);
    changedPort = getPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(2));
    assertNotNull("The changed virtual port should not be null", changedPort);
    assertEquals("Virtual port state should be disabled", false, changedPort.isEnabled());
    for (VirtualPort virtualPort : virtualPorts) {
        manager.removeVirtualPort(virtualNetwork1.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
        expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED);
        // attempt to remove the same virtual port again.
        manager.removeVirtualPort(virtualNetwork1.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    }
    virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), virtualDevice.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.isEmpty());
    // Add/remove the virtual port again.
    VirtualPort virtualPort = manager.createVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED);
    ConnectPoint newCp = new ConnectPoint(DID2, PortNumber.portNumber(2));
    manager.bindVirtualPort(virtualNetwork1.id(), virtualDevice.id(), PortNumber.portNumber(1), newCp);
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED);
    manager.removeVirtualPort(virtualNetwork1.id(), (DeviceId) virtualPort.element().id(), virtualPort.number());
    expectedEventTypes.add(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED);
    virtualPorts = manager.getVirtualPorts(virtualNetwork1.id(), virtualDevice.id());
    assertTrue("The virtual port set should be empty.", virtualPorts.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) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) ArrayList(java.util.ArrayList) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 19 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testAddRemoveVirtualHost.

/**
 * Tests add and remove of virtual hosts.
 */
@Test
public void testAddRemoveVirtualHost() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork2 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice virtualDevice1 = manager.createVirtualDevice(virtualNetwork1.id(), DID1);
    VirtualDevice virtualDevice2 = manager.createVirtualDevice(virtualNetwork2.id(), DID2);
    ConnectPoint hostCp1 = new ConnectPoint(DID1, P1);
    ConnectPoint hostCp2 = new ConnectPoint(DID2, P2);
    manager.createVirtualPort(virtualNetwork1.id(), hostCp1.deviceId(), hostCp1.port(), new ConnectPoint(virtualDevice1.id(), hostCp1.port()));
    manager.createVirtualPort(virtualNetwork2.id(), hostCp2.deviceId(), hostCp2.port(), new ConnectPoint(virtualDevice2.id(), hostCp2.port()));
    manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
    manager.createVirtualHost(virtualNetwork2.id(), HID2, MAC2, VLAN2, LOC2, IPSET2);
    Set<VirtualHost> virtualHosts1 = manager.getVirtualHosts(virtualNetwork1.id());
    assertNotNull("The virtual host set should not be null", virtualHosts1);
    assertEquals("The virtual host set size did not match.", 1, virtualHosts1.size());
    Set<VirtualHost> virtualHosts2 = manager.getVirtualHosts(virtualNetwork2.id());
    assertNotNull("The virtual host set should not be null", virtualHosts2);
    assertEquals("The virtual host set size did not match.", 1, virtualHosts2.size());
    for (VirtualHost virtualHost : virtualHosts1) {
        manager.removeVirtualHost(virtualNetwork1.id(), virtualHost.id());
        // attempt to remove the same virtual host again.
        manager.removeVirtualHost(virtualNetwork1.id(), virtualHost.id());
    }
    virtualHosts1 = manager.getVirtualHosts(virtualNetwork1.id());
    assertTrue("The virtual host set should be empty.", virtualHosts1.isEmpty());
    // Add/remove the virtual host again.
    VirtualHost virtualHost = manager.createVirtualHost(virtualNetwork1.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
    manager.removeVirtualHost(virtualHost.networkId(), virtualHost.id());
    virtualHosts1 = manager.getVirtualHosts(virtualNetwork1.id());
    assertTrue("The virtual host set should be empty.", virtualHosts1.isEmpty());
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 20 with VirtualNetwork

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

the class VirtualNetworkManagerTest method testServiceGetReturnsSavedInstance.

/**
 * Tests that the get() method returns saved service instances.
 */
@Test
public void testServiceGetReturnsSavedInstance() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), DeviceService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), LinkService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), TopologyService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), HostService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), PathService.class);
    // extra setup needed for FlowRuleService, PacketService, GroupService, and IntentService
    VirtualProviderManager virtualProviderManager = new VirtualProviderManager();
    virtualProviderManager.registerProvider(new DefaultVirtualFlowRuleProvider());
    virtualProviderManager.registerProvider(new DefaultVirtualPacketProvider());
    virtualProviderManager.registerProvider(new DefaultVirtualGroupProvider());
    testDirectory.add(CoreService.class, coreService).add(VirtualProviderRegistryService.class, virtualProviderManager).add(EventDeliveryService.class, new TestEventDispatcher()).add(ClusterService.class, new ClusterServiceAdapter()).add(VirtualNetworkFlowRuleStore.class, new SimpleVirtualFlowRuleStore()).add(VirtualNetworkPacketStore.class, new SimpleVirtualPacketStore()).add(VirtualNetworkGroupStore.class, new SimpleVirtualGroupStore()).add(VirtualNetworkIntentStore.class, new SimpleVirtualIntentStore()).add(VirtualNetworkFlowObjectiveStore.class, new SimpleVirtualFlowObjectiveStore());
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), FlowRuleService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), FlowObjectiveService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), PacketService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), GroupService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), IntentService.class);
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) SimpleVirtualFlowRuleStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowRuleStore) SimpleVirtualFlowObjectiveStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowObjectiveStore) VirtualNetworkIntentStore(org.onosproject.incubator.net.virtual.VirtualNetworkIntentStore) SimpleVirtualPacketStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualPacketStore) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) DefaultVirtualPacketProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualPacketProvider) DefaultVirtualGroupProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualGroupProvider) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) SimpleVirtualIntentStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualIntentStore) ClusterService(org.onosproject.cluster.ClusterService) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) SimpleVirtualGroupStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualGroupStore) DefaultVirtualFlowRuleProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualFlowRuleProvider) VirtualProviderManager(org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager) VirtualNetworkPacketStore(org.onosproject.incubator.net.virtual.VirtualNetworkPacketStore) 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