Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 2 | |
| 3 | import unittest |
| 4 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 5 | from config import config |
Pratikshya Prasai | 657bdf7 | 2022-08-18 11:09:38 -0400 | [diff] [blame] | 6 | from asfframework import VppTestCase, VppTestRunner |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 7 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
| 8 | |
| 9 | |
| 10 | class TestMactime(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 11 | """Mactime Unit Test Cases""" |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 12 | |
| 13 | @classmethod |
| 14 | def setUpClass(cls): |
| 15 | super(TestMactime, cls).setUpClass() |
| 16 | |
| 17 | @classmethod |
| 18 | def tearDownClass(cls): |
| 19 | super(TestMactime, cls).tearDownClass() |
| 20 | |
| 21 | def setUp(self): |
| 22 | super(TestMactime, self).setUp() |
| 23 | |
| 24 | def tearDown(self): |
| 25 | super(TestMactime, self).tearDown() |
| 26 | |
| 27 | def test_mactime_range_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 28 | """Time Range Test""" |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 29 | error = self.vapi.cli("test time-range") |
| 30 | |
| 31 | if error: |
| 32 | self.logger.critical(error) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | self.assertNotIn("FAILED", error) |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 34 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 35 | @unittest.skipUnless(config.gcov, "part of code coverage tests") |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 36 | def test_mactime_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 37 | """Mactime Plugin Code Coverage Test""" |
| 38 | cmds = [ |
| 39 | "loopback create", |
| 40 | "mactime enable-disable disable", |
| 41 | "mactime enable-disable loop0", |
| 42 | "mactime enable-disable loop0 disable", |
| 43 | "mactime enable-disable sw_if_index 9999", |
| 44 | "bin mactime_enable_disable loop0", |
| 45 | "bin mactime_enable_disable loop0 disable", |
| 46 | "bin mactime_enable_disable sw_if_index 1", |
| 47 | "set interface state loop0 up", |
| 48 | "clear mactime", |
| 49 | "set ip neighbor loop0 192.168.1.1 00:d0:2d:5e:86:85", |
| 50 | "bin mactime_add_del_range name sallow " |
| 51 | "mac 00:d0:2d:5e:86:85 allow-static del", |
| 52 | "bin mactime_add_del_range name sallow " |
| 53 | "mac 00:d0:2d:5e:86:85 allow-static", |
| 54 | "bin mactime_add_del_range name sallow " |
| 55 | "mac 00:d0:2d:5e:86:85 allow-static del", |
| 56 | "bin mactime_add_del_range name sallow " |
| 57 | "mac 00:d0:2d:5e:86:85 allow-static", |
| 58 | "bin mactime_add_del_range name sblock " |
| 59 | "mac 01:00:5e:7f:ff:fa drop-static", |
| 60 | "bin mactime_add_del_range name ddrop " |
| 61 | "mac c8:bc:c8:5a:ba:f3 drop-range Sun - Sat " |
| 62 | "00:00 - 23:59", |
| 63 | "bin mactime_add_del_range name dallow " |
| 64 | "mac c8:bc:c8:5a:ba:f4 allow-range Sun - Sat " |
| 65 | "00:00 - 23:59", |
| 66 | "bin mactime_add_del_range name multi " |
| 67 | "mac c8:bc:c8:f0:f0:f0 allow-range Sun - Mon " |
| 68 | "00:00 - 23:59 Tue - Sat 00:00 - 23:59", |
| 69 | "bin mactime_add_del_range bogus", |
| 70 | "bin mactime_add_del_range mac 01:00:5e:7f:f0:f0 allow-static", |
| 71 | "bin mactime_add_del_range " |
| 72 | "name tooloooooooooooooooooooooooooooooooooooooooooooooooo" |
| 73 | "nnnnnnnnnnnnnnnnnnnnnnnnnnnng mac 00:00:de:ad:be:ef " |
| 74 | "allow-static", |
| 75 | "packet-generator new {\n" |
| 76 | " name allow\n" |
| 77 | " limit 15\n" |
| 78 | " size 128-128\n" |
| 79 | " interface loop0\n" |
| 80 | " node ethernet-input\n" |
| 81 | " data {\n" |
| 82 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 83 | " ICMP: db00::1 -> db00::2\n" |
| 84 | " incrementing 30\n" |
| 85 | " }\n", |
| 86 | "}\n", |
| 87 | "packet-generator new {\n" |
| 88 | " name deny\n" |
| 89 | " limit 15\n" |
| 90 | " size 128-128\n" |
| 91 | " interface loop0\n" |
| 92 | " node ethernet-input\n" |
| 93 | " data {\n" |
| 94 | " IP6: 01:00:5e:7f:ff:fa -> 00:0d:ea:d0:00:00\n" |
| 95 | " ICMP: db00::1 -> db00::2\n" |
| 96 | " incrementing 30\n" |
| 97 | " }\n", |
| 98 | "}\n", |
| 99 | "packet-generator new {\n" |
| 100 | " name ddrop\n" |
| 101 | " limit 15\n" |
| 102 | " size 128-128\n" |
| 103 | " interface loop0\n" |
| 104 | " node ethernet-input\n" |
| 105 | " data {\n" |
| 106 | " IP6: c8:bc:c8:5a:ba:f3 -> 00:0d:ea:d0:00:00\n" |
| 107 | " ICMP: db00::1 -> db00::2\n" |
| 108 | " incrementing 30\n" |
| 109 | " }\n", |
| 110 | "}\n", |
| 111 | "packet-generator new {\n" |
| 112 | " name dallow\n" |
| 113 | " limit 15\n" |
| 114 | " size 128-128\n" |
| 115 | " interface loop0\n" |
| 116 | " node ethernet-input\n" |
| 117 | " data {\n" |
| 118 | " IP6: c8:bc:c8:5a:ba:f4 -> 00:0d:ea:d0:00:00\n" |
| 119 | " ICMP: db00::1 -> db00::2\n" |
| 120 | " incrementing 30\n" |
| 121 | " }\n" |
| 122 | "}\n" |
| 123 | "packet-generator new {\n" |
| 124 | " name makeentry\n" |
| 125 | " limit 15\n" |
| 126 | " size 128-128\n" |
| 127 | " interface loop0\n" |
| 128 | " node ethernet-input\n" |
| 129 | " data {\n" |
| 130 | " IP6: c8:bc:c8:5a:b0:0b -> 00:0d:ea:d0:00:00\n" |
| 131 | " ICMP: db00::1 -> db00::2\n" |
| 132 | " incrementing 30\n" |
| 133 | " }\n" |
| 134 | "}\n" |
| 135 | "packet-generator new {\n" |
| 136 | " name tx\n" |
| 137 | " limit 15\n" |
| 138 | " size 128-128\n" |
| 139 | " interface local0\n" |
| 140 | " tx-interface loop0\n" |
| 141 | " node loop0-output\n" |
| 142 | " data {\n" |
| 143 | " hex 0x01005e7ffffa000dead000000800" |
| 144 | "0102030405060708090a0b0c0d0e0f0102030405\n" |
| 145 | " }\n" |
| 146 | "}\n" |
| 147 | "trace add pg-input 2", |
| 148 | "pa en", |
| 149 | "show mactime verbose 2", |
| 150 | "show trace", |
| 151 | "show error", |
| 152 | ] |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 153 | |
| 154 | for cmd in cmds: |
Dave Barach | 5932ce1 | 2019-10-09 17:28:04 -0400 | [diff] [blame] | 155 | r = self.vapi.cli_return_response(cmd) |
| 156 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 157 | if hasattr(r, "reply"): |
Dave Barach | 5932ce1 | 2019-10-09 17:28:04 -0400 | [diff] [blame] | 158 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 159 | else: |
| 160 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 161 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 162 | |
| 163 | if __name__ == "__main__": |
Dave Barach | 7d31ab2 | 2019-05-08 19:18:18 -0400 | [diff] [blame] | 164 | unittest.main(testRunner=VppTestRunner) |