diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-02-23 16:14:10 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-02-23 16:14:10 +0200 |
commit | 5eca0227f15b360fb87d9c07de9cebfc118116a5 (patch) | |
tree | 21ebbb11bd3b81c986af51fe7704b9280d4eb409 /scripts/automation | |
parent | 5a951d9435dd13b8c785969f1fd85b1c19743ab0 (diff) | |
parent | 66bebea92f15db3ccf055814ab48cda24477fa9d (diff) |
Merge mask instruction add_value field
Diffstat (limited to 'scripts/automation')
-rwxr-xr-x | scripts/automation/regression/hltapi_playground.py (renamed from scripts/automation/regression/hltapi_example.py) | 32 | ||||
-rwxr-xr-x | scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py | 90 | ||||
-rw-r--r-- | scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py | 9 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py | 361 |
4 files changed, 305 insertions, 187 deletions
diff --git a/scripts/automation/regression/hltapi_example.py b/scripts/automation/regression/hltapi_playground.py index 5695d32f..793b0282 100755 --- a/scripts/automation/regression/hltapi_example.py +++ b/scripts/automation/regression/hltapi_playground.py @@ -1,7 +1,8 @@ #!/router/bin/python import outer_packages -from trex_stl_lib.trex_stl_hltapi import CTRexHltApi, CStreamsPerPort +#from trex_stl_lib.trex_stl_hltapi import CTRexHltApi, CStreamsPerPort +from trex_stl_lib.trex_stl_hltapi import * import traceback import sys, time from pprint import pprint @@ -53,13 +54,27 @@ if __name__ == "__main__": res = check_res(hlt_client.connect(device = args.device, port_list = [0, 1], username = 'danklei', break_locks = True, reset = True)) port_handle = res['port_handle'] print('Connected, got port handles %s' % port_handle) - ports_streams_dict = CStreamsPerPort(port_handle) - - print('Imix should create 3 streams (forth ratio is 0)') - res = check_res(hlt_client.traffic_config(mode = 'create', l2_encap = 'ethernet_ii_vlan', bidirectional = True, length_mode = 'imix', - port_handle = port_handle, save_to_yaml = '/tmp/d1.yaml')) + ports_streams_dict = CStreamsPerPort() + + res = check_res(hlt_client.traffic_config(mode = 'create', l2_encap = 'ethernet_ii_vlan', rate_pps = 1, + l3_protocol = 'ipv4', + length_mode = 'imix', l3_length = 200, + ipv6_dst_mode = 'decrement', ipv6_dst_count = 300, ipv6_dst_addr = 'fe80:0:0:0:0:0:0:000f', + port_handle = port_handle, port_handle2 = port_handle[1], save_to_yaml = '/tmp/d1.yaml')) + #print res + #print hlt_client._streams_history + #print hlt_client.trex_client._STLClient__get_all_streams(port_id = port_handle[0]) + #print hlt_client.trex_client._STLClient__get_all_streams(port_id = port_handle[1]) + #ports_streams_dict.add_streams_from_res(res) + sys.exit(0) + res = check_res(hlt_client.traffic_config(mode = 'create', l2_encap = 'ethernet_ii_vlan', rate_pps = 1, + port_handle = port_handle[0], port_handle2 = port_handle[1], save_to_yaml = '/tmp/d1.yaml', + l4_protocol = 'udp', + #udp_src_port_mode = 'decrement', + #udp_src_port_count = 10, udp_src_port = 5, + )) ports_streams_dict.add_streams_from_res(res) - + sys.exit(0) #print ports_streams_dict #print hlt_client.trex_client._STLClient__get_all_streams(port_id = port_handle[0]) res = check_res(hlt_client.traffic_config(mode = 'modify', port_handle = port_handle[0], stream_id = ports_streams_dict[0][0], @@ -71,7 +86,8 @@ if __name__ == "__main__": #print hlt_client.trex_client._STLClient__get_all_streams(port_id = port_handle[0]) check_res(hlt_client.traffic_config(mode = 'reset', port_handle = port_handle)) - res = check_res(hlt_client.traffic_config(mode = 'create', bidirectional = True, length_mode = 'fixed', port_handle = port_handle, + res = check_res(hlt_client.traffic_config(mode = 'create', bidirectional = True, length_mode = 'fixed', + port_handle = port_handle[0], port_handle2 = port_handle[1], transmit_mode = 'single_burst', pkts_per_burst = 100, rate_pps = 100, mac_src = '1-2-3-4-5-6', mac_dst = '6:5:4:4:5:6', diff --git a/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py index df93aba1..297034db 100755 --- a/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py +++ b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py @@ -112,30 +112,30 @@ TBD self_start: true vm: instructions: - - init_value: 3232235777 - max_value: 3232235781 - min_value: 3232235777 - name: ip_src + - init_value: 0 + max_value: 4 + min_value: 0 + name: inc_4_4_1 op: inc size: 4 step: 1 type: flow_var - - add_value: 0 + - add_value: 3232235777 is_big_endian: true - name: ip_src + name: inc_4_4_1 pkt_offset: 26 type: write_flow_var - init_value: 0 max_value: 4294967295 min_value: 0 - name: ip_dst + name: ip_dst_random op: random size: 4 step: 1 type: flow_var - add_value: 0 is_big_endian: true - name: ip_dst + name: ip_dst_random pkt_offset: 30 type: write_flow_var - pkt_offset: 14 @@ -170,35 +170,35 @@ TBD self_start: true vm: instructions: - - init_value: 1024 - max_value: 1024 - min_value: 1015 - name: tcp_src + - init_value: 9 + max_value: 9 + min_value: 0 + name: dec_2_9_1 op: dec size: 2 step: 1 type: flow_var - - add_value: 0 + - add_value: 1015 is_big_endian: true - name: tcp_src + name: dec_2_9_1 pkt_offset: 34 type: write_flow_var - init_value: 0 max_value: 65535 min_value: 0 - name: tcp_dst + name: tcp_dst_random op: random size: 2 step: 1 type: flow_var - add_value: 0 is_big_endian: true - name: tcp_dst + name: tcp_dst_random pkt_offset: 36 type: write_flow_var - pkt_offset: 14 type: fix_checksum_ipv4 - split_by_var: tcp_src + split_by_var: dec_2_9_1 ''' # Eth / IP / UDP, udp ports are changed by VM @@ -247,35 +247,35 @@ TBD self_start: true vm: instructions: - - init_value: 1234 - max_value: 1234 - min_value: 1225 - name: udp_src + - init_value: 9 + max_value: 9 + min_value: 0 + name: dec_2_9_1 op: dec size: 2 step: 1 type: flow_var - - add_value: 0 + - add_value: 1225 is_big_endian: true - name: udp_src + name: dec_2_9_1 pkt_offset: 34 type: write_flow_var - - init_value: 1234 - max_value: 1243 - min_value: 1234 - name: udp_dst + - init_value: 0 + max_value: 9 + min_value: 0 + name: inc_2_9_1 op: inc size: 2 step: 1 type: flow_var - - add_value: 0 + - add_value: 1234 is_big_endian: true - name: udp_dst + name: inc_2_9_1 pkt_offset: 36 type: write_flow_var - pkt_offset: 14 type: fix_checksum_ipv4 - split_by_var: udp_src + split_by_var: dec_2_9_1 ''' # Eth/IP/TCP, packet length is changed in VM by frame_size @@ -543,7 +543,7 @@ TBD pps: 1 type: continuous packet: - binary: AAAAAAAAAAABAAABht1gAAAAAFIGQP6AAAAAAAAAAAAAAAAAABL+gAAAAAAAAAAAAAAAAAAiBAAAUAAAAAEAAAABUAAP5Zs3AAAhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIQ== + binary: AAAAAAAAAAABAAABht1gAAAAAG4GQP6AAAAAAAAAAAAAAAAAABL+gAAAAAAAAAAAAAAAAAAiBAAAUAAAAAEAAAABUAAP5ctLAAAhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISE= meta: '' rx_stats: enabled: false @@ -573,40 +573,40 @@ TBD pps: 1 type: continuous packet: - binary: AAAAAAAAAAABAAABht1gAAAAAFIRQBERIiIzM0REVVVmZnd3iIgRERERERERERERERERERERBAAAUABSQkIhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIQ== + binary: AAAAAAAAAAABAAABht1gAAAAAG4RQBERIiIzM0REVVVmZnd3iIgRERERERERERERERERERERBAAAUABucjohISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISE= meta: '' rx_stats: enabled: false self_start: true vm: instructions: - - init_value: 2004322440 - max_value: 2004322485 - min_value: 2004322440 - name: ipv6_src + - init_value: 0 + max_value: 45 + min_value: 0 + name: inc_4_9_5 op: inc size: 4 step: 5 type: flow_var - - add_value: 0 + - add_value: 2004322440 is_big_endian: true - name: ipv6_src + name: inc_4_9_5 pkt_offset: 34 type: write_flow_var - - init_value: 286331153 - max_value: 286331153 - min_value: 286328620 - name: ipv6_dst + - init_value: 2533 + max_value: 2533 + min_value: 0 + name: dec_4_149_17 op: dec size: 4 step: 17 type: flow_var - - add_value: 0 + - add_value: 286328620 is_big_endian: true - name: ipv6_dst + name: dec_4_149_17 pkt_offset: 50 type: write_flow_var - split_by_var: ipv6_dst + split_by_var: dec_4_149_17 ''' 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 8b9c9bac..c92bc5ac 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 @@ -200,9 +200,14 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): def test_hlt_profiles (self): p = ( ['hlt/hlt_udp_inc_dec_len_9k.py', '-m 1 -l 20', True], - ['hlt/hlt_imix_default.py', '-m 1 -l 40', True], + ['hlt/hlt_imix_default.py', '-m 1 -l 20', True], + ['hlt/hlt_imix_4rates.py', '-m 1 -l 20', True], + ['hlt/hlt_david1.py', '-m 1 -l 20', True], + ['hlt/hlt_david2.py', '-m 1 -l 20', True], + ['hlt/hlt_david3.py', '-m 1 -l 20', True], + ['hlt/hlt_david4.py', '-m 1 -l 20', True], + ['hlt/hlt_tcp_ranges.py', '-m 1 -l 20', True], ) - for obj in p: self.run_py_profile_path (obj[0], obj[1], compare =obj[2], do_no_remove=True) 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 60654f0a..581ea418 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 @@ -212,7 +212,7 @@ def correct_macs(kwargs): list_of_mac_steps = ['mac_src_step', 'mac_dst_step', 'mac_src2_step', 'mac_dst2_step'] for mac_arg in list_of_mac_args + list_of_mac_steps: if mac_arg in kwargs: - if type(kwargs[mac_arg]) in (int, long) and kwargs[mac_arg] in list_of_mac_steps: # step can be number + if type(kwargs[mac_arg]) in (int, long) and mac_arg in list_of_mac_steps: # step can be number continue if type(kwargs[mac_arg]) is not str: raise STLError('Argument %s should be str' % mac_arg) kwargs[mac_arg] = kwargs[mac_arg].replace('{', '').replace('}', '').strip().replace('-', ' ').replace(':', ' ').replace('.', ' ') @@ -483,7 +483,7 @@ class CTRexHltApi(object): if mode == 'create' or mode == 'modify': # create a new stream with desired attributes, starting by creating packet streams_per_port = CStreamsPerPort() - if kwargs['bidirectional']: # two streams with opposite directions + if is_true(kwargs['bidirectional']): # two streams with opposite directions del user_kwargs['bidirectional'] save_to_yaml = user_kwargs.get('save_to_yaml') bidirect_err = 'When using bidirectional flag, ' @@ -502,8 +502,6 @@ class CTRexHltApi(object): streams_per_port.add_streams_from_res(res1) kwargs['direction'] = 1 - kwargs['direction'] # not correct_direction(user_kwargs, kwargs) - user_kwargs['mac_src'] = kwargs['mac_src2'] - user_kwargs['mac_dst'] = kwargs['mac_dst2'] if save_to_yaml and type(save_to_yaml) is str: user_kwargs['save_to_yaml'] = save_to_yaml.replace('.yaml', '_bi2.yaml') user_kwargs['port_handle'] = port_handle2 @@ -713,7 +711,7 @@ def STLHltStream(**user_kwargs): transmit_mode_class = STLTXSingleBurst(pps = rate_pps, total_pkts = pkts_per_burst) elif transmit_mode == 'multi_burst': transmit_mode_class = STLTXMultiBurst(pps = rate_pps, total_pkts = pkts_per_burst, - count = kwargs['burst_loop_count'], ibg = kwargs['inter_burst_gap']) + count = int(kwargs['burst_loop_count']), ibg = kwargs['inter_burst_gap']) else: raise STLError('transmit_mode %s not supported/implemented') except Exception as e: @@ -744,6 +742,7 @@ def generate_packet(**user_kwargs): correct_direction(kwargs, kwargs) vm_cmds = [] + vm_variables_cache = {} # we will keep in cache same variables (inc/dec, var size in bytes, number of steps, step) fix_ipv4_checksum = False ### L2 ### @@ -754,27 +753,39 @@ def generate_packet(**user_kwargs): l2_layer = Ether(src = kwargs['mac_src'], dst = kwargs['mac_dst']) # Eth VM - # WIP!!! Need 8 bytes mask and vars + # !!!! Need 8 bytes mask and vars !!!! for now will change only 32 lsb if kwargs['mac_src_mode'] != 'fixed': - mac_src_count = kwargs['mac_src_count'] - 1 - if mac_src_count < 0: + count = int(kwargs['mac_src_count']) - 1 + if count < 0: raise STLError('mac_src_count has to be at least 1') - if mac_src_count > 0: + if count > 0: mac_src = mac_str_to_num(mac2str(kwargs['mac_src'])) + 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)) + add_val = 0 if kwargs['mac_src_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'inc', step = kwargs['mac_src_step'], - min_value = mac_src, - max_value = mac_src + mac_src_count * kwargs['mac_src_step'])) + add_val = mac_src + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['mac_src_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'dec', step = kwargs['mac_src_step'], - min_value = mac_src - mac_src_count * kwargs['mac_src_step'], - max_value = mac_src)) + add_val = mac_src - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['mac_src_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'random', min_value = 0, max_value = 0xffffffffffffffff)) + var_name = 'mac_src_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffffffff)) else: raise STLError('mac_src_mode %s is not supported' % kwargs['mac_src_mode']) - vm_cmds.append(STLVmWrMaskFlowVar(fv_name = 'mac_src', pkt_offset = 'Ethernet.src', pkt_cast_size = 4, mask = 0xffffffff)) - + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.src', offset_fixup = 2, add_val = add_val)) if kwargs['l2_encap'] == 'ethernet_ii_vlan' or (kwargs['l2_encap'] == 'ethernet_ii' and vlan_in_args(user_kwargs)): #fields_desc = [ BitField("prio", 0, 3), @@ -783,9 +794,9 @@ def generate_packet(**user_kwargs): # XShortEnumField("type", 0x0000, ETHER_TYPES) ] for i, vlan_kwargs in enumerate(split_vlan_args(kwargs)): vlan_id = int(vlan_kwargs['vlan_id']) - dot1q_kwargs = {'prio': vlan_kwargs['vlan_user_priority'], + dot1q_kwargs = {'prio': int(vlan_kwargs['vlan_user_priority']), 'vlan': vlan_id, - 'id': vlan_kwargs['vlan_cfi']} + 'id': int(vlan_kwargs['vlan_cfi'])} vlan_protocol_tag_id = vlan_kwargs['vlan_protocol_tag_id'] if vlan_protocol_tag_id is not None: if type(vlan_protocol_tag_id) is str: @@ -796,19 +807,21 @@ def generate_packet(**user_kwargs): # vlan VM vlan_id_mode = vlan_kwargs['vlan_id_mode'] if vlan_id_mode != 'fixed': - vlan_id_count = int(vlan_kwargs['vlan_id_count']) - 1 - if vlan_id_count < 0: + count = int(vlan_kwargs['vlan_id_count']) - 1 + if count < 0: raise STLError('vlan_id_count has to be at least 1') - if vlan_id_count > 0 or vlan_id_mode == 'random': + if count > 0 or vlan_id_mode == 'random': var_name = 'vlan_id%s' % i step = int(vlan_kwargs['vlan_id_step']) + if step < 1: + raise STLError('vlan_id_step has to be at least 1') if vlan_id_mode == 'increment': vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = vlan_id, - max_value = vlan_id + vlan_id_count * step)) + max_value = vlan_id + count * step)) elif vlan_id_mode == 'decrement': vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step, - min_value = vlan_id - vlan_id_count * step, + min_value = vlan_id - count * step, max_value = vlan_id)) elif vlan_id_mode == 'random': vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff)) @@ -850,56 +863,77 @@ def generate_packet(**user_kwargs): ) # IPv4 VM if kwargs['ip_src_mode'] != 'fixed': - ip_src_count = kwargs['ip_src_count'] - 1 - if ip_src_count < 0: + count = int(kwargs['ip_src_count']) - 1 + if count < 0: raise STLError('ip_src_count has to be at least 1') - if ip_src_count > 0: + if count > 0: fix_ipv4_checksum = True + add_val = 0 ip_src_addr = kwargs['ip_src_addr'] if type(ip_src_addr) is str: ip_src_addr = ipv4_str_to_num(is_valid_ipv4(ip_src_addr)) - ip_src_step = kwargs['ip_src_step'] - if type(ip_src_step) is str: - ip_src_step = ipv4_str_to_num(is_valid_ipv4(ip_src_step)) + step = kwargs['ip_src_step'] + if step < 1: + raise STLError('ip_src_step has to be at least 1') + if type(step) is str: + step = ipv4_str_to_num(is_valid_ipv4(step)) if kwargs['ip_src_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'inc', step = ip_src_step, - min_value = ip_src_addr, - max_value = ip_src_addr + ip_src_count * ip_src_step)) + add_val = ip_src_addr + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ip_src_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'dec', step = ip_src_step, - min_value = ip_src_addr - ip_src_count * ip_src_step, - max_value = ip_src_addr)) + add_val = ip_src_addr - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ip_src_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) + var_name = 'ip_src_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) else: raise STLError('ip_src_mode %s is not supported' % kwargs['ip_src_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='ip_src', pkt_offset = 'IP.src')) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IP.src', add_val = add_val)) if kwargs['ip_dst_mode'] != 'fixed': - ip_dst_count = kwargs['ip_dst_count'] - 1 - if ip_dst_count < 0: + count = int(kwargs['ip_dst_count']) - 1 + if count < 0: raise STLError('ip_dst_count has to be at least 1') - if ip_dst_count > 0: + if count > 0: fix_ipv4_checksum = True + add_val = 0 ip_dst_addr = kwargs['ip_dst_addr'] if type(ip_dst_addr) is str: ip_dst_addr = ipv4_str_to_num(is_valid_ipv4(ip_dst_addr)) - ip_dst_step = kwargs['ip_dst_step'] - if type(ip_dst_step) is str: - ip_dst_step = ipv4_str_to_num(is_valid_ipv4(ip_dst_step)) + step = kwargs['ip_dst_step'] + if step < 1: + raise STLError('ip_dst_step has to be at least 1') + if type(step) is str: + step = ipv4_str_to_num(is_valid_ipv4(step)) if kwargs['ip_dst_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'inc', step = ip_dst_step, - min_value = ip_dst_addr, - max_value = ip_dst_addr + ip_dst_count * ip_dst_step)) + add_val = ip_dst_addr + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ip_dst_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'dec', step = ip_dst_step, - min_value = ip_dst_addr - ip_dst_count * ip_dst_step, - max_value = ip_dst_addr)) + add_val = ip_dst_addr - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ip_dst_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) + var_name = 'ip_dst_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) else: raise STLError('ip_dst_mode %s is not supported' % kwargs['ip_dst_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='ip_dst', pkt_offset = 'IP.dst')) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IP.dst', add_val = add_val)) + elif kwargs['l3_protocol'] == 'ipv6': #fields_desc = [ BitField("version" , 6 , 4), # BitField("tc", 0, 8), #TODO: IPv6, ByteField ? @@ -922,50 +956,70 @@ def generate_packet(**user_kwargs): # IPv6 VM if kwargs['ipv6_src_mode'] != 'fixed': - ipv6_src_count = kwargs['ipv6_src_count'] - 1 - if ipv6_src_count < 0: + count = int(kwargs['ipv6_src_count']) - 1 + if count < 0: raise STLError('ipv6_src_count has to be at least 1') - if ipv6_src_count > 0: + if count > 0: + add_val = 0 ipv6_src_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_src_addr'])[-4:]) - ipv6_src_step = kwargs['ipv6_src_step'] - if type(ipv6_src_step) is str: # convert ipv6 step to number - ipv6_src_step = ipv4_str_to_num(is_valid_ipv6(ipv6_src_step)[-4:]) + step = kwargs['ipv6_src_step'] + if step < 1: + raise STLError('ipv6_src_step has to be at least 1') + if type(step) is str: # convert ipv6 step to number + step = ipv4_str_to_num(is_valid_ipv6(step)[-4:]) if kwargs['ipv6_src_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_src', size = 4, op = 'inc', step = ipv6_src_step, - min_value = ipv6_src_addr_num, - max_value = ipv6_src_addr_num + ipv6_src_count * ipv6_src_step)) + add_val = ipv6_src_addr_num + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ipv6_src_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_src', size = 4, op = 'dec', step = ipv6_src_step, - min_value = ipv6_src_addr_num - ipv6_src_count * ipv6_src_step, - max_value = ipv6_src_addr_num)) + add_val = ipv6_src_addr_num - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ipv6_src_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_src', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) + var_name = 'ipv6_src_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) else: raise STLError('ipv6_src_mode %s is not supported' % kwargs['ipv6_src_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='ipv6_src', pkt_offset = 'IPv6.src', offset_fixup = 12)) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.src', offset_fixup = 12, add_val = add_val)) if kwargs['ipv6_dst_mode'] != 'fixed': - ipv6_dst_count = kwargs['ipv6_dst_count'] - 1 - if ipv6_dst_count < 0: + count = int(kwargs['ipv6_dst_count']) - 1 + if count < 0: raise STLError('ipv6_dst_count has to be at least 1') - if ipv6_dst_count > 0: + if count > 0: + add_val = 0 ipv6_dst_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_dst_addr'])[-4:]) - ipv6_dst_step = kwargs['ipv6_dst_step'] - if type(ipv6_dst_step) is str: # convert ipv6 step to number - ipv6_dst_step = ipv4_str_to_num(is_valid_ipv6(ipv6_dst_step)[-4:]) + step = kwargs['ipv6_dst_step'] + if step < 1: + raise STLError('ipv6_dst_step has to be at least 1') + if type(step) is str: # convert ipv6 step to number + step = ipv4_str_to_num(is_valid_ipv6(step)[-4:]) if kwargs['ipv6_dst_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_dst', size = 4, op = 'inc', step = ipv6_dst_step, - min_value = ipv6_dst_addr_num, - max_value = ipv6_dst_addr_num + ipv6_dst_count * ipv6_dst_step)) + add_val = ipv6_dst_addr_num + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ipv6_dst_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_dst', size = 4, op = 'dec', step = ipv6_dst_step, - min_value = ipv6_dst_addr_num - ipv6_dst_count * ipv6_dst_step, - max_value = ipv6_dst_addr_num)) + add_val = ipv6_dst_addr_num - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['ipv6_dst_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_dst', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) + var_name = 'ipv6_dst_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', min_value = 0, max_value = 0xffffffff)) else: raise STLError('ipv6_dst_mode %s is not supported' % kwargs['ipv6_dst_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='ipv6_dst', pkt_offset = 'IPv6.dst', offset_fixup = 12)) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.dst', offset_fixup = 12, add_val = add_val)) else: raise NotImplementedError("l3_protocol '%s' is not supported by TRex yet." % kwargs['l3_protocol']) @@ -1003,44 +1057,66 @@ def generate_packet(**user_kwargs): ) # TCP VM if kwargs['tcp_src_port_mode'] != 'fixed': - tcp_src_port_count = kwargs['tcp_src_port_count'] - 1 - if tcp_src_port_count < 0: + count = int(kwargs['tcp_src_port_count']) - 1 + if count < 0: raise STLError('tcp_src_port_count has to be at least 1') - if tcp_src_port_count > 0: + if count > 0: fix_ipv4_checksum = True + add_val = 0 + step = kwargs['tcp_src_port_step'] + if step < 1: + raise STLError('tcp_src_port_step has to be at least 1') if kwargs['tcp_src_port_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_src', size = 2, op = 'inc', step = kwargs['tcp_src_port_step'], - min_value = kwargs['tcp_src_port'], - max_value = kwargs['tcp_src_port'] + tcp_src_port_count * kwargs['tcp_src_port_step'])) + add_val = kwargs['tcp_src_port'] + var_name = '%s_%s_%s_%s' % ('inc', 2, count, step) + if var_name not in vm_variables_cache: + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['tcp_src_port_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_src', size = 2, op = 'dec', step = kwargs['tcp_src_port_step'], - min_value = kwargs['tcp_src_port'] - tcp_src_port_count * kwargs['tcp_src_port_step'], - max_value = kwargs['tcp_src_port'])) + add_val = kwargs['tcp_src_port'] - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['tcp_src_port_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_src', size = 2, op = 'random', min_value = 0, max_value = 0xffff)) + var_name = 'tcp_src_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff)) else: raise STLError('tcp_src_port_mode %s is not supported' % kwargs['tcp_src_port_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='tcp_src', pkt_offset = 'TCP.sport')) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'TCP.sport', add_val = add_val)) if kwargs['tcp_dst_port_mode'] != 'fixed': - tcp_dst_port_count = kwargs['tcp_dst_port_count'] - 1 - if tcp_dst_port_count < 0: + count = int(kwargs['tcp_dst_port_count']) - 1 + if count < 0: raise STLError('tcp_dst_port_count has to be at least 1') - if tcp_dst_port_count > 0: + if count > 0: fix_ipv4_checksum = True + add_val = 0 + step = kwargs['tcp_dst_port_step'] + if step < 1: + raise STLError('tcp_dst_port_step has to be at least 1') if kwargs['tcp_dst_port_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_dst', size = 2, op = 'inc', step = kwargs['tcp_dst_port_step'], - min_value = kwargs['tcp_dst_port'], - max_value = kwargs['tcp_dst_port'] + tcp_dst_port_count * kwargs['tcp_dst_port_step'])) + add_val = kwargs['tcp_dst_port'] + var_name = '%s_%s_%s_%s' % ('inc', 2, count, step) + if var_name not in vm_variables_cache: + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['tcp_dst_port_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_dst', size = 2, op = 'dec', step = kwargs['tcp_dst_port_step'], - min_value = kwargs['tcp_dst_port'] - tcp_dst_port_count * kwargs['tcp_dst_port_step'], - max_value = kwargs['tcp_dst_port'])) + add_val = kwargs['tcp_dst_port'] - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['tcp_dst_port_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_dst', size = 2, op = 'random', min_value = 0, max_value = 0xffff)) + var_name = 'tcp_dst_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff)) else: raise STLError('tcp_dst_port_mode %s is not supported' % kwargs['tcp_dst_port_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='tcp_dst', pkt_offset = 'TCP.dport')) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'TCP.dport', add_val = add_val)) elif kwargs['l4_protocol'] == 'udp': #fields_desc = [ ShortEnumField("sport", 53, UDP_SERVICES), @@ -1052,44 +1128,64 @@ def generate_packet(**user_kwargs): len = kwargs['udp_length'], chksum = None) # UDP VM if kwargs['udp_src_port_mode'] != 'fixed': - udp_src_port_count = kwargs['udp_src_port_count'] - 1 - if udp_src_port_count < 0: + count = int(kwargs['udp_src_port_count']) - 1 + if count < 0: raise STLError('udp_src_port_count has to be at least 1') - if udp_src_port_count > 0: + if count > 0: fix_ipv4_checksum = True + add_val = 0 + step = kwargs['udp_src_port_step'] + if step < 1: + raise STLError('udp_src_port_step has to be at least 1') if kwargs['udp_src_port_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_src', size = 2, op = 'inc', step = kwargs['udp_src_port_step'], - min_value = kwargs['udp_src_port'], - max_value = kwargs['udp_src_port'] + udp_src_port_count * kwargs['udp_src_port_step'])) + add_val = kwargs['udp_src_port'] + var_name = '%s_%s_%s_%s' % ('inc', 2, count, step) + if var_name not in vm_variables_cache: + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['udp_src_port_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_src', size = 2, op = 'dec', step = kwargs['udp_src_port_step'], - min_value = kwargs['udp_src_port'] - udp_src_port_count * kwargs['udp_src_port_step'], - max_value = kwargs['udp_src_port'])) + add_val = kwargs['udp_src_port'] - count * step + 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, + max_value = count * step)) + vm_variables_cache[var_name] = True elif kwargs['udp_src_port_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_src', size = 2, op = 'random', min_value = 0, max_value = 0xffff)) + var_name = 'udp_src_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff)) else: raise STLError('udp_src_port_mode %s is not supported' % kwargs['udp_src_port_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='udp_src', pkt_offset = 'UDP.sport')) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'UDP.sport', add_val = add_val)) if kwargs['udp_dst_port_mode'] != 'fixed': - udp_dst_port_count = kwargs['udp_dst_port_count'] - 1 - if udp_dst_port_count < 0: + count = int(kwargs['udp_dst_port_count']) - 1 + if count < 0: raise STLError('udp_dst_port_count has to be at least 1') - if udp_dst_port_count > 0: + if count > 0: fix_ipv4_checksum = True + add_val = 0 + step = kwargs['udp_dst_port_step'] + if step < 1: + raise STLError('udp_dst_port_step has to be at least 1') if kwargs['udp_dst_port_mode'] == 'increment': - vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_dst', size = 2, op = 'inc', step = kwargs['udp_dst_port_step'], - min_value = kwargs['udp_dst_port'], - max_value = kwargs['udp_dst_port'] + udp_dst_port_count * kwargs['udp_dst_port_step'])) + add_val = kwargs['udp_dst_port'] + var_name = '%s_%s_%s_%s' % ('inc', 2, count, step) + if var_name not in vm_variables_cache: + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step, + max_value = count * step)) elif kwargs['udp_dst_port_mode'] == 'decrement': - vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_dst', size = 2, op = 'dec', step = kwargs['udp_dst_port_step'], - min_value = kwargs['udp_dst_port'] - udp_dst_port_count * kwargs['udp_dst_port_step'], - max_value = kwargs['udp_dst_port'])) + add_val = kwargs['udp_dst_port'] + 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, + max_value = count * step)) elif kwargs['udp_dst_port_mode'] == 'random': - vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_dst', size = 2, op = 'random', min_value = 0, max_value = 0xffff)) + var_name = 'udp_dst_random' + vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff)) else: raise STLError('udp_dst_port_mode %s is not supported' % kwargs['udp_dst_port_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='udp_dst', pkt_offset = 'UDP.dport')) + vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'UDP.dport', add_val = add_val)) else: raise NotImplementedError("l4_protocol '%s' is not supported by TRex yet." % kwargs['l3_protocol']) base_pkt /= l4_layer @@ -1099,10 +1195,10 @@ def generate_packet(**user_kwargs): if length_mode == 'auto': payload_len = 0 elif length_mode == 'fixed': - if 'frame_size' in user_kwargs: + if 'frame_size' in user_kwargs: # L2 has higher priority over L3 payload_len = kwargs['frame_size'] - len(base_pkt) elif 'l3_length' in user_kwargs: - payload_len = kwargs['l3_length'] - len(base_pkt) - len(l2_layer) + payload_len = kwargs['l3_length'] - (len(base_pkt) - len(l2_layer)) else: # default payload_len = kwargs['frame_size'] - len(base_pkt) elif length_mode == 'imix': @@ -1151,9 +1247,7 @@ def generate_packet(**user_kwargs): vm_cmds.append(CTRexVmDescFixIpv4(offset = 'IP')) if vm_cmds: split_by_field = None - if kwargs['split_by_cores'] == 'single': - raise STLError("split_by_cores 'single' not implemented yet") - elif kwargs['split_by_cores'] == 'split': + if kwargs['split_by_cores'] == 'split': max_length = 0 for cmd in vm_cmds: if isinstance(cmd, CTRexVmDescFlowVar): @@ -1166,8 +1260,10 @@ def generate_packet(**user_kwargs): if length > max_length: max_length = length split_by_field = cmd.name + elif kwargs['split_by_cores'] == 'single': + raise STLError("split_by_cores 'single' not implemented yet") elif kwargs['split_by_cores'] != 'duplicate': - raise STLError("split_by_cores '%s' not supported" % kwargs['split_by_cores']) + raise STLError("split_by_cores '%s' is not supported" % kwargs['split_by_cores']) pkt.add_command(CTRexScRaw(vm_cmds, split_by_field)) # debug (only the base packet, without VM) @@ -1226,7 +1322,8 @@ def split_vlan_args(kwargs): def correct_direction(user_kwargs, kwargs): if kwargs['direction'] == 0: return - user_kwargs['mac_src'], user_kwargs['mac_dst'] = kwargs['mac_dst'], kwargs['mac_src'] + user_kwargs['mac_src'] = kwargs['mac_src2'] + user_kwargs['mac_dst'] = kwargs['mac_dst2'] if kwargs['l3_protocol'] == 'ipv4': for arg in kwargs.keys(): if 'ip_src_' in arg: |