blob: 435b15ee1212879e2f3f746bf937e0a95f02034a [file] [log] [blame]
Steven Luonga77ae472021-02-14 11:37:02 -08001from scapy.layers.l2 import ARP
2from scapy.layers.inet6 import ICMPv6ND_NS, ICMPv6ND_NA, IPv6
3
4from framework import VppTestCase
Dmitry Valter34fa0ce2024-03-11 10:38:46 +00005from config import config
6
7import unittest
Steven Luonga77ae472021-02-14 11:37:02 -08008
9""" TestArping is a subclass of VPPTestCase classes.
10
11Basic test for sanity check of arping.
12
13"""
14
15
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000016@unittest.skipIf("arping" in config.excluded_plugins, "Exclude Arping plugin tests")
Steven Luonga77ae472021-02-14 11:37:02 -080017class TestArping(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020018 """Arping Test Case"""
Steven Luonga77ae472021-02-14 11:37:02 -080019
20 @classmethod
21 def setUpClass(cls):
22 super(TestArping, cls).setUpClass()
23 try:
24 cls.create_pg_interfaces(range(2))
25 cls.interfaces = list(cls.pg_interfaces)
26
27 for i in cls.interfaces:
28 i.admin_up()
29 i.config_ip4()
30 i.config_ip6()
31 i.disable_ipv6_ra()
32 i.resolve_arp()
33 i.resolve_ndp()
34 except Exception:
35 super(TestArping, cls).tearDownClass()
36 raise
37
38 @classmethod
39 def tearDownClass(cls):
40 super(TestArping, cls).tearDownClass()
41
42 def tearDown(self):
43 super(TestArping, self).tearDown()
44
45 def show_commands_at_teardown(self):
46 self.logger.info(self.vapi.cli("show hardware"))
47
48 def verify_arping_request(self, p, src, dst):
49 arp = p[ARP]
50 self.assertEqual(arp.hwtype, 0x0001)
51 self.assertEqual(arp.ptype, 0x0800)
52 self.assertEqual(arp.hwlen, 6)
53 self.assertEqual(arp.op, 1)
54 self.assertEqual(arp.psrc, src)
55 self.assertEqual(arp.pdst, dst)
56
57 def verify_arping_ip6_ns(self, p, src, dst):
58 icmpv6 = p[ICMPv6ND_NS]
59 self.assertEqual(icmpv6.type, 135)
60 self.assertEqual(icmpv6.tgt, dst)
61 ipv6 = p[IPv6]
62 self.assertEqual(src, ipv6.src)
63
64 def verify_arping_ip6_na(self, p, src, dst):
65 icmpv6 = p[ICMPv6ND_NA]
66 self.assertEqual(icmpv6.type, 136)
67 self.assertEqual(icmpv6.tgt, dst)
68 ipv6 = p[IPv6]
69 self.assertEqual(src, ipv6.src)
70
71 def test_arping_ip4_arp_request_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020072 """arping IP4 arp request CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -080073 try:
74 self.pg_enable_capture(self.pg_interfaces)
75 self.pg_start()
76 remote_ip4 = self.pg1.remote_ip4
77
78 ping_cmd = "arping " + remote_ip4 + "pg1 repeat 5 interval 0.1"
79 ret = self.vapi.cli(ping_cmd)
80 self.logger.info(ret)
81
82 ping_cmd = "arping " + remote_ip4 + "pg1"
83 ret = self.vapi.cli(ping_cmd)
84 self.logger.info(ret)
85
86 out = self.pg1.get_capture(6)
87 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020088 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -080089 finally:
90 self.vapi.cli("show error")
91
92 def test_arping_ip4_garp_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020093 """arping ip4 gratuitous arp CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -080094 try:
95 self.pg_enable_capture(self.pg_interfaces)
96 self.pg_start()
97
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020098 ping_cmd = (
99 "arping gratuitous" + self.pg1.local_ip4 + "pg1 repeat 5 interval 0.1"
100 )
Steven Luonga77ae472021-02-14 11:37:02 -0800101 ret = self.vapi.cli(ping_cmd)
102 self.logger.info(ret)
103
104 ping_cmd = "arping gratuitous" + self.pg1.local_ip4 + "pg1"
105 ret = self.vapi.cli(ping_cmd)
106 self.logger.info(ret)
107
108 out = self.pg1.get_capture(6)
109 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200110 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -0800111 finally:
112 self.vapi.cli("show error")
113
114 def test_arping_ip4_arp_request_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200115 """arping ip4 arp request API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800116 try:
117 self.pg_enable_capture(self.pg_interfaces)
118 self.pg_start()
119 remote_ip4 = self.pg1.remote_ip4
120
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200121 ret = self.vapi.arping(
122 address=remote_ip4,
123 sw_if_index=self.pg1.sw_if_index,
124 is_garp=0,
125 repeat=5,
126 interval=0.1,
127 )
Steven Luonga77ae472021-02-14 11:37:02 -0800128 self.logger.info(ret)
129
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200130 ret = self.vapi.arping(
131 address=remote_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=0
132 )
Steven Luonga77ae472021-02-14 11:37:02 -0800133 self.logger.info(ret)
134
135 out = self.pg1.get_capture(6)
136 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200137 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -0800138 finally:
139 self.vapi.cli("show error")
140
141 def test_arping_ip4_garp_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200142 """arping ip4 gratuitous arp API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800143 try:
144 self.pg_enable_capture(self.pg_interfaces)
145 self.pg_start()
146
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200147 ret = self.vapi.arping(
148 address=self.pg1.local_ip4,
149 sw_if_index=self.pg1.sw_if_index,
150 is_garp=1,
151 repeat=5,
152 interval=0.1,
153 )
Steven Luonga77ae472021-02-14 11:37:02 -0800154 self.logger.info(ret)
155
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200156 ret = self.vapi.arping(
157 address=self.pg1.local_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=1
158 )
Steven Luonga77ae472021-02-14 11:37:02 -0800159 self.logger.info(ret)
160
161 out = self.pg1.get_capture(6)
162 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200163 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -0800164 finally:
165 self.vapi.cli("show error")
166
167 def test_arping_ip6_ns_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200168 """arping IP6 neighbor solicitation CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800169 try:
170 self.pg_enable_capture(self.pg_interfaces)
171 self.pg_start()
172 remote_ip6 = self.pg1.remote_ip6
173
174 ping_cmd = "arping " + remote_ip6 + "pg1 repeat 5 interval 0.1"
175 ret = self.vapi.cli(ping_cmd)
176 self.logger.info(ret)
177
178 ping_cmd = "arping " + remote_ip6 + "pg1"
179 ret = self.vapi.cli(ping_cmd)
180 self.logger.info(ret)
181
182 out = self.pg1.get_capture(6)
183 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200184 self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800185 finally:
186 self.vapi.cli("show error")
187
188 def test_arping_ip6_ns_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200189 """arping ip6 neighbor solicitation API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800190 try:
191 self.pg_enable_capture(self.pg_interfaces)
192 self.pg_start()
193 remote_ip6 = self.pg1.remote_ip6
194
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200195 ret = self.vapi.arping(
196 address=remote_ip6,
197 sw_if_index=self.pg1.sw_if_index,
198 is_garp=0,
199 repeat=5,
200 interval=0.1,
201 )
Steven Luonga77ae472021-02-14 11:37:02 -0800202 self.logger.info(ret)
203
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200204 ret = self.vapi.arping(
205 address=remote_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=0
206 )
Steven Luonga77ae472021-02-14 11:37:02 -0800207 self.logger.info(ret)
208
209 out = self.pg1.get_capture(6)
210 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200211 self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800212 finally:
213 self.vapi.cli("show error")
214
215 def test_arping_ip6_na_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200216 """arping ip6 neighbor advertisement CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800217 try:
218 self.pg_enable_capture(self.pg_interfaces)
219 self.pg_start()
220
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200221 ping_cmd = (
222 "arping gratuitous" + self.pg1.local_ip6 + "pg1 repeat 5 interval 0.1"
223 )
Steven Luonga77ae472021-02-14 11:37:02 -0800224 ret = self.vapi.cli(ping_cmd)
225 self.logger.info(ret)
226
227 ping_cmd = "arping gratuitous" + self.pg1.local_ip6 + "pg1"
228 ret = self.vapi.cli(ping_cmd)
229 self.logger.info(ret)
230
231 out = self.pg1.get_capture(6)
232 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200233 self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800234 finally:
235 self.vapi.cli("show error")
236
237 def test_arping_ip6_na_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200238 """arping ip6 neighbor advertisement API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800239 try:
240 self.pg_enable_capture(self.pg_interfaces)
241 self.pg_start()
242
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200243 ret = self.vapi.arping(
244 address=self.pg1.local_ip6,
245 sw_if_index=self.pg1.sw_if_index,
246 is_garp=1,
247 repeat=5,
248 interval=0.1,
249 )
Steven Luonga77ae472021-02-14 11:37:02 -0800250 self.logger.info(ret)
251
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200252 ret = self.vapi.arping(
253 address=self.pg1.local_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=1
254 )
Steven Luonga77ae472021-02-14 11:37:02 -0800255 self.logger.info(ret)
256
257 out = self.pg1.get_capture(6)
258 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200259 self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800260 finally:
261 self.vapi.cli("show error")
262
263
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200264if __name__ == "__main__":
Steven Luonga77ae472021-02-14 11:37:02 -0800265 unittest.main(testRunner=VppTestRunner)