Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 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; |
Ray Milkey | cc00124 | 2018-09-18 14:55:59 -0700 | [diff] [blame] | 22 | import org.onlab.graph.ScalarWeight; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 23 | import org.onlab.junit.TestUtils; |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 24 | import org.onlab.osgi.TestServiceDirectory; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 25 | import org.onosproject.common.event.impl.TestEventDispatcher; |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 26 | import org.onosproject.core.ApplicationId; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 27 | import org.onosproject.core.CoreService; |
| 28 | import org.onosproject.core.CoreServiceAdapter; |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 29 | import org.onosproject.core.DefaultApplicationId; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 30 | import org.onosproject.core.IdGenerator; |
| 31 | import org.onosproject.incubator.net.virtual.NetworkId; |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame^] | 32 | import org.onosproject.net.TenantId; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 33 | import org.onosproject.incubator.net.virtual.VirtualDevice; |
| 34 | import org.onosproject.incubator.net.virtual.VirtualLink; |
| 35 | import org.onosproject.incubator.net.virtual.VirtualNetwork; |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame^] | 36 | import org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.DeviceId; |
| 39 | import org.onosproject.net.DisjointPath; |
| 40 | import org.onosproject.net.Link; |
| 41 | import org.onosproject.net.NetTestTools; |
| 42 | import org.onosproject.net.Path; |
| 43 | import org.onosproject.net.PortNumber; |
| 44 | import org.onosproject.net.TestDeviceParams; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 45 | import org.onosproject.net.topology.LinkWeigher; |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 46 | import org.onosproject.net.topology.LinkWeigherAdapter; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 47 | import org.onosproject.net.topology.Topology; |
| 48 | import org.onosproject.net.topology.TopologyCluster; |
| 49 | import org.onosproject.net.topology.TopologyService; |
| 50 | import org.onosproject.store.service.TestStorageService; |
| 51 | |
| 52 | import java.util.Map; |
| 53 | import java.util.Optional; |
| 54 | import java.util.Set; |
| 55 | import java.util.concurrent.atomic.AtomicLong; |
| 56 | |
| 57 | import static junit.framework.TestCase.assertTrue; |
Ray Milkey | 094a135 | 2018-01-22 14:03:54 -0800 | [diff] [blame] | 58 | import static org.junit.Assert.assertEquals; |
| 59 | import static org.junit.Assert.assertFalse; |
| 60 | import static org.junit.Assert.assertNotNull; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Junit tests for VirtualNetworkTopologyService. |
| 64 | */ |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 65 | public class VirtualNetworkTopologyManagerTest extends TestDeviceParams { |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 66 | |
| 67 | private final String tenantIdValue1 = "TENANT_ID1"; |
| 68 | |
| 69 | private VirtualNetworkManager manager; |
| 70 | private DistributedVirtualNetworkStore virtualNetworkManagerStore; |
| 71 | private CoreService coreService; |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 72 | private TestServiceDirectory testDirectory; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 73 | |
| 74 | @Before |
| 75 | public void setUp() throws Exception { |
| 76 | virtualNetworkManagerStore = new DistributedVirtualNetworkStore(); |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 77 | coreService = new VirtualNetworkTopologyManagerTest.TestCoreService(); |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 78 | TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 79 | TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService()); |
| 80 | virtualNetworkManagerStore.activate(); |
| 81 | |
| 82 | manager = new VirtualNetworkManager(); |
| 83 | manager.store = virtualNetworkManagerStore; |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 84 | manager.coreService = coreService; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 85 | NetTestTools.injectEventDispatcher(manager, new TestEventDispatcher()); |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 86 | |
| 87 | testDirectory = new TestServiceDirectory(); |
| 88 | TestUtils.setField(manager, "serviceDirectory", testDirectory); |
| 89 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 90 | manager.activate(); |
| 91 | } |
| 92 | |
| 93 | @After |
| 94 | public void tearDown() { |
| 95 | virtualNetworkManagerStore.deactivate(); |
| 96 | manager.deactivate(); |
| 97 | NetTestTools.injectEventDispatcher(manager, null); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Method to create the virtual network for further testing. |
| 102 | * |
| 103 | * @return virtual network |
| 104 | */ |
| 105 | private VirtualNetwork setupVirtualNetworkTopology() { |
| 106 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 107 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 108 | VirtualDevice virtualDevice1 = |
| 109 | manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 110 | VirtualDevice virtualDevice2 = |
| 111 | manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 112 | VirtualDevice virtualDevice3 = |
| 113 | manager.createVirtualDevice(virtualNetwork.id(), DID3); |
| 114 | VirtualDevice virtualDevice4 = |
| 115 | manager.createVirtualDevice(virtualNetwork.id(), DID4); |
| 116 | |
| 117 | ConnectPoint cp1 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(1)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 118 | manager.createVirtualPort(virtualNetwork.id(), cp1.deviceId(), cp1.port(), cp1); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 119 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 120 | ConnectPoint cp2 = new ConnectPoint(virtualDevice1.id(), PortNumber.portNumber(2)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 121 | manager.createVirtualPort(virtualNetwork.id(), cp2.deviceId(), cp2.port(), cp2); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 122 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 123 | ConnectPoint cp3 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(3)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 124 | manager.createVirtualPort(virtualNetwork.id(), cp3.deviceId(), cp3.port(), cp3); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 125 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 126 | ConnectPoint cp4 = new ConnectPoint(virtualDevice2.id(), PortNumber.portNumber(4)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 127 | manager.createVirtualPort(virtualNetwork.id(), cp4.deviceId(), cp4.port(), cp4); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 128 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 129 | ConnectPoint cp5 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(5)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 130 | manager.createVirtualPort(virtualNetwork.id(), cp5.deviceId(), cp5.port(), cp5); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 131 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 132 | ConnectPoint cp6 = new ConnectPoint(virtualDevice3.id(), PortNumber.portNumber(6)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 133 | manager.createVirtualPort(virtualNetwork.id(), cp6.deviceId(), cp6.port(), cp6); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 134 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 135 | VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3); |
| 136 | virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE); |
| 137 | VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1); |
| 138 | virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE); |
| 139 | VirtualLink link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5); |
| 140 | virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE); |
| 141 | VirtualLink link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4); |
| 142 | virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE); |
| 143 | VirtualLink link5 = manager.createVirtualLink(virtualNetwork.id(), cp2, cp6); |
| 144 | virtualNetworkManagerStore.updateLink(link5, link5.tunnelId(), Link.State.ACTIVE); |
| 145 | VirtualLink link6 = manager.createVirtualLink(virtualNetwork.id(), cp6, cp2); |
| 146 | virtualNetworkManagerStore.updateLink(link6, link6.tunnelId(), Link.State.ACTIVE); |
| 147 | |
| 148 | return virtualNetwork; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Tests the currentTopology() method. |
| 153 | */ |
| 154 | @Test |
| 155 | public void testCurrentTopology() { |
| 156 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 157 | |
| 158 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 159 | Topology topology = topologyService.currentTopology(); |
| 160 | assertNotNull("The topology should not be null.", topology); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Test isLatest() method using a null topology. |
| 165 | */ |
| 166 | @Test(expected = NullPointerException.class) |
| 167 | public void testIsLatestByNullTopology() { |
| 168 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 169 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 170 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 171 | |
| 172 | // test the isLatest() method with a null topology. |
| 173 | topologyService.isLatest(null); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Test isLatest() method. |
| 178 | */ |
| 179 | @Test |
| 180 | public void testIsLatest() { |
| 181 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 182 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 183 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 184 | Topology topology = topologyService.currentTopology(); |
| 185 | |
| 186 | // test the isLatest() method. |
| 187 | assertTrue("This should be latest topology", topologyService.isLatest(topology)); |
| 188 | |
| 189 | VirtualDevice srcVirtualDevice = |
| 190 | manager.createVirtualDevice(virtualNetwork.id(), DID1); |
| 191 | VirtualDevice dstVirtualDevice = |
| 192 | manager.createVirtualDevice(virtualNetwork.id(), DID2); |
| 193 | |
| 194 | // test the isLatest() method where a new device has been added to the current topology. |
| 195 | assertFalse("This should not be latest topology", topologyService.isLatest(topology)); |
| 196 | |
| 197 | topology = topologyService.currentTopology(); |
| 198 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 199 | manager.createVirtualPort(virtualNetwork.id(), src.deviceId(), src.port(), |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 200 | new ConnectPoint(srcVirtualDevice.id(), src.port())); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 201 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 202 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 203 | manager.createVirtualPort(virtualNetwork.id(), dst.deviceId(), dst.port(), |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 204 | new ConnectPoint(dstVirtualDevice.id(), dst.port())); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 205 | VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst); |
| 206 | |
| 207 | // test the isLatest() method where a new link has been added to the current topology. |
| 208 | assertFalse("This should not be latest topology", topologyService.isLatest(topology)); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Test getGraph() method. |
| 213 | */ |
| 214 | @Test |
| 215 | public void testGetGraph() { |
| 216 | manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); |
| 217 | VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); |
| 218 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 219 | Topology topology = topologyService.currentTopology(); |
| 220 | |
| 221 | // test the getGraph() method. |
| 222 | assertNotNull("The graph should not be null.", topologyService.getGraph(topology)); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Test getClusters() method. |
| 227 | */ |
| 228 | @Test |
| 229 | public void testGetClusters() { |
| 230 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 231 | |
| 232 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 233 | |
| 234 | Topology topology = topologyService.currentTopology(); |
| 235 | |
| 236 | // test the getClusters() method. |
| 237 | assertNotNull("The clusters should not be null.", topologyService.getClusters(topology)); |
| 238 | assertEquals("The clusters size did not match.", 2, topologyService.getClusters(topology).size()); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Test getCluster() method using a null cluster identifier. |
| 243 | */ |
| 244 | @Test(expected = NullPointerException.class) |
| 245 | public void testGetClusterUsingNullClusterId() { |
| 246 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 247 | |
| 248 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 249 | Topology topology = topologyService.currentTopology(); |
| 250 | |
| 251 | Set<TopologyCluster> clusters = topologyService.getClusters(topology); |
| 252 | TopologyCluster cluster = clusters.stream().findFirst().get(); |
| 253 | |
| 254 | // test the getCluster() method with a null cluster identifier |
| 255 | TopologyCluster cluster1 = topologyService.getCluster(topology, null); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Test getCluster() method. |
| 260 | */ |
| 261 | @Test |
| 262 | public void testGetCluster() { |
| 263 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 264 | |
| 265 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 266 | Topology topology = topologyService.currentTopology(); |
| 267 | |
| 268 | Set<TopologyCluster> clusters = topologyService.getClusters(topology); |
| 269 | assertNotNull("The clusters should not be null.", clusters); |
| 270 | assertEquals("The clusters size did not match.", 2, clusters.size()); |
| 271 | |
| 272 | // test the getCluster() method. |
| 273 | TopologyCluster cluster = clusters.stream().findFirst().get(); |
| 274 | assertNotNull("The cluster should not be null.", cluster); |
| 275 | TopologyCluster cluster1 = topologyService.getCluster(topology, cluster.id()); |
| 276 | assertNotNull("The cluster should not be null.", cluster1); |
| 277 | assertEquals("The cluster ID did not match.", cluster.id(), cluster1.id()); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Test getClusterDevices() methods with a null cluster. |
| 282 | */ |
| 283 | @Test(expected = NullPointerException.class) |
| 284 | public void testGetClusterDevicesUsingNullCluster() { |
| 285 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 286 | |
| 287 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 288 | Topology topology = topologyService.currentTopology(); |
| 289 | Set<TopologyCluster> clusters = topologyService.getClusters(topology); |
| 290 | |
| 291 | // test the getClusterDevices() method using a null cluster. |
| 292 | Object[] objects = clusters.stream().toArray(); |
| 293 | assertNotNull("The cluster should not be null.", objects); |
| 294 | Set<DeviceId> clusterDevices = topologyService.getClusterDevices(topology, null); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Test getClusterLinks() methods with a null cluster. |
| 299 | */ |
| 300 | @Test(expected = NullPointerException.class) |
| 301 | public void testGetClusterLinksUsingNullCluster() { |
| 302 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 303 | |
| 304 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 305 | Topology topology = topologyService.currentTopology(); |
| 306 | Set<TopologyCluster> clusters = topologyService.getClusters(topology); |
| 307 | |
| 308 | // test the getClusterLinks() method using a null cluster. |
| 309 | Object[] objects = clusters.stream().toArray(); |
| 310 | assertNotNull("The cluster should not be null.", objects); |
| 311 | Set<Link> clusterLinks = topologyService.getClusterLinks(topology, null); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Test getClusterDevices() and getClusterLinks() methods. |
| 316 | */ |
| 317 | @Test |
| 318 | public void testGetClusterDevicesLinks() { |
| 319 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 320 | |
| 321 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 322 | Topology topology = topologyService.currentTopology(); |
| 323 | |
| 324 | Set<TopologyCluster> clusters = topologyService.getClusters(topology); |
| 325 | assertNotNull("The clusters should not be null.", clusters); |
| 326 | assertEquals("The clusters size did not match.", 2, clusters.size()); |
| 327 | |
| 328 | // test the getClusterDevices() method. |
| 329 | Object[] objects = clusters.stream().toArray(); |
| 330 | assertNotNull("The cluster should not be null.", objects); |
| 331 | Set<DeviceId> clusterDevices = topologyService.getClusterDevices(topology, (TopologyCluster) objects[0]); |
| 332 | assertNotNull("The devices should not be null.", clusterDevices); |
| 333 | assertEquals("The devices size did not match.", 3, clusterDevices.size()); |
| 334 | Set<DeviceId> clusterDevices1 = topologyService.getClusterDevices(topology, (TopologyCluster) objects[1]); |
| 335 | assertNotNull("The devices should not be null.", clusterDevices1); |
| 336 | assertEquals("The devices size did not match.", 1, clusterDevices1.size()); |
| 337 | |
| 338 | // test the getClusterLinks() method. |
| 339 | Set<Link> clusterLinks = topologyService.getClusterLinks(topology, (TopologyCluster) objects[0]); |
| 340 | assertNotNull("The links should not be null.", clusterLinks); |
| 341 | assertEquals("The links size did not match.", 6, clusterLinks.size()); |
| 342 | Set<Link> clusterLinks1 = topologyService.getClusterLinks(topology, (TopologyCluster) objects[1]); |
| 343 | assertNotNull("The links should not be null.", clusterLinks1); |
| 344 | assertEquals("The links size did not match.", 0, clusterLinks1.size()); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Test getPaths() method using a null src device identifier. |
| 349 | */ |
| 350 | @Test(expected = NullPointerException.class) |
| 351 | public void testGetPathsUsingNullSrcDeviceId() { |
| 352 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 353 | |
| 354 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 355 | Topology topology = topologyService.currentTopology(); |
| 356 | |
| 357 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 358 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 359 | |
| 360 | // test the getPaths() method using a null src device identifier. |
| 361 | Set<Path> paths = topologyService.getPaths(topology, null, dstVirtualDevice.id()); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Test getPaths() method using a null dst device identifier. |
| 366 | */ |
| 367 | @Test(expected = NullPointerException.class) |
| 368 | public void testGetPathsUsingNullDstDeviceId() { |
| 369 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 370 | |
| 371 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 372 | Topology topology = topologyService.currentTopology(); |
| 373 | |
| 374 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 375 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 376 | |
| 377 | // test the getPaths() method using a null dst device identifier. |
| 378 | Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), null); |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Test getPaths() method using a null weight. |
| 383 | */ |
| 384 | @Test(expected = NullPointerException.class) |
| 385 | public void testGetPathsUsingNullWeight() { |
| 386 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 387 | |
| 388 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 389 | Topology topology = topologyService.currentTopology(); |
| 390 | |
| 391 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 392 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 393 | |
| 394 | // test the getPaths() method using a null weight. |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 395 | Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), |
| 396 | dstVirtualDevice.id(), (LinkWeigher) null); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Test getPaths() and getPaths() by weight methods. |
| 401 | */ |
| 402 | @Test |
| 403 | public void testGetPaths() { |
| 404 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 405 | |
| 406 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 407 | Topology topology = topologyService.currentTopology(); |
| 408 | |
| 409 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 410 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 411 | |
| 412 | // test the getPaths() method. |
| 413 | Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id()); |
| 414 | assertNotNull("The paths should not be null.", paths); |
| 415 | assertEquals("The paths size did not match.", 1, paths.size()); |
| 416 | |
| 417 | // test the getPaths() by weight method. |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 418 | LinkWeigher weight = new LinkWeigherAdapter(1.0); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 419 | Set<Path> paths1 = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id(), weight); |
| 420 | assertNotNull("The paths should not be null.", paths1); |
| 421 | assertEquals("The paths size did not match.", 1, paths1.size()); |
| 422 | Path path = paths1.iterator().next(); |
| 423 | assertEquals("wrong path length", 1, path.links().size()); |
Ray Milkey | cc00124 | 2018-09-18 14:55:59 -0700 | [diff] [blame] | 424 | assertEquals("wrong path cost", ScalarWeight.toWeight(1.0), path.weight()); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Test getDisjointPaths() methods using a null src device identifier. |
| 429 | */ |
| 430 | @Test(expected = NullPointerException.class) |
| 431 | public void testGetDisjointPathsUsingNullSrcDeviceId() { |
| 432 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 433 | |
| 434 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 435 | Topology topology = topologyService.currentTopology(); |
| 436 | |
| 437 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 438 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 439 | |
| 440 | // test the getDisjointPaths() method using a null src device identifier. |
| 441 | Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, null, dstVirtualDevice.id()); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Test getDisjointPaths() methods using a null dst device identifier. |
| 446 | */ |
| 447 | @Test(expected = NullPointerException.class) |
| 448 | public void testGetDisjointPathsUsingNullDstDeviceId() { |
| 449 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 450 | |
| 451 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 452 | Topology topology = topologyService.currentTopology(); |
| 453 | |
| 454 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 455 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 456 | |
| 457 | // test the getDisjointPaths() method using a null dst device identifier. |
| 458 | Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), null); |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Test getDisjointPaths() methods using a null weight. |
| 463 | */ |
| 464 | @Test(expected = NullPointerException.class) |
| 465 | public void testGetDisjointPathsUsingNullWeight() { |
| 466 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 467 | |
| 468 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 469 | Topology topology = topologyService.currentTopology(); |
| 470 | |
| 471 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 472 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 473 | |
| 474 | // test the getDisjointPaths() method using a null weight. |
| 475 | Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 476 | dstVirtualDevice.id(), (LinkWeigher) null); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Test getDisjointPaths() methods using a null risk profile. |
| 481 | */ |
| 482 | @Test(expected = NullPointerException.class) |
| 483 | public void testGetDisjointPathsUsingNullRiskProfile() { |
| 484 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 485 | |
| 486 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 487 | Topology topology = topologyService.currentTopology(); |
| 488 | |
| 489 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 490 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 491 | |
| 492 | // test the getDisjointPaths() method using a null risk profile. |
| 493 | Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), |
| 494 | dstVirtualDevice.id(), (Map<Link, Object>) null); |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Test getDisjointPaths() methods. |
| 499 | */ |
| 500 | @Test |
| 501 | public void testGetDisjointPaths() { |
| 502 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 503 | |
| 504 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 505 | Topology topology = topologyService.currentTopology(); |
| 506 | |
| 507 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 508 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2); |
| 509 | |
| 510 | // test the getDisjointPaths() method. |
| 511 | Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), |
| 512 | dstVirtualDevice.id()); |
| 513 | assertNotNull("The paths should not be null.", paths); |
| 514 | assertEquals("The paths size did not match.", 1, paths.size()); |
| 515 | |
| 516 | // test the getDisjointPaths() method using a weight. |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 517 | LinkWeigher weight = new LinkWeigherAdapter(1.0); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 518 | Set<DisjointPath> paths1 = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), |
| 519 | dstVirtualDevice.id(), weight); |
| 520 | assertNotNull("The paths should not be null.", paths1); |
| 521 | assertEquals("The paths size did not match.", 1, paths1.size()); |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Test isInfrastructure() method using a null connect point. |
| 526 | */ |
| 527 | @Test(expected = NullPointerException.class) |
| 528 | public void testIsInfrastructureUsingNullConnectPoint() { |
| 529 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 530 | |
| 531 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 532 | Topology topology = topologyService.currentTopology(); |
| 533 | |
| 534 | // test the isInfrastructure() method using a null connect point. |
| 535 | Boolean isInfrastructure = topologyService.isInfrastructure(topology, null); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Test isInfrastructure() method. |
| 540 | */ |
| 541 | @Test |
| 542 | public void testIsInfrastructure() { |
| 543 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 544 | |
| 545 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 546 | Topology topology = topologyService.currentTopology(); |
| 547 | |
| 548 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 549 | VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID4); |
| 550 | ConnectPoint cp1 = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
| 551 | ConnectPoint cp2 = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); |
| 552 | |
| 553 | // test the isInfrastructure() method. |
| 554 | Boolean isInfrastructure = topologyService.isInfrastructure(topology, cp1); |
| 555 | assertTrue("The connect point should be infrastructure.", isInfrastructure); |
| 556 | |
| 557 | isInfrastructure = topologyService.isInfrastructure(topology, cp2); |
| 558 | assertFalse("The connect point should not be infrastructure.", isInfrastructure); |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Test isBroadcastPoint() method using a null connect point. |
| 563 | */ |
| 564 | @Test(expected = NullPointerException.class) |
| 565 | public void testIsBroadcastUsingNullConnectPoint() { |
| 566 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 567 | |
| 568 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 569 | Topology topology = topologyService.currentTopology(); |
| 570 | |
| 571 | // test the isInfrastructure() method using a null connect point. |
| 572 | Boolean isInfrastructure = topologyService.isBroadcastPoint(topology, null); |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Test isBroadcastPoint() method. |
| 577 | */ |
| 578 | @Test |
| 579 | public void testIsBroadcastPoint() { |
| 580 | VirtualNetwork virtualNetwork = setupVirtualNetworkTopology(); |
| 581 | |
| 582 | TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class); |
| 583 | Topology topology = topologyService.currentTopology(); |
| 584 | |
| 585 | VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1); |
| 586 | ConnectPoint cp = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
| 587 | |
| 588 | // test the isBroadcastPoint() method. |
| 589 | Boolean isBroadcastPoint = topologyService.isBroadcastPoint(topology, cp); |
| 590 | assertTrue("The connect point should be a broadcast point.", isBroadcastPoint); |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Return the virtual device matching the device identifier. |
| 595 | * |
| 596 | * @param networkId virtual network identifier |
| 597 | * @param deviceId device identifier |
| 598 | * @return virtual device |
| 599 | */ |
| 600 | private VirtualDevice getVirtualDevice(NetworkId networkId, DeviceId deviceId) { |
| 601 | Optional<VirtualDevice> foundDevice = manager.getVirtualDevices(networkId) |
| 602 | .stream() |
| 603 | .filter(device -> deviceId.equals(device.id())) |
| 604 | .findFirst(); |
| 605 | if (foundDevice.isPresent()) { |
| 606 | return foundDevice.get(); |
| 607 | } |
| 608 | return null; |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Core service test class. |
| 613 | */ |
| 614 | private class TestCoreService extends CoreServiceAdapter { |
| 615 | |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 616 | ApplicationId appId; |
| 617 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 618 | @Override |
| 619 | public IdGenerator getIdGenerator(String topic) { |
| 620 | return new IdGenerator() { |
| 621 | private AtomicLong counter = new AtomicLong(0); |
| 622 | |
| 623 | @Override |
| 624 | public long getNewId() { |
| 625 | return counter.getAndIncrement(); |
| 626 | } |
| 627 | }; |
| 628 | } |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 629 | |
| 630 | @Override |
| 631 | public ApplicationId registerApplication(String name) { |
| 632 | appId = new DefaultApplicationId(1, name); |
| 633 | return appId; |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public ApplicationId getAppId(String name) { |
| 638 | return appId; |
| 639 | } |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 640 | } |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 641 | |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 642 | } |