如果我用-y C和-r参数使用iperf来testing双向传输并将其导出为CSV。
我得到了一些输出,但问题是,我不知道列名是什么。 例如,它显示了三行数据,但我不知道哪个对应于发送和接收。
我能猜到的其他专栏,但我宁愿确定。
我找不到任何地方logging!
字段是
时间戳,source_address,source_port,的destination_address,destination_port,间隔,transferred_bytes,bits_per_second
我通过观察推断出这一点
$ iperf -c localhost -r ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ ------------------------------------------------------------ Client connecting to localhost, TCP port 5001 TCP window size: 648 KByte (default) ------------------------------------------------------------ [ 5] local 127.0.0.1 port 54401 connected with 127.0.0.1 port 5001 [ 4] local 127.0.0.1 port 5001 connected with 127.0.0.1 port 54401 [ ID] Interval Transfer Bandwidth [ 5] 0.0-10.0 sec 50.3 GBytes 43.2 Gbits/sec [ 4] 0.0-10.0 sec 50.3 GBytes 43.2 Gbits/sec $ iperf -c localhost -r -y C 20140114124826,127.0.0.1,54402,127.0.0.1,5001,5,0.0-10.0,52551090176,42041052917 20140114124826,127.0.0.1,5001,127.0.0.1,54402,4,0.0-10.0,52551090200,41999020136
编辑:你可以在这里find相关的源代码:
// TCP Reporting printf( reportCSV_bw_format, timestamp, (stats->reserved_delay == NULL ? ",,," : stats->reserved_delay), stats->transferID, stats->startTime, stats->endTime, stats->TotalLen, speed); } else { // UDP Reporting printf( reportCSV_bw_jitter_loss_format, timestamp, (stats->reserved_delay == NULL ? ",,," : stats->reserved_delay), stats->transferID, stats->startTime, stats->endTime, stats->TotalLen, speed, stats->jitter*1000.0, stats->cntError, stats->cntDatagrams, (100.0 * stats->cntError) / stats->cntDatagrams, stats->cntOutofOrder ); }
以“,”(逗号)作为字段分隔符来看第6个字段。 然后在这里看看这些行:
Server listening on TCP port 5001 ------------------------------------------------------------ Client connecting to localhost, TCP port 5001
[ 5] local 127.0.0.1 port 54401 connected with 127.0.0.1 port 5001 [ 4] local 127.0.0.1 port 5001 connected with 127.0.0.1 port 54401 [ ID] Interval Transfer Bandwidth [ 5] 0.0-10.0 sec 50.3 GBytes 43.2 Gbits/sec [ 4] 0.0-10.0 sec 50.3 GBytes 43.2 Gbits/sec
“5”表示客户端 – >服务器连接,然后“4”表示“服务器 – >客户端”连接(在“sciurus”给出的特定示例中查看源/目的端口。
date和时间,源IP,源端口,目标IP,目的端口,Iperf进程号,时间间隔,传输的数据量(字节),带宽(每秒位数),抖动(毫秒),丢失的数据报数量,总数发送的数据报,丢失的百分比,不按顺序接收的数据报的数量
我从以下获得了以上信息:
接受的答案跳过一个奇数字段:在源和目标IP +端口对之后的字段:
timestamp, source_address, source_port, destination_address, destination_port, XXX, <---- this one interval, transferred_bytes, bits_per_second
接受的答案中的代码表示这来自transferIDvariables。 这里的一些其他答案似乎认为它代表连接标识符或连接方向。 但是,通过代码的快速浏览表明transferID来自名为groupID的全局variables。 它被初始化为零:
// Global ID that we increment to be used // as identifier for SUM reports int groupID = 0;
然而,通过代码快速grep似乎表明,它是递增和递减很多,非常容易混淆。 似乎没有任何定义的常数说明它的含义。 手动testing( iperf version 2.0.9 (9 Sept 2016) pthreads )显示连接之间重复使用的数字。 所以我想这个故事的道德是…忽略这个数字? 或者使用iperf3。
这里是一个简单的演示,使用CSV值并在循环中运行,检查是否满足给定的bps。
我还发现在上面的答案中有一个额外的字段,其值是3/4/5。 4和5似乎是方向。 3我不确定这是什么意思。 无论如何,如果这有助于:
#!/usr/bin/python import sys import subprocess from subprocess import Popen def runProcess(exe): p = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while(True): retcode = p.poll() #returns None while subprocess is running line = p.stdout.readline() yield line if(retcode is not None): break # # do an iperf to a peer and check the bps calculated is at least # what we asked for # def peer_run_until_target_bps_not_met (peer, sample_period, target_bps): debug = 0 target_kbps = target_bps / 1024.0 target_mbps = target_bps / (1024.0 * 1024.0) cmd = "iperf -c %s -t %d -i %d -y C" % (peer, sample_period, sample_period) while (True): bps=0 for line in runProcess(cmd.split()): if line == "": break if (debug): print "timestamp %s" % line.split(',')[0] print "source_address %s" % line.split(',')[1] print "source_port %s" % line.split(',')[2] print "destination_address %s" % line.split(',')[3] print "destination_port %s" % line.split(',')[4] # # "3" ??? # "5" indicates client -> server connection, # "4" indicates "server -> client" # print "direction %s" % line.split(',')[5] print "interval %s" % line.split(',')[6] print "transferred_bytes %s" % line.split(',')[7] print "bits_per_second %s" % line.split(',')[8] transferred_bytes = float(line.split(',')[7]) bps = (transferred_bytes * 8) / float(sample_period) kbps = bps / 1024.0 mbps = bps / (1024.0 * 1024.0) print "OK: %12.2f bps / %10.2f Kbps / %10.2f Mbps (target %-10.2f Mbps)" % (bps, kbps, mbps, target_mbps) if (bps < target_bps): print "FAILED: need %.2f bps / %.2fKbps / %.2f Mbps" % \ (target_bps, target_kbps, target_mbps) return peer_run_until_target_bps_not_met("10.2.0.0", 5, 0.2 * 1024 * 1024) # 10 Mbps