You are on page 1of 3

#!

/usr/bin/perl # # Sequence number extraction # # $event_filter = "[+rs]"; @ptype_filter = ("udp", "ack"); # trace MAC instead of AGT # (ns doesn't install trace objects at the ports of all Mobile Nodes!) $ttype_filter = "MAC"; # list containing the opened file name. @trace_list = (); if (@ARGV < 1) { printf "usage plot_seq.pl <trace file> [node]\n"; exit; } $tracename = shift; if (@ARGV == 1) # because of the 'shift'only one ARG left { $tracenode = shift; open sendlog, '>' . "send$tracenode.log" or die "couldn't open send$tracenod e.log"; open recvlog, '>' . "recv$tracenode.log" or die "couldn't open recv$tracenod e.log"; } else #specifying parse for all nodes { $tracenode = -1; } # Extracting from secondary trace file '0', the packet no. of the dropped # packets from Connection Monitor. We compare this hash list with the traffic # tracefile. If exists, treat it as a drop and not receive! open(infile, $tracename) or die "couldn't open $tracename"; while ($line = <infile>) { ++$line_no; #move to next line if does not match event_filter next if ($line !~ /^$event_filter/); $cont = 0; foreach $t (@ptype_filter) { if ($line =~ /$t/) { $cont = 1; last; } } next unless ($cont); @entry = split(/[\s\(\)\[\]]+/, $line);

$event = $entry[0]; # parse entry if ($entry[3] eq '-Hs') # WIRELESS { $time = $entry[2]; next if ($entry[18] ne $ttype_filter);

# filter out those aren't MAC # In the case of setting CN and MAP as bsnode, the filtering will not be effected, since # we are filing out those aren' t MAC. Good!! # $thisnode = $entry[4]; #id for 'this' node (value -Hs) $seqno = $entry[46]; #value -Ps $packetno = $entry[40]; #value -Ii # This will be used to filter out droped packets for application/transport level i.e. TCP/UDP. } else # WIRED { $time = $entry[1]; if ($event eq '+') { $thisnode = $entry[2]; } elsif ($event eq 'r') { $thisnode = $entry[3]; } $seqno = $entry[10]; } # write results to file if ($tracenode == -1) { # write for all nodes

if ($sendlog[$thisnode] eq "") { push @trace_list, $thisnode; $sendlog[$thisnode] = $fh++; #increment the file handler $fh open($sendlog[$thisnode], ">send$thisnode.log") or die "couldn't ope n send$thisnode.log"; $recvlog[$thisnode] = $fh++; open($recvlog[$thisnode], ">recv$thisnode.log") or die "couldn't ope n recv$thisnode.log"; } if ($event eq 's') { printf { $sendlog[$thisnode] } "%08.4f %s\n", $time, $seqno; } elsif ($event eq 'r') { # RCH # A very special hack due to the fact that we implemented a Connecti on # # # # # ge! if (exists($HASH{$packetno}) && ($thisnode == 6)) { # Do nothing } else Monitor. Since for TCP, we are extracting based on MAC layer info and not AGT layer. We need this special hack to 'drop' those packets that are received by MAC layer and never made it to the application agent, i.e. TCP. The comparison of $thisnode == 6 is BAD. A static hack at this sta

{ printf { $recvlog[$thisnode] } "%08.4f %s\n", $time, $seqno; } } elsif ($event eq '+') { printf { $sendlog[$thisnode] } "%08.4f %i\n", $time, $seqno; } } else # write for specified node { if (($event eq 's') && ($thisnode == $tracenode)) { printf { sendlog } "%08.4f %s\n", $time, $seqno; } elsif (($event eq 'r') && ($thisnode == $tracenode)) { if (exists($HASH{$packetno}) && ($thisnode == 6)) { # Do nothing } else { printf { $recvlog[$thisnode] } "%08.4f %s\n", $time, $seqno; } } elsif (($event eq '+') && ($thisnode == $tracenode)) { printf { sendlog } "%08.4f %i\n", $time, $seqno; } } } close(infile); foreach $item (@trace_list) { close $sendlog[$item]; close $recvlog[$item]; }

You might also like