Info/FDP.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 74 CC 6 SCAR 20.4
CC
6
Cov
0%
hasFDP
12.0
fdp_if
12.0
fdp_run
6.0
CRAP 7.7
1 # SNMP::Info::FDP
2 #
3 # Copyright (c) 2008 Bruce Rodger, Max Baker
4 # All rights reserved.
5 #
6 # Copyright (c) 2002,2003 Regents of the University of California
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # * Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # * Neither the name of the University of California, Santa Cruz nor the
18 # names of its contributors may be used to endorse or promote products
19 # derived from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32  
33 package SNMP::Info::FDP;
34  
35 use strict;
36 use warnings;
37 use Exporter;
38 use SNMP::Info;
39  
40 @SNMP::Info::FDP::ISA = qw/SNMP::Info Exporter/;
41 @SNMP::Info::FDP::EXPORT_OK = qw//;
42  
43 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
44  
45 $VERSION = '3.985003';
46  
47 %MIBS = ( 'FOUNDRY-SN-SWITCH-GROUP-MIB' => 'snFdpGlobalRun' );
48  
49 %GLOBALS = (
50 'fdp_run' => 'snFdpGlobalRun',
51 'fdp_interval' => 'snFdpGlobalMessageInterval',
52 'fdp_holdtime' => 'snFdpGlobalHoldTime',
53 );
54  
55 %FUNCS = (
56 'fdp_proto' => 'snFdpCacheAddressType',
57 'fdp_ip' => 'snFdpCacheAddress',
58 'fdp_ver' => 'snFdpCacheVersion',
59 'fdp_id' => 'snFdpCacheDeviceId',
60 'fdp_port' => 'snFdpCacheDevicePort',
61 'fdp_platform' => 'snFdpCachePlatform',
62 'fdp_capabilities' => 'snFdpCacheCapabilities',
63 'fdp_cache_type' => 'snFdpCacheVendorId',
64 );
65  
66 %MUNGE = (
67 'fdp_capabilities' => \&SNMP::Info::munge_bits,
68 'fdp_ip' => \&SNMP::Info::munge_ip,
69 );
70  
71 sub fdp_run {
72 my $fdp = shift;
73 my $fdp_run = $fdp->orig_fdp_run();
74  
75 # if fdp_run isn't implemented on device, assume FDP is on
76 return $fdp_run if defined $fdp_run;
77 return 1;
78 }
79  
80 sub hasFDP {
81 my $fdp = shift;
82  
83 my $ver = $fdp->snmp_ver();
84  
85 # SNMP v1 clients dont have the globals
86 if ( defined $ver and $ver == 1 ) {
87 my $fdp_ip = $fdp->fdp_ip();
88  
89 # See if anything in fdp cache, if so we have fdp
90 return 1 if ( defined $fdp_ip and scalar( keys %$fdp_ip ) );
91 return;
92 }
93  
94 return $fdp->fdp_run();
95 }
96  
97 sub fdp_if {
98 my $fdp = shift;
99  
100 my $fdp_ip = $fdp->fdp_ip();
101 unless ( defined $fdp_ip ) {
102 $fdp->error_throw(
103 "SNMP::Info::FDP:fdp_if() - Device doesn't have fdp_ip() data. Can't fake fdp_index()"
104 );
105 return;
106 }
107  
108 my %fdp_if;
109 foreach my $key ( keys %$fdp_ip ) {
110 next unless defined $key;
111 my $iid = $key;
112  
113 # Truncate .1 from fdp cache entry
114 $iid =~ s/\.\d+$//;
115 $fdp_if{$key} = $iid;
116 }
117  
118 return \%fdp_if;
119 }
120  
121 1;
122 __END__