blob: 0a0d56cbb8dfd52dc904ed0521e90fbb9d2d8b77 [file] [log] [blame]
Damjan Marionf56b77a2016-10-03 19:44:57 +02001#!/usr/bin/env python
2
Damjan Marionf56b77a2016-10-03 19:44:57 +02003import unittest
Neale Ranns3f844d02017-02-18 00:03:54 -08004from socket import AF_INET6
Klement Sekeraf62ae122016-10-11 11:47:09 +02005
Damjan Marionf56b77a2016-10-03 19:44:57 +02006from framework import VppTestCase, VppTestRunner
Matej Klotton86d87c42016-11-11 11:38:55 +01007from vpp_sub_interface import VppSubInterface, VppDot1QSubint
Neale Ranns32e1c012016-11-22 17:07:28 +00008from vpp_pg_interface import is_ipv6_misc
Neale Ranns180279b2017-03-16 15:49:09 -04009from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
Neale Ranns71275e32017-05-25 12:38:58 -070010 VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \
Neale Ranns15002542017-09-10 04:39:11 -070011 VppMplsRoute, DpoProto, VppMplsTable
Neale Rannsb3b2de72017-03-08 05:17:22 -080012from vpp_neighbor import find_nbr, VppNeighbor
Damjan Marionf56b77a2016-10-03 19:44:57 +020013
14from scapy.packet import Raw
15from scapy.layers.l2 import Ether, Dot1Q
Neale Rannsd91c1db2017-07-31 02:30:50 -070016from scapy.layers.inet6 import IPv6, UDP, TCP, ICMPv6ND_NS, ICMPv6ND_RS, \
Neale Ranns87df12d2017-02-18 08:16:41 -080017 ICMPv6ND_RA, ICMPv6NDOptSrcLLAddr, getmacbyip6, ICMPv6MRD_Solicitation, \
Neale Ranns3f844d02017-02-18 00:03:54 -080018 ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \
Neale Ranns4c7c8e52017-10-21 09:37:55 -070019 ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \
20 ICMPv6TimeExceeded
Neale Ranns3f844d02017-02-18 00:03:54 -080021
Klement Sekera7bb873a2016-11-18 07:38:42 +010022from util import ppp
Neale Ranns75152282017-01-09 01:00:45 -080023from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \
Neale Ranns32e1c012016-11-22 17:07:28 +000024 in6_mactoifaceid, in6_ismaddr
Neale Ranns75152282017-01-09 01:00:45 -080025from scapy.utils import inet_pton, inet_ntop
Neale Ranns71275e32017-05-25 12:38:58 -070026from scapy.contrib.mpls import MPLS
Neale Ranns75152282017-01-09 01:00:45 -080027
Neale Ranns5737d882017-02-03 06:14:49 -080028
Neale Ranns75152282017-01-09 01:00:45 -080029def mk_ll_addr(mac):
30 euid = in6_mactoifaceid(mac)
31 addr = "fe80::" + euid
32 return addr
Damjan Marionf56b77a2016-10-03 19:44:57 +020033
34
Neale Ranns3f844d02017-02-18 00:03:54 -080035class TestIPv6ND(VppTestCase):
36 def validate_ra(self, intf, rx, dst_ip=None):
37 if not dst_ip:
38 dst_ip = intf.remote_ip6
39
40 # unicasted packets must come to the unicast mac
41 self.assertEqual(rx[Ether].dst, intf.remote_mac)
42
43 # and from the router's MAC
44 self.assertEqual(rx[Ether].src, intf.local_mac)
45
46 # the rx'd RA should be addressed to the sender's source
47 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
48 self.assertEqual(in6_ptop(rx[IPv6].dst),
49 in6_ptop(dst_ip))
50
51 # and come from the router's link local
52 self.assertTrue(in6_islladdr(rx[IPv6].src))
53 self.assertEqual(in6_ptop(rx[IPv6].src),
54 in6_ptop(mk_ll_addr(intf.local_mac)))
55
56 def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None):
57 if not dst_ip:
58 dst_ip = intf.remote_ip6
59 if not tgt_ip:
60 dst_ip = intf.local_ip6
61
62 # unicasted packets must come to the unicast mac
63 self.assertEqual(rx[Ether].dst, intf.remote_mac)
64
65 # and from the router's MAC
66 self.assertEqual(rx[Ether].src, intf.local_mac)
67
68 # the rx'd NA should be addressed to the sender's source
69 self.assertTrue(rx.haslayer(ICMPv6ND_NA))
70 self.assertEqual(in6_ptop(rx[IPv6].dst),
71 in6_ptop(dst_ip))
72
73 # and come from the target address
74 self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip))
75
76 # Dest link-layer options should have the router's MAC
77 dll = rx[ICMPv6NDOptDstLLAddr]
78 self.assertEqual(dll.lladdr, intf.local_mac)
79
Neale Rannsdcd6d622017-05-26 02:59:16 -070080 def validate_ns(self, intf, rx, tgt_ip):
81 nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip))
82 dst_ip = inet_ntop(AF_INET6, nsma)
83
84 # NS is broadcast
85 self.assertEqual(rx[Ether].dst, "ff:ff:ff:ff:ff:ff")
86
87 # and from the router's MAC
88 self.assertEqual(rx[Ether].src, intf.local_mac)
89
90 # the rx'd NS should be addressed to an mcast address
91 # derived from the target address
92 self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip))
93
94 # expect the tgt IP in the NS header
95 ns = rx[ICMPv6ND_NS]
96 self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip))
97
98 # packet is from the router's local address
99 self.assertEqual(in6_ptop(rx[IPv6].src), intf.local_ip6)
100
101 # Src link-layer options should have the router's MAC
102 sll = rx[ICMPv6NDOptSrcLLAddr]
103 self.assertEqual(sll.lladdr, intf.local_mac)
104
Neale Ranns3f844d02017-02-18 00:03:54 -0800105 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
106 filter_out_fn=is_ipv6_misc):
107 intf.add_stream(pkts)
Neale Ranns3f844d02017-02-18 00:03:54 -0800108 self.pg_enable_capture(self.pg_interfaces)
109 self.pg_start()
110 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
111
112 self.assertEqual(len(rx), 1)
113 rx = rx[0]
114 self.validate_ra(intf, rx, dst_ip)
115
Neale Ranns2a3ea492017-04-19 05:24:40 -0700116 def send_and_expect_na(self, intf, pkts, remark, dst_ip=None,
117 tgt_ip=None,
118 filter_out_fn=is_ipv6_misc):
119 intf.add_stream(pkts)
120 self.pg_enable_capture(self.pg_interfaces)
121 self.pg_start()
122 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
123
124 self.assertEqual(len(rx), 1)
125 rx = rx[0]
126 self.validate_na(intf, rx, dst_ip, tgt_ip)
127
Neale Rannsdcd6d622017-05-26 02:59:16 -0700128 def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip,
129 filter_out_fn=is_ipv6_misc):
130 tx_intf.add_stream(pkts)
131 self.pg_enable_capture(self.pg_interfaces)
132 self.pg_start()
133 rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn)
134
135 self.assertEqual(len(rx), 1)
136 rx = rx[0]
137 self.validate_ns(rx_intf, rx, tgt_ip)
138
Neale Ranns3f844d02017-02-18 00:03:54 -0800139 def send_and_assert_no_replies(self, intf, pkts, remark):
140 intf.add_stream(pkts)
141 self.pg_enable_capture(self.pg_interfaces)
142 self.pg_start()
Neale Ranns2a3ea492017-04-19 05:24:40 -0700143 for i in self.pg_interfaces:
144 i.get_capture(0)
145 i.assert_nothing_captured(remark=remark)
Neale Ranns3f844d02017-02-18 00:03:54 -0800146
Neale Rannsdcd6d622017-05-26 02:59:16 -0700147 def verify_ip(self, rx, smac, dmac, sip, dip):
148 ether = rx[Ether]
149 self.assertEqual(ether.dst, dmac)
150 self.assertEqual(ether.src, smac)
151
152 ip = rx[IPv6]
153 self.assertEqual(ip.src, sip)
154 self.assertEqual(ip.dst, dip)
155
Neale Ranns3f844d02017-02-18 00:03:54 -0800156
157class TestIPv6(TestIPv6ND):
Damjan Marionf56b77a2016-10-03 19:44:57 +0200158 """ IPv6 Test Case """
159
160 @classmethod
161 def setUpClass(cls):
162 super(TestIPv6, cls).setUpClass()
163
Klement Sekeraf62ae122016-10-11 11:47:09 +0200164 def setUp(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100165 """
166 Perform test setup before test case.
167
168 **Config:**
169 - create 3 pg interfaces
170 - untagged pg0 interface
171 - Dot1Q subinterface on pg1
172 - Dot1AD subinterface on pg2
173 - setup interfaces:
174 - put it into UP state
175 - set IPv6 addresses
176 - resolve neighbor address using NDP
177 - configure 200 fib entries
178
179 :ivar list interfaces: pg interfaces and subinterfaces.
180 :ivar dict flows: IPv4 packet flows in test.
181 :ivar list pg_if_packet_sizes: packet sizes in test.
182
183 *TODO:* Create AD sub interface
184 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200185 super(TestIPv6, self).setUp()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200186
Klement Sekeraf62ae122016-10-11 11:47:09 +0200187 # create 3 pg interfaces
188 self.create_pg_interfaces(range(3))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200189
Klement Sekeraf62ae122016-10-11 11:47:09 +0200190 # create 2 subinterfaces for p1 and pg2
191 self.sub_interfaces = [
192 VppDot1QSubint(self, self.pg1, 100),
Matej Klotton86d87c42016-11-11 11:38:55 +0100193 VppDot1QSubint(self, self.pg2, 200)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194 # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400)
Matej Klotton86d87c42016-11-11 11:38:55 +0100195 ]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200196
Klement Sekeraf62ae122016-10-11 11:47:09 +0200197 # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc.
198 self.flows = dict()
199 self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if]
200 self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if]
201 self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200202
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203 # packet sizes
204 self.pg_if_packet_sizes = [64, 512, 1518, 9018]
205 self.sub_if_packet_sizes = [64, 512, 1518 + 4, 9018 + 4]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207 self.interfaces = list(self.pg_interfaces)
208 self.interfaces.extend(self.sub_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200209
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210 # setup all interfaces
211 for i in self.interfaces:
212 i.admin_up()
213 i.config_ip6()
214 i.resolve_ndp()
215
Matej Klotton86d87c42016-11-11 11:38:55 +0100216 # config 2M FIB entries
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217 self.config_fib_entries(200)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200218
219 def tearDown(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100220 """Run standard test teardown and log ``show ip6 neighbors``."""
Neale Ranns75152282017-01-09 01:00:45 -0800221 for i in self.sub_interfaces:
222 i.unconfig_ip6()
223 i.ip6_disable()
224 i.admin_down()
225 i.remove_vpp_config()
226
Klement Sekeraf62ae122016-10-11 11:47:09 +0200227 super(TestIPv6, self).tearDown()
228 if not self.vpp_dead:
Matej Klotton86d87c42016-11-11 11:38:55 +0100229 self.logger.info(self.vapi.cli("show ip6 neighbors"))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200230 # info(self.vapi.cli("show ip6 fib")) # many entries
Damjan Marionf56b77a2016-10-03 19:44:57 +0200231
Klement Sekeraf62ae122016-10-11 11:47:09 +0200232 def config_fib_entries(self, count):
Matej Klotton86d87c42016-11-11 11:38:55 +0100233 """For each interface add to the FIB table *count* routes to
234 "fd02::1/128" destination with interface's local address as next-hop
235 address.
236
237 :param int count: Number of FIB entries.
238
239 - *TODO:* check if the next-hop address shouldn't be remote address
240 instead of local address.
241 """
Klement Sekeraf62ae122016-10-11 11:47:09 +0200242 n_int = len(self.interfaces)
243 percent = 0
244 counter = 0.0
Neale Ranns3f844d02017-02-18 00:03:54 -0800245 dest_addr = inet_pton(AF_INET6, "fd02::1")
Klement Sekeraf62ae122016-10-11 11:47:09 +0200246 dest_addr_len = 128
247 for i in self.interfaces:
248 next_hop_address = i.local_ip6n
249 for j in range(count / n_int):
250 self.vapi.ip_add_del_route(
251 dest_addr, dest_addr_len, next_hop_address, is_ipv6=1)
Matej Klotton86d87c42016-11-11 11:38:55 +0100252 counter += 1
Klement Sekeraf62ae122016-10-11 11:47:09 +0200253 if counter / count * 100 > percent:
Matej Klotton86d87c42016-11-11 11:38:55 +0100254 self.logger.info("Configure %d FIB entries .. %d%% done" %
Klement Sekera7bb873a2016-11-18 07:38:42 +0100255 (count, percent))
Matej Klotton86d87c42016-11-11 11:38:55 +0100256 percent += 1
Damjan Marionf56b77a2016-10-03 19:44:57 +0200257
Klement Sekeraf62ae122016-10-11 11:47:09 +0200258 def create_stream(self, src_if, packet_sizes):
Matej Klotton86d87c42016-11-11 11:38:55 +0100259 """Create input packet stream for defined interface.
260
261 :param VppInterface src_if: Interface to create packet stream for.
262 :param list packet_sizes: Required packet sizes.
263 """
Damjan Marionf56b77a2016-10-03 19:44:57 +0200264 pkts = []
265 for i in range(0, 257):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200266 dst_if = self.flows[src_if][i % 2]
Klement Sekeradab231a2016-12-21 08:50:14 +0100267 info = self.create_packet_info(src_if, dst_if)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200268 payload = self.info_to_payload(info)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200269 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
270 IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6) /
Damjan Marionf56b77a2016-10-03 19:44:57 +0200271 UDP(sport=1234, dport=1234) /
272 Raw(payload))
273 info.data = p.copy()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200274 if isinstance(src_if, VppSubInterface):
275 p = src_if.add_dot1_layer(p)
276 size = packet_sizes[(i // 2) % len(packet_sizes)]
Damjan Marionf56b77a2016-10-03 19:44:57 +0200277 self.extend_packet(p, size)
278 pkts.append(p)
279 return pkts
280
Klement Sekeraf62ae122016-10-11 11:47:09 +0200281 def verify_capture(self, dst_if, capture):
Matej Klotton86d87c42016-11-11 11:38:55 +0100282 """Verify captured input packet stream for defined interface.
283
284 :param VppInterface dst_if: Interface to verify captured packet stream
285 for.
286 :param list capture: Captured packet stream.
287 """
288 self.logger.info("Verifying capture on interface %s" % dst_if.name)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200289 last_info = dict()
Damjan Marionf56b77a2016-10-03 19:44:57 +0200290 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200291 last_info[i.sw_if_index] = None
292 is_sub_if = False
293 dst_sw_if_index = dst_if.sw_if_index
294 if hasattr(dst_if, 'parent'):
295 is_sub_if = True
Damjan Marionf56b77a2016-10-03 19:44:57 +0200296 for packet in capture:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200297 if is_sub_if:
298 # Check VLAN tags and Ethernet header
299 packet = dst_if.remove_dot1_layer(packet)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200300 self.assertTrue(Dot1Q not in packet)
301 try:
302 ip = packet[IPv6]
303 udp = packet[UDP]
304 payload_info = self.payload_to_info(str(packet[Raw]))
305 packet_index = payload_info.index
Klement Sekeraf62ae122016-10-11 11:47:09 +0200306 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerada505f62017-01-04 12:58:53 +0100307 self.logger.debug(
308 "Got packet on port %s: src=%u (id=%u)" %
309 (dst_if.name, payload_info.src, packet_index))
Klement Sekeraf62ae122016-10-11 11:47:09 +0200310 next_info = self.get_next_packet_info_for_interface2(
311 payload_info.src, dst_sw_if_index,
312 last_info[payload_info.src])
313 last_info[payload_info.src] = next_info
Damjan Marionf56b77a2016-10-03 19:44:57 +0200314 self.assertTrue(next_info is not None)
315 self.assertEqual(packet_index, next_info.index)
316 saved_packet = next_info.data
317 # Check standard fields
318 self.assertEqual(ip.src, saved_packet[IPv6].src)
319 self.assertEqual(ip.dst, saved_packet[IPv6].dst)
320 self.assertEqual(udp.sport, saved_packet[UDP].sport)
321 self.assertEqual(udp.dport, saved_packet[UDP].dport)
322 except:
Klement Sekera7bb873a2016-11-18 07:38:42 +0100323 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200324 raise
325 for i in self.interfaces:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200326 remaining_packet = self.get_next_packet_info_for_interface2(
327 i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index])
Klement Sekera7bb873a2016-11-18 07:38:42 +0100328 self.assertTrue(remaining_packet is None,
329 "Interface %s: Packet expected from interface %s "
330 "didn't arrive" % (dst_if.name, i.name))
Damjan Marionf56b77a2016-10-03 19:44:57 +0200331
332 def test_fib(self):
Matej Klotton86d87c42016-11-11 11:38:55 +0100333 """ IPv6 FIB test
334
335 Test scenario:
336 - Create IPv6 stream for pg0 interface
337 - Create IPv6 tagged streams for pg1's and pg2's subinterface.
338 - Send and verify received packets on each interface.
339 """
Damjan Marionf56b77a2016-10-03 19:44:57 +0200340
Klement Sekeraf62ae122016-10-11 11:47:09 +0200341 pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes)
342 self.pg0.add_stream(pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200343
Klement Sekeraf62ae122016-10-11 11:47:09 +0200344 for i in self.sub_interfaces:
345 pkts = self.create_stream(i, self.sub_if_packet_sizes)
346 i.parent.add_stream(pkts)
347
348 self.pg_enable_capture(self.pg_interfaces)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200349 self.pg_start()
350
Klement Sekeraf62ae122016-10-11 11:47:09 +0200351 pkts = self.pg0.get_capture()
352 self.verify_capture(self.pg0, pkts)
353
354 for i in self.sub_interfaces:
355 pkts = i.parent.get_capture()
356 self.verify_capture(i, pkts)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200357
Neale Ranns75152282017-01-09 01:00:45 -0800358 def test_ns(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100359 """ IPv6 Neighbour Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800360
Klement Sekerada505f62017-01-04 12:58:53 +0100361 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800362 - Send an NS Sourced from an address not covered by the link sub-net
363 - Send an NS to an mcast address the router has not joined
364 - Send NS for a target address the router does not onn.
365 """
366
367 #
368 # An NS from a non link source address
369 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800370 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
371 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800372
373 p = (Ether(dst=in6_getnsmac(nsma)) /
374 IPv6(dst=d, src="2002::2") /
375 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
376 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
377 pkts = [p]
378
Klement Sekerada505f62017-01-04 12:58:53 +0100379 self.send_and_assert_no_replies(
380 self.pg0, pkts,
381 "No response to NS source by address not on sub-net")
Neale Ranns75152282017-01-09 01:00:45 -0800382
383 #
Klement Sekerada505f62017-01-04 12:58:53 +0100384 # An NS for sent to a solicited mcast group the router is
385 # not a member of FAILS
Neale Ranns75152282017-01-09 01:00:45 -0800386 #
387 if 0:
Neale Ranns3f844d02017-02-18 00:03:54 -0800388 nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff"))
389 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800390
391 p = (Ether(dst=in6_getnsmac(nsma)) /
392 IPv6(dst=d, src=self.pg0.remote_ip6) /
393 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
394 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
395 pkts = [p]
396
Klement Sekerada505f62017-01-04 12:58:53 +0100397 self.send_and_assert_no_replies(
398 self.pg0, pkts,
399 "No response to NS sent to unjoined mcast address")
Neale Ranns75152282017-01-09 01:00:45 -0800400
401 #
402 # An NS whose target address is one the router does not own
403 #
Neale Ranns3f844d02017-02-18 00:03:54 -0800404 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
405 d = inet_ntop(AF_INET6, nsma)
Neale Ranns75152282017-01-09 01:00:45 -0800406
407 p = (Ether(dst=in6_getnsmac(nsma)) /
408 IPv6(dst=d, src=self.pg0.remote_ip6) /
409 ICMPv6ND_NS(tgt="fd::ffff") /
410 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
411 pkts = [p]
412
413 self.send_and_assert_no_replies(self.pg0, pkts,
414 "No response to NS for unknown target")
415
Neale Rannsb3b2de72017-03-08 05:17:22 -0800416 #
417 # A neighbor entry that has no associated FIB-entry
418 #
419 self.pg0.generate_remote_hosts(4)
420 nd_entry = VppNeighbor(self,
421 self.pg0.sw_if_index,
422 self.pg0.remote_hosts[2].mac,
423 self.pg0.remote_hosts[2].ip6,
424 af=AF_INET6,
425 is_no_fib_entry=1)
426 nd_entry.add_vpp_config()
427
428 #
429 # check we have the neighbor, but no route
430 #
431 self.assertTrue(find_nbr(self,
432 self.pg0.sw_if_index,
433 self.pg0._remote_hosts[2].ip6,
434 inet=AF_INET6))
435 self.assertFalse(find_route(self,
436 self.pg0._remote_hosts[2].ip6,
437 128,
438 inet=AF_INET6))
439
Neale Ranns2a3ea492017-04-19 05:24:40 -0700440 #
441 # send an NS from a link local address to the interface's global
442 # address
443 #
444 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
445 IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6_ll) /
446 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
447 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
448
449 self.send_and_expect_na(self.pg0, p,
450 "NS from link-local",
451 dst_ip=self.pg0._remote_hosts[2].ip6_ll,
452 tgt_ip=self.pg0.local_ip6)
453
454 #
455 # we should have learned an ND entry for the peer's link-local
456 # but not inserted a route to it in the FIB
457 #
458 self.assertTrue(find_nbr(self,
459 self.pg0.sw_if_index,
460 self.pg0._remote_hosts[2].ip6_ll,
461 inet=AF_INET6))
462 self.assertFalse(find_route(self,
463 self.pg0._remote_hosts[2].ip6_ll,
464 128,
465 inet=AF_INET6))
466
467 #
468 # An NS to the router's own Link-local
469 #
470 p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
471 IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6_ll) /
472 ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) /
473 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
474
475 self.send_and_expect_na(self.pg0, p,
476 "NS to/from link-local",
477 dst_ip=self.pg0._remote_hosts[3].ip6_ll,
478 tgt_ip=self.pg0.local_ip6_ll)
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[3].ip6_ll,
487 inet=AF_INET6))
488 self.assertFalse(find_route(self,
489 self.pg0._remote_hosts[3].ip6_ll,
490 128,
491 inet=AF_INET6))
492
Neale Rannsdcd6d622017-05-26 02:59:16 -0700493 def test_ns_duplicates(self):
Neale Rannsda78f952017-05-24 09:15:43 -0700494 """ ND Duplicates"""
Neale Rannsdcd6d622017-05-26 02:59:16 -0700495
496 #
497 # Generate some hosts on the LAN
498 #
499 self.pg1.generate_remote_hosts(3)
500
501 #
502 # Add host 1 on pg1 and pg2
503 #
504 ns_pg1 = VppNeighbor(self,
505 self.pg1.sw_if_index,
506 self.pg1.remote_hosts[1].mac,
507 self.pg1.remote_hosts[1].ip6,
508 af=AF_INET6)
509 ns_pg1.add_vpp_config()
510 ns_pg2 = VppNeighbor(self,
511 self.pg2.sw_if_index,
512 self.pg2.remote_mac,
513 self.pg1.remote_hosts[1].ip6,
514 af=AF_INET6)
515 ns_pg2.add_vpp_config()
516
517 #
518 # IP packet destined for pg1 remote host arrives on pg1 again.
519 #
520 p = (Ether(dst=self.pg0.local_mac,
521 src=self.pg0.remote_mac) /
522 IPv6(src=self.pg0.remote_ip6,
523 dst=self.pg1.remote_hosts[1].ip6) /
524 UDP(sport=1234, dport=1234) /
525 Raw())
526
527 self.pg0.add_stream(p)
528 self.pg_enable_capture(self.pg_interfaces)
529 self.pg_start()
530
531 rx1 = self.pg1.get_capture(1)
532
533 self.verify_ip(rx1[0],
534 self.pg1.local_mac,
535 self.pg1.remote_hosts[1].mac,
536 self.pg0.remote_ip6,
537 self.pg1.remote_hosts[1].ip6)
538
539 #
540 # remove the duplicate on pg1
Neale Rannsda78f952017-05-24 09:15:43 -0700541 # packet stream shoud generate NSs out of pg1
Neale Rannsdcd6d622017-05-26 02:59:16 -0700542 #
543 ns_pg1.remove_vpp_config()
544
545 self.send_and_expect_ns(self.pg0, self.pg1,
546 p, self.pg1.remote_hosts[1].ip6)
547
548 #
549 # Add it back
550 #
551 ns_pg1.add_vpp_config()
552
553 self.pg0.add_stream(p)
554 self.pg_enable_capture(self.pg_interfaces)
555 self.pg_start()
556
557 rx1 = self.pg1.get_capture(1)
558
559 self.verify_ip(rx1[0],
560 self.pg1.local_mac,
561 self.pg1.remote_hosts[1].mac,
562 self.pg0.remote_ip6,
563 self.pg1.remote_hosts[1].ip6)
564
Neale Ranns87df12d2017-02-18 08:16:41 -0800565 def validate_ra(self, intf, rx, dst_ip=None, mtu=9000, pi_opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000566 if not dst_ip:
567 dst_ip = intf.remote_ip6
Neale Ranns75152282017-01-09 01:00:45 -0800568
Neale Ranns5737d882017-02-03 06:14:49 -0800569 # unicasted packets must come to the unicast mac
Neale Ranns32e1c012016-11-22 17:07:28 +0000570 self.assertEqual(rx[Ether].dst, intf.remote_mac)
571
572 # and from the router's MAC
573 self.assertEqual(rx[Ether].src, intf.local_mac)
Neale Ranns75152282017-01-09 01:00:45 -0800574
575 # the rx'd RA should be addressed to the sender's source
576 self.assertTrue(rx.haslayer(ICMPv6ND_RA))
577 self.assertEqual(in6_ptop(rx[IPv6].dst),
Neale Ranns32e1c012016-11-22 17:07:28 +0000578 in6_ptop(dst_ip))
Neale Ranns75152282017-01-09 01:00:45 -0800579
580 # and come from the router's link local
581 self.assertTrue(in6_islladdr(rx[IPv6].src))
582 self.assertEqual(in6_ptop(rx[IPv6].src),
583 in6_ptop(mk_ll_addr(intf.local_mac)))
584
Neale Ranns87df12d2017-02-18 08:16:41 -0800585 # it should contain the links MTU
586 ra = rx[ICMPv6ND_RA]
587 self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu)
588
589 # it should contain the source's link layer address option
590 sll = ra[ICMPv6NDOptSrcLLAddr]
591 self.assertEqual(sll.lladdr, intf.local_mac)
592
593 if not pi_opt:
594 # the RA should not contain prefix information
595 self.assertFalse(ra.haslayer(ICMPv6NDOptPrefixInfo))
596 else:
597 raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1)
598
599 # the options are nested in the scapy packet in way that i cannot
600 # decipher how to decode. this 1st layer of option always returns
601 # nested classes, so a direct obj1=obj2 comparison always fails.
602 # however, the getlayer(.., 2) does give one instnace.
603 # so we cheat here and construct a new opt instnace for comparison
604 rd = ICMPv6NDOptPrefixInfo(prefixlen=raos.prefixlen,
605 prefix=raos.prefix,
606 L=raos.L,
607 A=raos.A)
608 if type(pi_opt) is list:
609 for ii in range(len(pi_opt)):
610 self.assertEqual(pi_opt[ii], rd)
611 rd = rx.getlayer(ICMPv6NDOptPrefixInfo, ii+2)
612 else:
613 self.assertEqual(pi_opt, raos)
614
Neale Ranns32e1c012016-11-22 17:07:28 +0000615 def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None,
Neale Ranns87df12d2017-02-18 08:16:41 -0800616 filter_out_fn=is_ipv6_misc,
617 opt=None):
Neale Ranns32e1c012016-11-22 17:07:28 +0000618 intf.add_stream(pkts)
Neale Ranns32e1c012016-11-22 17:07:28 +0000619 self.pg_enable_capture(self.pg_interfaces)
620 self.pg_start()
621 rx = intf.get_capture(1, filter_out_fn=filter_out_fn)
622
623 self.assertEqual(len(rx), 1)
624 rx = rx[0]
Neale Ranns87df12d2017-02-18 08:16:41 -0800625 self.validate_ra(intf, rx, dst_ip, pi_opt=opt)
Neale Ranns32e1c012016-11-22 17:07:28 +0000626
Neale Ranns75152282017-01-09 01:00:45 -0800627 def test_rs(self):
Klement Sekerada505f62017-01-04 12:58:53 +0100628 """ IPv6 Router Solicitation Exceptions
Neale Ranns75152282017-01-09 01:00:45 -0800629
Klement Sekerada505f62017-01-04 12:58:53 +0100630 Test scenario:
Neale Ranns75152282017-01-09 01:00:45 -0800631 """
632
633 #
Klement Sekerada505f62017-01-04 12:58:53 +0100634 # Before we begin change the IPv6 RA responses to use the unicast
635 # address - that way we will not confuse them with the periodic
636 # RAs which go to the mcast address
Neale Ranns32e1c012016-11-22 17:07:28 +0000637 # Sit and wait for the first periodic RA.
638 #
639 # TODO
Neale Ranns75152282017-01-09 01:00:45 -0800640 #
641 self.pg0.ip6_ra_config(send_unicast=1)
642
643 #
644 # An RS from a link source address
645 # - expect an RA in return
646 #
647 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
648 IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) /
649 ICMPv6ND_RS())
650 pkts = [p]
651 self.send_and_expect_ra(self.pg0, pkts, "Genuine RS")
652
653 #
654 # For the next RS sent the RA should be rate limited
655 #
656 self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited")
657
658 #
659 # When we reconfiure the IPv6 RA config, we reset the RA rate limiting,
Klement Sekerada505f62017-01-04 12:58:53 +0100660 # so we need to do this before each test below so as not to drop
661 # packets for rate limiting reasons. Test this works here.
Neale Ranns75152282017-01-09 01:00:45 -0800662 #
663 self.pg0.ip6_ra_config(send_unicast=1)
664 self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS")
665
666 #
667 # An RS sent from a non-link local source
668 #
669 self.pg0.ip6_ra_config(send_unicast=1)
670 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
671 IPv6(dst=self.pg0.local_ip6, src="2002::ffff") /
672 ICMPv6ND_RS())
673 pkts = [p]
674 self.send_and_assert_no_replies(self.pg0, pkts,
675 "RS from non-link source")
676
677 #
678 # Source an RS from a link local address
679 #
680 self.pg0.ip6_ra_config(send_unicast=1)
681 ll = mk_ll_addr(self.pg0.remote_mac)
682 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
683 IPv6(dst=self.pg0.local_ip6, src=ll) /
684 ICMPv6ND_RS())
685 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000686 self.send_and_expect_ra(self.pg0, pkts,
687 "RS sourced from link-local",
688 dst_ip=ll)
689
690 #
691 # Send the RS multicast
692 #
693 self.pg0.ip6_ra_config(send_unicast=1)
Neale Ranns3f844d02017-02-18 00:03:54 -0800694 dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2"))
Neale Ranns32e1c012016-11-22 17:07:28 +0000695 ll = mk_ll_addr(self.pg0.remote_mac)
696 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
697 IPv6(dst="ff02::2", src=ll) /
698 ICMPv6ND_RS())
699 pkts = [p]
700 self.send_and_expect_ra(self.pg0, pkts,
701 "RS sourced from link-local",
702 dst_ip=ll)
Neale Ranns75152282017-01-09 01:00:45 -0800703
704 #
Klement Sekerada505f62017-01-04 12:58:53 +0100705 # Source from the unspecified address ::. This happens when the RS
706 # is sent before the host has a configured address/sub-net,
707 # i.e. auto-config. Since the sender has no IP address, the reply
708 # comes back mcast - so the capture needs to not filter this.
709 # If we happen to pick up the periodic RA at this point then so be it,
710 # it's not an error.
Neale Ranns75152282017-01-09 01:00:45 -0800711 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000712 self.pg0.ip6_ra_config(send_unicast=1, suppress=1)
713 p = (Ether(dst=dmac, src=self.pg0.remote_mac) /
714 IPv6(dst="ff02::2", src="::") /
Neale Ranns75152282017-01-09 01:00:45 -0800715 ICMPv6ND_RS())
716 pkts = [p]
Neale Ranns32e1c012016-11-22 17:07:28 +0000717 self.send_and_expect_ra(self.pg0, pkts,
718 "RS sourced from unspecified",
719 dst_ip="ff02::1",
720 filter_out_fn=None)
Neale Ranns75152282017-01-09 01:00:45 -0800721
722 #
Neale Ranns87df12d2017-02-18 08:16:41 -0800723 # Configure The RA to announce the links prefix
724 #
725 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
726 self.pg0.local_ip6_prefix_len)
727
728 #
729 # RAs should now contain the prefix information option
730 #
731 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
732 prefix=self.pg0.local_ip6,
733 L=1,
734 A=1)
735
736 self.pg0.ip6_ra_config(send_unicast=1)
737 ll = mk_ll_addr(self.pg0.remote_mac)
738 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
739 IPv6(dst=self.pg0.local_ip6, src=ll) /
740 ICMPv6ND_RS())
741 self.send_and_expect_ra(self.pg0, p,
742 "RA with prefix-info",
743 dst_ip=ll,
744 opt=opt)
745
746 #
747 # Change the prefix info to not off-link
748 # L-flag is clear
749 #
750 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
751 self.pg0.local_ip6_prefix_len,
752 off_link=1)
753
754 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
755 prefix=self.pg0.local_ip6,
756 L=0,
757 A=1)
758
759 self.pg0.ip6_ra_config(send_unicast=1)
760 self.send_and_expect_ra(self.pg0, p,
761 "RA with Prefix info with L-flag=0",
762 dst_ip=ll,
763 opt=opt)
764
765 #
766 # Change the prefix info to not off-link, no-autoconfig
767 # L and A flag are clear in the advert
768 #
769 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
770 self.pg0.local_ip6_prefix_len,
771 off_link=1,
772 no_autoconfig=1)
773
774 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
775 prefix=self.pg0.local_ip6,
776 L=0,
777 A=0)
778
779 self.pg0.ip6_ra_config(send_unicast=1)
780 self.send_and_expect_ra(self.pg0, p,
781 "RA with Prefix info with A & L-flag=0",
782 dst_ip=ll,
783 opt=opt)
784
785 #
786 # Change the flag settings back to the defaults
787 # L and A flag are set in the advert
788 #
789 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
790 self.pg0.local_ip6_prefix_len)
791
792 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
793 prefix=self.pg0.local_ip6,
794 L=1,
795 A=1)
796
797 self.pg0.ip6_ra_config(send_unicast=1)
798 self.send_and_expect_ra(self.pg0, p,
799 "RA with Prefix info",
800 dst_ip=ll,
801 opt=opt)
802
803 #
804 # Change the prefix info to not off-link, no-autoconfig
805 # L and A flag are clear in the advert
806 #
807 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
808 self.pg0.local_ip6_prefix_len,
809 off_link=1,
810 no_autoconfig=1)
811
812 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
813 prefix=self.pg0.local_ip6,
814 L=0,
815 A=0)
816
817 self.pg0.ip6_ra_config(send_unicast=1)
818 self.send_and_expect_ra(self.pg0, p,
819 "RA with Prefix info with A & L-flag=0",
820 dst_ip=ll,
821 opt=opt)
822
823 #
824 # Use the reset to defults option to revert to defaults
825 # L and A flag are clear in the advert
826 #
827 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
828 self.pg0.local_ip6_prefix_len,
829 use_default=1)
830
831 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
832 prefix=self.pg0.local_ip6,
833 L=1,
834 A=1)
835
836 self.pg0.ip6_ra_config(send_unicast=1)
837 self.send_and_expect_ra(self.pg0, p,
838 "RA with Prefix reverted to defaults",
839 dst_ip=ll,
840 opt=opt)
841
842 #
843 # Advertise Another prefix. With no L-flag/A-flag
844 #
845 self.pg0.ip6_ra_prefix(self.pg1.local_ip6n,
846 self.pg1.local_ip6_prefix_len,
847 off_link=1,
848 no_autoconfig=1)
849
850 opt = [ICMPv6NDOptPrefixInfo(prefixlen=self.pg0.local_ip6_prefix_len,
851 prefix=self.pg0.local_ip6,
852 L=1,
853 A=1),
854 ICMPv6NDOptPrefixInfo(prefixlen=self.pg1.local_ip6_prefix_len,
855 prefix=self.pg1.local_ip6,
856 L=0,
857 A=0)]
858
859 self.pg0.ip6_ra_config(send_unicast=1)
860 ll = mk_ll_addr(self.pg0.remote_mac)
861 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
862 IPv6(dst=self.pg0.local_ip6, src=ll) /
863 ICMPv6ND_RS())
864 self.send_and_expect_ra(self.pg0, p,
865 "RA with multiple Prefix infos",
866 dst_ip=ll,
867 opt=opt)
868
869 #
870 # Remove the first refix-info - expect the second is still in the
871 # advert
872 #
873 self.pg0.ip6_ra_prefix(self.pg0.local_ip6n,
874 self.pg0.local_ip6_prefix_len,
875 is_no=1)
876
877 opt = ICMPv6NDOptPrefixInfo(prefixlen=self.pg1.local_ip6_prefix_len,
878 prefix=self.pg1.local_ip6,
879 L=0,
880 A=0)
881
882 self.pg0.ip6_ra_config(send_unicast=1)
883 self.send_and_expect_ra(self.pg0, p,
884 "RA with Prefix reverted to defaults",
885 dst_ip=ll,
886 opt=opt)
887
888 #
889 # Remove the second prefix-info - expect no prefix-info i nthe adverts
890 #
891 self.pg0.ip6_ra_prefix(self.pg1.local_ip6n,
892 self.pg1.local_ip6_prefix_len,
893 is_no=1)
894
895 self.pg0.ip6_ra_config(send_unicast=1)
896 self.send_and_expect_ra(self.pg0, p,
897 "RA with Prefix reverted to defaults",
898 dst_ip=ll)
899
900 #
Neale Ranns5737d882017-02-03 06:14:49 -0800901 # Reset the periodic advertisements back to default values
Neale Ranns75152282017-01-09 01:00:45 -0800902 #
Neale Ranns32e1c012016-11-22 17:07:28 +0000903 self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0)
Damjan Marionf56b77a2016-10-03 19:44:57 +0200904
Neale Ranns3f844d02017-02-18 00:03:54 -0800905
906class IPv6NDProxyTest(TestIPv6ND):
907 """ IPv6 ND ProxyTest Case """
908
909 def setUp(self):
910 super(IPv6NDProxyTest, self).setUp()
911
912 # create 3 pg interfaces
913 self.create_pg_interfaces(range(3))
914
915 # pg0 is the master interface, with the configured subnet
916 self.pg0.admin_up()
917 self.pg0.config_ip6()
918 self.pg0.resolve_ndp()
919
920 self.pg1.ip6_enable()
921 self.pg2.ip6_enable()
922
923 def tearDown(self):
924 super(IPv6NDProxyTest, self).tearDown()
925
926 def test_nd_proxy(self):
927 """ IPv6 Proxy ND """
928
929 #
930 # Generate some hosts in the subnet that we are proxying
931 #
932 self.pg0.generate_remote_hosts(8)
933
934 nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6))
935 d = inet_ntop(AF_INET6, nsma)
936
937 #
938 # Send an NS for one of those remote hosts on one of the proxy links
939 # expect no response since it's from an address that is not
940 # on the link that has the prefix configured
941 #
942 ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) /
943 IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6) /
944 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
945 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac))
946
947 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS")
948
949 #
950 # Add proxy support for the host
951 #
952 self.vapi.ip6_nd_proxy(
953 inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
954 self.pg1.sw_if_index)
955
956 #
957 # try that NS again. this time we expect an NA back
958 #
Neale Ranns2a3ea492017-04-19 05:24:40 -0700959 self.send_and_expect_na(self.pg1, ns_pg1,
960 "NS to proxy entry",
961 dst_ip=self.pg0._remote_hosts[2].ip6,
962 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -0800963
964 #
965 # ... and that we have an entry in the ND cache
966 #
967 self.assertTrue(find_nbr(self,
968 self.pg1.sw_if_index,
969 self.pg0._remote_hosts[2].ip6,
970 inet=AF_INET6))
971
972 #
973 # ... and we can route traffic to it
974 #
975 t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
976 IPv6(dst=self.pg0._remote_hosts[2].ip6,
977 src=self.pg0.remote_ip6) /
978 UDP(sport=10000, dport=20000) /
979 Raw('\xa5' * 100))
980
981 self.pg0.add_stream(t)
982 self.pg_enable_capture(self.pg_interfaces)
983 self.pg_start()
984 rx = self.pg1.get_capture(1)
985 rx = rx[0]
986
987 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
988 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
989
990 self.assertEqual(rx[IPv6].src, t[IPv6].src)
991 self.assertEqual(rx[IPv6].dst, t[IPv6].dst)
992
993 #
994 # Test we proxy for the host on the main interface
995 #
996 ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) /
997 IPv6(dst=d, src=self.pg0.remote_ip6) /
998 ICMPv6ND_NS(tgt=self.pg0._remote_hosts[2].ip6) /
999 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
1000
Neale Ranns2a3ea492017-04-19 05:24:40 -07001001 self.send_and_expect_na(self.pg0, ns_pg0,
1002 "NS to proxy entry on main",
1003 tgt_ip=self.pg0._remote_hosts[2].ip6,
1004 dst_ip=self.pg0.remote_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001005
1006 #
1007 # Setup and resolve proxy for another host on another interface
1008 #
1009 ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) /
1010 IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6) /
1011 ICMPv6ND_NS(tgt=self.pg0.local_ip6) /
1012 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac))
1013
1014 self.vapi.ip6_nd_proxy(
1015 inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1016 self.pg2.sw_if_index)
1017
Neale Ranns2a3ea492017-04-19 05:24:40 -07001018 self.send_and_expect_na(self.pg2, ns_pg2,
1019 "NS to proxy entry other interface",
1020 dst_ip=self.pg0._remote_hosts[3].ip6,
1021 tgt_ip=self.pg0.local_ip6)
Neale Ranns3f844d02017-02-18 00:03:54 -08001022
1023 self.assertTrue(find_nbr(self,
1024 self.pg2.sw_if_index,
1025 self.pg0._remote_hosts[3].ip6,
1026 inet=AF_INET6))
1027
1028 #
1029 # hosts can communicate. pg2->pg1
1030 #
1031 t2 = (Ether(dst=self.pg2.local_mac,
1032 src=self.pg0.remote_hosts[3].mac) /
1033 IPv6(dst=self.pg0._remote_hosts[2].ip6,
1034 src=self.pg0._remote_hosts[3].ip6) /
1035 UDP(sport=10000, dport=20000) /
1036 Raw('\xa5' * 100))
1037
1038 self.pg2.add_stream(t2)
1039 self.pg_enable_capture(self.pg_interfaces)
1040 self.pg_start()
1041 rx = self.pg1.get_capture(1)
1042 rx = rx[0]
1043
1044 self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac)
1045 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
1046
1047 self.assertEqual(rx[IPv6].src, t2[IPv6].src)
1048 self.assertEqual(rx[IPv6].dst, t2[IPv6].dst)
1049
1050 #
1051 # remove the proxy configs
1052 #
1053 self.vapi.ip6_nd_proxy(
1054 inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6),
1055 self.pg1.sw_if_index,
1056 is_del=1)
1057 self.vapi.ip6_nd_proxy(
1058 inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6),
1059 self.pg2.sw_if_index,
1060 is_del=1)
1061
1062 self.assertFalse(find_nbr(self,
1063 self.pg2.sw_if_index,
1064 self.pg0._remote_hosts[3].ip6,
1065 inet=AF_INET6))
1066 self.assertFalse(find_nbr(self,
1067 self.pg1.sw_if_index,
1068 self.pg0._remote_hosts[2].ip6,
1069 inet=AF_INET6))
1070
1071 #
1072 # no longer proxy-ing...
1073 #
1074 self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured")
1075 self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured")
1076 self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured")
1077
1078 #
1079 # no longer forwarding. traffic generates NS out of the glean/main
1080 # interface
1081 #
1082 self.pg2.add_stream(t2)
1083 self.pg_enable_capture(self.pg_interfaces)
1084 self.pg_start()
1085
1086 rx = self.pg0.get_capture(1)
1087
1088 self.assertTrue(rx[0].haslayer(ICMPv6ND_NS))
1089
1090
Neale Ranns37be7362017-02-21 17:30:26 -08001091class TestIPNull(VppTestCase):
1092 """ IPv6 routes via NULL """
1093
1094 def setUp(self):
1095 super(TestIPNull, self).setUp()
1096
1097 # create 2 pg interfaces
1098 self.create_pg_interfaces(range(1))
1099
1100 for i in self.pg_interfaces:
1101 i.admin_up()
1102 i.config_ip6()
1103 i.resolve_ndp()
1104
1105 def tearDown(self):
1106 super(TestIPNull, self).tearDown()
1107 for i in self.pg_interfaces:
1108 i.unconfig_ip6()
1109 i.admin_down()
1110
1111 def test_ip_null(self):
1112 """ IP NULL route """
1113
1114 p = (Ether(src=self.pg0.remote_mac,
1115 dst=self.pg0.local_mac) /
1116 IPv6(src=self.pg0.remote_ip6, dst="2001::1") /
1117 UDP(sport=1234, dport=1234) /
1118 Raw('\xa5' * 100))
1119
1120 #
1121 # A route via IP NULL that will reply with ICMP unreachables
1122 #
1123 ip_unreach = VppIpRoute(self, "2001::", 64, [], is_unreach=1, is_ip6=1)
1124 ip_unreach.add_vpp_config()
1125
1126 self.pg0.add_stream(p)
1127 self.pg_enable_capture(self.pg_interfaces)
1128 self.pg_start()
1129
1130 rx = self.pg0.get_capture(1)
1131 rx = rx[0]
1132 icmp = rx[ICMPv6DestUnreach]
1133
1134 # 0 = "No route to destination"
1135 self.assertEqual(icmp.code, 0)
1136
1137 # ICMP is rate limited. pause a bit
1138 self.sleep(1)
1139
1140 #
1141 # A route via IP NULL that will reply with ICMP prohibited
1142 #
1143 ip_prohibit = VppIpRoute(self, "2001::1", 128, [],
1144 is_prohibit=1, is_ip6=1)
1145 ip_prohibit.add_vpp_config()
1146
1147 self.pg0.add_stream(p)
1148 self.pg_enable_capture(self.pg_interfaces)
1149 self.pg_start()
1150
1151 rx = self.pg0.get_capture(1)
1152 rx = rx[0]
1153 icmp = rx[ICMPv6DestUnreach]
1154
1155 # 1 = "Communication with destination administratively prohibited"
1156 self.assertEqual(icmp.code, 1)
1157
1158
Neale Ranns180279b2017-03-16 15:49:09 -04001159class TestIPDisabled(VppTestCase):
1160 """ IPv6 disabled """
1161
1162 def setUp(self):
1163 super(TestIPDisabled, self).setUp()
1164
1165 # create 2 pg interfaces
1166 self.create_pg_interfaces(range(2))
1167
1168 # PG0 is IP enalbed
1169 self.pg0.admin_up()
1170 self.pg0.config_ip6()
1171 self.pg0.resolve_ndp()
1172
1173 # PG 1 is not IP enabled
1174 self.pg1.admin_up()
1175
1176 def tearDown(self):
1177 super(TestIPDisabled, self).tearDown()
1178 for i in self.pg_interfaces:
1179 i.unconfig_ip4()
1180 i.admin_down()
1181
1182 def send_and_assert_no_replies(self, intf, pkts, remark):
1183 intf.add_stream(pkts)
1184 self.pg_enable_capture(self.pg_interfaces)
1185 self.pg_start()
1186 for i in self.pg_interfaces:
1187 i.get_capture(0)
1188 i.assert_nothing_captured(remark=remark)
1189
1190 def test_ip_disabled(self):
1191 """ IP Disabled """
1192
1193 #
1194 # An (S,G).
1195 # one accepting interface, pg0, 2 forwarding interfaces
1196 #
1197 route_ff_01 = VppIpMRoute(
1198 self,
1199 "::",
1200 "ffef::1", 128,
1201 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
1202 [VppMRoutePath(self.pg1.sw_if_index,
1203 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
1204 VppMRoutePath(self.pg0.sw_if_index,
1205 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
1206 is_ip6=1)
1207 route_ff_01.add_vpp_config()
1208
1209 pu = (Ether(src=self.pg1.remote_mac,
1210 dst=self.pg1.local_mac) /
1211 IPv6(src="2001::1", dst=self.pg0.remote_ip6) /
1212 UDP(sport=1234, dport=1234) /
1213 Raw('\xa5' * 100))
1214 pm = (Ether(src=self.pg1.remote_mac,
1215 dst=self.pg1.local_mac) /
1216 IPv6(src="2001::1", dst="ffef::1") /
1217 UDP(sport=1234, dport=1234) /
1218 Raw('\xa5' * 100))
1219
1220 #
1221 # PG1 does not forward IP traffic
1222 #
1223 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1224 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1225
1226 #
1227 # IP enable PG1
1228 #
1229 self.pg1.config_ip6()
1230
1231 #
1232 # Now we get packets through
1233 #
1234 self.pg1.add_stream(pu)
1235 self.pg_enable_capture(self.pg_interfaces)
1236 self.pg_start()
1237 rx = self.pg0.get_capture(1)
1238
1239 self.pg1.add_stream(pm)
1240 self.pg_enable_capture(self.pg_interfaces)
1241 self.pg_start()
1242 rx = self.pg0.get_capture(1)
1243
1244 #
1245 # Disable PG1
1246 #
1247 self.pg1.unconfig_ip6()
1248
1249 #
1250 # PG1 does not forward IP traffic
1251 #
1252 self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled")
1253 self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled")
1254
1255
Neale Ranns227038a2017-04-21 01:07:59 -07001256class TestIP6LoadBalance(VppTestCase):
1257 """ IPv6 Load-Balancing """
1258
1259 def setUp(self):
1260 super(TestIP6LoadBalance, self).setUp()
1261
1262 self.create_pg_interfaces(range(5))
1263
Neale Ranns15002542017-09-10 04:39:11 -07001264 mpls_tbl = VppMplsTable(self, 0)
1265 mpls_tbl.add_vpp_config()
1266
Neale Ranns227038a2017-04-21 01:07:59 -07001267 for i in self.pg_interfaces:
1268 i.admin_up()
1269 i.config_ip6()
1270 i.resolve_ndp()
Neale Ranns71275e32017-05-25 12:38:58 -07001271 i.enable_mpls()
Neale Ranns227038a2017-04-21 01:07:59 -07001272
1273 def tearDown(self):
Neale Ranns227038a2017-04-21 01:07:59 -07001274 for i in self.pg_interfaces:
1275 i.unconfig_ip6()
1276 i.admin_down()
Neale Ranns71275e32017-05-25 12:38:58 -07001277 i.disable_mpls()
Neale Ranns15002542017-09-10 04:39:11 -07001278 super(TestIP6LoadBalance, self).tearDown()
Neale Ranns227038a2017-04-21 01:07:59 -07001279
1280 def send_and_expect_load_balancing(self, input, pkts, outputs):
1281 input.add_stream(pkts)
1282 self.pg_enable_capture(self.pg_interfaces)
1283 self.pg_start()
1284 for oo in outputs:
1285 rx = oo._get_capture(1)
1286 self.assertNotEqual(0, len(rx))
1287
Neale Ranns71275e32017-05-25 12:38:58 -07001288 def send_and_expect_one_itf(self, input, pkts, itf):
1289 input.add_stream(pkts)
1290 self.pg_enable_capture(self.pg_interfaces)
1291 self.pg_start()
1292 rx = itf.get_capture(len(pkts))
1293
Neale Ranns227038a2017-04-21 01:07:59 -07001294 def test_ip6_load_balance(self):
1295 """ IPv6 Load-Balancing """
1296
1297 #
1298 # An array of packets that differ only in the destination port
Neale Ranns71275e32017-05-25 12:38:58 -07001299 # - IP only
1300 # - MPLS EOS
1301 # - MPLS non-EOS
1302 # - MPLS non-EOS with an entropy label
Neale Ranns227038a2017-04-21 01:07:59 -07001303 #
Neale Ranns71275e32017-05-25 12:38:58 -07001304 port_ip_pkts = []
1305 port_mpls_pkts = []
1306 port_mpls_neos_pkts = []
1307 port_ent_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001308
1309 #
1310 # An array of packets that differ only in the source address
1311 #
Neale Ranns71275e32017-05-25 12:38:58 -07001312 src_ip_pkts = []
1313 src_mpls_pkts = []
Neale Ranns227038a2017-04-21 01:07:59 -07001314
1315 for ii in range(65):
Neale Ranns71275e32017-05-25 12:38:58 -07001316 port_ip_hdr = (IPv6(dst="3000::1", src="3000:1::1") /
1317 UDP(sport=1234, dport=1234 + ii) /
1318 Raw('\xa5' * 100))
1319 port_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1320 dst=self.pg0.local_mac) /
1321 port_ip_hdr))
1322 port_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1323 dst=self.pg0.local_mac) /
1324 MPLS(label=66, ttl=2) /
1325 port_ip_hdr))
1326 port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac,
1327 dst=self.pg0.local_mac) /
1328 MPLS(label=67, ttl=2) /
1329 MPLS(label=77, ttl=2) /
1330 port_ip_hdr))
1331 port_ent_pkts.append((Ether(src=self.pg0.remote_mac,
1332 dst=self.pg0.local_mac) /
1333 MPLS(label=67, ttl=2) /
1334 MPLS(label=14, ttl=2) /
1335 MPLS(label=999, ttl=2) /
1336 port_ip_hdr))
1337 src_ip_hdr = (IPv6(dst="3000::1", src="3000:1::%d" % ii) /
1338 UDP(sport=1234, dport=1234) /
1339 Raw('\xa5' * 100))
1340 src_ip_pkts.append((Ether(src=self.pg0.remote_mac,
1341 dst=self.pg0.local_mac) /
1342 src_ip_hdr))
1343 src_mpls_pkts.append((Ether(src=self.pg0.remote_mac,
1344 dst=self.pg0.local_mac) /
1345 MPLS(label=66, ttl=2) /
1346 src_ip_hdr))
Neale Ranns227038a2017-04-21 01:07:59 -07001347
Neale Ranns71275e32017-05-25 12:38:58 -07001348 #
1349 # A route for the IP pacekts
1350 #
Neale Ranns227038a2017-04-21 01:07:59 -07001351 route_3000_1 = VppIpRoute(self, "3000::1", 128,
1352 [VppRoutePath(self.pg1.remote_ip6,
1353 self.pg1.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001354 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns227038a2017-04-21 01:07:59 -07001355 VppRoutePath(self.pg2.remote_ip6,
1356 self.pg2.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001357 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns227038a2017-04-21 01:07:59 -07001358 is_ip6=1)
1359 route_3000_1.add_vpp_config()
1360
1361 #
Neale Ranns71275e32017-05-25 12:38:58 -07001362 # a local-label for the EOS packets
1363 #
1364 binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1)
1365 binding.add_vpp_config()
1366
1367 #
1368 # An MPLS route for the non-EOS packets
1369 #
1370 route_67 = VppMplsRoute(self, 67, 0,
1371 [VppRoutePath(self.pg1.remote_ip6,
1372 self.pg1.sw_if_index,
1373 labels=[67],
Neale Rannsda78f952017-05-24 09:15:43 -07001374 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns71275e32017-05-25 12:38:58 -07001375 VppRoutePath(self.pg2.remote_ip6,
1376 self.pg2.sw_if_index,
1377 labels=[67],
Neale Rannsda78f952017-05-24 09:15:43 -07001378 proto=DpoProto.DPO_PROTO_IP6)])
Neale Ranns71275e32017-05-25 12:38:58 -07001379 route_67.add_vpp_config()
1380
1381 #
Neale Ranns227038a2017-04-21 01:07:59 -07001382 # inject the packet on pg0 - expect load-balancing across the 2 paths
1383 # - since the default hash config is to use IP src,dst and port
1384 # src,dst
1385 # We are not going to ensure equal amounts of packets across each link,
1386 # since the hash algorithm is statistical and therefore this can never
1387 # be guaranteed. But wuth 64 different packets we do expect some
1388 # balancing. So instead just ensure there is traffic on each link.
1389 #
Neale Ranns71275e32017-05-25 12:38:58 -07001390 self.send_and_expect_load_balancing(self.pg0, port_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001391 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001392 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001393 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001394 self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts,
1395 [self.pg1, self.pg2])
1396 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1397 [self.pg1, self.pg2])
1398 self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts,
1399 [self.pg1, self.pg2])
1400
1401 #
1402 # The packets with Entropy label in should not load-balance,
1403 # since the Entorpy value is fixed.
1404 #
1405 self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1)
Neale Ranns227038a2017-04-21 01:07:59 -07001406
1407 #
1408 # change the flow hash config so it's only IP src,dst
1409 # - now only the stream with differing source address will
1410 # load-balance
1411 #
1412 self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=0, dport=0)
1413
Neale Ranns71275e32017-05-25 12:38:58 -07001414 self.send_and_expect_load_balancing(self.pg0, src_ip_pkts,
Neale Ranns227038a2017-04-21 01:07:59 -07001415 [self.pg1, self.pg2])
Neale Ranns71275e32017-05-25 12:38:58 -07001416 self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts,
1417 [self.pg1, self.pg2])
1418 self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2)
Neale Ranns227038a2017-04-21 01:07:59 -07001419
1420 #
1421 # change the flow hash config back to defaults
1422 #
1423 self.vapi.set_ip_flow_hash(0, is_ip6=1, src=1, dst=1, sport=1, dport=1)
1424
1425 #
1426 # Recursive prefixes
1427 # - testing that 2 stages of load-balancing occurs and there is no
1428 # polarisation (i.e. only 2 of 4 paths are used)
1429 #
1430 port_pkts = []
1431 src_pkts = []
1432
1433 for ii in range(257):
1434 port_pkts.append((Ether(src=self.pg0.remote_mac,
1435 dst=self.pg0.local_mac) /
1436 IPv6(dst="4000::1", src="4000:1::1") /
1437 UDP(sport=1234, dport=1234 + ii) /
1438 Raw('\xa5' * 100)))
1439 src_pkts.append((Ether(src=self.pg0.remote_mac,
1440 dst=self.pg0.local_mac) /
1441 IPv6(dst="4000::1", src="4000:1::%d" % ii) /
1442 UDP(sport=1234, dport=1234) /
1443 Raw('\xa5' * 100)))
1444
1445 route_3000_2 = VppIpRoute(self, "3000::2", 128,
1446 [VppRoutePath(self.pg3.remote_ip6,
1447 self.pg3.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001448 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns227038a2017-04-21 01:07:59 -07001449 VppRoutePath(self.pg4.remote_ip6,
1450 self.pg4.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001451 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns227038a2017-04-21 01:07:59 -07001452 is_ip6=1)
1453 route_3000_2.add_vpp_config()
1454
1455 route_4000_1 = VppIpRoute(self, "4000::1", 128,
1456 [VppRoutePath("3000::1",
1457 0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -07001458 proto=DpoProto.DPO_PROTO_IP6),
Neale Ranns227038a2017-04-21 01:07:59 -07001459 VppRoutePath("3000::2",
1460 0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -07001461 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns227038a2017-04-21 01:07:59 -07001462 is_ip6=1)
1463 route_4000_1.add_vpp_config()
1464
1465 #
1466 # inject the packet on pg0 - expect load-balancing across all 4 paths
1467 #
1468 self.vapi.cli("clear trace")
1469 self.send_and_expect_load_balancing(self.pg0, port_pkts,
1470 [self.pg1, self.pg2,
1471 self.pg3, self.pg4])
1472 self.send_and_expect_load_balancing(self.pg0, src_pkts,
1473 [self.pg1, self.pg2,
1474 self.pg3, self.pg4])
1475
Neale Ranns42e6b092017-07-31 02:56:03 -07001476 #
1477 # Recursive prefixes
1478 # - testing that 2 stages of load-balancing no choices
1479 #
1480 port_pkts = []
1481
1482 for ii in range(257):
1483 port_pkts.append((Ether(src=self.pg0.remote_mac,
1484 dst=self.pg0.local_mac) /
1485 IPv6(dst="6000::1", src="6000:1::1") /
1486 UDP(sport=1234, dport=1234 + ii) /
1487 Raw('\xa5' * 100)))
1488
1489 route_5000_2 = VppIpRoute(self, "5000::2", 128,
1490 [VppRoutePath(self.pg3.remote_ip6,
1491 self.pg3.sw_if_index,
Neale Rannsda78f952017-05-24 09:15:43 -07001492 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns42e6b092017-07-31 02:56:03 -07001493 is_ip6=1)
1494 route_5000_2.add_vpp_config()
1495
1496 route_6000_1 = VppIpRoute(self, "6000::1", 128,
1497 [VppRoutePath("5000::2",
1498 0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -07001499 proto=DpoProto.DPO_PROTO_IP6)],
Neale Ranns42e6b092017-07-31 02:56:03 -07001500 is_ip6=1)
1501 route_6000_1.add_vpp_config()
1502
1503 #
1504 # inject the packet on pg0 - expect load-balancing across all 4 paths
1505 #
1506 self.vapi.cli("clear trace")
1507 self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3)
1508
Neale Ranns227038a2017-04-21 01:07:59 -07001509
Neale Rannsd91c1db2017-07-31 02:30:50 -07001510class TestIP6Punt(VppTestCase):
1511 """ IPv6 Punt Police/Redirect """
1512
1513 def setUp(self):
1514 super(TestIP6Punt, self).setUp()
1515
1516 self.create_pg_interfaces(range(2))
1517
1518 for i in self.pg_interfaces:
1519 i.admin_up()
1520 i.config_ip6()
1521 i.resolve_ndp()
1522
1523 def tearDown(self):
1524 super(TestIP6Punt, self).tearDown()
1525 for i in self.pg_interfaces:
1526 i.unconfig_ip6()
1527 i.admin_down()
1528
1529 def send_and_expect(self, input, pkts, output):
1530 input.add_stream(pkts)
1531 self.pg_enable_capture(self.pg_interfaces)
1532 self.pg_start()
1533 rx = output.get_capture(len(pkts))
1534 return rx
1535
1536 def send_and_assert_no_replies(self, intf, pkts, remark):
1537 self.vapi.cli("clear trace")
1538 intf.add_stream(pkts)
1539 self.pg_enable_capture(self.pg_interfaces)
1540 self.pg_start()
1541 for i in self.pg_interfaces:
1542 i.get_capture(0)
1543 i.assert_nothing_captured(remark=remark)
1544
1545 def test_ip_punt(self):
1546 """ IP6 punt police and redirect """
1547
1548 p = (Ether(src=self.pg0.remote_mac,
1549 dst=self.pg0.local_mac) /
1550 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
1551 TCP(sport=1234, dport=1234) /
1552 Raw('\xa5' * 100))
1553
1554 pkts = p * 1025
1555
1556 #
1557 # Configure a punt redirect via pg1.
1558 #
1559 nh_addr = inet_pton(AF_INET6,
1560 self.pg1.remote_ip6)
1561 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
1562 self.pg1.sw_if_index,
1563 nh_addr,
1564 is_ip6=1)
1565
1566 self.send_and_expect(self.pg0, pkts, self.pg1)
1567
1568 #
1569 # add a policer
1570 #
1571 policer = self.vapi.policer_add_del("ip6-punt", 400, 0, 10, 0,
1572 rate_type=1)
1573 self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
1574
1575 self.vapi.cli("clear trace")
1576 self.pg0.add_stream(pkts)
1577 self.pg_enable_capture(self.pg_interfaces)
1578 self.pg_start()
1579
1580 #
1581 # the number of packet recieved should be greater than 0,
1582 # but not equal to the number sent, since some were policed
1583 #
1584 rx = self.pg1._get_capture(1)
1585 self.assertTrue(len(rx) > 0)
1586 self.assertTrue(len(rx) < len(pkts))
1587
1588 #
1589 # remove the poilcer. back to full rx
1590 #
1591 self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
1592 self.vapi.policer_add_del("ip6-punt", 400, 0, 10, 0,
1593 rate_type=1, is_add=0)
1594 self.send_and_expect(self.pg0, pkts, self.pg1)
1595
1596 #
1597 # remove the redirect. expect full drop.
1598 #
1599 self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
1600 self.pg1.sw_if_index,
1601 nh_addr,
1602 is_add=0,
1603 is_ip6=1)
1604 self.send_and_assert_no_replies(self.pg0, pkts,
1605 "IP no punt config")
1606
1607 #
1608 # Add a redirect that is not input port selective
1609 #
1610 self.vapi.ip_punt_redirect(0xffffffff,
1611 self.pg1.sw_if_index,
1612 nh_addr,
1613 is_ip6=1)
1614 self.send_and_expect(self.pg0, pkts, self.pg1)
1615
1616 self.vapi.ip_punt_redirect(0xffffffff,
1617 self.pg1.sw_if_index,
1618 nh_addr,
1619 is_add=0,
1620 is_ip6=1)
1621
Neale Ranns4c7c8e52017-10-21 09:37:55 -07001622
1623class TestIP6Input(VppTestCase):
1624 """ IPv6 Input Exceptions """
1625
1626 def setUp(self):
1627 super(TestIP6Input, self).setUp()
1628
1629 self.create_pg_interfaces(range(2))
1630
1631 for i in self.pg_interfaces:
1632 i.admin_up()
1633 i.config_ip6()
1634 i.resolve_ndp()
1635
1636 def tearDown(self):
1637 super(TestIP6Input, self).tearDown()
1638 for i in self.pg_interfaces:
1639 i.unconfig_ip6()
1640 i.admin_down()
1641
1642 def send_and_expect(self, input, pkts, output):
1643 self.vapi.cli("clear trace")
1644 input.add_stream(pkts)
1645 self.pg_enable_capture(self.pg_interfaces)
1646 self.pg_start()
1647 rx = output.get_capture(len(pkts))
1648 return rx
1649
1650 def send_and_assert_no_replies(self, intf, pkts, remark):
1651 self.vapi.cli("clear trace")
1652 intf.add_stream(pkts)
1653 self.pg_enable_capture(self.pg_interfaces)
1654 self.pg_start()
1655 for i in self.pg_interfaces:
1656 i.get_capture(0)
1657 i.assert_nothing_captured(remark=remark)
1658
1659 def test_ip_input(self):
1660 """ IP6 Input Exceptions """
1661
1662 #
1663 # bad version - this is dropped
1664 #
1665 p_version = (Ether(src=self.pg0.remote_mac,
1666 dst=self.pg0.local_mac) /
1667 IPv6(src=self.pg0.remote_ip6,
1668 dst=self.pg1.remote_ip6,
1669 version=3) /
1670 UDP(sport=1234, dport=1234) /
1671 Raw('\xa5' * 100))
1672
1673 self.send_and_assert_no_replies(self.pg0, p_version * 65,
1674 "funky version")
1675
1676 #
1677 # hop limit - IMCP replies
1678 #
1679 p_version = (Ether(src=self.pg0.remote_mac,
1680 dst=self.pg0.local_mac) /
1681 IPv6(src=self.pg0.remote_ip6,
1682 dst=self.pg1.remote_ip6,
1683 hlim=1) /
1684 UDP(sport=1234, dport=1234) /
1685 Raw('\xa5' * 100))
1686
1687 rx = self.send_and_expect(self.pg0, p_version * 65, self.pg0)
1688 rx = rx[0]
1689 icmp = rx[ICMPv6TimeExceeded]
1690 self.assertEqual(icmp.type, 3)
1691 # 0: "hop limit exceeded in transit",
1692 self.assertEqual(icmp.code, 0)
1693
1694 self.logger.error(self.vapi.cli("sh error"))
1695
1696
Damjan Marionf56b77a2016-10-03 19:44:57 +02001697if __name__ == '__main__':
Klement Sekeraf62ae122016-10-11 11:47:09 +02001698 unittest.main(testRunner=VppTestRunner)