Info/CiscoPortSecurity.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 46 CC 2 SCAR 11.5
CC
2
Cov
0%
munge_pae_capabilities
6.0
i_err_disable_cause
2.0
BEGIN
2.0
CRAP 3.1
1 # SNMP::Info::CiscoPortSecurity
2 #
3 # Copyright (c) 2008 Eric Miller
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29  
30 package SNMP::Info::CiscoPortSecurity;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info;
36  
37 @SNMP::Info::CiscoPortSecurity::ISA = qw/SNMP::Info Exporter/;
38 @SNMP::Info::CiscoPortSecurity::EXPORT_OK = qw//;
39  
40 our ($VERSION, %MIBS, %FUNCS, %GLOBALS, %MUNGE, %PAECAPABILITIES);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (
45 'CISCO-PORT-SECURITY-MIB' => 'ciscoPortSecurityMIB',
46 'CISCO-PAE-MIB' => 'ciscoPaeMIB',
47 'IEEE8021-PAE-MIB' => 'dot1xAuthLastEapolFrameSource',
48 'CISCO-ERR-DISABLE-MIB' => 'ciscoErrDisableMIB',
49 );
50  
51 %GLOBALS = (
52  
53 # CISCO-PORT-SECURITY-MIB
54 'cps_clear' => 'cpsGlobalClearSecureMacAddresses',
55 'cps_notify' => 'cpsGlobalSNMPNotifControl',
56 'cps_rate' => 'cpsGlobalSNMPNotifRate',
57 'cps_enable' => 'cpsGlobalPortSecurityEnable',
58 'cps_mac_count' => 'cpsGlobalTotalSecureAddress',
59 'cps_mac_max' => 'cpsGlobalMaxSecureAddress',
60 );
61  
62 %FUNCS = (
63  
64 # CISCO-PORT-SECURITY-MIB::cpsIfConfigTable
65 'cps_i_limit_val' => 'cpsIfInvalidSrcRateLimitValue',
66 'cps_i_limit' => 'cpsIfInvalidSrcRateLimitEnable',
67 'cps_i_sticky' => 'cpsIfStickyEnable',
68 'cps_i_clear_type' => 'cpsIfClearSecureMacAddresses',
69 'cps_i_shutdown' => 'cpsIfShutdownTimeout',
70 'cps_i_flood' => 'cpsIfUnicastFloodingEnable',
71 'cps_i_clear' => 'cpsIfClearSecureAddresses',
72 'cps_i_mac' => 'cpsIfSecureLastMacAddress',
73 'cps_i_count' => 'cpsIfViolationCount',
74 'cps_i_action' => 'cpsIfViolationAction',
75 'cps_i_mac_static' => 'cpsIfStaticMacAddrAgingEnable',
76 'cps_i_mac_type' => 'cpsIfSecureMacAddrAgingType',
77 'cps_i_mac_age' => 'cpsIfSecureMacAddrAgingTime',
78 'cps_i_mac_count' => 'cpsIfCurrentSecureMacAddrCount',
79 'cps_i_mac_max' => 'cpsIfMaxSecureMacAddr',
80 'cps_i_status' => 'cpsIfPortSecurityStatus',
81 'cps_i_enable' => 'cpsIfPortSecurityEnable',
82  
83 # CISCO-PORT-SECURITY-MIB::cpsIfVlanTable
84 'cps_i_v_mac_count' => 'cpsIfVlanCurSecureMacAddrCount',
85 'cps_i_v_mac_max' => 'cpsIfVlanMaxSecureMacAddr',
86  
87 # CISCO-PORT-SECURITY-MIB::cpsIfVlanSecureMacAddrTable
88 'cps_i_v_mac_status' => 'cpsIfVlanSecureMacAddrRowStatus',
89 'cps_i_v_mac_age' => 'cpsIfVlanSecureMacAddrRemainAge',
90 'cps_i_v_mac_type' => 'cpsIfVlanSecureMacAddrType',
91  
92 # CISCO-PORT-SECURITY-MIB::cpsSecureMacAddressTable
93 'cps_m_status' => 'cpsSecureMacAddrRowStatus',
94 'cps_m_age' => 'cpsSecureMacAddrRemainingAge',
95 'cps_m_type' => 'cpsSecureMacAddrType',
96  
97 # IEEE8021-PAE-MIB::dot1xPaePortEntry
98 'pae_i_capabilities' => 'dot1xPaePortCapabilities',
99 'pae_i_last_eapol_frame_source' => 'dot1xAuthLastEapolFrameSource',
100  
101 # CISCO-ERR-DISABLE-MIB::cErrDisableIfStatusEntry
102 'cerr_i_cause' => 'cErrDisableIfStatusCause',
103 );
104  
105 %MUNGE = (
106 'cps_i_mac' => \&SNMP::Info::munge_mac,
107 'pae_i_last_eapol_frame_source' => \&SNMP::Info::munge_mac,
108 'pae_i_capabilities' => \&munge_pae_capabilities,
109 );
110  
111 %PAECAPABILITIES = (
112 0 => 'dot1xPaePortAuthCapable',
113 1 => 'dot1xPaePortSuppCapable',
114 );
115  
116 sub munge_pae_capabilities {
117 my $bits = shift;
118  
119 return unless defined $bits;
120 my @vals
121 = map( $PAECAPABILITIES{$_}, sprintf( "%x", unpack( 'b*', $bits ) ) );
122 return join( ' ', @vals );
123 }
124  
125 # Define a generic method to show the cause for a port to be err-disabled.
126 # Cisco indexes cErrDisableIfStatusCause by {ifindex,vlan}, but for a more
127 # generic method, using ifIndex only makes it easier to implement across
128 # device classes. Besides, several (most?) err-disable features will disable
129 # the whole interface anyway, and not just a vlan on the interface.
130 sub i_err_disable_cause {
131 my $cps = shift;
132 my $ret;
133 my $causes = $cps->cerr_i_cause() || {};
134 foreach my $interfacevlan (keys %$causes) {
135 my ($iid, $vid) = split(/\./, $interfacevlan);
136 $ret->{$iid} = $causes->{$interfacevlan};
137 }
138 return $ret;
139 }
140  
141 1;
142 __END__