blob: 1328a62e1d30aa26137d2d24472f3b04a5be0647 [file] [log] [blame]
snaramre5d4b8912019-12-13 23:39:35 +00001from socket import AF_INET6, inet_ntop, inet_pton
Paul Vinciguerrae8fece82019-02-28 15:34:00 -08002
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02003from 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 Sloboda81119e82018-05-25 14:02:20 +020022from scapy.layers.inet6 import IPv6, Ether, UDP
Paul Vinciguerrae8fece82019-02-28 15:34:00 -080023
Juraj Sloboda81119e82018-05-25 14:02:20 +020024from framework import VppTestCase
Dave Wallace8800f732023-08-31 00:47:44 -040025from asfframework import tag_fixme_vpp_workers, tag_run_solo
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020026from vpp_papi import VppEnum
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000027from config import config
Paul Vinciguerrae8fece82019-02-28 15:34:00 -080028import util
Neale Ranns02bfd642019-10-07 00:39:28 -070029import os
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000030import unittest
Juraj Sloboda81119e82018-05-25 14:02:20 +020031
32
33def ip6_normalize(ip6):
34 return inet_ntop(AF_INET6, inet_pton(AF_INET6, ip6))
35
36
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000037@unittest.skipIf("dhcp" in config.excluded_plugins, "Exclude DHCP plugin tests")
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020038class TestDHCPv6DataPlane(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020039 """DHCPv6 Data Plane Test Case"""
Juraj Sloboda81119e82018-05-25 14:02:20 +020040
41 @classmethod
42 def setUpClass(cls):
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020043 super(TestDHCPv6DataPlane, cls).setUpClass()
Juraj Sloboda81119e82018-05-25 14:02:20 +020044
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070045 @classmethod
46 def tearDownClass(cls):
47 super(TestDHCPv6DataPlane, cls).tearDownClass()
48
Juraj Sloboda81119e82018-05-25 14:02:20 +020049 def setUp(self):
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020050 super(TestDHCPv6DataPlane, self).setUp()
Juraj Sloboda81119e82018-05-25 14:02:20 +020051
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 Slobodad9778c22018-06-12 10:21:05 +020058 self.server_duid = DUID_LL(lladdr=self.pg0.remote_mac)
Juraj Sloboda81119e82018-05-25 14:02:20 +020059
60 def tearDown(self):
61 for i in self.interfaces:
62 i.unconfig_ip6()
63 i.admin_down()
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020064 super(TestDHCPv6DataPlane, self).tearDown()
Juraj Sloboda81119e82018-05-25 14:02:20 +020065
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020066 def test_dhcp_ia_na_send_solicit_receive_advertise(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020067 """Verify DHCPv6 IA NA Solicit packet and Advertise event"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020068
Neale Ranns02bfd642019-10-07 00:39:28 -070069 self.vapi.dhcp6_clients_enable_disable(enable=1)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020070
71 self.pg_enable_capture(self.pg_interfaces)
72 self.pg_start()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020073 address = {"address": "1:2:3::5", "preferred_time": 60, "valid_time": 120}
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020074 self.vapi.dhcp6_send_client_message(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020075 server_index=0xFFFFFFFF,
Neale Ranns02bfd642019-10-07 00:39:28 -070076 mrc=1,
Jakub Grajciar103ba6b2019-10-01 11:30:56 +020077 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 Sekerad9b0c6f2022-04-26 19:02:15 +020082 n_addresses=len([address]),
83 )
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020084 rx_list = self.pg0.get_capture(1)
85 self.assertEqual(len(rx_list), 1)
86 packet = rx_list[0]
87
Paul Vinciguerra978aa642018-11-24 22:19:12 -080088 self.assertEqual(packet.haslayer(IPv6), 1)
89 self.assertEqual(packet[IPv6].haslayer(DHCP6_Solicit), 1)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +020090
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200105 self.assert_equal(address.addr, "1:2:3::5")
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200106 self.assert_equal(address.preflft, 60)
107 self.assert_equal(address.validlft, 120)
108
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200109 self.vapi.want_dhcp6_reply_events(enable_disable=1, pid=os.getpid())
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200110
111 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200112 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 Slobodadd3b8f72018-05-04 14:20:06 +0200126 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 Grajciar103ba6b2019-10-01 11:30:56 +0200137 address = ia_na_opts.getfieldval("addr")
138 self.assert_equal(str(reported_address.address), address)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200139 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 Slobodadd3b8f72018-05-04 14:20:06 +0200145
146 finally:
147 self.vapi.want_dhcp6_reply_events(enable_disable=0)
Neale Ranns02bfd642019-10-07 00:39:28 -0700148 self.vapi.dhcp6_clients_enable_disable(enable=0)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200149
150 def test_dhcp_pd_send_solicit_receive_advertise(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200151 """Verify DHCPv6 PD Solicit packet and Advertise event"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200152
Neale Ranns02bfd642019-10-07 00:39:28 -0700153 self.vapi.dhcp6_clients_enable_disable(enable=1)
Juraj Slobodad9778c22018-06-12 10:21:05 +0200154
Juraj Sloboda81119e82018-05-25 14:02:20 +0200155 self.pg_enable_capture(self.pg_interfaces)
156 self.pg_start()
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200157
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200158 prefix = {
159 "prefix": {"address": "1:2:3::", "len": 50},
160 "preferred_time": 60,
161 "valid_time": 120,
162 }
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200163 prefixes = [prefix]
164 self.vapi.dhcp6_pd_send_client_message(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200165 server_index=0xFFFFFFFF,
Neale Ranns02bfd642019-10-07 00:39:28 -0700166 mrc=1,
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200167 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200172 n_prefixes=len(prefixes),
173 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200174 rx_list = self.pg0.get_capture(1)
175 self.assertEqual(len(rx_list), 1)
176 packet = rx_list[0]
177
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800178 self.assertEqual(packet.haslayer(IPv6), 1)
179 self.assertEqual(packet[IPv6].haslayer(DHCP6_Solicit), 1)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200180
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200195 self.assert_equal(prefix.prefix, "1:2:3::")
Juraj Sloboda81119e82018-05-25 14:02:20 +0200196 self.assert_equal(prefix.plen, 50)
197 self.assert_equal(prefix.preflft, 60)
198 self.assert_equal(prefix.validlft, 120)
199
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200200 self.vapi.want_dhcp6_pd_reply_events(enable_disable=1, pid=os.getpid())
Juraj Sloboda81119e82018-05-25 14:02:20 +0200201
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200202 try:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200203 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 Slobodadd3b8f72018-05-04 14:20:06 +0200219 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 Grajciar103ba6b2019-10-01 11:30:56 +0200230 prefix = ia_pd_opts.getfieldval("prefix")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200231 self.assert_equal(str(reported_prefix.prefix).split("/")[0], prefix)
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200232 self.assert_equal(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200233 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 Slobodadd3b8f72018-05-04 14:20:06 +0200242
243 finally:
244 self.vapi.want_dhcp6_pd_reply_events(enable_disable=0)
Neale Ranns02bfd642019-10-07 00:39:28 -0700245 self.vapi.dhcp6_clients_enable_disable(enable=0)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200246
247
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000248@tag_run_solo
Dmitry Valter34fa0ce2024-03-11 10:38:46 +0000249@unittest.skipIf("dhcp" in config.excluded_plugins, "Exclude DHCP plugin tests")
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200250class TestDHCPv6IANAControlPlane(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200251 """DHCPv6 IA NA Control Plane Test Case"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200252
253 @classmethod
254 def setUpClass(cls):
255 super(TestDHCPv6IANAControlPlane, cls).setUpClass()
256
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700257 @classmethod
258 def tearDownClass(cls):
259 super(TestDHCPv6IANAControlPlane, cls).tearDownClass()
260
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200261 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 Ranns097fa662018-05-01 05:17:55 -0700274 fib = self.vapi.ip_route_dump(0, True)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200275 self.initial_addresses = set(self.get_interface_addresses(fib, self.pg0))
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200276
277 self.pg_enable_capture(self.pg_interfaces)
278 self.pg_start()
279
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200280 self.vapi.dhcp6_client_enable_disable(
281 sw_if_index=self.pg0.sw_if_index, enable=1
282 )
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200283
284 def tearDown(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200285 self.vapi.dhcp6_client_enable_disable(
286 sw_if_index=self.pg0.sw_if_index, enable=0
287 )
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200288
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 Ranns097fa662018-05-01 05:17:55 -0700298 if entry.route.prefix.prefixlen == 128:
299 path = entry.route.paths[0]
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200300 if path.sw_if_index == pg.sw_if_index:
Neale Ranns097fa662018-05-01 05:17:55 -0700301 lst.append(str(entry.route.prefix.network_address))
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200302 return lst
303
304 def get_addresses(self):
Neale Ranns097fa662018-05-01 05:17:55 -0700305 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200306 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 Wallacecf9356d2024-07-23 01:28:19 -0400310 DUID_LL(bytes(duid))
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200311
312 def validate_packet(self, packet, msg_type, is_resend=False):
313 try:
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800314 self.assertEqual(packet.haslayer(msg_type), 1)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200315 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200330 self.assertEqual(ip.dst, "ff02::1:2")
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200331 self.assertEqual(udp.sport, 546)
332 self.assertEqual(udp.dport, 547)
333 dhcpv6 = packet[msg_type]
334 elapsed_time = dhcpv6[DHCP6OptElapsedTime]
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200335 if is_resend:
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200336 self.assertNotEqual(elapsed_time.elapsedtime, 0)
337 else:
338 self.assertEqual(elapsed_time.elapsedtime, 0)
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200339 except BaseException:
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200340 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200374 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 Sloboda81119e82018-05-25 14:02:20 +0200383 self.pg0.add_stream([p])
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200384 self.pg_enable_capture(self.pg_interfaces)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200385 self.pg_start()
386
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200387 def send_advertise(self, t1=None, t2=None, ianaopts=None):
388 self.send_packet(DHCP6_Advertise, t1, t2, ianaopts)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200389
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200390 def send_reply(self, t1=None, t2=None, ianaopts=None):
391 self.send_packet(DHCP6_Reply, t1, t2, ianaopts)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200392
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200393 def test_T1_and_T2_timeouts(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200394 """Test T1 and T2 timeouts"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200395
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200412 """Test handling of addresses"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200413
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200414 ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=1, validlft=2)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200415
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200426 self.assertEqual(addr, "7:8::2")
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200427
428 self.sleep(2)
429
430 # check that the address is deleted
Neale Ranns097fa662018-05-01 05:17:55 -0700431 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200432 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200437 """VPP receives messages from DHCPv6 client"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200438
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200448 """Server sends messages with inappropriate message types"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200449
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200461 """Advertise message contains NoAddrsAvail status code"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200462
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 Vinciguerra8feeaff2019-03-27 11:25:48 -0700468 def test_preferred_greater_than_valid_lifetime(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200469 """Preferred lifetime is greater than valid lifetime"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200470
471 self.wait_for_solicit()
472 self.send_advertise()
473 self.wait_for_request()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200474 ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=4, validlft=3)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200475 self.send_reply(ianaopts=ia_na_opts)
476
477 self.sleep(0.5)
478
479 # check FIB contains no addresses
Neale Ranns097fa662018-05-01 05:17:55 -0700480 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200481 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200486 """T1 is greater than T2"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200487
488 self.wait_for_solicit()
489 self.send_advertise()
490 self.wait_for_request()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200491 ia_na_opts = DHCP6OptIAAddress(addr="7:8::2", preflft=4, validlft=8)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200492 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 Ranns097fa662018-05-01 05:17:55 -0700497 fib = self.vapi.ip_route_dump(0, True)
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200498 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 Sloboda81119e82018-05-25 14:02:20 +0200501
502
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +0000503@tag_fixme_vpp_workers
Dmitry Valter34fa0ce2024-03-11 10:38:46 +0000504@unittest.skipIf("dhcp" in config.excluded_plugins, "Exclude DHCP plugin tests")
Juraj Sloboda81119e82018-05-25 14:02:20 +0200505class TestDHCPv6PDControlPlane(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200506 """DHCPv6 PD Control Plane Test Case"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200507
508 @classmethod
509 def setUpClass(cls):
510 super(TestDHCPv6PDControlPlane, cls).setUpClass()
511
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700512 @classmethod
513 def tearDownClass(cls):
514 super(TestDHCPv6PDControlPlane, cls).tearDownClass()
515
Juraj Sloboda81119e82018-05-25 14:02:20 +0200516 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 Slobodad9778c22018-06-12 10:21:05 +0200524 self.server_duid = DUID_LL(lladdr=self.pg0.remote_mac)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200525 self.client_duid = None
526 self.T1 = 1
527 self.T2 = 2
528
Neale Ranns097fa662018-05-01 05:17:55 -0700529 fib = self.vapi.ip_route_dump(0, True)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200530 self.initial_addresses = set(self.get_interface_addresses(fib, self.pg1))
Juraj Sloboda81119e82018-05-25 14:02:20 +0200531
532 self.pg_enable_capture(self.pg_interfaces)
533 self.pg_start()
534
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200535 self.prefix_group = "my-pd-prefix-group"
Juraj Sloboda81119e82018-05-25 14:02:20 +0200536
537 self.vapi.dhcp6_pd_client_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200538 enable=1, sw_if_index=self.pg0.sw_if_index, prefix_group=self.prefix_group
539 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200540
541 def tearDown(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200542 self.vapi.dhcp6_pd_client_enable_disable(self.pg0.sw_if_index, enable=0)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200543
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 Ranns097fa662018-05-01 05:17:55 -0700553 if entry.route.prefix.prefixlen == 128:
554 path = entry.route.paths[0]
Juraj Sloboda81119e82018-05-25 14:02:20 +0200555 if path.sw_if_index == pg.sw_if_index:
Neale Ranns097fa662018-05-01 05:17:55 -0700556 lst.append(str(entry.route.prefix.network_address))
Juraj Sloboda81119e82018-05-25 14:02:20 +0200557 return lst
558
559 def get_addresses(self):
Neale Ranns097fa662018-05-01 05:17:55 -0700560 fib = self.vapi.ip_route_dump(0, True)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200561 addresses = set(self.get_interface_addresses(fib, self.pg1))
562 return addresses.difference(self.initial_addresses)
563
Juraj Slobodad9778c22018-06-12 10:21:05 +0200564 def validate_duid_ll(self, duid):
Dave Wallacecf9356d2024-07-23 01:28:19 -0400565 DUID_LL(bytes(duid))
Juraj Sloboda81119e82018-05-25 14:02:20 +0200566
567 def validate_packet(self, packet, msg_type, is_resend=False):
568 try:
Paul Vinciguerra978aa642018-11-24 22:19:12 -0800569 self.assertEqual(packet.haslayer(msg_type), 1)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200570 client_duid = packet[DHCP6OptClientId].duid
571 if self.client_duid is None:
572 self.client_duid = client_duid
Juraj Slobodad9778c22018-06-12 10:21:05 +0200573 self.validate_duid_ll(client_duid)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200574 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200585 self.assertEqual(ip.dst, "ff02::1:2")
Juraj Sloboda81119e82018-05-25 14:02:20 +0200586 self.assertEqual(udp.sport, 546)
587 self.assertEqual(udp.dport, 547)
588 dhcpv6 = packet[msg_type]
589 elapsed_time = dhcpv6[DHCP6OptElapsedTime]
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200590 if is_resend:
Juraj Sloboda81119e82018-05-25 14:02:20 +0200591 self.assertNotEqual(elapsed_time.elapsedtime, 0)
592 else:
593 self.assertEqual(elapsed_time.elapsedtime, 0)
Jakub Grajciar103ba6b2019-10-01 11:30:56 +0200594 except BaseException:
Juraj Sloboda81119e82018-05-25 14:02:20 +0200595 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200629 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 Sloboda81119e82018-05-25 14:02:20 +0200638 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200649 """Test T1 and T2 timeouts"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200650
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200667 """Test handling of prefixes"""
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200668
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200669 address1 = "::2:0:0:0:405/60"
670 address2 = "::76:0:0:0:406/62"
Juraj Sloboda81119e82018-05-25 14:02:20 +0200671 try:
Jakub Grajciard5262832019-09-30 13:06:48 +0200672 self.vapi.ip6_add_del_address_using_prefix(
673 sw_if_index=self.pg1.sw_if_index,
674 address_with_prefix=address1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200675 prefix_group=self.prefix_group,
676 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200677
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200678 ia_pd_opts = DHCP6OptIAPrefix(
679 prefix="7:8::", plen=56, preflft=2, validlft=3
680 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200681
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200692 self.assertEqual(addr, "7:8:0:2::405")
Juraj Sloboda81119e82018-05-25 14:02:20 +0200693
694 self.sleep(1)
695
Jakub Grajciard5262832019-09-30 13:06:48 +0200696 self.vapi.ip6_add_del_address_using_prefix(
697 sw_if_index=self.pg1.sw_if_index,
698 address_with_prefix=address2,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200699 prefix_group=self.prefix_group,
700 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200701
702 self.sleep(1)
703
704 # check FIB contains 2 addresses
Neale Ranns097fa662018-05-01 05:17:55 -0700705 fib = self.vapi.ip_route_dump(0, True)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200706 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200711 if addr1 == "7:8:0:76::406":
Juraj Sloboda81119e82018-05-25 14:02:20 +0200712 addr1, addr2 = addr2, addr1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200713 self.assertEqual(addr1, "7:8:0:2::405")
714 self.assertEqual(addr2, "7:8:0:76::406")
Juraj Sloboda81119e82018-05-25 14:02:20 +0200715
716 self.sleep(1)
717
718 # check that the addresses are deleted
Neale Ranns097fa662018-05-01 05:17:55 -0700719 fib = self.vapi.ip_route_dump(0, True)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200720 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 Grajciard5262832019-09-30 13:06:48 +0200725 if address1 is not None:
Juraj Sloboda81119e82018-05-25 14:02:20 +0200726 self.vapi.ip6_add_del_address_using_prefix(
Jakub Grajciard5262832019-09-30 13:06:48 +0200727 sw_if_index=self.pg1.sw_if_index,
728 address_with_prefix=address1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200729 prefix_group=self.prefix_group,
730 is_add=0,
731 )
Jakub Grajciard5262832019-09-30 13:06:48 +0200732 if address2 is not None:
Juraj Sloboda81119e82018-05-25 14:02:20 +0200733 self.vapi.ip6_add_del_address_using_prefix(
Jakub Grajciard5262832019-09-30 13:06:48 +0200734 sw_if_index=self.pg1.sw_if_index,
735 address_with_prefix=address2,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200736 prefix_group=self.prefix_group,
737 is_add=0,
738 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200739
740 def test_sending_client_messages_solicit(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200741 """VPP receives messages from DHCPv6 client"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200742
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 Slobodadd3b8f72018-05-04 14:20:06 +0200751 def test_sending_inappropriate_packets(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200752 """Server sends messages with inappropriate message types"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200753
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200765 """Advertise message contains NoPrefixAvail status code"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200766
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 Vinciguerra8feeaff2019-03-27 11:25:48 -0700772 def test_preferred_greater_than_valid_lifetime(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200773 """Preferred lifetime is greater than valid lifetime"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200774
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200775 address1 = "::2:0:0:0:405/60"
Juraj Sloboda81119e82018-05-25 14:02:20 +0200776 try:
Jakub Grajciard5262832019-09-30 13:06:48 +0200777 self.vapi.ip6_add_del_address_using_prefix(
778 sw_if_index=self.pg1.sw_if_index,
779 address_with_prefix=address1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200780 prefix_group=self.prefix_group,
781 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200782
783 self.wait_for_solicit()
784 self.send_advertise()
785 self.wait_for_request()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200786 ia_pd_opts = DHCP6OptIAPrefix(
787 prefix="7:8::", plen=56, preflft=4, validlft=3
788 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200789 self.send_reply(iapdopt=ia_pd_opts)
790
791 self.sleep(0.5)
792
793 # check FIB contains no addresses
Neale Ranns097fa662018-05-01 05:17:55 -0700794 fib = self.vapi.ip_route_dump(0, True)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200795 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 Grajciard5262832019-09-30 13:06:48 +0200800 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200804 is_add=0,
805 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200806
807 def test_T1_greater_than_T2(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200808 """T1 is greater than T2"""
Juraj Sloboda81119e82018-05-25 14:02:20 +0200809
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200810 address1 = "::2:0:0:0:405/60"
Juraj Sloboda81119e82018-05-25 14:02:20 +0200811 try:
Jakub Grajciard5262832019-09-30 13:06:48 +0200812 self.vapi.ip6_add_del_address_using_prefix(
813 sw_if_index=self.pg1.sw_if_index,
814 address_with_prefix=address1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200815 prefix_group=self.prefix_group,
816 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200817
818 self.wait_for_solicit()
819 self.send_advertise()
820 self.wait_for_request()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200821 ia_pd_opts = DHCP6OptIAPrefix(
822 prefix="7:8::", plen=56, preflft=4, validlft=8
823 )
Juraj Sloboda81119e82018-05-25 14:02:20 +0200824 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 Ranns097fa662018-05-01 05:17:55 -0700829 fib = self.vapi.ip_route_dump(0, True)
Juraj Sloboda81119e82018-05-25 14:02:20 +0200830 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 Grajciard5262832019-09-30 13:06:48 +0200835 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200839 is_add=False,
840 )