LinkDiscoveryManager implements IOFMessageListener,
IOFSwitchListener, IStorageSourceListener, ILinkDiscoveryService,
IFloodlightModule, IInfoProvider { @Override public void switchAdded(DatapathId switchId) { }  @Override OFPacketOut generateLLDPMessage(DatapathId sw, OFPort port,
			boolean isStandard, boolean isReverse); int getLldpFrequency(); int getLldpTimeout(); @Override Map<NodePortTuple, Set<Link>> getPortLinks(); @Override Set<NodePortTuple> getSuppressLLDPsInfo(); @Override void AddToSuppressLLDPs(DatapathId sw, OFPort port); @Override void RemoveFromSuppressLLDPs(DatapathId sw, OFPort port); boolean isShuttingDown(); @Override boolean isTunnelPort(DatapathId sw, OFPort port); @Override ILinkDiscovery.LinkType getLinkType(Link lt, LinkInfo info); @Override Set<OFPort> getQuarantinedPorts(DatapathId sw); @Override Map<DatapathId, Set<Link>> getSwitchLinks(); @Override void addMACToIgnoreList(MacAddress mac, int ignoreBits); @Override boolean isAutoPortFastFeature(); @Override void setAutoPortFastFeature(boolean autoPortFastFeature); @Override void addListener(ILinkDiscoveryListener listener); @Override Map<Link, LinkInfo> getLinks(); @Override LinkInfo getLinkInfo(Link link); @Override String getName(); @Override Command receive(IOFSwitch sw, OFMessage msg,
			FloodlightContext cntx); @Override boolean isCallbackOrderingPrereq(OFType type, String name); @Override boolean isCallbackOrderingPostreq(OFType type, String name); @Override void switchPortChanged(DatapathId switchId,
			OFPortDesc port,
			PortChangeType type); @Override void switchAdded(DatapathId switchId); @Override void switchRemoved(DatapathId sw); @Override void switchActivated(DatapathId switchId); @Override void switchChanged(DatapathId switchId); void setStorageSource(IStorageSourceService storageSourceService); IStorageSourceService getStorageSource(); @Override void rowsModified(String tableName, Set<Object> rowKeys); @Override void rowsDeleted(String tableName, Set<Object> rowKeys); Long readLinkValidTime(Link lt); @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 @LogMessageDocs({ @LogMessageDoc(level = "ERROR", message = "No storage source found.", explanation = "Storage source was not initialized; cannot initialize " + "link discovery.", recommendation = LogMessageDoc.REPORT_CONTROLLER_BUG), @LogMessageDoc(level = "ERROR", message = "Error in installing listener for " + "switch config table {table}", explanation = "Failed to install storage notification for the " + "switch config table", recommendation = LogMessageDoc.REPORT_CONTROLLER_BUG), @LogMessageDoc(level = "ERROR", message = "No storage source found.", explanation = "Storage source was not initialized; cannot initialize " + "link discovery.", recommendation = LogMessageDoc.REPORT_CONTROLLER_BUG), @LogMessageDoc(level = "ERROR", message = "Exception in LLDP send timer.", explanation = "An unknown error occured while sending LLDP " + "messages to switches.", recommendation = LogMessageDoc.CHECK_SWITCH) }) void startUp(FloodlightModuleContext context); @Override Map<String, Object> getInfo(String type); static final String MODULE_NAME; }
@Test public void testSwitchAdded() throws Exception { LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); linkDiscovery.switchService = getMockSwitchService(); Capture<OFMessage> wc; Set<OFPort> qPorts; OFPortDesc ofpp = OFFactories.getFactory(OFVersion.OF_13).buildPortDesc() .setName("eth4242") .setPortNo(OFPort.of(4242)) .setHwAddr(MacAddress.of("5c:16:c7:00:00:01")) .setCurr(new HashSet<OFPortFeatures>()) .build(); IOFSwitch sw1 = createMockSwitch(1L); Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>(); switches.put(DatapathId.of(1L), sw1); getMockSwitchService().setSwitches(switches); List<OFPort> ports = new ArrayList<OFPort>(); for(short p=1; p<=20; ++p) { ports.add(OFPort.of(p)); } wc = new Capture<OFMessage>(CaptureType.ALL); expect(sw1.getEnabledPortNumbers()).andReturn(ports).anyTimes(); expect(sw1.getPort(OFPort.of(EasyMock.anyInt()))).andReturn(ofpp).anyTimes(); expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes(); sw1.write(capture(wc)); expectLastCall().anyTimes(); replay(sw1); linkDiscovery.switchActivated(sw1.getId()); verify(sw1); qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId()); assertNotNull(qPorts); assertFalse(qPorts.isEmpty()); Thread.sleep(100); qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId()); assertNotNull(qPorts); assertFalse(qPorts.isEmpty()); Thread.sleep(200); qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId()); assertNotNull(qPorts); assertTrue(qPorts.isEmpty()); assertTrue(wc.hasCaptured()); List<OFMessage> msgList = wc.getValues(); assertTrue(msgList.size() == ports.size() * 2); }