Info/Layer3/C6500.pm untested

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 196 CC 17 SCAR 29.5
CC
17
Cov
0%
i_duplex_admin
42.0
i_duplex
30.0
set_i_duplex_admin
20.0
CRAP 19.2
1 # SNMP::Info::Layer3::C6500
2 #
3 # Copyright (c) 2008-2009 Max Baker
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::Layer3::C6500;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::CiscoStack;
36 use SNMP::Info::Layer3::CiscoSwitch;
37 use SNMP::Info::MAU;
38  
39 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
40  
41 # NOTE : Top-most items gets precedence for @ISA
42 @SNMP::Info::Layer3::C6500::ISA = qw/
43 SNMP::Info::CiscoStack
44 SNMP::Info::Layer3::CiscoSwitch
45 SNMP::Info::MAU
46 Exporter
47 /;
48  
49 @SNMP::Info::Layer3::C6500::EXPORT_OK = qw//;
50  
51 $VERSION = '3.985003';
52  
53 # NOTE: Order creates precedence
54 # Example: v_name exists in Bridge.pm and CiscoVTP.pm
55 # Bridge is called from Layer3 and CiscoStpExtensions
56 # So we want CiscoVTP to come last to get the right one.
57 # The @ISA order should match these orders.
58  
59 %MIBS = (
60 %SNMP::Info::MAU::MIBS,
61 %SNMP::Info::Layer3::CiscoSwitch::MIBS,
62 %SNMP::Info::CiscoStack::MIBS,
63 'CISCO-VIRTUAL-SWITCH-MIB' => 'cvsSwitchMode',
64 );
65  
66 %GLOBALS = (
67 %SNMP::Info::MAU::GLOBALS,
68 %SNMP::Info::Layer3::CiscoSwitch::GLOBALS,
69 %SNMP::Info::CiscoStack::GLOBALS,
70 );
71  
72 %FUNCS = (
73 %SNMP::Info::MAU::FUNCS,
74 %SNMP::Info::Layer3::CiscoSwitch::FUNCS,
75 %SNMP::Info::CiscoStack::FUNCS,
76 );
77  
78 %MUNGE = (
79 %SNMP::Info::MAU::MUNGE,
80 %SNMP::Info::Layer3::CiscoSwitch::MUNGE,
81 %SNMP::Info::CiscoStack::MUNGE,
82 );
83  
84 sub vendor {
85 return 'cisco';
86 }
87  
88 sub serial {
89 my $c6500 = shift;
90  
91 my $serial = $c6500->SUPER::serial();
92 return $serial if defined $serial and $serial;
93  
94 # now grab the table only if SUPER cannot find it
95 my $e_serial = $c6500->e_serial();
96  
97 # Find entity table entry for this unit
98 foreach my $e ( sort keys %$e_serial ) {
99 if (defined $e_serial->{$e} and $e_serial->{$e} !~ /^\s*$/) {
100 return $e_serial->{$e};
101 }
102 }
103 }
104  
105 # Newer versions use the ETHERLIKE-MIB to report operational duplex.
106  
107 sub i_duplex {
108 my $c6500 = shift;
109 my $partial = shift;
110  
111 my $el_duplex = $c6500->el_duplex($partial);
112  
113 # Newer software
114 if ( defined $el_duplex and scalar( keys %$el_duplex ) ) {
115 my %i_duplex;
116 foreach my $el_port ( keys %$el_duplex ) {
117 my $duplex = $el_duplex->{$el_port};
118 next unless defined $duplex;
119  
120 $i_duplex{$el_port} = 'half' if $duplex =~ /half/i;
121 $i_duplex{$el_port} = 'full' if $duplex =~ /full/i;
122 }
123 return \%i_duplex;
124 }
125  
126 # Fall back to CiscoStack method
127 else {
128 return $c6500->SUPER::i_duplex($partial);
129 }
130 }
131  
132 # Newer software uses portDuplex as admin setting
133  
134 sub i_duplex_admin {
135 my $c6500 = shift;
136 my $partial = shift;
137  
138 my $el_duplex = $c6500->el_duplex($partial);
139  
140 # Newer software
141 if ( defined $el_duplex and scalar( keys %$el_duplex ) ) {
142  
143 # Some IOS releases (Sup2T) publish MAU-MIB, which holds the
144 # configured setting
145 my $mau_admin = $c6500->mau_i_duplex_admin($partial);
146 return $mau_admin if $mau_admin and scalar( keys %$mau_admin );
147  
148 my $p_port = $c6500->p_port() || {};
149 my $p_duplex = $c6500->p_duplex() || {};
150 my $p_speed = $c6500->p_speed() || {};
151  
152 my $i_duplex_admin = {};
153 foreach my $port ( keys %$p_duplex ) {
154 my $iid = $p_port->{$port};
155 next unless defined $iid;
156 next if ( defined $partial and $iid !~ /^$partial$/ );
157  
158 # portDuplex is the negotiated duplex on a connected port, so a
159 # port with auto speed is configured for auto duplex
160 my $speed = $p_speed->{$port};
161 $i_duplex_admin->{$iid}
162 = ( defined $speed and $speed =~ /auto/ )
163 ? 'auto'
164 : $p_duplex->{$port};
165 }
166 return $i_duplex_admin;
167 }
168  
169 # Fall back to CiscoStack method
170 else {
171 return $c6500->SUPER::i_duplex_admin($partial);
172 }
173 }
174  
175 sub is_virtual_switch {
176 my $cvs = shift;
177 my $cvsSwM = $cvs->cvsSwitchMode() || '';
178  
179 if ( $cvsSwM eq 'multiNode' ) {
180 return 1;
181 }
182 return 0;
183 }
184  
185 sub set_i_duplex_admin {
186  
187 # map a textual duplex to an integer one the switch understands
188 my %duplexes = qw/half 1 full 2 auto 4/;
189  
190 my $c6500 = shift;
191 my ( $duplex, $iid ) = @_;
192  
193 if ( $c6500->is_virtual_switch() ) {
194  
195 # VSS -> MAU
196 # Due to VSS bug
197 # 1. Set the ifMauDefaultType
198 # 2. Disable ifMauAutoNegAdminStatus
199 # If the second set is not done, this is not going to be
200 # working... Cisco Bug id CSCty97033.
201 # SXI is not working (up to at least release SXI9).
202 # SXJ is working at SXJ3 (not before).
203  
204 return $c6500->mau_set_i_duplex_admin( $duplex, $iid );
205 }
206  
207 my $el_duplex = $c6500->el_duplex($iid);
208  
209 # Auto duplex only supported on newer software
210 if ( defined $el_duplex and scalar( keys %$el_duplex ) ) {
211 my $p_port = $c6500->p_port() || {};
212 my %reverse_p_port = reverse %$p_port;
213  
214 $duplex = lc($duplex);
215  
216 return 0 unless defined $duplexes{$duplex};
217  
218 $iid = $reverse_p_port{$iid};
219  
220 return $c6500->set_p_duplex( $duplexes{$duplex}, $iid );
221 }
222 else {
223 return $c6500->SUPER::set_i_duplex_admin( $duplex, $iid );
224 }
225 }
226  
227 sub set_i_speed_admin {
228 my $c6500 = shift;
229 my ( $speed, $iid ) = @_;
230  
231 if ( $c6500->is_virtual_switch() ) {
232  
233 # VSS -> MAU
234 # Due to VSS bug
235 # 1. Set the ifMauDefaultType
236 # 2. Disable ifMauAutoNegAdminStatus
237 # If the second set is not done, this is not going to be working...
238 # Cisco Bug id CSCty97033.
239 # SXI is not working (at least up to release SXI9).
240 # SXJ is working at SXJ3 (not before).
241  
242 return $c6500->mau_set_i_speed_admin( $speed, $iid );
243 }
244 else {
245  
246 # normal behavior using the CiscoStack method
247 return $c6500->SUPER::set_i_speed_admin( $speed, $iid );
248 }
249 }
250  
251 1;
252 __END__