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