use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualPortsEmptyArray.
// Tests for Virtual Ports
/**
* Tests the result of the REST API GET when there are no virtual ports.
*/
@Test
public void testGetVirtualPortsEmptyArray() {
NetworkId networkId = networkId4;
DeviceId deviceId = devId2;
expect(mockVnetService.getVirtualPorts(networkId, deviceId)).andReturn(ImmutableSet.of()).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String location = "vnets/" + networkId.toString() + "/devices/" + deviceId.toString() + "/ports";
String response = wt.path(location).request().get(String.class);
assertThat(response, is("{\"ports\":[]}"));
verify(mockVnetService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualLinksArray.
/**
* Tests the result of the REST API GET when virtual links are defined.
*/
@Test
public void testGetVirtualLinksArray() {
NetworkId networkId = networkId3;
final Set<VirtualLink> vlinkSet = ImmutableSet.of(vlink1, vlink2);
expect(mockVnetService.getVirtualLinks(networkId)).andReturn(vlinkSet).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String location = "vnets/" + networkId.toString() + "/links";
String response = wt.path(location).request().get(String.class);
assertThat(response, containsString("{\"links\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("links"));
final JsonArray vnetJsonArray = result.get("links").asArray();
assertThat(vnetJsonArray, notNullValue());
assertEquals("Virtual links array is not the correct size.", vlinkSet.size(), vnetJsonArray.size());
vlinkSet.forEach(vlink -> assertThat(vnetJsonArray, hasVlink(vlink)));
verify(mockVnetService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualize.
/**
* Translate the requested virtual outbound packet into
* a set of physical OutboundPacket.
* See {@link org.onosproject.net.packet.OutboundPacket}
*
* @param packet an OutboundPacket to be translated
* @return a set of de-virtualized (physical) OutboundPacket
*/
private Set<OutboundPacket> devirtualize(NetworkId networkId, OutboundPacket packet) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, packet.sendThrough());
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
packet.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
PortNumber vOutPortNum = packet.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
if (!vOutPortNum.isLogical()) {
Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(v -> v.realizedBy()).findFirst();
if (!optionalCpOut.isPresent()) {
log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, packet.sendThrough());
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
for (VirtualPort outPort : vPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, packet.data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, packet.sendThrough());
}
}
}
}
return outboundPackets;
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResource method createVirtualPort.
/**
* Creates a virtual network port in a virtual device in a virtual network.
*
* @param networkId network identifier
* @param virtDeviceId virtual device identifier
* @param stream virtual port JSON stream
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel VirtualPort
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/devices/{deviceId}/ports")
public Response createVirtualPort(@PathParam("networkId") long networkId, @PathParam("deviceId") String virtDeviceId, InputStream stream) {
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
// final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
throw new IllegalArgumentException(INVALID_FIELD + "networkId");
}
if (specifiedDeviceId == null || !specifiedDeviceId.asText().equals(virtDeviceId)) {
throw new IllegalArgumentException(INVALID_FIELD + "deviceId");
}
JsonNode specifiedPortNum = jsonTree.get("portNum");
JsonNode specifiedPhysDeviceId = jsonTree.get("physDeviceId");
JsonNode specifiedPhysPortNum = jsonTree.get("physPortNum");
final NetworkId nid = NetworkId.networkId(networkId);
DeviceId vdevId = DeviceId.deviceId(virtDeviceId);
ConnectPoint realizedBy = new ConnectPoint(DeviceId.deviceId(specifiedPhysDeviceId.asText()), PortNumber.portNumber(specifiedPhysPortNum.asText()));
VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId, PortNumber.portNumber(specifiedPortNum.asText()), realizedBy);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("vnets").path(specifiedNetworkId.asText()).path("devices").path(specifiedDeviceId.asText()).path("ports").path(vport.number().toString());
return Response.created(locationBuilder.build()).build();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.onosproject.incubator.net.virtual.NetworkId 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();
}
Aggregations