/** * Test switchActivated for a new switch while in slave: disconnect the switch */ @Test public void testNewSwitchActivatedWhileSlave() throws Exception { doSetUp(HARole.STANDBY); IOFSwitchBackend sw = createMock(IOFSwitchBackend.class); IOFSwitchListener listener = createMock(IOFSwitchListener.class); switchManager.addOFSwitchListener(listener); expect(sw.getId()).andReturn(DATAPATH_ID_0).anyTimes(); expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes(); sw.disconnect(); expectLastCall().once(); expect(sw.getOFFactory()).andReturn(factory).once(); replay(sw, listener); // nothing recorded switchManager.switchAdded(sw); switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER); verify(sw); controller.processUpdateQueueForTesting(); verify(listener); }
/** * Try to remove a switch that's different from what's in the active * switch map. Should be ignored */ @Test public void testSwitchDisconnectedOther() throws Exception { IOFSwitch origSw = doActivateNewSwitch(DATAPATH_ID_1, null, null); // create a new mock switch IOFSwitchBackend sw = createMock(IOFSwitchBackend.class); expect(sw.getId()).andReturn(DATAPATH_ID_1).anyTimes(); IOFSwitchListener listener = createMock(IOFSwitchListener.class); switchManager.addOFSwitchListener(listener); replay(sw, listener); switchManager.switchDisconnected(sw); controller.processUpdateQueueForTesting(); verify(sw, listener); expect(origSw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes(); replay(origSw); assertSame(origSw, switchManager.getSwitch(DATAPATH_ID_1)); }
/** * Test switchActivated for a new switch while in slave: disconnect the switch */ @Test public void testNewSwitchActivatedWhileSlave() throws Exception { doSetUp(HARole.STANDBY); IOFSwitchBackend sw = createMock(IOFSwitchBackend.class); IOFSwitchListener listener = createMock(IOFSwitchListener.class); switchManager.addOFSwitchListener(listener); expect(sw.getId()).andReturn(DATAPATH_ID_0).anyTimes(); expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes(); sw.disconnect(); expectLastCall().once(); replay(sw, listener); // nothing recorded switchManager.switchAdded(sw); switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER); verify(sw); controller.processUpdateQueueForTesting(); verify(listener); }
/** * Disconnect a switch. normal program flow */ @Test private void doTestSwitchConnectReconnect(boolean reconnect) throws Exception { IOFSwitch sw = doActivateNewSwitch(1L, null, null); expect(sw.getId()).andReturn(1L).anyTimes(); expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes(); sw.cancelAllStatisticsReplies(); expectLastCall().once(); IOFSwitchListener listener = createMock(IOFSwitchListener.class); listener.switchRemoved(1L); expectLastCall().once(); controller.addOFSwitchListener(listener); replay(sw, listener); controller.switchDisconnected(sw); controller.processUpdateQueueForTesting(); verify(sw, listener); assertNull(controller.getSwitch(1L)); assertNull(storeClient.getValue(1L)); if (reconnect) { controller.removeOFSwitchListener(listener); sw = doActivateOldSwitch(1L, null, null); } }
/** * Remove a nonexisting switch. should be ignored */ @Test public void testNonexistingSwitchDisconnected() throws Exception { IOFSwitch sw = createMock(IOFSwitch.class); expect(sw.getId()).andReturn(1L).anyTimes(); expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes(); IOFSwitchListener listener = createMock(IOFSwitchListener.class); controller.addOFSwitchListener(listener); replay(sw, listener); controller.switchDisconnected(sw); controller.processUpdateQueueForTesting(); verify(sw, listener); assertNull(controller.getSwitch(1L)); assertNull(storeClient.getValue(1L)); }
/** * Try to remove a switch that's different from what's in the active * switch map. Should be ignored */ @Test public void testSwitchDisconnectedOther() throws Exception { IOFSwitch origSw = doActivateNewSwitch(1L, null, null); // create a new mock switch IOFSwitch sw = createMock(IOFSwitch.class); expect(sw.getId()).andReturn(1L).anyTimes(); expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes(); IOFSwitchListener listener = createMock(IOFSwitchListener.class); controller.addOFSwitchListener(listener); replay(sw, listener); controller.switchDisconnected(sw); controller.processUpdateQueueForTesting(); verify(sw, listener); assertSame(origSw, controller.getSwitch(1L)); assertNotNull(storeClient.getValue(1L)); }
public void dispatch() { if (log.isTraceEnabled()) { log.trace("Dispatching switch update {} {}", sw, switchUpdateType); } if (switchListeners != null) { for (IOFSwitchListener listener : switchListeners) { switch(switchUpdateType) { case ADDED: listener.addedSwitch(sw); break; case REMOVED: listener.removedSwitch(sw); break; case PORTCHANGED: listener.switchPortChanged(sw.getId()); break; } } } }
/** * Initialize internal data structures */ public void init(Map<String, String> configParams) { // These data structures are initialized here because other // module's startUp() might be called before ours this.messageListeners = new ConcurrentHashMap<OFType, ListenerDispatcher<OFType, IOFMessageListener>>(); this.switchListeners = new CopyOnWriteArraySet<IOFSwitchListener>(); this.haListeners = new CopyOnWriteArraySet<IHAListener>(); this.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); this.connectedSwitches = new HashSet<OFSwitchImpl>(); this.controllerNodeIPsCache = new HashMap<String, String>(); this.updates = new LinkedBlockingQueue<IUpdate>(); this.factory = new BasicFactory(); this.providerMap = new HashMap<String, List<IInfoProvider>>(); setConfigParams(configParams); this.role = getInitialRole(configParams); this.roleChanger = new RoleChanger(); initVendorMessages(); this.systemStartTime = System.currentTimeMillis(); }
/** * Test adding a new switch in the MASTER role. * We expect a switchActivatedMaster event fired to the switch listeners. */ @Test public void testSwitchActivatedMaster() throws Exception { long dpid = 1L; controller.setAlwaysClearFlowsOnSwActivate(false); controller.setAlwaysClearFlowsOnSwAdd(false); // Create a 1.0 switch. There's no difference between 1.0 and 1.3 here. IOFSwitch sw = createMockSwitch(dpid, OFVersion.OF_10); // strict mock. Order of events matters! IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class); listener.switchActivatedMaster(dpid); expectLastCall().once(); replay(listener); controller.addOFSwitchListener(listener); replay(sw); controller.addConnectedSwitch(dpid, new OFChannelHandler(controller)); controller.addActivatedMasterSwitch(dpid, sw); verify(sw); assertEquals(sw, controller.getMasterSwitch(dpid)); controller.processUpdateQueueForTesting(); verify(listener); }
/** * Test adding a new switch in the EQUAL role. * We expect a switchActivatedEqual event fired to the switch listeners. */ @Test public void testSwitchActivatedEqual() throws Exception { long dpid = 1L; // Create a 1.0 switch. There's no difference between 1.0 and 1.3 here. IOFSwitch sw = createMockSwitch(dpid, OFVersion.OF_10); IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class); controller.addOFSwitchListener(listener); listener.switchActivatedEqual(dpid); replay(sw, listener); // nothing recorded controller.addConnectedSwitch(dpid, new OFChannelHandler(controller)); controller.addActivatedEqualSwitch(dpid, sw); verify(sw); controller.processUpdateQueueForTesting(); verify(listener); }