A Discrete-Event Network Simulator
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
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  */
25 #ifndef DHCP_SERVER_H
26 #define DHCP_SERVER_H
28 #include "ns3/application.h"
29 #include "ns3/event-id.h"
30 #include "ns3/ptr.h"
31 #include "ns3/address.h"
32 #include "ns3/traced-value.h"
33 #include "ns3/inet-socket-address.h"
34 #include "dhcp-header.h"
35 #include <map>
37 namespace ns3 {
39 class Socket;
40 class Packet;
48 class DhcpServer : public Application
49 {
50 public:
55  static TypeId GetTypeId (void);
57  DhcpServer ();
58  virtual ~DhcpServer ();
66  void AddStaticDhcpEntry (Address chaddr, Ipv4Address addr);
69 protected:
70  virtual void DoDispose (void);
72 private:
73  static const int PORT = 67;
79  void NetHandler (Ptr<Socket> socket);
87  void SendOffer (Ptr<NetDevice> iDev, DhcpHeader header, InetSocketAddress from);
95  void SendAck (Ptr<NetDevice> iDev, DhcpHeader header, InetSocketAddress from);
100  void TimerHandler (void);
105  virtual void StartApplication (void);
110  virtual void StopApplication (void);
120  typedef std::map<Address, std::pair<Ipv4Address, uint32_t> > LeasedAddress;
122  typedef std::map<Address, std::pair<Ipv4Address, uint32_t> >::iterator LeasedAddressIter;
124  typedef std::map<Address, std::pair<Ipv4Address, uint32_t> >::const_iterator LeasedAddressCIter;
127  typedef std::list<Address> ExpiredAddress;
129  typedef std::list<Address>::iterator ExpiredAddressIter;
131  typedef std::list<Address>::const_iterator ExpiredAddressCIter;
134  typedef std::list<Ipv4Address> AvailableAddress;
136  LeasedAddress m_leasedAddresses;
137  ExpiredAddress m_expiredAddresses;
138  AvailableAddress m_availableAddresses;
143 };
145 } // namespace ns3
147 #endif /* DHCP_SERVER_H */
Ipv4Address m_minAddress
The first address in the address pool.
Definition: dhcp-server.h:114
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ptr< Socket > m_socket
The socket bound to port 67.
Definition: dhcp-server.h:112
AvailableAddress m_availableAddresses
Available addresses to be used (IP addresses)
Definition: dhcp-server.h:138
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-server.cc:49
an Inet address class
Ipv4Address m_maxAddress
The last address in the address pool.
Definition: dhcp-server.h:115
std::list< Address >::const_iterator ExpiredAddressCIter
Expired address const iterator - chaddr.
Definition: dhcp-server.h:131
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
Implements the functionality of a DHCP server.
Definition: dhcp-server.h:48
std::map< Address, std::pair< Ipv4Address, uint32_t > >::iterator LeasedAddressIter
Leased address iterator - chaddr + IP addr / lease time.
Definition: dhcp-server.h:122
Ipv4Address m_gateway
The gateway address.
Definition: dhcp-server.h:117
a polymophic address class
Definition: address.h:90
void AddStaticDhcpEntry(Address chaddr, Ipv4Address addr)
Add a static entry to the pool.
Definition: dhcp-server.cc:392
Ipv4Address m_poolAddress
The network address available to the server.
Definition: dhcp-server.h:113
Time m_lease
The granted lease time for an address.
Definition: dhcp-server.h:139
void SendAck(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP ACK (or NACK) after receiving Request.
Definition: dhcp-server.cc:332
The base class for all ns3 applications.
Definition: application.h:60
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-server.cc:110
Introspection did not find any typical Config paths.
Definition: dhcp-header.h:83
LeasedAddress m_leasedAddresses
Leased address and their status (cache memory)
Definition: dhcp-server.h:136
std::map< Address, std::pair< Ipv4Address, uint32_t > >::const_iterator LeasedAddressCIter
Leased address const iterator - chaddr + IP addr / lease time.
Definition: dhcp-server.h:124
Time m_renew
The renewal time for an address.
Definition: dhcp-server.h:140
std::list< Address >::iterator ExpiredAddressIter
Expired address iterator - chaddr.
Definition: dhcp-server.h:129
std::map< Address, std::pair< Ipv4Address, uint32_t > > LeasedAddress
Leased address container - chaddr + IP addr / lease time.
Definition: dhcp-server.h:120
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const int PORT
Port number of DHCP server.
Definition: dhcp-server.h:73
Ipv4Mask m_poolMask
The network mask of the pool.
Definition: dhcp-server.h:116
ExpiredAddress m_expiredAddresses
Expired addresses to be reused (chaddr of the clients)
Definition: dhcp-server.h:137
virtual void StartApplication(void)
Starts the DHCP Server application.
Definition: dhcp-server.cc:116
EventId m_expiredEvent
The Event to trigger TimerHandler.
Definition: dhcp-server.h:142
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
An identifier for simulation events.
Definition: event-id.h:53
Time m_rebind
The rebinding time for an address.
Definition: dhcp-server.h:141
void SendOffer(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP offer after receiving DHCP Discover.
Definition: dhcp-server.cc:248
void TimerHandler(void)
Modifies the remaining lease time of addresses.
Definition: dhcp-server.cc:190
virtual ~DhcpServer()
Definition: dhcp-server.cc:104
std::list< Address > ExpiredAddress
Expired address container - chaddr.
Definition: dhcp-server.h:127
virtual void StopApplication(void)
Stops the DHCP client application.
Definition: dhcp-server.cc:177
std::list< Ipv4Address > AvailableAddress
Available address container - IP addr.
Definition: dhcp-server.h:134
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-server.cc:215
a unique identifier for an interface.
Definition: type-id.h:58