summaryrefslogtreecommitdiffstats
path: root/scripts/api/stl/examples/stl_simple_burst.py
blob: 0de4df899f1e381e1f94416ad8e90a342e196f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
sys.path.insert(0, "../")

from trex_stl_api import *
from scapy.all import *
import time

def simple_burst ():
        

    # create client
    c = STLClient()
    passed = True
    
    try:

        pkt = STLPktBuilder(pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/IP()/'a_payload_example')

        # 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())


        # connect to server
        c.connect()

        # prepare our ports
        c.reset(ports = [0, 3])

        # add both streams to ports
        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, 3], mult = "1gbps")
            c.wait_on_traffic(ports = [0, 3])

            stats = c.get_stats()
            ipackets  = stats['total']['ipackets']

            print "Test iteration {0} - Packets Received: {1} ".format(i, ipackets)
            # (5000 + 3000) * 2 ports = 16,000
            if (ipackets != (16000)):
                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
simple_burst()