Refactoring:
* Moved method FlowEntry.isSameDataPath() to
TopologyManager.isSameFlowEntryDataPath()
* Added new method TopologyManager.computeNetworkPath() that
computes the appropriate network path based on the Flow Path type.
* Edit some of the comments inside class PathComputation, so they
are not shortest-path specific anymore.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PathComputation.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PathComputation.java
index d840353..661fab1 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PathComputation.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PathComputation.java
@@ -15,6 +15,7 @@
import net.onrc.onos.ofcontroller.topology.ShortestPath;
import net.onrc.onos.ofcontroller.topology.Topology;
import net.onrc.onos.ofcontroller.topology.TopologyElement;
+import net.onrc.onos.ofcontroller.topology.TopologyManager;
import net.onrc.onos.ofcontroller.util.DataPath;
import net.onrc.onos.ofcontroller.util.EventEntry;
import net.onrc.onos.ofcontroller.util.FlowEntry;
@@ -239,7 +240,11 @@
modifiedFlowPaths.add(flowPath);
}
- // TODO: Implement the rest: push the Flow Entries from modifiedFlowPaths!
+ //
+ // Push the Flow Entries that have been modified
+ //
+ // TODO: Uncomment the following to enable pushing of flow entries
+ // flowManager.pushModifiedFlowEntries(modifiedFlowPaths);
// Cleanup
topologyEvents.clear();
@@ -267,11 +272,9 @@
DataPath oldDataPath = flowPath.dataPath();
- // Compute the new shortest path
- DataPath newDataPath =
- ShortestPath.getTopologyShortestPath(topology,
- flowPath.dataPath().srcPort(),
- flowPath.dataPath().dstPort());
+ // Compute the new path
+ DataPath newDataPath = TopologyManager.computeNetworkPath(topology,
+ flowPath);
if (newDataPath == null) {
// We need the DataPath to compare the paths
newDataPath = new DataPath();
@@ -279,7 +282,7 @@
newDataPath.applyFlowPathFlags(flowPath.flowPathFlags());
//
- // Test whether the shortest path is same
+ // Test whether the new path is same
//
if (oldDataPath.flowEntries().size() !=
newDataPath.flowEntries().size()) {
@@ -290,7 +293,8 @@
while (oldIter.hasNext() && newIter.hasNext()) {
FlowEntry oldFlowEntry = oldIter.next();
FlowEntry newFlowEntry = newIter.next();
- if (! newFlowEntry.isSameDataPath(oldFlowEntry)) {
+ if (! TopologyManager.isSameFlowEntryDataPath(oldFlowEntry,
+ newFlowEntry)) {
hasChanged = true;
break;
}
@@ -300,7 +304,7 @@
return hasChanged;
//
- // Merge the changes in the shortest path:
+ // Merge the changes in the path:
// - If a Flow Entry for a switch is in the old data path, but not
// in the new data path, then mark it for deletion.
// - If a Flow Entry for a switch is in the new data path, but not
@@ -348,7 +352,8 @@
oldFlowEntriesMap.get(newFlowEntry.dpid().value());
if ((oldFlowEntry != null) &&
- newFlowEntry.isSameDataPath(oldFlowEntry)) {
+ TopologyManager.isSameFlowEntryDataPath(oldFlowEntry,
+ newFlowEntry)) {
//
// Both Flow Entries are same
//
diff --git a/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java b/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java
index ccb64f8..ffe806a 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java
@@ -15,6 +15,9 @@
import net.onrc.onos.graph.GraphDBOperation;
import net.onrc.onos.ofcontroller.floodlightlistener.INetworkGraphService;
import net.onrc.onos.ofcontroller.util.DataPath;
+import net.onrc.onos.ofcontroller.util.FlowEntry;
+import net.onrc.onos.ofcontroller.util.FlowPath;
+import net.onrc.onos.ofcontroller.util.Port;
import net.onrc.onos.ofcontroller.util.SwitchPort;
import org.slf4j.Logger;
@@ -202,6 +205,80 @@
}
/**
+ * Compute the network path for a Flow.
+ *
+ * @param topology the topology handler to use.
+ * @param flowPath the Flow to compute the network path for.
+ * @return the data path with the computed path if found, otherwise null.
+ */
+ public static DataPath computeNetworkPath(Topology topology,
+ FlowPath flowPath) {
+ //
+ // Compute the network path based on the desired Flow Path type
+ //
+ switch (flowPath.flowPathType()) {
+ case FP_TYPE_SHORTEST_PATH: {
+ SwitchPort src = flowPath.dataPath().srcPort();
+ SwitchPort dest = flowPath.dataPath().dstPort();
+ return ShortestPath.getTopologyShortestPath(topology, src, dest);
+ }
+ case FP_TYPE_EXPLICIT_PATH:
+ return flowPath.dataPath();
+ }
+
+ return null;
+ }
+
+ /**
+ * Test whether two Flow Entries represent same points in a data path.
+ *
+ * NOTE: Two Flow Entries represent same points in a data path if
+ * the Switch DPID, incoming port and outgoing port are same.
+ *
+ * NOTE: This method is specialized for shortest-path unicast paths,
+ * and probably should be moved somewhere else.
+ *
+ * @param oldFlowEntry the first Flow Entry to compare.
+ * @param newFlowEntry the second Flow Entry to compare.
+ * @return true if the two Flow Entries represent same points in a
+ * data path, otherwise false.
+ */
+ public static boolean isSameFlowEntryDataPath(FlowEntry oldFlowEntry,
+ FlowEntry newFlowEntry) {
+ // Test the DPID
+ if (oldFlowEntry.dpid().value() != newFlowEntry.dpid().value())
+ return false;
+
+ // Test the inPort
+ do {
+ Port oldPort = oldFlowEntry.inPort();
+ Port newPort = newFlowEntry.inPort();
+ if ((oldPort != null) && (newPort != null) &&
+ (oldPort.value() == newPort.value())) {
+ break;
+ }
+ if ((oldPort == null) && (newPort == null))
+ break;
+ return false; // inPort is different
+ } while (false);
+
+ // Test the outPort
+ do {
+ Port oldPort = oldFlowEntry.outPort();
+ Port newPort = newFlowEntry.outPort();
+ if ((oldPort != null) && (newPort != null) &&
+ (oldPort.value() == newPort.value())) {
+ break;
+ }
+ if ((oldPort == null) && (newPort == null))
+ break;
+ return false; // outPort is different
+ } while (false);
+
+ return true;
+ }
+
+ /**
* Get the shortest path from a source to a destination by
* using the pre-populated local topology state prepared
* by method @ref newDatabaseTopology().
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java
index 29f3ceb..762d272 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/FlowEntry.java
@@ -315,50 +315,6 @@
}
/**
- * Test whether two Flow Entries represent same points in a data path.
- *
- * NOTE: Two Flow Entries represent same points in a data path if
- * the Switch DPID, incoming port and outgoing port are same.
- *
- * @param otherFlowEntry the other Flow Entry to compare with.
- * @return true if the two Flow Entries represent same points in a
- * data path, otherwise false.
- */
- public boolean isSameDataPath(FlowEntry otherFlowEntry) {
- // Test the DPID
- if (this.dpid.value() != otherFlowEntry.dpid().value())
- return false;
-
- // Test the inPort
- do {
- Port oldPort = this.inPort;
- Port newPort = otherFlowEntry.inPort();
- if ((oldPort != null) && (newPort != null) &&
- (oldPort.value() == newPort.value())) {
- break;
- }
- if ((oldPort == null) && (newPort == null))
- break;
- return false; // inPort is different
- } while (false);
-
- // Test the outPort
- do {
- Port oldPort = this.outPort;
- Port newPort = otherFlowEntry.outPort();
- if ((oldPort != null) && (newPort != null) &&
- (oldPort.value() == newPort.value())) {
- break;
- }
- if ((oldPort == null) && (newPort == null))
- break;
- return false; // outPort is different
- } while (false);
-
- return true;
- }
-
- /**
* Convert the flow entry to a string.
*
* The string has the following form: