A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dhcp6-server.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kavya Bhat <kavyabhat@gmail.com>
7 *
8 */
9
10#ifndef DHCP6_SERVER_H
11#define DHCP6_SERVER_H
12
13#include "dhcp6-duid.h"
14#include "dhcp6-header.h"
15
16#include "ns3/application.h"
17#include "ns3/ipv6-address.h"
18#include "ns3/net-device-container.h"
19#include "ns3/pair.h"
20#include "ns3/ptr.h"
21
22#include <map>
23
24namespace ns3
25{
26
27class Inet6SocketAddress;
28class Socket;
29class Packet;
30
31/**
32 * @ingroup dhcp6
33 *
34 * @class LeaseInfo
35 * @brief Includes information about available subnets and corresponding leases.
36 */
38{
39 public:
40 /**
41 * Constructor.
42 * @param addressPool Address pool
43 * @param prefix Prefix of the address pool
44 * @param minAddress Minimum address in the pool
45 * @param maxAddress Maximum address in the pool
46 */
47 LeaseInfo(Ipv6Address addressPool,
48 Ipv6Prefix prefix,
49 Ipv6Address minAddress,
50 Ipv6Address maxAddress);
51
52 friend class Dhcp6Server;
53
54 private:
55 /**
56 * @brief Get the address pool.
57 * @return The address pool
58 */
60
61 /**
62 * @brief Get the prefix of the address pool.
63 * @return The prefix of the address pool
64 */
65 Ipv6Prefix GetPrefix() const;
66
67 /**
68 * @brief Get the minimum address in the pool.
69 * @return The minimum address in the pool
70 */
72
73 /**
74 * @brief Get the maximum address in the pool.
75 * @return The maximum address in the pool
76 */
78
79 /**
80 * @brief Get the number of addresses leased.
81 * @return The number of addresses leased
82 */
84
85 /**
86 * @brief Expired Addresses (Section 6.2 of RFC 8415)
87 * Expired time / Ipv6Address
88 */
89 typedef std::multimap<Time, std::pair<Duid, Ipv6Address>> ExpiredAddresses;
90
91 /**
92 * @brief Leased Addresses
93 * Client DUID + Ipv6Address / Lease time
94 */
95 typedef std::unordered_multimap<Duid, std::pair<Ipv6Address, Time>, Duid::DuidHash>
97
98 /**
99 * @brief Declined Addresses
100 * Ipv6Address + Client DUID
101 */
102 typedef std::unordered_map<Ipv6Address, Duid, Ipv6AddressHash> DeclinedAddresses;
103
104 LeasedAddresses m_leasedAddresses; //!< Leased addresses
105 ExpiredAddresses m_expiredAddresses; //!< Expired addresses
106 DeclinedAddresses m_declinedAddresses; //!< Declined addresses
107 Ipv6Address m_maxOfferedAddress; //!< Maximum address offered so far.
108
109 Ipv6Address m_addressPool; //!< Address pool
110 Ipv6Prefix m_prefix; //!< Prefix of the address pool
111 Ipv6Address m_minAddress; //!< Minimum address in the pool
112 Ipv6Address m_maxAddress; //!< Maximum address in the pool
113 uint32_t m_numAddresses; //!< Number of addresses leased.
114};
115
116/**
117 * @ingroup dhcp6
118 *
119 * @class Dhcp6Server
120 * @brief Implements the DHCPv6 server.
121 */
123{
124 public:
125 /**
126 * @brief Get the type ID.
127 * @return the object TypeId
128 */
129 static TypeId GetTypeId();
130
131 /**
132 * @brief Default constructor.
133 */
134 Dhcp6Server();
135
136 /**
137 * @brief Set the list of net devices that the DHCPv6 server will use.
138 * @param netDevices The net devices that the server will listen on.
139 */
141
142 /**
143 * @brief Add a managed address pool.
144 * @param pool The address pool to be managed by the server.
145 * @param prefix The prefix of the address pool.
146 * @param minAddress The minimum address in the pool.
147 * @param maxAddress The maximum address in the pool.
148 */
149 void AddSubnet(Ipv6Address pool,
150 Ipv6Prefix prefix,
151 Ipv6Address minAddress,
152 Ipv6Address maxAddress);
153
154 protected:
155 void DoDispose() override;
156
157 private:
158 void StartApplication() override;
159 void StopApplication() override;
160
161 /**
162 * @brief Handles incoming packets from the network
163 * @param socket Socket bound to port 547 of the DHCP server
164 */
165 void NetHandler(Ptr<Socket> socket);
166
167 /**
168 * @brief Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.
169 * @param iDev incoming NetDevice
170 * @param header DHCPv6 header of the received message
171 * @param client Address of the DHCPv6 client
172 */
174
175 /**
176 * @brief Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.
177 * @param iDev incoming NetDevice
178 * @param header DHCPv6 header of the received message
179 * @param client Address of the DHCPv6 client
180 */
182
183 /**
184 * @brief Sends Reply after receiving Request
185 * @param iDev incoming NetDevice
186 * @param header DHCPv6 header of the received message
187 * @param client Address of the DHCP client
188 */
189 void SendReply(Ptr<NetDevice> iDev, Dhcp6Header header, Inet6SocketAddress client);
190
191 /**
192 * @brief Sends Reply after receiving Request
193 * @param iDev incoming NetDevice
194 * @param header DHCPv6 header of the received message
195 * @param client Address of the DHCP client
196 */
198
199 /**
200 * @brief Sends Reply after receiving Request
201 * @param iDev incoming NetDevice
202 * @param header DHCPv6 header of the received message
203 * @param client Address of the DHCP client
204 */
206
207 /**
208 * @brief Modifies the remaining lease time of addresses
209 */
211
212 /**
213 * @brief Callback for when an M flag is received.
214 * @param recvInterface The interface on which the M flag was received.
215 */
216 void ReceiveMflag(uint32_t recvInterface);
217
218 /**
219 * @brief Clean up stale lease info.
220 */
221 void CleanLeases();
222
223 Ptr<Socket> m_recvSocket; //!< Socket bound to port 547.
224 Duid m_serverDuid; //!< Server DUID
225 std::vector<LeaseInfo> m_subnets; //!< List of managed subnets.
226 Time m_leaseCleanup = Seconds(10.0); //!< Lease cleanup time
227 EventId m_leaseCleanupEvent; //!< Event ID for lease cleanup
228
229 /// Map of NetDevice - Corresponding socket used to send packets.
230 std::unordered_map<uint32_t, Ptr<Socket>> m_sendSockets;
231
232 /// Store IA bindings. Map of DUID + IA Type / IAID
233 std::multimap<Duid, std::pair<Options::OptionType, uint32_t>> m_iaBindings;
234
235 /**
236 * @brief Default preferred lifetime for an address.
237 * According to ISC's Kea guide, the default preferred lifetime is 3000
238 * seconds.
239 */
241
242 /**
243 * @brief Default valid lifetime.
244 * According to ISC's Kea guide, the default valid lifetime is 4000 seconds.
245 */
247
248 /**
249 * @brief The default renew timer.
250 * This defines the T1 timer. According to ISC's Kea guide, the default
251 * renew timer is 1000 seconds.
252 * Maximum value is REN_MAX_RT (RFC 8415, Section 7.6).
253 */
255
256 /**
257 * @brief The default rebind timer.
258 * This defines the T2 timer. According to ISC's Kea guide, the default
259 * rebind timer is 2000 seconds.
260 * Maximum value is REB_MAX_RT (RFC 8415, Section 7.6).
261 */
263};
264} // namespace ns3
265
266#endif
The base class for all ns3 applications.
Definition application.h:51
Implements the DHCPv6 header.
Implements the DHCPv6 server.
void SendAdvertise(Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.
std::unordered_map< uint32_t, Ptr< Socket > > m_sendSockets
Map of NetDevice - Corresponding socket used to send packets.
void DoDispose() override
Destructor implementation.
void SendReply(Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
Sends Reply after receiving Request.
void TimerHandler()
Modifies the remaining lease time of addresses.
void StartApplication() override
Application specific startup code.
void AddSubnet(Ipv6Address pool, Ipv6Prefix prefix, Ipv6Address minAddress, Ipv6Address maxAddress)
Add a managed address pool.
std::multimap< Duid, std::pair< Options::OptionType, uint32_t > > m_iaBindings
Store IA bindings. Map of DUID + IA Type / IAID.
Duid m_serverDuid
Server DUID.
EventId m_leaseCleanupEvent
Event ID for lease cleanup.
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
static TypeId GetTypeId()
Get the type ID.
Dhcp6Server()
Default constructor.
Ptr< Socket > m_recvSocket
Socket bound to port 547.
Time m_validLifetime
Default valid lifetime.
Time m_prefLifetime
Default preferred lifetime for an address.
Time m_renew
The default renew timer.
std::vector< LeaseInfo > m_subnets
List of managed subnets.
void SetDhcp6ServerNetDevice(NetDeviceContainer netDevices)
Set the list of net devices that the DHCPv6 server will use.
void CleanLeases()
Clean up stale lease info.
void ProcessSolicit(Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
Sends DHCPv6 Advertise after receiving DHCPv6 Solicit.
void StopApplication() override
Application specific shutdown code.
Time m_leaseCleanup
Lease cleanup time.
void ReceiveMflag(uint32_t recvInterface)
Callback for when an M flag is received.
void UpdateBindings(Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
Sends Reply after receiving Request.
void RenewRebindLeases(Ptr< NetDevice > iDev, Dhcp6Header header, Inet6SocketAddress client)
Sends Reply after receiving Request.
Time m_rebind
The default rebind timer.
Class providing a hash for DUIDs.
Definition dhcp6-duid.h:50
Implements the unique identifier for DHCPv6.
Definition dhcp6-duid.h:27
An identifier for simulation events.
Definition event-id.h:45
An Inet6 address class.
Describes an IPv6 address.
Describes an IPv6 prefix.
Includes information about available subnets and corresponding leases.
std::unordered_multimap< Duid, std::pair< Ipv6Address, Time >, Duid::DuidHash > LeasedAddresses
Leased Addresses Client DUID + Ipv6Address / Lease time.
Ipv6Address GetMinAddress() const
Get the minimum address in the pool.
DeclinedAddresses m_declinedAddresses
Declined addresses.
uint32_t GetNumAddresses() const
Get the number of addresses leased.
Ipv6Address m_maxAddress
Maximum address in the pool.
Ipv6Prefix GetPrefix() const
Get the prefix of the address pool.
Ipv6Prefix m_prefix
Prefix of the address pool.
Ipv6Address GetMaxAddress() const
Get the maximum address in the pool.
Ipv6Address m_maxOfferedAddress
Maximum address offered so far.
ExpiredAddresses m_expiredAddresses
Expired addresses.
LeasedAddresses m_leasedAddresses
Leased addresses.
Ipv6Address m_addressPool
Address pool.
Ipv6Address GetAddressPool() const
Get the address pool.
std::multimap< Time, std::pair< Duid, Ipv6Address > > ExpiredAddresses
Expired Addresses (Section 6.2 of RFC 8415) Expired time / Ipv6Address.
std::unordered_map< Ipv6Address, Duid, Ipv6AddressHash > DeclinedAddresses
Declined Addresses Ipv6Address + Client DUID.
Ipv6Address m_minAddress
Minimum address in the pool.
uint32_t m_numAddresses
Number of addresses leased.
LeaseInfo(Ipv6Address addressPool, Ipv6Prefix prefix, Ipv6Address minAddress, Ipv6Address maxAddress)
Constructor.
holds a vector of ns3::NetDevice pointers
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:49
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.