Naoki's Periodic whole topology read code, simply adapted to RC
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
index 8b1f7c0..a9a6f0c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
@@ -8,6 +8,8 @@
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.TreeMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -47,6 +49,14 @@
/** The logger. */
private final static Logger log = LoggerFactory.getLogger(FlowEventHandler.class);
+ // Flag to refresh Topology object periodically
+ private final static boolean refreshTopology = true;
+ // Refresh delay(ms)
+ private final static long refreshTopologyDelay = 5000;
+ // Refresh interval(ms)
+ private final static long refreshTopologyInterval = 1000;
+ private Timer refreshTopologyTimer;
+
private FlowManager flowManager; // The Flow Manager to use
private IDatagridService datagridService; // The Datagrid Service to use
private Topology topology; // The network topology
@@ -141,6 +151,24 @@
synchronized (allFlowPaths) {
processEvents();
}
+
+ if (refreshTopology) {
+ refreshTopologyTimer = new Timer();
+ refreshTopologyTimer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ log.debug("[BEFORE] {}", topology.toString());
+ long begin, end;
+ synchronized(topology) {
+ begin = System.nanoTime();
+ topology.readFromDatabase(flowManager.dbHandlerInner);
+ end = System.nanoTime();
+ }
+ log.debug("[AFTER] {}", topology.toString());
+ log.debug("refresh takes : {}[us]", (end - begin) / 1000.0);
+ }
+ }, refreshTopologyDelay, refreshTopologyInterval);
+ }
}
/**
@@ -443,10 +471,14 @@
switch (eventEntry.eventType()) {
case ENTRY_ADD:
- isTopologyModified |= topology.addTopologyElement(topologyElement);
+ synchronized (topology) {
+ isTopologyModified |= topology.addTopologyElement(topologyElement);
+ }
break;
case ENTRY_REMOVE:
- isTopologyModified |= topology.removeTopologyElement(topologyElement);
+ synchronized (topology) {
+ isTopologyModified |= topology.removeTopologyElement(topologyElement);
+ }
break;
}
}
@@ -730,8 +762,12 @@
DataPath oldDataPath = flowPath.dataPath();
// Compute the new path
- DataPath newDataPath = TopologyManager.computeNetworkPath(topology,
+ DataPath newDataPath;
+ synchronized (topology) {
+ newDataPath = TopologyManager.computeNetworkPath(topology,
flowPath);
+ }
+
if (newDataPath == null) {
// We need the DataPath to compare the paths
newDataPath = new DataPath();
diff --git a/src/main/java/net/onrc/onos/ofcontroller/topology/Topology.java b/src/main/java/net/onrc/onos/ofcontroller/topology/Topology.java
index 761189c..98a517c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/Topology.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/Topology.java
@@ -1,11 +1,11 @@
package net.onrc.onos.ofcontroller.topology;
-import java.util.List;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
@@ -13,7 +13,6 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
-import net.onrc.onos.graph.DBOperation;
/**
* A class for storing Node and Link information for fast computation
@@ -452,4 +451,20 @@
}
dbHandler.commit();
}
+
+ // Only for debug use
+ @Override
+ public String toString() {
+ long numNodes = nodesMap.size();
+ long numLinks = 0;
+ for (Map.Entry<Long, Node> entry : nodesMap.entrySet()) {
+ Node n = entry.getValue();
+ for (Map.Entry<Integer, Node.Link> linkEntry : n.links.entrySet()) {
+ if (n.nodeId > linkEntry.getValue().neighbor.nodeId) {
+ ++numLinks;
+ }
+ }
+ }
+ return "Topology has " + numNodes + " Nodes and " + numLinks + " Links.";
+ }
}