Iperf3.1.3简介

来源:互联网 发布:城乡统筹发展数据 编辑:程序博客网 时间:2024/06/06 01:08

较上次发表的Iperf3.1.3移植介绍,本章节主要简单介绍Iperf3.1.3工具和优化个别功能,包括配对校对和宽带测试优化。

1、软件流程:

 

 

2、时间管理模块

2.1、设计一个时间链表

该链表以时间作为链表项排序位置,时间越大排得越后;

代码实现:

该函数实现时间加法计算

usecs为时间系数,一般取值为01000000L*n,如客户端"-t"=test->duration=5n=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_procB

client_reporter_timer_procC

按时间(秒)设置链表    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"计算出32md5校验值,并截取前20个字符串;

3.12字符串结合成32个字符串;

举例:149377389618076447a681a68b92b034dc4e3a2577801e57

从左到右0~10位为机器系统时间()1493773896

11~16位共6位为机器系统时间(微妙)180764

17~48为共32位为MD5校验值47a681a68b92b034dc4e3a2577801e57

最终发送给服务端字符串为:149377389618076447a681a68b92b034dc4e

 

服务端校验过程:

1.先判断前面16位时间值,容差时间为半个小时;

2.后判断20MD5校验值

举例:获取到字符串:149377389618076447a681a68b92b034dc4e

获取到时间()1493773896,对比当前时间,不大于30分钟;

获取到20MD5校验值:47a681a68b92b034dc4e,与自身校验MD5对比;

 

4、iperf测试带宽规则

Iperf测试带宽是单通道的,就是每次执行只能测试单向下行或上行;Iperf设置一个128K字节包,通过一秒钟能发\收多少个字节(byte/sec),来测试上行\下行带宽;

  这里我们设计了一个机制,在测试5~20区间,我们将每秒的数据包做小到大排序,去掉0值,取有效值中间值,以中间值乘以4作为高位基准值,去掉大于高位基准值的数据,以中间值除以4作为低位基准值,去掉小于低位基准值的数据。再将有效值除响应时间得到带宽值;


这里我已经上次了优化的Iperf3.1.3工具,可以在我的博客中找到!

原创粉丝点击