From c0ae7278d7009434f5b660cae0636ba77b7a01e7 Mon Sep 17 00:00:00 2001 From: Kanzhe Jiang <kanzhe.jiang@bigswitch.com> Date: Mon, 4 Jun 2012 17:56:07 -0700 Subject: [PATCH] topology keeps a list of applied link updates. topologyAware modules can query updated links after getting topologyChanged event --- .../linkdiscovery/ILinkDiscovery.java | 16 ++++++++++ .../topology/ITopologyService.java | 8 +++++ .../topology/TopologyManager.java | 30 ++++++++++++++----- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java index 48c00f343..35dc6e084 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 5eda58bbe..96a729c38 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 189cc6c4e..54aafaa25 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(); } -- GitLab