blob: 930d556a876a94809d5ebb2c7275be1a12a87b75 [file] [log] [blame]
Damjan Marionf56b77a2016-10-03 19:44:57 +02001#!/usr/bin/env python
2
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01003import socket
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -08004import unittest
5
Neale Rannsae809832018-11-23 09:00:27 -08006from parameterized import parameterized
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -08007import scapy.layers.inet6 as inet6
8from scapy.contrib.mpls import MPLS
9from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \
10 ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
11 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
12 ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply
13from scapy.layers.l2 import Ether, Dot1Q
14from scapy.packet import Raw
15from scapy.utils import inet_pton, inet_ntop
16from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
17 in6_mactoifaceid
18from six import moves
Klement Sekeraf62ae122016-10-11 11:47:09 +020019
Damjan Marionf56b77a2016-10-03 19:44:57 +020020from framework import VppTestCase, VppTestRunner
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010021from util import ppp, ip6_normalize
Neale Rannsc0a93142018-09-05 15:42:26 -070022from vpp_ip import DpoProto
Neale Ranns180279b2017-03-16 15:49:09 -040023from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
Neale Ranns71275e32017-05-25 12:38:58 -070024 VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
Ole Troan0bcad322018-12-11 13:04:01 +010025 VppMplsRoute, VppMplsTable, VppIpTable
Neale Rannsb3b2de72017-03-08 05:17:22 -080026from vpp_neighbor import find_nbr, VppNeighbor
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -080027from vpp_pg_interface import is_ipv6_misc
28from vpp_sub_interface import VppSubInterface, VppDot1QSubint
Neale Ranns75152282017-01-09 01:00:45 -080029
Juraj Sloboda4b9669d2018-01-15 10:39:21 +010030AF_INET6 = socket.AF_INET6
31
32
Neale Ranns75152282017-01-09 01:00:45 -080033def mk_ll_addr(mac):
34 euid = in6_mactoifaceid(mac)
35 addr = "fe80::" + euid
36 return addr
Damjan Marionf56b77a2016-10-03 19:44:57 +020037
38
Neale Ranns3f844d02017-02-18 00:03:54 -080039class TestIPv6ND(VppTestCase):
40 def validate_ra(self, intf, rx, dst_ip=None):
41 if not dst_ip:
42 dst_ip = intf.remote_ip6
43
44 # unicasted packets must come to the unicast mac
45 self.assertEqual(rx[Ether].dst, intf.remote_mac)
46
47 # and from the router's MAC
48 self.assertEqual(rx[Ether].src, intf.local_mac)
49
50 # the rx'd RA should be addressed to the sender's source
51 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
52 self.assertEqual(in6_ptop(rx[IPv6].dst),
53 in6_ptop(dst_ip))
54
55 # and come from the router's link local
56 self.assertTrue(in6_islladdr(rx[IPv6].src))
57 self.assertEqual(in6_ptop(rx[IPv6].src),
58 in6_ptop(mk_ll_addr(intf.local_mac)))
59
60 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
61 if not dst_ip:
62 dst_ip = intf.remote_ip6
63 if not tgt_ip:
64 dst_ip = intf.local_ip6
65
66 # unicasted packets must come to the unicast mac
67 self.assertEqual(rx[Ether].dst, intf.remote_mac)
68
69 # and from the router's MAC
70 self.assertEqual(rx[Ether].src, intf.local_mac)
71
72 # the rx'd NA should be addressed to the sender's source
73 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
74 self.assertEqual(in6_ptop(rx[IPv6].dst),
75 in6_ptop(dst_ip))
76
77 # and come from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -080078 self.assertEqual(
79 in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
Neale Ranns3f844d02017-02-18 00:03:54 -080080
81 # Dest link-layer options should have the router's MAC
82 dll = rx[ICMPv6NDOptDstLLAddr]
83 self.assertEqual(dll.lladdr, intf.local_mac)
84
Neale Rannsdcd6d622017-05-26 02:59:16 -070085 def validate_ns(self, intf, rx, tgt_ip):
86 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
87 dst_ip = inet_ntop(AF_INET6, nsma)
88
89 # NS is broadcast
Neale Rannsc7b8f202018-04-25 06:34:31 -070090 self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma))
Neale Rannsdcd6d622017-05-26 02:59:16 -070091
92 # and from the router's MAC
93 self.assertEqual(rx[Ether].src, intf.local_mac)
94
95 # the rx'd NS should be addressed to an mcast address
96 # derived from the target address
Paul Vinciguerra978aa642018-11-24 22:19:12 -080097 self.assertEqual(
98 in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
Neale Rannsdcd6d622017-05-26 02:59:16 -070099
100 # expect the tgt IP in the NS header
101 ns = rx[ICMPv6ND_NS]
102 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
103
104 # packet is from the router's local address
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800105 self.assertEqual(
106 in6_ptop(rx[IPv6].src), intf.local_ip6)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700107
108 # Src link-layer options should have the router's MAC
109 sll = rx[ICMPv6NDOptSrcLLAddr]
110 self.assertEqual(sll.lladdr, intf.local_mac)
111
Neale Ranns3f844d02017-02-18 00:03:54 -0800112 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
113 filter_out_fn=is_ipv6_misc):
114 intf.add_stream(pkts)
Neale Ranns3f844d02017-02-18 00:03:54 -0800115 self.pg_enable_capture(self.pg_interfaces)
116 self.pg_start()
117 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
118
119 self.assertEqual(len(rx), 1)
120 rx = rx[0]
121 self.validate_ra(intf, rx, dst_ip)
122
Neale Ranns2a3ea492017-04-19 05:24:40 -0700123 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
124 tgt_ip=None,
125 filter_out_fn=is_ipv6_misc):
126 intf.add_stream(pkts)
127 self.pg_enable_capture(self.pg_interfaces)
128 self.pg_start()
129 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
130
131 self.assertEqual(len(rx), 1)
132 rx = rx[0]
133 self.validate_na(intf, rx, dst_ip, tgt_ip)
134
Neale Rannsdcd6d622017-05-26 02:59:16 -0700135 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
136 filter_out_fn=is_ipv6_misc):
137 tx_intf.add_stream(pkts)
138 self.pg_enable_capture(self.pg_interfaces)
139 self.pg_start()
140 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
141
142 self.assertEqual(len(rx), 1)
143 rx = rx[0]
144 self.validate_ns(rx_intf, rx, tgt_ip)
145
Neale Rannsdcd6d622017-05-26 02:59:16 -0700146 def verify_ip(self, rx, smac, dmac, sip, dip):
147 ether = rx[Ether]
148 self.assertEqual(ether.dst, dmac)
149 self.assertEqual(ether.src, smac)
150
151 ip = rx[IPv6]
152 self.assertEqual(ip.src, sip)
153 self.assertEqual(ip.dst, dip)
154
Neale Ranns3f844d02017-02-18 00:03:54 -0800155
156class TestIPv6(TestIPv6ND):
Damjan Marionf56b77a2016-10-03 19:44:57 +0200157 """ IPv6 Test Case """
158
159 @classmethod
160 def setUpClass(cls):
161 super(TestIPv6, cls).setUpClass()
162
Klement Sekeraf62ae122016-10-11 11:47:09 +0200163 def setUp(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100164 """
165 Perform test setup before test case.
166
167 **Config:**
168 - create 3 pg interfaces
169 - untagged pg0 interface
170 - Dot1Q subinterface on pg1
171 - Dot1AD subinterface on pg2
172 - setup interfaces:
173 - put it into UP state
174 - set IPv6 addresses
175 - resolve neighbor address using NDP
176 - configure 200 fib entries
177
178 :ivar list interfaces: pg interfaces and subinterfaces.
179 :ivar dict flows: IPv4 packet flows in test.
Matej Klotton86d87c42016-11-11 11:38:55 +0100180
181 *TODO:* Create AD sub interface
182 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200183 super(TestIPv6, self).setUp()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200184
Klement Sekeraf62ae122016-10-11 11:47:09 +0200185 # create 3 pg interfaces
186 self.create_pg_interfaces(range(3))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200187
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188 # create 2 subinterfaces for p1 and pg2
189 self.sub_interfaces = [
190 VppDot1QSubint(self, self.pg1, 100),
Matej Klotton86d87c42016-11-11 11:38:55 +0100191 VppDot1QSubint(self, self.pg2, 200)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200192 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
Matej Klotton86d87c42016-11-11 11:38:55 +0100193 ]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200194
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
196 self.flows = dict()
197 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
198 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
199 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200200
Klement Sekeraf62ae122016-10-11 11:47:09 +0200201 # packet sizes
Jan Geletye6c78ee2018-06-26 12:24:03 +0200202 self.pg_if_packet_sizes = [64, 1500, 9020]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200203
Klement Sekeraf62ae122016-10-11 11:47:09 +0200204 self.interfaces = list(self.pg_interfaces)
205 self.interfaces.extend(self.sub_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207 # setup all interfaces
208 for i in self.interfaces:
209 i.admin_up()
210 i.config_ip6()
211 i.resolve_ndp()
212
Matej Klotton86d87c42016-11-11 11:38:55 +0100213 # config 2M FIB entries
Klement Sekeraf62ae122016-10-11 11:47:09 +0200214 self.config_fib_entries(200)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200215
216 def tearDown(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100217 """Run standard test teardown and log ``show ip6 neighbors``."""
Neale Ranns744902e2017-08-14 10:35:44 -0700218 for i in self.interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800219 i.unconfig_ip6()
220 i.ip6_disable()
221 i.admin_down()
Neale Ranns744902e2017-08-14 10:35:44 -0700222 for i in self.sub_interfaces:
Neale Ranns75152282017-01-09 01:00:45 -0800223 i.remove_vpp_config()
224
Klement Sekeraf62ae122016-10-11 11:47:09 +0200225 super(TestIPv6, self).tearDown()
226 if not self.vpp_dead:
Matej Klotton86d87c42016-11-11 11:38:55 +0100227 self.logger.info(self.vapi.cli("show ip6 neighbors"))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200228 # info(self.vapi.cli("show ip6 fib")) # many entries
Damjan Marionf56b77a2016-10-03 19:44:57 +0200229
Klement Sekeraf62ae122016-10-11 11:47:09 +0200230 def config_fib_entries(self, count):
Matej Klotton86d87c42016-11-11 11:38:55 +0100231 """For each interface add to the FIB table *count* routes to
232 "fd02::1/128" destination with interface's local address as next-hop
233 address.
234
235 :param int count: Number of FIB entries.
236
237 - *TODO:* check if the next-hop address shouldn't be remote address
238 instead of local address.
239 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200240 n_int = len(self.interfaces)
241 percent = 0
242 counter = 0.0
Neale Ranns3f844d02017-02-18 00:03:54 -0800243 dest_addr = inet_pton(AF_INET6, "fd02::1")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200244 dest_addr_len = 128
245 for i in self.interfaces:
246 next_hop_address = i.local_ip6n
247 for j in range(count / n_int):
248 self.vapi.ip_add_del_route(
249 dest_addr, dest_addr_len, next_hop_address, is_ipv6=1)
Matej Klotton86d87c42016-11-11 11:38:55 +0100250 counter += 1
Klement Sekeraf62ae122016-10-11 11:47:09 +0200251 if counter / count * 100 > percent:
Matej Klotton86d87c42016-11-11 11:38:55 +0100252 self.logger.info("Configure %d FIB entries .. %d%% done" %
Klement Sekera7bb873a2016-11-18 07:38:42 +0100253 (count, percent))
Matej Klotton86d87c42016-11-11 11:38:55 +0100254 percent += 1
Damjan Marionf56b77a2016-10-03 19:44:57 +0200255
Jan Geletye6c78ee2018-06-26 12:24:03 +0200256 def modify_packet(self, src_if, packet_size, pkt):
257 """Add load, set destination IP and extend packet to required packet
258 size for defined interface.
259
260 :param VppInterface src_if: Interface to create packet for.
261 :param int packet_size: Required packet size.
262 :param Scapy pkt: Packet to be modified.
263 """
264 dst_if_idx = packet_size / 10 % 2
265 dst_if = self.flows[src_if][dst_if_idx]
266 info = self.create_packet_info(src_if, dst_if)
267 payload = self.info_to_payload(info)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800268 p = pkt / Raw(payload)
Jan Geletye6c78ee2018-06-26 12:24:03 +0200269 p[IPv6].dst = dst_if.remote_ip6
270 info.data = p.copy()
271 if isinstance(src_if, VppSubInterface):
272 p = src_if.add_dot1_layer(p)
273 self.extend_packet(p, packet_size)
274
275 return p
276
277 def create_stream(self, src_if):
Matej Klotton86d87c42016-11-11 11:38:55 +0100278 """Create input packet stream for defined interface.
279
280 :param VppInterface src_if: Interface to create packet stream for.
Matej Klotton86d87c42016-11-11 11:38:55 +0100281 """
Jan Geletye6c78ee2018-06-26 12:24:03 +0200282 hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0
283 pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
284 IPv6(src=src_if.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800285 inet6.UDP(sport=1234, dport=1234))
Jan Geletye6c78ee2018-06-26 12:24:03 +0200286
287 pkts = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800288 for i in moves.range(self.pg_if_packet_sizes[0],
289 self.pg_if_packet_sizes[1], 10)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200290 pkts_b = [self.modify_packet(src_if, i, pkt_tmpl)
Paul Vinciguerraa6fe4632018-11-25 11:21:50 -0800291 for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext,
292 self.pg_if_packet_sizes[2] + hdr_ext,
293 50)]
Jan Geletye6c78ee2018-06-26 12:24:03 +0200294 pkts.extend(pkts_b)
295
Damjan Marionf56b77a2016-10-03 19:44:57 +0200296 return pkts
297
Klement Sekeraf62ae122016-10-11 11:47:09 +0200298 def verify_capture(self, dst_if, capture):
Matej Klotton86d87c42016-11-11 11:38:55 +0100299 """Verify captured input packet stream for defined interface.
300
301 :param VppInterface dst_if: Interface to verify captured packet stream
302 for.
303 :param list capture: Captured packet stream.
304 """
305 self.logger.info("Verifying capture on interface %s" % dst_if.name)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200306 last_info = dict()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200307 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200308 last_info[i.sw_if_index] = None
309 is_sub_if = False
310 dst_sw_if_index = dst_if.sw_if_index
311 if hasattr(dst_if, 'parent'):
312 is_sub_if = True
Damjan Marionf56b77a2016-10-03 19:44:57 +0200313 for packet in capture:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200314 if is_sub_if:
315 # Check VLAN tags and Ethernet header
316 packet = dst_if.remove_dot1_layer(packet)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200317 self.assertTrue(Dot1Q not in packet)
318 try:
319 ip = packet[IPv6]
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800320 udp = packet[inet6.UDP]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200321 payload_info = self.payload_to_info(str(packet[Raw]))
322 packet_index = payload_info.index
Klement Sekeraf62ae122016-10-11 11:47:09 +0200323 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerada505f62017-01-04 12:58:53 +0100324 self.logger.debug(
325 "Got packet on port %s: src=%u (id=%u)" %
326 (dst_if.name, payload_info.src, packet_index))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200327 next_info = self.get_next_packet_info_for_interface2(
328 payload_info.src, dst_sw_if_index,
329 last_info[payload_info.src])
330 last_info[payload_info.src] = next_info
Damjan Marionf56b77a2016-10-03 19:44:57 +0200331 self.assertTrue(next_info is not None)
332 self.assertEqual(packet_index, next_info.index)
333 saved_packet = next_info.data
334 # Check standard fields
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800335 self.assertEqual(
336 ip.src, saved_packet[IPv6].src)
337 self.assertEqual(
338 ip.dst, saved_packet[IPv6].dst)
339 self.assertEqual(
340 udp.sport, saved_packet[inet6.UDP].sport)
341 self.assertEqual(
342 udp.dport, saved_packet[inet6.UDP].dport)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200343 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100344 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200345 raise
346 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200347 remaining_packet = self.get_next_packet_info_for_interface2(
348 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
Klement Sekera7bb873a2016-11-18 07:38:42 +0100349 self.assertTrue(remaining_packet is None,
350 "Interface %s: Packet expected from interface %s "
351 "didn't arrive" % (dst_if.name, i.name))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200352
353 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,
448 af=AF_INET6,
449 is_no_fib_entry=1)
450 nd_entry.add_vpp_config()
451
452 #
453 # check we have the neighbor, but no route
454 #
455 self.assertTrue(find_nbr(self,
456 self.pg0.sw_if_index,
457 self.pg0._remote_hosts[2].ip6,
458 inet=AF_INET6))
459 self.assertFalse(find_route(self,
460 self.pg0._remote_hosts[2].ip6,
461 128,
462 inet=AF_INET6))
463
Neale Ranns2a3ea492017-04-19 05:24:40 -0700464 #
465 # send an NS from a link local address to the interface's global
466 # address
467 #
468 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800469 IPv6(
470 dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700471 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800472 ICMPv6NDOptSrcLLAddr(
473 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700474
475 self.send_and_expect_na(self.pg0, p,
476 "NS from link-local",
477 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
478 tgt_ip=self.pg0.local_ip6)
479
480 #
481 # we should have learned an ND entry for the peer's link-local
482 # but not inserted a route to it in the FIB
483 #
484 self.assertTrue(find_nbr(self,
485 self.pg0.sw_if_index,
486 self.pg0._remote_hosts[2].ip6_ll,
487 inet=AF_INET6))
488 self.assertFalse(find_route(self,
489 self.pg0._remote_hosts[2].ip6_ll,
490 128,
491 inet=AF_INET6))
492
493 #
494 # An NS to the router's own Link-local
495 #
496 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800497 IPv6(
498 dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
Neale Ranns2a3ea492017-04-19 05:24:40 -0700499 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800500 ICMPv6NDOptSrcLLAddr(
501 lladdr=self.pg0.remote_mac))
Neale Ranns2a3ea492017-04-19 05:24:40 -0700502
503 self.send_and_expect_na(self.pg0, p,
504 "NS to/from link-local",
505 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
506 tgt_ip=self.pg0.local_ip6_ll)
507
508 #
509 # we should have learned an ND entry for the peer's link-local
510 # but not inserted a route to it in the FIB
511 #
512 self.assertTrue(find_nbr(self,
513 self.pg0.sw_if_index,
514 self.pg0._remote_hosts[3].ip6_ll,
515 inet=AF_INET6))
516 self.assertFalse(find_route(self,
517 self.pg0._remote_hosts[3].ip6_ll,
518 128,
519 inet=AF_INET6))
520
Neale Rannsdcd6d622017-05-26 02:59:16 -0700521 def test_ns_duplicates(self):
Neale Rannsda78f952017-05-24 09:15:43 -0700522 """ ND Duplicates"""
Neale Rannsdcd6d622017-05-26 02:59:16 -0700523
524 #
525 # Generate some hosts on the LAN
526 #
527 self.pg1.generate_remote_hosts(3)
528
529 #
530 # Add host 1 on pg1 and pg2
531 #
532 ns_pg1 = VppNeighbor(self,
533 self.pg1.sw_if_index,
534 self.pg1.remote_hosts[1].mac,
535 self.pg1.remote_hosts[1].ip6,
536 af=AF_INET6)
537 ns_pg1.add_vpp_config()
538 ns_pg2 = VppNeighbor(self,
539 self.pg2.sw_if_index,
540 self.pg2.remote_mac,
541 self.pg1.remote_hosts[1].ip6,
542 af=AF_INET6)
543 ns_pg2.add_vpp_config()
544
545 #
546 # IP packet destined for pg1 remote host arrives on pg1 again.
547 #
548 p = (Ether(dst=self.pg0.local_mac,
549 src=self.pg0.remote_mac) /
550 IPv6(src=self.pg0.remote_ip6,
551 dst=self.pg1.remote_hosts[1].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800552 inet6.UDP(sport=1234, dport=1234) /
Neale Rannsdcd6d622017-05-26 02:59:16 -0700553 Raw())
554
555 self.pg0.add_stream(p)
556 self.pg_enable_capture(self.pg_interfaces)
557 self.pg_start()
558
559 rx1 = self.pg1.get_capture(1)
560
561 self.verify_ip(rx1[0],
562 self.pg1.local_mac,
563 self.pg1.remote_hosts[1].mac,
564 self.pg0.remote_ip6,
565 self.pg1.remote_hosts[1].ip6)
566
567 #
568 # remove the duplicate on pg1
Neale Rannsda78f952017-05-24 09:15:43 -0700569 # packet stream shoud generate NSs out of pg1
Neale Rannsdcd6d622017-05-26 02:59:16 -0700570 #
571 ns_pg1.remove_vpp_config()
572
573 self.send_and_expect_ns(self.pg0, self.pg1,
574 p, self.pg1.remote_hosts[1].ip6)
575
576 #
577 # Add it back
578 #
579 ns_pg1.add_vpp_config()
580
581 self.pg0.add_stream(p)
582 self.pg_enable_capture(self.pg_interfaces)
583 self.pg_start()
584
585 rx1 = self.pg1.get_capture(1)
586
587 self.verify_ip(rx1[0],
588 self.pg1.local_mac,
589 self.pg1.remote_hosts[1].mac,
590 self.pg0.remote_ip6,
591 self.pg1.remote_hosts[1].ip6)
592
Neale Ranns87df12d2017-02-18 08:16:41 -0800593 def validate_ra(self, intf, rx, dst_ip=None, mtu=9000, pi_opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000594 if not dst_ip:
595 dst_ip = intf.remote_ip6
Neale Ranns75152282017-01-09 01:00:45 -0800596
Neale Ranns5737d882017-02-03 06:14:49 -0800597 # unicasted packets must come to the unicast mac
Neale Ranns32e1c012016-11-22 17:07:28 +0000598 self.assertEqual(rx[Ether].dst, intf.remote_mac)
599
600 # and from the router's MAC
601 self.assertEqual(rx[Ether].src, intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800602
603 # the rx'd RA should be addressed to the sender's source
604 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
605 self.assertEqual(in6_ptop(rx[IPv6].dst),
Neale Ranns32e1c012016-11-22 17:07:28 +0000606 in6_ptop(dst_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800607
608 # and come from the router's link local
609 self.assertTrue(in6_islladdr(rx[IPv6].src))
610 self.assertEqual(in6_ptop(rx[IPv6].src),
611 in6_ptop(mk_ll_addr(intf.local_mac)))
612
Neale Ranns87df12d2017-02-18 08:16:41 -0800613 # it should contain the links MTU
614 ra = rx[ICMPv6ND_RA]
615 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
616
617 # it should contain the source's link layer address option
618 sll = ra[ICMPv6NDOptSrcLLAddr]
619 self.assertEqual(sll.lladdr, intf.local_mac)
620
621 if not pi_opt:
622 # the RA should not contain prefix information
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800623 self.assertFalse(ra.haslayer(
624 ICMPv6NDOptPrefixInfo))
Neale Ranns87df12d2017-02-18 08:16:41 -0800625 else:
626 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
627
628 # the options are nested in the scapy packet in way that i cannot
629 # decipher how to decode. this 1st layer of option always returns
630 # nested classes, so a direct obj1=obj2 comparison always fails.
631 # however, the getlayer(.., 2) does give one instnace.
632 # so we cheat here and construct a new opt instnace for comparison
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800633 rd = ICMPv6NDOptPrefixInfo(
634 prefixlen=raos.prefixlen,
635 prefix=raos.prefix,
636 L=raos.L,
637 A=raos.A)
Neale Ranns87df12d2017-02-18 08:16:41 -0800638 if type(pi_opt) is list:
639 for ii in range(len(pi_opt)):
640 self.assertEqual(pi_opt[ii], rd)
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800641 rd = rx.getlayer(
642 ICMPv6NDOptPrefixInfo, ii + 2)
Neale Ranns87df12d2017-02-18 08:16:41 -0800643 else:
644 self.assertEqual(pi_opt, raos)
645
Neale Ranns32e1c012016-11-22 17:07:28 +0000646 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
Neale Ranns87df12d2017-02-18 08:16:41 -0800647 filter_out_fn=is_ipv6_misc,
648 opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000649 intf.add_stream(pkts)
Neale Ranns32e1c012016-11-22 17:07:28 +0000650 self.pg_enable_capture(self.pg_interfaces)
651 self.pg_start()
652 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
653
654 self.assertEqual(len(rx), 1)
655 rx = rx[0]
Neale Ranns87df12d2017-02-18 08:16:41 -0800656 self.validate_ra(intf, rx, dst_ip, pi_opt=opt)
Neale Ranns32e1c012016-11-22 17:07:28 +0000657
Neale Ranns75152282017-01-09 01:00:45 -0800658 def test_rs(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100659 """ IPv6 Router Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800660
Klement Sekerada505f62017-01-04 12:58:53 +0100661 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800662 """
663
664 #
Klement Sekerada505f62017-01-04 12:58:53 +0100665 # Before we begin change the IPv6 RA responses to use the unicast
666 # address - that way we will not confuse them with the periodic
667 # RAs which go to the mcast address
Neale Ranns32e1c012016-11-22 17:07:28 +0000668 # Sit and wait for the first periodic RA.
669 #
670 # TODO
Neale Ranns75152282017-01-09 01:00:45 -0800671 #
672 self.pg0.ip6_ra_config(send_unicast=1)
673
674 #
675 # An RS from a link source address
676 # - expect an RA in return
677 #
678 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800679 IPv6(
680 dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
Neale Ranns75152282017-01-09 01:00:45 -0800681 ICMPv6ND_RS())
682 pkts = [p]
683 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
684
685 #
686 # For the next RS sent the RA should be rate limited
687 #
688 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
689
690 #
691 # When we reconfiure the IPv6 RA config, we reset the RA rate limiting,
Klement Sekerada505f62017-01-04 12:58:53 +0100692 # so we need to do this before each test below so as not to drop
693 # packets for rate limiting reasons. Test this works here.
Neale Ranns75152282017-01-09 01:00:45 -0800694 #
695 self.pg0.ip6_ra_config(send_unicast=1)
696 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
697
698 #
699 # An RS sent from a non-link local source
700 #
701 self.pg0.ip6_ra_config(send_unicast=1)
702 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800703 IPv6(dst=self.pg0.local_ip6,
704 src="2002::ffff") /
Neale Ranns75152282017-01-09 01:00:45 -0800705 ICMPv6ND_RS())
706 pkts = [p]
707 self.send_and_assert_no_replies(self.pg0, pkts,
708 "RS from non-link source")
709
710 #
711 # Source an RS from a link local address
712 #
713 self.pg0.ip6_ra_config(send_unicast=1)
714 ll = mk_ll_addr(self.pg0.remote_mac)
715 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
716 IPv6(dst=self.pg0.local_ip6, src=ll) /
717 ICMPv6ND_RS())
718 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000719 self.send_and_expect_ra(self.pg0, pkts,
720 "RS sourced from link-local",
721 dst_ip=ll)
722
723 #
724 # Send the RS multicast
725 #
726 self.pg0.ip6_ra_config(send_unicast=1)
Neale Ranns3f844d02017-02-18 00:03:54 -0800727 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
Neale Ranns32e1c012016-11-22 17:07:28 +0000728 ll = mk_ll_addr(self.pg0.remote_mac)
729 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
730 IPv6(dst="ff02::2", src=ll) /
731 ICMPv6ND_RS())
732 pkts = [p]
733 self.send_and_expect_ra(self.pg0, pkts,
734 "RS sourced from link-local",
735 dst_ip=ll)
Neale Ranns75152282017-01-09 01:00:45 -0800736
737 #
Klement Sekerada505f62017-01-04 12:58:53 +0100738 # Source from the unspecified address ::. This happens when the RS
739 # is sent before the host has a configured address/sub-net,
740 # i.e. auto-config. Since the sender has no IP address, the reply
741 # comes back mcast - so the capture needs to not filter this.
742 # If we happen to pick up the periodic RA at this point then so be it,
743 # it's not an error.
Neale Ranns75152282017-01-09 01:00:45 -0800744 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000745 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
746 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
747 IPv6(dst="ff02::2", src="::") /
Neale Ranns75152282017-01-09 01:00:45 -0800748 ICMPv6ND_RS())
749 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000750 self.send_and_expect_ra(self.pg0, pkts,
751 "RS sourced from unspecified",
752 dst_ip="ff02::1",
753 filter_out_fn=None)
Neale Ranns75152282017-01-09 01:00:45 -0800754
755 #
Neale Ranns87df12d2017-02-18 08:16:41 -0800756 # Configure The RA to announce the links prefix
757 #
758 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
759 self.pg0.local_ip6_prefix_len)
760
761 #
762 # RAs should now contain the prefix information option
763 #
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800764 opt = ICMPv6NDOptPrefixInfo(
765 prefixlen=self.pg0.local_ip6_prefix_len,
766 prefix=self.pg0.local_ip6,
767 L=1,
768 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800769
770 self.pg0.ip6_ra_config(send_unicast=1)
771 ll = mk_ll_addr(self.pg0.remote_mac)
772 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
773 IPv6(dst=self.pg0.local_ip6, src=ll) /
774 ICMPv6ND_RS())
775 self.send_and_expect_ra(self.pg0, p,
776 "RA with prefix-info",
777 dst_ip=ll,
778 opt=opt)
779
780 #
781 # Change the prefix info to not off-link
782 # L-flag is clear
783 #
784 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
785 self.pg0.local_ip6_prefix_len,
786 off_link=1)
787
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800788 opt = ICMPv6NDOptPrefixInfo(
789 prefixlen=self.pg0.local_ip6_prefix_len,
790 prefix=self.pg0.local_ip6,
791 L=0,
792 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800793
794 self.pg0.ip6_ra_config(send_unicast=1)
795 self.send_and_expect_ra(self.pg0, p,
796 "RA with Prefix info with L-flag=0",
797 dst_ip=ll,
798 opt=opt)
799
800 #
801 # Change the prefix info to not off-link, no-autoconfig
802 # L and A flag are clear in the advert
803 #
804 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
805 self.pg0.local_ip6_prefix_len,
806 off_link=1,
807 no_autoconfig=1)
808
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800809 opt = ICMPv6NDOptPrefixInfo(
810 prefixlen=self.pg0.local_ip6_prefix_len,
811 prefix=self.pg0.local_ip6,
812 L=0,
813 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800814
815 self.pg0.ip6_ra_config(send_unicast=1)
816 self.send_and_expect_ra(self.pg0, p,
817 "RA with Prefix info with A & L-flag=0",
818 dst_ip=ll,
819 opt=opt)
820
821 #
822 # Change the flag settings back to the defaults
823 # L and A flag are set in the advert
824 #
825 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
826 self.pg0.local_ip6_prefix_len)
827
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800828 opt = ICMPv6NDOptPrefixInfo(
829 prefixlen=self.pg0.local_ip6_prefix_len,
830 prefix=self.pg0.local_ip6,
831 L=1,
832 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800833
834 self.pg0.ip6_ra_config(send_unicast=1)
835 self.send_and_expect_ra(self.pg0, p,
836 "RA with Prefix info",
837 dst_ip=ll,
838 opt=opt)
839
840 #
841 # Change the prefix info to not off-link, no-autoconfig
842 # L and A flag are clear in the advert
843 #
844 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
845 self.pg0.local_ip6_prefix_len,
846 off_link=1,
847 no_autoconfig=1)
848
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800849 opt = ICMPv6NDOptPrefixInfo(
850 prefixlen=self.pg0.local_ip6_prefix_len,
851 prefix=self.pg0.local_ip6,
852 L=0,
853 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800854
855 self.pg0.ip6_ra_config(send_unicast=1)
856 self.send_and_expect_ra(self.pg0, p,
857 "RA with Prefix info with A & L-flag=0",
858 dst_ip=ll,
859 opt=opt)
860
861 #
862 # Use the reset to defults option to revert to defaults
863 # L and A flag are clear in the advert
864 #
865 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
866 self.pg0.local_ip6_prefix_len,
867 use_default=1)
868
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800869 opt = ICMPv6NDOptPrefixInfo(
870 prefixlen=self.pg0.local_ip6_prefix_len,
871 prefix=self.pg0.local_ip6,
872 L=1,
873 A=1)
Neale Ranns87df12d2017-02-18 08:16:41 -0800874
875 self.pg0.ip6_ra_config(send_unicast=1)
876 self.send_and_expect_ra(self.pg0, p,
877 "RA with Prefix reverted to defaults",
878 dst_ip=ll,
879 opt=opt)
880
881 #
882 # Advertise Another prefix. With no L-flag/A-flag
883 #
884 self.pg0.ip6_ra_prefix(self.pg1.local_ip6n,
885 self.pg1.local_ip6_prefix_len,
886 off_link=1,
887 no_autoconfig=1)
888
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800889 opt = [ICMPv6NDOptPrefixInfo(
890 prefixlen=self.pg0.local_ip6_prefix_len,
891 prefix=self.pg0.local_ip6,
892 L=1,
893 A=1),
894 ICMPv6NDOptPrefixInfo(
895 prefixlen=self.pg1.local_ip6_prefix_len,
896 prefix=self.pg1.local_ip6,
897 L=0,
898 A=0)]
Neale Ranns87df12d2017-02-18 08:16:41 -0800899
900 self.pg0.ip6_ra_config(send_unicast=1)
901 ll = mk_ll_addr(self.pg0.remote_mac)
902 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
903 IPv6(dst=self.pg0.local_ip6, src=ll) /
904 ICMPv6ND_RS())
905 self.send_and_expect_ra(self.pg0, p,
906 "RA with multiple Prefix infos",
907 dst_ip=ll,
908 opt=opt)
909
910 #
911 # Remove the first refix-info - expect the second is still in the
912 # advert
913 #
914 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
915 self.pg0.local_ip6_prefix_len,
916 is_no=1)
917
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800918 opt = ICMPv6NDOptPrefixInfo(
919 prefixlen=self.pg1.local_ip6_prefix_len,
920 prefix=self.pg1.local_ip6,
921 L=0,
922 A=0)
Neale Ranns87df12d2017-02-18 08:16:41 -0800923
924 self.pg0.ip6_ra_config(send_unicast=1)
925 self.send_and_expect_ra(self.pg0, p,
926 "RA with Prefix reverted to defaults",
927 dst_ip=ll,
928 opt=opt)
929
930 #
931 # Remove the second prefix-info - expect no prefix-info i nthe adverts
932 #
933 self.pg0.ip6_ra_prefix(self.pg1.local_ip6n,
934 self.pg1.local_ip6_prefix_len,
935 is_no=1)
936
937 self.pg0.ip6_ra_config(send_unicast=1)
938 self.send_and_expect_ra(self.pg0, p,
939 "RA with Prefix reverted to defaults",
940 dst_ip=ll)
941
942 #
Neale Ranns5737d882017-02-03 06:14:49 -0800943 # Reset the periodic advertisements back to default values
Neale Ranns75152282017-01-09 01:00:45 -0800944 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000945 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200946
Neale Ranns3f844d02017-02-18 00:03:54 -0800947
Jan Geletye6c78ee2018-06-26 12:24:03 +0200948class TestICMPv6Echo(VppTestCase):
949 """ ICMPv6 Echo Test Case """
950
951 def setUp(self):
952 super(TestICMPv6Echo, self).setUp()
953
954 # create 1 pg interface
955 self.create_pg_interfaces(range(1))
956
957 for i in self.pg_interfaces:
958 i.admin_up()
959 i.config_ip6()
960 i.resolve_ndp()
961
962 def tearDown(self):
963 super(TestICMPv6Echo, self).tearDown()
964 for i in self.pg_interfaces:
965 i.unconfig_ip6()
966 i.ip6_disable()
967 i.admin_down()
968
969 def test_icmpv6_echo(self):
970 """ VPP replies to ICMPv6 Echo Request
971
972 Test scenario:
973
974 - Receive ICMPv6 Echo Request message on pg0 interface.
975 - Check outgoing ICMPv6 Echo Reply message on pg0 interface.
976 """
977
978 icmpv6_id = 0xb
979 icmpv6_seq = 5
980 icmpv6_data = '\x0a' * 18
981 p_echo_request = (Ether(src=self.pg0.remote_mac,
982 dst=self.pg0.local_mac) /
983 IPv6(src=self.pg0.remote_ip6,
984 dst=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800985 ICMPv6EchoRequest(
986 id=icmpv6_id,
987 seq=icmpv6_seq,
988 data=icmpv6_data))
Jan Geletye6c78ee2018-06-26 12:24:03 +0200989
990 self.pg0.add_stream(p_echo_request)
991 self.pg_enable_capture(self.pg_interfaces)
992 self.pg_start()
993
994 rx = self.pg0.get_capture(1)
995 rx = rx[0]
996 ether = rx[Ether]
997 ipv6 = rx[IPv6]
998 icmpv6 = rx[ICMPv6EchoReply]
999
1000 self.assertEqual(ether.src, self.pg0.local_mac)
1001 self.assertEqual(ether.dst, self.pg0.remote_mac)
1002
1003 self.assertEqual(ipv6.src, self.pg0.local_ip6)
1004 self.assertEqual(ipv6.dst, self.pg0.remote_ip6)
1005
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001006 self.assertEqual(
1007 icmp6types[icmpv6.type], "Echo Reply")
Jan Geletye6c78ee2018-06-26 12:24:03 +02001008 self.assertEqual(icmpv6.id, icmpv6_id)
1009 self.assertEqual(icmpv6.seq, icmpv6_seq)
1010 self.assertEqual(icmpv6.data, icmpv6_data)
1011
1012
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001013class TestIPv6RD(TestIPv6ND):
1014 """ IPv6 Router Discovery Test Case """
1015
1016 @classmethod
1017 def setUpClass(cls):
1018 super(TestIPv6RD, cls).setUpClass()
1019
1020 def setUp(self):
1021 super(TestIPv6RD, self).setUp()
1022
1023 # create 2 pg interfaces
1024 self.create_pg_interfaces(range(2))
1025
1026 self.interfaces = list(self.pg_interfaces)
1027
1028 # setup all interfaces
1029 for i in self.interfaces:
1030 i.admin_up()
1031 i.config_ip6()
1032
1033 def tearDown(self):
Neale Ranns744902e2017-08-14 10:35:44 -07001034 for i in self.interfaces:
1035 i.unconfig_ip6()
1036 i.admin_down()
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001037 super(TestIPv6RD, self).tearDown()
1038
1039 def test_rd_send_router_solicitation(self):
1040 """ Verify router solicitation packets """
1041
1042 count = 2
1043 self.pg_enable_capture(self.pg_interfaces)
1044 self.pg_start()
1045 self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index,
1046 mrc=count)
1047 rx_list = self.pg1.get_capture(count, timeout=3)
1048 self.assertEqual(len(rx_list), count)
1049 for packet in rx_list:
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001050 self.assertEqual(packet.haslayer(IPv6), 1)
1051 self.assertEqual(packet[IPv6].haslayer(
1052 ICMPv6ND_RS), 1)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001053 dst = ip6_normalize(packet[IPv6].dst)
1054 dst2 = ip6_normalize("ff02::2")
1055 self.assert_equal(dst, dst2)
1056 src = ip6_normalize(packet[IPv6].src)
1057 src2 = ip6_normalize(self.pg1.local_ip6_ll)
1058 self.assert_equal(src, src2)
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001059 self.assertTrue(
1060 bool(packet[ICMPv6ND_RS].haslayer(
1061 ICMPv6NDOptSrcLLAddr)))
1062 self.assert_equal(
1063 packet[ICMPv6NDOptSrcLLAddr].lladdr,
1064 self.pg1.local_mac)
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001065
1066 def verify_prefix_info(self, reported_prefix, prefix_option):
1067 prefix = socket.inet_pton(socket.AF_INET6,
1068 prefix_option.getfieldval("prefix"))
1069 self.assert_equal(reported_prefix.dst_address, prefix)
1070 self.assert_equal(reported_prefix.dst_address_length,
1071 prefix_option.getfieldval("prefixlen"))
1072 L = prefix_option.getfieldval("L")
1073 A = prefix_option.getfieldval("A")
1074 option_flags = (L << 7) | (A << 6)
1075 self.assert_equal(reported_prefix.flags, option_flags)
1076 self.assert_equal(reported_prefix.valid_time,
1077 prefix_option.getfieldval("validlifetime"))
1078 self.assert_equal(reported_prefix.preferred_time,
1079 prefix_option.getfieldval("preferredlifetime"))
1080
1081 def test_rd_receive_router_advertisement(self):
1082 """ Verify events triggered by received RA packets """
1083
1084 self.vapi.want_ip6_ra_events()
1085
1086 prefix_info_1 = ICMPv6NDOptPrefixInfo(
1087 prefix="1::2",
1088 prefixlen=50,
1089 validlifetime=200,
1090 preferredlifetime=500,
1091 L=1,
1092 A=1,
1093 )
1094
1095 prefix_info_2 = ICMPv6NDOptPrefixInfo(
1096 prefix="7::4",
1097 prefixlen=20,
1098 validlifetime=70,
1099 preferredlifetime=1000,
1100 L=1,
1101 A=0,
1102 )
1103
1104 p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) /
1105 IPv6(dst=self.pg1.local_ip6_ll,
1106 src=mk_ll_addr(self.pg1.remote_mac)) /
1107 ICMPv6ND_RA() /
1108 prefix_info_1 /
1109 prefix_info_2)
1110 self.pg1.add_stream([p])
1111 self.pg_start()
1112
1113 ev = self.vapi.wait_for_event(10, "ip6_ra_event")
1114
1115 self.assert_equal(ev.current_hop_limit, 0)
1116 self.assert_equal(ev.flags, 8)
1117 self.assert_equal(ev.router_lifetime_in_sec, 1800)
1118 self.assert_equal(ev.neighbor_reachable_time_in_msec, 0)
1119 self.assert_equal(
1120 ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0)
1121
1122 self.assert_equal(ev.n_prefixes, 2)
1123
1124 self.verify_prefix_info(ev.prefixes[0], prefix_info_1)
1125 self.verify_prefix_info(ev.prefixes[1], prefix_info_2)
1126
1127
Juraj Slobodac0374232018-02-01 15:18:49 +01001128class TestIPv6RDControlPlane(TestIPv6ND):
1129 """ IPv6 Router Discovery Control Plane Test Case """
1130
1131 @classmethod
1132 def setUpClass(cls):
1133 super(TestIPv6RDControlPlane, cls).setUpClass()
1134
1135 def setUp(self):
1136 super(TestIPv6RDControlPlane, self).setUp()
1137
1138 # create 1 pg interface
1139 self.create_pg_interfaces(range(1))
1140
1141 self.interfaces = list(self.pg_interfaces)
1142
1143 # setup all interfaces
1144 for i in self.interfaces:
1145 i.admin_up()
1146 i.config_ip6()
1147
1148 def tearDown(self):
1149 super(TestIPv6RDControlPlane, self).tearDown()
1150
1151 @staticmethod
1152 def create_ra_packet(pg, routerlifetime=None):
1153 src_ip = pg.remote_ip6_ll
1154 dst_ip = pg.local_ip6
1155 if routerlifetime is not None:
1156 ra = ICMPv6ND_RA(routerlifetime=routerlifetime)
1157 else:
1158 ra = ICMPv6ND_RA()
1159 p = (Ether(dst=pg.local_mac, src=pg.remote_mac) /
1160 IPv6(dst=dst_ip, src=src_ip) / ra)
1161 return p
1162
1163 @staticmethod
1164 def get_default_routes(fib):
1165 list = []
1166 for entry in fib:
1167 if entry.address_length == 0:
1168 for path in entry.path:
1169 if path.sw_if_index != 0xFFFFFFFF:
1170 defaut_route = {}
1171 defaut_route['sw_if_index'] = path.sw_if_index
1172 defaut_route['next_hop'] = path.next_hop
1173 list.append(defaut_route)
1174 return list
1175
1176 @staticmethod
1177 def get_interface_addresses(fib, pg):
1178 list = []
1179 for entry in fib:
1180 if entry.address_length == 128:
1181 path = entry.path[0]
1182 if path.sw_if_index == pg.sw_if_index:
1183 list.append(entry.address)
1184 return list
1185
1186 def test_all(self):
1187 """ Test handling of SLAAC addresses and default routes """
1188
1189 fib = self.vapi.ip6_fib_dump()
1190 default_routes = self.get_default_routes(fib)
1191 initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
1192 self.assertEqual(default_routes, [])
1193 router_address = self.pg0.remote_ip6n_ll
1194
1195 self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1)
1196
1197 self.sleep(0.1)
1198
1199 # send RA
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001200 packet = (self.create_ra_packet(
1201 self.pg0) / ICMPv6NDOptPrefixInfo(
Juraj Slobodac0374232018-02-01 15:18:49 +01001202 prefix="1::",
1203 prefixlen=64,
1204 validlifetime=2,
1205 preferredlifetime=2,
1206 L=1,
1207 A=1,
1208 ) / ICMPv6NDOptPrefixInfo(
1209 prefix="7::",
1210 prefixlen=20,
1211 validlifetime=1500,
1212 preferredlifetime=1000,
1213 L=1,
1214 A=0,
1215 ))
1216 self.pg0.add_stream([packet])
1217 self.pg_start()
1218
1219 self.sleep(0.1)
1220
1221 fib = self.vapi.ip6_fib_dump()
1222
1223 # check FIB for new address
1224 addresses = set(self.get_interface_addresses(fib, self.pg0))
1225 new_addresses = addresses.difference(initial_addresses)
1226 self.assertEqual(len(new_addresses), 1)
1227 prefix = list(new_addresses)[0][:8] + '\0\0\0\0\0\0\0\0'
1228 self.assertEqual(inet_ntop(AF_INET6, prefix), '1::')
1229
1230 # check FIB for new default route
1231 default_routes = self.get_default_routes(fib)
1232 self.assertEqual(len(default_routes), 1)
1233 dr = default_routes[0]
1234 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1235 self.assertEqual(dr['next_hop'], router_address)
1236
1237 # send RA to delete default route
1238 packet = self.create_ra_packet(self.pg0, routerlifetime=0)
1239 self.pg0.add_stream([packet])
1240 self.pg_start()
1241
1242 self.sleep(0.1)
1243
1244 # check that default route is deleted
1245 fib = self.vapi.ip6_fib_dump()
1246 default_routes = self.get_default_routes(fib)
1247 self.assertEqual(len(default_routes), 0)
1248
1249 self.sleep(0.1)
1250
1251 # send RA
1252 packet = self.create_ra_packet(self.pg0)
1253 self.pg0.add_stream([packet])
1254 self.pg_start()
1255
1256 self.sleep(0.1)
1257
1258 # check FIB for new default route
1259 fib = self.vapi.ip6_fib_dump()
1260 default_routes = self.get_default_routes(fib)
1261 self.assertEqual(len(default_routes), 1)
1262 dr = default_routes[0]
1263 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1264 self.assertEqual(dr['next_hop'], router_address)
1265
1266 # send RA, updating router lifetime to 1s
1267 packet = self.create_ra_packet(self.pg0, 1)
1268 self.pg0.add_stream([packet])
1269 self.pg_start()
1270
1271 self.sleep(0.1)
1272
1273 # check that default route still exists
1274 fib = self.vapi.ip6_fib_dump()
1275 default_routes = self.get_default_routes(fib)
1276 self.assertEqual(len(default_routes), 1)
1277 dr = default_routes[0]
1278 self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index)
1279 self.assertEqual(dr['next_hop'], router_address)
1280
1281 self.sleep(1)
1282
1283 # check that default route is deleted
1284 fib = self.vapi.ip6_fib_dump()
1285 default_routes = self.get_default_routes(fib)
1286 self.assertEqual(len(default_routes), 0)
1287
1288 # check FIB still contains the SLAAC address
1289 addresses = set(self.get_interface_addresses(fib, self.pg0))
1290 new_addresses = addresses.difference(initial_addresses)
1291 self.assertEqual(len(new_addresses), 1)
1292 prefix = list(new_addresses)[0][:8] + '\0\0\0\0\0\0\0\0'
1293 self.assertEqual(inet_ntop(AF_INET6, prefix), '1::')
1294
1295 self.sleep(1)
1296
1297 # check that SLAAC address is deleted
1298 fib = self.vapi.ip6_fib_dump()
1299 addresses = set(self.get_interface_addresses(fib, self.pg0))
1300 new_addresses = addresses.difference(initial_addresses)
1301 self.assertEqual(len(new_addresses), 0)
1302
1303
Neale Ranns3f844d02017-02-18 00:03:54 -08001304class IPv6NDProxyTest(TestIPv6ND):
1305 """ IPv6 ND ProxyTest Case """
1306
1307 def setUp(self):
1308 super(IPv6NDProxyTest, self).setUp()
1309
1310 # create 3 pg interfaces
1311 self.create_pg_interfaces(range(3))
1312
1313 # pg0 is the master interface, with the configured subnet
1314 self.pg0.admin_up()
1315 self.pg0.config_ip6()
1316 self.pg0.resolve_ndp()
1317
1318 self.pg1.ip6_enable()
1319 self.pg2.ip6_enable()
1320
1321 def tearDown(self):
1322 super(IPv6NDProxyTest, self).tearDown()
1323
1324 def test_nd_proxy(self):
1325 """ IPv6 Proxy ND """
1326
1327 #
1328 # Generate some hosts in the subnet that we are proxying
1329 #
1330 self.pg0.generate_remote_hosts(8)
1331
1332 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
1333 d = inet_ntop(AF_INET6, nsma)
1334
1335 #
1336 # Send an NS for one of those remote hosts on one of the proxy links
1337 # expect no response since it's from an address that is not
1338 # on the link that has the prefix configured
1339 #
1340 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001341 IPv6(dst=d,
1342 src=self.pg0._remote_hosts[2].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001343 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001344 ICMPv6NDOptSrcLLAddr(
1345 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001346
1347 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
1348
1349 #
1350 # Add proxy support for the host
1351 #
1352 self.vapi.ip6_nd_proxy(
1353 inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1354 self.pg1.sw_if_index)
1355
1356 #
1357 # try that NS again. this time we expect an NA back
1358 #
Neale Ranns2a3ea492017-04-19 05:24:40 -07001359 self.send_and_expect_na(self.pg1, ns_pg1,
1360 "NS to proxy entry",
1361 dst_ip=self.pg0._remote_hosts[2].ip6,
1362 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001363
1364 #
1365 # ... and that we have an entry in the ND cache
1366 #
1367 self.assertTrue(find_nbr(self,
1368 self.pg1.sw_if_index,
1369 self.pg0._remote_hosts[2].ip6,
1370 inet=AF_INET6))
1371
1372 #
1373 # ... and we can route traffic to it
1374 #
1375 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
1376 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1377 src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001378 inet6.UDP(sport=10000, dport=20000) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001379 Raw('\xa5' * 100))
1380
1381 self.pg0.add_stream(t)
1382 self.pg_enable_capture(self.pg_interfaces)
1383 self.pg_start()
1384 rx = self.pg1.get_capture(1)
1385 rx = rx[0]
1386
1387 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1388 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1389
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001390 self.assertEqual(rx[IPv6].src,
1391 t[IPv6].src)
1392 self.assertEqual(rx[IPv6].dst,
1393 t[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001394
1395 #
1396 # Test we proxy for the host on the main interface
1397 #
1398 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
1399 IPv6(dst=d, src=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001400 ICMPv6ND_NS(
1401 tgt=self.pg0._remote_hosts[2].ip6) /
1402 ICMPv6NDOptSrcLLAddr(
1403 lladdr=self.pg0.remote_mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001404
Neale Ranns2a3ea492017-04-19 05:24:40 -07001405 self.send_and_expect_na(self.pg0, ns_pg0,
1406 "NS to proxy entry on main",
1407 tgt_ip=self.pg0._remote_hosts[2].ip6,
1408 dst_ip=self.pg0.remote_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001409
1410 #
1411 # Setup and resolve proxy for another host on another interface
1412 #
1413 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001414 IPv6(dst=d,
1415 src=self.pg0._remote_hosts[3].ip6) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001416 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001417 ICMPv6NDOptSrcLLAddr(
1418 lladdr=self.pg0._remote_hosts[2].mac))
Neale Ranns3f844d02017-02-18 00:03:54 -08001419
1420 self.vapi.ip6_nd_proxy(
1421 inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1422 self.pg2.sw_if_index)
1423
Neale Ranns2a3ea492017-04-19 05:24:40 -07001424 self.send_and_expect_na(self.pg2, ns_pg2,
1425 "NS to proxy entry other interface",
1426 dst_ip=self.pg0._remote_hosts[3].ip6,
1427 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001428
1429 self.assertTrue(find_nbr(self,
1430 self.pg2.sw_if_index,
1431 self.pg0._remote_hosts[3].ip6,
1432 inet=AF_INET6))
1433
1434 #
1435 # hosts can communicate. pg2->pg1
1436 #
1437 t2 = (Ether(dst=self.pg2.local_mac,
1438 src=self.pg0.remote_hosts[3].mac) /
1439 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1440 src=self.pg0._remote_hosts[3].ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001441 inet6.UDP(sport=10000, dport=20000) /
Neale Ranns3f844d02017-02-18 00:03:54 -08001442 Raw('\xa5' * 100))
1443
1444 self.pg2.add_stream(t2)
1445 self.pg_enable_capture(self.pg_interfaces)
1446 self.pg_start()
1447 rx = self.pg1.get_capture(1)
1448 rx = rx[0]
1449
1450 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1451 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1452
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001453 self.assertEqual(rx[IPv6].src,
1454 t2[IPv6].src)
1455 self.assertEqual(rx[IPv6].dst,
1456 t2[IPv6].dst)
Neale Ranns3f844d02017-02-18 00:03:54 -08001457
1458 #
1459 # remove the proxy configs
1460 #
1461 self.vapi.ip6_nd_proxy(
1462 inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1463 self.pg1.sw_if_index,
1464 is_del=1)
1465 self.vapi.ip6_nd_proxy(
1466 inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1467 self.pg2.sw_if_index,
1468 is_del=1)
1469
1470 self.assertFalse(find_nbr(self,
1471 self.pg2.sw_if_index,
1472 self.pg0._remote_hosts[3].ip6,
1473 inet=AF_INET6))
1474 self.assertFalse(find_nbr(self,
1475 self.pg1.sw_if_index,
1476 self.pg0._remote_hosts[2].ip6,
1477 inet=AF_INET6))
1478
1479 #
1480 # no longer proxy-ing...
1481 #
1482 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1483 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1484 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1485
1486 #
1487 # no longer forwarding. traffic generates NS out of the glean/main
1488 # interface
1489 #
1490 self.pg2.add_stream(t2)
1491 self.pg_enable_capture(self.pg_interfaces)
1492 self.pg_start()
1493
1494 rx = self.pg0.get_capture(1)
1495
1496 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1497
1498
Neale Ranns37be7362017-02-21 17:30:26 -08001499class TestIPNull(VppTestCase):
1500 """ IPv6 routes via NULL """
1501
1502 def setUp(self):
1503 super(TestIPNull, self).setUp()
1504
1505 # create 2 pg interfaces
1506 self.create_pg_interfaces(range(1))
1507
1508 for i in self.pg_interfaces:
1509 i.admin_up()
1510 i.config_ip6()
1511 i.resolve_ndp()
1512
1513 def tearDown(self):
1514 super(TestIPNull, self).tearDown()
1515 for i in self.pg_interfaces:
1516 i.unconfig_ip6()
1517 i.admin_down()
1518
1519 def test_ip_null(self):
1520 """ IP NULL route """
1521
1522 p = (Ether(src=self.pg0.remote_mac,
1523 dst=self.pg0.local_mac) /
1524 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001525 inet6.UDP(sport=1234, dport=1234) /
Neale Ranns37be7362017-02-21 17:30:26 -08001526 Raw('\xa5' * 100))
1527
1528 #
1529 # A route via IP NULL that will reply with ICMP unreachables
1530 #
1531 ip_unreach = VppIpRoute(self, "2001::", 64, [], is_unreach=1, is_ip6=1)
1532 ip_unreach.add_vpp_config()
1533
1534 self.pg0.add_stream(p)
1535 self.pg_enable_capture(self.pg_interfaces)
1536 self.pg_start()
1537
1538 rx = self.pg0.get_capture(1)
1539 rx = rx[0]
1540 icmp = rx[ICMPv6DestUnreach]
1541
1542 # 0 = "No route to destination"
1543 self.assertEqual(icmp.code, 0)
1544
1545 # ICMP is rate limited. pause a bit
1546 self.sleep(1)
1547
1548 #
1549 # A route via IP NULL that will reply with ICMP prohibited
1550 #
1551 ip_prohibit = VppIpRoute(self, "2001::1", 128, [],
1552 is_prohibit=1, is_ip6=1)
1553 ip_prohibit.add_vpp_config()
1554
1555 self.pg0.add_stream(p)
1556 self.pg_enable_capture(self.pg_interfaces)
1557 self.pg_start()
1558
1559 rx = self.pg0.get_capture(1)
1560 rx = rx[0]
1561 icmp = rx[ICMPv6DestUnreach]
1562
1563 # 1 = "Communication with destination administratively prohibited"
1564 self.assertEqual(icmp.code, 1)
1565
1566
Neale Ranns180279b2017-03-16 15:49:09 -04001567class TestIPDisabled(VppTestCase):
1568 """ IPv6 disabled """
1569
1570 def setUp(self):
1571 super(TestIPDisabled, self).setUp()
1572
1573 # create 2 pg interfaces
1574 self.create_pg_interfaces(range(2))
1575
1576 # PG0 is IP enalbed
1577 self.pg0.admin_up()
1578 self.pg0.config_ip6()
1579 self.pg0.resolve_ndp()
1580
1581 # PG 1 is not IP enabled
1582 self.pg1.admin_up()
1583
1584 def tearDown(self):
1585 super(TestIPDisabled, self).tearDown()
1586 for i in self.pg_interfaces:
1587 i.unconfig_ip4()
1588 i.admin_down()
1589
Neale Ranns180279b2017-03-16 15:49:09 -04001590 def test_ip_disabled(self):
1591 """ IP Disabled """
1592
1593 #
1594 # An (S,G).
1595 # one accepting interface, pg0, 2 forwarding interfaces
1596 #
1597 route_ff_01 = VppIpMRoute(
1598 self,
1599 "::",
1600 "ffef::1", 128,
1601 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1602 [VppMRoutePath(self.pg1.sw_if_index,
1603 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1604 VppMRoutePath(self.pg0.sw_if_index,
1605 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
1606 is_ip6=1)
1607 route_ff_01.add_vpp_config()
1608
1609 pu = (Ether(src=self.pg1.remote_mac,
1610 dst=self.pg1.local_mac) /
1611 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001612 inet6.UDP(sport=1234, dport=1234) /
Neale Ranns180279b2017-03-16 15:49:09 -04001613 Raw('\xa5' * 100))
1614 pm = (Ether(src=self.pg1.remote_mac,
1615 dst=self.pg1.local_mac) /
1616 IPv6(src="2001::1", dst="ffef::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001617 inet6.UDP(sport=1234, dport=1234) /
Neale Ranns180279b2017-03-16 15:49:09 -04001618 Raw('\xa5' * 100))
1619
1620 #
1621 # PG1 does not forward IP traffic
1622 #
1623 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1624 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1625
1626 #
1627 # IP enable PG1
1628 #
1629 self.pg1.config_ip6()
1630
1631 #
1632 # Now we get packets through
1633 #
1634 self.pg1.add_stream(pu)
1635 self.pg_enable_capture(self.pg_interfaces)
1636 self.pg_start()
1637 rx = self.pg0.get_capture(1)
1638
1639 self.pg1.add_stream(pm)
1640 self.pg_enable_capture(self.pg_interfaces)
1641 self.pg_start()
1642 rx = self.pg0.get_capture(1)
1643
1644 #
1645 # Disable PG1
1646 #
1647 self.pg1.unconfig_ip6()
1648
1649 #
1650 # PG1 does not forward IP traffic
1651 #
1652 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1653 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1654
1655
Neale Ranns227038a2017-04-21 01:07:59 -07001656class TestIP6LoadBalance(VppTestCase):
1657 """ IPv6 Load-Balancing """
1658
1659 def setUp(self):
1660 super(TestIP6LoadBalance, self).setUp()
1661
1662 self.create_pg_interfaces(range(5))
1663
Neale Ranns15002542017-09-10 04:39:11 -07001664 mpls_tbl = VppMplsTable(self, 0)
1665 mpls_tbl.add_vpp_config()
1666
Neale Ranns227038a2017-04-21 01:07:59 -07001667 for i in self.pg_interfaces:
1668 i.admin_up()
1669 i.config_ip6()
1670 i.resolve_ndp()
Neale Ranns71275e32017-05-25 12:38:58 -07001671 i.enable_mpls()
Neale Ranns227038a2017-04-21 01:07:59 -07001672
1673 def tearDown(self):
Neale Ranns227038a2017-04-21 01:07:59 -07001674 for i in self.pg_interfaces:
1675 i.unconfig_ip6()
1676 i.admin_down()
Neale Ranns71275e32017-05-25 12:38:58 -07001677 i.disable_mpls()
Neale Ranns15002542017-09-10 04:39:11 -07001678 super(TestIP6LoadBalance, self).tearDown()
Neale Ranns227038a2017-04-21 01:07:59 -07001679
1680 def send_and_expect_load_balancing(self, input, pkts, outputs):
Neale Ranns62fe07c2017-10-31 12:28:22 -07001681 self.vapi.cli("clear trace")
Neale Ranns227038a2017-04-21 01:07:59 -07001682 input.add_stream(pkts)
1683 self.pg_enable_capture(self.pg_interfaces)
1684 self.pg_start()
1685 for oo in outputs:
1686 rx = oo._get_capture(1)
1687 self.assertNotEqual(0, len(rx))
1688
Neale Ranns71275e32017-05-25 12:38:58 -07001689 def send_and_expect_one_itf(self, input, pkts, itf):
Neale Ranns62fe07c2017-10-31 12:28:22 -07001690 self.vapi.cli("clear trace")
Neale Ranns71275e32017-05-25 12:38:58 -07001691 input.add_stream(pkts)
1692 self.pg_enable_capture(self.pg_interfaces)
1693 self.pg_start()
1694 rx = itf.get_capture(len(pkts))
1695
Neale Ranns227038a2017-04-21 01:07:59 -07001696 def test_ip6_load_balance(self):
1697 """ IPv6 Load-Balancing """
1698
1699 #
1700 # An array of packets that differ only in the destination port
Neale Ranns71275e32017-05-25 12:38:58 -07001701 # - IP only
1702 # - MPLS EOS
1703 # - MPLS non-EOS
1704 # - MPLS non-EOS with an entropy label
Neale Ranns227038a2017-04-21 01:07:59 -07001705 #
Neale Ranns71275e32017-05-25 12:38:58 -07001706 port_ip_pkts = []
1707 port_mpls_pkts = []
1708 port_mpls_neos_pkts = []
1709 port_ent_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001710
1711 #
1712 # An array of packets that differ only in the source address
1713 #
Neale Ranns71275e32017-05-25 12:38:58 -07001714 src_ip_pkts = []
1715 src_mpls_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001716
1717 for ii in range(65):
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001718 port_ip_hdr = (
1719 IPv6(dst="3000::1", src="3000:1::1") /
1720 inet6.UDP(sport=1234, dport=1234 + ii) /
1721 Raw('\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001722 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1723 dst=self.pg0.local_mac) /
1724 port_ip_hdr))
1725 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1726 dst=self.pg0.local_mac) /
1727 MPLS(label=66, ttl=2) /
1728 port_ip_hdr))
1729 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1730 dst=self.pg0.local_mac) /
1731 MPLS(label=67, ttl=2) /
1732 MPLS(label=77, ttl=2) /
1733 port_ip_hdr))
1734 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1735 dst=self.pg0.local_mac) /
1736 MPLS(label=67, ttl=2) /
1737 MPLS(label=14, ttl=2) /
1738 MPLS(label=999, ttl=2) /
1739 port_ip_hdr))
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001740 src_ip_hdr = (
1741 IPv6(dst="3000::1", src="3000:1::%d" % ii) /
1742 inet6.UDP(sport=1234, dport=1234) /
1743 Raw('\xa5' * 100))
Neale Ranns71275e32017-05-25 12:38:58 -07001744 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1745 dst=self.pg0.local_mac) /
1746 src_ip_hdr))
1747 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1748 dst=self.pg0.local_mac) /
1749 MPLS(label=66, ttl=2) /
1750 src_ip_hdr))
Neale Ranns227038a2017-04-21 01:07:59 -07001751
Neale Ranns71275e32017-05-25 12:38:58 -07001752 #
1753 # A route for the IP pacekts
1754 #
Neale Ranns227038a2017-04-21 01:07:59 -07001755 route_3000_1 = VppIpRoute(self, "3000::1", 128,
1756 [VppRoutePath(self.pg1.remote_ip6,
1757 self.pg1.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001758 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns227038a2017-04-21 01:07:59 -07001759 VppRoutePath(self.pg2.remote_ip6,
1760 self.pg2.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001761 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns227038a2017-04-21 01:07:59 -07001762 is_ip6=1)
1763 route_3000_1.add_vpp_config()
1764
1765 #
Neale Ranns71275e32017-05-25 12:38:58 -07001766 # a local-label for the EOS packets
1767 #
1768 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
1769 binding.add_vpp_config()
1770
1771 #
1772 # An MPLS route for the non-EOS packets
1773 #
1774 route_67 = VppMplsRoute(self, 67, 0,
1775 [VppRoutePath(self.pg1.remote_ip6,
1776 self.pg1.sw_if_index,
1777 labels=[67],
Neale Rannsda78f952017-05-24 09:15:43 -07001778 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns71275e32017-05-25 12:38:58 -07001779 VppRoutePath(self.pg2.remote_ip6,
1780 self.pg2.sw_if_index,
1781 labels=[67],
Neale Rannsda78f952017-05-24 09:15:43 -07001782 proto=DpoProto.DPO_PROTO_IP6)])
Neale Ranns71275e32017-05-25 12:38:58 -07001783 route_67.add_vpp_config()
1784
1785 #
Neale Ranns227038a2017-04-21 01:07:59 -07001786 # inject the packet on pg0 - expect load-balancing across the 2 paths
1787 # - since the default hash config is to use IP src,dst and port
1788 # src,dst
1789 # We are not going to ensure equal amounts of packets across each link,
1790 # since the hash algorithm is statistical and therefore this can never
1791 # be guaranteed. But wuth 64 different packets we do expect some
1792 # balancing. So instead just ensure there is traffic on each link.
1793 #
Neale Ranns71275e32017-05-25 12:38:58 -07001794 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001795 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001796 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001797 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001798 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
1799 [self.pg1, self.pg2])
1800 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1801 [self.pg1, self.pg2])
1802 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
1803 [self.pg1, self.pg2])
1804
1805 #
1806 # The packets with Entropy label in should not load-balance,
1807 # since the Entorpy value is fixed.
1808 #
1809 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
Neale Ranns227038a2017-04-21 01:07:59 -07001810
1811 #
1812 # change the flow hash config so it's only IP src,dst
1813 # - now only the stream with differing source address will
1814 # load-balance
1815 #
1816 self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=0, dport=0)
1817
Neale Ranns71275e32017-05-25 12:38:58 -07001818 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001819 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001820 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1821 [self.pg1, self.pg2])
1822 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
Neale Ranns227038a2017-04-21 01:07:59 -07001823
1824 #
1825 # change the flow hash config back to defaults
1826 #
1827 self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=1, dport=1)
1828
1829 #
1830 # Recursive prefixes
1831 # - testing that 2 stages of load-balancing occurs and there is no
1832 # polarisation (i.e. only 2 of 4 paths are used)
1833 #
1834 port_pkts = []
1835 src_pkts = []
1836
1837 for ii in range(257):
1838 port_pkts.append((Ether(src=self.pg0.remote_mac,
1839 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001840 IPv6(dst="4000::1",
1841 src="4000:1::1") /
1842 inet6.UDP(sport=1234,
1843 dport=1234 + ii) /
Neale Ranns227038a2017-04-21 01:07:59 -07001844 Raw('\xa5' * 100)))
1845 src_pkts.append((Ether(src=self.pg0.remote_mac,
1846 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001847 IPv6(dst="4000::1",
1848 src="4000:1::%d" % ii) /
1849 inet6.UDP(sport=1234, dport=1234) /
Neale Ranns227038a2017-04-21 01:07:59 -07001850 Raw('\xa5' * 100)))
1851
1852 route_3000_2 = VppIpRoute(self, "3000::2", 128,
1853 [VppRoutePath(self.pg3.remote_ip6,
1854 self.pg3.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001855 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns227038a2017-04-21 01:07:59 -07001856 VppRoutePath(self.pg4.remote_ip6,
1857 self.pg4.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001858 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns227038a2017-04-21 01:07:59 -07001859 is_ip6=1)
1860 route_3000_2.add_vpp_config()
1861
1862 route_4000_1 = VppIpRoute(self, "4000::1", 128,
1863 [VppRoutePath("3000::1",
1864 0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -07001865 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns227038a2017-04-21 01:07:59 -07001866 VppRoutePath("3000::2",
1867 0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -07001868 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns227038a2017-04-21 01:07:59 -07001869 is_ip6=1)
1870 route_4000_1.add_vpp_config()
1871
1872 #
1873 # inject the packet on pg0 - expect load-balancing across all 4 paths
1874 #
1875 self.vapi.cli("clear trace")
1876 self.send_and_expect_load_balancing(self.pg0, port_pkts,
1877 [self.pg1, self.pg2,
1878 self.pg3, self.pg4])
1879 self.send_and_expect_load_balancing(self.pg0, src_pkts,
1880 [self.pg1, self.pg2,
1881 self.pg3, self.pg4])
1882
Neale Ranns42e6b092017-07-31 02:56:03 -07001883 #
1884 # Recursive prefixes
1885 # - testing that 2 stages of load-balancing no choices
1886 #
1887 port_pkts = []
1888
1889 for ii in range(257):
1890 port_pkts.append((Ether(src=self.pg0.remote_mac,
1891 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001892 IPv6(dst="6000::1",
1893 src="6000:1::1") /
1894 inet6.UDP(sport=1234,
1895 dport=1234 + ii) /
Neale Ranns42e6b092017-07-31 02:56:03 -07001896 Raw('\xa5' * 100)))
1897
1898 route_5000_2 = VppIpRoute(self, "5000::2", 128,
1899 [VppRoutePath(self.pg3.remote_ip6,
1900 self.pg3.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001901 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns42e6b092017-07-31 02:56:03 -07001902 is_ip6=1)
1903 route_5000_2.add_vpp_config()
1904
1905 route_6000_1 = VppIpRoute(self, "6000::1", 128,
1906 [VppRoutePath("5000::2",
1907 0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -07001908 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns42e6b092017-07-31 02:56:03 -07001909 is_ip6=1)
1910 route_6000_1.add_vpp_config()
1911
1912 #
1913 # inject the packet on pg0 - expect load-balancing across all 4 paths
1914 #
1915 self.vapi.cli("clear trace")
1916 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
1917
Neale Ranns227038a2017-04-21 01:07:59 -07001918
Neale Rannsd91c1db2017-07-31 02:30:50 -07001919class TestIP6Punt(VppTestCase):
1920 """ IPv6 Punt Police/Redirect """
1921
1922 def setUp(self):
1923 super(TestIP6Punt, self).setUp()
1924
Pavel Kotucek609e1212018-11-27 09:59:44 +01001925 self.create_pg_interfaces(range(4))
Neale Rannsd91c1db2017-07-31 02:30:50 -07001926
1927 for i in self.pg_interfaces:
1928 i.admin_up()
1929 i.config_ip6()
1930 i.resolve_ndp()
1931
1932 def tearDown(self):
1933 super(TestIP6Punt, self).tearDown()
1934 for i in self.pg_interfaces:
1935 i.unconfig_ip6()
1936 i.admin_down()
1937
Neale Rannsd91c1db2017-07-31 02:30:50 -07001938 def test_ip_punt(self):
1939 """ IP6 punt police and redirect """
1940
1941 p = (Ether(src=self.pg0.remote_mac,
1942 dst=self.pg0.local_mac) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08001943 IPv6(src=self.pg0.remote_ip6,
1944 dst=self.pg0.local_ip6) /
1945 inet6.TCP(sport=1234, dport=1234) /
Neale Rannsd91c1db2017-07-31 02:30:50 -07001946 Raw('\xa5' * 100))
1947
1948 pkts = p * 1025
1949
1950 #
1951 # Configure a punt redirect via pg1.
1952 #
Ole Troan0bcad322018-12-11 13:04:01 +01001953 nh_addr = self.pg1.remote_ip6
Neale Rannsd91c1db2017-07-31 02:30:50 -07001954 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
1955 self.pg1.sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001956 nh_addr)
Neale Rannsd91c1db2017-07-31 02:30:50 -07001957
1958 self.send_and_expect(self.pg0, pkts, self.pg1)
1959
1960 #
1961 # add a policer
1962 #
1963 policer = self.vapi.policer_add_del("ip6-punt", 400, 0, 10, 0,
1964 rate_type=1)
1965 self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
1966
1967 self.vapi.cli("clear trace")
1968 self.pg0.add_stream(pkts)
1969 self.pg_enable_capture(self.pg_interfaces)
1970 self.pg_start()
1971
1972 #
1973 # the number of packet recieved should be greater than 0,
1974 # but not equal to the number sent, since some were policed
1975 #
1976 rx = self.pg1._get_capture(1)
Paul Vinciguerra3d2df212018-11-24 23:19:53 -08001977 self.assertGreater(len(rx), 0)
1978 self.assertLess(len(rx), len(pkts))
Neale Rannsd91c1db2017-07-31 02:30:50 -07001979
1980 #
1981 # remove the poilcer. back to full rx
1982 #
1983 self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
1984 self.vapi.policer_add_del("ip6-punt", 400, 0, 10, 0,
1985 rate_type=1, is_add=0)
1986 self.send_and_expect(self.pg0, pkts, self.pg1)
1987
1988 #
1989 # remove the redirect. expect full drop.
1990 #
1991 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
1992 self.pg1.sw_if_index,
1993 nh_addr,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001994 is_add=0)
Neale Rannsd91c1db2017-07-31 02:30:50 -07001995 self.send_and_assert_no_replies(self.pg0, pkts,
1996 "IP no punt config")
1997
1998 #
1999 # Add a redirect that is not input port selective
2000 #
2001 self.vapi.ip_punt_redirect(0xffffffff,
2002 self.pg1.sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002003 nh_addr)
Neale Rannsd91c1db2017-07-31 02:30:50 -07002004 self.send_and_expect(self.pg0, pkts, self.pg1)
2005
2006 self.vapi.ip_punt_redirect(0xffffffff,
2007 self.pg1.sw_if_index,
2008 nh_addr,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002009 is_add=0)
2010
2011 def test_ip_punt_dump(self):
2012 """ IP6 punt redirect dump"""
2013
2014 #
2015 # Configure a punt redirects
2016 #
Ole Troan0bcad322018-12-11 13:04:01 +01002017 nh_addr = self.pg3.remote_ip6
Pavel Kotucek609e1212018-11-27 09:59:44 +01002018 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
2019 self.pg3.sw_if_index,
2020 nh_addr)
2021 self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
2022 self.pg3.sw_if_index,
2023 nh_addr)
2024 self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
2025 self.pg3.sw_if_index,
Ole Troan0bcad322018-12-11 13:04:01 +01002026 '0::0')
Pavel Kotucek609e1212018-11-27 09:59:44 +01002027
2028 #
2029 # Dump pg0 punt redirects
2030 #
2031 punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
2032 is_ipv6=1)
2033 for p in punts:
2034 self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
2035
2036 #
2037 # Dump punt redirects for all interfaces
2038 #
2039 punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1)
2040 self.assertEqual(len(punts), 3)
2041 for p in punts:
2042 self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index)
Ole Troan0bcad322018-12-11 13:04:01 +01002043 self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6)
2044 self.assertEqual(str(punts[2].punt.nh), '::')
Neale Rannsd91c1db2017-07-31 02:30:50 -07002045
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002046
Neale Rannsce9e0b42018-08-01 12:53:17 -07002047class TestIPDeag(VppTestCase):
2048 """ IPv6 Deaggregate Routes """
2049
2050 def setUp(self):
2051 super(TestIPDeag, self).setUp()
2052
2053 self.create_pg_interfaces(range(3))
2054
2055 for i in self.pg_interfaces:
2056 i.admin_up()
2057 i.config_ip6()
2058 i.resolve_ndp()
2059
2060 def tearDown(self):
2061 super(TestIPDeag, self).tearDown()
2062 for i in self.pg_interfaces:
2063 i.unconfig_ip6()
2064 i.admin_down()
2065
2066 def test_ip_deag(self):
2067 """ IP Deag Routes """
2068
2069 #
2070 # Create a table to be used for:
2071 # 1 - another destination address lookup
2072 # 2 - a source address lookup
2073 #
2074 table_dst = VppIpTable(self, 1, is_ip6=1)
2075 table_src = VppIpTable(self, 2, is_ip6=1)
2076 table_dst.add_vpp_config()
2077 table_src.add_vpp_config()
2078
2079 #
2080 # Add a route in the default table to point to a deag/
2081 # second lookup in each of these tables
2082 #
2083 route_to_dst = VppIpRoute(self, "1::1", 128,
2084 [VppRoutePath("::",
2085 0xffffffff,
2086 nh_table_id=1,
2087 proto=DpoProto.DPO_PROTO_IP6)],
2088 is_ip6=1)
2089 route_to_src = VppIpRoute(self, "1::2", 128,
2090 [VppRoutePath("::",
2091 0xffffffff,
2092 nh_table_id=2,
2093 is_source_lookup=1,
2094 proto=DpoProto.DPO_PROTO_IP6)],
2095 is_ip6=1)
2096 route_to_dst.add_vpp_config()
2097 route_to_src.add_vpp_config()
2098
2099 #
2100 # packets to these destination are dropped, since they'll
2101 # hit the respective default routes in the second table
2102 #
2103 p_dst = (Ether(src=self.pg0.remote_mac,
2104 dst=self.pg0.local_mac) /
2105 IPv6(src="5::5", dst="1::1") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002106 inet6.TCP(sport=1234, dport=1234) /
Neale Rannsce9e0b42018-08-01 12:53:17 -07002107 Raw('\xa5' * 100))
2108 p_src = (Ether(src=self.pg0.remote_mac,
2109 dst=self.pg0.local_mac) /
2110 IPv6(src="2::2", dst="1::2") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002111 inet6.TCP(sport=1234, dport=1234) /
Neale Rannsce9e0b42018-08-01 12:53:17 -07002112 Raw('\xa5' * 100))
2113 pkts_dst = p_dst * 257
2114 pkts_src = p_src * 257
2115
2116 self.send_and_assert_no_replies(self.pg0, pkts_dst,
2117 "IP in dst table")
2118 self.send_and_assert_no_replies(self.pg0, pkts_src,
2119 "IP in src table")
2120
2121 #
2122 # add a route in the dst table to forward via pg1
2123 #
2124 route_in_dst = VppIpRoute(self, "1::1", 128,
2125 [VppRoutePath(self.pg1.remote_ip6,
2126 self.pg1.sw_if_index,
2127 proto=DpoProto.DPO_PROTO_IP6)],
2128 is_ip6=1,
2129 table_id=1)
2130 route_in_dst.add_vpp_config()
2131
2132 self.send_and_expect(self.pg0, pkts_dst, self.pg1)
2133
2134 #
2135 # add a route in the src table to forward via pg2
2136 #
2137 route_in_src = VppIpRoute(self, "2::2", 128,
2138 [VppRoutePath(self.pg2.remote_ip6,
2139 self.pg2.sw_if_index,
2140 proto=DpoProto.DPO_PROTO_IP6)],
2141 is_ip6=1,
2142 table_id=2)
2143 route_in_src.add_vpp_config()
2144 self.send_and_expect(self.pg0, pkts_src, self.pg2)
2145
2146 #
2147 # loop in the lookup DP
2148 #
2149 route_loop = VppIpRoute(self, "3::3", 128,
2150 [VppRoutePath("::",
2151 0xffffffff,
2152 proto=DpoProto.DPO_PROTO_IP6)],
2153 is_ip6=1)
2154 route_loop.add_vpp_config()
2155
2156 p_l = (Ether(src=self.pg0.remote_mac,
2157 dst=self.pg0.local_mac) /
2158 IPv6(src="3::4", dst="3::3") /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002159 inet6.TCP(sport=1234, dport=1234) /
Neale Rannsce9e0b42018-08-01 12:53:17 -07002160 Raw('\xa5' * 100))
2161
2162 self.send_and_assert_no_replies(self.pg0, p_l * 257,
2163 "IP lookup loop")
2164
2165
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002166class TestIP6Input(VppTestCase):
Neale Rannsae809832018-11-23 09:00:27 -08002167 """ IPv6 Input Exception Test Cases """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002168
2169 def setUp(self):
2170 super(TestIP6Input, self).setUp()
2171
2172 self.create_pg_interfaces(range(2))
2173
2174 for i in self.pg_interfaces:
2175 i.admin_up()
2176 i.config_ip6()
2177 i.resolve_ndp()
2178
2179 def tearDown(self):
2180 super(TestIP6Input, self).tearDown()
2181 for i in self.pg_interfaces:
2182 i.unconfig_ip6()
2183 i.admin_down()
2184
Neale Rannsae809832018-11-23 09:00:27 -08002185 def test_ip_input_icmp_reply(self):
2186 """ IP6 Input Exception - Return ICMP (3,0) """
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002187 #
Neale Rannsae809832018-11-23 09:00:27 -08002188 # hop limit - ICMP replies
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002189 #
2190 p_version = (Ether(src=self.pg0.remote_mac,
2191 dst=self.pg0.local_mac) /
2192 IPv6(src=self.pg0.remote_ip6,
2193 dst=self.pg1.remote_ip6,
2194 hlim=1) /
Paul Vinciguerra978aa642018-11-24 22:19:12 -08002195 inet6.UDP(sport=1234, dport=1234) /
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002196 Raw('\xa5' * 100))
2197
2198 rx = self.send_and_expect(self.pg0, p_version * 65, self.pg0)
2199 rx = rx[0]
2200 icmp = rx[ICMPv6TimeExceeded]
Neale Rannsae809832018-11-23 09:00:27 -08002201
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002202 # 0: "hop limit exceeded in transit",
Neale Rannsae809832018-11-23 09:00:27 -08002203 self.assertEqual((icmp.type, icmp.code), (3, 0))
2204
2205 icmpv6_data = '\x0a' * 18
2206 all_0s = "::"
2207 all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
2208
2209 @parameterized.expand([
2210 # Name, src, dst, l4proto, msg, timeout
2211 ("src='iface', dst='iface'", None, None,
2212 inet6.UDP(sport=1234, dport=1234), "funky version", None),
2213 ("src='All 0's', dst='iface'", all_0s, None,
2214 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2215 ("src='iface', dst='All 0's'", None, all_0s,
2216 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2217 ("src='All 1's', dst='iface'", all_1s, None,
2218 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2219 ("src='iface', dst='All 1's'", None, all_1s,
2220 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2221 ("src='All 1's', dst='All 1's'", all_1s, all_1s,
2222 ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1),
2223
2224 ])
2225 def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout):
2226
2227 self._testMethodDoc = 'IPv6 Input Exception - %s' % name
2228
2229 p_version = (Ether(src=self.pg0.remote_mac,
2230 dst=self.pg0.local_mac) /
2231 IPv6(src=src or self.pg0.remote_ip6,
2232 dst=dst or self.pg1.remote_ip6,
2233 version=3) /
2234 l4 /
2235 Raw('\xa5' * 100))
2236
2237 self.send_and_assert_no_replies(self.pg0, p_version * 65,
2238 remark=msg or "",
2239 timeout=timeout)
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002240
Neale Ranns4c7c8e52017-10-21 09:37:55 -07002241
Damjan Marionf56b77a2016-10-03 19:44:57 +02002242if __name__ == '__main__':
Klement Sekeraf62ae122016-10-11 11:47:09 +02002243 unittest.main(testRunner=VppTestRunner)