A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches

Implements the unique identifier for DHCPv6. More...

#include "dhcp6-duid.h"

Collaboration diagram for ns3::Duid:

Classes

class  DuidHash
 Class providing a hash for DUIDs. More...

Public Types

enum class  Type { LLT = 1 , EN , LL , UUID }
 DUID type. More...

Public Member Functions

uint32_t Deserialize (Buffer::Iterator start, uint32_t len)
 Deserialize the DUID.
Type GetDuidType () const
 Get the DUID type.
std::vector< uint8_t > GetIdentifier () const
 Return the identifier of the node.
uint8_t GetLength () const
 Get the length of the DUID.
uint32_t GetSerializedSize () const
 Get the DUID serialized size.
void Initialize (Type duidType, Ptr< Node > node, uint32_t enIdentifierLength)
 Initialize a DUID.
void InitializeEN (uint32_t enNumber, const std::vector< uint8_t > &identifier)
 Initialize the DUID-EN for a client or server.
void InitializeLL (Ptr< Node > node)
 Initialize the DUID-LL for a client or server.
void InitializeLLT (Ptr< Node > node)
 Initialize the DUID-LLT for a client or server.
void InitializeUUID (const std::vector< uint8_t > &uuid)
 Initialize the DUID-EN for a client or server.
bool IsInvalid () const
 Check if the DUID is invalid.
bool operator== (const Duid &other) const
 Comparison operator.
void Serialize (Buffer::Iterator start) const
 Serialize the DUID.

Private Types

enum  Offset { LLT = 6 , EN = 4 , LL = 2 , UUID = 0 }
 DUID data offset. More...

Private Member Functions

Address FindSuitableNetDeviceAddress (Ptr< Node > node)
 Find a suitable NetDevice address to create a DUID-LL or DUID-LLT.
void HtoN (uint32_t source, std::vector< uint8_t >::iterator dest)
 Utility function to convert a 32-bit number to an array with its bytes in network order.

Private Attributes

std::vector< uint8_t > m_blob {}
 DUID data, content depending on the DUID type.
Type m_duidType {Duid::Type::LL}
 DUID type.

Friends

std::ostream & operator<< (std::ostream &os, const Duid &duid)
 Stream output operator.
std::strong_ordering operator<=> (const Duid &a, const Duid &b)
 Spaceship comparison operator.

Detailed Description

Implements the unique identifier for DHCPv6.

Definition at line 26 of file dhcp6-duid.h.

Member Enumeration Documentation

◆ Offset

enum ns3::Duid::Offset
private

DUID data offset.

Each DUID has some fixed-length fields (e.g., Hardware Type), and a variable length part. This is the offset to the variable length part.

Enumerator
LLT 
EN 
LL 
UUID 

Definition at line 191 of file dhcp6-duid.h.

◆ Type

enum class ns3::Duid::Type
strong

DUID type.

Enumerator
LLT 
EN 
LL 
UUID 

Definition at line 30 of file dhcp6-duid.h.

Member Function Documentation

◆ Deserialize()

uint32_t ns3::Duid::Deserialize ( Buffer::Iterator start,
uint32_t len )

Deserialize the DUID.

Parameters
startThe buffer iterator.
lenThe number of bytes to be read.
Returns
The number of bytes read.

Definition at line 229 of file dhcp6-duid.cc.

References GetSerializedSize(), m_blob, m_duidType, ns3::Buffer::Iterator::Read(), and ns3::Buffer::Iterator::ReadNtohU16().

Referenced by ns3::Dhcp6Header::Deserialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindSuitableNetDeviceAddress()

Address ns3::Duid::FindSuitableNetDeviceAddress ( Ptr< Node > node)
private

Find a suitable NetDevice address to create a DUID-LL or DUID-LLT.

We select the NetDevices with the longest MAC address length, and among them, the one with the smallest index.

Parameters
nodeThe node for which the DUID is to be generated.
Returns
the L2 address for the DUID Hardware Identifier.

Definition at line 169 of file dhcp6-duid.cc.

References ns3::DynamicCast(), ns3::Address::IsInvalid(), NS_ASSERT_MSG, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by InitializeLL(), and InitializeLLT().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDuidType()

Duid::Type ns3::Duid::GetDuidType ( ) const

Get the DUID type.

Returns
the DUID type.

Definition at line 47 of file dhcp6-duid.cc.

References m_duidType.

◆ GetIdentifier()

std::vector< uint8_t > ns3::Duid::GetIdentifier ( ) const

Return the identifier of the node.

Returns
the identifier.

Definition at line 41 of file dhcp6-duid.cc.

References m_blob.

◆ GetLength()

uint8_t ns3::Duid::GetLength ( ) const

Get the length of the DUID.

Returns
the DUID length.

Definition at line 35 of file dhcp6-duid.cc.

References m_blob.

◆ GetSerializedSize()

uint32_t ns3::Duid::GetSerializedSize ( ) const

Get the DUID serialized size.

Returns
The DUID serialized sized in bytes.

Definition at line 213 of file dhcp6-duid.cc.

References m_blob.

Referenced by ns3::Dhcp6Header::AddIdentifierOption(), Deserialize(), Dhcp6DuidTestCase::DoRun(), and ns3::Dhcp6Header::Serialize().

Here is the caller graph for this function:

◆ HtoN()

void ns3::Duid::HtoN ( uint32_t source,
std::vector< uint8_t >::iterator dest )
private

Utility function to convert a 32-bit number to an array with its bytes in network order.

Parameters
[in]sourcethe number to convert.
[out]destthe converted number.

Definition at line 243 of file dhcp6-duid.cc.

Referenced by Initialize(), InitializeEN(), and InitializeLLT().

Here is the caller graph for this function:

◆ Initialize()

void ns3::Duid::Initialize ( Type duidType,
Ptr< Node > node,
uint32_t enIdentifierLength )

Initialize a DUID.

The DUID initialization logic is the following:

  • DUID-LLT and DUID-LL: the identifier is created by selecting the NetDevices with the longest MAC address length, and among them, the one with the smallest index.
  • DUID-LLT: the creation time is taken from the simulation time.
  • DUID-EN: the Enterprise number is 0xf00dcafe (arbitrary number, currently unused), and the identifier is based on the Node ID.
  • DUID-UUID: the UUID is based on the Node ID.
Parameters
duidTypethe DUID type.
nodethe node this DUID refers to
enIdentifierLengththe DUID-EN identifier length (unused in other DUID types)

Definition at line 136 of file dhcp6-duid.cc.

References EN, HtoN(), InitializeEN(), InitializeLL(), InitializeLLT(), InitializeUUID(), LL, LLT, NS_LOG_FUNCTION, and UUID.

Here is the call graph for this function:

◆ InitializeEN()

void ns3::Duid::InitializeEN ( uint32_t enNumber,
const std::vector< uint8_t > & identifier )

Initialize the DUID-EN for a client or server.

Parameters
enNumberThe Enterprise Number.
identifierThe device Identifier.

Definition at line 102 of file dhcp6-duid.cc.

References EN, HtoN(), m_blob, m_duidType, NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by Dhcp6DuidTestCase::DoRun(), and Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeLL()

void ns3::Duid::InitializeLL ( Ptr< Node > node)

Initialize the DUID-LL for a client or server.

Parameters
nodeThe node for which the DUID is to be generated.

Definition at line 53 of file dhcp6-duid.cc.

References ns3::Address::CopyTo(), FindSuitableNetDeviceAddress(), ns3::Address::GetLength(), LL, m_blob, m_duidType, NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by Dhcp6DuidTestCase::DoRun(), and Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeLLT()

void ns3::Duid::InitializeLLT ( Ptr< Node > node)

Initialize the DUID-LLT for a client or server.

Parameters
nodeThe node for which the DUID is to be generated.

Definition at line 74 of file dhcp6-duid.cc.

References ns3::Address::CopyTo(), FindSuitableNetDeviceAddress(), ns3::Address::GetLength(), HtoN(), LL, LLT, m_blob, m_duidType, ns3::Simulator::Now(), NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by Dhcp6DuidTestCase::DoRun(), and Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeUUID()

void ns3::Duid::InitializeUUID ( const std::vector< uint8_t > & uuid)

Initialize the DUID-EN for a client or server.

Parameters
uuidThe UUID.

Definition at line 122 of file dhcp6-duid.cc.

References m_blob, m_duidType, NS_ASSERT_MSG, NS_LOG_FUNCTION, and UUID.

Referenced by Dhcp6DuidTestCase::DoRun(), and Initialize().

Here is the caller graph for this function:

◆ IsInvalid()

bool ns3::Duid::IsInvalid ( ) const

Check if the DUID is invalid.

Returns
true if the DUID is invalid.

Definition at line 29 of file dhcp6-duid.cc.

References m_blob.

◆ operator==()

bool ns3::Duid::operator== ( const Duid & other) const

Comparison operator.

Note
Defined because gcc-13.3 raises an error in optimized builds. Other than that, the comparison is semantically identical to the default one.
Parameters
otherDUID to compare to this one.
Returns
true if the duids are equal.

Definition at line 264 of file dhcp6-duid.cc.

◆ Serialize()

void ns3::Duid::Serialize ( Buffer::Iterator start) const

Serialize the DUID.

Parameters
startThe buffer iterator.

Definition at line 220 of file dhcp6-duid.cc.

References m_blob, m_duidType, ns3::Buffer::Iterator::Write(), and ns3::Buffer::Iterator::WriteHtonU16().

Referenced by ns3::Dhcp6Header::Serialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Duid & duid )
friend

Stream output operator.

The DUID is printed according to its type, e.g.:

  • DUID-LL HWtype: 1 Identifier: 0x000000000002
  • DUID-LLT HWtype: 1 Time: 0 Identifier: 0x000000000002
  • DUID-EN EnNumber: 0xf00dcafe Identifier: 0x000102030405060708090a
  • DUID-UUID UUID: 0x000102030405060708090a0b0c0d0e0f
Parameters
osoutput stream
duidThe reference to the DUID object.
Returns
updated stream

Definition at line 280 of file dhcp6-duid.cc.

References EN, LL, LLT, m_blob, m_duidType, and UUID.

◆ operator<=>

std::strong_ordering operator<=> ( const Duid & a,
const Duid & b )
friend

Spaceship comparison operator.

All the other comparison operators are automatically generated from this one.

Note
Defined because gcc-13.3 raises an error in optimized builds. Other than that, the comparison is semantically identical to the default one.
Parameters
aleft operand DUID to compare.
bright operand DUID to compare.
Returns
The result of the comparison.

Definition at line 269 of file dhcp6-duid.cc.

References m_blob, and m_duidType.

Member Data Documentation

◆ m_blob

std::vector<uint8_t> ns3::Duid::m_blob {}
private

DUID data, content depending on the DUID type.

Definition at line 221 of file dhcp6-duid.h.

Referenced by Deserialize(), GetIdentifier(), GetLength(), GetSerializedSize(), InitializeEN(), InitializeLL(), InitializeLLT(), InitializeUUID(), IsInvalid(), operator<<, operator<=>, and Serialize().

◆ m_duidType

Type ns3::Duid::m_duidType {Duid::Type::LL}
private

The documentation for this class was generated from the following files: