A Discrete-Event Network Simulator
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
23namespace 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 */
37class 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 */
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,
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 */
109
110 /**
111 * @brief Get the server identifier.
112 * @return the server identifier option.
113 */
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 */
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 */
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 */
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.
275
276 /// List of additional options requested.
278
279 /// The preference value for the server.
281
282 /// The amount of time since the client began the transaction.
284};
285} // namespace ns3
286
287#endif
iterator in a Buffer instance
Definition buffer.h:89
Implements the DHCPv6 header.
uint32_t GetSerializedSize() const override
IdentifierOption GetClientIdentifier()
Get the client identifier.
void AddElapsedTime(uint16_t timestamp)
Set the elapsed time option.
void AddServerIdentifier(Duid duid)
Add the server identifier option.
void ResetOptions()
Reset all options.
std::map< Options::OptionType, bool > GetOptionList()
Get list of all options set in the header.
uint32_t m_transactId
The transaction ID calculated by the client or the server.
std::vector< IaOptions > m_ianaList
Vector of IA_NA options.
void AddIdentifierOption(IdentifierOption &identifier, Options::OptionType optionType, Duid duid)
Add an identifier option to the header.
void Print(std::ostream &os) const override
void AddClientIdentifier(Duid duid)
Add the client identifier option.
IdentifierOption m_serverIdentifier
The server identifier option.
static TypeId GetTypeId()
Get the type ID.
uint32_t Deserialize(Buffer::Iterator start) override
ElapsedTimeOption m_elapsedTime
The amount of time since the client began the transaction.
uint32_t GetTransactId() const
Get the transaction ID.
static const uint16_t CLIENT_PORT
The port number of the DHCPv6 client.
RequestOptions m_optionRequest
List of additional options requested.
void AddAddress(uint32_t iaid, Ipv6Address address, uint32_t prefLifetime, uint32_t validLifetime)
Add IA address option to the IANA or IATA.
MessageType GetMessageType() const
Get the type of message.
static const uint16_t SERVER_PORT
The port number of the DHCPv6 server.
std::map< Options::OptionType, bool > m_options
Options present in the header, indexed by option code.
void AddSolMaxRt()
Add the SOL_MAX_RT option.
void AddIataOption(uint32_t iaid)
Add IATA option.
void AddOptionRequest(Options::OptionType optionType)
Request additional options.
std::vector< IaOptions > m_iataList
Vector of IA_TA options.
uint32_t m_len
The length of the message.
MessageType
Enum to identify the message type.
void HandleOptionRequest(std::vector< Options::OptionType > requestedOptions)
Handle all options requested by client.
PreferenceOption m_preference
The preference value for the server.
void AddStatusCode(Options::StatusCodeValues statusCode, std::string statusMsg)
Add the status code option.
void AddIanaOption(uint32_t iaid, uint32_t t1, uint32_t t2)
Add IANA option.
MessageType m_msgType
The message type.
void SetMessageType(MessageType msgType)
Set the message type.
void AddMessageLength(uint32_t len)
Update the message length.
std::vector< IaOptions > GetIanaOptions()
Get the list of IA_NA options.
void AddIaOption(Options::OptionType optionType, uint32_t iaid, uint32_t t1=0, uint32_t t2=0)
Add IANA or IATA option to the header.
IdentifierOption m_clientIdentifier
The client identifier option.
uint32_t m_solMaxRt
Default value for SOL_MAX_RT option.
StatusCodeOption m_statusCode
(optional) The status code of the operation just performed.
RequestOptions GetOptionRequest()
Get the option request option.
Dhcp6Header()
Default constructor.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
IdentifierOption GetServerIdentifier()
Get the server identifier.
StatusCodeOption GetStatusCodeOption()
Get the status code of the operation.
void Serialize(Buffer::Iterator start) const override
void SetTransactId(uint32_t transactId)
Set the transaction ID.
Implements the unique identifier for DHCPv6.
Definition dhcp6-duid.h:27
Protocol header serialization and deserialization.
Definition header.h:33
Implements the client and server identifier options.
Describes an IPv6 address.
StatusCodeValues
Enum to identify the status code of the operation.
OptionType
Enum to identify the option type.
Implements the Option Request option.
Implements the Status Code option.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.