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