diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java index 48c00f343eaf20a354035f841eab600496ad7a2a..35dc6e084569c12fbe40d022cd3be02e656b5b8b 100644 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java +++ b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java @@ -36,6 +36,18 @@ public interface ILinkDiscovery { dstPortState, type, operation); } + public LDUpdate(LDUpdate old) { + this.src = old.src; + this.srcPort = old.srcPort; + this.srcPortState = old.srcPortState; + this.dst = old.dst; + this.dstPort = old.dstPort; + this.dstPortState = old.dstPortState; + this.srcType = old.srcType; + this.type = old.type; + this.operation = old.operation; + } + // For updtedSwitch(sw) public LDUpdate(long switchId, SwitchType stype) { this.operation = UpdateOperation.SWITCH_UPDATED; @@ -79,6 +91,10 @@ public interface ILinkDiscovery { return operation; } + public void setOperation(UpdateOperation operation) { + this.operation = operation; + } + @Override public String toString() { return "LDUpdate [src=" + src + ", srcPort=" + srcPort diff --git a/src/main/java/net/floodlightcontroller/topology/ITopologyService.java b/src/main/java/net/floodlightcontroller/topology/ITopologyService.java index 5eda58bbe936c1ec26acc9488d4bfa4eb98dfb69..96a729c3815b6b98eb0f1e3cee9efbeb4eecab80 100644 --- a/src/main/java/net/floodlightcontroller/topology/ITopologyService.java +++ b/src/main/java/net/floodlightcontroller/topology/ITopologyService.java @@ -3,6 +3,7 @@ package net.floodlightcontroller.topology; import java.util.Set; import net.floodlightcontroller.core.module.IFloodlightService; +import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LDUpdate; public interface ITopologyService extends IFloodlightService { @@ -182,4 +183,11 @@ public interface ITopologyService extends IFloodlightService { * @return */ public Set<NodePortTuple> getBlockedPorts(); + + /** + * Returns a set of link updates, which had been applied + * in computing the new topology. + * @return + */ + public Set<LDUpdate> getAppliedLinkUpdates(); } diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java index 189cc6c4e06d4e53fd15b027d13d1fbd17afe45b..54aafaa25b9a026a08243722cc28108ea5299f5e 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java @@ -83,13 +83,13 @@ public class TopologyManager implements protected ILinkDiscoveryService linkDiscovery; protected IThreadPoolService threadPool; protected IFloodlightProviderService floodlightProvider; - protected ICounterStoreService counterStore; protected IRestApiService restApi; // Modules that listen to our updates protected ArrayList<ITopologyListener> topologyAware; protected BlockingQueue<LDUpdate> ldUpdates; + protected Set<LDUpdate> appliedUpdates; protected TopologyInstance currentInstance; protected TopologyInstance currentInstanceWithoutTunnels; protected SingletonTask newInstanceTask; @@ -428,6 +428,10 @@ public class TopologyManager implements return blockedPorts; } + @Override + public Set<LDUpdate> getAppliedLinkUpdates() { + return appliedUpdates; + } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -580,8 +584,6 @@ public class TopologyManager implements threadPool = context.getServiceImpl(IThreadPoolService.class); floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); - counterStore = - context.getServiceImpl(ICounterStoreService.class); restApi = context.getServiceImpl(IRestApiService.class); switchPorts = new HashMap<Long,Set<Short>>(); @@ -590,7 +592,7 @@ public class TopologyManager implements tunnelLinks = new HashMap<NodePortTuple, Set<Link>>(); topologyAware = new ArrayList<ITopologyListener>(); ldUpdates = new LinkedBlockingQueue<LDUpdate>(); - + appliedUpdates = new HashSet<LDUpdate>(); } @Override @@ -779,10 +781,14 @@ public class TopologyManager implements public void applyUpdates() { + appliedUpdates.clear(); LDUpdate update = null; while (ldUpdates.peek() != null) { + boolean updateApplied = false; + LDUpdate newUpdate = null; try { update = ldUpdates.take(); + newUpdate = new LDUpdate(update); } catch (Exception e) { log.error("Error reading link discovery update.", e); } @@ -801,13 +807,23 @@ public class TopologyManager implements addOrUpdateLink(update.getSrc(), update.getSrcPort(), update.getDst(), update.getDstPort(), update.getType()); + updateApplied = true; } else { removeLink(update.getSrc(), update.getSrcPort(), update.getDst(), update.getDstPort()); + newUpdate = new LDUpdate(update); + // set the update operation to remove + newUpdate.setOperation(UpdateOperation.REMOVE); + updateApplied = true; } } else if (update.getOperation() == UpdateOperation.REMOVE) { removeLink(update.getSrc(), update.getSrcPort(), update.getDst(), update.getDstPort()); + updateApplied = true; + } + + if (updateApplied) { + appliedUpdates.add(newUpdate); } } } @@ -986,6 +1002,7 @@ public class TopologyManager implements switchPortLinks.clear(); portBroadcastDomainLinks.clear(); tunnelLinks.clear(); + appliedUpdates.clear(); } /** @@ -993,10 +1010,7 @@ public class TopologyManager implements * send out updates. */ private void clearCurrentTopology() { - switchPorts.clear(); - switchPortLinks.clear(); - portBroadcastDomainLinks.clear(); - tunnelLinks.clear(); + this.clear(); createNewInstance(); }