A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::Ping Class Reference

This application behaves similarly to the Unix ping application, although with fewer options supported. More...

#include "ping.h"

+ Inheritance diagram for ns3::Ping:
+ Collaboration diagram for ns3::Ping:

Classes

class  EchoRequestData
 Sent echo request data. More...
 
struct  PingReport
 A ping report provides all of the data that is typically output to the terminal when the application stops, including number sent and received and the RTT statistics. More...
 

Public Types

enum  DropReason { DROP_TIMEOUT = 0 , DROP_HOST_UNREACHABLE , DROP_NET_UNREACHABLE }
 Reason why a ping was dropped. More...
 
typedef void(* DropTrace) (uint16_t seq, DropReason reason)
 TracedCallback signature for Drop trace.
 
typedef void(* ReportTrace) (const PingReport &report)
 TracedCallback signature for Report trace.
 
typedef void(* RttTrace) (uint16_t seq, Time rtt)
 TracedCallback signature for Rtt trace.
 
typedef void(* TxTrace) (uint16_t seq, Ptr< const Packet > p)
 TracedCallback signature for Rtt trace.
 
enum  VerboseMode { VERBOSE = 0 , QUIET = 1 , SILENT = 2 }
 Encode three possible levels of verbose output. More...
 
- Public Types inherited from ns3::Application
typedef void(* DelayAddressCallback) (const Time &delay, const Address &from)
 Common callback signature for packet delay and address.
 
typedef void(* StateTransitionCallback) (const std::string &oldState, const std::string &newState)
 Common signature used by callbacks to application's state transition trace source.
 

Public Member Functions

 Ping ()
 Constructor.
 
 ~Ping () override
 Destructor.
 
void SetRouters (const std::vector< Ipv6Address > &routers)
 Set routers for IPv6 routing type 0 (loose routing).
 
- Public Member Functions inherited from ns3::Application
 Application ()
 
 ~Application () override
 
virtual int64_t AssignStreams (int64_t stream)
 Assign a fixed random variable stream number to the random variables used by this Application object.
 
Ptr< NodeGetNode () const
 
void SetNode (Ptr< Node > node)
 
void SetStartTime (Time start)
 Specify application start time.
 
void SetStopTime (Time stop)
 Specify application stop time.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Application
static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Protected Member Functions

void DoDispose () override
 Destructor implementation.
 
- Protected Member Functions inherited from ns3::Application
void DoInitialize () override
 Initialize() implementation.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Private Member Functions

uint64_t GetApplicationSignature () const
 Return the application signatiure.
 
void PrintReport ()
 Print the report.
 
uint64_t Read64 (const uint8_t *buffer)
 Writes data from a little-endian formatted buffer to data.
 
void Receive (Ptr< Socket > socket)
 Receive an ICMPv4 or an ICMPv6 Echo reply.
 
void Send ()
 Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination.
 
void StartApplication () override
 Application specific startup code.
 
void StopApplication () override
 Application specific shutdown code.
 
void Write64 (uint8_t *buffer, const uint64_t data)
 Writes data to buffer in little-endian format.
 

Private Attributes

uint64_t m_appSignature {0}
 App signature: ID of the node where the app is installed || ID of the Application.
 
Average< doublem_avgRtt
 Average rtt is ms.
 
uint32_t m_count {0}
 Number of packets to be sent.
 
Address m_destination
 Remote address.
 
TracedCallback< uint16_t, DropReasonm_dropTrace
 TracedCallback for drop events.
 
uint32_t m_duplicate {0}
 Duplicate packets counter.
 
Address m_interfaceAddress
 Sender Local Address.
 
Time m_interval {Seconds(1)}
 Wait interval between ECHO requests.
 
bool m_multipleDestinations {false}
 Destination is Broadcast or Multicast.
 
EventId m_next
 Next packet will be sent.
 
uint32_t m_recv {0}
 Received packets counter.
 
bool m_reportPrinted {false}
 True if the report has been printed already.
 
TracedCallback< const PingReport & > m_reportTrace
 TracedCallback for final ping report.
 
std::vector< Ipv6Addressm_routers
 Routers addresses for IPv6 routing type 0.
 
TracedCallback< uint16_t, Timem_rttTrace
 TracedCallback for RTT samples.
 
std::vector< EchoRequestDatam_sent
 All sent but not answered packets. Map icmp seqno -> when sent, acked at least once.
 
uint16_t m_seq {0}
 ICMP ECHO sequence number.
 
uint32_t m_size {56}
 Specifies the number of data bytes to be sent.
 
Ptr< Socketm_socket
 The socket we send packets from.
 
Time m_started
 Start time to report total ping time.
 
Time m_timeout {Seconds(1)}
 Time to wait for a response, in seconds.
 
uint8_t m_tos
 The Type of Service carried by ICMP ECHOs.
 
TracedCallback< uint16_t, Ptr< Packet > > m_txTrace
 Callbacks for tracing the packet Tx events.
 
bool m_useIpv6 {false}
 Use IPv4 (false) or IPv6 (true)
 
VerboseMode m_verbose {VerboseMode::VERBOSE}
 Variable to stor verbose mode.
 

Additional Inherited Members

- Protected Attributes inherited from ns3::Application
Ptr< Nodem_node
 The node that this application is installed on.
 
EventId m_startEvent
 The event that will fire at m_startTime to start the application.
 
Time m_startTime
 The simulation time that the application will start.
 
EventId m_stopEvent
 The event that will fire at m_stopTime to end the application.
 
Time m_stopTime
 The simulation time that the application will end.
 

Detailed Description

This application behaves similarly to the Unix ping application, although with fewer options supported.

The application can be used to send ICMP echo requests to unicast IPv4 and IPv6 addresses. The application can produce a verbose output similar to the real application, and can also export statistics via a trace source. The ping packet count, packet size, and interval between pings can be controlled via attributes of this class.

Definition at line 44 of file ping.h.

Member Typedef Documentation

◆ DropTrace

typedef void(* ns3::Ping::DropTrace) (uint16_t seq, DropReason reason)

TracedCallback signature for Drop trace.

Parameters
[in]seqThe ICMP sequence number
[in]reasonThe reason for the reported drop

Definition at line 130 of file ping.h.

◆ ReportTrace

typedef void(* ns3::Ping::ReportTrace) (const PingReport &report)

TracedCallback signature for Report trace.

Parameters
[in]reportThe report information

Definition at line 137 of file ping.h.

◆ RttTrace

typedef void(* ns3::Ping::RttTrace) (uint16_t seq, Time rtt)

TracedCallback signature for Rtt trace.

Parameters
[in]seqThe ICMP sequence number
[in]rttThe reported RTT

Definition at line 122 of file ping.h.

◆ TxTrace

typedef void(* ns3::Ping::TxTrace) (uint16_t seq, Ptr< const Packet > p)

TracedCallback signature for Rtt trace.

Parameters
[in]seqThe ICMP sequence number
[in]pThe ICMP echo request packet (including ICMP header)

Definition at line 114 of file ping.h.

Member Enumeration Documentation

◆ DropReason

Reason why a ping was dropped.

Enumerator
DROP_TIMEOUT 

Response timed out.

DROP_HOST_UNREACHABLE 

Received ICMP Destination Host Unreachable.

DROP_NET_UNREACHABLE 

Received ICMP Destination Network Unreachable.

Definition at line 68 of file ping.h.

◆ VerboseMode

Encode three possible levels of verbose output.

Enumerator
VERBOSE 

Verbose output (similar to real ping output)

QUIET 

Quiet output (similar to real 'ping -q' output)

SILENT 

Silent output (no terminal output at all)

Definition at line 57 of file ping.h.

Constructor & Destructor Documentation

◆ Ping()

ns3::Ping::Ping ( )

Constructor.

Definition at line 120 of file ping.cc.

References NS_LOG_FUNCTION.

◆ ~Ping()

ns3::Ping::~Ping ( )
override

Destructor.

Definition at line 125 of file ping.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ DoDispose()

void ns3::Ping::DoDispose ( )
overrideprotectedvirtual

Destructor implementation.

This method is called by Dispose() or by the Object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.

It is safe to call GetObject() from within this method.

Reimplemented from ns3::Application.

Definition at line 131 of file ping.cc.

References ns3::Application::DoDispose(), m_socket, NS_LOG_FUNCTION, and StopApplication().

+ Here is the call graph for this function:

◆ GetApplicationSignature()

uint64_t ns3::Ping::GetApplicationSignature ( ) const
private

Return the application signatiure.

Returns
the application signature.

The application signature is the NodeId concatenated with the application index in the node.

Definition at line 140 of file ping.cc.

References ns3::Node::GetId(), ns3::Application::GetNode(), NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by StartApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::Ping::GetTypeId ( )
static

◆ PrintReport()

◆ Read64()

uint64_t ns3::Ping::Read64 ( const uint8_t * buffer)
private

Writes data from a little-endian formatted buffer to data.

Parameters
bufferthe buffer to read from
Returns
the read data

Definition at line 389 of file ping.cc.

References data, and NS_LOG_FUNCTION.

Referenced by Receive().

+ Here is the caller graph for this function:

◆ Receive()

void ns3::Ping::Receive ( Ptr< Socket > socket)
private

Receive an ICMPv4 or an ICMPv6 Echo reply.

Parameters
socketthe receiving socket

This function is called by lower layers through a callback.

Definition at line 161 of file ping.cc.

References ns3::Inet6SocketAddress::ConvertFrom(), ns3::InetSocketAddress::ConvertFrom(), ns3::Ipv6PacketInfoTag::GetAddress(), ns3::Icmpv4Echo::GetData(), ns3::Icmpv4Echo::GetDataSize(), ns3::Ipv6Header::GetHopLimit(), ns3::Icmpv6Echo::GetId(), ns3::Icmpv4Echo::GetIdentifier(), ns3::InetSocketAddress::GetIpv4(), ns3::Inet6SocketAddress::GetIpv6(), ns3::Object::GetObject(), ns3::Socket::GetRxAvailable(), ns3::Icmpv6Echo::GetSeq(), ns3::Icmpv4Echo::GetSequenceNumber(), ns3::Ipv4Header::GetSerializedSize(), ns3::Ipv6Header::GetSerializedSize(), ns3::Ipv4Header::GetTtl(), ns3::Icmpv4Header::GetType(), ns3::Icmpv4Header::ICMPV4_DEST_UNREACH, ns3::Icmpv4Header::ICMPV4_ECHO_REPLY, ns3::Icmpv4Header::ICMPV4_TIME_EXCEEDED, ns3::Icmpv6Header::ICMPV6_ECHO_REPLY, ns3::Icmpv6Header::ICMPV6_ERROR_DESTINATION_UNREACHABLE, ns3::Icmpv6Header::ICMPV6_ERROR_TIME_EXCEEDED, ns3::Inet6SocketAddress::IsMatchingType(), ns3::InetSocketAddress::IsMatchingType(), m_appSignature, m_avgRtt, m_count, m_duplicate, m_multipleDestinations, ns3::Application::m_node, m_recv, m_rttTrace, m_sent, m_socket, m_verbose, ns3::Simulator::Now(), NS_ASSERT, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::PING_ID, Read64(), ns3::Socket::RecvFrom(), ns3::Simulator::ScheduleNow(), StopApplication(), ns3::Average< T >::Update(), and VERBOSE.

Referenced by StartApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Send()

void ns3::Ping::Send ( )
private

Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination.

Definition at line 412 of file ping.cc.

References ns3::Node::ChecksumEnabled(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Average< T >::Count(), ns3::Create(), data, ns3::Icmpv4Header::EnableChecksum(), ns3::Icmpv4Header::ICMPV4_ECHO, ns3::Ipv6Header::IPV6_EXT_ROUTING, ns3::Ipv6Header::IPV6_ICMPV6, m_appSignature, m_avgRtt, m_count, m_destination, m_interval, m_next, m_routers, m_sent, m_seq, m_size, m_socket, m_timeout, m_txTrace, m_useIpv6, ns3::Average< T >::Max(), ns3::MilliSeconds(), ns3::Simulator::Now(), NS_ASSERT_MSG, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::PING_ID, ns3::Simulator::Schedule(), Send(), ns3::Socket::SendTo(), ns3::ObjectBase::SetAttribute(), ns3::Icmpv4Header::SetCode(), ns3::Icmpv4Echo::SetData(), ns3::Icmpv6Echo::SetId(), ns3::Icmpv4Echo::SetIdentifier(), ns3::Ipv6ExtensionHeader::SetNextHeader(), ns3::Ipv6ExtensionLooseRoutingHeader::SetRoutersAddress(), ns3::Ipv6ExtensionRoutingHeader::SetSegmentsLeft(), ns3::Icmpv6Echo::SetSeq(), ns3::Icmpv4Echo::SetSequenceNumber(), ns3::Icmpv4Header::SetType(), ns3::Ipv6ExtensionRoutingHeader::SetTypeRouting(), StopApplication(), and Write64().

Referenced by Send(), and StartApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetRouters()

void ns3::Ping::SetRouters ( const std::vector< Ipv6Address > & routers)

Set routers for IPv6 routing type 0 (loose routing).

Parameters
routersrouters addresses

Definition at line 687 of file ping.cc.

References m_routers.

◆ StartApplication()

◆ StopApplication()

void ns3::Ping::StopApplication ( )
overrideprivatevirtual

Application specific shutdown code.

The StopApplication method is called at the stop time specified by Stop This method should be overridden by all or most application subclasses.

Reimplemented from ns3::Application.

Definition at line 615 of file ping.cc.

References ns3::EventId::Cancel(), ns3::Socket::Close(), ns3::EventId::IsPending(), m_next, m_socket, ns3::Application::m_stopEvent, NS_LOG_FUNCTION, and PrintReport().

Referenced by DoDispose(), Receive(), and Send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Write64()

void ns3::Ping::Write64 ( uint8_t * buffer,
const uint64_t data )
private

Writes data to buffer in little-endian format.

Least significant byte of data is at lowest buffer address

Parameters
[out]bufferthe buffer to write to
[in]datathe data to write

Definition at line 374 of file ping.cc.

References data, and NS_LOG_FUNCTION.

Referenced by Send().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_appSignature

uint64_t ns3::Ping::m_appSignature {0}
private

App signature: ID of the node where the app is installed || ID of the Application.

Definition at line 270 of file ping.h.

Referenced by Receive(), Send(), and StartApplication().

◆ m_avgRtt

Average<double> ns3::Ping::m_avgRtt
private

Average rtt is ms.

Definition at line 227 of file ping.h.

Referenced by PrintReport(), Receive(), and Send().

◆ m_count

uint32_t ns3::Ping::m_count {0}
private

Number of packets to be sent.

Definition at line 255 of file ping.h.

Referenced by GetTypeId(), Receive(), Send(), and StartApplication().

◆ m_destination

Address ns3::Ping::m_destination
private

Remote address.

Definition at line 194 of file ping.h.

Referenced by GetTypeId(), PrintReport(), Send(), and StartApplication().

◆ m_dropTrace

TracedCallback<uint16_t, DropReason> ns3::Ping::m_dropTrace
private

TracedCallback for drop events.

Definition at line 215 of file ping.h.

Referenced by GetTypeId().

◆ m_duplicate

uint32_t ns3::Ping::m_duplicate {0}
private

Duplicate packets counter.

Definition at line 223 of file ping.h.

Referenced by PrintReport(), and Receive().

◆ m_interfaceAddress

Address ns3::Ping::m_interfaceAddress
private

Sender Local Address.

Definition at line 192 of file ping.h.

Referenced by GetTypeId(), and StartApplication().

◆ m_interval

Time ns3::Ping::m_interval {Seconds(1)}
private

Wait interval between ECHO requests.

Definition at line 196 of file ping.h.

Referenced by GetTypeId(), Send(), and StartApplication().

◆ m_multipleDestinations

bool ns3::Ping::m_multipleDestinations {false}
private

Destination is Broadcast or Multicast.

Definition at line 264 of file ping.h.

Referenced by Receive(), and StartApplication().

◆ m_next

EventId ns3::Ping::m_next
private

Next packet will be sent.

Definition at line 229 of file ping.h.

Referenced by Send(), and StopApplication().

◆ m_recv

uint32_t ns3::Ping::m_recv {0}
private

Received packets counter.

Definition at line 221 of file ping.h.

Referenced by PrintReport(), and Receive().

◆ m_reportPrinted

bool ns3::Ping::m_reportPrinted {false}
private

True if the report has been printed already.

Definition at line 260 of file ping.h.

Referenced by PrintReport(), and StartApplication().

◆ m_reportTrace

TracedCallback<const PingReport&> ns3::Ping::m_reportTrace
private

TracedCallback for final ping report.

Definition at line 217 of file ping.h.

Referenced by GetTypeId(), and PrintReport().

◆ m_routers

std::vector<Ipv6Address> ns3::Ping::m_routers
private

Routers addresses for IPv6 routing type 0.

Definition at line 267 of file ping.h.

Referenced by Send(), and SetRouters().

◆ m_rttTrace

TracedCallback<uint16_t, Time> ns3::Ping::m_rttTrace
private

TracedCallback for RTT samples.

Definition at line 213 of file ping.h.

Referenced by GetTypeId(), and Receive().

◆ m_sent

std::vector<EchoRequestData> ns3::Ping::m_sent
private

All sent but not answered packets. Map icmp seqno -> when sent, acked at least once.

Definition at line 253 of file ping.h.

Referenced by Receive(), Send(), and StartApplication().

◆ m_seq

uint16_t ns3::Ping::m_seq {0}
private

ICMP ECHO sequence number.

Definition at line 209 of file ping.h.

Referenced by PrintReport(), and Send().

◆ m_size

uint32_t ns3::Ping::m_size {56}
private

Specifies the number of data bytes to be sent.

The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.

Definition at line 203 of file ping.h.

Referenced by GetTypeId(), Send(), and StartApplication().

◆ m_socket

Ptr<Socket> ns3::Ping::m_socket
private

The socket we send packets from.

Definition at line 205 of file ping.h.

Referenced by DoDispose(), Receive(), Send(), StartApplication(), and StopApplication().

◆ m_started

Time ns3::Ping::m_started
private

Start time to report total ping time.

Definition at line 225 of file ping.h.

Referenced by PrintReport(), and StartApplication().

◆ m_timeout

Time ns3::Ping::m_timeout {Seconds(1)}
private

Time to wait for a response, in seconds.

The option affects only timeout in absence of any responses, otherwise ping waits for two RTTs

Definition at line 258 of file ping.h.

Referenced by GetTypeId(), and Send().

◆ m_tos

uint8_t ns3::Ping::m_tos
private

The Type of Service carried by ICMP ECHOs.

Definition at line 207 of file ping.h.

Referenced by GetTypeId(), and StartApplication().

◆ m_txTrace

TracedCallback<uint16_t, Ptr<Packet> > ns3::Ping::m_txTrace
private

Callbacks for tracing the packet Tx events.

Definition at line 211 of file ping.h.

Referenced by GetTypeId(), and Send().

◆ m_useIpv6

bool ns3::Ping::m_useIpv6 {false}
private

Use IPv4 (false) or IPv6 (true)

Definition at line 262 of file ping.h.

Referenced by Send(), and StartApplication().

◆ m_verbose

VerboseMode ns3::Ping::m_verbose {VerboseMode::VERBOSE}
private

Variable to stor verbose mode.

Definition at line 219 of file ping.h.

Referenced by GetTypeId(), PrintReport(), Receive(), and StartApplication().


The documentation for this class was generated from the following files: