本文描述从main函数入口开始,到一轮TCP测试包收发结束时,做为 TCP服务端的 函数调用顺序。
加入调试代码
同前文,我们在我们可以在iperf_api.h及其它一些头文件中中增加编译宏,然后在每个函数的入口处增加这个宏的调用,可以打印出函数调用关系。
#ifndef PRINTFILEFUNCLINE
#define PRINTFILEFUNCLINE printf("debug out: func = %-25s,line = %4d, file = %s\r\n",__FUNCTION__,__LINE__,__FILE__);
#endif
测试用命令
打流命令为
服务端
iperf3 -s
客户端
总共发送8K数据,每次发送1K
iperf3 -c 127.0.0.1 -n 8K -l 1K
要注意,在测试过程中,TCP客户端除了往TCP服务端发送测试数据流外,还会在测试开始时,测试过程中每固定间隔,测试完成时这三个时间分别向TCP服务端发送测试结果报告。
伪代码流程
TCP客户端发送TCP数据的代码调用逻辑如下面伪代码:
进入主函数main
{
调用iperf_new_test创建测试对象test
调用iperf_default和iperf_parse_arguments初始化测试对象test
调用run,测试对象test开始运行
调用iperf_run_client运行TCP客户端程序
调用iperf_connect–>netdial连接服务端
调
连接成功并且创建本次测试后进入while(IPERF_NOT_DONE)循环
{
调用iperf_create_streams–>iperf_new_stream创建本次测试
状态转为TEST_RUNNING
调用iperf_send通过sp->snd函数指针调用iperf_tcp_send开始向服务端发送数据包
检测到TCP数据全部发送完成后或者其它原因导致的连接断开后,跳出循环
}
}
测试代码调用关系输出
xxx@xxx-pc:~/iperf3/iperf$ iperf3 -c 127.0.0.1 -n 8K -l 1K
debug out: func = main ,line = 62, file = main.c
debug out: func = iperf_new_test ,line = 2732, file = iperf_api.c
debug out: func = iperf_defaults ,line = 2796, file = iperf_api.c
debug out: func = iperf_parse_arguments ,line = 1125, file = iperf_api.c
debug out: func = run ,line = 145, file = main.c
debug out: func = iperf_run_client ,line = 529, file = iperf_client_api.c
debug out: func = iperf_connect ,line = 377, file = iperf_client_api.c
debug out: func = netdial ,line = 238, file = net.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
Connecting to host 127.0.0.1, port 5201
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_create_streams ,line = 62, file = iperf_client_api.c
debug out: func = iperf_new_stream ,line = 4223, file = iperf_api.c
[ 5] local 127.0.0.1 port 39254 connected to 127.0.0.1 port 5201
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 648, file = iperf_client_api.c
debug out: func = iperf_send ,line = 1877, file = iperf_api.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_send ,line = 1900, file = iperf_api.c
debug out: func = iperf_tcp_send ,line = 94, file = iperf_tcp.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 577, file = iperf_client_api.c
while(TEST_NO_DONE)
debug out: func = iperf_run_client ,line = 593, file = iperf_client_api.c
debug out: func = iperf_run_client ,line = 595, file = iperf_client_api.c
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-0.00 sec 8.00 KBytes 446 Mbits/sec 0 320 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-0.00 sec 8.00 KBytes 446 Mbits/sec 0 sender
[ 5] 0.00-0.00 sec 4.00 KBytes 166 Mbits/sec receiver
iperf Done.