Search in sources :

Example 16 with VirtualDevice

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

the class VirtualNetworkTopologyManagerTest method testGetDisjointPathsUsingNullDstDeviceId.

/**
 * Test getDisjointPaths() methods using a null dst device identifier.
 */
@Test(expected = NullPointerException.class)
public void testGetDisjointPathsUsingNullDstDeviceId() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    Topology topology = topologyService.currentTopology();
    VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2);
    // test the getDisjointPaths() method using a null dst device identifier.
    Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) Topology(org.onosproject.net.topology.Topology) DisjointPath(org.onosproject.net.DisjointPath) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Example 17 with VirtualDevice

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

the class DistributedVirtualNetworkStore method removeNetwork.

@Override
public void removeNetwork(NetworkId networkId) {
    // Make sure that the virtual network exists before attempting to remove it.
    checkState(networkExists(networkId), "The network does not exist.");
    // Remove all the devices of this network
    Set<VirtualDevice> deviceSet = getDevices(networkId);
    if (deviceSet != null) {
        deviceSet.forEach(virtualDevice -> removeDevice(networkId, virtualDevice.id()));
    }
    // TODO update both maps in one transaction.
    VirtualNetwork virtualNetwork = networkIdVirtualNetworkMap.remove(networkId);
    if (virtualNetwork == null) {
        return;
    }
    TenantId tenantId = virtualNetwork.tenantId();
    Set<NetworkId> networkIdSet = new HashSet<>();
    tenantIdNetworkIdSetMap.get(tenantId).forEach(networkId1 -> {
        if (networkId1.id().equals(networkId.id())) {
            networkIdSet.add(networkId1);
        }
    });
    tenantIdNetworkIdSetMap.compute(virtualNetwork.tenantId(), (id, existingNetworkIds) -> {
        if (existingNetworkIds == null || existingNetworkIds.isEmpty()) {
            return new HashSet<>();
        } else {
            return new HashSet<>(Sets.difference(existingNetworkIds, networkIdSet));
        }
    });
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) TenantId(org.onosproject.net.TenantId) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) HashSet(java.util.HashSet)

Example 18 with VirtualDevice

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

the class DistributedVirtualNetworkStore method bindPort.

@Override
public void bindPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, ConnectPoint realizedBy) {
    Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(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.");
    VirtualDevice device = deviceIdVirtualDeviceMap.get(new VirtualDeviceId(networkId, deviceId));
    checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
    VirtualPort vPort = virtualPortOptional.get();
    virtualPortSet.remove(vPort);
    vPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
    virtualPortSet.add(vPort);
    networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
    notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, networkId, device, vPort));
}
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 19 with VirtualDevice

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

the class DefaultVirtualPacketProvider method getMappedVirtualPort.

/**
 * Find the corresponding virtual port with the physical port.
 *
 * @param cp the connect point for the physical network
 * @return a virtual port
 */
private VirtualPort getMappedVirtualPort(ConnectPoint cp) {
    Set<TenantId> tIds = vnaService.getTenantIds();
    Set<VirtualNetwork> vNetworks = new HashSet<>();
    tIds.forEach(tid -> vNetworks.addAll(vnaService.getVirtualNetworks(tid)));
    for (VirtualNetwork vNet : vNetworks) {
        Set<VirtualDevice> vDevices = vnaService.getVirtualDevices(vNet.id());
        Set<VirtualPort> vPorts = new HashSet<>();
        vDevices.forEach(dev -> vPorts.addAll(vnaService.getVirtualPorts(dev.networkId(), dev.id())));
        VirtualPort vPort = vPorts.stream().filter(vp -> vp.realizedBy().equals(cp)).findFirst().orElse(null);
        if (vPort != null) {
            return vPort;
        }
    }
    return null;
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) TenantId(org.onosproject.net.TenantId) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) HashSet(java.util.HashSet)

Example 20 with VirtualDevice

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

the class VirtualNetworkWebResource method createVirtualDevice.

/**
 * Creates a virtual device from the JSON input stream.
 *
 * @param networkId network identifier
 * @param stream    virtual device JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel VirtualDevice
 */
@POST
@Path("{networkId}/devices")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVirtualDevice(@PathParam("networkId") long networkId, InputStream stream) {
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
            throw new IllegalArgumentException(INVALID_FIELD + "networkId");
        }
        final VirtualDevice vdevRes = vnetAdminService.createVirtualDevice(vdevReq.networkId(), vdevReq.id());
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("vnets").path(specifiedNetworkId.asText()).path("devices").path(vdevRes.id().toString());
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

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