blob: 5dc7269f203e354c2c2db66d33479b9ddc38fb44 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Damjan Marionf56b77a2016-10-03 19:44:57 +02002
Paul Vinciguerra582eac52020-04-03 12:18:40 -04003import socket
snaramre5d4b8912019-12-13 23:39:35 +00004from socket import inet_pton, inet_ntop
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -08005import unittest
6
Neale Rannsae809832018-11-23 09:00:27 -08007from parameterized import parameterized
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07008import scapy.compat
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -08009import scapy.layers.inet6 as inet6
Neale Rannsdfef64b2021-05-20 16:28:12 +000010from scapy.layers.inet import UDP, IP
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080011from scapy.contrib.mpls import MPLS
12from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \
13 ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
14 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
Neale Rannsf267d112020-02-07 09:45:07 +000015 ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply, \
16 IPv6ExtHdrHopByHop, ICMPv6MLReport2, ICMPv6MLDMultAddrRec
Neale Rannsdfef64b2021-05-20 16:28:12 +000017from scapy.layers.l2 import Ether, Dot1Q, GRE
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080018from scapy.packet import Raw
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080019from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
20 in6_mactoifaceid
21from six import moves
Klement Sekeraf62ae122016-10-11 11:47:09 +020022
Andrew Yourtchenko06f32812021-01-14 10:19:08 +000023from framework import VppTestCase, VppTestRunner, tag_run_solo
Paul Vinciguerrae8fece82019-02-28 15:34:00 -080024from util import ppp, ip6_normalize, mk_ll_addr
Neale Ranns990f6942020-10-20 07:20:17 +000025from vpp_papi import VppEnum
Neale Ranns8f5fef22020-12-21 08:29:34 +000026from vpp_ip import DpoProto, VppIpPuntPolicer, VppIpPuntRedirect, VppIpPathMtu
Neale Ranns180279b2017-03-16 15:49:09 -040027from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
Neale Ranns990f6942020-10-20 07:20:17 +000028 VppMRoutePath, VppMplsIpBind, \
Neale Ranns9db6ada2019-11-08 12:42:31 +000029 VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
Neale Rannsec40a7d2020-04-23 07:36:12 +000030 VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump, \
Neale Ranns976b2592019-12-04 06:11:00 +000031 VppIp6LinkLocalAddress, VppIpRouteV2
Neale Rannsb3b2de72017-03-08 05:17:22 -080032from vpp_neighbor import find_nbr, VppNeighbor
Neale Ranns8f5fef22020-12-21 08:29:34 +000033from vpp_ipip_tun_interface import VppIpIpTunInterface
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080034from vpp_pg_interface import is_ipv6_misc
35from vpp_sub_interface import VppSubInterface, VppDot1QSubint
Brian Russell5214f3a2021-01-19 16:58:34 +000036from vpp_policer import VppPolicer, PolicerAction
Neale Rannsefd7bc22019-11-11 08:32:34 +000037from ipaddress import IPv6Network, IPv6Address
Neale Rannsdfef64b2021-05-20 16:28:12 +000038from vpp_gre_interface import VppGreInterface
39from vpp_teib import VppTeib
Neale Ranns75152282017-01-09 01:00:45 -080040
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010041AF_INET6 = socket.AF_INET6
42
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -080043try:
44 text_type = unicode
45except NameError:
46 text_type = str
47
Paul Vinciguerra4271c972019-05-14 13:25:49 -040048NUM_PKTS = 67
49
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010050
Neale Ranns3f844d02017-02-18 00:03:54 -080051class TestIPv6ND(VppTestCase):
52 def validate_ra(self, intf, rx, dst_ip=None):
53 if not dst_ip:
54 dst_ip = intf.remote_ip6
55
56 # unicasted packets must come to the unicast mac
57 self.assertEqual(rx[Ether].dst, intf.remote_mac)
58
59 # and from the router's MAC
60 self.assertEqual(rx[Ether].src, intf.local_mac)
61
62 # the rx'd RA should be addressed to the sender's source
63 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
64 self.assertEqual(in6_ptop(rx[IPv6].dst),
65 in6_ptop(dst_ip))
66
67 # and come from the router's link local
68 self.assertTrue(in6_islladdr(rx[IPv6].src))
69 self.assertEqual(in6_ptop(rx[IPv6].src),
70 in6_ptop(mk_ll_addr(intf.local_mac)))
71
72 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
73 if not dst_ip:
74 dst_ip = intf.remote_ip6
75 if not tgt_ip:
76 dst_ip = intf.local_ip6
77
78 # unicasted packets must come to the unicast mac
79 self.assertEqual(rx[Ether].dst, intf.remote_mac)
80
81 # and from the router's MAC
82 self.assertEqual(rx[Ether].src, intf.local_mac)
83
84 # the rx'd NA should be addressed to the sender's source
85 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
86 self.assertEqual(in6_ptop(rx[IPv6].dst),
87 in6_ptop(dst_ip))
88
89 # and come from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -080090 self.assertEqual(
91 in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
Neale Ranns3f844d02017-02-18 00:03:54 -080092
93 # Dest link-layer options should have the router's MAC
94 dll = rx[ICMPv6NDOptDstLLAddr]
95 self.assertEqual(dll.lladdr, intf.local_mac)
96
Neale Rannsdcd6d622017-05-26 02:59:16 -070097 def validate_ns(self, intf, rx, tgt_ip):
98 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
99 dst_ip = inet_ntop(AF_INET6, nsma)
100
101 # NS is broadcast
Neale Rannsc7b8f202018-04-25 06:34:31 -0700102 self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
Neale Rannsdcd6d622017-05-26 02:59:16 -0700103
104 # and from the router's MAC
105 self.assertEqual(rx[Ether].src, intf.local_mac)
106
107 # the rx'd NS should be addressed to an mcast address
108 # derived from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800109 self.assertEqual(
110 in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
Neale Rannsdcd6d622017-05-26 02:59:16 -0700111
112 # expect the tgt IP in the NS header
113 ns = rx[ICMPv6ND_NS]
114 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
115
116 # packet is from the router's local address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800117 self.assertEqual(
118 in6_ptop(rx[IPv6].src), intf.local_ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700119
120 # Src link-layer options should have the router's MAC
121 sll = rx[ICMPv6NDOptSrcLLAddr]
122 self.assertEqual(sll.lladdr, intf.local_mac)
123
Neale Ranns3f844d02017-02-18 00:03:54 -0800124 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
125 filter_out_fn=is_ipv6_misc):
126 intf.add_stream(pkts)
Neale Ranns3f844d02017-02-18 00:03:54 -0800127 self.pg_enable_capture(self.pg_interfaces)
128 self.pg_start()
129 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
130
131 self.assertEqual(len(rx), 1)
132 rx = rx[0]
133 self.validate_ra(intf, rx, dst_ip)
134
Neale Ranns2a3ea492017-04-19 05:24:40 -0700135 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
136 tgt_ip=None,
137 filter_out_fn=is_ipv6_misc):
138 intf.add_stream(pkts)
139 self.pg_enable_capture(self.pg_interfaces)
140 self.pg_start()
141 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
142
143 self.assertEqual(len(rx), 1)
144 rx = rx[0]
145 self.validate_na(intf, rx, dst_ip, tgt_ip)
146
Neale Rannsdcd6d622017-05-26 02:59:16 -0700147 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
148 filter_out_fn=is_ipv6_misc):
Neale Rannscbe25aa2019-09-30 10:53:31 +0000149 self.vapi.cli("clear trace")
Neale Rannsdcd6d622017-05-26 02:59:16 -0700150 tx_intf.add_stream(pkts)
151 self.pg_enable_capture(self.pg_interfaces)
152 self.pg_start()
153 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
154
155 self.assertEqual(len(rx), 1)
156 rx = rx[0]
157 self.validate_ns(rx_intf, rx, tgt_ip)
158
Neale Rannsdcd6d622017-05-26 02:59:16 -0700159 def verify_ip(self, rx, smac, dmac, sip, dip):
160 ether = rx[Ether]
161 self.assertEqual(ether.dst, dmac)
162 self.assertEqual(ether.src, smac)
163
164 ip = rx[IPv6]
165 self.assertEqual(ip.src, sip)
166 self.assertEqual(ip.dst, dip)
167
Neale Ranns3f844d02017-02-18 00:03:54 -0800168
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000169@tag_run_solo
Neale Ranns3f844d02017-02-18 00:03:54 -0800170class TestIPv6(TestIPv6ND):
Damjan Marionf56b77a2016-10-03 19:44:57 +0200171 """ IPv6 Test Case """
172
173 @classmethod
174 def setUpClass(cls):
175 super(TestIPv6, cls).setUpClass()
176
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700177 @classmethod
178 def tearDownClass(cls):
179 super(TestIPv6, cls).tearDownClass()
180
Klement Sekeraf62ae122016-10-11 11:47:09 +0200181 def setUp(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100182 """
183 Perform test setup before test case.
184
185 **Config:**
186 - create 3 pg interfaces
187 - untagged pg0 interface
188 - Dot1Q subinterface on pg1
189 - Dot1AD subinterface on pg2
190 - setup interfaces:
191 - put it into UP state
192 - set IPv6 addresses
193 - resolve neighbor address using NDP
194 - configure 200 fib entries
195
196 :ivar list interfaces: pg interfaces and subinterfaces.
197 :ivar dict flows: IPv4 packet flows in test.
Matej Klotton86d87c42016-11-11 11:38:55 +0100198
199 *TODO:* Create AD sub interface
200 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200201 super(TestIPv6, self).setUp()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200202
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203 # create 3 pg interfaces
204 self.create_pg_interfaces(range(3))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200205
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206 # create 2 subinterfaces for p1 and pg2
207 self.sub_interfaces = [
208 VppDot1QSubint(self, self.pg1, 100),
Matej Klotton86d87c42016-11-11 11:38:55 +0100209 VppDot1QSubint(self, self.pg2, 200)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
Matej Klotton86d87c42016-11-11 11:38:55 +0100211 ]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200212
Klement Sekeraf62ae122016-10-11 11:47:09 +0200213 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
214 self.flows = dict()
215 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
216 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
217 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200218
Klement Sekeraf62ae122016-10-11 11:47:09 +0200219 # packet sizes
Jan Geletye6c78ee2018-06-26 12:24:03 +0200220 self.pg_if_packet_sizes = [64, 1500, 9020]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200221
Klement Sekeraf62ae122016-10-11 11:47:09 +0200222 self.interfaces = list(self.pg_interfaces)
223 self.interfaces.extend(self.sub_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200224
Klement Sekeraf62ae122016-10-11 11:47:09 +0200225 # setup all interfaces
226 for i in self.interfaces:
227 i.admin_up()
228 i.config_ip6()
229 i.resolve_ndp()
230
Damjan Marionf56b77a2016-10-03 19:44:57 +0200231 def tearDown(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100232 """Run standard test teardown and log ``show ip6 neighbors``."""
Neale Ranns744902e2017-08-14 10:35:44 -0700233 for i in self.interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800234 i.unconfig_ip6()
Neale Ranns75152282017-01-09 01:00:45 -0800235 i.admin_down()
Neale Ranns744902e2017-08-14 10:35:44 -0700236 for i in self.sub_interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800237 i.remove_vpp_config()
238
Klement Sekeraf62ae122016-10-11 11:47:09 +0200239 super(TestIPv6, self).tearDown()
240 if not self.vpp_dead:
Matej Klotton86d87c42016-11-11 11:38:55 +0100241 self.logger.info(self.vapi.cli("show ip6 neighbors"))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200242 # info(self.vapi.cli("show ip6 fib")) # many entries
Damjan Marionf56b77a2016-10-03 19:44:57 +0200243
Jan Geletye6c78ee2018-06-26 12:24:03 +0200244 def modify_packet(self, src_if, packet_size, pkt):
245 """Add load, set destination IP and extend packet to required packet
246 size for defined interface.
247
248 :param VppInterface src_if: Interface to create packet for.
249 :param int packet_size: Required packet size.
250 :param Scapy pkt: Packet to be modified.
251 """
snaramre07a0f212019-10-11 21:28:56 +0000252 dst_if_idx = int(packet_size / 10 % 2)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200253 dst_if = self.flows[src_if][dst_if_idx]
254 info = self.create_packet_info(src_if, dst_if)
255 payload = self.info_to_payload(info)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800256 p = pkt / Raw(payload)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200257 p[IPv6].dst = dst_if.remote_ip6
258 info.data = p.copy()
259 if isinstance(src_if, VppSubInterface):
260 p = src_if.add_dot1_layer(p)
261 self.extend_packet(p, packet_size)
262
263 return p
264
265 def create_stream(self, src_if):
Matej Klotton86d87c42016-11-11 11:38:55 +0100266 """Create input packet stream for defined interface.
267
268 :param VppInterface src_if: Interface to create packet stream for.
Matej Klotton86d87c42016-11-11 11:38:55 +0100269 """
Jan Geletye6c78ee2018-06-26 12:24:03 +0200270 hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
271 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
272 IPv6(src=src_if.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800273 inet6.UDP(sport=1234, dport=1234))
Jan Geletye6c78ee2018-06-26 12:24:03 +0200274
275 pkts = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800276 for i in moves.range(self.pg_if_packet_sizes[0],
277 self.pg_if_packet_sizes[1], 10)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200278 pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800279 for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
280 self.pg_if_packet_sizes[2] + hdr_ext,
281 50)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200282 pkts.extend(pkts_b)
283
Damjan Marionf56b77a2016-10-03 19:44:57 +0200284 return pkts
285
Klement Sekeraf62ae122016-10-11 11:47:09 +0200286 def verify_capture(self, dst_if, capture):
Matej Klotton86d87c42016-11-11 11:38:55 +0100287 """Verify captured input packet stream for defined interface.
288
289 :param VppInterface dst_if: Interface to verify captured packet stream
290 for.
291 :param list capture: Captured packet stream.
292 """
293 self.logger.info("Verifying capture on interface %s" % dst_if.name)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200294 last_info = dict()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200295 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200296 last_info[i.sw_if_index] = None
297 is_sub_if = False
298 dst_sw_if_index = dst_if.sw_if_index
299 if hasattr(dst_if, 'parent'):
300 is_sub_if = True
Damjan Marionf56b77a2016-10-03 19:44:57 +0200301 for packet in capture:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200302 if is_sub_if:
303 # Check VLAN tags and Ethernet header
304 packet = dst_if.remove_dot1_layer(packet)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200305 self.assertTrue(Dot1Q not in packet)
306 try:
307 ip = packet[IPv6]
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800308 udp = packet[inet6.UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800309 payload_info = self.payload_to_info(packet[Raw])
Damjan Marionf56b77a2016-10-03 19:44:57 +0200310 packet_index = payload_info.index
Klement Sekeraf62ae122016-10-11 11:47:09 +0200311 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerada505f62017-01-04 12:58:53 +0100312 self.logger.debug(
313 "Got packet on port %s: src=%u (id=%u)" %
314 (dst_if.name, payload_info.src, packet_index))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200315 next_info = self.get_next_packet_info_for_interface2(
316 payload_info.src, dst_sw_if_index,
317 last_info[payload_info.src])
318 last_info[payload_info.src] = next_info
Damjan Marionf56b77a2016-10-03 19:44:57 +0200319 self.assertTrue(next_info is not None)
320 self.assertEqual(packet_index, next_info.index)
321 saved_packet = next_info.data
322 # Check standard fields
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800323 self.assertEqual(
324 ip.src, saved_packet[IPv6].src)
325 self.assertEqual(
326 ip.dst, saved_packet[IPv6].dst)
327 self.assertEqual(
328 udp.sport, saved_packet[inet6.UDP].sport)
329 self.assertEqual(
330 udp.dport, saved_packet[inet6.UDP].dport)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200331 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100332 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200333 raise
334 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200335 remaining_packet = self.get_next_packet_info_for_interface2(
336 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
Klement Sekera7bb873a2016-11-18 07:38:42 +0100337 self.assertTrue(remaining_packet is None,
338 "Interface %s: Packet expected from interface %s "
339 "didn't arrive" % (dst_if.name, i.name))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200340
Klement Sekerae8498652019-06-17 12:23:15 +0000341 def test_next_header_anomaly(self):
342 """ IPv6 next header anomaly test
343
344 Test scenario:
345 - ipv6 next header field = Fragment Header (44)
346 - next header is ICMPv6 Echo Request
347 - wait for reassembly
348 """
349 pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) /
350 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) /
351 ICMPv6EchoRequest())
352
353 self.pg0.add_stream(pkt)
354 self.pg_start()
355
356 # wait for reassembly
357 self.sleep(10)
358
Damjan Marionf56b77a2016-10-03 19:44:57 +0200359 def test_fib(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100360 """ IPv6 FIB test
361
362 Test scenario:
363 - Create IPv6 stream for pg0 interface
364 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
365 - Send and verify received packets on each interface.
366 """
Damjan Marionf56b77a2016-10-03 19:44:57 +0200367
Jan Geletye6c78ee2018-06-26 12:24:03 +0200368 pkts = self.create_stream(self.pg0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200369 self.pg0.add_stream(pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200370
Klement Sekeraf62ae122016-10-11 11:47:09 +0200371 for i in self.sub_interfaces:
Jan Geletye6c78ee2018-06-26 12:24:03 +0200372 pkts = self.create_stream(i)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200373 i.parent.add_stream(pkts)
374
375 self.pg_enable_capture(self.pg_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200376 self.pg_start()
377
Klement Sekeraf62ae122016-10-11 11:47:09 +0200378 pkts = self.pg0.get_capture()
379 self.verify_capture(self.pg0, pkts)
380
381 for i in self.sub_interfaces:
382 pkts = i.parent.get_capture()
383 self.verify_capture(i, pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200384
Neale Ranns75152282017-01-09 01:00:45 -0800385 def test_ns(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100386 """ IPv6 Neighbour Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800387
Klement Sekerada505f62017-01-04 12:58:53 +0100388 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800389 - Send an NS Sourced from an address not covered by the link sub-net
390 - Send an NS to an mcast address the router has not joined
391 - Send NS for a target address the router does not onn.
392 """
393
394 #
395 # An NS from a non link source address
396 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800397 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
398 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800399
400 p = (Ether(dst=in6_getnsmac(nsma)) /
401 IPv6(dst=d, src="2002::2") /
402 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800403 ICMPv6NDOptSrcLLAddr(
404 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800405 pkts = [p]
406
Klement Sekerada505f62017-01-04 12:58:53 +0100407 self.send_and_assert_no_replies(
408 self.pg0, pkts,
409 "No response to NS source by address not on sub-net")
Neale Ranns75152282017-01-09 01:00:45 -0800410
411 #
Klement Sekerada505f62017-01-04 12:58:53 +0100412 # An NS for sent to a solicited mcast group the router is
413 # not a member of FAILS
Neale Ranns75152282017-01-09 01:00:45 -0800414 #
415 if 0:
Neale Ranns3f844d02017-02-18 00:03:54 -0800416 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
417 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800418
419 p = (Ether(dst=in6_getnsmac(nsma)) /
420 IPv6(dst=d, src=self.pg0.remote_ip6) /
421 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800422 ICMPv6NDOptSrcLLAddr(
423 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800424 pkts = [p]
425
Klement Sekerada505f62017-01-04 12:58:53 +0100426 self.send_and_assert_no_replies(
427 self.pg0, pkts,
428 "No response to NS sent to unjoined mcast address")
Neale Ranns75152282017-01-09 01:00:45 -0800429
430 #
431 # An NS whose target address is one the router does not own
432 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800433 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
434 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800435
436 p = (Ether(dst=in6_getnsmac(nsma)) /
437 IPv6(dst=d, src=self.pg0.remote_ip6) /
438 ICMPv6ND_NS(tgt="fd::ffff") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800439 ICMPv6NDOptSrcLLAddr(
440 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800441 pkts = [p]
442
443 self.send_and_assert_no_replies(self.pg0, pkts,
444 "No response to NS for unknown target")
445
Neale Rannsb3b2de72017-03-08 05:17:22 -0800446 #
447 # A neighbor entry that has no associated FIB-entry
448 #
449 self.pg0.generate_remote_hosts(4)
450 nd_entry = VppNeighbor(self,
451 self.pg0.sw_if_index,
452 self.pg0.remote_hosts[2].mac,
453 self.pg0.remote_hosts[2].ip6,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800454 is_no_fib_entry=1)
455 nd_entry.add_vpp_config()
456
457 #
458 # check we have the neighbor, but no route
459 #
460 self.assertTrue(find_nbr(self,
461 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700462 self.pg0._remote_hosts[2].ip6))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800463 self.assertFalse(find_route(self,
464 self.pg0._remote_hosts[2].ip6,
Neale Ranns097fa662018-05-01 05:17:55 -0700465 128))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800466
Neale Ranns2a3ea492017-04-19 05:24:40 -0700467 #
468 # send an NS from a link local address to the interface's global
469 # address
470 #
471 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800472 IPv6(
473 dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700474 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800475 ICMPv6NDOptSrcLLAddr(
476 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700477
478 self.send_and_expect_na(self.pg0, p,
479 "NS from link-local",
480 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
481 tgt_ip=self.pg0.local_ip6)
482
483 #
484 # we should have learned an ND entry for the peer's link-local
485 # but not inserted a route to it in the FIB
486 #
487 self.assertTrue(find_nbr(self,
488 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700489 self.pg0._remote_hosts[2].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700490 self.assertFalse(find_route(self,
491 self.pg0._remote_hosts[2].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700492 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700493
494 #
495 # An NS to the router's own Link-local
496 #
497 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800498 IPv6(
499 dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700500 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800501 ICMPv6NDOptSrcLLAddr(
502 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700503
504 self.send_and_expect_na(self.pg0, p,
505 "NS to/from link-local",
506 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
507 tgt_ip=self.pg0.local_ip6_ll)
508
509 #
Neale Rannse2b67362021-04-02 07:34:39 +0000510 # do not respond to a NS for the peer's address
511 #
512 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
513 IPv6(dst=d,
514 src=self.pg0._remote_hosts[3].ip6_ll) /
515 ICMPv6ND_NS(tgt=self.pg0._remote_hosts[3].ip6_ll) /
516 ICMPv6NDOptSrcLLAddr(
517 lladdr=self.pg0.remote_mac))
518
519 self.send_and_assert_no_replies(self.pg0, p)
520
521 #
Neale Ranns2a3ea492017-04-19 05:24:40 -0700522 # we should have learned an ND entry for the peer's link-local
523 # but not inserted a route to it in the FIB
524 #
525 self.assertTrue(find_nbr(self,
526 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700527 self.pg0._remote_hosts[3].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700528 self.assertFalse(find_route(self,
529 self.pg0._remote_hosts[3].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700530 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700531
Neale Rannsdcd6d622017-05-26 02:59:16 -0700532 def test_ns_duplicates(self):
Neale Rannsda78f952017-05-24 09:15:43 -0700533 """ ND Duplicates"""
Neale Rannsdcd6d622017-05-26 02:59:16 -0700534
535 #
536 # Generate some hosts on the LAN
537 #
538 self.pg1.generate_remote_hosts(3)
539
540 #
541 # Add host 1 on pg1 and pg2
542 #
543 ns_pg1 = VppNeighbor(self,
544 self.pg1.sw_if_index,
545 self.pg1.remote_hosts[1].mac,
Neale Ranns37029302018-08-10 05:30:06 -0700546 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700547 ns_pg1.add_vpp_config()
548 ns_pg2 = VppNeighbor(self,
549 self.pg2.sw_if_index,
550 self.pg2.remote_mac,
Neale Ranns37029302018-08-10 05:30:06 -0700551 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700552 ns_pg2.add_vpp_config()
553
554 #
555 # IP packet destined for pg1 remote host arrives on pg1 again.
556 #
557 p = (Ether(dst=self.pg0.local_mac,
558 src=self.pg0.remote_mac) /
559 IPv6(src=self.pg0.remote_ip6,
560 dst=self.pg1.remote_hosts[1].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800561 inet6.UDP(sport=1234, dport=1234) /
Neale Rannsdcd6d622017-05-26 02:59:16 -0700562 Raw())
563
564 self.pg0.add_stream(p)
565 self.pg_enable_capture(self.pg_interfaces)
566 self.pg_start()
567
568 rx1 = self.pg1.get_capture(1)
569
570 self.verify_ip(rx1[0],
571 self.pg1.local_mac,
572 self.pg1.remote_hosts[1].mac,
573 self.pg0.remote_ip6,
574 self.pg1.remote_hosts[1].ip6)
575
576 #
577 # remove the duplicate on pg1
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700578 # packet stream should generate NSs out of pg1
Neale Rannsdcd6d622017-05-26 02:59:16 -0700579 #
580 ns_pg1.remove_vpp_config()
581
582 self.send_and_expect_ns(self.pg0, self.pg1,
583 p, self.pg1.remote_hosts[1].ip6)
584
585 #
586 # Add it back
587 #
588 ns_pg1.add_vpp_config()
589
590 self.pg0.add_stream(p)
591 self.pg_enable_capture(self.pg_interfaces)
592 self.pg_start()
593
594 rx1 = self.pg1.get_capture(1)
595
596 self.verify_ip(rx1[0],
597 self.pg1.local_mac,
598 self.pg1.remote_hosts[1].mac,
599 self.pg0.remote_ip6,
600 self.pg1.remote_hosts[1].ip6)
601
Neale Rannscbe25aa2019-09-30 10:53:31 +0000602 def validate_ra(self, intf, rx, dst_ip=None, src_ip=None,
603 mtu=9000, pi_opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000604 if not dst_ip:
605 dst_ip = intf.remote_ip6
Neale Rannscbe25aa2019-09-30 10:53:31 +0000606 if not src_ip:
607 src_ip = mk_ll_addr(intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800608
Neale Ranns5737d882017-02-03 06:14:49 -0800609 # unicasted packets must come to the unicast mac
Neale Ranns32e1c012016-11-22 17:07:28 +0000610 self.assertEqual(rx[Ether].dst, intf.remote_mac)
611
612 # and from the router's MAC
613 self.assertEqual(rx[Ether].src, intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800614
615 # the rx'd RA should be addressed to the sender's source
616 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
617 self.assertEqual(in6_ptop(rx[IPv6].dst),
Neale Ranns32e1c012016-11-22 17:07:28 +0000618 in6_ptop(dst_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800619
620 # and come from the router's link local
621 self.assertTrue(in6_islladdr(rx[IPv6].src))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000622 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800623
Neale Ranns87df12d2017-02-18 08:16:41 -0800624 # it should contain the links MTU
625 ra = rx[ICMPv6ND_RA]
626 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
627
628 # it should contain the source's link layer address option
629 sll = ra[ICMPv6NDOptSrcLLAddr]
630 self.assertEqual(sll.lladdr, intf.local_mac)
631
632 if not pi_opt:
633 # the RA should not contain prefix information
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800634 self.assertFalse(ra.haslayer(
635 ICMPv6NDOptPrefixInfo))
Neale Ranns87df12d2017-02-18 08:16:41 -0800636 else:
637 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
638
639 # the options are nested in the scapy packet in way that i cannot
640 # decipher how to decode. this 1st layer of option always returns
641 # nested classes, so a direct obj1=obj2 comparison always fails.
Paul Vinciguerraab055082019-06-06 14:07:55 -0400642 # however, the getlayer(.., 2) does give one instance.
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700643 # so we cheat here and construct a new opt instance for comparison
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800644 rd = ICMPv6NDOptPrefixInfo(
645 prefixlen=raos.prefixlen,
646 prefix=raos.prefix,
647 L=raos.L,
648 A=raos.A)
Neale Ranns87df12d2017-02-18 08:16:41 -0800649 if type(pi_opt) is list:
650 for ii in range(len(pi_opt)):
651 self.assertEqual(pi_opt[ii], rd)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800652 rd = rx.getlayer(
653 ICMPv6NDOptPrefixInfo, ii + 2)
Neale Ranns87df12d2017-02-18 08:16:41 -0800654 else:
Paul Vinciguerraab055082019-06-06 14:07:55 -0400655 self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s'
656 % (pi_opt.show(dump=True),
657 raos.show(dump=True)))
Neale Ranns87df12d2017-02-18 08:16:41 -0800658
Neale Ranns32e1c012016-11-22 17:07:28 +0000659 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
Neale Ranns87df12d2017-02-18 08:16:41 -0800660 filter_out_fn=is_ipv6_misc,
Neale Rannscbe25aa2019-09-30 10:53:31 +0000661 opt=None,
662 src_ip=None):
663 self.vapi.cli("clear trace")
Neale Ranns32e1c012016-11-22 17:07:28 +0000664 intf.add_stream(pkts)
Neale Ranns32e1c012016-11-22 17:07:28 +0000665 self.pg_enable_capture(self.pg_interfaces)
666 self.pg_start()
667 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
668
669 self.assertEqual(len(rx), 1)
670 rx = rx[0]
Neale Rannscbe25aa2019-09-30 10:53:31 +0000671 self.validate_ra(intf, rx, dst_ip, src_ip=src_ip, pi_opt=opt)
Neale Ranns32e1c012016-11-22 17:07:28 +0000672
Neale Ranns75152282017-01-09 01:00:45 -0800673 def test_rs(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100674 """ IPv6 Router Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800675
Klement Sekerada505f62017-01-04 12:58:53 +0100676 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800677 """
678
679 #
Klement Sekerada505f62017-01-04 12:58:53 +0100680 # Before we begin change the IPv6 RA responses to use the unicast
681 # address - that way we will not confuse them with the periodic
682 # RAs which go to the mcast address
Neale Ranns32e1c012016-11-22 17:07:28 +0000683 # Sit and wait for the first periodic RA.
684 #
685 # TODO
Neale Ranns75152282017-01-09 01:00:45 -0800686 #
687 self.pg0.ip6_ra_config(send_unicast=1)
688
689 #
690 # An RS from a link source address
691 # - expect an RA in return
692 #
693 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Neale Rannscbe25aa2019-09-30 10:53:31 +0000694 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
Neale Ranns75152282017-01-09 01:00:45 -0800695 ICMPv6ND_RS())
696 pkts = [p]
697 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
698
699 #
700 # For the next RS sent the RA should be rate limited
701 #
702 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
703
704 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700705 # When we reconfigure the IPv6 RA config,
706 # we reset the RA rate limiting,
Klement Sekerada505f62017-01-04 12:58:53 +0100707 # so we need to do this before each test below so as not to drop
708 # packets for rate limiting reasons. Test this works here.
Neale Ranns75152282017-01-09 01:00:45 -0800709 #
710 self.pg0.ip6_ra_config(send_unicast=1)
711 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
712
713 #
714 # An RS sent from a non-link local source
715 #
716 self.pg0.ip6_ra_config(send_unicast=1)
717 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800718 IPv6(dst=self.pg0.local_ip6,
719 src="2002::ffff") /
Neale Ranns75152282017-01-09 01:00:45 -0800720 ICMPv6ND_RS())
721 pkts = [p]
722 self.send_and_assert_no_replies(self.pg0, pkts,
723 "RS from non-link source")
724
725 #
726 # Source an RS from a link local address
727 #
728 self.pg0.ip6_ra_config(send_unicast=1)
729 ll = mk_ll_addr(self.pg0.remote_mac)
730 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
731 IPv6(dst=self.pg0.local_ip6, src=ll) /
732 ICMPv6ND_RS())
733 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000734 self.send_and_expect_ra(self.pg0, pkts,
735 "RS sourced from link-local",
736 dst_ip=ll)
737
738 #
739 # Send the RS multicast
740 #
741 self.pg0.ip6_ra_config(send_unicast=1)
Neale Ranns3f844d02017-02-18 00:03:54 -0800742 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
Neale Ranns32e1c012016-11-22 17:07:28 +0000743 ll = mk_ll_addr(self.pg0.remote_mac)
744 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
745 IPv6(dst="ff02::2", src=ll) /
746 ICMPv6ND_RS())
747 pkts = [p]
748 self.send_and_expect_ra(self.pg0, pkts,
749 "RS sourced from link-local",
750 dst_ip=ll)
Neale Ranns75152282017-01-09 01:00:45 -0800751
752 #
Klement Sekerada505f62017-01-04 12:58:53 +0100753 # Source from the unspecified address ::. This happens when the RS
754 # is sent before the host has a configured address/sub-net,
755 # i.e. auto-config. Since the sender has no IP address, the reply
756 # comes back mcast - so the capture needs to not filter this.
757 # If we happen to pick up the periodic RA at this point then so be it,
758 # it's not an error.
Neale Ranns75152282017-01-09 01:00:45 -0800759 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000760 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
761 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
762 IPv6(dst="ff02::2", src="::") /
Neale Ranns75152282017-01-09 01:00:45 -0800763 ICMPv6ND_RS())
764 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000765 self.send_and_expect_ra(self.pg0, pkts,
766 "RS sourced from unspecified",
767 dst_ip="ff02::1",
768 filter_out_fn=None)
Neale Ranns75152282017-01-09 01:00:45 -0800769
770 #
Neale Ranns87df12d2017-02-18 08:16:41 -0800771 # Configure The RA to announce the links prefix
772 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400773 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
774 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800775
776 #
777 # RAs should now contain the prefix information option
778 #
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800779 opt = ICMPv6NDOptPrefixInfo(
780 prefixlen=self.pg0.local_ip6_prefix_len,
781 prefix=self.pg0.local_ip6,
782 L=1,
783 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800784
785 self.pg0.ip6_ra_config(send_unicast=1)
786 ll = mk_ll_addr(self.pg0.remote_mac)
787 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
788 IPv6(dst=self.pg0.local_ip6, src=ll) /
789 ICMPv6ND_RS())
790 self.send_and_expect_ra(self.pg0, p,
791 "RA with prefix-info",
792 dst_ip=ll,
793 opt=opt)
794
795 #
796 # Change the prefix info to not off-link
797 # L-flag is clear
798 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400799 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
800 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800801 off_link=1)
802
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800803 opt = ICMPv6NDOptPrefixInfo(
804 prefixlen=self.pg0.local_ip6_prefix_len,
805 prefix=self.pg0.local_ip6,
806 L=0,
807 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800808
809 self.pg0.ip6_ra_config(send_unicast=1)
810 self.send_and_expect_ra(self.pg0, p,
811 "RA with Prefix info with L-flag=0",
812 dst_ip=ll,
813 opt=opt)
814
815 #
816 # Change the prefix info to not off-link, no-autoconfig
817 # L and A flag are clear in the advert
818 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400819 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
820 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800821 off_link=1,
822 no_autoconfig=1)
823
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800824 opt = ICMPv6NDOptPrefixInfo(
825 prefixlen=self.pg0.local_ip6_prefix_len,
826 prefix=self.pg0.local_ip6,
827 L=0,
828 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800829
830 self.pg0.ip6_ra_config(send_unicast=1)
831 self.send_and_expect_ra(self.pg0, p,
832 "RA with Prefix info with A & L-flag=0",
833 dst_ip=ll,
834 opt=opt)
835
836 #
837 # Change the flag settings back to the defaults
838 # L and A flag are set in the advert
839 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400840 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
841 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800842
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800843 opt = ICMPv6NDOptPrefixInfo(
844 prefixlen=self.pg0.local_ip6_prefix_len,
845 prefix=self.pg0.local_ip6,
846 L=1,
847 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800848
849 self.pg0.ip6_ra_config(send_unicast=1)
850 self.send_and_expect_ra(self.pg0, p,
851 "RA with Prefix info",
852 dst_ip=ll,
853 opt=opt)
854
855 #
856 # Change the prefix info to not off-link, no-autoconfig
857 # L and A flag are clear in the advert
858 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400859 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
860 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800861 off_link=1,
862 no_autoconfig=1)
863
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800864 opt = ICMPv6NDOptPrefixInfo(
865 prefixlen=self.pg0.local_ip6_prefix_len,
866 prefix=self.pg0.local_ip6,
867 L=0,
868 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800869
870 self.pg0.ip6_ra_config(send_unicast=1)
871 self.send_and_expect_ra(self.pg0, p,
872 "RA with Prefix info with A & L-flag=0",
873 dst_ip=ll,
874 opt=opt)
875
876 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700877 # Use the reset to defaults option to revert to defaults
Neale Ranns87df12d2017-02-18 08:16:41 -0800878 # L and A flag are clear in the advert
879 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400880 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
881 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800882 use_default=1)
883
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800884 opt = ICMPv6NDOptPrefixInfo(
885 prefixlen=self.pg0.local_ip6_prefix_len,
886 prefix=self.pg0.local_ip6,
887 L=1,
888 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800889
890 self.pg0.ip6_ra_config(send_unicast=1)
891 self.send_and_expect_ra(self.pg0, p,
892 "RA with Prefix reverted to defaults",
893 dst_ip=ll,
894 opt=opt)
895
896 #
897 # Advertise Another prefix. With no L-flag/A-flag
898 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400899 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
900 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800901 off_link=1,
902 no_autoconfig=1)
903
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800904 opt = [ICMPv6NDOptPrefixInfo(
905 prefixlen=self.pg0.local_ip6_prefix_len,
906 prefix=self.pg0.local_ip6,
907 L=1,
908 A=1),
909 ICMPv6NDOptPrefixInfo(
910 prefixlen=self.pg1.local_ip6_prefix_len,
911 prefix=self.pg1.local_ip6,
912 L=0,
913 A=0)]
Neale Ranns87df12d2017-02-18 08:16:41 -0800914
915 self.pg0.ip6_ra_config(send_unicast=1)
916 ll = mk_ll_addr(self.pg0.remote_mac)
917 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
918 IPv6(dst=self.pg0.local_ip6, src=ll) /
919 ICMPv6ND_RS())
920 self.send_and_expect_ra(self.pg0, p,
921 "RA with multiple Prefix infos",
922 dst_ip=ll,
923 opt=opt)
924
925 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700926 # Remove the first prefix-info - expect the second is still in the
Neale Ranns87df12d2017-02-18 08:16:41 -0800927 # advert
928 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400929 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
930 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800931 is_no=1)
932
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800933 opt = ICMPv6NDOptPrefixInfo(
934 prefixlen=self.pg1.local_ip6_prefix_len,
935 prefix=self.pg1.local_ip6,
936 L=0,
937 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800938
939 self.pg0.ip6_ra_config(send_unicast=1)
940 self.send_and_expect_ra(self.pg0, p,
941 "RA with Prefix reverted to defaults",
942 dst_ip=ll,
943 opt=opt)
944
945 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700946 # Remove the second prefix-info - expect no prefix-info in the adverts
Neale Ranns87df12d2017-02-18 08:16:41 -0800947 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400948 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
949 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800950 is_no=1)
951
Neale Rannscbe25aa2019-09-30 10:53:31 +0000952 #
953 # change the link's link local, so we know that works too.
954 #
955 self.vapi.sw_interface_ip6_set_link_local_address(
956 sw_if_index=self.pg0.sw_if_index,
957 ip="fe80::88")
958
Neale Ranns87df12d2017-02-18 08:16:41 -0800959 self.pg0.ip6_ra_config(send_unicast=1)
960 self.send_and_expect_ra(self.pg0, p,
961 "RA with Prefix reverted to defaults",
Neale Rannscbe25aa2019-09-30 10:53:31 +0000962 dst_ip=ll,
963 src_ip="fe80::88")
Neale Ranns87df12d2017-02-18 08:16:41 -0800964
965 #
Neale Ranns5737d882017-02-03 06:14:49 -0800966 # Reset the periodic advertisements back to default values
Neale Ranns75152282017-01-09 01:00:45 -0800967 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000968 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200969
Neale Rannsf267d112020-02-07 09:45:07 +0000970 def test_mld(self):
971 """ MLD Report """
972 #
973 # test one MLD is sent after applying an IPv6 Address on an interface
974 #
975 self.pg_enable_capture(self.pg_interfaces)
976 self.pg_start()
977
978 subitf = VppDot1QSubint(self, self.pg1, 99)
979
980 subitf.admin_up()
981 subitf.config_ip6()
982
Neale Ranns03c254e2020-03-17 14:25:10 +0000983 rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None)
Neale Rannsf267d112020-02-07 09:45:07 +0000984
985 #
986 # hunt for the MLD on vlan 99
987 #
988 for rx in rxs:
989 # make sure ipv6 packets with hop by hop options have
990 # correct checksums
991 self.assert_packet_checksums_valid(rx)
992 if rx.haslayer(IPv6ExtHdrHopByHop) and \
993 rx.haslayer(Dot1Q) and \
994 rx[Dot1Q].vlan == 99:
995 mld = rx[ICMPv6MLReport2]
996
997 self.assertEqual(mld.records_number, 4)
998
Neale Ranns3f844d02017-02-18 00:03:54 -0800999
Christian Hoppsf5d38e02020-05-04 10:28:03 -04001000class TestIPv6RouteLookup(VppTestCase):
1001 """ IPv6 Route Lookup Test Case """
1002 routes = []
1003
1004 def route_lookup(self, prefix, exact):
1005 return self.vapi.api(self.vapi.papi.ip_route_lookup,
1006 {
1007 'table_id': 0,
1008 'exact': exact,
1009 'prefix': prefix,
1010 })
1011
1012 @classmethod
1013 def setUpClass(cls):
1014 super(TestIPv6RouteLookup, cls).setUpClass()
1015
1016 @classmethod
1017 def tearDownClass(cls):
1018 super(TestIPv6RouteLookup, cls).tearDownClass()
1019
1020 def setUp(self):
1021 super(TestIPv6RouteLookup, self).setUp()
1022
1023 drop_nh = VppRoutePath("::1", 0xffffffff,
1024 type=FibPathType.FIB_PATH_TYPE_DROP)
1025
1026 # Add 3 routes
1027 r = VppIpRoute(self, "2001:1111::", 32, [drop_nh])
1028 r.add_vpp_config()
1029 self.routes.append(r)
1030
1031 r = VppIpRoute(self, "2001:1111:2222::", 48, [drop_nh])
1032 r.add_vpp_config()
1033 self.routes.append(r)
1034
1035 r = VppIpRoute(self, "2001:1111:2222::1", 128, [drop_nh])
1036 r.add_vpp_config()
1037 self.routes.append(r)
1038
1039 def tearDown(self):
1040 # Remove the routes we added
1041 for r in self.routes:
1042 r.remove_vpp_config()
1043
1044 super(TestIPv6RouteLookup, self).tearDown()
1045
1046 def test_exact_match(self):
1047 # Verify we find the host route
1048 prefix = "2001:1111:2222::1/128"
1049 result = self.route_lookup(prefix, True)
1050 assert (prefix == str(result.route.prefix))
1051
1052 # Verify we find a middle prefix route
1053 prefix = "2001:1111:2222::/48"
1054 result = self.route_lookup(prefix, True)
1055 assert (prefix == str(result.route.prefix))
1056
1057 # Verify we do not find an available LPM.
1058 with self.vapi.assert_negative_api_retval():
1059 self.route_lookup("2001::2/128", True)
1060
1061 def test_longest_prefix_match(self):
1062 # verify we find lpm
1063 lpm_prefix = "2001:1111:2222::/48"
1064 result = self.route_lookup("2001:1111:2222::2/128", False)
1065 assert (lpm_prefix == str(result.route.prefix))
1066
1067 # Verify we find the exact when not requested
1068 result = self.route_lookup(lpm_prefix, False)
1069 assert (lpm_prefix == str(result.route.prefix))
1070
1071 # Can't seem to delete the default route so no negative LPM test.
1072
1073
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001074class TestIPv6IfAddrRoute(VppTestCase):
1075 """ IPv6 Interface Addr Route Test Case """
1076
1077 @classmethod
1078 def setUpClass(cls):
1079 super(TestIPv6IfAddrRoute, cls).setUpClass()
1080
1081 @classmethod
1082 def tearDownClass(cls):
1083 super(TestIPv6IfAddrRoute, cls).tearDownClass()
1084
1085 def setUp(self):
1086 super(TestIPv6IfAddrRoute, self).setUp()
1087
1088 # create 1 pg interface
1089 self.create_pg_interfaces(range(1))
1090
1091 for i in self.pg_interfaces:
1092 i.admin_up()
1093 i.config_ip6()
1094 i.resolve_ndp()
1095
1096 def tearDown(self):
1097 super(TestIPv6IfAddrRoute, self).tearDown()
1098 for i in self.pg_interfaces:
1099 i.unconfig_ip6()
1100 i.admin_down()
1101
1102 def test_ipv6_ifaddrs_same_prefix(self):
1103 """ IPv6 Interface Addresses Same Prefix test
1104
1105 Test scenario:
1106
1107 - Verify no route in FIB for prefix 2001:10::/64
1108 - Configure IPv4 address 2001:10::10/64 on an interface
1109 - Verify route in FIB for prefix 2001:10::/64
1110 - Configure IPv4 address 2001:10::20/64 on an interface
1111 - Delete 2001:10::10/64 from interface
1112 - Verify route in FIB for prefix 2001:10::/64
1113 - Delete 2001:10::20/64 from interface
1114 - Verify no route in FIB for prefix 2001:10::/64
1115 """
1116
1117 addr1 = "2001:10::10"
1118 addr2 = "2001:10::20"
1119
Neale Rannsefd7bc22019-11-11 08:32:34 +00001120 if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64)
1121 if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64)
1122 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001123 self.assertFalse(find_route(self, addr1, 128))
1124 self.assertFalse(find_route(self, addr2, 128))
1125
1126 # configure first address, verify route present
1127 if_addr1.add_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001128 self.assertTrue(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001129 self.assertTrue(find_route(self, addr1, 128))
1130 self.assertFalse(find_route(self, addr2, 128))
1131
1132 # configure second address, delete first, verify route not removed
1133 if_addr2.add_vpp_config()
1134 if_addr1.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001135 self.assertFalse(if_addr1.query_vpp_config())
1136 self.assertTrue(if_addr2.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001137 self.assertFalse(find_route(self, addr1, 128))
1138 self.assertTrue(find_route(self, addr2, 128))
1139
1140 # delete second address, verify route removed
1141 if_addr2.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001142 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001143 self.assertFalse(find_route(self, addr1, 128))
1144 self.assertFalse(find_route(self, addr2, 128))
1145
yedgdbd366b2020-05-14 10:51:53 +08001146 def test_ipv6_ifaddr_del(self):
1147 """ Delete an interface address that does not exist """
1148
1149 loopbacks = self.create_loopback_interfaces(1)
1150 lo = self.lo_interfaces[0]
1151
1152 lo.config_ip6()
1153 lo.admin_up()
1154
1155 #
1156 # try and remove pg0's subnet from lo
1157 #
1158 with self.vapi.assert_negative_api_retval():
1159 self.vapi.sw_interface_add_del_address(
1160 sw_if_index=lo.sw_if_index,
1161 prefix=self.pg0.local_ip6_prefix,
1162 is_add=0)
1163
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001164
Jan Geletye6c78ee2018-06-26 12:24:03 +02001165class TestICMPv6Echo(VppTestCase):
1166 """ ICMPv6 Echo Test Case """
1167
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001168 @classmethod
1169 def setUpClass(cls):
1170 super(TestICMPv6Echo, cls).setUpClass()
1171
1172 @classmethod
1173 def tearDownClass(cls):
1174 super(TestICMPv6Echo, cls).tearDownClass()
1175
Jan Geletye6c78ee2018-06-26 12:24:03 +02001176 def setUp(self):
1177 super(TestICMPv6Echo, self).setUp()
1178
1179 # create 1 pg interface
1180 self.create_pg_interfaces(range(1))
1181
1182 for i in self.pg_interfaces:
1183 i.admin_up()
1184 i.config_ip6()
Benoît Ganne2699fe22021-01-18 19:25:38 +01001185 i.resolve_ndp(link_layer=True)
Jan Geletye6c78ee2018-06-26 12:24:03 +02001186 i.resolve_ndp()
1187
1188 def tearDown(self):
1189 super(TestICMPv6Echo, self).tearDown()
1190 for i in self.pg_interfaces:
1191 i.unconfig_ip6()
Jan Geletye6c78ee2018-06-26 12:24:03 +02001192 i.admin_down()
1193
1194 def test_icmpv6_echo(self):
1195 """ VPP replies to ICMPv6 Echo Request
1196
1197 Test scenario:
1198
1199 - Receive ICMPv6 Echo Request message on pg0 interface.
1200 - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
1201 """
1202
Benoît Ganne2699fe22021-01-18 19:25:38 +01001203 # test both with global and local ipv6 addresses
1204 dsts = (self.pg0.local_ip6, self.pg0.local_ip6_ll)
1205 id = 0xb
1206 seq = 5
1207 data = b'\x0a' * 18
1208 p = list()
1209 for dst in dsts:
1210 p.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
1211 IPv6(src=self.pg0.remote_ip6, dst=dst) /
1212 ICMPv6EchoRequest(id=id, seq=seq, data=data)))
Jan Geletye6c78ee2018-06-26 12:24:03 +02001213
Benoît Ganne2699fe22021-01-18 19:25:38 +01001214 self.pg0.add_stream(p)
Jan Geletye6c78ee2018-06-26 12:24:03 +02001215 self.pg_enable_capture(self.pg_interfaces)
1216 self.pg_start()
Benoît Ganne2699fe22021-01-18 19:25:38 +01001217 rxs = self.pg0.get_capture(len(dsts))
Jan Geletye6c78ee2018-06-26 12:24:03 +02001218
Benoît Ganne2699fe22021-01-18 19:25:38 +01001219 for rx, dst in zip(rxs, dsts):
1220 ether = rx[Ether]
1221 ipv6 = rx[IPv6]
1222 icmpv6 = rx[ICMPv6EchoReply]
1223 self.assertEqual(ether.src, self.pg0.local_mac)
1224 self.assertEqual(ether.dst, self.pg0.remote_mac)
1225 self.assertEqual(ipv6.src, dst)
1226 self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1227 self.assertEqual(icmp6types[icmpv6.type], "Echo Reply")
1228 self.assertEqual(icmpv6.id, id)
1229 self.assertEqual(icmpv6.seq, seq)
1230 self.assertEqual(icmpv6.data, data)
Jan Geletye6c78ee2018-06-26 12:24:03 +02001231
1232
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001233class TestIPv6RD(TestIPv6ND):
1234 """ IPv6 Router Discovery Test Case """
1235
1236 @classmethod
1237 def setUpClass(cls):
1238 super(TestIPv6RD, cls).setUpClass()
1239
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001240 @classmethod
1241 def tearDownClass(cls):
1242 super(TestIPv6RD, cls).tearDownClass()
1243
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001244 def setUp(self):
1245 super(TestIPv6RD, self).setUp()
1246
1247 # create 2 pg interfaces
1248 self.create_pg_interfaces(range(2))
1249
1250 self.interfaces = list(self.pg_interfaces)
1251
1252 # setup all interfaces
1253 for i in self.interfaces:
1254 i.admin_up()
1255 i.config_ip6()
1256
1257 def tearDown(self):
Neale Ranns744902e2017-08-14 10:35:44 -07001258 for i in self.interfaces:
1259 i.unconfig_ip6()
1260 i.admin_down()
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001261 super(TestIPv6RD, self).tearDown()
1262
1263 def test_rd_send_router_solicitation(self):
1264 """ Verify router solicitation packets """
1265
1266 count = 2
1267 self.pg_enable_capture(self.pg_interfaces)
1268 self.pg_start()
1269 self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1270 mrc=count)
1271 rx_list = self.pg1.get_capture(count, timeout=3)
1272 self.assertEqual(len(rx_list), count)
1273 for packet in rx_list:
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001274 self.assertEqual(packet.haslayer(IPv6), 1)
1275 self.assertEqual(packet[IPv6].haslayer(
1276 ICMPv6ND_RS), 1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001277 dst = ip6_normalize(packet[IPv6].dst)
1278 dst2 = ip6_normalize("ff02::2")
1279 self.assert_equal(dst, dst2)
1280 src = ip6_normalize(packet[IPv6].src)
1281 src2 = ip6_normalize(self.pg1.local_ip6_ll)
1282 self.assert_equal(src, src2)
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001283 self.assertTrue(
1284 bool(packet[ICMPv6ND_RS].haslayer(
1285 ICMPv6NDOptSrcLLAddr)))
1286 self.assert_equal(
1287 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1288 self.pg1.local_mac)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001289
1290 def verify_prefix_info(self, reported_prefix, prefix_option):
Neale Ranns37029302018-08-10 05:30:06 -07001291 prefix = IPv6Network(
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -08001292 text_type(prefix_option.getfieldval("prefix") +
1293 "/" +
1294 text_type(prefix_option.getfieldval("prefixlen"))),
Neale Ranns37029302018-08-10 05:30:06 -07001295 strict=False)
1296 self.assert_equal(reported_prefix.prefix.network_address,
1297 prefix.network_address)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001298 L = prefix_option.getfieldval("L")
1299 A = prefix_option.getfieldval("A")
1300 option_flags = (L << 7) | (A << 6)
1301 self.assert_equal(reported_prefix.flags, option_flags)
1302 self.assert_equal(reported_prefix.valid_time,
1303 prefix_option.getfieldval("validlifetime"))
1304 self.assert_equal(reported_prefix.preferred_time,
1305 prefix_option.getfieldval("preferredlifetime"))
1306
1307 def test_rd_receive_router_advertisement(self):
1308 """ Verify events triggered by received RA packets """
1309
Neale Rannscbe25aa2019-09-30 10:53:31 +00001310 self.vapi.want_ip6_ra_events(enable=1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001311
1312 prefix_info_1 = ICMPv6NDOptPrefixInfo(
1313 prefix="1::2",
1314 prefixlen=50,
1315 validlifetime=200,
1316 preferredlifetime=500,
1317 L=1,
1318 A=1,
1319 )
1320
1321 prefix_info_2 = ICMPv6NDOptPrefixInfo(
1322 prefix="7::4",
1323 prefixlen=20,
1324 validlifetime=70,
1325 preferredlifetime=1000,
1326 L=1,
1327 A=0,
1328 )
1329
1330 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1331 IPv6(dst=self.pg1.local_ip6_ll,
1332 src=mk_ll_addr(self.pg1.remote_mac)) /
1333 ICMPv6ND_RA() /
1334 prefix_info_1 /
1335 prefix_info_2)
1336 self.pg1.add_stream([p])
1337 self.pg_start()
1338
1339 ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1340
1341 self.assert_equal(ev.current_hop_limit, 0)
1342 self.assert_equal(ev.flags, 8)
1343 self.assert_equal(ev.router_lifetime_in_sec, 1800)
1344 self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1345 self.assert_equal(
1346 ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1347
1348 self.assert_equal(ev.n_prefixes, 2)
1349
1350 self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1351 self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1352
1353
Juraj Slobodac0374232018-02-01 15:18:49 +01001354class TestIPv6RDControlPlane(TestIPv6ND):
1355 """ IPv6 Router Discovery Control Plane Test Case """
1356
1357 @classmethod
1358 def setUpClass(cls):
1359 super(TestIPv6RDControlPlane, cls).setUpClass()
1360
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001361 @classmethod
1362 def tearDownClass(cls):
1363 super(TestIPv6RDControlPlane, cls).tearDownClass()
1364
Juraj Slobodac0374232018-02-01 15:18:49 +01001365 def setUp(self):
1366 super(TestIPv6RDControlPlane, self).setUp()
1367
1368 # create 1 pg interface
1369 self.create_pg_interfaces(range(1))
1370
1371 self.interfaces = list(self.pg_interfaces)
1372
1373 # setup all interfaces
1374 for i in self.interfaces:
1375 i.admin_up()
1376 i.config_ip6()
1377
1378 def tearDown(self):
1379 super(TestIPv6RDControlPlane, self).tearDown()
1380
1381 @staticmethod
1382 def create_ra_packet(pg, routerlifetime=None):
1383 src_ip = pg.remote_ip6_ll
1384 dst_ip = pg.local_ip6
1385 if routerlifetime is not None:
1386 ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1387 else:
1388 ra = ICMPv6ND_RA()
1389 p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1390 IPv6(dst=dst_ip, src=src_ip) / ra)
1391 return p
1392
1393 @staticmethod
1394 def get_default_routes(fib):
1395 list = []
1396 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001397 if entry.route.prefix.prefixlen == 0:
1398 for path in entry.route.paths:
Juraj Slobodac0374232018-02-01 15:18:49 +01001399 if path.sw_if_index != 0xFFFFFFFF:
Neale Ranns097fa662018-05-01 05:17:55 -07001400 defaut_route = {}
1401 defaut_route['sw_if_index'] = path.sw_if_index
1402 defaut_route['next_hop'] = path.nh.address.ip6
1403 list.append(defaut_route)
Juraj Slobodac0374232018-02-01 15:18:49 +01001404 return list
1405
1406 @staticmethod
1407 def get_interface_addresses(fib, pg):
1408 list = []
1409 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001410 if entry.route.prefix.prefixlen == 128:
1411 path = entry.route.paths[0]
Juraj Slobodac0374232018-02-01 15:18:49 +01001412 if path.sw_if_index == pg.sw_if_index:
Neale Ranns097fa662018-05-01 05:17:55 -07001413 list.append(str(entry.route.prefix.network_address))
Juraj Slobodac0374232018-02-01 15:18:49 +01001414 return list
1415
Neale Rannscbe25aa2019-09-30 10:53:31 +00001416 def wait_for_no_default_route(self, n_tries=50, s_time=1):
1417 while (n_tries):
1418 fib = self.vapi.ip_route_dump(0, True)
1419 default_routes = self.get_default_routes(fib)
Ole Troan6e6ad642020-02-04 13:28:13 +01001420 if 0 == len(default_routes):
Neale Rannscbe25aa2019-09-30 10:53:31 +00001421 return True
1422 n_tries = n_tries - 1
1423 self.sleep(s_time)
1424
1425 return False
1426
Juraj Slobodac0374232018-02-01 15:18:49 +01001427 def test_all(self):
1428 """ Test handling of SLAAC addresses and default routes """
1429
Neale Ranns097fa662018-05-01 05:17:55 -07001430 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001431 default_routes = self.get_default_routes(fib)
1432 initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1433 self.assertEqual(default_routes, [])
Neale Ranns097fa662018-05-01 05:17:55 -07001434 router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll))
Juraj Slobodac0374232018-02-01 15:18:49 +01001435
1436 self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1437
1438 self.sleep(0.1)
1439
1440 # send RA
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001441 packet = (self.create_ra_packet(
1442 self.pg0) / ICMPv6NDOptPrefixInfo(
Juraj Slobodac0374232018-02-01 15:18:49 +01001443 prefix="1::",
1444 prefixlen=64,
1445 validlifetime=2,
1446 preferredlifetime=2,
1447 L=1,
1448 A=1,
1449 ) / ICMPv6NDOptPrefixInfo(
1450 prefix="7::",
1451 prefixlen=20,
1452 validlifetime=1500,
1453 preferredlifetime=1000,
1454 L=1,
1455 A=0,
1456 ))
1457 self.pg0.add_stream([packet])
1458 self.pg_start()
1459
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001460 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001461
Neale Ranns097fa662018-05-01 05:17:55 -07001462 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001463
1464 # check FIB for new address
1465 addresses = set(self.get_interface_addresses(fib, self.pg0))
1466 new_addresses = addresses.difference(initial_addresses)
1467 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001468 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1469 strict=False)
1470 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001471
1472 # check FIB for new default route
1473 default_routes = self.get_default_routes(fib)
1474 self.assertEqual(len(default_routes), 1)
1475 dr = default_routes[0]
1476 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1477 self.assertEqual(dr['next_hop'], router_address)
1478
1479 # send RA to delete default route
1480 packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1481 self.pg0.add_stream([packet])
1482 self.pg_start()
1483
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001484 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001485
1486 # check that default route is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001487 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001488 default_routes = self.get_default_routes(fib)
1489 self.assertEqual(len(default_routes), 0)
1490
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001491 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001492
1493 # send RA
1494 packet = self.create_ra_packet(self.pg0)
1495 self.pg0.add_stream([packet])
1496 self.pg_start()
1497
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001498 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001499
1500 # check FIB for new default route
Neale Ranns097fa662018-05-01 05:17:55 -07001501 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001502 default_routes = self.get_default_routes(fib)
1503 self.assertEqual(len(default_routes), 1)
1504 dr = default_routes[0]
1505 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1506 self.assertEqual(dr['next_hop'], router_address)
1507
1508 # send RA, updating router lifetime to 1s
1509 packet = self.create_ra_packet(self.pg0, 1)
1510 self.pg0.add_stream([packet])
1511 self.pg_start()
1512
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001513 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001514
1515 # check that default route still exists
Neale Ranns097fa662018-05-01 05:17:55 -07001516 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001517 default_routes = self.get_default_routes(fib)
1518 self.assertEqual(len(default_routes), 1)
1519 dr = default_routes[0]
1520 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1521 self.assertEqual(dr['next_hop'], router_address)
1522
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001523 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001524
1525 # check that default route is deleted
Neale Rannscbe25aa2019-09-30 10:53:31 +00001526 self.assertTrue(self.wait_for_no_default_route())
Juraj Slobodac0374232018-02-01 15:18:49 +01001527
1528 # check FIB still contains the SLAAC address
1529 addresses = set(self.get_interface_addresses(fib, self.pg0))
1530 new_addresses = addresses.difference(initial_addresses)
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001531
Juraj Slobodac0374232018-02-01 15:18:49 +01001532 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001533 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1534 strict=False)
1535 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001536
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001537 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001538
1539 # check that SLAAC address is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001540 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001541 addresses = set(self.get_interface_addresses(fib, self.pg0))
1542 new_addresses = addresses.difference(initial_addresses)
1543 self.assertEqual(len(new_addresses), 0)
1544
1545
Neale Ranns3f844d02017-02-18 00:03:54 -08001546class IPv6NDProxyTest(TestIPv6ND):
1547 """ IPv6 ND ProxyTest Case """
1548
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001549 @classmethod
1550 def setUpClass(cls):
1551 super(IPv6NDProxyTest, cls).setUpClass()
1552
1553 @classmethod
1554 def tearDownClass(cls):
1555 super(IPv6NDProxyTest, cls).tearDownClass()
1556
Neale Ranns3f844d02017-02-18 00:03:54 -08001557 def setUp(self):
1558 super(IPv6NDProxyTest, self).setUp()
1559
1560 # create 3 pg interfaces
1561 self.create_pg_interfaces(range(3))
1562
1563 # pg0 is the master interface, with the configured subnet
1564 self.pg0.admin_up()
1565 self.pg0.config_ip6()
1566 self.pg0.resolve_ndp()
1567
1568 self.pg1.ip6_enable()
1569 self.pg2.ip6_enable()
1570
1571 def tearDown(self):
1572 super(IPv6NDProxyTest, self).tearDown()
1573
1574 def test_nd_proxy(self):
1575 """ IPv6 Proxy ND """
1576
1577 #
1578 # Generate some hosts in the subnet that we are proxying
1579 #
1580 self.pg0.generate_remote_hosts(8)
1581
1582 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1583 d = inet_ntop(AF_INET6, nsma)
1584
1585 #
1586 # Send an NS for one of those remote hosts on one of the proxy links
1587 # expect no response since it's from an address that is not
1588 # on the link that has the prefix configured
1589 #
1590 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001591 IPv6(dst=d,
1592 src=self.pg0._remote_hosts[2].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001593 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001594 ICMPv6NDOptSrcLLAddr(
1595 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001596
1597 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1598
1599 #
1600 # Add proxy support for the host
1601 #
Ole Troane1ade682019-03-04 23:55:43 +01001602 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001603 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001604 sw_if_index=self.pg1.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001605
1606 #
1607 # try that NS again. this time we expect an NA back
1608 #
Neale Ranns2a3ea492017-04-19 05:24:40 -07001609 self.send_and_expect_na(self.pg1, ns_pg1,
1610 "NS to proxy entry",
1611 dst_ip=self.pg0._remote_hosts[2].ip6,
1612 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001613
1614 #
1615 # ... and that we have an entry in the ND cache
1616 #
1617 self.assertTrue(find_nbr(self,
1618 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001619 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001620
1621 #
1622 # ... and we can route traffic to it
1623 #
1624 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1625 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1626 src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001627 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001628 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001629
1630 self.pg0.add_stream(t)
1631 self.pg_enable_capture(self.pg_interfaces)
1632 self.pg_start()
1633 rx = self.pg1.get_capture(1)
1634 rx = rx[0]
1635
1636 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1637 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1638
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001639 self.assertEqual(rx[IPv6].src,
1640 t[IPv6].src)
1641 self.assertEqual(rx[IPv6].dst,
1642 t[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001643
1644 #
1645 # Test we proxy for the host on the main interface
1646 #
1647 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1648 IPv6(dst=d, src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001649 ICMPv6ND_NS(
1650 tgt=self.pg0._remote_hosts[2].ip6) /
1651 ICMPv6NDOptSrcLLAddr(
1652 lladdr=self.pg0.remote_mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001653
Neale Ranns2a3ea492017-04-19 05:24:40 -07001654 self.send_and_expect_na(self.pg0, ns_pg0,
1655 "NS to proxy entry on main",
1656 tgt_ip=self.pg0._remote_hosts[2].ip6,
1657 dst_ip=self.pg0.remote_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001658
1659 #
1660 # Setup and resolve proxy for another host on another interface
1661 #
1662 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001663 IPv6(dst=d,
1664 src=self.pg0._remote_hosts[3].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001665 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001666 ICMPv6NDOptSrcLLAddr(
1667 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001668
Ole Troane1ade682019-03-04 23:55:43 +01001669 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001670 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001671 sw_if_index=self.pg2.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001672
Neale Ranns2a3ea492017-04-19 05:24:40 -07001673 self.send_and_expect_na(self.pg2, ns_pg2,
1674 "NS to proxy entry other interface",
1675 dst_ip=self.pg0._remote_hosts[3].ip6,
1676 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001677
1678 self.assertTrue(find_nbr(self,
1679 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001680 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001681
1682 #
1683 # hosts can communicate. pg2->pg1
1684 #
1685 t2 = (Ether(dst=self.pg2.local_mac,
1686 src=self.pg0.remote_hosts[3].mac) /
1687 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1688 src=self.pg0._remote_hosts[3].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001689 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001690 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001691
1692 self.pg2.add_stream(t2)
1693 self.pg_enable_capture(self.pg_interfaces)
1694 self.pg_start()
1695 rx = self.pg1.get_capture(1)
1696 rx = rx[0]
1697
1698 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1699 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1700
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001701 self.assertEqual(rx[IPv6].src,
1702 t2[IPv6].src)
1703 self.assertEqual(rx[IPv6].dst,
1704 t2[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001705
1706 #
1707 # remove the proxy configs
1708 #
Ole Troane1ade682019-03-04 23:55:43 +01001709 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001710 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001711 sw_if_index=self.pg1.sw_if_index, is_add=0)
Ole Troane1ade682019-03-04 23:55:43 +01001712 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001713 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001714 sw_if_index=self.pg2.sw_if_index, is_add=0)
Neale Ranns3f844d02017-02-18 00:03:54 -08001715
1716 self.assertFalse(find_nbr(self,
1717 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001718 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001719 self.assertFalse(find_nbr(self,
1720 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001721 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001722
1723 #
1724 # no longer proxy-ing...
1725 #
1726 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1727 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1728 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1729
1730 #
1731 # no longer forwarding. traffic generates NS out of the glean/main
1732 # interface
1733 #
1734 self.pg2.add_stream(t2)
1735 self.pg_enable_capture(self.pg_interfaces)
1736 self.pg_start()
1737
1738 rx = self.pg0.get_capture(1)
1739
1740 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1741
1742
Neale Ranns37be7362017-02-21 17:30:26 -08001743class TestIPNull(VppTestCase):
1744 """ IPv6 routes via NULL """
1745
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001746 @classmethod
1747 def setUpClass(cls):
1748 super(TestIPNull, cls).setUpClass()
1749
1750 @classmethod
1751 def tearDownClass(cls):
1752 super(TestIPNull, cls).tearDownClass()
1753
Neale Ranns37be7362017-02-21 17:30:26 -08001754 def setUp(self):
1755 super(TestIPNull, self).setUp()
1756
1757 # create 2 pg interfaces
1758 self.create_pg_interfaces(range(1))
1759
1760 for i in self.pg_interfaces:
1761 i.admin_up()
1762 i.config_ip6()
1763 i.resolve_ndp()
1764
1765 def tearDown(self):
1766 super(TestIPNull, self).tearDown()
1767 for i in self.pg_interfaces:
1768 i.unconfig_ip6()
1769 i.admin_down()
1770
1771 def test_ip_null(self):
1772 """ IP NULL route """
1773
1774 p = (Ether(src=self.pg0.remote_mac,
1775 dst=self.pg0.local_mac) /
1776 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001777 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001778 Raw(b'\xa5' * 100))
Neale Ranns37be7362017-02-21 17:30:26 -08001779
1780 #
1781 # A route via IP NULL that will reply with ICMP unreachables
1782 #
Neale Ranns097fa662018-05-01 05:17:55 -07001783 ip_unreach = VppIpRoute(
1784 self, "2001::", 64,
1785 [VppRoutePath("::", 0xffffffff,
1786 type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)])
Neale Ranns37be7362017-02-21 17:30:26 -08001787 ip_unreach.add_vpp_config()
1788
1789 self.pg0.add_stream(p)
1790 self.pg_enable_capture(self.pg_interfaces)
1791 self.pg_start()
1792
1793 rx = self.pg0.get_capture(1)
1794 rx = rx[0]
1795 icmp = rx[ICMPv6DestUnreach]
1796
1797 # 0 = "No route to destination"
1798 self.assertEqual(icmp.code, 0)
1799
1800 # ICMP is rate limited. pause a bit
1801 self.sleep(1)
1802
1803 #
1804 # A route via IP NULL that will reply with ICMP prohibited
1805 #
Neale Ranns097fa662018-05-01 05:17:55 -07001806 ip_prohibit = VppIpRoute(
1807 self, "2001::1", 128,
1808 [VppRoutePath("::", 0xffffffff,
1809 type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)])
Neale Ranns37be7362017-02-21 17:30:26 -08001810 ip_prohibit.add_vpp_config()
1811
1812 self.pg0.add_stream(p)
1813 self.pg_enable_capture(self.pg_interfaces)
1814 self.pg_start()
1815
1816 rx = self.pg0.get_capture(1)
1817 rx = rx[0]
1818 icmp = rx[ICMPv6DestUnreach]
1819
1820 # 1 = "Communication with destination administratively prohibited"
1821 self.assertEqual(icmp.code, 1)
1822
1823
Neale Ranns180279b2017-03-16 15:49:09 -04001824class TestIPDisabled(VppTestCase):
1825 """ IPv6 disabled """
1826
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001827 @classmethod
1828 def setUpClass(cls):
1829 super(TestIPDisabled, cls).setUpClass()
1830
1831 @classmethod
1832 def tearDownClass(cls):
1833 super(TestIPDisabled, cls).tearDownClass()
1834
Neale Ranns180279b2017-03-16 15:49:09 -04001835 def setUp(self):
1836 super(TestIPDisabled, self).setUp()
1837
1838 # create 2 pg interfaces
1839 self.create_pg_interfaces(range(2))
1840
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001841 # PG0 is IP enabled
Neale Ranns180279b2017-03-16 15:49:09 -04001842 self.pg0.admin_up()
1843 self.pg0.config_ip6()
1844 self.pg0.resolve_ndp()
1845
1846 # PG 1 is not IP enabled
1847 self.pg1.admin_up()
1848
1849 def tearDown(self):
1850 super(TestIPDisabled, self).tearDown()
1851 for i in self.pg_interfaces:
1852 i.unconfig_ip4()
1853 i.admin_down()
1854
Neale Ranns180279b2017-03-16 15:49:09 -04001855 def test_ip_disabled(self):
1856 """ IP Disabled """
1857
Neale Ranns990f6942020-10-20 07:20:17 +00001858 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
1859 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
Neale Ranns180279b2017-03-16 15:49:09 -04001860 #
1861 # An (S,G).
1862 # one accepting interface, pg0, 2 forwarding interfaces
1863 #
1864 route_ff_01 = VppIpMRoute(
1865 self,
1866 "::",
1867 "ffef::1", 128,
Neale Ranns990f6942020-10-20 07:20:17 +00001868 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
Neale Ranns180279b2017-03-16 15:49:09 -04001869 [VppMRoutePath(self.pg1.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00001870 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
Neale Ranns180279b2017-03-16 15:49:09 -04001871 VppMRoutePath(self.pg0.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00001872 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
Neale Ranns180279b2017-03-16 15:49:09 -04001873 route_ff_01.add_vpp_config()
1874
1875 pu = (Ether(src=self.pg1.remote_mac,
1876 dst=self.pg1.local_mac) /
1877 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001878 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001879 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001880 pm = (Ether(src=self.pg1.remote_mac,
1881 dst=self.pg1.local_mac) /
1882 IPv6(src="2001::1", dst="ffef::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001883 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001884 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001885
1886 #
1887 # PG1 does not forward IP traffic
1888 #
1889 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1890 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1891
1892 #
1893 # IP enable PG1
1894 #
1895 self.pg1.config_ip6()
1896
1897 #
1898 # Now we get packets through
1899 #
1900 self.pg1.add_stream(pu)
1901 self.pg_enable_capture(self.pg_interfaces)
1902 self.pg_start()
1903 rx = self.pg0.get_capture(1)
1904
1905 self.pg1.add_stream(pm)
1906 self.pg_enable_capture(self.pg_interfaces)
1907 self.pg_start()
1908 rx = self.pg0.get_capture(1)
1909
1910 #
1911 # Disable PG1
1912 #
1913 self.pg1.unconfig_ip6()
1914
1915 #
1916 # PG1 does not forward IP traffic
1917 #
1918 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1919 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1920
1921
Neale Ranns227038a2017-04-21 01:07:59 -07001922class TestIP6LoadBalance(VppTestCase):
1923 """ IPv6 Load-Balancing """
1924
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001925 @classmethod
1926 def setUpClass(cls):
1927 super(TestIP6LoadBalance, cls).setUpClass()
1928
1929 @classmethod
1930 def tearDownClass(cls):
1931 super(TestIP6LoadBalance, cls).tearDownClass()
1932
Neale Ranns227038a2017-04-21 01:07:59 -07001933 def setUp(self):
1934 super(TestIP6LoadBalance, self).setUp()
1935
1936 self.create_pg_interfaces(range(5))
1937
Neale Ranns15002542017-09-10 04:39:11 -07001938 mpls_tbl = VppMplsTable(self, 0)
1939 mpls_tbl.add_vpp_config()
1940
Neale Ranns227038a2017-04-21 01:07:59 -07001941 for i in self.pg_interfaces:
1942 i.admin_up()
1943 i.config_ip6()
1944 i.resolve_ndp()
Neale Ranns71275e32017-05-25 12:38:58 -07001945 i.enable_mpls()
Neale Ranns227038a2017-04-21 01:07:59 -07001946
1947 def tearDown(self):
Neale Ranns227038a2017-04-21 01:07:59 -07001948 for i in self.pg_interfaces:
1949 i.unconfig_ip6()
1950 i.admin_down()
Neale Ranns71275e32017-05-25 12:38:58 -07001951 i.disable_mpls()
Neale Ranns15002542017-09-10 04:39:11 -07001952 super(TestIP6LoadBalance, self).tearDown()
Neale Ranns227038a2017-04-21 01:07:59 -07001953
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001954 def pg_send(self, input, pkts):
Neale Ranns62fe07c2017-10-31 12:28:22 -07001955 self.vapi.cli("clear trace")
Neale Ranns227038a2017-04-21 01:07:59 -07001956 input.add_stream(pkts)
1957 self.pg_enable_capture(self.pg_interfaces)
1958 self.pg_start()
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001959
1960 def send_and_expect_load_balancing(self, input, pkts, outputs):
1961 self.pg_send(input, pkts)
Neale Ranns3d5f08a2021-01-22 16:12:38 +00001962 rxs = []
Neale Ranns227038a2017-04-21 01:07:59 -07001963 for oo in outputs:
1964 rx = oo._get_capture(1)
1965 self.assertNotEqual(0, len(rx))
Neale Ranns3d5f08a2021-01-22 16:12:38 +00001966 rxs.append(rx)
1967 return rxs
Neale Ranns227038a2017-04-21 01:07:59 -07001968
Neale Ranns71275e32017-05-25 12:38:58 -07001969 def send_and_expect_one_itf(self, input, pkts, itf):
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001970 self.pg_send(input, pkts)
Neale Ranns71275e32017-05-25 12:38:58 -07001971 rx = itf.get_capture(len(pkts))
1972
Neale Ranns227038a2017-04-21 01:07:59 -07001973 def test_ip6_load_balance(self):
1974 """ IPv6 Load-Balancing """
1975
1976 #
1977 # An array of packets that differ only in the destination port
Neale Ranns71275e32017-05-25 12:38:58 -07001978 # - IP only
1979 # - MPLS EOS
1980 # - MPLS non-EOS
1981 # - MPLS non-EOS with an entropy label
Neale Ranns227038a2017-04-21 01:07:59 -07001982 #
Neale Ranns71275e32017-05-25 12:38:58 -07001983 port_ip_pkts = []
1984 port_mpls_pkts = []
1985 port_mpls_neos_pkts = []
1986 port_ent_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001987
1988 #
1989 # An array of packets that differ only in the source address
1990 #
Neale Ranns71275e32017-05-25 12:38:58 -07001991 src_ip_pkts = []
1992 src_mpls_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001993
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001994 for ii in range(NUM_PKTS):
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001995 port_ip_hdr = (
1996 IPv6(dst="3000::1", src="3000:1::1") /
1997 inet6.UDP(sport=1234, dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01001998 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001999 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
2000 dst=self.pg0.local_mac) /
2001 port_ip_hdr))
2002 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
2003 dst=self.pg0.local_mac) /
2004 MPLS(label=66, ttl=2) /
2005 port_ip_hdr))
2006 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
2007 dst=self.pg0.local_mac) /
2008 MPLS(label=67, ttl=2) /
2009 MPLS(label=77, ttl=2) /
2010 port_ip_hdr))
2011 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
2012 dst=self.pg0.local_mac) /
2013 MPLS(label=67, ttl=2) /
2014 MPLS(label=14, ttl=2) /
2015 MPLS(label=999, ttl=2) /
2016 port_ip_hdr))
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002017 src_ip_hdr = (
2018 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
2019 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002020 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07002021 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
2022 dst=self.pg0.local_mac) /
2023 src_ip_hdr))
2024 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
2025 dst=self.pg0.local_mac) /
2026 MPLS(label=66, ttl=2) /
2027 src_ip_hdr))
Neale Ranns227038a2017-04-21 01:07:59 -07002028
Neale Ranns71275e32017-05-25 12:38:58 -07002029 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002030 # A route for the IP packets
Neale Ranns71275e32017-05-25 12:38:58 -07002031 #
Neale Ranns227038a2017-04-21 01:07:59 -07002032 route_3000_1 = VppIpRoute(self, "3000::1", 128,
2033 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002034 self.pg1.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002035 VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002036 self.pg2.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002037 route_3000_1.add_vpp_config()
2038
2039 #
Neale Ranns71275e32017-05-25 12:38:58 -07002040 # a local-label for the EOS packets
2041 #
2042 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
2043 binding.add_vpp_config()
2044
2045 #
2046 # An MPLS route for the non-EOS packets
2047 #
2048 route_67 = VppMplsRoute(self, 67, 0,
2049 [VppRoutePath(self.pg1.remote_ip6,
2050 self.pg1.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07002051 labels=[67]),
Neale Ranns71275e32017-05-25 12:38:58 -07002052 VppRoutePath(self.pg2.remote_ip6,
2053 self.pg2.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07002054 labels=[67])])
Neale Ranns71275e32017-05-25 12:38:58 -07002055 route_67.add_vpp_config()
2056
2057 #
Neale Ranns227038a2017-04-21 01:07:59 -07002058 # inject the packet on pg0 - expect load-balancing across the 2 paths
2059 # - since the default hash config is to use IP src,dst and port
2060 # src,dst
2061 # We are not going to ensure equal amounts of packets across each link,
2062 # since the hash algorithm is statistical and therefore this can never
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002063 # be guaranteed. But with 64 different packets we do expect some
Neale Ranns227038a2017-04-21 01:07:59 -07002064 # balancing. So instead just ensure there is traffic on each link.
2065 #
Neale Ranns3d5f08a2021-01-22 16:12:38 +00002066 rx = self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
2067 [self.pg1, self.pg2])
2068 n_ip_pg0 = len(rx[0])
Neale Ranns71275e32017-05-25 12:38:58 -07002069 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002070 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002071 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
2072 [self.pg1, self.pg2])
2073 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2074 [self.pg1, self.pg2])
Neale Ranns3d5f08a2021-01-22 16:12:38 +00002075 rx = self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
2076 [self.pg1, self.pg2])
2077 n_mpls_pg0 = len(rx[0])
2078
2079 #
2080 # change the router ID and expect the distribution changes
2081 #
2082 self.vapi.set_ip_flow_hash_router_id(router_id=0x11111111)
2083
2084 rx = self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
2085 [self.pg1, self.pg2])
2086 self.assertNotEqual(n_ip_pg0, len(rx[0]))
2087
2088 rx = self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2089 [self.pg1, self.pg2])
2090 self.assertNotEqual(n_mpls_pg0, len(rx[0]))
Neale Ranns71275e32017-05-25 12:38:58 -07002091
2092 #
2093 # The packets with Entropy label in should not load-balance,
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002094 # since the Entropy value is fixed.
Neale Ranns71275e32017-05-25 12:38:58 -07002095 #
2096 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
Neale Ranns227038a2017-04-21 01:07:59 -07002097
2098 #
2099 # change the flow hash config so it's only IP src,dst
2100 # - now only the stream with differing source address will
2101 # load-balance
2102 #
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002103 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, proto=1,
2104 sport=0, dport=0, is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07002105
Neale Ranns71275e32017-05-25 12:38:58 -07002106 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002107 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002108 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2109 [self.pg1, self.pg2])
2110 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
Neale Ranns227038a2017-04-21 01:07:59 -07002111
2112 #
2113 # change the flow hash config back to defaults
2114 #
Ole Troana5b2eec2019-03-11 19:23:25 +01002115 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1,
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002116 proto=1, is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07002117
2118 #
2119 # Recursive prefixes
2120 # - testing that 2 stages of load-balancing occurs and there is no
2121 # polarisation (i.e. only 2 of 4 paths are used)
2122 #
2123 port_pkts = []
2124 src_pkts = []
2125
2126 for ii in range(257):
2127 port_pkts.append((Ether(src=self.pg0.remote_mac,
2128 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002129 IPv6(dst="4000::1",
2130 src="4000:1::1") /
2131 inet6.UDP(sport=1234,
2132 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002133 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002134 src_pkts.append((Ether(src=self.pg0.remote_mac,
2135 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002136 IPv6(dst="4000::1",
2137 src="4000:1::%d" % ii) /
2138 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002139 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002140
2141 route_3000_2 = VppIpRoute(self, "3000::2", 128,
2142 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002143 self.pg3.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002144 VppRoutePath(self.pg4.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002145 self.pg4.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002146 route_3000_2.add_vpp_config()
2147
2148 route_4000_1 = VppIpRoute(self, "4000::1", 128,
2149 [VppRoutePath("3000::1",
Neale Ranns097fa662018-05-01 05:17:55 -07002150 0xffffffff),
Neale Ranns227038a2017-04-21 01:07:59 -07002151 VppRoutePath("3000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002152 0xffffffff)])
Neale Ranns227038a2017-04-21 01:07:59 -07002153 route_4000_1.add_vpp_config()
2154
2155 #
2156 # inject the packet on pg0 - expect load-balancing across all 4 paths
2157 #
2158 self.vapi.cli("clear trace")
2159 self.send_and_expect_load_balancing(self.pg0, port_pkts,
2160 [self.pg1, self.pg2,
2161 self.pg3, self.pg4])
2162 self.send_and_expect_load_balancing(self.pg0, src_pkts,
2163 [self.pg1, self.pg2,
2164 self.pg3, self.pg4])
2165
Neale Ranns42e6b092017-07-31 02:56:03 -07002166 #
2167 # Recursive prefixes
2168 # - testing that 2 stages of load-balancing no choices
2169 #
2170 port_pkts = []
2171
2172 for ii in range(257):
2173 port_pkts.append((Ether(src=self.pg0.remote_mac,
2174 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002175 IPv6(dst="6000::1",
2176 src="6000:1::1") /
2177 inet6.UDP(sport=1234,
2178 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002179 Raw(b'\xa5' * 100)))
Neale Ranns42e6b092017-07-31 02:56:03 -07002180
2181 route_5000_2 = VppIpRoute(self, "5000::2", 128,
2182 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002183 self.pg3.sw_if_index)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002184 route_5000_2.add_vpp_config()
2185
2186 route_6000_1 = VppIpRoute(self, "6000::1", 128,
2187 [VppRoutePath("5000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002188 0xffffffff)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002189 route_6000_1.add_vpp_config()
2190
2191 #
2192 # inject the packet on pg0 - expect load-balancing across all 4 paths
2193 #
2194 self.vapi.cli("clear trace")
2195 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
2196
Neale Ranns227038a2017-04-21 01:07:59 -07002197
Brian Russella1f36062021-01-19 16:58:14 +00002198class IP6PuntSetup(object):
2199 """ Setup for IPv6 Punt Police/Redirect """
Neale Rannsd91c1db2017-07-31 02:30:50 -07002200
Brian Russella1f36062021-01-19 16:58:14 +00002201 def punt_setup(self):
Pavel Kotucek609e1212018-11-27 09:59:44 +01002202 self.create_pg_interfaces(range(4))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002203
2204 for i in self.pg_interfaces:
2205 i.admin_up()
2206 i.config_ip6()
2207 i.resolve_ndp()
2208
Brian Russella1f36062021-01-19 16:58:14 +00002209 self.pkt = (Ether(src=self.pg0.remote_mac,
2210 dst=self.pg0.local_mac) /
2211 IPv6(src=self.pg0.remote_ip6,
2212 dst=self.pg0.local_ip6) /
2213 inet6.TCP(sport=1234, dport=1234) /
2214 Raw(b'\xa5' * 100))
2215
2216 def punt_teardown(self):
Neale Rannsd91c1db2017-07-31 02:30:50 -07002217 for i in self.pg_interfaces:
2218 i.unconfig_ip6()
2219 i.admin_down()
2220
Brian Russella1f36062021-01-19 16:58:14 +00002221
2222class TestIP6Punt(IP6PuntSetup, VppTestCase):
2223 """ IPv6 Punt Police/Redirect """
2224
2225 def setUp(self):
2226 super(TestIP6Punt, self).setUp()
2227 super(TestIP6Punt, self).punt_setup()
2228
2229 def tearDown(self):
2230 super(TestIP6Punt, self).punt_teardown()
2231 super(TestIP6Punt, self).tearDown()
2232
Neale Rannsd91c1db2017-07-31 02:30:50 -07002233 def test_ip_punt(self):
2234 """ IP6 punt police and redirect """
2235
Brian Russella1f36062021-01-19 16:58:14 +00002236 pkts = self.pkt * 1025
Neale Rannsd91c1db2017-07-31 02:30:50 -07002237
2238 #
2239 # Configure a punt redirect via pg1.
2240 #
Ole Troan0bcad322018-12-11 13:04:01 +01002241 nh_addr = self.pg1.remote_ip6
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002242 ip_punt_redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index,
2243 self.pg1.sw_if_index, nh_addr)
2244 ip_punt_redirect.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002245
2246 self.send_and_expect(self.pg0, pkts, self.pg1)
2247
2248 #
2249 # add a policer
2250 #
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002251 policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1)
2252 policer.add_vpp_config()
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002253 ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index,
2254 is_ip6=True)
2255 ip_punt_policer.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002256
2257 self.vapi.cli("clear trace")
2258 self.pg0.add_stream(pkts)
2259 self.pg_enable_capture(self.pg_interfaces)
2260 self.pg_start()
2261
2262 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002263 # the number of packet received should be greater than 0,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002264 # but not equal to the number sent, since some were policed
2265 #
2266 rx = self.pg1._get_capture(1)
Brian Russelle9887262021-01-27 14:45:22 +00002267 stats = policer.get_stats()
2268
2269 # Single rate policer - expect conform, violate but no exceed
2270 self.assertGreater(stats['conform_packets'], 0)
2271 self.assertEqual(stats['exceed_packets'], 0)
2272 self.assertGreater(stats['violate_packets'], 0)
2273
Paul Vinciguerra3d2df212018-11-24 23:19:53 -08002274 self.assertGreater(len(rx), 0)
2275 self.assertLess(len(rx), len(pkts))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002276
2277 #
Paul Vinciguerraeb414432019-02-20 09:01:14 -08002278 # remove the policer. back to full rx
Neale Rannsd91c1db2017-07-31 02:30:50 -07002279 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002280 ip_punt_policer.remove_vpp_config()
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002281 policer.remove_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002282 self.send_and_expect(self.pg0, pkts, self.pg1)
2283
2284 #
2285 # remove the redirect. expect full drop.
2286 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002287 ip_punt_redirect.remove_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002288 self.send_and_assert_no_replies(self.pg0, pkts,
2289 "IP no punt config")
2290
2291 #
2292 # Add a redirect that is not input port selective
2293 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002294 ip_punt_redirect = VppIpPuntRedirect(self, 0xffffffff,
2295 self.pg1.sw_if_index, nh_addr)
2296 ip_punt_redirect.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002297 self.send_and_expect(self.pg0, pkts, self.pg1)
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002298 ip_punt_redirect.remove_vpp_config()
Pavel Kotucek609e1212018-11-27 09:59:44 +01002299
2300 def test_ip_punt_dump(self):
2301 """ IP6 punt redirect dump"""
2302
2303 #
2304 # Configure a punt redirects
2305 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002306 nh_address = self.pg3.remote_ip6
2307 ipr_03 = VppIpPuntRedirect(self, self.pg0.sw_if_index,
2308 self.pg3.sw_if_index, nh_address)
2309 ipr_13 = VppIpPuntRedirect(self, self.pg1.sw_if_index,
2310 self.pg3.sw_if_index, nh_address)
2311 ipr_23 = VppIpPuntRedirect(self, self.pg2.sw_if_index,
2312 self.pg3.sw_if_index, '0::0')
2313 ipr_03.add_vpp_config()
2314 ipr_13.add_vpp_config()
2315 ipr_23.add_vpp_config()
Pavel Kotucek609e1212018-11-27 09:59:44 +01002316
2317 #
2318 # Dump pg0 punt redirects
2319 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002320 self.assertTrue(ipr_03.query_vpp_config())
2321 self.assertTrue(ipr_13.query_vpp_config())
2322 self.assertTrue(ipr_23.query_vpp_config())
Pavel Kotucek609e1212018-11-27 09:59:44 +01002323
2324 #
2325 # Dump punt redirects for all interfaces
2326 #
2327 punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2328 self.assertEqual(len(punts), 3)
2329 for p in punts:
2330 self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
Ole Troan0bcad322018-12-11 13:04:01 +01002331 self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2332 self.assertEqual(str(punts[2].punt.nh), '::')
Neale Rannsd91c1db2017-07-31 02:30:50 -07002333
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002334
Brian Russell5214f3a2021-01-19 16:58:34 +00002335class TestIP6PuntHandoff(IP6PuntSetup, VppTestCase):
2336 """ IPv6 Punt Police/Redirect """
Klement Sekera8d815022021-03-15 16:58:10 +01002337 vpp_worker_count = 2
Brian Russell5214f3a2021-01-19 16:58:34 +00002338
2339 def setUp(self):
2340 super(TestIP6PuntHandoff, self).setUp()
2341 super(TestIP6PuntHandoff, self).punt_setup()
2342
2343 def tearDown(self):
2344 super(TestIP6PuntHandoff, self).punt_teardown()
2345 super(TestIP6PuntHandoff, self).tearDown()
2346
2347 def test_ip_punt(self):
2348 """ IP6 punt policer thread handoff """
2349 pkts = self.pkt * NUM_PKTS
2350
2351 #
2352 # Configure a punt redirect via pg1.
2353 #
2354 nh_addr = self.pg1.remote_ip6
2355 ip_punt_redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index,
2356 self.pg1.sw_if_index, nh_addr)
2357 ip_punt_redirect.add_vpp_config()
2358
2359 action_tx = PolicerAction(
2360 VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT,
2361 0)
2362 #
2363 # This policer drops no packets, we are just
2364 # testing that they get to the right thread.
2365 #
2366 policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, 1,
2367 0, 0, False, action_tx, action_tx, action_tx)
2368 policer.add_vpp_config()
2369 ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index,
2370 is_ip6=True)
2371 ip_punt_policer.add_vpp_config()
2372
2373 for worker in [0, 1]:
2374 self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker)
2375 if worker == 0:
2376 self.logger.debug(self.vapi.cli("show trace max 100"))
2377
Brian Russelle9887262021-01-27 14:45:22 +00002378 # Combined stats, all threads
2379 stats = policer.get_stats()
2380
2381 # Single rate policer - expect conform, violate but no exceed
2382 self.assertGreater(stats['conform_packets'], 0)
2383 self.assertEqual(stats['exceed_packets'], 0)
2384 self.assertGreater(stats['violate_packets'], 0)
2385
2386 # Worker 0, should have done all the policing
2387 stats0 = policer.get_stats(worker=0)
2388 self.assertEqual(stats, stats0)
2389
2390 # Worker 1, should have handed everything off
2391 stats1 = policer.get_stats(worker=1)
2392 self.assertEqual(stats1['conform_packets'], 0)
2393 self.assertEqual(stats1['exceed_packets'], 0)
2394 self.assertEqual(stats1['violate_packets'], 0)
2395
Brian Russellbb983142021-02-10 13:56:06 +00002396 # Bind the policer to worker 1 and repeat
2397 policer.bind_vpp_config(1, True)
2398 for worker in [0, 1]:
2399 self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker)
2400 self.logger.debug(self.vapi.cli("show trace max 100"))
2401
2402 # The 2 workers should now have policed the same amount
2403 stats = policer.get_stats()
2404 stats0 = policer.get_stats(worker=0)
2405 stats1 = policer.get_stats(worker=1)
2406
2407 self.assertGreater(stats0['conform_packets'], 0)
2408 self.assertEqual(stats0['exceed_packets'], 0)
2409 self.assertGreater(stats0['violate_packets'], 0)
2410
2411 self.assertGreater(stats1['conform_packets'], 0)
2412 self.assertEqual(stats1['exceed_packets'], 0)
2413 self.assertGreater(stats1['violate_packets'], 0)
2414
2415 self.assertEqual(stats0['conform_packets'] + stats1['conform_packets'],
2416 stats['conform_packets'])
2417
2418 self.assertEqual(stats0['violate_packets'] + stats1['violate_packets'],
2419 stats['violate_packets'])
2420
2421 # Unbind the policer and repeat
2422 policer.bind_vpp_config(1, False)
2423 for worker in [0, 1]:
2424 self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker)
2425 self.logger.debug(self.vapi.cli("show trace max 100"))
2426
2427 # The policer should auto-bind to worker 0 when packets arrive
2428 stats = policer.get_stats()
2429 stats0new = policer.get_stats(worker=0)
2430 stats1new = policer.get_stats(worker=1)
2431
2432 self.assertGreater(stats0new['conform_packets'],
2433 stats0['conform_packets'])
2434 self.assertEqual(stats0new['exceed_packets'], 0)
2435 self.assertGreater(stats0new['violate_packets'],
2436 stats0['violate_packets'])
2437
2438 self.assertEqual(stats1, stats1new)
2439
Brian Russell5214f3a2021-01-19 16:58:34 +00002440 #
2441 # Clean up
2442 #
2443 ip_punt_policer.remove_vpp_config()
2444 policer.remove_vpp_config()
2445 ip_punt_redirect.remove_vpp_config()
2446
2447
Neale Rannsce9e0b42018-08-01 12:53:17 -07002448class TestIPDeag(VppTestCase):
2449 """ IPv6 Deaggregate Routes """
2450
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002451 @classmethod
2452 def setUpClass(cls):
2453 super(TestIPDeag, cls).setUpClass()
2454
2455 @classmethod
2456 def tearDownClass(cls):
2457 super(TestIPDeag, cls).tearDownClass()
2458
Neale Rannsce9e0b42018-08-01 12:53:17 -07002459 def setUp(self):
2460 super(TestIPDeag, self).setUp()
2461
2462 self.create_pg_interfaces(range(3))
2463
2464 for i in self.pg_interfaces:
2465 i.admin_up()
2466 i.config_ip6()
2467 i.resolve_ndp()
2468
2469 def tearDown(self):
2470 super(TestIPDeag, self).tearDown()
2471 for i in self.pg_interfaces:
2472 i.unconfig_ip6()
2473 i.admin_down()
2474
2475 def test_ip_deag(self):
2476 """ IP Deag Routes """
2477
2478 #
2479 # Create a table to be used for:
2480 # 1 - another destination address lookup
2481 # 2 - a source address lookup
2482 #
2483 table_dst = VppIpTable(self, 1, is_ip6=1)
2484 table_src = VppIpTable(self, 2, is_ip6=1)
2485 table_dst.add_vpp_config()
2486 table_src.add_vpp_config()
2487
2488 #
2489 # Add a route in the default table to point to a deag/
2490 # second lookup in each of these tables
2491 #
2492 route_to_dst = VppIpRoute(self, "1::1", 128,
2493 [VppRoutePath("::",
2494 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -07002495 nh_table_id=1)])
2496 route_to_src = VppIpRoute(
2497 self, "1::2", 128,
2498 [VppRoutePath("::",
2499 0xffffffff,
2500 nh_table_id=2,
2501 type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)])
2502
Neale Rannsce9e0b42018-08-01 12:53:17 -07002503 route_to_dst.add_vpp_config()
2504 route_to_src.add_vpp_config()
2505
2506 #
2507 # packets to these destination are dropped, since they'll
2508 # hit the respective default routes in the second table
2509 #
2510 p_dst = (Ether(src=self.pg0.remote_mac,
2511 dst=self.pg0.local_mac) /
2512 IPv6(src="5::5", dst="1::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002513 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002514 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002515 p_src = (Ether(src=self.pg0.remote_mac,
2516 dst=self.pg0.local_mac) /
2517 IPv6(src="2::2", dst="1::2") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002518 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002519 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002520 pkts_dst = p_dst * 257
2521 pkts_src = p_src * 257
2522
2523 self.send_and_assert_no_replies(self.pg0, pkts_dst,
2524 "IP in dst table")
2525 self.send_and_assert_no_replies(self.pg0, pkts_src,
2526 "IP in src table")
2527
2528 #
2529 # add a route in the dst table to forward via pg1
2530 #
2531 route_in_dst = VppIpRoute(self, "1::1", 128,
2532 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002533 self.pg1.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002534 table_id=1)
2535 route_in_dst.add_vpp_config()
2536
2537 self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2538
2539 #
2540 # add a route in the src table to forward via pg2
2541 #
2542 route_in_src = VppIpRoute(self, "2::2", 128,
2543 [VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002544 self.pg2.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002545 table_id=2)
2546 route_in_src.add_vpp_config()
2547 self.send_and_expect(self.pg0, pkts_src, self.pg2)
2548
2549 #
2550 # loop in the lookup DP
2551 #
2552 route_loop = VppIpRoute(self, "3::3", 128,
2553 [VppRoutePath("::",
Neale Ranns097fa662018-05-01 05:17:55 -07002554 0xffffffff)])
Neale Rannsce9e0b42018-08-01 12:53:17 -07002555 route_loop.add_vpp_config()
2556
2557 p_l = (Ether(src=self.pg0.remote_mac,
2558 dst=self.pg0.local_mac) /
2559 IPv6(src="3::4", dst="3::3") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002560 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002561 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002562
2563 self.send_and_assert_no_replies(self.pg0, p_l * 257,
2564 "IP lookup loop")
2565
2566
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002567class TestIP6Input(VppTestCase):
Neale Rannsae809832018-11-23 09:00:27 -08002568 """ IPv6 Input Exception Test Cases """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002569
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002570 @classmethod
2571 def setUpClass(cls):
2572 super(TestIP6Input, cls).setUpClass()
2573
2574 @classmethod
2575 def tearDownClass(cls):
2576 super(TestIP6Input, cls).tearDownClass()
2577
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002578 def setUp(self):
2579 super(TestIP6Input, self).setUp()
2580
2581 self.create_pg_interfaces(range(2))
2582
2583 for i in self.pg_interfaces:
2584 i.admin_up()
2585 i.config_ip6()
2586 i.resolve_ndp()
2587
2588 def tearDown(self):
2589 super(TestIP6Input, self).tearDown()
2590 for i in self.pg_interfaces:
2591 i.unconfig_ip6()
2592 i.admin_down()
2593
Neale Rannsae809832018-11-23 09:00:27 -08002594 def test_ip_input_icmp_reply(self):
2595 """ IP6 Input Exception - Return ICMP (3,0) """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002596 #
Neale Rannsae809832018-11-23 09:00:27 -08002597 # hop limit - ICMP replies
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002598 #
2599 p_version = (Ether(src=self.pg0.remote_mac,
2600 dst=self.pg0.local_mac) /
2601 IPv6(src=self.pg0.remote_ip6,
2602 dst=self.pg1.remote_ip6,
2603 hlim=1) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002604 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002605 Raw(b'\xa5' * 100))
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002606
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002607 rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002608 rx = rx[0]
2609 icmp = rx[ICMPv6TimeExceeded]
Neale Rannsae809832018-11-23 09:00:27 -08002610
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002611 # 0: "hop limit exceeded in transit",
Neale Rannsae809832018-11-23 09:00:27 -08002612 self.assertEqual((icmp.type, icmp.code), (3, 0))
2613
2614 icmpv6_data = '\x0a' * 18
2615 all_0s = "::"
2616 all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2617
2618 @parameterized.expand([
2619 # Name, src, dst, l4proto, msg, timeout
2620 ("src='iface', dst='iface'", None, None,
2621 inet6.UDP(sport=1234, dport=1234), "funky version", None),
2622 ("src='All 0's', dst='iface'", all_0s, None,
2623 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2624 ("src='iface', dst='All 0's'", None, all_0s,
2625 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2626 ("src='All 1's', dst='iface'", all_1s, None,
2627 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2628 ("src='iface', dst='All 1's'", None, all_1s,
2629 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2630 ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2631 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2632
2633 ])
2634 def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2635
2636 self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2637
2638 p_version = (Ether(src=self.pg0.remote_mac,
2639 dst=self.pg0.local_mac) /
2640 IPv6(src=src or self.pg0.remote_ip6,
2641 dst=dst or self.pg1.remote_ip6,
2642 version=3) /
2643 l4 /
Ole Troan770a0de2019-11-07 13:52:21 +01002644 Raw(b'\xa5' * 100))
Neale Rannsae809832018-11-23 09:00:27 -08002645
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002646 self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS,
Neale Rannsae809832018-11-23 09:00:27 -08002647 remark=msg or "",
2648 timeout=timeout)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002649
Dave Barach90800962019-05-24 13:03:01 -04002650 def test_hop_by_hop(self):
2651 """ Hop-by-hop header test """
2652
2653 p = (Ether(src=self.pg0.remote_mac,
2654 dst=self.pg0.local_mac) /
2655 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
2656 IPv6ExtHdrHopByHop() /
2657 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002658 Raw(b'\xa5' * 100))
Dave Barach90800962019-05-24 13:03:01 -04002659
2660 self.pg0.add_stream(p)
2661 self.pg_enable_capture(self.pg_interfaces)
2662 self.pg_start()
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002663
Neale Ranns9db6ada2019-11-08 12:42:31 +00002664
2665class TestIPReplace(VppTestCase):
2666 """ IPv6 Table Replace """
2667
2668 @classmethod
2669 def setUpClass(cls):
2670 super(TestIPReplace, cls).setUpClass()
2671
2672 @classmethod
2673 def tearDownClass(cls):
2674 super(TestIPReplace, cls).tearDownClass()
2675
2676 def setUp(self):
2677 super(TestIPReplace, self).setUp()
2678
2679 self.create_pg_interfaces(range(4))
2680
2681 table_id = 1
2682 self.tables = []
2683
2684 for i in self.pg_interfaces:
2685 i.admin_up()
2686 i.config_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002687 i.generate_remote_hosts(2)
2688 self.tables.append(VppIpTable(self, table_id,
2689 True).add_vpp_config())
2690 table_id += 1
2691
2692 def tearDown(self):
2693 super(TestIPReplace, self).tearDown()
2694 for i in self.pg_interfaces:
2695 i.admin_down()
Neale Rannsec40a7d2020-04-23 07:36:12 +00002696 i.unconfig_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002697
2698 def test_replace(self):
2699 """ IP Table Replace """
2700
Neale Ranns990f6942020-10-20 07:20:17 +00002701 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
2702 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
Neale Ranns9db6ada2019-11-08 12:42:31 +00002703 N_ROUTES = 20
2704 links = [self.pg0, self.pg1, self.pg2, self.pg3]
2705 routes = [[], [], [], []]
2706
2707 # the sizes of 'empty' tables
2708 for t in self.tables:
2709 self.assertEqual(len(t.dump()), 2)
2710 self.assertEqual(len(t.mdump()), 5)
2711
2712 # load up the tables with some routes
2713 for ii, t in enumerate(self.tables):
2714 for jj in range(1, N_ROUTES):
2715 uni = VppIpRoute(
2716 self, "2001::%d" % jj if jj != 0 else "2001::", 128,
2717 [VppRoutePath(links[ii].remote_hosts[0].ip6,
2718 links[ii].sw_if_index),
2719 VppRoutePath(links[ii].remote_hosts[1].ip6,
2720 links[ii].sw_if_index)],
2721 table_id=t.table_id).add_vpp_config()
2722 multi = VppIpMRoute(
2723 self, "::",
2724 "ff:2001::%d" % jj, 128,
Neale Ranns990f6942020-10-20 07:20:17 +00002725 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002726 [VppMRoutePath(self.pg0.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002727 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002728 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2729 VppMRoutePath(self.pg1.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002730 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002731 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2732 VppMRoutePath(self.pg2.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002733 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002734 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2735 VppMRoutePath(self.pg3.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002736 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002737 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
2738 table_id=t.table_id).add_vpp_config()
2739 routes[ii].append({'uni': uni,
2740 'multi': multi})
2741
2742 #
2743 # replace the tables a few times
2744 #
2745 for kk in range(3):
2746 # replace each table
2747 for t in self.tables:
2748 t.replace_begin()
2749
2750 # all the routes are still there
2751 for ii, t in enumerate(self.tables):
2752 dump = t.dump()
2753 mdump = t.mdump()
2754 for r in routes[ii]:
2755 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2756 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2757
2758 # redownload the even numbered routes
2759 for ii, t in enumerate(self.tables):
2760 for jj in range(0, N_ROUTES, 2):
2761 routes[ii][jj]['uni'].add_vpp_config()
2762 routes[ii][jj]['multi'].add_vpp_config()
2763
2764 # signal each table converged
2765 for t in self.tables:
2766 t.replace_end()
2767
2768 # we should find the even routes, but not the odd
2769 for ii, t in enumerate(self.tables):
2770 dump = t.dump()
2771 mdump = t.mdump()
2772 for jj in range(0, N_ROUTES, 2):
2773 self.assertTrue(find_route_in_dump(
2774 dump, routes[ii][jj]['uni'], t))
2775 self.assertTrue(find_mroute_in_dump(
2776 mdump, routes[ii][jj]['multi'], t))
2777 for jj in range(1, N_ROUTES - 1, 2):
2778 self.assertFalse(find_route_in_dump(
2779 dump, routes[ii][jj]['uni'], t))
2780 self.assertFalse(find_mroute_in_dump(
2781 mdump, routes[ii][jj]['multi'], t))
2782
2783 # reload all the routes
2784 for ii, t in enumerate(self.tables):
2785 for r in routes[ii]:
2786 r['uni'].add_vpp_config()
2787 r['multi'].add_vpp_config()
2788
2789 # all the routes are still there
2790 for ii, t in enumerate(self.tables):
2791 dump = t.dump()
2792 mdump = t.mdump()
2793 for r in routes[ii]:
2794 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2795 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2796
2797 #
2798 # finally flush the tables for good measure
2799 #
2800 for t in self.tables:
2801 t.flush()
2802 self.assertEqual(len(t.dump()), 2)
2803 self.assertEqual(len(t.mdump()), 5)
2804
2805
Neale Ranns59f71132020-04-08 12:19:38 +00002806class TestIP6Replace(VppTestCase):
2807 """ IPv4 Interface Address Replace """
2808
2809 @classmethod
2810 def setUpClass(cls):
2811 super(TestIP6Replace, cls).setUpClass()
2812
2813 @classmethod
2814 def tearDownClass(cls):
2815 super(TestIP6Replace, cls).tearDownClass()
2816
2817 def setUp(self):
2818 super(TestIP6Replace, self).setUp()
2819
2820 self.create_pg_interfaces(range(4))
2821
2822 for i in self.pg_interfaces:
2823 i.admin_up()
2824
2825 def tearDown(self):
2826 super(TestIP6Replace, self).tearDown()
2827 for i in self.pg_interfaces:
2828 i.admin_down()
2829
2830 def get_n_pfxs(self, intf):
2831 return len(self.vapi.ip_address_dump(intf.sw_if_index, True))
2832
2833 def test_replace(self):
2834 """ IP interface address replace """
2835
2836 intf_pfxs = [[], [], [], []]
2837
2838 # add prefixes to each of the interfaces
2839 for i in range(len(self.pg_interfaces)):
2840 intf = self.pg_interfaces[i]
2841
2842 # 2001:16:x::1/64
2843 addr = "2001:16:%d::1" % intf.sw_if_index
2844 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2845 intf_pfxs[i].append(a)
2846
2847 # 2001:16:x::2/64 - a different address in the same subnet as above
2848 addr = "2001:16:%d::2" % intf.sw_if_index
2849 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2850 intf_pfxs[i].append(a)
2851
2852 # 2001:15:x::2/64 - a different address and subnet
2853 addr = "2001:15:%d::2" % intf.sw_if_index
2854 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2855 intf_pfxs[i].append(a)
2856
2857 # a dump should n_address in it
2858 for intf in self.pg_interfaces:
2859 self.assertEqual(self.get_n_pfxs(intf), 3)
2860
2861 #
2862 # remove all the address thru a replace
2863 #
2864 self.vapi.sw_interface_address_replace_begin()
2865 self.vapi.sw_interface_address_replace_end()
2866 for intf in self.pg_interfaces:
2867 self.assertEqual(self.get_n_pfxs(intf), 0)
2868
2869 #
2870 # add all the interface addresses back
2871 #
2872 for p in intf_pfxs:
2873 for v in p:
2874 v.add_vpp_config()
2875 for intf in self.pg_interfaces:
2876 self.assertEqual(self.get_n_pfxs(intf), 3)
2877
2878 #
2879 # replace again, but this time update/re-add the address on the first
2880 # two interfaces
2881 #
2882 self.vapi.sw_interface_address_replace_begin()
2883
2884 for p in intf_pfxs[:2]:
2885 for v in p:
2886 v.add_vpp_config()
2887
2888 self.vapi.sw_interface_address_replace_end()
2889
2890 # on the first two the address still exist,
2891 # on the other two they do not
2892 for intf in self.pg_interfaces[:2]:
2893 self.assertEqual(self.get_n_pfxs(intf), 3)
2894 for p in intf_pfxs[:2]:
2895 for v in p:
2896 self.assertTrue(v.query_vpp_config())
2897 for intf in self.pg_interfaces[2:]:
2898 self.assertEqual(self.get_n_pfxs(intf), 0)
2899
2900 #
2901 # add all the interface addresses back on the last two
2902 #
2903 for p in intf_pfxs[2:]:
2904 for v in p:
2905 v.add_vpp_config()
2906 for intf in self.pg_interfaces:
2907 self.assertEqual(self.get_n_pfxs(intf), 3)
2908
2909 #
2910 # replace again, this time add different prefixes on all the interfaces
2911 #
2912 self.vapi.sw_interface_address_replace_begin()
2913
2914 pfxs = []
2915 for intf in self.pg_interfaces:
2916 # 2001:18:x::1/64
2917 addr = "2001:18:%d::1" % intf.sw_if_index
2918 pfxs.append(VppIpInterfaceAddress(self, intf, addr,
2919 64).add_vpp_config())
2920
2921 self.vapi.sw_interface_address_replace_end()
2922
2923 # only .18 should exist on each interface
2924 for intf in self.pg_interfaces:
2925 self.assertEqual(self.get_n_pfxs(intf), 1)
2926 for pfx in pfxs:
2927 self.assertTrue(pfx.query_vpp_config())
2928
2929 #
2930 # remove everything
2931 #
2932 self.vapi.sw_interface_address_replace_begin()
2933 self.vapi.sw_interface_address_replace_end()
2934 for intf in self.pg_interfaces:
2935 self.assertEqual(self.get_n_pfxs(intf), 0)
2936
2937 #
2938 # add prefixes to each interface. post-begin add the prefix from
2939 # interface X onto interface Y. this would normally be an error
2940 # since it would generate a 'duplicate address' warning. but in
2941 # this case, since what is newly downloaded is sane, it's ok
2942 #
2943 for intf in self.pg_interfaces:
2944 # 2001:18:x::1/64
2945 addr = "2001:18:%d::1" % intf.sw_if_index
2946 VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2947
2948 self.vapi.sw_interface_address_replace_begin()
2949
2950 pfxs = []
2951 for intf in self.pg_interfaces:
2952 # 2001:18:x::1/64
2953 addr = "2001:18:%d::1" % (intf.sw_if_index + 1)
2954 pfxs.append(VppIpInterfaceAddress(self, intf,
2955 addr, 64).add_vpp_config())
2956
2957 self.vapi.sw_interface_address_replace_end()
2958
2959 self.logger.info(self.vapi.cli("sh int addr"))
2960
2961 for intf in self.pg_interfaces:
2962 self.assertEqual(self.get_n_pfxs(intf), 1)
2963 for pfx in pfxs:
2964 self.assertTrue(pfx.query_vpp_config())
2965
2966
Neale Rannsec40a7d2020-04-23 07:36:12 +00002967class TestIP6LinkLocal(VppTestCase):
2968 """ IPv6 Link Local """
2969
2970 @classmethod
2971 def setUpClass(cls):
2972 super(TestIP6LinkLocal, cls).setUpClass()
2973
2974 @classmethod
2975 def tearDownClass(cls):
2976 super(TestIP6LinkLocal, cls).tearDownClass()
2977
2978 def setUp(self):
2979 super(TestIP6LinkLocal, self).setUp()
2980
2981 self.create_pg_interfaces(range(2))
2982
2983 for i in self.pg_interfaces:
2984 i.admin_up()
2985
2986 def tearDown(self):
2987 super(TestIP6LinkLocal, self).tearDown()
2988 for i in self.pg_interfaces:
2989 i.admin_down()
2990
2991 def test_ip6_ll(self):
2992 """ IPv6 Link Local """
2993
2994 #
2995 # two APIs to add a link local address.
2996 # 1 - just like any other prefix
2997 # 2 - with the special set LL API
2998 #
2999
3000 #
3001 # First with the API to set a 'normal' prefix
3002 #
3003 ll1 = "fe80:1::1"
3004 ll2 = "fe80:2::2"
3005 ll3 = "fe80:3::3"
3006
Neale Rannsdfef64b2021-05-20 16:28:12 +00003007 VppNeighbor(self,
3008 self.pg0.sw_if_index,
3009 self.pg0.remote_mac,
3010 ll2).add_vpp_config()
3011
Neale Rannsec40a7d2020-04-23 07:36:12 +00003012 VppIpInterfaceAddress(self, self.pg0, ll1, 128).add_vpp_config()
3013
3014 #
3015 # should be able to ping the ll
3016 #
3017 p_echo_request_1 = (Ether(src=self.pg0.remote_mac,
3018 dst=self.pg0.local_mac) /
3019 IPv6(src=ll2,
3020 dst=ll1) /
3021 ICMPv6EchoRequest())
3022
3023 self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0)
3024
3025 #
3026 # change the link-local on pg0
3027 #
3028 v_ll3 = VppIpInterfaceAddress(self, self.pg0,
3029 ll3, 128).add_vpp_config()
3030
3031 p_echo_request_3 = (Ether(src=self.pg0.remote_mac,
3032 dst=self.pg0.local_mac) /
3033 IPv6(src=ll2,
3034 dst=ll3) /
3035 ICMPv6EchoRequest())
3036
3037 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
3038
3039 #
3040 # set a normal v6 prefix on the link
3041 #
3042 self.pg0.config_ip6()
3043
3044 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
3045
3046 # the link-local cannot be removed
3047 with self.vapi.assert_negative_api_retval():
3048 v_ll3.remove_vpp_config()
3049
3050 #
3051 # Use the specific link-local API on pg1
3052 #
3053 VppIp6LinkLocalAddress(self, self.pg1, ll1).add_vpp_config()
3054 self.send_and_expect(self.pg1, [p_echo_request_1], self.pg1)
3055
3056 VppIp6LinkLocalAddress(self, self.pg1, ll3).add_vpp_config()
3057 self.send_and_expect(self.pg1, [p_echo_request_3], self.pg1)
3058
Neale Rannsdfef64b2021-05-20 16:28:12 +00003059 def test_ip6_ll_p2p(self):
3060 """ IPv6 Link Local P2P (GRE)"""
3061
3062 self.pg0.config_ip4()
3063 self.pg0.resolve_arp()
3064 gre_if = VppGreInterface(self,
3065 self.pg0.local_ip4,
3066 self.pg0.remote_ip4).add_vpp_config()
3067 gre_if.admin_up()
3068
3069 ll1 = "fe80:1::1"
3070 ll2 = "fe80:2::2"
3071
3072 VppIpInterfaceAddress(self, gre_if, ll1, 128).add_vpp_config()
3073
3074 self.logger.info(self.vapi.cli("sh ip6-ll gre0 fe80:2::2"))
3075
3076 p_echo_request_1 = (Ether(src=self.pg0.remote_mac,
3077 dst=self.pg0.local_mac) /
3078 IP(src=self.pg0.remote_ip4,
3079 dst=self.pg0.local_ip4) /
3080 GRE() /
3081 IPv6(src=ll2, dst=ll1) /
3082 ICMPv6EchoRequest())
3083 self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0)
3084
3085 self.pg0.unconfig_ip4()
3086 gre_if.remove_vpp_config()
3087
3088 def test_ip6_ll_p2mp(self):
3089 """ IPv6 Link Local P2MP (GRE)"""
3090
3091 self.pg0.config_ip4()
3092 self.pg0.resolve_arp()
3093
3094 gre_if = VppGreInterface(
3095 self,
3096 self.pg0.local_ip4,
3097 "0.0.0.0",
3098 mode=(VppEnum.vl_api_tunnel_mode_t.
3099 TUNNEL_API_MODE_MP)).add_vpp_config()
3100 gre_if.admin_up()
3101
3102 ll1 = "fe80:1::1"
3103 ll2 = "fe80:2::2"
3104
3105 VppIpInterfaceAddress(self, gre_if, ll1, 128).add_vpp_config()
3106
3107 p_echo_request_1 = (Ether(src=self.pg0.remote_mac,
3108 dst=self.pg0.local_mac) /
3109 IP(src=self.pg0.remote_ip4,
3110 dst=self.pg0.local_ip4) /
3111 GRE() /
3112 IPv6(src=ll2, dst=ll1) /
3113 ICMPv6EchoRequest())
3114
3115 # no route back at this point
3116 self.send_and_assert_no_replies(self.pg0, [p_echo_request_1])
3117
3118 # add teib entry for the peer
3119 teib = VppTeib(self, gre_if, ll2, self.pg0.remote_ip4)
3120 teib.add_vpp_config()
3121
3122 self.logger.info(self.vapi.cli("sh ip6-ll gre0 %s" % ll2))
3123 self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0)
3124
3125 # teardown
3126 self.pg0.unconfig_ip4()
3127
Neale Rannsec40a7d2020-04-23 07:36:12 +00003128
Neale Ranns8f5fef22020-12-21 08:29:34 +00003129class TestIPv6PathMTU(VppTestCase):
3130 """ IPv6 Path MTU """
3131
3132 def setUp(self):
3133 super(TestIPv6PathMTU, self).setUp()
3134
3135 self.create_pg_interfaces(range(2))
3136
3137 # setup all interfaces
3138 for i in self.pg_interfaces:
3139 i.admin_up()
3140 i.config_ip6()
3141 i.resolve_ndp()
3142
3143 def tearDown(self):
3144 super(TestIPv6PathMTU, self).tearDown()
3145 for i in self.pg_interfaces:
3146 i.unconfig_ip6()
3147 i.admin_down()
3148
3149 def test_path_mtu_local(self):
3150 """ Path MTU for attached neighbour """
3151
3152 self.vapi.cli("set log class ip level debug")
3153 #
3154 # The goal here is not test that fragmentation works correctly,
3155 # that's done elsewhere, the intent is to ensure that the Path MTU
3156 # settings are honoured.
3157 #
3158
3159 #
3160 # IPv6 will only frag locally generated packets, so use tunnelled
3161 # packets post encap
3162 #
3163 tun = VppIpIpTunInterface(
3164 self,
3165 self.pg1,
3166 self.pg1.local_ip6,
3167 self.pg1.remote_ip6)
3168 tun.add_vpp_config()
3169 tun.admin_up()
3170 tun.config_ip6()
3171
3172 # set the interface MTU to a reasonable value
3173 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3174 [2800, 0, 0, 0])
3175
3176 p_2k = (Ether(dst=self.pg0.local_mac,
3177 src=self.pg0.remote_mac) /
3178 IPv6(src=self.pg0.remote_ip6,
3179 dst=tun.remote_ip6) /
3180 UDP(sport=1234, dport=5678) /
3181 Raw(b'0xa' * 1000))
3182 p_1k = (Ether(dst=self.pg0.local_mac,
3183 src=self.pg0.remote_mac) /
3184 IPv6(src=self.pg0.remote_ip6,
3185 dst=tun.remote_ip6) /
3186 UDP(sport=1234, dport=5678) /
3187 Raw(b'0xa' * 600))
3188
3189 nbr = VppNeighbor(self,
3190 self.pg1.sw_if_index,
3191 self.pg1.remote_mac,
3192 self.pg1.remote_ip6).add_vpp_config()
3193
3194 # this is now the interface MTU frags
3195 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2)
3196 self.send_and_expect(self.pg0, [p_1k], self.pg1)
3197
3198 # drop the path MTU for this neighbour to below the interface MTU
3199 # expect more frags
3200 pmtu = VppIpPathMtu(self, self.pg1.remote_ip6, 1300).add_vpp_config()
3201
3202 # print/format the adj delegate and trackers
3203 self.logger.info(self.vapi.cli("sh ip pmtu"))
3204 self.logger.info(self.vapi.cli("sh adj 7"))
3205
3206 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3207 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3208
3209 # increase the path MTU to more than the interface
3210 # expect to use the interface MTU
3211 pmtu.modify(8192)
3212
3213 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2)
3214 self.send_and_expect(self.pg0, [p_1k], self.pg1)
3215
3216 # go back to an MTU from the path
3217 pmtu.modify(1300)
3218
3219 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3220 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3221
3222 # raise the interface's MTU
3223 # should still use that of the path
3224 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3225 [2000, 0, 0, 0])
3226 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3227 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3228
3229 # set path high and interface low
3230 pmtu.modify(2000)
3231 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3232 [1300, 0, 0, 0])
3233 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3234 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3235
3236 # remove the path MTU
3237 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3238 [2800, 0, 0, 0])
3239 pmtu.modify(0)
3240
3241 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2)
3242 self.send_and_expect(self.pg0, [p_1k], self.pg1)
3243
3244 def test_path_mtu_remote(self):
3245 """ Path MTU for remote neighbour """
3246
3247 self.vapi.cli("set log class ip level debug")
3248 #
3249 # The goal here is not test that fragmentation works correctly,
3250 # that's done elsewhere, the intent is to ensure that the Path MTU
3251 # settings are honoured.
3252 #
3253 tun_dst = "2001::1"
3254
3255 route = VppIpRoute(
3256 self, tun_dst, 64,
3257 [VppRoutePath(self.pg1.remote_ip6,
3258 self.pg1.sw_if_index)]).add_vpp_config()
3259
3260 #
3261 # IPv6 will only frag locally generated packets, so use tunnelled
3262 # packets post encap
3263 #
3264 tun = VppIpIpTunInterface(
3265 self,
3266 self.pg1,
3267 self.pg1.local_ip6,
3268 tun_dst)
3269 tun.add_vpp_config()
3270 tun.admin_up()
3271 tun.config_ip6()
3272
3273 # set the interface MTU to a reasonable value
3274 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3275 [2800, 0, 0, 0])
3276
3277 p_2k = (Ether(dst=self.pg0.local_mac,
3278 src=self.pg0.remote_mac) /
3279 IPv6(src=self.pg0.remote_ip6,
3280 dst=tun.remote_ip6) /
3281 UDP(sport=1234, dport=5678) /
3282 Raw(b'0xa' * 1000))
3283 p_1k = (Ether(dst=self.pg0.local_mac,
3284 src=self.pg0.remote_mac) /
3285 IPv6(src=self.pg0.remote_ip6,
3286 dst=tun.remote_ip6) /
3287 UDP(sport=1234, dport=5678) /
3288 Raw(b'0xa' * 600))
3289
3290 nbr = VppNeighbor(self,
3291 self.pg1.sw_if_index,
3292 self.pg1.remote_mac,
3293 self.pg1.remote_ip6).add_vpp_config()
3294
3295 # this is now the interface MTU frags
3296 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2)
3297 self.send_and_expect(self.pg0, [p_1k], self.pg1)
3298
3299 # drop the path MTU for this neighbour to below the interface MTU
3300 # expect more frags
3301 pmtu = VppIpPathMtu(self, tun_dst, 1300).add_vpp_config()
3302
3303 # print/format the fib entry/dpo
3304 self.logger.info(self.vapi.cli("sh ip6 fib 2001::1"))
3305
3306 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3307 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3308
3309 # increase the path MTU to more than the interface
3310 # expect to use the interface MTU
3311 pmtu.modify(8192)
3312
3313 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2)
3314 self.send_and_expect(self.pg0, [p_1k], self.pg1)
3315
3316 # go back to an MTU from the path
3317 pmtu.modify(1300)
3318
3319 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3320 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3321
3322 # raise the interface's MTU
3323 # should still use that of the path
3324 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3325 [2000, 0, 0, 0])
3326 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3327 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3328
3329 # turn the tun_dst into an attached neighbour
3330 route.modify([VppRoutePath("::",
3331 self.pg1.sw_if_index)])
3332 nbr2 = VppNeighbor(self,
3333 self.pg1.sw_if_index,
3334 self.pg1.remote_mac,
3335 tun_dst).add_vpp_config()
3336
3337 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3338 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3339
3340 # add back to not attached
3341 nbr2.remove_vpp_config()
3342 route.modify([VppRoutePath(self.pg1.remote_ip6,
3343 self.pg1.sw_if_index)])
3344
3345 # set path high and interface low
3346 pmtu.modify(2000)
3347 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3348 [1300, 0, 0, 0])
3349 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3)
3350 self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2)
3351
3352 # remove the path MTU
3353 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index,
3354 [2800, 0, 0, 0])
3355 pmtu.remove_vpp_config()
3356 self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2)
3357 self.send_and_expect(self.pg0, [p_1k], self.pg1)
3358
3359
Neale Ranns976b2592019-12-04 06:11:00 +00003360class TestIPFibSource(VppTestCase):
3361 """ IPv6 Table FibSource """
3362
3363 @classmethod
3364 def setUpClass(cls):
3365 super(TestIPFibSource, cls).setUpClass()
3366
3367 @classmethod
3368 def tearDownClass(cls):
3369 super(TestIPFibSource, cls).tearDownClass()
3370
3371 def setUp(self):
3372 super(TestIPFibSource, self).setUp()
3373
3374 self.create_pg_interfaces(range(2))
3375
3376 for i in self.pg_interfaces:
3377 i.admin_up()
3378 i.config_ip6()
3379 i.resolve_arp()
3380 i.generate_remote_hosts(2)
3381 i.configure_ipv6_neighbors()
3382
3383 def tearDown(self):
3384 super(TestIPFibSource, self).tearDown()
3385 for i in self.pg_interfaces:
3386 i.admin_down()
3387 i.unconfig_ip4()
3388
3389 def test_fib_source(self):
3390 """ IP Table FibSource """
3391
3392 routes = self.vapi.ip_route_v2_dump(0, True)
3393
3394 # 2 interfaces (4 routes) + 2 specials + 4 neighbours = 10 routes
3395 self.assertEqual(len(routes), 10)
3396
3397 # dump all the sources in the FIB
3398 sources = self.vapi.fib_source_dump()
3399 for source in sources:
3400 if (source.src.name == "API"):
3401 api_source = source.src
3402 if (source.src.name == "interface"):
3403 intf_source = source.src
3404 if (source.src.name == "adjacency"):
3405 adj_source = source.src
3406 if (source.src.name == "special"):
3407 special_source = source.src
3408 if (source.src.name == "default-route"):
3409 dr_source = source.src
3410
3411 # dump the individual route types
3412 routes = self.vapi.ip_route_v2_dump(0, True, src=adj_source.id)
3413 self.assertEqual(len(routes), 4)
3414 routes = self.vapi.ip_route_v2_dump(0, True, src=intf_source.id)
3415 self.assertEqual(len(routes), 4)
3416 routes = self.vapi.ip_route_v2_dump(0, True, src=special_source.id)
3417 self.assertEqual(len(routes), 1)
3418 routes = self.vapi.ip_route_v2_dump(0, True, src=dr_source.id)
3419 self.assertEqual(len(routes), 1)
3420
3421 # add a new soure that'a better than the API
3422 self.vapi.fib_source_add(src={'name': "bgp",
3423 "priority": api_source.priority - 1})
3424
3425 # dump all the sources to check our new one is there
3426 sources = self.vapi.fib_source_dump()
3427
3428 for source in sources:
3429 if (source.src.name == "bgp"):
3430 bgp_source = source.src
3431
3432 self.assertTrue(bgp_source)
3433 self.assertEqual(bgp_source.priority,
3434 api_source.priority - 1)
3435
3436 # add a route with the default API source
3437 r1 = VppIpRouteV2(
3438 self, "2001::1", 128,
3439 [VppRoutePath(self.pg0.remote_ip6,
3440 self.pg0.sw_if_index)]).add_vpp_config()
3441
3442 r2 = VppIpRouteV2(self, "2001::1", 128,
3443 [VppRoutePath(self.pg1.remote_ip6,
3444 self.pg1.sw_if_index)],
3445 src=bgp_source.id).add_vpp_config()
3446
3447 # ensure the BGP source takes priority
3448 p = (Ether(src=self.pg0.remote_mac,
3449 dst=self.pg0.local_mac) /
3450 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
3451 inet6.UDP(sport=1234, dport=1234) /
3452 Raw(b'\xa5' * 100))
3453
3454 self.send_and_expect(self.pg0, [p], self.pg1)
3455
3456 r2.remove_vpp_config()
3457 r1.remove_vpp_config()
3458
3459 self.assertFalse(find_route(self, "2001::1", 128))
3460
3461
Neale Ranns91adf242021-05-27 12:18:52 +00003462class TestIPxAF(VppTestCase):
3463 """ IP cross AF """
3464
3465 @classmethod
3466 def setUpClass(cls):
3467 super(TestIPxAF, cls).setUpClass()
3468
3469 @classmethod
3470 def tearDownClass(cls):
3471 super(TestIPxAF, cls).tearDownClass()
3472
3473 def setUp(self):
3474 super(TestIPxAF, self).setUp()
3475
3476 self.create_pg_interfaces(range(2))
3477
3478 for i in self.pg_interfaces:
3479 i.admin_up()
3480 i.config_ip6()
3481 i.config_ip4()
3482 i.resolve_arp()
3483 i.resolve_ndp()
3484
3485 def tearDown(self):
3486 super(TestIPxAF, self).tearDown()
3487 for i in self.pg_interfaces:
3488 i.admin_down()
3489 i.unconfig_ip4()
3490 i.unconfig_ip6()
3491
3492 def test_x_af(self):
3493 """ Cross AF routing """
3494
3495 N_PKTS = 63
3496 # a v4 route via a v6 attached next-hop
3497 VppIpRoute(
3498 self, "1.1.1.1", 32,
3499 [VppRoutePath(self.pg1.remote_ip6,
3500 self.pg1.sw_if_index)]).add_vpp_config()
3501
3502 p = (Ether(src=self.pg0.remote_mac,
3503 dst=self.pg0.local_mac) /
3504 IP(src=self.pg0.remote_ip4, dst="1.1.1.1") /
3505 UDP(sport=1234, dport=1234) /
3506 Raw(b'\xa5' * 100))
3507 rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1)
3508
3509 for rx in rxs:
3510 self.assertEqual(rx[IP].dst, "1.1.1.1")
3511
3512 # a v6 route via a v4 attached next-hop
3513 VppIpRoute(
3514 self, "2001::1", 128,
3515 [VppRoutePath(self.pg1.remote_ip4,
3516 self.pg1.sw_if_index)]).add_vpp_config()
3517
3518 p = (Ether(src=self.pg0.remote_mac,
3519 dst=self.pg0.local_mac) /
3520 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
3521 UDP(sport=1234, dport=1234) /
3522 Raw(b'\xa5' * 100))
3523 rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1)
3524
3525 for rx in rxs:
3526 self.assertEqual(rx[IPv6].dst, "2001::1")
3527
3528 # a recursive v4 route via a v6 next-hop (from above)
3529 VppIpRoute(
3530 self, "2.2.2.2", 32,
3531 [VppRoutePath("2001::1",
3532 0xffffffff)]).add_vpp_config()
3533
3534 p = (Ether(src=self.pg0.remote_mac,
3535 dst=self.pg0.local_mac) /
3536 IP(src=self.pg0.remote_ip4, dst="2.2.2.2") /
3537 UDP(sport=1234, dport=1234) /
3538 Raw(b'\xa5' * 100))
3539 rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1)
3540
3541 # a recursive v4 route via a v6 next-hop
3542 VppIpRoute(
3543 self, "2.2.2.3", 32,
3544 [VppRoutePath(self.pg1.remote_ip6,
3545 0xffffffff)]).add_vpp_config()
3546
3547 p = (Ether(src=self.pg0.remote_mac,
3548 dst=self.pg0.local_mac) /
3549 IP(src=self.pg0.remote_ip4, dst="2.2.2.3") /
3550 UDP(sport=1234, dport=1234) /
3551 Raw(b'\xa5' * 100))
3552 rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1)
3553
3554 # a recursive v6 route via a v4 next-hop
3555 VppIpRoute(
3556 self, "3001::1", 128,
3557 [VppRoutePath(self.pg1.remote_ip4,
3558 0xffffffff)]).add_vpp_config()
3559
3560 p = (Ether(src=self.pg0.remote_mac,
3561 dst=self.pg0.local_mac) /
3562 IPv6(src=self.pg0.remote_ip6, dst="3001::1") /
3563 UDP(sport=1234, dport=1234) /
3564 Raw(b'\xa5' * 100))
3565 rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1)
3566
3567 for rx in rxs:
3568 self.assertEqual(rx[IPv6].dst, "3001::1")
3569
3570 VppIpRoute(
3571 self, "3001::2", 128,
3572 [VppRoutePath("1.1.1.1",
3573 0xffffffff)]).add_vpp_config()
3574
3575 p = (Ether(src=self.pg0.remote_mac,
3576 dst=self.pg0.local_mac) /
3577 IPv6(src=self.pg0.remote_ip6, dst="3001::2") /
3578 UDP(sport=1234, dport=1234) /
3579 Raw(b'\xa5' * 100))
3580 rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1)
3581
3582 for rx in rxs:
3583 self.assertEqual(rx[IPv6].dst, "3001::2")
3584
3585
Damjan Marionf56b77a2016-10-03 19:44:57 +02003586if __name__ == '__main__':
Klement Sekeraf62ae122016-10-11 11:47:09 +02003587 unittest.main(testRunner=VppTestRunner)