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

Implements the functionality of a DHCP server. More...

#include "dhcp-server.h"

+ Inheritance diagram for ns3::DhcpServer:
+ Collaboration diagram for ns3::DhcpServer:

Public Member Functions

 DhcpServer ()
 
 ~DhcpServer () override
 
void AddStaticDhcpEntry (Address chaddr, Ipv4Address addr)
 Add a static entry to the pool.
 
- 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 override
 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 Types

typedef std::list< Ipv4AddressAvailableAddress
 Available address container - IP addr.
 
typedef std::list< AddressExpiredAddress
 Expired address container - chaddr.
 
typedef std::list< Address >::const_iterator ExpiredAddressCIter
 Expired address const iterator - chaddr.
 
typedef std::list< Address >::iterator ExpiredAddressIter
 Expired address iterator - chaddr.
 
typedef std::map< Address, std::pair< Ipv4Address, uint32_t > > LeasedAddress
 Leased address container - chaddr + IP addr / lease time.
 
typedef std::map< Address, std::pair< Ipv4Address, uint32_t > >::const_iterator LeasedAddressCIter
 Leased address const iterator - chaddr + IP addr / lease time.
 
typedef std::map< Address, std::pair< Ipv4Address, uint32_t > >::iterator LeasedAddressIter
 Leased address iterator - chaddr + IP addr / lease time.
 

Private Member Functions

void NetHandler (Ptr< Socket > socket)
 Handles incoming packets from the network.
 
void SendAck (Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
 Sends DHCP ACK (or NACK) after receiving Request.
 
void SendOffer (Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
 Sends DHCP offer after receiving DHCP Discover.
 
void StartApplication () override
 Application specific startup code.
 
void StopApplication () override
 Application specific shutdown code.
 
void TimerHandler ()
 Modifies the remaining lease time of addresses.
 

Private Attributes

AvailableAddress m_availableAddresses
 Available addresses to be used (IP addresses)
 
ExpiredAddress m_expiredAddresses
 Expired addresses to be reused (chaddr of the clients)
 
EventId m_expiredEvent
 The Event to trigger TimerHandler.
 
Ipv4Address m_gateway
 The gateway address.
 
Time m_lease
 The granted lease time for an address.
 
LeasedAddress m_leasedAddresses
 Leased address and their status (cache memory)
 
Ipv4Address m_maxAddress
 The last address in the address pool.
 
Ipv4Address m_minAddress
 The first address in the address pool.
 
Ipv4Address m_poolAddress
 The network address available to the server.
 
Ipv4Mask m_poolMask
 The network mask of the pool.
 
Time m_rebind
 The rebinding time for an address.
 
Time m_renew
 The renewal time for an address.
 
Ptr< Socketm_socket
 The socket bound to port 67.
 

Static Private Attributes

static const int PORT = 67
 Port number of DHCP server.
 

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 functionality of a DHCP server.

Definition at line 36 of file dhcp-server.h.

Member Typedef Documentation

◆ AvailableAddress

typedef std::list<Ipv4Address> ns3::DhcpServer::AvailableAddress
private

Available address container - IP addr.

Definition at line 114 of file dhcp-server.h.

◆ ExpiredAddress

typedef std::list<Address> ns3::DhcpServer::ExpiredAddress
private

Expired address container - chaddr.

Definition at line 107 of file dhcp-server.h.

◆ ExpiredAddressCIter

typedef std::list<Address>::const_iterator ns3::DhcpServer::ExpiredAddressCIter
private

Expired address const iterator - chaddr.

Definition at line 111 of file dhcp-server.h.

◆ ExpiredAddressIter

typedef std::list<Address>::iterator ns3::DhcpServer::ExpiredAddressIter
private

Expired address iterator - chaddr.

Definition at line 109 of file dhcp-server.h.

◆ LeasedAddress

typedef std::map<Address, std::pair<Ipv4Address, uint32_t> > ns3::DhcpServer::LeasedAddress
private

Leased address container - chaddr + IP addr / lease time.

Definition at line 100 of file dhcp-server.h.

◆ LeasedAddressCIter

typedef std::map<Address,std::pair<Ipv4Address,uint32_t>>::const_iterator ns3::DhcpServer::LeasedAddressCIter
private

Leased address const iterator - chaddr + IP addr / lease time.

Definition at line 104 of file dhcp-server.h.

◆ LeasedAddressIter

typedef std::map<Address,std::pair<Ipv4Address,uint32_t>>::iterator ns3::DhcpServer::LeasedAddressIter
private

Leased address iterator - chaddr + IP addr / lease time.

Definition at line 102 of file dhcp-server.h.

Constructor & Destructor Documentation

◆ DhcpServer()

ns3::DhcpServer::DhcpServer ( )

Definition at line 84 of file dhcp-server.cc.

References NS_LOG_FUNCTION.

◆ ~DhcpServer()

ns3::DhcpServer::~DhcpServer ( )
override

Definition at line 89 of file dhcp-server.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ AddStaticDhcpEntry()

void ns3::DhcpServer::AddStaticDhcpEntry ( Address chaddr,
Ipv4Address addr )

Add a static entry to the pool.

Parameters
chaddrThe client chaddr.
addrThe address to handle to the client.

Definition at line 397 of file dhcp-server.cc.

References ns3::Address::CopyFrom(), ns3::Address::CopyTo(), ns3::Ipv4Address::Get(), m_availableAddresses, m_leasedAddresses, m_maxAddress, m_minAddress, ns3::Address::MAX_SIZE, NS_ASSERT_MSG, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DoDispose()

void ns3::DhcpServer::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 95 of file dhcp-server.cc.

References ns3::Application::DoDispose(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetTypeId()

TypeId ns3::DhcpServer::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 35 of file dhcp-server.cc.

References m_gateway, m_lease, m_maxAddress, m_minAddress, m_poolAddress, m_poolMask, m_rebind, m_renew, ns3::MakeIpv4AddressAccessor(), ns3::MakeIpv4AddressChecker(), ns3::MakeIpv4MaskAccessor(), ns3::MakeIpv4MaskChecker(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().

Referenced by ns3::DhcpHelper::DhcpHelper().

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

◆ NetHandler()

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

Handles incoming packets from the network.

Parameters
socketSocket bound to port 67 of the DHCP server

Definition at line 204 of file dhcp-server.cc.

References ns3::InetSocketAddress::ConvertFrom(), ns3::DhcpHeader::DHCPDISCOVER, ns3::DhcpHeader::DHCPREQ, ns3::Ipv4Address::Get(), ns3::Node::GetDevice(), ns3::Application::GetNode(), ns3::Ipv4PacketInfoTag::GetRecvIf(), ns3::DhcpHeader::GetReq(), ns3::DhcpHeader::GetType(), m_maxAddress, m_minAddress, m_socket, NS_ABORT_MSG, NS_LOG_FUNCTION, ns3::Socket::RecvFrom(), SendAck(), and SendOffer().

Referenced by StartApplication().

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

◆ SendAck()

void ns3::DhcpServer::SendAck ( Ptr< NetDevice > iDev,
DhcpHeader header,
InetSocketAddress from )
private

Sends DHCP ACK (or NACK) after receiving Request.

Parameters
iDevincoming NetDevice
headerDHCP header of the received message
fromAddress of the DHCP client

Definition at line 333 of file dhcp-server.cc.

References ns3::Create(), ns3::DhcpHeader::DHCPACK, ns3::DhcpHeader::DHCPNACK, ns3::DhcpHeader::GetChaddr(), ns3::InetSocketAddress::GetIpv4(), ns3::InetSocketAddress::GetPort(), ns3::DhcpHeader::GetReq(), ns3::Time::GetSeconds(), ns3::DhcpHeader::GetTran(), m_lease, m_leasedAddresses, m_socket, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::DhcpHeader::ResetOpt(), ns3::Socket::SendTo(), ns3::DhcpHeader::SetChaddr(), ns3::DhcpHeader::SetTime(), ns3::DhcpHeader::SetTran(), ns3::DhcpHeader::SetType(), and ns3::DhcpHeader::SetYiaddr().

Referenced by NetHandler().

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

◆ SendOffer()

void ns3::DhcpServer::SendOffer ( Ptr< NetDevice > iDev,
DhcpHeader header,
InetSocketAddress from )
private

Sends DHCP offer after receiving DHCP Discover.

Parameters
iDevincoming NetDevice
headerDHCP header of the received message
fromAddress of the DHCP client

Definition at line 239 of file dhcp-server.cc.

References ns3::Create(), ns3::DhcpHeader::DHCPOFFER, ns3::Ipv4Mask::Get(), ns3::DhcpHeader::GetChaddr(), ns3::InetSocketAddress::GetIpv4(), ns3::Application::GetNode(), ns3::Object::GetObject(), ns3::InetSocketAddress::GetPort(), ns3::Time::GetSeconds(), ns3::DhcpHeader::GetTran(), ns3::Ipv4InterfaceAddress::GLOBAL, m_availableAddresses, m_expiredAddresses, m_gateway, m_lease, m_leasedAddresses, m_poolMask, m_rebind, m_renew, m_socket, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC, ns3::DhcpHeader::ResetOpt(), ns3::Socket::SendTo(), ns3::DhcpHeader::SetChaddr(), ns3::DhcpHeader::SetDhcps(), ns3::DhcpHeader::SetLease(), ns3::DhcpHeader::SetMask(), ns3::DhcpHeader::SetRebind(), ns3::DhcpHeader::SetRenew(), ns3::DhcpHeader::SetRouter(), ns3::DhcpHeader::SetTime(), ns3::DhcpHeader::SetTran(), ns3::DhcpHeader::SetType(), and ns3::DhcpHeader::SetYiaddr().

Referenced by NetHandler().

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

◆ StartApplication()

void ns3::DhcpServer::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 102 of file dhcp-server.cc.

References ns3::Socket::Bind(), ns3::Socket::BindToNetDevice(), ns3::Socket::CreateSocket(), ns3::Ipv4Address::Get(), ns3::Ipv4Address::GetAny(), ns3::Application::GetNode(), ns3::Object::GetObject(), ns3::TypeId::LookupByName(), m_availableAddresses, m_expiredEvent, m_leasedAddresses, m_maxAddress, m_minAddress, m_poolAddress, m_poolMask, m_socket, ns3::MakeCallback(), NetHandler(), NS_ABORT_MSG, NS_ASSERT_MSG, NS_LOG_FUNCTION, NS_LOG_LOGIC, PORT, ns3::Simulator::Schedule(), ns3::Seconds(), ns3::Socket::SetAllowBroadcast(), ns3::Socket::SetRecvCallback(), ns3::Socket::SetRecvPktInfo(), and TimerHandler().

+ Here is the call graph for this function:

◆ StopApplication()

void ns3::DhcpServer::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 165 of file dhcp-server.cc.

References ns3::EventId::Cancel(), m_expiredEvent, m_leasedAddresses, m_socket, ns3::MakeNullCallback(), NS_LOG_FUNCTION, and ns3::Socket::SetRecvCallback().

+ Here is the call graph for this function:

◆ TimerHandler()

void ns3::DhcpServer::TimerHandler ( )
private

Modifies the remaining lease time of addresses.

Definition at line 179 of file dhcp-server.cc.

References m_expiredAddresses, m_expiredEvent, m_leasedAddresses, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Simulator::Schedule(), ns3::Seconds(), and TimerHandler().

Referenced by StartApplication(), and TimerHandler().

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

Member Data Documentation

◆ m_availableAddresses

AvailableAddress ns3::DhcpServer::m_availableAddresses
private

Available addresses to be used (IP addresses)

Definition at line 118 of file dhcp-server.h.

Referenced by AddStaticDhcpEntry(), SendOffer(), and StartApplication().

◆ m_expiredAddresses

ExpiredAddress ns3::DhcpServer::m_expiredAddresses
private

Expired addresses to be reused (chaddr of the clients)

Definition at line 117 of file dhcp-server.h.

Referenced by SendOffer(), and TimerHandler().

◆ m_expiredEvent

EventId ns3::DhcpServer::m_expiredEvent
private

The Event to trigger TimerHandler.

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

Referenced by StartApplication(), StopApplication(), and TimerHandler().

◆ m_gateway

Ipv4Address ns3::DhcpServer::m_gateway
private

The gateway address.

Definition at line 97 of file dhcp-server.h.

Referenced by GetTypeId(), and SendOffer().

◆ m_lease

Time ns3::DhcpServer::m_lease
private

The granted lease time for an address.

Definition at line 119 of file dhcp-server.h.

Referenced by GetTypeId(), SendAck(), and SendOffer().

◆ m_leasedAddresses

LeasedAddress ns3::DhcpServer::m_leasedAddresses
private

Leased address and their status (cache memory)

Definition at line 116 of file dhcp-server.h.

Referenced by AddStaticDhcpEntry(), SendAck(), SendOffer(), StartApplication(), StopApplication(), and TimerHandler().

◆ m_maxAddress

Ipv4Address ns3::DhcpServer::m_maxAddress
private

The last address in the address pool.

Definition at line 95 of file dhcp-server.h.

Referenced by AddStaticDhcpEntry(), GetTypeId(), NetHandler(), and StartApplication().

◆ m_minAddress

Ipv4Address ns3::DhcpServer::m_minAddress
private

The first address in the address pool.

Definition at line 94 of file dhcp-server.h.

Referenced by AddStaticDhcpEntry(), GetTypeId(), NetHandler(), and StartApplication().

◆ m_poolAddress

Ipv4Address ns3::DhcpServer::m_poolAddress
private

The network address available to the server.

Definition at line 93 of file dhcp-server.h.

Referenced by GetTypeId(), and StartApplication().

◆ m_poolMask

Ipv4Mask ns3::DhcpServer::m_poolMask
private

The network mask of the pool.

Definition at line 96 of file dhcp-server.h.

Referenced by GetTypeId(), SendOffer(), and StartApplication().

◆ m_rebind

Time ns3::DhcpServer::m_rebind
private

The rebinding time for an address.

Definition at line 121 of file dhcp-server.h.

Referenced by GetTypeId(), and SendOffer().

◆ m_renew

Time ns3::DhcpServer::m_renew
private

The renewal time for an address.

Definition at line 120 of file dhcp-server.h.

Referenced by GetTypeId(), and SendOffer().

◆ m_socket

Ptr<Socket> ns3::DhcpServer::m_socket
private

The socket bound to port 67.

Definition at line 92 of file dhcp-server.h.

Referenced by NetHandler(), SendAck(), SendOffer(), StartApplication(), and StopApplication().

◆ PORT

const int ns3::DhcpServer::PORT = 67
staticprivate

Port number of DHCP server.

Definition at line 63 of file dhcp-server.h.

Referenced by StartApplication().


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