Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 3 | import socket |
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 |
| 16 | from scapy.utils import inet_pton, inet_ntop |
| 17 | from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \ |
| 18 | in6_mactoifaceid |
| 19 | from six import moves |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 20 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 21 | from framework import VppTestCase, VppTestRunner |
Paul Vinciguerra | e8fece8 | 2019-02-28 15:34:00 -0800 | [diff] [blame] | 22 | from util import ppp, ip6_normalize, mk_ll_addr |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 23 | from vpp_ip import DpoProto |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 24 | from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \ |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 25 | VppMRoutePath, MRouteItfFlags, MRouteEntryFlags, VppMplsIpBind, \ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 26 | VppMplsRoute, VppMplsTable, VppIpTable, FibPathType |
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 | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 30 | from ipaddress import IPv6Network, IPv4Network, 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): |
| 140 | tx_intf.add_stream(pkts) |
| 141 | self.pg_enable_capture(self.pg_interfaces) |
| 142 | self.pg_start() |
| 143 | rx = rx_intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 144 | |
| 145 | self.assertEqual(len(rx), 1) |
| 146 | rx = rx[0] |
| 147 | self.validate_ns(rx_intf, rx, tgt_ip) |
| 148 | |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 149 | def verify_ip(self, rx, smac, dmac, sip, dip): |
| 150 | ether = rx[Ether] |
| 151 | self.assertEqual(ether.dst, dmac) |
| 152 | self.assertEqual(ether.src, smac) |
| 153 | |
| 154 | ip = rx[IPv6] |
| 155 | self.assertEqual(ip.src, sip) |
| 156 | self.assertEqual(ip.dst, dip) |
| 157 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 158 | |
| 159 | class TestIPv6(TestIPv6ND): |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 160 | """ IPv6 Test Case """ |
| 161 | |
| 162 | @classmethod |
| 163 | def setUpClass(cls): |
| 164 | super(TestIPv6, cls).setUpClass() |
| 165 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 166 | @classmethod |
| 167 | def tearDownClass(cls): |
| 168 | super(TestIPv6, cls).tearDownClass() |
| 169 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 170 | def setUp(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 171 | """ |
| 172 | Perform test setup before test case. |
| 173 | |
| 174 | **Config:** |
| 175 | - create 3 pg interfaces |
| 176 | - untagged pg0 interface |
| 177 | - Dot1Q subinterface on pg1 |
| 178 | - Dot1AD subinterface on pg2 |
| 179 | - setup interfaces: |
| 180 | - put it into UP state |
| 181 | - set IPv6 addresses |
| 182 | - resolve neighbor address using NDP |
| 183 | - configure 200 fib entries |
| 184 | |
| 185 | :ivar list interfaces: pg interfaces and subinterfaces. |
| 186 | :ivar dict flows: IPv4 packet flows in test. |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 187 | |
| 188 | *TODO:* Create AD sub interface |
| 189 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 190 | super(TestIPv6, self).setUp() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 191 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 192 | # create 3 pg interfaces |
| 193 | self.create_pg_interfaces(range(3)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 194 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 195 | # create 2 subinterfaces for p1 and pg2 |
| 196 | self.sub_interfaces = [ |
| 197 | VppDot1QSubint(self, self.pg1, 100), |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 198 | VppDot1QSubint(self, self.pg2, 200) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 199 | # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 200 | ] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 201 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 202 | # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. |
| 203 | self.flows = dict() |
| 204 | self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] |
| 205 | self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] |
| 206 | self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 207 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 208 | # packet sizes |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 209 | self.pg_if_packet_sizes = [64, 1500, 9020] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 210 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 211 | self.interfaces = list(self.pg_interfaces) |
| 212 | self.interfaces.extend(self.sub_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 213 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 214 | # setup all interfaces |
| 215 | for i in self.interfaces: |
| 216 | i.admin_up() |
| 217 | i.config_ip6() |
| 218 | i.resolve_ndp() |
| 219 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 220 | def tearDown(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 221 | """Run standard test teardown and log ``show ip6 neighbors``.""" |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 222 | for i in self.interfaces: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 223 | i.unconfig_ip6() |
| 224 | i.ip6_disable() |
| 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 | """ |
| 242 | dst_if_idx = packet_size / 10 % 2 |
| 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 | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 580 | def validate_ra(self, intf, rx, dst_ip=None, mtu=9000, pi_opt=None): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 581 | if not dst_ip: |
| 582 | dst_ip = intf.remote_ip6 |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 583 | |
Neale Ranns | 5737d88 | 2017-02-03 06:14:49 -0800 | [diff] [blame] | 584 | # unicasted packets must come to the unicast mac |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 585 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 586 | |
| 587 | # and from the router's MAC |
| 588 | self.assertEqual(rx[Ether].src, intf.local_mac) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 589 | |
| 590 | # the rx'd RA should be addressed to the sender's source |
| 591 | self.assertTrue(rx.haslayer(ICMPv6ND_RA)) |
| 592 | self.assertEqual(in6_ptop(rx[IPv6].dst), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 593 | in6_ptop(dst_ip)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 594 | |
| 595 | # and come from the router's link local |
| 596 | self.assertTrue(in6_islladdr(rx[IPv6].src)) |
| 597 | self.assertEqual(in6_ptop(rx[IPv6].src), |
| 598 | in6_ptop(mk_ll_addr(intf.local_mac))) |
| 599 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 600 | # it should contain the links MTU |
| 601 | ra = rx[ICMPv6ND_RA] |
| 602 | self.assertEqual(ra[ICMPv6NDOptMTU].mtu, mtu) |
| 603 | |
| 604 | # it should contain the source's link layer address option |
| 605 | sll = ra[ICMPv6NDOptSrcLLAddr] |
| 606 | self.assertEqual(sll.lladdr, intf.local_mac) |
| 607 | |
| 608 | if not pi_opt: |
| 609 | # the RA should not contain prefix information |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 610 | self.assertFalse(ra.haslayer( |
| 611 | ICMPv6NDOptPrefixInfo)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 612 | else: |
| 613 | raos = rx.getlayer(ICMPv6NDOptPrefixInfo, 1) |
| 614 | |
| 615 | # the options are nested in the scapy packet in way that i cannot |
| 616 | # decipher how to decode. this 1st layer of option always returns |
| 617 | # nested classes, so a direct obj1=obj2 comparison always fails. |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 618 | # however, the getlayer(.., 2) does give one instance. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 619 | # so we cheat here and construct a new opt instance for comparison |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 620 | rd = ICMPv6NDOptPrefixInfo( |
| 621 | prefixlen=raos.prefixlen, |
| 622 | prefix=raos.prefix, |
| 623 | L=raos.L, |
| 624 | A=raos.A) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 625 | if type(pi_opt) is list: |
| 626 | for ii in range(len(pi_opt)): |
| 627 | self.assertEqual(pi_opt[ii], rd) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 628 | rd = rx.getlayer( |
| 629 | ICMPv6NDOptPrefixInfo, ii + 2) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 630 | else: |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 631 | self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s' |
| 632 | % (pi_opt.show(dump=True), |
| 633 | raos.show(dump=True))) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 634 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 635 | def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None, |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 636 | filter_out_fn=is_ipv6_misc, |
| 637 | opt=None): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 638 | intf.add_stream(pkts) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 639 | self.pg_enable_capture(self.pg_interfaces) |
| 640 | self.pg_start() |
| 641 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 642 | |
| 643 | self.assertEqual(len(rx), 1) |
| 644 | rx = rx[0] |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 645 | self.validate_ra(intf, rx, dst_ip, pi_opt=opt) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 646 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 647 | def test_rs(self): |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 648 | """ IPv6 Router Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 649 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 650 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 651 | """ |
| 652 | |
| 653 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 654 | # Before we begin change the IPv6 RA responses to use the unicast |
| 655 | # address - that way we will not confuse them with the periodic |
| 656 | # RAs which go to the mcast address |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 657 | # Sit and wait for the first periodic RA. |
| 658 | # |
| 659 | # TODO |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 660 | # |
| 661 | self.pg0.ip6_ra_config(send_unicast=1) |
| 662 | |
| 663 | # |
| 664 | # An RS from a link source address |
| 665 | # - expect an RA in return |
| 666 | # |
| 667 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 668 | IPv6( |
| 669 | dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 670 | ICMPv6ND_RS()) |
| 671 | pkts = [p] |
| 672 | self.send_and_expect_ra(self.pg0, pkts, "Genuine RS") |
| 673 | |
| 674 | # |
| 675 | # For the next RS sent the RA should be rate limited |
| 676 | # |
| 677 | self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited") |
| 678 | |
| 679 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 680 | # When we reconfigure the IPv6 RA config, |
| 681 | # we reset the RA rate limiting, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 682 | # so we need to do this before each test below so as not to drop |
| 683 | # packets for rate limiting reasons. Test this works here. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 684 | # |
| 685 | self.pg0.ip6_ra_config(send_unicast=1) |
| 686 | self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS") |
| 687 | |
| 688 | # |
| 689 | # An RS sent from a non-link local source |
| 690 | # |
| 691 | self.pg0.ip6_ra_config(send_unicast=1) |
| 692 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 693 | IPv6(dst=self.pg0.local_ip6, |
| 694 | src="2002::ffff") / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 695 | ICMPv6ND_RS()) |
| 696 | pkts = [p] |
| 697 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 698 | "RS from non-link source") |
| 699 | |
| 700 | # |
| 701 | # Source an RS from a link local address |
| 702 | # |
| 703 | self.pg0.ip6_ra_config(send_unicast=1) |
| 704 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 705 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 706 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 707 | ICMPv6ND_RS()) |
| 708 | pkts = [p] |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 709 | self.send_and_expect_ra(self.pg0, pkts, |
| 710 | "RS sourced from link-local", |
| 711 | dst_ip=ll) |
| 712 | |
| 713 | # |
| 714 | # Send the RS multicast |
| 715 | # |
| 716 | self.pg0.ip6_ra_config(send_unicast=1) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 717 | dmac = in6_getnsmac(inet_pton(AF_INET6, "ff02::2")) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 718 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 719 | p = (Ether(dst=dmac, src=self.pg0.remote_mac) / |
| 720 | IPv6(dst="ff02::2", src=ll) / |
| 721 | ICMPv6ND_RS()) |
| 722 | pkts = [p] |
| 723 | self.send_and_expect_ra(self.pg0, pkts, |
| 724 | "RS sourced from link-local", |
| 725 | dst_ip=ll) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 726 | |
| 727 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 728 | # Source from the unspecified address ::. This happens when the RS |
| 729 | # is sent before the host has a configured address/sub-net, |
| 730 | # i.e. auto-config. Since the sender has no IP address, the reply |
| 731 | # comes back mcast - so the capture needs to not filter this. |
| 732 | # If we happen to pick up the periodic RA at this point then so be it, |
| 733 | # it's not an error. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 734 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 735 | self.pg0.ip6_ra_config(send_unicast=1, suppress=1) |
| 736 | p = (Ether(dst=dmac, src=self.pg0.remote_mac) / |
| 737 | IPv6(dst="ff02::2", src="::") / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 738 | ICMPv6ND_RS()) |
| 739 | pkts = [p] |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 740 | self.send_and_expect_ra(self.pg0, pkts, |
| 741 | "RS sourced from unspecified", |
| 742 | dst_ip="ff02::1", |
| 743 | filter_out_fn=None) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 744 | |
| 745 | # |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 746 | # Configure The RA to announce the links prefix |
| 747 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 748 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 749 | self.pg0.local_ip6_prefix_len)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 750 | |
| 751 | # |
| 752 | # RAs should now contain the prefix information option |
| 753 | # |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 754 | opt = ICMPv6NDOptPrefixInfo( |
| 755 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 756 | prefix=self.pg0.local_ip6, |
| 757 | L=1, |
| 758 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 759 | |
| 760 | self.pg0.ip6_ra_config(send_unicast=1) |
| 761 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 762 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 763 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 764 | ICMPv6ND_RS()) |
| 765 | self.send_and_expect_ra(self.pg0, p, |
| 766 | "RA with prefix-info", |
| 767 | dst_ip=ll, |
| 768 | opt=opt) |
| 769 | |
| 770 | # |
| 771 | # Change the prefix info to not off-link |
| 772 | # L-flag is clear |
| 773 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 774 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 775 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 776 | off_link=1) |
| 777 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 778 | opt = ICMPv6NDOptPrefixInfo( |
| 779 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 780 | prefix=self.pg0.local_ip6, |
| 781 | L=0, |
| 782 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 783 | |
| 784 | self.pg0.ip6_ra_config(send_unicast=1) |
| 785 | self.send_and_expect_ra(self.pg0, p, |
| 786 | "RA with Prefix info with L-flag=0", |
| 787 | dst_ip=ll, |
| 788 | opt=opt) |
| 789 | |
| 790 | # |
| 791 | # Change the prefix info to not off-link, no-autoconfig |
| 792 | # L and A flag are clear in the advert |
| 793 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 794 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 795 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 796 | off_link=1, |
| 797 | no_autoconfig=1) |
| 798 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 799 | opt = ICMPv6NDOptPrefixInfo( |
| 800 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 801 | prefix=self.pg0.local_ip6, |
| 802 | L=0, |
| 803 | A=0) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 804 | |
| 805 | self.pg0.ip6_ra_config(send_unicast=1) |
| 806 | self.send_and_expect_ra(self.pg0, p, |
| 807 | "RA with Prefix info with A & L-flag=0", |
| 808 | dst_ip=ll, |
| 809 | opt=opt) |
| 810 | |
| 811 | # |
| 812 | # Change the flag settings back to the defaults |
| 813 | # L and A flag are set in the advert |
| 814 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 815 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 816 | self.pg0.local_ip6_prefix_len)) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 817 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 818 | opt = ICMPv6NDOptPrefixInfo( |
| 819 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 820 | prefix=self.pg0.local_ip6, |
| 821 | L=1, |
| 822 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 823 | |
| 824 | self.pg0.ip6_ra_config(send_unicast=1) |
| 825 | self.send_and_expect_ra(self.pg0, p, |
| 826 | "RA with Prefix info", |
| 827 | dst_ip=ll, |
| 828 | opt=opt) |
| 829 | |
| 830 | # |
| 831 | # Change the prefix info to not off-link, no-autoconfig |
| 832 | # L and A flag are clear in the advert |
| 833 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 834 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 835 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 836 | off_link=1, |
| 837 | no_autoconfig=1) |
| 838 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 839 | opt = ICMPv6NDOptPrefixInfo( |
| 840 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 841 | prefix=self.pg0.local_ip6, |
| 842 | L=0, |
| 843 | A=0) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 844 | |
| 845 | self.pg0.ip6_ra_config(send_unicast=1) |
| 846 | self.send_and_expect_ra(self.pg0, p, |
| 847 | "RA with Prefix info with A & L-flag=0", |
| 848 | dst_ip=ll, |
| 849 | opt=opt) |
| 850 | |
| 851 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 852 | # Use the reset to defaults option to revert to defaults |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 853 | # L and A flag are clear in the advert |
| 854 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 855 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 856 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 857 | use_default=1) |
| 858 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 859 | opt = ICMPv6NDOptPrefixInfo( |
| 860 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 861 | prefix=self.pg0.local_ip6, |
| 862 | L=1, |
| 863 | A=1) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 864 | |
| 865 | self.pg0.ip6_ra_config(send_unicast=1) |
| 866 | self.send_and_expect_ra(self.pg0, p, |
| 867 | "RA with Prefix reverted to defaults", |
| 868 | dst_ip=ll, |
| 869 | opt=opt) |
| 870 | |
| 871 | # |
| 872 | # Advertise Another prefix. With no L-flag/A-flag |
| 873 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 874 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6, |
| 875 | self.pg1.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 876 | off_link=1, |
| 877 | no_autoconfig=1) |
| 878 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 879 | opt = [ICMPv6NDOptPrefixInfo( |
| 880 | prefixlen=self.pg0.local_ip6_prefix_len, |
| 881 | prefix=self.pg0.local_ip6, |
| 882 | L=1, |
| 883 | A=1), |
| 884 | ICMPv6NDOptPrefixInfo( |
| 885 | prefixlen=self.pg1.local_ip6_prefix_len, |
| 886 | prefix=self.pg1.local_ip6, |
| 887 | L=0, |
| 888 | A=0)] |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 889 | |
| 890 | self.pg0.ip6_ra_config(send_unicast=1) |
| 891 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 892 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 893 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 894 | ICMPv6ND_RS()) |
| 895 | self.send_and_expect_ra(self.pg0, p, |
| 896 | "RA with multiple Prefix infos", |
| 897 | dst_ip=ll, |
| 898 | opt=opt) |
| 899 | |
| 900 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 901 | # Remove the first prefix-info - expect the second is still in the |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 902 | # advert |
| 903 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 904 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, |
| 905 | self.pg0.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 906 | is_no=1) |
| 907 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 908 | opt = ICMPv6NDOptPrefixInfo( |
| 909 | prefixlen=self.pg1.local_ip6_prefix_len, |
| 910 | prefix=self.pg1.local_ip6, |
| 911 | L=0, |
| 912 | A=0) |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 913 | |
| 914 | self.pg0.ip6_ra_config(send_unicast=1) |
| 915 | self.send_and_expect_ra(self.pg0, p, |
| 916 | "RA with Prefix reverted to defaults", |
| 917 | dst_ip=ll, |
| 918 | opt=opt) |
| 919 | |
| 920 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 921 | # Remove the second prefix-info - expect no prefix-info in the adverts |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 922 | # |
Paul Vinciguerra | ab05508 | 2019-06-06 14:07:55 -0400 | [diff] [blame^] | 923 | self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6, |
| 924 | self.pg1.local_ip6_prefix_len), |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 925 | is_no=1) |
| 926 | |
| 927 | self.pg0.ip6_ra_config(send_unicast=1) |
| 928 | self.send_and_expect_ra(self.pg0, p, |
| 929 | "RA with Prefix reverted to defaults", |
| 930 | dst_ip=ll) |
| 931 | |
| 932 | # |
Neale Ranns | 5737d88 | 2017-02-03 06:14:49 -0800 | [diff] [blame] | 933 | # Reset the periodic advertisements back to default values |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 934 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 935 | self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 936 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 937 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 938 | class TestICMPv6Echo(VppTestCase): |
| 939 | """ ICMPv6 Echo Test Case """ |
| 940 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 941 | @classmethod |
| 942 | def setUpClass(cls): |
| 943 | super(TestICMPv6Echo, cls).setUpClass() |
| 944 | |
| 945 | @classmethod |
| 946 | def tearDownClass(cls): |
| 947 | super(TestICMPv6Echo, cls).tearDownClass() |
| 948 | |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 949 | def setUp(self): |
| 950 | super(TestICMPv6Echo, self).setUp() |
| 951 | |
| 952 | # create 1 pg interface |
| 953 | self.create_pg_interfaces(range(1)) |
| 954 | |
| 955 | for i in self.pg_interfaces: |
| 956 | i.admin_up() |
| 957 | i.config_ip6() |
| 958 | i.resolve_ndp() |
| 959 | |
| 960 | def tearDown(self): |
| 961 | super(TestICMPv6Echo, self).tearDown() |
| 962 | for i in self.pg_interfaces: |
| 963 | i.unconfig_ip6() |
| 964 | i.ip6_disable() |
| 965 | i.admin_down() |
| 966 | |
| 967 | def test_icmpv6_echo(self): |
| 968 | """ VPP replies to ICMPv6 Echo Request |
| 969 | |
| 970 | Test scenario: |
| 971 | |
| 972 | - Receive ICMPv6 Echo Request message on pg0 interface. |
| 973 | - Check outgoing ICMPv6 Echo Reply message on pg0 interface. |
| 974 | """ |
| 975 | |
| 976 | icmpv6_id = 0xb |
| 977 | icmpv6_seq = 5 |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 978 | icmpv6_data = b'\x0a' * 18 |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 979 | p_echo_request = (Ether(src=self.pg0.remote_mac, |
| 980 | dst=self.pg0.local_mac) / |
| 981 | IPv6(src=self.pg0.remote_ip6, |
| 982 | dst=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 983 | ICMPv6EchoRequest( |
| 984 | id=icmpv6_id, |
| 985 | seq=icmpv6_seq, |
| 986 | data=icmpv6_data)) |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 987 | |
| 988 | self.pg0.add_stream(p_echo_request) |
| 989 | self.pg_enable_capture(self.pg_interfaces) |
| 990 | self.pg_start() |
| 991 | |
| 992 | rx = self.pg0.get_capture(1) |
| 993 | rx = rx[0] |
| 994 | ether = rx[Ether] |
| 995 | ipv6 = rx[IPv6] |
| 996 | icmpv6 = rx[ICMPv6EchoReply] |
| 997 | |
| 998 | self.assertEqual(ether.src, self.pg0.local_mac) |
| 999 | self.assertEqual(ether.dst, self.pg0.remote_mac) |
| 1000 | |
| 1001 | self.assertEqual(ipv6.src, self.pg0.local_ip6) |
| 1002 | self.assertEqual(ipv6.dst, self.pg0.remote_ip6) |
| 1003 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1004 | self.assertEqual( |
| 1005 | icmp6types[icmpv6.type], "Echo Reply") |
Jan Gelety | e6c78ee | 2018-06-26 12:24:03 +0200 | [diff] [blame] | 1006 | self.assertEqual(icmpv6.id, icmpv6_id) |
| 1007 | self.assertEqual(icmpv6.seq, icmpv6_seq) |
| 1008 | self.assertEqual(icmpv6.data, icmpv6_data) |
| 1009 | |
| 1010 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1011 | class TestIPv6RD(TestIPv6ND): |
| 1012 | """ IPv6 Router Discovery Test Case """ |
| 1013 | |
| 1014 | @classmethod |
| 1015 | def setUpClass(cls): |
| 1016 | super(TestIPv6RD, cls).setUpClass() |
| 1017 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1018 | @classmethod |
| 1019 | def tearDownClass(cls): |
| 1020 | super(TestIPv6RD, cls).tearDownClass() |
| 1021 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1022 | def setUp(self): |
| 1023 | super(TestIPv6RD, self).setUp() |
| 1024 | |
| 1025 | # create 2 pg interfaces |
| 1026 | self.create_pg_interfaces(range(2)) |
| 1027 | |
| 1028 | self.interfaces = list(self.pg_interfaces) |
| 1029 | |
| 1030 | # setup all interfaces |
| 1031 | for i in self.interfaces: |
| 1032 | i.admin_up() |
| 1033 | i.config_ip6() |
| 1034 | |
| 1035 | def tearDown(self): |
Neale Ranns | 744902e | 2017-08-14 10:35:44 -0700 | [diff] [blame] | 1036 | for i in self.interfaces: |
| 1037 | i.unconfig_ip6() |
| 1038 | i.admin_down() |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1039 | super(TestIPv6RD, self).tearDown() |
| 1040 | |
| 1041 | def test_rd_send_router_solicitation(self): |
| 1042 | """ Verify router solicitation packets """ |
| 1043 | |
| 1044 | count = 2 |
| 1045 | self.pg_enable_capture(self.pg_interfaces) |
| 1046 | self.pg_start() |
| 1047 | self.vapi.ip6nd_send_router_solicitation(self.pg1.sw_if_index, |
| 1048 | mrc=count) |
| 1049 | rx_list = self.pg1.get_capture(count, timeout=3) |
| 1050 | self.assertEqual(len(rx_list), count) |
| 1051 | for packet in rx_list: |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1052 | self.assertEqual(packet.haslayer(IPv6), 1) |
| 1053 | self.assertEqual(packet[IPv6].haslayer( |
| 1054 | ICMPv6ND_RS), 1) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1055 | dst = ip6_normalize(packet[IPv6].dst) |
| 1056 | dst2 = ip6_normalize("ff02::2") |
| 1057 | self.assert_equal(dst, dst2) |
| 1058 | src = ip6_normalize(packet[IPv6].src) |
| 1059 | src2 = ip6_normalize(self.pg1.local_ip6_ll) |
| 1060 | self.assert_equal(src, src2) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1061 | self.assertTrue( |
| 1062 | bool(packet[ICMPv6ND_RS].haslayer( |
| 1063 | ICMPv6NDOptSrcLLAddr))) |
| 1064 | self.assert_equal( |
| 1065 | packet[ICMPv6NDOptSrcLLAddr].lladdr, |
| 1066 | self.pg1.local_mac) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1067 | |
| 1068 | def verify_prefix_info(self, reported_prefix, prefix_option): |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1069 | prefix = IPv6Network( |
Paul Vinciguerra | 1e18eb2 | 2018-11-25 16:09:26 -0800 | [diff] [blame] | 1070 | text_type(prefix_option.getfieldval("prefix") + |
| 1071 | "/" + |
| 1072 | text_type(prefix_option.getfieldval("prefixlen"))), |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1073 | strict=False) |
| 1074 | self.assert_equal(reported_prefix.prefix.network_address, |
| 1075 | prefix.network_address) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1076 | L = prefix_option.getfieldval("L") |
| 1077 | A = prefix_option.getfieldval("A") |
| 1078 | option_flags = (L << 7) | (A << 6) |
| 1079 | self.assert_equal(reported_prefix.flags, option_flags) |
| 1080 | self.assert_equal(reported_prefix.valid_time, |
| 1081 | prefix_option.getfieldval("validlifetime")) |
| 1082 | self.assert_equal(reported_prefix.preferred_time, |
| 1083 | prefix_option.getfieldval("preferredlifetime")) |
| 1084 | |
| 1085 | def test_rd_receive_router_advertisement(self): |
| 1086 | """ Verify events triggered by received RA packets """ |
| 1087 | |
| 1088 | self.vapi.want_ip6_ra_events() |
| 1089 | |
| 1090 | prefix_info_1 = ICMPv6NDOptPrefixInfo( |
| 1091 | prefix="1::2", |
| 1092 | prefixlen=50, |
| 1093 | validlifetime=200, |
| 1094 | preferredlifetime=500, |
| 1095 | L=1, |
| 1096 | A=1, |
| 1097 | ) |
| 1098 | |
| 1099 | prefix_info_2 = ICMPv6NDOptPrefixInfo( |
| 1100 | prefix="7::4", |
| 1101 | prefixlen=20, |
| 1102 | validlifetime=70, |
| 1103 | preferredlifetime=1000, |
| 1104 | L=1, |
| 1105 | A=0, |
| 1106 | ) |
| 1107 | |
| 1108 | p = (Ether(dst=self.pg1.local_mac, src=self.pg1.remote_mac) / |
| 1109 | IPv6(dst=self.pg1.local_ip6_ll, |
| 1110 | src=mk_ll_addr(self.pg1.remote_mac)) / |
| 1111 | ICMPv6ND_RA() / |
| 1112 | prefix_info_1 / |
| 1113 | prefix_info_2) |
| 1114 | self.pg1.add_stream([p]) |
| 1115 | self.pg_start() |
| 1116 | |
| 1117 | ev = self.vapi.wait_for_event(10, "ip6_ra_event") |
| 1118 | |
| 1119 | self.assert_equal(ev.current_hop_limit, 0) |
| 1120 | self.assert_equal(ev.flags, 8) |
| 1121 | self.assert_equal(ev.router_lifetime_in_sec, 1800) |
| 1122 | self.assert_equal(ev.neighbor_reachable_time_in_msec, 0) |
| 1123 | self.assert_equal( |
| 1124 | ev.time_in_msec_between_retransmitted_neighbor_solicitations, 0) |
| 1125 | |
| 1126 | self.assert_equal(ev.n_prefixes, 2) |
| 1127 | |
| 1128 | self.verify_prefix_info(ev.prefixes[0], prefix_info_1) |
| 1129 | self.verify_prefix_info(ev.prefixes[1], prefix_info_2) |
| 1130 | |
| 1131 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1132 | class TestIPv6RDControlPlane(TestIPv6ND): |
| 1133 | """ IPv6 Router Discovery Control Plane Test Case """ |
| 1134 | |
| 1135 | @classmethod |
| 1136 | def setUpClass(cls): |
| 1137 | super(TestIPv6RDControlPlane, cls).setUpClass() |
| 1138 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1139 | @classmethod |
| 1140 | def tearDownClass(cls): |
| 1141 | super(TestIPv6RDControlPlane, cls).tearDownClass() |
| 1142 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1143 | def setUp(self): |
| 1144 | super(TestIPv6RDControlPlane, self).setUp() |
| 1145 | |
| 1146 | # create 1 pg interface |
| 1147 | self.create_pg_interfaces(range(1)) |
| 1148 | |
| 1149 | self.interfaces = list(self.pg_interfaces) |
| 1150 | |
| 1151 | # setup all interfaces |
| 1152 | for i in self.interfaces: |
| 1153 | i.admin_up() |
| 1154 | i.config_ip6() |
| 1155 | |
| 1156 | def tearDown(self): |
| 1157 | super(TestIPv6RDControlPlane, self).tearDown() |
| 1158 | |
| 1159 | @staticmethod |
| 1160 | def create_ra_packet(pg, routerlifetime=None): |
| 1161 | src_ip = pg.remote_ip6_ll |
| 1162 | dst_ip = pg.local_ip6 |
| 1163 | if routerlifetime is not None: |
| 1164 | ra = ICMPv6ND_RA(routerlifetime=routerlifetime) |
| 1165 | else: |
| 1166 | ra = ICMPv6ND_RA() |
| 1167 | p = (Ether(dst=pg.local_mac, src=pg.remote_mac) / |
| 1168 | IPv6(dst=dst_ip, src=src_ip) / ra) |
| 1169 | return p |
| 1170 | |
| 1171 | @staticmethod |
| 1172 | def get_default_routes(fib): |
| 1173 | list = [] |
| 1174 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1175 | if entry.route.prefix.prefixlen == 0: |
| 1176 | for path in entry.route.paths: |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1177 | if path.sw_if_index != 0xFFFFFFFF: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1178 | defaut_route = {} |
| 1179 | defaut_route['sw_if_index'] = path.sw_if_index |
| 1180 | defaut_route['next_hop'] = path.nh.address.ip6 |
| 1181 | list.append(defaut_route) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1182 | return list |
| 1183 | |
| 1184 | @staticmethod |
| 1185 | def get_interface_addresses(fib, pg): |
| 1186 | list = [] |
| 1187 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1188 | if entry.route.prefix.prefixlen == 128: |
| 1189 | path = entry.route.paths[0] |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1190 | if path.sw_if_index == pg.sw_if_index: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1191 | list.append(str(entry.route.prefix.network_address)) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1192 | return list |
| 1193 | |
| 1194 | def test_all(self): |
| 1195 | """ Test handling of SLAAC addresses and default routes """ |
| 1196 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1197 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1198 | default_routes = self.get_default_routes(fib) |
| 1199 | initial_addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1200 | self.assertEqual(default_routes, []) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1201 | router_address = IPv6Address(text_type(self.pg0.remote_ip6_ll)) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1202 | |
| 1203 | self.vapi.ip6_nd_address_autoconfig(self.pg0.sw_if_index, 1, 1) |
| 1204 | |
| 1205 | self.sleep(0.1) |
| 1206 | |
| 1207 | # send RA |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1208 | packet = (self.create_ra_packet( |
| 1209 | self.pg0) / ICMPv6NDOptPrefixInfo( |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1210 | prefix="1::", |
| 1211 | prefixlen=64, |
| 1212 | validlifetime=2, |
| 1213 | preferredlifetime=2, |
| 1214 | L=1, |
| 1215 | A=1, |
| 1216 | ) / ICMPv6NDOptPrefixInfo( |
| 1217 | prefix="7::", |
| 1218 | prefixlen=20, |
| 1219 | validlifetime=1500, |
| 1220 | preferredlifetime=1000, |
| 1221 | L=1, |
| 1222 | A=0, |
| 1223 | )) |
| 1224 | self.pg0.add_stream([packet]) |
| 1225 | self.pg_start() |
| 1226 | |
| 1227 | self.sleep(0.1) |
| 1228 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1229 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1230 | |
| 1231 | # check FIB for new address |
| 1232 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1233 | new_addresses = addresses.difference(initial_addresses) |
| 1234 | self.assertEqual(len(new_addresses), 1) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1235 | prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)), |
| 1236 | strict=False) |
| 1237 | self.assertEqual(prefix, IPv6Network(text_type('1::/20'))) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1238 | |
| 1239 | # check FIB for new default route |
| 1240 | default_routes = self.get_default_routes(fib) |
| 1241 | self.assertEqual(len(default_routes), 1) |
| 1242 | dr = default_routes[0] |
| 1243 | self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index) |
| 1244 | self.assertEqual(dr['next_hop'], router_address) |
| 1245 | |
| 1246 | # send RA to delete default route |
| 1247 | packet = self.create_ra_packet(self.pg0, routerlifetime=0) |
| 1248 | self.pg0.add_stream([packet]) |
| 1249 | self.pg_start() |
| 1250 | |
| 1251 | self.sleep(0.1) |
| 1252 | |
| 1253 | # check that default route is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1254 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1255 | default_routes = self.get_default_routes(fib) |
| 1256 | self.assertEqual(len(default_routes), 0) |
| 1257 | |
| 1258 | self.sleep(0.1) |
| 1259 | |
| 1260 | # send RA |
| 1261 | packet = self.create_ra_packet(self.pg0) |
| 1262 | self.pg0.add_stream([packet]) |
| 1263 | self.pg_start() |
| 1264 | |
| 1265 | self.sleep(0.1) |
| 1266 | |
| 1267 | # check FIB for new default route |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1268 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1269 | default_routes = self.get_default_routes(fib) |
| 1270 | self.assertEqual(len(default_routes), 1) |
| 1271 | dr = default_routes[0] |
| 1272 | self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index) |
| 1273 | self.assertEqual(dr['next_hop'], router_address) |
| 1274 | |
| 1275 | # send RA, updating router lifetime to 1s |
| 1276 | packet = self.create_ra_packet(self.pg0, 1) |
| 1277 | self.pg0.add_stream([packet]) |
| 1278 | self.pg_start() |
| 1279 | |
| 1280 | self.sleep(0.1) |
| 1281 | |
| 1282 | # check that default route still exists |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1283 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1284 | default_routes = self.get_default_routes(fib) |
| 1285 | self.assertEqual(len(default_routes), 1) |
| 1286 | dr = default_routes[0] |
| 1287 | self.assertEqual(dr['sw_if_index'], self.pg0.sw_if_index) |
| 1288 | self.assertEqual(dr['next_hop'], router_address) |
| 1289 | |
| 1290 | self.sleep(1) |
| 1291 | |
| 1292 | # check that default route is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1293 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1294 | default_routes = self.get_default_routes(fib) |
| 1295 | self.assertEqual(len(default_routes), 0) |
| 1296 | |
| 1297 | # check FIB still contains the SLAAC address |
| 1298 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1299 | new_addresses = addresses.difference(initial_addresses) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1300 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1301 | self.assertEqual(len(new_addresses), 1) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1302 | prefix = IPv6Network(text_type("%s/%d" % (list(new_addresses)[0], 20)), |
| 1303 | strict=False) |
| 1304 | self.assertEqual(prefix, IPv6Network(text_type('1::/20'))) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1305 | |
| 1306 | self.sleep(1) |
| 1307 | |
| 1308 | # check that SLAAC address is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1309 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 1310 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 1311 | new_addresses = addresses.difference(initial_addresses) |
| 1312 | self.assertEqual(len(new_addresses), 0) |
| 1313 | |
| 1314 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1315 | class IPv6NDProxyTest(TestIPv6ND): |
| 1316 | """ IPv6 ND ProxyTest Case """ |
| 1317 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1318 | @classmethod |
| 1319 | def setUpClass(cls): |
| 1320 | super(IPv6NDProxyTest, cls).setUpClass() |
| 1321 | |
| 1322 | @classmethod |
| 1323 | def tearDownClass(cls): |
| 1324 | super(IPv6NDProxyTest, cls).tearDownClass() |
| 1325 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1326 | def setUp(self): |
| 1327 | super(IPv6NDProxyTest, self).setUp() |
| 1328 | |
| 1329 | # create 3 pg interfaces |
| 1330 | self.create_pg_interfaces(range(3)) |
| 1331 | |
| 1332 | # pg0 is the master interface, with the configured subnet |
| 1333 | self.pg0.admin_up() |
| 1334 | self.pg0.config_ip6() |
| 1335 | self.pg0.resolve_ndp() |
| 1336 | |
| 1337 | self.pg1.ip6_enable() |
| 1338 | self.pg2.ip6_enable() |
| 1339 | |
| 1340 | def tearDown(self): |
| 1341 | super(IPv6NDProxyTest, self).tearDown() |
| 1342 | |
| 1343 | def test_nd_proxy(self): |
| 1344 | """ IPv6 Proxy ND """ |
| 1345 | |
| 1346 | # |
| 1347 | # Generate some hosts in the subnet that we are proxying |
| 1348 | # |
| 1349 | self.pg0.generate_remote_hosts(8) |
| 1350 | |
| 1351 | nsma = in6_getnsma(inet_pton(AF_INET6, self.pg0.local_ip6)) |
| 1352 | d = inet_ntop(AF_INET6, nsma) |
| 1353 | |
| 1354 | # |
| 1355 | # Send an NS for one of those remote hosts on one of the proxy links |
| 1356 | # expect no response since it's from an address that is not |
| 1357 | # on the link that has the prefix configured |
| 1358 | # |
| 1359 | ns_pg1 = (Ether(dst=in6_getnsmac(nsma), src=self.pg1.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1360 | IPv6(dst=d, |
| 1361 | src=self.pg0._remote_hosts[2].ip6) / |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1362 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1363 | ICMPv6NDOptSrcLLAddr( |
| 1364 | lladdr=self.pg0._remote_hosts[2].mac)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1365 | |
| 1366 | self.send_and_assert_no_replies(self.pg1, ns_pg1, "Off link NS") |
| 1367 | |
| 1368 | # |
| 1369 | # Add proxy support for the host |
| 1370 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1371 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1372 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), |
| 1373 | sw_if_index=self.pg1.sw_if_index) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1374 | |
| 1375 | # |
| 1376 | # try that NS again. this time we expect an NA back |
| 1377 | # |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1378 | self.send_and_expect_na(self.pg1, ns_pg1, |
| 1379 | "NS to proxy entry", |
| 1380 | dst_ip=self.pg0._remote_hosts[2].ip6, |
| 1381 | tgt_ip=self.pg0.local_ip6) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1382 | |
| 1383 | # |
| 1384 | # ... and that we have an entry in the ND cache |
| 1385 | # |
| 1386 | self.assertTrue(find_nbr(self, |
| 1387 | self.pg1.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1388 | self.pg0._remote_hosts[2].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1389 | |
| 1390 | # |
| 1391 | # ... and we can route traffic to it |
| 1392 | # |
| 1393 | t = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 1394 | IPv6(dst=self.pg0._remote_hosts[2].ip6, |
| 1395 | src=self.pg0.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1396 | inet6.UDP(sport=10000, dport=20000) / |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1397 | Raw('\xa5' * 100)) |
| 1398 | |
| 1399 | self.pg0.add_stream(t) |
| 1400 | self.pg_enable_capture(self.pg_interfaces) |
| 1401 | self.pg_start() |
| 1402 | rx = self.pg1.get_capture(1) |
| 1403 | rx = rx[0] |
| 1404 | |
| 1405 | self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) |
| 1406 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1407 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1408 | self.assertEqual(rx[IPv6].src, |
| 1409 | t[IPv6].src) |
| 1410 | self.assertEqual(rx[IPv6].dst, |
| 1411 | t[IPv6].dst) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1412 | |
| 1413 | # |
| 1414 | # Test we proxy for the host on the main interface |
| 1415 | # |
| 1416 | ns_pg0 = (Ether(dst=in6_getnsmac(nsma), src=self.pg0.remote_mac) / |
| 1417 | IPv6(dst=d, src=self.pg0.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1418 | ICMPv6ND_NS( |
| 1419 | tgt=self.pg0._remote_hosts[2].ip6) / |
| 1420 | ICMPv6NDOptSrcLLAddr( |
| 1421 | lladdr=self.pg0.remote_mac)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1422 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1423 | self.send_and_expect_na(self.pg0, ns_pg0, |
| 1424 | "NS to proxy entry on main", |
| 1425 | tgt_ip=self.pg0._remote_hosts[2].ip6, |
| 1426 | dst_ip=self.pg0.remote_ip6) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1427 | |
| 1428 | # |
| 1429 | # Setup and resolve proxy for another host on another interface |
| 1430 | # |
| 1431 | ns_pg2 = (Ether(dst=in6_getnsmac(nsma), src=self.pg2.remote_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1432 | IPv6(dst=d, |
| 1433 | src=self.pg0._remote_hosts[3].ip6) / |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1434 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1435 | ICMPv6NDOptSrcLLAddr( |
| 1436 | lladdr=self.pg0._remote_hosts[2].mac)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1437 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1438 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1439 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), |
| 1440 | sw_if_index=self.pg2.sw_if_index) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1441 | |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1442 | self.send_and_expect_na(self.pg2, ns_pg2, |
| 1443 | "NS to proxy entry other interface", |
| 1444 | dst_ip=self.pg0._remote_hosts[3].ip6, |
| 1445 | tgt_ip=self.pg0.local_ip6) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1446 | |
| 1447 | self.assertTrue(find_nbr(self, |
| 1448 | self.pg2.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1449 | self.pg0._remote_hosts[3].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1450 | |
| 1451 | # |
| 1452 | # hosts can communicate. pg2->pg1 |
| 1453 | # |
| 1454 | t2 = (Ether(dst=self.pg2.local_mac, |
| 1455 | src=self.pg0.remote_hosts[3].mac) / |
| 1456 | IPv6(dst=self.pg0._remote_hosts[2].ip6, |
| 1457 | src=self.pg0._remote_hosts[3].ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1458 | inet6.UDP(sport=10000, dport=20000) / |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1459 | Raw('\xa5' * 100)) |
| 1460 | |
| 1461 | self.pg2.add_stream(t2) |
| 1462 | self.pg_enable_capture(self.pg_interfaces) |
| 1463 | self.pg_start() |
| 1464 | rx = self.pg1.get_capture(1) |
| 1465 | rx = rx[0] |
| 1466 | |
| 1467 | self.assertEqual(rx[Ether].dst, self.pg0._remote_hosts[2].mac) |
| 1468 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 1469 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1470 | self.assertEqual(rx[IPv6].src, |
| 1471 | t2[IPv6].src) |
| 1472 | self.assertEqual(rx[IPv6].dst, |
| 1473 | t2[IPv6].dst) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1474 | |
| 1475 | # |
| 1476 | # remove the proxy configs |
| 1477 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1478 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1479 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[2].ip6), |
| 1480 | sw_if_index=self.pg1.sw_if_index, is_del=1) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1481 | self.vapi.ip6nd_proxy_add_del( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1482 | ip=inet_pton(AF_INET6, self.pg0._remote_hosts[3].ip6), |
| 1483 | sw_if_index=self.pg2.sw_if_index, is_del=1) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1484 | |
| 1485 | self.assertFalse(find_nbr(self, |
| 1486 | self.pg2.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1487 | self.pg0._remote_hosts[3].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1488 | self.assertFalse(find_nbr(self, |
| 1489 | self.pg1.sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1490 | self.pg0._remote_hosts[2].ip6)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1491 | |
| 1492 | # |
| 1493 | # no longer proxy-ing... |
| 1494 | # |
| 1495 | self.send_and_assert_no_replies(self.pg0, ns_pg0, "Proxy unconfigured") |
| 1496 | self.send_and_assert_no_replies(self.pg1, ns_pg1, "Proxy unconfigured") |
| 1497 | self.send_and_assert_no_replies(self.pg2, ns_pg2, "Proxy unconfigured") |
| 1498 | |
| 1499 | # |
| 1500 | # no longer forwarding. traffic generates NS out of the glean/main |
| 1501 | # interface |
| 1502 | # |
| 1503 | self.pg2.add_stream(t2) |
| 1504 | self.pg_enable_capture(self.pg_interfaces) |
| 1505 | self.pg_start() |
| 1506 | |
| 1507 | rx = self.pg0.get_capture(1) |
| 1508 | |
| 1509 | self.assertTrue(rx[0].haslayer(ICMPv6ND_NS)) |
| 1510 | |
| 1511 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1512 | class TestIPNull(VppTestCase): |
| 1513 | """ IPv6 routes via NULL """ |
| 1514 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1515 | @classmethod |
| 1516 | def setUpClass(cls): |
| 1517 | super(TestIPNull, cls).setUpClass() |
| 1518 | |
| 1519 | @classmethod |
| 1520 | def tearDownClass(cls): |
| 1521 | super(TestIPNull, cls).tearDownClass() |
| 1522 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1523 | def setUp(self): |
| 1524 | super(TestIPNull, self).setUp() |
| 1525 | |
| 1526 | # create 2 pg interfaces |
| 1527 | self.create_pg_interfaces(range(1)) |
| 1528 | |
| 1529 | for i in self.pg_interfaces: |
| 1530 | i.admin_up() |
| 1531 | i.config_ip6() |
| 1532 | i.resolve_ndp() |
| 1533 | |
| 1534 | def tearDown(self): |
| 1535 | super(TestIPNull, self).tearDown() |
| 1536 | for i in self.pg_interfaces: |
| 1537 | i.unconfig_ip6() |
| 1538 | i.admin_down() |
| 1539 | |
| 1540 | def test_ip_null(self): |
| 1541 | """ IP NULL route """ |
| 1542 | |
| 1543 | p = (Ether(src=self.pg0.remote_mac, |
| 1544 | dst=self.pg0.local_mac) / |
| 1545 | IPv6(src=self.pg0.remote_ip6, dst="2001::1") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1546 | inet6.UDP(sport=1234, dport=1234) / |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1547 | Raw('\xa5' * 100)) |
| 1548 | |
| 1549 | # |
| 1550 | # A route via IP NULL that will reply with ICMP unreachables |
| 1551 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1552 | ip_unreach = VppIpRoute( |
| 1553 | self, "2001::", 64, |
| 1554 | [VppRoutePath("::", 0xffffffff, |
| 1555 | type=FibPathType.FIB_PATH_TYPE_ICMP_UNREACH)]) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1556 | ip_unreach.add_vpp_config() |
| 1557 | |
| 1558 | self.pg0.add_stream(p) |
| 1559 | self.pg_enable_capture(self.pg_interfaces) |
| 1560 | self.pg_start() |
| 1561 | |
| 1562 | rx = self.pg0.get_capture(1) |
| 1563 | rx = rx[0] |
| 1564 | icmp = rx[ICMPv6DestUnreach] |
| 1565 | |
| 1566 | # 0 = "No route to destination" |
| 1567 | self.assertEqual(icmp.code, 0) |
| 1568 | |
| 1569 | # ICMP is rate limited. pause a bit |
| 1570 | self.sleep(1) |
| 1571 | |
| 1572 | # |
| 1573 | # A route via IP NULL that will reply with ICMP prohibited |
| 1574 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1575 | ip_prohibit = VppIpRoute( |
| 1576 | self, "2001::1", 128, |
| 1577 | [VppRoutePath("::", 0xffffffff, |
| 1578 | type=FibPathType.FIB_PATH_TYPE_ICMP_PROHIBIT)]) |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 1579 | ip_prohibit.add_vpp_config() |
| 1580 | |
| 1581 | self.pg0.add_stream(p) |
| 1582 | self.pg_enable_capture(self.pg_interfaces) |
| 1583 | self.pg_start() |
| 1584 | |
| 1585 | rx = self.pg0.get_capture(1) |
| 1586 | rx = rx[0] |
| 1587 | icmp = rx[ICMPv6DestUnreach] |
| 1588 | |
| 1589 | # 1 = "Communication with destination administratively prohibited" |
| 1590 | self.assertEqual(icmp.code, 1) |
| 1591 | |
| 1592 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1593 | class TestIPDisabled(VppTestCase): |
| 1594 | """ IPv6 disabled """ |
| 1595 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1596 | @classmethod |
| 1597 | def setUpClass(cls): |
| 1598 | super(TestIPDisabled, cls).setUpClass() |
| 1599 | |
| 1600 | @classmethod |
| 1601 | def tearDownClass(cls): |
| 1602 | super(TestIPDisabled, cls).tearDownClass() |
| 1603 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1604 | def setUp(self): |
| 1605 | super(TestIPDisabled, self).setUp() |
| 1606 | |
| 1607 | # create 2 pg interfaces |
| 1608 | self.create_pg_interfaces(range(2)) |
| 1609 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1610 | # PG0 is IP enabled |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1611 | self.pg0.admin_up() |
| 1612 | self.pg0.config_ip6() |
| 1613 | self.pg0.resolve_ndp() |
| 1614 | |
| 1615 | # PG 1 is not IP enabled |
| 1616 | self.pg1.admin_up() |
| 1617 | |
| 1618 | def tearDown(self): |
| 1619 | super(TestIPDisabled, self).tearDown() |
| 1620 | for i in self.pg_interfaces: |
| 1621 | i.unconfig_ip4() |
| 1622 | i.admin_down() |
| 1623 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1624 | def test_ip_disabled(self): |
| 1625 | """ IP Disabled """ |
| 1626 | |
| 1627 | # |
| 1628 | # An (S,G). |
| 1629 | # one accepting interface, pg0, 2 forwarding interfaces |
| 1630 | # |
| 1631 | route_ff_01 = VppIpMRoute( |
| 1632 | self, |
| 1633 | "::", |
| 1634 | "ffef::1", 128, |
| 1635 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
| 1636 | [VppMRoutePath(self.pg1.sw_if_index, |
| 1637 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 1638 | VppMRoutePath(self.pg0.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1639 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1640 | route_ff_01.add_vpp_config() |
| 1641 | |
| 1642 | pu = (Ether(src=self.pg1.remote_mac, |
| 1643 | dst=self.pg1.local_mac) / |
| 1644 | IPv6(src="2001::1", dst=self.pg0.remote_ip6) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1645 | inet6.UDP(sport=1234, dport=1234) / |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1646 | Raw('\xa5' * 100)) |
| 1647 | pm = (Ether(src=self.pg1.remote_mac, |
| 1648 | dst=self.pg1.local_mac) / |
| 1649 | IPv6(src="2001::1", dst="ffef::1") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1650 | inet6.UDP(sport=1234, dport=1234) / |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 1651 | Raw('\xa5' * 100)) |
| 1652 | |
| 1653 | # |
| 1654 | # PG1 does not forward IP traffic |
| 1655 | # |
| 1656 | self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") |
| 1657 | self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") |
| 1658 | |
| 1659 | # |
| 1660 | # IP enable PG1 |
| 1661 | # |
| 1662 | self.pg1.config_ip6() |
| 1663 | |
| 1664 | # |
| 1665 | # Now we get packets through |
| 1666 | # |
| 1667 | self.pg1.add_stream(pu) |
| 1668 | self.pg_enable_capture(self.pg_interfaces) |
| 1669 | self.pg_start() |
| 1670 | rx = self.pg0.get_capture(1) |
| 1671 | |
| 1672 | self.pg1.add_stream(pm) |
| 1673 | self.pg_enable_capture(self.pg_interfaces) |
| 1674 | self.pg_start() |
| 1675 | rx = self.pg0.get_capture(1) |
| 1676 | |
| 1677 | # |
| 1678 | # Disable PG1 |
| 1679 | # |
| 1680 | self.pg1.unconfig_ip6() |
| 1681 | |
| 1682 | # |
| 1683 | # PG1 does not forward IP traffic |
| 1684 | # |
| 1685 | self.send_and_assert_no_replies(self.pg1, pu, "IPv6 disabled") |
| 1686 | self.send_and_assert_no_replies(self.pg1, pm, "IPv6 disabled") |
| 1687 | |
| 1688 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1689 | class TestIP6LoadBalance(VppTestCase): |
| 1690 | """ IPv6 Load-Balancing """ |
| 1691 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1692 | @classmethod |
| 1693 | def setUpClass(cls): |
| 1694 | super(TestIP6LoadBalance, cls).setUpClass() |
| 1695 | |
| 1696 | @classmethod |
| 1697 | def tearDownClass(cls): |
| 1698 | super(TestIP6LoadBalance, cls).tearDownClass() |
| 1699 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1700 | def setUp(self): |
| 1701 | super(TestIP6LoadBalance, self).setUp() |
| 1702 | |
| 1703 | self.create_pg_interfaces(range(5)) |
| 1704 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1705 | mpls_tbl = VppMplsTable(self, 0) |
| 1706 | mpls_tbl.add_vpp_config() |
| 1707 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1708 | for i in self.pg_interfaces: |
| 1709 | i.admin_up() |
| 1710 | i.config_ip6() |
| 1711 | i.resolve_ndp() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1712 | i.enable_mpls() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1713 | |
| 1714 | def tearDown(self): |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1715 | for i in self.pg_interfaces: |
| 1716 | i.unconfig_ip6() |
| 1717 | i.admin_down() |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1718 | i.disable_mpls() |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1719 | super(TestIP6LoadBalance, self).tearDown() |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1720 | |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 1721 | def pg_send(self, input, pkts): |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 1722 | self.vapi.cli("clear trace") |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1723 | input.add_stream(pkts) |
| 1724 | self.pg_enable_capture(self.pg_interfaces) |
| 1725 | self.pg_start() |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 1726 | |
| 1727 | def send_and_expect_load_balancing(self, input, pkts, outputs): |
| 1728 | self.pg_send(input, pkts) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1729 | for oo in outputs: |
| 1730 | rx = oo._get_capture(1) |
| 1731 | self.assertNotEqual(0, len(rx)) |
| 1732 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1733 | def send_and_expect_one_itf(self, input, pkts, itf): |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 1734 | self.pg_send(input, pkts) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1735 | rx = itf.get_capture(len(pkts)) |
| 1736 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1737 | def test_ip6_load_balance(self): |
| 1738 | """ IPv6 Load-Balancing """ |
| 1739 | |
| 1740 | # |
| 1741 | # An array of packets that differ only in the destination port |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1742 | # - IP only |
| 1743 | # - MPLS EOS |
| 1744 | # - MPLS non-EOS |
| 1745 | # - MPLS non-EOS with an entropy label |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1746 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1747 | port_ip_pkts = [] |
| 1748 | port_mpls_pkts = [] |
| 1749 | port_mpls_neos_pkts = [] |
| 1750 | port_ent_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1751 | |
| 1752 | # |
| 1753 | # An array of packets that differ only in the source address |
| 1754 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1755 | src_ip_pkts = [] |
| 1756 | src_mpls_pkts = [] |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1757 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1758 | for ii in range(NUM_PKTS): |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1759 | port_ip_hdr = ( |
| 1760 | IPv6(dst="3000::1", src="3000:1::1") / |
| 1761 | inet6.UDP(sport=1234, dport=1234 + ii) / |
| 1762 | Raw('\xa5' * 100)) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1763 | port_ip_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1764 | dst=self.pg0.local_mac) / |
| 1765 | port_ip_hdr)) |
| 1766 | port_mpls_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1767 | dst=self.pg0.local_mac) / |
| 1768 | MPLS(label=66, ttl=2) / |
| 1769 | port_ip_hdr)) |
| 1770 | port_mpls_neos_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1771 | dst=self.pg0.local_mac) / |
| 1772 | MPLS(label=67, ttl=2) / |
| 1773 | MPLS(label=77, ttl=2) / |
| 1774 | port_ip_hdr)) |
| 1775 | port_ent_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1776 | dst=self.pg0.local_mac) / |
| 1777 | MPLS(label=67, ttl=2) / |
| 1778 | MPLS(label=14, ttl=2) / |
| 1779 | MPLS(label=999, ttl=2) / |
| 1780 | port_ip_hdr)) |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1781 | src_ip_hdr = ( |
| 1782 | IPv6(dst="3000::1", src="3000:1::%d" % ii) / |
| 1783 | inet6.UDP(sport=1234, dport=1234) / |
| 1784 | Raw('\xa5' * 100)) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1785 | src_ip_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1786 | dst=self.pg0.local_mac) / |
| 1787 | src_ip_hdr)) |
| 1788 | src_mpls_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1789 | dst=self.pg0.local_mac) / |
| 1790 | MPLS(label=66, ttl=2) / |
| 1791 | src_ip_hdr)) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1792 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1793 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1794 | # A route for the IP packets |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1795 | # |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1796 | route_3000_1 = VppIpRoute(self, "3000::1", 128, |
| 1797 | [VppRoutePath(self.pg1.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1798 | self.pg1.sw_if_index), |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1799 | VppRoutePath(self.pg2.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1800 | self.pg2.sw_if_index)]) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1801 | route_3000_1.add_vpp_config() |
| 1802 | |
| 1803 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1804 | # a local-label for the EOS packets |
| 1805 | # |
| 1806 | binding = VppMplsIpBind(self, 66, "3000::1", 128, is_ip6=1) |
| 1807 | binding.add_vpp_config() |
| 1808 | |
| 1809 | # |
| 1810 | # An MPLS route for the non-EOS packets |
| 1811 | # |
| 1812 | route_67 = VppMplsRoute(self, 67, 0, |
| 1813 | [VppRoutePath(self.pg1.remote_ip6, |
| 1814 | self.pg1.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1815 | labels=[67]), |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1816 | VppRoutePath(self.pg2.remote_ip6, |
| 1817 | self.pg2.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1818 | labels=[67])]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1819 | route_67.add_vpp_config() |
| 1820 | |
| 1821 | # |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1822 | # inject the packet on pg0 - expect load-balancing across the 2 paths |
| 1823 | # - since the default hash config is to use IP src,dst and port |
| 1824 | # src,dst |
| 1825 | # We are not going to ensure equal amounts of packets across each link, |
| 1826 | # since the hash algorithm is statistical and therefore this can never |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1827 | # be guaranteed. But with 64 different packets we do expect some |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1828 | # balancing. So instead just ensure there is traffic on each link. |
| 1829 | # |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1830 | self.send_and_expect_load_balancing(self.pg0, port_ip_pkts, |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1831 | [self.pg1, self.pg2]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1832 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1833 | [self.pg1, self.pg2]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1834 | self.send_and_expect_load_balancing(self.pg0, port_mpls_pkts, |
| 1835 | [self.pg1, self.pg2]) |
| 1836 | self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, |
| 1837 | [self.pg1, self.pg2]) |
| 1838 | self.send_and_expect_load_balancing(self.pg0, port_mpls_neos_pkts, |
| 1839 | [self.pg1, self.pg2]) |
| 1840 | |
| 1841 | # |
| 1842 | # The packets with Entropy label in should not load-balance, |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1843 | # since the Entropy value is fixed. |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1844 | # |
| 1845 | 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] | 1846 | |
| 1847 | # |
| 1848 | # change the flow hash config so it's only IP src,dst |
| 1849 | # - now only the stream with differing source address will |
| 1850 | # load-balance |
| 1851 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 1852 | self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=0, dport=0, |
| 1853 | is_ipv6=1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1854 | |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1855 | self.send_and_expect_load_balancing(self.pg0, src_ip_pkts, |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1856 | [self.pg1, self.pg2]) |
Neale Ranns | 71275e3 | 2017-05-25 12:38:58 -0700 | [diff] [blame] | 1857 | self.send_and_expect_load_balancing(self.pg0, src_mpls_pkts, |
| 1858 | [self.pg1, self.pg2]) |
| 1859 | 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] | 1860 | |
| 1861 | # |
| 1862 | # change the flow hash config back to defaults |
| 1863 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 1864 | self.vapi.set_ip_flow_hash(vrf_id=0, src=1, dst=1, sport=1, dport=1, |
| 1865 | is_ipv6=1) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1866 | |
| 1867 | # |
| 1868 | # Recursive prefixes |
| 1869 | # - testing that 2 stages of load-balancing occurs and there is no |
| 1870 | # polarisation (i.e. only 2 of 4 paths are used) |
| 1871 | # |
| 1872 | port_pkts = [] |
| 1873 | src_pkts = [] |
| 1874 | |
| 1875 | for ii in range(257): |
| 1876 | port_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1877 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1878 | IPv6(dst="4000::1", |
| 1879 | src="4000:1::1") / |
| 1880 | inet6.UDP(sport=1234, |
| 1881 | dport=1234 + ii) / |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1882 | Raw('\xa5' * 100))) |
| 1883 | src_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1884 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1885 | IPv6(dst="4000::1", |
| 1886 | src="4000:1::%d" % ii) / |
| 1887 | inet6.UDP(sport=1234, dport=1234) / |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1888 | Raw('\xa5' * 100))) |
| 1889 | |
| 1890 | route_3000_2 = VppIpRoute(self, "3000::2", 128, |
| 1891 | [VppRoutePath(self.pg3.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1892 | self.pg3.sw_if_index), |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1893 | VppRoutePath(self.pg4.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1894 | self.pg4.sw_if_index)]) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1895 | route_3000_2.add_vpp_config() |
| 1896 | |
| 1897 | route_4000_1 = VppIpRoute(self, "4000::1", 128, |
| 1898 | [VppRoutePath("3000::1", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1899 | 0xffffffff), |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1900 | VppRoutePath("3000::2", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1901 | 0xffffffff)]) |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1902 | route_4000_1.add_vpp_config() |
| 1903 | |
| 1904 | # |
| 1905 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 1906 | # |
| 1907 | self.vapi.cli("clear trace") |
| 1908 | self.send_and_expect_load_balancing(self.pg0, port_pkts, |
| 1909 | [self.pg1, self.pg2, |
| 1910 | self.pg3, self.pg4]) |
| 1911 | self.send_and_expect_load_balancing(self.pg0, src_pkts, |
| 1912 | [self.pg1, self.pg2, |
| 1913 | self.pg3, self.pg4]) |
| 1914 | |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1915 | # |
| 1916 | # Recursive prefixes |
| 1917 | # - testing that 2 stages of load-balancing no choices |
| 1918 | # |
| 1919 | port_pkts = [] |
| 1920 | |
| 1921 | for ii in range(257): |
| 1922 | port_pkts.append((Ether(src=self.pg0.remote_mac, |
| 1923 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1924 | IPv6(dst="6000::1", |
| 1925 | src="6000:1::1") / |
| 1926 | inet6.UDP(sport=1234, |
| 1927 | dport=1234 + ii) / |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1928 | Raw('\xa5' * 100))) |
| 1929 | |
| 1930 | route_5000_2 = VppIpRoute(self, "5000::2", 128, |
| 1931 | [VppRoutePath(self.pg3.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1932 | self.pg3.sw_if_index)]) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1933 | route_5000_2.add_vpp_config() |
| 1934 | |
| 1935 | route_6000_1 = VppIpRoute(self, "6000::1", 128, |
| 1936 | [VppRoutePath("5000::2", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1937 | 0xffffffff)]) |
Neale Ranns | 42e6b09 | 2017-07-31 02:56:03 -0700 | [diff] [blame] | 1938 | route_6000_1.add_vpp_config() |
| 1939 | |
| 1940 | # |
| 1941 | # inject the packet on pg0 - expect load-balancing across all 4 paths |
| 1942 | # |
| 1943 | self.vapi.cli("clear trace") |
| 1944 | self.send_and_expect_one_itf(self.pg0, port_pkts, self.pg3) |
| 1945 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1946 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1947 | class TestIP6Punt(VppTestCase): |
| 1948 | """ IPv6 Punt Police/Redirect """ |
| 1949 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 1950 | @classmethod |
| 1951 | def setUpClass(cls): |
| 1952 | super(TestIP6Punt, cls).setUpClass() |
| 1953 | |
| 1954 | @classmethod |
| 1955 | def tearDownClass(cls): |
| 1956 | super(TestIP6Punt, cls).tearDownClass() |
| 1957 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1958 | def setUp(self): |
| 1959 | super(TestIP6Punt, self).setUp() |
| 1960 | |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1961 | self.create_pg_interfaces(range(4)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1962 | |
| 1963 | for i in self.pg_interfaces: |
| 1964 | i.admin_up() |
| 1965 | i.config_ip6() |
| 1966 | i.resolve_ndp() |
| 1967 | |
| 1968 | def tearDown(self): |
| 1969 | super(TestIP6Punt, self).tearDown() |
| 1970 | for i in self.pg_interfaces: |
| 1971 | i.unconfig_ip6() |
| 1972 | i.admin_down() |
| 1973 | |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1974 | def test_ip_punt(self): |
| 1975 | """ IP6 punt police and redirect """ |
| 1976 | |
| 1977 | p = (Ether(src=self.pg0.remote_mac, |
| 1978 | dst=self.pg0.local_mac) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 1979 | IPv6(src=self.pg0.remote_ip6, |
| 1980 | dst=self.pg0.local_ip6) / |
| 1981 | inet6.TCP(sport=1234, dport=1234) / |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1982 | Raw('\xa5' * 100)) |
| 1983 | |
| 1984 | pkts = p * 1025 |
| 1985 | |
| 1986 | # |
| 1987 | # Configure a punt redirect via pg1. |
| 1988 | # |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 1989 | nh_addr = self.pg1.remote_ip6 |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1990 | self.vapi.ip_punt_redirect(self.pg0.sw_if_index, |
| 1991 | self.pg1.sw_if_index, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1992 | nh_addr) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1993 | |
| 1994 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 1995 | |
| 1996 | # |
| 1997 | # add a policer |
| 1998 | # |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 1999 | 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] | 2000 | rate_type=1) |
| 2001 | self.vapi.ip_punt_police(policer.policer_index, is_ip6=1) |
| 2002 | |
| 2003 | self.vapi.cli("clear trace") |
| 2004 | self.pg0.add_stream(pkts) |
| 2005 | self.pg_enable_capture(self.pg_interfaces) |
| 2006 | self.pg_start() |
| 2007 | |
| 2008 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2009 | # the number of packet received should be greater than 0, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2010 | # but not equal to the number sent, since some were policed |
| 2011 | # |
| 2012 | rx = self.pg1._get_capture(1) |
Paul Vinciguerra | 3d2df21 | 2018-11-24 23:19:53 -0800 | [diff] [blame] | 2013 | self.assertGreater(len(rx), 0) |
| 2014 | self.assertLess(len(rx), len(pkts)) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2015 | |
| 2016 | # |
Paul Vinciguerra | eb41443 | 2019-02-20 09:01:14 -0800 | [diff] [blame] | 2017 | # remove the policer. back to full rx |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2018 | # |
| 2019 | 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] | 2020 | self.vapi.policer_add_del(b"ip6-punt", 400, 0, 10, 0, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2021 | rate_type=1, is_add=0) |
| 2022 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 2023 | |
| 2024 | # |
| 2025 | # remove the redirect. expect full drop. |
| 2026 | # |
| 2027 | self.vapi.ip_punt_redirect(self.pg0.sw_if_index, |
| 2028 | self.pg1.sw_if_index, |
| 2029 | nh_addr, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2030 | is_add=0) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2031 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 2032 | "IP no punt config") |
| 2033 | |
| 2034 | # |
| 2035 | # Add a redirect that is not input port selective |
| 2036 | # |
| 2037 | self.vapi.ip_punt_redirect(0xffffffff, |
| 2038 | self.pg1.sw_if_index, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2039 | nh_addr) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2040 | self.send_and_expect(self.pg0, pkts, self.pg1) |
| 2041 | |
| 2042 | self.vapi.ip_punt_redirect(0xffffffff, |
| 2043 | self.pg1.sw_if_index, |
| 2044 | nh_addr, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2045 | is_add=0) |
| 2046 | |
| 2047 | def test_ip_punt_dump(self): |
| 2048 | """ IP6 punt redirect dump""" |
| 2049 | |
| 2050 | # |
| 2051 | # Configure a punt redirects |
| 2052 | # |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2053 | nh_addr = self.pg3.remote_ip6 |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2054 | self.vapi.ip_punt_redirect(self.pg0.sw_if_index, |
| 2055 | self.pg3.sw_if_index, |
| 2056 | nh_addr) |
| 2057 | self.vapi.ip_punt_redirect(self.pg1.sw_if_index, |
| 2058 | self.pg3.sw_if_index, |
| 2059 | nh_addr) |
| 2060 | self.vapi.ip_punt_redirect(self.pg2.sw_if_index, |
| 2061 | self.pg3.sw_if_index, |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2062 | '0::0') |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2063 | |
| 2064 | # |
| 2065 | # Dump pg0 punt redirects |
| 2066 | # |
| 2067 | punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index, |
| 2068 | is_ipv6=1) |
| 2069 | for p in punts: |
| 2070 | self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index) |
| 2071 | |
| 2072 | # |
| 2073 | # Dump punt redirects for all interfaces |
| 2074 | # |
| 2075 | punts = self.vapi.ip_punt_redirect_dump(0xffffffff, is_ipv6=1) |
| 2076 | self.assertEqual(len(punts), 3) |
| 2077 | for p in punts: |
| 2078 | 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] | 2079 | self.assertNotEqual(punts[1].punt.nh, self.pg3.remote_ip6) |
| 2080 | self.assertEqual(str(punts[2].punt.nh), '::') |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2081 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2082 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2083 | class TestIPDeag(VppTestCase): |
| 2084 | """ IPv6 Deaggregate Routes """ |
| 2085 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2086 | @classmethod |
| 2087 | def setUpClass(cls): |
| 2088 | super(TestIPDeag, cls).setUpClass() |
| 2089 | |
| 2090 | @classmethod |
| 2091 | def tearDownClass(cls): |
| 2092 | super(TestIPDeag, cls).tearDownClass() |
| 2093 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2094 | def setUp(self): |
| 2095 | super(TestIPDeag, self).setUp() |
| 2096 | |
| 2097 | self.create_pg_interfaces(range(3)) |
| 2098 | |
| 2099 | for i in self.pg_interfaces: |
| 2100 | i.admin_up() |
| 2101 | i.config_ip6() |
| 2102 | i.resolve_ndp() |
| 2103 | |
| 2104 | def tearDown(self): |
| 2105 | super(TestIPDeag, self).tearDown() |
| 2106 | for i in self.pg_interfaces: |
| 2107 | i.unconfig_ip6() |
| 2108 | i.admin_down() |
| 2109 | |
| 2110 | def test_ip_deag(self): |
| 2111 | """ IP Deag Routes """ |
| 2112 | |
| 2113 | # |
| 2114 | # Create a table to be used for: |
| 2115 | # 1 - another destination address lookup |
| 2116 | # 2 - a source address lookup |
| 2117 | # |
| 2118 | table_dst = VppIpTable(self, 1, is_ip6=1) |
| 2119 | table_src = VppIpTable(self, 2, is_ip6=1) |
| 2120 | table_dst.add_vpp_config() |
| 2121 | table_src.add_vpp_config() |
| 2122 | |
| 2123 | # |
| 2124 | # Add a route in the default table to point to a deag/ |
| 2125 | # second lookup in each of these tables |
| 2126 | # |
| 2127 | route_to_dst = VppIpRoute(self, "1::1", 128, |
| 2128 | [VppRoutePath("::", |
| 2129 | 0xffffffff, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2130 | nh_table_id=1)]) |
| 2131 | route_to_src = VppIpRoute( |
| 2132 | self, "1::2", 128, |
| 2133 | [VppRoutePath("::", |
| 2134 | 0xffffffff, |
| 2135 | nh_table_id=2, |
| 2136 | type=FibPathType.FIB_PATH_TYPE_SOURCE_LOOKUP)]) |
| 2137 | |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2138 | route_to_dst.add_vpp_config() |
| 2139 | route_to_src.add_vpp_config() |
| 2140 | |
| 2141 | # |
| 2142 | # packets to these destination are dropped, since they'll |
| 2143 | # hit the respective default routes in the second table |
| 2144 | # |
| 2145 | p_dst = (Ether(src=self.pg0.remote_mac, |
| 2146 | dst=self.pg0.local_mac) / |
| 2147 | IPv6(src="5::5", dst="1::1") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2148 | inet6.TCP(sport=1234, dport=1234) / |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2149 | Raw('\xa5' * 100)) |
| 2150 | p_src = (Ether(src=self.pg0.remote_mac, |
| 2151 | dst=self.pg0.local_mac) / |
| 2152 | IPv6(src="2::2", dst="1::2") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2153 | inet6.TCP(sport=1234, dport=1234) / |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2154 | Raw('\xa5' * 100)) |
| 2155 | pkts_dst = p_dst * 257 |
| 2156 | pkts_src = p_src * 257 |
| 2157 | |
| 2158 | self.send_and_assert_no_replies(self.pg0, pkts_dst, |
| 2159 | "IP in dst table") |
| 2160 | self.send_and_assert_no_replies(self.pg0, pkts_src, |
| 2161 | "IP in src table") |
| 2162 | |
| 2163 | # |
| 2164 | # add a route in the dst table to forward via pg1 |
| 2165 | # |
| 2166 | route_in_dst = VppIpRoute(self, "1::1", 128, |
| 2167 | [VppRoutePath(self.pg1.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2168 | self.pg1.sw_if_index)], |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2169 | table_id=1) |
| 2170 | route_in_dst.add_vpp_config() |
| 2171 | |
| 2172 | self.send_and_expect(self.pg0, pkts_dst, self.pg1) |
| 2173 | |
| 2174 | # |
| 2175 | # add a route in the src table to forward via pg2 |
| 2176 | # |
| 2177 | route_in_src = VppIpRoute(self, "2::2", 128, |
| 2178 | [VppRoutePath(self.pg2.remote_ip6, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2179 | self.pg2.sw_if_index)], |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2180 | table_id=2) |
| 2181 | route_in_src.add_vpp_config() |
| 2182 | self.send_and_expect(self.pg0, pkts_src, self.pg2) |
| 2183 | |
| 2184 | # |
| 2185 | # loop in the lookup DP |
| 2186 | # |
| 2187 | route_loop = VppIpRoute(self, "3::3", 128, |
| 2188 | [VppRoutePath("::", |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 2189 | 0xffffffff)]) |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2190 | route_loop.add_vpp_config() |
| 2191 | |
| 2192 | p_l = (Ether(src=self.pg0.remote_mac, |
| 2193 | dst=self.pg0.local_mac) / |
| 2194 | IPv6(src="3::4", dst="3::3") / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2195 | inet6.TCP(sport=1234, dport=1234) / |
Neale Ranns | ce9e0b4 | 2018-08-01 12:53:17 -0700 | [diff] [blame] | 2196 | Raw('\xa5' * 100)) |
| 2197 | |
| 2198 | self.send_and_assert_no_replies(self.pg0, p_l * 257, |
| 2199 | "IP lookup loop") |
| 2200 | |
| 2201 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2202 | class TestIP6Input(VppTestCase): |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2203 | """ IPv6 Input Exception Test Cases """ |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2204 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 2205 | @classmethod |
| 2206 | def setUpClass(cls): |
| 2207 | super(TestIP6Input, cls).setUpClass() |
| 2208 | |
| 2209 | @classmethod |
| 2210 | def tearDownClass(cls): |
| 2211 | super(TestIP6Input, cls).tearDownClass() |
| 2212 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2213 | def setUp(self): |
| 2214 | super(TestIP6Input, self).setUp() |
| 2215 | |
| 2216 | self.create_pg_interfaces(range(2)) |
| 2217 | |
| 2218 | for i in self.pg_interfaces: |
| 2219 | i.admin_up() |
| 2220 | i.config_ip6() |
| 2221 | i.resolve_ndp() |
| 2222 | |
| 2223 | def tearDown(self): |
| 2224 | super(TestIP6Input, self).tearDown() |
| 2225 | for i in self.pg_interfaces: |
| 2226 | i.unconfig_ip6() |
| 2227 | i.admin_down() |
| 2228 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2229 | def test_ip_input_icmp_reply(self): |
| 2230 | """ IP6 Input Exception - Return ICMP (3,0) """ |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2231 | # |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2232 | # hop limit - ICMP replies |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2233 | # |
| 2234 | p_version = (Ether(src=self.pg0.remote_mac, |
| 2235 | dst=self.pg0.local_mac) / |
| 2236 | IPv6(src=self.pg0.remote_ip6, |
| 2237 | dst=self.pg1.remote_ip6, |
| 2238 | hlim=1) / |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 2239 | inet6.UDP(sport=1234, dport=1234) / |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2240 | Raw('\xa5' * 100)) |
| 2241 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2242 | 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] | 2243 | rx = rx[0] |
| 2244 | icmp = rx[ICMPv6TimeExceeded] |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2245 | |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2246 | # 0: "hop limit exceeded in transit", |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2247 | self.assertEqual((icmp.type, icmp.code), (3, 0)) |
| 2248 | |
| 2249 | icmpv6_data = '\x0a' * 18 |
| 2250 | all_0s = "::" |
| 2251 | all_1s = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF" |
| 2252 | |
| 2253 | @parameterized.expand([ |
| 2254 | # Name, src, dst, l4proto, msg, timeout |
| 2255 | ("src='iface', dst='iface'", None, None, |
| 2256 | inet6.UDP(sport=1234, dport=1234), "funky version", None), |
| 2257 | ("src='All 0's', dst='iface'", all_0s, None, |
| 2258 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2259 | ("src='iface', dst='All 0's'", None, all_0s, |
| 2260 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2261 | ("src='All 1's', dst='iface'", all_1s, None, |
| 2262 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2263 | ("src='iface', dst='All 1's'", None, all_1s, |
| 2264 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2265 | ("src='All 1's', dst='All 1's'", all_1s, all_1s, |
| 2266 | ICMPv6EchoRequest(id=0xb, seq=5, data=icmpv6_data), None, 0.1), |
| 2267 | |
| 2268 | ]) |
| 2269 | def test_ip_input_no_replies(self, name, src, dst, l4, msg, timeout): |
| 2270 | |
| 2271 | self._testMethodDoc = 'IPv6 Input Exception - %s' % name |
| 2272 | |
| 2273 | p_version = (Ether(src=self.pg0.remote_mac, |
| 2274 | dst=self.pg0.local_mac) / |
| 2275 | IPv6(src=src or self.pg0.remote_ip6, |
| 2276 | dst=dst or self.pg1.remote_ip6, |
| 2277 | version=3) / |
| 2278 | l4 / |
| 2279 | Raw('\xa5' * 100)) |
| 2280 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2281 | self.send_and_assert_no_replies(self.pg0, p_version * NUM_PKTS, |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 2282 | remark=msg or "", |
| 2283 | timeout=timeout) |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2284 | |
Dave Barach | 9080096 | 2019-05-24 13:03:01 -0400 | [diff] [blame] | 2285 | def test_hop_by_hop(self): |
| 2286 | """ Hop-by-hop header test """ |
| 2287 | |
| 2288 | p = (Ether(src=self.pg0.remote_mac, |
| 2289 | dst=self.pg0.local_mac) / |
| 2290 | IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) / |
| 2291 | IPv6ExtHdrHopByHop() / |
| 2292 | inet6.UDP(sport=1234, dport=1234) / |
| 2293 | Raw('\xa5' * 100)) |
| 2294 | |
| 2295 | self.pg0.add_stream(p) |
| 2296 | self.pg_enable_capture(self.pg_interfaces) |
| 2297 | self.pg_start() |
Neale Ranns | 4c7c8e5 | 2017-10-21 09:37:55 -0700 | [diff] [blame] | 2298 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 2299 | if __name__ == '__main__': |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 2300 | unittest.main(testRunner=VppTestRunner) |