Fixing port-stats DBZ
Change-Id: I2bd1f9d94c1441d6bdcde00a5d2a3e595e0c5c4f
diff --git a/core/api/src/main/java/org/onosproject/net/statistic/DefaultLoad.java b/core/api/src/main/java/org/onosproject/net/statistic/DefaultLoad.java
index 12f87fe..91af1f3 100644
--- a/core/api/src/main/java/org/onosproject/net/statistic/DefaultLoad.java
+++ b/core/api/src/main/java/org/onosproject/net/statistic/DefaultLoad.java
@@ -17,6 +17,8 @@
import com.google.common.base.MoreObjects;
+import static com.google.common.base.Preconditions.checkArgument;
+
/**
* Implementation of a load.
*/
@@ -62,6 +64,7 @@
* @param interval poll interval for this load
*/
public DefaultLoad(long current, long previous, int interval) {
+ checkArgument(interval > 0, "Interval must be greater than 0");
this.current = current;
this.previous = previous;
this.time = System.currentTimeMillis();
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java
index 9d6e1cb..19b093c 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/impl/PortStatisticsManager.java
@@ -46,8 +46,11 @@
@Component(immediate = true)
@Service
public class PortStatisticsManager implements PortStatisticsService {
+
private final Logger log = getLogger(getClass());
+ private static final int SECOND = 1_000;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@@ -73,9 +76,9 @@
public Load load(ConnectPoint connectPoint) {
DataPoint c = current.get(connectPoint);
DataPoint p = previous.get(connectPoint);
- if (c != null && p != null) {
+ if (c != null && p != null && (c.time > p.time + SECOND)) {
return new DefaultLoad(c.stats.bytesSent(), p.stats.bytesSent(),
- (int) (c.time - p.time) / 1000);
+ (int) (c.time - p.time) / SECOND);
}
return null;
}