* Remove clearFlow() and clearAllFlows(), and the corresponding REST
calls, because semantically they are not needed.
The web/clear_flow.py script is removed as well.
* Update the backend implementation of deleteFlow() and deleteAllFlows()
to perform the actions that were done before by clearFlow() and
clearAllFlows()
Removed clearFlow() and clearAllFlows()
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 f623541..73c4e51 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
@@ -370,122 +370,6 @@
* @return true on success, otherwise false.
*/
static boolean deleteAllFlows(GraphDBOperation dbHandler) {
- final ConcurrentLinkedQueue<FlowId> concurrentAllFlowIds =
- new ConcurrentLinkedQueue<FlowId>();
-
- // Get all Flow IDs
- Iterable<IFlowPath> allFlowPaths = dbHandler.getAllFlowPaths();
- for (IFlowPath flowPathObj : allFlowPaths) {
- if (flowPathObj == null)
- continue;
- String flowIdStr = flowPathObj.getFlowId();
- if (flowIdStr == null)
- continue;
- FlowId flowId = new FlowId(flowIdStr);
- concurrentAllFlowIds.add(flowId);
- }
-
- // Delete all flows one-by-one
- for (FlowId flowId : concurrentAllFlowIds)
- deleteFlow(dbHandler, flowId);
-
- /*
- * TODO: A faster mechanism to delete the Flow Paths by using
- * a number of threads. Commented-out for now.
- */
- /*
- //
- // Create the threads to delete the Flow Paths
- //
- List<Thread> threads = new LinkedList<Thread>();
- for (int i = 0; i < 10; i++) {
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- while (true) {
- FlowId flowId = concurrentAllFlowIds.poll();
- if (flowId == null)
- return;
- deleteFlow(dbHandler, flowId);
- }
- }}, "Delete All Flow Paths");
- threads.add(thread);
- }
-
- // Start processing
- for (Thread thread : threads) {
- thread.start();
- }
-
- // Wait for all threads to complete
- for (Thread thread : threads) {
- try {
- thread.join();
- } catch (InterruptedException e) {
- log.debug("Exception waiting for a thread to delete a Flow Path: ", e);
- }
- }
- */
-
- return true;
- }
-
- /**
- * Delete a previously added flow.
- *
- * @param dbHandler the Graph Database handler to use.
- * @param flowId the Flow ID of the flow to delete.
- * @return true on success, otherwise false.
- */
- static boolean deleteFlow(GraphDBOperation dbHandler, FlowId flowId) {
- IFlowPath flowObj = null;
- //
- // We just mark the entries for deletion,
- // and let the switches remove each individual entry after
- // it has been removed from the switches.
- //
- try {
- flowObj = dbHandler.searchFlowPath(flowId);
- } catch (Exception e) {
- // TODO: handle exceptions
- dbHandler.rollback();
- log.error(":deleteFlow FlowId:{} failed", flowId.toString());
- return false;
- }
- if (flowObj == null) {
- dbHandler.commit();
- return true; // OK: No such flow
- }
-
- //
- // Find and mark for deletion all Flow Entries,
- // and the Flow itself.
- //
- flowObj.setFlowPathUserState("FP_USER_DELETE");
- Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
- boolean empty = true; // TODO: an ugly hack
- for (IFlowEntry flowEntryObj : flowEntries) {
- empty = false;
- // flowObj.removeFlowEntry(flowEntryObj);
- // conn.utils().removeFlowEntry(conn, flowEntryObj);
- flowEntryObj.setUserState("FE_USER_DELETE");
- flowEntryObj.setSwitchState("FE_SWITCH_NOT_UPDATED");
- }
- // Remove from the database empty flows
- if (empty)
- dbHandler.removeFlowPath(flowObj);
- dbHandler.commit();
-
- return true;
- }
-
- /**
- * Clear the state for all previously added flows.
- *
- * @param dbHandler the Graph Database handler to use.
- * @return true on success, otherwise false.
- */
- static boolean clearAllFlows(GraphDBOperation dbHandler) {
List<FlowId> allFlowIds = new LinkedList<FlowId>();
// Get all Flow IDs
@@ -500,29 +384,29 @@
allFlowIds.add(flowId);
}
- // Clear all flows one-by-one
+ // Delete all flows one-by-one
for (FlowId flowId : allFlowIds) {
- clearFlow(dbHandler, flowId);
+ deleteFlow(dbHandler, flowId);
}
return true;
}
/**
- * Clear the state for a previously added flow.
+ * Delete a previously added flow.
*
* @param dbHandler the Graph Database handler to use.
- * @param flowId the Flow ID of the flow to clear.
+ * @param flowId the Flow ID of the flow to delete.
* @return true on success, otherwise false.
*/
- static boolean clearFlow(GraphDBOperation dbHandler, FlowId flowId) {
+ static boolean deleteFlow(GraphDBOperation dbHandler, FlowId flowId) {
IFlowPath flowObj = null;
try {
flowObj = dbHandler.searchFlowPath(flowId);
} catch (Exception e) {
// TODO: handle exceptions
dbHandler.rollback();
- log.error(":clearFlow FlowId:{} failed", flowId.toString());
+ log.error(":deleteFlow FlowId:{} failed", flowId.toString());
return false;
}
if (flowObj == null) {
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 b75b603..45e8a6f 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -287,19 +287,11 @@
*/
@Override
public boolean deleteAllFlows() {
- //
- // TODO: In the notification-based implementation,
- // deleteFlow() is implemented by using clearFlow()
- //
- return clearAllFlows();
-
- /*
if (FlowDatabaseOperation.deleteAllFlows(dbHandlerApi)) {
datagridService.notificationSendAllFlowsRemoved();
return true;
}
return false;
- */
}
/**
@@ -310,47 +302,11 @@
*/
@Override
public boolean deleteFlow(FlowId flowId) {
- //
- // TODO: In the notification-based implementation,
- // deleteFlow() is implemented by using clearFlow()
- //
- return clearFlow(flowId);
- /*
if (FlowDatabaseOperation.deleteFlow(dbHandlerApi, flowId)) {
datagridService.notificationSendFlowRemoved(flowId);
return true;
}
return false;
- */
- }
-
- /**
- * Clear the state for all previously added flows.
- *
- * @return true on success, otherwise false.
- */
- @Override
- public boolean clearAllFlows() {
- if (FlowDatabaseOperation.clearAllFlows(dbHandlerApi)) {
- datagridService.notificationSendAllFlowsRemoved();
- return true;
- }
- return false;
- }
-
- /**
- * Clear the state for a previously added flow.
- *
- * @param flowId the Flow ID of the flow to clear.
- * @return true on success, otherwise false.
- */
- @Override
- public boolean clearFlow(FlowId flowId) {
- if (FlowDatabaseOperation.clearFlow(dbHandlerApi, flowId)) {
- datagridService.notificationSendFlowRemoved(flowId);
- return true;
- }
- return false;
}
/**
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 f39acb5..b06d844 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/IFlowService.java
@@ -42,21 +42,6 @@
boolean deleteFlow(FlowId flowId);
/**
- * Clear the state for all previously added flows.
- *
- * @return true on success, otherwise false.
- */
- boolean clearAllFlows();
-
- /**
- * Clear the state for a previously added flow.
- *
- * @param flowId the Flow ID of the flow to clear.
- * @return true on success, otherwise false.
- */
- boolean clearFlow(FlowId flowId);
-
- /**
* Get a previously added flow.
*
* @param flowId the Flow ID of the flow to get.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/ClearFlowResource.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/ClearFlowResource.java
deleted file mode 100644
index b8942b9..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/ClearFlowResource.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package net.onrc.onos.ofcontroller.flowmanager.web;
-
-import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
-import net.onrc.onos.ofcontroller.util.FlowId;
-
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Flow Manager REST API implementation: Clear internal Flow state.
- *
- * The "{flow-id}" request attribute value can be either a specific Flow ID,
- * or the keyword "all" to clear all Flows:
- *
- * GET /wm/flow/clear/{flow-id}/json
- */
-public class ClearFlowResource extends ServerResource {
- protected final static Logger log = LoggerFactory.getLogger(ClearFlowResource.class);
-
- /**
- * Implement the API.
- *
- * @return true on success, otehrwise false.
- */
- @Get("json")
- public Boolean retrieve() {
- Boolean result = false;
-
- IFlowService flowService =
- (IFlowService)getContext().getAttributes().
- get(IFlowService.class.getCanonicalName());
-
- if (flowService == null) {
- log.debug("ONOS Flow Service not found");
- return result;
- }
-
- // Extract the arguments
- String flowIdStr = (String) getRequestAttributes().get("flow-id");
-
- // Process the request
- if (flowIdStr.equals("all")) {
- log.debug("Clear All Flows");
- result = flowService.clearAllFlows();
- } else {
- FlowId flowId = new FlowId(flowIdStr);
- log.debug("Clear Flow Id: " + flowIdStr);
- result = flowService.clearFlow(flowId);
- }
- return result;
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java
index e027270..81d26dd 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/web/FlowWebRoutable.java
@@ -18,7 +18,6 @@
Router router = new Router(context);
router.attach("/add/json", AddFlowResource.class);
router.attach("/add-shortest-path/json", AddShortestPathFlowResource.class);
- router.attach("/clear/{flow-id}/json", ClearFlowResource.class);
router.attach("/delete/{flow-id}/json", DeleteFlowResource.class);
router.attach("/get/{flow-id}/json", GetFlowByIdResource.class);
router.attach("/getall-by-installer-id/{installer-id}/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json", GetAllFlowsByInstallerIdResource.class);
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 7fd0f67..881ff7c 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -239,49 +239,48 @@
verifyAll();
assertTrue(result);
}
-
+
/**
- * Test method for {@link FlowManager#deleteAllFlows()}.
- * @throws Exception
+ * Test method for {@link FlowManager#deleteFlow(FlowId)}.
+ * @throws Exception
*/
@Test
- public final void testDeleteAllFlowsSuccessNormally() throws Exception {
+ public final void testDeleteFlowSuccessNormally() throws Exception {
// create mock objects
- IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
- IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
+ IFlowPath flowPath = createIFlowPathMock(123, "id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
+ IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
+ IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
+ IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
// instantiate required objects
- ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
- flowPaths.add(flowPath1);
- flowPaths.add(flowPath2);
FlowManager fm = new FlowManager();
-
+ FlowId flowId = new FlowId(123);
+ ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>();
+ flowEntries.add(flowEntry1);
+ flowEntries.add(flowEntry2);
+ flowEntries.add(flowEntry3);
+
// setup expectations
expectInitWithContext();
- expect(op.getAllFlowPaths()).andReturn(flowPaths);
-
- expect(flowPath1.getFlowId()).andReturn("1").anyTimes();
- expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowPath1);
- expect(flowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
- op.removeFlowPath(flowPath1);
-
- expect(flowPath2.getFlowId()).andReturn("2").anyTimes();
- expect(op.searchFlowPath(cmpEq(new FlowId(2)))).andReturn(flowPath2);
- expect(flowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
- op.removeFlowPath(flowPath2);
-
+ expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath);
+ expect(flowPath.getFlowEntries()).andReturn(flowEntries);
+ flowPath.removeFlowEntry(flowEntry1);
+ flowPath.removeFlowEntry(flowEntry2);
+ flowPath.removeFlowEntry(flowEntry3);
+ op.removeFlowEntry(flowEntry1);
+ op.removeFlowEntry(flowEntry2);
+ op.removeFlowEntry(flowEntry3);
+ op.removeFlowPath(flowPath);
op.commit();
- expectLastCall().anyTimes();
// start the test
replayAll();
fm.init(context);
- Boolean result = fm.deleteAllFlows();
+ fm.deleteFlow(flowId);
// verify the test
verifyAll();
- assertTrue(result);
}
/**
@@ -316,16 +315,16 @@
}
/**
- * Test method for {@link FlowManager#clearAllFlows()}.
+ * Test method for {@link FlowManager#deleteAllFlows()}.
* @throws Exception
*/
@Test
- public final void testClearAllFlowsSuccessNormally() throws Exception {
+ public final void testDeleteAllFlowsSuccessNormally() throws Exception {
// create mock objects
IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
IFlowPath flowPath3 = createNiceMock(IFlowPath.class);
- FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "clearFlow");
+ FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "deleteFlow");
// instantiate required objects
ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
@@ -340,16 +339,16 @@
expect(flowPath1.getFlowId()).andReturn(new FlowId(1).toString());
expect(flowPath2.getFlowId()).andReturn(null);
expect(flowPath3.getFlowId()).andReturn(new FlowId(3).toString());
- expect(fm.clearFlow(cmpEq(new FlowId(1)))).andReturn(true);
- expect(fm.clearFlow(cmpEq(new FlowId(3)))).andReturn(true);
+ expect(fm.deleteFlow(cmpEq(new FlowId(1)))).andReturn(true);
+ expect(fm.deleteFlow(cmpEq(new FlowId(3)))).andReturn(true);
// start the test
replayAll();
fm.init(context);
- Boolean result = fm.clearAllFlows();
+ Boolean result = fm.deleteAllFlows();
- //verify the test
+ // verify the test
verifyAll();
assertTrue(result);
}
@@ -786,50 +785,6 @@
// other methods
-
- /**
- * Test method for {@link FlowManager#clearFlow(FlowId)}.
- * @throws Exception
- */
- @Test
- public final void testClearFlowSuccessNormally() throws Exception {
- // create mock objects
- IFlowPath flowPath = createIFlowPathMock(123, "id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
- IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
- IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
- IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
-
- // instantiate required objects
- FlowManager fm = new FlowManager();
- FlowId flowId = new FlowId(123);
- ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>();
- flowEntries.add(flowEntry1);
- flowEntries.add(flowEntry2);
- flowEntries.add(flowEntry3);
-
- // setup expectations
- expectInitWithContext();
- expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath);
- expect(flowPath.getFlowEntries()).andReturn(flowEntries);
- flowPath.removeFlowEntry(flowEntry1);
- flowPath.removeFlowEntry(flowEntry2);
- flowPath.removeFlowEntry(flowEntry3);
- op.removeFlowEntry(flowEntry1);
- op.removeFlowEntry(flowEntry2);
- op.removeFlowEntry(flowEntry3);
- op.removeFlowPath(flowPath);
- op.commit();
-
- // start the test
- replayAll();
-
- fm.init(context);
- fm.clearFlow(flowId);
-
- // verify the test
- verifyAll();
- }
-
/**
* Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}.
* @throws Exception