Skip to content
Snippets Groups Projects
Commit 96b67018 authored by Srinivasan Ramasubramanian's avatar Srinivasan Ramasubramanian
Browse files

Topology recompute task now runs every half a second.

parent 33472a60
No related branches found
No related tags found
No related merge requests found
...@@ -120,6 +120,8 @@ public class TopologyManager implements ...@@ -120,6 +120,8 @@ public class TopologyManager implements
*/ */
protected boolean dtLinksUpdated; protected boolean dtLinksUpdated;
protected final int TOPOLOGY_COMPUTE_INTERVAL_MS = 500;
/** /**
* Thread for recomputing topology. The thread is always running, * Thread for recomputing topology. The thread is always running,
* however the function applyUpdates() has a blocking call. * however the function applyUpdates() has a blocking call.
...@@ -133,10 +135,15 @@ public class TopologyManager implements ...@@ -133,10 +135,15 @@ public class TopologyManager implements
@Override @Override
public void run() { public void run() {
try { try {
updateTopology(); if (ldUpdates.peek() != null)
updateTopology();
} }
catch (Exception e) { catch (Exception e) {
log.error("Error in topology instance task thread", e); log.error("Error in topology instance task thread", e);
} finally {
if (floodlightProvider.getRole() != Role.SLAVE)
newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS,
TimeUnit.MILLISECONDS);
} }
} }
} }
...@@ -158,20 +165,10 @@ public class TopologyManager implements ...@@ -158,20 +165,10 @@ public class TopologyManager implements
@Override @Override
public void linkDiscoveryUpdate(LDUpdate update) { public void linkDiscoveryUpdate(LDUpdate update) {
boolean scheduleFlag = false;
// if there's no udpates in the queue, then
// we need to schedule an update.
if (ldUpdates.peek() == null)
scheduleFlag = true;
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
log.trace("Queuing update: {}", update); log.trace("Queuing update: {}", update);
} }
ldUpdates.add(update); ldUpdates.add(update);
if (scheduleFlag) {
newInstanceTask.reschedule(1, TimeUnit.MICROSECONDS);
}
} }
// **************** // ****************
...@@ -582,12 +579,14 @@ public class TopologyManager implements ...@@ -582,12 +579,14 @@ public class TopologyManager implements
if (oldRole == Role.SLAVE) { if (oldRole == Role.SLAVE) {
log.debug("Re-computing topology due " + log.debug("Re-computing topology due " +
"to HA change from SLAVE->MASTER"); "to HA change from SLAVE->MASTER");
newInstanceTask.reschedule(1, TimeUnit.MILLISECONDS); newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS,
TimeUnit.MILLISECONDS);
} }
break; break;
case SLAVE: case SLAVE:
log.debug("Clearing topology due to " + log.debug("Clearing topology due to " +
"HA change to SLAVE"); "HA change to SLAVE");
ldUpdates.clear();
clearCurrentTopology(); clearCurrentTopology();
break; break;
default: default:
...@@ -666,6 +665,11 @@ public class TopologyManager implements ...@@ -666,6 +665,11 @@ public class TopologyManager implements
public void startUp(FloodlightModuleContext context) { public void startUp(FloodlightModuleContext context) {
ScheduledExecutorService ses = threadPool.getScheduledExecutor(); ScheduledExecutorService ses = threadPool.getScheduledExecutor();
newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker()); newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());
if (floodlightProvider.getRole() != Role.SLAVE)
newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS,
TimeUnit.MILLISECONDS);
linkDiscovery.addListener(this); linkDiscovery.addListener(this);
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this); floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
floodlightProvider.addHAListener(this); floodlightProvider.addHAListener(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment