use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkDeviceManagerTest method testGetPorts.
/**
* Tests querying the ports of a device by device identifier.
*/
@Test
public void testGetPorts() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
ConnectPoint cp = new ConnectPoint(virtualDevice.id(), PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
manager.createVirtualPort(virtualNetwork.id(), virtualDevice.id(), PortNumber.portNumber(2), cp);
// test the getPorts() method
assertEquals("The port set size did not match.", 2, deviceService.getPorts(DID1).size());
assertEquals("The port set size did not match.", 0, deviceService.getPorts(DID2).size());
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkDeviceManagerTest method testGetDevices.
/**
* Tests the getDevices(), getAvailableDevices(), getDeviceCount(), getDevice(), and isAvailable() methods.
*/
@Test
public void testGetDevices() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), DID1);
VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
// test the getDevices() method
Iterator<Device> it = deviceService.getDevices().iterator();
assertEquals("The device set size did not match.", 2, Iterators.size(it));
// test the getAvailableDevices() method
Iterator<Device> it2 = deviceService.getAvailableDevices().iterator();
assertEquals("The device set size did not match.", 2, Iterators.size(it2));
// test the getDeviceCount() method
assertEquals("The device set size did not match.", 2, deviceService.getDeviceCount());
// test the getDevice() method
assertEquals("The expect device did not match.", device1, deviceService.getDevice(DID1));
assertNotEquals("The expect device should not have matched.", device1, deviceService.getDevice(DID2));
// test the isAvailable() method
assertTrue("The expect device availability did not match.", deviceService.isAvailable(DID1));
assertFalse("The expect device availability did not match.", deviceService.isAvailable(DID3));
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualNetworksArray.
/**
* Tests the result of the REST API GET when virtual networks are defined.
*/
@Test
public void testGetVirtualNetworksArray() {
final Set<VirtualNetwork> vnetSet = ImmutableSet.of(vnet1, vnet2, vnet3, vnet4);
expect(mockVnetAdminService.getTenantIds()).andReturn(ImmutableSet.of(tenantId3)).anyTimes();
replay(mockVnetAdminService);
expect(mockVnetService.getVirtualNetworks(tenantId3)).andReturn(vnetSet).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String response = wt.path("vnets").request().get(String.class);
assertThat(response, containsString("{\"vnets\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("vnets"));
final JsonArray vnetJsonArray = result.get("vnets").asArray();
assertThat(vnetJsonArray, notNullValue());
assertEquals("Virtual networks array is not the correct size.", vnetSet.size(), vnetJsonArray.size());
vnetSet.forEach(vnet -> assertThat(vnetJsonArray, hasVnet(vnet)));
verify(mockVnetService);
verify(mockVnetAdminService);
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkWebResourceTest method testGetVirtualNetworksByTenantId.
/**
* Tests the result of the REST API GET for virtual networks with tenant id.
*/
@Test
public void testGetVirtualNetworksByTenantId() {
final Set<VirtualNetwork> vnetSet = ImmutableSet.of(vnet1, vnet2, vnet3, vnet4);
expect(mockVnetAdminService.getTenantIds()).andReturn(ImmutableSet.of(tenantId3)).anyTimes();
replay(mockVnetAdminService);
expect(mockVnetService.getVirtualNetworks(tenantId3)).andReturn(vnetSet).anyTimes();
replay(mockVnetService);
WebTarget wt = target();
String response = wt.path("vnets/" + tenantId3.id()).request().get(String.class);
assertThat(response, containsString("{\"vnets\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("vnets"));
final JsonArray vnetJsonArray = result.get("vnets").asArray();
assertThat(vnetJsonArray, notNullValue());
assertEquals("Virtual networks array is not the correct size.", vnetSet.size(), vnetJsonArray.size());
vnetSet.forEach(vnet -> assertThat(vnetJsonArray, hasVnet(vnet)));
verify(mockVnetService);
verify(mockVnetAdminService);
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkManager method getTenantId.
@Override
public TenantId getTenantId(NetworkId networkId) {
VirtualNetwork virtualNetwork = getVirtualNetwork(networkId);
checkNotNull(virtualNetwork, "The network does not exist.");
return virtualNetwork.tenantId();
}
Aggregations