diff options
Diffstat (limited to 'scripts/api/stl/examples')
-rw-r--r-- | scripts/api/stl/examples/stl_bi_dir_flows.py | 77 | ||||
-rw-r--r-- | scripts/api/stl/examples/stl_simple_burst.py | 52 |
2 files changed, 50 insertions, 79 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..b7967066 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_val=src['start'],max_val=src['end'],size=4,op="inc"), + STLVmWriteFlowVar(fv_name="src",pkt_offset= "IP.src"), + + # dst + STLVmFlowVar(name="dst",min_val=dst['start'],max_val=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_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'] |