How does the ping implementation calculate round-trip time?

I found out about the implementation of ping.

I had one doubt about this. Confidence in how they calculate round-trip time.

They made some calculations to calculate round-trip time. I can not understand this calculation.

Here is the code for calculating round-trip time.

tsum += triptime; tsum2 += (long long)triptime * (long long)triptime; if (triptime < tmin) tmin = triptime; if (triptime > tmax) tmax = triptime; if (!rtt) rtt = triptime*8; else rtt += triptime-rtt/8; 

The variables tsum, tsum2, triptime, tmax are initially equal to 0. The value of tmin contains the value as 2147483647 as originally. The triptime event is evaluated before sending a packet marked once. At the destination, the packet is received, before it sends a replay, it will notice one time, and it will fill it in the response packet and send the response. Subtracted two times and convert this subtracted time into microseconds. The triptime variable contains microseconds.

For example, take the bottom output to calculate rtt.

The shutdown time for the first packet is 42573, and the second packet 43707, the third packet 48047 and the fourth packet 42559.

Using this, how they calculate round-trip time. Why they are multiplied with 8 at the beginning and after that they are divided by 8 and subtracted with the first rtt. I can not find why they calculate rtt like this. Can someone explain to me why they multiply with 8 at the beginning, and after that they divide by 8 and subtract with the calculated rtt. The link below contains the full ping implementation code.

ping_common.c

ping.c

Thanks in advance.

+5
source share
3 answers

rtt Modified moving average of triptime values, multiplied by 8 for simple calculations, with N==8 .

0
source

rtt in the name of the program variable is not necessarily rtt in the output - and here it is not.

The "average round-trip delay" in the implementation you are showing is in tsum / number of packets. When you look at rtt , you really look at something else. This is only displayed when using ping in adaptive mode.

0
source

Because you are dealing with bits. Bit rate and transmission time are not the same thing, so you need to do tiny arithmetic to convert. Formula:

Packet transfer time = packet size / bit rate

So, assuming 100 Mbps and a packet size of 1526 bytes, you get:

1526 bytes x 8 bits / (100 x 10 6 bits / sec)) = 116 microseconds

The bit block is canceled and you are left with seconds.

Now here is another example. Let's say you have a round-trip time of 225 milliseconds, and your throughput is 32 kilobytes. You are getting:

32,000 bytes * 8 bits / 0.255 = 1.003.921 bits per second

-1
source

All Articles