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