summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-03-13 10:34:53 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2016-03-13 10:34:53 +0200
commit4c7026517965700242fe4aebf47f099a6ffd7842 (patch)
tree1f4e48284163b42985c158ba96680cbada085346
parent45ba3d4bbe5d5d5155f1cf0c1c80b14b9fa61c6c (diff)
hlt add traffic_control: action=poll, reset, sync_run, clear_stats. add wait_on_traffic. fix cleanup_session to remove streams
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py3
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py70
-rw-r--r--src/rpc-server/trex_rpc_cmd.cpp2
3 files changed, 55 insertions, 20 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 c7503ab0..ec821f68 100644
--- 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
@@ -1755,9 +1755,6 @@ class STLClient(object):
ports = ports if ports is not None else self.get_acquired_ports()
ports = self._validate_port_list(ports)
-
- expr = time.time() + timeout
-
return set(self.get_active_ports()).intersection(ports)
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
index a74824d2..056a9afa 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
@@ -303,6 +303,7 @@ class CStreamsPerPort(defaultdict):
# save HLT args to modify streams later
def save_stream_args(self, ports_list, stream_id, stream_hlt_args):
+ if stream_id is None: return # no stream_id, can't save TODO: remove this check ASAP
if stream_hlt_args.get('load_profile'): return # can't modify profiles, don't save
if not self.hlt_history: raise STLError('CStreamsPerPort: this object works only with HLT history, try init with hlt_history = True')
if type(stream_id) not in (int, long): raise STLError('CStreamsPerPort: stream_id should be number')
@@ -401,9 +402,17 @@ class CTRexHltApi(object):
except Exception as e:
return HLT_ERR('Unable to determine which ports to release: %s' % e if isinstance(e, STLError) else traceback.format_exc())
try:
+ self.trex_client.stop(port_list)
+ except Exception as e:
+ return HLT_ERR('Unable to stop traffic %s: %s' % (port_list, e if isinstance(e, STLError) else traceback.format_exc()))
+ try:
+ self.trex_client.remove_all_streams(port_list)
+ except Exception as e:
+ return HLT_ERR('Unable to remove all streams %s: %s' % (port_list, e if isinstance(e, STLError) else traceback.format_exc()))
+ try:
self.trex_client.release(port_list)
except Exception as e:
- return HLT_ERR('Unable to release ports %s: %s' % (port_list, e))
+ return HLT_ERR('Unable to release ports %s: %s' % (port_list, e if isinstance(e, STLError) else traceback.format_exc()))
try:
self.trex_client.disconnect(stop_traffic = False, release_ports = False)
except Exception as e:
@@ -585,30 +594,53 @@ class CTRexHltApi(object):
kwargs = merge_kwargs(traffic_control_kwargs, user_kwargs)
action = kwargs['action']
port_handle = kwargs['port_handle']
- ALLOWED_ACTIONS = ['clear_stats', 'run', 'stop', 'sync_run']
+ ALLOWED_ACTIONS = ['clear_stats', 'run', 'stop', 'sync_run', 'poll', 'reset']
if action not in ALLOWED_ACTIONS:
return HLT_ERR('Action must be one of the following values: {actions}'.format(actions=ALLOWED_ACTIONS))
- if type(port_handle) is not list:
- port_handle = [port_handle]
if action == 'run':
try:
self.trex_client.start(ports = port_handle)
except Exception as e:
return HLT_ERR('Could not start traffic: %s' % e if isinstance(e, STLError) else traceback.format_exc())
- return HLT_OK(stopped = 0)
+
+ elif action == 'sync_run': # (clear_stats + run)
+ try:
+ self.trex_client.clear_stats(ports = port_handle)
+ self.trex_client.start(ports = port_handle)
+ except Exception as e:
+ return HLT_ERR('Unable to do sync_run: %s' % e if isinstance(e, STLError) else traceback.format_exc())
elif action == 'stop':
try:
self.trex_client.stop(ports = port_handle)
except Exception as e:
- return HLT_ERR('Could not start traffic: %s' % e if isinstance(e, STLError) else traceback.format_exc())
- return HLT_OK(stopped = 1)
- else:
- return HLT_ERR("Action '{0}' is not supported yet on TRex".format(action))
+ return HLT_ERR('Could not stop traffic: %s' % e if isinstance(e, STLError) else traceback.format_exc())
+
+ elif action == 'reset':
+ try:
+ self.trex_client.reset(ports = port_handle)
+ for port in port_handle:
+ if port in self._streams_history:
+ del self._streams_history[port]
+ except Exception as e:
+ return HLT_ERR('Could not reset traffic: %s' % e if isinstance(e, STLError) else traceback.format_exc())
+
+ elif action == 'clear_stats':
+ try:
+ self.trex_client.clear_stats(ports = port_handle)
+ except Exception as e:
+ return HLT_ERR('Could not clear stats: %s' % e if isinstance(e, STLError) else traceback.format_exc())
+
+ elif action != 'poll': # at poll just return 'stopped' status
+ return HLT_ERR("Action '%s' is not supported yet on TRex" % action)
- # if we arrived here, this means that operation FAILED!
- return HLT_ERR("Probably action '%s' is not implemented" % action)
+ try:
+ is_traffic_active = self.trex_client.is_traffic_active(ports = port_handle)
+ except Exception as e:
+ return HLT_ERR('Unable to determine ports status: %s' % e if isinstance(e, STLError) else traceback.format_exc())
+
+ return HLT_OK(stopped = not is_traffic_active)
def traffic_stats(self, **user_kwargs):
if not self.trex_client:
@@ -653,6 +685,16 @@ class CTRexHltApi(object):
}
return HLT_OK(hlt_stats_dict)
+ # timeout = maximal time to wait
+ def wait_on_traffic(self, port_handle = None, timeout = 60):
+ try:
+ self.trex_client.wait_on_traffic(port_handle, timeout)
+ except Exception as e:
+ return HLT_ERR('Unable to run wait_on_traffic: %s' % e if isinstance(e, STLError) else traceback.format_exc())
+
+###########################
+# Private functions #
+###########################
# remove streams from given port(s).
# stream_id can be:
@@ -689,11 +731,6 @@ class CTRexHltApi(object):
return
raise STLError('_remove_stream: wrong param %s' % stream_id)
-
-###########################
-# Private functions #
-###########################
-
@staticmethod
def _parse_port_list(port_list):
if type(port_list) is str:
@@ -1481,6 +1518,7 @@ def correct_direction(user_kwargs, kwargs):
dst_arg = 'ipv6_dst_' + arg[9:]
user_kwargs[arg], user_kwargs[dst_arg] = kwargs[dst_arg], kwargs[arg]
+# we produce packets without fcs, so need to reduce produced sizes
def correct_sizes(kwargs):
for arg in kwargs.keys():
if type(arg) in (int, long):
diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp
index 77869d0d..caf161e3 100644
--- a/src/rpc-server/trex_rpc_cmd.cpp
+++ b/src/rpc-server/trex_rpc_cmd.cpp
@@ -51,7 +51,7 @@ TrexRpcCommand::check_param_count(const Json::Value &params, int expected, Json:
if (params.size() != expected) {
std::stringstream ss;
- ss << "method expects '" << expected << "' paramteres, '" << params.size() << "' provided";
+ ss << "method expects '" << expected << "' parameter(s), '" << params.size() << "' provided";
generate_parse_err(result, ss.str());
}
}