Search in sources :

Example 36 with NetworkId

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);
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 37 with NetworkId

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);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) DeviceId(org.onosproject.net.DeviceId) JsonObject(com.eclipsesource.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 38 with NetworkId

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);
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 39 with NetworkId

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);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 40 with NetworkId

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;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) ComponentContext(org.osgi.service.component.ComponentContext) VirtualPacketProviderService(org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) TenantId(org.onosproject.net.TenantId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualPacketProvider(org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider) VirtualNetworkListener(org.onosproject.incubator.net.virtual.VirtualNetworkListener) AbstractVirtualProvider(org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) Optional(java.util.Optional) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Dictionary(java.util.Dictionary) DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Aggregations

NetworkId (org.onosproject.incubator.net.virtual.NetworkId)50 DeviceId (org.onosproject.net.DeviceId)23 Test (org.junit.Test)21 WebTarget (javax.ws.rs.client.WebTarget)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 HostResourceTest (org.onosproject.rest.resources.HostResourceTest)20 LinksResourceTest (org.onosproject.rest.resources.LinksResourceTest)20 ResourceTest (org.onosproject.rest.resources.ResourceTest)20 Activate (org.osgi.service.component.annotations.Activate)11 Logger (org.slf4j.Logger)11 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)11 Set (java.util.Set)10 Component (org.osgi.service.component.annotations.Component)10 Deactivate (org.osgi.service.component.annotations.Deactivate)10 HashSet (java.util.HashSet)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortNumber (org.onosproject.net.PortNumber)9 Reference (org.osgi.service.component.annotations.Reference)9 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)9