Commit e0420109 authored by Dan Gebhardt's avatar Dan Gebhardt
Browse files

Major re-do of the initial condition gathering.

Available data elements in initial condition structure:
- Exponential average for bandwidth and latency,
- Number of samples used
- Number of error-val samples
- Number of sequential error-val from newest measurement, backwards
- timestamp of most recent measurement
- source node
- destination node

Testing needed.
parent 7901885c
......@@ -23,7 +23,28 @@ my $pprefix = "planet-";
use lib '/usr/testbed/lib';
use libtbdb;
use Socket;
<<<<<<< init-elabnodes.pl
use Getopt::Std;
use Class::Struct;
use libxmlrpc;
use strict;
my ($initvalLat, $initvalBw);
################
# Define a structure to hold the values used in initial condition reporting
struct( initvalres => {
srcnode => '$',
dstnode => '$',
ave_exp => '$',
numSamples => '$',
numErrValSamples => '$',
numLastSeqErr =>'$',
tstampLastSample => '$' } );
#'################
=======
use Getopt::Std;
>>>>>>> 1.5
#
# Every source host has a list of <dest-IP,bw,delay,plr> tuples, one
......@@ -71,6 +92,23 @@ else{
TBDBConnect($DBNAME, $DBUSER, $DBPWD) == 0
or die("Could not connect to pelab database!\n");
# RPC STUFF ##############################################
my $TB = "/usr/testbed";
my $ELABINELAB = 0;
my $RPCSERVER = "boss.emulab.net"; #?
my $RPCPORT = "3069";
#my $RPCCERT = "/etc/outer_emulab.pem"; #?
my $RPCCERT = "~/.ssl/emulab.pem";
my $MODULE = "node";
my $METHOD = "getlist";
libxmlrpc::Config({"server" => $RPCSERVER,
"verbose" => 0,
"portnum" => $RPCPORT});
# END RPC STUFF ##########################################
#
# XXX figure out how many pairs there are, and for each, who the
# corresponding planetlab node is. Can probably get all this easier
......@@ -78,11 +116,12 @@ TBDBConnect($DBNAME, $DBUSER, $DBPWD) == 0
#
my @nodelist = split('\s+', `$NLIST -m -e $pid,$eid`);
chomp(@nodelist);
my $nnodes = grep(/^${pprefix}/, @nodelist);
if ($nnodes == 0) {
print STDERR "No planetlab nodes in $pid/$eid?!\n";
exit(1);
}
#TODO: uncomment after testing
#my $nnodes = grep(/^${pprefix}/, @nodelist);
#if ($nnodes == 0) {
# print STDERR "No planetlab nodes in $pid/$eid?!\n";
# exit(1);
#}
# Preload the site indicies rather then doing fancy joins.
my %site_mapping = ();
......@@ -165,18 +204,69 @@ sub get_plabinfo($)
my ($srcvnode) = @_;
my $srcix = $ix_mapping{$srcvnode};
@{$shapeinfo{"elab-$ix"}} = ();
@{$shapeinfo{"elab-$srcix"}} = ();
foreach my $dstvnode (keys(%node_mapping)) {
next
if ($srcvnode eq $dstvnode);
#Only need these two for error messages. get_pathInitCond finds them
# itself.
my $dst = $ip_mapping{$node_mapping{$dstvnode}};
my $src_site = $site_mapping{$node_mapping{$srcvnode}};
my $dst_site = $site_mapping{$node_mapping{$dstvnode}};
my $dstix = $ix_mapping{$dstvnode};
# Get initial conditions
($initvalLat, $initvalBw) =
get_pathInitCond( $node_mapping{$srcvnode},
$node_mapping{$dstvnode},
24, 0.8 );
{ print "\nLATENCY\n";
printInitValResStruct($initvalLat);
print "\nBW\n";
printInitValResStruct($initvalBw);
} #if ($showonly);
#TODO: is this print statement wanted here? Should it be conditional
# on available path measurements, like in the original?
print "elab-$srcix -> elab-$dstix (on behalf of $dst):\n"
if ($showonly);
my ($del,$plr,$bw) = ($initvalLat->ave_exp,
undef, #TODO!!! LOSS RATE!!!
$initvalBw->ave_exp);
# handle a path with no available measurements
if($initvalLat->numSamples == $initvalLat->numErrValSamples){
$del = $DEF_DEL;
warn("*** Could not get latency ".
"$srcvnode ($src_site) --> $dstvnode ($dst_site)\n".
" defaulting to ".
"${DEF_DEL}ms\n" );
}
if(!defined($plr)){
$plr = $DEF_PLR;
warn("*** Could not get lossrate ".
"$srcvnode ($src_site) --> $dstvnode ($dst_site)\n".
" defaulting to ".
"${DEF_PLR}plr\n" );
}
if($initvalBw->numSamples == $initvalLat->numErrValSamples){
$bw = $DEF_BW;
warn("*** Could not get bandwidth ".
"$srcvnode ($src_site) --> $dstvnode ($dst_site)\n".
" defaulting to ".
"${DEF_BW}bps\n" );
}
=pod
my $dst = $ip_mapping{$node_mapping{$dstvnode}};
my $src_site = $site_mapping{$node_mapping{$srcvnode}};
my $dst_site = $site_mapping{$node_mapping{$dstvnode}};
my $dstix = $ix_mapping{$dstvnode};
my ($del,$plr,$bw);
my $query_result =
DBQueryFatal("select latency,loss,bw from pair_data ".
"where srcsite_idx='$src_site' and ".
......@@ -213,6 +303,7 @@ sub get_plabinfo($)
$del = int($del / 2);
}
=cut
print "elab-$srcix -> elab-$dstix: ".
"real=$dst, bw=$bw, del=$del, plr=$plr\n";
......@@ -223,3 +314,172 @@ sub get_plabinfo($)
push(@{$shapeinfo{"elab-$srcix"}}, [ $dst, $bw, $del, $plr ]);
}
}
######################################################################
# Grab data from DB to create an initial condition structure
#
# Notes:
# + Data used in init cond is from any node at the sites containing
# the given nodes.
#
sub get_pathInitCond($$$;$)
{
my ($srcnode, $dstnode, $pasthours, $expAlpha) = @_;
if( !defined $expAlpha) { $expAlpha = 0.6; } #default alpha value
my $endtime = time();
#my $starttime = $endtime - (60*60*24);
my $starttime = $endtime - (60*60*$pasthours);
my $srcsite_idx = $site_mapping{$srcnode};
my $dstsite_idx = $site_mapping{$dstnode};
my $initvalLat = new initvalres;
my $initvalBw = new initvalres;
my @latsamples = ();
my @bwsamples = ();
my @latsamples_noerr;
my @bwsamples_noerr;
#
# retreive data for last 24 hours for the given path and
# populate result structures
#
my $sth = DBQuery(
"SELECT * ".
"FROM pair_data WHERE ".
"srcsite_idx = $srcsite_idx and ".
"dstsite_idx = $dstsite_idx and ".
"(latency IS NOT NULL or bw IS NOT NULL) and ".
"unixstamp > $starttime and ".
"unixstamp < $endtime ".
"order by unixstamp asc ".
";" );
while( my $hr = $sth->fetchrow_hashref() ){
my %row = %{$hr};
if ( defined $row{latency} ){
push @latsamples, $row{latency};
$initvalLat->tstampLastSample($row{unixstamp});
$initvalLat->srcnode($srcnode) if !defined($initvalLat->srcnode);
$initvalLat->dstnode($dstnode) if !defined($initvalLat->dstnode);
}
if ( defined $row{bw} ){
push @bwsamples, $row{bw} ;
$initvalBw->tstampLastSample($row{unixstamp});
$initvalBw->srcnode($srcnode) if !defined($initvalBw->srcnode);
$initvalBw->dstnode($dstnode) if !defined($initvalBw->dstnode);
}
}
#do another query in reverse path if given one doesn't have latency data
if( scalar @latsamples == 0 ){
my $sth = DBQuery(
"SELECT latency ".
"FROM pair_data WHERE ".
"srcsite_idx = $dstsite_idx and ".
"dstsite_idx = $srcsite_idx and ".
"(latency IS NOT NULL) and ".
"unixstamp > $starttime and ".
"unixstamp < $endtime ".
"order by unixstamp asc ".
";" );
while( my $hr = $sth->fetchrow_hashref() ){
my %row = %{$hr};
if ( defined $row{latency} ){
push @latsamples, $row{latency};
$initvalLat->tstampLastSample($row{unixstamp});
$initvalLat->srcnode($dstnode)
if !defined($initvalLat->srcnode);
$initvalLat->dstnode($srcnode)
if !defined($initvalLat->dstnode);
}
}
}
# print "latsamples = @latsamples\n";
# print "bwsamples = @bwsamples\n";
$initvalLat->numSamples(scalar @latsamples);
$initvalBw->numSamples(scalar @bwsamples);
# Find err vals
#do for latency
my $flag_errseriesEnd = 0;
my $numErrs = 0;
my $numSeriesErr = 0;
for( my $i=$#latsamples; $i >=0; $i-- ){
if( $latsamples[$i] < 0 ){
$numErrs++;
if( $flag_errseriesEnd == 0 ){
$numSeriesErr++;
}
}else{
$flag_errseriesEnd = 1;
unshift @latsamples_noerr, $latsamples[$i];
}
}
$initvalLat->numLastSeqErr($numSeriesErr);
$initvalLat->numErrValSamples($numErrs);
#now for bw
$flag_errseriesEnd = 0;
$numErrs = 0;
$numSeriesErr = 0;
for( my $i=$#bwsamples; $i >=0; $i-- ){
if( $bwsamples[$i] < 0 ){
$numErrs++;
if( $flag_errseriesEnd == 0 ){
$numSeriesErr++;
}
}else{
$flag_errseriesEnd = 1;
unshift @bwsamples_noerr, $bwsamples[$i];
}
}
$initvalBw->numErrValSamples($numErrs);
$initvalBw->numLastSeqErr($numSeriesErr);
# Calculate Exponential average
# TODO!! Change this called function such that the time between
# samples is factored into the weighting.
$initvalLat->ave_exp( calcExpAve($expAlpha,\@latsamples_noerr) );
$initvalBw->ave_exp( calcExpAve($expAlpha,\@bwsamples_noerr) );
=pod
print "\nLatency\n@latsamples\n";
printInitValResStruct($initvalLat);
print "\nBW\n@bwsamples\n";
printInitValResStruct($initvalBw);
=cut
return [$initvalLat, $initvalBw];
}
sub printInitValResStruct($)
{
my ($struct) = @_;
print "printing InitValRes Structure\n";
foreach my $var (keys %{$struct}){
print "$var = \t".${$struct}{$var} ."\n"
if defined ${$struct}{$var};
}
}
sub calcExpAve($$\@)
{
my ($alpha, $aref) = @_;
my @values = @$aref;
if( scalar(@values) == 0 ){ return 0; }
my $lastAve = $values[0]; #start with first sample
for( my $i=1; $i<@values; $i++ ){
$lastAve = $alpha*$values[$i] + (1-$alpha)*$lastAve;
}
return $lastAve;
}
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