script/ospfd2yaml

filter: Statementstmt 92.9% 66 / 71 Branchbran 43.3% 13 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod n/a totaltotal 80.6% 96 / 119 CC 16 SCAR 17.7
CC
16
Cov
78%
main
10.9
main
10.9
usage
2.0
CRAP 5.9
« blib/lib/OSPF/LSDB/gated.pm ↑ Summary script/ciscoospf2yaml »
1 #!/usr/bin/perl
2  
3 ##########################################################################
4 # Copyright (c) 2010-2012 Alexander Bluhm <alexander.bluhm@gmx.net>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ##########################################################################
18  
19 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Getopt::Long qw(:config posix_default bundling);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use OSPF::LSDB::ospfd;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use OSPF::LSDB::ospf6d;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use OSPF::LSDB::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 sub usage(@) {
27 1 ▶ print STDERR "Error: @_\n" if @_;
Subroutine usage: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
28 1 print STDERR <<EOF;
29 Convert OpenBSD ospfd or ospf6d link state database to YAML file.
30 If the ospfctl content files are not given on the command line,
31 ospfctl is invoked on the local machine.
32  
33 Usage: $0 [-46h] [-B boundary] [-E external] [-H user\@host]
34 [-I selfid] [-N network] [-R router] [-S summary] [ospf.yaml]
35 -4 use ospfd (default)
36 -6 use ospf6d instead of ospfd
37 -h help, print usage
38 -B boundary file containg output of 'ospfctl show database asbr'
39 -E external file containg output of 'ospfctl show database external'
40 -H user\@host use ssh to login into user\@host to run ospfctl there
41 -I selfid file containg output of 'ospfctl show summary'
42 -L link file containg output of 'ospf6ctl show database link'
43 -N network file containg output of 'ospfctl show database network'
44 -P intra file containg output of 'ospf6ctl show database intra'
45 -R router file containg output of 'ospfctl show database router'
46 -S summary file containg output of 'ospfctl show database summary'
47 ospf.yaml output file, default stdout
48 EOF
49 1 exit(2);
50 }
51  
52 sub main() {
53 2 ▶ my %files;
Subroutine main: called CC=8 SCAR=23.9
Subroutine main: called CC=8 SCAR=23.9
54 my $ipv6;
55 2 my $ssh;
56 GetOptions(
57 0 ▶ '4' => sub { $ipv6 = 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 1 ▶ '6' => sub { $ipv6 = 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
59 1 ▶ 'h' => sub { usage() },
Subroutine __ANON__: called CC=1 SCAR=0.0
60 'B=s' => \$files{boundary},
61 'E=s' => \$files{external},
62 'H=s' => \$ssh,
63 'I=s' => \$files{selfid},
64 'L=s' => \$files{link},
65 'N=s' => \$files{network},
66 'P=s' => \$files{intra},
67 'R=s' => \$files{router},
68 'S=s' => \$files{summary},
69 2 ▶ ) or usage("Bad option");
Branch: 2 branches
BranchTrueFalseTotal
&GetOptions(4, sub { $ipv6 = 0; } , 6, sub { $ipv6 = 1; } , "h", sub { &usage(); } , "B=s", \$files{"boundary"}, "E=s", \$files{"external"}, "H=s", \$ssh, "I=s", \$files{"selfid"}, "L=s", \$files{"link"}, "N=s", \$files{"network"}, "P=s", \$files{"intra"}, "R=s", \$files{"router"}, "S=s", \$files{"summary"}) or &usage("Bad option") 0 1 1
&GetOptions(4, sub { $ipv6 = 0; } , 6, sub { $ipv6 = 1; } , "h", sub { &usage(); } , "B=s", \$files{"boundary"}, "E=s", \$files{"external"}, "H=s", \$ssh, "I=s", \$files{"selfid"}, "L=s", \$files{"link"}, "N=s", \$files{"network"}, "P=s", \$files{"intra"}, "R=s", \$files{"router"}, "S=s", \$files{"summary"}) or &usage("Bad option") 0 1 1
70 1 ▶ usage("Only one arguments allowed") if @ARGV > 1;
Branch: 2 branches
BranchTrueFalseTotal
if @ARGV > 1 0 1 1
if @ARGV > 1 0 1 1
71 1 ▶ unless ($ipv6) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($ipv6) 0 1 1
unless ($ipv6) 1 0 1
72 0 ▶ usage("Option -L also needs -6") if $files{link};
Branch: 2 branches
BranchTrueFalseTotal
if $files{"link"} 0 0 0
if $files{"link"} 0 1 1
73 0 ▶ usage("Option -P also needs -6") if $files{intra};
Branch: 2 branches
BranchTrueFalseTotal
if $files{"intra"} 0 0 0
if $files{"intra"} 0 1 1
74 }
75  
76 1 ▶ my $class = $ipv6 ? 'OSPF::LSDB::ospf6d' : 'OSPF::LSDB::ospfd';
Branch: 2 branches
BranchTrueFalseTotal
$ipv6 ? : 1 0 1
$ipv6 ? : 0 1 1
77 1 my $ospfd = $class->new(ssh => $ssh);
78 1 $ospfd->parse(%files);
79  
80 1 my $yaml = OSPF::LSDB::YAML->new($ospfd);
81 1 ▶ if (@ARGV > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@ARGV > 0) { } 1 0 1
if (@ARGV > 0) { } 1 0 1
82 1 $yaml->DumpFile($ARGV[0]);
83 } else {
84 0 print $yaml->Dump();
85 }
86 }
87  
88 1 main();
« blib/lib/OSPF/LSDB/gated.pm ↑ Summary script/ciscoospf2yaml »