Commit 9d81a41e authored by Olav Kvittem's avatar Olav Kvittem

added deliver-file.pl

parent e4f8270e
#! /usr/bin/perl
#
# Deliver an amount of data for perfomance testing
# Olav Kvittem ( Olav.Kvittem@uninett.no )
#
# use CGI;
use CGI qw/:standard -debug/;
my $q = CGI->new;
$feilmelding = "<h3><font color=red>%s</font></h3>\n";
if ( 0 && $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp" ){
my %msg;
$msg{error}="Access to iperf denied : unauthorized";
push(@mtr, %msg);
print STDERR "Error: ";
my %headers = map { $_ => $q->http($_) } $q->http();
print STDERR "Wrong secret : Got the following headers:\n";
for my $header ( keys %headers ) {
print STDERR "$header: $headers{$header}\n";
}
print $q->header('appliation/json');
print encode_json \%msg;
} else {
my $bytes = $q->param('bytes') ; #
my $duration = $q->param('duration'); # second
$bytes=~ s/[^\w\d\.\,]/_/g; # protect attack
$duration=~ s/[^\d\.\,]/_/g;
my $testfile="bigfile-1M.bin";
open DATA, "<", $testfile || error("Could not open test file : $testfile : $!");
my $data=<DATA>;
my $datasent=0;
my $start=time;
syswrite STDOUT, $q->header('application/binary');
printf STDERR "bytes %d duration %d sec\n", $bytes, $duration;
while ( $datasent < $bytes && ( (time-$start) < $duration ) ){
syswrite STDOUT, $data;
$datasent+=length($data);
printf STDERR "data sent %d time %d sec\n", $datasent, time-$start;
}
}
exit(0);
sub error {
my $msg = shift;
die $msg;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment