X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_acl_plugin_macip.py;h=d2d684abc11288971ab95a443e7f321d754759f6;hb=ea2450fa2d1e8ba0295ea9861a404796100dad1e;hp=8bcef25c49a77129996e442985df638a7753b42e;hpb=b9ef2739dd1e681143e78ada1ffc342ae2fb89b0;p=vpp.git diff --git a/test/test_acl_plugin_macip.py b/test/test_acl_plugin_macip.py index 8bcef25c49a..d2d684abc11 100644 --- a/test/test_acl_plugin_macip.py +++ b/test/test_acl_plugin_macip.py @@ -1,12 +1,14 @@ #!/usr/bin/env python +from __future__ import print_function """ACL plugin - MACIP tests """ +import binascii import random +from socket import inet_ntop, inet_pton, AF_INET, AF_INET6 +from struct import pack, unpack import re import unittest -from socket import inet_ntop, inet_pton, AF_INET, AF_INET6 -from struct import * from scapy.packet import Raw from scapy.layers.l2 import Ether from scapy.layers.inet import IP, UDP @@ -16,6 +18,7 @@ from framework import VppTestCase, VppTestRunner, running_extended_tests from vpp_lo_interface import VppLoInterface from vpp_papi_provider import L2_VTR_OP from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint +from vpp_papi_provider import L2_PORT_TYPE class MethodHolder(VppTestCase): @@ -90,7 +93,8 @@ class MethodHolder(VppTestCase): # Create BD with MAC learning enabled and put interfaces to this BD cls.vapi.sw_interface_set_l2_bridge( - cls.loop0.sw_if_index, bd_id=cls.bd_id, bvi=1) + cls.loop0.sw_if_index, bd_id=cls.bd_id, + port_type=L2_PORT_TYPE.BVI) cls.vapi.sw_interface_set_l2_bridge( cls.pg0.sw_if_index, bd_id=cls.bd_id) cls.vapi.sw_interface_set_l2_bridge( @@ -142,7 +146,7 @@ class MethodHolder(VppTestCase): cls.subifs[3].remote_hosts = cls.loop0.remote_hosts[175:] except Exception: - super(TestMACIP, cls).tearDownClass() + super(MethodHolder, cls).tearDownClass() raise def setUp(self): @@ -164,29 +168,29 @@ class MethodHolder(VppTestCase): self.logger.info(self.vapi.ppcli("sh acl-plugin acl")) self.logger.info(self.vapi.ppcli("sh acl-plugin interface")) self.logger.info(self.vapi.ppcli("sh acl-plugin tables")) - # print self.vapi.ppcli("show interface address") - # print self.vapi.ppcli("show hardware") - # print self.vapi.ppcli("sh acl-plugin macip interface") - # print self.vapi.ppcli("sh acl-plugin macip acl") + # print(self.vapi.ppcli("show interface address")) + # print(self.vapi.ppcli("show hardware")) + # print(self.vapi.ppcli("sh acl-plugin macip interface")) + # print(self.vapi.ppcli("sh acl-plugin macip acl")) self.delete_acls() def macip_acl_dump_debug(self): acls = self.vapi.macip_acl_dump() if self.DEBUG: for acl in acls: - print "ACL #"+str(acl.acl_index) + print("ACL #"+str(acl.acl_index)) for r in acl.r: rule = "ACTION" if r.is_permit == 1: rule = "PERMIT" elif r.is_permit == 0: rule = "DENY " - print " IP6" if r.is_ipv6 else " IP4", \ - rule, \ - r.src_mac.encode('hex'), \ - r.src_mac_mask.encode('hex'),\ - unpack('<16B', r.src_ip_addr), \ - r.src_ip_prefix_len + print(" IP6" if r.is_ipv6 else " IP4", + rule, + binascii.hexlify(r.src_mac), + binascii.hexlify(r.src_mac_mask), + unpack('<16B', r.src_ip_addr), + r.src_ip_prefix_len) return acls def create_rules(self, mac_type=EXACT_MAC, ip_type=EXACT_IP, @@ -233,7 +237,8 @@ class MethodHolder(VppTestCase): mac = ':'.join(re.findall('..', '{:02x}'.format( src_mac))[:3])+":00:00:00" else: - mac = ':'.join(re.findall('..', '{:02x}'.format(src_mac))) + mac = ':'.join(re.findall( + '..', '{:02x}'.format(src_mac))) if ip_type == self.EXACT_IP: ip4[3] = random.randint(100, 200) @@ -566,22 +571,22 @@ class MethodHolder(VppTestCase): # p_l3 = IPv6 if is_ip6 else IP # if self.DEBUG: # for p in stream: - # print p[Ether].src, p[Ether].dst, p[p_l3].src, p[p_l3].dst + # print(p[Ether].src, p[Ether].dst, p[p_l3].src, p[p_l3].dst) # # acls = self.macip_acl_dump_debug() # TODO : verify # for acl in acls: # for r in acl.r: - # print r.src_mac.encode('hex'), \ - # r.src_mac_mask.encode('hex'),\ + # print(binascii.hexlify(r.src_mac), \ + # binascii.hexlify(r.src_mac_mask),\ # unpack('<16B', r.src_ip_addr), \ - # r.src_ip_prefix_len + # r.src_ip_prefix_len) # # for p in capture: - # print p[Ether].src, p[Ether].dst, p[p_l3].src, p[p_l3].dst - # data = p[Raw].load.split(':',1)[1] - # print p[p_l3].src, data + # print(p[Ether].src, p[Ether].dst, p[p_l3].src, p[p_l3].dst + # data = p[Raw].load.split(':',1)[1]) + # print(p[p_l3].src, data) def run_traffic(self, mac_type, ip_type, traffic, is_ip6, packets, do_not_expected_capture=False, tags=None, @@ -1080,8 +1085,8 @@ class TestMACIP(MethodHolder): self.apply_macip_rules(self.create_rules(acl_count=3, rules_count=[3, 5, 4])) - intf.append(VppLoInterface(self, 0)) - intf.append(VppLoInterface(self, 1)) + intf.append(VppLoInterface(self)) + intf.append(VppLoInterface(self)) sw_if_index0 = intf[0].sw_if_index self.vapi.macip_acl_interface_add_del(sw_if_index0, 1) @@ -1103,8 +1108,8 @@ class TestMACIP(MethodHolder): self.assertEqual(reply.acls[sw_if_index0], 4294967295) self.assertEqual(reply.acls[sw_if_index1], 0) - intf.append(VppLoInterface(self, 2)) - intf.append(VppLoInterface(self, 3)) + intf.append(VppLoInterface(self)) + intf.append(VppLoInterface(self)) sw_if_index2 = intf[2].sw_if_index sw_if_index3 = intf[3].sw_if_index self.vapi.macip_acl_interface_add_del(sw_if_index2, 1)