Commit efe42822 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Add basic code for getting pair_data from DB. This is incomplete!

Look for the XXX in get_plabinfo to see where it needs to be beefed
up.
parent 77c61233
......@@ -19,6 +19,26 @@ my $TEVC = "/usr/testbed/bin/tevc";
my $NLIST = "/usr/testbed/bin/node_list";
my $pprefix = "planet-";
# XXX Need to configure this stuff!
use lib '/usr/testbed/lib';
use libtbdb;
use Socket;
my $PWDFILE = "/usr/testbed/etc/pelabdb.pwd";
my $DBNAME = "pelab";
my $DBUSER = "pelab";
# Get DB password and connect.
my $DBPWD = `cat $PWDFILE`;
if ($DBPWD =~ /^([\w]*)\s([\w]*)$/) {
$DBPWD = $1;
}
else{
fatal("Bad chars in password!");
}
TBDBConnect($DBNAME, $DBUSER, $DBPWD) == 0
or die("Could not connect to pelab database!\n");
#
# Every source host has a list of <dest-IP,bw,delay,plr> tuples, one
# element per possible destination
......@@ -36,7 +56,7 @@ my ($pid,$eid) = @ARGV;
# corresponding planetlab node is. Can probably get all this easier
# via XMLRPC...
#
my @nodelist = split('\s+', `$NLIST -v -e $pid,$eid`);
my @nodelist = split('\s+', `$NLIST -m -e $pid,$eid`);
chomp(@nodelist);
my $nnodes = grep(/^${pprefix}/, @nodelist);
if ($nnodes == 0) {
......@@ -44,13 +64,52 @@ if ($nnodes == 0) {
exit(1);
}
# Preload the site indicies rather then doing fancy joins.
my %site_mapping = ();
my %node_mapping = ();
my %ix_mapping = ();
my %ip_mapping = ();
foreach my $mapping (@nodelist) {
if ($mapping =~ /^(${pprefix}[\d]+)=([\w]*)$/) {
my $vnode = $1;
my $pnode = $2;
# Grab the site index.
my $query_result =
DBQueryFatal("select site_idx from site_mapping ".
"where node_id='$pnode'");
if (! $query_result->numrows) {
die("Could not map $pnode to its site index!\n");
}
my ($site_index) = $query_result->fetchrow_array();
$node_mapping{$vnode} = $pnode;
$site_mapping{$pnode} = $site_index;
if ($vnode =~ /^${pprefix}(\d+)/) {
$ix_mapping{$vnode} = $1;
}
else {
die("Could not map $vnode to its index!\n");
}
# Grab the IP address and save.
my (undef,undef,undef,undef,@ips) = gethostbyname("$pnode");
if (!@ips) {
die("Could not map $pnode to its ipaddr\n");
}
$ip_mapping{$pnode} = inet_ntoa($ips[0]);
}
}
#
# Get planetlab info for each planetlab node...
#
foreach (@nodelist) {
if (/^${pprefix}(\d+)/) {
get_plabinfo($1);
}
foreach my $vnode (keys(%node_mapping)) {
get_plabinfo($vnode);
}
#
......@@ -78,23 +137,42 @@ sub send_events()
}
#
# XXX testing...
# Replace with real code that looks up IP of "planet-$ix" and
# then looks in DB for info.
# Grab data from DB.
#
sub get_plabinfo($)
{
my ($ix) = @_;
my ($srcvnode) = @_;
my $srcix = $ix_mapping{$srcvnode};
@{$shapeinfo{"elab-$ix"}} = ();
foreach my $i (1 .. $nnodes) {
next if ($i == $ix);
my $dst = "10.0.0.$ix";
my $bw = $i * 1000;
my $del = $i;
my $plr = $i / 100;
foreach my $dstvnode (keys(%node_mapping)) {
next
if ($srcvnode eq $dstvnode);
my $dst = $ip_mapping{$node_mapping{$dstvnode}};
my $src_site = $site_mapping{$node_mapping{$srcvnode}};
my $dst_site = $site_mapping{$node_mapping{$dstvnode}};
my $query_result =
DBQueryFatal("select latency,loss,bw from pair_data ".
"where srcsite_idx='$src_site' and ".
" dstsite_idx='$dst_site' ".
"order by unixstamp desc");
if (!$query_result->numrows) {
warn("Could not get pair data for ".
"$srcvnode ($src_site) --> $dstvnode ($dst_site)\n");
next;
}
#
# XXX This needs to be modified!
#
my ($del,$plr,$bw) = $query_result->fetchrow_array();
push(@{$shapeinfo{"elab-$ix"}}, [ $dst, $bw, $del, $plr ]);
print "elab-$srcix: $dst, $bw, $del, $plr\n";
push(@{$shapeinfo{"elab-$srcix"}}, [ $dst, $bw, $del, $plr ]);
}
}
Supports Markdown
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