suibin
Committed by Ray Milkey

fix calculation on event rate

Conflicts:
	providers/null/link/src/main/java/org/onosproject/provider/nil/link/impl/NullLinkProvider.java
	tools/package/etc/org.onosproject.provider.nil.link.impl.NullLinkProvider.cfg
Change-Id: I955abaec4c3906441ada91d97ed30854a8ce44f8
......@@ -16,7 +16,6 @@
package org.onosproject.provider.nil.link.impl;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.util.Tools.delay;
import static org.onlab.util.Tools.namedThreads;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onlab.util.Tools.toHex;
......@@ -112,6 +111,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
@Property(name = "eventRate", value = "0",
label = "Duration between Link Event")
private int eventRate = DEFAULT_RATE;
private int checkRateDuration = 10;
// For flicker = true, duration between events in msec.
@Property(name = "neighbors", value = "",
......@@ -337,12 +337,36 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
@Override
public void run() {
long startTime = System.currentTimeMillis();
long countEvent = 0;
float effLoad = 0;
while (!linkDriver.isShutdown()) {
//Assuming eventRate is in microsecond unit
if (countEvent <= checkRateDuration * 1000000 / eventRate) {
for (LinkDescription desc : descriptions.values()) {
providerService.linkVanished(desc);
delay(eventRate);
countEvent++;
try {
TimeUnit.MICROSECONDS.sleep(eventRate);
} catch (InterruptedException e) {
log.warn(String.valueOf(e));
}
providerService.linkDetected(desc);
delay(eventRate);
countEvent++;
try {
TimeUnit.MICROSECONDS.sleep(eventRate);
} catch (InterruptedException e) {
log.warn(String.valueOf(e));
}
}
} else {
// log in WARN the effective load generation rate in events/sec, every 10 seconds
effLoad = (float) (countEvent * 1000 / (System.currentTimeMillis() - startTime));
log.warn("Effective Loading is {} events/second", String.valueOf(effLoad));
countEvent = 0;
startTime = System.currentTimeMillis();
}
}
}
......
......@@ -4,7 +4,9 @@
# If enabled, sets the time between LinkEvent generation,
# in milliseconds.
#
# eventRate = 2000
#eventRate = 100000
#
# Set order of islands to chain together, in a line.
......