18#include "ns3/assert.h"
19#include "ns3/boolean.h"
20#include "ns3/icmpv4.h"
21#include "ns3/inet-socket-address.h"
22#include "ns3/ipv4-address.h"
24#include "ns3/packet.h"
25#include "ns3/socket.h"
26#include "ns3/trace-source-accessor.h"
27#include "ns3/uinteger.h"
41 .SetGroupName(
"Internet-Apps")
43 .AddAttribute(
"Remote",
44 "The address of the machine we want to ping.",
47 MakeIpv4AddressChecker())
48 .AddAttribute(
"Verbose",
49 "Produce usual output.",
53 .AddAttribute(
"Interval",
54 "Wait interval seconds between sending each packet.",
59 "The number of data bytes to be sent, real packet will "
60 "be 8 (ICMP) + 20 (IP) bytes longer.",
63 MakeUintegerChecker<uint32_t>(16))
64 .AddTraceSource(
"Rtt",
65 "The rtt calculated by the ping.",
67 "ns3::Time::TracedCallback");
151 Read32((
const uint8_t*)&buf[0], nodeId);
152 Read32((
const uint8_t*)&buf[1], appId);
156 Time sendTime = i->second;
167 std::cout << recvSize <<
" bytes from " << realFrom.
GetIpv4() <<
":"
169 <<
" ttl=" << (unsigned)ipv4.
GetTtl()
186 buffer[0] = (
data >> 0) & 0xff;
187 buffer[1] = (
data >> 8) & 0xff;
188 buffer[2] = (
data >> 16) & 0xff;
189 buffer[3] = (
data >> 24) & 0xff;
197 data = (buffer[3] << 24) + (buffer[2] << 16) + (buffer[1] << 8) + buffer[0];
257 <<
" bytes including ICMP and IPv4 headers.\n";
291 std::ostringstream os;
293 os <<
"--- " <<
m_remote <<
" ping statistics ---\n"
294 <<
m_seq <<
" packets transmitted, " <<
m_recv <<
" received, "
303 std::cout << os.str();
a polymophic address class
The base class for all ns3 applications.
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
double Avg() const
Sample average.
T Min() const
Sample minimum.
T Max() const
Sample maximum.
void Update(const T &x)
Add new sample.
uint32_t Count() const
Sample size.
double Stddev() const
Sample standard deviation.
AttributeValue implementation for Boolean.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
uint32_t GetData(uint8_t payload[]) const
Get the Echo data.
void SetIdentifier(uint16_t id)
Set the Echo identifier.
void SetData(Ptr< const Packet > data)
Set the Echo data.
uint16_t GetIdentifier() const
Get the Echo identifier.
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
uint32_t GetDataSize() const
Get the Echo data size.
uint16_t GetSequenceNumber() const
Get the Echo sequence number.
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
static Ipv4Address GetAny()
AttributeValue implementation for Ipv4Address.
uint32_t GetNApplications() const
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
static bool ChecksumEnabled()
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
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 uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
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 Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Simulation virtual time values and global simulation resolution.
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
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.
Hold an unsigned integer type.
an application which sends one ICMP ECHO request, waits for a REPLYs and reports the calculated RTT.
void Read32(const uint8_t *buffer, uint32_t &data)
Writes data from a little-endian formatted buffer to data.
Average< double > m_avgRtt
Average rtt is ms.
bool m_verbose
produce ping-style output if true
EventId m_next
Next packet will be sent.
uint32_t m_size
Specifies the number of data bytes to be sent.
void StartApplication() override
Application specific startup code.
Ptr< Socket > m_socket
The socket we send packets from.
uint32_t m_recv
received packets counter
void StopApplication() override
Application specific shutdown code.
void Send()
Send one Ping (ICMP ECHO) to the destination.
Ipv4Address m_remote
Remote address.
uint16_t m_seq
ICMP ECHO sequence number.
void Write32(uint8_t *buffer, const uint32_t data)
Writes data to buffer in little-endian format.
void Receive(Ptr< Socket > socket)
Receive an ICMP Echo.
static TypeId GetTypeId()
Get the type ID.
V4Ping()
create a pinger applications
void DoDispose() override
Destructor implementation.
TracedCallback< Time > m_traceRtt
TracedCallback for RTT measured by ICMP ECHOs.
uint32_t GetApplicationId() const
Return the application ID in the node.
std::map< uint16_t, Time > m_sent
All sent but not answered packets. Map icmp seqno -> when sent.
Time m_interval
Wait interval seconds between sending each packet.
Time m_started
Start time to report total ping time.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#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 > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.