#include "dhcp-client.h"
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< NetDevice > | GetDhcpClientNetDevice (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< Node > | GetNode () 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... | |
SimpleRefCount & | operator= (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< NetDevice > | m_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< DhcpHeader > | m_offerList |
Stores all the offers given to the client. More... | |
Ptr< RandomVariableStream > | m_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< Socket > | m_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< Node > | m_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... | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid (void) |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
Implements the functionality of a DHCP client.
ns3::DhcpClient is accessible through the following paths with Config::Set and Config::Connect:
Size of this type is 464 bytes (on a 64-bit architecture).
Definition at line 48 of file dhcp-client.h.
|
private |
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.
ns3::DhcpClient::DhcpClient | ( | ) |
Definition at line 89 of file dhcp-client.cc.
References ns3::Ipv4Address::GetAny(), m_discoverEvent, m_nextOfferEvent, m_rebindEvent, m_refreshEvent, m_requestEvent, m_server, m_socket, m_timeout, and NS_LOG_FUNCTION_NOARGS.
|
virtual |
Definition at line 116 of file dhcp-client.cc.
References NS_LOG_FUNCTION_NOARGS.
Constructor.
netDevice | the 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.
|
private |
Receives the DHCP ACK and configures IP address of the client.
It also triggers the timeout, renew and rebind events.
header | DhcpHeader of the DHCP ACK message |
from | Address of DHCP server that sent the DHCP ACK |
Definition at line 417 of file dhcp-client.cc.
References ns3::Socket::Connect(), ns3::InetSocketAddress::ConvertFrom(), DHCP_PEER_PORT, ns3::InetSocketAddress::GetIpv4(), ns3::Application::GetNode(), ns3::Object::GetObject(), ns3::Ipv4StaticRoutingHelper::GetStaticRouting(), m_device, m_expiry, m_gateway, m_lease, m_myAddress, m_myMask, m_newLease, m_offeredAddress, m_offerList, m_rebind, m_rebindEvent, m_refreshEvent, m_remoteAddress, m_renew, m_socket, m_state, m_timeout, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC(), REFRESH_LEASE, ns3::Simulator::Remove(), RemoveAndStart(), Request(), and ns3::Simulator::Schedule().
Referenced by NetHandler().
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.
stream | First stream index to use |
Definition at line 148 of file dhcp-client.cc.
References m_ran, NS_LOG_FUNCTION, and ns3::RandomVariableStream::SetStream().
|
private |
Sends DHCP DISCOVER and changes the client state to WAIT_OFFER.
Definition at line 307 of file dhcp-client.cc.
References ns3::Packet::AddHeader(), DHCP_PEER_PORT, ns3::DhcpHeader::DHCPDISCOVER, ns3::RandomVariableStream::GetValue(), m_chaddr, m_discoverEvent, m_offered, m_ran, m_remoteAddress, m_rtrs, m_socket, m_state, m_tran, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::DhcpHeader::ResetOpt(), ns3::Simulator::Schedule(), ns3::Socket::SendTo(), ns3::DhcpHeader::SetChaddr(), ns3::DhcpHeader::SetTime(), ns3::DhcpHeader::SetTran(), ns3::DhcpHeader::SetType(), and WAIT_OFFER.
Referenced by NetHandler(), Select(), and StartApplication().
|
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.
Get the the NetDevice DHCP should work on.
Definition at line 121 of file dhcp-client.cc.
References m_device.
Ipv4Address ns3::DhcpClient::GetDhcpServer | ( | void | ) |
Get the IPv4Address of current DHCP server.
Definition at line 132 of file dhcp-client.cc.
References m_server.
|
static |
Get the type ID.
Definition at line 55 of file dhcp-client.cc.
References m_collect, m_expiry, m_newLease, m_nextoffer, m_ran, m_rtrs, ns3::MakePointerAccessor(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::MakeTraceSourceAccessor(), ns3::Seconds(), and ns3::TypeId::SetParent().
Referenced by ns3::DhcpHelper::DhcpHelper().
|
private |
Handles changes in LinkState.
Definition at line 232 of file dhcp-client.cc.
References ns3::Application::GetNode(), ns3::Object::GetObject(), ns3::Ipv4StaticRoutingHelper::GetStaticRouting(), m_device, m_gateway, m_myAddress, m_rebindEvent, m_refreshEvent, m_socket, m_timeout, ns3::MakeCallback(), ns3::MakeNullCallback(), NetHandler(), ns3::Simulator::Now(), NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Simulator::Remove(), ns3::Time::S, ns3::Socket::SetRecvCallback(), and StartApplication().
Referenced by StartApplication().
Handles incoming packets from the network.
socket | Socket bound to port 68 of the DHCP client |
Definition at line 276 of file dhcp-client.cc.
References AcceptAck(), Boot(), ns3::DhcpHeader::DHCPACK, ns3::DhcpHeader::DHCPNACK, ns3::DhcpHeader::DHCPOFFER, ns3::DhcpHeader::GetChaddr(), ns3::DhcpHeader::GetType(), m_chaddr, m_nextOfferEvent, m_socket, m_state, NS_LOG_FUNCTION, OfferHandler(), ns3::Socket::RecvFrom(), ns3::Simulator::Remove(), ns3::Packet::RemoveHeader(), WAIT_ACK, and WAIT_OFFER.
Referenced by LinkStateHandler(), and StartApplication().
|
private |
Stores DHCP offers in m_offerList.
header | DhcpHeader 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().
|
private |
Remove the current DHCP information and restart the process.
Definition at line 471 of file dhcp-client.cc.
References ns3::Application::GetNode(), ns3::Object::GetObject(), ns3::Ipv4StaticRoutingHelper::GetStaticRouting(), m_device, m_expiry, m_gateway, m_myAddress, m_nextOfferEvent, m_rebindEvent, m_refreshEvent, m_timeout, NS_LOG_FUNCTION, ns3::Simulator::Remove(), and StartApplication().
Referenced by AcceptAck().
|
private |
Sends the DHCP REQUEST message and changes the client state to WAIT_ACK.
Definition at line 372 of file dhcp-client.cc.
References ns3::Packet::AddHeader(), DHCP_PEER_PORT, ns3::DhcpHeader::DHCPREQ, ns3::Ipv4Address::Get(), ns3::RandomVariableStream::GetValue(), m_chaddr, m_myAddress, m_nextoffer, m_nextOfferEvent, m_offeredAddress, m_ran, m_remoteAddress, m_socket, m_state, m_tran, NS_LOG_FUNCTION, NS_LOG_INFO, REFRESH_LEASE, ns3::DhcpHeader::ResetOpt(), ns3::Simulator::Schedule(), Select(), ns3::Socket::SendTo(), ns3::DhcpHeader::SetChaddr(), ns3::DhcpHeader::SetReq(), ns3::DhcpHeader::SetTime(), ns3::DhcpHeader::SetTran(), ns3::DhcpHeader::SetType(), and WAIT_ACK.
Referenced by AcceptAck(), and Select().
|
private |
Selects an OFFER from m_offerList.
Definition at line 348 of file dhcp-client.cc.
References Boot(), ns3::DhcpHeader::GetDhcps(), ns3::DhcpHeader::GetLease(), ns3::DhcpHeader::GetMask(), ns3::DhcpHeader::GetRebind(), ns3::DhcpHeader::GetRenew(), ns3::DhcpHeader::GetRouter(), ns3::DhcpHeader::GetYiaddr(), m_gateway, m_lease, m_myMask, m_offered, m_offeredAddress, m_offerList, m_rebind, m_renew, m_server, NS_LOG_FUNCTION, Request(), and ns3::Seconds().
Referenced by OfferHandler(), and Request().
Set the NetDevice DHCP should work on.
netDevice | the NetDevice DHCP should work on |
Definition at line 127 of file dhcp-client.cc.
References m_device.
|
privatevirtual |
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 156 of file dhcp-client.cc.
References ns3::Socket::Bind(), ns3::Socket::BindToNetDevice(), Boot(), ns3::Address::CopyFrom(), ns3::Address::CopyTo(), ns3::Socket::CreateSocket(), ns3::Ipv4Address::GetAny(), ns3::Application::GetNode(), ns3::Object::GetObject(), LinkStateHandler(), ns3::TypeId::LookupByName(), m_chaddr, m_device, m_gateway, m_myAddress, m_remoteAddress, m_socket, ns3::MakeCallback(), ns3::Address::MAX_SIZE, NetHandler(), NS_ASSERT_MSG(), NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Socket::SetAllowBroadcast(), and ns3::Socket::SetRecvCallback().
Referenced by LinkStateHandler(), and RemoveAndStart().
|
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().
|
staticprivate |
DHCP server port.
Definition at line 107 of file dhcp-client.h.
Referenced by AcceptAck(), Boot(), and Request().
|
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().
|
private |
Time for which client should collect offers.
Definition at line 186 of file dhcp-client.h.
Referenced by GetTypeId(), and OfferHandler().
NetDevice pointer.
Definition at line 165 of file dhcp-client.h.
Referenced by AcceptAck(), DhcpClient(), DoDispose(), GetDhcpClientNetDevice(), LinkStateHandler(), RemoveAndStart(), SetDhcpClientNetDevice(), StartApplication(), and StopApplication().
|
private |
Message retransmission event.
Definition at line 175 of file dhcp-client.h.
Referenced by Boot(), DhcpClient(), OfferHandler(), and StopApplication().
|
private |
Trace of lease expire.
Definition at line 191 of file dhcp-client.h.
Referenced by AcceptAck(), GetTypeId(), and RemoveAndStart().
|
private |
Address of the gateway.
Definition at line 173 of file dhcp-client.h.
Referenced by AcceptAck(), LinkStateHandler(), RemoveAndStart(), Select(), and StartApplication().
|
private |
Store the lease time of address.
Definition at line 180 of file dhcp-client.h.
Referenced by AcceptAck(), and Select().
|
private |
Address assigned to the client.
Definition at line 169 of file dhcp-client.h.
Referenced by AcceptAck(), LinkStateHandler(), RemoveAndStart(), Request(), StartApplication(), and StopApplication().
|
private |
Mask of the address assigned.
Definition at line 171 of file dhcp-client.h.
Referenced by AcceptAck(), and Select().
|
private |
Trace of new lease.
Definition at line 190 of file dhcp-client.h.
Referenced by AcceptAck(), and GetTypeId().
|
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().
|
private |
Message next offer event.
Definition at line 178 of file dhcp-client.h.
Referenced by DhcpClient(), NetHandler(), RemoveAndStart(), Request(), and StopApplication().
|
private |
Specify if the client has got any offer.
Definition at line 187 of file dhcp-client.h.
Referenced by Boot(), OfferHandler(), and Select().
|
private |
Address offered to the client.
Definition at line 168 of file dhcp-client.h.
Referenced by AcceptAck(), Request(), and Select().
|
private |
Stores all the offers given to the client.
Definition at line 188 of file dhcp-client.h.
Referenced by AcceptAck(), OfferHandler(), and Select().
|
private |
Uniform random variable for transaction ID.
Definition at line 184 of file dhcp-client.h.
Referenced by AssignStreams(), Boot(), GetTypeId(), and Request().
|
private |
Store the rebind time of address.
Definition at line 182 of file dhcp-client.h.
Referenced by AcceptAck(), and Select().
|
private |
Message rebind event.
Definition at line 177 of file dhcp-client.h.
Referenced by AcceptAck(), DhcpClient(), LinkStateHandler(), RemoveAndStart(), and StopApplication().
|
private |
Message refresh event.
Definition at line 176 of file dhcp-client.h.
Referenced by AcceptAck(), DhcpClient(), LinkStateHandler(), RemoveAndStart(), and StopApplication().
|
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().
|
private |
Store the renew time of address.
Definition at line 181 of file dhcp-client.h.
Referenced by AcceptAck(), and Select().
|
private |
Address refresh event.
Definition at line 174 of file dhcp-client.h.
Referenced by DhcpClient(), and StopApplication().
|
private |
Defining the time for retransmission.
Definition at line 185 of file dhcp-client.h.
Referenced by Boot(), and GetTypeId().
|
private |
Address of the DHCP server.
Definition at line 172 of file dhcp-client.h.
Referenced by DhcpClient(), GetDhcpServer(), and Select().
Socket for remote communication.
Definition at line 166 of file dhcp-client.h.
Referenced by AcceptAck(), Boot(), DhcpClient(), LinkStateHandler(), NetHandler(), Request(), StartApplication(), and StopApplication().
|
private |
State of the DHCP client.
Definition at line 164 of file dhcp-client.h.
Referenced by AcceptAck(), Boot(), NetHandler(), and Request().
|
private |
The timeout period.
Definition at line 179 of file dhcp-client.h.
Referenced by AcceptAck(), DhcpClient(), LinkStateHandler(), RemoveAndStart(), and StopApplication().
|
private |
Stores the current transaction number to be used.
Definition at line 189 of file dhcp-client.h.