2008年7月6日星期日

Measure acket loss rate, jitter, and end-to-end delay for UDP-based applications

Two methods will be presented. One is to parse the traffic trace file by using gawk, and the other is to insert some codes in C++ codes. The first method is easy when the simulation is only on wired network topology. When the simulation covers wireless part, using gawk to parse traffic trace file becomes hard. Because the trace format for wireless is not the same. However, the second method needs some efforts before using it. But if the work is done, it will be easy for you to get these metrics despite wireless or wired simulation scenarios.

Method.1 Parsing the trace file (skipped)

Method.2 Modify and add mudp&mudpsink


The basic idea is to insert two fields, sendtime_ and pkt_id_, in the hdr_cmn header. When packets are sent, the packet id and send time is recorded in the sender trace file. Then when packets are received at the destination, the packet id and receiving time is recorded in the receiver trace file. So I prepare two agents, mudp and mudpsink to do the jobs. Mudp is the extension of udp agent. It only overrides the sendmsg function to keep download the packet id and sendtime in the user specified file.

[Insert the codes into NS2]

1.Download mudp.cc, mudp.h, mudpsink.cc, and mudpsink.h.
2.Create a folder named measure under ns. (for example, ~/ns-allinone-2.28/ns-2.28/measure)
3.Put these four files into measure folder.
4.Add sendtime_, pkt_id_ into packet common header. (modify common/packet.h)

struct hdr_cmn {
enum dir_t { DOWN= -1, NONE= 0, UP= 1 };
packet_t ptype_; // packet type (see above)
int size_; // simulated packet size
int uid_; // unique id
int error_; // error flag
int errbitcnt_; // # of corrupted bits jahn
int fecsize_;
double ts_; // timestamp: for q-delay measurement
int iface_; // receiving interface (label)
dir_t direction_; // direction: 0=none, 1=up, -1=down
double sendtime_; ...
unsigned long int pkt_id_;
...
inline int& addr_type() { return (addr_type_); }
inline int& num_forwards() { return (num_forwards_); }
inline int& opt_num_forwards() { return (opt_num_forwards_); }
//monarch_end
inline double& sendtime() { return (sendtime_); } // added by smallko
}

5.Add the “measure/mudp.o measure/mudpsink.o “ in the OBJ_CC of Makefile.
6.Add “Agent/mUDP set packetSize_ 1000” in the ns-default.tcl. (ns-default.tcl is under ~/ns-allinone-2.28/ns-2.28/tcl/lib)
7.make clean ; make

Then in tcl file:

...
#Setup a mUDP connection
set udp [new Agent/mUDP]
#set the sender trace file name (sd)
$udp set_filename sd
$ns attach-agent $n1 $udp
set null [new Agent/mUdpSink]
#set the receiver trace file name (rd)
$null set_filename rd
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2

#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
...

After running, you will get sd and rd.

(sd)

0 0.100000
1 0.108000
2 0.116000
3 0.124000

……………………………….

The first column: packet id ; the second column: packet send time

(rd)

0 0.100000 0.138706 0.038706
1 0.108000 0.146706 0.038706
2 0.116000 0.154706 0.038706

……………………………………………………………………………

The first column: packet id ; the second column: packet send time; the third column: packet receiving time; the fourth column: end-to-end delay.


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

补充:还有另外2个连接讲述类似诶内容,统计相关数据的
http://hpds.ee.ncku.edu.tw/~smallko/ns2/wireless-udp-1.htm 针对udp
http://140.116.72.80/~smallko/ns2/tool.htm (中文)针对用awk来统计ns2的trace各类数据以及制图

没有评论: