blib/lib/OSPF/LSDB/ospf6d.pm

filter: Statementstmt 99.2% 249 / 251 Branchbran 97.4% 230 / 236 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 17 / 17 Podpod 20.0% 2 / 10 totaltotal 96.9% 513 / 529 CC 128 SCAR 32.7
CC
128
Cov
98%
parse_router
39.1
parse_intra
31.0
parse_link
23.0
CRAP 26.4
« blib/lib/OSPF/LSDB/Cisco.pm ↑ Summary blib/lib/OSPF/LSDB/ospfd.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::ospf6d - parse OpenBSD B<ospf6d> link state database
25  
26 =head1 SYNOPSIS
27  
28 use OSPF::LSDB::ospf6d;
29  
30 my $ospf6d = OSPF::LSDB::ospf6d-E<gt>new();
31  
32 my $ospf6d = OSPF::LSDB::ospf6d-E<gt>new(ssh => "user@host");
33  
34 $ospf6d-E<gt>parse(%files);
35  
36 =head1 DESCRIPTION
37  
38 The OSPF::LSDB::ospf6d module parses the output of OpenBSD
39 B<ospf6ctl> and fills the L<OSPF::LSDB> base object.
40 The output of
41 C<show summary>,
42 C<show database router>,
43 C<show database network>,
44 C<show database summary>,
45 C<show database asbr>,
46 C<show database external>
47 C<show database link>
48 C<show database intra>
49 is needed.
50 It can be given as separate files or obtained dynamically.
51 In the latter case B<doas> is invoked if permissions are not
52 sufficient to run B<ospf6ctl>.
53 If the object has been created with the C<ssh> argument, the specified
54 user and host are used to login and run B<ospf6ctl> there.
55  
56 There is only one public method:
57  
58 =cut
59  
60 package OSPF::LSDB::ospf6d;
61 11 ▶use base 'OSPF::LSDB::ospfd';
Subroutine BEGIN: called CC=1 SCAR=0.0
62 11 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 11 ▶use Regexp::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 11 ▶use Regexp::IPv6;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 11 use fields qw(
66 link intra
67 11 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 sub new {
70 8 ▶ my OSPF::LSDB::ospf6d $self = OSPF::LSDB::ospfd::new(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
71 8 $self->{ospfd} = "ospf6d";
72 8 $self->{ospfctl} = "ospf6ctl";
73 # XXX hard coded routing domain 0
74 8 $self->{ospfsock} = "/var/run/ospf6d.sock.0";
75 8 %{$self->{showdb}} = (%{$self->{showdb}}, (
76 link => "link",
77 intra => "intra",
78 ));
79 8 return $self;
80 }
81  
82 # shortcut
83 11 my $IP = qr/$RE{net}{IPv4}{-keep}/;
84 11 my $IP6 = qr/($Regexp::IPv6::IPv6_re|::)/;
85 11 my $PREFIX = qr,($Regexp::IPv6::IPv6_re|::)/$RE{num}{int}{-keep},;
86  
87 sub parse_router {
88 16 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_router: called CC=39 SCAR=36.7
Pod undocumented
89 16 my($area, $router, $link) = ("", "", "");
90 16 my(@routers, $lnum, $type, $r, $l);
91 16 foreach (@{$self->{router}}) {
92 327 ▶ if (/^ +Router Link States \(Area $IP\)$/) {
Branch: 4 branches
BranchTrueFalseTotal
if (/^ +Router Link States \(Area $IP\)$/) { } 18 309 327
elsif (/^$/) { } 62 247 309
elsif (not $r and /^\w/) { } 21 226 247
elsif (not $l and /^ {4}\w/) { } 19 255 274
93 18 ▶ die "$_ Link $link of router $router in area $area not finished.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $l 1 17 18
94 if $l;
95 17 ▶ die "$_ Too few links at router $router in area $area.\n" if $lnum;
Branch: 1 branch
BranchTrueFalseTotal
if $lnum 1 16 17
96 16 ▶ die "$_ Router $router in area $area not finished.\n" if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 1 15 16
97 15 $area = $1;
98 15 next;
99 } elsif (/^$/) {
100 62 ▶ if ($l) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l) 14 48 62
101 14 ▶ die "Link $link of router $router in area $area without type.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 13 14
102 if ! $type;
103 13 push @{$r->{$type.'s'}}, $l;
104 13 undef $type;
105 13 undef $l;
106 }
107 61 ▶ if (! $lnum) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lnum) 41 20 61
108 41 undef $r;
109 }
110 61 next;
111 ▶ } elsif (! $r && /^\w/) {
Condition100%3/3
not $r and /^\w/
!ll&&!rl&&r
225121
MC/DC100%2/2
not $r and /^\w/
not $r /^\w/
Truth table100%3/3
not(A) and B
A= not $rB= /^\w/
ABresult
0X0
100
111
112 21 ▶ die "$_ No area for router defined.\n" if ! $area;
Branch: 1 branch
BranchTrueFalseTotal
unless $area 1 20 21
113 20 $router = "";
114 20 $r = { area => $area };
115 20 push @routers, $r;
116 ▶ } elsif (! $l && /^ {4}\w/) {
Condition100%3/3
not $l and /^ {4}\w/
!ll&&!rl&&r
4815919
MC/DC100%2/2
not $l and /^ {4}\w/
not $l /^ {4}\w/
Truth table100%3/3
not(A) and B
A= not $lB= /^ {4}\w/
ABresult
0X0
100
111
117 19 ▶ die "$_ Too many links at router $router in area $area.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $lnum 1 18 19
118 if ! $lnum;
119 18 $lnum--;
120 18 $link = "";
121 18 $l = {};
122 }
123 245 ▶ if (/^LS age: $RE{num}{int}{-keep}$/) {
Branch: 13 branches
BranchTrueFalseTotal
if (/^LS age: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 20 225 245
elsif (/^LS Type: ([\w ()]+)$/) { } 20 205 225
elsif (/^Link State ID: $IP$/) { } 19 186 205
elsif (/^Advertising Router: $IP$/) { } 19 167 186
elsif (/^LS Seq Number: (0x$OSPF::LSDB::ospf6d::RE{'num'}{'hex'})$/) { } 19 148 167
elsif (/^Flags: ([-*|\w]*)$/) { } 16 132 148
elsif (/^Number of Links: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 16 116 132
elsif (/^ Link \([ .\w]*\) connected to: ([\w -]+)$/) { } 17 99 116
elsif (/^ (?:Designated )?Router ID: $IP$/) { } 17 82 99
elsif (/^ (?:DR )?Interface ID: $IP$/) { } 17 65 82
elsif (/^ Metric: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 14 51 65
elsif (/^ {4}\w/) { } 1 50 51
elsif (not /^(Options|Checksum|Length):/) { } 1 49 50
124 20 $r->{age} = $1;
125 } elsif (/^LS Type: ([\w ()]+)$/) {
126 20 ▶ die "$_ Type of router-LSA is $1 and not Router in area $area.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "Router" 1 19 20
127 if $1 ne "Router";
128 } elsif (/^Link State ID: $IP$/) {
129 19 $r->{router} = $1;
130 } elsif (/^Advertising Router: $IP$/) {
131 19 $r->{routerid} = $1;
132 19 $router = $1;
133 } elsif (/^LS Seq Number: (0x$RE{num}{hex})$/) {
134 19 $r->{sequence} = $1;
135 } elsif (/^Flags: ([-*|\w]*)$/) {
136 16 my $flags = $1;
137 16 foreach (qw(W V E B)) {
138 64 ▶ $r->{bits}{$_} = $flags =~ /\b$_\b/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$flags =~ /\b$_\b/ ? : 16 48 64
139 }
140 } elsif (/^Number of Links: $RE{num}{int}{-keep}$/) {
141 16 $lnum = $1;
142 } elsif (/^ Link \([ .\w]*\) connected to: ([\w -]+)$/) {
143 17 ▶ if ($1 eq "Point-to-Point") {
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq 'Point-to-Point') { } 0 17 17
elsif ($1 eq 'Transit Network') { } 16 1 17
elsif ($1 eq 'Virtual Link') { } 0 1 1
144 0 $type = "pointtopoint";
145 } elsif ($1 eq "Transit Network") {
146 16 $type = "transit";
147 } elsif ($1 eq "Virtual Link") {
148 0 $type = "virtual";
149 } else {
150 1 die "$_ Unknown link type $1 at router $router ".
151 "in area $area.\n";
152 }
153 16 ▶ if (/\(Interface ID $IP\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\(Interface ID $IP\)/) 16 0 16
154 16 $l->{interface} = $1;
155 }
156 } elsif (/^ (?:Designated )?Router ID: $IP$/) {
157 17 $l->{routerid} = $1;
158 17 $link = $1;
159 } elsif (/^ (?:DR )?Interface ID: $IP$/) {
160 17 $l->{address} = $1;
161 17 $link = "$1\@$link";
162 } elsif (/^ Metric: $RE{num}{int}{-keep}$/) {
163 14 $l->{metric} = $1;
164 } elsif (/^ {4}\w/) {
165 1 die "$_ Unknown line at link $link of router $router ".
166 "in area $area.\n";
167 } elsif (! /^(Options|Checksum|Length):/) {
168 1 die "$_ Unknown line at router $router in area $area.\n";
169 }
170 }
171 6 ▶ die "Link $link of router $router in area $area not finished.\n" if $l;
Branch: 1 branch
BranchTrueFalseTotal
if $l 1 5 6
172 5 ▶ die "Too few links at router $router in area $area.\n" if $lnum;
Branch: 1 branch
BranchTrueFalseTotal
if $lnum 1 4 5
173 4 ▶ die "Router $router in area $area not finished.\n" if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 1 3 4
174 3 $self->{ospf}{database}{routers} = \@routers;
175 }
176  
177 sub parse_network {
178 11 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_network: called CC=22 SCAR=30.9
Pod undocumented
179 11 my($area, $network) = ("", "");
180 11 my(@networks, $attachments, $rnum, $n);
181 11 foreach (@{$self->{network}}) {
182 122 ▶ if (/^ +Net Link States \(Area $IP\)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^ +Net Link States \(Area $IP\)$/) { } 12 110 122
elsif (/^$/) { } 26 84 110
elsif (not $n) { } 11 73 84
183 12 ▶ die "$_ Attached routers of network $network in area $area ".
Branch: 1 branch
BranchTrueFalseTotal
if $attachments 1 11 12
184 "not finished.\n" if $attachments;
185 11 ▶ die "$_ Network $network in area $area not finished.\n" if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 1 10 11
186 10 $area = $1;
187 10 next;
188 } elsif (/^$/) {
189 26 ▶ die "$_ Too few attached routers at network $network ".
Branch: 1 branch
BranchTrueFalseTotal
if $rnum 1 25 26
190 "in area $area.\n" if $rnum;
191 25 undef $attachments;
192 25 undef $n;
193 25 next;
194 } elsif (! $n) {
195 11 ▶ die "$_ No area for network defined.\n" if ! $area;
Branch: 1 branch
BranchTrueFalseTotal
unless $area 1 10 11
196 10 $network = "";
197 10 $n = { area => $area };
198 10 push @networks, $n;
199 }
200 83 ▶ if (/^LS age: $RE{num}{int}{-keep}$/) {
Branch: 8 branches
BranchTrueFalseTotal
if (/^LS age: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 10 73 83
elsif (/^LS Type: ([\w ()]+)$/) { } 10 63 73
elsif (/^Link State ID: $IP \(Interface ID of Designated Router\)$/) { } 9 54 63
elsif (/^Advertising Router: $IP$/) { } 9 45 54
elsif (/^LS Seq Number: (0x$OSPF::LSDB::ospf6d::RE{'num'}{'hex'})$/) { } 9 36 45
elsif (/^Number of Routers: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 6 30 36
elsif (/^ Attached Router: $IP$/) { } 10 20 30
elsif (not /^(Options|Checksum|Length):/) { } 1 19 20
201 10 $n->{age} = $1;
202 } elsif (/^LS Type: ([\w ()]+)$/) {
203 10 ▶ die "$_ Type of network-LSA is $1 and not Network in area $area.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "Network" 1 9 10
204 if $1 ne "Network";
205 } elsif (/^Link State ID: $IP \(Interface ID of Designated Router\)$/) {
206 9 $n->{address} = $1;
207 9 $network = $1;
208 } elsif (/^Advertising Router: $IP$/) {
209 9 $n->{routerid} = $1;
210 9 $network .= "\@$1";
211 } elsif (/^LS Seq Number: (0x$RE{num}{hex})$/) {
212 9 $n->{sequence} = $1;
213 } elsif (/^Number of Routers: $RE{num}{int}{-keep}$/) {
214 6 $rnum = $1;
215 } elsif (/^ Attached Router: $IP$/) {
216 10 ▶ if (! $attachments) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attachments) 6 4 10
217 6 $attachments = [];
218 6 $n->{attachments} = $attachments;
219 }
220 10 ▶ $rnum-- if defined $rnum ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rnum 10 0 10
221 10 push @$attachments, { routerid => $1 };
222 } elsif (! /^(Options|Checksum|Length):/) {
223 1 die "$_ Unknown line at network $network in area $area.\n";
224 }
225 }
226 5 ▶ die "Attached routers of network $network in area $area not finished.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $attachments 1 4 5
227 if $attachments;
228 4 ▶ die "Network $network in area $area not finished.\n" if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 1 3 4
229 3 $self->{ospf}{database}{networks} = \@networks;
230 }
231  
232 sub parse_summary {
233 2 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_summary: called CC=1 SCAR=0.0
Pod undocumented
234 # XXX not yet
235 2 $self->{ospf}{database}{summarys} = [];
236 }
237  
238 sub parse_boundary {
239 2 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_boundary: called CC=1 SCAR=0.0
Pod undocumented
240 # XXX not yet
241 2 $self->{ospf}{database}{boundarys} = [];
242 }
243  
244 sub parse_external {
245 8 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_external: called CC=17 SCAR=28.3
Pod undocumented
246 8 my $external = "";
247 8 my(@externals, $e);
248 8 foreach (@{$self->{external}}) {
249 331 ▶ if (/^ +Type-5 AS External Link States$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^ +Type-5 AS External Link States$/) { } 10 321 331
elsif (/^$/) { } 42 279 321
elsif (not $e) { } 30 249 279
250 10 ▶ die "$_ External $external not finished.\n" if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 1 9 10
251 9 ▶ die "$_ Too many external sections.\n", if @externals;
Branch: 1 branch
BranchTrueFalseTotal
if @externals 1 8 9
252 8 next;
253 } elsif (/^$/) {
254 42 undef $e;
255 42 next;
256 } elsif (! $e) {
257 30 $external = "";
258 30 $e = {};
259 30 push @externals, $e;
260 }
261 279 ▶ if (/^LS age: $RE{num}{int}{-keep}$/) {
Branch: 8 branches
BranchTrueFalseTotal
if (/^LS age: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 30 249 279
elsif (/^LS Type: ([\w ()]+)$/) { } 30 219 249
elsif (/^Link State ID: $IP$/) { } 29 190 219
elsif (/^Advertising Router: $IP$/) { } 29 161 190
elsif (/^LS Seq Number: (0x$OSPF::LSDB::ospf6d::RE{'num'}{'hex'})$/) { } 29 132 161
elsif (/^ Metric: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'} Type: ([1-2])$/) { } 26 106 132
elsif (/^ Prefix: $PREFIX$/) { } 26 80 106
elsif (not /^(Checksum|Length| Flags):/) { } 1 79 80
262 30 $e->{age} = $1;
263 } elsif (/^LS Type: ([\w ()]+)$/) {
264 30 ▶ die "$_ Type of external-LSA is $1 and not AS External.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "AS External" 1 29 30
265 if $1 ne "AS External";
266 } elsif (/^Link State ID: $IP$/) {
267 29 $e->{address} = $1;
268 29 $external = $1;
269 } elsif (/^Advertising Router: $IP$/) {
270 29 $e->{routerid} = $1;
271 29 $external .= "\@$1";
272 } elsif (/^LS Seq Number: (0x$RE{num}{hex})$/) {
273 29 $e->{sequence} = $1;
274 } elsif (/^ Metric: $RE{num}{int}{-keep} Type: ([1-2])$/) {
275 26 $e->{metric} = $1;
276 26 $e->{type} = $4;
277 } elsif (/^ Prefix: $PREFIX$/) {
278 26 $e->{prefixaddress} = $1;
279 26 $e->{prefixlength} = $2;
280 } elsif (! /^(Checksum|Length| Flags):/) {
281 1 die "$_ Unknown line at external $external.\n";
282 }
283 }
284 4 ▶ die "External $external not finished.\n" if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 1 3 4
285 3 $self->{ospf}{database}{externals} = \@externals;
286 }
287  
288 sub parse_link {
289 11 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_link: called CC=23 SCAR=31.4
Pod undocumented
290 11 my($area, $link) = ("", "");
291 11 my(@links, $prefixes, $pnum, $l);
292 11 foreach (@{$self->{link}}) {
293 397 ▶ if (/^ +Link \(Type-8\) Link States \(Area $IP Interface \w+\)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^ +Link \(Type-8\) Link States \(Area $IP Interface \w+\)$/) { } 19 378 397
elsif (/^$/) { } 59 319 378
elsif (not $l) { } 30 289 319
294 19 ▶ die "$_ Prefixes of link $link in area $area not finished.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $prefixes 1 18 19
295 if $prefixes;
296 18 ▶ die "$_ Link $link in area $area not finished.\n" if $l;
Branch: 1 branch
BranchTrueFalseTotal
if $l 1 17 18
297 17 $area = $1;
298 17 next;
299 } elsif (/^$/) {
300 59 ▶ die "$_ Too few prefixes at link $link in area $area.\n" if $pnum;
Branch: 1 branch
BranchTrueFalseTotal
if $pnum 1 58 59
301 58 undef $prefixes;
302 58 undef $l;
303 58 next;
304 } elsif (! $l) {
305 30 ▶ die "$_ No area for link defined.\n" if ! $area;
Branch: 1 branch
BranchTrueFalseTotal
unless $area 1 29 30
306 29 $link = "";
307 29 $l = { area => $area };
308 29 push @links, $l;
309 }
310 318 ▶ if (/^LS age: $RE{num}{int}{-keep}$/) {
Branch: 9 branches
BranchTrueFalseTotal
if (/^LS age: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 29 289 318
elsif (/^LS Type: ([\w ()]+)$/) { } 29 260 289
elsif (/^Link State ID: $IP \(Interface ID of Advertising Router\)$/) { } 28 232 260
elsif (/^Advertising Router: $IP$/) { } 28 204 232
elsif (/^LS Seq Number: (0x$OSPF::LSDB::ospf6d::RE{'num'}{'hex'})$/) { } 28 176 204
elsif (/^Link Local Address: ($IP6)$/) { } 25 151 176
elsif (/^Number of Prefixes: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 25 126 151
elsif (/^ Prefix: $PREFIX$/) { } 49 77 126
elsif (not /^(Options|Checksum|Length):/) { } 1 76 77
311 29 $l->{age} = $1;
312 } elsif (/^LS Type: ([\w ()]+)$/) {
313 29 ▶ die "$_ Type of link-LSA is $1 and not Link in area $area.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "Link" 1 28 29
314 if $1 ne "Link";
315 } elsif (/^Link State ID: $IP \(Interface ID of Advertising Router\)$/) {
316 28 $l->{interface} = $1;
317 28 $link = $1;
318 } elsif (/^Advertising Router: $IP$/) {
319 28 $l->{routerid} = $1;
320 28 $link .= "\@$1";
321 } elsif (/^LS Seq Number: (0x$RE{num}{hex})$/) {
322 28 $l->{sequence} = $1;
323 } elsif (/^Link Local Address: ($IP6)$/) {
324 25 $l->{linklocal} = $1;
325 } elsif (/^Number of Prefixes: $RE{num}{int}{-keep}$/) {
326 25 $pnum = $1;
327 } elsif (/^ Prefix: $PREFIX$/) {
328 49 ▶ if (! $prefixes) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prefixes) 10 39 49
329 10 $prefixes = [];
330 10 $l->{prefixes} = $prefixes;
331 }
332 49 ▶ $pnum-- if defined $pnum ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pnum 49 0 49
333 49 push @$prefixes, { prefixaddress => $1, prefixlength => $2 };
334 } elsif (! /^(Options|Checksum|Length):/) {
335 1 die "$_ Unknown line at link $link in area $area.\n";
336 }
337 }
338 5 ▶ die "Prefixes of link $link in area $area not finished.\n" if $prefixes;
Branch: 1 branch
BranchTrueFalseTotal
if $prefixes 1 4 5
339 4 ▶ die "Link $link in area $area not finished.\n" if $l;
Branch: 1 branch
BranchTrueFalseTotal
if $l 1 3 4
340 3 $self->{ospf}{database}{links} = \@links;
341 }
342  
343 sub parse_intra {
344 14 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_intra: called CC=31 SCAR=34.3
Pod undocumented
345 14 my($area, $intra) = ("", "");
346 14 my(@intranetworks, @intrarouters, $type, $prefixes, $pnum, $i);
347 14 foreach (@{$self->{intra}}) {
348 435 ▶ if (/^ +Intra Area Prefix Link States \(Area $IP\)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^ +Intra Area Prefix Link States \(Area $IP\)$/) { } 15 420 435
elsif (/^$/) { } 50 370 420
elsif (not $i) { } 31 339 370
349 15 ▶ die "$_ Prefixes of intra-area-prefix $intra in area $area ".
Branch: 1 branch
BranchTrueFalseTotal
if $prefixes 1 14 15
350 "not finished.\n" if $prefixes;
351 14 ▶ die "$_ Intra-area-prefix $intra in area $area not finished.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $i 1 13 14
352 if $i;
353 13 $area = $1;
354 13 next;
355 } elsif (/^$/) {
356 50 ▶ die "$_ Too few prefixes at intra-area-prefix $intra ".
Branch: 1 branch
BranchTrueFalseTotal
if $pnum 1 49 50
357 "in area $area.\n" if $pnum;
358 49 ▶ die "$_ Intra-area-prefix $intra in area $area has no ".
Branch: 1 branch
BranchTrueFalseTotal
if $i and not $type 1 48 49
Condition100%3/3
$i and not $type
!ll&&!rl&&r
28201
MC/DC100%2/2
$i and not $type
$i not $type
Truth table100%3/3
A and not(B)
A= $iB= not $type
ABresult
0X0
100
111
359 "referenced LS type.\n" if $i && ! $type;
360 48 undef $type;
361 48 undef $prefixes;
362 48 undef $i;
363 48 next;
364 } elsif (! $i) {
365 31 ▶ die "$_ No area for intra-area-prefix defined.\n" if ! $area;
Branch: 1 branch
BranchTrueFalseTotal
unless $area 1 30 31
366 30 $intra = "";
367 30 $i = { area => $area };
368 }
369 369 ▶ if (/^LS age: $RE{num}{int}{-keep}$/) {
Branch: 11 branches
BranchTrueFalseTotal
if (/^LS age: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 30 339 369
elsif (/^LS Type: ([\w ()]+)$/) { } 30 309 339
elsif (/^Link State ID: $IP$/) { } 29 280 309
elsif (/^Advertising Router: $IP$/) { } 29 251 280
elsif (/^LS Seq Number: (0x$OSPF::LSDB::ospf6d::RE{'num'}{'hex'})$/) { } 29 222 251
elsif (/^Referenced LS Type: (\w+)$/) { } 26 196 222
elsif (/^Referenced Link State ID: $IP$/) { } 23 173 196
elsif (/^Referenced Advertising Router: $IP$/) { } 23 150 173
elsif (/^Number of Prefixes: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'}$/) { } 23 127 150
elsif (/^ Prefix: $PREFIX(?: Options: \S+)?(?: Metric: $OSPF::LSDB::ospf6d::RE{'num'}{'int'}{'-keep'})?$/) { } 73 54 127
elsif (not /^(Checksum|Length):/) { } 1 53 54
370 30 $i->{age} = $1;
371 } elsif (/^LS Type: ([\w ()]+)$/) {
372 30 ▶ die "$_ Type of intra-area-prefix-LSA is $1 and not Intra Area ".
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "Intra Area (Prefix)" 1 29 30
373 "(Prefix) in area $area.\n" if $1 ne "Intra Area (Prefix)";
374 } elsif (/^Link State ID: $IP$/) {
375 29 $i->{address} = $1;
376 29 $intra = $1;
377 } elsif (/^Advertising Router: $IP$/) {
378 29 $i->{routerid} = $1;
379 29 $intra .= "\@$1";
380 } elsif (/^LS Seq Number: (0x$RE{num}{hex})$/) {
381 29 $i->{sequence} = $1;
382 } elsif (/^Referenced LS Type: (\w+)$/) {
383 26 ▶ die "$_ Referenced LS type given more than once ".
Branch: 1 branch
BranchTrueFalseTotal
if $type 1 25 26
384 "at intra-area-prefix $intra in area $area.\n" if $type;
385 25 $type = $1;
386 25 ▶ if ($type eq "Router") {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'Router') { } 13 12 25
elsif ($type eq 'Network') { } 11 1 12
387 13 push @intrarouters, $i
388 } elsif ($type eq "Network") {
389 11 push @intranetworks, $i
390 } else {
391 1 die "$_ Unknown referenced LS type $type ".
392 "at intra-area-prefix $intra in area $area.\n";
393 }
394 } elsif (/^Referenced Link State ID: $IP$/) {
395 23 $i->{interface} = $1;
396 } elsif (/^Referenced Advertising Router: $IP$/) {
397 23 $i->{router} = $1;
398 } elsif (/^Number of Prefixes: $RE{num}{int}{-keep}$/) {
399 23 $pnum = $1;
400 } elsif (/^ Prefix: $PREFIX(?: Options: \S+)?(?: Metric: $RE{num}{int}{-keep})?$/) {
401 73 ▶ if (! $prefixes) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prefixes) 20 53 73
402 20 $prefixes = [];
403 20 $i->{prefixes} = $prefixes;
404 }
405 73 ▶ $pnum-- if defined $pnum ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pnum 73 0 73
406 73 my %pfx = (prefixaddress => $1, prefixlength => $2);
407 73 ▶ $pfx{metric} = $5 if defined $5;
Branch: 1 branch
BranchTrueFalseTotal
if defined $5 15 58 73
408 73 push @$prefixes, \%pfx;
409 } elsif (! /^(Checksum|Length):/) {
410 1 die "$_ Unknown line at intra-area-prefix $intra in area $area.\n";
411 }
412 }
413 5 ▶ die "Prefixes of intra-area-prefix $intra in area $area not finished.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $prefixes 1 4 5
414 if $prefixes;
415 4 ▶ die "Intra-area-prefix $intra in area $area not finished.\n" if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 1 3 4
416 3 $self->{ospf}{database}{intranetworks} = \@intranetworks;
417 3 $self->{ospf}{database}{intrarouters} = \@intrarouters;
418 }
419  
420 sub parse_lsdb {
421 2 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse_lsdb: called CC=1 SCAR=0.0
Pod undocumented
422 2 $self->SUPER::parse_lsdb(@_);
423 2 $self->parse_link();
424 2 $self->parse_intra();
425 }
426  
427 =pod
428  
429 =over 4
430  
431 =item $self-E<gt>parse(%files)
432  
433 This function takes a hash with file names as value containing the
434 B<ospf6ctl> output data.
435 The hash keys are named C<selfid>, C<router>, C<network>, C<summary>,
436 C<boundary>, C<external>, C<link>, C<intra>.
437 If a hash entry is missing, B<ospf6ctl> is run instead to obtain the
438 information dynamically.
439  
440 The complete OSPF link state database is stored in the B<ospf> field
441 of the base class.
442  
443 =back
444  
445 =cut
446  
447 sub parse {
448 2 ▶ my OSPF::LSDB::ospf6d $self = shift;
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
449 2 $self->SUPER::parse(@_);
450 2 $self->{ospf}{ipv6} = 1;
451 }
452  
453 =pod
454  
455 This module has been tested with OpenBSD 5.1.
456 If it works with other versions is unknown.
457  
458 =head1 ERRORS
459  
460 The methods die if any error occurs.
461  
462 =head1 SEE ALSO
463  
464 L<OSPF::LSDB>,
465 L<OSPF::LSDB::ospfd>
466  
467 L<ospfd2yaml>
468  
469 =head1 AUTHORS
470  
471 Alexander Bluhm
472  
473 =cut
474  
475 11 1;
« blib/lib/OSPF/LSDB/Cisco.pm ↑ Summary blib/lib/OSPF/LSDB/ospfd.pm »