Minor refactoring of the Shortest Path computation mechanism
that uses prefetching of the topology: return the prefetched
info as a handler to the caller and pass it as an argument
to follow-up calls.
diff --git a/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java b/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java
index ecf217e..f217c25 100644
--- a/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java
+++ b/src/main/java/net/floodlightcontroller/core/INetMapTopologyService.java
@@ -1,6 +1,7 @@
package net.floodlightcontroller.core;
import java.util.List;
+import java.util.Map;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject;
@@ -47,7 +48,7 @@
/**
* Fetch the Switch and Ports info from the Titan Graph
- * and store it locally for fast access during the shortest path
+ * and return it for fast access during the shortest path
* computation.
*
* After fetching the state, method @ref getTopoShortestPath()
@@ -63,14 +64,17 @@
* method @ref dropShortestPathTopo() should be used to release
* the internal state that is not needed anymore:
*
- * prepareShortestPathTopo();
+ * Map<Long, ?> shortestPathTopo;
+ * shortestPathTopo = prepareShortestPathTopo();
* for (int i = 0; i < 10000; i++) {
- * dataPath = getTopoShortestPath(...);
+ * dataPath = getTopoShortestPath(shortestPathTopo, ...);
* ...
* }
- * dropShortestPathTopo();
+ * dropShortestPathTopo(shortestPathTopo);
+ *
+ * @return the Shortest Path info handler stored in a map.
*/
- void prepareShortestPathTopo();
+ Map<Long, ?> prepareShortestPathTopo();
/**
* Release the state that was populated by
@@ -78,8 +82,10 @@
*
* See the documentation for method @ref prepareShortestPathTopo()
* for additional information and usage.
+ *
+ * @shortestPathTopo the Shortest Path info handler to release.
*/
- void dropShortestPathTopo();
+ void dropShortestPathTopo(Map<Long, ?> shortestPathTopo);
/**
* Get the shortest path from a source to a destination by
@@ -89,12 +95,15 @@
* See the documentation for method @ref prepareShortestPathTopo()
* for additional information and usage.
*
+ * @paran shortestPathTopoHandler the Shortest Path info handler
+ * to use.
* @param src the source in the shortest path computation.
* @param dest the destination in the shortest path computation.
* @return the data path with the computed shortest path if
* found, otherwise null.
*/
- DataPath getTopoShortestPath(SwitchPort src, SwitchPort dest);
+ DataPath getTopoShortestPath(Map<Long, ?> shortestPathTopo,
+ SwitchPort src, SwitchPort dest);
/**
* Test whether a route exists from a source to a destination.
diff --git a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
index 57c136c..1020eab 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
@@ -98,6 +98,7 @@
private LinkedList<FlowPath> measurementStoredPaths = new LinkedList<FlowPath>();
private long measurementStartTimeProcessingPaths = 0;
private long measurementEndTimeProcessingPaths = 0;
+ Map<Long, ?> measurementShortestPathTopo = null;
/** The logger. */
private static Logger log = LoggerFactory.getLogger(FlowManager.class);
@@ -277,7 +278,8 @@
// Fetch and recompute the Shortest Path for those
// Flow Paths this controller is responsible for.
//
- topoRouteService.prepareShortestPathTopo();
+ Map<Long, ?> shortestPathTopo =
+ topoRouteService.prepareShortestPathTopo();
Iterable<IFlowPath> allFlowPaths = conn.utils().getAllFlowPaths(conn);
for (IFlowPath flowPathObj : allFlowPaths) {
counterAllFlowPaths++;
@@ -352,7 +354,8 @@
// to avoid closing the transaction.
//
DataPath dataPath =
- topoRouteService.getTopoShortestPath(srcSwitchPort,
+ topoRouteService.getTopoShortestPath(shortestPathTopo,
+ srcSwitchPort,
dstSwitchPort);
if (dataPath == null) {
// We need the DataPath to compare the paths
@@ -377,7 +380,7 @@
conn.utils().removeFlowPath(conn, flowPathObj);
}
- topoRouteService.dropShortestPathTopo();
+ topoRouteService.dropShortestPathTopo(shortestPathTopo);
conn.endTx(Transaction.COMMIT);
@@ -1891,13 +1894,14 @@
// Prepare the Shortest Path computation if the first Flow Path
//
if (measurementStoredPaths.isEmpty())
- topoRouteService.prepareShortestPathTopo();
+ measurementShortestPathTopo = topoRouteService.prepareShortestPathTopo();
//
// Compute the Shortest Path
//
DataPath dataPath =
- topoRouteService.getTopoShortestPath(flowPath.dataPath().srcPort(),
+ topoRouteService.getTopoShortestPath(measurementShortestPathTopo,
+ flowPath.dataPath().srcPort(),
flowPath.dataPath().dstPort());
if (dataPath == null) {
// We need the DataPath to populate the Network MAP
@@ -2030,7 +2034,7 @@
@Override
public boolean measurementClearAllPaths() {
measurementStoredPaths.clear();
- topoRouteService.dropShortestPathTopo();
+ topoRouteService.dropShortestPathTopo(measurementShortestPathTopo);
measurementStartTimeProcessingPaths = 0;
measurementEndTimeProcessingPaths = 0;
diff --git a/src/main/java/net/floodlightcontroller/routing/TopoRouteService.java b/src/main/java/net/floodlightcontroller/routing/TopoRouteService.java
index 95a3b19..1e002aa 100644
--- a/src/main/java/net/floodlightcontroller/routing/TopoRouteService.java
+++ b/src/main/java/net/floodlightcontroller/routing/TopoRouteService.java
@@ -101,14 +101,6 @@
GraphDBConnection conn;
- //
- // Topology state for storing (on demand) Switch and Ports info for
- // fast access during the shortest path computation.
- // It is explicitly populated by method @ref prepareShortestPathTopo().
- // See the documentation for that method for details.
- //
- HashMap<Long, Node> shortestPathTopo;
-
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Collection<Class<? extends IFloodlightService>> l =
@@ -168,7 +160,7 @@
/**
* Fetch the Switch and Ports info from the Titan Graph
- * and store it locally for fast access during the shortest path
+ * and return it for fast access during the shortest path
* computation.
*
* After fetching the state, method @ref getTopoShortestPath()
@@ -184,16 +176,18 @@
* method @ref dropShortestPathTopo() should be used to release
* the internal state that is not needed anymore:
*
- * prepareShortestPathTopo();
+ * Map<Long, ?> shortestPathTopo;
+ * shortestPathTopo = prepareShortestPathTopo();
* for (int i = 0; i < 10000; i++) {
- * dataPath = getTopoShortestPath(...);
+ * dataPath = getTopoShortestPath(shortestPathTopo, ...);
* ...
* }
- * dropShortestPathTopo();
+ * dropShortestPathTopo(shortestPathTopo);
+ *
+ * @return the Shortest Path info handler stored in a map.
*/
-
- public void prepareShortestPathTopo() {
- shortestPathTopo = new HashMap<Long, Node>();
+ public Map<Long, ?> prepareShortestPathTopo() {
+ Map<Long, Node> shortestPathTopo = new HashMap<Long, Node>();
//
// Fetch the relevant info from the Switch and Port vertices
@@ -260,6 +254,8 @@
}
}
conn.endTx(Transaction.COMMIT);
+
+ return shortestPathTopo;
}
/**
@@ -268,9 +264,10 @@
*
* See the documentation for method @ref prepareShortestPathTopo()
* for additional information and usage.
+ *
+ * @shortestPathTopo the Shortest Path info handler to release.
*/
-
- public void dropShortestPathTopo() {
+ public void dropShortestPathTopo(Map<Long, ?> shortestPathTopo) {
shortestPathTopo = null;
}
@@ -282,13 +279,17 @@
* See the documentation for method @ref prepareShortestPathTopo()
* for additional information and usage.
*
+ * @param shortestPathTopoHandler the Shortest Path info handler
+ * to use.
* @param src the source in the shortest path computation.
* @param dest the destination in the shortest path computation.
* @return the data path with the computed shortest path if
* found, otherwise null.
*/
-
- public DataPath getTopoShortestPath(SwitchPort src, SwitchPort dest) {
+ public DataPath getTopoShortestPath(Map<Long, ?> shortestPathTopoHandler,
+ SwitchPort src, SwitchPort dest) {
+ @SuppressWarnings("unchecked")
+ Map<Long, Node> shortestPathTopo = (Map)shortestPathTopoHandler;
DataPath result_data_path = new DataPath();
// Initialize the source and destination in the data path to return