A Discrete-Event Network Simulator
API
dhcp-header.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 UPB
4  * Copyright (c) 2017 NITK Surathkal
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Radu Lupu <rlupu@elcom.pub.ro>
20  * Ankit Deepak <adadeepak8@gmail.com>
21  * Deepti Rajagopal <deeptir96@gmail.com>
22  *
23  */
24 
25 #ifndef DHCP_HEADER_H
26 #define DHCP_HEADER_H
27 
28 #include "ns3/header.h"
29 #include <ns3/mac48-address.h>
30 #include <ns3/mac64-address.h>
31 
32 namespace ns3 {
33 
83 class DhcpHeader : public Header
84 {
85 public:
90  static TypeId GetTypeId (void);
91 
95  DhcpHeader ();
96 
100  ~DhcpHeader ();
101 
103  enum Options
104  {
105  OP_MASK = 1,
106  OP_ROUTE = 3,
107  OP_ADDREQ = 50,
108  OP_LEASE = 51,
109  OP_MSGTYPE = 53,
110  OP_SERVID = 54,
111  OP_RENEW = 58,
112  OP_REBIND = 59,
113  OP_END = 255
114  };
115 
117  enum Messages
118  {
120  DHCPOFFER = 1,
121  DHCPREQ = 2,
122  DHCPACK = 4,
123  DHCPNACK = 5
124  };
125 
130  void SetType (uint8_t type);
131 
136  uint8_t GetType (void) const;
137 
143  void SetHWType (uint8_t htype, uint8_t hlen);
144 
149  void SetTran (uint32_t tran);
150 
155  uint32_t GetTran (void) const;
156 
160  void SetTime ();
161 
169  void SetChaddr (Address addr);
170 
176  void SetChaddr (uint8_t* addr, uint8_t len);
177 
185  Address GetChaddr (void);
186 
191  void SetYiaddr (Ipv4Address addr);
192 
197  Ipv4Address GetYiaddr (void) const;
198 
203  void SetDhcps (Ipv4Address addr);
204 
209  Ipv4Address GetDhcps (void) const;
210 
215  void SetReq (Ipv4Address addr);
216 
221  Ipv4Address GetReq (void) const;
222 
227  void SetMask (uint32_t addr);
228 
233  uint32_t GetMask (void) const;
234 
239  void SetRouter (Ipv4Address addr);
240 
245  Ipv4Address GetRouter (void) const;
246 
251  void SetLease (uint32_t time);
252 
257  uint32_t GetLease (void) const;
258 
263  void SetRenew (uint32_t time);
264 
269  uint32_t GetRenew (void) const;
270 
275  void SetRebind (uint32_t time);
276 
281  uint32_t GetRebind (void) const;
282 
286  void ResetOpt ();
287 
288 private:
289  virtual TypeId GetInstanceTypeId (void) const;
290  virtual void Print (std::ostream &os) const;
291  virtual uint32_t GetSerializedSize (void) const;
292  virtual void Serialize (Buffer::Iterator start) const;
293  virtual uint32_t Deserialize (Buffer::Iterator start);
294 
295  uint8_t m_op;
296  uint8_t m_bootp;
297  uint8_t m_hType;
298  uint8_t m_hLen;
299  uint8_t m_hops;
300  uint32_t m_xid;
301  uint32_t m_mask;
302  uint32_t m_len;
303  uint16_t m_secs;
304  uint16_t m_flags;
305  uint8_t m_chaddr[16];
313  uint8_t m_sname[64];
314  uint8_t m_file[128];
315  uint8_t m_magic_cookie[4];
316  uint32_t m_lease;
317  uint32_t m_renew;
318  uint32_t m_rebind;
319  bool m_opt[255];
320 };
321 
322 } // namespace ns3
323 
324 #endif /* DHCP_HEADER_H */
Protocol header serialization and deserialization.
Definition: header.h:42
BOOTP Option 255: END.
Definition: dhcp-header.h:113
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: dhcp-header.cc:273
Ipv4Address m_ciAddr
The IP address of the client.
Definition: dhcp-header.h:307
void SetTime()
Set the time when message is sent.
Definition: dhcp-header.cc:107
BOOTP Option 58: Address Renewal Time.
Definition: dhcp-header.h:111
Ipv4Address m_giAddr
Relay Agent IP address.
Definition: dhcp-header.h:309
virtual uint32_t GetSerializedSize(void) const
Definition: dhcp-header.cc:258
Ipv4Address GetRouter(void) const
Return the Ipv4Address of gateway to be used.
Definition: dhcp-header.cc:198
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-header.cc:263
uint32_t m_renew
The renewal time for the client.
Definition: dhcp-header.h:317
def start()
Definition: core.py:1806
Code for DHCP NACK.
Definition: dhcp-header.h:123
uint32_t m_rebind
The rebinding time for the client.
Definition: dhcp-header.h:318
void SetYiaddr(Ipv4Address addr)
Set the IPv4Address of the client.
Definition: dhcp-header.cc:133
Ipv4Address m_yiAddr
Your (client) IP address.
Definition: dhcp-header.h:306
Messages
DHCP messages.
Definition: dhcp-header.h:117
virtual void Serialize(Buffer::Iterator start) const
Definition: dhcp-header.cc:284
BOOTP Option 51: Address Lease Time.
Definition: dhcp-header.h:108
uint32_t GetTran(void) const
Get the transaction id.
Definition: dhcp-header.cc:102
Ipv4Address m_route
Router Option Address.
Definition: dhcp-header.h:312
uint32_t m_lease
The lease time of the address.
Definition: dhcp-header.h:316
uint8_t GetType(void) const
Return the type of DHCP message.
Definition: dhcp-header.cc:86
uint32_t GetLease(void) const
Return the lease time of the IPv4Address.
Definition: dhcp-header.cc:213
Address GetChaddr(void)
Get the Address of the client.
Definition: dhcp-header.cc:126
void SetType(uint8_t type)
Set the type of BOOTP and DHCP messages.
Definition: dhcp-header.cc:75
Ipv4Address m_dhcps
DHCP server IP address.
Definition: dhcp-header.h:310
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:90
uint8_t m_hType
The hardware type.
Definition: dhcp-header.h:297
uint32_t GetMask(void) const
Return the mask of the network.
Definition: dhcp-header.cc:183
void SetHWType(uint8_t htype, uint8_t hlen)
Set the hardware information.
Definition: dhcp-header.cc:91
virtual void Print(std::ostream &os) const
Definition: dhcp-header.cc:278
Ipv4Address m_req
Requested Address.
Definition: dhcp-header.h:311
void SetTran(uint32_t tran)
Set the transaction ID.
Definition: dhcp-header.cc:97
uint8_t m_hLen
The hardware length.
Definition: dhcp-header.h:298
uint32_t GetRenew(void) const
Return the Renewal time of the address.
Definition: dhcp-header.cc:228
BOOTP Option 53: DHCP Message Type.
Definition: dhcp-header.h:109
Ipv4Address m_siAddr
Next Server IP address.
Definition: dhcp-header.h:308
BOOTP Option 50: Requested Address.
Definition: dhcp-header.h:107
Introspection did not find any typical Config paths.
Definition: dhcp-header.h:83
uint32_t m_len
The length of the header.
Definition: dhcp-header.h:302
void SetReq(Ipv4Address addr)
Set the Ipv4Address requested by the client.
Definition: dhcp-header.cc:158
uint8_t m_op
The DHCP Message type.
Definition: dhcp-header.h:295
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetChaddr(Address addr)
Set the Address of the device.
Definition: dhcp-header.cc:112
BOOTP Option 59: Address Rebind Time.
Definition: dhcp-header.h:112
Ipv4Address GetDhcps(void) const
Get the information about the DHCP server.
Definition: dhcp-header.cc:153
uint8_t m_file[128]
File name (Padded for now)
Definition: dhcp-header.h:314
bool m_opt[255]
BOOTP option list.
Definition: dhcp-header.h:319
DhcpHeader()
Constructor.
Definition: dhcp-header.cc:37
BOOTP Option 1: Address Mask.
Definition: dhcp-header.h:105
Code for DHCP Offer.
Definition: dhcp-header.h:120
void ResetOpt()
Reset the BOOTP options.
Definition: dhcp-header.cc:248
uint32_t GetRebind(void) const
Return the Rebind time of the address.
Definition: dhcp-header.cc:243
uint8_t m_magic_cookie[4]
DHCP Magic Cookie.
Definition: dhcp-header.h:315
void SetDhcps(Ipv4Address addr)
Set the DHCP server information.
Definition: dhcp-header.cc:143
Code for DHCP ACK.
Definition: dhcp-header.h:122
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
uint32_t m_xid
The transaction number.
Definition: dhcp-header.h:300
uint8_t m_hops
The number of hops covered by the message.
Definition: dhcp-header.h:299
Options
BOOTP options.
Definition: dhcp-header.h:103
uint16_t m_secs
Seconds elapsed.
Definition: dhcp-header.h:303
~DhcpHeader()
Destructor.
Definition: dhcp-header.cc:71
void SetLease(uint32_t time)
Set the lease time of the IPv4Address.
Definition: dhcp-header.cc:203
uint8_t m_sname[64]
Server name (Padded for now)
Definition: dhcp-header.h:313
uint32_t m_mask
The mask of the network.
Definition: dhcp-header.h:301
void SetRenew(uint32_t time)
Set the Renewal time of the IPv4Address.
Definition: dhcp-header.cc:218
Code for DHCP Request.
Definition: dhcp-header.h:121
Ipv4Address GetYiaddr(void) const
Get the IPv4Address of the client.
Definition: dhcp-header.cc:138
void SetMask(uint32_t addr)
Set the mask of the IPv4Address.
Definition: dhcp-header.cc:173
Ipv4Address GetReq(void) const
Get the IPv4Address requested by the client.
Definition: dhcp-header.cc:168
BOOTP Option 54: Server Identifier.
Definition: dhcp-header.h:110
a unique identifier for an interface.
Definition: type-id.h:58
BOOTP Option 3: Router Option.
Definition: dhcp-header.h:106
uint16_t m_flags
BOOTP flags.
Definition: dhcp-header.h:304
Code for DHCP Discover.
Definition: dhcp-header.h:119
uint8_t m_chaddr[16]
The address identifier.
Definition: dhcp-header.h:305
void SetRouter(Ipv4Address addr)
Set the Ipv4Address of gateway to be used.
Definition: dhcp-header.cc:188
uint8_t m_bootp
The BOOTP Message type.
Definition: dhcp-header.h:296
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: dhcp-header.cc:353
void SetRebind(uint32_t time)
Set the Rebind time of the IPv4Address.
Definition: dhcp-header.cc:233