* Added new method FlowDatabaseOperation.getFlowSourceDpid() that
  can be used to get the Source Switch DPID

* Added a boolean flag to FlowEventHandler and FlowManager to enable/disable
  the new Flow setup mechanism:
    enableOnrc2014MeasurementsFlows

* Create locally the FlowEventHandler.dbHandler instead of
  reusing the dbHandler from the FlowManager.
  Reusing the dbHandler from the FlowManager might not be thread-safe (??)

* Renamed flag FlowEventHandler.accessDBFlag
  to enableOnrc2014MeasurementsTopology
  (for consistency with the Flow setup-related flag)

* Changed the logic when reading the complete topology from the database:
  if there is a topology-related event, we unconditionally assume
  the topology has been modified. Long-term this might be sub-optimal,
  but gives us the bare-bones behavior we want to measure.

* Reverse the change to Topology.readFromDatabase() to exclude the
  compareTopology() call (see above bullet).

* Fix a bug when cheching whether there is any event to process.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
index e075bad..2cbadd6 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
@@ -464,6 +464,45 @@
     }
 
     /**
+     * Get the source switch DPID of a previously added flow.
+     *
+     * @param dbHandler the Graph Database handler to use.
+     * @param flowId the Flow ID of the flow to get.
+     * @return the source switch DPID if found, otherwise null.
+     */
+    static Dpid getFlowSourceDpid(GraphDBOperation dbHandler, FlowId flowId) {
+	IFlowPath flowObj = null;
+	try {
+	    flowObj = dbHandler.searchFlowPath(flowId);
+	} catch (Exception e) {
+	    // TODO: handle exceptions
+	    dbHandler.rollback();
+	    log.error(":getFlowSourceDpid FlowId:{} failed", flowId);
+	    return null;
+	}
+	if (flowObj == null) {
+	    dbHandler.commit();
+	    return null;		// Flow not found
+	}
+
+	//
+	// Extract the Flow Source DPID
+	//
+	String srcSwitchStr = flowObj.getSrcSwitch();
+	if (srcSwitchStr == null) {
+	    // TODO: A work-around, becauuse of some bogus database objects
+	    dbHandler.commit();
+	    return null;
+	}
+
+	Dpid dpid = new Dpid(srcSwitchStr);
+
+	dbHandler.commit();
+
+	return dpid;
+    }
+
+    /**
      * Get all installed flows by all installers.
      *
      * @param dbHandler the Graph Database handler to use.
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 4c801d6..9979664 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
@@ -45,12 +45,13 @@
  * - Recompute impacted FlowPath using cached Topology.
  */
 class FlowEventHandler extends Thread implements IFlowEventHandlerService {
+
+    private boolean enableOnrc2014MeasurementsFlows = false;
+    private boolean enableOnrc2014MeasurementsTopology = false;
+
     /** The logger. */
     private final static Logger log = LoggerFactory.getLogger(FlowEventHandler.class);
     
-    // Flag to enable feature of acquiring topology information from DB instead of datagrid.
-    private final boolean accessDBFlag = false;
-
     private GraphDBOperation dbHandler;
     private FlowManager flowManager;		// The Flow Manager to use
     private IDatagridService datagridService;	// The Datagrid Service to use
@@ -98,12 +99,10 @@
      * @param datagridService the Datagrid Service to use.
      */
     FlowEventHandler(FlowManager flowManager,
-		     IDatagridService datagridService,
-		     GraphDBOperation dbHandler) {
+		     IDatagridService datagridService) {
 	this.flowManager = flowManager;
 	this.datagridService = datagridService;
 	this.topology = new Topology();
-	this.dbHandler = dbHandler;
     }
 
     /**
@@ -117,6 +116,8 @@
      * Startup processing.
      */
     private void startup() {
+	this.dbHandler = new GraphDBOperation("");
+
 	//
 	// Obtain the initial Topology state
 	//
@@ -240,7 +241,7 @@
 	Collection<FlowEntry> modifiedFlowEntries;
 
 	if (topologyEvents.isEmpty() && flowPathEvents.isEmpty() &&
-	    flowEntryEvents.isEmpty()) {
+	    flowEntryEvents.isEmpty() && flowIdEvents.isEmpty()) {
 	    return;		// Nothing to do
 	}
 
@@ -501,11 +502,10 @@
 	// Process all Topology events and update the appropriate state
 	//
 	boolean isTopologyModified = false;
-	if (accessDBFlag) {
+	if (enableOnrc2014MeasurementsTopology) {
 		log.debug("[BEFORE] {}", topology.toString());
-		if (! topology.readFromDatabase(dbHandler)) {
-			isTopologyModified = true;
-		}
+		topology.readFromDatabase(dbHandler);
+		isTopologyModified = true;
 		log.debug("[AFTER] {}", topology.toString());
 	} else {
 		for (EventEntry<TopologyElement> eventEntry : topologyEvents) {
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index 388035a..2ac97b8 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -48,6 +48,9 @@
  * Flow Manager class for handling the network flows.
  */
 public class FlowManager implements IFloodlightModule, IFlowService, INetMapStorage {
+
+    private boolean enableOnrc2014MeasurementsFlows = false;
+
     protected GraphDBOperation dbHandlerApi;
     protected GraphDBOperation dbHandlerInner;
 
@@ -224,7 +227,7 @@
 	//  - register with the Datagrid Service
 	//  - startup
 	//
-	flowEventHandler = new FlowEventHandler(this, datagridService, dbHandlerInner);
+	flowEventHandler = new FlowEventHandler(this, datagridService);
 	datagridService.registerFlowEventHandlerService(flowEventHandler);
 	flowEventHandler.start();
     }
@@ -265,7 +268,12 @@
 	}
 
 	if (FlowDatabaseOperation.addFlow(dbHandlerApi, flowPath)) {
-	    datagridService.notificationSendFlowAdded(flowPath);
+	    if (enableOnrc2014MeasurementsFlows) {
+		datagridService.notificationSendFlowIdAdded(flowPath.flowId());
+	    } else {
+		datagridService.notificationSendFlowAdded(flowPath);
+	    }
+
 	    return flowPath.flowId();
 	}
 	return null;
@@ -279,7 +287,11 @@
     @Override
     public boolean deleteAllFlows() {
 	if (FlowDatabaseOperation.deleteAllFlows(dbHandlerApi)) {
-	    datagridService.notificationSendAllFlowsRemoved();
+	    if (enableOnrc2014MeasurementsFlows) {
+		datagridService.notificationSendAllFlowIdsRemoved();
+	    } else {
+		datagridService.notificationSendAllFlowsRemoved();
+	    }
 	    return true;
 	}
 	return false;
@@ -294,7 +306,11 @@
     @Override
     public boolean deleteFlow(FlowId flowId) {
 	if (FlowDatabaseOperation.deleteFlow(dbHandlerApi, flowId)) {
-	    datagridService.notificationSendFlowRemoved(flowId);
+	    if (enableOnrc2014MeasurementsFlows) {
+		datagridService.notificationSendFlowIdRemoved(flowId);
+	    } else {
+		datagridService.notificationSendFlowRemoved(flowId);
+	    }
 	    return true;
 	}
 	return false;
@@ -312,6 +328,16 @@
     }
 
     /**
+     * Get the source switch DPID of a previously added flow.
+     *
+     * @param flowId the Flow ID of the flow to get.
+     * @return the source switch DPID if found, otherwise null.
+     */
+    public Dpid getFlowSourceDpid(FlowId flowId) {
+	return FlowDatabaseOperation.getFlowSourceDpid(dbHandlerApi, flowId);
+    }
+
+    /**
      * Get all installed flows by all installers.
      *
      * @return the Flow Paths if found, otherwise null.
@@ -413,6 +439,9 @@
     public void flowEntriesPushedToSwitch(
 		Collection<Pair<IOFSwitch, FlowEntry>> entries) {
 
+	if (enableOnrc2014MeasurementsFlows)
+	    return;
+
 	//
 	// Process all entries
 	//
@@ -483,7 +512,9 @@
 	//
 	pushModifiedFlowEntriesToSwitches(modifiedFlowEntries);
 	pushModifiedFlowPathsToDatabase(modifiedFlowPaths);
-	cleanupDeletedFlowEntriesFromDatagrid(modifiedFlowEntries);
+	if (! enableOnrc2014MeasurementsFlows) {
+	    cleanupDeletedFlowEntriesFromDatagrid(modifiedFlowEntries);
+	}
     }
 
     /**
@@ -714,6 +745,11 @@
 		    } 
 		} while (retry);
 
+		if (enableOnrc2014MeasurementsFlows) {
+		    // Send the notification
+		    datagridService.notificationSendFlowIdRemoved(flowPath.flowId());
+		}
+
 		continue;
 	    }
 
@@ -730,10 +766,12 @@
 		    allValid = false;
 		    break;
 		}
-		if (flowEntry.flowEntrySwitchState() !=
-		    FlowEntrySwitchState.FE_SWITCH_UPDATED) {
-		    allValid = false;
-		    break;
+		if (! enableOnrc2014MeasurementsFlows) {
+		    if (flowEntry.flowEntrySwitchState() !=
+			FlowEntrySwitchState.FE_SWITCH_UPDATED) {
+			allValid = false;
+			break;
+		    }
 		}
 	    }
 	    if (! allValid)
@@ -759,6 +797,11 @@
 		    log.error("Exception writing Flow Path to Network MAP: ", e);
 		}
 	    } while (retry);
+
+	    if (enableOnrc2014MeasurementsFlows) {
+		// Send the notification
+		datagridService.notificationSendFlowIdAdded(flowPath.flowId());
+	    }
 	}
     }
 }
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 dedb589..92da9ba 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/Topology.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/Topology.java
@@ -381,17 +381,13 @@
      * Read topology state from the database.
      *
      * @param dbHandler the Graph Database handler to use.
-     * @return true if topology is updated. In other words,
-     * 		topology read from database is different from current topology.
      */
-    public boolean readFromDatabase(GraphDBOperation dbHandler) {
+    public void readFromDatabase(GraphDBOperation dbHandler) {
 	//
 	// Fetch the relevant info from the Switch and Port vertices
 	// from the Titan Graph.
 	//
-    
-	Map<Long,Node> oldNodesMap = nodesMap;
-	nodesMap = new TreeMap<Long,Node>();
+    	nodesMap = new TreeMap<Long,Node>();
 	
 	Iterable<ISwitchObject> activeSwitches = dbHandler.getActiveSwitches();
 	for (ISwitchObject switchObj : activeSwitches) {
@@ -456,7 +452,6 @@
 	    }
 	}
 	dbHandler.commit();
-	return ! compareTopology(oldNodesMap, nodesMap);
     }
     
     // TODO Merge into loops in readFromDatabase() can reduce execution time.