summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/examples
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-03-13 17:07:39 +0200
committerHanoh Haim <hhaim@cisco.com>2016-03-13 17:07:39 +0200
commit33386099a94c8940616cdd9c3f674f0ee63d8af6 (patch)
tree01f37d3ddcabf0148b839f636a0218173ccb192a /scripts/automation/trex_control_plane/stl/examples
parent1c53541847206c2fb33ef713014fd43d7a6c1357 (diff)
add more API sample
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/examples')
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_profile.py59
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py59
2 files changed, 118 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_profile.py b/scripts/automation/trex_control_plane/stl/examples/stl_profile.py
new file mode 100644
index 00000000..ad9d525a
--- /dev/null
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_profile.py
@@ -0,0 +1,59 @@
+import stl_path
+from trex_stl_lib.api import *
+
+import time
+
+def simple ():
+
+ # create client
+ #verbose_level = LoggerApi.VERBOSE_HIGH
+ c = STLClient(verbose_level = LoggerApi.VERBOSE_REGULAR)
+ passed = True
+
+ try:
+ # connect to server
+ c.connect()
+
+ my_ports=[0,1]
+
+ # prepare our ports
+ c.reset(ports = my_ports)
+
+ profile_file = "../../../../stl/udp_1pkt_simple.py"
+
+ try:
+ profile = STLProfile.load(profile_file)
+ except STLError as e:
+ print format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold')
+ print e.brief() + "\n"
+ return
+
+ print profile.dump_to_yaml()
+
+ c.remove_all_streams(my_ports)
+
+
+ c.add_streams(profile.get_streams(), ports = my_ports)
+
+ c.start(ports = [0, 1], mult = "5mpps", duration = 10)
+
+ # block until done
+ c.wait_on_traffic(ports = [0, 1])
+
+
+ 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()
+
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
new file mode 100644
index 00000000..dc9b2b2b
--- /dev/null
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py
@@ -0,0 +1,59 @@
+import stl_path
+from trex_stl_lib.api import *
+
+import time
+
+def simple ():
+
+ # create client
+ #verbose_level = LoggerApi.VERBOSE_HIGH
+ c = STLClient(verbose_level = LoggerApi.VERBOSE_REGULAR)
+ passed = True
+
+ try:
+ # connect to server
+ c.connect()
+
+ my_ports=[0,1]
+
+ # prepare our ports
+ c.reset(ports = my_ports)
+
+ print (" is connected {0}".format(c.is_connected()))
+
+ print (" number of ports {0}".format(c.get_port_count()))
+ print (" acquired_ports {0}".format(c.get_acquired_ports()))
+ # port stats
+ print c.get_stats(my_ports)
+ # port info
+ print c.get_port_info(my_ports)
+
+ c.ping()
+
+ print("start")
+ c.start_line (" -f ../../../../stl/udp_1pkt_simple.py -m 10mpps --port 0 1 ")
+ time.sleep(2);
+ c.pause_line("--port 0 1");
+ time.sleep(2);
+ c.resume_line("--port 0 1");
+ time.sleep(2);
+ c.update_line("--port 0 1 -m 5mpps");
+ time.sleep(2);
+ c.stop_line("--port 0 1");
+
+ 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()
+