use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testPostVirtualHost.
/**
* Tests adding of new virtual host using POST via JSON stream.
*/
@Test
public void testPostVirtualHost() {
NetworkId networkId = networkId3;
expect(mockVnetAdminService.createVirtualHost(networkId, hId1, mac1, vlan1, loc1, ipSet1)).andReturn(vhost1);
replay(mockVnetAdminService);
WebTarget wt = target();
InputStream jsonStream = VirtualNetworkWebResourceTest.class.getResourceAsStream("post-virtual-host.json");
String reqLocation = "vnets/" + networkId.toString() + "/hosts";
Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonStream));
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
String location = response.getLocation().getPath();
assertThat(location, Matchers.startsWith("/" + reqLocation));
verify(mockVnetAdminService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualPortsArray.
/**
* Tests the result of the REST API GET when virtual ports are defined.
*/
@Test
public void testGetVirtualPortsArray() {
NetworkId networkId = networkId3;
DeviceId deviceId = dev22.id();
vportSet.add(vport23);
vportSet.add(vport22);
expect(mockVnetService.getVirtualPorts(networkId, deviceId)).andReturn(vportSet).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, containsString("{\"ports\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("ports"));
final JsonArray vnetJsonArray = result.get("ports").asArray();
assertThat(vnetJsonArray, notNullValue());
assertEquals("Virtual ports array is not the correct size.", vportSet.size(), vnetJsonArray.size());
vportSet.forEach(vport -> assertThat(vnetJsonArray, hasVport(vport)));
verify(mockVnetService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testPostVirtualHostNullJsonStream.
/**
* Tests adding of a null virtual host using POST via JSON stream.
*/
@Test
public void testPostVirtualHostNullJsonStream() {
NetworkId networkId = networkId3;
replay(mockVnetAdminService);
WebTarget wt = target();
try {
String reqLocation = "vnets/" + networkId.toString() + "/hosts";
wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(null), String.class);
fail("POST of null virtual host did not throw an exception");
} catch (BadRequestException ex) {
assertThat(ex.getMessage(), containsString("HTTP 400 Bad Request"));
}
verify(mockVnetAdminService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualDevicesArray.
/**
* Tests the result of the REST API GET when virtual devices are defined.
*/
@Test
public void testGetVirtualDevicesArray() {
NetworkId networkId = networkId3;
vdevSet.add(vdev1);
vdevSet.add(vdev2);
expect(mockVnetService.getVirtualDevices(networkId)).andReturn(vdevSet).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String location = "vnets/" + networkId.toString() + "/devices";
String response = wt.path(location).request().get(String.class);
assertThat(response, containsString("{\"devices\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("devices"));
final JsonArray vnetJsonArray = result.get("devices").asArray();
assertThat(vnetJsonArray, notNullValue());
assertEquals("Virtual devices array is not the correct size.", vdevSet.size(), vnetJsonArray.size());
vdevSet.forEach(vdev -> assertThat(vnetJsonArray, hasVdev(vdev)));
verify(mockVnetService);
}
use of org.onosproject.incubator.net.virtual.NetworkId in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method devirtualizeContext.
/**
* Translate the requested virtual packet context into
* a set of physical outbound packets.
*
* @param context A handled virtual packet context
*/
private Set<OutboundPacket> devirtualizeContext(VirtualPacketContext context) {
Set<OutboundPacket> outboundPackets = new HashSet<>();
NetworkId networkId = context.networkId();
TrafficTreatment vTreatment = context.treatmentBuilder().build();
DeviceId sendThrough = context.outPacket().sendThrough();
Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, sendThrough);
PortNumber vOutPortNum = vTreatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
vTreatment.allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
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, sendThrough);
return outboundPackets;
}
ConnectPoint egressPoint = optionalCpOut.get();
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, context.outPacket().data());
outboundPackets.add(outboundPacket);
} else {
if (vOutPortNum == PortNumber.FLOOD) {
Set<VirtualPort> outPorts = vPorts.stream().filter(vp -> !vp.number().isLogical()).filter(vp -> vp.number() != context.inPacket().receivedFrom().port()).collect(Collectors.toSet());
for (VirtualPort outPort : outPorts) {
ConnectPoint cpOut = outPort.realizedBy();
if (cpOut != null) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, context.outPacket().data());
outboundPackets.add(outboundPacket);
} else {
log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, sendThrough);
}
}
}
}
return outboundPackets;
}
Aggregations