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