显示标签为“throughput”的博文。显示所有博文
显示标签为“throughput”的博文。显示所有博文

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
......

[Read More...]

Get the system throughput for UDP-based application

非常有用的很直接能看到flow的throughput的修改.利用loss-monitor,记录第一个包和最后一个包的抵达时间,然后计算出流量. 用于UDP.

A. Modification:

1. Modify the tools/loss-monitor.h

class LossMonitor : public Agent {
public:
LossMonitor();
virtual int command(int argc, const char*const* argv);
virtual void recv(Packet* pkt, Handler*);
protected:
int nlost_;
int npkts_;
int expected_;
int bytes_;
int seqno_;
double last_packet_time_;
//add the following two lines
double first_packet_time_;
int first;

};

2. Modify the tools/loss-monitor.cc

LossMonitor::LossMonitor() : Agent(PT_NTYPE)
{
bytes_ = 0;
nlost_ = 0;
npkts_ = 0;
expected_ = -1;
last_packet_time_ = 0.;
first_packet_time_ = 0.;
first=0;

seqno_ = 0;
bind("nlost_", &nlost_);
bind("npkts_", &npkts_);
bind("bytes_", &bytes_);
bind("lastPktTime_", &last_packet_time_);
bind("firstPktTime_", &first_packet_time_);
bind("expected_", &expected_);
}

void LossMonitor::recv(Packet* pkt, Handler*)
{
hdr_rtp* p = hdr_rtp::access(pkt);
seqno_ = p->seqno();
bytes_ += hdr_cmn::access(pkt)->size();
++npkts_;
if(first==0){
first_packet_time_=Scheduler::instance().clock();
first=1;
}

3. Recompile

cd ns.../ns...; make clean; make

B. Usage

In NS2 tcl file:

Modify each end null agent of udp traffic as a LossMonitor agent

set udp_($i) [new Agent/UDP]
$ns_ attach-agent $node_($i) $udp_($i)
set null_($i) [new Agent/LossMonitor]
$ns_ attach-agent $node_($i) $null_($i)

And by the end of the tcl: add "record" procedure:

$ns_ at 4.9 "record"
proc record {} {
global ns_ null_ val
set sum 0
###Add more, one by one###
set i 0
set th 0
set a [$null_($i) set bytes_]
set b [$null_($i) set lastPktTime_]
set c [$null_($i) set firstPktTime_]
set d [$null_($i) set npkts_]
if {$b>$c} {
set th [expr ($a-$d*20)*8/($b-$c)]
puts "flow $i has $th bps while working time"
}
set sum [expr $sum+$th]
###Add more, one by one###
puts "total throughput:$sum bps"
}

Then, we can see the udp throughput by the end of simulation.. : )

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

......

[Read More...]