diff options
Diffstat (limited to 'scripts')
5 files changed, 148 insertions, 34 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index b33b0447..5ea959ac 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -488,7 +488,7 @@ class TRexConsole(TRexGeneralCmd): ############# update @verify_connected def do_update(self, line): - '''update speed of port(s)currently transmitting traffic\n''' + '''update speed of port(s) currently transmitting traffic\n''' self.stateless_client.update_line(line) @@ -549,6 +549,13 @@ class TRexConsole(TRexGeneralCmd): '''Clear cached local statistics\n''' self.stateless_client.clear_stats_line(line) + @verify_connected + def do_service (self, line): + '''Sets port(s) service mode state''' + self.stateless_client.service_line(line) + + def help_service (self, line): + self.do_service("-h") def help_clear(self): self.do_clear("-h") 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 cc20e088..fd41491e 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 @@ -878,6 +878,15 @@ class STLClient(object): return rc + def __set_service_mode (self, port_id_list, enabled): + port_id_list = self.__ports(port_id_list) + rc = RC() + + for port_id in port_id_list: + rc.add(self.ports[port_id].set_service_mode(enabled)) + + return rc + # connect to server def __connect(self): @@ -1387,6 +1396,12 @@ class STLClient(object): if port_obj.is_acquired() and port_obj.get_dst_addr()['ipv4'] is not None] + def get_service_enabled_ports(self): + return [port_id + for port_id, port_obj in self.ports.items() + if port_obj.is_acquired() and port_obj.is_service_mode_on()] + + # get paused ports def get_paused_ports (self, owned = True): if owned: @@ -1854,9 +1869,7 @@ class STLClient(object): raise STLError("pkt_size should be a value between 64 and 9216: '{0}'".format(pkt_size)) validate_type('count', count, int) - - - + self.logger.pre_cmd("Pinging {0} from port {1} with {2} bytes of data:".format(dst_ipv4, src_port, pkt_size)) @@ -2164,7 +2177,10 @@ class STLClient(object): unresolved_ports = [port_id for port_id in ports if not self.ports[port_id].is_resolved()] if unresolved_ports and not force: raise STLError("Port(s) {0} have unresolved destination addresses - please resolve them or specify 'force'".format(unresolved_ports)) - + + if self.get_service_enabled_ports() and not force: + raise STLError("Port(s) {0} are under service mode - please disable service mode or specify 'force'".format(self.get_service_enabled_ports())) + @__api_check(True) def start (self, @@ -2827,7 +2843,7 @@ class STLClient(object): validate_type('led_on', led_on, (bool, type(None))) validate_type('flow_ctrl', flow_ctrl, (int, type(None))) validate_choice('rxf', rxf, ['hw', 'all']) - + # common attributes for all ports cmn_attr_dict = {} @@ -2880,7 +2896,35 @@ class STLClient(object): self.resolve(ports = resolve_ports) + + @__api_check(True) + def set_service_mode (self, ports = None, enabled = True): + """ + Set service mode for port(s) + In service mode ports will respond to ARP, PING and etc. + + :parameters: + ports - for which ports to configure service mode on/off + enabled - True for activating service mode, False for disabling + :raises: + + :exe:'STLError' + + """ + # by default take all acquired ports + ports = ports if ports is not None else self.get_acquired_ports() + ports = self._validate_port_list(ports) + + if enabled: + self.logger.pre_cmd('Enabling service mode on port(s) {0}:'.format(ports)) + else: + self.logger.pre_cmd('Disabling service mode on port(s) {0}:'.format(ports)) + + rc = self.__set_service_mode(ports, enabled) + self.logger.post_cmd(rc) + if not rc: + raise STLError(rc) + @__api_check(True) def resolve (self, ports = None, retries = 0): @@ -3078,7 +3122,7 @@ class STLClient(object): try: rc = f(*args) except STLError as e: - client.logger.log("Log:\n" + format_text(e.brief() + "\n", 'bold')) + client.logger.log("Action has failed with the following error:\n" + format_text(e.brief() + "\n", 'bold')) return RC_ERR(e.brief()) # if got true - print time @@ -3697,18 +3741,12 @@ class STLClient(object): self.set_rx_sniffer_line.__doc__, parsing_opts.PORT_LIST_WITH_ALL, parsing_opts.OUTPUT_FILENAME, - parsing_opts.LIMIT, - parsing_opts.ALL_FILES) + parsing_opts.LIMIT) opts = parser.parse_args(line.split(), default_ports = self.get_acquired_ports(), verify_acquired = True) if not opts: return opts - rxf = 'all' if opts.all else None - - if rxf: - self.set_port_attr(opts.ports, rxf = rxf) - self.set_rx_sniffer(opts.ports, opts.output_filename, opts.limit) return RC_OK() @@ -3840,10 +3878,37 @@ class STLClient(object): return "{0}(read-only)>".format(prefix) elif self.is_all_ports_acquired(): - return "{0}>".format(prefix) + p = prefix + + if self.get_service_enabled_ports(): + if self.get_service_enabled_ports() == self.get_acquired_ports(): + p += '(service)' + else: + p += '(service: {0})'.format(self.get_service_enabled_ports()) + + return "{0}>".format(p) else: return "{0} {1}>".format(prefix, self.get_acquired_ports()) + @__console + def service_line (self, line): + '''Configures port for service mode. + In service mode ports will reply to ARP, PING + and etc. + ''' + + parser = parsing_opts.gen_parser(self, + "service", + self.service_line.__doc__, + parsing_opts.PORT_LIST_WITH_ALL, + parsing_opts.SERVICE_OFF) + + opts = parser.parse_args(line.split()) + if not opts: + return opts + + self.set_service_mode(ports = opts.ports, enabled = opts.enabled) + 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 389a942b..4ac31fba 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 @@ -489,6 +489,9 @@ class Port(object): @owned def set_rx_sniffer (self, pcap_filename, limit): + if not self.is_service_mode_on(): + return self.err('port service mode must be enabled for performing RX capturing') + params = {"handler": self.handler, "port_id": self.port_id, "type": "capture", @@ -529,7 +532,8 @@ class Port(object): if rc.bad(): return self.err(rc.err()) - return self.ok() + # instead of updating manualy - let's sync with the server + return self.sync() @@ -684,6 +688,9 @@ class Port(object): json_attr['ipv4'] = {'addr': kwargs.get('ipv4')} if kwargs.get('dest') is not None: + if not self.is_service_mode_on(): + return self.err('setting destination requires port to be in service mode') + json_attr['dest'] = {'addr': kwargs.get('dest')} @@ -698,6 +705,26 @@ class Port(object): # update the dictionary from the server explicitly return self.sync() + + @owned + def set_service_mode (self, enabled): + rc = self.set_attr(rx_filter_mode = 'all' if enabled else 'hw') + if not rc: + return rc + + if not enabled: + rc = self.remove_rx_queue() + if not rc: + return rc + + rc = self.remove_rx_sniffer() + if not rc: + return rc + + return self.ok() + + def is_service_mode_on (self): + return self.get_rx_filter_mode() == 'all' @writeable def push_remote (self, pcap_filename, ipg_usec, speedup, count, duration, is_dual, slave_handler): @@ -877,6 +904,8 @@ class Port(object): return {'mac': src_mac, 'ipv4': src_ipv4} + def get_rx_filter_mode (self): + return self.__attr['rx_filter_mode'] def get_dst_addr (self): dest = self.__attr['dest'] @@ -904,10 +933,16 @@ class Port(object): @writeable def arp_resolve (self, retries): + if not self.is_service_mode_on(): + return self.err('port service mode must be enabled for performing ARP resolution') + return ARPResolver(self).resolve(retries) @writeable def ping (self, ping_ipv4, pkt_size): + if not self.is_service_mode_on(): + return self.err('port service mode must be enabled for performing ping') + return PingResolver(self, ping_ipv4, pkt_size).resolve() diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_rx_features.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_rx_features.py index 3754e608..e0fc1724 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_rx_features.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_rx_features.py @@ -46,11 +46,6 @@ class Resolver(object): # add the stream(s) self.port.add_streams(self.generate_request()) - - rc = self.port.set_attr(rx_filter_mode = 'all') - if not rc: - return rc - rc = self.port.set_rx_queue(size = 100) if not rc: return rc @@ -59,7 +54,6 @@ class Resolver(object): finally: # best effort restore - self.port.set_attr(rx_filter_mode = 'hw') self.port.remove_rx_queue() self.port.remove_all_streams() @@ -202,19 +196,13 @@ class PingResolver(Resolver): if self.dst['mac'] is None: return self.port.err('Ping - port has an unresolved destination, cannot determine next hop MAC address') - if self.ping_ip == self.src['ipv4']: - return self.port.err('Ping - cannot ping own IP') - return self.port.ok() # return a list of streams for request def generate_request (self): - src = self.port.get_src_addr() - dst = self.port.get_dst_addr() - - base_pkt = Ether(dst = dst['mac'])/IP(src = src['ipv4'], dst = self.ping_ip)/ICMP(type = 8) + base_pkt = Ether(dst = self.dst['mac'])/IP(src = self.src['ipv4'], dst = self.ping_ip)/ICMP(type = 8) pad = max(0, self.pkt_size - len(base_pkt)) base_pkt = base_pkt / (pad * 'x') @@ -222,6 +210,8 @@ class PingResolver(Resolver): #base_pkt.show2() s1 = STLStream( packet = STLPktBuilder(pkt = base_pkt), mode = STLTXSingleBurst(total_pkts = 1) ) + self.base_pkt = base_pkt + return [s1] # return None for more packets otherwise RC object @@ -230,23 +220,32 @@ class PingResolver(Resolver): if not 'ICMP' in scapy_pkt: return None - #scapy_pkt.show2() ip = scapy_pkt['IP'] - + if ip.dst != self.src['ipv4']: + return None + icmp = scapy_pkt['ICMP'] dt = pkt['ts'] - self.start_ts + # echo reply if icmp.type == 0: - # echo reply + # check seq + if icmp.seq != self.base_pkt['ICMP'].seq: + return None return self.port.ok('Reply from {0}: bytes={1}, time={2:.2f}ms, TTL={3}'.format(ip.src, len(pkt['binary']), dt * 1000, ip.ttl)) # unreachable elif icmp.type == 3: + # check seq + if icmp.payload.seq != self.base_pkt['ICMP'].seq: + return None return self.port.ok('Reply from {0}: Destination host unreachable'.format(icmp.src)) + else: - scapy_pkt.show2() - return self.port.err('unknown ICMP reply') + # skip any other types + #scapy_pkt.show2() + return None 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 7ae22e89..66a17a03 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 @@ -60,6 +60,8 @@ PING_IPV4 = 40 PING_COUNT = 41 PKT_SIZE = 42 +SERVICE_OFF = 43 + GLOBAL_STATS = 50 PORT_STATS = 51 PORT_STATUS = 52 @@ -575,6 +577,12 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], 'default': None, 'help': "Core mask - only cores responding to the bit mask will be active"}), + SERVICE_OFF: ArgumentPack(['--off'], + {'action': 'store_false', + 'dest': 'enabled', + 'default': True, + 'help': 'Deactivates services on port(s)'}), + # advanced options PORT_LIST_WITH_ALL: ArgumentGroup(MUTEX, [PORT_LIST, ALL_PORTS], |