Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS
diff --git a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
index c562556..59e6f46 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
@@ -131,14 +131,9 @@
 		//
 		boolean processed_measurement_flow = false;
 		Iterable<IFlowEntry> allFlowEntries =
-		    conn.utils().getAllFlowEntries(conn);
+		    conn.utils().getAllSwitchNotUpdatedFlowEntries(conn);
 		for (IFlowEntry flowEntryObj : allFlowEntries) {
 		    counterAllFlowEntries++;
-		    String switchState = flowEntryObj.getSwitchState();
-		    if ((switchState == null) ||
-			(! switchState.equals("FE_SWITCH_NOT_UPDATED"))) {
-			continue;	// Ignore the entry: nothing to do
-		    }
 
 		    String dpidStr = flowEntryObj.getSwitchDpid();
 		    if (dpidStr == null)
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 4d23b0d..d5fe4c6 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -68,6 +68,10 @@
 		        	graph.createKeyIndex("flow_entry_id",
 						     Vertex.class);
 		        }
+		        if (!s.contains("switch_state")) {
+		        	graph.createKeyIndex("switch_state",
+						     Vertex.class);
+		        }
 		        graph.stopTransaction(Conclusion.SUCCESS);
 		        eg = new EventTransactionalGraph<TitanGraph>(graph);
 		   }		   
diff --git a/src/main/java/net/onrc/onos/util/GraphDBUtils.java b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
index 7ed51b9..2dac008 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
@@ -194,6 +194,13 @@
 		
 		return fg.getVertices("type", "flow_entry", IFlowEntry.class);
 	}
+	
+	@Override
+	public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries(GraphDBConnection conn) {
+		FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+		//TODO: Should use an enum for flow_switch_state
+		return fg.getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", IFlowEntry.class);
+	}
 
 	@Override
 	public Iterable<ISwitchObject> getActiveSwitches(GraphDBConnection conn) {
diff --git a/src/main/java/net/onrc/onos/util/IDBUtils.java b/src/main/java/net/onrc/onos/util/IDBUtils.java
index 51948a2..4aa8168 100644
--- a/src/main/java/net/onrc/onos/util/IDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/IDBUtils.java
@@ -37,4 +37,6 @@
 	ISwitchObject newSwitch(GraphDBConnection conn);
 	void removePort(GraphDBConnection conn, IPortObject port);
 	void removeSwitch(GraphDBConnection conn, ISwitchObject sw);
+	Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries(
+			GraphDBConnection conn);
 }