Nine, iperf3 source code analysis: the main flow of the main function, detailed explanation of the interaction process between the server and the client during the forward TCP one-way test

brief description

Here, the interaction process between the server and the client during the forward TCP one-way test of iperf3 is explained in detail and drawn into a diagram.
Only the test process on the second side is described, and the specific code calling process can refer to the other two articles.
Seven, iperf3 source code analysis: state machine and state transition process —> server code when running forward TCP one-way test
Eight, iperf3 source code analysis: state machine and state transition process —> running forward TCP one-way test client code for

Client and server interaction process and state machine transition diagram

insert image description here

appendix

CSDN does not support sequenceDiagram, so it is posted on the website https://mermaid-js.github.io/mermaid-live-editor/ after editing, and the original document is below.

sequenceDiagram
    
    note left of iperf3客户端: 先运行服务端,再运行客户端
    note right of iperf3服务端: 先运行服务端,再运行客户端
    

    iperf3服务端 ->> iperf3服务端 : main进入启动iperf3iperf3服务端
    iperf3服务端 ->> iperf3服务端 : 调用iperf_new_test创建并初始化测试对象
    note over iperf3服务端: 进入:初始化状态
    iperf3服务端 ->> iperf3服务端 : 读取配置参数,并创建服务端监听端口
    note over iperf3服务端: 进入:IPERF_START状态

    iperf3客户端 ->> iperf3客户端 : main进入启动iperf3客户端
    iperf3客户端 ->> iperf3客户端 : 调用iperf_new_test创建并初始化测试对象
    note over iperf3客户端: 进入:初始化状态
    iperf3客户端 ->> iperf3服务端 : 读取配置参数,向服务端发起连接请求,
    iperf3服务端 ->> iperf3服务端 : 调用select/accept函数建立控制链接
    note over iperf3服务端: 进入:PARAM_EXCHANGE状态
    iperf3服务端 ->> iperf3客户端 : 通过控制链接发送PARAM_EXCHANGE指令
    note over iperf3客户端: 进入:PARAM_EXCHANGE状态
    iperf3客户端 ->> iperf3服务端 : 发送用户命令行输入配置参数给服务端
    iperf3服务端 ->> iperf3服务端 : 保存配置参数,并让配置参数生效
    note over iperf3服务端: 进入:CREATE_STREAM状态 
    iperf3服务端 ->> iperf3客户端 : 通过控制链接发送CREATE_STREAM指令
    note over iperf3客户端: 进入:CREATE_STREAM状态
    iperf3客户端 ->> iperf3服务端 : 调用iperf_create_streams函数,创建TCP测试流实例 
    iperf3客户端 ->> iperf3客户端 : 调用iperf_handle_message_client()等待服务端发起新的指令
    iperf3服务端 ->> iperf3服务端 : 调用iperf_tcp_accept接受连接请求
    iperf3服务端 ->> iperf3服务端 : 调用iperf_add_stream创建TCP测试流实例
    note over iperf3服务端: 进入:TEST_START状态 
    iperf3服务端 ->> iperf3客户端 : 通过控制链接发送TEST_START指令
    iperf3服务端 ->> iperf3服务端 :  创建服务端为TCP测试流使用的各种定时器及其它资源
    note over iperf3客户端: 进入:TEST_START状态 
    note over iperf3服务端: 进入:TEST_RUNNING状态 
    iperf3客户端 ->> iperf3客户端 : 开始创建客户端为TCP测试流使用的各种定时器及其它资源
    iperf3客户端 ->> iperf3客户端 : 等待服务端发过来的下一条命令
    iperf3服务端 ->> iperf3客户端 : 通过控制链接发送TEST_RUNNING指令
    note over iperf3客户端: 进入:TEST_RUNNING状态 
    iperf3客户端 ->>  iperf3服务端 : 通过调用iperf_send函数里的sp->snd和test->protocol->send二个函数指针,
    iperf3客户端 ->>  iperf3服务端 : 最终调用iperf_tcp_send()函数向服务端发送测试数据开始测试
    iperf3服务端 ->>  iperf3服务端 : 调用iperf_run_server函数,直接进入TEST_RUNNING分支后,
    iperf3服务端 ->>  iperf3服务端 : 调用iperf_recv函数里的sp->rcv和test->protocol->recv二个函数指针
    iperf3服务端 ->>  iperf3服务端 : 最终调用iperf_tcp_recv()函数接收客户端发过来的测试数据,
    iperf3客户端 ->>  iperf3服务端 : ......
    iperf3客户端 ->>  iperf3服务端 : 最终调用iperf_tcp_send()函数向服务端发送测试数据开始测试
    iperf3客户端 ->>  iperf3服务端 : 直到本次测试完成
    iperf3服务端 ->>  iperf3服务端 : 并做统计,直到所有测试数据接收处理完毕,
    note over iperf3客户端: 进入:TEST_END状态 
    iperf3服务端 ->>  iperf3服务端 : 等待客户端通过控制链接发过来的TEST_END控制信息。
    iperf3客户端 ->>  iperf3服务端 : 通过控制链接发送TEST_END指令
    iperf3客户端 ->>  iperf3客户端 : 等待服务端发送EXCHANGE_RESULT指令
    note over iperf3服务端: 进入:TEST_END状态 
    iperf3服务端 ->>  iperf3服务端 : 通过test->stats_callback(test)和test->reporter_callback(test)二个函数指针,
    iperf3服务端 ->>  iperf3服务端 : 调用iperf_stats_callback和iperf_reporter_callback
    iperf3服务端 ->>  iperf3服务端 : 进行测试结果汇总和生成测试报告
    note over iperf3服务端: 进入:EXCHANGE_RESULT状态 
    iperf3服务端 ->>  iperf3客户端 : 通过控制链接发送EXCHANGE_RESULT指令
    iperf3服务端 ->>  iperf3服务端 : 调用iperf_exchange_result()函数,等待客户端发过来的测试报告
    note over iperf3客户端: 进入:EXCHANGE_RESULT状态 
    iperf3客户端 ->>  iperf3服务端 : 调用iperf_exchange_result()函数,向服务端发送的测试报告
    iperf3客户端 ->>  iperf3客户端 : 等待服务端发送DISPLAY_RESULT指令
    note over iperf3服务端: 进入:DISPLAY_RESULT状态 
    iperf3服务端 ->>  iperf3客户端 : 通过控制链接发送DISPLAY_RESULT指令
     iperf3服务端 ->>  iperf3服务端 : 打印测试报告
    iperf3服务端 ->>  iperf3服务端 : 等待服务端发送IPERF_DONE指令
    note over iperf3客户端: 进入:DISPLAY_RESULT状态 
    iperf3客户端 ->>  iperf3客户端 : 客户端主动发起打印测试报告,
    note over iperf3客户端: 进入:IPERF_DONE状态 
    iperf3客户端 ->>  iperf3服务端 : 并向服务端发IPERF_DONE指令
    iperf3客户端 ->>  iperf3客户端 : 退出iperf3客户端,测试结束
    note over iperf3服务端: 进入:IPERF_DONE状态

    iperf3服务端 ->>  iperf3服务端 : 调用run()–>iperf_run_server()–>iperf_reset_test()函数,reset测试对象test,
    note over iperf3服务端: 进入:初始化状态
    iperf3服务端 ->>  iperf3服务端 : 重新运行初始化,建立监听端口,
    note over iperf3服务端: 进入:IPERF_START状态,
    iperf3服务端 ->>  iperf3服务端 : 等待下一次测试的开始。   

Guess you like

Origin blog.csdn.net/meihualing/article/details/129411589