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