#!/usr/bin/env python3

import unittest

from config import config
from framework import VppTestCase, VppTestRunner
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(config.gcov, "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)
