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 |
| 10 | from scapy.contrib.mpls import MPLS |
| 11 | from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_RS, \ |
| 12 | ICMPv6ND_RA, ICMPv6NDOptMTU, ICMPv6NDOptSrcLLAddr, ICMPv6NDOptPrefixInfo, \ |
| 13 | ICMPv6ND_NA, ICMPv6NDOptDstLLAddr, ICMPv6DestUnreach, icmp6types, \ |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 14 | ICMPv6TimeExceeded, ICMPv6EchoRequest, ICMPv6EchoReply, \ |
| 15 | IPv6ExtHdrHopByHop, ICMPv6MLReport2, ICMPv6MLDMultAddrRec |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 16 | from scapy.layers.l2 import Ether, Dot1Q |
| 17 | from scapy.packet import Raw |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 18 | from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \ |
| 19 | in6_mactoifaceid |
| 20 | from six import moves |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 21 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 22 | from framework import VppTestCase, VppTestRunner |
Paul Vinciguerra | e8fece8 | 2019-02-28 15:34:00 -0800 | [diff] [blame] | 23 | from util import ppp, ip6_normalize, mk_ll_addr |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 24 | from vpp_papi import VppEnum |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 25 | from vpp_ip import DpoProto, VppIpPuntPolicer, VppIpPuntRedirect |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 26 | from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \ |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 27 | VppMRoutePath, VppMplsIpBind, \ |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 28 | VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \ |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 29 | VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump, \ |
| 30 | VppIp6LinkLocalAddress |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 31 | from vpp_neighbor import find_nbr, VppNeighbor |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 32 | from vpp_pg_interface import is_ipv6_misc |
| 33 | from vpp_sub_interface import VppSubInterface, VppDot1QSubint |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 34 | from vpp_policer import VppPolicer |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 35 | from ipaddress import IPv6Network, IPv6Address |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 36 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 37 | AF_INET6 = socket.AF_INET6 |
| 38 | |
Paul Vinciguerra | 1e18eb2 | 2018-11-25 16:09:26 -0800 | [diff] [blame] | 39 | try: |
| 40 | text_type = unicode |
| 41 | except NameError: |
| 42 | text_type = str |
| 43 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 44 | NUM_PKTS = 67 |
| 45 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 46 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 47 | class TestIPv6ND(VppTestCase): |
| 48 | def validate_ra(self, intf, rx, dst_ip=None): |
| 49 | if not dst_ip: |
| 50 | dst_ip = intf.remote_ip6 |
| 51 | |
| 52 | # unicasted packets must come to the unicast mac |
| 53 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 54 | |
| 55 | # and from the router's MAC |
| 56 | self.assertEqual(rx[Ether].src, intf.local_mac) |
| 57 | |
| 58 | # the rx'd RA should be addressed to the sender's source |
| 59 | self.assertTrue(rx.haslayer(ICMPv6ND_RA)) |
| 60 | self.assertEqual(in6_ptop(rx[IPv6].dst), |
| 61 | in6_ptop(dst_ip)) |
| 62 | |
| 63 | # and come from the router's link local |
| 64 | self.assertTrue(in6_islladdr(rx[IPv6].src)) |
| 65 | self.assertEqual(in6_ptop(rx[IPv6].src), |
| 66 | in6_ptop(mk_ll_addr(intf.local_mac))) |
| 67 | |
| 68 | def validate_na(self, intf, rx, dst_ip=None, tgt_ip=None): |
| 69 | if not dst_ip: |
| 70 | dst_ip = intf.remote_ip6 |
| 71 | if not tgt_ip: |
| 72 | dst_ip = intf.local_ip6 |
| 73 | |
| 74 | # unicasted packets must come to the unicast mac |
| 75 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 76 | |
| 77 | # and from the router's MAC |
| 78 | self.assertEqual(rx[Ether].src, intf.local_mac) |
| 79 | |
| 80 | # the rx'd NA should be addressed to the sender's source |
| 81 | self.assertTrue(rx.haslayer(ICMPv6ND_NA)) |
| 82 | self.assertEqual(in6_ptop(rx[IPv6].dst), |
| 83 | in6_ptop(dst_ip)) |
| 84 | |
| 85 | # and come from the target address |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 86 | self.assertEqual( |
| 87 | in6_ptop(rx[IPv6].src), in6_ptop(tgt_ip)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 88 | |
| 89 | # Dest link-layer options should have the router's MAC |
| 90 | dll = rx[ICMPv6NDOptDstLLAddr] |
| 91 | self.assertEqual(dll.lladdr, intf.local_mac) |
| 92 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 93 | def validate_ns(self, intf, rx, tgt_ip): |
| 94 | nsma = in6_getnsma(inet_pton(AF_INET6, tgt_ip)) |
| 95 | dst_ip = inet_ntop(AF_INET6, nsma) |
| 96 | |
| 97 | # NS is broadcast |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 98 | self.assertEqual(rx[Ether].dst, in6_getnsmac(nsma)) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 99 | |
| 100 | # and from the router's MAC |
| 101 | self.assertEqual(rx[Ether].src, intf.local_mac) |
| 102 | |
| 103 | # the rx'd NS should be addressed to an mcast address |
| 104 | # derived from the target address |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 105 | self.assertEqual( |
| 106 | in6_ptop(rx[IPv6].dst), in6_ptop(dst_ip)) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 107 | |
| 108 | # expect the tgt IP in the NS header |
| 109 | ns = rx[ICMPv6ND_NS] |
| 110 | self.assertEqual(in6_ptop(ns.tgt), in6_ptop(tgt_ip)) |
| 111 | |
| 112 | # packet is from the router's local address |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 113 | self.assertEqual( |
| 114 | in6_ptop(rx[IPv6].src), intf.local_ip6) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 115 | |
| 116 | # Src link-layer options should have the router's MAC |
| 117 | sll = rx[ICMPv6NDOptSrcLLAddr] |
| 118 | self.assertEqual(sll.lladdr, intf.local_mac) |
| 119 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 120 | def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None, |
| 121 | filter_out_fn=is_ipv6_misc): |
| 122 | intf.add_stream(pkts) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 123 | self.pg_enable_capture(self.pg_interfaces) |
| 124 | self.pg_start() |
| 125 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 126 | |
| 127 | self.assertEqual(len(rx), 1) |
| 128 | rx = rx[0] |
| 129 | self.validate_ra(intf, rx, dst_ip) |
| 130 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 131 | def send_and_expect_na(self, intf, pkts, remark, dst_ip=None, |
| 132 | tgt_ip=None, |
| 133 | filter_out_fn=is_ipv6_misc): |
| 134 | intf.add_stream(pkts) |
| 135 | self.pg_enable_capture(self.pg_interfaces) |
| 136 | self.pg_start() |
| 137 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 138 | |
| 139 | self.assertEqual(len(rx), 1) |
| 140 | rx = rx[0] |
| 141 | self.validate_na(intf, rx, dst_ip, tgt_ip) |
| 142 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 143 | def send_and_expect_ns(self, tx_intf, rx_intf, pkts, tgt_ip, |
| 144 | filter_out_fn=is_ipv6_misc): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 145 | self.vapi.cli("clear trace") |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 146 | tx_intf.add_stream(pkts) |
| 147 | self.pg_enable_capture(self.pg_interfaces) |
| 148 | self.pg_start() |
| 149 | rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 150 | |
| 151 | self.assertEqual(len(rx), 1) |
| 152 | rx = rx[0] |
| 153 | self.validate_ns(rx_intf, rx, tgt_ip) |
| 154 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 155 | def verify_ip(self, rx, smac, dmac, sip, dip): |
| 156 | ether = rx[Ether] |
| 157 | self.assertEqual(ether.dst, dmac) |
| 158 | self.assertEqual(ether.src, smac) |
| 159 | |
| 160 | ip = rx[IPv6] |
| 161 | self.assertEqual(ip.src, sip) |
| 162 | self.assertEqual(ip.dst, dip) |
| 163 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 164 | |
| 165 | class TestIPv6(TestIPv6ND): |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 166 | """ IPv6 Test Case """ |
| 167 | |
| 168 | @classmethod |
Andrew Yourtchenko | a3b7c55 | 2020-08-26 14:33:54 +0000 | [diff] [blame] | 169 | def force_solo(cls): |
| 170 | return True |
| 171 | |
| 172 | @classmethod |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 173 | def setUpClass(cls): |
| 174 | super(TestIPv6, cls).setUpClass() |
| 175 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 176 | @classmethod |
| 177 | def tearDownClass(cls): |
| 178 | super(TestIPv6, cls).tearDownClass() |
| 179 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 180 | def setUp(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 181 | """ |
| 182 | Perform test setup before test case. |
| 183 | |
| 184 | **Config:** |
| 185 | - create 3 pg interfaces |
| 186 | - untagged pg0 interface |
| 187 | - Dot1Q subinterface on pg1 |
| 188 | - Dot1AD subinterface on pg2 |
| 189 | - setup interfaces: |
| 190 | - put it into UP state |
| 191 | - set IPv6 addresses |
| 192 | - resolve neighbor address using NDP |
| 193 | - configure 200 fib entries |
| 194 | |
| 195 | :ivar list interfaces: pg interfaces and subinterfaces. |
| 196 | :ivar dict flows: IPv4 packet flows in test. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 197 | |
| 198 | *TODO:* Create AD sub interface |
| 199 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 200 | super(TestIPv6, self).setUp() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 201 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 202 | # create 3 pg interfaces |
| 203 | self.create_pg_interfaces(range(3)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 204 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 205 | # create 2 subinterfaces for p1 and pg2 |
| 206 | self.sub_interfaces = [ |
| 207 | VppDot1QSubint(self, self.pg1, 100), |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 208 | VppDot1QSubint(self, self.pg2, 200) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 209 | # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 210 | ] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 211 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 212 | # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. |
| 213 | self.flows = dict() |
| 214 | self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] |
| 215 | self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] |
| 216 | self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 217 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 218 | # packet sizes |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 219 | self.pg_if_packet_sizes = [64, 1500, 9020] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 220 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 221 | self.interfaces = list(self.pg_interfaces) |
| 222 | self.interfaces.extend(self.sub_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 223 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 224 | # setup all interfaces |
| 225 | for i in self.interfaces: |
| 226 | i.admin_up() |
| 227 | i.config_ip6() |
| 228 | i.resolve_ndp() |
| 229 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 230 | def tearDown(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 231 | """Run standard test teardown and log ``show ip6 neighbors``.""" |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 232 | for i in self.interfaces: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 233 | i.unconfig_ip6() |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 234 | i.admin_down() |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 235 | for i in self.sub_interfaces: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 236 | i.remove_vpp_config() |
| 237 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 238 | super(TestIPv6, self).tearDown() |
| 239 | if not self.vpp_dead: |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 240 | self.logger.info(self.vapi.cli("show ip6 neighbors")) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 241 | # info(self.vapi.cli("show ip6 fib")) # many entries |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 242 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 243 | def modify_packet(self, src_if, packet_size, pkt): |
| 244 | """Add load, set destination IP and extend packet to required packet |
| 245 | size for defined interface. |
| 246 | |
| 247 | :param VppInterface src_if: Interface to create packet for. |
| 248 | :param int packet_size: Required packet size. |
| 249 | :param Scapy pkt: Packet to be modified. |
| 250 | """ |
snaramre | 07a0f21 | 2019-10-11 21:28:56 +0000 | [diff] [blame] | 251 | dst_if_idx = int(packet_size / 10 % 2) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 252 | dst_if = self.flows[src_if][dst_if_idx] |
| 253 | info = self.create_packet_info(src_if, dst_if) |
| 254 | payload = self.info_to_payload(info) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 255 | p = pkt / Raw(payload) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 256 | p[IPv6].dst = dst_if.remote_ip6 |
| 257 | info.data = p.copy() |
| 258 | if isinstance(src_if, VppSubInterface): |
| 259 | p = src_if.add_dot1_layer(p) |
| 260 | self.extend_packet(p, packet_size) |
| 261 | |
| 262 | return p |
| 263 | |
| 264 | def create_stream(self, src_if): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 265 | """Create input packet stream for defined interface. |
| 266 | |
| 267 | :param VppInterface src_if: Interface to create packet stream for. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 268 | """ |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 269 | hdr_ext = 4 if isinstance(src_if, VppSubInterface) else 0 |
| 270 | pkt_tmpl = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / |
| 271 | IPv6(src=src_if.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 272 | inet6.UDP(sport=1234, dport=1234)) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 273 | |
| 274 | pkts = [self.modify_packet(src_if, i, pkt_tmpl) |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 275 | for i in moves.range(self.pg_if_packet_sizes[0], |
| 276 | self.pg_if_packet_sizes[1], 10)] |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 277 | pkts_b = [self.modify_packet(src_if, i, pkt_tmpl) |
Paul Vinciguerra | a6fe463 | 2018-11-25 11:21:50 -0800 | [diff] [blame] | 278 | for i in moves.range(self.pg_if_packet_sizes[1] + hdr_ext, |
| 279 | self.pg_if_packet_sizes[2] + hdr_ext, |
| 280 | 50)] |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 281 | pkts.extend(pkts_b) |
| 282 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 283 | return pkts |
| 284 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 285 | def verify_capture(self, dst_if, capture): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 286 | """Verify captured input packet stream for defined interface. |
| 287 | |
| 288 | :param VppInterface dst_if: Interface to verify captured packet stream |
| 289 | for. |
| 290 | :param list capture: Captured packet stream. |
| 291 | """ |
| 292 | self.logger.info("Verifying capture on interface %s" % dst_if.name) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 293 | last_info = dict() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 294 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 295 | last_info[i.sw_if_index] = None |
| 296 | is_sub_if = False |
| 297 | dst_sw_if_index = dst_if.sw_if_index |
| 298 | if hasattr(dst_if, 'parent'): |
| 299 | is_sub_if = True |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 300 | for packet in capture: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 301 | if is_sub_if: |
| 302 | # Check VLAN tags and Ethernet header |
| 303 | packet = dst_if.remove_dot1_layer(packet) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 304 | self.assertTrue(Dot1Q not in packet) |
| 305 | try: |
| 306 | ip = packet[IPv6] |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 307 | udp = packet[inet6.UDP] |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 308 | payload_info = self.payload_to_info(packet[Raw]) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 309 | packet_index = payload_info.index |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 310 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 311 | self.logger.debug( |
| 312 | "Got packet on port %s: src=%u (id=%u)" % |
| 313 | (dst_if.name, payload_info.src, packet_index)) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 314 | next_info = self.get_next_packet_info_for_interface2( |
| 315 | payload_info.src, dst_sw_if_index, |
| 316 | last_info[payload_info.src]) |
| 317 | last_info[payload_info.src] = next_info |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 318 | self.assertTrue(next_info is not None) |
| 319 | self.assertEqual(packet_index, next_info.index) |
| 320 | saved_packet = next_info.data |
| 321 | # Check standard fields |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 322 | self.assertEqual( |
| 323 | ip.src, saved_packet[IPv6].src) |
| 324 | self.assertEqual( |
| 325 | ip.dst, saved_packet[IPv6].dst) |
| 326 | self.assertEqual( |
| 327 | udp.sport, saved_packet[inet6.UDP].sport) |
| 328 | self.assertEqual( |
| 329 | udp.dport, saved_packet[inet6.UDP].dport) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 330 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 331 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 332 | raise |
| 333 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 334 | remaining_packet = self.get_next_packet_info_for_interface2( |
| 335 | i.sw_if_index, dst_sw_if_index, last_info[i.sw_if_index]) |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 336 | self.assertTrue(remaining_packet is None, |
| 337 | "Interface %s: Packet expected from interface %s " |
| 338 | "didn't arrive" % (dst_if.name, i.name)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 339 | |
Klement Sekera | e849865 | 2019-06-17 12:23:15 +0000 | [diff] [blame] | 340 | def test_next_header_anomaly(self): |
| 341 | """ IPv6 next header anomaly test |
| 342 | |
| 343 | Test scenario: |
| 344 | - ipv6 next header field = Fragment Header (44) |
| 345 | - next header is ICMPv6 Echo Request |
| 346 | - wait for reassembly |
| 347 | """ |
| 348 | pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) / |
| 349 | IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44) / |
| 350 | ICMPv6EchoRequest()) |
| 351 | |
| 352 | self.pg0.add_stream(pkt) |
| 353 | self.pg_start() |
| 354 | |
| 355 | # wait for reassembly |
| 356 | self.sleep(10) |
| 357 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 358 | def test_fib(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 359 | """ IPv6 FIB test |
| 360 | |
| 361 | Test scenario: |
| 362 | - Create IPv6 stream for pg0 interface |
| 363 | - Create IPv6 tagged streams for pg1's and pg2's subinterface. |
| 364 | - Send and verify received packets on each interface. |
| 365 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 366 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 367 | pkts = self.create_stream(self.pg0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 368 | self.pg0.add_stream(pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 369 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 370 | for i in self.sub_interfaces: |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 371 | pkts = self.create_stream(i) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 372 | i.parent.add_stream(pkts) |
| 373 | |
| 374 | self.pg_enable_capture(self.pg_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 375 | self.pg_start() |
| 376 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 377 | pkts = self.pg0.get_capture() |
| 378 | self.verify_capture(self.pg0, pkts) |
| 379 | |
| 380 | for i in self.sub_interfaces: |
| 381 | pkts = i.parent.get_capture() |
| 382 | self.verify_capture(i, pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 383 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 384 | def test_ns(self): |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 385 | """ IPv6 Neighbour Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 386 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 387 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 388 | - Send an NS Sourced from an address not covered by the link sub-net |
| 389 | - Send an NS to an mcast address the router has not joined |
| 390 | - Send NS for a target address the router does not onn. |
| 391 | """ |
| 392 | |
| 393 | # |
| 394 | # An NS from a non link source address |
| 395 | # |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 396 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 397 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 398 | |
| 399 | p = (Ether(dst=in6_getnsmac(nsma)) / |
| 400 | IPv6(dst=d, src="2002::2") / |
| 401 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 402 | ICMPv6NDOptSrcLLAddr( |
| 403 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 404 | pkts = [p] |
| 405 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 406 | self.send_and_assert_no_replies( |
| 407 | self.pg0, pkts, |
| 408 | "No response to NS source by address not on sub-net") |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 409 | |
| 410 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 411 | # An NS for sent to a solicited mcast group the router is |
| 412 | # not a member of FAILS |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 413 | # |
| 414 | if 0: |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 415 | nsma = in6_getnsma(inet_pton(AF_INET6, "fd::ffff")) |
| 416 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 417 | |
| 418 | p = (Ether(dst=in6_getnsmac(nsma)) / |
| 419 | IPv6(dst=d, src=self.pg0.remote_ip6) / |
| 420 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 421 | ICMPv6NDOptSrcLLAddr( |
| 422 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 423 | pkts = [p] |
| 424 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 425 | self.send_and_assert_no_replies( |
| 426 | self.pg0, pkts, |
| 427 | "No response to NS sent to unjoined mcast address") |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 428 | |
| 429 | # |
| 430 | # An NS whose target address is one the router does not own |
| 431 | # |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 432 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 433 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 434 | |
| 435 | p = (Ether(dst=in6_getnsmac(nsma)) / |
| 436 | IPv6(dst=d, src=self.pg0.remote_ip6) / |
| 437 | ICMPv6ND_NS(tgt="fd::ffff") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 438 | ICMPv6NDOptSrcLLAddr( |
| 439 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 440 | pkts = [p] |
| 441 | |
| 442 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 443 | "No response to NS for unknown target") |
| 444 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 445 | # |
| 446 | # A neighbor entry that has no associated FIB-entry |
| 447 | # |
| 448 | self.pg0.generate_remote_hosts(4) |
| 449 | nd_entry = VppNeighbor(self, |
| 450 | self.pg0.sw_if_index, |
| 451 | self.pg0.remote_hosts[2].mac, |
| 452 | self.pg0.remote_hosts[2].ip6, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 453 | is_no_fib_entry=1) |
| 454 | nd_entry.add_vpp_config() |
| 455 | |
| 456 | # |
| 457 | # check we have the neighbor, but no route |
| 458 | # |
| 459 | self.assertTrue(find_nbr(self, |
| 460 | self.pg0.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 461 | self.pg0._remote_hosts[2].ip6)) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 462 | self.assertFalse(find_route(self, |
| 463 | self.pg0._remote_hosts[2].ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 464 | 128)) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 465 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 466 | # |
| 467 | # send an NS from a link local address to the interface's global |
| 468 | # address |
| 469 | # |
| 470 | p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 471 | IPv6( |
| 472 | dst=d, src=self.pg0._remote_hosts[2].ip6_ll) / |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 473 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 474 | ICMPv6NDOptSrcLLAddr( |
| 475 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 476 | |
| 477 | self.send_and_expect_na(self.pg0, p, |
| 478 | "NS from link-local", |
| 479 | dst_ip=self.pg0._remote_hosts[2].ip6_ll, |
| 480 | tgt_ip=self.pg0.local_ip6) |
| 481 | |
| 482 | # |
| 483 | # we should have learned an ND entry for the peer's link-local |
| 484 | # but not inserted a route to it in the FIB |
| 485 | # |
| 486 | self.assertTrue(find_nbr(self, |
| 487 | self.pg0.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 488 | self.pg0._remote_hosts[2].ip6_ll)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 489 | self.assertFalse(find_route(self, |
| 490 | self.pg0._remote_hosts[2].ip6_ll, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 491 | 128)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 492 | |
| 493 | # |
| 494 | # An NS to the router's own Link-local |
| 495 | # |
| 496 | p = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 497 | IPv6( |
| 498 | dst=d, src=self.pg0._remote_hosts[3].ip6_ll) / |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 499 | ICMPv6ND_NS(tgt=self.pg0.local_ip6_ll) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 500 | ICMPv6NDOptSrcLLAddr( |
| 501 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 502 | |
| 503 | self.send_and_expect_na(self.pg0, p, |
| 504 | "NS to/from link-local", |
| 505 | dst_ip=self.pg0._remote_hosts[3].ip6_ll, |
| 506 | tgt_ip=self.pg0.local_ip6_ll) |
| 507 | |
| 508 | # |
| 509 | # we should have learned an ND entry for the peer's link-local |
| 510 | # but not inserted a route to it in the FIB |
| 511 | # |
| 512 | self.assertTrue(find_nbr(self, |
| 513 | self.pg0.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 514 | self.pg0._remote_hosts[3].ip6_ll)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 515 | self.assertFalse(find_route(self, |
| 516 | self.pg0._remote_hosts[3].ip6_ll, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 517 | 128)) |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 518 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 519 | def test_ns_duplicates(self): |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 520 | """ ND Duplicates""" |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 521 | |
| 522 | # |
| 523 | # Generate some hosts on the LAN |
| 524 | # |
| 525 | self.pg1.generate_remote_hosts(3) |
| 526 | |
| 527 | # |
| 528 | # Add host 1 on pg1 and pg2 |
| 529 | # |
| 530 | ns_pg1 = VppNeighbor(self, |
| 531 | self.pg1.sw_if_index, |
| 532 | self.pg1.remote_hosts[1].mac, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 533 | self.pg1.remote_hosts[1].ip6) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 534 | ns_pg1.add_vpp_config() |
| 535 | ns_pg2 = VppNeighbor(self, |
| 536 | self.pg2.sw_if_index, |
| 537 | self.pg2.remote_mac, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 538 | self.pg1.remote_hosts[1].ip6) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 539 | ns_pg2.add_vpp_config() |
| 540 | |
| 541 | # |
| 542 | # IP packet destined for pg1 remote host arrives on pg1 again. |
| 543 | # |
| 544 | p = (Ether(dst=self.pg0.local_mac, |
| 545 | src=self.pg0.remote_mac) / |
| 546 | IPv6(src=self.pg0.remote_ip6, |
| 547 | dst=self.pg1.remote_hosts[1].ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 548 | inet6.UDP(sport=1234, dport=1234) / |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 549 | Raw()) |
| 550 | |
| 551 | self.pg0.add_stream(p) |
| 552 | self.pg_enable_capture(self.pg_interfaces) |
| 553 | self.pg_start() |
| 554 | |
| 555 | rx1 = self.pg1.get_capture(1) |
| 556 | |
| 557 | self.verify_ip(rx1[0], |
| 558 | self.pg1.local_mac, |
| 559 | self.pg1.remote_hosts[1].mac, |
| 560 | self.pg0.remote_ip6, |
| 561 | self.pg1.remote_hosts[1].ip6) |
| 562 | |
| 563 | # |
| 564 | # remove the duplicate on pg1 |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 565 | # packet stream should generate NSs out of pg1 |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 566 | # |
| 567 | ns_pg1.remove_vpp_config() |
| 568 | |
| 569 | self.send_and_expect_ns(self.pg0, self.pg1, |
| 570 | p, self.pg1.remote_hosts[1].ip6) |
| 571 | |
| 572 | # |
| 573 | # Add it back |
| 574 | # |
| 575 | ns_pg1.add_vpp_config() |
| 576 | |
| 577 | self.pg0.add_stream(p) |
| 578 | self.pg_enable_capture(self.pg_interfaces) |
| 579 | self.pg_start() |
| 580 | |
| 581 | rx1 = self.pg1.get_capture(1) |
| 582 | |
| 583 | self.verify_ip(rx1[0], |
| 584 | self.pg1.local_mac, |
| 585 | self.pg1.remote_hosts[1].mac, |
| 586 | self.pg0.remote_ip6, |
| 587 | self.pg1.remote_hosts[1].ip6) |
| 588 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 589 | def validate_ra(self, intf, rx, dst_ip=None, src_ip=None, |
| 590 | mtu=9000, pi_opt=None): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 591 | if not dst_ip: |
| 592 | dst_ip = intf.remote_ip6 |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 593 | if not src_ip: |
| 594 | src_ip = mk_ll_addr(intf.local_mac) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 595 | |
Neale Ranns | 5737d88 | 2017-02-03 06:14:49 -0800 | [diff] [blame] | 596 | # unicasted packets must come to the unicast mac |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 597 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 598 | |
| 599 | # and from the router's MAC |
| 600 | self.assertEqual(rx[Ether].src, intf.local_mac) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 601 | |
| 602 | # the rx'd RA should be addressed to the sender's source |
| 603 | self.assertTrue(rx.haslayer(ICMPv6ND_RA)) |
| 604 | self.assertEqual(in6_ptop(rx[IPv6].dst), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 605 | in6_ptop(dst_ip)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 606 | |
| 607 | # and come from the router's link local |
| 608 | self.assertTrue(in6_islladdr(rx[IPv6].src)) |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 609 | self.assertEqual(in6_ptop(rx[IPv6].src), in6_ptop(src_ip)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 610 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 611 | # it should contain the links MTU |
| 612 | ra = rx[ICMPv6ND_RA] |
| 613 | self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu) |
| 614 | |
| 615 | # it should contain the source's link layer address option |
| 616 | sll = ra[ICMPv6NDOptSrcLLAddr] |
| 617 | self.assertEqual(sll.lladdr, intf.local_mac) |
| 618 | |
| 619 | if not pi_opt: |
| 620 | # the RA should not contain prefix information |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 621 | self.assertFalse(ra.haslayer( |
| 622 | ICMPv6NDOptPrefixInfo)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 623 | else: |
| 624 | raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1) |
| 625 | |
| 626 | # the options are nested in the scapy packet in way that i cannot |
| 627 | # decipher how to decode. this 1st layer of option always returns |
| 628 | # nested classes, so a direct obj1=obj2 comparison always fails. |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 629 | # however, the getlayer(.., 2) does give one instance. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 630 | # so we cheat here and construct a new opt instance for comparison |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 631 | rd = ICMPv6NDOptPrefixInfo( |
| 632 | prefixlen=raos.prefixlen, |
| 633 | prefix=raos.prefix, |
| 634 | L=raos.L, |
| 635 | A=raos.A) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 636 | if type(pi_opt) is list: |
| 637 | for ii in range(len(pi_opt)): |
| 638 | self.assertEqual(pi_opt[ii], rd) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 639 | rd = rx.getlayer( |
| 640 | ICMPv6NDOptPrefixInfo, ii + 2) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 641 | else: |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 642 | self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s' |
| 643 | % (pi_opt.show(dump=True), |
| 644 | raos.show(dump=True))) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 645 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 646 | def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None, |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 647 | filter_out_fn=is_ipv6_misc, |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 648 | opt=None, |
| 649 | src_ip=None): |
| 650 | self.vapi.cli("clear trace") |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 651 | intf.add_stream(pkts) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 652 | self.pg_enable_capture(self.pg_interfaces) |
| 653 | self.pg_start() |
| 654 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 655 | |
| 656 | self.assertEqual(len(rx), 1) |
| 657 | rx = rx[0] |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 658 | 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] | 659 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 660 | def test_rs(self): |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 661 | """ IPv6 Router Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 662 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 663 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 664 | """ |
| 665 | |
| 666 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 667 | # Before we begin change the IPv6 RA responses to use the unicast |
| 668 | # address - that way we will not confuse them with the periodic |
| 669 | # RAs which go to the mcast address |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 670 | # Sit and wait for the first periodic RA. |
| 671 | # |
| 672 | # TODO |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 673 | # |
| 674 | self.pg0.ip6_ra_config(send_unicast=1) |
| 675 | |
| 676 | # |
| 677 | # An RS from a link source address |
| 678 | # - expect an RA in return |
| 679 | # |
| 680 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 681 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 682 | ICMPv6ND_RS()) |
| 683 | pkts = [p] |
| 684 | self.send_and_expect_ra(self.pg0, pkts, "Genuine RS") |
| 685 | |
| 686 | # |
| 687 | # For the next RS sent the RA should be rate limited |
| 688 | # |
| 689 | self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited") |
| 690 | |
| 691 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 692 | # When we reconfigure the IPv6 RA config, |
| 693 | # we reset the RA rate limiting, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 694 | # so we need to do this before each test below so as not to drop |
| 695 | # packets for rate limiting reasons. Test this works here. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 696 | # |
| 697 | self.pg0.ip6_ra_config(send_unicast=1) |
| 698 | self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS") |
| 699 | |
| 700 | # |
| 701 | # An RS sent from a non-link local source |
| 702 | # |
| 703 | self.pg0.ip6_ra_config(send_unicast=1) |
| 704 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 705 | IPv6(dst=self.pg0.local_ip6, |
| 706 | src="2002::ffff") / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 707 | ICMPv6ND_RS()) |
| 708 | pkts = [p] |
| 709 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 710 | "RS from non-link source") |
| 711 | |
| 712 | # |
| 713 | # Source an RS from a link local address |
| 714 | # |
| 715 | self.pg0.ip6_ra_config(send_unicast=1) |
| 716 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 717 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 718 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 719 | ICMPv6ND_RS()) |
| 720 | pkts = [p] |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 721 | self.send_and_expect_ra(self.pg0, pkts, |
| 722 | "RS sourced from link-local", |
| 723 | dst_ip=ll) |
| 724 | |
| 725 | # |
| 726 | # Send the RS multicast |
| 727 | # |
| 728 | self.pg0.ip6_ra_config(send_unicast=1) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 729 | dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2")) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 730 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 731 | p = (Ether(dst=dmac, src=self.pg0.remote_mac) / |
| 732 | IPv6(dst="ff02::2", src=ll) / |
| 733 | ICMPv6ND_RS()) |
| 734 | pkts = [p] |
| 735 | self.send_and_expect_ra(self.pg0, pkts, |
| 736 | "RS sourced from link-local", |
| 737 | dst_ip=ll) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 738 | |
| 739 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 740 | # Source from the unspecified address ::. This happens when the RS |
| 741 | # is sent before the host has a configured address/sub-net, |
| 742 | # i.e. auto-config. Since the sender has no IP address, the reply |
| 743 | # comes back mcast - so the capture needs to not filter this. |
| 744 | # If we happen to pick up the periodic RA at this point then so be it, |
| 745 | # it's not an error. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 746 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 747 | self.pg0.ip6_ra_config(send_unicast=1, suppress=1) |
| 748 | p = (Ether(dst=dmac, src=self.pg0.remote_mac) / |
| 749 | IPv6(dst="ff02::2", src="::") / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 750 | ICMPv6ND_RS()) |
| 751 | pkts = [p] |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 752 | self.send_and_expect_ra(self.pg0, pkts, |
| 753 | "RS sourced from unspecified", |
| 754 | dst_ip="ff02::1", |
| 755 | filter_out_fn=None) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 756 | |
| 757 | # |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 758 | # Configure The RA to announce the links prefix |
| 759 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 760 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 761 | self.pg0.local_ip6_prefix_len)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 762 | |
| 763 | # |
| 764 | # RAs should now contain the prefix information option |
| 765 | # |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 766 | opt = ICMPv6NDOptPrefixInfo( |
| 767 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 768 | prefix=self.pg0.local_ip6, |
| 769 | L=1, |
| 770 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 771 | |
| 772 | self.pg0.ip6_ra_config(send_unicast=1) |
| 773 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 774 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 775 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 776 | ICMPv6ND_RS()) |
| 777 | self.send_and_expect_ra(self.pg0, p, |
| 778 | "RA with prefix-info", |
| 779 | dst_ip=ll, |
| 780 | opt=opt) |
| 781 | |
| 782 | # |
| 783 | # Change the prefix info to not off-link |
| 784 | # L-flag is clear |
| 785 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 786 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 787 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 788 | off_link=1) |
| 789 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 790 | opt = ICMPv6NDOptPrefixInfo( |
| 791 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 792 | prefix=self.pg0.local_ip6, |
| 793 | L=0, |
| 794 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 795 | |
| 796 | self.pg0.ip6_ra_config(send_unicast=1) |
| 797 | self.send_and_expect_ra(self.pg0, p, |
| 798 | "RA with Prefix info with L-flag=0", |
| 799 | dst_ip=ll, |
| 800 | opt=opt) |
| 801 | |
| 802 | # |
| 803 | # Change the prefix info to not off-link, no-autoconfig |
| 804 | # L and A flag are clear in the advert |
| 805 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 806 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 807 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 808 | off_link=1, |
| 809 | no_autoconfig=1) |
| 810 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 811 | opt = ICMPv6NDOptPrefixInfo( |
| 812 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 813 | prefix=self.pg0.local_ip6, |
| 814 | L=0, |
| 815 | A=0) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 816 | |
| 817 | self.pg0.ip6_ra_config(send_unicast=1) |
| 818 | self.send_and_expect_ra(self.pg0, p, |
| 819 | "RA with Prefix info with A & L-flag=0", |
| 820 | dst_ip=ll, |
| 821 | opt=opt) |
| 822 | |
| 823 | # |
| 824 | # Change the flag settings back to the defaults |
| 825 | # L and A flag are set in the advert |
| 826 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 827 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 828 | self.pg0.local_ip6_prefix_len)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 829 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 830 | opt = ICMPv6NDOptPrefixInfo( |
| 831 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 832 | prefix=self.pg0.local_ip6, |
| 833 | L=1, |
| 834 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 835 | |
| 836 | self.pg0.ip6_ra_config(send_unicast=1) |
| 837 | self.send_and_expect_ra(self.pg0, p, |
| 838 | "RA with Prefix info", |
| 839 | dst_ip=ll, |
| 840 | opt=opt) |
| 841 | |
| 842 | # |
| 843 | # Change the prefix info to not off-link, no-autoconfig |
| 844 | # L and A flag are clear in the advert |
| 845 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 846 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 847 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 848 | off_link=1, |
| 849 | no_autoconfig=1) |
| 850 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 851 | opt = ICMPv6NDOptPrefixInfo( |
| 852 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 853 | prefix=self.pg0.local_ip6, |
| 854 | L=0, |
| 855 | A=0) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 856 | |
| 857 | self.pg0.ip6_ra_config(send_unicast=1) |
| 858 | self.send_and_expect_ra(self.pg0, p, |
| 859 | "RA with Prefix info with A & L-flag=0", |
| 860 | dst_ip=ll, |
| 861 | opt=opt) |
| 862 | |
| 863 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 864 | # Use the reset to defaults option to revert to defaults |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 865 | # L and A flag are clear in the advert |
| 866 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 867 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 868 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 869 | use_default=1) |
| 870 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 871 | opt = ICMPv6NDOptPrefixInfo( |
| 872 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 873 | prefix=self.pg0.local_ip6, |
| 874 | L=1, |
| 875 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 876 | |
| 877 | self.pg0.ip6_ra_config(send_unicast=1) |
| 878 | self.send_and_expect_ra(self.pg0, p, |
| 879 | "RA with Prefix reverted to defaults", |
| 880 | dst_ip=ll, |
| 881 | opt=opt) |
| 882 | |
| 883 | # |
| 884 | # Advertise Another prefix. With no L-flag/A-flag |
| 885 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 886 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6, |
| 887 | self.pg1.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 888 | off_link=1, |
| 889 | no_autoconfig=1) |
| 890 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 891 | opt = [ICMPv6NDOptPrefixInfo( |
| 892 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 893 | prefix=self.pg0.local_ip6, |
| 894 | L=1, |
| 895 | A=1), |
| 896 | ICMPv6NDOptPrefixInfo( |
| 897 | prefixlen=self.pg1.local_ip6_prefix_len, |
| 898 | prefix=self.pg1.local_ip6, |
| 899 | L=0, |
| 900 | A=0)] |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 901 | |
| 902 | self.pg0.ip6_ra_config(send_unicast=1) |
| 903 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 904 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 905 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 906 | ICMPv6ND_RS()) |
| 907 | self.send_and_expect_ra(self.pg0, p, |
| 908 | "RA with multiple Prefix infos", |
| 909 | dst_ip=ll, |
| 910 | opt=opt) |
| 911 | |
| 912 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 913 | # Remove the first prefix-info - expect the second is still in the |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 914 | # advert |
| 915 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 916 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 917 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 918 | is_no=1) |
| 919 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 920 | opt = ICMPv6NDOptPrefixInfo( |
| 921 | prefixlen=self.pg1.local_ip6_prefix_len, |
| 922 | prefix=self.pg1.local_ip6, |
| 923 | L=0, |
| 924 | A=0) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 925 | |
| 926 | self.pg0.ip6_ra_config(send_unicast=1) |
| 927 | self.send_and_expect_ra(self.pg0, p, |
| 928 | "RA with Prefix reverted to defaults", |
| 929 | dst_ip=ll, |
| 930 | opt=opt) |
| 931 | |
| 932 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 933 | # Remove the second prefix-info - expect no prefix-info in the adverts |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 934 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame] | 935 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6, |
| 936 | self.pg1.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 937 | is_no=1) |
| 938 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 939 | # |
| 940 | # change the link's link local, so we know that works too. |
| 941 | # |
| 942 | self.vapi.sw_interface_ip6_set_link_local_address( |
| 943 | sw_if_index=self.pg0.sw_if_index, |
| 944 | ip="fe80::88") |
| 945 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 946 | self.pg0.ip6_ra_config(send_unicast=1) |
| 947 | self.send_and_expect_ra(self.pg0, p, |
| 948 | "RA with Prefix reverted to defaults", |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 949 | dst_ip=ll, |
| 950 | src_ip="fe80::88") |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 951 | |
| 952 | # |
Neale Ranns | 5737d88 | 2017-02-03 06:14:49 -0800 | [diff] [blame] | 953 | # Reset the periodic advertisements back to default values |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 954 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 955 | self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 956 | |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 957 | def test_mld(self): |
| 958 | """ MLD Report """ |
| 959 | # |
| 960 | # test one MLD is sent after applying an IPv6 Address on an interface |
| 961 | # |
| 962 | self.pg_enable_capture(self.pg_interfaces) |
| 963 | self.pg_start() |
| 964 | |
| 965 | subitf = VppDot1QSubint(self, self.pg1, 99) |
| 966 | |
| 967 | subitf.admin_up() |
| 968 | subitf.config_ip6() |
| 969 | |
Neale Ranns | 03c254e | 2020-03-17 14:25:10 +0000 | [diff] [blame] | 970 | rxs = self.pg1._get_capture(timeout=4, filter_out_fn=None) |
Neale Ranns | f267d11 | 2020-02-07 09:45:07 +0000 | [diff] [blame] | 971 | |
| 972 | # |
| 973 | # hunt for the MLD on vlan 99 |
| 974 | # |
| 975 | for rx in rxs: |
| 976 | # make sure ipv6 packets with hop by hop options have |
| 977 | # correct checksums |
| 978 | self.assert_packet_checksums_valid(rx) |
| 979 | if rx.haslayer(IPv6ExtHdrHopByHop) and \ |
| 980 | rx.haslayer(Dot1Q) and \ |
| 981 | rx[Dot1Q].vlan == 99: |
| 982 | mld = rx[ICMPv6MLReport2] |
| 983 | |
| 984 | self.assertEqual(mld.records_number, 4) |
| 985 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 986 | |
Christian Hopps | f5d38e0 | 2020-05-04 10:28:03 -0400 | [diff] [blame] | 987 | class TestIPv6RouteLookup(VppTestCase): |
| 988 | """ IPv6 Route Lookup Test Case """ |
| 989 | routes = [] |
| 990 | |
| 991 | def route_lookup(self, prefix, exact): |
| 992 | return self.vapi.api(self.vapi.papi.ip_route_lookup, |
| 993 | { |
| 994 | 'table_id': 0, |
| 995 | 'exact': exact, |
| 996 | 'prefix': prefix, |
| 997 | }) |
| 998 | |
| 999 | @classmethod |
| 1000 | def setUpClass(cls): |
| 1001 | super(TestIPv6RouteLookup, cls).setUpClass() |
| 1002 | |
| 1003 | @classmethod |
| 1004 | def tearDownClass(cls): |
| 1005 | super(TestIPv6RouteLookup, cls).tearDownClass() |
| 1006 | |
| 1007 | def setUp(self): |
| 1008 | super(TestIPv6RouteLookup, self).setUp() |
| 1009 | |
| 1010 | drop_nh = VppRoutePath("::1", 0xffffffff, |
| 1011 | type=FibPathType.FIB_PATH_TYPE_DROP) |
| 1012 | |
| 1013 | # Add 3 routes |
| 1014 | r = VppIpRoute(self, "2001:1111::", 32, [drop_nh]) |
| 1015 | r.add_vpp_config() |
| 1016 | self.routes.append(r) |
| 1017 | |
| 1018 | r = VppIpRoute(self, "2001:1111:2222::", 48, [drop_nh]) |
| 1019 | r.add_vpp_config() |
| 1020 | self.routes.append(r) |
| 1021 | |
| 1022 | r = VppIpRoute(self, "2001:1111:2222::1", 128, [drop_nh]) |
| 1023 | r.add_vpp_config() |
| 1024 | self.routes.append(r) |
| 1025 | |
| 1026 | def tearDown(self): |
| 1027 | # Remove the routes we added |
| 1028 | for r in self.routes: |
| 1029 | r.remove_vpp_config() |
| 1030 | |
| 1031 | super(TestIPv6RouteLookup, self).tearDown() |
| 1032 | |
| 1033 | def test_exact_match(self): |
| 1034 | # Verify we find the host route |
| 1035 | prefix = "2001:1111:2222::1/128" |
| 1036 | result = self.route_lookup(prefix, True) |
| 1037 | assert (prefix == str(result.route.prefix)) |
| 1038 | |
| 1039 | # Verify we find a middle prefix route |
| 1040 | prefix = "2001:1111:2222::/48" |
| 1041 | result = self.route_lookup(prefix, True) |
| 1042 | assert (prefix == str(result.route.prefix)) |
| 1043 | |
| 1044 | # Verify we do not find an available LPM. |
| 1045 | with self.vapi.assert_negative_api_retval(): |
| 1046 | self.route_lookup("2001::2/128", True) |
| 1047 | |
| 1048 | def test_longest_prefix_match(self): |
| 1049 | # verify we find lpm |
| 1050 | lpm_prefix = "2001:1111:2222::/48" |
| 1051 | result = self.route_lookup("2001:1111:2222::2/128", False) |
| 1052 | assert (lpm_prefix == str(result.route.prefix)) |
| 1053 | |
| 1054 | # Verify we find the exact when not requested |
| 1055 | result = self.route_lookup(lpm_prefix, False) |
| 1056 | assert (lpm_prefix == str(result.route.prefix)) |
| 1057 | |
| 1058 | # Can't seem to delete the default route so no negative LPM test. |
| 1059 | |
| 1060 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1061 | class TestIPv6IfAddrRoute(VppTestCase): |
| 1062 | """ IPv6 Interface Addr Route Test Case """ |
| 1063 | |
| 1064 | @classmethod |
| 1065 | def setUpClass(cls): |
| 1066 | super(TestIPv6IfAddrRoute, cls).setUpClass() |
| 1067 | |
| 1068 | @classmethod |
| 1069 | def tearDownClass(cls): |
| 1070 | super(TestIPv6IfAddrRoute, cls).tearDownClass() |
| 1071 | |
| 1072 | def setUp(self): |
| 1073 | super(TestIPv6IfAddrRoute, self).setUp() |
| 1074 | |
| 1075 | # create 1 pg interface |
| 1076 | self.create_pg_interfaces(range(1)) |
| 1077 | |
| 1078 | for i in self.pg_interfaces: |
| 1079 | i.admin_up() |
| 1080 | i.config_ip6() |
| 1081 | i.resolve_ndp() |
| 1082 | |
| 1083 | def tearDown(self): |
| 1084 | super(TestIPv6IfAddrRoute, self).tearDown() |
| 1085 | for i in self.pg_interfaces: |
| 1086 | i.unconfig_ip6() |
| 1087 | i.admin_down() |
| 1088 | |
| 1089 | def test_ipv6_ifaddrs_same_prefix(self): |
| 1090 | """ IPv6 Interface Addresses Same Prefix test |
| 1091 | |
| 1092 | Test scenario: |
| 1093 | |
| 1094 | - Verify no route in FIB for prefix 2001:10::/64 |
| 1095 | - Configure IPv4 address 2001:10::10/64 on an interface |
| 1096 | - Verify route in FIB for prefix 2001:10::/64 |
| 1097 | - Configure IPv4 address 2001:10::20/64 on an interface |
| 1098 | - Delete 2001:10::10/64 from interface |
| 1099 | - Verify route in FIB for prefix 2001:10::/64 |
| 1100 | - Delete 2001:10::20/64 from interface |
| 1101 | - Verify no route in FIB for prefix 2001:10::/64 |
| 1102 | """ |
| 1103 | |
| 1104 | addr1 = "2001:10::10" |
| 1105 | addr2 = "2001:10::20" |
| 1106 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1107 | if_addr1 = VppIpInterfaceAddress(self, self.pg0, addr1, 64) |
| 1108 | if_addr2 = VppIpInterfaceAddress(self, self.pg0, addr2, 64) |
| 1109 | self.assertFalse(if_addr1.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1110 | self.assertFalse(find_route(self, addr1, 128)) |
| 1111 | self.assertFalse(find_route(self, addr2, 128)) |
| 1112 | |
| 1113 | # configure first address, verify route present |
| 1114 | if_addr1.add_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1115 | self.assertTrue(if_addr1.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1116 | self.assertTrue(find_route(self, addr1, 128)) |
| 1117 | self.assertFalse(find_route(self, addr2, 128)) |
| 1118 | |
| 1119 | # configure second address, delete first, verify route not removed |
| 1120 | if_addr2.add_vpp_config() |
| 1121 | if_addr1.remove_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1122 | self.assertFalse(if_addr1.query_vpp_config()) |
| 1123 | self.assertTrue(if_addr2.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1124 | self.assertFalse(find_route(self, addr1, 128)) |
| 1125 | self.assertTrue(find_route(self, addr2, 128)) |
| 1126 | |
| 1127 | # delete second address, verify route removed |
| 1128 | if_addr2.remove_vpp_config() |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1129 | self.assertFalse(if_addr1.query_vpp_config()) |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1130 | self.assertFalse(find_route(self, addr1, 128)) |
| 1131 | self.assertFalse(find_route(self, addr2, 128)) |
| 1132 | |
yedg | dbd366b | 2020-05-14 10:51:53 +0800 | [diff] [blame] | 1133 | def test_ipv6_ifaddr_del(self): |
| 1134 | """ Delete an interface address that does not exist """ |
| 1135 | |
| 1136 | loopbacks = self.create_loopback_interfaces(1) |
| 1137 | lo = self.lo_interfaces[0] |
| 1138 | |
| 1139 | lo.config_ip6() |
| 1140 | lo.admin_up() |
| 1141 | |
| 1142 | # |
| 1143 | # try and remove pg0's subnet from lo |
| 1144 | # |
| 1145 | with self.vapi.assert_negative_api_retval(): |
| 1146 | self.vapi.sw_interface_add_del_address( |
| 1147 | sw_if_index=lo.sw_if_index, |
| 1148 | prefix=self.pg0.local_ip6_prefix, |
| 1149 | is_add=0) |
| 1150 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 1151 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1152 | class TestICMPv6Echo(VppTestCase): |
| 1153 | """ ICMPv6 Echo Test Case """ |
| 1154 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1155 | @classmethod |
| 1156 | def setUpClass(cls): |
| 1157 | super(TestICMPv6Echo, cls).setUpClass() |
| 1158 | |
| 1159 | @classmethod |
| 1160 | def tearDownClass(cls): |
| 1161 | super(TestICMPv6Echo, cls).tearDownClass() |
| 1162 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1163 | def setUp(self): |
| 1164 | super(TestICMPv6Echo, self).setUp() |
| 1165 | |
| 1166 | # create 1 pg interface |
| 1167 | self.create_pg_interfaces(range(1)) |
| 1168 | |
| 1169 | for i in self.pg_interfaces: |
| 1170 | i.admin_up() |
| 1171 | i.config_ip6() |
| 1172 | i.resolve_ndp() |
| 1173 | |
| 1174 | def tearDown(self): |
| 1175 | super(TestICMPv6Echo, self).tearDown() |
| 1176 | for i in self.pg_interfaces: |
| 1177 | i.unconfig_ip6() |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1178 | i.admin_down() |
| 1179 | |
| 1180 | def test_icmpv6_echo(self): |
| 1181 | """ VPP replies to ICMPv6 Echo Request |
| 1182 | |
| 1183 | Test scenario: |
| 1184 | |
| 1185 | - Receive ICMPv6 Echo Request message on pg0 interface. |
| 1186 | - Check outgoing ICMPv6 Echo Reply message on pg0 interface. |
| 1187 | """ |
| 1188 | |
| 1189 | icmpv6_id = 0xb |
| 1190 | icmpv6_seq = 5 |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 1191 | icmpv6_data = b'\x0a' * 18 |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1192 | p_echo_request = (Ether(src=self.pg0.remote_mac, |
| 1193 | dst=self.pg0.local_mac) / |
| 1194 | IPv6(src=self.pg0.remote_ip6, |
| 1195 | dst=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1196 | ICMPv6EchoRequest( |
| 1197 | id=icmpv6_id, |
| 1198 | seq=icmpv6_seq, |
| 1199 | data=icmpv6_data)) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1200 | |
| 1201 | self.pg0.add_stream(p_echo_request) |
| 1202 | self.pg_enable_capture(self.pg_interfaces) |
| 1203 | self.pg_start() |
| 1204 | |
| 1205 | rx = self.pg0.get_capture(1) |
| 1206 | rx = rx[0] |
| 1207 | ether = rx[Ether] |
| 1208 | ipv6 = rx[IPv6] |
| 1209 | icmpv6 = rx[ICMPv6EchoReply] |
| 1210 | |
| 1211 | self.assertEqual(ether.src, self.pg0.local_mac) |
| 1212 | self.assertEqual(ether.dst, self.pg0.remote_mac) |
| 1213 | |
| 1214 | self.assertEqual(ipv6.src, self.pg0.local_ip6) |
| 1215 | self.assertEqual(ipv6.dst, self.pg0.remote_ip6) |
| 1216 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1217 | self.assertEqual( |
| 1218 | icmp6types[icmpv6.type], "Echo Reply") |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1219 | self.assertEqual(icmpv6.id, icmpv6_id) |
| 1220 | self.assertEqual(icmpv6.seq, icmpv6_seq) |
| 1221 | self.assertEqual(icmpv6.data, icmpv6_data) |
| 1222 | |
| 1223 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1224 | class TestIPv6RD(TestIPv6ND): |
| 1225 | """ IPv6 Router Discovery Test Case """ |
| 1226 | |
| 1227 | @classmethod |
| 1228 | def setUpClass(cls): |
| 1229 | super(TestIPv6RD, cls).setUpClass() |
| 1230 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1231 | @classmethod |
| 1232 | def tearDownClass(cls): |
| 1233 | super(TestIPv6RD, cls).tearDownClass() |
| 1234 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1235 | def setUp(self): |
| 1236 | super(TestIPv6RD, self).setUp() |
| 1237 | |
| 1238 | # create 2 pg interfaces |
| 1239 | self.create_pg_interfaces(range(2)) |
| 1240 | |
| 1241 | self.interfaces = list(self.pg_interfaces) |
| 1242 | |
| 1243 | # setup all interfaces |
| 1244 | for i in self.interfaces: |
| 1245 | i.admin_up() |
| 1246 | i.config_ip6() |
| 1247 | |
| 1248 | def tearDown(self): |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 1249 | for i in self.interfaces: |
| 1250 | i.unconfig_ip6() |
| 1251 | i.admin_down() |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1252 | super(TestIPv6RD, self).tearDown() |
| 1253 | |
| 1254 | def test_rd_send_router_solicitation(self): |
| 1255 | """ Verify router solicitation packets """ |
| 1256 | |
| 1257 | count = 2 |
| 1258 | self.pg_enable_capture(self.pg_interfaces) |
| 1259 | self.pg_start() |
| 1260 | self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index, |
| 1261 | mrc=count) |
| 1262 | rx_list = self.pg1.get_capture(count, timeout=3) |
| 1263 | self.assertEqual(len(rx_list), count) |
| 1264 | for packet in rx_list: |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1265 | self.assertEqual(packet.haslayer(IPv6), 1) |
| 1266 | self.assertEqual(packet[IPv6].haslayer( |
| 1267 | ICMPv6ND_RS), 1) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1268 | dst = ip6_normalize(packet[IPv6].dst) |
| 1269 | dst2 = ip6_normalize("ff02::2") |
| 1270 | self.assert_equal(dst, dst2) |
| 1271 | src = ip6_normalize(packet[IPv6].src) |
| 1272 | src2 = ip6_normalize(self.pg1.local_ip6_ll) |
| 1273 | self.assert_equal(src, src2) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1274 | self.assertTrue( |
| 1275 | bool(packet[ICMPv6ND_RS].haslayer( |
| 1276 | ICMPv6NDOptSrcLLAddr))) |
| 1277 | self.assert_equal( |
| 1278 | packet[ICMPv6NDOptSrcLLAddr].lladdr, |
| 1279 | self.pg1.local_mac) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1280 | |
| 1281 | def verify_prefix_info(self, reported_prefix, prefix_option): |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1282 | prefix = IPv6Network( |
Paul Vinciguerra | 1e18eb2 | 2018-11-25 16:09:26 -0800 | [diff] [blame] | 1283 | text_type(prefix_option.getfieldval("prefix") + |
| 1284 | "/" + |
| 1285 | text_type(prefix_option.getfieldval("prefixlen"))), |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1286 | strict=False) |
| 1287 | self.assert_equal(reported_prefix.prefix.network_address, |
| 1288 | prefix.network_address) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1289 | L = prefix_option.getfieldval("L") |
| 1290 | A = prefix_option.getfieldval("A") |
| 1291 | option_flags = (L << 7) | (A << 6) |
| 1292 | self.assert_equal(reported_prefix.flags, option_flags) |
| 1293 | self.assert_equal(reported_prefix.valid_time, |
| 1294 | prefix_option.getfieldval("validlifetime")) |
| 1295 | self.assert_equal(reported_prefix.preferred_time, |
| 1296 | prefix_option.getfieldval("preferredlifetime")) |
| 1297 | |
| 1298 | def test_rd_receive_router_advertisement(self): |
| 1299 | """ Verify events triggered by received RA packets """ |
| 1300 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1301 | self.vapi.want_ip6_ra_events(enable=1) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1302 | |
| 1303 | prefix_info_1 = ICMPv6NDOptPrefixInfo( |
| 1304 | prefix="1::2", |
| 1305 | prefixlen=50, |
| 1306 | validlifetime=200, |
| 1307 | preferredlifetime=500, |
| 1308 | L=1, |
| 1309 | A=1, |
| 1310 | ) |
| 1311 | |
| 1312 | prefix_info_2 = ICMPv6NDOptPrefixInfo( |
| 1313 | prefix="7::4", |
| 1314 | prefixlen=20, |
| 1315 | validlifetime=70, |
| 1316 | preferredlifetime=1000, |
| 1317 | L=1, |
| 1318 | A=0, |
| 1319 | ) |
| 1320 | |
| 1321 | p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 1322 | IPv6(dst=self.pg1.local_ip6_ll, |
| 1323 | src=mk_ll_addr(self.pg1.remote_mac)) / |
| 1324 | ICMPv6ND_RA() / |
| 1325 | prefix_info_1 / |
| 1326 | prefix_info_2) |
| 1327 | self.pg1.add_stream([p]) |
| 1328 | self.pg_start() |
| 1329 | |
| 1330 | ev = self.vapi.wait_for_event(10, "ip6_ra_event") |
| 1331 | |
| 1332 | self.assert_equal(ev.current_hop_limit, 0) |
| 1333 | self.assert_equal(ev.flags, 8) |
| 1334 | self.assert_equal(ev.router_lifetime_in_sec, 1800) |
| 1335 | self.assert_equal(ev.neighbor_reachable_time_in_msec, 0) |
| 1336 | self.assert_equal( |
| 1337 | ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0) |
| 1338 | |
| 1339 | self.assert_equal(ev.n_prefixes, 2) |
| 1340 | |
| 1341 | self.verify_prefix_info(ev.prefixes[0], prefix_info_1) |
| 1342 | self.verify_prefix_info(ev.prefixes[1], prefix_info_2) |
| 1343 | |
| 1344 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1345 | class TestIPv6RDControlPlane(TestIPv6ND): |
| 1346 | """ IPv6 Router Discovery Control Plane Test Case """ |
| 1347 | |
| 1348 | @classmethod |
| 1349 | def setUpClass(cls): |
| 1350 | super(TestIPv6RDControlPlane, cls).setUpClass() |
| 1351 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1352 | @classmethod |
| 1353 | def tearDownClass(cls): |
| 1354 | super(TestIPv6RDControlPlane, cls).tearDownClass() |
| 1355 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1356 | def setUp(self): |
| 1357 | super(TestIPv6RDControlPlane, self).setUp() |
| 1358 | |
| 1359 | # create 1 pg interface |
| 1360 | self.create_pg_interfaces(range(1)) |
| 1361 | |
| 1362 | self.interfaces = list(self.pg_interfaces) |
| 1363 | |
| 1364 | # setup all interfaces |
| 1365 | for i in self.interfaces: |
| 1366 | i.admin_up() |
| 1367 | i.config_ip6() |
| 1368 | |
| 1369 | def tearDown(self): |
| 1370 | super(TestIPv6RDControlPlane, self).tearDown() |
| 1371 | |
| 1372 | @staticmethod |
| 1373 | def create_ra_packet(pg, routerlifetime=None): |
| 1374 | src_ip = pg.remote_ip6_ll |
| 1375 | dst_ip = pg.local_ip6 |
| 1376 | if routerlifetime is not None: |
| 1377 | ra = ICMPv6ND_RA(routerlifetime=routerlifetime) |
| 1378 | else: |
| 1379 | ra = ICMPv6ND_RA() |
| 1380 | p = (Ether(dst=pg.local_mac, src=pg.remote_mac) / |
| 1381 | IPv6(dst=dst_ip, src=src_ip) / ra) |
| 1382 | return p |
| 1383 | |
| 1384 | @staticmethod |
| 1385 | def get_default_routes(fib): |
| 1386 | list = [] |
| 1387 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1388 | if entry.route.prefix.prefixlen == 0: |
| 1389 | for path in entry.route.paths: |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1390 | if path.sw_if_index != 0xFFFFFFFF: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1391 | defaut_route = {} |
| 1392 | defaut_route['sw_if_index'] = path.sw_if_index |
| 1393 | defaut_route['next_hop'] = path.nh.address.ip6 |
| 1394 | list.append(defaut_route) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1395 | return list |
| 1396 | |
| 1397 | @staticmethod |
| 1398 | def get_interface_addresses(fib, pg): |
| 1399 | list = [] |
| 1400 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1401 | if entry.route.prefix.prefixlen == 128: |
| 1402 | path = entry.route.paths[0] |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1403 | if path.sw_if_index == pg.sw_if_index: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1404 | list.append(str(entry.route.prefix.network_address)) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1405 | return list |
| 1406 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1407 | def wait_for_no_default_route(self, n_tries=50, s_time=1): |
| 1408 | while (n_tries): |
| 1409 | fib = self.vapi.ip_route_dump(0, True) |
| 1410 | default_routes = self.get_default_routes(fib) |
Ole Troan | 6e6ad64 | 2020-02-04 13:28:13 +0100 | [diff] [blame] | 1411 | if 0 == len(default_routes): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1412 | return True |
| 1413 | n_tries = n_tries - 1 |
| 1414 | self.sleep(s_time) |
| 1415 | |
| 1416 | return False |
| 1417 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1418 | def test_all(self): |
| 1419 | """ Test handling of SLAAC addresses and default routes """ |
| 1420 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1421 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1422 | default_routes = self.get_default_routes(fib) |
| 1423 | initial_addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1424 | self.assertEqual(default_routes, []) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1425 | router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll)) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1426 | |
| 1427 | self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1) |
| 1428 | |
| 1429 | self.sleep(0.1) |
| 1430 | |
| 1431 | # send RA |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1432 | packet = (self.create_ra_packet( |
| 1433 | self.pg0) / ICMPv6NDOptPrefixInfo( |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1434 | prefix="1::", |
| 1435 | prefixlen=64, |
| 1436 | validlifetime=2, |
| 1437 | preferredlifetime=2, |
| 1438 | L=1, |
| 1439 | A=1, |
| 1440 | ) / ICMPv6NDOptPrefixInfo( |
| 1441 | prefix="7::", |
| 1442 | prefixlen=20, |
| 1443 | validlifetime=1500, |
| 1444 | preferredlifetime=1000, |
| 1445 | L=1, |
| 1446 | A=0, |
| 1447 | )) |
| 1448 | self.pg0.add_stream([packet]) |
| 1449 | self.pg_start() |
| 1450 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1451 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1452 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1453 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1454 | |
| 1455 | # check FIB for new address |
| 1456 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1457 | new_addresses = addresses.difference(initial_addresses) |
| 1458 | self.assertEqual(len(new_addresses), 1) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1459 | prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)), |
| 1460 | strict=False) |
| 1461 | self.assertEqual(prefix, IPv6Network(text_type('1::/20'))) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1462 | |
| 1463 | # check FIB for new default route |
| 1464 | default_routes = self.get_default_routes(fib) |
| 1465 | self.assertEqual(len(default_routes), 1) |
| 1466 | dr = default_routes[0] |
| 1467 | self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index) |
| 1468 | self.assertEqual(dr['next_hop'], router_address) |
| 1469 | |
| 1470 | # send RA to delete default route |
| 1471 | packet = self.create_ra_packet(self.pg0, routerlifetime=0) |
| 1472 | self.pg0.add_stream([packet]) |
| 1473 | self.pg_start() |
| 1474 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1475 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1476 | |
| 1477 | # check that default route is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1478 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1479 | default_routes = self.get_default_routes(fib) |
| 1480 | self.assertEqual(len(default_routes), 0) |
| 1481 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1482 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1483 | |
| 1484 | # send RA |
| 1485 | packet = self.create_ra_packet(self.pg0) |
| 1486 | self.pg0.add_stream([packet]) |
| 1487 | self.pg_start() |
| 1488 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1489 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1490 | |
| 1491 | # check FIB for new default route |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1492 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1493 | default_routes = self.get_default_routes(fib) |
| 1494 | self.assertEqual(len(default_routes), 1) |
| 1495 | dr = default_routes[0] |
| 1496 | self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index) |
| 1497 | self.assertEqual(dr['next_hop'], router_address) |
| 1498 | |
| 1499 | # send RA, updating router lifetime to 1s |
| 1500 | packet = self.create_ra_packet(self.pg0, 1) |
| 1501 | self.pg0.add_stream([packet]) |
| 1502 | self.pg_start() |
| 1503 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1504 | self.sleep_on_vpp_time(0.1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1505 | |
| 1506 | # check that default route still exists |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1507 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1508 | default_routes = self.get_default_routes(fib) |
| 1509 | self.assertEqual(len(default_routes), 1) |
| 1510 | dr = default_routes[0] |
| 1511 | self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index) |
| 1512 | self.assertEqual(dr['next_hop'], router_address) |
| 1513 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1514 | self.sleep_on_vpp_time(1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1515 | |
| 1516 | # check that default route is deleted |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1517 | self.assertTrue(self.wait_for_no_default_route()) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1518 | |
| 1519 | # check FIB still contains the SLAAC address |
| 1520 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1521 | new_addresses = addresses.difference(initial_addresses) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1522 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1523 | self.assertEqual(len(new_addresses), 1) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1524 | prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)), |
| 1525 | strict=False) |
| 1526 | self.assertEqual(prefix, IPv6Network(text_type('1::/20'))) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1527 | |
Andrew Yourtchenko | 63cb882 | 2019-10-13 18:56:03 +0000 | [diff] [blame] | 1528 | self.sleep_on_vpp_time(1) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1529 | |
| 1530 | # check that SLAAC address is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1531 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1532 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1533 | new_addresses = addresses.difference(initial_addresses) |
| 1534 | self.assertEqual(len(new_addresses), 0) |
| 1535 | |
| 1536 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1537 | class IPv6NDProxyTest(TestIPv6ND): |
| 1538 | """ IPv6 ND ProxyTest Case """ |
| 1539 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1540 | @classmethod |
| 1541 | def setUpClass(cls): |
| 1542 | super(IPv6NDProxyTest, cls).setUpClass() |
| 1543 | |
| 1544 | @classmethod |
| 1545 | def tearDownClass(cls): |
| 1546 | super(IPv6NDProxyTest, cls).tearDownClass() |
| 1547 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1548 | def setUp(self): |
| 1549 | super(IPv6NDProxyTest, self).setUp() |
| 1550 | |
| 1551 | # create 3 pg interfaces |
| 1552 | self.create_pg_interfaces(range(3)) |
| 1553 | |
| 1554 | # pg0 is the master interface, with the configured subnet |
| 1555 | self.pg0.admin_up() |
| 1556 | self.pg0.config_ip6() |
| 1557 | self.pg0.resolve_ndp() |
| 1558 | |
| 1559 | self.pg1.ip6_enable() |
| 1560 | self.pg2.ip6_enable() |
| 1561 | |
| 1562 | def tearDown(self): |
| 1563 | super(IPv6NDProxyTest, self).tearDown() |
| 1564 | |
| 1565 | def test_nd_proxy(self): |
| 1566 | """ IPv6 Proxy ND """ |
| 1567 | |
| 1568 | # |
| 1569 | # Generate some hosts in the subnet that we are proxying |
| 1570 | # |
| 1571 | self.pg0.generate_remote_hosts(8) |
| 1572 | |
| 1573 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 1574 | d = inet_ntop(AF_INET6, nsma) |
| 1575 | |
| 1576 | # |
| 1577 | # Send an NS for one of those remote hosts on one of the proxy links |
| 1578 | # expect no response since it's from an address that is not |
| 1579 | # on the link that has the prefix configured |
| 1580 | # |
| 1581 | ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1582 | IPv6(dst=d, |
| 1583 | src=self.pg0._remote_hosts[2].ip6) / |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1584 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1585 | ICMPv6NDOptSrcLLAddr( |
| 1586 | lladdr=self.pg0._remote_hosts[2].mac)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1587 | |
| 1588 | self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS") |
| 1589 | |
| 1590 | # |
| 1591 | # Add proxy support for the host |
| 1592 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1593 | self.vapi.ip6nd_proxy_add_del( |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1594 | is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1595 | sw_if_index=self.pg1.sw_if_index) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1596 | |
| 1597 | # |
| 1598 | # try that NS again. this time we expect an NA back |
| 1599 | # |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1600 | self.send_and_expect_na(self.pg1, ns_pg1, |
| 1601 | "NS to proxy entry", |
| 1602 | dst_ip=self.pg0._remote_hosts[2].ip6, |
| 1603 | tgt_ip=self.pg0.local_ip6) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1604 | |
| 1605 | # |
| 1606 | # ... and that we have an entry in the ND cache |
| 1607 | # |
| 1608 | self.assertTrue(find_nbr(self, |
| 1609 | self.pg1.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1610 | self.pg0._remote_hosts[2].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1611 | |
| 1612 | # |
| 1613 | # ... and we can route traffic to it |
| 1614 | # |
| 1615 | t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 1616 | IPv6(dst=self.pg0._remote_hosts[2].ip6, |
| 1617 | src=self.pg0.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1618 | inet6.UDP(sport=10000, dport=20000) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1619 | Raw(b'\xa5' * 100)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1620 | |
| 1621 | self.pg0.add_stream(t) |
| 1622 | self.pg_enable_capture(self.pg_interfaces) |
| 1623 | self.pg_start() |
| 1624 | rx = self.pg1.get_capture(1) |
| 1625 | rx = rx[0] |
| 1626 | |
| 1627 | self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) |
| 1628 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1629 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1630 | self.assertEqual(rx[IPv6].src, |
| 1631 | t[IPv6].src) |
| 1632 | self.assertEqual(rx[IPv6].dst, |
| 1633 | t[IPv6].dst) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1634 | |
| 1635 | # |
| 1636 | # Test we proxy for the host on the main interface |
| 1637 | # |
| 1638 | ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / |
| 1639 | IPv6(dst=d, src=self.pg0.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1640 | ICMPv6ND_NS( |
| 1641 | tgt=self.pg0._remote_hosts[2].ip6) / |
| 1642 | ICMPv6NDOptSrcLLAddr( |
| 1643 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1644 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1645 | self.send_and_expect_na(self.pg0, ns_pg0, |
| 1646 | "NS to proxy entry on main", |
| 1647 | tgt_ip=self.pg0._remote_hosts[2].ip6, |
| 1648 | dst_ip=self.pg0.remote_ip6) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1649 | |
| 1650 | # |
| 1651 | # Setup and resolve proxy for another host on another interface |
| 1652 | # |
| 1653 | ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1654 | IPv6(dst=d, |
| 1655 | src=self.pg0._remote_hosts[3].ip6) / |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1656 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1657 | ICMPv6NDOptSrcLLAddr( |
| 1658 | lladdr=self.pg0._remote_hosts[2].mac)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1659 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1660 | self.vapi.ip6nd_proxy_add_del( |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1661 | is_add=1, ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1662 | sw_if_index=self.pg2.sw_if_index) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1663 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1664 | self.send_and_expect_na(self.pg2, ns_pg2, |
| 1665 | "NS to proxy entry other interface", |
| 1666 | dst_ip=self.pg0._remote_hosts[3].ip6, |
| 1667 | tgt_ip=self.pg0.local_ip6) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1668 | |
| 1669 | self.assertTrue(find_nbr(self, |
| 1670 | self.pg2.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1671 | self.pg0._remote_hosts[3].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1672 | |
| 1673 | # |
| 1674 | # hosts can communicate. pg2->pg1 |
| 1675 | # |
| 1676 | t2 = (Ether(dst=self.pg2.local_mac, |
| 1677 | src=self.pg0.remote_hosts[3].mac) / |
| 1678 | IPv6(dst=self.pg0._remote_hosts[2].ip6, |
| 1679 | src=self.pg0._remote_hosts[3].ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1680 | inet6.UDP(sport=10000, dport=20000) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1681 | Raw(b'\xa5' * 100)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1682 | |
| 1683 | self.pg2.add_stream(t2) |
| 1684 | self.pg_enable_capture(self.pg_interfaces) |
| 1685 | self.pg_start() |
| 1686 | rx = self.pg1.get_capture(1) |
| 1687 | rx = rx[0] |
| 1688 | |
| 1689 | self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) |
| 1690 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1691 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1692 | self.assertEqual(rx[IPv6].src, |
| 1693 | t2[IPv6].src) |
| 1694 | self.assertEqual(rx[IPv6].dst, |
| 1695 | t2[IPv6].dst) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1696 | |
| 1697 | # |
| 1698 | # remove the proxy configs |
| 1699 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1700 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1701 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1702 | sw_if_index=self.pg1.sw_if_index, is_add=0) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1703 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1704 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1705 | sw_if_index=self.pg2.sw_if_index, is_add=0) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1706 | |
| 1707 | self.assertFalse(find_nbr(self, |
| 1708 | self.pg2.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1709 | self.pg0._remote_hosts[3].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1710 | self.assertFalse(find_nbr(self, |
| 1711 | self.pg1.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1712 | self.pg0._remote_hosts[2].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1713 | |
| 1714 | # |
| 1715 | # no longer proxy-ing... |
| 1716 | # |
| 1717 | self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured") |
| 1718 | self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured") |
| 1719 | self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured") |
| 1720 | |
| 1721 | # |
| 1722 | # no longer forwarding. traffic generates NS out of the glean/main |
| 1723 | # interface |
| 1724 | # |
| 1725 | self.pg2.add_stream(t2) |
| 1726 | self.pg_enable_capture(self.pg_interfaces) |
| 1727 | self.pg_start() |
| 1728 | |
| 1729 | rx = self.pg0.get_capture(1) |
| 1730 | |
| 1731 | self.assertTrue(rx[0].haslayer(ICMPv6ND_NS)) |
| 1732 | |
| 1733 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1734 | class TestIPNull(VppTestCase): |
| 1735 | """ IPv6 routes via NULL """ |
| 1736 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1737 | @classmethod |
| 1738 | def setUpClass(cls): |
| 1739 | super(TestIPNull, cls).setUpClass() |
| 1740 | |
| 1741 | @classmethod |
| 1742 | def tearDownClass(cls): |
| 1743 | super(TestIPNull, cls).tearDownClass() |
| 1744 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1745 | def setUp(self): |
| 1746 | super(TestIPNull, self).setUp() |
| 1747 | |
| 1748 | # create 2 pg interfaces |
| 1749 | self.create_pg_interfaces(range(1)) |
| 1750 | |
| 1751 | for i in self.pg_interfaces: |
| 1752 | i.admin_up() |
| 1753 | i.config_ip6() |
| 1754 | i.resolve_ndp() |
| 1755 | |
| 1756 | def tearDown(self): |
| 1757 | super(TestIPNull, self).tearDown() |
| 1758 | for i in self.pg_interfaces: |
| 1759 | i.unconfig_ip6() |
| 1760 | i.admin_down() |
| 1761 | |
| 1762 | def test_ip_null(self): |
| 1763 | """ IP NULL route """ |
| 1764 | |
| 1765 | p = (Ether(src=self.pg0.remote_mac, |
| 1766 | dst=self.pg0.local_mac) / |
| 1767 | IPv6(src=self.pg0.remote_ip6, dst="2001::1") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1768 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1769 | Raw(b'\xa5' * 100)) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1770 | |
| 1771 | # |
| 1772 | # A route via IP NULL that will reply with ICMP unreachables |
| 1773 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1774 | ip_unreach = VppIpRoute( |
| 1775 | self, "2001::", 64, |
| 1776 | [VppRoutePath("::", 0xffffffff, |
| 1777 | type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)]) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1778 | ip_unreach.add_vpp_config() |
| 1779 | |
| 1780 | self.pg0.add_stream(p) |
| 1781 | self.pg_enable_capture(self.pg_interfaces) |
| 1782 | self.pg_start() |
| 1783 | |
| 1784 | rx = self.pg0.get_capture(1) |
| 1785 | rx = rx[0] |
| 1786 | icmp = rx[ICMPv6DestUnreach] |
| 1787 | |
| 1788 | # 0 = "No route to destination" |
| 1789 | self.assertEqual(icmp.code, 0) |
| 1790 | |
| 1791 | # ICMP is rate limited. pause a bit |
| 1792 | self.sleep(1) |
| 1793 | |
| 1794 | # |
| 1795 | # A route via IP NULL that will reply with ICMP prohibited |
| 1796 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1797 | ip_prohibit = VppIpRoute( |
| 1798 | self, "2001::1", 128, |
| 1799 | [VppRoutePath("::", 0xffffffff, |
| 1800 | type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)]) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1801 | ip_prohibit.add_vpp_config() |
| 1802 | |
| 1803 | self.pg0.add_stream(p) |
| 1804 | self.pg_enable_capture(self.pg_interfaces) |
| 1805 | self.pg_start() |
| 1806 | |
| 1807 | rx = self.pg0.get_capture(1) |
| 1808 | rx = rx[0] |
| 1809 | icmp = rx[ICMPv6DestUnreach] |
| 1810 | |
| 1811 | # 1 = "Communication with destination administratively prohibited" |
| 1812 | self.assertEqual(icmp.code, 1) |
| 1813 | |
| 1814 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1815 | class TestIPDisabled(VppTestCase): |
| 1816 | """ IPv6 disabled """ |
| 1817 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1818 | @classmethod |
| 1819 | def setUpClass(cls): |
| 1820 | super(TestIPDisabled, cls).setUpClass() |
| 1821 | |
| 1822 | @classmethod |
| 1823 | def tearDownClass(cls): |
| 1824 | super(TestIPDisabled, cls).tearDownClass() |
| 1825 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1826 | def setUp(self): |
| 1827 | super(TestIPDisabled, self).setUp() |
| 1828 | |
| 1829 | # create 2 pg interfaces |
| 1830 | self.create_pg_interfaces(range(2)) |
| 1831 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1832 | # PG0 is IP enabled |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1833 | self.pg0.admin_up() |
| 1834 | self.pg0.config_ip6() |
| 1835 | self.pg0.resolve_ndp() |
| 1836 | |
| 1837 | # PG 1 is not IP enabled |
| 1838 | self.pg1.admin_up() |
| 1839 | |
| 1840 | def tearDown(self): |
| 1841 | super(TestIPDisabled, self).tearDown() |
| 1842 | for i in self.pg_interfaces: |
| 1843 | i.unconfig_ip4() |
| 1844 | i.admin_down() |
| 1845 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1846 | def test_ip_disabled(self): |
| 1847 | """ IP Disabled """ |
| 1848 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 1849 | MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t |
| 1850 | MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1851 | # |
| 1852 | # An (S,G). |
| 1853 | # one accepting interface, pg0, 2 forwarding interfaces |
| 1854 | # |
| 1855 | route_ff_01 = VppIpMRoute( |
| 1856 | self, |
| 1857 | "::", |
| 1858 | "ffef::1", 128, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 1859 | MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE, |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1860 | [VppMRoutePath(self.pg1.sw_if_index, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 1861 | MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT), |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1862 | VppMRoutePath(self.pg0.sw_if_index, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 1863 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)]) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1864 | route_ff_01.add_vpp_config() |
| 1865 | |
| 1866 | pu = (Ether(src=self.pg1.remote_mac, |
| 1867 | dst=self.pg1.local_mac) / |
| 1868 | IPv6(src="2001::1", dst=self.pg0.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1869 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1870 | Raw(b'\xa5' * 100)) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1871 | pm = (Ether(src=self.pg1.remote_mac, |
| 1872 | dst=self.pg1.local_mac) / |
| 1873 | IPv6(src="2001::1", dst="ffef::1") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1874 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1875 | Raw(b'\xa5' * 100)) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1876 | |
| 1877 | # |
| 1878 | # PG1 does not forward IP traffic |
| 1879 | # |
| 1880 | self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") |
| 1881 | self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") |
| 1882 | |
| 1883 | # |
| 1884 | # IP enable PG1 |
| 1885 | # |
| 1886 | self.pg1.config_ip6() |
| 1887 | |
| 1888 | # |
| 1889 | # Now we get packets through |
| 1890 | # |
| 1891 | self.pg1.add_stream(pu) |
| 1892 | self.pg_enable_capture(self.pg_interfaces) |
| 1893 | self.pg_start() |
| 1894 | rx = self.pg0.get_capture(1) |
| 1895 | |
| 1896 | self.pg1.add_stream(pm) |
| 1897 | self.pg_enable_capture(self.pg_interfaces) |
| 1898 | self.pg_start() |
| 1899 | rx = self.pg0.get_capture(1) |
| 1900 | |
| 1901 | # |
| 1902 | # Disable PG1 |
| 1903 | # |
| 1904 | self.pg1.unconfig_ip6() |
| 1905 | |
| 1906 | # |
| 1907 | # PG1 does not forward IP traffic |
| 1908 | # |
| 1909 | self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") |
| 1910 | self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") |
| 1911 | |
| 1912 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1913 | class TestIP6LoadBalance(VppTestCase): |
| 1914 | """ IPv6 Load-Balancing """ |
| 1915 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1916 | @classmethod |
| 1917 | def setUpClass(cls): |
| 1918 | super(TestIP6LoadBalance, cls).setUpClass() |
| 1919 | |
| 1920 | @classmethod |
| 1921 | def tearDownClass(cls): |
| 1922 | super(TestIP6LoadBalance, cls).tearDownClass() |
| 1923 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1924 | def setUp(self): |
| 1925 | super(TestIP6LoadBalance, self).setUp() |
| 1926 | |
| 1927 | self.create_pg_interfaces(range(5)) |
| 1928 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1929 | mpls_tbl = VppMplsTable(self, 0) |
| 1930 | mpls_tbl.add_vpp_config() |
| 1931 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1932 | for i in self.pg_interfaces: |
| 1933 | i.admin_up() |
| 1934 | i.config_ip6() |
| 1935 | i.resolve_ndp() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1936 | i.enable_mpls() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1937 | |
| 1938 | def tearDown(self): |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1939 | for i in self.pg_interfaces: |
| 1940 | i.unconfig_ip6() |
| 1941 | i.admin_down() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1942 | i.disable_mpls() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1943 | super(TestIP6LoadBalance, self).tearDown() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1944 | |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 1945 | def pg_send(self, input, pkts): |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 1946 | self.vapi.cli("clear trace") |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1947 | input.add_stream(pkts) |
| 1948 | self.pg_enable_capture(self.pg_interfaces) |
| 1949 | self.pg_start() |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 1950 | |
| 1951 | def send_and_expect_load_balancing(self, input, pkts, outputs): |
| 1952 | self.pg_send(input, pkts) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1953 | for oo in outputs: |
| 1954 | rx = oo._get_capture(1) |
| 1955 | self.assertNotEqual(0, len(rx)) |
| 1956 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1957 | def send_and_expect_one_itf(self, input, pkts, itf): |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 1958 | self.pg_send(input, pkts) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1959 | rx = itf.get_capture(len(pkts)) |
| 1960 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1961 | def test_ip6_load_balance(self): |
| 1962 | """ IPv6 Load-Balancing """ |
| 1963 | |
| 1964 | # |
| 1965 | # An array of packets that differ only in the destination port |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1966 | # - IP only |
| 1967 | # - MPLS EOS |
| 1968 | # - MPLS non-EOS |
| 1969 | # - MPLS non-EOS with an entropy label |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1970 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1971 | port_ip_pkts = [] |
| 1972 | port_mpls_pkts = [] |
| 1973 | port_mpls_neos_pkts = [] |
| 1974 | port_ent_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1975 | |
| 1976 | # |
| 1977 | # An array of packets that differ only in the source address |
| 1978 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1979 | src_ip_pkts = [] |
| 1980 | src_mpls_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1981 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1982 | for ii in range(NUM_PKTS): |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1983 | port_ip_hdr = ( |
| 1984 | IPv6(dst="3000::1", src="3000:1::1") / |
| 1985 | inet6.UDP(sport=1234, dport=1234 + ii) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1986 | Raw(b'\xa5' * 100)) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1987 | port_ip_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1988 | dst=self.pg0.local_mac) / |
| 1989 | port_ip_hdr)) |
| 1990 | port_mpls_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1991 | dst=self.pg0.local_mac) / |
| 1992 | MPLS(label=66, ttl=2) / |
| 1993 | port_ip_hdr)) |
| 1994 | port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1995 | dst=self.pg0.local_mac) / |
| 1996 | MPLS(label=67, ttl=2) / |
| 1997 | MPLS(label=77, ttl=2) / |
| 1998 | port_ip_hdr)) |
| 1999 | port_ent_pkts.append((Ether(src=self.pg0.remote_mac, |
| 2000 | dst=self.pg0.local_mac) / |
| 2001 | MPLS(label=67, ttl=2) / |
| 2002 | MPLS(label=14, ttl=2) / |
| 2003 | MPLS(label=999, ttl=2) / |
| 2004 | port_ip_hdr)) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2005 | src_ip_hdr = ( |
| 2006 | IPv6(dst="3000::1", src="3000:1::%d" % ii) / |
| 2007 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2008 | Raw(b'\xa5' * 100)) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2009 | src_ip_pkts.append((Ether(src=self.pg0.remote_mac, |
| 2010 | dst=self.pg0.local_mac) / |
| 2011 | src_ip_hdr)) |
| 2012 | src_mpls_pkts.append((Ether(src=self.pg0.remote_mac, |
| 2013 | dst=self.pg0.local_mac) / |
| 2014 | MPLS(label=66, ttl=2) / |
| 2015 | src_ip_hdr)) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2016 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2017 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2018 | # A route for the IP packets |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2019 | # |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2020 | route_3000_1 = VppIpRoute(self, "3000::1", 128, |
| 2021 | [VppRoutePath(self.pg1.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2022 | self.pg1.sw_if_index), |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2023 | VppRoutePath(self.pg2.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2024 | self.pg2.sw_if_index)]) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2025 | route_3000_1.add_vpp_config() |
| 2026 | |
| 2027 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2028 | # a local-label for the EOS packets |
| 2029 | # |
| 2030 | binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1) |
| 2031 | binding.add_vpp_config() |
| 2032 | |
| 2033 | # |
| 2034 | # An MPLS route for the non-EOS packets |
| 2035 | # |
| 2036 | route_67 = VppMplsRoute(self, 67, 0, |
| 2037 | [VppRoutePath(self.pg1.remote_ip6, |
| 2038 | self.pg1.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2039 | labels=[67]), |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2040 | VppRoutePath(self.pg2.remote_ip6, |
| 2041 | self.pg2.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2042 | labels=[67])]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2043 | route_67.add_vpp_config() |
| 2044 | |
| 2045 | # |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2046 | # inject the packet on pg0 - expect load-balancing across the 2 paths |
| 2047 | # - since the default hash config is to use IP src,dst and port |
| 2048 | # src,dst |
| 2049 | # We are not going to ensure equal amounts of packets across each link, |
| 2050 | # since the hash algorithm is statistical and therefore this can never |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2051 | # be guaranteed. But with 64 different packets we do expect some |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2052 | # balancing. So instead just ensure there is traffic on each link. |
| 2053 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2054 | self.send_and_expect_load_balancing(self.pg0, port_ip_pkts, |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2055 | [self.pg1, self.pg2]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2056 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2057 | [self.pg1, self.pg2]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2058 | self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts, |
| 2059 | [self.pg1, self.pg2]) |
| 2060 | self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, |
| 2061 | [self.pg1, self.pg2]) |
| 2062 | self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts, |
| 2063 | [self.pg1, self.pg2]) |
| 2064 | |
| 2065 | # |
| 2066 | # The packets with Entropy label in should not load-balance, |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2067 | # since the Entropy value is fixed. |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2068 | # |
| 2069 | self.send_and_expect_one_itf(self.pg0, port_ent_pkts, self.pg1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2070 | |
| 2071 | # |
| 2072 | # change the flow hash config so it's only IP src,dst |
| 2073 | # - now only the stream with differing source address will |
| 2074 | # load-balance |
| 2075 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 2076 | self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0, |
| 2077 | is_ipv6=1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2078 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2079 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2080 | [self.pg1, self.pg2]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 2081 | self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, |
| 2082 | [self.pg1, self.pg2]) |
| 2083 | self.send_and_expect_one_itf(self.pg0, port_ip_pkts, self.pg2) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2084 | |
| 2085 | # |
| 2086 | # change the flow hash config back to defaults |
| 2087 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 2088 | self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1, |
| 2089 | is_ipv6=1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2090 | |
| 2091 | # |
| 2092 | # Recursive prefixes |
| 2093 | # - testing that 2 stages of load-balancing occurs and there is no |
| 2094 | # polarisation (i.e. only 2 of 4 paths are used) |
| 2095 | # |
| 2096 | port_pkts = [] |
| 2097 | src_pkts = [] |
| 2098 | |
| 2099 | for ii in range(257): |
| 2100 | port_pkts.append((Ether(src=self.pg0.remote_mac, |
| 2101 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2102 | IPv6(dst="4000::1", |
| 2103 | src="4000:1::1") / |
| 2104 | inet6.UDP(sport=1234, |
| 2105 | dport=1234 + ii) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2106 | Raw(b'\xa5' * 100))) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2107 | src_pkts.append((Ether(src=self.pg0.remote_mac, |
| 2108 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2109 | IPv6(dst="4000::1", |
| 2110 | src="4000:1::%d" % ii) / |
| 2111 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2112 | Raw(b'\xa5' * 100))) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2113 | |
| 2114 | route_3000_2 = VppIpRoute(self, "3000::2", 128, |
| 2115 | [VppRoutePath(self.pg3.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2116 | self.pg3.sw_if_index), |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2117 | VppRoutePath(self.pg4.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2118 | self.pg4.sw_if_index)]) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2119 | route_3000_2.add_vpp_config() |
| 2120 | |
| 2121 | route_4000_1 = VppIpRoute(self, "4000::1", 128, |
| 2122 | [VppRoutePath("3000::1", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2123 | 0xffffffff), |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2124 | VppRoutePath("3000::2", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2125 | 0xffffffff)]) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2126 | route_4000_1.add_vpp_config() |
| 2127 | |
| 2128 | # |
| 2129 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 2130 | # |
| 2131 | self.vapi.cli("clear trace") |
| 2132 | self.send_and_expect_load_balancing(self.pg0, port_pkts, |
| 2133 | [self.pg1, self.pg2, |
| 2134 | self.pg3, self.pg4]) |
| 2135 | self.send_and_expect_load_balancing(self.pg0, src_pkts, |
| 2136 | [self.pg1, self.pg2, |
| 2137 | self.pg3, self.pg4]) |
| 2138 | |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2139 | # |
| 2140 | # Recursive prefixes |
| 2141 | # - testing that 2 stages of load-balancing no choices |
| 2142 | # |
| 2143 | port_pkts = [] |
| 2144 | |
| 2145 | for ii in range(257): |
| 2146 | port_pkts.append((Ether(src=self.pg0.remote_mac, |
| 2147 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2148 | IPv6(dst="6000::1", |
| 2149 | src="6000:1::1") / |
| 2150 | inet6.UDP(sport=1234, |
| 2151 | dport=1234 + ii) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2152 | Raw(b'\xa5' * 100))) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2153 | |
| 2154 | route_5000_2 = VppIpRoute(self, "5000::2", 128, |
| 2155 | [VppRoutePath(self.pg3.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2156 | self.pg3.sw_if_index)]) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2157 | route_5000_2.add_vpp_config() |
| 2158 | |
| 2159 | route_6000_1 = VppIpRoute(self, "6000::1", 128, |
| 2160 | [VppRoutePath("5000::2", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2161 | 0xffffffff)]) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 2162 | route_6000_1.add_vpp_config() |
| 2163 | |
| 2164 | # |
| 2165 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 2166 | # |
| 2167 | self.vapi.cli("clear trace") |
| 2168 | self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3) |
| 2169 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 2170 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2171 | class TestIP6Punt(VppTestCase): |
| 2172 | """ IPv6 Punt Police/Redirect """ |
| 2173 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2174 | @classmethod |
| 2175 | def setUpClass(cls): |
| 2176 | super(TestIP6Punt, cls).setUpClass() |
| 2177 | |
| 2178 | @classmethod |
| 2179 | def tearDownClass(cls): |
| 2180 | super(TestIP6Punt, cls).tearDownClass() |
| 2181 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2182 | def setUp(self): |
| 2183 | super(TestIP6Punt, self).setUp() |
| 2184 | |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2185 | self.create_pg_interfaces(range(4)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2186 | |
| 2187 | for i in self.pg_interfaces: |
| 2188 | i.admin_up() |
| 2189 | i.config_ip6() |
| 2190 | i.resolve_ndp() |
| 2191 | |
| 2192 | def tearDown(self): |
| 2193 | super(TestIP6Punt, self).tearDown() |
| 2194 | for i in self.pg_interfaces: |
| 2195 | i.unconfig_ip6() |
| 2196 | i.admin_down() |
| 2197 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2198 | def test_ip_punt(self): |
| 2199 | """ IP6 punt police and redirect """ |
| 2200 | |
| 2201 | p = (Ether(src=self.pg0.remote_mac, |
| 2202 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2203 | IPv6(src=self.pg0.remote_ip6, |
| 2204 | dst=self.pg0.local_ip6) / |
| 2205 | inet6.TCP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2206 | Raw(b'\xa5' * 100)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2207 | |
| 2208 | pkts = p * 1025 |
| 2209 | |
| 2210 | # |
| 2211 | # Configure a punt redirect via pg1. |
| 2212 | # |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2213 | nh_addr = self.pg1.remote_ip6 |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2214 | ip_punt_redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index, |
| 2215 | self.pg1.sw_if_index, nh_addr) |
| 2216 | ip_punt_redirect.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2217 | |
| 2218 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 2219 | |
| 2220 | # |
| 2221 | # add a policer |
| 2222 | # |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 2223 | policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1) |
| 2224 | policer.add_vpp_config() |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2225 | ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index, |
| 2226 | is_ip6=True) |
| 2227 | ip_punt_policer.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2228 | |
| 2229 | self.vapi.cli("clear trace") |
| 2230 | self.pg0.add_stream(pkts) |
| 2231 | self.pg_enable_capture(self.pg_interfaces) |
| 2232 | self.pg_start() |
| 2233 | |
| 2234 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2235 | # the number of packet received should be greater than 0, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2236 | # but not equal to the number sent, since some were policed |
| 2237 | # |
| 2238 | rx = self.pg1._get_capture(1) |
Paul Vinciguerra | 3d2df21 | 2018-11-24 23:19:53 -0800 | [diff] [blame] | 2239 | self.assertGreater(len(rx), 0) |
| 2240 | self.assertLess(len(rx), len(pkts)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2241 | |
| 2242 | # |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 2243 | # remove the policer. back to full rx |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2244 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2245 | ip_punt_policer.remove_vpp_config() |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 2246 | policer.remove_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2247 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 2248 | |
| 2249 | # |
| 2250 | # remove the redirect. expect full drop. |
| 2251 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2252 | ip_punt_redirect.remove_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2253 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 2254 | "IP no punt config") |
| 2255 | |
| 2256 | # |
| 2257 | # Add a redirect that is not input port selective |
| 2258 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2259 | ip_punt_redirect = VppIpPuntRedirect(self, 0xffffffff, |
| 2260 | self.pg1.sw_if_index, nh_addr) |
| 2261 | ip_punt_redirect.add_vpp_config() |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2262 | self.send_and_expect(self.pg0, pkts, self.pg1) |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2263 | ip_punt_redirect.remove_vpp_config() |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2264 | |
| 2265 | def test_ip_punt_dump(self): |
| 2266 | """ IP6 punt redirect dump""" |
| 2267 | |
| 2268 | # |
| 2269 | # Configure a punt redirects |
| 2270 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2271 | nh_address = self.pg3.remote_ip6 |
| 2272 | ipr_03 = VppIpPuntRedirect(self, self.pg0.sw_if_index, |
| 2273 | self.pg3.sw_if_index, nh_address) |
| 2274 | ipr_13 = VppIpPuntRedirect(self, self.pg1.sw_if_index, |
| 2275 | self.pg3.sw_if_index, nh_address) |
| 2276 | ipr_23 = VppIpPuntRedirect(self, self.pg2.sw_if_index, |
| 2277 | self.pg3.sw_if_index, '0::0') |
| 2278 | ipr_03.add_vpp_config() |
| 2279 | ipr_13.add_vpp_config() |
| 2280 | ipr_23.add_vpp_config() |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2281 | |
| 2282 | # |
| 2283 | # Dump pg0 punt redirects |
| 2284 | # |
Jakub Grajciar | 2df2f75 | 2020-12-01 11:23:44 +0100 | [diff] [blame] | 2285 | self.assertTrue(ipr_03.query_vpp_config()) |
| 2286 | self.assertTrue(ipr_13.query_vpp_config()) |
| 2287 | self.assertTrue(ipr_23.query_vpp_config()) |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2288 | |
| 2289 | # |
| 2290 | # Dump punt redirects for all interfaces |
| 2291 | # |
| 2292 | punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1) |
| 2293 | self.assertEqual(len(punts), 3) |
| 2294 | for p in punts: |
| 2295 | 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] | 2296 | self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6) |
| 2297 | self.assertEqual(str(punts[2].punt.nh), '::') |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2298 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2299 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2300 | class TestIPDeag(VppTestCase): |
| 2301 | """ IPv6 Deaggregate Routes """ |
| 2302 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2303 | @classmethod |
| 2304 | def setUpClass(cls): |
| 2305 | super(TestIPDeag, cls).setUpClass() |
| 2306 | |
| 2307 | @classmethod |
| 2308 | def tearDownClass(cls): |
| 2309 | super(TestIPDeag, cls).tearDownClass() |
| 2310 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2311 | def setUp(self): |
| 2312 | super(TestIPDeag, self).setUp() |
| 2313 | |
| 2314 | self.create_pg_interfaces(range(3)) |
| 2315 | |
| 2316 | for i in self.pg_interfaces: |
| 2317 | i.admin_up() |
| 2318 | i.config_ip6() |
| 2319 | i.resolve_ndp() |
| 2320 | |
| 2321 | def tearDown(self): |
| 2322 | super(TestIPDeag, self).tearDown() |
| 2323 | for i in self.pg_interfaces: |
| 2324 | i.unconfig_ip6() |
| 2325 | i.admin_down() |
| 2326 | |
| 2327 | def test_ip_deag(self): |
| 2328 | """ IP Deag Routes """ |
| 2329 | |
| 2330 | # |
| 2331 | # Create a table to be used for: |
| 2332 | # 1 - another destination address lookup |
| 2333 | # 2 - a source address lookup |
| 2334 | # |
| 2335 | table_dst = VppIpTable(self, 1, is_ip6=1) |
| 2336 | table_src = VppIpTable(self, 2, is_ip6=1) |
| 2337 | table_dst.add_vpp_config() |
| 2338 | table_src.add_vpp_config() |
| 2339 | |
| 2340 | # |
| 2341 | # Add a route in the default table to point to a deag/ |
| 2342 | # second lookup in each of these tables |
| 2343 | # |
| 2344 | route_to_dst = VppIpRoute(self, "1::1", 128, |
| 2345 | [VppRoutePath("::", |
| 2346 | 0xffffffff, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2347 | nh_table_id=1)]) |
| 2348 | route_to_src = VppIpRoute( |
| 2349 | self, "1::2", 128, |
| 2350 | [VppRoutePath("::", |
| 2351 | 0xffffffff, |
| 2352 | nh_table_id=2, |
| 2353 | type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)]) |
| 2354 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2355 | route_to_dst.add_vpp_config() |
| 2356 | route_to_src.add_vpp_config() |
| 2357 | |
| 2358 | # |
| 2359 | # packets to these destination are dropped, since they'll |
| 2360 | # hit the respective default routes in the second table |
| 2361 | # |
| 2362 | p_dst = (Ether(src=self.pg0.remote_mac, |
| 2363 | dst=self.pg0.local_mac) / |
| 2364 | IPv6(src="5::5", dst="1::1") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2365 | inet6.TCP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2366 | Raw(b'\xa5' * 100)) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2367 | p_src = (Ether(src=self.pg0.remote_mac, |
| 2368 | dst=self.pg0.local_mac) / |
| 2369 | IPv6(src="2::2", dst="1::2") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2370 | inet6.TCP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2371 | Raw(b'\xa5' * 100)) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2372 | pkts_dst = p_dst * 257 |
| 2373 | pkts_src = p_src * 257 |
| 2374 | |
| 2375 | self.send_and_assert_no_replies(self.pg0, pkts_dst, |
| 2376 | "IP in dst table") |
| 2377 | self.send_and_assert_no_replies(self.pg0, pkts_src, |
| 2378 | "IP in src table") |
| 2379 | |
| 2380 | # |
| 2381 | # add a route in the dst table to forward via pg1 |
| 2382 | # |
| 2383 | route_in_dst = VppIpRoute(self, "1::1", 128, |
| 2384 | [VppRoutePath(self.pg1.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2385 | self.pg1.sw_if_index)], |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2386 | table_id=1) |
| 2387 | route_in_dst.add_vpp_config() |
| 2388 | |
| 2389 | self.send_and_expect(self.pg0, pkts_dst, self.pg1) |
| 2390 | |
| 2391 | # |
| 2392 | # add a route in the src table to forward via pg2 |
| 2393 | # |
| 2394 | route_in_src = VppIpRoute(self, "2::2", 128, |
| 2395 | [VppRoutePath(self.pg2.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2396 | self.pg2.sw_if_index)], |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2397 | table_id=2) |
| 2398 | route_in_src.add_vpp_config() |
| 2399 | self.send_and_expect(self.pg0, pkts_src, self.pg2) |
| 2400 | |
| 2401 | # |
| 2402 | # loop in the lookup DP |
| 2403 | # |
| 2404 | route_loop = VppIpRoute(self, "3::3", 128, |
| 2405 | [VppRoutePath("::", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2406 | 0xffffffff)]) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2407 | route_loop.add_vpp_config() |
| 2408 | |
| 2409 | p_l = (Ether(src=self.pg0.remote_mac, |
| 2410 | dst=self.pg0.local_mac) / |
| 2411 | IPv6(src="3::4", dst="3::3") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2412 | inet6.TCP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2413 | Raw(b'\xa5' * 100)) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2414 | |
| 2415 | self.send_and_assert_no_replies(self.pg0, p_l * 257, |
| 2416 | "IP lookup loop") |
| 2417 | |
| 2418 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2419 | class TestIP6Input(VppTestCase): |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2420 | """ IPv6 Input Exception Test Cases """ |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2421 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2422 | @classmethod |
| 2423 | def setUpClass(cls): |
| 2424 | super(TestIP6Input, cls).setUpClass() |
| 2425 | |
| 2426 | @classmethod |
| 2427 | def tearDownClass(cls): |
| 2428 | super(TestIP6Input, cls).tearDownClass() |
| 2429 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2430 | def setUp(self): |
| 2431 | super(TestIP6Input, self).setUp() |
| 2432 | |
| 2433 | self.create_pg_interfaces(range(2)) |
| 2434 | |
| 2435 | for i in self.pg_interfaces: |
| 2436 | i.admin_up() |
| 2437 | i.config_ip6() |
| 2438 | i.resolve_ndp() |
| 2439 | |
| 2440 | def tearDown(self): |
| 2441 | super(TestIP6Input, self).tearDown() |
| 2442 | for i in self.pg_interfaces: |
| 2443 | i.unconfig_ip6() |
| 2444 | i.admin_down() |
| 2445 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2446 | def test_ip_input_icmp_reply(self): |
| 2447 | """ IP6 Input Exception - Return ICMP (3,0) """ |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2448 | # |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2449 | # hop limit - ICMP replies |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2450 | # |
| 2451 | p_version = (Ether(src=self.pg0.remote_mac, |
| 2452 | dst=self.pg0.local_mac) / |
| 2453 | IPv6(src=self.pg0.remote_ip6, |
| 2454 | dst=self.pg1.remote_ip6, |
| 2455 | hlim=1) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2456 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2457 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2458 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2459 | rx = self.send_and_expect(self.pg0, p_version * NUM_PKTS, self.pg0) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2460 | rx = rx[0] |
| 2461 | icmp = rx[ICMPv6TimeExceeded] |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2462 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2463 | # 0: "hop limit exceeded in transit", |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2464 | self.assertEqual((icmp.type, icmp.code), (3, 0)) |
| 2465 | |
| 2466 | icmpv6_data = '\x0a' * 18 |
| 2467 | all_0s = "::" |
| 2468 | all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF" |
| 2469 | |
| 2470 | @parameterized.expand([ |
| 2471 | # Name, src, dst, l4proto, msg, timeout |
| 2472 | ("src='iface', dst='iface'", None, None, |
| 2473 | inet6.UDP(sport=1234, dport=1234), "funky version", None), |
| 2474 | ("src='All 0's', dst='iface'", all_0s, None, |
| 2475 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2476 | ("src='iface', dst='All 0's'", None, all_0s, |
| 2477 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2478 | ("src='All 1's', dst='iface'", all_1s, None, |
| 2479 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2480 | ("src='iface', dst='All 1's'", None, all_1s, |
| 2481 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2482 | ("src='All 1's', dst='All 1's'", all_1s, all_1s, |
| 2483 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2484 | |
| 2485 | ]) |
| 2486 | def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout): |
| 2487 | |
| 2488 | self._testMethodDoc = 'IPv6 Input Exception - %s' % name |
| 2489 | |
| 2490 | p_version = (Ether(src=self.pg0.remote_mac, |
| 2491 | dst=self.pg0.local_mac) / |
| 2492 | IPv6(src=src or self.pg0.remote_ip6, |
| 2493 | dst=dst or self.pg1.remote_ip6, |
| 2494 | version=3) / |
| 2495 | l4 / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2496 | Raw(b'\xa5' * 100)) |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2497 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2498 | self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS, |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2499 | remark=msg or "", |
| 2500 | timeout=timeout) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2501 | |
Dave Barach | 9080096 | 2019-05-24 13:03:01 -0400 | [diff] [blame] | 2502 | def test_hop_by_hop(self): |
| 2503 | """ Hop-by-hop header test """ |
| 2504 | |
| 2505 | p = (Ether(src=self.pg0.remote_mac, |
| 2506 | dst=self.pg0.local_mac) / |
| 2507 | IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) / |
| 2508 | IPv6ExtHdrHopByHop() / |
| 2509 | inet6.UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2510 | Raw(b'\xa5' * 100)) |
Dave Barach | 9080096 | 2019-05-24 13:03:01 -0400 | [diff] [blame] | 2511 | |
| 2512 | self.pg0.add_stream(p) |
| 2513 | self.pg_enable_capture(self.pg_interfaces) |
| 2514 | self.pg_start() |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2515 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2516 | |
| 2517 | class TestIPReplace(VppTestCase): |
| 2518 | """ IPv6 Table Replace """ |
| 2519 | |
| 2520 | @classmethod |
| 2521 | def setUpClass(cls): |
| 2522 | super(TestIPReplace, cls).setUpClass() |
| 2523 | |
| 2524 | @classmethod |
| 2525 | def tearDownClass(cls): |
| 2526 | super(TestIPReplace, cls).tearDownClass() |
| 2527 | |
| 2528 | def setUp(self): |
| 2529 | super(TestIPReplace, self).setUp() |
| 2530 | |
| 2531 | self.create_pg_interfaces(range(4)) |
| 2532 | |
| 2533 | table_id = 1 |
| 2534 | self.tables = [] |
| 2535 | |
| 2536 | for i in self.pg_interfaces: |
| 2537 | i.admin_up() |
| 2538 | i.config_ip6() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2539 | i.generate_remote_hosts(2) |
| 2540 | self.tables.append(VppIpTable(self, table_id, |
| 2541 | True).add_vpp_config()) |
| 2542 | table_id += 1 |
| 2543 | |
| 2544 | def tearDown(self): |
| 2545 | super(TestIPReplace, self).tearDown() |
| 2546 | for i in self.pg_interfaces: |
| 2547 | i.admin_down() |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 2548 | i.unconfig_ip6() |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2549 | |
| 2550 | def test_replace(self): |
| 2551 | """ IP Table Replace """ |
| 2552 | |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2553 | MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t |
| 2554 | MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2555 | N_ROUTES = 20 |
| 2556 | links = [self.pg0, self.pg1, self.pg2, self.pg3] |
| 2557 | routes = [[], [], [], []] |
| 2558 | |
| 2559 | # the sizes of 'empty' tables |
| 2560 | for t in self.tables: |
| 2561 | self.assertEqual(len(t.dump()), 2) |
| 2562 | self.assertEqual(len(t.mdump()), 5) |
| 2563 | |
| 2564 | # load up the tables with some routes |
| 2565 | for ii, t in enumerate(self.tables): |
| 2566 | for jj in range(1, N_ROUTES): |
| 2567 | uni = VppIpRoute( |
| 2568 | self, "2001::%d" % jj if jj != 0 else "2001::", 128, |
| 2569 | [VppRoutePath(links[ii].remote_hosts[0].ip6, |
| 2570 | links[ii].sw_if_index), |
| 2571 | VppRoutePath(links[ii].remote_hosts[1].ip6, |
| 2572 | links[ii].sw_if_index)], |
| 2573 | table_id=t.table_id).add_vpp_config() |
| 2574 | multi = VppIpMRoute( |
| 2575 | self, "::", |
| 2576 | "ff:2001::%d" % jj, 128, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2577 | MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2578 | [VppMRoutePath(self.pg0.sw_if_index, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2579 | MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2580 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
| 2581 | VppMRoutePath(self.pg1.sw_if_index, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2582 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2583 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
| 2584 | VppMRoutePath(self.pg2.sw_if_index, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2585 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2586 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
| 2587 | VppMRoutePath(self.pg3.sw_if_index, |
Neale Ranns | 990f694 | 2020-10-20 07:20:17 +0000 | [diff] [blame] | 2588 | MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 2589 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)], |
| 2590 | table_id=t.table_id).add_vpp_config() |
| 2591 | routes[ii].append({'uni': uni, |
| 2592 | 'multi': multi}) |
| 2593 | |
| 2594 | # |
| 2595 | # replace the tables a few times |
| 2596 | # |
| 2597 | for kk in range(3): |
| 2598 | # replace each table |
| 2599 | for t in self.tables: |
| 2600 | t.replace_begin() |
| 2601 | |
| 2602 | # all the routes are still there |
| 2603 | for ii, t in enumerate(self.tables): |
| 2604 | dump = t.dump() |
| 2605 | mdump = t.mdump() |
| 2606 | for r in routes[ii]: |
| 2607 | self.assertTrue(find_route_in_dump(dump, r['uni'], t)) |
| 2608 | self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t)) |
| 2609 | |
| 2610 | # redownload the even numbered routes |
| 2611 | for ii, t in enumerate(self.tables): |
| 2612 | for jj in range(0, N_ROUTES, 2): |
| 2613 | routes[ii][jj]['uni'].add_vpp_config() |
| 2614 | routes[ii][jj]['multi'].add_vpp_config() |
| 2615 | |
| 2616 | # signal each table converged |
| 2617 | for t in self.tables: |
| 2618 | t.replace_end() |
| 2619 | |
| 2620 | # we should find the even routes, but not the odd |
| 2621 | for ii, t in enumerate(self.tables): |
| 2622 | dump = t.dump() |
| 2623 | mdump = t.mdump() |
| 2624 | for jj in range(0, N_ROUTES, 2): |
| 2625 | self.assertTrue(find_route_in_dump( |
| 2626 | dump, routes[ii][jj]['uni'], t)) |
| 2627 | self.assertTrue(find_mroute_in_dump( |
| 2628 | mdump, routes[ii][jj]['multi'], t)) |
| 2629 | for jj in range(1, N_ROUTES - 1, 2): |
| 2630 | self.assertFalse(find_route_in_dump( |
| 2631 | dump, routes[ii][jj]['uni'], t)) |
| 2632 | self.assertFalse(find_mroute_in_dump( |
| 2633 | mdump, routes[ii][jj]['multi'], t)) |
| 2634 | |
| 2635 | # reload all the routes |
| 2636 | for ii, t in enumerate(self.tables): |
| 2637 | for r in routes[ii]: |
| 2638 | r['uni'].add_vpp_config() |
| 2639 | r['multi'].add_vpp_config() |
| 2640 | |
| 2641 | # all the routes are still there |
| 2642 | for ii, t in enumerate(self.tables): |
| 2643 | dump = t.dump() |
| 2644 | mdump = t.mdump() |
| 2645 | for r in routes[ii]: |
| 2646 | self.assertTrue(find_route_in_dump(dump, r['uni'], t)) |
| 2647 | self.assertTrue(find_mroute_in_dump(mdump, r['multi'], t)) |
| 2648 | |
| 2649 | # |
| 2650 | # finally flush the tables for good measure |
| 2651 | # |
| 2652 | for t in self.tables: |
| 2653 | t.flush() |
| 2654 | self.assertEqual(len(t.dump()), 2) |
| 2655 | self.assertEqual(len(t.mdump()), 5) |
| 2656 | |
| 2657 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2658 | class TestIP6Replace(VppTestCase): |
| 2659 | """ IPv4 Interface Address Replace """ |
| 2660 | |
| 2661 | @classmethod |
| 2662 | def setUpClass(cls): |
| 2663 | super(TestIP6Replace, cls).setUpClass() |
| 2664 | |
| 2665 | @classmethod |
| 2666 | def tearDownClass(cls): |
| 2667 | super(TestIP6Replace, cls).tearDownClass() |
| 2668 | |
| 2669 | def setUp(self): |
| 2670 | super(TestIP6Replace, self).setUp() |
| 2671 | |
| 2672 | self.create_pg_interfaces(range(4)) |
| 2673 | |
| 2674 | for i in self.pg_interfaces: |
| 2675 | i.admin_up() |
| 2676 | |
| 2677 | def tearDown(self): |
| 2678 | super(TestIP6Replace, self).tearDown() |
| 2679 | for i in self.pg_interfaces: |
| 2680 | i.admin_down() |
| 2681 | |
| 2682 | def get_n_pfxs(self, intf): |
| 2683 | return len(self.vapi.ip_address_dump(intf.sw_if_index, True)) |
| 2684 | |
| 2685 | def test_replace(self): |
| 2686 | """ IP interface address replace """ |
| 2687 | |
| 2688 | intf_pfxs = [[], [], [], []] |
| 2689 | |
| 2690 | # add prefixes to each of the interfaces |
| 2691 | for i in range(len(self.pg_interfaces)): |
| 2692 | intf = self.pg_interfaces[i] |
| 2693 | |
| 2694 | # 2001:16:x::1/64 |
| 2695 | addr = "2001:16:%d::1" % intf.sw_if_index |
| 2696 | a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 2697 | intf_pfxs[i].append(a) |
| 2698 | |
| 2699 | # 2001:16:x::2/64 - a different address in the same subnet as above |
| 2700 | addr = "2001:16:%d::2" % intf.sw_if_index |
| 2701 | a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 2702 | intf_pfxs[i].append(a) |
| 2703 | |
| 2704 | # 2001:15:x::2/64 - a different address and subnet |
| 2705 | addr = "2001:15:%d::2" % intf.sw_if_index |
| 2706 | a = VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 2707 | intf_pfxs[i].append(a) |
| 2708 | |
| 2709 | # a dump should n_address in it |
| 2710 | for intf in self.pg_interfaces: |
| 2711 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2712 | |
| 2713 | # |
| 2714 | # remove all the address thru a replace |
| 2715 | # |
| 2716 | self.vapi.sw_interface_address_replace_begin() |
| 2717 | self.vapi.sw_interface_address_replace_end() |
| 2718 | for intf in self.pg_interfaces: |
| 2719 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 2720 | |
| 2721 | # |
| 2722 | # add all the interface addresses back |
| 2723 | # |
| 2724 | for p in intf_pfxs: |
| 2725 | for v in p: |
| 2726 | v.add_vpp_config() |
| 2727 | for intf in self.pg_interfaces: |
| 2728 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2729 | |
| 2730 | # |
| 2731 | # replace again, but this time update/re-add the address on the first |
| 2732 | # two interfaces |
| 2733 | # |
| 2734 | self.vapi.sw_interface_address_replace_begin() |
| 2735 | |
| 2736 | for p in intf_pfxs[:2]: |
| 2737 | for v in p: |
| 2738 | v.add_vpp_config() |
| 2739 | |
| 2740 | self.vapi.sw_interface_address_replace_end() |
| 2741 | |
| 2742 | # on the first two the address still exist, |
| 2743 | # on the other two they do not |
| 2744 | for intf in self.pg_interfaces[:2]: |
| 2745 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2746 | for p in intf_pfxs[:2]: |
| 2747 | for v in p: |
| 2748 | self.assertTrue(v.query_vpp_config()) |
| 2749 | for intf in self.pg_interfaces[2:]: |
| 2750 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 2751 | |
| 2752 | # |
| 2753 | # add all the interface addresses back on the last two |
| 2754 | # |
| 2755 | for p in intf_pfxs[2:]: |
| 2756 | for v in p: |
| 2757 | v.add_vpp_config() |
| 2758 | for intf in self.pg_interfaces: |
| 2759 | self.assertEqual(self.get_n_pfxs(intf), 3) |
| 2760 | |
| 2761 | # |
| 2762 | # replace again, this time add different prefixes on all the interfaces |
| 2763 | # |
| 2764 | self.vapi.sw_interface_address_replace_begin() |
| 2765 | |
| 2766 | pfxs = [] |
| 2767 | for intf in self.pg_interfaces: |
| 2768 | # 2001:18:x::1/64 |
| 2769 | addr = "2001:18:%d::1" % intf.sw_if_index |
| 2770 | pfxs.append(VppIpInterfaceAddress(self, intf, addr, |
| 2771 | 64).add_vpp_config()) |
| 2772 | |
| 2773 | self.vapi.sw_interface_address_replace_end() |
| 2774 | |
| 2775 | # only .18 should exist on each interface |
| 2776 | for intf in self.pg_interfaces: |
| 2777 | self.assertEqual(self.get_n_pfxs(intf), 1) |
| 2778 | for pfx in pfxs: |
| 2779 | self.assertTrue(pfx.query_vpp_config()) |
| 2780 | |
| 2781 | # |
| 2782 | # remove everything |
| 2783 | # |
| 2784 | self.vapi.sw_interface_address_replace_begin() |
| 2785 | self.vapi.sw_interface_address_replace_end() |
| 2786 | for intf in self.pg_interfaces: |
| 2787 | self.assertEqual(self.get_n_pfxs(intf), 0) |
| 2788 | |
| 2789 | # |
| 2790 | # add prefixes to each interface. post-begin add the prefix from |
| 2791 | # interface X onto interface Y. this would normally be an error |
| 2792 | # since it would generate a 'duplicate address' warning. but in |
| 2793 | # this case, since what is newly downloaded is sane, it's ok |
| 2794 | # |
| 2795 | for intf in self.pg_interfaces: |
| 2796 | # 2001:18:x::1/64 |
| 2797 | addr = "2001:18:%d::1" % intf.sw_if_index |
| 2798 | VppIpInterfaceAddress(self, intf, addr, 64).add_vpp_config() |
| 2799 | |
| 2800 | self.vapi.sw_interface_address_replace_begin() |
| 2801 | |
| 2802 | pfxs = [] |
| 2803 | for intf in self.pg_interfaces: |
| 2804 | # 2001:18:x::1/64 |
| 2805 | addr = "2001:18:%d::1" % (intf.sw_if_index + 1) |
| 2806 | pfxs.append(VppIpInterfaceAddress(self, intf, |
| 2807 | addr, 64).add_vpp_config()) |
| 2808 | |
| 2809 | self.vapi.sw_interface_address_replace_end() |
| 2810 | |
| 2811 | self.logger.info(self.vapi.cli("sh int addr")) |
| 2812 | |
| 2813 | for intf in self.pg_interfaces: |
| 2814 | self.assertEqual(self.get_n_pfxs(intf), 1) |
| 2815 | for pfx in pfxs: |
| 2816 | self.assertTrue(pfx.query_vpp_config()) |
| 2817 | |
| 2818 | |
Neale Ranns | ec40a7d | 2020-04-23 07:36:12 +0000 | [diff] [blame] | 2819 | class TestIP6LinkLocal(VppTestCase): |
| 2820 | """ IPv6 Link Local """ |
| 2821 | |
| 2822 | @classmethod |
| 2823 | def setUpClass(cls): |
| 2824 | super(TestIP6LinkLocal, cls).setUpClass() |
| 2825 | |
| 2826 | @classmethod |
| 2827 | def tearDownClass(cls): |
| 2828 | super(TestIP6LinkLocal, cls).tearDownClass() |
| 2829 | |
| 2830 | def setUp(self): |
| 2831 | super(TestIP6LinkLocal, self).setUp() |
| 2832 | |
| 2833 | self.create_pg_interfaces(range(2)) |
| 2834 | |
| 2835 | for i in self.pg_interfaces: |
| 2836 | i.admin_up() |
| 2837 | |
| 2838 | def tearDown(self): |
| 2839 | super(TestIP6LinkLocal, self).tearDown() |
| 2840 | for i in self.pg_interfaces: |
| 2841 | i.admin_down() |
| 2842 | |
| 2843 | def test_ip6_ll(self): |
| 2844 | """ IPv6 Link Local """ |
| 2845 | |
| 2846 | # |
| 2847 | # two APIs to add a link local address. |
| 2848 | # 1 - just like any other prefix |
| 2849 | # 2 - with the special set LL API |
| 2850 | # |
| 2851 | |
| 2852 | # |
| 2853 | # First with the API to set a 'normal' prefix |
| 2854 | # |
| 2855 | ll1 = "fe80:1::1" |
| 2856 | ll2 = "fe80:2::2" |
| 2857 | ll3 = "fe80:3::3" |
| 2858 | |
| 2859 | VppIpInterfaceAddress(self, self.pg0, ll1, 128).add_vpp_config() |
| 2860 | |
| 2861 | # |
| 2862 | # should be able to ping the ll |
| 2863 | # |
| 2864 | p_echo_request_1 = (Ether(src=self.pg0.remote_mac, |
| 2865 | dst=self.pg0.local_mac) / |
| 2866 | IPv6(src=ll2, |
| 2867 | dst=ll1) / |
| 2868 | ICMPv6EchoRequest()) |
| 2869 | |
| 2870 | self.send_and_expect(self.pg0, [p_echo_request_1], self.pg0) |
| 2871 | |
| 2872 | # |
| 2873 | # change the link-local on pg0 |
| 2874 | # |
| 2875 | v_ll3 = VppIpInterfaceAddress(self, self.pg0, |
| 2876 | ll3, 128).add_vpp_config() |
| 2877 | |
| 2878 | p_echo_request_3 = (Ether(src=self.pg0.remote_mac, |
| 2879 | dst=self.pg0.local_mac) / |
| 2880 | IPv6(src=ll2, |
| 2881 | dst=ll3) / |
| 2882 | ICMPv6EchoRequest()) |
| 2883 | |
| 2884 | self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0) |
| 2885 | |
| 2886 | # |
| 2887 | # set a normal v6 prefix on the link |
| 2888 | # |
| 2889 | self.pg0.config_ip6() |
| 2890 | |
| 2891 | self.send_and_expect(self.pg0, [p_echo_request_3], self.pg0) |
| 2892 | |
| 2893 | # the link-local cannot be removed |
| 2894 | with self.vapi.assert_negative_api_retval(): |
| 2895 | v_ll3.remove_vpp_config() |
| 2896 | |
| 2897 | # |
| 2898 | # Use the specific link-local API on pg1 |
| 2899 | # |
| 2900 | VppIp6LinkLocalAddress(self, self.pg1, ll1).add_vpp_config() |
| 2901 | self.send_and_expect(self.pg1, [p_echo_request_1], self.pg1) |
| 2902 | |
| 2903 | VppIp6LinkLocalAddress(self, self.pg1, ll3).add_vpp_config() |
| 2904 | self.send_and_expect(self.pg1, [p_echo_request_3], self.pg1) |
| 2905 | |
| 2906 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 2907 | if __name__ == '__main__': |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 2908 | unittest.main(testRunner=VppTestRunner) |