From 87bac1abebe2f5a853e32301a68b9f6adf97de99 Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 12 Apr 2016 18:01:43 +0300 Subject: added checks for warnings on examples --- .../trex_control_plane/stl/console/trex_console.py | 3 +- .../stl/examples/stl_bi_dir_flows.py | 44 ++++---- .../stl/examples/stl_bi_dir_flows1.py | 114 --------------------- .../stl/examples/stl_flow_stats.py | 18 ++-- .../trex_control_plane/stl/examples/stl_imix.py | 7 +- .../stl/examples/stl_simple_burst.py | 31 +++--- .../stl/trex_stl_lib/trex_stl_stats.py | 7 +- scripts/exp/stl_vm_split_client_var.erf-0.erf | Bin 11000 -> 11000 bytes .../exp/stl_vm_split_flow_var_big_range.erf-0.erf | Bin 11000 -> 11000 bytes scripts/exp/stl_vm_split_flow_var_inc.erf-0.erf | Bin 11000 -> 11000 bytes .../stl_vm_split_flow_var_small_range.erf-0.erf | Bin 11000 -> 11000 bytes 11 files changed, 67 insertions(+), 157 deletions(-) delete mode 100644 scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index 94cb4009..cb266505 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -572,7 +572,8 @@ class TRexConsole(TRexGeneralCmd): exe = './trex-console --top -t -q -s {0} -p {1} --async_port {2}'.format(info['server'], info['sync_port'], info['async_port']) cmd = ['/usr/bin/xterm', '-geometry', '111x48', '-sl', '0', '-title', 'trex_tui', '-e', exe] - self.terminal = subprocess.Popen(cmd) + # detach child + self.terminal = subprocess.Popen(cmd, preexec_fn = os.setpgrp) return 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 d4661b1a..9977fa3e 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 @@ -38,7 +38,7 @@ def create_pkt (size, direction): vm = vm) -def simple_burst (): +def simple_burst (port_a, port_b, pkt_size, rate): # create client @@ -50,11 +50,11 @@ def simple_burst (): #c.set_verbose("high") # create two streams - s1 = STLStream(packet = create_pkt(200, 0), + s1 = STLStream(packet = create_pkt(pkt_size, 0), mode = STLTXCont(pps = 100)) # second stream with a phase of 1ms (inter stream gap) - s2 = STLStream(packet = create_pkt(200, 1), + s2 = STLStream(packet = create_pkt(pkt_size, 1), isg = 1000, mode = STLTXCont(pps = 100)) @@ -62,36 +62,41 @@ def simple_burst (): # connect to server c.connect() - # prepare our ports (my machine has 0 <--> 1 with static route) - c.reset(ports = [0, 1]) + # prepare our ports + c.reset(ports = [port_a, port_b]) # add both streams to ports - c.add_streams(s1, ports = [0]) - c.add_streams(s2, ports = [1]) + c.add_streams(s1, ports = [port_a]) + c.add_streams(s2, ports = [port_b]) # clear the stats before injecting c.clear_stats() - # choose rate and start traffic for 10 seconds on 5 mpps - print("Running 100 Mbps on ports 0, 1 for 10 seconds...") - c.start(ports = [0, 1], mult = "100mbps", duration = 10) + # here we multiply the traffic lineaer to whatever given in rate + print("Running {:} on ports {:}, {:} for 10 seconds...".format(rate, port_a, port_b)) + c.start(ports = [port_a, port_b], mult = rate, duration = 10) # block until done - c.wait_on_traffic(ports = [0, 1]) + c.wait_on_traffic(ports = [port_a, port_b]) # 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[port_a], indent = 4, separators=(',', ': '), sort_keys = True)) + print(json.dumps(stats[port_b], indent = 4, separators=(',', ': '), sort_keys = True)) - lost_a = stats[0]["opackets"] - stats[1]["ipackets"] - lost_b = stats[1]["opackets"] - stats[0]["ipackets"] + lost_a = stats[port_a]["opackets"] - stats[port_b]["ipackets"] + lost_b = stats[port_b]["opackets"] - stats[port_a]["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}: {2} pkts".format(port_a, port_b, lost_a)) + print("packets lost from {0} --> {1}: {2} pkts".format(port_b, port_a, lost_b)) - if (lost_a == 0) and (lost_b == 0): + if c.get_warnings(): + print("\n\n*** test had warnings ****\n\n") + for w in c.get_warnings(): + print(w) + + if (lost_a == 0) and (lost_b == 0) and not c.get_warnings(): passed = True else: passed = False @@ -108,7 +113,6 @@ def simple_burst (): else: print("\nTest has failed :-(\n") -while True: # run the tests - simple_burst() +simple_burst(0, 3, 64, "10gbps") 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 deleted file mode 100644 index c9cab8e9..00000000 --- a/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py +++ /dev/null @@ -1,114 +0,0 @@ -import stl_path -from trex_stl_lib.api import * - -import time -import json - -# simple packet creation -def create_pkt (size, direction): - - ip_range = {'src': {'start': "10.0.0.1", 'end': "10.0.0.254"}, - 'dst': {'start': "8.0.0.1", 'end': "8.0.0.254"}} - - if (direction == 0): - src = ip_range['src'] - dst = ip_range['dst'] - else: - src = ip_range['dst'] - dst = ip_range['src'] - - vm = [ - # src - STLVmFlowVar(name="src",min_value=src['start'],max_value=src['end'],size=4,op="inc"), - STLVmWrFlowVar(fv_name="src",pkt_offset= "IP.src"), - - # dst - STLVmFlowVar(name="dst",min_value=dst['start'],max_value=dst['end'],size=4,op="inc"), - STLVmWrFlowVar(fv_name="dst",pkt_offset= "IP.dst"), - - # checksum - STLVmFixIpv4(offset = "IP") - ] - - - base = Ether()/IP()/UDP() - pad = max(0, size-len(base)) * 'x' - - return STLPktBuilder(pkt = base/pad, - vm = vm) - - -def simple_burst (): - - - # create client - c = STLClient() - passed = True - - try: - # turn this on for some information - #c.set_verbose("high") - - # create two streams - s1 = STLStream(packet = create_pkt(200, 0), - mode = STLTXCont(pps = 100)) - - # second stream with a phase of 1ms (inter stream gap) - s2 = STLStream(packet = create_pkt(200, 1), - isg = 1000, - mode = STLTXCont(pps = 100)) - - - # connect to server - c.connect() - - # prepare our ports (my machine has 0 <--> 1 with static route) - c.reset(ports = [2, 3]) - - # add both streams to ports - c.add_streams(s1, ports = [2]) - c.add_streams(s2, ports = [3]) - - # clear the stats before injecting - 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...") - c.start(ports = [2, 3], mult = "5mpps", duration = 10) - - # block until done - c.wait_on_traffic(ports = [2, 3]) - - # 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)) - - 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)) - - if (lost_a == 0) and (lost_b == 0): - passed = True - else: - passed = False - - except STLError as e: - passed = False - print(e) - - finally: - c.disconnect() - - if passed: - print("\nTest has passed :-)\n") - else: - print("\nTest has failed :-(\n") - -while True : - # run the tests - simple_burst() - 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 d938852e..ed4902fa 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 @@ -4,7 +4,7 @@ from trex_stl_lib.api import * import time import pprint -def rx_example (tx_port, rx_port, burst_size): +def rx_example (tx_port, rx_port, burst_size, bw): print("\nGoing to inject {0} packets on port {1} - checking RX stats on port {2}\n".format(burst_size, tx_port, rx_port)) @@ -19,9 +19,7 @@ def rx_example (tx_port, rx_port, burst_size): packet = pkt, flow_stats = STLFlowStats(pg_id = 5), mode = STLTXSingleBurst(total_pkts = total_pkts, - #pps = total_pkts - percentage = 80 - )) + percentage = bw)) # connect to server c.connect() @@ -36,7 +34,7 @@ def rx_example (tx_port, rx_port, burst_size): for i in range(0, 10): print("\nStarting iteration: {0}:".format(i)) - rc = rx_iteration(c, tx_port, rx_port, total_pkts, pkt.get_pkt_len()) + rc = rx_iteration(c, tx_port, rx_port, total_pkts, pkt.get_pkt_len(), bw) if not rc: passed = False break @@ -55,7 +53,7 @@ def rx_example (tx_port, rx_port, burst_size): print("\nTest has failed :-(\n") # RX one iteration -def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len): +def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len, bw): c.clear_stats() @@ -71,6 +69,12 @@ def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len): tx_bytes = flow_stats['tx_bytes'].get(tx_port, 0) rx_pkts = flow_stats['rx_pkts'].get(rx_port, 0) + if c.get_warnings(): + print("\n\n*** test had warnings ****\n\n") + for w in c.get_warnings(): + print(w) + return False + if tx_pkts != total_pkts: print("TX pkts mismatch - got: {0}, expected: {1}".format(tx_pkts, total_pkts)) pprint.pprint(flow_stats) @@ -95,5 +99,5 @@ def rx_iteration (c, tx_port, rx_port, total_pkts, pkt_len): return True # run the tests -rx_example(tx_port = 1, rx_port = 2, burst_size = 500000) +rx_example(tx_port = 1, rx_port = 2, burst_size = 500000, bw = 50) 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 bc7990aa..46d86b2b 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_imix.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_imix.py @@ -83,7 +83,12 @@ def imix_test (server, mult): print("\npackets lost from {0} --> {1}: {2:,} pkts".format(dir_0, dir_0, lost_0)) print("packets lost from {0} --> {1}: {2:,} pkts".format(dir_1, dir_1, lost_1)) - if (lost_0 <= 0) and (lost_1 <= 0): # less or equal because we might have incoming arps etc. + if c.get_warnings(): + print("\n\n*** test had warnings ****\n\n") + for w in c.get_warnings(): + print(w) + + if (lost_0 <= 0) and (lost_1 <= 0) and not c.get_warnings(): # less or equal because we might have incoming arps etc. passed = True else: passed = False 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 29341674..4bd9fd4c 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 @@ -3,47 +3,49 @@ from trex_stl_lib.api import * import time -def simple_burst (): +def simple_burst (port_a, port_b, pkt_size, burst_size, rate): # create client c = STLClient() 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') + pkt_base = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/IP() + pad = max(0, pkt_size - len(pkt_base)) * 'x' + pkt = STLPktBuilder(pkt = pkt_base / pad) # create two bursts and link them s1 = STLStream(name = 'A', packet = pkt, - mode = STLTXSingleBurst(total_pkts = 5000), + mode = STLTXSingleBurst(total_pkts = burst_size), next = 'B') s2 = STLStream(name = 'B', self_start = False, packet = pkt, - mode = STLTXSingleBurst(total_pkts = 3000)) + mode = STLTXSingleBurst(total_pkts = burst_size)) # connect to server c.connect() # prepare our ports - c.reset(ports = [0, 3]) + c.reset(ports = [port_a, port_b]) # add both streams to ports - stream_ids = c.add_streams([s1, s2], ports = [0, 3]) + stream_ids = c.add_streams([s1, s2], ports = [port_a, port_b]) # run 5 times for i in range(1, 6): c.clear_stats() - c.start(ports = [0, 3], mult = "1gbps") - c.wait_on_traffic(ports = [0, 3]) + c.start(ports = [port_a, port_b], mult = rate) + c.wait_on_traffic(ports = [port_a, port_b]) stats = c.get_stats() ipackets = stats['total']['ipackets'] print("Test iteration {0} - Packets Received: {1} ".format(i, ipackets)) - # (5000 + 3000) * 2 ports = 16,000 - if (ipackets != (16000)): + # two streams X 2 ports + if (ipackets != (burst_size * 2 * 2)): passed = False except STLError as e: @@ -53,12 +55,17 @@ def simple_burst (): finally: c.disconnect() - if passed: + if c.get_warnings(): + print("\n\n*** test had warnings ****\n\n") + for w in c.get_warnings(): + print(w) + + if passed and not c.get_warnings(): print("\nTest has passed :-)\n") else: print("\nTest has failed :-(\n") # run the tests -simple_burst() +simple_burst(0, 3, 256, 50000, "80%") diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index 48111433..dea7c6d5 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -105,6 +105,9 @@ class WatchedField(object): self.current = None def update (self, value): + if value is None: + return + if value > self.high_th and not self.hot: self.events_handler.log_warning("{0} is high: {1}{2}".format(self.name, value, self.suffix)) self.hot = True @@ -607,8 +610,8 @@ class CGlobalStats(CTRexStats): # simple... self.latest_stats = snapshot - self.watched_cpu_util.update(snapshot['m_cpu_util']) - self.watched_rx_cpu_util.update(snapshot['m_rx_cpu_util']) + self.watched_cpu_util.update(snapshot.get('m_cpu_util')) + self.watched_rx_cpu_util.update(snapshot.get('m_rx_cpu_util')) return True diff --git a/scripts/exp/stl_vm_split_client_var.erf-0.erf b/scripts/exp/stl_vm_split_client_var.erf-0.erf index 25b2a2bd..f156bfe5 100644 Binary files a/scripts/exp/stl_vm_split_client_var.erf-0.erf and b/scripts/exp/stl_vm_split_client_var.erf-0.erf differ diff --git a/scripts/exp/stl_vm_split_flow_var_big_range.erf-0.erf b/scripts/exp/stl_vm_split_flow_var_big_range.erf-0.erf index d5ad29d8..9a386724 100644 Binary files a/scripts/exp/stl_vm_split_flow_var_big_range.erf-0.erf and b/scripts/exp/stl_vm_split_flow_var_big_range.erf-0.erf differ diff --git a/scripts/exp/stl_vm_split_flow_var_inc.erf-0.erf b/scripts/exp/stl_vm_split_flow_var_inc.erf-0.erf index a938b37c..e6b9b85b 100644 Binary files a/scripts/exp/stl_vm_split_flow_var_inc.erf-0.erf and b/scripts/exp/stl_vm_split_flow_var_inc.erf-0.erf differ diff --git a/scripts/exp/stl_vm_split_flow_var_small_range.erf-0.erf b/scripts/exp/stl_vm_split_flow_var_small_range.erf-0.erf index 94e493fe..0a13e822 100644 Binary files a/scripts/exp/stl_vm_split_flow_var_small_range.erf-0.erf and b/scripts/exp/stl_vm_split_flow_var_small_range.erf-0.erf differ -- cgit 1.2.3-korg