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/event-id.h"
30 #include "ns3/ptr.h"
31 #include "ns3/ipv4-address.h"
32 #include "ns3/random-variable-stream.h"
33 #include "ns3/traced-value.h"
34 #include "dhcp-header.h"
35 #include <list>
37 namespace ns3 {
39 class Socket;
40 class Packet;
48 class DhcpClient : public Application
49 {
50 public:
55  static TypeId
56  GetTypeId (void);
58  DhcpClient ();
59  virtual ~DhcpClient ();
65  DhcpClient (Ptr<NetDevice> netDevice);
77  void SetDhcpClientNetDevice (Ptr<NetDevice> netDevice);
93  int64_t AssignStreams (int64_t stream);
95 protected:
96  virtual void DoDispose (void);
98 private:
100  enum States
101  {
104  WAIT_ACK = 9
105  };
107  static const int DHCP_PEER_PORT = 67;
109  /*
110  * \brief Starts the DHCP client application
111  */
112  virtual void StartApplication (void);
114  /*
115  * \brief Stops the DHCP client application
116  */
117  virtual void StopApplication (void);
122  void LinkStateHandler (void);
128  void NetHandler (Ptr<Socket> socket);
133  void Boot (void);
139  void OfferHandler (DhcpHeader header);
144  void Select (void);
149  void Request (void);
157  void AcceptAck (DhcpHeader header, Address from);
162  void RemoveAndStart ();
164  uint8_t m_state;
187  bool m_offered;
188  std::list<DhcpHeader> m_offerList;
189  uint32_t m_tran;
192 };
194 } // namespace ns3
196 #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:171
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void OfferHandler(DhcpHeader header)
Stores DHCP offers in m_offerList.
Definition: dhcp-client.cc:335
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:181
uint8_t m_state
State of the DHCP client.
Definition: dhcp-client.h:164
Ptr< NetDevice > GetDhcpClientNetDevice(void)
Get the the NetDevice DHCP should work on.
Definition: dhcp-client.cc:121
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
EventId m_refreshEvent
Message refresh event.
Definition: dhcp-client.h:176
Forward calls to a chain of Callback.
client states
Definition: dhcp-client.h:100
void Request(void)
Sends the DHCP REQUEST message and changes the client state to WAIT_ACK.
Definition: dhcp-client.cc:372
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-client.cc:55
Ipv4Address m_myAddress
Address assigned to the client.
Definition: dhcp-client.h:169
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:417
Ipv4Address m_server
Address of the DHCP server.
Definition: dhcp-client.h:172
virtual ~DhcpClient()
Definition: dhcp-client.cc:116
Ipv4Address GetDhcpServer(void)
Get the IPv4Address of current DHCP server.
Definition: dhcp-client.cc:132
uint32_t m_tran
Stores the current transaction number to be used.
Definition: dhcp-client.h:189
Ptr< RandomVariableStream > m_ran
Uniform random variable for transaction ID.
Definition: dhcp-client.h:184
bool m_offered
Specify if the client has got any offer.
Definition: dhcp-client.h:187
The base class for all ns3 applications.
Definition: application.h:60
void LinkStateHandler(void)
Handles changes in LinkState.
Definition: dhcp-client.cc:232
EventId m_rebindEvent
Message rebind event.
Definition: dhcp-client.h:177
void RemoveAndStart()
Remove the current DHCP information and restart the process.
Definition: dhcp-client.cc:471
Introspection did not find any typical Config paths.
Definition: dhcp-header.h:83
Ipv4Address m_gateway
Address of the gateway.
Definition: dhcp-client.h:173
void Select(void)
Selects an OFFER from m_offerList.
Definition: dhcp-client.cc:348
Time m_collect
Time for which client should collect offers.
Definition: dhcp-client.h:186
EventId m_timeout
The timeout period.
Definition: dhcp-client.h:179
EventId m_requestEvent
Address refresh event.
Definition: dhcp-client.h:174
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:107
void SetDhcpClientNetDevice(Ptr< NetDevice > netDevice)
Set the NetDevice DHCP should work on.
Definition: dhcp-client.cc:127
virtual void StopApplication(void)
Application specific shutdown code.
Definition: dhcp-client.cc:206
TracedCallback< const Ipv4Address & > m_newLease
Trace of new lease.
Definition: dhcp-client.h:190
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-client.cc:276
Ptr< NetDevice > m_device
NetDevice pointer.
Definition: dhcp-client.h:165
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-client.cc:138
Time m_nextoffer
Time to try the next offer (if request gets no reply)
Definition: dhcp-client.h:183
Ptr< Socket > m_socket
Socket for remote communication.
Definition: dhcp-client.h:166
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ipv4Address m_offeredAddress
Address offered to the client.
Definition: dhcp-client.h:168
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:188
Address m_chaddr
chaddr of the interface (stored as an Address for convenience).
Definition: dhcp-client.h:170
State of a client that needs to refresh the lease.
Definition: dhcp-client.h:103
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:178
Implements the functionality of a DHCP client.
Definition: dhcp-client.h:48
State of a client that waits for the offer.
Definition: dhcp-client.h:102
EventId m_discoverEvent
Message retransmission event.
Definition: dhcp-client.h:175
State of a client that waits for acknowledgment.
Definition: dhcp-client.h:104
Time m_rtrs
Defining the time for retransmission.
Definition: dhcp-client.h:185
void Boot(void)
Sends DHCP DISCOVER and changes the client state to WAIT_OFFER.
Definition: dhcp-client.cc:307
Time m_lease
Store the lease time of address.
Definition: dhcp-client.h:180
a unique identifier for an interface.
Definition: type-id.h:58
TracedCallback< const Ipv4Address & > m_expiry
Trace of lease expire.
Definition: dhcp-client.h:191
Ipv4Address m_remoteAddress
Initially set to to start DHCP.
Definition: dhcp-client.h:167
Time m_rebind
Store the rebind time of address.
Definition: dhcp-client.h:182