4 from socket import AF_INET, AF_INET6, inet_pton
6 from framework import VppTestCase, VppTestRunner
7 from vpp_neighbor import VppNeighbor, find_nbr
8 from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, \
11 from scapy.packet import Raw
12 from scapy.layers.l2 import Ether, ARP, Dot1Q
13 from scapy.layers.inet import IP, UDP
14 from scapy.contrib.mpls import MPLS
16 # not exported by scapy, so redefined here
17 arp_opts = {"who-has": 1, "is-at": 2}
20 class ARPTestCase(VppTestCase):
24 super(ARPTestCase, self).setUp()
26 # create 3 pg interfaces
27 self.create_pg_interfaces(range(4))
29 # pg0 configured with ip4 and 6 addresses used for input
30 # pg1 configured with ip4 and 6 addresses used for output
31 # pg2 is unnumbered to pg0
32 for i in self.pg_interfaces:
37 self.pg0.resolve_arp()
42 # pg3 in a different VRF
43 self.tbl = VppIpTable(self, 1)
44 self.tbl.add_vpp_config()
46 self.pg3.set_table_ip4(1)
50 self.pg0.unconfig_ip4()
51 self.pg0.unconfig_ip6()
53 self.pg1.unconfig_ip4()
54 self.pg1.unconfig_ip6()
56 self.pg3.unconfig_ip4()
57 self.pg3.set_table_ip4(0)
59 for i in self.pg_interfaces:
62 super(ARPTestCase, self).tearDown()
64 def verify_arp_req(self, rx, smac, sip, dip):
66 self.assertEqual(ether.dst, "ff:ff:ff:ff:ff:ff")
67 self.assertEqual(ether.src, smac)
70 self.assertEqual(arp.hwtype, 1)
71 self.assertEqual(arp.ptype, 0x800)
72 self.assertEqual(arp.hwlen, 6)
73 self.assertEqual(arp.plen, 4)
74 self.assertEqual(arp.op, arp_opts["who-has"])
75 self.assertEqual(arp.hwsrc, smac)
76 self.assertEqual(arp.hwdst, "00:00:00:00:00:00")
77 self.assertEqual(arp.psrc, sip)
78 self.assertEqual(arp.pdst, dip)
80 def verify_arp_resp(self, rx, smac, dmac, sip, dip):
82 self.assertEqual(ether.dst, dmac)
83 self.assertEqual(ether.src, smac)
86 self.assertEqual(arp.hwtype, 1)
87 self.assertEqual(arp.ptype, 0x800)
88 self.assertEqual(arp.hwlen, 6)
89 self.assertEqual(arp.plen, 4)
90 self.assertEqual(arp.op, arp_opts["is-at"])
91 self.assertEqual(arp.hwsrc, smac)
92 self.assertEqual(arp.hwdst, dmac)
93 self.assertEqual(arp.psrc, sip)
94 self.assertEqual(arp.pdst, dip)
96 def verify_arp_vrrp_resp(self, rx, smac, dmac, sip, dip):
98 self.assertEqual(ether.dst, dmac)
99 self.assertEqual(ether.src, smac)
102 self.assertEqual(arp.hwtype, 1)
103 self.assertEqual(arp.ptype, 0x800)
104 self.assertEqual(arp.hwlen, 6)
105 self.assertEqual(arp.plen, 4)
106 self.assertEqual(arp.op, arp_opts["is-at"])
107 self.assertNotEqual(arp.hwsrc, smac)
108 self.assertTrue("00:00:5e:00:01" in arp.hwsrc or
109 "00:00:5E:00:01" in arp.hwsrc)
110 self.assertEqual(arp.hwdst, dmac)
111 self.assertEqual(arp.psrc, sip)
112 self.assertEqual(arp.pdst, dip)
114 def verify_ip(self, rx, smac, dmac, sip, dip):
116 self.assertEqual(ether.dst, dmac)
117 self.assertEqual(ether.src, smac)
120 self.assertEqual(ip.src, sip)
121 self.assertEqual(ip.dst, dip)
123 def verify_ip_o_mpls(self, rx, smac, dmac, label, sip, dip):
125 self.assertEqual(ether.dst, dmac)
126 self.assertEqual(ether.src, smac)
129 self.assertTrue(mpls.label, label)
132 self.assertEqual(ip.src, sip)
133 self.assertEqual(ip.dst, dip)
135 def send_and_assert_no_replies(self, intf, pkts, remark):
136 intf.add_stream(pkts)
137 self.pg_enable_capture(self.pg_interfaces)
140 for i in self.pg_interfaces:
141 i.get_capture(0, timeout=timeout)
142 i.assert_nothing_captured(remark=remark)
149 # Generate some hosts on the LAN
151 self.pg1.generate_remote_hosts(11)
154 # Send IP traffic to one of these unresolved hosts.
155 # expect the generation of an ARP request
157 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
158 IP(src=self.pg0.remote_ip4, dst=self.pg1._remote_hosts[1].ip4) /
159 UDP(sport=1234, dport=1234) /
162 self.pg0.add_stream(p)
163 self.pg_enable_capture(self.pg_interfaces)
166 rx = self.pg1.get_capture(1)
168 self.verify_arp_req(rx[0],
171 self.pg1._remote_hosts[1].ip4)
174 # And a dynamic ARP entry for host 1
176 dyn_arp = VppNeighbor(self,
177 self.pg1.sw_if_index,
178 self.pg1.remote_hosts[1].mac,
179 self.pg1.remote_hosts[1].ip4)
180 dyn_arp.add_vpp_config()
183 # now we expect IP traffic forwarded
185 dyn_p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
186 IP(src=self.pg0.remote_ip4,
187 dst=self.pg1._remote_hosts[1].ip4) /
188 UDP(sport=1234, dport=1234) /
191 self.pg0.add_stream(dyn_p)
192 self.pg_enable_capture(self.pg_interfaces)
195 rx = self.pg1.get_capture(1)
197 self.verify_ip(rx[0],
199 self.pg1.remote_hosts[1].mac,
201 self.pg1._remote_hosts[1].ip4)
204 # And a Static ARP entry for host 2
206 static_arp = VppNeighbor(self,
207 self.pg1.sw_if_index,
208 self.pg1.remote_hosts[2].mac,
209 self.pg1.remote_hosts[2].ip4,
211 static_arp.add_vpp_config()
213 static_p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
214 IP(src=self.pg0.remote_ip4,
215 dst=self.pg1._remote_hosts[2].ip4) /
216 UDP(sport=1234, dport=1234) /
219 self.pg0.add_stream(static_p)
220 self.pg_enable_capture(self.pg_interfaces)
223 rx = self.pg1.get_capture(1)
225 self.verify_ip(rx[0],
227 self.pg1.remote_hosts[2].mac,
229 self.pg1._remote_hosts[2].ip4)
232 # flap the link. dynamic ARPs get flush, statics don't
234 self.pg1.admin_down()
237 self.pg0.add_stream(static_p)
238 self.pg_enable_capture(self.pg_interfaces)
240 rx = self.pg1.get_capture(1)
242 self.verify_ip(rx[0],
244 self.pg1.remote_hosts[2].mac,
246 self.pg1._remote_hosts[2].ip4)
248 self.pg0.add_stream(dyn_p)
249 self.pg_enable_capture(self.pg_interfaces)
252 rx = self.pg1.get_capture(1)
253 self.verify_arp_req(rx[0],
256 self.pg1._remote_hosts[1].ip4)
259 # Send an ARP request from one of the so-far unlearned remote hosts
261 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
262 src=self.pg1._remote_hosts[3].mac) /
264 hwsrc=self.pg1._remote_hosts[3].mac,
265 pdst=self.pg1.local_ip4,
266 psrc=self.pg1._remote_hosts[3].ip4))
268 self.pg1.add_stream(p)
269 self.pg_enable_capture(self.pg_interfaces)
272 rx = self.pg1.get_capture(1)
273 self.verify_arp_resp(rx[0],
275 self.pg1._remote_hosts[3].mac,
277 self.pg1._remote_hosts[3].ip4)
280 # VPP should have learned the mapping for the remote host
282 self.assertTrue(find_nbr(self,
283 self.pg1.sw_if_index,
284 self.pg1._remote_hosts[3].ip4))
286 # Fire in an ARP request before the interface becomes IP enabled
288 self.pg2.generate_remote_hosts(4)
290 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
292 hwsrc=self.pg2.remote_mac,
293 pdst=self.pg1.local_ip4,
294 psrc=self.pg2.remote_hosts[3].ip4))
295 pt = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
298 hwsrc=self.pg2.remote_mac,
299 pdst=self.pg1.local_ip4,
300 psrc=self.pg2.remote_hosts[3].ip4))
301 self.send_and_assert_no_replies(self.pg2, p,
302 "interface not IP enabled")
305 # Make pg2 un-numbered to pg1
307 self.pg2.set_unnumbered(self.pg1.sw_if_index)
310 # We should respond to ARP requests for the unnumbered to address
311 # once an attached route to the source is known
313 self.send_and_assert_no_replies(
315 "ARP req for unnumbered address - no source")
317 attached_host = VppIpRoute(self, self.pg2.remote_hosts[3].ip4, 32,
318 [VppRoutePath("0.0.0.0",
319 self.pg2.sw_if_index)])
320 attached_host.add_vpp_config()
322 self.pg2.add_stream(p)
323 self.pg_enable_capture(self.pg_interfaces)
326 rx = self.pg2.get_capture(1)
327 self.verify_arp_resp(rx[0],
331 self.pg2.remote_hosts[3].ip4)
333 self.pg2.add_stream(pt)
334 self.pg_enable_capture(self.pg_interfaces)
337 rx = self.pg2.get_capture(1)
338 self.verify_arp_resp(rx[0],
342 self.pg2.remote_hosts[3].ip4)
345 # A neighbor entry that has no associated FIB-entry
347 arp_no_fib = VppNeighbor(self,
348 self.pg1.sw_if_index,
349 self.pg1.remote_hosts[4].mac,
350 self.pg1.remote_hosts[4].ip4,
352 arp_no_fib.add_vpp_config()
355 # check we have the neighbor, but no route
357 self.assertTrue(find_nbr(self,
358 self.pg1.sw_if_index,
359 self.pg1._remote_hosts[4].ip4))
360 self.assertFalse(find_route(self,
361 self.pg1._remote_hosts[4].ip4,
364 # pg2 is unnumbered to pg1, so we can form adjacencies out of pg2
365 # from within pg1's subnet
367 arp_unnum = VppNeighbor(self,
368 self.pg2.sw_if_index,
369 self.pg1.remote_hosts[5].mac,
370 self.pg1.remote_hosts[5].ip4)
371 arp_unnum.add_vpp_config()
373 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
374 IP(src=self.pg0.remote_ip4,
375 dst=self.pg1._remote_hosts[5].ip4) /
376 UDP(sport=1234, dport=1234) /
379 self.pg0.add_stream(p)
380 self.pg_enable_capture(self.pg_interfaces)
383 rx = self.pg2.get_capture(1)
385 self.verify_ip(rx[0],
387 self.pg1.remote_hosts[5].mac,
389 self.pg1._remote_hosts[5].ip4)
392 # ARP requests from hosts in pg1's subnet sent on pg2 are replied to
393 # with the unnumbered interface's address as the source
395 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
397 hwsrc=self.pg2.remote_mac,
398 pdst=self.pg1.local_ip4,
399 psrc=self.pg1.remote_hosts[6].ip4))
401 self.pg2.add_stream(p)
402 self.pg_enable_capture(self.pg_interfaces)
405 rx = self.pg2.get_capture(1)
406 self.verify_arp_resp(rx[0],
410 self.pg1.remote_hosts[6].ip4)
413 # An attached host route out of pg2 for an undiscovered hosts generates
414 # an ARP request with the unnumbered address as the source
416 att_unnum = VppIpRoute(self, self.pg1.remote_hosts[7].ip4, 32,
417 [VppRoutePath("0.0.0.0",
418 self.pg2.sw_if_index)])
419 att_unnum.add_vpp_config()
421 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
422 IP(src=self.pg0.remote_ip4,
423 dst=self.pg1._remote_hosts[7].ip4) /
424 UDP(sport=1234, dport=1234) /
427 self.pg0.add_stream(p)
428 self.pg_enable_capture(self.pg_interfaces)
431 rx = self.pg2.get_capture(1)
433 self.verify_arp_req(rx[0],
436 self.pg1._remote_hosts[7].ip4)
438 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
440 hwsrc=self.pg2.remote_mac,
441 pdst=self.pg1.local_ip4,
442 psrc=self.pg1.remote_hosts[7].ip4))
444 self.pg2.add_stream(p)
445 self.pg_enable_capture(self.pg_interfaces)
448 rx = self.pg2.get_capture(1)
449 self.verify_arp_resp(rx[0],
453 self.pg1.remote_hosts[7].ip4)
456 # An attached host route as yet unresolved out of pg2 for an
457 # undiscovered host, an ARP requests begets a response.
459 att_unnum1 = VppIpRoute(self, self.pg1.remote_hosts[8].ip4, 32,
460 [VppRoutePath("0.0.0.0",
461 self.pg2.sw_if_index)])
462 att_unnum1.add_vpp_config()
464 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
466 hwsrc=self.pg2.remote_mac,
467 pdst=self.pg1.local_ip4,
468 psrc=self.pg1.remote_hosts[8].ip4))
470 self.pg2.add_stream(p)
471 self.pg_enable_capture(self.pg_interfaces)
474 rx = self.pg2.get_capture(1)
475 self.verify_arp_resp(rx[0],
479 self.pg1.remote_hosts[8].ip4)
482 # Send an ARP request from one of the so-far unlearned remote hosts
485 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
486 src=self.pg1._remote_hosts[9].mac) /
489 hwsrc=self.pg1._remote_hosts[9].mac,
490 pdst=self.pg1.local_ip4,
491 psrc=self.pg1._remote_hosts[9].ip4))
493 self.pg1.add_stream(p)
494 self.pg_enable_capture(self.pg_interfaces)
497 rx = self.pg1.get_capture(1)
498 self.verify_arp_resp(rx[0],
500 self.pg1._remote_hosts[9].mac,
502 self.pg1._remote_hosts[9].ip4)
505 # Add a hierachy of routes for a host in the sub-net.
506 # Should still get an ARP resp since the cover is attached
508 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg1.remote_mac) /
510 hwsrc=self.pg1.remote_mac,
511 pdst=self.pg1.local_ip4,
512 psrc=self.pg1.remote_hosts[10].ip4))
514 r1 = VppIpRoute(self, self.pg1.remote_hosts[10].ip4, 30,
515 [VppRoutePath(self.pg1.remote_hosts[10].ip4,
516 self.pg1.sw_if_index)])
519 self.pg1.add_stream(p)
520 self.pg_enable_capture(self.pg_interfaces)
522 rx = self.pg1.get_capture(1)
523 self.verify_arp_resp(rx[0],
527 self.pg1.remote_hosts[10].ip4)
529 r2 = VppIpRoute(self, self.pg1.remote_hosts[10].ip4, 32,
530 [VppRoutePath(self.pg1.remote_hosts[10].ip4,
531 self.pg1.sw_if_index)])
534 self.pg1.add_stream(p)
535 self.pg_enable_capture(self.pg_interfaces)
537 rx = self.pg1.get_capture(1)
538 self.verify_arp_resp(rx[0],
542 self.pg1.remote_hosts[10].ip4)
545 # add an ARP entry that's not on the sub-net and so whose
546 # adj-fib fails the refinement check. then send an ARP request
549 a1 = VppNeighbor(self,
550 self.pg0.sw_if_index,
555 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
557 hwsrc=self.pg0.remote_mac,
558 psrc="100.100.100.50",
559 pdst=self.pg0.remote_ip4))
560 self.send_and_assert_no_replies(self.pg0, p,
561 "ARP req for from failed adj-fib")
565 # 1 - don't respond to ARP request for address not within the
566 # interface's sub-net
567 # 1b - nor within the unnumbered subnet
568 # 1c - nor within the subnet of a different interface
570 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
572 hwsrc=self.pg0.remote_mac,
574 psrc=self.pg0.remote_ip4))
575 self.send_and_assert_no_replies(self.pg0, p,
576 "ARP req for non-local destination")
577 self.assertFalse(find_nbr(self,
578 self.pg0.sw_if_index,
581 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
583 hwsrc=self.pg2.remote_mac,
585 psrc=self.pg1.remote_hosts[7].ip4))
586 self.send_and_assert_no_replies(
588 "ARP req for non-local destination - unnum")
590 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
592 hwsrc=self.pg0.remote_mac,
593 pdst=self.pg1.local_ip4,
594 psrc=self.pg1.remote_ip4))
595 self.send_and_assert_no_replies(self.pg0, p,
596 "ARP req diff sub-net")
597 self.assertFalse(find_nbr(self,
598 self.pg0.sw_if_index,
599 self.pg1.remote_ip4))
602 # 2 - don't respond to ARP request from an address not within the
603 # interface's sub-net
604 # 2b - to a prxied address
605 # 2c - not within a differents interface's sub-net
606 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
608 hwsrc=self.pg0.remote_mac,
610 pdst=self.pg0.local_ip4))
611 self.send_and_assert_no_replies(self.pg0, p,
612 "ARP req for non-local source")
613 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
615 hwsrc=self.pg2.remote_mac,
617 pdst=self.pg0.local_ip4))
618 self.send_and_assert_no_replies(
620 "ARP req for non-local source - unnum")
621 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
623 hwsrc=self.pg0.remote_mac,
624 psrc=self.pg1.remote_ip4,
625 pdst=self.pg0.local_ip4))
626 self.send_and_assert_no_replies(self.pg0, p,
627 "ARP req for non-local source 2c")
630 # 3 - don't respond to ARP request from an address that belongs to
633 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
635 hwsrc=self.pg0.remote_mac,
636 psrc=self.pg0.local_ip4,
637 pdst=self.pg0.local_ip4))
638 self.send_and_assert_no_replies(self.pg0, p,
639 "ARP req for non-local source")
642 # 4 - don't respond to ARP requests that has mac source different
643 # from ARP request HW source
646 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
648 hwsrc="00:00:00:DE:AD:BE",
649 psrc=self.pg0.remote_ip4,
650 pdst=self.pg0.local_ip4))
651 self.send_and_assert_no_replies(self.pg0, p,
652 "ARP req for non-local source")
657 dyn_arp.remove_vpp_config()
658 static_arp.remove_vpp_config()
659 self.pg2.unset_unnumbered(self.pg1.sw_if_index)
661 # need this to flush the adj-fibs
662 self.pg2.unset_unnumbered(self.pg1.sw_if_index)
663 self.pg2.admin_down()
664 self.pg1.admin_down()
666 def test_proxy_mirror_arp(self):
667 """ Interface Mirror Proxy ARP """
670 # When VPP has an interface whose address is also applied to a TAP
671 # interface on the host, then VPP's TAP interface will be unnumbered
672 # to the 'real' interface and do proxy ARP from the host.
673 # the curious aspect of this setup is that ARP requests from the host
674 # will come from the VPP's own address.
676 self.pg0.generate_remote_hosts(2)
678 arp_req_from_me = (Ether(src=self.pg2.remote_mac,
679 dst="ff:ff:ff:ff:ff:ff") /
681 hwsrc=self.pg2.remote_mac,
682 pdst=self.pg0.remote_hosts[1].ip4,
683 psrc=self.pg0.local_ip4))
686 # Configure Proxy ARP for the subnet on PG0addresses on pg0
688 self.vapi.proxy_arp_add_del(self.pg0._local_ip4n_subnet,
689 self.pg0._local_ip4n_bcast)
691 # Make pg2 un-numbered to pg0
693 self.pg2.set_unnumbered(self.pg0.sw_if_index)
696 # Enable pg2 for proxy ARP
698 self.pg2.set_proxy_arp()
701 # Send the ARP request with an originating address that
702 # is VPP's own address
704 self.pg2.add_stream(arp_req_from_me)
705 self.pg_enable_capture(self.pg_interfaces)
708 rx = self.pg2.get_capture(1)
709 self.verify_arp_resp(rx[0],
712 self.pg0.remote_hosts[1].ip4,
716 # validate we have not learned an ARP entry as a result of this
718 self.assertFalse(find_nbr(self,
719 self.pg2.sw_if_index,
725 self.pg2.set_proxy_arp(0)
726 self.vapi.proxy_arp_add_del(self.pg0._local_ip4n_subnet,
727 self.pg0._local_ip4n_bcast,
730 def test_proxy_arp(self):
733 self.pg1.generate_remote_hosts(2)
736 # Proxy ARP rewquest packets for each interface
738 arp_req_pg0 = (Ether(src=self.pg0.remote_mac,
739 dst="ff:ff:ff:ff:ff:ff") /
741 hwsrc=self.pg0.remote_mac,
743 psrc=self.pg0.remote_ip4))
744 arp_req_pg0_tagged = (Ether(src=self.pg0.remote_mac,
745 dst="ff:ff:ff:ff:ff:ff") /
748 hwsrc=self.pg0.remote_mac,
750 psrc=self.pg0.remote_ip4))
751 arp_req_pg1 = (Ether(src=self.pg1.remote_mac,
752 dst="ff:ff:ff:ff:ff:ff") /
754 hwsrc=self.pg1.remote_mac,
756 psrc=self.pg1.remote_ip4))
757 arp_req_pg2 = (Ether(src=self.pg2.remote_mac,
758 dst="ff:ff:ff:ff:ff:ff") /
760 hwsrc=self.pg2.remote_mac,
762 psrc=self.pg1.remote_hosts[1].ip4))
763 arp_req_pg3 = (Ether(src=self.pg3.remote_mac,
764 dst="ff:ff:ff:ff:ff:ff") /
766 hwsrc=self.pg3.remote_mac,
768 psrc=self.pg3.remote_ip4))
771 # Configure Proxy ARP for 10.10.10.0 -> 10.10.10.124
773 self.vapi.proxy_arp_add_del(inet_pton(AF_INET, "10.10.10.2"),
774 inet_pton(AF_INET, "10.10.10.124"))
777 # No responses are sent when the interfaces are not enabled for proxy
780 self.send_and_assert_no_replies(self.pg0, arp_req_pg0,
781 "ARP req from unconfigured interface")
782 self.send_and_assert_no_replies(self.pg2, arp_req_pg2,
783 "ARP req from unconfigured interface")
786 # Make pg2 un-numbered to pg1
789 self.pg2.set_unnumbered(self.pg1.sw_if_index)
791 self.send_and_assert_no_replies(self.pg2, arp_req_pg2,
792 "ARP req from unnumbered interface")
795 # Enable each interface to reply to proxy ARPs
797 for i in self.pg_interfaces:
801 # Now each of the interfaces should reply to a request to a proxied
804 self.pg0.add_stream(arp_req_pg0)
805 self.pg_enable_capture(self.pg_interfaces)
808 rx = self.pg0.get_capture(1)
809 self.verify_arp_resp(rx[0],
815 self.pg0.add_stream(arp_req_pg0_tagged)
816 self.pg_enable_capture(self.pg_interfaces)
819 rx = self.pg0.get_capture(1)
820 self.verify_arp_resp(rx[0],
826 self.pg1.add_stream(arp_req_pg1)
827 self.pg_enable_capture(self.pg_interfaces)
830 rx = self.pg1.get_capture(1)
831 self.verify_arp_resp(rx[0],
837 self.pg2.add_stream(arp_req_pg2)
838 self.pg_enable_capture(self.pg_interfaces)
841 rx = self.pg2.get_capture(1)
842 self.verify_arp_resp(rx[0],
846 self.pg1.remote_hosts[1].ip4)
849 # A request for an address out of the configured range
851 arp_req_pg1_hi = (Ether(src=self.pg1.remote_mac,
852 dst="ff:ff:ff:ff:ff:ff") /
854 hwsrc=self.pg1.remote_mac,
856 psrc=self.pg1.remote_ip4))
857 self.send_and_assert_no_replies(self.pg1, arp_req_pg1_hi,
858 "ARP req out of range HI")
859 arp_req_pg1_low = (Ether(src=self.pg1.remote_mac,
860 dst="ff:ff:ff:ff:ff:ff") /
862 hwsrc=self.pg1.remote_mac,
864 psrc=self.pg1.remote_ip4))
865 self.send_and_assert_no_replies(self.pg1, arp_req_pg1_low,
866 "ARP req out of range Low")
869 # Request for an address in the proxy range but from an interface
872 self.send_and_assert_no_replies(self.pg3, arp_req_pg3,
873 "ARP req from different VRF")
876 # Disable Each interface for proxy ARP
877 # - expect none to respond
879 for i in self.pg_interfaces:
882 self.send_and_assert_no_replies(self.pg0, arp_req_pg0,
883 "ARP req from disable")
884 self.send_and_assert_no_replies(self.pg1, arp_req_pg1,
885 "ARP req from disable")
886 self.send_and_assert_no_replies(self.pg2, arp_req_pg2,
887 "ARP req from disable")
890 # clean up on interface 2
892 self.pg2.unset_unnumbered(self.pg1.sw_if_index)
898 # Interface 2 does not yet have ip4 config
900 self.pg2.config_ip4()
901 self.pg2.generate_remote_hosts(2)
904 # Add a reoute with out going label via an ARP unresolved next-hop
906 ip_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32,
907 [VppRoutePath(self.pg2.remote_hosts[1].ip4,
908 self.pg2.sw_if_index,
910 ip_10_0_0_1.add_vpp_config()
913 # packets should generate an ARP request
915 p = (Ether(src=self.pg0.remote_mac,
916 dst=self.pg0.local_mac) /
917 IP(src=self.pg0.remote_ip4, dst="10.0.0.1") /
918 UDP(sport=1234, dport=1234) /
921 self.pg0.add_stream(p)
922 self.pg_enable_capture(self.pg_interfaces)
925 rx = self.pg2.get_capture(1)
926 self.verify_arp_req(rx[0],
929 self.pg2._remote_hosts[1].ip4)
932 # now resolve the neighbours
934 self.pg2.configure_ipv4_neighbors()
937 # Now packet should be properly MPLS encapped.
938 # This verifies that MPLS link-type adjacencies are completed
939 # when the ARP entry resolves
941 self.pg0.add_stream(p)
942 self.pg_enable_capture(self.pg_interfaces)
945 rx = self.pg2.get_capture(1)
946 self.verify_ip_o_mpls(rx[0],
948 self.pg2.remote_hosts[1].mac,
952 self.pg2.unconfig_ip4()
954 def test_arp_vrrp(self):
955 """ ARP reply with VRRP virtual src hw addr """
958 # IP packet destined for pg1 remote host arrives on pg0 resulting
959 # in an ARP request for the address of the remote host on pg1
961 p0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
962 IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) /
963 UDP(sport=1234, dport=1234) /
966 self.pg0.add_stream(p0)
967 self.pg_enable_capture(self.pg_interfaces)
970 rx1 = self.pg1.get_capture(1)
972 self.verify_arp_req(rx1[0],
978 # ARP reply for address of pg1 remote host arrives on pg1 with
979 # the hw src addr set to a value in the VRRP IPv4 range of
982 p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
983 ARP(op="is-at", hwdst=self.pg1.local_mac,
984 hwsrc="00:00:5e:00:01:09", pdst=self.pg1.local_ip4,
985 psrc=self.pg1.remote_ip4))
987 self.pg1.add_stream(p1)
988 self.pg_enable_capture(self.pg_interfaces)
992 # IP packet destined for pg1 remote host arrives on pg0 again.
993 # VPP should have an ARP entry for that address now and the packet
994 # should be sent out pg1.
996 self.pg0.add_stream(p0)
997 self.pg_enable_capture(self.pg_interfaces)
1000 rx1 = self.pg1.get_capture(1)
1002 self.verify_ip(rx1[0],
1004 "00:00:5e:00:01:09",
1005 self.pg0.remote_ip4,
1006 self.pg1.remote_ip4)
1008 self.pg1.admin_down()
1011 def test_arp_duplicates(self):
1012 """ ARP Duplicates"""
1015 # Generate some hosts on the LAN
1017 self.pg1.generate_remote_hosts(3)
1020 # Add host 1 on pg1 and pg2
1022 arp_pg1 = VppNeighbor(self,
1023 self.pg1.sw_if_index,
1024 self.pg1.remote_hosts[1].mac,
1025 self.pg1.remote_hosts[1].ip4)
1026 arp_pg1.add_vpp_config()
1027 arp_pg2 = VppNeighbor(self,
1028 self.pg2.sw_if_index,
1029 self.pg2.remote_mac,
1030 self.pg1.remote_hosts[1].ip4)
1031 arp_pg2.add_vpp_config()
1034 # IP packet destined for pg1 remote host arrives on pg1 again.
1036 p = (Ether(dst=self.pg0.local_mac,
1037 src=self.pg0.remote_mac) /
1038 IP(src=self.pg0.remote_ip4,
1039 dst=self.pg1.remote_hosts[1].ip4) /
1040 UDP(sport=1234, dport=1234) /
1043 self.pg0.add_stream(p)
1044 self.pg_enable_capture(self.pg_interfaces)
1047 rx1 = self.pg1.get_capture(1)
1049 self.verify_ip(rx1[0],
1051 self.pg1.remote_hosts[1].mac,
1052 self.pg0.remote_ip4,
1053 self.pg1.remote_hosts[1].ip4)
1056 # remove the duplicate on pg1
1057 # packet stream shoud generate ARPs out of pg1
1059 arp_pg1.remove_vpp_config()
1061 self.pg0.add_stream(p)
1062 self.pg_enable_capture(self.pg_interfaces)
1065 rx1 = self.pg1.get_capture(1)
1067 self.verify_arp_req(rx1[0],
1070 self.pg1.remote_hosts[1].ip4)
1075 arp_pg1.add_vpp_config()
1077 self.pg0.add_stream(p)
1078 self.pg_enable_capture(self.pg_interfaces)
1081 rx1 = self.pg1.get_capture(1)
1083 self.verify_ip(rx1[0],
1085 self.pg1.remote_hosts[1].mac,
1086 self.pg0.remote_ip4,
1087 self.pg1.remote_hosts[1].ip4)
1089 def test_arp_static(self):
1091 self.pg2.generate_remote_hosts(3)
1094 # Add a static ARP entry
1096 static_arp = VppNeighbor(self,
1097 self.pg2.sw_if_index,
1098 self.pg2.remote_hosts[1].mac,
1099 self.pg2.remote_hosts[1].ip4,
1101 static_arp.add_vpp_config()
1104 # Add the connected prefix to the interface
1106 self.pg2.config_ip4()
1109 # We should now find the adj-fib
1111 self.assertTrue(find_nbr(self,
1112 self.pg2.sw_if_index,
1113 self.pg2.remote_hosts[1].ip4,
1115 self.assertTrue(find_route(self,
1116 self.pg2.remote_hosts[1].ip4,
1120 # remove the connected
1122 self.pg2.unconfig_ip4()
1125 # put the interface into table 1
1127 self.pg2.set_table_ip4(1)
1130 # configure the same connected and expect to find the
1131 # adj fib in the new table
1133 self.pg2.config_ip4()
1134 self.assertTrue(find_route(self,
1135 self.pg2.remote_hosts[1].ip4,
1142 self.pg2.unconfig_ip4()
1143 self.pg2.set_table_ip4(0)
1146 if __name__ == '__main__':
1147 unittest.main(testRunner=VppTestRunner)