Brian Stanke
Committed by Gerrit Code Review

ONOS-2184 - Adding VirtualNetworkTopologyService using Virtual networks.

Change-Id: Ib7071314b49e23dc67459f70e7ca345f8a97db4e
......@@ -35,6 +35,8 @@ public abstract class TestDeviceParams {
protected static final ProviderId PID = new ProviderId("of", "foo");
protected static final DeviceId DID1 = deviceId("of:foo");
protected static final DeviceId DID2 = deviceId("of:bar");
protected static final DeviceId DID3 = deviceId("of:who");
protected static final DeviceId DID4 = deviceId("of:what");
protected static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01");
protected static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02");
protected static final VlanId VLAN1 = VlanId.vlanId((short) 11);
......
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//core/common:onos-core-common',
'//incubator/api:onos-incubator-api',
]
......
......@@ -47,6 +47,7 @@ import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -287,6 +288,8 @@ public class VirtualNetworkManager
service = new VirtualNetworkDeviceService(this, network);
} else if (serviceKey.serviceClass.equals(LinkService.class)) {
service = new VirtualNetworkLinkService(this, network);
} else if (serviceKey.serviceClass.equals(TopologyService.class)) {
service = new VirtualNetworkTopologyService(this, network);
} else {
return null;
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.virtual.impl;
import org.onosproject.common.DefaultTopology;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.incubator.net.virtual.VirtualNetwork;
import org.onosproject.incubator.net.virtual.VirtualNetworkService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.DisjointPath;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.topology.ClusterId;
import org.onosproject.net.topology.DefaultGraphDescription;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyCluster;
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyGraph;
import org.onosproject.net.topology.TopologyListener;
import org.onosproject.net.topology.TopologyService;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.incubator.net.virtual.DefaultVirtualLink.PID;
/**
* Topology service implementation built on the virtual network service.
*/
public class VirtualNetworkTopologyService extends AbstractListenerManager<TopologyEvent, TopologyListener>
implements TopologyService, VnetService {
private static final String NETWORK_NULL = "Network ID cannot be null";
private static final String TOPOLOGY_NULL = "Topology cannot be null";
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null";
private static final String CLUSTER_NULL = "Topology cluster cannot be null";
private static final String CONNECTION_POINT_NULL = "Connection point cannot be null";
private static final String LINK_WEIGHT_NULL = "Link weight cannot be null";
private final VirtualNetwork network;
private final VirtualNetworkService manager;
/**
* Creates a new VirtualNetworkTopologyService object.
*
* @param virtualNetworkManager virtual network manager service
* @param network virtual network
*/
public VirtualNetworkTopologyService(VirtualNetworkService virtualNetworkManager, VirtualNetwork network) {
checkNotNull(network, NETWORK_NULL);
this.network = network;
this.manager = virtualNetworkManager;
}
@Override
public Topology currentTopology() {
Iterable<Device> devices = manager.getVirtualDevices(network().id())
.stream()
.collect(Collectors.toSet());
Iterable<Link> links = manager.getVirtualLinks(network().id())
.stream()
.collect(Collectors.toSet());
DefaultGraphDescription graph = new DefaultGraphDescription(System.nanoTime(), System.currentTimeMillis(),
devices, links);
return new DefaultTopology(PID, graph);
}
@Override
public boolean isLatest(Topology topology) {
Topology currentTopology = currentTopology();
return defaultTopology(topology).getGraph().equals(defaultTopology(currentTopology).getGraph());
}
@Override
public TopologyGraph getGraph(Topology topology) {
return defaultTopology(topology).getGraph();
}
// Validates the specified topology and returns it as a default
private DefaultTopology defaultTopology(Topology topology) {
checkNotNull(topology, TOPOLOGY_NULL);
checkArgument(topology instanceof DefaultTopology,
"Topology class %s not supported", topology.getClass());
return (DefaultTopology) topology;
}
@Override
public Set<TopologyCluster> getClusters(Topology topology) {
return defaultTopology(topology).getClusters();
}
@Override
public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
checkNotNull(clusterId, CLUSTER_ID_NULL);
return defaultTopology(topology).getCluster(clusterId);
}
@Override
public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
checkNotNull(cluster, CLUSTER_NULL);
return defaultTopology(topology).getClusterDevices(cluster);
}
@Override
public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
checkNotNull(cluster, CLUSTER_NULL);
return defaultTopology(topology).getClusterLinks(cluster);
}
@Override
public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
return defaultTopology(topology).getPaths(src, dst);
}
@Override
public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
checkNotNull(weight, LINK_WEIGHT_NULL);
return defaultTopology(topology).getPaths(src, dst, weight);
}
@Override
public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
return defaultTopology(topology).getDisjointPaths(src, dst);
}
@Override
public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
checkNotNull(weight, LINK_WEIGHT_NULL);
return defaultTopology(topology).getDisjointPaths(src, dst, weight);
}
@Override
public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
Map<Link, Object> riskProfile) {
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
return defaultTopology(topology).getDisjointPaths(src, dst, riskProfile);
}
@Override
public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
LinkWeight weight, Map<Link, Object> riskProfile) {
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
checkNotNull(weight, LINK_WEIGHT_NULL);
return defaultTopology(topology).getDisjointPaths(src, dst, weight, riskProfile);
}
@Override
public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return defaultTopology(topology).isInfrastructure(connectPoint);
}
@Override
public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return defaultTopology(topology).isBroadcastPoint(connectPoint);
}
@Override
public VirtualNetwork network() {
return network;
}
}
......@@ -32,11 +32,11 @@ import org.onosproject.incubator.net.virtual.VirtualPort;
import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
import org.onosproject.net.DefaultPort;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TestDeviceParams;
import org.onosproject.net.device.DeviceService;
import org.onosproject.store.service.TestStorageService;
......@@ -48,11 +48,8 @@ import static org.junit.Assert.*;
/**
* Junit tests for VirtualNetworkDeviceService.
*/
public class VirtualNetworkDeviceServiceTest {
public class VirtualNetworkDeviceServiceTest extends TestDeviceParams {
private final String tenantIdValue1 = "TENANT_ID1";
private final String deviceIdValue1 = "DEVICE_ID1";
private final String deviceIdValue2 = "DEVICE_ID2";
private final String deviceIdValue3 = "DEVICE_ID3";
private VirtualNetworkManager manager;
private DistributedVirtualNetworkStore virtualNetworkManagerStore;
......@@ -88,8 +85,8 @@ public class VirtualNetworkDeviceServiceTest {
public void testGetDevices() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1));
VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), DID1);
VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
......@@ -106,15 +103,15 @@ public class VirtualNetworkDeviceServiceTest {
// test the getDevice() method
assertEquals("The expect device did not match.", device1,
deviceService.getDevice(DeviceId.deviceId(deviceIdValue1)));
deviceService.getDevice(DID1));
assertNotEquals("The expect device should not have matched.", device1,
deviceService.getDevice(DeviceId.deviceId(deviceIdValue2)));
deviceService.getDevice(DID2));
// test the isAvailable() method
assertTrue("The expect device availability did not match.",
deviceService.isAvailable(DeviceId.deviceId(deviceIdValue1)));
deviceService.isAvailable(DID1));
assertFalse("The expect device availability did not match.",
deviceService.isAvailable(DeviceId.deviceId(deviceIdValue3)));
deviceService.isAvailable(DID3));
}
/**
......@@ -163,8 +160,8 @@ public class VirtualNetworkDeviceServiceTest {
public void testGetDeviceType() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
......@@ -203,7 +200,7 @@ public class VirtualNetworkDeviceServiceTest {
// test the getRole() method
assertEquals("The expect device role did not match.", MastershipRole.MASTER,
deviceService.getRole(DeviceId.deviceId(deviceIdValue1)));
deviceService.getRole(DID1));
}
/**
......@@ -226,9 +223,8 @@ public class VirtualNetworkDeviceServiceTest {
public void testGetPorts() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(),
DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
......@@ -239,9 +235,9 @@ public class VirtualNetworkDeviceServiceTest {
// test the getPorts() method
assertEquals("The port set size did not match.", 2,
deviceService.getPorts(DeviceId.deviceId(deviceIdValue1)).size());
deviceService.getPorts(DID1).size());
assertEquals("The port set size did not match.", 0,
deviceService.getPorts(DeviceId.deviceId(deviceIdValue2)).size());
deviceService.getPorts(DID2).size());
}
/**
......@@ -251,9 +247,8 @@ public class VirtualNetworkDeviceServiceTest {
public void testGetPort() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(),
DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
......@@ -265,9 +260,9 @@ public class VirtualNetworkDeviceServiceTest {
// test the getPort() method
assertEquals("The port did not match as expected.", virtualPort1,
deviceService.getPort(DeviceId.deviceId(deviceIdValue1), PortNumber.portNumber(1)));
deviceService.getPort(DID1, PortNumber.portNumber(1)));
assertNotEquals("The port did not match as expected.", virtualPort1,
deviceService.getPort(DeviceId.deviceId(deviceIdValue1), PortNumber.portNumber(3)));
deviceService.getPort(DID1, PortNumber.portNumber(3)));
}
/**
......@@ -290,15 +285,14 @@ public class VirtualNetworkDeviceServiceTest {
public void testGetPortStatistics() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(),
DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
// test the getPortStatistics() method
assertEquals("The port statistics set size did not match.", 0,
deviceService.getPortStatistics(DeviceId.deviceId(deviceIdValue1)).size());
deviceService.getPortStatistics(DID1).size());
}
/**
......@@ -321,15 +315,14 @@ public class VirtualNetworkDeviceServiceTest {
public void testGetPortDeltaStatistics() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(),
DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
// test the getPortDeltaStatistics() method
assertEquals("The port delta statistics set size did not match.", 0,
deviceService.getPortDeltaStatistics(DeviceId.deviceId(deviceIdValue1)).size());
deviceService.getPortDeltaStatistics(DID1).size());
}
/**
......
......@@ -31,10 +31,10 @@ import org.onosproject.incubator.net.virtual.VirtualLink;
import org.onosproject.incubator.net.virtual.VirtualNetwork;
import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TestDeviceParams;
import org.onosproject.net.link.LinkService;
import org.onosproject.store.service.TestStorageService;
......@@ -47,12 +47,9 @@ import static org.junit.Assert.assertNotEquals;
/**
* Junit tests for VirtualNetworkLinkService.
*/
public class VirtualNetworkLinkServiceTest {
public class VirtualNetworkLinkServiceTest extends TestDeviceParams {
private final String tenantIdValue1 = "TENANT_ID1";
private final String deviceIdValue1 = "DEVICE_ID1";
private final String deviceIdValue2 = "DEVICE_ID2";
private final String deviceIdValue3 = "DEVICE_ID3";
private VirtualNetworkManager manager;
private DistributedVirtualNetworkStore virtualNetworkManagerStore;
......@@ -92,9 +89,9 @@ public class VirtualNetworkLinkServiceTest {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice srcVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DID1);
VirtualDevice dstVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
manager.createVirtualDevice(virtualNetwork.id(), DID2);
ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst);
......@@ -134,27 +131,27 @@ public class VirtualNetworkLinkServiceTest {
// test the getDeviceLinks() method
assertEquals("The link set size did not match.", 2,
linkService.getDeviceLinks(DeviceId.deviceId(deviceIdValue1)).size());
linkService.getDeviceLinks(DID1).size());
assertEquals("The link set size did not match.", 2,
linkService.getDeviceLinks(DeviceId.deviceId(deviceIdValue2)).size());
linkService.getDeviceLinks(DID2).size());
assertEquals("The link set size did not match.", 0,
linkService.getDeviceLinks(DeviceId.deviceId(deviceIdValue3)).size());
linkService.getDeviceLinks(DID3).size());
// test the getDeviceEgressLinks() method
assertEquals("The link set size did not match.", 1,
linkService.getDeviceEgressLinks(DeviceId.deviceId(deviceIdValue1)).size());
linkService.getDeviceEgressLinks(DID1).size());
assertEquals("The link set size did not match.", 1,
linkService.getDeviceEgressLinks(DeviceId.deviceId(deviceIdValue2)).size());
linkService.getDeviceEgressLinks(DID2).size());
assertEquals("The link set size did not match.", 0,
linkService.getDeviceEgressLinks(DeviceId.deviceId(deviceIdValue3)).size());
linkService.getDeviceEgressLinks(DID3).size());
// test the getDeviceIngressLinks() method
assertEquals("The link set size did not match.", 1,
linkService.getDeviceIngressLinks(DeviceId.deviceId(deviceIdValue1)).size());
linkService.getDeviceIngressLinks(DID1).size());
assertEquals("The link set size did not match.", 1,
linkService.getDeviceIngressLinks(DeviceId.deviceId(deviceIdValue2)).size());
linkService.getDeviceIngressLinks(DID2).size());
assertEquals("The link set size did not match.", 0,
linkService.getDeviceIngressLinks(DeviceId.deviceId(deviceIdValue3)).size());
linkService.getDeviceIngressLinks(DID3).size());
// test the getEgressLinks() method
assertEquals("The link set size did not match.", 1,
......@@ -182,9 +179,9 @@ public class VirtualNetworkLinkServiceTest {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice srcVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DID1);
VirtualDevice dstVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
manager.createVirtualDevice(virtualNetwork.id(), DID2);
ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
manager.createVirtualLink(virtualNetwork.id(), src, dst);
......@@ -205,9 +202,9 @@ public class VirtualNetworkLinkServiceTest {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice srcVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1));
manager.createVirtualDevice(virtualNetwork.id(), DID1);
VirtualDevice dstVirtualDevice =
manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2));
manager.createVirtualDevice(virtualNetwork.id(), DID2);
ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
manager.createVirtualLink(virtualNetwork.id(), src, dst);
......