Commit c0c581e4 authored by Tarun Prabhu's avatar Tarun Prabhu
Browse files

More code to libvtop to suppose rspec. Nothing specific worth mentioning....

More code to libvtop to suppose rspec. Nothing specific worth mentioning. Still work to be done though.
parent fabe11af
......@@ -37,7 +37,7 @@ CXXFLAGS += -I/sw/include
ifeq ($(HAVE_XERCES),yes)
CXXFLAGS += -DWITH_XML
LIBS += -L/usr/local/lib -lxerces-c
OBJS += parse_ptop_xml.o parse_vtop_xml.o parse_policy_xml.o parse_error_handler.o xmlhelpers.o parse_advertisement_rspec.o parse_request_rspec.o annotate_rspec.o annotate_vtop.o annotate.o
OBJS += parse_ptop_xml.o parse_vtop_xml.o parse_policy_xml.o parse_error_handler.o xmlhelpers.o parse_advertisement_rspec.o parse_request_rspec.o annotate_rspec.o annotate_vtop.o annotate.o rspec_parser_helper.o rspec_parser.o rspec_parser_v1.o rspec_parser_v2.o
endif
# Pick either this
......@@ -120,6 +120,7 @@ assign.o: assign.cc port.h common.h fstring.h delay.h physical.h \
solution.h maps.h anneal.h config.h
config.o: config.cc config.h common.h port.h fstring.h score.h physical.h \
delay.h featuredesire.h forwarding.h virtual.h anneal.h pclass.h
emulab_extensions_parser.o: emulab_extensions_parser.cc
featuredesire.o: featuredesire.cc featuredesire.h common.h port.h \
fstring.h score.h physical.h delay.h forwarding.h virtual.h
forwarding.o: forwarding.cc forwarding.h port.h fstring.h physical.h \
......@@ -143,6 +144,10 @@ parse_vtop_xml.o: parse_vtop_xml.cc
parser.o: parser.cc parser.h port.h
pclass.o: pclass.cc port.h common.h fstring.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h pclass.h
rspec_parser.o: rspec_parser.cc
rspec_parser_helper.o: rspec_parser_helper.cc
rspec_parser_v1.o: rspec_parser_v1.cc
rspec_parser_v2.o: rspec_parser_v2.cc
score.o: score.cc port.h common.h fstring.h vclass.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h pclass.h score.h
solution.o: solution.cc solution.h port.h delay.h physical.h common.h \
......
......@@ -31,6 +31,7 @@ use Carp;
use POSIX;
use XML::LibXML;
use XML::Simple;
use GeniXML;
# Configure variables
my $TB = "@prefix@";
......@@ -42,10 +43,13 @@ my $OS_SELECT = "$TB/bin/os_select";
my $DELAYCAPACITY = @DELAYCAPACITY@; # Can be overridden by user.
my $DELAYTHRESH = @DELAYTHRESH@;
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $OURDOMAIN = "@OURDOMAIN@";
my $cmid = '';
if ($PGENISUPPORT) {
require libGeni;
require GeniHRN;
$cmid = GeniHRN::Generate($OURDOMAIN, "authority", "cm");
}
# Flags.
......@@ -94,7 +98,7 @@ sub Create($$$$)
"links" => [],
"class" => [],
"fixed" => [] };
$self->{'RSPEC'} = undef;
$self->{'RSPEC'} = {};
# Mostly for update mode.
$self->{'FIXEDNODES'} = {};
......@@ -215,8 +219,8 @@ sub createLink($$$$$$$$)
# The table could also contain non-default values for latency and packet_loss
my ($self, $name, $cm, $src, $dst, $bw, $type, $others) = @_;
my $ref = {
'client_id' => $name,
'component_manager_id' => $cm,
'name' => $name,
'cm' => $cm,
'link_type' => "$type",
'interface_ref' => [$src, $dst],
'capacity' => $bw,
......@@ -226,7 +230,7 @@ sub createLink($$$$$$$$)
if ($others) {
while ( my ($key, $value) = each %{$others} ) {
$ref{$key} = $value;
$ref->{$key} = $value;
}
}
if (!exists($self->rspec()->{'link'})) {
......@@ -235,22 +239,31 @@ sub createLink($$$$$$$$)
push(@{ $self->rspec()->{'link'} }, $ref);
}
sub createNode ($$$$$$)
sub createNode ($$$$$$$)
{
# $others here will be a hashtable for the desires
# The key will be the desire name and the value will be a pair
# of the desire type and the penalty
my ($self, $name, $cm, $type, $type_count, $others) = @_;
my ($self, $name, $cm, $type, $type_count, $desires, $others) = @_;
print "TYPE COUNT: $type_count";
my $ref = {
'client_id' => $name,
'component_manager_id' => $cm,
'name' => $name,
'cm' => $cm,
'node_type' => $type,
'type_count' => $type_count
'type_slots' => $type_count,
};
my $desiretable = {};
if ($desires) {
while ( my ($key, $value) = each %{$others} ) {
$desiretable->{$key} = $value;
}
}
$ref->{'desires'} = $desiretable;
if ($others) {
while ( my ($key, $value) = each %{$others} ) {
$ref{$key} = $value;
$ref->{$key} = $value;
}
}
......@@ -1327,27 +1340,34 @@ sub GenVirtNodes($)
push(@{ $self->rspec()->{'node'} }, $ref);
next;
}
my $subnodestr = "";
my $desires = {};
my $others = {};
# my $subnodestr = "";
if ($vnode->_issubnode()) {
my $parent = $vnode->_parent();
$subnodestr = "subnode_of:$parent";
# my $parent = $vnode->_parent();
# $subnodestr = "subnode_of:$parent";
$others->{'subnode'} = $vnode->_parent();
}
my $desirestr = "";
# my $desirestr = "";
foreach my $desirename (keys(%{ $vnode->_desires() })) {
my $weight = $vnode->_desires()->{$desirename};
$desirestr .= " "
if ($desirestr ne "");
$desirestr .= "$desirename:" . sprintf("%f",$weight);
# $desirestr .= " "
# if ($desirestr ne "");
# $desirestr .= "$desirename:" . sprintf("%f",$weight);
$desires->{$desirename} = ['', $weight];
}
if ($vnode->_isplabnode() && $experiment->cpu_usage()) {
# Yuck
$desirestr .= " +load:" . (($experiment->cpu_usage() - 1) / 5.0);
# $desirestr .= " +load:" . (($experiment->cpu_usage() - 1) / 5.0);
$desires->{'load'} = ['+', (($experiment->cpu_usage() - 1) / 5.0)];
}
if ($self->updating()) {
$desirestr .= " already_reserved:.2";
# $desirestr .= " already_reserved:.2";
$desires->{'already_reserved'} = ['', 0.2];
}
if (defined($vnode->_startloc())) {
$desirestr .= " area-" . $vnode->_startloc() . ":1";
# $desirestr .= " area-" . $vnode->_startloc() . ":1";
$desires->{"area-" . $vnode->_startloc()} = ['', 1];
}
# Require that this vnode be placed onto a pnode that supports
# the OS it is going to run. However, if the OS is one with a
......@@ -1367,22 +1387,29 @@ sub GenVirtNodes($)
if (!defined($posinfo)) {
my $jailosid = $self->nodejailosid($vnode);
$desirestr .= " OS-$jailosid:1";
# $desirestr .= " OS-$jailosid:1";
$desires->{"OS-$jailosid"} = ['', 1];
}
else {
$desirestr .= " OS-" . $posinfo->osid() . ":1";
$desirestr .= " OS-" . $posinfo->osid() .
"-" . $osinfo->osid() . ":1";
# $desirestr .= " OS-" . $posinfo->osid() . ":1";
# $desirestr .= " OS-" . $posinfo->osid() .
# "-" . $osinfo->osid() . ":1";
$desires->{"OS-$posinfo->osid()"} = ['', 1];
$desires->{"OS-$posinfo->osid()-$osinfo->osid()"} = ['', 1];
}
}
elsif (!defined($osinfo->path()) || $osinfo->path() eq "") {
if (!defined($posinfo)) {
$desirestr .= " OS-" . $osinfo->osid() . ":1";
# $desirestr .= " OS-" . $osinfo->osid() . ":1";
$desires->{"OS-$osinfo->osid()"} = ['', 1];
}
else {
$desirestr .= " OS-" . $posinfo->osid() . ":1";
$desirestr .= " OS-" . $posinfo->osid() .
"-" . $osinfo->osid() . ":1";
# $desirestr .= " OS-" . $posinfo->osid() . ":1";
# $desirestr .= " OS-" . $posinfo->osid() .
# "-" . $osinfo->osid() . ":1";
$desires->{"OS-$posinfo->osid()"} = ['', 1];
$desires->{"OS-$posinfo->osid()-$osinfo->osid()"} = ['', 1];
}
}
}
......@@ -1392,19 +1419,22 @@ sub GenVirtNodes($)
# simnodes that I do not understand.
#
my $typestr = $type;
my $nodeweight = '1';
if ($vnode->_issimnode()) {
my $query_result =
DBQueryWarn("select nodeweight from virt_simnode_attributes ".
"where pid='$pid' and eid='$eid' and ".
" vname='$vname'");
if ($query_result && $query_result->numrows) {
my ($nodeweight) = $query_result->fetchrow_array();
($nodeweight) = $query_result->fetchrow_array();
if ($nodeweight) {
$typestr = "$type:$nodeweight";
}
}
}
$self->f("$vname $typestr $subnodestr $desirestr");
$self->createNode($vname, $cmid, $type, $nodeweight, $desires, $others);
# $self->addnode("$vname $typestr $subnodestr $desirestr");
}
#
......@@ -1586,8 +1616,7 @@ sub GenVirtLans($)
# ],
# };
# TODO: Insert component manager ID here
$self->createLink($name, "TODO:CMID",
$self->createLink($vname, $cmid,
$member0, $member1,
$bw, "tunnel", undef)
......@@ -2031,8 +2060,7 @@ sub GenVirtLans($)
#
# $self->addnode("fakelan/$vname $protocol");
# TODO: Insert CM
$self->createNode("fakelan/$vname", "TODO:CM", $protocol, 1, undef);
$self->createNode("fakelan/$vname", $cmid, $protocol, '1', undef, undef);
# So we ignore it when it comes back from assign.
......@@ -2054,8 +2082,7 @@ sub GenVirtLans($)
# }
# push(@{ $self->rspec()->{'link'} }, $ref);
# TODO: Insert CM
$self->createLink($plink, "TODO:CM", $vnode, "fakelan/$vname",
$self->createLink($plink, $cmid, $vnode, "fakelan/$vname",
$top_bw, $protocol);
next;
}
......@@ -2127,8 +2154,7 @@ sub GenVirtLans($)
# ],
# };
# TODO: Insert CM
$self->createLink($vname, "TODO:CM", $member0, $member1, $bw,
$self->createLink($vname, $cmid, $member0, $member1, $bw,
"ethernet", undef);
next;
}
......@@ -2230,9 +2256,9 @@ sub GenVirtLans($)
$fixsrc = "$fixi0";
}
if (defined($fixi1) && $fixi1 ne '') {
if ($fixall ne "") {
$fixall .= " ";
}
# if ($fixall ne "") {
# $fixall .= " ";
# }
# $fixsrc1 = "fixsrciface:$fixi1";
# $fixdst1 = "fixdstiface:$fixi1";
# $fixall .= "fixdstiface:$fixi1";
......@@ -2263,8 +2289,7 @@ sub GenVirtLans($)
if ($self->virtlan_use_linkdelay($vlan, $shaped)) {
my $plink = "linksimple/$vname/$member0,$member1";
# TODO: Component manager ID
$self->createLink($plink, "TODO:CM", $vname0, $vname1,
$self->createLink($plink, $cmid, $vname0, $vname1,
max($top_bw, $top_rbw), $protocol,
{ 'emulated' => "1",
'trivial_ok' => "1" });
......@@ -2298,20 +2323,20 @@ sub GenVirtLans($)
my @delayinfo = ($delay,$bw,$backfill,$loss,
$rdelay,$rbw,$rbackfill,$rloss,0);
# TODO: Insert CM ID
$self->createNode($delayname, "TODO:CM", "delay", 1,
$self->createNode($delayname, $cmid, "delay", '1',
{ "$delaydesirename"
=>
[$delaydesiretype, $delaydesirepenalty});
[$delaydesiretype, $delaydesirepenalty]},
undef);
# $self->addnode("$delayname delay $delaydesire");
# TODO: Insert CM
my $others = {};
if ($fixsrc0 ne '')
$others {'fixsrciface'} = $fixsrc0;
if ($fixsrc0 ne '') {
$others->{'fixsrciface'} = $fixsrc0;
}
$self->createLink("linksdelaysrc/$vname/$member0,$member1",
"TODO:CMID", $vname0, $delayname,
$cmid, $vname0, $delayname,
($top_bw == 0 ? "*" : $top_bw), $protocol,
$others);
......@@ -2320,11 +2345,11 @@ sub GenVirtLans($)
# ($top_bw == 0 ? "*" : $top_bw) .
# " 0 0 $protocol $fixsrc0");
# TODO: Insert CM
if ($fixdst0 ne '')
$others {'fixdstiface'} = $fixdst0;
if ($fixdst0 ne '') {
$others->{'fixdstiface'} = $fixdst0;
}
$self->createLink("linksdelaydst/$vname/$member1,$member0",
"TODO:CMID", $vname1, $delayname,
$cmid, $vname1, $delayname,
($top_bw == 0 ? "*" : $top_bw), $protocol,
$others);
......@@ -2369,12 +2394,12 @@ sub GenVirtLans($)
# $spec .= " 0 0 $protocol";
# $spec .= " emulated" if ($emulated);
if ($emulated) {
$others{'emulated'} = 1;
$others->{'emulated'} = 1;
}
if ($trivial_ok) {
# $spec .= " trivial_ok";
$others{'trivial_ok'} = 1;
$others->{'trivial_ok'} = 1;
#
# We store this info in case assign actually does turn it
# into a trivial link. If that happens, we have to insert
......@@ -2395,13 +2420,12 @@ sub GenVirtLans($)
# $spec .= " $fixall";
# }
if ($fixsrc ne '') {
$others {'fixsrciface'} = $fixsrc;
$others->{'fixsrciface'} = $fixsrc;
}
if ($fixdst ne '') {
$others {'fixdstiface'} = $fixdst;
$others->{'fixdstiface'} = $fixdst;
}
# TODO: Insert CM
$self->createLink($plink, "TODO:CM", $vname0, $vname1, $bw,
$self->createLink($plink, $cmid, $vname0, $vname1, $bw,
$protocol, $others);
# $self->addlink($spec);
}
......@@ -2412,8 +2436,7 @@ sub GenVirtLans($)
# Lan node for assign.
# $self->addnode("lan/$vname lan");
# TODO: Insert CM
$self->createNode("lan/$vname", "TODO:CM", "lan", 1, undef);
$self->createNode("lan/$vname", $cmid, "lan", '1', undef, undef);
# So we ignore it when it comes back from assign.
$self->lannodes()->{"lan/$vname"} = 1;
......@@ -2456,28 +2479,28 @@ sub GenVirtLans($)
$noderef->{'component_urn'} =
GeniHRN::Generate($authority, "node", "*");
}
# my $ref = {
# 'virtual_id' => "$vname:$member",
# # The list references are so XML::Simple does not
# # turn them into attributes. Need a better solution.
# 'latency' => [0],
# 'packet_loss' => [0],
# # 'link_type' => {"type_name" => "ethernet"},
# 'link_type' => "ethernet",
# 'bandwidth' => [$bw],
# 'interface_ref' =>
# [
# { 'virtual_node_id' => $virtnode->vname(),
# 'virtual_interface_id' => "$member" },
# { 'virtual_node_id' => "lan-$vname",
# 'virtual_interface_id' => "$member" }
# ]
# };
# my $ref = {
# 'virtual_id' => "$vname:$member",
# # The list references are so XML::Simple does not
# # turn them into attributes. Need a better solution.
# 'latency' => [0],
# 'packet_loss' => [0],
# # 'link_type' => {"type_name" => "ethernet"},
# 'link_type' => "ethernet",
# 'bandwidth' => [$bw],
# 'interface_ref' =>
# [
# { 'virtual_node_id' => $virtnode->vname(),
# 'virtual_interface_id' => "$member" },
# { 'virtual_node_id' => "lan-$vname",
# 'virtual_interface_id' => "$member" }
# ]
# };
my $ref = {
'virtual_id' => "$vname:$member",
# The list references are so XML::Simple does not
# turn them into attributes. Need a better solution.
# The list references are so XML::Simple does not
# turn them into attributes. Need a better solution.
'capacity' => [$bw],
'latency' => [0],
'packet_loss' => [0],
......@@ -2495,7 +2518,7 @@ sub GenVirtLans($)
'capacity' => $bw,
'latency' => 0,
'packet_loss' => 0 }
]
],
'interface_ref' =>
[
{ 'virtual_node_id' => $virtnode->vname(),
......@@ -2626,16 +2649,15 @@ sub GenVirtLans($)
my $others = {};
if ($emulated) {
$others{'emulated'} = 1;
$others->{'emulated'} = 1;
}
if ($trivial_ok) {
$others{'trivial_ok'} = 1;
$others->{'trivial_ok'} = 1;
}
if ($fixsrc0) {
$others{'fixsrciface'} = $fixi0;
$others->{'fixsrciface'} = $fixi0;
}
# TODO: Insert CM
$self->createLink($plink, "TODO:CM", $vnodevname, "lan/$vname",
$self->createLink($plink, $cmid, $vnodevname, "lan/$vname",
$top_bw == 0 ? "*" : max($top_bw,$top_rbw),
$protocol, $others);
......@@ -2664,19 +2686,18 @@ sub GenVirtLans($)
my @delayinfo = ($delay,$bw,$backfill,$loss,
$rdelay,$rbw,$rbackfill,$rloss,0);
# TODO: Insert CM
$self->createNode($delayname, "TODO:CM", "delay", 1,
$self->createNode($delayname, $cmid, "delay", '1',
{ "$delaydesirename"
=>
[$delaydesiretype, $delaydesirepenalty});
[$delaydesiretype, $delaydesirepenalty]},
undef);
# $self->addnode("$delayname delay $delaydesire");
# TODO: Insert CM
my $others = {};
if ($fixsrc0) {
$others{'fixsrciface'} = $fixi0;
$others->{'fixsrciface'} = $fixi0;
}
$self->createLink("linkdelaysrc/$vname/$member", "TODO:CM",
$self->createLink("linkdelaysrc/$vname/$member", $cmid,
$vnodevname, $delayname,
$top_bw == 0 ? "*" : $top_bw,
$protocol, $others);
......@@ -2686,8 +2707,7 @@ sub GenVirtLans($)
# ($top_bw == 0 ? "*" : $top_bw) .
# " 0 0 $protocol $fixsrc0");
# TODO: Insert CM
$self->createLink("linkdelaysrc/$vname/$member", "TODO:CM",
$self->createLink("linkdelaysrc/$vname/$member", $cmid,
"lan/$vname", $delayname,
$top_bw == 0 ? "*" : $top_bw,
$protocol, $others);
......@@ -2722,13 +2742,13 @@ sub GenVirtLans($)
# my $spec = "$plink $vnodevname lan/$vname ";
my $others = {};
if ($emulated) {
$others{'emulated'} = 1;
$others->{'emulated'} = 1;
}
if ($trivial_ok) {
$others{'trivial_ok'} = 1;
$others->{'trivial_ok'} = 1;
}
if ($fixsrc0) {
$others{'fixsrciface'} = $fixsrc0;
$others->{'fixsrciface'} = $fixsrc0;
}
# Let assign choose bw if top_bw is zero.
......@@ -2755,16 +2775,14 @@ sub GenVirtLans($)
[$delay,$bw,$backfill,$loss,
$rdelay,$rbw,$rbackfill,$rloss,1];
}
}
# if ($fixsrc0) {
# $spec .= " $fixsrc0";
# }
# TODO: Insert CM
$self->createLink("linklan/$vname/$member", "TODO:CM",
$vnodename, "lan/$vname",
$self->createLink("linklan/$vname/$member", $cmid,
"$vnodevname", "lan/$vname",
($top_bw == 0 ? "*" : $top_bw), $protocol,
$others);
$self->addlink($spec);
# $self->addlink($spec);
}
}
}
......@@ -2803,7 +2821,7 @@ sub PrintTop($;$)
#
# Print the rspec part of the topo. Eventually the whole thing needs
# to be in rspec. The RSPEC prints the results in v1 format
# to be in rspec. The RSPEC prints the results in v2 format
#
sub PrintRspec($;$)
{
......@@ -2833,14 +2851,13 @@ sub PrintRspec($;$)
$doc->setDocumentElement($root);
foreach my $ref (@{$self->results->{'nodeslinks'}}) {
my ($which, $what) = @{ $ref };
if ($which eq "node") {
$self->processNode($doc, $root, $what);
}
else {
$self->processLink($doc, $root, $what);
foreach my $ref (@{$self->rspec()->{'node'}}) {
# my ($which, $what) = @{ $ref };
$self->processNodeRspec($doc, $root, $ref);
}
foreach my $ref (@{$self->rspec()->{'link'}}) {
# my ($which, $what) = @{ $ref };
$self->processLinkRspec($doc, $root, $ref);
}
print $output $doc->toString(1) . "\n";
......@@ -6822,6 +6839,14 @@ sub addNode($$$)
return $newNode;
}
sub addNodeRspec ($$$)
{
my ($doc, $root, $name) = @_;
my $newnode = $doc->createElement($name);
$root->appendChild($newnode);
return $newnode;
}
#
# Creates a child node with name "nodeName" whose parent is "parent"
# in the XML document "document" The child node has a textnode within
......@@ -6843,12 +6868,16 @@ sub addNodeWithText($$$$)
#
sub processNodeRspec ($$$$)
{
my ($self, $xmlDocument, $root, $line) = @_;
my ($nodename, $nodetype, @tokens) = split(/\s+/, $line);
my $newNode = addNode ($xmlDocument, $root, "node");
# TODO: Add extensions
my ($self, $doc, $root, $node) = @_;
my $rspecnode = addNodeRspec ($doc, $root, 'node');
$rspecnode->setAttribute('client_id', $node->{'name'});
$rspecnode->setAttribute('component_manager_id', $node->{'cm'});
my $slivertype = addNodeRspec($doc, $rspecnode, 'sliver_type');
$slivertype->setAttribute('name', $node->{'node_type'});
my $typecount = addNodeRspec($doc, $slivertype, 'emulab:ext_node_type');
$typecount->setAttribute('type_slots', $node->{'type_slots'});
}
#
......@@ -6958,6 +6987,24 @@ sub processNode($$$$)
return 0;
}
sub processLinkRspec ($$$$)
{
my ($self, $doc, $root, $link) = @_;
my $rspeclink = addNodeRspec($doc, $root, 'link');
$rspeclink->setAttribute('client_id', $link->{'name'});
$rspeclink->setAttribute('component_manager_id', $link->{'cm'});
my $linktype = addNodeRspec($doc, $rspeclink, 'link_type');
$linktype->setAttribute('name', $link->{'link_type'});
my $interfaceref;
$interfaceref = addNodeRspec($doc, $rspeclink, 'interface_ref');
$interfaceref->setAttribute('src', $link->{'interface_ref'}->[0]);
$interfaceref->setAttribute('dst', $link->{'interface_ref'}->[1]);
$interfaceref->setAttribute('capacity', $link->{'capacity'});
$interfaceref->setAttribute('latency', $link->{'latency'});
$interfaceref->setAttribute('packet_loss', $link->{'packet_loss'});
}
#
# Processes a link
#
......
......@@ -478,7 +478,8 @@ sub RunAssign($$)
tberror("Could not open $vtopfile: $!\n");
return -1;
}
if ($vtop->PrintTop(*VTOPFILE) != 0) {
# if ($vtop->PrintTop(*VTOPFILE) != 0) {
if ($vtop->PrintRspec(*VTOPFILE) != 0) {
tberror("Could not print vtop file for $experiment\n");
return -1;
}
......
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