Search in sources :

Example 46 with VirtualNetwork

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());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 47 with VirtualNetwork

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));
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Device(org.onosproject.net.Device) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

Example 48 with VirtualNetwork

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

Example 49 with VirtualNetwork

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

Example 50 with VirtualNetwork

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();
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork)

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