A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
dhcp6-header.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_HEADER_H
11
#define DHCP6_HEADER_H
12
13
#include "
dhcp6-duid.h
"
14
#include "
dhcp6-options.h
"
15
16
#include "ns3/address.h"
17
#include "ns3/buffer.h"
18
#include "ns3/header.h"
19
#include "ns3/ipv6-address.h"
20
#include "ns3/ptr.h"
21
#include "ns3/random-variable-stream.h"
22
23
namespace
ns3
24
{
25
26
/**
27
* @ingroup internet-apps
28
* @defgroup dhcp6 DHCPv6 Client and Server
29
*/
30
31
/**
32
* @ingroup dhcp6
33
*
34
* @class Dhcp6Header
35
* @brief Implements the DHCPv6 header.
36
*/
37
class
Dhcp6Header
:
public
Header
38
{
39
public
:
40
/**
41
* @brief Get the type ID.
42
* @return the object TypeId
43
*/
44
static
TypeId
GetTypeId
();
45
46
/**
47
* @brief Default constructor.
48
*/
49
Dhcp6Header
();
50
51
/**
52
* Enum to identify the message type.
53
* RELAY_FORW, RELAY_REPL message types are not currently implemented.
54
* These symbols and values are defined in [RFC 8415,
55
* section 7.3](https://datatracker.ietf.org/doc/html/rfc8415#section-7.3)
56
*/
57
enum class
MessageType
58
{
59
INIT
= 0,
// Added for initialization
60
SOLICIT
= 1,
61
ADVERTISE
= 2,
62
REQUEST
= 3,
63
CONFIRM
= 4,
64
RENEW
= 5,
65
REBIND
= 6,
66
REPLY
= 7,
67
RELEASE
= 8,
68
DECLINE
= 9,
69
RECONFIGURE
= 10,
70
INFORMATION_REQUEST
= 11,
71
RELAY_FORW
= 12,
72
RELAY_REPL
= 13
73
};
74
75
/**
76
* @brief Get the type of message.
77
* @return integer corresponding to the message type.
78
*/
79
MessageType
GetMessageType
()
const
;
80
81
/**
82
* @brief Set the message type.
83
* @param msgType integer corresponding to the message type.
84
*/
85
void
SetMessageType
(MessageType msgType);
86
87
/**
88
* @brief Get the transaction ID.
89
* @return the 32-bit transaction ID
90
*/
91
uint32_t
GetTransactId
()
const
;
92
93
/**
94
* @brief Set the transaction ID.
95
* @param transactId A 32-bit transaction ID.
96
*/
97
void
SetTransactId
(
uint32_t
transactId);
98
99
/**
100
* @brief Reset all options.
101
*/
102
void
ResetOptions
();
103
104
/**
105
* @brief Get the client identifier.
106
* @return the client identifier option.
107
*/
108
IdentifierOption
GetClientIdentifier
();
109
110
/**
111
* @brief Get the server identifier.
112
* @return the server identifier option.
113
*/
114
IdentifierOption
GetServerIdentifier
();
115
116
/**
117
* @brief Get the list of IA_NA options.
118
* @return the list of IA_NA options.
119
*/
120
std::vector<IaOptions>
GetIanaOptions
();
121
122
/**
123
* @brief Get the status code of the operation.
124
* @return the status code option.
125
*/
126
StatusCodeOption
GetStatusCodeOption
();
127
128
/**
129
* @brief Set the elapsed time option.
130
* @param timestamp the time at which the client began the exchange.
131
*/
132
void
AddElapsedTime
(uint16_t timestamp);
133
134
/**
135
* @brief Add the client identifier option.
136
* @param duid The DUID which identifies the client.
137
*/
138
void
AddClientIdentifier
(
Duid
duid);
139
140
/**
141
* @brief Add the server identifier option.
142
* @param duid The DUID which identifies the server.
143
*/
144
void
AddServerIdentifier
(
Duid
duid);
145
146
/**
147
* @brief Request additional options.
148
* @param optionType the option to be requested.
149
*/
150
void
AddOptionRequest
(
Options::OptionType
optionType);
151
152
/**
153
* @brief Add the status code option.
154
* @param statusCode the status code of the operation.
155
* @param statusMsg the status message.
156
*/
157
void
AddStatusCode
(
Options::StatusCodeValues
statusCode, std::string statusMsg);
158
159
/**
160
* @brief Add IANA option.
161
* @param iaid
162
* @param t1
163
* @param t2
164
*/
165
void
AddIanaOption
(
uint32_t
iaid,
uint32_t
t1,
uint32_t
t2);
166
167
/**
168
* @brief Add IATA option.
169
* @param iaid
170
*/
171
void
AddIataOption
(
uint32_t
iaid);
172
173
/**
174
* @brief Add IA address option to the IANA or IATA.
175
* @param iaid the unique identifier of the identity association.
176
* @param address The IPv6 address to be offered.
177
* @param prefLifetime the preferred lifetime in seconds.
178
* @param validLifetime the valid lifetime in seconds.
179
*/
180
void
AddAddress
(
uint32_t
iaid,
181
Ipv6Address
address,
182
uint32_t
prefLifetime,
183
uint32_t
validLifetime);
184
185
/**
186
* @brief Get the option request option.
187
* @return the option request option.
188
*/
189
RequestOptions
GetOptionRequest
();
190
191
/**
192
* @brief Handle all options requested by client.
193
* @param requestedOptions the options requested by the client.
194
*/
195
void
HandleOptionRequest
(std::vector<Options::OptionType> requestedOptions);
196
197
/**
198
* @brief Add the SOL_MAX_RT option.
199
*/
200
void
AddSolMaxRt
();
201
202
/**
203
* @brief Get list of all options set in the header.
204
* @return the list of options.
205
*/
206
std::map<Options::OptionType, bool>
GetOptionList
();
207
208
/**
209
* @brief The port number of the DHCPv6 client.
210
*/
211
static
const
uint16_t
CLIENT_PORT
= 546;
212
213
/**
214
* @brief The port number of the DHCPv6 server.
215
*/
216
static
const
uint16_t
SERVER_PORT
= 547;
217
218
private
:
219
TypeId
GetInstanceTypeId
()
const override
;
220
void
Print
(std::ostream& os)
const override
;
221
uint32_t
GetSerializedSize
()
const override
;
222
void
Serialize
(
Buffer::Iterator
start)
const override
;
223
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
;
224
225
/**
226
* @brief Update the message length.
227
* @param len The length to be added to the total.
228
*/
229
void
AddMessageLength
(
uint32_t
len);
230
231
/**
232
* @brief Add an identifier option to the header.
233
* @param identifier the client or server identifier option object.
234
* @param optionType identify whether to add a client or server identifier.
235
* @param duid The unique identifier for the client or server.
236
*/
237
void
AddIdentifierOption
(
IdentifierOption
& identifier,
238
Options::OptionType
optionType,
239
Duid
duid);
240
241
/**
242
* @brief Add IANA or IATA option to the header.
243
* @param optionType identify whether to add an IANA or IATA.
244
* @param iaid
245
* @param t1
246
* @param t2
247
*/
248
void
AddIaOption
(
Options::OptionType
optionType,
249
uint32_t
iaid,
250
uint32_t
t1 = 0,
251
uint32_t
t2 = 0);
252
253
uint32_t
m_len
;
//!< The length of the message.
254
MessageType
m_msgType
;
//!< The message type.
255
IdentifierOption
m_clientIdentifier
;
//!< The client identifier option.
256
IdentifierOption
m_serverIdentifier
;
//!< The server identifier option.
257
std::vector<IaOptions>
m_ianaList
;
//!< Vector of IA_NA options.
258
std::vector<IaOptions>
m_iataList
;
//!< Vector of IA_TA options.
259
uint32_t
m_solMaxRt
;
//!< Default value for SOL_MAX_RT option.
260
261
/**
262
* The transaction ID calculated by the client or the server.
263
* This is a 24-bit integer.
264
*/
265
uint32_t
m_transactId
: 24;
266
267
/**
268
* Options present in the header, indexed by option code.
269
* TODO: Use std::set instead.
270
*/
271
std::map<Options::OptionType, bool>
m_options
;
272
273
/// (optional) The status code of the operation just performed.
274
StatusCodeOption
m_statusCode
;
275
276
/// List of additional options requested.
277
RequestOptions
m_optionRequest
;
278
279
/// The preference value for the server.
280
PreferenceOption
m_preference
;
281
282
/// The amount of time since the client began the transaction.
283
ElapsedTimeOption
m_elapsedTime
;
284
};
285
}
// namespace ns3
286
287
#endif
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Dhcp6Header
Implements the DHCPv6 header.
Definition
dhcp6-header.h:38
ns3::Dhcp6Header::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
dhcp6-header.cc:374
ns3::Dhcp6Header::GetClientIdentifier
IdentifierOption GetClientIdentifier()
Get the client identifier.
Definition
dhcp6-header.cc:90
ns3::Dhcp6Header::AddElapsedTime
void AddElapsedTime(uint16_t timestamp)
Set the elapsed time option.
Definition
dhcp6-header.cc:114
ns3::Dhcp6Header::AddServerIdentifier
void AddServerIdentifier(Duid duid)
Add the server identifier option.
Definition
dhcp6-header.cc:135
ns3::Dhcp6Header::ResetOptions
void ResetOptions()
Reset all options.
Definition
dhcp6-header.cc:67
ns3::Dhcp6Header::GetOptionList
std::map< Options::OptionType, bool > GetOptionList()
Get list of all options set in the header.
Definition
dhcp6-header.cc:352
ns3::Dhcp6Header::m_transactId
uint32_t m_transactId
The transaction ID calculated by the client or the server.
Definition
dhcp6-header.h:265
ns3::Dhcp6Header::m_ianaList
std::vector< IaOptions > m_ianaList
Vector of IA_NA options.
Definition
dhcp6-header.h:257
ns3::Dhcp6Header::AddIdentifierOption
void AddIdentifierOption(IdentifierOption &identifier, Options::OptionType optionType, Duid duid)
Add an identifier option to the header.
Definition
dhcp6-header.cc:141
ns3::Dhcp6Header::Print
void Print(std::ostream &os) const override
Definition
dhcp6-header.cc:380
ns3::Dhcp6Header::AddClientIdentifier
void AddClientIdentifier(Duid duid)
Add the client identifier option.
Definition
dhcp6-header.cc:129
ns3::Dhcp6Header::m_serverIdentifier
IdentifierOption m_serverIdentifier
The server identifier option.
Definition
dhcp6-header.h:256
ns3::Dhcp6Header::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
dhcp6-header.cc:74
ns3::Dhcp6Header::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
dhcp6-header.cc:475
ns3::Dhcp6Header::m_elapsedTime
ElapsedTimeOption m_elapsedTime
The amount of time since the client began the transaction.
Definition
dhcp6-header.h:283
ns3::Dhcp6Header::GetTransactId
uint32_t GetTransactId() const
Get the transaction ID.
Definition
dhcp6-header.cc:48
ns3::Dhcp6Header::CLIENT_PORT
static const uint16_t CLIENT_PORT
The port number of the DHCPv6 client.
Definition
dhcp6-header.h:211
ns3::Dhcp6Header::m_optionRequest
RequestOptions m_optionRequest
List of additional options requested.
Definition
dhcp6-header.h:277
ns3::Dhcp6Header::AddAddress
void AddAddress(uint32_t iaid, Ipv6Address address, uint32_t prefLifetime, uint32_t validLifetime)
Add IA address option to the IANA or IATA.
Definition
dhcp6-header.cc:293
ns3::Dhcp6Header::GetMessageType
MessageType GetMessageType() const
Get the type of message.
Definition
dhcp6-header.cc:35
ns3::Dhcp6Header::SERVER_PORT
static const uint16_t SERVER_PORT
The port number of the DHCPv6 server.
Definition
dhcp6-header.h:216
ns3::Dhcp6Header::m_options
std::map< Options::OptionType, bool > m_options
Options present in the header, indexed by option code.
Definition
dhcp6-header.h:271
ns3::Dhcp6Header::AddSolMaxRt
void AddSolMaxRt()
Add the SOL_MAX_RT option.
Definition
dhcp6-header.cc:205
ns3::Dhcp6Header::AddIataOption
void AddIataOption(uint32_t iaid)
Add IATA option.
Definition
dhcp6-header.cc:222
ns3::Dhcp6Header::AddOptionRequest
void AddOptionRequest(Options::OptionType optionType)
Request additional options.
Definition
dhcp6-header.cc:167
ns3::Dhcp6Header::m_iataList
std::vector< IaOptions > m_iataList
Vector of IA_TA options.
Definition
dhcp6-header.h:258
ns3::Dhcp6Header::m_len
uint32_t m_len
The length of the message.
Definition
dhcp6-header.h:253
ns3::Dhcp6Header::MessageType
MessageType
Enum to identify the message type.
Definition
dhcp6-header.h:58
ns3::Dhcp6Header::MessageType::REPLY
@ REPLY
ns3::Dhcp6Header::MessageType::RELAY_REPL
@ RELAY_REPL
ns3::Dhcp6Header::MessageType::REBIND
@ REBIND
ns3::Dhcp6Header::MessageType::SOLICIT
@ SOLICIT
ns3::Dhcp6Header::MessageType::INFORMATION_REQUEST
@ INFORMATION_REQUEST
ns3::Dhcp6Header::MessageType::RELEASE
@ RELEASE
ns3::Dhcp6Header::MessageType::DECLINE
@ DECLINE
ns3::Dhcp6Header::MessageType::CONFIRM
@ CONFIRM
ns3::Dhcp6Header::MessageType::ADVERTISE
@ ADVERTISE
ns3::Dhcp6Header::MessageType::REQUEST
@ REQUEST
ns3::Dhcp6Header::MessageType::RELAY_FORW
@ RELAY_FORW
ns3::Dhcp6Header::MessageType::RECONFIGURE
@ RECONFIGURE
ns3::Dhcp6Header::MessageType::RENEW
@ RENEW
ns3::Dhcp6Header::MessageType::INIT
@ INIT
ns3::Dhcp6Header::HandleOptionRequest
void HandleOptionRequest(std::vector< Options::OptionType > requestedOptions)
Handle all options requested by client.
Definition
dhcp6-header.cc:188
ns3::Dhcp6Header::m_preference
PreferenceOption m_preference
The preference value for the server.
Definition
dhcp6-header.h:280
ns3::Dhcp6Header::AddStatusCode
void AddStatusCode(Options::StatusCodeValues statusCode, std::string statusMsg)
Add the status code option.
Definition
dhcp6-header.cc:358
ns3::Dhcp6Header::AddIanaOption
void AddIanaOption(uint32_t iaid, uint32_t t1, uint32_t t2)
Add IANA option.
Definition
dhcp6-header.cc:216
ns3::Dhcp6Header::m_msgType
MessageType m_msgType
The message type.
Definition
dhcp6-header.h:254
ns3::Dhcp6Header::SetMessageType
void SetMessageType(MessageType msgType)
Set the message type.
Definition
dhcp6-header.cc:41
ns3::Dhcp6Header::AddMessageLength
void AddMessageLength(uint32_t len)
Update the message length.
Definition
dhcp6-header.cc:61
ns3::Dhcp6Header::GetIanaOptions
std::vector< IaOptions > GetIanaOptions()
Get the list of IA_NA options.
Definition
dhcp6-header.cc:108
ns3::Dhcp6Header::AddIaOption
void AddIaOption(Options::OptionType optionType, uint32_t iaid, uint32_t t1=0, uint32_t t2=0)
Add IANA or IATA option to the header.
Definition
dhcp6-header.cc:228
ns3::Dhcp6Header::m_clientIdentifier
IdentifierOption m_clientIdentifier
The client identifier option.
Definition
dhcp6-header.h:255
ns3::Dhcp6Header::m_solMaxRt
uint32_t m_solMaxRt
Default value for SOL_MAX_RT option.
Definition
dhcp6-header.h:259
ns3::Dhcp6Header::m_statusCode
StatusCodeOption m_statusCode
(optional) The status code of the operation just performed.
Definition
dhcp6-header.h:274
ns3::Dhcp6Header::GetOptionRequest
RequestOptions GetOptionRequest()
Get the option request option.
Definition
dhcp6-header.cc:161
ns3::Dhcp6Header::Dhcp6Header
Dhcp6Header()
Default constructor.
Definition
dhcp6-header.cc:26
ns3::Dhcp6Header::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
dhcp6-header.cc:84
ns3::Dhcp6Header::GetServerIdentifier
IdentifierOption GetServerIdentifier()
Get the server identifier.
Definition
dhcp6-header.cc:96
ns3::Dhcp6Header::GetStatusCodeOption
StatusCodeOption GetStatusCodeOption()
Get the status code of the operation.
Definition
dhcp6-header.cc:102
ns3::Dhcp6Header::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
dhcp6-header.cc:386
ns3::Dhcp6Header::SetTransactId
void SetTransactId(uint32_t transactId)
Set the transaction ID.
Definition
dhcp6-header.cc:54
ns3::Duid
Implements the unique identifier for DHCPv6.
Definition
dhcp6-duid.h:27
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::IdentifierOption
Implements the client and server identifier options.
Definition
dhcp6-options.h:134
ns3::IntegerOptions< uint8_t >
ns3::Ipv6Address
Describes an IPv6 address.
Definition
ipv6-address.h:38
ns3::Options::StatusCodeValues
StatusCodeValues
Enum to identify the status code of the operation.
Definition
dhcp6-options.h:42
ns3::Options::OptionType
OptionType
Enum to identify the option type.
Definition
dhcp6-options.h:58
ns3::RequestOptions
Implements the Option Request option.
Definition
dhcp6-options.h:368
ns3::StatusCodeOption
Implements the Status Code option.
Definition
dhcp6-options.h:172
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
uint32_t
dhcp6-duid.h
dhcp6-options.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet-apps
model
dhcp6-header.h
Generated on Tue Apr 29 2025 11:06:54 for ns-3 by
1.11.0