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