blob: a3e7e041ba1789a3f55af9db759a110acca64b6f [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
5
6""" TestArping is a subclass of VPPTestCase classes.
7
8Basic test for sanity check of arping.
9
10"""
11
12
13class TestArping(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020014 """Arping Test Case"""
Steven Luonga77ae472021-02-14 11:37:02 -080015
16 @classmethod
17 def setUpClass(cls):
18 super(TestArping, cls).setUpClass()
19 try:
20 cls.create_pg_interfaces(range(2))
21 cls.interfaces = list(cls.pg_interfaces)
22
23 for i in cls.interfaces:
24 i.admin_up()
25 i.config_ip4()
26 i.config_ip6()
27 i.disable_ipv6_ra()
28 i.resolve_arp()
29 i.resolve_ndp()
30 except Exception:
31 super(TestArping, cls).tearDownClass()
32 raise
33
34 @classmethod
35 def tearDownClass(cls):
36 super(TestArping, cls).tearDownClass()
37
38 def tearDown(self):
39 super(TestArping, self).tearDown()
40
41 def show_commands_at_teardown(self):
42 self.logger.info(self.vapi.cli("show hardware"))
43
44 def verify_arping_request(self, p, src, dst):
45 arp = p[ARP]
46 self.assertEqual(arp.hwtype, 0x0001)
47 self.assertEqual(arp.ptype, 0x0800)
48 self.assertEqual(arp.hwlen, 6)
49 self.assertEqual(arp.op, 1)
50 self.assertEqual(arp.psrc, src)
51 self.assertEqual(arp.pdst, dst)
52
53 def verify_arping_ip6_ns(self, p, src, dst):
54 icmpv6 = p[ICMPv6ND_NS]
55 self.assertEqual(icmpv6.type, 135)
56 self.assertEqual(icmpv6.tgt, dst)
57 ipv6 = p[IPv6]
58 self.assertEqual(src, ipv6.src)
59
60 def verify_arping_ip6_na(self, p, src, dst):
61 icmpv6 = p[ICMPv6ND_NA]
62 self.assertEqual(icmpv6.type, 136)
63 self.assertEqual(icmpv6.tgt, dst)
64 ipv6 = p[IPv6]
65 self.assertEqual(src, ipv6.src)
66
67 def test_arping_ip4_arp_request_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020068 """arping IP4 arp request CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -080069 try:
70 self.pg_enable_capture(self.pg_interfaces)
71 self.pg_start()
72 remote_ip4 = self.pg1.remote_ip4
73
74 ping_cmd = "arping " + remote_ip4 + "pg1 repeat 5 interval 0.1"
75 ret = self.vapi.cli(ping_cmd)
76 self.logger.info(ret)
77
78 ping_cmd = "arping " + remote_ip4 + "pg1"
79 ret = self.vapi.cli(ping_cmd)
80 self.logger.info(ret)
81
82 out = self.pg1.get_capture(6)
83 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020084 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -080085 finally:
86 self.vapi.cli("show error")
87
88 def test_arping_ip4_garp_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 """arping ip4 gratuitous arp CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -080090 try:
91 self.pg_enable_capture(self.pg_interfaces)
92 self.pg_start()
93
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 ping_cmd = (
95 "arping gratuitous" + self.pg1.local_ip4 + "pg1 repeat 5 interval 0.1"
96 )
Steven Luonga77ae472021-02-14 11:37:02 -080097 ret = self.vapi.cli(ping_cmd)
98 self.logger.info(ret)
99
100 ping_cmd = "arping gratuitous" + self.pg1.local_ip4 + "pg1"
101 ret = self.vapi.cli(ping_cmd)
102 self.logger.info(ret)
103
104 out = self.pg1.get_capture(6)
105 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200106 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -0800107 finally:
108 self.vapi.cli("show error")
109
110 def test_arping_ip4_arp_request_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200111 """arping ip4 arp request API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800112 try:
113 self.pg_enable_capture(self.pg_interfaces)
114 self.pg_start()
115 remote_ip4 = self.pg1.remote_ip4
116
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200117 ret = self.vapi.arping(
118 address=remote_ip4,
119 sw_if_index=self.pg1.sw_if_index,
120 is_garp=0,
121 repeat=5,
122 interval=0.1,
123 )
Steven Luonga77ae472021-02-14 11:37:02 -0800124 self.logger.info(ret)
125
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200126 ret = self.vapi.arping(
127 address=remote_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=0
128 )
Steven Luonga77ae472021-02-14 11:37:02 -0800129 self.logger.info(ret)
130
131 out = self.pg1.get_capture(6)
132 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200133 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -0800134 finally:
135 self.vapi.cli("show error")
136
137 def test_arping_ip4_garp_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200138 """arping ip4 gratuitous arp API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800139 try:
140 self.pg_enable_capture(self.pg_interfaces)
141 self.pg_start()
142
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200143 ret = self.vapi.arping(
144 address=self.pg1.local_ip4,
145 sw_if_index=self.pg1.sw_if_index,
146 is_garp=1,
147 repeat=5,
148 interval=0.1,
149 )
Steven Luonga77ae472021-02-14 11:37:02 -0800150 self.logger.info(ret)
151
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200152 ret = self.vapi.arping(
153 address=self.pg1.local_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=1
154 )
Steven Luonga77ae472021-02-14 11:37:02 -0800155 self.logger.info(ret)
156
157 out = self.pg1.get_capture(6)
158 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200159 self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4)
Steven Luonga77ae472021-02-14 11:37:02 -0800160 finally:
161 self.vapi.cli("show error")
162
163 def test_arping_ip6_ns_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200164 """arping IP6 neighbor solicitation CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800165 try:
166 self.pg_enable_capture(self.pg_interfaces)
167 self.pg_start()
168 remote_ip6 = self.pg1.remote_ip6
169
170 ping_cmd = "arping " + remote_ip6 + "pg1 repeat 5 interval 0.1"
171 ret = self.vapi.cli(ping_cmd)
172 self.logger.info(ret)
173
174 ping_cmd = "arping " + remote_ip6 + "pg1"
175 ret = self.vapi.cli(ping_cmd)
176 self.logger.info(ret)
177
178 out = self.pg1.get_capture(6)
179 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200180 self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800181 finally:
182 self.vapi.cli("show error")
183
184 def test_arping_ip6_ns_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200185 """arping ip6 neighbor solicitation API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800186 try:
187 self.pg_enable_capture(self.pg_interfaces)
188 self.pg_start()
189 remote_ip6 = self.pg1.remote_ip6
190
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200191 ret = self.vapi.arping(
192 address=remote_ip6,
193 sw_if_index=self.pg1.sw_if_index,
194 is_garp=0,
195 repeat=5,
196 interval=0.1,
197 )
Steven Luonga77ae472021-02-14 11:37:02 -0800198 self.logger.info(ret)
199
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200200 ret = self.vapi.arping(
201 address=remote_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=0
202 )
Steven Luonga77ae472021-02-14 11:37:02 -0800203 self.logger.info(ret)
204
205 out = self.pg1.get_capture(6)
206 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200207 self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800208 finally:
209 self.vapi.cli("show error")
210
211 def test_arping_ip6_na_cli(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200212 """arping ip6 neighbor advertisement CLI test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800213 try:
214 self.pg_enable_capture(self.pg_interfaces)
215 self.pg_start()
216
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200217 ping_cmd = (
218 "arping gratuitous" + self.pg1.local_ip6 + "pg1 repeat 5 interval 0.1"
219 )
Steven Luonga77ae472021-02-14 11:37:02 -0800220 ret = self.vapi.cli(ping_cmd)
221 self.logger.info(ret)
222
223 ping_cmd = "arping gratuitous" + self.pg1.local_ip6 + "pg1"
224 ret = self.vapi.cli(ping_cmd)
225 self.logger.info(ret)
226
227 out = self.pg1.get_capture(6)
228 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200229 self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800230 finally:
231 self.vapi.cli("show error")
232
233 def test_arping_ip6_na_api(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200234 """arping ip6 neighbor advertisement API test"""
Steven Luonga77ae472021-02-14 11:37:02 -0800235 try:
236 self.pg_enable_capture(self.pg_interfaces)
237 self.pg_start()
238
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200239 ret = self.vapi.arping(
240 address=self.pg1.local_ip6,
241 sw_if_index=self.pg1.sw_if_index,
242 is_garp=1,
243 repeat=5,
244 interval=0.1,
245 )
Steven Luonga77ae472021-02-14 11:37:02 -0800246 self.logger.info(ret)
247
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200248 ret = self.vapi.arping(
249 address=self.pg1.local_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=1
250 )
Steven Luonga77ae472021-02-14 11:37:02 -0800251 self.logger.info(ret)
252
253 out = self.pg1.get_capture(6)
254 for p in out:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200255 self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6)
Steven Luonga77ae472021-02-14 11:37:02 -0800256 finally:
257 self.vapi.cli("show error")
258
259
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200260if __name__ == "__main__":
Steven Luonga77ae472021-02-14 11:37:02 -0800261 unittest.main(testRunner=VppTestRunner)