4 from socket import inet_pton, inet_ntop
7 from parameterized import parameterized
9 import scapy.layers.inet6 as inet6
10 from scapy.contrib.mpls import MPLS
11 from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \
12 ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
13 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
14 ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply, \
15 IPv6ExtHdrHopByHop, ICMPv6MLReport2, ICMPv6MLDMultAddrRec
16 from scapy.layers.l2 import Ether, Dot1Q
17 from scapy.packet import Raw
18 from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
22 from framework import VppTestCase, VppTestRunner
23 from util import ppp, ip6_normalize, mk_ll_addr
24 from vpp_ip import DpoProto
25 from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
26 VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
27 VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
28 VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump
29 from vpp_neighbor import find_nbr, VppNeighbor
30 from vpp_pg_interface import is_ipv6_misc
31 from vpp_sub_interface import VppSubInterface, VppDot1QSubint
32 from vpp_policer import VppPolicer
33 from ipaddress import IPv6Network, IPv6Address
35 AF_INET6 = socket.AF_INET6
45 class TestIPv6ND(VppTestCase):
46 def validate_ra(self, intf, rx, dst_ip=None):
48 dst_ip = intf.remote_ip6
50 # unicasted packets must come to the unicast mac
51 self.assertEqual(rx[Ether].dst, intf.remote_mac)
53 # and from the router's MAC
54 self.assertEqual(rx[Ether].src, intf.local_mac)
56 # the rx'd RA should be addressed to the sender's source
57 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
58 self.assertEqual(in6_ptop(rx[IPv6].dst),
61 # and come from the router's link local
62 self.assertTrue(in6_islladdr(rx[IPv6].src))
63 self.assertEqual(in6_ptop(rx[IPv6].src),
64 in6_ptop(mk_ll_addr(intf.local_mac)))
66 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
68 dst_ip = intf.remote_ip6
70 dst_ip = intf.local_ip6
72 # unicasted packets must come to the unicast mac
73 self.assertEqual(rx[Ether].dst, intf.remote_mac)
75 # and from the router's MAC
76 self.assertEqual(rx[Ether].src, intf.local_mac)
78 # the rx'd NA should be addressed to the sender's source
79 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
80 self.assertEqual(in6_ptop(rx[IPv6].dst),
83 # and come from the target address
85 in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
87 # Dest link-layer options should have the router's MAC
88 dll = rx[ICMPv6NDOptDstLLAddr]
89 self.assertEqual(dll.lladdr, intf.local_mac)
91 def validate_ns(self, intf, rx, tgt_ip):
92 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
93 dst_ip = inet_ntop(AF_INET6, nsma)
96 self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
98 # and from the router's MAC
99 self.assertEqual(rx[Ether].src, intf.local_mac)
101 # the rx'd NS should be addressed to an mcast address
102 # derived from the target address
104 in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
106 # expect the tgt IP in the NS header
108 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
110 # packet is from the router's local address
112 in6_ptop(rx[IPv6].src), intf.local_ip6)
114 # Src link-layer options should have the router's MAC
115 sll = rx[ICMPv6NDOptSrcLLAddr]
116 self.assertEqual(sll.lladdr, intf.local_mac)
118 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
119 filter_out_fn=is_ipv6_misc):
120 intf.add_stream(pkts)
121 self.pg_enable_capture(self.pg_interfaces)
123 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
125 self.assertEqual(len(rx), 1)
127 self.validate_ra(intf, rx, dst_ip)
129 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
131 filter_out_fn=is_ipv6_misc):
132 intf.add_stream(pkts)
133 self.pg_enable_capture(self.pg_interfaces)
135 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
137 self.assertEqual(len(rx), 1)
139 self.validate_na(intf, rx, dst_ip, tgt_ip)
141 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
142 filter_out_fn=is_ipv6_misc):
143 self.vapi.cli("clear trace")
144 tx_intf.add_stream(pkts)
145 self.pg_enable_capture(self.pg_interfaces)
147 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
149 self.assertEqual(len(rx), 1)
151 self.validate_ns(rx_intf, rx, tgt_ip)
153 def verify_ip(self, rx, smac, dmac, sip, dip):
155 self.assertEqual(ether.dst, dmac)
156 self.assertEqual(ether.src, smac)
159 self.assertEqual(ip.src, sip)
160 self.assertEqual(ip.dst, dip)
163 class TestIPv6(TestIPv6ND):
164 """ IPv6 Test Case """
168 super(TestIPv6, cls).setUpClass()
171 def tearDownClass(cls):
172 super(TestIPv6, cls).tearDownClass()
176 Perform test setup before test case.
179 - create 3 pg interfaces
180 - untagged pg0 interface
181 - Dot1Q subinterface on pg1
182 - Dot1AD subinterface on pg2
184 - put it into UP state
186 - resolve neighbor address using NDP
187 - configure 200 fib entries
189 :ivar list interfaces: pg interfaces and subinterfaces.
190 :ivar dict flows: IPv4 packet flows in test.
192 *TODO:* Create AD sub interface
194 super(TestIPv6, self).setUp()
196 # create 3 pg interfaces
197 self.create_pg_interfaces(range(3))
199 # create 2 subinterfaces for p1 and pg2
200 self.sub_interfaces = [
201 VppDot1QSubint(self, self.pg1, 100),
202 VppDot1QSubint(self, self.pg2, 200)
203 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
206 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
208 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
209 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
210 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
213 self.pg_if_packet_sizes = [64, 1500, 9020]
215 self.interfaces = list(self.pg_interfaces)
216 self.interfaces.extend(self.sub_interfaces)
218 # setup all interfaces
219 for i in self.interfaces:
225 """Run standard test teardown and log ``show ip6 neighbors``."""
226 for i in self.interfaces:
229 for i in self.sub_interfaces:
230 i.remove_vpp_config()
232 super(TestIPv6, self).tearDown()
233 if not self.vpp_dead:
234 self.logger.info(self.vapi.cli("show ip6 neighbors"))
235 # info(self.vapi.cli("show ip6 fib")) # many entries
237 def modify_packet(self, src_if, packet_size, pkt):
238 """Add load, set destination IP and extend packet to required packet
239 size for defined interface.
241 :param VppInterface src_if: Interface to create packet for.
242 :param int packet_size: Required packet size.
243 :param Scapy pkt: Packet to be modified.
245 dst_if_idx = int(packet_size / 10 % 2)
246 dst_if = self.flows[src_if][dst_if_idx]
247 info = self.create_packet_info(src_if, dst_if)
248 payload = self.info_to_payload(info)
249 p = pkt / Raw(payload)
250 p[IPv6].dst = dst_if.remote_ip6
252 if isinstance(src_if, VppSubInterface):
253 p = src_if.add_dot1_layer(p)
254 self.extend_packet(p, packet_size)
258 def create_stream(self, src_if):
259 """Create input packet stream for defined interface.
261 :param VppInterface src_if: Interface to create packet stream for.
263 hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
264 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
265 IPv6(src=src_if.remote_ip6) /
266 inet6.UDP(sport=1234, dport=1234))
268 pkts = [self.modify_packet(src_if, i, pkt_tmpl)
269 for i in moves.range(self.pg_if_packet_sizes[0],
270 self.pg_if_packet_sizes[1], 10)]
271 pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
272 for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
273 self.pg_if_packet_sizes[2] + hdr_ext,
279 def verify_capture(self, dst_if, capture):
280 """Verify captured input packet stream for defined interface.
282 :param VppInterface dst_if: Interface to verify captured packet stream
284 :param list capture: Captured packet stream.
286 self.logger.info("Verifying capture on interface %s" % dst_if.name)
288 for i in self.interfaces:
289 last_info[i.sw_if_index] = None
291 dst_sw_if_index = dst_if.sw_if_index
292 if hasattr(dst_if, 'parent'):
294 for packet in capture:
296 # Check VLAN tags and Ethernet header
297 packet = dst_if.remove_dot1_layer(packet)
298 self.assertTrue(Dot1Q not in packet)
301 udp = packet[inet6.UDP]
302 payload_info = self.payload_to_info(packet[Raw])
303 packet_index = payload_info.index
304 self.assertEqual(payload_info.dst, dst_sw_if_index)
306 "Got packet on port %s: src=%u (id=%u)" %
307 (dst_if.name, payload_info.src, packet_index))
308 next_info = self.get_next_packet_info_for_interface2(
309 payload_info.src, dst_sw_if_index,
310 last_info[payload_info.src])
311 last_info[payload_info.src] = next_info
312 self.assertTrue(next_info is not None)
313 self.assertEqual(packet_index, next_info.index)
314 saved_packet = next_info.data
315 # Check standard fields
317 ip.src, saved_packet[IPv6].src)
319 ip.dst, saved_packet[IPv6].dst)
321 udp.sport, saved_packet[inet6.UDP].sport)
323 udp.dport, saved_packet[inet6.UDP].dport)
325 self.logger.error(ppp("Unexpected or invalid packet:", packet))
327 for i in self.interfaces:
328 remaining_packet = self.get_next_packet_info_for_interface2(
329 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
330 self.assertTrue(remaining_packet is None,
331 "Interface %s: Packet expected from interface %s "
332 "didn't arrive" % (dst_if.name, i.name))
334 def test_next_header_anomaly(self):
335 """ IPv6 next header anomaly test
338 - ipv6 next header field = Fragment Header (44)
339 - next header is ICMPv6 Echo Request
340 - wait for reassembly
342 pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) /
343 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) /
346 self.pg0.add_stream(pkt)
349 # wait for reassembly
356 - Create IPv6 stream for pg0 interface
357 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
358 - Send and verify received packets on each interface.
361 pkts = self.create_stream(self.pg0)
362 self.pg0.add_stream(pkts)
364 for i in self.sub_interfaces:
365 pkts = self.create_stream(i)
366 i.parent.add_stream(pkts)
368 self.pg_enable_capture(self.pg_interfaces)
371 pkts = self.pg0.get_capture()
372 self.verify_capture(self.pg0, pkts)
374 for i in self.sub_interfaces:
375 pkts = i.parent.get_capture()
376 self.verify_capture(i, pkts)
379 """ IPv6 Neighbour Solicitation Exceptions
382 - Send an NS Sourced from an address not covered by the link sub-net
383 - Send an NS to an mcast address the router has not joined
384 - Send NS for a target address the router does not onn.
388 # An NS from a non link source address
390 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
391 d = inet_ntop(AF_INET6, nsma)
393 p = (Ether(dst=in6_getnsmac(nsma)) /
394 IPv6(dst=d, src="2002::2") /
395 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
396 ICMPv6NDOptSrcLLAddr(
397 lladdr=self.pg0.remote_mac))
400 self.send_and_assert_no_replies(
402 "No response to NS source by address not on sub-net")
405 # An NS for sent to a solicited mcast group the router is
406 # not a member of FAILS
409 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
410 d = inet_ntop(AF_INET6, nsma)
412 p = (Ether(dst=in6_getnsmac(nsma)) /
413 IPv6(dst=d, src=self.pg0.remote_ip6) /
414 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
415 ICMPv6NDOptSrcLLAddr(
416 lladdr=self.pg0.remote_mac))
419 self.send_and_assert_no_replies(
421 "No response to NS sent to unjoined mcast address")
424 # An NS whose target address is one the router does not own
426 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
427 d = inet_ntop(AF_INET6, nsma)
429 p = (Ether(dst=in6_getnsmac(nsma)) /
430 IPv6(dst=d, src=self.pg0.remote_ip6) /
431 ICMPv6ND_NS(tgt="fd::ffff") /
432 ICMPv6NDOptSrcLLAddr(
433 lladdr=self.pg0.remote_mac))
436 self.send_and_assert_no_replies(self.pg0, pkts,
437 "No response to NS for unknown target")
440 # A neighbor entry that has no associated FIB-entry
442 self.pg0.generate_remote_hosts(4)
443 nd_entry = VppNeighbor(self,
444 self.pg0.sw_if_index,
445 self.pg0.remote_hosts[2].mac,
446 self.pg0.remote_hosts[2].ip6,
448 nd_entry.add_vpp_config()
451 # check we have the neighbor, but no route
453 self.assertTrue(find_nbr(self,
454 self.pg0.sw_if_index,
455 self.pg0._remote_hosts[2].ip6))
456 self.assertFalse(find_route(self,
457 self.pg0._remote_hosts[2].ip6,
461 # send an NS from a link local address to the interface's global
464 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
466 dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
467 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
468 ICMPv6NDOptSrcLLAddr(
469 lladdr=self.pg0.remote_mac))
471 self.send_and_expect_na(self.pg0, p,
472 "NS from link-local",
473 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
474 tgt_ip=self.pg0.local_ip6)
477 # we should have learned an ND entry for the peer's link-local
478 # but not inserted a route to it in the FIB
480 self.assertTrue(find_nbr(self,
481 self.pg0.sw_if_index,
482 self.pg0._remote_hosts[2].ip6_ll))
483 self.assertFalse(find_route(self,
484 self.pg0._remote_hosts[2].ip6_ll,
488 # An NS to the router's own Link-local
490 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
492 dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
493 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
494 ICMPv6NDOptSrcLLAddr(
495 lladdr=self.pg0.remote_mac))
497 self.send_and_expect_na(self.pg0, p,
498 "NS to/from link-local",
499 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
500 tgt_ip=self.pg0.local_ip6_ll)
503 # we should have learned an ND entry for the peer's link-local
504 # but not inserted a route to it in the FIB
506 self.assertTrue(find_nbr(self,
507 self.pg0.sw_if_index,
508 self.pg0._remote_hosts[3].ip6_ll))
509 self.assertFalse(find_route(self,
510 self.pg0._remote_hosts[3].ip6_ll,
513 def test_ns_duplicates(self):
517 # Generate some hosts on the LAN
519 self.pg1.generate_remote_hosts(3)
522 # Add host 1 on pg1 and pg2
524 ns_pg1 = VppNeighbor(self,
525 self.pg1.sw_if_index,
526 self.pg1.remote_hosts[1].mac,
527 self.pg1.remote_hosts[1].ip6)
528 ns_pg1.add_vpp_config()
529 ns_pg2 = VppNeighbor(self,
530 self.pg2.sw_if_index,
532 self.pg1.remote_hosts[1].ip6)
533 ns_pg2.add_vpp_config()
536 # IP packet destined for pg1 remote host arrives on pg1 again.
538 p = (Ether(dst=self.pg0.local_mac,
539 src=self.pg0.remote_mac) /
540 IPv6(src=self.pg0.remote_ip6,
541 dst=self.pg1.remote_hosts[1].ip6) /
542 inet6.UDP(sport=1234, dport=1234) /
545 self.pg0.add_stream(p)
546 self.pg_enable_capture(self.pg_interfaces)
549 rx1 = self.pg1.get_capture(1)
551 self.verify_ip(rx1[0],
553 self.pg1.remote_hosts[1].mac,
555 self.pg1.remote_hosts[1].ip6)
558 # remove the duplicate on pg1
559 # packet stream should generate NSs out of pg1
561 ns_pg1.remove_vpp_config()
563 self.send_and_expect_ns(self.pg0, self.pg1,
564 p, self.pg1.remote_hosts[1].ip6)
569 ns_pg1.add_vpp_config()
571 self.pg0.add_stream(p)
572 self.pg_enable_capture(self.pg_interfaces)
575 rx1 = self.pg1.get_capture(1)
577 self.verify_ip(rx1[0],
579 self.pg1.remote_hosts[1].mac,
581 self.pg1.remote_hosts[1].ip6)
583 def validate_ra(self, intf, rx, dst_ip=None, src_ip=None,
584 mtu=9000, pi_opt=None):
586 dst_ip = intf.remote_ip6
588 src_ip = mk_ll_addr(intf.local_mac)
590 # unicasted packets must come to the unicast mac
591 self.assertEqual(rx[Ether].dst, intf.remote_mac)
593 # and from the router's MAC
594 self.assertEqual(rx[Ether].src, intf.local_mac)
596 # the rx'd RA should be addressed to the sender's source
597 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
598 self.assertEqual(in6_ptop(rx[IPv6].dst),
601 # and come from the router's link local
602 self.assertTrue(in6_islladdr(rx[IPv6].src))
603 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip))
605 # it should contain the links MTU
607 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
609 # it should contain the source's link layer address option
610 sll = ra[ICMPv6NDOptSrcLLAddr]
611 self.assertEqual(sll.lladdr, intf.local_mac)
614 # the RA should not contain prefix information
615 self.assertFalse(ra.haslayer(
616 ICMPv6NDOptPrefixInfo))
618 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
620 # the options are nested in the scapy packet in way that i cannot
621 # decipher how to decode. this 1st layer of option always returns
622 # nested classes, so a direct obj1=obj2 comparison always fails.
623 # however, the getlayer(.., 2) does give one instance.
624 # so we cheat here and construct a new opt instance for comparison
625 rd = ICMPv6NDOptPrefixInfo(
626 prefixlen=raos.prefixlen,
630 if type(pi_opt) is list:
631 for ii in range(len(pi_opt)):
632 self.assertEqual(pi_opt[ii], rd)
634 ICMPv6NDOptPrefixInfo, ii + 2)
636 self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s'
637 % (pi_opt.show(dump=True),
638 raos.show(dump=True)))
640 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
641 filter_out_fn=is_ipv6_misc,
644 self.vapi.cli("clear trace")
645 intf.add_stream(pkts)
646 self.pg_enable_capture(self.pg_interfaces)
648 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
650 self.assertEqual(len(rx), 1)
652 self.validate_ra(intf, rx, dst_ip, src_ip=src_ip, pi_opt=opt)
655 """ IPv6 Router Solicitation Exceptions
661 # Before we begin change the IPv6 RA responses to use the unicast
662 # address - that way we will not confuse them with the periodic
663 # RAs which go to the mcast address
664 # Sit and wait for the first periodic RA.
668 self.pg0.ip6_ra_config(send_unicast=1)
671 # An RS from a link source address
672 # - expect an RA in return
674 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
675 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
678 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
681 # For the next RS sent the RA should be rate limited
683 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
686 # When we reconfigure the IPv6 RA config,
687 # we reset the RA rate limiting,
688 # so we need to do this before each test below so as not to drop
689 # packets for rate limiting reasons. Test this works here.
691 self.pg0.ip6_ra_config(send_unicast=1)
692 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
695 # An RS sent from a non-link local source
697 self.pg0.ip6_ra_config(send_unicast=1)
698 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
699 IPv6(dst=self.pg0.local_ip6,
703 self.send_and_assert_no_replies(self.pg0, pkts,
704 "RS from non-link source")
707 # Source an RS from a link local address
709 self.pg0.ip6_ra_config(send_unicast=1)
710 ll = mk_ll_addr(self.pg0.remote_mac)
711 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
712 IPv6(dst=self.pg0.local_ip6, src=ll) /
715 self.send_and_expect_ra(self.pg0, pkts,
716 "RS sourced from link-local",
720 # Send the RS multicast
722 self.pg0.ip6_ra_config(send_unicast=1)
723 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
724 ll = mk_ll_addr(self.pg0.remote_mac)
725 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
726 IPv6(dst="ff02::2", src=ll) /
729 self.send_and_expect_ra(self.pg0, pkts,
730 "RS sourced from link-local",
734 # Source from the unspecified address ::. This happens when the RS
735 # is sent before the host has a configured address/sub-net,
736 # i.e. auto-config. Since the sender has no IP address, the reply
737 # comes back mcast - so the capture needs to not filter this.
738 # If we happen to pick up the periodic RA at this point then so be it,
741 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
742 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
743 IPv6(dst="ff02::2", src="::") /
746 self.send_and_expect_ra(self.pg0, pkts,
747 "RS sourced from unspecified",
752 # Configure The RA to announce the links prefix
754 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
755 self.pg0.local_ip6_prefix_len))
758 # RAs should now contain the prefix information option
760 opt = ICMPv6NDOptPrefixInfo(
761 prefixlen=self.pg0.local_ip6_prefix_len,
762 prefix=self.pg0.local_ip6,
766 self.pg0.ip6_ra_config(send_unicast=1)
767 ll = mk_ll_addr(self.pg0.remote_mac)
768 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
769 IPv6(dst=self.pg0.local_ip6, src=ll) /
771 self.send_and_expect_ra(self.pg0, p,
772 "RA with prefix-info",
777 # Change the prefix info to not off-link
780 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
781 self.pg0.local_ip6_prefix_len),
784 opt = ICMPv6NDOptPrefixInfo(
785 prefixlen=self.pg0.local_ip6_prefix_len,
786 prefix=self.pg0.local_ip6,
790 self.pg0.ip6_ra_config(send_unicast=1)
791 self.send_and_expect_ra(self.pg0, p,
792 "RA with Prefix info with L-flag=0",
797 # Change the prefix info to not off-link, no-autoconfig
798 # L and A flag are clear in the advert
800 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
801 self.pg0.local_ip6_prefix_len),
805 opt = ICMPv6NDOptPrefixInfo(
806 prefixlen=self.pg0.local_ip6_prefix_len,
807 prefix=self.pg0.local_ip6,
811 self.pg0.ip6_ra_config(send_unicast=1)
812 self.send_and_expect_ra(self.pg0, p,
813 "RA with Prefix info with A & L-flag=0",
818 # Change the flag settings back to the defaults
819 # L and A flag are set in the advert
821 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
822 self.pg0.local_ip6_prefix_len))
824 opt = ICMPv6NDOptPrefixInfo(
825 prefixlen=self.pg0.local_ip6_prefix_len,
826 prefix=self.pg0.local_ip6,
830 self.pg0.ip6_ra_config(send_unicast=1)
831 self.send_and_expect_ra(self.pg0, p,
832 "RA with Prefix info",
837 # Change the prefix info to not off-link, no-autoconfig
838 # L and A flag are clear in the advert
840 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
841 self.pg0.local_ip6_prefix_len),
845 opt = ICMPv6NDOptPrefixInfo(
846 prefixlen=self.pg0.local_ip6_prefix_len,
847 prefix=self.pg0.local_ip6,
851 self.pg0.ip6_ra_config(send_unicast=1)
852 self.send_and_expect_ra(self.pg0, p,
853 "RA with Prefix info with A & L-flag=0",
858 # Use the reset to defaults option to revert to defaults
859 # L and A flag are clear in the advert
861 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
862 self.pg0.local_ip6_prefix_len),
865 opt = ICMPv6NDOptPrefixInfo(
866 prefixlen=self.pg0.local_ip6_prefix_len,
867 prefix=self.pg0.local_ip6,
871 self.pg0.ip6_ra_config(send_unicast=1)
872 self.send_and_expect_ra(self.pg0, p,
873 "RA with Prefix reverted to defaults",
878 # Advertise Another prefix. With no L-flag/A-flag
880 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
881 self.pg1.local_ip6_prefix_len),
885 opt = [ICMPv6NDOptPrefixInfo(
886 prefixlen=self.pg0.local_ip6_prefix_len,
887 prefix=self.pg0.local_ip6,
890 ICMPv6NDOptPrefixInfo(
891 prefixlen=self.pg1.local_ip6_prefix_len,
892 prefix=self.pg1.local_ip6,
896 self.pg0.ip6_ra_config(send_unicast=1)
897 ll = mk_ll_addr(self.pg0.remote_mac)
898 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
899 IPv6(dst=self.pg0.local_ip6, src=ll) /
901 self.send_and_expect_ra(self.pg0, p,
902 "RA with multiple Prefix infos",
907 # Remove the first prefix-info - expect the second is still in the
910 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
911 self.pg0.local_ip6_prefix_len),
914 opt = ICMPv6NDOptPrefixInfo(
915 prefixlen=self.pg1.local_ip6_prefix_len,
916 prefix=self.pg1.local_ip6,
920 self.pg0.ip6_ra_config(send_unicast=1)
921 self.send_and_expect_ra(self.pg0, p,
922 "RA with Prefix reverted to defaults",
927 # Remove the second prefix-info - expect no prefix-info in the adverts
929 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
930 self.pg1.local_ip6_prefix_len),
934 # change the link's link local, so we know that works too.
936 self.vapi.sw_interface_ip6_set_link_local_address(
937 sw_if_index=self.pg0.sw_if_index,
940 self.pg0.ip6_ra_config(send_unicast=1)
941 self.send_and_expect_ra(self.pg0, p,
942 "RA with Prefix reverted to defaults",
947 # Reset the periodic advertisements back to default values
949 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
954 # test one MLD is sent after applying an IPv6 Address on an interface
956 self.pg_enable_capture(self.pg_interfaces)
959 subitf = VppDot1QSubint(self, self.pg1, 99)
964 rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None)
967 # hunt for the MLD on vlan 99
970 # make sure ipv6 packets with hop by hop options have
972 self.assert_packet_checksums_valid(rx)
973 if rx.haslayer(IPv6ExtHdrHopByHop) and \
974 rx.haslayer(Dot1Q) and \
975 rx[Dot1Q].vlan == 99:
976 mld = rx[ICMPv6MLReport2]
978 self.assertEqual(mld.records_number, 4)
981 class TestIPv6IfAddrRoute(VppTestCase):
982 """ IPv6 Interface Addr Route Test Case """
986 super(TestIPv6IfAddrRoute, cls).setUpClass()
989 def tearDownClass(cls):
990 super(TestIPv6IfAddrRoute, cls).tearDownClass()
993 super(TestIPv6IfAddrRoute, self).setUp()
995 # create 1 pg interface
996 self.create_pg_interfaces(range(1))
998 for i in self.pg_interfaces:
1004 super(TestIPv6IfAddrRoute, self).tearDown()
1005 for i in self.pg_interfaces:
1009 def test_ipv6_ifaddrs_same_prefix(self):
1010 """ IPv6 Interface Addresses Same Prefix test
1014 - Verify no route in FIB for prefix 2001:10::/64
1015 - Configure IPv4 address 2001:10::10/64 on an interface
1016 - Verify route in FIB for prefix 2001:10::/64
1017 - Configure IPv4 address 2001:10::20/64 on an interface
1018 - Delete 2001:10::10/64 from interface
1019 - Verify route in FIB for prefix 2001:10::/64
1020 - Delete 2001:10::20/64 from interface
1021 - Verify no route in FIB for prefix 2001:10::/64
1024 addr1 = "2001:10::10"
1025 addr2 = "2001:10::20"
1027 if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64)
1028 if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64)
1029 self.assertFalse(if_addr1.query_vpp_config())
1030 self.assertFalse(find_route(self, addr1, 128))
1031 self.assertFalse(find_route(self, addr2, 128))
1033 # configure first address, verify route present
1034 if_addr1.add_vpp_config()
1035 self.assertTrue(if_addr1.query_vpp_config())
1036 self.assertTrue(find_route(self, addr1, 128))
1037 self.assertFalse(find_route(self, addr2, 128))
1039 # configure second address, delete first, verify route not removed
1040 if_addr2.add_vpp_config()
1041 if_addr1.remove_vpp_config()
1042 self.assertFalse(if_addr1.query_vpp_config())
1043 self.assertTrue(if_addr2.query_vpp_config())
1044 self.assertFalse(find_route(self, addr1, 128))
1045 self.assertTrue(find_route(self, addr2, 128))
1047 # delete second address, verify route removed
1048 if_addr2.remove_vpp_config()
1049 self.assertFalse(if_addr1.query_vpp_config())
1050 self.assertFalse(find_route(self, addr1, 128))
1051 self.assertFalse(find_route(self, addr2, 128))
1054 class TestICMPv6Echo(VppTestCase):
1055 """ ICMPv6 Echo Test Case """
1058 def setUpClass(cls):
1059 super(TestICMPv6Echo, cls).setUpClass()
1062 def tearDownClass(cls):
1063 super(TestICMPv6Echo, cls).tearDownClass()
1066 super(TestICMPv6Echo, self).setUp()
1068 # create 1 pg interface
1069 self.create_pg_interfaces(range(1))
1071 for i in self.pg_interfaces:
1077 super(TestICMPv6Echo, self).tearDown()
1078 for i in self.pg_interfaces:
1082 def test_icmpv6_echo(self):
1083 """ VPP replies to ICMPv6 Echo Request
1087 - Receive ICMPv6 Echo Request message on pg0 interface.
1088 - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
1093 icmpv6_data = b'\x0a' * 18
1094 p_echo_request = (Ether(src=self.pg0.remote_mac,
1095 dst=self.pg0.local_mac) /
1096 IPv6(src=self.pg0.remote_ip6,
1097 dst=self.pg0.local_ip6) /
1103 self.pg0.add_stream(p_echo_request)
1104 self.pg_enable_capture(self.pg_interfaces)
1107 rx = self.pg0.get_capture(1)
1111 icmpv6 = rx[ICMPv6EchoReply]
1113 self.assertEqual(ether.src, self.pg0.local_mac)
1114 self.assertEqual(ether.dst, self.pg0.remote_mac)
1116 self.assertEqual(ipv6.src, self.pg0.local_ip6)
1117 self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1120 icmp6types[icmpv6.type], "Echo Reply")
1121 self.assertEqual(icmpv6.id, icmpv6_id)
1122 self.assertEqual(icmpv6.seq, icmpv6_seq)
1123 self.assertEqual(icmpv6.data, icmpv6_data)
1126 class TestIPv6RD(TestIPv6ND):
1127 """ IPv6 Router Discovery Test Case """
1130 def setUpClass(cls):
1131 super(TestIPv6RD, cls).setUpClass()
1134 def tearDownClass(cls):
1135 super(TestIPv6RD, cls).tearDownClass()
1138 super(TestIPv6RD, self).setUp()
1140 # create 2 pg interfaces
1141 self.create_pg_interfaces(range(2))
1143 self.interfaces = list(self.pg_interfaces)
1145 # setup all interfaces
1146 for i in self.interfaces:
1151 for i in self.interfaces:
1154 super(TestIPv6RD, self).tearDown()
1156 def test_rd_send_router_solicitation(self):
1157 """ Verify router solicitation packets """
1160 self.pg_enable_capture(self.pg_interfaces)
1162 self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1164 rx_list = self.pg1.get_capture(count, timeout=3)
1165 self.assertEqual(len(rx_list), count)
1166 for packet in rx_list:
1167 self.assertEqual(packet.haslayer(IPv6), 1)
1168 self.assertEqual(packet[IPv6].haslayer(
1170 dst = ip6_normalize(packet[IPv6].dst)
1171 dst2 = ip6_normalize("ff02::2")
1172 self.assert_equal(dst, dst2)
1173 src = ip6_normalize(packet[IPv6].src)
1174 src2 = ip6_normalize(self.pg1.local_ip6_ll)
1175 self.assert_equal(src, src2)
1177 bool(packet[ICMPv6ND_RS].haslayer(
1178 ICMPv6NDOptSrcLLAddr)))
1180 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1183 def verify_prefix_info(self, reported_prefix, prefix_option):
1184 prefix = IPv6Network(
1185 text_type(prefix_option.getfieldval("prefix") +
1187 text_type(prefix_option.getfieldval("prefixlen"))),
1189 self.assert_equal(reported_prefix.prefix.network_address,
1190 prefix.network_address)
1191 L = prefix_option.getfieldval("L")
1192 A = prefix_option.getfieldval("A")
1193 option_flags = (L << 7) | (A << 6)
1194 self.assert_equal(reported_prefix.flags, option_flags)
1195 self.assert_equal(reported_prefix.valid_time,
1196 prefix_option.getfieldval("validlifetime"))
1197 self.assert_equal(reported_prefix.preferred_time,
1198 prefix_option.getfieldval("preferredlifetime"))
1200 def test_rd_receive_router_advertisement(self):
1201 """ Verify events triggered by received RA packets """
1203 self.vapi.want_ip6_ra_events(enable=1)
1205 prefix_info_1 = ICMPv6NDOptPrefixInfo(
1209 preferredlifetime=500,
1214 prefix_info_2 = ICMPv6NDOptPrefixInfo(
1218 preferredlifetime=1000,
1223 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1224 IPv6(dst=self.pg1.local_ip6_ll,
1225 src=mk_ll_addr(self.pg1.remote_mac)) /
1229 self.pg1.add_stream([p])
1232 ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1234 self.assert_equal(ev.current_hop_limit, 0)
1235 self.assert_equal(ev.flags, 8)
1236 self.assert_equal(ev.router_lifetime_in_sec, 1800)
1237 self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1239 ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1241 self.assert_equal(ev.n_prefixes, 2)
1243 self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1244 self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1247 class TestIPv6RDControlPlane(TestIPv6ND):
1248 """ IPv6 Router Discovery Control Plane Test Case """
1251 def setUpClass(cls):
1252 super(TestIPv6RDControlPlane, cls).setUpClass()
1255 def tearDownClass(cls):
1256 super(TestIPv6RDControlPlane, cls).tearDownClass()
1259 super(TestIPv6RDControlPlane, self).setUp()
1261 # create 1 pg interface
1262 self.create_pg_interfaces(range(1))
1264 self.interfaces = list(self.pg_interfaces)
1266 # setup all interfaces
1267 for i in self.interfaces:
1272 super(TestIPv6RDControlPlane, self).tearDown()
1275 def create_ra_packet(pg, routerlifetime=None):
1276 src_ip = pg.remote_ip6_ll
1277 dst_ip = pg.local_ip6
1278 if routerlifetime is not None:
1279 ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1282 p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1283 IPv6(dst=dst_ip, src=src_ip) / ra)
1287 def get_default_routes(fib):
1290 if entry.route.prefix.prefixlen == 0:
1291 for path in entry.route.paths:
1292 if path.sw_if_index != 0xFFFFFFFF:
1294 defaut_route['sw_if_index'] = path.sw_if_index
1295 defaut_route['next_hop'] = path.nh.address.ip6
1296 list.append(defaut_route)
1300 def get_interface_addresses(fib, pg):
1303 if entry.route.prefix.prefixlen == 128:
1304 path = entry.route.paths[0]
1305 if path.sw_if_index == pg.sw_if_index:
1306 list.append(str(entry.route.prefix.network_address))
1309 def wait_for_no_default_route(self, n_tries=50, s_time=1):
1311 fib = self.vapi.ip_route_dump(0, True)
1312 default_routes = self.get_default_routes(fib)
1313 if 0 == len(default_routes):
1315 n_tries = n_tries - 1
1321 """ Test handling of SLAAC addresses and default routes """
1323 fib = self.vapi.ip_route_dump(0, True)
1324 default_routes = self.get_default_routes(fib)
1325 initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1326 self.assertEqual(default_routes, [])
1327 router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll))
1329 self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1334 packet = (self.create_ra_packet(
1335 self.pg0) / ICMPv6NDOptPrefixInfo(
1339 preferredlifetime=2,
1342 ) / ICMPv6NDOptPrefixInfo(
1346 preferredlifetime=1000,
1350 self.pg0.add_stream([packet])
1353 self.sleep_on_vpp_time(0.1)
1355 fib = self.vapi.ip_route_dump(0, True)
1357 # check FIB for new address
1358 addresses = set(self.get_interface_addresses(fib, self.pg0))
1359 new_addresses = addresses.difference(initial_addresses)
1360 self.assertEqual(len(new_addresses), 1)
1361 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1363 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
1365 # check FIB for new default route
1366 default_routes = self.get_default_routes(fib)
1367 self.assertEqual(len(default_routes), 1)
1368 dr = default_routes[0]
1369 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1370 self.assertEqual(dr['next_hop'], router_address)
1372 # send RA to delete default route
1373 packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1374 self.pg0.add_stream([packet])
1377 self.sleep_on_vpp_time(0.1)
1379 # check that default route is deleted
1380 fib = self.vapi.ip_route_dump(0, True)
1381 default_routes = self.get_default_routes(fib)
1382 self.assertEqual(len(default_routes), 0)
1384 self.sleep_on_vpp_time(0.1)
1387 packet = self.create_ra_packet(self.pg0)
1388 self.pg0.add_stream([packet])
1391 self.sleep_on_vpp_time(0.1)
1393 # check FIB for new default route
1394 fib = self.vapi.ip_route_dump(0, True)
1395 default_routes = self.get_default_routes(fib)
1396 self.assertEqual(len(default_routes), 1)
1397 dr = default_routes[0]
1398 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1399 self.assertEqual(dr['next_hop'], router_address)
1401 # send RA, updating router lifetime to 1s
1402 packet = self.create_ra_packet(self.pg0, 1)
1403 self.pg0.add_stream([packet])
1406 self.sleep_on_vpp_time(0.1)
1408 # check that default route still exists
1409 fib = self.vapi.ip_route_dump(0, True)
1410 default_routes = self.get_default_routes(fib)
1411 self.assertEqual(len(default_routes), 1)
1412 dr = default_routes[0]
1413 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1414 self.assertEqual(dr['next_hop'], router_address)
1416 self.sleep_on_vpp_time(1)
1418 # check that default route is deleted
1419 self.assertTrue(self.wait_for_no_default_route())
1421 # check FIB still contains the SLAAC address
1422 addresses = set(self.get_interface_addresses(fib, self.pg0))
1423 new_addresses = addresses.difference(initial_addresses)
1425 self.assertEqual(len(new_addresses), 1)
1426 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1428 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
1430 self.sleep_on_vpp_time(1)
1432 # check that SLAAC address is deleted
1433 fib = self.vapi.ip_route_dump(0, True)
1434 addresses = set(self.get_interface_addresses(fib, self.pg0))
1435 new_addresses = addresses.difference(initial_addresses)
1436 self.assertEqual(len(new_addresses), 0)
1439 class IPv6NDProxyTest(TestIPv6ND):
1440 """ IPv6 ND ProxyTest Case """
1443 def setUpClass(cls):
1444 super(IPv6NDProxyTest, cls).setUpClass()
1447 def tearDownClass(cls):
1448 super(IPv6NDProxyTest, cls).tearDownClass()
1451 super(IPv6NDProxyTest, self).setUp()
1453 # create 3 pg interfaces
1454 self.create_pg_interfaces(range(3))
1456 # pg0 is the master interface, with the configured subnet
1458 self.pg0.config_ip6()
1459 self.pg0.resolve_ndp()
1461 self.pg1.ip6_enable()
1462 self.pg2.ip6_enable()
1465 super(IPv6NDProxyTest, self).tearDown()
1467 def test_nd_proxy(self):
1468 """ IPv6 Proxy ND """
1471 # Generate some hosts in the subnet that we are proxying
1473 self.pg0.generate_remote_hosts(8)
1475 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1476 d = inet_ntop(AF_INET6, nsma)
1479 # Send an NS for one of those remote hosts on one of the proxy links
1480 # expect no response since it's from an address that is not
1481 # on the link that has the prefix configured
1483 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
1485 src=self.pg0._remote_hosts[2].ip6) /
1486 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
1487 ICMPv6NDOptSrcLLAddr(
1488 lladdr=self.pg0._remote_hosts[2].mac))
1490 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1493 # Add proxy support for the host
1495 self.vapi.ip6nd_proxy_add_del(
1496 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1497 sw_if_index=self.pg1.sw_if_index)
1500 # try that NS again. this time we expect an NA back
1502 self.send_and_expect_na(self.pg1, ns_pg1,
1503 "NS to proxy entry",
1504 dst_ip=self.pg0._remote_hosts[2].ip6,
1505 tgt_ip=self.pg0.local_ip6)
1508 # ... and that we have an entry in the ND cache
1510 self.assertTrue(find_nbr(self,
1511 self.pg1.sw_if_index,
1512 self.pg0._remote_hosts[2].ip6))
1515 # ... and we can route traffic to it
1517 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1518 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1519 src=self.pg0.remote_ip6) /
1520 inet6.UDP(sport=10000, dport=20000) /
1523 self.pg0.add_stream(t)
1524 self.pg_enable_capture(self.pg_interfaces)
1526 rx = self.pg1.get_capture(1)
1529 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1530 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1532 self.assertEqual(rx[IPv6].src,
1534 self.assertEqual(rx[IPv6].dst,
1538 # Test we proxy for the host on the main interface
1540 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1541 IPv6(dst=d, src=self.pg0.remote_ip6) /
1543 tgt=self.pg0._remote_hosts[2].ip6) /
1544 ICMPv6NDOptSrcLLAddr(
1545 lladdr=self.pg0.remote_mac))
1547 self.send_and_expect_na(self.pg0, ns_pg0,
1548 "NS to proxy entry on main",
1549 tgt_ip=self.pg0._remote_hosts[2].ip6,
1550 dst_ip=self.pg0.remote_ip6)
1553 # Setup and resolve proxy for another host on another interface
1555 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
1557 src=self.pg0._remote_hosts[3].ip6) /
1558 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
1559 ICMPv6NDOptSrcLLAddr(
1560 lladdr=self.pg0._remote_hosts[2].mac))
1562 self.vapi.ip6nd_proxy_add_del(
1563 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1564 sw_if_index=self.pg2.sw_if_index)
1566 self.send_and_expect_na(self.pg2, ns_pg2,
1567 "NS to proxy entry other interface",
1568 dst_ip=self.pg0._remote_hosts[3].ip6,
1569 tgt_ip=self.pg0.local_ip6)
1571 self.assertTrue(find_nbr(self,
1572 self.pg2.sw_if_index,
1573 self.pg0._remote_hosts[3].ip6))
1576 # hosts can communicate. pg2->pg1
1578 t2 = (Ether(dst=self.pg2.local_mac,
1579 src=self.pg0.remote_hosts[3].mac) /
1580 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1581 src=self.pg0._remote_hosts[3].ip6) /
1582 inet6.UDP(sport=10000, dport=20000) /
1585 self.pg2.add_stream(t2)
1586 self.pg_enable_capture(self.pg_interfaces)
1588 rx = self.pg1.get_capture(1)
1591 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1592 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1594 self.assertEqual(rx[IPv6].src,
1596 self.assertEqual(rx[IPv6].dst,
1600 # remove the proxy configs
1602 self.vapi.ip6nd_proxy_add_del(
1603 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1604 sw_if_index=self.pg1.sw_if_index, is_add=0)
1605 self.vapi.ip6nd_proxy_add_del(
1606 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1607 sw_if_index=self.pg2.sw_if_index, is_add=0)
1609 self.assertFalse(find_nbr(self,
1610 self.pg2.sw_if_index,
1611 self.pg0._remote_hosts[3].ip6))
1612 self.assertFalse(find_nbr(self,
1613 self.pg1.sw_if_index,
1614 self.pg0._remote_hosts[2].ip6))
1617 # no longer proxy-ing...
1619 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1620 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1621 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1624 # no longer forwarding. traffic generates NS out of the glean/main
1627 self.pg2.add_stream(t2)
1628 self.pg_enable_capture(self.pg_interfaces)
1631 rx = self.pg0.get_capture(1)
1633 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1636 class TestIPNull(VppTestCase):
1637 """ IPv6 routes via NULL """
1640 def setUpClass(cls):
1641 super(TestIPNull, cls).setUpClass()
1644 def tearDownClass(cls):
1645 super(TestIPNull, cls).tearDownClass()
1648 super(TestIPNull, self).setUp()
1650 # create 2 pg interfaces
1651 self.create_pg_interfaces(range(1))
1653 for i in self.pg_interfaces:
1659 super(TestIPNull, self).tearDown()
1660 for i in self.pg_interfaces:
1664 def test_ip_null(self):
1665 """ IP NULL route """
1667 p = (Ether(src=self.pg0.remote_mac,
1668 dst=self.pg0.local_mac) /
1669 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
1670 inet6.UDP(sport=1234, dport=1234) /
1674 # A route via IP NULL that will reply with ICMP unreachables
1676 ip_unreach = VppIpRoute(
1678 [VppRoutePath("::", 0xffffffff,
1679 type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)])
1680 ip_unreach.add_vpp_config()
1682 self.pg0.add_stream(p)
1683 self.pg_enable_capture(self.pg_interfaces)
1686 rx = self.pg0.get_capture(1)
1688 icmp = rx[ICMPv6DestUnreach]
1690 # 0 = "No route to destination"
1691 self.assertEqual(icmp.code, 0)
1693 # ICMP is rate limited. pause a bit
1697 # A route via IP NULL that will reply with ICMP prohibited
1699 ip_prohibit = VppIpRoute(
1700 self, "2001::1", 128,
1701 [VppRoutePath("::", 0xffffffff,
1702 type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)])
1703 ip_prohibit.add_vpp_config()
1705 self.pg0.add_stream(p)
1706 self.pg_enable_capture(self.pg_interfaces)
1709 rx = self.pg0.get_capture(1)
1711 icmp = rx[ICMPv6DestUnreach]
1713 # 1 = "Communication with destination administratively prohibited"
1714 self.assertEqual(icmp.code, 1)
1717 class TestIPDisabled(VppTestCase):
1718 """ IPv6 disabled """
1721 def setUpClass(cls):
1722 super(TestIPDisabled, cls).setUpClass()
1725 def tearDownClass(cls):
1726 super(TestIPDisabled, cls).tearDownClass()
1729 super(TestIPDisabled, self).setUp()
1731 # create 2 pg interfaces
1732 self.create_pg_interfaces(range(2))
1736 self.pg0.config_ip6()
1737 self.pg0.resolve_ndp()
1739 # PG 1 is not IP enabled
1743 super(TestIPDisabled, self).tearDown()
1744 for i in self.pg_interfaces:
1748 def test_ip_disabled(self):
1753 # one accepting interface, pg0, 2 forwarding interfaces
1755 route_ff_01 = VppIpMRoute(
1759 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1760 [VppMRoutePath(self.pg1.sw_if_index,
1761 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1762 VppMRoutePath(self.pg0.sw_if_index,
1763 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
1764 route_ff_01.add_vpp_config()
1766 pu = (Ether(src=self.pg1.remote_mac,
1767 dst=self.pg1.local_mac) /
1768 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
1769 inet6.UDP(sport=1234, dport=1234) /
1771 pm = (Ether(src=self.pg1.remote_mac,
1772 dst=self.pg1.local_mac) /
1773 IPv6(src="2001::1", dst="ffef::1") /
1774 inet6.UDP(sport=1234, dport=1234) /
1778 # PG1 does not forward IP traffic
1780 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1781 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1786 self.pg1.config_ip6()
1789 # Now we get packets through
1791 self.pg1.add_stream(pu)
1792 self.pg_enable_capture(self.pg_interfaces)
1794 rx = self.pg0.get_capture(1)
1796 self.pg1.add_stream(pm)
1797 self.pg_enable_capture(self.pg_interfaces)
1799 rx = self.pg0.get_capture(1)
1804 self.pg1.unconfig_ip6()
1807 # PG1 does not forward IP traffic
1809 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1810 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1813 class TestIP6LoadBalance(VppTestCase):
1814 """ IPv6 Load-Balancing """
1817 def setUpClass(cls):
1818 super(TestIP6LoadBalance, cls).setUpClass()
1821 def tearDownClass(cls):
1822 super(TestIP6LoadBalance, cls).tearDownClass()
1825 super(TestIP6LoadBalance, self).setUp()
1827 self.create_pg_interfaces(range(5))
1829 mpls_tbl = VppMplsTable(self, 0)
1830 mpls_tbl.add_vpp_config()
1832 for i in self.pg_interfaces:
1839 for i in self.pg_interfaces:
1843 super(TestIP6LoadBalance, self).tearDown()
1845 def pg_send(self, input, pkts):
1846 self.vapi.cli("clear trace")
1847 input.add_stream(pkts)
1848 self.pg_enable_capture(self.pg_interfaces)
1851 def send_and_expect_load_balancing(self, input, pkts, outputs):
1852 self.pg_send(input, pkts)
1854 rx = oo._get_capture(1)
1855 self.assertNotEqual(0, len(rx))
1857 def send_and_expect_one_itf(self, input, pkts, itf):
1858 self.pg_send(input, pkts)
1859 rx = itf.get_capture(len(pkts))
1861 def test_ip6_load_balance(self):
1862 """ IPv6 Load-Balancing """
1865 # An array of packets that differ only in the destination port
1869 # - MPLS non-EOS with an entropy label
1873 port_mpls_neos_pkts = []
1877 # An array of packets that differ only in the source address
1882 for ii in range(NUM_PKTS):
1884 IPv6(dst="3000::1", src="3000:1::1") /
1885 inet6.UDP(sport=1234, dport=1234 + ii) /
1887 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1888 dst=self.pg0.local_mac) /
1890 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1891 dst=self.pg0.local_mac) /
1892 MPLS(label=66, ttl=2) /
1894 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1895 dst=self.pg0.local_mac) /
1896 MPLS(label=67, ttl=2) /
1897 MPLS(label=77, ttl=2) /
1899 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1900 dst=self.pg0.local_mac) /
1901 MPLS(label=67, ttl=2) /
1902 MPLS(label=14, ttl=2) /
1903 MPLS(label=999, ttl=2) /
1906 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
1907 inet6.UDP(sport=1234, dport=1234) /
1909 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1910 dst=self.pg0.local_mac) /
1912 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1913 dst=self.pg0.local_mac) /
1914 MPLS(label=66, ttl=2) /
1918 # A route for the IP packets
1920 route_3000_1 = VppIpRoute(self, "3000::1", 128,
1921 [VppRoutePath(self.pg1.remote_ip6,
1922 self.pg1.sw_if_index),
1923 VppRoutePath(self.pg2.remote_ip6,
1924 self.pg2.sw_if_index)])
1925 route_3000_1.add_vpp_config()
1928 # a local-label for the EOS packets
1930 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
1931 binding.add_vpp_config()
1934 # An MPLS route for the non-EOS packets
1936 route_67 = VppMplsRoute(self, 67, 0,
1937 [VppRoutePath(self.pg1.remote_ip6,
1938 self.pg1.sw_if_index,
1940 VppRoutePath(self.pg2.remote_ip6,
1941 self.pg2.sw_if_index,
1943 route_67.add_vpp_config()
1946 # inject the packet on pg0 - expect load-balancing across the 2 paths
1947 # - since the default hash config is to use IP src,dst and port
1949 # We are not going to ensure equal amounts of packets across each link,
1950 # since the hash algorithm is statistical and therefore this can never
1951 # be guaranteed. But with 64 different packets we do expect some
1952 # balancing. So instead just ensure there is traffic on each link.
1954 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
1955 [self.pg1, self.pg2])
1956 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
1957 [self.pg1, self.pg2])
1958 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
1959 [self.pg1, self.pg2])
1960 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1961 [self.pg1, self.pg2])
1962 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
1963 [self.pg1, self.pg2])
1966 # The packets with Entropy label in should not load-balance,
1967 # since the Entropy value is fixed.
1969 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
1972 # change the flow hash config so it's only IP src,dst
1973 # - now only the stream with differing source address will
1976 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0,
1979 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
1980 [self.pg1, self.pg2])
1981 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1982 [self.pg1, self.pg2])
1983 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
1986 # change the flow hash config back to defaults
1988 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1,
1992 # Recursive prefixes
1993 # - testing that 2 stages of load-balancing occurs and there is no
1994 # polarisation (i.e. only 2 of 4 paths are used)
1999 for ii in range(257):
2000 port_pkts.append((Ether(src=self.pg0.remote_mac,
2001 dst=self.pg0.local_mac) /
2004 inet6.UDP(sport=1234,
2006 Raw(b'\xa5' * 100)))
2007 src_pkts.append((Ether(src=self.pg0.remote_mac,
2008 dst=self.pg0.local_mac) /
2010 src="4000:1::%d" % ii) /
2011 inet6.UDP(sport=1234, dport=1234) /
2012 Raw(b'\xa5' * 100)))
2014 route_3000_2 = VppIpRoute(self, "3000::2", 128,
2015 [VppRoutePath(self.pg3.remote_ip6,
2016 self.pg3.sw_if_index),
2017 VppRoutePath(self.pg4.remote_ip6,
2018 self.pg4.sw_if_index)])
2019 route_3000_2.add_vpp_config()
2021 route_4000_1 = VppIpRoute(self, "4000::1", 128,
2022 [VppRoutePath("3000::1",
2024 VppRoutePath("3000::2",
2026 route_4000_1.add_vpp_config()
2029 # inject the packet on pg0 - expect load-balancing across all 4 paths
2031 self.vapi.cli("clear trace")
2032 self.send_and_expect_load_balancing(self.pg0, port_pkts,
2033 [self.pg1, self.pg2,
2034 self.pg3, self.pg4])
2035 self.send_and_expect_load_balancing(self.pg0, src_pkts,
2036 [self.pg1, self.pg2,
2037 self.pg3, self.pg4])
2040 # Recursive prefixes
2041 # - testing that 2 stages of load-balancing no choices
2045 for ii in range(257):
2046 port_pkts.append((Ether(src=self.pg0.remote_mac,
2047 dst=self.pg0.local_mac) /
2050 inet6.UDP(sport=1234,
2052 Raw(b'\xa5' * 100)))
2054 route_5000_2 = VppIpRoute(self, "5000::2", 128,
2055 [VppRoutePath(self.pg3.remote_ip6,
2056 self.pg3.sw_if_index)])
2057 route_5000_2.add_vpp_config()
2059 route_6000_1 = VppIpRoute(self, "6000::1", 128,
2060 [VppRoutePath("5000::2",
2062 route_6000_1.add_vpp_config()
2065 # inject the packet on pg0 - expect load-balancing across all 4 paths
2067 self.vapi.cli("clear trace")
2068 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
2071 class TestIP6Punt(VppTestCase):
2072 """ IPv6 Punt Police/Redirect """
2075 def setUpClass(cls):
2076 super(TestIP6Punt, cls).setUpClass()
2079 def tearDownClass(cls):
2080 super(TestIP6Punt, cls).tearDownClass()
2083 super(TestIP6Punt, self).setUp()
2085 self.create_pg_interfaces(range(4))
2087 for i in self.pg_interfaces:
2093 super(TestIP6Punt, self).tearDown()
2094 for i in self.pg_interfaces:
2098 def test_ip_punt(self):
2099 """ IP6 punt police and redirect """
2101 p = (Ether(src=self.pg0.remote_mac,
2102 dst=self.pg0.local_mac) /
2103 IPv6(src=self.pg0.remote_ip6,
2104 dst=self.pg0.local_ip6) /
2105 inet6.TCP(sport=1234, dport=1234) /
2111 # Configure a punt redirect via pg1.
2113 nh_addr = self.pg1.remote_ip6
2114 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2115 self.pg1.sw_if_index,
2118 self.send_and_expect(self.pg0, pkts, self.pg1)
2123 policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1)
2124 policer.add_vpp_config()
2125 self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
2127 self.vapi.cli("clear trace")
2128 self.pg0.add_stream(pkts)
2129 self.pg_enable_capture(self.pg_interfaces)
2133 # the number of packet received should be greater than 0,
2134 # but not equal to the number sent, since some were policed
2136 rx = self.pg1._get_capture(1)
2137 self.assertGreater(len(rx), 0)
2138 self.assertLess(len(rx), len(pkts))
2141 # remove the policer. back to full rx
2143 self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
2144 policer.remove_vpp_config()
2145 self.send_and_expect(self.pg0, pkts, self.pg1)
2148 # remove the redirect. expect full drop.
2150 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2151 self.pg1.sw_if_index,
2154 self.send_and_assert_no_replies(self.pg0, pkts,
2155 "IP no punt config")
2158 # Add a redirect that is not input port selective
2160 self.vapi.ip_punt_redirect(0xffffffff,
2161 self.pg1.sw_if_index,
2163 self.send_and_expect(self.pg0, pkts, self.pg1)
2165 self.vapi.ip_punt_redirect(0xffffffff,
2166 self.pg1.sw_if_index,
2170 def test_ip_punt_dump(self):
2171 """ IP6 punt redirect dump"""
2174 # Configure a punt redirects
2176 nh_addr = self.pg3.remote_ip6
2177 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2178 self.pg3.sw_if_index,
2180 self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
2181 self.pg3.sw_if_index,
2183 self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
2184 self.pg3.sw_if_index,
2188 # Dump pg0 punt redirects
2190 punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
2193 self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
2196 # Dump punt redirects for all interfaces
2198 punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2199 self.assertEqual(len(punts), 3)
2201 self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
2202 self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2203 self.assertEqual(str(punts[2].punt.nh), '::')
2206 class TestIPDeag(VppTestCase):
2207 """ IPv6 Deaggregate Routes """
2210 def setUpClass(cls):
2211 super(TestIPDeag, cls).setUpClass()
2214 def tearDownClass(cls):
2215 super(TestIPDeag, cls).tearDownClass()
2218 super(TestIPDeag, self).setUp()
2220 self.create_pg_interfaces(range(3))
2222 for i in self.pg_interfaces:
2228 super(TestIPDeag, self).tearDown()
2229 for i in self.pg_interfaces:
2233 def test_ip_deag(self):
2234 """ IP Deag Routes """
2237 # Create a table to be used for:
2238 # 1 - another destination address lookup
2239 # 2 - a source address lookup
2241 table_dst = VppIpTable(self, 1, is_ip6=1)
2242 table_src = VppIpTable(self, 2, is_ip6=1)
2243 table_dst.add_vpp_config()
2244 table_src.add_vpp_config()
2247 # Add a route in the default table to point to a deag/
2248 # second lookup in each of these tables
2250 route_to_dst = VppIpRoute(self, "1::1", 128,
2254 route_to_src = VppIpRoute(
2259 type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)])
2261 route_to_dst.add_vpp_config()
2262 route_to_src.add_vpp_config()
2265 # packets to these destination are dropped, since they'll
2266 # hit the respective default routes in the second table
2268 p_dst = (Ether(src=self.pg0.remote_mac,
2269 dst=self.pg0.local_mac) /
2270 IPv6(src="5::5", dst="1::1") /
2271 inet6.TCP(sport=1234, dport=1234) /
2273 p_src = (Ether(src=self.pg0.remote_mac,
2274 dst=self.pg0.local_mac) /
2275 IPv6(src="2::2", dst="1::2") /
2276 inet6.TCP(sport=1234, dport=1234) /
2278 pkts_dst = p_dst * 257
2279 pkts_src = p_src * 257
2281 self.send_and_assert_no_replies(self.pg0, pkts_dst,
2283 self.send_and_assert_no_replies(self.pg0, pkts_src,
2287 # add a route in the dst table to forward via pg1
2289 route_in_dst = VppIpRoute(self, "1::1", 128,
2290 [VppRoutePath(self.pg1.remote_ip6,
2291 self.pg1.sw_if_index)],
2293 route_in_dst.add_vpp_config()
2295 self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2298 # add a route in the src table to forward via pg2
2300 route_in_src = VppIpRoute(self, "2::2", 128,
2301 [VppRoutePath(self.pg2.remote_ip6,
2302 self.pg2.sw_if_index)],
2304 route_in_src.add_vpp_config()
2305 self.send_and_expect(self.pg0, pkts_src, self.pg2)
2308 # loop in the lookup DP
2310 route_loop = VppIpRoute(self, "3::3", 128,
2313 route_loop.add_vpp_config()
2315 p_l = (Ether(src=self.pg0.remote_mac,
2316 dst=self.pg0.local_mac) /
2317 IPv6(src="3::4", dst="3::3") /
2318 inet6.TCP(sport=1234, dport=1234) /
2321 self.send_and_assert_no_replies(self.pg0, p_l * 257,
2325 class TestIP6Input(VppTestCase):
2326 """ IPv6 Input Exception Test Cases """
2329 def setUpClass(cls):
2330 super(TestIP6Input, cls).setUpClass()
2333 def tearDownClass(cls):
2334 super(TestIP6Input, cls).tearDownClass()
2337 super(TestIP6Input, self).setUp()
2339 self.create_pg_interfaces(range(2))
2341 for i in self.pg_interfaces:
2347 super(TestIP6Input, self).tearDown()
2348 for i in self.pg_interfaces:
2352 def test_ip_input_icmp_reply(self):
2353 """ IP6 Input Exception - Return ICMP (3,0) """
2355 # hop limit - ICMP replies
2357 p_version = (Ether(src=self.pg0.remote_mac,
2358 dst=self.pg0.local_mac) /
2359 IPv6(src=self.pg0.remote_ip6,
2360 dst=self.pg1.remote_ip6,
2362 inet6.UDP(sport=1234, dport=1234) /
2365 rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0)
2367 icmp = rx[ICMPv6TimeExceeded]
2369 # 0: "hop limit exceeded in transit",
2370 self.assertEqual((icmp.type, icmp.code), (3, 0))
2372 icmpv6_data = '\x0a' * 18
2374 all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2376 @parameterized.expand([
2377 # Name, src, dst, l4proto, msg, timeout
2378 ("src='iface', dst='iface'", None, None,
2379 inet6.UDP(sport=1234, dport=1234), "funky version", None),
2380 ("src='All 0's', dst='iface'", all_0s, None,
2381 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2382 ("src='iface', dst='All 0's'", None, all_0s,
2383 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2384 ("src='All 1's', dst='iface'", all_1s, None,
2385 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2386 ("src='iface', dst='All 1's'", None, all_1s,
2387 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2388 ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2389 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2392 def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2394 self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2396 p_version = (Ether(src=self.pg0.remote_mac,
2397 dst=self.pg0.local_mac) /
2398 IPv6(src=src or self.pg0.remote_ip6,
2399 dst=dst or self.pg1.remote_ip6,
2404 self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS,
2408 def test_hop_by_hop(self):
2409 """ Hop-by-hop header test """
2411 p = (Ether(src=self.pg0.remote_mac,
2412 dst=self.pg0.local_mac) /
2413 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
2414 IPv6ExtHdrHopByHop() /
2415 inet6.UDP(sport=1234, dport=1234) /
2418 self.pg0.add_stream(p)
2419 self.pg_enable_capture(self.pg_interfaces)
2423 class TestIPReplace(VppTestCase):
2424 """ IPv6 Table Replace """
2427 def setUpClass(cls):
2428 super(TestIPReplace, cls).setUpClass()
2431 def tearDownClass(cls):
2432 super(TestIPReplace, cls).tearDownClass()
2435 super(TestIPReplace, self).setUp()
2437 self.create_pg_interfaces(range(4))
2442 for i in self.pg_interfaces:
2446 i.generate_remote_hosts(2)
2447 self.tables.append(VppIpTable(self, table_id,
2448 True).add_vpp_config())
2452 super(TestIPReplace, self).tearDown()
2453 for i in self.pg_interfaces:
2457 def test_replace(self):
2458 """ IP Table Replace """
2461 links = [self.pg0, self.pg1, self.pg2, self.pg3]
2462 routes = [[], [], [], []]
2464 # the sizes of 'empty' tables
2465 for t in self.tables:
2466 self.assertEqual(len(t.dump()), 2)
2467 self.assertEqual(len(t.mdump()), 5)
2469 # load up the tables with some routes
2470 for ii, t in enumerate(self.tables):
2471 for jj in range(1, N_ROUTES):
2473 self, "2001::%d" % jj if jj != 0 else "2001::", 128,
2474 [VppRoutePath(links[ii].remote_hosts[0].ip6,
2475 links[ii].sw_if_index),
2476 VppRoutePath(links[ii].remote_hosts[1].ip6,
2477 links[ii].sw_if_index)],
2478 table_id=t.table_id).add_vpp_config()
2479 multi = VppIpMRoute(
2481 "ff:2001::%d" % jj, 128,
2482 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
2483 [VppMRoutePath(self.pg0.sw_if_index,
2484 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
2485 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2486 VppMRoutePath(self.pg1.sw_if_index,
2487 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2488 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2489 VppMRoutePath(self.pg2.sw_if_index,
2490 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2491 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2492 VppMRoutePath(self.pg3.sw_if_index,
2493 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2494 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
2495 table_id=t.table_id).add_vpp_config()
2496 routes[ii].append({'uni': uni,
2500 # replace the tables a few times
2503 # replace each table
2504 for t in self.tables:
2507 # all the routes are still there
2508 for ii, t in enumerate(self.tables):
2511 for r in routes[ii]:
2512 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2513 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2515 # redownload the even numbered routes
2516 for ii, t in enumerate(self.tables):
2517 for jj in range(0, N_ROUTES, 2):
2518 routes[ii][jj]['uni'].add_vpp_config()
2519 routes[ii][jj]['multi'].add_vpp_config()
2521 # signal each table converged
2522 for t in self.tables:
2525 # we should find the even routes, but not the odd
2526 for ii, t in enumerate(self.tables):
2529 for jj in range(0, N_ROUTES, 2):
2530 self.assertTrue(find_route_in_dump(
2531 dump, routes[ii][jj]['uni'], t))
2532 self.assertTrue(find_mroute_in_dump(
2533 mdump, routes[ii][jj]['multi'], t))
2534 for jj in range(1, N_ROUTES - 1, 2):
2535 self.assertFalse(find_route_in_dump(
2536 dump, routes[ii][jj]['uni'], t))
2537 self.assertFalse(find_mroute_in_dump(
2538 mdump, routes[ii][jj]['multi'], t))
2540 # reload all the routes
2541 for ii, t in enumerate(self.tables):
2542 for r in routes[ii]:
2543 r['uni'].add_vpp_config()
2544 r['multi'].add_vpp_config()
2546 # all the routes are still there
2547 for ii, t in enumerate(self.tables):
2550 for r in routes[ii]:
2551 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2552 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2555 # finally flush the tables for good measure
2557 for t in self.tables:
2559 self.assertEqual(len(t.dump()), 2)
2560 self.assertEqual(len(t.mdump()), 5)
2563 if __name__ == '__main__':
2564 unittest.main(testRunner=VppTestRunner)