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 {
78  NS_LOG_FUNCTION (this);
80  m_socket = 0;
86  m_timeout = EventId ();
88  m_firstBoot = true;
89 }
90 
92 {
93  NS_LOG_FUNCTION (this << netDevice);
94  m_device = netDevice;
96  m_socket = 0;
100  m_rebindEvent = EventId ();
102  m_timeout = EventId ();
103  m_collectEvent = EventId ();
104  m_firstBoot = true;
105 }
106 
108 {
109  NS_LOG_FUNCTION (this);
110 }
111 
113 {
114  return m_device;
115 }
116 
117 
119 {
120  m_device = netDevice;
121 }
122 
124 {
125  return m_server;
126 }
127 
128 void
130 {
131  NS_LOG_FUNCTION (this);
132 
133  m_device = 0;
134 
135  // Stop all the timers
141  m_timeout.Cancel ();
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  if (m_firstBoot)
201  {
203  m_firstBoot = false;
204  }
205  Boot ();
206 
207 }
208 
209 void
211 {
212  NS_LOG_FUNCTION (this);
213 
214  // Stop all the timers
220  m_timeout.Cancel ();
222 
223  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
224 
225  int32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
226  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
227  {
228  if (ipv4->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
229  {
230  ipv4->RemoveAddress (ifIndex, i);
231  break;
232  }
233  }
234 
236  m_socket->Close ();
237 }
238 
240 {
241  NS_LOG_FUNCTION (this);
242 
243  if (m_device->IsLinkUp ())
244  {
245  NS_LOG_INFO ("Link up at " << Simulator::Now ().As (Time::S));
247  StartApplication ();
248  }
249  else
250  {
251  NS_LOG_INFO ("Link down at " << Simulator::Now ().As (Time::S)); //reinitialization
252 
253  // Stop all the timers
259  m_timeout.Cancel ();
261 
262  m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); //stop receiving on this socket !!!
263 
264  Ptr<Ipv4> ipv4MN = GetNode ()->GetObject<Ipv4> ();
265  int32_t ifIndex = ipv4MN->GetInterfaceForDevice (m_device);
266 
267  for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
268  {
269  if (ipv4MN->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
270  {
271  ipv4MN->RemoveAddress (ifIndex, i);
272  break;
273  }
274  }
275 
276  Ipv4StaticRoutingHelper ipv4RoutingHelper;
277  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4MN);
278  uint32_t i;
279  for (i = 0; i < staticRouting->GetNRoutes (); i++)
280  {
281  if (staticRouting->GetRoute (i).GetGateway () == m_gateway)
282  {
283  staticRouting->RemoveRoute (i);
284  break;
285  }
286  }
287 
288  m_state = 0;
289  m_myAddress = Ipv4Address ("0.0.0.0");
290  m_gateway = Ipv4Address ("0.0.0.0");
291  }
292 }
293 
295 {
296  NS_LOG_FUNCTION (this << socket);
297 
298  Address from;
299  Ptr<Packet> packet = m_socket->RecvFrom (from);
300  DhcpHeader header;
301  if (packet->RemoveHeader (header) == 0)
302  {
303  return;
304  }
305  if (header.GetChaddr () != m_chaddr)
306  {
307  return;
308  }
309  if (m_state == WAIT_OFFER && header.GetType () == DhcpHeader::DHCPOFFER)
310  {
311  OfferHandler (header);
312  }
313  if (m_state == WAIT_ACK && header.GetType () == DhcpHeader::DHCPACK)
314  {
316  AcceptAck (header,from);
317  }
318  if (m_state == WAIT_ACK && header.GetType () == DhcpHeader::DHCPNACK)
319  {
321  Boot ();
322  }
323 }
324 
325 void DhcpClient::Boot (void)
326 {
327  NS_LOG_FUNCTION (this);
328 
329  DhcpHeader header;
330  Ptr<Packet> packet;
331  packet = Create<Packet> ();
332  header.ResetOpt ();
333  m_tran = (uint32_t) (m_ran->GetValue ());
334  header.SetTran (m_tran);
336  header.SetTime ();
337  header.SetChaddr (m_chaddr);
338  packet->AddHeader (header);
339 
340  if ((m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), DHCP_PEER_PORT))) >= 0)
341  {
342  NS_LOG_INFO ("DHCP DISCOVER sent" );
343  }
344  else
345  {
346  NS_LOG_INFO ("Error while sending DHCP DISCOVER to " << m_remoteAddress);
347  }
349  m_offered = false;
351 }
352 
354 {
355  NS_LOG_FUNCTION (this << header);
356 
357  m_offerList.push_back (header);
358  if (m_offered == false)
359  {
361  m_offered = true;
363  }
364 }
365 
367 {
368  NS_LOG_FUNCTION (this);
369 
370  if (m_offerList.empty ())
371  {
372  Boot ();
373  return;
374  }
375 
376  DhcpHeader header = m_offerList.front ();
377  m_offerList.pop_front ();
378  m_lease = Time (Seconds (header.GetLease ()));
379  m_renew = Time (Seconds (header.GetRenew ()));
380  m_rebind = Time (Seconds (header.GetRebind ()));
381  m_offeredAddress = header.GetYiaddr ();
382  m_myMask = Ipv4Mask (header.GetMask ());
383  m_server = header.GetDhcps ();
384  m_gateway = header.GetRouter ();
385  m_offerList.clear ();
386  m_offered = false;
387  Request ();
388 }
389 
391 {
392  NS_LOG_FUNCTION (this);
393 
394  DhcpHeader header;
395  Ptr<Packet> packet;
396  if (m_state != REFRESH_LEASE)
397  {
398  packet = Create<Packet> ();
399  header.ResetOpt ();
400  header.SetType (DhcpHeader::DHCPREQ);
401  header.SetTime ();
402  header.SetTran (m_tran);
403  header.SetReq (m_offeredAddress);
404  header.SetChaddr (m_chaddr);
405  packet->AddHeader (header);
406  m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), DHCP_PEER_PORT));
407  m_state = WAIT_ACK;
409  }
410  else
411  {
412  uint32_t addr = m_myAddress.Get ();
413  packet = Create<Packet> ((uint8_t*)&addr, sizeof(addr));
414  header.ResetOpt ();
415  m_tran = (uint32_t) (m_ran->GetValue ());
416  header.SetTran (m_tran);
417  header.SetTime ();
418  header.SetType (DhcpHeader::DHCPREQ);
419  header.SetReq (m_myAddress);
421  header.SetChaddr (m_chaddr);
422  packet->AddHeader (header);
423  if ((m_socket->SendTo (packet, 0, InetSocketAddress (m_remoteAddress, DHCP_PEER_PORT))) >= 0)
424  {
425  NS_LOG_INFO ("DHCP REQUEST sent");
426  }
427  else
428  {
429  NS_LOG_INFO ("Error while sending DHCP REQ to " << m_remoteAddress);
430  }
431  m_state = WAIT_ACK;
432  }
433 }
434 
436 {
437  NS_LOG_FUNCTION (this << header << from);
438 
441  m_timeout.Cancel ();
442 
443  NS_LOG_INFO ("DHCP ACK received");
444  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
445  int32_t ifIndex = ipv4->GetInterfaceForDevice (m_device);
446 
448  {
449  for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
450  {
451  if (ipv4->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
452  {
453  NS_LOG_LOGIC ("Got a new address (" << m_offeredAddress << "), removing old one: " << m_myAddress);
454  ipv4->RemoveAddress (ifIndex, i);
455  break;
456  }
457  }
458 
459  ipv4->AddAddress (ifIndex, Ipv4InterfaceAddress (m_offeredAddress, m_myMask));
460  ipv4->SetUp (ifIndex);
461  }
462 
464  m_socket->Connect (remote);
466  {
468  if (m_myAddress != Ipv4Address ("0.0.0.0"))
469  {
471  }
472  }
474  Ipv4StaticRoutingHelper ipv4RoutingHelper;
475  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
476  if (m_gateway == Ipv4Address ("0.0.0.0"))
477  {
479  }
480 
481  staticRouting->SetDefaultRoute (m_gateway, ifIndex, 0);
482 
484  NS_LOG_INFO ("Current DHCP Server is " << m_remoteAddress);
485 
486  m_offerList.clear ();
491 }
492 
494 {
495  NS_LOG_FUNCTION (this);
496 
500  m_timeout.Cancel ();
501 
502  Ptr<Ipv4> ipv4MN = GetNode ()->GetObject<Ipv4> ();
503  int32_t ifIndex = ipv4MN->GetInterfaceForDevice (m_device);
504 
505  for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
506  {
507  if (ipv4MN->GetAddress (ifIndex,i).GetLocal () == m_myAddress)
508  {
509  ipv4MN->RemoveAddress (ifIndex, i);
510  break;
511  }
512  }
514  Ipv4StaticRoutingHelper ipv4RoutingHelper;
515  Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4MN);
516  uint32_t i;
517  for (i = 0; i < staticRouting->GetNRoutes (); i++)
518  {
519  if (staticRouting->GetRoute (i).GetGateway () == m_gateway)
520  {
521  staticRouting->RemoveRoute (i);
522  break;
523  }
524  }
525  StartApplication ();
526 }
527 
528 } // Namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::Socket::SetAllowBroadcast
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::DhcpClient::m_firstBoot
bool m_firstBoot
First boot (used to add the link state change callback)
Definition: dhcp-client.h:162
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
ns3::Socket::Bind
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::DhcpClient::m_myMask
Ipv4Mask m_myMask
Mask of the address assigned.
Definition: dhcp-client.h:169
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3::NetDevice::GetAddress
virtual Address GetAddress(void) const =0
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DhcpClient::SetDhcpClientNetDevice
void SetDhcpClientNetDevice(Ptr< NetDevice > netDevice)
Set the NetDevice DHCP should work on.
Definition: dhcp-client.cc:118
ns3::DhcpClient::m_gateway
Ipv4Address m_gateway
Address of the gateway.
Definition: dhcp-client.h:171
ns3::DhcpClient::Select
void Select(void)
Selects an OFFER from m_offerList.
Definition: dhcp-client.cc:366
ns3::DhcpHeader::GetDhcps
Ipv4Address GetDhcps(void) const
Get the information about the DHCP server.
Definition: dhcp-header.cc:152
ns3::DhcpClient::m_discoverEvent
EventId m_discoverEvent
Message retransmission event.
Definition: dhcp-client.h:173
dhcp-header.h
ns3::DhcpClient::m_collect
Time m_collect
Time for which client should collect offers.
Definition: dhcp-client.h:185
ns3::DhcpClient::~DhcpClient
virtual ~DhcpClient()
Definition: dhcp-client.cc:107
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::DhcpClient::m_lease
Time m_lease
Store the lease time of address.
Definition: dhcp-client.h:179
ns3::DhcpClient::m_chaddr
Address m_chaddr
chaddr of the interface (stored as an Address for convenience).
Definition: dhcp-client.h:168
ns3::DhcpClient::Boot
void Boot(void)
Sends DHCP DISCOVER and changes the client state to WAIT_OFFER.
Definition: dhcp-client.cc:325
ns3::DhcpHeader::SetType
void SetType(uint8_t type)
Set the type of BOOTP and DHCP messages.
Definition: dhcp-header.cc:74
ns3::DhcpClient::m_requestEvent
EventId m_requestEvent
Address refresh event.
Definition: dhcp-client.h:172
ns3::Ipv4Address::Get
uint32_t Get(void) const
Get the host-order 32-bit IP address.
Definition: ipv4-address.cc:214
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::DhcpClient::m_timeout
EventId m_timeout
The timeout period.
Definition: dhcp-client.h:177
dhcp-client.h
ns3::DhcpClient::m_rebind
Time m_rebind
Store the rebind time of address.
Definition: dhcp-client.h:181
ns3::Application::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: application.cc:83
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
ns3::Socket::SendTo
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
ns3::DhcpClient::m_state
uint8_t m_state
State of the DHCP client.
Definition: dhcp-client.h:161
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition: inet-socket-address.cc:126
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DhcpClient::m_nextOfferEvent
EventId m_nextOfferEvent
Message next offer event.
Definition: dhcp-client.h:176
ns3::DhcpClient::GetDhcpClientNetDevice
Ptr< NetDevice > GetDhcpClientNetDevice(void)
Get the the NetDevice DHCP should work on.
Definition: dhcp-client.cc:112
ns3::MakeNullCallback
Callback< R, Ts... > MakeNullCallback(void)
Definition: callback.h:1682
ns3::DhcpClient::m_myAddress
Ipv4Address m_myAddress
Address assigned to the client.
Definition: dhcp-client.h:167
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::DhcpHeader::DHCPOFFER
@ DHCPOFFER
Code for DHCP Offer.
Definition: dhcp-header.h:118
ns3::DhcpHeader::GetRenew
uint32_t GetRenew(void) const
Return the Renewal time of the address.
Definition: dhcp-header.cc:227
ns3::DhcpHeader::SetTran
void SetTran(uint32_t tran)
Set the transaction ID.
Definition: dhcp-header.cc:96
ns3::Ipv4
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
ns3::Ipv4StaticRoutingHelper
Helper class that adds ns3::Ipv4StaticRouting objects.
Definition: ipv4-static-routing-helper.h:43
ns3::DhcpClient::LinkStateHandler
void LinkStateHandler(void)
Handles changes in LinkState.
Definition: dhcp-client.cc:239
ns3::Ptr< NetDevice >
ns3::NetDevice::IsLinkUp
virtual bool IsLinkUp(void) const =0
ns3::DhcpClient::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-client.cc:129
ns3::Socket::SetRecvCallback
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
ns3::Ipv4StaticRoutingHelper::GetStaticRouting
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...
Definition: ipv4-static-routing-helper.cc:58
ns3::DhcpClient::StopApplication
virtual void StopApplication(void)
Application specific shutdown code.
Definition: dhcp-client.cc:210
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::DhcpClient::m_server
Ipv4Address m_server
Address of the DHCP server.
Definition: dhcp-client.h:170
ns3::DhcpClient::m_offerList
std::list< DhcpHeader > m_offerList
Stores all the offers given to the client.
Definition: dhcp-client.h:187
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition: ipv4-interface-address.h:44
ns3::DhcpClient::m_device
Ptr< NetDevice > m_device
NetDevice pointer.
Definition: dhcp-client.h:163
ns3::DhcpClient::AcceptAck
void AcceptAck(DhcpHeader header, Address from)
Receives the DHCP ACK and configures IP address of the client.
Definition: dhcp-client.cc:435
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
ns3::DhcpClient::AssignStreams
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
ns3::Socket::RecvFrom
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.
ns3::DhcpClient::WAIT_OFFER
@ WAIT_OFFER
State of a client that waits for the offer.
Definition: dhcp-client.h:99
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4(void) const
Definition: inet-socket-address.cc:71
ns3::DhcpHeader::GetRebind
uint32_t GetRebind(void) const
Return the Rebind time of the address.
Definition: dhcp-header.cc:242
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
ns3::EventId::Cancel
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
ns3::Address::CopyFrom
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
ns3::DhcpHeader::SetTime
void SetTime()
Set the time when message is sent.
Definition: dhcp-header.cc:106
ns3::DhcpClient::m_nextoffer
Time m_nextoffer
Time to try the next offer (if request gets no reply)
Definition: dhcp-client.h:182
ns3::Socket::Close
virtual int Close(void)=0
Close a socket.
ns3::DhcpHeader::GetYiaddr
Ipv4Address GetYiaddr(void) const
Get the IPv4Address of the client.
Definition: dhcp-header.cc:137
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
ns3::DhcpHeader::ResetOpt
void ResetOpt()
Reset the BOOTP options.
Definition: dhcp-header.cc:247
ns3::DhcpHeader::DHCPDISCOVER
@ DHCPDISCOVER
Code for DHCP Discover.
Definition: dhcp-header.h:117
ns3::DhcpClient::GetDhcpServer
Ipv4Address GetDhcpServer(void)
Get the IPv4Address of current DHCP server.
Definition: dhcp-client.cc:123
ns3::DhcpHeader::DHCPREQ
@ DHCPREQ
Code for DHCP Request.
Definition: dhcp-header.h:119
ns3::DhcpClient::Request
void Request(void)
Sends the DHCP REQUEST message and changes the client state to WAIT_ACK.
Definition: dhcp-client.cc:390
ns3::DhcpHeader::GetType
uint8_t GetType(void) const
Return the type of DHCP message.
Definition: dhcp-header.cc:85
ns3::DhcpClient::m_refreshEvent
EventId m_refreshEvent
Message refresh event.
Definition: dhcp-client.h:174
ns3::MakeCallback
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::DhcpClient::m_offered
bool m_offered
Specify if the client has got any offer.
Definition: dhcp-client.h:186
ns3::MakePointerAccessor
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:227
ns3::DhcpHeader::GetRouter
Ipv4Address GetRouter(void) const
Return the Ipv4Address of gateway to be used.
Definition: dhcp-header.cc:197
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::DhcpHeader::GetChaddr
Address GetChaddr(void)
Get the Address of the client.
Definition: dhcp-header.cc:125
ns3::DhcpClient::m_remoteAddress
Ipv4Address m_remoteAddress
Initially set to 255.255.255.255 to start DHCP.
Definition: dhcp-client.h:165
ns3::DhcpClient::WAIT_ACK
@ WAIT_ACK
State of a client that waits for acknowledgment.
Definition: dhcp-client.h:101
ns3::Ipv4Address::GetAny
static Ipv4Address GetAny(void)
Definition: ipv4-address.cc:395
ns3::Socket::Connect
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
ns3::RandomVariableStream::GetValue
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::DhcpClient::m_socket
Ptr< Socket > m_socket
Socket for remote communication.
Definition: dhcp-client.h:164
ns3::Time::S
@ S
second
Definition: nstime.h:115
ns3::NetDevice::AddLinkChangeCallback
virtual void AddLinkChangeCallback(Callback< void > callback)=0
ns3::DhcpHeader::DHCPACK
@ DHCPACK
Code for DHCP ACK.
Definition: dhcp-header.h:120
ns3::DhcpClient::m_expiry
TracedCallback< const Ipv4Address & > m_expiry
Trace of lease expire.
Definition: dhcp-client.h:190
ns3::Socket::BindToNetDevice
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::DhcpClient::StartApplication
virtual void StartApplication(void)
Application specific startup code.
Definition: dhcp-client.cc:156
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
ns3::DhcpHeader::GetMask
uint32_t GetMask(void) const
Return the mask of the network.
Definition: dhcp-header.cc:182
ns3::RandomVariableStream::SetStream
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Definition: random-variable-stream.cc:100
ns3::DhcpClient::OfferHandler
void OfferHandler(DhcpHeader header)
Stores DHCP offers in m_offerList.
Definition: dhcp-client.cc:353
ns3::Application::GetNode
Ptr< Node > GetNode() const
Definition: application.cc:104
ns3::Socket::CreateSocket
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
ns3::TracedValueCallback::Time
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:813
ns3::DhcpClient::m_renew
Time m_renew
Store the renew time of address.
Definition: dhcp-client.h:180
ns3::DhcpHeader::GetLease
uint32_t GetLease(void) const
Return the lease time of the IPv4Address.
Definition: dhcp-header.cc:212
ns3::DhcpClient::RemoveAndStart
void RemoveAndStart()
Remove the current DHCP information and restart the process.
Definition: dhcp-client.cc:493
ns3::Application
The base class for all ns3 applications.
Definition: application.h:61
ns3::DhcpClient::m_offeredAddress
Ipv4Address m_offeredAddress
Address offered to the client.
Definition: dhcp-client.h:166
ns3::DhcpHeader
BOOTP header with DHCP messages supports the following options: Subnet Mask (1), Address Request (50)...
Definition: dhcp-header.h:82
ns3::DhcpClient::m_rebindEvent
EventId m_rebindEvent
Message rebind event.
Definition: dhcp-client.h:175
ns3::Address::MAX_SIZE
@ MAX_SIZE
Definition: address.h:98
ns3::DhcpHeader::DHCPNACK
@ DHCPNACK
Code for DHCP NACK.
Definition: dhcp-header.h:121
ns3::DhcpClient::DhcpClient
DhcpClient()
Definition: dhcp-client.cc:76
ns3::DhcpClient::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-client.cc:42
ns3::DhcpClient::DHCP_PEER_PORT
static const int DHCP_PEER_PORT
DHCP server port.
Definition: dhcp-client.h:104
ns3::TypeId::LookupByName
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:830
ns3::DhcpClient::NetHandler
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-client.cc:294
ns3::DhcpClient::m_tran
uint32_t m_tran
Stores the current transaction number to be used.
Definition: dhcp-client.h:188
ns3::DhcpClient::m_ran
Ptr< RandomVariableStream > m_ran
Uniform random variable for transaction ID.
Definition: dhcp-client.h:183
ns3::DhcpHeader::SetChaddr
void SetChaddr(Address addr)
Set the Address of the device.
Definition: dhcp-header.cc:111
ns3::DhcpHeader::SetReq
void SetReq(Ipv4Address addr)
Set the Ipv4Address requested by the client.
Definition: dhcp-header.cc:157
ns3::DhcpClient::m_rtrs
Time m_rtrs
Defining the time for retransmission.
Definition: dhcp-client.h:184
ns3::MakeTimeAccessor
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:1354
ns3::DhcpClient::m_collectEvent
EventId m_collectEvent
Offer collection event.
Definition: dhcp-client.h:178
ns3::DhcpClient::m_newLease
TracedCallback< const Ipv4Address & > m_newLease
Trace of new lease.
Definition: dhcp-client.h:189
ns3::DhcpClient::REFRESH_LEASE
@ REFRESH_LEASE
State of a client that needs to refresh the lease.
Definition: dhcp-client.h:100