blob: 5dd2bbcff64d0b8cca3fe721e28b22567bfe0dcd [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 Ranns990f6942020-10-20 07:20:17 +000024from vpp_papi import VppEnum
Jakub Grajciar2df2f752020-12-01 11:23:44 +010025from vpp_ip import DpoProto, VppIpPuntPolicer, VppIpPuntRedirect
Neale Ranns180279b2017-03-16 15:49:09 -040026from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
Neale Ranns990f6942020-10-20 07:20:17 +000027 VppMRoutePath, VppMplsIpBind, \
Neale Ranns9db6ada2019-11-08 12:42:31 +000028 VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
Neale Rannsec40a7d2020-04-23 07:36:12 +000029 VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump, \
30 VppIp6LinkLocalAddress
Neale Rannsb3b2de72017-03-08 05:17:22 -080031from vpp_neighbor import find_nbr, VppNeighbor
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080032from vpp_pg_interface import is_ipv6_misc
33from vpp_sub_interface import VppSubInterface, VppDot1QSubint
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010034from vpp_policer import VppPolicer
Neale Rannsefd7bc22019-11-11 08:32:34 +000035from ipaddress import IPv6Network, IPv6Address
Neale Ranns75152282017-01-09 01:00:45 -080036
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010037AF_INET6 = socket.AF_INET6
38
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -080039try:
40 text_type = unicode
41except NameError:
42 text_type = str
43
Paul Vinciguerra4271c972019-05-14 13:25:49 -040044NUM_PKTS = 67
45
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010046
Neale Ranns3f844d02017-02-18 00:03:54 -080047class TestIPv6ND(VppTestCase):
48 def validate_ra(self, intf, rx, dst_ip=None):
49 if not dst_ip:
50 dst_ip = intf.remote_ip6
51
52 # unicasted packets must come to the unicast mac
53 self.assertEqual(rx[Ether].dst, intf.remote_mac)
54
55 # and from the router's MAC
56 self.assertEqual(rx[Ether].src, intf.local_mac)
57
58 # the rx'd RA should be addressed to the sender's source
59 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
60 self.assertEqual(in6_ptop(rx[IPv6].dst),
61 in6_ptop(dst_ip))
62
63 # and come from the router's link local
64 self.assertTrue(in6_islladdr(rx[IPv6].src))
65 self.assertEqual(in6_ptop(rx[IPv6].src),
66 in6_ptop(mk_ll_addr(intf.local_mac)))
67
68 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
69 if not dst_ip:
70 dst_ip = intf.remote_ip6
71 if not tgt_ip:
72 dst_ip = intf.local_ip6
73
74 # unicasted packets must come to the unicast mac
75 self.assertEqual(rx[Ether].dst, intf.remote_mac)
76
77 # and from the router's MAC
78 self.assertEqual(rx[Ether].src, intf.local_mac)
79
80 # the rx'd NA should be addressed to the sender's source
81 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
82 self.assertEqual(in6_ptop(rx[IPv6].dst),
83 in6_ptop(dst_ip))
84
85 # and come from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -080086 self.assertEqual(
87 in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
Neale Ranns3f844d02017-02-18 00:03:54 -080088
89 # Dest link-layer options should have the router's MAC
90 dll = rx[ICMPv6NDOptDstLLAddr]
91 self.assertEqual(dll.lladdr, intf.local_mac)
92
Neale Rannsdcd6d622017-05-26 02:59:16 -070093 def validate_ns(self, intf, rx, tgt_ip):
94 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
95 dst_ip = inet_ntop(AF_INET6, nsma)
96
97 # NS is broadcast
Neale Rannsc7b8f202018-04-25 06:34:31 -070098 self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
Neale Rannsdcd6d622017-05-26 02:59:16 -070099
100 # and from the router's MAC
101 self.assertEqual(rx[Ether].src, intf.local_mac)
102
103 # the rx'd NS should be addressed to an mcast address
104 # derived from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800105 self.assertEqual(
106 in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
Neale Rannsdcd6d622017-05-26 02:59:16 -0700107
108 # expect the tgt IP in the NS header
109 ns = rx[ICMPv6ND_NS]
110 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
111
112 # packet is from the router's local address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800113 self.assertEqual(
114 in6_ptop(rx[IPv6].src), intf.local_ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700115
116 # Src link-layer options should have the router's MAC
117 sll = rx[ICMPv6NDOptSrcLLAddr]
118 self.assertEqual(sll.lladdr, intf.local_mac)
119
Neale Ranns3f844d02017-02-18 00:03:54 -0800120 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
121 filter_out_fn=is_ipv6_misc):
122 intf.add_stream(pkts)
Neale Ranns3f844d02017-02-18 00:03:54 -0800123 self.pg_enable_capture(self.pg_interfaces)
124 self.pg_start()
125 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
126
127 self.assertEqual(len(rx), 1)
128 rx = rx[0]
129 self.validate_ra(intf, rx, dst_ip)
130
Neale Ranns2a3ea492017-04-19 05:24:40 -0700131 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
132 tgt_ip=None,
133 filter_out_fn=is_ipv6_misc):
134 intf.add_stream(pkts)
135 self.pg_enable_capture(self.pg_interfaces)
136 self.pg_start()
137 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
138
139 self.assertEqual(len(rx), 1)
140 rx = rx[0]
141 self.validate_na(intf, rx, dst_ip, tgt_ip)
142
Neale Rannsdcd6d622017-05-26 02:59:16 -0700143 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
144 filter_out_fn=is_ipv6_misc):
Neale Rannscbe25aa2019-09-30 10:53:31 +0000145 self.vapi.cli("clear trace")
Neale Rannsdcd6d622017-05-26 02:59:16 -0700146 tx_intf.add_stream(pkts)
147 self.pg_enable_capture(self.pg_interfaces)
148 self.pg_start()
149 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
150
151 self.assertEqual(len(rx), 1)
152 rx = rx[0]
153 self.validate_ns(rx_intf, rx, tgt_ip)
154
Neale Rannsdcd6d622017-05-26 02:59:16 -0700155 def verify_ip(self, rx, smac, dmac, sip, dip):
156 ether = rx[Ether]
157 self.assertEqual(ether.dst, dmac)
158 self.assertEqual(ether.src, smac)
159
160 ip = rx[IPv6]
161 self.assertEqual(ip.src, sip)
162 self.assertEqual(ip.dst, dip)
163
Neale Ranns3f844d02017-02-18 00:03:54 -0800164
165class TestIPv6(TestIPv6ND):
Damjan Marionf56b77a2016-10-03 19:44:57 +0200166 """ IPv6 Test Case """
167
168 @classmethod
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000169 def force_solo(cls):
170 return True
171
172 @classmethod
Damjan Marionf56b77a2016-10-03 19:44:57 +0200173 def setUpClass(cls):
174 super(TestIPv6, cls).setUpClass()
175
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700176 @classmethod
177 def tearDownClass(cls):
178 super(TestIPv6, cls).tearDownClass()
179
Klement Sekeraf62ae122016-10-11 11:47:09 +0200180 def setUp(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100181 """
182 Perform test setup before test case.
183
184 **Config:**
185 - create 3 pg interfaces
186 - untagged pg0 interface
187 - Dot1Q subinterface on pg1
188 - Dot1AD subinterface on pg2
189 - setup interfaces:
190 - put it into UP state
191 - set IPv6 addresses
192 - resolve neighbor address using NDP
193 - configure 200 fib entries
194
195 :ivar list interfaces: pg interfaces and subinterfaces.
196 :ivar dict flows: IPv4 packet flows in test.
Matej Klotton86d87c42016-11-11 11:38:55 +0100197
198 *TODO:* Create AD sub interface
199 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200200 super(TestIPv6, self).setUp()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200201
Klement Sekeraf62ae122016-10-11 11:47:09 +0200202 # create 3 pg interfaces
203 self.create_pg_interfaces(range(3))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200204
Klement Sekeraf62ae122016-10-11 11:47:09 +0200205 # create 2 subinterfaces for p1 and pg2
206 self.sub_interfaces = [
207 VppDot1QSubint(self, self.pg1, 100),
Matej Klotton86d87c42016-11-11 11:38:55 +0100208 VppDot1QSubint(self, self.pg2, 200)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200209 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
Matej Klotton86d87c42016-11-11 11:38:55 +0100210 ]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200211
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
213 self.flows = dict()
214 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
215 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
216 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200217
Klement Sekeraf62ae122016-10-11 11:47:09 +0200218 # packet sizes
Jan Geletye6c78ee2018-06-26 12:24:03 +0200219 self.pg_if_packet_sizes = [64, 1500, 9020]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200220
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221 self.interfaces = list(self.pg_interfaces)
222 self.interfaces.extend(self.sub_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200223
Klement Sekeraf62ae122016-10-11 11:47:09 +0200224 # setup all interfaces
225 for i in self.interfaces:
226 i.admin_up()
227 i.config_ip6()
228 i.resolve_ndp()
229
Damjan Marionf56b77a2016-10-03 19:44:57 +0200230 def tearDown(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100231 """Run standard test teardown and log ``show ip6 neighbors``."""
Neale Ranns744902e2017-08-14 10:35:44 -0700232 for i in self.interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800233 i.unconfig_ip6()
Neale Ranns75152282017-01-09 01:00:45 -0800234 i.admin_down()
Neale Ranns744902e2017-08-14 10:35:44 -0700235 for i in self.sub_interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800236 i.remove_vpp_config()
237
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238 super(TestIPv6, self).tearDown()
239 if not self.vpp_dead:
Matej Klotton86d87c42016-11-11 11:38:55 +0100240 self.logger.info(self.vapi.cli("show ip6 neighbors"))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200241 # info(self.vapi.cli("show ip6 fib")) # many entries
Damjan Marionf56b77a2016-10-03 19:44:57 +0200242
Jan Geletye6c78ee2018-06-26 12:24:03 +0200243 def modify_packet(self, src_if, packet_size, pkt):
244 """Add load, set destination IP and extend packet to required packet
245 size for defined interface.
246
247 :param VppInterface src_if: Interface to create packet for.
248 :param int packet_size: Required packet size.
249 :param Scapy pkt: Packet to be modified.
250 """
snaramre07a0f212019-10-11 21:28:56 +0000251 dst_if_idx = int(packet_size / 10 % 2)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200252 dst_if = self.flows[src_if][dst_if_idx]
253 info = self.create_packet_info(src_if, dst_if)
254 payload = self.info_to_payload(info)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800255 p = pkt / Raw(payload)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200256 p[IPv6].dst = dst_if.remote_ip6
257 info.data = p.copy()
258 if isinstance(src_if, VppSubInterface):
259 p = src_if.add_dot1_layer(p)
260 self.extend_packet(p, packet_size)
261
262 return p
263
264 def create_stream(self, src_if):
Matej Klotton86d87c42016-11-11 11:38:55 +0100265 """Create input packet stream for defined interface.
266
267 :param VppInterface src_if: Interface to create packet stream for.
Matej Klotton86d87c42016-11-11 11:38:55 +0100268 """
Jan Geletye6c78ee2018-06-26 12:24:03 +0200269 hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
270 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
271 IPv6(src=src_if.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800272 inet6.UDP(sport=1234, dport=1234))
Jan Geletye6c78ee2018-06-26 12:24:03 +0200273
274 pkts = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800275 for i in moves.range(self.pg_if_packet_sizes[0],
276 self.pg_if_packet_sizes[1], 10)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200277 pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800278 for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
279 self.pg_if_packet_sizes[2] + hdr_ext,
280 50)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200281 pkts.extend(pkts_b)
282
Damjan Marionf56b77a2016-10-03 19:44:57 +0200283 return pkts
284
Klement Sekeraf62ae122016-10-11 11:47:09 +0200285 def verify_capture(self, dst_if, capture):
Matej Klotton86d87c42016-11-11 11:38:55 +0100286 """Verify captured input packet stream for defined interface.
287
288 :param VppInterface dst_if: Interface to verify captured packet stream
289 for.
290 :param list capture: Captured packet stream.
291 """
292 self.logger.info("Verifying capture on interface %s" % dst_if.name)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200293 last_info = dict()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200294 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200295 last_info[i.sw_if_index] = None
296 is_sub_if = False
297 dst_sw_if_index = dst_if.sw_if_index
298 if hasattr(dst_if, 'parent'):
299 is_sub_if = True
Damjan Marionf56b77a2016-10-03 19:44:57 +0200300 for packet in capture:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200301 if is_sub_if:
302 # Check VLAN tags and Ethernet header
303 packet = dst_if.remove_dot1_layer(packet)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200304 self.assertTrue(Dot1Q not in packet)
305 try:
306 ip = packet[IPv6]
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800307 udp = packet[inet6.UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800308 payload_info = self.payload_to_info(packet[Raw])
Damjan Marionf56b77a2016-10-03 19:44:57 +0200309 packet_index = payload_info.index
Klement Sekeraf62ae122016-10-11 11:47:09 +0200310 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerada505f62017-01-04 12:58:53 +0100311 self.logger.debug(
312 "Got packet on port %s: src=%u (id=%u)" %
313 (dst_if.name, payload_info.src, packet_index))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200314 next_info = self.get_next_packet_info_for_interface2(
315 payload_info.src, dst_sw_if_index,
316 last_info[payload_info.src])
317 last_info[payload_info.src] = next_info
Damjan Marionf56b77a2016-10-03 19:44:57 +0200318 self.assertTrue(next_info is not None)
319 self.assertEqual(packet_index, next_info.index)
320 saved_packet = next_info.data
321 # Check standard fields
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800322 self.assertEqual(
323 ip.src, saved_packet[IPv6].src)
324 self.assertEqual(
325 ip.dst, saved_packet[IPv6].dst)
326 self.assertEqual(
327 udp.sport, saved_packet[inet6.UDP].sport)
328 self.assertEqual(
329 udp.dport, saved_packet[inet6.UDP].dport)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200330 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100331 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200332 raise
333 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200334 remaining_packet = self.get_next_packet_info_for_interface2(
335 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
Klement Sekera7bb873a2016-11-18 07:38:42 +0100336 self.assertTrue(remaining_packet is None,
337 "Interface %s: Packet expected from interface %s "
338 "didn't arrive" % (dst_if.name, i.name))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200339
Klement Sekerae8498652019-06-17 12:23:15 +0000340 def test_next_header_anomaly(self):
341 """ IPv6 next header anomaly test
342
343 Test scenario:
344 - ipv6 next header field = Fragment Header (44)
345 - next header is ICMPv6 Echo Request
346 - wait for reassembly
347 """
348 pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) /
349 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) /
350 ICMPv6EchoRequest())
351
352 self.pg0.add_stream(pkt)
353 self.pg_start()
354
355 # wait for reassembly
356 self.sleep(10)
357
Damjan Marionf56b77a2016-10-03 19:44:57 +0200358 def test_fib(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100359 """ IPv6 FIB test
360
361 Test scenario:
362 - Create IPv6 stream for pg0 interface
363 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
364 - Send and verify received packets on each interface.
365 """
Damjan Marionf56b77a2016-10-03 19:44:57 +0200366
Jan Geletye6c78ee2018-06-26 12:24:03 +0200367 pkts = self.create_stream(self.pg0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200368 self.pg0.add_stream(pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200369
Klement Sekeraf62ae122016-10-11 11:47:09 +0200370 for i in self.sub_interfaces:
Jan Geletye6c78ee2018-06-26 12:24:03 +0200371 pkts = self.create_stream(i)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200372 i.parent.add_stream(pkts)
373
374 self.pg_enable_capture(self.pg_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200375 self.pg_start()
376
Klement Sekeraf62ae122016-10-11 11:47:09 +0200377 pkts = self.pg0.get_capture()
378 self.verify_capture(self.pg0, pkts)
379
380 for i in self.sub_interfaces:
381 pkts = i.parent.get_capture()
382 self.verify_capture(i, pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200383
Neale Ranns75152282017-01-09 01:00:45 -0800384 def test_ns(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100385 """ IPv6 Neighbour Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800386
Klement Sekerada505f62017-01-04 12:58:53 +0100387 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800388 - Send an NS Sourced from an address not covered by the link sub-net
389 - Send an NS to an mcast address the router has not joined
390 - Send NS for a target address the router does not onn.
391 """
392
393 #
394 # An NS from a non link source address
395 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800396 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
397 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800398
399 p = (Ether(dst=in6_getnsmac(nsma)) /
400 IPv6(dst=d, src="2002::2") /
401 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800402 ICMPv6NDOptSrcLLAddr(
403 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800404 pkts = [p]
405
Klement Sekerada505f62017-01-04 12:58:53 +0100406 self.send_and_assert_no_replies(
407 self.pg0, pkts,
408 "No response to NS source by address not on sub-net")
Neale Ranns75152282017-01-09 01:00:45 -0800409
410 #
Klement Sekerada505f62017-01-04 12:58:53 +0100411 # An NS for sent to a solicited mcast group the router is
412 # not a member of FAILS
Neale Ranns75152282017-01-09 01:00:45 -0800413 #
414 if 0:
Neale Ranns3f844d02017-02-18 00:03:54 -0800415 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
416 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800417
418 p = (Ether(dst=in6_getnsmac(nsma)) /
419 IPv6(dst=d, src=self.pg0.remote_ip6) /
420 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800421 ICMPv6NDOptSrcLLAddr(
422 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800423 pkts = [p]
424
Klement Sekerada505f62017-01-04 12:58:53 +0100425 self.send_and_assert_no_replies(
426 self.pg0, pkts,
427 "No response to NS sent to unjoined mcast address")
Neale Ranns75152282017-01-09 01:00:45 -0800428
429 #
430 # An NS whose target address is one the router does not own
431 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800432 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
433 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800434
435 p = (Ether(dst=in6_getnsmac(nsma)) /
436 IPv6(dst=d, src=self.pg0.remote_ip6) /
437 ICMPv6ND_NS(tgt="fd::ffff") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800438 ICMPv6NDOptSrcLLAddr(
439 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800440 pkts = [p]
441
442 self.send_and_assert_no_replies(self.pg0, pkts,
443 "No response to NS for unknown target")
444
Neale Rannsb3b2de72017-03-08 05:17:22 -0800445 #
446 # A neighbor entry that has no associated FIB-entry
447 #
448 self.pg0.generate_remote_hosts(4)
449 nd_entry = VppNeighbor(self,
450 self.pg0.sw_if_index,
451 self.pg0.remote_hosts[2].mac,
452 self.pg0.remote_hosts[2].ip6,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800453 is_no_fib_entry=1)
454 nd_entry.add_vpp_config()
455
456 #
457 # check we have the neighbor, but no route
458 #
459 self.assertTrue(find_nbr(self,
460 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700461 self.pg0._remote_hosts[2].ip6))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800462 self.assertFalse(find_route(self,
463 self.pg0._remote_hosts[2].ip6,
Neale Ranns097fa662018-05-01 05:17:55 -0700464 128))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800465
Neale Ranns2a3ea492017-04-19 05:24:40 -0700466 #
467 # send an NS from a link local address to the interface's global
468 # address
469 #
470 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800471 IPv6(
472 dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700473 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800474 ICMPv6NDOptSrcLLAddr(
475 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700476
477 self.send_and_expect_na(self.pg0, p,
478 "NS from link-local",
479 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
480 tgt_ip=self.pg0.local_ip6)
481
482 #
483 # we should have learned an ND entry for the peer's link-local
484 # but not inserted a route to it in the FIB
485 #
486 self.assertTrue(find_nbr(self,
487 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700488 self.pg0._remote_hosts[2].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700489 self.assertFalse(find_route(self,
490 self.pg0._remote_hosts[2].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700491 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700492
493 #
494 # An NS to the router's own Link-local
495 #
496 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800497 IPv6(
498 dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700499 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800500 ICMPv6NDOptSrcLLAddr(
501 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700502
503 self.send_and_expect_na(self.pg0, p,
504 "NS to/from link-local",
505 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
506 tgt_ip=self.pg0.local_ip6_ll)
507
508 #
509 # we should have learned an ND entry for the peer's link-local
510 # but not inserted a route to it in the FIB
511 #
512 self.assertTrue(find_nbr(self,
513 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700514 self.pg0._remote_hosts[3].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700515 self.assertFalse(find_route(self,
516 self.pg0._remote_hosts[3].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700517 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700518
Neale Rannsdcd6d622017-05-26 02:59:16 -0700519 def test_ns_duplicates(self):
Neale Rannsda78f952017-05-24 09:15:43 -0700520 """ ND Duplicates"""
Neale Rannsdcd6d622017-05-26 02:59:16 -0700521
522 #
523 # Generate some hosts on the LAN
524 #
525 self.pg1.generate_remote_hosts(3)
526
527 #
528 # Add host 1 on pg1 and pg2
529 #
530 ns_pg1 = VppNeighbor(self,
531 self.pg1.sw_if_index,
532 self.pg1.remote_hosts[1].mac,
Neale Ranns37029302018-08-10 05:30:06 -0700533 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700534 ns_pg1.add_vpp_config()
535 ns_pg2 = VppNeighbor(self,
536 self.pg2.sw_if_index,
537 self.pg2.remote_mac,
Neale Ranns37029302018-08-10 05:30:06 -0700538 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700539 ns_pg2.add_vpp_config()
540
541 #
542 # IP packet destined for pg1 remote host arrives on pg1 again.
543 #
544 p = (Ether(dst=self.pg0.local_mac,
545 src=self.pg0.remote_mac) /
546 IPv6(src=self.pg0.remote_ip6,
547 dst=self.pg1.remote_hosts[1].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800548 inet6.UDP(sport=1234, dport=1234) /
Neale Rannsdcd6d622017-05-26 02:59:16 -0700549 Raw())
550
551 self.pg0.add_stream(p)
552 self.pg_enable_capture(self.pg_interfaces)
553 self.pg_start()
554
555 rx1 = self.pg1.get_capture(1)
556
557 self.verify_ip(rx1[0],
558 self.pg1.local_mac,
559 self.pg1.remote_hosts[1].mac,
560 self.pg0.remote_ip6,
561 self.pg1.remote_hosts[1].ip6)
562
563 #
564 # remove the duplicate on pg1
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700565 # packet stream should generate NSs out of pg1
Neale Rannsdcd6d622017-05-26 02:59:16 -0700566 #
567 ns_pg1.remove_vpp_config()
568
569 self.send_and_expect_ns(self.pg0, self.pg1,
570 p, self.pg1.remote_hosts[1].ip6)
571
572 #
573 # Add it back
574 #
575 ns_pg1.add_vpp_config()
576
577 self.pg0.add_stream(p)
578 self.pg_enable_capture(self.pg_interfaces)
579 self.pg_start()
580
581 rx1 = self.pg1.get_capture(1)
582
583 self.verify_ip(rx1[0],
584 self.pg1.local_mac,
585 self.pg1.remote_hosts[1].mac,
586 self.pg0.remote_ip6,
587 self.pg1.remote_hosts[1].ip6)
588
Neale Rannscbe25aa2019-09-30 10:53:31 +0000589 def validate_ra(self, intf, rx, dst_ip=None, src_ip=None,
590 mtu=9000, pi_opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000591 if not dst_ip:
592 dst_ip = intf.remote_ip6
Neale Rannscbe25aa2019-09-30 10:53:31 +0000593 if not src_ip:
594 src_ip = mk_ll_addr(intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800595
Neale Ranns5737d882017-02-03 06:14:49 -0800596 # unicasted packets must come to the unicast mac
Neale Ranns32e1c012016-11-22 17:07:28 +0000597 self.assertEqual(rx[Ether].dst, intf.remote_mac)
598
599 # and from the router's MAC
600 self.assertEqual(rx[Ether].src, intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800601
602 # the rx'd RA should be addressed to the sender's source
603 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
604 self.assertEqual(in6_ptop(rx[IPv6].dst),
Neale Ranns32e1c012016-11-22 17:07:28 +0000605 in6_ptop(dst_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800606
607 # and come from the router's link local
608 self.assertTrue(in6_islladdr(rx[IPv6].src))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000609 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800610
Neale Ranns87df12d2017-02-18 08:16:41 -0800611 # it should contain the links MTU
612 ra = rx[ICMPv6ND_RA]
613 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
614
615 # it should contain the source's link layer address option
616 sll = ra[ICMPv6NDOptSrcLLAddr]
617 self.assertEqual(sll.lladdr, intf.local_mac)
618
619 if not pi_opt:
620 # the RA should not contain prefix information
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800621 self.assertFalse(ra.haslayer(
622 ICMPv6NDOptPrefixInfo))
Neale Ranns87df12d2017-02-18 08:16:41 -0800623 else:
624 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
625
626 # the options are nested in the scapy packet in way that i cannot
627 # decipher how to decode. this 1st layer of option always returns
628 # nested classes, so a direct obj1=obj2 comparison always fails.
Paul Vinciguerraab055082019-06-06 14:07:55 -0400629 # however, the getlayer(.., 2) does give one instance.
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700630 # so we cheat here and construct a new opt instance for comparison
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800631 rd = ICMPv6NDOptPrefixInfo(
632 prefixlen=raos.prefixlen,
633 prefix=raos.prefix,
634 L=raos.L,
635 A=raos.A)
Neale Ranns87df12d2017-02-18 08:16:41 -0800636 if type(pi_opt) is list:
637 for ii in range(len(pi_opt)):
638 self.assertEqual(pi_opt[ii], rd)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800639 rd = rx.getlayer(
640 ICMPv6NDOptPrefixInfo, ii + 2)
Neale Ranns87df12d2017-02-18 08:16:41 -0800641 else:
Paul Vinciguerraab055082019-06-06 14:07:55 -0400642 self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s'
643 % (pi_opt.show(dump=True),
644 raos.show(dump=True)))
Neale Ranns87df12d2017-02-18 08:16:41 -0800645
Neale Ranns32e1c012016-11-22 17:07:28 +0000646 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
Neale Ranns87df12d2017-02-18 08:16:41 -0800647 filter_out_fn=is_ipv6_misc,
Neale Rannscbe25aa2019-09-30 10:53:31 +0000648 opt=None,
649 src_ip=None):
650 self.vapi.cli("clear trace")
Neale Ranns32e1c012016-11-22 17:07:28 +0000651 intf.add_stream(pkts)
Neale Ranns32e1c012016-11-22 17:07:28 +0000652 self.pg_enable_capture(self.pg_interfaces)
653 self.pg_start()
654 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
655
656 self.assertEqual(len(rx), 1)
657 rx = rx[0]
Neale Rannscbe25aa2019-09-30 10:53:31 +0000658 self.validate_ra(intf, rx, dst_ip, src_ip=src_ip, pi_opt=opt)
Neale Ranns32e1c012016-11-22 17:07:28 +0000659
Neale Ranns75152282017-01-09 01:00:45 -0800660 def test_rs(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100661 """ IPv6 Router Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800662
Klement Sekerada505f62017-01-04 12:58:53 +0100663 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800664 """
665
666 #
Klement Sekerada505f62017-01-04 12:58:53 +0100667 # Before we begin change the IPv6 RA responses to use the unicast
668 # address - that way we will not confuse them with the periodic
669 # RAs which go to the mcast address
Neale Ranns32e1c012016-11-22 17:07:28 +0000670 # Sit and wait for the first periodic RA.
671 #
672 # TODO
Neale Ranns75152282017-01-09 01:00:45 -0800673 #
674 self.pg0.ip6_ra_config(send_unicast=1)
675
676 #
677 # An RS from a link source address
678 # - expect an RA in return
679 #
680 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Neale Rannscbe25aa2019-09-30 10:53:31 +0000681 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
Neale Ranns75152282017-01-09 01:00:45 -0800682 ICMPv6ND_RS())
683 pkts = [p]
684 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
685
686 #
687 # For the next RS sent the RA should be rate limited
688 #
689 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
690
691 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700692 # When we reconfigure the IPv6 RA config,
693 # we reset the RA rate limiting,
Klement Sekerada505f62017-01-04 12:58:53 +0100694 # so we need to do this before each test below so as not to drop
695 # packets for rate limiting reasons. Test this works here.
Neale Ranns75152282017-01-09 01:00:45 -0800696 #
697 self.pg0.ip6_ra_config(send_unicast=1)
698 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
699
700 #
701 # An RS sent from a non-link local source
702 #
703 self.pg0.ip6_ra_config(send_unicast=1)
704 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800705 IPv6(dst=self.pg0.local_ip6,
706 src="2002::ffff") /
Neale Ranns75152282017-01-09 01:00:45 -0800707 ICMPv6ND_RS())
708 pkts = [p]
709 self.send_and_assert_no_replies(self.pg0, pkts,
710 "RS from non-link source")
711
712 #
713 # Source an RS from a link local address
714 #
715 self.pg0.ip6_ra_config(send_unicast=1)
716 ll = mk_ll_addr(self.pg0.remote_mac)
717 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
718 IPv6(dst=self.pg0.local_ip6, src=ll) /
719 ICMPv6ND_RS())
720 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000721 self.send_and_expect_ra(self.pg0, pkts,
722 "RS sourced from link-local",
723 dst_ip=ll)
724
725 #
726 # Send the RS multicast
727 #
728 self.pg0.ip6_ra_config(send_unicast=1)
Neale Ranns3f844d02017-02-18 00:03:54 -0800729 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
Neale Ranns32e1c012016-11-22 17:07:28 +0000730 ll = mk_ll_addr(self.pg0.remote_mac)
731 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
732 IPv6(dst="ff02::2", src=ll) /
733 ICMPv6ND_RS())
734 pkts = [p]
735 self.send_and_expect_ra(self.pg0, pkts,
736 "RS sourced from link-local",
737 dst_ip=ll)
Neale Ranns75152282017-01-09 01:00:45 -0800738
739 #
Klement Sekerada505f62017-01-04 12:58:53 +0100740 # Source from the unspecified address ::. This happens when the RS
741 # is sent before the host has a configured address/sub-net,
742 # i.e. auto-config. Since the sender has no IP address, the reply
743 # comes back mcast - so the capture needs to not filter this.
744 # If we happen to pick up the periodic RA at this point then so be it,
745 # it's not an error.
Neale Ranns75152282017-01-09 01:00:45 -0800746 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000747 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
748 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
749 IPv6(dst="ff02::2", src="::") /
Neale Ranns75152282017-01-09 01:00:45 -0800750 ICMPv6ND_RS())
751 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000752 self.send_and_expect_ra(self.pg0, pkts,
753 "RS sourced from unspecified",
754 dst_ip="ff02::1",
755 filter_out_fn=None)
Neale Ranns75152282017-01-09 01:00:45 -0800756
757 #
Neale Ranns87df12d2017-02-18 08:16:41 -0800758 # Configure The RA to announce the links prefix
759 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400760 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
761 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800762
763 #
764 # RAs should now contain the prefix information option
765 #
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800766 opt = ICMPv6NDOptPrefixInfo(
767 prefixlen=self.pg0.local_ip6_prefix_len,
768 prefix=self.pg0.local_ip6,
769 L=1,
770 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800771
772 self.pg0.ip6_ra_config(send_unicast=1)
773 ll = mk_ll_addr(self.pg0.remote_mac)
774 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
775 IPv6(dst=self.pg0.local_ip6, src=ll) /
776 ICMPv6ND_RS())
777 self.send_and_expect_ra(self.pg0, p,
778 "RA with prefix-info",
779 dst_ip=ll,
780 opt=opt)
781
782 #
783 # Change the prefix info to not off-link
784 # L-flag is clear
785 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400786 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
787 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800788 off_link=1)
789
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800790 opt = ICMPv6NDOptPrefixInfo(
791 prefixlen=self.pg0.local_ip6_prefix_len,
792 prefix=self.pg0.local_ip6,
793 L=0,
794 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800795
796 self.pg0.ip6_ra_config(send_unicast=1)
797 self.send_and_expect_ra(self.pg0, p,
798 "RA with Prefix info with L-flag=0",
799 dst_ip=ll,
800 opt=opt)
801
802 #
803 # Change the prefix info to not off-link, no-autoconfig
804 # L and A flag are clear in the advert
805 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400806 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
807 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800808 off_link=1,
809 no_autoconfig=1)
810
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800811 opt = ICMPv6NDOptPrefixInfo(
812 prefixlen=self.pg0.local_ip6_prefix_len,
813 prefix=self.pg0.local_ip6,
814 L=0,
815 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800816
817 self.pg0.ip6_ra_config(send_unicast=1)
818 self.send_and_expect_ra(self.pg0, p,
819 "RA with Prefix info with A & L-flag=0",
820 dst_ip=ll,
821 opt=opt)
822
823 #
824 # Change the flag settings back to the defaults
825 # L and A flag are set in the advert
826 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400827 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
828 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800829
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800830 opt = ICMPv6NDOptPrefixInfo(
831 prefixlen=self.pg0.local_ip6_prefix_len,
832 prefix=self.pg0.local_ip6,
833 L=1,
834 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800835
836 self.pg0.ip6_ra_config(send_unicast=1)
837 self.send_and_expect_ra(self.pg0, p,
838 "RA with Prefix info",
839 dst_ip=ll,
840 opt=opt)
841
842 #
843 # Change the prefix info to not off-link, no-autoconfig
844 # L and A flag are clear in the advert
845 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400846 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
847 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800848 off_link=1,
849 no_autoconfig=1)
850
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800851 opt = ICMPv6NDOptPrefixInfo(
852 prefixlen=self.pg0.local_ip6_prefix_len,
853 prefix=self.pg0.local_ip6,
854 L=0,
855 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800856
857 self.pg0.ip6_ra_config(send_unicast=1)
858 self.send_and_expect_ra(self.pg0, p,
859 "RA with Prefix info with A & L-flag=0",
860 dst_ip=ll,
861 opt=opt)
862
863 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700864 # Use the reset to defaults option to revert to defaults
Neale Ranns87df12d2017-02-18 08:16:41 -0800865 # L and A flag are clear in the advert
866 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400867 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
868 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800869 use_default=1)
870
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800871 opt = ICMPv6NDOptPrefixInfo(
872 prefixlen=self.pg0.local_ip6_prefix_len,
873 prefix=self.pg0.local_ip6,
874 L=1,
875 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800876
877 self.pg0.ip6_ra_config(send_unicast=1)
878 self.send_and_expect_ra(self.pg0, p,
879 "RA with Prefix reverted to defaults",
880 dst_ip=ll,
881 opt=opt)
882
883 #
884 # Advertise Another prefix. With no L-flag/A-flag
885 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400886 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
887 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800888 off_link=1,
889 no_autoconfig=1)
890
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800891 opt = [ICMPv6NDOptPrefixInfo(
892 prefixlen=self.pg0.local_ip6_prefix_len,
893 prefix=self.pg0.local_ip6,
894 L=1,
895 A=1),
896 ICMPv6NDOptPrefixInfo(
897 prefixlen=self.pg1.local_ip6_prefix_len,
898 prefix=self.pg1.local_ip6,
899 L=0,
900 A=0)]
Neale Ranns87df12d2017-02-18 08:16:41 -0800901
902 self.pg0.ip6_ra_config(send_unicast=1)
903 ll = mk_ll_addr(self.pg0.remote_mac)
904 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
905 IPv6(dst=self.pg0.local_ip6, src=ll) /
906 ICMPv6ND_RS())
907 self.send_and_expect_ra(self.pg0, p,
908 "RA with multiple Prefix infos",
909 dst_ip=ll,
910 opt=opt)
911
912 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700913 # Remove the first prefix-info - expect the second is still in the
Neale Ranns87df12d2017-02-18 08:16:41 -0800914 # advert
915 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400916 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
917 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800918 is_no=1)
919
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800920 opt = ICMPv6NDOptPrefixInfo(
921 prefixlen=self.pg1.local_ip6_prefix_len,
922 prefix=self.pg1.local_ip6,
923 L=0,
924 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800925
926 self.pg0.ip6_ra_config(send_unicast=1)
927 self.send_and_expect_ra(self.pg0, p,
928 "RA with Prefix reverted to defaults",
929 dst_ip=ll,
930 opt=opt)
931
932 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700933 # Remove the second prefix-info - expect no prefix-info in the adverts
Neale Ranns87df12d2017-02-18 08:16:41 -0800934 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400935 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
936 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800937 is_no=1)
938
Neale Rannscbe25aa2019-09-30 10:53:31 +0000939 #
940 # change the link's link local, so we know that works too.
941 #
942 self.vapi.sw_interface_ip6_set_link_local_address(
943 sw_if_index=self.pg0.sw_if_index,
944 ip="fe80::88")
945
Neale Ranns87df12d2017-02-18 08:16:41 -0800946 self.pg0.ip6_ra_config(send_unicast=1)
947 self.send_and_expect_ra(self.pg0, p,
948 "RA with Prefix reverted to defaults",
Neale Rannscbe25aa2019-09-30 10:53:31 +0000949 dst_ip=ll,
950 src_ip="fe80::88")
Neale Ranns87df12d2017-02-18 08:16:41 -0800951
952 #
Neale Ranns5737d882017-02-03 06:14:49 -0800953 # Reset the periodic advertisements back to default values
Neale Ranns75152282017-01-09 01:00:45 -0800954 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000955 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200956
Neale Rannsf267d112020-02-07 09:45:07 +0000957 def test_mld(self):
958 """ MLD Report """
959 #
960 # test one MLD is sent after applying an IPv6 Address on an interface
961 #
962 self.pg_enable_capture(self.pg_interfaces)
963 self.pg_start()
964
965 subitf = VppDot1QSubint(self, self.pg1, 99)
966
967 subitf.admin_up()
968 subitf.config_ip6()
969
Neale Ranns03c254e2020-03-17 14:25:10 +0000970 rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None)
Neale Rannsf267d112020-02-07 09:45:07 +0000971
972 #
973 # hunt for the MLD on vlan 99
974 #
975 for rx in rxs:
976 # make sure ipv6 packets with hop by hop options have
977 # correct checksums
978 self.assert_packet_checksums_valid(rx)
979 if rx.haslayer(IPv6ExtHdrHopByHop) and \
980 rx.haslayer(Dot1Q) and \
981 rx[Dot1Q].vlan == 99:
982 mld = rx[ICMPv6MLReport2]
983
984 self.assertEqual(mld.records_number, 4)
985
Neale Ranns3f844d02017-02-18 00:03:54 -0800986
Christian Hoppsf5d38e02020-05-04 10:28:03 -0400987class TestIPv6RouteLookup(VppTestCase):
988 """ IPv6 Route Lookup Test Case """
989 routes = []
990
991 def route_lookup(self, prefix, exact):
992 return self.vapi.api(self.vapi.papi.ip_route_lookup,
993 {
994 'table_id': 0,
995 'exact': exact,
996 'prefix': prefix,
997 })
998
999 @classmethod
1000 def setUpClass(cls):
1001 super(TestIPv6RouteLookup, cls).setUpClass()
1002
1003 @classmethod
1004 def tearDownClass(cls):
1005 super(TestIPv6RouteLookup, cls).tearDownClass()
1006
1007 def setUp(self):
1008 super(TestIPv6RouteLookup, self).setUp()
1009
1010 drop_nh = VppRoutePath("::1", 0xffffffff,
1011 type=FibPathType.FIB_PATH_TYPE_DROP)
1012
1013 # Add 3 routes
1014 r = VppIpRoute(self, "2001:1111::", 32, [drop_nh])
1015 r.add_vpp_config()
1016 self.routes.append(r)
1017
1018 r = VppIpRoute(self, "2001:1111:2222::", 48, [drop_nh])
1019 r.add_vpp_config()
1020 self.routes.append(r)
1021
1022 r = VppIpRoute(self, "2001:1111:2222::1", 128, [drop_nh])
1023 r.add_vpp_config()
1024 self.routes.append(r)
1025
1026 def tearDown(self):
1027 # Remove the routes we added
1028 for r in self.routes:
1029 r.remove_vpp_config()
1030
1031 super(TestIPv6RouteLookup, self).tearDown()
1032
1033 def test_exact_match(self):
1034 # Verify we find the host route
1035 prefix = "2001:1111:2222::1/128"
1036 result = self.route_lookup(prefix, True)
1037 assert (prefix == str(result.route.prefix))
1038
1039 # Verify we find a middle prefix route
1040 prefix = "2001:1111:2222::/48"
1041 result = self.route_lookup(prefix, True)
1042 assert (prefix == str(result.route.prefix))
1043
1044 # Verify we do not find an available LPM.
1045 with self.vapi.assert_negative_api_retval():
1046 self.route_lookup("2001::2/128", True)
1047
1048 def test_longest_prefix_match(self):
1049 # verify we find lpm
1050 lpm_prefix = "2001:1111:2222::/48"
1051 result = self.route_lookup("2001:1111:2222::2/128", False)
1052 assert (lpm_prefix == str(result.route.prefix))
1053
1054 # Verify we find the exact when not requested
1055 result = self.route_lookup(lpm_prefix, False)
1056 assert (lpm_prefix == str(result.route.prefix))
1057
1058 # Can't seem to delete the default route so no negative LPM test.
1059
1060
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001061class TestIPv6IfAddrRoute(VppTestCase):
1062 """ IPv6 Interface Addr Route Test Case """
1063
1064 @classmethod
1065 def setUpClass(cls):
1066 super(TestIPv6IfAddrRoute, cls).setUpClass()
1067
1068 @classmethod
1069 def tearDownClass(cls):
1070 super(TestIPv6IfAddrRoute, cls).tearDownClass()
1071
1072 def setUp(self):
1073 super(TestIPv6IfAddrRoute, self).setUp()
1074
1075 # create 1 pg interface
1076 self.create_pg_interfaces(range(1))
1077
1078 for i in self.pg_interfaces:
1079 i.admin_up()
1080 i.config_ip6()
1081 i.resolve_ndp()
1082
1083 def tearDown(self):
1084 super(TestIPv6IfAddrRoute, self).tearDown()
1085 for i in self.pg_interfaces:
1086 i.unconfig_ip6()
1087 i.admin_down()
1088
1089 def test_ipv6_ifaddrs_same_prefix(self):
1090 """ IPv6 Interface Addresses Same Prefix test
1091
1092 Test scenario:
1093
1094 - Verify no route in FIB for prefix 2001:10::/64
1095 - Configure IPv4 address 2001:10::10/64 on an interface
1096 - Verify route in FIB for prefix 2001:10::/64
1097 - Configure IPv4 address 2001:10::20/64 on an interface
1098 - Delete 2001:10::10/64 from interface
1099 - Verify route in FIB for prefix 2001:10::/64
1100 - Delete 2001:10::20/64 from interface
1101 - Verify no route in FIB for prefix 2001:10::/64
1102 """
1103
1104 addr1 = "2001:10::10"
1105 addr2 = "2001:10::20"
1106
Neale Rannsefd7bc22019-11-11 08:32:34 +00001107 if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64)
1108 if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64)
1109 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001110 self.assertFalse(find_route(self, addr1, 128))
1111 self.assertFalse(find_route(self, addr2, 128))
1112
1113 # configure first address, verify route present
1114 if_addr1.add_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001115 self.assertTrue(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001116 self.assertTrue(find_route(self, addr1, 128))
1117 self.assertFalse(find_route(self, addr2, 128))
1118
1119 # configure second address, delete first, verify route not removed
1120 if_addr2.add_vpp_config()
1121 if_addr1.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001122 self.assertFalse(if_addr1.query_vpp_config())
1123 self.assertTrue(if_addr2.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001124 self.assertFalse(find_route(self, addr1, 128))
1125 self.assertTrue(find_route(self, addr2, 128))
1126
1127 # delete second address, verify route removed
1128 if_addr2.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001129 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001130 self.assertFalse(find_route(self, addr1, 128))
1131 self.assertFalse(find_route(self, addr2, 128))
1132
yedgdbd366b2020-05-14 10:51:53 +08001133 def test_ipv6_ifaddr_del(self):
1134 """ Delete an interface address that does not exist """
1135
1136 loopbacks = self.create_loopback_interfaces(1)
1137 lo = self.lo_interfaces[0]
1138
1139 lo.config_ip6()
1140 lo.admin_up()
1141
1142 #
1143 # try and remove pg0's subnet from lo
1144 #
1145 with self.vapi.assert_negative_api_retval():
1146 self.vapi.sw_interface_add_del_address(
1147 sw_if_index=lo.sw_if_index,
1148 prefix=self.pg0.local_ip6_prefix,
1149 is_add=0)
1150
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001151
Jan Geletye6c78ee2018-06-26 12:24:03 +02001152class TestICMPv6Echo(VppTestCase):
1153 """ ICMPv6 Echo Test Case """
1154
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001155 @classmethod
1156 def setUpClass(cls):
1157 super(TestICMPv6Echo, cls).setUpClass()
1158
1159 @classmethod
1160 def tearDownClass(cls):
1161 super(TestICMPv6Echo, cls).tearDownClass()
1162
Jan Geletye6c78ee2018-06-26 12:24:03 +02001163 def setUp(self):
1164 super(TestICMPv6Echo, self).setUp()
1165
1166 # create 1 pg interface
1167 self.create_pg_interfaces(range(1))
1168
1169 for i in self.pg_interfaces:
1170 i.admin_up()
1171 i.config_ip6()
Benoît Ganne2699fe22021-01-18 19:25:38 +01001172 i.resolve_ndp(link_layer=True)
Jan Geletye6c78ee2018-06-26 12:24:03 +02001173 i.resolve_ndp()
1174
1175 def tearDown(self):
1176 super(TestICMPv6Echo, self).tearDown()
1177 for i in self.pg_interfaces:
1178 i.unconfig_ip6()
Jan Geletye6c78ee2018-06-26 12:24:03 +02001179 i.admin_down()
1180
1181 def test_icmpv6_echo(self):
1182 """ VPP replies to ICMPv6 Echo Request
1183
1184 Test scenario:
1185
1186 - Receive ICMPv6 Echo Request message on pg0 interface.
1187 - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
1188 """
1189
Benoît Ganne2699fe22021-01-18 19:25:38 +01001190 # test both with global and local ipv6 addresses
1191 dsts = (self.pg0.local_ip6, self.pg0.local_ip6_ll)
1192 id = 0xb
1193 seq = 5
1194 data = b'\x0a' * 18
1195 p = list()
1196 for dst in dsts:
1197 p.append((Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
1198 IPv6(src=self.pg0.remote_ip6, dst=dst) /
1199 ICMPv6EchoRequest(id=id, seq=seq, data=data)))
Jan Geletye6c78ee2018-06-26 12:24:03 +02001200
Benoît Ganne2699fe22021-01-18 19:25:38 +01001201 self.pg0.add_stream(p)
Jan Geletye6c78ee2018-06-26 12:24:03 +02001202 self.pg_enable_capture(self.pg_interfaces)
1203 self.pg_start()
Benoît Ganne2699fe22021-01-18 19:25:38 +01001204 rxs = self.pg0.get_capture(len(dsts))
Jan Geletye6c78ee2018-06-26 12:24:03 +02001205
Benoît Ganne2699fe22021-01-18 19:25:38 +01001206 for rx, dst in zip(rxs, dsts):
1207 ether = rx[Ether]
1208 ipv6 = rx[IPv6]
1209 icmpv6 = rx[ICMPv6EchoReply]
1210 self.assertEqual(ether.src, self.pg0.local_mac)
1211 self.assertEqual(ether.dst, self.pg0.remote_mac)
1212 self.assertEqual(ipv6.src, dst)
1213 self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1214 self.assertEqual(icmp6types[icmpv6.type], "Echo Reply")
1215 self.assertEqual(icmpv6.id, id)
1216 self.assertEqual(icmpv6.seq, seq)
1217 self.assertEqual(icmpv6.data, data)
Jan Geletye6c78ee2018-06-26 12:24:03 +02001218
1219
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001220class TestIPv6RD(TestIPv6ND):
1221 """ IPv6 Router Discovery Test Case """
1222
1223 @classmethod
1224 def setUpClass(cls):
1225 super(TestIPv6RD, cls).setUpClass()
1226
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001227 @classmethod
1228 def tearDownClass(cls):
1229 super(TestIPv6RD, cls).tearDownClass()
1230
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001231 def setUp(self):
1232 super(TestIPv6RD, self).setUp()
1233
1234 # create 2 pg interfaces
1235 self.create_pg_interfaces(range(2))
1236
1237 self.interfaces = list(self.pg_interfaces)
1238
1239 # setup all interfaces
1240 for i in self.interfaces:
1241 i.admin_up()
1242 i.config_ip6()
1243
1244 def tearDown(self):
Neale Ranns744902e2017-08-14 10:35:44 -07001245 for i in self.interfaces:
1246 i.unconfig_ip6()
1247 i.admin_down()
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001248 super(TestIPv6RD, self).tearDown()
1249
1250 def test_rd_send_router_solicitation(self):
1251 """ Verify router solicitation packets """
1252
1253 count = 2
1254 self.pg_enable_capture(self.pg_interfaces)
1255 self.pg_start()
1256 self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1257 mrc=count)
1258 rx_list = self.pg1.get_capture(count, timeout=3)
1259 self.assertEqual(len(rx_list), count)
1260 for packet in rx_list:
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001261 self.assertEqual(packet.haslayer(IPv6), 1)
1262 self.assertEqual(packet[IPv6].haslayer(
1263 ICMPv6ND_RS), 1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001264 dst = ip6_normalize(packet[IPv6].dst)
1265 dst2 = ip6_normalize("ff02::2")
1266 self.assert_equal(dst, dst2)
1267 src = ip6_normalize(packet[IPv6].src)
1268 src2 = ip6_normalize(self.pg1.local_ip6_ll)
1269 self.assert_equal(src, src2)
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001270 self.assertTrue(
1271 bool(packet[ICMPv6ND_RS].haslayer(
1272 ICMPv6NDOptSrcLLAddr)))
1273 self.assert_equal(
1274 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1275 self.pg1.local_mac)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001276
1277 def verify_prefix_info(self, reported_prefix, prefix_option):
Neale Ranns37029302018-08-10 05:30:06 -07001278 prefix = IPv6Network(
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -08001279 text_type(prefix_option.getfieldval("prefix") +
1280 "/" +
1281 text_type(prefix_option.getfieldval("prefixlen"))),
Neale Ranns37029302018-08-10 05:30:06 -07001282 strict=False)
1283 self.assert_equal(reported_prefix.prefix.network_address,
1284 prefix.network_address)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001285 L = prefix_option.getfieldval("L")
1286 A = prefix_option.getfieldval("A")
1287 option_flags = (L << 7) | (A << 6)
1288 self.assert_equal(reported_prefix.flags, option_flags)
1289 self.assert_equal(reported_prefix.valid_time,
1290 prefix_option.getfieldval("validlifetime"))
1291 self.assert_equal(reported_prefix.preferred_time,
1292 prefix_option.getfieldval("preferredlifetime"))
1293
1294 def test_rd_receive_router_advertisement(self):
1295 """ Verify events triggered by received RA packets """
1296
Neale Rannscbe25aa2019-09-30 10:53:31 +00001297 self.vapi.want_ip6_ra_events(enable=1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001298
1299 prefix_info_1 = ICMPv6NDOptPrefixInfo(
1300 prefix="1::2",
1301 prefixlen=50,
1302 validlifetime=200,
1303 preferredlifetime=500,
1304 L=1,
1305 A=1,
1306 )
1307
1308 prefix_info_2 = ICMPv6NDOptPrefixInfo(
1309 prefix="7::4",
1310 prefixlen=20,
1311 validlifetime=70,
1312 preferredlifetime=1000,
1313 L=1,
1314 A=0,
1315 )
1316
1317 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1318 IPv6(dst=self.pg1.local_ip6_ll,
1319 src=mk_ll_addr(self.pg1.remote_mac)) /
1320 ICMPv6ND_RA() /
1321 prefix_info_1 /
1322 prefix_info_2)
1323 self.pg1.add_stream([p])
1324 self.pg_start()
1325
1326 ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1327
1328 self.assert_equal(ev.current_hop_limit, 0)
1329 self.assert_equal(ev.flags, 8)
1330 self.assert_equal(ev.router_lifetime_in_sec, 1800)
1331 self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1332 self.assert_equal(
1333 ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1334
1335 self.assert_equal(ev.n_prefixes, 2)
1336
1337 self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1338 self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1339
1340
Juraj Slobodac0374232018-02-01 15:18:49 +01001341class TestIPv6RDControlPlane(TestIPv6ND):
1342 """ IPv6 Router Discovery Control Plane Test Case """
1343
1344 @classmethod
1345 def setUpClass(cls):
1346 super(TestIPv6RDControlPlane, cls).setUpClass()
1347
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001348 @classmethod
1349 def tearDownClass(cls):
1350 super(TestIPv6RDControlPlane, cls).tearDownClass()
1351
Juraj Slobodac0374232018-02-01 15:18:49 +01001352 def setUp(self):
1353 super(TestIPv6RDControlPlane, self).setUp()
1354
1355 # create 1 pg interface
1356 self.create_pg_interfaces(range(1))
1357
1358 self.interfaces = list(self.pg_interfaces)
1359
1360 # setup all interfaces
1361 for i in self.interfaces:
1362 i.admin_up()
1363 i.config_ip6()
1364
1365 def tearDown(self):
1366 super(TestIPv6RDControlPlane, self).tearDown()
1367
1368 @staticmethod
1369 def create_ra_packet(pg, routerlifetime=None):
1370 src_ip = pg.remote_ip6_ll
1371 dst_ip = pg.local_ip6
1372 if routerlifetime is not None:
1373 ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1374 else:
1375 ra = ICMPv6ND_RA()
1376 p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1377 IPv6(dst=dst_ip, src=src_ip) / ra)
1378 return p
1379
1380 @staticmethod
1381 def get_default_routes(fib):
1382 list = []
1383 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001384 if entry.route.prefix.prefixlen == 0:
1385 for path in entry.route.paths:
Juraj Slobodac0374232018-02-01 15:18:49 +01001386 if path.sw_if_index != 0xFFFFFFFF:
Neale Ranns097fa662018-05-01 05:17:55 -07001387 defaut_route = {}
1388 defaut_route['sw_if_index'] = path.sw_if_index
1389 defaut_route['next_hop'] = path.nh.address.ip6
1390 list.append(defaut_route)
Juraj Slobodac0374232018-02-01 15:18:49 +01001391 return list
1392
1393 @staticmethod
1394 def get_interface_addresses(fib, pg):
1395 list = []
1396 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001397 if entry.route.prefix.prefixlen == 128:
1398 path = entry.route.paths[0]
Juraj Slobodac0374232018-02-01 15:18:49 +01001399 if path.sw_if_index == pg.sw_if_index:
Neale Ranns097fa662018-05-01 05:17:55 -07001400 list.append(str(entry.route.prefix.network_address))
Juraj Slobodac0374232018-02-01 15:18:49 +01001401 return list
1402
Neale Rannscbe25aa2019-09-30 10:53:31 +00001403 def wait_for_no_default_route(self, n_tries=50, s_time=1):
1404 while (n_tries):
1405 fib = self.vapi.ip_route_dump(0, True)
1406 default_routes = self.get_default_routes(fib)
Ole Troan6e6ad642020-02-04 13:28:13 +01001407 if 0 == len(default_routes):
Neale Rannscbe25aa2019-09-30 10:53:31 +00001408 return True
1409 n_tries = n_tries - 1
1410 self.sleep(s_time)
1411
1412 return False
1413
Juraj Slobodac0374232018-02-01 15:18:49 +01001414 def test_all(self):
1415 """ Test handling of SLAAC addresses and default routes """
1416
Neale Ranns097fa662018-05-01 05:17:55 -07001417 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001418 default_routes = self.get_default_routes(fib)
1419 initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1420 self.assertEqual(default_routes, [])
Neale Ranns097fa662018-05-01 05:17:55 -07001421 router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll))
Juraj Slobodac0374232018-02-01 15:18:49 +01001422
1423 self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1424
1425 self.sleep(0.1)
1426
1427 # send RA
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001428 packet = (self.create_ra_packet(
1429 self.pg0) / ICMPv6NDOptPrefixInfo(
Juraj Slobodac0374232018-02-01 15:18:49 +01001430 prefix="1::",
1431 prefixlen=64,
1432 validlifetime=2,
1433 preferredlifetime=2,
1434 L=1,
1435 A=1,
1436 ) / ICMPv6NDOptPrefixInfo(
1437 prefix="7::",
1438 prefixlen=20,
1439 validlifetime=1500,
1440 preferredlifetime=1000,
1441 L=1,
1442 A=0,
1443 ))
1444 self.pg0.add_stream([packet])
1445 self.pg_start()
1446
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001447 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001448
Neale Ranns097fa662018-05-01 05:17:55 -07001449 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001450
1451 # check FIB for new address
1452 addresses = set(self.get_interface_addresses(fib, self.pg0))
1453 new_addresses = addresses.difference(initial_addresses)
1454 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001455 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1456 strict=False)
1457 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001458
1459 # check FIB for new default route
1460 default_routes = self.get_default_routes(fib)
1461 self.assertEqual(len(default_routes), 1)
1462 dr = default_routes[0]
1463 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1464 self.assertEqual(dr['next_hop'], router_address)
1465
1466 # send RA to delete default route
1467 packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1468 self.pg0.add_stream([packet])
1469 self.pg_start()
1470
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001471 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001472
1473 # check that default route is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001474 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001475 default_routes = self.get_default_routes(fib)
1476 self.assertEqual(len(default_routes), 0)
1477
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001478 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001479
1480 # send RA
1481 packet = self.create_ra_packet(self.pg0)
1482 self.pg0.add_stream([packet])
1483 self.pg_start()
1484
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001485 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001486
1487 # check FIB for new default route
Neale Ranns097fa662018-05-01 05:17:55 -07001488 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001489 default_routes = self.get_default_routes(fib)
1490 self.assertEqual(len(default_routes), 1)
1491 dr = default_routes[0]
1492 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1493 self.assertEqual(dr['next_hop'], router_address)
1494
1495 # send RA, updating router lifetime to 1s
1496 packet = self.create_ra_packet(self.pg0, 1)
1497 self.pg0.add_stream([packet])
1498 self.pg_start()
1499
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001500 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001501
1502 # check that default route still exists
Neale Ranns097fa662018-05-01 05:17:55 -07001503 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001504 default_routes = self.get_default_routes(fib)
1505 self.assertEqual(len(default_routes), 1)
1506 dr = default_routes[0]
1507 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1508 self.assertEqual(dr['next_hop'], router_address)
1509
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001510 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001511
1512 # check that default route is deleted
Neale Rannscbe25aa2019-09-30 10:53:31 +00001513 self.assertTrue(self.wait_for_no_default_route())
Juraj Slobodac0374232018-02-01 15:18:49 +01001514
1515 # check FIB still contains the SLAAC address
1516 addresses = set(self.get_interface_addresses(fib, self.pg0))
1517 new_addresses = addresses.difference(initial_addresses)
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001518
Juraj Slobodac0374232018-02-01 15:18:49 +01001519 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001520 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1521 strict=False)
1522 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001523
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001524 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001525
1526 # check that SLAAC address is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001527 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001528 addresses = set(self.get_interface_addresses(fib, self.pg0))
1529 new_addresses = addresses.difference(initial_addresses)
1530 self.assertEqual(len(new_addresses), 0)
1531
1532
Neale Ranns3f844d02017-02-18 00:03:54 -08001533class IPv6NDProxyTest(TestIPv6ND):
1534 """ IPv6 ND ProxyTest Case """
1535
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001536 @classmethod
1537 def setUpClass(cls):
1538 super(IPv6NDProxyTest, cls).setUpClass()
1539
1540 @classmethod
1541 def tearDownClass(cls):
1542 super(IPv6NDProxyTest, cls).tearDownClass()
1543
Neale Ranns3f844d02017-02-18 00:03:54 -08001544 def setUp(self):
1545 super(IPv6NDProxyTest, self).setUp()
1546
1547 # create 3 pg interfaces
1548 self.create_pg_interfaces(range(3))
1549
1550 # pg0 is the master interface, with the configured subnet
1551 self.pg0.admin_up()
1552 self.pg0.config_ip6()
1553 self.pg0.resolve_ndp()
1554
1555 self.pg1.ip6_enable()
1556 self.pg2.ip6_enable()
1557
1558 def tearDown(self):
1559 super(IPv6NDProxyTest, self).tearDown()
1560
1561 def test_nd_proxy(self):
1562 """ IPv6 Proxy ND """
1563
1564 #
1565 # Generate some hosts in the subnet that we are proxying
1566 #
1567 self.pg0.generate_remote_hosts(8)
1568
1569 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1570 d = inet_ntop(AF_INET6, nsma)
1571
1572 #
1573 # Send an NS for one of those remote hosts on one of the proxy links
1574 # expect no response since it's from an address that is not
1575 # on the link that has the prefix configured
1576 #
1577 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001578 IPv6(dst=d,
1579 src=self.pg0._remote_hosts[2].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001580 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001581 ICMPv6NDOptSrcLLAddr(
1582 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001583
1584 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1585
1586 #
1587 # Add proxy support for the host
1588 #
Ole Troane1ade682019-03-04 23:55:43 +01001589 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001590 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001591 sw_if_index=self.pg1.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001592
1593 #
1594 # try that NS again. this time we expect an NA back
1595 #
Neale Ranns2a3ea492017-04-19 05:24:40 -07001596 self.send_and_expect_na(self.pg1, ns_pg1,
1597 "NS to proxy entry",
1598 dst_ip=self.pg0._remote_hosts[2].ip6,
1599 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001600
1601 #
1602 # ... and that we have an entry in the ND cache
1603 #
1604 self.assertTrue(find_nbr(self,
1605 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001606 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001607
1608 #
1609 # ... and we can route traffic to it
1610 #
1611 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1612 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1613 src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001614 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001615 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001616
1617 self.pg0.add_stream(t)
1618 self.pg_enable_capture(self.pg_interfaces)
1619 self.pg_start()
1620 rx = self.pg1.get_capture(1)
1621 rx = rx[0]
1622
1623 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1624 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1625
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001626 self.assertEqual(rx[IPv6].src,
1627 t[IPv6].src)
1628 self.assertEqual(rx[IPv6].dst,
1629 t[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001630
1631 #
1632 # Test we proxy for the host on the main interface
1633 #
1634 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1635 IPv6(dst=d, src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001636 ICMPv6ND_NS(
1637 tgt=self.pg0._remote_hosts[2].ip6) /
1638 ICMPv6NDOptSrcLLAddr(
1639 lladdr=self.pg0.remote_mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001640
Neale Ranns2a3ea492017-04-19 05:24:40 -07001641 self.send_and_expect_na(self.pg0, ns_pg0,
1642 "NS to proxy entry on main",
1643 tgt_ip=self.pg0._remote_hosts[2].ip6,
1644 dst_ip=self.pg0.remote_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001645
1646 #
1647 # Setup and resolve proxy for another host on another interface
1648 #
1649 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001650 IPv6(dst=d,
1651 src=self.pg0._remote_hosts[3].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001652 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001653 ICMPv6NDOptSrcLLAddr(
1654 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001655
Ole Troane1ade682019-03-04 23:55:43 +01001656 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001657 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001658 sw_if_index=self.pg2.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001659
Neale Ranns2a3ea492017-04-19 05:24:40 -07001660 self.send_and_expect_na(self.pg2, ns_pg2,
1661 "NS to proxy entry other interface",
1662 dst_ip=self.pg0._remote_hosts[3].ip6,
1663 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001664
1665 self.assertTrue(find_nbr(self,
1666 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001667 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001668
1669 #
1670 # hosts can communicate. pg2->pg1
1671 #
1672 t2 = (Ether(dst=self.pg2.local_mac,
1673 src=self.pg0.remote_hosts[3].mac) /
1674 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1675 src=self.pg0._remote_hosts[3].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001676 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001677 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001678
1679 self.pg2.add_stream(t2)
1680 self.pg_enable_capture(self.pg_interfaces)
1681 self.pg_start()
1682 rx = self.pg1.get_capture(1)
1683 rx = rx[0]
1684
1685 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1686 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1687
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001688 self.assertEqual(rx[IPv6].src,
1689 t2[IPv6].src)
1690 self.assertEqual(rx[IPv6].dst,
1691 t2[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001692
1693 #
1694 # remove the proxy configs
1695 #
Ole Troane1ade682019-03-04 23:55:43 +01001696 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001697 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001698 sw_if_index=self.pg1.sw_if_index, is_add=0)
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[3].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001701 sw_if_index=self.pg2.sw_if_index, is_add=0)
Neale Ranns3f844d02017-02-18 00:03:54 -08001702
1703 self.assertFalse(find_nbr(self,
1704 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001705 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001706 self.assertFalse(find_nbr(self,
1707 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001708 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001709
1710 #
1711 # no longer proxy-ing...
1712 #
1713 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1714 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1715 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1716
1717 #
1718 # no longer forwarding. traffic generates NS out of the glean/main
1719 # interface
1720 #
1721 self.pg2.add_stream(t2)
1722 self.pg_enable_capture(self.pg_interfaces)
1723 self.pg_start()
1724
1725 rx = self.pg0.get_capture(1)
1726
1727 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1728
1729
Neale Ranns37be7362017-02-21 17:30:26 -08001730class TestIPNull(VppTestCase):
1731 """ IPv6 routes via NULL """
1732
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001733 @classmethod
1734 def setUpClass(cls):
1735 super(TestIPNull, cls).setUpClass()
1736
1737 @classmethod
1738 def tearDownClass(cls):
1739 super(TestIPNull, cls).tearDownClass()
1740
Neale Ranns37be7362017-02-21 17:30:26 -08001741 def setUp(self):
1742 super(TestIPNull, self).setUp()
1743
1744 # create 2 pg interfaces
1745 self.create_pg_interfaces(range(1))
1746
1747 for i in self.pg_interfaces:
1748 i.admin_up()
1749 i.config_ip6()
1750 i.resolve_ndp()
1751
1752 def tearDown(self):
1753 super(TestIPNull, self).tearDown()
1754 for i in self.pg_interfaces:
1755 i.unconfig_ip6()
1756 i.admin_down()
1757
1758 def test_ip_null(self):
1759 """ IP NULL route """
1760
1761 p = (Ether(src=self.pg0.remote_mac,
1762 dst=self.pg0.local_mac) /
1763 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001764 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001765 Raw(b'\xa5' * 100))
Neale Ranns37be7362017-02-21 17:30:26 -08001766
1767 #
1768 # A route via IP NULL that will reply with ICMP unreachables
1769 #
Neale Ranns097fa662018-05-01 05:17:55 -07001770 ip_unreach = VppIpRoute(
1771 self, "2001::", 64,
1772 [VppRoutePath("::", 0xffffffff,
1773 type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)])
Neale Ranns37be7362017-02-21 17:30:26 -08001774 ip_unreach.add_vpp_config()
1775
1776 self.pg0.add_stream(p)
1777 self.pg_enable_capture(self.pg_interfaces)
1778 self.pg_start()
1779
1780 rx = self.pg0.get_capture(1)
1781 rx = rx[0]
1782 icmp = rx[ICMPv6DestUnreach]
1783
1784 # 0 = "No route to destination"
1785 self.assertEqual(icmp.code, 0)
1786
1787 # ICMP is rate limited. pause a bit
1788 self.sleep(1)
1789
1790 #
1791 # A route via IP NULL that will reply with ICMP prohibited
1792 #
Neale Ranns097fa662018-05-01 05:17:55 -07001793 ip_prohibit = VppIpRoute(
1794 self, "2001::1", 128,
1795 [VppRoutePath("::", 0xffffffff,
1796 type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)])
Neale Ranns37be7362017-02-21 17:30:26 -08001797 ip_prohibit.add_vpp_config()
1798
1799 self.pg0.add_stream(p)
1800 self.pg_enable_capture(self.pg_interfaces)
1801 self.pg_start()
1802
1803 rx = self.pg0.get_capture(1)
1804 rx = rx[0]
1805 icmp = rx[ICMPv6DestUnreach]
1806
1807 # 1 = "Communication with destination administratively prohibited"
1808 self.assertEqual(icmp.code, 1)
1809
1810
Neale Ranns180279b2017-03-16 15:49:09 -04001811class TestIPDisabled(VppTestCase):
1812 """ IPv6 disabled """
1813
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001814 @classmethod
1815 def setUpClass(cls):
1816 super(TestIPDisabled, cls).setUpClass()
1817
1818 @classmethod
1819 def tearDownClass(cls):
1820 super(TestIPDisabled, cls).tearDownClass()
1821
Neale Ranns180279b2017-03-16 15:49:09 -04001822 def setUp(self):
1823 super(TestIPDisabled, self).setUp()
1824
1825 # create 2 pg interfaces
1826 self.create_pg_interfaces(range(2))
1827
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001828 # PG0 is IP enabled
Neale Ranns180279b2017-03-16 15:49:09 -04001829 self.pg0.admin_up()
1830 self.pg0.config_ip6()
1831 self.pg0.resolve_ndp()
1832
1833 # PG 1 is not IP enabled
1834 self.pg1.admin_up()
1835
1836 def tearDown(self):
1837 super(TestIPDisabled, self).tearDown()
1838 for i in self.pg_interfaces:
1839 i.unconfig_ip4()
1840 i.admin_down()
1841
Neale Ranns180279b2017-03-16 15:49:09 -04001842 def test_ip_disabled(self):
1843 """ IP Disabled """
1844
Neale Ranns990f6942020-10-20 07:20:17 +00001845 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
1846 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
Neale Ranns180279b2017-03-16 15:49:09 -04001847 #
1848 # An (S,G).
1849 # one accepting interface, pg0, 2 forwarding interfaces
1850 #
1851 route_ff_01 = VppIpMRoute(
1852 self,
1853 "::",
1854 "ffef::1", 128,
Neale Ranns990f6942020-10-20 07:20:17 +00001855 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
Neale Ranns180279b2017-03-16 15:49:09 -04001856 [VppMRoutePath(self.pg1.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00001857 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
Neale Ranns180279b2017-03-16 15:49:09 -04001858 VppMRoutePath(self.pg0.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00001859 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
Neale Ranns180279b2017-03-16 15:49:09 -04001860 route_ff_01.add_vpp_config()
1861
1862 pu = (Ether(src=self.pg1.remote_mac,
1863 dst=self.pg1.local_mac) /
1864 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001865 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001866 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001867 pm = (Ether(src=self.pg1.remote_mac,
1868 dst=self.pg1.local_mac) /
1869 IPv6(src="2001::1", dst="ffef::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001870 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001871 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001872
1873 #
1874 # PG1 does not forward IP traffic
1875 #
1876 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1877 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1878
1879 #
1880 # IP enable PG1
1881 #
1882 self.pg1.config_ip6()
1883
1884 #
1885 # Now we get packets through
1886 #
1887 self.pg1.add_stream(pu)
1888 self.pg_enable_capture(self.pg_interfaces)
1889 self.pg_start()
1890 rx = self.pg0.get_capture(1)
1891
1892 self.pg1.add_stream(pm)
1893 self.pg_enable_capture(self.pg_interfaces)
1894 self.pg_start()
1895 rx = self.pg0.get_capture(1)
1896
1897 #
1898 # Disable PG1
1899 #
1900 self.pg1.unconfig_ip6()
1901
1902 #
1903 # PG1 does not forward IP traffic
1904 #
1905 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1906 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1907
1908
Neale Ranns227038a2017-04-21 01:07:59 -07001909class TestIP6LoadBalance(VppTestCase):
1910 """ IPv6 Load-Balancing """
1911
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001912 @classmethod
1913 def setUpClass(cls):
1914 super(TestIP6LoadBalance, cls).setUpClass()
1915
1916 @classmethod
1917 def tearDownClass(cls):
1918 super(TestIP6LoadBalance, cls).tearDownClass()
1919
Neale Ranns227038a2017-04-21 01:07:59 -07001920 def setUp(self):
1921 super(TestIP6LoadBalance, self).setUp()
1922
1923 self.create_pg_interfaces(range(5))
1924
Neale Ranns15002542017-09-10 04:39:11 -07001925 mpls_tbl = VppMplsTable(self, 0)
1926 mpls_tbl.add_vpp_config()
1927
Neale Ranns227038a2017-04-21 01:07:59 -07001928 for i in self.pg_interfaces:
1929 i.admin_up()
1930 i.config_ip6()
1931 i.resolve_ndp()
Neale Ranns71275e32017-05-25 12:38:58 -07001932 i.enable_mpls()
Neale Ranns227038a2017-04-21 01:07:59 -07001933
1934 def tearDown(self):
Neale Ranns227038a2017-04-21 01:07:59 -07001935 for i in self.pg_interfaces:
1936 i.unconfig_ip6()
1937 i.admin_down()
Neale Ranns71275e32017-05-25 12:38:58 -07001938 i.disable_mpls()
Neale Ranns15002542017-09-10 04:39:11 -07001939 super(TestIP6LoadBalance, self).tearDown()
Neale Ranns227038a2017-04-21 01:07:59 -07001940
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001941 def pg_send(self, input, pkts):
Neale Ranns62fe07c2017-10-31 12:28:22 -07001942 self.vapi.cli("clear trace")
Neale Ranns227038a2017-04-21 01:07:59 -07001943 input.add_stream(pkts)
1944 self.pg_enable_capture(self.pg_interfaces)
1945 self.pg_start()
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001946
1947 def send_and_expect_load_balancing(self, input, pkts, outputs):
1948 self.pg_send(input, pkts)
Neale Ranns227038a2017-04-21 01:07:59 -07001949 for oo in outputs:
1950 rx = oo._get_capture(1)
1951 self.assertNotEqual(0, len(rx))
1952
Neale Ranns71275e32017-05-25 12:38:58 -07001953 def send_and_expect_one_itf(self, input, pkts, itf):
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001954 self.pg_send(input, pkts)
Neale Ranns71275e32017-05-25 12:38:58 -07001955 rx = itf.get_capture(len(pkts))
1956
Neale Ranns227038a2017-04-21 01:07:59 -07001957 def test_ip6_load_balance(self):
1958 """ IPv6 Load-Balancing """
1959
1960 #
1961 # An array of packets that differ only in the destination port
Neale Ranns71275e32017-05-25 12:38:58 -07001962 # - IP only
1963 # - MPLS EOS
1964 # - MPLS non-EOS
1965 # - MPLS non-EOS with an entropy label
Neale Ranns227038a2017-04-21 01:07:59 -07001966 #
Neale Ranns71275e32017-05-25 12:38:58 -07001967 port_ip_pkts = []
1968 port_mpls_pkts = []
1969 port_mpls_neos_pkts = []
1970 port_ent_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001971
1972 #
1973 # An array of packets that differ only in the source address
1974 #
Neale Ranns71275e32017-05-25 12:38:58 -07001975 src_ip_pkts = []
1976 src_mpls_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001977
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001978 for ii in range(NUM_PKTS):
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001979 port_ip_hdr = (
1980 IPv6(dst="3000::1", src="3000:1::1") /
1981 inet6.UDP(sport=1234, dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01001982 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001983 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1984 dst=self.pg0.local_mac) /
1985 port_ip_hdr))
1986 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1987 dst=self.pg0.local_mac) /
1988 MPLS(label=66, ttl=2) /
1989 port_ip_hdr))
1990 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1991 dst=self.pg0.local_mac) /
1992 MPLS(label=67, ttl=2) /
1993 MPLS(label=77, ttl=2) /
1994 port_ip_hdr))
1995 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1996 dst=self.pg0.local_mac) /
1997 MPLS(label=67, ttl=2) /
1998 MPLS(label=14, ttl=2) /
1999 MPLS(label=999, ttl=2) /
2000 port_ip_hdr))
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002001 src_ip_hdr = (
2002 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
2003 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002004 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07002005 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
2006 dst=self.pg0.local_mac) /
2007 src_ip_hdr))
2008 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
2009 dst=self.pg0.local_mac) /
2010 MPLS(label=66, ttl=2) /
2011 src_ip_hdr))
Neale Ranns227038a2017-04-21 01:07:59 -07002012
Neale Ranns71275e32017-05-25 12:38:58 -07002013 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002014 # A route for the IP packets
Neale Ranns71275e32017-05-25 12:38:58 -07002015 #
Neale Ranns227038a2017-04-21 01:07:59 -07002016 route_3000_1 = VppIpRoute(self, "3000::1", 128,
2017 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002018 self.pg1.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002019 VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002020 self.pg2.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002021 route_3000_1.add_vpp_config()
2022
2023 #
Neale Ranns71275e32017-05-25 12:38:58 -07002024 # a local-label for the EOS packets
2025 #
2026 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
2027 binding.add_vpp_config()
2028
2029 #
2030 # An MPLS route for the non-EOS packets
2031 #
2032 route_67 = VppMplsRoute(self, 67, 0,
2033 [VppRoutePath(self.pg1.remote_ip6,
2034 self.pg1.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07002035 labels=[67]),
Neale Ranns71275e32017-05-25 12:38:58 -07002036 VppRoutePath(self.pg2.remote_ip6,
2037 self.pg2.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07002038 labels=[67])])
Neale Ranns71275e32017-05-25 12:38:58 -07002039 route_67.add_vpp_config()
2040
2041 #
Neale Ranns227038a2017-04-21 01:07:59 -07002042 # inject the packet on pg0 - expect load-balancing across the 2 paths
2043 # - since the default hash config is to use IP src,dst and port
2044 # src,dst
2045 # We are not going to ensure equal amounts of packets across each link,
2046 # since the hash algorithm is statistical and therefore this can never
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002047 # be guaranteed. But with 64 different packets we do expect some
Neale Ranns227038a2017-04-21 01:07:59 -07002048 # balancing. So instead just ensure there is traffic on each link.
2049 #
Neale Ranns71275e32017-05-25 12:38:58 -07002050 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002051 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002052 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002053 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002054 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
2055 [self.pg1, self.pg2])
2056 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2057 [self.pg1, self.pg2])
2058 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
2059 [self.pg1, self.pg2])
2060
2061 #
2062 # The packets with Entropy label in should not load-balance,
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002063 # since the Entropy value is fixed.
Neale Ranns71275e32017-05-25 12:38:58 -07002064 #
2065 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
Neale Ranns227038a2017-04-21 01:07:59 -07002066
2067 #
2068 # change the flow hash config so it's only IP src,dst
2069 # - now only the stream with differing source address will
2070 # load-balance
2071 #
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002072 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, proto=1,
2073 sport=0, dport=0, is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07002074
Neale Ranns71275e32017-05-25 12:38:58 -07002075 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07002076 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07002077 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
2078 [self.pg1, self.pg2])
2079 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
Neale Ranns227038a2017-04-21 01:07:59 -07002080
2081 #
2082 # change the flow hash config back to defaults
2083 #
Ole Troana5b2eec2019-03-11 19:23:25 +01002084 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1,
Ahmed Abdelsalamf2984bb2020-11-20 18:56:09 +00002085 proto=1, is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07002086
2087 #
2088 # Recursive prefixes
2089 # - testing that 2 stages of load-balancing occurs and there is no
2090 # polarisation (i.e. only 2 of 4 paths are used)
2091 #
2092 port_pkts = []
2093 src_pkts = []
2094
2095 for ii in range(257):
2096 port_pkts.append((Ether(src=self.pg0.remote_mac,
2097 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002098 IPv6(dst="4000::1",
2099 src="4000:1::1") /
2100 inet6.UDP(sport=1234,
2101 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002102 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002103 src_pkts.append((Ether(src=self.pg0.remote_mac,
2104 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002105 IPv6(dst="4000::1",
2106 src="4000:1::%d" % ii) /
2107 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002108 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002109
2110 route_3000_2 = VppIpRoute(self, "3000::2", 128,
2111 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002112 self.pg3.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002113 VppRoutePath(self.pg4.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002114 self.pg4.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002115 route_3000_2.add_vpp_config()
2116
2117 route_4000_1 = VppIpRoute(self, "4000::1", 128,
2118 [VppRoutePath("3000::1",
Neale Ranns097fa662018-05-01 05:17:55 -07002119 0xffffffff),
Neale Ranns227038a2017-04-21 01:07:59 -07002120 VppRoutePath("3000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002121 0xffffffff)])
Neale Ranns227038a2017-04-21 01:07:59 -07002122 route_4000_1.add_vpp_config()
2123
2124 #
2125 # inject the packet on pg0 - expect load-balancing across all 4 paths
2126 #
2127 self.vapi.cli("clear trace")
2128 self.send_and_expect_load_balancing(self.pg0, port_pkts,
2129 [self.pg1, self.pg2,
2130 self.pg3, self.pg4])
2131 self.send_and_expect_load_balancing(self.pg0, src_pkts,
2132 [self.pg1, self.pg2,
2133 self.pg3, self.pg4])
2134
Neale Ranns42e6b092017-07-31 02:56:03 -07002135 #
2136 # Recursive prefixes
2137 # - testing that 2 stages of load-balancing no choices
2138 #
2139 port_pkts = []
2140
2141 for ii in range(257):
2142 port_pkts.append((Ether(src=self.pg0.remote_mac,
2143 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002144 IPv6(dst="6000::1",
2145 src="6000:1::1") /
2146 inet6.UDP(sport=1234,
2147 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002148 Raw(b'\xa5' * 100)))
Neale Ranns42e6b092017-07-31 02:56:03 -07002149
2150 route_5000_2 = VppIpRoute(self, "5000::2", 128,
2151 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002152 self.pg3.sw_if_index)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002153 route_5000_2.add_vpp_config()
2154
2155 route_6000_1 = VppIpRoute(self, "6000::1", 128,
2156 [VppRoutePath("5000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002157 0xffffffff)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002158 route_6000_1.add_vpp_config()
2159
2160 #
2161 # inject the packet on pg0 - expect load-balancing across all 4 paths
2162 #
2163 self.vapi.cli("clear trace")
2164 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
2165
Neale Ranns227038a2017-04-21 01:07:59 -07002166
Neale Rannsd91c1db2017-07-31 02:30:50 -07002167class TestIP6Punt(VppTestCase):
2168 """ IPv6 Punt Police/Redirect """
2169
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002170 @classmethod
2171 def setUpClass(cls):
2172 super(TestIP6Punt, cls).setUpClass()
2173
2174 @classmethod
2175 def tearDownClass(cls):
2176 super(TestIP6Punt, cls).tearDownClass()
2177
Neale Rannsd91c1db2017-07-31 02:30:50 -07002178 def setUp(self):
2179 super(TestIP6Punt, self).setUp()
2180
Pavel Kotucek609e1212018-11-27 09:59:44 +01002181 self.create_pg_interfaces(range(4))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002182
2183 for i in self.pg_interfaces:
2184 i.admin_up()
2185 i.config_ip6()
2186 i.resolve_ndp()
2187
2188 def tearDown(self):
2189 super(TestIP6Punt, self).tearDown()
2190 for i in self.pg_interfaces:
2191 i.unconfig_ip6()
2192 i.admin_down()
2193
Neale Rannsd91c1db2017-07-31 02:30:50 -07002194 def test_ip_punt(self):
2195 """ IP6 punt police and redirect """
2196
2197 p = (Ether(src=self.pg0.remote_mac,
2198 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002199 IPv6(src=self.pg0.remote_ip6,
2200 dst=self.pg0.local_ip6) /
2201 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002202 Raw(b'\xa5' * 100))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002203
2204 pkts = p * 1025
2205
2206 #
2207 # Configure a punt redirect via pg1.
2208 #
Ole Troan0bcad322018-12-11 13:04:01 +01002209 nh_addr = self.pg1.remote_ip6
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002210 ip_punt_redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index,
2211 self.pg1.sw_if_index, nh_addr)
2212 ip_punt_redirect.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002213
2214 self.send_and_expect(self.pg0, pkts, self.pg1)
2215
2216 #
2217 # add a policer
2218 #
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002219 policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1)
2220 policer.add_vpp_config()
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002221 ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index,
2222 is_ip6=True)
2223 ip_punt_policer.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002224
2225 self.vapi.cli("clear trace")
2226 self.pg0.add_stream(pkts)
2227 self.pg_enable_capture(self.pg_interfaces)
2228 self.pg_start()
2229
2230 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002231 # the number of packet received should be greater than 0,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002232 # but not equal to the number sent, since some were policed
2233 #
2234 rx = self.pg1._get_capture(1)
Paul Vinciguerra3d2df212018-11-24 23:19:53 -08002235 self.assertGreater(len(rx), 0)
2236 self.assertLess(len(rx), len(pkts))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002237
2238 #
Paul Vinciguerraeb414432019-02-20 09:01:14 -08002239 # remove the policer. back to full rx
Neale Rannsd91c1db2017-07-31 02:30:50 -07002240 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002241 ip_punt_policer.remove_vpp_config()
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002242 policer.remove_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002243 self.send_and_expect(self.pg0, pkts, self.pg1)
2244
2245 #
2246 # remove the redirect. expect full drop.
2247 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002248 ip_punt_redirect.remove_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002249 self.send_and_assert_no_replies(self.pg0, pkts,
2250 "IP no punt config")
2251
2252 #
2253 # Add a redirect that is not input port selective
2254 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002255 ip_punt_redirect = VppIpPuntRedirect(self, 0xffffffff,
2256 self.pg1.sw_if_index, nh_addr)
2257 ip_punt_redirect.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002258 self.send_and_expect(self.pg0, pkts, self.pg1)
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002259 ip_punt_redirect.remove_vpp_config()
Pavel Kotucek609e1212018-11-27 09:59:44 +01002260
2261 def test_ip_punt_dump(self):
2262 """ IP6 punt redirect dump"""
2263
2264 #
2265 # Configure a punt redirects
2266 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002267 nh_address = self.pg3.remote_ip6
2268 ipr_03 = VppIpPuntRedirect(self, self.pg0.sw_if_index,
2269 self.pg3.sw_if_index, nh_address)
2270 ipr_13 = VppIpPuntRedirect(self, self.pg1.sw_if_index,
2271 self.pg3.sw_if_index, nh_address)
2272 ipr_23 = VppIpPuntRedirect(self, self.pg2.sw_if_index,
2273 self.pg3.sw_if_index, '0::0')
2274 ipr_03.add_vpp_config()
2275 ipr_13.add_vpp_config()
2276 ipr_23.add_vpp_config()
Pavel Kotucek609e1212018-11-27 09:59:44 +01002277
2278 #
2279 # Dump pg0 punt redirects
2280 #
Jakub Grajciar2df2f752020-12-01 11:23:44 +01002281 self.assertTrue(ipr_03.query_vpp_config())
2282 self.assertTrue(ipr_13.query_vpp_config())
2283 self.assertTrue(ipr_23.query_vpp_config())
Pavel Kotucek609e1212018-11-27 09:59:44 +01002284
2285 #
2286 # Dump punt redirects for all interfaces
2287 #
2288 punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2289 self.assertEqual(len(punts), 3)
2290 for p in punts:
2291 self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
Ole Troan0bcad322018-12-11 13:04:01 +01002292 self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2293 self.assertEqual(str(punts[2].punt.nh), '::')
Neale Rannsd91c1db2017-07-31 02:30:50 -07002294
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002295
Neale Rannsce9e0b42018-08-01 12:53:17 -07002296class TestIPDeag(VppTestCase):
2297 """ IPv6 Deaggregate Routes """
2298
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002299 @classmethod
2300 def setUpClass(cls):
2301 super(TestIPDeag, cls).setUpClass()
2302
2303 @classmethod
2304 def tearDownClass(cls):
2305 super(TestIPDeag, cls).tearDownClass()
2306
Neale Rannsce9e0b42018-08-01 12:53:17 -07002307 def setUp(self):
2308 super(TestIPDeag, self).setUp()
2309
2310 self.create_pg_interfaces(range(3))
2311
2312 for i in self.pg_interfaces:
2313 i.admin_up()
2314 i.config_ip6()
2315 i.resolve_ndp()
2316
2317 def tearDown(self):
2318 super(TestIPDeag, self).tearDown()
2319 for i in self.pg_interfaces:
2320 i.unconfig_ip6()
2321 i.admin_down()
2322
2323 def test_ip_deag(self):
2324 """ IP Deag Routes """
2325
2326 #
2327 # Create a table to be used for:
2328 # 1 - another destination address lookup
2329 # 2 - a source address lookup
2330 #
2331 table_dst = VppIpTable(self, 1, is_ip6=1)
2332 table_src = VppIpTable(self, 2, is_ip6=1)
2333 table_dst.add_vpp_config()
2334 table_src.add_vpp_config()
2335
2336 #
2337 # Add a route in the default table to point to a deag/
2338 # second lookup in each of these tables
2339 #
2340 route_to_dst = VppIpRoute(self, "1::1", 128,
2341 [VppRoutePath("::",
2342 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -07002343 nh_table_id=1)])
2344 route_to_src = VppIpRoute(
2345 self, "1::2", 128,
2346 [VppRoutePath("::",
2347 0xffffffff,
2348 nh_table_id=2,
2349 type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)])
2350
Neale Rannsce9e0b42018-08-01 12:53:17 -07002351 route_to_dst.add_vpp_config()
2352 route_to_src.add_vpp_config()
2353
2354 #
2355 # packets to these destination are dropped, since they'll
2356 # hit the respective default routes in the second table
2357 #
2358 p_dst = (Ether(src=self.pg0.remote_mac,
2359 dst=self.pg0.local_mac) /
2360 IPv6(src="5::5", dst="1::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002361 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002362 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002363 p_src = (Ether(src=self.pg0.remote_mac,
2364 dst=self.pg0.local_mac) /
2365 IPv6(src="2::2", dst="1::2") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002366 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002367 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002368 pkts_dst = p_dst * 257
2369 pkts_src = p_src * 257
2370
2371 self.send_and_assert_no_replies(self.pg0, pkts_dst,
2372 "IP in dst table")
2373 self.send_and_assert_no_replies(self.pg0, pkts_src,
2374 "IP in src table")
2375
2376 #
2377 # add a route in the dst table to forward via pg1
2378 #
2379 route_in_dst = VppIpRoute(self, "1::1", 128,
2380 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002381 self.pg1.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002382 table_id=1)
2383 route_in_dst.add_vpp_config()
2384
2385 self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2386
2387 #
2388 # add a route in the src table to forward via pg2
2389 #
2390 route_in_src = VppIpRoute(self, "2::2", 128,
2391 [VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002392 self.pg2.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002393 table_id=2)
2394 route_in_src.add_vpp_config()
2395 self.send_and_expect(self.pg0, pkts_src, self.pg2)
2396
2397 #
2398 # loop in the lookup DP
2399 #
2400 route_loop = VppIpRoute(self, "3::3", 128,
2401 [VppRoutePath("::",
Neale Ranns097fa662018-05-01 05:17:55 -07002402 0xffffffff)])
Neale Rannsce9e0b42018-08-01 12:53:17 -07002403 route_loop.add_vpp_config()
2404
2405 p_l = (Ether(src=self.pg0.remote_mac,
2406 dst=self.pg0.local_mac) /
2407 IPv6(src="3::4", dst="3::3") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002408 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002409 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002410
2411 self.send_and_assert_no_replies(self.pg0, p_l * 257,
2412 "IP lookup loop")
2413
2414
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002415class TestIP6Input(VppTestCase):
Neale Rannsae809832018-11-23 09:00:27 -08002416 """ IPv6 Input Exception Test Cases """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002417
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002418 @classmethod
2419 def setUpClass(cls):
2420 super(TestIP6Input, cls).setUpClass()
2421
2422 @classmethod
2423 def tearDownClass(cls):
2424 super(TestIP6Input, cls).tearDownClass()
2425
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002426 def setUp(self):
2427 super(TestIP6Input, self).setUp()
2428
2429 self.create_pg_interfaces(range(2))
2430
2431 for i in self.pg_interfaces:
2432 i.admin_up()
2433 i.config_ip6()
2434 i.resolve_ndp()
2435
2436 def tearDown(self):
2437 super(TestIP6Input, self).tearDown()
2438 for i in self.pg_interfaces:
2439 i.unconfig_ip6()
2440 i.admin_down()
2441
Neale Rannsae809832018-11-23 09:00:27 -08002442 def test_ip_input_icmp_reply(self):
2443 """ IP6 Input Exception - Return ICMP (3,0) """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002444 #
Neale Rannsae809832018-11-23 09:00:27 -08002445 # hop limit - ICMP replies
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002446 #
2447 p_version = (Ether(src=self.pg0.remote_mac,
2448 dst=self.pg0.local_mac) /
2449 IPv6(src=self.pg0.remote_ip6,
2450 dst=self.pg1.remote_ip6,
2451 hlim=1) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002452 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002453 Raw(b'\xa5' * 100))
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002454
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002455 rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002456 rx = rx[0]
2457 icmp = rx[ICMPv6TimeExceeded]
Neale Rannsae809832018-11-23 09:00:27 -08002458
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002459 # 0: "hop limit exceeded in transit",
Neale Rannsae809832018-11-23 09:00:27 -08002460 self.assertEqual((icmp.type, icmp.code), (3, 0))
2461
2462 icmpv6_data = '\x0a' * 18
2463 all_0s = "::"
2464 all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2465
2466 @parameterized.expand([
2467 # Name, src, dst, l4proto, msg, timeout
2468 ("src='iface', dst='iface'", None, None,
2469 inet6.UDP(sport=1234, dport=1234), "funky version", None),
2470 ("src='All 0's', dst='iface'", all_0s, None,
2471 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2472 ("src='iface', dst='All 0's'", None, all_0s,
2473 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2474 ("src='All 1's', dst='iface'", all_1s, None,
2475 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2476 ("src='iface', dst='All 1's'", None, all_1s,
2477 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2478 ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2479 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2480
2481 ])
2482 def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2483
2484 self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2485
2486 p_version = (Ether(src=self.pg0.remote_mac,
2487 dst=self.pg0.local_mac) /
2488 IPv6(src=src or self.pg0.remote_ip6,
2489 dst=dst or self.pg1.remote_ip6,
2490 version=3) /
2491 l4 /
Ole Troan770a0de2019-11-07 13:52:21 +01002492 Raw(b'\xa5' * 100))
Neale Rannsae809832018-11-23 09:00:27 -08002493
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002494 self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS,
Neale Rannsae809832018-11-23 09:00:27 -08002495 remark=msg or "",
2496 timeout=timeout)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002497
Dave Barach90800962019-05-24 13:03:01 -04002498 def test_hop_by_hop(self):
2499 """ Hop-by-hop header test """
2500
2501 p = (Ether(src=self.pg0.remote_mac,
2502 dst=self.pg0.local_mac) /
2503 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
2504 IPv6ExtHdrHopByHop() /
2505 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002506 Raw(b'\xa5' * 100))
Dave Barach90800962019-05-24 13:03:01 -04002507
2508 self.pg0.add_stream(p)
2509 self.pg_enable_capture(self.pg_interfaces)
2510 self.pg_start()
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002511
Neale Ranns9db6ada2019-11-08 12:42:31 +00002512
2513class TestIPReplace(VppTestCase):
2514 """ IPv6 Table Replace """
2515
2516 @classmethod
2517 def setUpClass(cls):
2518 super(TestIPReplace, cls).setUpClass()
2519
2520 @classmethod
2521 def tearDownClass(cls):
2522 super(TestIPReplace, cls).tearDownClass()
2523
2524 def setUp(self):
2525 super(TestIPReplace, self).setUp()
2526
2527 self.create_pg_interfaces(range(4))
2528
2529 table_id = 1
2530 self.tables = []
2531
2532 for i in self.pg_interfaces:
2533 i.admin_up()
2534 i.config_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002535 i.generate_remote_hosts(2)
2536 self.tables.append(VppIpTable(self, table_id,
2537 True).add_vpp_config())
2538 table_id += 1
2539
2540 def tearDown(self):
2541 super(TestIPReplace, self).tearDown()
2542 for i in self.pg_interfaces:
2543 i.admin_down()
Neale Rannsec40a7d2020-04-23 07:36:12 +00002544 i.unconfig_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002545
2546 def test_replace(self):
2547 """ IP Table Replace """
2548
Neale Ranns990f6942020-10-20 07:20:17 +00002549 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
2550 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
Neale Ranns9db6ada2019-11-08 12:42:31 +00002551 N_ROUTES = 20
2552 links = [self.pg0, self.pg1, self.pg2, self.pg3]
2553 routes = [[], [], [], []]
2554
2555 # the sizes of 'empty' tables
2556 for t in self.tables:
2557 self.assertEqual(len(t.dump()), 2)
2558 self.assertEqual(len(t.mdump()), 5)
2559
2560 # load up the tables with some routes
2561 for ii, t in enumerate(self.tables):
2562 for jj in range(1, N_ROUTES):
2563 uni = VppIpRoute(
2564 self, "2001::%d" % jj if jj != 0 else "2001::", 128,
2565 [VppRoutePath(links[ii].remote_hosts[0].ip6,
2566 links[ii].sw_if_index),
2567 VppRoutePath(links[ii].remote_hosts[1].ip6,
2568 links[ii].sw_if_index)],
2569 table_id=t.table_id).add_vpp_config()
2570 multi = VppIpMRoute(
2571 self, "::",
2572 "ff:2001::%d" % jj, 128,
Neale Ranns990f6942020-10-20 07:20:17 +00002573 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002574 [VppMRoutePath(self.pg0.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002575 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002576 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2577 VppMRoutePath(self.pg1.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002578 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002579 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2580 VppMRoutePath(self.pg2.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002581 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002582 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2583 VppMRoutePath(self.pg3.sw_if_index,
Neale Ranns990f6942020-10-20 07:20:17 +00002584 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
Neale Ranns9db6ada2019-11-08 12:42:31 +00002585 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
2586 table_id=t.table_id).add_vpp_config()
2587 routes[ii].append({'uni': uni,
2588 'multi': multi})
2589
2590 #
2591 # replace the tables a few times
2592 #
2593 for kk in range(3):
2594 # replace each table
2595 for t in self.tables:
2596 t.replace_begin()
2597
2598 # all the routes are still there
2599 for ii, t in enumerate(self.tables):
2600 dump = t.dump()
2601 mdump = t.mdump()
2602 for r in routes[ii]:
2603 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2604 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2605
2606 # redownload the even numbered routes
2607 for ii, t in enumerate(self.tables):
2608 for jj in range(0, N_ROUTES, 2):
2609 routes[ii][jj]['uni'].add_vpp_config()
2610 routes[ii][jj]['multi'].add_vpp_config()
2611
2612 # signal each table converged
2613 for t in self.tables:
2614 t.replace_end()
2615
2616 # we should find the even routes, but not the odd
2617 for ii, t in enumerate(self.tables):
2618 dump = t.dump()
2619 mdump = t.mdump()
2620 for jj in range(0, N_ROUTES, 2):
2621 self.assertTrue(find_route_in_dump(
2622 dump, routes[ii][jj]['uni'], t))
2623 self.assertTrue(find_mroute_in_dump(
2624 mdump, routes[ii][jj]['multi'], t))
2625 for jj in range(1, N_ROUTES - 1, 2):
2626 self.assertFalse(find_route_in_dump(
2627 dump, routes[ii][jj]['uni'], t))
2628 self.assertFalse(find_mroute_in_dump(
2629 mdump, routes[ii][jj]['multi'], t))
2630
2631 # reload all the routes
2632 for ii, t in enumerate(self.tables):
2633 for r in routes[ii]:
2634 r['uni'].add_vpp_config()
2635 r['multi'].add_vpp_config()
2636
2637 # all the routes are still there
2638 for ii, t in enumerate(self.tables):
2639 dump = t.dump()
2640 mdump = t.mdump()
2641 for r in routes[ii]:
2642 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2643 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2644
2645 #
2646 # finally flush the tables for good measure
2647 #
2648 for t in self.tables:
2649 t.flush()
2650 self.assertEqual(len(t.dump()), 2)
2651 self.assertEqual(len(t.mdump()), 5)
2652
2653
Neale Ranns59f71132020-04-08 12:19:38 +00002654class TestIP6Replace(VppTestCase):
2655 """ IPv4 Interface Address Replace """
2656
2657 @classmethod
2658 def setUpClass(cls):
2659 super(TestIP6Replace, cls).setUpClass()
2660
2661 @classmethod
2662 def tearDownClass(cls):
2663 super(TestIP6Replace, cls).tearDownClass()
2664
2665 def setUp(self):
2666 super(TestIP6Replace, self).setUp()
2667
2668 self.create_pg_interfaces(range(4))
2669
2670 for i in self.pg_interfaces:
2671 i.admin_up()
2672
2673 def tearDown(self):
2674 super(TestIP6Replace, self).tearDown()
2675 for i in self.pg_interfaces:
2676 i.admin_down()
2677
2678 def get_n_pfxs(self, intf):
2679 return len(self.vapi.ip_address_dump(intf.sw_if_index, True))
2680
2681 def test_replace(self):
2682 """ IP interface address replace """
2683
2684 intf_pfxs = [[], [], [], []]
2685
2686 # add prefixes to each of the interfaces
2687 for i in range(len(self.pg_interfaces)):
2688 intf = self.pg_interfaces[i]
2689
2690 # 2001:16:x::1/64
2691 addr = "2001:16:%d::1" % intf.sw_if_index
2692 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2693 intf_pfxs[i].append(a)
2694
2695 # 2001:16:x::2/64 - a different address in the same subnet as above
2696 addr = "2001:16:%d::2" % intf.sw_if_index
2697 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2698 intf_pfxs[i].append(a)
2699
2700 # 2001:15:x::2/64 - a different address and subnet
2701 addr = "2001:15:%d::2" % intf.sw_if_index
2702 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2703 intf_pfxs[i].append(a)
2704
2705 # a dump should n_address in it
2706 for intf in self.pg_interfaces:
2707 self.assertEqual(self.get_n_pfxs(intf), 3)
2708
2709 #
2710 # remove all the address thru a replace
2711 #
2712 self.vapi.sw_interface_address_replace_begin()
2713 self.vapi.sw_interface_address_replace_end()
2714 for intf in self.pg_interfaces:
2715 self.assertEqual(self.get_n_pfxs(intf), 0)
2716
2717 #
2718 # add all the interface addresses back
2719 #
2720 for p in intf_pfxs:
2721 for v in p:
2722 v.add_vpp_config()
2723 for intf in self.pg_interfaces:
2724 self.assertEqual(self.get_n_pfxs(intf), 3)
2725
2726 #
2727 # replace again, but this time update/re-add the address on the first
2728 # two interfaces
2729 #
2730 self.vapi.sw_interface_address_replace_begin()
2731
2732 for p in intf_pfxs[:2]:
2733 for v in p:
2734 v.add_vpp_config()
2735
2736 self.vapi.sw_interface_address_replace_end()
2737
2738 # on the first two the address still exist,
2739 # on the other two they do not
2740 for intf in self.pg_interfaces[:2]:
2741 self.assertEqual(self.get_n_pfxs(intf), 3)
2742 for p in intf_pfxs[:2]:
2743 for v in p:
2744 self.assertTrue(v.query_vpp_config())
2745 for intf in self.pg_interfaces[2:]:
2746 self.assertEqual(self.get_n_pfxs(intf), 0)
2747
2748 #
2749 # add all the interface addresses back on the last two
2750 #
2751 for p in intf_pfxs[2:]:
2752 for v in p:
2753 v.add_vpp_config()
2754 for intf in self.pg_interfaces:
2755 self.assertEqual(self.get_n_pfxs(intf), 3)
2756
2757 #
2758 # replace again, this time add different prefixes on all the interfaces
2759 #
2760 self.vapi.sw_interface_address_replace_begin()
2761
2762 pfxs = []
2763 for intf in self.pg_interfaces:
2764 # 2001:18:x::1/64
2765 addr = "2001:18:%d::1" % intf.sw_if_index
2766 pfxs.append(VppIpInterfaceAddress(self, intf, addr,
2767 64).add_vpp_config())
2768
2769 self.vapi.sw_interface_address_replace_end()
2770
2771 # only .18 should exist on each interface
2772 for intf in self.pg_interfaces:
2773 self.assertEqual(self.get_n_pfxs(intf), 1)
2774 for pfx in pfxs:
2775 self.assertTrue(pfx.query_vpp_config())
2776
2777 #
2778 # remove everything
2779 #
2780 self.vapi.sw_interface_address_replace_begin()
2781 self.vapi.sw_interface_address_replace_end()
2782 for intf in self.pg_interfaces:
2783 self.assertEqual(self.get_n_pfxs(intf), 0)
2784
2785 #
2786 # add prefixes to each interface. post-begin add the prefix from
2787 # interface X onto interface Y. this would normally be an error
2788 # since it would generate a 'duplicate address' warning. but in
2789 # this case, since what is newly downloaded is sane, it's ok
2790 #
2791 for intf in self.pg_interfaces:
2792 # 2001:18:x::1/64
2793 addr = "2001:18:%d::1" % intf.sw_if_index
2794 VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2795
2796 self.vapi.sw_interface_address_replace_begin()
2797
2798 pfxs = []
2799 for intf in self.pg_interfaces:
2800 # 2001:18:x::1/64
2801 addr = "2001:18:%d::1" % (intf.sw_if_index + 1)
2802 pfxs.append(VppIpInterfaceAddress(self, intf,
2803 addr, 64).add_vpp_config())
2804
2805 self.vapi.sw_interface_address_replace_end()
2806
2807 self.logger.info(self.vapi.cli("sh int addr"))
2808
2809 for intf in self.pg_interfaces:
2810 self.assertEqual(self.get_n_pfxs(intf), 1)
2811 for pfx in pfxs:
2812 self.assertTrue(pfx.query_vpp_config())
2813
2814
Neale Rannsec40a7d2020-04-23 07:36:12 +00002815class TestIP6LinkLocal(VppTestCase):
2816 """ IPv6 Link Local """
2817
2818 @classmethod
2819 def setUpClass(cls):
2820 super(TestIP6LinkLocal, cls).setUpClass()
2821
2822 @classmethod
2823 def tearDownClass(cls):
2824 super(TestIP6LinkLocal, cls).tearDownClass()
2825
2826 def setUp(self):
2827 super(TestIP6LinkLocal, self).setUp()
2828
2829 self.create_pg_interfaces(range(2))
2830
2831 for i in self.pg_interfaces:
2832 i.admin_up()
2833
2834 def tearDown(self):
2835 super(TestIP6LinkLocal, self).tearDown()
2836 for i in self.pg_interfaces:
2837 i.admin_down()
2838
2839 def test_ip6_ll(self):
2840 """ IPv6 Link Local """
2841
2842 #
2843 # two APIs to add a link local address.
2844 # 1 - just like any other prefix
2845 # 2 - with the special set LL API
2846 #
2847
2848 #
2849 # First with the API to set a 'normal' prefix
2850 #
2851 ll1 = "fe80:1::1"
2852 ll2 = "fe80:2::2"
2853 ll3 = "fe80:3::3"
2854
2855 VppIpInterfaceAddress(self, self.pg0, ll1, 128).add_vpp_config()
2856
2857 #
2858 # should be able to ping the ll
2859 #
2860 p_echo_request_1 = (Ether(src=self.pg0.remote_mac,
2861 dst=self.pg0.local_mac) /
2862 IPv6(src=ll2,
2863 dst=ll1) /
2864 ICMPv6EchoRequest())
2865
2866 self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0)
2867
2868 #
2869 # change the link-local on pg0
2870 #
2871 v_ll3 = VppIpInterfaceAddress(self, self.pg0,
2872 ll3, 128).add_vpp_config()
2873
2874 p_echo_request_3 = (Ether(src=self.pg0.remote_mac,
2875 dst=self.pg0.local_mac) /
2876 IPv6(src=ll2,
2877 dst=ll3) /
2878 ICMPv6EchoRequest())
2879
2880 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
2881
2882 #
2883 # set a normal v6 prefix on the link
2884 #
2885 self.pg0.config_ip6()
2886
2887 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
2888
2889 # the link-local cannot be removed
2890 with self.vapi.assert_negative_api_retval():
2891 v_ll3.remove_vpp_config()
2892
2893 #
2894 # Use the specific link-local API on pg1
2895 #
2896 VppIp6LinkLocalAddress(self, self.pg1, ll1).add_vpp_config()
2897 self.send_and_expect(self.pg1, [p_echo_request_1], self.pg1)
2898
2899 VppIp6LinkLocalAddress(self, self.pg1, ll3).add_vpp_config()
2900 self.send_and_expect(self.pg1, [p_echo_request_3], self.pg1)
2901
2902
Damjan Marionf56b77a2016-10-03 19:44:57 +02002903if __name__ == '__main__':
Klement Sekeraf62ae122016-10-11 11:47:09 +02002904 unittest.main(testRunner=VppTestRunner)