A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dhcp6-duid.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_DUID_H
11#define DHCP6_DUID_H
12
13#include "ns3/buffer.h"
14#include "ns3/node.h"
15#include "ns3/nstime.h"
16
17namespace ns3
18{
19
20/**
21 * @ingroup dhcp6
22 *
23 * @class Duid
24 * @brief Implements the unique identifier for DHCPv6.
25 */
26class Duid
27{
28 public:
29 /**
30 * @brief Default constructor.
31 */
32 Duid();
33
34 /// DUID type.
35 enum class Type
36 {
37 LLT = 1, // Link-layer address plus time
38 EN, // Vendor-assigned unique ID based on Enterprise Number
39 LL, // Link-layer address
40 UUID, // Universally Unique Identifier (UUID) [RFC6355]
41 };
42
43 /**
44 * @ingroup dhcp6
45 *
46 * @class DuidHash
47 * @brief Class providing a hash for DUIDs
48 */
50 {
51 public:
52 /**
53 * @brief Returns the hash of a DUID.
54 * @param x the DUID
55 * @return the hash
56 *
57 * This method uses std::hash rather than class Hash
58 * as speed is more important than cryptographic robustness.
59 */
60 size_t operator()(const Duid& x) const noexcept;
61 };
62
63 /**
64 * @brief Initialize the DUID for a client or server.
65 * @param node The node for which the DUID is to be generated.
66 */
67 void Initialize(Ptr<Node> node);
68
69 /**
70 * @brief Check if the DUID is invalid.
71 * @return true if the DUID is invalid.
72 */
73 bool IsInvalid() const;
74
75 /**
76 * @brief Get the DUID type
77 * @return the DUID type.
78 */
79 Type GetDuidType() const;
80
81 /**
82 * @brief Set the DUID type
83 * @param duidType the DUID type.
84 */
85 void SetDuidType(Type duidType);
86
87 /**
88 * @brief Get the hardware type.
89 * @return the hardware type
90 */
91 uint16_t GetHardwareType() const;
92
93 /**
94 * @brief Set the hardware type.
95 * @param hardwareType the hardware type.
96 */
97 void SetHardwareType(uint16_t hardwareType);
98
99 /**
100 * @brief Set the identifier as the DUID.
101 * @param identifier the identifier of the node.
102 */
103 void SetDuid(std::vector<uint8_t> identifier);
104
105 /**
106 * @brief Get the time at which the DUID is generated.
107 * @return the timestamp.
108 */
109 Time GetTime() const;
110
111 /**
112 * @brief Get the length of the DUID.
113 * @return the DUID length.
114 */
115 uint8_t GetLength() const;
116
117 /**
118 * @brief Set the time at which DUID is generated.
119 * @param time the timestamp.
120 */
121 void SetTime(Time time);
122
123 /**
124 * @brief Get the DUID serialized size.
125 * @return The DUID serialized sized in bytes.
126 */
128
129 /**
130 * @brief Serialize the DUID.
131 * @param start The buffer iterator.
132 */
133 void Serialize(Buffer::Iterator start) const;
134
135 /**
136 * @brief Deserialize the DUID.
137 * @param start The buffer iterator.
138 * @param len The number of bytes to be read.
139 * @return The number of bytes read.
140 */
142
143 /**
144 * @brief Comparison operator
145 * @param duid header to compare
146 * @return true if the headers are equal
147 */
148 bool operator==(const Duid& duid) const;
149
150 /**
151 * @brief Less than operator.
152 *
153 * @param a the first operand
154 * @param b the first operand
155 * @returns true if the operand a is less than operand b
156 */
157 friend bool operator<(const Duid& a, const Duid& b);
158
159 // TypeId GetInstanceTypeId() const override;
160 // void Print(std::ostream& os) const override;
161 // uint32_t GetSerializedSize() const override;
162 // void Serialize(Buffer::Iterator start) const override;
163 // uint32_t Deserialize(Buffer::Iterator start) override;
164
165 private:
166 /**
167 * @brief Return the identifier of the node.
168 * @return the identifier.
169 */
170 std::vector<uint8_t> GetIdentifier() const;
171
172 /**
173 * Type of the DUID.
174 * We currently use only DUID-LL, based on the link-layer address.
175 */
177
178 uint16_t m_hardwareType; //!< Valid hardware type assigned by IANA.
179 Time m_time; //!< Time at which the DUID is generated. Used in DUID-LLT.
180 std::vector<uint8_t> m_identifier; //!< Identifier of the node in bytes.
181};
182
183/**
184 * @brief Stream output operator
185 * @param os output stream
186 * @param duid The reference to the DUID object.
187 * @return updated stream
188 */
189std::ostream& operator<<(std::ostream& os, const Duid& duid);
190
191/**
192 * Stream extraction operator
193 * @param is input stream
194 * @param duid The reference to the DUID object.
195 * @return std::istream
196 */
197std::istream& operator>>(std::istream& is, Duid& duid);
198
199} // namespace ns3
200
201#endif
iterator in a Buffer instance
Definition buffer.h:89
Class providing a hash for DUIDs.
Definition dhcp6-duid.h:50
size_t operator()(const Duid &x) const noexcept
Returns the hash of a DUID.
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
uint32_t Deserialize(Buffer::Iterator start, uint32_t len)
Deserialize the DUID.
uint8_t GetLength() const
Get the length of the DUID.
Definition dhcp6-duid.cc:69
Type m_duidType
Type of the DUID.
Definition dhcp6-duid.h:176
Time m_time
Time at which the DUID is generated.
Definition dhcp6-duid.h:179
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 Serialize(Buffer::Iterator start) const
Serialize the DUID.
uint16_t m_hardwareType
Valid hardware type assigned by IANA.
Definition dhcp6-duid.h:178
bool IsInvalid() const
Check if the DUID is invalid.
Definition dhcp6-duid.cc:63
bool operator==(const Duid &duid) const
Comparison operator.
Definition dhcp6-duid.cc:33
void SetTime(Time time)
Set the time at which DUID is generated.
std::vector< uint8_t > GetIdentifier() const
Return the identifier of the node.
Definition dhcp6-duid.cc:75
uint32_t GetSerializedSize() const
Get the DUID serialized size.
Type GetDuidType() const
Get the DUID type.
Definition dhcp6-duid.cc:81
uint16_t GetHardwareType() const
Get the hardware type.
Definition dhcp6-duid.cc:93
void Initialize(Ptr< Node > node)
Initialize the DUID for a client or server.
Duid()
Default constructor.
Definition dhcp6-duid.cc:24
std::vector< uint8_t > m_identifier
Identifier of the node in bytes.
Definition dhcp6-duid.h:180
Time GetTime() const
Get the time at which the DUID is generated.
Type
DUID type.
Definition dhcp6-duid.h:36
friend bool operator<(const Duid &a, const Duid &b)
Less than operator.
Definition dhcp6-duid.cc:40
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172