blob: c92ebb5852a900e1e16ef25ea9fe3fd4886d0bdc [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Damjan Marionf56b77a2016-10-03 19:44:57 +02002
Paul Vinciguerra582eac52020-04-03 12:18:40 -04003import socket
snaramre5d4b8912019-12-13 23:39:35 +00004from socket import inet_pton, inet_ntop
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -08005import unittest
6
Neale Rannsae809832018-11-23 09:00:27 -08007from parameterized import parameterized
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07008import scapy.compat
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -08009import scapy.layers.inet6 as inet6
10from scapy.contrib.mpls import MPLS
11from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \
12 ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
13 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
Neale Rannsf267d112020-02-07 09:45:07 +000014 ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply, \
15 IPv6ExtHdrHopByHop, ICMPv6MLReport2, ICMPv6MLDMultAddrRec
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080016from scapy.layers.l2 import Ether, Dot1Q
17from scapy.packet import Raw
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080018from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
19 in6_mactoifaceid
20from six import moves
Klement Sekeraf62ae122016-10-11 11:47:09 +020021
Damjan Marionf56b77a2016-10-03 19:44:57 +020022from framework import VppTestCase, VppTestRunner
Paul Vinciguerrae8fece82019-02-28 15:34:00 -080023from util import ppp, ip6_normalize, mk_ll_addr
Neale Rannsefd7bc22019-11-11 08:32:34 +000024from vpp_ip import DpoProto
Neale Ranns180279b2017-03-16 15:49:09 -040025from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
Neale Ranns71275e32017-05-25 12:38:58 -070026 VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
Neale Ranns9db6ada2019-11-08 12:42:31 +000027 VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
Neale Rannsec40a7d2020-04-23 07:36:12 +000028 VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump, \
29 VppIp6LinkLocalAddress
Neale Rannsb3b2de72017-03-08 05:17:22 -080030from vpp_neighbor import find_nbr, VppNeighbor
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080031from vpp_pg_interface import is_ipv6_misc
32from vpp_sub_interface import VppSubInterface, VppDot1QSubint
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010033from vpp_policer import VppPolicer
Neale Rannsefd7bc22019-11-11 08:32:34 +000034from ipaddress import IPv6Network, IPv6Address
Neale Ranns75152282017-01-09 01:00:45 -080035
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010036AF_INET6 = socket.AF_INET6
37
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -080038try:
39 text_type = unicode
40except NameError:
41 text_type = str
42
Paul Vinciguerra4271c972019-05-14 13:25:49 -040043NUM_PKTS = 67
44
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010045
Neale Ranns3f844d02017-02-18 00:03:54 -080046class TestIPv6ND(VppTestCase):
47 def validate_ra(self, intf, rx, dst_ip=None):
48 if not dst_ip:
49 dst_ip = intf.remote_ip6
50
51 # unicasted packets must come to the unicast mac
52 self.assertEqual(rx[Ether].dst, intf.remote_mac)
53
54 # and from the router's MAC
55 self.assertEqual(rx[Ether].src, intf.local_mac)
56
57 # the rx'd RA should be addressed to the sender's source
58 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
59 self.assertEqual(in6_ptop(rx[IPv6].dst),
60 in6_ptop(dst_ip))
61
62 # and come from the router's link local
63 self.assertTrue(in6_islladdr(rx[IPv6].src))
64 self.assertEqual(in6_ptop(rx[IPv6].src),
65 in6_ptop(mk_ll_addr(intf.local_mac)))
66
67 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
68 if not dst_ip:
69 dst_ip = intf.remote_ip6
70 if not tgt_ip:
71 dst_ip = intf.local_ip6
72
73 # unicasted packets must come to the unicast mac
74 self.assertEqual(rx[Ether].dst, intf.remote_mac)
75
76 # and from the router's MAC
77 self.assertEqual(rx[Ether].src, intf.local_mac)
78
79 # the rx'd NA should be addressed to the sender's source
80 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
81 self.assertEqual(in6_ptop(rx[IPv6].dst),
82 in6_ptop(dst_ip))
83
84 # and come from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -080085 self.assertEqual(
86 in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
Neale Ranns3f844d02017-02-18 00:03:54 -080087
88 # Dest link-layer options should have the router's MAC
89 dll = rx[ICMPv6NDOptDstLLAddr]
90 self.assertEqual(dll.lladdr, intf.local_mac)
91
Neale Rannsdcd6d622017-05-26 02:59:16 -070092 def validate_ns(self, intf, rx, tgt_ip):
93 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
94 dst_ip = inet_ntop(AF_INET6, nsma)
95
96 # NS is broadcast
Neale Rannsc7b8f202018-04-25 06:34:31 -070097 self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
Neale Rannsdcd6d622017-05-26 02:59:16 -070098
99 # and from the router's MAC
100 self.assertEqual(rx[Ether].src, intf.local_mac)
101
102 # the rx'd NS should be addressed to an mcast address
103 # derived from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800104 self.assertEqual(
105 in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
Neale Rannsdcd6d622017-05-26 02:59:16 -0700106
107 # expect the tgt IP in the NS header
108 ns = rx[ICMPv6ND_NS]
109 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
110
111 # packet is from the router's local address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800112 self.assertEqual(
113 in6_ptop(rx[IPv6].src), intf.local_ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700114
115 # Src link-layer options should have the router's MAC
116 sll = rx[ICMPv6NDOptSrcLLAddr]
117 self.assertEqual(sll.lladdr, intf.local_mac)
118
Neale Ranns3f844d02017-02-18 00:03:54 -0800119 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
120 filter_out_fn=is_ipv6_misc):
121 intf.add_stream(pkts)
Neale Ranns3f844d02017-02-18 00:03:54 -0800122 self.pg_enable_capture(self.pg_interfaces)
123 self.pg_start()
124 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
125
126 self.assertEqual(len(rx), 1)
127 rx = rx[0]
128 self.validate_ra(intf, rx, dst_ip)
129
Neale Ranns2a3ea492017-04-19 05:24:40 -0700130 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
131 tgt_ip=None,
132 filter_out_fn=is_ipv6_misc):
133 intf.add_stream(pkts)
134 self.pg_enable_capture(self.pg_interfaces)
135 self.pg_start()
136 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
137
138 self.assertEqual(len(rx), 1)
139 rx = rx[0]
140 self.validate_na(intf, rx, dst_ip, tgt_ip)
141
Neale Rannsdcd6d622017-05-26 02:59:16 -0700142 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
143 filter_out_fn=is_ipv6_misc):
Neale Rannscbe25aa2019-09-30 10:53:31 +0000144 self.vapi.cli("clear trace")
Neale Rannsdcd6d622017-05-26 02:59:16 -0700145 tx_intf.add_stream(pkts)
146 self.pg_enable_capture(self.pg_interfaces)
147 self.pg_start()
148 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
149
150 self.assertEqual(len(rx), 1)
151 rx = rx[0]
152 self.validate_ns(rx_intf, rx, tgt_ip)
153
Neale Rannsdcd6d622017-05-26 02:59:16 -0700154 def verify_ip(self, rx, smac, dmac, sip, dip):
155 ether = rx[Ether]
156 self.assertEqual(ether.dst, dmac)
157 self.assertEqual(ether.src, smac)
158
159 ip = rx[IPv6]
160 self.assertEqual(ip.src, sip)
161 self.assertEqual(ip.dst, dip)
162
Neale Ranns3f844d02017-02-18 00:03:54 -0800163
164class TestIPv6(TestIPv6ND):
Damjan Marionf56b77a2016-10-03 19:44:57 +0200165 """ IPv6 Test Case """
166
167 @classmethod
168 def setUpClass(cls):
169 super(TestIPv6, cls).setUpClass()
170
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700171 @classmethod
172 def tearDownClass(cls):
173 super(TestIPv6, cls).tearDownClass()
174
Klement Sekeraf62ae122016-10-11 11:47:09 +0200175 def setUp(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100176 """
177 Perform test setup before test case.
178
179 **Config:**
180 - create 3 pg interfaces
181 - untagged pg0 interface
182 - Dot1Q subinterface on pg1
183 - Dot1AD subinterface on pg2
184 - setup interfaces:
185 - put it into UP state
186 - set IPv6 addresses
187 - resolve neighbor address using NDP
188 - configure 200 fib entries
189
190 :ivar list interfaces: pg interfaces and subinterfaces.
191 :ivar dict flows: IPv4 packet flows in test.
Matej Klotton86d87c42016-11-11 11:38:55 +0100192
193 *TODO:* Create AD sub interface
194 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195 super(TestIPv6, self).setUp()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200196
Klement Sekeraf62ae122016-10-11 11:47:09 +0200197 # create 3 pg interfaces
198 self.create_pg_interfaces(range(3))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200199
Klement Sekeraf62ae122016-10-11 11:47:09 +0200200 # create 2 subinterfaces for p1 and pg2
201 self.sub_interfaces = [
202 VppDot1QSubint(self, self.pg1, 100),
Matej Klotton86d87c42016-11-11 11:38:55 +0100203 VppDot1QSubint(self, self.pg2, 200)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200204 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
Matej Klotton86d87c42016-11-11 11:38:55 +0100205 ]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
208 self.flows = dict()
209 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
210 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
211 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200212
Klement Sekeraf62ae122016-10-11 11:47:09 +0200213 # packet sizes
Jan Geletye6c78ee2018-06-26 12:24:03 +0200214 self.pg_if_packet_sizes = [64, 1500, 9020]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200215
Klement Sekeraf62ae122016-10-11 11:47:09 +0200216 self.interfaces = list(self.pg_interfaces)
217 self.interfaces.extend(self.sub_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200218
Klement Sekeraf62ae122016-10-11 11:47:09 +0200219 # setup all interfaces
220 for i in self.interfaces:
221 i.admin_up()
222 i.config_ip6()
223 i.resolve_ndp()
224
Damjan Marionf56b77a2016-10-03 19:44:57 +0200225 def tearDown(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100226 """Run standard test teardown and log ``show ip6 neighbors``."""
Neale Ranns744902e2017-08-14 10:35:44 -0700227 for i in self.interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800228 i.unconfig_ip6()
Neale Ranns75152282017-01-09 01:00:45 -0800229 i.admin_down()
Neale Ranns744902e2017-08-14 10:35:44 -0700230 for i in self.sub_interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800231 i.remove_vpp_config()
232
Klement Sekeraf62ae122016-10-11 11:47:09 +0200233 super(TestIPv6, self).tearDown()
234 if not self.vpp_dead:
Matej Klotton86d87c42016-11-11 11:38:55 +0100235 self.logger.info(self.vapi.cli("show ip6 neighbors"))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200236 # info(self.vapi.cli("show ip6 fib")) # many entries
Damjan Marionf56b77a2016-10-03 19:44:57 +0200237
Jan Geletye6c78ee2018-06-26 12:24:03 +0200238 def modify_packet(self, src_if, packet_size, pkt):
239 """Add load, set destination IP and extend packet to required packet
240 size for defined interface.
241
242 :param VppInterface src_if: Interface to create packet for.
243 :param int packet_size: Required packet size.
244 :param Scapy pkt: Packet to be modified.
245 """
snaramre07a0f212019-10-11 21:28:56 +0000246 dst_if_idx = int(packet_size / 10 % 2)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200247 dst_if = self.flows[src_if][dst_if_idx]
248 info = self.create_packet_info(src_if, dst_if)
249 payload = self.info_to_payload(info)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800250 p = pkt / Raw(payload)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200251 p[IPv6].dst = dst_if.remote_ip6
252 info.data = p.copy()
253 if isinstance(src_if, VppSubInterface):
254 p = src_if.add_dot1_layer(p)
255 self.extend_packet(p, packet_size)
256
257 return p
258
259 def create_stream(self, src_if):
Matej Klotton86d87c42016-11-11 11:38:55 +0100260 """Create input packet stream for defined interface.
261
262 :param VppInterface src_if: Interface to create packet stream for.
Matej Klotton86d87c42016-11-11 11:38:55 +0100263 """
Jan Geletye6c78ee2018-06-26 12:24:03 +0200264 hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
265 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
266 IPv6(src=src_if.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800267 inet6.UDP(sport=1234, dport=1234))
Jan Geletye6c78ee2018-06-26 12:24:03 +0200268
269 pkts = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800270 for i in moves.range(self.pg_if_packet_sizes[0],
271 self.pg_if_packet_sizes[1], 10)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200272 pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800273 for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
274 self.pg_if_packet_sizes[2] + hdr_ext,
275 50)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200276 pkts.extend(pkts_b)
277
Damjan Marionf56b77a2016-10-03 19:44:57 +0200278 return pkts
279
Klement Sekeraf62ae122016-10-11 11:47:09 +0200280 def verify_capture(self, dst_if, capture):
Matej Klotton86d87c42016-11-11 11:38:55 +0100281 """Verify captured input packet stream for defined interface.
282
283 :param VppInterface dst_if: Interface to verify captured packet stream
284 for.
285 :param list capture: Captured packet stream.
286 """
287 self.logger.info("Verifying capture on interface %s" % dst_if.name)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200288 last_info = dict()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200289 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200290 last_info[i.sw_if_index] = None
291 is_sub_if = False
292 dst_sw_if_index = dst_if.sw_if_index
293 if hasattr(dst_if, 'parent'):
294 is_sub_if = True
Damjan Marionf56b77a2016-10-03 19:44:57 +0200295 for packet in capture:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200296 if is_sub_if:
297 # Check VLAN tags and Ethernet header
298 packet = dst_if.remove_dot1_layer(packet)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200299 self.assertTrue(Dot1Q not in packet)
300 try:
301 ip = packet[IPv6]
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800302 udp = packet[inet6.UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800303 payload_info = self.payload_to_info(packet[Raw])
Damjan Marionf56b77a2016-10-03 19:44:57 +0200304 packet_index = payload_info.index
Klement Sekeraf62ae122016-10-11 11:47:09 +0200305 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerada505f62017-01-04 12:58:53 +0100306 self.logger.debug(
307 "Got packet on port %s: src=%u (id=%u)" %
308 (dst_if.name, payload_info.src, packet_index))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200309 next_info = self.get_next_packet_info_for_interface2(
310 payload_info.src, dst_sw_if_index,
311 last_info[payload_info.src])
312 last_info[payload_info.src] = next_info
Damjan Marionf56b77a2016-10-03 19:44:57 +0200313 self.assertTrue(next_info is not None)
314 self.assertEqual(packet_index, next_info.index)
315 saved_packet = next_info.data
316 # Check standard fields
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800317 self.assertEqual(
318 ip.src, saved_packet[IPv6].src)
319 self.assertEqual(
320 ip.dst, saved_packet[IPv6].dst)
321 self.assertEqual(
322 udp.sport, saved_packet[inet6.UDP].sport)
323 self.assertEqual(
324 udp.dport, saved_packet[inet6.UDP].dport)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200325 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100326 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200327 raise
328 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200329 remaining_packet = self.get_next_packet_info_for_interface2(
330 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
Klement Sekera7bb873a2016-11-18 07:38:42 +0100331 self.assertTrue(remaining_packet is None,
332 "Interface %s: Packet expected from interface %s "
333 "didn't arrive" % (dst_if.name, i.name))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200334
Klement Sekerae8498652019-06-17 12:23:15 +0000335 def test_next_header_anomaly(self):
336 """ IPv6 next header anomaly test
337
338 Test scenario:
339 - ipv6 next header field = Fragment Header (44)
340 - next header is ICMPv6 Echo Request
341 - wait for reassembly
342 """
343 pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) /
344 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) /
345 ICMPv6EchoRequest())
346
347 self.pg0.add_stream(pkt)
348 self.pg_start()
349
350 # wait for reassembly
351 self.sleep(10)
352
Damjan Marionf56b77a2016-10-03 19:44:57 +0200353 def test_fib(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100354 """ IPv6 FIB test
355
356 Test scenario:
357 - Create IPv6 stream for pg0 interface
358 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
359 - Send and verify received packets on each interface.
360 """
Damjan Marionf56b77a2016-10-03 19:44:57 +0200361
Jan Geletye6c78ee2018-06-26 12:24:03 +0200362 pkts = self.create_stream(self.pg0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200363 self.pg0.add_stream(pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200364
Klement Sekeraf62ae122016-10-11 11:47:09 +0200365 for i in self.sub_interfaces:
Jan Geletye6c78ee2018-06-26 12:24:03 +0200366 pkts = self.create_stream(i)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200367 i.parent.add_stream(pkts)
368
369 self.pg_enable_capture(self.pg_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200370 self.pg_start()
371
Klement Sekeraf62ae122016-10-11 11:47:09 +0200372 pkts = self.pg0.get_capture()
373 self.verify_capture(self.pg0, pkts)
374
375 for i in self.sub_interfaces:
376 pkts = i.parent.get_capture()
377 self.verify_capture(i, pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200378
Neale Ranns75152282017-01-09 01:00:45 -0800379 def test_ns(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100380 """ IPv6 Neighbour Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800381
Klement Sekerada505f62017-01-04 12:58:53 +0100382 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800383 - Send an NS Sourced from an address not covered by the link sub-net
384 - Send an NS to an mcast address the router has not joined
385 - Send NS for a target address the router does not onn.
386 """
387
388 #
389 # An NS from a non link source address
390 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800391 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
392 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800393
394 p = (Ether(dst=in6_getnsmac(nsma)) /
395 IPv6(dst=d, src="2002::2") /
396 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800397 ICMPv6NDOptSrcLLAddr(
398 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800399 pkts = [p]
400
Klement Sekerada505f62017-01-04 12:58:53 +0100401 self.send_and_assert_no_replies(
402 self.pg0, pkts,
403 "No response to NS source by address not on sub-net")
Neale Ranns75152282017-01-09 01:00:45 -0800404
405 #
Klement Sekerada505f62017-01-04 12:58:53 +0100406 # An NS for sent to a solicited mcast group the router is
407 # not a member of FAILS
Neale Ranns75152282017-01-09 01:00:45 -0800408 #
409 if 0:
Neale Ranns3f844d02017-02-18 00:03:54 -0800410 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
411 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800412
413 p = (Ether(dst=in6_getnsmac(nsma)) /
414 IPv6(dst=d, src=self.pg0.remote_ip6) /
415 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800416 ICMPv6NDOptSrcLLAddr(
417 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800418 pkts = [p]
419
Klement Sekerada505f62017-01-04 12:58:53 +0100420 self.send_and_assert_no_replies(
421 self.pg0, pkts,
422 "No response to NS sent to unjoined mcast address")
Neale Ranns75152282017-01-09 01:00:45 -0800423
424 #
425 # An NS whose target address is one the router does not own
426 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800427 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
428 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800429
430 p = (Ether(dst=in6_getnsmac(nsma)) /
431 IPv6(dst=d, src=self.pg0.remote_ip6) /
432 ICMPv6ND_NS(tgt="fd::ffff") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800433 ICMPv6NDOptSrcLLAddr(
434 lladdr=self.pg0.remote_mac))
Neale Ranns75152282017-01-09 01:00:45 -0800435 pkts = [p]
436
437 self.send_and_assert_no_replies(self.pg0, pkts,
438 "No response to NS for unknown target")
439
Neale Rannsb3b2de72017-03-08 05:17:22 -0800440 #
441 # A neighbor entry that has no associated FIB-entry
442 #
443 self.pg0.generate_remote_hosts(4)
444 nd_entry = VppNeighbor(self,
445 self.pg0.sw_if_index,
446 self.pg0.remote_hosts[2].mac,
447 self.pg0.remote_hosts[2].ip6,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800448 is_no_fib_entry=1)
449 nd_entry.add_vpp_config()
450
451 #
452 # check we have the neighbor, but no route
453 #
454 self.assertTrue(find_nbr(self,
455 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700456 self.pg0._remote_hosts[2].ip6))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800457 self.assertFalse(find_route(self,
458 self.pg0._remote_hosts[2].ip6,
Neale Ranns097fa662018-05-01 05:17:55 -0700459 128))
Neale Rannsb3b2de72017-03-08 05:17:22 -0800460
Neale Ranns2a3ea492017-04-19 05:24:40 -0700461 #
462 # send an NS from a link local address to the interface's global
463 # address
464 #
465 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800466 IPv6(
467 dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700468 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800469 ICMPv6NDOptSrcLLAddr(
470 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700471
472 self.send_and_expect_na(self.pg0, p,
473 "NS from link-local",
474 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
475 tgt_ip=self.pg0.local_ip6)
476
477 #
478 # we should have learned an ND entry for the peer's link-local
479 # but not inserted a route to it in the FIB
480 #
481 self.assertTrue(find_nbr(self,
482 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700483 self.pg0._remote_hosts[2].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700484 self.assertFalse(find_route(self,
485 self.pg0._remote_hosts[2].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700486 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700487
488 #
489 # An NS to the router's own Link-local
490 #
491 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800492 IPv6(
493 dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700494 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800495 ICMPv6NDOptSrcLLAddr(
496 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700497
498 self.send_and_expect_na(self.pg0, p,
499 "NS to/from link-local",
500 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
501 tgt_ip=self.pg0.local_ip6_ll)
502
503 #
504 # we should have learned an ND entry for the peer's link-local
505 # but not inserted a route to it in the FIB
506 #
507 self.assertTrue(find_nbr(self,
508 self.pg0.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700509 self.pg0._remote_hosts[3].ip6_ll))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700510 self.assertFalse(find_route(self,
511 self.pg0._remote_hosts[3].ip6_ll,
Neale Ranns097fa662018-05-01 05:17:55 -0700512 128))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700513
Neale Rannsdcd6d622017-05-26 02:59:16 -0700514 def test_ns_duplicates(self):
Neale Rannsda78f952017-05-24 09:15:43 -0700515 """ ND Duplicates"""
Neale Rannsdcd6d622017-05-26 02:59:16 -0700516
517 #
518 # Generate some hosts on the LAN
519 #
520 self.pg1.generate_remote_hosts(3)
521
522 #
523 # Add host 1 on pg1 and pg2
524 #
525 ns_pg1 = VppNeighbor(self,
526 self.pg1.sw_if_index,
527 self.pg1.remote_hosts[1].mac,
Neale Ranns37029302018-08-10 05:30:06 -0700528 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700529 ns_pg1.add_vpp_config()
530 ns_pg2 = VppNeighbor(self,
531 self.pg2.sw_if_index,
532 self.pg2.remote_mac,
Neale Ranns37029302018-08-10 05:30:06 -0700533 self.pg1.remote_hosts[1].ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700534 ns_pg2.add_vpp_config()
535
536 #
537 # IP packet destined for pg1 remote host arrives on pg1 again.
538 #
539 p = (Ether(dst=self.pg0.local_mac,
540 src=self.pg0.remote_mac) /
541 IPv6(src=self.pg0.remote_ip6,
542 dst=self.pg1.remote_hosts[1].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800543 inet6.UDP(sport=1234, dport=1234) /
Neale Rannsdcd6d622017-05-26 02:59:16 -0700544 Raw())
545
546 self.pg0.add_stream(p)
547 self.pg_enable_capture(self.pg_interfaces)
548 self.pg_start()
549
550 rx1 = self.pg1.get_capture(1)
551
552 self.verify_ip(rx1[0],
553 self.pg1.local_mac,
554 self.pg1.remote_hosts[1].mac,
555 self.pg0.remote_ip6,
556 self.pg1.remote_hosts[1].ip6)
557
558 #
559 # remove the duplicate on pg1
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700560 # packet stream should generate NSs out of pg1
Neale Rannsdcd6d622017-05-26 02:59:16 -0700561 #
562 ns_pg1.remove_vpp_config()
563
564 self.send_and_expect_ns(self.pg0, self.pg1,
565 p, self.pg1.remote_hosts[1].ip6)
566
567 #
568 # Add it back
569 #
570 ns_pg1.add_vpp_config()
571
572 self.pg0.add_stream(p)
573 self.pg_enable_capture(self.pg_interfaces)
574 self.pg_start()
575
576 rx1 = self.pg1.get_capture(1)
577
578 self.verify_ip(rx1[0],
579 self.pg1.local_mac,
580 self.pg1.remote_hosts[1].mac,
581 self.pg0.remote_ip6,
582 self.pg1.remote_hosts[1].ip6)
583
Neale Rannscbe25aa2019-09-30 10:53:31 +0000584 def validate_ra(self, intf, rx, dst_ip=None, src_ip=None,
585 mtu=9000, pi_opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000586 if not dst_ip:
587 dst_ip = intf.remote_ip6
Neale Rannscbe25aa2019-09-30 10:53:31 +0000588 if not src_ip:
589 src_ip = mk_ll_addr(intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800590
Neale Ranns5737d882017-02-03 06:14:49 -0800591 # unicasted packets must come to the unicast mac
Neale Ranns32e1c012016-11-22 17:07:28 +0000592 self.assertEqual(rx[Ether].dst, intf.remote_mac)
593
594 # and from the router's MAC
595 self.assertEqual(rx[Ether].src, intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800596
597 # the rx'd RA should be addressed to the sender's source
598 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
599 self.assertEqual(in6_ptop(rx[IPv6].dst),
Neale Ranns32e1c012016-11-22 17:07:28 +0000600 in6_ptop(dst_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800601
602 # and come from the router's link local
603 self.assertTrue(in6_islladdr(rx[IPv6].src))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000604 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800605
Neale Ranns87df12d2017-02-18 08:16:41 -0800606 # it should contain the links MTU
607 ra = rx[ICMPv6ND_RA]
608 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
609
610 # it should contain the source's link layer address option
611 sll = ra[ICMPv6NDOptSrcLLAddr]
612 self.assertEqual(sll.lladdr, intf.local_mac)
613
614 if not pi_opt:
615 # the RA should not contain prefix information
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800616 self.assertFalse(ra.haslayer(
617 ICMPv6NDOptPrefixInfo))
Neale Ranns87df12d2017-02-18 08:16:41 -0800618 else:
619 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
620
621 # the options are nested in the scapy packet in way that i cannot
622 # decipher how to decode. this 1st layer of option always returns
623 # nested classes, so a direct obj1=obj2 comparison always fails.
Paul Vinciguerraab055082019-06-06 14:07:55 -0400624 # however, the getlayer(.., 2) does give one instance.
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700625 # so we cheat here and construct a new opt instance for comparison
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800626 rd = ICMPv6NDOptPrefixInfo(
627 prefixlen=raos.prefixlen,
628 prefix=raos.prefix,
629 L=raos.L,
630 A=raos.A)
Neale Ranns87df12d2017-02-18 08:16:41 -0800631 if type(pi_opt) is list:
632 for ii in range(len(pi_opt)):
633 self.assertEqual(pi_opt[ii], rd)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800634 rd = rx.getlayer(
635 ICMPv6NDOptPrefixInfo, ii + 2)
Neale Ranns87df12d2017-02-18 08:16:41 -0800636 else:
Paul Vinciguerraab055082019-06-06 14:07:55 -0400637 self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s'
638 % (pi_opt.show(dump=True),
639 raos.show(dump=True)))
Neale Ranns87df12d2017-02-18 08:16:41 -0800640
Neale Ranns32e1c012016-11-22 17:07:28 +0000641 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
Neale Ranns87df12d2017-02-18 08:16:41 -0800642 filter_out_fn=is_ipv6_misc,
Neale Rannscbe25aa2019-09-30 10:53:31 +0000643 opt=None,
644 src_ip=None):
645 self.vapi.cli("clear trace")
Neale Ranns32e1c012016-11-22 17:07:28 +0000646 intf.add_stream(pkts)
Neale Ranns32e1c012016-11-22 17:07:28 +0000647 self.pg_enable_capture(self.pg_interfaces)
648 self.pg_start()
649 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
650
651 self.assertEqual(len(rx), 1)
652 rx = rx[0]
Neale Rannscbe25aa2019-09-30 10:53:31 +0000653 self.validate_ra(intf, rx, dst_ip, src_ip=src_ip, pi_opt=opt)
Neale Ranns32e1c012016-11-22 17:07:28 +0000654
Neale Ranns75152282017-01-09 01:00:45 -0800655 def test_rs(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100656 """ IPv6 Router Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800657
Klement Sekerada505f62017-01-04 12:58:53 +0100658 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800659 """
660
661 #
Klement Sekerada505f62017-01-04 12:58:53 +0100662 # Before we begin change the IPv6 RA responses to use the unicast
663 # address - that way we will not confuse them with the periodic
664 # RAs which go to the mcast address
Neale Ranns32e1c012016-11-22 17:07:28 +0000665 # Sit and wait for the first periodic RA.
666 #
667 # TODO
Neale Ranns75152282017-01-09 01:00:45 -0800668 #
669 self.pg0.ip6_ra_config(send_unicast=1)
670
671 #
672 # An RS from a link source address
673 # - expect an RA in return
674 #
675 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Neale Rannscbe25aa2019-09-30 10:53:31 +0000676 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
Neale Ranns75152282017-01-09 01:00:45 -0800677 ICMPv6ND_RS())
678 pkts = [p]
679 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
680
681 #
682 # For the next RS sent the RA should be rate limited
683 #
684 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
685
686 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700687 # When we reconfigure the IPv6 RA config,
688 # we reset the RA rate limiting,
Klement Sekerada505f62017-01-04 12:58:53 +0100689 # so we need to do this before each test below so as not to drop
690 # packets for rate limiting reasons. Test this works here.
Neale Ranns75152282017-01-09 01:00:45 -0800691 #
692 self.pg0.ip6_ra_config(send_unicast=1)
693 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
694
695 #
696 # An RS sent from a non-link local source
697 #
698 self.pg0.ip6_ra_config(send_unicast=1)
699 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800700 IPv6(dst=self.pg0.local_ip6,
701 src="2002::ffff") /
Neale Ranns75152282017-01-09 01:00:45 -0800702 ICMPv6ND_RS())
703 pkts = [p]
704 self.send_and_assert_no_replies(self.pg0, pkts,
705 "RS from non-link source")
706
707 #
708 # Source an RS from a link local address
709 #
710 self.pg0.ip6_ra_config(send_unicast=1)
711 ll = mk_ll_addr(self.pg0.remote_mac)
712 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
713 IPv6(dst=self.pg0.local_ip6, src=ll) /
714 ICMPv6ND_RS())
715 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000716 self.send_and_expect_ra(self.pg0, pkts,
717 "RS sourced from link-local",
718 dst_ip=ll)
719
720 #
721 # Send the RS multicast
722 #
723 self.pg0.ip6_ra_config(send_unicast=1)
Neale Ranns3f844d02017-02-18 00:03:54 -0800724 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
Neale Ranns32e1c012016-11-22 17:07:28 +0000725 ll = mk_ll_addr(self.pg0.remote_mac)
726 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
727 IPv6(dst="ff02::2", src=ll) /
728 ICMPv6ND_RS())
729 pkts = [p]
730 self.send_and_expect_ra(self.pg0, pkts,
731 "RS sourced from link-local",
732 dst_ip=ll)
Neale Ranns75152282017-01-09 01:00:45 -0800733
734 #
Klement Sekerada505f62017-01-04 12:58:53 +0100735 # Source from the unspecified address ::. This happens when the RS
736 # is sent before the host has a configured address/sub-net,
737 # i.e. auto-config. Since the sender has no IP address, the reply
738 # comes back mcast - so the capture needs to not filter this.
739 # If we happen to pick up the periodic RA at this point then so be it,
740 # it's not an error.
Neale Ranns75152282017-01-09 01:00:45 -0800741 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000742 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
743 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
744 IPv6(dst="ff02::2", src="::") /
Neale Ranns75152282017-01-09 01:00:45 -0800745 ICMPv6ND_RS())
746 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000747 self.send_and_expect_ra(self.pg0, pkts,
748 "RS sourced from unspecified",
749 dst_ip="ff02::1",
750 filter_out_fn=None)
Neale Ranns75152282017-01-09 01:00:45 -0800751
752 #
Neale Ranns87df12d2017-02-18 08:16:41 -0800753 # Configure The RA to announce the links prefix
754 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400755 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
756 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800757
758 #
759 # RAs should now contain the prefix information option
760 #
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800761 opt = ICMPv6NDOptPrefixInfo(
762 prefixlen=self.pg0.local_ip6_prefix_len,
763 prefix=self.pg0.local_ip6,
764 L=1,
765 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800766
767 self.pg0.ip6_ra_config(send_unicast=1)
768 ll = mk_ll_addr(self.pg0.remote_mac)
769 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
770 IPv6(dst=self.pg0.local_ip6, src=ll) /
771 ICMPv6ND_RS())
772 self.send_and_expect_ra(self.pg0, p,
773 "RA with prefix-info",
774 dst_ip=ll,
775 opt=opt)
776
777 #
778 # Change the prefix info to not off-link
779 # L-flag is clear
780 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400781 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
782 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800783 off_link=1)
784
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800785 opt = ICMPv6NDOptPrefixInfo(
786 prefixlen=self.pg0.local_ip6_prefix_len,
787 prefix=self.pg0.local_ip6,
788 L=0,
789 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800790
791 self.pg0.ip6_ra_config(send_unicast=1)
792 self.send_and_expect_ra(self.pg0, p,
793 "RA with Prefix info with L-flag=0",
794 dst_ip=ll,
795 opt=opt)
796
797 #
798 # Change the prefix info to not off-link, no-autoconfig
799 # L and A flag are clear in the advert
800 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400801 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
802 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800803 off_link=1,
804 no_autoconfig=1)
805
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800806 opt = ICMPv6NDOptPrefixInfo(
807 prefixlen=self.pg0.local_ip6_prefix_len,
808 prefix=self.pg0.local_ip6,
809 L=0,
810 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800811
812 self.pg0.ip6_ra_config(send_unicast=1)
813 self.send_and_expect_ra(self.pg0, p,
814 "RA with Prefix info with A & L-flag=0",
815 dst_ip=ll,
816 opt=opt)
817
818 #
819 # Change the flag settings back to the defaults
820 # L and A flag are set in the advert
821 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400822 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
823 self.pg0.local_ip6_prefix_len))
Neale Ranns87df12d2017-02-18 08:16:41 -0800824
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800825 opt = ICMPv6NDOptPrefixInfo(
826 prefixlen=self.pg0.local_ip6_prefix_len,
827 prefix=self.pg0.local_ip6,
828 L=1,
829 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800830
831 self.pg0.ip6_ra_config(send_unicast=1)
832 self.send_and_expect_ra(self.pg0, p,
833 "RA with Prefix info",
834 dst_ip=ll,
835 opt=opt)
836
837 #
838 # Change the prefix info to not off-link, no-autoconfig
839 # L and A flag are clear in the advert
840 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400841 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
842 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800843 off_link=1,
844 no_autoconfig=1)
845
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800846 opt = ICMPv6NDOptPrefixInfo(
847 prefixlen=self.pg0.local_ip6_prefix_len,
848 prefix=self.pg0.local_ip6,
849 L=0,
850 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800851
852 self.pg0.ip6_ra_config(send_unicast=1)
853 self.send_and_expect_ra(self.pg0, p,
854 "RA with Prefix info with A & L-flag=0",
855 dst_ip=ll,
856 opt=opt)
857
858 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700859 # Use the reset to defaults option to revert to defaults
Neale Ranns87df12d2017-02-18 08:16:41 -0800860 # L and A flag are clear in the advert
861 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400862 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
863 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800864 use_default=1)
865
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800866 opt = ICMPv6NDOptPrefixInfo(
867 prefixlen=self.pg0.local_ip6_prefix_len,
868 prefix=self.pg0.local_ip6,
869 L=1,
870 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800871
872 self.pg0.ip6_ra_config(send_unicast=1)
873 self.send_and_expect_ra(self.pg0, p,
874 "RA with Prefix reverted to defaults",
875 dst_ip=ll,
876 opt=opt)
877
878 #
879 # Advertise Another prefix. With no L-flag/A-flag
880 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400881 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
882 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800883 off_link=1,
884 no_autoconfig=1)
885
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800886 opt = [ICMPv6NDOptPrefixInfo(
887 prefixlen=self.pg0.local_ip6_prefix_len,
888 prefix=self.pg0.local_ip6,
889 L=1,
890 A=1),
891 ICMPv6NDOptPrefixInfo(
892 prefixlen=self.pg1.local_ip6_prefix_len,
893 prefix=self.pg1.local_ip6,
894 L=0,
895 A=0)]
Neale Ranns87df12d2017-02-18 08:16:41 -0800896
897 self.pg0.ip6_ra_config(send_unicast=1)
898 ll = mk_ll_addr(self.pg0.remote_mac)
899 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
900 IPv6(dst=self.pg0.local_ip6, src=ll) /
901 ICMPv6ND_RS())
902 self.send_and_expect_ra(self.pg0, p,
903 "RA with multiple Prefix infos",
904 dst_ip=ll,
905 opt=opt)
906
907 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700908 # Remove the first prefix-info - expect the second is still in the
Neale Ranns87df12d2017-02-18 08:16:41 -0800909 # advert
910 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400911 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6,
912 self.pg0.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800913 is_no=1)
914
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800915 opt = ICMPv6NDOptPrefixInfo(
916 prefixlen=self.pg1.local_ip6_prefix_len,
917 prefix=self.pg1.local_ip6,
918 L=0,
919 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800920
921 self.pg0.ip6_ra_config(send_unicast=1)
922 self.send_and_expect_ra(self.pg0, p,
923 "RA with Prefix reverted to defaults",
924 dst_ip=ll,
925 opt=opt)
926
927 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700928 # Remove the second prefix-info - expect no prefix-info in the adverts
Neale Ranns87df12d2017-02-18 08:16:41 -0800929 #
Paul Vinciguerraab055082019-06-06 14:07:55 -0400930 self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6,
931 self.pg1.local_ip6_prefix_len),
Neale Ranns87df12d2017-02-18 08:16:41 -0800932 is_no=1)
933
Neale Rannscbe25aa2019-09-30 10:53:31 +0000934 #
935 # change the link's link local, so we know that works too.
936 #
937 self.vapi.sw_interface_ip6_set_link_local_address(
938 sw_if_index=self.pg0.sw_if_index,
939 ip="fe80::88")
940
Neale Ranns87df12d2017-02-18 08:16:41 -0800941 self.pg0.ip6_ra_config(send_unicast=1)
942 self.send_and_expect_ra(self.pg0, p,
943 "RA with Prefix reverted to defaults",
Neale Rannscbe25aa2019-09-30 10:53:31 +0000944 dst_ip=ll,
945 src_ip="fe80::88")
Neale Ranns87df12d2017-02-18 08:16:41 -0800946
947 #
Neale Ranns5737d882017-02-03 06:14:49 -0800948 # Reset the periodic advertisements back to default values
Neale Ranns75152282017-01-09 01:00:45 -0800949 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000950 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200951
Neale Rannsf267d112020-02-07 09:45:07 +0000952 def test_mld(self):
953 """ MLD Report """
954 #
955 # test one MLD is sent after applying an IPv6 Address on an interface
956 #
957 self.pg_enable_capture(self.pg_interfaces)
958 self.pg_start()
959
960 subitf = VppDot1QSubint(self, self.pg1, 99)
961
962 subitf.admin_up()
963 subitf.config_ip6()
964
Neale Ranns03c254e2020-03-17 14:25:10 +0000965 rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None)
Neale Rannsf267d112020-02-07 09:45:07 +0000966
967 #
968 # hunt for the MLD on vlan 99
969 #
970 for rx in rxs:
971 # make sure ipv6 packets with hop by hop options have
972 # correct checksums
973 self.assert_packet_checksums_valid(rx)
974 if rx.haslayer(IPv6ExtHdrHopByHop) and \
975 rx.haslayer(Dot1Q) and \
976 rx[Dot1Q].vlan == 99:
977 mld = rx[ICMPv6MLReport2]
978
979 self.assertEqual(mld.records_number, 4)
980
Neale Ranns3f844d02017-02-18 00:03:54 -0800981
Matthew Smith6c92f5b2019-08-07 11:46:30 -0500982class TestIPv6IfAddrRoute(VppTestCase):
983 """ IPv6 Interface Addr Route Test Case """
984
985 @classmethod
986 def setUpClass(cls):
987 super(TestIPv6IfAddrRoute, cls).setUpClass()
988
989 @classmethod
990 def tearDownClass(cls):
991 super(TestIPv6IfAddrRoute, cls).tearDownClass()
992
993 def setUp(self):
994 super(TestIPv6IfAddrRoute, self).setUp()
995
996 # create 1 pg interface
997 self.create_pg_interfaces(range(1))
998
999 for i in self.pg_interfaces:
1000 i.admin_up()
1001 i.config_ip6()
1002 i.resolve_ndp()
1003
1004 def tearDown(self):
1005 super(TestIPv6IfAddrRoute, self).tearDown()
1006 for i in self.pg_interfaces:
1007 i.unconfig_ip6()
1008 i.admin_down()
1009
1010 def test_ipv6_ifaddrs_same_prefix(self):
1011 """ IPv6 Interface Addresses Same Prefix test
1012
1013 Test scenario:
1014
1015 - Verify no route in FIB for prefix 2001:10::/64
1016 - Configure IPv4 address 2001:10::10/64 on an interface
1017 - Verify route in FIB for prefix 2001:10::/64
1018 - Configure IPv4 address 2001:10::20/64 on an interface
1019 - Delete 2001:10::10/64 from interface
1020 - Verify route in FIB for prefix 2001:10::/64
1021 - Delete 2001:10::20/64 from interface
1022 - Verify no route in FIB for prefix 2001:10::/64
1023 """
1024
1025 addr1 = "2001:10::10"
1026 addr2 = "2001:10::20"
1027
Neale Rannsefd7bc22019-11-11 08:32:34 +00001028 if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64)
1029 if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64)
1030 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001031 self.assertFalse(find_route(self, addr1, 128))
1032 self.assertFalse(find_route(self, addr2, 128))
1033
1034 # configure first address, verify route present
1035 if_addr1.add_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001036 self.assertTrue(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001037 self.assertTrue(find_route(self, addr1, 128))
1038 self.assertFalse(find_route(self, addr2, 128))
1039
1040 # configure second address, delete first, verify route not removed
1041 if_addr2.add_vpp_config()
1042 if_addr1.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001043 self.assertFalse(if_addr1.query_vpp_config())
1044 self.assertTrue(if_addr2.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001045 self.assertFalse(find_route(self, addr1, 128))
1046 self.assertTrue(find_route(self, addr2, 128))
1047
1048 # delete second address, verify route removed
1049 if_addr2.remove_vpp_config()
Neale Rannsefd7bc22019-11-11 08:32:34 +00001050 self.assertFalse(if_addr1.query_vpp_config())
Matthew Smith6c92f5b2019-08-07 11:46:30 -05001051 self.assertFalse(find_route(self, addr1, 128))
1052 self.assertFalse(find_route(self, addr2, 128))
1053
1054
Jan Geletye6c78ee2018-06-26 12:24:03 +02001055class TestICMPv6Echo(VppTestCase):
1056 """ ICMPv6 Echo Test Case """
1057
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001058 @classmethod
1059 def setUpClass(cls):
1060 super(TestICMPv6Echo, cls).setUpClass()
1061
1062 @classmethod
1063 def tearDownClass(cls):
1064 super(TestICMPv6Echo, cls).tearDownClass()
1065
Jan Geletye6c78ee2018-06-26 12:24:03 +02001066 def setUp(self):
1067 super(TestICMPv6Echo, self).setUp()
1068
1069 # create 1 pg interface
1070 self.create_pg_interfaces(range(1))
1071
1072 for i in self.pg_interfaces:
1073 i.admin_up()
1074 i.config_ip6()
1075 i.resolve_ndp()
1076
1077 def tearDown(self):
1078 super(TestICMPv6Echo, self).tearDown()
1079 for i in self.pg_interfaces:
1080 i.unconfig_ip6()
Jan Geletye6c78ee2018-06-26 12:24:03 +02001081 i.admin_down()
1082
1083 def test_icmpv6_echo(self):
1084 """ VPP replies to ICMPv6 Echo Request
1085
1086 Test scenario:
1087
1088 - Receive ICMPv6 Echo Request message on pg0 interface.
1089 - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
1090 """
1091
1092 icmpv6_id = 0xb
1093 icmpv6_seq = 5
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -08001094 icmpv6_data = b'\x0a' * 18
Jan Geletye6c78ee2018-06-26 12:24:03 +02001095 p_echo_request = (Ether(src=self.pg0.remote_mac,
1096 dst=self.pg0.local_mac) /
1097 IPv6(src=self.pg0.remote_ip6,
1098 dst=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001099 ICMPv6EchoRequest(
1100 id=icmpv6_id,
1101 seq=icmpv6_seq,
1102 data=icmpv6_data))
Jan Geletye6c78ee2018-06-26 12:24:03 +02001103
1104 self.pg0.add_stream(p_echo_request)
1105 self.pg_enable_capture(self.pg_interfaces)
1106 self.pg_start()
1107
1108 rx = self.pg0.get_capture(1)
1109 rx = rx[0]
1110 ether = rx[Ether]
1111 ipv6 = rx[IPv6]
1112 icmpv6 = rx[ICMPv6EchoReply]
1113
1114 self.assertEqual(ether.src, self.pg0.local_mac)
1115 self.assertEqual(ether.dst, self.pg0.remote_mac)
1116
1117 self.assertEqual(ipv6.src, self.pg0.local_ip6)
1118 self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1119
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001120 self.assertEqual(
1121 icmp6types[icmpv6.type], "Echo Reply")
Jan Geletye6c78ee2018-06-26 12:24:03 +02001122 self.assertEqual(icmpv6.id, icmpv6_id)
1123 self.assertEqual(icmpv6.seq, icmpv6_seq)
1124 self.assertEqual(icmpv6.data, icmpv6_data)
1125
1126
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001127class TestIPv6RD(TestIPv6ND):
1128 """ IPv6 Router Discovery Test Case """
1129
1130 @classmethod
1131 def setUpClass(cls):
1132 super(TestIPv6RD, cls).setUpClass()
1133
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001134 @classmethod
1135 def tearDownClass(cls):
1136 super(TestIPv6RD, cls).tearDownClass()
1137
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001138 def setUp(self):
1139 super(TestIPv6RD, self).setUp()
1140
1141 # create 2 pg interfaces
1142 self.create_pg_interfaces(range(2))
1143
1144 self.interfaces = list(self.pg_interfaces)
1145
1146 # setup all interfaces
1147 for i in self.interfaces:
1148 i.admin_up()
1149 i.config_ip6()
1150
1151 def tearDown(self):
Neale Ranns744902e2017-08-14 10:35:44 -07001152 for i in self.interfaces:
1153 i.unconfig_ip6()
1154 i.admin_down()
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001155 super(TestIPv6RD, self).tearDown()
1156
1157 def test_rd_send_router_solicitation(self):
1158 """ Verify router solicitation packets """
1159
1160 count = 2
1161 self.pg_enable_capture(self.pg_interfaces)
1162 self.pg_start()
1163 self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1164 mrc=count)
1165 rx_list = self.pg1.get_capture(count, timeout=3)
1166 self.assertEqual(len(rx_list), count)
1167 for packet in rx_list:
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001168 self.assertEqual(packet.haslayer(IPv6), 1)
1169 self.assertEqual(packet[IPv6].haslayer(
1170 ICMPv6ND_RS), 1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001171 dst = ip6_normalize(packet[IPv6].dst)
1172 dst2 = ip6_normalize("ff02::2")
1173 self.assert_equal(dst, dst2)
1174 src = ip6_normalize(packet[IPv6].src)
1175 src2 = ip6_normalize(self.pg1.local_ip6_ll)
1176 self.assert_equal(src, src2)
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001177 self.assertTrue(
1178 bool(packet[ICMPv6ND_RS].haslayer(
1179 ICMPv6NDOptSrcLLAddr)))
1180 self.assert_equal(
1181 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1182 self.pg1.local_mac)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001183
1184 def verify_prefix_info(self, reported_prefix, prefix_option):
Neale Ranns37029302018-08-10 05:30:06 -07001185 prefix = IPv6Network(
Paul Vinciguerra1e18eb22018-11-25 16:09:26 -08001186 text_type(prefix_option.getfieldval("prefix") +
1187 "/" +
1188 text_type(prefix_option.getfieldval("prefixlen"))),
Neale Ranns37029302018-08-10 05:30:06 -07001189 strict=False)
1190 self.assert_equal(reported_prefix.prefix.network_address,
1191 prefix.network_address)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001192 L = prefix_option.getfieldval("L")
1193 A = prefix_option.getfieldval("A")
1194 option_flags = (L << 7) | (A << 6)
1195 self.assert_equal(reported_prefix.flags, option_flags)
1196 self.assert_equal(reported_prefix.valid_time,
1197 prefix_option.getfieldval("validlifetime"))
1198 self.assert_equal(reported_prefix.preferred_time,
1199 prefix_option.getfieldval("preferredlifetime"))
1200
1201 def test_rd_receive_router_advertisement(self):
1202 """ Verify events triggered by received RA packets """
1203
Neale Rannscbe25aa2019-09-30 10:53:31 +00001204 self.vapi.want_ip6_ra_events(enable=1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001205
1206 prefix_info_1 = ICMPv6NDOptPrefixInfo(
1207 prefix="1::2",
1208 prefixlen=50,
1209 validlifetime=200,
1210 preferredlifetime=500,
1211 L=1,
1212 A=1,
1213 )
1214
1215 prefix_info_2 = ICMPv6NDOptPrefixInfo(
1216 prefix="7::4",
1217 prefixlen=20,
1218 validlifetime=70,
1219 preferredlifetime=1000,
1220 L=1,
1221 A=0,
1222 )
1223
1224 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1225 IPv6(dst=self.pg1.local_ip6_ll,
1226 src=mk_ll_addr(self.pg1.remote_mac)) /
1227 ICMPv6ND_RA() /
1228 prefix_info_1 /
1229 prefix_info_2)
1230 self.pg1.add_stream([p])
1231 self.pg_start()
1232
1233 ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1234
1235 self.assert_equal(ev.current_hop_limit, 0)
1236 self.assert_equal(ev.flags, 8)
1237 self.assert_equal(ev.router_lifetime_in_sec, 1800)
1238 self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1239 self.assert_equal(
1240 ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1241
1242 self.assert_equal(ev.n_prefixes, 2)
1243
1244 self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1245 self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1246
1247
Juraj Slobodac0374232018-02-01 15:18:49 +01001248class TestIPv6RDControlPlane(TestIPv6ND):
1249 """ IPv6 Router Discovery Control Plane Test Case """
1250
1251 @classmethod
1252 def setUpClass(cls):
1253 super(TestIPv6RDControlPlane, cls).setUpClass()
1254
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001255 @classmethod
1256 def tearDownClass(cls):
1257 super(TestIPv6RDControlPlane, cls).tearDownClass()
1258
Juraj Slobodac0374232018-02-01 15:18:49 +01001259 def setUp(self):
1260 super(TestIPv6RDControlPlane, self).setUp()
1261
1262 # create 1 pg interface
1263 self.create_pg_interfaces(range(1))
1264
1265 self.interfaces = list(self.pg_interfaces)
1266
1267 # setup all interfaces
1268 for i in self.interfaces:
1269 i.admin_up()
1270 i.config_ip6()
1271
1272 def tearDown(self):
1273 super(TestIPv6RDControlPlane, self).tearDown()
1274
1275 @staticmethod
1276 def create_ra_packet(pg, routerlifetime=None):
1277 src_ip = pg.remote_ip6_ll
1278 dst_ip = pg.local_ip6
1279 if routerlifetime is not None:
1280 ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1281 else:
1282 ra = ICMPv6ND_RA()
1283 p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1284 IPv6(dst=dst_ip, src=src_ip) / ra)
1285 return p
1286
1287 @staticmethod
1288 def get_default_routes(fib):
1289 list = []
1290 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001291 if entry.route.prefix.prefixlen == 0:
1292 for path in entry.route.paths:
Juraj Slobodac0374232018-02-01 15:18:49 +01001293 if path.sw_if_index != 0xFFFFFFFF:
Neale Ranns097fa662018-05-01 05:17:55 -07001294 defaut_route = {}
1295 defaut_route['sw_if_index'] = path.sw_if_index
1296 defaut_route['next_hop'] = path.nh.address.ip6
1297 list.append(defaut_route)
Juraj Slobodac0374232018-02-01 15:18:49 +01001298 return list
1299
1300 @staticmethod
1301 def get_interface_addresses(fib, pg):
1302 list = []
1303 for entry in fib:
Neale Ranns097fa662018-05-01 05:17:55 -07001304 if entry.route.prefix.prefixlen == 128:
1305 path = entry.route.paths[0]
Juraj Slobodac0374232018-02-01 15:18:49 +01001306 if path.sw_if_index == pg.sw_if_index:
Neale Ranns097fa662018-05-01 05:17:55 -07001307 list.append(str(entry.route.prefix.network_address))
Juraj Slobodac0374232018-02-01 15:18:49 +01001308 return list
1309
Neale Rannscbe25aa2019-09-30 10:53:31 +00001310 def wait_for_no_default_route(self, n_tries=50, s_time=1):
1311 while (n_tries):
1312 fib = self.vapi.ip_route_dump(0, True)
1313 default_routes = self.get_default_routes(fib)
Ole Troan6e6ad642020-02-04 13:28:13 +01001314 if 0 == len(default_routes):
Neale Rannscbe25aa2019-09-30 10:53:31 +00001315 return True
1316 n_tries = n_tries - 1
1317 self.sleep(s_time)
1318
1319 return False
1320
Juraj Slobodac0374232018-02-01 15:18:49 +01001321 def test_all(self):
1322 """ Test handling of SLAAC addresses and default routes """
1323
Neale Ranns097fa662018-05-01 05:17:55 -07001324 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001325 default_routes = self.get_default_routes(fib)
1326 initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1327 self.assertEqual(default_routes, [])
Neale Ranns097fa662018-05-01 05:17:55 -07001328 router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll))
Juraj Slobodac0374232018-02-01 15:18:49 +01001329
1330 self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1331
1332 self.sleep(0.1)
1333
1334 # send RA
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001335 packet = (self.create_ra_packet(
1336 self.pg0) / ICMPv6NDOptPrefixInfo(
Juraj Slobodac0374232018-02-01 15:18:49 +01001337 prefix="1::",
1338 prefixlen=64,
1339 validlifetime=2,
1340 preferredlifetime=2,
1341 L=1,
1342 A=1,
1343 ) / ICMPv6NDOptPrefixInfo(
1344 prefix="7::",
1345 prefixlen=20,
1346 validlifetime=1500,
1347 preferredlifetime=1000,
1348 L=1,
1349 A=0,
1350 ))
1351 self.pg0.add_stream([packet])
1352 self.pg_start()
1353
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001354 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001355
Neale Ranns097fa662018-05-01 05:17:55 -07001356 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001357
1358 # check FIB for new address
1359 addresses = set(self.get_interface_addresses(fib, self.pg0))
1360 new_addresses = addresses.difference(initial_addresses)
1361 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001362 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1363 strict=False)
1364 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001365
1366 # check FIB for new default route
1367 default_routes = self.get_default_routes(fib)
1368 self.assertEqual(len(default_routes), 1)
1369 dr = default_routes[0]
1370 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1371 self.assertEqual(dr['next_hop'], router_address)
1372
1373 # send RA to delete default route
1374 packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1375 self.pg0.add_stream([packet])
1376 self.pg_start()
1377
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001378 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001379
1380 # check that default route is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001381 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001382 default_routes = self.get_default_routes(fib)
1383 self.assertEqual(len(default_routes), 0)
1384
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001385 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001386
1387 # send RA
1388 packet = self.create_ra_packet(self.pg0)
1389 self.pg0.add_stream([packet])
1390 self.pg_start()
1391
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001392 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001393
1394 # check FIB for new default route
Neale Ranns097fa662018-05-01 05:17:55 -07001395 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001396 default_routes = self.get_default_routes(fib)
1397 self.assertEqual(len(default_routes), 1)
1398 dr = default_routes[0]
1399 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1400 self.assertEqual(dr['next_hop'], router_address)
1401
1402 # send RA, updating router lifetime to 1s
1403 packet = self.create_ra_packet(self.pg0, 1)
1404 self.pg0.add_stream([packet])
1405 self.pg_start()
1406
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001407 self.sleep_on_vpp_time(0.1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001408
1409 # check that default route still exists
Neale Ranns097fa662018-05-01 05:17:55 -07001410 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001411 default_routes = self.get_default_routes(fib)
1412 self.assertEqual(len(default_routes), 1)
1413 dr = default_routes[0]
1414 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1415 self.assertEqual(dr['next_hop'], router_address)
1416
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001417 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001418
1419 # check that default route is deleted
Neale Rannscbe25aa2019-09-30 10:53:31 +00001420 self.assertTrue(self.wait_for_no_default_route())
Juraj Slobodac0374232018-02-01 15:18:49 +01001421
1422 # check FIB still contains the SLAAC address
1423 addresses = set(self.get_interface_addresses(fib, self.pg0))
1424 new_addresses = addresses.difference(initial_addresses)
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001425
Juraj Slobodac0374232018-02-01 15:18:49 +01001426 self.assertEqual(len(new_addresses), 1)
Neale Ranns097fa662018-05-01 05:17:55 -07001427 prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)),
1428 strict=False)
1429 self.assertEqual(prefix, IPv6Network(text_type('1::/20')))
Juraj Slobodac0374232018-02-01 15:18:49 +01001430
Andrew Yourtchenko63cb8822019-10-13 18:56:03 +00001431 self.sleep_on_vpp_time(1)
Juraj Slobodac0374232018-02-01 15:18:49 +01001432
1433 # check that SLAAC address is deleted
Neale Ranns097fa662018-05-01 05:17:55 -07001434 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodac0374232018-02-01 15:18:49 +01001435 addresses = set(self.get_interface_addresses(fib, self.pg0))
1436 new_addresses = addresses.difference(initial_addresses)
1437 self.assertEqual(len(new_addresses), 0)
1438
1439
Neale Ranns3f844d02017-02-18 00:03:54 -08001440class IPv6NDProxyTest(TestIPv6ND):
1441 """ IPv6 ND ProxyTest Case """
1442
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001443 @classmethod
1444 def setUpClass(cls):
1445 super(IPv6NDProxyTest, cls).setUpClass()
1446
1447 @classmethod
1448 def tearDownClass(cls):
1449 super(IPv6NDProxyTest, cls).tearDownClass()
1450
Neale Ranns3f844d02017-02-18 00:03:54 -08001451 def setUp(self):
1452 super(IPv6NDProxyTest, self).setUp()
1453
1454 # create 3 pg interfaces
1455 self.create_pg_interfaces(range(3))
1456
1457 # pg0 is the master interface, with the configured subnet
1458 self.pg0.admin_up()
1459 self.pg0.config_ip6()
1460 self.pg0.resolve_ndp()
1461
1462 self.pg1.ip6_enable()
1463 self.pg2.ip6_enable()
1464
1465 def tearDown(self):
1466 super(IPv6NDProxyTest, self).tearDown()
1467
1468 def test_nd_proxy(self):
1469 """ IPv6 Proxy ND """
1470
1471 #
1472 # Generate some hosts in the subnet that we are proxying
1473 #
1474 self.pg0.generate_remote_hosts(8)
1475
1476 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1477 d = inet_ntop(AF_INET6, nsma)
1478
1479 #
1480 # Send an NS for one of those remote hosts on one of the proxy links
1481 # expect no response since it's from an address that is not
1482 # on the link that has the prefix configured
1483 #
1484 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001485 IPv6(dst=d,
1486 src=self.pg0._remote_hosts[2].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001487 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001488 ICMPv6NDOptSrcLLAddr(
1489 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001490
1491 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1492
1493 #
1494 # Add proxy support for the host
1495 #
Ole Troane1ade682019-03-04 23:55:43 +01001496 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001497 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001498 sw_if_index=self.pg1.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001499
1500 #
1501 # try that NS again. this time we expect an NA back
1502 #
Neale Ranns2a3ea492017-04-19 05:24:40 -07001503 self.send_and_expect_na(self.pg1, ns_pg1,
1504 "NS to proxy entry",
1505 dst_ip=self.pg0._remote_hosts[2].ip6,
1506 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001507
1508 #
1509 # ... and that we have an entry in the ND cache
1510 #
1511 self.assertTrue(find_nbr(self,
1512 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001513 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001514
1515 #
1516 # ... and we can route traffic to it
1517 #
1518 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1519 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1520 src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001521 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001522 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001523
1524 self.pg0.add_stream(t)
1525 self.pg_enable_capture(self.pg_interfaces)
1526 self.pg_start()
1527 rx = self.pg1.get_capture(1)
1528 rx = rx[0]
1529
1530 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1531 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1532
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001533 self.assertEqual(rx[IPv6].src,
1534 t[IPv6].src)
1535 self.assertEqual(rx[IPv6].dst,
1536 t[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001537
1538 #
1539 # Test we proxy for the host on the main interface
1540 #
1541 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1542 IPv6(dst=d, src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001543 ICMPv6ND_NS(
1544 tgt=self.pg0._remote_hosts[2].ip6) /
1545 ICMPv6NDOptSrcLLAddr(
1546 lladdr=self.pg0.remote_mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001547
Neale Ranns2a3ea492017-04-19 05:24:40 -07001548 self.send_and_expect_na(self.pg0, ns_pg0,
1549 "NS to proxy entry on main",
1550 tgt_ip=self.pg0._remote_hosts[2].ip6,
1551 dst_ip=self.pg0.remote_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001552
1553 #
1554 # Setup and resolve proxy for another host on another interface
1555 #
1556 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001557 IPv6(dst=d,
1558 src=self.pg0._remote_hosts[3].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001559 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001560 ICMPv6NDOptSrcLLAddr(
1561 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001562
Ole Troane1ade682019-03-04 23:55:43 +01001563 self.vapi.ip6nd_proxy_add_del(
Neale Rannscbe25aa2019-09-30 10:53:31 +00001564 is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Ole Troan9a475372019-03-05 16:58:24 +01001565 sw_if_index=self.pg2.sw_if_index)
Neale Ranns3f844d02017-02-18 00:03:54 -08001566
Neale Ranns2a3ea492017-04-19 05:24:40 -07001567 self.send_and_expect_na(self.pg2, ns_pg2,
1568 "NS to proxy entry other interface",
1569 dst_ip=self.pg0._remote_hosts[3].ip6,
1570 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001571
1572 self.assertTrue(find_nbr(self,
1573 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001574 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001575
1576 #
1577 # hosts can communicate. pg2->pg1
1578 #
1579 t2 = (Ether(dst=self.pg2.local_mac,
1580 src=self.pg0.remote_hosts[3].mac) /
1581 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1582 src=self.pg0._remote_hosts[3].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001583 inet6.UDP(sport=10000, dport=20000) /
Ole Troan770a0de2019-11-07 13:52:21 +01001584 Raw(b'\xa5' * 100))
Neale Ranns3f844d02017-02-18 00:03:54 -08001585
1586 self.pg2.add_stream(t2)
1587 self.pg_enable_capture(self.pg_interfaces)
1588 self.pg_start()
1589 rx = self.pg1.get_capture(1)
1590 rx = rx[0]
1591
1592 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1593 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1594
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001595 self.assertEqual(rx[IPv6].src,
1596 t2[IPv6].src)
1597 self.assertEqual(rx[IPv6].dst,
1598 t2[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001599
1600 #
1601 # remove the proxy configs
1602 #
Ole Troane1ade682019-03-04 23:55:43 +01001603 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001604 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001605 sw_if_index=self.pg1.sw_if_index, is_add=0)
Ole Troane1ade682019-03-04 23:55:43 +01001606 self.vapi.ip6nd_proxy_add_del(
Ole Troan9a475372019-03-05 16:58:24 +01001607 ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
Neale Rannscbe25aa2019-09-30 10:53:31 +00001608 sw_if_index=self.pg2.sw_if_index, is_add=0)
Neale Ranns3f844d02017-02-18 00:03:54 -08001609
1610 self.assertFalse(find_nbr(self,
1611 self.pg2.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001612 self.pg0._remote_hosts[3].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001613 self.assertFalse(find_nbr(self,
1614 self.pg1.sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -07001615 self.pg0._remote_hosts[2].ip6))
Neale Ranns3f844d02017-02-18 00:03:54 -08001616
1617 #
1618 # no longer proxy-ing...
1619 #
1620 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1621 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1622 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1623
1624 #
1625 # no longer forwarding. traffic generates NS out of the glean/main
1626 # interface
1627 #
1628 self.pg2.add_stream(t2)
1629 self.pg_enable_capture(self.pg_interfaces)
1630 self.pg_start()
1631
1632 rx = self.pg0.get_capture(1)
1633
1634 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1635
1636
Neale Ranns37be7362017-02-21 17:30:26 -08001637class TestIPNull(VppTestCase):
1638 """ IPv6 routes via NULL """
1639
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001640 @classmethod
1641 def setUpClass(cls):
1642 super(TestIPNull, cls).setUpClass()
1643
1644 @classmethod
1645 def tearDownClass(cls):
1646 super(TestIPNull, cls).tearDownClass()
1647
Neale Ranns37be7362017-02-21 17:30:26 -08001648 def setUp(self):
1649 super(TestIPNull, self).setUp()
1650
1651 # create 2 pg interfaces
1652 self.create_pg_interfaces(range(1))
1653
1654 for i in self.pg_interfaces:
1655 i.admin_up()
1656 i.config_ip6()
1657 i.resolve_ndp()
1658
1659 def tearDown(self):
1660 super(TestIPNull, self).tearDown()
1661 for i in self.pg_interfaces:
1662 i.unconfig_ip6()
1663 i.admin_down()
1664
1665 def test_ip_null(self):
1666 """ IP NULL route """
1667
1668 p = (Ether(src=self.pg0.remote_mac,
1669 dst=self.pg0.local_mac) /
1670 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001671 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001672 Raw(b'\xa5' * 100))
Neale Ranns37be7362017-02-21 17:30:26 -08001673
1674 #
1675 # A route via IP NULL that will reply with ICMP unreachables
1676 #
Neale Ranns097fa662018-05-01 05:17:55 -07001677 ip_unreach = VppIpRoute(
1678 self, "2001::", 64,
1679 [VppRoutePath("::", 0xffffffff,
1680 type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)])
Neale Ranns37be7362017-02-21 17:30:26 -08001681 ip_unreach.add_vpp_config()
1682
1683 self.pg0.add_stream(p)
1684 self.pg_enable_capture(self.pg_interfaces)
1685 self.pg_start()
1686
1687 rx = self.pg0.get_capture(1)
1688 rx = rx[0]
1689 icmp = rx[ICMPv6DestUnreach]
1690
1691 # 0 = "No route to destination"
1692 self.assertEqual(icmp.code, 0)
1693
1694 # ICMP is rate limited. pause a bit
1695 self.sleep(1)
1696
1697 #
1698 # A route via IP NULL that will reply with ICMP prohibited
1699 #
Neale Ranns097fa662018-05-01 05:17:55 -07001700 ip_prohibit = VppIpRoute(
1701 self, "2001::1", 128,
1702 [VppRoutePath("::", 0xffffffff,
1703 type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)])
Neale Ranns37be7362017-02-21 17:30:26 -08001704 ip_prohibit.add_vpp_config()
1705
1706 self.pg0.add_stream(p)
1707 self.pg_enable_capture(self.pg_interfaces)
1708 self.pg_start()
1709
1710 rx = self.pg0.get_capture(1)
1711 rx = rx[0]
1712 icmp = rx[ICMPv6DestUnreach]
1713
1714 # 1 = "Communication with destination administratively prohibited"
1715 self.assertEqual(icmp.code, 1)
1716
1717
Neale Ranns180279b2017-03-16 15:49:09 -04001718class TestIPDisabled(VppTestCase):
1719 """ IPv6 disabled """
1720
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001721 @classmethod
1722 def setUpClass(cls):
1723 super(TestIPDisabled, cls).setUpClass()
1724
1725 @classmethod
1726 def tearDownClass(cls):
1727 super(TestIPDisabled, cls).tearDownClass()
1728
Neale Ranns180279b2017-03-16 15:49:09 -04001729 def setUp(self):
1730 super(TestIPDisabled, self).setUp()
1731
1732 # create 2 pg interfaces
1733 self.create_pg_interfaces(range(2))
1734
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001735 # PG0 is IP enabled
Neale Ranns180279b2017-03-16 15:49:09 -04001736 self.pg0.admin_up()
1737 self.pg0.config_ip6()
1738 self.pg0.resolve_ndp()
1739
1740 # PG 1 is not IP enabled
1741 self.pg1.admin_up()
1742
1743 def tearDown(self):
1744 super(TestIPDisabled, self).tearDown()
1745 for i in self.pg_interfaces:
1746 i.unconfig_ip4()
1747 i.admin_down()
1748
Neale Ranns180279b2017-03-16 15:49:09 -04001749 def test_ip_disabled(self):
1750 """ IP Disabled """
1751
1752 #
1753 # An (S,G).
1754 # one accepting interface, pg0, 2 forwarding interfaces
1755 #
1756 route_ff_01 = VppIpMRoute(
1757 self,
1758 "::",
1759 "ffef::1", 128,
1760 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1761 [VppMRoutePath(self.pg1.sw_if_index,
1762 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1763 VppMRoutePath(self.pg0.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07001764 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
Neale Ranns180279b2017-03-16 15:49:09 -04001765 route_ff_01.add_vpp_config()
1766
1767 pu = (Ether(src=self.pg1.remote_mac,
1768 dst=self.pg1.local_mac) /
1769 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001770 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001771 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001772 pm = (Ether(src=self.pg1.remote_mac,
1773 dst=self.pg1.local_mac) /
1774 IPv6(src="2001::1", dst="ffef::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001775 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001776 Raw(b'\xa5' * 100))
Neale Ranns180279b2017-03-16 15:49:09 -04001777
1778 #
1779 # PG1 does not forward IP traffic
1780 #
1781 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1782 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1783
1784 #
1785 # IP enable PG1
1786 #
1787 self.pg1.config_ip6()
1788
1789 #
1790 # Now we get packets through
1791 #
1792 self.pg1.add_stream(pu)
1793 self.pg_enable_capture(self.pg_interfaces)
1794 self.pg_start()
1795 rx = self.pg0.get_capture(1)
1796
1797 self.pg1.add_stream(pm)
1798 self.pg_enable_capture(self.pg_interfaces)
1799 self.pg_start()
1800 rx = self.pg0.get_capture(1)
1801
1802 #
1803 # Disable PG1
1804 #
1805 self.pg1.unconfig_ip6()
1806
1807 #
1808 # PG1 does not forward IP traffic
1809 #
1810 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1811 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1812
1813
Neale Ranns227038a2017-04-21 01:07:59 -07001814class TestIP6LoadBalance(VppTestCase):
1815 """ IPv6 Load-Balancing """
1816
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001817 @classmethod
1818 def setUpClass(cls):
1819 super(TestIP6LoadBalance, cls).setUpClass()
1820
1821 @classmethod
1822 def tearDownClass(cls):
1823 super(TestIP6LoadBalance, cls).tearDownClass()
1824
Neale Ranns227038a2017-04-21 01:07:59 -07001825 def setUp(self):
1826 super(TestIP6LoadBalance, self).setUp()
1827
1828 self.create_pg_interfaces(range(5))
1829
Neale Ranns15002542017-09-10 04:39:11 -07001830 mpls_tbl = VppMplsTable(self, 0)
1831 mpls_tbl.add_vpp_config()
1832
Neale Ranns227038a2017-04-21 01:07:59 -07001833 for i in self.pg_interfaces:
1834 i.admin_up()
1835 i.config_ip6()
1836 i.resolve_ndp()
Neale Ranns71275e32017-05-25 12:38:58 -07001837 i.enable_mpls()
Neale Ranns227038a2017-04-21 01:07:59 -07001838
1839 def tearDown(self):
Neale Ranns227038a2017-04-21 01:07:59 -07001840 for i in self.pg_interfaces:
1841 i.unconfig_ip6()
1842 i.admin_down()
Neale Ranns71275e32017-05-25 12:38:58 -07001843 i.disable_mpls()
Neale Ranns15002542017-09-10 04:39:11 -07001844 super(TestIP6LoadBalance, self).tearDown()
Neale Ranns227038a2017-04-21 01:07:59 -07001845
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001846 def pg_send(self, input, pkts):
Neale Ranns62fe07c2017-10-31 12:28:22 -07001847 self.vapi.cli("clear trace")
Neale Ranns227038a2017-04-21 01:07:59 -07001848 input.add_stream(pkts)
1849 self.pg_enable_capture(self.pg_interfaces)
1850 self.pg_start()
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001851
1852 def send_and_expect_load_balancing(self, input, pkts, outputs):
1853 self.pg_send(input, pkts)
Neale Ranns227038a2017-04-21 01:07:59 -07001854 for oo in outputs:
1855 rx = oo._get_capture(1)
1856 self.assertNotEqual(0, len(rx))
1857
Neale Ranns71275e32017-05-25 12:38:58 -07001858 def send_and_expect_one_itf(self, input, pkts, itf):
Paul Vinciguerraeb414432019-02-20 09:01:14 -08001859 self.pg_send(input, pkts)
Neale Ranns71275e32017-05-25 12:38:58 -07001860 rx = itf.get_capture(len(pkts))
1861
Neale Ranns227038a2017-04-21 01:07:59 -07001862 def test_ip6_load_balance(self):
1863 """ IPv6 Load-Balancing """
1864
1865 #
1866 # An array of packets that differ only in the destination port
Neale Ranns71275e32017-05-25 12:38:58 -07001867 # - IP only
1868 # - MPLS EOS
1869 # - MPLS non-EOS
1870 # - MPLS non-EOS with an entropy label
Neale Ranns227038a2017-04-21 01:07:59 -07001871 #
Neale Ranns71275e32017-05-25 12:38:58 -07001872 port_ip_pkts = []
1873 port_mpls_pkts = []
1874 port_mpls_neos_pkts = []
1875 port_ent_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001876
1877 #
1878 # An array of packets that differ only in the source address
1879 #
Neale Ranns71275e32017-05-25 12:38:58 -07001880 src_ip_pkts = []
1881 src_mpls_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001882
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001883 for ii in range(NUM_PKTS):
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001884 port_ip_hdr = (
1885 IPv6(dst="3000::1", src="3000:1::1") /
1886 inet6.UDP(sport=1234, dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01001887 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001888 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1889 dst=self.pg0.local_mac) /
1890 port_ip_hdr))
1891 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1892 dst=self.pg0.local_mac) /
1893 MPLS(label=66, ttl=2) /
1894 port_ip_hdr))
1895 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1896 dst=self.pg0.local_mac) /
1897 MPLS(label=67, ttl=2) /
1898 MPLS(label=77, ttl=2) /
1899 port_ip_hdr))
1900 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1901 dst=self.pg0.local_mac) /
1902 MPLS(label=67, ttl=2) /
1903 MPLS(label=14, ttl=2) /
1904 MPLS(label=999, ttl=2) /
1905 port_ip_hdr))
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001906 src_ip_hdr = (
1907 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
1908 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01001909 Raw(b'\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001910 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1911 dst=self.pg0.local_mac) /
1912 src_ip_hdr))
1913 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1914 dst=self.pg0.local_mac) /
1915 MPLS(label=66, ttl=2) /
1916 src_ip_hdr))
Neale Ranns227038a2017-04-21 01:07:59 -07001917
Neale Ranns71275e32017-05-25 12:38:58 -07001918 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001919 # A route for the IP packets
Neale Ranns71275e32017-05-25 12:38:58 -07001920 #
Neale Ranns227038a2017-04-21 01:07:59 -07001921 route_3000_1 = VppIpRoute(self, "3000::1", 128,
1922 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07001923 self.pg1.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07001924 VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07001925 self.pg2.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07001926 route_3000_1.add_vpp_config()
1927
1928 #
Neale Ranns71275e32017-05-25 12:38:58 -07001929 # a local-label for the EOS packets
1930 #
1931 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
1932 binding.add_vpp_config()
1933
1934 #
1935 # An MPLS route for the non-EOS packets
1936 #
1937 route_67 = VppMplsRoute(self, 67, 0,
1938 [VppRoutePath(self.pg1.remote_ip6,
1939 self.pg1.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07001940 labels=[67]),
Neale Ranns71275e32017-05-25 12:38:58 -07001941 VppRoutePath(self.pg2.remote_ip6,
1942 self.pg2.sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -07001943 labels=[67])])
Neale Ranns71275e32017-05-25 12:38:58 -07001944 route_67.add_vpp_config()
1945
1946 #
Neale Ranns227038a2017-04-21 01:07:59 -07001947 # inject the packet on pg0 - expect load-balancing across the 2 paths
1948 # - since the default hash config is to use IP src,dst and port
1949 # src,dst
1950 # We are not going to ensure equal amounts of packets across each link,
1951 # since the hash algorithm is statistical and therefore this can never
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001952 # be guaranteed. But with 64 different packets we do expect some
Neale Ranns227038a2017-04-21 01:07:59 -07001953 # balancing. So instead just ensure there is traffic on each link.
1954 #
Neale Ranns71275e32017-05-25 12:38:58 -07001955 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001956 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001957 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001958 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001959 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
1960 [self.pg1, self.pg2])
1961 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1962 [self.pg1, self.pg2])
1963 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
1964 [self.pg1, self.pg2])
1965
1966 #
1967 # The packets with Entropy label in should not load-balance,
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001968 # since the Entropy value is fixed.
Neale Ranns71275e32017-05-25 12:38:58 -07001969 #
1970 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
Neale Ranns227038a2017-04-21 01:07:59 -07001971
1972 #
1973 # change the flow hash config so it's only IP src,dst
1974 # - now only the stream with differing source address will
1975 # load-balance
1976 #
Ole Troana5b2eec2019-03-11 19:23:25 +01001977 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0,
1978 is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07001979
Neale Ranns71275e32017-05-25 12:38:58 -07001980 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001981 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001982 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1983 [self.pg1, self.pg2])
1984 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
Neale Ranns227038a2017-04-21 01:07:59 -07001985
1986 #
1987 # change the flow hash config back to defaults
1988 #
Ole Troana5b2eec2019-03-11 19:23:25 +01001989 self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1,
1990 is_ipv6=1)
Neale Ranns227038a2017-04-21 01:07:59 -07001991
1992 #
1993 # Recursive prefixes
1994 # - testing that 2 stages of load-balancing occurs and there is no
1995 # polarisation (i.e. only 2 of 4 paths are used)
1996 #
1997 port_pkts = []
1998 src_pkts = []
1999
2000 for ii in range(257):
2001 port_pkts.append((Ether(src=self.pg0.remote_mac,
2002 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002003 IPv6(dst="4000::1",
2004 src="4000:1::1") /
2005 inet6.UDP(sport=1234,
2006 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002007 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002008 src_pkts.append((Ether(src=self.pg0.remote_mac,
2009 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002010 IPv6(dst="4000::1",
2011 src="4000:1::%d" % ii) /
2012 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002013 Raw(b'\xa5' * 100)))
Neale Ranns227038a2017-04-21 01:07:59 -07002014
2015 route_3000_2 = VppIpRoute(self, "3000::2", 128,
2016 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002017 self.pg3.sw_if_index),
Neale Ranns227038a2017-04-21 01:07:59 -07002018 VppRoutePath(self.pg4.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002019 self.pg4.sw_if_index)])
Neale Ranns227038a2017-04-21 01:07:59 -07002020 route_3000_2.add_vpp_config()
2021
2022 route_4000_1 = VppIpRoute(self, "4000::1", 128,
2023 [VppRoutePath("3000::1",
Neale Ranns097fa662018-05-01 05:17:55 -07002024 0xffffffff),
Neale Ranns227038a2017-04-21 01:07:59 -07002025 VppRoutePath("3000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002026 0xffffffff)])
Neale Ranns227038a2017-04-21 01:07:59 -07002027 route_4000_1.add_vpp_config()
2028
2029 #
2030 # inject the packet on pg0 - expect load-balancing across all 4 paths
2031 #
2032 self.vapi.cli("clear trace")
2033 self.send_and_expect_load_balancing(self.pg0, port_pkts,
2034 [self.pg1, self.pg2,
2035 self.pg3, self.pg4])
2036 self.send_and_expect_load_balancing(self.pg0, src_pkts,
2037 [self.pg1, self.pg2,
2038 self.pg3, self.pg4])
2039
Neale Ranns42e6b092017-07-31 02:56:03 -07002040 #
2041 # Recursive prefixes
2042 # - testing that 2 stages of load-balancing no choices
2043 #
2044 port_pkts = []
2045
2046 for ii in range(257):
2047 port_pkts.append((Ether(src=self.pg0.remote_mac,
2048 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002049 IPv6(dst="6000::1",
2050 src="6000:1::1") /
2051 inet6.UDP(sport=1234,
2052 dport=1234 + ii) /
Ole Troan770a0de2019-11-07 13:52:21 +01002053 Raw(b'\xa5' * 100)))
Neale Ranns42e6b092017-07-31 02:56:03 -07002054
2055 route_5000_2 = VppIpRoute(self, "5000::2", 128,
2056 [VppRoutePath(self.pg3.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002057 self.pg3.sw_if_index)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002058 route_5000_2.add_vpp_config()
2059
2060 route_6000_1 = VppIpRoute(self, "6000::1", 128,
2061 [VppRoutePath("5000::2",
Neale Ranns097fa662018-05-01 05:17:55 -07002062 0xffffffff)])
Neale Ranns42e6b092017-07-31 02:56:03 -07002063 route_6000_1.add_vpp_config()
2064
2065 #
2066 # inject the packet on pg0 - expect load-balancing across all 4 paths
2067 #
2068 self.vapi.cli("clear trace")
2069 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
2070
Neale Ranns227038a2017-04-21 01:07:59 -07002071
Neale Rannsd91c1db2017-07-31 02:30:50 -07002072class TestIP6Punt(VppTestCase):
2073 """ IPv6 Punt Police/Redirect """
2074
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002075 @classmethod
2076 def setUpClass(cls):
2077 super(TestIP6Punt, cls).setUpClass()
2078
2079 @classmethod
2080 def tearDownClass(cls):
2081 super(TestIP6Punt, cls).tearDownClass()
2082
Neale Rannsd91c1db2017-07-31 02:30:50 -07002083 def setUp(self):
2084 super(TestIP6Punt, self).setUp()
2085
Pavel Kotucek609e1212018-11-27 09:59:44 +01002086 self.create_pg_interfaces(range(4))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002087
2088 for i in self.pg_interfaces:
2089 i.admin_up()
2090 i.config_ip6()
2091 i.resolve_ndp()
2092
2093 def tearDown(self):
2094 super(TestIP6Punt, self).tearDown()
2095 for i in self.pg_interfaces:
2096 i.unconfig_ip6()
2097 i.admin_down()
2098
Neale Rannsd91c1db2017-07-31 02:30:50 -07002099 def test_ip_punt(self):
2100 """ IP6 punt police and redirect """
2101
2102 p = (Ether(src=self.pg0.remote_mac,
2103 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002104 IPv6(src=self.pg0.remote_ip6,
2105 dst=self.pg0.local_ip6) /
2106 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002107 Raw(b'\xa5' * 100))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002108
2109 pkts = p * 1025
2110
2111 #
2112 # Configure a punt redirect via pg1.
2113 #
Ole Troan0bcad322018-12-11 13:04:01 +01002114 nh_addr = self.pg1.remote_ip6
Neale Rannsd91c1db2017-07-31 02:30:50 -07002115 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2116 self.pg1.sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002117 nh_addr)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002118
2119 self.send_and_expect(self.pg0, pkts, self.pg1)
2120
2121 #
2122 # add a policer
2123 #
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002124 policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1)
2125 policer.add_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002126 self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
2127
2128 self.vapi.cli("clear trace")
2129 self.pg0.add_stream(pkts)
2130 self.pg_enable_capture(self.pg_interfaces)
2131 self.pg_start()
2132
2133 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002134 # the number of packet received should be greater than 0,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002135 # but not equal to the number sent, since some were policed
2136 #
2137 rx = self.pg1._get_capture(1)
Paul Vinciguerra3d2df212018-11-24 23:19:53 -08002138 self.assertGreater(len(rx), 0)
2139 self.assertLess(len(rx), len(pkts))
Neale Rannsd91c1db2017-07-31 02:30:50 -07002140
2141 #
Paul Vinciguerraeb414432019-02-20 09:01:14 -08002142 # remove the policer. back to full rx
Neale Rannsd91c1db2017-07-31 02:30:50 -07002143 #
2144 self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
Jakub Grajciarcd01fb42020-03-02 13:16:53 +01002145 policer.remove_vpp_config()
Neale Rannsd91c1db2017-07-31 02:30:50 -07002146 self.send_and_expect(self.pg0, pkts, self.pg1)
2147
2148 #
2149 # remove the redirect. expect full drop.
2150 #
2151 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2152 self.pg1.sw_if_index,
2153 nh_addr,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002154 is_add=0)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002155 self.send_and_assert_no_replies(self.pg0, pkts,
2156 "IP no punt config")
2157
2158 #
2159 # Add a redirect that is not input port selective
2160 #
2161 self.vapi.ip_punt_redirect(0xffffffff,
2162 self.pg1.sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002163 nh_addr)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002164 self.send_and_expect(self.pg0, pkts, self.pg1)
2165
2166 self.vapi.ip_punt_redirect(0xffffffff,
2167 self.pg1.sw_if_index,
2168 nh_addr,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002169 is_add=0)
2170
2171 def test_ip_punt_dump(self):
2172 """ IP6 punt redirect dump"""
2173
2174 #
2175 # Configure a punt redirects
2176 #
Ole Troan0bcad322018-12-11 13:04:01 +01002177 nh_addr = self.pg3.remote_ip6
Pavel Kotucek609e1212018-11-27 09:59:44 +01002178 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2179 self.pg3.sw_if_index,
2180 nh_addr)
2181 self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
2182 self.pg3.sw_if_index,
2183 nh_addr)
2184 self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
2185 self.pg3.sw_if_index,
Ole Troan0bcad322018-12-11 13:04:01 +01002186 '0::0')
Pavel Kotucek609e1212018-11-27 09:59:44 +01002187
2188 #
2189 # Dump pg0 punt redirects
2190 #
2191 punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
2192 is_ipv6=1)
2193 for p in punts:
2194 self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
2195
2196 #
2197 # Dump punt redirects for all interfaces
2198 #
2199 punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2200 self.assertEqual(len(punts), 3)
2201 for p in punts:
2202 self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
Ole Troan0bcad322018-12-11 13:04:01 +01002203 self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2204 self.assertEqual(str(punts[2].punt.nh), '::')
Neale Rannsd91c1db2017-07-31 02:30:50 -07002205
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002206
Neale Rannsce9e0b42018-08-01 12:53:17 -07002207class TestIPDeag(VppTestCase):
2208 """ IPv6 Deaggregate Routes """
2209
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002210 @classmethod
2211 def setUpClass(cls):
2212 super(TestIPDeag, cls).setUpClass()
2213
2214 @classmethod
2215 def tearDownClass(cls):
2216 super(TestIPDeag, cls).tearDownClass()
2217
Neale Rannsce9e0b42018-08-01 12:53:17 -07002218 def setUp(self):
2219 super(TestIPDeag, self).setUp()
2220
2221 self.create_pg_interfaces(range(3))
2222
2223 for i in self.pg_interfaces:
2224 i.admin_up()
2225 i.config_ip6()
2226 i.resolve_ndp()
2227
2228 def tearDown(self):
2229 super(TestIPDeag, self).tearDown()
2230 for i in self.pg_interfaces:
2231 i.unconfig_ip6()
2232 i.admin_down()
2233
2234 def test_ip_deag(self):
2235 """ IP Deag Routes """
2236
2237 #
2238 # Create a table to be used for:
2239 # 1 - another destination address lookup
2240 # 2 - a source address lookup
2241 #
2242 table_dst = VppIpTable(self, 1, is_ip6=1)
2243 table_src = VppIpTable(self, 2, is_ip6=1)
2244 table_dst.add_vpp_config()
2245 table_src.add_vpp_config()
2246
2247 #
2248 # Add a route in the default table to point to a deag/
2249 # second lookup in each of these tables
2250 #
2251 route_to_dst = VppIpRoute(self, "1::1", 128,
2252 [VppRoutePath("::",
2253 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -07002254 nh_table_id=1)])
2255 route_to_src = VppIpRoute(
2256 self, "1::2", 128,
2257 [VppRoutePath("::",
2258 0xffffffff,
2259 nh_table_id=2,
2260 type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)])
2261
Neale Rannsce9e0b42018-08-01 12:53:17 -07002262 route_to_dst.add_vpp_config()
2263 route_to_src.add_vpp_config()
2264
2265 #
2266 # packets to these destination are dropped, since they'll
2267 # hit the respective default routes in the second table
2268 #
2269 p_dst = (Ether(src=self.pg0.remote_mac,
2270 dst=self.pg0.local_mac) /
2271 IPv6(src="5::5", dst="1::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002272 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002273 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002274 p_src = (Ether(src=self.pg0.remote_mac,
2275 dst=self.pg0.local_mac) /
2276 IPv6(src="2::2", dst="1::2") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002277 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002278 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002279 pkts_dst = p_dst * 257
2280 pkts_src = p_src * 257
2281
2282 self.send_and_assert_no_replies(self.pg0, pkts_dst,
2283 "IP in dst table")
2284 self.send_and_assert_no_replies(self.pg0, pkts_src,
2285 "IP in src table")
2286
2287 #
2288 # add a route in the dst table to forward via pg1
2289 #
2290 route_in_dst = VppIpRoute(self, "1::1", 128,
2291 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002292 self.pg1.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002293 table_id=1)
2294 route_in_dst.add_vpp_config()
2295
2296 self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2297
2298 #
2299 # add a route in the src table to forward via pg2
2300 #
2301 route_in_src = VppIpRoute(self, "2::2", 128,
2302 [VppRoutePath(self.pg2.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -07002303 self.pg2.sw_if_index)],
Neale Rannsce9e0b42018-08-01 12:53:17 -07002304 table_id=2)
2305 route_in_src.add_vpp_config()
2306 self.send_and_expect(self.pg0, pkts_src, self.pg2)
2307
2308 #
2309 # loop in the lookup DP
2310 #
2311 route_loop = VppIpRoute(self, "3::3", 128,
2312 [VppRoutePath("::",
Neale Ranns097fa662018-05-01 05:17:55 -07002313 0xffffffff)])
Neale Rannsce9e0b42018-08-01 12:53:17 -07002314 route_loop.add_vpp_config()
2315
2316 p_l = (Ether(src=self.pg0.remote_mac,
2317 dst=self.pg0.local_mac) /
2318 IPv6(src="3::4", dst="3::3") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002319 inet6.TCP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002320 Raw(b'\xa5' * 100))
Neale Rannsce9e0b42018-08-01 12:53:17 -07002321
2322 self.send_and_assert_no_replies(self.pg0, p_l * 257,
2323 "IP lookup loop")
2324
2325
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002326class TestIP6Input(VppTestCase):
Neale Rannsae809832018-11-23 09:00:27 -08002327 """ IPv6 Input Exception Test Cases """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002328
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002329 @classmethod
2330 def setUpClass(cls):
2331 super(TestIP6Input, cls).setUpClass()
2332
2333 @classmethod
2334 def tearDownClass(cls):
2335 super(TestIP6Input, cls).tearDownClass()
2336
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002337 def setUp(self):
2338 super(TestIP6Input, self).setUp()
2339
2340 self.create_pg_interfaces(range(2))
2341
2342 for i in self.pg_interfaces:
2343 i.admin_up()
2344 i.config_ip6()
2345 i.resolve_ndp()
2346
2347 def tearDown(self):
2348 super(TestIP6Input, self).tearDown()
2349 for i in self.pg_interfaces:
2350 i.unconfig_ip6()
2351 i.admin_down()
2352
Neale Rannsae809832018-11-23 09:00:27 -08002353 def test_ip_input_icmp_reply(self):
2354 """ IP6 Input Exception - Return ICMP (3,0) """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002355 #
Neale Rannsae809832018-11-23 09:00:27 -08002356 # hop limit - ICMP replies
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002357 #
2358 p_version = (Ether(src=self.pg0.remote_mac,
2359 dst=self.pg0.local_mac) /
2360 IPv6(src=self.pg0.remote_ip6,
2361 dst=self.pg1.remote_ip6,
2362 hlim=1) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002363 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002364 Raw(b'\xa5' * 100))
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002365
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002366 rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002367 rx = rx[0]
2368 icmp = rx[ICMPv6TimeExceeded]
Neale Rannsae809832018-11-23 09:00:27 -08002369
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002370 # 0: "hop limit exceeded in transit",
Neale Rannsae809832018-11-23 09:00:27 -08002371 self.assertEqual((icmp.type, icmp.code), (3, 0))
2372
2373 icmpv6_data = '\x0a' * 18
2374 all_0s = "::"
2375 all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2376
2377 @parameterized.expand([
2378 # Name, src, dst, l4proto, msg, timeout
2379 ("src='iface', dst='iface'", None, None,
2380 inet6.UDP(sport=1234, dport=1234), "funky version", None),
2381 ("src='All 0's', dst='iface'", all_0s, None,
2382 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2383 ("src='iface', dst='All 0's'", None, all_0s,
2384 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2385 ("src='All 1's', dst='iface'", all_1s, None,
2386 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2387 ("src='iface', dst='All 1's'", None, all_1s,
2388 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2389 ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2390 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2391
2392 ])
2393 def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2394
2395 self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2396
2397 p_version = (Ether(src=self.pg0.remote_mac,
2398 dst=self.pg0.local_mac) /
2399 IPv6(src=src or self.pg0.remote_ip6,
2400 dst=dst or self.pg1.remote_ip6,
2401 version=3) /
2402 l4 /
Ole Troan770a0de2019-11-07 13:52:21 +01002403 Raw(b'\xa5' * 100))
Neale Rannsae809832018-11-23 09:00:27 -08002404
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002405 self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS,
Neale Rannsae809832018-11-23 09:00:27 -08002406 remark=msg or "",
2407 timeout=timeout)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002408
Dave Barach90800962019-05-24 13:03:01 -04002409 def test_hop_by_hop(self):
2410 """ Hop-by-hop header test """
2411
2412 p = (Ether(src=self.pg0.remote_mac,
2413 dst=self.pg0.local_mac) /
2414 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
2415 IPv6ExtHdrHopByHop() /
2416 inet6.UDP(sport=1234, dport=1234) /
Ole Troan770a0de2019-11-07 13:52:21 +01002417 Raw(b'\xa5' * 100))
Dave Barach90800962019-05-24 13:03:01 -04002418
2419 self.pg0.add_stream(p)
2420 self.pg_enable_capture(self.pg_interfaces)
2421 self.pg_start()
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002422
Neale Ranns9db6ada2019-11-08 12:42:31 +00002423
2424class TestIPReplace(VppTestCase):
2425 """ IPv6 Table Replace """
2426
2427 @classmethod
2428 def setUpClass(cls):
2429 super(TestIPReplace, cls).setUpClass()
2430
2431 @classmethod
2432 def tearDownClass(cls):
2433 super(TestIPReplace, cls).tearDownClass()
2434
2435 def setUp(self):
2436 super(TestIPReplace, self).setUp()
2437
2438 self.create_pg_interfaces(range(4))
2439
2440 table_id = 1
2441 self.tables = []
2442
2443 for i in self.pg_interfaces:
2444 i.admin_up()
2445 i.config_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002446 i.generate_remote_hosts(2)
2447 self.tables.append(VppIpTable(self, table_id,
2448 True).add_vpp_config())
2449 table_id += 1
2450
2451 def tearDown(self):
2452 super(TestIPReplace, self).tearDown()
2453 for i in self.pg_interfaces:
2454 i.admin_down()
Neale Rannsec40a7d2020-04-23 07:36:12 +00002455 i.unconfig_ip6()
Neale Ranns9db6ada2019-11-08 12:42:31 +00002456
2457 def test_replace(self):
2458 """ IP Table Replace """
2459
2460 N_ROUTES = 20
2461 links = [self.pg0, self.pg1, self.pg2, self.pg3]
2462 routes = [[], [], [], []]
2463
2464 # the sizes of 'empty' tables
2465 for t in self.tables:
2466 self.assertEqual(len(t.dump()), 2)
2467 self.assertEqual(len(t.mdump()), 5)
2468
2469 # load up the tables with some routes
2470 for ii, t in enumerate(self.tables):
2471 for jj in range(1, N_ROUTES):
2472 uni = VppIpRoute(
2473 self, "2001::%d" % jj if jj != 0 else "2001::", 128,
2474 [VppRoutePath(links[ii].remote_hosts[0].ip6,
2475 links[ii].sw_if_index),
2476 VppRoutePath(links[ii].remote_hosts[1].ip6,
2477 links[ii].sw_if_index)],
2478 table_id=t.table_id).add_vpp_config()
2479 multi = VppIpMRoute(
2480 self, "::",
2481 "ff:2001::%d" % jj, 128,
2482 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
2483 [VppMRoutePath(self.pg0.sw_if_index,
2484 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
2485 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2486 VppMRoutePath(self.pg1.sw_if_index,
2487 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2488 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2489 VppMRoutePath(self.pg2.sw_if_index,
2490 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2491 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
2492 VppMRoutePath(self.pg3.sw_if_index,
2493 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
2494 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
2495 table_id=t.table_id).add_vpp_config()
2496 routes[ii].append({'uni': uni,
2497 'multi': multi})
2498
2499 #
2500 # replace the tables a few times
2501 #
2502 for kk in range(3):
2503 # replace each table
2504 for t in self.tables:
2505 t.replace_begin()
2506
2507 # all the routes are still there
2508 for ii, t in enumerate(self.tables):
2509 dump = t.dump()
2510 mdump = t.mdump()
2511 for r in routes[ii]:
2512 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2513 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2514
2515 # redownload the even numbered routes
2516 for ii, t in enumerate(self.tables):
2517 for jj in range(0, N_ROUTES, 2):
2518 routes[ii][jj]['uni'].add_vpp_config()
2519 routes[ii][jj]['multi'].add_vpp_config()
2520
2521 # signal each table converged
2522 for t in self.tables:
2523 t.replace_end()
2524
2525 # we should find the even routes, but not the odd
2526 for ii, t in enumerate(self.tables):
2527 dump = t.dump()
2528 mdump = t.mdump()
2529 for jj in range(0, N_ROUTES, 2):
2530 self.assertTrue(find_route_in_dump(
2531 dump, routes[ii][jj]['uni'], t))
2532 self.assertTrue(find_mroute_in_dump(
2533 mdump, routes[ii][jj]['multi'], t))
2534 for jj in range(1, N_ROUTES - 1, 2):
2535 self.assertFalse(find_route_in_dump(
2536 dump, routes[ii][jj]['uni'], t))
2537 self.assertFalse(find_mroute_in_dump(
2538 mdump, routes[ii][jj]['multi'], t))
2539
2540 # reload all the routes
2541 for ii, t in enumerate(self.tables):
2542 for r in routes[ii]:
2543 r['uni'].add_vpp_config()
2544 r['multi'].add_vpp_config()
2545
2546 # all the routes are still there
2547 for ii, t in enumerate(self.tables):
2548 dump = t.dump()
2549 mdump = t.mdump()
2550 for r in routes[ii]:
2551 self.assertTrue(find_route_in_dump(dump, r['uni'], t))
2552 self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t))
2553
2554 #
2555 # finally flush the tables for good measure
2556 #
2557 for t in self.tables:
2558 t.flush()
2559 self.assertEqual(len(t.dump()), 2)
2560 self.assertEqual(len(t.mdump()), 5)
2561
2562
Neale Ranns59f71132020-04-08 12:19:38 +00002563class TestIP6Replace(VppTestCase):
2564 """ IPv4 Interface Address Replace """
2565
2566 @classmethod
2567 def setUpClass(cls):
2568 super(TestIP6Replace, cls).setUpClass()
2569
2570 @classmethod
2571 def tearDownClass(cls):
2572 super(TestIP6Replace, cls).tearDownClass()
2573
2574 def setUp(self):
2575 super(TestIP6Replace, self).setUp()
2576
2577 self.create_pg_interfaces(range(4))
2578
2579 for i in self.pg_interfaces:
2580 i.admin_up()
2581
2582 def tearDown(self):
2583 super(TestIP6Replace, self).tearDown()
2584 for i in self.pg_interfaces:
2585 i.admin_down()
2586
2587 def get_n_pfxs(self, intf):
2588 return len(self.vapi.ip_address_dump(intf.sw_if_index, True))
2589
2590 def test_replace(self):
2591 """ IP interface address replace """
2592
2593 intf_pfxs = [[], [], [], []]
2594
2595 # add prefixes to each of the interfaces
2596 for i in range(len(self.pg_interfaces)):
2597 intf = self.pg_interfaces[i]
2598
2599 # 2001:16:x::1/64
2600 addr = "2001:16:%d::1" % intf.sw_if_index
2601 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2602 intf_pfxs[i].append(a)
2603
2604 # 2001:16:x::2/64 - a different address in the same subnet as above
2605 addr = "2001:16:%d::2" % intf.sw_if_index
2606 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2607 intf_pfxs[i].append(a)
2608
2609 # 2001:15:x::2/64 - a different address and subnet
2610 addr = "2001:15:%d::2" % intf.sw_if_index
2611 a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2612 intf_pfxs[i].append(a)
2613
2614 # a dump should n_address in it
2615 for intf in self.pg_interfaces:
2616 self.assertEqual(self.get_n_pfxs(intf), 3)
2617
2618 #
2619 # remove all the address thru a replace
2620 #
2621 self.vapi.sw_interface_address_replace_begin()
2622 self.vapi.sw_interface_address_replace_end()
2623 for intf in self.pg_interfaces:
2624 self.assertEqual(self.get_n_pfxs(intf), 0)
2625
2626 #
2627 # add all the interface addresses back
2628 #
2629 for p in intf_pfxs:
2630 for v in p:
2631 v.add_vpp_config()
2632 for intf in self.pg_interfaces:
2633 self.assertEqual(self.get_n_pfxs(intf), 3)
2634
2635 #
2636 # replace again, but this time update/re-add the address on the first
2637 # two interfaces
2638 #
2639 self.vapi.sw_interface_address_replace_begin()
2640
2641 for p in intf_pfxs[:2]:
2642 for v in p:
2643 v.add_vpp_config()
2644
2645 self.vapi.sw_interface_address_replace_end()
2646
2647 # on the first two the address still exist,
2648 # on the other two they do not
2649 for intf in self.pg_interfaces[:2]:
2650 self.assertEqual(self.get_n_pfxs(intf), 3)
2651 for p in intf_pfxs[:2]:
2652 for v in p:
2653 self.assertTrue(v.query_vpp_config())
2654 for intf in self.pg_interfaces[2:]:
2655 self.assertEqual(self.get_n_pfxs(intf), 0)
2656
2657 #
2658 # add all the interface addresses back on the last two
2659 #
2660 for p in intf_pfxs[2:]:
2661 for v in p:
2662 v.add_vpp_config()
2663 for intf in self.pg_interfaces:
2664 self.assertEqual(self.get_n_pfxs(intf), 3)
2665
2666 #
2667 # replace again, this time add different prefixes on all the interfaces
2668 #
2669 self.vapi.sw_interface_address_replace_begin()
2670
2671 pfxs = []
2672 for intf in self.pg_interfaces:
2673 # 2001:18:x::1/64
2674 addr = "2001:18:%d::1" % intf.sw_if_index
2675 pfxs.append(VppIpInterfaceAddress(self, intf, addr,
2676 64).add_vpp_config())
2677
2678 self.vapi.sw_interface_address_replace_end()
2679
2680 # only .18 should exist on each interface
2681 for intf in self.pg_interfaces:
2682 self.assertEqual(self.get_n_pfxs(intf), 1)
2683 for pfx in pfxs:
2684 self.assertTrue(pfx.query_vpp_config())
2685
2686 #
2687 # remove everything
2688 #
2689 self.vapi.sw_interface_address_replace_begin()
2690 self.vapi.sw_interface_address_replace_end()
2691 for intf in self.pg_interfaces:
2692 self.assertEqual(self.get_n_pfxs(intf), 0)
2693
2694 #
2695 # add prefixes to each interface. post-begin add the prefix from
2696 # interface X onto interface Y. this would normally be an error
2697 # since it would generate a 'duplicate address' warning. but in
2698 # this case, since what is newly downloaded is sane, it's ok
2699 #
2700 for intf in self.pg_interfaces:
2701 # 2001:18:x::1/64
2702 addr = "2001:18:%d::1" % intf.sw_if_index
2703 VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()
2704
2705 self.vapi.sw_interface_address_replace_begin()
2706
2707 pfxs = []
2708 for intf in self.pg_interfaces:
2709 # 2001:18:x::1/64
2710 addr = "2001:18:%d::1" % (intf.sw_if_index + 1)
2711 pfxs.append(VppIpInterfaceAddress(self, intf,
2712 addr, 64).add_vpp_config())
2713
2714 self.vapi.sw_interface_address_replace_end()
2715
2716 self.logger.info(self.vapi.cli("sh int addr"))
2717
2718 for intf in self.pg_interfaces:
2719 self.assertEqual(self.get_n_pfxs(intf), 1)
2720 for pfx in pfxs:
2721 self.assertTrue(pfx.query_vpp_config())
2722
2723
Neale Rannsec40a7d2020-04-23 07:36:12 +00002724class TestIP6LinkLocal(VppTestCase):
2725 """ IPv6 Link Local """
2726
2727 @classmethod
2728 def setUpClass(cls):
2729 super(TestIP6LinkLocal, cls).setUpClass()
2730
2731 @classmethod
2732 def tearDownClass(cls):
2733 super(TestIP6LinkLocal, cls).tearDownClass()
2734
2735 def setUp(self):
2736 super(TestIP6LinkLocal, self).setUp()
2737
2738 self.create_pg_interfaces(range(2))
2739
2740 for i in self.pg_interfaces:
2741 i.admin_up()
2742
2743 def tearDown(self):
2744 super(TestIP6LinkLocal, self).tearDown()
2745 for i in self.pg_interfaces:
2746 i.admin_down()
2747
2748 def test_ip6_ll(self):
2749 """ IPv6 Link Local """
2750
2751 #
2752 # two APIs to add a link local address.
2753 # 1 - just like any other prefix
2754 # 2 - with the special set LL API
2755 #
2756
2757 #
2758 # First with the API to set a 'normal' prefix
2759 #
2760 ll1 = "fe80:1::1"
2761 ll2 = "fe80:2::2"
2762 ll3 = "fe80:3::3"
2763
2764 VppIpInterfaceAddress(self, self.pg0, ll1, 128).add_vpp_config()
2765
2766 #
2767 # should be able to ping the ll
2768 #
2769 p_echo_request_1 = (Ether(src=self.pg0.remote_mac,
2770 dst=self.pg0.local_mac) /
2771 IPv6(src=ll2,
2772 dst=ll1) /
2773 ICMPv6EchoRequest())
2774
2775 self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0)
2776
2777 #
2778 # change the link-local on pg0
2779 #
2780 v_ll3 = VppIpInterfaceAddress(self, self.pg0,
2781 ll3, 128).add_vpp_config()
2782
2783 p_echo_request_3 = (Ether(src=self.pg0.remote_mac,
2784 dst=self.pg0.local_mac) /
2785 IPv6(src=ll2,
2786 dst=ll3) /
2787 ICMPv6EchoRequest())
2788
2789 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
2790
2791 #
2792 # set a normal v6 prefix on the link
2793 #
2794 self.pg0.config_ip6()
2795
2796 self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0)
2797
2798 # the link-local cannot be removed
2799 with self.vapi.assert_negative_api_retval():
2800 v_ll3.remove_vpp_config()
2801
2802 #
2803 # Use the specific link-local API on pg1
2804 #
2805 VppIp6LinkLocalAddress(self, self.pg1, ll1).add_vpp_config()
2806 self.send_and_expect(self.pg1, [p_echo_request_1], self.pg1)
2807
2808 VppIp6LinkLocalAddress(self, self.pg1, ll3).add_vpp_config()
2809 self.send_and_expect(self.pg1, [p_echo_request_3], self.pg1)
2810
2811
Damjan Marionf56b77a2016-10-03 19:44:57 +02002812if __name__ == '__main__':
Klement Sekeraf62ae122016-10-11 11:47:09 +02002813 unittest.main(testRunner=VppTestRunner)