A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dhcp6-options.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kavya Bhat <kavyabhat@gmail.com>
7 *
8 */
9
10#ifndef DHCP6_OPTIONS_H
11#define DHCP6_OPTIONS_H
12
13#include "dhcp6-duid.h"
14
15#include "ns3/address.h"
16#include "ns3/buffer.h"
17#include "ns3/header.h"
18#include "ns3/ipv6-address.h"
19#include "ns3/node.h"
20#include "ns3/nstime.h"
21#include "ns3/ptr.h"
22#include "ns3/random-variable-stream.h"
23
24namespace ns3
25{
26
27/**
28 * @ingroup dhcp6
29 *
30 * @class Options
31 * @brief Implements the functionality of DHCPv6 options
32 */
34{
35 public:
36 /**
37 * Enum to identify the status code of the operation.
38 * These symbols and values are defined in [RFC 8415,
39 * section 21.13](https://datatracker.ietf.org/doc/html/rfc8415#section-21.13)
40 */
42 {
43 Success = 0,
44 UnspecFail = 1,
45 NoAddrsAvail = 2,
46 NoBinding = 3,
47 NotOnLink = 4,
48 UseMulticast = 5,
49 NoPrefixAvail = 6,
50 };
51
52 /**
53 * Enum to identify the option type.
54 * These symbols and values are defined in [RFC 8415, section 21]
55 * (https://datatracker.ietf.org/doc/html/rfc8415#section-21)
56 */
57 enum class OptionType
58 {
59 OPTION_INIT = 0, // Added for initialization
62 OPTION_IA_NA = 3,
63 OPTION_IA_TA = 4,
64 OPTION_IAADDR = 5,
65 OPTION_ORO = 6,
69 OPTION_AUTH = 11,
70 OPTION_UNICAST = 12,
79 OPTION_IA_PD = 25,
80 OPTION_IAPREFIX = 26,
84 };
85
86 /**
87 * @brief Default constructor.
88 */
89 Options();
90
91 /**
92 * @brief Constructor.
93 * @param code The option code.
94 * @param length The option length.
95 */
96 Options(OptionType code, uint16_t length);
97
98 /**
99 * @brief Get the option code.
100 * @return option code
101 */
102 OptionType GetOptionCode() const;
103
104 /**
105 * @brief Set the option code.
106 * @param code The option code to be added.
107 */
108 void SetOptionCode(OptionType code);
109
110 /**
111 * @brief Get the option length.
112 * @return option length
113 */
114 uint16_t GetOptionLength() const;
115
116 /**
117 * @brief Set the option length.
118 * @param length The option length to be parsed.
119 */
120 void SetOptionLength(uint16_t length);
121
122 private:
123 OptionType m_optionCode; //!< Option code
124 uint16_t m_optionLength; //!< Option length
125};
126
127/**
128 * @ingroup dhcp6
129 *
130 * @class IdentifierOption
131 * @brief Implements the client and server identifier options.
132 */
134{
135 public:
136 /**
137 * Default constructor.
138 */
140
141 /**
142 * @brief Constructor.
143 * @param hardwareType The hardware type.
144 * @param linkLayerAddress The link-layer address.
145 * @param time The time at which the DUID is generated.
146 */
147 IdentifierOption(uint16_t hardwareType, Address linkLayerAddress, Time time = Time());
148
149 /**
150 * @brief Set the DUID.
151 * @param duid The DUID.
152 */
153 void SetDuid(Duid duid);
154
155 /**
156 * @brief Get the DUID object.
157 * @return the DUID.
158 */
159 Duid GetDuid() const;
160
161 private:
162 Duid m_duid; //!< Unique identifier of the node.
163};
164
165/**
166 * @ingroup dhcp6
167 *
168 * @class StatusCodeOption
169 * @brief Implements the Status Code option.
170 */
172{
173 public:
174 /**
175 * @brief Default constructor.
176 */
178
179 /**
180 * @brief Get the status code of the operation.
181 * @return the status code.
182 */
184
185 /**
186 * @brief Set the status code of the operation.
187 * @param statusCode the status code of the performed operation.
188 */
189 void SetStatusCode(StatusCodeValues statusCode);
190
191 /**
192 * @brief Get the status message of the operation.
193 * @return the status message
194 */
195 std::string GetStatusMessage() const;
196
197 /**
198 * @brief Set the status message of the operation.
199 * @param statusMessage the status message of the operation.
200 */
201 void SetStatusMessage(std::string statusMessage);
202
203 private:
204 /**
205 * The status code of an operation involving the IA_NA, IA_TA or
206 * IA address.
207 */
209
210 /**
211 * The status message of the operation. This is to be UTF-8 encoded
212 * as per RFC 3629.
213 */
214 std::string m_statusMessage;
215};
216
217/**
218 * @ingroup dhcp6
219 *
220 * @class IaAddressOption
221 * @brief Implements the IA Address options.
222 */
224{
225 public:
226 /**
227 * @brief Default constructor.
228 */
230
231 /**
232 * @brief Constructor.
233 * @param iaAddress The IA Address.
234 * @param preferredLifetime The preferred lifetime of the address.
235 * @param validLifetime The valid lifetime of the address.
236 */
237 IaAddressOption(Ipv6Address iaAddress, uint32_t preferredLifetime, uint32_t validLifetime);
238
239 /**
240 * @brief Get the IA Address.
241 * @return the IPv6 address of the Identity Association
242 */
244
245 /**
246 * @brief Set the IA Address.
247 * @param iaAddress the IPv6 address of this Identity Association.
248 */
249 void SetIaAddress(Ipv6Address iaAddress);
250
251 /**
252 * @brief Get the preferred lifetime.
253 * @return the preferred lifetime
254 */
256
257 /**
258 * @brief Set the preferred lifetime.
259 * @param preferredLifetime the preferred lifetime for this address.
260 */
261 void SetPreferredLifetime(uint32_t preferredLifetime);
262
263 /**
264 * @brief Get the valid lifetime.
265 * @return the lifetime for which the address is valid.
266 */
268
269 /**
270 * @brief Set the valid lifetime.
271 * @param validLifetime the lifetime for which the address is valid.
272 */
273 void SetValidLifetime(uint32_t validLifetime);
274
275 private:
276 Ipv6Address m_iaAddress; //!< the IPv6 address offered to the client.
277 uint32_t m_preferredLifetime; //!< The preferred lifetime of the address, in seconds.
278 uint32_t m_validLifetime; //!< The valid lifetime of the address, in seconds.
279
280 /// (optional) The status code of any operation involving this address
282};
283
284/**
285 * @ingroup dhcp6
286 *
287 * @class IaOptions
288 * @brief Implements the IANA and IATA options.
289 */
290class IaOptions : public Options
291{
292 public:
293 /**
294 * @brief Default constructor.
295 */
296 IaOptions();
297
298 /**
299 * @brief Get the unique identifier for the given IANA or IATA.
300 * @return the ID of the IANA or IATA
301 */
302 uint32_t GetIaid() const;
303
304 /**
305 * @brief Set the unique identifier for the given IANA or IATA.
306 * @param iaid the unique ID for the IANA or IATA.
307 */
308 void SetIaid(uint32_t iaid);
309
310 /**
311 * @brief Get the time interval in seconds after which the client contacts
312 * the server which provided the address to extend the lifetime.
313 * @return the time interval T1
314 */
315 uint32_t GetT1() const;
316
317 /**
318 * @brief Set the time interval in seconds after which the client contacts
319 * the server which provided the address to extend the lifetime.
320 * @param t1 the time interval in seconds.
321 */
322 void SetT1(uint32_t t1);
323
324 /**
325 * @brief Get the time interval in seconds after which the client contacts
326 * any available server to extend the address lifetime.
327 * @return the time interval T2
328 */
329 uint32_t GetT2() const;
330
331 /**
332 * @brief Set the time interval in seconds after which the client contacts
333 * any available server to extend the address lifetime.
334 * @param t2 time interval in seconds.
335 */
336 void SetT2(uint32_t t2);
337
338 /// The list of IA Address options associated with the IANA.
339 std::vector<IaAddressOption> m_iaAddressOption;
340
341 private:
342 /// The unique identifier for the given IA_NA or IA_TA.
344
345 /**
346 * The time interval in seconds after which the client contacts the
347 * server which provided the address to extend the lifetime.
348 */
350
351 /**
352 * The time interval in seconds after which the client contacts any
353 * available server to extend the address lifetime.
354 */
356
357 /// (optional) The status code of any operation involving the IANA.
359};
360
361/**
362 * @ingroup dhcp6
363 *
364 * @class RequestOptions
365 * @brief Implements the Option Request option.
366 */
368{
369 public:
370 /**
371 * @brief Constructor.
372 */
374
375 /**
376 * @brief Get the option values
377 * @return requested option list.
378 */
379 std::vector<OptionType> GetRequestedOptions() const;
380
381 /**
382 * @brief Set the option values.
383 * @param requestedOption option to be requested from the server.
384 */
385 void AddRequestedOption(OptionType requestedOption);
386
387 private:
388 std::vector<OptionType> m_requestedOptions; //!< List of requested options.
389};
390
391/**
392 * @ingroup dhcp6
393 *
394 * @class IntegerOptions
395 * @brief Implements the Preference and Elapsed Time options.
396 */
397template <typename T>
399{
400 public:
401 /**
402 * @brief Constructor.
403 */
405
406 /**
407 * @brief Get the option value
408 * @return elapsed time or preference value.
409 */
410 T GetOptionValue() const;
411
412 /**
413 * @brief Set the option value.
414 * @param optionValue elapsed time or preference value.
415 */
416 void SetOptionValue(T optionValue);
417
418 private:
419 /// Indicates the elapsed time or preference value.
421};
422
423/**
424 * @ingroup dhcp6
425 *
426 * @class ServerUnicastOption
427 * @brief Implements the Server Unicast option.
428 */
430{
431 public:
433
434 /**
435 * @brief Get the server address.
436 * @return The 128 bit server address.
437 */
439
440 /**
441 * @brief Set the server address.
442 * @param serverAddress the 128-bit server address.
443 */
444 void SetServerAddress(Ipv6Address serverAddress);
445
446 private:
447 /**
448 * The 128-bit server address to which the client should send
449 * unicast messages.
450 */
452};
453
454/**
455 * @ingroup dhcp6
456 * Create the typedef PreferenceOption with T as uint8_t
457 */
459
460/**
461 * @ingroup dhcp6
462 * Create the typedef ElapsedTimeOption with T as uint16_t
463 */
465
466} // namespace ns3
467
468#endif
a polymophic address class
Definition address.h:90
Implements the unique identifier for DHCPv6.
Definition dhcp6-duid.h:27
Implements the IA Address options.
void SetPreferredLifetime(uint32_t preferredLifetime)
Set the preferred lifetime.
IaAddressOption()
Default constructor.
StatusCodeOption m_statusCodeOption
(optional) The status code of any operation involving this address
Ipv6Address GetIaAddress() const
Get the IA Address.
uint32_t GetValidLifetime() const
Get the valid lifetime.
void SetValidLifetime(uint32_t validLifetime)
Set the valid lifetime.
Ipv6Address m_iaAddress
the IPv6 address offered to the client.
void SetIaAddress(Ipv6Address iaAddress)
Set the IA Address.
uint32_t m_preferredLifetime
The preferred lifetime of the address, in seconds.
uint32_t GetPreferredLifetime() const
Get the preferred lifetime.
uint32_t m_validLifetime
The valid lifetime of the address, in seconds.
Implements the IANA and IATA options.
uint32_t GetT2() const
Get the time interval in seconds after which the client contacts any available server to extend the a...
std::vector< IaAddressOption > m_iaAddressOption
The list of IA Address options associated with the IANA.
void SetT1(uint32_t t1)
Set the time interval in seconds after which the client contacts the server which provided the addres...
uint32_t GetT1() const
Get the time interval in seconds after which the client contacts the server which provided the addres...
uint32_t m_t1
The time interval in seconds after which the client contacts the server which provided the address to...
IaOptions()
Default constructor.
uint32_t m_t2
The time interval in seconds after which the client contacts any available server to extend the addre...
uint32_t m_iaid
The unique identifier for the given IA_NA or IA_TA.
void SetT2(uint32_t t2)
Set the time interval in seconds after which the client contacts any available server to extend the a...
uint32_t GetIaid() const
Get the unique identifier for the given IANA or IATA.
void SetIaid(uint32_t iaid)
Set the unique identifier for the given IANA or IATA.
StatusCodeOption m_statusCodeOption
(optional) The status code of any operation involving the IANA.
Implements the client and server identifier options.
IdentifierOption()
Default constructor.
void SetDuid(Duid duid)
Set the DUID.
Duid GetDuid() const
Get the DUID object.
Duid m_duid
Unique identifier of the node.
Implements the Preference and Elapsed Time options.
T m_optionValue
Indicates the elapsed time or preference value.
void SetOptionValue(T optionValue)
Set the option value.
IntegerOptions()
Constructor.
T GetOptionValue() const
Get the option value.
Describes an IPv6 address.
Implements the functionality of DHCPv6 options.
StatusCodeValues
Enum to identify the status code of the operation.
uint16_t m_optionLength
Option length.
void SetOptionCode(OptionType code)
Set the option code.
OptionType m_optionCode
Option code.
uint16_t GetOptionLength() const
Get the option length.
OptionType GetOptionCode() const
Get the option code.
OptionType
Enum to identify the option type.
Options()
Default constructor.
void SetOptionLength(uint16_t length)
Set the option length.
Implements the Option Request option.
std::vector< OptionType > GetRequestedOptions() const
Get the option values.
void AddRequestedOption(OptionType requestedOption)
Set the option values.
RequestOptions()
Constructor.
std::vector< OptionType > m_requestedOptions
List of requested options.
Implements the Server Unicast option.
Ipv6Address m_serverAddress
The 128-bit server address to which the client should send unicast messages.
void SetServerAddress(Ipv6Address serverAddress)
Set the server address.
Ipv6Address GetServerAddress()
Get the server address.
Implements the Status Code option.
StatusCodeOption()
Default constructor.
std::string m_statusMessage
The status message of the operation.
void SetStatusCode(StatusCodeValues statusCode)
Set the status code of the operation.
StatusCodeValues GetStatusCode() const
Get the status code of the operation.
StatusCodeValues m_statusCode
The status code of an operation involving the IA_NA, IA_TA or IA address.
std::string GetStatusMessage() const
Get the status message of the operation.
void SetStatusMessage(std::string statusMessage)
Set the status message of the operation.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
IntegerOptions< uint8_t > PreferenceOption
Create the typedef PreferenceOption with T as uint8_t.
IntegerOptions< uint16_t > ElapsedTimeOption
Create the typedef ElapsedTimeOption with T as uint16_t.
Every class exported by the ns3 library is enclosed in the ns3 namespace.