Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/core/api/src/main/java/org/onlab/onos/net/statistic/Load.java b/core/api/src/main/java/org/onlab/onos/net/statistic/Load.java
new file mode 100644
index 0000000..534b10c
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/statistic/Load.java
@@ -0,0 +1,20 @@
+package org.onlab.onos.net.statistic;
+
+/**
+ * Simple data repository for link load information.
+ */
+public interface Load {
+
+ /**
+ * Obtain the current observed rate on a link.
+ * @return long value
+ */
+ long rate();
+
+ /**
+ * Obtain the latest counter viewed on that link.
+ * @return long value
+ */
+ long latest();
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/statistic/StatisticService.java b/core/api/src/main/java/org/onlab/onos/net/statistic/StatisticService.java
new file mode 100644
index 0000000..b1809d7
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/statistic/StatisticService.java
@@ -0,0 +1,51 @@
+package org.onlab.onos.net.statistic;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.Path;
+import org.onlab.onos.net.flow.FlowRule;
+
+/**
+ * Service for obtaining statistic information about link in the system.
+ * Statistics are obtained from the FlowRuleService in order to minimize the
+ * amount of hammering occuring at the dataplane.
+ */
+public interface StatisticService {
+
+ /**
+ * Obtain the load for a the ingress to the given link.
+ * @param link the link to query.
+ * @return a {@link org.onlab.onos.net.statistic.Load Load}
+ */
+ Load load(Link link);
+
+ /**
+ * Obtain the load for the given port.
+ * @param connectPoint the port to query
+ * @return a {@link org.onlab.onos.net.statistic.Load}
+ */
+ Load load(ConnectPoint connectPoint);
+
+ /**
+ * Find the most loaded link along a path.
+ * @param path the path to search in
+ * @return the most loaded {@link org.onlab.onos.net.Link}.
+ */
+ Link max(Path path);
+
+ /**
+ * Find the least loaded link along a path.
+ * @param path the path to search in
+ * @return the least loaded {@link org.onlab.onos.net.Link}.
+ */
+ Link min(Path path);
+
+ /**
+ * Returns the highest hitter (a flow rule) of for a given port, ie. the
+ * flow rule which is generating the most load.
+ * @param connectPoint the port
+ * @return the flow rule
+ */
+ FlowRule highestHitter(ConnectPoint connectPoint);
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/statistic/StatisticStore.java b/core/api/src/main/java/org/onlab/onos/net/statistic/StatisticStore.java
new file mode 100644
index 0000000..d0d625c
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/statistic/StatisticStore.java
@@ -0,0 +1,45 @@
+package org.onlab.onos.net.statistic;
+
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.flow.FlowEntry;
+import org.onlab.onos.net.flow.FlowRule;
+
+import java.util.Set;
+
+/**
+ * Store to house the computed statistics.
+ */
+public interface StatisticStore {
+
+ /**
+ * Lay the foundation for receiving flow stats for this rule.
+ * @param rule a {@link org.onlab.onos.net.flow.FlowRule}
+ */
+ void prepareForStatistics(FlowRule rule);
+
+ /**
+ * Remove entries associated with this rule.
+ a @param rule {@link org.onlab.onos.net.flow.FlowRule}
+ */
+ void removeFromStatistics(FlowRule rule);
+
+ /**
+ * Adds a stats observation for a flow rule.
+ * @param rule a {@link org.onlab.onos.net.flow.FlowEntry}
+ */
+ void addOrUpdateStatistic(FlowEntry rule);
+
+ /**
+ * Fetches the current observed stats values.
+ * @param connectPoint the port to fetch information for
+ * @return set of current flow rules
+ */
+ Set<FlowEntry> getCurrentStatistic(ConnectPoint connectPoint);
+
+ /**
+ * Fetches the current observed stats values.
+ * @param connectPoint the port to fetch information for
+ * @return set of current values
+ */
+ Set<FlowEntry> getPreviousStatistic(ConnectPoint connectPoint);
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/statistic/package-info.java b/core/api/src/main/java/org/onlab/onos/net/statistic/package-info.java
new file mode 100644
index 0000000..445a0f3
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/statistic/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Service for looking up statistics on links.
+ */
+package org.onlab.onos.net.statistic;
\ No newline at end of file
diff --git a/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java b/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java
new file mode 100644
index 0000000..4bca215
--- /dev/null
+++ b/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java
@@ -0,0 +1,89 @@
+package org.onlab.onos.net.statistic.impl;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.Path;
+import org.onlab.onos.net.flow.FlowRule;
+import org.onlab.onos.net.flow.FlowRuleEvent;
+import org.onlab.onos.net.flow.FlowRuleListener;
+import org.onlab.onos.net.flow.FlowRuleService;
+import org.onlab.onos.net.statistic.Load;
+import org.onlab.onos.net.statistic.StatisticService;
+import org.onlab.onos.net.statistic.StatisticStore;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Provides an implementation of the Statistic Service.
+ */
+@Component(immediate = true)
+@Service
+public class StatisticManager implements StatisticService {
+
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FlowRuleService flowRuleService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected StatisticStore statisticStore;
+
+ private final InternalFlowRuleListener listener = new InternalFlowRuleListener();
+
+ @Activate
+ public void activate() {
+ flowRuleService.addListener(listener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ flowRuleService.removeListener(listener);
+ log.info("Stopped");
+ }
+
+ @Override
+ public Load load(Link link) {
+ return null;
+ }
+
+ @Override
+ public Load load(ConnectPoint connectPoint) {
+ return null;
+ }
+
+ @Override
+ public Link max(Path path) {
+ return null;
+ }
+
+ @Override
+ public Link min(Path path) {
+ return null;
+ }
+
+ @Override
+ public FlowRule highestHitter(ConnectPoint connectPoint) {
+ return null;
+ }
+
+ /**
+ * Internal flow rule event listener.
+ */
+ private class InternalFlowRuleListener implements FlowRuleListener {
+
+ @Override
+ public void event(FlowRuleEvent event) {
+
+ }
+ }
+
+
+}
diff --git a/core/net/src/main/java/org/onlab/onos/net/statistic/impl/package-info.java b/core/net/src/main/java/org/onlab/onos/net/statistic/impl/package-info.java
new file mode 100644
index 0000000..cbe301c
--- /dev/null
+++ b/core/net/src/main/java/org/onlab/onos/net/statistic/impl/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Core subsystem for responding to statistical inquiries.
+ */
+package org.onlab.onos.net.statistic.impl;
\ No newline at end of file