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