Iperf3.1.3简介
来源:互联网 发布:城乡统筹发展数据 编辑:程序博客网 时间:2024/06/06 01:08
较上次发表的Iperf3.1.3移植介绍,本章节主要简单介绍Iperf3.1.3工具和优化个别功能,包括配对校对和宽带测试优化。
1、软件流程:
2、时间管理模块
2.1、设计一个时间链表
该链表以时间作为链表项排序位置,时间越大排得越后;
代码实现:
该函数实现时间加法计算
usecs为时间系数,一般取值为0或1000000L*n,如客户端"-t"=test->duration=5,n=5;
则t->tv_sec为当前系数加5s;
static voidadd_usecs( struct timeval* t, int64_t usecs ){ t->tv_sec += usecs / 1000000L; t->tv_usec += usecs % 1000000L; if ( t->tv_usec >= 1000000L ) { t->tv_sec += t->tv_usec / 1000000L; t->tv_usec %= 1000000L; }}
保证链表从左到右时间是呈递增,链表头时间最小。
static voidlist_add( Timer* t ){ Timer* t2; Timer* t2prev; if ( timers == NULL ) { /* The list is empty. */ timers = t; t->prev = t->next = NULL; } else { //当前时间项小于链表头时间项,则当前项作为链表头,大的链表项向后移一位。 if ( t->time.tv_sec < timers->time.tv_sec || ( t->time.tv_sec == timers->time.tv_sec && t->time.tv_usec < timers->time.tv_usec ) ) { /* The new timer goes at the head of the list. */ t->prev = NULL; t->next = timers; timers->prev = t; timers = t; } else { //当前时间项大于链表头时间项,则当前项添加在链表头后移一位。 /* Walk the list to find the insertion point. */ for ( t2prev = timers, t2 = timers->next; t2 != NULL; t2prev = t2, t2 = t2->next ) { if ( t->time.tv_sec < t2->time.tv_sec || ( t->time.tv_sec == t2->time.tv_sec && t->time.tv_usec < t2->time.tv_usec ) ) { /* Found it. */ t2prev->next = t; t->prev = t2prev; t->next = t2; t2->prev = t; return; } } /* Oops, got to the end of the list. Add to tail. */ t2prev->next = t; t->prev = t2prev; t->next = NULL; } }}
2.2、时间管理注册及执行函数
voidtmr_run( struct timeval* nowP ){ struct timeval now; Timer* t; Timer* next; getnow( nowP, &now ); for ( t = timers; t != NULL; t = next ) { next = t->next; /* Since the list is sorted, as soon as we find a timer ** that isn't ready yet, we are done. */ //链表时间大于当前时间则退出,防止回调函数只执行一次; if ( t->time.tv_sec > now.tv_sec || ( t->time.tv_sec == now.tv_sec && t->time.tv_usec > now.tv_usec ) ) break; (t->timer_proc)( t->client_data, &now );//回调函数 if ( t->periodic ) { /* Reschedule. */ add_usecs( &t->time, t->usecs );//时间累加 list_resort( t );//添加到链表中,将现执行链表头去掉,添加累加时间后的链表; } else tmr_cancel( t );//直接删除链表头 }}//timer_proc为回调函数//client_data回调函数传参Timer*tmr_create( struct timeval* nowP, TimerProc* timer_proc, TimerClientData client_data, int64_t usecs, int periodic ){ struct timeval now; Timer* t; getnow( nowP, &now ); if ( free_timers != NULL ) { t = free_timers; free_timers = t->next; } else { t = (Timer*) malloc( sizeof(Timer) ); if ( t == NULL ) return NULL; } t->timer_proc = timer_proc; t->client_data = client_data; t->usecs = usecs; t->periodic = periodic; t->time = now; add_usecs( &t->time, usecs ); /* Add the new timer to the active list. */ list_add( t ); return t;}
2.3、实现例子
SEC_TO_US = 1000000L;
tmr_create(&now, test_timer_proc, cd, 5 * SEC_TO_US, 0);
tmr_create(&now, client_stats_timer_proc, cd, 1 * SEC_TO_US, 1);
tmr_create(&now, client_reporter_timer_proc, cd, 1 * SEC_TO_US, 1);
test_timer_proc标志位A;
client_stats_timer_proc为B;
client_reporter_timer_proc为C;
按时间(秒)设置链表 1 2 3 4 5
执行第一次tmr_run B|C B|C A
执行到第三个链表项时间大于现在时间则推出,下述类同;
执行第二次tmr_run B|C B|C A
执行第三次tmr_run B|C B|C A
执行第四次tmr_run B|C A|B|C
第四次执行到A就完成整个流程;
3、添加MD5校验
iperf3协议校验过程,客户端通过发送一串36字符给服务端,服务端校验该字符串;
客户端36为字符串生成规则:
1.前十六位为机器系统时间(10位秒+6位微妙),获取函数为gettimeofday();
2.后20位字符为生成规则,将上面16位字符串+"hlzt2015*01234567890qwertyuiopasdfghjklzxcvbnm"计算出32位md5校验值,并截取前20个字符串;
3.将1、2字符串结合成32个字符串;
举例:149377389618076447a681a68b92b034dc4e3a2577801e57
从左到右0~10位为机器系统时间(秒)1493773896;
11~16位共6位为机器系统时间(微妙)180764;
17~48为共32位为MD5校验值47a681a68b92b034dc4e3a2577801e57;
最终发送给服务端字符串为:149377389618076447a681a68b92b034dc4e
服务端校验过程:
1.先判断前面16位时间值,容差时间为半个小时;
2.后判断20位MD5校验值
举例:获取到字符串:149377389618076447a681a68b92b034dc4e
获取到时间(秒)1493773896,对比当前时间,不大于30分钟;
获取到20位MD5校验值:47a681a68b92b034dc4e,与自身校验MD5对比;
4、iperf测试带宽规则
Iperf测试带宽是单通道的,就是每次执行只能测试单向下行或上行;Iperf设置一个128K字节包,通过一秒钟能发\收多少个字节(byte/sec),来测试上行\下行带宽;
这里我们设计了一个机制,在测试5~20区间,我们将每秒的数据包做小到大排序,去掉0值,取有效值中间值,以中间值乘以4作为高位基准值,去掉大于高位基准值的数据,以中间值除以4作为低位基准值,去掉小于低位基准值的数据。再将有效值除响应时间得到带宽值;
这里我已经上次了优化的Iperf3.1.3工具,可以在我的博客中找到!
- Iperf3.1.3简介
- Iperf3.1.3移植与使用
- FEP: iperf3
- ubuntu如何安装iperf3
- Linux install iperf3 record
- iperf3打流
- iperf3.0带宽测试说明
- IPerf3 execution from Android 7
- iperf3.0 hisi uclib 交叉编译
- iperf3已不再支持双工模式测试
- Iperf3移植到ARM Linux及使用教程
- ovs原生和ovs+dpdk iperf3测试结果对比
- linux下测试2台电脑传输速度iperf3
- (OK) iperf 3 --- compile iperf3 for android-x86_64-7.0 by using mmm
- Hisi海思交叉编译iperf3,提示undefined reference to `__ctype_tolower' __ctype_b
- 1.3NIO简介
- 1.3 Android简介
- 简介
- 广播中的提示方式NotificationManager
- winform 读写.ini 文件
- 递归求角谷定理
- BZOJ1083 繁忙的都市 (洛谷P2330)
- JVM G1垃圾收集器
- Iperf3.1.3简介
- ImageLoade
- web项目使用Tomcat作为服务器,GET请求参数中文乱码
- 公众号网页发开教程
- ONVIF协议网络摄像机(IPC)客户端程序开发(1):专栏开篇
- PHP + AJAX实现幸运转盘抽奖
- Android开发(一、初窥安卓--1.创建项目)
- H264系列(10):GOP之M和N值介绍
- Android——Jsoup工具类(图片,标题,时间等的获取)