#!/usr/bin/env python3

import unittest

from framework import VppTestCase, VppTestRunner, running_gcov_tests
from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath


class TestAdl(VppTestCase):
    """ Allow/Deny Plugin Unit Test Cases """

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

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

    def setUp(self):
        super(TestAdl, self).setUp()

    def tearDown(self):
        super(TestAdl, self).tearDown()

    def test_adl1_unittest(self):
        """ Plugin API Test """
        cmds = ["loop create\n",
                "set int ip address loop0 192.168.1.1/24\n",
                "set int ip6 table loop0 0\n",
                "set int ip address loop0 2001:db01::1/64\n",
                "set int state loop0 up\n",
                "packet-generator new {\n"
                " name ip4\n"
                " limit 100\n"
                " rate 0\n"
                " size 128-128\n"
                " interface loop0\n"
                " node adl-input\n"
                " data { IP4: 1.2.40 -> 3cfd.fed0.b6c8\n"
                "        UDP: 192.168.1.2-192.168.1.10 -> 192.168.2.1\n"
                "        UDP: 1234 -> 2345\n"
                "        incrementing 114\n"
                "       }\n"
                " }\n",
                "packet-generator new {\n"
                " name ip6-allow\n"
                " limit 50\n"
                " rate 0\n"
                " size 128-128\n"
                " interface loop0\n"
                " node adl-input\n"
                " data { IP6: 1.2.40 -> 3cfd.fed0.b6c8\n"
                "        UDP: 2001:db01::2 -> 2001:db01::1\n"
                "        UDP: 1234 -> 2345\n"
                "        incrementing 80\n"
                "      }\n"
                " }\n",
                "packet-generator new {\n"
                " name ip6-drop\n"
                " limit 50\n"
                " rate 0\n"
                " size 128-128\n"
                " interface loop0\n"
                " node adl-input\n"
                " data { IP6: 1.2.40 -> 3cfd.fed0.b6c8\n"
                "        UDP: 2001:db01::3 -> 2001:db01::1\n"
                "        UDP: 1234 -> 2345\n"
                "        incrementing 80\n"
                "      }\n"
                " }\n",
                "ip table 1\n",
                "ip route add 192.168.2.1/32 via drop\n",
                "ip route add table 1 192.168.1.2/32 via local\n",
                "ip6 table 1\n",
                "ip route add 2001:db01::1/128 via drop\n",
                "ip route add table 1 2001:db01::2/128 via local\n",
                "bin adl_interface_enable_disable loop0\n",
                "bin adl_allowlist_enable_disable loop0 fib-id 1 ip4 ip6\n",
                "pa en\n"]

        for cmd in cmds:
            r = self.vapi.cli_return_response(cmd)
            if r.retval != 0:
                if hasattr(r, 'reply'):
                    self.logger.info(cmd + " FAIL reply " + r.reply)
                else:
                    self.logger.info(cmd + " FAIL retval " + str(r.retval))

        total_pkts = self.statistics.get_err_counter(
            "/err/adl-input/Allow/Deny packets processed")

        self.assertEqual(total_pkts, 200)

        ip4_allow = self.statistics.get_err_counter(
            "/err/ip4-adl-allowlist/ip4 allowlist allowed")
        self.assertEqual(ip4_allow, 12)
        ip6_allow = self.statistics.get_err_counter(
            "/err/ip6-adl-allowlist/ip6 allowlist allowed")
        self.assertEqual(ip6_allow, 50)

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