1import stl_path
2from trex_stl_lib.api import *
3
4import time
5
6def simple ():
7
8    # create client
9    #verbose_level = LoggerApi.VERBOSE_HIGH
10    c = STLClient(verbose_level = LoggerApi.VERBOSE_REGULAR)
11    passed = True
12
13    try:
14        # connect to server
15        c.connect()
16
17        my_ports=[0,1]
18
19        # prepare our ports
20        c.reset(ports = my_ports)
21        profile_file = os.path.join(stl_path.STL_PROFILES_PATH, 'hlt', 'udp_1pkt_simple.py')
22
23        try:
24            profile = STLProfile.load(profile_file)
25        except STLError as e:
26            print(format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold'))
27            print(e.brief() + "\n")
28            return
29
30        print(profile.dump_to_yaml())
31
32        c.remove_all_streams(my_ports)
33
34
35        c.add_streams(profile.get_streams(), ports = my_ports)
36
37        c.start(ports = [0, 1], mult = "5mpps", duration = 10)
38
39        # block until done
40        c.wait_on_traffic(ports = [0, 1])
41
42
43    except STLError as e:
44        passed = False
45        print(e)
46
47    finally:
48        c.disconnect()
49
50    if passed:
51        print("\nTest has passed :-)\n")
52    else:
53        print("\nTest has failed :-(\n")
54
55
56# run the tests
57simple()
58
59