summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-03-21 17:22:06 +0200
committerimarom <imarom@cisco.com>2016-03-21 17:22:06 +0200
commit738da2c0cd38f13a3cf7ae726f7698959ebf1ff0 (patch)
tree8be6fb021cbf6039cb91ce991e22254bdfb8cff7 /scripts/automation
parentc59a02f8036bbdc488f286412e990a16e3aa1df9 (diff)
python 3 - examples working
Diffstat (limited to 'scripts/automation')
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows.py16
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py16
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_flow_stats.py26
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_pcap.py6
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_profile.py12
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_run_udp_simple.py18
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_simple_burst.py10
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_simple_console_like.py16
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py7
9 files changed, 66 insertions, 61 deletions
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows.py b/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows.py
index 05fff67c..ff16d397 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows.py
@@ -73,7 +73,7 @@ def simple_burst ():
c.clear_stats()
# choose rate and start traffic for 10 seconds on 5 mpps
- print "Running 5 Mpps on ports 0, 1 for 10 seconds..."
+ print("Running 5 Mpps on ports 0, 1 for 10 seconds...")
c.start(ports = [0, 1], mult = "5mpps", duration = 10)
# block until done
@@ -82,14 +82,14 @@ def simple_burst ():
# read the stats after the test
stats = c.get_stats()
- print json.dumps(stats[0], indent = 4, separators=(',', ': '), sort_keys = True)
- print json.dumps(stats[1], indent = 4, separators=(',', ': '), sort_keys = True)
+ print(json.dumps(stats[0], indent = 4, separators=(',', ': '), sort_keys = True))
+ print(json.dumps(stats[1], indent = 4, separators=(',', ': '), sort_keys = True))
lost_a = stats[0]["opackets"] - stats[1]["ipackets"]
lost_b = stats[1]["opackets"] - stats[0]["ipackets"]
- print "\npackets lost from 0 --> 1: {0} pkts".format(lost_a)
- print "packets lost from 1 --> 0: {0} pkts".format(lost_b)
+ print("\npackets lost from 0 --> 1: {0} pkts".format(lost_a))
+ print("packets lost from 1 --> 0: {0} pkts".format(lost_b))
if (lost_a == 0) and (lost_b == 0):
passed = True
@@ -98,15 +98,15 @@ def simple_burst ():
except STLError as e:
passed = False
- print e
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nTest has passed :-)\n"
+ print("\nTest has passed :-)\n")
else:
- print "\nTest has failed :-(\n"
+ print("\nTest has failed :-(\n")
while True:
# run the tests
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py b/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py
index 264d985e..6e08a0fa 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py
@@ -73,7 +73,7 @@ def simple_burst ():
c.clear_stats()
# choose rate and start traffic for 10 seconds on 5 mpps
- print "Running 5 Mpps on ports 0, 1 for 10 seconds..."
+ print("Running 5 Mpps on ports 0, 1 for 10 seconds...")
c.start(ports = [2, 3], mult = "5mpps", duration = 10)
# block until done
@@ -82,14 +82,14 @@ def simple_burst ():
# read the stats after the test
stats = c.get_stats()
- print json.dumps(stats[2], indent = 4, separators=(',', ': '), sort_keys = True)
- print json.dumps(stats[3], indent = 4, separators=(',', ': '), sort_keys = True)
+ print(json.dumps(stats[2], indent = 4, separators=(',', ': '), sort_keys = True))
+ print(json.dumps(stats[3], indent = 4, separators=(',', ': '), sort_keys = True))
lost_a = stats[2]["opackets"] - stats[3]["ipackets"]
lost_b = stats[3]["opackets"] - stats[2]["ipackets"]
- print "\npackets lost from 0 --> 1: {0} pkts".format(lost_a)
- print "packets lost from 1 --> 0: {0} pkts".format(lost_b)
+ print("\npackets lost from 0 --> 1: {0} pkts".format(lost_a))
+ print("packets lost from 1 --> 0: {0} pkts".format(lost_b))
if (lost_a == 0) and (lost_b == 0):
passed = True
@@ -98,15 +98,15 @@ def simple_burst ():
except STLError as e:
passed = False
- print e
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nTest has passed :-)\n"
+ print("\nTest has passed :-)\n")
else:
- print "\nTest has failed :-(\n"
+ print("\nTest has failed :-(\n")
while True :
# run the tests
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_flow_stats.py b/scripts/automation/trex_control_plane/stl/examples/stl_flow_stats.py
index fa6e67c3..d938852e 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_flow_stats.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_flow_stats.py
@@ -6,7 +6,7 @@ import pprint
def rx_example (tx_port, rx_port, burst_size):
- print "\nGoing to inject {0} packets on port {1} - checking RX stats on port {2}\n".format(burst_size, tx_port, rx_port)
+ print("\nGoing to inject {0} packets on port {1} - checking RX stats on port {2}\n".format(burst_size, tx_port, rx_port))
# create client
c = STLClient()
@@ -32,10 +32,10 @@ def rx_example (tx_port, rx_port, burst_size):
# add both streams to ports
c.add_streams([s1], ports = [tx_port])
- print "\ninjecting {0} packets on port {1}\n".format(total_pkts, tx_port)
+ print("\ninjecting {0} packets on port {1}\n".format(total_pkts, tx_port))
for i in range(0, 10):
- print "\nStarting iteration: {0}:".format(i)
+ print("\nStarting iteration: {0}:".format(i))
rc = rx_iteration(c, tx_port, rx_port, total_pkts, pkt.get_pkt_len())
if not rc:
passed = False
@@ -44,15 +44,15 @@ def rx_example (tx_port, rx_port, burst_size):
except STLError as e:
passed = False
- print e
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nTest has passed :-)\n"
+ print("\nTest has passed :-)\n")
else:
- print "\nTest has failed :-(\n"
+ print("\nTest has failed :-(\n")
# RX one iteration
def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len):
@@ -64,7 +64,7 @@ def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len):
flow_stats = c.get_stats()['flow_stats'].get(5)
if not flow_stats:
- print "no flow stats available"
+ print("no flow stats available")
return False
tx_pkts = flow_stats['tx_pkts'].get(tx_port, 0)
@@ -72,25 +72,25 @@ def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len):
rx_pkts = flow_stats['rx_pkts'].get(rx_port, 0)
if tx_pkts != total_pkts:
- print "TX pkts mismatch - got: {0}, expected: {1}".format(tx_pkts, total_pkts)
+ print("TX pkts mismatch - got: {0}, expected: {1}".format(tx_pkts, total_pkts))
pprint.pprint(flow_stats)
return False
else:
- print "TX pkts match - {0}".format(tx_pkts)
+ print("TX pkts match - {0}".format(tx_pkts))
if tx_bytes != (total_pkts * pkt_len):
- print "TX bytes mismatch - got: {0}, expected: {1}".format(tx_bytes, (total_pkts * pkt_len))
+ print("TX bytes mismatch - got: {0}, expected: {1}".format(tx_bytes, (total_pkts * pkt_len)))
pprint.pprint(flow_stats)
return False
else:
- print "TX bytes match - {0}".format(tx_bytes)
+ print("TX bytes match - {0}".format(tx_bytes))
if rx_pkts != total_pkts:
- print "RX pkts mismatch - got: {0}, expected: {1}".format(rx_pkts, total_pkts)
+ print("RX pkts mismatch - got: {0}, expected: {1}".format(rx_pkts, total_pkts))
pprint.pprint(flow_stats)
return False
else:
- print "RX pkts match - {0}".format(rx_pkts)
+ print("RX pkts match - {0}".format(rx_pkts))
return True
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py b/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py
index a729a572..317f44c7 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py
@@ -31,7 +31,7 @@ def inject_pcap (pcap_file, port, loop_count, ipg_usec, use_vm):
profile = STLProfile.load_pcap(pcap_file, ipg_usec = ipg_usec, loop_count = loop_count, vm = vm)
- print "Loaded pcap {0} with {1} packets...\n".format(pcap_file, len(profile))
+ print("Loaded pcap {0} with {1} packets...\n".format(pcap_file, len(profile)))
# uncomment this for simulator run
#STLSim().run(profile.get_streams(), outfile = 'out.cap')
@@ -47,10 +47,10 @@ def inject_pcap (pcap_file, port, loop_count, ipg_usec, use_vm):
stats = c.get_stats()
opackets = stats[port]['opackets']
- print "{0} packets were Tx on port {1}\n".format(opackets, port)
+ print("{0} packets were Tx on port {1}\n".format(opackets, port))
except STLError as e:
- print e
+ print(e)
finally:
c.disconnect()
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 ad9d525a..3ae5f855 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_profile.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_profile.py
@@ -24,11 +24,11 @@ def simple ():
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"
+ print(format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold'))
+ print(e.brief() + "\n")
return
- print profile.dump_to_yaml()
+ print(profile.dump_to_yaml())
c.remove_all_streams(my_ports)
@@ -43,15 +43,15 @@ def simple ():
except STLError as e:
passed = False
- print e
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nTest has passed :-)\n"
+ print("\nTest has passed :-)\n")
else:
- print "\nTest has failed :-(\n"
+ print("\nTest has failed :-(\n")
# run the tests
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_run_udp_simple.py b/scripts/automation/trex_control_plane/stl/examples/stl_run_udp_simple.py
index 465b3dde..d06414e4 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_run_udp_simple.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_run_udp_simple.py
@@ -108,7 +108,7 @@ def simple_burst (duration = 10, frame_size = 9000, speed = '1gbps'):
c.clear_stats()
# choose rate and start traffic for 10 seconds on 5 mpps
- print "Running {0} on ports 0, 1 for 10 seconds, UDP {1}...".format(speed,frame_size+4)
+ print("Running {0} on ports 0, 1 for 10 seconds, UDP {1}...".format(speed,frame_size+4))
c.start(ports = [0, 1], mult = speed, duration = duration)
# block until done
@@ -118,14 +118,14 @@ def simple_burst (duration = 10, frame_size = 9000, speed = '1gbps'):
stats = c.get_stats()
#print stats
- print json.dumps(stats[0], indent = 4, separators=(',', ': '), sort_keys = True)
- print json.dumps(stats[1], indent = 4, separators=(',', ': '), sort_keys = True)
+ print(json.dumps(stats[0], indent = 4, separators=(',', ': '), sort_keys = True))
+ print(json.dumps(stats[1], indent = 4, separators=(',', ': '), sort_keys = True))
lost_a = stats[0]["opackets"] - stats[1]["ipackets"]
lost_b = stats[1]["opackets"] - stats[0]["ipackets"]
- print "\npackets lost from 0 --> 1: {0} pkts".format(lost_a)
- print "packets lost from 1 --> 0: {0} pkts".format(lost_b)
+ print("\npackets lost from 0 --> 1: {0} pkts".format(lost_a))
+ print("packets lost from 1 --> 0: {0} pkts".format(lost_b))
if (lost_a == 0) and (lost_b == 0):
passed = True
@@ -134,15 +134,15 @@ def simple_burst (duration = 10, frame_size = 9000, speed = '1gbps'):
except STLError as e:
passed = False
- print e
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nPASSED\n"
+ print("\nPASSED\n")
else:
- print "\nFAILED\n"
+ print("\nFAILED\n")
def process_options ():
parser = argparse.ArgumentParser(usage="""
@@ -202,7 +202,7 @@ def process_options ():
version=H_VER )
t_global.args = parser.parse_args();
- print t_global.args
+ print(t_global.args)
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_simple_burst.py b/scripts/automation/trex_control_plane/stl/examples/stl_simple_burst.py
index ed0cb93a..29341674 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_simple_burst.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_simple_burst.py
@@ -33,7 +33,7 @@ def simple_burst ():
stream_ids = c.add_streams([s1, s2], ports = [0, 3])
# run 5 times
- for i in xrange(1, 6):
+ for i in range(1, 6):
c.clear_stats()
c.start(ports = [0, 3], mult = "1gbps")
c.wait_on_traffic(ports = [0, 3])
@@ -41,22 +41,22 @@ def simple_burst ():
stats = c.get_stats()
ipackets = stats['total']['ipackets']
- print "Test iteration {0} - Packets Received: {1} ".format(i, 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
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nTest has passed :-)\n"
+ print("\nTest has passed :-)\n")
else:
- print "\nTest has failed :-(\n"
+ print("\nTest has failed :-(\n")
# run the tests
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 dc9b2b2b..03909e65 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
@@ -19,14 +19,14 @@ def simple ():
# prepare our ports
c.reset(ports = my_ports)
- print (" is connected {0}".format(c.is_connected()))
+ 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()))
+ 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)
+ print(c.get_stats(my_ports))
# port info
- print c.get_port_info(my_ports)
+ print(c.get_port_info(my_ports))
c.ping()
@@ -43,15 +43,15 @@ def simple ():
except STLError as e:
passed = False
- print e
+ print(e)
finally:
c.disconnect()
if passed:
- print "\nTest has passed :-)\n"
+ print("\nTest has passed :-)\n")
else:
- print "\nTest has failed :-(\n"
+ print("\nTest has failed :-(\n")
# run the tests
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
index 75e15ca1..e501c185 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
@@ -31,9 +31,14 @@ import argparse
import tempfile
import subprocess
import os
-from dpkt import pcap
from operator import itemgetter
+# HACK
+import sys
+if sys.version_info < (3, 0):
+ from dpkt import pcap
+# HACK END
+
class BpSimException(Exception):
pass