Search in sources :

Example 11 with NetworkId

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

the class DistributedVirtualNetworkStore method addNetwork.

@Override
public VirtualNetwork addNetwork(TenantId tenantId) {
    checkState(tenantIdSet.contains(tenantId), "The tenant has not been registered. " + tenantId.id());
    VirtualNetwork virtualNetwork = new DefaultVirtualNetwork(genNetworkId(), tenantId);
    // TODO update both maps in one transaction.
    networkIdVirtualNetworkMap.put(virtualNetwork.id(), virtualNetwork);
    Set<NetworkId> networkIdSet = tenantIdNetworkIdSetMap.get(tenantId);
    if (networkIdSet == null) {
        networkIdSet = new HashSet<>();
    }
    networkIdSet.add(virtualNetwork.id());
    tenantIdNetworkIdSetMap.put(tenantId, networkIdSet);
    return virtualNetwork;
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) NetworkId(org.onosproject.incubator.net.virtual.NetworkId)

Example 12 with NetworkId

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

the class VirtualNetworkWebResourceTest method testGetVirtualDevicesEmptyArray.

// Tests for Virtual Device
/**
 * Tests the result of the REST API GET when there are no virtual devices.
 */
@Test
public void testGetVirtualDevicesEmptyArray() {
    NetworkId networkId = networkId4;
    expect(mockVnetService.getVirtualDevices(networkId)).andReturn(ImmutableSet.of()).anyTimes();
    replay(mockVnetService);
    WebTarget wt = target();
    String location = "vnets/" + networkId.toString() + "/devices";
    String response = wt.path(location).request().get(String.class);
    assertThat(response, is("{\"devices\":[]}"));
    verify(mockVnetService);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 13 with NetworkId

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

the class VirtualNetworkWebResourceTest method testGetVirtualHostsArray.

/**
 * Tests the result of the REST API GET when virtual hosts are defined.
 */
@Test
public void testGetVirtualHostsArray() {
    NetworkId networkId = networkId3;
    final Set<VirtualHost> vhostSet = ImmutableSet.of(vhost1, vhost2);
    expect(mockVnetService.getVirtualHosts(networkId)).andReturn(vhostSet).anyTimes();
    replay(mockVnetService);
    WebTarget wt = target();
    String location = "vnets/" + networkId.toString() + "/hosts";
    String response = wt.path(location).request().get(String.class);
    assertThat(response, containsString("{\"hosts\":["));
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("hosts"));
    final JsonArray vnetJsonArray = result.get("hosts").asArray();
    assertThat(vnetJsonArray, notNullValue());
    assertEquals("Virtual hosts array is not the correct size.", vhostSet.size(), vnetJsonArray.size());
    vhostSet.forEach(vhost -> assertThat(vnetJsonArray, hasVhost(vhost)));
    verify(mockVnetService);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 14 with NetworkId

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

the class VirtualNetworkWebResourceTest method testPostVirtualLinkNullJsonStream.

/**
 * Tests adding of a null virtual link using POST via JSON stream.
 */
@Test
public void testPostVirtualLinkNullJsonStream() {
    NetworkId networkId = networkId3;
    replay(mockVnetAdminService);
    WebTarget wt = target();
    try {
        String reqLocation = "vnets/" + networkId.toString() + "/links";
        wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(null), String.class);
        fail("POST of null virtual link did not throw an exception");
    } catch (BadRequestException ex) {
        assertThat(ex.getMessage(), containsString("HTTP 400 Bad Request"));
    }
    verify(mockVnetAdminService);
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Example 15 with NetworkId

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

the class VirtualNetworkWebResourceTest method testGetVirtualLinksEmptyArray.

// Tests for Virtual Links
/**
 * Tests the result of the REST API GET when there are no virtual links.
 */
@Test
public void testGetVirtualLinksEmptyArray() {
    NetworkId networkId = networkId4;
    expect(mockVnetService.getVirtualLinks(networkId)).andReturn(ImmutableSet.of()).anyTimes();
    replay(mockVnetService);
    WebTarget wt = target();
    String location = "vnets/" + networkId.toString() + "/links";
    String response = wt.path(location).request().get(String.class);
    assertThat(response, is("{\"links\":[]}"));
    verify(mockVnetService);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) LinksResourceTest(org.onosproject.rest.resources.LinksResourceTest) ResourceTest(org.onosproject.rest.resources.ResourceTest) HostResourceTest(org.onosproject.rest.resources.HostResourceTest) Test(org.junit.Test)

Aggregations

NetworkId (org.onosproject.incubator.net.virtual.NetworkId)50 DeviceId (org.onosproject.net.DeviceId)23 Test (org.junit.Test)21 WebTarget (javax.ws.rs.client.WebTarget)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 HostResourceTest (org.onosproject.rest.resources.HostResourceTest)20 LinksResourceTest (org.onosproject.rest.resources.LinksResourceTest)20 ResourceTest (org.onosproject.rest.resources.ResourceTest)20 Activate (org.osgi.service.component.annotations.Activate)11 Logger (org.slf4j.Logger)11 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)11 Set (java.util.Set)10 Component (org.osgi.service.component.annotations.Component)10 Deactivate (org.osgi.service.component.annotations.Deactivate)10 HashSet (java.util.HashSet)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortNumber (org.onosproject.net.PortNumber)9 Reference (org.osgi.service.component.annotations.Reference)9 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)9