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