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;
}
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));
}
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);
}
}
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();
}
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));
}
Aggregations