#!/usr/bin/perl -wT #-------------------------------------------------------------- # Security Measures # - httpd being run by user apache # - use strict; is on to verify variables # - perl -w is on for warnings # - perl -T is on for taint control #-------------------------------------------------------------- #-------------------------------------------------------------- # NIST Net Calibration, santay@nist.gov, March, 2004 # # Allow user to select calibration parameters and plot results, # which include first order statistics and links to more info. #-------------------------------------------------------------- #-------------------------------------------------------------- # Setup Main Variables #-------------------------------------------------------------- # TAINT needs PATH BEGIN { $ENV{'PATH'} = '/NN_Calibration'; } # CGI Stuff use strict; use CGI::Carp qw(fatalsToBrowser); use CGI; my $q = new CGI; # Working Directory my $home = "/NN_Calibration"; # PopUp Menu Choices my $Control = ['OFF','Loopback','Disabled']; my $Delay = ['ALL','OFF','0','10','20','50','100','200','500','1000']; my $Variance = ['ALL','OFF','0','10','50','100','200','500']; my $Streams = ['ALL','1','10','50','100']; my $OfferedLoad = ['ALL','10','30','50','70','90']; my $PacketSize = ['ALL','128','512','1024','1500']; #-------------------------------------------------------------- # Start Main WWW Page #-------------------------------------------------------------- print $q->header; print $q->start_html('NIST Net Calibration', 'santay@nist.gov'); unless($q->param) { print $q->start_form('Search'); print "
"; print "

NIST Net Calibration



"; print "
"; print "The NIST Net Network Emulation Tool has been calibrated through "; print "an extensive testing process. The results of this "; print "effort can be analyzed with this interactive plotting tool. Select the desired test parameters and the "; print "latency calibration results will be displayed in Mean and Standard Deviation plots. "; print "Access to the raw data has also been provided."; print "


A maximum of Three selections may be set to ALL."; print "




"; print "Select a Control parameter *OR* a Delay/Variance pairing"; print "
(Turn other selection(s) to OFF)


"; print "Control: ",$q->popup_menu('Control',$Control,'OFF'),""; print "     *OR*     "; print "Delay: ",$q->popup_menu('Delay',$Delay,'100'),"     "; print "Variance: ",$q->popup_menu('Variance',$Variance,'0'),""; print "





"; print "Select the Flow variants

"; print "Streams: ",$q->popup_menu('Streams',$Streams,'1'),"       "; print "Offered Load: ",$q->popup_menu('OfferedLoad',$OfferedLoad,'50'),"     "; print "  Packet Size: ",$q->popup_menu('PacketSize',$PacketSize,'1024'); print "





Generate Results

"; print "




"; print "Contact: nistnet-dev\@antd.nist.gov"; print $q->end_form; } #-------------------------------------------------------------- # Check inputs #-------------------------------------------------------------- else { # More Variables my @array; # UnTainted my @names; # Tainted my $error = "pass"; # Invalid Entry? my $ALL_Count = 0; # How Many ALLs my $OFF_Count = "fail"; # Ensure Something is OFF $names[0] = $q->param("Control"); $names[1] = $q->param("Delay"); $names[2] = $q->param("Variance"); $names[3] = $q->param("Streams"); $names[4] = $q->param("OfferedLoad"); $names[5] = $q->param("PacketSize"); # UNTAINT - Make sure inputed string is clean from start(^) to end($) # Verify one or more words with [._0-9a-z-A-Z] and no other characters for (my $i=0;$i<6;$i++) { if ($names[$i] =~ /^([\w.]+)$/) { $array[$i] = $1; # Keep good data } else { $array[$i] = $names[$i]; # Keep bad data to show $error = "fail"; } # While we're FOR-Looping let's count ALLs if ($array[$i] eq "ALL") { $ALL_Count++; } } # How Many ALLs were found? if ($ALL_Count > 3) { $ALL_Count = "fail" # Too Many } else { $ALL_Count = "pass" } # Ensure proper Tests were selected if (($array[0] eq "OFF") && ($array[1] ne "OFF") && ($array[2] ne "OFF")) { $OFF_Count = "pass"; } elsif (($array[0] ne "OFF") && ($array[1] eq "OFF") && ($array[2] eq "OFF")) { $OFF_Count = "pass"; } #-------------------------------------------------------------- # Fail Screen if Parameters not Correct #-------------------------------------------------------------- # Unless everything Passed do this... if (($ALL_Count eq "fail") || ($OFF_Count eq "fail") || ($error eq "fail")) { print "
"; print "

NIST Net Calibration
"; print "


"; print "There was an error processing the selections for the Calibration results...



"; # print "

$array[0] . $array[1] . $array[2] . $array[3] . $array[4] . $array[5]


"; print "

  • Please ensure either Control or Delay/Variance are set to OFF "; print "  [ $OFF_Count ]"; print "

  • Please ensure no more than Three selections are set to ALL "; print "  [ $ALL_Count ]"; print "

  • Please ensure ALL input fields have Valid/Legal entries "; print "  [ $error ]


    "; print "


    "; print "Contact: nistnet-dev\@antd.nist.gov"; } #-------------------------------------------------------------- # Create means to Display Results since Parameters were Correct #-------------------------------------------------------------- # User Input is Good else { my $file = ""; # Stats file to Use #---------------------------------------- # Input Field not the same as file format #---------------------------------------- if ($array[0] eq "Loopback") { $array[0] = "Loop.Back"; } elsif ($array[0] eq "Disabled") { $array[0] = "NN.Disabled"; } if ($array[1] eq "0"){ $array[1] = "0000"; } elsif ($array[1] eq "10") { $array[1] = "0010"; } elsif ($array[1] eq "20") { $array[1] = "0020"; } elsif ($array[1] eq "50") { $array[1] = "0050"; } elsif ($array[1] eq "100") { $array[1] = "0100"; } elsif ($array[1] eq "200") { $array[1] = "0200"; } elsif ($array[1] eq "500") { $array[1] = "0500"; } if ($array[2] eq "0"){ $array[2] = "000"; } elsif ($array[2] eq "10") { $array[2] = "010"; } elsif ($array[2] eq "50") { $array[2] = "050"; } if ($array[3] eq "1"){ $array[3] = "001"; } elsif ($array[3] eq "10") { $array[3] = "010"; } elsif ($array[3] eq "50") { $array[3] = "050"; } # $array[4] always = 2 digits if ($array[5] eq "128"){ $array[5] = "0128"; } elsif ($array[5] eq "512") { $array[5] = "0512"; } #---------------------------------------- # Convert ALL entries to [0-9]* for System use # Just * would pick up Loop.Back and NN.Disabled for (my $j=0;$j<6;$j++) { if ($array[$j] ne "OFF") { if ($array[$j] eq "ALL") { $file = $file . "[0-9]*" . "."; } else { $file = $file . $array[$j] . "."; } } } # After line below $file is something like: 100.50.[0-9]*.90.1024.stats $file = $file . "stats"; system ("cat $home/STATS/$file > $home/data"); system ("ls $home/STATS/$file > $home/names"); my $length = 0; # Gnuplot uses for range [-1:$length] my $line; # Read a line of INPUT file my $line2; # Read a line of INPUT file my $var1; # Mean for Raw Data file my $var2; # StDv for Raw Data file my @fields; # Break STATS file into pieces # Create Two Gnuplot files for Mean & Standard Deviation Graphs # Create a Raw data file for user to use # STATS Fields: 0-Mean; 1-Stdv; 2-Min; 3-Max open (MEAN, ">$home/mean"); open (STDV, ">$home/stdv"); open (USER, ">$home/user.$file"); open (NAME, "$home/names"); open (DATA, "$home/data"); $line = ; chop $line; print USER " Histogram\t\t Mean\t StDv\n"; print USER "--------------------\t -----------\t ----------\n"; while ($line ne "") { @fields = split (/\t/, $line); print MEAN "$fields[0]\n"; print STDV "$fields[1]\n"; $line2 = ; chop $line2; $line2 =~ s/\/NN_Calibration\/STATS\///; $line2 =~ s/.stats//; $var1 = sprintf("%12.3f",$fields[0]); $var2 = sprintf("%12.3f",$fields[1]); print USER "$line2\t$var1\t$var2\n"; $line = ; chop $line; $length++; } close DATA; close NAME; close USER; close STDV; close MEAN; #No more than 50 labels should be used per graph. Divide and Round answer. my $labels = sprintf("%.0f", $length / 50); # Create Gnuplot Xtic Values my $xtics = ""; # Gnuplot Xtic values my $count = 0; # Gnuplot Label number open (NAMES, "$home/names"); $line = ; chop $line; while ($line ne "") { $line =~ s/\/NN_Calibration\/STATS\///; $line =~ s/.stats//; if ($xtics eq "") { $xtics = "\" $line\" $count "; } else { $xtics = $xtics . ", \" $line\" $count "; } # Use every $labels-th label if > 1 if ($labels ge "1") { for (my $x=0;$x<$labels;$x++) { $line = ; $count++; } } else { $line = ; $count++; } chop $line; } close NAMES; #-------------------------------------------------------------- # Create Gnuplots #-------------------------------------------------------------- open (OUTFILE, ">$home/graph.mean"); print OUTFILE ("set term png\n"); print OUTFILE ("set ylabel \"microseconds\"\n"); if ($array[0] eq "Loop.Back") { print OUTFILE ("set xlabel \"Loop.Back.Streams.OfferedLoad.PacketSize\"\n"); } elsif ($array[0] eq "NN.Disabled") { print OUTFILE ("set xlabel \"NN.Disabled.Streams.OfferedLoad.PacketSize\"\n"); } else { print OUTFILE ("set xlabel \"Delay.Variance.Streams.OfferedLoad.PacketSize\"\n"); } print OUTFILE ("set xtic rotate\n"); print OUTFILE ("set xtic ($xtics)\n"); print OUTFILE ("set out '$home/$file.mean.png'\n"); print OUTFILE ("plot [-1:$length] '$home/mean' with impulses linetype 1\n"); close OUTFILE; $| = 1; # Hold scrip until System call completes system ("gnuplot $home/graph.mean"); open (OUTFILE, ">$home/graph.stdv"); print OUTFILE ("set term png\n"); print OUTFILE ("set ylabel \"microseconds\"\n"); if ($array[0] eq "Loop.Back") { print OUTFILE ("set xlabel \"Loop.Back.Streams.OfferedLoad.PacketSize\"\n"); } elsif ($array[0] eq "NN.Disabled") { print OUTFILE ("set xlabel \"NN.Disabled.Streams.OfferedLoad.PacketSize\"\n"); } else { print OUTFILE ("set xlabel \"Delay.Variance.Streams.OfferedLoad.PacketSize\"\n"); } print OUTFILE ("set xtic rotate\n"); print OUTFILE ("set xtic ($xtics)\n"); print OUTFILE ("set out '$home/$file.stdv.png'\n"); print OUTFILE ("plot [-1:$length] '$home/stdv' with impulses linetype 3\n"); close OUTFILE; $| = 1; # Hold scrip until System call completes system ("gnuplot $home/graph.stdv"); system ("ls -l $home/data > $home/size"); # Create Results page open (SIZE, "$home/size"); $line = ; @fields = split (/ +/, $line); if ($fields[4] eq "0") { print "
    "; print "

    NIST Net Calibration
    "; print "
    $array[0] . $array[1] . $array[2] . $array[3] . $array[4] . $array[5]"; print "





    "; print "Search results have no data

    "; print "



    "; print "Contact: nistnet-dev\@antd.nist.gov"; } else { print "
    "; print "

    NIST Net Calibration
    "; print "
    Control . Delay . Variance . Streams . OfferedLoad . PacketSize"; print "

    $array[0] . $array[1] . $array[2] . $array[3] . $array[4] . $array[5]"; print "

    View the Raw Data for this iteration
    "; #print "

    View the Raw Data for this iteration"; print "





    Mean

    "; print "


    Standard Deviation


    "; print "


    "; print "


    "; print "Contact: nistnet-dev\@antd.nist.gov"; open (ACCESS, ">>$home/access"); my @localtime = localtime; my $today = sprintf("%04d-%02d-%02d", $localtime[5]+1900, $localtime[4]+1, $localtime[3]); print ACCESS "$ENV{'REMOTE_ADDR'}\t$today\t$ENV{'QUERY_STRING'}\n"; close ACCESS; } close SIZE; } } #--------------------------------------------------------------