A Discrete-Event Network Simulator
API
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ns3::DhcpClient Class Reference


More...

#include "dhcp-client.h"

+ Inheritance diagram for ns3::DhcpClient:

Public Member Functions

 DhcpClient ()
 
 DhcpClient (Ptr< NetDevice > netDevice)
 Constructor. More...
 
virtual ~DhcpClient ()
 
int64_t AssignStreams (int64_t stream)
 Assign a fixed random variable stream number to the random variables used by this model. More...
 
Ptr< NetDeviceGetDhcpClientNetDevice (void)
 Get the the NetDevice DHCP should work on. More...
 
Ipv4Address GetDhcpServer (void)
 Get the IPv4Address of current DHCP server. More...
 
void SetDhcpClientNetDevice (Ptr< NetDevice > netDevice)
 Set the NetDevice DHCP should work on. More...
 
- Public Member Functions inherited from ns3::Application
 Application ()
 
virtual ~Application ()
 
Ptr< NodeGetNode () const
 
void SetNode (Ptr< Node > node)
 
void SetStartTime (Time start)
 Specify application start time. More...
 
void SetStopTime (Time stop)
 Specify application stop time. More...
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose (void)
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator (void) const
 Get an iterator to the Objects aggregated to this one. More...
 
virtual TypeId GetInstanceTypeId (void) const
 Get the most derived TypeId for this Object. More...
 
template<typename T >
Ptr< T > GetObject (void) const
 Get a pointer to the requested aggregated Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
void Initialize (void)
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized (void) const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising erros. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

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

Protected Member Functions

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

Private Types

enum  States { WAIT_OFFER = 1, REFRESH_LEASE = 2, WAIT_ACK = 9 }
 client states More...
 

Private Member Functions

void AcceptAck (DhcpHeader header, Address from)
 Receives the DHCP ACK and configures IP address of the client. More...
 
void Boot (void)
 Sends DHCP DISCOVER and changes the client state to WAIT_OFFER. More...
 
void LinkStateHandler (void)
 Handles changes in LinkState. More...
 
void NetHandler (Ptr< Socket > socket)
 Handles incoming packets from the network. More...
 
void OfferHandler (DhcpHeader header)
 Stores DHCP offers in m_offerList. More...
 
void RemoveAndStart ()
 Remove the current DHCP information and restart the process. More...
 
void Request (void)
 Sends the DHCP REQUEST message and changes the client state to WAIT_ACK. More...
 
void Select (void)
 Selects an OFFER from m_offerList. More...
 
virtual void StartApplication (void)
 Application specific startup code. More...
 
virtual void StopApplication (void)
 Application specific shutdown code. More...
 

Private Attributes

Address m_chaddr
 chaddr of the interface (stored as an Address for convenience). More...
 
Time m_collect
 Time for which client should collect offers. More...
 
Ptr< NetDevicem_device
 NetDevice pointer. More...
 
EventId m_discoverEvent
 Message retransmission event. More...
 
TracedCallback< const Ipv4Address & > m_expiry
 Trace of lease expire. More...
 
Ipv4Address m_gateway
 Address of the gateway. More...
 
Time m_lease
 Store the lease time of address. More...
 
Ipv4Address m_myAddress
 Address assigned to the client. More...
 
Ipv4Mask m_myMask
 Mask of the address assigned. More...
 
TracedCallback< const Ipv4Address & > m_newLease
 Trace of new lease. More...
 
Time m_nextoffer
 Time to try the next offer (if request gets no reply) More...
 
EventId m_nextOfferEvent
 Message next offer event. More...
 
bool m_offered
 Specify if the client has got any offer. More...
 
Ipv4Address m_offeredAddress
 Address offered to the client. More...
 
std::list< DhcpHeaderm_offerList
 Stores all the offers given to the client. More...
 
Ptr< RandomVariableStreamm_ran
 Uniform random variable for transaction ID. More...
 
Time m_rebind
 Store the rebind time of address. More...
 
EventId m_rebindEvent
 Message rebind event. More...
 
EventId m_refreshEvent
 Message refresh event. More...
 
Ipv4Address m_remoteAddress
 Initially set to 255.255.255.255 to start DHCP. More...
 
Time m_renew
 Store the renew time of address. More...
 
EventId m_requestEvent
 Address refresh event. More...
 
Time m_rtrs
 Defining the time for retransmission. More...
 
Ipv4Address m_server
 Address of the DHCP server. More...
 
Ptr< Socketm_socket
 Socket for remote communication. More...
 
uint8_t m_state
 State of the DHCP client. More...
 
EventId m_timeout
 The timeout period. More...
 
uint32_t m_tran
 Stores the current transaction number to be used. More...
 

Static Private Attributes

static const int DHCP_PEER_PORT = 67
 DHCP server port. More...
 

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. More...
 
typedef void(* StateTransitionCallback) (const std::string &oldState, const std::string &newState)
 Common signature used by callbacks to application's state transition trace source. More...
 
- Protected Attributes inherited from ns3::Application
Ptr< Nodem_node
 The node that this application is installed on. More...
 
EventId m_startEvent
 The event that will fire at m_startTime to start the application. More...
 
Time m_startTime
 The simulation time that the application will start. More...
 
EventId m_stopEvent
 The event that will fire at m_stopTime to end the application. More...
 
Time m_stopTime
 The simulation time that the application will end. More...
 

Detailed Description


Implements the functionality of a DHCP client.

Config Paths

ns3::DhcpClient is accessible through the following paths with Config::Set and Config::Connect:

Attributes

Attributes defined in parent class ns3::Application

TraceSources

Size of this type is 464 bytes (on a 64-bit architecture).

Definition at line 48 of file dhcp-client.h.

Member Enumeration Documentation

◆ States

client states

Enumerator
WAIT_OFFER 

State of a client that waits for the offer.

REFRESH_LEASE 

State of a client that needs to refresh the lease.

WAIT_ACK 

State of a client that waits for acknowledgment.

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

Constructor & Destructor Documentation

◆ DhcpClient() [1/2]

ns3::DhcpClient::DhcpClient ( )

◆ ~DhcpClient()

ns3::DhcpClient::~DhcpClient ( )
virtual

Definition at line 116 of file dhcp-client.cc.

References NS_LOG_FUNCTION_NOARGS.

◆ DhcpClient() [2/2]

ns3::DhcpClient::DhcpClient ( Ptr< NetDevice netDevice)

Constructor.

Parameters
netDevicethe NetDevice DHCP should work on

Definition at line 102 of file dhcp-client.cc.

References ns3::Ipv4Address::GetAny(), m_device, m_discoverEvent, m_nextOfferEvent, m_rebindEvent, m_refreshEvent, m_requestEvent, m_server, m_socket, m_timeout, and NS_LOG_FUNCTION_NOARGS.

Member Function Documentation

◆ AcceptAck()

void ns3::DhcpClient::AcceptAck ( DhcpHeader  header,
Address  from 
)
private

◆ AssignStreams()

int64_t ns3::DhcpClient::AssignStreams ( int64_t  stream)

Assign a fixed random variable stream number to the random variables used by this model.

Return the number of streams (possibly zero) that have been assigned.

Parameters
streamFirst stream index to use
Returns
the number of stream indices assigned by this model

Definition at line 148 of file dhcp-client.cc.

References m_ran, NS_LOG_FUNCTION, and ns3::RandomVariableStream::SetStream().

◆ Boot()

void ns3::DhcpClient::Boot ( void  )
private

◆ DoDispose()

void ns3::DhcpClient::DoDispose ( void  )
protectedvirtual

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 138 of file dhcp-client.cc.

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

◆ GetDhcpClientNetDevice()

Ptr< NetDevice > ns3::DhcpClient::GetDhcpClientNetDevice ( void  )

Get the the NetDevice DHCP should work on.

Returns
the NetDevice DHCP should work on

Definition at line 121 of file dhcp-client.cc.

References m_device.

◆ GetDhcpServer()

Ipv4Address ns3::DhcpClient::GetDhcpServer ( void  )

Get the IPv4Address of current DHCP server.

Returns
Ipv4Address of current DHCP server

Definition at line 132 of file dhcp-client.cc.

References m_server.

◆ GetTypeId()

TypeId ns3::DhcpClient::GetTypeId ( void  )
static

◆ LinkStateHandler()

void ns3::DhcpClient::LinkStateHandler ( void  )
private

◆ NetHandler()

void ns3::DhcpClient::NetHandler ( Ptr< Socket socket)
private

◆ OfferHandler()

void ns3::DhcpClient::OfferHandler ( DhcpHeader  header)
private

Stores DHCP offers in m_offerList.

Parameters
headerDhcpHeader of the DHCP OFFER message

Definition at line 335 of file dhcp-client.cc.

References m_collect, m_discoverEvent, m_offered, m_offerList, NS_LOG_FUNCTION, ns3::Simulator::Remove(), ns3::Simulator::Schedule(), and Select().

Referenced by NetHandler().

◆ RemoveAndStart()

void ns3::DhcpClient::RemoveAndStart ( )
private

◆ Request()

void ns3::DhcpClient::Request ( void  )
private

◆ Select()

void ns3::DhcpClient::Select ( void  )
private

◆ SetDhcpClientNetDevice()

void ns3::DhcpClient::SetDhcpClientNetDevice ( Ptr< NetDevice netDevice)

Set the NetDevice DHCP should work on.

Parameters
netDevicethe NetDevice DHCP should work on

Definition at line 127 of file dhcp-client.cc.

References m_device.

◆ StartApplication()

void ns3::DhcpClient::StartApplication ( void  )
privatevirtual

◆ StopApplication()

void ns3::DhcpClient::StopApplication ( void  )
privatevirtual

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 206 of file dhcp-client.cc.

References ns3::Socket::Close(), ns3::Application::GetNode(), ns3::Object::GetObject(), m_device, m_discoverEvent, m_myAddress, m_nextOfferEvent, m_rebindEvent, m_refreshEvent, m_requestEvent, m_socket, m_timeout, ns3::MakeNullCallback(), NS_LOG_FUNCTION, ns3::Simulator::Remove(), and ns3::Socket::SetRecvCallback().

Member Data Documentation

◆ DHCP_PEER_PORT

const int ns3::DhcpClient::DHCP_PEER_PORT = 67
staticprivate

DHCP server port.

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

Referenced by AcceptAck(), Boot(), and Request().

◆ m_chaddr

Address ns3::DhcpClient::m_chaddr
private

chaddr of the interface (stored as an Address for convenience).

Definition at line 170 of file dhcp-client.h.

Referenced by Boot(), NetHandler(), Request(), and StartApplication().

◆ m_collect

Time ns3::DhcpClient::m_collect
private

Time for which client should collect offers.

Definition at line 186 of file dhcp-client.h.

Referenced by GetTypeId(), and OfferHandler().

◆ m_device

Ptr<NetDevice> ns3::DhcpClient::m_device
private

◆ m_discoverEvent

EventId ns3::DhcpClient::m_discoverEvent
private

Message retransmission event.

Definition at line 175 of file dhcp-client.h.

Referenced by Boot(), DhcpClient(), OfferHandler(), and StopApplication().

◆ m_expiry

TracedCallback<const Ipv4Address&> ns3::DhcpClient::m_expiry
private

Trace of lease expire.

Definition at line 191 of file dhcp-client.h.

Referenced by AcceptAck(), GetTypeId(), and RemoveAndStart().

◆ m_gateway

Ipv4Address ns3::DhcpClient::m_gateway
private

Address of the gateway.

Definition at line 173 of file dhcp-client.h.

Referenced by AcceptAck(), LinkStateHandler(), RemoveAndStart(), Select(), and StartApplication().

◆ m_lease

Time ns3::DhcpClient::m_lease
private

Store the lease time of address.

Definition at line 180 of file dhcp-client.h.

Referenced by AcceptAck(), and Select().

◆ m_myAddress

Ipv4Address ns3::DhcpClient::m_myAddress
private

Address assigned to the client.

Definition at line 169 of file dhcp-client.h.

Referenced by AcceptAck(), LinkStateHandler(), RemoveAndStart(), Request(), StartApplication(), and StopApplication().

◆ m_myMask

Ipv4Mask ns3::DhcpClient::m_myMask
private

Mask of the address assigned.

Definition at line 171 of file dhcp-client.h.

Referenced by AcceptAck(), and Select().

◆ m_newLease

TracedCallback<const Ipv4Address&> ns3::DhcpClient::m_newLease
private

Trace of new lease.

Definition at line 190 of file dhcp-client.h.

Referenced by AcceptAck(), and GetTypeId().

◆ m_nextoffer

Time ns3::DhcpClient::m_nextoffer
private

Time to try the next offer (if request gets no reply)

Definition at line 183 of file dhcp-client.h.

Referenced by GetTypeId(), and Request().

◆ m_nextOfferEvent

EventId ns3::DhcpClient::m_nextOfferEvent
private

Message next offer event.

Definition at line 178 of file dhcp-client.h.

Referenced by DhcpClient(), NetHandler(), RemoveAndStart(), Request(), and StopApplication().

◆ m_offered

bool ns3::DhcpClient::m_offered
private

Specify if the client has got any offer.

Definition at line 187 of file dhcp-client.h.

Referenced by Boot(), OfferHandler(), and Select().

◆ m_offeredAddress

Ipv4Address ns3::DhcpClient::m_offeredAddress
private

Address offered to the client.

Definition at line 168 of file dhcp-client.h.

Referenced by AcceptAck(), Request(), and Select().

◆ m_offerList

std::list<DhcpHeader> ns3::DhcpClient::m_offerList
private

Stores all the offers given to the client.

Definition at line 188 of file dhcp-client.h.

Referenced by AcceptAck(), OfferHandler(), and Select().

◆ m_ran

Ptr<RandomVariableStream> ns3::DhcpClient::m_ran
private

Uniform random variable for transaction ID.

Definition at line 184 of file dhcp-client.h.

Referenced by AssignStreams(), Boot(), GetTypeId(), and Request().

◆ m_rebind

Time ns3::DhcpClient::m_rebind
private

Store the rebind time of address.

Definition at line 182 of file dhcp-client.h.

Referenced by AcceptAck(), and Select().

◆ m_rebindEvent

EventId ns3::DhcpClient::m_rebindEvent
private

Message rebind event.

Definition at line 177 of file dhcp-client.h.

Referenced by AcceptAck(), DhcpClient(), LinkStateHandler(), RemoveAndStart(), and StopApplication().

◆ m_refreshEvent

EventId ns3::DhcpClient::m_refreshEvent
private

Message refresh event.

Definition at line 176 of file dhcp-client.h.

Referenced by AcceptAck(), DhcpClient(), LinkStateHandler(), RemoveAndStart(), and StopApplication().

◆ m_remoteAddress

Ipv4Address ns3::DhcpClient::m_remoteAddress
private

Initially set to 255.255.255.255 to start DHCP.

Definition at line 167 of file dhcp-client.h.

Referenced by AcceptAck(), Boot(), Request(), and StartApplication().

◆ m_renew

Time ns3::DhcpClient::m_renew
private

Store the renew time of address.

Definition at line 181 of file dhcp-client.h.

Referenced by AcceptAck(), and Select().

◆ m_requestEvent

EventId ns3::DhcpClient::m_requestEvent
private

Address refresh event.

Definition at line 174 of file dhcp-client.h.

Referenced by DhcpClient(), and StopApplication().

◆ m_rtrs

Time ns3::DhcpClient::m_rtrs
private

Defining the time for retransmission.

Definition at line 185 of file dhcp-client.h.

Referenced by Boot(), and GetTypeId().

◆ m_server

Ipv4Address ns3::DhcpClient::m_server
private

Address of the DHCP server.

Definition at line 172 of file dhcp-client.h.

Referenced by DhcpClient(), GetDhcpServer(), and Select().

◆ m_socket

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

Socket for remote communication.

Definition at line 166 of file dhcp-client.h.

Referenced by AcceptAck(), Boot(), DhcpClient(), LinkStateHandler(), NetHandler(), Request(), StartApplication(), and StopApplication().

◆ m_state

uint8_t ns3::DhcpClient::m_state
private

State of the DHCP client.

Definition at line 164 of file dhcp-client.h.

Referenced by AcceptAck(), Boot(), NetHandler(), and Request().

◆ m_timeout

EventId ns3::DhcpClient::m_timeout
private

The timeout period.

Definition at line 179 of file dhcp-client.h.

Referenced by AcceptAck(), DhcpClient(), LinkStateHandler(), RemoveAndStart(), and StopApplication().

◆ m_tran

uint32_t ns3::DhcpClient::m_tran
private

Stores the current transaction number to be used.

Definition at line 189 of file dhcp-client.h.

Referenced by Boot(), and Request().


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