Thomas Vachuska
Committed by Gerrit Code Review

OpenFlowRuleProvider is now configurable with respect to flowPollFrequency.

Change-Id: I3a559a9cd65df1ae56d80017696452788fc08d91
......@@ -23,8 +23,6 @@ import org.onosproject.net.provider.Provider;
*/
public interface FlowRuleProvider extends Provider {
static final int POLL_INTERVAL = 10;
/**
* Instructs the provider to apply the specified flow rules to their
* respective devices.
......
......@@ -16,7 +16,6 @@
package org.onosproject.net.statistic;
import com.google.common.base.MoreObjects;
import org.onosproject.net.flow.FlowRuleProvider;
/**
* Implementation of a load.
......@@ -29,6 +28,11 @@ public class DefaultLoad implements Load {
private final long time;
/**
* Indicates the flow statistics poll interval in seconds.
*/
private static int pollInterval = 10;
/**
* Creates an invalid load.
*/
public DefaultLoad() {
......@@ -50,9 +54,19 @@ public class DefaultLoad implements Load {
this.isValid = true;
}
/**
* Sets the poll interval in seconds. Used solely for the purpose of
* computing the load.
*
* @param newPollInterval poll interval duration in seconds
*/
public static void setPollInterval(int newPollInterval) {
pollInterval = newPollInterval;
}
@Override
public long rate() {
return (current - previous) / FlowRuleProvider.POLL_INTERVAL;
return (current - previous) / pollInterval;
}
@Override
......
......@@ -31,4 +31,10 @@
<description>ONOS OpenFlow protocol flow provider</description>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
</dependencies>
</project>
......
......@@ -15,87 +15,86 @@
*/
package org.onosproject.provider.of.flow.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timeout;
import org.jboss.netty.util.TimerTask;
import org.onlab.util.SharedExecutors;
import org.onosproject.openflow.controller.OpenFlowSwitch;
import org.onosproject.openflow.controller.RoleState;
import org.onlab.util.Timer;
import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest;
import org.projectfloodlight.openflow.types.OFPort;
import org.projectfloodlight.openflow.types.TableId;
import org.slf4j.Logger;
public class FlowStatsCollector implements TimerTask {
import java.util.Timer;
import java.util.TimerTask;
private final Logger log = getLogger(getClass());
import static org.slf4j.LoggerFactory.getLogger;
private final HashedWheelTimer timer = Timer.getTimer();
private final OpenFlowSwitch sw;
private final int refreshInterval;
/**
* Collects flow statistics for the specified switch.
*/
class FlowStatsCollector {
private Timeout timeout;
private final Logger log = getLogger(getClass());
private boolean stopTimer = false;;
public static final int SECONDS = 1000;
public FlowStatsCollector(OpenFlowSwitch sw, int refreshInterval) {
private final OpenFlowSwitch sw;
private Timer timer;
private TimerTask task;
private int pollInterval;
/**
* Creates a new collector for the given switch and poll frequency.
*
* @param timer timer to use for scheduling
* @param sw switch to pull
* @param pollInterval poll frequency in seconds
*/
FlowStatsCollector(Timer timer, OpenFlowSwitch sw, int pollInterval) {
this.timer = timer;
this.sw = sw;
this.refreshInterval = refreshInterval;
this.pollInterval = pollInterval;
}
@Override
public void run(Timeout timeout) throws Exception {
log.trace("Collecting stats for {}", this.sw.getStringId());
sendFlowStatistics();
if (!this.stopTimer) {
log.trace("Scheduling stats collection in {} seconds for {}",
this.refreshInterval, this.sw.getStringId());
timeout.getTimer().newTimeout(this, refreshInterval,
TimeUnit.SECONDS);
}
/**
* Adjusts poll frequency.
*
* @param pollInterval poll frequency in seconds
*/
synchronized void adjustPollInterval(int pollInterval) {
this.pollInterval = pollInterval;
task.cancel();
task = new InternalTimerTask();
timer.scheduleAtFixedRate(task, pollInterval * SECONDS, pollInterval * 1000);
}
private void sendFlowStatistics() {
if (log.isTraceEnabled()) {
log.trace("sendFlowStatistics {}:{}", sw.getStringId(), sw.getRole());
private class InternalTimerTask extends TimerTask {
@Override
public void run() {
if (sw.getRole() == RoleState.MASTER) {
log.trace("Collecting stats for {}", sw.getStringId());
OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest()
.setMatch(sw.factory().matchWildcardAll())
.setTableId(TableId.ALL)
.setOutPort(OFPort.NO_MASK)
.build();
sw.sendMsg(request);
}
}
if (sw.getRole() != RoleState.MASTER) {
// Switch not master.
return;
}
OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest()
.setMatch(sw.factory().matchWildcardAll())
.setTableId(TableId.ALL)
.setOutPort(OFPort.NO_MASK)
.build();
this.sw.sendMsg(request);
}
public void start() {
/*
* Initially start polling quickly. Then drop down to configured value
*/
log.info("Starting Stats collection thread for {}",
this.sw.getStringId());
timeout = timer.newTimeout(this, 1, TimeUnit.SECONDS);
public synchronized void start() {
// Initially start polling quickly. Then drop down to configured value
log.debug("Starting Stats collection thread for {}", sw.getStringId());
task = new InternalTimerTask();
SharedExecutors.getTimer().scheduleAtFixedRate(task, 1 * SECONDS,
pollInterval * SECONDS);
}
public void stop() {
log.info("Stopping Stats collection thread for {}",
this.sw.getStringId());
this.stopTimer = true;
timeout.cancel();
public synchronized void stop() {
log.debug("Stopping Stats collection thread for {}", sw.getStringId());
task.cancel();
task = null;
}
}
......