Il giorno dom, 26/02/2006 alle 21.04 -0800, S RAVIKIRAN ha scritto:
> is there any in built fn. to count the no. of droped/
> recived packets if know how to get the count using
> mathematicaly....

I've found a solution in the manual "NS for beginner", which is linked
in the homepage of NS:
http://www-sop.inria.fr/maestro/personnel/Eitan.Altman/COURS-NS/n3.pdf

Since your question appears frequently on this list, I send the script I
use, inspired on that manual.
========================================================================
#!/usr/bin/perl -w
#
# USAGE: throughput.pl <trace_file> <node> <granularity> <packet-type>
#
# EXAMPLE: throughput.pl out.tr 1 0.1 udp
#
# HINT: if packet-type == any, it computes the overall throughput
#       if packet-type == dropped, it counts the dropped packets

use strict;

my $infile = $ARGV[0];
my $tonode = $ARGV[1];
my $granularity = $ARGV[2];
my $packet_type = $ARGV[3];

# we compute how many bytes were transmitted during time interval
# specified by granularity parameter in seconds
my ($sum, $clock, $throughput) = (0,0,0);
my @x;
open (DATA, "<$infile") or die "Can't open $infile: $!\n";
while (<DATA>) {
 @x = split;

 # map column   ==> data:
 #  0  event-type (r,+,-,d)
 #  1  time
 #  2  from-node
 #  3  to-node
 #  4  packet-type
 #  5  packet-size (bytes)
 #  6  flags
 #  7  flow id in IPv6
 #  8  source address in form "node.port"
 #  9  destination address in form "node.port"
 # 10  packet sequence number (network layer protocol)
 # 11  packet unique id

 if ($x[1] - $clock <= $granularity) {
  if ($packet_type ne 'dropped') {
   if ($x[0] eq 'r') {
    if (($x[3] == $tonode) or ($tonode eq 'any')){
     if (($x[4] eq $packet_type) or ($packet_type eq 'any')) {
      $sum += $x[5];
     }
    }
   }
  } else {
   if ($x[0] eq 'd') {
    if (($x[3] == $tonode) or ($tonode eq 'any')){
     $sum += $x[5];
    }
   }
  }
 } else {
  $throughput = $sum / $granularity;
  $throughput /= 1000000; # just for Mbps ...
  print "$x[1] $throughput\n";
  $clock += $granularity;
  $sum = 0;
 }
}
$throughput = $sum / $granularity;
$throughput /= 1000000; # just for Mbps ...
print "$x[1] $throughput\n";

close DATA;
exit 0;
========================================================================

Hope it helps,
-- 
:::: Emanuele  Vecchio ::::
Happy Debian GNU/Linux User
::::: [EMAIL PROTECTED] ::::::

Reply via email to