5 from framework import VppTestCase, VppTestRunner, running_gcov_tests
6 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
9 class TestAdl(VppTestCase):
10 """ Allow/Deny Plugin Unit Test Cases """
14 super(TestAdl, cls).setUpClass()
17 def tearDownClass(cls):
18 super(TestAdl, cls).tearDownClass()
21 super(TestAdl, self).setUp()
24 super(TestAdl, self).tearDown()
26 def test_adl1_unittest(self):
27 """ Plugin API Test """
28 cmds = ["loop create\n",
29 "set int ip address loop0 192.168.1.1/24\n",
30 "set int ip6 table loop0 0\n",
31 "set int ip address loop0 2001:db01::1/64\n",
32 "set int state loop0 up\n",
33 "packet-generator new {\n"
40 " data { IP4: 1.2.40 -> 3cfd.fed0.b6c8\n"
41 " UDP: 192.168.1.2-192.168.1.10 -> 192.168.2.1\n"
42 " UDP: 1234 -> 2345\n"
46 "packet-generator new {\n"
53 " data { IP6: 1.2.40 -> 3cfd.fed0.b6c8\n"
54 " UDP: 2001:db01::2 -> 2001:db01::1\n"
55 " UDP: 1234 -> 2345\n"
59 "packet-generator new {\n"
66 " data { IP6: 1.2.40 -> 3cfd.fed0.b6c8\n"
67 " UDP: 2001:db01::3 -> 2001:db01::1\n"
68 " UDP: 1234 -> 2345\n"
73 "ip route add 192.168.2.1/32 via drop\n",
74 "ip route add table 1 192.168.1.2/32 via local\n",
76 "ip route add 2001:db01::1/128 via drop\n",
77 "ip route add table 1 2001:db01::2/128 via local\n",
78 "bin adl_interface_enable_disable loop0\n",
79 "bin adl_allowlist_enable_disable loop0 fib-id 1 ip4 ip6\n",
83 r = self.vapi.cli_return_response(cmd)
85 if hasattr(r, 'reply'):
86 self.logger.info(cmd + " FAIL reply " + r.reply)
88 self.logger.info(cmd + " FAIL retval " + str(r.retval))
90 total_pkts = self.statistics.get_err_counter(
91 "/err/adl-input/Allow/Deny packets processed")
93 self.assertEqual(total_pkts, 200)
95 ip4_allow = self.statistics.get_err_counter(
96 "/err/ip4-adl-allowlist/ip4 allowlist allowed")
97 self.assertEqual(ip4_allow, 12)
98 ip6_allow = self.statistics.get_err_counter(
99 "/err/ip6-adl-allowlist/ip6 allowlist allowed")
100 self.assertEqual(ip6_allow, 50)
102 if __name__ == '__main__':
103 unittest.main(testRunner=VppTestRunner)