| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
########################################################################## |
|
4
|
|
|
|
|
|
|
# Copyright (c) 2010-2012 Alexander Bluhm |
|
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
|
|
|
7
|
|
1509924
|
use strict; |
|
|
7
|
|
|
5
|
|
21
|
|
|
|
7
|
|
|
|
|
224
|
|
|
|
5
|
|
|
|
|
15419381
|
|
|
|
5
|
|
|
|
|
134
|
|
|
|
5
|
|
|
|
|
672
|
|
|
20
|
7
|
|
|
7
|
|
30
|
use warnings; |
|
|
7
|
|
|
5
|
|
19
|
|
|
|
7
|
|
|
|
|
210
|
|
|
|
5
|
|
|
|
|
156
|
|
|
|
5
|
|
|
|
|
60
|
|
|
|
5
|
|
|
|
|
630
|
|
|
21
|
7
|
|
|
7
|
|
583
|
use File::Slurp; |
|
|
7
|
|
|
5
|
|
29449
|
|
|
|
7
|
|
|
|
|
399
|
|
|
|
5
|
|
|
|
|
105
|
|
|
|
5
|
|
|
|
|
73
|
|
|
|
5
|
|
|
|
|
1650
|
|
|
22
|
7
|
|
|
7
|
|
4543
|
use Getopt::Long qw(:config posix_default bundling); |
|
|
7
|
|
|
5
|
|
62918
|
|
|
|
7
|
|
|
|
|
23
|
|
|
|
5
|
|
|
|
|
87
|
|
|
|
5
|
|
|
|
|
75
|
|
|
|
5
|
|
|
|
|
186
|
|
|
23
|
7
|
|
|
7
|
|
6307
|
use OSPF::LSDB::View; |
|
|
7
|
|
|
5
|
|
22
|
|
|
|
7
|
|
|
|
|
226
|
|
|
|
5
|
|
|
|
|
3347
|
|
|
|
5
|
|
|
|
|
40
|
|
|
|
5
|
|
|
|
|
378
|
|
|
24
|
7
|
|
|
7
|
|
4109
|
use OSPF::LSDB::View6; |
|
|
7
|
|
|
5
|
|
22
|
|
|
|
7
|
|
|
|
|
210
|
|
|
|
5
|
|
|
|
|
53
|
|
|
|
5
|
|
|
|
|
27
|
|
|
|
5
|
|
|
|
|
345
|
|
|
25
|
7
|
|
|
7
|
|
2722
|
use OSPF::LSDB::YAML; |
|
|
7
|
|
|
5
|
|
15
|
|
|
|
7
|
|
|
|
|
4685
|
|
|
|
5
|
|
|
|
|
108
|
|
|
|
5
|
|
|
|
|
25
|
|
|
|
5
|
|
|
|
|
8071
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub usage(@) { |
|
28
|
6
|
100
|
|
6
|
|
155
|
print STDERR "Error: @_\n" if @_; |
|
29
|
6
|
|
|
|
|
145
|
print STDERR <
|
|
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
|
|
|
|
|
525
|
exit(2); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub main() { |
|
56
|
7
|
|
|
7
|
|
81
|
my %todo; |
|
57
|
|
|
|
|
|
|
my $ipv6; |
|
58
|
7
|
|
|
|
|
0
|
my $legend; |
|
59
|
|
|
|
|
|
|
GetOptions( |
|
60
|
0
|
|
|
0
|
|
0
|
'4' => sub { $ipv6 = 0 }, |
|
61
|
0
|
|
|
0
|
|
0
|
'6' => sub { $ipv6 = 1 }, |
|
62
|
1
|
|
|
1
|
|
1135
|
'b' => sub { $todo{boundary}{generate} = 1 }, |
|
63
|
2
|
|
|
2
|
|
225
|
'B' => sub { $todo{boundary}{aggregate} = 1 }, |
|
64
|
1
|
|
|
1
|
|
859
|
'c' => sub { $todo{cluster} = 1 }, |
|
65
|
1
|
|
|
1
|
|
1206
|
'e' => sub { $todo{external}{generate} = 1 }, |
|
66
|
2
|
|
|
2
|
|
173
|
'E' => sub { $todo{external}{aggregate} = 1 }, |
|
67
|
1
|
|
|
1
|
|
874
|
'h' => sub { usage() }, |
|
68
|
|
|
|
|
|
|
'l' => \$legend, |
|
69
|
1
|
|
|
1
|
|
1280
|
'p' => sub { $todo{prefix}{generate} = 1 }, |
|
70
|
1
|
|
|
1
|
|
102
|
'P' => sub { $todo{prefix}{aggregate} = 1 }, |
|
71
|
1
|
|
|
1
|
|
1220
|
's' => sub { $todo{summary}{generate} = 1 }, |
|
72
|
2
|
|
|
2
|
|
179
|
'S' => sub { $todo{summary}{aggregate} = 1 }, |
|
73
|
1
|
|
|
1
|
|
1220
|
'w' => sub { $todo{warning}{single} = 1 }, |
|
74
|
1
|
|
|
1
|
|
92
|
'W' => sub { $todo{warning}{all} = 1 }, |
|
75
|
0
|
|
|
0
|
|
0
|
'v' => sub { $todo{verbose} = 1 }, |
|
76
|
7
|
50
|
|
|
|
235
|
) or usage("Bad option"); |
|
77
|
6
|
50
|
|
|
|
362
|
usage("Only two arguments allowed") if @ARGV > 2; |
|
78
|
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
16
|
foreach my $option (qw(boundary external prefix summary warning)) { |
|
80
|
20
|
100
|
|
|
|
59
|
if (keys %{$todo{$option} || {}} > 1) { |
|
|
20
|
100
|
|
|
|
622
|
|
|
81
|
5
|
|
|
|
|
23
|
my $opt = substr($option, 0, 1); |
|
82
|
5
|
|
|
|
|
47
|
usage("Options -$opt and -".uc($opt)." used together"); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
2
|
if ($todo{prefix}) { |
|
87
|
0
|
|
|
|
|
0
|
$todo{intra}{generate} = 1; |
|
88
|
0
|
0
|
|
|
|
0
|
$todo{link}{generate} = 1 if $todo{prefix}{generate}; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
2
|
if ($legend) { |
|
92
|
0
|
0
|
|
|
|
0
|
my $class = $ipv6 ? 'OSPF::LSDB::View6' : 'OSPF::LSDB::View'; |
|
93
|
0
|
|
|
|
|
0
|
print $class->legend(); |
|
94
|
0
|
|
|
|
|
0
|
exit 0; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
5
|
my $yaml = OSPF::LSDB::YAML->new(); |
|
98
|
1
|
50
|
|
|
|
4
|
if (@ARGV > 0) { |
|
99
|
1
|
|
|
|
|
2
|
$yaml->LoadFile($ARGV[0]); |
|
100
|
|
|
|
|
|
|
} else { |
|
101
|
0
|
|
|
|
|
0
|
local $/; |
|
102
|
0
|
|
|
|
|
0
|
$yaml->Load(); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
1
|
50
|
33
|
|
|
1015
|
if (defined $ipv6 && $ipv6 != $yaml->ipv6) { |
|
106
|
0
|
|
|
|
|
0
|
die "Address family of yaml file does not match -4 and -6 options.\n"; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
1
|
50
|
|
|
|
2
|
my $class = $yaml->ipv6 ? 'OSPF::LSDB::View6' : 'OSPF::LSDB::View'; |
|
109
|
1
|
|
|
|
|
7
|
my $view = $class->new($yaml); |
|
110
|
1
|
|
|
|
|
4
|
my $dot = $view->graph(%todo); |
|
111
|
1
|
50
|
|
|
|
4
|
if ($todo{verbose}) { |
|
112
|
0
|
|
|
|
|
0
|
my @errors = $view->get_errors; |
|
113
|
0
|
0
|
|
|
|
0
|
warn map { "$_\n" } @errors if @errors; |
|
|
0
|
|
|
|
|
0
|
|
|
114
|
|
|
|
|
|
|
} |
|
115
|
1
|
50
|
|
|
|
4
|
if (@ARGV > 1) { |
|
116
|
1
|
|
|
|
|
4
|
write_file($ARGV[1], $dot); |
|
117
|
|
|
|
|
|
|
} else { |
|
118
|
0
|
|
|
|
|
|
print $dot; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
main(); |