Search in sources :

Example 36 with VirtualDevice

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

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

the class DistributedVirtualNetworkStore method addDevice.

@Override
public VirtualDevice addDevice(NetworkId networkId, DeviceId deviceId) {
    checkState(networkExists(networkId), "The network has not been added.");
    Set<DeviceId> deviceIdSet = networkIdDeviceIdSetMap.get(networkId);
    if (deviceIdSet == null) {
        deviceIdSet = new HashSet<>();
    }
    checkState(!deviceIdSet.contains(deviceId), "The device already exists.");
    VirtualDevice virtualDevice = new DefaultVirtualDevice(networkId, deviceId);
    // TODO update both maps in one transaction.
    deviceIdVirtualDeviceMap.put(new VirtualDeviceId(networkId, deviceId), virtualDevice);
    deviceIdSet.add(deviceId);
    networkIdDeviceIdSetMap.put(networkId, deviceIdSet);
    return virtualDevice;
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice)

Example 38 with VirtualDevice

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

the class DistributedVirtualNetworkStore method updatePortState.

@Override
public void updatePortState(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, boolean isEnabled) {
    checkState(networkExists(networkId), "No network with NetworkId %s exists.", networkId);
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "No device %s exists in NetworkId: %s", deviceId, networkId);
    Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
    checkNotNull(virtualPortSet, "No port has been created for NetworkId: %s", networkId);
    Optional<VirtualPort> virtualPortOptional = virtualPortSet.stream().filter(p -> p.element().id().equals(deviceId) && p.number().equals(portNumber)).findFirst();
    checkState(virtualPortOptional.isPresent(), "The virtual port has not been added.");
    VirtualPort oldPort = virtualPortOptional.get();
    if (oldPort.isEnabled() == isEnabled) {
        log.debug("No change in port state - port not updated");
        return;
    }
    VirtualPort newPort = new DefaultVirtualPort(networkId, device, portNumber, isEnabled, oldPort.realizedBy());
    virtualPortSet.remove(oldPort);
    virtualPortSet.add(newPort);
    networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
    notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, newPort));
    log.debug("port state changed from {} to {}", oldPort.isEnabled(), isEnabled);
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) ConsistentMap(org.onosproject.store.service.ConsistentMap) HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) BiFunction(java.util.function.BiFunction) PortNumber(org.onosproject.net.PortNumber) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) IdGenerator(org.onosproject.core.IdGenerator) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) VirtualNetworkStoreDelegate(org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate) DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Optional(java.util.Optional) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) DeviceId(org.onosproject.net.DeviceId) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KryoNamespace(org.onlab.util.KryoNamespace) VirtualNetworkStore(org.onosproject.incubator.net.virtual.VirtualNetworkStore) MapEventListener(org.onosproject.store.service.MapEventListener) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TenantId(org.onosproject.net.TenantId) Logger(org.slf4j.Logger) SetEvent(org.onosproject.store.service.SetEvent) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) SetEventListener(org.onosproject.store.service.SetEventListener) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DistributedSet(org.onosproject.store.service.DistributedSet) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

Example 39 with VirtualDevice

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

the class DistributedVirtualNetworkStore method removePort.

@Override
public void removePort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
    checkState(networkExists(networkId), "The network has not been added.");
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
    if (networkIdVirtualPortSetMap.get(networkId) == null) {
        log.warn("No port has been created for NetworkId: {}", networkId);
        return;
    }
    Set<VirtualPort> virtualPortSet = new HashSet<>();
    networkIdVirtualPortSetMap.get(networkId).forEach(port -> {
        if (port.element().id().equals(deviceId) && port.number().equals(portNumber)) {
            virtualPortSet.add(port);
        }
    });
    if (!virtualPortSet.isEmpty()) {
        AtomicBoolean portRemoved = new AtomicBoolean(false);
        networkIdVirtualPortSetMap.compute(networkId, (id, existingVirtualPorts) -> {
            if (existingVirtualPorts == null || existingVirtualPorts.isEmpty()) {
                return new HashSet<>();
            } else {
                portRemoved.set(true);
                return new HashSet<>(Sets.difference(existingVirtualPorts, virtualPortSet));
            }
        });
        if (portRemoved.get()) {
            virtualPortSet.forEach(virtualPort -> notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED, networkId, device, virtualPort)));
            // Remove all the virtual links connected to this virtual port
            Set<VirtualLink> existingVirtualLinks = networkIdVirtualLinkSetMap.get(networkId);
            if (existingVirtualLinks != null && !existingVirtualLinks.isEmpty()) {
                Set<VirtualLink> virtualLinkSet = new HashSet<>();
                ConnectPoint cp = new ConnectPoint(deviceId, portNumber);
                existingVirtualLinks.forEach(virtualLink -> {
                    if (virtualLink.src().equals(cp) || virtualLink.dst().equals(cp)) {
                        virtualLinkSet.add(virtualLink);
                    }
                });
                virtualLinkSet.forEach(virtualLink -> removeLink(networkId, virtualLink.src(), virtualLink.dst()));
            }
            // Remove all the hosts connected to this virtual port
            Set<HostId> hostIdSet = new HashSet<>();
            hostIdVirtualHostMap.forEach((hostId, virtualHost) -> {
                if (virtualHost.location().deviceId().equals(deviceId) && virtualHost.location().port().equals(portNumber)) {
                    hostIdSet.add(hostId);
                }
            });
            hostIdSet.forEach(hostId -> removeHost(networkId, hostId));
        }
    }
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink)

Example 40 with VirtualDevice

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

the class DistributedVirtualNetworkStore method addPort.

@Override
public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
    checkState(networkExists(networkId), "The network has not been added.");
    Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
    if (virtualPortSet == null) {
        virtualPortSet = new HashSet<>();
    }
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
    checkState(!virtualPortExists(networkId, deviceId, portNumber), "The requested Port Number has been added.");
    VirtualPort virtualPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
    virtualPortSet.add(virtualPort);
    networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
    notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED, networkId, device, virtualPort));
    return virtualPort;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) DefaultVirtualPort(org.onosproject.incubator.net.virtual.DefaultVirtualPort)

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