diff options
author | 2016-12-13 18:15:22 +0200 | |
---|---|---|
committer | 2016-12-13 18:15:22 +0200 | |
commit | 0fdd81a94d62592b0ec9888022d793f670c8476f (patch) | |
tree | ec52cd0f090793e26f67bc017d402b737acd71b5 /scripts/automation/trex_control_plane/stl/trex_stl_lib | |
parent | 0c45815234abbb79b147b8093eb19e274ee65f52 (diff) |
Major refactor - L2 / L3 modes for ports
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib')
5 files changed, 116 insertions, 101 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 80daadd2..ee5db1f0 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 @@ -1843,15 +1843,14 @@ class STLClient(object): raise STLError(rc) - @__api_check(True) - def set_source_addr (self, port, addr): + def set_l2_mode (self, port, dst_mac): """ - Configures a port with a source address + Sets the port mode to L2 :parameters: - port - the port to set the source address - addr - source address. currently only IPv4 is supported + port - the port to set the source address + dst_mac - destination MAC :raises: + :exc:`STLError` """ @@ -1859,33 +1858,27 @@ class STLClient(object): validate_type('port', port, int) if port not in self.get_all_ports(): raise STLError("port {0} is not a valid port id".format(port)) - - if not is_valid_ipv4(addr): - raise STLError("addr is not a valid IPv4 address: '{0}'".format(addr)) - - self.logger.pre_cmd("Setting port {0} source address as '{1}': ".format(port, addr)) - rc = self.ports[port].set_source_addr(addr) - self.logger.post_cmd(rc) + + if not is_valid_mac(dst_mac): + raise STLError("dest_mac is not a valid MAC address: '{0}'".format(dst_mac)) + + self.logger.pre_cmd("Setting port {0} in L2 mode: ".format(port)) + rc = self.ports[port].set_l2_mode(dst_mac) + self.logger.post_cmd(rc) if not rc: raise STLError(rc) - - # for MAC dest - no resolve - if not self.ports[port].get_dst_addr()['ipv4']: - return rc - # resolve the address - return self.resolve(ports = port, verbose = False) - @__api_check(True) - def set_dest_addr (self, port, addr): + def set_l3_mode (self, port, src_ipv4, dst_ipv4): """ - Configures a port with a destination address + Sets the port mode to L3 :parameters: - port - the port to set the destination address - addr - destination address. can be either MAC or IPv4 + port - the port to set the source address + src_ipv4 - IPv4 source address for the port + dst_ipv4 - IPv4 destination address :raises: + :exc:`STLError` """ @@ -1893,24 +1886,29 @@ class STLClient(object): validate_type('port', port, int) if port not in self.get_all_ports(): raise STLError("port {0} is not a valid port id".format(port)) - - if not is_valid_ipv4(addr) and not is_valid_mac(addr): - raise STLError("addr is not a valid IPv4 address or a MAC address: '{0}'".format(addr)) - - if is_valid_ipv4(addr) and not self.ports[port].get_src_addr()['ipv4']: - raise STLError("cannot configure destination as IPv4 address without IPv4 source address") - self.logger.pre_cmd("Setting port {0} destination address as '{1}': ".format(port, addr)) - rc = self.ports[port].set_dest_addr(addr) - self.logger.post_cmd(rc) + if not is_valid_ipv4(src_ipv4): + raise STLError("src_ipv4 is not a valid IPv4 address: '{0}'".format(src_ipv4)) + + if not is_valid_ipv4(dst_ipv4): + raise STLError("dst_ipv4 is not a valid IPv4 address: '{0}'".format(dst_ipv4)) + + self.logger.pre_cmd("Setting port {0} in L3 mode: ".format(port)) + rc = self.ports[port].set_l3_mode(src_ipv4, dst_ipv4) + self.logger.post_cmd(rc) if not rc: raise STLError(rc) - - # resolve the address - return self.resolve(ports = port, verbose = False) - - + + # try to resolve + with self.logger.supress(level = LoggerApi.VERBOSE_REGULAR_SYNC): + self.logger.pre_cmd("ARP resolving address '{0}': ".format(dst_ipv4)) + rc = self.ports[port].arp_resolve(0) + self.logger.post_cmd(rc) + if not rc: + raise STLError(rc) + + @__api_check(True) def ping_ip (self, src_port, dst_ipv4, pkt_size = 64, count = 5): """ @@ -3177,7 +3175,7 @@ class STLClient(object): parser = parsing_opts.gen_parser(self, "ping", self.ping_line.__doc__, - parsing_opts.SOURCE_PORT, + parsing_opts.SINGLE_PORT, parsing_opts.PING_IPV4, parsing_opts.PKT_SIZE, parsing_opts.PING_COUNT) @@ -3808,41 +3806,46 @@ class STLClient(object): @__console - def set_source_addr_line (self, line): - '''Configures source address for port(s)''' + def set_l2_mode_line (self, line): + '''Configures a port in L2 mode''' parser = parsing_opts.gen_parser(self, - "source", - self.set_source_addr_line.__doc__, - parsing_opts.SOURCE_PORT, - parsing_opts.IPV4) + "port", + self.set_l2_mode_line.__doc__, + parsing_opts.SINGLE_PORT, + parsing_opts.DST_MAC, + ) opts = parser.parse_args(line.split()) if not opts: return opts + # source ports maps to ports as a single port - self.set_source_addr(opts.ports[0], opts.ipv4) + self.set_l2_mode(opts.ports[0], dst_mac = opts.dst_mac) return RC_OK() @__console - def set_dest_addr_line (self, line): - '''Configures destination address for port(s)''' + def set_l3_mode_line (self, line): + '''Configures a port in L3 mode''' parser = parsing_opts.gen_parser(self, - "dest", - self.set_dest_addr_line.__doc__, - parsing_opts.SOURCE_PORT, - parsing_opts.DEST) + "port", + self.set_l3_mode_line.__doc__, + parsing_opts.SINGLE_PORT, + parsing_opts.SRC_IPV4, + parsing_opts.DST_IPV4, + ) opts = parser.parse_args(line.split()) if not opts: return opts + # source ports maps to ports as a single port - self.set_dest_addr(opts.ports[0], opts.dest) + self.set_l3_mode(opts.ports[0], src_ipv4 = opts.src_ipv4, dst_ipv4 = opts.dst_ipv4) return RC_OK() 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 5ec1f852..e44fe801 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 @@ -519,39 +519,40 @@ class Port(object): return self.ok() - @owned - def set_source_addr (self, addr): + def set_l2_mode (self, dst_mac): if not self.is_service_mode_on(): - return self.err('port service mode must be enabled for configuring source address. Please enable service mode') + return self.err('port service mode must be enabled for configuring L2 mode. Please enable service mode') - return self.set_attr(ipv4 = addr) - + params = {"handler": self.handler, + "port_id": self.port_id, + "dst_mac": dst_mac} - @owned - def set_dest_addr (self, addr): - if not self.is_service_mode_on(): - return self.err('port service mode must be enabled for configuring destination address. Please enable service mode') - - return self.set_attr(dest = addr) + rc = self.transmit("set_l2", params) + if rc.bad(): + return self.err(rc.err()) + + return self.sync() @owned - def set_arp_resolution (self, ipv4, mac): - + def set_l3_mode (self, src_addr, dest_addr, resolved_mac = None): + if not self.is_service_mode_on(): + return self.err('port service mode must be enabled for configuring L3 mode. Please enable service mode') + params = {"handler": self.handler, "port_id": self.port_id, - "ipv4": ipv4, - "mac": mac} + "src_addr": src_addr, + "dst_addr": dest_addr} - rc = self.transmit("set_arp_resolution", params) + if resolved_mac: + params["resolved_mac"] = resolved_mac + + rc = self.transmit("set_l3", params) if rc.bad(): return self.err(rc.err()) - # instead of updating manualy - let's sync with the server return self.sync() - - @owned @@ -700,15 +701,6 @@ class Port(object): if kwargs.get('rx_filter_mode') is not None: json_attr['rx_filter_mode'] = {'mode': kwargs.get('rx_filter_mode')} - if kwargs.get('ipv4') is not None: - 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')} - params = {"handler": self.handler, "port_id": self.port_id, @@ -879,7 +871,7 @@ class Port(object): info['src_ipv4'] = attr['src_ipv4'] if info['src_ipv4'] is None: - info['src_ipv4'] = 'Not Configured' + info['src_ipv4'] = '-' # dest dest = attr['dest'] @@ -908,6 +900,14 @@ class Port(object): queue = rx_info['queue'] info['rx_queue'] = '[{0} / {1}]'.format(queue['count'], queue['size']) if queue['is_active'] else 'off' + # Grat ARP + grat_arp = rx_info['grat_arp'] + if grat_arp['is_active']: + info['grat_arp'] = grat_arp['interval_sec'] + else: + info['grat_arp'] = "off" + + return info @@ -991,6 +991,7 @@ class Port(object): "RX Filter Mode": info['rx_filter_mode'], "RX Queueing": info['rx_queue'], "RX sniffer": info['rx_sniffer'], + "Grat ARP": info['grat_arp'], } 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 e0fc1724..ec83de5d 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 @@ -164,7 +164,8 @@ class ARPResolver(Resolver): return None - rc = self.port.set_arp_resolution(arp.psrc, arp.hwsrc) + # update the port with L3 full configuration + rc = self.port.set_l3_mode(self.src['ipv4'], self.dst['ipv4'], arp.hwsrc) if not rc: return rc 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 6a59126f..c08a0af8 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 @@ -682,6 +682,7 @@ class CTRexInfoGenerator(object): ("RX Filter Mode", []), ("RX Queueing", []), ("RX sniffer", []), + ("Grat ARP", []), ] ) 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 c5f53d68..0a7b510f 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 @@ -49,17 +49,20 @@ OUTPUT_FILENAME = 31 LIMIT = 33 PORT_RESTART = 34 -IPV4 = 35 -DEST = 36 RETRIES = 37 -SOURCE_PORT = 39 +SINGLE_PORT = 38 +DST_MAC = 39 + PING_IPV4 = 40 PING_COUNT = 41 PKT_SIZE = 42 SERVICE_OFF = 43 +SRC_IPV4 = 44 +DST_IPV4 = 45 + GLOBAL_STATS = 50 PORT_STATS = 51 PORT_STATUS = 52 @@ -250,9 +253,9 @@ def check_pkt_size (pkt_size): return pkt_size -def check_dest_addr (addr): - if not (is_valid_ipv4(addr) or is_valid_mac(addr)): - raise argparse.ArgumentTypeError("not a valid IPv4 or MAC address: '{0}'".format(addr)) +def check_mac_addr (addr): + if not is_valid_mac(addr): + raise argparse.ArgumentTypeError("not a valid MAC address: '{0}'".format(addr)) return addr @@ -341,18 +344,24 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], 'dest': 'flow_ctrl', 'choices': FLOW_CTRL_DICT}), - IPV4: ArgumentPack(['--ipv4'], - {'help': 'IPv4 address(s) for the port(s)', - 'dest': 'ipv4', - 'required': True, - 'type': check_ipv4_addr}), - - DEST: ArgumentPack(['--addr'], - {'help': 'Destination address(s) for the port(s) in either IPv4 or MAC format', - 'metavar': 'addr', - 'dest': 'dest', - 'required' : True, - 'type': check_dest_addr}), + SRC_IPV4: ArgumentPack(['--src'], + {'help': 'Configure source IPv4 address', + 'dest': 'src_ipv4', + 'required': True, + 'type': check_ipv4_addr}), + + DST_IPV4: ArgumentPack(['--dst'], + {'help': 'Configure destination IPv4 address', + 'dest': 'dst_ipv4', + 'required': True, + 'type': check_ipv4_addr}), + + + DST_MAC: ArgumentPack(['--dst'], + {'help': 'Configure destination MAC address', + 'dest': 'dst_mac', + 'required': True, + 'type': check_mac_addr}), RETRIES: ArgumentPack(['-r', '--retries'], {'help': 'retries count [default is zero]', @@ -405,7 +414,7 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], 'default': []}), - SOURCE_PORT: ArgumentPack(['--port', '-p'], + SINGLE_PORT: ArgumentPack(['--port', '-p'], {'dest':'ports', 'type': int, 'metavar': 'PORT', |