#!/usr/bin/env python3

import unittest
import random

from scapy.packet import Raw
from scapy.layers.l2 import Ether, Dot1Q
from scapy.layers.inet import IP, UDP

from util import Host
from framework import VppTestCase, VppTestRunner
from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint, VppDot1ADSubint
from collections import namedtuple

Tag = namedtuple("Tag", ["dot1", "vlan"])
DOT1AD = 0x88A8
DOT1Q = 0x8100


class TestVtr(VppTestCase):
    """VTR Test Case"""

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

        # Test variables
        cls.bd_id = 1
        cls.mac_entries_count = 5
        cls.Atag = 100
        cls.Btag = 200
        cls.dot1ad_sub_id = 20

        try:
            ifs = range(3)
            cls.create_pg_interfaces(ifs)

            cls.sub_interfaces = [
                VppDot1ADSubint(cls, cls.pg1, cls.dot1ad_sub_id, cls.Btag, cls.Atag),
                VppDot1QSubint(cls, cls.pg2, cls.Btag),
            ]

            interfaces = list(cls.pg_interfaces)
            interfaces.extend(cls.sub_interfaces)

            # Create BD with MAC learning enabled and put interfaces and
            #  sub-interfaces to this BD
            for pg_if in cls.pg_interfaces:
                sw_if_index = (
                    pg_if.sub_if.sw_if_index
                    if hasattr(pg_if, "sub_if")
                    else pg_if.sw_if_index
                )
                cls.vapi.sw_interface_set_l2_bridge(
                    rx_sw_if_index=sw_if_index, bd_id=cls.bd_id
                )

            # setup all interfaces
            for i in interfaces:
                i.admin_up()

            # mapping between packet-generator index and lists of test hosts
            cls.hosts_by_pg_idx = dict()

            # create test host entries and inject packets to learn MAC entries
            # in the bridge-domain
            cls.create_hosts_and_learn(cls.mac_entries_count)
            cls.logger.info(cls.vapi.ppcli("show l2fib"))

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

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

    def setUp(self):
        """
        Clear trace and packet infos before running each test.
        """
        super(TestVtr, self).setUp()
        self.reset_packet_infos()

    def tearDown(self):
        """
        Show various debug prints after each test.
        """
        super(TestVtr, self).tearDown()

    def show_commands_at_teardown(self):
        self.logger.info(self.vapi.ppcli("show l2fib verbose"))
        self.logger.info(self.vapi.ppcli("show bridge-domain %s detail" % self.bd_id))

    @classmethod
    def create_hosts_and_learn(cls, count):
        for pg_if in cls.pg_interfaces:
            cls.hosts_by_pg_idx[pg_if.sw_if_index] = []
            hosts = cls.hosts_by_pg_idx[pg_if.sw_if_index]
            packets = []
            for j in range(1, count + 1):
                host = Host(
                    "00:00:00:ff:%02x:%02x" % (pg_if.sw_if_index, j),
                    "172.17.1%02x.%u" % (pg_if.sw_if_index, j),
                )
                packet = Ether(dst="ff:ff:ff:ff:ff:ff", src=host.mac)
                hosts.append(host)
                if hasattr(pg_if, "sub_if"):
                    packet = pg_if.sub_if.add_dot1_layer(packet)
                packets.append(packet)
            pg_if.add_stream(packets)
        cls.logger.info("Sending broadcast eth frames for MAC learning")
        cls.pg_enable_capture(cls.pg_interfaces)
        cls.pg_start()

    def create_packet(self, src_if, dst_if, do_dot1=True):
        packet_sizes = [64, 512, 1518, 9018]
        dst_host = random.choice(self.hosts_by_pg_idx[dst_if.sw_if_index])
        src_host = random.choice(self.hosts_by_pg_idx[src_if.sw_if_index])
        pkt_info = self.create_packet_info(src_if, dst_if)
        payload = self.info_to_payload(pkt_info)
        p = (
            Ether(dst=dst_host.mac, src=src_host.mac)
            / IP(src=src_host.ip4, dst=dst_host.ip4)
            / UDP(sport=1234, dport=1234)
            / Raw(payload)
        )
        pkt_info.data = p.copy()
        if do_dot1 and hasattr(src_if, "sub_if"):
            p = src_if.sub_if.add_dot1_layer(p)
        size = random.choice(packet_sizes)
        self.extend_packet(p, size)
        return p

    def _add_tag(self, packet, vlan, tag_type):
        payload = packet.payload
        inner_type = packet.type
        packet.remove_payload()
        packet.add_payload(Dot1Q(vlan=vlan) / payload)
        packet.payload.type = inner_type
        packet.payload.vlan = vlan
        packet.type = tag_type
        return packet

    def _remove_tag(self, packet, vlan=None, tag_type=None):
        if tag_type:
            self.assertEqual(packet.type, tag_type)

        payload = packet.payload
        if vlan:
            self.assertEqual(payload.vlan, vlan)
        inner_type = payload.type
        payload = payload.payload
        packet.remove_payload()
        packet.add_payload(payload)
        packet.type = inner_type

    def add_tags(self, packet, tags):
        for t in reversed(tags):
            self._add_tag(packet, t.vlan, t.dot1)

    def remove_tags(self, packet, tags):
        for t in tags:
            self._remove_tag(packet, t.vlan, t.dot1)

    def vtr_test(self, swif, tags):
        p = self.create_packet(swif, self.pg0)
        swif.add_stream(p)
        self.pg_enable_capture(self.pg_interfaces)
        self.pg_start()
        rx = self.pg0.get_capture(1)

        if tags:
            self.remove_tags(rx[0], tags)
        self.assertTrue(Dot1Q not in rx[0])

        if not tags:
            return

        i = VppDot1QSubint(self, self.pg0, tags[0].vlan)
        self.vapi.sw_interface_set_l2_bridge(
            rx_sw_if_index=i.sw_if_index, bd_id=self.bd_id, enable=1
        )
        i.admin_up()

        p = self.create_packet(self.pg0, swif, do_dot1=False)
        self.add_tags(p, tags)
        self.pg0.add_stream(p)
        self.pg_enable_capture(self.pg_interfaces)
        self.pg_start()
        rx = swif.get_capture(1)
        swif.sub_if.remove_dot1_layer(rx[0])
        self.assertTrue(Dot1Q not in rx[0])

        self.vapi.sw_interface_set_l2_bridge(
            rx_sw_if_index=i.sw_if_index, bd_id=self.bd_id, enable=0
        )
        i.remove_vpp_config()

    def test_1ad_vtr_pop_1(self):
        """1AD VTR pop 1 test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_POP_1)
        self.vtr_test(self.pg1, [Tag(dot1=DOT1Q, vlan=100)])

    def test_1ad_vtr_pop_2(self):
        """1AD VTR pop 2 test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_POP_2)
        self.vtr_test(self.pg1, [])

    def test_1ad_vtr_push_1ad(self):
        """1AD VTR push 1 1AD test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_PUSH_1, tag=300)
        self.vtr_test(
            self.pg1,
            [
                Tag(dot1=DOT1AD, vlan=300),
                Tag(dot1=DOT1AD, vlan=200),
                Tag(dot1=DOT1Q, vlan=100),
            ],
        )

    def test_1ad_vtr_push_2ad(self):
        """1AD VTR push 2 1AD test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_PUSH_2, outer=400, inner=300)
        self.vtr_test(
            self.pg1,
            [
                Tag(dot1=DOT1AD, vlan=400),
                Tag(dot1=DOT1Q, vlan=300),
                Tag(dot1=DOT1AD, vlan=200),
                Tag(dot1=DOT1Q, vlan=100),
            ],
        )

    def test_1ad_vtr_push_1q(self):
        """1AD VTR push 1 1Q test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_PUSH_1, tag=300, push1q=1)
        self.vtr_test(
            self.pg1,
            [
                Tag(dot1=DOT1Q, vlan=300),
                Tag(dot1=DOT1AD, vlan=200),
                Tag(dot1=DOT1Q, vlan=100),
            ],
        )

    def test_1ad_vtr_push_2q(self):
        """1AD VTR push 2 1Q test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_PUSH_2, outer=400, inner=300, push1q=1)
        self.vtr_test(
            self.pg1,
            [
                Tag(dot1=DOT1Q, vlan=400),
                Tag(dot1=DOT1Q, vlan=300),
                Tag(dot1=DOT1AD, vlan=200),
                Tag(dot1=DOT1Q, vlan=100),
            ],
        )

    def test_1ad_vtr_translate_1_1ad(self):
        """1AD VTR translate 1 -> 1 1AD test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_1_1, tag=300)
        self.vtr_test(self.pg1, [Tag(dot1=DOT1AD, vlan=300), Tag(dot1=DOT1Q, vlan=100)])

    def test_1ad_vtr_translate_1_2ad(self):
        """1AD VTR translate 1 -> 2 1AD test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_1_2, inner=300, outer=400)
        self.vtr_test(
            self.pg1,
            [
                Tag(dot1=DOT1AD, vlan=400),
                Tag(dot1=DOT1Q, vlan=300),
                Tag(dot1=DOT1Q, vlan=100),
            ],
        )

    def test_1ad_vtr_translate_2_1ad(self):
        """1AD VTR translate 2 -> 1 1AD test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_2_1, tag=300)
        self.vtr_test(self.pg1, [Tag(dot1=DOT1AD, vlan=300)])

    def test_1ad_vtr_translate_2_2ad(self):
        """1AD VTR translate 2 -> 2 1AD test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_2_2, inner=300, outer=400)
        self.vtr_test(self.pg1, [Tag(dot1=DOT1AD, vlan=400), Tag(dot1=DOT1Q, vlan=300)])

    def test_1ad_vtr_translate_1_1q(self):
        """1AD VTR translate 1 -> 1 1Q test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_1_1, tag=300, push1q=1)
        self.vtr_test(self.pg1, [Tag(dot1=DOT1Q, vlan=300), Tag(dot1=DOT1Q, vlan=100)])

    def test_1ad_vtr_translate_1_2q(self):
        """1AD VTR translate 1 -> 2 1Q test"""
        self.pg1.sub_if.set_vtr(
            L2_VTR_OP.L2_TRANSLATE_1_2, inner=300, outer=400, push1q=1
        )
        self.vtr_test(
            self.pg1,
            [
                Tag(dot1=DOT1Q, vlan=400),
                Tag(dot1=DOT1Q, vlan=300),
                Tag(dot1=DOT1Q, vlan=100),
            ],
        )

    def test_1ad_vtr_translate_2_1q(self):
        """1AD VTR translate 2 -> 1 1Q test"""
        self.pg1.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_2_1, tag=300, push1q=1)
        self.vtr_test(self.pg1, [Tag(dot1=DOT1Q, vlan=300)])

    def test_1ad_vtr_translate_2_2q(self):
        """1AD VTR translate 2 -> 2 1Q test"""
        self.pg1.sub_if.set_vtr(
            L2_VTR_OP.L2_TRANSLATE_2_2, inner=300, outer=400, push1q=1
        )
        self.vtr_test(self.pg1, [Tag(dot1=DOT1Q, vlan=400), Tag(dot1=DOT1Q, vlan=300)])

    def test_1q_vtr_pop_1(self):
        """1Q VTR pop 1 test"""
        self.pg2.sub_if.set_vtr(L2_VTR_OP.L2_POP_1)
        self.vtr_test(self.pg2, [])

    def test_1q_vtr_push_1(self):
        """1Q VTR push 1 test"""
        self.pg2.sub_if.set_vtr(L2_VTR_OP.L2_PUSH_1, tag=300)
        self.vtr_test(self.pg2, [Tag(dot1=DOT1AD, vlan=300), Tag(dot1=DOT1Q, vlan=200)])

    def test_1q_vtr_push_2(self):
        """1Q VTR push 2 test"""
        self.pg2.sub_if.set_vtr(L2_VTR_OP.L2_PUSH_2, outer=400, inner=300)
        self.vtr_test(
            self.pg2,
            [
                Tag(dot1=DOT1AD, vlan=400),
                Tag(dot1=DOT1Q, vlan=300),
                Tag(dot1=DOT1Q, vlan=200),
            ],
        )

    def test_1q_vtr_translate_1_1(self):
        """1Q VTR translate 1 -> 1 test"""
        self.pg2.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_1_1, tag=300)
        self.vtr_test(self.pg2, [Tag(dot1=DOT1AD, vlan=300)])

    def test_1q_vtr_translate_1_2(self):
        """1Q VTR translate 1 -> 2 test"""
        self.pg2.sub_if.set_vtr(L2_VTR_OP.L2_TRANSLATE_1_2, inner=300, outer=400)
        self.vtr_test(self.pg2, [Tag(dot1=DOT1AD, vlan=400), Tag(dot1=DOT1Q, vlan=300)])

    def test_if_vtr_disable(self):
        """Disable VTR on non-sub-interfaces"""
        # First set the VTR fields to junk
        self.vapi.l2_interface_vlan_tag_rewrite(
            sw_if_index=self.pg0.sw_if_index,
            vtr_op=L2_VTR_OP.L2_PUSH_2,
            push_dot1q=1,
            tag1=19,
            tag2=630,
        )

        if_state = self.vapi.sw_interface_dump(sw_if_index=self.pg0.sw_if_index)
        self.assertEqual(if_state[0].sw_if_index, self.pg0.sw_if_index)
        self.assertNotEqual(if_state[0].vtr_op, L2_VTR_OP.L2_DISABLED)

        # Then ensure that a request to disable VTR is honored.
        self.vapi.l2_interface_vlan_tag_rewrite(
            sw_if_index=self.pg0.sw_if_index, vtr_op=L2_VTR_OP.L2_DISABLED
        )

        if_state = self.vapi.sw_interface_dump(sw_if_index=self.pg0.sw_if_index)
        self.assertEqual(if_state[0].sw_if_index, self.pg0.sw_if_index)
        self.assertEqual(if_state[0].vtr_op, L2_VTR_OP.L2_DISABLED)

    def test_if_vtr_push_1q(self):
        """1Q VTR push 1 on non-sub-interfaces"""
        self.vapi.l2_interface_vlan_tag_rewrite(
            sw_if_index=self.pg0.sw_if_index,
            vtr_op=L2_VTR_OP.L2_PUSH_1,
            push_dot1q=1,
            tag1=150,
        )

        if_state = self.vapi.sw_interface_dump(sw_if_index=self.pg0.sw_if_index)
        self.assertEqual(if_state[0].sw_if_index, self.pg0.sw_if_index)
        self.assertEqual(if_state[0].vtr_op, L2_VTR_OP.L2_PUSH_1)
        self.assertEqual(if_state[0].vtr_tag1, 150)
        self.assertNotEqual(if_state[0].vtr_push_dot1q, 0)

    def test_if_vtr_push_2ad(self):
        """1AD VTR push 2 on non-sub-interfaces"""
        self.vapi.l2_interface_vlan_tag_rewrite(
            sw_if_index=self.pg0.sw_if_index,
            vtr_op=L2_VTR_OP.L2_PUSH_2,
            push_dot1q=0,
            tag1=450,
            tag2=350,
        )

        if_state = self.vapi.sw_interface_dump(sw_if_index=self.pg0.sw_if_index)
        self.assertEqual(if_state[0].sw_if_index, self.pg0.sw_if_index)
        self.assertEqual(if_state[0].vtr_op, L2_VTR_OP.L2_PUSH_2)
        self.assertEqual(if_state[0].vtr_tag1, 450)  # outer
        self.assertEqual(if_state[0].vtr_tag2, 350)  # inner
        self.assertEqual(if_state[0].vtr_push_dot1q, 0)


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