blib/lib/OSPF/LSDB/View6.pm

filter: Statementstmt 72.3% 660 / 912 Branchbran 54.8% 180 / 328 Conditioncond 67.7% 82 / 121 MC/DCmcdc 58.8% 40 / 68 Subroutinesub 69.7% 30 / 43 Podpod 2.5% 1 / 39 totaltotal 65.7% 993 / 1511 CC 290 SCAR 43.7
CC
290
Cov
68%
create_externaggr
702.0
link2edges
182.0
intranetwork2edges
90.0
CRAP 78.8
« script/ospfview ↑ Summary blib/lib/OSPF/LSDB/Cisco.pm »
1 ##########################################################################
2 # Copyright (c) 2010-2021 Alexander Bluhm <alexander.bluhm@gmx.net>
3 #
4 # Permission to use, copy, modify, and distribute this software for any
5 # purpose with or without fee is hereby granted, provided that the above
6 # copyright notice and this permission notice appear in all copies.
7 #
8 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 ##########################################################################
16  
17 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 =pod
21  
22 =head1 NAME
23  
24 OSPF::LSDB::View6 - display OSPF for IPv6 database as graphviz dot
25  
26 =head1 SYNOPSIS
27  
28 use OSPF::LSDB;
29  
30 use OSPF::LSDB::View6;
31  
32 my $ospf = OSPF::LSDB-E<gt>new();
33  
34 my $view = OSPF::LSDB::View6-E<gt>new($ospf);
35  
36 my $dot = view-E<gt>graph();
37  
38 =head1 DESCRIPTION
39  
40 The OSPF::LSDB::View6 module converts the IPv6 content of a
41 L<OSPF::LSDB> instance into a graphviz dot string.
42  
43 Most of OSPF::LSDB::View6 is derived from L<OSPF::LSDB::View>.
44 Only differences between the v2 and v3 protocoll are implemented
45 and documented by this module.
46  
47 =cut
48  
49 package OSPF::LSDB::View6;
50 11 ▶use base 'OSPF::LSDB::View';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 11 use fields qw (
52 sumlsids
53 boundlsids
54 externlsids
55 lnkhash
56 intraroutehash
57 intranethash
58 11 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 sub new {
61 65 ▶ my OSPF::LSDB::View6 $self = OSPF::LSDB::new(@_);
Subroutine new: called CC=2 SCAR=7.1
Pod documented
62 65 ▶ die "$_[0] does not support IPv4" unless $self->ipv6();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ipv6 0 65 65
63 65 return $self;
64 }
65  
66 ########################################################################
67 # RFC 2740
68 # LSA function code LS Type Description
69 # ----------------------------------------------------
70 # 1 0x2001 Router-LSA
71 ########################################################################
72 # routers => [
73 # area => 'ipv4',
74 # bits => {
75 # B => 'int', # bit B
76 # E => 'int', # bit E
77 # V => 'int', # bit V
78 # W => 'int', # bit W
79 # },
80 # pointtopoints => [] # Point-to-point connection to another router
81 # transits => [] # Connection to a transit network
82 # virtuals => [] # Virtual link
83 # router => 'ipv4', # Link State ID
84 # routerid => 'ipv4', # Advertising Router
85 # ],
86 ########################################################################
87 # $routehash{$routerid} = {
88 # graph => { N => router10, color => red, style => solid, }
89 # hashes => [ { router hash } ]
90 # areas => { $area => 1 }
91 # missing => 1 (optional)
92 # }
93 ########################################################################
94  
95 # take router hash
96 # detect inconsistencies and set colors
97 sub check_router {
98 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_router: called CC=10 SCAR=23.0
Pod undocumented
99 65 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 65 65
100 65 ▶ while (my($rid,$rv) = each %$routehash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$routehash) 133 65 198
101 133 my %colors;
102 133 my @areas = sort keys %{$rv->{areas}};
103 133 ▶ if (@areas > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@areas > 1) { } 23 110 133
104 23 $colors{black} = \@areas;
105 23 ▶ if (my @badareas = map { $_->{area} || () }
Branch: 2 branches
BranchTrueFalseTotal
if (my(@badareas) = map({$_->{"area"} or ();} grep({not $_->{"bits"}{"B"};} @{$$rv{"hashes"};}))) 1 22 23
$_->{"area"} or () 2 1 3
106 47 grep { ! $_->{bits}{B} } @{$rv->{hashes}}) {
107 $self->error($colors{orange} =
108 1 "Router $rid in multiple areas is not border router ".
109 "in areas @badareas.");
110 }
111 } else {
112 110 $colors{gray} = $areas[0];
113 }
114 133 ▶ if ($rv->{missing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv->{'missing'}) { } 10 123 133
115 10 $self->error($colors{red} = "Router $rid missing.");
116 } else {
117 123 ▶ while (my($area,$av) = each %{$rv->{areas}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$rv{"areas"};}) 147 123 270
118 # TODO check wether bits are equal
119 147 ▶ while (my($lsid,$num) = each %$av) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$av) 147 147 294
120 147 ▶ if ($num > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 1) 1 146 147
121 $self->error($colors{magenta} =
122 1 "Router $rid has multiple link state IDs $lsid ".
123 "in area $area.");
124 }
125 }
126 }
127 }
128 133 $rv->{colors} = \%colors;
129 }
130 }
131  
132 # take router hash, routerid,
133 # network hash, summary hash, boundary hash, external hash
134 # add missing routers to router hash
135 sub add_missing_router {
136 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine add_missing_router: called CC=17 SCAR=28.3
Pod undocumented
137 65 my($index) = @_;
138 65 my $boundhash = $self->{boundhash};
139 65 my $externhash = $self->{externhash};
140 # create router hash
141 65 my %rid2areas;
142 12 my @rids = map { keys %{$_->{routers}} }
143 65 map { values %$_ } values %$externhash;
144 65 foreach my $rid (@rids) {
145 # if ase is conneted to boundary router, router is not missing
146 20 ▶ next if $boundhash->{$rid};
Branch: 1 branch
BranchTrueFalseTotal
if $boundhash->{$rid} 10 10 20
147 10 $rid2areas{$rid}{ase} = 1;
148 }
149 65 my $sumhash = $self->{sumhash};
150 29 my @arearids = map { $_->{arearids} }
151 65 (values %$boundhash, map { values %$_ } values %$sumhash);
152 65 foreach my $ar (@arearids) {
153 29 ▶ while (my($area,$av) = each %$ar) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ar) 42 29 71
154 42 ▶ while (my($rid,$num) = each %$av) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$av) 44 42 86
155 44 $rid2areas{$rid}{$area} = 1;
156 }
157 }
158 }
159 65 foreach my $type (qw(pointtopoint virtual)) {
160 130 ▶ my $linkhash = $self->{$type."hash"} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $linkhash = $$self{$type . 'hash'} or die "Uninitialized member" 0 130 130
161 130 ▶ while (my($dstrid,$dv) = each %$linkhash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$linkhash) 22 130 152
162 22 ▶ while (my($area,$av) = each %$dv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$dv) 22 22 44
163 22 $rid2areas{$dstrid}{$area} = 1;
164 }
165 }
166 }
167 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
168 50 my @hashes = map { @{$_->{hashes}} } map { values %$_ }
169 65 map { values %$_ } values %$nethash;
170 65 foreach my $n (@hashes) {
171 52 my $area = $n->{area};
172 52 $rid2areas{$n->{routerid}}{$area} = 1;
173 52 foreach (@{$n->{attachments}}) {
174 103 $rid2areas{$_->{routerid}}{$area} = 1;
175 }
176 }
177 65 my $routerid = $self->{ospf}{self}{routerid};
178 65 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 65 65
179 65 foreach my $rid (sort keys %rid2areas) {
180 115 my $rv = $rid2areas{$rid};
181 115 my $elem = $routehash->{$rid};
182 115 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 10 105 115
183 10 $routehash->{$rid} = $elem = {};
184 $elem->{graph} = {
185 10 N => "router$$index",
186 label => $rid,
187 shape => "box",
188 style => "dotted",
189 };
190 10 $elem->{index} = $$index++;
191 10 ▶ if ($rid eq $routerid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rid eq $routerid) 5 5 10
192 5 $elem->{graph}{peripheries} = 2;
193 }
194 10 push @{$elem->{hashes}}, {};
195 10 $elem->{areas} = $rv;
196 10 $elem->{missing}++;
197 }
198 }
199 }
200  
201 ########################################################################
202 # RFC 2740
203 # Type Description
204 # ---------------------------------------------------
205 # 1 Point-to-point connection to another router
206 ########################################################################
207 # pointtopoints => [
208 # address => 'ipv4', # Neighbor Interface ID
209 # interface => 'ipv4', # Interface ID
210 # metric => 'int', # Metric
211 # routerid => 'ipv4', # Neighbor Router ID
212 # ]
213 ########################################################################
214 # $pointtopointhash{$dst_routerid}{$areas}{$routerid} = {
215 # hashes => [ { link hash } ]
216 # }
217 ########################################################################
218  
219 ########################################################################
220 # RFC 2740
221 # Type Description
222 # ---------------------------------------------------
223 # 4 Virtual link
224 ########################################################################
225 # virtuals => [
226 # address => 'ipv4', # Neighbor Interface ID
227 # interface => 'ipv4', # Interface ID
228 # metric => 'int', # Metric
229 # routerid => 'ipv4', # Neighbor Router ID
230 # ],
231 ########################################################################
232 # $virtualhash{$dst_routerid}{$areas}{$routerid} = {
233 # hashes => [ { link hash } ]
234 # }
235 ########################################################################
236  
237 # take link hash, type (pointtopoint or virtual), router hash
238 # return list of edges from src router to dst router
239 sub router2edges {
240 130 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine router2edges: called CC=19 SCAR=29.5
Pod undocumented
241 130 my($type) = @_;
242 130 ▶ my $name = $type eq "pointtopoint" ? "Point-to-point" : "Virtual";
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'pointtopoint' ? : 65 65 130
243 130 ▶ my $style = $type eq "pointtopoint" ? "solid" : "dotted";
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'pointtopoint' ? : 65 65 130
244 130 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 130 130
245 130 ▶ my $linkhash = $self->{$type."hash"} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $linkhash = $$self{$type . 'hash'} or die "Uninitialized member" 0 130 130
246 130 my $ifaddrs = $self->{ifaddrs};
247 130 my @elements;
248 130 my $index = 0;
249 130 foreach my $dstrid (sort keys %$linkhash) {
250 22 my $dv = $linkhash->{$dstrid};
251 22 foreach my $area (sort keys %$dv) {
252 22 my $ev = $dv->{$area};
253 22 foreach my $rid (sort keys %$ev) {
254 22 my $rv = $ev->{$rid};
255 22 my %colors = (gray => $area);
256 22 my $src = $routehash->{$rid}{graph}{N};
257 22 my $dst = $routehash->{$dstrid}{graph}{N};
258 22 my @hashes = @{$rv->{hashes}};
259 22 ▶ if ($type ne "pointtopoint" && @hashes > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "pointtopoint" and @hashes > 1) 2 20 22
Condition100%3/3
$type ne "pointtopoint" and @hashes > 1
!ll&&!rl&&r
1282
MC/DC100%2/2
$type ne "pointtopoint" and @hashes > 1
$type ne "pointtopoint" @hashes > 1
Truth table100%3/3
A and B
A= $type ne "pointtopoint"B= @hashes > 1
ABresult
0X0
100
111
260 $self->error($colors{yellow} =
261 2 "$name link at router $rid to router $dstrid ".
262 "has multiple entries in area $area.");
263 }
264 22 ▶ if (! $routehash->{$dstrid}{areas}{$area}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $routehash->{$dstrid}{'areas'}{$area}) { } 4 18 22
elsif (not $linkhash->{$rid} && $linkhash->{$rid}{$area} && $linkhash->{$rid}{$area}{$dstrid} || $routehash->{$dstrid}{'missing'}) { } 2 16 18
265 $self->error($colors{orange} =
266 4 "$name link at router $rid to router $dstrid ".
267 "not in same area $area.");
268 ▶ } elsif (! ($linkhash->{$rid} && $linkhash->{$rid}{$area} &&
Condition77%7/9
$linkhash->{$rid} && $linkhash->{$rid}{$area} && $linkhash->{$rid}{$area}{$dstrid} || $routehash->{$dstrid}{'missing'}
l!l&&r!l&&!r
1422
$linkhash->{$rid} and $linkhash->{$rid}{$area} and $linkhash->{$rid}{$area}{$dstrid}
!ll&&!rl&&r
4014
$linkhash->{$rid} and $linkhash->{$rid}{$area}
!ll&&!rl&&r
4014
MC/DC50%2/4
$linkhash->{$rid} && $linkhash->{$rid}{$area} && $linkhash->{$rid}{$area}{$dstrid} || $routehash->{$dstrid}{'missing'}
$linkhash->{$rid} $linkhash->{$rid}{$area} $linkhash->{$rid}{$area}{$dstrid} $routehash->{$dstrid}{'missing'}
Truth table42%3/7
A and B and C || D
A= $linkhash->{$rid}B= $linkhash->{$rid}{$area}C= $linkhash->{$rid}{$area}{$dstrid}D= $routehash->{$dstrid}{'missing'}
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
269 $linkhash->{$rid}{$area}{$dstrid}) &&
270 ! $routehash->{$dstrid}{missing}) {
271 $self->error($colors{brown} =
272 2 "$name link at router $rid to router $dstrid ".
273 "not symmetric in area $area.");
274 }
275 22 foreach my $link (@hashes) {
276 25 my $intf = $link->{interface};
277 25 delete $colors{green};
278 25 ▶ if ($type eq "pointtopoint" and $ifaddrs->{$intf} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "pointtopoint" and ($ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1)) 1 24 25
Condition83%5/6
$type eq "pointtopoint" and ($ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1)
!ll&&!rl&&r
12121
$ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1
!ll&&!rl&&r
0121
MC/DC66%2/3
$type eq "pointtopoint" and ($ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1)
$type eq "pointtopoint" $ifaddrs->{$intf} $ifaddrs->{$intf}{$rid} > 1
Truth table75%3/4
A and B and C
A= $type eq "pointtopoint"B= $ifaddrs->{$intf}C= $ifaddrs->{$intf}{$rid} > 1
ABCresult
0XX0
10X0
1100
1111
279 $ifaddrs->{$intf}{$rid} > 1) {
280 $self->error($colors{green} =
281 1 "$name link at router $rid to router $dstrid ".
282 "interface address $intf not unique.");
283 }
284 25 my $metric = $link->{metric};
285 25 push @elements, {
286 graph => {
287 S => $src,
288 D => $dst,
289 label => $intf,
290 style => $style,
291 taillabel => $metric,
292 },
293 colors => { %colors },
294 index => $index++,
295 };
296 }
297 }
298 }
299 }
300 130 return $self->elements2graphs(@elements);
301 }
302  
303 ########################################################################
304 # RFC 2740
305 # Type Description
306 # ---------------------------------------------------
307 # 2 Connection to a transit network
308 ########################################################################
309 # transits => [
310 # address => 'ipv4', # Neighbor Interface ID
311 # interface => 'ipv4', # Interface ID
312 # metric => 'int', # Metric
313 # routerid => 'ipv4', # Neighbor Router ID
314 # ],
315 ########################################################################
316 # $transithash{$address}{$netrouterid}{$area}{$routerid} = {
317 # graph => { N => transit2, color => red, style => solid, } (optional)
318 # hashes => [ { link hash } ]
319 # }
320 # $transitnets->{$interface}{$routerid}{$area}{$address}{$netrouterid}++;
321 ########################################################################
322  
323 # take transit hash, transit cluster hash, net hash
324 # detect inconsistencies and set colors
325 sub check_transit {
326 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_transit: called CC=15 SCAR=27.1
Pod undocumented
327 65 my($transitcluster) = @_;
328 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
329 65 ▶ my $transithash = $self->{transithash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $transithash = $self->{"transithash"} or die "Uninitialized member" 0 65 65
330 65 foreach my $addr (sort keys %$transithash) {
331 53 my $av = $transithash->{$addr};
332 # TODO check if the there is more than one designated neigbor
333 53 foreach my $netrid (sort keys %$av) {
334 53 my $nv = $av->{$netrid};
335 53 my %colors;
336 53 ▶ if (! $nethash->{$addr}{$netrid} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $nethash->{$addr}{$netrid} and keys %$nv > 1) 2 51 53
Condition100%3/3
not $nethash->{$addr}{$netrid} and keys %$nv > 1
!ll&&!rl&&r
4832
MC/DC100%2/2
not $nethash->{$addr}{$netrid} and keys %$nv > 1
not $nethash->{$addr}{$netrid} keys %$nv > 1
Truth table100%3/3
not(A) and B
A= not $nethash->{$addr}{$netrid}B= keys %$nv > 1
ABresult
0X0
100
111
337 keys %$nv > 1) {
338 $self->error($colors{orange} =
339 2 "Transit network $addr\@$netrid missing in multiple areas.");
340 }
341 53 foreach my $area (sort keys %$nv) {
342 57 my $ev = $nv->{$area};
343 57 $colors{gray} = $area;
344 57 delete $colors{blue};
345 57 ▶ if (! $nethash->{$addr}{$netrid} && keys %$ev > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nethash->{$addr}{$netrid} and keys %$ev > 1) 1 56 57
Condition100%3/3
not $nethash->{$addr}{$netrid} and keys %$ev > 1
!ll&&!rl&&r
5061
MC/DC100%2/2
not $nethash->{$addr}{$netrid} and keys %$ev > 1
not $nethash->{$addr}{$netrid} keys %$ev > 1
Truth table100%3/3
not(A) and B
A= not $nethash->{$addr}{$netrid}B= keys %$ev > 1
ABresult
0X0
100
111
346 $self->error($colors{blue} =
347 1 "Transit network $addr\@$netrid missing in area $area ".
348 "at multiple routers.");
349 }
350 57 foreach my $rid (sort keys %$ev) {
351 98 my $rv = $ev->{$rid};
352 98 ▶ next unless $rv->{graph};
Branch: 1 branch
BranchTrueFalseTotal
unless $rv->{"graph"} 89 9 98
353 9 delete @colors{qw(yellow red)};
354 9 ▶ if ($nethash->{$addr}{$netrid}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nethash->{$addr}{$netrid}) { } 1 8 9
elsif (not $colors{'orange'} || $colors{'blue'}) { } 2 6 8
355 $self->error($colors{yellow} =
356 1 "Transit network $addr\@$netrid in area $area ".
357 "at router $rid and network not in same area.");
358 ▶ } elsif (! $colors{orange} && ! $colors{blue}) {
Condition100%3/3
$colors{'orange'} || $colors{'blue'}
l!l&&r!l&&!r
422
MC/DC100%2/2
$colors{'orange'} || $colors{'blue'}
$colors{'orange'} $colors{'blue'}
Truth table100%3/3
A || B
A= $colors{'orange'}B= $colors{'blue'}
ABresult
1X1
011
000
359 $self->error($colors{red} =
360 2 "Transit network $addr\@$netrid network missing.");
361 }
362 9 %{$rv->{colors}} = %colors;
363 9 push @{$transitcluster->{$addr}}, $rv->{graph};
364 }
365 }
366 }
367 }
368 }
369  
370 # take transit hash, router id, area, link structure, network hash
371 # add new element to transit hash
372 sub add_transit_value {
373 100 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine add_transit_value: called CC=5 SCAR=16.1
Pod undocumented
374 100 my($transithash, $transitnets, $index, $rid, $area, $link) = @_;
375 100 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 100 100
376 100 my $addr = $link->{address};
377 100 my $netrid = $link->{routerid};
378 100 my $intf = $link->{interface};
379 100 $transitnets->{$intf}{$rid}{$area}{$addr}{$netrid}++;
380 100 my $elem = $transithash->{$addr}{$netrid}{$area}{$rid};
381 100 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 98 2 100
382 98 $transithash->{$addr}{$netrid}{$area}{$rid} = $elem = {};
383 # check if address is in nethash and in matching nethash area
384 98 ▶ if (! $nethash->{$addr}{$netrid} ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($nethash->{$addr}{$netrid} and $nethash->{$addr}{$netrid}{$area}) 9 89 98
Condition100%3/3
$nethash->{$addr}{$netrid} and $nethash->{$addr}{$netrid}{$area}
!ll&&!rl&&r
8189
MC/DC100%2/2
$nethash->{$addr}{$netrid} and $nethash->{$addr}{$netrid}{$area}
$nethash->{$addr}{$netrid} $nethash->{$addr}{$netrid}{$area}
Truth table100%3/3
A and B
A= $nethash->{$addr}{$netrid}B= $nethash->{$addr}{$netrid}{$area}
ABresult
0X0
100
111
385 ! $nethash->{$addr}{$netrid}{$area}) {
386 $elem->{graph} = {
387 9 N => "transitnet$$index",
388 label => "$addr\\n$netrid",
389 shape => "ellipse",
390 style => "dotted",
391 };
392 9 $elem->{index} = $$index++;
393 }
394 }
395 100 push @{$elem->{hashes}}, $link;
396 }
397  
398 # take hash containing transit network nodes
399 # return list of nodes
400 sub transit2nodes {
401 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine transit2nodes: called CC=2 SCAR=7.0
Pod undocumented
402 65 ▶ my $transithash = $self->{transithash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $transithash = $self->{"transithash"} or die "Uninitialized member" 0 65 65
403 57 return $self->elements2graphs(map { values %$_ } map { values %$_ }
404 65 map { values %$_ } values %$transithash);
405 }
406  
407 # take link hash, router hash, network hash
408 # return list of edges from router to transit network
409 sub transit2edges {
410 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine transit2edges: called CC=17 SCAR=28.4
Pod undocumented
411 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
412 65 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 65 65
413 65 ▶ my $transithash = $self->{transithash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $transithash = $self->{"transithash"} or die "Uninitialized member" 0 65 65
414 65 my $ifaddrs = $self->{ifaddrs};
415 65 my @elements;
416 65 my $index = 0;
417 65 foreach my $addr (sort keys %$transithash) {
418 53 my $av = $transithash->{$addr};
419 53 foreach my $netrid (sort keys %$av) {
420 53 my $nv = $av->{$netrid};
421 53 my $nid = "$addr\@$netrid";
422 53 foreach my $area (sort keys %$nv) {
423 57 my $ev = $nv->{$area};
424 57 foreach my $rid (sort keys %$ev) {
425 98 my $rv = $ev->{$rid};
426 98 my %colors = (gray => $area);
427 98 my $src = $routehash->{$rid}{graph}{N};
428 98 ▶ if (@{$rv->{hashes}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rv->{"hashes"};} > 1) 2 96 98
429 $self->error($colors{yellow} =
430 2 "Transit network $nid at router $rid ".
431 "has multiple entries in area $area.");
432 }
433 98 foreach my $link (@{$rv->{hashes}}) {
434 100 my $intf = $link->{interface};
435 100 delete $colors{green};
436 100 ▶ if ($ifaddrs->{$intf} && $ifaddrs->{$intf}{$rid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1) 3 97 100
Condition66%2/3
$ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1
!ll&&!rl&&r
0973
MC/DC50%1/2
$ifaddrs->{$intf} and $ifaddrs->{$intf}{$rid} > 1
$ifaddrs->{$intf} $ifaddrs->{$intf}{$rid} > 1
Truth table66%2/3
A and B
A= $ifaddrs->{$intf}B= $ifaddrs->{$intf}{$rid} > 1
ABresult
0X0
100
111
437 $self->error($colors{green} =
438 3 "Transit link at router $rid to network $nid ".
439 "interface address $intf not unique.");
440 }
441 100 my $metric = $link->{metric};
442 # link from designated router to attached net
443 100 ▶ my $style = $netrid eq $rid && $addr eq $intf ?
Branch: 1 branch
BranchTrueFalseTotal
$netrid eq $rid && $addr eq $intf ? : 43 57 100
Condition100%3/3
$netrid eq $rid and $addr eq $intf
!ll&&!rl&&r
49843
MC/DC100%2/2
$netrid eq $rid and $addr eq $intf
$netrid eq $rid $addr eq $intf
Truth table100%3/3
A and B
A= $netrid eq $ridB= $addr eq $intf
ABresult
0X0
100
111
444 "bold" : "solid";
445 100 delete $colors{magenta};
446 100 delete $colors{brown};
447 100 delete $colors{tan};
448 100 ▶ if ($rv->{graph}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv->{"graph"}) 10 90 100
449 10 my $dst = $rv->{graph}{N};
450 10 push @elements, {
451 graph => {
452 S => $src,
453 D => $dst,
454 headlabel => $intf,
455 style => $style,
456 taillabel => $metric,
457 },
458 colors => { %colors },
459 index => $index++,
460 };
461 10 next;
462 }
463 90 my $nv = $nethash->{$addr}{$netrid};
464 90 delete $colors{magenta};
465 90 ▶ my $ev = $nv->{$area}
Branch: 1 branch
BranchTrueFalseTotal
my $ev = $nv->{$area} or next 0 90 90
466 or next;
467 90 delete $colors{brown};
468 90 delete $colors{tan};
469 90 ▶ if (! $ev->{attachrouters}{$rid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ev->{"attachrouters"}{$rid}) 2 88 90
470 $self->error($colors{brown} =
471 2 "Transit link at router $rid not attached ".
472 "by network $nid in area $area.");
473 }
474 90 my $dst = $ev->{graph}{N};
475 90 push @elements, {
476 graph => {
477 S => $src,
478 D => $dst,
479 headlabel => $intf,
480 style => $style,
481 taillabel => $metric,
482 },
483 colors => { %colors },
484 index => $index++,
485 };
486 }
487 }
488 }
489 }
490 }
491 65 return $self->elements2graphs(@elements);
492 }
493  
494 ########################################################################
495 # RFC 2740
496 # LSA function code LS Type Description
497 # ----------------------------------------------------
498 # 2 0x2002 Network-LSA
499 ########################################################################
500 # networks => [
501 # address => 'ipv4', # Link State ID
502 # area => 'ipv4',
503 # attachments => [
504 # routerid => 'ipv4', # Attached Router
505 # ],
506 # routerid => 'ipv4', # Advertising Router
507 # ],
508 ########################################################################
509 # $nethash{$address}{$routerid}{$area} = {
510 # graph => { N => network1, color => red, style => bold, }
511 # hashes => [ { network hash } ]
512 # attachrouters => { $attachmentrouterid => 1 }
513 # }
514 # $nets{$address}{$routerid}++
515 # $netareas{$address}{$routerid}{$area}++
516 ########################################################################
517  
518 # take network hash, net cluster hash, net hash
519 # detect inconsistencies and set colors
520 sub check_network {
521 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_network: called CC=11 SCAR=24.0
Pod undocumented
522 65 my($netcluster) = @_;
523 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
524 65 ▶ my $nets = $self->{nets} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nets = $self->{"nets"} or die "Uninitialized member" 0 65 65
525 65 my %colors;
526 65 foreach my $addr (sort keys %$nethash) {
527 54 my $av = $nethash->{$addr};
528 54 foreach my $rid (sort keys %$av) {
529 49 my $rv = $av->{$rid};
530 49 my $nid = "$addr\@$rid";
531 49 delete $colors{green};
532 49 ▶ if ($nets->{$addr}{$rid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nets->{$addr}{$rid} > 1) 3 46 49
533 $self->error($colors{green} =
534 3 "Network $nid not unique at router $rid.");
535 }
536 49 delete $colors{orange};
537 49 ▶ if (keys %$rv > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$rv > 1) 1 48 49
538 $self->error($colors{orange} =
539 1 "Network $nid at router $rid in multiple areas.");
540 }
541 49 foreach my $area (sort keys %$rv) {
542 50 my $ev = $rv->{$area};
543 50 $colors{gray} = $area;
544 50 delete $colors{yellow};
545 50 ▶ if (@{$ev->{hashes}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$ev->{"hashes"};} > 1) 2 48 50
546 $self->error($colors{yellow} =
547 2 "Network $nid at router $rid ".
548 "has multiple entries in area $area.");
549 }
550 50 delete $colors{brown};
551 50 my @attrids = keys %{$ev->{attachrouters}};
552 50 ▶ if (@attrids == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attrids == 0) 1 49 50
553 $self->error($colors{red} =
554 1 "Network $nid at router $rid not attached ".
555 "to any router in area $area.");
556 }
557 50 ▶ if (@attrids == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attrids == 1) 1 49 50
558 $self->error($colors{brown} =
559 1 "Network $nid at router $rid attached only ".
560 "to router @attrids in area $area.");
561 }
562 50 %{$ev->{colors}} = %colors;
563 # TODO move netcluster to prefix lsa
564 50 push @{$netcluster->{"$addr\@$rid"}}, $ev->{graph};
565 }
566 }
567 }
568 }
569  
570 # take network structure, net cluster hash
571 # return network hash
572 sub create_network {
573 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_network: called CC=4 SCAR=13.9
Pod undocumented
574 65 my $index = 0;
575 65 my %nethash;
576 my %nets;
577 65 my %netareas;
578 65 foreach my $n (@{$self->{ospf}{database}{networks}}) {
579 52 my $addr = $n->{address};
580 52 my $rid = $n->{routerid};
581 52 my $nid = "$addr\@$rid";
582 52 $nets{$addr}{$rid}++;
583 52 my $area = $n->{area};
584 52 $netareas{$addr}{$rid}{$area}++;
585 52 my $elem = $nethash{$addr}{$rid}{$area};
586 52 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 50 2 52
587 50 $nethash{$addr}{$rid}{$area} = $elem = {};
588 $elem->{graph} = {
589 50 N => "network$index",
590 label => "$addr\\n$rid",
591 shape => "ellipse",
592 style => "bold",
593 };
594 50 $elem->{index} = $index++;
595 }
596 52 push @{$elem->{hashes}}, $n;
597 52 foreach my $att (@{$n->{attachments}}) {
598 103 $elem->{attachrouters}{$att->{routerid}} = 1;
599 }
600 }
601 65 $self->{nethash} = \%nethash;
602 65 $self->{nets} = \%nets;
603 # TODO netareas should handle prefixes
604 65 $self->{netareas} = \%netareas;
605 }
606  
607 # take network hash,
608 # intra network hash
609 # add missing networks to network hash
610 sub add_missing_network {
611 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine add_missing_network: called CC=8 SCAR=32.9
Pod undocumented
612 65 my($index) = @_;
613 65 my $intranethash = $self->{intranethash};
614 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
615 65 ▶ my $nets = $self->{nets} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nets = $self->{"nets"} or die "Uninitialized member" 0 65 65
616 65 ▶ my $netareas = $self->{netareas} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $netareas = $self->{"netareas"} or die "Uninitialized member" 0 65 65
617 65 foreach my $addr (sort keys %$intranethash) {
618 0 my $av = $intranethash->{$addr};
619 0 foreach my $rid (sort keys %$av) {
620 0 my $rv = $av->{$rid};
621 0 foreach my $area (sort keys %$rv) {
622 0 my $ev = $rv->{$area};
623 0 my $elem = $nethash->{$addr}{$rid}{$area};
624 0 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 0 0 0
625 0 $nets->{$addr}{$rid}++;
626 0 $netareas->{$addr}{$rid}{$area}++;
627 0 $nethash->{$addr}{$rid}{$area} = $elem = {};
628 $elem->{graph} = {
629 0 N => "network$$index",
630 label => "$addr\\n$rid",
631 shape => "ellipse",
632 style => "dotted",
633 };
634 0 $elem->{index} = $$index++;
635 0 push @{$elem->{hashes}}, {
636 area => $area,
637 routerid => $rid,
638 };
639 0 $elem->{missing}++;
640 }
641 }
642 }
643 }
644 }
645  
646 # take hash containing network nodes
647 # return list of nodes
648 sub network2nodes {
649 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine network2nodes: called CC=2 SCAR=7.0
Pod undocumented
650 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
651 65 return $self->elements2graphs(map { values %$_ } map { values %$_ }
652 values %$nethash);
653 }
654  
655 # take network hash, router hash
656 # return list of edges from transit network to router
657 sub network2edges {
658 65 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine network2edges: called CC=22 SCAR=31.0
Pod undocumented
659 65 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 65 65
660 65 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 65 65
661 65 ▶ my $transithash = $self->{transithash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $transithash = $self->{"transithash"} or die "Uninitialized member" 0 65 65
662 65 my @elements;
663 65 my $index = 0;
664 65 foreach my $addr (sort keys %$nethash) {
665 54 my $av = $nethash->{$addr};
666 54 foreach my $rid (sort keys %$av) {
667 49 my $rv = $av->{$rid};
668 49 my $nid = "$addr\@$rid";
669 49 foreach my $area (sort keys %$rv) {
670 50 my $ev = $rv->{$area};
671 50 my $src = $ev->{graph}{N};
672 50 foreach my $net (@{$ev->{hashes}}) {
673 52 my %attcolors;
674 52 foreach (@{$net->{attachments}}) {
675 103 my $arid = $_->{routerid};
676 103 ▶ if ($attcolors{$arid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attcolors{$arid}) 2 101 103
677 $self->error($attcolors{$arid}{yellow} =
678 2 "Network $nid in area $area at router $rid ".
679 "attached to router $arid multiple times.");
680 2 next;
681 }
682 101 $attcolors{$arid}{gray} = $area;
683 101 ▶ if ($routehash->{$arid}{areas} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($routehash->{$arid}{"areas"} and not $routehash->{$arid}{"areas"}{$area}) 4 97 101
Condition66%2/3
$routehash->{$arid}{"areas"} and not $routehash->{$arid}{"areas"}{$area}
!ll&&!rl&&r
0974
MC/DC50%1/2
$routehash->{$arid}{"areas"} and not $routehash->{$arid}{"areas"}{$area}
$routehash->{$arid}{"areas"} not $routehash->{$arid}{"areas"}{$area}
Truth table66%2/3
A and not(B)
A= $routehash->{$arid}{"areas"}B= not $routehash->{$arid}{"areas"}{$area}
ABresult
0X0
100
111
684 ! $routehash->{$arid}{areas}{$area}) {
685 $self->error($attcolors{$arid}{orange} =
686 4 "Network $nid and router $arid ".
687 "not in same area $area.");
688 4 next;
689 }
690 97 my $tv = $transithash->{$addr}{$rid}{$area}{$arid};
691 97 ▶ if (! $tv && ! $routehash->{$arid}{missing}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tv or $routehash->{$arid}{"missing"}) 1 96 97
Condition100%3/3
$tv or $routehash->{$arid}{"missing"}
l!l&&r!l&&!r
9061
MC/DC100%2/2
$tv or $routehash->{$arid}{"missing"}
$tv $routehash->{$arid}{"missing"}
Truth table100%3/3
A or B
A= $tvB= $routehash->{$arid}{"missing"}
ABresult
1X1
011
000
692 $self->error($attcolors{$arid}{brown} =
693 1 "Network $nid not transit net ".
694 "of attached router $arid in area $area.");
695 1 next;
696 }
697 96 ▶ if ($arid eq $rid && $tv && ! grep { $addr eq
Branch: 1 branch
BranchTrueFalseTotal
if ($arid eq $rid and $tv and not grep({$addr eq $_->{"interface"};} @{$$tv{"hashes"};})) 5 91 96
Condition100%6/6
$arid eq $rid and $tv and not grep({$addr eq $_->{"interface"};} @{$$tv{"hashes"};})
!ll&&!rl&&r
53385
$arid eq $rid and $tv
!ll&&!rl&&r
50343
MC/DC100%3/3
$arid eq $rid and $tv and not grep({$addr eq $_->{"interface"};} @{$$tv{"hashes"};})
$arid eq $rid $tv not grep({$addr eq $_->{"interface"};} @{$$tv{"hashes"};})
Truth table100%4/4
A and B and not(C)
A= $arid eq $ridB= $tvC= not grep({$addr eq $_->{"interface"};} @{$$tv{"hashes"};})
ABCresult
0XX0
10X0
1100
1111
698 44 $_->{interface} } @{$tv->{hashes}}) {
699 $self->error($attcolors{$arid}{tan} =
700 5 "Network $nid at router $arid in area $area ".
701 "is designated but transit link is not.");
702 5 next;
703 }
704 }
705 52 foreach (@{$net->{attachments}}) {
706 103 my $arid = $_->{routerid};
707 my $dst = $routehash->{$arid}{graph}{N}
708 103 ▶ or die "No router graph $arid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $routehash->{$arid}{"graph"}{"N"} or die "No router graph $arid" 0 103 103
709 103 my $style = "solid";
710 103 ▶ if ($arid eq $rid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arid eq $rid) 51 52 103
711 # router is designated router
712 51 $style = "bold";
713 }
714 push @elements, {
715 graph => {
716 S => $src,
717 D => $dst,
718 style => $style,
719 },
720 103 colors => { %{$attcolors{$arid}} },
721 index => $index++,
722 };
723 }
724 52 ▶ if (! $attcolors{$rid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attcolors{$rid}) 3 49 52
725 my $dst = $routehash->{$rid}{graph}{N}
726 3 ▶ or die "No router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $routehash->{$rid}{"graph"}{"N"} or die "No router graph $rid" 0 3 3
727 3 $attcolors{$rid}{gray} = $area;
728 $self->error($attcolors{$rid}{red} =
729 3 "Network $nid not attached ".
730 "to designated router $rid in area $area.");
731 push @elements, {
732 graph => {
733 S => $src,
734 D => $dst,
735 style => "bold",
736 },
737 3 colors => { %{$attcolors{$rid}} },
738 index => $index++,
739 };
740 }
741 }
742 }
743 }
744 }
745 65 return $self->elements2graphs(@elements);
746 }
747  
748 ########################################################################
749 # RFC 2740
750 # LSA function code LS Type Description
751 # ----------------------------------------------------
752 # 3 0x2003 Inter-Area-Prefix-LSA
753 ########################################################################
754 # summarys => [
755 # address => 'ipv4', # Link State ID
756 # area => 'ipv4',
757 # metric => 'int', # Metric
758 # prefixaddress => 'ipv6', # Address Prefix
759 # prefixlength => 'int', # PrefixLength
760 # routerid => 'ipv4', # Advertising Router
761 # ],
762 ########################################################################
763 # $sumhash{$prefixaddress}{$prefixlength} = {
764 # graph => { N => summary4, color => red, style => solid, }
765 # hashes => [ { summary hash } ]
766 # arearids => { $area => { $routerid => 1 } }
767 # }
768 ########################################################################
769  
770 # take summary hash, net cluster hash, network hash, stub hash
771 # detect inconsistencies and set colors
772 sub check_summary {
773 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_summary: called CC=6 SCAR=18.0
Pod undocumented
774 52 my($netcluster) = @_;
775 52 ▶ my $netareas = $self->{netareas} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $netareas = $self->{"netareas"} or die "Uninitialized member" 0 52 52
776 52 ▶ my $sumhash = $self->{sumhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $sumhash = $self->{"sumhash"} or die "Uninitialized member" 0 52 52
777 52 foreach my $paddr (sort keys %$sumhash) {
778 9 my $av = $sumhash->{$paddr};
779 9 foreach my $plen (sort keys %$av) {
780 9 my $lv = $av->{$plen};
781 9 my %colors;
782 9 my $nid = "$paddr/$plen";
783 9 my @areas = sort keys %{$lv->{arearids}};
784 9 ▶ if (@areas > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@areas > 1) { } 5 4 9
785 5 $colors{black} = \@areas;
786 } else {
787 4 $colors{gray} = $areas[0];
788 }
789 # TODO check wether lower prefix address is zero
790 # TODO check Link- and Prefix-LSAs
791 # if (my @badareas = grep { $netareas->{$net}{$mask}{$_} } @areas) {
792 # $self->error($colors{blue} =
793 # "Summary network $nid is also network in areas @badareas.");
794 # }
795 # if ($stubareas and
796 # my @badareas = grep { $stubareas->{$net}{$mask}{$_} } @areas) {
797 # $self->error($colors{green} =
798 # "Summary network $nid is also stub network ".
799 # "in areas @badareas.");
800 # }
801 # TODO check for duplicate Link-State-IDs
802 9 $lv->{colors} = \%colors;
803 9 push @{$netcluster->{"$paddr/$plen"}}, $lv->{graph};
804 }
805 }
806 }
807  
808 # take summary structure, net cluster hash, network hash, link hash
809 # return summary hash
810 sub create_summary {
811 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_summary: called CC=3 SCAR=11.0
Pod undocumented
812 52 my $index = 0;
813 52 my %sumhash;
814 my %sums;
815 52 my %sumlsids;
816 52 foreach my $s (@{$self->{ospf}{database}{summarys}}) {
817 17 my $paddr = $s->{prefixaddress};
818 17 my $plen = $s->{prefixlength};
819 17 my $nid = "$paddr/$plen";
820 17 my $rid = $s->{routerid};
821 17 my $addr = $s->{address};
822 17 my $area = $s->{area};
823 17 $sumlsids{$area}{$rid}{$addr}++;
824 17 my $elem = $sumhash{$paddr}{$plen};
825 17 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 9 8 17
826 9 $sumhash{$paddr}{$plen} = $elem = {};
827 $elem->{graph} = {
828 9 N => "summary$index",
829 label => "$paddr/$plen",
830 shape => "ellipse",
831 style => "dashed",
832 };
833 9 $elem->{index} = $index++;
834 }
835 17 push @{$elem->{hashes}}, $s;
836 17 $elem->{arearids}{$area}{$rid}++;
837 }
838 52 $self->{sumhash} = \%sumhash;
839 52 $self->{sums} = \%sums;
840 52 $self->{sumlsids} = \%sumlsids;
841 }
842  
843 # take summary hash, router hash
844 # return list of edges from summary network to router
845 sub summary2edges {
846 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine summary2edges: called CC=13 SCAR=26.0
Pod undocumented
847 52 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 52 52
848 52 ▶ my $sumhash = $self->{sumhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $sumhash = $self->{"sumhash"} or die "Uninitialized member" 0 52 52
849 52 ▶ my $sumlsids = $self->{sumlsids} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $sumlsids = $self->{"sumlsids"} or die "Uninitialized member" 0 52 52
850 52 my @elements;
851 52 my $index = 0;
852 52 foreach my $paddr (sort keys %$sumhash) {
853 9 my $av = $sumhash->{$paddr};
854 9 foreach my $plen (sort keys %$av) {
855 9 my $lv = $av->{$plen};
856 9 my $nid = "$paddr/$plen";
857 9 ▶ my $src = $lv->{graph} && $lv->{graph}{N};
Condition33%1/3
$lv->{'graph'} && $lv->{'graph'}{'N'}
!ll&&!rl&&r
009
MC/DC0%0/2
$lv->{'graph'} && $lv->{'graph'}{'N'}
$lv->{'graph'} $lv->{'graph'}{'N'}
Truth table33%1/3
A && B
A= $lv->{'graph'}B= $lv->{'graph'}{'N'}
ABresult
0X0
100
111
858 9 foreach my $s (@{$lv->{hashes}}) {
859 17 my $rid = $s->{routerid};
860 my $dst = $routehash->{$rid}{graph}{N}
861 17 ▶ or die "No router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $routehash->{$rid}{"graph"}{"N"} or die "No router graph $rid" 0 17 17
862 17 my $addr = $s->{address};
863 17 my $area = $s->{area};
864 17 my %colors = (gray => $area);
865 17 ▶ if (! $routehash->{$rid}{areas}{$area}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($routehash->{$rid}{"areas"}{$area}) 1 16 17
866 $self->error($colors{orange} =
867 1 "Summary network $nid and router $rid ".
868 "not in same area $area.");
869 }
870 17 ▶ if ($lv->{arearids}{$area}{$rid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lv->{"arearids"}{$area}{$rid} > 1) 4 13 17
871 $self->error($colors{yellow} =
872 4 "Summary network $nid at router $rid ".
873 "has multiple entries in area $area.");
874 }
875 17 ▶ if ($sumlsids->{$area}{$rid}{$addr} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sumlsids->{$area}{$rid}{$addr} > 1) 4 13 17
876 $self->error($colors{magenta} =
877 4 "Summary network $nid at router $rid ".
878 "has multiple link state IDs $addr in area $area.");
879 }
880 17 my $metric = $s->{metric};
881 $s->{graph} = {
882 17 S => $src,
883 D => $dst,
884 headlabel => $metric,
885 style => "dashed",
886 taillabel => $addr,
887 };
888 17 $s->{colors} = \%colors;
889 17 $s->{index} = $index++;
890 # in case of aggregation src is undef
891 17 ▶ push @elements, $s if $src;
Branch: 1 branch
BranchTrueFalseTotal
if $src 17 0 17
892 }
893 }
894 }
895 52 return $self->elements2graphs(@elements);
896 }
897  
898 ########################################################################
899 # RFC 2740
900 # LSA function code LS Type Description
901 # ----------------------------------------------------
902 # 4 0x2004 Inter-Area-Router-LSA
903 ########################################################################
904 # boundarys => [
905 # address => 'ipv4', # Link State ID
906 # area => 'ipv4',
907 # asbrouter => 'ipv4', # Destination Router ID
908 # metric => 'int', # Metric
909 # routerid => 'ipv4', # Advertising Router
910 # ],
911 ########################################################################
912 # $boundhash{$asbrouter} = {
913 # graph => { N => boundary6, color => red, style => dashed, }
914 # hashes => [ { boundary hash } ]
915 # arearids => { $area => { $routerid => 1 }
916 # aggregate => { $asbraggr => 1 } (optional)
917 # }
918 ########################################################################
919  
920 # take boundary structure
921 # return boundary hash
922 sub create_boundary {
923 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_boundary: called CC=3 SCAR=11.0
Pod undocumented
924 52 my $index = 0;
925 52 my %boundhash;
926 my %boundlsids;
927 52 foreach my $b (@{$self->{ospf}{database}{boundarys}}) {
928 32 my $asbr = $b->{asbrouter};
929 32 my $rid = $b->{routerid};
930 32 my $area = $b->{area};
931 32 my $addr = $b->{address};
932 32 $boundlsids{$area}{$rid}{$addr}++;
933 32 my $elem = $boundhash{$asbr};
934 32 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 20 12 32
935 20 $boundhash{$asbr} = $elem = {};
936 $elem->{graph} = {
937 20 N => "boundary$index",
938 label => $asbr,
939 shape => "box",
940 style => "dashed",
941 };
942 20 $elem->{index} = $index++;
943 }
944 32 push @{$elem->{hashes}}, $b;
945 32 $elem->{arearids}{$area}{$rid}++;
946 }
947 52 $self->{boundhash} = \%boundhash;
948 52 $self->{boundlsids} = \%boundlsids;
949 }
950  
951 # take boundary hash, router hash
952 # return list of edges from boundary router to router
953 sub boundary2edges {
954 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine boundary2edges: called CC=16 SCAR=27.9
Pod undocumented
955 52 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 52 52
956 52 ▶ my $boundhash = $self->{boundhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $boundhash = $self->{"boundhash"} or die "Uninitialized member" 0 52 52
957 52 ▶ my $boundlsids = $self->{boundlsids} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $boundlsids = $self->{"boundlsids"} or die "Uninitialized member" 0 52 52
958 52 my @elements;
959 52 my $index = 0;
960 52 foreach my $asbr (sort keys %$boundhash) {
961 20 my $bv = $boundhash->{$asbr};
962 20 my $src;
963 20 ▶ if ($bv->{graph}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bv->{'graph'}) { } 13 7 20
elsif ($routehash->{$asbr}) { } 7 0 7
964 13 $src = $bv->{graph}{N};
965 } elsif ($routehash->{$asbr}) {
966 $src = $routehash->{$asbr}{graph}{N}
967 7 }
968 20 foreach my $b (@{$bv->{hashes}}) {
969 32 my $rid = $b->{routerid};
970 my $dst = $routehash->{$rid}{graph}{N}
971 32 ▶ or die "No router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $routehash->{$rid}{"graph"}{"N"} or die "No router graph $rid" 0 32 32
972 32 my $addr = $b->{address};
973 32 my $area = $b->{area};
974 32 my %colors = (gray => $area);
975 32 ▶ if ($asbr eq $rid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($asbr eq $rid) { } 1 31 32
elsif ($routehash->{$asbr} and $routehash->{$asbr}{'areas'}{$area}) { } 1 51 52
976 $self->error($colors{brown} =
977 1 "AS boundary router $asbr is advertized by itself ".
978 "in area $area.");
979 ▶ } elsif ($routehash->{$asbr} && $routehash->{$asbr}{areas}{$area}) {
Condition100%3/3
$routehash->{$asbr} and $routehash->{$asbr}{"areas"}{$area}
!ll&&!rl&&r
2191
MC/DC100%2/2
$routehash->{$asbr} and $routehash->{$asbr}{"areas"}{$area}
$routehash->{$asbr} $routehash->{$asbr}{"areas"}{$area}
Truth table100%3/3
A and B
A= $routehash->{$asbr}B= $routehash->{$asbr}{"areas"}{$area}
ABresult
0X0
100
111
980 $self->error($colors{blue} =
981 1 "AS boundary router $asbr is router in same area $area.");
982 }
983 32 ▶ if (! $routehash->{$rid}{areas}{$area}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($routehash->{$rid}{"areas"}{$area}) 2 30 32
984 $self->error($colors{orange} =
985 2 "AS boundary router $asbr and router $rid ".
986 "not in same area $area.");
987 }
988 32 ▶ if ($bv->{arearids}{$area}{$rid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bv->{"arearids"}{$area}{$rid} > 1) 6 26 32
989 $self->error($colors{yellow} =
990 6 "AS boundary router $asbr at router $rid ".
991 "has multiple entries in area $area.");
992 }
993 32 ▶ if ($boundlsids->{$area}{$rid}{$addr} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boundlsids->{$area}{$rid}{$addr} > 1) 4 28 32
994 $self->error($colors{magenta} =
995 4 "AS boundary router $asbr at router $rid ".
996 "has multiple link state IDs $addr in area $area.");
997 }
998 32 my $metric = $b->{metric};
999 $b->{graph} = {
1000 32 S => $src,
1001 D => $dst,
1002 headlabel => $metric,
1003 style => "dashed",
1004 taillabel => $addr,
1005 };
1006 32 $b->{colors} = \%colors;
1007 32 $b->{index} = $index++;
1008 # in case of aggregation src is undef
1009 32 ▶ push @elements, $b if $src;
Branch: 1 branch
BranchTrueFalseTotal
if $src 32 0 32
1010 }
1011 }
1012 52 return $self->elements2graphs(@elements);
1013 }
1014  
1015 ########################################################################
1016 # RFC 2740
1017 # LSA function code LS Type Description
1018 # ----------------------------------------------------
1019 # 5 0x4005 AS-External-LSA
1020 ########################################################################
1021 # externals => [
1022 # address => 'ipv4', # Link State ID
1023 # metric => 'int', # Metric
1024 # prefixaddress => 'ipv6', # Address Prefix
1025 # prefixlength => 'int', # PrefixLength
1026 # routerid => 'ipv4', # Advertising Router
1027 # type => 'int', # bit E
1028 # ],
1029 ########################################################################
1030 # $externhash{$prefixaddress}{$prefixlength} = {
1031 # graph => { N => external8, color => red, style => dashed, }
1032 # hashes => [ { ase hash } ]
1033 # routers => { $routerid => 1 }
1034 # }
1035  
1036 # take external hash, net cluster hash, network hash, stub hash, summary hash
1037 # detect inconsistencies and set colors
1038 sub check_external {
1039 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_external: called CC=5 SCAR=16.2
Pod undocumented
1040 52 my($netcluster) = @_;
1041 52 ▶ my $nets = $self->{nets} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nets = $self->{"nets"} or die "Uninitialized member" 0 52 52
1042 52 my $sums = $self->{sums};
1043 52 ▶ my $externhash = $self->{externhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $externhash = $self->{"externhash"} or die "Uninitialized member" 0 52 52
1044 52 foreach my $paddr (sort keys %$externhash) {
1045 12 my $av = $externhash->{$paddr};
1046 12 foreach my $plen (sort keys %$av) {
1047 12 my $lv = $av->{$plen};
1048 12 my %colors = (gray => "ase");
1049 12 my $nid = "$paddr/$plen";
1050 # TODO check wether lower prefix address is zero
1051 # TODO check Link- and Prefix-LSAs
1052 # if ($nets->{$net}{$mask}) {
1053 # $self->error($colors{blue} =
1054 # "AS external network $nid is also network.");
1055 # }
1056 # if ($stubs->{$net}{$mask}) {
1057 # $self->error($colors{green} =
1058 # "AS external network $nid is also stub network.");
1059 # }
1060 # if ($sums->{$net}{$mask}) {
1061 # $self->error($colors{cyan} =
1062 # "AS external network $nid is also summary network.");
1063 # }
1064 # TODO check for duplicate Link-State-IDs
1065 12 $lv->{colors} = \%colors;
1066 12 push @{$netcluster->{"$paddr/$plen"}}, $lv->{graph};
1067 }
1068 }
1069 }
1070  
1071 # take external structure, net cluster hash, network hash, link hash
1072 # return external hash
1073 sub create_external {
1074 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_external: called CC=3 SCAR=11.0
Pod undocumented
1075 52 my $index = 0;
1076 52 my %externhash;
1077 my %externlsids;
1078 52 foreach my $e (@{$self->{ospf}{database}{externals}}) {
1079 24 my $paddr = $e->{prefixaddress};
1080 24 my $plen = $e->{prefixlength};
1081 24 my $rid = $e->{routerid};
1082 24 my $addr = $e->{address};
1083 24 $externlsids{$rid}{$addr}++;
1084 24 my $elem = $externhash{$paddr}{$plen};
1085 24 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 12 12 24
1086 12 $externhash{$paddr}{$plen} = $elem = {};
1087 $elem->{graph} = {
1088 12 N => "external$index",
1089 label => "$paddr/$plen",
1090 shape => "egg",
1091 style => "solid",
1092 };
1093 12 $elem->{index} = $index++;
1094 }
1095 24 push @{$elem->{hashes}}, $e;
1096 24 $elem->{routers}{$rid}++;
1097 }
1098 52 $self->{externhash} = \%externhash;
1099 52 $self->{externlsids} = \%externlsids;
1100 }
1101  
1102 # take external hash, router hash, boundary hash, boundary aggregate
1103 # return list of edges from external network to router
1104 sub external2edges {
1105 52 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine external2edges: called CC=21 SCAR=35.0
Pod undocumented
1106 52 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 52 52
1107 52 my $boundhash = $self->{boundhash};
1108 52 my $boundaggr = $self->{boundaggr};
1109 52 ▶ my $externhash = $self->{externhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $externhash = $self->{"externhash"} or die "Uninitialized member" 0 52 52
1110 52 ▶ my $externlsids = $self->{externlsids} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $externlsids = $self->{"externlsids"} or die "Uninitialized member" 0 52 52
1111 52 my @elements;
1112 52 my $index = 0;
1113 52 foreach my $paddr (sort keys %$externhash) {
1114 12 my $pv = $externhash->{$paddr};
1115 12 foreach my $plen (sort keys %$pv) {
1116 12 my $lv = $pv->{$plen};
1117 12 my $nid = "$paddr/$plen";
1118 12 my $src = $lv->{graph}{N};
1119 12 my %dtm; # when dst is aggregated, aggregate edges
1120 12 foreach my $e (@{$lv->{hashes}}) {
1121 24 my $rid = $e->{routerid};
1122 24 my $addr = $e->{address};
1123 24 my $type = $e->{type};
1124 24 my $metric = $e->{metric};
1125 24 my %colors = (gray => "ase");
1126 24 ▶ if ($lv->{routers}{$rid} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lv->{"routers"}{$rid} > 1) 7 17 24
1127 $self->error($colors{yellow} =
1128 7 "AS external network $nid at router $rid ".
1129 "has multiple entries.");
1130 }
1131 24 ▶ if ($externlsids->{$rid}{$addr} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($externlsids->{$rid}{$addr} > 1) 7 17 24
1132 $self->error($colors{magenta} =
1133 7 "AS external network $nid at router $rid ".
1134 "has multiple link state IDs $addr.");
1135 }
1136 24 ▶ my $style = $type == 1 ? "solid" : "dashed";
Branch: 1 branch
BranchTrueFalseTotal
$type == 1 ? : 21 3 24
1137 24 my %graph = (
1138 S => $src,
1139 headlabel => $metric,
1140 style => $style,
1141 taillabel => $addr,
1142 );
1143 24 ▶ if ($routehash->{$rid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routehash->{$rid}) 15 9 24
1144 my $dst = $routehash->{$rid}{graph}{N}
1145 15 ▶ or die "No router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $routehash->{$rid}{"graph"}{"N"} or die "No router graph $rid" 0 15 15
1146 15 $graph{D} = $dst;
1147 15 $e->{elems}{$dst} = {
1148 graph => \%graph,
1149 colors => \%colors,
1150 index => $index++,
1151 };
1152 15 ▶ push @elements, $e->{elems}{$dst} if $src;
Branch: 1 branch
BranchTrueFalseTotal
if $src 15 0 15
1153 15 next;
1154 }
1155 9 my $av = $boundhash->{$rid}{aggregate};
1156 9 ▶ if (! $av) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($av) 9 0 9
1157 my $dst = $boundhash->{$rid}{graph}{N}
1158 9 ▶ or die "No ASB router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $boundhash->{$rid}{"graph"}{"N"} or die "No ASB router graph $rid" 0 9 9
1159 9 $graph{D} = $dst;
1160 9 $e->{elems}{$dst} = {
1161 graph => \%graph,
1162 colors => \%colors,
1163 index => $index++,
1164 };
1165 9 ▶ push @elements, $e->{elems}{$dst} if $src;
Branch: 1 branch
BranchTrueFalseTotal
if $src 9 0 9
1166 9 next;
1167 }
1168 0 foreach my $asbraggr (sort keys %$av) {
1169 0 my $num = $av->{$asbraggr};
1170 my $dst = $boundaggr->{$asbraggr}{graph}{N}
1171 0 ▶ or die "No ASBR graph $asbraggr";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $boundaggr->{$asbraggr}{"graph"}{"N"} or die "No ASBR graph $asbraggr" 0 0 0
1172 0 $graph{D} = $dst;
1173 0 $e->{elems}{$dst} = {
1174 graph => { %graph },
1175 colors => { %colors },
1176 index => $index++,
1177 };
1178 # no not aggregate graphs with errors
1179 0 ▶ if (grep { ! /^(gray|black)$/ } keys %colors) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not /^(gray|black)$/;} keys %colors) { } 0 0 0
1180 0 ▶ push @elements, $e->{elems}{$dst} if $src;
Branch: 1 branch
BranchTrueFalseTotal
if $src 0 0 0
1181 } else {
1182 0 $dtm{$dst}{$type}{$metric} = $e->{elems}{$dst};
1183 }
1184 }
1185 }
1186 12 ▶ push @elements, map { values %$_ } map { values %$_ } values %dtm
Branch: 1 branch
BranchTrueFalseTotal
if $src 12 0 12
1187 if $src;
1188 }
1189 }
1190 52 return $self->elements2graphs(@elements);
1191 }
1192  
1193 ########################################################################
1194 # $externaggr{$netaggr} = {
1195 # graph => { N => external9, color => red, style => dashed, }
1196 # routers => { $routerid => { $type => { $metric => [ { ase hash } ] } } }
1197 # }
1198 ########################################################################
1199  
1200 # take external hash
1201 # return external aggregate
1202 sub create_externaggr {
1203 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_externaggr: not called CC=26 SCAR=65.5
Pod undocumented
1204 # $ridnets{$rid}{$network} =
1205 # color => orange,
1206 # types => { $type => { $metric => [ { ase hash } ] } }
1207 0 ▶ my $externhash = $self->{externhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $externhash = $self->{"externhash"} or die "Uninitialized member" 0 0 0
1208 0 my %ridnets;
1209 0 foreach my $net (sort keys %$externhash) {
1210 0 my $nv = $externhash->{$net};
1211 0 foreach my $mask (sort keys %$nv) {
1212 0 my $mv = $nv->{$mask};
1213 0 my $nid = "$net/$mask";
1214 # no not aggregate clustered graphs
1215 0 ▶ next if $mv->{graph}{C};
Branch: 1 branch
BranchTrueFalseTotal
if $mv->{"graph"}{"C"} 0 0 0
1216 0 my $colors = $mv->{colors};
1217 # no not aggregate graphs with errors
1218 0 ▶ next if grep { ! /^(gray|black)$/ } keys %$colors;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not /^(gray|black)$/;} keys %$colors 0 0 0
1219 0 foreach my $e (@{$mv->{hashes}}) {
1220 0 my $rid = $e->{routerid};
1221 0 my $type = $e->{type};
1222 0 my $metric = $e->{metric};
1223 0 my $elem = $ridnets{$rid}{$nid};
1224 0 ▶ if (! $elem) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $elem) { } 0 0 0
elsif (not $elem->{'colors'}{'gray'} && $colors->{'gray'} or $elem->{'colors'}{'gray'} ne $colors->{'gray'}) { } 0 0 0
1225 0 $ridnets{$rid}{$nid} = $elem = {
1226 colors => { %$colors },
1227 };
1228 ▶ } elsif (! $elem->{colors}{gray} || ! $colors->{gray} ||
Condition0%0/6
not $elem->{"colors"}{"gray"} && $colors->{"gray"} or $elem->{"colors"}{"gray"} ne $colors->{"gray"}
l!l&&r!l&&!r
000
$elem->{'colors'}{'gray'} && $colors->{'gray'}
!ll&&!rl&&r
000
MC/DC0%0/3
not $elem->{"colors"}{"gray"} && $colors->{"gray"} or $elem->{"colors"}{"gray"} ne $colors->{"gray"}
$elem->{'colors'}{'gray'} $colors->{'gray'} $elem->{"colors"}{"gray"} ne $colors->{"gray"}
Truth table0%0/4
not(A && B) or C
A= $elem->{'colors'}{'gray'}B= $colors->{'gray'}C= $elem->{"colors"}{"gray"} ne $colors->{"gray"}
ABCresult
0XX1
10X1
1111
1100
1229 $elem->{colors}{gray} ne $colors->{gray}) {
1230 0 ▶ push @{$elem->{colors}{black}},
Condition0%0/6
delete $elem->{'colors'}{'gray'} || ()
l!l&&r!l&&!r
000
$colors->{'gray'} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $elem->{'colors'}{'gray'} || ()
delete $elem->{'colors'}{'gray'} ()
MC/DC0%0/2
$colors->{'gray'} || ()
$colors->{'gray'} ()
Truth table0%0/3
A || B
A= delete $elem->{'colors'}{'gray'}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $colors->{'gray'}B= ()
ABresult
1X1
011
000
1231 (delete($elem->{colors}{gray}) || ()),
1232 0 ▶ ($colors->{gray} || ()), @{$colors->{black} || []};
Branch: 1 branch
BranchTrueFalseTotal
$colors->{"black"} or [] 0 0 0
1233 }
1234 0 push @{$elem->{types}{$type}{$metric}}, $e;
1235 }
1236 0 delete $mv->{graph};
1237 }
1238 }
1239 0 my $index = 0;
1240 0 my %externaggr;
1241 0 foreach my $rid (sort keys %ridnets) {
1242 0 my $rv = $ridnets{$rid};
1243 0 my $netaggr = join('\n', sort keys %$rv); # TODO ip sort
1244 0 my $elem = $externaggr{$netaggr};
1245 0 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 0 0 0
1246 0 $externaggr{$netaggr} = $elem = {};
1247 $elem->{graph} = {
1248 0 N => "externalaggregate$index",
1249 label => $netaggr,
1250 shape => "egg",
1251 style => "solid",
1252 };
1253 0 $elem->{index} = $index++;
1254 }
1255 0 foreach my $nid (sort keys %$rv) {
1256 0 my $nv = $rv->{$nid};
1257 0 my $colors = $nv->{colors};
1258 0 ▶ if (! $elem->{colors}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $elem->{'colors'}) { } 0 0 0
elsif (not $elem->{'colors'}{'gray'} && $colors->{'gray'} or $elem->{'colors'}{'gray'} ne $colors->{'gray'}) { } 0 0 0
1259 0 %{$elem->{colors}} = %$colors;
1260 ▶ } elsif (! $elem->{colors}{gray} || ! $colors->{gray} ||
Condition0%0/6
not $elem->{"colors"}{"gray"} && $colors->{"gray"} or $elem->{"colors"}{"gray"} ne $colors->{"gray"}
l!l&&r!l&&!r
000
$elem->{'colors'}{'gray'} && $colors->{'gray'}
!ll&&!rl&&r
000
MC/DC0%0/3
not $elem->{"colors"}{"gray"} && $colors->{"gray"} or $elem->{"colors"}{"gray"} ne $colors->{"gray"}
$elem->{'colors'}{'gray'} $colors->{'gray'} $elem->{"colors"}{"gray"} ne $colors->{"gray"}
Truth table0%0/4
not(A && B) or C
A= $elem->{'colors'}{'gray'}B= $colors->{'gray'}C= $elem->{"colors"}{"gray"} ne $colors->{"gray"}
ABCresult
0XX1
10X1
1111
1100
1261 $elem->{colors}{gray} ne $colors->{gray}) {
1262 0 ▶ push @{$elem->{colors}{black}},
Condition0%0/6
delete $elem->{'colors'}{'gray'} || ()
l!l&&r!l&&!r
000
$colors->{'gray'} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $elem->{'colors'}{'gray'} || ()
delete $elem->{'colors'}{'gray'} ()
MC/DC0%0/2
$colors->{'gray'} || ()
$colors->{'gray'} ()
Truth table0%0/3
A || B
A= delete $elem->{'colors'}{'gray'}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $colors->{'gray'}B= ()
ABresult
1X1
011
000
1263 (delete($elem->{colors}{gray}) || ()),
1264 0 ▶ ($colors->{gray} || ()), @{$colors->{black} || []};
Branch: 1 branch
BranchTrueFalseTotal
$colors->{"black"} or [] 0 0 0
1265 }
1266 0 foreach my $type (sort keys %{$nv->{types}}) {
1267 0 my $tv = $nv->{types}{$type};
1268 0 foreach my $metric (sort keys %$tv) {
1269 0 my $es = $tv->{$metric};
1270 0 push @{$elem->{routers}{$rid}{$type}{$metric}}, @$es;
1271 }
1272 }
1273 }
1274 }
1275 0 $self->{externaggr} = \%externaggr;
1276 }
1277  
1278 ########################################################################
1279 # RFC 2740
1280 # LSA function code LS Type Description
1281 # ----------------------------------------------------
1282 # 8 0x0008 Link-LSA
1283 ########################################################################
1284 # links => [
1285 # area => 'ipv4',
1286 # interface => 'ipv4', # Link State ID
1287 # linklocal => 'ipv6', # Link-local Interface Address
1288 # prefixes => [
1289 # prefixaddress => 'ipv6', # Address Prefix
1290 # prefixlength => 'int', # PrefixLength
1291 # ],
1292 # routerid => 'ipv4', # Advertising Router
1293 # ],
1294 ########################################################################
1295 # $lnkhash{$interface}{$routerid}{$area} = {
1296 # graph => { N => link1, color => red, }
1297 # hashes => [ { link hash } ]
1298 # }
1299 ########################################################################
1300  
1301 # take link hash
1302 # detect inconsistencies and set colors
1303 sub check_link {
1304 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_link: not called CC=5 SCAR=34.0
Pod undocumented
1305 0 ▶ my $lnkhash = $self->{lnkhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $lnkhash = $self->{"lnkhash"} or die "Uninitialized member" 0 0 0
1306 0 my %colors;
1307 0 ▶ while (my($intf,$iv) = each %$lnkhash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$lnkhash) 0 0 0
1308 0 ▶ while (my($rid, $rv) = each %$iv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$iv) 0 0 0
1309 0 my $lid = "$intf\@$rid";
1310 0 ▶ while (my($area, $av) = each %$rv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$rv) 0 0 0
1311 0 $colors{gray} = $area;
1312 0 %{$av->{colors}} = %colors;
1313 }
1314 }
1315 }
1316 }
1317  
1318 sub create_link {
1319 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_link: not called CC=4 SCAR=30.0
Pod undocumented
1320 0 my $index = 0;
1321 0 my %lnkhash;
1322 0 foreach my $l (@{$self->{ospf}{database}{links}}) {
1323 0 my $intf = $l->{interface};
1324 0 my $rid = $l->{routerid};
1325 0 my $lid = "$intf\@$rid";
1326 0 my $area = $l->{area};
1327 0 my $linklocal = $l->{linklocal};
1328 my $prefixes = join("\\n",
1329 0 map { "$_->{prefixaddress}/$_->{prefixlength}" }
1330 0 ▶ @{$l->{prefixes} || []});
Branch: 1 branch
BranchTrueFalseTotal
$l->{"prefixes"} or [] 0 0 0
1331 0 my $elem = $lnkhash{$intf}{$rid}{$area};
1332 0 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 0 0 0
1333 0 $lnkhash{$intf}{$rid}{$area} = $elem = {};
1334 $elem->{graph} = {
1335 0 N => "link$index",
1336 label => "$linklocal\\n$prefixes",
1337 shape => "hexagon",
1338 style => "solid",
1339 };
1340 0 $elem->{index} = $index++;
1341 }
1342 0 push @{$elem->{hashes}}, $l;
1343 }
1344 0 $self->{lnkhash} = \%lnkhash;
1345 }
1346  
1347 # take hash containing link nodes
1348 # return list of nodes
1349 sub link2nodes {
1350 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine link2nodes: not called CC=2 SCAR=17.9
Pod undocumented
1351 0 ▶ my $lnkhash = $self->{lnkhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $lnkhash = $self->{"lnkhash"} or die "Uninitialized member" 0 0 0
1352 0 return $self->elements2graphs(map { values %$_ } map { values %$_ }
1353 values %$lnkhash);
1354 }
1355  
1356 # take link hash, network hash, router hash
1357 # return list of edges from network and router to link
1358 sub link2edges {
1359 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine link2edges: not called CC=13 SCAR=52.0
Pod undocumented
1360 0 ▶ my $lnkhash = $self->{lnkhash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $lnkhash = $self->{"lnkhash"} or die "Uninitialized member" 0 0 0
1361 0 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 0 0
1362 0 ▶ my $transithash = $self->{transithash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $transithash = $self->{"transithash"} or die "Uninitialized member" 0 0 0
1363 0 ▶ my $transitnets = $self->{transitnets} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $transitnets = $self->{"transitnets"} or die "Uninitialized member" 0 0 0
1364 0 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 0 0
1365 0 my @elements;
1366 0 my $index = 0;
1367 0 foreach my $intf (sort keys %$lnkhash) {
1368 0 my $iv = $lnkhash->{$intf};
1369 0 foreach my $rid (sort keys %$iv) {
1370 0 my $rv = $iv->{$rid};
1371 0 my $lid = "$intf\@$rid";
1372 my $rdst = $routehash->{$rid}{graph}{N}
1373 0 ▶ or die "No router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $rdst = $routehash->{$rid}{"graph"}{"N"} or die "No router graph $rid" 0 0 0
1374 # TODO create missing router
1375 0 foreach my $area (sort keys %$rv) {
1376 0 my $av = $rv->{$area};
1377 0 my $src = $av->{graph}{N};
1378 0 my %colors;
1379 0 $colors{gray} = $area;
1380 0 push @elements, {
1381 graph => {
1382 S => $src,
1383 D => $rdst,
1384 style => "bold",
1385 taillabel => $intf,
1386 },
1387 colors => \%colors,
1388 index => $index++,
1389 };
1390 0 ▶ my $tv = $transitnets->{$intf}{$rid}{$area}
Branch: 1 branch
BranchTrueFalseTotal
my $tv = $transitnets->{$intf}{$rid}{$area} or next 0 0 0
1391 or next;
1392 # TODO check for duplicates in check_transit
1393 0 my($netaddr,$nv) = each %$tv;
1394 0 my($netrid,$num) = each %$nv;
1395 my $ndst = $nethash->{$netaddr}{$netrid}{$area}{graph}{N} ||
1396 $transithash->{$netaddr}{$netrid}{$area}{$rid}{graph}{N}
1397 0 ▶ or next;
Branch: 1 branch
BranchTrueFalseTotal
my $ndst = $nethash->{$netaddr}{$netrid}{$area}{"graph"}{"N"} || $transithash->{$netaddr}{$netrid}{$area}{$rid}{"graph"}{"N"} or next 0 0 0
Condition0%0/3
$nethash->{$netaddr}{$netrid}{$area}{'graph'}{'N'} || $transithash->{$netaddr}{$netrid}{$area}{$rid}{'graph'}{'N'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$nethash->{$netaddr}{$netrid}{$area}{'graph'}{'N'} || $transithash->{$netaddr}{$netrid}{$area}{$rid}{'graph'}{'N'}
$nethash->{$netaddr}{$netrid}{$area}{'graph'}{'N'} $transithash->{$netaddr}{$netrid}{$area}{$rid}{'graph'}{'N'}
Truth table0%0/3
A || B
A= $nethash->{$netaddr}{$netrid}{$area}{'graph'}{'N'}B= $transithash->{$netaddr}{$netrid}{$area}{$rid}{'graph'}{'N'}
ABresult
1X1
011
000
1398 0 push @elements, {
1399 graph => {
1400 S => $src,
1401 D => $ndst,
1402 style => "solid",
1403 },
1404 colors => \%colors,
1405 index => $index++,
1406 };
1407 }
1408 }
1409 }
1410 0 return $self->elements2graphs(@elements);
1411 }
1412  
1413 ########################################################################
1414 # RFC 2740
1415 # LSA function code LS Type Description
1416 # ----------------------------------------------------
1417 # 9 0x2009 Intra-Area-Prefix-LSA
1418 # Referenced LS type 1 router-LSA
1419 ########################################################################
1420 # intrarouters => [
1421 # address => 'ipv4', # Link State ID
1422 # area => 'ipv4',
1423 # interface => 'ipv4', # Referenced Link State ID, 0
1424 # # 0
1425 # prefixes => [
1426 # prefixaddress => 'ipv6', # Address Prefix
1427 # prefixlength => 'int', # PrefixLength
1428 # ],
1429 # router => 'ipv4', # Referenced Advertising Router
1430 # # originating router's Router ID
1431 # routerid => 'ipv4', # Advertising Router
1432 # ],
1433 ########################################################################
1434 # $intraroutehash{$router}{$area} = {
1435 # graph => { N => intrarouter1, color => red, }
1436 # hashes => [ { intrarouter hash } ]
1437 # }
1438 ########################################################################
1439  
1440 # take intrarouter hash
1441 # detect inconsistencies and set colors
1442 sub check_intrarouter {
1443 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_intrarouter: not called CC=4 SCAR=30.0
Pod undocumented
1444 0 ▶ my $intraroutehash = $self->{intraroutehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $intraroutehash = $self->{"intraroutehash"} or die "Uninitialized member" 0 0 0
1445 0 my %colors;
1446 0 ▶ while (my($rid, $rv) = each %$intraroutehash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$intraroutehash) 0 0 0
1447 0 my $iid = "$rid";
1448 0 ▶ while (my($area, $av) = each %$rv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$rv) 0 0 0
1449 0 $colors{gray} = $area;
1450 0 %{$av->{colors}} = %colors;
1451 }
1452 }
1453 }
1454  
1455 sub create_intrarouters {
1456 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_intrarouters: not called CC=4 SCAR=30.0
Pod undocumented
1457 0 my $index = 0;
1458 0 my %intraroutehash;
1459 0 foreach my $i (@{$self->{ospf}{database}{intrarouters}}) {
1460 0 my $intf = $i->{interface};
1461 0 my $rid = $i->{router};
1462 0 my $area = $i->{area};
1463 0 my $elem = $intraroutehash{$rid}{$area};
1464 0 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 0 0 0
1465 0 $intraroutehash{$rid}{$area} = $elem = {};
1466 $elem->{graph} = {
1467 0 N => "intrarouter$index",
1468 label => "prefixes",
1469 shape => "octagon",
1470 style => "solid",
1471 };
1472 0 $elem->{index} = $index++;
1473 }
1474 0 push @{$elem->{hashes}}, $i;
1475 $elem->{graph}{label} = join("\\n",
1476 0 map { "$_->{prefixaddress}/$_->{prefixlength}" }
1477 0 ▶ map { @{$_->{prefixes} || []} } @{$elem->{hashes}});
Branch: 1 branch
BranchTrueFalseTotal
$_->{"prefixes"} or [] 0 0 0
1478 }
1479 0 $self->{intraroutehash} = \%intraroutehash;
1480 }
1481  
1482 # take hash containing intrarouter nodes
1483 # return list of nodes
1484 sub intrarouter2nodes {
1485 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine intrarouter2nodes: not called CC=2 SCAR=17.9
Pod undocumented
1486 0 ▶ my $intraroutehash = $self->{intraroutehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $intraroutehash = $self->{"intraroutehash"} or die "Uninitialized member" 0 0 0
1487 0 return $self->elements2graphs(map { values %$_ } values %$intraroutehash);
1488 }
1489  
1490 # take intrarouter hash, router hash
1491 # return list of edges from intrarouter to router
1492 sub intrarouter2edges {
1493 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine intrarouter2edges: not called CC=7 SCAR=40.3
Pod undocumented
1494 0 ▶ my $intraroutehash = $self->{intraroutehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $intraroutehash = $self->{"intraroutehash"} or die "Uninitialized member" 0 0 0
1495 0 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 0 0
1496 0 my @elements;
1497 0 my $index = 0;
1498 0 foreach my $rid (sort keys %$intraroutehash) {
1499 0 my $rv = $intraroutehash->{$rid};
1500 0 my $iid = "$rid";
1501 0 foreach my $area (sort keys %$rv) {
1502 0 my $av = $rv->{$area};
1503 0 my $src = $av->{graph}{N};
1504 my $dst = $routehash->{$rid}{graph}{N}
1505 0 ▶ or die "No router graph $rid";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $routehash->{$rid}{"graph"}{"N"} or die "No router graph $rid" 0 0 0
1506 # TODO create missing router
1507 0 my %colors;
1508 0 $colors{gray} = $area;
1509 0 foreach my $i (@{$av->{hashes}}) {
1510 0 my $addr = $i->{address};
1511 0 push @elements, {
1512 graph => {
1513 S => $src,
1514 D => $dst,
1515 style => "bold",
1516 taillabel => $addr,
1517 },
1518 colors => { %colors },
1519 index => $index++,
1520 };
1521 }
1522 }
1523 }
1524 0 return $self->elements2graphs(@elements);
1525 }
1526  
1527 ########################################################################
1528 # RFC 2740
1529 # LSA function code LS Type Description
1530 # ----------------------------------------------------
1531 # 9 0x2009 Intra-Area-Prefix-LSA
1532 # Referenced LS type 2 network-LSA
1533 ########################################################################
1534 # intranetworks => [
1535 # address => 'ipv4', # Link State ID
1536 # area => 'ipv4',
1537 # interface => 'ipv4', # Referenced Link State ID
1538 # # Interface ID of Designated Router
1539 # prefixes => [
1540 # prefixaddress => 'ipv6', # Address Prefix
1541 # prefixlength => 'int', # PrefixLength
1542 # ],
1543 # router => 'ipv4', # Referenced Advertising Router
1544 # # Designated Router's Router ID
1545 # routerid => 'ipv4', # Advertising Router
1546 # ],
1547 ########################################################################
1548 # $intranethash{$interface}{$router}{$area} = {
1549 # graph => { N => intranetwork1, color => red, }
1550 # hashes => [ { intranetwork hash } ]
1551 # }
1552 ########################################################################
1553  
1554 # take intranetwork hash
1555 # detect inconsistencies and set colors
1556 sub check_intranetwork {
1557 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine check_intranetwork: not called CC=5 SCAR=34.0
Pod undocumented
1558 0 ▶ my $intranethash = $self->{intranethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $intranethash = $self->{"intranethash"} or die "Uninitialized member" 0 0 0
1559 0 my %colors;
1560 0 ▶ while (my($intf,$iv) = each %$intranethash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$intranethash) 0 0 0
1561 0 ▶ while (my($rid, $rv) = each %$iv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$iv) 0 0 0
1562 0 my $iid = "$intf\@$rid";
1563 0 ▶ while (my($area, $av) = each %$rv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$rv) 0 0 0
1564 0 $colors{gray} = $area;
1565 0 %{$av->{colors}} = %colors;
1566 }
1567 }
1568 }
1569 }
1570  
1571 sub create_intranetworks {
1572 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine create_intranetworks: not called CC=4 SCAR=30.0
Pod undocumented
1573 0 my $index = 0;
1574 0 my %intranethash;
1575 0 foreach my $i (@{$self->{ospf}{database}{intranetworks}}) {
1576 0 my $intf = $i->{interface};
1577 0 my $rid = $i->{router};
1578 0 my $area = $i->{area};
1579 0 my $elem = $intranethash{$intf}{$rid}{$area};
1580 0 ▶ if (! $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem) 0 0 0
1581 0 $intranethash{$intf}{$rid}{$area} = $elem = {};
1582 $elem->{graph} = {
1583 0 N => "intranetwork$index",
1584 label => "prefixes",
1585 shape => "octagon",
1586 style => "bold",
1587 };
1588 0 $elem->{index} = $index++;
1589 }
1590 0 push @{$elem->{hashes}}, $i;
1591 $elem->{graph}{label} = join("\\n",
1592 0 map { "$_->{prefixaddress}/$_->{prefixlength}" }
1593 0 ▶ map { @{$_->{prefixes} || []} } @{$elem->{hashes}});
Branch: 1 branch
BranchTrueFalseTotal
$_->{"prefixes"} or [] 0 0 0
1594 }
1595 0 $self->{intranethash} = \%intranethash;
1596 }
1597  
1598 # take hash containing intranetwork nodes
1599 # return list of nodes
1600 sub intranetwork2nodes {
1601 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine intranetwork2nodes: not called CC=2 SCAR=17.9
Pod undocumented
1602 0 ▶ my $intranethash = $self->{intranethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $intranethash = $self->{"intranethash"} or die "Uninitialized member" 0 0 0
1603 0 return $self->elements2graphs(map { values %$_ } map { values %$_ }
1604 values %$intranethash);
1605 }
1606  
1607 # take intranetwork hash, network hash, router hash
1608 # return list of edges from intranetwork to network and router
1609 sub intranetwork2edges {
1610 0 ▶ my OSPF::LSDB::View6 $self = shift;
Subroutine intranetwork2edges: not called CC=9 SCAR=45.0
Pod undocumented
1611 0 ▶ my $intranethash = $self->{intranethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $intranethash = $self->{"intranethash"} or die "Uninitialized member" 0 0 0
1612 0 ▶ my $nethash = $self->{nethash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $nethash = $self->{"nethash"} or die "Uninitialized member" 0 0 0
1613 0 ▶ my $routehash = $self->{routehash} or die "Uninitialized member";
Branch: 1 branch
BranchTrueFalseTotal
my $routehash = $self->{"routehash"} or die "Uninitialized member" 0 0 0
1614 0 my @elements;
1615 0 my $index = 0;
1616 0 foreach my $intf (sort keys %$intranethash) {
1617 0 my $iv = $intranethash->{$intf};
1618 0 foreach my $rid (sort keys %$iv) {
1619 0 my $rv = $iv->{$rid};
1620 0 my $iid = "$intf\@$rid";
1621 0 foreach my $area (sort keys %$rv) {
1622 0 my $av = $rv->{$area};
1623 0 my $src = $av->{graph}{N};
1624 my $dst = $nethash->{$intf}{$rid}{$area}{graph}{N}
1625 0 ▶ or die "No network graph $intf $rid $area";
Branch: 1 branch
BranchTrueFalseTotal
my $dst = $nethash->{$intf}{$rid}{$area}{"graph"}{"N"} or die "No network graph $intf $rid $area" 0 0 0
1626 0 my %colors;
1627 0 $colors{gray} = $area;
1628 0 foreach my $i (@{$av->{hashes}}) {
1629 0 my $addr = $i->{address};
1630 0 push @elements, {
1631 graph => {
1632 S => $src,
1633 D => $dst,
1634 style => "bold",
1635 taillabel => $addr,
1636 },
1637 colors => { %colors },
1638 index => $index++,
1639 };
1640 }
1641 }
1642 }
1643 }
1644 0 return $self->elements2graphs(@elements);
1645 }
1646  
1647 # return legend routers as dot graph
1648 sub legend_router {
1649 1 ▶ my $class = shift;
Subroutine legend_router: called CC=4 SCAR=13.9
Pod undocumented
1650 1 my $index = 0;
1651 1 my @nodes = (
1652 {
1653 label => 'ospf\nrouter',
1654 }, {
1655 label => 'current\nlocation',
1656 peripheries => 2,
1657 }, {
1658 label => 'area border\nrouter',
1659 style => 'bold',
1660 }, {
1661 label => 'summary AS\nboundary router',
1662 style => 'dashed',
1663 },
1664 );
1665 1 foreach (@nodes) {
1666 4 $_->{N} = 'router'. $index++;
1667 4 ▶ $_->{shape} ||= 'box';
Condition50%1/2
$_->{"shape"} ||= "box"
l!l
04
MC/DC0%0/1
$_->{"shape"} ||= "box"
$_->{"shape"}
Truth table50%1/2
A
A= $_->{"shape"}
Aresult
11
00
1668 4 ▶ $_->{style} ||= 'solid';
Condition100%2/2
$_->{"style"} ||= "solid"
l!l
22
MC/DC100%1/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1669 }
1670  
1671 1 my $dot = "";
1672 1 $dot .= $class->graph_nodes(@nodes);
1673 1 $dot .= "\t{ rank=same;";
1674 1 $dot .= join("", map { " $_->{N};" } @nodes);
1675 1 $dot .= " }\n";
1676 1 return $dot;
1677 }
1678  
1679 # return legend networks as dot graph
1680 sub legend_network {
1681 1 ▶ my $class = shift;
Subroutine legend_network: called CC=4 SCAR=13.9
Pod undocumented
1682 1 my $index = 0;
1683 1 my @nodes = (
1684 {
1685 label => 'transit\nnetwork',
1686 style => 'bold',
1687 }, {
1688 label => 'summary\nnetwork',
1689 style => 'dashed',
1690 }, {
1691 color => 'gray35',
1692 label => 'AS external\nnetwork',
1693 shape => 'egg',
1694 }, {
1695 label => 'link\nprefix',
1696 shape => 'hexagon',
1697 }, {
1698 label => 'intra-area\nprefix',
1699 shape => 'octagon',
1700 },
1701 );
1702 1 foreach (@nodes) {
1703 5 $_->{N} = 'network'. $index++;
1704 5 ▶ $_->{shape} ||= 'ellipse';
Condition100%2/2
$_->{"shape"} ||= "ellipse"
l!l
32
MC/DC100%1/1
$_->{"shape"} ||= "ellipse"
$_->{"shape"}
Truth table100%2/2
A
A= $_->{"shape"}
Aresult
11
00
1705 5 ▶ $_->{style} ||= 'solid';
Condition100%2/2
$_->{"style"} ||= "solid"
l!l
23
MC/DC100%1/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1706 }
1707  
1708 1 my $dot = "";
1709 1 $dot .= $class->graph_nodes(@nodes);
1710 1 $dot .= "\t{ rank=same;";
1711 1 $dot .= join("", map { " $_->{N};" } @nodes);
1712 1 $dot .= " }\n";
1713 1 return $dot;
1714 }
1715  
1716 # return legend router network edges as dot graph
1717 sub legend_edge {
1718 1 ▶ my $class = shift;
Subroutine legend_edge: called CC=8 SCAR=20.8
Pod undocumented
1719 1 my @networknodes = (
1720 {
1721 label => 'network',
1722 }, {
1723 label => 'transit\nnetwork',
1724 style => 'bold',
1725 }, {
1726 color => 'gray35',
1727 label => 'ASE type 1\nnetwork',
1728 shape => 'egg',
1729 }, {
1730 color => 'gray35',
1731 label => 'ASE type 2\nnetwork',
1732 shape => 'egg',
1733 }, {
1734 label => 'link\nprefix',
1735 shape => 'hexagon',
1736 }, {
1737 label => 'intra-area\nrouter prefix',
1738 shape => 'octagon',
1739 },
1740 );
1741 1 foreach (@networknodes) {
1742 6 ▶ $_->{shape} ||= 'ellipse';
Condition100%2/2
$_->{"shape"} ||= "ellipse"
l!l
42
MC/DC100%1/1
$_->{"shape"} ||= "ellipse"
$_->{"shape"}
Truth table100%2/2
A
A= $_->{"shape"}
Aresult
11
00
1743 6 ▶ $_->{style} ||= 'solid';
Condition100%2/2
$_->{"style"} ||= "solid"
l!l
15
MC/DC100%1/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1744 }
1745  
1746 1 my @routernodes = (
1747 {
1748 label => 'router',
1749 }, {
1750 label => 'designated\nrouter',
1751 }, {
1752 label => 'AS boundary\nrouter',
1753 }, {
1754 label => 'AS boundary\nrouter',
1755 }, {
1756 label => 'router',
1757 },
1758 );
1759 1 foreach (@routernodes) {
1760 5 ▶ $_->{shape} ||= 'box';
Condition50%1/2
$_->{"shape"} ||= "box"
l!l
05
MC/DC0%0/1
$_->{"shape"} ||= "box"
$_->{"shape"}
Truth table50%1/2
A
A= $_->{"shape"}
Aresult
11
00
1761 5 ▶ $_->{style} ||= 'solid';
Condition50%1/2
$_->{"style"} ||= "solid"
l!l
05
MC/DC0%0/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table50%1/2
A
A= $_->{"style"}
Aresult
11
00
1762 }
1763  
1764 1 my $index = 0;
1765 1 my @edges = (
1766 {
1767 headlabel => 'Interface',
1768 style => 'solid',
1769 taillabel => 'cost',
1770 }, {
1771 style => 'bold',
1772 }, {
1773 color => 'gray35',
1774 headlabel => 'cost',
1775 style => 'solid',
1776 taillabel => 'LS-ID'
1777 }, {
1778 color => 'gray35',
1779 headlabel => 'cost',
1780 style => 'dashed',
1781 taillabel => 'LS-ID'
1782 }, {
1783 style => 'bold',
1784 taillabel => 'Interface'
1785 }, {
1786 style => 'bold',
1787 taillabel => 'LS-ID'
1788 },
1789 );
1790 1 ▶ for(my $i=0; $i<@edges; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @edges) 6 1 7
1791 6 $networknodes[$i]{N} = 'edgenetwork'. $index;
1792 6 $routernodes [$i]{N} = 'edgerouter'. $index;
1793 6 $edges [$i]{S} = 'edgenetwork'. $index;
1794 6 $edges [$i]{D} = 'edgerouter'. $index;
1795 6 $index++;
1796 }
1797 # swap arrow for cost IF explanation
1798 1 ($edges[0]{D}, $edges[0]{S}) = ($edges[0]{S}, $edges[0]{D});
1799 # link and intra area prefix have same router destination
1800 1 $edges[-1]{D} = $edges[-2]{D};
1801 1 pop @routernodes;
1802  
1803 1 my $dot = "";
1804 1 $dot .= $class->graph_nodes(@networknodes);
1805 1 $dot .= $class->graph_nodes(@routernodes);
1806 1 $dot .= $class->graph_edges(@edges);
1807 1 $dot .= "\t{ rank=same;";
1808 1 $dot .= join("", map { " $_->{S};" } @edges);
1809 1 $dot .= " }\n";
1810 1 return $dot;
1811 }
1812  
1813 # return legend router link to router or network as dot graph
1814 sub legend_link {
1815 1 ▶ my $class = shift;
Subroutine legend_link: called CC=12 SCAR=24.9
Pod undocumented
1816 1 my @routernodes = (
1817 {}, {}, {
1818 label => 'designated\nrouter',
1819 }, {}, {
1820 label => 'link\nprefix',
1821 shape => 'hexagon',
1822 }, {
1823 label => 'intra-area\nnetwork prefix',
1824 shape => 'octagon',
1825 },
1826 );
1827 1 foreach (@routernodes) {
1828 6 ▶ $_->{label} ||= 'router';
Condition100%2/2
$_->{"label"} ||= "router"
l!l
33
MC/DC100%1/1
$_->{"label"} ||= "router"
$_->{"label"}
Truth table100%2/2
A
A= $_->{"label"}
Aresult
11
00
1829 6 ▶ $_->{shape} ||= 'box';
Condition100%2/2
$_->{"shape"} ||= "box"
l!l
24
MC/DC100%1/1
$_->{"shape"} ||= "box"
$_->{"shape"}
Truth table100%2/2
A
A= $_->{"shape"}
Aresult
11
00
1830 6 ▶ $_->{style} ||= 'solid';
Condition50%1/2
$_->{"style"} ||= "solid"
l!l
06
MC/DC0%0/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table50%1/2
A
A= $_->{"style"}
Aresult
11
00
1831 }
1832  
1833 1 my @dstnodes = (
1834 {}, {
1835 label => 'transit\nnetwork',
1836 style => 'bold',
1837 shape => 'ellipse',
1838 }, {
1839 label => 'transit\nnetwork',
1840 style => 'bold',
1841 shape => 'ellipse',
1842 }, {}, {
1843 label => 'transit\nnetwork',
1844 style => 'bold',
1845 shape => 'ellipse',
1846 },
1847 );
1848 1 foreach (@dstnodes) {
1849 $_->{label} ||= 'router',
1850 5 ▶ $_->{shape} ||= 'box';
Condition100%4/4
$_->{"label"} ||= "router"
l!l
32
$_->{"shape"} ||= "box"
l!l
32
MC/DC100%1/1
$_->{"label"} ||= "router"
$_->{"label"}
MC/DC100%1/1
$_->{"shape"} ||= "box"
$_->{"shape"}
Truth table100%2/2
A
A= $_->{"label"}
Aresult
11
00
Truth table100%2/2
A
A= $_->{"shape"}
Aresult
11
00
1851 5 ▶ $_->{style} ||= 'solid';
Condition100%2/2
$_->{"style"} ||= "solid"
l!l
32
MC/DC100%1/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1852 }
1853  
1854 1 my $index = 0;
1855 1 my @edges = (
1856 {
1857 label => 'point-to-point\nlink',
1858 }, {
1859 label => 'link to\ntransit network',
1860 }, {
1861 label => 'link to\ntransit network',
1862 style => 'bold',
1863 }, {
1864 label => 'virtual\nlink',
1865 style => 'dotted',
1866 }, {
1867 style => 'solid',
1868 }, {
1869 style => 'bold',
1870 taillabel => 'LS-ID',
1871 },
1872 );
1873 1 foreach (@edges) {
1874 6 ▶ $_->{style} ||= 'solid';
Condition100%2/2
$_->{"style"} ||= "solid"
l!l
42
MC/DC100%1/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1875 }
1876 1 ▶ for(my $i=0; $i<@edges; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @edges) 6 1 7
1877 6 $routernodes[$i]{N} = 'linkrouter'. $index;
1878 6 $dstnodes [$i]{N} = 'linkdst'. $index;
1879 6 $edges [$i]{S} = 'linkrouter'. $index;
1880 6 $edges [$i]{D} = 'linkdst'. $index;
1881 6 $index++;
1882 }
1883 # link and intra area prefix have same network destination
1884 1 $edges[-1]{D} = $edges[-2]{D};
1885 1 pop @dstnodes;
1886  
1887 1 my $dot = "";
1888 1 $dot .= $class->graph_nodes(@routernodes);
1889 1 $dot .= $class->graph_nodes(@dstnodes);
1890 1 $dot .= $class->graph_edges(@edges);
1891 1 $dot .= "\t{ rank=same;";
1892 1 $dot .= join("", map { " $_->{S};" } @edges);
1893 1 $dot .= " }\n";
1894 1 return $dot;
1895 }
1896  
1897 # return legend summary network and router edges as dot graph
1898 sub legend_summary {
1899 1 ▶ my $class = shift;
Subroutine legend_summary: called CC=9 SCAR=22.0
Pod undocumented
1900 1 my @networknodes = (
1901 {
1902 label => 'summary\nnetwork',
1903 style => 'dashed',
1904 }, {
1905 label => 'summary AS\nboundary router',
1906 shape => 'box',
1907 style => 'dashed',
1908 }, {
1909 label => 'router and summary \nAS boundary router',
1910 shape => 'box',
1911 }, {
1912 color => 'gray35',
1913 label => 'ASE\nnetwork',
1914 shape => 'egg',
1915 },
1916 );
1917 1 foreach (@networknodes) {
1918 4 ▶ $_->{shape} ||= 'ellipse';
Condition100%2/2
$_->{"shape"} ||= "ellipse"
l!l
31
MC/DC100%1/1
$_->{"shape"} ||= "ellipse"
$_->{"shape"}
Truth table100%2/2
A
A= $_->{"shape"}
Aresult
11
00
1919 4 ▶ $_->{style} ||= 'solid';
Condition100%2/2
$_->{"style"} ||= "solid"
l!l
22
MC/DC100%1/1
$_->{"style"} ||= "solid"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1920 }
1921  
1922 1 my @routernodes = (
1923 {}, {}, {
1924 color => 'black',
1925 }, {
1926 color => 'gray35',
1927 label => 'summary AS\nboundary router',
1928 style => 'dashed',
1929 },
1930 );
1931 1 foreach (@routernodes) {
1932 4 ▶ $_->{label} ||= 'area border\nrouter';
Condition100%2/2
$_->{"label"} ||= "area border\\nrouter"
l!l
13
MC/DC100%1/1
$_->{"label"} ||= "area border\\nrouter"
$_->{"label"}
Truth table100%2/2
A
A= $_->{"label"}
Aresult
11
00
1933 4 ▶ $_->{shape} ||= 'box';
Condition50%1/2
$_->{"shape"} ||= "box"
l!l
04
MC/DC0%0/1
$_->{"shape"} ||= "box"
$_->{"shape"}
Truth table50%1/2
A
A= $_->{"shape"}
Aresult
11
00
1934 4 ▶ $_->{style} ||= 'bold';
Condition100%2/2
$_->{"style"} ||= "bold"
l!l
13
MC/DC100%1/1
$_->{"style"} ||= "bold"
$_->{"style"}
Truth table100%2/2
A
A= $_->{"style"}
Aresult
11
00
1935 }
1936  
1937 1 my $index = 0;
1938 1 my @edges = (
1939 {
1940 headlabel => 'cost',
1941 style => 'dashed',
1942 taillabel => 'LS-ID'
1943 }, {
1944 headlabel => 'cost',
1945 style => 'dashed',
1946 taillabel => 'LS-ID'
1947 }, {
1948 color => 'gray75',
1949 headlabel => 'cost',
1950 style => 'dashed',
1951 taillabel => 'LS-ID'
1952 }, {
1953 color => 'gray35',
1954 headlabel => 'cost',
1955 style => 'solid',
1956 taillabel => 'LS-ID'
1957 },
1958 );
1959 1 ▶ for(my $i=0; $i<@edges; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @edges) 4 1 5
1960 4 $networknodes[$i]{N} = 'summarynetwork'. $index;
1961 4 $routernodes [$i]{N} = 'summaryrouter'. $index;
1962 4 $edges [$i]{S} = 'summarynetwork'. $index;
1963 4 $edges [$i]{D} = 'summaryrouter'. $index;
1964 4 $index++;
1965 }
1966  
1967 1 my $dot = "";
1968 1 $dot .= $class->graph_nodes(@networknodes);
1969 1 $dot .= $class->graph_nodes(@routernodes);
1970 1 $dot .= $class->graph_edges(@edges);
1971 1 $dot .= "\t{ rank=same;";
1972 1 $dot .= join("", map { " $_->{S};" } @edges);
1973 1 $dot .= " }\n";
1974 1 return $dot;
1975 }
1976  
1977 =pod
1978  
1979 =head1 SEE ALSO
1980  
1981 L<OSPF::LSDB>,
1982 L<OSPF::LSDB::View>
1983  
1984 L<ospf2dot>,
1985 L<ospfview>
1986  
1987 RFC 5340 - OSPF for IPv6 - July 2008
1988  
1989 =head1 AUTHORS
1990  
1991 Alexander Bluhm
1992  
1993 =head1 BUGS
1994  
1995 IPv6 support has not been finished yet.
1996 Especially there are much less checks than in IPv4.
1997  
1998 =cut
1999  
2000 11 1;
« script/ospfview ↑ Summary blib/lib/OSPF/LSDB/Cisco.pm »