Vous êtes sur la page 1sur 3

#!

# # # # # # #

/usr/bin/perl Run ns-2 simulations vary the amount of mobile nodes in the simulation. Nathan Balon University of Michigan - Dearborn

use warnings; use strict; sub setValuesFromArgs($); my %message_type = ( emergency => 21, warning => 33, message => 42, ); # set the default values our $number_sim = 5; # the number of simulations to run our $step_size = 200; # the step size of the number of nodes our $trace_dir = 'trace'; # directory containing trace files our $data_dir = 'data'; # directory containing data files our $graph_dir = 'graphs'; # directory containing graph files our $mobility_dir = 'mobility'; # directory containing mobility files our $traffic_dir = 'traffic'; # directory containing traffic files our $seed = 12345; # seed for the simulation our $time_int = 10; # time interval for graph plots our $end_time = 65; # end of simulation our $modified = 0; # modifed algorithm our $int_size = 2147483647; # maximum random number our $cw = 15; # get the command line arguments for(my $argnum = 0; $argnum <= $#ARGV; $argnum++){ if($ARGV[$argnum] eq "-h"){ displayHelp(); exit; }elsif($argnum + 1 <= $#ARGV){ setValuesFromArgs($argnum); $argnum++; } } my @dir = ($trace_dir, $data_dir, $graph_dir); # check that the directories exit and if not create them foreach my $dir_name (@dir){ # print "$dir_name\n"; if(!(-d $dir_name) && !(-e $dir_name)){ mkdir $dir_name or die $!; chmod 0744, $dir_name; } }

# check if the traffic directory exists and if not create the traffic if(!(-d $traffic_dir) && !(-e $traffic_dir)){ print "making directory $traffic_dir\n"; mkdir $traffic_dir or die $!; chmod 0744, $traffic_dir; # system("./generate-traffic.pl --nodes $step_size " . # "--num-sim $number_sim --end $end_time") == 0 # or die "Unable to create traffic files $!\n"; } srand $seed; for(my $i = $step_size; $i <= $step_size * $number_sim; $i += $step_size){ # get random number to seed the simulation my $random_num = int(rand ($int_size)); # command to run the simulation my $ns_command = "ns sim.tcl " . "-x 1000 " . "-y 1000 " . " -nn $i " . "-nam_tr nam/out_$i.nam " . "-cp $traffic_dir/traffic_$i.tcl " . "-sc $mobility_dir/mobility_$i.tcl " . "-tr $trace_dir/trace_$i.tr " . "-seed $random_num " . "-cw $cw " . "> /dev/null"; # display the command print "$ns_command\n"; # run the simulation system($ns_command) == 0 or die "system call failed: $?"; # parse the trace file system ("./reception.pl --trace $trace_dir/trace_$i.tr --output data/recp-$i.txt") == 0 or die "system call failed: $?"; system ("./access_time.pl --trace $trace_dir/trace_$i.tr --output data/access.txt") == 0 or die "system call failed: $?"; } ################################################################## # # functions # ################################################################## sub displayHelp { # display help my $space = " " x (length($0) + 7) ; print "usgage $0 [--num-sim \"number of simulations\" ]\n" . "$space [--nodes \"number of nodes\"]\n" . "$space [--seed \"seed for random numbers\"]\n" .

"$space "$space "$space "$space "$space "$space "$space "$space "$space }

[--trace-dir \"trace directory\"]\n" . [--data-dir \"data directory\"]\n" . [--graph-dir \"graph directory\"]\n" . [--mobility-dir \"mobility directory\"]\n" . [--traffic-dir \"traffic directory\"]\n" . [--time-int \"time interval for graphs\"]\n" . [--end \"end of simulation\"]\n" . [--modified \"broadcast algorithm to use\"]\n"; [--cw \"CW size\"]\n";

# Set the parameters used by the program from the # command line arguments. sub setValuesFromArgs($) { my $argnum = shift; if($ARGV[$argnum] eq "--num-sim"){ $number_sim = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--nodes"){ $step_size = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--trace-dir"){ $trace_dir = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--data-dir"){ $data_dir = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--graph-dir"){ $graph_dir = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--mobility-dir"){ $mobility_dir = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--traffic-dir"){ $traffic_dir = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--seed"){ $seed = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--time-int"){ $time_int = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--end"){ $end_time = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--modified"){ $modified = $ARGV[$argnum + 1]; }elsif($ARGV[$argnum] eq "--cw"){ $cw = $ARGV[$argnum + 1]; }else{ die "invalid command line argument"; } }

Vous aimerez peut-être aussi