From 53169abe298996dd87c0a62cfe41af0598c766d8 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Mon, 29 Feb 2016 17:03:09 +0200 Subject: hltapi: fix decrement exceeding maximal add_value range, add several useful functions, add mac profile --- .../unit_tests/functional_tests/stl_basic_tests.py | 1 + .../stl/trex_stl_lib/trex_stl_hltapi.py | 134 +++++++++++++-------- scripts/exp/hlt_mac_ranges.pcap | Bin 0 -> 1784 bytes scripts/stl/hlt/hlt_mac_ranges.py | 29 +++++ 4 files changed, 114 insertions(+), 50 deletions(-) create mode 100644 scripts/exp/hlt_mac_ranges.pcap create mode 100755 scripts/stl/hlt/hlt_mac_ranges.py diff --git a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py index e31ef59f..2099c953 100644 --- a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py +++ b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py @@ -220,6 +220,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): ['hlt/hlt_vlans_vm.py', '-m 1 -l 20', True], ['hlt/hlt_ipv6_default.py', '-m 1 -l 20', True], ['hlt/hlt_ipv6_ranges.py', '-m 1 -l 20', True], + ['hlt/hlt_mac_ranges.py', '-m 1 -l 20', True], ) for obj in p: 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 3fad0bfb..5e8fddfa 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 @@ -228,6 +228,40 @@ def is_true(input): return True return False +def error(err = None): + if not err: + raise Exception('Unknown exception, look traceback') + if type(err) is str and not err.startswith('[ERR]'): + err = '[ERR] ' + err + print(err) + sys.exit(1) + +def check_res(res): + if res['status'] == 0: + error('Encountered error:\n%s' % res['log']) + return res + +def print_brief_stats(res): + title_str = ' '*3 + tx_str = 'TX:' + rx_str = 'RX:' + for port_id, stat in res.iteritems(): + if type(port_id) is not int: + continue + title_str += ' '*10 + 'Port%s' % port_id + tx_str += '%15s' % res[port_id]['aggregate']['tx']['total_pkts'] + rx_str += '%15s' % res[port_id]['aggregate']['rx']['total_pkts'] + print(title_str) + print(tx_str) + print(rx_str) + +def wait_with_progress(seconds): + for i in range(0, seconds): + time.sleep(1) + sys.stdout.write('.') + sys.stdout.flush() + print('') + # dict of streams per port # hlt_history = False: holds list of stream_id per port # hlt_history = True: act as dictionary (per port) stream_id -> hlt arguments used for build @@ -658,7 +692,7 @@ class CTRexHltApi(object): return [int(port) for port in port_list.strip().split()] elif type(port_list) is list: return [int(port) for port in port_list] - elif type(port) in (int, long): + elif type(port_list) in (int, long): return [int(port_list)] raise STLError('port_list should be string with ports, list, or single number') @@ -774,27 +808,27 @@ def generate_packet(**user_kwargs): if count < 0: raise STLError('mac_src_count has to be at least 1') if count > 0 or kwargs['mac_src_mode'] == 'random': - mac_src = mac_str_to_num(mac2str(kwargs['mac_src'])) + mac_src = ipv4_str_to_num(mac2str(kwargs['mac_src'])[2:]) # take only 32 lsb step = kwargs['mac_src_step'] if step < 1: raise STLError('mac_src_step has to be at least 1') if type(step) is str: - step = mac_str_to_num(mac2str(step)) + step = ipv4_str_to_num(mac2str(step)[2:]) # take only 32 lsb if kwargs['mac_src_mode'] == 'increment': add_val = mac_src - 0x7fffffff var_name = '%s_%s_%s_%s' % ('inc', 4, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True elif kwargs['mac_src_mode'] == 'decrement': - add_val = mac_src - count * step - 0x7fffffff + add_val = mac_src - 0x7fffffff var_name = '%s_%s_%s_%s' % ('dec', 4, count, step) if var_name not in vm_variables_cache: - vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'dec', step = step, - min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'dec', step = step, + min_value = 0x7fffffff - count * step, + max_value = 0x7fffffff)) vm_variables_cache[var_name] = True elif kwargs['mac_src_mode'] == 'random': add_val = 0 @@ -809,27 +843,27 @@ def generate_packet(**user_kwargs): if count < 0: raise STLError('mac_dst_count has to be at least 1') if count > 0 or kwargs['mac_dst_mode'] == 'random': - mac_dst = mac_str_to_num(mac2str(kwargs['mac_dst'])) + mac_dst = ipv4_str_to_num(mac2str(kwargs['mac_dst'])[2:]) # take only 32 lsb step = kwargs['mac_dst_step'] if step < 1: raise STLError('mac_dst_step has to be at least 1') if type(step) is str: - step = mac_str_to_num(mac2str(step)) + step = ipv4_str_to_num(mac2str(step)[2:]) # take only 32 lsb if kwargs['mac_dst_mode'] == 'increment': add_val = mac_dst - 0x7fffffff var_name = '%s_%s_%s_%s' % ('inc', 4, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True elif kwargs['mac_dst_mode'] == 'decrement': - add_val = mac_dst - count * step - 0x7fffffff + add_val = mac_dst - 0x7fffffff var_name = '%s_%s_%s_%s' % ('dec', 4, count, step) if var_name not in vm_variables_cache: - vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_dst', size = 4, op = 'dec', step = step, - min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'dec', step = step, + min_value = 0x7fffffff - count * step, + max_value = 0x7fffffff)) vm_variables_cache[var_name] = True elif kwargs['mac_dst_mode'] == 'random': add_val = 0 @@ -873,15 +907,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, - max_value = count * step + 0x7fff)) + max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True elif vlan_id_mode == 'decrement': - add_val = vlan_id - count * step - 0x7fff + add_val = vlan_id - 0x7fff var_name = '%s_%s_%s_%s' % ('dec', 2, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step, - min_value = 0x7fff, - max_value = count * step + 0x7fff)) + min_value = 0x7fff - count * step, + max_value = 0x7fff)) vm_variables_cache[var_name] = True elif vlan_id_mode == 'random': add_val = 0 @@ -945,15 +979,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True elif kwargs['ip_src_mode'] == 'decrement': - add_val = ip_src_addr - count * step - 0x7fffffff + add_val = ip_src_addr - 0x7fffffff var_name = '%s_%s_%s_%s' % ('dec', 4, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'dec', step = step, - min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + min_value = 0x7fffffff - count * step, + max_value = 0x7fffffff)) vm_variables_cache[var_name] = True elif kwargs['ip_src_mode'] == 'random': add_val = 0 @@ -983,15 +1017,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True elif kwargs['ip_dst_mode'] == 'decrement': - add_val = ip_dst_addr - count * step - 0x7fffffff + add_val = ip_dst_addr - 0x7fffffff var_name = '%s_%s_%s_%s' % ('dec', 4, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'dec', step = step, - min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + min_value = 0x7fffffff - count * step, + max_value = 0x7fffffff)) vm_variables_cache[var_name] = True elif kwargs['ip_dst_mode'] == 'random': add_val = 0 @@ -1039,15 +1073,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True elif kwargs['ipv6_src_mode'] == 'decrement': - add_val = ipv6_src_addr_num - count * step - 0x7fffffff + add_val = ipv6_src_addr_num - 0x7fffffff var_name = '%s_%s_%s_%s' % ('dec', 4, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'dec', step = step, - min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + min_value = 0x7fffffff - count * step, + max_value = 0x7fffffff)) vm_variables_cache[var_name] = True elif kwargs['ipv6_src_mode'] == 'random': add_val = 0 @@ -1074,15 +1108,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True elif kwargs['ipv6_dst_mode'] == 'decrement': - add_val = ipv6_dst_addr_num - count * step - 0x7fffffff + add_val = ipv6_dst_addr_num - 0x7fffffff var_name = '%s_%s_%s_%s' % ('dec', 4, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'dec', step = step, - min_value = 0x7fffffff, - max_value = count * step + 0x7fffffff)) + min_value = 0x7fffffff - count * step, + max_value = 0x7fffffff)) vm_variables_cache[var_name] = True elif kwargs['ipv6_dst_mode'] == 'random': add_val = 0 @@ -1146,15 +1180,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, - max_value = count * step + 0x7fff)) + max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True elif kwargs['tcp_src_port_mode'] == 'decrement': - add_val = kwargs['tcp_src_port'] - count * step - 0x7fff + add_val = kwargs['tcp_src_port'] - 0x7fff var_name = '%s_%s_%s_%s' % ('dec', 2, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step, - min_value = 0x7fff, - max_value = count * step + 0x7fff)) + min_value = 0x7fff - count * step, + max_value = 0x7fff)) vm_variables_cache[var_name] = True elif kwargs['tcp_src_port_mode'] == 'random': add_val = 0 @@ -1179,15 +1213,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, - max_value = count * step + 0x7fff)) + max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True elif kwargs['tcp_dst_port_mode'] == 'decrement': - add_val = kwargs['tcp_dst_port'] - count * step - 0x7fff + add_val = kwargs['tcp_dst_port'] - 0x7fff var_name = '%s_%s_%s_%s' % ('dec', 2, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step, - min_value = 0x7fff, - max_value = count * step + 0x7fff)) + min_value = 0x7fff - count * step, + max_value = 0x7fff)) vm_variables_cache[var_name] = True elif kwargs['tcp_dst_port_mode'] == 'random': add_val = 0 @@ -1222,15 +1256,15 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, - max_value = count * step + 0x7fff)) + max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True elif kwargs['udp_src_port_mode'] == 'decrement': - add_val = kwargs['udp_src_port'] - count * step - 0x7fff + add_val = kwargs['udp_src_port'] - 0x7fff var_name = '%s_%s_%s_%s' % ('dec', 2, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step, - min_value = 0x7fff, - max_value = count * step + 0x7fff)) + min_value = 0x7fff - count * step, + max_value = 0x7fff)) vm_variables_cache[var_name] = True elif kwargs['udp_src_port_mode'] == 'random': add_val = 0 @@ -1255,14 +1289,14 @@ def generate_packet(**user_kwargs): if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, - max_value = count * step + 0x7fff)) + max_value = 0x7fff + count * step)) elif kwargs['udp_dst_port_mode'] == 'decrement': add_val = kwargs['udp_dst_port'] - 0x7fff var_name = '%s_%s_%s_%s' % ('dec', 2, count, step) if var_name not in vm_variables_cache: vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step, - min_value = 0x7fff, - max_value = count * step + 0x7fff)) + min_value = 0x7fff - count * step, + max_value = 0x7fff)) elif kwargs['udp_dst_port_mode'] == 'random': add_val = 0 var_name = 'udp_dst_random' diff --git a/scripts/exp/hlt_mac_ranges.pcap b/scripts/exp/hlt_mac_ranges.pcap new file mode 100644 index 00000000..a916a09a Binary files /dev/null and b/scripts/exp/hlt_mac_ranges.pcap differ diff --git a/scripts/stl/hlt/hlt_mac_ranges.py b/scripts/stl/hlt/hlt_mac_ranges.py new file mode 100755 index 00000000..e265ba5f --- /dev/null +++ b/scripts/stl/hlt/hlt_mac_ranges.py @@ -0,0 +1,29 @@ +from trex_stl_lib.trex_stl_hltapi import STLHltStream + + +class STLS1(object): + ''' + Eth/IP/UDP stream with VM, to change the MAC addr (only 32 lsb) + ''' + + def create_streams (self, direction = 0): + return STLHltStream(l3_protocol = 'ipv4', l4_protocol = 'udp', + mac_src = '10:00:00:00:00:01', mac_dst = '10:00:00:00:01:00', + mac_src2 = '11:11:00:00:00:01', mac_dst2 = '11:11:00:00:01:00', + mac_src_step = 2, mac_src_mode = 'decrement', mac_src_count = 19, + mac_dst_step = 2, mac_dst_mode = 'increment', mac_dst_count = 19, + mac_src2_step = 2, mac_src2_mode = 'decrement', mac_src2_count = 19, + mac_dst2_step = 2, mac_dst2_mode = 'increment', mac_dst2_count = 19, + direction = direction, + save_to_yaml = '/tmp/foo.yaml', + ) + + def get_streams (self, direction = 0): + return self.create_streams(direction) + +# dynamic load - used for trex console or simulator +def register(): + return STLS1() + + + -- cgit 1.2.3-korg