summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-09-29 09:13:06 +0300
committerimarom <imarom@cisco.com>2016-09-29 09:13:06 +0300
commit13abd76b59cb1fd2094f5919b5e044d2f2338895 (patch)
tree0440c710a7b7d8b4ba7966d641a6bb92a2b0f0eb
parentbc02d31292c32469fe3d8fae6f529450512cf6f0 (diff)
https://trex-tgn.cisco.com/youtrack/issue/trex-247
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py9
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py18
2 files changed, 23 insertions, 4 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
index b5ae0f94..2d7cb269 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
@@ -12,7 +12,7 @@ from .trex_stl_types import *
from .trex_stl_async_client import CTRexAsyncClient
from .utils import parsing_opts, text_tables, common
-from .utils.common import list_intersect, list_difference, is_sub_list
+from .utils.common import list_intersect, list_difference, is_sub_list, PassiveTimer
from .utils.text_opts import *
from functools import wraps
@@ -2521,7 +2521,7 @@ class STLClient(object):
@__api_check(True)
- def wait_on_traffic (self, ports = None, timeout = 60, rx_delay_ms = 10):
+ def wait_on_traffic (self, ports = None, timeout = None, rx_delay_ms = 10):
"""
.. _wait_on_traffic:
@@ -2533,6 +2533,7 @@ class STLClient(object):
timeout : int
timeout in seconds
+ default will be blocking
rx_delay_ms : int
Time to wait (in milliseconds) after last packet was sent, until RX filters used for
@@ -2551,7 +2552,7 @@ class STLClient(object):
ports = self._validate_port_list(ports)
- expr = time.time() + timeout
+ timer = PassiveTimer(timeout)
# wait while any of the required ports are active
while set(self.get_active_ports()).intersection(ports):
@@ -2561,7 +2562,7 @@ class STLClient(object):
raise STLError("subscriber thread is dead")
time.sleep(0.01)
- if time.time() > expr:
+ if timer.has_expired():
raise STLTimeoutError(timeout)
# remove any RX filters
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
index 6835ea5f..638684c3 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
@@ -2,6 +2,7 @@ import os
import sys
import string
import random
+import time
try:
import pwd
@@ -65,3 +66,20 @@ def list_difference (l1, l2):
def is_sub_list (l1, l2):
return set(l1) <= set(l2)
+# a simple passive timer
+class PassiveTimer(object):
+
+ # timeout_sec = None means forever
+ def __init__ (self, timeout_sec):
+ if timeout_sec != None:
+ self.expr_sec = time.time() + timeout_sec
+ else:
+ self.expr_sec = None
+
+ def has_expired (self):
+ # if no timeout was set - return always false
+ if self.expr_sec == None:
+ return False
+
+ return (time.time() > self.expr_sec)
+