Example to demonstrate the working of the Ping Application Network topology: More...
#include "ns3/core-module.h"#include "ns3/internet-apps-module.h"#include "ns3/internet-module.h"#include "ns3/network-module.h"#include "ns3/nix-vector-routing-module.h"#include "ns3/point-to-point-module.h"#include <fstream>#include <optional>Go to the source code of this file.
Example to demonstrate the working of the Ping Application Network topology:
A ------------------------------ B ------------------------------ C
100 Mbps 100 Mbps
5 ms (one way) 5 ms (one way)
IPv4 addresses:
10.1.1.1 <-> 10.1.1.2 / 10.1.2.1 <-> 10.1.2.2
IPv6 addresses:
2001:1::200:ff:fe00:1
<-> 2001:1::200:ff:fe00:2 / 2001:1:0:1:200:ff:fe00:3
<-> 2001:1:0:1:200:ff:fe00:4
The topology has three nodes interconnected by two point-to-point links. Each link has 5 ms one-way delay, for a round-trip propagation delay of 20 ms. The transmission rate on each link is 100 Mbps. The routing between links is enabled by ns-3's NixVector routing.
By default, this program will send 5 pings from node A to node C using IPv6. When using IPv6, the output will look like this:
PING 2001:1:0:1:200:ff:fe00:4 - 56 bytes of data; 104 bytes including ICMP and IPv6 headers. 64 bytes from (2001:1:0:1:200:ff:fe00:4): icmp_seq=0 ttl=63 time=20.033 ms 64 bytes from (2001:1:0:1:200:ff:fe00:4): icmp_seq=1 ttl=63 time=20.033 ms 64 bytes from (2001:1:0:1:200:ff:fe00:4): icmp_seq=2 ttl=63 time=20.033 ms 64 bytes from (2001:1:0:1:200:ff:fe00:4): icmp_seq=3 ttl=63 time=20.033 ms 64 bytes from (2001:1:0:1:200:ff:fe00:4): icmp_seq=4 ttl=63 time=20.033 ms --- 2001:1:0:1:200:ff:fe00:4 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4020ms rtt min/avg/max/mdev = 20/20/20/0 ms
When using IPv4, the output will look like this:
PING 10.1.2.2 - 56 bytes of data; 84 bytes including ICMP and IPv4 headers. 64 bytes from (10.1.2.2): icmp_seq=0 ttl=63 time=20.027 ms 64 bytes from (10.1.2.2): icmp_seq=1 ttl=63 time=20.027 ms 64 bytes from (10.1.2.2): icmp_seq=2 ttl=63 time=20.027 ms 64 bytes from (10.1.2.2): icmp_seq=3 ttl=63 time=20.027 ms 64 bytes from (10.1.2.2): icmp_seq=4 ttl=63 time=20.027 ms --- 10.1.2.2 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4020ms rtt min/avg/max/mdev = 20/20/20/0 ms
The example program will also produce four pcap traces (one for each NetDevice in the scenario) that can be viewed using tcpdump or Wireshark.
Other program options include options to change the destination and source addresses, number of packets (count), packet size, interval, and whether to enable logging (if logging is enabled in the build).
The Ping application in this example starts at simulation time 1 and will stop either at simulation time 50 or once 'Count' pings have been responded to, whichever comes first.
Definition in file ping-example.cc.