A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dhcp6-options.cc
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#include "dhcp6-options.h"
11
12#include "dhcp6-duid.h"
13
14#include "ns3/address-utils.h"
15#include "ns3/assert.h"
16#include "ns3/log.h"
17#include "ns3/loopback-net-device.h"
18#include "ns3/ptr.h"
19#include "ns3/simulator.h"
20
21namespace ns3
22{
23
24NS_LOG_COMPONENT_DEFINE("Dhcp6Options");
25
31
32Options::Options(OptionType code, uint16_t length)
33{
34 NS_LOG_FUNCTION(this << static_cast<uint16_t>(code) << length);
35 m_optionCode = code;
36 m_optionLength = length;
37}
38
41{
42 return m_optionCode;
43}
44
45void
47{
48 NS_LOG_FUNCTION(this << static_cast<uint16_t>(code));
49 m_optionCode = code;
50}
51
52uint16_t
54{
55 return m_optionLength;
56}
57
58void
60{
61 NS_LOG_FUNCTION(this << length);
62 m_optionLength = length;
63}
64
68
69IdentifierOption::IdentifierOption(uint16_t hardwareType, Address linkLayerAddress, Time time)
70{
71 NS_LOG_FUNCTION(this << hardwareType << linkLayerAddress);
72 if (time.IsZero())
73 {
75 }
76 else
77 {
79 }
80
81 m_duid.SetHardwareType(hardwareType);
82
83 uint8_t buffer[16];
84 linkLayerAddress.CopyTo(buffer);
85
86 std::vector<uint8_t> identifier;
87 std::copy(buffer, buffer + linkLayerAddress.GetLength(), identifier.begin());
88 m_duid.SetDuid(identifier);
89}
90
91void
93{
94 NS_LOG_FUNCTION(this);
95 m_duid = duid;
96}
97
98Duid
100{
101 return m_duid;
102}
103
109
112{
113 return m_statusCode;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << static_cast<uint16_t>(statusCode));
120 m_statusCode = statusCode;
121}
122
123std::string
128
129void
130StatusCodeOption::SetStatusMessage(std::string statusMessage)
131{
132 NS_LOG_FUNCTION(this);
133 m_statusMessage = statusMessage;
134}
135
142
144 uint32_t preferredLifetime,
145 uint32_t validLifetime)
146{
147 m_iaAddress = iaAddress;
148 m_preferredLifetime = preferredLifetime;
149 m_validLifetime = validLifetime;
150}
151
154{
155 return m_iaAddress;
156}
157
158void
160{
161 NS_LOG_FUNCTION(this << iaAddress);
162 m_iaAddress = iaAddress;
163}
164
170
171void
173{
174 NS_LOG_FUNCTION(this << preferredLifetime);
175 m_preferredLifetime = preferredLifetime;
176}
177
183
184void
186{
187 NS_LOG_FUNCTION(this << validLifetime);
188 m_validLifetime = validLifetime;
189}
190
192{
193 m_iaid = 0;
194 m_t1 = 0;
195 m_t2 = 0;
196}
197
200{
201 return m_iaid;
202}
203
204void
206{
207 NS_LOG_FUNCTION(this << iaid);
208 m_iaid = iaid;
209}
210
213{
214 return m_t1;
215}
216
217void
219{
220 NS_LOG_FUNCTION(this << t1);
221 m_t1 = t1;
222}
223
226{
227 return m_t2;
228}
229
230void
232{
233 NS_LOG_FUNCTION(this << t2);
234 m_t2 = t2;
235}
236
238{
239 m_requestedOptions = std::vector<OptionType>();
240}
241
242std::vector<Options::OptionType>
247
248void
250{
251 m_requestedOptions.push_back(requestedOption);
252}
253
254template <typename T>
256{
257 m_optionValue = 0;
258}
259
260template <typename T>
261T
263{
264 return m_optionValue;
265}
266
267template <typename T>
268void
270{
271 NS_LOG_FUNCTION(this << optionValue);
272 m_optionValue = optionValue;
273}
274
279
285
286void
288{
289 NS_LOG_FUNCTION(this << serverAddress);
290 m_serverAddress = serverAddress;
291}
292
293// Public template function declarations.
294
295template class IntegerOptions<uint16_t>;
296template class IntegerOptions<uint8_t>;
297
298} // namespace ns3
a polymophic address class
Definition address.h:90
uint8_t GetLength() const
Get the length of the underlying address.
Definition address.cc:67
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition address.cc:75
Implements the unique identifier for DHCPv6.
Definition dhcp6-duid.h:27
void SetHardwareType(uint16_t hardwareType)
Set the hardware type.
Definition dhcp6-duid.cc:99
void SetDuidType(Type duidType)
Set the DUID type.
Definition dhcp6-duid.cc:87
void SetDuid(std::vector< uint8_t > identifier)
Set the identifier as the DUID.
void SetPreferredLifetime(uint32_t preferredLifetime)
Set the preferred lifetime.
IaAddressOption()
Default constructor.
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.
uint32_t GetT2() const
Get the time interval in seconds after which the client contacts any available server to extend the a...
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.
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.
void SetOptionValue(T optionValue)
Set the option value.
IntegerOptions()
Constructor.
T GetOptionValue() const
Get the option value.
Describes an IPv6 address.
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.
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.
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.
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
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:304
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.