tests: move ip4 punt setup to its own class 89/30889/2
authorBrian Russell <brian@graphiant.com>
Tue, 19 Jan 2021 16:56:32 +0000 (16:56 +0000)
committerNeale Ranns <neale@graphiant.com>
Thu, 28 Jan 2021 10:27:32 +0000 (10:27 +0000)
Move interface and packet setup for the ip4 punt test to its own
class so that child classes can be created that use it.

Type: test
Signed-off-by: Brian Russell <brian@graphiant.com>
Change-Id: I1a976e8fc0e8a44a86fe923a3ae093fe0c9057a8

test/test_ip4.py

index 589c668..6edb9e8 100644 (file)
@@ -1448,20 +1448,10 @@ class TestIPVlan0(VppTestCase):
         self.send_and_expect(self.pg0, pkts, self.pg1)
 
 
-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()
+class IPPuntSetup(object):
+    """ Setup for IPv4 Punt Police/Redirect """
 
+    def punt_setup(self):
         self.create_pg_interfaces(range(4))
 
         for i in self.pg_interfaces:
@@ -1469,15 +1459,6 @@ class TestIPPunt(VppTestCase):
             i.config_ip4()
             i.resolve_arp()
 
-    def tearDown(self):
-        super(TestIPPunt, self).tearDown()
-        for i in self.pg_interfaces:
-            i.unconfig_ip4()
-            i.admin_down()
-
-    def test_ip_punt(self):
-        """ IP punt police and redirect """
-
         # use UDP packet that have a port we need to explicitly
         # register to get punted.
         pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4
@@ -1496,13 +1477,33 @@ class TestIPPunt(VppTestCase):
 
         self.vapi.set_punt(is_add=1, punt=punt_udp)
 
-        p = (Ether(src=self.pg0.remote_mac,
-                   dst=self.pg0.local_mac) /
-             IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
-             UDP(sport=1234, dport=1234) /
-             Raw(b'\xa5' * 100))
+        self.pkt = (Ether(src=self.pg0.remote_mac,
+                          dst=self.pg0.local_mac) /
+                    IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
+                    UDP(sport=1234, dport=1234) /
+                    Raw(b'\xa5' * 100))
+
+    def punt_teardown(self):
+        for i in self.pg_interfaces:
+            i.unconfig_ip4()
+            i.admin_down()
+
+
+class TestIPPunt(IPPuntSetup, VppTestCase):
+    """ IPv4 Punt Police/Redirect """
+
+    def setUp(self):
+        super(TestIPPunt, self).setUp()
+        super(TestIPPunt, self).punt_setup()
+
+    def tearDown(self):
+        super(TestIPPunt, self).punt_teardown()
+        super(TestIPPunt, self).tearDown()
+
+    def test_ip_punt(self):
+        """ IP punt police and redirect """
 
-        pkts = p * 1025
+        pkts = self.pkt * 1025
 
         #
         # Configure a punt redirect via pg1.