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)
139 # Generate some hosts on the LAN
141 self.pg1.generate_remote_hosts(11)
144 # Send IP traffic to one of these unresolved hosts.
145 # expect the generation of an ARP request
147 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
148 IP(src=self.pg0.remote_ip4, dst=self.pg1._remote_hosts[1].ip4) /
149 UDP(sport=1234, dport=1234) /
152 self.pg0.add_stream(p)
153 self.pg_enable_capture(self.pg_interfaces)
156 rx = self.pg1.get_capture(1)
158 self.verify_arp_req(rx[0],
161 self.pg1._remote_hosts[1].ip4)
164 # And a dynamic ARP entry for host 1
166 dyn_arp = VppNeighbor(self,
167 self.pg1.sw_if_index,
168 self.pg1.remote_hosts[1].mac,
169 self.pg1.remote_hosts[1].ip4)
170 dyn_arp.add_vpp_config()
173 # now we expect IP traffic forwarded
175 dyn_p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
176 IP(src=self.pg0.remote_ip4,
177 dst=self.pg1._remote_hosts[1].ip4) /
178 UDP(sport=1234, dport=1234) /
181 self.pg0.add_stream(dyn_p)
182 self.pg_enable_capture(self.pg_interfaces)
185 rx = self.pg1.get_capture(1)
187 self.verify_ip(rx[0],
189 self.pg1.remote_hosts[1].mac,
191 self.pg1._remote_hosts[1].ip4)
194 # And a Static ARP entry for host 2
196 static_arp = VppNeighbor(self,
197 self.pg1.sw_if_index,
198 self.pg1.remote_hosts[2].mac,
199 self.pg1.remote_hosts[2].ip4,
201 static_arp.add_vpp_config()
203 static_p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
204 IP(src=self.pg0.remote_ip4,
205 dst=self.pg1._remote_hosts[2].ip4) /
206 UDP(sport=1234, dport=1234) /
209 self.pg0.add_stream(static_p)
210 self.pg_enable_capture(self.pg_interfaces)
213 rx = self.pg1.get_capture(1)
215 self.verify_ip(rx[0],
217 self.pg1.remote_hosts[2].mac,
219 self.pg1._remote_hosts[2].ip4)
222 # flap the link. dynamic ARPs get flush, statics don't
224 self.pg1.admin_down()
227 self.pg0.add_stream(static_p)
228 self.pg_enable_capture(self.pg_interfaces)
230 rx = self.pg1.get_capture(1)
232 self.verify_ip(rx[0],
234 self.pg1.remote_hosts[2].mac,
236 self.pg1._remote_hosts[2].ip4)
238 self.pg0.add_stream(dyn_p)
239 self.pg_enable_capture(self.pg_interfaces)
242 rx = self.pg1.get_capture(1)
243 self.verify_arp_req(rx[0],
246 self.pg1._remote_hosts[1].ip4)
249 # Send an ARP request from one of the so-far unlearned remote hosts
251 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
252 src=self.pg1._remote_hosts[3].mac) /
254 hwsrc=self.pg1._remote_hosts[3].mac,
255 pdst=self.pg1.local_ip4,
256 psrc=self.pg1._remote_hosts[3].ip4))
258 self.pg1.add_stream(p)
259 self.pg_enable_capture(self.pg_interfaces)
262 rx = self.pg1.get_capture(1)
263 self.verify_arp_resp(rx[0],
265 self.pg1._remote_hosts[3].mac,
267 self.pg1._remote_hosts[3].ip4)
270 # VPP should have learned the mapping for the remote host
272 self.assertTrue(find_nbr(self,
273 self.pg1.sw_if_index,
274 self.pg1._remote_hosts[3].ip4))
276 # Fire in an ARP request before the interface becomes IP enabled
278 self.pg2.generate_remote_hosts(4)
280 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
282 hwsrc=self.pg2.remote_mac,
283 pdst=self.pg1.local_ip4,
284 psrc=self.pg2.remote_hosts[3].ip4))
285 pt = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
288 hwsrc=self.pg2.remote_mac,
289 pdst=self.pg1.local_ip4,
290 psrc=self.pg2.remote_hosts[3].ip4))
291 self.send_and_assert_no_replies(self.pg2, p,
292 "interface not IP enabled")
295 # Make pg2 un-numbered to pg1
297 self.pg2.set_unnumbered(self.pg1.sw_if_index)
299 unnum = self.vapi.ip_unnumbered_dump()
300 self.assertEqual(unnum[0].ip_sw_if_index, self.pg1.sw_if_index)
301 self.assertEqual(unnum[0].sw_if_index, self.pg2.sw_if_index)
304 # We should respond to ARP requests for the unnumbered to address
305 # once an attached route to the source is known
307 self.send_and_assert_no_replies(
309 "ARP req for unnumbered address - no source")
311 attached_host = VppIpRoute(self, self.pg2.remote_hosts[3].ip4, 32,
312 [VppRoutePath("0.0.0.0",
313 self.pg2.sw_if_index)])
314 attached_host.add_vpp_config()
316 self.pg2.add_stream(p)
317 self.pg_enable_capture(self.pg_interfaces)
320 rx = self.pg2.get_capture(1)
321 self.verify_arp_resp(rx[0],
325 self.pg2.remote_hosts[3].ip4)
327 self.pg2.add_stream(pt)
328 self.pg_enable_capture(self.pg_interfaces)
331 rx = self.pg2.get_capture(1)
332 self.verify_arp_resp(rx[0],
336 self.pg2.remote_hosts[3].ip4)
339 # A neighbor entry that has no associated FIB-entry
341 arp_no_fib = VppNeighbor(self,
342 self.pg1.sw_if_index,
343 self.pg1.remote_hosts[4].mac,
344 self.pg1.remote_hosts[4].ip4,
346 arp_no_fib.add_vpp_config()
349 # check we have the neighbor, but no route
351 self.assertTrue(find_nbr(self,
352 self.pg1.sw_if_index,
353 self.pg1._remote_hosts[4].ip4))
354 self.assertFalse(find_route(self,
355 self.pg1._remote_hosts[4].ip4,
358 # pg2 is unnumbered to pg1, so we can form adjacencies out of pg2
359 # from within pg1's subnet
361 arp_unnum = VppNeighbor(self,
362 self.pg2.sw_if_index,
363 self.pg1.remote_hosts[5].mac,
364 self.pg1.remote_hosts[5].ip4)
365 arp_unnum.add_vpp_config()
367 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
368 IP(src=self.pg0.remote_ip4,
369 dst=self.pg1._remote_hosts[5].ip4) /
370 UDP(sport=1234, dport=1234) /
373 self.pg0.add_stream(p)
374 self.pg_enable_capture(self.pg_interfaces)
377 rx = self.pg2.get_capture(1)
379 self.verify_ip(rx[0],
381 self.pg1.remote_hosts[5].mac,
383 self.pg1._remote_hosts[5].ip4)
386 # ARP requests from hosts in pg1's subnet sent on pg2 are replied to
387 # with the unnumbered interface's address as the source
389 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
391 hwsrc=self.pg2.remote_mac,
392 pdst=self.pg1.local_ip4,
393 psrc=self.pg1.remote_hosts[6].ip4))
395 self.pg2.add_stream(p)
396 self.pg_enable_capture(self.pg_interfaces)
399 rx = self.pg2.get_capture(1)
400 self.verify_arp_resp(rx[0],
404 self.pg1.remote_hosts[6].ip4)
407 # An attached host route out of pg2 for an undiscovered hosts generates
408 # an ARP request with the unnumbered address as the source
410 att_unnum = VppIpRoute(self, self.pg1.remote_hosts[7].ip4, 32,
411 [VppRoutePath("0.0.0.0",
412 self.pg2.sw_if_index)])
413 att_unnum.add_vpp_config()
415 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
416 IP(src=self.pg0.remote_ip4,
417 dst=self.pg1._remote_hosts[7].ip4) /
418 UDP(sport=1234, dport=1234) /
421 self.pg0.add_stream(p)
422 self.pg_enable_capture(self.pg_interfaces)
425 rx = self.pg2.get_capture(1)
427 self.verify_arp_req(rx[0],
430 self.pg1._remote_hosts[7].ip4)
432 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
434 hwsrc=self.pg2.remote_mac,
435 pdst=self.pg1.local_ip4,
436 psrc=self.pg1.remote_hosts[7].ip4))
438 self.pg2.add_stream(p)
439 self.pg_enable_capture(self.pg_interfaces)
442 rx = self.pg2.get_capture(1)
443 self.verify_arp_resp(rx[0],
447 self.pg1.remote_hosts[7].ip4)
450 # An attached host route as yet unresolved out of pg2 for an
451 # undiscovered host, an ARP requests begets a response.
453 att_unnum1 = VppIpRoute(self, self.pg1.remote_hosts[8].ip4, 32,
454 [VppRoutePath("0.0.0.0",
455 self.pg2.sw_if_index)])
456 att_unnum1.add_vpp_config()
458 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
460 hwsrc=self.pg2.remote_mac,
461 pdst=self.pg1.local_ip4,
462 psrc=self.pg1.remote_hosts[8].ip4))
464 self.pg2.add_stream(p)
465 self.pg_enable_capture(self.pg_interfaces)
468 rx = self.pg2.get_capture(1)
469 self.verify_arp_resp(rx[0],
473 self.pg1.remote_hosts[8].ip4)
476 # Send an ARP request from one of the so-far unlearned remote hosts
479 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
480 src=self.pg1._remote_hosts[9].mac) /
483 hwsrc=self.pg1._remote_hosts[9].mac,
484 pdst=self.pg1.local_ip4,
485 psrc=self.pg1._remote_hosts[9].ip4))
487 self.pg1.add_stream(p)
488 self.pg_enable_capture(self.pg_interfaces)
491 rx = self.pg1.get_capture(1)
492 self.verify_arp_resp(rx[0],
494 self.pg1._remote_hosts[9].mac,
496 self.pg1._remote_hosts[9].ip4)
499 # Add a hierachy of routes for a host in the sub-net.
500 # Should still get an ARP resp since the cover is attached
502 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg1.remote_mac) /
504 hwsrc=self.pg1.remote_mac,
505 pdst=self.pg1.local_ip4,
506 psrc=self.pg1.remote_hosts[10].ip4))
508 r1 = VppIpRoute(self, self.pg1.remote_hosts[10].ip4, 30,
509 [VppRoutePath(self.pg1.remote_hosts[10].ip4,
510 self.pg1.sw_if_index)])
513 self.pg1.add_stream(p)
514 self.pg_enable_capture(self.pg_interfaces)
516 rx = self.pg1.get_capture(1)
517 self.verify_arp_resp(rx[0],
521 self.pg1.remote_hosts[10].ip4)
523 r2 = VppIpRoute(self, self.pg1.remote_hosts[10].ip4, 32,
524 [VppRoutePath(self.pg1.remote_hosts[10].ip4,
525 self.pg1.sw_if_index)])
528 self.pg1.add_stream(p)
529 self.pg_enable_capture(self.pg_interfaces)
531 rx = self.pg1.get_capture(1)
532 self.verify_arp_resp(rx[0],
536 self.pg1.remote_hosts[10].ip4)
539 # add an ARP entry that's not on the sub-net and so whose
540 # adj-fib fails the refinement check. then send an ARP request
543 a1 = VppNeighbor(self,
544 self.pg0.sw_if_index,
549 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
551 hwsrc=self.pg0.remote_mac,
552 psrc="100.100.100.50",
553 pdst=self.pg0.remote_ip4))
554 self.send_and_assert_no_replies(self.pg0, p,
555 "ARP req for from failed adj-fib")
559 # 1 - don't respond to ARP request for address not within the
560 # interface's sub-net
561 # 1b - nor within the unnumbered subnet
562 # 1c - nor within the subnet of a different interface
564 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
566 hwsrc=self.pg0.remote_mac,
568 psrc=self.pg0.remote_ip4))
569 self.send_and_assert_no_replies(self.pg0, p,
570 "ARP req for non-local destination")
571 self.assertFalse(find_nbr(self,
572 self.pg0.sw_if_index,
575 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
577 hwsrc=self.pg2.remote_mac,
579 psrc=self.pg1.remote_hosts[7].ip4))
580 self.send_and_assert_no_replies(
582 "ARP req for non-local destination - unnum")
584 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
586 hwsrc=self.pg0.remote_mac,
587 pdst=self.pg1.local_ip4,
588 psrc=self.pg1.remote_ip4))
589 self.send_and_assert_no_replies(self.pg0, p,
590 "ARP req diff sub-net")
591 self.assertFalse(find_nbr(self,
592 self.pg0.sw_if_index,
593 self.pg1.remote_ip4))
596 # 2 - don't respond to ARP request from an address not within the
597 # interface's sub-net
598 # 2b - to a prxied address
599 # 2c - not within a differents interface's sub-net
600 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
602 hwsrc=self.pg0.remote_mac,
604 pdst=self.pg0.local_ip4))
605 self.send_and_assert_no_replies(self.pg0, p,
606 "ARP req for non-local source")
607 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg2.remote_mac) /
609 hwsrc=self.pg2.remote_mac,
611 pdst=self.pg0.local_ip4))
612 self.send_and_assert_no_replies(
614 "ARP req for non-local source - unnum")
615 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
617 hwsrc=self.pg0.remote_mac,
618 psrc=self.pg1.remote_ip4,
619 pdst=self.pg0.local_ip4))
620 self.send_and_assert_no_replies(self.pg0, p,
621 "ARP req for non-local source 2c")
624 # 3 - don't respond to ARP request from an address that belongs to
627 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
629 hwsrc=self.pg0.remote_mac,
630 psrc=self.pg0.local_ip4,
631 pdst=self.pg0.local_ip4))
632 self.send_and_assert_no_replies(self.pg0, p,
633 "ARP req for non-local source")
636 # 4 - don't respond to ARP requests that has mac source different
637 # from ARP request HW source
639 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
641 hwsrc="00:00:00:DE:AD:BE",
642 psrc=self.pg0.remote_ip4,
643 pdst=self.pg0.local_ip4))
644 self.send_and_assert_no_replies(self.pg0, p,
645 "ARP req for non-local source")
648 # 5 - don't respond to ARP requests for address within the
649 # interface's sub-net but not the interface's address
651 self.pg0.generate_remote_hosts(2)
652 p = (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.pg0.remote_mac) /
654 hwsrc=self.pg0.remote_mac,
655 psrc=self.pg0.remote_hosts[0].ip4,
656 pdst=self.pg0.remote_hosts[1].ip4))
657 self.send_and_assert_no_replies(self.pg0, p,
658 "ARP req for non-local destination")
663 dyn_arp.remove_vpp_config()
664 static_arp.remove_vpp_config()
665 self.pg2.unset_unnumbered(self.pg1.sw_if_index)
667 # need this to flush the adj-fibs
668 self.pg2.unset_unnumbered(self.pg1.sw_if_index)
669 self.pg2.admin_down()
670 self.pg1.admin_down()
672 def test_proxy_mirror_arp(self):
673 """ Interface Mirror Proxy ARP """
676 # When VPP has an interface whose address is also applied to a TAP
677 # interface on the host, then VPP's TAP interface will be unnumbered
678 # to the 'real' interface and do proxy ARP from the host.
679 # the curious aspect of this setup is that ARP requests from the host
680 # will come from the VPP's own address.
682 self.pg0.generate_remote_hosts(2)
684 arp_req_from_me = (Ether(src=self.pg2.remote_mac,
685 dst="ff:ff:ff:ff:ff:ff") /
687 hwsrc=self.pg2.remote_mac,
688 pdst=self.pg0.remote_hosts[1].ip4,
689 psrc=self.pg0.local_ip4))
692 # Configure Proxy ARP for the subnet on PG0addresses on pg0
694 self.vapi.proxy_arp_add_del(self.pg0._local_ip4n_subnet,
695 self.pg0._local_ip4n_bcast)
697 # Make pg2 un-numbered to pg0
699 self.pg2.set_unnumbered(self.pg0.sw_if_index)
702 # Enable pg2 for proxy ARP
704 self.pg2.set_proxy_arp()
707 # Send the ARP request with an originating address that
708 # is VPP's own address
710 self.pg2.add_stream(arp_req_from_me)
711 self.pg_enable_capture(self.pg_interfaces)
714 rx = self.pg2.get_capture(1)
715 self.verify_arp_resp(rx[0],
718 self.pg0.remote_hosts[1].ip4,
722 # validate we have not learned an ARP entry as a result of this
724 self.assertFalse(find_nbr(self,
725 self.pg2.sw_if_index,
731 self.pg2.set_proxy_arp(0)
732 self.vapi.proxy_arp_add_del(self.pg0._local_ip4n_subnet,
733 self.pg0._local_ip4n_bcast,
736 def test_proxy_arp(self):
739 self.pg1.generate_remote_hosts(2)
742 # Proxy ARP rewquest packets for each interface
744 arp_req_pg0 = (Ether(src=self.pg0.remote_mac,
745 dst="ff:ff:ff:ff:ff:ff") /
747 hwsrc=self.pg0.remote_mac,
749 psrc=self.pg0.remote_ip4))
750 arp_req_pg0_tagged = (Ether(src=self.pg0.remote_mac,
751 dst="ff:ff:ff:ff:ff:ff") /
754 hwsrc=self.pg0.remote_mac,
756 psrc=self.pg0.remote_ip4))
757 arp_req_pg1 = (Ether(src=self.pg1.remote_mac,
758 dst="ff:ff:ff:ff:ff:ff") /
760 hwsrc=self.pg1.remote_mac,
762 psrc=self.pg1.remote_ip4))
763 arp_req_pg2 = (Ether(src=self.pg2.remote_mac,
764 dst="ff:ff:ff:ff:ff:ff") /
766 hwsrc=self.pg2.remote_mac,
768 psrc=self.pg1.remote_hosts[1].ip4))
769 arp_req_pg3 = (Ether(src=self.pg3.remote_mac,
770 dst="ff:ff:ff:ff:ff:ff") /
772 hwsrc=self.pg3.remote_mac,
774 psrc=self.pg3.remote_ip4))
777 # Configure Proxy ARP for 10.10.10.0 -> 10.10.10.124
779 self.vapi.proxy_arp_add_del(inet_pton(AF_INET, "10.10.10.2"),
780 inet_pton(AF_INET, "10.10.10.124"))
783 # No responses are sent when the interfaces are not enabled for proxy
786 self.send_and_assert_no_replies(self.pg0, arp_req_pg0,
787 "ARP req from unconfigured interface")
788 self.send_and_assert_no_replies(self.pg2, arp_req_pg2,
789 "ARP req from unconfigured interface")
792 # Make pg2 un-numbered to pg1
795 self.pg2.set_unnumbered(self.pg1.sw_if_index)
797 self.send_and_assert_no_replies(self.pg2, arp_req_pg2,
798 "ARP req from unnumbered interface")
801 # Enable each interface to reply to proxy ARPs
803 for i in self.pg_interfaces:
807 # Now each of the interfaces should reply to a request to a proxied
810 self.pg0.add_stream(arp_req_pg0)
811 self.pg_enable_capture(self.pg_interfaces)
814 rx = self.pg0.get_capture(1)
815 self.verify_arp_resp(rx[0],
821 self.pg0.add_stream(arp_req_pg0_tagged)
822 self.pg_enable_capture(self.pg_interfaces)
825 rx = self.pg0.get_capture(1)
826 self.verify_arp_resp(rx[0],
832 self.pg1.add_stream(arp_req_pg1)
833 self.pg_enable_capture(self.pg_interfaces)
836 rx = self.pg1.get_capture(1)
837 self.verify_arp_resp(rx[0],
843 self.pg2.add_stream(arp_req_pg2)
844 self.pg_enable_capture(self.pg_interfaces)
847 rx = self.pg2.get_capture(1)
848 self.verify_arp_resp(rx[0],
852 self.pg1.remote_hosts[1].ip4)
855 # A request for an address out of the configured range
857 arp_req_pg1_hi = (Ether(src=self.pg1.remote_mac,
858 dst="ff:ff:ff:ff:ff:ff") /
860 hwsrc=self.pg1.remote_mac,
862 psrc=self.pg1.remote_ip4))
863 self.send_and_assert_no_replies(self.pg1, arp_req_pg1_hi,
864 "ARP req out of range HI")
865 arp_req_pg1_low = (Ether(src=self.pg1.remote_mac,
866 dst="ff:ff:ff:ff:ff:ff") /
868 hwsrc=self.pg1.remote_mac,
870 psrc=self.pg1.remote_ip4))
871 self.send_and_assert_no_replies(self.pg1, arp_req_pg1_low,
872 "ARP req out of range Low")
875 # Request for an address in the proxy range but from an interface
878 self.send_and_assert_no_replies(self.pg3, arp_req_pg3,
879 "ARP req from different VRF")
882 # Disable Each interface for proxy ARP
883 # - expect none to respond
885 for i in self.pg_interfaces:
888 self.send_and_assert_no_replies(self.pg0, arp_req_pg0,
889 "ARP req from disable")
890 self.send_and_assert_no_replies(self.pg1, arp_req_pg1,
891 "ARP req from disable")
892 self.send_and_assert_no_replies(self.pg2, arp_req_pg2,
893 "ARP req from disable")
896 # clean up on interface 2
898 self.pg2.unset_unnumbered(self.pg1.sw_if_index)
904 # Interface 2 does not yet have ip4 config
906 self.pg2.config_ip4()
907 self.pg2.generate_remote_hosts(2)
910 # Add a reoute with out going label via an ARP unresolved next-hop
912 ip_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32,
913 [VppRoutePath(self.pg2.remote_hosts[1].ip4,
914 self.pg2.sw_if_index,
916 ip_10_0_0_1.add_vpp_config()
919 # packets should generate an ARP request
921 p = (Ether(src=self.pg0.remote_mac,
922 dst=self.pg0.local_mac) /
923 IP(src=self.pg0.remote_ip4, dst="10.0.0.1") /
924 UDP(sport=1234, dport=1234) /
927 self.pg0.add_stream(p)
928 self.pg_enable_capture(self.pg_interfaces)
931 rx = self.pg2.get_capture(1)
932 self.verify_arp_req(rx[0],
935 self.pg2._remote_hosts[1].ip4)
938 # now resolve the neighbours
940 self.pg2.configure_ipv4_neighbors()
943 # Now packet should be properly MPLS encapped.
944 # This verifies that MPLS link-type adjacencies are completed
945 # when the ARP entry resolves
947 self.pg0.add_stream(p)
948 self.pg_enable_capture(self.pg_interfaces)
951 rx = self.pg2.get_capture(1)
952 self.verify_ip_o_mpls(rx[0],
954 self.pg2.remote_hosts[1].mac,
958 self.pg2.unconfig_ip4()
960 def test_arp_vrrp(self):
961 """ ARP reply with VRRP virtual src hw addr """
964 # IP packet destined for pg1 remote host arrives on pg0 resulting
965 # in an ARP request for the address of the remote host on pg1
967 p0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
968 IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) /
969 UDP(sport=1234, dport=1234) /
972 self.pg0.add_stream(p0)
973 self.pg_enable_capture(self.pg_interfaces)
976 rx1 = self.pg1.get_capture(1)
978 self.verify_arp_req(rx1[0],
984 # ARP reply for address of pg1 remote host arrives on pg1 with
985 # the hw src addr set to a value in the VRRP IPv4 range of
988 p1 = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
989 ARP(op="is-at", hwdst=self.pg1.local_mac,
990 hwsrc="00:00:5e:00:01:09", pdst=self.pg1.local_ip4,
991 psrc=self.pg1.remote_ip4))
993 self.pg1.add_stream(p1)
994 self.pg_enable_capture(self.pg_interfaces)
998 # IP packet destined for pg1 remote host arrives on pg0 again.
999 # VPP should have an ARP entry for that address now and the packet
1000 # should be sent out pg1.
1002 self.pg0.add_stream(p0)
1003 self.pg_enable_capture(self.pg_interfaces)
1006 rx1 = self.pg1.get_capture(1)
1008 self.verify_ip(rx1[0],
1010 "00:00:5e:00:01:09",
1011 self.pg0.remote_ip4,
1012 self.pg1.remote_ip4)
1014 self.pg1.admin_down()
1017 def test_arp_duplicates(self):
1018 """ ARP Duplicates"""
1021 # Generate some hosts on the LAN
1023 self.pg1.generate_remote_hosts(3)
1026 # Add host 1 on pg1 and pg2
1028 arp_pg1 = VppNeighbor(self,
1029 self.pg1.sw_if_index,
1030 self.pg1.remote_hosts[1].mac,
1031 self.pg1.remote_hosts[1].ip4)
1032 arp_pg1.add_vpp_config()
1033 arp_pg2 = VppNeighbor(self,
1034 self.pg2.sw_if_index,
1035 self.pg2.remote_mac,
1036 self.pg1.remote_hosts[1].ip4)
1037 arp_pg2.add_vpp_config()
1040 # IP packet destined for pg1 remote host arrives on pg1 again.
1042 p = (Ether(dst=self.pg0.local_mac,
1043 src=self.pg0.remote_mac) /
1044 IP(src=self.pg0.remote_ip4,
1045 dst=self.pg1.remote_hosts[1].ip4) /
1046 UDP(sport=1234, dport=1234) /
1049 self.pg0.add_stream(p)
1050 self.pg_enable_capture(self.pg_interfaces)
1053 rx1 = self.pg1.get_capture(1)
1055 self.verify_ip(rx1[0],
1057 self.pg1.remote_hosts[1].mac,
1058 self.pg0.remote_ip4,
1059 self.pg1.remote_hosts[1].ip4)
1062 # remove the duplicate on pg1
1063 # packet stream shoud generate ARPs out of pg1
1065 arp_pg1.remove_vpp_config()
1067 self.pg0.add_stream(p)
1068 self.pg_enable_capture(self.pg_interfaces)
1071 rx1 = self.pg1.get_capture(1)
1073 self.verify_arp_req(rx1[0],
1076 self.pg1.remote_hosts[1].ip4)
1081 arp_pg1.add_vpp_config()
1083 self.pg0.add_stream(p)
1084 self.pg_enable_capture(self.pg_interfaces)
1087 rx1 = self.pg1.get_capture(1)
1089 self.verify_ip(rx1[0],
1091 self.pg1.remote_hosts[1].mac,
1092 self.pg0.remote_ip4,
1093 self.pg1.remote_hosts[1].ip4)
1095 def test_arp_static(self):
1097 self.pg2.generate_remote_hosts(3)
1100 # Add a static ARP entry
1102 static_arp = VppNeighbor(self,
1103 self.pg2.sw_if_index,
1104 self.pg2.remote_hosts[1].mac,
1105 self.pg2.remote_hosts[1].ip4,
1107 static_arp.add_vpp_config()
1110 # Add the connected prefix to the interface
1112 self.pg2.config_ip4()
1115 # We should now find the adj-fib
1117 self.assertTrue(find_nbr(self,
1118 self.pg2.sw_if_index,
1119 self.pg2.remote_hosts[1].ip4,
1121 self.assertTrue(find_route(self,
1122 self.pg2.remote_hosts[1].ip4,
1126 # remove the connected
1128 self.pg2.unconfig_ip4()
1131 # put the interface into table 1
1133 self.pg2.set_table_ip4(1)
1136 # configure the same connected and expect to find the
1137 # adj fib in the new table
1139 self.pg2.config_ip4()
1140 self.assertTrue(find_route(self,
1141 self.pg2.remote_hosts[1].ip4,
1148 self.pg2.unconfig_ip4()
1149 self.pg2.set_table_ip4(0)
1151 def test_arp_incomplete(self):
1152 """ ARP Incomplete"""
1153 self.pg1.generate_remote_hosts(3)
1155 p0 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1156 IP(src=self.pg0.remote_ip4,
1157 dst=self.pg1.remote_hosts[1].ip4) /
1158 UDP(sport=1234, dport=1234) /
1160 p1 = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1161 IP(src=self.pg0.remote_ip4,
1162 dst=self.pg1.remote_hosts[2].ip4) /
1163 UDP(sport=1234, dport=1234) /
1167 # a packet to an unresolved destination generates an ARP request
1169 rx = self.send_and_expect(self.pg0, [p0], self.pg1)
1170 self.verify_arp_req(rx[0],
1173 self.pg1._remote_hosts[1].ip4)
1176 # add a neighbour for remote host 1
1178 static_arp = VppNeighbor(self,
1179 self.pg1.sw_if_index,
1180 self.pg1.remote_hosts[1].mac,
1181 self.pg1.remote_hosts[1].ip4,
1183 static_arp.add_vpp_config()
1186 # change the interface's MAC
1188 mac = [chr(0x00), chr(0x00), chr(0x00),
1189 chr(0x33), chr(0x33), chr(0x33)]
1190 mac_string = ''.join(mac)
1192 self.vapi.sw_interface_set_mac_address(self.pg1.sw_if_index,
1196 # now ARP requests come from the new source mac
1198 rx = self.send_and_expect(self.pg0, [p1], self.pg1)
1199 self.verify_arp_req(rx[0],
1200 "00:00:00:33:33:33",
1202 self.pg1._remote_hosts[2].ip4)
1205 # packets to the resolved host also have the new source mac
1207 rx = self.send_and_expect(self.pg0, [p0], self.pg1)
1208 self.verify_ip(rx[0],
1209 "00:00:00:33:33:33",
1210 self.pg1.remote_hosts[1].mac,
1211 self.pg0.remote_ip4,
1212 self.pg1.remote_hosts[1].ip4)
1215 # set the mac address on the inteface that does not have a
1216 # configured subnet and thus no glean
1218 self.vapi.sw_interface_set_mac_address(self.pg2.sw_if_index,
1221 def test_garp(self):
1225 # Generate some hosts on the LAN
1227 self.pg1.generate_remote_hosts(4)
1232 arp = VppNeighbor(self,
1233 self.pg1.sw_if_index,
1234 self.pg1.remote_hosts[1].mac,
1235 self.pg1.remote_hosts[1].ip4)
1236 arp.add_vpp_config()
1238 self.assertTrue(find_nbr(self,
1239 self.pg1.sw_if_index,
1240 self.pg1.remote_hosts[1].ip4,
1241 mac=self.pg1.remote_hosts[1].mac))
1244 # Send a GARP (request) to swap the host 1's address to that of host 2
1246 p1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
1247 src=self.pg1.remote_hosts[2].mac) /
1249 hwdst=self.pg1.local_mac,
1250 hwsrc=self.pg1.remote_hosts[2].mac,
1251 pdst=self.pg1.remote_hosts[1].ip4,
1252 psrc=self.pg1.remote_hosts[1].ip4))
1254 self.pg1.add_stream(p1)
1255 self.pg_enable_capture(self.pg_interfaces)
1258 self.assertTrue(find_nbr(self,
1259 self.pg1.sw_if_index,
1260 self.pg1.remote_hosts[1].ip4,
1261 mac=self.pg1.remote_hosts[2].mac))
1264 # Send a GARP (reply) to swap the host 1's address to that of host 3
1266 p1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
1267 src=self.pg1.remote_hosts[3].mac) /
1269 hwdst=self.pg1.local_mac,
1270 hwsrc=self.pg1.remote_hosts[3].mac,
1271 pdst=self.pg1.remote_hosts[1].ip4,
1272 psrc=self.pg1.remote_hosts[1].ip4))
1274 self.pg1.add_stream(p1)
1275 self.pg_enable_capture(self.pg_interfaces)
1278 self.assertTrue(find_nbr(self,
1279 self.pg1.sw_if_index,
1280 self.pg1.remote_hosts[1].ip4,
1281 mac=self.pg1.remote_hosts[3].mac))
1284 # GARPs (requets nor replies) for host we don't know yet
1285 # don't result in new neighbour entries
1287 p1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
1288 src=self.pg1.remote_hosts[3].mac) /
1290 hwdst=self.pg1.local_mac,
1291 hwsrc=self.pg1.remote_hosts[3].mac,
1292 pdst=self.pg1.remote_hosts[2].ip4,
1293 psrc=self.pg1.remote_hosts[2].ip4))
1295 self.pg1.add_stream(p1)
1296 self.pg_enable_capture(self.pg_interfaces)
1299 self.assertFalse(find_nbr(self,
1300 self.pg1.sw_if_index,
1301 self.pg1.remote_hosts[2].ip4))
1303 p1 = (Ether(dst="ff:ff:ff:ff:ff:ff",
1304 src=self.pg1.remote_hosts[3].mac) /
1306 hwdst=self.pg1.local_mac,
1307 hwsrc=self.pg1.remote_hosts[3].mac,
1308 pdst=self.pg1.remote_hosts[2].ip4,
1309 psrc=self.pg1.remote_hosts[2].ip4))
1311 self.pg1.add_stream(p1)
1312 self.pg_enable_capture(self.pg_interfaces)
1315 self.assertFalse(find_nbr(self,
1316 self.pg1.sw_if_index,
1317 self.pg1.remote_hosts[2].ip4))
1319 def test_arp_incomplete(self):
1322 # ensure that we throttle the ARP requests
1324 self.pg0.generate_remote_hosts(2)
1326 ip_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32,
1327 [VppRoutePath(self.pg0.remote_hosts[1].ip4,
1328 self.pg0.sw_if_index,
1330 ip_10_0_0_1.add_vpp_config()
1332 p1 = (Ether(dst=self.pg1.local_mac,
1333 src=self.pg1.remote_mac) /
1334 IP(src=self.pg1.remote_ip4,
1336 UDP(sport=1234, dport=1234) /
1339 self.pg1.add_stream(p1 * 257)
1340 self.pg_enable_capture(self.pg_interfaces)
1342 rx = self.pg0._get_capture(1)
1345 # how many we get is going to be dependent on the time for packet
1346 # processing but it should be small
1348 self.assertTrue(len(rx) < 64)
1351 if __name__ == '__main__':
1352 unittest.main(testRunner=VppTestRunner)