* Refactor the implementation of the FlowManager.getAllFlowsSummary()
implementation so it is less add-hoc.
Now it uses getAllFlows() in its backend, and returns an array
of FlowPath objects instead of IFlowPath.
* Renamed method FlowDatabaseOperation.getAllFlowsWithoutFlowEntries()
to getAllFlowsWithDataPathSummary() to reflect better its behavior.
* Removed method FlowManager.getAllFlowsWithoutFlowEntries()
because it is not really used.
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 73c4e51..ce2b1c7 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
@@ -590,9 +590,9 @@
* @param maxFlows the maximum number of flows to be returned.
* @return the Flow Paths if found, otherwise null.
*/
- static ArrayList<IFlowPath> getAllFlowsSummary(GraphDBOperation dbHandler,
- FlowId flowId,
- int maxFlows) {
+ static ArrayList<FlowPath> getAllFlowsSummary(GraphDBOperation dbHandler,
+ FlowId flowId,
+ int maxFlows) {
//
// TODO: The implementation below is not optimal:
// We fetch all flows, and then return only the subset that match
@@ -600,61 +600,32 @@
// We should use the appropriate Titan/Gremlin query to filter-out
// the flows as appropriate.
//
- ArrayList<IFlowPath> flowPathsWithoutFlowEntries =
- getAllFlowsWithoutFlowEntries(dbHandler);
-
- Collections.sort(flowPathsWithoutFlowEntries,
- new Comparator<IFlowPath>() {
- @Override
- public int compare(IFlowPath first, IFlowPath second) {
- long result =
- new FlowId(first.getFlowId()).value()
- - new FlowId(second.getFlowId()).value();
- if (result > 0) {
- return 1;
- } else if (result < 0) {
- return -1;
- } else {
- return 0;
- }
- }
- }
- );
-
- return flowPathsWithoutFlowEntries;
+ ArrayList<FlowPath> flowPaths = getAllFlowsWithDataPathSummary(dbHandler);
+ Collections.sort(flowPaths);
+ return flowPaths;
}
/**
- * Get all Flows information, without the associated Flow Entries.
+ * Get all Flows information, with Data Path summary for the Flow Entries.
*
* @param dbHandler the Graph Database handler to use.
- * @return all Flows information, without the associated Flow Entries.
+ * @return all Flows information, with Data Path summary for the Flow
+ * Entries.
*/
- static ArrayList<IFlowPath> getAllFlowsWithoutFlowEntries(GraphDBOperation dbHandler) {
- Iterable<IFlowPath> flowPathsObj = null;
- ArrayList<IFlowPath> flowPathsObjArray = new ArrayList<IFlowPath>();
+ static ArrayList<FlowPath> getAllFlowsWithDataPathSummary(GraphDBOperation dbHandler) {
+ ArrayList<FlowPath> flowPaths = getAllFlows(dbHandler);
- // TODO: Remove this op.commit() flow, because it is not needed?
- dbHandler.commit();
+ // Truncate each Flow Path and Flow Entry
+ for (FlowPath flowPath : flowPaths) {
+ flowPath.setFlowEntryMatch(null);
+ flowPath.setFlowEntryActions(null);
+ for (FlowEntry flowEntry : flowPath.flowEntries()) {
+ flowEntry.setFlowEntryMatch(null);
+ flowEntry.setFlowEntryActions(null);
+ }
+ }
- try {
- flowPathsObj = dbHandler.getAllFlowPaths();
- } catch (Exception e) {
- // TODO: handle exceptions
- dbHandler.rollback();
- log.error(":getAllFlowPaths failed");
- return flowPathsObjArray; // No Flows found
- }
- if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) {
- return flowPathsObjArray; // No Flows found
- }
-
- for (IFlowPath flowObj : flowPathsObj)
- flowPathsObjArray.add(flowObj);
-
- // conn.endTx(Transaction.COMMIT);
-
- return flowPathsObjArray;
+ return flowPaths;
}
/**
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 45e8a6f..f427beb 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -365,22 +365,13 @@
* @return the Flow Paths if found, otherwise null.
*/
@Override
- public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId,
- int maxFlows) {
+ public ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId,
+ int maxFlows) {
return FlowDatabaseOperation.getAllFlowsSummary(dbHandlerApi, flowId,
maxFlows);
}
/**
- * Get all Flows information, without the associated Flow Entries.
- *
- * @return all Flows information, without the associated Flow Entries.
- */
- public ArrayList<IFlowPath> getAllFlowsWithoutFlowEntries() {
- return FlowDatabaseOperation.getAllFlowsWithoutFlowEntries(dbHandlerApi);
- }
-
- /**
* Add and maintain a shortest-path flow.
*
* NOTE: The Flow Path argument does NOT contain flow entries.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
index b06d844..ba3a6e7 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import net.floodlightcontroller.core.module.IFloodlightService;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.onrc.onos.ofcontroller.topology.Topology;
import net.onrc.onos.ofcontroller.util.CallerId;
import net.onrc.onos.ofcontroller.util.DataPathEndpoints;
@@ -82,7 +81,7 @@
* @param maxFlows number of flows to return
* @return the Flow Paths if found, otherwise null.
*/
- ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows);
+ ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows);
/**
* Add and maintain a shortest-path flow.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/GetSummaryFlowsResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/GetSummaryFlowsResource.java
index 89e5b01..58f82a9 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/GetSummaryFlowsResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/GetSummaryFlowsResource.java
@@ -2,8 +2,8 @@
import java.util.ArrayList;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
+import net.onrc.onos.ofcontroller.util.FlowPath;
import net.onrc.onos.ofcontroller.util.FlowId;
import org.restlet.resource.Get;
@@ -31,8 +31,8 @@
* @return the collection of Flow states if any found, otherwise null.
*/
@Get("json")
- public ArrayList<IFlowPath> retrieve() {
- ArrayList<IFlowPath> result = null;
+ public ArrayList<FlowPath> retrieve() {
+ ArrayList<FlowPath> result = null;
FlowId flowId;
int maxFlows = 0;
diff --git a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
index 881ff7c..8a727d3 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -463,35 +463,35 @@
*/
@Test
public final void testGetAllFlowsSummarySuccessNormally() throws Exception {
- final String getAllFlowsWithoutFlowEntries = "getAllFlowsWithoutFlowEntries";
+ final String getAllFlowsWithDataPathSummary = "getAllFlowsWithDataPathSummary";
// create mock objects
- FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithoutFlowEntries);
- IFlowPath flowPath1 = createIFlowPathMock(1, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
- IFlowPath flowPath2 = createIFlowPathMock(5, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 3, 4, 5);
- IFlowPath flowPath3 = createIFlowPathMock(10, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 3, 4, 5, 6);
+ FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithDataPathSummary);
+ FlowPath flowPath1 = createTestFlowPath(1, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
+ FlowPath flowPath2 = createTestFlowPath(5, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 3, 4, 5);
+ FlowPath flowPath3 = createTestFlowPath(10, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 3, 4, 5, 6);
// instantiate required objects
- ArrayList<IFlowPath> flows = new ArrayList<IFlowPath>();
+ ArrayList<FlowPath> flows = new ArrayList<FlowPath>();
flows.add(flowPath3);
flows.add(flowPath1);
flows.add(flowPath2);
// setup expectations
expectInitWithContext();
- expectPrivate(fm, getAllFlowsWithoutFlowEntries).andReturn(flows);
+ expectPrivate(fm, getAllFlowsWithDataPathSummary).andReturn(flows);
// start the test
replayAll();
fm.init(context);
- ArrayList<IFlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0);
+ ArrayList<FlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0);
// verify the test
verifyAll();
assertEquals(3, returnedFlows.size());
- assertEquals(1, new FlowId(returnedFlows.get(0).getFlowId()).value());
- assertEquals(5, new FlowId(returnedFlows.get(1).getFlowId()).value());
- assertEquals(10, new FlowId(returnedFlows.get(2).getFlowId()).value());
+ assertEquals(1, new FlowId(returnedFlows.get(0).flowId().value()).value());
+ assertEquals(5, new FlowId(returnedFlows.get(1).flowId().value()).value());
+ assertEquals(10, new FlowId(returnedFlows.get(2).flowId().value()).value());
}
/**
@@ -786,41 +786,6 @@
// other methods
/**
- * Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}.
- * @throws Exception
- */
- @Test
- public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception {
- // create mock objects
- IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2);
- IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 5, 3, 5);
-
- // instantiate required objects
- ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
- flowPaths.add(iFlowPath1);
- flowPaths.add(iFlowPath2);
- FlowManager fm = new FlowManager();
-
- // setup expectations
- expectInitWithContext();
- op.commit();
- expect(op.getAllFlowPaths()).andReturn(flowPaths);
-
- // start the test
- replayAll();
-
- fm.init(context);
- ArrayList<IFlowPath> result = fm.getAllFlowsWithoutFlowEntries();
-
- // verify the test
- verifyAll();
- assertEquals(iFlowPath1, result.get(0));
- assertEquals(iFlowPath2, result.get(1));
-
- // TODO: does this method just return the replica of the flow paths?
- }
-
- /**
* Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}.
* @throws Exception
*/