| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 70 | 1 | ▶ | usage("Only one arguments allowed") if @ARGV > 1; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | 1 | ▶ | unless ($ipv6) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 72 | 0 | ▶ | usage("Option -L also needs -6") if $files{link}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 73 | 0 | ▶ | usage("Option -P also needs -6") if $files{intra}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 1 | ▶ | my $class = $ipv6 ? 'OSPF::LSDB::ospf6d' : 'OSPF::LSDB::ospfd'; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 82 | 1 | $yaml->DumpFile($ARGV[0]); | |||||||||||||
| 83 | } else { | ||||||||||||||
| 84 | 0 | print $yaml->Dump(); | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | 1 | main(); | |||||||||||||