#!/usr/bin/env python3

import unittest

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


class TestMactime(VppTestCase):
    """ Mactime Unit Test Cases """

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

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

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

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

    def test_mactime_range_unittest(self):
        """ Time Range Test """
        error = self.vapi.cli("test time-range")

        if error:
            self.logger.critical(error)
        self.assertNotIn('FAILED', error)

    @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
    def test_mactime_unittest(self):
        """ Mactime Plugin Code Coverage Test """
        cmds = ["loopback create",
                "mactime enable-disable disable",
                "mactime enable-disable loop0",
                "mactime enable-disable loop0 disable",
                "mactime enable-disable sw_if_index 9999",
                "bin mactime_enable_disable loop0",
                "bin mactime_enable_disable loop0 disable",
                "bin mactime_enable_disable sw_if_index 1",
                "set interface state loop0 up",
                "clear mactime",
                "set ip neighbor loop0 192.168.1.1 00:d0:2d:5e:86:85",
                "bin mactime_add_del_range name sallow "
                "mac 00:d0:2d:5e:86:85 allow-static del",
                "bin mactime_add_del_range name sallow "
                "mac 00:d0:2d:5e:86:85 allow-static",
                "bin mactime_add_del_range name sallow "
                "mac 00:d0:2d:5e:86:85 allow-static del",
                "bin mactime_add_del_range name sallow "
                "mac 00:d0:2d:5e:86:85 allow-static",
                "bin mactime_add_del_range name sblock "
                "mac 01:00:5e:7f:ff:fa drop-static",
                "bin mactime_add_del_range name ddrop "
                "mac c8:bc:c8:5a:ba:f3 drop-range Sun - Sat "
                "00:00 - 23:59",
                "bin mactime_add_del_range name dallow "
                "mac c8:bc:c8:5a:ba:f4 allow-range Sun - Sat "
                "00:00 - 23:59",
                "bin mactime_add_del_range name multi "
                "mac c8:bc:c8:f0:f0:f0 allow-range Sun - Mon "
                "00:00 - 23:59 Tue - Sat 00:00 - 23:59",
                "bin mactime_add_del_range bogus",
                "bin mactime_add_del_range mac 01:00:5e:7f:f0:f0 allow-static",
                "bin mactime_add_del_range "
                "name tooloooooooooooooooooooooooooooooooooooooooooooooooo"
                "nnnnnnnnnnnnnnnnnnnnnnnnnnnng mac 00:00:de:ad:be:ef "
                "allow-static",
                "packet-generator new {\n"
                " name allow\n"
                " limit 15\n"
                " size 128-128\n"
                " interface loop0\n"
                " node ethernet-input\n"
                " data {\n"
                "   IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n"
                "   ICMP: db00::1 -> db00::2\n"
                "   incrementing 30\n"
                "   }\n",
                "}\n",
                "packet-generator new {\n"
                " name deny\n"
                " limit 15\n"
                " size 128-128\n"
                " interface loop0\n"
                " node ethernet-input\n"
                " data {\n"
                "   IP6: 01:00:5e:7f:ff:fa -> 00:0d:ea:d0:00:00\n"
                "   ICMP: db00::1 -> db00::2\n"
                "   incrementing 30\n"
                "   }\n",
                "}\n",
                "packet-generator new {\n"
                " name ddrop\n"
                " limit 15\n"
                " size 128-128\n"
                " interface loop0\n"
                " node ethernet-input\n"
                " data {\n"
                "   IP6: c8:bc:c8:5a:ba:f3 -> 00:0d:ea:d0:00:00\n"
                "   ICMP: db00::1 -> db00::2\n"
                "   incrementing 30\n"
                "   }\n",
                "}\n",
                "packet-generator new {\n"
                " name dallow\n"
                " limit 15\n"
                " size 128-128\n"
                " interface loop0\n"
                " node ethernet-input\n"
                " data {\n"
                "   IP6: c8:bc:c8:5a:ba:f4 -> 00:0d:ea:d0:00:00\n"
                "   ICMP: db00::1 -> db00::2\n"
                "   incrementing 30\n"
                "   }\n"
                "}\n"
                "packet-generator new {\n"
                " name makeentry\n"
                " limit 15\n"
                " size 128-128\n"
                " interface loop0\n"
                " node ethernet-input\n"
                " data {\n"
                "   IP6: c8:bc:c8:5a:b0:0b -> 00:0d:ea:d0:00:00\n"
                "   ICMP: db00::1 -> db00::2\n"
                "   incrementing 30\n"
                "   }\n"
                "}\n"
                "packet-generator new {\n"
                " name tx\n"
                " limit 15\n"
                " size 128-128\n"
                " interface local0\n"
                " tx-interface loop0\n"
                " node loop0-output\n"
                " data {\n"
                "   hex 0x01005e7ffffa000dead000000800"
                "0102030405060708090a0b0c0d0e0f0102030405\n"
                "   }\n"
                "}\n"
                "trace add pg-input 2",
                "pa en",
                "show mactime verbose 2",
                "show trace",
                "show error"]

        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))

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