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