Committed by
Gerrit Code Review
ONOS-2184 - Adding VirtualNetworkTopologyService using Virtual networks.
Change-Id: Ib7071314b49e23dc67459f70e7ca345f8a97db4e
Showing
7 changed files
with
842 additions
and
52 deletions
| ... | @@ -35,6 +35,8 @@ public abstract class TestDeviceParams { | ... | @@ -35,6 +35,8 @@ public abstract class TestDeviceParams { |
| 35 | protected static final ProviderId PID = new ProviderId("of", "foo"); | 35 | protected static final ProviderId PID = new ProviderId("of", "foo"); |
| 36 | protected static final DeviceId DID1 = deviceId("of:foo"); | 36 | protected static final DeviceId DID1 = deviceId("of:foo"); |
| 37 | protected static final DeviceId DID2 = deviceId("of:bar"); | 37 | protected static final DeviceId DID2 = deviceId("of:bar"); |
| 38 | + protected static final DeviceId DID3 = deviceId("of:who"); | ||
| 39 | + protected static final DeviceId DID4 = deviceId("of:what"); | ||
| 38 | protected static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01"); | 40 | protected static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01"); |
| 39 | protected static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02"); | 41 | protected static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02"); |
| 40 | protected static final VlanId VLAN1 = VlanId.vlanId((short) 11); | 42 | protected static final VlanId VLAN1 = VlanId.vlanId((short) 11); | ... | ... |
| ... | @@ -47,6 +47,7 @@ import org.onosproject.net.device.DeviceService; | ... | @@ -47,6 +47,7 @@ import org.onosproject.net.device.DeviceService; |
| 47 | import org.onosproject.net.link.LinkService; | 47 | import org.onosproject.net.link.LinkService; |
| 48 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; | 48 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
| 49 | import org.onosproject.net.provider.AbstractProviderService; | 49 | import org.onosproject.net.provider.AbstractProviderService; |
| 50 | +import org.onosproject.net.topology.TopologyService; | ||
| 50 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
| 51 | import org.slf4j.LoggerFactory; | 52 | import org.slf4j.LoggerFactory; |
| 52 | 53 | ||
| ... | @@ -287,6 +288,8 @@ public class VirtualNetworkManager | ... | @@ -287,6 +288,8 @@ public class VirtualNetworkManager |
| 287 | service = new VirtualNetworkDeviceService(this, network); | 288 | service = new VirtualNetworkDeviceService(this, network); |
| 288 | } else if (serviceKey.serviceClass.equals(LinkService.class)) { | 289 | } else if (serviceKey.serviceClass.equals(LinkService.class)) { |
| 289 | service = new VirtualNetworkLinkService(this, network); | 290 | service = new VirtualNetworkLinkService(this, network); |
| 291 | + } else if (serviceKey.serviceClass.equals(TopologyService.class)) { | ||
| 292 | + service = new VirtualNetworkTopologyService(this, network); | ||
| 290 | } else { | 293 | } else { |
| 291 | return null; | 294 | return null; |
| 292 | } | 295 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.incubator.net.virtual.impl; | ||
| 18 | + | ||
| 19 | +import org.onosproject.common.DefaultTopology; | ||
| 20 | +import org.onosproject.event.AbstractListenerManager; | ||
| 21 | +import org.onosproject.incubator.net.virtual.VirtualNetwork; | ||
| 22 | +import org.onosproject.incubator.net.virtual.VirtualNetworkService; | ||
| 23 | +import org.onosproject.net.ConnectPoint; | ||
| 24 | +import org.onosproject.net.Device; | ||
| 25 | +import org.onosproject.net.DeviceId; | ||
| 26 | +import org.onosproject.net.DisjointPath; | ||
| 27 | +import org.onosproject.net.Link; | ||
| 28 | +import org.onosproject.net.Path; | ||
| 29 | +import org.onosproject.net.topology.ClusterId; | ||
| 30 | +import org.onosproject.net.topology.DefaultGraphDescription; | ||
| 31 | +import org.onosproject.net.topology.LinkWeight; | ||
| 32 | +import org.onosproject.net.topology.Topology; | ||
| 33 | +import org.onosproject.net.topology.TopologyCluster; | ||
| 34 | +import org.onosproject.net.topology.TopologyEvent; | ||
| 35 | +import org.onosproject.net.topology.TopologyGraph; | ||
| 36 | +import org.onosproject.net.topology.TopologyListener; | ||
| 37 | +import org.onosproject.net.topology.TopologyService; | ||
| 38 | + | ||
| 39 | +import java.util.Map; | ||
| 40 | +import java.util.Set; | ||
| 41 | +import java.util.stream.Collectors; | ||
| 42 | + | ||
| 43 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 44 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 45 | +import static org.onosproject.incubator.net.virtual.DefaultVirtualLink.PID; | ||
| 46 | + | ||
| 47 | +/** | ||
| 48 | + * Topology service implementation built on the virtual network service. | ||
| 49 | + */ | ||
| 50 | +public class VirtualNetworkTopologyService extends AbstractListenerManager<TopologyEvent, TopologyListener> | ||
| 51 | + implements TopologyService, VnetService { | ||
| 52 | + | ||
| 53 | + private static final String NETWORK_NULL = "Network ID cannot be null"; | ||
| 54 | + private static final String TOPOLOGY_NULL = "Topology cannot be null"; | ||
| 55 | + private static final String DEVICE_ID_NULL = "Device ID cannot be null"; | ||
| 56 | + private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null"; | ||
| 57 | + private static final String CLUSTER_NULL = "Topology cluster cannot be null"; | ||
| 58 | + private static final String CONNECTION_POINT_NULL = "Connection point cannot be null"; | ||
| 59 | + private static final String LINK_WEIGHT_NULL = "Link weight cannot be null"; | ||
| 60 | + | ||
| 61 | + private final VirtualNetwork network; | ||
| 62 | + private final VirtualNetworkService manager; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * Creates a new VirtualNetworkTopologyService object. | ||
| 66 | + * | ||
| 67 | + * @param virtualNetworkManager virtual network manager service | ||
| 68 | + * @param network virtual network | ||
| 69 | + */ | ||
| 70 | + public VirtualNetworkTopologyService(VirtualNetworkService virtualNetworkManager, VirtualNetwork network) { | ||
| 71 | + checkNotNull(network, NETWORK_NULL); | ||
| 72 | + this.network = network; | ||
| 73 | + this.manager = virtualNetworkManager; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public Topology currentTopology() { | ||
| 78 | + Iterable<Device> devices = manager.getVirtualDevices(network().id()) | ||
| 79 | + .stream() | ||
| 80 | + .collect(Collectors.toSet()); | ||
| 81 | + Iterable<Link> links = manager.getVirtualLinks(network().id()) | ||
| 82 | + .stream() | ||
| 83 | + .collect(Collectors.toSet()); | ||
| 84 | + | ||
| 85 | + DefaultGraphDescription graph = new DefaultGraphDescription(System.nanoTime(), System.currentTimeMillis(), | ||
| 86 | + devices, links); | ||
| 87 | + return new DefaultTopology(PID, graph); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public boolean isLatest(Topology topology) { | ||
| 92 | + Topology currentTopology = currentTopology(); | ||
| 93 | + return defaultTopology(topology).getGraph().equals(defaultTopology(currentTopology).getGraph()); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public TopologyGraph getGraph(Topology topology) { | ||
| 98 | + return defaultTopology(topology).getGraph(); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + // Validates the specified topology and returns it as a default | ||
| 102 | + private DefaultTopology defaultTopology(Topology topology) { | ||
| 103 | + checkNotNull(topology, TOPOLOGY_NULL); | ||
| 104 | + checkArgument(topology instanceof DefaultTopology, | ||
| 105 | + "Topology class %s not supported", topology.getClass()); | ||
| 106 | + return (DefaultTopology) topology; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + public Set<TopologyCluster> getClusters(Topology topology) { | ||
| 111 | + return defaultTopology(topology).getClusters(); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public TopologyCluster getCluster(Topology topology, ClusterId clusterId) { | ||
| 116 | + checkNotNull(clusterId, CLUSTER_ID_NULL); | ||
| 117 | + return defaultTopology(topology).getCluster(clusterId); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Override | ||
| 121 | + public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) { | ||
| 122 | + checkNotNull(cluster, CLUSTER_NULL); | ||
| 123 | + return defaultTopology(topology).getClusterDevices(cluster); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + @Override | ||
| 127 | + public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) { | ||
| 128 | + checkNotNull(cluster, CLUSTER_NULL); | ||
| 129 | + return defaultTopology(topology).getClusterLinks(cluster); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) { | ||
| 134 | + checkNotNull(src, DEVICE_ID_NULL); | ||
| 135 | + checkNotNull(dst, DEVICE_ID_NULL); | ||
| 136 | + return defaultTopology(topology).getPaths(src, dst); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @Override | ||
| 140 | + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) { | ||
| 141 | + checkNotNull(src, DEVICE_ID_NULL); | ||
| 142 | + checkNotNull(dst, DEVICE_ID_NULL); | ||
| 143 | + checkNotNull(weight, LINK_WEIGHT_NULL); | ||
| 144 | + return defaultTopology(topology).getPaths(src, dst, weight); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + @Override | ||
| 148 | + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) { | ||
| 149 | + checkNotNull(src, DEVICE_ID_NULL); | ||
| 150 | + checkNotNull(dst, DEVICE_ID_NULL); | ||
| 151 | + return defaultTopology(topology).getDisjointPaths(src, dst); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + @Override | ||
| 155 | + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) { | ||
| 156 | + checkNotNull(src, DEVICE_ID_NULL); | ||
| 157 | + checkNotNull(dst, DEVICE_ID_NULL); | ||
| 158 | + checkNotNull(weight, LINK_WEIGHT_NULL); | ||
| 159 | + return defaultTopology(topology).getDisjointPaths(src, dst, weight); | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + @Override | ||
| 163 | + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, | ||
| 164 | + Map<Link, Object> riskProfile) { | ||
| 165 | + checkNotNull(src, DEVICE_ID_NULL); | ||
| 166 | + checkNotNull(dst, DEVICE_ID_NULL); | ||
| 167 | + return defaultTopology(topology).getDisjointPaths(src, dst, riskProfile); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, | ||
| 172 | + LinkWeight weight, Map<Link, Object> riskProfile) { | ||
| 173 | + checkNotNull(src, DEVICE_ID_NULL); | ||
| 174 | + checkNotNull(dst, DEVICE_ID_NULL); | ||
| 175 | + checkNotNull(weight, LINK_WEIGHT_NULL); | ||
| 176 | + return defaultTopology(topology).getDisjointPaths(src, dst, weight, riskProfile); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + @Override | ||
| 180 | + public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { | ||
| 181 | + checkNotNull(connectPoint, CONNECTION_POINT_NULL); | ||
| 182 | + return defaultTopology(topology).isInfrastructure(connectPoint); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 186 | + public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) { | ||
| 187 | + checkNotNull(connectPoint, CONNECTION_POINT_NULL); | ||
| 188 | + return defaultTopology(topology).isBroadcastPoint(connectPoint); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + @Override | ||
| 192 | + public VirtualNetwork network() { | ||
| 193 | + return network; | ||
| 194 | + } | ||
| 195 | +} |
| ... | @@ -32,11 +32,11 @@ import org.onosproject.incubator.net.virtual.VirtualPort; | ... | @@ -32,11 +32,11 @@ import org.onosproject.incubator.net.virtual.VirtualPort; |
| 32 | import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore; | 32 | import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore; |
| 33 | import org.onosproject.net.DefaultPort; | 33 | import org.onosproject.net.DefaultPort; |
| 34 | import org.onosproject.net.Device; | 34 | import org.onosproject.net.Device; |
| 35 | -import org.onosproject.net.DeviceId; | ||
| 36 | import org.onosproject.net.MastershipRole; | 35 | import org.onosproject.net.MastershipRole; |
| 37 | import org.onosproject.net.NetTestTools; | 36 | import org.onosproject.net.NetTestTools; |
| 38 | import org.onosproject.net.Port; | 37 | import org.onosproject.net.Port; |
| 39 | import org.onosproject.net.PortNumber; | 38 | import org.onosproject.net.PortNumber; |
| 39 | +import org.onosproject.net.TestDeviceParams; | ||
| 40 | import org.onosproject.net.device.DeviceService; | 40 | import org.onosproject.net.device.DeviceService; |
| 41 | import org.onosproject.store.service.TestStorageService; | 41 | import org.onosproject.store.service.TestStorageService; |
| 42 | 42 | ||
| ... | @@ -48,11 +48,8 @@ import static org.junit.Assert.*; | ... | @@ -48,11 +48,8 @@ import static org.junit.Assert.*; |
| 48 | /** | 48 | /** |
| 49 | * Junit tests for VirtualNetworkDeviceService. | 49 | * Junit tests for VirtualNetworkDeviceService. |
| 50 | */ | 50 | */ |
| 51 | -public class VirtualNetworkDeviceServiceTest { | 51 | +public class VirtualNetworkDeviceServiceTest extends TestDeviceParams { |
| 52 | private final String tenantIdValue1 = "TENANT_ID1"; | 52 | private final String tenantIdValue1 = "TENANT_ID1"; |
| 53 | - private final String deviceIdValue1 = "DEVICE_ID1"; | ||
| 54 | - private final String deviceIdValue2 = "DEVICE_ID2"; | ||
| 55 | - private final String deviceIdValue3 = "DEVICE_ID3"; | ||
| 56 | 53 | ||
| 57 | private VirtualNetworkManager manager; | 54 | private VirtualNetworkManager manager; |
| 58 | private DistributedVirtualNetworkStore virtualNetworkManagerStore; | 55 | private DistributedVirtualNetworkStore virtualNetworkManagerStore; |
| ... | @@ -88,8 +85,8 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -88,8 +85,8 @@ public class VirtualNetworkDeviceServiceTest { |
| 88 | public void testGetDevices() { | 85 | public void testGetDevices() { |
| 89 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 86 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 90 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 87 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 91 | - VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1)); | 88 | + VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 92 | - VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | 89 | + VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 93 | 90 | ||
| 94 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); | 91 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); |
| 95 | 92 | ||
| ... | @@ -106,15 +103,15 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -106,15 +103,15 @@ public class VirtualNetworkDeviceServiceTest { |
| 106 | 103 | ||
| 107 | // test the getDevice() method | 104 | // test the getDevice() method |
| 108 | assertEquals("The expect device did not match.", device1, | 105 | assertEquals("The expect device did not match.", device1, |
| 109 | - deviceService.getDevice(DeviceId.deviceId(deviceIdValue1))); | 106 | + deviceService.getDevice(DID1)); |
| 110 | assertNotEquals("The expect device should not have matched.", device1, | 107 | assertNotEquals("The expect device should not have matched.", device1, |
| 111 | - deviceService.getDevice(DeviceId.deviceId(deviceIdValue2))); | 108 | + deviceService.getDevice(DID2)); |
| 112 | 109 | ||
| 113 | // test the isAvailable() method | 110 | // test the isAvailable() method |
| 114 | assertTrue("The expect device availability did not match.", | 111 | assertTrue("The expect device availability did not match.", |
| 115 | - deviceService.isAvailable(DeviceId.deviceId(deviceIdValue1))); | 112 | + deviceService.isAvailable(DID1)); |
| 116 | assertFalse("The expect device availability did not match.", | 113 | assertFalse("The expect device availability did not match.", |
| 117 | - deviceService.isAvailable(DeviceId.deviceId(deviceIdValue3))); | 114 | + deviceService.isAvailable(DID3)); |
| 118 | } | 115 | } |
| 119 | 116 | ||
| 120 | /** | 117 | /** |
| ... | @@ -163,8 +160,8 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -163,8 +160,8 @@ public class VirtualNetworkDeviceServiceTest { |
| 163 | public void testGetDeviceType() { | 160 | public void testGetDeviceType() { |
| 164 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 161 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 165 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 162 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 166 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1)); | 163 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 167 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | 164 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 168 | 165 | ||
| 169 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); | 166 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); |
| 170 | 167 | ||
| ... | @@ -203,7 +200,7 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -203,7 +200,7 @@ public class VirtualNetworkDeviceServiceTest { |
| 203 | 200 | ||
| 204 | // test the getRole() method | 201 | // test the getRole() method |
| 205 | assertEquals("The expect device role did not match.", MastershipRole.MASTER, | 202 | assertEquals("The expect device role did not match.", MastershipRole.MASTER, |
| 206 | - deviceService.getRole(DeviceId.deviceId(deviceIdValue1))); | 203 | + deviceService.getRole(DID1)); |
| 207 | } | 204 | } |
| 208 | 205 | ||
| 209 | /** | 206 | /** |
| ... | @@ -226,9 +223,8 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -226,9 +223,8 @@ public class VirtualNetworkDeviceServiceTest { |
| 226 | public void testGetPorts() { | 223 | public void testGetPorts() { |
| 227 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 224 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 228 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 225 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 229 | - VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), | 226 | + VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 230 | - DeviceId.deviceId(deviceIdValue1)); | 227 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 231 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | ||
| 232 | 228 | ||
| 233 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); | 229 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); |
| 234 | 230 | ||
| ... | @@ -239,9 +235,9 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -239,9 +235,9 @@ public class VirtualNetworkDeviceServiceTest { |
| 239 | 235 | ||
| 240 | // test the getPorts() method | 236 | // test the getPorts() method |
| 241 | assertEquals("The port set size did not match.", 2, | 237 | assertEquals("The port set size did not match.", 2, |
| 242 | - deviceService.getPorts(DeviceId.deviceId(deviceIdValue1)).size()); | 238 | + deviceService.getPorts(DID1).size()); |
| 243 | assertEquals("The port set size did not match.", 0, | 239 | assertEquals("The port set size did not match.", 0, |
| 244 | - deviceService.getPorts(DeviceId.deviceId(deviceIdValue2)).size()); | 240 | + deviceService.getPorts(DID2).size()); |
| 245 | } | 241 | } |
| 246 | 242 | ||
| 247 | /** | 243 | /** |
| ... | @@ -251,9 +247,8 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -251,9 +247,8 @@ public class VirtualNetworkDeviceServiceTest { |
| 251 | public void testGetPort() { | 247 | public void testGetPort() { |
| 252 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 248 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 253 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 249 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 254 | - VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), | 250 | + VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 255 | - DeviceId.deviceId(deviceIdValue1)); | 251 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 256 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | ||
| 257 | 252 | ||
| 258 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); | 253 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); |
| 259 | 254 | ||
| ... | @@ -265,9 +260,9 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -265,9 +260,9 @@ public class VirtualNetworkDeviceServiceTest { |
| 265 | 260 | ||
| 266 | // test the getPort() method | 261 | // test the getPort() method |
| 267 | assertEquals("The port did not match as expected.", virtualPort1, | 262 | assertEquals("The port did not match as expected.", virtualPort1, |
| 268 | - deviceService.getPort(DeviceId.deviceId(deviceIdValue1), PortNumber.portNumber(1))); | 263 | + deviceService.getPort(DID1, PortNumber.portNumber(1))); |
| 269 | assertNotEquals("The port did not match as expected.", virtualPort1, | 264 | assertNotEquals("The port did not match as expected.", virtualPort1, |
| 270 | - deviceService.getPort(DeviceId.deviceId(deviceIdValue1), PortNumber.portNumber(3))); | 265 | + deviceService.getPort(DID1, PortNumber.portNumber(3))); |
| 271 | } | 266 | } |
| 272 | 267 | ||
| 273 | /** | 268 | /** |
| ... | @@ -290,15 +285,14 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -290,15 +285,14 @@ public class VirtualNetworkDeviceServiceTest { |
| 290 | public void testGetPortStatistics() { | 285 | public void testGetPortStatistics() { |
| 291 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 286 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 292 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 287 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 293 | - VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), | 288 | + VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 294 | - DeviceId.deviceId(deviceIdValue1)); | 289 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 295 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | ||
| 296 | 290 | ||
| 297 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); | 291 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); |
| 298 | 292 | ||
| 299 | // test the getPortStatistics() method | 293 | // test the getPortStatistics() method |
| 300 | assertEquals("The port statistics set size did not match.", 0, | 294 | assertEquals("The port statistics set size did not match.", 0, |
| 301 | - deviceService.getPortStatistics(DeviceId.deviceId(deviceIdValue1)).size()); | 295 | + deviceService.getPortStatistics(DID1).size()); |
| 302 | } | 296 | } |
| 303 | 297 | ||
| 304 | /** | 298 | /** |
| ... | @@ -321,15 +315,14 @@ public class VirtualNetworkDeviceServiceTest { | ... | @@ -321,15 +315,14 @@ public class VirtualNetworkDeviceServiceTest { |
| 321 | public void testGetPortDeltaStatistics() { | 315 | public void testGetPortDeltaStatistics() { |
| 322 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 316 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 323 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 317 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 324 | - VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), | 318 | + VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 325 | - DeviceId.deviceId(deviceIdValue1)); | 319 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 326 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | ||
| 327 | 320 | ||
| 328 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); | 321 | DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class); |
| 329 | 322 | ||
| 330 | // test the getPortDeltaStatistics() method | 323 | // test the getPortDeltaStatistics() method |
| 331 | assertEquals("The port delta statistics set size did not match.", 0, | 324 | assertEquals("The port delta statistics set size did not match.", 0, |
| 332 | - deviceService.getPortDeltaStatistics(DeviceId.deviceId(deviceIdValue1)).size()); | 325 | + deviceService.getPortDeltaStatistics(DID1).size()); |
| 333 | } | 326 | } |
| 334 | 327 | ||
| 335 | /** | 328 | /** | ... | ... |
| ... | @@ -31,10 +31,10 @@ import org.onosproject.incubator.net.virtual.VirtualLink; | ... | @@ -31,10 +31,10 @@ import org.onosproject.incubator.net.virtual.VirtualLink; |
| 31 | import org.onosproject.incubator.net.virtual.VirtualNetwork; | 31 | import org.onosproject.incubator.net.virtual.VirtualNetwork; |
| 32 | import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore; | 32 | import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore; |
| 33 | import org.onosproject.net.ConnectPoint; | 33 | import org.onosproject.net.ConnectPoint; |
| 34 | -import org.onosproject.net.DeviceId; | ||
| 35 | import org.onosproject.net.Link; | 34 | import org.onosproject.net.Link; |
| 36 | import org.onosproject.net.NetTestTools; | 35 | import org.onosproject.net.NetTestTools; |
| 37 | import org.onosproject.net.PortNumber; | 36 | import org.onosproject.net.PortNumber; |
| 37 | +import org.onosproject.net.TestDeviceParams; | ||
| 38 | import org.onosproject.net.link.LinkService; | 38 | import org.onosproject.net.link.LinkService; |
| 39 | import org.onosproject.store.service.TestStorageService; | 39 | import org.onosproject.store.service.TestStorageService; |
| 40 | 40 | ||
| ... | @@ -47,12 +47,9 @@ import static org.junit.Assert.assertNotEquals; | ... | @@ -47,12 +47,9 @@ import static org.junit.Assert.assertNotEquals; |
| 47 | /** | 47 | /** |
| 48 | * Junit tests for VirtualNetworkLinkService. | 48 | * Junit tests for VirtualNetworkLinkService. |
| 49 | */ | 49 | */ |
| 50 | -public class VirtualNetworkLinkServiceTest { | 50 | +public class VirtualNetworkLinkServiceTest extends TestDeviceParams { |
| 51 | 51 | ||
| 52 | private final String tenantIdValue1 = "TENANT_ID1"; | 52 | private final String tenantIdValue1 = "TENANT_ID1"; |
| 53 | - private final String deviceIdValue1 = "DEVICE_ID1"; | ||
| 54 | - private final String deviceIdValue2 = "DEVICE_ID2"; | ||
| 55 | - private final String deviceIdValue3 = "DEVICE_ID3"; | ||
| 56 | 53 | ||
| 57 | private VirtualNetworkManager manager; | 54 | private VirtualNetworkManager manager; |
| 58 | private DistributedVirtualNetworkStore virtualNetworkManagerStore; | 55 | private DistributedVirtualNetworkStore virtualNetworkManagerStore; |
| ... | @@ -92,9 +89,9 @@ public class VirtualNetworkLinkServiceTest { | ... | @@ -92,9 +89,9 @@ public class VirtualNetworkLinkServiceTest { |
| 92 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 89 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 93 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 90 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 94 | VirtualDevice srcVirtualDevice = | 91 | VirtualDevice srcVirtualDevice = |
| 95 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1)); | 92 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 96 | VirtualDevice dstVirtualDevice = | 93 | VirtualDevice dstVirtualDevice = |
| 97 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | 94 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 98 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | 95 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
| 99 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | 96 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); |
| 100 | VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst); | 97 | VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst); |
| ... | @@ -134,27 +131,27 @@ public class VirtualNetworkLinkServiceTest { | ... | @@ -134,27 +131,27 @@ public class VirtualNetworkLinkServiceTest { |
| 134 | 131 | ||
| 135 | // test the getDeviceLinks() method | 132 | // test the getDeviceLinks() method |
| 136 | assertEquals("The link set size did not match.", 2, | 133 | assertEquals("The link set size did not match.", 2, |
| 137 | - linkService.getDeviceLinks(DeviceId.deviceId(deviceIdValue1)).size()); | 134 | + linkService.getDeviceLinks(DID1).size()); |
| 138 | assertEquals("The link set size did not match.", 2, | 135 | assertEquals("The link set size did not match.", 2, |
| 139 | - linkService.getDeviceLinks(DeviceId.deviceId(deviceIdValue2)).size()); | 136 | + linkService.getDeviceLinks(DID2).size()); |
| 140 | assertEquals("The link set size did not match.", 0, | 137 | assertEquals("The link set size did not match.", 0, |
| 141 | - linkService.getDeviceLinks(DeviceId.deviceId(deviceIdValue3)).size()); | 138 | + linkService.getDeviceLinks(DID3).size()); |
| 142 | 139 | ||
| 143 | // test the getDeviceEgressLinks() method | 140 | // test the getDeviceEgressLinks() method |
| 144 | assertEquals("The link set size did not match.", 1, | 141 | assertEquals("The link set size did not match.", 1, |
| 145 | - linkService.getDeviceEgressLinks(DeviceId.deviceId(deviceIdValue1)).size()); | 142 | + linkService.getDeviceEgressLinks(DID1).size()); |
| 146 | assertEquals("The link set size did not match.", 1, | 143 | assertEquals("The link set size did not match.", 1, |
| 147 | - linkService.getDeviceEgressLinks(DeviceId.deviceId(deviceIdValue2)).size()); | 144 | + linkService.getDeviceEgressLinks(DID2).size()); |
| 148 | assertEquals("The link set size did not match.", 0, | 145 | assertEquals("The link set size did not match.", 0, |
| 149 | - linkService.getDeviceEgressLinks(DeviceId.deviceId(deviceIdValue3)).size()); | 146 | + linkService.getDeviceEgressLinks(DID3).size()); |
| 150 | 147 | ||
| 151 | // test the getDeviceIngressLinks() method | 148 | // test the getDeviceIngressLinks() method |
| 152 | assertEquals("The link set size did not match.", 1, | 149 | assertEquals("The link set size did not match.", 1, |
| 153 | - linkService.getDeviceIngressLinks(DeviceId.deviceId(deviceIdValue1)).size()); | 150 | + linkService.getDeviceIngressLinks(DID1).size()); |
| 154 | assertEquals("The link set size did not match.", 1, | 151 | assertEquals("The link set size did not match.", 1, |
| 155 | - linkService.getDeviceIngressLinks(DeviceId.deviceId(deviceIdValue2)).size()); | 152 | + linkService.getDeviceIngressLinks(DID2).size()); |
| 156 | assertEquals("The link set size did not match.", 0, | 153 | assertEquals("The link set size did not match.", 0, |
| 157 | - linkService.getDeviceIngressLinks(DeviceId.deviceId(deviceIdValue3)).size()); | 154 | + linkService.getDeviceIngressLinks(DID3).size()); |
| 158 | 155 | ||
| 159 | // test the getEgressLinks() method | 156 | // test the getEgressLinks() method |
| 160 | assertEquals("The link set size did not match.", 1, | 157 | assertEquals("The link set size did not match.", 1, |
| ... | @@ -182,9 +179,9 @@ public class VirtualNetworkLinkServiceTest { | ... | @@ -182,9 +179,9 @@ public class VirtualNetworkLinkServiceTest { |
| 182 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 179 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 183 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 180 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 184 | VirtualDevice srcVirtualDevice = | 181 | VirtualDevice srcVirtualDevice = |
| 185 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1)); | 182 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 186 | VirtualDevice dstVirtualDevice = | 183 | VirtualDevice dstVirtualDevice = |
| 187 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | 184 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 188 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | 185 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
| 189 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | 186 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); |
| 190 | manager.createVirtualLink(virtualNetwork.id(), src, dst); | 187 | manager.createVirtualLink(virtualNetwork.id(), src, dst); |
| ... | @@ -205,9 +202,9 @@ public class VirtualNetworkLinkServiceTest { | ... | @@ -205,9 +202,9 @@ public class VirtualNetworkLinkServiceTest { |
| 205 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | 202 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 206 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | 203 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 207 | VirtualDevice srcVirtualDevice = | 204 | VirtualDevice srcVirtualDevice = |
| 208 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue1)); | 205 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 209 | VirtualDevice dstVirtualDevice = | 206 | VirtualDevice dstVirtualDevice = |
| 210 | - manager.createVirtualDevice(virtualNetwork.id(), DeviceId.deviceId(deviceIdValue2)); | 207 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 211 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | 208 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
| 212 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | 209 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); |
| 213 | manager.createVirtualLink(virtualNetwork.id(), src, dst); | 210 | manager.createVirtualLink(virtualNetwork.id(), src, dst); | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.incubator.net.virtual.impl; | ||
| 18 | + | ||
| 19 | +import org.junit.After; | ||
| 20 | +import org.junit.Before; | ||
| 21 | +import org.junit.Test; | ||
| 22 | +import org.onlab.junit.TestUtils; | ||
| 23 | +import org.onosproject.common.event.impl.TestEventDispatcher; | ||
| 24 | +import org.onosproject.core.CoreService; | ||
| 25 | +import org.onosproject.core.CoreServiceAdapter; | ||
| 26 | +import org.onosproject.core.IdGenerator; | ||
| 27 | +import org.onosproject.incubator.net.virtual.NetworkId; | ||
| 28 | +import org.onosproject.incubator.net.virtual.TenantId; | ||
| 29 | +import org.onosproject.incubator.net.virtual.VirtualDevice; | ||
| 30 | +import org.onosproject.incubator.net.virtual.VirtualLink; | ||
| 31 | +import org.onosproject.incubator.net.virtual.VirtualNetwork; | ||
| 32 | +import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore; | ||
| 33 | +import org.onosproject.net.ConnectPoint; | ||
| 34 | +import org.onosproject.net.DeviceId; | ||
| 35 | +import org.onosproject.net.DisjointPath; | ||
| 36 | +import org.onosproject.net.Link; | ||
| 37 | +import org.onosproject.net.NetTestTools; | ||
| 38 | +import org.onosproject.net.Path; | ||
| 39 | +import org.onosproject.net.PortNumber; | ||
| 40 | +import org.onosproject.net.TestDeviceParams; | ||
| 41 | +import org.onosproject.net.topology.LinkWeight; | ||
| 42 | +import org.onosproject.net.topology.Topology; | ||
| 43 | +import org.onosproject.net.topology.TopologyCluster; | ||
| 44 | +import org.onosproject.net.topology.TopologyService; | ||
| 45 | +import org.onosproject.store.service.TestStorageService; | ||
| 46 | + | ||
| 47 | +import java.util.Map; | ||
| 48 | +import java.util.Optional; | ||
| 49 | +import java.util.Set; | ||
| 50 | +import java.util.concurrent.atomic.AtomicLong; | ||
| 51 | + | ||
| 52 | +import static junit.framework.TestCase.assertTrue; | ||
| 53 | +import static org.junit.Assert.*; | ||
| 54 | + | ||
| 55 | +/** | ||
| 56 | + * Junit tests for VirtualNetworkTopologyService. | ||
| 57 | + */ | ||
| 58 | +public class VirtualNetworkTopologyServiceTest extends TestDeviceParams { | ||
| 59 | + | ||
| 60 | + private final String tenantIdValue1 = "TENANT_ID1"; | ||
| 61 | + | ||
| 62 | + private VirtualNetworkManager manager; | ||
| 63 | + private DistributedVirtualNetworkStore virtualNetworkManagerStore; | ||
| 64 | + private CoreService coreService; | ||
| 65 | + | ||
| 66 | + @Before | ||
| 67 | + public void setUp() throws Exception { | ||
| 68 | + virtualNetworkManagerStore = new DistributedVirtualNetworkStore(); | ||
| 69 | + | ||
| 70 | + coreService = new VirtualNetworkTopologyServiceTest.TestCoreService(); | ||
| 71 | + virtualNetworkManagerStore.setCoreService(coreService); | ||
| 72 | + TestUtils.setField(coreService, "coreService", new VirtualNetworkTopologyServiceTest.TestCoreService()); | ||
| 73 | + TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService()); | ||
| 74 | + virtualNetworkManagerStore.activate(); | ||
| 75 | + | ||
| 76 | + manager = new VirtualNetworkManager(); | ||
| 77 | + manager.store = virtualNetworkManagerStore; | ||
| 78 | + NetTestTools.injectEventDispatcher(manager, new TestEventDispatcher()); | ||
| 79 | + manager.activate(); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @After | ||
| 83 | + public void tearDown() { | ||
| 84 | + virtualNetworkManagerStore.deactivate(); | ||
| 85 | + manager.deactivate(); | ||
| 86 | + NetTestTools.injectEventDispatcher(manager, null); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * Method to create the virtual network for further testing. | ||
| 91 | + * | ||
| 92 | + * @return virtual network | ||
| 93 | + */ | ||
| 94 | + private VirtualNetwork setupVirtualNetworkTopology() { | ||
| 95 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
| 96 | + VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
| 97 | + VirtualDevice virtualDevice1 = | ||
| 98 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); | ||
| 99 | + VirtualDevice virtualDevice2 = | ||
| 100 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); | ||
| 101 | + VirtualDevice virtualDevice3 = | ||
| 102 | + manager.createVirtualDevice(virtualNetwork.id(), DID3); | ||
| 103 | + VirtualDevice virtualDevice4 = | ||
| 104 | + manager.createVirtualDevice(virtualNetwork.id(), DID4); | ||
| 105 | + | ||
| 106 | + ConnectPoint cp1 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1)); | ||
| 107 | + ConnectPoint cp2 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(2)); | ||
| 108 | + ConnectPoint cp3 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(3)); | ||
| 109 | + ConnectPoint cp4 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(4)); | ||
| 110 | + ConnectPoint cp5 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(5)); | ||
| 111 | + ConnectPoint cp6 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(6)); | ||
| 112 | + VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3); | ||
| 113 | + virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE); | ||
| 114 | + VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1); | ||
| 115 | + virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE); | ||
| 116 | + VirtualLink link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5); | ||
| 117 | + virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE); | ||
| 118 | + VirtualLink link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4); | ||
| 119 | + virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE); | ||
| 120 | + VirtualLink link5 = manager.createVirtualLink(virtualNetwork.id(), cp2, cp6); | ||
| 121 | + virtualNetworkManagerStore.updateLink(link5, link5.tunnelId(), Link.State.ACTIVE); | ||
| 122 | + VirtualLink link6 = manager.createVirtualLink(virtualNetwork.id(), cp6, cp2); | ||
| 123 | + virtualNetworkManagerStore.updateLink(link6, link6.tunnelId(), Link.State.ACTIVE); | ||
| 124 | + | ||
| 125 | + return virtualNetwork; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * Tests the currentTopology() method. | ||
| 130 | + */ | ||
| 131 | + @Test | ||
| 132 | + public void testCurrentTopology() { | ||
| 133 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 134 | + | ||
| 135 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 136 | + Topology topology = topologyService.currentTopology(); | ||
| 137 | + assertNotNull("The topology should not be null.", topology); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * Test isLatest() method using a null topology. | ||
| 142 | + */ | ||
| 143 | + @Test(expected = NullPointerException.class) | ||
| 144 | + public void testIsLatestByNullTopology() { | ||
| 145 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
| 146 | + VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
| 147 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 148 | + | ||
| 149 | + // test the isLatest() method with a null topology. | ||
| 150 | + topologyService.isLatest(null); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + /** | ||
| 154 | + * Test isLatest() method. | ||
| 155 | + */ | ||
| 156 | + @Test | ||
| 157 | + public void testIsLatest() { | ||
| 158 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
| 159 | + VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
| 160 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 161 | + Topology topology = topologyService.currentTopology(); | ||
| 162 | + | ||
| 163 | + // test the isLatest() method. | ||
| 164 | + assertTrue("This should be latest topology", topologyService.isLatest(topology)); | ||
| 165 | + | ||
| 166 | + VirtualDevice srcVirtualDevice = | ||
| 167 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); | ||
| 168 | + VirtualDevice dstVirtualDevice = | ||
| 169 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); | ||
| 170 | + | ||
| 171 | + // test the isLatest() method where a new device has been added to the current topology. | ||
| 172 | + assertFalse("This should not be latest topology", topologyService.isLatest(topology)); | ||
| 173 | + | ||
| 174 | + topology = topologyService.currentTopology(); | ||
| 175 | + ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | ||
| 176 | + ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | ||
| 177 | + VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst); | ||
| 178 | + | ||
| 179 | + // test the isLatest() method where a new link has been added to the current topology. | ||
| 180 | + assertFalse("This should not be latest topology", topologyService.isLatest(topology)); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * Test getGraph() method. | ||
| 185 | + */ | ||
| 186 | + @Test | ||
| 187 | + public void testGetGraph() { | ||
| 188 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
| 189 | + VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
| 190 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 191 | + Topology topology = topologyService.currentTopology(); | ||
| 192 | + | ||
| 193 | + // test the getGraph() method. | ||
| 194 | + assertNotNull("The graph should not be null.", topologyService.getGraph(topology)); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 198 | + * Test getClusters() method. | ||
| 199 | + */ | ||
| 200 | + @Test | ||
| 201 | + public void testGetClusters() { | ||
| 202 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 203 | + | ||
| 204 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 205 | + | ||
| 206 | + Topology topology = topologyService.currentTopology(); | ||
| 207 | + | ||
| 208 | + // test the getClusters() method. | ||
| 209 | + assertNotNull("The clusters should not be null.", topologyService.getClusters(topology)); | ||
| 210 | + assertEquals("The clusters size did not match.", 2, topologyService.getClusters(topology).size()); | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /** | ||
| 214 | + * Test getCluster() method using a null cluster identifier. | ||
| 215 | + */ | ||
| 216 | + @Test(expected = NullPointerException.class) | ||
| 217 | + public void testGetClusterUsingNullClusterId() { | ||
| 218 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 219 | + | ||
| 220 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 221 | + Topology topology = topologyService.currentTopology(); | ||
| 222 | + | ||
| 223 | + Set<TopologyCluster> clusters = topologyService.getClusters(topology); | ||
| 224 | + TopologyCluster cluster = clusters.stream().findFirst().get(); | ||
| 225 | + | ||
| 226 | + // test the getCluster() method with a null cluster identifier | ||
| 227 | + TopologyCluster cluster1 = topologyService.getCluster(topology, null); | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + /** | ||
| 231 | + * Test getCluster() method. | ||
| 232 | + */ | ||
| 233 | + @Test | ||
| 234 | + public void testGetCluster() { | ||
| 235 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 236 | + | ||
| 237 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 238 | + Topology topology = topologyService.currentTopology(); | ||
| 239 | + | ||
| 240 | + Set<TopologyCluster> clusters = topologyService.getClusters(topology); | ||
| 241 | + assertNotNull("The clusters should not be null.", clusters); | ||
| 242 | + assertEquals("The clusters size did not match.", 2, clusters.size()); | ||
| 243 | + | ||
| 244 | + // test the getCluster() method. | ||
| 245 | + TopologyCluster cluster = clusters.stream().findFirst().get(); | ||
| 246 | + assertNotNull("The cluster should not be null.", cluster); | ||
| 247 | + TopologyCluster cluster1 = topologyService.getCluster(topology, cluster.id()); | ||
| 248 | + assertNotNull("The cluster should not be null.", cluster1); | ||
| 249 | + assertEquals("The cluster ID did not match.", cluster.id(), cluster1.id()); | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + /** | ||
| 253 | + * Test getClusterDevices() methods with a null cluster. | ||
| 254 | + */ | ||
| 255 | + @Test(expected = NullPointerException.class) | ||
| 256 | + public void testGetClusterDevicesUsingNullCluster() { | ||
| 257 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 258 | + | ||
| 259 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 260 | + Topology topology = topologyService.currentTopology(); | ||
| 261 | + Set<TopologyCluster> clusters = topologyService.getClusters(topology); | ||
| 262 | + | ||
| 263 | + // test the getClusterDevices() method using a null cluster. | ||
| 264 | + Object[] objects = clusters.stream().toArray(); | ||
| 265 | + assertNotNull("The cluster should not be null.", objects); | ||
| 266 | + Set<DeviceId> clusterDevices = topologyService.getClusterDevices(topology, null); | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + /** | ||
| 270 | + * Test getClusterLinks() methods with a null cluster. | ||
| 271 | + */ | ||
| 272 | + @Test(expected = NullPointerException.class) | ||
| 273 | + public void testGetClusterLinksUsingNullCluster() { | ||
| 274 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 275 | + | ||
| 276 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 277 | + Topology topology = topologyService.currentTopology(); | ||
| 278 | + Set<TopologyCluster> clusters = topologyService.getClusters(topology); | ||
| 279 | + | ||
| 280 | + // test the getClusterLinks() method using a null cluster. | ||
| 281 | + Object[] objects = clusters.stream().toArray(); | ||
| 282 | + assertNotNull("The cluster should not be null.", objects); | ||
| 283 | + Set<Link> clusterLinks = topologyService.getClusterLinks(topology, null); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + /** | ||
| 287 | + * Test getClusterDevices() and getClusterLinks() methods. | ||
| 288 | + */ | ||
| 289 | + @Test | ||
| 290 | + public void testGetClusterDevicesLinks() { | ||
| 291 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 292 | + | ||
| 293 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 294 | + Topology topology = topologyService.currentTopology(); | ||
| 295 | + | ||
| 296 | + Set<TopologyCluster> clusters = topologyService.getClusters(topology); | ||
| 297 | + assertNotNull("The clusters should not be null.", clusters); | ||
| 298 | + assertEquals("The clusters size did not match.", 2, clusters.size()); | ||
| 299 | + | ||
| 300 | + // test the getClusterDevices() method. | ||
| 301 | + Object[] objects = clusters.stream().toArray(); | ||
| 302 | + assertNotNull("The cluster should not be null.", objects); | ||
| 303 | + Set<DeviceId> clusterDevices = topologyService.getClusterDevices(topology, (TopologyCluster) objects[0]); | ||
| 304 | + assertNotNull("The devices should not be null.", clusterDevices); | ||
| 305 | + assertEquals("The devices size did not match.", 3, clusterDevices.size()); | ||
| 306 | + Set<DeviceId> clusterDevices1 = topologyService.getClusterDevices(topology, (TopologyCluster) objects[1]); | ||
| 307 | + assertNotNull("The devices should not be null.", clusterDevices1); | ||
| 308 | + assertEquals("The devices size did not match.", 1, clusterDevices1.size()); | ||
| 309 | + | ||
| 310 | + // test the getClusterLinks() method. | ||
| 311 | + Set<Link> clusterLinks = topologyService.getClusterLinks(topology, (TopologyCluster) objects[0]); | ||
| 312 | + assertNotNull("The links should not be null.", clusterLinks); | ||
| 313 | + assertEquals("The links size did not match.", 6, clusterLinks.size()); | ||
| 314 | + Set<Link> clusterLinks1 = topologyService.getClusterLinks(topology, (TopologyCluster) objects[1]); | ||
| 315 | + assertNotNull("The links should not be null.", clusterLinks1); | ||
| 316 | + assertEquals("The links size did not match.", 0, clusterLinks1.size()); | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + /** | ||
| 320 | + * Test getPaths() method using a null src device identifier. | ||
| 321 | + */ | ||
| 322 | + @Test(expected = NullPointerException.class) | ||
| 323 | + public void testGetPathsUsingNullSrcDeviceId() { | ||
| 324 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 325 | + | ||
| 326 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 327 | + Topology topology = topologyService.currentTopology(); | ||
| 328 | + | ||
| 329 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 330 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 331 | + | ||
| 332 | + // test the getPaths() method using a null src device identifier. | ||
| 333 | + Set<Path> paths = topologyService.getPaths(topology, null, dstVirtualDevice.id()); | ||
| 334 | + } | ||
| 335 | + | ||
| 336 | + /** | ||
| 337 | + * Test getPaths() method using a null dst device identifier. | ||
| 338 | + */ | ||
| 339 | + @Test(expected = NullPointerException.class) | ||
| 340 | + public void testGetPathsUsingNullDstDeviceId() { | ||
| 341 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 342 | + | ||
| 343 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 344 | + Topology topology = topologyService.currentTopology(); | ||
| 345 | + | ||
| 346 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 347 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 348 | + | ||
| 349 | + // test the getPaths() method using a null dst device identifier. | ||
| 350 | + Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), null); | ||
| 351 | + } | ||
| 352 | + | ||
| 353 | + /** | ||
| 354 | + * Test getPaths() method using a null weight. | ||
| 355 | + */ | ||
| 356 | + @Test(expected = NullPointerException.class) | ||
| 357 | + public void testGetPathsUsingNullWeight() { | ||
| 358 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 359 | + | ||
| 360 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 361 | + Topology topology = topologyService.currentTopology(); | ||
| 362 | + | ||
| 363 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 364 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 365 | + | ||
| 366 | + // test the getPaths() method using a null weight. | ||
| 367 | + Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id(), null); | ||
| 368 | + } | ||
| 369 | + | ||
| 370 | + /** | ||
| 371 | + * Test getPaths() and getPaths() by weight methods. | ||
| 372 | + */ | ||
| 373 | + @Test | ||
| 374 | + public void testGetPaths() { | ||
| 375 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 376 | + | ||
| 377 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 378 | + Topology topology = topologyService.currentTopology(); | ||
| 379 | + | ||
| 380 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 381 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 382 | + | ||
| 383 | + // test the getPaths() method. | ||
| 384 | + Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id()); | ||
| 385 | + assertNotNull("The paths should not be null.", paths); | ||
| 386 | + assertEquals("The paths size did not match.", 1, paths.size()); | ||
| 387 | + | ||
| 388 | + // test the getPaths() by weight method. | ||
| 389 | + LinkWeight weight = edge -> 1.0; | ||
| 390 | + Set<Path> paths1 = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id(), weight); | ||
| 391 | + assertNotNull("The paths should not be null.", paths1); | ||
| 392 | + assertEquals("The paths size did not match.", 1, paths1.size()); | ||
| 393 | + Path path = paths1.iterator().next(); | ||
| 394 | + assertEquals("wrong path length", 1, path.links().size()); | ||
| 395 | + assertEquals("wrong path cost", 1.0, path.cost(), 0.01); | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + /** | ||
| 399 | + * Test getDisjointPaths() methods using a null src device identifier. | ||
| 400 | + */ | ||
| 401 | + @Test(expected = NullPointerException.class) | ||
| 402 | + public void testGetDisjointPathsUsingNullSrcDeviceId() { | ||
| 403 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 404 | + | ||
| 405 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 406 | + Topology topology = topologyService.currentTopology(); | ||
| 407 | + | ||
| 408 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 409 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 410 | + | ||
| 411 | + // test the getDisjointPaths() method using a null src device identifier. | ||
| 412 | + Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, null, dstVirtualDevice.id()); | ||
| 413 | + } | ||
| 414 | + | ||
| 415 | + /** | ||
| 416 | + * Test getDisjointPaths() methods using a null dst device identifier. | ||
| 417 | + */ | ||
| 418 | + @Test(expected = NullPointerException.class) | ||
| 419 | + public void testGetDisjointPathsUsingNullDstDeviceId() { | ||
| 420 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 421 | + | ||
| 422 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 423 | + Topology topology = topologyService.currentTopology(); | ||
| 424 | + | ||
| 425 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 426 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 427 | + | ||
| 428 | + // test the getDisjointPaths() method using a null dst device identifier. | ||
| 429 | + Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), null); | ||
| 430 | + } | ||
| 431 | + | ||
| 432 | + /** | ||
| 433 | + * Test getDisjointPaths() methods using a null weight. | ||
| 434 | + */ | ||
| 435 | + @Test(expected = NullPointerException.class) | ||
| 436 | + public void testGetDisjointPathsUsingNullWeight() { | ||
| 437 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 438 | + | ||
| 439 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 440 | + Topology topology = topologyService.currentTopology(); | ||
| 441 | + | ||
| 442 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 443 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 444 | + | ||
| 445 | + // test the getDisjointPaths() method using a null weight. | ||
| 446 | + Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), | ||
| 447 | + dstVirtualDevice.id(), (LinkWeight) null); | ||
| 448 | + } | ||
| 449 | + | ||
| 450 | + /** | ||
| 451 | + * Test getDisjointPaths() methods using a null risk profile. | ||
| 452 | + */ | ||
| 453 | + @Test(expected = NullPointerException.class) | ||
| 454 | + public void testGetDisjointPathsUsingNullRiskProfile() { | ||
| 455 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 456 | + | ||
| 457 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 458 | + Topology topology = topologyService.currentTopology(); | ||
| 459 | + | ||
| 460 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 461 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 462 | + | ||
| 463 | + // test the getDisjointPaths() method using a null risk profile. | ||
| 464 | + Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), | ||
| 465 | + dstVirtualDevice.id(), (Map<Link, Object>) null); | ||
| 466 | + } | ||
| 467 | + | ||
| 468 | + /** | ||
| 469 | + * Test getDisjointPaths() methods. | ||
| 470 | + */ | ||
| 471 | + @Test | ||
| 472 | + public void testGetDisjointPaths() { | ||
| 473 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 474 | + | ||
| 475 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 476 | + Topology topology = topologyService.currentTopology(); | ||
| 477 | + | ||
| 478 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 479 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); | ||
| 480 | + | ||
| 481 | + // test the getDisjointPaths() method. | ||
| 482 | + Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), | ||
| 483 | + dstVirtualDevice.id()); | ||
| 484 | + assertNotNull("The paths should not be null.", paths); | ||
| 485 | + assertEquals("The paths size did not match.", 1, paths.size()); | ||
| 486 | + | ||
| 487 | + // test the getDisjointPaths() method using a weight. | ||
| 488 | + LinkWeight weight = edge -> 1.0; | ||
| 489 | + Set<DisjointPath> paths1 = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), | ||
| 490 | + dstVirtualDevice.id(), weight); | ||
| 491 | + assertNotNull("The paths should not be null.", paths1); | ||
| 492 | + assertEquals("The paths size did not match.", 1, paths1.size()); | ||
| 493 | + } | ||
| 494 | + | ||
| 495 | + /** | ||
| 496 | + * Test isInfrastructure() method using a null connect point. | ||
| 497 | + */ | ||
| 498 | + @Test(expected = NullPointerException.class) | ||
| 499 | + public void testIsInfrastructureUsingNullConnectPoint() { | ||
| 500 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 501 | + | ||
| 502 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 503 | + Topology topology = topologyService.currentTopology(); | ||
| 504 | + | ||
| 505 | + // test the isInfrastructure() method using a null connect point. | ||
| 506 | + Boolean isInfrastructure = topologyService.isInfrastructure(topology, null); | ||
| 507 | + } | ||
| 508 | + | ||
| 509 | + /** | ||
| 510 | + * Test isInfrastructure() method. | ||
| 511 | + */ | ||
| 512 | + @Test | ||
| 513 | + public void testIsInfrastructure() { | ||
| 514 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 515 | + | ||
| 516 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 517 | + Topology topology = topologyService.currentTopology(); | ||
| 518 | + | ||
| 519 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 520 | + VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID4); | ||
| 521 | + ConnectPoint cp1 = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | ||
| 522 | + ConnectPoint cp2 = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | ||
| 523 | + | ||
| 524 | + // test the isInfrastructure() method. | ||
| 525 | + Boolean isInfrastructure = topologyService.isInfrastructure(topology, cp1); | ||
| 526 | + assertTrue("The connect point should be infrastructure.", isInfrastructure); | ||
| 527 | + | ||
| 528 | + isInfrastructure = topologyService.isInfrastructure(topology, cp2); | ||
| 529 | + assertFalse("The connect point should not be infrastructure.", isInfrastructure); | ||
| 530 | + } | ||
| 531 | + | ||
| 532 | + /** | ||
| 533 | + * Test isBroadcastPoint() method using a null connect point. | ||
| 534 | + */ | ||
| 535 | + @Test(expected = NullPointerException.class) | ||
| 536 | + public void testIsBroadcastUsingNullConnectPoint() { | ||
| 537 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 538 | + | ||
| 539 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 540 | + Topology topology = topologyService.currentTopology(); | ||
| 541 | + | ||
| 542 | + // test the isInfrastructure() method using a null connect point. | ||
| 543 | + Boolean isInfrastructure = topologyService.isBroadcastPoint(topology, null); | ||
| 544 | + } | ||
| 545 | + | ||
| 546 | + /** | ||
| 547 | + * Test isBroadcastPoint() method. | ||
| 548 | + */ | ||
| 549 | + @Test | ||
| 550 | + public void testIsBroadcastPoint() { | ||
| 551 | + VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); | ||
| 552 | + | ||
| 553 | + TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); | ||
| 554 | + Topology topology = topologyService.currentTopology(); | ||
| 555 | + | ||
| 556 | + VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); | ||
| 557 | + ConnectPoint cp = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | ||
| 558 | + | ||
| 559 | + // test the isBroadcastPoint() method. | ||
| 560 | + Boolean isBroadcastPoint = topologyService.isBroadcastPoint(topology, cp); | ||
| 561 | + assertTrue("The connect point should be a broadcast point.", isBroadcastPoint); | ||
| 562 | + } | ||
| 563 | + | ||
| 564 | + /** | ||
| 565 | + * Return the virtual device matching the device identifier. | ||
| 566 | + * | ||
| 567 | + * @param networkId virtual network identifier | ||
| 568 | + * @param deviceId device identifier | ||
| 569 | + * @return virtual device | ||
| 570 | + */ | ||
| 571 | + private VirtualDevice getVirtualDevice(NetworkId networkId, DeviceId deviceId) { | ||
| 572 | + Optional<VirtualDevice> foundDevice = manager.getVirtualDevices(networkId) | ||
| 573 | + .stream() | ||
| 574 | + .filter(device -> deviceId.equals(device.id())) | ||
| 575 | + .findFirst(); | ||
| 576 | + if (foundDevice.isPresent()) { | ||
| 577 | + return foundDevice.get(); | ||
| 578 | + } | ||
| 579 | + return null; | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + /** | ||
| 583 | + * Core service test class. | ||
| 584 | + */ | ||
| 585 | + private class TestCoreService extends CoreServiceAdapter { | ||
| 586 | + | ||
| 587 | + @Override | ||
| 588 | + public IdGenerator getIdGenerator(String topic) { | ||
| 589 | + return new IdGenerator() { | ||
| 590 | + private AtomicLong counter = new AtomicLong(0); | ||
| 591 | + | ||
| 592 | + @Override | ||
| 593 | + public long getNewId() { | ||
| 594 | + return counter.getAndIncrement(); | ||
| 595 | + } | ||
| 596 | + }; | ||
| 597 | + } | ||
| 598 | + } | ||
| 599 | +} |
-
Please register or login to post a comment