acl: API cleanup
[vpp.git] / src / plugins / abf / test / test_abf.py
index 221a793..097476b 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
 import unittest
 
 from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
 import unittest
@@ -7,11 +7,13 @@ from framework import VppTestCase, VppTestRunner
 from vpp_ip import DpoProto
 from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsLabel, \
     VppIpTable, FibPathProto
 from vpp_ip import DpoProto
 from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsLabel, \
     VppIpTable, FibPathProto
+from vpp_acl import AclRule, VppAcl
 
 from scapy.packet import Raw
 from scapy.layers.l2 import Ether
 from scapy.layers.inet import IP, UDP
 from scapy.layers.inet6 import IPv6
 
 from scapy.packet import Raw
 from scapy.layers.l2 import Ether
 from scapy.layers.inet import IP, UDP
 from scapy.layers.inet6 import IPv6
+from ipaddress import IPv4Network, IPv6Network
 
 from vpp_object import VppObject
 
 
 from vpp_object import VppObject
 
@@ -141,7 +143,6 @@ class TestAbf(VppTestCase):
         for i in self.pg_interfaces:
             i.unconfig_ip4()
             i.unconfig_ip6()
         for i in self.pg_interfaces:
             i.unconfig_ip4()
             i.unconfig_ip6()
-            i.ip6_disable()
             i.admin_down()
         super(TestAbf, self).tearDown()
 
             i.admin_down()
         super(TestAbf, self).tearDown()
 
@@ -162,18 +163,11 @@ class TestAbf(VppTestCase):
         #
         # Rule 1
         #
         #
         # Rule 1
         #
-        rule_1 = ({'is_permit': 1,
-                   'is_ipv6': 0,
-                   'proto': 17,
-                   'srcport_or_icmptype_first': 1234,
-                   'srcport_or_icmptype_last': 1234,
-                   'src_ip_prefix_len': 32,
-                   'src_ip_addr': inet_pton(AF_INET, "1.1.1.1"),
-                   'dstport_or_icmpcode_first': 1234,
-                   'dstport_or_icmpcode_last': 1234,
-                   'dst_ip_prefix_len': 32,
-                   'dst_ip_addr': inet_pton(AF_INET, "1.1.1.2")})
-        acl_1 = self.vapi.acl_add_replace(acl_index=4294967295, r=[rule_1])
+        rule_1 = AclRule(is_permit=1, proto=17, ports=1234,
+                         src_prefix=IPv4Network("1.1.1.1/32"),
+                         dst_prefix=IPv4Network("1.1.1.2/32"))
+        acl_1 = VppAcl(self, rules=[rule_1])
+        acl_1.add_vpp_config()
 
         #
         # ABF policy for ACL 1 - path via interface 1
 
         #
         # ABF policy for ACL 1 - path via interface 1
@@ -197,7 +191,7 @@ class TestAbf(VppTestCase):
                      dst=self.pg0.local_mac) /
                IP(src="1.1.1.1", dst="1.1.1.2") /
                UDP(sport=1234, dport=1234) /
                      dst=self.pg0.local_mac) /
                IP(src="1.1.1.1", dst="1.1.1.2") /
                UDP(sport=1234, dport=1234) /
-               Raw('\xa5' * 100))
+               Raw(b'\xa5' * 100))
         self.send_and_expect(self.pg0, p_1*NUM_PKTS, self.pg1)
 
         #
         self.send_and_expect(self.pg0, p_1*NUM_PKTS, self.pg1)
 
         #
@@ -240,7 +234,7 @@ class TestAbf(VppTestCase):
                      dst=self.pg1.local_mac) /
                IP(src="1.1.1.1", dst="1.1.1.2") /
                UDP(sport=1234, dport=1234) /
                      dst=self.pg1.local_mac) /
                IP(src="1.1.1.1", dst="1.1.1.2") /
                UDP(sport=1234, dport=1234) /
-               Raw('\xa5' * 100))
+               Raw(b'\xa5' * 100))
         self.send_and_expect(self.pg1, p_2 * NUM_PKTS, self.pg3)
 
         #
         self.send_and_expect(self.pg1, p_2 * NUM_PKTS, self.pg3)
 
         #
@@ -285,19 +279,11 @@ class TestAbf(VppTestCase):
         #
         # Rule 1
         #
         #
         # Rule 1
         #
-        rule_1 = ({'is_permit': 1,
-                   'is_ipv6': 1,
-                   'proto': 17,
-                   'srcport_or_icmptype_first': 1234,
-                   'srcport_or_icmptype_last': 1234,
-                   'src_ip_prefix_len': 128,
-                   'src_ip_addr': inet_pton(AF_INET6, "2001::2"),
-                   'dstport_or_icmpcode_first': 1234,
-                   'dstport_or_icmpcode_last': 1234,
-                   'dst_ip_prefix_len': 128,
-                   'dst_ip_addr': inet_pton(AF_INET6, "2001::1")})
-        acl_1 = self.vapi.acl_add_replace(acl_index=4294967295,
-                                          r=[rule_1])
+        rule_1 = AclRule(is_permit=1, proto=17, ports=1234,
+                         src_prefix=IPv6Network("2001::2/128"),
+                         dst_prefix=IPv6Network("2001::1/128"))
+        acl_1 = VppAcl(self, rules=[rule_1])
+        acl_1.add_vpp_config()
 
         #
         # ABF policy for ACL 1 - path via interface 1
 
         #
         # ABF policy for ACL 1 - path via interface 1
@@ -318,7 +304,7 @@ class TestAbf(VppTestCase):
                    dst=self.pg0.local_mac) /
              IPv6(src="2001::2", dst="2001::1") /
              UDP(sport=1234, dport=1234) /
                    dst=self.pg0.local_mac) /
              IPv6(src="2001::2", dst="2001::1") /
              UDP(sport=1234, dport=1234) /
-             Raw('\xa5' * 100))
+             Raw(b'\xa5' * 100))
 
         #
         # packets are dropped because there is no route to the policy's
 
         #
         # packets are dropped because there is no route to the policy's