Cleanup the FlowManager. No functional changes.
- Removed unused code
- Formatting
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 1215558..82aa25c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -99,12 +99,6 @@
private static int nextFlowEntryIdSuffix = 0;
private static long nextFlowEntryId = 0;
- // State for measurement purpose
- private static long measurementFlowId = 100000;
- private static String measurementFlowIdStr = "0x186a0"; // 100000
- private long modifiedMeasurementFlowTime = 0;
- //
-
/** The logger. */
private static Logger log = LoggerFactory.getLogger(FlowManager.class);
@@ -148,10 +142,10 @@
new LinkedList<IFlowEntry>();
//
- // Fetch all Flow Entries which need to be updated and select only my Flow Entries
- // that need to be updated into the switches.
+ // Fetch all Flow Entries which need to be updated and select
+ // only my Flow Entries that need to be updated into the
+ // switches.
//
- boolean processed_measurement_flow = false;
Iterable<IFlowEntry> allFlowEntries =
op.getAllSwitchNotUpdatedFlowEntries();
for (IFlowEntry flowEntryObj : allFlowEntries) {
@@ -188,15 +182,6 @@
addFlowEntries.add(flowEntryObj);
}
counterMyNotUpdatedFlowEntries++;
- // Code for measurement purpose
- // TODO: Commented-out for now
- /*
- {
- if (flowObj.getFlowId().equals(measurementFlowIdStr)) {
- processed_measurement_flow = true;
- }
- }
- */
}
//
@@ -239,14 +224,6 @@
op.commit();
- if (processed_measurement_flow) {
- long estimatedTime =
- System.nanoTime() - modifiedMeasurementFlowTime;
- String logMsg = "MEASUREMENT: Pushed Flow delay: " +
- (double)estimatedTime / 1000000000 + " sec";
- log.debug(logMsg);
- }
-
long estimatedTime = System.nanoTime() - startTime;
double rate = 0.0;
if (estimatedTime > 0)
@@ -292,8 +269,6 @@
}
LinkedList<IFlowPath> deleteFlows = new LinkedList<IFlowPath>();
- boolean processed_measurement_flow = false;
-
//
// Fetch and recompute the Shortest Path for those
// Flow Paths this controller is responsible for.
@@ -404,14 +379,6 @@
op.commit();
- if (processed_measurement_flow) {
- long estimatedTime =
- System.nanoTime() - modifiedMeasurementFlowTime;
- String logMsg = "MEASUREMENT: Pushed Flow delay: " +
- (double)estimatedTime / 1000000000 + " sec";
- log.debug(logMsg);
- }
-
long estimatedTime = System.nanoTime() - startTime;
double rate = 0.0;
if (estimatedTime > 0)
@@ -487,7 +454,7 @@
*/
@Override
public Collection<Class<? extends IFloodlightService>>
- getModuleDependencies() {
+ getModuleDependencies() {
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
@@ -515,9 +482,8 @@
EnumSet.of(OFType.FLOW_MOD),
OFMESSAGE_DAMPER_TIMEOUT);
- String conf = "";
- this.init(conf);
-
+ this.init("");
+
mapReaderScheduler = Executors.newScheduledThreadPool(1);
shortestPathReconcileScheduler = Executors.newScheduledThreadPool(1);
}
@@ -553,10 +519,10 @@
@Override
public void startUp(FloodlightModuleContext context) {
restApi.addRestletRoutable(new FlowWebRoutable());
-
+
// Initialize the Flow Entry ID generator
nextFlowEntryIdPrefix = randomGenerator.nextInt();
-
+
mapReaderScheduler.scheduleAtFixedRate(
mapReader, 3, 3, TimeUnit.SECONDS);
shortestPathReconcileScheduler.scheduleAtFixedRate(
@@ -578,25 +544,13 @@
@Override
public boolean addFlow(FlowPath flowPath, FlowId flowId,
String dataPathSummaryStr) {
- /*
- * TODO: Commented-out for now
- if (flowPath.flowId().value() == measurementFlowId) {
- modifiedMeasurementFlowTime = System.nanoTime();
- }
- */
-
IFlowPath flowObj = null;
boolean found = false;
try {
- if ((flowObj = op.searchFlowPath(flowPath.flowId()))
- != null) {
- log.debug("Adding FlowPath with FlowId {}: found existing FlowPath",
- flowPath.flowId().toString());
+ if ((flowObj = op.searchFlowPath(flowPath.flowId())) != null) {
found = true;
} else {
flowObj = op.newFlowPath();
- log.debug("Adding FlowPath with FlowId {}: creating new FlowPath",
- flowPath.flowId().toString());
}
} catch (Exception e) {
// TODO: handle exceptions
@@ -746,13 +700,9 @@
try {
if ((flowEntryObj =
op.searchFlowEntry(flowEntry.flowEntryId())) != null) {
- log.debug("Adding FlowEntry with FlowEntryId {}: found existing FlowEntry",
- flowEntry.flowEntryId().toString());
found = true;
} else {
flowEntryObj = op.newFlowEntry();
- log.debug("Adding FlowEntry with FlowEntryId {}: creating new FlowEntry",
- flowEntry.flowEntryId().toString());
}
} catch (Exception e) {
log.error(":addFlow FlowEntryId:{} failed",
@@ -950,13 +900,6 @@
*/
@Override
public boolean deleteFlow(FlowId flowId) {
- /*
- * TODO: Commented-out for now
- if (flowId.value() == measurementFlowId) {
- modifiedMeasurementFlowTime = System.nanoTime();
- }
- */
-
IFlowPath flowObj = null;
//
// We just mark the entries for deletion,
@@ -964,14 +907,7 @@
// it has been removed from the switches.
//
try {
- if ((flowObj = op.searchFlowPath(flowId))
- != null) {
- log.debug("Deleting FlowPath with FlowId {}: found existing FlowPath",
- flowId.toString());
- } else {
- log.debug("Deleting FlowPath with FlowId {}: FlowPath not found",
- flowId.toString());
- }
+ flowObj = op.searchFlowPath(flowId);
} catch (Exception e) {
// TODO: handle exceptions
op.rollback();
@@ -1043,14 +979,7 @@
public boolean clearFlow(FlowId flowId) {
IFlowPath flowObj = null;
try {
- if ((flowObj = op.searchFlowPath(flowId))
- != null) {
- log.debug("Clearing FlowPath with FlowId {}: found existing FlowPath",
- flowId.toString());
- } else {
- log.debug("Clearing FlowPath with FlowId {}: FlowPath not found",
- flowId.toString());
- }
+ flowObj = op.searchFlowPath(flowId);
} catch (Exception e) {
// TODO: handle exceptions
op.rollback();
@@ -1086,14 +1015,7 @@
public FlowPath getFlow(FlowId flowId) {
IFlowPath flowObj = null;
try {
- if ((flowObj = op.searchFlowPath(flowId))
- != null) {
- log.debug("Get FlowPath with FlowId {}: found existing FlowPath",
- flowId.toString());
- } else {
- log.debug("Get FlowPath with FlowId {}: FlowPath not found",
- flowId.toString());
- }
+ flowObj = op.searchFlowPath(flowId);
} catch (Exception e) {
// TODO: handle exceptions
op.rollback();
@@ -1134,10 +1056,8 @@
ArrayList<FlowPath> allFlows = getAllFlows();
ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
- if (allFlows == null) {
- log.debug("Get FlowPaths for installerId{} and dataPathEndpoints{}: no FlowPaths found", installerId, dataPathEndpoints);
+ if (allFlows == null)
return flowPaths;
- }
for (FlowPath flow : allFlows) {
//
@@ -1156,12 +1076,6 @@
flowPaths.add(flow);
}
- if (flowPaths.isEmpty()) {
- log.debug("Get FlowPaths for installerId{} and dataPathEndpoints{}: no FlowPaths found", installerId, dataPathEndpoints);
- } else {
- log.debug("Get FlowPaths for installerId{} and dataPathEndpoints{}: FlowPaths are found", installerId, dataPathEndpoints);
- }
-
return flowPaths;
}
@@ -1180,13 +1094,11 @@
// We should use the appropriate Titan/Gremlin query to filter-out
// the flows as appropriate.
//
- ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
- ArrayList<FlowPath> allFlows = getAllFlows();
+ ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
+ ArrayList<FlowPath> allFlows = getAllFlows();
- if (allFlows == null) {
- log.debug("Get FlowPaths for dataPathEndpoints{}: no FlowPaths found", dataPathEndpoints);
+ if (allFlows == null)
return flowPaths;
- }
for (FlowPath flow : allFlows) {
//
@@ -1203,13 +1115,7 @@
flowPaths.add(flow);
}
- if (flowPaths.isEmpty()) {
- log.debug("Get FlowPaths for dataPathEndpoints{}: no FlowPaths found", dataPathEndpoints);
- } else {
- log.debug("Get FlowPaths for dataPathEndpoints{}: FlowPaths are found", dataPathEndpoints);
- }
-
- return flowPaths;
+return flowPaths;
}
/**
@@ -1220,7 +1126,8 @@
* @return the Flow Paths if found, otherwise null.
*/
@Override
- public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows) {
+ public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId,
+ int maxFlows) {
//
// TODO: The implementation below is not optimal:
@@ -1229,64 +1136,28 @@
// We should use the appropriate Titan/Gremlin query to filter-out
// the flows as appropriate.
//
- //ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
-
- ArrayList<IFlowPath> flowPathsWithoutFlowEntries = getAllFlowsWithoutFlowEntries();
-
+ ArrayList<IFlowPath> flowPathsWithoutFlowEntries =
+ getAllFlowsWithoutFlowEntries();
+
Collections.sort(flowPathsWithoutFlowEntries,
- new Comparator<IFlowPath>(){
- @Override
- public int compare(IFlowPath first, IFlowPath second) {
- // TODO Auto-generated method stub
- 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;
- }
- }
- );
+ 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> allFlows = getAllFlows();
-
- if (allFlows == null) {
- log.debug("Get FlowPathsSummary for {} {}: no FlowPaths found", flowId, maxFlows);
- return flowPaths;
- }
-
- Collections.sort(allFlows);
-
- for (FlowPath flow : allFlows) {
- flow.setFlowEntryMatch(null);
-
- // 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);
- } else {
- log.debug("Get FlowPathsSummary for {} {}: FlowPaths were found", flowId, maxFlows);
- }
-
- return flowPaths;
- */
}
/**
@@ -1300,11 +1171,7 @@
ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
try {
- if ((flowPathsObj = op.getAllFlowPaths()) != null) {
- log.debug("Get all FlowPaths: found FlowPaths");
- } else {
- log.debug("Get all FlowPaths: no FlowPaths found");
- }
+ flowPathsObj = op.getAllFlowPaths();
} catch (Exception e) {
// TODO: handle exceptions
op.rollback();
@@ -1338,39 +1205,24 @@
Iterable<IFlowPath> flowPathsObj = null;
ArrayList<IFlowPath> flowPathsObjArray = new ArrayList<IFlowPath>();
+ // TODO: Remove this op.commit() flow, because it is not needed?
op.commit();
-
+
try {
- if ((flowPathsObj = op.getAllFlowPaths()) != null) {
- log.debug("Get all FlowPaths: found FlowPaths");
- } else {
- log.debug("Get all FlowPaths: no FlowPaths found");
- }
+ flowPathsObj = op.getAllFlowPaths();
} catch (Exception e) {
// TODO: handle exceptions
op.rollback();
log.error(":getAllFlowPaths failed");
}
if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) {
- return new ArrayList<IFlowPath>(); // No Flows found
+ return flowPathsObjArray; // No Flows found
}
- for (IFlowPath flowObj : flowPathsObj){
- flowPathsObjArray.add(flowObj);
- }
- /*
- ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
- for (IFlowPath flowObj : flowPathsObj) {
- //
- // Extract the Flow state
- //
- FlowPath flowPath = extractFlowPath(flowObj);
- if (flowPath != null)
- flowPaths.add(flowPath);
- }
- */
+ for (IFlowPath flowObj : flowPathsObj)
+ flowPathsObjArray.add(flowObj);
- //conn.endTx(Transaction.COMMIT);
+ // conn.endTx(Transaction.COMMIT);
return flowPathsObjArray;
}
@@ -2326,39 +2178,4 @@
//
return (installFlowEntry(mySwitch, flowPath, flowEntry));
}
-
- /**
- * Install a Flow Entry on a remote controller.
- *
- * TODO: We need it now: Jono
- * - For now it will make a REST call to the remote controller.
- * - Internally, it needs to know the name of the remote controller.
- *
- * @param flowPath the flow path for the flow entry to install.
- * @param flowEntry the flow entry to install.
- * @return true on success, otherwise false.
- */
- public boolean installRemoteFlowEntry(FlowPath flowPath,
- FlowEntry flowEntry) {
- // TODO: We need it now: Jono
- // - For now it will make a REST call to the remote controller.
- // - Internally, it needs to know the name of the remote controller.
- return true;
- }
-
- /**
- * Remove a flow entry on a remote controller.
- *
- * @param flowPath the flow path for the flow entry to remove.
- * @param flowEntry the flow entry to remove.
- * @return true on success, otherwise false.
- */
- public boolean removeRemoteFlowEntry(FlowPath flowPath,
- FlowEntry flowEntry) {
- //
- // The installRemoteFlowEntry() method implements both installation
- // and removal of flow entries.
- //
- return (installRemoteFlowEntry(flowPath, flowEntry));
- }
}
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 cc67f6a..db82825 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -976,22 +976,4 @@
public final void testRemoveFlowEntrySuccessNormally() {
fail("not yet implemented");
}
-
- /**
- * Test method for {@link FlowManager#installRemoteFlowEntry(FlowPath, FlowEntry)}.
- * The method seems to be not implemented and not used for now.
- */
- @Ignore @Test
- public final void testInstallRemoteFlowEntrySuccessNormally() {
- fail("not yet implemented");
- }
-
- /**
- * Test method for {@link FlowManager#removeRemoteFlowEntry(FlowPath, FlowEntry)}.
- * The method seems to be not implemented and not used for now.
- */
- @Ignore @Test
- public final void testRemoveRemoteFlowEntrySuccessNormally() {
- fail("not yet implemented");
- }
}