Implements the functionality of a DHCP server. More...
#include "dhcp-server.h"
Public Member Functions | |
DhcpServer () | |
~DhcpServer () override | |
void | AddStaticDhcpEntry (Address chaddr, Ipv4Address addr) |
Add a static entry to the pool. More... | |
Public Member Functions inherited from ns3::Application | |
Application () | |
~Application () override | |
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... | |
~Object () override | |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose () |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. More... | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. More... | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. More... | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. More... | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. More... | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. More... | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
bool | IsInitialized () 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[[maybe_unused]]) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o[[maybe_unused]]) |
Assignment operator. More... | |
void | Ref () const |
Increment the reference count. More... | |
void | Unref () 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 errors. 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 () |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Application | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. More... | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Protected Member Functions | |
void | DoDispose () override |
Destructor implementation. More... | |
Protected Member Functions inherited from ns3::Application | |
void | DoDispose () override |
Destructor implementation. More... | |
void | DoInitialize () override |
Initialize() implementation. More... | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. More... | |
virtual void | NotifyNewAggregate () |
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 () |
Notifier called once the ObjectBase is fully constructed. More... | |
Private Types | |
typedef std::list< Ipv4Address > | AvailableAddress |
Available address container - IP addr. More... | |
typedef std::list< Address > | ExpiredAddress |
Expired address container - chaddr. More... | |
typedef std::list< Address >::const_iterator | ExpiredAddressCIter |
Expired address const iterator - chaddr. More... | |
typedef std::list< Address >::iterator | ExpiredAddressIter |
Expired address iterator - chaddr. More... | |
typedef std::map< Address, std::pair< Ipv4Address, uint32_t > > | LeasedAddress |
Leased address container - chaddr + IP addr / lease time. More... | |
typedef std::map< Address, std::pair< Ipv4Address, uint32_t > >::const_iterator | LeasedAddressCIter |
Leased address const iterator - chaddr + IP addr / lease time. More... | |
typedef std::map< Address, std::pair< Ipv4Address, uint32_t > >::iterator | LeasedAddressIter |
Leased address iterator - chaddr + IP addr / lease time. More... | |
Private Member Functions | |
void | NetHandler (Ptr< Socket > socket) |
Handles incoming packets from the network. More... | |
void | SendAck (Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from) |
Sends DHCP ACK (or NACK) after receiving Request. More... | |
void | SendOffer (Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from) |
Sends DHCP offer after receiving DHCP Discover. More... | |
void | StartApplication () override |
Starts the DHCP Server application. More... | |
void | StopApplication () override |
Stops the DHCP client application. More... | |
void | TimerHandler () |
Modifies the remaining lease time of addresses. More... | |
Private Attributes | |
AvailableAddress | m_availableAddresses |
Available addresses to be used (IP addresses) More... | |
ExpiredAddress | m_expiredAddresses |
Expired addresses to be reused (chaddr of the clients) More... | |
EventId | m_expiredEvent |
The Event to trigger TimerHandler. More... | |
Ipv4Address | m_gateway |
The gateway address. More... | |
Time | m_lease |
The granted lease time for an address. More... | |
LeasedAddress | m_leasedAddresses |
Leased address and their status (cache memory) More... | |
Ipv4Address | m_maxAddress |
The last address in the address pool. More... | |
Ipv4Address | m_minAddress |
The first address in the address pool. More... | |
Ipv4Address | m_poolAddress |
The network address available to the server. More... | |
Ipv4Mask | m_poolMask |
The network mask of the pool. More... | |
Time | m_rebind |
The rebinding time for an address. More... | |
Time | m_renew |
The renewal time for an address. More... | |
Ptr< Socket > | m_socket |
The socket bound to port 67. More... | |
Static Private Attributes | |
static const int | PORT = 67 |
Port number of DHCP server. 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 () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
Implements the functionality of a DHCP server.
Definition at line 47 of file dhcp-server.h.
|
private |
Available address container - IP addr.
Definition at line 132 of file dhcp-server.h.
|
private |
Expired address container - chaddr.
Definition at line 125 of file dhcp-server.h.
|
private |
Expired address const iterator - chaddr.
Definition at line 129 of file dhcp-server.h.
|
private |
Expired address iterator - chaddr.
Definition at line 127 of file dhcp-server.h.
|
private |
Leased address container - chaddr + IP addr / lease time.
Definition at line 118 of file dhcp-server.h.
|
private |
Leased address const iterator - chaddr + IP addr / lease time.
Definition at line 122 of file dhcp-server.h.
|
private |
Leased address iterator - chaddr + IP addr / lease time.
Definition at line 120 of file dhcp-server.h.
ns3::DhcpServer::DhcpServer | ( | ) |
Definition at line 95 of file dhcp-server.cc.
References NS_LOG_FUNCTION.
|
override |
Definition at line 100 of file dhcp-server.cc.
References NS_LOG_FUNCTION.
void ns3::DhcpServer::AddStaticDhcpEntry | ( | Address | chaddr, |
Ipv4Address | addr | ||
) |
Add a static entry to the pool.
chaddr | The client chaddr. |
addr | The address to handle to the client. |
Definition at line 408 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.
|
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::Object.
Definition at line 106 of file dhcp-server.cc.
References ns3::Application::DoDispose(), and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 46 of file dhcp-server.cc.
References m_gateway, m_lease, m_maxAddress, m_minAddress, m_poolAddress, m_poolMask, m_rebind, m_renew, ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().
Referenced by ns3::DhcpHelper::DhcpHelper().
Handles incoming packets from the network.
socket | Socket bound to port 67 of the DHCP server |
Definition at line 215 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(), ns3::Packet::RemoveHeader(), ns3::Packet::RemovePacketTag(), SendAck(), and SendOffer().
Referenced by StartApplication().
|
private |
Sends DHCP ACK (or NACK) after receiving Request.
iDev | incoming NetDevice |
header | DHCP header of the received message |
from | Address of the DHCP client |
Definition at line 344 of file dhcp-server.cc.
References ns3::Packet::AddHeader(), first::address, 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().
|
private |
Sends DHCP offer after receiving DHCP Discover.
iDev | incoming NetDevice |
header | DHCP header of the received message |
from | Address of the DHCP client |
Definition at line 250 of file dhcp-server.cc.
References ns3::Packet::AddHeader(), 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(), nsclick-simple-lan::ipv4, 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().
|
overrideprivatevirtual |
Starts the DHCP Server application.
Reimplemented from ns3::Application.
Definition at line 113 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(), nsclick-simple-lan::ipv4, 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().
|
overrideprivatevirtual |
Stops the DHCP client application.
Reimplemented from ns3::Application.
Definition at line 176 of file dhcp-server.cc.
References ns3::EventId::Cancel(), m_expiredEvent, m_leasedAddresses, m_socket, ns3::MakeNullCallback(), NS_LOG_FUNCTION, and ns3::Socket::SetRecvCallback().
|
private |
Modifies the remaining lease time of addresses.
Definition at line 190 of file dhcp-server.cc.
References m_expiredAddresses, m_expiredEvent, m_leasedAddresses, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Simulator::Schedule(), and ns3::Seconds().
Referenced by StartApplication().
|
private |
Available addresses to be used (IP addresses)
Definition at line 136 of file dhcp-server.h.
Referenced by AddStaticDhcpEntry(), SendOffer(), and StartApplication().
|
private |
Expired addresses to be reused (chaddr of the clients)
Definition at line 135 of file dhcp-server.h.
Referenced by SendOffer(), and TimerHandler().
|
private |
The Event to trigger TimerHandler.
Definition at line 140 of file dhcp-server.h.
Referenced by StartApplication(), StopApplication(), and TimerHandler().
|
private |
The gateway address.
Definition at line 115 of file dhcp-server.h.
Referenced by GetTypeId(), and SendOffer().
|
private |
The granted lease time for an address.
Definition at line 137 of file dhcp-server.h.
Referenced by GetTypeId(), SendAck(), and SendOffer().
|
private |
Leased address and their status (cache memory)
Definition at line 134 of file dhcp-server.h.
Referenced by AddStaticDhcpEntry(), SendAck(), SendOffer(), StartApplication(), StopApplication(), and TimerHandler().
|
private |
The last address in the address pool.
Definition at line 113 of file dhcp-server.h.
Referenced by AddStaticDhcpEntry(), GetTypeId(), NetHandler(), and StartApplication().
|
private |
The first address in the address pool.
Definition at line 112 of file dhcp-server.h.
Referenced by AddStaticDhcpEntry(), GetTypeId(), NetHandler(), and StartApplication().
|
private |
The network address available to the server.
Definition at line 111 of file dhcp-server.h.
Referenced by GetTypeId(), and StartApplication().
|
private |
The network mask of the pool.
Definition at line 114 of file dhcp-server.h.
Referenced by GetTypeId(), SendOffer(), and StartApplication().
|
private |
The rebinding time for an address.
Definition at line 139 of file dhcp-server.h.
Referenced by GetTypeId(), and SendOffer().
|
private |
The renewal time for an address.
Definition at line 138 of file dhcp-server.h.
Referenced by GetTypeId(), and SendOffer().
The socket bound to port 67.
Definition at line 110 of file dhcp-server.h.
Referenced by NetHandler(), SendAck(), SendOffer(), StartApplication(), and StopApplication().
|
staticprivate |
Port number of DHCP server.
Definition at line 71 of file dhcp-server.h.
Referenced by StartApplication().