OFSwitchManager implements IOFSwitchManager, INewOFConnectionListener, IHAListener, IFloodlightModule, IOFSwitchService, IStoreListener<DatapathId> { @Override public IOFSwitch getActiveSwitch(DatapathId dpid) { IOFSwitchBackend sw = this.switches.get(dpid); if(sw != null && sw.getStatus().isVisible()) return sw; else return null; }  @Override void transitionToActive(); @Override void transitionToStandby(); @Override SwitchManagerCounters getCounters(); @Override synchronized void switchAdded(IOFSwitchBackend sw); @LogMessageDocs({ @LogMessageDoc(level="ERROR", message="Switch {switch} activated but was already active", explanation="A switch that was already activated was " + "activated again. This should not happen.", recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG ), @LogMessageDoc(level="WARN", message="New switch added {switch} for already-added switch {switch}", explanation="A switch with the same DPID as another switch " + "connected to the controller. This can be caused by " + "multiple switches configured with the same DPID, or " + "by a switch reconnected very quickly after " + "disconnecting.", recommendation="If this happens repeatedly, it is likely there " + "are switches with duplicate DPIDs on the network. " + "Reconfigure the appropriate switches. If it happens " + "very rarely, then it is likely this is a transient " + "network problem that can be ignored." ) }) @Override synchronized void switchStatusChanged(IOFSwitchBackend sw, SwitchStatus oldStatus, SwitchStatus newStatus); @Override synchronized void switchDisconnected(IOFSwitchBackend sw); @Override void handshakeDisconnected(DatapathId dpid); Iterable<IOFSwitch> getActiveSwitches(); Map<DatapathId, IOFSwitch> getAllSwitchMap(boolean showInvisible); @Override Map<DatapathId, IOFSwitch> getAllSwitchMap(); @Override Set<DatapathId> getAllSwitchDpids(); Set<DatapathId> getAllSwitchDpids(boolean showInvisible); @Override IOFSwitch getSwitch(DatapathId dpid); @Override IOFSwitch getActiveSwitch(DatapathId dpid); @Override void connectionOpened(IOFConnectionBackend connection, OFFeaturesReply featuresReply); @Override void addSwitchEvent(DatapathId dpid, String reason, boolean flushNow); @Override synchronized void notifyPortChanged(IOFSwitchBackend sw,
			OFPortDesc port,
			PortChangeType changeType); @Override IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection,
			SwitchDescription description,
			OFFactory factory, DatapathId datapathId); @Override void handleMessage(IOFSwitchBackend sw, OFMessage m, FloodlightContext bContext); @Override void addOFSwitchDriver(String manufacturerDescriptionPrefix,
			IOFSwitchDriver driver); @Override ImmutableList<OFSwitchHandshakeHandler> getSwitchHandshakeHandlers(); @Override int getNumRequiredConnections(); Set<LogicalOFMessageCategory> getLogicalOFMessageCategories(); @Override void addOFSwitchListener(IOFSwitchListener listener); @Override void removeOFSwitchListener(IOFSwitchListener listener); @Override void registerLogicalOFMessageCategory(LogicalOFMessageCategory category); @Override boolean isCategoryRegistered(LogicalOFMessageCategory category); @Override SwitchRepresentation getSwitchRepresentation(DatapathId dpid); @Override List<SwitchRepresentation> getSwitchRepresentations(); @Override void registerHandshakePlugin(IAppHandshakePluginFactory factory); @Override List<IAppHandshakePluginFactory> getHandshakePlugins(); @Override Collection<Class<? extends IFloodlightService>> getModuleServices(); @Override Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls(); @Override Collection<Class<? extends IFloodlightService>> getModuleDependencies(); @Override void init(FloodlightModuleContext context); @Override void startUp(FloodlightModuleContext context); void startUpBase(FloodlightModuleContext context); void bootstrapNetty(); void loadLogicalCategories(); @Override String getName(); @Override boolean isCallbackOrderingPrereq(HAListenerTypeMarker type, String name); @Override boolean isCallbackOrderingPostreq(HAListenerTypeMarker type, String name); @Override void controllerNodeIPsChanged(Map<String, String> curControllerNodeIPs,
			Map<String, String> addedControllerNodeIPs,
			Map<String, String> removedControllerNodeIPs); @Override void keysModified(Iterator<DatapathId> keys, UpdateType type); static final String SWITCH_SYNC_STORE_NAME; }
@Test public void testGetActiveSwitch() { MockOFConnection connection = new MockOFConnection(DATAPATH_ID_1, OFAuxId.MAIN); IOFSwitchBackend sw = new MockOFSwitchImpl(connection); sw.setStatus(SwitchStatus.HANDSHAKE); assertNull(switchManager.getActiveSwitch(DATAPATH_ID_1)); switchManager.switchAdded(sw); assertNull(switchManager.getActiveSwitch(DATAPATH_ID_1)); sw.setStatus(SwitchStatus.MASTER); assertEquals(sw, switchManager.getActiveSwitch(DATAPATH_ID_1)); sw.setStatus(SwitchStatus.QUARANTINED); assertNull(switchManager.getActiveSwitch(DATAPATH_ID_1)); sw.setStatus(SwitchStatus.SLAVE); assertEquals(sw, switchManager.getActiveSwitch(DATAPATH_ID_1)); sw.setStatus(SwitchStatus.DISCONNECTED); assertNull(switchManager.getActiveSwitch(DATAPATH_ID_1)); controller.processUpdateQueueForTesting(); }