tests: move ip6 punt setup to its own class 91/30891/2
authorBrian Russell <brian@graphiant.com>
Tue, 19 Jan 2021 16:58:14 +0000 (16:58 +0000)
committerNeale Ranns <neale@graphiant.com>
Thu, 28 Jan 2021 10:27:52 +0000 (10:27 +0000)
Move interface and packet setup for the ip6 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: I14acedc1bcd12cb320835a36833cd32303c5f793

test/test_ip6.py

index 1b3b9d0..a9244bd 100644 (file)
@@ -2179,20 +2179,10 @@ class TestIP6LoadBalance(VppTestCase):
         self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
 
 
-class TestIP6Punt(VppTestCase):
-    """ IPv6 Punt Police/Redirect """
-
-    @classmethod
-    def setUpClass(cls):
-        super(TestIP6Punt, cls).setUpClass()
-
-    @classmethod
-    def tearDownClass(cls):
-        super(TestIP6Punt, cls).tearDownClass()
-
-    def setUp(self):
-        super(TestIP6Punt, self).setUp()
+class IP6PuntSetup(object):
+    """ Setup for IPv6 Punt Police/Redirect """
 
+    def punt_setup(self):
         self.create_pg_interfaces(range(4))
 
         for i in self.pg_interfaces:
@@ -2200,23 +2190,34 @@ class TestIP6Punt(VppTestCase):
             i.config_ip6()
             i.resolve_ndp()
 
-    def tearDown(self):
-        super(TestIP6Punt, self).tearDown()
+        self.pkt = (Ether(src=self.pg0.remote_mac,
+                          dst=self.pg0.local_mac) /
+                    IPv6(src=self.pg0.remote_ip6,
+                         dst=self.pg0.local_ip6) /
+                    inet6.TCP(sport=1234, dport=1234) /
+                    Raw(b'\xa5' * 100))
+
+    def punt_teardown(self):
         for i in self.pg_interfaces:
             i.unconfig_ip6()
             i.admin_down()
 
+
+class TestIP6Punt(IP6PuntSetup, VppTestCase):
+    """ IPv6 Punt Police/Redirect """
+
+    def setUp(self):
+        super(TestIP6Punt, self).setUp()
+        super(TestIP6Punt, self).punt_setup()
+
+    def tearDown(self):
+        super(TestIP6Punt, self).punt_teardown()
+        super(TestIP6Punt, self).tearDown()
+
     def test_ip_punt(self):
         """ IP6 punt police and redirect """
 
-        p = (Ether(src=self.pg0.remote_mac,
-                   dst=self.pg0.local_mac) /
-             IPv6(src=self.pg0.remote_ip6,
-                  dst=self.pg0.local_ip6) /
-             inet6.TCP(sport=1234, dport=1234) /
-             Raw(b'\xa5' * 100))
-
-        pkts = p * 1025
+        pkts = self.pkt * 1025
 
         #
         # Configure a punt redirect via pg1.