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"
46 .AddConstructor<DhcpClient> ()
47 .SetGroupName (
"Internet-Apps")
48 .AddAttribute (
"RTRS",
"Time for retransmission of Discover message",
52 .AddAttribute (
"Collect",
"Time for which offer collection starts",
56 .AddAttribute (
"ReRequest",
"Time after which request will be resent to next server",
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",
68 "ns3::Ipv4Address::TracedCallback")
69 .AddTraceSource (
"ExpireLease",
72 "ns3::Ipv4Address::TracedCallback");
164 uint32_t ifIndex = ipv4->GetInterfaceForDevice (
m_device);
172 uint32_t len = myAddress.
CopyTo (addr);
173 NS_ASSERT_MSG (len <= 16,
"DHCP client can not handle a chaddr larger than 16 bytes");
178 for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
180 if (ipv4->GetAddress (ifIndex, i).GetLocal () ==
m_myAddress)
225 int32_t ifIndex = ipv4->GetInterfaceForDevice (
m_device);
226 for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
228 if (ipv4->GetAddress (ifIndex,i).GetLocal () ==
m_myAddress)
230 ipv4->RemoveAddress (ifIndex, i);
265 int32_t ifIndex = ipv4MN->GetInterfaceForDevice (
m_device);
267 for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
269 if (ipv4MN->GetAddress (ifIndex,i).GetLocal () ==
m_myAddress)
271 ipv4MN->RemoveAddress (ifIndex, i);
279 for (i = 0; i < staticRouting->GetNRoutes (); i++)
281 if (staticRouting->GetRoute (i).GetGateway () ==
m_gateway)
283 staticRouting->RemoveRoute (i);
331 packet = Create<Packet> ();
398 packet = Create<Packet> ();
413 packet = Create<Packet> ((uint8_t*)&addr,
sizeof(addr));
445 int32_t ifIndex = ipv4->GetInterfaceForDevice (
m_device);
449 for (uint32_t i = 0; i < ipv4->GetNAddresses (ifIndex); i++)
451 if (ipv4->GetAddress (ifIndex,i).GetLocal () ==
m_myAddress)
454 ipv4->RemoveAddress (ifIndex, i);
460 ipv4->SetUp (ifIndex);
481 staticRouting->SetDefaultRoute (
m_gateway, ifIndex, 0);
503 int32_t ifIndex = ipv4MN->GetInterfaceForDevice (
m_device);
505 for (uint32_t i = 0; i < ipv4MN->GetNAddresses (ifIndex); i++)
507 if (ipv4MN->GetAddress (ifIndex,i).GetLocal () ==
m_myAddress)
509 ipv4MN->RemoveAddress (ifIndex, i);
517 for (i = 0; i < staticRouting->GetNRoutes (); i++)
519 if (staticRouting->GetRoute (i).GetGateway () ==
m_gateway)
521 staticRouting->RemoveRoute (i);
a polymophic address class
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
The base class for all ns3 applications.
virtual void DoDispose(void)
Destructor implementation.
Ptr< Node > GetNode() const
EventId m_requestEvent
Address refresh event.
Ipv4Address m_gateway
Address of the gateway.
Ipv4Mask m_myMask
Mask of the address assigned.
Time m_rebind
Store the rebind time of address.
void SetDhcpClientNetDevice(Ptr< NetDevice > netDevice)
Set the NetDevice DHCP should work on.
void Select(void)
Selects an OFFER from m_offerList.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
uint32_t m_tran
Stores the current transaction number to be used.
void RemoveAndStart()
Remove the current DHCP information and restart the process.
virtual void StopApplication(void)
Application specific shutdown code.
Ptr< Socket > m_socket
Socket for remote communication.
void LinkStateHandler(void)
Handles changes in LinkState.
bool m_firstBoot
First boot (used to add the link state change callback)
Time m_collect
Time for which client should collect offers.
Address m_chaddr
chaddr of the interface (stored as an Address for convenience).
@ WAIT_OFFER
State of a client that waits for the offer.
@ WAIT_ACK
State of a client that waits for acknowledgment.
@ REFRESH_LEASE
State of a client that needs to refresh the lease.
Ptr< NetDevice > m_device
NetDevice pointer.
EventId m_timeout
The timeout period.
virtual void DoDispose(void)
Destructor implementation.
Ptr< RandomVariableStream > m_ran
Uniform random variable for transaction ID.
EventId m_rebindEvent
Message rebind event.
static const int DHCP_PEER_PORT
DHCP server port.
std::list< DhcpHeader > m_offerList
Stores all the offers given to the client.
void Boot(void)
Sends DHCP DISCOVER and changes the client state to WAIT_OFFER.
Ipv4Address m_server
Address of the DHCP server.
EventId m_nextOfferEvent
Message next offer event.
bool m_offered
Specify if the client has got any offer.
void Request(void)
Sends the DHCP REQUEST message and changes the client state to WAIT_ACK.
Ipv4Address GetDhcpServer(void)
Get the IPv4Address of current DHCP server.
void OfferHandler(DhcpHeader header)
Stores DHCP offers in m_offerList.
TracedCallback< const Ipv4Address & > m_expiry
Trace of lease expire.
Ptr< NetDevice > GetDhcpClientNetDevice(void)
Get the the NetDevice DHCP should work on.
TracedCallback< const Ipv4Address & > m_newLease
Trace of new lease.
virtual void StartApplication(void)
Application specific startup code.
uint8_t m_state
State of the DHCP client.
EventId m_discoverEvent
Message retransmission event.
EventId m_refreshEvent
Message refresh event.
Ipv4Address m_myAddress
Address assigned to the client.
Time m_rtrs
Defining the time for retransmission.
Time m_nextoffer
Time to try the next offer (if request gets no reply)
Ipv4Address m_remoteAddress
Initially set to 255.255.255.255 to start DHCP.
void NetHandler(Ptr< Socket > socket)
Handles incoming packets from the network.
void AcceptAck(DhcpHeader header, Address from)
Receives the DHCP ACK and configures IP address of the client.
Ipv4Address m_offeredAddress
Address offered to the client.
Time m_renew
Store the renew time of address.
static TypeId GetTypeId(void)
Get the type ID.
EventId m_collectEvent
Offer collection event.
Time m_lease
Store the lease time of address.
An identifier for simulation events.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Ipv4Address GetIpv4(void) const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
uint32_t Get(void) const
Get the host-order 32-bit IP address.
static Ipv4Address GetAny(void)
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Helper class that adds ns3::Ipv4StaticRouting objects.
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...
virtual Address GetAddress(void) const =0
virtual void AddLinkChangeCallback(Callback< void > callback)=0
virtual bool IsLinkUp(void) const =0
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual int Close(void)=0
Close a socket.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
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...
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
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.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
Hold variables of type string.
AttributeValue implementation for Time.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Callback< R, Ts... > MakeNullCallback(void)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
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...