diff --git a/src/main/java/net/floodlightcontroller/flowcache/FlowReconcileManager.java b/src/main/java/net/floodlightcontroller/flowcache/FlowReconcileManager.java index 1eb9691a88c6e9eb1681206e819a4c22083e89b7..773f94505c2d3ee5bf721527d2d85dfc4bd1a55c 100644 --- a/src/main/java/net/floodlightcontroller/flowcache/FlowReconcileManager.java +++ b/src/main/java/net/floodlightcontroller/flowcache/FlowReconcileManager.java @@ -10,6 +10,7 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleException; @@ -64,7 +65,8 @@ public class FlowReconcileManager /** a minimum flow reconcile rate so that it won't stave */ protected static int MIN_FLOW_RECONCILE_PER_SECOND = 200; - /** once per second */ + /** start flow reconcile in 10ms after a new reconcile request is received. + * The max delay is 1 second. */ protected static int FLOW_RECONCILE_DELAY_MILLISEC = 10; protected Date lastReconcileTime; @@ -72,7 +74,7 @@ public class FlowReconcileManager protected static final String EnableConfigKey = "enable"; protected boolean flowReconcileEnabled; - volatile public int flowReconcileThreadRunCount; + public AtomicInteger flowReconcileThreadRunCount; @Override public synchronized void addFlowReconcileListener( @@ -215,7 +217,7 @@ public class FlowReconcileManager flowReconcileEnabled = false; } - flowReconcileThreadRunCount = 0; + flowReconcileThreadRunCount = new AtomicInteger(0); lastReconcileTime = new Date(0); logger.debug("FlowReconcile is {}", flowReconcileEnabled); } @@ -313,7 +315,7 @@ public class FlowReconcileManager } // Flush the flowCache counters. updateFlush(); - flowReconcileThreadRunCount++; + flowReconcileThreadRunCount.incrementAndGet(); } else { if (logger.isTraceEnabled()) { logger.trace("No flow to be reconciled."); diff --git a/src/test/java/net/floodlightcontroller/flowcache/FlowReconcileMgrTest.java b/src/test/java/net/floodlightcontroller/flowcache/FlowReconcileMgrTest.java index 0dcbb357e3c5fa81483f6663422d3654a224a0e5..accac8e4ceb90d0eeb80b2331efdff0fdde1c8f8 100644 --- a/src/test/java/net/floodlightcontroller/flowcache/FlowReconcileMgrTest.java +++ b/src/test/java/net/floodlightcontroller/flowcache/FlowReconcileMgrTest.java @@ -117,7 +117,7 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { flowReconcileMgr.addFlowReconcileListener(r3); int pre_flowReconcileThreadRunCount = - flowReconcileMgr.flowReconcileThreadRunCount; + flowReconcileMgr.flowReconcileThreadRunCount.get(); Date startTime = new Date(); OFMatchReconcile ofmRcIn = new OFMatchReconcile(); try { @@ -147,11 +147,11 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { }).anyTimes(); pre_flowReconcileThreadRunCount = - flowReconcileMgr.flowReconcileThreadRunCount; + flowReconcileMgr.flowReconcileThreadRunCount.get(); startTime = new Date(); replay(r1, r2, r3); flowReconcileMgr.reconcileFlow(ofmRcIn); - while (flowReconcileMgr.flowReconcileThreadRunCount <= + while (flowReconcileMgr.flowReconcileThreadRunCount.get() <= pre_flowReconcileThreadRunCount) { Thread.sleep(10); Date currTime = new Date(); @@ -174,12 +174,12 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { }).anyTimes(); pre_flowReconcileThreadRunCount = - flowReconcileMgr.flowReconcileThreadRunCount; + flowReconcileMgr.flowReconcileThreadRunCount.get(); startTime = new Date(); replay(r1, r2, r3); flowReconcileMgr.reconcileFlow(ofmRcIn); - while (flowReconcileMgr.flowReconcileThreadRunCount <= + while (flowReconcileMgr.flowReconcileThreadRunCount.get() <= pre_flowReconcileThreadRunCount) { Thread.sleep(10); Date currTime = new Date(); @@ -197,12 +197,12 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { .andReturn(Command.STOP).times(1); pre_flowReconcileThreadRunCount = - flowReconcileMgr.flowReconcileThreadRunCount; + flowReconcileMgr.flowReconcileThreadRunCount.get(); startTime = new Date(); replay(r1, r2, r3); flowReconcileMgr.reconcileFlow(ofmRcIn); - while (flowReconcileMgr.flowReconcileThreadRunCount <= + while (flowReconcileMgr.flowReconcileThreadRunCount.get() <= pre_flowReconcileThreadRunCount) { Thread.sleep(10); Date currTime = new Date(); @@ -227,11 +227,11 @@ public class FlowReconcileMgrTest extends FloodlightTestCase { .andReturn(Command.STOP).times(1); pre_flowReconcileThreadRunCount = - flowReconcileMgr.flowReconcileThreadRunCount; + flowReconcileMgr.flowReconcileThreadRunCount.get(); startTime = new Date(); replay(r1, r2, r3); flowReconcileMgr.reconcileFlow(ofmRcIn); - while (flowReconcileMgr.flowReconcileThreadRunCount <= + while (flowReconcileMgr.flowReconcileThreadRunCount.get() <= pre_flowReconcileThreadRunCount) { Thread.sleep(10); Date currTime = new Date();