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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Radu Lupu <rlupu@elcom.pub.ro>
8 * Ankit Deepak <adadeepak8@gmail.com>
9 * Deepti Rajagopal <deeptir96@gmail.com>
10 *
11 */
12
13#ifndef DHCP_SERVER_H
14#define DHCP_SERVER_H
15
16#include "dhcp-header.h"
17
18#include "ns3/application.h"
19#include "ns3/ipv4-address.h"
20
21#include <map>
22
23namespace ns3
24{
25
26class InetSocketAddress;
27class Socket;
28class Packet;
29
30/**
31 * \ingroup dhcp
32 *
33 * \class DhcpServer
34 * \brief Implements the functionality of a DHCP server
35 */
36class DhcpServer : public Application
37{
38 public:
39 /**
40 * \brief Get the type ID.
41 * \return the object TypeId
42 */
43 static TypeId GetTypeId();
44
45 DhcpServer();
46 ~DhcpServer() override;
47
48 /**
49 * \brief Add a static entry to the pool.
50 *
51 * \param chaddr The client chaddr.
52 * \param addr The address to handle to the client.
53 */
54 void AddStaticDhcpEntry(Address chaddr, Ipv4Address addr);
55
56 protected:
57 void DoDispose() override;
58
59 private:
60 void StartApplication() override;
61 void StopApplication() override;
62
63 static const int PORT = 67; //!< Port number of DHCP server
64
65 /**
66 * \brief Handles incoming packets from the network
67 * \param socket Socket bound to port 67 of the DHCP server
68 */
69 void NetHandler(Ptr<Socket> socket);
70
71 /**
72 * \brief Sends DHCP offer after receiving DHCP Discover
73 * \param iDev incoming NetDevice
74 * \param header DHCP header of the received message
75 * \param from Address of the DHCP client
76 */
78
79 /**
80 * \brief Sends DHCP ACK (or NACK) after receiving Request
81 * \param iDev incoming NetDevice
82 * \param header DHCP header of the received message
83 * \param from Address of the DHCP client
84 */
85 void SendAck(Ptr<NetDevice> iDev, DhcpHeader header, InetSocketAddress from);
86
87 /**
88 * \brief Modifies the remaining lease time of addresses
89 */
90 void TimerHandler();
91
92 Ptr<Socket> m_socket; //!< The socket bound to port 67
93 Ipv4Address m_poolAddress; //!< The network address available to the server
94 Ipv4Address m_minAddress; //!< The first address in the address pool
95 Ipv4Address m_maxAddress; //!< The last address in the address pool
96 Ipv4Mask m_poolMask; //!< The network mask of the pool
97 Ipv4Address m_gateway; //!< The gateway address
98
99 /// Leased address container - chaddr + IP addr / lease time
100 typedef std::map<Address, std::pair<Ipv4Address, uint32_t>> LeasedAddress;
101 /// Leased address iterator - chaddr + IP addr / lease time
102 typedef std::map<Address, std::pair<Ipv4Address, uint32_t>>::iterator LeasedAddressIter;
103 /// Leased address const iterator - chaddr + IP addr / lease time
104 typedef std::map<Address, std::pair<Ipv4Address, uint32_t>>::const_iterator LeasedAddressCIter;
105
106 /// Expired address container - chaddr
107 typedef std::list<Address> ExpiredAddress;
108 /// Expired address iterator - chaddr
109 typedef std::list<Address>::iterator ExpiredAddressIter;
110 /// Expired address const iterator - chaddr
111 typedef std::list<Address>::const_iterator ExpiredAddressCIter;
112
113 /// Available address container - IP addr
114 typedef std::list<Ipv4Address> AvailableAddress;
115
116 LeasedAddress m_leasedAddresses; //!< Leased address and their status (cache memory)
117 ExpiredAddress m_expiredAddresses; //!< Expired addresses to be reused (chaddr of the clients)
118 AvailableAddress m_availableAddresses; //!< Available addresses to be used (IP addresses)
119 Time m_lease; //!< The granted lease time for an address
120 Time m_renew; //!< The renewal time for an address
121 Time m_rebind; //!< The rebinding time for an address
122 EventId m_expiredEvent; //!< The Event to trigger TimerHandler
123};
124
125} // namespace ns3
126
127#endif /* DHCP_SERVER_H */
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
BOOTP header with DHCP messages.
Definition dhcp-header.h:73
Implements the functionality of a DHCP server.
Definition dhcp-server.h:37
EventId m_expiredEvent
The Event to trigger TimerHandler.
void StopApplication() override
Application specific shutdown code.
static const int PORT
Port number of DHCP server.
Definition dhcp-server.h:63
AvailableAddress m_availableAddresses
Available addresses to be used (IP addresses)
Time m_rebind
The rebinding time for an address.
Time m_lease
The granted lease time for an address.
Ipv4Mask m_poolMask
The network mask of the pool.
Definition dhcp-server.h:96
Ptr< Socket > m_socket
The socket bound to port 67.
Definition dhcp-server.h:92
ExpiredAddress m_expiredAddresses
Expired addresses to be reused (chaddr of the clients)
std::map< Address, std::pair< Ipv4Address, uint32_t > > LeasedAddress
Leased address container - chaddr + IP addr / lease time.
void StartApplication() override
Application specific startup code.
std::map< Address, std::pair< Ipv4Address, uint32_t > >::const_iterator LeasedAddressCIter
Leased address const iterator - chaddr + IP addr / lease time.
std::list< Ipv4Address > AvailableAddress
Available address container - IP addr.
void AddStaticDhcpEntry(Address chaddr, Ipv4Address addr)
Add a static entry to the pool.
LeasedAddress m_leasedAddresses
Leased address and their status (cache memory)
Ipv4Address m_minAddress
The first address in the address pool.
Definition dhcp-server.h:94
std::list< Address >::iterator ExpiredAddressIter
Expired address iterator - chaddr.
Ipv4Address m_gateway
The gateway address.
Definition dhcp-server.h:97
static TypeId GetTypeId()
Get the type ID.
Time m_renew
The renewal time for an address.
Ipv4Address m_maxAddress
The last address in the address pool.
Definition dhcp-server.h:95
Ipv4Address m_poolAddress
The network address available to the server.
Definition dhcp-server.h:93
~DhcpServer() override
void TimerHandler()
Modifies the remaining lease time of addresses.
std::list< Address >::const_iterator ExpiredAddressCIter
Expired address const iterator - chaddr.
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
void SendAck(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP ACK (or NACK) after receiving Request.
std::map< Address, std::pair< Ipv4Address, uint32_t > >::iterator LeasedAddressIter
Leased address iterator - chaddr + IP addr / lease time.
void SendOffer(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP offer after receiving DHCP Discover.
void DoDispose() override
Destructor implementation.
std::list< Address > ExpiredAddress
Expired address container - chaddr.
An identifier for simulation events.
Definition event-id.h:45
an Inet address class
Ipv4 addresses are stored in host order in this class.
a class to represent an Ipv4 address mask
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.