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