2008年7月5日星期六

Measure the throughput of TCP-based application

TCP流量的取得,先修改添加tcpsink,然后用perl脚本对tcpsink的trace进行分析:
如下:

[Preparation for tcpsink]

1. Follow the steps of method2 at http://140.116.72.80/~smallko/ns2/tool_en.htm
2. Download mtcpsink.cc, mtcpsink.h
3. Put these two files into measure folder
4. Add the “measure/mtcpsink.o” in the OBJ_CC of Makefile
5. make clean; make

In tcl file:

...
set tcp1 [new Agent/TCP/Reno]
$ns attach-agent $s1 $tcp1
set tcpsink1 [new Agent/TCPSink/mTcpSink]
$tcpsink1 set_filename tcp_sink
$ns attach-agent $wl_node_(0) $tcpsink1
$ns connect $tcp1 $tcpsink1
set ftp1 [$tcp1 attach-source FTP]
....

After running the script, you will get “tcp_sink”.

...
4 0.013904 1040
5 0.015277 1040
6 0.016750 1040
...

[use perl to calculate the throughput] (throughput.pl)

#使用方法: perl throughput.pl

#記錄檔檔名
$infile=$ARGV[0];

#多少時間計算一次(單位為秒)
$granularity=$ARGV[1];

$sum=0;
$sum_total=0;
$clock=0;
$init=0;

#打開記錄檔
open (DATA,"<$infile") die "Can't open $infile $!"; #讀取記錄檔中的每行資料,資料是以空白分成眾多欄位 while () {
@x = split(' ');

if($init==0){
$start=$x[1];
$init=1;
}

#讀取的第一個欄位是時間
#判斷所讀到的時間,是否已經達到要統計吞吐量的時候
if ($x[1]-$clock <= $granularity) { #計算單位時間內累積的封包大小 $sum=$sum+$x[2]; #計算累積的總封包大小 $sum_total=$sum_total+$x[2]; } else { #計算吞吐量 $throughput=$sum*8.0/$granularity; #輸出結果: 時間 吞吐量(bps) print STDOUT "$x[1]: $throughput bps\n"; #設定下次要計算吞吐量的時間 $clock=$clock+$granularity; #計算單位時間內累積的封包大小 $sum=$sum+$x[1]; #把累積量規零 $sum=0; } } $endtime=$x[1]; #計算最後一次的吞吐量大小 $throughput=$sum*8.0/$granularity; print STDOUT "$x[1]: $throughput bps\n"; $clock=$clock+$granularity; $sum=0; #print STDOUT "$sum_total $start $endtime\n"; $avgrate=$sum_total*8.0/($endtime-$start); print STDOUT "Average rate: $avgrate bps\n"; #關閉檔案 close DATA; exit(0); Each 1 second, we calculate the TCP throughput. $perl throughput.pl tcp.sink 1.0 …………………………………………………………………………………… 42.003966: 3502720 bps 43.000810: 3452800 bps 44.001948: 3452800 bps 45.001001: 3494400 bps 45.026674: 83200 bps Average rate: 3463041.26872255 bps


转自
http://140.116.72.80/~smallko/ns2/measure_tcp.htm

没有评论: