Commit 6af03a3d authored by Christopher Alfeld's avatar Christopher Alfeld
Browse files

Fixed bug. Works fine now with multiple delays per PC.

parent cfe745d5
......@@ -22,6 +22,13 @@
# if Y belongs to other node add to reach
# else gen_reach(Y)
$verbose = 0;
sub printdb {
if ($verbose) {
print "$_[0]";
}
};
my $IRLIB = "@prefix@/lib/ir";
my $DBNAME = "@TBDBNAME@";
......@@ -91,6 +98,8 @@ foreach (split("\n",&ir_get("/virtual/nodes"))) {
foreach (split("\n",&ir_get("/delay"))) {
@info = split;
($node,$maca,$macb) = @info[0,4,5];
$odelay{$maca} = $macb;
$odelay{$macb} = $maca;
$delays{$node} = [$maca,$macb];
}
......@@ -111,7 +120,9 @@ sub mac2node {
# is used to avoid loops. Both should be reset before a top-level call.
sub gen_reach {
local($mac) = @_;
printdb " gen_reach $mac (".&mac2node($mac).") (".join(" ",@reach).")\n";
if (grep(/^$mac$/,@done)) {
printdb " done\n";
return;
}
push(@done,$mac);
......@@ -131,19 +142,17 @@ sub gen_reach {
foreach $omac (@{$vlanmap{$vlan}}) {
if ($omac ne $mac) {
($node) = (&mac2node($omac))[0];
printdb " $omac = $node\n";
if (! defined($delays{$node})) {
# found a reach
if (!grep(/^$omac$/,@reach)) {
printdb " Found reach $omac (".&mac2node($omac).")\n";
push(@reach,$omac);
}
} else {
# let's find the other side
($maca,$macb) = @{$delays{$node}};
if ($maca eq $omac) {
$nextmac = $macb;
} else {
$nextmac = $maca;
}
$nextmac = $odelay{$omac};
printdb " recursing (@reach)\n";
&gen_reach($nextmac);
}
}
......@@ -159,6 +168,7 @@ sub sortbysubnet {
# main loop
foreach $node (keys(%rvnodemap)) {
if (! defined($delays{$node})) {
printdb "\nHandling $node\n";
# remove all dest entries for node from virt_names
$sth=$dbh->prepare("DELETE from virt_names where dest_node_id = \"$node\"");
$sth->execute;
......@@ -169,9 +179,11 @@ foreach $node (keys(%rvnodemap)) {
$sth->execute;
@macs = ();
while (($mac) = $sth->fetchrow_array) {
printdb " $mac - resetting done\n";
@reach = ();
@done = ();
&gen_reach($mac);
printdb " reach = @reach\n";
if (@reach) {
$macreach{$mac} = [];
push(@{$macreach{$mac}},@reach);
......@@ -180,12 +192,16 @@ foreach $node (keys(%rvnodemap)) {
}
$sth->finish;
@sortmacs = sort sortbysubnet @macs;
printdb "Adding to DB\n";
# add to DB
$lindex = 0;
foreach $mac (@sortmacs) {
printdb "$mac (".&mac2node($mac).")has reach\n";
foreach $src (@{$macreach{$mac}}) {
$srcnode = (&mac2node($src))[0];
printdb " $src - $srcnode\n";
$sth = $dbh->prepare("INSERT into virt_names (src_node_id,dest_node_id,lindex,ip) values (\"$srcnode\",\"$node\",$lindex,\"$ipmap{$mac}\")");
$sth->execute;
$sth->finish;
......
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