Backend changes to get all flow summary to improve performance
diff --git a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
index cfb2ea4..6907803 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/FlowManager.java
@@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@@ -12,12 +11,9 @@
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
-import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.floodlightcontroller.core.IFloodlightProviderService;
@@ -32,13 +28,12 @@
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
-import net.floodlightcontroller.flowcache.IFlowService;
import net.floodlightcontroller.flowcache.web.FlowWebRoutable;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.util.CallerId;
import net.floodlightcontroller.util.DataPath;
-import net.floodlightcontroller.util.Dpid;
import net.floodlightcontroller.util.DataPathEndpoints;
+import net.floodlightcontroller.util.Dpid;
import net.floodlightcontroller.util.FlowEntry;
import net.floodlightcontroller.util.FlowEntryAction;
import net.floodlightcontroller.util.FlowEntryId;
@@ -63,7 +58,6 @@
import org.openflow.protocol.OFType;
import org.openflow.protocol.action.OFAction;
import org.openflow.protocol.action.OFActionOutput;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1017,7 +1011,10 @@
* @return the Flow Paths if found, otherwise null.
*/
@Override
- public ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows) {
+ public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows) {
+
+
+
//
// TODO: The implementation below is not optimal:
// We fetch all flows, and then return only the subset that match
@@ -1025,10 +1022,15 @@
// We should use the appropriate Titan/Gremlin query to filter-out
// the flows as appropriate.
//
- ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
+ //ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
+ ArrayList<IFlowPath> flowPathsWithoutFlowEntries = getAllFlowsWithoutFlowEntries();
+
+ return flowPathsWithoutFlowEntries;
+
+ /*
ArrayList<FlowPath> allFlows = getAllFlows();
-
+
if (allFlows == null) {
log.debug("Get FlowPathsSummary for {} {}: no FlowPaths found", flowId, maxFlows);
return flowPaths;
@@ -1063,6 +1065,7 @@
}
return flowPaths;
+ */
}
/**
@@ -1104,6 +1107,45 @@
return flowPaths;
}
+
+ public ArrayList<IFlowPath> getAllFlowsWithoutFlowEntries(){
+ Iterable<IFlowPath> flowPathsObj = null;
+ ArrayList<IFlowPath> flowPathsObjArray = new ArrayList<IFlowPath>();
+ ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
+
+ try {
+ if ((flowPathsObj = conn.utils().getAllFlowPaths(conn)) != null) {
+ log.debug("Get all FlowPaths: found FlowPaths");
+ } else {
+ log.debug("Get all FlowPaths: no FlowPaths found");
+ }
+ } catch (Exception e) {
+ // TODO: handle exceptions
+ conn.endTx(Transaction.ROLLBACK);
+ log.error(":getAllFlowPaths failed");
+ }
+ if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) {
+ return new ArrayList<IFlowPath>(); // No Flows found
+ }
+
+ for (IFlowPath flowObj : flowPathsObj){
+ flowPathsObjArray.add(flowObj);
+ }
+ /*
+ for (IFlowPath flowObj : flowPathsObj) {
+ //
+ // Extract the Flow state
+ //
+ FlowPath flowPath = extractFlowPath(flowObj);
+ if (flowPath != null)
+ flowPaths.add(flowPath);
+ }
+ */
+
+ //conn.endTx(Transaction.COMMIT);
+
+ return flowPathsObjArray;
+ }
/**
* Extract Flow Path State from a Titan Database Object @ref IFlowPath.
diff --git a/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java b/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java
index 619d36b..855f064 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/IFlowService.java
@@ -2,6 +2,7 @@
import java.util.ArrayList;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.util.CallerId;
import net.floodlightcontroller.util.DataPathEndpoints;
@@ -77,7 +78,7 @@
* @param maxFlows: number of flows to return
* @return the Flow Paths if found, otherwise null.
*/
- ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows);
+ ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows);
/**
* Get all installed flows by all installers.
diff --git a/src/main/java/net/floodlightcontroller/flowcache/web/DatapathSummarySerializer.java b/src/main/java/net/floodlightcontroller/flowcache/web/DatapathSummarySerializer.java
new file mode 100644
index 0000000..b780e5c
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/flowcache/web/DatapathSummarySerializer.java
@@ -0,0 +1,82 @@
+package net.floodlightcontroller.flowcache.web;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DatapathSummarySerializer extends JsonSerializer<String>{
+ static Logger log = LoggerFactory.getLogger(DatapathSummarySerializer.class);
+
+ @Override
+ public void serialize(String datapathSummary, JsonGenerator jGen,
+ SerializerProvider serializer) throws IOException,
+ JsonProcessingException {
+
+ String[] flowEntries = datapathSummary.split(";");
+ if (flowEntries.length < 2){
+ log.debug("datapathSummary string to short to parse: {}",
+ datapathSummary);
+ jGen.writeStartObject();
+ jGen.writeEndObject();
+ return;
+ }
+
+ String[] srcFlowEntry = flowEntries[0].split("/");
+ String[] dstFlowEntry = flowEntries[flowEntries.length - 1].split("/");
+ if (srcFlowEntry.length != 3 || dstFlowEntry.length != 3){
+ log.debug("Malformed datapathSummary string: {}", datapathSummary);
+ jGen.writeStartObject();
+ jGen.writeEndObject();
+ return;
+ }
+
+ jGen.writeStartObject();
+
+ /*
+ jGen.writeObjectFieldStart("srcPort");
+ jGen.writeObjectFieldStart("dpid");
+ jGen.writeStringField("value", srcFlowEntry[1]);
+ jGen.writeEndObject();
+ jGen.writeObjectFieldStart("port");
+ jGen.writeStringField("value", srcFlowEntry[0]);
+ jGen.writeEndObject();
+ jGen.writeEndObject();
+
+ jGen.writeObjectFieldStart("dstPort");
+ jGen.writeObjectFieldStart("dpid");
+ jGen.writeStringField("value", srcFlowEntry[1]);
+ jGen.writeEndObject();
+ jGen.writeObjectFieldStart("port");
+ jGen.writeStringField("value", srcFlowEntry[2]);
+ jGen.writeEndObject();
+ jGen.writeEndObject();
+ */
+ jGen.writeArrayFieldStart("flowEntries");
+
+ for (String flowEntryString : flowEntries){
+ String[] flowEntry = flowEntryString.split("/");
+ if (flowEntry.length != 3){
+ log.debug("Malformed datapathSummary string: {}", datapathSummary);
+ jGen.writeStartObject();
+ jGen.writeEndObject();
+ continue;
+ }
+
+ jGen.writeStartObject();
+ jGen.writeObjectFieldStart("dpid");
+ jGen.writeStringField("value", flowEntry[1]);
+ jGen.writeEndObject();
+ jGen.writeEndObject();
+ }
+
+ jGen.writeEndArray();
+
+ jGen.writeEndObject();
+ }
+
+}
diff --git a/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java b/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java
index 7a928c9..5f63222 100644
--- a/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java
+++ b/src/main/java/net/floodlightcontroller/flowcache/web/GetSummaryFlowsResource.java
@@ -2,9 +2,10 @@
import java.util.ArrayList;
+import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.floodlightcontroller.flowcache.IFlowService;
-import net.floodlightcontroller.util.FlowPath;
import net.floodlightcontroller.util.FlowId;
+import net.floodlightcontroller.util.FlowPath;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
@@ -15,8 +16,8 @@
protected static Logger log = LoggerFactory.getLogger(GetSummaryFlowsResource.class);
@Get("json")
- public ArrayList<FlowPath> retrieve() {
- ArrayList<FlowPath> result = null;
+ public ArrayList<IFlowPath> retrieve() {
+ ArrayList<IFlowPath> result = null;
FlowId flowId;
int maxFlows = 0;