Search in sources :

Example 51 with VirtualNetwork

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

the class VirtualNetworkWebResource method getVirtualNetworkById.

/**
 * Returns the virtual networks with the specified tenant identifier.
 *
 * @param tenantId tenant identifier
 * @return 200 OK with a virtual network, 404 not found
 * @onos.rsModel VirtualNetworks
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{tenantId}")
public Response getVirtualNetworkById(@PathParam("tenantId") String tenantId) {
    final TenantId existingTid = TenantWebResource.getExistingTenantId(vnetAdminService, TenantId.tenantId(tenantId));
    Set<VirtualNetwork> vnets = vnetService.getVirtualNetworks(existingTid);
    return ok(encodeArray(VirtualNetwork.class, "vnets", vnets)).build();
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) TenantId(org.onosproject.net.TenantId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 52 with VirtualNetwork

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

the class VirtualNetworkWebResource method createVirtualNetwork.

/**
 * Creates a virtual network from the JSON input stream.
 *
 * @param stream tenant identifier JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel TenantId
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVirtualNetwork(InputStream stream) {
    try {
        final TenantId tid = TenantId.tenantId(getFromJsonStream(stream, "id").asText());
        VirtualNetwork newVnet = vnetAdminService.createVirtualNetwork(tid);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("vnets").path(newVnet.id().toString());
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) TenantId(org.onosproject.net.TenantId) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 53 with VirtualNetwork

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

the class VirtualNetworkHostManagerTest method testGetHostsByNullIp.

/**
 * Tests querying for hosts with null ip.
 */
@Test(expected = NullPointerException.class)
public void testGetHostsByNullIp() {
    VirtualNetwork vnet = setupVnet();
    HostService hostService = manager.get(vnet.id(), HostService.class);
    hostService.getHostsByIp(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) Test(org.junit.Test)

Example 54 with VirtualNetwork

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

the class VirtualNetworkHostManagerTest method testGetConnectedHostsByNullLoc.

/**
 * Tests querying for connected hosts with null host location (connect point).
 */
@Test(expected = NullPointerException.class)
public void testGetConnectedHostsByNullLoc() {
    VirtualNetwork vnet = setupEmptyVnet();
    HostService hostService = manager.get(vnet.id(), HostService.class);
    hostService.getConnectedHosts((ConnectPoint) null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) Test(org.junit.Test)

Example 55 with VirtualNetwork

use of org.onosproject.incubator.net.virtual.VirtualNetwork 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

VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)98 Test (org.junit.Test)82 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)38 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)24 ConnectPoint (org.onosproject.net.ConnectPoint)24 TopologyService (org.onosproject.net.topology.TopologyService)24 Topology (org.onosproject.net.topology.Topology)23 DeviceService (org.onosproject.net.device.DeviceService)15 VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)12 DisjointPath (org.onosproject.net.DisjointPath)11 LinkService (org.onosproject.net.link.LinkService)10 ArrayList (java.util.ArrayList)8 HostService (org.onosproject.net.host.HostService)8 TenantId (org.onosproject.net.TenantId)7 Path (org.onosproject.net.Path)6 PathService (org.onosproject.net.topology.PathService)5 TopologyCluster (org.onosproject.net.topology.TopologyCluster)5 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)4 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)4 Link (org.onosproject.net.Link)4