Search in sources :

Example 6 with VirtualLink

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

the class VirtualNetworkTopologyProviderTest method testTopologyChanged.

/**
 * Test the topologyChanged() method.
 */
@Test
public void testTopologyChanged() {
    // Initial setup is two clusters of devices/links.
    assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
    // Adding this link will join the two clusters together.
    List<Event> reasons = new ArrayList<>();
    VirtualLink link = manager.createVirtualLink(virtualNetwork.id(), cp6, cp7);
    virtualNetworkManagerStore.updateLink(link, link.tunnelId(), Link.State.ACTIVE);
    VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp7, cp6);
    virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_ADDED, link));
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_ADDED, link2));
    TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topologyService.currentTopology(), reasons);
    topologyProvider.topologyListener.event(event);
    // Wait for the topology changed event, and that the topologyChanged method was called.
    try {
        if (!changed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for topology changed event.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception." + e.getMessage());
    }
    // Validate that the topology changed method received a single cluster of connect points.
    // This means that the two previous clusters have now joined into a single cluster.
    assertEquals("The cluster count did not match.", 1, this.clusters.size());
    assertEquals("The cluster count did not match.", 1, topologyService.currentTopology().clusterCount());
    // Now remove the virtual link to split it back into two clusters.
    manager.removeVirtualLink(virtualNetwork.id(), link.src(), link.dst());
    manager.removeVirtualLink(virtualNetwork.id(), link2.src(), link2.dst());
    assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
    reasons = new ArrayList<>();
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_REMOVED, link));
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2));
    event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topologyService.currentTopology(), reasons);
    topologyProvider.topologyListener.event(event);
    // Wait for the topology changed event, and that the topologyChanged method was called.
    try {
        if (!changed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for topology changed event.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception." + e.getMessage());
    }
    // Validate that the topology changed method received two clusters of connect points.
    // This means that the single previous clusters has now split into two clusters.
    assertEquals("The cluster count did not match.", 2, this.clusters.size());
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ArrayList(java.util.ArrayList) LinkEvent(org.onosproject.net.link.LinkEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Test(org.junit.Test)

Example 7 with VirtualLink

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

the class DistributedVirtualNetworkStore method updateLink.

@Override
public void updateLink(VirtualLink virtualLink, TunnelId tunnelId, Link.State state) {
    checkState(networkExists(virtualLink.networkId()), "The network has not been added.");
    Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(virtualLink.networkId());
    if (virtualLinkSet == null) {
        virtualLinkSet = new HashSet<>();
        networkIdVirtualLinkSetMap.put(virtualLink.networkId(), virtualLinkSet);
        log.warn("The updated virtual link {} has not been added", virtualLink);
        return;
    }
    if (!virtualLinkSet.remove(virtualLink)) {
        log.warn("The updated virtual link {} does not exist", virtualLink);
        return;
    }
    VirtualLink newVirtualLink = DefaultVirtualLink.builder().networkId(virtualLink.networkId()).src(virtualLink.src()).dst(virtualLink.dst()).tunnelId(tunnelId).state(state).build();
    virtualLinkSet.add(newVirtualLink);
    networkIdVirtualLinkSetMap.put(newVirtualLink.networkId(), virtualLinkSet);
}
Also used : DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink)

Example 8 with VirtualLink

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

the class DistributedVirtualNetworkStore method removeLink.

@Override
public VirtualLink removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) {
    checkState(networkExists(networkId), "The network has not been added.");
    final VirtualLink virtualLink = getLink(networkId, src, dst);
    if (virtualLink == null) {
        log.warn("The removed virtual link between {} and {} does not exist", src, dst);
        return null;
    }
    Set<VirtualLink> virtualLinkSet = new HashSet<>();
    virtualLinkSet.add(virtualLink);
    networkIdVirtualLinkSetMap.compute(networkId, (id, existingVirtualLinks) -> {
        if (existingVirtualLinks == null || existingVirtualLinks.isEmpty()) {
            return new HashSet<>();
        } else {
            return new HashSet<>(Sets.difference(existingVirtualLinks, virtualLinkSet));
        }
    });
    return virtualLink;
}
Also used : DefaultVirtualLink(org.onosproject.incubator.net.virtual.DefaultVirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) HashSet(java.util.HashSet)

Example 9 with VirtualLink

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

the class VirtualNetworkWebResourceTest method testGetVirtualLinksArray.

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

Example 10 with VirtualLink

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

the class VirtualNetworkWebResource method removeVirtualLink.

/**
 * Removes the virtual network link from the JSON input stream.
 *
 * @param networkId network identifier
 * @param stream    virtual link JSON stream
 * @return 204 NO CONTENT
 * @onos.rsModel VirtualLink
 */
@DELETE
@Path("{networkId}/links")
@Consumes(MediaType.APPLICATION_JSON)
public Response removeVirtualLink(@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 VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this);
        vnetAdminService.removeVirtualLink(vlinkReq.networkId(), vlinkReq.src(), vlinkReq.dst());
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return Response.noContent().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Aggregations

VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)24 ConnectPoint (org.onosproject.net.ConnectPoint)11 DefaultVirtualLink (org.onosproject.incubator.net.virtual.DefaultVirtualLink)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 Test (org.junit.Test)7 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)4 Link (org.onosproject.net.Link)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 Event (org.onosproject.event.Event)2 VirtualNetworkEvent (org.onosproject.incubator.net.virtual.VirtualNetworkEvent)2 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)2