A Discrete-Event Network Simulator
API
dhcp-server.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 #include "ns3/log.h"
26 #include "ns3/assert.h"
27 #include "ns3/ipv4-address.h"
28 #include "ns3/nstime.h"
29 #include "ns3/inet-socket-address.h"
30 #include "ns3/ipv4-packet-info-tag.h"
31 #include "ns3/socket.h"
32 #include "ns3/simulator.h"
33 #include "ns3/socket-factory.h"
34 #include "ns3/packet.h"
35 #include "ns3/uinteger.h"
36 #include "ns3/config.h"
37 #include "dhcp-server.h"
38 #include "dhcp-header.h"
39 #include "ns3/ipv4.h"
40 #include <map>
41 #include <algorithm>
42 
43 namespace ns3 {
44 
45 NS_LOG_COMPONENT_DEFINE ("DhcpServer");
46 NS_OBJECT_ENSURE_REGISTERED (DhcpServer);
47 
48 TypeId
50 {
51  static TypeId tid = TypeId ("ns3::DhcpServer")
53  .AddConstructor<DhcpServer> ()
54  .SetGroupName ("Internet-Apps")
55  .AddAttribute ("LeaseTime",
56  "Lease for which address will be leased.",
57  TimeValue (Seconds (30)),
59  MakeTimeChecker ())
60  .AddAttribute ("RenewTime",
61  "Time after which client should renew.",
62  TimeValue (Seconds (15)),
64  MakeTimeChecker ())
65  .AddAttribute ("RebindTime",
66  "Time after which client should rebind.",
67  TimeValue (Seconds (25)),
69  MakeTimeChecker ())
70  .AddAttribute ("PoolAddresses",
71  "Pool of addresses to provide on request.",
75  .AddAttribute ("FirstAddress",
76  "The First valid address that can be given.",
80  .AddAttribute ("LastAddress",
81  "The Last valid address that can be given.",
85  .AddAttribute ("PoolMask",
86  "Mask of the pool of addresses.",
87  Ipv4MaskValue (),
90  .AddAttribute ("Gateway",
91  "Address of default gateway",
95  ;
96  return tid;
97 }
98 
100 {
101  NS_LOG_FUNCTION (this);
102 }
103 
105 {
106  NS_LOG_FUNCTION (this);
107 }
108 
109 void
111 {
112  NS_LOG_FUNCTION (this);
114 }
115 
117 {
118  NS_LOG_FUNCTION (this);
119 
120  NS_ASSERT_MSG (m_minAddress < m_maxAddress,"Invalid Address range");
121 
122  Ipv4Address myOwnAddress;
123 
124  if (m_socket)
125  {
126  NS_ABORT_MSG ("DHCP daemon is not (yet) meant to be started twice or more.");
127  }
128 
129  uint32_t addrIndex;
130 
131  //add the DHCP local address to the leased addresses list, if it is defined!
132  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
133  int32_t ifIndex = ipv4->GetInterfaceForPrefix (m_poolAddress, m_poolMask);
134 
135  if (ifIndex < 0)
136  {
137  NS_ABORT_MSG ("DHCP daemon must be run on the same subnet it is assigning the addresses.");
138  }
139 
140  for (addrIndex = 0; addrIndex < ipv4->GetNAddresses (ifIndex); addrIndex++)
141  {
142  if (ipv4->GetAddress (ifIndex, addrIndex).GetLocal ().CombineMask (m_poolMask) == m_poolAddress &&
143  ipv4->GetAddress (ifIndex, addrIndex).GetLocal ().Get () >= m_minAddress.Get () &&
144  ipv4->GetAddress (ifIndex, addrIndex).GetLocal ().Get () <= m_maxAddress.Get ())
145  {
146  // set infinite GRANTED_LEASED_TIME for my address
147 
148  myOwnAddress = ipv4->GetAddress (ifIndex, addrIndex).GetLocal ();
149  m_leasedAddresses[Address ()] = std::make_pair (myOwnAddress, 0xffffffff);
150  break;
151  }
152  }
153 
154  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
157  m_socket->SetAllowBroadcast (true);
158  m_socket->BindToNetDevice (ipv4->GetNetDevice (ifIndex));
159  m_socket->Bind (local);
160  m_socket->SetRecvPktInfo (true);
161 
162  uint32_t range = m_maxAddress.Get () - m_minAddress.Get () + 1;
163  for (uint32_t searchSeq = 0; searchSeq < range; searchSeq ++)
164  {
165  Ipv4Address poolAddress = Ipv4Address (m_minAddress.Get () + searchSeq);
166  if (poolAddress != myOwnAddress)
167  {
168  NS_LOG_LOGIC ("Adding " << poolAddress << " to the pool");
169  m_availableAddresses.push_back (poolAddress);
170  }
171  }
172 
175 }
176 
178 {
179  NS_LOG_FUNCTION (this);
180 
181  if (m_socket != 0)
182  {
184  }
185 
186  m_leasedAddresses.clear ();
188 }
189 
191 {
192  NS_LOG_FUNCTION (this);
193 
194  // Set up timeout events and release of unsolicited addresses from the list
196  for (i = m_leasedAddresses.begin (); i != m_leasedAddresses.end (); i++)
197  {
198  // update the address state
199  if (i->second.second != 0xffffffff && i->second.second != 0)
200  {
201  i->second.second--;
202  if (i->second.second == 0)
203  {
204  NS_LOG_INFO ("Address leased state expired, address removed - " <<
205  "chaddr: " << i->first <<
206  "IP address " << i->second.first);
207  i->second.second = 0;
208  m_expiredAddresses.push_front (i->first);
209  }
210  }
211  }
213 }
214 
216 {
217  NS_LOG_FUNCTION (this << socket);
218 
219  DhcpHeader header;
220  Ptr<Packet> packet = 0;
221  Address from;
222  packet = m_socket->RecvFrom (from);
223 
225 
226  Ipv4PacketInfoTag interfaceInfo;
227  if (!packet->RemovePacketTag (interfaceInfo))
228  {
229  NS_ABORT_MSG ("No incoming interface on DHCP message, aborting.");
230  }
231  uint32_t incomingIf = interfaceInfo.GetRecvIf ();
232  Ptr<NetDevice> iDev = GetNode ()->GetDevice (incomingIf);
233 
234  if (packet->RemoveHeader (header) == 0)
235  {
236  return;
237  }
238  if (header.GetType () == DhcpHeader::DHCPDISCOVER)
239  {
240  SendOffer (iDev, header, senderAddr);
241  }
242  if (header.GetType () == DhcpHeader::DHCPREQ && (header.GetReq ()).Get () >= m_minAddress.Get () && (header.GetReq ()).Get () <= m_maxAddress.Get ())
243  {
244  SendAck (iDev, header, senderAddr);
245  }
246 }
247 
249 {
250  NS_LOG_FUNCTION (this << iDev << header << from);
251 
252  DhcpHeader newDhcpHeader;
253  Address sourceChaddr = header.GetChaddr ();
254  uint32_t tran = header.GetTran ();
255  Ptr<Packet> packet = 0;
256  Ipv4Address offeredAddress;
257 
258  NS_LOG_INFO ("DHCP DISCOVER from: " << from.GetIpv4 () << " source port: " << from.GetPort ());
259 
260  LeasedAddressIter iter = m_leasedAddresses.find (sourceChaddr);
261  if (iter != m_leasedAddresses.end ())
262  {
263  // We know this client from some time ago
264  if (m_leasedAddresses[sourceChaddr].second != 0 && m_leasedAddresses[sourceChaddr].second != 0xffffffff)
265  {
266  NS_LOG_LOGIC ("This client is sending a DISCOVER but it has still a lease active - perhaps it didn't shut down gracefully: " << sourceChaddr);
267  }
268 
269  m_expiredAddresses.remove (sourceChaddr);
270  offeredAddress = m_leasedAddresses[sourceChaddr].first;
271 
272  }
273  else
274  {
275  // No previous record of the client, we must find a suitable address and create a record.
276  if (!m_availableAddresses.empty ())
277  {
278  // use an address never used before (if there is one)
279  offeredAddress = m_availableAddresses.front ();
280  m_availableAddresses.pop_front ();
281  }
282  else
283  {
284  // there's still hope: reuse the old ones.
285  if (!m_expiredAddresses.empty ())
286  {
287  Address oldestChaddr = m_expiredAddresses.back ();
288  m_expiredAddresses.pop_back ();
289  offeredAddress = m_leasedAddresses[oldestChaddr].first;
290  m_leasedAddresses.erase (oldestChaddr);
291  }
292  }
293  }
294 
295  if (offeredAddress != Ipv4Address ())
296  {
297  m_leasedAddresses[sourceChaddr] = std::make_pair (offeredAddress, m_lease.GetSeconds ());
298 
299  packet = Create<Packet> ();
300  newDhcpHeader.ResetOpt ();
301  newDhcpHeader.SetType (DhcpHeader::DHCPOFFER);
302  newDhcpHeader.SetChaddr (sourceChaddr);
303  newDhcpHeader.SetYiaddr (offeredAddress);
304 
305  Ptr<Ipv4> ipv4 = GetNode ()->GetObject<Ipv4> ();
306  Ipv4Address myAddress = ipv4->SelectSourceAddress (iDev, offeredAddress, Ipv4InterfaceAddress::InterfaceAddressScope_e::GLOBAL);
307 
308  newDhcpHeader.SetDhcps (myAddress);
309  newDhcpHeader.SetMask (m_poolMask.Get ());
310  newDhcpHeader.SetTran (tran);
311  newDhcpHeader.SetLease (m_lease.GetSeconds ());
312  newDhcpHeader.SetRenew (m_renew.GetSeconds ());
313  newDhcpHeader.SetRebind (m_rebind.GetSeconds ());
314  newDhcpHeader.SetTime ();
315  if (m_gateway != Ipv4Address ())
316  {
317  newDhcpHeader.SetRouter (m_gateway);
318  }
319  packet->AddHeader (newDhcpHeader);
320 
321  if ((m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), from.GetPort ()))) >= 0)
322  {
323  NS_LOG_INFO ("DHCP OFFER" << " Offered Address: " << offeredAddress);
324  }
325  else
326  {
327  NS_LOG_INFO ("Error while sending DHCP OFFER");
328  }
329  }
330 }
331 
333 {
334  NS_LOG_FUNCTION (this << iDev << header << from);
335 
336  DhcpHeader newDhcpHeader;
337  Address sourceChaddr = header.GetChaddr ();
338  uint32_t tran = header.GetTran ();
339  Ptr<Packet> packet = 0;
340  Ipv4Address address = header.GetReq ();
341 
342  NS_LOG_INFO ("DHCP REQUEST from: " << from.GetIpv4 () <<
343  " source port: " << from.GetPort () <<
344  " - refreshed addr: " << address);
345 
346  LeasedAddressIter iter;
347  iter = m_leasedAddresses.find (sourceChaddr);
348  if (iter != m_leasedAddresses.end ())
349  {
350  // update the lease time of this address - send ACK
351  (iter->second.second) += m_lease.GetSeconds ();
352  packet = Create<Packet> ();
353  newDhcpHeader.ResetOpt ();
354  newDhcpHeader.SetType (DhcpHeader::DHCPACK);
355  newDhcpHeader.SetChaddr (sourceChaddr);
356  newDhcpHeader.SetYiaddr (address);
357  newDhcpHeader.SetTran (tran);
358  newDhcpHeader.SetTime ();
359  packet->AddHeader (newDhcpHeader);
360  if (from.GetIpv4 () != address)
361  {
362  m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), from.GetPort ()));
363  }
364  else
365  {
366  m_socket->SendTo (packet, 0, from);
367  }
368  }
369  else
370  {
371  // Deleted or expired lease - send NACK
372  packet = Create<Packet> ();
373  newDhcpHeader.ResetOpt ();
374  newDhcpHeader.SetType (DhcpHeader::DHCPNACK);
375  newDhcpHeader.SetChaddr (sourceChaddr);
376  newDhcpHeader.SetYiaddr (address);
377  newDhcpHeader.SetTran (tran);
378  newDhcpHeader.SetTime ();
379  packet->AddHeader (newDhcpHeader);
380  if (from.GetIpv4 () != address)
381  {
382  m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255.255.255"), from.GetPort ()));
383  }
384  else
385  {
386  m_socket->SendTo (packet, 0, from);
387  }
388  NS_LOG_INFO ("IP addr does not exists or released!");
389  }
390 }
391 
393 {
394  NS_LOG_FUNCTION (this << chaddr << addr);
395  Address cleanedCaddr;
396 
397  NS_ASSERT_MSG (addr.Get () >= m_minAddress.Get () && addr.Get () <= m_maxAddress.Get (),
398  "Required address is not in the pool " << addr << " is not in [" << m_minAddress << ", " << m_maxAddress << "]");
399 
400  // We need to cleanup the type from the stored chaddr, or later we'll fail to compare it.
401  // Moreover, the length is always 16, because chaddr is 16 bytes.
402  uint8_t buffer[Address::MAX_SIZE];
403  std::memset (buffer, 0, Address::MAX_SIZE);
404  uint32_t len = chaddr.CopyTo (buffer);
405  NS_ASSERT_MSG (len <= 16, "DHCP server can not handle a chaddr larger than 16 bytes");
406  cleanedCaddr.CopyFrom (buffer, 16);
407 
408  NS_ASSERT_MSG (m_leasedAddresses.find (cleanedCaddr) == m_leasedAddresses.end (),
409  "Client has already an active lease: " << m_leasedAddresses[cleanedCaddr].first);
410 
411  AvailableAddress::iterator it = find (m_availableAddresses.begin (), m_availableAddresses.end (), addr);
412  NS_ASSERT_MSG (it == m_availableAddresses.end (),
413  "Required address is not available (perhaps it has been already assigned): " << addr);
414 
415  m_availableAddresses.remove (addr);
416  m_leasedAddresses[cleanedCaddr] = std::make_pair (addr, 0xffffffff);
417 }
418 
419 } // Namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:267
Ipv4Address m_minAddress
The first address in the address pool.
Definition: dhcp-server.h:114
Ptr< Socket > m_socket
The socket bound to port 67.
Definition: dhcp-server.h:112
AvailableAddress m_availableAddresses
Available addresses to be used (IP addresses)
Definition: dhcp-server.h:138
static TypeId GetTypeId(void)
Get the type ID.
Definition: dhcp-server.cc:49
an Inet address class
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 "...
Definition: second.py:1
Ptr< const AttributeAccessor > MakeIpv4MaskAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: ipv4-address.h:330
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#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
Ipv4Address m_maxAddress
The last address in the address pool.
Definition: dhcp-server.h:115
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
Code for DHCP NACK.
Definition: dhcp-header.h:123
void SetYiaddr(Ipv4Address addr)
Set the IPv4Address of the client.
Definition: dhcp-header.cc:133
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetTran(void) const
Get the transaction id.
Definition: dhcp-header.cc:102
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
Callback< R > MakeNullCallback(void)
Definition: callback.h:1635
uint8_t GetType(void) const
Return the type of DHCP message.
Definition: dhcp-header.cc:86
std::map< Address, std::pair< Ipv4Address, uint32_t > >::iterator LeasedAddressIter
Leased address iterator - chaddr + IP addr / lease time.
Definition: dhcp-server.h:122
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
Ipv4Address m_gateway
The gateway address.
Definition: dhcp-server.h:117
a polymophic address class
Definition: address.h:90
void AddStaticDhcpEntry(Address chaddr, Ipv4Address addr)
Add a static entry to the pool.
Definition: dhcp-server.cc:392
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:358
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
Ipv4Address m_poolAddress
The network address available to the server.
Definition: dhcp-server.h:113
void SetTran(uint32_t tran)
Set the transaction ID.
Definition: dhcp-header.cc:97
Time m_lease
The granted lease time for an address.
Definition: dhcp-server.h:139
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1375
void SendAck(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP ACK (or NACK) after receiving Request.
Definition: dhcp-server.cc:332
The base class for all ns3 applications.
Definition: application.h:60
AttributeValue implementation for Time.
Definition: nstime.h:1055
uint32_t Get(void) const
Get the host-order 32-bit IP address.
virtual void DoDispose(void)
Destructor implementation.
Definition: dhcp-server.cc:110
Ptr< const AttributeChecker > MakeIpv4AddressChecker(void)
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
Ptr< Node > GetNode() const
Definition: application.cc:104
Introspection did not find any typical Config paths.
Definition: dhcp-header.h:83
LeasedAddress m_leasedAddresses
Leased address and their status (cache memory)
Definition: dhcp-server.h:136
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:142
Time m_renew
The renewal time for an address.
Definition: dhcp-server.h:140
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
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
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
virtual void DoDispose(void)
Destructor implementation.
Definition: application.cc:83
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
static const int PORT
Port number of DHCP server.
Definition: dhcp-server.h:73
Ipv4Mask m_poolMask
The network mask of the pool.
Definition: dhcp-server.h:116
ExpiredAddress m_expiredAddresses
Expired addresses to be reused (chaddr of the clients)
Definition: dhcp-server.h:137
AttributeValue implementation for Ipv4Address.
Definition: ipv4-address.h:329
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:1056
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 BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
virtual void StartApplication(void)
Starts the DHCP Server application.
Definition: dhcp-server.cc:116
#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:90
void SetDhcps(Ipv4Address addr)
Set the DHCP server information.
Definition: dhcp-header.cc:143
Code for DHCP ACK.
Definition: dhcp-header.h:122
EventId m_expiredEvent
The Event to trigger TimerHandler.
Definition: dhcp-server.h:142
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
Time m_rebind
The rebinding time for an address.
Definition: dhcp-server.h:141
void SendOffer(Ptr< NetDevice > iDev, DhcpHeader header, InetSocketAddress from)
Sends DHCP offer after receiving DHCP Discover.
Definition: dhcp-server.cc:248
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:821
void TimerHandler(void)
Modifies the remaining lease time of addresses.
Definition: dhcp-server.cc:190
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
virtual ~DhcpServer()
Definition: dhcp-server.cc:104
AttributeValue implementation for Ipv4Mask.
Definition: ipv4-address.h:330
Ptr< const AttributeChecker > MakeIpv4MaskChecker(void)
void SetLease(uint32_t time)
Set the lease time of the IPv4Address.
Definition: dhcp-header.cc:203
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
uint32_t Get(void) const
Get the host-order 32-bit IP mask.
uint16_t GetPort(void) const
void SetRenew(uint32_t time)
Set the Renewal time of the IPv4Address.
Definition: dhcp-header.cc:218
virtual void StopApplication(void)
Stops the DHCP client application.
Definition: dhcp-server.cc:177
Code for DHCP Request.
Definition: dhcp-header.h:121
tuple address
Definition: first.py:37
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.
Ptr< const AttributeAccessor > MakeIpv4AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: ipv4-address.h:329
void SetMask(uint32_t addr)
Set the mask of the IPv4Address.
Definition: dhcp-header.cc:173
Ipv4Address GetReq(void) const
Get the IPv4Address requested by the client.
Definition: dhcp-header.cc:168
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
Definition: dhcp-server.cc:215
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
Code for DHCP Discover.
Definition: dhcp-header.h:119
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
void SetRouter(Ipv4Address addr)
Set the Ipv4Address of gateway to be used.
Definition: dhcp-header.cc:188
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:823
void SetRebind(uint32_t time)
Set the Rebind time of the IPv4Address.
Definition: dhcp-header.cc:233