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();
}
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);
}
}
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;
}
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));
}
}
}
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;
}
Aggregations