Trying to send UDP packets at low bandwidth will fail horribly and flood.
An example, requesting a bandwidth of 1000 bits/s, sending 10 packets of 125 bytes, which should mean 1 packet per second, this is what I get:
$ time iperf -u -c 10.0.0.254 -b1000 -l125 -n1250
------------------------------------------------------------
Client connecting to 10.0.0.254, UDP port 5001
Sending 125 byte datagrams
nanosleep failed: Invalid argument
UDP buffer size: 120 KByte (default)
------------------------------------------------------------
nanosleep failed: Invalid argument
[ 3] local 10.0.0.18 port 50674 connected with 10.0.0.254 port 5001
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
nanosleep failed: Invalid argument
[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 0.0 sec 1.22 KBytes 119 Mbits/sec
[ 3] Sent 10 datagrams
[ 3] Server Report:
[ 3] 0.0-3814.5 sec 1.22 KBytes 2.62 bits/sec 0.000 ms 0/ 9 (0%)
[ 3] 0.0-3814.5 sec 1 datagrams received out-of-order
real 0m0.021s
user 0m0.003s
sys 0m0.000s
The problem is compat/delay.cpp:delay_loop() doesn't deal with usec=1000000 properly. POSIX nanosleep() requires that the tv_nsec argument be lower than 1000 million, that is, that the seconds value be used appropriately. As is, delay_loop will fail for usec > 999999.
I am attaching a patch that fixes this and restores expected behavior:
$ time ./src/iperf -u -c 10.0.0.254 -b1000 -l125 -n1250
------------------------------------------------------------
Client connecting to 10.0.0.254, UDP port 5001
Sending 125 byte datagrams
UDP buffer size: 120 KByte (default)
------------------------------------------------------------
[ 3] local 10.0.0.18 port 35078 connected with 10.0.0.254 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 1.22 KBytes 1000 bits/sec
[ 3] Sent 10 datagrams
[ 3] Server Report:
[ 3] 0.0-4130.0 sec 1.22 KBytes 2.42 bits/sec 0.006 ms 0/ 10 (0%)
real 0m10.027s
user 0m0.000s
sys 0m0.010s
Patch is made against SVN trunk (r81), but it also applies perfectly against releases 2.0.5 and 2.0.5b1
Changelog entry:
2011-10-14 Israel G. Lugo <israel.lugo@lugosys.com>
* Fix delay_loop() for delays of 1s and greater. Was causing breakage when a
low bandwidth limit was specified.
fix delay_loop() for delays of 1s and greater