diff options
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
7 files changed, 401 insertions, 129 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/api.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/api.py index d19dcaf0..9b8f9f79 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/api.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/api.py @@ -10,18 +10,6 @@ from trex_stl_streams import * from trex_stl_packet_builder_scapy import * from scapy.all import * -# packet builder -STLPktBuilder = CScapyTRexPktBuilder - -# VM -STLVmFlowVar = CTRexVmDescFlowVar -STLVmWrFlowVar = CTRexVmDescWrFlowVar -STLVmWrMaskFlowVar = CTRexVmDescWrMaskFlowVar -STLVmFixIpv4 = CTRexVmDescFixIpv4 -STLVmTrimPktSize = CTRexVmDescTrimPktSize -STLVmTupleGen = CTRexVmDescTupleGen -STLVmTrimPktSize = CTRexVmDescTrimPktSize - # simulator from trex_stl_sim import STLSim 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 c7503ab0..1d109988 100644 --- 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 @@ -406,11 +406,25 @@ class STLClient(object): async_port : int the ASYNC port - :return: - None + For example:: - :raises: - None + # connect to local TRex server + c = STLClient() + + # connect to remote server trex-remote-server + c = STLClient(server = "trex-remote-server" ) + + c = STLClient(server = "10.0.0.10" ) + + # verbose mode + c = STLClient(server = "10.0.0.10", verbose_level = LoggerApi.VERBOSE_HIGH ) + + # change user name + c = STLClient(username = "root",server = "10.0.0.10", verbose_level = LoggerApi.VERBOSE_HIGH ) + + c.connect() + + c.disconnect() """ 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 a74824d2..81676df8 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 @@ -846,7 +846,7 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True @@ -854,17 +854,17 @@ def generate_packet(**user_kwargs): 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 = var_name, size = 4, op = 'dec', step = step, + vm_cmds.append(STLVmFlowVar(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 var_name = 'mac_src_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) else: raise STLError('mac_src_mode %s is not supported' % kwargs['mac_src_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.src', offset_fixup = 2, add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.src', offset_fixup = 2, add_val = add_val)) if kwargs['mac_dst_mode'] != 'fixed': count = int(kwargs['mac_dst_count']) - 1 @@ -881,7 +881,7 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True @@ -889,17 +889,17 @@ def generate_packet(**user_kwargs): 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 = var_name, size = 4, op = 'dec', step = step, + vm_cmds.append(STLVmFlowVar(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 var_name = 'mac_dst_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) else: raise STLError('mac_dst_mode %s is not supported' % kwargs['mac_dst_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.dst', offset_fixup = 2, add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.dst', 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), @@ -933,7 +933,7 @@ def generate_packet(**user_kwargs): 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 = 'inc', step = step, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True @@ -941,14 +941,14 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'dec', step = step, min_value = 0x7fff - count * step, max_value = 0x7fff)) vm_variables_cache[var_name] = True elif vlan_id_mode == 'random': add_val = 0 var_name = 'vlan_id_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', max_value = 0xffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'random', max_value = 0xffff)) else: raise STLError('vlan_id_mode %s is not supported' % vlan_id_mode) vm_cmds.append(STLVmWrMaskFlowVar(fv_name = var_name, pkt_offset = '802|1Q:%s.vlan' % i, @@ -1005,7 +1005,7 @@ def generate_packet(**user_kwargs): add_val = ip_src_addr - 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True @@ -1013,17 +1013,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(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['ip_src_mode'] == 'random': add_val = 0 var_name = 'ip_src_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) else: raise STLError('ip_src_mode %s is not supported' % kwargs['ip_src_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IP.src', add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'IP.src', add_val = add_val)) if kwargs['ip_dst_mode'] != 'fixed': count = int(kwargs['ip_dst_count']) - 1 @@ -1043,7 +1043,7 @@ def generate_packet(**user_kwargs): add_val = ip_dst_addr - 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True @@ -1051,17 +1051,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(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['ip_dst_mode'] == 'random': add_val = 0 var_name = 'ip_dst_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) else: raise STLError('ip_dst_mode %s is not supported' % kwargs['ip_dst_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IP.dst', add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'IP.dst', add_val = add_val)) elif kwargs['l3_protocol'] == 'ipv6': #fields_desc = [ BitField("version" , 6 , 4), @@ -1099,7 +1099,7 @@ def generate_packet(**user_kwargs): add_val = ipv6_src_addr_num - 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True @@ -1107,17 +1107,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(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['ipv6_src_mode'] == 'random': add_val = 0 var_name = 'ipv6_src_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) else: raise STLError('ipv6_src_mode %s is not supported' % kwargs['ipv6_src_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.src', offset_fixup = 12, add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.src', offset_fixup = 12, add_val = add_val)) if kwargs['ipv6_dst_mode'] != 'fixed': count = int(kwargs['ipv6_dst_count']) - 1 @@ -1134,7 +1134,7 @@ def generate_packet(**user_kwargs): add_val = ipv6_dst_addr_num - 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'inc', step = step, min_value = 0x7fffffff, max_value = 0x7fffffff + count * step)) vm_variables_cache[var_name] = True @@ -1142,17 +1142,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(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['ipv6_dst_mode'] == 'random': add_val = 0 var_name = 'ipv6_dst_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff)) else: raise STLError('ipv6_dst_mode %s is not supported' % kwargs['ipv6_dst_mode']) - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.dst', offset_fixup = 12, add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.dst', offset_fixup = 12, add_val = add_val)) elif kwargs['l3_protocol'] is not None: raise NotImplementedError("l3_protocol '%s' is not supported by TRex yet." % kwargs['l3_protocol']) @@ -1206,7 +1206,7 @@ def generate_packet(**user_kwargs): add_val = kwargs['tcp_src_port'] - 0x7fff 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True @@ -1214,17 +1214,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'dec', step = step, min_value = 0x7fff - count * step, max_value = 0x7fff)) vm_variables_cache[var_name] = True elif kwargs['tcp_src_port_mode'] == 'random': add_val = 0 var_name = 'tcp_src_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', max_value = 0xffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'random', 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 = var_name, pkt_offset = 'TCP.sport', add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'TCP.sport', add_val = add_val)) if kwargs['tcp_dst_port_mode'] != 'fixed': count = int(kwargs['tcp_dst_port_count']) - 1 @@ -1239,7 +1239,7 @@ def generate_packet(**user_kwargs): add_val = kwargs['tcp_dst_port'] - 0x7fff 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True @@ -1247,17 +1247,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'dec', step = step, min_value = 0x7fff - count * step, max_value = 0x7fff)) vm_variables_cache[var_name] = True elif kwargs['tcp_dst_port_mode'] == 'random': add_val = 0 var_name = 'tcp_dst_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', max_value = 0xffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'random', 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 = var_name, pkt_offset = 'TCP.dport', add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'TCP.dport', add_val = add_val)) elif kwargs['l4_protocol'] == 'udp': assert kwargs['l3_protocol'] in ('ipv4', 'ipv6'), 'UDP must be over ipv4/ipv6' @@ -1282,7 +1282,7 @@ def generate_packet(**user_kwargs): add_val = kwargs['udp_src_port'] - 0x7fff 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 0x7fff, max_value = 0x7fff + count * step)) vm_variables_cache[var_name] = True @@ -1290,17 +1290,17 @@ def generate_packet(**user_kwargs): 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'dec', step = step, min_value = 0x7fff - count * step, max_value = 0x7fff)) vm_variables_cache[var_name] = True elif kwargs['udp_src_port_mode'] == 'random': add_val = 0 var_name = 'udp_src_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', max_value = 0xffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'random', 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 = var_name, pkt_offset = 'UDP.sport', add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'UDP.sport', add_val = add_val)) if kwargs['udp_dst_port_mode'] != 'fixed': count = int(kwargs['udp_dst_port_count']) - 1 @@ -1315,23 +1315,23 @@ def generate_packet(**user_kwargs): add_val = kwargs['udp_dst_port'] - 0x7fff 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'inc', step = step, min_value = 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, + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'dec', step = step, min_value = 0x7fff - count * step, max_value = 0x7fff)) elif kwargs['udp_dst_port_mode'] == 'random': add_val = 0 var_name = 'udp_dst_random' - vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', max_value = 0xffff)) + vm_cmds.append(STLVmFlowVar(name = var_name, size = 2, op = 'random', 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 = var_name, pkt_offset = 'UDP.dport', add_val = add_val)) + vm_cmds.append(STLVmWrFlowVar(fv_name = var_name, pkt_offset = 'UDP.dport', add_val = add_val)) elif kwargs['l4_protocol'] is not None: raise NotImplementedError("l4_protocol '%s' is not supported by TRex yet." % kwargs['l4_protocol']) if l4_layer is not None: @@ -1358,10 +1358,10 @@ def generate_packet(**user_kwargs): raise STLError('frame_size_min is bigger than frame_size_max') if kwargs['frame_size_min'] != kwargs['frame_size_max']: fix_ipv4_checksum = True - vm_cmds.append(CTRexVmDescFlowVar(name = 'pkt_len', size = 2, op = trim_dict[length_mode], step = kwargs['frame_size_step'], + vm_cmds.append(STLVmFlowVar(name = 'pkt_len', size = 2, op = trim_dict[length_mode], step = kwargs['frame_size_step'], min_value = kwargs['frame_size_min'], max_value = kwargs['frame_size_max'])) - vm_cmds.append(CTRexVmDescTrimPktSize('pkt_len')) + vm_cmds.append(STLVmTrimPktSize('pkt_len')) payload_len = kwargs['frame_size_max'] - len(base_pkt) else: # size is determined by L3 if kwargs['l3_length_min'] < 40 or kwargs['l3_length_max'] < 40: @@ -1370,16 +1370,16 @@ def generate_packet(**user_kwargs): raise STLError('l3_length_min is bigger than l3_length_max') if kwargs['l3_length_min'] != kwargs['l3_length_max']: fix_ipv4_checksum = True - vm_cmds.append(CTRexVmDescFlowVar(name = 'pkt_len', size = 2, op = trim_dict[length_mode], step = kwargs['l3_length_step'], + vm_cmds.append(STLVmFlowVar(name = 'pkt_len', size = 2, op = trim_dict[length_mode], step = kwargs['l3_length_step'], min_value = kwargs['l3_length_min'] + len(l2_layer), max_value = kwargs['l3_length_max'] + len(l2_layer))) payload_len = kwargs['l3_length_max'] + len(l2_layer) - len(base_pkt) - vm_cmds.append(CTRexVmDescTrimPktSize('pkt_len')) + vm_cmds.append(STLVmTrimPktSize('pkt_len')) if (l3_layer and l3_layer.name == 'IP'): - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'IP.len', add_val = -len(l2_layer))) + vm_cmds.append(STLVmWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'IP.len', add_val = -len(l2_layer))) if (l4_layer and l4_layer.name == 'UDP'): - vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'UDP.len', add_val = -len(l2_layer) - len(l3_layer))) + vm_cmds.append(STLVmWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'UDP.len', add_val = -len(l2_layer) - len(l3_layer))) else: raise STLError('length_mode should be one of the following: %s' % ['auto', 'fixed'] + trim_dict.keys()) @@ -1390,13 +1390,13 @@ def generate_packet(**user_kwargs): pkt = STLPktBuilder() pkt.set_packet(base_pkt) if fix_ipv4_checksum and l3_layer.name == 'IP' and kwargs['ip_checksum'] is None: - vm_cmds.append(CTRexVmDescFixIpv4(offset = 'IP')) + vm_cmds.append(STLVmFixIpv4(offset = 'IP')) if vm_cmds: split_by_field = None if kwargs['split_by_cores'] == 'split': max_length = 0 for cmd in vm_cmds: - if isinstance(cmd, CTRexVmDescFlowVar): + if isinstance(cmd, STLVmFlowVar): if cmd.op not in ('inc', 'dec'): continue length = float(cmd.max_value - cmd.min_value) / cmd.step @@ -1410,7 +1410,7 @@ def generate_packet(**user_kwargs): raise STLError("split_by_cores 'single' not implemented yet") elif kwargs['split_by_cores'] != 'duplicate': raise STLError("split_by_cores '%s' is not supported" % kwargs['split_by_cores']) - pkt.add_command(CTRexScRaw(vm_cmds, split_by_field)) + pkt.add_command(STLScVmRaw(vm_cmds, split_by_field)) # debug (only the base packet, without VM) debug_filename = kwargs.get('save_to_pcap') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py index eac12ebb..35326590 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py @@ -172,12 +172,12 @@ class CTRexScTrimPacketSize(CTRexScriptsBase): raise CTRexPacketBuildException(-11, 'CTRexScTrimPacketSize min_pkt_size is bigger than max_pkt_size '); -class CTRexScRaw(CTRexScriptsBase): +class STLScVmRaw(CTRexScriptsBase): """ raw instructions """ def __init__(self,list_of_commands=None,split_by_field=None): - super(CTRexScRaw, self).__init__() + super(STLScVmRaw, self).__init__() self.split_by_field = split_by_field if list_of_commands==None: self.commands =[] @@ -526,16 +526,62 @@ def check_for_int (val): assert type(val)==int, 'type of vcal is not int' -class CTRexVmDescFlowVar(CTRexVmDescBase): - """ - flow var instruction - """ +class STLVmFlowVar(CTRexVmDescBase): def __init__(self, name, init_value=None, min_value=0, max_value=255, size=4, step=1,op="inc"): """ - + Flow variable instruction. Allocate a variable on a stream context. The size of the variable could be determined + The operation can be inc, dec and random. In case of increment and decrement operation, it is possible to set the "step" size. + Initialization value, minimum and maximum value could be set too. + + :parameters: + name : string + The name of the stream variable + + init_value : int + The init value of the variable. in case of None it will be min_value + + min_value : int + The min value + + max_value : int + The max value + + size : int + the number of bytes of the variable. could be 1,2,4,8 for uint8_t, uint16_t, uint32_t, uint64_t + + step : int + step in case of "inc","dec" operation + + op : string + could be "inc", "dec", "random" + + For example:: + + # input + STLVmFlowVar(min_value=0, max_value=3, size=1,op="inc") + + # output 0,1,2,3,0,1,2,3 .. + + # input + STLVmFlowVar(min_value=0, max_value=3, size=1,op="dec") + + # output 0,3,2,1,0,3,2,1 .. + + + # input + STLVmFlowVar(min_value=0, max_value=3, size=1,op="random") + + # output 1,1,2,3,1,2,1,0 .. + + # input + STLVmFlowVar(min_value=0, max_value=10, size=1,op="inc",step=3) + + # output 0,3,6,9,0,3,6,9,0.. + + """ - super(CTRexVmDescFlowVar, self).__init__() + super(STLVmFlowVar, self).__init__() self.name = name; assert type(name)==str, 'type of name is not str' self.size =size @@ -562,9 +608,32 @@ class CTRexVmDescFlowVar(CTRexVmDescBase): return [self.name] -class CTRexVmDescFixIpv4(CTRexVmDescBase): +class STLVmFixIpv4(CTRexVmDescBase): def __init__(self, offset): - super(CTRexVmDescFixIpv4, self).__init__() + """ + Fix IPv4 header checksum. should be added if the packet header was changed and there is a need to fix he checksum + + :parameters: + offset : uint16_t or string + **IPv4 header** offset from packet start. It is **not** the offset of the checksum field itself. + in could be string in case of scapy packet. format IP[:[id]] + + For example:: + + pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) + + # by offset + STLVmFixIpv4(offset=14) + + # in case of scapy packet can be defined by header name + STLVmFixIpv4(offset="IP") + + # string for second "IP" header in the packet is IP:1 + STLVmFixIpv4(offset="IP:1") + + """ + + super(STLVmFixIpv4, self).__init__() self.offset = offset; # could be a name of offset def get_obj (self): @@ -574,9 +643,48 @@ class CTRexVmDescFixIpv4(CTRexVmDescBase): if type(self.offset)==str: self.offset = parent._pkt_layer_offset(self.offset); -class CTRexVmDescWrFlowVar(CTRexVmDescBase): +class STLVmWrFlowVar(CTRexVmDescBase): def __init__(self, fv_name, pkt_offset, offset_fixup=0, add_val=0, is_big=True): - super(CTRexVmDescWrFlowVar, self).__init__() + """ + Write a stream variable into a packet field. + The write is done in size of the stream variable. + In case there is a need to change the write have a look into the command `STLVmWrMaskFlowVar`. + The Field name/offset can be given by name in this format ``header[:id].field``. + + + :parameters: + fv_name : string + the stream variable to write to a packet offset + + pkt_offset : string or in + the name of the field or offset in byte from packet start. + + offset_fixup : int + how many bytes to go forward. In case of a negative value go backward + + add_val : int + value to add to stream variable before writing it to packet field. can be used as a constant offset + + is_big : bool + how to write the variable to the the packet. is it big-edian or little edian + + For example:: + + pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) + + + # write to ip.src offset + STLVmWrFlowVar (fv_name="tuple", pkt_offset= "IP.src" ) + + # packet offset is varible + STLVmWrFlowVar (fv_name="tuple", pkt_offset= 26 ) + + # add l3_len_fix before writing fv_rand into IP.len field + STLVmWrFlowVar(fv_name="fv_rand", pkt_offset= "IP.len", add_val=l3_len_fix) + + """ + + super(STLVmWrFlowVar, self).__init__() self.name =fv_name assert type(fv_name)==str, 'type of fv_name is not str' self.offset_fixup =offset_fixup @@ -598,9 +706,9 @@ class CTRexVmDescWrFlowVar(CTRexVmDescBase): t=parent._name_to_offset(self.pkt_offset) self.pkt_offset = t[0] -class CTRexVmDescWrMaskFlowVar(CTRexVmDescBase): +class STLVmWrMaskFlowVar(CTRexVmDescBase): def __init__(self, fv_name, pkt_offset, pkt_cast_size=1, mask=0xff, shift=0, add_value=0, offset_fixup=0, is_big=True): - super(CTRexVmDescWrMaskFlowVar, self).__init__() + super(STLVmWrMaskFlowVar, self).__init__() self.name =fv_name assert type(fv_name)==str, 'type of fv_name is not str' self.offset_fixup =offset_fixup @@ -633,9 +741,61 @@ class CTRexVmDescWrMaskFlowVar(CTRexVmDescBase): self.pkt_offset = t[0] -class CTRexVmDescTrimPktSize(CTRexVmDescBase): +class STLVmTrimPktSize(CTRexVmDescBase): + """ + Trim packet size by stream variable size. This instruction will only change the total packet size and will not fix up the fields to match the new size. + + + :parameters: + fv_name : string + the stream variable name. the value from this variable would be the new total packet size. + + + + For example:: + + def create_stream (self): + # pkt + p_l2 = Ether(); + p_l3 = IP(src="16.0.0.1",dst="48.0.0.1") + p_l4 = UDP(dport=12,sport=1025) + pyld_size = max(0, self.max_pkt_size_l3 - len(p_l3/p_l4)); + base_pkt = p_l2/p_l3/p_l4/('\x55'*(pyld_size)) + + l3_len_fix =-(len(p_l2)); + l4_len_fix =-(len(p_l2/p_l3)); + + + # vm + vm = STLScVmRaw( [ STLVmFlowVar(name="fv_rand", min_value=64, + max_value=len(base_pkt), + size=2, op="inc"), + + STLVmTrimPktSize("fv_rand"), # change total packet size <<< + + STLVmWrFlowVar(fv_name="fv_rand", + pkt_offset= "IP.len", + add_val=l3_len_fix), # fix ip len + + STLVmFixIpv4(offset = "IP"), # fix checksum + + STLVmWrFlowVar(fv_name="fv_rand", + pkt_offset= "UDP.len", + add_val=l4_len_fix) # fix udp len + ] + ) + + pkt = STLPktBuilder(pkt = base_pkt, + vm = vm) + + return STLStream(packet = pkt, + mode = STLTXCont()) + + + """ + def __init__(self,fv_name): - super(CTRexVmDescTrimPktSize, self).__init__() + super(STLVmTrimPktSize, self).__init__() self.name = fv_name assert type(fv_name)==str, 'type of fv_name is not str' @@ -647,9 +807,116 @@ class CTRexVmDescTrimPktSize(CTRexVmDescBase): -class CTRexVmDescTupleGen(CTRexVmDescBase): +class STLVmTupleGen(CTRexVmDescBase): def __init__(self,name, ip_min="0.0.0.1", ip_max="0.0.0.10", port_min=1025, port_max=65535, limit_flows=100000, flags=0): - super(CTRexVmDescTupleGen, self).__init__() + """ + Generate a struct with two varibles. ``var_name.ip`` as uint32_t and ``var_name.port`` as uint16_t + The variable are dependent. When the ip variable is wrapped the port is getting increment. + + For: + + * ip_min = 10.0.0.1 + * ip_max = 10.0.0.5 + * port_min = 1025 + * port_max = 1028 + * limit_flows = 10 + + The result: + + +------------+------------+-----------+ + | ip | port | flow_id | + +============+============+===========+ + | 10.0.0.1 | 1025 | 1 | + +------------+------------+-----------+ + | 10.0.0.2 | 1025 | 2 | + +------------+------------+-----------+ + | 10.0.0.3 | 1025 | 3 | + +------------+------------+-----------+ + | 10.0.0.4 | 1025 | 4 | + +------------+------------+-----------+ + | 10.0.0.5 | 1025 | 5 | + +------------+------------+-----------+ + | 10.0.0.1 | 1026 | 6 | + +------------+------------+-----------+ + | 10.0.0.2 | 1026 | 7 | + +------------+------------+-----------+ + | 10.0.0.3 | 1026 | 8 | + +------------+------------+-----------+ + | 10.0.0.4 | 1026 | 9 | + +------------+------------+-----------+ + | 10.0.0.5 | 1026 | 10 | + +------------+------------+-----------+ + | 10.0.0.1 | 1025 | 1 | + +------------+------------+-----------+ + + + :parameters: + name : string + The name of the stream struct. + + ip_min : string or int + The min value of the ip value. It can be in IPv4 format + + ip_max : string or int + The max value of the ip value. It can be in IPv4 format + + port_min : int + min value for port variable + + port_max : int + max value for port variable + + limit_flows : int + The limit of number of flows + + flags : 0 + + ="0.0.0.10", port_min=1025, port_max=65535, limit_flows=100000, flags=0 + + + For example:: + + def create_stream (self): + # pkt + p_l2 = Ether(); + p_l3 = IP(src="16.0.0.1",dst="48.0.0.1") + p_l4 = UDP(dport=12,sport=1025) + pyld_size = max(0, self.max_pkt_size_l3 - len(p_l3/p_l4)); + base_pkt = p_l2/p_l3/p_l4/('\x55'*(pyld_size)) + + l3_len_fix =-(len(p_l2)); + l4_len_fix =-(len(p_l2/p_l3)); + + + # vm + vm = STLScVmRaw( [ STLVmFlowVar(name="fv_rand", min_value=64, + max_value=len(base_pkt), + size=2, op="inc"), + + STLVmTrimPktSize("fv_rand"), # change total packet size <<< + + STLVmWrFlowVar(fv_name="fv_rand", + pkt_offset= "IP.len", + add_val=l3_len_fix), # fix ip len + + STLVmFixIpv4(offset = "IP"), # fix checksum + + STLVmWrFlowVar(fv_name="fv_rand", + pkt_offset= "UDP.len", + add_val=l4_len_fix) # fix udp len + ] + ) + + pkt = STLPktBuilder(pkt = base_pkt, + vm = vm) + + return STLStream(packet = pkt, + mode = STLTXCont()) + + + """ + + super(STLVmTupleGen, self).__init__() self.name = name assert type(name)==str, 'type of fv_name is not str' self.ip_min = convert_val(ip_min); @@ -672,22 +939,22 @@ class CTRexVmDescTupleGen(CTRexVmDescBase): ################################################################################################ -class CScapyTRexPktBuilder(CTrexPktBuilderInterface): - """ - This class defines the TRex API of building a packet and Field engine using scapy package. - Using this class the user can also define how TRex will handle the packet by specifying the Field engine setting. - pkt could be Scapy pkt or pcap file name - When path_relative_to_profile is a True load pcap file from a path relative to the profile - """ +class STLPktBuilder(CTrexPktBuilderInterface): def __init__(self, pkt = None, pkt_buffer = None, vm = None, path_relative_to_profile = False, build_raw = False, remove_fcs = True): """ + + This class defines a way to build a template packet, and Field Engine using scapy package. + Using this class the user can also define how TRex will handle the packet by specifying the Field engine setting. + pkt could be Scapy pkt or pcap file name + When path_relative_to_profile is a True load pcap file from a path relative to the profile + Instantiate a CTRexPktBuilder object :parameters: - pkt : Scapy or pcap file filename - a scapy packet + pkt : string, + Scapy or pcap file filename a scapy packet pkt_buffer : string a packet as buffer @@ -717,7 +984,7 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): path_relative_to_profile = True) - vm = CTRexScRaw( [ STLVmTupleGen ( ip_min="16.0.0.1", ip_max="16.0.0.2", + vm = STLScVmRaw( [ STLVmTupleGen ( ip_min="16.0.0.1", ip_max="16.0.0.2", port_min=1025, port_max=65535, name="tuple"), # define tuple gen @@ -735,7 +1002,7 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): """ - super(CScapyTRexPktBuilder, self).__init__() + super(STLPktBuilder, self).__init__() self.pkt = None # as input self.pkt_raw = None # from raw pcap file @@ -760,10 +1027,10 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): # process VM if vm != None: - if not isinstance(vm, (CTRexScRaw, list)): + if not isinstance(vm, (STLScVmRaw, list)): raise CTRexPacketBuildException(-14, "bad value for variable vm") - self.add_command(vm if isinstance(vm, CTRexScRaw) else CTRexScRaw(vm)) + self.add_command(vm if isinstance(vm, STLScVmRaw) else STLScVmRaw(vm)) # raw source build to see MAC presence/ fields offset by name in VM if build_raw and self.pkt_raw and not self.pkt: @@ -928,7 +1195,7 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): # compile the VM for sc in self.vm_scripts: - if isinstance(sc, CTRexScRaw): + if isinstance(sc, STLScVmRaw): self._compile_raw(sc) def get_pkt_len (self): 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 4529efa9..2a8bedb8 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 @@ -1,7 +1,7 @@ from collections import namedtuple, OrderedDict -from trex_stl_packet_builder_scapy import CScapyTRexPktBuilder +from trex_stl_packet_builder_scapy import STLPktBuilder from trex_stl_streams import STLStream import base64 import trex_stl_stats @@ -576,7 +576,7 @@ class Port(object): # lazy build scapy repr. if not 'pkt_type' in obj: - obj['pkt_type'] = CScapyTRexPktBuilder.pkt_layers_desc_from_buffer(obj['pkt']) + obj['pkt_type'] = STLPktBuilder.pkt_layers_desc_from_buffer(obj['pkt']) data[id] = OrderedDict([ ('id', id), ('packet_type', obj['pkt_type']), diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py index d582b499..8596bbfe 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_std.py @@ -12,7 +12,7 @@ def stl_map_ports (client, ports = None): client.reset(ports) # generate streams - base_pkt = CScapyTRexPktBuilder(pkt = Ether()/IP()) + base_pkt = STLPktBuilder(pkt = Ether()/IP()) # send something initial to calm down switches with arps etc. stream = STLStream(packet = base_pkt, diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py index 2a99be8d..939c8ed5 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py @@ -3,7 +3,7 @@ from trex_stl_exceptions import * from trex_stl_types import verify_exclusive_arg, validate_type from trex_stl_packet_builder_interface import CTrexPktBuilderInterface -from trex_stl_packet_builder_scapy import CScapyTRexPktBuilder, Ether, IP, UDP, TCP, RawPcapReader +from trex_stl_packet_builder_scapy import STLPktBuilder, Ether, IP, UDP, TCP, RawPcapReader from collections import OrderedDict, namedtuple from scapy.utils import ltoa @@ -200,6 +200,14 @@ STLStreamDstMAC_ARP =2 # RX stats class class STLFlowStats(object): + """ Define per stream stats + + For example:: + + flow_stats = STLFlowStats(pg_id = 7) + + """ + def __init__ (self, pg_id): self.fields = {} @@ -210,6 +218,7 @@ class STLFlowStats(object): def to_json (self): + """ dump as json""" return dict(self.fields) @staticmethod @@ -220,6 +229,7 @@ class STLStream(object): """ One stream object, include mode, Field Engine mode packet template and Rx stats For example:: + base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) pad = max(0, size - len(base_pkt)) * 'x' @@ -229,6 +239,7 @@ class STLStream(object): mode = STLTXSingleBurst( pps = 10, total_pkts = 1), next = 'S1'), # point to next stream + """ def __init__ (self, @@ -257,7 +268,7 @@ class STLStream(object): packet : STLPktBuilder The template packet and field engine program e.g. packet = STLPktBuilder(pkt = base_pkt/pad) - mode : STLTXCont or STLTXSingleBurst or STLTXMultiBurst + mode : :class:`trex_stl_lib.trex_stl_streams.STLTXCont` or :class:`trex_stl_lib.trex_stl_streams.STLTXSingleBurst` or :class:`trex_stl_lib.trex_stl_streams.STLTXMultiBurst` enabled : bool if the stream is enabled. @@ -268,7 +279,7 @@ class STLStream(object): isg : float Inter stream gap in usec. time to wait until stream will send the first packet - flow_stats : STLFlowStats + flow_stats : :class:`trex_stl_lib.trex_stl_streams.STLFlowStats` Per stream statistic object see STLFlowStats next : string @@ -288,14 +299,6 @@ class STLStream(object): mac_dst_override_mode=None : STLStreamDstMAC_xx Template packet will set dst MAC - - - :return: - None - - :raises: - None - """ @@ -366,7 +369,7 @@ class STLStream(object): self.fields['vm'] = {} if not packet: - packet = CScapyTRexPktBuilder(pkt = Ether()/IP()) + packet = STLPktBuilder(pkt = Ether()/IP()) self.scapy_pkt_builder = packet # packet builder @@ -429,7 +432,7 @@ class STLStream(object): def get_pkt_type (self): """ Get packet description for example IP:UDP """ if self.packet_desc == None: - self.packet_desc = CScapyTRexPktBuilder.pkt_layers_desc_from_buffer(self.get_pkt()) + self.packet_desc = STLPktBuilder.pkt_layers_desc_from_buffer(self.get_pkt()) return self.packet_desc @@ -459,7 +462,7 @@ class STLStream(object): if self.name: print "Stream Name: ",self.name scapy_b = self.scapy_pkt_builder; - if scapy_b and isinstance(scapy_b,CScapyTRexPktBuilder): + if scapy_b and isinstance(scapy_b,STLPktBuilder): scapy_b.to_pkt_dump() else: print "Nothing to dump" @@ -517,25 +520,25 @@ class STLStream(object): vm_list = [] for inst in self.fields['vm']['instructions']: if inst['type'] == 'flow_var': - vm_list.append("CTRexVmDescFlowVar(name='{name}', size={size}, op='{op}', init_value={init_value}, min_value={min_value}, max_value={max_value}, step={step})".format(**inst)) + vm_list.append("STLVmFlowVar(name='{name}', size={size}, op='{op}', init_value={init_value}, min_value={min_value}, max_value={max_value}, step={step})".format(**inst)) elif inst['type'] == 'write_flow_var': - vm_list.append("CTRexVmDescWrFlowVar(fv_name='{name}', pkt_offset={pkt_offset}, add_val={add_value}, is_big={is_big_endian})".format(**inst)) + vm_list.append("STLVmWrFlowVar(fv_name='{name}', pkt_offset={pkt_offset}, add_val={add_value}, is_big={is_big_endian})".format(**inst)) elif inst['type'] == 'write_mask_flow_var': inst = copy.copy(inst) inst['mask'] = hex(inst['mask']) - vm_list.append("CTRexVmDescWrMaskFlowVar(fv_name='{name}', pkt_offset={pkt_offset}, pkt_cast_size={pkt_cast_size}, mask={mask}, shift={shift}, add_value={add_value}, is_big={is_big_endian})".format(**inst)) + vm_list.append("STLVmWrMaskFlowVar(fv_name='{name}', pkt_offset={pkt_offset}, pkt_cast_size={pkt_cast_size}, mask={mask}, shift={shift}, add_value={add_value}, is_big={is_big_endian})".format(**inst)) elif inst['type'] == 'fix_checksum_ipv4': - vm_list.append("CTRexVmDescFixIpv4(offset={pkt_offset})".format(**inst)) + vm_list.append("STLVmFixIpv4(offset={pkt_offset})".format(**inst)) elif inst['type'] == 'trim_pkt_size': - vm_list.append("CTRexVmDescTrimPktSize(fv_name='{name}')".format(**inst)) + vm_list.append("STLVmTrimPktSize(fv_name='{name}')".format(**inst)) elif inst['type'] == 'tuple_flow_var': inst = copy.copy(inst) inst['ip_min'] = ltoa(inst['ip_min']) inst['ip_max'] = ltoa(inst['ip_max']) - vm_list.append("CTRexVmDescTupleGen(name='{name}', ip_min='{ip_min}', ip_max='{ip_max}', port_min={port_min}, port_max={port_max}, limit_flows={limit_flows}, flags={flags})".format(**inst)) - vm_code = 'vm = CTRexScRaw([' + ',\n '.join(vm_list) + '], split_by_field = %s)' % STLStream.__add_quotes(self.fields['vm'].get('split_by_var')) + vm_list.append("STLVmTupleGen(name='{name}', ip_min='{ip_min}', ip_max='{ip_max}', port_min={port_min}, port_max={port_max}, limit_flows={limit_flows}, flags={flags})".format(**inst)) + vm_code = 'vm = STLScVmRaw([' + ',\n '.join(vm_list) + '], split_by_field = %s)' % STLStream.__add_quotes(self.fields['vm'].get('split_by_var')) stream_params_list = [] - stream_params_list.append('packet = CScapyTRexPktBuilder(pkt = packet, vm = vm)') + stream_params_list.append('packet = STLPktBuilder(pkt = packet, vm = vm)') if default_STLStream.name != self.name: stream_params_list.append('name = %s' % STLStream.__add_quotes(self.name)) if default_STLStream.fields['enabled'] != self.fields['enabled']: @@ -618,7 +621,7 @@ class YAMLLoader(object): except TypeError: raise STLError("'binary' field is not a valid packet format") - builder = CScapyTRexPktBuilder(pkt_buffer = pkt_str) + builder = STLPktBuilder(pkt_buffer = pkt_str) elif 'pcap' in packet_type: pcap = os.path.join(self.yaml_path, packet_dict['pcap']) @@ -626,7 +629,7 @@ class YAMLLoader(object): if not os.path.exists(pcap): raise STLError("'pcap' - cannot find '{0}'".format(pcap)) - builder = CScapyTRexPktBuilder(pkt = pcap) + builder = STLPktBuilder(pkt = pcap) return builder @@ -769,7 +772,7 @@ class STLProfile(object): :parameters: - streams : list of STLStream + streams : list of :class:`trex_stl_lib.trex_stl_streams.STLStream` a list of stream objects @@ -901,7 +904,7 @@ class STLProfile(object): streams.append(STLStream(name = i, - packet = CScapyTRexPktBuilder(pkt_buffer = cap, vm = vm), + packet = STLPktBuilder(pkt_buffer = cap, vm = vm), mode = STLTXSingleBurst(total_pkts = 1, percentage = 100), self_start = True if (i == 1) else False, isg = (ts_usec - last_ts_usec), # seconds to usec |