diff options
author | 2016-02-03 09:21:10 -0500 | |
---|---|---|
committer | 2016-02-03 14:07:14 -0500 | |
commit | 2887433cb71f43c9bf91226915959f5ebea49869 (patch) | |
tree | 70c9e62a9e64a26d71f7dcfabb04e5f22993d353 /scripts/api/stl/examples/stl_simple_burst.py | |
parent | 7447c92021d7ce3fc0fe115109b54a2f681f2392 (diff) |
integration with scapy
Diffstat (limited to 'scripts/api/stl/examples/stl_simple_burst.py')
-rw-r--r-- | scripts/api/stl/examples/stl_simple_burst.py | 52 |
1 files changed, 14 insertions, 38 deletions
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'] |