diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-03-14 13:48:40 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-03-14 13:48:40 +0200 |
commit | 22f33006471cfed556e6987f88d3d9f7e532687a (patch) | |
tree | d82c114419afa32076cb2edb687a1137aa3967f7 /scripts/automation/trex_control_plane/stl | |
parent | d82201e2da3beb0e81e0c8ba30600d87f1b8276f (diff) | |
parent | 22e06f3c3532890ad336341c279012afc0710a9d (diff) |
merge cleanup
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
6 files changed, 92 insertions, 44 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 1d109988..c76abeea 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 @@ -1406,7 +1406,8 @@ class STLClient(object): if not rc: raise STLError(rc) - return [stream.get_id() for stream in streams] + # return the stream IDs + return rc.data() @__api_check(True) @@ -1769,9 +1770,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) @@ -1958,8 +1956,8 @@ class STLClient(object): try: profile = STLProfile.load(opts.file[0]) except STLError as e: - print format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold') - print e.brief() + "\n" + self.logger.log(format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold')) + self.logger.log(e.brief() + "\n") return @@ -2221,7 +2219,7 @@ class STLClient(object): self.start(ports = opts.ports, duration = opts.duration, force = opts.force) except STLError as e: - print e.brief() + stl.logger.log(e.brief()) return return True @@ -2245,7 +2243,7 @@ class STLClient(object): try: self.set_port_attr(opts.ports, opts.prom) except STLError as e: - print e.brief() + stl.logger.log(brief()) return 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 81676df8..98336ef2 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/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py index 2a8bedb8..0558360d 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py @@ -227,8 +227,9 @@ class Port(object): rc = self.transmit_batch(batch) + ret = RC() for i, single_rc in enumerate(rc): - if single_rc: + if single_rc.rc: stream_id = batch[i].params['stream_id'] next_id = batch[i].params['stream']['next_stream_id'] self.streams[stream_id] = {'next_id' : next_id, @@ -236,10 +237,13 @@ class Port(object): 'mode' : streams_list[i].get_mode(), 'rate' : streams_list[i].get_rate()} + ret.add(RC_OK(data = stream_id)) + else: + ret.add(RC(*single_rc)) self.state = self.STATE_STREAMS if (len(self.streams) > 0) else self.STATE_IDLE - return self.ok() if rc else self.err(str(rc)) + return ret if ret else self.err(str(ret)) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index bb877586..12bf881a 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -828,8 +828,8 @@ class CRxStats(CTRexStats): # copy timestamp field output['ts'] = current['ts'] - # aggregate all the PG ids (previous and current) - pg_ids = filter(is_intable, set(prev.keys() + current.keys())) + # we care only about the current active keys + pg_ids = filter(is_intable, current.keys()) for pg_id in pg_ids: @@ -854,6 +854,13 @@ class CRxStats(CTRexStats): self.calculate_bw_for_pg(output[pg_id], prev_pg, diff_sec) + # cleanp old reference values - they are dead + ref_pg_ids = filter(is_intable, self.reference_stats.keys()) + + deleted_pg_ids = set(ref_pg_ids).difference(pg_ids) + for d_pg_id in deleted_pg_ids: + del self.reference_stats[d_pg_id] + return output diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py index 8596bbfe..20600791 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py @@ -5,26 +5,15 @@ from trex_stl_packet_builder_scapy import * # will destroy all streams/data on the ports def stl_map_ports (client, ports = None): # by default use all ports - if ports == None: + if ports is None: ports = client.get_all_ports() - # reset the ports - client.reset(ports) - - # generate streams - base_pkt = STLPktBuilder(pkt = Ether()/IP()) - - # send something initial to calm down switches with arps etc. - stream = STLStream(packet = base_pkt, - mode = STLTXSingleBurst(pps = 100000, total_pkts = 1)) - client.add_streams(stream, ports) - - client.start(ports, mult = "50%") - client.wait_on_traffic(ports) - client.reset(ports) + stl_send_3_pkts(client, ports) tx_pkts = {} pkts = 1 + base_pkt = STLPktBuilder(pkt = Ether()/IP()) + for port in ports: tx_pkts[pkts] = port stream = STLStream(packet = base_pkt, @@ -75,3 +64,15 @@ def stl_map_ports (client, ports = None): return table +# reset ports and send 3 packets from each acquired port +def stl_send_3_pkts(client, ports = None): + + base_pkt = STLPktBuilder(pkt = Ether()/IP()) + stream = STLStream(packet = base_pkt, + mode = STLTXSingleBurst(pps = 100000, total_pkts = 3)) + + client.reset(ports) + client.add_streams(stream, ports) + client.start(ports, mult = "50%") + client.wait_on_traffic(ports) + client.reset(ports) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py index 496bea13..bd48f939 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py @@ -5,7 +5,7 @@ from trex_stl_exceptions import * import types RpcCmdData = namedtuple('RpcCmdData', ['method', 'params']) -TupleRC = namedtuple('RC', ['rc', 'data', 'is_warn']) +TupleRC = namedtuple('RCT', ['rc', 'data', 'is_warn']) class RpcResponseStatus(namedtuple('RpcResponseStatus', ['success', 'id', 'msg'])): __slots__ = () |