diff options
author | 2016-03-01 13:50:20 +0200 | |
---|---|---|
committer | 2016-03-01 13:50:20 +0200 | |
commit | 4dc464d004f0dffe1381b149a7ac36508e1b4234 (patch) | |
tree | 148de052e20bb3421c391923d8443c584f0f4413 | |
parent | 0af59f17029acc700b3a8bc569e05b5603d0a114 (diff) | |
parent | 37c4d0439365f70a01a3047085e7efef6d88930b (diff) |
Merge --pkt support to stl-sim
-rw-r--r-- | scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py | 1 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py | 115 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py | 134 | ||||
-rw-r--r-- | scripts/exp/hlt_mac_ranges.pcap | bin | 0 -> 1624 bytes | |||
-rwxr-xr-x | scripts/stl/hlt/hlt_mac_ranges.py | 29 |
5 files changed, 229 insertions, 50 deletions
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/examples/hlt_udp_simple.py b/scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py new file mode 100644 index 00000000..19752f4f --- /dev/null +++ b/scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py @@ -0,0 +1,115 @@ +#!/usr/bin/python + +""" +Sample HLTAPI application (for loopback) +Connect to TRex +Send UDP packet in specific length +Each direction has its own IP range +""" + +import sys +import argparse +import stl_path +from trex_stl_lib.api import * +from trex_stl_lib.trex_stl_hltapi import * + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(usage=""" + Connect to TRex and send burst of packets + + examples + + hlt_udp_simple.py -s 9000 -d 30 + + hlt_udp_simple.py -s 9000 -d 30 -rate_percent 10 + + hlt_udp_simple.py -s 300 -d 30 -rate_pps 5000000 + + hlt_udp_simple.py -s 800 -d 30 -rate_bps 500000000 --debug + + then run the simulator on the output + ./stl-sim -f example.yaml -o a.pcap ==> a.pcap include the packet + + """, + description="Example for TRex HLTAPI", + epilog=" based on hhaim's stl_run_udp_simple example"); + + parser.add_argument("--ip", + dest="ip", + help='Remote trex ip', + default="127.0.0.1", + type = str) + + parser.add_argument("-s", "--frame-size", + dest="frame_size", + help='L2 frame size in bytes without FCS', + default=60, + type = int,) + + parser.add_argument('-d','--duration', + dest='duration', + help='duration in second ', + default=10, + type = int,) + + parser.add_argument('--rate-pps', + dest='rate_pps', + help='speed in pps', + default="100") + + parser.add_argument('--src', + dest='src_mac', + help='src MAC', + default='00:50:56:b9:de:75') + + parser.add_argument('--dst', + dest='dst_mac', + help='dst MAC', + default='00:50:56:b9:34:f3') + + args = parser.parse_args(); + + hltapi = CTRexHltApi() + print 'Connecting to TRex' + res = hltapi.connect(device = args.ip, port_list = [0, 1], reset = True, break_locks = True) + check_res(res) + ports = res['port_handle'] + if len(ports) < 2: + error('Should have at least 2 ports for this test') + print 'Connected, acquired ports: %s' % ports + + print 'Creating traffic' + + res = hltapi.traffic_config(mode = 'create', bidirectional = True, + port_handle = ports[0], port_handle2 = ports[1], + frame_size = args.frame_size, + mac_src = args.src_mac, mac_dst = args.dst_mac, + mac_src2 = args.dst_mac, mac_dst2 = args.src_mac, + l3_protocol = 'ipv4', + ip_src_addr = '10.0.0.1', ip_src_mode = 'increment', ip_src_count = 254, + ip_dst_addr = '8.0.0.1', ip_dst_mode = 'increment', ip_dst_count = 254, + l4_protocol = 'udp', + udp_dst_port = 12, udp_src_port = 1025, + stream_id = 1, # temporary workaround, add_stream does not return stream_id + rate_pps = args.rate_pps, + ) + check_res(res) + + print 'Starting traffic' + res = hltapi.traffic_control(action = 'run', port_handle = ports[:2]) + check_res(res) + wait_with_progress(args.duration) + + print 'Stopping traffic' + res = hltapi.traffic_control(action = 'stop', port_handle = ports[:2]) + check_res(res) + + res = hltapi.traffic_stats(mode = 'aggregate', port_handle = ports[:2]) + check_res(res) + print_brief_stats(res) + + res = hltapi.cleanup_session(port_handle = 'all') + check_res(res) + + print 'Done' 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 Binary files differnew file mode 100644 index 00000000..4b5d09c6 --- /dev/null +++ b/scripts/exp/hlt_mac_ranges.pcap 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() + + + |