A Discrete-Event Network Simulator
API
dhcp-client.cc
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 
26 #include "ns3/ipv4.h"
27 #include "ns3/log.h"
28 #include "ns3/ipv4-static-routing-helper.h"
29 #include "ns3/random-variable-stream.h"
30 #include "ns3/pointer.h"
31 #include "ns3/string.h"
32 #include "ns3/ipv4-routing-table-entry.h"
33 #include "dhcp-client.h"
34 #include "dhcp-header.h"
35 
36 namespace ns3 {
37 
38 NS_LOG_COMPONENT_DEFINE ("DhcpClient");
39 NS_OBJECT_ENSURE_REGISTERED (DhcpClient);
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::DhcpClient")
46  .AddConstructor<DhcpClient> ()
47  .SetGroupName ("Internet-Apps")
48  .AddAttribute ("RTRS", "Time for retransmission of Discover message",
49  TimeValue (Seconds (5)),
51  MakeTimeChecker ())
52  .AddAttribute ("Collect", "Time for which offer collection starts",
53  TimeValue (Seconds (5)),
55  MakeTimeChecker ())
56  .AddAttribute ("ReRequest", "Time after which request will be resent to next server",
57  TimeValue (Seconds (10)),
59  MakeTimeChecker ())
60  .AddAttribute ("Transactions",
61  "The possible value of transaction numbers ",
62  StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000000.0]"),
64  MakePointerChecker<RandomVariableStream> ())
65  .AddTraceSource ("NewLease",
66  "Get a NewLease",
68  "ns3::Ipv4Address::TracedCallback")
69  .AddTraceSource ("ExpireLease",
70  "A lease expires",
72  "ns3::Ipv4Address::TracedCallback");
73  return tid;
74 }
75 
77 {
80  m_socket = 0;
86  m_timeout = EventId ();
87 }
88 
90 {
92  m_device = netDevice;
94  m_socket = 0;
100  m_timeout = EventId ();
101 }
102 
104 {
106 }
107 
109 {
110  return m_device;
111 }
112 
113 
115 {
116  m_device = netDevice;
117 }
118 
120 {
121  return m_server;
122 }
123 
124 void
126 {
127  NS_LOG_FUNCTION (this);
128 
129  m_device = 0;
130 
132 }
133 
134 int64_t
136 {
137  NS_LOG_FUNCTION (this << stream);
138  m_ran->SetStream (stream);
139  return 1;
140 }
141 
142 void
144 {
145  NS_LOG_FUNCTION (this);
146 
147  m_remoteAddress = Ipv4Address ("255.255.255.255");
148  m_myAddress = Ipv4Address ("0.0.0.0");
149  m_gateway = Ipv4Address ("0.0.0.0");
150  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
151  uint32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
152 
153  // We need to cleanup the type from the stored chaddr, or later we'll fail to compare it.
154  // Moreover, the length is always 16, because chaddr is 16 bytes.
155  Address myAddress = m_device->GetAddress ();
156  NS_LOG_INFO ("My address is " << myAddress);
157  uint8_t addr[Address::MAX_SIZE];
158  std::memset (addr, 0, Address::MAX_SIZE);
159  uint32_t len = myAddress.CopyTo (addr);
160  NS_ASSERT_MSG (len <= 16, "DHCP client can not handle a chaddr larger than 16 bytes");
161  m_chaddr.CopyFrom (addr, 16);
162  NS_LOG_INFO ("My m_chaddr is " << m_chaddr);
163 
164  bool found = false;
165  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
166  {
167  if (ipv4->GetAddress (ifIndex, i).GetLocal () == m_myAddress)
168  {
169  found = true;
170  }
171  }
172  if (!found)
173  {
174  ipv4->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("0.0.0.0"),Ipv4Mask ("/0")));
175  }
176  if (m_socket == 0)
177  {
178  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
181  m_socket->SetAllowBroadcast (true);
183  m_socket->Bind (local);
184  }
186 
187  m_device->AddLinkChangeCallback (MakeCallback (&DhcpClient::LinkStateHandler, this));
188  Boot ();
189 
190 }
191 
192 void
194 {
195  NS_LOG_FUNCTION (this);
196 
203  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
204 
205  int32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
206  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
207  {
208  if (ipv4->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
209  {
210  ipv4->RemoveAddress (ifIndex, i);
211  break;
212  }
213  }
214 
216  m_socket->Close ();
217 }
218 
220 {
221  NS_LOG_FUNCTION (this);
222 
223  if (m_device->IsLinkUp ())
224  {
225  NS_LOG_INFO ("Link up at " << Simulator::Now ().As (Time::S));
227  StartApplication ();
228  }
229  else
230  {
231  NS_LOG_INFO ("Link down at " << Simulator::Now ().As (Time::S)); //reinitialization
232  Simulator::Remove (m_refreshEvent); //stop refresh timer!!!!
235  m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); //stop receiving on this socket !!!
236 
237  Ptr<Ipv4> ipv4MN = GetNode ()->GetObject<Ipv4> ();
238  int32_t ifIndex = ipv4MN->GetInterfaceForDevice (m_device);
239 
240  for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
241  {
242  if (ipv4MN->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
243  {
244  ipv4MN->RemoveAddress (ifIndex, i);
245  break;
246  }
247  }
248 
249  Ipv4StaticRoutingHelper ipv4RoutingHelper;
250  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4MN);
251  uint32_t i;
252  for (i = 0; i < staticRouting->GetNRoutes (); i++)
253  {
254  if (staticRouting->GetRoute (i).GetGateway () == m_gateway)
255  {
256  staticRouting->RemoveRoute (i);
257  break;
258  }
259  }
260  }
261 }
262 
264 {
265  NS_LOG_FUNCTION (this << socket);
266 
267  Address from;
268  Ptr<Packet> packet = m_socket->RecvFrom (from);
269  DhcpHeader header;
270  if (packet->RemoveHeader (header) == 0)
271  {
272  return;
273  }
274  if (header.GetChaddr () != m_chaddr)
275  {
276  return;
277  }
278  if (m_state == WAIT_OFFER && header.GetType () == DhcpHeader::DHCPOFFER)
279  {
280  OfferHandler (header);
281  }
282  if (m_state == WAIT_ACK && header.GetType () == DhcpHeader::DHCPACK)
283  {
285  AcceptAck (header,from);
286  }
287  if (m_state == WAIT_ACK && header.GetType () == DhcpHeader::DHCPNACK)
288  {
290  Boot ();
291  }
292 }
293 
294 void DhcpClient::Boot (void)
295 {
296  NS_LOG_FUNCTION (this);
297 
298  DhcpHeader header;
299  Ptr<Packet> packet;
300  packet = Create<Packet> ();
301  header.ResetOpt ();
302  m_tran = (uint32_t) (m_ran->GetValue ());
303  header.SetTran (m_tran);
305  header.SetTime ();
306  header.SetChaddr (m_chaddr);
307  packet->AddHeader (header);
308 
309  if ((m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), DHCP_PEER_PORT))) >= 0)
310  {
311  NS_LOG_INFO ("DHCP DISCOVER sent" );
312  }
313  else
314  {
315  NS_LOG_INFO ("Error while sending DHCP DISCOVER to " << m_remoteAddress);
316  }
318  m_offered = false;
320 }
321 
323 {
324  NS_LOG_FUNCTION (this << header);
325 
326  m_offerList.push_back (header);
327  if (m_offered == false)
328  {
330  m_offered = true;
332  }
333 }
334 
336 {
337  NS_LOG_FUNCTION (this);
338 
339  if (m_offerList.empty ())
340  {
341  Boot ();
342  return;
343  }
344 
345  DhcpHeader header = m_offerList.front ();
346  m_offerList.pop_front ();
347  m_lease = Time (Seconds (header.GetLease ()));
348  m_renew = Time (Seconds (header.GetRenew ()));
349  m_rebind = Time (Seconds (header.GetRebind ()));
350  m_offeredAddress = header.GetYiaddr ();
351  m_myMask = Ipv4Mask (header.GetMask ());
352  m_server = header.GetDhcps ();
353  m_gateway = header.GetRouter ();
354  m_offerList.clear ();
355  m_offered = false;
356  Request ();
357 }
358 
360 {
361  NS_LOG_FUNCTION (this);
362 
363  DhcpHeader header;
364  Ptr<Packet> packet;
365  if (m_state != REFRESH_LEASE)
366  {
367  packet = Create<Packet> ();
368  header.ResetOpt ();
369  header.SetType (DhcpHeader::DHCPREQ);
370  header.SetTime ();
371  header.SetTran (m_tran);
372  header.SetReq (m_offeredAddress);
373  header.SetChaddr (m_chaddr);
374  packet->AddHeader (header);
375  m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), DHCP_PEER_PORT));
376  m_state = WAIT_ACK;
378  }
379  else
380  {
381  uint32_t addr = m_myAddress.Get ();
382  packet = Create<Packet> ((uint8_t*)&addr, sizeof(addr));
383  header.ResetOpt ();
384  m_tran = (uint32_t) (m_ran->GetValue ());
385  header.SetTran (m_tran);
386  header.SetTime ();
387  header.SetType (DhcpHeader::DHCPREQ);
388  header.SetReq (m_myAddress);
390  header.SetChaddr (m_chaddr);
391  packet->AddHeader (header);
392  if ((m_socket->SendTo (packet, 0, InetSocketAddress (m_remoteAddress, DHCP_PEER_PORT))) >= 0)
393  {
394  NS_LOG_INFO ("DHCP REQUEST sent");
395  }
396  else
397  {
398  NS_LOG_INFO ("Error while sending DHCP REQ to " << m_remoteAddress);
399  }
400  m_state = WAIT_ACK;
401  }
402 }
403 
405 {
406  NS_LOG_FUNCTION (this << header << from);
407 
411  NS_LOG_INFO ("DHCP ACK received");
412  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
413  int32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
414 
415  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
416  {
417  if (ipv4->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
418  {
419  NS_LOG_LOGIC ("Got a new address, removing old one: " << m_myAddress);
420  ipv4->RemoveAddress (ifIndex, i);
421  break;
422  }
423  }
424 
425  ipv4->AddAddress (ifIndex, Ipv4InterfaceAddress (m_offeredAddress, m_myMask));
426  ipv4->SetUp (ifIndex);
427 
429  m_socket->Connect (remote);
431  {
433  if (m_myAddress != Ipv4Address ("0.0.0.0"))
434  {
436  }
437  }
439  Ipv4StaticRoutingHelper ipv4RoutingHelper;
440  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
441  if (m_gateway == Ipv4Address ("0.0.0.0"))
442  {
444  }
445 
446  staticRouting->SetDefaultRoute (m_gateway, ifIndex, 0);
447 
449  NS_LOG_INFO ("Current DHCP Server is " << m_remoteAddress);
450 
451  m_offerList.clear ();
456 }
457 
459 {
460  NS_LOG_FUNCTION (this);
461 
466 
467  Ptr<Ipv4> ipv4MN = GetNode ()->GetObject<Ipv4> ();
468  int32_t ifIndex = ipv4MN->GetInterfaceForDevice (m_device);
469 
470  for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
471  {
472  if (ipv4MN->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
473  {
474  ipv4MN->RemoveAddress (ifIndex, i);
475  break;
476  }
477  }
479  Ipv4StaticRoutingHelper ipv4RoutingHelper;
480  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4MN);
481  uint32_t i;
482  for (i = 0; i < staticRouting->GetNRoutes (); i++)
483  {
484  if (staticRouting->GetRoute (i).GetGateway () == m_gateway)
485  {
486  staticRouting->RemoveRoute (i);
487  break;
488  }
489  }
490  StartApplication ();
491 }
492 
493 } // Namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
virtual void StartApplication(void)
Application specific startup code.
Definition: dhcp-client.cc:143
Ipv4Mask m_myMask
Mask of the address assigned.
Definition: dhcp-client.h:168
an Inet address class
void OfferHandler(DhcpHeader header)
Stores DHCP offers in m_offerList.
Definition: dhcp-client.cc:322
static Ipv4Address GetAny(void)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Time m_renew
Store the renew time of address.
Definition: dhcp-client.h:178
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetTime()
Set the time when message is sent.
Definition: dhcp-header.cc:106
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold variables of type string.
Definition: string.h:41
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
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:108
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
EventId m_refreshEvent
Message refresh event.
Definition: dhcp-client.h:173
Code for DHCP NACK.
Definition: dhcp-header.h:121
uint32_t GetMask(void) const
Return the mask of the network.
Definition: dhcp-header.cc:182
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:743
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Callback< R > MakeNullCallback(void)
Definition: callback.h:1635
void Request(void)
Sends the DHCP REQUEST message and changes the client state to WAIT_ACK.
Definition: dhcp-client.cc:359
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:166
Address GetChaddr(void)
Get the Address of the client.
Definition: dhcp-header.cc:125
uint8_t GetType(void) const
Return the type of DHCP message.
Definition: dhcp-header.cc:85
Ipv4Address GetRouter(void) const
Return the Ipv4Address of gateway to be used.
Definition: dhcp-header.cc:197
void SetType(uint8_t type)
Set the type of BOOTP and DHCP messages.
Definition: dhcp-header.cc:74
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
uint32_t GetRebind(void) const
Return the Rebind time of the address.
Definition: dhcp-header.cc:242
a polymophic address class
Definition: address.h:90
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
void AcceptAck(DhcpHeader header, Address from)
Receives the DHCP ACK and configures IP address of the client.
Definition: dhcp-client.cc:404
Ipv4Address m_server
Address of the DHCP server.
Definition: dhcp-client.h:169
virtual ~DhcpClient()
Definition: dhcp-client.cc:103
void SetTran(uint32_t tran)
Set the transaction ID.
Definition: dhcp-header.cc:96
Ipv4Address GetDhcpServer(void)
Get the IPv4Address of current DHCP server.
Definition: dhcp-client.cc:119
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:220
uint32_t m_tran
Stores the current transaction number to be used.
Definition: dhcp-client.h:186
Ptr< RandomVariableStream > m_ran
Uniform random variable for transaction ID.
Definition: dhcp-client.h:181
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
bool m_offered
Specify if the client has got any offer.
Definition: dhcp-client.h:184
The base class for all ns3 applications.
Definition: application.h:60
AttributeValue implementation for Time.
Definition: nstime.h:1124
void LinkStateHandler(void)
Handles changes in LinkState.
Definition: dhcp-client.cc:219
EventId m_rebindEvent
Message rebind event.
Definition: dhcp-client.h:174
void RemoveAndStart()
Remove the current DHCP information and restart the process.
Definition: dhcp-client.cc:458
Introspection did not find any typical Config paths.
Definition: dhcp-header.h:81
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Ipv4Address m_gateway
Address of the gateway.
Definition: dhcp-client.h:170
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:71
void Select(void)
Selects an OFFER from m_offerList.
Definition: dhcp-client.cc:335
Ipv4Address GetYiaddr(void) const
Get the IPv4Address of the client.
Definition: dhcp-header.cc:137
void SetReq(Ipv4Address addr)
Set the Ipv4Address requested by the client.
Definition: dhcp-header.cc:157
Ptr< Node > GetNode() const
Definition: application.cc:104
Time m_collect
Time for which client should collect offers.
Definition: dhcp-client.h:183
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
virtual void DoDispose(void)
Destructor implementation.
Definition: application.cc:83
EventId m_timeout
The timeout period.
Definition: dhcp-client.h:176
EventId m_requestEvent
Address refresh event.
Definition: dhcp-client.h:171
static void Remove(const EventId &id)
Remove an event from the event list.
Definition: simulator.cc:280
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
void SetChaddr(Address addr)
Set the Address of the device.
Definition: dhcp-header.cc:111
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:114
virtual void StopApplication(void)
Application specific shutdown code.
Definition: dhcp-client.cc:193
TracedCallback< const Ipv4Address & > m_newLease
Trace of new lease.
Definition: dhcp-client.h:187
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-client.cc:263
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1125
Ptr< NetDevice > m_device
NetDevice pointer.
Definition: dhcp-client.h:162
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
Code for DHCP Offer.
Definition: dhcp-header.h:118
void ResetOpt()
Reset the BOOTP options.
Definition: dhcp-header.cc:247
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-client.cc:125
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
Time m_nextoffer
Time to try the next offer (if request gets no reply)
Definition: dhcp-client.h:180
Ptr< Socket > m_socket
Socket for remote communication.
Definition: dhcp-client.h:163
Code for DHCP ACK.
Definition: dhcp-header.h:120
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:165
a class to store IPv4 address information on an interface
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:185
Address m_chaddr
chaddr of the interface (stored as an Address for convenience).
Definition: dhcp-client.h:167
Helper class that adds ns3::Ipv4StaticRouting objects.
Ipv4Address GetDhcps(void) const
Get the information about the DHCP server.
Definition: dhcp-header.cc:152
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:135
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
EventId m_nextOfferEvent
Message next offer event.
Definition: dhcp-client.h:175
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
State of a client that waits for the offer.
Definition: dhcp-client.h:99
second
Definition: nstime.h:114
Code for DHCP Request.
Definition: dhcp-header.h:119
uint32_t Get(void) const
Get the host-order 32-bit IP address.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
EventId m_discoverEvent
Message retransmission event.
Definition: dhcp-client.h:172
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:182
virtual int Close(void)=0
Close a socket.
void Boot(void)
Sends DHCP DISCOVER and changes the client state to WAIT_OFFER.
Definition: dhcp-client.cc:294
Time m_lease
Store the lease time of address.
Definition: dhcp-client.h:177
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
uint32_t GetLease(void) const
Return the lease time of the IPv4Address.
Definition: dhcp-header.cc:212
TracedCallback< const Ipv4Address & > m_expiry
Trace of lease expire.
Definition: dhcp-client.h:188
Code for DHCP Discover.
Definition: dhcp-header.h:117
uint32_t GetRenew(void) const
Return the Renewal time of the address.
Definition: dhcp-header.cc:227
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
Ipv4Address GetIpv4(void) const
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:824
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
Ipv4Address m_remoteAddress
Initially set to 255.255.255.255 to start DHCP.
Definition: dhcp-client.h:164
Time m_rebind
Store the rebind time of address.
Definition: dhcp-client.h:179