blob: f7fe7537da1dc246e3eb65f975b3f180dd964325 [file] [log] [blame]
weibitf7c31a42014-06-23 16:51:01 -07001package net.onrc.onos.core.topology;
2
Pavlin Radoslavov695f8952014-07-23 16:57:01 -07003import net.floodlightcontroller.core.IFloodlightProviderService.Role;
weibitf7c31a42014-06-23 16:51:01 -07004import net.floodlightcontroller.util.MACAddress;
5import net.onrc.onos.core.datagrid.IDatagridService;
6import net.onrc.onos.core.datagrid.IEventChannel;
7import net.onrc.onos.core.datagrid.IEventChannelListener;
8import net.onrc.onos.core.registry.IControllerRegistryService;
9import net.onrc.onos.core.util.Dpid;
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070010import net.onrc.onos.core.util.OnosInstanceId;
weibitf7c31a42014-06-23 16:51:01 -070011import net.onrc.onos.core.util.PortNumber;
12import net.onrc.onos.core.util.SwitchPort;
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070013import net.onrc.onos.core.util.TestUtils;
Ray Milkey38301352014-07-28 08:51:54 -070014import net.onrc.onos.core.util.UnitTest;
weibitf7c31a42014-06-23 16:51:01 -070015import org.easymock.EasyMock;
weibitf7c31a42014-06-23 16:51:01 -070016import org.junit.Before;
17import org.junit.Test;
18
Ray Milkey38301352014-07-28 08:51:54 -070019import java.util.ArrayList;
20import java.util.Collection;
21import java.util.List;
22import java.util.concurrent.CopyOnWriteArrayList;
23
24import static org.easymock.EasyMock.anyObject;
25import static org.easymock.EasyMock.createMock;
26import static org.easymock.EasyMock.eq;
27import static org.easymock.EasyMock.expect;
28import static org.easymock.EasyMock.replay;
29import static org.easymock.EasyMock.verify;
30import static org.hamcrest.Matchers.containsInAnyOrder;
31import static org.hamcrest.Matchers.hasItem;
32import static org.hamcrest.Matchers.not;
33import static org.junit.Assert.assertEquals;
34import static org.junit.Assert.assertNull;
35import static org.junit.Assert.assertThat;
36import static org.junit.Assert.assertTrue;
37
weibitf7c31a42014-06-23 16:51:01 -070038/**
39 * Unit tests for the TopologyManager class in the Topology module.
40 * These test cases only check the sanity of functions in the TopologyManager.
41 * Note that we do not test the eventHandler functions in the TopologyManager class.
42 * DatagridService, DataStoreService, eventChannel, and controllerRegistryService are mocked out.
43 */
Ray Milkey38301352014-07-28 08:51:54 -070044public class TopologyManagerTest extends UnitTest {
weibitf7c31a42014-06-23 16:51:01 -070045 private TopologyManager theTopologyManager;
46 private final String eventChannelName = "onos.topology";
47 private IEventChannel<byte[], TopologyEvent> eventChannel;
48 private IDatagridService datagridService;
49 private TopologyDatastore dataStoreService;
50 private IControllerRegistryService registryService;
51 private CopyOnWriteArrayList<ITopologyListener> topologyListeners;
52 private Collection<TopologyEvent> allTopologyEvents;
Pavlin Radoslavova5637c02014-07-30 15:55:11 -070053 private OnosInstanceId onosInstanceId = new OnosInstanceId("ONOS-Test-Instance-ID");
weibitf7c31a42014-06-23 16:51:01 -070054
55 @SuppressWarnings("unchecked")
56 @Before
57 public void setUp() throws Exception {
58 // Mock objects for testing
59 datagridService = EasyMock.createNiceMock(IDatagridService.class);
60 dataStoreService = EasyMock.createNiceMock(TopologyDatastore.class);
61 registryService = createMock(IControllerRegistryService.class);
62 eventChannel = EasyMock.createNiceMock(IEventChannel.class);
63
64 expect(datagridService.createChannel(
65 eq(eventChannelName),
66 eq(byte[].class),
67 eq(TopologyEvent.class)))
68 .andReturn(eventChannel).once();
69
70 expect(datagridService.addListener(
71 eq(eventChannelName),
72 anyObject(IEventChannelListener.class),
73 eq(byte[].class),
74 eq(TopologyEvent.class)))
75 .andReturn(eventChannel).once();
76
77 expect(dataStoreService.addSwitch(
78 anyObject(SwitchEvent.class),
79 anyObject(Collection.class)))
80 .andReturn(true).anyTimes();
81
82 expect(dataStoreService.deactivateSwitch(
83 anyObject(SwitchEvent.class),
84 anyObject(Collection.class)))
85 .andReturn(true).anyTimes();
86
87 expect(dataStoreService.addPort(
88 anyObject(PortEvent.class)))
89 .andReturn(true).anyTimes();
90
91 expect(dataStoreService.deactivatePort(
92 anyObject(PortEvent.class)))
93 .andReturn(true).anyTimes();
94
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070095 expect(dataStoreService.addHost(
96 anyObject(HostEvent.class)))
weibitf7c31a42014-06-23 16:51:01 -070097 .andReturn(true).anyTimes();
98
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070099 expect(dataStoreService.removeHost(
100 anyObject(HostEvent.class)))
weibitf7c31a42014-06-23 16:51:01 -0700101 .andReturn(true).anyTimes();
102
103 expect(dataStoreService.addLink(
104 anyObject(LinkEvent.class)))
105 .andReturn(true).anyTimes();
106
107 expect(dataStoreService.removeLink(
108 anyObject(LinkEvent.class)))
109 .andReturn(true).anyTimes();
110
Pavlin Radoslavova5637c02014-07-30 15:55:11 -0700111 expect(registryService.getOnosInstanceId()).andReturn(onosInstanceId).anyTimes();
112
weibitf7c31a42014-06-23 16:51:01 -0700113 replay(datagridService);
114 replay(registryService);
115 replay(dataStoreService);
116
117 allTopologyEvents = new CopyOnWriteArrayList<>();
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700118 expect(eventChannel.getAllEntries())
119 .andReturn(allTopologyEvents).anyTimes();
120 }
weibitf7c31a42014-06-23 16:51:01 -0700121
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700122 private void setupTopologyManager() {
weibitf7c31a42014-06-23 16:51:01 -0700123 // Create a topologyManager object for testing
124 topologyListeners = new CopyOnWriteArrayList<>();
125 theTopologyManager = new TopologyManager(registryService, topologyListeners);
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -0700126
127 // replace EventHandler to avoid thread from starting
128 TestUtils.setField(theTopologyManager, "eventHandler",
129 EasyMock.createNiceMock(TopologyManager.EventHandler.class));
weibitf7c31a42014-06-23 16:51:01 -0700130 theTopologyManager.startup(datagridService);
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -0700131
132 // replace data store with Mocked object
133 TestUtils.setField(theTopologyManager, "datastore", dataStoreService);
weibitf7c31a42014-06-23 16:51:01 -0700134 }
135
weibitf7c31a42014-06-23 16:51:01 -0700136 /**
137 * Test the Switch discovered and Port discovered functions.
138 */
139 @Test
140 public void testPutSwitchAndPortDiscoveryEvent() {
141 // Mock the eventChannel functions first
142 eventChannel.addEntry(anyObject(byte[].class),
143 anyObject(TopologyEvent.class));
144 EasyMock.expectLastCall().times(3, 3); // (1 switch + 1 port), 1 port
145 replay(eventChannel);
146
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700147 setupTopologyManager();
148
weibitf7c31a42014-06-23 16:51:01 -0700149 // mockSwitch has one port
150 Dpid swDPId = new Dpid(100L);
151 PortNumber portId = new PortNumber((short) 1);
152
153 // Generate a new switch event along with a port event
154 SwitchEvent switchEvent = new SwitchEvent(swDPId);
155
156 Collection<PortEvent> portEvents = new ArrayList<PortEvent>();
157 portEvents.add(new PortEvent(swDPId, portId));
158
159 // Call the topologyManager function for adding a switch
160 theTopologyManager.putSwitchDiscoveryEvent(switchEvent, portEvents);
161
162 for (PortEvent portEvent : portEvents) {
163 // Call the topologyManager function for adding a port
164 theTopologyManager.putPortDiscoveryEvent(portEvent);
165 }
166
167 // Verify the function calls
168 verify(eventChannel);
169
170 }
171
172 /**
173 * Test the switch and port removed functions.
174 */
175 @Test
176 public void testRemoveSwitchAndPortDiscoveryEvent() {
177 // Mock the eventChannel functions first
178 eventChannel.removeEntry(anyObject(byte[].class));
179 EasyMock.expectLastCall().times(2, 2); //1 switch, 1 port
180 replay(eventChannel);
181
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700182 setupTopologyManager();
183
weibitf7c31a42014-06-23 16:51:01 -0700184 Dpid swDPId = new Dpid(100L);
185 PortNumber portId = new PortNumber((short) 1);
186
187 // Generate a port event
188 Collection<PortEvent> portEvents = new ArrayList<PortEvent>();
189 portEvents.add(new PortEvent(swDPId, portId));
190
191 // Call the topologyManager function for removing a port
192 for (PortEvent portEvent : portEvents) {
193 theTopologyManager.removePortDiscoveryEvent(portEvent);
194 }
195
196 // Call the topologyManager function for removing a switch
197 SwitchEvent switchEvent = new SwitchEvent(swDPId);
198 theTopologyManager.removeSwitchDiscoveryEvent(switchEvent);
199
200 // Verify the function calls
201 verify(eventChannel);
202
203 }
204
205 /**
206 * Test the device discovered function.
207 */
208 @Test
209 public void testPutDeviceDiscoveryEvent() {
210 // Mock the eventChannel functions first
211 eventChannel.addEntry(anyObject(byte[].class),
212 anyObject(TopologyEvent.class));
213 EasyMock.expectLastCall().times(1, 1); // 1 device
214 replay(eventChannel);
215
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700216 setupTopologyManager();
217
weibitf7c31a42014-06-23 16:51:01 -0700218 long swDPId = 100L;
219 long portId = 1L;
220
221 // Generate a new device event
222 MACAddress devMac = MACAddress.valueOf("00:AA:11:BB:33:CC");
223 SwitchPort sp = new SwitchPort(swDPId, portId);
224 List<SwitchPort> spLists = new ArrayList<SwitchPort>();
225 spLists.add(sp);
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700226 HostEvent hostEvent = new HostEvent(devMac);
227 hostEvent.setAttachmentPoints(spLists);
weibitf7c31a42014-06-23 16:51:01 -0700228
229 // Call the topologyManager function for adding a device
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700230 theTopologyManager.putHostDiscoveryEvent(hostEvent);
weibitf7c31a42014-06-23 16:51:01 -0700231
232 // Verify the function calls
233 verify(eventChannel);
234 }
235
236 /**
237 * Test the device removed function.
238 */
239 @Test
240 public void testRemoveDeviceDiscoveryEvent() {
241 // Mock the eventChannel functions first
242 eventChannel.removeEntry(anyObject(byte[].class));
243 EasyMock.expectLastCall().times(1, 1); // 1 device
244 replay(eventChannel);
245
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700246 setupTopologyManager();
247
weibitf7c31a42014-06-23 16:51:01 -0700248 long swDPId = 100L;
249 long portId = 1L;
250
251 // Generate a new device event
252 MACAddress devMac = MACAddress.valueOf("00:AA:11:BB:33:CC");
253 SwitchPort sp = new SwitchPort(swDPId, portId);
254 List<SwitchPort> spLists = new ArrayList<SwitchPort>();
255 spLists.add(sp);
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700256 HostEvent hostEvent = new HostEvent(devMac);
257 hostEvent.setAttachmentPoints(spLists);
weibitf7c31a42014-06-23 16:51:01 -0700258
259 // Call the topologyManager function for removing a device
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700260 theTopologyManager.removeHostDiscoveryEvent(hostEvent);
weibitf7c31a42014-06-23 16:51:01 -0700261
262 // Verify the function calls
263 verify(eventChannel);
264 }
265
266 /**
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700267 * Test the Switch Mastership updated event.
268 */
269 @Test
270 public void testPutSwitchMastershipEvent() {
271 // Mock the eventChannel functions first
272 eventChannel.addEntry(anyObject(byte[].class),
273 anyObject(TopologyEvent.class));
274 EasyMock.expectLastCall().times(1, 1); // 1 event
275 replay(eventChannel);
276
277 setupTopologyManager();
278
279 // Generate a new Switch Mastership event
280 Dpid dpid = new Dpid(100L);
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700281 Role role = Role.MASTER;
282 MastershipEvent mastershipEvent =
Pavlin Radoslavova5637c02014-07-30 15:55:11 -0700283 new MastershipEvent(dpid, this.onosInstanceId, role);
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700284
285 // Call the topologyManager function for adding the event
286 theTopologyManager.putSwitchMastershipEvent(mastershipEvent);
287
288 // Verify the function calls
289 verify(eventChannel);
290 }
291
292 /**
293 * Test the Switch Mastership removed event.
294 */
295 @Test
296 public void testRemoveSwitchMastershipEvent() {
297 // Mock the eventChannel functions first
298 eventChannel.removeEntry(anyObject(byte[].class));
299 EasyMock.expectLastCall().times(1, 1); // 1 event
300 replay(eventChannel);
301
302 setupTopologyManager();
303
304 // Generate a new Switch Mastership event
305 Dpid dpid = new Dpid(100L);
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700306 Role role = Role.MASTER;
307 MastershipEvent mastershipEvent =
Pavlin Radoslavova5637c02014-07-30 15:55:11 -0700308 new MastershipEvent(dpid, this.onosInstanceId, role);
Pavlin Radoslavov695f8952014-07-23 16:57:01 -0700309
310 // Call the topologyManager function for removing the event
311 theTopologyManager.removeSwitchMastershipEvent(mastershipEvent);
312
313 // Verify the function calls
314 verify(eventChannel);
315 }
316
317 /**
weibitf7c31a42014-06-23 16:51:01 -0700318 * Test the link discovered function.
319 */
320 @Test
321 public void testPutLinkDiscoveryEvent() {
322 // Mock the eventChannel functions first
323 eventChannel.addEntry(anyObject(byte[].class),
324 anyObject(TopologyEvent.class));
325 EasyMock.expectLastCall().times(5, 5); // (2 switch + 2 port + 1 link)
326 replay(eventChannel);
327
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700328 setupTopologyManager();
329
weibitf7c31a42014-06-23 16:51:01 -0700330 // Assign the switch and port IDs
331 Dpid sw1DPId = new Dpid(100L);
332 PortNumber port1Id = new PortNumber((short) 1);
333 Dpid sw2DPId = new Dpid(200L);
334 PortNumber port2Id = new PortNumber((short) 2);
335
336 // Generate the switch and port events
337 SwitchEvent switchEvent1 = new SwitchEvent(sw1DPId);
338 Collection<PortEvent> portEvents1 = new ArrayList<PortEvent>();
339 portEvents1.add(new PortEvent(sw1DPId, port1Id));
340
341 // Call the topologyManager function for adding a switch
342 theTopologyManager.putSwitchDiscoveryEvent(switchEvent1, portEvents1);
343
344 // Generate the switch and port events
345 SwitchEvent switchEvent2 = new SwitchEvent(sw2DPId);
346 Collection<PortEvent> portEvents2 = new ArrayList<PortEvent>();
347 portEvents2.add(new PortEvent(sw2DPId, port2Id));
348
349 // Call the topologyManager function for adding a switch
350 theTopologyManager.putSwitchDiscoveryEvent(switchEvent2, portEvents2);
351
352 // Create the link
Pavlin Radoslavova5637c02014-07-30 15:55:11 -0700353 LinkEvent linkEvent = new LinkEvent(new SwitchPort(sw1DPId, port1Id),
354 new SwitchPort(sw2DPId, port2Id));
weibitf7c31a42014-06-23 16:51:01 -0700355 theTopologyManager.putLinkDiscoveryEvent(linkEvent);
356
357 // Verify the function calls
358 verify(eventChannel);
359 }
360
361 /**
362 * Test the link removed function.
363 */
364 @Test
365 public void testRemoveLinkDiscoveryEvent() {
366 // Mock the eventChannel functions first
367 eventChannel.removeEntry(anyObject(byte[].class));
368 EasyMock.expectLastCall().times(1, 1); // (1 link)
369 replay(eventChannel);
370
Yuta HIGUCHI81d8b9e2014-07-14 23:56:34 -0700371 setupTopologyManager();
372
weibitf7c31a42014-06-23 16:51:01 -0700373 // Assign the switch and port IDs
374 Dpid sw1DPId = new Dpid(100L);
375 PortNumber port1Id = new PortNumber((short) 1);
376 Dpid sw2DPId = new Dpid(200L);
377 PortNumber port2Id = new PortNumber((short) 2);
378
379 // Generate the switch and port events
380 SwitchEvent switchEvent1 = new SwitchEvent(sw1DPId);
381 Collection<PortEvent> portEvents1 = new ArrayList<PortEvent>();
382 portEvents1.add(new PortEvent(sw1DPId, port1Id));
383
384 // Call the topologyManager function for adding a switch
385 theTopologyManager.putSwitchDiscoveryEvent(switchEvent1, portEvents1);
386
387 // Generate the switch and port events
388 SwitchEvent switchEvent2 = new SwitchEvent(sw2DPId);
389 Collection<PortEvent> portEvents2 = new ArrayList<PortEvent>();
390 portEvents2.add(new PortEvent(sw2DPId, port2Id));
391
392 // Call the topologyManager function for adding a switch
393 theTopologyManager.putSwitchDiscoveryEvent(switchEvent2, portEvents2);
394
395 // Remove the link
Pavlin Radoslavova5637c02014-07-30 15:55:11 -0700396 LinkEvent linkEventRemove =
397 new LinkEvent(new SwitchPort(sw1DPId, port1Id),
398 new SwitchPort(sw2DPId, port2Id));
weibitf7c31a42014-06-23 16:51:01 -0700399 theTopologyManager.removeLinkDiscoveryEvent(linkEventRemove);
400
401 // Verify the function calls
402 verify(eventChannel);
403 }
404
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -0700405 /**
406 * Test to confirm topology replica transformation.
407 */
408 @Test
409 public void testAddSwitch() {
410 setupTopologyManager();
411
412 final Dpid dpid = new Dpid(1);
413 SwitchEvent sw = new SwitchEvent(dpid);
414 sw.createStringAttribute("foo", "bar");
415
416 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
417
418 // check topology structure
419 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
420 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
421 assertEquals(sw, swInTopo);
422 assertTrue(swInTopo.isFrozen());
423 assertEquals("bar", swInTopo.getStringAttribute("foo"));
424
425 // check events to be fired
426 List<SwitchEvent> apiAddedSwitchEvents
427 = TestUtils.getField(theTopologyManager, "apiAddedSwitchEvents");
428 assertThat(apiAddedSwitchEvents, hasItem(sw));
429 }
430
431 /**
432 * Test to confirm topology replica transformation.
433 */
434 @Test
435 public void testAddPort() {
436 setupTopologyManager();
437
438 final Dpid dpid = new Dpid(1);
439 SwitchEvent sw = new SwitchEvent(dpid);
440 sw.createStringAttribute("foo", "bar");
441
442 final PortNumber portNumber = new PortNumber((short) 2);
443 PortEvent port = new PortEvent(dpid, portNumber);
444 port.createStringAttribute("fuzz", "buzz");
445
446 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
447 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, port);
448
449 // check topology structure
450 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
451 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
452 assertEquals(sw, swInTopo);
453 assertTrue(swInTopo.isFrozen());
454 assertEquals("bar", swInTopo.getStringAttribute("foo"));
455
456 final SwitchPort portId = new SwitchPort(dpid, portNumber);
457 PortEvent portInTopo = topology.getPortEvent(portId);
458 assertEquals(port, portInTopo);
459 assertTrue(portInTopo.isFrozen());
460 assertEquals("buzz", portInTopo.getStringAttribute("fuzz"));
461
462 // check events to be fired
463 List<PortEvent> apiAddedPortEvents
464 = TestUtils.getField(theTopologyManager, "apiAddedPortEvents");
465 assertThat(apiAddedPortEvents, hasItem(port));
466 }
467
468 /**
469 * Test to confirm topology replica transformation.
470 */
471 @Test
472 public void testRemovePortThenSwitch() {
473 setupTopologyManager();
474
475 final Dpid dpid = new Dpid(1);
476 SwitchEvent sw = new SwitchEvent(dpid);
477 sw.createStringAttribute("foo", "bar");
478
479 final PortNumber portNumber = new PortNumber((short) 2);
480 PortEvent port = new PortEvent(dpid, portNumber);
481 port.createStringAttribute("fuzz", "buzz");
482
483 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
484 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, port);
485
486 // check topology structure
487 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
488 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
489 assertEquals(sw, swInTopo);
490 assertTrue(swInTopo.isFrozen());
491 assertEquals("bar", swInTopo.getStringAttribute("foo"));
492
493 final SwitchPort portId = new SwitchPort(dpid, portNumber);
494 PortEvent portInTopo = topology.getPortEvent(portId);
495 assertEquals(port, portInTopo);
496 assertTrue(portInTopo.isFrozen());
497 assertEquals("buzz", portInTopo.getStringAttribute("fuzz"));
498
499 // remove in proper order
500 TestUtils.callMethod(theTopologyManager, "removePort",
501 PortEvent.class, new PortEvent(port));
502 TestUtils.callMethod(theTopologyManager, "removeSwitch",
503 SwitchEvent.class, new SwitchEvent(sw));
504
505
506 // check events to be fired
507 List<PortEvent> apiRemovedPortEvents
508 = TestUtils.getField(theTopologyManager, "apiRemovedPortEvents");
509 assertThat(apiRemovedPortEvents, hasItem(port));
510 List<SwitchEvent> apiRemovedSwitchEvents
511 = TestUtils.getField(theTopologyManager, "apiRemovedSwitchEvents");
512 assertThat(apiRemovedSwitchEvents, hasItem(sw));
513 }
514
515 /**
516 * Test to confirm topology replica transformation.
517 */
518 @Test
519 public void testRemoveSwitch() {
520 setupTopologyManager();
521
522 final Dpid dpid = new Dpid(1);
523 SwitchEvent sw = new SwitchEvent(dpid);
524 sw.createStringAttribute("foo", "bar");
525
526 final PortNumber portNumber = new PortNumber((short) 2);
527 PortEvent port = new PortEvent(dpid, portNumber);
528 port.createStringAttribute("fuzz", "buzz");
529
530 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
531 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, port);
532
533 // check topology structure
534 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
535 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
536 assertEquals(sw, swInTopo);
537 assertTrue(swInTopo.isFrozen());
538 assertEquals("bar", swInTopo.getStringAttribute("foo"));
539
540 final SwitchPort portId = new SwitchPort(dpid, portNumber);
541 PortEvent portInTopo = topology.getPortEvent(portId);
542 assertEquals(port, portInTopo);
543 assertTrue(portInTopo.isFrozen());
544 assertEquals("buzz", portInTopo.getStringAttribute("fuzz"));
545
546 // remove in in-proper order
547// TestUtils.callMethod(theTopologyManager, "removePort",
548// PortEvent.class, new PortEvent(port));
549 TestUtils.callMethod(theTopologyManager, "removeSwitch",
550 SwitchEvent.class, new SwitchEvent(sw));
551
552
553 // check events to be fired
554 // outcome should be the same as #testRemovePortThenSwitch
555 List<PortEvent> apiRemovedPortEvents
556 = TestUtils.getField(theTopologyManager, "apiRemovedPortEvents");
557 assertThat(apiRemovedPortEvents, hasItem(port));
558 List<SwitchEvent> apiRemovedSwitchEvents
559 = TestUtils.getField(theTopologyManager, "apiRemovedSwitchEvents");
560 assertThat(apiRemovedSwitchEvents, hasItem(sw));
561 }
562
563 /**
564 * Test to confirm topology replica transformation.
565 */
566 @Test
567 public void testAddLink() {
568 setupTopologyManager();
569
570 final Dpid dpid = new Dpid(1);
571 SwitchEvent sw = new SwitchEvent(dpid);
572 sw.createStringAttribute("foo", "bar");
573
574 final PortNumber portNumberA = new PortNumber((short) 2);
575 PortEvent portA = new PortEvent(dpid, portNumberA);
576 portA.createStringAttribute("fuzz", "buzz");
577
578 final PortNumber portNumberB = new PortNumber((short) 3);
579 PortEvent portB = new PortEvent(dpid, portNumberB);
580 portB.createStringAttribute("fizz", "buz");
581
582 LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
583 linkA.createStringAttribute(TopologyElement.TYPE,
584 TopologyElement.TYPE_OPTICAL_LAYER);
585 LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
586 linkB.createStringAttribute(TopologyElement.TYPE,
587 TopologyElement.TYPE_OPTICAL_LAYER);
588
589 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
590 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
591 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
592 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
593 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
594
595 // check topology structure
596 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
597 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
598 assertEquals(sw, swInTopo);
599 assertTrue(swInTopo.isFrozen());
600 assertEquals("bar", swInTopo.getStringAttribute("foo"));
601
602 final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
603 PortEvent portAInTopo = topology.getPortEvent(portIdA);
604 assertEquals(portA, portAInTopo);
605 assertTrue(portAInTopo.isFrozen());
606 assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
607
608 final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
609 PortEvent portBInTopo = topology.getPortEvent(portIdB);
610 assertEquals(portB, portBInTopo);
611 assertTrue(portBInTopo.isFrozen());
612 assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
613
614 LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
615 assertEquals(linkA, linkAInTopo);
616 assertTrue(linkAInTopo.isFrozen());
617 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
618
619 LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
620 assertEquals(linkB, linkBInTopo);
621 assertTrue(linkBInTopo.isFrozen());
622 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
623
624 // check events to be fired
625 List<LinkEvent> apiAddedLinkEvents
626 = TestUtils.getField(theTopologyManager, "apiAddedLinkEvents");
627 assertThat(apiAddedLinkEvents, containsInAnyOrder(linkA, linkB));
628 }
629
630 /**
631 * Test to confirm topology replica transformation.
632 */
633 @Test
634 public void testAddLinkKickingOffHost() {
635 setupTopologyManager();
636
637 final Dpid dpid = new Dpid(1);
638 SwitchEvent sw = new SwitchEvent(dpid);
639 sw.createStringAttribute("foo", "bar");
640
641 final PortNumber portNumberA = new PortNumber((short) 2);
642 PortEvent portA = new PortEvent(dpid, portNumberA);
643 portA.createStringAttribute("fuzz", "buzz");
644
645 final PortNumber portNumberB = new PortNumber((short) 3);
646 PortEvent portB = new PortEvent(dpid, portNumberB);
647 portB.createStringAttribute("fizz", "buz");
648
649 final PortNumber portNumberC = new PortNumber((short) 4);
650 PortEvent portC = new PortEvent(dpid, portNumberC);
651 portC.createStringAttribute("fizz", "buz");
652
653 final MACAddress macA = MACAddress.valueOf(666L);
654 HostEvent hostA = new HostEvent(macA);
655 hostA.addAttachmentPoint(portA.getSwitchPort());
656 final long timestampA = 392893200L;
657 hostA.setLastSeenTime(timestampA);
658
659 final MACAddress macB = MACAddress.valueOf(999L);
660 HostEvent hostB = new HostEvent(macB);
661 hostB.addAttachmentPoint(portB.getSwitchPort());
662 hostB.addAttachmentPoint(portC.getSwitchPort());
663 final long timestampB = 392893201L;
664 hostB.setLastSeenTime(timestampB);
665
666
667 LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
668 linkA.createStringAttribute(TopologyElement.TYPE,
669 TopologyElement.TYPE_OPTICAL_LAYER);
670 LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
671 linkB.createStringAttribute(TopologyElement.TYPE,
672 TopologyElement.TYPE_OPTICAL_LAYER);
673
674 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
675 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
676 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
677 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portC);
678 TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostA);
679 TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostB);
680
681 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
682 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
683
684 // check topology structure
685 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
686 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
687 assertEquals(sw, swInTopo);
688 assertTrue(swInTopo.isFrozen());
689 assertEquals("bar", swInTopo.getStringAttribute("foo"));
690
691 final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
692 PortEvent portAInTopo = topology.getPortEvent(portIdA);
693 assertEquals(portA, portAInTopo);
694 assertTrue(portAInTopo.isFrozen());
695 assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
696
697 final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
698 PortEvent portBInTopo = topology.getPortEvent(portIdB);
699 assertEquals(portB, portBInTopo);
700 assertTrue(portBInTopo.isFrozen());
701 assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
702
703 // hostA expected to be removed
704 assertNull(topology.getHostEvent(macA));
705 // hostB expected to be there with reduced attachment point
706 HostEvent hostBrev = new HostEvent(macB);
707 hostBrev.addAttachmentPoint(portC.getSwitchPort());
708 hostBrev.setLastSeenTime(timestampB);
709 hostBrev.freeze();
710 assertEquals(hostBrev, topology.getHostEvent(macB));
711
712
713 LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
714 assertEquals(linkA, linkAInTopo);
715 assertTrue(linkAInTopo.isFrozen());
716 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
717
718 LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
719 assertEquals(linkB, linkBInTopo);
720 assertTrue(linkBInTopo.isFrozen());
721 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
722
723 // check events to be fired
724 List<HostEvent> apiAddedHostEvents
725 = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
726 assertThat(apiAddedHostEvents, hasItem(hostBrev));
727
728 List<HostEvent> apiRemovedHostEvents
729 = TestUtils.getField(theTopologyManager, "apiRemovedHostEvents");
730 assertThat(apiRemovedHostEvents, hasItem(hostA));
731 List<LinkEvent> apiAddedLinkEvents
732 = TestUtils.getField(theTopologyManager, "apiAddedLinkEvents");
733 assertThat(apiAddedLinkEvents, containsInAnyOrder(linkA, linkB));
734 }
735
736 /**
737 * Test to confirm topology replica transformation.
738 */
739 @Test
740 public void testRemoveLink() {
741 setupTopologyManager();
742
743 final Dpid dpid = new Dpid(1);
744 SwitchEvent sw = new SwitchEvent(dpid);
745 sw.createStringAttribute("foo", "bar");
746
747 final PortNumber portNumberA = new PortNumber((short) 2);
748 PortEvent portA = new PortEvent(dpid, portNumberA);
749 portA.createStringAttribute("fuzz", "buzz");
750
751 final PortNumber portNumberB = new PortNumber((short) 3);
752 PortEvent portB = new PortEvent(dpid, portNumberB);
753 portB.createStringAttribute("fizz", "buz");
754
755 LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
756 linkA.createStringAttribute(TopologyElement.TYPE,
757 TopologyElement.TYPE_OPTICAL_LAYER);
758 LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
759 linkB.createStringAttribute(TopologyElement.TYPE,
760 TopologyElement.TYPE_OPTICAL_LAYER);
761
762 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
763 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
764 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
765 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
766 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
767
768 // check topology structure
769 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
770 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
771 assertEquals(sw, swInTopo);
772 assertTrue(swInTopo.isFrozen());
773 assertEquals("bar", swInTopo.getStringAttribute("foo"));
774
775 final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
776 PortEvent portAInTopo = topology.getPortEvent(portIdA);
777 assertEquals(portA, portAInTopo);
778 assertTrue(portAInTopo.isFrozen());
779 assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
780
781 final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
782 PortEvent portBInTopo = topology.getPortEvent(portIdB);
783 assertEquals(portB, portBInTopo);
784 assertTrue(portBInTopo.isFrozen());
785 assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
786
787 LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
788 assertEquals(linkA, linkAInTopo);
789 assertTrue(linkAInTopo.isFrozen());
790 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
791
792
793 LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
794 assertEquals(linkB, linkBInTopo);
795 assertTrue(linkBInTopo.isFrozen());
796 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
797
798 // check events to be fired
799 // FIXME if link flapped (linkA in this scenario),
800 // linkA appears in both removed and added is this expected behavior?
801 List<LinkEvent> apiAddedLinkEvents
802 = TestUtils.getField(theTopologyManager, "apiAddedLinkEvents");
803 assertThat(apiAddedLinkEvents, containsInAnyOrder(linkA, linkB));
804
805 // clear event before removing Link
806 apiAddedLinkEvents.clear();
807
808 // remove link
809 TestUtils.callMethod(theTopologyManager, "removeLink", LinkEvent.class, new LinkEvent(linkA));
810
811 LinkEvent linkANotInTopo = topology.getLinkEvent(linkA.getLinkTuple());
812 assertNull(linkANotInTopo);
813
814 List<LinkEvent> apiRemovedLinkEvents
815 = TestUtils.getField(theTopologyManager, "apiRemovedLinkEvents");
816 assertThat(apiRemovedLinkEvents, hasItem(linkA));
817 }
818
819 /**
820 * Test to confirm topology replica transformation.
821 */
822 @Test
823 public void testAddHostIgnoredByLink() {
824 setupTopologyManager();
825
826 final Dpid dpid = new Dpid(1);
827 SwitchEvent sw = new SwitchEvent(dpid);
828 sw.createStringAttribute("foo", "bar");
829
830 final PortNumber portNumberA = new PortNumber((short) 2);
831 PortEvent portA = new PortEvent(dpid, portNumberA);
832 portA.createStringAttribute("fuzz", "buzz");
833
834 final PortNumber portNumberB = new PortNumber((short) 3);
835 PortEvent portB = new PortEvent(dpid, portNumberB);
836 portB.createStringAttribute("fizz", "buz");
837
838 final PortNumber portNumberC = new PortNumber((short) 4);
839 PortEvent portC = new PortEvent(dpid, portNumberC);
840 portC.createStringAttribute("fizz", "buz");
841
842 LinkEvent linkA = new LinkEvent(portA.getSwitchPort(), portB.getSwitchPort());
843 linkA.createStringAttribute(TopologyElement.TYPE,
844 TopologyElement.TYPE_OPTICAL_LAYER);
845 LinkEvent linkB = new LinkEvent(portB.getSwitchPort(), portA.getSwitchPort());
846 linkB.createStringAttribute(TopologyElement.TYPE,
847 TopologyElement.TYPE_OPTICAL_LAYER);
848
849 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
850 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
851 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
852 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portC);
853 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkA);
854 TestUtils.callMethod(theTopologyManager, "addLink", LinkEvent.class, linkB);
855
856 // Add hostA attached to a port which already has a link
857 final MACAddress macA = MACAddress.valueOf(666L);
858 HostEvent hostA = new HostEvent(macA);
859 hostA.addAttachmentPoint(portA.getSwitchPort());
860 final long timestampA = 392893200L;
861 hostA.setLastSeenTime(timestampA);
862
863 TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostA);
864
865 // Add hostB attached to multiple ports,
866 // some of them which already has a link
867 final MACAddress macB = MACAddress.valueOf(999L);
868 HostEvent hostB = new HostEvent(macB);
869 hostB.addAttachmentPoint(portB.getSwitchPort());
870 hostB.addAttachmentPoint(portC.getSwitchPort());
871 final long timestampB = 392893201L;
872 hostB.setLastSeenTime(timestampB);
873
874 TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostB);
875
876 // check topology structure
877 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
878 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
879 assertEquals(sw, swInTopo);
880 assertTrue(swInTopo.isFrozen());
881 assertEquals("bar", swInTopo.getStringAttribute("foo"));
882
883 final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
884 PortEvent portAInTopo = topology.getPortEvent(portIdA);
885 assertEquals(portA, portAInTopo);
886 assertTrue(portAInTopo.isFrozen());
887 assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
888
889 final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
890 PortEvent portBInTopo = topology.getPortEvent(portIdB);
891 assertEquals(portB, portBInTopo);
892 assertTrue(portBInTopo.isFrozen());
893 assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
894
895 // hostA expected to be completely ignored
896 assertNull(topology.getHostEvent(macA));
897 // hostB expected to be there with reduced attachment point
898 HostEvent hostBrev = new HostEvent(macB);
899 hostBrev.addAttachmentPoint(portC.getSwitchPort());
900 hostBrev.setLastSeenTime(timestampB);
901 hostBrev.freeze();
902 assertEquals(hostBrev, topology.getHostEvent(macB));
903
904
905 LinkEvent linkAInTopo = topology.getLinkEvent(linkA.getLinkTuple());
906 assertEquals(linkA, linkAInTopo);
907 assertTrue(linkAInTopo.isFrozen());
908 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkAInTopo.getType());
909
910 LinkEvent linkBInTopo = topology.getLinkEvent(linkB.getLinkTuple());
911 assertEquals(linkB, linkBInTopo);
912 assertTrue(linkBInTopo.isFrozen());
913 assertEquals(TopologyElement.TYPE_OPTICAL_LAYER, linkBInTopo.getType());
914
915 // check events to be fired
916 // hostB should be added with reduced attachment points
917 List<HostEvent> apiAddedHostEvents
918 = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
919 assertThat(apiAddedHostEvents, hasItem(hostBrev));
920
921 // hostA should not be ignored
922 List<HostEvent> apiRemovedHostEvents
923 = TestUtils.getField(theTopologyManager, "apiRemovedHostEvents");
924 assertThat(apiRemovedHostEvents, not(hasItem(hostA)));
925
926 List<LinkEvent> apiAddedLinkEvents
927 = TestUtils.getField(theTopologyManager, "apiAddedLinkEvents");
928 assertThat(apiAddedLinkEvents, containsInAnyOrder(linkA, linkB));
929 }
930
931 /**
932 * Test to confirm topology replica transformation.
933 */
934 @Test
935 public void testAddHostMove() {
936 setupTopologyManager();
937
938 final Dpid dpid = new Dpid(1);
939 SwitchEvent sw = new SwitchEvent(dpid);
940 sw.createStringAttribute("foo", "bar");
941
942 final PortNumber portNumberA = new PortNumber((short) 2);
943 PortEvent portA = new PortEvent(dpid, portNumberA);
944 portA.createStringAttribute("fuzz", "buzz");
945
946 final PortNumber portNumberB = new PortNumber((short) 3);
947 PortEvent portB = new PortEvent(dpid, portNumberB);
948 portB.createStringAttribute("fizz", "buz");
949
950 final PortNumber portNumberC = new PortNumber((short) 4);
951 PortEvent portC = new PortEvent(dpid, portNumberC);
952 portC.createStringAttribute("fizz", "buz");
953
954 TestUtils.callMethod(theTopologyManager, "addSwitch", SwitchEvent.class, sw);
955 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portA);
956 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portB);
957 TestUtils.callMethod(theTopologyManager, "addPort", PortEvent.class, portC);
958
959 // Add hostA attached to a port which already has a link
960 final MACAddress macA = MACAddress.valueOf(666L);
961 HostEvent hostA = new HostEvent(macA);
962 hostA.addAttachmentPoint(portA.getSwitchPort());
963 final long timestampA = 392893200L;
964 hostA.setLastSeenTime(timestampA);
965
966 TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostA);
967
968
969 // check topology structure
970 TopologyInternal topology = (TopologyInternal) theTopologyManager.getTopology();
971 SwitchEvent swInTopo = topology.getSwitchEvent(dpid);
972 assertEquals(sw, swInTopo);
973 assertTrue(swInTopo.isFrozen());
974 assertEquals("bar", swInTopo.getStringAttribute("foo"));
975
976 final SwitchPort portIdA = new SwitchPort(dpid, portNumberA);
977 PortEvent portAInTopo = topology.getPortEvent(portIdA);
978 assertEquals(portA, portAInTopo);
979 assertTrue(portAInTopo.isFrozen());
980 assertEquals("buzz", portAInTopo.getStringAttribute("fuzz"));
981
982 final SwitchPort portIdB = new SwitchPort(dpid, portNumberB);
983 PortEvent portBInTopo = topology.getPortEvent(portIdB);
984 assertEquals(portB, portBInTopo);
985 assertTrue(portBInTopo.isFrozen());
986 assertEquals("buz", portBInTopo.getStringAttribute("fizz"));
987
988 // hostA expected to be there
989 assertEquals(hostA, topology.getHostEvent(macA));
990 assertEquals(timestampA, topology.getHostEvent(macA).getLastSeenTime());
991
992 // check events to be fired
993 // hostA should be added
994 List<HostEvent> apiAddedHostEvents
995 = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
996 assertThat(apiAddedHostEvents, hasItem(hostA));
997
998
999 // clear event before moving host
1000 apiAddedHostEvents.clear();
1001
1002 HostEvent hostAmoved = new HostEvent(macA);
1003 hostAmoved.addAttachmentPoint(portB.getSwitchPort());
1004 final long timestampAmoved = 392893201L;
1005 hostAmoved.setLastSeenTime(timestampAmoved);
1006
1007 TestUtils.callMethod(theTopologyManager, "addHost", HostEvent.class, hostAmoved);
1008
1009 assertEquals(hostAmoved, topology.getHostEvent(macA));
1010 assertEquals(timestampAmoved, topology.getHostEvent(macA).getLastSeenTime());
1011
1012 // hostA expected to be there with new attachment point
1013 apiAddedHostEvents
1014 = TestUtils.getField(theTopologyManager, "apiAddedHostEvents");
1015 assertThat(apiAddedHostEvents, hasItem(hostAmoved));
1016
1017 // hostA is updated not removed
1018 List<HostEvent> apiRemovedHostEvents
1019 = TestUtils.getField(theTopologyManager, "apiRemovedHostEvents");
1020 assertThat(apiRemovedHostEvents, not(hasItem(hostA)));
1021 }
weibitf7c31a42014-06-23 16:51:01 -07001022}