Commit 04695250 authored by Jonathon Duerig's avatar Jonathon Duerig

Optimization checkpoint for ptopgen_new.

ptopgen_new is now merely twice as slow as the original.
parent 6481b25d
...@@ -65,6 +65,10 @@ our %auxtypemap = (); ...@@ -65,6 +65,10 @@ our %auxtypemap = ();
# Map from type names to lists of features # Map from type names to lists of features
our %typefeatures = (); our %typefeatures = ();
# Mapping from types to the 'forwarding_protocols' node_type_attribute
our %type_forwarding = ();
# Mapping from types to the 'dedicated_widearea' node_type_attribute
our %type_dedicatedwa = ();
# Keyed by osids. Contains OsInfo structures # Keyed by osids. Contains OsInfo structures
our %osinfo = (); our %osinfo = ();
...@@ -141,7 +145,7 @@ sub LookupNodes() ...@@ -141,7 +145,7 @@ sub LookupNodes()
my $dbresult; my $dbresult;
my $row; my $row;
# Bulk lookup on nodes table # Bulk lookup on nodes table
$dbresult = DBQueryFatal("select * from nodes"); $dbresult = DBQueryFatal("select * from nodes where role='testnode' or role='testswitch' or role='widearea_switch' or role='testnodefoo'");
while ($row = $dbresult->fetchrow_hashref()) { while ($row = $dbresult->fetchrow_hashref()) {
my $node = libptop::pnode->Create($row); my $node = libptop::pnode->Create($row);
if (defined($node)) { if (defined($node)) {
...@@ -149,7 +153,7 @@ sub LookupNodes() ...@@ -149,7 +153,7 @@ sub LookupNodes()
$node->set_eventstate($row->{'eventstate'}); $node->set_eventstate($row->{'eventstate'});
if (! defined($node->type()) && $debug) { if (! defined($node->type()) && $debug) {
die("****Node $node had a type not in node_types table.\n"); die("****Node $node had a type not in node_types table.\n");
} }
} elsif ($debug) { } elsif ($debug) {
print STDERR "Failed to create node $node from database row.\n"; print STDERR "Failed to create node $node from database row.\n";
} }
...@@ -213,6 +217,19 @@ sub LookupNodes() ...@@ -213,6 +217,19 @@ sub LookupNodes()
} }
} }
# Bulk lookup on node_type_attributes
$dbresult = DBQueryFatal("select type, attrkey, attrvalue ".
"from node_type_attributes ".
"where attrkey='forwarding_protocols' ".
"or attrkey='dedicated_widearea'");
while (my ($type, $key, $value) = $dbresult->fetchrow_array()) {
if ($key eq "forwarding_protocols") {
$type_forwarding{$type} = $value;
} elsif ($key eq "dedicated_widearea") {
$type_dedicatedwa{$type} = $value
}
}
TBGetSiteVar('general/default_longitude', \$default_longitude); TBGetSiteVar('general/default_longitude', \$default_longitude);
TBGetSiteVar('general/default_latitude', \$default_latitude); TBGetSiteVar('general/default_latitude', \$default_latitude);
TBGetSiteVar('general/default_country', \$default_country); TBGetSiteVar('general/default_country', \$default_country);
...@@ -229,14 +246,14 @@ sub LookupPermissions() ...@@ -229,14 +246,14 @@ sub LookupPermissions()
# projects which it is attached to. # projects which it is attached to.
my $dbresult = my $dbresult =
DBQueryFatal("select distinct type ". DBQueryFatal("select distinct type ".
"from nodetypeXpid_permissions"); "from nodetypeXpid_permissions");
while (my ($type) = $dbresult->fetchrow_array()) { while (my ($type) = $dbresult->fetchrow_array()) {
$permissions{$type} = 0; $permissions{$type} = 0;
} }
$dbresult = $dbresult =
DBQueryFatal("select type ". DBQueryFatal("select type ".
"from nodetypeXpid_permissions ". "from nodetypeXpid_permissions ".
"where pid='$user_project'"); "where pid='$user_project'");
while (my ($type) = $dbresult->fetchrow_array()) { while (my ($type) = $dbresult->fetchrow_array()) {
$permissions{$type} = 1; $permissions{$type} = 1;
} }
...@@ -284,7 +301,12 @@ sub LookupAuxtypes() ...@@ -284,7 +301,12 @@ sub LookupAuxtypes()
# #
$dbresult = DBQueryFatal("select node_id, type, count from node_auxtypes"); $dbresult = DBQueryFatal("select node_id, type, count from node_auxtypes");
while (my ($node_id, $type, $count) = $dbresult->fetchrow_array()) { while (my ($node_id, $type, $count) = $dbresult->fetchrow_array()) {
$nodeList{$node_id}->addAuxtype($type, $count); my $node = $nodeList{$node_id};
if (defined($node)) {
$node->addAuxtype($type, $count);
} elsif ($debug) {
print STDERR "Node $node_id in node_auxtypes but not in nodes\n";
}
} }
} }
...@@ -505,7 +527,7 @@ sub AddSharedBandwidth() ...@@ -505,7 +527,7 @@ sub AddSharedBandwidth()
if (! exists($sharedbw{"$node:$iface"})) { if (! exists($sharedbw{"$node:$iface"})) {
my $bw = $interfaceList{"$node:$iface"}->remaining_bandwidth(); my $bw = $interfaceList{"$node:$iface"}->remaining_bandwidth();
$sharedbw{"$node:$iface"} = Math::BigInt->new($bw); $sharedbw{"$node:$iface"} = $bw;
} }
$sharedbw{"$node:$iface"} += $bandwidth; $sharedbw{"$node:$iface"} += $bandwidth;
} }
...@@ -632,7 +654,7 @@ sub SwitchBandwidth($$) ...@@ -632,7 +654,7 @@ sub SwitchBandwidth($$)
# Default to 100 MBit. The default should never be used unless # Default to 100 MBit. The default should never be used unless
# there is an error in the database. If the wires table references # there is an error in the database. If the wires table references
# a node which doesn't exist, for instance. # a node which doesn't exist, for instance.
my $result = Math::BigInt->new(100000); my $result = 100000;
if (defined($node)) { if (defined($node)) {
my $basetype = $node->get_basetype(); my $basetype = $node->get_basetype();
$result = TypeBandwidth($nodename, $iface, $basetype); $result = TypeBandwidth($nodename, $iface, $basetype);
...@@ -656,19 +678,19 @@ sub TypeBandwidth($$$) ...@@ -656,19 +678,19 @@ sub TypeBandwidth($$$)
} }
} }
} }
return Math::BigInt->new($result); return $result;
} }
sub ShareBandwidth($$) sub ShareBandwidth($$)
{ {
my ($node, $iface) = @_; my ($node, $iface) = @_;
my $result = Math::BigInt->new(0); my $result = 0;
if (exists($sharedbw{"$node:$iface"})) { if (exists($sharedbw{"$node:$iface"})) {
$result = $sharedbw{"$node:$iface"}; $result = $sharedbw{"$node:$iface"};
} elsif (exists($interfaceList{"$node:$iface"})) { } elsif (exists($interfaceList{"$node:$iface"})) {
$result = $interfaceList{"$node:$iface"}->remaining_bandwidth(); $result = $interfaceList{"$node:$iface"}->remaining_bandwidth();
} }
return Math::BigInt->new($result); return $result;
} }
sub make_ip($) sub make_ip($)
...@@ -782,8 +804,7 @@ sub set_eventstate($) { $_[0]->{'EVENTSTATE'} = $_[1]; } ...@@ -782,8 +804,7 @@ sub set_eventstate($) { $_[0]->{'EVENTSTATE'} = $_[1]; }
sub get_basetype($) sub get_basetype($)
{ {
my ($self) = @_; my ($self) = @_;
my $result = undef; my $result = $type_forwarding{$self->node()->type()};
$self->node()->NodeTypeAttribute("forwarding_protocols", \$result);
if (! defined($result)) { if (! defined($result)) {
$result = "ethernet"; $result = "ethernet";
} }
...@@ -800,12 +821,11 @@ sub set_reserved($$) ...@@ -800,12 +821,11 @@ sub set_reserved($$)
{ {
my ($self, $row) = @_; my ($self, $row) = @_;
if (defined($row)) { if (defined($row)) {
my $node = $self->node(); # $self->node()->SetReservedRow($row);
$node->SetReservedRow($row); $self->{'SHARED'} = $row->{'sharing_mode'};
$self->{'SHARED'} = $node->sharing_mode(); $self->{'EID'} = $row->{'eid'};
$self->{'EID'} = $node->eid(); $self->{'PID'} = $row->{'pid'};
$self->{'PID'} = $node->pid(); $self->{'EROLE'} = $row->{'erole'};
$self->{'EROLE'} = $node->erole();
} }
} }
...@@ -878,6 +898,14 @@ sub available($;$) ...@@ -878,6 +898,14 @@ sub available($;$)
} }
sub isswitch($) sub isswitch($)
{
if (! defined($_[0]->{'IS_SWITCH'})) {
$_[0]->{'IS_SWITCH'} = $_[0]->calculateSwitch();
}
return $_[0]->{'IS_SWITCH'};
}
sub calculateSwitch($)
{ {
my ($self) = @_; my ($self) = @_;
my $role = $self->node()->role(); my $role = $self->node()->role();
...@@ -886,23 +914,39 @@ sub isswitch($) ...@@ -886,23 +914,39 @@ sub isswitch($)
} }
sub islocal($) sub islocal($)
{
if (! defined($_[0]->{'IS_LOCAL'})) {
$_[0]->{'IS_LOCAL'} = $_[0]->calculateLocal();
}
return $_[0]->{'IS_LOCAL'};
}
sub calculateLocal($)
{ {
my ($self) = @_; my ($self) = @_;
my $node = $self->node(); my $node = $self->node();
my $isremotenode = $node->isremotenode(); my $isremotenode = $node->isremotenode();
my $wa_attrvalue = $node->NodeTypeAttribute('dedicated_widearea'); my $wa_attrvalue = $type_dedicatedwa{$node->type()};
return ( $node->role() eq 'testnode' return ( $node->role() eq 'testnode'
&& ((! defined($isremotenode) || $isremotenode == 0) && ((! defined($isremotenode) || $isremotenode == 0)
|| (defined($wa_attrvalue) && $wa_attrvalue == 1))); || (defined($wa_attrvalue) && $wa_attrvalue == 1)));
} }
sub iswidearea($) sub iswidearea($)
{
if (! defined($_[0]->{'IS_WIDEAREA'})) {
$_[0]->{'IS_WIDEAREA'} = $_[0]->calculateWidearea();
}
return $_[0]->{'IS_WIDEAREA'};
}
sub calculateWidearea($)
{ {
my ($self) = @_; my ($self) = @_;
my $node = $self->node(); my $node = $self->node();
my $isremotenode = $node->isremotenode(); my $isremotenode = $node->isremotenode();
my $isvirtnode = $node-> isvirtnode(); my $isvirtnode = $node-> isvirtnode();
my $wa_attrvalue = $node->NodeTypeAttribute('dedicated_widearea'); my $wa_attrvalue = $type_dedicatedwa{$node->type()};
return ($node->role() eq 'testnode' return ($node->role() eq 'testnode'
&& defined($isremotenode) && defined($isremotenode)
&& $isremotenode == 1 && $isremotenode == 1
...@@ -1078,7 +1122,7 @@ sub processLocal($) ...@@ -1078,7 +1122,7 @@ sub processLocal($)
# This is for the case that we are modifying an existing experiment - tell # This is for the case that we are modifying an existing experiment - tell
# assign to prefer nodes the user has already allocated # assign to prefer nodes the user has already allocated
if (defined($exempt_eid) && $available_only if (defined($exempt_eid) && $available_only
&& defined($node->eid()) && defined($node->pid())) { && defined($self->eid()) && defined($self->pid())) {
$self->addFeature('already_reserved', 0); $self->addFeature('already_reserved', 0);
} }
$self->processSubnode(); $self->processSubnode();
...@@ -1385,7 +1429,7 @@ sub processWidearea($) ...@@ -1385,7 +1429,7 @@ sub processWidearea($)
} }
return; return;
} }
if (! defined($node->eid()) || ! defined($node->pid())) { if (! defined($self->eid()) || ! defined($self->pid())) {
if ($debug) { if ($debug) {
print STDERR "Widearea node is not reserved to an eid or pid". print STDERR "Widearea node is not reserved to an eid or pid".
$node->node_id()."\n"; $node->node_id()."\n";
...@@ -1393,7 +1437,7 @@ sub processWidearea($) ...@@ -1393,7 +1437,7 @@ sub processWidearea($)
return; return;
} }
if ($self->status() ne 'up' || if ($self->status() ne 'up' ||
($node->eid() eq NODEDEAD_EID() || $node->pid() eq NODEDEAD_PID())) { ($self->eid() eq NODEDEAD_EID() || $self->pid() eq NODEDEAD_PID())) {
if ($genimode) { if ($genimode) {
return; return;
} }
...@@ -1820,7 +1864,6 @@ sub toXML($$) ...@@ -1820,7 +1864,6 @@ sub toXML($$)
package libptop::plink; package libptop::plink;
use libdb qw(TBOSID TB_OPSPID); use libdb qw(TBOSID TB_OPSPID);
use Math::BigInt;
sub Create($) sub Create($)
{ {
...@@ -1836,7 +1879,7 @@ sub Create($) ...@@ -1836,7 +1879,7 @@ sub Create($)
$self->{'DEST_IF'} = undef; $self->{'DEST_IF'} = undef;
$self->{'DEST_CARD'} = undef; $self->{'DEST_CARD'} = undef;
$self->{'DEST_PORT'} = undef; $self->{'DEST_PORT'} = undef;
$self->{'BW'} = Math::BigInt->new(0); $self->{'BW'} = 0;
$self->{'DELAY'} = 0; $self->{'DELAY'} = 0;
$self->{'LOSS'} = 0.0; $self->{'LOSS'} = 0.0;
$self->{'TYPES'} = []; $self->{'TYPES'} = [];
...@@ -1982,7 +2025,7 @@ sub toString($) ...@@ -1982,7 +2025,7 @@ sub toString($)
$result .= $self->source() . "/" . $self->sourceif() . " "; $result .= $self->source() . "/" . $self->sourceif() . " ";
$result .= $self->dest() . ":"; $result .= $self->dest() . ":";
$result .= $self->dest() . "/" . $self->destif() . " "; $result .= $self->dest() . "/" . $self->destif() . " ";
$result .= $self->bw()->bstr() . " "; $result .= $self->bw() . " ";
$result .= $self->delay() . " "; $result .= $self->delay() . " ";
$result .= $self->loss() . " "; $result .= $self->loss() . " ";
$result .= "1 " . join(" ", @{ $self->types() }); $result .= "1 " . join(" ", @{ $self->types() });
...@@ -1999,7 +2042,7 @@ sub toXML($$) ...@@ -1999,7 +2042,7 @@ sub toXML($$)
GeniXML::SetText("component_manager_uuid", $xml, $cmurn); GeniXML::SetText("component_manager_uuid", $xml, $cmurn);
GeniXML::SetText("component_uuid", $xml, $urn); GeniXML::SetText("component_uuid", $xml, $urn);
my $bw = GeniXML::AddElement("bandwidth", $xml); my $bw = GeniXML::AddElement("bandwidth", $xml);
$bw->appendText($self->bw()->bstr()); $bw->appendText($self->bw());
my $latency = GeniXML::AddElement("latency", $xml); my $latency = GeniXML::AddElement("latency", $xml);
$latency->appendText($self->delay()); $latency->appendText($self->delay());
my $loss = GeniXML::AddElement("packet_loss", $xml); my $loss = GeniXML::AddElement("packet_loss", $xml);
...@@ -2010,11 +2053,11 @@ sub toXML($$) ...@@ -2010,11 +2053,11 @@ sub toXML($$)
GeniXML::SetText("component_id", $xml, $urn); GeniXML::SetText("component_id", $xml, $urn);
$self->propertyToXml($xml, $self->source(), $self->sourceif(), $self->propertyToXml($xml, $self->source(), $self->sourceif(),
$self->dest(), $self->destif(), $self->dest(), $self->destif(),
$self->bw()->bstr(), $self->delay(), $self->bw(), $self->delay(),
$self->loss()); $self->loss());
$self->propertyToXml($xml, $self->dest(), $self->destif(), $self->propertyToXml($xml, $self->dest(), $self->destif(),
$self->source(), $self->sourceif(), $self->source(), $self->sourceif(),
$self->bw()->bstr(), $self->delay(), $self->bw(), $self->delay(),
$self->loss()); $self->loss());
} }
GeniXML::SetText("component_name", $xml, $self->name()); GeniXML::SetText("component_name", $xml, $self->name());
......
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