From a393247f71ea669e738d5e89d6b51e1638c9baa2 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 6 Feb 2017 14:15:19 +0200 Subject: added another functional test - PING Signed-off-by: imarom --- .../stl/examples/stl_functional.py | 47 +++++++++++++++++++++- .../stl/trex_stl_lib/trex_stl_exceptions.py | 4 +- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_functional.py b/scripts/automation/trex_control_plane/stl/examples/stl_functional.py index 6322ce88..0057a764 100644 --- a/scripts/automation/trex_control_plane/stl/examples/stl_functional.py +++ b/scripts/automation/trex_control_plane/stl/examples/stl_functional.py @@ -44,7 +44,48 @@ def test_dot1q (c, rx_port, tx_port): rx_scapy_pkt.show2() +# test a echo request / echo reply +def test_ping (c, tx_port, rx_port): + + # activate service mode on RX code + c.set_service_mode(ports = [tx_port, rx_port]) + + # fetch the config + tx_port_attr = c.get_port_attr(port = tx_port) + rx_port_attr = c.get_port_attr(port = rx_port) + + assert(tx_port_attr['layer_mode'] == 'IPv4') + assert(rx_port_attr['layer_mode'] == 'IPv4') + + pkt = Ether() / IP(src = tx_port_attr['src_ipv4'], dst = rx_port_attr['src_ipv4']) / ICMP(type = 8) + + # start a capture on the sending port + capture = c.start_capture(rx_ports = tx_port) + + print('\nSending ping request on port {}'.format(tx_port)) + + # send the ping packet + c.push_packets(ports = tx_port, pkts = pkt, force = True) + c.wait_on_traffic(ports = tx_port) + + # fetch the packet + rx_pkts = [] + c.stop_capture(capture_id = capture['id'], output = rx_pkts) + + print('\nRecived {} packets on port {}:\n'.format(len(rx_pkts), tx_port)) + + c.set_service_mode(ports = rx_port, enabled = False) + + # got back one packet + assert(len(rx_pkts) == 1) + rx_scapy_pkt = Ether(rx_pkts[0]['binary']) + # check for ICMP reply + assert('ICMP' in rx_scapy_pkt) + assert(rx_scapy_pkt['ICMP'].type == 0) + + rx_scapy_pkt.show2() + def main (): # create a client @@ -58,9 +99,11 @@ def main (): tx_port, rx_port = stl_map_ports(c)['bi'][0] c.reset(ports = [tx_port, rx_port]) - # call the test + # test 1 test_dot1q(c, tx_port, rx_port) - + + # test 2 + test_ping(c, tx_port, rx_port) except STLError as e: print(e) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py index fa8163b8..79a001fe 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py @@ -23,9 +23,9 @@ class STLError(Exception): s += format_text("\nFull error report:\n\n", 'underline') - for line in reversed(self.tb): + for line in reversed(self.tb[:-1]): fname, lineno, func, src = os.path.split(line[0])[1], line[1], line[2], line[3] - s += " {:}:{:<20} - '{}'\n".format(format_text(fname, 'bold'), format_text(lineno, 'bold'), format_text(src.strip(), 'bold')) + s += " {:<50} - '{}'\n".format(format_text(fname, 'bold') + ':' + format_text(lineno, 'bold'), format_text(src.strip(), 'bold')) return s -- cgit 1.2.3-korg