Skip to content

Commit 62ddb6f

Browse files
author
Emil Gustafsson
committed
format
Signed-off-by: Emil Gustafsson <[email protected]>
1 parent 3b41dcd commit 62ddb6f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/main/java/com/cisco/trex/stateless/TRexClient.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.LinkedList;
3636
import java.util.List;
3737
import java.util.Map;
38+
import java.util.Map.Entry;
3839
import java.util.Queue;
3940
import java.util.Set;
4041
import java.util.function.Predicate;
@@ -380,6 +381,68 @@ public void removeRxFilters(int portIndex, int profileId) {
380381
callMethod("remove_rx_filters", payload);
381382
}
382383

384+
/**
385+
* Block until traffic on specified port(s) has ended
386+
*
387+
* @param timeoutInSecounds 0 means blocking
388+
* @param rxDelayMs Time to wait (in milliseconds) after last packet was sent, until RX filters
389+
* used for measuring flow statistics and latency are removed. This value should reflect the
390+
* time it takes packets which were transmitted to arrive to the destination. After this time,
391+
* RX filters will be removed, and packets arriving for per flow statistics feature and
392+
* latency flows will be counted as errors.
393+
* @param ports Ports on which to execute the command
394+
*/
395+
public void waitOnTrafficToFinish(int timeoutInSecounds, int rxDelayMs, Port... ports) {
396+
Map<Port, Boolean> portTrafficMap = new HashMap<>();
397+
long endTime = System.currentTimeMillis() + timeoutInSecounds * 1000;
398+
399+
for (Port port : ports) {
400+
portTrafficMap.put(port, true);
401+
}
402+
while (portTrafficMap.containsValue(true)) {
403+
for (Entry<Port, Boolean> entry : portTrafficMap.entrySet()) {
404+
if (entry.getValue()) { // port is still true, meaning still running traffic
405+
// set port to false if traffic is stopped(IDLE)
406+
entry.setValue(!getPortStatus(entry.getKey().getIndex()).get().getState().equals("IDLE"));
407+
}
408+
}
409+
if (System.currentTimeMillis() > endTime) {
410+
break;
411+
}
412+
}
413+
414+
removeRxFiltersWithDelay(rxDelayMs, ports);
415+
}
416+
417+
/**
418+
* Delay some time to let packets arrive at destination port before removing filters
419+
*
420+
* @param rxDelayMs
421+
* @param ports
422+
*/
423+
protected void removeRxFiltersWithDelay(int rxDelayMs, Port... ports) {
424+
int rxDelayToUse;
425+
if (rxDelayMs <= 0) {
426+
if (ports[0].is_virtual) {
427+
rxDelayToUse = 100;
428+
} else {
429+
rxDelayToUse = 10;
430+
}
431+
} else {
432+
rxDelayToUse = rxDelayMs;
433+
}
434+
435+
try {
436+
Thread.sleep(rxDelayToUse);
437+
} catch (InterruptedException e) {
438+
// Do nothing
439+
}
440+
441+
for (Port port : ports) {
442+
removeRxFilters(port.getIndex(), 0);
443+
}
444+
}
445+
383446
/** Set promiscuous mode, Enable interface to receive packets from all mac addresses */
384447
public void setPromiscuousMode(int portIndex, boolean enabled) {
385448
Map<String, Object> payload = createPayload(portIndex);

0 commit comments

Comments
 (0)