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. More... | |
typedef void(* | ReportTrace) (const PingReport &report) |
TracedCallback signature for Report trace. More... | |
typedef void(* | RttTrace) (uint16_t seq, Time rtt) |
TracedCallback signature for Rtt trace. More... | |
typedef void(* | TxTrace) (uint16_t seq, Ptr< const Packet > p) |
TracedCallback signature for Rtt trace. More... | |
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. More... | |
typedef void(* | StateTransitionCallback) (const std::string &oldState, const std::string &newState) |
Common signature used by callbacks to application's state transition trace source. More... | |
Public Member Functions | |
Ping () | |
Constructor. More... | |
~Ping () override | |
Destructor. More... | |
void | SetRouters (const std::vector< Ipv6Address > &routers) |
Set routers for IPv6 routing type 0 (loose routing). More... | |
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. More... | |
void | SetStopTime (Time stop) |
Specify application stop time. More... | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. More... | |
~Object () override | |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose () |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. More... | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. More... | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. More... | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. More... | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. More... | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. More... | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
bool | IsInitialized () const |
Check if the object has been initialized. More... | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Default constructor. More... | |
SimpleRefCount (const SimpleRefCount &o[[maybe_unused]]) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o[[maybe_unused]]) |
Assignment operator. More... | |
void | Ref () const |
Increment the reference count. More... | |
void | Unref () const |
Decrement the reference count. More... | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
Get the value of an attribute, raising fatal errors if unsuccessful. More... | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising errors. More... | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. More... | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. More... | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. More... | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. More... | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. More... | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. More... | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Application | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. More... | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Private Member Functions | |
void | DoDispose () override |
Destructor implementation. More... | |
uint64_t | GetApplicationSignature () const |
Return the application signatiure. More... | |
void | PrintReport () |
Print the report. More... | |
uint64_t | Read64 (const uint8_t *buffer) |
Writes data from a little-endian formatted buffer to data. More... | |
void | Receive (Ptr< Socket > socket) |
Receive an ICMPv4 or an ICMPv6 Echo reply. More... | |
void | Send () |
Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination. More... | |
void | StartApplication () override |
Application specific startup code. More... | |
void | StopApplication () override |
Application specific shutdown code. More... | |
void | Write64 (uint8_t *buffer, const uint64_t data) |
Writes data to buffer in little-endian format. More... | |
Private Attributes | |
uint64_t | m_appSignature {0} |
App signature: ID of the node where the app is installed || ID of the Application. More... | |
Average< double > | m_avgRtt |
Average rtt is ms. More... | |
uint32_t | m_count {0} |
Number of packets to be sent. More... | |
Address | m_destination |
Remote address. More... | |
TracedCallback< uint16_t, DropReason > | m_dropTrace |
TracedCallback for drop events. More... | |
uint32_t | m_duplicate {0} |
Duplicate packets counter. More... | |
Address | m_interfaceAddress |
Sender Local Address. More... | |
Time | m_interval {Seconds(1)} |
Wait interval between ECHO requests. More... | |
bool | m_multipleDestinations {false} |
Destination is Broadcast or Multicast. More... | |
EventId | m_next |
Next packet will be sent. More... | |
uint32_t | m_recv {0} |
Received packets counter. More... | |
bool | m_reportPrinted {false} |
True if the report has been printed already. More... | |
TracedCallback< const PingReport & > | m_reportTrace |
TracedCallback for final ping report. More... | |
std::vector< Ipv6Address > | m_routers |
Routers addresses for IPv6 routing type 0. More... | |
TracedCallback< uint16_t, Time > | m_rttTrace |
TracedCallback for RTT samples. More... | |
std::vector< EchoRequestData > | m_sent |
All sent but not answered packets. Map icmp seqno -> when sent, acked at least once. More... | |
uint16_t | m_seq {0} |
ICMP ECHO sequence number. More... | |
uint32_t | m_size {56} |
Specifies the number of data bytes to be sent. More... | |
Ptr< Socket > | m_socket |
The socket we send packets from. More... | |
Time | m_started |
Start time to report total ping time. More... | |
Time | m_timeout {Seconds(1)} |
Time to wait for a response, in seconds. More... | |
uint8_t | m_tos |
The Type of Service carried by ICMP ECHOs. More... | |
TracedCallback< uint16_t, Ptr< Packet > > | m_txTrace |
Callbacks for tracing the packet Tx events. More... | |
bool | m_useIpv6 {false} |
Use IPv4 (false) or IPv6 (true) More... | |
VerboseMode | m_verbose {VerboseMode::VERBOSE} |
Variable to stor verbose mode. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from ns3::Application | |
void | DoDispose () override |
Destructor implementation. More... | |
void | DoInitialize () override |
Initialize() implementation. More... | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. More... | |
virtual void | NotifyNewAggregate () |
Notify all Objects aggregated to this one of a new Object being aggregated. More... | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. More... | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. More... | |
Protected Attributes inherited from ns3::Application | |
Ptr< Node > | m_node |
The node that this application is installed on. More... | |
EventId | m_startEvent |
The event that will fire at m_startTime to start the application. More... | |
Time | m_startTime |
The simulation time that the application will start. More... | |
EventId | m_stopEvent |
The event that will fire at m_stopTime to end the application. More... | |
Time | m_stopTime |
The simulation time that the application will end. More... | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
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.
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 142 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 151 of file ping.cc.
References ns3::Node::GetApplication(), ns3::Node::GetId(), ns3::Node::GetNApplications(), 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_tos, m_txTrace, m_verbose, ns3::MakeEnumChecker(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::MakeTraceSourceAccessor(), ns3::MakeUintegerAccessor(), ns3::Seconds(), and ns3::TypeId::SetParent().
|
private |
Print the report.
Definition at line 645 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(), and ns3::Average< T >::Stddev().
Referenced by StopApplication().
|
private |
Writes data from a little-endian formatted buffer to data.
buffer | the buffer to read from |
Definition at line 400 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 172 of file ping.cc.
References ns3::Inet6SocketAddress::ConvertFrom(), ns3::InetSocketAddress::ConvertFrom(), ns3::Packet::CopyData(), two-ray-to-three-gpp-ch-calibration::delta, 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::Packet::GetSize(), 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::Packet::RemoveHeader(), ns3::Packet::RemovePacketTag(), ns3::Simulator::ScheduleNow(), StopApplication(), check-style-clang-format::type, and ns3::Average< T >::Update().
Referenced by StartApplication().
|
private |
Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination.
Definition at line 423 of file ping.cc.
References ns3::Packet::AddHeader(), ns3::Node::ChecksumEnabled(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Packet::Copy(), 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_tos, 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(), 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 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 526 of file ping.cc.
References ns3::Socket::Bind(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Socket::CreateSocket(), two-ray-to-three-gpp-ch-calibration::delta, 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, Receive(), Send(), ns3::ObjectBase::SetAttribute(), ns3::Socket::SetRecvCallback(), and ns3::Socket::SetRecvPktInfo().
|
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 626 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 385 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 280 of file ping.h.
Referenced by Receive(), Send(), and StartApplication().
|
private |
|
private |
Number of packets to be sent.
Definition at line 265 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 233 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 274 of file ping.h.
Referenced by Receive(), and StartApplication().
|
private |
Next packet will be sent.
Definition at line 239 of file ping.h.
Referenced by Send(), and StopApplication().
|
private |
Received packets counter.
Definition at line 231 of file ping.h.
Referenced by PrintReport(), and Receive().
|
private |
True if the report has been printed already.
Definition at line 270 of file ping.h.
Referenced by PrintReport(), and StartApplication().
|
private |
TracedCallback for final ping report.
Definition at line 227 of file ping.h.
Referenced by GetTypeId(), and PrintReport().
|
private |
Routers addresses for IPv6 routing type 0.
Definition at line 277 of file ping.h.
Referenced by Send(), and SetRouters().
|
private |
TracedCallback for RTT samples.
Definition at line 223 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 263 of file ping.h.
Referenced by Receive(), Send(), and StartApplication().
|
private |
ICMP ECHO sequence number.
Definition at line 219 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 235 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 268 of file ping.h.
Referenced by GetTypeId(), and Send().
|
private |
The Type of Service carried by ICMP ECHOs.
Definition at line 217 of file ping.h.
Referenced by GetTypeId(), and Send().
|
private |
Callbacks for tracing the packet Tx events.
Definition at line 221 of file ping.h.
Referenced by GetTypeId(), and Send().
|
private |
Use IPv4 (false) or IPv6 (true)
Definition at line 272 of file ping.h.
Referenced by Send(), and StartApplication().
|
private |
Variable to stor verbose mode.
Definition at line 229 of file ping.h.
Referenced by GetTypeId(), PrintReport(), Receive(), and StartApplication().