use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualNetworkIntentManagerTest method setupVirtualNetworkTopology.
/**
* Method to create the virtual network for further testing.
*
* @return virtual network
*/
private VirtualNetwork setupVirtualNetworkTopology() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
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);
Port port1 = new DefaultPort(virtualDevice1, PortNumber.portNumber(1), true);
cp1 = new ConnectPoint(virtualDevice1.id(), port1.number());
manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port1.number(), cp1);
Port port2 = new DefaultPort(virtualDevice1, PortNumber.portNumber(2), true);
cp2 = new ConnectPoint(virtualDevice1.id(), port2.number());
manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port2.number(), cp2);
Port port3 = new DefaultPort(virtualDevice2, PortNumber.portNumber(3), true);
cp3 = new ConnectPoint(virtualDevice2.id(), port3.number());
manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port3.number(), cp3);
Port port4 = new DefaultPort(virtualDevice2, PortNumber.portNumber(4), true);
cp4 = new ConnectPoint(virtualDevice2.id(), port4.number());
manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port4.number(), cp4);
Port port5 = new DefaultPort(virtualDevice3, PortNumber.portNumber(5), true);
cp5 = new ConnectPoint(virtualDevice3.id(), port5.number());
manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port5.number(), cp5);
Port port6 = new DefaultPort(virtualDevice3, PortNumber.portNumber(6), true);
cp6 = new ConnectPoint(virtualDevice3.id(), port6.number());
manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port6.number(), cp6);
link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3);
virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1);
virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5);
virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE);
link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4);
virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE);
vnetIntentService = new VirtualNetworkIntentManager(manager, virtualNetwork.id());
vnetIntentService.intentStore = intentStore;
return virtualNetwork;
}
use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualNetworkLinkManagerTest method testGetLinkByNullDst.
/**
* Tests the getLink() method using a null dst connect point.
*/
@Test(expected = NullPointerException.class)
public void testGetLinkByNullDst() {
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));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
manager.createVirtualLink(virtualNetwork.id(), src, dst);
manager.createVirtualLink(virtualNetwork.id(), dst, src);
LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
// test the getLink() method with a null dst connect point.
linkService.getLink(src, null);
}
use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualNetworkLinkManagerTest method testGetLinkByNullSrc.
/**
* Tests the getLink() method using a null src connect point.
*/
@Test(expected = NullPointerException.class)
public void testGetLinkByNullSrc() {
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));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
manager.createVirtualLink(virtualNetwork.id(), src, dst);
manager.createVirtualLink(virtualNetwork.id(), dst, src);
LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
// test the getLink() method with a null src connect point.
linkService.getLink(null, dst);
}
use of org.onosproject.incubator.net.virtual.VirtualDevice 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();
}
use of org.onosproject.incubator.net.virtual.VirtualDevice 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()]));
}
Aggregations