?? myput_node.pl
字號:
#!/usr/bin/perl# Vikas Kawadia#script to calculate thruput # creates a log file and a .gnu file per flow# so run in a separate directory#$layer = "AGT";# can be only one of r, s, d, f #$event_filter = "r";$gran_time = 0.0 ;$granularity = 2.0 ;%psize = ();%thruput = ();%indexer = ();@data = ();# this array defines what to use to differentiate flows, depending on the# event type$indexer{r} = '-Id'; # for a receive event its dest address.dest port number$indexer{s} = '-Is'; # for a send event its source address.source port number$indexer{f} = '-Hs'; # for forward its id for this node$indexerjjmadru = '-Hs'; # same for drop#print "#ARGV is $#ARGV \n";if ($#ARGV < 2){ print "Usage: myput_node.pl <tracefile> <event> <layer> nodes\n"; die "could'nt process command line\n";}#name of the trace file to process$tracefile = shift ; #@ARGV[1]# the event you want to plot# can be only one of r, s, d, f $event_filter = shift ;# this event at what layer$layer = shift;#$type = shift;# ids of all the nodes you want to plot@trace_list = @ARGV ;print "Tracefile: $tracefile\n";print "Monitoring: event $event_filter\n";print "Layer: $layer\n";#print "Packet type: $type\n";print "For nodes @trace_list\n";#system "rm -f *.log *.gnu"; open(infile, $tracefile) or die "could'nt open $tracefile";open(logfile_total, ">$event_filter-total.log") or die "could'nt open $event_filter-total.log\n";$ptime_total = 0.0 ;$psize_total = 0 ;print logfile_total "0.0\n";while ($line = <infile>) { #read the different words into the list array @single_list @single_list = split(/\s/, $line); #get the first element which is the flag r,s,f or d $event_type = shift(@single_list); #skip the loop if event not of interest next if($event_type ne $event_filter) ; #next if($event_type !~ /$event_filter/) ; #now assign it to the associative array so that it will be indexed by the -tags %record = @single_list ;#skip if the packet is not at the layer of interest next if($record{-Nl} ne $layer); #skip if the packet type is not what we are intersted in # next if($record{-It} ne $type); #now we could have many ports and many sources, how to deal with that.... # but each port should have a single agent type... #ok so index by mynode.port #initialize logfile for each flow detected if( $logfile{$record{$indexer{$event_filter}}} eq "") { open( $logfile{$record{$indexer{$event_filter}}}, ">$event_type-$record{$indexer{$event_filter}}.log") or die "could'nt open $event_type-$record{$indexer{$event_filter}}.log\n" ; print { $logfile{$record{$indexer{$event_filter}}}} "0.0 0\n" ; $psize{$record{$indexer{$event_filter}}} = 0; $ptime{$record{$indexer{$event_filter}}} = 0; $ptype{$record{$indexer{$event_filter}}} = $record{-It}; } while($record{-t} > $ptime{$record{$indexer{$event_filter}}} + $granularity) { $ptime{$record{$indexer{$event_filter}}} += $granularity; $thruput{$record{$indexer{$event_filter}}} = ($psize{$record{$indexer{$event_filter}}}/$granularity) *(8/1024); $psize{$record{$indexer{$event_filter}}} = 0; print { $logfile{$record{$indexer{$event_filter}}}} "$ptime{$record{$indexer{$event_filter}}} $thruput{$record{$indexer{$event_filter}}}\n" ; }# packet size at the IP level.... is this okay ? -vikas $psize{$record{$indexer{$event_filter}}} += $record{-Il}; while($record{-t} > $ptime_total + $granularity) { $ptime_total += $granularity ; $thruput_total = ($psize_total/$granularity) *(8/1024) ; $psize_total = 0; print logfile_total "$ptime_total $thruput_total\n"; } $psize_total += $record{-Il}; }$final_time = $record{-t};close(infile);foreach $f (keys %psize) { #write last line before closing everything $thruput{$f} = ($psize{$f}/($final_time - $ptime{$f})) * (8/1024); print { $logfile{$f}} "$final_time $thruput{$f}\n" ; close($logfile{$f});} $thruput_total = ($psize_total/($final_time - $ptime_total)) * (8/1024);print logfile_total "$final_time $thruput_total\n";close(logfile_total);open(cmd, ">$event_filter-total.gnu");#print cmd "set term post color solid 20\n";#print cmd "set output \"out.ps\"\n";print cmd "set key top left\n";print cmd "set grid\n";print cmd "#set term postscript \n";print cmd "#set output \"$event_filter-total.ps\" \n";print cmd "set xlabel \"Time (s)\"\n";print cmd "set xrange [0:$record{-t}]\n";print cmd "set yrange [0:]\n";print cmd "set ylabel \"Throughput (Kbits/s)\"\n";print cmd "set title \"Aggregate Throughput (Kbits/s)\"\n";print cmd "plot ";#print cmd "\"$event_filter-total.log\" u 1:(\$2 *8/1000) t \"Total \" w l ";print cmd "\"$event_filter-total.log\" u 1:2 t \"Total \" w l ";print cmd "\n";print cmd "pause -1\n";close(cmd);system "gnuplot $event_filter-total.gnu";foreach $node (@trace_list) {open(cmd, ">$event_filter-$node.gnu");print cmd "set key top left\n";print cmd "set grid\n";print cmd "#set term postscript \n";print cmd "#set output \"$event_filter-$node.ps\" \n";print cmd "set title \"Aggregate rate at Node $node\" \n";print cmd "set xlabel \"Time (s)\"\n";print cmd "set xrange [0:$record{-t}]\n";print cmd "set yrange [0:]\n";print cmd "set ylabel \"Throughput (Kbits/s)\"\n";print cmd "plot ";$col = 2;@curr_flows = grep(/^$node\./, keys(%psize)) ; $len = @curr_flows ;if($len == 0){ print "Nothing for node $node \n"; close(cmd); next;} foreach $fl1 (@curr_flows) { #print cmd "\"tp$fl1.log\" u 1:(\$2 *8/1000) t \"$fl1 : $ptype{$fl1}\" w l "; print cmd "\"$event_filter-$fl1.log\" u 1:2 t \"$fl1: $ptype{$fl1}\" w l "; if($col <= $len){ print cmd "," ; } ++$col; }print cmd "\n";print cmd "pause -1\n";close(cmd);system "gnuplot $event_filter-$node.gnu";}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -