A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::Dhcp6Server Class Reference

Implements the DHCPv6 server. More...

#include "dhcp6-server.h"

+ Inheritance diagram for ns3::Dhcp6Server:
+ Collaboration diagram for ns3::Dhcp6Server:

Public Member Functions

 Dhcp6Server ()
 Default constructor.
 
void AddSubnet (Ipv6Address pool, Ipv6Prefix prefix, Ipv6Address minAddress, Ipv6Address maxAddress)
 Add a managed address pool.
 
void SetDhcp6ServerNetDevice (NetDeviceContainer netDevices)
 Set the list of net devices that the DHCPv6 server will use.
 
- Public Member Functions inherited from ns3::Application
 Application ()
 
 ~Application () override
 
virtual int64_t AssignStreams (int64_t stream)
 Assign a fixed random variable stream number to the random variables used by this Application object.
 
Ptr< NodeGetNode () const
 
void SetNode (Ptr< Node > node)
 
void SetStartTime (Time start)
 Specify application start time.
 
void SetStopTime (Time stop)
 Specify application stop time.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const final
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Application
static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Protected Member Functions

void DoDispose () override
 Destructor implementation.
 
- Protected Member Functions inherited from ns3::Application
void DoInitialize () override
 Initialize() implementation.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Private Member Functions

void CleanLeases ()
 Clean up stale lease info.
 
void NetHandler (Ptr< Socket > socket)
 Handles incoming packets from the network.
 
void ProcessSolicit (Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
 Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.
 
void ReceiveMflag (uint32_t recvInterface)
 Callback for when an M flag is received.
 
void RenewRebindLeases (Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
 Sends Reply after receiving Request.
 
void SendAdvertise (Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
 Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.
 
void SendReply (Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
 Sends Reply after receiving Request.
 
void StartApplication () override
 Application specific startup code.
 
void StopApplication () override
 Application specific shutdown code.
 
void TimerHandler ()
 Modifies the remaining lease time of addresses.
 
void UpdateBindings (Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
 Sends Reply after receiving Request.
 

Private Attributes

std::multimap< Duid, std::pair< Options::OptionType, uint32_t > > m_iaBindings
 Store IA bindings. Map of DUID + IA Type / IAID.
 
Time m_leaseCleanup = Seconds(10.0)
 Lease cleanup time.
 
EventId m_leaseCleanupEvent
 Event ID for lease cleanup.
 
Time m_prefLifetime
 Default preferred lifetime for an address.
 
Time m_rebind
 The default rebind timer.
 
Ptr< Socketm_recvSocket
 Socket bound to port 547.
 
Time m_renew
 The default renew timer.
 
std::unordered_map< uint32_t, Ptr< Socket > > m_sendSockets
 Map of NetDevice - Corresponding socket used to send packets.
 
Duid m_serverDuid
 Server DUID.
 
std::vector< LeaseInfom_subnets
 List of managed subnets.
 
Time m_validLifetime
 Default valid lifetime.
 

Additional Inherited Members

- Public Types inherited from ns3::Application
typedef void(* DelayAddressCallback) (const Time &delay, const Address &from)
 Common callback signature for packet delay and address.
 
typedef void(* StateTransitionCallback) (const std::string &oldState, const std::string &newState)
 Common signature used by callbacks to application's state transition trace source.
 
- Protected Attributes inherited from ns3::Application
Ptr< Nodem_node
 The node that this application is installed on.
 
EventId m_startEvent
 The event that will fire at m_startTime to start the application.
 
Time m_startTime
 The simulation time that the application will start.
 
EventId m_stopEvent
 The event that will fire at m_stopTime to end the application.
 
Time m_stopTime
 The simulation time that the application will end.
 

Detailed Description

Implements the DHCPv6 server.

Definition at line 122 of file dhcp6-server.h.

Constructor & Destructor Documentation

◆ Dhcp6Server()

ns3::Dhcp6Server::Dhcp6Server ( )

Default constructor.

Definition at line 69 of file dhcp6-server.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ AddSubnet()

void ns3::Dhcp6Server::AddSubnet ( Ipv6Address pool,
Ipv6Prefix prefix,
Ipv6Address minAddress,
Ipv6Address maxAddress )

Add a managed address pool.

Parameters
poolThe address pool to be managed by the server.
prefixThe prefix of the address pool.
minAddressThe minimum address in the pool.
maxAddressThe maximum address in the pool.

Definition at line 696 of file dhcp6-server.cc.

References m_subnets, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

◆ CleanLeases()

void ns3::Dhcp6Server::CleanLeases ( )
private

Clean up stale lease info.

Definition at line 791 of file dhcp6-server.cc.

References CleanLeases(), m_leaseCleanup, m_leaseCleanupEvent, m_subnets, ns3::Simulator::Now(), NS_LOG_DEBUG, and ns3::Simulator::Schedule().

Referenced by CleanLeases(), and StartApplication().

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

◆ DoDispose()

void ns3::Dhcp6Server::DoDispose ( )
overrideprotectedvirtual

Destructor implementation.

This method is called by Dispose() or by the Object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.

It is safe to call GetObject() from within this method.

Reimplemented from ns3::Application.

Definition at line 75 of file dhcp6-server.cc.

References ns3::EventId::Cancel(), ns3::Socket::Close(), ns3::Application::DoDispose(), m_iaBindings, m_leaseCleanupEvent, m_recvSocket, m_sendSockets, m_subnets, ns3::MakeNullCallback(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetTypeId()

TypeId ns3::Dhcp6Server::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 33 of file dhcp6-server.cc.

References m_prefLifetime, m_rebind, m_renew, m_validLifetime, ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().

Referenced by ns3::Dhcp6Helper::Dhcp6Helper().

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

◆ NetHandler()

void ns3::Dhcp6Server::NetHandler ( Ptr< Socket > socket)
private

Handles incoming packets from the network.

Parameters
socketSocket bound to port 547 of the DHCP server

Definition at line 648 of file dhcp6-server.cc.

References ns3::Inet6SocketAddress::ConvertFrom(), ns3::Dhcp6Header::DECLINE, ns3::Node::GetDevice(), ns3::Dhcp6Header::GetMessageType(), ns3::Application::GetNode(), ns3::Ipv6PacketInfoTag::GetRecvIf(), ns3::Duid::Initialize(), m_recvSocket, m_serverDuid, NS_ASSERT_MSG, NS_LOG_FUNCTION, ProcessSolicit(), ns3::Dhcp6Header::REBIND, ns3::Socket::RecvFrom(), ns3::Dhcp6Header::RELEASE, ns3::Dhcp6Header::RENEW, RenewRebindLeases(), ns3::Dhcp6Header::REQUEST, SendAdvertise(), SendReply(), ns3::Dhcp6Header::SOLICIT, and UpdateBindings().

Referenced by ReceiveMflag(), and StartApplication().

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

◆ ProcessSolicit()

void ns3::Dhcp6Server::ProcessSolicit ( Ptr< NetDevice > iDev,
Dhcp6Header header,
Inet6SocketAddress client )
private

Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.

Parameters
iDevincoming NetDevice
headerDHCPv6 header of the received message
clientAddress of the DHCPv6 client

Definition at line 112 of file dhcp6-server.cc.

References ns3::Dhcp6Header::GetClientIdentifier(), ns3::IdentifierOption::GetDuid(), ns3::Dhcp6Header::GetIanaOptions(), ns3::Dhcp6Header::GetOptionList(), m_iaBindings, NS_LOG_DEBUG, and ns3::Options::OPTION_IA_NA.

Referenced by NetHandler().

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

◆ ReceiveMflag()

void ns3::Dhcp6Server::ReceiveMflag ( uint32_t recvInterface)
private

Callback for when an M flag is received.

Parameters
recvInterfaceThe interface on which the M flag was received.

Definition at line 709 of file dhcp6-server.cc.

References ns3::Socket::CreateSocket(), ns3::Node::GetDevice(), ns3::Application::GetNode(), ns3::TypeId::LookupByName(), m_sendSockets, ns3::MakeCallback(), NetHandler(), and ns3::Dhcp6Header::SERVER_PORT.

Referenced by StartApplication().

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

◆ RenewRebindLeases()

void ns3::Dhcp6Server::RenewRebindLeases ( Ptr< NetDevice > iDev,
Dhcp6Header header,
Inet6SocketAddress client )
private

◆ SendAdvertise()

void ns3::Dhcp6Server::SendAdvertise ( Ptr< NetDevice > iDev,
Dhcp6Header header,
Inet6SocketAddress client )
private

◆ SendReply()

void ns3::Dhcp6Server::SendReply ( Ptr< NetDevice > iDev,
Dhcp6Header header,
Inet6SocketAddress client )
private

◆ SetDhcp6ServerNetDevice()

void ns3::Dhcp6Server::SetDhcp6ServerNetDevice ( NetDeviceContainer netDevices)

Set the list of net devices that the DHCPv6 server will use.

Parameters
netDevicesThe net devices that the server will listen on.

Definition at line 636 of file dhcp6-server.cc.

References ns3::NetDeviceContainer::Begin(), ns3::NetDeviceContainer::End(), ns3::Application::GetNode(), ns3::Object::GetObject(), and m_sendSockets.

+ Here is the call graph for this function:

◆ StartApplication()

void ns3::Dhcp6Server::StartApplication ( )
overrideprivatevirtual

Application specific startup code.

The StartApplication method is called at the start time specified by Start This method should be overridden by all or most application subclasses.

Reimplemented from ns3::Application.

Definition at line 740 of file dhcp6-server.cc.

References ns3::Socket::Bind(), CleanLeases(), ns3::Socket::CreateSocket(), ns3::DynamicCast(), ns3::Ipv6Address::GetAllNodesMulticast(), ns3::Node::GetDevice(), ns3::Application::GetNode(), ns3::Icmpv6L4Protocol::GetStaticProtocolNumber(), ns3::TypeId::LookupByName(), m_leaseCleanup, m_leaseCleanupEvent, m_recvSocket, m_sendSockets, ns3::MakeCallback(), NetHandler(), NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_INFO, ReceiveMflag(), ns3::Simulator::Schedule(), ns3::Dhcp6Header::SERVER_PORT, ns3::Socket::SetRecvCallback(), and ns3::Socket::SetRecvPktInfo().

+ Here is the call graph for this function:

◆ StopApplication()

void ns3::Dhcp6Server::StopApplication ( )
overrideprivatevirtual

Application specific shutdown code.

The StopApplication method is called at the stop time specified by Stop This method should be overridden by all or most application subclasses.

Reimplemented from ns3::Application.

Definition at line 785 of file dhcp6-server.cc.

References NS_LOG_FUNCTION.

◆ TimerHandler()

void ns3::Dhcp6Server::TimerHandler ( )
private

Modifies the remaining lease time of addresses.

◆ UpdateBindings()

void ns3::Dhcp6Server::UpdateBindings ( Ptr< NetDevice > iDev,
Dhcp6Header header,
Inet6SocketAddress client )
private

Sends Reply after receiving Request.

Parameters
iDevincoming NetDevice
headerDHCPv6 header of the received message
clientAddress of the DHCP client

Definition at line 537 of file dhcp6-server.cc.

References ns3::Dhcp6Header::AddClientIdentifier(), ns3::Dhcp6Header::AddServerIdentifier(), ns3::Dhcp6Header::AddStatusCode(), ns3::Create(), ns3::Dhcp6Header::DECLINE, ns3::Dhcp6Header::GetClientIdentifier(), ns3::IdentifierOption::GetDuid(), ns3::Dhcp6Header::GetIanaOptions(), ns3::Dhcp6Header::GetMessageType(), ns3::Application::GetNode(), ns3::Object::GetObject(), ns3::Dhcp6Header::GetTransactId(), m_sendSockets, m_serverDuid, m_subnets, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Dhcp6Header::RELEASE, ns3::Dhcp6Header::REPLY, ns3::Dhcp6Header::ResetOptions(), ns3::Dhcp6Header::SetMessageType(), ns3::Dhcp6Header::SetTransactId(), and ns3::Options::Success.

Referenced by NetHandler().

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

Member Data Documentation

◆ m_iaBindings

std::multimap<Duid, std::pair<Options::OptionType, uint32_t> > ns3::Dhcp6Server::m_iaBindings
private

Store IA bindings. Map of DUID + IA Type / IAID.

Definition at line 233 of file dhcp6-server.h.

Referenced by DoDispose(), and ProcessSolicit().

◆ m_leaseCleanup

Time ns3::Dhcp6Server::m_leaseCleanup = Seconds(10.0)
private

Lease cleanup time.

Definition at line 226 of file dhcp6-server.h.

Referenced by CleanLeases(), and StartApplication().

◆ m_leaseCleanupEvent

EventId ns3::Dhcp6Server::m_leaseCleanupEvent
private

Event ID for lease cleanup.

Definition at line 227 of file dhcp6-server.h.

Referenced by CleanLeases(), DoDispose(), and StartApplication().

◆ m_prefLifetime

Time ns3::Dhcp6Server::m_prefLifetime
private

Default preferred lifetime for an address.

According to ISC's Kea guide, the default preferred lifetime is 3000 seconds.

Definition at line 240 of file dhcp6-server.h.

Referenced by GetTypeId(), RenewRebindLeases(), SendAdvertise(), and SendReply().

◆ m_rebind

Time ns3::Dhcp6Server::m_rebind
private

The default rebind timer.

This defines the T2 timer. According to ISC's Kea guide, the default rebind timer is 2000 seconds. Maximum value is REB_MAX_RT (RFC 8415, Section 7.6).

Definition at line 262 of file dhcp6-server.h.

Referenced by GetTypeId(), and SendAdvertise().

◆ m_recvSocket

Ptr<Socket> ns3::Dhcp6Server::m_recvSocket
private

Socket bound to port 547.

Definition at line 223 of file dhcp6-server.h.

Referenced by DoDispose(), NetHandler(), and StartApplication().

◆ m_renew

Time ns3::Dhcp6Server::m_renew
private

The default renew timer.

This defines the T1 timer. According to ISC's Kea guide, the default renew timer is 1000 seconds. Maximum value is REN_MAX_RT (RFC 8415, Section 7.6).

Definition at line 254 of file dhcp6-server.h.

Referenced by GetTypeId(), and SendAdvertise().

◆ m_sendSockets

std::unordered_map<uint32_t, Ptr<Socket> > ns3::Dhcp6Server::m_sendSockets
private

Map of NetDevice - Corresponding socket used to send packets.

Definition at line 230 of file dhcp6-server.h.

Referenced by DoDispose(), ReceiveMflag(), RenewRebindLeases(), SendAdvertise(), SendReply(), SetDhcp6ServerNetDevice(), StartApplication(), and UpdateBindings().

◆ m_serverDuid

Duid ns3::Dhcp6Server::m_serverDuid
private

Server DUID.

Definition at line 224 of file dhcp6-server.h.

Referenced by NetHandler(), RenewRebindLeases(), SendAdvertise(), SendReply(), and UpdateBindings().

◆ m_subnets

std::vector<LeaseInfo> ns3::Dhcp6Server::m_subnets
private

List of managed subnets.

Definition at line 225 of file dhcp6-server.h.

Referenced by AddSubnet(), CleanLeases(), DoDispose(), RenewRebindLeases(), SendAdvertise(), SendReply(), and UpdateBindings().

◆ m_validLifetime

Time ns3::Dhcp6Server::m_validLifetime
private

Default valid lifetime.

According to ISC's Kea guide, the default valid lifetime is 4000 seconds.

Definition at line 246 of file dhcp6-server.h.

Referenced by GetTypeId(), RenewRebindLeases(), SendAdvertise(), and SendReply().


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