How iperf calculates network statistics

Jack Chan picture Jack Chan · May 6, 2016 · Viewed 7.7k times · Source

iperf is a great tool to measure network statistics, such as loss, throughput, jitter. I have used it a lot. But, I am just wondering how it calculates those statistics. For throughput, it can simply measure the number of bytes it received in a certain period of time; For jitter, it can just measure the packet arrival time. But, for UDP loss, how it can calculate. My guess is that it construct its payload specifically by embedding sequence numbers. So, the server can predict what packets are lost. Does anyone know what is the content of iperf packet payload?

The other thing is that, in the end of connection, the iperf client (sender) will receive a server report (which has the statistics). Which port number this report is sent? This report uses TCP or UDP? I cannot capture it using tcpdump.

I tried to search online to find the answers to my above questions. But, I can only find how to USE iperf. Looks like no document/website explain how iperf WORKs. Can someone give some insight or point to some documents?

Answer

Jack Chan picture Jack Chan · May 10, 2016

I looked at the source code, and also took some tcpdumps for iperf3. I have the following understanding for iperf3.

In iperf UDP packets, a time stamp and a sequence number (which iperf source code calls it pcount) is written into the payload by the sender. Once the receiver gets the packet, it extracts time stamp for jitter, and sequence number for packet loss count.

Jitter is calculated by compared the time stamp and the current time to find the delay, D_current, first. Then, find |D_current - D_previous| (the difference cancels the clock insync between the sender and the receiver) to contribute to jitter.

Loss is just to accumulate the the difference between the current pcount and the expected pcount which is previously received pcount plus one.

No matter it is iperf udp (with option -u in client side) or tcp, when iperf starts, a control TCP connection will be established. This control TCP connection is used to exchange client side and server side statistics, which include CPU utils, jitter and loss calculated above, at the end of test.

From iperf2 log, I do not find that control TCP connection.