A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ping.cc
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 Ping code)
5 *
6 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 * Author: Chandrakant Jena <chandrakant.barcelona@gmail.com>
9 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
10 *
11 * Derived from original v4Ping application (author: Mathieu Lacage)
12 * Derived from original ping6 application (author: Sebastien Vincent)
13 */
14
15#include "ping.h"
16
17#include "ns3/abort.h"
18#include "ns3/assert.h"
19#include "ns3/boolean.h"
20#include "ns3/enum.h"
21#include "ns3/icmpv4.h"
22#include "ns3/icmpv6-header.h"
23#include "ns3/inet-socket-address.h"
24#include "ns3/ipv4-address.h"
25#include "ns3/ipv6-extension-header.h"
26#include "ns3/ipv6-header.h"
27#include "ns3/ipv6-l3-protocol.h"
28#include "ns3/ipv6-packet-info-tag.h"
29#include "ns3/log.h"
30#include "ns3/packet.h"
31#include "ns3/socket.h"
32#include "ns3/trace-source-accessor.h"
33#include "ns3/uinteger.h"
34
35namespace ns3
36{
37
39
41
42/// This value is used to quickly identify ECHO packets generated by this app.
43constexpr uint16_t PING_ID{0xbeef};
44
45TypeId
47{
48 static TypeId tid =
49 TypeId("ns3::Ping")
51 .SetGroupName("Internet-Apps")
52 .AddConstructor<Ping>()
53 .AddAttribute("Destination",
54 "The unicast IPv4 or IPv6 address of the machine we want to ping",
58 .AddAttribute("VerboseMode",
59 "Configure verbose, quiet, or silent output",
63 "Verbose",
65 "Quiet",
67 "Silent"))
68 .AddAttribute("Interval",
69 "Time interval between sending each packet",
73 .AddAttribute(
74 "Size",
75 "The number of data bytes to be sent, before ICMP and IP headers are added",
76 UintegerValue(56),
79 .AddAttribute(
80 "Count",
81 "The maximum number of packets the application will send (zero means no limits)",
85 .AddAttribute("InterfaceAddress",
86 "Local address of the sender",
90 .AddAttribute("Timeout",
91 "Time to wait for a response if no RTT samples are available",
95 .AddAttribute("Tos",
96 "The Type of Service used to send the ICMP Echo Requests. "
97 "All 8 bits of the TOS byte are set (including ECN bits).",
101 .AddTraceSource("Tx",
102 "The sequence number and ICMP echo response packet.",
104 "ns3::Ping::TxTrace")
105 .AddTraceSource("Rtt",
106 "The sequence number and RTT sample.",
108 "ns3::Ping::RttTrace")
109 .AddTraceSource("Drop",
110 "Drop events due to destination unreachable or other errors.",
112 "ns3::Ping::DropTrace")
113 .AddTraceSource("Report",
114 "Summary report at close of application.",
116 "ns3::Ping::ReportTrace");
117 return tid;
118}
119
121{
122 NS_LOG_FUNCTION(this);
123}
124
126{
127 NS_LOG_FUNCTION(this);
128}
129
130void
132{
133 NS_LOG_FUNCTION(this);
135 m_socket = nullptr;
137}
138
139uint64_t
141{
142 NS_LOG_FUNCTION(this);
143
144 uint64_t appSignature = GetNode()->GetId();
145 appSignature <<= 32;
146
147 Ptr<Node> node = GetNode();
148 for (uint32_t i = 0; i < node->GetNApplications(); ++i)
149 {
150 if (node->GetApplication(i) == this)
151 {
152 appSignature += i;
153 return appSignature;
154 }
155 }
156 NS_ASSERT_MSG(false, "forgot to add application to node");
157 return 0; // quiet compiler
158}
159
160void
162{
163 NS_LOG_FUNCTION(this << socket);
164
165 while (m_socket->GetRxAvailable() > 0)
166 {
167 Address from;
168 Ptr<Packet> packet = m_socket->RecvFrom(from);
169 uint32_t recvSize = packet->GetSize();
170 NS_LOG_DEBUG("recv " << recvSize << " bytes " << *packet);
171
173 {
175 Ipv4Header ipv4Hdr;
176 packet->RemoveHeader(ipv4Hdr);
177 recvSize -= ipv4Hdr.GetSerializedSize();
178 Icmpv4Header icmp;
179 packet->RemoveHeader(icmp);
180
181 switch (icmp.GetType())
182 {
184 Icmpv4Echo echo;
185 packet->RemoveHeader(echo);
186
187 if (echo.GetIdentifier() != PING_ID)
188 {
189 return;
190 }
191
192 NS_LOG_INFO("Received Echo Reply size = "
193 << std::dec << recvSize << " bytes from " << realFrom.GetIpv4()
194 << " id = " << echo.GetIdentifier()
195 << " seq = " << echo.GetSequenceNumber()
196 << " TTL = " << static_cast<uint16_t>(ipv4Hdr.GetTtl()));
197
198 uint32_t dataSize = echo.GetDataSize();
199 if (dataSize < 8)
200 {
201 NS_LOG_INFO("Packet too short, discarding");
202 return;
203 }
204 auto buf = new uint8_t[dataSize];
205 echo.GetData(buf);
206 uint64_t appSignature = Read64(buf);
207 delete[] buf;
208
209 if (appSignature == m_appSignature)
210 {
211 Time sendTime = m_sent.at(echo.GetSequenceNumber()).txTime;
212 NS_ASSERT(Simulator::Now() >= sendTime);
213 Time delta = Simulator::Now() - sendTime;
214
215 bool dupReply = false;
216 if (m_sent.at(echo.GetSequenceNumber()).acked)
217 {
218 m_duplicate++;
219 dupReply = true;
220 }
221 else
222 {
223 m_recv++;
224 m_sent.at(echo.GetSequenceNumber()).acked = true;
225 }
226
227 m_avgRtt.Update(delta.GetMilliSeconds());
228 m_rttTrace(echo.GetSequenceNumber(), delta);
229
231 {
232 std::cout << recvSize << " bytes from " << realFrom.GetIpv4() << ":"
233 << " icmp_seq=" << echo.GetSequenceNumber()
234 << " ttl=" << static_cast<uint16_t>(ipv4Hdr.GetTtl())
235 << " time=" << delta.GetMicroSeconds() / 1000.0 << " ms";
236 if (dupReply && !m_multipleDestinations)
237 {
238 std::cout << " (DUP!)";
239 }
240 std::cout << "\n";
241 }
242 }
243
244 break;
245 }
248 packet->RemoveHeader(destUnreach);
249
250 NS_LOG_INFO("Received Destination Unreachable from " << realFrom.GetIpv4());
251 break;
252 }
254 Icmpv4TimeExceeded timeExceeded;
255 packet->RemoveHeader(timeExceeded);
256
257 NS_LOG_INFO("Received Time Exceeded from " << realFrom.GetIpv4());
258 break;
259 }
260 default:
261 break;
262 }
263 }
265 {
267 Ipv6Header ipv6Hdr;
268
269 // We need the IP interface index.
270 Ipv6PacketInfoTag infoTag;
271 packet->RemovePacketTag(infoTag);
273 Ipv6Address myAddr = infoTag.GetAddress();
274 int32_t ipIfIndex = ipv6->GetInterfaceForAddress(myAddr);
275
276 packet->RemoveHeader(ipv6Hdr);
277 recvSize -= ipv6Hdr.GetSerializedSize();
278 uint8_t type;
279 packet->CopyData(&type, sizeof(type));
280
281 switch (type)
282 {
284 Icmpv6Echo echo(false);
285 packet->RemoveHeader(echo);
286
287 if (echo.GetId() != PING_ID)
288 {
289 return;
290 }
291
292 NS_LOG_INFO("Received Echo Reply size = "
293 << std::dec << recvSize << " bytes from " << realFrom.GetIpv6()
294 << " id = " << echo.GetId() << " seq = " << echo.GetSeq()
295 << " Hop Count = " << static_cast<uint16_t>(ipv6Hdr.GetHopLimit()));
296
297 uint32_t dataSize = packet->GetSize();
298 if (dataSize < 8)
299 {
300 NS_LOG_INFO("Packet too short, discarding");
301 return;
302 }
303 auto buf = new uint8_t[dataSize];
304 packet->CopyData(buf, dataSize);
305 uint64_t appSignature = Read64(buf);
306 delete[] buf;
307
308 if (appSignature == m_appSignature)
309 {
310 Time sendTime = m_sent.at(echo.GetSeq()).txTime;
311 NS_ASSERT(Simulator::Now() >= sendTime);
312 Time delta = Simulator::Now() - sendTime;
313
314 bool dupReply = false;
315 if (m_sent.at(echo.GetSeq()).acked)
316 {
317 m_duplicate++;
318 dupReply = true;
319 }
320 else
321 {
322 m_recv++;
323 m_sent.at(echo.GetSeq()).acked = true;
324 }
325
326 m_avgRtt.Update(delta.GetMilliSeconds());
327 m_rttTrace(echo.GetSeq(), delta);
328
330 {
331 std::cout << recvSize << " bytes from (" << realFrom.GetIpv6() << "):"
332 << " icmp_seq=" << echo.GetSeq()
333 << " ttl=" << static_cast<uint16_t>(ipv6Hdr.GetHopLimit())
334 << " time=" << delta.GetMicroSeconds() / 1000.0 << " ms";
335 if (dupReply)
336 {
337 std::cout << " (DUP!)";
338 }
339 std::cout << "\n";
340 }
341 }
342 ipv6->ReachabilityHint(ipIfIndex, realFrom.GetIpv6());
343 break;
344 }
347 packet->RemoveHeader(destUnreach);
348
349 NS_LOG_INFO("Received Destination Unreachable from " << realFrom.GetIpv6());
350 break;
351 }
353 Icmpv6TimeExceeded timeExceeded;
354 packet->RemoveHeader(timeExceeded);
355
356 NS_LOG_INFO("Received Time Exceeded from " << realFrom.GetIpv6());
357 break;
358 }
359 default:
360 break;
361 }
362 }
363 }
364
366 {
368 }
369}
370
371// Writes data to buffer in little-endian format; least significant byte
372// of data is at lowest buffer address
373void
374Ping::Write64(uint8_t* buffer, const uint64_t data)
375{
376 NS_LOG_FUNCTION(this << (void*)buffer << data);
377 buffer[0] = (data >> 0) & 0xff;
378 buffer[1] = (data >> 8) & 0xff;
379 buffer[2] = (data >> 16) & 0xff;
380 buffer[3] = (data >> 24) & 0xff;
381 buffer[4] = (data >> 32) & 0xff;
382 buffer[5] = (data >> 40) & 0xff;
383 buffer[6] = (data >> 48) & 0xff;
384 buffer[7] = (data >> 56) & 0xff;
385}
386
387// Read data from a little-endian formatted buffer to data
388uint64_t
389Ping::Read64(const uint8_t* buffer)
390{
391 NS_LOG_FUNCTION(this << (void*)buffer);
392 uint64_t data = buffer[7];
393 data <<= 8;
394 data |= buffer[6];
395 data <<= 8;
396 data |= buffer[5];
397 data <<= 8;
398 data |= buffer[4];
399 data <<= 8;
400 data |= buffer[3];
401 data <<= 8;
402 data |= buffer[2];
403 data <<= 8;
404 data |= buffer[1];
405 data <<= 8;
406 data |= buffer[0];
407
408 return data;
409}
410
411void
413{
414 NS_LOG_FUNCTION(this);
415
416 NS_LOG_INFO("m_seq=" << m_seq);
417
418 // Prepare the payload.
419 // We must write quantities out in some form of network order. Since there
420 // isn't an htonl to work with we just follow the convention in pcap traces
421 // (where any difference would show up anyway) and borrow that code. Don't
422 // be too surprised when you see that this is a little endian convention.
423 //
424 auto data = new uint8_t[m_size];
425 memset(data, 0, m_size);
426 NS_ASSERT_MSG(m_size >= 16, "ECHO Payload size must be at least 16 bytes");
427
429 Ptr<Packet> dataPacket = Create<Packet>(data, m_size);
430
432 int returnValue = 0;
433
434 if (!m_useIpv6)
435 {
436 // Using IPv4
437 Icmpv4Echo echo;
440
441 // In the Icmpv4Echo the payload is part of the header.
442 echo.SetData(dataPacket);
443
444 p->AddHeader(echo);
445 Icmpv4Header header;
447 header.SetCode(0);
449 {
450 header.EnableChecksum();
451 }
452 p->AddHeader(header);
454 returnValue = m_socket->SendTo(p, 0, dest);
455 }
456 else
457 {
458 // Using IPv6
459 Icmpv6Echo echo(true);
460
461 echo.SetSeq(m_seq);
462 echo.SetId(PING_ID);
463
464 // In the Icmpv6Echo the payload is just the content of the packet.
465 p = dataPacket->Copy();
466
467 p->AddHeader(echo);
468
469 /* use Loose Routing (routing type 0) */
470 if (!m_routers.empty())
471 {
474 routingHeader.SetTypeRouting(0);
475 routingHeader.SetSegmentsLeft(m_routers.size());
476 routingHeader.SetRoutersAddress(m_routers);
477 p->AddHeader(routingHeader);
479 }
480
481 returnValue =
483
484 // Loose routing could have changed (temporarily) the protocol. Set it again to receive the
485 // replies.
487 }
488 if (returnValue > 0)
489 {
490 m_sent.emplace_back(Simulator::Now(), false);
491 m_txTrace(m_seq, p);
492 }
493 else
494 {
495 NS_LOG_INFO("Send failure; socket return value: " << returnValue);
496 }
497 m_seq++;
498 delete[] data;
499
500 if (m_count == 0 || m_seq < m_count)
501 {
503 }
504
505 // We have sent all the requests. Schedule a shutdown after the linger time
506 if (m_count > 0 && m_seq == m_count)
507 {
508 Time lingerTime = m_avgRtt.Count() > 0 ? MilliSeconds(2 * m_avgRtt.Max()) : m_timeout;
509 Simulator::Schedule(lingerTime, &Ping::StopApplication, this);
510 }
511}
512
513void
515{
516 NS_LOG_FUNCTION(this);
517
519 {
520 NS_ABORT_MSG("Destination Address value must be set when starting application");
521 }
522
524
526 m_reportPrinted = false;
528 {
530 {
532 std::cout << "PING " << realFrom.GetIpv4() << " - " << m_size << " bytes of data; "
533 << m_size + 28 << " bytes including ICMP and IPv4 headers.\n";
534 }
536 {
538 std::cout << "PING " << realFrom.GetIpv6() << " - " << m_size << " bytes of data; "
539 << m_size + 48 << " bytes including ICMP and IPv6 headers.\n";
540 }
541 else
542 {
543 NS_ABORT_MSG("Invalid Address");
544 }
545 }
546
548 {
549 m_socket =
550 Socket::CreateSocket(GetNode(), TypeId::LookupByName("ns3::Ipv4RawSocketFactory"));
551 NS_ASSERT_MSG(m_socket, "Ping::StartApplication: can not create socket.");
552 m_socket->SetAttribute("Protocol", UintegerValue(1)); // icmp
555 m_useIpv6 = false;
556
559 }
561 {
562 m_socket =
563 Socket::CreateSocket(GetNode(), TypeId::LookupByName("ns3::Ipv6RawSocketFactory"));
564 NS_ASSERT_MSG(m_socket, "Ping::StartApplication: can not create socket.");
568 m_useIpv6 = true;
569
572 }
573 else
574 {
575 NS_ABORT_MSG("Destination Address value must be of type Ipv4 or Ipv6");
576 }
577
579 {
581 {
583 int status = m_socket->Bind(senderInet);
584 NS_ASSERT_MSG(status == 0, "Failed to bind IPv4 socket");
585 }
587 {
588 Inet6SocketAddress senderInet =
590 int status = m_socket->Bind(senderInet);
591 NS_ASSERT_MSG(status == 0, "Failed to bind IPv6 socket");
592 }
593 else
594 {
595 NS_ABORT_MSG("Sender Address value must be of type Ipv4 or Ipv6");
596 }
597 }
598
599 // Guess how large should be the data storage and pre-book it.
600 if (m_count == 0)
601 {
602 Time delta = m_stopTime - Now();
603 int64_t guessedTx = Div(delta, m_interval) + 1;
604 m_sent.reserve(guessedTx);
605 }
606 else
607 {
608 m_sent.reserve(m_count);
609 }
610
611 Send();
612}
613
614void
616{
617 NS_LOG_FUNCTION(this);
619 {
621 }
622 if (m_next.IsPending())
623 {
624 m_next.Cancel();
625 }
626 if (m_socket)
627 {
628 m_socket->Close();
629 }
630 PrintReport();
631}
632
633void
635{
636 if (m_reportPrinted)
637 {
638 return;
639 }
640 m_reportPrinted = true;
641
643 {
644 std::ostringstream os;
645 os.precision(4);
647 {
649 os << "\n--- " << realFrom.GetIpv4() << " ping statistics ---\n";
650 }
652 {
654 os << "\n--- " << realFrom.GetIpv6() << " ping statistics ---\n";
655 }
656 os << m_seq << " packets transmitted, " << m_recv << " received, ";
657 if (m_duplicate)
658 {
659 os << m_duplicate << " duplicates, ";
660 }
661
662 // note: integer math to match Linux implementation and avoid turning a 99.9% into a 100%.
663 os << ((m_seq - m_recv) * 100 / m_seq) << "% packet loss, "
664 << "time " << (Simulator::Now() - m_started).GetMilliSeconds() << "ms\n";
665
666 if (m_avgRtt.Count() > 0)
667 {
668 os << "rtt min/avg/max/mdev = " << m_avgRtt.Min() << "/" << m_avgRtt.Avg() << "/"
669 << m_avgRtt.Max() << "/" << m_avgRtt.Stddev() << " ms\n";
670 }
671 std::cout << os.str();
672 }
673 PingReport report;
674 report.m_transmitted = m_seq;
675 report.m_received = m_recv;
676 // note: integer math to match Linux implementation and avoid turning a 99.9% into a 100%.
677 report.m_loss = (m_seq - m_recv) * 100 / m_seq;
678 report.m_duration = (Simulator::Now() - m_started);
679 report.m_rttMin = m_avgRtt.Min();
680 report.m_rttAvg = m_avgRtt.Avg();
681 report.m_rttMax = m_avgRtt.Max();
682 report.m_rttMdev = m_avgRtt.Stddev();
683 m_reportTrace(report);
684}
685
686void
687Ping::SetRouters(const std::vector<Ipv6Address>& routers)
688{
689 m_routers = routers;
690}
691
692} // namespace ns3
a polymophic address class
Definition address.h:90
bool IsInvalid() const
Definition address.cc:60
AttributeValue implementation for Address.
Definition address.h:275
The base class for all ns3 applications.
Definition application.h:51
void DoDispose() override
Destructor implementation.
Time m_stopTime
The simulation time that the application will end.
EventId m_stopEvent
The event that will fire at m_stopTime to end the application.
Ptr< Node > GetNode() const
Ptr< Node > m_node
The node that this application is installed on.
double Avg() const
Sample average.
Definition average.h:97
T Min() const
Sample minimum.
Definition average.h:79
T Max() const
Sample maximum.
Definition average.h:88
void Update(const T &x)
Add new sample.
Definition average.h:45
uint32_t Count() const
Sample size.
Definition average.h:70
double Stddev() const
Sample standard deviation.
Definition average.h:124
Hold variables of type enum.
Definition enum.h:52
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
ICMP Destination Unreachable header.
Definition icmpv4.h:164
ICMP Echo header.
Definition icmpv4.h:99
uint32_t GetData(uint8_t payload[]) const
Get the Echo data.
Definition icmpv4.cc:196
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition icmpv4.cc:139
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition icmpv4.cc:153
uint16_t GetIdentifier() const
Get the Echo identifier.
Definition icmpv4.cc:175
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition icmpv4.cc:146
uint32_t GetDataSize() const
Get the Echo data size.
Definition icmpv4.cc:189
uint16_t GetSequenceNumber() const
Get the Echo sequence number.
Definition icmpv4.cc:182
Base class for all the ICMP packet headers.
Definition icmpv4.h:32
void SetCode(uint8_t code)
Set ICMP code.
Definition icmpv4.cc:112
void SetType(uint8_t type)
Set ICMP type.
Definition icmpv4.cc:105
void EnableChecksum()
Enables ICMP Checksum calculation.
Definition icmpv4.cc:49
uint8_t GetType() const
Get ICMP type.
Definition icmpv4.cc:119
ICMP Time Exceeded header.
Definition icmpv4.h:239
ICMPv6 Error Destination Unreachable header.
ICMPv6 Echo message.
void SetId(uint16_t id)
Set the ID of the packet.
uint16_t GetId() const
Get the ID of the packet.
void SetSeq(uint16_t seq)
Set the sequence number.
uint16_t GetSeq() const
Get the sequence number.
@ ICMPV6_ERROR_DESTINATION_UNREACHABLE
ICMPv6 Error Time Exceeded header.
An Inet6 address class.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
an Inet address class
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
bool IsMulticast() const
static Ipv4Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
bool IsBroadcast() const
Packet header for IPv4.
Definition ipv4-header.h:23
uint32_t GetSerializedSize() const override
uint8_t GetTtl() const
Describes an IPv6 address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
void SetNextHeader(uint8_t nextHeader)
Set the "Next header" field.
Header of IPv6 Extension Routing : Type 0 (Loose Routing)
void SetRoutersAddress(std::vector< Ipv6Address > routersAddress)
Set the vector of routers' address.
void SetTypeRouting(uint8_t typeRouting)
Set the "Type of Routing" field.
void SetSegmentsLeft(uint8_t segmentsLeft)
Set the "Segments left" field.
Packet header for IPv6.
Definition ipv6-header.h:24
uint8_t GetHopLimit() const
Get the "Hop limit" field (TTL).
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
IPv6 layer implementation.
This class implements a tag that carries socket ancillary data to the socket interface.
Ipv6Address GetAddress() const
Get the tag's address.
uint32_t GetId() const
Definition node.cc:106
static bool ChecksumEnabled()
Definition node.cc:267
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
This application behaves similarly to the Unix ping application, although with fewer options supporte...
Definition ping.h:45
uint32_t m_size
Specifies the number of data bytes to be sent.
Definition ping.h:203
uint32_t m_recv
Received packets counter.
Definition ping.h:221
Time m_started
Start time to report total ping time.
Definition ping.h:225
bool m_reportPrinted
True if the report has been printed already.
Definition ping.h:260
std::vector< EchoRequestData > m_sent
All sent but not answered packets. Map icmp seqno -> when sent, acked at least once.
Definition ping.h:253
uint64_t Read64(const uint8_t *buffer)
Writes data from a little-endian formatted buffer to data.
Definition ping.cc:389
bool m_useIpv6
Use IPv4 (false) or IPv6 (true)
Definition ping.h:262
@ SILENT
Silent output (no terminal output at all)
Definition ping.h:61
@ VERBOSE
Verbose output (similar to real ping output)
Definition ping.h:59
@ QUIET
Quiet output (similar to real 'ping -q' output)
Definition ping.h:60
void SetRouters(const std::vector< Ipv6Address > &routers)
Set routers for IPv6 routing type 0 (loose routing).
Definition ping.cc:687
std::vector< Ipv6Address > m_routers
Routers addresses for IPv6 routing type 0.
Definition ping.h:267
~Ping() override
Destructor.
Definition ping.cc:125
TracedCallback< uint16_t, Ptr< Packet > > m_txTrace
Callbacks for tracing the packet Tx events.
Definition ping.h:211
uint64_t m_appSignature
App signature: ID of the node where the app is installed || ID of the Application.
Definition ping.h:270
uint32_t m_count
Number of packets to be sent.
Definition ping.h:255
uint64_t GetApplicationSignature() const
Return the application signatiure.
Definition ping.cc:140
void Send()
Send one Ping (ICMPv4 ECHO or ICMPv6 ECHO) to the destination.
Definition ping.cc:412
void DoDispose() override
Destructor implementation.
Definition ping.cc:131
void StartApplication() override
Application specific startup code.
Definition ping.cc:514
TracedCallback< const PingReport & > m_reportTrace
TracedCallback for final ping report.
Definition ping.h:217
void StopApplication() override
Application specific shutdown code.
Definition ping.cc:615
Average< double > m_avgRtt
Average rtt is ms.
Definition ping.h:227
void PrintReport()
Print the report.
Definition ping.cc:634
Ping()
Constructor.
Definition ping.cc:120
Time m_interval
Wait interval between ECHO requests.
Definition ping.h:196
static TypeId GetTypeId()
Get the type ID.
Definition ping.cc:46
bool m_multipleDestinations
Destination is Broadcast or Multicast.
Definition ping.h:264
uint16_t m_seq
ICMP ECHO sequence number.
Definition ping.h:209
uint32_t m_duplicate
Duplicate packets counter.
Definition ping.h:223
Address m_interfaceAddress
Sender Local Address.
Definition ping.h:192
void Receive(Ptr< Socket > socket)
Receive an ICMPv4 or an ICMPv6 Echo reply.
Definition ping.cc:161
uint8_t m_tos
The Type of Service carried by ICMP ECHOs.
Definition ping.h:207
void Write64(uint8_t *buffer, const uint64_t data)
Writes data to buffer in little-endian format.
Definition ping.cc:374
Address m_destination
Remote address.
Definition ping.h:194
EventId m_next
Next packet will be sent.
Definition ping.h:229
Ptr< Socket > m_socket
The socket we send packets from.
Definition ping.h:205
VerboseMode m_verbose
Variable to stor verbose mode.
Definition ping.h:219
TracedCallback< uint16_t, DropReason > m_dropTrace
TracedCallback for drop events.
Definition ping.h:215
Time m_timeout
Time to wait for a response, in seconds.
Definition ping.h:258
TracedCallback< uint16_t, Time > m_rttTrace
TracedCallback for RTT samples.
Definition ping.h:213
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:594
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition socket.cc:423
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.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition socket.cc:343
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition socket.cc:117
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...
Definition socket.cc:61
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
AttributeValue implementation for Time.
Definition nstime.h:1395
a unique identifier for an interface.
Definition type-id.h:48
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:872
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Ptr< const AttributeChecker > MakeAddressChecker()
Definition address.cc:169
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition address.h:275
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition enum.h:221
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
int64_t Div(const Length &numerator, const Length &denominator, Length *remainder)
Calculate how many times numerator can be split into denominator sized pieces.
Definition length.cc:471
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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.
constexpr uint16_t PING_ID
This value is used to quickly identify ECHO packets generated by this app.
Definition ping.cc:43
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...
Definition callback.h:684
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:179
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:81
Time m_duration
Duration of the application.
Definition ping.h:85
uint16_t m_loss
Percentage of lost packets (decimal value 0-100)
Definition ping.h:84
double m_rttAvg
rtt avg value
Definition ping.h:87
double m_rttMdev
rtt mdev value
Definition ping.h:89
uint32_t m_received
Number of echo replies received.
Definition ping.h:83
double m_rttMin
rtt min value
Definition ping.h:86
uint32_t m_transmitted
Number of echo requests sent.
Definition ping.h:82
double m_rttMax
rtt max value
Definition ping.h:88