use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkManagerTest method testTopologyChanged.
/**
* Test the topologyChanged() method.
*/
@Test
public void testTopologyChanged() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(tenantIdValue1);
VirtualNetworkProviderService providerService = manager.createProviderService(topologyProvider);
// Initial setup is two clusters of devices/links.
assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
// Adding this link will join the two clusters together.
List<Event> reasons = new ArrayList<>();
VirtualLink link = manager.createVirtualLink(virtualNetwork.id(), cp6, cp7);
virtualNetworkManagerStore.updateLink(link, link.tunnelId(), Link.State.ACTIVE);
VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp7, cp6);
virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
Topology topology = topologyService.currentTopology();
providerService.topologyChanged(topologyProvider.getConnectPoints(topology));
// Validate that all links are still active.
manager.getVirtualLinks(virtualNetwork.id()).forEach(virtualLink -> {
assertTrue("The virtual link should be active.", virtualLink.state().equals(Link.State.ACTIVE));
});
virtualNetworkManagerStore.updateLink(link, link.tunnelId(), Link.State.INACTIVE);
virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.INACTIVE);
providerService.topologyChanged(topologyProvider.getConnectPoints(topology));
// Validate that all links are active again.
manager.getVirtualLinks(virtualNetwork.id()).forEach(virtualLink -> {
assertTrue("The virtual link should be active.", virtualLink.state().equals(Link.State.ACTIVE));
});
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkManagerTest method testAddRemoveVirtualNetwork.
/**
* Tests add and remove of virtual networks.
*/
@Test
public void testAddRemoveVirtualNetwork() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
Set<VirtualNetwork> virtualNetworks = manager.getVirtualNetworks(TenantId.tenantId(tenantIdValue1));
assertNotNull("The virtual network set should not be null", virtualNetworks);
assertEquals("The virtual network set size did not match.", 2, virtualNetworks.size());
int remaining = virtualNetworks.size();
for (VirtualNetwork virtualNetwork : virtualNetworks) {
manager.removeVirtualNetwork(virtualNetwork.id());
assertEquals("The expected virtual network size does not match", --remaining, manager.getVirtualNetworks(TenantId.tenantId(tenantIdValue1)).size());
}
virtualNetworks = manager.getVirtualNetworks(TenantId.tenantId(tenantIdValue1));
assertTrue("The virtual network set should be empty.", virtualNetworks.isEmpty());
// Create/remove a virtual network.
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
manager.removeVirtualNetwork(virtualNetwork.id());
virtualNetworks = manager.getVirtualNetworks(TenantId.tenantId(tenantIdValue1));
assertTrue("The virtual network set should be empty.", virtualNetworks.isEmpty());
// Validate that the events were all received in the correct order.
validateEvents(VirtualNetworkEvent.Type.TENANT_REGISTERED, VirtualNetworkEvent.Type.NETWORK_ADDED, VirtualNetworkEvent.Type.NETWORK_ADDED, VirtualNetworkEvent.Type.NETWORK_REMOVED, VirtualNetworkEvent.Type.NETWORK_REMOVED, VirtualNetworkEvent.Type.NETWORK_ADDED, VirtualNetworkEvent.Type.NETWORK_REMOVED);
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork 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);
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkManagerTest method testCreateNullVirtualHost.
/**
* Tests adding a null virtual host.
*/
@Test(expected = NullPointerException.class)
public void testCreateNullVirtualHost() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
manager.createVirtualHost(virtualNetwork.id(), null, null, null, null, null);
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork 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;
}
Aggregations