blob: 36ef577720730475028d62dee7ef43e64e8ad6c6 [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
10from scapy.contrib.mpls import MPLS
11from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \
12 ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
13 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
Neale Rannsf267d112020-02-07 09:45:07 +000014 ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply, \
15 IPv6ExtHdrHopByHop, ICMPv6MLReport2, ICMPv6MLDMultAddrRec
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080016from scapy.layers.l2 import Ether, Dot1Q
17from scapy.packet import Raw
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080018from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
19 in6_mactoifaceid
20from six import moves
Klement Sekeraf62ae122016-10-11 11:47:09 +020021
Damjan Marionf56b77a2016-10-03 19:44:57 +020022from framework import VppTestCase, VppTestRunner
Paul Vinciguerrae8fece82019-02-28 15:34:00 -080023from util import ppp, ip6_normalize, mk_ll_addr
Neale Rannsefd7bc22019-11-11 08:32:34 +000024from vpp_ip import DpoProto
Neale Ranns180279b2017-03-16 15:49:09 -040025from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
Neale Ranns71275e32017-05-25 12:38:58 -070026 VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
Neale Ranns9db6ada2019-11-08 12:42:31 +000027 VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
Neale Rannsec40a7d2020-04-23 07:36:12 +000028 VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump, \
29 VppIp6LinkLocalAddress
Neale Rannsb3b2de72017-03-08 05:17:22 -080030from vpp_neighbor import find_nbr, VppNeighbor
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080031from vpp_pg_interface import is_ipv6_misc
32from vpp_sub_interface import VppSubInterface, VppDot1QSubint
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010033from vpp_policer import VppPolicer
Neale Rannsefd7bc22019-11-11 08:32:34 +000034from ipaddress import IPv6Network, IPv6Address
Neale Ranns75152282017-01-09 01:00:45 -080035
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010036AF_INET6 = socket.AF_INET6
37
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -080038try:
39 text_type = unicode
40except NameError:
41 text_type = str
42
Paul Vinciguerra4271c972019-05-14 13:25:49 -040043NUM_PKTS = 67
44
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010045
Neale Ranns3f844d02017-02-18 00:03:54 -080046class TestIPv6ND(VppTestCase):
47 def validate_ra(self, intf, rx, dst_ip=None):
48 if not dst_ip:
49 dst_ip = intf.remote_ip6
50
51 # unicasted packets must come to the unicast mac
52 self.assertEqual(rx[Ether].dst, intf.remote_mac)
53
54 # and from the router's MAC
55 self.assertEqual(rx[Ether].src, intf.local_mac)
56
57 # the rx'd RA should be addressed to the sender's source
58 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
59 self.assertEqual(in6_ptop(rx[IPv6].dst),
60 in6_ptop(dst_ip))
61
62 # and come from the router's link local
63 self.assertTrue(in6_islladdr(rx[IPv6].src))
64 self.assertEqual(in6_ptop(rx[IPv6].src),
65 in6_ptop(mk_ll_addr(intf.local_mac)))
66
67 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
68 if not dst_ip:
69 dst_ip = intf.remote_ip6
70 if not tgt_ip:
71 dst_ip = intf.local_ip6
72
73 # unicasted packets must come to the unicast mac
74 self.assertEqual(rx[Ether].dst, intf.remote_mac)
75
76 # and from the router's MAC
77 self.assertEqual(rx[Ether].src, intf.local_mac)
78
79 # the rx'd NA should be addressed to the sender's source
80 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
81 self.assertEqual(in6_ptop(rx[IPv6].dst),
82 in6_ptop(dst_ip))
83
84 # and come from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -080085 self.assertEqual(
86 in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
Neale Ranns3f844d02017-02-18 00:03:54 -080087
88 # Dest link-layer options should have the router's MAC
89 dll = rx[ICMPv6NDOptDstLLAddr]
90 self.assertEqual(dll.lladdr, intf.local_mac)
91
Neale Rannsdcd6d622017-05-26 02:59:16 -070092 def validate_ns(self, intf, rx, tgt_ip):
93 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
94 dst_ip = inet_ntop(AF_INET6, nsma)
95
96 # NS is broadcast
Neale Rannsc7b8f202018-04-25 06:34:31 -070097 self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
Neale Rannsdcd6d622017-05-26 02:59:16 -070098
99 # and from the router's MAC
100 self.assertEqual(rx[Ether].src, intf.local_mac)
101
102 # the rx'd NS should be addressed to an mcast address
103 # derived from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800104 self.assertEqual(
105 in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
Neale Rannsdcd6d622017-05-26 02:59:16 -0700106
107 # expect the tgt IP in the NS header
108 ns = rx[ICMPv6ND_NS]
109 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
110
111 # packet is from the router's local address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800112 self.assertEqual(
113 in6_ptop(rx[IPv6].src), intf.local_ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700114
115 # Src link-layer options should have the router's MAC
116 sll = rx[ICMPv6NDOptSrcLLAddr]
117 self.assertEqual(sll.lladdr, intf.local_mac)
118
Neale Ranns3f844d02017-02-18 00:03:54 -0800119 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
120 filter_out_fn=is_ipv6_misc):
121 intf.add_stream(pkts)
Neale Ranns3f844d02017-02-18 00:03:54 -0800122 self.pg_enable_capture(self.pg_interfaces)
123 self.pg_start()
124 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
125
126 self.assertEqual(len(rx), 1)
127 rx = rx[0]
128 self.validate_ra(intf, rx, dst_ip)
129
Neale Ranns2a3ea492017-04-19 05:24:40 -0700130 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
131 tgt_ip=None,
132 filter_out_fn=is_ipv6_misc):
133 intf.add_stream(pkts)
134 self.pg_enable_capture(self.pg_interfaces)
135 self.pg_start()
136 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
137
138 self.assertEqual(len(rx), 1)
139 rx = rx[0]
140 self.validate_na(intf, rx, dst_ip, tgt_ip)
141
Neale Rannsdcd6d622017-05-26 02:59:16 -0700142 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
143 filter_out_fn=is_ipv6_misc):
Neale Rannscbe25aa2019-09-30 10:53:31 +0000144 self.vapi.cli("clear trace")
Neale Rannsdcd6d622017-05-26 02:59:16 -0700145 tx_intf.add_stream(pkts)
146 self.pg_enable_capture(self.pg_interfaces)
147 self.pg_start()
148 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
149
150 self.assertEqual(len(rx), 1)
151 rx = rx[0]
152 self.validate_ns(rx_intf, rx, tgt_ip)
153
Neale Rannsdcd6d622017-05-26 02:59:16 -0700154 def verify_ip(self, rx, smac, dmac, sip, dip):
155 ether = rx[Ether]
156 self.assertEqual(ether.dst, dmac)
157 self.assertEqual(ether.src, smac)
158
159 ip = rx[IPv6]
160 self.assertEqual(ip.src, sip)
161 self.assertEqual(ip.dst, dip)
162
Neale Ranns3f844d02017-02-18 00:03:54 -0800163
164class TestIPv6(TestIPv6ND):
Damjan Marionf56b77a2016-10-03 19:44:57 +0200165 """ IPv6 Test Case """
166
167 @classmethod
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000168 def force_solo(cls):
169 return True
170
171 @classmethod
Damjan Marionf56b77a2016-10-03 19:44:57 +0200172 def setUpClass(cls):
173 super(TestIPv6, cls).setUpClass()
174
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700175 @classmethod
176 def tearDownClass(cls):
177 super(TestIPv6, cls).tearDownClass()
178
Klement Sekeraf62ae122016-10-11 11:47:09 +0200179 def setUp(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100180 """
181 Perform test setup before test case.
182
183 **Config:**
184 - create 3 pg interfaces
185 - untagged pg0 interface
186 - Dot1Q subinterface on pg1
187 - Dot1AD subinterface on pg2
188 - setup interfaces:
189 - put it into UP state
190 - set IPv6 addresses
191 - resolve neighbor address using NDP
192 - configure 200 fib entries
193
194 :ivar list interfaces: pg interfaces and subinterfaces.
195 :ivar dict flows: IPv4 packet flows in test.
Matej Klotton86d87c42016-11-11 11:38:55 +0100196
197 *TODO:* Create AD sub interface
198 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200199 super(TestIPv6, self).setUp()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200200
Klement Sekeraf62ae122016-10-11 11:47:09 +0200201 # create 3 pg interfaces
202 self.create_pg_interfaces(range(3))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200203
Klement Sekeraf62ae122016-10-11 11:47:09 +0200204 # create 2 subinterfaces for p1 and pg2
205 self.sub_interfaces = [
206 VppDot1QSubint(self, self.pg1, 100),
Matej Klotton86d87c42016-11-11 11:38:55 +0100207 VppDot1QSubint(self, self.pg2, 200)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200208 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
Matej Klotton86d87c42016-11-11 11:38:55 +0100209 ]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200210
Klement Sekeraf62ae122016-10-11 11:47:09 +0200211 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
212 self.flows = dict()
213 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
214 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
215 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200216
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217 # packet sizes
Jan Geletye6c78ee2018-06-26 12:24:03 +0200218 self.pg_if_packet_sizes = [64, 1500, 9020]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200219
Klement Sekeraf62ae122016-10-11 11:47:09 +0200220 self.interfaces = list(self.pg_interfaces)
221 self.interfaces.extend(self.sub_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200222
Klement Sekeraf62ae122016-10-11 11:47:09 +0200223 # setup all interfaces
224 for i in self.interfaces:
225 i.admin_up()
226 i.config_ip6()
227 i.resolve_ndp()
228
Damjan Marionf56b77a2016-10-03 19:44:57 +0200229 def tearDown(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100230 """Run standard test teardown and log ``show ip6 neighbors``."""
Neale Ranns744902e2017-08-14 10:35:44 -0700231 for i in self.interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800232 i.unconfig_ip6()
Neale Ranns75152282017-01-09 01:00:45 -0800233 i.admin_down()
Neale Ranns744902e2017-08-14 10:35:44 -0700234 for i in self.sub_interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800235 i.remove_vpp_config()
236
Klement Sekeraf62ae122016-10-11 11:47:09 +0200237 super(TestIPv6, self).tearDown()
238 if not self.vpp_dead:
Matej Klotton86d87c42016-11-11 11:38:55 +0100239 self.logger.info(self.vapi.cli("show ip6 neighbors"))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200240 # info(self.vapi.cli("show ip6 fib")) # many entries
Damjan Marionf56b77a2016-10-03 19:44:57 +0200241
Jan Geletye6c78ee2018-06-26 12:24:03 +0200242 def modify_packet(self, src_if, packet_size, pkt):
243 """Add load, set destination IP and extend packet to required packet
244 size for defined interface.
245
246 :param VppInterface src_if: Interface to create packet for.
247 :param int packet_size: Required packet size.
248 :param Scapy pkt: Packet to be modified.
249 """
snaramre07a0f212019-10-11 21:28:56 +0000250 dst_if_idx = int(packet_size / 10 % 2)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200251 dst_if = self.flows[src_if][dst_if_idx]
252 info = self.create_packet_info(src_if, dst_if)
253 payload = self.info_to_payload(info)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800254 p = pkt / Raw(payload)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200255 p[IPv6].dst = dst_if.remote_ip6
256 info.data = p.copy()
257 if isinstance(src_if, VppSubInterface):
258 p = src_if.add_dot1_layer(p)
259 self.extend_packet(p, packet_size)
260
261 return p
262
263 def create_stream(self, src_if):
Matej Klotton86d87c42016-11-11 11:38:55 +0100264 """Create input packet stream for defined interface.
265
266 :param VppInterface src_if: Interface to create packet stream for.
Matej Klotton86d87c42016-11-11 11:38:55 +0100267 """
Jan Geletye6c78ee2018-06-26 12:24:03 +0200268 hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
269 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
270 IPv6(src=src_if.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800271 inet6.UDP(sport=1234, dport=1234))
Jan Geletye6c78ee2018-06-26 12:24:03 +0200272
273 pkts = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800274 for i in moves.range(self.pg_if_packet_sizes[0],
275 self.pg_if_packet_sizes[1], 10)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200276 pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800277 for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
278 self.pg_if_packet_sizes[2] + hdr_ext,
279 50)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200280 pkts.extend(pkts_b)
281
Damjan Marionf56b77a2016-10-03 19:44:57 +0200282 return pkts
283
Klement Sekeraf62ae122016-10-11 11:47:09 +0200284 def verify_capture(self, dst_if, capture):
Matej Klotton86d87c42016-11-11 11:38:55 +0100285 """Verify captured input packet stream for defined interface.
286
287 :param VppInterface dst_if: Interface to verify captured packet stream
288 for.
289 :param list capture: Captured packet stream.
290 """
291 self.logger.info("Verifying capture on interface %s" % dst_if.name)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200292 last_info = dict()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200293 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200294 last_info[i.sw_if_index] = None
295 is_sub_if = False
296 dst_sw_if_index = dst_if.sw_if_index
297 if hasattr(dst_if, 'parent'):
298 is_sub_if = True
Damjan Marionf56b77a2016-10-03 19:44:57 +0200299 for packet in capture:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200300 if is_sub_if:
301 # Check VLAN tags and Ethernet header
302 packet = dst_if.remove_dot1_layer(packet)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200303 self.assertTrue(Dot1Q not in packet)
304 try:
305 ip = packet[IPv6]
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800306 udp = packet[inet6.UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800307 payload_info = self.payload_to_info(packet[Raw])
Damjan Marionf56b77a2016-10-03 19:44:57 +0200308 packet_index = payload_info.index
Klement Sekeraf62ae122016-10-11 11:47:09 +0200309 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerada505f62017-01-04 12:58:53 +0100310 self.logger.debug(
311 "Got packet on port %s: src=%u (id=%u)" %
312 (dst_if.name, payload_info.src, packet_index))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200313 next_info = self.get_next_packet_info_for_interface2(
314 payload_info.src, dst_sw_if_index,
315 last_info[payload_info.src])
316 last_info[payload_info.src] = next_info
Damjan Marionf56b77a2016-10-03 19:44:57 +0200317 self.assertTrue(next_info is not None)
318 self.assertEqual(packet_index, next_info.index)
319 saved_packet = next_info.data
320 # Check standard fields
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800321 self.assertEqual(
322 ip.src, saved_packet[IPv6].src)
323 self.assertEqual(
324 ip.dst, saved_packet[IPv6].dst)
325 self.assertEqual(
326 udp.sport, saved_packet[inet6.UDP].sport)
327 self.assertEqual(
328 udp.dport, saved_packet[inet6.UDP].dport)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200329 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100330 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200331 raise
332 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200333 remaining_packet = self.get_next_packet_info_for_interface2(
334 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
Klement Sekera7bb873a2016-11-18 07:38:42 +0100335 self.assertTrue(remaining_packet is None,
336 "Interface %s: Packet expected from interface %s "
337 "didn't arrive" % (dst_if.name, i.name))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200338
Klement Sekerae8498652019-06-17 12:23:15 +0000339 def test_next_header_anomaly(self):
340 """ IPv6 next header anomaly test
341
342 Test scenario:
343 - ipv6 next header field = Fragment Header (44)
344 - next header is ICMPv6 Echo Request
345 - wait for reassembly
346 """
347 pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) /
348 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) /
349 ICMPv6EchoRequest())
350
351 self.pg0.add_stream(pkt)
352 self.pg_start()
353
354 # wait for reassembly
355 self.sleep(10)
356
Damjan Marionf56b77a2016-10-03 19:44:57 +0200357 def test_fib(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100358 """ IPv6 FIB test
359
360 Test scenario:
361 - Create IPv6 stream for pg0 interface
362 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
363 - Send and verify received packets on each interface.
364 """
Damjan Marionf56b77a2016-10-03 19:44:57 +0200365
Jan Geletye6c78ee2018-06-26 12:24:03 +0200366 pkts = self.create_stream(self.pg0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200367 self.pg0.add_stream(pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200368
Klement Sekeraf62ae122016-10-11 11:47:09 +0200369 for i in self.sub_interfaces:
Jan Geletye6c78ee2018-06-26 12:24:03 +0200370 pkts = self.create_stream(i)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200371 i.parent.add_stream(pkts)
372
373 self.pg_enable_capture(self.pg_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200374 self.pg_start()
375
Klement Sekeraf62ae122016-10-11 11:47:09 +0200376 pkts = self.pg0.get_capture()
377 self.verify_capture(self.pg0, pkts)
378
379 for i in self.sub_interfaces:
380 pkts = i.parent.get_capture()
381 self.verify_capture(i, pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200382
Neale Ranns75152282017-01-09 01:00:45 -0800383 def test_ns(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100384 """ IPv6 Neighbour Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800385
Klement Sekerada505f62017-01-04 12:58:53 +0100386 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800387 - Send an NS Sourced from an address not covered by the link sub-net
388 - Send an NS to an mcast address the router has not joined
389 - Send NS for a target address the router does not onn.
390 """
391
392 #
393 # An NS from a non link source address
394 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800395 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
396 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800397
398 p = (Ether(dst=in6_getnsmac(nsma)) /
399 IPv6(dst=d, src="2002::2") /
400 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800401 ICMPv6NDOptSrcLLAddr(
402 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800403 pkts = [p]
404
Klement Sekerada505f62017-01-04 12:58:53 +0100405 self.send_and_assert_no_replies(
406 self.pg0, pkts,
407 "No response to NS source by address not on sub-net")
Neale Ranns75152282017-01-09 01:00:45 -0800408
409 #
Klement Sekerada505f62017-01-04 12:58:53 +0100410 # An NS for sent to a solicited mcast group the router is
411 # not a member of FAILS
Neale Ranns75152282017-01-09 01:00:45 -0800412 #
413 if 0:
Neale Ranns3f844d02017-02-18 00:03:54 -0800414 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
415 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800416
417 p = (Ether(dst=in6_getnsmac(nsma)) /
418 IPv6(dst=d, src=self.pg0.remote_ip6) /
419 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800420 ICMPv6NDOptSrcLLAddr(
421 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800422 pkts = [p]
423
Klement Sekerada505f62017-01-04 12:58:53 +0100424 self.send_and_assert_no_replies(
425 self.pg0, pkts,
426 "No response to NS sent to unjoined mcast address")
Neale Ranns75152282017-01-09 01:00:45 -0800427
428 #
429 # An NS whose target address is one the router does not own
430 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800431 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
432 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800433
434 p = (Ether(dst=in6_getnsmac(nsma)) /
435 IPv6(dst=d, src=self.pg0.remote_ip6) /
436 ICMPv6ND_NS(tgt="fd::ffff") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800437 ICMPv6NDOptSrcLLAddr(
438 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800439 pkts = [p]
440
441 self.send_and_assert_no_replies(self.pg0, pkts,
442 "No response to NS for unknown target")
443
Neale Rannsb3b2de72017-03-08 05:17:22 -0800444 #
445 # A neighbor entry that has no associated FIB-entry
446 #
447 self.pg0.generate_remote_hosts(4)
448 nd_entry = VppNeighbor(self,
449 self.pg0.sw_if_index,
450 self.pg0.remote_hosts[2].mac,
451 self.pg0.remote_hosts[2].ip6,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800452 is_no_fib_entry=1)
453 nd_entry.add_vpp_config()
454
455 #
456 # check we have the neighbor, but no route
457 #
458 self.assertTrue(find_nbr(self,
459 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700460 self.pg0._remote_hosts[2].ip6))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800461 self.assertFalse(find_route(self,
462 self.pg0._remote_hosts[2].ip6,
Neale Ranns097fa662018-05-01 05:17:55 -0700463 128))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800464
Neale Ranns2a3ea492017-04-19 05:24:40 -0700465 #
466 # send an NS from a link local address to the interface's global
467 # address
468 #
469 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800470 IPv6(
471 dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700472 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800473 ICMPv6NDOptSrcLLAddr(
474 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700475
476 self.send_and_expect_na(self.pg0, p,
477 "NS from link-local",
478 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
479 tgt_ip=self.pg0.local_ip6)
480
481 #
482 # we should have learned an ND entry for the peer's link-local
483 # but not inserted a route to it in the FIB
484 #
485 self.assertTrue(find_nbr(self,
486 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700487 self.pg0._remote_hosts[2].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700488 self.assertFalse(find_route(self,
489 self.pg0._remote_hosts[2].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700490 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700491
492 #
493 # An NS to the router's own Link-local
494 #
495 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800496 IPv6(
497 dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700498 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800499 ICMPv6NDOptSrcLLAddr(
500 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700501
502 self.send_and_expect_na(self.pg0, p,
503 "NS to/from link-local",
504 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
505 tgt_ip=self.pg0.local_ip6_ll)
506
507 #
508 # we should have learned an ND entry for the peer's link-local
509 # but not inserted a route to it in the FIB
510 #
511 self.assertTrue(find_nbr(self,
512 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700513 self.pg0._remote_hosts[3].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700514 self.assertFalse(find_route(self,
515 self.pg0._remote_hosts[3].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700516 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700517
Neale Rannsdcd6d622017-05-26 02:59:16 -0700518 def test_ns_duplicates(self):
Neale Rannsda78f952017-05-24 09:15:43 -0700519 """ ND Duplicates"""
Neale Rannsdcd6d622017-05-26 02:59:16 -0700520
521 #
522 # Generate some hosts on the LAN
523 #
524 self.pg1.generate_remote_hosts(3)
525
526 #
527 # Add host 1 on pg1 and pg2
528 #
529 ns_pg1 = VppNeighbor(self,
530 self.pg1.sw_if_index,
531 self.pg1.remote_hosts[1].mac,
Neale Ranns37029302018-08-10 05:30:06 -0700532 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700533 ns_pg1.add_vpp_config()
534 ns_pg2 = VppNeighbor(self,
535 self.pg2.sw_if_index,
536 self.pg2.remote_mac,
Neale Ranns37029302018-08-10 05:30:06 -0700537 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700538 ns_pg2.add_vpp_config()
539
540 #
541 # IP packet destined for pg1 remote host arrives on pg1 again.
542 #
543 p = (Ether(dst=self.pg0.local_mac,
544 src=self.pg0.remote_mac) /
545 IPv6(src=self.pg0.remote_ip6,
546 dst=self.pg1.remote_hosts[1].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800547 inet6.UDP(sport=1234, dport=1234) /
Neale Rannsdcd6d622017-05-26 02:59:16 -0700548 Raw())
549
550 self.pg0.add_stream(p)
551 self.pg_enable_capture(self.pg_interfaces)
552 self.pg_start()
553
554 rx1 = self.pg1.get_capture(1)
555
556 self.verify_ip(rx1[0],
557 self.pg1.local_mac,
558 self.pg1.remote_hosts[1].mac,
559 self.pg0.remote_ip6,
560 self.pg1.remote_hosts[1].ip6)
561
562 #
563 # remove the duplicate on pg1
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700564 # packet stream should generate NSs out of pg1
Neale Rannsdcd6d622017-05-26 02:59:16 -0700565 #
566 ns_pg1.remove_vpp_config()
567
568 self.send_and_expect_ns(self.pg0, self.pg1,
569 p, self.pg1.remote_hosts[1].ip6)
570
571 #
572 # Add it back
573 #
574 ns_pg1.add_vpp_config()
575
576 self.pg0.add_stream(p)
577 self.pg_enable_capture(self.pg_interfaces)
578 self.pg_start()
579
580 rx1 = self.pg1.get_capture(1)
581
582 self.verify_ip(rx1[0],
583 self.pg1.local_mac,
584 self.pg1.remote_hosts[1].mac,
585 self.pg0.remote_ip6,
586 self.pg1.remote_hosts[1].ip6)
587
Neale Rannscbe25aa2019-09-30 10:53:31 +0000588 def validate_ra(self, intf, rx, dst_ip=None, src_ip=None,
589 mtu=9000, pi_opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000590 if not dst_ip:
591 dst_ip = intf.remote_ip6
Neale Rannscbe25aa2019-09-30 10:53:31 +0000592 if not src_ip:
593 src_ip = mk_ll_addr(intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800594
Neale Ranns5737d882017-02-03 06:14:49 -0800595 # unicasted packets must come to the unicast mac
Neale Ranns32e1c012016-11-22 17:07:28 +0000596 self.assertEqual(rx[Ether].dst, intf.remote_mac)
597
598 # and from the router's MAC
599 self.assertEqual(rx[Ether].src, intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800600
601 # the rx'd RA should be addressed to the sender's source
602 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
603 self.assertEqual(in6_ptop(rx[IPv6].dst),
Neale Ranns32e1c012016-11-22 17:07:28 +0000604 in6_ptop(dst_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800605
606 # and come from the router's link local
607 self.assertTrue(in6_islladdr(rx[IPv6].src))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000608 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800609
Neale Ranns87df12d2017-02-18 08:16:41 -0800610 # it should contain the links MTU
611 ra = rx[ICMPv6ND_RA]
612 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
613
614 # it should contain the source's link layer address option
615 sll = ra[ICMPv6NDOptSrcLLAddr]
616 self.assertEqual(sll.lladdr, intf.local_mac)
617
618 if not pi_opt:
619 # the RA should not contain prefix information
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800620 self.assertFalse(ra.haslayer(
621 ICMPv6NDOptPrefixInfo))
Neale Ranns87df12d2017-02-18 08:16:41 -0800622 else:
623 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
624
625 # the options are nested in the scapy packet in way that i cannot
626 # decipher how to decode. this 1st layer of option always returns
627 # nested classes, so a direct obj1=obj2 comparison always fails.
Paul Vinciguerraab055082019-06-06 14:07:55 -0400628 # however, the getlayer(.., 2) does give one instance.
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700629 # so we cheat here and construct a new opt instance for comparison
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800630 rd = ICMPv6NDOptPrefixInfo(
631 prefixlen=raos.prefixlen,
632 prefix=raos.prefix,
633 L=raos.L,
634 A=raos.A)
Neale Ranns87df12d2017-02-18 08:16:41 -0800635 if type(pi_opt) is list:
636 for ii in range(len(pi_opt)):
637 self.assertEqual(pi_opt[ii], rd)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800638 rd = rx.getlayer(
639 ICMPv6NDOptPrefixInfo, ii + 2)
Neale Ranns87df12d2017-02-18 08:16:41 -0800640 else:
Paul Vinciguerraab055082019-06-06 14:07:55 -0400641 self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s'
642 % (pi_opt.show(dump=True),
643 raos.show(dump=True)))
Neale Ranns87df12d2017-02-18 08:16:41 -0800644
Neale Ranns32e1c012016-11-22 17:07:28 +0000645 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
Neale Ranns87df12d2017-02-18 08:16:41 -0800646 filter_out_fn=is_ipv6_misc,
Neale Rannscbe25aa2019-09-30 10:53:31 +0000647 opt=None,
648 src_ip=None):
649 self.vapi.cli("clear trace")
Neale Ranns32e1c012016-11-22 17:07:28 +0000650 intf.add_stream(pkts)
Neale Ranns32e1c012016-11-22 17:07:28 +0000651 self.pg_enable_capture(self.pg_interfaces)
652 self.pg_start()
653 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
654
655 self.assertEqual(len(rx), 1)
656 rx = rx[0]
Neale Rannscbe25aa2019-09-30 10:53:31 +0000657 self.validate_ra(intf, rx, dst_ip, src_ip=src_ip, pi_opt=opt)
Neale Ranns32e1c012016-11-22 17:07:28 +0000658
Neale Ranns75152282017-01-09 01:00:45 -0800659 def test_rs(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100660 """ IPv6 Router Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800661
Klement Sekerada505f62017-01-04 12:58:53 +0100662 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800663 """
664
665 #
Klement Sekerada505f62017-01-04 12:58:53 +0100666 # Before we begin change the IPv6 RA responses to use the unicast
667 # address - that way we will not confuse them with the periodic
668 # RAs which go to the mcast address
Neale Ranns32e1c012016-11-22 17:07:28 +0000669 # Sit and wait for the first periodic RA.
670 #
671 # TODO
Neale Ranns75152282017-01-09 01:00:45 -0800672 #
673 self.pg0.ip6_ra_config(send_unicast=1)
674
675 #
676 # An RS from a link source address
677 # - expect an RA in return
678 #
679 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Neale Rannscbe25aa2019-09-30 10:53:31 +0000680 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
Neale Ranns75152282017-01-09 01:00:45 -0800681 ICMPv6ND_RS())
682 pkts = [p]
683 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
684
685 #
686 # For the next RS sent the RA should be rate limited
687 #
688 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
689
690 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700691 # When we reconfigure the IPv6 RA config,
692 # we reset the RA rate limiting,
Klement Sekerada505f62017-01-04 12:58:53 +0100693 # so we need to do this before each test below so as not to drop
694 # packets for rate limiting reasons. Test this works here.
Neale Ranns75152282017-01-09 01:00:45 -0800695 #
696 self.pg0.ip6_ra_config(send_unicast=1)
697 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
698
699 #
700 # An RS sent from a non-link local source
701 #
702 self.pg0.ip6_ra_config(send_unicast=1)
703 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800704 IPv6(dst=self.pg0.local_ip6,
705 src="2002::ffff") /
Neale Ranns75152282017-01-09 01:00:45 -0800706 ICMPv6ND_RS())
707 pkts = [p]
708 self.send_and_assert_no_replies(self.pg0, pkts,
709 "RS from non-link source")
710
711 #
712 # Source an RS from a link local address
713 #
714 self.pg0.ip6_ra_config(send_unicast=1)
715 ll = mk_ll_addr(self.pg0.remote_mac)
716 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
717 IPv6(dst=self.pg0.local_ip6, src=ll) /
718 ICMPv6ND_RS())
719 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000720 self.send_and_expect_ra(self.pg0, pkts,
721 "RS sourced from link-local",
722 dst_ip=ll)
723
724 #
725 # Send the RS multicast
726 #
727 self.pg0.ip6_ra_config(send_unicast=1)
Neale Ranns3f844d02017-02-18 00:03:54 -0800728 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
Neale Ranns32e1c012016-11-22 17:07:28 +0000729 ll = mk_ll_addr(self.pg0.remote_mac)
730 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
731 IPv6(dst="ff02::2", src=ll) /
732 ICMPv6ND_RS())
733 pkts = [p]
734 self.send_and_expect_ra(self.pg0, pkts,
735 "RS sourced from link-local",
736 dst_ip=ll)
Neale Ranns75152282017-01-09 01:00:45 -0800737
738 #
Klement Sekerada505f62017-01-04 12:58:53 +0100739 # Source from the unspecified address ::. This happens when the RS
740 # is sent before the host has a configured address/sub-net,
741 # i.e. auto-config. Since the sender has no IP address, the reply
742 # comes back mcast - so the capture needs to not filter this.
743 # If we happen to pick up the periodic RA at this point then so be it,
744 # it's not an error.
Neale Ranns75152282017-01-09 01:00:45 -0800745 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000746 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
747 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
748 IPv6(dst="ff02::2", src="::") /
Neale Ranns75152282017-01-09 01:00:45 -0800749 ICMPv6ND_RS())
750 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000751 self.send_and_expect_ra(self.pg0, pkts,
752 "RS sourced from unspecified",
753 dst_ip="ff02::1",
754 filter_out_fn=None)
Neale Ranns75152282017-01-09 01:00:45 -0800755
756 #
Neale Ranns87df12d2017-02-18 08:16:41 -0800757 # Configure The RA to announce the links prefix
758 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400759 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
760 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800761
762 #
763 # RAs should now contain the prefix information option
764 #
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800765 opt = ICMPv6NDOptPrefixInfo(
766 prefixlen=self.pg0.local_ip6_prefix_len,
767 prefix=self.pg0.local_ip6,
768 L=1,
769 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800770
771 self.pg0.ip6_ra_config(send_unicast=1)
772 ll = mk_ll_addr(self.pg0.remote_mac)
773 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
774 IPv6(dst=self.pg0.local_ip6, src=ll) /
775 ICMPv6ND_RS())
776 self.send_and_expect_ra(self.pg0, p,
777 "RA with prefix-info",
778 dst_ip=ll,
779 opt=opt)
780
781 #
782 # Change the prefix info to not off-link
783 # L-flag is clear
784 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400785 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
786 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800787 off_link=1)
788
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800789 opt = ICMPv6NDOptPrefixInfo(
790 prefixlen=self.pg0.local_ip6_prefix_len,
791 prefix=self.pg0.local_ip6,
792 L=0,
793 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800794
795 self.pg0.ip6_ra_config(send_unicast=1)
796 self.send_and_expect_ra(self.pg0, p,
797 "RA with Prefix info with L-flag=0",
798 dst_ip=ll,
799 opt=opt)
800
801 #
802 # Change the prefix info to not off-link, no-autoconfig
803 # L and A flag are clear in the advert
804 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400805 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
806 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800807 off_link=1,
808 no_autoconfig=1)
809
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800810 opt = ICMPv6NDOptPrefixInfo(
811 prefixlen=self.pg0.local_ip6_prefix_len,
812 prefix=self.pg0.local_ip6,
813 L=0,
814 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800815
816 self.pg0.ip6_ra_config(send_unicast=1)
817 self.send_and_expect_ra(self.pg0, p,
818 "RA with Prefix info with A & L-flag=0",
819 dst_ip=ll,
820 opt=opt)
821
822 #
823 # Change the flag settings back to the defaults
824 # L and A flag are set in the advert
825 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400826 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
827 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800828
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800829 opt = ICMPv6NDOptPrefixInfo(
830 prefixlen=self.pg0.local_ip6_prefix_len,
831 prefix=self.pg0.local_ip6,
832 L=1,
833 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800834
835 self.pg0.ip6_ra_config(send_unicast=1)
836 self.send_and_expect_ra(self.pg0, p,
837 "RA with Prefix info",
838 dst_ip=ll,
839 opt=opt)
840
841 #
842 # Change the prefix info to not off-link, no-autoconfig
843 # L and A flag are clear in the advert
844 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400845 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
846 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800847 off_link=1,
848 no_autoconfig=1)
849
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800850 opt = ICMPv6NDOptPrefixInfo(
851 prefixlen=self.pg0.local_ip6_prefix_len,
852 prefix=self.pg0.local_ip6,
853 L=0,
854 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800855
856 self.pg0.ip6_ra_config(send_unicast=1)
857 self.send_and_expect_ra(self.pg0, p,
858 "RA with Prefix info with A & L-flag=0",
859 dst_ip=ll,
860 opt=opt)
861
862 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700863 # Use the reset to defaults option to revert to defaults
Neale Ranns87df12d2017-02-18 08:16:41 -0800864 # L and A flag are clear in the advert
865 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400866 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
867 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800868 use_default=1)
869
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800870 opt = ICMPv6NDOptPrefixInfo(
871 prefixlen=self.pg0.local_ip6_prefix_len,
872 prefix=self.pg0.local_ip6,
873 L=1,
874 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800875
876 self.pg0.ip6_ra_config(send_unicast=1)
877 self.send_and_expect_ra(self.pg0, p,
878 "RA with Prefix reverted to defaults",
879 dst_ip=ll,
880 opt=opt)
881
882 #
883 # Advertise Another prefix. With no L-flag/A-flag
884 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400885 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
886 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800887 off_link=1,
888 no_autoconfig=1)
889
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800890 opt = [ICMPv6NDOptPrefixInfo(
891 prefixlen=self.pg0.local_ip6_prefix_len,
892 prefix=self.pg0.local_ip6,
893 L=1,
894 A=1),
895 ICMPv6NDOptPrefixInfo(
896 prefixlen=self.pg1.local_ip6_prefix_len,
897 prefix=self.pg1.local_ip6,
898 L=0,
899 A=0)]
Neale Ranns87df12d2017-02-18 08:16:41 -0800900
901 self.pg0.ip6_ra_config(send_unicast=1)
902 ll = mk_ll_addr(self.pg0.remote_mac)
903 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
904 IPv6(dst=self.pg0.local_ip6, src=ll) /
905 ICMPv6ND_RS())
906 self.send_and_expect_ra(self.pg0, p,
907 "RA with multiple Prefix infos",
908 dst_ip=ll,
909 opt=opt)
910
911 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700912 # Remove the first prefix-info - expect the second is still in the
Neale Ranns87df12d2017-02-18 08:16:41 -0800913 # advert
914 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400915 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
916 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800917 is_no=1)
918
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800919 opt = ICMPv6NDOptPrefixInfo(
920 prefixlen=self.pg1.local_ip6_prefix_len,
921 prefix=self.pg1.local_ip6,
922 L=0,
923 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800924
925 self.pg0.ip6_ra_config(send_unicast=1)
926 self.send_and_expect_ra(self.pg0, p,
927 "RA with Prefix reverted to defaults",
928 dst_ip=ll,
929 opt=opt)
930
931 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700932 # Remove the second prefix-info - expect no prefix-info in the adverts
Neale Ranns87df12d2017-02-18 08:16:41 -0800933 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400934 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
935 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800936 is_no=1)
937
Neale Rannscbe25aa2019-09-30 10:53:31 +0000938 #
939 # change the link's link local, so we know that works too.
940 #
941 self.vapi.sw_interface_ip6_set_link_local_address(
942 sw_if_index=self.pg0.sw_if_index,
943 ip="fe80::88")
944
Neale Ranns87df12d2017-02-18 08:16:41 -0800945 self.pg0.ip6_ra_config(send_unicast=1)
946 self.send_and_expect_ra(self.pg0, p,
947 "RA with Prefix reverted to defaults",
Neale Rannscbe25aa2019-09-30 10:53:31 +0000948 dst_ip=ll,
949 src_ip="fe80::88")
Neale Ranns87df12d2017-02-18 08:16:41 -0800950
951 #
Neale Ranns5737d882017-02-03 06:14:49 -0800952 # Reset the periodic advertisements back to default values
Neale Ranns75152282017-01-09 01:00:45 -0800953 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000954 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200955
Neale Rannsf267d112020-02-07 09:45:07 +0000956 def test_mld(self):
957 """ MLD Report """
958 #
959 # test one MLD is sent after applying an IPv6 Address on an interface
960 #
961 self.pg_enable_capture(self.pg_interfaces)
962 self.pg_start()
963
964 subitf = VppDot1QSubint(self, self.pg1, 99)
965
966 subitf.admin_up()
967 subitf.config_ip6()
968
Neale Ranns03c254e2020-03-17 14:25:10 +0000969 rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None)
Neale Rannsf267d112020-02-07 09:45:07 +0000970
971 #
972 # hunt for the MLD on vlan 99
973 #
974 for rx in rxs:
975 # make sure ipv6 packets with hop by hop options have
976 # correct checksums
977 self.assert_packet_checksums_valid(rx)
978 if rx.haslayer(IPv6ExtHdrHopByHop) and \
979 rx.haslayer(Dot1Q) and \
980 rx[Dot1Q].vlan == 99:
981 mld = rx[ICMPv6MLReport2]
982
983 self.assertEqual(mld.records_number, 4)
984
Neale Ranns3f844d02017-02-18 00:03:54 -0800985
Christian Hoppsf5d38e02020-05-04 10:28:03 -0400986class TestIPv6RouteLookup(VppTestCase):
987 """ IPv6 Route Lookup Test Case """
988 routes = []
989
990 def route_lookup(self, prefix, exact):
991 return self.vapi.api(self.vapi.papi.ip_route_lookup,
992 {
993 'table_id': 0,
994 'exact': exact,
995 'prefix': prefix,
996 })
997
998 @classmethod
999 def setUpClass(cls):
1000 super(TestIPv6RouteLookup, cls).setUpClass()
1001
1002 @classmethod
1003 def tearDownClass(cls):
1004 super(TestIPv6RouteLookup, cls).tearDownClass()
1005
1006 def setUp(self):
1007 super(TestIPv6RouteLookup, self).setUp()
1008
1009 drop_nh = VppRoutePath("::1", 0xffffffff,
1010 type=FibPathType.FIB_PATH_TYPE_DROP)
1011
1012 # Add 3 routes
1013 r = VppIpRoute(self, "2001:1111::", 32, [drop_nh])
1014 r.add_vpp_config()
1015 self.routes.append(r)
1016
1017 r = VppIpRoute(self, "2001:1111:2222::", 48, [drop_nh])
1018 r.add_vpp_config()
1019 self.routes.append(r)
1020
1021 r = VppIpRoute(self, "2001:1111:2222::1", 128, [drop_nh])
1022 r.add_vpp_config()
1023 self.routes.append(r)
1024
1025 def tearDown(self):
1026 # Remove the routes we added
1027 for r in self.routes:
1028 r.remove_vpp_config()
1029
1030 super(TestIPv6RouteLookup, self).tearDown()
1031
1032 def test_exact_match(self):
1033 # Verify we find the host route
1034 prefix = "2001:1111:2222::1/128"
1035 result = self.route_lookup(prefix, True)
1036 assert (prefix == str(result.route.prefix))
1037
1038 # Verify we find a middle prefix route
1039 prefix = "2001:1111:2222::/48"
1040 result = self.route_lookup(prefix, True)
1041 assert (prefix == str(result.route.prefix))
1042
1043 # Verify we do not find an available LPM.
1044 with self.vapi.assert_negative_api_retval():
1045 self.route_lookup("2001::2/128", True)
1046
1047 def test_longest_prefix_match(self):
1048 # verify we find lpm
1049 lpm_prefix = "2001:1111:2222::/48"
1050 result = self.route_lookup("2001:1111:2222::2/128", False)
1051 assert (lpm_prefix == str(result.route.prefix))
1052
1053 # Verify we find the exact when not requested
1054 result = self.route_lookup(lpm_prefix, False)
1055 assert (lpm_prefix == str(result.route.prefix))
1056
1057 # Can't seem to delete the default route so no negative LPM test.
1058
1059
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001060class TestIPv6IfAddrRoute(VppTestCase):
1061 """ IPv6 Interface Addr Route Test Case """
1062
1063 @classmethod
1064 def setUpClass(cls):
1065 super(TestIPv6IfAddrRoute, cls).setUpClass()
1066
1067 @classmethod
1068 def tearDownClass(cls):
1069 super(TestIPv6IfAddrRoute, cls).tearDownClass()
1070
1071 def setUp(self):
1072 super(TestIPv6IfAddrRoute, self).setUp()
1073
1074 # create 1 pg interface
1075 self.create_pg_interfaces(range(1))
1076
1077 for i in self.pg_interfaces:
1078 i.admin_up()
1079 i.config_ip6()
1080 i.resolve_ndp()
1081
1082 def tearDown(self):
1083 super(TestIPv6IfAddrRoute, self).tearDown()
1084 for i in self.pg_interfaces:
1085 i.unconfig_ip6()
1086 i.admin_down()
1087
1088 def test_ipv6_ifaddrs_same_prefix(self):
1089 """ IPv6 Interface Addresses Same Prefix test
1090
1091 Test scenario:
1092
1093 - Verify no route in FIB for prefix 2001:10::/64
1094 - Configure IPv4 address 2001:10::10/64 on an interface
1095 - Verify route in FIB for prefix 2001:10::/64
1096 - Configure IPv4 address 2001:10::20/64 on an interface
1097 - Delete 2001:10::10/64 from interface
1098 - Verify route in FIB for prefix 2001:10::/64
1099 - Delete 2001:10::20/64 from interface
1100 - Verify no route in FIB for prefix 2001:10::/64
1101 """
1102
1103 addr1 = "2001:10::10"
1104 addr2 = "2001:10::20"
1105
Neale Rannsefd7bc22019-11-11 08:32:34 +00001106 if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64)
1107 if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64)
1108 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001109 self.assertFalse(find_route(self, addr1, 128))
1110 self.assertFalse(find_route(self, addr2, 128))
1111
1112 # configure first address, verify route present
1113 if_addr1.add_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001114 self.assertTrue(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001115 self.assertTrue(find_route(self, addr1, 128))
1116 self.assertFalse(find_route(self, addr2, 128))
1117
1118 # configure second address, delete first, verify route not removed
1119 if_addr2.add_vpp_config()
1120 if_addr1.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001121 self.assertFalse(if_addr1.query_vpp_config())
1122 self.assertTrue(if_addr2.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001123 self.assertFalse(find_route(self, addr1, 128))
1124 self.assertTrue(find_route(self, addr2, 128))
1125
1126 # delete second address, verify route removed
1127 if_addr2.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001128 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001129 self.assertFalse(find_route(self, addr1, 128))
1130 self.assertFalse(find_route(self, addr2, 128))
1131
yedgdbd366b2020-05-14 10:51:53 +08001132 def test_ipv6_ifaddr_del(self):
1133 """ Delete an interface address that does not exist """
1134
1135 loopbacks = self.create_loopback_interfaces(1)
1136 lo = self.lo_interfaces[0]
1137
1138 lo.config_ip6()
1139 lo.admin_up()
1140
1141 #
1142 # try and remove pg0's subnet from lo
1143 #
1144 with self.vapi.assert_negative_api_retval():
1145 self.vapi.sw_interface_add_del_address(
1146 sw_if_index=lo.sw_if_index,
1147 prefix=self.pg0.local_ip6_prefix,
1148 is_add=0)
1149
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001150
Jan Geletye6c78ee2018-06-26 12:24:03 +02001151class TestICMPv6Echo(VppTestCase):
1152 """ ICMPv6 Echo Test Case """
1153
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001154 @classmethod
1155 def setUpClass(cls):
1156 super(TestICMPv6Echo, cls).setUpClass()
1157
1158 @classmethod
1159 def tearDownClass(cls):
1160 super(TestICMPv6Echo, cls).tearDownClass()
1161
Jan Geletye6c78ee2018-06-26 12:24:03 +02001162 def setUp(self):
1163 super(TestICMPv6Echo, self).setUp()
1164
1165 # create 1 pg interface
1166 self.create_pg_interfaces(range(1))
1167
1168 for i in self.pg_interfaces:
1169 i.admin_up()
1170 i.config_ip6()
1171 i.resolve_ndp()
1172
1173 def tearDown(self):
1174 super(TestICMPv6Echo, self).tearDown()
1175 for i in self.pg_interfaces:
1176 i.unconfig_ip6()
Jan Geletye6c78ee2018-06-26 12:24:03 +02001177 i.admin_down()
1178
1179 def test_icmpv6_echo(self):
1180 """ VPP replies to ICMPv6 Echo Request
1181
1182 Test scenario:
1183
1184 - Receive ICMPv6 Echo Request message on pg0 interface.
1185 - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
1186 """
1187
1188 icmpv6_id = 0xb
1189 icmpv6_seq = 5
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -08001190 icmpv6_data = b'\x0a' * 18
Jan Geletye6c78ee2018-06-26 12:24:03 +02001191 p_echo_request = (Ether(src=self.pg0.remote_mac,
1192 dst=self.pg0.local_mac) /
1193 IPv6(src=self.pg0.remote_ip6,
1194 dst=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001195 ICMPv6EchoRequest(
1196 id=icmpv6_id,
1197 seq=icmpv6_seq,
1198 data=icmpv6_data))
Jan Geletye6c78ee2018-06-26 12:24:03 +02001199
1200 self.pg0.add_stream(p_echo_request)
1201 self.pg_enable_capture(self.pg_interfaces)
1202 self.pg_start()
1203
1204 rx = self.pg0.get_capture(1)
1205 rx = rx[0]
1206 ether = rx[Ether]
1207 ipv6 = rx[IPv6]
1208 icmpv6 = rx[ICMPv6EchoReply]
1209
1210 self.assertEqual(ether.src, self.pg0.local_mac)
1211 self.assertEqual(ether.dst, self.pg0.remote_mac)
1212
1213 self.assertEqual(ipv6.src, self.pg0.local_ip6)
1214 self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1215
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001216 self.assertEqual(
1217 icmp6types[icmpv6.type], "Echo Reply")
Jan Geletye6c78ee2018-06-26 12:24:03 +02001218 self.assertEqual(icmpv6.id, icmpv6_id)
1219 self.assertEqual(icmpv6.seq, icmpv6_seq)
1220 self.assertEqual(icmpv6.data, icmpv6_data)
1221
1222
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001223class TestIPv6RD(TestIPv6ND):
1224 """ IPv6 Router Discovery Test Case """
1225
1226 @classmethod
1227 def setUpClass(cls):
1228 super(TestIPv6RD, cls).setUpClass()
1229
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001230 @classmethod
1231 def tearDownClass(cls):
1232 super(TestIPv6RD, cls).tearDownClass()
1233
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001234 def setUp(self):
1235 super(TestIPv6RD, self).setUp()
1236
1237 # create 2 pg interfaces
1238 self.create_pg_interfaces(range(2))
1239
1240 self.interfaces = list(self.pg_interfaces)
1241
1242 # setup all interfaces
1243 for i in self.interfaces:
1244 i.admin_up()
1245 i.config_ip6()
1246
1247 def tearDown(self):
Neale Ranns744902e2017-08-14 10:35:44 -07001248 for i in self.interfaces:
1249 i.unconfig_ip6()
1250 i.admin_down()
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001251 super(TestIPv6RD, self).tearDown()
1252
1253 def test_rd_send_router_solicitation(self):
1254 """ Verify router solicitation packets """
1255
1256 count = 2
1257 self.pg_enable_capture(self.pg_interfaces)
1258 self.pg_start()
1259 self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1260 mrc=count)
1261 rx_list = self.pg1.get_capture(count, timeout=3)
1262 self.assertEqual(len(rx_list), count)
1263 for packet in rx_list:
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001264 self.assertEqual(packet.haslayer(IPv6), 1)
1265 self.assertEqual(packet[IPv6].haslayer(
1266 ICMPv6ND_RS), 1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001267 dst = ip6_normalize(packet[IPv6].dst)
1268 dst2 = ip6_normalize("ff02::2")
1269 self.assert_equal(dst, dst2)
1270 src = ip6_normalize(packet[IPv6].src)
1271 src2 = ip6_normalize(self.pg1.local_ip6_ll)
1272 self.assert_equal(src, src2)
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001273 self.assertTrue(
1274 bool(packet[ICMPv6ND_RS].haslayer(
1275 ICMPv6NDOptSrcLLAddr)))
1276 self.assert_equal(
1277 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1278 self.pg1.local_mac)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001279
1280 def verify_prefix_info(self, reported_prefix, prefix_option):
Neale Ranns37029302018-08-10 05:30:06 -07001281 prefix = IPv6Network(
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -08001282 text_type(prefix_option.getfieldval("prefix") +
1283 "/" +
1284 text_type(prefix_option.getfieldval("prefixlen"))),
Neale Ranns37029302018-08-10 05:30:06 -07001285 strict=False)
1286 self.assert_equal(reported_prefix.prefix.network_address,
1287 prefix.network_address)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001288 L = prefix_option.getfieldval("L")
1289 A = prefix_option.getfieldval("A")
1290 option_flags = (L << 7) | (A << 6)
1291 self.assert_equal(reported_prefix.flags, option_flags)
1292 self.assert_equal(reported_prefix.valid_time,
1293 prefix_option.getfieldval("validlifetime"))
1294 self.assert_equal(reported_prefix.preferred_time,
1295 prefix_option.getfieldval("preferredlifetime"))
1296
1297 def test_rd_receive_router_advertisement(self):
1298 """ Verify events triggered by received RA packets """
1299
Neale Rannscbe25aa2019-09-30 10:53:31 +00001300 self.vapi.want_ip6_ra_events(enable=1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001301
1302 prefix_info_1 = ICMPv6NDOptPrefixInfo(
1303 prefix="1::2",
1304 prefixlen=50,
1305 validlifetime=200,
1306 preferredlifetime=500,
1307 L=1,
1308 A=1,
1309 )
1310
1311 prefix_info_2 = ICMPv6NDOptPrefixInfo(
1312 prefix="7::4",
1313 prefixlen=20,
1314 validlifetime=70,
1315 preferredlifetime=1000,
1316 L=1,
1317 A=0,
1318 )
1319
1320 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1321 IPv6(dst=self.pg1.local_ip6_ll,
1322 src=mk_ll_addr(self.pg1.remote_mac)) /
1323 ICMPv6ND_RA() /
1324 prefix_info_1 /
1325 prefix_info_2)
1326 self.pg1.add_stream([p])
1327 self.pg_start()
1328
1329 ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1330
1331 self.assert_equal(ev.current_hop_limit, 0)
1332 self.assert_equal(ev.flags, 8)
1333 self.assert_equal(ev.router_lifetime_in_sec, 1800)
1334 self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1335 self.assert_equal(
1336 ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1337
1338 self.assert_equal(ev.n_prefixes, 2)
1339
1340 self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1341 self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1342
1343
Juraj Slobodac0374232018-02-01 15:18:49 +01001344class TestIPv6RDControlPlane(TestIPv6ND):
1345 """ IPv6 Router Discovery Control Plane Test Case """
1346
1347 @classmethod
1348 def setUpClass(cls):
1349 super(TestIPv6RDControlPlane, cls).setUpClass()
1350
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001351 @classmethod
1352 def tearDownClass(cls):
1353 super(TestIPv6RDControlPlane, cls).tearDownClass()
1354
Juraj Slobodac0374232018-02-01 15:18:49 +01001355 def setUp(self):
1356 super(TestIPv6RDControlPlane, self).setUp()
1357
1358 # create 1 pg interface
1359 self.create_pg_interfaces(range(1))
1360
1361 self.interfaces = list(self.pg_interfaces)
1362
1363 # setup all interfaces
1364 for i in self.interfaces:
1365 i.admin_up()
1366 i.config_ip6()
1367
1368 def tearDown(self):
1369 super(TestIPv6RDControlPlane, self).tearDown()
1370
1371 @staticmethod
1372 def create_ra_packet(pg, routerlifetime=None):
1373 src_ip = pg.remote_ip6_ll
1374 dst_ip = pg.local_ip6
1375 if routerlifetime is not None:
1376 ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1377 else:
1378 ra = ICMPv6ND_RA()
1379 p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1380 IPv6(dst=dst_ip, src=src_ip) / ra)
1381 return p
1382
1383 @staticmethod
1384 def get_default_routes(fib):
1385 list = []
1386 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001387 if entry.route.prefix.prefixlen == 0:
1388 for path in entry.route.paths:
Juraj Slobodac0374232018-02-01 15:18:49 +01001389 if path.sw_if_index != 0xFFFFFFFF:
Neale Ranns097fa662018-05-01 05:17:55 -07001390 defaut_route = {}
1391 defaut_route['sw_if_index'] = path.sw_if_index
1392 defaut_route['next_hop'] = path.nh.address.ip6
1393 list.append(defaut_route)
Juraj Slobodac0374232018-02-01 15:18:49 +01001394 return list
1395
1396 @staticmethod
1397 def get_interface_addresses(fib, pg):
1398 list = []
1399 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001400 if entry.route.prefix.prefixlen == 128:
1401 path = entry.route.paths[0]
Juraj Slobodac0374232018-02-01 15:18:49 +01001402 if path.sw_if_index == pg.sw_if_index:
Neale Ranns097fa662018-05-01 05:17:55 -07001403 list.append(str(entry.route.prefix.network_address))
Juraj Slobodac0374232018-02-01 15:18:49 +01001404 return list
1405
Neale Rannscbe25aa2019-09-30 10:53:31 +00001406 def wait_for_no_default_route(self, n_tries=50, s_time=1):
1407 while (n_tries):
1408 fib = self.vapi.ip_route_dump(0, True)
1409 default_routes = self.get_default_routes(fib)
Ole Troan6e6ad642020-02-04 13:28:13 +01001410 if 0 == len(default_routes):
Neale Rannscbe25aa2019-09-30 10:53:31 +00001411 return True
1412 n_tries = n_tries - 1
1413 self.sleep(s_time)
1414
1415 return False
1416
Juraj Slobodac0374232018-02-01 15:18:49 +01001417 def test_all(self):
1418 """ Test handling of SLAAC addresses and default routes """
1419
Neale Ranns097fa662018-05-01 05:17:55 -07001420 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001421 default_routes = self.get_default_routes(fib)
1422 initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1423 self.assertEqual(default_routes, [])
Neale Ranns097fa662018-05-01 05:17:55 -07001424 router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll))
Juraj Slobodac0374232018-02-01 15:18:49 +01001425
1426 self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1427
1428 self.sleep(0.1)
1429
1430 # send RA
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001431 packet = (self.create_ra_packet(
1432 self.pg0) / ICMPv6NDOptPrefixInfo(
Juraj Slobodac0374232018-02-01 15:18:49 +01001433 prefix="1::",
1434 prefixlen=64,
1435 validlifetime=2,
1436 preferredlifetime=2,
1437 L=1,
1438 A=1,
1439 ) / ICMPv6NDOptPrefixInfo(
1440 prefix="7::",
1441 prefixlen=20,
1442 validlifetime=1500,
1443 preferredlifetime=1000,
1444 L=1,
1445 A=0,
1446 ))
1447 self.pg0.add_stream([packet])
1448 self.pg_start()
1449
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001450 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001451
Neale Ranns097fa662018-05-01 05:17:55 -07001452 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001453
1454 # check FIB for new address
1455 addresses = set(self.get_interface_addresses(fib, self.pg0))
1456 new_addresses = addresses.difference(initial_addresses)
1457 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001458 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1459 strict=False)
1460 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001461
1462 # check FIB for new default route
1463 default_routes = self.get_default_routes(fib)
1464 self.assertEqual(len(default_routes), 1)
1465 dr = default_routes[0]
1466 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1467 self.assertEqual(dr['next_hop'], router_address)
1468
1469 # send RA to delete default route
1470 packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1471 self.pg0.add_stream([packet])
1472 self.pg_start()
1473
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001474 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001475
1476 # check that default route is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001477 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001478 default_routes = self.get_default_routes(fib)
1479 self.assertEqual(len(default_routes), 0)
1480
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001481 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001482
1483 # send RA
1484 packet = self.create_ra_packet(self.pg0)
1485 self.pg0.add_stream([packet])
1486 self.pg_start()
1487
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001488 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001489
1490 # check FIB for new default route
Neale Ranns097fa662018-05-01 05:17:55 -07001491 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001492 default_routes = self.get_default_routes(fib)
1493 self.assertEqual(len(default_routes), 1)
1494 dr = default_routes[0]
1495 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1496 self.assertEqual(dr['next_hop'], router_address)
1497
1498 # send RA, updating router lifetime to 1s
1499 packet = self.create_ra_packet(self.pg0, 1)
1500 self.pg0.add_stream([packet])
1501 self.pg_start()
1502
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001503 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001504
1505 # check that default route still exists
Neale Ranns097fa662018-05-01 05:17:55 -07001506 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001507 default_routes = self.get_default_routes(fib)
1508 self.assertEqual(len(default_routes), 1)
1509 dr = default_routes[0]
1510 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1511 self.assertEqual(dr['next_hop'], router_address)
1512
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001513 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001514
1515 # check that default route is deleted
Neale Rannscbe25aa2019-09-30 10:53:31 +00001516 self.assertTrue(self.wait_for_no_default_route())
Juraj Slobodac0374232018-02-01 15:18:49 +01001517
1518 # check FIB still contains the SLAAC address
1519 addresses = set(self.get_interface_addresses(fib, self.pg0))
1520 new_addresses = addresses.difference(initial_addresses)
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001521
Juraj Slobodac0374232018-02-01 15:18:49 +01001522 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001523 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1524 strict=False)
1525 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001526
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001527 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001528
1529 # check that SLAAC address is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001530 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001531 addresses = set(self.get_interface_addresses(fib, self.pg0))
1532 new_addresses = addresses.difference(initial_addresses)
1533 self.assertEqual(len(new_addresses), 0)
1534
1535
Neale Ranns3f844d02017-02-18 00:03:54 -08001536class IPv6NDProxyTest(TestIPv6ND):
1537 """ IPv6 ND ProxyTest Case """
1538
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001539 @classmethod
1540 def setUpClass(cls):
1541 super(IPv6NDProxyTest, cls).setUpClass()
1542
1543 @classmethod
1544 def tearDownClass(cls):
1545 super(IPv6NDProxyTest, cls).tearDownClass()
1546
Neale Ranns3f844d02017-02-18 00:03:54 -08001547 def setUp(self):
1548 super(IPv6NDProxyTest, self).setUp()
1549
1550 # create 3 pg interfaces
1551 self.create_pg_interfaces(range(3))
1552
1553 # pg0 is the master interface, with the configured subnet
1554 self.pg0.admin_up()
1555 self.pg0.config_ip6()
1556 self.pg0.resolve_ndp()
1557
1558 self.pg1.ip6_enable()
1559 self.pg2.ip6_enable()
1560
1561 def tearDown(self):
1562 super(IPv6NDProxyTest, self).tearDown()
1563
1564 def test_nd_proxy(self):
1565 """ IPv6 Proxy ND """
1566
1567 #
1568 # Generate some hosts in the subnet that we are proxying
1569 #
1570 self.pg0.generate_remote_hosts(8)
1571
1572 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1573 d = inet_ntop(AF_INET6, nsma)
1574
1575 #
1576 # Send an NS for one of those remote hosts on one of the proxy links
1577 # expect no response since it's from an address that is not
1578 # on the link that has the prefix configured
1579 #
1580 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001581 IPv6(dst=d,
1582 src=self.pg0._remote_hosts[2].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001583 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001584 ICMPv6NDOptSrcLLAddr(
1585 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001586
1587 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1588
1589 #
1590 # Add proxy support for the host
1591 #
Ole Troane1ade682019-03-04 23:55:43 +01001592 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001593 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001594 sw_if_index=self.pg1.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001595
1596 #
1597 # try that NS again. this time we expect an NA back
1598 #
Neale Ranns2a3ea492017-04-19 05:24:40 -07001599 self.send_and_expect_na(self.pg1, ns_pg1,
1600 "NS to proxy entry",
1601 dst_ip=self.pg0._remote_hosts[2].ip6,
1602 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001603
1604 #
1605 # ... and that we have an entry in the ND cache
1606 #
1607 self.assertTrue(find_nbr(self,
1608 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001609 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001610
1611 #
1612 # ... and we can route traffic to it
1613 #
1614 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1615 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1616 src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001617 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001618 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001619
1620 self.pg0.add_stream(t)
1621 self.pg_enable_capture(self.pg_interfaces)
1622 self.pg_start()
1623 rx = self.pg1.get_capture(1)
1624 rx = rx[0]
1625
1626 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1627 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1628
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001629 self.assertEqual(rx[IPv6].src,
1630 t[IPv6].src)
1631 self.assertEqual(rx[IPv6].dst,
1632 t[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001633
1634 #
1635 # Test we proxy for the host on the main interface
1636 #
1637 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1638 IPv6(dst=d, src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001639 ICMPv6ND_NS(
1640 tgt=self.pg0._remote_hosts[2].ip6) /
1641 ICMPv6NDOptSrcLLAddr(
1642 lladdr=self.pg0.remote_mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001643
Neale Ranns2a3ea492017-04-19 05:24:40 -07001644 self.send_and_expect_na(self.pg0, ns_pg0,
1645 "NS to proxy entry on main",
1646 tgt_ip=self.pg0._remote_hosts[2].ip6,
1647 dst_ip=self.pg0.remote_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001648
1649 #
1650 # Setup and resolve proxy for another host on another interface
1651 #
1652 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001653 IPv6(dst=d,
1654 src=self.pg0._remote_hosts[3].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001655 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001656 ICMPv6NDOptSrcLLAddr(
1657 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001658
Ole Troane1ade682019-03-04 23:55:43 +01001659 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001660 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001661 sw_if_index=self.pg2.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001662
Neale Ranns2a3ea492017-04-19 05:24:40 -07001663 self.send_and_expect_na(self.pg2, ns_pg2,
1664 "NS to proxy entry other interface",
1665 dst_ip=self.pg0._remote_hosts[3].ip6,
1666 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001667
1668 self.assertTrue(find_nbr(self,
1669 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001670 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001671
1672 #
1673 # hosts can communicate. pg2->pg1
1674 #
1675 t2 = (Ether(dst=self.pg2.local_mac,
1676 src=self.pg0.remote_hosts[3].mac) /
1677 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1678 src=self.pg0._remote_hosts[3].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001679 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001680 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001681
1682 self.pg2.add_stream(t2)
1683 self.pg_enable_capture(self.pg_interfaces)
1684 self.pg_start()
1685 rx = self.pg1.get_capture(1)
1686 rx = rx[0]
1687
1688 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1689 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1690
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001691 self.assertEqual(rx[IPv6].src,
1692 t2[IPv6].src)
1693 self.assertEqual(rx[IPv6].dst,
1694 t2[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001695
1696 #
1697 # remove the proxy configs
1698 #
Ole Troane1ade682019-03-04 23:55:43 +01001699 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001700 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001701 sw_if_index=self.pg1.sw_if_index, is_add=0)
Ole Troane1ade682019-03-04 23:55:43 +01001702 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001703 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001704 sw_if_index=self.pg2.sw_if_index, is_add=0)
Neale Ranns3f844d02017-02-18 00:03:54 -08001705
1706 self.assertFalse(find_nbr(self,
1707 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001708 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001709 self.assertFalse(find_nbr(self,
1710 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001711 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001712
1713 #
1714 # no longer proxy-ing...
1715 #
1716 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1717 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1718 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1719
1720 #
1721 # no longer forwarding. traffic generates NS out of the glean/main
1722 # interface
1723 #
1724 self.pg2.add_stream(t2)
1725 self.pg_enable_capture(self.pg_interfaces)
1726 self.pg_start()
1727
1728 rx = self.pg0.get_capture(1)
1729
1730 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1731
1732
Neale Ranns37be7362017-02-21 17:30:26 -08001733class TestIPNull(VppTestCase):
1734 """ IPv6 routes via NULL """
1735
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001736 @classmethod
1737 def setUpClass(cls):
1738 super(TestIPNull, cls).setUpClass()
1739
1740 @classmethod
1741 def tearDownClass(cls):
1742 super(TestIPNull, cls).tearDownClass()
1743
Neale Ranns37be7362017-02-21 17:30:26 -08001744 def setUp(self):
1745 super(TestIPNull, self).setUp()
1746
1747 # create 2 pg interfaces
1748 self.create_pg_interfaces(range(1))
1749
1750 for i in self.pg_interfaces:
1751 i.admin_up()
1752 i.config_ip6()
1753 i.resolve_ndp()
1754
1755 def tearDown(self):
1756 super(TestIPNull, self).tearDown()
1757 for i in self.pg_interfaces:
1758 i.unconfig_ip6()
1759 i.admin_down()
1760
1761 def test_ip_null(self):
1762 """ IP NULL route """
1763
1764 p = (Ether(src=self.pg0.remote_mac,
1765 dst=self.pg0.local_mac) /
1766 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001767 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001768 Raw(b'\xa5' * 100))
Neale Ranns37be7362017-02-21 17:30:26 -08001769
1770 #
1771 # A route via IP NULL that will reply with ICMP unreachables
1772 #
Neale Ranns097fa662018-05-01 05:17:55 -07001773 ip_unreach = VppIpRoute(
1774 self, "2001::", 64,
1775 [VppRoutePath("::", 0xffffffff,
1776 type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)])
Neale Ranns37be7362017-02-21 17:30:26 -08001777 ip_unreach.add_vpp_config()
1778
1779 self.pg0.add_stream(p)
1780 self.pg_enable_capture(self.pg_interfaces)
1781 self.pg_start()
1782
1783 rx = self.pg0.get_capture(1)
1784 rx = rx[0]
1785 icmp = rx[ICMPv6DestUnreach]
1786
1787 # 0 = "No route to destination"
1788 self.assertEqual(icmp.code, 0)
1789
1790 # ICMP is rate limited. pause a bit
1791 self.sleep(1)
1792
1793 #
1794 # A route via IP NULL that will reply with ICMP prohibited
1795 #
Neale Ranns097fa662018-05-01 05:17:55 -07001796 ip_prohibit = VppIpRoute(
1797 self, "2001::1", 128,
1798 [VppRoutePath("::", 0xffffffff,
1799 type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)])
Neale Ranns37be7362017-02-21 17:30:26 -08001800 ip_prohibit.add_vpp_config()
1801
1802 self.pg0.add_stream(p)
1803 self.pg_enable_capture(self.pg_interfaces)
1804 self.pg_start()
1805
1806 rx = self.pg0.get_capture(1)
1807 rx = rx[0]
1808 icmp = rx[ICMPv6DestUnreach]
1809
1810 # 1 = "Communication with destination administratively prohibited"
1811 self.assertEqual(icmp.code, 1)
1812
1813
Neale Ranns180279b2017-03-16 15:49:09 -04001814class TestIPDisabled(VppTestCase):
1815 """ IPv6 disabled """
1816
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001817 @classmethod
1818 def setUpClass(cls):
1819 super(TestIPDisabled, cls).setUpClass()
1820
1821 @classmethod
1822 def tearDownClass(cls):
1823 super(TestIPDisabled, cls).tearDownClass()
1824
Neale Ranns180279b2017-03-16 15:49:09 -04001825 def setUp(self):
1826 super(TestIPDisabled, self).setUp()
1827
1828 # create 2 pg interfaces
1829 self.create_pg_interfaces(range(2))
1830
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001831 # PG0 is IP enabled
Neale Ranns180279b2017-03-16 15:49:09 -04001832 self.pg0.admin_up()
1833 self.pg0.config_ip6()
1834 self.pg0.resolve_ndp()
1835
1836 # PG 1 is not IP enabled
1837 self.pg1.admin_up()
1838
1839 def tearDown(self):
1840 super(TestIPDisabled, self).tearDown()
1841 for i in self.pg_interfaces:
1842 i.unconfig_ip4()
1843 i.admin_down()
1844
Neale Ranns180279b2017-03-16 15:49:09 -04001845 def test_ip_disabled(self):
1846 """ IP Disabled """
1847
1848 #
1849 # An (S,G).
1850 # one accepting interface, pg0, 2 forwarding interfaces
1851 #
1852 route_ff_01 = VppIpMRoute(
1853 self,
1854 "::",
1855 "ffef::1", 128,
1856 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1857 [VppMRoutePath(self.pg1.sw_if_index,
1858 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1859 VppMRoutePath(self.pg0.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07001860 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns180279b2017-03-16 15:49:09 -04001861 route_ff_01.add_vpp_config()
1862
1863 pu = (Ether(src=self.pg1.remote_mac,
1864 dst=self.pg1.local_mac) /
1865 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001866 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001867 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001868 pm = (Ether(src=self.pg1.remote_mac,
1869 dst=self.pg1.local_mac) /
1870 IPv6(src="2001::1", dst="ffef::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001871 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001872 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001873
1874 #
1875 # PG1 does not forward IP traffic
1876 #
1877 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1878 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1879
1880 #
1881 # IP enable PG1
1882 #
1883 self.pg1.config_ip6()
1884
1885 #
1886 # Now we get packets through
1887 #
1888 self.pg1.add_stream(pu)
1889 self.pg_enable_capture(self.pg_interfaces)
1890 self.pg_start()
1891 rx = self.pg0.get_capture(1)
1892
1893 self.pg1.add_stream(pm)
1894 self.pg_enable_capture(self.pg_interfaces)
1895 self.pg_start()
1896 rx = self.pg0.get_capture(1)
1897
1898 #
1899 # Disable PG1
1900 #
1901 self.pg1.unconfig_ip6()
1902
1903 #
1904 # PG1 does not forward IP traffic
1905 #
1906 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1907 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1908
1909
Neale Ranns227038a2017-04-21 01:07:59 -07001910class TestIP6LoadBalance(VppTestCase):
1911 """ IPv6 Load-Balancing """
1912
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001913 @classmethod
1914 def setUpClass(cls):
1915 super(TestIP6LoadBalance, cls).setUpClass()
1916
1917 @classmethod
1918 def tearDownClass(cls):
1919 super(TestIP6LoadBalance, cls).tearDownClass()
1920
Neale Ranns227038a2017-04-21 01:07:59 -07001921 def setUp(self):
1922 super(TestIP6LoadBalance, self).setUp()
1923
1924 self.create_pg_interfaces(range(5))
1925
Neale Ranns15002542017-09-10 04:39:11 -07001926 mpls_tbl = VppMplsTable(self, 0)
1927 mpls_tbl.add_vpp_config()
1928
Neale Ranns227038a2017-04-21 01:07:59 -07001929 for i in self.pg_interfaces:
1930 i.admin_up()
1931 i.config_ip6()
1932 i.resolve_ndp()
Neale Ranns71275e32017-05-25 12:38:58 -07001933 i.enable_mpls()
Neale Ranns227038a2017-04-21 01:07:59 -07001934
1935 def tearDown(self):
Neale Ranns227038a2017-04-21 01:07:59 -07001936 for i in self.pg_interfaces:
1937 i.unconfig_ip6()
1938 i.admin_down()
Neale Ranns71275e32017-05-25 12:38:58 -07001939 i.disable_mpls()
Neale Ranns15002542017-09-10 04:39:11 -07001940 super(TestIP6LoadBalance, self).tearDown()
Neale Ranns227038a2017-04-21 01:07:59 -07001941
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001942 def pg_send(self, input, pkts):
Neale Ranns62fe07c2017-10-31 12:28:22 -07001943 self.vapi.cli("clear trace")
Neale Ranns227038a2017-04-21 01:07:59 -07001944 input.add_stream(pkts)
1945 self.pg_enable_capture(self.pg_interfaces)
1946 self.pg_start()
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001947
1948 def send_and_expect_load_balancing(self, input, pkts, outputs):
1949 self.pg_send(input, pkts)
Neale Ranns227038a2017-04-21 01:07:59 -07001950 for oo in outputs:
1951 rx = oo._get_capture(1)
1952 self.assertNotEqual(0, len(rx))
1953
Neale Ranns71275e32017-05-25 12:38:58 -07001954 def send_and_expect_one_itf(self, input, pkts, itf):
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001955 self.pg_send(input, pkts)
Neale Ranns71275e32017-05-25 12:38:58 -07001956 rx = itf.get_capture(len(pkts))
1957
Neale Ranns227038a2017-04-21 01:07:59 -07001958 def test_ip6_load_balance(self):
1959 """ IPv6 Load-Balancing """
1960
1961 #
1962 # An array of packets that differ only in the destination port
Neale Ranns71275e32017-05-25 12:38:58 -07001963 # - IP only
1964 # - MPLS EOS
1965 # - MPLS non-EOS
1966 # - MPLS non-EOS with an entropy label
Neale Ranns227038a2017-04-21 01:07:59 -07001967 #
Neale Ranns71275e32017-05-25 12:38:58 -07001968 port_ip_pkts = []
1969 port_mpls_pkts = []
1970 port_mpls_neos_pkts = []
1971 port_ent_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001972
1973 #
1974 # An array of packets that differ only in the source address
1975 #
Neale Ranns71275e32017-05-25 12:38:58 -07001976 src_ip_pkts = []
1977 src_mpls_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001978
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001979 for ii in range(NUM_PKTS):
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001980 port_ip_hdr = (
1981 IPv6(dst="3000::1", src="3000:1::1") /
1982 inet6.UDP(sport=1234, dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01001983 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001984 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1985 dst=self.pg0.local_mac) /
1986 port_ip_hdr))
1987 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1988 dst=self.pg0.local_mac) /
1989 MPLS(label=66, ttl=2) /
1990 port_ip_hdr))
1991 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1992 dst=self.pg0.local_mac) /
1993 MPLS(label=67, ttl=2) /
1994 MPLS(label=77, ttl=2) /
1995 port_ip_hdr))
1996 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1997 dst=self.pg0.local_mac) /
1998 MPLS(label=67, ttl=2) /
1999 MPLS(label=14, ttl=2) /
2000 MPLS(label=999, ttl=2) /
2001 port_ip_hdr))
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002002 src_ip_hdr = (
2003 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
2004 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002005 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07002006 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
2007 dst=self.pg0.local_mac) /
2008 src_ip_hdr))
2009 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
2010 dst=self.pg0.local_mac) /
2011 MPLS(label=66, ttl=2) /
2012 src_ip_hdr))
Neale Ranns227038a2017-04-21 01:07:59 -07002013
Neale Ranns71275e32017-05-25 12:38:58 -07002014 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002015 # A route for the IP packets
Neale Ranns71275e32017-05-25 12:38:58 -07002016 #
Neale Ranns227038a2017-04-21 01:07:59 -07002017 route_3000_1 = VppIpRoute(self, "3000::1", 128,
2018 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002019 self.pg1.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002020 VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002021 self.pg2.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002022 route_3000_1.add_vpp_config()
2023
2024 #
Neale Ranns71275e32017-05-25 12:38:58 -07002025 # a local-label for the EOS packets
2026 #
2027 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
2028 binding.add_vpp_config()
2029
2030 #
2031 # An MPLS route for the non-EOS packets
2032 #
2033 route_67 = VppMplsRoute(self, 67, 0,
2034 [VppRoutePath(self.pg1.remote_ip6,
2035 self.pg1.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07002036 labels=[67]),
Neale Ranns71275e32017-05-25 12:38:58 -07002037 VppRoutePath(self.pg2.remote_ip6,
2038 self.pg2.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07002039 labels=[67])])
Neale Ranns71275e32017-05-25 12:38:58 -07002040 route_67.add_vpp_config()
2041
2042 #
Neale Ranns227038a2017-04-21 01:07:59 -07002043 # inject the packet on pg0 - expect load-balancing across the 2 paths
2044 # - since the default hash config is to use IP src,dst and port
2045 # src,dst
2046 # We are not going to ensure equal amounts of packets across each link,
2047 # since the hash algorithm is statistical and therefore this can never
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002048 # be guaranteed. But with 64 different packets we do expect some
Neale Ranns227038a2017-04-21 01:07:59 -07002049 # balancing. So instead just ensure there is traffic on each link.
2050 #
Neale Ranns71275e32017-05-25 12:38:58 -07002051 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002052 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002053 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002054 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002055 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
2056 [self.pg1, self.pg2])
2057 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2058 [self.pg1, self.pg2])
2059 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
2060 [self.pg1, self.pg2])
2061
2062 #
2063 # The packets with Entropy label in should not load-balance,
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002064 # since the Entropy value is fixed.
Neale Ranns71275e32017-05-25 12:38:58 -07002065 #
2066 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
Neale Ranns227038a2017-04-21 01:07:59 -07002067
2068 #
2069 # change the flow hash config so it's only IP src,dst
2070 # - now only the stream with differing source address will
2071 # load-balance
2072 #
Ole Troana5b2eec2019-03-11 19:23:25 +01002073 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0,
2074 is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07002075
Neale Ranns71275e32017-05-25 12:38:58 -07002076 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002077 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002078 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2079 [self.pg1, self.pg2])
2080 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
Neale Ranns227038a2017-04-21 01:07:59 -07002081
2082 #
2083 # change the flow hash config back to defaults
2084 #
Ole Troana5b2eec2019-03-11 19:23:25 +01002085 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1,
2086 is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07002087
2088 #
2089 # Recursive prefixes
2090 # - testing that 2 stages of load-balancing occurs and there is no
2091 # polarisation (i.e. only 2 of 4 paths are used)
2092 #
2093 port_pkts = []
2094 src_pkts = []
2095
2096 for ii in range(257):
2097 port_pkts.append((Ether(src=self.pg0.remote_mac,
2098 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002099 IPv6(dst="4000::1",
2100 src="4000:1::1") /
2101 inet6.UDP(sport=1234,
2102 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002103 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002104 src_pkts.append((Ether(src=self.pg0.remote_mac,
2105 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002106 IPv6(dst="4000::1",
2107 src="4000:1::%d" % ii) /
2108 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002109 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002110
2111 route_3000_2 = VppIpRoute(self, "3000::2", 128,
2112 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002113 self.pg3.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002114 VppRoutePath(self.pg4.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002115 self.pg4.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002116 route_3000_2.add_vpp_config()
2117
2118 route_4000_1 = VppIpRoute(self, "4000::1", 128,
2119 [VppRoutePath("3000::1",
Neale Ranns097fa662018-05-01 05:17:55 -07002120 0xffffffff),
Neale Ranns227038a2017-04-21 01:07:59 -07002121 VppRoutePath("3000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002122 0xffffffff)])
Neale Ranns227038a2017-04-21 01:07:59 -07002123 route_4000_1.add_vpp_config()
2124
2125 #
2126 # inject the packet on pg0 - expect load-balancing across all 4 paths
2127 #
2128 self.vapi.cli("clear trace")
2129 self.send_and_expect_load_balancing(self.pg0, port_pkts,
2130 [self.pg1, self.pg2,
2131 self.pg3, self.pg4])
2132 self.send_and_expect_load_balancing(self.pg0, src_pkts,
2133 [self.pg1, self.pg2,
2134 self.pg3, self.pg4])
2135
Neale Ranns42e6b092017-07-31 02:56:03 -07002136 #
2137 # Recursive prefixes
2138 # - testing that 2 stages of load-balancing no choices
2139 #
2140 port_pkts = []
2141
2142 for ii in range(257):
2143 port_pkts.append((Ether(src=self.pg0.remote_mac,
2144 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002145 IPv6(dst="6000::1",
2146 src="6000:1::1") /
2147 inet6.UDP(sport=1234,
2148 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002149 Raw(b'\xa5' * 100)))
Neale Ranns42e6b092017-07-31 02:56:03 -07002150
2151 route_5000_2 = VppIpRoute(self, "5000::2", 128,
2152 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002153 self.pg3.sw_if_index)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002154 route_5000_2.add_vpp_config()
2155
2156 route_6000_1 = VppIpRoute(self, "6000::1", 128,
2157 [VppRoutePath("5000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002158 0xffffffff)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002159 route_6000_1.add_vpp_config()
2160
2161 #
2162 # inject the packet on pg0 - expect load-balancing across all 4 paths
2163 #
2164 self.vapi.cli("clear trace")
2165 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
2166
Neale Ranns227038a2017-04-21 01:07:59 -07002167
Neale Rannsd91c1db2017-07-31 02:30:50 -07002168class TestIP6Punt(VppTestCase):
2169 """ IPv6 Punt Police/Redirect """
2170
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002171 @classmethod
2172 def setUpClass(cls):
2173 super(TestIP6Punt, cls).setUpClass()
2174
2175 @classmethod
2176 def tearDownClass(cls):
2177 super(TestIP6Punt, cls).tearDownClass()
2178
Neale Rannsd91c1db2017-07-31 02:30:50 -07002179 def setUp(self):
2180 super(TestIP6Punt, self).setUp()
2181
Pavel Kotucek609e1212018-11-27 09:59:44 +01002182 self.create_pg_interfaces(range(4))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002183
2184 for i in self.pg_interfaces:
2185 i.admin_up()
2186 i.config_ip6()
2187 i.resolve_ndp()
2188
2189 def tearDown(self):
2190 super(TestIP6Punt, self).tearDown()
2191 for i in self.pg_interfaces:
2192 i.unconfig_ip6()
2193 i.admin_down()
2194
Neale Rannsd91c1db2017-07-31 02:30:50 -07002195 def test_ip_punt(self):
2196 """ IP6 punt police and redirect """
2197
2198 p = (Ether(src=self.pg0.remote_mac,
2199 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002200 IPv6(src=self.pg0.remote_ip6,
2201 dst=self.pg0.local_ip6) /
2202 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002203 Raw(b'\xa5' * 100))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002204
2205 pkts = p * 1025
2206
2207 #
2208 # Configure a punt redirect via pg1.
2209 #
Ole Troan0bcad322018-12-11 13:04:01 +01002210 nh_addr = self.pg1.remote_ip6
Neale Rannsd91c1db2017-07-31 02:30:50 -07002211 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2212 self.pg1.sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002213 nh_addr)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002214
2215 self.send_and_expect(self.pg0, pkts, self.pg1)
2216
2217 #
2218 # add a policer
2219 #
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002220 policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1)
2221 policer.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002222 self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
2223
2224 self.vapi.cli("clear trace")
2225 self.pg0.add_stream(pkts)
2226 self.pg_enable_capture(self.pg_interfaces)
2227 self.pg_start()
2228
2229 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002230 # the number of packet received should be greater than 0,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002231 # but not equal to the number sent, since some were policed
2232 #
2233 rx = self.pg1._get_capture(1)
Paul Vinciguerra3d2df212018-11-24 23:19:53 -08002234 self.assertGreater(len(rx), 0)
2235 self.assertLess(len(rx), len(pkts))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002236
2237 #
Paul Vinciguerraeb414432019-02-20 09:01:14 -08002238 # remove the policer. back to full rx
Neale Rannsd91c1db2017-07-31 02:30:50 -07002239 #
2240 self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002241 policer.remove_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002242 self.send_and_expect(self.pg0, pkts, self.pg1)
2243
2244 #
2245 # remove the redirect. expect full drop.
2246 #
2247 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2248 self.pg1.sw_if_index,
2249 nh_addr,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002250 is_add=0)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002251 self.send_and_assert_no_replies(self.pg0, pkts,
2252 "IP no punt config")
2253
2254 #
2255 # Add a redirect that is not input port selective
2256 #
2257 self.vapi.ip_punt_redirect(0xffffffff,
2258 self.pg1.sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002259 nh_addr)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002260 self.send_and_expect(self.pg0, pkts, self.pg1)
2261
2262 self.vapi.ip_punt_redirect(0xffffffff,
2263 self.pg1.sw_if_index,
2264 nh_addr,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002265 is_add=0)
2266
2267 def test_ip_punt_dump(self):
2268 """ IP6 punt redirect dump"""
2269
2270 #
2271 # Configure a punt redirects
2272 #
Ole Troan0bcad322018-12-11 13:04:01 +01002273 nh_addr = self.pg3.remote_ip6
Pavel Kotucek609e1212018-11-27 09:59:44 +01002274 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2275 self.pg3.sw_if_index,
2276 nh_addr)
2277 self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
2278 self.pg3.sw_if_index,
2279 nh_addr)
2280 self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
2281 self.pg3.sw_if_index,
Ole Troan0bcad322018-12-11 13:04:01 +01002282 '0::0')
Pavel Kotucek609e1212018-11-27 09:59:44 +01002283
2284 #
2285 # Dump pg0 punt redirects
2286 #
2287 punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
2288 is_ipv6=1)
2289 for p in punts:
2290 self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
2291
2292 #
2293 # Dump punt redirects for all interfaces
2294 #
2295 punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2296 self.assertEqual(len(punts), 3)
2297 for p in punts:
2298 self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
Ole Troan0bcad322018-12-11 13:04:01 +01002299 self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2300 self.assertEqual(str(punts[2].punt.nh), '::')
Neale Rannsd91c1db2017-07-31 02:30:50 -07002301
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002302
Neale Rannsce9e0b42018-08-01 12:53:17 -07002303class TestIPDeag(VppTestCase):
2304 """ IPv6 Deaggregate Routes """
2305
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002306 @classmethod
2307 def setUpClass(cls):
2308 super(TestIPDeag, cls).setUpClass()
2309
2310 @classmethod
2311 def tearDownClass(cls):
2312 super(TestIPDeag, cls).tearDownClass()
2313
Neale Rannsce9e0b42018-08-01 12:53:17 -07002314 def setUp(self):
2315 super(TestIPDeag, self).setUp()
2316
2317 self.create_pg_interfaces(range(3))
2318
2319 for i in self.pg_interfaces:
2320 i.admin_up()
2321 i.config_ip6()
2322 i.resolve_ndp()
2323
2324 def tearDown(self):
2325 super(TestIPDeag, self).tearDown()
2326 for i in self.pg_interfaces:
2327 i.unconfig_ip6()
2328 i.admin_down()
2329
2330 def test_ip_deag(self):
2331 """ IP Deag Routes """
2332
2333 #
2334 # Create a table to be used for:
2335 # 1 - another destination address lookup
2336 # 2 - a source address lookup
2337 #
2338 table_dst = VppIpTable(self, 1, is_ip6=1)
2339 table_src = VppIpTable(self, 2, is_ip6=1)
2340 table_dst.add_vpp_config()
2341 table_src.add_vpp_config()
2342
2343 #
2344 # Add a route in the default table to point to a deag/
2345 # second lookup in each of these tables
2346 #
2347 route_to_dst = VppIpRoute(self, "1::1", 128,
2348 [VppRoutePath("::",
2349 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -07002350 nh_table_id=1)])
2351 route_to_src = VppIpRoute(
2352 self, "1::2", 128,
2353 [VppRoutePath("::",
2354 0xffffffff,
2355 nh_table_id=2,
2356 type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)])
2357
Neale Rannsce9e0b42018-08-01 12:53:17 -07002358 route_to_dst.add_vpp_config()
2359 route_to_src.add_vpp_config()
2360
2361 #
2362 # packets to these destination are dropped, since they'll
2363 # hit the respective default routes in the second table
2364 #
2365 p_dst = (Ether(src=self.pg0.remote_mac,
2366 dst=self.pg0.local_mac) /
2367 IPv6(src="5::5", dst="1::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002368 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002369 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002370 p_src = (Ether(src=self.pg0.remote_mac,
2371 dst=self.pg0.local_mac) /
2372 IPv6(src="2::2", dst="1::2") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002373 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002374 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002375 pkts_dst = p_dst * 257
2376 pkts_src = p_src * 257
2377
2378 self.send_and_assert_no_replies(self.pg0, pkts_dst,
2379 "IP in dst table")
2380 self.send_and_assert_no_replies(self.pg0, pkts_src,
2381 "IP in src table")
2382
2383 #
2384 # add a route in the dst table to forward via pg1
2385 #
2386 route_in_dst = VppIpRoute(self, "1::1", 128,
2387 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002388 self.pg1.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002389 table_id=1)
2390 route_in_dst.add_vpp_config()
2391
2392 self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2393
2394 #
2395 # add a route in the src table to forward via pg2
2396 #
2397 route_in_src = VppIpRoute(self, "2::2", 128,
2398 [VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002399 self.pg2.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002400 table_id=2)
2401 route_in_src.add_vpp_config()
2402 self.send_and_expect(self.pg0, pkts_src, self.pg2)
2403
2404 #
2405 # loop in the lookup DP
2406 #
2407 route_loop = VppIpRoute(self, "3::3", 128,
2408 [VppRoutePath("::",
Neale Ranns097fa662018-05-01 05:17:55 -07002409 0xffffffff)])
Neale Rannsce9e0b42018-08-01 12:53:17 -07002410 route_loop.add_vpp_config()
2411
2412 p_l = (Ether(src=self.pg0.remote_mac,
2413 dst=self.pg0.local_mac) /
2414 IPv6(src="3::4", dst="3::3") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002415 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002416 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002417
2418 self.send_and_assert_no_replies(self.pg0, p_l * 257,
2419 "IP lookup loop")
2420
2421
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002422class TestIP6Input(VppTestCase):
Neale Rannsae809832018-11-23 09:00:27 -08002423 """ IPv6 Input Exception Test Cases """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002424
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002425 @classmethod
2426 def setUpClass(cls):
2427 super(TestIP6Input, cls).setUpClass()
2428
2429 @classmethod
2430 def tearDownClass(cls):
2431 super(TestIP6Input, cls).tearDownClass()
2432
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002433 def setUp(self):
2434 super(TestIP6Input, self).setUp()
2435
2436 self.create_pg_interfaces(range(2))
2437
2438 for i in self.pg_interfaces:
2439 i.admin_up()
2440 i.config_ip6()
2441 i.resolve_ndp()
2442
2443 def tearDown(self):
2444 super(TestIP6Input, self).tearDown()
2445 for i in self.pg_interfaces:
2446 i.unconfig_ip6()
2447 i.admin_down()
2448
Neale Rannsae809832018-11-23 09:00:27 -08002449 def test_ip_input_icmp_reply(self):
2450 """ IP6 Input Exception - Return ICMP (3,0) """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002451 #
Neale Rannsae809832018-11-23 09:00:27 -08002452 # hop limit - ICMP replies
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002453 #
2454 p_version = (Ether(src=self.pg0.remote_mac,
2455 dst=self.pg0.local_mac) /
2456 IPv6(src=self.pg0.remote_ip6,
2457 dst=self.pg1.remote_ip6,
2458 hlim=1) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002459 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002460 Raw(b'\xa5' * 100))
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002461
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002462 rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002463 rx = rx[0]
2464 icmp = rx[ICMPv6TimeExceeded]
Neale Rannsae809832018-11-23 09:00:27 -08002465
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002466 # 0: "hop limit exceeded in transit",
Neale Rannsae809832018-11-23 09:00:27 -08002467 self.assertEqual((icmp.type, icmp.code), (3, 0))
2468
2469 icmpv6_data = '\x0a' * 18
2470 all_0s = "::"
2471 all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2472
2473 @parameterized.expand([
2474 # Name, src, dst, l4proto, msg, timeout
2475 ("src='iface', dst='iface'", None, None,
2476 inet6.UDP(sport=1234, dport=1234), "funky version", None),
2477 ("src='All 0's', dst='iface'", all_0s, None,
2478 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2479 ("src='iface', dst='All 0's'", None, all_0s,
2480 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2481 ("src='All 1's', dst='iface'", all_1s, None,
2482 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2483 ("src='iface', dst='All 1's'", None, all_1s,
2484 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2485 ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2486 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2487
2488 ])
2489 def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2490
2491 self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2492
2493 p_version = (Ether(src=self.pg0.remote_mac,
2494 dst=self.pg0.local_mac) /
2495 IPv6(src=src or self.pg0.remote_ip6,
2496 dst=dst or self.pg1.remote_ip6,
2497 version=3) /
2498 l4 /
Ole Troan770a0de2019-11-07 13:52:21 +01002499 Raw(b'\xa5' * 100))
Neale Rannsae809832018-11-23 09:00:27 -08002500
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002501 self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS,
Neale Rannsae809832018-11-23 09:00:27 -08002502 remark=msg or "",
2503 timeout=timeout)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002504
Dave Barach90800962019-05-24 13:03:01 -04002505 def test_hop_by_hop(self):
2506 """ Hop-by-hop header test """
2507
2508 p = (Ether(src=self.pg0.remote_mac,
2509 dst=self.pg0.local_mac) /
2510 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
2511 IPv6ExtHdrHopByHop() /
2512 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002513 Raw(b'\xa5' * 100))
Dave Barach90800962019-05-24 13:03:01 -04002514
2515 self.pg0.add_stream(p)
2516 self.pg_enable_capture(self.pg_interfaces)
2517 self.pg_start()
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002518
Neale Ranns9db6ada2019-11-08 12:42:31 +00002519
2520class TestIPReplace(VppTestCase):
2521 """ IPv6 Table Replace """
2522
2523 @classmethod
2524 def setUpClass(cls):
2525 super(TestIPReplace, cls).setUpClass()
2526
2527 @classmethod
2528 def tearDownClass(cls):
2529 super(TestIPReplace, cls).tearDownClass()
2530
2531 def setUp(self):
2532 super(TestIPReplace, self).setUp()
2533
2534 self.create_pg_interfaces(range(4))
2535
2536 table_id = 1
2537 self.tables = []
2538
2539 for i in self.pg_interfaces:
2540 i.admin_up()
2541 i.config_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002542 i.generate_remote_hosts(2)
2543 self.tables.append(VppIpTable(self, table_id,
2544 True).add_vpp_config())
2545 table_id += 1
2546
2547 def tearDown(self):
2548 super(TestIPReplace, self).tearDown()
2549 for i in self.pg_interfaces:
2550 i.admin_down()
Neale Rannsec40a7d2020-04-23 07:36:12 +00002551 i.unconfig_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002552
2553 def test_replace(self):
2554 """ IP Table Replace """
2555
2556 N_ROUTES = 20
2557 links = [self.pg0, self.pg1, self.pg2, self.pg3]
2558 routes = [[], [], [], []]
2559
2560 # the sizes of 'empty' tables
2561 for t in self.tables:
2562 self.assertEqual(len(t.dump()), 2)
2563 self.assertEqual(len(t.mdump()), 5)
2564
2565 # load up the tables with some routes
2566 for ii, t in enumerate(self.tables):
2567 for jj in range(1, N_ROUTES):
2568 uni = VppIpRoute(
2569 self, "2001::%d" % jj if jj != 0 else "2001::", 128,
2570 [VppRoutePath(links[ii].remote_hosts[0].ip6,
2571 links[ii].sw_if_index),
2572 VppRoutePath(links[ii].remote_hosts[1].ip6,
2573 links[ii].sw_if_index)],
2574 table_id=t.table_id).add_vpp_config()
2575 multi = VppIpMRoute(
2576 self, "::",
2577 "ff:2001::%d" % jj, 128,
2578 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
2579 [VppMRoutePath(self.pg0.sw_if_index,
2580 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
2581 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2582 VppMRoutePath(self.pg1.sw_if_index,
2583 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2584 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2585 VppMRoutePath(self.pg2.sw_if_index,
2586 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2587 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2588 VppMRoutePath(self.pg3.sw_if_index,
2589 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2590 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
2591 table_id=t.table_id).add_vpp_config()
2592 routes[ii].append({'uni': uni,
2593 'multi': multi})
2594
2595 #
2596 # replace the tables a few times
2597 #
2598 for kk in range(3):
2599 # replace each table
2600 for t in self.tables:
2601 t.replace_begin()
2602
2603 # all the routes are still there
2604 for ii, t in enumerate(self.tables):
2605 dump = t.dump()
2606 mdump = t.mdump()
2607 for r in routes[ii]:
2608 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2609 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2610
2611 # redownload the even numbered routes
2612 for ii, t in enumerate(self.tables):
2613 for jj in range(0, N_ROUTES, 2):
2614 routes[ii][jj]['uni'].add_vpp_config()
2615 routes[ii][jj]['multi'].add_vpp_config()
2616
2617 # signal each table converged
2618 for t in self.tables:
2619 t.replace_end()
2620
2621 # we should find the even routes, but not the odd
2622 for ii, t in enumerate(self.tables):
2623 dump = t.dump()
2624 mdump = t.mdump()
2625 for jj in range(0, N_ROUTES, 2):
2626 self.assertTrue(find_route_in_dump(
2627 dump, routes[ii][jj]['uni'], t))
2628 self.assertTrue(find_mroute_in_dump(
2629 mdump, routes[ii][jj]['multi'], t))
2630 for jj in range(1, N_ROUTES - 1, 2):
2631 self.assertFalse(find_route_in_dump(
2632 dump, routes[ii][jj]['uni'], t))
2633 self.assertFalse(find_mroute_in_dump(
2634 mdump, routes[ii][jj]['multi'], t))
2635
2636 # reload all the routes
2637 for ii, t in enumerate(self.tables):
2638 for r in routes[ii]:
2639 r['uni'].add_vpp_config()
2640 r['multi'].add_vpp_config()
2641
2642 # all the routes are still there
2643 for ii, t in enumerate(self.tables):
2644 dump = t.dump()
2645 mdump = t.mdump()
2646 for r in routes[ii]:
2647 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2648 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2649
2650 #
2651 # finally flush the tables for good measure
2652 #
2653 for t in self.tables:
2654 t.flush()
2655 self.assertEqual(len(t.dump()), 2)
2656 self.assertEqual(len(t.mdump()), 5)
2657
2658
Neale Ranns59f71132020-04-08 12:19:38 +00002659class TestIP6Replace(VppTestCase):
2660 """ IPv4 Interface Address Replace """
2661
2662 @classmethod
2663 def setUpClass(cls):
2664 super(TestIP6Replace, cls).setUpClass()
2665
2666 @classmethod
2667 def tearDownClass(cls):
2668 super(TestIP6Replace, cls).tearDownClass()
2669
2670 def setUp(self):
2671 super(TestIP6Replace, self).setUp()
2672
2673 self.create_pg_interfaces(range(4))
2674
2675 for i in self.pg_interfaces:
2676 i.admin_up()
2677
2678 def tearDown(self):
2679 super(TestIP6Replace, self).tearDown()
2680 for i in self.pg_interfaces:
2681 i.admin_down()
2682
2683 def get_n_pfxs(self, intf):
2684 return len(self.vapi.ip_address_dump(intf.sw_if_index, True))
2685
2686 def test_replace(self):
2687 """ IP interface address replace """
2688
2689 intf_pfxs = [[], [], [], []]
2690
2691 # add prefixes to each of the interfaces
2692 for i in range(len(self.pg_interfaces)):
2693 intf = self.pg_interfaces[i]
2694
2695 # 2001:16:x::1/64
2696 addr = "2001:16:%d::1" % intf.sw_if_index
2697 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2698 intf_pfxs[i].append(a)
2699
2700 # 2001:16:x::2/64 - a different address in the same subnet as above
2701 addr = "2001:16:%d::2" % intf.sw_if_index
2702 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2703 intf_pfxs[i].append(a)
2704
2705 # 2001:15:x::2/64 - a different address and subnet
2706 addr = "2001:15:%d::2" % intf.sw_if_index
2707 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2708 intf_pfxs[i].append(a)
2709
2710 # a dump should n_address in it
2711 for intf in self.pg_interfaces:
2712 self.assertEqual(self.get_n_pfxs(intf), 3)
2713
2714 #
2715 # remove all the address thru a replace
2716 #
2717 self.vapi.sw_interface_address_replace_begin()
2718 self.vapi.sw_interface_address_replace_end()
2719 for intf in self.pg_interfaces:
2720 self.assertEqual(self.get_n_pfxs(intf), 0)
2721
2722 #
2723 # add all the interface addresses back
2724 #
2725 for p in intf_pfxs:
2726 for v in p:
2727 v.add_vpp_config()
2728 for intf in self.pg_interfaces:
2729 self.assertEqual(self.get_n_pfxs(intf), 3)
2730
2731 #
2732 # replace again, but this time update/re-add the address on the first
2733 # two interfaces
2734 #
2735 self.vapi.sw_interface_address_replace_begin()
2736
2737 for p in intf_pfxs[:2]:
2738 for v in p:
2739 v.add_vpp_config()
2740
2741 self.vapi.sw_interface_address_replace_end()
2742
2743 # on the first two the address still exist,
2744 # on the other two they do not
2745 for intf in self.pg_interfaces[:2]:
2746 self.assertEqual(self.get_n_pfxs(intf), 3)
2747 for p in intf_pfxs[:2]:
2748 for v in p:
2749 self.assertTrue(v.query_vpp_config())
2750 for intf in self.pg_interfaces[2:]:
2751 self.assertEqual(self.get_n_pfxs(intf), 0)
2752
2753 #
2754 # add all the interface addresses back on the last two
2755 #
2756 for p in intf_pfxs[2:]:
2757 for v in p:
2758 v.add_vpp_config()
2759 for intf in self.pg_interfaces:
2760 self.assertEqual(self.get_n_pfxs(intf), 3)
2761
2762 #
2763 # replace again, this time add different prefixes on all the interfaces
2764 #
2765 self.vapi.sw_interface_address_replace_begin()
2766
2767 pfxs = []
2768 for intf in self.pg_interfaces:
2769 # 2001:18:x::1/64
2770 addr = "2001:18:%d::1" % intf.sw_if_index
2771 pfxs.append(VppIpInterfaceAddress(self, intf, addr,
2772 64).add_vpp_config())
2773
2774 self.vapi.sw_interface_address_replace_end()
2775
2776 # only .18 should exist on each interface
2777 for intf in self.pg_interfaces:
2778 self.assertEqual(self.get_n_pfxs(intf), 1)
2779 for pfx in pfxs:
2780 self.assertTrue(pfx.query_vpp_config())
2781
2782 #
2783 # remove everything
2784 #
2785 self.vapi.sw_interface_address_replace_begin()
2786 self.vapi.sw_interface_address_replace_end()
2787 for intf in self.pg_interfaces:
2788 self.assertEqual(self.get_n_pfxs(intf), 0)
2789
2790 #
2791 # add prefixes to each interface. post-begin add the prefix from
2792 # interface X onto interface Y. this would normally be an error
2793 # since it would generate a 'duplicate address' warning. but in
2794 # this case, since what is newly downloaded is sane, it's ok
2795 #
2796 for intf in self.pg_interfaces:
2797 # 2001:18:x::1/64
2798 addr = "2001:18:%d::1" % intf.sw_if_index
2799 VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2800
2801 self.vapi.sw_interface_address_replace_begin()
2802
2803 pfxs = []
2804 for intf in self.pg_interfaces:
2805 # 2001:18:x::1/64
2806 addr = "2001:18:%d::1" % (intf.sw_if_index + 1)
2807 pfxs.append(VppIpInterfaceAddress(self, intf,
2808 addr, 64).add_vpp_config())
2809
2810 self.vapi.sw_interface_address_replace_end()
2811
2812 self.logger.info(self.vapi.cli("sh int addr"))
2813
2814 for intf in self.pg_interfaces:
2815 self.assertEqual(self.get_n_pfxs(intf), 1)
2816 for pfx in pfxs:
2817 self.assertTrue(pfx.query_vpp_config())
2818
2819
Neale Rannsec40a7d2020-04-23 07:36:12 +00002820class TestIP6LinkLocal(VppTestCase):
2821 """ IPv6 Link Local """
2822
2823 @classmethod
2824 def setUpClass(cls):
2825 super(TestIP6LinkLocal, cls).setUpClass()
2826
2827 @classmethod
2828 def tearDownClass(cls):
2829 super(TestIP6LinkLocal, cls).tearDownClass()
2830
2831 def setUp(self):
2832 super(TestIP6LinkLocal, self).setUp()
2833
2834 self.create_pg_interfaces(range(2))
2835
2836 for i in self.pg_interfaces:
2837 i.admin_up()
2838
2839 def tearDown(self):
2840 super(TestIP6LinkLocal, self).tearDown()
2841 for i in self.pg_interfaces:
2842 i.admin_down()
2843
2844 def test_ip6_ll(self):
2845 """ IPv6 Link Local """
2846
2847 #
2848 # two APIs to add a link local address.
2849 # 1 - just like any other prefix
2850 # 2 - with the special set LL API
2851 #
2852
2853 #
2854 # First with the API to set a 'normal' prefix
2855 #
2856 ll1 = "fe80:1::1"
2857 ll2 = "fe80:2::2"
2858 ll3 = "fe80:3::3"
2859
2860 VppIpInterfaceAddress(self, self.pg0, ll1, 128).add_vpp_config()
2861
2862 #
2863 # should be able to ping the ll
2864 #
2865 p_echo_request_1 = (Ether(src=self.pg0.remote_mac,
2866 dst=self.pg0.local_mac) /
2867 IPv6(src=ll2,
2868 dst=ll1) /
2869 ICMPv6EchoRequest())
2870
2871 self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0)
2872
2873 #
2874 # change the link-local on pg0
2875 #
2876 v_ll3 = VppIpInterfaceAddress(self, self.pg0,
2877 ll3, 128).add_vpp_config()
2878
2879 p_echo_request_3 = (Ether(src=self.pg0.remote_mac,
2880 dst=self.pg0.local_mac) /
2881 IPv6(src=ll2,
2882 dst=ll3) /
2883 ICMPv6EchoRequest())
2884
2885 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
2886
2887 #
2888 # set a normal v6 prefix on the link
2889 #
2890 self.pg0.config_ip6()
2891
2892 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
2893
2894 # the link-local cannot be removed
2895 with self.vapi.assert_negative_api_retval():
2896 v_ll3.remove_vpp_config()
2897
2898 #
2899 # Use the specific link-local API on pg1
2900 #
2901 VppIp6LinkLocalAddress(self, self.pg1, ll1).add_vpp_config()
2902 self.send_and_expect(self.pg1, [p_echo_request_1], self.pg1)
2903
2904 VppIp6LinkLocalAddress(self, self.pg1, ll3).add_vpp_config()
2905 self.send_and_expect(self.pg1, [p_echo_request_3], self.pg1)
2906
2907
Damjan Marionf56b77a2016-10-03 19:44:57 +02002908if __name__ == '__main__':
Klement Sekeraf62ae122016-10-11 11:47:09 +02002909 unittest.main(testRunner=VppTestRunner)