tests: allow not removing vpp objects after test
[vpp.git] / test / test_classify_l2_acl.py
index d9557ee..b130988 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """ Classifier-based L2 ACL Test Case HLD:
 """
 
 """ Classifier-based L2 ACL Test Case HLD:
 """
 
@@ -16,9 +16,10 @@ from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest
 from scapy.layers.inet6 import IPv6ExtHdrFragment
 from framework import VppTestCase, VppTestRunner
 from util import Host, ppp
 from scapy.layers.inet6 import IPv6ExtHdrFragment
 from framework import VppTestCase, VppTestRunner
 from util import Host, ppp
+from template_classifier import TestClassifier
 
 
 
 
-class TestClassifyAcl(VppTestCase):
+class TestClassifyAcl(TestClassifier):
     """ Classifier-based L2 input and output ACL Test Case """
 
     # traffic types
     """ Classifier-based L2 input and output ACL Test Case """
 
     # traffic types
@@ -88,6 +89,7 @@ class TestClassifyAcl(VppTestCase):
         variables and configure VPP.
         """
         super(TestClassifyAcl, cls).setUpClass()
         variables and configure VPP.
         """
         super(TestClassifyAcl, cls).setUpClass()
+        cls.af = None
 
         try:
             # Create 2 pg interfaces
 
         try:
             # Create 2 pg interfaces
@@ -105,8 +107,8 @@ class TestClassifyAcl(VppTestCase):
             cls.vapi.bridge_domain_add_del(bd_id=cls.bd_id, uu_flood=1,
                                            learn=1)
             for pg_if in cls.pg_interfaces:
             cls.vapi.bridge_domain_add_del(bd_id=cls.bd_id, uu_flood=1,
                                            learn=1)
             for pg_if in cls.pg_interfaces:
-                cls.vapi.sw_interface_set_l2_bridge(pg_if.sw_if_index,
-                                                    bd_id=cls.bd_id)
+                cls.vapi.sw_interface_set_l2_bridge(
+                    rx_sw_if_index=pg_if.sw_if_index, bd_id=cls.bd_id)
 
             # Set up all interfaces
             for i in cls.pg_interfaces:
 
             # Set up all interfaces
             for i in cls.pg_interfaces:
@@ -132,22 +134,19 @@ class TestClassifyAcl(VppTestCase):
             super(TestClassifyAcl, cls).tearDownClass()
             raise
 
             super(TestClassifyAcl, cls).tearDownClass()
             raise
 
+    @classmethod
+    def tearDownClass(cls):
+        super(TestClassifyAcl, cls).tearDownClass()
+
     def setUp(self):
         super(TestClassifyAcl, self).setUp()
     def setUp(self):
         super(TestClassifyAcl, self).setUp()
-
         self.acl_tbl_idx = {}
         self.acl_tbl_idx = {}
-        self.reset_packet_infos()
 
     def tearDown(self):
         """
         Show various debug prints after each test.
         """
         if not self.vpp_dead:
 
     def tearDown(self):
         """
         Show various debug prints after each test.
         """
         if not self.vpp_dead:
-            self.logger.info(self.vapi.ppcli("show inacl type l2"))
-            self.logger.info(self.vapi.ppcli("show outacl type l2"))
-            self.logger.info(self.vapi.ppcli("show classify tables verbose"))
-            self.logger.info(self.vapi.ppcli("show bridge-domain %s detail"
-                                             % self.bd_id))
             if self.acl_active_table == 'mac_inout':
                 self.output_acl_set_interface(
                     self.pg1, self.acl_tbl_idx.get(self.acl_active_table), 0)
             if self.acl_active_table == 'mac_inout':
                 self.output_acl_set_interface(
                     self.pg1, self.acl_tbl_idx.get(self.acl_active_table), 0)
@@ -165,53 +164,6 @@ class TestClassifyAcl(VppTestCase):
 
         super(TestClassifyAcl, self).tearDown()
 
 
         super(TestClassifyAcl, self).tearDown()
 
-    @staticmethod
-    def build_mac_mask(dst_mac='', src_mac='', ether_type=''):
-        """Build MAC ACL mask data with hexstring format
-
-        :param str dst_mac: source MAC address <0-ffffffffffff>
-        :param str src_mac: destination MAC address <0-ffffffffffff>
-        :param str ether_type: ethernet type <0-ffff>
-        """
-
-        return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
-                                              ether_type)).rstrip('0')
-
-    @staticmethod
-    def build_mac_match(dst_mac='', src_mac='', ether_type=''):
-        """Build MAC ACL match data with hexstring format
-
-        :param str dst_mac: source MAC address <x:x:x:x:x:x>
-        :param str src_mac: destination MAC address <x:x:x:x:x:x>
-        :param str ether_type: ethernet type <0-ffff>
-        """
-        if dst_mac:
-            dst_mac = dst_mac.replace(':', '')
-        if src_mac:
-            src_mac = src_mac.replace(':', '')
-
-        return ('{:0>12}{:0>12}{:0>4}'.format(dst_mac, src_mac,
-                                              ether_type)).rstrip('0')
-
-    def create_classify_table(self, key, mask, data_offset=0, is_add=1):
-        """Create Classify Table
-
-        :param str key: key for classify table (ex, ACL name).
-        :param str mask: mask value for interested traffic.
-        :param int match_n_vectors:
-        :param int is_add: option to configure classify table.
-            - create(1) or delete(0)
-        """
-        r = self.vapi.classify_add_del_table(
-            is_add,
-            binascii.unhexlify(mask),
-            match_n_vectors=(len(mask) - 1) // 32 + 1,
-            miss_next_index=0,
-            current_data_flag=1,
-            current_data_offset=data_offset)
-        self.assertIsNotNone(r, msg='No response msg for add_del_table')
-        self.acl_tbl_idx[key] = r.new_table_index
-
     def create_classify_session(self, intf, table_index, match,
                                 hit_next_index=0xffffffff, is_add=1):
         """Create Classify Session
     def create_classify_session(self, intf, table_index, match,
                                 hit_next_index=0xffffffff, is_add=1):
         """Create Classify Session
@@ -219,45 +171,17 @@ class TestClassifyAcl(VppTestCase):
         :param VppInterface intf: Interface to apply classify session.
         :param int table_index: table index to identify classify table.
         :param str match: matched value for interested traffic.
         :param VppInterface intf: Interface to apply classify session.
         :param int table_index: table index to identify classify table.
         :param str match: matched value for interested traffic.
-        :param int pbr_action: enable/disable PBR feature.
-        :param int vrfid: VRF id.
         :param int is_add: option to configure classify session.
             - create(1) or delete(0)
         """
         :param int is_add: option to configure classify session.
             - create(1) or delete(0)
         """
+        mask_match, mask_match_len = self._resolve_mask_match(match)
         r = self.vapi.classify_add_del_session(
         r = self.vapi.classify_add_del_session(
-            is_add,
-            table_index,
-            binascii.unhexlify(match),
+            is_add=is_add,
+            table_index=table_index,
+            match=mask_match,
+            match_len=mask_match_len,
             hit_next_index=hit_next_index)
             hit_next_index=hit_next_index)
-        self.assertIsNotNone(r, msg='No response msg for add_del_session')
-
-    def input_acl_set_interface(self, intf, table_index, is_add=1):
-        """Configure Input ACL interface
-
-        :param VppInterface intf: Interface to apply Input ACL feature.
-        :param int table_index: table index to identify classify table.
-        :param int is_add: option to configure classify session.
-            - enable(1) or disable(0)
-        """
-        r = self.vapi.input_acl_set_interface(
-            is_add,
-            intf.sw_if_index,
-            l2_table_index=table_index)
-        self.assertIsNotNone(r, msg='No response msg for acl_set_interface')
-
-    def output_acl_set_interface(self, intf, table_index, is_add=1):
-        """Configure Output ACL interface
-
-        :param VppInterface intf: Interface to apply Output ACL feature.
-        :param int table_index: table index to identify classify table.
-        :param int is_add: option to configure classify session.
-            - enable(1) or disable(0)
-        """
-        r = self.vapi.output_acl_set_interface(
-            is_add,
-            intf.sw_if_index,
-            l2_table_index=table_index)
-        self.assertIsNotNone(r, msg='No response msg for acl_set_interface')
+        self.assertIsNotNone(r, 'No response msg for add_del_session')
 
     def create_hosts(self, count, start=0):
         """
 
     def create_hosts(self, count, start=0):
         """
@@ -268,7 +192,7 @@ class TestClassifyAcl(VppTestCase):
         :param int start: Number to start numbering from.
         """
         n_int = len(self.pg_interfaces)
         :param int start: Number to start numbering from.
         """
         n_int = len(self.pg_interfaces)
-        macs_per_if = count / n_int
+        macs_per_if = count // n_int
         i = -1
         for pg_if in self.pg_interfaces:
             i += 1
         i = -1
         for pg_if in self.pg_interfaces:
             i += 1
@@ -322,7 +246,7 @@ class TestClassifyAcl(VppTestCase):
                 dst_hosts = self.hosts_by_pg_idx[dst_if.sw_if_index]
                 n_int = len(dst_hosts) * len(src_hosts)
                 for i in range(0, n_int):
                 dst_hosts = self.hosts_by_pg_idx[dst_if.sw_if_index]
                 n_int = len(dst_hosts) * len(src_hosts)
                 for i in range(0, n_int):
-                    dst_host = dst_hosts[i / len(src_hosts)]
+                    dst_host = dst_hosts[i // len(src_hosts)]
                     src_host = src_hosts[i % len(src_hosts)]
                     pkt_info = self.create_packet_info(src_if, dst_if)
                     if ipv6 == 1:
                     src_host = src_hosts[i % len(src_hosts)]
                     pkt_info = self.create_packet_info(src_if, dst_if)
                     if ipv6 == 1:
@@ -396,7 +320,7 @@ class TestClassifyAcl(VppTestCase):
                         packet[ICMPv6EchoRequest].data)
                     payload = packet[ICMPv6EchoRequest]
                 else:
                         packet[ICMPv6EchoRequest].data)
                     payload = packet[ICMPv6EchoRequest]
                 else:
-                    payload_info = self.payload_to_info(str(packet[Raw]))
+                    payload_info = self.payload_to_info(packet[Raw])
                     payload = packet[self.proto_map[payload_info.proto]]
             except:
                 self.logger.error(ppp("Unexpected or invalid packet "
                     payload = packet[self.proto_map[payload_info.proto]]
             except:
                 self.logger.error(ppp("Unexpected or invalid packet "
@@ -679,5 +603,6 @@ class TestClassifyAcl(VppTestCase):
         self.acl_active_table = key
         self.run_verify_test(self.IP, self.IPV4, -1)
 
         self.acl_active_table = key
         self.run_verify_test(self.IP, self.IPV4, -1)
 
+
 if __name__ == '__main__':
     unittest.main(testRunner=VppTestRunner)
 if __name__ == '__main__':
     unittest.main(testRunner=VppTestRunner)