Search in sources :

Example 11 with VirtualHost

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

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

the class DistributedVirtualNetworkStore method addHost.

@Override
public VirtualHost addHost(NetworkId networkId, HostId hostId, MacAddress mac, VlanId vlan, HostLocation location, Set<IpAddress> ips) {
    checkState(networkExists(networkId), "The network has not been added.");
    checkState(virtualPortExists(networkId, location.deviceId(), location.port()), "The virtual port has not been created.");
    Set<HostId> hostIdSet = networkIdHostIdSetMap.get(networkId);
    if (hostIdSet == null) {
        hostIdSet = new HashSet<>();
    }
    VirtualHost virtualhost = new DefaultVirtualHost(networkId, hostId, mac, vlan, location, ips);
    // TODO update both maps in one transaction.
    hostIdVirtualHostMap.put(hostId, virtualhost);
    hostIdSet.add(hostId);
    networkIdHostIdSetMap.put(networkId, hostIdSet);
    return virtualhost;
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) HostId(org.onosproject.net.HostId)

Aggregations

VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)12 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 DefaultVirtualHost (org.onosproject.incubator.net.virtual.DefaultVirtualHost)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Path (javax.ws.rs.Path)3 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)3 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 MockCodecContext (org.onosproject.codec.impl.MockCodecContext)2 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)2 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)2 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 HostId (org.onosproject.net.HostId)2 JsonArray (com.eclipsesource.json.JsonArray)1 JsonObject (com.eclipsesource.json.JsonObject)1