diff options
author | 2016-11-22 17:16:36 +0200 | |
---|---|---|
committer | 2016-11-22 17:16:36 +0200 | |
commit | 75585e213de850395b6bcd0aff0841cd9cced92c (patch) | |
tree | fc2733edff683748929317a610c83fc33cb7935f /scripts/automation/trex_control_plane/stl | |
parent | 6c18d6a2173ff2f3ecd031046077cd65d3ed8785 (diff) |
RX features - few tweaks
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
4 files changed, 41 insertions, 14 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 1ddf359b..9e727993 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, PassiveTimer, is_valid_ipv4, is_valid_mac +from .utils.common import list_intersect, list_difference, is_sub_list, PassiveTimer, is_valid_ipv4, is_valid_mac, list_remove_dup from .utils.text_opts import * from functools import wraps @@ -1067,7 +1067,7 @@ class STLClient(object): if not port_id in valid_ports: raise STLError("Port ID '{0}' is not a valid port ID - valid values: {1}".format(port_id, valid_ports)) - return port_id_list + return list_remove_dup(port_id_list) # transmit request on the RPC link @@ -1372,6 +1372,12 @@ class STLClient(object): if port_obj.is_active()] + def get_resolvable_ports (self): + return [port_id + for port_id, port_obj in self.ports.items() + if port_obj.is_acquired() and port_obj.get_dst_addr()['ipv4'] is not None] + + # get paused ports def get_paused_ports (self, owned = True): if owned: @@ -2895,21 +2901,25 @@ class STLClient(object): """ # by default - resolve all the ports that are configured with IPv4 dest if ports is None: - ports = [port_id for port_id in self.get_acquired_ports() if self.ports[port_id].get_dst_addr()['ipv4'] is not None] + ports = self.get_resolvable_ports() if not ports: - raise STLError('resolve - No ports configured with destination as IPv4') + raise STLError('No ports configured with destination as IPv4') active_ports = list(set(self.get_active_ports()).intersection(ports)) if active_ports: - raise STLError('resolve - Port(s) {0} are active, please stop them before resolving'.format(active_ports)) + raise STLError('Port(s) {0} are active, please stop them before resolving'.format(active_ports)) ports = self._validate_port_list(ports) self.logger.pre_cmd("Resolving destination on port(s) {0}:".format(ports)) with self.logger.supress(): rc = self.__resolve(ports, retries) + self.logger.post_cmd(rc) - + + if rc: + self.logger.log(rc) + if not rc: raise STLError(rc) @@ -3722,9 +3732,7 @@ class STLClient(object): parsing_opts.PORT_LIST_WITH_ALL, parsing_opts.RETRIES) - resolvable_ports = [port_id for port_id in self.get_acquired_ports() if self.ports[port_id].get_dst_addr() is not None] - - opts = parser.parse_args(line.split(), default_ports = resolvable_ports, verify_acquired = True) + opts = parser.parse_args(line.split(), default_ports = self.get_resolvable_ports(), verify_acquired = True) if not opts: return opts 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 aef325ef..aeff64de 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 @@ -924,9 +924,13 @@ class Port(object): return {'ipv4': dst_ipv4, 'mac' : dst_mac} + # return True if the port is resolved (either has MAC as dest of ARP resolution) def is_resolved (self): return (self.get_dst_addr()['mac'] != None) - + + # return True if the port is valid for resolve (has an IPv4 address as dest) + def is_resolvable (self): + return (self.get_dst_addr()['ipv4'] != None) @writeable def arp_resolve (self, retries): @@ -1204,10 +1208,10 @@ class ARPResolver(Resolver): src = self.port.get_src_addr() if dst['ipv4'] is None: - return self.port.err('ARP resolve - port does not have an IPv4 as destination') + return self.port.err("Port has a non-IPv4 destination: '{0}'".format(dst['mac'])) if src['ipv4'] is None: - return self.port.err('ARP Resolve - port does not have an IPv4 address configured') + return self.port.err('Port must have an IPv4 source address configured') # invalidate the current ARP resolution (if exists) return self.port.invalidate_arp() @@ -1240,7 +1244,10 @@ class ARPResolver(Resolver): rc = self.port.set_arp_resolution(arp.psrc, arp.hwsrc) - return rc + if not rc: + return rc + + return self.port.ok('Port {0} - Recieved ARP reply from: {1}, hw: {2}'.format(self.port.port_id, arp.psrc, arp.hwsrc)) def on_timeout_err (self, retries): 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 02e13fd7..cbbacb27 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 @@ -98,3 +98,13 @@ def is_valid_ipv4 (addr): def is_valid_mac (mac): return bool(re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower())) +def list_remove_dup (l): + tmp = list() + + for x in l: + if not x in tmp: + tmp.append(x) + + return tmp + + diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py index f9c416d8..f20bdad6 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py @@ -1,6 +1,6 @@ import argparse from collections import namedtuple, OrderedDict -from .common import list_intersect, list_difference, is_valid_ipv4, is_valid_mac +from .common import list_intersect, list_difference, is_valid_ipv4, is_valid_mac, list_remove_dup from .text_opts import format_text from ..trex_stl_types import * from .constants import ON_OFF_DICT, UP_DOWN_DICT, FLOW_CTRL_DICT @@ -644,6 +644,8 @@ class CCmdArgParser(argparse.ArgumentParser): else: opts.ports = default_ports + opts.ports = list_remove_dup(opts.ports) + # so maybe we have ports configured invalid_ports = list_difference(opts.ports, self.stateless_client.get_all_ports()) if invalid_ports: |