snaramre | 5d4b891 | 2019-12-13 23:39:35 +0000 | [diff] [blame] | 1 | from socket import AF_INET6, inet_ntop, inet_pton |
Paul Vinciguerra | e8fece8 | 2019-02-28 15:34:00 -0800 | [diff] [blame] | 2 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 3 | from scapy.layers.dhcp6 import ( |
| 4 | DHCP6_Advertise, |
| 5 | DHCP6OptClientId, |
| 6 | DHCP6OptStatusCode, |
| 7 | DHCP6OptPref, |
| 8 | DHCP6OptIA_PD, |
| 9 | DHCP6OptIAPrefix, |
| 10 | DHCP6OptServerId, |
| 11 | DHCP6_Solicit, |
| 12 | DHCP6_Reply, |
| 13 | DHCP6_Request, |
| 14 | DHCP6_Renew, |
| 15 | DHCP6_Rebind, |
| 16 | DUID_LL, |
| 17 | DHCP6_Release, |
| 18 | DHCP6OptElapsedTime, |
| 19 | DHCP6OptIA_NA, |
| 20 | DHCP6OptIAAddress, |
| 21 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 22 | from scapy.layers.inet6 import IPv6, Ether, UDP |
Paul Vinciguerra | e8fece8 | 2019-02-28 15:34:00 -0800 | [diff] [blame] | 23 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 24 | from framework import VppTestCase |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 25 | from asfframework import tag_fixme_vpp_workers, tag_run_solo |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 26 | from vpp_papi import VppEnum |
Paul Vinciguerra | e8fece8 | 2019-02-28 15:34:00 -0800 | [diff] [blame] | 27 | import util |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 28 | import os |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def ip6_normalize(ip6): |
| 32 | return inet_ntop(AF_INET6, inet_pton(AF_INET6, ip6)) |
| 33 | |
| 34 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 35 | class TestDHCPv6DataPlane(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 36 | """DHCPv6 Data Plane Test Case""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 37 | |
| 38 | @classmethod |
| 39 | def setUpClass(cls): |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 40 | super(TestDHCPv6DataPlane, cls).setUpClass() |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 41 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 42 | @classmethod |
| 43 | def tearDownClass(cls): |
| 44 | super(TestDHCPv6DataPlane, cls).tearDownClass() |
| 45 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 46 | def setUp(self): |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 47 | super(TestDHCPv6DataPlane, self).setUp() |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 48 | |
| 49 | self.create_pg_interfaces(range(1)) |
| 50 | self.interfaces = list(self.pg_interfaces) |
| 51 | for i in self.interfaces: |
| 52 | i.admin_up() |
| 53 | i.config_ip6() |
| 54 | |
Juraj Sloboda | d9778c2 | 2018-06-12 10:21:05 +0200 | [diff] [blame] | 55 | self.server_duid = DUID_LL(lladdr=self.pg0.remote_mac) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 56 | |
| 57 | def tearDown(self): |
| 58 | for i in self.interfaces: |
| 59 | i.unconfig_ip6() |
| 60 | i.admin_down() |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 61 | super(TestDHCPv6DataPlane, self).tearDown() |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 62 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 63 | def test_dhcp_ia_na_send_solicit_receive_advertise(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 64 | """Verify DHCPv6 IA NA Solicit packet and Advertise event""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 65 | |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 66 | self.vapi.dhcp6_clients_enable_disable(enable=1) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 67 | |
| 68 | self.pg_enable_capture(self.pg_interfaces) |
| 69 | self.pg_start() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 70 | address = {"address": "1:2:3::5", "preferred_time": 60, "valid_time": 120} |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 71 | self.vapi.dhcp6_send_client_message( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 72 | server_index=0xFFFFFFFF, |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 73 | mrc=1, |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 74 | msg_type=VppEnum.vl_api_dhcpv6_msg_type_t.DHCPV6_MSG_API_SOLICIT, |
| 75 | sw_if_index=self.pg0.sw_if_index, |
| 76 | T1=20, |
| 77 | T2=40, |
| 78 | addresses=[address], |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 79 | n_addresses=len([address]), |
| 80 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 81 | rx_list = self.pg0.get_capture(1) |
| 82 | self.assertEqual(len(rx_list), 1) |
| 83 | packet = rx_list[0] |
| 84 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 85 | self.assertEqual(packet.haslayer(IPv6), 1) |
| 86 | self.assertEqual(packet[IPv6].haslayer(DHCP6_Solicit), 1) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 87 | |
| 88 | client_duid = packet[DHCP6OptClientId].duid |
| 89 | trid = packet[DHCP6_Solicit].trid |
| 90 | |
| 91 | dst = ip6_normalize(packet[IPv6].dst) |
| 92 | dst2 = ip6_normalize("ff02::1:2") |
| 93 | self.assert_equal(dst, dst2) |
| 94 | src = ip6_normalize(packet[IPv6].src) |
| 95 | src2 = ip6_normalize(self.pg0.local_ip6_ll) |
| 96 | self.assert_equal(src, src2) |
| 97 | ia_na = packet[DHCP6OptIA_NA] |
| 98 | self.assert_equal(ia_na.T1, 20) |
| 99 | self.assert_equal(ia_na.T2, 40) |
| 100 | self.assert_equal(len(ia_na.ianaopts), 1) |
| 101 | address = ia_na.ianaopts[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 102 | self.assert_equal(address.addr, "1:2:3::5") |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 103 | self.assert_equal(address.preflft, 60) |
| 104 | self.assert_equal(address.validlft, 120) |
| 105 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 106 | self.vapi.want_dhcp6_reply_events(enable_disable=1, pid=os.getpid()) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 107 | |
| 108 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 109 | ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=60, validlft=120) |
| 110 | p = ( |
| 111 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 112 | / IPv6( |
| 113 | src=util.mk_ll_addr(self.pg0.remote_mac), dst=self.pg0.local_ip6_ll |
| 114 | ) |
| 115 | / UDP(sport=547, dport=546) |
| 116 | / DHCP6_Advertise(trid=trid) |
| 117 | / DHCP6OptServerId(duid=self.server_duid) |
| 118 | / DHCP6OptClientId(duid=client_duid) |
| 119 | / DHCP6OptPref(prefval=7) |
| 120 | / DHCP6OptStatusCode(statuscode=1) |
| 121 | / DHCP6OptIA_NA(iaid=1, T1=20, T2=40, ianaopts=ia_na_opts) |
| 122 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 123 | self.pg0.add_stream([p]) |
| 124 | self.pg_start() |
| 125 | |
| 126 | ev = self.vapi.wait_for_event(1, "dhcp6_reply_event") |
| 127 | |
| 128 | self.assert_equal(ev.preference, 7) |
| 129 | self.assert_equal(ev.status_code, 1) |
| 130 | self.assert_equal(ev.T1, 20) |
| 131 | self.assert_equal(ev.T2, 40) |
| 132 | |
| 133 | reported_address = ev.addresses[0] |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 134 | address = ia_na_opts.getfieldval("addr") |
| 135 | self.assert_equal(str(reported_address.address), address) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 136 | self.assert_equal( |
| 137 | reported_address.preferred_time, ia_na_opts.getfieldval("preflft") |
| 138 | ) |
| 139 | self.assert_equal( |
| 140 | reported_address.valid_time, ia_na_opts.getfieldval("validlft") |
| 141 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 142 | |
| 143 | finally: |
| 144 | self.vapi.want_dhcp6_reply_events(enable_disable=0) |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 145 | self.vapi.dhcp6_clients_enable_disable(enable=0) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 146 | |
| 147 | def test_dhcp_pd_send_solicit_receive_advertise(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 148 | """Verify DHCPv6 PD Solicit packet and Advertise event""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 149 | |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 150 | self.vapi.dhcp6_clients_enable_disable(enable=1) |
Juraj Sloboda | d9778c2 | 2018-06-12 10:21:05 +0200 | [diff] [blame] | 151 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 152 | self.pg_enable_capture(self.pg_interfaces) |
| 153 | self.pg_start() |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 154 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 155 | prefix = { |
| 156 | "prefix": {"address": "1:2:3::", "len": 50}, |
| 157 | "preferred_time": 60, |
| 158 | "valid_time": 120, |
| 159 | } |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 160 | prefixes = [prefix] |
| 161 | self.vapi.dhcp6_pd_send_client_message( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 162 | server_index=0xFFFFFFFF, |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 163 | mrc=1, |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 164 | msg_type=VppEnum.vl_api_dhcpv6_msg_type_t.DHCPV6_MSG_API_SOLICIT, |
| 165 | sw_if_index=self.pg0.sw_if_index, |
| 166 | T1=20, |
| 167 | T2=40, |
| 168 | prefixes=prefixes, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 169 | n_prefixes=len(prefixes), |
| 170 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 171 | rx_list = self.pg0.get_capture(1) |
| 172 | self.assertEqual(len(rx_list), 1) |
| 173 | packet = rx_list[0] |
| 174 | |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 175 | self.assertEqual(packet.haslayer(IPv6), 1) |
| 176 | self.assertEqual(packet[IPv6].haslayer(DHCP6_Solicit), 1) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 177 | |
| 178 | client_duid = packet[DHCP6OptClientId].duid |
| 179 | trid = packet[DHCP6_Solicit].trid |
| 180 | |
| 181 | dst = ip6_normalize(packet[IPv6].dst) |
| 182 | dst2 = ip6_normalize("ff02::1:2") |
| 183 | self.assert_equal(dst, dst2) |
| 184 | src = ip6_normalize(packet[IPv6].src) |
| 185 | src2 = ip6_normalize(self.pg0.local_ip6_ll) |
| 186 | self.assert_equal(src, src2) |
| 187 | ia_pd = packet[DHCP6OptIA_PD] |
| 188 | self.assert_equal(ia_pd.T1, 20) |
| 189 | self.assert_equal(ia_pd.T2, 40) |
| 190 | self.assert_equal(len(ia_pd.iapdopt), 1) |
| 191 | prefix = ia_pd.iapdopt[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | self.assert_equal(prefix.prefix, "1:2:3::") |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 193 | self.assert_equal(prefix.plen, 50) |
| 194 | self.assert_equal(prefix.preflft, 60) |
| 195 | self.assert_equal(prefix.validlft, 120) |
| 196 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 197 | self.vapi.want_dhcp6_pd_reply_events(enable_disable=1, pid=os.getpid()) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 198 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 199 | try: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 200 | ia_pd_opts = DHCP6OptIAPrefix( |
| 201 | prefix="7:8::", plen=56, preflft=60, validlft=120 |
| 202 | ) |
| 203 | p = ( |
| 204 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 205 | / IPv6( |
| 206 | src=util.mk_ll_addr(self.pg0.remote_mac), dst=self.pg0.local_ip6_ll |
| 207 | ) |
| 208 | / UDP(sport=547, dport=546) |
| 209 | / DHCP6_Advertise(trid=trid) |
| 210 | / DHCP6OptServerId(duid=self.server_duid) |
| 211 | / DHCP6OptClientId(duid=client_duid) |
| 212 | / DHCP6OptPref(prefval=7) |
| 213 | / DHCP6OptStatusCode(statuscode=1) |
| 214 | / DHCP6OptIA_PD(iaid=1, T1=20, T2=40, iapdopt=ia_pd_opts) |
| 215 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 216 | self.pg0.add_stream([p]) |
| 217 | self.pg_start() |
| 218 | |
| 219 | ev = self.vapi.wait_for_event(1, "dhcp6_pd_reply_event") |
| 220 | |
| 221 | self.assert_equal(ev.preference, 7) |
| 222 | self.assert_equal(ev.status_code, 1) |
| 223 | self.assert_equal(ev.T1, 20) |
| 224 | self.assert_equal(ev.T2, 40) |
| 225 | |
| 226 | reported_prefix = ev.prefixes[0] |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 227 | prefix = ia_pd_opts.getfieldval("prefix") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 228 | self.assert_equal(str(reported_prefix.prefix).split("/")[0], prefix) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 229 | self.assert_equal( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 230 | int(str(reported_prefix.prefix).split("/")[1]), |
| 231 | ia_pd_opts.getfieldval("plen"), |
| 232 | ) |
| 233 | self.assert_equal( |
| 234 | reported_prefix.preferred_time, ia_pd_opts.getfieldval("preflft") |
| 235 | ) |
| 236 | self.assert_equal( |
| 237 | reported_prefix.valid_time, ia_pd_opts.getfieldval("validlft") |
| 238 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 239 | |
| 240 | finally: |
| 241 | self.vapi.want_dhcp6_pd_reply_events(enable_disable=0) |
Neale Ranns | 02bfd64 | 2019-10-07 00:39:28 -0700 | [diff] [blame] | 242 | self.vapi.dhcp6_clients_enable_disable(enable=0) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 243 | |
| 244 | |
Andrew Yourtchenko | 06f3281 | 2021-01-14 10:19:08 +0000 | [diff] [blame] | 245 | @tag_run_solo |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 246 | class TestDHCPv6IANAControlPlane(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 247 | """DHCPv6 IA NA Control Plane Test Case""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 248 | |
| 249 | @classmethod |
| 250 | def setUpClass(cls): |
| 251 | super(TestDHCPv6IANAControlPlane, cls).setUpClass() |
| 252 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 253 | @classmethod |
| 254 | def tearDownClass(cls): |
| 255 | super(TestDHCPv6IANAControlPlane, cls).tearDownClass() |
| 256 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 257 | def setUp(self): |
| 258 | super(TestDHCPv6IANAControlPlane, self).setUp() |
| 259 | |
| 260 | self.create_pg_interfaces(range(1)) |
| 261 | self.interfaces = list(self.pg_interfaces) |
| 262 | for i in self.interfaces: |
| 263 | i.admin_up() |
| 264 | |
| 265 | self.server_duid = DUID_LL(lladdr=self.pg0.remote_mac) |
| 266 | self.client_duid = None |
| 267 | self.T1 = 1 |
| 268 | self.T2 = 2 |
| 269 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 270 | fib = self.vapi.ip_route_dump(0, True) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 271 | self.initial_addresses = set(self.get_interface_addresses(fib, self.pg0)) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 272 | |
| 273 | self.pg_enable_capture(self.pg_interfaces) |
| 274 | self.pg_start() |
| 275 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 276 | self.vapi.dhcp6_client_enable_disable( |
| 277 | sw_if_index=self.pg0.sw_if_index, enable=1 |
| 278 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 279 | |
| 280 | def tearDown(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 281 | self.vapi.dhcp6_client_enable_disable( |
| 282 | sw_if_index=self.pg0.sw_if_index, enable=0 |
| 283 | ) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 284 | |
| 285 | for i in self.interfaces: |
| 286 | i.admin_down() |
| 287 | |
| 288 | super(TestDHCPv6IANAControlPlane, self).tearDown() |
| 289 | |
| 290 | @staticmethod |
| 291 | def get_interface_addresses(fib, pg): |
| 292 | lst = [] |
| 293 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 294 | if entry.route.prefix.prefixlen == 128: |
| 295 | path = entry.route.paths[0] |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 296 | if path.sw_if_index == pg.sw_if_index: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 297 | lst.append(str(entry.route.prefix.network_address)) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 298 | return lst |
| 299 | |
| 300 | def get_addresses(self): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 301 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 302 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 303 | return addresses.difference(self.initial_addresses) |
| 304 | |
| 305 | def validate_duid_ll(self, duid): |
| 306 | DUID_LL(duid) |
| 307 | |
| 308 | def validate_packet(self, packet, msg_type, is_resend=False): |
| 309 | try: |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 310 | self.assertEqual(packet.haslayer(msg_type), 1) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 311 | client_duid = packet[DHCP6OptClientId].duid |
| 312 | if self.client_duid is None: |
| 313 | self.client_duid = client_duid |
| 314 | self.validate_duid_ll(client_duid) |
| 315 | else: |
| 316 | self.assertEqual(self.client_duid, client_duid) |
| 317 | if msg_type != DHCP6_Solicit and msg_type != DHCP6_Rebind: |
| 318 | server_duid = packet[DHCP6OptServerId].duid |
| 319 | self.assertEqual(server_duid, self.server_duid) |
| 320 | if is_resend: |
| 321 | self.assertEqual(self.trid, packet[msg_type].trid) |
| 322 | else: |
| 323 | self.trid = packet[msg_type].trid |
| 324 | ip = packet[IPv6] |
| 325 | udp = packet[UDP] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 326 | self.assertEqual(ip.dst, "ff02::1:2") |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 327 | self.assertEqual(udp.sport, 546) |
| 328 | self.assertEqual(udp.dport, 547) |
| 329 | dhcpv6 = packet[msg_type] |
| 330 | elapsed_time = dhcpv6[DHCP6OptElapsedTime] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 331 | if is_resend: |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 332 | self.assertNotEqual(elapsed_time.elapsedtime, 0) |
| 333 | else: |
| 334 | self.assertEqual(elapsed_time.elapsedtime, 0) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 335 | except BaseException: |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 336 | packet.show() |
| 337 | raise |
| 338 | |
| 339 | def wait_for_packet(self, msg_type, timeout=None, is_resend=False): |
| 340 | if timeout is None: |
| 341 | timeout = 3 |
| 342 | rx_list = self.pg0.get_capture(1, timeout=timeout) |
| 343 | packet = rx_list[0] |
| 344 | self.validate_packet(packet, msg_type, is_resend=is_resend) |
| 345 | |
| 346 | def wait_for_solicit(self, timeout=None, is_resend=False): |
| 347 | self.wait_for_packet(DHCP6_Solicit, timeout, is_resend=is_resend) |
| 348 | |
| 349 | def wait_for_request(self, timeout=None, is_resend=False): |
| 350 | self.wait_for_packet(DHCP6_Request, timeout, is_resend=is_resend) |
| 351 | |
| 352 | def wait_for_renew(self, timeout=None, is_resend=False): |
| 353 | self.wait_for_packet(DHCP6_Renew, timeout, is_resend=is_resend) |
| 354 | |
| 355 | def wait_for_rebind(self, timeout=None, is_resend=False): |
| 356 | self.wait_for_packet(DHCP6_Rebind, timeout, is_resend=is_resend) |
| 357 | |
| 358 | def wait_for_release(self, timeout=None, is_resend=False): |
| 359 | self.wait_for_packet(DHCP6_Release, timeout, is_resend=is_resend) |
| 360 | |
| 361 | def send_packet(self, msg_type, t1=None, t2=None, ianaopts=None): |
| 362 | if t1 is None: |
| 363 | t1 = self.T1 |
| 364 | if t2 is None: |
| 365 | t2 = self.T2 |
| 366 | if ianaopts is None: |
| 367 | opt_ia_na = DHCP6OptIA_NA(iaid=1, T1=t1, T2=t2) |
| 368 | else: |
| 369 | opt_ia_na = DHCP6OptIA_NA(iaid=1, T1=t1, T2=t2, ianaopts=ianaopts) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 370 | p = ( |
| 371 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 372 | / IPv6(src=util.mk_ll_addr(self.pg0.remote_mac), dst=self.pg0.local_ip6_ll) |
| 373 | / UDP(sport=547, dport=546) |
| 374 | / msg_type(trid=self.trid) |
| 375 | / DHCP6OptServerId(duid=self.server_duid) |
| 376 | / DHCP6OptClientId(duid=self.client_duid) |
| 377 | / opt_ia_na |
| 378 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 379 | self.pg0.add_stream([p]) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 380 | self.pg_enable_capture(self.pg_interfaces) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 381 | self.pg_start() |
| 382 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 383 | def send_advertise(self, t1=None, t2=None, ianaopts=None): |
| 384 | self.send_packet(DHCP6_Advertise, t1, t2, ianaopts) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 385 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 386 | def send_reply(self, t1=None, t2=None, ianaopts=None): |
| 387 | self.send_packet(DHCP6_Reply, t1, t2, ianaopts) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 388 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 389 | def test_T1_and_T2_timeouts(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 390 | """Test T1 and T2 timeouts""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 391 | |
| 392 | self.wait_for_solicit() |
| 393 | self.send_advertise() |
| 394 | self.wait_for_request() |
| 395 | self.send_reply() |
| 396 | |
| 397 | self.sleep(1) |
| 398 | |
| 399 | self.wait_for_renew() |
| 400 | |
| 401 | self.pg_enable_capture(self.pg_interfaces) |
| 402 | |
| 403 | self.sleep(1) |
| 404 | |
| 405 | self.wait_for_rebind() |
| 406 | |
| 407 | def test_addresses(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 408 | """Test handling of addresses""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 409 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 410 | ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=1, validlft=2) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 411 | |
| 412 | self.wait_for_solicit() |
| 413 | self.send_advertise(t1=20, t2=40, ianaopts=ia_na_opts) |
| 414 | self.wait_for_request() |
| 415 | self.send_reply(t1=20, t2=40, ianaopts=ia_na_opts) |
| 416 | self.sleep(0.1) |
| 417 | |
| 418 | # check FIB for new address |
| 419 | new_addresses = self.get_addresses() |
| 420 | self.assertEqual(len(new_addresses), 1) |
| 421 | addr = list(new_addresses)[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 422 | self.assertEqual(addr, "7:8::2") |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 423 | |
| 424 | self.sleep(2) |
| 425 | |
| 426 | # check that the address is deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 427 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 428 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 429 | new_addresses = addresses.difference(self.initial_addresses) |
| 430 | self.assertEqual(len(new_addresses), 0) |
| 431 | |
| 432 | def test_sending_client_messages_solicit(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 433 | """VPP receives messages from DHCPv6 client""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 434 | |
| 435 | self.wait_for_solicit() |
| 436 | self.send_packet(DHCP6_Solicit) |
| 437 | self.send_packet(DHCP6_Request) |
| 438 | self.send_packet(DHCP6_Renew) |
| 439 | self.send_packet(DHCP6_Rebind) |
| 440 | self.sleep(1) |
| 441 | self.wait_for_solicit(is_resend=True) |
| 442 | |
| 443 | def test_sending_inappropriate_packets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 444 | """Server sends messages with inappropriate message types""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 445 | |
| 446 | self.wait_for_solicit() |
| 447 | self.send_reply() |
| 448 | self.wait_for_solicit(is_resend=True) |
| 449 | self.send_advertise() |
| 450 | self.wait_for_request() |
| 451 | self.send_advertise() |
| 452 | self.wait_for_request(is_resend=True) |
| 453 | self.send_reply() |
| 454 | self.wait_for_renew() |
| 455 | |
| 456 | def test_no_address_available_in_advertise(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 457 | """Advertise message contains NoAddrsAvail status code""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 458 | |
| 459 | self.wait_for_solicit() |
| 460 | noavail = DHCP6OptStatusCode(statuscode=2) # NoAddrsAvail |
| 461 | self.send_advertise(ianaopts=noavail) |
| 462 | self.wait_for_solicit(is_resend=True) |
| 463 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 464 | def test_preferred_greater_than_valid_lifetime(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 465 | """Preferred lifetime is greater than valid lifetime""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 466 | |
| 467 | self.wait_for_solicit() |
| 468 | self.send_advertise() |
| 469 | self.wait_for_request() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 470 | ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=4, validlft=3) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 471 | self.send_reply(ianaopts=ia_na_opts) |
| 472 | |
| 473 | self.sleep(0.5) |
| 474 | |
| 475 | # check FIB contains no addresses |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 476 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 477 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 478 | new_addresses = addresses.difference(self.initial_addresses) |
| 479 | self.assertEqual(len(new_addresses), 0) |
| 480 | |
| 481 | def test_T1_greater_than_T2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 482 | """T1 is greater than T2""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 483 | |
| 484 | self.wait_for_solicit() |
| 485 | self.send_advertise() |
| 486 | self.wait_for_request() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 487 | ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=4, validlft=8) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 488 | self.send_reply(t1=80, t2=40, ianaopts=ia_na_opts) |
| 489 | |
| 490 | self.sleep(0.5) |
| 491 | |
| 492 | # check FIB contains no addresses |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 493 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 494 | addresses = set(self.get_interface_addresses(fib, self.pg0)) |
| 495 | new_addresses = addresses.difference(self.initial_addresses) |
| 496 | self.assertEqual(len(new_addresses), 0) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 497 | |
| 498 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 499 | @tag_fixme_vpp_workers |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 500 | class TestDHCPv6PDControlPlane(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 501 | """DHCPv6 PD Control Plane Test Case""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 502 | |
| 503 | @classmethod |
| 504 | def setUpClass(cls): |
| 505 | super(TestDHCPv6PDControlPlane, cls).setUpClass() |
| 506 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 507 | @classmethod |
| 508 | def tearDownClass(cls): |
| 509 | super(TestDHCPv6PDControlPlane, cls).tearDownClass() |
| 510 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 511 | def setUp(self): |
| 512 | super(TestDHCPv6PDControlPlane, self).setUp() |
| 513 | |
| 514 | self.create_pg_interfaces(range(2)) |
| 515 | self.interfaces = list(self.pg_interfaces) |
| 516 | for i in self.interfaces: |
| 517 | i.admin_up() |
| 518 | |
Juraj Sloboda | d9778c2 | 2018-06-12 10:21:05 +0200 | [diff] [blame] | 519 | self.server_duid = DUID_LL(lladdr=self.pg0.remote_mac) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 520 | self.client_duid = None |
| 521 | self.T1 = 1 |
| 522 | self.T2 = 2 |
| 523 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 524 | fib = self.vapi.ip_route_dump(0, True) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 525 | self.initial_addresses = set(self.get_interface_addresses(fib, self.pg1)) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 526 | |
| 527 | self.pg_enable_capture(self.pg_interfaces) |
| 528 | self.pg_start() |
| 529 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 530 | self.prefix_group = "my-pd-prefix-group" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 531 | |
| 532 | self.vapi.dhcp6_pd_client_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 533 | enable=1, sw_if_index=self.pg0.sw_if_index, prefix_group=self.prefix_group |
| 534 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 535 | |
| 536 | def tearDown(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 537 | self.vapi.dhcp6_pd_client_enable_disable(self.pg0.sw_if_index, enable=0) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 538 | |
| 539 | for i in self.interfaces: |
| 540 | i.admin_down() |
| 541 | |
| 542 | super(TestDHCPv6PDControlPlane, self).tearDown() |
| 543 | |
| 544 | @staticmethod |
| 545 | def get_interface_addresses(fib, pg): |
| 546 | lst = [] |
| 547 | for entry in fib: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 548 | if entry.route.prefix.prefixlen == 128: |
| 549 | path = entry.route.paths[0] |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 550 | if path.sw_if_index == pg.sw_if_index: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 551 | lst.append(str(entry.route.prefix.network_address)) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 552 | return lst |
| 553 | |
| 554 | def get_addresses(self): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 555 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 556 | addresses = set(self.get_interface_addresses(fib, self.pg1)) |
| 557 | return addresses.difference(self.initial_addresses) |
| 558 | |
Juraj Sloboda | d9778c2 | 2018-06-12 10:21:05 +0200 | [diff] [blame] | 559 | def validate_duid_ll(self, duid): |
| 560 | DUID_LL(duid) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 561 | |
| 562 | def validate_packet(self, packet, msg_type, is_resend=False): |
| 563 | try: |
Paul Vinciguerra | 978aa64 | 2018-11-24 22:19:12 -0800 | [diff] [blame] | 564 | self.assertEqual(packet.haslayer(msg_type), 1) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 565 | client_duid = packet[DHCP6OptClientId].duid |
| 566 | if self.client_duid is None: |
| 567 | self.client_duid = client_duid |
Juraj Sloboda | d9778c2 | 2018-06-12 10:21:05 +0200 | [diff] [blame] | 568 | self.validate_duid_ll(client_duid) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 569 | else: |
| 570 | self.assertEqual(self.client_duid, client_duid) |
| 571 | if msg_type != DHCP6_Solicit and msg_type != DHCP6_Rebind: |
| 572 | server_duid = packet[DHCP6OptServerId].duid |
| 573 | self.assertEqual(server_duid, self.server_duid) |
| 574 | if is_resend: |
| 575 | self.assertEqual(self.trid, packet[msg_type].trid) |
| 576 | else: |
| 577 | self.trid = packet[msg_type].trid |
| 578 | ip = packet[IPv6] |
| 579 | udp = packet[UDP] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 580 | self.assertEqual(ip.dst, "ff02::1:2") |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 581 | self.assertEqual(udp.sport, 546) |
| 582 | self.assertEqual(udp.dport, 547) |
| 583 | dhcpv6 = packet[msg_type] |
| 584 | elapsed_time = dhcpv6[DHCP6OptElapsedTime] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 585 | if is_resend: |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 586 | self.assertNotEqual(elapsed_time.elapsedtime, 0) |
| 587 | else: |
| 588 | self.assertEqual(elapsed_time.elapsedtime, 0) |
Jakub Grajciar | 103ba6b | 2019-10-01 11:30:56 +0200 | [diff] [blame] | 589 | except BaseException: |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 590 | packet.show() |
| 591 | raise |
| 592 | |
| 593 | def wait_for_packet(self, msg_type, timeout=None, is_resend=False): |
| 594 | if timeout is None: |
| 595 | timeout = 3 |
| 596 | rx_list = self.pg0.get_capture(1, timeout=timeout) |
| 597 | packet = rx_list[0] |
| 598 | self.validate_packet(packet, msg_type, is_resend=is_resend) |
| 599 | |
| 600 | def wait_for_solicit(self, timeout=None, is_resend=False): |
| 601 | self.wait_for_packet(DHCP6_Solicit, timeout, is_resend=is_resend) |
| 602 | |
| 603 | def wait_for_request(self, timeout=None, is_resend=False): |
| 604 | self.wait_for_packet(DHCP6_Request, timeout, is_resend=is_resend) |
| 605 | |
| 606 | def wait_for_renew(self, timeout=None, is_resend=False): |
| 607 | self.wait_for_packet(DHCP6_Renew, timeout, is_resend=is_resend) |
| 608 | |
| 609 | def wait_for_rebind(self, timeout=None, is_resend=False): |
| 610 | self.wait_for_packet(DHCP6_Rebind, timeout, is_resend=is_resend) |
| 611 | |
| 612 | def wait_for_release(self, timeout=None, is_resend=False): |
| 613 | self.wait_for_packet(DHCP6_Release, timeout, is_resend=is_resend) |
| 614 | |
| 615 | def send_packet(self, msg_type, t1=None, t2=None, iapdopt=None): |
| 616 | if t1 is None: |
| 617 | t1 = self.T1 |
| 618 | if t2 is None: |
| 619 | t2 = self.T2 |
| 620 | if iapdopt is None: |
| 621 | opt_ia_pd = DHCP6OptIA_PD(iaid=1, T1=t1, T2=t2) |
| 622 | else: |
| 623 | opt_ia_pd = DHCP6OptIA_PD(iaid=1, T1=t1, T2=t2, iapdopt=iapdopt) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 624 | p = ( |
| 625 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 626 | / IPv6(src=util.mk_ll_addr(self.pg0.remote_mac), dst=self.pg0.local_ip6_ll) |
| 627 | / UDP(sport=547, dport=546) |
| 628 | / msg_type(trid=self.trid) |
| 629 | / DHCP6OptServerId(duid=self.server_duid) |
| 630 | / DHCP6OptClientId(duid=self.client_duid) |
| 631 | / opt_ia_pd |
| 632 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 633 | self.pg0.add_stream([p]) |
| 634 | self.pg_enable_capture(self.pg_interfaces) |
| 635 | self.pg_start() |
| 636 | |
| 637 | def send_advertise(self, t1=None, t2=None, iapdopt=None): |
| 638 | self.send_packet(DHCP6_Advertise, t1, t2, iapdopt) |
| 639 | |
| 640 | def send_reply(self, t1=None, t2=None, iapdopt=None): |
| 641 | self.send_packet(DHCP6_Reply, t1, t2, iapdopt) |
| 642 | |
| 643 | def test_T1_and_T2_timeouts(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 644 | """Test T1 and T2 timeouts""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 645 | |
| 646 | self.wait_for_solicit() |
| 647 | self.send_advertise() |
| 648 | self.wait_for_request() |
| 649 | self.send_reply() |
| 650 | |
| 651 | self.sleep(1) |
| 652 | |
| 653 | self.wait_for_renew() |
| 654 | |
| 655 | self.pg_enable_capture(self.pg_interfaces) |
| 656 | |
| 657 | self.sleep(1) |
| 658 | |
| 659 | self.wait_for_rebind() |
| 660 | |
| 661 | def test_prefixes(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 662 | """Test handling of prefixes""" |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 663 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 664 | address1 = "::2:0:0:0:405/60" |
| 665 | address2 = "::76:0:0:0:406/62" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 666 | try: |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 667 | self.vapi.ip6_add_del_address_using_prefix( |
| 668 | sw_if_index=self.pg1.sw_if_index, |
| 669 | address_with_prefix=address1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 670 | prefix_group=self.prefix_group, |
| 671 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 672 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 673 | ia_pd_opts = DHCP6OptIAPrefix( |
| 674 | prefix="7:8::", plen=56, preflft=2, validlft=3 |
| 675 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 676 | |
| 677 | self.wait_for_solicit() |
| 678 | self.send_advertise(t1=20, t2=40, iapdopt=ia_pd_opts) |
| 679 | self.wait_for_request() |
| 680 | self.send_reply(t1=20, t2=40, iapdopt=ia_pd_opts) |
| 681 | self.sleep(0.1) |
| 682 | |
| 683 | # check FIB for new address |
| 684 | new_addresses = self.get_addresses() |
| 685 | self.assertEqual(len(new_addresses), 1) |
| 686 | addr = list(new_addresses)[0] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 687 | self.assertEqual(addr, "7:8:0:2::405") |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 688 | |
| 689 | self.sleep(1) |
| 690 | |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 691 | self.vapi.ip6_add_del_address_using_prefix( |
| 692 | sw_if_index=self.pg1.sw_if_index, |
| 693 | address_with_prefix=address2, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 694 | prefix_group=self.prefix_group, |
| 695 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 696 | |
| 697 | self.sleep(1) |
| 698 | |
| 699 | # check FIB contains 2 addresses |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 700 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 701 | addresses = set(self.get_interface_addresses(fib, self.pg1)) |
| 702 | new_addresses = addresses.difference(self.initial_addresses) |
| 703 | self.assertEqual(len(new_addresses), 2) |
| 704 | addr1 = list(new_addresses)[0] |
| 705 | addr2 = list(new_addresses)[1] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 706 | if addr1 == "7:8:0:76::406": |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 707 | addr1, addr2 = addr2, addr1 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 708 | self.assertEqual(addr1, "7:8:0:2::405") |
| 709 | self.assertEqual(addr2, "7:8:0:76::406") |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 710 | |
| 711 | self.sleep(1) |
| 712 | |
| 713 | # check that the addresses are deleted |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 714 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 715 | addresses = set(self.get_interface_addresses(fib, self.pg1)) |
| 716 | new_addresses = addresses.difference(self.initial_addresses) |
| 717 | self.assertEqual(len(new_addresses), 0) |
| 718 | |
| 719 | finally: |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 720 | if address1 is not None: |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 721 | self.vapi.ip6_add_del_address_using_prefix( |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 722 | sw_if_index=self.pg1.sw_if_index, |
| 723 | address_with_prefix=address1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 724 | prefix_group=self.prefix_group, |
| 725 | is_add=0, |
| 726 | ) |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 727 | if address2 is not None: |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 728 | self.vapi.ip6_add_del_address_using_prefix( |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 729 | sw_if_index=self.pg1.sw_if_index, |
| 730 | address_with_prefix=address2, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 731 | prefix_group=self.prefix_group, |
| 732 | is_add=0, |
| 733 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 734 | |
| 735 | def test_sending_client_messages_solicit(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 736 | """VPP receives messages from DHCPv6 client""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 737 | |
| 738 | self.wait_for_solicit() |
| 739 | self.send_packet(DHCP6_Solicit) |
| 740 | self.send_packet(DHCP6_Request) |
| 741 | self.send_packet(DHCP6_Renew) |
| 742 | self.send_packet(DHCP6_Rebind) |
| 743 | self.sleep(1) |
| 744 | self.wait_for_solicit(is_resend=True) |
| 745 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 746 | def test_sending_inappropriate_packets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 747 | """Server sends messages with inappropriate message types""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 748 | |
| 749 | self.wait_for_solicit() |
| 750 | self.send_reply() |
| 751 | self.wait_for_solicit(is_resend=True) |
| 752 | self.send_advertise() |
| 753 | self.wait_for_request() |
| 754 | self.send_advertise() |
| 755 | self.wait_for_request(is_resend=True) |
| 756 | self.send_reply() |
| 757 | self.wait_for_renew() |
| 758 | |
| 759 | def test_no_prefix_available_in_advertise(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 760 | """Advertise message contains NoPrefixAvail status code""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 761 | |
| 762 | self.wait_for_solicit() |
| 763 | noavail = DHCP6OptStatusCode(statuscode=6) # NoPrefixAvail |
| 764 | self.send_advertise(iapdopt=noavail) |
| 765 | self.wait_for_solicit(is_resend=True) |
| 766 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 767 | def test_preferred_greater_than_valid_lifetime(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 768 | """Preferred lifetime is greater than valid lifetime""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 769 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 770 | address1 = "::2:0:0:0:405/60" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 771 | try: |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 772 | self.vapi.ip6_add_del_address_using_prefix( |
| 773 | sw_if_index=self.pg1.sw_if_index, |
| 774 | address_with_prefix=address1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 775 | prefix_group=self.prefix_group, |
| 776 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 777 | |
| 778 | self.wait_for_solicit() |
| 779 | self.send_advertise() |
| 780 | self.wait_for_request() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 781 | ia_pd_opts = DHCP6OptIAPrefix( |
| 782 | prefix="7:8::", plen=56, preflft=4, validlft=3 |
| 783 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 784 | self.send_reply(iapdopt=ia_pd_opts) |
| 785 | |
| 786 | self.sleep(0.5) |
| 787 | |
| 788 | # check FIB contains no addresses |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 789 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 790 | addresses = set(self.get_interface_addresses(fib, self.pg1)) |
| 791 | new_addresses = addresses.difference(self.initial_addresses) |
| 792 | self.assertEqual(len(new_addresses), 0) |
| 793 | |
| 794 | finally: |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 795 | self.vapi.ip6_add_del_address_using_prefix( |
| 796 | sw_if_index=self.pg1.sw_if_index, |
| 797 | address_with_prefix=address1, |
| 798 | prefix_group=self.prefix_group, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 799 | is_add=0, |
| 800 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 801 | |
| 802 | def test_T1_greater_than_T2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 803 | """T1 is greater than T2""" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 804 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 805 | address1 = "::2:0:0:0:405/60" |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 806 | try: |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 807 | self.vapi.ip6_add_del_address_using_prefix( |
| 808 | sw_if_index=self.pg1.sw_if_index, |
| 809 | address_with_prefix=address1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 810 | prefix_group=self.prefix_group, |
| 811 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 812 | |
| 813 | self.wait_for_solicit() |
| 814 | self.send_advertise() |
| 815 | self.wait_for_request() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 816 | ia_pd_opts = DHCP6OptIAPrefix( |
| 817 | prefix="7:8::", plen=56, preflft=4, validlft=8 |
| 818 | ) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 819 | self.send_reply(t1=80, t2=40, iapdopt=ia_pd_opts) |
| 820 | |
| 821 | self.sleep(0.5) |
| 822 | |
| 823 | # check FIB contains no addresses |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 824 | fib = self.vapi.ip_route_dump(0, True) |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 825 | addresses = set(self.get_interface_addresses(fib, self.pg1)) |
| 826 | new_addresses = addresses.difference(self.initial_addresses) |
| 827 | self.assertEqual(len(new_addresses), 0) |
| 828 | |
| 829 | finally: |
Jakub Grajciar | d526283 | 2019-09-30 13:06:48 +0200 | [diff] [blame] | 830 | self.vapi.ip6_add_del_address_using_prefix( |
| 831 | sw_if_index=self.pg1.sw_if_index, |
| 832 | prefix_group=self.prefix_group, |
| 833 | address_with_prefix=address1, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 834 | is_add=False, |
| 835 | ) |