Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 2 | |
Paul Vinciguerra | 582eac5 | 2020-04-03 12:18:40 -0400 | [diff] [blame] | 3 | import socket |
snaramre | 5d4b891 | 2019-12-13 23:39:35 +0000 | [diff] [blame] | 4 | from socket import inet_pton, inet_ntop |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 5 | import unittest |
| 6 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 7 | from parameterized import parameterized |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 8 | import scapy.compat |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 9 | import scapy.layers.inet6 as inet6 |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 10 | from scapy.layers.inet import UDP, IP |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 11 | from scapy.contrib.mpls import MPLS |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 12 | from scapy.layers.inet6 import ( |
| 13 | IPv6, |
| 14 | ICMPv6ND_NS, |
| 15 | ICMPv6ND_RS, |
| 16 | ICMPv6ND_RA, |
| 17 | ICMPv6NDOptMTU, |
| 18 | ICMPv6NDOptSrcLLAddr, |
| 19 | ICMPv6NDOptPrefixInfo, |
| 20 | ICMPv6ND_NA, |
| 21 | ICMPv6NDOptDstLLAddr, |
| 22 | ICMPv6DestUnreach, |
| 23 | icmp6types, |
| 24 | ICMPv6TimeExceeded, |
| 25 | ICMPv6EchoRequest, |
| 26 | ICMPv6EchoReply, |
| 27 | IPv6ExtHdrHopByHop, |
| 28 | ICMPv6MLReport2, |
| 29 | ICMPv6MLDMultAddrRec, |
| 30 | ) |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 31 | from scapy.layers.l2 import Ether, Dot1Q, GRE |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 32 | from scapy.packet import Raw |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | from scapy.utils6 import ( |
| 34 | in6_getnsma, |
| 35 | in6_getnsmac, |
| 36 | in6_ptop, |
| 37 | in6_islladdr, |
| 38 | in6_mactoifaceid, |
| 39 | ) |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 40 | from six import moves |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 41 | |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 42 | from framework import VppTestCase, VppTestRunner, tag_run_solo |
Paul Vinciguerra | e8fece8 | 2019-02-28 15:34:00 -0800 | [diff] [blame] | 43 | from util import ppp, ip6_normalize, mk_ll_addr |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 44 | from vpp_papi import VppEnum |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 45 | from vpp_ip import DpoProto, VppIpPuntPolicer, VppIpPuntRedirect, VppIpPathMtu |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 46 | from vpp_ip_route import ( |
| 47 | VppIpRoute, |
| 48 | VppRoutePath, |
| 49 | find_route, |
| 50 | VppIpMRoute, |
| 51 | VppMRoutePath, |
| 52 | VppMplsIpBind, |
| 53 | VppMplsRoute, |
| 54 | VppMplsTable, |
| 55 | VppIpTable, |
| 56 | FibPathType, |
| 57 | FibPathProto, |
| 58 | VppIpInterfaceAddress, |
| 59 | find_route_in_dump, |
| 60 | find_mroute_in_dump, |
| 61 | VppIp6LinkLocalAddress, |
| 62 | VppIpRouteV2, |
| 63 | ) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 64 | from vpp_neighbor import find_nbr, VppNeighbor |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 65 | from vpp_ipip_tun_interface import VppIpIpTunInterface |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 66 | from vpp_pg_interface import is_ipv6_misc |
| 67 | from vpp_sub_interface import VppSubInterface, VppDot1QSubint |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 68 | from vpp_policer import VppPolicer, PolicerAction |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 69 | from ipaddress import IPv6Network, IPv6Address |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 70 | from vpp_gre_interface import VppGreInterface |
| 71 | from vpp_teib import VppTeib |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 72 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 73 | AF_INET6 = socket.AF_INET6 |
| 74 | |
Paul Vinciguerra | 1e18eb2 | 2018-11-25 16:09:26 -0800 | [diff] [blame] | 75 | try: |
| 76 | text_type = unicode |
| 77 | except NameError: |
| 78 | text_type = str |
| 79 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 80 | NUM_PKTS = 67 |
| 81 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 82 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 83 | class TestIPv6ND(VppTestCase): |
| 84 | def validate_ra(self, intf, rx, dst_ip=None): |
| 85 | if not dst_ip: |
| 86 | dst_ip = intf.remote_ip6 |
| 87 | |
| 88 | # unicasted packets must come to the unicast mac |
| 89 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 90 | |
| 91 | # and from the router's MAC |
| 92 | self.assertEqual(rx[Ether].src, intf.local_mac) |
| 93 | |
| 94 | # the rx'd RA should be addressed to the sender's source |
| 95 | self.assertTrue(rx.haslayer(ICMPv6ND_RA)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 96 | self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 97 | |
| 98 | # and come from the router's link local |
| 99 | self.assertTrue(in6_islladdr(rx[IPv6].src)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 100 | self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(mk_ll_addr(intf.local_mac))) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 101 | |
| 102 | def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None): |
| 103 | if not dst_ip: |
| 104 | dst_ip = intf.remote_ip6 |
| 105 | if not tgt_ip: |
| 106 | dst_ip = intf.local_ip6 |
| 107 | |
| 108 | # unicasted packets must come to the unicast mac |
| 109 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 110 | |
| 111 | # and from the router's MAC |
| 112 | self.assertEqual(rx[Ether].src, intf.local_mac) |
| 113 | |
| 114 | # the rx'd NA should be addressed to the sender's source |
| 115 | self.assertTrue(rx.haslayer(ICMPv6ND_NA)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 116 | self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 117 | |
| 118 | # and come from the target address |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 119 | self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 120 | |
| 121 | # Dest link-layer options should have the router's MAC |
| 122 | dll = rx[ICMPv6NDOptDstLLAddr] |
| 123 | self.assertEqual(dll.lladdr, intf.local_mac) |
| 124 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 125 | def validate_ns(self, intf, rx, tgt_ip): |
| 126 | nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip)) |
| 127 | dst_ip = inet_ntop(AF_INET6, nsma) |
| 128 | |
| 129 | # NS is broadcast |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 130 | self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma)) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 131 | |
| 132 | # and from the router's MAC |
| 133 | self.assertEqual(rx[Ether].src, intf.local_mac) |
| 134 | |
| 135 | # the rx'd NS should be addressed to an mcast address |
| 136 | # derived from the target address |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 137 | self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 138 | |
| 139 | # expect the tgt IP in the NS header |
| 140 | ns = rx[ICMPv6ND_NS] |
| 141 | self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip)) |
| 142 | |
| 143 | # packet is from the router's local address |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 144 | self.assertEqual(in6_ptop(rx[IPv6].src), intf.local_ip6) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 145 | |
| 146 | # Src link-layer options should have the router's MAC |
| 147 | sll = rx[ICMPv6NDOptSrcLLAddr] |
| 148 | self.assertEqual(sll.lladdr, intf.local_mac) |
| 149 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 150 | def send_and_expect_ra( |
| 151 | self, intf, pkts, remark, dst_ip=None, filter_out_fn=is_ipv6_misc |
| 152 | ): |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 153 | intf.add_stream(pkts) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 154 | self.pg_enable_capture(self.pg_interfaces) |
| 155 | self.pg_start() |
| 156 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 157 | |
| 158 | self.assertEqual(len(rx), 1) |
| 159 | rx = rx[0] |
| 160 | self.validate_ra(intf, rx, dst_ip) |
| 161 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 162 | def send_and_expect_na( |
| 163 | self, intf, pkts, remark, dst_ip=None, tgt_ip=None, filter_out_fn=is_ipv6_misc |
| 164 | ): |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 165 | intf.add_stream(pkts) |
| 166 | self.pg_enable_capture(self.pg_interfaces) |
| 167 | self.pg_start() |
| 168 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 169 | |
| 170 | self.assertEqual(len(rx), 1) |
| 171 | rx = rx[0] |
| 172 | self.validate_na(intf, rx, dst_ip, tgt_ip) |
| 173 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 174 | def send_and_expect_ns( |
| 175 | self, tx_intf, rx_intf, pkts, tgt_ip, filter_out_fn=is_ipv6_misc |
| 176 | ): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 177 | self.vapi.cli("clear trace") |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 178 | tx_intf.add_stream(pkts) |
| 179 | self.pg_enable_capture(self.pg_interfaces) |
| 180 | self.pg_start() |
| 181 | rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 182 | |
| 183 | self.assertEqual(len(rx), 1) |
| 184 | rx = rx[0] |
| 185 | self.validate_ns(rx_intf, rx, tgt_ip) |
| 186 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 187 | def verify_ip(self, rx, smac, dmac, sip, dip): |
| 188 | ether = rx[Ether] |
| 189 | self.assertEqual(ether.dst, dmac) |
| 190 | self.assertEqual(ether.src, smac) |
| 191 | |
| 192 | ip = rx[IPv6] |
| 193 | self.assertEqual(ip.src, sip) |
| 194 | self.assertEqual(ip.dst, dip) |
| 195 | |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 196 | def get_ip6_nd_rx_requests(self, itf): |
| 197 | """Get IP6 ND RX request stats for and interface""" |
| 198 | return self.statistics["/net/ip6-nd/rx/requests"][:, itf.sw_if_index].sum() |
| 199 | |
| 200 | def get_ip6_nd_tx_requests(self, itf): |
| 201 | """Get IP6 ND TX request stats for and interface""" |
| 202 | return self.statistics["/net/ip6-nd/tx/requests"][:, itf.sw_if_index].sum() |
| 203 | |
| 204 | def get_ip6_nd_rx_replies(self, itf): |
| 205 | """Get IP6 ND RX replies stats for and interface""" |
| 206 | return self.statistics["/net/ip6-nd/rx/replies"][:, itf.sw_if_index].sum() |
| 207 | |
| 208 | def get_ip6_nd_tx_replies(self, itf): |
| 209 | """Get IP6 ND TX replies stats for and interface""" |
| 210 | return self.statistics["/net/ip6-nd/tx/replies"][:, itf.sw_if_index].sum() |
| 211 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 212 | |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 213 | @tag_run_solo |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 214 | class TestIPv6(TestIPv6ND): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 215 | """IPv6 Test Case""" |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 216 | |
| 217 | @classmethod |
| 218 | def setUpClass(cls): |
| 219 | super(TestIPv6, cls).setUpClass() |
| 220 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 221 | @classmethod |
| 222 | def tearDownClass(cls): |
| 223 | super(TestIPv6, cls).tearDownClass() |
| 224 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 225 | def setUp(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 226 | """ |
| 227 | Perform test setup before test case. |
| 228 | |
| 229 | **Config:** |
| 230 | - create 3 pg interfaces |
| 231 | - untagged pg0 interface |
| 232 | - Dot1Q subinterface on pg1 |
| 233 | - Dot1AD subinterface on pg2 |
| 234 | - setup interfaces: |
| 235 | - put it into UP state |
| 236 | - set IPv6 addresses |
| 237 | - resolve neighbor address using NDP |
| 238 | - configure 200 fib entries |
| 239 | |
| 240 | :ivar list interfaces: pg interfaces and subinterfaces. |
| 241 | :ivar dict flows: IPv4 packet flows in test. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 242 | |
| 243 | *TODO:* Create AD sub interface |
| 244 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 245 | super(TestIPv6, self).setUp() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 246 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 247 | # create 3 pg interfaces |
| 248 | self.create_pg_interfaces(range(3)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 249 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 250 | # create 2 subinterfaces for p1 and pg2 |
| 251 | self.sub_interfaces = [ |
| 252 | VppDot1QSubint(self, self.pg1, 100), |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 253 | VppDot1QSubint(self, self.pg2, 200) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 254 | # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 255 | ] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 256 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 257 | # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. |
| 258 | self.flows = dict() |
| 259 | self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] |
| 260 | self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] |
| 261 | self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 262 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 263 | # packet sizes |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 264 | self.pg_if_packet_sizes = [64, 1500, 9020] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 265 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 266 | self.interfaces = list(self.pg_interfaces) |
| 267 | self.interfaces.extend(self.sub_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 268 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 269 | # setup all interfaces |
| 270 | for i in self.interfaces: |
| 271 | i.admin_up() |
| 272 | i.config_ip6() |
| 273 | i.resolve_ndp() |
| 274 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 275 | def tearDown(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 276 | """Run standard test teardown and log ``show ip6 neighbors``.""" |
Vladislav Grishenko | 1fb62c0 | 2022-05-16 01:44:43 +0500 | [diff] [blame] | 277 | for i in reversed(self.interfaces): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 278 | i.unconfig_ip6() |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 279 | i.admin_down() |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 280 | for i in self.sub_interfaces: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 281 | i.remove_vpp_config() |
| 282 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 283 | super(TestIPv6, self).tearDown() |
| 284 | if not self.vpp_dead: |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 285 | self.logger.info(self.vapi.cli("show ip6 neighbors")) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 286 | # info(self.vapi.cli("show ip6 fib")) # many entries |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 287 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 288 | def modify_packet(self, src_if, packet_size, pkt): |
| 289 | """Add load, set destination IP and extend packet to required packet |
| 290 | size for defined interface. |
| 291 | |
| 292 | :param VppInterface src_if: Interface to create packet for. |
| 293 | :param int packet_size: Required packet size. |
| 294 | :param Scapy pkt: Packet to be modified. |
| 295 | """ |
snaramre | 07a0f21 | 2019-10-11 21:28:56 +0000 | [diff] [blame] | 296 | dst_if_idx = int(packet_size / 10 % 2) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 297 | dst_if = self.flows[src_if][dst_if_idx] |
| 298 | info = self.create_packet_info(src_if, dst_if) |
| 299 | payload = self.info_to_payload(info) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 300 | p = pkt / Raw(payload) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 301 | p[IPv6].dst = dst_if.remote_ip6 |
| 302 | info.data = p.copy() |
| 303 | if isinstance(src_if, VppSubInterface): |
| 304 | p = src_if.add_dot1_layer(p) |
| 305 | self.extend_packet(p, packet_size) |
| 306 | |
| 307 | return p |
| 308 | |
| 309 | def create_stream(self, src_if): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 310 | """Create input packet stream for defined interface. |
| 311 | |
| 312 | :param VppInterface src_if: Interface to create packet stream for. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 313 | """ |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 314 | hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 315 | pkt_tmpl = ( |
| 316 | Ether(dst=src_if.local_mac, src=src_if.remote_mac) |
| 317 | / IPv6(src=src_if.remote_ip6) |
| 318 | / inet6.UDP(sport=1234, dport=1234) |
| 319 | ) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 320 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 321 | pkts = [ |
| 322 | self.modify_packet(src_if, i, pkt_tmpl) |
| 323 | for i in moves.range( |
| 324 | self.pg_if_packet_sizes[0], self.pg_if_packet_sizes[1], 10 |
| 325 | ) |
| 326 | ] |
| 327 | pkts_b = [ |
| 328 | self.modify_packet(src_if, i, pkt_tmpl) |
| 329 | for i in moves.range( |
| 330 | self.pg_if_packet_sizes[1] + hdr_ext, |
| 331 | self.pg_if_packet_sizes[2] + hdr_ext, |
| 332 | 50, |
| 333 | ) |
| 334 | ] |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 335 | pkts.extend(pkts_b) |
| 336 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 337 | return pkts |
| 338 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 339 | def verify_capture(self, dst_if, capture): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 340 | """Verify captured input packet stream for defined interface. |
| 341 | |
| 342 | :param VppInterface dst_if: Interface to verify captured packet stream |
| 343 | for. |
| 344 | :param list capture: Captured packet stream. |
| 345 | """ |
| 346 | self.logger.info("Verifying capture on interface %s" % dst_if.name) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 347 | last_info = dict() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 348 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 349 | last_info[i.sw_if_index] = None |
| 350 | is_sub_if = False |
| 351 | dst_sw_if_index = dst_if.sw_if_index |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 352 | if hasattr(dst_if, "parent"): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 353 | is_sub_if = True |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 354 | for packet in capture: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 355 | if is_sub_if: |
| 356 | # Check VLAN tags and Ethernet header |
| 357 | packet = dst_if.remove_dot1_layer(packet) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 358 | self.assertTrue(Dot1Q not in packet) |
| 359 | try: |
| 360 | ip = packet[IPv6] |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 361 | udp = packet[inet6.UDP] |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 362 | payload_info = self.payload_to_info(packet[Raw]) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 363 | packet_index = payload_info.index |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 364 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 365 | self.logger.debug( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 366 | "Got packet on port %s: src=%u (id=%u)" |
| 367 | % (dst_if.name, payload_info.src, packet_index) |
| 368 | ) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 369 | next_info = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 370 | payload_info.src, dst_sw_if_index, last_info[payload_info.src] |
| 371 | ) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 372 | last_info[payload_info.src] = next_info |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 373 | self.assertTrue(next_info is not None) |
| 374 | self.assertEqual(packet_index, next_info.index) |
| 375 | saved_packet = next_info.data |
| 376 | # Check standard fields |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 377 | self.assertEqual(ip.src, saved_packet[IPv6].src) |
| 378 | self.assertEqual(ip.dst, saved_packet[IPv6].dst) |
| 379 | self.assertEqual(udp.sport, saved_packet[inet6.UDP].sport) |
| 380 | self.assertEqual(udp.dport, saved_packet[inet6.UDP].dport) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 381 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 382 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 383 | raise |
| 384 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 385 | remaining_packet = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 386 | i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index] |
| 387 | ) |
| 388 | self.assertTrue( |
| 389 | remaining_packet is None, |
| 390 | "Interface %s: Packet expected from interface %s " |
| 391 | "didn't arrive" % (dst_if.name, i.name), |
| 392 | ) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 393 | |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 394 | def test_next_header_anomaly(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 395 | """IPv6 next header anomaly test |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 396 | |
| 397 | Test scenario: |
| 398 | - ipv6 next header field = Fragment Header (44) |
| 399 | - next header is ICMPv6 Echo Request |
| 400 | - wait for reassembly |
| 401 | """ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 402 | pkt = ( |
| 403 | Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) |
| 404 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) |
| 405 | / ICMPv6EchoRequest() |
| 406 | ) |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 407 | |
| 408 | self.pg0.add_stream(pkt) |
| 409 | self.pg_start() |
| 410 | |
| 411 | # wait for reassembly |
| 412 | self.sleep(10) |
| 413 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 414 | def test_fib(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 415 | """IPv6 FIB test |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 416 | |
| 417 | Test scenario: |
| 418 | - Create IPv6 stream for pg0 interface |
| 419 | - Create IPv6 tagged streams for pg1's and pg2's subinterface. |
| 420 | - Send and verify received packets on each interface. |
| 421 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 422 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 423 | pkts = self.create_stream(self.pg0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 424 | self.pg0.add_stream(pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 425 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 426 | for i in self.sub_interfaces: |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 427 | pkts = self.create_stream(i) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 428 | i.parent.add_stream(pkts) |
| 429 | |
| 430 | self.pg_enable_capture(self.pg_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 431 | self.pg_start() |
| 432 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 433 | pkts = self.pg0.get_capture() |
| 434 | self.verify_capture(self.pg0, pkts) |
| 435 | |
| 436 | for i in self.sub_interfaces: |
| 437 | pkts = i.parent.get_capture() |
| 438 | self.verify_capture(i, pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 439 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 440 | def test_ns(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 441 | """IPv6 Neighbour Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 442 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 443 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 444 | - Send an NS Sourced from an address not covered by the link sub-net |
| 445 | - Send an NS to an mcast address the router has not joined |
| 446 | - Send NS for a target address the router does not onn. |
| 447 | """ |
| 448 | |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 449 | n_rx_req_pg0 = self.get_ip6_nd_rx_requests(self.pg0) |
| 450 | n_tx_rep_pg0 = self.get_ip6_nd_tx_replies(self.pg0) |
| 451 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 452 | # |
| 453 | # An NS from a non link source address |
| 454 | # |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 455 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 456 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 457 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 458 | p = ( |
| 459 | Ether(dst=in6_getnsmac(nsma)) |
| 460 | / IPv6(dst=d, src="2002::2") |
| 461 | / ICMPv6ND_NS(tgt=self.pg0.local_ip6) |
| 462 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 463 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 464 | pkts = [p] |
| 465 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 466 | self.send_and_assert_no_replies( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 467 | self.pg0, pkts, "No response to NS source by address not on sub-net" |
| 468 | ) |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 469 | self.assert_equal(self.get_ip6_nd_rx_requests(self.pg0), n_rx_req_pg0 + 1) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 470 | |
| 471 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 472 | # An NS for sent to a solicited mcast group the router is |
| 473 | # not a member of FAILS |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 474 | # |
| 475 | if 0: |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 476 | nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff")) |
| 477 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 478 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 479 | p = ( |
| 480 | Ether(dst=in6_getnsmac(nsma)) |
| 481 | / IPv6(dst=d, src=self.pg0.remote_ip6) |
| 482 | / ICMPv6ND_NS(tgt=self.pg0.local_ip6) |
| 483 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 484 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 485 | pkts = [p] |
| 486 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 487 | self.send_and_assert_no_replies( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 488 | self.pg0, pkts, "No response to NS sent to unjoined mcast address" |
| 489 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 490 | |
| 491 | # |
| 492 | # An NS whose target address is one the router does not own |
| 493 | # |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 494 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 495 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 496 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 497 | p = ( |
| 498 | Ether(dst=in6_getnsmac(nsma)) |
| 499 | / IPv6(dst=d, src=self.pg0.remote_ip6) |
| 500 | / ICMPv6ND_NS(tgt="fd::ffff") |
| 501 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 502 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 503 | pkts = [p] |
| 504 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 505 | self.send_and_assert_no_replies( |
| 506 | self.pg0, pkts, "No response to NS for unknown target" |
| 507 | ) |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 508 | self.assert_equal(self.get_ip6_nd_rx_requests(self.pg0), n_rx_req_pg0 + 2) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 509 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 510 | # |
| 511 | # A neighbor entry that has no associated FIB-entry |
| 512 | # |
| 513 | self.pg0.generate_remote_hosts(4) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 514 | nd_entry = VppNeighbor( |
| 515 | self, |
| 516 | self.pg0.sw_if_index, |
| 517 | self.pg0.remote_hosts[2].mac, |
| 518 | self.pg0.remote_hosts[2].ip6, |
| 519 | is_no_fib_entry=1, |
| 520 | ) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 521 | nd_entry.add_vpp_config() |
| 522 | |
| 523 | # |
| 524 | # check we have the neighbor, but no route |
| 525 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 526 | self.assertTrue( |
| 527 | find_nbr(self, self.pg0.sw_if_index, self.pg0._remote_hosts[2].ip6) |
| 528 | ) |
| 529 | self.assertFalse(find_route(self, self.pg0._remote_hosts[2].ip6, 128)) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 530 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 531 | # |
| 532 | # send an NS from a link local address to the interface's global |
| 533 | # address |
| 534 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 535 | p = ( |
| 536 | Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) |
| 537 | / IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6_ll) |
| 538 | / ICMPv6ND_NS(tgt=self.pg0.local_ip6) |
| 539 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 540 | ) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 541 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 542 | self.send_and_expect_na( |
| 543 | self.pg0, |
| 544 | p, |
| 545 | "NS from link-local", |
| 546 | dst_ip=self.pg0._remote_hosts[2].ip6_ll, |
| 547 | tgt_ip=self.pg0.local_ip6, |
| 548 | ) |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 549 | self.assert_equal(self.get_ip6_nd_rx_requests(self.pg0), n_rx_req_pg0 + 3) |
| 550 | self.assert_equal(self.get_ip6_nd_tx_replies(self.pg0), n_tx_rep_pg0 + 1) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 551 | |
| 552 | # |
| 553 | # we should have learned an ND entry for the peer's link-local |
| 554 | # but not inserted a route to it in the FIB |
| 555 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 556 | self.assertTrue( |
| 557 | find_nbr(self, self.pg0.sw_if_index, self.pg0._remote_hosts[2].ip6_ll) |
| 558 | ) |
| 559 | self.assertFalse(find_route(self, self.pg0._remote_hosts[2].ip6_ll, 128)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 560 | |
| 561 | # |
| 562 | # An NS to the router's own Link-local |
| 563 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 564 | p = ( |
| 565 | Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) |
| 566 | / IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6_ll) |
| 567 | / ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) |
| 568 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 569 | ) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 570 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 571 | self.send_and_expect_na( |
| 572 | self.pg0, |
| 573 | p, |
| 574 | "NS to/from link-local", |
| 575 | dst_ip=self.pg0._remote_hosts[3].ip6_ll, |
| 576 | tgt_ip=self.pg0.local_ip6_ll, |
| 577 | ) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 578 | |
| 579 | # |
Neale Ranns | e2b6736 | 2021-04-02 07:34:39 +0000 | [diff] [blame] | 580 | # do not respond to a NS for the peer's address |
| 581 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 582 | p = ( |
| 583 | Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) |
| 584 | / IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6_ll) |
| 585 | / ICMPv6ND_NS(tgt=self.pg0._remote_hosts[3].ip6_ll) |
| 586 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 587 | ) |
Neale Ranns | e2b6736 | 2021-04-02 07:34:39 +0000 | [diff] [blame] | 588 | |
| 589 | self.send_and_assert_no_replies(self.pg0, p) |
| 590 | |
| 591 | # |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 592 | # we should have learned an ND entry for the peer's link-local |
| 593 | # but not inserted a route to it in the FIB |
| 594 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 595 | self.assertTrue( |
| 596 | find_nbr(self, self.pg0.sw_if_index, self.pg0._remote_hosts[3].ip6_ll) |
| 597 | ) |
| 598 | self.assertFalse(find_route(self, self.pg0._remote_hosts[3].ip6_ll, 128)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 599 | |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 600 | def test_nd_incomplete(self): |
| 601 | """IP6-ND Incomplete""" |
| 602 | self.pg1.generate_remote_hosts(3) |
| 603 | |
| 604 | p0 = ( |
| 605 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 606 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_hosts[1].ip6) |
| 607 | / UDP(sport=1234, dport=1234) |
| 608 | / Raw() |
| 609 | ) |
| 610 | |
| 611 | # |
| 612 | # a packet to an unresolved destination generates an ND request |
| 613 | # |
| 614 | n_tx_req_pg1 = self.get_ip6_nd_tx_requests(self.pg1) |
| 615 | self.send_and_expect_ns(self.pg0, self.pg1, p0, self.pg1.remote_hosts[1].ip6) |
| 616 | self.assert_equal(self.get_ip6_nd_tx_requests(self.pg1), n_tx_req_pg1 + 1) |
| 617 | |
| 618 | # |
| 619 | # a reply to the request |
| 620 | # |
| 621 | self.assert_equal(self.get_ip6_nd_rx_replies(self.pg1), 0) |
| 622 | na = ( |
| 623 | Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) |
| 624 | / IPv6(dst=self.pg1.local_ip6, src=self.pg1.remote_hosts[1].ip6) |
| 625 | / ICMPv6ND_NA(tgt=self.pg1.remote_hosts[1].ip6) |
| 626 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg1.remote_hosts[1].mac) |
| 627 | ) |
| 628 | self.send_and_assert_no_replies(self.pg1, [na]) |
| 629 | self.assert_equal(self.get_ip6_nd_rx_replies(self.pg1), 1) |
| 630 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 631 | def test_ns_duplicates(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 632 | """ND Duplicates""" |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 633 | |
| 634 | # |
| 635 | # Generate some hosts on the LAN |
| 636 | # |
| 637 | self.pg1.generate_remote_hosts(3) |
| 638 | |
| 639 | # |
| 640 | # Add host 1 on pg1 and pg2 |
| 641 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 642 | ns_pg1 = VppNeighbor( |
| 643 | self, |
| 644 | self.pg1.sw_if_index, |
| 645 | self.pg1.remote_hosts[1].mac, |
| 646 | self.pg1.remote_hosts[1].ip6, |
| 647 | ) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 648 | ns_pg1.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 649 | ns_pg2 = VppNeighbor( |
| 650 | self, |
| 651 | self.pg2.sw_if_index, |
| 652 | self.pg2.remote_mac, |
| 653 | self.pg1.remote_hosts[1].ip6, |
| 654 | ) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 655 | ns_pg2.add_vpp_config() |
| 656 | |
| 657 | # |
| 658 | # IP packet destined for pg1 remote host arrives on pg1 again. |
| 659 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 660 | p = ( |
| 661 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 662 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_hosts[1].ip6) |
| 663 | / inet6.UDP(sport=1234, dport=1234) |
| 664 | / Raw() |
| 665 | ) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 666 | |
| 667 | self.pg0.add_stream(p) |
| 668 | self.pg_enable_capture(self.pg_interfaces) |
| 669 | self.pg_start() |
| 670 | |
| 671 | rx1 = self.pg1.get_capture(1) |
| 672 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 673 | self.verify_ip( |
| 674 | rx1[0], |
| 675 | self.pg1.local_mac, |
| 676 | self.pg1.remote_hosts[1].mac, |
| 677 | self.pg0.remote_ip6, |
| 678 | self.pg1.remote_hosts[1].ip6, |
| 679 | ) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 680 | |
| 681 | # |
| 682 | # remove the duplicate on pg1 |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 683 | # packet stream should generate NSs out of pg1 |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 684 | # |
| 685 | ns_pg1.remove_vpp_config() |
| 686 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 687 | self.send_and_expect_ns(self.pg0, self.pg1, p, self.pg1.remote_hosts[1].ip6) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 688 | |
| 689 | # |
| 690 | # Add it back |
| 691 | # |
| 692 | ns_pg1.add_vpp_config() |
| 693 | |
| 694 | self.pg0.add_stream(p) |
| 695 | self.pg_enable_capture(self.pg_interfaces) |
| 696 | self.pg_start() |
| 697 | |
| 698 | rx1 = self.pg1.get_capture(1) |
| 699 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 700 | self.verify_ip( |
| 701 | rx1[0], |
| 702 | self.pg1.local_mac, |
| 703 | self.pg1.remote_hosts[1].mac, |
| 704 | self.pg0.remote_ip6, |
| 705 | self.pg1.remote_hosts[1].ip6, |
| 706 | ) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 707 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 708 | def validate_ra(self, intf, rx, dst_ip=None, src_ip=None, mtu=9000, pi_opt=None): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 709 | if not dst_ip: |
| 710 | dst_ip = intf.remote_ip6 |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 711 | if not src_ip: |
| 712 | src_ip = mk_ll_addr(intf.local_mac) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 713 | |
Neale Ranns | 5737d88 | 2017-02-03 06:14:49 -0800 | [diff] [blame] | 714 | # unicasted packets must come to the unicast mac |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 715 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 716 | |
| 717 | # and from the router's MAC |
| 718 | self.assertEqual(rx[Ether].src, intf.local_mac) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 719 | |
| 720 | # the rx'd RA should be addressed to the sender's source |
| 721 | self.assertTrue(rx.haslayer(ICMPv6ND_RA)) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 722 | self.assertEqual(in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 723 | |
| 724 | # and come from the router's link local |
| 725 | self.assertTrue(in6_islladdr(rx[IPv6].src)) |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 726 | self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 727 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 728 | # it should contain the links MTU |
| 729 | ra = rx[ICMPv6ND_RA] |
| 730 | self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu) |
| 731 | |
| 732 | # it should contain the source's link layer address option |
| 733 | sll = ra[ICMPv6NDOptSrcLLAddr] |
| 734 | self.assertEqual(sll.lladdr, intf.local_mac) |
| 735 | |
| 736 | if not pi_opt: |
| 737 | # the RA should not contain prefix information |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 738 | self.assertFalse(ra.haslayer(ICMPv6NDOptPrefixInfo)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 739 | else: |
| 740 | raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1) |
| 741 | |
| 742 | # the options are nested in the scapy packet in way that i cannot |
| 743 | # decipher how to decode. this 1st layer of option always returns |
| 744 | # nested classes, so a direct obj1=obj2 comparison always fails. |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 745 | # however, the getlayer(.., 2) does give one instance. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 746 | # so we cheat here and construct a new opt instance for comparison |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 747 | rd = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 748 | prefixlen=raos.prefixlen, prefix=raos.prefix, L=raos.L, A=raos.A |
| 749 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 750 | if type(pi_opt) is list: |
| 751 | for ii in range(len(pi_opt)): |
| 752 | self.assertEqual(pi_opt[ii], rd) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 753 | rd = rx.getlayer(ICMPv6NDOptPrefixInfo, ii + 2) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 754 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 755 | self.assertEqual( |
| 756 | pi_opt, |
| 757 | raos, |
| 758 | "Expected: %s, received: %s" |
| 759 | % (pi_opt.show(dump=True), raos.show(dump=True)), |
| 760 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 761 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 762 | def send_and_expect_ra( |
| 763 | self, |
| 764 | intf, |
| 765 | pkts, |
| 766 | remark, |
| 767 | dst_ip=None, |
| 768 | filter_out_fn=is_ipv6_misc, |
| 769 | opt=None, |
| 770 | src_ip=None, |
| 771 | ): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 772 | self.vapi.cli("clear trace") |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 773 | intf.add_stream(pkts) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 774 | self.pg_enable_capture(self.pg_interfaces) |
| 775 | self.pg_start() |
| 776 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 777 | |
| 778 | self.assertEqual(len(rx), 1) |
| 779 | rx = rx[0] |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 780 | self.validate_ra(intf, rx, dst_ip, src_ip=src_ip, pi_opt=opt) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 781 | |
Alexander Chernavin | 3b28fd7 | 2023-02-02 14:22:56 +0000 | [diff] [blame] | 782 | def test_ip6_ra_dump(self): |
| 783 | """IPv6 RA dump""" |
| 784 | |
| 785 | # Dump IPv6 RA for all interfaces |
| 786 | ip6_ra_dump = self.vapi.sw_interface_ip6nd_ra_dump(sw_if_index=0xFFFFFFFF) |
| 787 | self.assertEqual(len(ip6_ra_dump), len(self.interfaces)) |
| 788 | |
| 789 | for ip6_ra in ip6_ra_dump: |
| 790 | self.assertFalse(ip6_ra.send_radv) |
| 791 | self.assertEqual(ip6_ra.n_prefixes, 0) |
| 792 | self.assertEqual(len(ip6_ra.prefixes), 0) |
| 793 | self.assertEqual(ip6_ra.last_radv_time, 0.0) |
| 794 | self.assertEqual(ip6_ra.last_multicast_time, 0.0) |
| 795 | self.assertEqual(ip6_ra.next_multicast_time, 0.0) |
| 796 | self.assertEqual(ip6_ra.n_advertisements_sent, 0) |
| 797 | self.assertEqual(ip6_ra.n_solicitations_rcvd, 0) |
| 798 | self.assertEqual(ip6_ra.n_solicitations_dropped, 0) |
| 799 | |
| 800 | # Enable sending IPv6 RA for an interface |
| 801 | self.pg0.ip6_ra_config(no=1, suppress=1) |
| 802 | |
| 803 | # Add IPv6 RA prefixes for the interface |
| 804 | pfx0 = IPv6Network( |
| 805 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len), strict=False |
| 806 | ) |
| 807 | pfx1 = IPv6Network("fafa::/96") |
| 808 | self.pg0.ip6_ra_prefix(pfx0, off_link=0, no_autoconfig=0) |
| 809 | self.pg0.ip6_ra_prefix(pfx1, off_link=1, no_autoconfig=1) |
| 810 | |
| 811 | # Wait for multicast IPv6 RA |
| 812 | self.sleep(1) |
| 813 | |
| 814 | # Dump IPv6 RA for the interface |
| 815 | ip6_ra_dump = self.vapi.sw_interface_ip6nd_ra_dump( |
| 816 | sw_if_index=self.pg0.sw_if_index |
| 817 | ) |
| 818 | self.assertEqual(len(ip6_ra_dump), 1) |
| 819 | ip6_ra = ip6_ra_dump[0] |
| 820 | |
| 821 | self.assertEqual(ip6_ra.sw_if_index, self.pg0.sw_if_index) |
| 822 | self.assertTrue(ip6_ra.send_radv) |
| 823 | self.assertEqual(ip6_ra.n_prefixes, 2) |
| 824 | self.assertEqual(len(ip6_ra.prefixes), 2) |
| 825 | self.assertEqual(ip6_ra.last_radv_time, 0.0) |
| 826 | self.assertGreater(ip6_ra.last_multicast_time, 0.0) |
| 827 | self.assertGreater(ip6_ra.next_multicast_time, 0.0) |
| 828 | self.assertGreater(ip6_ra.n_advertisements_sent, 0) |
| 829 | self.assertEqual(ip6_ra.n_solicitations_rcvd, 0) |
| 830 | self.assertEqual(ip6_ra.n_solicitations_dropped, 0) |
| 831 | |
| 832 | self.assertEqual(ip6_ra.prefixes[0].prefix, pfx0) |
| 833 | self.assertTrue(ip6_ra.prefixes[0].onlink_flag) |
| 834 | self.assertTrue(ip6_ra.prefixes[0].autonomous_flag) |
| 835 | self.assertFalse(ip6_ra.prefixes[0].no_advertise) |
| 836 | |
| 837 | self.assertEqual(ip6_ra.prefixes[1].prefix, pfx1) |
| 838 | self.assertFalse(ip6_ra.prefixes[1].onlink_flag) |
| 839 | self.assertFalse(ip6_ra.prefixes[1].autonomous_flag) |
| 840 | self.assertFalse(ip6_ra.prefixes[1].no_advertise) |
| 841 | |
| 842 | # Reset sending IPv6 RA for the interface |
| 843 | self.pg0.ip6_ra_config(suppress=1) |
| 844 | |
| 845 | # Remove IPv6 RA prefixes for the interface |
| 846 | self.pg0.ip6_ra_prefix(pfx0, is_no=1) |
| 847 | self.pg0.ip6_ra_prefix(pfx1, is_no=1) |
| 848 | |
| 849 | # Dump IPv6 RA for the interface |
| 850 | ip6_ra_dump = self.vapi.sw_interface_ip6nd_ra_dump( |
| 851 | sw_if_index=self.pg0.sw_if_index |
| 852 | ) |
| 853 | self.assertEqual(len(ip6_ra_dump), 1) |
| 854 | ip6_ra = ip6_ra_dump[0] |
| 855 | |
| 856 | self.assertEqual(ip6_ra.sw_if_index, self.pg0.sw_if_index) |
| 857 | self.assertFalse(ip6_ra.send_radv) |
| 858 | self.assertEqual(ip6_ra.n_prefixes, 0) |
| 859 | self.assertEqual(len(ip6_ra.prefixes), 0) |
| 860 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 861 | def test_rs(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 862 | """IPv6 Router Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 863 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 864 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 865 | """ |
| 866 | |
Alexander Chernavin | e99f762 | 2022-03-05 15:51:54 +0000 | [diff] [blame] | 867 | self.pg0.ip6_ra_config(no=1, suppress=1) |
| 868 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 869 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 870 | # Before we begin change the IPv6 RA responses to use the unicast |
| 871 | # address - that way we will not confuse them with the periodic |
| 872 | # RAs which go to the mcast address |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 873 | # Sit and wait for the first periodic RA. |
| 874 | # |
| 875 | # TODO |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 876 | # |
| 877 | self.pg0.ip6_ra_config(send_unicast=1) |
| 878 | |
| 879 | # |
| 880 | # An RS from a link source address |
| 881 | # - expect an RA in return |
| 882 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 883 | p = ( |
| 884 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 885 | / IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) |
| 886 | / ICMPv6ND_RS() |
| 887 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 888 | pkts = [p] |
| 889 | self.send_and_expect_ra(self.pg0, pkts, "Genuine RS") |
| 890 | |
| 891 | # |
| 892 | # For the next RS sent the RA should be rate limited |
| 893 | # |
| 894 | self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited") |
| 895 | |
| 896 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 897 | # When we reconfigure the IPv6 RA config, |
| 898 | # we reset the RA rate limiting, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 899 | # so we need to do this before each test below so as not to drop |
| 900 | # packets for rate limiting reasons. Test this works here. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 901 | # |
| 902 | self.pg0.ip6_ra_config(send_unicast=1) |
| 903 | self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS") |
| 904 | |
| 905 | # |
| 906 | # An RS sent from a non-link local source |
| 907 | # |
| 908 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 909 | p = ( |
| 910 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 911 | / IPv6(dst=self.pg0.local_ip6, src="2002::ffff") |
| 912 | / ICMPv6ND_RS() |
| 913 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 914 | pkts = [p] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 915 | self.send_and_assert_no_replies(self.pg0, pkts, "RS from non-link source") |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 916 | |
| 917 | # |
| 918 | # Source an RS from a link local address |
| 919 | # |
| 920 | self.pg0.ip6_ra_config(send_unicast=1) |
| 921 | ll = mk_ll_addr(self.pg0.remote_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 922 | p = ( |
| 923 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 924 | / IPv6(dst=self.pg0.local_ip6, src=ll) |
| 925 | / ICMPv6ND_RS() |
| 926 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 927 | pkts = [p] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 928 | self.send_and_expect_ra(self.pg0, pkts, "RS sourced from link-local", dst_ip=ll) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 929 | |
| 930 | # |
Ole Troan | 5d280d5 | 2021-08-06 09:58:09 +0200 | [diff] [blame] | 931 | # Source an RS from a link local address |
| 932 | # Ensure suppress also applies to solicited RS |
| 933 | # |
| 934 | self.pg0.ip6_ra_config(send_unicast=1, suppress=1) |
| 935 | ll = mk_ll_addr(self.pg0.remote_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 936 | p = ( |
| 937 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 938 | / IPv6(dst=self.pg0.local_ip6, src=ll) |
| 939 | / ICMPv6ND_RS() |
| 940 | ) |
Ole Troan | 5d280d5 | 2021-08-06 09:58:09 +0200 | [diff] [blame] | 941 | pkts = [p] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 942 | self.send_and_assert_no_replies(self.pg0, pkts, "Suppressed RS from link-local") |
Ole Troan | 5d280d5 | 2021-08-06 09:58:09 +0200 | [diff] [blame] | 943 | |
| 944 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 945 | # Send the RS multicast |
| 946 | # |
Ole Troan | 5d280d5 | 2021-08-06 09:58:09 +0200 | [diff] [blame] | 947 | self.pg0.ip6_ra_config(no=1, suppress=1) # Reset suppress flag to zero |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 948 | self.pg0.ip6_ra_config(send_unicast=1) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 949 | dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2")) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 950 | ll = mk_ll_addr(self.pg0.remote_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 951 | p = ( |
| 952 | Ether(dst=dmac, src=self.pg0.remote_mac) |
| 953 | / IPv6(dst="ff02::2", src=ll) |
| 954 | / ICMPv6ND_RS() |
| 955 | ) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 956 | pkts = [p] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 957 | self.send_and_expect_ra(self.pg0, pkts, "RS sourced from link-local", dst_ip=ll) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 958 | |
| 959 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 960 | # Source from the unspecified address ::. This happens when the RS |
| 961 | # is sent before the host has a configured address/sub-net, |
| 962 | # i.e. auto-config. Since the sender has no IP address, the reply |
| 963 | # comes back mcast - so the capture needs to not filter this. |
| 964 | # If we happen to pick up the periodic RA at this point then so be it, |
| 965 | # it's not an error. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 966 | # |
Alexander Chernavin | e99f762 | 2022-03-05 15:51:54 +0000 | [diff] [blame] | 967 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 968 | p = ( |
| 969 | Ether(dst=dmac, src=self.pg0.remote_mac) |
| 970 | / IPv6(dst="ff02::2", src="::") |
| 971 | / ICMPv6ND_RS() |
| 972 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 973 | pkts = [p] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 974 | self.send_and_expect_ra( |
| 975 | self.pg0, |
| 976 | pkts, |
| 977 | "RS sourced from unspecified", |
| 978 | dst_ip="ff02::1", |
| 979 | filter_out_fn=None, |
| 980 | ) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 981 | |
| 982 | # |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 983 | # Configure The RA to announce the links prefix |
| 984 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 985 | self.pg0.ip6_ra_prefix( |
| 986 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len) |
| 987 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 988 | |
| 989 | # |
| 990 | # RAs should now contain the prefix information option |
| 991 | # |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 992 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 993 | prefixlen=self.pg0.local_ip6_prefix_len, prefix=self.pg0.local_ip6, L=1, A=1 |
| 994 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 995 | |
| 996 | self.pg0.ip6_ra_config(send_unicast=1) |
| 997 | ll = mk_ll_addr(self.pg0.remote_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 998 | p = ( |
| 999 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 1000 | / IPv6(dst=self.pg0.local_ip6, src=ll) |
| 1001 | / ICMPv6ND_RS() |
| 1002 | ) |
| 1003 | self.send_and_expect_ra(self.pg0, p, "RA with prefix-info", dst_ip=ll, opt=opt) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1004 | |
| 1005 | # |
| 1006 | # Change the prefix info to not off-link |
| 1007 | # L-flag is clear |
| 1008 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1009 | self.pg0.ip6_ra_prefix( |
| 1010 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len), off_link=1 |
| 1011 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1012 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1013 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1014 | prefixlen=self.pg0.local_ip6_prefix_len, prefix=self.pg0.local_ip6, L=0, A=1 |
| 1015 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1016 | |
| 1017 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1018 | self.send_and_expect_ra( |
| 1019 | self.pg0, p, "RA with Prefix info with L-flag=0", dst_ip=ll, opt=opt |
| 1020 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1021 | |
| 1022 | # |
| 1023 | # Change the prefix info to not off-link, no-autoconfig |
| 1024 | # L and A flag are clear in the advert |
| 1025 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1026 | self.pg0.ip6_ra_prefix( |
| 1027 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len), |
| 1028 | off_link=1, |
| 1029 | no_autoconfig=1, |
| 1030 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1031 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1032 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1033 | prefixlen=self.pg0.local_ip6_prefix_len, prefix=self.pg0.local_ip6, L=0, A=0 |
| 1034 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1035 | |
| 1036 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1037 | self.send_and_expect_ra( |
| 1038 | self.pg0, p, "RA with Prefix info with A & L-flag=0", dst_ip=ll, opt=opt |
| 1039 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1040 | |
| 1041 | # |
| 1042 | # Change the flag settings back to the defaults |
| 1043 | # L and A flag are set in the advert |
| 1044 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1045 | self.pg0.ip6_ra_prefix( |
| 1046 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len) |
| 1047 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1048 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1049 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1050 | prefixlen=self.pg0.local_ip6_prefix_len, prefix=self.pg0.local_ip6, L=1, A=1 |
| 1051 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1052 | |
| 1053 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1054 | self.send_and_expect_ra(self.pg0, p, "RA with Prefix info", dst_ip=ll, opt=opt) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1055 | |
| 1056 | # |
| 1057 | # Change the prefix info to not off-link, no-autoconfig |
| 1058 | # L and A flag are clear in the advert |
| 1059 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1060 | self.pg0.ip6_ra_prefix( |
| 1061 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len), |
| 1062 | off_link=1, |
| 1063 | no_autoconfig=1, |
| 1064 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1065 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1066 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1067 | prefixlen=self.pg0.local_ip6_prefix_len, prefix=self.pg0.local_ip6, L=0, A=0 |
| 1068 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1069 | |
| 1070 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1071 | self.send_and_expect_ra( |
| 1072 | self.pg0, p, "RA with Prefix info with A & L-flag=0", dst_ip=ll, opt=opt |
| 1073 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1074 | |
| 1075 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1076 | # Use the reset to defaults option to revert to defaults |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1077 | # L and A flag are clear in the advert |
| 1078 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1079 | self.pg0.ip6_ra_prefix( |
| 1080 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len), use_default=1 |
| 1081 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1082 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1083 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1084 | prefixlen=self.pg0.local_ip6_prefix_len, prefix=self.pg0.local_ip6, L=1, A=1 |
| 1085 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1086 | |
| 1087 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1088 | self.send_and_expect_ra( |
| 1089 | self.pg0, p, "RA with Prefix reverted to defaults", dst_ip=ll, opt=opt |
| 1090 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1091 | |
| 1092 | # |
| 1093 | # Advertise Another prefix. With no L-flag/A-flag |
| 1094 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1095 | self.pg0.ip6_ra_prefix( |
| 1096 | "%s/%s" % (self.pg1.local_ip6, self.pg1.local_ip6_prefix_len), |
| 1097 | off_link=1, |
| 1098 | no_autoconfig=1, |
| 1099 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1100 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1101 | opt = [ |
| 1102 | ICMPv6NDOptPrefixInfo( |
| 1103 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 1104 | prefix=self.pg0.local_ip6, |
| 1105 | L=1, |
| 1106 | A=1, |
| 1107 | ), |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1108 | ICMPv6NDOptPrefixInfo( |
| 1109 | prefixlen=self.pg1.local_ip6_prefix_len, |
| 1110 | prefix=self.pg1.local_ip6, |
| 1111 | L=0, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1112 | A=0, |
| 1113 | ), |
| 1114 | ] |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1115 | |
| 1116 | self.pg0.ip6_ra_config(send_unicast=1) |
| 1117 | ll = mk_ll_addr(self.pg0.remote_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1118 | p = ( |
| 1119 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 1120 | / IPv6(dst=self.pg0.local_ip6, src=ll) |
| 1121 | / ICMPv6ND_RS() |
| 1122 | ) |
| 1123 | self.send_and_expect_ra( |
| 1124 | self.pg0, p, "RA with multiple Prefix infos", dst_ip=ll, opt=opt |
| 1125 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1126 | |
| 1127 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1128 | # Remove the first prefix-info - expect the second is still in the |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1129 | # advert |
| 1130 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1131 | self.pg0.ip6_ra_prefix( |
| 1132 | "%s/%s" % (self.pg0.local_ip6, self.pg0.local_ip6_prefix_len), is_no=1 |
| 1133 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1134 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1135 | opt = ICMPv6NDOptPrefixInfo( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1136 | prefixlen=self.pg1.local_ip6_prefix_len, prefix=self.pg1.local_ip6, L=0, A=0 |
| 1137 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1138 | |
| 1139 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1140 | self.send_and_expect_ra( |
| 1141 | self.pg0, p, "RA with Prefix reverted to defaults", dst_ip=ll, opt=opt |
| 1142 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1143 | |
| 1144 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1145 | # Remove the second prefix-info - expect no prefix-info in the adverts |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1146 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1147 | self.pg0.ip6_ra_prefix( |
| 1148 | "%s/%s" % (self.pg1.local_ip6, self.pg1.local_ip6_prefix_len), is_no=1 |
| 1149 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1150 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1151 | # |
| 1152 | # change the link's link local, so we know that works too. |
| 1153 | # |
| 1154 | self.vapi.sw_interface_ip6_set_link_local_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1155 | sw_if_index=self.pg0.sw_if_index, ip="fe80::88" |
| 1156 | ) |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1157 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1158 | self.pg0.ip6_ra_config(send_unicast=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1159 | self.send_and_expect_ra( |
| 1160 | self.pg0, |
| 1161 | p, |
| 1162 | "RA with Prefix reverted to defaults", |
| 1163 | dst_ip=ll, |
| 1164 | src_ip="fe80::88", |
| 1165 | ) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 1166 | |
| 1167 | # |
Neale Ranns | 5737d88 | 2017-02-03 06:14:49 -0800 | [diff] [blame] | 1168 | # Reset the periodic advertisements back to default values |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1169 | # |
Alexander Chernavin | e99f762 | 2022-03-05 15:51:54 +0000 | [diff] [blame] | 1170 | self.pg0.ip6_ra_config(suppress=1) |
| 1171 | self.pg0.ip6_ra_config(no=1, send_unicast=1) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 1172 | |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 1173 | def test_mld(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1174 | """MLD Report""" |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 1175 | # |
| 1176 | # test one MLD is sent after applying an IPv6 Address on an interface |
| 1177 | # |
| 1178 | self.pg_enable_capture(self.pg_interfaces) |
| 1179 | self.pg_start() |
| 1180 | |
| 1181 | subitf = VppDot1QSubint(self, self.pg1, 99) |
Vladislav Grishenko | 1fb62c0 | 2022-05-16 01:44:43 +0500 | [diff] [blame] | 1182 | self.interfaces.append(subitf) |
| 1183 | self.sub_interfaces.append(subitf) |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 1184 | |
| 1185 | subitf.admin_up() |
| 1186 | subitf.config_ip6() |
| 1187 | |
Neale Ranns | 03c254e | 2020-03-17 14:25:10 +0000 | [diff] [blame] | 1188 | rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None) |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 1189 | |
| 1190 | # |
| 1191 | # hunt for the MLD on vlan 99 |
| 1192 | # |
| 1193 | for rx in rxs: |
| 1194 | # make sure ipv6 packets with hop by hop options have |
| 1195 | # correct checksums |
| 1196 | self.assert_packet_checksums_valid(rx) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1197 | if ( |
| 1198 | rx.haslayer(IPv6ExtHdrHopByHop) |
| 1199 | and rx.haslayer(Dot1Q) |
| 1200 | and rx[Dot1Q].vlan == 99 |
| 1201 | ): |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 1202 | mld = rx[ICMPv6MLReport2] |
| 1203 | |
| 1204 | self.assertEqual(mld.records_number, 4) |
| 1205 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1206 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1207 | class TestIPv6RouteLookup(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1208 | """IPv6 Route Lookup Test Case""" |
| 1209 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1210 | routes = [] |
| 1211 | |
| 1212 | def route_lookup(self, prefix, exact): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1213 | return self.vapi.api( |
| 1214 | self.vapi.papi.ip_route_lookup, |
| 1215 | { |
| 1216 | "table_id": 0, |
| 1217 | "exact": exact, |
| 1218 | "prefix": prefix, |
| 1219 | }, |
| 1220 | ) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1221 | |
| 1222 | @classmethod |
| 1223 | def setUpClass(cls): |
| 1224 | super(TestIPv6RouteLookup, cls).setUpClass() |
| 1225 | |
| 1226 | @classmethod |
| 1227 | def tearDownClass(cls): |
| 1228 | super(TestIPv6RouteLookup, cls).tearDownClass() |
| 1229 | |
| 1230 | def setUp(self): |
| 1231 | super(TestIPv6RouteLookup, self).setUp() |
| 1232 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1233 | drop_nh = VppRoutePath("::1", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_DROP) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1234 | |
| 1235 | # Add 3 routes |
| 1236 | r = VppIpRoute(self, "2001:1111::", 32, [drop_nh]) |
| 1237 | r.add_vpp_config() |
| 1238 | self.routes.append(r) |
| 1239 | |
| 1240 | r = VppIpRoute(self, "2001:1111:2222::", 48, [drop_nh]) |
| 1241 | r.add_vpp_config() |
| 1242 | self.routes.append(r) |
| 1243 | |
| 1244 | r = VppIpRoute(self, "2001:1111:2222::1", 128, [drop_nh]) |
| 1245 | r.add_vpp_config() |
| 1246 | self.routes.append(r) |
| 1247 | |
| 1248 | def tearDown(self): |
| 1249 | # Remove the routes we added |
| 1250 | for r in self.routes: |
| 1251 | r.remove_vpp_config() |
| 1252 | |
| 1253 | super(TestIPv6RouteLookup, self).tearDown() |
| 1254 | |
| 1255 | def test_exact_match(self): |
| 1256 | # Verify we find the host route |
| 1257 | prefix = "2001:1111:2222::1/128" |
| 1258 | result = self.route_lookup(prefix, True) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1259 | assert prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1260 | |
| 1261 | # Verify we find a middle prefix route |
| 1262 | prefix = "2001:1111:2222::/48" |
| 1263 | result = self.route_lookup(prefix, True) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1264 | assert prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1265 | |
| 1266 | # Verify we do not find an available LPM. |
| 1267 | with self.vapi.assert_negative_api_retval(): |
| 1268 | self.route_lookup("2001::2/128", True) |
| 1269 | |
| 1270 | def test_longest_prefix_match(self): |
| 1271 | # verify we find lpm |
| 1272 | lpm_prefix = "2001:1111:2222::/48" |
| 1273 | result = self.route_lookup("2001:1111:2222::2/128", False) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1274 | assert lpm_prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1275 | |
| 1276 | # Verify we find the exact when not requested |
| 1277 | result = self.route_lookup(lpm_prefix, False) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1278 | assert lpm_prefix == str(result.route.prefix) |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 1279 | |
| 1280 | # Can't seem to delete the default route so no negative LPM test. |
| 1281 | |
| 1282 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1283 | class TestIPv6IfAddrRoute(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1284 | """IPv6 Interface Addr Route Test Case""" |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1285 | |
| 1286 | @classmethod |
| 1287 | def setUpClass(cls): |
| 1288 | super(TestIPv6IfAddrRoute, cls).setUpClass() |
| 1289 | |
| 1290 | @classmethod |
| 1291 | def tearDownClass(cls): |
| 1292 | super(TestIPv6IfAddrRoute, cls).tearDownClass() |
| 1293 | |
| 1294 | def setUp(self): |
| 1295 | super(TestIPv6IfAddrRoute, self).setUp() |
| 1296 | |
| 1297 | # create 1 pg interface |
| 1298 | self.create_pg_interfaces(range(1)) |
| 1299 | |
| 1300 | for i in self.pg_interfaces: |
| 1301 | i.admin_up() |
| 1302 | i.config_ip6() |
| 1303 | i.resolve_ndp() |
| 1304 | |
| 1305 | def tearDown(self): |
| 1306 | super(TestIPv6IfAddrRoute, self).tearDown() |
| 1307 | for i in self.pg_interfaces: |
| 1308 | i.unconfig_ip6() |
| 1309 | i.admin_down() |
| 1310 | |
| 1311 | def test_ipv6_ifaddrs_same_prefix(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1312 | """IPv6 Interface Addresses Same Prefix test |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1313 | |
| 1314 | Test scenario: |
| 1315 | |
| 1316 | - Verify no route in FIB for prefix 2001:10::/64 |
| 1317 | - Configure IPv4 address 2001:10::10/64 on an interface |
| 1318 | - Verify route in FIB for prefix 2001:10::/64 |
| 1319 | - Configure IPv4 address 2001:10::20/64 on an interface |
| 1320 | - Delete 2001:10::10/64 from interface |
| 1321 | - Verify route in FIB for prefix 2001:10::/64 |
| 1322 | - Delete 2001:10::20/64 from interface |
| 1323 | - Verify no route in FIB for prefix 2001:10::/64 |
| 1324 | """ |
| 1325 | |
| 1326 | addr1 = "2001:10::10" |
| 1327 | addr2 = "2001:10::20" |
| 1328 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1329 | if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64) |
| 1330 | if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64) |
| 1331 | self.assertFalse(if_addr1.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1332 | self.assertFalse(find_route(self, addr1, 128)) |
| 1333 | self.assertFalse(find_route(self, addr2, 128)) |
| 1334 | |
| 1335 | # configure first address, verify route present |
| 1336 | if_addr1.add_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1337 | self.assertTrue(if_addr1.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1338 | self.assertTrue(find_route(self, addr1, 128)) |
| 1339 | self.assertFalse(find_route(self, addr2, 128)) |
| 1340 | |
| 1341 | # configure second address, delete first, verify route not removed |
| 1342 | if_addr2.add_vpp_config() |
| 1343 | if_addr1.remove_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1344 | self.assertFalse(if_addr1.query_vpp_config()) |
| 1345 | self.assertTrue(if_addr2.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1346 | self.assertFalse(find_route(self, addr1, 128)) |
| 1347 | self.assertTrue(find_route(self, addr2, 128)) |
| 1348 | |
| 1349 | # delete second address, verify route removed |
| 1350 | if_addr2.remove_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1351 | self.assertFalse(if_addr1.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1352 | self.assertFalse(find_route(self, addr1, 128)) |
| 1353 | self.assertFalse(find_route(self, addr2, 128)) |
| 1354 | |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 1355 | def test_ipv6_ifaddr_del(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1356 | """Delete an interface address that does not exist""" |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 1357 | |
| 1358 | loopbacks = self.create_loopback_interfaces(1) |
| 1359 | lo = self.lo_interfaces[0] |
| 1360 | |
| 1361 | lo.config_ip6() |
| 1362 | lo.admin_up() |
| 1363 | |
| 1364 | # |
| 1365 | # try and remove pg0's subnet from lo |
| 1366 | # |
| 1367 | with self.vapi.assert_negative_api_retval(): |
| 1368 | self.vapi.sw_interface_add_del_address( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1369 | sw_if_index=lo.sw_if_index, prefix=self.pg0.local_ip6_prefix, is_add=0 |
| 1370 | ) |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 1371 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1372 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1373 | class TestICMPv6Echo(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1374 | """ICMPv6 Echo Test Case""" |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1375 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1376 | @classmethod |
| 1377 | def setUpClass(cls): |
| 1378 | super(TestICMPv6Echo, cls).setUpClass() |
| 1379 | |
| 1380 | @classmethod |
| 1381 | def tearDownClass(cls): |
| 1382 | super(TestICMPv6Echo, cls).tearDownClass() |
| 1383 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1384 | def setUp(self): |
| 1385 | super(TestICMPv6Echo, self).setUp() |
| 1386 | |
| 1387 | # create 1 pg interface |
| 1388 | self.create_pg_interfaces(range(1)) |
| 1389 | |
| 1390 | for i in self.pg_interfaces: |
| 1391 | i.admin_up() |
| 1392 | i.config_ip6() |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1393 | i.resolve_ndp(link_layer=True) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1394 | i.resolve_ndp() |
| 1395 | |
| 1396 | def tearDown(self): |
| 1397 | super(TestICMPv6Echo, self).tearDown() |
| 1398 | for i in self.pg_interfaces: |
| 1399 | i.unconfig_ip6() |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1400 | i.admin_down() |
| 1401 | |
| 1402 | def test_icmpv6_echo(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1403 | """VPP replies to ICMPv6 Echo Request |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1404 | |
| 1405 | Test scenario: |
| 1406 | |
| 1407 | - Receive ICMPv6 Echo Request message on pg0 interface. |
| 1408 | - Check outgoing ICMPv6 Echo Reply message on pg0 interface. |
| 1409 | """ |
| 1410 | |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1411 | # test both with global and local ipv6 addresses |
| 1412 | dsts = (self.pg0.local_ip6, self.pg0.local_ip6_ll) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1413 | id = 0xB |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1414 | seq = 5 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1415 | data = b"\x0a" * 18 |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1416 | p = list() |
| 1417 | for dst in dsts: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1418 | p.append( |
| 1419 | ( |
| 1420 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 1421 | / IPv6(src=self.pg0.remote_ip6, dst=dst) |
| 1422 | / ICMPv6EchoRequest(id=id, seq=seq, data=data) |
| 1423 | ) |
| 1424 | ) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1425 | |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1426 | self.pg0.add_stream(p) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1427 | self.pg_enable_capture(self.pg_interfaces) |
| 1428 | self.pg_start() |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1429 | rxs = self.pg0.get_capture(len(dsts)) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1430 | |
Benoît Ganne | 2699fe2 | 2021-01-18 19:25:38 +0100 | [diff] [blame] | 1431 | for rx, dst in zip(rxs, dsts): |
| 1432 | ether = rx[Ether] |
| 1433 | ipv6 = rx[IPv6] |
| 1434 | icmpv6 = rx[ICMPv6EchoReply] |
| 1435 | self.assertEqual(ether.src, self.pg0.local_mac) |
| 1436 | self.assertEqual(ether.dst, self.pg0.remote_mac) |
| 1437 | self.assertEqual(ipv6.src, dst) |
| 1438 | self.assertEqual(ipv6.dst, self.pg0.remote_ip6) |
| 1439 | self.assertEqual(icmp6types[icmpv6.type], "Echo Reply") |
| 1440 | self.assertEqual(icmpv6.id, id) |
| 1441 | self.assertEqual(icmpv6.seq, seq) |
| 1442 | self.assertEqual(icmpv6.data, data) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1443 | |
| 1444 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1445 | class TestIPv6RD(TestIPv6ND): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1446 | """IPv6 Router Discovery Test Case""" |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1447 | |
| 1448 | @classmethod |
| 1449 | def setUpClass(cls): |
| 1450 | super(TestIPv6RD, cls).setUpClass() |
| 1451 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1452 | @classmethod |
| 1453 | def tearDownClass(cls): |
| 1454 | super(TestIPv6RD, cls).tearDownClass() |
| 1455 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1456 | def setUp(self): |
| 1457 | super(TestIPv6RD, self).setUp() |
| 1458 | |
| 1459 | # create 2 pg interfaces |
| 1460 | self.create_pg_interfaces(range(2)) |
| 1461 | |
| 1462 | self.interfaces = list(self.pg_interfaces) |
| 1463 | |
| 1464 | # setup all interfaces |
| 1465 | for i in self.interfaces: |
| 1466 | i.admin_up() |
| 1467 | i.config_ip6() |
| 1468 | |
| 1469 | def tearDown(self): |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 1470 | for i in self.interfaces: |
| 1471 | i.unconfig_ip6() |
| 1472 | i.admin_down() |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1473 | super(TestIPv6RD, self).tearDown() |
| 1474 | |
| 1475 | def test_rd_send_router_solicitation(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1476 | """Verify router solicitation packets""" |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1477 | |
| 1478 | count = 2 |
| 1479 | self.pg_enable_capture(self.pg_interfaces) |
| 1480 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1481 | self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index, mrc=count) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1482 | rx_list = self.pg1.get_capture(count, timeout=3) |
| 1483 | self.assertEqual(len(rx_list), count) |
| 1484 | for packet in rx_list: |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1485 | self.assertEqual(packet.haslayer(IPv6), 1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1486 | self.assertEqual(packet[IPv6].haslayer(ICMPv6ND_RS), 1) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1487 | dst = ip6_normalize(packet[IPv6].dst) |
| 1488 | dst2 = ip6_normalize("ff02::2") |
| 1489 | self.assert_equal(dst, dst2) |
| 1490 | src = ip6_normalize(packet[IPv6].src) |
| 1491 | src2 = ip6_normalize(self.pg1.local_ip6_ll) |
| 1492 | self.assert_equal(src, src2) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1493 | self.assertTrue(bool(packet[ICMPv6ND_RS].haslayer(ICMPv6NDOptSrcLLAddr))) |
| 1494 | self.assert_equal(packet[ICMPv6NDOptSrcLLAddr].lladdr, self.pg1.local_mac) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1495 | |
| 1496 | def verify_prefix_info(self, reported_prefix, prefix_option): |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1497 | prefix = IPv6Network( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1498 | text_type( |
| 1499 | prefix_option.getfieldval("prefix") |
| 1500 | + "/" |
| 1501 | + text_type(prefix_option.getfieldval("prefixlen")) |
| 1502 | ), |
| 1503 | strict=False, |
| 1504 | ) |
| 1505 | self.assert_equal( |
| 1506 | reported_prefix.prefix.network_address, prefix.network_address |
| 1507 | ) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1508 | L = prefix_option.getfieldval("L") |
| 1509 | A = prefix_option.getfieldval("A") |
| 1510 | option_flags = (L << 7) | (A << 6) |
| 1511 | self.assert_equal(reported_prefix.flags, option_flags) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1512 | self.assert_equal( |
| 1513 | reported_prefix.valid_time, prefix_option.getfieldval("validlifetime") |
| 1514 | ) |
| 1515 | self.assert_equal( |
| 1516 | reported_prefix.preferred_time, |
| 1517 | prefix_option.getfieldval("preferredlifetime"), |
| 1518 | ) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1519 | |
| 1520 | def test_rd_receive_router_advertisement(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1521 | """Verify events triggered by received RA packets""" |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1522 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1523 | self.vapi.want_ip6_ra_events(enable=1) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1524 | |
| 1525 | prefix_info_1 = ICMPv6NDOptPrefixInfo( |
| 1526 | prefix="1::2", |
| 1527 | prefixlen=50, |
| 1528 | validlifetime=200, |
| 1529 | preferredlifetime=500, |
| 1530 | L=1, |
| 1531 | A=1, |
| 1532 | ) |
| 1533 | |
| 1534 | prefix_info_2 = ICMPv6NDOptPrefixInfo( |
| 1535 | prefix="7::4", |
| 1536 | prefixlen=20, |
| 1537 | validlifetime=70, |
| 1538 | preferredlifetime=1000, |
| 1539 | L=1, |
| 1540 | A=0, |
| 1541 | ) |
| 1542 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1543 | p = ( |
| 1544 | Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) |
| 1545 | / IPv6(dst=self.pg1.local_ip6_ll, src=mk_ll_addr(self.pg1.remote_mac)) |
| 1546 | / ICMPv6ND_RA() |
| 1547 | / prefix_info_1 |
| 1548 | / prefix_info_2 |
| 1549 | ) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1550 | self.pg1.add_stream([p]) |
| 1551 | self.pg_start() |
| 1552 | |
| 1553 | ev = self.vapi.wait_for_event(10, "ip6_ra_event") |
| 1554 | |
| 1555 | self.assert_equal(ev.current_hop_limit, 0) |
| 1556 | self.assert_equal(ev.flags, 8) |
| 1557 | self.assert_equal(ev.router_lifetime_in_sec, 1800) |
| 1558 | self.assert_equal(ev.neighbor_reachable_time_in_msec, 0) |
| 1559 | self.assert_equal( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1560 | ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0 |
| 1561 | ) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1562 | |
| 1563 | self.assert_equal(ev.n_prefixes, 2) |
| 1564 | |
| 1565 | self.verify_prefix_info(ev.prefixes[0], prefix_info_1) |
| 1566 | self.verify_prefix_info(ev.prefixes[1], prefix_info_2) |
| 1567 | |
| 1568 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1569 | class TestIPv6RDControlPlane(TestIPv6ND): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1570 | """IPv6 Router Discovery Control Plane Test Case""" |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1571 | |
| 1572 | @classmethod |
| 1573 | def setUpClass(cls): |
| 1574 | super(TestIPv6RDControlPlane, cls).setUpClass() |
| 1575 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1576 | @classmethod |
| 1577 | def tearDownClass(cls): |
| 1578 | super(TestIPv6RDControlPlane, cls).tearDownClass() |
| 1579 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1580 | def setUp(self): |
| 1581 | super(TestIPv6RDControlPlane, self).setUp() |
| 1582 | |
| 1583 | # create 1 pg interface |
| 1584 | self.create_pg_interfaces(range(1)) |
| 1585 | |
| 1586 | self.interfaces = list(self.pg_interfaces) |
| 1587 | |
| 1588 | # setup all interfaces |
| 1589 | for i in self.interfaces: |
| 1590 | i.admin_up() |
| 1591 | i.config_ip6() |
| 1592 | |
| 1593 | def tearDown(self): |
| 1594 | super(TestIPv6RDControlPlane, self).tearDown() |
| 1595 | |
| 1596 | @staticmethod |
| 1597 | def create_ra_packet(pg, routerlifetime=None): |
| 1598 | src_ip = pg.remote_ip6_ll |
| 1599 | dst_ip = pg.local_ip6 |
| 1600 | if routerlifetime is not None: |
| 1601 | ra = ICMPv6ND_RA(routerlifetime=routerlifetime) |
| 1602 | else: |
| 1603 | ra = ICMPv6ND_RA() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1604 | p = ( |
| 1605 | Ether(dst=pg.local_mac, src=pg.remote_mac) |
| 1606 | / IPv6(dst=dst_ip, src=src_ip) |
| 1607 | / ra |
| 1608 | ) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1609 | return p |
| 1610 | |
| 1611 | @staticmethod |
| 1612 | def get_default_routes(fib): |
| 1613 | list = [] |
| 1614 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1615 | if entry.route.prefix.prefixlen == 0: |
| 1616 | for path in entry.route.paths: |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1617 | if path.sw_if_index != 0xFFFFFFFF: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1618 | defaut_route = {} |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1619 | defaut_route["sw_if_index"] = path.sw_if_index |
| 1620 | defaut_route["next_hop"] = path.nh.address.ip6 |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1621 | list.append(defaut_route) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1622 | return list |
| 1623 | |
| 1624 | @staticmethod |
| 1625 | def get_interface_addresses(fib, pg): |
| 1626 | list = [] |
| 1627 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1628 | if entry.route.prefix.prefixlen == 128: |
| 1629 | path = entry.route.paths[0] |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1630 | if path.sw_if_index == pg.sw_if_index: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1631 | list.append(str(entry.route.prefix.network_address)) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1632 | return list |
| 1633 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1634 | def wait_for_no_default_route(self, n_tries=50, s_time=1): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1635 | while n_tries: |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1636 | fib = self.vapi.ip_route_dump(0, True) |
| 1637 | default_routes = self.get_default_routes(fib) |
Ole Troan | 6e6ad64 | 2020-02-04 13:28:13 +0100 | [diff] [blame] | 1638 | if 0 == len(default_routes): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1639 | return True |
| 1640 | n_tries = n_tries - 1 |
| 1641 | self.sleep(s_time) |
| 1642 | |
| 1643 | return False |
| 1644 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1645 | def test_all(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1646 | """Test handling of SLAAC addresses and default routes""" |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1647 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1648 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1649 | default_routes = self.get_default_routes(fib) |
| 1650 | initial_addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1651 | self.assertEqual(default_routes, []) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1652 | router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll)) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1653 | |
| 1654 | self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1) |
| 1655 | |
| 1656 | self.sleep(0.1) |
| 1657 | |
| 1658 | # send RA |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1659 | packet = ( |
| 1660 | self.create_ra_packet(self.pg0) |
| 1661 | / ICMPv6NDOptPrefixInfo( |
| 1662 | prefix="1::", |
| 1663 | prefixlen=64, |
| 1664 | validlifetime=2, |
| 1665 | preferredlifetime=2, |
| 1666 | L=1, |
| 1667 | A=1, |
| 1668 | ) |
| 1669 | / ICMPv6NDOptPrefixInfo( |
| 1670 | prefix="7::", |
| 1671 | prefixlen=20, |
| 1672 | validlifetime=1500, |
| 1673 | preferredlifetime=1000, |
| 1674 | L=1, |
| 1675 | A=0, |
| 1676 | ) |
| 1677 | ) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1678 | self.pg0.add_stream([packet]) |
| 1679 | self.pg_start() |
| 1680 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1681 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1682 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1683 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1684 | |
| 1685 | # check FIB for new address |
| 1686 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1687 | new_addresses = addresses.difference(initial_addresses) |
| 1688 | self.assertEqual(len(new_addresses), 1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1689 | prefix = IPv6Network( |
| 1690 | text_type("%s/%d" % (list(new_addresses)[0], 20)), strict=False |
| 1691 | ) |
| 1692 | self.assertEqual(prefix, IPv6Network(text_type("1::/20"))) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1693 | |
| 1694 | # check FIB for new default route |
| 1695 | default_routes = self.get_default_routes(fib) |
| 1696 | self.assertEqual(len(default_routes), 1) |
| 1697 | dr = default_routes[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1698 | self.assertEqual(dr["sw_if_index"], self.pg0.sw_if_index) |
| 1699 | self.assertEqual(dr["next_hop"], router_address) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1700 | |
| 1701 | # send RA to delete default route |
| 1702 | packet = self.create_ra_packet(self.pg0, routerlifetime=0) |
| 1703 | self.pg0.add_stream([packet]) |
| 1704 | self.pg_start() |
| 1705 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1706 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1707 | |
| 1708 | # check that default route is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1709 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1710 | default_routes = self.get_default_routes(fib) |
| 1711 | self.assertEqual(len(default_routes), 0) |
| 1712 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1713 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1714 | |
| 1715 | # send RA |
| 1716 | packet = self.create_ra_packet(self.pg0) |
| 1717 | self.pg0.add_stream([packet]) |
| 1718 | self.pg_start() |
| 1719 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1720 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1721 | |
| 1722 | # check FIB for new default route |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1723 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1724 | default_routes = self.get_default_routes(fib) |
| 1725 | self.assertEqual(len(default_routes), 1) |
| 1726 | dr = default_routes[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1727 | self.assertEqual(dr["sw_if_index"], self.pg0.sw_if_index) |
| 1728 | self.assertEqual(dr["next_hop"], router_address) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1729 | |
| 1730 | # send RA, updating router lifetime to 1s |
| 1731 | packet = self.create_ra_packet(self.pg0, 1) |
| 1732 | self.pg0.add_stream([packet]) |
| 1733 | self.pg_start() |
| 1734 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1735 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1736 | |
| 1737 | # check that default route still exists |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1738 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1739 | default_routes = self.get_default_routes(fib) |
| 1740 | self.assertEqual(len(default_routes), 1) |
| 1741 | dr = default_routes[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1742 | self.assertEqual(dr["sw_if_index"], self.pg0.sw_if_index) |
| 1743 | self.assertEqual(dr["next_hop"], router_address) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1744 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1745 | self.sleep_on_vpp_time(1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1746 | |
| 1747 | # check that default route is deleted |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1748 | self.assertTrue(self.wait_for_no_default_route()) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1749 | |
| 1750 | # check FIB still contains the SLAAC address |
| 1751 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1752 | new_addresses = addresses.difference(initial_addresses) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1753 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1754 | self.assertEqual(len(new_addresses), 1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1755 | prefix = IPv6Network( |
| 1756 | text_type("%s/%d" % (list(new_addresses)[0], 20)), strict=False |
| 1757 | ) |
| 1758 | self.assertEqual(prefix, IPv6Network(text_type("1::/20"))) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1759 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1760 | self.sleep_on_vpp_time(1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1761 | |
| 1762 | # check that SLAAC address is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1763 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1764 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1765 | new_addresses = addresses.difference(initial_addresses) |
| 1766 | self.assertEqual(len(new_addresses), 0) |
| 1767 | |
| 1768 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1769 | class IPv6NDProxyTest(TestIPv6ND): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1770 | """IPv6 ND ProxyTest Case""" |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1771 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1772 | @classmethod |
| 1773 | def setUpClass(cls): |
| 1774 | super(IPv6NDProxyTest, cls).setUpClass() |
| 1775 | |
| 1776 | @classmethod |
| 1777 | def tearDownClass(cls): |
| 1778 | super(IPv6NDProxyTest, cls).tearDownClass() |
| 1779 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1780 | def setUp(self): |
| 1781 | super(IPv6NDProxyTest, self).setUp() |
| 1782 | |
| 1783 | # create 3 pg interfaces |
| 1784 | self.create_pg_interfaces(range(3)) |
| 1785 | |
| 1786 | # pg0 is the master interface, with the configured subnet |
| 1787 | self.pg0.admin_up() |
| 1788 | self.pg0.config_ip6() |
| 1789 | self.pg0.resolve_ndp() |
| 1790 | |
| 1791 | self.pg1.ip6_enable() |
| 1792 | self.pg2.ip6_enable() |
| 1793 | |
| 1794 | def tearDown(self): |
| 1795 | super(IPv6NDProxyTest, self).tearDown() |
| 1796 | |
| 1797 | def test_nd_proxy(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1798 | """IPv6 Proxy ND""" |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1799 | |
| 1800 | # |
| 1801 | # Generate some hosts in the subnet that we are proxying |
| 1802 | # |
| 1803 | self.pg0.generate_remote_hosts(8) |
| 1804 | |
| 1805 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 1806 | d = inet_ntop(AF_INET6, nsma) |
| 1807 | |
| 1808 | # |
| 1809 | # Send an NS for one of those remote hosts on one of the proxy links |
| 1810 | # expect no response since it's from an address that is not |
| 1811 | # on the link that has the prefix configured |
| 1812 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1813 | ns_pg1 = ( |
| 1814 | Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) |
| 1815 | / IPv6(dst=d, src=self.pg0._remote_hosts[2].ip6) |
| 1816 | / ICMPv6ND_NS(tgt=self.pg0.local_ip6) |
| 1817 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac) |
| 1818 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1819 | |
| 1820 | self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS") |
| 1821 | |
| 1822 | # |
| 1823 | # Add proxy support for the host |
| 1824 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1825 | self.vapi.ip6nd_proxy_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1826 | is_add=1, |
| 1827 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), |
| 1828 | sw_if_index=self.pg1.sw_if_index, |
| 1829 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1830 | |
| 1831 | # |
| 1832 | # try that NS again. this time we expect an NA back |
| 1833 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1834 | self.send_and_expect_na( |
| 1835 | self.pg1, |
| 1836 | ns_pg1, |
| 1837 | "NS to proxy entry", |
| 1838 | dst_ip=self.pg0._remote_hosts[2].ip6, |
| 1839 | tgt_ip=self.pg0.local_ip6, |
| 1840 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1841 | |
| 1842 | # |
| 1843 | # ... and that we have an entry in the ND cache |
| 1844 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1845 | self.assertTrue( |
| 1846 | find_nbr(self, self.pg1.sw_if_index, self.pg0._remote_hosts[2].ip6) |
| 1847 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1848 | |
| 1849 | # |
| 1850 | # ... and we can route traffic to it |
| 1851 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1852 | t = ( |
| 1853 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 1854 | / IPv6(dst=self.pg0._remote_hosts[2].ip6, src=self.pg0.remote_ip6) |
| 1855 | / inet6.UDP(sport=10000, dport=20000) |
| 1856 | / Raw(b"\xa5" * 100) |
| 1857 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1858 | |
| 1859 | self.pg0.add_stream(t) |
| 1860 | self.pg_enable_capture(self.pg_interfaces) |
| 1861 | self.pg_start() |
| 1862 | rx = self.pg1.get_capture(1) |
| 1863 | rx = rx[0] |
| 1864 | |
| 1865 | self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) |
| 1866 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1867 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1868 | self.assertEqual(rx[IPv6].src, t[IPv6].src) |
| 1869 | self.assertEqual(rx[IPv6].dst, t[IPv6].dst) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1870 | |
| 1871 | # |
| 1872 | # Test we proxy for the host on the main interface |
| 1873 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1874 | ns_pg0 = ( |
| 1875 | Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) |
| 1876 | / IPv6(dst=d, src=self.pg0.remote_ip6) |
| 1877 | / ICMPv6ND_NS(tgt=self.pg0._remote_hosts[2].ip6) |
| 1878 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac) |
| 1879 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1880 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1881 | self.send_and_expect_na( |
| 1882 | self.pg0, |
| 1883 | ns_pg0, |
| 1884 | "NS to proxy entry on main", |
| 1885 | tgt_ip=self.pg0._remote_hosts[2].ip6, |
| 1886 | dst_ip=self.pg0.remote_ip6, |
| 1887 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1888 | |
| 1889 | # |
| 1890 | # Setup and resolve proxy for another host on another interface |
| 1891 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1892 | ns_pg2 = ( |
| 1893 | Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) |
| 1894 | / IPv6(dst=d, src=self.pg0._remote_hosts[3].ip6) |
| 1895 | / ICMPv6ND_NS(tgt=self.pg0.local_ip6) |
| 1896 | / ICMPv6NDOptSrcLLAddr(lladdr=self.pg0._remote_hosts[2].mac) |
| 1897 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1898 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1899 | self.vapi.ip6nd_proxy_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1900 | is_add=1, |
| 1901 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), |
| 1902 | sw_if_index=self.pg2.sw_if_index, |
| 1903 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1904 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1905 | self.send_and_expect_na( |
| 1906 | self.pg2, |
| 1907 | ns_pg2, |
| 1908 | "NS to proxy entry other interface", |
| 1909 | dst_ip=self.pg0._remote_hosts[3].ip6, |
| 1910 | tgt_ip=self.pg0.local_ip6, |
| 1911 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1912 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1913 | self.assertTrue( |
| 1914 | find_nbr(self, self.pg2.sw_if_index, self.pg0._remote_hosts[3].ip6) |
| 1915 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1916 | |
| 1917 | # |
| 1918 | # hosts can communicate. pg2->pg1 |
| 1919 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1920 | t2 = ( |
| 1921 | Ether(dst=self.pg2.local_mac, src=self.pg0.remote_hosts[3].mac) |
| 1922 | / IPv6(dst=self.pg0._remote_hosts[2].ip6, src=self.pg0._remote_hosts[3].ip6) |
| 1923 | / inet6.UDP(sport=10000, dport=20000) |
| 1924 | / Raw(b"\xa5" * 100) |
| 1925 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1926 | |
| 1927 | self.pg2.add_stream(t2) |
| 1928 | self.pg_enable_capture(self.pg_interfaces) |
| 1929 | self.pg_start() |
| 1930 | rx = self.pg1.get_capture(1) |
| 1931 | rx = rx[0] |
| 1932 | |
| 1933 | self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) |
| 1934 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1935 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1936 | self.assertEqual(rx[IPv6].src, t2[IPv6].src) |
| 1937 | self.assertEqual(rx[IPv6].dst, t2[IPv6].dst) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1938 | |
| 1939 | # |
| 1940 | # remove the proxy configs |
| 1941 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1942 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1943 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1944 | sw_if_index=self.pg1.sw_if_index, |
| 1945 | is_add=0, |
| 1946 | ) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1947 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1948 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1949 | sw_if_index=self.pg2.sw_if_index, |
| 1950 | is_add=0, |
| 1951 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1952 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1953 | self.assertFalse( |
| 1954 | find_nbr(self, self.pg2.sw_if_index, self.pg0._remote_hosts[3].ip6) |
| 1955 | ) |
| 1956 | self.assertFalse( |
| 1957 | find_nbr(self, self.pg1.sw_if_index, self.pg0._remote_hosts[2].ip6) |
| 1958 | ) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1959 | |
| 1960 | # |
| 1961 | # no longer proxy-ing... |
| 1962 | # |
| 1963 | self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured") |
| 1964 | self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured") |
| 1965 | self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured") |
| 1966 | |
| 1967 | # |
| 1968 | # no longer forwarding. traffic generates NS out of the glean/main |
| 1969 | # interface |
| 1970 | # |
| 1971 | self.pg2.add_stream(t2) |
| 1972 | self.pg_enable_capture(self.pg_interfaces) |
| 1973 | self.pg_start() |
| 1974 | |
| 1975 | rx = self.pg0.get_capture(1) |
| 1976 | |
| 1977 | self.assertTrue(rx[0].haslayer(ICMPv6ND_NS)) |
| 1978 | |
| 1979 | |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 1980 | class TestIP6Null(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1981 | """IPv6 routes via NULL""" |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1982 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1983 | @classmethod |
| 1984 | def setUpClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 1985 | super(TestIP6Null, cls).setUpClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1986 | |
| 1987 | @classmethod |
| 1988 | def tearDownClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 1989 | super(TestIP6Null, cls).tearDownClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1990 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1991 | def setUp(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 1992 | super(TestIP6Null, self).setUp() |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1993 | |
| 1994 | # create 2 pg interfaces |
| 1995 | self.create_pg_interfaces(range(1)) |
| 1996 | |
| 1997 | for i in self.pg_interfaces: |
| 1998 | i.admin_up() |
| 1999 | i.config_ip6() |
| 2000 | i.resolve_ndp() |
| 2001 | |
| 2002 | def tearDown(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2003 | super(TestIP6Null, self).tearDown() |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 2004 | for i in self.pg_interfaces: |
| 2005 | i.unconfig_ip6() |
| 2006 | i.admin_down() |
| 2007 | |
| 2008 | def test_ip_null(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2009 | """IP NULL route""" |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 2010 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2011 | p = ( |
| 2012 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2013 | / IPv6(src=self.pg0.remote_ip6, dst="2001::1") |
| 2014 | / inet6.UDP(sport=1234, dport=1234) |
| 2015 | / Raw(b"\xa5" * 100) |
| 2016 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 2017 | |
| 2018 | # |
| 2019 | # A route via IP NULL that will reply with ICMP unreachables |
| 2020 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2021 | ip_unreach = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2022 | self, |
| 2023 | "2001::", |
| 2024 | 64, |
| 2025 | [ |
| 2026 | VppRoutePath( |
| 2027 | "::", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH |
| 2028 | ) |
| 2029 | ], |
| 2030 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 2031 | ip_unreach.add_vpp_config() |
| 2032 | |
| 2033 | self.pg0.add_stream(p) |
| 2034 | self.pg_enable_capture(self.pg_interfaces) |
| 2035 | self.pg_start() |
| 2036 | |
| 2037 | rx = self.pg0.get_capture(1) |
| 2038 | rx = rx[0] |
| 2039 | icmp = rx[ICMPv6DestUnreach] |
| 2040 | |
| 2041 | # 0 = "No route to destination" |
| 2042 | self.assertEqual(icmp.code, 0) |
| 2043 | |
| 2044 | # ICMP is rate limited. pause a bit |
| 2045 | self.sleep(1) |
| 2046 | |
| 2047 | # |
| 2048 | # A route via IP NULL that will reply with ICMP prohibited |
| 2049 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2050 | ip_prohibit = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2051 | self, |
| 2052 | "2001::1", |
| 2053 | 128, |
| 2054 | [ |
| 2055 | VppRoutePath( |
| 2056 | "::", 0xFFFFFFFF, type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT |
| 2057 | ) |
| 2058 | ], |
| 2059 | ) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 2060 | ip_prohibit.add_vpp_config() |
| 2061 | |
| 2062 | self.pg0.add_stream(p) |
| 2063 | self.pg_enable_capture(self.pg_interfaces) |
| 2064 | self.pg_start() |
| 2065 | |
| 2066 | rx = self.pg0.get_capture(1) |
| 2067 | rx = rx[0] |
| 2068 | icmp = rx[ICMPv6DestUnreach] |
| 2069 | |
| 2070 | # 1 = "Communication with destination administratively prohibited" |
| 2071 | self.assertEqual(icmp.code, 1) |
| 2072 | |
| 2073 | |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2074 | class TestIP6Disabled(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2075 | """IPv6 disabled""" |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2076 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2077 | @classmethod |
| 2078 | def setUpClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2079 | super(TestIP6Disabled, cls).setUpClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2080 | |
| 2081 | @classmethod |
| 2082 | def tearDownClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2083 | super(TestIP6Disabled, cls).tearDownClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2084 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2085 | def setUp(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2086 | super(TestIP6Disabled, self).setUp() |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2087 | |
| 2088 | # create 2 pg interfaces |
| 2089 | self.create_pg_interfaces(range(2)) |
| 2090 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2091 | # PG0 is IP enabled |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2092 | self.pg0.admin_up() |
| 2093 | self.pg0.config_ip6() |
| 2094 | self.pg0.resolve_ndp() |
| 2095 | |
| 2096 | # PG 1 is not IP enabled |
| 2097 | self.pg1.admin_up() |
| 2098 | |
| 2099 | def tearDown(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2100 | super(TestIP6Disabled, self).tearDown() |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2101 | for i in self.pg_interfaces: |
| 2102 | i.unconfig_ip4() |
| 2103 | i.admin_down() |
| 2104 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2105 | def test_ip_disabled(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2106 | """IP Disabled""" |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2107 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2108 | MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t |
| 2109 | MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2110 | # |
| 2111 | # An (S,G). |
| 2112 | # one accepting interface, pg0, 2 forwarding interfaces |
| 2113 | # |
| 2114 | route_ff_01 = VppIpMRoute( |
| 2115 | self, |
| 2116 | "::", |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2117 | "ffef::1", |
| 2118 | 128, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2119 | MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2120 | [ |
| 2121 | VppMRoutePath( |
| 2122 | self.pg1.sw_if_index, MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
| 2123 | ), |
| 2124 | VppMRoutePath( |
| 2125 | self.pg0.sw_if_index, MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD |
| 2126 | ), |
| 2127 | ], |
| 2128 | ) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2129 | route_ff_01.add_vpp_config() |
| 2130 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2131 | pu = ( |
| 2132 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 2133 | / IPv6(src="2001::1", dst=self.pg0.remote_ip6) |
| 2134 | / inet6.UDP(sport=1234, dport=1234) |
| 2135 | / Raw(b"\xa5" * 100) |
| 2136 | ) |
| 2137 | pm = ( |
| 2138 | Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) |
| 2139 | / IPv6(src="2001::1", dst="ffef::1") |
| 2140 | / inet6.UDP(sport=1234, dport=1234) |
| 2141 | / Raw(b"\xa5" * 100) |
| 2142 | ) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 2143 | |
| 2144 | # |
| 2145 | # PG1 does not forward IP traffic |
| 2146 | # |
| 2147 | self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") |
| 2148 | self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") |
| 2149 | |
| 2150 | # |
| 2151 | # IP enable PG1 |
| 2152 | # |
| 2153 | self.pg1.config_ip6() |
| 2154 | |
| 2155 | # |
| 2156 | # Now we get packets through |
| 2157 | # |
| 2158 | self.pg1.add_stream(pu) |
| 2159 | self.pg_enable_capture(self.pg_interfaces) |
| 2160 | self.pg_start() |
| 2161 | rx = self.pg0.get_capture(1) |
| 2162 | |
| 2163 | self.pg1.add_stream(pm) |
| 2164 | self.pg_enable_capture(self.pg_interfaces) |
| 2165 | self.pg_start() |
| 2166 | rx = self.pg0.get_capture(1) |
| 2167 | |
| 2168 | # |
| 2169 | # Disable PG1 |
| 2170 | # |
| 2171 | self.pg1.unconfig_ip6() |
| 2172 | |
| 2173 | # |
| 2174 | # PG1 does not forward IP traffic |
| 2175 | # |
| 2176 | self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") |
| 2177 | self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") |
| 2178 | |
| 2179 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2180 | class TestIP6LoadBalance(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2181 | """IPv6 Load-Balancing""" |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2182 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2183 | @classmethod |
| 2184 | def setUpClass(cls): |
| 2185 | super(TestIP6LoadBalance, cls).setUpClass() |
| 2186 | |
| 2187 | @classmethod |
| 2188 | def tearDownClass(cls): |
| 2189 | super(TestIP6LoadBalance, cls).tearDownClass() |
| 2190 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2191 | def setUp(self): |
| 2192 | super(TestIP6LoadBalance, self).setUp() |
| 2193 | |
| 2194 | self.create_pg_interfaces(range(5)) |
| 2195 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 2196 | mpls_tbl = VppMplsTable(self, 0) |
| 2197 | mpls_tbl.add_vpp_config() |
| 2198 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2199 | for i in self.pg_interfaces: |
| 2200 | i.admin_up() |
| 2201 | i.config_ip6() |
| 2202 | i.resolve_ndp() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2203 | i.enable_mpls() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2204 | |
| 2205 | def tearDown(self): |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2206 | for i in self.pg_interfaces: |
| 2207 | i.unconfig_ip6() |
| 2208 | i.admin_down() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2209 | i.disable_mpls() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 2210 | super(TestIP6LoadBalance, self).tearDown() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2211 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2212 | def test_ip6_load_balance(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2213 | """IPv6 Load-Balancing""" |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2214 | |
| 2215 | # |
| 2216 | # An array of packets that differ only in the destination port |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2217 | # - IP only |
| 2218 | # - MPLS EOS |
| 2219 | # - MPLS non-EOS |
| 2220 | # - MPLS non-EOS with an entropy label |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2221 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2222 | port_ip_pkts = [] |
| 2223 | port_mpls_pkts = [] |
| 2224 | port_mpls_neos_pkts = [] |
| 2225 | port_ent_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2226 | |
| 2227 | # |
| 2228 | # An array of packets that differ only in the source address |
| 2229 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2230 | src_ip_pkts = [] |
| 2231 | src_mpls_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2232 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2233 | for ii in range(NUM_PKTS): |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2234 | port_ip_hdr = ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2235 | IPv6(dst="3000::1", src="3000:1::1") |
| 2236 | / inet6.UDP(sport=1234, dport=1234 + ii) |
| 2237 | / Raw(b"\xa5" * 100) |
| 2238 | ) |
| 2239 | port_ip_pkts.append( |
| 2240 | (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / port_ip_hdr) |
| 2241 | ) |
| 2242 | port_mpls_pkts.append( |
| 2243 | ( |
| 2244 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2245 | / MPLS(label=66, ttl=2) |
| 2246 | / port_ip_hdr |
| 2247 | ) |
| 2248 | ) |
| 2249 | port_mpls_neos_pkts.append( |
| 2250 | ( |
| 2251 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2252 | / MPLS(label=67, ttl=2) |
| 2253 | / MPLS(label=77, ttl=2) |
| 2254 | / port_ip_hdr |
| 2255 | ) |
| 2256 | ) |
| 2257 | port_ent_pkts.append( |
| 2258 | ( |
| 2259 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2260 | / MPLS(label=67, ttl=2) |
| 2261 | / MPLS(label=14, ttl=2) |
| 2262 | / MPLS(label=999, ttl=2) |
| 2263 | / port_ip_hdr |
| 2264 | ) |
| 2265 | ) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2266 | src_ip_hdr = ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2267 | IPv6(dst="3000::1", src="3000:1::%d" % ii) |
| 2268 | / inet6.UDP(sport=1234, dport=1234) |
| 2269 | / Raw(b"\xa5" * 100) |
| 2270 | ) |
| 2271 | src_ip_pkts.append( |
| 2272 | (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / src_ip_hdr) |
| 2273 | ) |
| 2274 | src_mpls_pkts.append( |
| 2275 | ( |
| 2276 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2277 | / MPLS(label=66, ttl=2) |
| 2278 | / src_ip_hdr |
| 2279 | ) |
| 2280 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2281 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2282 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2283 | # A route for the IP packets |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2284 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2285 | route_3000_1 = VppIpRoute( |
| 2286 | self, |
| 2287 | "3000::1", |
| 2288 | 128, |
| 2289 | [ |
| 2290 | VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index), |
| 2291 | VppRoutePath(self.pg2.remote_ip6, self.pg2.sw_if_index), |
| 2292 | ], |
| 2293 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2294 | route_3000_1.add_vpp_config() |
| 2295 | |
| 2296 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2297 | # a local-label for the EOS packets |
| 2298 | # |
| 2299 | binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1) |
| 2300 | binding.add_vpp_config() |
| 2301 | |
| 2302 | # |
| 2303 | # An MPLS route for the non-EOS packets |
| 2304 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2305 | route_67 = VppMplsRoute( |
| 2306 | self, |
| 2307 | 67, |
| 2308 | 0, |
| 2309 | [ |
| 2310 | VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index, labels=[67]), |
| 2311 | VppRoutePath(self.pg2.remote_ip6, self.pg2.sw_if_index, labels=[67]), |
| 2312 | ], |
| 2313 | ) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2314 | route_67.add_vpp_config() |
| 2315 | |
| 2316 | # |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2317 | # inject the packet on pg0 - expect load-balancing across the 2 paths |
| 2318 | # - since the default hash config is to use IP src,dst and port |
| 2319 | # src,dst |
| 2320 | # We are not going to ensure equal amounts of packets across each link, |
| 2321 | # since the hash algorithm is statistical and therefore this can never |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2322 | # be guaranteed. But with 64 different packets we do expect some |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2323 | # balancing. So instead just ensure there is traffic on each link. |
| 2324 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2325 | rx = self.send_and_expect_load_balancing( |
| 2326 | self.pg0, port_ip_pkts, [self.pg1, self.pg2] |
| 2327 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 2328 | n_ip_pg0 = len(rx[0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2329 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, [self.pg1, self.pg2]) |
| 2330 | self.send_and_expect_load_balancing( |
| 2331 | self.pg0, port_mpls_pkts, [self.pg1, self.pg2] |
| 2332 | ) |
| 2333 | self.send_and_expect_load_balancing( |
| 2334 | self.pg0, src_mpls_pkts, [self.pg1, self.pg2] |
| 2335 | ) |
| 2336 | rx = self.send_and_expect_load_balancing( |
| 2337 | self.pg0, port_mpls_neos_pkts, [self.pg1, self.pg2] |
| 2338 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 2339 | n_mpls_pg0 = len(rx[0]) |
| 2340 | |
| 2341 | # |
| 2342 | # change the router ID and expect the distribution changes |
| 2343 | # |
| 2344 | self.vapi.set_ip_flow_hash_router_id(router_id=0x11111111) |
| 2345 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2346 | rx = self.send_and_expect_load_balancing( |
| 2347 | self.pg0, port_ip_pkts, [self.pg1, self.pg2] |
| 2348 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 2349 | self.assertNotEqual(n_ip_pg0, len(rx[0])) |
| 2350 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2351 | rx = self.send_and_expect_load_balancing( |
| 2352 | self.pg0, src_mpls_pkts, [self.pg1, self.pg2] |
| 2353 | ) |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 2354 | self.assertNotEqual(n_mpls_pg0, len(rx[0])) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2355 | |
| 2356 | # |
| 2357 | # The packets with Entropy label in should not load-balance, |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2358 | # since the Entropy value is fixed. |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2359 | # |
Neale Ranns | 699bea2 | 2022-02-17 09:22:16 +0000 | [diff] [blame] | 2360 | self.send_and_expect_only(self.pg0, port_ent_pkts, self.pg1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2361 | |
| 2362 | # |
| 2363 | # change the flow hash config so it's only IP src,dst |
| 2364 | # - now only the stream with differing source address will |
| 2365 | # load-balance |
| 2366 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2367 | self.vapi.set_ip_flow_hash( |
| 2368 | vrf_id=0, src=1, dst=1, proto=1, sport=0, dport=0, is_ipv6=1 |
| 2369 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2370 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2371 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, [self.pg1, self.pg2]) |
| 2372 | self.send_and_expect_load_balancing( |
| 2373 | self.pg0, src_mpls_pkts, [self.pg1, self.pg2] |
| 2374 | ) |
Neale Ranns | 699bea2 | 2022-02-17 09:22:16 +0000 | [diff] [blame] | 2375 | self.send_and_expect_only(self.pg0, port_ip_pkts, self.pg2) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2376 | |
| 2377 | # |
| 2378 | # change the flow hash config back to defaults |
| 2379 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2380 | self.vapi.set_ip_flow_hash( |
| 2381 | vrf_id=0, src=1, dst=1, sport=1, dport=1, proto=1, is_ipv6=1 |
| 2382 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2383 | |
| 2384 | # |
| 2385 | # Recursive prefixes |
| 2386 | # - testing that 2 stages of load-balancing occurs and there is no |
| 2387 | # polarisation (i.e. only 2 of 4 paths are used) |
| 2388 | # |
| 2389 | port_pkts = [] |
| 2390 | src_pkts = [] |
| 2391 | |
| 2392 | for ii in range(257): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2393 | port_pkts.append( |
| 2394 | ( |
| 2395 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2396 | / IPv6(dst="4000::1", src="4000:1::1") |
| 2397 | / inet6.UDP(sport=1234, dport=1234 + ii) |
| 2398 | / Raw(b"\xa5" * 100) |
| 2399 | ) |
| 2400 | ) |
| 2401 | src_pkts.append( |
| 2402 | ( |
| 2403 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2404 | / IPv6(dst="4000::1", src="4000:1::%d" % ii) |
| 2405 | / inet6.UDP(sport=1234, dport=1234) |
| 2406 | / Raw(b"\xa5" * 100) |
| 2407 | ) |
| 2408 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2409 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2410 | route_3000_2 = VppIpRoute( |
| 2411 | self, |
| 2412 | "3000::2", |
| 2413 | 128, |
| 2414 | [ |
| 2415 | VppRoutePath(self.pg3.remote_ip6, self.pg3.sw_if_index), |
| 2416 | VppRoutePath(self.pg4.remote_ip6, self.pg4.sw_if_index), |
| 2417 | ], |
| 2418 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2419 | route_3000_2.add_vpp_config() |
| 2420 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2421 | route_4000_1 = VppIpRoute( |
| 2422 | self, |
| 2423 | "4000::1", |
| 2424 | 128, |
| 2425 | [VppRoutePath("3000::1", 0xFFFFFFFF), VppRoutePath("3000::2", 0xFFFFFFFF)], |
| 2426 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2427 | route_4000_1.add_vpp_config() |
| 2428 | |
| 2429 | # |
| 2430 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 2431 | # |
| 2432 | self.vapi.cli("clear trace") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2433 | self.send_and_expect_load_balancing( |
| 2434 | self.pg0, port_pkts, [self.pg1, self.pg2, self.pg3, self.pg4] |
| 2435 | ) |
| 2436 | self.send_and_expect_load_balancing( |
| 2437 | self.pg0, src_pkts, [self.pg1, self.pg2, self.pg3, self.pg4] |
| 2438 | ) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2439 | |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2440 | # |
| 2441 | # Recursive prefixes |
| 2442 | # - testing that 2 stages of load-balancing no choices |
| 2443 | # |
| 2444 | port_pkts = [] |
| 2445 | |
| 2446 | for ii in range(257): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2447 | port_pkts.append( |
| 2448 | ( |
| 2449 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2450 | / IPv6(dst="6000::1", src="6000:1::1") |
| 2451 | / inet6.UDP(sport=1234, dport=1234 + ii) |
| 2452 | / Raw(b"\xa5" * 100) |
| 2453 | ) |
| 2454 | ) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2455 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2456 | route_5000_2 = VppIpRoute( |
| 2457 | self, |
| 2458 | "5000::2", |
| 2459 | 128, |
| 2460 | [VppRoutePath(self.pg3.remote_ip6, self.pg3.sw_if_index)], |
| 2461 | ) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2462 | route_5000_2.add_vpp_config() |
| 2463 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2464 | route_6000_1 = VppIpRoute( |
| 2465 | self, "6000::1", 128, [VppRoutePath("5000::2", 0xFFFFFFFF)] |
| 2466 | ) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2467 | route_6000_1.add_vpp_config() |
| 2468 | |
| 2469 | # |
| 2470 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 2471 | # |
| 2472 | self.vapi.cli("clear trace") |
Neale Ranns | 699bea2 | 2022-02-17 09:22:16 +0000 | [diff] [blame] | 2473 | self.send_and_expect_only(self.pg0, port_pkts, self.pg3) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2474 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2475 | |
Brian Russell | a1f3606 | 2021-01-19 16:58:14 +0000 | [diff] [blame] | 2476 | class IP6PuntSetup(object): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2477 | """Setup for IPv6 Punt Police/Redirect""" |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2478 | |
Brian Russell | a1f3606 | 2021-01-19 16:58:14 +0000 | [diff] [blame] | 2479 | def punt_setup(self): |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2480 | self.create_pg_interfaces(range(4)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2481 | |
| 2482 | for i in self.pg_interfaces: |
| 2483 | i.admin_up() |
| 2484 | i.config_ip6() |
| 2485 | i.resolve_ndp() |
| 2486 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2487 | self.pkt = ( |
| 2488 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2489 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) |
| 2490 | / inet6.TCP(sport=1234, dport=1234) |
| 2491 | / Raw(b"\xa5" * 100) |
| 2492 | ) |
Brian Russell | a1f3606 | 2021-01-19 16:58:14 +0000 | [diff] [blame] | 2493 | |
| 2494 | def punt_teardown(self): |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2495 | for i in self.pg_interfaces: |
| 2496 | i.unconfig_ip6() |
| 2497 | i.admin_down() |
| 2498 | |
Brian Russell | a1f3606 | 2021-01-19 16:58:14 +0000 | [diff] [blame] | 2499 | |
| 2500 | class TestIP6Punt(IP6PuntSetup, VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2501 | """IPv6 Punt Police/Redirect""" |
Brian Russell | a1f3606 | 2021-01-19 16:58:14 +0000 | [diff] [blame] | 2502 | |
| 2503 | def setUp(self): |
| 2504 | super(TestIP6Punt, self).setUp() |
| 2505 | super(TestIP6Punt, self).punt_setup() |
| 2506 | |
| 2507 | def tearDown(self): |
| 2508 | super(TestIP6Punt, self).punt_teardown() |
| 2509 | super(TestIP6Punt, self).tearDown() |
| 2510 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2511 | def test_ip_punt(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2512 | """IP6 punt police and redirect""" |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2513 | |
Brian Russell | a1f3606 | 2021-01-19 16:58:14 +0000 | [diff] [blame] | 2514 | pkts = self.pkt * 1025 |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2515 | |
| 2516 | # |
| 2517 | # Configure a punt redirect via pg1. |
| 2518 | # |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2519 | nh_addr = self.pg1.remote_ip6 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2520 | ip_punt_redirect = VppIpPuntRedirect( |
| 2521 | self, self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr |
| 2522 | ) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2523 | ip_punt_redirect.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2524 | |
| 2525 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 2526 | |
| 2527 | # |
| 2528 | # add a policer |
| 2529 | # |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 2530 | policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1) |
| 2531 | policer.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2532 | ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index, is_ip6=True) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2533 | ip_punt_policer.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2534 | |
| 2535 | self.vapi.cli("clear trace") |
| 2536 | self.pg0.add_stream(pkts) |
| 2537 | self.pg_enable_capture(self.pg_interfaces) |
| 2538 | self.pg_start() |
| 2539 | |
| 2540 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2541 | # the number of packet received should be greater than 0, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2542 | # but not equal to the number sent, since some were policed |
| 2543 | # |
| 2544 | rx = self.pg1._get_capture(1) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2545 | stats = policer.get_stats() |
| 2546 | |
| 2547 | # Single rate policer - expect conform, violate but no exceed |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2548 | self.assertGreater(stats["conform_packets"], 0) |
| 2549 | self.assertEqual(stats["exceed_packets"], 0) |
| 2550 | self.assertGreater(stats["violate_packets"], 0) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2551 | |
Paul Vinciguerra | 3d2df21 | 2018-11-24 23:19:53 -0800 | [diff] [blame] | 2552 | self.assertGreater(len(rx), 0) |
| 2553 | self.assertLess(len(rx), len(pkts)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2554 | |
| 2555 | # |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 2556 | # remove the policer. back to full rx |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2557 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2558 | ip_punt_policer.remove_vpp_config() |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 2559 | policer.remove_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2560 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 2561 | |
| 2562 | # |
| 2563 | # remove the redirect. expect full drop. |
| 2564 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2565 | ip_punt_redirect.remove_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2566 | self.send_and_assert_no_replies(self.pg0, pkts, "IP no punt config") |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2567 | |
| 2568 | # |
| 2569 | # Add a redirect that is not input port selective |
| 2570 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2571 | ip_punt_redirect = VppIpPuntRedirect( |
| 2572 | self, 0xFFFFFFFF, self.pg1.sw_if_index, nh_addr |
| 2573 | ) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2574 | ip_punt_redirect.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2575 | self.send_and_expect(self.pg0, pkts, self.pg1) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2576 | ip_punt_redirect.remove_vpp_config() |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2577 | |
| 2578 | def test_ip_punt_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2579 | """IP6 punt redirect dump""" |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2580 | |
| 2581 | # |
| 2582 | # Configure a punt redirects |
| 2583 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2584 | nh_address = self.pg3.remote_ip6 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2585 | ipr_03 = VppIpPuntRedirect( |
| 2586 | self, self.pg0.sw_if_index, self.pg3.sw_if_index, nh_address |
| 2587 | ) |
| 2588 | ipr_13 = VppIpPuntRedirect( |
| 2589 | self, self.pg1.sw_if_index, self.pg3.sw_if_index, nh_address |
| 2590 | ) |
| 2591 | ipr_23 = VppIpPuntRedirect( |
| 2592 | self, self.pg2.sw_if_index, self.pg3.sw_if_index, "0::0" |
| 2593 | ) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2594 | ipr_03.add_vpp_config() |
| 2595 | ipr_13.add_vpp_config() |
| 2596 | ipr_23.add_vpp_config() |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2597 | |
| 2598 | # |
| 2599 | # Dump pg0 punt redirects |
| 2600 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2601 | self.assertTrue(ipr_03.query_vpp_config()) |
| 2602 | self.assertTrue(ipr_13.query_vpp_config()) |
| 2603 | self.assertTrue(ipr_23.query_vpp_config()) |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2604 | |
| 2605 | # |
| 2606 | # Dump punt redirects for all interfaces |
| 2607 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2608 | punts = self.vapi.ip_punt_redirect_dump(0xFFFFFFFF, is_ipv6=1) |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2609 | self.assertEqual(len(punts), 3) |
| 2610 | for p in punts: |
| 2611 | self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index) |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2612 | self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2613 | self.assertEqual(str(punts[2].punt.nh), "::") |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2614 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2615 | |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2616 | class TestIP6PuntHandoff(IP6PuntSetup, VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2617 | """IPv6 Punt Police/Redirect""" |
| 2618 | |
Klement Sekera | 8d81502 | 2021-03-15 16:58:10 +0100 | [diff] [blame] | 2619 | vpp_worker_count = 2 |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2620 | |
| 2621 | def setUp(self): |
| 2622 | super(TestIP6PuntHandoff, self).setUp() |
| 2623 | super(TestIP6PuntHandoff, self).punt_setup() |
| 2624 | |
| 2625 | def tearDown(self): |
| 2626 | super(TestIP6PuntHandoff, self).punt_teardown() |
| 2627 | super(TestIP6PuntHandoff, self).tearDown() |
| 2628 | |
| 2629 | def test_ip_punt(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2630 | """IP6 punt policer thread handoff""" |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2631 | pkts = self.pkt * NUM_PKTS |
| 2632 | |
| 2633 | # |
| 2634 | # Configure a punt redirect via pg1. |
| 2635 | # |
| 2636 | nh_addr = self.pg1.remote_ip6 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2637 | ip_punt_redirect = VppIpPuntRedirect( |
| 2638 | self, self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr |
| 2639 | ) |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2640 | ip_punt_redirect.add_vpp_config() |
| 2641 | |
| 2642 | action_tx = PolicerAction( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2643 | VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT, 0 |
| 2644 | ) |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2645 | # |
| 2646 | # This policer drops no packets, we are just |
| 2647 | # testing that they get to the right thread. |
| 2648 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2649 | policer = VppPolicer( |
| 2650 | self, |
| 2651 | "ip6-punt", |
| 2652 | 400, |
| 2653 | 0, |
| 2654 | 10, |
| 2655 | 0, |
| 2656 | 1, |
| 2657 | 0, |
| 2658 | 0, |
| 2659 | False, |
| 2660 | action_tx, |
| 2661 | action_tx, |
| 2662 | action_tx, |
| 2663 | ) |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2664 | policer.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2665 | ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index, is_ip6=True) |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2666 | ip_punt_policer.add_vpp_config() |
| 2667 | |
| 2668 | for worker in [0, 1]: |
| 2669 | self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker) |
| 2670 | if worker == 0: |
| 2671 | self.logger.debug(self.vapi.cli("show trace max 100")) |
| 2672 | |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2673 | # Combined stats, all threads |
| 2674 | stats = policer.get_stats() |
| 2675 | |
| 2676 | # Single rate policer - expect conform, violate but no exceed |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2677 | self.assertGreater(stats["conform_packets"], 0) |
| 2678 | self.assertEqual(stats["exceed_packets"], 0) |
| 2679 | self.assertGreater(stats["violate_packets"], 0) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2680 | |
| 2681 | # Worker 0, should have done all the policing |
| 2682 | stats0 = policer.get_stats(worker=0) |
| 2683 | self.assertEqual(stats, stats0) |
| 2684 | |
| 2685 | # Worker 1, should have handed everything off |
| 2686 | stats1 = policer.get_stats(worker=1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2687 | self.assertEqual(stats1["conform_packets"], 0) |
| 2688 | self.assertEqual(stats1["exceed_packets"], 0) |
| 2689 | self.assertEqual(stats1["violate_packets"], 0) |
Brian Russell | e988726 | 2021-01-27 14:45:22 +0000 | [diff] [blame] | 2690 | |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2691 | # Bind the policer to worker 1 and repeat |
| 2692 | policer.bind_vpp_config(1, True) |
| 2693 | for worker in [0, 1]: |
| 2694 | self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker) |
| 2695 | self.logger.debug(self.vapi.cli("show trace max 100")) |
| 2696 | |
| 2697 | # The 2 workers should now have policed the same amount |
| 2698 | stats = policer.get_stats() |
| 2699 | stats0 = policer.get_stats(worker=0) |
| 2700 | stats1 = policer.get_stats(worker=1) |
| 2701 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2702 | self.assertGreater(stats0["conform_packets"], 0) |
| 2703 | self.assertEqual(stats0["exceed_packets"], 0) |
| 2704 | self.assertGreater(stats0["violate_packets"], 0) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2705 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2706 | self.assertGreater(stats1["conform_packets"], 0) |
| 2707 | self.assertEqual(stats1["exceed_packets"], 0) |
| 2708 | self.assertGreater(stats1["violate_packets"], 0) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2709 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2710 | self.assertEqual( |
| 2711 | stats0["conform_packets"] + stats1["conform_packets"], |
| 2712 | stats["conform_packets"], |
| 2713 | ) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2714 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2715 | self.assertEqual( |
| 2716 | stats0["violate_packets"] + stats1["violate_packets"], |
| 2717 | stats["violate_packets"], |
| 2718 | ) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2719 | |
| 2720 | # Unbind the policer and repeat |
| 2721 | policer.bind_vpp_config(1, False) |
| 2722 | for worker in [0, 1]: |
| 2723 | self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker) |
| 2724 | self.logger.debug(self.vapi.cli("show trace max 100")) |
| 2725 | |
| 2726 | # The policer should auto-bind to worker 0 when packets arrive |
| 2727 | stats = policer.get_stats() |
| 2728 | stats0new = policer.get_stats(worker=0) |
| 2729 | stats1new = policer.get_stats(worker=1) |
| 2730 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2731 | self.assertGreater(stats0new["conform_packets"], stats0["conform_packets"]) |
| 2732 | self.assertEqual(stats0new["exceed_packets"], 0) |
| 2733 | self.assertGreater(stats0new["violate_packets"], stats0["violate_packets"]) |
Brian Russell | bb98314 | 2021-02-10 13:56:06 +0000 | [diff] [blame] | 2734 | |
| 2735 | self.assertEqual(stats1, stats1new) |
| 2736 | |
Brian Russell | 5214f3a | 2021-01-19 16:58:34 +0000 | [diff] [blame] | 2737 | # |
| 2738 | # Clean up |
| 2739 | # |
| 2740 | ip_punt_policer.remove_vpp_config() |
| 2741 | policer.remove_vpp_config() |
| 2742 | ip_punt_redirect.remove_vpp_config() |
| 2743 | |
| 2744 | |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2745 | class TestIP6Deag(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2746 | """IPv6 Deaggregate Routes""" |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2747 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2748 | @classmethod |
| 2749 | def setUpClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2750 | super(TestIP6Deag, cls).setUpClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2751 | |
| 2752 | @classmethod |
| 2753 | def tearDownClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2754 | super(TestIP6Deag, cls).tearDownClass() |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2755 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2756 | def setUp(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2757 | super(TestIP6Deag, self).setUp() |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2758 | |
| 2759 | self.create_pg_interfaces(range(3)) |
| 2760 | |
| 2761 | for i in self.pg_interfaces: |
| 2762 | i.admin_up() |
| 2763 | i.config_ip6() |
| 2764 | i.resolve_ndp() |
| 2765 | |
| 2766 | def tearDown(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 2767 | super(TestIP6Deag, self).tearDown() |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2768 | for i in self.pg_interfaces: |
| 2769 | i.unconfig_ip6() |
| 2770 | i.admin_down() |
| 2771 | |
| 2772 | def test_ip_deag(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2773 | """IP Deag Routes""" |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2774 | |
| 2775 | # |
| 2776 | # Create a table to be used for: |
| 2777 | # 1 - another destination address lookup |
| 2778 | # 2 - a source address lookup |
| 2779 | # |
| 2780 | table_dst = VppIpTable(self, 1, is_ip6=1) |
| 2781 | table_src = VppIpTable(self, 2, is_ip6=1) |
| 2782 | table_dst.add_vpp_config() |
| 2783 | table_src.add_vpp_config() |
| 2784 | |
| 2785 | # |
| 2786 | # Add a route in the default table to point to a deag/ |
| 2787 | # second lookup in each of these tables |
| 2788 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2789 | route_to_dst = VppIpRoute( |
| 2790 | self, "1::1", 128, [VppRoutePath("::", 0xFFFFFFFF, nh_table_id=1)] |
| 2791 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2792 | route_to_src = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2793 | self, |
| 2794 | "1::2", |
| 2795 | 128, |
| 2796 | [ |
| 2797 | VppRoutePath( |
| 2798 | "::", |
| 2799 | 0xFFFFFFFF, |
| 2800 | nh_table_id=2, |
| 2801 | type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP, |
| 2802 | ) |
| 2803 | ], |
| 2804 | ) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2805 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2806 | route_to_dst.add_vpp_config() |
| 2807 | route_to_src.add_vpp_config() |
| 2808 | |
| 2809 | # |
| 2810 | # packets to these destination are dropped, since they'll |
| 2811 | # hit the respective default routes in the second table |
| 2812 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2813 | p_dst = ( |
| 2814 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2815 | / IPv6(src="5::5", dst="1::1") |
| 2816 | / inet6.TCP(sport=1234, dport=1234) |
| 2817 | / Raw(b"\xa5" * 100) |
| 2818 | ) |
| 2819 | p_src = ( |
| 2820 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2821 | / IPv6(src="2::2", dst="1::2") |
| 2822 | / inet6.TCP(sport=1234, dport=1234) |
| 2823 | / Raw(b"\xa5" * 100) |
| 2824 | ) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2825 | pkts_dst = p_dst * 257 |
| 2826 | pkts_src = p_src * 257 |
| 2827 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2828 | self.send_and_assert_no_replies(self.pg0, pkts_dst, "IP in dst table") |
| 2829 | self.send_and_assert_no_replies(self.pg0, pkts_src, "IP in src table") |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2830 | |
| 2831 | # |
| 2832 | # add a route in the dst table to forward via pg1 |
| 2833 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2834 | route_in_dst = VppIpRoute( |
| 2835 | self, |
| 2836 | "1::1", |
| 2837 | 128, |
| 2838 | [VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)], |
| 2839 | table_id=1, |
| 2840 | ) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2841 | route_in_dst.add_vpp_config() |
| 2842 | |
| 2843 | self.send_and_expect(self.pg0, pkts_dst, self.pg1) |
| 2844 | |
| 2845 | # |
| 2846 | # add a route in the src table to forward via pg2 |
| 2847 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2848 | route_in_src = VppIpRoute( |
| 2849 | self, |
| 2850 | "2::2", |
| 2851 | 128, |
| 2852 | [VppRoutePath(self.pg2.remote_ip6, self.pg2.sw_if_index)], |
| 2853 | table_id=2, |
| 2854 | ) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2855 | route_in_src.add_vpp_config() |
| 2856 | self.send_and_expect(self.pg0, pkts_src, self.pg2) |
| 2857 | |
| 2858 | # |
| 2859 | # loop in the lookup DP |
| 2860 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2861 | route_loop = VppIpRoute(self, "3::3", 128, [VppRoutePath("::", 0xFFFFFFFF)]) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2862 | route_loop.add_vpp_config() |
| 2863 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2864 | p_l = ( |
| 2865 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2866 | / IPv6(src="3::4", dst="3::3") |
| 2867 | / inet6.TCP(sport=1234, dport=1234) |
| 2868 | / Raw(b"\xa5" * 100) |
| 2869 | ) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2870 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2871 | self.send_and_assert_no_replies(self.pg0, p_l * 257, "IP lookup loop") |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2872 | |
| 2873 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2874 | class TestIP6Input(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2875 | """IPv6 Input Exception Test Cases""" |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2876 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2877 | @classmethod |
| 2878 | def setUpClass(cls): |
| 2879 | super(TestIP6Input, cls).setUpClass() |
| 2880 | |
| 2881 | @classmethod |
| 2882 | def tearDownClass(cls): |
| 2883 | super(TestIP6Input, cls).tearDownClass() |
| 2884 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2885 | def setUp(self): |
| 2886 | super(TestIP6Input, self).setUp() |
| 2887 | |
| 2888 | self.create_pg_interfaces(range(2)) |
| 2889 | |
| 2890 | for i in self.pg_interfaces: |
| 2891 | i.admin_up() |
| 2892 | i.config_ip6() |
| 2893 | i.resolve_ndp() |
| 2894 | |
| 2895 | def tearDown(self): |
| 2896 | super(TestIP6Input, self).tearDown() |
| 2897 | for i in self.pg_interfaces: |
| 2898 | i.unconfig_ip6() |
| 2899 | i.admin_down() |
| 2900 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2901 | def test_ip_input_icmp_reply(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2902 | """IP6 Input Exception - Return ICMP (3,0)""" |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2903 | # |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2904 | # hop limit - ICMP replies |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2905 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2906 | p_version = ( |
| 2907 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2908 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_ip6, hlim=1) |
| 2909 | / inet6.UDP(sport=1234, dport=1234) |
| 2910 | / Raw(b"\xa5" * 100) |
| 2911 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2912 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2913 | rxs = self.send_and_expect_some(self.pg0, p_version * NUM_PKTS, self.pg0) |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2914 | |
Neale Ranns | 5c6dd17 | 2022-02-17 09:08:47 +0000 | [diff] [blame] | 2915 | for rx in rxs: |
| 2916 | icmp = rx[ICMPv6TimeExceeded] |
| 2917 | # 0: "hop limit exceeded in transit", |
| 2918 | self.assertEqual((icmp.type, icmp.code), (3, 0)) |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2919 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2920 | icmpv6_data = "\x0a" * 18 |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2921 | all_0s = "::" |
| 2922 | all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF" |
| 2923 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2924 | @parameterized.expand( |
| 2925 | [ |
| 2926 | # Name, src, dst, l4proto, msg, timeout |
| 2927 | ( |
| 2928 | "src='iface', dst='iface'", |
| 2929 | None, |
| 2930 | None, |
| 2931 | inet6.UDP(sport=1234, dport=1234), |
| 2932 | "funky version", |
| 2933 | None, |
| 2934 | ), |
| 2935 | ( |
| 2936 | "src='All 0's', dst='iface'", |
| 2937 | all_0s, |
| 2938 | None, |
| 2939 | ICMPv6EchoRequest(id=0xB, seq=5, data=icmpv6_data), |
| 2940 | None, |
| 2941 | 0.1, |
| 2942 | ), |
| 2943 | ( |
| 2944 | "src='iface', dst='All 0's'", |
| 2945 | None, |
| 2946 | all_0s, |
| 2947 | ICMPv6EchoRequest(id=0xB, seq=5, data=icmpv6_data), |
| 2948 | None, |
| 2949 | 0.1, |
| 2950 | ), |
| 2951 | ( |
| 2952 | "src='All 1's', dst='iface'", |
| 2953 | all_1s, |
| 2954 | None, |
| 2955 | ICMPv6EchoRequest(id=0xB, seq=5, data=icmpv6_data), |
| 2956 | None, |
| 2957 | 0.1, |
| 2958 | ), |
| 2959 | ( |
| 2960 | "src='iface', dst='All 1's'", |
| 2961 | None, |
| 2962 | all_1s, |
| 2963 | ICMPv6EchoRequest(id=0xB, seq=5, data=icmpv6_data), |
| 2964 | None, |
| 2965 | 0.1, |
| 2966 | ), |
| 2967 | ( |
| 2968 | "src='All 1's', dst='All 1's'", |
| 2969 | all_1s, |
| 2970 | all_1s, |
| 2971 | ICMPv6EchoRequest(id=0xB, seq=5, data=icmpv6_data), |
| 2972 | None, |
| 2973 | 0.1, |
| 2974 | ), |
| 2975 | ] |
| 2976 | ) |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2977 | def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout): |
| 2978 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2979 | self._testMethodDoc = "IPv6 Input Exception - %s" % name |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2980 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2981 | p_version = ( |
| 2982 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 2983 | / IPv6( |
| 2984 | src=src or self.pg0.remote_ip6, |
| 2985 | dst=dst or self.pg1.remote_ip6, |
| 2986 | version=3, |
| 2987 | ) |
| 2988 | / l4 |
| 2989 | / Raw(b"\xa5" * 100) |
| 2990 | ) |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2991 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2992 | self.send_and_assert_no_replies( |
| 2993 | self.pg0, p_version * NUM_PKTS, remark=msg or "", timeout=timeout |
| 2994 | ) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2995 | |
Dave Barach | 9080096 | 2019-05-24 13:03:01 -0400 | [diff] [blame] | 2996 | def test_hop_by_hop(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2997 | """Hop-by-hop header test""" |
Dave Barach | 9080096 | 2019-05-24 13:03:01 -0400 | [diff] [blame] | 2998 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 2999 | p = ( |
| 3000 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3001 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) |
| 3002 | / IPv6ExtHdrHopByHop() |
| 3003 | / inet6.UDP(sport=1234, dport=1234) |
| 3004 | / Raw(b"\xa5" * 100) |
| 3005 | ) |
Dave Barach | 9080096 | 2019-05-24 13:03:01 -0400 | [diff] [blame] | 3006 | |
| 3007 | self.pg0.add_stream(p) |
| 3008 | self.pg_enable_capture(self.pg_interfaces) |
| 3009 | self.pg_start() |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 3010 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3011 | |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3012 | class TestIP6Replace(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3013 | """IPv6 Table Replace""" |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3014 | |
| 3015 | @classmethod |
| 3016 | def setUpClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3017 | super(TestIP6Replace, cls).setUpClass() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3018 | |
| 3019 | @classmethod |
| 3020 | def tearDownClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3021 | super(TestIP6Replace, cls).tearDownClass() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3022 | |
| 3023 | def setUp(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3024 | super(TestIP6Replace, self).setUp() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3025 | |
| 3026 | self.create_pg_interfaces(range(4)) |
| 3027 | |
| 3028 | table_id = 1 |
| 3029 | self.tables = [] |
| 3030 | |
| 3031 | for i in self.pg_interfaces: |
| 3032 | i.admin_up() |
| 3033 | i.config_ip6() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3034 | i.generate_remote_hosts(2) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3035 | self.tables.append(VppIpTable(self, table_id, True).add_vpp_config()) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3036 | table_id += 1 |
| 3037 | |
| 3038 | def tearDown(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3039 | super(TestIP6Replace, self).tearDown() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3040 | for i in self.pg_interfaces: |
| 3041 | i.admin_down() |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3042 | i.unconfig_ip6() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3043 | |
| 3044 | def test_replace(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3045 | """IP Table Replace""" |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3046 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 3047 | MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t |
| 3048 | MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3049 | N_ROUTES = 20 |
| 3050 | links = [self.pg0, self.pg1, self.pg2, self.pg3] |
| 3051 | routes = [[], [], [], []] |
| 3052 | |
| 3053 | # the sizes of 'empty' tables |
| 3054 | for t in self.tables: |
| 3055 | self.assertEqual(len(t.dump()), 2) |
| 3056 | self.assertEqual(len(t.mdump()), 5) |
| 3057 | |
| 3058 | # load up the tables with some routes |
| 3059 | for ii, t in enumerate(self.tables): |
| 3060 | for jj in range(1, N_ROUTES): |
| 3061 | uni = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3062 | self, |
| 3063 | "2001::%d" % jj if jj != 0 else "2001::", |
| 3064 | 128, |
| 3065 | [ |
| 3066 | VppRoutePath( |
| 3067 | links[ii].remote_hosts[0].ip6, links[ii].sw_if_index |
| 3068 | ), |
| 3069 | VppRoutePath( |
| 3070 | links[ii].remote_hosts[1].ip6, links[ii].sw_if_index |
| 3071 | ), |
| 3072 | ], |
| 3073 | table_id=t.table_id, |
| 3074 | ).add_vpp_config() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3075 | multi = VppIpMRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3076 | self, |
| 3077 | "::", |
| 3078 | "ff:2001::%d" % jj, |
| 3079 | 128, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 3080 | MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3081 | [ |
| 3082 | VppMRoutePath( |
| 3083 | self.pg0.sw_if_index, |
| 3084 | MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT, |
| 3085 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 3086 | ), |
| 3087 | VppMRoutePath( |
| 3088 | self.pg1.sw_if_index, |
| 3089 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
| 3090 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 3091 | ), |
| 3092 | VppMRoutePath( |
| 3093 | self.pg2.sw_if_index, |
| 3094 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
| 3095 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 3096 | ), |
| 3097 | VppMRoutePath( |
| 3098 | self.pg3.sw_if_index, |
| 3099 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
| 3100 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 3101 | ), |
| 3102 | ], |
| 3103 | table_id=t.table_id, |
| 3104 | ).add_vpp_config() |
| 3105 | routes[ii].append({"uni": uni, "multi": multi}) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3106 | |
| 3107 | # |
| 3108 | # replace the tables a few times |
| 3109 | # |
| 3110 | for kk in range(3): |
| 3111 | # replace each table |
| 3112 | for t in self.tables: |
| 3113 | t.replace_begin() |
| 3114 | |
| 3115 | # all the routes are still there |
| 3116 | for ii, t in enumerate(self.tables): |
| 3117 | dump = t.dump() |
| 3118 | mdump = t.mdump() |
| 3119 | for r in routes[ii]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3120 | self.assertTrue(find_route_in_dump(dump, r["uni"], t)) |
| 3121 | self.assertTrue(find_mroute_in_dump(mdump, r["multi"], t)) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3122 | |
| 3123 | # redownload the even numbered routes |
| 3124 | for ii, t in enumerate(self.tables): |
| 3125 | for jj in range(0, N_ROUTES, 2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3126 | routes[ii][jj]["uni"].add_vpp_config() |
| 3127 | routes[ii][jj]["multi"].add_vpp_config() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3128 | |
| 3129 | # signal each table converged |
| 3130 | for t in self.tables: |
| 3131 | t.replace_end() |
| 3132 | |
| 3133 | # we should find the even routes, but not the odd |
| 3134 | for ii, t in enumerate(self.tables): |
| 3135 | dump = t.dump() |
| 3136 | mdump = t.mdump() |
| 3137 | for jj in range(0, N_ROUTES, 2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3138 | self.assertTrue(find_route_in_dump(dump, routes[ii][jj]["uni"], t)) |
| 3139 | self.assertTrue( |
| 3140 | find_mroute_in_dump(mdump, routes[ii][jj]["multi"], t) |
| 3141 | ) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3142 | for jj in range(1, N_ROUTES - 1, 2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3143 | self.assertFalse(find_route_in_dump(dump, routes[ii][jj]["uni"], t)) |
| 3144 | self.assertFalse( |
| 3145 | find_mroute_in_dump(mdump, routes[ii][jj]["multi"], t) |
| 3146 | ) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3147 | |
| 3148 | # reload all the routes |
| 3149 | for ii, t in enumerate(self.tables): |
| 3150 | for r in routes[ii]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3151 | r["uni"].add_vpp_config() |
| 3152 | r["multi"].add_vpp_config() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3153 | |
| 3154 | # all the routes are still there |
| 3155 | for ii, t in enumerate(self.tables): |
| 3156 | dump = t.dump() |
| 3157 | mdump = t.mdump() |
| 3158 | for r in routes[ii]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3159 | self.assertTrue(find_route_in_dump(dump, r["uni"], t)) |
| 3160 | self.assertTrue(find_mroute_in_dump(mdump, r["multi"], t)) |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 3161 | |
| 3162 | # |
| 3163 | # finally flush the tables for good measure |
| 3164 | # |
| 3165 | for t in self.tables: |
| 3166 | t.flush() |
| 3167 | self.assertEqual(len(t.dump()), 2) |
| 3168 | self.assertEqual(len(t.mdump()), 5) |
| 3169 | |
| 3170 | |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3171 | class TestIP6AddrReplace(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3172 | """IPv6 Interface Address Replace""" |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3173 | |
| 3174 | @classmethod |
| 3175 | def setUpClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3176 | super(TestIP6AddrReplace, cls).setUpClass() |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3177 | |
| 3178 | @classmethod |
| 3179 | def tearDownClass(cls): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3180 | super(TestIP6AddrReplace, cls).tearDownClass() |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3181 | |
| 3182 | def setUp(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3183 | super(TestIP6AddrReplace, self).setUp() |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3184 | |
| 3185 | self.create_pg_interfaces(range(4)) |
| 3186 | |
| 3187 | for i in self.pg_interfaces: |
| 3188 | i.admin_up() |
| 3189 | |
| 3190 | def tearDown(self): |
Tianyu Li | 6d95f8c | 2022-02-25 05:51:10 +0000 | [diff] [blame] | 3191 | super(TestIP6AddrReplace, self).tearDown() |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3192 | for i in self.pg_interfaces: |
| 3193 | i.admin_down() |
| 3194 | |
| 3195 | def get_n_pfxs(self, intf): |
| 3196 | return len(self.vapi.ip_address_dump(intf.sw_if_index, True)) |
| 3197 | |
| 3198 | def test_replace(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3199 | """IP interface address replace""" |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3200 | |
| 3201 | intf_pfxs = [[], [], [], []] |
| 3202 | |
| 3203 | # add prefixes to each of the interfaces |
| 3204 | for i in range(len(self.pg_interfaces)): |
| 3205 | intf = self.pg_interfaces[i] |
| 3206 | |
| 3207 | # 2001:16:x::1/64 |
| 3208 | addr = "2001:16:%d::1" % intf.sw_if_index |
| 3209 | a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 3210 | intf_pfxs[i].append(a) |
| 3211 | |
| 3212 | # 2001:16:x::2/64 - a different address in the same subnet as above |
| 3213 | addr = "2001:16:%d::2" % intf.sw_if_index |
| 3214 | a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 3215 | intf_pfxs[i].append(a) |
| 3216 | |
| 3217 | # 2001:15:x::2/64 - a different address and subnet |
| 3218 | addr = "2001:15:%d::2" % intf.sw_if_index |
| 3219 | a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 3220 | intf_pfxs[i].append(a) |
| 3221 | |
| 3222 | # a dump should n_address in it |
| 3223 | for intf in self.pg_interfaces: |
| 3224 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 3225 | |
| 3226 | # |
| 3227 | # remove all the address thru a replace |
| 3228 | # |
| 3229 | self.vapi.sw_interface_address_replace_begin() |
| 3230 | self.vapi.sw_interface_address_replace_end() |
| 3231 | for intf in self.pg_interfaces: |
| 3232 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 3233 | |
| 3234 | # |
| 3235 | # add all the interface addresses back |
| 3236 | # |
| 3237 | for p in intf_pfxs: |
| 3238 | for v in p: |
| 3239 | v.add_vpp_config() |
| 3240 | for intf in self.pg_interfaces: |
| 3241 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 3242 | |
| 3243 | # |
| 3244 | # replace again, but this time update/re-add the address on the first |
| 3245 | # two interfaces |
| 3246 | # |
| 3247 | self.vapi.sw_interface_address_replace_begin() |
| 3248 | |
| 3249 | for p in intf_pfxs[:2]: |
| 3250 | for v in p: |
| 3251 | v.add_vpp_config() |
| 3252 | |
| 3253 | self.vapi.sw_interface_address_replace_end() |
| 3254 | |
| 3255 | # on the first two the address still exist, |
| 3256 | # on the other two they do not |
| 3257 | for intf in self.pg_interfaces[:2]: |
| 3258 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 3259 | for p in intf_pfxs[:2]: |
| 3260 | for v in p: |
| 3261 | self.assertTrue(v.query_vpp_config()) |
| 3262 | for intf in self.pg_interfaces[2:]: |
| 3263 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 3264 | |
| 3265 | # |
| 3266 | # add all the interface addresses back on the last two |
| 3267 | # |
| 3268 | for p in intf_pfxs[2:]: |
| 3269 | for v in p: |
| 3270 | v.add_vpp_config() |
| 3271 | for intf in self.pg_interfaces: |
| 3272 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 3273 | |
| 3274 | # |
| 3275 | # replace again, this time add different prefixes on all the interfaces |
| 3276 | # |
| 3277 | self.vapi.sw_interface_address_replace_begin() |
| 3278 | |
| 3279 | pfxs = [] |
| 3280 | for intf in self.pg_interfaces: |
| 3281 | # 2001:18:x::1/64 |
| 3282 | addr = "2001:18:%d::1" % intf.sw_if_index |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3283 | pfxs.append(VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()) |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3284 | |
| 3285 | self.vapi.sw_interface_address_replace_end() |
| 3286 | |
| 3287 | # only .18 should exist on each interface |
| 3288 | for intf in self.pg_interfaces: |
| 3289 | self.assertEqual(self.get_n_pfxs(intf), 1) |
| 3290 | for pfx in pfxs: |
| 3291 | self.assertTrue(pfx.query_vpp_config()) |
| 3292 | |
| 3293 | # |
| 3294 | # remove everything |
| 3295 | # |
| 3296 | self.vapi.sw_interface_address_replace_begin() |
| 3297 | self.vapi.sw_interface_address_replace_end() |
| 3298 | for intf in self.pg_interfaces: |
| 3299 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 3300 | |
| 3301 | # |
| 3302 | # add prefixes to each interface. post-begin add the prefix from |
| 3303 | # interface X onto interface Y. this would normally be an error |
| 3304 | # since it would generate a 'duplicate address' warning. but in |
| 3305 | # this case, since what is newly downloaded is sane, it's ok |
| 3306 | # |
| 3307 | for intf in self.pg_interfaces: |
| 3308 | # 2001:18:x::1/64 |
| 3309 | addr = "2001:18:%d::1" % intf.sw_if_index |
| 3310 | VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 3311 | |
| 3312 | self.vapi.sw_interface_address_replace_begin() |
| 3313 | |
| 3314 | pfxs = [] |
| 3315 | for intf in self.pg_interfaces: |
| 3316 | # 2001:18:x::1/64 |
| 3317 | addr = "2001:18:%d::1" % (intf.sw_if_index + 1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3318 | pfxs.append(VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config()) |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3319 | |
| 3320 | self.vapi.sw_interface_address_replace_end() |
| 3321 | |
| 3322 | self.logger.info(self.vapi.cli("sh int addr")) |
| 3323 | |
| 3324 | for intf in self.pg_interfaces: |
| 3325 | self.assertEqual(self.get_n_pfxs(intf), 1) |
| 3326 | for pfx in pfxs: |
| 3327 | self.assertTrue(pfx.query_vpp_config()) |
| 3328 | |
| 3329 | |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3330 | class TestIP6LinkLocal(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3331 | """IPv6 Link Local""" |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3332 | |
| 3333 | @classmethod |
| 3334 | def setUpClass(cls): |
| 3335 | super(TestIP6LinkLocal, cls).setUpClass() |
| 3336 | |
| 3337 | @classmethod |
| 3338 | def tearDownClass(cls): |
| 3339 | super(TestIP6LinkLocal, cls).tearDownClass() |
| 3340 | |
| 3341 | def setUp(self): |
| 3342 | super(TestIP6LinkLocal, self).setUp() |
| 3343 | |
| 3344 | self.create_pg_interfaces(range(2)) |
| 3345 | |
| 3346 | for i in self.pg_interfaces: |
| 3347 | i.admin_up() |
| 3348 | |
| 3349 | def tearDown(self): |
| 3350 | super(TestIP6LinkLocal, self).tearDown() |
| 3351 | for i in self.pg_interfaces: |
| 3352 | i.admin_down() |
| 3353 | |
| 3354 | def test_ip6_ll(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3355 | """IPv6 Link Local""" |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3356 | |
| 3357 | # |
| 3358 | # two APIs to add a link local address. |
| 3359 | # 1 - just like any other prefix |
| 3360 | # 2 - with the special set LL API |
| 3361 | # |
| 3362 | |
| 3363 | # |
| 3364 | # First with the API to set a 'normal' prefix |
| 3365 | # |
| 3366 | ll1 = "fe80:1::1" |
| 3367 | ll2 = "fe80:2::2" |
| 3368 | ll3 = "fe80:3::3" |
| 3369 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3370 | VppNeighbor( |
| 3371 | self, self.pg0.sw_if_index, self.pg0.remote_mac, ll2 |
| 3372 | ).add_vpp_config() |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3373 | |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3374 | VppIpInterfaceAddress(self, self.pg0, ll1, 128).add_vpp_config() |
| 3375 | |
| 3376 | # |
| 3377 | # should be able to ping the ll |
| 3378 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3379 | p_echo_request_1 = ( |
| 3380 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3381 | / IPv6(src=ll2, dst=ll1) |
| 3382 | / ICMPv6EchoRequest() |
| 3383 | ) |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3384 | |
| 3385 | self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0) |
| 3386 | |
| 3387 | # |
| 3388 | # change the link-local on pg0 |
| 3389 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3390 | v_ll3 = VppIpInterfaceAddress(self, self.pg0, ll3, 128).add_vpp_config() |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3391 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3392 | p_echo_request_3 = ( |
| 3393 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3394 | / IPv6(src=ll2, dst=ll3) |
| 3395 | / ICMPv6EchoRequest() |
| 3396 | ) |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3397 | |
| 3398 | self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0) |
| 3399 | |
| 3400 | # |
| 3401 | # set a normal v6 prefix on the link |
| 3402 | # |
| 3403 | self.pg0.config_ip6() |
| 3404 | |
| 3405 | self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0) |
| 3406 | |
| 3407 | # the link-local cannot be removed |
| 3408 | with self.vapi.assert_negative_api_retval(): |
| 3409 | v_ll3.remove_vpp_config() |
| 3410 | |
| 3411 | # |
| 3412 | # Use the specific link-local API on pg1 |
| 3413 | # |
| 3414 | VppIp6LinkLocalAddress(self, self.pg1, ll1).add_vpp_config() |
| 3415 | self.send_and_expect(self.pg1, [p_echo_request_1], self.pg1) |
| 3416 | |
| 3417 | VppIp6LinkLocalAddress(self, self.pg1, ll3).add_vpp_config() |
| 3418 | self.send_and_expect(self.pg1, [p_echo_request_3], self.pg1) |
| 3419 | |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3420 | def test_ip6_ll_p2p(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3421 | """IPv6 Link Local P2P (GRE)""" |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3422 | |
| 3423 | self.pg0.config_ip4() |
| 3424 | self.pg0.resolve_arp() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3425 | gre_if = VppGreInterface( |
| 3426 | self, self.pg0.local_ip4, self.pg0.remote_ip4 |
| 3427 | ).add_vpp_config() |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3428 | gre_if.admin_up() |
| 3429 | |
| 3430 | ll1 = "fe80:1::1" |
| 3431 | ll2 = "fe80:2::2" |
| 3432 | |
| 3433 | VppIpInterfaceAddress(self, gre_if, ll1, 128).add_vpp_config() |
| 3434 | |
| 3435 | self.logger.info(self.vapi.cli("sh ip6-ll gre0 fe80:2::2")) |
| 3436 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3437 | p_echo_request_1 = ( |
| 3438 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3439 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 3440 | / GRE() |
| 3441 | / IPv6(src=ll2, dst=ll1) |
| 3442 | / ICMPv6EchoRequest() |
| 3443 | ) |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3444 | self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0) |
| 3445 | |
| 3446 | self.pg0.unconfig_ip4() |
| 3447 | gre_if.remove_vpp_config() |
| 3448 | |
| 3449 | def test_ip6_ll_p2mp(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3450 | """IPv6 Link Local P2MP (GRE)""" |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3451 | |
| 3452 | self.pg0.config_ip4() |
| 3453 | self.pg0.resolve_arp() |
| 3454 | |
| 3455 | gre_if = VppGreInterface( |
| 3456 | self, |
| 3457 | self.pg0.local_ip4, |
| 3458 | "0.0.0.0", |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3459 | mode=(VppEnum.vl_api_tunnel_mode_t.TUNNEL_API_MODE_MP), |
| 3460 | ).add_vpp_config() |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3461 | gre_if.admin_up() |
| 3462 | |
| 3463 | ll1 = "fe80:1::1" |
| 3464 | ll2 = "fe80:2::2" |
| 3465 | |
| 3466 | VppIpInterfaceAddress(self, gre_if, ll1, 128).add_vpp_config() |
| 3467 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3468 | p_echo_request_1 = ( |
| 3469 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3470 | / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) |
| 3471 | / GRE() |
| 3472 | / IPv6(src=ll2, dst=ll1) |
| 3473 | / ICMPv6EchoRequest() |
| 3474 | ) |
Neale Ranns | dfef64b | 2021-05-20 16:28:12 +0000 | [diff] [blame] | 3475 | |
| 3476 | # no route back at this point |
| 3477 | self.send_and_assert_no_replies(self.pg0, [p_echo_request_1]) |
| 3478 | |
| 3479 | # add teib entry for the peer |
| 3480 | teib = VppTeib(self, gre_if, ll2, self.pg0.remote_ip4) |
| 3481 | teib.add_vpp_config() |
| 3482 | |
| 3483 | self.logger.info(self.vapi.cli("sh ip6-ll gre0 %s" % ll2)) |
| 3484 | self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0) |
| 3485 | |
| 3486 | # teardown |
| 3487 | self.pg0.unconfig_ip4() |
| 3488 | |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 3489 | |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3490 | class TestIPv6PathMTU(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3491 | """IPv6 Path MTU""" |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3492 | |
| 3493 | def setUp(self): |
| 3494 | super(TestIPv6PathMTU, self).setUp() |
| 3495 | |
| 3496 | self.create_pg_interfaces(range(2)) |
| 3497 | |
| 3498 | # setup all interfaces |
| 3499 | for i in self.pg_interfaces: |
| 3500 | i.admin_up() |
| 3501 | i.config_ip6() |
| 3502 | i.resolve_ndp() |
| 3503 | |
| 3504 | def tearDown(self): |
| 3505 | super(TestIPv6PathMTU, self).tearDown() |
| 3506 | for i in self.pg_interfaces: |
| 3507 | i.unconfig_ip6() |
| 3508 | i.admin_down() |
| 3509 | |
| 3510 | def test_path_mtu_local(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3511 | """Path MTU for attached neighbour""" |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3512 | |
| 3513 | self.vapi.cli("set log class ip level debug") |
| 3514 | # |
| 3515 | # The goal here is not test that fragmentation works correctly, |
| 3516 | # that's done elsewhere, the intent is to ensure that the Path MTU |
| 3517 | # settings are honoured. |
| 3518 | # |
| 3519 | |
| 3520 | # |
| 3521 | # IPv6 will only frag locally generated packets, so use tunnelled |
| 3522 | # packets post encap |
| 3523 | # |
| 3524 | tun = VppIpIpTunInterface( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3525 | self, self.pg1, self.pg1.local_ip6, self.pg1.remote_ip6 |
| 3526 | ) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3527 | tun.add_vpp_config() |
| 3528 | tun.admin_up() |
| 3529 | tun.config_ip6() |
| 3530 | |
| 3531 | # set the interface MTU to a reasonable value |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3532 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2800, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3533 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3534 | p_6k = ( |
| 3535 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3536 | / IPv6(src=self.pg0.remote_ip6, dst=tun.remote_ip6) |
| 3537 | / UDP(sport=1234, dport=5678) |
| 3538 | / Raw(b"0xa" * 2000) |
| 3539 | ) |
| 3540 | p_2k = ( |
| 3541 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3542 | / IPv6(src=self.pg0.remote_ip6, dst=tun.remote_ip6) |
| 3543 | / UDP(sport=1234, dport=5678) |
| 3544 | / Raw(b"0xa" * 1000) |
| 3545 | ) |
| 3546 | p_1k = ( |
| 3547 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3548 | / IPv6(src=self.pg0.remote_ip6, dst=tun.remote_ip6) |
| 3549 | / UDP(sport=1234, dport=5678) |
| 3550 | / Raw(b"0xa" * 600) |
| 3551 | ) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3552 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3553 | nbr = VppNeighbor( |
| 3554 | self, self.pg1.sw_if_index, self.pg1.remote_mac, self.pg1.remote_ip6 |
| 3555 | ).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3556 | |
| 3557 | # this is now the interface MTU frags |
Neale Ranns | ec5371e | 2022-03-04 11:45:41 +0000 | [diff] [blame] | 3558 | self.send_and_expect(self.pg0, [p_6k], self.pg1, n_rx=4) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3559 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3560 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3561 | |
| 3562 | # drop the path MTU for this neighbour to below the interface MTU |
| 3563 | # expect more frags |
| 3564 | pmtu = VppIpPathMtu(self, self.pg1.remote_ip6, 1300).add_vpp_config() |
| 3565 | |
| 3566 | # print/format the adj delegate and trackers |
| 3567 | self.logger.info(self.vapi.cli("sh ip pmtu")) |
| 3568 | self.logger.info(self.vapi.cli("sh adj 7")) |
| 3569 | |
| 3570 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3571 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3572 | |
| 3573 | # increase the path MTU to more than the interface |
| 3574 | # expect to use the interface MTU |
| 3575 | pmtu.modify(8192) |
| 3576 | |
| 3577 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3578 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3579 | |
| 3580 | # go back to an MTU from the path |
| 3581 | pmtu.modify(1300) |
| 3582 | |
| 3583 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3584 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3585 | |
| 3586 | # raise the interface's MTU |
| 3587 | # should still use that of the path |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3588 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2000, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3589 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3590 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3591 | |
| 3592 | # set path high and interface low |
| 3593 | pmtu.modify(2000) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3594 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1300, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3595 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3596 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3597 | |
| 3598 | # remove the path MTU |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3599 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2800, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3600 | pmtu.modify(0) |
| 3601 | |
| 3602 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3603 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3604 | |
| 3605 | def test_path_mtu_remote(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3606 | """Path MTU for remote neighbour""" |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3607 | |
| 3608 | self.vapi.cli("set log class ip level debug") |
| 3609 | # |
| 3610 | # The goal here is not test that fragmentation works correctly, |
| 3611 | # that's done elsewhere, the intent is to ensure that the Path MTU |
| 3612 | # settings are honoured. |
| 3613 | # |
| 3614 | tun_dst = "2001::1" |
| 3615 | |
| 3616 | route = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3617 | self, tun_dst, 64, [VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)] |
| 3618 | ).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3619 | |
| 3620 | # |
| 3621 | # IPv6 will only frag locally generated packets, so use tunnelled |
| 3622 | # packets post encap |
| 3623 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3624 | tun = VppIpIpTunInterface(self, self.pg1, self.pg1.local_ip6, tun_dst) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3625 | tun.add_vpp_config() |
| 3626 | tun.admin_up() |
| 3627 | tun.config_ip6() |
| 3628 | |
| 3629 | # set the interface MTU to a reasonable value |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3630 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2800, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3631 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3632 | p_2k = ( |
| 3633 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3634 | / IPv6(src=self.pg0.remote_ip6, dst=tun.remote_ip6) |
| 3635 | / UDP(sport=1234, dport=5678) |
| 3636 | / Raw(b"0xa" * 1000) |
| 3637 | ) |
| 3638 | p_1k = ( |
| 3639 | Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) |
| 3640 | / IPv6(src=self.pg0.remote_ip6, dst=tun.remote_ip6) |
| 3641 | / UDP(sport=1234, dport=5678) |
| 3642 | / Raw(b"0xa" * 600) |
| 3643 | ) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3644 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3645 | nbr = VppNeighbor( |
| 3646 | self, self.pg1.sw_if_index, self.pg1.remote_mac, self.pg1.remote_ip6 |
| 3647 | ).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3648 | |
| 3649 | # this is now the interface MTU frags |
| 3650 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3651 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3652 | |
| 3653 | # drop the path MTU for this neighbour to below the interface MTU |
| 3654 | # expect more frags |
| 3655 | pmtu = VppIpPathMtu(self, tun_dst, 1300).add_vpp_config() |
| 3656 | |
| 3657 | # print/format the fib entry/dpo |
| 3658 | self.logger.info(self.vapi.cli("sh ip6 fib 2001::1")) |
| 3659 | |
| 3660 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3661 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3662 | |
| 3663 | # increase the path MTU to more than the interface |
| 3664 | # expect to use the interface MTU |
| 3665 | pmtu.modify(8192) |
| 3666 | |
| 3667 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3668 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3669 | |
| 3670 | # go back to an MTU from the path |
| 3671 | pmtu.modify(1300) |
| 3672 | |
| 3673 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3674 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3675 | |
| 3676 | # raise the interface's MTU |
| 3677 | # should still use that of the path |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3678 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2000, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3679 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3680 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3681 | |
| 3682 | # turn the tun_dst into an attached neighbour |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3683 | route.modify([VppRoutePath("::", self.pg1.sw_if_index)]) |
| 3684 | nbr2 = VppNeighbor( |
| 3685 | self, self.pg1.sw_if_index, self.pg1.remote_mac, tun_dst |
| 3686 | ).add_vpp_config() |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3687 | |
| 3688 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3689 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3690 | |
| 3691 | # add back to not attached |
| 3692 | nbr2.remove_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3693 | route.modify([VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3694 | |
| 3695 | # set path high and interface low |
| 3696 | pmtu.modify(2000) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3697 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1300, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3698 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=3) |
| 3699 | self.send_and_expect(self.pg0, [p_1k], self.pg1, n_rx=2) |
| 3700 | |
| 3701 | # remove the path MTU |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3702 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [2800, 0, 0, 0]) |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 3703 | pmtu.remove_vpp_config() |
| 3704 | self.send_and_expect(self.pg0, [p_2k], self.pg1, n_rx=2) |
| 3705 | self.send_and_expect(self.pg0, [p_1k], self.pg1) |
| 3706 | |
| 3707 | |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3708 | class TestIPFibSource(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3709 | """IPv6 Table FibSource""" |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3710 | |
| 3711 | @classmethod |
| 3712 | def setUpClass(cls): |
| 3713 | super(TestIPFibSource, cls).setUpClass() |
| 3714 | |
| 3715 | @classmethod |
| 3716 | def tearDownClass(cls): |
| 3717 | super(TestIPFibSource, cls).tearDownClass() |
| 3718 | |
| 3719 | def setUp(self): |
| 3720 | super(TestIPFibSource, self).setUp() |
| 3721 | |
| 3722 | self.create_pg_interfaces(range(2)) |
| 3723 | |
| 3724 | for i in self.pg_interfaces: |
| 3725 | i.admin_up() |
| 3726 | i.config_ip6() |
| 3727 | i.resolve_arp() |
| 3728 | i.generate_remote_hosts(2) |
| 3729 | i.configure_ipv6_neighbors() |
| 3730 | |
| 3731 | def tearDown(self): |
| 3732 | super(TestIPFibSource, self).tearDown() |
| 3733 | for i in self.pg_interfaces: |
| 3734 | i.admin_down() |
| 3735 | i.unconfig_ip4() |
| 3736 | |
| 3737 | def test_fib_source(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3738 | """IP Table FibSource""" |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3739 | |
| 3740 | routes = self.vapi.ip_route_v2_dump(0, True) |
| 3741 | |
| 3742 | # 2 interfaces (4 routes) + 2 specials + 4 neighbours = 10 routes |
| 3743 | self.assertEqual(len(routes), 10) |
| 3744 | |
| 3745 | # dump all the sources in the FIB |
| 3746 | sources = self.vapi.fib_source_dump() |
| 3747 | for source in sources: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3748 | if source.src.name == "API": |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3749 | api_source = source.src |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3750 | if source.src.name == "interface": |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3751 | intf_source = source.src |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3752 | if source.src.name == "adjacency": |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3753 | adj_source = source.src |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3754 | if source.src.name == "special": |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3755 | special_source = source.src |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3756 | if source.src.name == "default-route": |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3757 | dr_source = source.src |
| 3758 | |
| 3759 | # dump the individual route types |
| 3760 | routes = self.vapi.ip_route_v2_dump(0, True, src=adj_source.id) |
| 3761 | self.assertEqual(len(routes), 4) |
| 3762 | routes = self.vapi.ip_route_v2_dump(0, True, src=intf_source.id) |
| 3763 | self.assertEqual(len(routes), 4) |
| 3764 | routes = self.vapi.ip_route_v2_dump(0, True, src=special_source.id) |
| 3765 | self.assertEqual(len(routes), 1) |
| 3766 | routes = self.vapi.ip_route_v2_dump(0, True, src=dr_source.id) |
| 3767 | self.assertEqual(len(routes), 1) |
| 3768 | |
| 3769 | # add a new soure that'a better than the API |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3770 | self.vapi.fib_source_add( |
| 3771 | src={"name": "bgp", "priority": api_source.priority - 1} |
| 3772 | ) |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3773 | |
| 3774 | # dump all the sources to check our new one is there |
| 3775 | sources = self.vapi.fib_source_dump() |
| 3776 | |
| 3777 | for source in sources: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3778 | if source.src.name == "bgp": |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3779 | bgp_source = source.src |
| 3780 | |
| 3781 | self.assertTrue(bgp_source) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3782 | self.assertEqual(bgp_source.priority, api_source.priority - 1) |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3783 | |
| 3784 | # add a route with the default API source |
| 3785 | r1 = VppIpRouteV2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3786 | self, |
| 3787 | "2001::1", |
| 3788 | 128, |
| 3789 | [VppRoutePath(self.pg0.remote_ip6, self.pg0.sw_if_index)], |
| 3790 | ).add_vpp_config() |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3791 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3792 | r2 = VppIpRouteV2( |
| 3793 | self, |
| 3794 | "2001::1", |
| 3795 | 128, |
| 3796 | [VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)], |
| 3797 | src=bgp_source.id, |
| 3798 | ).add_vpp_config() |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3799 | |
| 3800 | # ensure the BGP source takes priority |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3801 | p = ( |
| 3802 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3803 | / IPv6(src=self.pg0.remote_ip6, dst="2001::1") |
| 3804 | / inet6.UDP(sport=1234, dport=1234) |
| 3805 | / Raw(b"\xa5" * 100) |
| 3806 | ) |
Neale Ranns | 976b259 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 3807 | |
| 3808 | self.send_and_expect(self.pg0, [p], self.pg1) |
| 3809 | |
| 3810 | r2.remove_vpp_config() |
| 3811 | r1.remove_vpp_config() |
| 3812 | |
| 3813 | self.assertFalse(find_route(self, "2001::1", 128)) |
| 3814 | |
| 3815 | |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3816 | class TestIPxAF(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3817 | """IP cross AF""" |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3818 | |
| 3819 | @classmethod |
| 3820 | def setUpClass(cls): |
| 3821 | super(TestIPxAF, cls).setUpClass() |
| 3822 | |
| 3823 | @classmethod |
| 3824 | def tearDownClass(cls): |
| 3825 | super(TestIPxAF, cls).tearDownClass() |
| 3826 | |
| 3827 | def setUp(self): |
| 3828 | super(TestIPxAF, self).setUp() |
| 3829 | |
| 3830 | self.create_pg_interfaces(range(2)) |
| 3831 | |
| 3832 | for i in self.pg_interfaces: |
| 3833 | i.admin_up() |
| 3834 | i.config_ip6() |
| 3835 | i.config_ip4() |
| 3836 | i.resolve_arp() |
| 3837 | i.resolve_ndp() |
| 3838 | |
| 3839 | def tearDown(self): |
| 3840 | super(TestIPxAF, self).tearDown() |
| 3841 | for i in self.pg_interfaces: |
| 3842 | i.admin_down() |
| 3843 | i.unconfig_ip4() |
| 3844 | i.unconfig_ip6() |
| 3845 | |
| 3846 | def test_x_af(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3847 | """Cross AF routing""" |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3848 | |
| 3849 | N_PKTS = 63 |
| 3850 | # a v4 route via a v6 attached next-hop |
| 3851 | VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3852 | self, |
| 3853 | "1.1.1.1", |
| 3854 | 32, |
| 3855 | [VppRoutePath(self.pg1.remote_ip6, self.pg1.sw_if_index)], |
| 3856 | ).add_vpp_config() |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3857 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3858 | p = ( |
| 3859 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3860 | / IP(src=self.pg0.remote_ip4, dst="1.1.1.1") |
| 3861 | / UDP(sport=1234, dport=1234) |
| 3862 | / Raw(b"\xa5" * 100) |
| 3863 | ) |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3864 | rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1) |
| 3865 | |
| 3866 | for rx in rxs: |
| 3867 | self.assertEqual(rx[IP].dst, "1.1.1.1") |
| 3868 | |
| 3869 | # a v6 route via a v4 attached next-hop |
| 3870 | VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3871 | self, |
| 3872 | "2001::1", |
| 3873 | 128, |
| 3874 | [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)], |
| 3875 | ).add_vpp_config() |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3876 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3877 | p = ( |
| 3878 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3879 | / IPv6(src=self.pg0.remote_ip6, dst="2001::1") |
| 3880 | / UDP(sport=1234, dport=1234) |
| 3881 | / Raw(b"\xa5" * 100) |
| 3882 | ) |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3883 | rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1) |
| 3884 | |
| 3885 | for rx in rxs: |
| 3886 | self.assertEqual(rx[IPv6].dst, "2001::1") |
| 3887 | |
| 3888 | # a recursive v4 route via a v6 next-hop (from above) |
| 3889 | VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3890 | self, "2.2.2.2", 32, [VppRoutePath("2001::1", 0xFFFFFFFF)] |
| 3891 | ).add_vpp_config() |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3892 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3893 | p = ( |
| 3894 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3895 | / IP(src=self.pg0.remote_ip4, dst="2.2.2.2") |
| 3896 | / UDP(sport=1234, dport=1234) |
| 3897 | / Raw(b"\xa5" * 100) |
| 3898 | ) |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3899 | rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1) |
| 3900 | |
| 3901 | # a recursive v4 route via a v6 next-hop |
| 3902 | VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3903 | self, "2.2.2.3", 32, [VppRoutePath(self.pg1.remote_ip6, 0xFFFFFFFF)] |
| 3904 | ).add_vpp_config() |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3905 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3906 | p = ( |
| 3907 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3908 | / IP(src=self.pg0.remote_ip4, dst="2.2.2.3") |
| 3909 | / UDP(sport=1234, dport=1234) |
| 3910 | / Raw(b"\xa5" * 100) |
| 3911 | ) |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3912 | rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1) |
| 3913 | |
| 3914 | # a recursive v6 route via a v4 next-hop |
| 3915 | VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3916 | self, "3001::1", 128, [VppRoutePath(self.pg1.remote_ip4, 0xFFFFFFFF)] |
| 3917 | ).add_vpp_config() |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3918 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3919 | p = ( |
| 3920 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3921 | / IPv6(src=self.pg0.remote_ip6, dst="3001::1") |
| 3922 | / UDP(sport=1234, dport=1234) |
| 3923 | / Raw(b"\xa5" * 100) |
| 3924 | ) |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3925 | rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1) |
| 3926 | |
| 3927 | for rx in rxs: |
| 3928 | self.assertEqual(rx[IPv6].dst, "3001::1") |
| 3929 | |
| 3930 | VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3931 | self, "3001::2", 128, [VppRoutePath("1.1.1.1", 0xFFFFFFFF)] |
| 3932 | ).add_vpp_config() |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3933 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3934 | p = ( |
| 3935 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3936 | / IPv6(src=self.pg0.remote_ip6, dst="3001::2") |
| 3937 | / UDP(sport=1234, dport=1234) |
| 3938 | / Raw(b"\xa5" * 100) |
| 3939 | ) |
Neale Ranns | 91adf24 | 2021-05-27 12:18:52 +0000 | [diff] [blame] | 3940 | rxs = self.send_and_expect(self.pg0, p * N_PKTS, self.pg1) |
| 3941 | |
| 3942 | for rx in rxs: |
| 3943 | self.assertEqual(rx[IPv6].dst, "3001::2") |
| 3944 | |
| 3945 | |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3946 | class TestIPv6Punt(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3947 | """IPv6 Punt Police/Redirect""" |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3948 | |
| 3949 | def setUp(self): |
| 3950 | super(TestIPv6Punt, self).setUp() |
| 3951 | self.create_pg_interfaces(range(4)) |
| 3952 | |
| 3953 | for i in self.pg_interfaces: |
| 3954 | i.admin_up() |
| 3955 | i.config_ip6() |
| 3956 | i.resolve_ndp() |
| 3957 | |
| 3958 | def tearDown(self): |
| 3959 | super(TestIPv6Punt, self).tearDown() |
| 3960 | for i in self.pg_interfaces: |
| 3961 | i.unconfig_ip6() |
| 3962 | i.admin_down() |
| 3963 | |
| 3964 | def test_ip6_punt(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3965 | """IPv6 punt police and redirect""" |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3966 | |
| 3967 | # use UDP packet that have a port we need to explicitly |
| 3968 | # register to get punted. |
| 3969 | pt_l4 = VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4 |
| 3970 | af_ip6 = VppEnum.vl_api_address_family_t.ADDRESS_IP6 |
| 3971 | udp_proto = VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP |
| 3972 | punt_udp = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3973 | "type": pt_l4, |
| 3974 | "punt": { |
| 3975 | "l4": { |
| 3976 | "af": af_ip6, |
| 3977 | "protocol": udp_proto, |
| 3978 | "port": 7654, |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3979 | } |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3980 | }, |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | self.vapi.set_punt(is_add=1, punt=punt_udp) |
| 3984 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3985 | pkts = ( |
| 3986 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 3987 | / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) |
| 3988 | / UDP(sport=1234, dport=7654) |
| 3989 | / Raw(b"\xa5" * 100) |
| 3990 | ) * 1025 |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3991 | |
| 3992 | # |
| 3993 | # Configure a punt redirect via pg1. |
| 3994 | # |
| 3995 | nh_addr = self.pg1.remote_ip6 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3996 | ip_punt_redirect = VppIpPuntRedirect( |
| 3997 | self, self.pg0.sw_if_index, self.pg1.sw_if_index, nh_addr |
| 3998 | ) |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 3999 | ip_punt_redirect.add_vpp_config() |
| 4000 | |
| 4001 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 4002 | |
| 4003 | # |
| 4004 | # add a policer |
| 4005 | # |
| 4006 | policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1) |
| 4007 | policer.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4008 | ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index, is_ip6=True) |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4009 | ip_punt_policer.add_vpp_config() |
| 4010 | |
| 4011 | self.vapi.cli("clear trace") |
| 4012 | self.pg0.add_stream(pkts) |
| 4013 | self.pg_enable_capture(self.pg_interfaces) |
| 4014 | self.pg_start() |
| 4015 | |
| 4016 | # |
| 4017 | # the number of packet received should be greater than 0, |
| 4018 | # but not equal to the number sent, since some were policed |
| 4019 | # |
| 4020 | rx = self.pg1._get_capture(1) |
| 4021 | |
| 4022 | stats = policer.get_stats() |
| 4023 | |
| 4024 | # Single rate policer - expect conform, violate but no exceed |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4025 | self.assertGreater(stats["conform_packets"], 0) |
| 4026 | self.assertEqual(stats["exceed_packets"], 0) |
| 4027 | self.assertGreater(stats["violate_packets"], 0) |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4028 | |
| 4029 | self.assertGreater(len(rx), 0) |
| 4030 | self.assertLess(len(rx), len(pkts)) |
| 4031 | |
| 4032 | # |
| 4033 | # remove the policer. back to full rx |
| 4034 | # |
| 4035 | ip_punt_policer.remove_vpp_config() |
| 4036 | policer.remove_vpp_config() |
| 4037 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 4038 | |
| 4039 | # |
| 4040 | # remove the redirect. expect full drop. |
| 4041 | # |
| 4042 | ip_punt_redirect.remove_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4043 | self.send_and_assert_no_replies(self.pg0, pkts, "IP no punt config") |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4044 | |
| 4045 | # |
| 4046 | # Add a redirect that is not input port selective |
| 4047 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4048 | ip_punt_redirect = VppIpPuntRedirect( |
| 4049 | self, 0xFFFFFFFF, self.pg1.sw_if_index, nh_addr |
| 4050 | ) |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4051 | ip_punt_redirect.add_vpp_config() |
| 4052 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 4053 | ip_punt_redirect.remove_vpp_config() |
| 4054 | |
| 4055 | def test_ip6_punt_dump(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4056 | """IPv6 punt redirect dump""" |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4057 | |
| 4058 | # |
| 4059 | # Configure a punt redirects |
| 4060 | # |
| 4061 | nh_address = self.pg3.remote_ip6 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4062 | ipr_03 = VppIpPuntRedirect( |
| 4063 | self, self.pg0.sw_if_index, self.pg3.sw_if_index, nh_address |
| 4064 | ) |
| 4065 | ipr_13 = VppIpPuntRedirect( |
| 4066 | self, self.pg1.sw_if_index, self.pg3.sw_if_index, nh_address |
| 4067 | ) |
| 4068 | ipr_23 = VppIpPuntRedirect( |
| 4069 | self, self.pg2.sw_if_index, self.pg3.sw_if_index, "::" |
| 4070 | ) |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4071 | ipr_03.add_vpp_config() |
| 4072 | ipr_13.add_vpp_config() |
| 4073 | ipr_23.add_vpp_config() |
| 4074 | |
| 4075 | # |
| 4076 | # Dump pg0 punt redirects |
| 4077 | # |
| 4078 | self.assertTrue(ipr_03.query_vpp_config()) |
| 4079 | self.assertTrue(ipr_13.query_vpp_config()) |
| 4080 | self.assertTrue(ipr_23.query_vpp_config()) |
| 4081 | |
| 4082 | # |
| 4083 | # Dump punt redirects for all interfaces |
| 4084 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4085 | punts = self.vapi.ip_punt_redirect_dump(sw_if_index=0xFFFFFFFF, is_ipv6=True) |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4086 | self.assertEqual(len(punts), 3) |
| 4087 | for p in punts: |
| 4088 | self.assertEqual(p.punt.tx_sw_if_index, self.pg3.sw_if_index) |
| 4089 | self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4090 | self.assertEqual(str(punts[2].punt.nh), "::") |
Benoît Ganne | 7c7b505 | 2021-10-04 12:03:20 +0200 | [diff] [blame] | 4091 | |
| 4092 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 4093 | if __name__ == "__main__": |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 4094 | unittest.main(testRunner=VppTestRunner) |