A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ping.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Chandrakant Jena
3 * Copyright (c) 2007-2009 Strasbourg University (original Ping6 code)
4 * Copyright (c) 2008 INRIA (original v4Ping code)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Chandrakant Jena <chandrakant.barcelona@gmail.com>
20 *
21 * Derived from original v4Ping application (author: Mathieu Lacage)
22 * Derived from original ping6 application (author: Sebastien Vincent)
23 */
24
25#ifndef PING_H
26#define PING_H
27
28#include "ns3/application.h"
29#include "ns3/average.h"
30#include "ns3/traced-callback.h"
31
32#include <map>
33
34namespace ns3
35{
36
37class Socket;
38
55class Ping : public Application
56{
57 public:
62 static TypeId GetTypeId();
63
69 {
70 VERBOSE = 0,
71 QUIET = 1,
72 SILENT = 2,
73 };
74
80 {
84 };
85
92 {
95 uint16_t m_loss{0};
97 double m_rttMin{0};
98 double m_rttAvg{0};
99 double m_rttMax{0};
100 double m_rttMdev{0};
101 };
102
106 Ping();
107
111 ~Ping() override;
112
117 void SetRouters(const std::vector<Ipv6Address>& routers);
118
125 typedef void (*TxTrace)(uint16_t seq, Ptr<const Packet> p);
126
133 typedef void (*RttTrace)(uint16_t seq, Time rtt);
134
141 typedef void (*DropTrace)(uint16_t seq, DropReason reason);
142
148 typedef void (*ReportTrace)(const PingReport& report);
149
150 private:
159 void Write64(uint8_t* buffer, const uint64_t data);
160
167 uint64_t Read64(const uint8_t* buffer);
168
169 // inherited from Application base class.
170 void StartApplication() override;
171 void StopApplication() override;
172 void DoDispose() override;
173
181 uint64_t GetApplicationSignature() const;
182
189 void Receive(Ptr<Socket> socket);
190
194 void Send();
195
199 void PrintReport();
200
207
217 uint16_t m_seq{0};
238
243 {
244 public:
250 EchoRequestData(Time txTimePar, bool ackedPar)
251 : txTime(txTimePar),
252 acked(ackedPar)
253 {
254 }
255
257 bool acked{false};
258 };
259
261 std::vector<EchoRequestData> m_sent;
268 bool m_reportPrinted{false};
270 bool m_useIpv6{false};
273
275 std::vector<Ipv6Address> m_routers;
276
278 uint64_t m_appSignature{0};
279};
280
281} // namespace ns3
282
283#endif /* PING_H */
a polymophic address class
Definition: address.h:100
The base class for all ns3 applications.
Definition: application.h:61
Simple average, min, max and std.
Definition: average.h:42
An identifier for simulation events.
Definition: event-id.h:55
Sent echo request data.
Definition: ping.h:243
EchoRequestData(Time txTimePar, bool ackedPar)
Constructor.
Definition: ping.h:250
bool acked
True if packet has been acknowledged.
Definition: ping.h:257
Time txTime
Tx time.
Definition: ping.h:256
This application behaves similarly to the Unix ping application, although with fewer options supporte...
Definition: ping.h:56
uint32_t m_size
Specifies the number of data bytes to be sent.
Definition: ping.h:213
uint32_t m_recv
Received packets counter.
Definition: ping.h:229
Time m_started
Start time to report total ping time.
Definition: ping.h:233
bool m_reportPrinted
True if the report has been printed already.
Definition: ping.h:268
std::vector< EchoRequestData > m_sent
All sent but not answered packets. Map icmp seqno -> when sent, acked at least once.
Definition: ping.h:261
uint64_t Read64(const uint8_t *buffer)
Writes data from a little-endian formatted buffer to data.
Definition: ping.cc:394
void(* RttTrace)(uint16_t seq, Time rtt)
TracedCallback signature for Rtt trace.
Definition: ping.h:133
void(* TxTrace)(uint16_t seq, Ptr< const Packet > p)
TracedCallback signature for Rtt trace.
Definition: ping.h:125
bool m_useIpv6
Use IPv4 (false) or IPv6 (true)
Definition: ping.h:270
VerboseMode
Encode three possible levels of verbose output.
Definition: ping.h:69
@ SILENT
Silent output (no terminal output at all)
Definition: ping.h:72
@ VERBOSE
Verbose output (similar to real ping output)
Definition: ping.h:70
@ QUIET
Quiet output (similar to real 'ping -q' output)
Definition: ping.h:71
void SetRouters(const std::vector< Ipv6Address > &routers)
Set routers for IPv6 routing type 0 (loose routing).
Definition: ping.cc:692
std::vector< Ipv6Address > m_routers
Routers addresses for IPv6 routing type 0.
Definition: ping.h:275
~Ping() override
Destructor.
Definition: ping.cc:130
TracedCallback< uint16_t, Ptr< Packet > > m_txTrace
Callbacks for tracing the packet Tx events.
Definition: ping.h:219
uint64_t m_appSignature
App signature: ID of the node where the app is installed || ID of the Application.
Definition: ping.h:278
uint32_t m_count
Number of packets to be sent.
Definition: ping.h:263
uint64_t GetApplicationSignature() const
Return the application signatiure.
Definition: ping.cc:145
void Send()
Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination.
Definition: ping.cc:417
void DoDispose() override
Destructor implementation.
Definition: ping.cc:136
void(* DropTrace)(uint16_t seq, DropReason reason)
TracedCallback signature for Drop trace.
Definition: ping.h:141
void StartApplication() override
Application specific startup code.
Definition: ping.cc:519
TracedCallback< const PingReport & > m_reportTrace
TracedCallback for final ping report.
Definition: ping.h:225
void StopApplication() override
Application specific shutdown code.
Definition: ping.cc:620
DropReason
Reason why a ping was dropped.
Definition: ping.h:80
@ DROP_TIMEOUT
Response timed out.
Definition: ping.h:81
@ DROP_NET_UNREACHABLE
Received ICMP Destination Network Unreachable.
Definition: ping.h:83
@ DROP_HOST_UNREACHABLE
Received ICMP Destination Host Unreachable.
Definition: ping.h:82
Average< double > m_avgRtt
Average rtt is ms.
Definition: ping.h:235
void PrintReport()
Print the report.
Definition: ping.cc:639
Ping()
Constructor.
Definition: ping.cc:125
Time m_interval
Wait interval between ECHO requests.
Definition: ping.h:206
static TypeId GetTypeId()
Get the type ID.
Definition: ping.cc:57
bool m_multipleDestinations
Destination is Broadcast or Multicast.
Definition: ping.h:272
uint16_t m_seq
ICMP ECHO sequence number.
Definition: ping.h:217
uint32_t m_duplicate
Duplicate packets counter.
Definition: ping.h:231
Address m_interfaceAddress
Sender Local Address.
Definition: ping.h:202
void Receive(Ptr< Socket > socket)
Receive an ICMPv4 or an ICMPv6 Echo reply.
Definition: ping.cc:166
void Write64(uint8_t *buffer, const uint64_t data)
Writes data to buffer in little-endian format.
Definition: ping.cc:379
Address m_destination
Remote address.
Definition: ping.h:204
EventId m_next
Next packet will be sent.
Definition: ping.h:237
Ptr< Socket > m_socket
The socket we send packets from.
Definition: ping.h:215
VerboseMode m_verbose
Variable to stor verbose mode.
Definition: ping.h:227
TracedCallback< uint16_t, DropReason > m_dropTrace
TracedCallback for drop events.
Definition: ping.h:223
Time m_timeout
Time to wait for a response, in seconds.
Definition: ping.h:266
void(* ReportTrace)(const PingReport &report)
TracedCallback signature for Report trace.
Definition: ping.h:148
TracedCallback< uint16_t, Time > m_rttTrace
TracedCallback for RTT samples.
Definition: ping.h:221
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]
A ping report provides all of the data that is typically output to the terminal when the application ...
Definition: ping.h:92
Time m_duration
Duration of the application.
Definition: ping.h:96
uint16_t m_loss
Percentage of lost packets (decimal value 0-100)
Definition: ping.h:95
double m_rttAvg
rtt avg value
Definition: ping.h:98
double m_rttMdev
rtt mdev value
Definition: ping.h:100
uint32_t m_received
Number of echo replies received.
Definition: ping.h:94
double m_rttMin
rtt min value
Definition: ping.h:97
uint32_t m_transmitted
Number of echo requests sent.
Definition: ping.h:93
double m_rttMax
rtt max value
Definition: ping.h:99