Search in sources :

Example 6 with VirtualHost

use of org.onosproject.incubator.net.virtual.VirtualHost in project onos by opennetworkinglab.

the class VirtualHostCompleter method getSortedVirtualHosts.

/**
 * Returns the list of virtual hosts sorted using the host identifier.
 *
 * @param networkId network id
 * @return virtual host list
 */
private List<VirtualHost> getSortedVirtualHosts(long networkId) {
    VirtualNetworkService service = getService(VirtualNetworkService.class);
    List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.addAll(service.getVirtualHosts(NetworkId.networkId(networkId)));
    return virtualHosts;
}
Also used : VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) ArrayList(java.util.ArrayList) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost)

Example 7 with VirtualHost

use of org.onosproject.incubator.net.virtual.VirtualHost in project onos by opennetworkinglab.

the class VirtualHostCodecTest method testDecode.

@Test
public void testDecode() throws IOException {
    MockCodecContext context = new MockCodecContext();
    InputStream jsonStream = VirtualHostCodecTest.class.getResourceAsStream("VirtualHost.json");
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat(json, notNullValue());
    JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
    VirtualHost virtualHost = codec.decode((ObjectNode) json, context);
    assertThat(virtualHost, notNullValue());
    assertThat(virtualHost.networkId().id(), is(TEST_NETWORK_ID));
    assertThat(virtualHost.id().toString(), is(NetTestTools.hid(TEST_MAC_ADDRESS + "/12").toString()));
    assertThat(virtualHost.mac().toString(), is(TEST_MAC_ADDRESS));
    assertThat(virtualHost.vlan().id(), is((short) TEST_VLAN_ID));
    assertThat(virtualHost.location().deviceId(), is(CONNECT_POINT.deviceId()));
    assertThat(virtualHost.location().port().toLong(), is(CONNECT_POINT.port().toLong()));
    assertThat(virtualHost.ipAddresses().contains(IpAddress.valueOf(TEST_IP1)), is(true));
    assertThat(virtualHost.ipAddresses().contains(IpAddress.valueOf(TEST_IP2)), is(true));
}
Also used : MockCodecContext(org.onosproject.codec.impl.MockCodecContext) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) Test(org.junit.Test)

Example 8 with VirtualHost

use of org.onosproject.incubator.net.virtual.VirtualHost in project onos by opennetworkinglab.

the class VirtualNetworkWebResource method createVirtualHost.

/**
 * Creates a virtual network host from the JSON input stream.
 *
 * @param networkId network identifier
 * @param stream    virtual host JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel VirtualHostPut
 */
@POST
@Path("{networkId}/hosts")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVirtualHost(@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 VirtualHost vhostReq = codec(VirtualHost.class).decode(jsonTree, this);
        vnetAdminService.createVirtualHost(vhostReq.networkId(), vhostReq.id(), vhostReq.mac(), vhostReq.vlan(), vhostReq.location(), vhostReq.ipAddresses());
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("vnets").path(specifiedNetworkId.asText()).path("hosts");
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 9 with VirtualHost

use of org.onosproject.incubator.net.virtual.VirtualHost in project onos by opennetworkinglab.

the class VirtualNetworkWebResource method getVirtualHosts.

/**
 * Returns all virtual network hosts in a virtual network.
 *
 * @param networkId network identifier
 * @return 200 OK with set of virtual network hosts
 * @onos.rsModel VirtualHosts
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/hosts")
public Response getVirtualHosts(@PathParam("networkId") long networkId) {
    NetworkId nid = NetworkId.networkId(networkId);
    Set<VirtualHost> vhosts = vnetService.getVirtualHosts(nid);
    return ok(encodeArray(VirtualHost.class, "hosts", vhosts)).build();
}
Also used : VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with VirtualHost

use of org.onosproject.incubator.net.virtual.VirtualHost in project onos by opennetworkinglab.

the class VirtualNetworkHostManagerTest method testGetHostsOnNonEmptyVnet.

/**
 * Tests the getHosts(), getHost(), getHostsByXX(), getConnectedHosts() methods
 * on a non-empty virtual network.
 */
@Test
public void testGetHostsOnNonEmptyVnet() {
    VirtualNetwork virtualNetwork = setupEmptyVnet();
    VirtualHost vhost1 = manager.createVirtualHost(virtualNetwork.id(), HID1, MAC1, VLAN1, LOC1, IPSET1);
    VirtualHost vhost2 = manager.createVirtualHost(virtualNetwork.id(), HID2, MAC2, VLAN2, LOC2, IPSET2);
    HostService hostService = manager.get(virtualNetwork.id(), HostService.class);
    // test the getHosts() and getHostCount() methods
    Iterator<Host> itHosts = hostService.getHosts().iterator();
    assertEquals("The host set size did not match.", 2, Iterators.size(itHosts));
    assertEquals("The host count did not match.", 2, hostService.getHostCount());
    // test the getHost() method
    Host testHost = hostService.getHost(HID2);
    assertEquals("The expected host did not match.", vhost2, testHost);
    // test the getHostsByVlan(...) method
    Collection<Host> collHost = hostService.getHostsByVlan(VLAN1);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost1));
    // test the getHostsByMac(...) method
    collHost = hostService.getHostsByMac(MAC2);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost2));
    // test the getHostsByIp(...) method
    collHost = hostService.getHostsByIp(IP1);
    assertEquals("The host set size did not match.", 2, collHost.size());
    collHost = hostService.getHostsByIp(IP2);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost1));
    // test the getConnectedHosts(ConnectPoint) method
    collHost = hostService.getConnectedHosts(LOC1);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost1));
    // test the getConnectedHosts(DeviceId) method
    collHost = hostService.getConnectedHosts(DID2);
    assertEquals("The host set size did not match.", 1, collHost.size());
    assertTrue("The host did not match.", collHost.contains(vhost2));
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) Host(org.onosproject.net.Host) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) Test(org.junit.Test)

Aggregations

VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)12 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 DefaultVirtualHost (org.onosproject.incubator.net.virtual.DefaultVirtualHost)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Path (javax.ws.rs.Path)3 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)3 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 MockCodecContext (org.onosproject.codec.impl.MockCodecContext)2 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)2 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)2 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 HostId (org.onosproject.net.HostId)2 JsonArray (com.eclipsesource.json.JsonArray)1 JsonObject (com.eclipsesource.json.JsonObject)1