4 from socket import AF_INET6
6 from framework import VppTestCase, VppTestRunner
7 from vpp_sub_interface import VppSubInterface, VppDot1QSubint
8 from vpp_pg_interface import is_ipv6_misc
9 from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
10 VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
11 VppMplsRoute, DpoProto, VppMplsTable
12 from vpp_neighbor import find_nbr, VppNeighbor
14 from scapy.packet import Raw
15 from scapy.layers.l2 import Ether, Dot1Q
16 from scapy.layers.inet6 import IPv6, UDP, TCP, ICMPv6ND_NS, ICMPv6ND_RS, \
17 ICMPv6ND_RA, ICMPv6NDOptSrcLLAddr, getmacbyip6, ICMPv6MRD_Solicitation, \
18 ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
19 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
23 from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
24 in6_mactoifaceid, in6_ismaddr
25 from scapy.utils import inet_pton, inet_ntop
26 from scapy.contrib.mpls import MPLS
30 euid = in6_mactoifaceid(mac)
31 addr = "fe80::" + euid
35 class TestIPv6ND(VppTestCase):
36 def validate_ra(self, intf, rx, dst_ip=None):
38 dst_ip = intf.remote_ip6
40 # unicasted packets must come to the unicast mac
41 self.assertEqual(rx[Ether].dst, intf.remote_mac)
43 # and from the router's MAC
44 self.assertEqual(rx[Ether].src, intf.local_mac)
46 # the rx'd RA should be addressed to the sender's source
47 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
48 self.assertEqual(in6_ptop(rx[IPv6].dst),
51 # and come from the router's link local
52 self.assertTrue(in6_islladdr(rx[IPv6].src))
53 self.assertEqual(in6_ptop(rx[IPv6].src),
54 in6_ptop(mk_ll_addr(intf.local_mac)))
56 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
58 dst_ip = intf.remote_ip6
60 dst_ip = intf.local_ip6
62 # unicasted packets must come to the unicast mac
63 self.assertEqual(rx[Ether].dst, intf.remote_mac)
65 # and from the router's MAC
66 self.assertEqual(rx[Ether].src, intf.local_mac)
68 # the rx'd NA should be addressed to the sender's source
69 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
70 self.assertEqual(in6_ptop(rx[IPv6].dst),
73 # and come from the target address
74 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
76 # Dest link-layer options should have the router's MAC
77 dll = rx[ICMPv6NDOptDstLLAddr]
78 self.assertEqual(dll.lladdr, intf.local_mac)
80 def validate_ns(self, intf, rx, tgt_ip):
81 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
82 dst_ip = inet_ntop(AF_INET6, nsma)
85 self.assertEqual(rx[Ether].dst, "ff:ff:ff:ff:ff:ff")
87 # and from the router's MAC
88 self.assertEqual(rx[Ether].src, intf.local_mac)
90 # the rx'd NS should be addressed to an mcast address
91 # derived from the target address
92 self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
94 # expect the tgt IP in the NS header
96 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
98 # packet is from the router's local address
99 self.assertEqual(in6_ptop(rx[IPv6].src), intf.local_ip6)
101 # Src link-layer options should have the router's MAC
102 sll = rx[ICMPv6NDOptSrcLLAddr]
103 self.assertEqual(sll.lladdr, intf.local_mac)
105 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
106 filter_out_fn=is_ipv6_misc):
107 intf.add_stream(pkts)
108 self.pg_enable_capture(self.pg_interfaces)
110 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
112 self.assertEqual(len(rx), 1)
114 self.validate_ra(intf, rx, dst_ip)
116 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
118 filter_out_fn=is_ipv6_misc):
119 intf.add_stream(pkts)
120 self.pg_enable_capture(self.pg_interfaces)
122 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
124 self.assertEqual(len(rx), 1)
126 self.validate_na(intf, rx, dst_ip, tgt_ip)
128 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
129 filter_out_fn=is_ipv6_misc):
130 tx_intf.add_stream(pkts)
131 self.pg_enable_capture(self.pg_interfaces)
133 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
135 self.assertEqual(len(rx), 1)
137 self.validate_ns(rx_intf, rx, tgt_ip)
139 def verify_ip(self, rx, smac, dmac, sip, dip):
141 self.assertEqual(ether.dst, dmac)
142 self.assertEqual(ether.src, smac)
145 self.assertEqual(ip.src, sip)
146 self.assertEqual(ip.dst, dip)
149 class TestIPv6(TestIPv6ND):
150 """ IPv6 Test Case """
154 super(TestIPv6, cls).setUpClass()
158 Perform test setup before test case.
161 - create 3 pg interfaces
162 - untagged pg0 interface
163 - Dot1Q subinterface on pg1
164 - Dot1AD subinterface on pg2
166 - put it into UP state
168 - resolve neighbor address using NDP
169 - configure 200 fib entries
171 :ivar list interfaces: pg interfaces and subinterfaces.
172 :ivar dict flows: IPv4 packet flows in test.
173 :ivar list pg_if_packet_sizes: packet sizes in test.
175 *TODO:* Create AD sub interface
177 super(TestIPv6, self).setUp()
179 # create 3 pg interfaces
180 self.create_pg_interfaces(range(3))
182 # create 2 subinterfaces for p1 and pg2
183 self.sub_interfaces = [
184 VppDot1QSubint(self, self.pg1, 100),
185 VppDot1QSubint(self, self.pg2, 200)
186 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
189 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
191 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
192 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
193 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
196 self.pg_if_packet_sizes = [64, 512, 1518, 9018]
197 self.sub_if_packet_sizes = [64, 512, 1518 + 4, 9018 + 4]
199 self.interfaces = list(self.pg_interfaces)
200 self.interfaces.extend(self.sub_interfaces)
202 # setup all interfaces
203 for i in self.interfaces:
208 # config 2M FIB entries
209 self.config_fib_entries(200)
212 """Run standard test teardown and log ``show ip6 neighbors``."""
213 for i in self.sub_interfaces:
217 i.remove_vpp_config()
219 super(TestIPv6, self).tearDown()
220 if not self.vpp_dead:
221 self.logger.info(self.vapi.cli("show ip6 neighbors"))
222 # info(self.vapi.cli("show ip6 fib")) # many entries
224 def config_fib_entries(self, count):
225 """For each interface add to the FIB table *count* routes to
226 "fd02::1/128" destination with interface's local address as next-hop
229 :param int count: Number of FIB entries.
231 - *TODO:* check if the next-hop address shouldn't be remote address
232 instead of local address.
234 n_int = len(self.interfaces)
237 dest_addr = inet_pton(AF_INET6, "fd02::1")
239 for i in self.interfaces:
240 next_hop_address = i.local_ip6n
241 for j in range(count / n_int):
242 self.vapi.ip_add_del_route(
243 dest_addr, dest_addr_len, next_hop_address, is_ipv6=1)
245 if counter / count * 100 > percent:
246 self.logger.info("Configure %d FIB entries .. %d%% done" %
250 def create_stream(self, src_if, packet_sizes):
251 """Create input packet stream for defined interface.
253 :param VppInterface src_if: Interface to create packet stream for.
254 :param list packet_sizes: Required packet sizes.
257 for i in range(0, 257):
258 dst_if = self.flows[src_if][i % 2]
259 info = self.create_packet_info(src_if, dst_if)
260 payload = self.info_to_payload(info)
261 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
262 IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6) /
263 UDP(sport=1234, dport=1234) /
266 if isinstance(src_if, VppSubInterface):
267 p = src_if.add_dot1_layer(p)
268 size = packet_sizes[(i // 2) % len(packet_sizes)]
269 self.extend_packet(p, size)
273 def verify_capture(self, dst_if, capture):
274 """Verify captured input packet stream for defined interface.
276 :param VppInterface dst_if: Interface to verify captured packet stream
278 :param list capture: Captured packet stream.
280 self.logger.info("Verifying capture on interface %s" % dst_if.name)
282 for i in self.interfaces:
283 last_info[i.sw_if_index] = None
285 dst_sw_if_index = dst_if.sw_if_index
286 if hasattr(dst_if, 'parent'):
288 for packet in capture:
290 # Check VLAN tags and Ethernet header
291 packet = dst_if.remove_dot1_layer(packet)
292 self.assertTrue(Dot1Q not in packet)
296 payload_info = self.payload_to_info(str(packet[Raw]))
297 packet_index = payload_info.index
298 self.assertEqual(payload_info.dst, dst_sw_if_index)
300 "Got packet on port %s: src=%u (id=%u)" %
301 (dst_if.name, payload_info.src, packet_index))
302 next_info = self.get_next_packet_info_for_interface2(
303 payload_info.src, dst_sw_if_index,
304 last_info[payload_info.src])
305 last_info[payload_info.src] = next_info
306 self.assertTrue(next_info is not None)
307 self.assertEqual(packet_index, next_info.index)
308 saved_packet = next_info.data
309 # Check standard fields
310 self.assertEqual(ip.src, saved_packet[IPv6].src)
311 self.assertEqual(ip.dst, saved_packet[IPv6].dst)
312 self.assertEqual(udp.sport, saved_packet[UDP].sport)
313 self.assertEqual(udp.dport, saved_packet[UDP].dport)
315 self.logger.error(ppp("Unexpected or invalid packet:", packet))
317 for i in self.interfaces:
318 remaining_packet = self.get_next_packet_info_for_interface2(
319 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
320 self.assertTrue(remaining_packet is None,
321 "Interface %s: Packet expected from interface %s "
322 "didn't arrive" % (dst_if.name, i.name))
328 - Create IPv6 stream for pg0 interface
329 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
330 - Send and verify received packets on each interface.
333 pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes)
334 self.pg0.add_stream(pkts)
336 for i in self.sub_interfaces:
337 pkts = self.create_stream(i, self.sub_if_packet_sizes)
338 i.parent.add_stream(pkts)
340 self.pg_enable_capture(self.pg_interfaces)
343 pkts = self.pg0.get_capture()
344 self.verify_capture(self.pg0, pkts)
346 for i in self.sub_interfaces:
347 pkts = i.parent.get_capture()
348 self.verify_capture(i, pkts)
351 """ IPv6 Neighbour Solicitation Exceptions
354 - Send an NS Sourced from an address not covered by the link sub-net
355 - Send an NS to an mcast address the router has not joined
356 - Send NS for a target address the router does not onn.
360 # An NS from a non link source address
362 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
363 d = inet_ntop(AF_INET6, nsma)
365 p = (Ether(dst=in6_getnsmac(nsma)) /
366 IPv6(dst=d, src="2002::2") /
367 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
368 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
371 self.send_and_assert_no_replies(
373 "No response to NS source by address not on sub-net")
376 # An NS for sent to a solicited mcast group the router is
377 # not a member of FAILS
380 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
381 d = inet_ntop(AF_INET6, nsma)
383 p = (Ether(dst=in6_getnsmac(nsma)) /
384 IPv6(dst=d, src=self.pg0.remote_ip6) /
385 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
386 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
389 self.send_and_assert_no_replies(
391 "No response to NS sent to unjoined mcast address")
394 # An NS whose target address is one the router does not own
396 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
397 d = inet_ntop(AF_INET6, nsma)
399 p = (Ether(dst=in6_getnsmac(nsma)) /
400 IPv6(dst=d, src=self.pg0.remote_ip6) /
401 ICMPv6ND_NS(tgt="fd::ffff") /
402 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
405 self.send_and_assert_no_replies(self.pg0, pkts,
406 "No response to NS for unknown target")
409 # A neighbor entry that has no associated FIB-entry
411 self.pg0.generate_remote_hosts(4)
412 nd_entry = VppNeighbor(self,
413 self.pg0.sw_if_index,
414 self.pg0.remote_hosts[2].mac,
415 self.pg0.remote_hosts[2].ip6,
418 nd_entry.add_vpp_config()
421 # check we have the neighbor, but no route
423 self.assertTrue(find_nbr(self,
424 self.pg0.sw_if_index,
425 self.pg0._remote_hosts[2].ip6,
427 self.assertFalse(find_route(self,
428 self.pg0._remote_hosts[2].ip6,
433 # send an NS from a link local address to the interface's global
436 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
437 IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
438 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
439 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
441 self.send_and_expect_na(self.pg0, p,
442 "NS from link-local",
443 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
444 tgt_ip=self.pg0.local_ip6)
447 # we should have learned an ND entry for the peer's link-local
448 # but not inserted a route to it in the FIB
450 self.assertTrue(find_nbr(self,
451 self.pg0.sw_if_index,
452 self.pg0._remote_hosts[2].ip6_ll,
454 self.assertFalse(find_route(self,
455 self.pg0._remote_hosts[2].ip6_ll,
460 # An NS to the router's own Link-local
462 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
463 IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
464 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
465 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
467 self.send_and_expect_na(self.pg0, p,
468 "NS to/from link-local",
469 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
470 tgt_ip=self.pg0.local_ip6_ll)
473 # we should have learned an ND entry for the peer's link-local
474 # but not inserted a route to it in the FIB
476 self.assertTrue(find_nbr(self,
477 self.pg0.sw_if_index,
478 self.pg0._remote_hosts[3].ip6_ll,
480 self.assertFalse(find_route(self,
481 self.pg0._remote_hosts[3].ip6_ll,
485 def test_ns_duplicates(self):
489 # Generate some hosts on the LAN
491 self.pg1.generate_remote_hosts(3)
494 # Add host 1 on pg1 and pg2
496 ns_pg1 = VppNeighbor(self,
497 self.pg1.sw_if_index,
498 self.pg1.remote_hosts[1].mac,
499 self.pg1.remote_hosts[1].ip6,
501 ns_pg1.add_vpp_config()
502 ns_pg2 = VppNeighbor(self,
503 self.pg2.sw_if_index,
505 self.pg1.remote_hosts[1].ip6,
507 ns_pg2.add_vpp_config()
510 # IP packet destined for pg1 remote host arrives on pg1 again.
512 p = (Ether(dst=self.pg0.local_mac,
513 src=self.pg0.remote_mac) /
514 IPv6(src=self.pg0.remote_ip6,
515 dst=self.pg1.remote_hosts[1].ip6) /
516 UDP(sport=1234, dport=1234) /
519 self.pg0.add_stream(p)
520 self.pg_enable_capture(self.pg_interfaces)
523 rx1 = self.pg1.get_capture(1)
525 self.verify_ip(rx1[0],
527 self.pg1.remote_hosts[1].mac,
529 self.pg1.remote_hosts[1].ip6)
532 # remove the duplicate on pg1
533 # packet stream shoud generate NSs out of pg1
535 ns_pg1.remove_vpp_config()
537 self.send_and_expect_ns(self.pg0, self.pg1,
538 p, self.pg1.remote_hosts[1].ip6)
543 ns_pg1.add_vpp_config()
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)
557 def validate_ra(self, intf, rx, dst_ip=None, mtu=9000, pi_opt=None):
559 dst_ip = intf.remote_ip6
561 # unicasted packets must come to the unicast mac
562 self.assertEqual(rx[Ether].dst, intf.remote_mac)
564 # and from the router's MAC
565 self.assertEqual(rx[Ether].src, intf.local_mac)
567 # the rx'd RA should be addressed to the sender's source
568 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
569 self.assertEqual(in6_ptop(rx[IPv6].dst),
572 # and come from the router's link local
573 self.assertTrue(in6_islladdr(rx[IPv6].src))
574 self.assertEqual(in6_ptop(rx[IPv6].src),
575 in6_ptop(mk_ll_addr(intf.local_mac)))
577 # it should contain the links MTU
579 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
581 # it should contain the source's link layer address option
582 sll = ra[ICMPv6NDOptSrcLLAddr]
583 self.assertEqual(sll.lladdr, intf.local_mac)
586 # the RA should not contain prefix information
587 self.assertFalse(ra.haslayer(ICMPv6NDOptPrefixInfo))
589 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
591 # the options are nested in the scapy packet in way that i cannot
592 # decipher how to decode. this 1st layer of option always returns
593 # nested classes, so a direct obj1=obj2 comparison always fails.
594 # however, the getlayer(.., 2) does give one instnace.
595 # so we cheat here and construct a new opt instnace for comparison
596 rd = ICMPv6NDOptPrefixInfo(prefixlen=raos.prefixlen,
600 if type(pi_opt) is list:
601 for ii in range(len(pi_opt)):
602 self.assertEqual(pi_opt[ii], rd)
603 rd = rx.getlayer(ICMPv6NDOptPrefixInfo, ii+2)
605 self.assertEqual(pi_opt, raos)
607 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
608 filter_out_fn=is_ipv6_misc,
610 intf.add_stream(pkts)
611 self.pg_enable_capture(self.pg_interfaces)
613 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
615 self.assertEqual(len(rx), 1)
617 self.validate_ra(intf, rx, dst_ip, pi_opt=opt)
620 """ IPv6 Router Solicitation Exceptions
626 # Before we begin change the IPv6 RA responses to use the unicast
627 # address - that way we will not confuse them with the periodic
628 # RAs which go to the mcast address
629 # Sit and wait for the first periodic RA.
633 self.pg0.ip6_ra_config(send_unicast=1)
636 # An RS from a link source address
637 # - expect an RA in return
639 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
640 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
643 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
646 # For the next RS sent the RA should be rate limited
648 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
651 # When we reconfiure the IPv6 RA config, we reset the RA rate limiting,
652 # so we need to do this before each test below so as not to drop
653 # packets for rate limiting reasons. Test this works here.
655 self.pg0.ip6_ra_config(send_unicast=1)
656 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
659 # An RS sent from a non-link local source
661 self.pg0.ip6_ra_config(send_unicast=1)
662 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
663 IPv6(dst=self.pg0.local_ip6, src="2002::ffff") /
666 self.send_and_assert_no_replies(self.pg0, pkts,
667 "RS from non-link source")
670 # Source an RS from a link local address
672 self.pg0.ip6_ra_config(send_unicast=1)
673 ll = mk_ll_addr(self.pg0.remote_mac)
674 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
675 IPv6(dst=self.pg0.local_ip6, src=ll) /
678 self.send_and_expect_ra(self.pg0, pkts,
679 "RS sourced from link-local",
683 # Send the RS multicast
685 self.pg0.ip6_ra_config(send_unicast=1)
686 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
687 ll = mk_ll_addr(self.pg0.remote_mac)
688 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
689 IPv6(dst="ff02::2", src=ll) /
692 self.send_and_expect_ra(self.pg0, pkts,
693 "RS sourced from link-local",
697 # Source from the unspecified address ::. This happens when the RS
698 # is sent before the host has a configured address/sub-net,
699 # i.e. auto-config. Since the sender has no IP address, the reply
700 # comes back mcast - so the capture needs to not filter this.
701 # If we happen to pick up the periodic RA at this point then so be it,
704 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
705 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
706 IPv6(dst="ff02::2", src="::") /
709 self.send_and_expect_ra(self.pg0, pkts,
710 "RS sourced from unspecified",
715 # Configure The RA to announce the links prefix
717 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
718 self.pg0.local_ip6_prefix_len)
721 # RAs should now contain the prefix information option
723 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
724 prefix=self.pg0.local_ip6,
728 self.pg0.ip6_ra_config(send_unicast=1)
729 ll = mk_ll_addr(self.pg0.remote_mac)
730 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
731 IPv6(dst=self.pg0.local_ip6, src=ll) /
733 self.send_and_expect_ra(self.pg0, p,
734 "RA with prefix-info",
739 # Change the prefix info to not off-link
742 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
743 self.pg0.local_ip6_prefix_len,
746 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
747 prefix=self.pg0.local_ip6,
751 self.pg0.ip6_ra_config(send_unicast=1)
752 self.send_and_expect_ra(self.pg0, p,
753 "RA with Prefix info with L-flag=0",
758 # Change the prefix info to not off-link, no-autoconfig
759 # L and A flag are clear in the advert
761 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
762 self.pg0.local_ip6_prefix_len,
766 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
767 prefix=self.pg0.local_ip6,
771 self.pg0.ip6_ra_config(send_unicast=1)
772 self.send_and_expect_ra(self.pg0, p,
773 "RA with Prefix info with A & L-flag=0",
778 # Change the flag settings back to the defaults
779 # L and A flag are set in the advert
781 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
782 self.pg0.local_ip6_prefix_len)
784 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
785 prefix=self.pg0.local_ip6,
789 self.pg0.ip6_ra_config(send_unicast=1)
790 self.send_and_expect_ra(self.pg0, p,
791 "RA with Prefix info",
796 # Change the prefix info to not off-link, no-autoconfig
797 # L and A flag are clear in the advert
799 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
800 self.pg0.local_ip6_prefix_len,
804 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
805 prefix=self.pg0.local_ip6,
809 self.pg0.ip6_ra_config(send_unicast=1)
810 self.send_and_expect_ra(self.pg0, p,
811 "RA with Prefix info with A & L-flag=0",
816 # Use the reset to defults option to revert to defaults
817 # L and A flag are clear in the advert
819 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
820 self.pg0.local_ip6_prefix_len,
823 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
824 prefix=self.pg0.local_ip6,
828 self.pg0.ip6_ra_config(send_unicast=1)
829 self.send_and_expect_ra(self.pg0, p,
830 "RA with Prefix reverted to defaults",
835 # Advertise Another prefix. With no L-flag/A-flag
837 self.pg0.ip6_ra_prefix(self.pg1.local_ip6n,
838 self.pg1.local_ip6_prefix_len,
842 opt = [ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
843 prefix=self.pg0.local_ip6,
846 ICMPv6NDOptPrefixInfo(prefixlen=self.pg1.local_ip6_prefix_len,
847 prefix=self.pg1.local_ip6,
851 self.pg0.ip6_ra_config(send_unicast=1)
852 ll = mk_ll_addr(self.pg0.remote_mac)
853 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
854 IPv6(dst=self.pg0.local_ip6, src=ll) /
856 self.send_and_expect_ra(self.pg0, p,
857 "RA with multiple Prefix infos",
862 # Remove the first refix-info - expect the second is still in the
865 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
866 self.pg0.local_ip6_prefix_len,
869 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg1.local_ip6_prefix_len,
870 prefix=self.pg1.local_ip6,
874 self.pg0.ip6_ra_config(send_unicast=1)
875 self.send_and_expect_ra(self.pg0, p,
876 "RA with Prefix reverted to defaults",
881 # Remove the second prefix-info - expect no prefix-info i nthe adverts
883 self.pg0.ip6_ra_prefix(self.pg1.local_ip6n,
884 self.pg1.local_ip6_prefix_len,
887 self.pg0.ip6_ra_config(send_unicast=1)
888 self.send_and_expect_ra(self.pg0, p,
889 "RA with Prefix reverted to defaults",
893 # Reset the periodic advertisements back to default values
895 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
898 class IPv6NDProxyTest(TestIPv6ND):
899 """ IPv6 ND ProxyTest Case """
902 super(IPv6NDProxyTest, self).setUp()
904 # create 3 pg interfaces
905 self.create_pg_interfaces(range(3))
907 # pg0 is the master interface, with the configured subnet
909 self.pg0.config_ip6()
910 self.pg0.resolve_ndp()
912 self.pg1.ip6_enable()
913 self.pg2.ip6_enable()
916 super(IPv6NDProxyTest, self).tearDown()
918 def test_nd_proxy(self):
919 """ IPv6 Proxy ND """
922 # Generate some hosts in the subnet that we are proxying
924 self.pg0.generate_remote_hosts(8)
926 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
927 d = inet_ntop(AF_INET6, nsma)
930 # Send an NS for one of those remote hosts on one of the proxy links
931 # expect no response since it's from an address that is not
932 # on the link that has the prefix configured
934 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
935 IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6) /
936 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
937 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac))
939 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
942 # Add proxy support for the host
944 self.vapi.ip6_nd_proxy(
945 inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
946 self.pg1.sw_if_index)
949 # try that NS again. this time we expect an NA back
951 self.send_and_expect_na(self.pg1, ns_pg1,
953 dst_ip=self.pg0._remote_hosts[2].ip6,
954 tgt_ip=self.pg0.local_ip6)
957 # ... and that we have an entry in the ND cache
959 self.assertTrue(find_nbr(self,
960 self.pg1.sw_if_index,
961 self.pg0._remote_hosts[2].ip6,
965 # ... and we can route traffic to it
967 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
968 IPv6(dst=self.pg0._remote_hosts[2].ip6,
969 src=self.pg0.remote_ip6) /
970 UDP(sport=10000, dport=20000) /
973 self.pg0.add_stream(t)
974 self.pg_enable_capture(self.pg_interfaces)
976 rx = self.pg1.get_capture(1)
979 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
980 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
982 self.assertEqual(rx[IPv6].src, t[IPv6].src)
983 self.assertEqual(rx[IPv6].dst, t[IPv6].dst)
986 # Test we proxy for the host on the main interface
988 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
989 IPv6(dst=d, src=self.pg0.remote_ip6) /
990 ICMPv6ND_NS(tgt=self.pg0._remote_hosts[2].ip6) /
991 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
993 self.send_and_expect_na(self.pg0, ns_pg0,
994 "NS to proxy entry on main",
995 tgt_ip=self.pg0._remote_hosts[2].ip6,
996 dst_ip=self.pg0.remote_ip6)
999 # Setup and resolve proxy for another host on another interface
1001 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
1002 IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6) /
1003 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
1004 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac))
1006 self.vapi.ip6_nd_proxy(
1007 inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1008 self.pg2.sw_if_index)
1010 self.send_and_expect_na(self.pg2, ns_pg2,
1011 "NS to proxy entry other interface",
1012 dst_ip=self.pg0._remote_hosts[3].ip6,
1013 tgt_ip=self.pg0.local_ip6)
1015 self.assertTrue(find_nbr(self,
1016 self.pg2.sw_if_index,
1017 self.pg0._remote_hosts[3].ip6,
1021 # hosts can communicate. pg2->pg1
1023 t2 = (Ether(dst=self.pg2.local_mac,
1024 src=self.pg0.remote_hosts[3].mac) /
1025 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1026 src=self.pg0._remote_hosts[3].ip6) /
1027 UDP(sport=10000, dport=20000) /
1030 self.pg2.add_stream(t2)
1031 self.pg_enable_capture(self.pg_interfaces)
1033 rx = self.pg1.get_capture(1)
1036 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1037 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1039 self.assertEqual(rx[IPv6].src, t2[IPv6].src)
1040 self.assertEqual(rx[IPv6].dst, t2[IPv6].dst)
1043 # remove the proxy configs
1045 self.vapi.ip6_nd_proxy(
1046 inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1047 self.pg1.sw_if_index,
1049 self.vapi.ip6_nd_proxy(
1050 inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1051 self.pg2.sw_if_index,
1054 self.assertFalse(find_nbr(self,
1055 self.pg2.sw_if_index,
1056 self.pg0._remote_hosts[3].ip6,
1058 self.assertFalse(find_nbr(self,
1059 self.pg1.sw_if_index,
1060 self.pg0._remote_hosts[2].ip6,
1064 # no longer proxy-ing...
1066 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1067 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1068 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1071 # no longer forwarding. traffic generates NS out of the glean/main
1074 self.pg2.add_stream(t2)
1075 self.pg_enable_capture(self.pg_interfaces)
1078 rx = self.pg0.get_capture(1)
1080 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1083 class TestIPNull(VppTestCase):
1084 """ IPv6 routes via NULL """
1087 super(TestIPNull, self).setUp()
1089 # create 2 pg interfaces
1090 self.create_pg_interfaces(range(1))
1092 for i in self.pg_interfaces:
1098 super(TestIPNull, self).tearDown()
1099 for i in self.pg_interfaces:
1103 def test_ip_null(self):
1104 """ IP NULL route """
1106 p = (Ether(src=self.pg0.remote_mac,
1107 dst=self.pg0.local_mac) /
1108 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
1109 UDP(sport=1234, dport=1234) /
1113 # A route via IP NULL that will reply with ICMP unreachables
1115 ip_unreach = VppIpRoute(self, "2001::", 64, [], is_unreach=1, is_ip6=1)
1116 ip_unreach.add_vpp_config()
1118 self.pg0.add_stream(p)
1119 self.pg_enable_capture(self.pg_interfaces)
1122 rx = self.pg0.get_capture(1)
1124 icmp = rx[ICMPv6DestUnreach]
1126 # 0 = "No route to destination"
1127 self.assertEqual(icmp.code, 0)
1129 # ICMP is rate limited. pause a bit
1133 # A route via IP NULL that will reply with ICMP prohibited
1135 ip_prohibit = VppIpRoute(self, "2001::1", 128, [],
1136 is_prohibit=1, is_ip6=1)
1137 ip_prohibit.add_vpp_config()
1139 self.pg0.add_stream(p)
1140 self.pg_enable_capture(self.pg_interfaces)
1143 rx = self.pg0.get_capture(1)
1145 icmp = rx[ICMPv6DestUnreach]
1147 # 1 = "Communication with destination administratively prohibited"
1148 self.assertEqual(icmp.code, 1)
1151 class TestIPDisabled(VppTestCase):
1152 """ IPv6 disabled """
1155 super(TestIPDisabled, self).setUp()
1157 # create 2 pg interfaces
1158 self.create_pg_interfaces(range(2))
1162 self.pg0.config_ip6()
1163 self.pg0.resolve_ndp()
1165 # PG 1 is not IP enabled
1169 super(TestIPDisabled, self).tearDown()
1170 for i in self.pg_interfaces:
1174 def test_ip_disabled(self):
1179 # one accepting interface, pg0, 2 forwarding interfaces
1181 route_ff_01 = VppIpMRoute(
1185 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1186 [VppMRoutePath(self.pg1.sw_if_index,
1187 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1188 VppMRoutePath(self.pg0.sw_if_index,
1189 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
1191 route_ff_01.add_vpp_config()
1193 pu = (Ether(src=self.pg1.remote_mac,
1194 dst=self.pg1.local_mac) /
1195 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
1196 UDP(sport=1234, dport=1234) /
1198 pm = (Ether(src=self.pg1.remote_mac,
1199 dst=self.pg1.local_mac) /
1200 IPv6(src="2001::1", dst="ffef::1") /
1201 UDP(sport=1234, dport=1234) /
1205 # PG1 does not forward IP traffic
1207 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1208 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1213 self.pg1.config_ip6()
1216 # Now we get packets through
1218 self.pg1.add_stream(pu)
1219 self.pg_enable_capture(self.pg_interfaces)
1221 rx = self.pg0.get_capture(1)
1223 self.pg1.add_stream(pm)
1224 self.pg_enable_capture(self.pg_interfaces)
1226 rx = self.pg0.get_capture(1)
1231 self.pg1.unconfig_ip6()
1234 # PG1 does not forward IP traffic
1236 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1237 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1240 class TestIP6LoadBalance(VppTestCase):
1241 """ IPv6 Load-Balancing """
1244 super(TestIP6LoadBalance, self).setUp()
1246 self.create_pg_interfaces(range(5))
1248 mpls_tbl = VppMplsTable(self, 0)
1249 mpls_tbl.add_vpp_config()
1251 for i in self.pg_interfaces:
1258 for i in self.pg_interfaces:
1262 super(TestIP6LoadBalance, self).tearDown()
1264 def send_and_expect_load_balancing(self, input, pkts, outputs):
1265 self.vapi.cli("clear trace")
1266 input.add_stream(pkts)
1267 self.pg_enable_capture(self.pg_interfaces)
1270 rx = oo._get_capture(1)
1271 self.assertNotEqual(0, len(rx))
1273 def send_and_expect_one_itf(self, input, pkts, itf):
1274 self.vapi.cli("clear trace")
1275 input.add_stream(pkts)
1276 self.pg_enable_capture(self.pg_interfaces)
1278 rx = itf.get_capture(len(pkts))
1280 def test_ip6_load_balance(self):
1281 """ IPv6 Load-Balancing """
1284 # An array of packets that differ only in the destination port
1288 # - MPLS non-EOS with an entropy label
1292 port_mpls_neos_pkts = []
1296 # An array of packets that differ only in the source address
1301 for ii in range(65):
1302 port_ip_hdr = (IPv6(dst="3000::1", src="3000:1::1") /
1303 UDP(sport=1234, dport=1234 + ii) /
1305 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1306 dst=self.pg0.local_mac) /
1308 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1309 dst=self.pg0.local_mac) /
1310 MPLS(label=66, ttl=2) /
1312 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1313 dst=self.pg0.local_mac) /
1314 MPLS(label=67, ttl=2) /
1315 MPLS(label=77, ttl=2) /
1317 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1318 dst=self.pg0.local_mac) /
1319 MPLS(label=67, ttl=2) /
1320 MPLS(label=14, ttl=2) /
1321 MPLS(label=999, ttl=2) /
1323 src_ip_hdr = (IPv6(dst="3000::1", src="3000:1::%d" % ii) /
1324 UDP(sport=1234, dport=1234) /
1326 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1327 dst=self.pg0.local_mac) /
1329 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1330 dst=self.pg0.local_mac) /
1331 MPLS(label=66, ttl=2) /
1335 # A route for the IP pacekts
1337 route_3000_1 = VppIpRoute(self, "3000::1", 128,
1338 [VppRoutePath(self.pg1.remote_ip6,
1339 self.pg1.sw_if_index,
1340 proto=DpoProto.DPO_PROTO_IP6),
1341 VppRoutePath(self.pg2.remote_ip6,
1342 self.pg2.sw_if_index,
1343 proto=DpoProto.DPO_PROTO_IP6)],
1345 route_3000_1.add_vpp_config()
1348 # a local-label for the EOS packets
1350 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
1351 binding.add_vpp_config()
1354 # An MPLS route for the non-EOS packets
1356 route_67 = VppMplsRoute(self, 67, 0,
1357 [VppRoutePath(self.pg1.remote_ip6,
1358 self.pg1.sw_if_index,
1360 proto=DpoProto.DPO_PROTO_IP6),
1361 VppRoutePath(self.pg2.remote_ip6,
1362 self.pg2.sw_if_index,
1364 proto=DpoProto.DPO_PROTO_IP6)])
1365 route_67.add_vpp_config()
1368 # inject the packet on pg0 - expect load-balancing across the 2 paths
1369 # - since the default hash config is to use IP src,dst and port
1371 # We are not going to ensure equal amounts of packets across each link,
1372 # since the hash algorithm is statistical and therefore this can never
1373 # be guaranteed. But wuth 64 different packets we do expect some
1374 # balancing. So instead just ensure there is traffic on each link.
1376 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
1377 [self.pg1, self.pg2])
1378 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
1379 [self.pg1, self.pg2])
1380 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
1381 [self.pg1, self.pg2])
1382 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1383 [self.pg1, self.pg2])
1384 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
1385 [self.pg1, self.pg2])
1388 # The packets with Entropy label in should not load-balance,
1389 # since the Entorpy value is fixed.
1391 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
1394 # change the flow hash config so it's only IP src,dst
1395 # - now only the stream with differing source address will
1398 self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=0, dport=0)
1400 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
1401 [self.pg1, self.pg2])
1402 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1403 [self.pg1, self.pg2])
1404 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
1407 # change the flow hash config back to defaults
1409 self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=1, dport=1)
1412 # Recursive prefixes
1413 # - testing that 2 stages of load-balancing occurs and there is no
1414 # polarisation (i.e. only 2 of 4 paths are used)
1419 for ii in range(257):
1420 port_pkts.append((Ether(src=self.pg0.remote_mac,
1421 dst=self.pg0.local_mac) /
1422 IPv6(dst="4000::1", src="4000:1::1") /
1423 UDP(sport=1234, dport=1234 + ii) /
1425 src_pkts.append((Ether(src=self.pg0.remote_mac,
1426 dst=self.pg0.local_mac) /
1427 IPv6(dst="4000::1", src="4000:1::%d" % ii) /
1428 UDP(sport=1234, dport=1234) /
1431 route_3000_2 = VppIpRoute(self, "3000::2", 128,
1432 [VppRoutePath(self.pg3.remote_ip6,
1433 self.pg3.sw_if_index,
1434 proto=DpoProto.DPO_PROTO_IP6),
1435 VppRoutePath(self.pg4.remote_ip6,
1436 self.pg4.sw_if_index,
1437 proto=DpoProto.DPO_PROTO_IP6)],
1439 route_3000_2.add_vpp_config()
1441 route_4000_1 = VppIpRoute(self, "4000::1", 128,
1442 [VppRoutePath("3000::1",
1444 proto=DpoProto.DPO_PROTO_IP6),
1445 VppRoutePath("3000::2",
1447 proto=DpoProto.DPO_PROTO_IP6)],
1449 route_4000_1.add_vpp_config()
1452 # inject the packet on pg0 - expect load-balancing across all 4 paths
1454 self.vapi.cli("clear trace")
1455 self.send_and_expect_load_balancing(self.pg0, port_pkts,
1456 [self.pg1, self.pg2,
1457 self.pg3, self.pg4])
1458 self.send_and_expect_load_balancing(self.pg0, src_pkts,
1459 [self.pg1, self.pg2,
1460 self.pg3, self.pg4])
1463 # Recursive prefixes
1464 # - testing that 2 stages of load-balancing no choices
1468 for ii in range(257):
1469 port_pkts.append((Ether(src=self.pg0.remote_mac,
1470 dst=self.pg0.local_mac) /
1471 IPv6(dst="6000::1", src="6000:1::1") /
1472 UDP(sport=1234, dport=1234 + ii) /
1475 route_5000_2 = VppIpRoute(self, "5000::2", 128,
1476 [VppRoutePath(self.pg3.remote_ip6,
1477 self.pg3.sw_if_index,
1478 proto=DpoProto.DPO_PROTO_IP6)],
1480 route_5000_2.add_vpp_config()
1482 route_6000_1 = VppIpRoute(self, "6000::1", 128,
1483 [VppRoutePath("5000::2",
1485 proto=DpoProto.DPO_PROTO_IP6)],
1487 route_6000_1.add_vpp_config()
1490 # inject the packet on pg0 - expect load-balancing across all 4 paths
1492 self.vapi.cli("clear trace")
1493 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
1496 class TestIP6Punt(VppTestCase):
1497 """ IPv6 Punt Police/Redirect """
1500 super(TestIP6Punt, self).setUp()
1502 self.create_pg_interfaces(range(2))
1504 for i in self.pg_interfaces:
1510 super(TestIP6Punt, self).tearDown()
1511 for i in self.pg_interfaces:
1515 def test_ip_punt(self):
1516 """ IP6 punt police and redirect """
1518 p = (Ether(src=self.pg0.remote_mac,
1519 dst=self.pg0.local_mac) /
1520 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
1521 TCP(sport=1234, dport=1234) /
1527 # Configure a punt redirect via pg1.
1529 nh_addr = inet_pton(AF_INET6,
1530 self.pg1.remote_ip6)
1531 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
1532 self.pg1.sw_if_index,
1536 self.send_and_expect(self.pg0, pkts, self.pg1)
1541 policer = self.vapi.policer_add_del("ip6-punt", 400, 0, 10, 0,
1543 self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
1545 self.vapi.cli("clear trace")
1546 self.pg0.add_stream(pkts)
1547 self.pg_enable_capture(self.pg_interfaces)
1551 # the number of packet recieved should be greater than 0,
1552 # but not equal to the number sent, since some were policed
1554 rx = self.pg1._get_capture(1)
1555 self.assertTrue(len(rx) > 0)
1556 self.assertTrue(len(rx) < len(pkts))
1559 # remove the poilcer. back to full rx
1561 self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
1562 self.vapi.policer_add_del("ip6-punt", 400, 0, 10, 0,
1563 rate_type=1, is_add=0)
1564 self.send_and_expect(self.pg0, pkts, self.pg1)
1567 # remove the redirect. expect full drop.
1569 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
1570 self.pg1.sw_if_index,
1574 self.send_and_assert_no_replies(self.pg0, pkts,
1575 "IP no punt config")
1578 # Add a redirect that is not input port selective
1580 self.vapi.ip_punt_redirect(0xffffffff,
1581 self.pg1.sw_if_index,
1584 self.send_and_expect(self.pg0, pkts, self.pg1)
1586 self.vapi.ip_punt_redirect(0xffffffff,
1587 self.pg1.sw_if_index,
1593 class TestIP6Input(VppTestCase):
1594 """ IPv6 Input Exceptions """
1597 super(TestIP6Input, self).setUp()
1599 self.create_pg_interfaces(range(2))
1601 for i in self.pg_interfaces:
1607 super(TestIP6Input, self).tearDown()
1608 for i in self.pg_interfaces:
1612 def test_ip_input(self):
1613 """ IP6 Input Exceptions """
1616 # bad version - this is dropped
1618 p_version = (Ether(src=self.pg0.remote_mac,
1619 dst=self.pg0.local_mac) /
1620 IPv6(src=self.pg0.remote_ip6,
1621 dst=self.pg1.remote_ip6,
1623 UDP(sport=1234, dport=1234) /
1626 self.send_and_assert_no_replies(self.pg0, p_version * 65,
1630 # hop limit - IMCP replies
1632 p_version = (Ether(src=self.pg0.remote_mac,
1633 dst=self.pg0.local_mac) /
1634 IPv6(src=self.pg0.remote_ip6,
1635 dst=self.pg1.remote_ip6,
1637 UDP(sport=1234, dport=1234) /
1640 rx = self.send_and_expect(self.pg0, p_version * 65, self.pg0)
1642 icmp = rx[ICMPv6TimeExceeded]
1643 self.assertEqual(icmp.type, 3)
1644 # 0: "hop limit exceeded in transit",
1645 self.assertEqual(icmp.code, 0)
1648 if __name__ == '__main__':
1649 unittest.main(testRunner=VppTestRunner)