2008年7月5日星期六

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

没有评论: