This application behaves similarly to the Unix ping application, although with fewer options supported. More...
#include "ping.h"
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 | |
Ptr< Node > | GetNode () 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< Object > | GetObject () 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< Object > | GetObject (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. | |
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. | |
SimpleRefCount & | operator= (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) 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. | |
virtual TypeId | GetInstanceTypeId () const =0 |
Get the most derived TypeId for this Object. | |
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. | |
Private Member Functions | |
void | DoDispose () override |
Destructor implementation. | |
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< double > | m_avgRtt |
Average rtt is ms. | |
uint32_t | m_count {0} |
Number of packets to be sent. | |
Address | m_destination |
Remote address. | |
TracedCallback< uint16_t, DropReason > | m_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< Ipv6Address > | m_routers |
Routers addresses for IPv6 routing type 0. | |
TracedCallback< uint16_t, Time > | m_rttTrace |
TracedCallback for RTT samples. | |
std::vector< EchoRequestData > | m_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< Socket > | m_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. | |
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 Member Functions inherited from ns3::Application | |
void | DoDispose () override |
Destructor implementation. | |
void | DoInitialize () override |
Initialize() implementation. | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. | |
virtual void | DoDispose () |
Destructor implementation. | |
virtual void | DoInitialize () |
Initialize() implementation. | |
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. | |
Protected Attributes inherited from ns3::Application | |
Ptr< Node > | m_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. | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
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.
ns3::Ping is accessible through the following paths with Config::Set and Config::Connect:
Address
Address
Time
+9.22337e+18ns:+9.22337e+18ns Time
+9.22337e+18ns:+9.22337e+18ns Verbose|Quiet|Silent
Time
+9.22337e+18ns:+9.22337e+18ns Time
+9.22337e+18ns:+9.22337e+18ns Size of this type is 584 bytes (on a 64-bit architecture).
typedef void(* ns3::Ping::DropTrace) (uint16_t seq, DropReason reason) |
TracedCallback signature for Drop trace.
[in] | seq | The ICMP sequence number |
[in] | reason | The reason for the reported drop |
typedef void(* ns3::Ping::ReportTrace) (const PingReport &report) |
TracedCallback signature for Report trace.
[in] | report | The report information |
typedef void(* ns3::Ping::RttTrace) (uint16_t seq, Time rtt) |
TracedCallback signature for Rtt trace.
[in] | seq | The ICMP sequence number |
[in] | rtt | The reported RTT |
TracedCallback signature for Rtt trace.
[in] | seq | The ICMP sequence number |
[in] | p | The ICMP echo request packet (including ICMP header) |
ns3::Ping::Ping | ( | ) |
|
override |
|
overrideprivatevirtual |
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::Object.
Definition at line 136 of file ping.cc.
References ns3::Application::DoDispose(), m_socket, NS_LOG_FUNCTION, and StopApplication().
|
private |
Return the application signatiure.
The application signature is the NodeId concatenated with the application index in the node.
Definition at line 145 of file ping.cc.
References ns3::Node::GetId(), ns3::Application::GetNode(), NS_ASSERT_MSG, and NS_LOG_FUNCTION.
Referenced by StartApplication().
|
static |
Get the type ID.
Definition at line 57 of file ping.cc.
References m_count, m_destination, m_dropTrace, m_interfaceAddress, m_interval, m_reportTrace, m_rttTrace, m_size, m_timeout, m_txTrace, m_verbose, ns3::MakeEnumAccessor(), ns3::MakeEnumChecker(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::MakeTraceSourceAccessor(), ns3::MakeUintegerAccessor(), QUIET, ns3::Seconds(), ns3::TypeId::SetParent(), SILENT, and VERBOSE.
|
private |
Print the report.
Definition at line 639 of file ping.cc.
References ns3::Average< T >::Avg(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Average< T >::Count(), ns3::InetSocketAddress::GetIpv4(), ns3::Inet6SocketAddress::GetIpv6(), ns3::Ipv4Address::IsMatchingType(), ns3::Ipv6Address::IsMatchingType(), m_avgRtt, m_destination, m_duplicate, ns3::Ping::PingReport::m_duration, ns3::Ping::PingReport::m_loss, ns3::Ping::PingReport::m_received, m_recv, m_reportPrinted, m_reportTrace, ns3::Ping::PingReport::m_rttAvg, ns3::Ping::PingReport::m_rttMax, ns3::Ping::PingReport::m_rttMdev, ns3::Ping::PingReport::m_rttMin, m_seq, m_started, ns3::Ping::PingReport::m_transmitted, m_verbose, ns3::Average< T >::Max(), ns3::Average< T >::Min(), ns3::Simulator::Now(), QUIET, ns3::Average< T >::Stddev(), and VERBOSE.
Referenced by StopApplication().
|
private |
Writes data from a little-endian formatted buffer to data.
buffer | the buffer to read from |
Definition at line 394 of file ping.cc.
References data, and NS_LOG_FUNCTION.
Referenced by Receive().
Receive an ICMPv4 or an ICMPv6 Echo reply.
socket | the receiving socket |
This function is called by lower layers through a callback.
Definition at line 166 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().
|
private |
Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination.
Definition at line 417 of file ping.cc.
References ns3::Node::ChecksumEnabled(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Average< T >::Count(), 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().
void ns3::Ping::SetRouters | ( | const std::vector< Ipv6Address > & | routers | ) |
|
overrideprivatevirtual |
Application specific startup code.
The StartApplication method is called at the start time specified by Start This method should be overridden by all or most application subclasses.
Reimplemented from ns3::Application.
Definition at line 519 of file ping.cc.
References ns3::Socket::Bind(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Socket::CreateSocket(), ns3::Div(), GetApplicationSignature(), ns3::InetSocketAddress::GetIpv4(), ns3::Inet6SocketAddress::GetIpv6(), ns3::Application::GetNode(), ns3::Ipv6Header::IPV6_ICMPV6, ns3::Ipv4Address::IsBroadcast(), ns3::Address::IsInvalid(), ns3::Ipv4Address::IsMatchingType(), ns3::Ipv6Address::IsMatchingType(), ns3::Ipv4Address::IsMulticast(), ns3::Ipv6Address::IsMulticast(), ns3::TypeId::LookupByName(), m_appSignature, m_count, m_destination, m_interfaceAddress, m_interval, m_multipleDestinations, m_reportPrinted, m_sent, m_size, m_socket, m_started, ns3::Application::m_stopTime, m_useIpv6, m_verbose, ns3::MakeCallback(), ns3::Now(), ns3::Simulator::Now(), NS_ABORT_MSG, NS_ASSERT_MSG, NS_LOG_FUNCTION, QUIET, Receive(), Send(), ns3::ObjectBase::SetAttribute(), ns3::Socket::SetRecvCallback(), ns3::Socket::SetRecvPktInfo(), and VERBOSE.
|
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 620 of file ping.cc.
References ns3::EventId::Cancel(), ns3::Socket::Close(), ns3::EventId::IsRunning(), m_next, m_socket, ns3::Application::m_stopEvent, NS_LOG_FUNCTION, and PrintReport().
Referenced by DoDispose(), Receive(), and Send().
|
private |
Writes data to buffer in little-endian format.
Least significant byte of data is at lowest buffer address
[out] | buffer | the buffer to write to |
[in] | data | the data to write |
Definition at line 379 of file ping.cc.
References data, and NS_LOG_FUNCTION.
Referenced by Send().
|
private |
App signature: ID of the node where the app is installed || ID of the Application.
Definition at line 278 of file ping.h.
Referenced by Receive(), Send(), and StartApplication().
|
private |
Number of packets to be sent.
Definition at line 263 of file ping.h.
Referenced by GetTypeId(), Receive(), Send(), and StartApplication().
|
private |
Remote address.
Definition at line 204 of file ping.h.
Referenced by GetTypeId(), PrintReport(), Send(), and StartApplication().
|
private |
|
private |
Duplicate packets counter.
Definition at line 231 of file ping.h.
Referenced by PrintReport(), and Receive().
|
private |
Definition at line 202 of file ping.h.
Referenced by GetTypeId(), and StartApplication().
Wait interval between ECHO requests.
Definition at line 206 of file ping.h.
Referenced by GetTypeId(), Send(), and StartApplication().
|
private |
Destination is Broadcast or Multicast.
Definition at line 272 of file ping.h.
Referenced by Receive(), and StartApplication().
|
private |
Next packet will be sent.
Definition at line 237 of file ping.h.
Referenced by Send(), and StopApplication().
|
private |
Received packets counter.
Definition at line 229 of file ping.h.
Referenced by PrintReport(), and Receive().
|
private |
True if the report has been printed already.
Definition at line 268 of file ping.h.
Referenced by PrintReport(), and StartApplication().
|
private |
TracedCallback for final ping report.
Definition at line 225 of file ping.h.
Referenced by GetTypeId(), and PrintReport().
|
private |
Routers addresses for IPv6 routing type 0.
Definition at line 275 of file ping.h.
Referenced by Send(), and SetRouters().
|
private |
TracedCallback for RTT samples.
Definition at line 221 of file ping.h.
Referenced by GetTypeId(), and Receive().
|
private |
All sent but not answered packets. Map icmp seqno -> when sent, acked at least once.
Definition at line 261 of file ping.h.
Referenced by Receive(), Send(), and StartApplication().
|
private |
ICMP ECHO sequence number.
Definition at line 217 of file ping.h.
Referenced by PrintReport(), and Send().
|
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 213 of file ping.h.
Referenced by GetTypeId(), Send(), and StartApplication().
The socket we send packets from.
Definition at line 215 of file ping.h.
Referenced by DoDispose(), Receive(), Send(), StartApplication(), and StopApplication().
|
private |
Start time to report total ping time.
Definition at line 233 of file ping.h.
Referenced by PrintReport(), and StartApplication().
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 266 of file ping.h.
Referenced by GetTypeId(), and Send().
|
private |
Callbacks for tracing the packet Tx events.
Definition at line 219 of file ping.h.
Referenced by GetTypeId(), and Send().
|
private |
Use IPv4 (false) or IPv6 (true)
Definition at line 270 of file ping.h.
Referenced by Send(), and StartApplication().
|
private |
Variable to stor verbose mode.
Definition at line 227 of file ping.h.
Referenced by GetTypeId(), PrintReport(), Receive(), and StartApplication().