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 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.provider.nil.link.impl; 16 package org.onosproject.provider.nil.link.impl;
17 17
18 import static com.google.common.base.Strings.isNullOrEmpty; 18 import static com.google.common.base.Strings.isNullOrEmpty;
19 -import static org.onlab.util.Tools.delay;
20 import static org.onlab.util.Tools.namedThreads; 19 import static org.onlab.util.Tools.namedThreads;
21 import static org.slf4j.LoggerFactory.getLogger; 20 import static org.slf4j.LoggerFactory.getLogger;
22 import static org.onlab.util.Tools.toHex; 21 import static org.onlab.util.Tools.toHex;
...@@ -112,6 +111,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -112,6 +111,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
112 @Property(name = "eventRate", value = "0", 111 @Property(name = "eventRate", value = "0",
113 label = "Duration between Link Event") 112 label = "Duration between Link Event")
114 private int eventRate = DEFAULT_RATE; 113 private int eventRate = DEFAULT_RATE;
114 + private int checkRateDuration = 10;
115 115
116 // For flicker = true, duration between events in msec. 116 // For flicker = true, duration between events in msec.
117 @Property(name = "neighbors", value = "", 117 @Property(name = "neighbors", value = "",
...@@ -337,12 +337,36 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -337,12 +337,36 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
337 337
338 @Override 338 @Override
339 public void run() { 339 public void run() {
340 + long startTime = System.currentTimeMillis();
341 + long countEvent = 0;
342 + float effLoad = 0;
343 +
340 while (!linkDriver.isShutdown()) { 344 while (!linkDriver.isShutdown()) {
341 - for (LinkDescription desc : descriptions.values()) { 345 +
342 - providerService.linkVanished(desc); 346 + //Assuming eventRate is in microsecond unit
343 - delay(eventRate); 347 + if (countEvent <= checkRateDuration * 1000000 / eventRate) {
344 - providerService.linkDetected(desc); 348 + for (LinkDescription desc : descriptions.values()) {
345 - delay(eventRate); 349 + providerService.linkVanished(desc);
350 + countEvent++;
351 + try {
352 + TimeUnit.MICROSECONDS.sleep(eventRate);
353 + } catch (InterruptedException e) {
354 + log.warn(String.valueOf(e));
355 + }
356 + providerService.linkDetected(desc);
357 + countEvent++;
358 + try {
359 + TimeUnit.MICROSECONDS.sleep(eventRate);
360 + } catch (InterruptedException e) {
361 + log.warn(String.valueOf(e));
362 + }
363 + }
364 + } else {
365 + // log in WARN the effective load generation rate in events/sec, every 10 seconds
366 + effLoad = (float) (countEvent * 1000 / (System.currentTimeMillis() - startTime));
367 + log.warn("Effective Loading is {} events/second", String.valueOf(effLoad));
368 + countEvent = 0;
369 + startTime = System.currentTimeMillis();
346 } 370 }
347 } 371 }
348 } 372 }
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
4 # If enabled, sets the time between LinkEvent generation, 4 # If enabled, sets the time between LinkEvent generation,
5 # in milliseconds. 5 # in milliseconds.
6 # 6 #
7 -# eventRate = 2000 7 +
8 +#eventRate = 100000
9 +
8 10
9 # 11 #
10 # Set order of islands to chain together, in a line. 12 # Set order of islands to chain together, in a line.
......