test: consolidate the multiple versions of send_and_* 90/9990/2
authorNeale Ranns <nranns@cisco.com>
Mon, 8 Jan 2018 12:41:42 +0000 (04:41 -0800)
committerOle Trøan <otroan@employees.org>
Tue, 9 Jan 2018 12:41:23 +0000 (12:41 +0000)
Change-Id: I7fa7d0ebf73dab8264a2e5ddbd412600d78ead05
Signed-off-by: Neale Ranns <nranns@cisco.com>
test/framework.py
test/test_bier.py
test/test_dhcp.py
test/test_dvr.py
test/test_ip4.py
test/test_ip6.py
test/test_map.py
test/test_mpls.py
test/test_neighbor.py
test/test_udp.py

index 210eadb..2e3f978 100644 (file)
@@ -747,6 +747,25 @@ class VppTestCase(unittest.TestCase):
                 "Finished sleep (%s) - slept %ss (wanted %ss)" % (
                     remark, after - before, timeout))
 
+    def send_and_assert_no_replies(self, intf, pkts, remark=""):
+        self.vapi.cli("clear trace")
+        intf.add_stream(pkts)
+        self.pg_enable_capture(self.pg_interfaces)
+        self.pg_start()
+        timeout = 1
+        for i in self.pg_interfaces:
+            i.get_capture(0, timeout=timeout)
+            i.assert_nothing_captured(remark=remark)
+            timeout = 0.1
+
+    def send_and_expect(self, input, pkts, output):
+        self.vapi.cli("clear trace")
+        input.add_stream(pkts)
+        self.pg_enable_capture(self.pg_interfaces)
+        self.pg_start()
+        rx = output.get_capture(len(pkts))
+        return rx
+
 
 class TestCasePrinter(object):
     _shared_state = {}
index 514265c..e9c23fe 100644 (file)
@@ -66,21 +66,6 @@ class TestBier(VppTestCase):
             i.admin_down()
         super(TestBier, self).tearDown()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.assert_nothing_captured(remark=remark)
-
-    def send_and_expect(self, input, pkts, output):
-        self.vapi.cli("trace add bier-mpls-lookup 10")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
     def test_bier_midpoint(self):
         """BIER midpoint"""
 
index 7ae98e8..db7a7cc 100644 (file)
@@ -77,13 +77,6 @@ class TestDHCP(VppTestCase):
             i.admin_down()
         super(TestDHCP, self).tearDown()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.assert_nothing_captured(remark=remark)
-
     def verify_dhcp_has_option(self, pkt, option, value):
         dhcp = pkt[DHCP]
         found = False
index e8a9c04..e7b68db 100644 (file)
@@ -36,23 +36,6 @@ class TestDVR(VppTestCase):
 
         super(TestDVR, self).tearDown()
 
-    def send_and_assert_no_replies(self, intf, pkts):
-        self.vapi.cli("clear trace")
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured()
-
-    def send_and_expect(self, input, pkts, output):
-        self.vapi.cli("clear trace")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
     def assert_same_mac_addr(self, tx, rx):
         t_eth = tx[Ether]
         for p in rx:
index 12fbced..79d4a36 100644 (file)
@@ -572,14 +572,6 @@ class TestIPDisabled(VppTestCase):
             i.unconfig_ip4()
             i.admin_down()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_disabled(self):
         """ IP Disabled """
 
@@ -667,14 +659,6 @@ class TestIPSubNets(VppTestCase):
         for i in self.pg_interfaces:
             i.admin_down()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_sub_nets(self):
         """ IP Sub Nets """
 
@@ -985,12 +969,6 @@ class TestIPVlan0(VppTestCase):
             i.admin_down()
         super(TestIPVlan0, self).tearDown()
 
-    def send_and_expect(self, input, pkts, output):
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-
     def test_ip_vlan_0(self):
         """ IP VLAN-0 """
 
@@ -1028,23 +1006,6 @@ class TestIPPunt(VppTestCase):
             i.unconfig_ip4()
             i.admin_down()
 
-    def send_and_expect(self, input, pkts, output):
-        self.vapi.cli("clear trace")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        self.vapi.cli("clear trace")
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_punt(self):
         """ IP punt police and redirect """
 
@@ -1138,23 +1099,6 @@ class TestIPDeag(VppTestCase):
             i.unconfig_ip4()
             i.admin_down()
 
-    def send_and_expect(self, input, pkts, output):
-        self.vapi.cli("clear trace")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        self.vapi.cli("clear trace")
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_deag(self):
         """ IP Deag Routes """
 
@@ -1246,23 +1190,6 @@ class TestIPInput(VppTestCase):
             i.unconfig_ip4()
             i.admin_down()
 
-    def send_and_expect(self, input, pkts, output):
-        self.vapi.cli("clear trace")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        self.vapi.cli("clear trace")
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_input(self):
         """ IP Input Exceptions """
 
index 684eff5..68b077c 100644 (file)
@@ -136,14 +136,6 @@ class TestIPv6ND(VppTestCase):
         rx = rx[0]
         self.validate_ns(rx_intf, rx, tgt_ip)
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def verify_ip(self, rx, smac, dmac, sip, dip):
         ether = rx[Ether]
         self.assertEqual(ether.dst, dmac)
@@ -1179,14 +1171,6 @@ class TestIPDisabled(VppTestCase):
             i.unconfig_ip4()
             i.admin_down()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_disabled(self):
         """ IP Disabled """
 
@@ -1528,22 +1512,6 @@ class TestIP6Punt(VppTestCase):
             i.unconfig_ip6()
             i.admin_down()
 
-    def send_and_expect(self, input, pkts, output):
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        self.vapi.cli("clear trace")
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_punt(self):
         """ IP6 punt police and redirect """
 
@@ -1641,23 +1609,6 @@ class TestIP6Input(VppTestCase):
             i.unconfig_ip6()
             i.admin_down()
 
-    def send_and_expect(self, input, pkts, output):
-        self.vapi.cli("clear trace")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        self.vapi.cli("clear trace")
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_ip_input(self):
         """ IP6 Input Exceptions """
 
index bbf4aec..c5e193a 100644 (file)
@@ -38,13 +38,6 @@ class TestMAP(VppTestCase):
             i.unconfig_ip6()
             i.admin_down()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.assert_nothing_captured(remark=remark)
-
     def send_and_assert_encapped(self, tx, ip6_src, ip6_dst, dmac=None):
         if not dmac:
             dmac = self.pg1.remote_mac
index 9590519..aa5e674 100644 (file)
@@ -314,13 +314,6 @@ class TestMPLS(VppTestCase):
         except:
             raise
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.assert_nothing_captured(remark=remark)
-
     def test_swap(self):
         """ MPLS label swap tests """
 
@@ -1218,7 +1211,13 @@ class TestMPLS(VppTestCase):
         #
         tx = self.create_stream_labelled_ip6(self.pg0, [34], 255,
                                              dst_ip="ff01::1", hlim=1)
-        self.send_and_assert_no_replies(self.pg0, tx, "Hop Limt Expired")
+        self.pg0.add_stream(tx)
+
+        self.pg_enable_capture(self.pg_interfaces)
+        self.pg_start()
+
+        rx = self.pg0.get_capture(257)
+        self.verify_capture_ip6_icmp(self.pg0, rx, tx)
 
         #
         # set the RPF-ID of the enrtry to not match the input packet's
@@ -1258,14 +1257,6 @@ class TestMPLSDisabled(VppTestCase):
         self.pg0.disable_mpls()
         super(TestMPLSDisabled, self).tearDown()
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        for i in self.pg_interfaces:
-            i.get_capture(0)
-            i.assert_nothing_captured(remark=remark)
-
     def test_mpls_disabled(self):
         """ MPLS Disabled """
 
index 565a8b4..47e9c5b 100644 (file)
@@ -132,16 +132,6 @@ class ARPTestCase(VppTestCase):
         self.assertEqual(ip.src, sip)
         self.assertEqual(ip.dst, dip)
 
-    def send_and_assert_no_replies(self, intf, pkts, remark):
-        intf.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        timeout = 1
-        for i in self.pg_interfaces:
-            i.get_capture(0, timeout=timeout)
-            i.assert_nothing_captured(remark=remark)
-            timeout = 0.1
-
     def test_arp(self):
         """ ARP """
 
index 7853ac3..68b023c 100644 (file)
@@ -79,14 +79,6 @@ class TestUdpEncap(VppTestCase):
         self.assertEqual(rx.dst, tx[IPv6].dst)
         self.assertEqual(rx.hlim, tx[IPv6].hlim)
 
-    def send_and_expect(self, input, output, pkts):
-        self.vapi.cli("clear trace")
-        input.add_stream(pkts)
-        self.pg_enable_capture(self.pg_interfaces)
-        self.pg_start()
-        rx = output.get_capture(len(pkts))
-        return rx
-
     def test_udp_encap(self):
         """ UDP Encap test
         """
@@ -159,7 +151,7 @@ class TestUdpEncap(VppTestCase):
                  IP(src="2.2.2.2", dst="1.1.0.1") /
                  UDP(sport=1234, dport=1234) /
                  Raw('\xa5' * 100))
-        rx = self.send_and_expect(self.pg0, self.pg0, p_4o4*65)
+        rx = self.send_and_expect(self.pg0, p_4o4*65, self.pg0)
         for p in rx:
             self.validate_outer4(p, udp_encap_0)
             p = IP(p["UDP"].payload.load)
@@ -173,7 +165,7 @@ class TestUdpEncap(VppTestCase):
                  IP(src="2.2.2.2", dst="1.1.2.1") /
                  UDP(sport=1234, dport=1234) /
                  Raw('\xa5' * 100))
-        rx = self.send_and_expect(self.pg0, self.pg2, p_4o6*65)
+        rx = self.send_and_expect(self.pg0, p_4o6*65, self.pg2)
         for p in rx:
             self.validate_outer6(p, udp_encap_2)
             p = IP(p["UDP"].payload.load)
@@ -187,7 +179,7 @@ class TestUdpEncap(VppTestCase):
                  IPv6(src="2001::100", dst="2001::1") /
                  UDP(sport=1234, dport=1234) /
                  Raw('\xa5' * 100))
-        rx = self.send_and_expect(self.pg0, self.pg1, p_6o4*65)
+        rx = self.send_and_expect(self.pg0, p_6o4*65, self.pg1)
         for p in rx:
             self.validate_outer4(p, udp_encap_1)
             p = IPv6(p["UDP"].payload.load)
@@ -201,7 +193,7 @@ class TestUdpEncap(VppTestCase):
                  IPv6(src="2001::100", dst="2001::3") /
                  UDP(sport=1234, dport=1234) /
                  Raw('\xa5' * 100))
-        rx = self.send_and_expect(self.pg0, self.pg3, p_6o6*65)
+        rx = self.send_and_expect(self.pg0, p_6o6*65, self.pg3)
         for p in rx:
             self.validate_outer6(p, udp_encap_3)
             p = IPv6(p["UDP"].payload.load)
@@ -224,7 +216,7 @@ class TestUdpEncap(VppTestCase):
                    IP(src="2.2.2.2", dst="1.1.2.22") /
                    UDP(sport=1234, dport=1234) /
                    Raw('\xa5' * 100))
-        rx = self.send_and_expect(self.pg0, self.pg1, p_4omo4*65)
+        rx = self.send_and_expect(self.pg0, p_4omo4*65, self.pg1)
         for p in rx:
             self.validate_outer4(p, udp_encap_1)
             p = MPLS(p["UDP"].payload.load)