diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-03-30 13:58:11 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-03-30 13:58:11 +0300 |
commit | 422c7c52632ebb6fbc5d5ff638b6ef0e1bc56f6b (patch) | |
tree | 5794318455a66a03828f98a5d6e825f47df3084e /scripts/automation/trex_control_plane | |
parent | 2ec326cbe088f3ee5634336e326ae8c3561c7461 (diff) | |
parent | b91c216db1aa10ca7cc81b8c74b04ab79df251fe (diff) |
Merge GA to Python API
Diffstat (limited to 'scripts/automation/trex_control_plane')
20 files changed, 86 insertions, 20 deletions
diff --git a/scripts/automation/trex_control_plane/doc/conf.py b/scripts/automation/trex_control_plane/doc/conf.py index a2641ffc..ec133a1c 100755 --- a/scripts/automation/trex_control_plane/doc/conf.py +++ b/scripts/automation/trex_control_plane/doc/conf.py @@ -20,7 +20,7 @@ import shlex # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('../stf')) +sys.path.insert(0, os.path.abspath('../stf/trex_stf_lib')) sys.path.insert(0, os.path.abspath('../client_utils')) sys.path.insert(0, os.path.abspath('../examples')) sys.path.insert(0, os.path.abspath('../common')) diff --git a/scripts/automation/trex_control_plane/stf/examples/stf_example.py b/scripts/automation/trex_control_plane/stf/examples/stf_example.py new file mode 100755 index 00000000..f6ebffe7 --- /dev/null +++ b/scripts/automation/trex_control_plane/stf/examples/stf_example.py @@ -0,0 +1,53 @@ +import argparse +import stf_path +from trex_stf_lib.trex_client import CTRexClient + +# sample TRex stateless run +# assuming server daemon is running. + +def minimal_stateful_test(server): + print('Connecting to %s' % server) + trex_client = CTRexClient(server) + + print('Connected, start TRex') + trex_client.start_trex( + c = 1, + m = 700, + f = 'cap2/http_simple.yaml', + d = 5, + l = 1000, + trex_development = True, + ) + + print('Sample until end') + result = trex_client.sample_to_run_finish() + + print('Test results:') + print(result) + + print('TX by ports:') + tx_ptks_dict = result.get_last_value('trex-global.data', 'opackets-*') + print(' | '.join(['%s: %s' % (k.split('-')[-1], tx_ptks_dict[k]) for k in sorted(tx_ptks_dict.keys())])) + + print('RX by ports:') + rx_ptks_dict = result.get_last_value('trex-global.data', 'ipackets-*') + print(' | '.join(['%s: %s' % (k.split('-')[-1], rx_ptks_dict[k]) for k in sorted(rx_ptks_dict.keys())])) + + print('CPU utilization:') + print(result.get_value_list('trex-global.data.m_cpu_util')) + + #print('Dump of *latest* result sample, uncomment to see it all') + #print(result.get_latest_dump()) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Example for TRex Stateful, assuming server daemon is running.") + parser.add_argument('-s', '--server', + dest='server', + help='Remote trex address', + default='127.0.0.1', + type = str) + args = parser.parse_args() + + minimal_stateful_test(args.server) + diff --git a/scripts/automation/trex_control_plane/stf/examples/stf_path.py b/scripts/automation/trex_control_plane/stf/examples/stf_path.py new file mode 100755 index 00000000..bb401148 --- /dev/null +++ b/scripts/automation/trex_control_plane/stf/examples/stf_path.py @@ -0,0 +1,4 @@ +import sys + +# FIXME to the write path for trex_stf_lib +sys.path.insert(0, "../") diff --git a/scripts/automation/trex_control_plane/stf/CCustomLogger.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/CCustomLogger.py index ecf7d519..ecf7d519 100755 --- a/scripts/automation/trex_control_plane/stf/CCustomLogger.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/CCustomLogger.py diff --git a/scripts/automation/trex_control_plane/stf/__init__.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/__init__.py index 5a1da046..5a1da046 100755 --- a/scripts/automation/trex_control_plane/stf/__init__.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/__init__.py diff --git a/scripts/automation/trex_control_plane/stf/external_packages.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/external_packages.py index 7353c397..7353c397 100755 --- a/scripts/automation/trex_control_plane/stf/external_packages.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/external_packages.py diff --git a/scripts/automation/trex_control_plane/stf/general_utils.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/general_utils.py index d2521f02..d2521f02 100755 --- a/scripts/automation/trex_control_plane/stf/general_utils.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/general_utils.py diff --git a/scripts/automation/trex_control_plane/stf/outer_packages.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/outer_packages.py index 5e29f8d6..f8d50ce6 100755 --- a/scripts/automation/trex_control_plane/stf/outer_packages.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/outer_packages.py @@ -5,8 +5,8 @@ import os CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) -PARENT_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir, 'external_libs')) -SCRIPTS_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, os.pardir, 'external_libs')) +PACKAGE_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, 'external_libs')) +SCRIPTS_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, os.pardir, os.pardir, 'external_libs')) CLIENT_MODULES = ['enum34-1.0.4', 'jsonrpclib-pelix-0.2.5', @@ -22,9 +22,9 @@ def import_module_list(ext_libs_path): raise Exception('Library %s is absent in path %s' % (p, ext_libs_path)) sys.path.insert(1, full_path) -if os.path.exists(PARENT_PATH): - import_module_list(PARENT_PATH) +if os.path.exists(PACKAGE_PATH): + import_module_list(PACKAGE_PATH) elif os.path.exists(SCRIPTS_PATH): import_module_list(SCRIPTS_PATH) else: - raise Exception('Could not find external libs in path: %s' % [PARENT_PATH, SCRIPTS_PATH]) + raise Exception('Could not find external libs in path: %s' % [PACKAGE_PATH, SCRIPTS_PATH]) diff --git a/scripts/automation/trex_control_plane/stf/text_opts.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/text_opts.py index 78a0ab1f..78a0ab1f 100755 --- a/scripts/automation/trex_control_plane/stf/text_opts.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/text_opts.py diff --git a/scripts/automation/trex_control_plane/stf/trex_client.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py index 919253d1..919253d1 100755 --- a/scripts/automation/trex_control_plane/stf/trex_client.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py diff --git a/scripts/automation/trex_control_plane/stf/trex_daemon_server.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_daemon_server.py index 9784d42a..9784d42a 100755 --- a/scripts/automation/trex_control_plane/stf/trex_daemon_server.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_daemon_server.py diff --git a/scripts/automation/trex_control_plane/stf/trex_exceptions.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_exceptions.py index 0de38411..0de38411 100755 --- a/scripts/automation/trex_control_plane/stf/trex_exceptions.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_exceptions.py diff --git a/scripts/automation/trex_control_plane/stf/trex_status.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_status.py index f132720c..f132720c 100644 --- a/scripts/automation/trex_control_plane/stf/trex_status.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_status.py diff --git a/scripts/automation/trex_control_plane/stf/trex_status_e.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_status_e.py index 79a25acc..79a25acc 100755 --- a/scripts/automation/trex_control_plane/stf/trex_status_e.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_status_e.py diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_imix.py b/scripts/automation/trex_control_plane/stl/examples/stl_imix.py index 56fd3cfd..7e43488b 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_imix.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_imix.py @@ -12,7 +12,7 @@ import argparse # and attach it to both sides and inject # at a certain rate for some time # finally it checks that all packets arrived -def imix_test (server): +def imix_test (server, mult): # create client @@ -37,7 +37,8 @@ def imix_test (server): print("Mapped ports to sides {0} <--> {1}".format(dir_0, dir_1)) # load IMIX profile - profile = STLProfile.load_py('../../../../stl/imix.py') + profile_file = os.path.join(stl_path.STL_PROFILES_PATH, 'imix.py') + profile = STLProfile.load_py(profile_file) streams = profile.get_streams() # add both streams to ports @@ -47,9 +48,8 @@ def imix_test (server): # clear the stats before injecting c.clear_stats() - # choose rate and start traffic for 10 seconds on 5 mpps + # choose rate and start traffic for 10 seconds duration = 10 - mult = "30%" print("Injecting {0} <--> {1} on total rate of '{2}' for {3} seconds".format(dir_0, dir_1, mult, duration)) c.start(ports = (dir_0 + dir_1), mult = mult, duration = duration, total = True) @@ -107,8 +107,13 @@ parser.add_argument('-s', '--server', help='Remote trex address', default='127.0.0.1', type = str) +parser.add_argument('-m', '--mult', + dest='mult', + help='Multiplier of traffic, see Stateless help for more info', + default='30%', + type = str) args = parser.parse_args() # run the tests -imix_test(args.server) +imix_test(args.server, args.mult) diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_imix_bidir.py b/scripts/automation/trex_control_plane/stl/examples/stl_imix_bidir.py index 05a8777b..05615aeb 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_imix_bidir.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_imix_bidir.py @@ -29,14 +29,15 @@ def imix_test (server): # take all the ports c.reset() - dir_0 = [0] - dir_1 = [1] + dir_0 = [0] + dir_1 = [1] print "Mapped ports to sides {0} <--> {1}".format(dir_0, dir_1) # load IMIX profile - profile1 = STLProfile.load_py('../../../../stl/imix.py', direction=0) - profile2 = STLProfile.load_py('../../../../stl/imix.py', direction=1) + profile_file = os.path.join(stl_path.STL_PROFILES_PATH, 'imix.py') + profile1 = STLProfile.load_py(profile_file, direction=0) + profile2 = STLProfile.load_py(profile_file, direction=1) stream1 = profile1.get_streams() stream2 = profile2.get_streams() diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_path.py b/scripts/automation/trex_control_plane/stl/examples/stl_path.py index 8f400d23..f1592571 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_path.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_path.py @@ -1,4 +1,7 @@ -import sys +import sys, os # FIXME to the write path for trex_stl_lib sys.path.insert(0, "../") + +STL_PROFILES_PATH = os.path.join(os.pardir, os.pardir, os.pardir, os.pardir, 'stl') + diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_profile.py b/scripts/automation/trex_control_plane/stl/examples/stl_profile.py index 3ae5f855..16d5238e 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_profile.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_profile.py @@ -18,8 +18,7 @@ def simple (): # prepare our ports c.reset(ports = my_ports) - - profile_file = "../../../../stl/udp_1pkt_simple.py" + profile_file = os.path.join(stl_path.STL_PROFILES_PATH, 'hlt', 'udp_1pkt_simple.py') try: profile = STLProfile.load(profile_file) diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py b/scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py index 03909e65..1d4ef250 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py @@ -29,9 +29,10 @@ def simple (): print(c.get_port_info(my_ports)) c.ping() + profile_file = os.path.join(stl_path.STL_PROFILES_PATH, 'udp_1pkt_simple.py') print("start") - c.start_line (" -f ../../../../stl/udp_1pkt_simple.py -m 10mpps --port 0 1 ") + c.start_line (" -f %s -m 10mpps --port 0 1 " % profile_file) time.sleep(2); c.pause_line("--port 0 1"); time.sleep(2); diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py index d6d66ec3..ed0c393d 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py @@ -9,7 +9,7 @@ TREX_STL_EXT_PATH = os.environ.get('TREX_STL_EXT_PATH') # take default if not TREX_STL_EXT_PATH or not os.path.exists(TREX_STL_EXT_PATH): CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) - TREX_STL_EXT_PATH = os.path.normpath(os.path.join(CURRENT_PATH, os.pardir, 'external_libs')) + TREX_STL_EXT_PATH = os.path.normpath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, 'external_libs')) if not os.path.exists(TREX_STL_EXT_PATH): # ../../../../external_libs TREX_STL_EXT_PATH = os.path.normpath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, os.pardir, os.pardir, 'external_libs')) |