| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright (c) 2010-2012 Alexander Bluhm <alexander.bluhm@gmx.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Permission to use, copy, modify, and distribute this software for any | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # purpose with or without fee is hereby granted, provided that the above | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # copyright notice and this permission notice appear in all copies. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use Getopt::Long qw(:config posix_default bundling); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use OSPF::LSDB::View; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | use OSPF::LSDB::View6; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use OSPF::LSDB::YAML; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub usage(@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | print STDERR "Error: @_\n" if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | print STDERR <<EOF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | Convert OSPF LSDB in YAML format to dot file used by Graphviz. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Usage: $0 [-46bBceEhlpPsSwWv] [ospf.yaml] [ospf.dot] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | -4 disable IPv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | -6 enable IPv6 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | -b generate other area AS boundary router summary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | -B aggregate other area AS boundary router summary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | -c cluster identical networks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | -e generate AS external networks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | -E aggregate AS external networks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | -h help, print usage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | -l generate legend | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | -p generate link and intra-area-prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | -P generate intra-area-prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | -s generate other area network summary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | -S aggregate other area network summary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | -w show most serious warning in dot graph | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | -W show all warnings and areas in dot graph | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | -v be verbose, print warnings to stderr | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ospf.yaml input file, default stdin | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ospf.dot output file, default stdout | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | exit(2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub main() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | my %todo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=17 SCAR=36.7
Subroutine
main: called CC=17 SCAR=36.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | my $ipv6; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | my $legend; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | '4' => sub { $ipv6 = 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | '6' => sub { $ipv6 = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | 'b' => sub { $todo{boundary}{generate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | 'B' => sub { $todo{boundary}{aggregate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | 'c' => sub { $todo{cluster} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | 'e' => sub { $todo{external}{generate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | 'E' => sub { $todo{external}{aggregate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | 'h' => sub { usage() }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 'l' => \$legend, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | 'p' => sub { $todo{prefix}{generate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | 'P' => sub { $todo{prefix}{aggregate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | 's' => sub { $todo{summary}{generate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | 'S' => sub { $todo{summary}{aggregate} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | 'w' => sub { $todo{warning}{single} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | 'W' => sub { $todo{warning}{all} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | 'v' => sub { $todo{verbose} = 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | ▶ | ) or usage("Bad option"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | usage("Only two arguments allowed") if @ARGV > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | foreach my $option (qw(boundary external prefix summary warning)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 23 | ▶ | if (keys %{$todo{$option} || {}} > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | my $opt = substr($option, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | usage("Options -$opt and -".uc($opt)." used together"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | if ($todo{prefix}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $todo{intra}{generate} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $todo{link}{generate} = 1 if $todo{prefix}{generate}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | if ($legend) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $class = $ipv6 ? 'OSPF::LSDB::View6' : 'OSPF::LSDB::View'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | print $class->legend(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | my $yaml = OSPF::LSDB::YAML->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | if (@ARGV > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | $yaml->LoadFile($ARGV[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $yaml->Load(<STDIN>); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | if (defined $ipv6 && $ipv6 != $yaml->ipv6) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $ipv6 and $ipv6 != $yaml->ipv6
defined $ipv6 and $ipv6 != $yaml->ipv6
MC/DC0%0/2
defined $ipv6 and $ipv6 != $yaml->ipv6
defined $ipv6
$ipv6 != $yaml->ipv6
MC/DC0%0/2
defined $ipv6 and $ipv6 != $yaml->ipv6
defined $ipv6
$ipv6 != $yaml->ipv6
Truth table33%1/3
A and B
A= defined $ipv6B= $ipv6 != $yaml->ipv6
Truth table33%1/3
A and B
A= defined $ipv6B= $ipv6 != $yaml->ipv6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | die "Address family of yaml file does not match -4 and -6 options.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | my $class = $yaml->ipv6 ? 'OSPF::LSDB::View6' : 'OSPF::LSDB::View'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | my $view = $class->new($yaml); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | my $dot = $view->graph(%todo); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if ($todo{verbose}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my @errors = $view->get_errors; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | warn map { "$_\n" } @errors if @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | if (@ARGV > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | write_file($ARGV[1], $dot); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | print $dot; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | main(); | |||||||||||||||||||||||||||||||||||||||||||||||||