tests: changes for scapy 2.4.3 migration
[vpp.git] / test / test_ip6.py
1 #!/usr/bin/env python3
2
3 from socket import inet_pton, inet_ntop
4 import unittest
5
6 from parameterized import parameterized
7 import scapy.compat
8 import scapy.layers.inet6 as inet6
9 from scapy.contrib.mpls import MPLS
10 from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \
11     ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
12     ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
13     ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply, IPv6ExtHdrHopByHop
14 from scapy.layers.l2 import Ether, Dot1Q
15 from scapy.packet import Raw
16 from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
17     in6_mactoifaceid
18 from six import moves
19
20 from framework import VppTestCase, VppTestRunner
21 from util import ppp, ip6_normalize, mk_ll_addr
22 from vpp_ip import DpoProto
23 from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
24     VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
25     VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
26     VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump
27 from vpp_neighbor import find_nbr, VppNeighbor
28 from vpp_pg_interface import is_ipv6_misc
29 from vpp_sub_interface import VppSubInterface, VppDot1QSubint
30 from ipaddress import IPv6Network, IPv6Address
31
32 AF_INET6 = socket.AF_INET6
33
34 try:
35     text_type = unicode
36 except NameError:
37     text_type = str
38
39 NUM_PKTS = 67
40
41
42 class TestIPv6ND(VppTestCase):
43     def validate_ra(self, intf, rx, dst_ip=None):
44         if not dst_ip:
45             dst_ip = intf.remote_ip6
46
47         # unicasted packets must come to the unicast mac
48         self.assertEqual(rx[Ether].dst, intf.remote_mac)
49
50         # and from the router's MAC
51         self.assertEqual(rx[Ether].src, intf.local_mac)
52
53         # the rx'd RA should be addressed to the sender's source
54         self.assertTrue(rx.haslayer(ICMPv6ND_RA))
55         self.assertEqual(in6_ptop(rx[IPv6].dst),
56                          in6_ptop(dst_ip))
57
58         # and come from the router's link local
59         self.assertTrue(in6_islladdr(rx[IPv6].src))
60         self.assertEqual(in6_ptop(rx[IPv6].src),
61                          in6_ptop(mk_ll_addr(intf.local_mac)))
62
63     def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
64         if not dst_ip:
65             dst_ip = intf.remote_ip6
66         if not tgt_ip:
67             dst_ip = intf.local_ip6
68
69         # unicasted packets must come to the unicast mac
70         self.assertEqual(rx[Ether].dst, intf.remote_mac)
71
72         # and from the router's MAC
73         self.assertEqual(rx[Ether].src, intf.local_mac)
74
75         # the rx'd NA should be addressed to the sender's source
76         self.assertTrue(rx.haslayer(ICMPv6ND_NA))
77         self.assertEqual(in6_ptop(rx[IPv6].dst),
78                          in6_ptop(dst_ip))
79
80         # and come from the target address
81         self.assertEqual(
82             in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
83
84         # Dest link-layer options should have the router's MAC
85         dll = rx[ICMPv6NDOptDstLLAddr]
86         self.assertEqual(dll.lladdr, intf.local_mac)
87
88     def validate_ns(self, intf, rx, tgt_ip):
89         nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
90         dst_ip = inet_ntop(AF_INET6, nsma)
91
92         # NS is broadcast
93         self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
94
95         # and from the router's MAC
96         self.assertEqual(rx[Ether].src, intf.local_mac)
97
98         # the rx'd NS should be addressed to an mcast address
99         # derived from the target address
100         self.assertEqual(
101             in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
102
103         # expect the tgt IP in the NS header
104         ns = rx[ICMPv6ND_NS]
105         self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
106
107         # packet is from the router's local address
108         self.assertEqual(
109             in6_ptop(rx[IPv6].src), intf.local_ip6)
110
111         # Src link-layer options should have the router's MAC
112         sll = rx[ICMPv6NDOptSrcLLAddr]
113         self.assertEqual(sll.lladdr, intf.local_mac)
114
115     def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
116                            filter_out_fn=is_ipv6_misc):
117         intf.add_stream(pkts)
118         self.pg_enable_capture(self.pg_interfaces)
119         self.pg_start()
120         rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
121
122         self.assertEqual(len(rx), 1)
123         rx = rx[0]
124         self.validate_ra(intf, rx, dst_ip)
125
126     def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
127                            tgt_ip=None,
128                            filter_out_fn=is_ipv6_misc):
129         intf.add_stream(pkts)
130         self.pg_enable_capture(self.pg_interfaces)
131         self.pg_start()
132         rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
133
134         self.assertEqual(len(rx), 1)
135         rx = rx[0]
136         self.validate_na(intf, rx, dst_ip, tgt_ip)
137
138     def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
139                            filter_out_fn=is_ipv6_misc):
140         tx_intf.add_stream(pkts)
141         self.pg_enable_capture(self.pg_interfaces)
142         self.pg_start()
143         rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
144
145         self.assertEqual(len(rx), 1)
146         rx = rx[0]
147         self.validate_ns(rx_intf, rx, tgt_ip)
148
149     def verify_ip(self, rx, smac, dmac, sip, dip):
150         ether = rx[Ether]
151         self.assertEqual(ether.dst, dmac)
152         self.assertEqual(ether.src, smac)
153
154         ip = rx[IPv6]
155         self.assertEqual(ip.src, sip)
156         self.assertEqual(ip.dst, dip)
157
158
159 class TestIPv6(TestIPv6ND):
160     """ IPv6 Test Case """
161
162     @classmethod
163     def setUpClass(cls):
164         super(TestIPv6, cls).setUpClass()
165
166     @classmethod
167     def tearDownClass(cls):
168         super(TestIPv6, cls).tearDownClass()
169
170     def setUp(self):
171         """
172         Perform test setup before test case.
173
174         **Config:**
175             - create 3 pg interfaces
176                 - untagged pg0 interface
177                 - Dot1Q subinterface on pg1
178                 - Dot1AD subinterface on pg2
179             - setup interfaces:
180                 - put it into UP state
181                 - set IPv6 addresses
182                 - resolve neighbor address using NDP
183             - configure 200 fib entries
184
185         :ivar list interfaces: pg interfaces and subinterfaces.
186         :ivar dict flows: IPv4 packet flows in test.
187
188         *TODO:* Create AD sub interface
189         """
190         super(TestIPv6, self).setUp()
191
192         # create 3 pg interfaces
193         self.create_pg_interfaces(range(3))
194
195         # create 2 subinterfaces for p1 and pg2
196         self.sub_interfaces = [
197             VppDot1QSubint(self, self.pg1, 100),
198             VppDot1QSubint(self, self.pg2, 200)
199             # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
200         ]
201
202         # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
203         self.flows = dict()
204         self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
205         self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
206         self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
207
208         # packet sizes
209         self.pg_if_packet_sizes = [64, 1500, 9020]
210
211         self.interfaces = list(self.pg_interfaces)
212         self.interfaces.extend(self.sub_interfaces)
213
214         # setup all interfaces
215         for i in self.interfaces:
216             i.admin_up()
217             i.config_ip6()
218             i.resolve_ndp()
219
220     def tearDown(self):
221         """Run standard test teardown and log ``show ip6 neighbors``."""
222         for i in self.interfaces:
223             i.unconfig_ip6()
224             i.ip6_disable()
225             i.admin_down()
226         for i in self.sub_interfaces:
227             i.remove_vpp_config()
228
229         super(TestIPv6, self).tearDown()
230         if not self.vpp_dead:
231             self.logger.info(self.vapi.cli("show ip6 neighbors"))
232             # info(self.vapi.cli("show ip6 fib"))  # many entries
233
234     def modify_packet(self, src_if, packet_size, pkt):
235         """Add load, set destination IP and extend packet to required packet
236         size for defined interface.
237
238         :param VppInterface src_if: Interface to create packet for.
239         :param int packet_size: Required packet size.
240         :param Scapy pkt: Packet to be modified.
241         """
242         dst_if_idx = int(packet_size / 10 % 2)
243         dst_if = self.flows[src_if][dst_if_idx]
244         info = self.create_packet_info(src_if, dst_if)
245         payload = self.info_to_payload(info)
246         p = pkt / Raw(payload)
247         p[IPv6].dst = dst_if.remote_ip6
248         info.data = p.copy()
249         if isinstance(src_if, VppSubInterface):
250             p = src_if.add_dot1_layer(p)
251         self.extend_packet(p, packet_size)
252
253         return p
254
255     def create_stream(self, src_if):
256         """Create input packet stream for defined interface.
257
258         :param VppInterface src_if: Interface to create packet stream for.
259         """
260         hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
261         pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
262                     IPv6(src=src_if.remote_ip6) /
263                     inet6.UDP(sport=1234, dport=1234))
264
265         pkts = [self.modify_packet(src_if, i, pkt_tmpl)
266                 for i in moves.range(self.pg_if_packet_sizes[0],
267                                      self.pg_if_packet_sizes[1], 10)]
268         pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
269                   for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
270                                        self.pg_if_packet_sizes[2] + hdr_ext,
271                                        50)]
272         pkts.extend(pkts_b)
273
274         return pkts
275
276     def verify_capture(self, dst_if, capture):
277         """Verify captured input packet stream for defined interface.
278
279         :param VppInterface dst_if: Interface to verify captured packet stream
280                                     for.
281         :param list capture: Captured packet stream.
282         """
283         self.logger.info("Verifying capture on interface %s" % dst_if.name)
284         last_info = dict()
285         for i in self.interfaces:
286             last_info[i.sw_if_index] = None
287         is_sub_if = False
288         dst_sw_if_index = dst_if.sw_if_index
289         if hasattr(dst_if, 'parent'):
290             is_sub_if = True
291         for packet in capture:
292             if is_sub_if:
293                 # Check VLAN tags and Ethernet header
294                 packet = dst_if.remove_dot1_layer(packet)
295             self.assertTrue(Dot1Q not in packet)
296             try:
297                 ip = packet[IPv6]
298                 udp = packet[inet6.UDP]
299                 payload_info = self.payload_to_info(packet[Raw])
300                 packet_index = payload_info.index
301                 self.assertEqual(payload_info.dst, dst_sw_if_index)
302                 self.logger.debug(
303                     "Got packet on port %s: src=%u (id=%u)" %
304                     (dst_if.name, payload_info.src, packet_index))
305                 next_info = self.get_next_packet_info_for_interface2(
306                     payload_info.src, dst_sw_if_index,
307                     last_info[payload_info.src])
308                 last_info[payload_info.src] = next_info
309                 self.assertTrue(next_info is not None)
310                 self.assertEqual(packet_index, next_info.index)
311                 saved_packet = next_info.data
312                 # Check standard fields
313                 self.assertEqual(
314                     ip.src, saved_packet[IPv6].src)
315                 self.assertEqual(
316                     ip.dst, saved_packet[IPv6].dst)
317                 self.assertEqual(
318                     udp.sport, saved_packet[inet6.UDP].sport)
319                 self.assertEqual(
320                     udp.dport, saved_packet[inet6.UDP].dport)
321             except:
322                 self.logger.error(ppp("Unexpected or invalid packet:", packet))
323                 raise
324         for i in self.interfaces:
325             remaining_packet = self.get_next_packet_info_for_interface2(
326                 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
327             self.assertTrue(remaining_packet is None,
328                             "Interface %s: Packet expected from interface %s "
329                             "didn't arrive" % (dst_if.name, i.name))
330
331     def test_next_header_anomaly(self):
332         """ IPv6 next header anomaly test
333
334         Test scenario:
335             - ipv6 next header field = Fragment Header (44)
336             - next header is ICMPv6 Echo Request
337             - wait for reassembly
338         """
339         pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) /
340                IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) /
341                ICMPv6EchoRequest())
342
343         self.pg0.add_stream(pkt)
344         self.pg_start()
345
346         # wait for reassembly
347         self.sleep(10)
348
349     def test_fib(self):
350         """ IPv6 FIB test
351
352         Test scenario:
353             - Create IPv6 stream for pg0 interface
354             - Create IPv6 tagged streams for pg1's and pg2's subinterface.
355             - Send and verify received packets on each interface.
356         """
357
358         pkts = self.create_stream(self.pg0)
359         self.pg0.add_stream(pkts)
360
361         for i in self.sub_interfaces:
362             pkts = self.create_stream(i)
363             i.parent.add_stream(pkts)
364
365         self.pg_enable_capture(self.pg_interfaces)
366         self.pg_start()
367
368         pkts = self.pg0.get_capture()
369         self.verify_capture(self.pg0, pkts)
370
371         for i in self.sub_interfaces:
372             pkts = i.parent.get_capture()
373             self.verify_capture(i, pkts)
374
375     def test_ns(self):
376         """ IPv6 Neighbour Solicitation Exceptions
377
378         Test scenario:
379            - Send an NS Sourced from an address not covered by the link sub-net
380            - Send an NS to an mcast address the router has not joined
381            - Send NS for a target address the router does not onn.
382         """
383
384         #
385         # An NS from a non link source address
386         #
387         nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
388         d = inet_ntop(AF_INET6, nsma)
389
390         p = (Ether(dst=in6_getnsmac(nsma)) /
391              IPv6(dst=d, src="2002::2") /
392              ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
393              ICMPv6NDOptSrcLLAddr(
394                  lladdr=self.pg0.remote_mac))
395         pkts = [p]
396
397         self.send_and_assert_no_replies(
398             self.pg0, pkts,
399             "No response to NS source by address not on sub-net")
400
401         #
402         # An NS for sent to a solicited mcast group the router is
403         # not a member of FAILS
404         #
405         if 0:
406             nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
407             d = inet_ntop(AF_INET6, nsma)
408
409             p = (Ether(dst=in6_getnsmac(nsma)) /
410                  IPv6(dst=d, src=self.pg0.remote_ip6) /
411                  ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
412                  ICMPv6NDOptSrcLLAddr(
413                      lladdr=self.pg0.remote_mac))
414             pkts = [p]
415
416             self.send_and_assert_no_replies(
417                 self.pg0, pkts,
418                 "No response to NS sent to unjoined mcast address")
419
420         #
421         # An NS whose target address is one the router does not own
422         #
423         nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
424         d = inet_ntop(AF_INET6, nsma)
425
426         p = (Ether(dst=in6_getnsmac(nsma)) /
427              IPv6(dst=d, src=self.pg0.remote_ip6) /
428              ICMPv6ND_NS(tgt="fd::ffff") /
429              ICMPv6NDOptSrcLLAddr(
430                  lladdr=self.pg0.remote_mac))
431         pkts = [p]
432
433         self.send_and_assert_no_replies(self.pg0, pkts,
434                                         "No response to NS for unknown target")
435
436         #
437         # A neighbor entry that has no associated FIB-entry
438         #
439         self.pg0.generate_remote_hosts(4)
440         nd_entry = VppNeighbor(self,
441                                self.pg0.sw_if_index,
442                                self.pg0.remote_hosts[2].mac,
443                                self.pg0.remote_hosts[2].ip6,
444                                is_no_fib_entry=1)
445         nd_entry.add_vpp_config()
446
447         #
448         # check we have the neighbor, but no route
449         #
450         self.assertTrue(find_nbr(self,
451                                  self.pg0.sw_if_index,
452                                  self.pg0._remote_hosts[2].ip6))
453         self.assertFalse(find_route(self,
454                                     self.pg0._remote_hosts[2].ip6,
455                                     128))
456
457         #
458         # send an NS from a link local address to the interface's global
459         # address
460         #
461         p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
462              IPv6(
463                  dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
464              ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
465              ICMPv6NDOptSrcLLAddr(
466                  lladdr=self.pg0.remote_mac))
467
468         self.send_and_expect_na(self.pg0, p,
469                                 "NS from link-local",
470                                 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
471                                 tgt_ip=self.pg0.local_ip6)
472
473         #
474         # we should have learned an ND entry for the peer's link-local
475         # but not inserted a route to it in the FIB
476         #
477         self.assertTrue(find_nbr(self,
478                                  self.pg0.sw_if_index,
479                                  self.pg0._remote_hosts[2].ip6_ll))
480         self.assertFalse(find_route(self,
481                                     self.pg0._remote_hosts[2].ip6_ll,
482                                     128))
483
484         #
485         # An NS to the router's own Link-local
486         #
487         p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
488              IPv6(
489                  dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
490              ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
491              ICMPv6NDOptSrcLLAddr(
492                  lladdr=self.pg0.remote_mac))
493
494         self.send_and_expect_na(self.pg0, p,
495                                 "NS to/from link-local",
496                                 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
497                                 tgt_ip=self.pg0.local_ip6_ll)
498
499         #
500         # we should have learned an ND entry for the peer's link-local
501         # but not inserted a route to it in the FIB
502         #
503         self.assertTrue(find_nbr(self,
504                                  self.pg0.sw_if_index,
505                                  self.pg0._remote_hosts[3].ip6_ll))
506         self.assertFalse(find_route(self,
507                                     self.pg0._remote_hosts[3].ip6_ll,
508                                     128))
509
510     def test_ns_duplicates(self):
511         """ ND Duplicates"""
512
513         #
514         # Generate some hosts on the LAN
515         #
516         self.pg1.generate_remote_hosts(3)
517
518         #
519         # Add host 1 on pg1 and pg2
520         #
521         ns_pg1 = VppNeighbor(self,
522                              self.pg1.sw_if_index,
523                              self.pg1.remote_hosts[1].mac,
524                              self.pg1.remote_hosts[1].ip6)
525         ns_pg1.add_vpp_config()
526         ns_pg2 = VppNeighbor(self,
527                              self.pg2.sw_if_index,
528                              self.pg2.remote_mac,
529                              self.pg1.remote_hosts[1].ip6)
530         ns_pg2.add_vpp_config()
531
532         #
533         # IP packet destined for pg1 remote host arrives on pg1 again.
534         #
535         p = (Ether(dst=self.pg0.local_mac,
536                    src=self.pg0.remote_mac) /
537              IPv6(src=self.pg0.remote_ip6,
538                   dst=self.pg1.remote_hosts[1].ip6) /
539              inet6.UDP(sport=1234, dport=1234) /
540              Raw())
541
542         self.pg0.add_stream(p)
543         self.pg_enable_capture(self.pg_interfaces)
544         self.pg_start()
545
546         rx1 = self.pg1.get_capture(1)
547
548         self.verify_ip(rx1[0],
549                        self.pg1.local_mac,
550                        self.pg1.remote_hosts[1].mac,
551                        self.pg0.remote_ip6,
552                        self.pg1.remote_hosts[1].ip6)
553
554         #
555         # remove the duplicate on pg1
556         # packet stream should generate NSs out of pg1
557         #
558         ns_pg1.remove_vpp_config()
559
560         self.send_and_expect_ns(self.pg0, self.pg1,
561                                 p, self.pg1.remote_hosts[1].ip6)
562
563         #
564         # Add it back
565         #
566         ns_pg1.add_vpp_config()
567
568         self.pg0.add_stream(p)
569         self.pg_enable_capture(self.pg_interfaces)
570         self.pg_start()
571
572         rx1 = self.pg1.get_capture(1)
573
574         self.verify_ip(rx1[0],
575                        self.pg1.local_mac,
576                        self.pg1.remote_hosts[1].mac,
577                        self.pg0.remote_ip6,
578                        self.pg1.remote_hosts[1].ip6)
579
580     def validate_ra(self, intf, rx, dst_ip=None, mtu=9000, pi_opt=None):
581         if not dst_ip:
582             dst_ip = intf.remote_ip6
583
584         # unicasted packets must come to the unicast mac
585         self.assertEqual(rx[Ether].dst, intf.remote_mac)
586
587         # and from the router's MAC
588         self.assertEqual(rx[Ether].src, intf.local_mac)
589
590         # the rx'd RA should be addressed to the sender's source
591         self.assertTrue(rx.haslayer(ICMPv6ND_RA))
592         self.assertEqual(in6_ptop(rx[IPv6].dst),
593                          in6_ptop(dst_ip))
594
595         # and come from the router's link local
596         self.assertTrue(in6_islladdr(rx[IPv6].src))
597         self.assertEqual(in6_ptop(rx[IPv6].src),
598                          in6_ptop(mk_ll_addr(intf.local_mac)))
599
600         # it should contain the links MTU
601         ra = rx[ICMPv6ND_RA]
602         self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
603
604         # it should contain the source's link layer address option
605         sll = ra[ICMPv6NDOptSrcLLAddr]
606         self.assertEqual(sll.lladdr, intf.local_mac)
607
608         if not pi_opt:
609             # the RA should not contain prefix information
610             self.assertFalse(ra.haslayer(
611                 ICMPv6NDOptPrefixInfo))
612         else:
613             raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
614
615             # the options are nested in the scapy packet in way that i cannot
616             # decipher how to decode. this 1st layer of option always returns
617             # nested classes, so a direct obj1=obj2 comparison always fails.
618             # however, the getlayer(.., 2) does give one instance.
619             # so we cheat here and construct a new opt instance for comparison
620             rd = ICMPv6NDOptPrefixInfo(
621                 prefixlen=raos.prefixlen,
622                 prefix=raos.prefix,
623                 L=raos.L,
624                 A=raos.A)
625             if type(pi_opt) is list:
626                 for ii in range(len(pi_opt)):
627                     self.assertEqual(pi_opt[ii], rd)
628                     rd = rx.getlayer(
629                         ICMPv6NDOptPrefixInfo, ii + 2)
630             else:
631                 self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s'
632                                  % (pi_opt.show(dump=True),
633                                     raos.show(dump=True)))
634
635     def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
636                            filter_out_fn=is_ipv6_misc,
637                            opt=None):
638         intf.add_stream(pkts)
639         self.pg_enable_capture(self.pg_interfaces)
640         self.pg_start()
641         rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
642
643         self.assertEqual(len(rx), 1)
644         rx = rx[0]
645         self.validate_ra(intf, rx, dst_ip, pi_opt=opt)
646
647     def test_rs(self):
648         """ IPv6 Router Solicitation Exceptions
649
650         Test scenario:
651         """
652
653         #
654         # Before we begin change the IPv6 RA responses to use the unicast
655         # address - that way we will not confuse them with the periodic
656         # RAs which go to the mcast address
657         # Sit and wait for the first periodic RA.
658         #
659         # TODO
660         #
661         self.pg0.ip6_ra_config(send_unicast=1)
662
663         #
664         # An RS from a link source address
665         #  - expect an RA in return
666         #
667         p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
668              IPv6(
669                  dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
670              ICMPv6ND_RS())
671         pkts = [p]
672         self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
673
674         #
675         # For the next RS sent the RA should be rate limited
676         #
677         self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
678
679         #
680         # When we reconfigure the IPv6 RA config,
681         # we reset the RA rate limiting,
682         # so we need to do this before each test below so as not to drop
683         # packets for rate limiting reasons. Test this works here.
684         #
685         self.pg0.ip6_ra_config(send_unicast=1)
686         self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
687
688         #
689         # An RS sent from a non-link local source
690         #
691         self.pg0.ip6_ra_config(send_unicast=1)
692         p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
693              IPv6(dst=self.pg0.local_ip6,
694                   src="2002::ffff") /
695              ICMPv6ND_RS())
696         pkts = [p]
697         self.send_and_assert_no_replies(self.pg0, pkts,
698                                         "RS from non-link source")
699
700         #
701         # Source an RS from a link local address
702         #
703         self.pg0.ip6_ra_config(send_unicast=1)
704         ll = mk_ll_addr(self.pg0.remote_mac)
705         p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
706              IPv6(dst=self.pg0.local_ip6, src=ll) /
707              ICMPv6ND_RS())
708         pkts = [p]
709         self.send_and_expect_ra(self.pg0, pkts,
710                                 "RS sourced from link-local",
711                                 dst_ip=ll)
712
713         #
714         # Send the RS multicast
715         #
716         self.pg0.ip6_ra_config(send_unicast=1)
717         dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
718         ll = mk_ll_addr(self.pg0.remote_mac)
719         p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
720              IPv6(dst="ff02::2", src=ll) /
721              ICMPv6ND_RS())
722         pkts = [p]
723         self.send_and_expect_ra(self.pg0, pkts,
724                                 "RS sourced from link-local",
725                                 dst_ip=ll)
726
727         #
728         # Source from the unspecified address ::. This happens when the RS
729         # is sent before the host has a configured address/sub-net,
730         # i.e. auto-config. Since the sender has no IP address, the reply
731         # comes back mcast - so the capture needs to not filter this.
732         # If we happen to pick up the periodic RA at this point then so be it,
733         # it's not an error.
734         #
735         self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
736         p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
737              IPv6(dst="ff02::2", src="::") /
738              ICMPv6ND_RS())
739         pkts = [p]
740         self.send_and_expect_ra(self.pg0, pkts,
741                                 "RS sourced from unspecified",
742                                 dst_ip="ff02::1",
743                                 filter_out_fn=None)
744
745         #
746         # Configure The RA to announce the links prefix
747         #
748         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
749                                self.pg0.local_ip6_prefix_len))
750
751         #
752         # RAs should now contain the prefix information option
753         #
754         opt = ICMPv6NDOptPrefixInfo(
755             prefixlen=self.pg0.local_ip6_prefix_len,
756             prefix=self.pg0.local_ip6,
757             L=1,
758             A=1)
759
760         self.pg0.ip6_ra_config(send_unicast=1)
761         ll = mk_ll_addr(self.pg0.remote_mac)
762         p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
763              IPv6(dst=self.pg0.local_ip6, src=ll) /
764              ICMPv6ND_RS())
765         self.send_and_expect_ra(self.pg0, p,
766                                 "RA with prefix-info",
767                                 dst_ip=ll,
768                                 opt=opt)
769
770         #
771         # Change the prefix info to not off-link
772         #  L-flag is clear
773         #
774         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
775                                self.pg0.local_ip6_prefix_len),
776                                off_link=1)
777
778         opt = ICMPv6NDOptPrefixInfo(
779             prefixlen=self.pg0.local_ip6_prefix_len,
780             prefix=self.pg0.local_ip6,
781             L=0,
782             A=1)
783
784         self.pg0.ip6_ra_config(send_unicast=1)
785         self.send_and_expect_ra(self.pg0, p,
786                                 "RA with Prefix info with L-flag=0",
787                                 dst_ip=ll,
788                                 opt=opt)
789
790         #
791         # Change the prefix info to not off-link, no-autoconfig
792         #  L and A flag are clear in the advert
793         #
794         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
795                                self.pg0.local_ip6_prefix_len),
796                                off_link=1,
797                                no_autoconfig=1)
798
799         opt = ICMPv6NDOptPrefixInfo(
800             prefixlen=self.pg0.local_ip6_prefix_len,
801             prefix=self.pg0.local_ip6,
802             L=0,
803             A=0)
804
805         self.pg0.ip6_ra_config(send_unicast=1)
806         self.send_and_expect_ra(self.pg0, p,
807                                 "RA with Prefix info with A & L-flag=0",
808                                 dst_ip=ll,
809                                 opt=opt)
810
811         #
812         # Change the flag settings back to the defaults
813         #  L and A flag are set in the advert
814         #
815         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
816                                self.pg0.local_ip6_prefix_len))
817
818         opt = ICMPv6NDOptPrefixInfo(
819             prefixlen=self.pg0.local_ip6_prefix_len,
820             prefix=self.pg0.local_ip6,
821             L=1,
822             A=1)
823
824         self.pg0.ip6_ra_config(send_unicast=1)
825         self.send_and_expect_ra(self.pg0, p,
826                                 "RA with Prefix info",
827                                 dst_ip=ll,
828                                 opt=opt)
829
830         #
831         # Change the prefix info to not off-link, no-autoconfig
832         #  L and A flag are clear in the advert
833         #
834         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
835                                self.pg0.local_ip6_prefix_len),
836                                off_link=1,
837                                no_autoconfig=1)
838
839         opt = ICMPv6NDOptPrefixInfo(
840             prefixlen=self.pg0.local_ip6_prefix_len,
841             prefix=self.pg0.local_ip6,
842             L=0,
843             A=0)
844
845         self.pg0.ip6_ra_config(send_unicast=1)
846         self.send_and_expect_ra(self.pg0, p,
847                                 "RA with Prefix info with A & L-flag=0",
848                                 dst_ip=ll,
849                                 opt=opt)
850
851         #
852         # Use the reset to defaults option to revert to defaults
853         #  L and A flag are clear in the advert
854         #
855         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
856                                self.pg0.local_ip6_prefix_len),
857                                use_default=1)
858
859         opt = ICMPv6NDOptPrefixInfo(
860             prefixlen=self.pg0.local_ip6_prefix_len,
861             prefix=self.pg0.local_ip6,
862             L=1,
863             A=1)
864
865         self.pg0.ip6_ra_config(send_unicast=1)
866         self.send_and_expect_ra(self.pg0, p,
867                                 "RA with Prefix reverted to defaults",
868                                 dst_ip=ll,
869                                 opt=opt)
870
871         #
872         # Advertise Another prefix. With no L-flag/A-flag
873         #
874         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
875                                self.pg1.local_ip6_prefix_len),
876                                off_link=1,
877                                no_autoconfig=1)
878
879         opt = [ICMPv6NDOptPrefixInfo(
880             prefixlen=self.pg0.local_ip6_prefix_len,
881             prefix=self.pg0.local_ip6,
882             L=1,
883             A=1),
884             ICMPv6NDOptPrefixInfo(
885                 prefixlen=self.pg1.local_ip6_prefix_len,
886                 prefix=self.pg1.local_ip6,
887                 L=0,
888                 A=0)]
889
890         self.pg0.ip6_ra_config(send_unicast=1)
891         ll = mk_ll_addr(self.pg0.remote_mac)
892         p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
893              IPv6(dst=self.pg0.local_ip6, src=ll) /
894              ICMPv6ND_RS())
895         self.send_and_expect_ra(self.pg0, p,
896                                 "RA with multiple Prefix infos",
897                                 dst_ip=ll,
898                                 opt=opt)
899
900         #
901         # Remove the first prefix-info - expect the second is still in the
902         # advert
903         #
904         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
905                                self.pg0.local_ip6_prefix_len),
906                                is_no=1)
907
908         opt = ICMPv6NDOptPrefixInfo(
909             prefixlen=self.pg1.local_ip6_prefix_len,
910             prefix=self.pg1.local_ip6,
911             L=0,
912             A=0)
913
914         self.pg0.ip6_ra_config(send_unicast=1)
915         self.send_and_expect_ra(self.pg0, p,
916                                 "RA with Prefix reverted to defaults",
917                                 dst_ip=ll,
918                                 opt=opt)
919
920         #
921         # Remove the second prefix-info - expect no prefix-info in the adverts
922         #
923         self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
924                                self.pg1.local_ip6_prefix_len),
925                                is_no=1)
926
927         self.pg0.ip6_ra_config(send_unicast=1)
928         self.send_and_expect_ra(self.pg0, p,
929                                 "RA with Prefix reverted to defaults",
930                                 dst_ip=ll)
931
932         #
933         # Reset the periodic advertisements back to default values
934         #
935         self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
936
937
938 class TestIPv6IfAddrRoute(VppTestCase):
939     """ IPv6 Interface Addr Route Test Case """
940
941     @classmethod
942     def setUpClass(cls):
943         super(TestIPv6IfAddrRoute, cls).setUpClass()
944
945     @classmethod
946     def tearDownClass(cls):
947         super(TestIPv6IfAddrRoute, cls).tearDownClass()
948
949     def setUp(self):
950         super(TestIPv6IfAddrRoute, self).setUp()
951
952         # create 1 pg interface
953         self.create_pg_interfaces(range(1))
954
955         for i in self.pg_interfaces:
956             i.admin_up()
957             i.config_ip6()
958             i.resolve_ndp()
959
960     def tearDown(self):
961         super(TestIPv6IfAddrRoute, self).tearDown()
962         for i in self.pg_interfaces:
963             i.unconfig_ip6()
964             i.admin_down()
965
966     def test_ipv6_ifaddrs_same_prefix(self):
967         """ IPv6 Interface Addresses Same Prefix test
968
969         Test scenario:
970
971             - Verify no route in FIB for prefix 2001:10::/64
972             - Configure IPv4 address 2001:10::10/64  on an interface
973             - Verify route in FIB for prefix 2001:10::/64
974             - Configure IPv4 address 2001:10::20/64 on an interface
975             - Delete 2001:10::10/64 from interface
976             - Verify route in FIB for prefix 2001:10::/64
977             - Delete 2001:10::20/64 from interface
978             - Verify no route in FIB for prefix 2001:10::/64
979         """
980
981         addr1 = "2001:10::10"
982         addr2 = "2001:10::20"
983
984         if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64)
985         if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64)
986         self.assertFalse(if_addr1.query_vpp_config())
987         self.assertFalse(find_route(self, addr1, 128))
988         self.assertFalse(find_route(self, addr2, 128))
989
990         # configure first address, verify route present
991         if_addr1.add_vpp_config()
992         self.assertTrue(if_addr1.query_vpp_config())
993         self.assertTrue(find_route(self, addr1, 128))
994         self.assertFalse(find_route(self, addr2, 128))
995
996         # configure second address, delete first, verify route not removed
997         if_addr2.add_vpp_config()
998         if_addr1.remove_vpp_config()
999         self.assertFalse(if_addr1.query_vpp_config())
1000         self.assertTrue(if_addr2.query_vpp_config())
1001         self.assertFalse(find_route(self, addr1, 128))
1002         self.assertTrue(find_route(self, addr2, 128))
1003
1004         # delete second address, verify route removed
1005         if_addr2.remove_vpp_config()
1006         self.assertFalse(if_addr1.query_vpp_config())
1007         self.assertFalse(find_route(self, addr1, 128))
1008         self.assertFalse(find_route(self, addr2, 128))
1009
1010
1011 class TestICMPv6Echo(VppTestCase):
1012     """ ICMPv6 Echo Test Case """
1013
1014     @classmethod
1015     def setUpClass(cls):
1016         super(TestICMPv6Echo, cls).setUpClass()
1017
1018     @classmethod
1019     def tearDownClass(cls):
1020         super(TestICMPv6Echo, cls).tearDownClass()
1021
1022     def setUp(self):
1023         super(TestICMPv6Echo, self).setUp()
1024
1025         # create 1 pg interface
1026         self.create_pg_interfaces(range(1))
1027
1028         for i in self.pg_interfaces:
1029             i.admin_up()
1030             i.config_ip6()
1031             i.resolve_ndp()
1032
1033     def tearDown(self):
1034         super(TestICMPv6Echo, self).tearDown()
1035         for i in self.pg_interfaces:
1036             i.unconfig_ip6()
1037             i.ip6_disable()
1038             i.admin_down()
1039
1040     def test_icmpv6_echo(self):
1041         """ VPP replies to ICMPv6 Echo Request
1042
1043         Test scenario:
1044
1045             - Receive ICMPv6 Echo Request message on pg0 interface.
1046             - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
1047         """
1048
1049         icmpv6_id = 0xb
1050         icmpv6_seq = 5
1051         icmpv6_data = b'\x0a' * 18
1052         p_echo_request = (Ether(src=self.pg0.remote_mac,
1053                                 dst=self.pg0.local_mac) /
1054                           IPv6(src=self.pg0.remote_ip6,
1055                                dst=self.pg0.local_ip6) /
1056                           ICMPv6EchoRequest(
1057                               id=icmpv6_id,
1058                               seq=icmpv6_seq,
1059                               data=icmpv6_data))
1060
1061         self.pg0.add_stream(p_echo_request)
1062         self.pg_enable_capture(self.pg_interfaces)
1063         self.pg_start()
1064
1065         rx = self.pg0.get_capture(1)
1066         rx = rx[0]
1067         ether = rx[Ether]
1068         ipv6 = rx[IPv6]
1069         icmpv6 = rx[ICMPv6EchoReply]
1070
1071         self.assertEqual(ether.src, self.pg0.local_mac)
1072         self.assertEqual(ether.dst, self.pg0.remote_mac)
1073
1074         self.assertEqual(ipv6.src, self.pg0.local_ip6)
1075         self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1076
1077         self.assertEqual(
1078             icmp6types[icmpv6.type], "Echo Reply")
1079         self.assertEqual(icmpv6.id, icmpv6_id)
1080         self.assertEqual(icmpv6.seq, icmpv6_seq)
1081         self.assertEqual(icmpv6.data, icmpv6_data)
1082
1083
1084 class TestIPv6RD(TestIPv6ND):
1085     """ IPv6 Router Discovery Test Case """
1086
1087     @classmethod
1088     def setUpClass(cls):
1089         super(TestIPv6RD, cls).setUpClass()
1090
1091     @classmethod
1092     def tearDownClass(cls):
1093         super(TestIPv6RD, cls).tearDownClass()
1094
1095     def setUp(self):
1096         super(TestIPv6RD, self).setUp()
1097
1098         # create 2 pg interfaces
1099         self.create_pg_interfaces(range(2))
1100
1101         self.interfaces = list(self.pg_interfaces)
1102
1103         # setup all interfaces
1104         for i in self.interfaces:
1105             i.admin_up()
1106             i.config_ip6()
1107
1108     def tearDown(self):
1109         for i in self.interfaces:
1110             i.unconfig_ip6()
1111             i.admin_down()
1112         super(TestIPv6RD, self).tearDown()
1113
1114     def test_rd_send_router_solicitation(self):
1115         """ Verify router solicitation packets """
1116
1117         count = 2
1118         self.pg_enable_capture(self.pg_interfaces)
1119         self.pg_start()
1120         self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1121                                                  mrc=count)
1122         rx_list = self.pg1.get_capture(count, timeout=3)
1123         self.assertEqual(len(rx_list), count)
1124         for packet in rx_list:
1125             self.assertEqual(packet.haslayer(IPv6), 1)
1126             self.assertEqual(packet[IPv6].haslayer(
1127                 ICMPv6ND_RS), 1)
1128             dst = ip6_normalize(packet[IPv6].dst)
1129             dst2 = ip6_normalize("ff02::2")
1130             self.assert_equal(dst, dst2)
1131             src = ip6_normalize(packet[IPv6].src)
1132             src2 = ip6_normalize(self.pg1.local_ip6_ll)
1133             self.assert_equal(src, src2)
1134             self.assertTrue(
1135                 bool(packet[ICMPv6ND_RS].haslayer(
1136                     ICMPv6NDOptSrcLLAddr)))
1137             self.assert_equal(
1138                 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1139                 self.pg1.local_mac)
1140
1141     def verify_prefix_info(self, reported_prefix, prefix_option):
1142         prefix = IPv6Network(
1143             text_type(prefix_option.getfieldval("prefix") +
1144                       "/" +
1145                       text_type(prefix_option.getfieldval("prefixlen"))),
1146             strict=False)
1147         self.assert_equal(reported_prefix.prefix.network_address,
1148                           prefix.network_address)
1149         L = prefix_option.getfieldval("L")
1150         A = prefix_option.getfieldval("A")
1151         option_flags = (L << 7) | (A << 6)
1152         self.assert_equal(reported_prefix.flags, option_flags)
1153         self.assert_equal(reported_prefix.valid_time,
1154                           prefix_option.getfieldval("validlifetime"))
1155         self.assert_equal(reported_prefix.preferred_time,
1156                           prefix_option.getfieldval("preferredlifetime"))
1157
1158     def test_rd_receive_router_advertisement(self):
1159         """ Verify events triggered by received RA packets """
1160
1161         self.vapi.want_ip6_ra_events()
1162
1163         prefix_info_1 = ICMPv6NDOptPrefixInfo(
1164             prefix="1::2",
1165             prefixlen=50,
1166             validlifetime=200,
1167             preferredlifetime=500,
1168             L=1,
1169             A=1,
1170         )
1171
1172         prefix_info_2 = ICMPv6NDOptPrefixInfo(
1173             prefix="7::4",
1174             prefixlen=20,
1175             validlifetime=70,
1176             preferredlifetime=1000,
1177             L=1,
1178             A=0,
1179         )
1180
1181         p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1182              IPv6(dst=self.pg1.local_ip6_ll,
1183                   src=mk_ll_addr(self.pg1.remote_mac)) /
1184              ICMPv6ND_RA() /
1185              prefix_info_1 /
1186              prefix_info_2)
1187         self.pg1.add_stream([p])
1188         self.pg_start()
1189
1190         ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1191
1192         self.assert_equal(ev.current_hop_limit, 0)
1193         self.assert_equal(ev.flags, 8)
1194         self.assert_equal(ev.router_lifetime_in_sec, 1800)
1195         self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1196         self.assert_equal(
1197             ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1198
1199         self.assert_equal(ev.n_prefixes, 2)
1200
1201         self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1202         self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1203
1204
1205 class TestIPv6RDControlPlane(TestIPv6ND):
1206     """ IPv6 Router Discovery Control Plane Test Case """
1207
1208     @classmethod
1209     def setUpClass(cls):
1210         super(TestIPv6RDControlPlane, cls).setUpClass()
1211
1212     @classmethod
1213     def tearDownClass(cls):
1214         super(TestIPv6RDControlPlane, cls).tearDownClass()
1215
1216     def setUp(self):
1217         super(TestIPv6RDControlPlane, self).setUp()
1218
1219         # create 1 pg interface
1220         self.create_pg_interfaces(range(1))
1221
1222         self.interfaces = list(self.pg_interfaces)
1223
1224         # setup all interfaces
1225         for i in self.interfaces:
1226             i.admin_up()
1227             i.config_ip6()
1228
1229     def tearDown(self):
1230         super(TestIPv6RDControlPlane, self).tearDown()
1231
1232     @staticmethod
1233     def create_ra_packet(pg, routerlifetime=None):
1234         src_ip = pg.remote_ip6_ll
1235         dst_ip = pg.local_ip6
1236         if routerlifetime is not None:
1237             ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1238         else:
1239             ra = ICMPv6ND_RA()
1240         p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1241              IPv6(dst=dst_ip, src=src_ip) / ra)
1242         return p
1243
1244     @staticmethod
1245     def get_default_routes(fib):
1246         list = []
1247         for entry in fib:
1248             if entry.route.prefix.prefixlen == 0:
1249                 for path in entry.route.paths:
1250                     if path.sw_if_index != 0xFFFFFFFF:
1251                         defaut_route = {}
1252                         defaut_route['sw_if_index'] = path.sw_if_index
1253                         defaut_route['next_hop'] = path.nh.address.ip6
1254                         list.append(defaut_route)
1255         return list
1256
1257     @staticmethod
1258     def get_interface_addresses(fib, pg):
1259         list = []
1260         for entry in fib:
1261             if entry.route.prefix.prefixlen == 128:
1262                 path = entry.route.paths[0]
1263                 if path.sw_if_index == pg.sw_if_index:
1264                     list.append(str(entry.route.prefix.network_address))
1265         return list
1266
1267     def test_all(self):
1268         """ Test handling of SLAAC addresses and default routes """
1269
1270         fib = self.vapi.ip_route_dump(0, True)
1271         default_routes = self.get_default_routes(fib)
1272         initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1273         self.assertEqual(default_routes, [])
1274         router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll))
1275
1276         self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1277
1278         self.sleep(0.1)
1279
1280         # send RA
1281         packet = (self.create_ra_packet(
1282             self.pg0) / ICMPv6NDOptPrefixInfo(
1283             prefix="1::",
1284             prefixlen=64,
1285             validlifetime=2,
1286             preferredlifetime=2,
1287             L=1,
1288             A=1,
1289         ) / ICMPv6NDOptPrefixInfo(
1290             prefix="7::",
1291             prefixlen=20,
1292             validlifetime=1500,
1293             preferredlifetime=1000,
1294             L=1,
1295             A=0,
1296         ))
1297         self.pg0.add_stream([packet])
1298         self.pg_start()
1299
1300         self.sleep_on_vpp_time(0.1)
1301
1302         fib = self.vapi.ip_route_dump(0, True)
1303
1304         # check FIB for new address
1305         addresses = set(self.get_interface_addresses(fib, self.pg0))
1306         new_addresses = addresses.difference(initial_addresses)
1307         self.assertEqual(len(new_addresses), 1)
1308         prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1309                              strict=False)
1310         self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
1311
1312         # check FIB for new default route
1313         default_routes = self.get_default_routes(fib)
1314         self.assertEqual(len(default_routes), 1)
1315         dr = default_routes[0]
1316         self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1317         self.assertEqual(dr['next_hop'], router_address)
1318
1319         # send RA to delete default route
1320         packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1321         self.pg0.add_stream([packet])
1322         self.pg_start()
1323
1324         self.sleep_on_vpp_time(0.1)
1325
1326         # check that default route is deleted
1327         fib = self.vapi.ip_route_dump(0, True)
1328         default_routes = self.get_default_routes(fib)
1329         self.assertEqual(len(default_routes), 0)
1330
1331         self.sleep_on_vpp_time(0.1)
1332
1333         # send RA
1334         packet = self.create_ra_packet(self.pg0)
1335         self.pg0.add_stream([packet])
1336         self.pg_start()
1337
1338         self.sleep_on_vpp_time(0.1)
1339
1340         # check FIB for new default route
1341         fib = self.vapi.ip_route_dump(0, True)
1342         default_routes = self.get_default_routes(fib)
1343         self.assertEqual(len(default_routes), 1)
1344         dr = default_routes[0]
1345         self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1346         self.assertEqual(dr['next_hop'], router_address)
1347
1348         # send RA, updating router lifetime to 1s
1349         packet = self.create_ra_packet(self.pg0, 1)
1350         self.pg0.add_stream([packet])
1351         self.pg_start()
1352
1353         self.sleep_on_vpp_time(0.1)
1354
1355         # check that default route still exists
1356         fib = self.vapi.ip_route_dump(0, True)
1357         default_routes = self.get_default_routes(fib)
1358         self.assertEqual(len(default_routes), 1)
1359         dr = default_routes[0]
1360         self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1361         self.assertEqual(dr['next_hop'], router_address)
1362
1363         self.sleep_on_vpp_time(1)
1364
1365         # check that default route is deleted
1366         fib = self.vapi.ip_route_dump(0, True)
1367         default_routes = self.get_default_routes(fib)
1368         self.assertEqual(len(default_routes), 0)
1369
1370         # check FIB still contains the SLAAC address
1371         addresses = set(self.get_interface_addresses(fib, self.pg0))
1372         new_addresses = addresses.difference(initial_addresses)
1373
1374         self.assertEqual(len(new_addresses), 1)
1375         prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1376                              strict=False)
1377         self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
1378
1379         self.sleep_on_vpp_time(1)
1380
1381         # check that SLAAC address is deleted
1382         fib = self.vapi.ip_route_dump(0, True)
1383         addresses = set(self.get_interface_addresses(fib, self.pg0))
1384         new_addresses = addresses.difference(initial_addresses)
1385         self.assertEqual(len(new_addresses), 0)
1386
1387
1388 class IPv6NDProxyTest(TestIPv6ND):
1389     """ IPv6 ND ProxyTest Case """
1390
1391     @classmethod
1392     def setUpClass(cls):
1393         super(IPv6NDProxyTest, cls).setUpClass()
1394
1395     @classmethod
1396     def tearDownClass(cls):
1397         super(IPv6NDProxyTest, cls).tearDownClass()
1398
1399     def setUp(self):
1400         super(IPv6NDProxyTest, self).setUp()
1401
1402         # create 3 pg interfaces
1403         self.create_pg_interfaces(range(3))
1404
1405         # pg0 is the master interface, with the configured subnet
1406         self.pg0.admin_up()
1407         self.pg0.config_ip6()
1408         self.pg0.resolve_ndp()
1409
1410         self.pg1.ip6_enable()
1411         self.pg2.ip6_enable()
1412
1413     def tearDown(self):
1414         super(IPv6NDProxyTest, self).tearDown()
1415
1416     def test_nd_proxy(self):
1417         """ IPv6 Proxy ND """
1418
1419         #
1420         # Generate some hosts in the subnet that we are proxying
1421         #
1422         self.pg0.generate_remote_hosts(8)
1423
1424         nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1425         d = inet_ntop(AF_INET6, nsma)
1426
1427         #
1428         # Send an NS for one of those remote hosts on one of the proxy links
1429         # expect no response since it's from an address that is not
1430         # on the link that has the prefix configured
1431         #
1432         ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
1433                   IPv6(dst=d,
1434                        src=self.pg0._remote_hosts[2].ip6) /
1435                   ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
1436                   ICMPv6NDOptSrcLLAddr(
1437                       lladdr=self.pg0._remote_hosts[2].mac))
1438
1439         self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1440
1441         #
1442         # Add proxy support for the host
1443         #
1444         self.vapi.ip6nd_proxy_add_del(
1445             ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1446             sw_if_index=self.pg1.sw_if_index)
1447
1448         #
1449         # try that NS again. this time we expect an NA back
1450         #
1451         self.send_and_expect_na(self.pg1, ns_pg1,
1452                                 "NS to proxy entry",
1453                                 dst_ip=self.pg0._remote_hosts[2].ip6,
1454                                 tgt_ip=self.pg0.local_ip6)
1455
1456         #
1457         # ... and that we have an entry in the ND cache
1458         #
1459         self.assertTrue(find_nbr(self,
1460                                  self.pg1.sw_if_index,
1461                                  self.pg0._remote_hosts[2].ip6))
1462
1463         #
1464         # ... and we can route traffic to it
1465         #
1466         t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1467              IPv6(dst=self.pg0._remote_hosts[2].ip6,
1468                   src=self.pg0.remote_ip6) /
1469              inet6.UDP(sport=10000, dport=20000) /
1470              Raw(b'\xa5' * 100))
1471
1472         self.pg0.add_stream(t)
1473         self.pg_enable_capture(self.pg_interfaces)
1474         self.pg_start()
1475         rx = self.pg1.get_capture(1)
1476         rx = rx[0]
1477
1478         self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1479         self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1480
1481         self.assertEqual(rx[IPv6].src,
1482                          t[IPv6].src)
1483         self.assertEqual(rx[IPv6].dst,
1484                          t[IPv6].dst)
1485
1486         #
1487         # Test we proxy for the host on the main interface
1488         #
1489         ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1490                   IPv6(dst=d, src=self.pg0.remote_ip6) /
1491                   ICMPv6ND_NS(
1492                       tgt=self.pg0._remote_hosts[2].ip6) /
1493                   ICMPv6NDOptSrcLLAddr(
1494                       lladdr=self.pg0.remote_mac))
1495
1496         self.send_and_expect_na(self.pg0, ns_pg0,
1497                                 "NS to proxy entry on main",
1498                                 tgt_ip=self.pg0._remote_hosts[2].ip6,
1499                                 dst_ip=self.pg0.remote_ip6)
1500
1501         #
1502         # Setup and resolve proxy for another host on another interface
1503         #
1504         ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
1505                   IPv6(dst=d,
1506                        src=self.pg0._remote_hosts[3].ip6) /
1507                   ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
1508                   ICMPv6NDOptSrcLLAddr(
1509                       lladdr=self.pg0._remote_hosts[2].mac))
1510
1511         self.vapi.ip6nd_proxy_add_del(
1512             ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1513             sw_if_index=self.pg2.sw_if_index)
1514
1515         self.send_and_expect_na(self.pg2, ns_pg2,
1516                                 "NS to proxy entry other interface",
1517                                 dst_ip=self.pg0._remote_hosts[3].ip6,
1518                                 tgt_ip=self.pg0.local_ip6)
1519
1520         self.assertTrue(find_nbr(self,
1521                                  self.pg2.sw_if_index,
1522                                  self.pg0._remote_hosts[3].ip6))
1523
1524         #
1525         # hosts can communicate. pg2->pg1
1526         #
1527         t2 = (Ether(dst=self.pg2.local_mac,
1528                     src=self.pg0.remote_hosts[3].mac) /
1529               IPv6(dst=self.pg0._remote_hosts[2].ip6,
1530                    src=self.pg0._remote_hosts[3].ip6) /
1531               inet6.UDP(sport=10000, dport=20000) /
1532               Raw(b'\xa5' * 100))
1533
1534         self.pg2.add_stream(t2)
1535         self.pg_enable_capture(self.pg_interfaces)
1536         self.pg_start()
1537         rx = self.pg1.get_capture(1)
1538         rx = rx[0]
1539
1540         self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1541         self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1542
1543         self.assertEqual(rx[IPv6].src,
1544                          t2[IPv6].src)
1545         self.assertEqual(rx[IPv6].dst,
1546                          t2[IPv6].dst)
1547
1548         #
1549         # remove the proxy configs
1550         #
1551         self.vapi.ip6nd_proxy_add_del(
1552             ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1553             sw_if_index=self.pg1.sw_if_index, is_del=1)
1554         self.vapi.ip6nd_proxy_add_del(
1555             ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1556             sw_if_index=self.pg2.sw_if_index, is_del=1)
1557
1558         self.assertFalse(find_nbr(self,
1559                                   self.pg2.sw_if_index,
1560                                   self.pg0._remote_hosts[3].ip6))
1561         self.assertFalse(find_nbr(self,
1562                                   self.pg1.sw_if_index,
1563                                   self.pg0._remote_hosts[2].ip6))
1564
1565         #
1566         # no longer proxy-ing...
1567         #
1568         self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1569         self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1570         self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1571
1572         #
1573         # no longer forwarding. traffic generates NS out of the glean/main
1574         # interface
1575         #
1576         self.pg2.add_stream(t2)
1577         self.pg_enable_capture(self.pg_interfaces)
1578         self.pg_start()
1579
1580         rx = self.pg0.get_capture(1)
1581
1582         self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1583
1584
1585 class TestIPNull(VppTestCase):
1586     """ IPv6 routes via NULL """
1587
1588     @classmethod
1589     def setUpClass(cls):
1590         super(TestIPNull, cls).setUpClass()
1591
1592     @classmethod
1593     def tearDownClass(cls):
1594         super(TestIPNull, cls).tearDownClass()
1595
1596     def setUp(self):
1597         super(TestIPNull, self).setUp()
1598
1599         # create 2 pg interfaces
1600         self.create_pg_interfaces(range(1))
1601
1602         for i in self.pg_interfaces:
1603             i.admin_up()
1604             i.config_ip6()
1605             i.resolve_ndp()
1606
1607     def tearDown(self):
1608         super(TestIPNull, self).tearDown()
1609         for i in self.pg_interfaces:
1610             i.unconfig_ip6()
1611             i.admin_down()
1612
1613     def test_ip_null(self):
1614         """ IP NULL route """
1615
1616         p = (Ether(src=self.pg0.remote_mac,
1617                    dst=self.pg0.local_mac) /
1618              IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
1619              inet6.UDP(sport=1234, dport=1234) /
1620              Raw(b'\xa5' * 100))
1621
1622         #
1623         # A route via IP NULL that will reply with ICMP unreachables
1624         #
1625         ip_unreach = VppIpRoute(
1626             self, "2001::", 64,
1627             [VppRoutePath("::", 0xffffffff,
1628                           type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)])
1629         ip_unreach.add_vpp_config()
1630
1631         self.pg0.add_stream(p)
1632         self.pg_enable_capture(self.pg_interfaces)
1633         self.pg_start()
1634
1635         rx = self.pg0.get_capture(1)
1636         rx = rx[0]
1637         icmp = rx[ICMPv6DestUnreach]
1638
1639         # 0 = "No route to destination"
1640         self.assertEqual(icmp.code, 0)
1641
1642         # ICMP is rate limited. pause a bit
1643         self.sleep(1)
1644
1645         #
1646         # A route via IP NULL that will reply with ICMP prohibited
1647         #
1648         ip_prohibit = VppIpRoute(
1649             self, "2001::1", 128,
1650             [VppRoutePath("::", 0xffffffff,
1651                           type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)])
1652         ip_prohibit.add_vpp_config()
1653
1654         self.pg0.add_stream(p)
1655         self.pg_enable_capture(self.pg_interfaces)
1656         self.pg_start()
1657
1658         rx = self.pg0.get_capture(1)
1659         rx = rx[0]
1660         icmp = rx[ICMPv6DestUnreach]
1661
1662         # 1 = "Communication with destination administratively prohibited"
1663         self.assertEqual(icmp.code, 1)
1664
1665
1666 class TestIPDisabled(VppTestCase):
1667     """ IPv6 disabled """
1668
1669     @classmethod
1670     def setUpClass(cls):
1671         super(TestIPDisabled, cls).setUpClass()
1672
1673     @classmethod
1674     def tearDownClass(cls):
1675         super(TestIPDisabled, cls).tearDownClass()
1676
1677     def setUp(self):
1678         super(TestIPDisabled, self).setUp()
1679
1680         # create 2 pg interfaces
1681         self.create_pg_interfaces(range(2))
1682
1683         # PG0 is IP enabled
1684         self.pg0.admin_up()
1685         self.pg0.config_ip6()
1686         self.pg0.resolve_ndp()
1687
1688         # PG 1 is not IP enabled
1689         self.pg1.admin_up()
1690
1691     def tearDown(self):
1692         super(TestIPDisabled, self).tearDown()
1693         for i in self.pg_interfaces:
1694             i.unconfig_ip4()
1695             i.admin_down()
1696
1697     def test_ip_disabled(self):
1698         """ IP Disabled """
1699
1700         #
1701         # An (S,G).
1702         # one accepting interface, pg0, 2 forwarding interfaces
1703         #
1704         route_ff_01 = VppIpMRoute(
1705             self,
1706             "::",
1707             "ffef::1", 128,
1708             MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1709             [VppMRoutePath(self.pg1.sw_if_index,
1710                            MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1711              VppMRoutePath(self.pg0.sw_if_index,
1712                            MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
1713         route_ff_01.add_vpp_config()
1714
1715         pu = (Ether(src=self.pg1.remote_mac,
1716                     dst=self.pg1.local_mac) /
1717               IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
1718               inet6.UDP(sport=1234, dport=1234) /
1719               Raw(b'\xa5' * 100))
1720         pm = (Ether(src=self.pg1.remote_mac,
1721                     dst=self.pg1.local_mac) /
1722               IPv6(src="2001::1", dst="ffef::1") /
1723               inet6.UDP(sport=1234, dport=1234) /
1724               Raw(b'\xa5' * 100))
1725
1726         #
1727         # PG1 does not forward IP traffic
1728         #
1729         self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1730         self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1731
1732         #
1733         # IP enable PG1
1734         #
1735         self.pg1.config_ip6()
1736
1737         #
1738         # Now we get packets through
1739         #
1740         self.pg1.add_stream(pu)
1741         self.pg_enable_capture(self.pg_interfaces)
1742         self.pg_start()
1743         rx = self.pg0.get_capture(1)
1744
1745         self.pg1.add_stream(pm)
1746         self.pg_enable_capture(self.pg_interfaces)
1747         self.pg_start()
1748         rx = self.pg0.get_capture(1)
1749
1750         #
1751         # Disable PG1
1752         #
1753         self.pg1.unconfig_ip6()
1754
1755         #
1756         # PG1 does not forward IP traffic
1757         #
1758         self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1759         self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1760
1761
1762 class TestIP6LoadBalance(VppTestCase):
1763     """ IPv6 Load-Balancing """
1764
1765     @classmethod
1766     def setUpClass(cls):
1767         super(TestIP6LoadBalance, cls).setUpClass()
1768
1769     @classmethod
1770     def tearDownClass(cls):
1771         super(TestIP6LoadBalance, cls).tearDownClass()
1772
1773     def setUp(self):
1774         super(TestIP6LoadBalance, self).setUp()
1775
1776         self.create_pg_interfaces(range(5))
1777
1778         mpls_tbl = VppMplsTable(self, 0)
1779         mpls_tbl.add_vpp_config()
1780
1781         for i in self.pg_interfaces:
1782             i.admin_up()
1783             i.config_ip6()
1784             i.resolve_ndp()
1785             i.enable_mpls()
1786
1787     def tearDown(self):
1788         for i in self.pg_interfaces:
1789             i.unconfig_ip6()
1790             i.admin_down()
1791             i.disable_mpls()
1792         super(TestIP6LoadBalance, self).tearDown()
1793
1794     def pg_send(self, input, pkts):
1795         self.vapi.cli("clear trace")
1796         input.add_stream(pkts)
1797         self.pg_enable_capture(self.pg_interfaces)
1798         self.pg_start()
1799
1800     def send_and_expect_load_balancing(self, input, pkts, outputs):
1801         self.pg_send(input, pkts)
1802         for oo in outputs:
1803             rx = oo._get_capture(1)
1804             self.assertNotEqual(0, len(rx))
1805
1806     def send_and_expect_one_itf(self, input, pkts, itf):
1807         self.pg_send(input, pkts)
1808         rx = itf.get_capture(len(pkts))
1809
1810     def test_ip6_load_balance(self):
1811         """ IPv6 Load-Balancing """
1812
1813         #
1814         # An array of packets that differ only in the destination port
1815         #  - IP only
1816         #  - MPLS EOS
1817         #  - MPLS non-EOS
1818         #  - MPLS non-EOS with an entropy label
1819         #
1820         port_ip_pkts = []
1821         port_mpls_pkts = []
1822         port_mpls_neos_pkts = []
1823         port_ent_pkts = []
1824
1825         #
1826         # An array of packets that differ only in the source address
1827         #
1828         src_ip_pkts = []
1829         src_mpls_pkts = []
1830
1831         for ii in range(NUM_PKTS):
1832             port_ip_hdr = (
1833                 IPv6(dst="3000::1", src="3000:1::1") /
1834                 inet6.UDP(sport=1234, dport=1234 + ii) /
1835                 Raw(b'\xa5' * 100))
1836             port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1837                                        dst=self.pg0.local_mac) /
1838                                  port_ip_hdr))
1839             port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1840                                          dst=self.pg0.local_mac) /
1841                                    MPLS(label=66, ttl=2) /
1842                                    port_ip_hdr))
1843             port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1844                                               dst=self.pg0.local_mac) /
1845                                         MPLS(label=67, ttl=2) /
1846                                         MPLS(label=77, ttl=2) /
1847                                         port_ip_hdr))
1848             port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1849                                         dst=self.pg0.local_mac) /
1850                                   MPLS(label=67, ttl=2) /
1851                                   MPLS(label=14, ttl=2) /
1852                                   MPLS(label=999, ttl=2) /
1853                                   port_ip_hdr))
1854             src_ip_hdr = (
1855                 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
1856                 inet6.UDP(sport=1234, dport=1234) /
1857                 Raw(b'\xa5' * 100))
1858             src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1859                                       dst=self.pg0.local_mac) /
1860                                 src_ip_hdr))
1861             src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1862                                         dst=self.pg0.local_mac) /
1863                                   MPLS(label=66, ttl=2) /
1864                                   src_ip_hdr))
1865
1866         #
1867         # A route for the IP packets
1868         #
1869         route_3000_1 = VppIpRoute(self, "3000::1", 128,
1870                                   [VppRoutePath(self.pg1.remote_ip6,
1871                                                 self.pg1.sw_if_index),
1872                                    VppRoutePath(self.pg2.remote_ip6,
1873                                                 self.pg2.sw_if_index)])
1874         route_3000_1.add_vpp_config()
1875
1876         #
1877         # a local-label for the EOS packets
1878         #
1879         binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
1880         binding.add_vpp_config()
1881
1882         #
1883         # An MPLS route for the non-EOS packets
1884         #
1885         route_67 = VppMplsRoute(self, 67, 0,
1886                                 [VppRoutePath(self.pg1.remote_ip6,
1887                                               self.pg1.sw_if_index,
1888                                               labels=[67]),
1889                                  VppRoutePath(self.pg2.remote_ip6,
1890                                               self.pg2.sw_if_index,
1891                                               labels=[67])])
1892         route_67.add_vpp_config()
1893
1894         #
1895         # inject the packet on pg0 - expect load-balancing across the 2 paths
1896         #  - since the default hash config is to use IP src,dst and port
1897         #    src,dst
1898         # We are not going to ensure equal amounts of packets across each link,
1899         # since the hash algorithm is statistical and therefore this can never
1900         # be guaranteed. But with 64 different packets we do expect some
1901         # balancing. So instead just ensure there is traffic on each link.
1902         #
1903         self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
1904                                             [self.pg1, self.pg2])
1905         self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
1906                                             [self.pg1, self.pg2])
1907         self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
1908                                             [self.pg1, self.pg2])
1909         self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1910                                             [self.pg1, self.pg2])
1911         self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
1912                                             [self.pg1, self.pg2])
1913
1914         #
1915         # The packets with Entropy label in should not load-balance,
1916         # since the Entropy value is fixed.
1917         #
1918         self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
1919
1920         #
1921         # change the flow hash config so it's only IP src,dst
1922         #  - now only the stream with differing source address will
1923         #    load-balance
1924         #
1925         self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0,
1926                                    is_ipv6=1)
1927
1928         self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
1929                                             [self.pg1, self.pg2])
1930         self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1931                                             [self.pg1, self.pg2])
1932         self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
1933
1934         #
1935         # change the flow hash config back to defaults
1936         #
1937         self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1,
1938                                    is_ipv6=1)
1939
1940         #
1941         # Recursive prefixes
1942         #  - testing that 2 stages of load-balancing occurs and there is no
1943         #    polarisation (i.e. only 2 of 4 paths are used)
1944         #
1945         port_pkts = []
1946         src_pkts = []
1947
1948         for ii in range(257):
1949             port_pkts.append((Ether(src=self.pg0.remote_mac,
1950                                     dst=self.pg0.local_mac) /
1951                               IPv6(dst="4000::1",
1952                                    src="4000:1::1") /
1953                               inet6.UDP(sport=1234,
1954                                         dport=1234 + ii) /
1955                               Raw(b'\xa5' * 100)))
1956             src_pkts.append((Ether(src=self.pg0.remote_mac,
1957                                    dst=self.pg0.local_mac) /
1958                              IPv6(dst="4000::1",
1959                                   src="4000:1::%d" % ii) /
1960                              inet6.UDP(sport=1234, dport=1234) /
1961                              Raw(b'\xa5' * 100)))
1962
1963         route_3000_2 = VppIpRoute(self, "3000::2", 128,
1964                                   [VppRoutePath(self.pg3.remote_ip6,
1965                                                 self.pg3.sw_if_index),
1966                                    VppRoutePath(self.pg4.remote_ip6,
1967                                                 self.pg4.sw_if_index)])
1968         route_3000_2.add_vpp_config()
1969
1970         route_4000_1 = VppIpRoute(self, "4000::1", 128,
1971                                   [VppRoutePath("3000::1",
1972                                                 0xffffffff),
1973                                    VppRoutePath("3000::2",
1974                                                 0xffffffff)])
1975         route_4000_1.add_vpp_config()
1976
1977         #
1978         # inject the packet on pg0 - expect load-balancing across all 4 paths
1979         #
1980         self.vapi.cli("clear trace")
1981         self.send_and_expect_load_balancing(self.pg0, port_pkts,
1982                                             [self.pg1, self.pg2,
1983                                              self.pg3, self.pg4])
1984         self.send_and_expect_load_balancing(self.pg0, src_pkts,
1985                                             [self.pg1, self.pg2,
1986                                              self.pg3, self.pg4])
1987
1988         #
1989         # Recursive prefixes
1990         #  - testing that 2 stages of load-balancing no choices
1991         #
1992         port_pkts = []
1993
1994         for ii in range(257):
1995             port_pkts.append((Ether(src=self.pg0.remote_mac,
1996                                     dst=self.pg0.local_mac) /
1997                               IPv6(dst="6000::1",
1998                                    src="6000:1::1") /
1999                               inet6.UDP(sport=1234,
2000                                         dport=1234 + ii) /
2001                               Raw(b'\xa5' * 100)))
2002
2003         route_5000_2 = VppIpRoute(self, "5000::2", 128,
2004                                   [VppRoutePath(self.pg3.remote_ip6,
2005                                                 self.pg3.sw_if_index)])
2006         route_5000_2.add_vpp_config()
2007
2008         route_6000_1 = VppIpRoute(self, "6000::1", 128,
2009                                   [VppRoutePath("5000::2",
2010                                                 0xffffffff)])
2011         route_6000_1.add_vpp_config()
2012
2013         #
2014         # inject the packet on pg0 - expect load-balancing across all 4 paths
2015         #
2016         self.vapi.cli("clear trace")
2017         self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
2018
2019
2020 class TestIP6Punt(VppTestCase):
2021     """ IPv6 Punt Police/Redirect """
2022
2023     @classmethod
2024     def setUpClass(cls):
2025         super(TestIP6Punt, cls).setUpClass()
2026
2027     @classmethod
2028     def tearDownClass(cls):
2029         super(TestIP6Punt, cls).tearDownClass()
2030
2031     def setUp(self):
2032         super(TestIP6Punt, self).setUp()
2033
2034         self.create_pg_interfaces(range(4))
2035
2036         for i in self.pg_interfaces:
2037             i.admin_up()
2038             i.config_ip6()
2039             i.resolve_ndp()
2040
2041     def tearDown(self):
2042         super(TestIP6Punt, self).tearDown()
2043         for i in self.pg_interfaces:
2044             i.unconfig_ip6()
2045             i.admin_down()
2046
2047     def test_ip_punt(self):
2048         """ IP6 punt police and redirect """
2049
2050         p = (Ether(src=self.pg0.remote_mac,
2051                    dst=self.pg0.local_mac) /
2052              IPv6(src=self.pg0.remote_ip6,
2053                   dst=self.pg0.local_ip6) /
2054              inet6.TCP(sport=1234, dport=1234) /
2055              Raw(b'\xa5' * 100))
2056
2057         pkts = p * 1025
2058
2059         #
2060         # Configure a punt redirect via pg1.
2061         #
2062         nh_addr = self.pg1.remote_ip6
2063         self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2064                                    self.pg1.sw_if_index,
2065                                    nh_addr)
2066
2067         self.send_and_expect(self.pg0, pkts, self.pg1)
2068
2069         #
2070         # add a policer
2071         #
2072         policer = self.vapi.policer_add_del(b"ip6-punt", 400, 0, 10, 0,
2073                                             rate_type=1)
2074         self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
2075
2076         self.vapi.cli("clear trace")
2077         self.pg0.add_stream(pkts)
2078         self.pg_enable_capture(self.pg_interfaces)
2079         self.pg_start()
2080
2081         #
2082         # the number of packet received should be greater than 0,
2083         # but not equal to the number sent, since some were policed
2084         #
2085         rx = self.pg1._get_capture(1)
2086         self.assertGreater(len(rx), 0)
2087         self.assertLess(len(rx), len(pkts))
2088
2089         #
2090         # remove the policer. back to full rx
2091         #
2092         self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
2093         self.vapi.policer_add_del(b"ip6-punt", 400, 0, 10, 0,
2094                                   rate_type=1, is_add=0)
2095         self.send_and_expect(self.pg0, pkts, self.pg1)
2096
2097         #
2098         # remove the redirect. expect full drop.
2099         #
2100         self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2101                                    self.pg1.sw_if_index,
2102                                    nh_addr,
2103                                    is_add=0)
2104         self.send_and_assert_no_replies(self.pg0, pkts,
2105                                         "IP no punt config")
2106
2107         #
2108         # Add a redirect that is not input port selective
2109         #
2110         self.vapi.ip_punt_redirect(0xffffffff,
2111                                    self.pg1.sw_if_index,
2112                                    nh_addr)
2113         self.send_and_expect(self.pg0, pkts, self.pg1)
2114
2115         self.vapi.ip_punt_redirect(0xffffffff,
2116                                    self.pg1.sw_if_index,
2117                                    nh_addr,
2118                                    is_add=0)
2119
2120     def test_ip_punt_dump(self):
2121         """ IP6 punt redirect dump"""
2122
2123         #
2124         # Configure a punt redirects
2125         #
2126         nh_addr = self.pg3.remote_ip6
2127         self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2128                                    self.pg3.sw_if_index,
2129                                    nh_addr)
2130         self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
2131                                    self.pg3.sw_if_index,
2132                                    nh_addr)
2133         self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
2134                                    self.pg3.sw_if_index,
2135                                    '0::0')
2136
2137         #
2138         # Dump pg0 punt redirects
2139         #
2140         punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
2141                                                 is_ipv6=1)
2142         for p in punts:
2143             self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
2144
2145         #
2146         # Dump punt redirects for all interfaces
2147         #
2148         punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2149         self.assertEqual(len(punts), 3)
2150         for p in punts:
2151             self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
2152         self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2153         self.assertEqual(str(punts[2].punt.nh), '::')
2154
2155
2156 class TestIPDeag(VppTestCase):
2157     """ IPv6 Deaggregate Routes """
2158
2159     @classmethod
2160     def setUpClass(cls):
2161         super(TestIPDeag, cls).setUpClass()
2162
2163     @classmethod
2164     def tearDownClass(cls):
2165         super(TestIPDeag, cls).tearDownClass()
2166
2167     def setUp(self):
2168         super(TestIPDeag, self).setUp()
2169
2170         self.create_pg_interfaces(range(3))
2171
2172         for i in self.pg_interfaces:
2173             i.admin_up()
2174             i.config_ip6()
2175             i.resolve_ndp()
2176
2177     def tearDown(self):
2178         super(TestIPDeag, self).tearDown()
2179         for i in self.pg_interfaces:
2180             i.unconfig_ip6()
2181             i.admin_down()
2182
2183     def test_ip_deag(self):
2184         """ IP Deag Routes """
2185
2186         #
2187         # Create a table to be used for:
2188         #  1 - another destination address lookup
2189         #  2 - a source address lookup
2190         #
2191         table_dst = VppIpTable(self, 1, is_ip6=1)
2192         table_src = VppIpTable(self, 2, is_ip6=1)
2193         table_dst.add_vpp_config()
2194         table_src.add_vpp_config()
2195
2196         #
2197         # Add a route in the default table to point to a deag/
2198         # second lookup in each of these tables
2199         #
2200         route_to_dst = VppIpRoute(self, "1::1", 128,
2201                                   [VppRoutePath("::",
2202                                                 0xffffffff,
2203                                                 nh_table_id=1)])
2204         route_to_src = VppIpRoute(
2205             self, "1::2", 128,
2206             [VppRoutePath("::",
2207                           0xffffffff,
2208                           nh_table_id=2,
2209                           type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)])
2210
2211         route_to_dst.add_vpp_config()
2212         route_to_src.add_vpp_config()
2213
2214         #
2215         # packets to these destination are dropped, since they'll
2216         # hit the respective default routes in the second table
2217         #
2218         p_dst = (Ether(src=self.pg0.remote_mac,
2219                        dst=self.pg0.local_mac) /
2220                  IPv6(src="5::5", dst="1::1") /
2221                  inet6.TCP(sport=1234, dport=1234) /
2222                  Raw(b'\xa5' * 100))
2223         p_src = (Ether(src=self.pg0.remote_mac,
2224                        dst=self.pg0.local_mac) /
2225                  IPv6(src="2::2", dst="1::2") /
2226                  inet6.TCP(sport=1234, dport=1234) /
2227                  Raw(b'\xa5' * 100))
2228         pkts_dst = p_dst * 257
2229         pkts_src = p_src * 257
2230
2231         self.send_and_assert_no_replies(self.pg0, pkts_dst,
2232                                         "IP in dst table")
2233         self.send_and_assert_no_replies(self.pg0, pkts_src,
2234                                         "IP in src table")
2235
2236         #
2237         # add a route in the dst table to forward via pg1
2238         #
2239         route_in_dst = VppIpRoute(self, "1::1", 128,
2240                                   [VppRoutePath(self.pg1.remote_ip6,
2241                                                 self.pg1.sw_if_index)],
2242                                   table_id=1)
2243         route_in_dst.add_vpp_config()
2244
2245         self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2246
2247         #
2248         # add a route in the src table to forward via pg2
2249         #
2250         route_in_src = VppIpRoute(self, "2::2", 128,
2251                                   [VppRoutePath(self.pg2.remote_ip6,
2252                                                 self.pg2.sw_if_index)],
2253                                   table_id=2)
2254         route_in_src.add_vpp_config()
2255         self.send_and_expect(self.pg0, pkts_src, self.pg2)
2256
2257         #
2258         # loop in the lookup DP
2259         #
2260         route_loop = VppIpRoute(self, "3::3", 128,
2261                                 [VppRoutePath("::",
2262                                               0xffffffff)])
2263         route_loop.add_vpp_config()
2264
2265         p_l = (Ether(src=self.pg0.remote_mac,
2266                      dst=self.pg0.local_mac) /
2267                IPv6(src="3::4", dst="3::3") /
2268                inet6.TCP(sport=1234, dport=1234) /
2269                Raw(b'\xa5' * 100))
2270
2271         self.send_and_assert_no_replies(self.pg0, p_l * 257,
2272                                         "IP lookup loop")
2273
2274
2275 class TestIP6Input(VppTestCase):
2276     """ IPv6 Input Exception Test Cases """
2277
2278     @classmethod
2279     def setUpClass(cls):
2280         super(TestIP6Input, cls).setUpClass()
2281
2282     @classmethod
2283     def tearDownClass(cls):
2284         super(TestIP6Input, cls).tearDownClass()
2285
2286     def setUp(self):
2287         super(TestIP6Input, self).setUp()
2288
2289         self.create_pg_interfaces(range(2))
2290
2291         for i in self.pg_interfaces:
2292             i.admin_up()
2293             i.config_ip6()
2294             i.resolve_ndp()
2295
2296     def tearDown(self):
2297         super(TestIP6Input, self).tearDown()
2298         for i in self.pg_interfaces:
2299             i.unconfig_ip6()
2300             i.admin_down()
2301
2302     def test_ip_input_icmp_reply(self):
2303         """ IP6 Input Exception - Return ICMP (3,0) """
2304         #
2305         # hop limit - ICMP replies
2306         #
2307         p_version = (Ether(src=self.pg0.remote_mac,
2308                            dst=self.pg0.local_mac) /
2309                      IPv6(src=self.pg0.remote_ip6,
2310                           dst=self.pg1.remote_ip6,
2311                           hlim=1) /
2312                      inet6.UDP(sport=1234, dport=1234) /
2313                      Raw(b'\xa5' * 100))
2314
2315         rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0)
2316         rx = rx[0]
2317         icmp = rx[ICMPv6TimeExceeded]
2318
2319         # 0: "hop limit exceeded in transit",
2320         self.assertEqual((icmp.type, icmp.code), (3, 0))
2321
2322     icmpv6_data = '\x0a' * 18
2323     all_0s = "::"
2324     all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2325
2326     @parameterized.expand([
2327         # Name, src, dst, l4proto, msg, timeout
2328         ("src='iface',   dst='iface'", None, None,
2329          inet6.UDP(sport=1234, dport=1234), "funky version", None),
2330         ("src='All 0's', dst='iface'", all_0s, None,
2331          ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2332         ("src='iface',   dst='All 0's'", None, all_0s,
2333          ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2334         ("src='All 1's', dst='iface'", all_1s, None,
2335          ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2336         ("src='iface',   dst='All 1's'", None, all_1s,
2337          ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2338         ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2339          ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2340
2341     ])
2342     def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2343
2344         self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2345
2346         p_version = (Ether(src=self.pg0.remote_mac,
2347                            dst=self.pg0.local_mac) /
2348                      IPv6(src=src or self.pg0.remote_ip6,
2349                           dst=dst or self.pg1.remote_ip6,
2350                           version=3) /
2351                      l4 /
2352                      Raw(b'\xa5' * 100))
2353
2354         self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS,
2355                                         remark=msg or "",
2356                                         timeout=timeout)
2357
2358     def test_hop_by_hop(self):
2359         """ Hop-by-hop header test """
2360
2361         p = (Ether(src=self.pg0.remote_mac,
2362                    dst=self.pg0.local_mac) /
2363              IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
2364              IPv6ExtHdrHopByHop() /
2365              inet6.UDP(sport=1234, dport=1234) /
2366              Raw(b'\xa5' * 100))
2367
2368         self.pg0.add_stream(p)
2369         self.pg_enable_capture(self.pg_interfaces)
2370         self.pg_start()
2371
2372
2373 class TestIPReplace(VppTestCase):
2374     """ IPv6 Table Replace """
2375
2376     @classmethod
2377     def setUpClass(cls):
2378         super(TestIPReplace, cls).setUpClass()
2379
2380     @classmethod
2381     def tearDownClass(cls):
2382         super(TestIPReplace, cls).tearDownClass()
2383
2384     def setUp(self):
2385         super(TestIPReplace, self).setUp()
2386
2387         self.create_pg_interfaces(range(4))
2388
2389         table_id = 1
2390         self.tables = []
2391
2392         for i in self.pg_interfaces:
2393             i.admin_up()
2394             i.config_ip6()
2395             i.resolve_arp()
2396             i.generate_remote_hosts(2)
2397             self.tables.append(VppIpTable(self, table_id,
2398                                           True).add_vpp_config())
2399             table_id += 1
2400
2401     def tearDown(self):
2402         super(TestIPReplace, self).tearDown()
2403         for i in self.pg_interfaces:
2404             i.admin_down()
2405             i.unconfig_ip4()
2406
2407     def test_replace(self):
2408         """ IP Table Replace """
2409
2410         N_ROUTES = 20
2411         links = [self.pg0, self.pg1, self.pg2, self.pg3]
2412         routes = [[], [], [], []]
2413
2414         # the sizes of 'empty' tables
2415         for t in self.tables:
2416             self.assertEqual(len(t.dump()), 2)
2417             self.assertEqual(len(t.mdump()), 5)
2418
2419         # load up the tables with some routes
2420         for ii, t in enumerate(self.tables):
2421             for jj in range(1, N_ROUTES):
2422                 uni = VppIpRoute(
2423                     self, "2001::%d" % jj if jj != 0 else "2001::", 128,
2424                     [VppRoutePath(links[ii].remote_hosts[0].ip6,
2425                                   links[ii].sw_if_index),
2426                      VppRoutePath(links[ii].remote_hosts[1].ip6,
2427                                   links[ii].sw_if_index)],
2428                     table_id=t.table_id).add_vpp_config()
2429                 multi = VppIpMRoute(
2430                     self, "::",
2431                     "ff:2001::%d" % jj, 128,
2432                     MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
2433                     [VppMRoutePath(self.pg0.sw_if_index,
2434                                    MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
2435                                    proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2436                      VppMRoutePath(self.pg1.sw_if_index,
2437                                    MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2438                                    proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2439                      VppMRoutePath(self.pg2.sw_if_index,
2440                                    MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2441                                    proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2442                      VppMRoutePath(self.pg3.sw_if_index,
2443                                    MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2444                                    proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
2445                     table_id=t.table_id).add_vpp_config()
2446                 routes[ii].append({'uni': uni,
2447                                    'multi': multi})
2448
2449         #
2450         # replace the tables a few times
2451         #
2452         for kk in range(3):
2453             # replace each table
2454             for t in self.tables:
2455                 t.replace_begin()
2456
2457             # all the routes are still there
2458             for ii, t in enumerate(self.tables):
2459                 dump = t.dump()
2460                 mdump = t.mdump()
2461                 for r in routes[ii]:
2462                     self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2463                     self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2464
2465             # redownload the even numbered routes
2466             for ii, t in enumerate(self.tables):
2467                 for jj in range(0, N_ROUTES, 2):
2468                     routes[ii][jj]['uni'].add_vpp_config()
2469                     routes[ii][jj]['multi'].add_vpp_config()
2470
2471             # signal each table converged
2472             for t in self.tables:
2473                 t.replace_end()
2474
2475             # we should find the even routes, but not the odd
2476             for ii, t in enumerate(self.tables):
2477                 dump = t.dump()
2478                 mdump = t.mdump()
2479                 for jj in range(0, N_ROUTES, 2):
2480                     self.assertTrue(find_route_in_dump(
2481                         dump, routes[ii][jj]['uni'], t))
2482                     self.assertTrue(find_mroute_in_dump(
2483                         mdump, routes[ii][jj]['multi'], t))
2484                 for jj in range(1, N_ROUTES - 1, 2):
2485                     self.assertFalse(find_route_in_dump(
2486                         dump, routes[ii][jj]['uni'], t))
2487                     self.assertFalse(find_mroute_in_dump(
2488                         mdump, routes[ii][jj]['multi'], t))
2489
2490             # reload all the routes
2491             for ii, t in enumerate(self.tables):
2492                 for r in routes[ii]:
2493                     r['uni'].add_vpp_config()
2494                     r['multi'].add_vpp_config()
2495
2496             # all the routes are still there
2497             for ii, t in enumerate(self.tables):
2498                 dump = t.dump()
2499                 mdump = t.mdump()
2500                 for r in routes[ii]:
2501                     self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2502                     self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2503
2504         #
2505         # finally flush the tables for good measure
2506         #
2507         for t in self.tables:
2508             t.flush()
2509             self.assertEqual(len(t.dump()), 2)
2510             self.assertEqual(len(t.mdump()), 5)
2511
2512
2513 if __name__ == '__main__':
2514     unittest.main(testRunner=VppTestRunner)