File Coverage

script/ciscoospf2yaml
Criterion Covered Total %
statement 21 28 75.0
branch 1 8 12.5
condition n/a
subroutine 8 8 100.0
pod n/a
total 30 44 68.1


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             ##########################################################################
4             # Copyright (c) 2010-2012 Alexander Bluhm
5             #
6             # Permission to use, copy, modify, and distribute this software for any
7             # purpose with or without fee is hereby granted, provided that the above
8             # copyright notice and this permission notice appear in all copies.
9             #
10             # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11             # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12             # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13             # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14             # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15             # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16             # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17             ##########################################################################
18              
19 1     1   3755 use strict;
  1         10  
  1         59  
20 1     1   11 use warnings;
  1         7  
  1         106  
21 1     1   680 use Getopt::Long qw(:config posix_default bundling);
  1         8778  
  1         3  
22 1     1   1547 use OSPF::LSDB::Cisco;
  1         4  
  1         34  
23 1     1   404 use OSPF::LSDB::YAML;
  1         2  
  1         246  
24              
25             sub usage(@) {
26 1 50   1   4 print STDERR "Error: @_\n" if @_;
27 1         46 print STDERR <
28             Convert Cisco OSPF link state database to YAML file. If the show
29             ip ospf content files are not given on the command line, ssh is
30             invoked to log into the router.
31              
32             Usage: $0 [-h] [-B boundary] [-E external] [-H user\@host]
33             [-I selfid] [-N network] [-R router] [-S summary] [ospf.yaml]
34             -h help, print usage
35             -B boundary file containg output of 'show ip ospf database asbr-summary'
36             -E external file containg output of 'show ip ospf database external'
37             -H user\@host use user\@host for ssh login
38             -I selfid file containg output of 'show ip ospf summary'
39             -N network file containg output of 'show ip ospf database network'
40             -R router file containg output of 'show ip ospf database router'
41             -S summary file containg output of 'show ip ospf database summary'
42             ospf.yaml output file, default stdout
43             EOF
44 1         146 exit(2);
45             }
46              
47             sub main() {
48 1     1   2 my(%files, $ssh);
49             GetOptions(
50 1     1   605 'h' => sub { usage() },
51             'B=s' => \$files{boundary},
52             'E=s' => \$files{external},
53             'H=s' => \$ssh,
54             'I=s' => \$files{selfid},
55             'N=s' => \$files{network},
56             'R=s' => \$files{router},
57             'S=s' => \$files{summary},
58 1 0       10 ) or usage("Bad option");
59 0 0         usage("Only one arguments allowed") if @ARGV > 1;
60              
61 0           my $cisco = OSPF::LSDB::Cisco->new(ssh => $ssh);
62 0           $cisco->parse(%files);
63              
64 0           my $yaml = OSPF::LSDB::YAML->new($cisco);
65 0 0         if (@ARGV > 0) {
66 0           $yaml->DumpFile($ARGV[0]);
67             } else {
68 0           print $yaml->Dump();
69             }
70             }
71              
72             main();