Commit 2a23edce authored by Robert Ricci's avatar Robert Ricci
Browse files

Support for vnode desires in the frontend. In an NS file, you can now

put:
$node add-desire desire weight

This will end up in the virt_node_desires table. assign_wrapper now
puts the desires from this table into the top file.
parent 24c394cb
......@@ -42,15 +42,16 @@ my $XMLHEADER = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
# These are the virtual tables that make up an experiment.
# Each one could have multiple rows, each of which will be a
# hash table.
my %virtual_tables = ("experiments" => undef,
"virt_nodes" => undef,
"virt_lans" => undef,
"virt_trafgens" => undef,
"virt_agents" => undef,
"virt_routes" => undef,
"virt_vtypes" => undef,
"nseconfigs" => undef,
"eventlist" => undef);
my %virtual_tables = ("experiments" => undef,
"virt_nodes" => undef,
"virt_lans" => undef,
"virt_trafgens" => undef,
"virt_agents" => undef,
"virt_node_desires" => undef,
"virt_routes" => undef,
"virt_vtypes" => undef,
"nseconfigs" => undef,
"eventlist" => undef);
# XXX
# The experiment table is special. Only certain fields are allowed to
......
......@@ -2618,8 +2618,13 @@ sub nodetypeisplab($) { return $node_types{$_[0]}->{"isplabdslice"}; }
#
sub LoadVirtNodes()
{
printdb "Loading virt_nodes.\n";
#
# Load up the virt_node_desires hash, which we'll use below in the node
# loop
#
my %virt_node_desires = LoadVirtNodeDesires();
printdb "Loading virt_nodes.\n";
my $query_result =
DBQueryFatal("select * from virt_nodes as vn ".
"where vn.pid='$pid' and vn.eid='$eid' ".
......@@ -2785,7 +2790,39 @@ sub LoadVirtNodes()
# Stash this in the virt_nodes data structure.
$rowref->{"__osid"} = $osid;
}
#
# Add in this node's desires
#
if ($virt_node_desires{$vname}) {
$rowref->{"__desires"} = $virt_node_desires{$vname};
} else {
$rowref->{"__desires"} = {};
}
}
}
#
# Returns a hash mapping vnames to desires. The desires themselves are
# represented by a has from desire name to desire weight.
#
sub LoadVirtNodeDesires()
{
printdb "Loading virt_node_desires.\n";
my %virt_node_desires = ();
my $query_result = DBQueryFatal("select vname, desire, weight from " .
"virt_node_desires where pid='$pid' and eid='$eid'");
while (my ($vname, $desire, $weight) = $query_result->fetchrow()) {
if (!$virt_node_desires{$vname}) {
$virt_node_desires{$vname} = { $desire => $weight };
} else {
${virt_node_desires{$vname}}{$desire} = $weight;
}
printdb " virt_node $vname has desire $desire = $weight.\n";
}
return %virt_node_desires;
}
#
......@@ -2820,6 +2857,13 @@ sub virtnodeisplabnode($) {
sub virtnodeisjailed($) {
return virtnodeisvirt($_[0]) && physnodeisjailed(virtnodepnode($_[0]));
}
sub virtnodedesires {
my @desires;
while (my ($desire, $weight) = each %{$virt_nodes{$_[0]}->{"__desires"}}) {
push @desires, $desire . ":" . sprintf("%f",$weight);
}
return join(" ",@desires);
}
#
# Load up the virt_nodes info, which includes the type info for each
......@@ -3097,10 +3141,10 @@ sub CreateTopFile()
my $parent = virtnodeparent($vname);
$subnodestr = "subnode_of:$parent";
}
my $desirestr = "";
my $desirestr = virtnodedesires($vname);
if (virtnodeisplabnode($vname) && $cpu_usage) {
# Yuck
$desirestr = "+load:" . (($cpu_usage - 1) / 5.0);
$desirestr .= " +load:" . (($cpu_usage - 1) / 5.0);
}
print TOPFILE "node $vname $type $subnodestr $desirestr\n";
if (virtnodeisvirt($vname)) {
......
......@@ -64,6 +64,10 @@ Node instproc init {s} {
# table).
$self set osid ""
# Start with an empty set of desires
$self instvar desirelist
array set desirelist {}
# These are just various strings that we pass through to the DB.
$self set cmdline ""
$self set rpms ""
......@@ -129,6 +133,7 @@ Node instproc updatedb {DB} {
$self instvar isvirt
$self instvar virthost
$self instvar issubnode
$self instvar desirelist
var_import ::TBCOMPAT::default_osids
var_import ::GLOBALS::pid
var_import ::GLOBALS::eid
......@@ -180,6 +185,12 @@ Node instproc updatedb {DB} {
# Update the DB
$sim spitxml_data "virt_nodes" [list "vname" "type" "ips" "osname" "cmd_line" "rpms" "deltas" "startupcmd" "tarfiles" "failureaction" "routertype" "fixed" ] [list $self $type $ipraw $osid $cmdline $rpms $deltas $startup $tarfiles $failureaction $default_ip_routing_type $fixed ]
# Put in the desires, too
foreach desire [lsort [array names desirelist]] {
set weight $desirelist($desire)
$sim spitxml_data "virt_node_desires" [list "vname" "desire" "weight"] [list $self $desire $weight]
}
}
# add_lanlink lanlink
......@@ -394,3 +405,16 @@ Node instproc start-command {command} {
return $newprog
}
#
# Add a desire to the node, with the given weight
# Fails if the desire already exists, but maybe it could just update the
# weight?
#
Node instproc add-desire {desire weight} {
$self instvar desirelist
if {[info exists desirelist($desire)]} {
perror "\[add-desire] Desire $desire on $self already exists!"
}
set desirelist($desire) $weight
}
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