Committed by
Gerrit Code Review
OpenFlowRuleProvider is now configurable with respect to flowPollFrequency.
Change-Id: I3a559a9cd65df1ae56d80017696452788fc08d91
Showing
5 changed files
with
80 additions
and
63 deletions
| ... | @@ -23,8 +23,6 @@ import org.onosproject.net.provider.Provider; | ... | @@ -23,8 +23,6 @@ import org.onosproject.net.provider.Provider; |
| 23 | */ | 23 | */ |
| 24 | public interface FlowRuleProvider extends Provider { | 24 | public interface FlowRuleProvider extends Provider { |
| 25 | 25 | ||
| 26 | - static final int POLL_INTERVAL = 10; | ||
| 27 | - | ||
| 28 | /** | 26 | /** |
| 29 | * Instructs the provider to apply the specified flow rules to their | 27 | * Instructs the provider to apply the specified flow rules to their |
| 30 | * respective devices. | 28 | * respective devices. | ... | ... |
| ... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
| 16 | package org.onosproject.net.statistic; | 16 | package org.onosproject.net.statistic; |
| 17 | 17 | ||
| 18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
| 19 | -import org.onosproject.net.flow.FlowRuleProvider; | ||
| 20 | 19 | ||
| 21 | /** | 20 | /** |
| 22 | * Implementation of a load. | 21 | * Implementation of a load. |
| ... | @@ -29,6 +28,11 @@ public class DefaultLoad implements Load { | ... | @@ -29,6 +28,11 @@ public class DefaultLoad implements Load { |
| 29 | private final long time; | 28 | private final long time; |
| 30 | 29 | ||
| 31 | /** | 30 | /** |
| 31 | + * Indicates the flow statistics poll interval in seconds. | ||
| 32 | + */ | ||
| 33 | + private static int pollInterval = 10; | ||
| 34 | + | ||
| 35 | + /** | ||
| 32 | * Creates an invalid load. | 36 | * Creates an invalid load. |
| 33 | */ | 37 | */ |
| 34 | public DefaultLoad() { | 38 | public DefaultLoad() { |
| ... | @@ -50,9 +54,19 @@ public class DefaultLoad implements Load { | ... | @@ -50,9 +54,19 @@ public class DefaultLoad implements Load { |
| 50 | this.isValid = true; | 54 | this.isValid = true; |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 57 | + /** | ||
| 58 | + * Sets the poll interval in seconds. Used solely for the purpose of | ||
| 59 | + * computing the load. | ||
| 60 | + * | ||
| 61 | + * @param newPollInterval poll interval duration in seconds | ||
| 62 | + */ | ||
| 63 | + public static void setPollInterval(int newPollInterval) { | ||
| 64 | + pollInterval = newPollInterval; | ||
| 65 | + } | ||
| 66 | + | ||
| 53 | @Override | 67 | @Override |
| 54 | public long rate() { | 68 | public long rate() { |
| 55 | - return (current - previous) / FlowRuleProvider.POLL_INTERVAL; | 69 | + return (current - previous) / pollInterval; |
| 56 | } | 70 | } |
| 57 | 71 | ||
| 58 | @Override | 72 | @Override | ... | ... |
| ... | @@ -31,4 +31,10 @@ | ... | @@ -31,4 +31,10 @@ |
| 31 | 31 | ||
| 32 | <description>ONOS OpenFlow protocol flow provider</description> | 32 | <description>ONOS OpenFlow protocol flow provider</description> |
| 33 | 33 | ||
| 34 | + <dependencies> | ||
| 35 | + <dependency> | ||
| 36 | + <groupId>org.osgi</groupId> | ||
| 37 | + <artifactId>org.osgi.compendium</artifactId> | ||
| 38 | + </dependency> | ||
| 39 | + </dependencies> | ||
| 34 | </project> | 40 | </project> | ... | ... |
| ... | @@ -15,87 +15,86 @@ | ... | @@ -15,87 +15,86 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.of.flow.impl; | 16 | package org.onosproject.provider.of.flow.impl; |
| 17 | 17 | ||
| 18 | -import static org.slf4j.LoggerFactory.getLogger; | 18 | +import org.onlab.util.SharedExecutors; |
| 19 | - | ||
| 20 | -import java.util.concurrent.TimeUnit; | ||
| 21 | - | ||
| 22 | -import org.jboss.netty.util.HashedWheelTimer; | ||
| 23 | -import org.jboss.netty.util.Timeout; | ||
| 24 | -import org.jboss.netty.util.TimerTask; | ||
| 25 | import org.onosproject.openflow.controller.OpenFlowSwitch; | 19 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 26 | import org.onosproject.openflow.controller.RoleState; | 20 | import org.onosproject.openflow.controller.RoleState; |
| 27 | -import org.onlab.util.Timer; | ||
| 28 | import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; | 21 | import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; |
| 29 | import org.projectfloodlight.openflow.types.OFPort; | 22 | import org.projectfloodlight.openflow.types.OFPort; |
| 30 | import org.projectfloodlight.openflow.types.TableId; | 23 | import org.projectfloodlight.openflow.types.TableId; |
| 31 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
| 32 | 25 | ||
| 33 | -public class FlowStatsCollector implements TimerTask { | 26 | +import java.util.Timer; |
| 27 | +import java.util.TimerTask; | ||
| 34 | 28 | ||
| 35 | - private final Logger log = getLogger(getClass()); | 29 | +import static org.slf4j.LoggerFactory.getLogger; |
| 36 | 30 | ||
| 37 | - private final HashedWheelTimer timer = Timer.getTimer(); | 31 | +/** |
| 38 | - private final OpenFlowSwitch sw; | 32 | + * Collects flow statistics for the specified switch. |
| 39 | - private final int refreshInterval; | 33 | + */ |
| 34 | +class FlowStatsCollector { | ||
| 40 | 35 | ||
| 41 | - private Timeout timeout; | 36 | + private final Logger log = getLogger(getClass()); |
| 42 | 37 | ||
| 43 | - private boolean stopTimer = false;; | 38 | + public static final int SECONDS = 1000; |
| 44 | 39 | ||
| 45 | - public FlowStatsCollector(OpenFlowSwitch sw, int refreshInterval) { | 40 | + private final OpenFlowSwitch sw; |
| 41 | + private Timer timer; | ||
| 42 | + private TimerTask task; | ||
| 43 | + | ||
| 44 | + private int pollInterval; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Creates a new collector for the given switch and poll frequency. | ||
| 48 | + * | ||
| 49 | + * @param timer timer to use for scheduling | ||
| 50 | + * @param sw switch to pull | ||
| 51 | + * @param pollInterval poll frequency in seconds | ||
| 52 | + */ | ||
| 53 | + FlowStatsCollector(Timer timer, OpenFlowSwitch sw, int pollInterval) { | ||
| 54 | + this.timer = timer; | ||
| 46 | this.sw = sw; | 55 | this.sw = sw; |
| 47 | - this.refreshInterval = refreshInterval; | 56 | + this.pollInterval = pollInterval; |
| 48 | } | 57 | } |
| 49 | 58 | ||
| 50 | - @Override | 59 | + /** |
| 51 | - public void run(Timeout timeout) throws Exception { | 60 | + * Adjusts poll frequency. |
| 52 | - log.trace("Collecting stats for {}", this.sw.getStringId()); | 61 | + * |
| 53 | - | 62 | + * @param pollInterval poll frequency in seconds |
| 54 | - sendFlowStatistics(); | 63 | + */ |
| 55 | - | 64 | + synchronized void adjustPollInterval(int pollInterval) { |
| 56 | - if (!this.stopTimer) { | 65 | + this.pollInterval = pollInterval; |
| 57 | - log.trace("Scheduling stats collection in {} seconds for {}", | 66 | + task.cancel(); |
| 58 | - this.refreshInterval, this.sw.getStringId()); | 67 | + task = new InternalTimerTask(); |
| 59 | - timeout.getTimer().newTimeout(this, refreshInterval, | 68 | + timer.scheduleAtFixedRate(task, pollInterval * SECONDS, pollInterval * 1000); |
| 60 | - TimeUnit.SECONDS); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - | ||
| 64 | } | 69 | } |
| 65 | 70 | ||
| 66 | - private void sendFlowStatistics() { | 71 | + private class InternalTimerTask extends TimerTask { |
| 67 | - if (log.isTraceEnabled()) { | 72 | + @Override |
| 68 | - log.trace("sendFlowStatistics {}:{}", sw.getStringId(), sw.getRole()); | 73 | + public void run() { |
| 74 | + if (sw.getRole() == RoleState.MASTER) { | ||
| 75 | + log.trace("Collecting stats for {}", sw.getStringId()); | ||
| 76 | + OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() | ||
| 77 | + .setMatch(sw.factory().matchWildcardAll()) | ||
| 78 | + .setTableId(TableId.ALL) | ||
| 79 | + .setOutPort(OFPort.NO_MASK) | ||
| 80 | + .build(); | ||
| 81 | + sw.sendMsg(request); | ||
| 82 | + } | ||
| 69 | } | 83 | } |
| 70 | - if (sw.getRole() != RoleState.MASTER) { | ||
| 71 | - // Switch not master. | ||
| 72 | - return; | ||
| 73 | - } | ||
| 74 | - OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() | ||
| 75 | - .setMatch(sw.factory().matchWildcardAll()) | ||
| 76 | - .setTableId(TableId.ALL) | ||
| 77 | - .setOutPort(OFPort.NO_MASK) | ||
| 78 | - .build(); | ||
| 79 | - | ||
| 80 | - this.sw.sendMsg(request); | ||
| 81 | - | ||
| 82 | } | 84 | } |
| 83 | 85 | ||
| 84 | - public void start() { | 86 | + public synchronized void start() { |
| 85 | - | 87 | + // Initially start polling quickly. Then drop down to configured value |
| 86 | - /* | 88 | + log.debug("Starting Stats collection thread for {}", sw.getStringId()); |
| 87 | - * Initially start polling quickly. Then drop down to configured value | 89 | + task = new InternalTimerTask(); |
| 88 | - */ | 90 | + SharedExecutors.getTimer().scheduleAtFixedRate(task, 1 * SECONDS, |
| 89 | - log.info("Starting Stats collection thread for {}", | 91 | + pollInterval * SECONDS); |
| 90 | - this.sw.getStringId()); | ||
| 91 | - timeout = timer.newTimeout(this, 1, TimeUnit.SECONDS); | ||
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | - public void stop() { | 94 | + public synchronized void stop() { |
| 95 | - log.info("Stopping Stats collection thread for {}", | 95 | + log.debug("Stopping Stats collection thread for {}", sw.getStringId()); |
| 96 | - this.sw.getStringId()); | 96 | + task.cancel(); |
| 97 | - this.stopTimer = true; | 97 | + task = null; |
| 98 | - timeout.cancel(); | ||
| 99 | } | 98 | } |
| 100 | 99 | ||
| 101 | } | 100 | } | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment