doAddSwitchToStore(1L, null, fr1a);
controller.processUpdateQueueForTesting();
verify(switchListener);
reset(switchListener);
IOFSwitch sw = controller.getSwitch(1L);
assertNotNull("Switch should be present", sw);
assertEquals(1L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
assertEquals(new HashSet<ImmutablePort>(ports1aImmutable),
new HashSet<ImmutablePort>(sw.getPorts()));
// add switch 2 with fr2a to store
reset(switchListener);
switchListener.switchAdded(2L);
expectLastCall().once();
replay(switchListener);
doAddSwitchToStore(2L, null, fr2a);
controller.processUpdateQueueForTesting();
verify(switchListener);
reset(switchListener);
sw = controller.getSwitch(2L);
assertNotNull("Switch should be present", sw);
assertEquals(2L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
assertEquals(new HashSet<ImmutablePort>(ports2aImmutable),
new HashSet<ImmutablePort>(sw.getPorts()));
// add switch 3 to store
reset(switchListener);
switchListener.switchAdded(3L);
expectLastCall().once();
replay(switchListener);
doAddSwitchToStore(3L, null, null);
controller.processUpdateQueueForTesting();
verify(switchListener);
reset(switchListener);
sw = controller.getSwitch(3L);
assertNotNull("Switch should be present", sw);
assertEquals(3L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
// add switch 4 to store
reset(switchListener);
switchListener.switchAdded(4L);
expectLastCall().once();
replay(switchListener);
doAddSwitchToStore(4L, null, null);
controller.processUpdateQueueForTesting();
verify(switchListener);
reset(switchListener);
sw = controller.getSwitch(4L);
assertNotNull("Switch should be present", sw);
assertEquals(4L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
// update switch 1 with fr1b
reset(switchListener);
switchListener.switchPortChanged(1L, sw1p2, PortChangeType.ADD);
expectLastCall().once();
replay(switchListener);
doAddSwitchToStore(1L, null, fr1b);
controller.processUpdateQueueForTesting();
verify(switchListener);
reset(switchListener);
sw = controller.getSwitch(1L);
assertNotNull("Switch should be present", sw);
assertEquals(1L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
assertEquals(new HashSet<ImmutablePort>(ports1bImmutable),
new HashSet<ImmutablePort>(sw.getPorts()));
// Check getAllSwitchDpids() and getAllSwitchMap()
Set<Long> expectedDpids = new HashSet<Long>();
expectedDpids.add(1L);
expectedDpids.add(2L);
expectedDpids.add(3L);
expectedDpids.add(4L);
assertEquals(expectedDpids, controller.getAllSwitchDpids());
Map<Long, IOFSwitch> expectedSwitchMap = new HashMap<Long, IOFSwitch>();
expectedSwitchMap.put(1L, controller.getSwitch(1L));
expectedSwitchMap.put(2L, controller.getSwitch(2L));
expectedSwitchMap.put(3L, controller.getSwitch(3L));
expectedSwitchMap.put(4L, controller.getSwitch(4L));
assertEquals(expectedSwitchMap, controller.getAllSwitchMap());
verify(haListener);
//--------------------------------------
// Transition to master
//--------------------------------------
reset(haListener);
haListener.transitionToMaster();
expectLastCall().once();
replay(haListener);
controller.setConsolidateStoreTaskDelay(consolidateStoreDelayMs);
controller.setRole(Role.MASTER, "FooBar");
controller.processUpdateQueueForTesting();
verify(haListener);
reset(haListener);
replay(haListener);
//--------------------------------------
// Activate switches
//--------------------------------------
// Activate switch 1
IOFSwitch sw1 = createMock(IOFSwitch.class);
setupSwitchForAddSwitch(sw1, 1L, null, fr1b);
reset(switchListener);
switchListener.switchActivated(1L);
expectLastCall().once();
replay(sw1);
replay(switchListener);
controller.switchActivated(sw1);
controller.processUpdateQueueForTesting();
verify(switchListener);
verify(sw1);
sw = controller.getSwitch(1L);
assertNotNull("Switch should be present", sw);
assertSame(sw1, sw); // the mock switch should be returned
// Activate switch 2 with different features reply
// should get portChanged
// also set alwaysClearFlorModOnSwAcitvate to true;
controller.setAlwaysClearFlowsOnSwActivate(true);
IOFSwitch sw2 = createMock(IOFSwitch.class);
setupSwitchForAddSwitch(sw2, 2L, null, fr2b);
sw2.clearAllFlowMods();
expectLastCall().once();
reset(switchListener);
switchListener.switchActivated(2L);
expectLastCall().once();
switchListener.switchPortChanged(2L, sw2p1, PortChangeType.DELETE);
switchListener.switchPortChanged(2L, sw2p1Changed, PortChangeType.ADD);
expectLastCall().once();
replay(sw2);
replay(switchListener);
controller.switchActivated(sw2);
controller.processUpdateQueueForTesting();
verify(switchListener);
verify(sw2);
sw = controller.getSwitch(2L);
assertNotNull("Switch should be present", sw);
assertSame(sw2, sw); // the mock switch should be returned
// Do not activate switch 3, but it should still be present
sw = controller.getSwitch(3L);
IOFSwitch sw3 = sw;
assertNotNull("Switch should be present", sw);
assertEquals(3L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
// Do not activate switch 4, but it should still be present
sw = controller.getSwitch(4L);
IOFSwitch sw4 = sw;
assertNotNull("Switch should be present", sw);
assertEquals(4L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
// Check getAllSwitchDpids() and getAllSwitchMap()