Commit cbffaa71 authored by Christopher Alfeld's avatar Christopher Alfeld

Added lindex by subnet code.

parent 76796608
......@@ -150,6 +150,17 @@ sub gen_reach {
}
}
# this is a sorting routine that takes two pairs of [node,ip] and sorts
# by the subnets of the ip.
sub sortbysubnet {
local($ipa) = @{$a}[1];
local($ipb) = @{$b}[1];
local($subneta) = ($ipa =~ /^[0-9]+\.[0-9]+\.([0-9]+)\.[0-9]+$/);
local($subnetb) = ($ipb =~ /^[0-9]+\.[0-9]+\.([0-9]+)\.[0-9]+$/);
return $subneta <=> $subnetb;
};
# main loop
foreach $node (keys(%rvnodemap)) {
if (! defined($delays{$node})) {
......@@ -168,17 +179,35 @@ foreach $node (keys(%rvnodemap)) {
}
# reach now contains all mac addresses we need to add an ip for
# we need to generate lindex's by subnet order.
@dests = ();
foreach $mac (@reach) {
($dstnode) = (&mac2node($mac))[0];
if ($dstnode eq $node) {
# we have a loop, but that's not our problem
next;
}
$sth = $dbh->prepare("SELECT IP from virt_names where src_node_id = \"$node\" and dest_node_id = \"$dstnode\"");
$sth->execute;
$lindex = $sth->rows;
$sth->finish;
$sth = $dbh->prepare("INSERT into virt_names (src_node_id,dest_node_id,lindex,ip) values (\"$node\",\"$dstnode\",$lindex,\"$ipmap{$mac}\")");
$ip = $ipmap{$mac};
push(@dests,[$dstnode,$ipmap{$mac}]);
}
@sortdests = sort sortbysubnet @dests;
# Now we add them to the table. In the case of duplicate
# dests we increment the lindex. As the list is sorted by
# subnet the lindex will correspond to the first, second, etc.
# subnet.
$lindex = 0;
$lastdest = "";
foreach $dest (@sortdests) {
($dest,$ip) = @$dest;
if ($dest ne $lastdest) {
$lindex = 0;
$lastdest = $dest;
} else {
$lindex++;
}
$sth = $dbh->prepare("INSERT into virt_names (src_node_id,dest_node_id,lindex,ip) values (\"$node\",\"$dest\",$lindex,\"$ip\")");
$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