blob: bd8b6250a540ce0aaa0cef53ed2e01477990dd78 [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):
14 """ Arping Test Case """
15
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):
68 """ arping IP4 arp request CLI test """
69 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:
84 self.verify_arping_request(p, self.pg1.local_ip4,
85 self.pg1.remote_ip4)
86 finally:
87 self.vapi.cli("show error")
88
89 def test_arping_ip4_garp_cli(self):
90 """ arping ip4 gratuitous arp CLI test """
91 try:
92 self.pg_enable_capture(self.pg_interfaces)
93 self.pg_start()
94
95 ping_cmd = ("arping gratuitous" + self.pg1.local_ip4 +
96 "pg1 repeat 5 interval 0.1")
97 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:
106 self.verify_arping_request(p, self.pg1.local_ip4,
107 self.pg1.local_ip4)
108 finally:
109 self.vapi.cli("show error")
110
111 def test_arping_ip4_arp_request_api(self):
112 """ arping ip4 arp request API test """
113 try:
114 self.pg_enable_capture(self.pg_interfaces)
115 self.pg_start()
116 remote_ip4 = self.pg1.remote_ip4
117
118 ret = self.vapi.arping(address=remote_ip4,
119 sw_if_index=self.pg1.sw_if_index,
120 is_garp=0, repeat=5, interval=0.1)
121 self.logger.info(ret)
122
123 ret = self.vapi.arping(address=remote_ip4,
124 sw_if_index=self.pg1.sw_if_index,
125 is_garp=0)
126 self.logger.info(ret)
127
128 out = self.pg1.get_capture(6)
129 for p in out:
130 self.verify_arping_request(p, self.pg1.local_ip4,
131 self.pg1.remote_ip4)
132 finally:
133 self.vapi.cli("show error")
134
135 def test_arping_ip4_garp_api(self):
136 """ arping ip4 gratuitous arp API test """
137 try:
138 self.pg_enable_capture(self.pg_interfaces)
139 self.pg_start()
140
141 ret = self.vapi.arping(address=self.pg1.local_ip4,
142 sw_if_index=self.pg1.sw_if_index,
143 is_garp=1, repeat=5, interval=0.1)
144 self.logger.info(ret)
145
146 ret = self.vapi.arping(address=self.pg1.local_ip4,
147 sw_if_index=self.pg1.sw_if_index,
148 is_garp=1)
149 self.logger.info(ret)
150
151 out = self.pg1.get_capture(6)
152 for p in out:
153 self.verify_arping_request(p, self.pg1.local_ip4,
154 self.pg1.local_ip4)
155 finally:
156 self.vapi.cli("show error")
157
158 def test_arping_ip6_ns_cli(self):
159 """ arping IP6 neighbor solicitation CLI test """
160 try:
161 self.pg_enable_capture(self.pg_interfaces)
162 self.pg_start()
163 remote_ip6 = self.pg1.remote_ip6
164
165 ping_cmd = "arping " + remote_ip6 + "pg1 repeat 5 interval 0.1"
166 ret = self.vapi.cli(ping_cmd)
167 self.logger.info(ret)
168
169 ping_cmd = "arping " + remote_ip6 + "pg1"
170 ret = self.vapi.cli(ping_cmd)
171 self.logger.info(ret)
172
173 out = self.pg1.get_capture(6)
174 for p in out:
175 self.verify_arping_ip6_ns(p, self.pg1.local_ip6,
176 self.pg1.remote_ip6)
177 finally:
178 self.vapi.cli("show error")
179
180 def test_arping_ip6_ns_api(self):
181 """ arping ip6 neighbor solicitation API test """
182 try:
183 self.pg_enable_capture(self.pg_interfaces)
184 self.pg_start()
185 remote_ip6 = self.pg1.remote_ip6
186
187 ret = self.vapi.arping(address=remote_ip6,
188 sw_if_index=self.pg1.sw_if_index,
189 is_garp=0, repeat=5, interval=0.1)
190 self.logger.info(ret)
191
192 ret = self.vapi.arping(address=remote_ip6,
193 sw_if_index=self.pg1.sw_if_index,
194 is_garp=0)
195 self.logger.info(ret)
196
197 out = self.pg1.get_capture(6)
198 for p in out:
199 self.verify_arping_ip6_ns(p, self.pg1.local_ip6,
200 self.pg1.remote_ip6)
201 finally:
202 self.vapi.cli("show error")
203
204 def test_arping_ip6_na_cli(self):
205 """ arping ip6 neighbor advertisement CLI test """
206 try:
207 self.pg_enable_capture(self.pg_interfaces)
208 self.pg_start()
209
210 ping_cmd = ("arping gratuitous" + self.pg1.local_ip6 +
211 "pg1 repeat 5 interval 0.1")
212 ret = self.vapi.cli(ping_cmd)
213 self.logger.info(ret)
214
215 ping_cmd = "arping gratuitous" + self.pg1.local_ip6 + "pg1"
216 ret = self.vapi.cli(ping_cmd)
217 self.logger.info(ret)
218
219 out = self.pg1.get_capture(6)
220 for p in out:
221 self.verify_arping_ip6_na(p, self.pg1.local_ip6,
222 self.pg1.local_ip6)
223 finally:
224 self.vapi.cli("show error")
225
226 def test_arping_ip6_na_api(self):
227 """ arping ip6 neighbor advertisement API test """
228 try:
229 self.pg_enable_capture(self.pg_interfaces)
230 self.pg_start()
231
232 ret = self.vapi.arping(address=self.pg1.local_ip6,
233 sw_if_index=self.pg1.sw_if_index,
234 is_garp=1, repeat=5, interval=0.1)
235 self.logger.info(ret)
236
237 ret = self.vapi.arping(address=self.pg1.local_ip6,
238 sw_if_index=self.pg1.sw_if_index,
239 is_garp=1)
240 self.logger.info(ret)
241
242 out = self.pg1.get_capture(6)
243 for p in out:
244 self.verify_arping_ip6_na(p, self.pg1.local_ip6,
245 self.pg1.local_ip6)
246 finally:
247 self.vapi.cli("show error")
248
249
250if __name__ == '__main__':
251 unittest.main(testRunner=VppTestRunner)