use of org.onosproject.incubator.net.virtual.VirtualLink in project onos by opennetworkinglab.
the class VirtualLinkListCommand method getSortedVirtualLinks.
/**
* Returns the list of virtual links sorted using the device identifier.
*
* @return virtual link list
*/
private List<VirtualLink> getSortedVirtualLinks() {
VirtualNetworkService service = get(VirtualNetworkService.class);
List<VirtualLink> virtualLinks = new ArrayList<>();
virtualLinks.addAll(service.getVirtualLinks(NetworkId.networkId(networkId)));
return virtualLinks;
}
use of org.onosproject.incubator.net.virtual.VirtualLink in project onos by opennetworkinglab.
the class VirtualLinkCodec method decode.
@Override
public VirtualLink decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonCodec<Link> codec = context.codec(Link.class);
Link link = codec.decode(json, context);
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
return DefaultVirtualLink.builder().networkId(nId).src(link.src()).dst(link.dst()).build();
}
use of org.onosproject.incubator.net.virtual.VirtualLink in project onos by opennetworkinglab.
the class VirtualLinkCodec method encode.
@Override
public ObjectNode encode(VirtualLink vLink, CodecContext context) {
checkNotNull(vLink, NULL_OBJECT_MSG);
ObjectNode result = context.mapper().createObjectNode().put(NETWORK_ID, vLink.networkId().toString());
JsonCodec<Link> codec = context.codec(Link.class);
ObjectNode linkResult = codec.encode(vLink, context);
result.setAll(linkResult);
return result;
}
use of org.onosproject.incubator.net.virtual.VirtualLink in project onos by opennetworkinglab.
the class VirtualNetworkTestUtil method setupVirtualNetworkTopology.
/**
* Method to create the virtual network for further testing.
*
* @return virtual network
*/
public static VirtualNetwork setupVirtualNetworkTopology(VirtualNetworkManager manager, TenantId tenantId) {
manager.registerTenantId(tenantId);
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(tenantId);
VirtualDevice virtualDevice1 = manager.createVirtualDevice(virtualNetwork.id(), VDID1);
VirtualDevice virtualDevice2 = manager.createVirtualDevice(virtualNetwork.id(), VDID2);
VirtualDevice virtualDevice3 = manager.createVirtualDevice(virtualNetwork.id(), VDID3);
VirtualDevice virtualDevice4 = manager.createVirtualDevice(virtualNetwork.id(), VDID4);
ConnectPoint vcp1 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1));
ConnectPoint cp1 = new ConnectPoint(DID1, PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), vcp1.deviceId(), vcp1.port(), cp1);
ConnectPoint vcp2 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(2));
ConnectPoint cp2 = new ConnectPoint(DID1, PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork.id(), vcp2.deviceId(), vcp2.port(), cp2);
ConnectPoint vcp3 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(3));
ConnectPoint cp3 = new ConnectPoint(DID2, PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), vcp3.deviceId(), vcp3.port(), cp3);
ConnectPoint vcp4 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(4));
ConnectPoint cp4 = new ConnectPoint(DID2, PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork.id(), vcp4.deviceId(), vcp4.port(), cp4);
ConnectPoint vcp5 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(5));
ConnectPoint cp5 = new ConnectPoint(DID3, PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), vcp5.deviceId(), vcp5.port(), cp5);
ConnectPoint vcp6 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(6));
ConnectPoint cp6 = new ConnectPoint(DID3, PortNumber.portNumber(2));
manager.createVirtualPort(virtualNetwork.id(), vcp6.deviceId(), vcp6.port(), cp6);
DistributedVirtualNetworkStore virtualNetworkManagerStore = (DistributedVirtualNetworkStore) manager.store;
VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), vcp1, vcp3);
virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), vcp3, vcp1);
virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
VirtualLink link3 = manager.createVirtualLink(virtualNetwork.id(), vcp4, vcp5);
virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE);
VirtualLink link4 = manager.createVirtualLink(virtualNetwork.id(), vcp5, vcp4);
virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE);
VirtualLink link5 = manager.createVirtualLink(virtualNetwork.id(), vcp2, vcp6);
virtualNetworkManagerStore.updateLink(link5, link5.tunnelId(), Link.State.ACTIVE);
VirtualLink link6 = manager.createVirtualLink(virtualNetwork.id(), vcp6, vcp2);
virtualNetworkManagerStore.updateLink(link6, link6.tunnelId(), Link.State.ACTIVE);
return virtualNetwork;
}
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());
}
Aggregations