Thomas Vachuska

Fixing port-stats DBZ

Change-Id: I2bd1f9d94c1441d6bdcde00a5d2a3e595e0c5c4f
......@@ -17,6 +17,8 @@ package org.onosproject.net.statistic;
import com.google.common.base.MoreObjects;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Implementation of a load.
*/
......@@ -62,6 +64,7 @@ public class DefaultLoad implements Load {
* @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();
......
......@@ -46,8 +46,11 @@ import static org.slf4j.LoggerFactory.getLogger;
@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 class PortStatisticsManager implements PortStatisticsService {
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;
}
......