#!/usr/bin/env python3
from __future__ import print_function

"""ACL plugin - MACIP tests
"""
import random
from socket import inet_ntop, inet_pton, AF_INET, AF_INET6
from struct import pack, unpack
import re
import unittest
from ipaddress import ip_network, IPv4Network, IPv6Network
from config import config

import scapy.compat
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 framework import VppTestCase
from asfframework import VppTestRunner
from vpp_lo_interface import VppLoInterface
from vpp_l2 import L2_PORT_TYPE
from vpp_sub_interface import (
    L2_VTR_OP,
    VppSubInterface,
    VppDot1QSubint,
    VppDot1ADSubint,
)
from vpp_acl import (
    AclRule,
    VppAcl,
    VppAclInterface,
    VppMacipAclInterface,
    VppMacipAcl,
    MacipRule,
)
from vpp_papi import MACAddress


@unittest.skipIf("acl" in config.excluded_plugins, "Exclude ACL plugin tests")
class MethodHolder(VppTestCase):
    DEBUG = False

    BRIDGED = True
    ROUTED = False

    IS_IP4 = False
    IS_IP6 = True

    DOT1AD = "dot1ad"
    DOT1Q = "dot1q"
    PERMIT_TAGS = True
    DENY_TAGS = False

    # rule types
    DENY = 0
    PERMIT = 1

    # ACL types
    EXACT_IP = 1
    SUBNET_IP = 2
    WILD_IP = 3

    EXACT_MAC = 1
    WILD_MAC = 2
    OUI_MAC = 3

    ACLS = []

    @classmethod
    def setUpClass(cls):
        """
        Perform standard class setup (defined by class method setUpClass in
        class VppTestCase) before running the test case, set test case related
        variables and configure VPP.
        """
        super(MethodHolder, cls).setUpClass()

        cls.pg_if_packet_sizes = [64, 512, 1518, 9018]  # packet sizes
        cls.bd_id = 111
        cls.remote_hosts_count = 200

        try:
            # create 4 pg interfaces, 1 loopback interface
            cls.create_pg_interfaces(range(4))
            cls.create_loopback_interfaces(1)

            # create 2 subinterfaces
            cls.subifs = [
                VppDot1QSubint(cls, cls.pg1, 10),
                VppDot1ADSubint(cls, cls.pg2, 20, 300, 400),
                VppDot1QSubint(cls, cls.pg3, 30),
                VppDot1ADSubint(cls, cls.pg3, 40, 600, 700),
            ]

            cls.subifs[0].set_vtr(L2_VTR_OP.L2_POP_1, inner=10, push1q=1)
            cls.subifs[1].set_vtr(L2_VTR_OP.L2_POP_2, outer=300, inner=400, push1q=1)
            cls.subifs[2].set_vtr(L2_VTR_OP.L2_POP_1, inner=30, push1q=1)
            cls.subifs[3].set_vtr(L2_VTR_OP.L2_POP_2, outer=600, inner=700, push1q=1)

            cls.interfaces = list(cls.pg_interfaces)
            cls.interfaces.extend(cls.lo_interfaces)
            cls.interfaces.extend(cls.subifs)

            for i in cls.interfaces:
                i.admin_up()

            # Create BD with MAC learning enabled and put interfaces to this BD
            cls.vapi.sw_interface_set_l2_bridge(
                rx_sw_if_index=cls.loop0.sw_if_index,
                bd_id=cls.bd_id,
                port_type=L2_PORT_TYPE.BVI,
            )
            cls.vapi.sw_interface_set_l2_bridge(
                rx_sw_if_index=cls.pg0.sw_if_index, bd_id=cls.bd_id
            )
            cls.vapi.sw_interface_set_l2_bridge(
                rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.bd_id
            )
            cls.vapi.sw_interface_set_l2_bridge(
                rx_sw_if_index=cls.subifs[0].sw_if_index, bd_id=cls.bd_id
            )
            cls.vapi.sw_interface_set_l2_bridge(
                rx_sw_if_index=cls.subifs[1].sw_if_index, bd_id=cls.bd_id
            )

            # Configure IPv4/6 addresses on loop interface and routed interface
            cls.loop0.config_ip4()
            cls.loop0.config_ip6()
            cls.pg2.config_ip4()
            cls.pg2.config_ip6()
            cls.pg3.config_ip4()
            cls.pg3.config_ip6()

            # Configure MAC address binding to IPv4 neighbors on loop0
            cls.loop0.generate_remote_hosts(cls.remote_hosts_count)
            # Modify host mac addresses to have different OUI parts
            for i in range(2, cls.remote_hosts_count + 2):
                mac = cls.loop0.remote_hosts[i - 2]._mac.split(":")
                mac[2] = format(int(mac[2], 16) + i, "02x")
                cls.loop0.remote_hosts[i - 2]._mac = ":".join(mac)

            cls.loop0.configure_ipv4_neighbors()
            cls.loop0.configure_ipv6_neighbors()

            # configure MAC address on pg3
            cls.pg3.resolve_arp()
            cls.pg3.resolve_ndp()

            # configure MAC address on subifs
            for i in cls.subifs:
                i.config_ip4()
                i.resolve_arp()
                i.config_ip6()

            # configure MAC address on pg2
            cls.pg2.resolve_arp()
            cls.pg2.resolve_ndp()

            # Loopback BVI interface has remote hosts
            # one half of hosts are behind pg0 second behind pg1,pg2,pg3 subifs
            cls.pg0.remote_hosts = cls.loop0.remote_hosts[:100]
            cls.subifs[0].remote_hosts = cls.loop0.remote_hosts[100:125]
            cls.subifs[1].remote_hosts = cls.loop0.remote_hosts[125:150]
            cls.subifs[2].remote_hosts = cls.loop0.remote_hosts[150:175]
            cls.subifs[3].remote_hosts = cls.loop0.remote_hosts[175:]

        except Exception:
            super(MethodHolder, cls).tearDownClass()
            raise

    @classmethod
    def tearDownClass(cls):
        super(MethodHolder, cls).tearDownClass()

    def setUp(self):
        super(MethodHolder, self).setUp()
        self.reset_packet_infos()

    def show_commands_at_teardown(self):
        self.logger.info(self.vapi.ppcli("show interface address"))
        self.logger.info(self.vapi.ppcli("show hardware"))
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl"))
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip interface"))
        self.logger.info(self.vapi.ppcli("sh classify tables verbose"))
        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"))

    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))
                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,
                          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, acl_count=1, rules_count=None
    ):
        acls = []
        if rules_count is None:
            rules_count = [1]
        src_mac = int("220000dead00", 16)
        for acl in range(2, (acl_count + 1) * 2):
            rules = []
            host = random.choice(self.loop0.remote_hosts)
            is_ip6 = acl % 2
            ip4 = host.ip4.split(".")
            ip6 = list(unpack("<16B", inet_pton(AF_INET6, host.ip6)))

            if ip_type == self.EXACT_IP:
                prefix_len4 = 32
                prefix_len6 = 128
            elif ip_type == self.WILD_IP:
                ip4 = [0, 0, 0, 0]
                ip6 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                prefix_len4 = 0
                prefix_len6 = 0
                rules_count[int((acl / 2) - 1)] = 1
            else:
                prefix_len4 = 24
                prefix_len6 = 64

            if mac_type == self.EXACT_MAC:
                mask = "ff:ff:ff:ff:ff:ff"
            elif mac_type == self.WILD_MAC:
                mask = "00:00:00:00:00:00"
            elif mac_type == self.OUI_MAC:
                mask = "ff:ff:ff:00:00:00"
            else:
                mask = "ff:ff:ff:ff:ff:00"

            ip = ip6 if is_ip6 else ip4
            ip_len = prefix_len6 if is_ip6 else prefix_len4

            for i in range(0, (rules_count[int((acl / 2) - 1)])):
                src_mac += 16777217
                if mac_type == self.WILD_MAC:
                    mac = "00:00:00:00:00:00"
                elif mac_type == self.OUI_MAC:
                    mac = (
                        ":".join(re.findall("..", "{:02x}".format(src_mac))[:3])
                        + ":00:00:00"
                    )
                else:
                    mac = ":".join(re.findall("..", "{:02x}".format(src_mac)))

                if ip_type == self.EXACT_IP:
                    ip4[3] = random.randint(100, 200)
                    ip6[15] = random.randint(100, 200)
                elif ip_type == self.SUBNET_IP:
                    ip4[2] = random.randint(100, 200)
                    ip4[3] = 0
                    ip6[7] = random.randint(100, 200)
                    ip6[15] = 0
                ip_pack = b""
                for j in range(0, len(ip)):
                    ip_pack += pack("<B", int(ip[j]))

                rule = MacipRule(
                    is_permit=self.PERMIT,
                    src_prefix=ip_network((ip_pack, ip_len)),
                    src_mac=MACAddress(mac).packed,
                    src_mac_mask=MACAddress(mask).packed,
                )
                rules.append(rule)
                if ip_type == self.WILD_IP:
                    break

            acls.append(rules)
            src_mac += 1099511627776
        return acls

    def apply_macip_rules(self, acls):
        macip_acls = []
        for acl in acls:
            macip_acl = VppMacipAcl(self, rules=acl)
            macip_acl.add_vpp_config()
            macip_acls.append(macip_acl)
        return macip_acls

    def verify_macip_acls(self, acl_count, rules_count, expected_count=2):
        reply = self.macip_acl_dump_debug()
        for acl in range(2, (acl_count + 1) * 2):
            self.assertEqual(reply[acl - 2].count, rules_count[acl // 2 - 1])

        self.vapi.macip_acl_interface_get()

        self.vapi.macip_acl_interface_add_del(sw_if_index=0, acl_index=0)
        self.vapi.macip_acl_interface_add_del(sw_if_index=1, acl_index=1)

        reply = self.vapi.macip_acl_interface_get()
        self.assertEqual(reply.count, expected_count)

    def create_stream(
        self,
        mac_type,
        ip_type,
        packet_count,
        src_if,
        dst_if,
        traffic,
        is_ip6,
        tags=PERMIT_TAGS,
    ):
        # exact MAC and exact IP
        # exact MAC and subnet of IPs
        # exact MAC and wildcard IP
        # wildcard MAC and exact IP
        # wildcard MAC and subnet of IPs
        # wildcard MAC and wildcard IP
        # OUI restricted MAC and exact IP
        # OUI restricted MAC and subnet of IPs
        # OUI restricted MAC and wildcard IP

        packets = []
        macip_rules = []
        acl_rules = []
        ip_permit = ""
        mac_permit = ""
        dst_mac = ""
        mac_rule = "00:00:00:00:00:00"
        mac_mask = "00:00:00:00:00:00"
        for p in range(0, packet_count):
            remote_dst_index = p % len(dst_if.remote_hosts)
            remote_dst_host = dst_if.remote_hosts[remote_dst_index]

            dst_port = 1234 + p
            src_port = 4321 + p
            is_permit = self.PERMIT if p % 3 == 0 else self.DENY
            denyMAC = True if not is_permit and p % 3 == 1 else False
            denyIP = True if not is_permit and p % 3 == 2 else False
            if not is_permit and ip_type == self.WILD_IP:
                denyMAC = True
            if not is_permit and mac_type == self.WILD_MAC:
                denyIP = True

            if traffic == self.BRIDGED:
                if is_permit:
                    src_mac = remote_dst_host._mac
                    dst_mac = "de:ad:00:00:00:00"
                    src_ip4 = remote_dst_host.ip4
                    dst_ip4 = src_if.remote_ip4
                    src_ip6 = remote_dst_host.ip6
                    dst_ip6 = src_if.remote_ip6
                    ip_permit = src_ip6 if is_ip6 else src_ip4
                    mac_permit = src_mac
                if denyMAC:
                    mac = src_mac.split(":")
                    mac[0] = format(int(mac[0], 16) + 1, "02x")
                    src_mac = ":".join(mac)
                    if is_ip6:
                        src_ip6 = ip_permit
                    else:
                        src_ip4 = ip_permit
                if denyIP:
                    if ip_type != self.WILD_IP:
                        src_mac = mac_permit
                    src_ip4 = remote_dst_host.ip4
                    dst_ip4 = src_if.remote_ip4
                    src_ip6 = remote_dst_host.ip6
                    dst_ip6 = src_if.remote_ip6
            else:
                if is_permit:
                    src_mac = remote_dst_host._mac
                    dst_mac = src_if.local_mac
                    src_ip4 = src_if.remote_ip4
                    dst_ip4 = remote_dst_host.ip4
                    src_ip6 = src_if.remote_ip6
                    dst_ip6 = remote_dst_host.ip6
                    ip_permit = src_ip6 if is_ip6 else src_ip4
                    mac_permit = src_mac
                if denyMAC:
                    mac = src_mac.split(":")
                    mac[0] = format(int(mac[0], 16) + 1, "02x")
                    src_mac = ":".join(mac)
                    if is_ip6:
                        src_ip6 = ip_permit
                    else:
                        src_ip4 = ip_permit
                if denyIP:
                    src_mac = remote_dst_host._mac
                    if ip_type != self.WILD_IP:
                        src_mac = mac_permit
                    src_ip4 = remote_dst_host.ip4
                    dst_ip4 = src_if.remote_ip4
                    src_ip6 = remote_dst_host.ip6
                    dst_ip6 = src_if.remote_ip6

            if is_permit:
                info = self.create_packet_info(src_if, dst_if)
                payload = self.info_to_payload(info)
            else:
                payload = "to be blocked"

            if mac_type == self.WILD_MAC:
                mac = src_mac.split(":")
                for i in range(1, 5):
                    mac[i] = format(random.randint(0, 255), "02x")
                src_mac = ":".join(mac)

            # create packet
            packet = Ether(src=src_mac, dst=dst_mac)
            ip_rule = src_ip6 if is_ip6 else src_ip4
            if is_ip6:
                if ip_type != self.EXACT_IP:
                    sub_ip = list(unpack("<16B", inet_pton(AF_INET6, ip_rule)))
                    if ip_type == self.WILD_IP:
                        sub_ip[0] = random.randint(240, 254)
                        sub_ip[1] = random.randint(230, 239)
                        sub_ip[14] = random.randint(100, 199)
                        sub_ip[15] = random.randint(200, 255)
                    elif ip_type == self.SUBNET_IP:
                        if denyIP:
                            sub_ip[2] = int(sub_ip[2]) + 1
                        sub_ip[14] = random.randint(100, 199)
                        sub_ip[15] = random.randint(200, 255)
                    packed_src_ip6 = b"".join([scapy.compat.chb(x) for x in sub_ip])
                    src_ip6 = inet_ntop(AF_INET6, packed_src_ip6)
                packet /= IPv6(src=src_ip6, dst=dst_ip6)
            else:
                if ip_type != self.EXACT_IP:
                    sub_ip = ip_rule.split(".")
                    if ip_type == self.WILD_IP:
                        sub_ip[0] = random.randint(1, 49)
                        sub_ip[1] = random.randint(50, 99)
                        sub_ip[2] = random.randint(100, 199)
                        sub_ip[3] = random.randint(200, 255)
                    elif ip_type == self.SUBNET_IP:
                        if denyIP:
                            sub_ip[1] = int(sub_ip[1]) + 1
                        sub_ip[2] = random.randint(100, 199)
                        sub_ip[3] = random.randint(200, 255)
                    src_ip4 = ".".join(["{!s}".format(x) for x in sub_ip])
                packet /= IP(src=src_ip4, dst=dst_ip4, frag=0, flags=0)

            packet /= UDP(sport=src_port, dport=dst_port) / Raw(payload)

            packet[Raw].load += b" mac:%s" % src_mac.encode("utf-8")

            size = self.pg_if_packet_sizes[p % len(self.pg_if_packet_sizes)]
            if isinstance(src_if, VppSubInterface):
                size = size + 4
            if isinstance(src_if, VppDot1QSubint):
                if src_if is self.subifs[0]:
                    if tags == self.PERMIT_TAGS:
                        packet = src_if.add_dot1q_layer(packet, 10)
                    else:
                        packet = src_if.add_dot1q_layer(packet, 11)
                else:
                    if tags == self.PERMIT_TAGS:
                        packet = src_if.add_dot1q_layer(packet, 30)
                    else:
                        packet = src_if.add_dot1q_layer(packet, 33)
            elif isinstance(src_if, VppDot1ADSubint):
                if src_if is self.subifs[1]:
                    if tags == self.PERMIT_TAGS:
                        packet = src_if.add_dot1ad_layer(packet, 300, 400)
                    else:
                        packet = src_if.add_dot1ad_layer(packet, 333, 444)
                else:
                    if tags == self.PERMIT_TAGS:
                        packet = src_if.add_dot1ad_layer(packet, 600, 700)
                    else:
                        packet = src_if.add_dot1ad_layer(packet, 666, 777)
            self.extend_packet(packet, size)
            packets.append(packet)

            # create suitable MACIP rule
            if mac_type == self.EXACT_MAC:
                mac_rule = src_mac
                mac_mask = "ff:ff:ff:ff:ff:ff"
            elif mac_type == self.WILD_MAC:
                mac_rule = "00:00:00:00:00:00"
                mac_mask = "00:00:00:00:00:00"
            elif mac_type == self.OUI_MAC:
                mac = src_mac.split(":")
                mac[3] = mac[4] = mac[5] = "00"
                mac_rule = ":".join(mac)
                mac_mask = "ff:ff:ff:00:00:00"

            if is_ip6:
                if ip_type == self.WILD_IP:
                    ip = "0::0"
                else:
                    ip = src_ip6
                    if ip_type == self.SUBNET_IP:
                        sub_ip = list(unpack("<16B", inet_pton(AF_INET6, ip)))
                        for i in range(8, 16):
                            sub_ip[i] = 0
                        packed_ip = b"".join([scapy.compat.chb(x) for x in sub_ip])
                        ip = inet_ntop(AF_INET6, packed_ip)
            else:
                if ip_type == self.WILD_IP:
                    ip = "0.0.0.0"
                else:
                    ip = src_ip4
                    if ip_type == self.SUBNET_IP:
                        sub_ip = ip.split(".")
                        sub_ip[2] = sub_ip[3] = "0"
                        ip = ".".join(sub_ip)

            prefix_len = 128 if is_ip6 else 32
            if ip_type == self.WILD_IP:
                prefix_len = 0
            elif ip_type == self.SUBNET_IP:
                prefix_len = 64 if is_ip6 else 16
            ip_rule = inet_pton(AF_INET6 if is_ip6 else AF_INET, ip)

            # create suitable ACL rule
            if is_permit:
                rule_l4_sport = packet[UDP].sport
                rule_l4_dport = packet[UDP].dport
                rule_family = AF_INET6 if packet.haslayer(IPv6) else AF_INET
                rule_prefix_len = 128 if packet.haslayer(IPv6) else 32
                rule_l3_layer = IPv6 if packet.haslayer(IPv6) else IP
                if packet.haslayer(IPv6):
                    rule_l4_proto = packet[UDP].overload_fields[IPv6]["nh"]
                else:
                    rule_l4_proto = packet[IP].proto

                src_network = ip_network((packet[rule_l3_layer].src, rule_prefix_len))
                dst_network = ip_network((packet[rule_l3_layer].dst, rule_prefix_len))
                acl_rule = AclRule(
                    is_permit=is_permit,
                    proto=rule_l4_proto,
                    src_prefix=src_network,
                    dst_prefix=dst_network,
                    sport_from=rule_l4_sport,
                    sport_to=rule_l4_sport,
                    dport_from=rule_l4_dport,
                    dport_to=rule_l4_dport,
                )
                acl_rules.append(acl_rule)

            if mac_type == self.WILD_MAC and ip_type == self.WILD_IP and p > 0:
                continue

            if is_permit:
                macip_rule = MacipRule(
                    is_permit=is_permit,
                    src_prefix=ip_network((ip_rule, prefix_len)),
                    src_mac=MACAddress(mac_rule).packed,
                    src_mac_mask=MACAddress(mac_mask).packed,
                )
                macip_rules.append(macip_rule)

        # deny all other packets
        if not (mac_type == self.WILD_MAC and ip_type == self.WILD_IP):
            network = IPv6Network((0, 0)) if is_ip6 else IPv4Network((0, 0))
            macip_rule = MacipRule(
                is_permit=0,
                src_prefix=network,
                src_mac=MACAddress("00:00:00:00:00:00").packed,
                src_mac_mask=MACAddress("00:00:00:00:00:00").packed,
            )
            macip_rules.append(macip_rule)

        network = IPv6Network((0, 0)) if is_ip6 else IPv4Network((0, 0))
        acl_rule = AclRule(
            is_permit=0,
            src_prefix=network,
            dst_prefix=network,
            sport_from=0,
            sport_to=0,
            dport_from=0,
            dport_to=0,
        )
        acl_rules.append(acl_rule)
        return {"stream": packets, "macip_rules": macip_rules, "acl_rules": acl_rules}

    def verify_capture(self, stream, capture, is_ip6):
        """
        :param stream:
        :param capture:
        :param is_ip6:
        :return:
        """
        # 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)
        #
        # acls = self.macip_acl_dump_debug()

        # TODO : verify
        # for acl in acls:
        #     for r in acl.r:
        #         print(binascii.hexlify(r.src_mac), \
        #               binascii.hexlify(r.src_mac_mask),\
        #               unpack('<16B', r.src_ip_addr), \
        #               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)

    def run_traffic(
        self,
        mac_type,
        ip_type,
        traffic,
        is_ip6,
        packets,
        do_not_expected_capture=False,
        tags=None,
        apply_rules=True,
        isMACIP=True,
        permit_tags=PERMIT_TAGS,
        try_replace=False,
    ):
        self.reset_packet_infos()

        if tags is None:
            tx_if = self.pg0 if traffic == self.BRIDGED else self.pg3
            rx_if = self.pg3 if traffic == self.BRIDGED else self.pg0
            src_if = self.pg3
            dst_if = self.loop0
        else:
            if tags == self.DOT1Q:
                if traffic == self.BRIDGED:
                    tx_if = self.subifs[0]
                    rx_if = self.pg0
                    src_if = self.subifs[0]
                    dst_if = self.loop0
                else:
                    tx_if = self.subifs[2]
                    rx_if = self.pg0
                    src_if = self.subifs[2]
                    dst_if = self.loop0
            elif tags == self.DOT1AD:
                if traffic == self.BRIDGED:
                    tx_if = self.subifs[1]
                    rx_if = self.pg0
                    src_if = self.subifs[1]
                    dst_if = self.loop0
                else:
                    tx_if = self.subifs[3]
                    rx_if = self.pg0
                    src_if = self.subifs[3]
                    dst_if = self.loop0
            else:
                return

        test_dict = self.create_stream(
            mac_type,
            ip_type,
            packets,
            src_if,
            dst_if,
            traffic,
            is_ip6,
            tags=permit_tags,
        )

        if apply_rules:
            if isMACIP:
                self.acl = VppMacipAcl(self, rules=test_dict["macip_rules"])
            else:
                self.acl = VppAcl(self, rules=test_dict["acl_rules"])
            self.acl.add_vpp_config()

            if isMACIP:
                self.acl_if = VppMacipAclInterface(
                    self, sw_if_index=tx_if.sw_if_index, acls=[self.acl]
                )
                self.acl_if.add_vpp_config()

                dump = self.acl_if.dump()
                self.assertTrue(dump)
                self.assertEqual(dump[0].acls[0], self.acl.acl_index)
            else:
                self.acl_if = VppAclInterface(
                    self, sw_if_index=tx_if.sw_if_index, n_input=1, acls=[self.acl]
                )
                self.acl_if.add_vpp_config()
        else:
            if hasattr(self, "acl_if"):
                self.acl_if.remove_vpp_config()
        if try_replace and hasattr(self, "acl"):
            if isMACIP:
                self.acl.modify_vpp_config(test_dict["macip_rules"])
            else:
                self.acl.modify_vpp_config(test_dict["acl_rules"])

        if not isinstance(src_if, VppSubInterface):
            tx_if.add_stream(test_dict["stream"])
        else:
            tx_if.parent.add_stream(test_dict["stream"])
        self.pg_enable_capture(self.pg_interfaces)
        self.pg_start()

        if do_not_expected_capture:
            rx_if.get_capture(0)
        else:
            if (
                traffic == self.BRIDGED
                and mac_type == self.WILD_MAC
                and ip_type == self.WILD_IP
            ):
                capture = rx_if.get_capture(packets)
            else:
                capture = rx_if.get_capture(
                    self.get_packet_count_for_if_idx(dst_if.sw_if_index)
                )
            self.verify_capture(test_dict["stream"], capture, is_ip6)
        if not isMACIP:
            if hasattr(self, "acl_if"):
                self.acl_if.remove_vpp_config()
            if hasattr(self, "acl"):
                self.acl.remove_vpp_config()

    def run_test_acls(
        self, mac_type, ip_type, acl_count, rules_count, traffic=None, ip=None
    ):
        self.apply_macip_rules(
            self.create_rules(mac_type, ip_type, acl_count, rules_count)
        )
        self.verify_macip_acls(acl_count, rules_count)

        if traffic is not None:
            self.run_traffic(self.EXACT_MAC, self.EXACT_IP, traffic, ip, 9)


class TestMACIP_IP4(MethodHolder):
    """MACIP with IP4 traffic"""

    @classmethod
    def setUpClass(cls):
        super(TestMACIP_IP4, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestMACIP_IP4, cls).tearDownClass()

    def test_acl_bridged_ip4_exactMAC_exactIP(self):
        """IP4 MACIP exactMAC|exactIP ACL bridged traffic"""
        self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_bridged_ip4_exactMAC_subnetIP(self):
        """IP4 MACIP exactMAC|subnetIP ACL bridged traffic"""

        self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_bridged_ip4_exactMAC_wildIP(self):
        """IP4 MACIP exactMAC|wildIP ACL bridged traffic"""

        self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_bridged_ip4_ouiMAC_exactIP(self):
        """IP4 MACIP ouiMAC|exactIP ACL bridged traffic"""

        self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP4, 3)

    def test_acl_bridged_ip4_ouiMAC_subnetIP(self):
        """IP4 MACIP ouiMAC|subnetIP ACL bridged traffic"""

        self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_bridged_ip4_ouiMAC_wildIP(self):
        """IP4 MACIP ouiMAC|wildIP ACL bridged traffic"""

        self.run_traffic(self.OUI_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_ac_bridgedl_ip4_wildMAC_exactIP(self):
        """IP4 MACIP wildcardMAC|exactIP ACL bridged traffic"""

        self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_bridged_ip4_wildMAC_subnetIP(self):
        """IP4 MACIP wildcardMAC|subnetIP ACL bridged traffic"""

        self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_bridged_ip4_wildMAC_wildIP(self):
        """IP4 MACIP wildcardMAC|wildIP ACL bridged traffic"""

        self.run_traffic(self.WILD_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP4, 9)

    def test_acl_routed_ip4_exactMAC_exactIP(self):
        """IP4 MACIP exactMAC|exactIP ACL routed traffic"""
        self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_exactMAC_subnetIP(self):
        """IP4 MACIP exactMAC|subnetIP ACL routed traffic"""
        self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_exactMAC_wildIP(self):
        """IP4 MACIP exactMAC|wildIP ACL routed traffic"""
        self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_ouiMAC_exactIP(self):
        """IP4 MACIP ouiMAC|exactIP ACL routed traffic"""

        self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_ouiMAC_subnetIP(self):
        """IP4 MACIP ouiMAC|subnetIP ACL routed traffic"""

        self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_ouiMAC_wildIP(self):
        """IP4 MACIP ouiMAC|wildIP ACL routed traffic"""

        self.run_traffic(self.OUI_MAC, self.WILD_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_wildMAC_exactIP(self):
        """IP4 MACIP wildcardMAC|exactIP ACL routed traffic"""

        self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_wildMAC_subnetIP(self):
        """IP4 MACIP wildcardMAC|subnetIP ACL routed traffic"""

        self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_routed_ip4_wildMAC_wildIP(self):
        """IP4 MACIP wildcardMAC|wildIP ACL"""

        self.run_traffic(self.WILD_MAC, self.WILD_IP, self.ROUTED, self.IS_IP4, 9)

    def test_acl_replace_traffic_ip4(self):
        """MACIP replace ACL with IP4 traffic"""
        self.run_traffic(
            self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9, try_replace=True
        )
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.BRIDGED,
            self.IS_IP4,
            9,
            try_replace=True,
        )


class TestMACIP_IP6(MethodHolder):
    """MACIP with IP6 traffic"""

    @classmethod
    def setUpClass(cls):
        super(TestMACIP_IP6, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestMACIP_IP6, cls).tearDownClass()

    def test_acl_bridged_ip6_exactMAC_exactIP(self):
        """IP6 MACIP exactMAC|exactIP ACL bridged traffic"""

        self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_exactMAC_subnetIP(self):
        """IP6 MACIP exactMAC|subnetIP ACL bridged traffic"""

        self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_exactMAC_wildIP(self):
        """IP6 MACIP exactMAC|wildIP ACL bridged traffic"""

        self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_ouiMAC_exactIP(self):
        """IP6 MACIP oui_MAC|exactIP ACL bridged traffic"""

        self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_ouiMAC_subnetIP(self):
        """IP6 MACIP ouiMAC|subnetIP ACL bridged traffic"""

        self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_ouiMAC_wildIP(self):
        """IP6 MACIP ouiMAC|wildIP ACL bridged traffic"""

        self.run_traffic(self.OUI_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_wildMAC_exactIP(self):
        """IP6 MACIP wildcardMAC|exactIP ACL bridged traffic"""

        self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_wildMAC_subnetIP(self):
        """IP6 MACIP wildcardMAC|subnetIP ACL bridged traffic"""

        self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_bridged_ip6_wildMAC_wildIP(self):
        """IP6 MACIP wildcardMAC|wildIP ACL bridged traffic"""

        self.run_traffic(self.WILD_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP6, 9)

    def test_acl_routed_ip6_exactMAC_exactIP(self):
        """IP6 MACIP exactMAC|exactIP ACL routed traffic"""

        self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_exactMAC_subnetIP(self):
        """IP6 MACIP exactMAC|subnetIP ACL routed traffic"""

        self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_exactMAC_wildIP(self):
        """IP6 MACIP exactMAC|wildIP ACL routed traffic"""

        self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_ouiMAC_exactIP(self):
        """IP6 MACIP ouiMAC|exactIP ACL routed traffic"""

        self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_ouiMAC_subnetIP(self):
        """IP6 MACIP ouiMAC|subnetIP ACL routed traffic"""

        self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_ouiMAC_wildIP(self):
        """IP6 MACIP ouiMAC|wildIP ACL routed traffic"""

        self.run_traffic(self.OUI_MAC, self.WILD_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_wildMAC_exactIP(self):
        """IP6 MACIP wildcardMAC|exactIP ACL routed traffic"""

        self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_wildMAC_subnetIP(self):
        """IP6 MACIP wildcardMAC|subnetIP ACL routed traffic"""

        self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_routed_ip6_wildMAC_wildIP(self):
        """IP6 MACIP wildcardMAC|wildIP ACL"""

        self.run_traffic(self.WILD_MAC, self.WILD_IP, self.ROUTED, self.IS_IP6, 9)

    def test_acl_replace_traffic_ip6(self):
        """MACIP replace ACL with IP6 traffic"""
        self.run_traffic(
            self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9, try_replace=True
        )
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.BRIDGED,
            self.IS_IP6,
            9,
            try_replace=True,
        )


class TestMACIP(MethodHolder):
    """MACIP Tests"""

    @classmethod
    def setUpClass(cls):
        super(TestMACIP, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestMACIP, cls).tearDownClass()

    def test_acl_1_2(self):
        """MACIP ACL with 2 entries"""

        self.run_test_acls(self.EXACT_MAC, self.WILD_IP, 1, [2])

    def test_acl_1_5(self):
        """MACIP ACL with 5 entries"""

        self.run_test_acls(self.EXACT_MAC, self.SUBNET_IP, 1, [5])

    def test_acl_1_10(self):
        """MACIP ACL with 10 entries"""

        self.run_test_acls(self.EXACT_MAC, self.EXACT_IP, 1, [10])

    def test_acl_1_20(self):
        """MACIP ACL with 20 entries"""

        self.run_test_acls(self.OUI_MAC, self.WILD_IP, 1, [20])

    def test_acl_1_50(self):
        """MACIP ACL with 50 entries"""

        self.run_test_acls(self.OUI_MAC, self.SUBNET_IP, 1, [50])

    def test_acl_1_100(self):
        """MACIP ACL with 100 entries"""

        self.run_test_acls(self.OUI_MAC, self.EXACT_IP, 1, [100])

    def test_acl_2_X(self):
        """MACIP 2 ACLs each with 100+ entries"""

        self.run_test_acls(self.OUI_MAC, self.SUBNET_IP, 2, [100, 200])

    def test_acl_10_X(self):
        """MACIP 10 ACLs each with 100+ entries"""

        self.run_test_acls(
            self.EXACT_MAC,
            self.EXACT_IP,
            10,
            [100, 120, 140, 160, 180, 200, 210, 220, 230, 240],
        )

    def test_acl_10_X_traffic_ip4(self):
        """MACIP 10 ACLs each with 100+ entries with IP4 traffic"""

        self.run_test_acls(
            self.EXACT_MAC,
            self.EXACT_IP,
            10,
            [100, 120, 140, 160, 180, 200, 210, 220, 230, 240],
            self.BRIDGED,
            self.IS_IP4,
        )

    def test_acl_10_X_traffic_ip6(self):
        """MACIP 10 ACLs each with 100+ entries with IP6 traffic"""

        self.run_test_acls(
            self.EXACT_MAC,
            self.EXACT_IP,
            10,
            [100, 120, 140, 160, 180, 200, 210, 220, 230, 240],
            self.BRIDGED,
            self.IS_IP6,
        )

    def test_acl_replace(self):
        """MACIP replace ACL"""

        r1 = self.create_rules(acl_count=3, rules_count=[2, 2, 2])
        r2 = self.create_rules(mac_type=self.OUI_MAC, ip_type=self.SUBNET_IP)
        macip_acls = self.apply_macip_rules(r1)

        acls_before = self.macip_acl_dump_debug()

        # replace acls #2, #3 with new
        macip_acls[2].modify_vpp_config(r2[0])
        macip_acls[3].modify_vpp_config(r2[1])

        acls_after = self.macip_acl_dump_debug()

        # verify changes
        self.assertEqual(len(acls_before), len(acls_after))
        for acl1, acl2 in zip(
            acls_before[:2] + acls_before[4:], acls_after[:2] + acls_after[4:]
        ):
            self.assertEqual(len(acl1), len(acl2))

            self.assertEqual(len(acl1.r), len(acl2.r))
            for r1, r2 in zip(acl1.r, acl2.r):
                self.assertEqual(len(acl1.r), len(acl2.r))
                self.assertEqual(acl1.r, acl2.r)
        for acl1, acl2 in zip(acls_before[2:4], acls_after[2:4]):
            self.assertEqual(len(acl1), len(acl2))

            self.assertNotEqual(len(acl1.r), len(acl2.r))
            for r1, r2 in zip(acl1.r, acl2.r):
                self.assertNotEqual(len(acl1.r), len(acl2.r))
                self.assertNotEqual(acl1.r, acl2.r)

    def test_delete_intf(self):
        """MACIP ACL delete intf with acl"""

        intf_count = len(self.interfaces) + 1
        intf = []
        macip_alcs = self.apply_macip_rules(
            self.create_rules(acl_count=3, rules_count=[3, 5, 4])
        )

        intf.append(VppLoInterface(self))
        intf.append(VppLoInterface(self))

        sw_if_index0 = intf[0].sw_if_index
        macip_acl_if0 = VppMacipAclInterface(
            self, sw_if_index=sw_if_index0, acls=[macip_alcs[1]]
        )
        macip_acl_if0.add_vpp_config()

        reply = self.vapi.macip_acl_interface_get()
        self.assertEqual(reply.count, intf_count + 1)
        self.assertEqual(reply.acls[sw_if_index0], 1)

        sw_if_index1 = intf[1].sw_if_index
        macip_acl_if1 = VppMacipAclInterface(
            self, sw_if_index=sw_if_index1, acls=[macip_alcs[0]]
        )
        macip_acl_if1.add_vpp_config()

        reply = self.vapi.macip_acl_interface_get()
        self.assertEqual(reply.count, intf_count + 2)
        self.assertEqual(reply.acls[sw_if_index1], 0)

        intf[0].remove_vpp_config()
        reply = self.vapi.macip_acl_interface_get()
        self.assertEqual(reply.count, intf_count + 2)
        self.assertEqual(reply.acls[sw_if_index0], 4294967295)
        self.assertEqual(reply.acls[sw_if_index1], 0)

        intf.append(VppLoInterface(self))
        intf.append(VppLoInterface(self))
        sw_if_index2 = intf[2].sw_if_index
        sw_if_index3 = intf[3].sw_if_index
        macip_acl_if2 = VppMacipAclInterface(
            self, sw_if_index=sw_if_index2, acls=[macip_alcs[1]]
        )
        macip_acl_if2.add_vpp_config()
        macip_acl_if3 = VppMacipAclInterface(
            self, sw_if_index=sw_if_index3, acls=[macip_alcs[1]]
        )
        macip_acl_if3.add_vpp_config()

        reply = self.vapi.macip_acl_interface_get()
        self.assertEqual(reply.count, intf_count + 3)
        self.assertEqual(reply.acls[sw_if_index1], 0)
        self.assertEqual(reply.acls[sw_if_index2], 1)
        self.assertEqual(reply.acls[sw_if_index3], 1)
        self.logger.info("MACIP ACL on multiple interfaces:")
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl"))
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl index 1234"))
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl index 1"))
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl index 0"))
        self.logger.info(self.vapi.ppcli("sh acl-plugin macip interface"))

        intf[2].remove_vpp_config()
        intf[1].remove_vpp_config()

        reply = self.vapi.macip_acl_interface_get()
        self.assertEqual(reply.count, intf_count + 3)
        self.assertEqual(reply.acls[sw_if_index0], 4294967295)
        self.assertEqual(reply.acls[sw_if_index1], 4294967295)
        self.assertEqual(reply.acls[sw_if_index2], 4294967295)
        self.assertEqual(reply.acls[sw_if_index3], 1)

        intf[3].remove_vpp_config()
        reply = self.vapi.macip_acl_interface_get()

        self.assertEqual(len([x for x in reply.acls if x != 4294967295]), 0)


class TestACL_dot1q_bridged(MethodHolder):
    """ACL on dot1q bridged subinterfaces Tests"""

    @classmethod
    def setUpClass(cls):
        super(TestACL_dot1q_bridged, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestACL_dot1q_bridged, cls).tearDownClass()

    def test_acl_bridged_ip4_subif_dot1q(self):
        """IP4 ACL SubIf Dot1Q bridged traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.BRIDGED,
            self.IS_IP4,
            9,
            tags=self.DOT1Q,
            isMACIP=False,
        )

    def test_acl_bridged_ip6_subif_dot1q(self):
        """IP6 ACL SubIf Dot1Q bridged traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.BRIDGED,
            self.IS_IP6,
            9,
            tags=self.DOT1Q,
            isMACIP=False,
        )


class TestACL_dot1ad_bridged(MethodHolder):
    """ACL on dot1ad bridged subinterfaces Tests"""

    @classmethod
    def setUpClass(cls):
        super(TestACL_dot1ad_bridged, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestACL_dot1ad_bridged, cls).tearDownClass()

    def test_acl_bridged_ip4_subif_dot1ad(self):
        """IP4 ACL SubIf Dot1AD bridged traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.BRIDGED,
            self.IS_IP4,
            9,
            tags=self.DOT1AD,
            isMACIP=False,
        )

    def test_acl_bridged_ip6_subif_dot1ad(self):
        """IP6 ACL SubIf Dot1AD bridged traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.BRIDGED,
            self.IS_IP6,
            9,
            tags=self.DOT1AD,
            isMACIP=False,
        )


class TestACL_dot1q_routed(MethodHolder):
    """ACL on dot1q routed subinterfaces Tests"""

    @classmethod
    def setUpClass(cls):
        super(TestACL_dot1q_routed, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestACL_dot1q_routed, cls).tearDownClass()

    def test_acl_routed_ip4_subif_dot1q(self):
        """IP4 ACL SubIf Dot1Q routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP4,
            9,
            tags=self.DOT1Q,
            isMACIP=False,
        )

    def test_acl_routed_ip6_subif_dot1q(self):
        """IP6 ACL SubIf Dot1Q routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP6,
            9,
            tags=self.DOT1Q,
            isMACIP=False,
        )

    def test_acl_routed_ip4_subif_dot1q_deny_by_tags(self):
        """IP4 ACL SubIf wrong tags Dot1Q routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP4,
            9,
            True,
            tags=self.DOT1Q,
            isMACIP=False,
            permit_tags=self.DENY_TAGS,
        )

    def test_acl_routed_ip6_subif_dot1q_deny_by_tags(self):
        """IP6 ACL SubIf wrong tags Dot1Q routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP6,
            9,
            True,
            tags=self.DOT1Q,
            isMACIP=False,
            permit_tags=self.DENY_TAGS,
        )


class TestACL_dot1ad_routed(MethodHolder):
    """ACL on dot1ad routed subinterfaces Tests"""

    @classmethod
    def setUpClass(cls):
        super(TestACL_dot1ad_routed, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(TestACL_dot1ad_routed, cls).tearDownClass()

    def test_acl_routed_ip6_subif_dot1ad(self):
        """IP6 ACL SubIf Dot1AD routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP6,
            9,
            tags=self.DOT1AD,
            isMACIP=False,
        )

    def test_acl_routed_ip4_subif_dot1ad(self):
        """IP4 ACL SubIf Dot1AD routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP4,
            9,
            tags=self.DOT1AD,
            isMACIP=False,
        )

    def test_acl_routed_ip6_subif_dot1ad_deny_by_tags(self):
        """IP6 ACL SubIf wrong tags Dot1AD routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP6,
            9,
            True,
            tags=self.DOT1AD,
            isMACIP=False,
            permit_tags=self.DENY_TAGS,
        )

    def test_acl_routed_ip4_subif_dot1ad_deny_by_tags(self):
        """IP4 ACL SubIf wrong tags Dot1AD routed traffic"""
        self.run_traffic(
            self.EXACT_MAC,
            self.EXACT_IP,
            self.ROUTED,
            self.IS_IP4,
            9,
            True,
            tags=self.DOT1AD,
            isMACIP=False,
            permit_tags=self.DENY_TAGS,
        )


if __name__ == "__main__":
    unittest.main(testRunner=VppTestRunner)
