Tests: Refactor tearDown show command logging, add lifecycle markers.
[vpp.git] / test / test_ip4.py
index 8282d13..ed7a565 100644 (file)
@@ -17,12 +17,19 @@ from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpMRoute, \
     VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
     VppMplsTable, VppIpTable
 from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint
-from vpp_ip import VppIpPrefix
 
 
 class TestIPv4(VppTestCase):
     """ IPv4 Test Case """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPv4, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPv4, cls).tearDownClass()
+
     def setUp(self):
         """
         Perform test setup before test case.
@@ -75,9 +82,10 @@ class TestIPv4(VppTestCase):
     def tearDown(self):
         """Run standard test teardown and log ``show ip arp``."""
         super(TestIPv4, self).tearDown()
-        if not self.vpp_dead:
-            self.logger.info(self.vapi.cli("show ip arp"))
-            # info(self.vapi.cli("show ip fib"))  # many entries
+
+    def show_commands_at_teardown(self):
+        self.logger.info(self.vapi.cli("show ip arp"))
+        # info(self.vapi.cli("show ip fib"))  # many entries
 
     def config_fib_entries(self, count):
         """For each interface add to the FIB table *count* routes to
@@ -230,6 +238,14 @@ class TestIPv4(VppTestCase):
 class TestICMPEcho(VppTestCase):
     """ ICMP Echo Test Case """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestICMPEcho, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestICMPEcho, cls).tearDownClass()
+
     def setUp(self):
         super(TestICMPEcho, self).setUp()
 
@@ -443,6 +459,10 @@ class TestIPv4FibCrud(VppTestCase):
             super(TestIPv4FibCrud, cls).tearDownClass()
             raise
 
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPv4FibCrud, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPv4FibCrud, self).setUp()
         self.reset_packet_infos()
@@ -569,6 +589,14 @@ class TestIPv4FibCrud(VppTestCase):
 class TestIPNull(VppTestCase):
     """ IPv4 routes via NULL """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPNull, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPNull, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPNull, self).setUp()
 
@@ -675,6 +703,14 @@ class TestIPNull(VppTestCase):
 class TestIPDisabled(VppTestCase):
     """ IPv4 disabled """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPDisabled, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPDisabled, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPDisabled, self).setUp()
 
@@ -763,13 +799,21 @@ class TestIPDisabled(VppTestCase):
 class TestIPSubNets(VppTestCase):
     """ IPv4 Subnets """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPSubNets, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPSubNets, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPSubNets, self).setUp()
 
         # create a 2 pg interfaces
         self.create_pg_interfaces(range(2))
 
-        # pg0 we will use to experiemnt
+        # pg0 we will use to experiment
         self.pg0.admin_up()
 
         # pg1 is setup normally
@@ -811,8 +855,8 @@ class TestIPSubNets(VppTestCase):
         ip_addr_n = socket.inet_pton(socket.AF_INET, "10.10.10.10")
 
         self.vapi.sw_interface_add_del_address(
-            sw_if_index=self.pg0.sw_if_index,
-            prefix=VppIpPrefix("10.10.10.10", 16).encode())
+            sw_if_index=self.pg0.sw_if_index, address=ip_addr_n,
+            address_length=16)
 
         pn = (Ether(src=self.pg1.remote_mac,
                     dst=self.pg1.local_mac) /
@@ -830,9 +874,8 @@ class TestIPSubNets(VppTestCase):
 
         # remove the sub-net and we are forwarding via the cover again
         self.vapi.sw_interface_add_del_address(
-            sw_if_index=self.pg0.sw_if_index,
-            prefix=VppIpPrefix("10.10.10.10", 16).encode(), is_add=0)
-
+            sw_if_index=self.pg0.sw_if_index, address=ip_addr_n,
+            address_length=16, is_add=0)
         self.pg1.add_stream(pn)
         self.pg_enable_capture(self.pg_interfaces)
         self.pg_start()
@@ -849,8 +892,8 @@ class TestIPSubNets(VppTestCase):
         ip_addr_n = socket.inet_pton(socket.AF_INET, "10.10.10.10")
 
         self.vapi.sw_interface_add_del_address(
-            sw_if_index=self.pg0.sw_if_index,
-            prefix=VppIpPrefix("10.10.10.10", 31).encode())
+            sw_if_index=self.pg0.sw_if_index, address=ip_addr_n,
+            address_length=31)
 
         pn = (Ether(src=self.pg1.remote_mac,
                     dst=self.pg1.local_mac) /
@@ -866,9 +909,8 @@ class TestIPSubNets(VppTestCase):
 
         # remove the sub-net and we are forwarding via the cover again
         self.vapi.sw_interface_add_del_address(
-            sw_if_index=self.pg0.sw_if_index,
-            prefix=VppIpPrefix("10.10.10.10", 31).encode(), is_add=0)
-
+            sw_if_index=self.pg0.sw_if_index, address=ip_addr_n,
+            address_length=31, is_add=0)
         self.pg1.add_stream(pn)
         self.pg_enable_capture(self.pg_interfaces)
         self.pg_start()
@@ -878,6 +920,14 @@ class TestIPSubNets(VppTestCase):
 class TestIPLoadBalance(VppTestCase):
     """ IPv4 Load-Balancing """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPLoadBalance, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPLoadBalance, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPLoadBalance, self).setUp()
 
@@ -970,7 +1020,7 @@ class TestIPLoadBalance(VppTestCase):
         #    src,dst
         # We are not going to ensure equal amounts of packets across each link,
         # since the hash algorithm is statistical and therefore this can never
-        # be guaranteed. But wuth 64 different packets we do expect some
+        # be guaranteed. But with 64 different packets we do expect some
         # balancing. So instead just ensure there is traffic on each link.
         #
         self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
@@ -1153,6 +1203,14 @@ class TestIPLoadBalance(VppTestCase):
 class TestIPVlan0(VppTestCase):
     """ IPv4 VLAN-0 """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPVlan0, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPVlan0, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPVlan0, self).setUp()
 
@@ -1194,6 +1252,14 @@ class TestIPVlan0(VppTestCase):
 class TestIPPunt(VppTestCase):
     """ IPv4 Punt Police/Redirect """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPPunt, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPPunt, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPPunt, self).setUp()
 
@@ -1244,7 +1310,7 @@ class TestIPPunt(VppTestCase):
         self.pg_start()
 
         #
-        # the number of packet recieved should be greater than 0,
+        # the number of packet received should be greater than 0,
         # but not equal to the number sent, since some were policed
         #
         rx = self.pg1._get_capture(1)
@@ -1252,7 +1318,7 @@ class TestIPPunt(VppTestCase):
         self.assertLess(len(rx), len(pkts))
 
         #
-        # remove the poilcer. back to full rx
+        # remove the policer. back to full rx
         #
         self.vapi.ip_punt_police(policer.policer_index, is_add=0)
         self.vapi.policer_add_del(b"ip4-punt", 400, 0, 10, 0,
@@ -1320,6 +1386,14 @@ class TestIPPunt(VppTestCase):
 class TestIPDeag(VppTestCase):
     """ IPv4 Deaggregate Routes """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPDeag, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPDeag, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPDeag, self).setUp()
 
@@ -1429,6 +1503,14 @@ class TestIPDeag(VppTestCase):
 class TestIPInput(VppTestCase):
     """ IPv4 Input Exceptions """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPInput, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPInput, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPInput, self).setUp()
 
@@ -1594,6 +1676,14 @@ class TestIPInput(VppTestCase):
 class TestIPDirectedBroadcast(VppTestCase):
     """ IPv4 Directed Broadcast """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPDirectedBroadcast, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPDirectedBroadcast, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPDirectedBroadcast, self).setUp()
 
@@ -1662,6 +1752,14 @@ class TestIPDirectedBroadcast(VppTestCase):
 class TestIPLPM(VppTestCase):
     """ IPv4 longest Prefix Match """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIPLPM, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPLPM, cls).tearDownClass()
+
     def setUp(self):
         super(TestIPLPM, self).setUp()
 
@@ -1725,6 +1823,10 @@ class TestIPv4Frag(VppTestCase):
             i.config_ip4()
             i.resolve_arp()
 
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIPv4Frag, cls).tearDownClass()
+
     def test_frag_large_packets(self):
         """ Fragmentation of large packets """