Friday, March 12, 2010

Method to analyse NS2 Trace file

Today I am going to show a simple perl code to analyze NS2 trace file as an example of AODV routing protocol. As you know when you run simulation, NS2 generates a trace file like sometrace.tr. It will give a lot of information about your simulation result. Not knowing how to analyze this file it is useless to run NS2 simulator. In this topic we will learn how to compute delivery ratio and message overhead.

First go to your home directory and create bin directory there. We will create trace file here so that we can access it from anywhere we want.

cd ~
mkdir bin
cd bin

Download analyze.pl file, which is attached to the post, to the bin directory. I will explain main points of the code. Following code opens a file to write simulation results.

$ofile="simulation_result.csv";
open OUT, ">$ofile" or die "$0 cannot open output file $ofile: $!";

Usually in trace file each line is started with some letter like r, s, D, N. Each of the letters has meaning. For detailed meaning of the letter refer to the NS Manual Page . And following perl code extracts lines which start with "s", which means sent packets. It maybe : control packets (AODV), data packets (cbr). We are only interested in packets those are sent by routers (RTR). If you enable MAC trace, the packets sent or received by MAC layer is also shown.

if (/^s/){
if (/^s.*AODV/) {
$aodvSent++;
if (/^s.*REQUEST/) {
$aodvSendRequest++;
}
elsif (/^s.*REPLY/) {
$aodvSendReply++;
}
}
elsif (/^s.*AGT/) {
$dataSent++;
}
}

REQUEST - AODV Route Request (RREQ) packets
REPLY - AODV Route Reply (RREP) packets;
AGT - Packets those are sent by agent such as cbr, udp, tcp;

And following code counts packet received by each function.

elsif (/^r/){
if (/^r.*AODV/) {
$aodvRecv++;
if (/^r.*REQUEST/) {
$aodvRecvRequest++;
}
elsif (/^r.*REPLY/) {
$aodvRecvReply++;
}
}
elsif (/^r.*AGT/) {
$dataRecv++;
}
}

Finally packets which are dropped are counted using following code :

elsif (/^D/) {
if (/^D.*AODV/) {
if (/^D.*REQUEST/) {
$aodvDropRequest++;
}
elsif (/^D.*REPLY/) {
$aodvDropReply++;
}
}
if (/^D.*RTR/) {
$routerDrop++;
}
}

Now we will analyze example file. In this post I have written about simulating WSN with AODV protocol, download it and do following. ( I am assuming you have already put analyze.pl file into your bin directory). Here is full source code to the analyze file : analyze.pl. More trace analyzer code is available in the this archive.

ns aodv_802_15_4.tcl
cat trace-aodv-802-15-4.tr | analyze.pl

5 comments:

lacoozy said...

please help i have my honours project that i must submit soon so i need you to help with the full running code, that analyzer the trace file, give throughput, delay, jitter, dropped packet, received packet. in different layer such as application layer, network layer and mac layer.

lacoozy said...

please help i have my honours project that i must submit soon so i nid you to help with the full running code, that analyzer the trace file, give throughput, delay, jitter, dropped packet, received packet from application layer, network layer and mac layer. and the tool must be able to analyzer the local view when considering node and be able to analyzer the global view of the trace file.

Jatinder Kaur Gill said...

hi thx for share
i have run analyze.pl

it is giving following output:-
AODV Sent: 871
AODV Recv: 6690
Data Sent: 19088
Data Recv 18649
Router Drop: 301
Delivery Ratio: 97.7001257334451

but now i need to anaylze complete traceanalyzer the link you have given.I have tried cat command as you told but for all files startan.pl,endan.pl etc. it is giving following error:--

bash:/root/bin/endan.pl: Permission denied

How to run this. Cam you help.

regards

Jatinder Kaur

Jatinder Kaur Gill said...

hi thx for share
i have run analyze.pl

it is giving following output:-
AODV Sent: 871
AODV Recv: 6690
Data Sent: 19088
Data Recv 18649
Router Drop: 301
Delivery Ratio: 97.7001257334451

but now i need to anaylze complete traceanalyzer the link you have given.I have tried cat command as you told but for all files startan.pl,endan.pl etc. it is giving following error:--

bash:/root/bin/endan.pl: Permission denied

How to run this. Cam you help.

regards

Jatinder Kaur

Unknown said...

Hi,

I think your tips are very useful, it's possible to batch processing and to automate the whole process.

I've developed a tool to help the trace file analysis, it's not a command line tool, but you can give it a try, NS2 Visual Trace Analyzer:
http://nsvisualtraceanalyzer.wordpress.com/

I hope it helps someone. :)


Regards.