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 <stdlib.h>
27 #include <stdio.h>
28 #include <list>
29 
30 #include "ns3/ipv4.h"
31 #include "ns3/log.h"
32 #include "ns3/double.h"
33 #include "ns3/ipv4-address.h"
34 #include "ns3/nstime.h"
35 #include "ns3/inet-socket-address.h"
36 #include "ns3/socket.h"
37 #include "ns3/simulator.h"
38 #include "ns3/socket-factory.h"
39 #include "ns3/packet.h"
40 #include "ns3/ipv4-static-routing-helper.h"
41 #include "ns3/uinteger.h"
42 #include "ns3/random-variable-stream.h"
43 #include "ns3/pointer.h"
44 #include "ns3/string.h"
45 #include "ns3/ipv4-routing-table-entry.h"
46 #include "dhcp-client.h"
47 #include "dhcp-header.h"
48 
49 namespace ns3 {
50 
51 NS_LOG_COMPONENT_DEFINE ("DhcpClient");
52 NS_OBJECT_ENSURE_REGISTERED (DhcpClient);
53 
54 TypeId
56 {
57  static TypeId tid = TypeId ("ns3::DhcpClient")
59  .AddConstructor<DhcpClient> ()
60  .SetGroupName ("Internet-Apps")
61  .AddAttribute ("RTRS", "Time for retransmission of Discover message",
62  TimeValue (Seconds (5)),
64  MakeTimeChecker ())
65  .AddAttribute ("Collect", "Time for which offer collection starts",
66  TimeValue (Seconds (5)),
68  MakeTimeChecker ())
69  .AddAttribute ("ReRequest", "Time after which request will be resent to next server",
70  TimeValue (Seconds (10)),
72  MakeTimeChecker ())
73  .AddAttribute ("Transactions",
74  "The possible value of transaction numbers ",
75  StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000000.0]"),
77  MakePointerChecker<RandomVariableStream> ())
78  .AddTraceSource ("NewLease",
79  "Get a NewLease",
81  "ns3::Ipv4Address::TracedCallback")
82  .AddTraceSource ("ExpireLease",
83  "A lease expires",
85  "ns3::Ipv4Address::TracedCallback");
86  return tid;
87 }
88 
90 {
93  m_socket = 0;
99  m_timeout = EventId ();
100 }
101 
103 {
105  m_device = netDevice;
107  m_socket = 0;
108  m_refreshEvent = EventId ();
109  m_requestEvent = EventId ();
111  m_rebindEvent = EventId ();
113  m_timeout = EventId ();
114 }
115 
117 {
119 }
120 
122 {
123  return m_device;
124 }
125 
126 
128 {
129  m_device = netDevice;
130 }
131 
133 {
134  return m_server;
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION (this);
141 
142  m_device = 0;
143 
145 }
146 
147 int64_t
149 {
150  NS_LOG_FUNCTION (this << stream);
151  m_ran->SetStream (stream);
152  return 1;
153 }
154 
155 void
157 {
158  NS_LOG_FUNCTION (this);
159 
160  m_remoteAddress = Ipv4Address ("255.255.255.255");
161  m_myAddress = Ipv4Address ("0.0.0.0");
162  m_gateway = Ipv4Address ("0.0.0.0");
163  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
164  uint32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
165 
166  // We need to cleanup the type from the stored chaddr, or later we'll fail to compare it.
167  // Moreover, the length is always 16, because chaddr is 16 bytes.
168  Address myAddress = m_device->GetAddress ();
169  NS_LOG_INFO ("My address is " << myAddress);
170  uint8_t addr[Address::MAX_SIZE];
171  std::memset (addr, 0, Address::MAX_SIZE);
172  uint32_t len = myAddress.CopyTo (addr);
173  NS_ASSERT_MSG (len <= 16, "DHCP client can not handle a chaddr larger than 16 bytes");
174  m_chaddr.CopyFrom (addr, 16);
175  NS_LOG_INFO ("My m_chaddr is " << m_chaddr);
176 
177  bool found = false;
178  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
179  {
180  if (ipv4->GetAddress (ifIndex, i).GetLocal () == m_myAddress)
181  {
182  found = true;
183  }
184  }
185  if (!found)
186  {
187  ipv4->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("0.0.0.0"),Ipv4Mask ("/0")));
188  }
189  if (m_socket == 0)
190  {
191  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
194  m_socket->SetAllowBroadcast (true);
196  m_socket->Bind (local);
197  }
199 
200  m_device->AddLinkChangeCallback (MakeCallback (&DhcpClient::LinkStateHandler, this));
201  Boot ();
202 
203 }
204 
205 void
207 {
208  NS_LOG_FUNCTION (this);
209 
216  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
217 
218  int32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
219  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
220  {
221  if (ipv4->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
222  {
223  ipv4->RemoveAddress (ifIndex, i);
224  break;
225  }
226  }
227 
229  m_socket->Close ();
230 }
231 
233 {
234  NS_LOG_FUNCTION (this);
235 
236  if (m_device->IsLinkUp ())
237  {
238  NS_LOG_INFO ("Link up at " << Simulator::Now ().As (Time::S));
240  StartApplication ();
241  }
242  else
243  {
244  NS_LOG_INFO ("Link down at " << Simulator::Now ().As (Time::S)); //reinitialization
245  Simulator::Remove (m_refreshEvent); //stop refresh timer!!!!
248  m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); //stop receiving on this socket !!!
249 
250  Ptr<Ipv4> ipv4MN = GetNode ()->GetObject<Ipv4> ();
251  int32_t ifIndex = ipv4MN->GetInterfaceForDevice (m_device);
252 
253  for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
254  {
255  if (ipv4MN->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
256  {
257  ipv4MN->RemoveAddress (ifIndex, i);
258  break;
259  }
260  }
261 
262  Ipv4StaticRoutingHelper ipv4RoutingHelper;
263  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4MN);
264  uint32_t i;
265  for (i = 0; i < staticRouting->GetNRoutes (); i++)
266  {
267  if (staticRouting->GetRoute (i).GetGateway () == m_gateway)
268  {
269  staticRouting->RemoveRoute (i);
270  break;
271  }
272  }
273  }
274 }
275 
277 {
278  NS_LOG_FUNCTION (this << socket);
279 
280  Address from;
281  Ptr<Packet> packet = m_socket->RecvFrom (from);
282  DhcpHeader header;
283  if (packet->RemoveHeader (header) == 0)
284  {
285  return;
286  }
287  if (header.GetChaddr () != m_chaddr)
288  {
289  return;
290  }
291  if (m_state == WAIT_OFFER && header.GetType () == DhcpHeader::DHCPOFFER)
292  {
293  OfferHandler (header);
294  }
295  if (m_state == WAIT_ACK && header.GetType () == DhcpHeader::DHCPACK)
296  {
298  AcceptAck (header,from);
299  }
300  if (m_state == WAIT_ACK && header.GetType () == DhcpHeader::DHCPNACK)
301  {
303  Boot ();
304  }
305 }
306 
307 void DhcpClient::Boot (void)
308 {
309  NS_LOG_FUNCTION (this);
310 
311  DhcpHeader header;
312  Ptr<Packet> packet;
313  packet = Create<Packet> ();
314  header.ResetOpt ();
315  m_tran = (uint32_t) (m_ran->GetValue ());
316  header.SetTran (m_tran);
318  header.SetTime ();
319  header.SetChaddr (m_chaddr);
320  packet->AddHeader (header);
321 
322  if ((m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), DHCP_PEER_PORT))) >= 0)
323  {
324  NS_LOG_INFO ("DHCP DISCOVER sent" );
325  }
326  else
327  {
328  NS_LOG_INFO ("Error while sending DHCP DISCOVER to " << m_remoteAddress);
329  }
331  m_offered = false;
333 }
334 
336 {
337  NS_LOG_FUNCTION (this << header);
338 
339  m_offerList.push_back (header);
340  if (m_offered == false)
341  {
343  m_offered = true;
345  }
346 }
347 
349 {
350  NS_LOG_FUNCTION (this);
351 
352  if (m_offerList.empty ())
353  {
354  Boot ();
355  return;
356  }
357 
358  DhcpHeader header = m_offerList.front ();
359  m_offerList.pop_front ();
360  m_lease = Time (Seconds (header.GetLease ()));
361  m_renew = Time (Seconds (header.GetRenew ()));
362  m_rebind = Time (Seconds (header.GetRebind ()));
363  m_offeredAddress = header.GetYiaddr ();
364  m_myMask = Ipv4Mask (header.GetMask ());
365  m_server = header.GetDhcps ();
366  m_gateway = header.GetRouter ();
367  m_offerList.clear ();
368  m_offered = false;
369  Request ();
370 }
371 
373 {
374  NS_LOG_FUNCTION (this);
375 
376  DhcpHeader header;
377  Ptr<Packet> packet;
378  if (m_state != REFRESH_LEASE)
379  {
380  packet = Create<Packet> ();
381  header.ResetOpt ();
382  header.SetType (DhcpHeader::DHCPREQ);
383  header.SetTime ();
384  header.SetTran (m_tran);
385  header.SetReq (m_offeredAddress);
386  header.SetChaddr (m_chaddr);
387  packet->AddHeader (header);
388  m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), DHCP_PEER_PORT));
389  m_state = WAIT_ACK;
391  }
392  else
393  {
394  uint32_t addr = m_myAddress.Get ();
395  packet = Create<Packet> ((uint8_t*)&addr, sizeof(addr));
396  header.ResetOpt ();
397  m_tran = (uint32_t) (m_ran->GetValue ());
398  header.SetTran (m_tran);
399  header.SetTime ();
400  header.SetType (DhcpHeader::DHCPREQ);
401  header.SetReq (m_myAddress);
403  header.SetChaddr (m_chaddr);
404  packet->AddHeader (header);
405  if ((m_socket->SendTo (packet, 0, InetSocketAddress (m_remoteAddress, DHCP_PEER_PORT))) >= 0)
406  {
407  NS_LOG_INFO ("DHCP REQUEST sent");
408  }
409  else
410  {
411  NS_LOG_INFO ("Error while sending DHCP REQ to " << m_remoteAddress);
412  }
413  m_state = WAIT_ACK;
414  }
415 }
416 
418 {
419  NS_LOG_FUNCTION (this << header << from);
420 
424  NS_LOG_INFO ("DHCP ACK received");
425  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
426  int32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
427 
428  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
429  {
430  if (ipv4->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
431  {
432  NS_LOG_LOGIC ("Got a new address, removing old one: " << m_myAddress);
433  ipv4->RemoveAddress (ifIndex, i);
434  break;
435  }
436  }
437 
438  ipv4->AddAddress (ifIndex, Ipv4InterfaceAddress (m_offeredAddress, m_myMask));
439  ipv4->SetUp (ifIndex);
440 
442  m_socket->Connect (remote);
444  {
446  if (m_myAddress != Ipv4Address ("0.0.0.0"))
447  {
449  }
450  }
452  Ipv4StaticRoutingHelper ipv4RoutingHelper;
453  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
454  if (m_gateway == Ipv4Address ("0.0.0.0"))
455  {
457  }
458 
459  staticRouting->SetDefaultRoute (m_gateway, ifIndex, 0);
460 
462  NS_LOG_INFO ("Current DHCP Server is " << m_remoteAddress);
463 
464  m_offerList.clear ();
469 }
470 
472 {
473  NS_LOG_FUNCTION (this);
474 
479 
480  Ptr<Ipv4> ipv4MN = GetNode ()->GetObject<Ipv4> ();
481  int32_t ifIndex = ipv4MN->GetInterfaceForDevice (m_device);
482 
483  for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
484  {
485  if (ipv4MN->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
486  {
487  ipv4MN->RemoveAddress (ifIndex, i);
488  break;
489  }
490  }
492  Ipv4StaticRoutingHelper ipv4RoutingHelper;
493  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4MN);
494  uint32_t i;
495  for (i = 0; i < staticRouting->GetNRoutes (); i++)
496  {
497  if (staticRouting->GetRoute (i).GetGateway () == m_gateway)
498  {
499  staticRouting->RemoveRoute (i);
500  break;
501  }
502  }
503  StartApplication ();
504 }
505 
506 } // 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:156
Ipv4Mask m_myMask
Mask of the address assigned.
Definition: dhcp-client.h:171
an Inet address class
void OfferHandler(DhcpHeader header)
Stores DHCP offers in m_offerList.
Definition: dhcp-client.cc:335
Ipv4Address GetIpv4(void) const
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:181
#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:107
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
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: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
Ipv4Address GetRouter(void) const
Return the Ipv4Address of gateway to be used.
Definition: dhcp-header.cc:198
Code for DHCP NACK.
Definition: dhcp-header.h:123
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:733
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Callback< R > MakeNullCallback(void)
Definition: callback.h:1635
uint8_t GetType(void) const
Return the type of DHCP message.
Definition: dhcp-header.cc:86
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
uint32_t GetLease(void) const
Return the lease time of the IPv4Address.
Definition: dhcp-header.cc:213
Ipv4Address m_myAddress
Address assigned to the client.
Definition: dhcp-client.h:169
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
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
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
uint32_t GetMask(void) const
Return the mask of the network.
Definition: dhcp-header.cc:183
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
void SetTran(uint32_t tran)
Set the transaction ID.
Definition: dhcp-header.cc:97
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
Ipv4Address GetDhcpServer(void)
Get the IPv4Address of current DHCP server.
Definition: dhcp-client.cc:132
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:189
Ptr< RandomVariableStream > m_ran
Uniform random variable for transaction ID.
Definition: dhcp-client.h:184
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
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
AttributeValue implementation for Time.
Definition: nstime.h:1069
void LinkStateHandler(void)
Handles changes in LinkState.
Definition: dhcp-client.cc:232
uint32_t GetRenew(void) const
Return the Renewal time of the address.
Definition: dhcp-header.cc:228
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
uint32_t Get(void) const
Get the host-order 32-bit IP address.
Ptr< Node > GetNode() const
Definition: application.cc:104
Introspection did not find any typical Config paths.
Definition: dhcp-header.h:83
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Ipv4Address m_gateway
Address of the gateway.
Definition: dhcp-client.h:173
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:348
void SetReq(Ipv4Address addr)
Set the Ipv4Address requested by the client.
Definition: dhcp-header.cc:158
Time m_collect
Time for which client should collect offers.
Definition: dhcp-client.h:186
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
virtual void DoDispose(void)
Destructor implementation.
Definition: application.cc:83
EventId m_timeout
The timeout period.
Definition: dhcp-client.h:179
EventId m_requestEvent
Address refresh event.
Definition: dhcp-client.h:174
static void Remove(const EventId &id)
Remove an event from the event list.
Definition: simulator.cc:336
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:112
Ipv4Address GetDhcps(void) const
Get the information about the DHCP server.
Definition: dhcp-header.cc:153
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< 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:1070
Ptr< NetDevice > m_device
NetDevice pointer.
Definition: dhcp-client.h:165
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
Code for DHCP Offer.
Definition: dhcp-header.h:120
void ResetOpt()
Reset the BOOTP options.
Definition: dhcp-header.cc:248
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-client.cc:138
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:183
uint32_t GetRebind(void) const
Return the Rebind time of the address.
Definition: dhcp-header.cc:243
Ptr< Socket > m_socket
Socket for remote communication.
Definition: dhcp-client.h:166
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 CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
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 m_offeredAddress
Address offered to the client.
Definition: dhcp-client.h:168
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:188
Address m_chaddr
chaddr of the interface (stored as an Address for convenience).
Definition: dhcp-client.h:170
Helper class that adds ns3::Ipv4StaticRouting objects.
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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
EventId m_nextOfferEvent
Message next offer event.
Definition: dhcp-client.h:178
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:102
second
Definition: nstime.h:114
Code for DHCP Request.
Definition: dhcp-header.h:121
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:175
Ipv4Address GetYiaddr(void) const
Get the IPv4Address of the client.
Definition: dhcp-header.cc:138
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
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: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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
TracedCallback< const Ipv4Address & > m_expiry
Trace of lease expire.
Definition: dhcp-client.h:191
Code for DHCP Discover.
Definition: dhcp-header.h:119
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:824
Ipv4Address m_remoteAddress
Initially set to 255.255.255.255 to start DHCP.
Definition: dhcp-client.h:167
Time m_rebind
Store the rebind time of address.
Definition: dhcp-client.h:182