Search in sources :

Example 11 with VirtualLink

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

the class VirtualNetworkWebResource method getVirtualLinks.

// VirtualLink
/**
 * Returns all virtual network links in a virtual network.
 *
 * @param networkId network identifier
 * @return 200 OK with set of virtual network links
 * @onos.rsModel VirtualLinks
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/links")
public Response getVirtualLinks(@PathParam("networkId") long networkId) {
    NetworkId nid = NetworkId.networkId(networkId);
    Set<VirtualLink> vlinks = vnetService.getVirtualLinks(nid);
    return ok(encodeArray(VirtualLink.class, "links", vlinks)).build();
}
Also used : NetworkId(org.onosproject.incubator.net.virtual.NetworkId) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with VirtualLink

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

the class VirtualNetworkWebResource method createVirtualLink.

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

Example 13 with VirtualLink

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

the class DistributedVirtualNetworkStore method addLink.

@Override
public VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, Link.State state, TunnelId realizedBy) {
    checkState(networkExists(networkId), "The network has not been added.");
    checkState(virtualPortExists(networkId, src.deviceId(), src.port()), "The source virtual port has not been added.");
    checkState(virtualPortExists(networkId, dst.deviceId(), dst.port()), "The destination virtual port has not been added.");
    Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId);
    if (virtualLinkSet == null) {
        virtualLinkSet = new HashSet<>();
    }
    // validate that the link does not already exist in this network
    checkState(getLink(networkId, src, dst) == null, "The virtual link already exists");
    checkState(getLink(networkId, src, null) == null, "The source connection point has been used by another link");
    checkState(getLink(networkId, null, dst) == null, "The destination connection point has been used by another link");
    VirtualLink virtualLink = DefaultVirtualLink.builder().networkId(networkId).src(src).dst(dst).state(state).tunnelId(realizedBy).build();
    virtualLinkSet.add(virtualLink);
    networkIdVirtualLinkSetMap.put(networkId, virtualLinkSet);
    return virtualLink;
}
Also used : DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink)

Example 14 with VirtualLink

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

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

the class DistributedVirtualNetworkStore method getLink.

@Override
public VirtualLink getLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) {
    Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId);
    if (virtualLinkSet == null) {
        return null;
    }
    VirtualLink virtualLink = null;
    for (VirtualLink link : virtualLinkSet) {
        if (src == null && link.dst().equals(dst)) {
            virtualLink = link;
            break;
        } else if (dst == null && link.src().equals(src)) {
            virtualLink = link;
            break;
        } else if (link.src().equals(src) && link.dst().equals(dst)) {
            virtualLink = link;
            break;
        }
    }
    return virtualLink;
}
Also used : DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink)

Aggregations

VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)24 ConnectPoint (org.onosproject.net.ConnectPoint)11 DefaultVirtualLink (org.onosproject.incubator.net.virtual.DefaultVirtualLink)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 Test (org.junit.Test)7 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)4 Link (org.onosproject.net.Link)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 Event (org.onosproject.event.Event)2 VirtualNetworkEvent (org.onosproject.incubator.net.virtual.VirtualNetworkEvent)2 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)2