A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
21
namespace
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
*/
72
class
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
92
enum
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
106
enum
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
*/
174
Address
GetChaddr
();
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 */
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::DhcpHeader
BOOTP header with DHCP messages.
Definition
dhcp-header.h:73
ns3::DhcpHeader::GetLease
uint32_t GetLease() const
Return the lease time of the IPv4Address.
Definition
dhcp-header.cc:223
ns3::DhcpHeader::SetTime
void SetTime()
Set the time when message is sent.
Definition
dhcp-header.cc:102
ns3::DhcpHeader::m_ciAddr
Ipv4Address m_ciAddr
The IP address of the client.
Definition
dhcp-header.h:296
ns3::DhcpHeader::GetReq
Ipv4Address GetReq() const
Get the IPv4Address requested by the client.
Definition
dhcp-header.cc:172
ns3::DhcpHeader::m_rebind
uint32_t m_rebind
The rebinding time for the client.
Definition
dhcp-header.h:307
ns3::DhcpHeader::m_chaddr
uint8_t m_chaddr[16]
The address identifier.
Definition
dhcp-header.h:294
ns3::DhcpHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
dhcp-header.cc:302
ns3::DhcpHeader::m_giAddr
Ipv4Address m_giAddr
Relay Agent IP address.
Definition
dhcp-header.h:298
ns3::DhcpHeader::ResetOpt
void ResetOpt()
Reset the BOOTP options.
Definition
dhcp-header.cc:263
ns3::DhcpHeader::m_hops
uint8_t m_hops
The number of hops covered by the message.
Definition
dhcp-header.h:288
ns3::DhcpHeader::GetRouter
Ipv4Address GetRouter() const
Return the Ipv4Address of gateway to be used.
Definition
dhcp-header.cc:206
ns3::DhcpHeader::m_bootp
uint8_t m_bootp
The BOOTP Message type.
Definition
dhcp-header.h:285
ns3::DhcpHeader::m_lease
uint32_t m_lease
The lease time of the address.
Definition
dhcp-header.h:305
ns3::DhcpHeader::SetType
void SetType(uint8_t type)
Set the type of BOOTP and DHCP messages.
Definition
dhcp-header.cc:65
ns3::DhcpHeader::Messages
Messages
DHCP messages.
Definition
dhcp-header.h:107
ns3::DhcpHeader::DHCPACK
@ DHCPACK
Code for DHCP ACK.
Definition
dhcp-header.h:111
ns3::DhcpHeader::DHCPOFFER
@ DHCPOFFER
Code for DHCP Offer.
Definition
dhcp-header.h:109
ns3::DhcpHeader::DHCPDISCOVER
@ DHCPDISCOVER
Code for DHCP Discover.
Definition
dhcp-header.h:108
ns3::DhcpHeader::DHCPREQ
@ DHCPREQ
Code for DHCP Request.
Definition
dhcp-header.h:110
ns3::DhcpHeader::DHCPNACK
@ DHCPNACK
Code for DHCP NACK.
Definition
dhcp-header.h:112
ns3::DhcpHeader::SetTran
void SetTran(uint32_t tran)
Set the transaction ID.
Definition
dhcp-header.cc:90
ns3::DhcpHeader::GetChaddr
Address GetChaddr()
Get the Address of the client.
Definition
dhcp-header.cc:124
ns3::DhcpHeader::m_sname
uint8_t m_sname[64]
Server name (Padded for now)
Definition
dhcp-header.h:302
ns3::DhcpHeader::GetDhcps
Ipv4Address GetDhcps() const
Get the information about the DHCP server.
Definition
dhcp-header.cc:155
ns3::DhcpHeader::m_yiAddr
Ipv4Address m_yiAddr
Your (client) IP address.
Definition
dhcp-header.h:295
ns3::DhcpHeader::~DhcpHeader
~DhcpHeader() override
Destructor.
Definition
dhcp-header.cc:60
ns3::DhcpHeader::SetYiaddr
void SetYiaddr(Ipv4Address addr)
Set the IPv4Address of the client.
Definition
dhcp-header.cc:132
ns3::DhcpHeader::m_len
uint32_t m_len
The length of the header.
Definition
dhcp-header.h:291
ns3::DhcpHeader::SetDhcps
void SetDhcps(Ipv4Address addr)
Set the DHCP server information.
Definition
dhcp-header.cc:144
ns3::DhcpHeader::m_secs
uint16_t m_secs
Seconds elapsed.
Definition
dhcp-header.h:292
ns3::DhcpHeader::GetMask
uint32_t GetMask() const
Return the mask of the network.
Definition
dhcp-header.cc:189
ns3::DhcpHeader::m_mask
uint32_t m_mask
The mask of the network.
Definition
dhcp-header.h:290
ns3::DhcpHeader::m_dhcps
Ipv4Address m_dhcps
DHCP server IP address.
Definition
dhcp-header.h:299
ns3::DhcpHeader::m_siAddr
Ipv4Address m_siAddr
Next Server IP address.
Definition
dhcp-header.h:297
ns3::DhcpHeader::GetType
uint8_t GetType() const
Return the type of DHCP message.
Definition
dhcp-header.cc:77
ns3::DhcpHeader::SetRenew
void SetRenew(uint32_t time)
Set the Renewal time of the IPv4Address.
Definition
dhcp-header.cc:229
ns3::DhcpHeader::GetTran
uint32_t GetTran() const
Get the transaction id.
Definition
dhcp-header.cc:96
ns3::DhcpHeader::m_opt
bool m_opt[255]
BOOTP option list.
Definition
dhcp-header.h:308
ns3::DhcpHeader::m_magic_cookie
uint8_t m_magic_cookie[4]
DHCP Magic Cookie.
Definition
dhcp-header.h:304
ns3::DhcpHeader::SetLease
void SetLease(uint32_t time)
Set the lease time of the IPv4Address.
Definition
dhcp-header.cc:212
ns3::DhcpHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
dhcp-header.cc:280
ns3::DhcpHeader::Options
Options
BOOTP options.
Definition
dhcp-header.h:93
ns3::DhcpHeader::OP_SERVID
@ OP_SERVID
BOOTP Option 54: Server Identifier.
Definition
dhcp-header.h:99
ns3::DhcpHeader::OP_MASK
@ OP_MASK
BOOTP Option 1: Address Mask.
Definition
dhcp-header.h:94
ns3::DhcpHeader::OP_REBIND
@ OP_REBIND
BOOTP Option 59: Address Rebind Time.
Definition
dhcp-header.h:101
ns3::DhcpHeader::OP_MSGTYPE
@ OP_MSGTYPE
BOOTP Option 53: DHCP Message Type.
Definition
dhcp-header.h:98
ns3::DhcpHeader::OP_RENEW
@ OP_RENEW
BOOTP Option 58: Address Renewal Time.
Definition
dhcp-header.h:100
ns3::DhcpHeader::OP_ADDREQ
@ OP_ADDREQ
BOOTP Option 50: Requested Address.
Definition
dhcp-header.h:96
ns3::DhcpHeader::OP_ROUTE
@ OP_ROUTE
BOOTP Option 3: Router Option.
Definition
dhcp-header.h:95
ns3::DhcpHeader::OP_END
@ OP_END
BOOTP Option 255: END.
Definition
dhcp-header.h:102
ns3::DhcpHeader::OP_LEASE
@ OP_LEASE
BOOTP Option 51: Address Lease Time.
Definition
dhcp-header.h:97
ns3::DhcpHeader::m_hLen
uint8_t m_hLen
The hardware length.
Definition
dhcp-header.h:287
ns3::DhcpHeader::DhcpHeader
DhcpHeader()
Constructor.
Definition
dhcp-header.cc:26
ns3::DhcpHeader::SetRouter
void SetRouter(Ipv4Address addr)
Set the Ipv4Address of gateway to be used.
Definition
dhcp-header.cc:195
ns3::DhcpHeader::SetMask
void SetMask(uint32_t addr)
Set the mask of the IPv4Address.
Definition
dhcp-header.cc:178
ns3::DhcpHeader::m_renew
uint32_t m_renew
The renewal time for the client.
Definition
dhcp-header.h:306
ns3::DhcpHeader::m_hType
uint8_t m_hType
The hardware type.
Definition
dhcp-header.h:286
ns3::DhcpHeader::SetReq
void SetReq(Ipv4Address addr)
Set the Ipv4Address requested by the client.
Definition
dhcp-header.cc:161
ns3::DhcpHeader::m_flags
uint16_t m_flags
BOOTP flags.
Definition
dhcp-header.h:293
ns3::DhcpHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
dhcp-header.cc:372
ns3::DhcpHeader::GetYiaddr
Ipv4Address GetYiaddr() const
Get the IPv4Address of the client.
Definition
dhcp-header.cc:138
ns3::DhcpHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
dhcp-header.cc:290
ns3::DhcpHeader::SetRebind
void SetRebind(uint32_t time)
Set the Rebind time of the IPv4Address.
Definition
dhcp-header.cc:246
ns3::DhcpHeader::Print
void Print(std::ostream &os) const override
Definition
dhcp-header.cc:296
ns3::DhcpHeader::m_route
Ipv4Address m_route
Router Option Address.
Definition
dhcp-header.h:301
ns3::DhcpHeader::m_op
uint8_t m_op
The DHCP Message type.
Definition
dhcp-header.h:284
ns3::DhcpHeader::m_xid
uint32_t m_xid
The transaction number.
Definition
dhcp-header.h:289
ns3::DhcpHeader::GetRebind
uint32_t GetRebind() const
Return the Rebind time of the address.
Definition
dhcp-header.cc:257
ns3::DhcpHeader::m_req
Ipv4Address m_req
Requested Address.
Definition
dhcp-header.h:300
ns3::DhcpHeader::SetChaddr
void SetChaddr(Address addr)
Set the Address of the device.
Definition
dhcp-header.cc:108
ns3::DhcpHeader::GetRenew
uint32_t GetRenew() const
Return the Renewal time of the address.
Definition
dhcp-header.cc:240
ns3::DhcpHeader::m_file
uint8_t m_file[128]
File name (Padded for now)
Definition
dhcp-header.h:303
ns3::DhcpHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
dhcp-header.cc:274
ns3::DhcpHeader::SetHWType
void SetHWType(uint8_t htype, uint8_t hlen)
Set the hardware information.
Definition
dhcp-header.cc:83
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet-apps
model
dhcp-header.h
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0