Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 3 | import unittest |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 4 | import socket |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 5 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 6 | from framework import VppTestCase, VppTestRunner |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 7 | from vpp_sub_interface import VppSubInterface, VppDot1QSubint |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 8 | from vpp_pg_interface import is_ipv6_misc |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 9 | |
| 10 | from scapy.packet import Raw |
| 11 | from scapy.layers.l2 import Ether, Dot1Q |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 12 | from scapy.layers.inet6 import IPv6, UDP, ICMPv6ND_NS, ICMPv6ND_RS, \ |
| 13 | ICMPv6ND_RA, ICMPv6NDOptSrcLLAddr, getmacbyip6, ICMPv6MRD_Solicitation |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 14 | from util import ppp |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 15 | from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ptop, in6_islladdr, \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 16 | in6_mactoifaceid, in6_ismaddr |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 17 | from scapy.utils import inet_pton, inet_ntop |
| 18 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 19 | def mk_ll_addr(mac): |
| 20 | euid = in6_mactoifaceid(mac) |
| 21 | addr = "fe80::" + euid |
| 22 | return addr |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 23 | |
| 24 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 25 | class TestIPv6(VppTestCase): |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 26 | """ IPv6 Test Case """ |
| 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
| 30 | super(TestIPv6, cls).setUpClass() |
| 31 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 32 | def setUp(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 33 | """ |
| 34 | Perform test setup before test case. |
| 35 | |
| 36 | **Config:** |
| 37 | - create 3 pg interfaces |
| 38 | - untagged pg0 interface |
| 39 | - Dot1Q subinterface on pg1 |
| 40 | - Dot1AD subinterface on pg2 |
| 41 | - setup interfaces: |
| 42 | - put it into UP state |
| 43 | - set IPv6 addresses |
| 44 | - resolve neighbor address using NDP |
| 45 | - configure 200 fib entries |
| 46 | |
| 47 | :ivar list interfaces: pg interfaces and subinterfaces. |
| 48 | :ivar dict flows: IPv4 packet flows in test. |
| 49 | :ivar list pg_if_packet_sizes: packet sizes in test. |
| 50 | |
| 51 | *TODO:* Create AD sub interface |
| 52 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 53 | super(TestIPv6, self).setUp() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 54 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 55 | # create 3 pg interfaces |
| 56 | self.create_pg_interfaces(range(3)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 57 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 58 | # create 2 subinterfaces for p1 and pg2 |
| 59 | self.sub_interfaces = [ |
| 60 | VppDot1QSubint(self, self.pg1, 100), |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 61 | VppDot1QSubint(self, self.pg2, 200) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 62 | # TODO: VppDot1ADSubint(self, self.pg2, 200, 300, 400) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 63 | ] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 64 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 65 | # packet flows mapping pg0 -> pg1.sub, pg2.sub, etc. |
| 66 | self.flows = dict() |
| 67 | self.flows[self.pg0] = [self.pg1.sub_if, self.pg2.sub_if] |
| 68 | self.flows[self.pg1.sub_if] = [self.pg0, self.pg2.sub_if] |
| 69 | self.flows[self.pg2.sub_if] = [self.pg0, self.pg1.sub_if] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 70 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 71 | # packet sizes |
| 72 | self.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 73 | self.sub_if_packet_sizes = [64, 512, 1518 + 4, 9018 + 4] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 74 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 75 | self.interfaces = list(self.pg_interfaces) |
| 76 | self.interfaces.extend(self.sub_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 77 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 78 | # setup all interfaces |
| 79 | for i in self.interfaces: |
| 80 | i.admin_up() |
| 81 | i.config_ip6() |
| 82 | i.resolve_ndp() |
| 83 | |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 84 | # config 2M FIB entries |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 85 | self.config_fib_entries(200) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 86 | |
| 87 | def tearDown(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 88 | """Run standard test teardown and log ``show ip6 neighbors``.""" |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 89 | for i in self.sub_interfaces: |
| 90 | i.unconfig_ip6() |
| 91 | i.ip6_disable() |
| 92 | i.admin_down() |
| 93 | i.remove_vpp_config() |
| 94 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 95 | super(TestIPv6, self).tearDown() |
| 96 | if not self.vpp_dead: |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 97 | self.logger.info(self.vapi.cli("show ip6 neighbors")) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 98 | # info(self.vapi.cli("show ip6 fib")) # many entries |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 99 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 100 | def config_fib_entries(self, count): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 101 | """For each interface add to the FIB table *count* routes to |
| 102 | "fd02::1/128" destination with interface's local address as next-hop |
| 103 | address. |
| 104 | |
| 105 | :param int count: Number of FIB entries. |
| 106 | |
| 107 | - *TODO:* check if the next-hop address shouldn't be remote address |
| 108 | instead of local address. |
| 109 | """ |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 110 | n_int = len(self.interfaces) |
| 111 | percent = 0 |
| 112 | counter = 0.0 |
| 113 | dest_addr = socket.inet_pton(socket.AF_INET6, "fd02::1") |
| 114 | dest_addr_len = 128 |
| 115 | for i in self.interfaces: |
| 116 | next_hop_address = i.local_ip6n |
| 117 | for j in range(count / n_int): |
| 118 | self.vapi.ip_add_del_route( |
| 119 | dest_addr, dest_addr_len, next_hop_address, is_ipv6=1) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 120 | counter += 1 |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 121 | if counter / count * 100 > percent: |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 122 | self.logger.info("Configure %d FIB entries .. %d%% done" % |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 123 | (count, percent)) |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 124 | percent += 1 |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 125 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 126 | def create_stream(self, src_if, packet_sizes): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 127 | """Create input packet stream for defined interface. |
| 128 | |
| 129 | :param VppInterface src_if: Interface to create packet stream for. |
| 130 | :param list packet_sizes: Required packet sizes. |
| 131 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 132 | pkts = [] |
| 133 | for i in range(0, 257): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 134 | dst_if = self.flows[src_if][i % 2] |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 135 | info = self.create_packet_info(src_if, dst_if) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 136 | payload = self.info_to_payload(info) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 137 | p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / |
| 138 | IPv6(src=src_if.remote_ip6, dst=dst_if.remote_ip6) / |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 139 | UDP(sport=1234, dport=1234) / |
| 140 | Raw(payload)) |
| 141 | info.data = p.copy() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 142 | if isinstance(src_if, VppSubInterface): |
| 143 | p = src_if.add_dot1_layer(p) |
| 144 | size = packet_sizes[(i // 2) % len(packet_sizes)] |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 145 | self.extend_packet(p, size) |
| 146 | pkts.append(p) |
| 147 | return pkts |
| 148 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 149 | def verify_capture(self, dst_if, capture): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 150 | """Verify captured input packet stream for defined interface. |
| 151 | |
| 152 | :param VppInterface dst_if: Interface to verify captured packet stream |
| 153 | for. |
| 154 | :param list capture: Captured packet stream. |
| 155 | """ |
| 156 | self.logger.info("Verifying capture on interface %s" % dst_if.name) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 157 | last_info = dict() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 158 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 159 | last_info[i.sw_if_index] = None |
| 160 | is_sub_if = False |
| 161 | dst_sw_if_index = dst_if.sw_if_index |
| 162 | if hasattr(dst_if, 'parent'): |
| 163 | is_sub_if = True |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 164 | for packet in capture: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 165 | if is_sub_if: |
| 166 | # Check VLAN tags and Ethernet header |
| 167 | packet = dst_if.remove_dot1_layer(packet) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 168 | self.assertTrue(Dot1Q not in packet) |
| 169 | try: |
| 170 | ip = packet[IPv6] |
| 171 | udp = packet[UDP] |
| 172 | payload_info = self.payload_to_info(str(packet[Raw])) |
| 173 | packet_index = payload_info.index |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 174 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 175 | self.logger.debug( |
| 176 | "Got packet on port %s: src=%u (id=%u)" % |
| 177 | (dst_if.name, payload_info.src, packet_index)) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 178 | next_info = self.get_next_packet_info_for_interface2( |
| 179 | payload_info.src, dst_sw_if_index, |
| 180 | last_info[payload_info.src]) |
| 181 | last_info[payload_info.src] = next_info |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 182 | self.assertTrue(next_info is not None) |
| 183 | self.assertEqual(packet_index, next_info.index) |
| 184 | saved_packet = next_info.data |
| 185 | # Check standard fields |
| 186 | self.assertEqual(ip.src, saved_packet[IPv6].src) |
| 187 | self.assertEqual(ip.dst, saved_packet[IPv6].dst) |
| 188 | self.assertEqual(udp.sport, saved_packet[UDP].sport) |
| 189 | self.assertEqual(udp.dport, saved_packet[UDP].dport) |
| 190 | except: |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 191 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 192 | raise |
| 193 | for i in self.interfaces: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 194 | remaining_packet = self.get_next_packet_info_for_interface2( |
| 195 | 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] | 196 | self.assertTrue(remaining_packet is None, |
| 197 | "Interface %s: Packet expected from interface %s " |
| 198 | "didn't arrive" % (dst_if.name, i.name)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 199 | |
| 200 | def test_fib(self): |
Matej Klotton | 86d87c4 | 2016-11-11 11:38:55 +0100 | [diff] [blame] | 201 | """ IPv6 FIB test |
| 202 | |
| 203 | Test scenario: |
| 204 | - Create IPv6 stream for pg0 interface |
| 205 | - Create IPv6 tagged streams for pg1's and pg2's subinterface. |
| 206 | - Send and verify received packets on each interface. |
| 207 | """ |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 208 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 209 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes) |
| 210 | self.pg0.add_stream(pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 211 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 212 | for i in self.sub_interfaces: |
| 213 | pkts = self.create_stream(i, self.sub_if_packet_sizes) |
| 214 | i.parent.add_stream(pkts) |
| 215 | |
| 216 | self.pg_enable_capture(self.pg_interfaces) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 217 | self.pg_start() |
| 218 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 219 | pkts = self.pg0.get_capture() |
| 220 | self.verify_capture(self.pg0, pkts) |
| 221 | |
| 222 | for i in self.sub_interfaces: |
| 223 | pkts = i.parent.get_capture() |
| 224 | self.verify_capture(i, pkts) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 225 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 226 | def send_and_assert_no_replies(self, intf, pkts, remark): |
| 227 | intf.add_stream(pkts) |
| 228 | self.pg_enable_capture(self.pg_interfaces) |
| 229 | self.pg_start() |
| 230 | intf.assert_nothing_captured(remark=remark) |
| 231 | |
| 232 | def test_ns(self): |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 233 | """ IPv6 Neighbour Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 234 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 235 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 236 | - Send an NS Sourced from an address not covered by the link sub-net |
| 237 | - Send an NS to an mcast address the router has not joined |
| 238 | - Send NS for a target address the router does not onn. |
| 239 | """ |
| 240 | |
| 241 | # |
| 242 | # An NS from a non link source address |
| 243 | # |
| 244 | nsma = in6_getnsma(inet_pton(socket.AF_INET6, self.pg0.local_ip6)) |
| 245 | d = inet_ntop(socket.AF_INET6, nsma) |
| 246 | |
| 247 | p = (Ether(dst=in6_getnsmac(nsma)) / |
| 248 | IPv6(dst=d, src="2002::2") / |
| 249 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
| 250 | ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) |
| 251 | pkts = [p] |
| 252 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 253 | self.send_and_assert_no_replies( |
| 254 | self.pg0, pkts, |
| 255 | "No response to NS source by address not on sub-net") |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 256 | |
| 257 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 258 | # An NS for sent to a solicited mcast group the router is |
| 259 | # not a member of FAILS |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 260 | # |
| 261 | if 0: |
| 262 | nsma = in6_getnsma(inet_pton(socket.AF_INET6, "fd::ffff")) |
| 263 | d = inet_ntop(socket.AF_INET6, nsma) |
| 264 | |
| 265 | p = (Ether(dst=in6_getnsmac(nsma)) / |
| 266 | IPv6(dst=d, src=self.pg0.remote_ip6) / |
| 267 | ICMPv6ND_NS(tgt=self.pg0.local_ip6) / |
| 268 | ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) |
| 269 | pkts = [p] |
| 270 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 271 | self.send_and_assert_no_replies( |
| 272 | self.pg0, pkts, |
| 273 | "No response to NS sent to unjoined mcast address") |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 274 | |
| 275 | # |
| 276 | # An NS whose target address is one the router does not own |
| 277 | # |
| 278 | nsma = in6_getnsma(inet_pton(socket.AF_INET6, self.pg0.local_ip6)) |
| 279 | d = inet_ntop(socket.AF_INET6, nsma) |
| 280 | |
| 281 | p = (Ether(dst=in6_getnsmac(nsma)) / |
| 282 | IPv6(dst=d, src=self.pg0.remote_ip6) / |
| 283 | ICMPv6ND_NS(tgt="fd::ffff") / |
| 284 | ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) |
| 285 | pkts = [p] |
| 286 | |
| 287 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 288 | "No response to NS for unknown target") |
| 289 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 290 | def validate_ra(self, intf, rx, dst_ip=None): |
| 291 | if not dst_ip: |
| 292 | dst_ip = intf.remote_ip6 |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 293 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 294 | # unicasted packets must come to the unicast mac |
| 295 | self.assertEqual(rx[Ether].dst, intf.remote_mac) |
| 296 | |
| 297 | # and from the router's MAC |
| 298 | self.assertEqual(rx[Ether].src, intf.local_mac) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 299 | |
| 300 | # the rx'd RA should be addressed to the sender's source |
| 301 | self.assertTrue(rx.haslayer(ICMPv6ND_RA)) |
| 302 | self.assertEqual(in6_ptop(rx[IPv6].dst), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 303 | in6_ptop(dst_ip)) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 304 | |
| 305 | # and come from the router's link local |
| 306 | self.assertTrue(in6_islladdr(rx[IPv6].src)) |
| 307 | self.assertEqual(in6_ptop(rx[IPv6].src), |
| 308 | in6_ptop(mk_ll_addr(intf.local_mac))) |
| 309 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 310 | |
| 311 | def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None, |
| 312 | filter_out_fn=is_ipv6_misc): |
| 313 | intf.add_stream(pkts) |
| 314 | self.pg0.add_stream(pkts) |
| 315 | self.pg_enable_capture(self.pg_interfaces) |
| 316 | self.pg_start() |
| 317 | rx = intf.get_capture(1, filter_out_fn=filter_out_fn) |
| 318 | |
| 319 | self.assertEqual(len(rx), 1) |
| 320 | rx = rx[0] |
| 321 | self.validate_ra(intf, rx, dst_ip) |
| 322 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 323 | def test_rs(self): |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 324 | """ IPv6 Router Solicitation Exceptions |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 325 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 326 | Test scenario: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 327 | """ |
| 328 | |
| 329 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 330 | # Before we begin change the IPv6 RA responses to use the unicast |
| 331 | # address - that way we will not confuse them with the periodic |
| 332 | # RAs which go to the mcast address |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 333 | # Sit and wait for the first periodic RA. |
| 334 | # |
| 335 | # TODO |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 336 | # |
| 337 | self.pg0.ip6_ra_config(send_unicast=1) |
| 338 | |
| 339 | # |
| 340 | # An RS from a link source address |
| 341 | # - expect an RA in return |
| 342 | # |
| 343 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 344 | IPv6(dst=self.pg0.local_ip6, src=self.pg0.remote_ip6) / |
| 345 | ICMPv6ND_RS()) |
| 346 | pkts = [p] |
| 347 | self.send_and_expect_ra(self.pg0, pkts, "Genuine RS") |
| 348 | |
| 349 | # |
| 350 | # For the next RS sent the RA should be rate limited |
| 351 | # |
| 352 | self.send_and_assert_no_replies(self.pg0, pkts, "RA rate limited") |
| 353 | |
| 354 | # |
| 355 | # 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] | 356 | # so we need to do this before each test below so as not to drop |
| 357 | # packets for rate limiting reasons. Test this works here. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 358 | # |
| 359 | self.pg0.ip6_ra_config(send_unicast=1) |
| 360 | self.send_and_expect_ra(self.pg0, pkts, "Rate limit reset RS") |
| 361 | |
| 362 | # |
| 363 | # An RS sent from a non-link local source |
| 364 | # |
| 365 | self.pg0.ip6_ra_config(send_unicast=1) |
| 366 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 367 | IPv6(dst=self.pg0.local_ip6, src="2002::ffff") / |
| 368 | ICMPv6ND_RS()) |
| 369 | pkts = [p] |
| 370 | self.send_and_assert_no_replies(self.pg0, pkts, |
| 371 | "RS from non-link source") |
| 372 | |
| 373 | # |
| 374 | # Source an RS from a link local address |
| 375 | # |
| 376 | self.pg0.ip6_ra_config(send_unicast=1) |
| 377 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 378 | p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) / |
| 379 | IPv6(dst=self.pg0.local_ip6, src=ll) / |
| 380 | ICMPv6ND_RS()) |
| 381 | pkts = [p] |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 382 | self.send_and_expect_ra(self.pg0, pkts, |
| 383 | "RS sourced from link-local", |
| 384 | dst_ip=ll) |
| 385 | |
| 386 | # |
| 387 | # Send the RS multicast |
| 388 | # |
| 389 | self.pg0.ip6_ra_config(send_unicast=1) |
| 390 | dmac = in6_getnsmac(inet_pton(socket.AF_INET6, "ff02::2")) |
| 391 | ll = mk_ll_addr(self.pg0.remote_mac) |
| 392 | p = (Ether(dst=dmac, src=self.pg0.remote_mac) / |
| 393 | IPv6(dst="ff02::2", src=ll) / |
| 394 | ICMPv6ND_RS()) |
| 395 | pkts = [p] |
| 396 | self.send_and_expect_ra(self.pg0, pkts, |
| 397 | "RS sourced from link-local", |
| 398 | dst_ip=ll) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 399 | |
| 400 | # |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 401 | # Source from the unspecified address ::. This happens when the RS |
| 402 | # is sent before the host has a configured address/sub-net, |
| 403 | # i.e. auto-config. Since the sender has no IP address, the reply |
| 404 | # comes back mcast - so the capture needs to not filter this. |
| 405 | # If we happen to pick up the periodic RA at this point then so be it, |
| 406 | # it's not an error. |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 407 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 408 | self.pg0.ip6_ra_config(send_unicast=1, suppress=1) |
| 409 | p = (Ether(dst=dmac, src=self.pg0.remote_mac) / |
| 410 | IPv6(dst="ff02::2", src="::") / |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 411 | ICMPv6ND_RS()) |
| 412 | pkts = [p] |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 413 | self.send_and_expect_ra(self.pg0, pkts, |
| 414 | "RS sourced from unspecified", |
| 415 | dst_ip="ff02::1", |
| 416 | filter_out_fn=None) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 417 | |
| 418 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 419 | # Reset the periodic advertisements back to default values |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 420 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame^] | 421 | self.pg0.ip6_ra_config(no=1, suppress=1, send_unicast=0) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 422 | |
| 423 | if __name__ == '__main__': |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 424 | unittest.main(testRunner=VppTestRunner) |