A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dhcp-header.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_HEADER_H
14#define DHCP_HEADER_H
15
16#include "ns3/address.h"
17#include "ns3/buffer.h"
18#include "ns3/header.h"
19#include "ns3/ipv4-address.h"
20
21namespace ns3
22{
23
24/**
25 * \ingroup internet-apps
26 * \defgroup dhcp DHCPv4 Client and Server
27 */
28
29/**
30 * \ingroup dhcp
31 *
32 * \class DhcpHeader
33 * \brief BOOTP header with DHCP messages. This supports the following options:
34 * Subnet Mask (1), Address Request (50), Refresh Lease Time (51),
35 * DHCP Message Type (53), DHCP Server ID (54), Renew Time (58),
36 * Rebind Time (59) and End (255) of BOOTP
37 *
38 * \verbatim
39 0 1 2 3
40 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 | op (1) | htype (1) | hlen (1) | hops (1) |
43 +---------------+---------------+---------------+---------------+
44 | xid (4) |
45 +-------------------------------+-------------------------------+
46 | secs (2) | flags (2) |
47 +-------------------------------+-------------------------------+
48 | ciaddr (4) |
49 +---------------------------------------------------------------+
50 | yiaddr (4) |
51 +---------------------------------------------------------------+
52 | siaddr (4) |
53 +---------------------------------------------------------------+
54 | giaddr (4) |
55 +---------------------------------------------------------------+
56 | |
57 | chaddr (16) |
58 | |
59 | |
60 +---------------------------------------------------------------+
61 | |
62 | sname (64) |
63 +---------------------------------------------------------------+
64 | |
65 | file (128) |
66 +---------------------------------------------------------------+
67 | |
68 | options (variable) |
69 +---------------------------------------------------------------+
70 \endverbatim
71 */
72class DhcpHeader : public Header
73{
74 public:
75 /**
76 * \brief Get the type ID.
77 * \return the object TypeId
78 */
79 static TypeId GetTypeId();
80
81 /**
82 * \brief Constructor
83 */
84 DhcpHeader();
85
86 /**
87 * \brief Destructor
88 */
89 ~DhcpHeader() override;
90
91 /// BOOTP options
93 {
94 OP_MASK = 1, //!< BOOTP Option 1: Address Mask
95 OP_ROUTE = 3, //!< BOOTP Option 3: Router Option
96 OP_ADDREQ = 50, //!< BOOTP Option 50: Requested Address
97 OP_LEASE = 51, //!< BOOTP Option 51: Address Lease Time
98 OP_MSGTYPE = 53, //!< BOOTP Option 53: DHCP Message Type
99 OP_SERVID = 54, //!< BOOTP Option 54: Server Identifier
100 OP_RENEW = 58, //!< BOOTP Option 58: Address Renewal Time
101 OP_REBIND = 59, //!< BOOTP Option 59: Address Rebind Time
102 OP_END = 255 //!< BOOTP Option 255: END
103 };
104
105 /// DHCP messages
107 {
108 DHCPDISCOVER = 0, //!< Code for DHCP Discover
109 DHCPOFFER = 1, //!< Code for DHCP Offer
110 DHCPREQ = 2, //!< Code for DHCP Request
111 DHCPACK = 4, //!< Code for DHCP ACK
112 DHCPNACK = 5 //!< Code for DHCP NACK
113 };
114
115 /**
116 * \brief Set the type of BOOTP and DHCP messages
117 * \param type The type of message
118 */
119 void SetType(uint8_t type);
120
121 /**
122 * \brief Return the type of DHCP message
123 * \return The type of message
124 */
125 uint8_t GetType() const;
126
127 /**
128 * \brief Set the hardware information
129 * \param htype Hardware type
130 * \param hlen Hardware length
131 */
132 void SetHWType(uint8_t htype, uint8_t hlen);
133
134 /**
135 * \brief Set the transaction ID
136 * \param tran The transaction number
137 */
138 void SetTran(uint32_t tran);
139
140 /**
141 * \brief Get the transaction id
142 * \return The transaction id
143 */
144 uint32_t GetTran() const;
145
146 /**
147 * \brief Set the time when message is sent
148 */
149 void SetTime();
150
151 /**
152 * \brief Set the Address of the device.
153 *
154 * Only the relevant bits are considered (i.e., not the type and length)
155 *
156 * \param addr Address of the device
157 */
158 void SetChaddr(Address addr);
159
160 /**
161 * \brief Set the Address of the device
162 * \param addr Address of the device
163 * \param len Address length
164 */
165 void SetChaddr(uint8_t* addr, uint8_t len);
166
167 /**
168 * \brief Get the Address of the client.
169 *
170 * Note: the address is always 16-bytes long.
171 *
172 * \return Address of the client
173 */
175
176 /**
177 * \brief Set the IPv4Address of the client
178 * \param addr The client Ipv4Address
179 */
180 void SetYiaddr(Ipv4Address addr);
181
182 /**
183 * \brief Get the IPv4Address of the client
184 * \return IPv4Address of the client
185 */
186 Ipv4Address GetYiaddr() const;
187
188 /**
189 * \brief Set the DHCP server information
190 * \param addr IPv4Address of the server
191 */
192 void SetDhcps(Ipv4Address addr);
193
194 /**
195 * \brief Get the information about the DHCP server
196 * \return IPv4Address of DHCP server
197 */
198 Ipv4Address GetDhcps() const;
199
200 /**
201 * \brief Set the Ipv4Address requested by the client
202 * \param addr Ipv4Address requested by the client
203 */
204 void SetReq(Ipv4Address addr);
205
206 /**
207 * \brief Get the IPv4Address requested by the client
208 * \return IPv4Address requested by the client
209 */
210 Ipv4Address GetReq() const;
211
212 /**
213 * \brief Set the mask of the IPv4Address
214 * \param addr 32 bit mask
215 */
216 void SetMask(uint32_t addr);
217
218 /**
219 * \brief Return the mask of the network
220 * \return 32 bit mask
221 */
222 uint32_t GetMask() const;
223
224 /**
225 * \brief Set the Ipv4Address of gateway to be used
226 * \param addr The Ipv4Address of the gateway
227 */
228 void SetRouter(Ipv4Address addr);
229
230 /**
231 * \brief Return the Ipv4Address of gateway to be used
232 * \return The Ipv4Address of the gateway
233 */
234 Ipv4Address GetRouter() const;
235
236 /**
237 * \brief Set the lease time of the IPv4Address
238 * \param time 32 bit time
239 */
240 void SetLease(uint32_t time);
241
242 /**
243 * \brief Return the lease time of the IPv4Address
244 * \return 32 bit time
245 */
246 uint32_t GetLease() const;
247
248 /**
249 * \brief Set the Renewal time of the IPv4Address
250 * \param time 32 bit time
251 */
252 void SetRenew(uint32_t time);
253
254 /**
255 * \brief Return the Renewal time of the address
256 * \return 32 bit time
257 */
258 uint32_t GetRenew() const;
259
260 /**
261 * \brief Set the Rebind time of the IPv4Address
262 * \param time 32 bit time
263 */
264 void SetRebind(uint32_t time);
265
266 /**
267 * \brief Return the Rebind time of the address
268 * \return 32 bit time
269 */
270 uint32_t GetRebind() const;
271
272 /**
273 * \brief Reset the BOOTP options
274 */
275 void ResetOpt();
276
277 private:
278 TypeId GetInstanceTypeId() const override;
279 void Print(std::ostream& os) const override;
280 uint32_t GetSerializedSize() const override;
281 void Serialize(Buffer::Iterator start) const override;
282 uint32_t Deserialize(Buffer::Iterator start) override;
283
284 uint8_t m_op; //!< The DHCP Message type
285 uint8_t m_bootp; //!< The BOOTP Message type
286 uint8_t m_hType; //!< The hardware type
287 uint8_t m_hLen; //!< The hardware length
288 uint8_t m_hops; //!< The number of hops covered by the message
289 uint32_t m_xid; //!< The transaction number
290 uint32_t m_mask; //!< The mask of the network
291 uint32_t m_len; //!< The length of the header
292 uint16_t m_secs; //!< Seconds elapsed
293 uint16_t m_flags; //!< BOOTP flags
294 uint8_t m_chaddr[16]; //!< The address identifier
295 Ipv4Address m_yiAddr; //!< Your (client) IP address
296 Ipv4Address m_ciAddr; //!< The IP address of the client
297 Ipv4Address m_siAddr; //!< Next Server IP address
298 Ipv4Address m_giAddr; //!< Relay Agent IP address
299 Ipv4Address m_dhcps; //!< DHCP server IP address
300 Ipv4Address m_req; //!< Requested Address
301 Ipv4Address m_route; //!< Router Option Address
302 uint8_t m_sname[64]; //!< Server name (Padded for now)
303 uint8_t m_file[128]; //!< File name (Padded for now)
304 uint8_t m_magic_cookie[4]; //!< DHCP Magic Cookie
305 uint32_t m_lease; //!< The lease time of the address
306 uint32_t m_renew; //!< The renewal time for the client
307 uint32_t m_rebind; //!< The rebinding time for the client
308 bool m_opt[255]; //!< BOOTP option list
309};
310
311} // namespace ns3
312
313#endif /* DHCP_HEADER_H */
a polymophic address class
Definition address.h:90
iterator in a Buffer instance
Definition buffer.h:89
BOOTP header with DHCP messages.
Definition dhcp-header.h:73
uint32_t GetLease() const
Return the lease time of the IPv4Address.
void SetTime()
Set the time when message is sent.
Ipv4Address m_ciAddr
The IP address of the client.
Ipv4Address GetReq() const
Get the IPv4Address requested by the client.
uint32_t m_rebind
The rebinding time for the client.
uint8_t m_chaddr[16]
The address identifier.
void Serialize(Buffer::Iterator start) const override
Ipv4Address m_giAddr
Relay Agent IP address.
void ResetOpt()
Reset the BOOTP options.
uint8_t m_hops
The number of hops covered by the message.
Ipv4Address GetRouter() const
Return the Ipv4Address of gateway to be used.
uint8_t m_bootp
The BOOTP Message type.
uint32_t m_lease
The lease time of the address.
void SetType(uint8_t type)
Set the type of BOOTP and DHCP messages.
Messages
DHCP messages.
@ DHCPACK
Code for DHCP ACK.
@ DHCPOFFER
Code for DHCP Offer.
@ DHCPDISCOVER
Code for DHCP Discover.
@ DHCPREQ
Code for DHCP Request.
@ DHCPNACK
Code for DHCP NACK.
void SetTran(uint32_t tran)
Set the transaction ID.
Address GetChaddr()
Get the Address of the client.
uint8_t m_sname[64]
Server name (Padded for now)
Ipv4Address GetDhcps() const
Get the information about the DHCP server.
Ipv4Address m_yiAddr
Your (client) IP address.
~DhcpHeader() override
Destructor.
void SetYiaddr(Ipv4Address addr)
Set the IPv4Address of the client.
uint32_t m_len
The length of the header.
void SetDhcps(Ipv4Address addr)
Set the DHCP server information.
uint16_t m_secs
Seconds elapsed.
uint32_t GetMask() const
Return the mask of the network.
uint32_t m_mask
The mask of the network.
Ipv4Address m_dhcps
DHCP server IP address.
Ipv4Address m_siAddr
Next Server IP address.
uint8_t GetType() const
Return the type of DHCP message.
void SetRenew(uint32_t time)
Set the Renewal time of the IPv4Address.
uint32_t GetTran() const
Get the transaction id.
bool m_opt[255]
BOOTP option list.
uint8_t m_magic_cookie[4]
DHCP Magic Cookie.
void SetLease(uint32_t time)
Set the lease time of the IPv4Address.
static TypeId GetTypeId()
Get the type ID.
Options
BOOTP options.
Definition dhcp-header.h:93
@ OP_SERVID
BOOTP Option 54: Server Identifier.
Definition dhcp-header.h:99
@ OP_MASK
BOOTP Option 1: Address Mask.
Definition dhcp-header.h:94
@ OP_REBIND
BOOTP Option 59: Address Rebind Time.
@ OP_MSGTYPE
BOOTP Option 53: DHCP Message Type.
Definition dhcp-header.h:98
@ OP_RENEW
BOOTP Option 58: Address Renewal Time.
@ OP_ADDREQ
BOOTP Option 50: Requested Address.
Definition dhcp-header.h:96
@ OP_ROUTE
BOOTP Option 3: Router Option.
Definition dhcp-header.h:95
@ OP_END
BOOTP Option 255: END.
@ OP_LEASE
BOOTP Option 51: Address Lease Time.
Definition dhcp-header.h:97
uint8_t m_hLen
The hardware length.
DhcpHeader()
Constructor.
void SetRouter(Ipv4Address addr)
Set the Ipv4Address of gateway to be used.
void SetMask(uint32_t addr)
Set the mask of the IPv4Address.
uint32_t m_renew
The renewal time for the client.
uint8_t m_hType
The hardware type.
void SetReq(Ipv4Address addr)
Set the Ipv4Address requested by the client.
uint16_t m_flags
BOOTP flags.
uint32_t Deserialize(Buffer::Iterator start) override
Ipv4Address GetYiaddr() const
Get the IPv4Address of the client.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetRebind(uint32_t time)
Set the Rebind time of the IPv4Address.
void Print(std::ostream &os) const override
Ipv4Address m_route
Router Option Address.
uint8_t m_op
The DHCP Message type.
uint32_t m_xid
The transaction number.
uint32_t GetRebind() const
Return the Rebind time of the address.
Ipv4Address m_req
Requested Address.
void SetChaddr(Address addr)
Set the Address of the device.
uint32_t GetRenew() const
Return the Renewal time of the address.
uint8_t m_file[128]
File name (Padded for now)
uint32_t GetSerializedSize() const override
void SetHWType(uint8_t htype, uint8_t hlen)
Set the hardware information.
Protocol header serialization and deserialization.
Definition header.h:33
Ipv4 addresses are stored in host order in this class.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.