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