A Discrete-Event Network Simulator
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
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  */
25 #ifndef DHCP_CLIENT_H
26 #define DHCP_CLIENT_H
28 #include "ns3/application.h"
29 #include "ns3/traced-value.h"
30 #include "dhcp-header.h"
31 #include <list>
33 namespace ns3 {
35 class Socket;
36 class Packet;
37 class RandomVariableStream;
45 class DhcpClient : public Application
46 {
47 public:
52  static TypeId
53  GetTypeId (void);
55  DhcpClient ();
56  virtual ~DhcpClient ();
62  DhcpClient (Ptr<NetDevice> netDevice);
74  void SetDhcpClientNetDevice (Ptr<NetDevice> netDevice);
90  int64_t AssignStreams (int64_t stream);
92 protected:
93  virtual void DoDispose (void);
95 private:
97  enum States
98  {
99  WAIT_OFFER = 1,
101  WAIT_ACK = 9
102  };
104  static const int DHCP_PEER_PORT = 67;
106  /*
107  * \brief Starts the DHCP client application
108  */
109  virtual void StartApplication (void);
111  /*
112  * \brief Stops the DHCP client application
113  */
114  virtual void StopApplication (void);
119  void LinkStateHandler (void);
125  void NetHandler (Ptr<Socket> socket);
130  void Boot (void);
136  void OfferHandler (DhcpHeader header);
141  void Select (void);
146  void Request (void);
154  void AcceptAck (DhcpHeader header, Address from);
159  void RemoveAndStart ();
161  uint8_t m_state;
162  bool m_firstBoot;
186  bool m_offered;
187  std::list<DhcpHeader> m_offerList;
188  uint32_t m_tran;
191 };
193 } // namespace ns3
195 #endif /* DHCP_CLIENT_H */
virtual void StartApplication(void)
Application specific startup code.
Definition: dhcp-client.cc:156
Ipv4Mask m_myMask
Mask of the address assigned.
Definition: dhcp-client.h:169
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
void OfferHandler(DhcpHeader header)
Stores DHCP offers in m_offerList.
Definition: dhcp-client.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Time m_renew
Store the renew time of address.
Definition: dhcp-client.h:180
uint8_t m_state
State of the DHCP client.
Definition: dhcp-client.h:161
Ptr< NetDevice > GetDhcpClientNetDevice(void)
Get the the NetDevice DHCP should work on.
Definition: dhcp-client.cc:112
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:269
EventId m_refreshEvent
Message refresh event.
Definition: dhcp-client.h:174
Forward calls to a chain of Callback.
client states
Definition: dhcp-client.h:97
bool m_firstBoot
First boot (used to add the link state change callback)
Definition: dhcp-client.h:162
void Request(void)
Sends the DHCP REQUEST message and changes the client state to WAIT_ACK.
Definition: dhcp-client.cc:390
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-client.cc:42
Ipv4Address m_myAddress
Address assigned to the client.
Definition: dhcp-client.h:167
a polymophic address class
Definition: address.h:90
void AcceptAck(DhcpHeader header, Address from)
Receives the DHCP ACK and configures IP address of the client.
Definition: dhcp-client.cc:435
Ipv4Address m_server
Address of the DHCP server.
Definition: dhcp-client.h:170
virtual ~DhcpClient()
Definition: dhcp-client.cc:107
Ipv4Address GetDhcpServer(void)
Get the IPv4Address of current DHCP server.
Definition: dhcp-client.cc:123
uint32_t m_tran
Stores the current transaction number to be used.
Definition: dhcp-client.h:188
Ptr< RandomVariableStream > m_ran
Uniform random variable for transaction ID.
Definition: dhcp-client.h:183
bool m_offered
Specify if the client has got any offer.
Definition: dhcp-client.h:186
The base class for all ns3 applications.
Definition: application.h:60
void LinkStateHandler(void)
Handles changes in LinkState.
Definition: dhcp-client.cc:239
EventId m_rebindEvent
Message rebind event.
Definition: dhcp-client.h:175
void RemoveAndStart()
Remove the current DHCP information and restart the process.
Definition: dhcp-client.cc:493
EventId m_collectEvent
Offer collection event.
Definition: dhcp-client.h:178
BOOTP header with DHCP messages supports the following options: Subnet Mask (1), Address Request (50)...
Definition: dhcp-header.h:81
Ipv4Address m_gateway
Address of the gateway.
Definition: dhcp-client.h:171
void Select(void)
Selects an OFFER from m_offerList.
Definition: dhcp-client.cc:366
Time m_collect
Time for which client should collect offers.
Definition: dhcp-client.h:185
EventId m_timeout
The timeout period.
Definition: dhcp-client.h:177
EventId m_requestEvent
Address refresh event.
Definition: dhcp-client.h:172
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const int DHCP_PEER_PORT
DHCP server port.
Definition: dhcp-client.h:104
void SetDhcpClientNetDevice(Ptr< NetDevice > netDevice)
Set the NetDevice DHCP should work on.
Definition: dhcp-client.cc:118
virtual void StopApplication(void)
Application specific shutdown code.
Definition: dhcp-client.cc:210
TracedCallback< const Ipv4Address & > m_newLease
Trace of new lease.
Definition: dhcp-client.h:189
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-client.cc:294
Ptr< NetDevice > m_device
NetDevice pointer.
Definition: dhcp-client.h:163
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-client.cc:129
Time m_nextoffer
Time to try the next offer (if request gets no reply)
Definition: dhcp-client.h:182
Ptr< Socket > m_socket
Socket for remote communication.
Definition: dhcp-client.h:164
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Ipv4Address m_offeredAddress
Address offered to the client.
Definition: dhcp-client.h:166
An identifier for simulation events.
Definition: event-id.h:53
std::list< DhcpHeader > m_offerList
Stores all the offers given to the client.
Definition: dhcp-client.h:187
Address m_chaddr
chaddr of the interface (stored as an Address for convenience).
Definition: dhcp-client.h:168
State of a client that needs to refresh the lease.
Definition: dhcp-client.h:100
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: dhcp-client.cc:148
EventId m_nextOfferEvent
Message next offer event.
Definition: dhcp-client.h:176
Implements the functionality of a DHCP client.
Definition: dhcp-client.h:45
State of a client that waits for the offer.
Definition: dhcp-client.h:99
EventId m_discoverEvent
Message retransmission event.
Definition: dhcp-client.h:173
State of a client that waits for acknowledgment.
Definition: dhcp-client.h:101
Time m_rtrs
Defining the time for retransmission.
Definition: dhcp-client.h:184
void Boot(void)
Sends DHCP DISCOVER and changes the client state to WAIT_OFFER.
Definition: dhcp-client.cc:325
Time m_lease
Store the lease time of address.
Definition: dhcp-client.h:179
a unique identifier for an interface.
Definition: type-id.h:58
TracedCallback< const Ipv4Address & > m_expiry
Trace of lease expire.
Definition: dhcp-client.h:190
Ipv4Address m_remoteAddress
Initially set to to start DHCP.
Definition: dhcp-client.h:165
Time m_rebind
Store the rebind time of address.
Definition: dhcp-client.h:181