diff options
author | 2016-02-04 10:31:04 +0200 | |
---|---|---|
committer | 2016-02-04 10:31:04 +0200 | |
commit | eaa1928aebec0d8069a1466e2c421d3dfb5b16f0 (patch) | |
tree | 7ba4f23c5308aad0102b1d6e106f2390bc1a19f8 /scripts | |
parent | d95c37b1d2b3c9d7c2e1942b4b8ee18f22464f72 (diff) | |
parent | 51f3f97dfcd156b79b10331312d238775443e23c (diff) |
Merge simulation fix
Diffstat (limited to 'scripts')
13 files changed, 374 insertions, 160 deletions
diff --git a/scripts/api/stl/examples/stl_bi_dir_flows.py b/scripts/api/stl/examples/stl_bi_dir_flows.py index 38cb36dd..7d090345 100644 --- a/scripts/api/stl/examples/stl_bi_dir_flows.py +++ b/scripts/api/stl/examples/stl_bi_dir_flows.py @@ -4,51 +4,46 @@ sys.path.insert(0, "../") from trex_stl_api import * -import dpkt import time import json +# simple packet creation +def create_pkt (size, direction): -def simple_burst (): - - # build A side packet - pkt_a = STLPktBuilder() - - pkt_a.add_pkt_layer("l2", dpkt.ethernet.Ethernet()) - pkt_a.add_pkt_layer("l3_ip", dpkt.ip.IP()) - pkt_a.add_pkt_layer("l4_udp", dpkt.udp.UDP()) - pkt_a.set_pkt_payload("somepayload") - pkt_a.set_layer_attr("l3_ip", "len", len(pkt_a.get_layer('l3_ip'))) - - # build B side packet - pkt_b = pkt_a.clone() - - # set IP range for pkt and split it by multiple cores - pkt_a.set_vm_ip_range(ip_layer_name = "l3_ip", - ip_field = "src", - ip_start="10.0.0.1", ip_end="10.0.0.254", - operation = "inc", - split = True) - - pkt_a.set_vm_ip_range(ip_layer_name = "l3_ip", - ip_field = "dst", - ip_start="8.0.0.1", ip_end="8.0.0.254", - operation = "inc") - - - # build B side packet - pkt_b.set_vm_ip_range(ip_layer_name = "l3_ip", - ip_field = "src", - ip_start="8.0.0.1", ip_end="8.0.0.254", - operation = "inc", - split = True) - - pkt_b.set_vm_ip_range(ip_layer_name = "l3_ip", - ip_field = "dst", - ip_start="10.0.0.1", ip_end="10.0.0.254", - operation = "inc") + ip_range = {'src': {'start': "10.0.0.1", 'end': "10.0.0.254"}, + 'dst': {'start': "8.0.0.1", 'end': "8.0.0.254"}} + + if (direction == 0): + src = ip_range['src'] + dst = ip_range['dst'] + else: + src = ip_range['dst'] + dst = ip_range['src'] + + vm = [ + # src + STLVmFlowVar(name="src",min_value=src['start'],max_value=src['end'],size=4,op="inc"), + STLVmWriteFlowVar(fv_name="src",pkt_offset= "IP.src"), + + # dst + STLVmFlowVar(name="dst",min_value=dst['start'],max_value=dst['end'],size=4,op="inc"), + STLVmWriteFlowVar(fv_name="dst",pkt_offset= "IP.dst"), + + # checksum + STLVmFixIpv4(offset = "IP") + ] + + base = Ether()/IP()/UDP() + pad = max(0, len(base)) * 'x' + + return STLPktBuilder(pkt = base/pad, + vm = vm) + + +def simple_burst (): + # create client c = STLClient() passed = True @@ -58,11 +53,11 @@ def simple_burst (): #c.set_verbose("high") # create two streams - s1 = STLStream(packet = pkt_a, + s1 = STLStream(packet = create_pkt(200, 0), mode = STLTXCont(pps = 100)) # second stream with a phase of 1ms (inter stream gap) - s2 = STLStream(packet = pkt_b, + s2 = STLStream(packet = create_pkt(200, 1), isg = 1000, mode = STLTXCont(pps = 100)) diff --git a/scripts/api/stl/examples/stl_imix.py b/scripts/api/stl/examples/stl_imix.py new file mode 100644 index 00000000..01eec9b4 --- /dev/null +++ b/scripts/api/stl/examples/stl_imix.py @@ -0,0 +1,106 @@ +# include the path of trex_stl_api.py +import sys +sys.path.insert(0, "../") + +from trex_stl_api import * +from trex_stl_lib import * +from profiles.imix import STLImix + +import time +import json +from pprint import pprint + +# IMIX test +# it maps the ports to sides +# then it load a predefind profile 'IMIX' +# and attach it to both sides and inject +# at a certain rate for some time +# finally it checks that all packets arrived +def imix_test (): + + + # create client + c = STLClient() + passed = True + + + try: + + # base profile - imix + profile = STLImix() + + # connect to server + c.connect() + + # take all the ports + c.reset() + + # map ports - identify the routes + table = stl_map_ports(c) + + print "Mapped ports to sides {0} <--> {1}".format(table['dir'][0], table['dir'][1]) + dir_0 = table['dir'][0] + dir_1 = table['dir'][1] + + # add both streams to ports + c.add_streams(profile.get_streams(direction = 0), ports = dir_0) + c.add_streams(profile.get_streams(direction = 1), ports = dir_1) + + # clear the stats before injecting + c.clear_stats() + + # choose rate and start traffic for 10 seconds on 5 mpps + duration = 10 + mult = "5mpps" + print "Injecting {0} <--> {1} on total rate of '{2}' for {3} seconds".format(dir_0, dir_1, mult, duration) + + c.start(ports = (dir_0 + dir_1), mult = mult, duration = duration, total = True) + + # block until done + c.wait_on_traffic(ports = (dir_0 + dir_1)) + + # read the stats after the test + stats = c.get_stats() + + # use this for debug info on all the stats + #pprint(stats) + + # sum dir 0 + dir_0_opackets = sum([stats[i]["opackets"] for i in dir_0]) + dir_0_ipackets = sum([stats[i]["ipackets"] for i in dir_0]) + + # sum dir 1 + dir_1_opackets = sum([stats[i]["opackets"] for i in dir_1]) + dir_1_ipackets = sum([stats[i]["ipackets"] for i in dir_1]) + + + lost_0 = dir_0_opackets - dir_1_ipackets + lost_1 = dir_1_opackets - dir_0_ipackets + + print "\nPackets injected from {0}: {1:,}".format(dir_0, dir_0_opackets) + print "Packets injected from {0}: {1:,}".format(dir_1, dir_1_opackets) + + print "\npackets lost from {0} --> {1}: {2:,} pkts".format(dir_0, dir_0, lost_0) + print "packets lost from {0} --> {1}: {2:,} pkts".format(dir_0, dir_0, lost_0) + + if (lost_0 == 0) and (lost_0 == 0): + passed = True + else: + passed = False + + except STLError as e: + passed = False + print e + + finally: + c.disconnect() + + if passed: + print "\nTest has passed :-)\n" + else: + print "\nTest has failed :-(\n" + + +# run the tests +imix_test() + diff --git a/scripts/api/stl/examples/stl_simple_burst.py b/scripts/api/stl/examples/stl_simple_burst.py index 2ca71b44..0de4df89 100644 --- a/scripts/api/stl/examples/stl_simple_burst.py +++ b/scripts/api/stl/examples/stl_simple_burst.py @@ -2,49 +2,25 @@ import sys sys.path.insert(0, "../") from trex_stl_api import * -import dpkt +from scapy.all import * import time def simple_burst (): - - # build a simple packet - - pkt_bld = STLPktBuilder() - pkt_bld.add_pkt_layer("l2", dpkt.ethernet.Ethernet()) - # set Ethernet layer attributes - pkt_bld.set_eth_layer_addr("l2", "src", "00:15:17:a7:75:a3") - pkt_bld.set_eth_layer_addr("l2", "dst", "e0:5f:b9:69:e9:22") - pkt_bld.set_layer_attr("l2", "type", dpkt.ethernet.ETH_TYPE_IP) - # set IP layer attributes - pkt_bld.add_pkt_layer("l3_ip", dpkt.ip.IP()) - pkt_bld.set_ip_layer_addr("l3_ip", "src", "21.0.0.2") - pkt_bld.set_ip_layer_addr("l3_ip", "dst", "22.0.0.12") - pkt_bld.set_layer_attr("l3_ip", "p", dpkt.ip.IP_PROTO_TCP) - # set TCP layer attributes - pkt_bld.add_pkt_layer("l4_tcp", dpkt.tcp.TCP()) - pkt_bld.set_layer_attr("l4_tcp", "sport", 13311) - pkt_bld.set_layer_attr("l4_tcp", "dport", 80) - pkt_bld.set_layer_attr("l4_tcp", "flags", 0) - pkt_bld.set_layer_attr("l4_tcp", "win", 32768) - pkt_bld.set_layer_attr("l4_tcp", "seq", 0) - #pkt_bld.set_pkt_payload("abcdefgh") - pkt_bld.set_layer_attr("l3_ip", "len", len(pkt_bld.get_layer('l3_ip'))) - - + + # create client c = STLClient() passed = True - + try: - - #c.set_verbose("high") - # create two bursts and link them - s1 = STLStream(packet = pkt_bld, - mode = STLTXSingleBurst(total_pkts = 5000) - ) + pkt = STLPktBuilder(pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/IP()/'a_payload_example') - s2 = STLStream(packet = pkt_bld, + # create two bursts and link them + s1 = STLStream(packet = pkt, + mode = STLTXSingleBurst(total_pkts = 5000)) + + s2 = STLStream(packet = pkt, mode = STLTXSingleBurst(total_pkts = 3000), next_stream_id = s1.get_id()) @@ -53,16 +29,16 @@ def simple_burst (): c.connect() # prepare our ports - c.reset(ports = [0, 1]) + c.reset(ports = [0, 3]) # add both streams to ports - stream_ids = c.add_streams([s1, s2], ports = [0, 1]) + stream_ids = c.add_streams([s1, s2], ports = [0, 3]) # run 5 times for i in xrange(1, 6): c.clear_stats() - c.start(ports = [0, 1], mult = "1gbps") - c.wait_on_traffic(ports = [0, 1]) + c.start(ports = [0, 3], mult = "1gbps") + c.wait_on_traffic(ports = [0, 3]) stats = c.get_stats() ipackets = stats['total']['ipackets'] diff --git a/scripts/api/stl/trex_stl_api.py b/scripts/api/stl/trex_stl_api.py index 0bfd1181..3ef7eaaa 100644 --- a/scripts/api/stl/trex_stl_api.py +++ b/scripts/api/stl/trex_stl_api.py @@ -1,7 +1,8 @@ import os import sys import time - +import json +import math # update the import path to include the stateless client root_path = os.path.dirname(os.path.abspath(__file__)) @@ -11,7 +12,7 @@ sys.path.insert(0, os.path.join(root_path, '../../stl/')) # aliasing import common.trex_streams -from client_utils.packet_builder import CTRexPktBuilder +from client_utils.scapy_packet_builder import * import common.trex_stl_exceptions import client.trex_stateless_client import client.trex_stateless_sim @@ -27,7 +28,12 @@ STLTXSingleBurst = common.trex_streams.STLTXSingleBurst STLTXMultiBurst = common.trex_streams.STLTXMultiBurst # packet builder -STLPktBuilder = CTRexPktBuilder +STLPktBuilder = CScapyTRexPktBuilder + +# VM +STLVmFlowVar = CTRexVmDescFlowVar +STLVmWriteFlowVar = CTRexVmDescWrFlowVar +STLVmFixIpv4 = CTRexVmDescFixIpv4 # simulator STLSim = client.trex_stateless_sim.STLSim diff --git a/scripts/api/stl/trex_stl_lib.py b/scripts/api/stl/trex_stl_lib.py new file mode 100644 index 00000000..a8574e82 --- /dev/null +++ b/scripts/api/stl/trex_stl_lib.py @@ -0,0 +1,71 @@ + +from trex_stl_api import * +from scapy.all import * + +# stl library for various utilities + + +# map ports +# will destroy all streams/data on the ports +def stl_map_ports (client, ports = None): + + # by default use all ports + if ports == None: + ports = client.get_all_ports() + + # reset the ports + client.reset(ports) + + # generate streams + base_pkt = STLPktBuilder(pkt = Ether()/IP()) + + pkts = 1 + for port in ports: + stream = STLStream(packet = base_pkt, + mode = STLTXSingleBurst(pps = 100000, total_pkts = pkts)) + + client.add_streams(stream, [port]) + pkts = pkts * 2 + + # inject + client.clear_stats() + client.start(ports, mult = "1mpps") + client.wait_on_traffic(ports) + + stats = client.get_stats() + + # cleanup + client.reset(ports = ports) + + table = {} + for port in ports: + table[port] = None + + for port in ports: + ipackets = stats[port]["ipackets"] + + exp = 1 + while ipackets >= exp: + if ((ipackets & exp) == (exp)): + source = int(math.log(exp, 2)) + table[source] = port + + exp *= 2 + + if not all(x != None for x in table.values()): + raise STLError('unable to map ports') + + dir_a = set() + dir_b = set() + for src, dst in table.iteritems(): + # src is not in + if src not in (dir_a, dir_b): + if dst in dir_a: + dir_b.add(src) + else: + dir_a.add(src) + + table['dir'] = [list(dir_a), list(dir_b)] + + return table + diff --git a/scripts/automation/regression/aggregate_results.py b/scripts/automation/regression/aggregate_results.py index 2a21b4be..8a3d0e4c 100755 --- a/scripts/automation/regression/aggregate_results.py +++ b/scripts/automation/regression/aggregate_results.py @@ -17,11 +17,10 @@ ERROR_CATEGORY = 'Error' def pad_tag(text, tag): return '<%s>%s</%s>' % (tag, text, tag) -def add_color_string(text, color, is_bold = False): - string = '<font color=%s>%s</font>' % (color, text) - if is_bold: - return pad_tag(string, 'b') - return string +def mark_string(text, color, condition): + if condition: + return '<font color=%s><b>%s</b></font>' % (color, text) + return text def is_functional_test_name(testname): @@ -328,11 +327,12 @@ if __name__ == '__main__': failure_tests_count = int(aggregated_root.attrib.get('failures', 0)) skipped_tests_count = int(aggregated_root.attrib.get('skip', 0)) passed_tests_count = total_tests_count - error_tests_count - failure_tests_count - skipped_tests_count - tests_count_string = 'Total: %s, ' % total_tests_count - tests_count_string += add_color_string('Passed: %s' % passed_tests_count, 'green', error_tests_count + failure_tests_count > 0) + ', ' - tests_count_string += add_color_string('Error: %s' % error_tests_count, 'red', error_tests_count > 0) + ', ' - tests_count_string += add_color_string('Failure: %s' % failure_tests_count, 'red', failure_tests_count > 0) + ', ' - tests_count_string += add_color_string('Skipped: %s' % skipped_tests_count, 'blue') + + tests_count_string = mark_string('Total: %s' % total_tests_count, 'red', total_tests_count == 0) + ', ' + tests_count_string += mark_string('Passed: %s' % passed_tests_count, 'red', error_tests_count + failure_tests_count > 0) + ', ' + tests_count_string += mark_string('Error: %s' % error_tests_count, 'red', error_tests_count > 0) + ', ' + tests_count_string += mark_string('Failure: %s' % failure_tests_count, 'red', failure_tests_count > 0) + ', ' + tests_count_string += 'Skipped: %s' % skipped_tests_count ##### save output xml diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py index 506decfe..ebc9a6ad 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -929,7 +929,7 @@ class STLClient(object): def get_stats (self, ports = None, async_barrier = True): # by default use all ports if ports == None: - ports = self.get_all_ports() + ports = self.get_acquired_ports() else: ports = self.__ports(ports) @@ -1306,7 +1306,6 @@ class STLClient(object): try: streams_db = CStreamsDB() stream_list = streams_db.load_yaml_file(filename) - # convert to new style stream object streams = [HACKSTLStream(stream) for stream in stream_list.compiled] except YAMLError: diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_sim.py b/scripts/automation/trex_control_plane/client/trex_stateless_sim.py index bfc3a932..d980932a 100644 --- a/scripts/automation/trex_control_plane/client/trex_stateless_sim.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_sim.py @@ -116,8 +116,8 @@ class STLSim(object): return module.register().get_streams() - except (AttributeError, ImportError): - pass + except (AttributeError, ImportError) as e: + print "specific error: {0}".format(e) raise STLError("bad format input file '{0}'".format(input_file)) diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder.py b/scripts/automation/trex_control_plane/client_utils/packet_builder.py index 5ad6cd7a..f9031436 100755 --- a/scripts/automation/trex_control_plane/client_utils/packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder.py @@ -14,7 +14,9 @@ from abc import ABCMeta, abstractmethod from collections import namedtuple import base64 -class CTRexPktBuilder(object): +from packet_builder_interface import CTrexPktBuilderInterface + +class CTRexPktBuilder(CTrexPktBuilderInterface): """ This class defines the TRex API of building a packet using dpkt package. Using this class the user can also define how TRex will handle the packet by specifying the VM setting. @@ -480,6 +482,9 @@ class CTRexPktBuilder(object): def get_vm_data(self): return self.vm.dump() + def compile (self): + pass + def dump_pkt(self, encode = True): """ Dumps the packet as a decimal array of bytes (each item x gets value between 0-255) diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder_interface.py b/scripts/automation/trex_control_plane/client_utils/packet_builder_interface.py new file mode 100644 index 00000000..b6e7c026 --- /dev/null +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder_interface.py @@ -0,0 +1,43 @@ + +# base object class for a packet builder +class CTrexPktBuilderInterface(object): + + def compile (self): + """ + Compiles the packet and VM + """ + raise Exception("implement me") + + + def dump_pkt(self): + """ + Dumps the packet as a decimal array of bytes (each item x gets value between 0-255) + + :parameters: + None + + :return: + + packet representation as array of bytes + + :raises: + + :exc:`CTRexPktBuilder.EmptyPacketError`, in case packet is empty. + + """ + + raise Exception("implement me") + + + def get_vm_data(self): + """ + Dumps the instructions + + :parameters: + None + + :return: + + json object of instructions + + """ + + raise Exception("implement me") + diff --git a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py index d3a5605b..30383469 100644 --- a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py @@ -8,6 +8,7 @@ import yaml import binascii import base64 +from packet_builder_interface import CTrexPktBuilderInterface from scapy.all import * @@ -482,7 +483,7 @@ def check_for_int (val): class CTRexVmDescFlowVar(CTRexVmDescBase): - def __init__(self, name, init_value=0, min_value=0, max_value=255, size=4, op="inc"): + def __init__(self, name, init_value=None, min_value=0, max_value=255, size=4, op="inc"): super(CTRexVmDescFlowVar, self).__init__() self.name = name; assert type(name)==str, 'type of name is not str' @@ -490,6 +491,11 @@ class CTRexVmDescFlowVar(CTRexVmDescBase): valid_fv_size(size) self.op =op valid_fv_ops (op) + + # choose default value for init val + if init_value == None: + init_value = max_value if op == "dec" else min_value + self.init_value = convert_val (init_value) self.min_value = convert_val (min_value); self.max_value = convert_val (max_value) @@ -581,13 +587,13 @@ class CTRexVmDescTupleGen(CTRexVmDescBase): ################################################################################################ -class CScapyTRexPktBuilder(object): +class CScapyTRexPktBuilder(CTrexPktBuilderInterface): """ This class defines the TRex API of building a packet using dpkt package. Using this class the user can also define how TRex will handle the packet by specifying the VM setting. """ - def __init__(self): + def __init__(self, pkt = None, vm = None): """ Instantiate a CTRexPktBuilder object @@ -596,11 +602,27 @@ class CScapyTRexPktBuilder(object): """ super(CScapyTRexPktBuilder, self).__init__() - self.pkt = None # scapy packet + + self.pkt = None self.vm_scripts = [] # list of high level instructions self.vm_low_level = None self.metadata="" + + # process packet + if pkt != None: + if not isinstance(pkt, Packet): + raise CTRexPacketBuildException(-14, "bad value for variable pkt") + self.set_packet(pkt) + + # process VM + if vm != None: + if not isinstance(vm, (CTRexScRaw, list)): + raise CTRexPacketBuildException(-14, "bad value for variable pkt") + + self.add_command(vm if isinstance(vm, CTRexScRaw) else CTRexScRaw(vm)) + + def dump_vm_data_as_yaml(self): print yaml.dump(self.get_vm_data(), default_flow_style=False) @@ -689,7 +711,6 @@ class CScapyTRexPktBuilder(object): var_names = desc.get_var_name() if var_names : - print var_names for var_name in var_names: if vars.has_key(var_name): raise CTRexPacketBuildException(-11,("variable %s define twice ") % (var_name) ); diff --git a/scripts/automation/trex_control_plane/common/trex_streams.py b/scripts/automation/trex_control_plane/common/trex_streams.py index 9b10995b..238c89f3 100755 --- a/scripts/automation/trex_control_plane/common/trex_streams.py +++ b/scripts/automation/trex_control_plane/common/trex_streams.py @@ -1,6 +1,7 @@ #!/router/bin/python import external_packages +from client_utils.packet_builder_interface import CTrexPktBuilderInterface from client_utils.packet_builder import CTRexPktBuilder from collections import OrderedDict, namedtuple from client_utils.yaml_utils import * @@ -422,7 +423,7 @@ class STLStream(object): if not isinstance(mode, STLTXMode): raise STLArgumentError('mode', mode) - if not isinstance(packet, CTRexPktBuilder): + if not isinstance(packet, CTrexPktBuilderInterface): raise STLArgumentError('packet', packet) if not isinstance(enabled, bool): @@ -452,6 +453,8 @@ class STLStream(object): # mode self.fields['mode'] = mode.to_json() + packet.compile() + # packet and VM self.fields['packet'] = packet.dump_pkt() self.fields['vm'] = packet.get_vm_data() diff --git a/scripts/stl/profiles/imix.py b/scripts/stl/profiles/imix.py index c0305cc3..c453222d 100644 --- a/scripts/stl/profiles/imix.py +++ b/scripts/stl/profiles/imix.py @@ -1,87 +1,76 @@ +import sys +import os -from common.trex_streams import * -from client_utils.packet_builder import CTRexPktBuilder +# we need the API path +CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) +API_PATH = os.path.join(CURRENT_PATH, "../../api/stl") +sys.path.insert(0, API_PATH) +from trex_stl_api import * +from scapy.all import * +# IMIX profile - involves 3 streams of UDP packets +# 1 - 60 bytes +# 2 - 590 bytes +# 3 - 1514 bytes class STLImix(object): def __init__ (self): - ip_range = {'src' : {}, 'dst': {}} + # default IP range + self.ip_range = {'src': {'start': "10.0.0.1", 'end': "10.0.0.254"}, + 'dst': {'start': "8.0.0.1", 'end': "8.0.0.254"}} - ip_range['src']['start'] = "10.0.0.1" - ip_range['src']['end'] = "10.0.0.254" - ip_range['dst']['start'] = "8.0.0.1" - ip_range['dst']['end'] = "8.0.0.254" + # default IMIX properties + self.imix_table = [ {'size': 60, 'pps': 28}, + {'size': 590, 'pps': 20}, + {'size': 1514, 'pps': 4}] - self.ip_range = ip_range - def get_streams (self, flip = False): + def create_stream (self, size, pps, vm): + # create a base packet and pad it to size + base_pkt = Ether()/IP()/UDP() + pad = max(0, size - len(base_pkt)) * 'x' - # construct the base packet for the profile - base_pkt = CTRexPktBuilder() + pkt = STLPktBuilder(pkt = base_pkt/pad, + vm = vm) + + return STLStream(packet = pkt, + mode = STLTXCont()) - base_pkt.add_pkt_layer("l2", dpkt.ethernet.Ethernet()) - base_pkt.set_layer_attr("l2", "type", dpkt.ethernet.ETH_TYPE_IP) - base_pkt.add_pkt_layer("l3_ip", dpkt.ip.IP()) - base_pkt.add_pkt_layer("l4_udp", dpkt.udp.UDP()) + def get_streams (self, direction = 0): - if not flip: + if direction == 0: src = self.ip_range['src'] dst = self.ip_range['dst'] else: src = self.ip_range['dst'] dst = self.ip_range['src'] - base_pkt.set_vm_ip_range(ip_layer_name = "l3_ip", - ip_field = "src", - ip_start = src['start'], - ip_end = src['end'], - operation = "inc", - split = True) - - base_pkt.set_vm_ip_range(ip_layer_name = "l3_ip", - ip_field = "dst", - ip_start = dst['start'], - ip_end = dst['end'], - operation = "inc") - - - - # pad to 60 bytes - pkt_1 = base_pkt.clone() - payload_size = 60 - len(pkt_1.get_layer('l2')) - pkt_1.set_pkt_payload("a" * payload_size) - - pkt_1.set_layer_attr("l3_ip", "len", len(pkt_1.get_layer('l3_ip'))) + # construct the base packet for the profile + vm =[ + # src + STLVmFlowVar(name="src",min_value=src['start'],max_value=src['end'],size=4,op="inc"), + STLVmWriteFlowVar(fv_name="src",pkt_offset= "IP.src"), - s1 = STLStream(packet = pkt_1, - mode = STLTXCont()) + # dst + STLVmFlowVar(name="dst",min_value=dst['start'],max_value=dst['end'],size=4,op="inc"), + STLVmWriteFlowVar(fv_name="dst",pkt_offset= "IP.dst"), - # stream 2 - pkt_2 = base_pkt.clone() - payload_size = 590 - len(pkt_2.get_layer('l2')) - pkt_2.set_pkt_payload("a" * payload_size) + # checksum + STLVmFixIpv4(offset = "IP") - pkt_2.set_layer_attr("l3_ip", "len", len(pkt_2.get_layer('l3_ip'))) + ] - s2 = STLStream(packet = pkt_2, - mode = STLTXCont()) + # create imix streams + return [self.create_stream(x['size'], x['pps'], vm) for x in self.imix_table] - # stream 3 - pkt_3 = base_pkt.clone() - payload_size = 1514 - len(pkt_3.get_layer('l2')) - pkt_3.set_pkt_payload("a" * payload_size) - pkt_3.set_layer_attr("l3_ip", "len", len(pkt_3.get_layer('l3_ip'))) +# dynamic load - used for trex console or simulator +def register(): + return STLImix() - s3 = STLStream(packet = pkt_3, - mode = STLTXCont()) - return [s1, s2, s3] -# dynamic load -def register(): - return STLImix() |