Here is my script for analyze output trace file in NS-2 using Perl. This script is modified from Elmurod website
#!/usr/bin/perl $tracefile=$ARGV[0]; $granularity=$ARGV[1]; #ouput file. You should change this line according to your output file folder...Abdusy modified $ofile="/home/abdusy/Documents/aodv-simulation/ref-abdusy/simulasi-aodv/results/simulation_result.csv"; open OUT, ">$ofile" or die "$0 cannot open output file $ofile: $!"; #my @pausetime = (10,50,100,200,400,600); open (DR,STDIN); $gclock=0; #Init Data Packet Information $dataSent = 0; $dataRecv = 0; $routerDrop = 0; $aodvDataSent = 0; #Init Routing Overhead & End-to-End Delay .............................Abdusy Added $routingOverHead = 0; $e2eDelay = 0 ; #Init for counting end-to-end delay.............................Abdusy Added $timesent = 0; $timereceived = 0; $timeav = 0; $timeall = 0; $idsent = 0; $time = 0; #Data Packet from Ad hoc-Host .............................Abdusy Added $dataA2H = 0; $dataH2A = 0; #AODV Message Packet Information $aodvSent = 0; $aodvRecv = 0; $aodvSentRequest = 0; $aodvRecvRequest = 0; $aodvDropRequest = 0; $aodvSentReply = 0; $aodvRecvReply = 0; $aodvDropReply = 0; $routerDropRequest = 0; $routerDropReply = 0; #loop...........................................for read trace file : Abdusy modified foreach $pausetime (@pausetime) { if ($granularity==0) {$granularity=30;} while(<>){ #while ($line) [ chomp; #chomp $line; #To split text in line .......................................Abdusy modified ($status, $t, $time, $data) = split ("t"); if (/^s/){ if (/^s.*AODV/) { $aodvSent++; if (/^s.*REQUEST/) { $aodvSendRequest++; } elsif (/^s.*REPLY/) { $aodvSendReply++; } #elsif (/^s.*AGT/) { # $aodvDataSent++; #} } #elsif (/^s.*cbr/) { elsif (/^s.*AGT/ && /^s.*8388609/ && /^s.*4194305*/ && /^s.*cbr/) { #elsif (/^s.*AGT/ && /^s.*4194305/ && /^s.*8388609*/ && /^s.*cbr/) { #elsif (/^s.*AGT/ && /^s.*cbr/) { $dataSent++; } } #condition for counting routing over head....................Abdusy Added elsif (/^f.*RTR/) { $routingOverHead++; } elsif (/^r/){ if (/^r.*AODV/) { $aodvRecv++; if (/^r.*REQUEST/) { $aodvRecvRequest++; } elsif (/^r.*REPLY/) { $aodvRecvReply++; } } # For old Trace Format ------------------------------ ABDUSY : Modified #elsif (/^r.*AGT/ && /^r.*cbr/) { # For new Trace Format elsif (/^r.*0 1.*cbr/) { $dataRecv++; if (($spl[46] eq $idsent)) { $received++; } } #print OUT "$pausetime t "."$aodvSent t"."$aodvRecv t". (($aodvSent != 0)?$aodvRecv /$aodvSent: 0)*100 ."n"; } elsif (/^D/) { if (/^D.*AODV/) { if (/^D.*REQUEST/) { $aodvDropRequest++; } elsif (/^D.*REPLY/) { $aodvDropReply++; } } if (/^D.*RTR/) { $routerDrop++; } } #.............................Abdusy } # end if } # end for close DR; #Calculate packet delivery ratio $delivery_ratio = (100*$dataRecv/$dataSent) ; #Calculate routing over head = sum of aodv message x besar paket yaitu 48 byte dibagi waktu simulasi........Abdusy Added $routingOverHead = (($routingOverHead + $aodvSent + $aodvRecv )* 48)/600; #Calculate end-to-end delay .................................................Abdusy Added #$timeav=$timesent/$dataRecv; print " n"; print " ##############################n"; print " # *** ANALYZE & RESULT *** #n"; print " ##############################n"; print " n"; print "AODV Sent : $aodvSent packets n"; print " AODV Sent Request : $aodvSentRequestn"; print " AODV Sent Reply : $aodvSentReplyn"; print "------------------------------------n"; print "AODV Recv : $aodvRecv packetsn"; print " AODV Recv Request : $aodvRecvRequestn"; print " AODV Recv Reply : $aodvRecvReplyn"; print "------------------------------------n"; print "Data Sent : $dataSent packetsn"; print "Data Recv : $dataRecv packetsn"; print "------------------------------------n"; print "Router Drop : $routerDrop packetsn"; print "------------------------------------n"; print "Packet Delivery Ratio : $delivery_ratio % n"; print "Routing Over Head : $routingOverHead bytes per second n"; print " n"; print " n"; close OUT; ############################################################################### # This script is modified from analyze.pl from Elmurod.net # to use this script, you have to copy to /usr/bin # and do "chmod 777 /usr/bin/analyze.pl" # To analyze trace file just run "cat trace-file.tr | analyze.pl" ###############################################################################l
linux@linux:~$ cd bin
linux@linux:~/bin$ cat trace-file.tr / analyze.pl
cat: trace-file.tr: No such file or directory
cat: /: Is a directory
#!/usr/bin/perl
$tracefile=$ARGV[0];
$granularity=$ARGV[1];
$ofile=”simulation_result.csv”;
open OUT, “>$ofile” or die “$0 cannot open output file $ofile: $!”;
open (DR,STDIN);
$gclock=0;
#Data Packet Information
$dataSent = 0;
$dataRecv = 0;
$routerDrop = 0;
#AODV Packet Information
$aodvSent = 0;
$aodvRecv = 0;
$aodvSentRequest = 0;
$aodvRecvRequest = 0;
$aodvDropRequest = 0;
$aodvSentReply = 0;
$aodvRecvReply = 0;
$aodvDropReply = 0;
if ($granularity==0) {$granularity=30;}
while(){
chomp;
if (/^s/){
if (/^s.*AODV/) {
$aodvSent++;
if (/^s.*REQUEST/) {
$aodvSendRequest++;
}
elsif (/^s.*REPLY/) {
$aodvSendReply++;
}
}
elsif (/^s.*AGT/) {
$dataSent++;
}
} elsif (/^r/){
if (/^r.*AODV/) {
$aodvRecv++;
if (/^r.*REQUEST/) {
$aodvRecvRequest++;
}
elsif (/^r.*REPLY/) {
$aodvRecvReply++;
}
}
elsif (/^r.*AGT/) {
$dataRecv++;
}
} elsif (/^D/) {
if (/^D.*AODV/) {
if (/^D.*REQUEST/) {
$aodvDropRequest++;
}
elsif (/^D.*REPLY/) {
$aodvDropReply++;
}
}
if (/^D.*RTR/) {
$routerDrop++;
}
}
}
close DR;
$delivery_ratio = 100*$dataRecv/$dataSent;
print “AODV Sent : $aodvSent\n”;
print “AODV Recv : $aodvRecv\n”;
print “Data Sent : $dataSent\n”;
print “Data Recv : $dataRecv\n”;
print “Router Drop : $routerDrop\n”;
print “Delivery Ratio : $delivery_ratio \n”;
print OUT “Messages Sent,$dataSent\n”;
print OUT “Messages Recieved,$dataRecv\n”;
print OUT “Messages Dropped,$routerDrop\n”;
print OUT “Delivery Rate,$delivery_ratio\n”;
close OUT;
linux@linux:~/bin$ chnod 777
No command ‘chnod’ found, did you mean:
Command ‘chmod’ from package ‘coreutils’ (main)
chnod: command not found
linux@linux:~/bin$ ns wireless.tcl
num_nodes is set 20
INITIALIZE THE LIST xListHead
Loading connection pattern…
couldn’t read file “cbr-20-10-1”: no such file or directory
while executing
“source.orig cbr-20-10-1”
(“uplevel” body line 1)
invoked from within
“uplevel source.orig [list $fileName]”
invoked from within
“if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
…”
(procedure “source” line 8)
invoked from within
“source $val(cp)”
(file “wireless.tcl” line 95)
linux@linux:~/bin$ cat wireless1-out.tr / analyze.pl
cat: /: Is a directory
#!/usr/bin/perl
$tracefile=$ARGV[0];
$granularity=$ARGV[1];
$ofile=”simulation_result.csv”;
open OUT, “>$ofile” or die “$0 cannot open output file $ofile: $!”;
open (DR,STDIN);
$gclock=0;
#Data Packet Information
$dataSent = 0;
$dataRecv = 0;
$routerDrop = 0;
#AODV Packet Information
$aodvSent = 0;
$aodvRecv = 0;
$aodvSentRequest = 0;
$aodvRecvRequest = 0;
$aodvDropRequest = 0;
$aodvSentReply = 0;
$aodvRecvReply = 0;
$aodvDropReply = 0;
if ($granularity==0) {$granularity=30;}
while(){
chomp;
if (/^s/){
if (/^s.*AODV/) {
$aodvSent++;
if (/^s.*REQUEST/) {
$aodvSendRequest++;
}
elsif (/^s.*REPLY/) {
$aodvSendReply++;
}
}
elsif (/^s.*AGT/) {
$dataSent++;
}
} elsif (/^r/){
if (/^r.*AODV/) {
$aodvRecv++;
if (/^r.*REQUEST/) {
$aodvRecvRequest++;
}
elsif (/^r.*REPLY/) {
$aodvRecvReply++;
}
}
elsif (/^r.*AGT/) {
$dataRecv++;
}
} elsif (/^D/) {
if (/^D.*AODV/) {
if (/^D.*REQUEST/) {
$aodvDropRequest++;
}
elsif (/^D.*REPLY/) {
$aodvDropReply++;
}
}
if (/^D.*RTR/) {
$routerDrop++;
}
}
}
close DR;
$delivery_ratio = 100*$dataRecv/$dataSent;
print “AODV Sent : $aodvSent\n”;
print “AODV Recv : $aodvRecv\n”;
print “Data Sent : $dataSent\n”;
print “Data Recv : $dataRecv\n”;
print “Router Drop : $routerDrop\n”;
print “Delivery Ratio : $delivery_ratio \n”;
print OUT “Messages Sent,$dataSent\n”;
print OUT “Messages Recieved,$dataRecv\n”;
print OUT “Messages Dropped,$routerDrop\n”;
print OUT “Delivery Rate,$delivery_ratio\n”;
close OUT;
linux@linux:~/bin$ cat wireless1-out.tr / throughput.pl
cat: /: Is a directory
# type: perl throughput.pl > output file
$infile=$ARGV[0];
$tonode=$ARGV[1];
$granularity=$ARGV[2];
#we compute how many bytes were transmitted during time interval specified
#by granularity parameter in seconds
$sum=0;
$clock=0;
open (DATA,”<$infile")
|| die "Can't open $infile $!";
while () {
@x = split(‘ ‘);
#column 1 is time
if ($x[1]-$clock <= $granularity)
{
#checking if the event corresponds to a reception
if ($x[0] eq 'r')
{
#checking if the destination corresponds to arg 1
if ($x[3] eq $tonode)
{
#checking if the packet type is TCP
if ($x[4] eq 'tcp')
{
$sum=$sum+$x[5];
}
}
}
}
else
{ $throughput=$sum/$granularity;
print STDOUT "$x[1] $throughput\n";
$clock=$clock+$granularity;
$sum=0;
}
}
$throughput=$sum/$granularity;
print STDOUT "$x[1] $throughput\n";
$clock=$clock+$granularity;
$sum=0;
close DATA;
exit(0);
I have above result kindly suggest me what to do
hi am new to perl script!! can yo plz help me to how to run the above given script???
Everything is very open with a really clear explanation of the issues.
It was definitely informative. Your site is useful.
Many thanks for sharing!