A Discrete-Event Network Simulator
API
dhcp-server.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 UPB
4  * Copyright (c) 2017 NITK Surathkal
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Radu Lupu <rlupu@elcom.pub.ro>
20  * Ankit Deepak <adadeepak8@gmail.com>
21  * Deepti Rajagopal <deeptir96@gmail.com>
22  *
23  */
24 
25 #ifndef DHCP_SERVER_H
26 #define DHCP_SERVER_H
27 
28 #include "ns3/application.h"
29 #include "ns3/ipv4-address.h"
30 #include "dhcp-header.h"
31 #include <map>
32 
33 namespace ns3 {
34 
35 class Socket;
36 class Packet;
37 
44 class DhcpServer : public Application
45 {
46 public:
51  static TypeId GetTypeId (void);
52 
53  DhcpServer ();
54  virtual ~DhcpServer ();
55 
62  void AddStaticDhcpEntry (Address chaddr, Ipv4Address addr);
63 
64 
65 protected:
66  virtual void DoDispose (void);
67 
68 private:
69  static const int PORT = 67;
70 
75  void NetHandler (Ptr<Socket> socket);
76 
83  void SendOffer (Ptr<NetDevice> iDev, DhcpHeader header, InetSocketAddress from);
84 
91  void SendAck (Ptr<NetDevice> iDev, DhcpHeader header, InetSocketAddress from);
92 
96  void TimerHandler (void);
97 
101  virtual void StartApplication (void);
102 
106  virtual void StopApplication (void);
107 
114 
116  typedef std::map<Address, std::pair<Ipv4Address, uint32_t> > LeasedAddress;
118  typedef std::map<Address, std::pair<Ipv4Address, uint32_t> >::iterator LeasedAddressIter;
120  typedef std::map<Address, std::pair<Ipv4Address, uint32_t> >::const_iterator LeasedAddressCIter;
121 
123  typedef std::list<Address> ExpiredAddress;
125  typedef std::list<Address>::iterator ExpiredAddressIter;
127  typedef std::list<Address>::const_iterator ExpiredAddressCIter;
128 
130  typedef std::list<Ipv4Address> AvailableAddress;
131 
139 };
140 
141 } // namespace ns3
142 
143 #endif /* DHCP_SERVER_H */
ns3::DhcpServer::TimerHandler
void TimerHandler(void)
Modifies the remaining lease time of addresses.
Definition: dhcp-server.cc:184
ns3::DhcpServer::m_rebind
Time m_rebind
The rebinding time for an address.
Definition: dhcp-server.h:137
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::DhcpServer::m_availableAddresses
AvailableAddress m_availableAddresses
Available addresses to be used (IP addresses)
Definition: dhcp-server.h:134
ns3::DhcpServer::PORT
static const int PORT
Port number of DHCP server.
Definition: dhcp-server.h:69
ns3::DhcpServer::DhcpServer
DhcpServer()
Definition: dhcp-server.cc:93
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::DhcpServer::AvailableAddress
std::list< Ipv4Address > AvailableAddress
Available address container - IP addr.
Definition: dhcp-server.h:130
ns3::DhcpServer::m_poolAddress
Ipv4Address m_poolAddress
The network address available to the server.
Definition: dhcp-server.h:109
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DhcpServer::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-server.cc:104
dhcp-header.h
ns3::DhcpServer::m_minAddress
Ipv4Address m_minAddress
The first address in the address pool.
Definition: dhcp-server.h:110
ns3::DhcpServer::m_lease
Time m_lease
The granted lease time for an address.
Definition: dhcp-server.h:135
ns3::DhcpServer::m_maxAddress
Ipv4Address m_maxAddress
The last address in the address pool.
Definition: dhcp-server.h:111
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::DhcpServer::m_expiredEvent
EventId m_expiredEvent
The Event to trigger TimerHandler.
Definition: dhcp-server.h:138
ns3::DhcpServer::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-server.cc:43
ns3::DhcpServer::ExpiredAddressIter
std::list< Address >::iterator ExpiredAddressIter
Expired address iterator - chaddr.
Definition: dhcp-server.h:125
ns3::DhcpServer::LeasedAddressIter
std::map< Address, std::pair< Ipv4Address, uint32_t > >::iterator LeasedAddressIter
Leased address iterator - chaddr + IP addr / lease time.
Definition: dhcp-server.h:118
ns3::DhcpServer::m_renew
Time m_renew
The renewal time for an address.
Definition: dhcp-server.h:136
ns3::DhcpServer::m_leasedAddresses
LeasedAddress m_leasedAddresses
Leased address and their status (cache memory)
Definition: dhcp-server.h:132
ns3::DhcpServer::ExpiredAddressCIter
std::list< Address >::const_iterator ExpiredAddressCIter
Expired address const iterator - chaddr.
Definition: dhcp-server.h:127
ns3::DhcpServer::SendOffer
void SendOffer(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP offer after receiving DHCP Discover.
Definition: dhcp-server.cc:242
ns3::DhcpServer::m_socket
Ptr< Socket > m_socket
The socket bound to port 67.
Definition: dhcp-server.h:108
ns3::Ptr< Socket >
ns3::DhcpServer::SendAck
void SendAck(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP ACK (or NACK) after receiving Request.
Definition: dhcp-server.cc:326
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::DhcpServer::NetHandler
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-server.cc:209
ns3::DhcpServer::m_poolMask
Ipv4Mask m_poolMask
The network mask of the pool.
Definition: dhcp-server.h:112
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::DhcpServer::StopApplication
virtual void StopApplication(void)
Stops the DHCP client application.
Definition: dhcp-server.cc:171
ns3::DhcpServer::ExpiredAddress
std::list< Address > ExpiredAddress
Expired address container - chaddr.
Definition: dhcp-server.h:123
ns3::DhcpServer::m_gateway
Ipv4Address m_gateway
The gateway address.
Definition: dhcp-server.h:113
ns3::DhcpServer::LeasedAddress
std::map< Address, std::pair< Ipv4Address, uint32_t > > LeasedAddress
Leased address container - chaddr + IP addr / lease time.
Definition: dhcp-server.h:116
ns3::DhcpServer::LeasedAddressCIter
std::map< Address, std::pair< Ipv4Address, uint32_t > >::const_iterator LeasedAddressCIter
Leased address const iterator - chaddr + IP addr / lease time.
Definition: dhcp-server.h:120
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
ns3::DhcpServer::AddStaticDhcpEntry
void AddStaticDhcpEntry(Address chaddr, Ipv4Address addr)
Add a static entry to the pool.
Definition: dhcp-server.cc:386
ns3::DhcpServer::~DhcpServer
virtual ~DhcpServer()
Definition: dhcp-server.cc:98
ns3::DhcpServer::m_expiredAddresses
ExpiredAddress m_expiredAddresses
Expired addresses to be reused (chaddr of the clients)
Definition: dhcp-server.h:133
ns3::Application
The base class for all ns3 applications.
Definition: application.h:61
ns3::DhcpHeader
BOOTP header with DHCP messages supports the following options: Subnet Mask (1), Address Request (50)...
Definition: dhcp-header.h:82
ns3::DhcpServer
Implements the functionality of a DHCP server.
Definition: dhcp-server.h:45
ns3::DhcpServer::StartApplication
virtual void StartApplication(void)
Starts the DHCP Server application.
Definition: dhcp-server.cc:110