diff options
author | Klement Sekera <ksekera@cisco.com> | 2016-12-12 08:36:58 +0100 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2016-12-16 08:09:40 +0000 |
commit | 9225dee9655ce607130f9bab5472441b72e25858 (patch) | |
tree | 6438ea39bf2b14eeca70770890165497ee146d30 /test/test_gre.py | |
parent | cc53285baf2c3a45b95e22dd66c8592d634568ee (diff) |
make test: improve robustness and performance
Introduce an API which asserts empty capture for interface.
Throw exception in old API if the capture does not exist, thus
making it clear if the test expects packets to arrive or not.
Improve performance by not doing sleeps after starting the packet
generator, rather lazily deleting captures when needed.
Fix wrong usage of packet.show() in various tests.
Change-Id: I456cb23316eef99b3f35f80344fe595c4db9a21c
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/test_gre.py')
-rw-r--r-- | test/test_gre.py | 62 |
1 files changed, 23 insertions, 39 deletions
diff --git a/test/test_gre.py b/test/test_gre.py index 0b5082859b7..59d03e9307e 100644 --- a/test/test_gre.py +++ b/test/test_gre.py @@ -1,22 +1,22 @@ #!/usr/bin/env python import unittest -import socket from logging import * from framework import VppTestCase, VppTestRunner -from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint +from vpp_sub_interface import VppDot1QSubint from vpp_gre_interface import VppGreInterface from vpp_ip_route import IpRoute, RoutePath from vpp_papi_provider import L2_VTR_OP from scapy.packet import Raw -from scapy.layers.l2 import Ether, Dot1Q, ARP, GRE +from scapy.layers.l2 import Ether, Dot1Q, GRE from scapy.layers.inet import IP, UDP -from scapy.layers.inet6 import ICMPv6ND_NS, ICMPv6ND_RA, IPv6, UDP -from scapy.contrib.mpls import MPLS +from scapy.layers.inet6 import ICMPv6ND_RA, IPv6 from scapy.volatile import RandMAC, RandIP +from util import ppp, ppc + class TestGRE(VppTestCase): """ GRE Test Case """ @@ -131,7 +131,7 @@ class TestGRE(VppTestCase): def verify_filter(self, capture, sent): if not len(capture) == len(sent): - # filter out any IPv6 RAs from the captur + # filter out any IPv6 RAs from the capture for p in capture: if (p.haslayer(ICMPv6ND_RA)): capture.remove(p) @@ -163,8 +163,8 @@ class TestGRE(VppTestCase): self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl) except: - rx.show() - tx.show() + self.logger.error(ppp("Rx:", rx)) + self.logger.error(ppp("Tx:", tx)) raise def verify_tunneled_l2o4(self, src_if, capture, sent, @@ -196,8 +196,8 @@ class TestGRE(VppTestCase): self.assertEqual(rx_ip.ttl, tx_ip.ttl) except: - rx.show() - tx.show() + self.logger.error(ppp("Rx:", rx)) + self.logger.error(ppp("Tx:", tx)) raise def verify_tunneled_vlano4(self, src_if, capture, sent, @@ -206,7 +206,7 @@ class TestGRE(VppTestCase): capture = self.verify_filter(capture, sent) self.assertEqual(len(capture), len(sent)) except: - capture.show() + ppc("Unexpected packets captured:", capture) raise for i in range(len(capture)): @@ -237,8 +237,8 @@ class TestGRE(VppTestCase): self.assertEqual(rx_ip.ttl, tx_ip.ttl) except: - rx.show() - tx.show() + self.logger.error(ppp("Rx:", rx)) + self.logger.error(ppp("Tx:", tx)) raise def verify_decapped_4o4(self, src_if, capture, sent): @@ -261,8 +261,8 @@ class TestGRE(VppTestCase): self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl) except: - rx.show() - tx.show() + self.logger.error(ppp("Rx:", rx)) + self.logger.error(ppp("Tx:", tx)) raise def verify_decapped_6o4(self, src_if, capture, sent): @@ -284,8 +284,8 @@ class TestGRE(VppTestCase): self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim) except: - rx.show() - tx.show() + self.logger.error(ppp("Rx:", rx)) + self.logger.error(ppp("Tx:", tx)) raise def test_gre(self): @@ -333,14 +333,8 @@ class TestGRE(VppTestCase): self.pg_enable_capture(self.pg_interfaces) self.pg_start() - rx = self.pg0.get_capture() - - try: - self.assertEqual(0, len(rx)) - except: - error("GRE packets forwarded without DIP resolved") - error(rx.show()) - raise + self.pg0.assert_nothing_captured( + remark="GRE packets forwarded without DIP resolved") # # Add a route that resolves the tunnel's destination @@ -397,13 +391,8 @@ class TestGRE(VppTestCase): self.pg_enable_capture(self.pg_interfaces) self.pg_start() - rx = self.pg0.get_capture() - try: - self.assertEqual(0, len(rx)) - except: - error("GRE packets forwarded despite no SRC address match") - error(rx.show()) - raise + self.pg0.assert_nothing_captured( + remark="GRE packets forwarded despite no SRC address match") # # Configure IPv6 on the PG interface so we can route IPv6 @@ -427,13 +416,8 @@ class TestGRE(VppTestCase): self.pg_enable_capture(self.pg_interfaces) self.pg_start() - rx = self.pg0.get_capture() - try: - self.assertEqual(0, len(rx)) - except: - error("IPv6 GRE packets forwarded despite IPv6 not enabled on tunnel") - error(rx.show()) - raise + self.pg0.assert_nothing_captured(remark="IPv6 GRE packets forwarded " + "despite IPv6 not enabled on tunnel") # # Enable IPv6 on the tunnel |