mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 01:31:55 +00:00
87b60bf7e8
we can use very simple function which is monotonic with respect to re-hashing: n ^= n >> 16; n ^= n << 10; h = (n >> (16 - o)) & ((1 << o) - 1); where o is table order. Statistical analysis for both backbone routing table and local OSPF routing tables gives values near theoretical optimum for uniform distribution (see ips.c for formulae). The trick is very simple: We always calculate a 16-bit hash value n and use o most significant bits (this gives us monotonity wrt. rehashing if we sort the chains by the value of n). The first shift/xor pair reduces the IP address to a 16-bit one, the second pair makes higher bits of the 16-bit value uniformly distributed even for tables containing lots of long prefixes (typical interior routing case with 24-bit or even longer prefixes).
21 lines
492 B
Perl
Executable File
21 lines
492 B
Perl
Executable File
#!/usr/bin/perl
|
|
#
|
|
# Convert Cisco routing table listing to list of prefixes
|
|
#
|
|
|
|
$loc = ($ARGV[0] eq "-l"); # Print only local prefixes
|
|
|
|
while (<STDIN>) {
|
|
($loc ? /^[OR]\s/ : /^B\s/) || next;
|
|
/^[ORB]( E[12])?\s+(\d+\.\d+\.\d+\.\d+)(\s|\/\d+\s)/ || die "Cannot parse $_";
|
|
$net = $2;
|
|
$len = $3;
|
|
if ($len =~ /^\s*$/) {
|
|
# Magic rule :)
|
|
$len = ($net =~ /\.0$/) ? 24 : 32;
|
|
}
|
|
$len =~ s/^\///;
|
|
$net =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
|
|
printf "%02x%02x%02x%02x/%d\n", $1, $2, $3, $4, $len;
|
|
}
|