blob: 70d32bce9dace0e7272070abc2e77a819fc8bb6b [file] [log] [blame]
Dave Barachac0326f2020-07-14 18:30:05 -04001#!/usr/bin/env python3
2
3import unittest
4
Dave Wallace8800f732023-08-31 00:47:44 -04005from asfframework import VppAsfTestCase, VppTestRunner
Dmitry Valter34fa0ce2024-03-11 10:38:46 +00006from config import config
Dave Barachac0326f2020-07-14 18:30:05 -04007
8
Dmitry Valter34fa0ce2024-03-11 10:38:46 +00009@unittest.skipIf("adl" in config.excluded_plugins, "Exclude ADL plugin tests")
Dave Wallace8800f732023-08-31 00:47:44 -040010class TestAdl(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020011 """Allow/Deny Plugin Unit Test Cases"""
Dave Barachac0326f2020-07-14 18:30:05 -040012
13 @classmethod
14 def setUpClass(cls):
15 super(TestAdl, cls).setUpClass()
16
17 @classmethod
18 def tearDownClass(cls):
19 super(TestAdl, cls).tearDownClass()
20
21 def setUp(self):
22 super(TestAdl, self).setUp()
23
24 def tearDown(self):
25 super(TestAdl, self).tearDown()
26
27 def test_adl1_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020028 """Plugin API Test"""
29 cmds = [
30 "loop create\n",
31 "set int ip address loop0 192.168.1.1/24\n",
32 "set int ip6 table loop0 0\n",
33 "set int ip address loop0 2001:db01::1/64\n",
34 "set int state loop0 up\n",
35 "packet-generator new {\n"
36 " name ip4\n"
37 " limit 100\n"
38 " rate 0\n"
39 " size 128-128\n"
40 " interface loop0\n"
41 " node adl-input\n"
42 " data { IP4: 1.2.40 -> 3cfd.fed0.b6c8\n"
43 " UDP: 192.168.1.2-192.168.1.10 -> 192.168.2.1\n"
44 " UDP: 1234 -> 2345\n"
45 " incrementing 114\n"
46 " }\n"
47 " }\n",
48 "packet-generator new {\n"
49 " name ip6-allow\n"
50 " limit 50\n"
51 " rate 0\n"
52 " size 128-128\n"
53 " interface loop0\n"
54 " node adl-input\n"
55 " data { IP6: 1.2.40 -> 3cfd.fed0.b6c8\n"
56 " UDP: 2001:db01::2 -> 2001:db01::1\n"
57 " UDP: 1234 -> 2345\n"
58 " incrementing 80\n"
59 " }\n"
60 " }\n",
61 "packet-generator new {\n"
62 " name ip6-drop\n"
63 " limit 50\n"
64 " rate 0\n"
65 " size 128-128\n"
66 " interface loop0\n"
67 " node adl-input\n"
68 " data { IP6: 1.2.40 -> 3cfd.fed0.b6c8\n"
69 " UDP: 2001:db01::3 -> 2001:db01::1\n"
70 " UDP: 1234 -> 2345\n"
71 " incrementing 80\n"
72 " }\n"
73 " }\n",
74 "ip table 1\n",
75 "ip route add 192.168.2.1/32 via drop\n",
76 "ip route add table 1 192.168.1.2/32 via local\n",
77 "ip6 table 1\n",
78 "ip route add 2001:db01::1/128 via drop\n",
79 "ip route add table 1 2001:db01::2/128 via local\n",
80 "bin adl_interface_enable_disable loop0\n",
81 "bin adl_allowlist_enable_disable loop0 fib-id 1 ip4 ip6\n",
82 "pa en\n",
83 ]
Dave Barachac0326f2020-07-14 18:30:05 -040084
85 for cmd in cmds:
86 r = self.vapi.cli_return_response(cmd)
87 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020088 if hasattr(r, "reply"):
Dave Barachac0326f2020-07-14 18:30:05 -040089 self.logger.info(cmd + " FAIL reply " + r.reply)
90 else:
91 self.logger.info(cmd + " FAIL retval " + str(r.retval))
92
93 total_pkts = self.statistics.get_err_counter(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 "/err/adl-input/Allow/Deny packets processed"
95 )
Dave Barachac0326f2020-07-14 18:30:05 -040096
97 self.assertEqual(total_pkts, 200)
98
99 ip4_allow = self.statistics.get_err_counter(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200100 "/err/ip4-adl-allowlist/ip4 allowlist allowed"
101 )
Dave Barachac0326f2020-07-14 18:30:05 -0400102 self.assertEqual(ip4_allow, 12)
103 ip6_allow = self.statistics.get_err_counter(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200104 "/err/ip6-adl-allowlist/ip6 allowlist allowed"
105 )
Dave Barachac0326f2020-07-14 18:30:05 -0400106 self.assertEqual(ip6_allow, 50)
107
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200108
109if __name__ == "__main__":
Dave Barachac0326f2020-07-14 18:30:05 -0400110 unittest.main(testRunner=VppTestRunner)