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