LinkDiscoveryManager implements IOFMessageListener, IOFSwitchListener, 
IStorageSourceListener, ILinkDiscoveryService,
IFloodlightModule, IInfoProvider, IHAListener { protected boolean addOrUpdateLink(Link lt, LinkInfo newInfo) { NodePortTuple srcNpt, dstNpt; boolean linkChanged = false; lock.writeLock().lock(); try { LinkInfo oldInfo = links.put(lt, newInfo); if (oldInfo != null && oldInfo.getFirstSeenTime() < newInfo.getFirstSeenTime()) newInfo.setFirstSeenTime(oldInfo.getFirstSeenTime()); if (log.isTraceEnabled()) { log.trace("addOrUpdateLink: {} {}", lt, (newInfo.getMulticastValidTime()!=null) ? "multicast" : "unicast"); } UpdateOperation updateOperation = null; linkChanged = false; srcNpt = new NodePortTuple(lt.getSrc(), lt.getSrcPort()); dstNpt = new NodePortTuple(lt.getDst(), lt.getDstPort()); if (oldInfo == null) { if (!switchLinks.containsKey(lt.getSrc())) switchLinks.put(lt.getSrc(), new HashSet<Link>()); switchLinks.get(lt.getSrc()).add(lt); if (!switchLinks.containsKey(lt.getDst())) switchLinks.put(lt.getDst(), new HashSet<Link>()); switchLinks.get(lt.getDst()).add(lt); if (!portLinks.containsKey(srcNpt)) portLinks.put(srcNpt, new HashSet<Link>()); portLinks.get(srcNpt).add(lt); if (!portLinks.containsKey(dstNpt)) portLinks.put(dstNpt, new HashSet<Link>()); portLinks.get(dstNpt).add(lt); if (newInfo.getUnicastValidTime() == null) addLinkToBroadcastDomain(lt); writeLinkToStorage(lt, newInfo); updateOperation = UpdateOperation.LINK_UPDATED; linkChanged = true; evHistTopoLink(lt.getSrc(), lt.getDst(), lt.getSrcPort(), lt.getDstPort(), newInfo.getSrcPortState(), newInfo.getDstPortState(), getLinkType(lt, newInfo), EvAction.LINK_ADDED, "LLDP Recvd"); } else { if (newInfo.getUnicastValidTime() == null) { if (oldInfo.getUnicastValidTime() != null) { newInfo.setUnicastValidTime(oldInfo.getUnicastValidTime()); } } else if (newInfo.getMulticastValidTime() == null) { if (oldInfo.getMulticastValidTime() != null) { newInfo.setMulticastValidTime(oldInfo.getMulticastValidTime()); } } Long oldTime = oldInfo.getUnicastValidTime(); Long newTime = newInfo.getUnicastValidTime(); if (oldTime != null & newTime == null) { addLinkToBroadcastDomain(lt); linkChanged = true; } else if (oldTime == null & newTime != null) { removeLinkFromBroadcastDomain(lt); linkChanged = true; } if (newInfo.getSrcPortState().intValue() != oldInfo.getSrcPortState().intValue() || newInfo.getDstPortState().intValue() != oldInfo.getDstPortState().intValue()) linkChanged = true; writeLinkToStorage(lt, newInfo); if (linkChanged) { updateOperation = getUpdateOperation(newInfo.getSrcPortState(), newInfo.getDstPortState()); if (log.isTraceEnabled()) { log.trace("Updated link {}", lt); } evHistTopoLink(lt.getSrc(), lt.getDst(), lt.getSrcPort(), lt.getDstPort(), newInfo.getSrcPortState(), newInfo.getDstPortState(), getLinkType(lt, newInfo), EvAction.LINK_PORT_STATE_UPDATED, "LLDP Recvd"); } } if (linkChanged) { updates.add(new LDUpdate(lt.getSrc(), lt.getSrcPort(), lt.getDst(), lt.getDstPort(), getLinkType(lt, newInfo), updateOperation)); } } finally { lock.writeLock().unlock(); } return linkChanged; }  int getLldpFrequency(); int getLldpTimeout(); Map<NodePortTuple, Set<Link>> getPortLinks(); Set<NodePortTuple> getSuppressLLDPsInfo(); void AddToSuppressLLDPs(long sw, short port); void RemoveFromSuppressLLDPs(long sw, short port); boolean isShuttingDown(); boolean isFastPort(long sw, short port); ILinkDiscovery.LinkType getLinkType(Link lt, LinkInfo info); Set<Short> getQuarantinedPorts(long sw); @Override String getName(); @Override Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx); Map<Long, Set<Link>> getSwitchLinks(); @Override void addedSwitch(IOFSwitch sw); @Override void removedSwitch(IOFSwitch iofSwitch); @Override void switchPortChanged(Long switchId); Map<NodePortTuple, Set<Link>> getPortBroadcastDomainLinks(); @Override Map<Link, LinkInfo> getLinks(); Long readLinkValidTime(Link lt); @Override void addListener(ILinkDiscoveryListener listener); void addLinkDiscoveryAware(ILinkDiscoveryListener linkDiscoveryAwareComponent); void removeLinkDiscoveryAware(ILinkDiscoveryListener linkDiscoveryAwareComponent); void setStorageSource(IStorageSourceService storageSource); IStorageSourceService getStorageSource(); @Override boolean isCallbackOrderingPrereq(OFType type, String name); @Override boolean isCallbackOrderingPostreq(OFType type, String name); @Override void rowsModified(String tableName, Set<Object> rowKeys); @Override void rowsDeleted(String tableName, Set<Object> rowKeys); @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); void evHistTopoCluster(long dpid, long clusterIdOld,
                                  long clusterIdNew, EvAction action, String reason); @Override Map<String, Object> getInfo(String type); @Override void roleChanged(Role oldRole, Role newRole); @Override void controllerNodeIPsChanged(
                                         Map<String, String> curControllerNodeIPs,
                                         Map<String, String> addedControllerNodeIPs,
                                         Map<String, String> removedControllerNodeIPs); boolean isAutoPortFastFeature(); void setAutoPortFastFeature(boolean autoPortFastFeature); public EventHistory<EventHistoryTopologySwitch> evHistTopologySwitch; public EventHistory<EventHistoryTopologyLink> evHistTopologyLink; public EventHistory<EventHistoryTopologyCluster> evHistTopologyCluster; public EventHistoryTopologySwitch evTopoSwitch; public EventHistoryTopologyLink evTopoLink; public EventHistoryTopologyCluster evTopoCluster; }
@Test public void testAddOrUpdateLink() throws Exception { LinkDiscoveryManager topology = getTopology(); Link lt = new Link(1L, 2, 2L, 1); LinkInfo info = new LinkInfo(System.currentTimeMillis(), System.currentTimeMillis(), null, 0, 0); topology.addOrUpdateLink(lt, info); NodePortTuple srcNpt = new NodePortTuple(1L, 2); NodePortTuple dstNpt = new NodePortTuple(2L, 1); assertNotNull(topology.switchLinks.get(lt.getSrc())); assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt)); assertNotNull(topology.portLinks.get(srcNpt)); assertTrue(topology.portLinks.get(srcNpt).contains(lt)); assertNotNull(topology.portLinks.get(dstNpt)); assertTrue(topology.portLinks.get(dstNpt).contains(lt)); assertTrue(topology.links.containsKey(lt)); }
@Test public void testAddOrUpdateLinkToSelf() throws Exception { LinkDiscoveryManager topology = getTopology(); Link lt = new Link(1L, 2, 2L, 3); NodePortTuple srcNpt = new NodePortTuple(1L, 2); NodePortTuple dstNpt = new NodePortTuple(2L, 3); LinkInfo info = new LinkInfo(System.currentTimeMillis(), System.currentTimeMillis(), null, 0, 0); topology.addOrUpdateLink(lt, info); assertNotNull(topology.switchLinks.get(lt.getSrc())); assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt)); assertNotNull(topology.portLinks.get(srcNpt)); assertTrue(topology.portLinks.get(srcNpt).contains(lt)); assertNotNull(topology.portLinks.get(dstNpt)); assertTrue(topology.portLinks.get(dstNpt).contains(lt)); assertTrue(topology.links.containsKey(lt)); }
@Test public void testHARoleChange() throws Exception { LinkDiscoveryManager topology = getTopology(); IOFSwitch sw1 = createMockSwitch(1L); IOFSwitch sw2 = createMockSwitch(2L); replay(sw1, sw2); Link lt = new Link(1L, 2, 2L, 1); NodePortTuple srcNpt = new NodePortTuple(1L, 2); NodePortTuple dstNpt = new NodePortTuple(2L, 1); LinkInfo info = new LinkInfo(System.currentTimeMillis(), System.currentTimeMillis(), null, 0, 0); topology.addOrUpdateLink(lt, info); assertNotNull(topology.switchLinks.get(lt.getSrc())); assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt)); assertNotNull(topology.portLinks.get(srcNpt)); assertTrue(topology.portLinks.get(srcNpt).contains(lt)); assertNotNull(topology.portLinks.get(dstNpt)); assertTrue(topology.portLinks.get(dstNpt).contains(lt)); assertTrue(topology.links.containsKey(lt)); getMockFloodlightProvider().dispatchRoleChanged(null, Role.SLAVE); assertTrue(topology.switchLinks.isEmpty()); getMockFloodlightProvider().dispatchRoleChanged(Role.SLAVE, Role.MASTER); assertTrue(ldm.isSendLLDPsCalled); assertTrue(ldm.isClearLinksCalled); ldm.reset(); }