diff options
author | 2016-02-08 06:08:14 -0500 | |
---|---|---|
committer | 2016-02-08 06:08:14 -0500 | |
commit | 995267db77f5554d5228697b8b2a862b51859fe6 (patch) | |
tree | 1a44007a59d8cabacab0690da515a68c3c25e7ac /scripts/api/stl | |
parent | 69e5a5c6b94175ece07b247af1b5ca6c0cfdf0e9 (diff) |
first refactor
Diffstat (limited to 'scripts/api/stl')
-rw-r--r-- | scripts/api/stl/examples/stl_bi_dir_flows.py | 7 | ||||
-rw-r--r-- | scripts/api/stl/examples/stl_imix.py | 19 | ||||
-rw-r--r-- | scripts/api/stl/examples/stl_path.py | 2 | ||||
-rw-r--r-- | scripts/api/stl/examples/stl_run_udp_simple.py | 5 | ||||
-rw-r--r-- | scripts/api/stl/examples/stl_simple_burst.py | 13 | ||||
-rw-r--r-- | scripts/api/stl/trex_stl_api.py | 44 | ||||
-rw-r--r-- | scripts/api/stl/trex_stl_lib.py | 71 |
7 files changed, 20 insertions, 141 deletions
diff --git a/scripts/api/stl/examples/stl_bi_dir_flows.py b/scripts/api/stl/examples/stl_bi_dir_flows.py index 7d090345..46b84c6e 100644 --- a/scripts/api/stl/examples/stl_bi_dir_flows.py +++ b/scripts/api/stl/examples/stl_bi_dir_flows.py @@ -1,8 +1,5 @@ -# include the path of trex_stl_api.py -import sys -sys.path.insert(0, "../") - -from trex_stl_api import * +import stl_path +from trex_control_plane.stl.api import * import time import json diff --git a/scripts/api/stl/examples/stl_imix.py b/scripts/api/stl/examples/stl_imix.py index 01eec9b4..c083a207 100644 --- a/scripts/api/stl/examples/stl_imix.py +++ b/scripts/api/stl/examples/stl_imix.py @@ -1,10 +1,5 @@ -# 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 stl_path +from trex_control_plane.stl.api import * import time import json @@ -26,9 +21,6 @@ def imix_test (): try: - # base profile - imix - profile = STLImix() - # connect to server c.connect() @@ -42,9 +34,12 @@ def imix_test (): dir_0 = table['dir'][0] dir_1 = table['dir'][1] + # load IMIX profile + streams = c.load_profile('../../../stl/profiles/imix.py') + # 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) + c.add_streams(streams, ports = dir_0) + c.add_streams(streams, ports = dir_1) # clear the stats before injecting c.clear_stats() diff --git a/scripts/api/stl/examples/stl_path.py b/scripts/api/stl/examples/stl_path.py new file mode 100644 index 00000000..e0056585 --- /dev/null +++ b/scripts/api/stl/examples/stl_path.py @@ -0,0 +1,2 @@ +import sys +sys.path.insert(0, "../../../automation") diff --git a/scripts/api/stl/examples/stl_run_udp_simple.py b/scripts/api/stl/examples/stl_run_udp_simple.py index 88dba5ac..47db1b5a 100644 --- a/scripts/api/stl/examples/stl_run_udp_simple.py +++ b/scripts/api/stl/examples/stl_run_udp_simple.py @@ -10,9 +10,8 @@ Compare Rx-pkts to TX-pkts assuming ports are loopback """ -sys.path.insert(0, "../") - -from trex_stl_api import * +import stl_path +from trex_control_plane.stl.api import * H_VER = "trex-x v0.1 " diff --git a/scripts/api/stl/examples/stl_simple_burst.py b/scripts/api/stl/examples/stl_simple_burst.py index 0de4df89..2ccd01c4 100644 --- a/scripts/api/stl/examples/stl_simple_burst.py +++ b/scripts/api/stl/examples/stl_simple_burst.py @@ -1,8 +1,6 @@ -import sys -sys.path.insert(0, "../") +import stl_path +from trex_control_plane.stl.api import * -from trex_stl_api import * -from scapy.all import * import time def simple_burst (): @@ -13,7 +11,6 @@ def simple_burst (): 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 @@ -24,7 +21,11 @@ def simple_burst (): mode = STLTXSingleBurst(total_pkts = 3000), next_stream_id = s1.get_id()) - + STLStream.dump_to_yaml([s1, s2], '1.yaml') + stream_list = STLStream.load_from_yaml('1.yaml') + print s2 + print stream_list[1] + exit(0) # connect to server c.connect() diff --git a/scripts/api/stl/trex_stl_api.py b/scripts/api/stl/trex_stl_api.py deleted file mode 100644 index 4dae4dce..00000000 --- a/scripts/api/stl/trex_stl_api.py +++ /dev/null @@ -1,44 +0,0 @@ -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__)) - -sys.path.insert(0, os.path.join(root_path, '../../automation/trex_control_plane/')) -sys.path.insert(0, os.path.join(root_path, '../../stl/')) - -# aliasing -import common.trex_streams -from client_utils.scapy_packet_builder import * -import common.trex_stl_exceptions -import client.trex_stateless_client -import client.trex_stateless_sim - -# client and errors -STLClient = client.trex_stateless_client.STLClient -STLError = common.trex_stl_exceptions.STLError - -# streams -STLStream = common.trex_streams.STLStream -STLTXCont = common.trex_streams.STLTXCont -STLTXSingleBurst = common.trex_streams.STLTXSingleBurst -STLTXMultiBurst = common.trex_streams.STLTXMultiBurst - -# packet builder -STLPktBuilder = CScapyTRexPktBuilder - -# VM -STLVmFlowVar = CTRexVmDescFlowVar -STLVmWriteFlowVar = CTRexVmDescWrFlowVar -STLVmFixIpv4 = CTRexVmDescFixIpv4 -STLVmTrimPktSize = CTRexVmDescTrimPktSize -STLVmTupleGen = CTRexVmDescTupleGen - - -# 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 deleted file mode 100644 index a8574e82..00000000 --- a/scripts/api/stl/trex_stl_lib.py +++ /dev/null @@ -1,71 +0,0 @@ - -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 - |