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 <limits>
22#include <map>
23
24namespace ns3
25{
26
28class Socket;
29class Packet;
30
31/**
32 * @ingroup dhcp
33 *
34 * @class DhcpServer
35 * @brief Implements the functionality of a DHCP server
36 */
37class DhcpServer : public Application
38{
39 public:
40 /**
41 * @brief Get the type ID.
42 * @return the object TypeId
43 */
44 static TypeId GetTypeId();
45
46 DhcpServer();
47 ~DhcpServer() override;
48
49 /**
50 * @brief Add a static entry to the pool.
51 *
52 * @param macAddr The client MAC address.
53 * @param addr The IP address to handle to the client.
54 */
55 void AddStaticDhcpEntry(Address macAddr, Ipv4Address addr);
56
57 protected:
58 void DoDispose() override;
59
60 private:
61 void StartApplication() override;
62 void StopApplication() override;
63
64 static const int PORT = 67; //!< Port number of DHCP server
65
66 /**
67 * @brief Handles incoming packets from the network
68 * @param socket Socket bound to port 67 of the DHCP server
69 */
70 void NetHandler(Ptr<Socket> socket);
71
72 /**
73 * @brief Sends DHCP offer after receiving DHCP Discover
74 * @param iDev incoming NetDevice
75 * @param header DHCP header of the received message
76 * @param from Address of the DHCP client
77 */
79
80 /**
81 * @brief Sends DHCP ACK (or NACK) after receiving Request
82 * @param iDev incoming NetDevice
83 * @param header DHCP header of the received message
84 * @param from Address of the DHCP client
85 */
86 void SendAck(Ptr<NetDevice> iDev, DhcpHeader header, InetSocketAddress from);
87
88 /**
89 * @brief Modifies the remaining lease time of addresses
90 */
91 void TimerHandler();
92
93 Ptr<Socket> m_socket; //!< The socket bound to port 67
94 Ipv4Address m_poolAddress; //!< The network address available to the server
95 Ipv4Address m_minAddress; //!< The first address in the address pool
96 Ipv4Address m_maxAddress; //!< The last address in the address pool
97 Ipv4Mask m_poolMask; //!< The network mask of the pool
98 Ipv4Address m_gateway; //!< The gateway address
99
100 /// Leased address container - chaddr + IP addr / lease time
101 using LeasedAddress = std::map<DhcpChaddr, std::pair<Ipv4Address, uint32_t>>;
102
103 /// Expired address container - chaddr
104 using ExpiredAddress = std::list<DhcpChaddr>;
105
106 /// Available address container - IP addr
107 using AvailableAddress = std::list<Ipv4Address>;
108
109 /// The maximum representable lease time means permanent lease.
110 static constexpr uint32_t PERMANENT_LEASE = std::numeric_limits<uint32_t>::max();
111
112 LeasedAddress m_leasedAddresses; //!< Leased address and their status (cache memory)
113 ExpiredAddress m_expiredAddresses; //!< Expired addresses to be reused (chaddr of the clients)
114 AvailableAddress m_availableAddresses; //!< Available addresses to be used (IP addresses)
115 Time m_lease; //!< The granted lease time for an address
116 Time m_renew; //!< The renewal time for an address
117 Time m_rebind; //!< The rebinding time for an address
118 EventId m_expiredEvent; //!< The Event to trigger TimerHandler
119};
120
121} // namespace ns3
122
123#endif /* DHCP_SERVER_H */
a polymophic address class
Definition address.h:111
BOOTP header with DHCP messages.
Definition dhcp-header.h:99
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:64
AvailableAddress m_availableAddresses
Available addresses to be used (IP addresses).
std::map< DhcpChaddr, std::pair< Ipv4Address, uint32_t > > LeasedAddress
Leased address container - chaddr + IP addr / lease time.
void AddStaticDhcpEntry(Address macAddr, Ipv4Address addr)
Add a static entry to the pool.
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:97
Ptr< Socket > m_socket
The socket bound to port 67.
Definition dhcp-server.h:93
ExpiredAddress m_expiredAddresses
Expired addresses to be reused (chaddr of the clients).
void StartApplication() override
Application specific startup code.
static constexpr uint32_t PERMANENT_LEASE
The maximum representable lease time means permanent lease.
LeasedAddress m_leasedAddresses
Leased address and their status (cache memory).
Ipv4Address m_minAddress
The first address in the address pool.
Definition dhcp-server.h:95
Ipv4Address m_gateway
The gateway address.
Definition dhcp-server.h:98
static TypeId GetTypeId()
Get the type ID.
std::list< Ipv4Address > AvailableAddress
Available address container - IP addr.
Time m_renew
The renewal time for an address.
Ipv4Address m_maxAddress
The last address in the address pool.
Definition dhcp-server.h:96
std::list< DhcpChaddr > ExpiredAddress
Expired address container - chaddr.
Ipv4Address m_poolAddress
The network address available to the server.
Definition dhcp-server.h:94
~DhcpServer() override
void TimerHandler()
Modifies the remaining lease time of addresses.
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.
void SendOffer(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP offer after receiving DHCP Discover.
void DoDispose() override
Destructor implementation.
An identifier for simulation events.
Definition event-id.h:44
an Inet address class
Ipv4 addresses are stored in host order in this class.
a class to represent an Ipv4 address mask
network packets
Definition packet.h:228
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
A low-level Socket API based loosely on the BSD Socket API.
Definition socket.h:57
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
a unique identifier for an interface.
Definition type-id.h:49
DhcpHeader classes declaration.
Every class exported by the ns3 library is enclosed in the ns3 namespace.