REST API for flow summary /wm/flow/getsummary/{0}/{0}/json
Check network map for missing link even on update link in link discovery to address issue 249
Only the master controller should delete links to address issue 249
diff --git a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
index 36d1059..a0c1635 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
@@ -8,6 +8,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.Collections;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -274,11 +275,13 @@
 		    String userState = flowEntryObj.getUserState();
 		    String switchState = flowEntryObj.getSwitchState();
 
+		    /**
 		    log.debug("Found Flow Entry {}: {}",
 			      flowEntryId.toString(),
 			      "User State: " + userState +
 			      " Switch State: " + switchState);
-
+		     */
+		    
 		    if (! switchState.equals("FE_SWITCH_NOT_UPDATED")) {
 			// Ignore the entry: nothing to do
 			continue;
@@ -956,6 +959,61 @@
     }
 
     /**
+     * Get summary of all installed flows by all installers in a given range
+     *
+     * @param flowId the data path endpoints of the flows to get.
+     * @param maxFlows: the maximum number of flows to be returned
+     * @return the Flow Paths if found, otherwise null.
+     */
+    @Override
+    public ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows) {
+		//
+		// TODO: The implementation below is not optimal:
+		// We fetch all flows, and then return only the subset that match
+		// the query conditions.
+		// We should use the appropriate Titan/Gremlin query to filter-out
+		// the flows as appropriate.
+		//
+	    ArrayList<FlowPath> allFlows = getAllFlows();
+	
+		if (allFlows == null) {
+		    log.debug("Get FlowPathsSummary for {} {}: no FlowPaths found", flowId, maxFlows);
+		    return null;
+		}
+	
+		Collections.sort(allFlows);
+		
+		ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
+		for (FlowPath flow : allFlows) {
+			
+			// start from desired flowId
+			if (flow.flowId().value() < flowId.value()) {
+				continue;
+			}
+			
+			// Summarize by making null flow entry fields that are not relevant to report
+			for (FlowEntry flowEntry : flow.dataPath().flowEntries()) {
+				flowEntry.setFlowEntryActions(null);
+				flowEntry.setFlowEntryMatch(null);
+			}
+			
+		    flowPaths.add(flow);
+		    if (maxFlows != 0 && flowPaths.size() >= maxFlows) {
+		    	break;
+		    }
+		}
+	
+		if (flowPaths.isEmpty()) {
+		    log.debug("Get FlowPathsSummary {} {}: no FlowPaths found", flowId, maxFlows);
+		    flowPaths = null;
+		} else {
+		    log.debug("Get FlowPathsSummary for {} {}: FlowPaths were found", flowId, maxFlows);
+		}
+	
+		return flowPaths;
+    }
+    
+    /**
      * Get all installed flows by all installers.
      *
      * @return the Flow Paths if found, otherwise null.
diff --git a/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java b/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java
index 48477f1..41c0f57 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java
@@ -68,6 +68,15 @@
     ArrayList<FlowPath> getAllFlows(DataPathEndpoints dataPathEndpoints);
 
     /**
+     * Get summary of all installed flows by all installers.
+     *
+     * @param flowId: starting flow Id of the range
+     * @param maxFlows: number of flows to return
+     * @return the Flow Paths if found, otherwise null.
+     */
+    ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows);
+    
+    /**
      * Get all installed flows by all installers.
      *
      * @return the Flow Paths if found, otherwise null.
diff --git a/src/main/java/net/floodlightcontroller/flowcache/web/FlowWebRoutable.java b/src/main/java/net/floodlightcontroller/flowcache/web/FlowWebRoutable.java
index a40a508..19f9e14 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/web/FlowWebRoutable.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/web/FlowWebRoutable.java
@@ -20,6 +20,7 @@
         router.attach("/getall-by-installer-id/{installer-id}/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json", GetAllFlowsByInstallerIdResource.class);
         router.attach("/getall-by-endpoints/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json", GetAllFlowsByEndpointsResource.class);
         router.attach("/getall/json", GetAllFlowsResource.class);
+        router.attach("/getsummary/{flow-id}/{max-flows}/json", GetSummaryFlowsResource.class);
         return router;
     }
 
diff --git a/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java b/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java
index 74a44d4..7a928c9 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java
@@ -12,12 +12,15 @@
 import org.slf4j.LoggerFactory;
 
 public class GetSummaryFlowsResource extends ServerResource {
-    protected static Logger log = LoggerFactory.getLogger(GetAllFlowsResource.class);
+    protected static Logger log = LoggerFactory.getLogger(GetSummaryFlowsResource.class);
 
     @Get("json")
     public ArrayList<FlowPath> retrieve() {
     	ArrayList<FlowPath> result = null;
     	
+    	FlowId flowId;
+    	int maxFlows = 0;
+    	
     	IFlowService flowService = (IFlowService)getContext().getAttributes().get(IFlowService.class.getCanonicalName());
 
         if (flowService == null) {
@@ -26,11 +29,15 @@
         }
 
         // Extract the arguments
-        log.debug("Get All Flows Endpoints");
+    	String flowIdStr = (String) getRequestAttributes().get("flow-id");
+    	String maxFlowStr = (String) getRequestAttributes().get("max-flows");
+    	log.debug("Get Summary Flows starting flow-id: " + flowIdStr + " max-flows: " + maxFlowStr);
+    	
+    	flowId = new FlowId(flowIdStr);
+    	maxFlows = Integer.parseInt(maxFlowStr);
+    	if (maxFlows < 0) maxFlows = 0;
 
-        FlowId flowId = new FlowId(0);
-        
-        result = flowService.getAllFlowsSummary(flowId, 0);
+        result = flowService.getAllFlowsSummary(flowId, maxFlows);
 
         return result;
     }