Info/Layer3/AlteonAD.pm untested

filter: Statementstmt 0.0% 0 / 178 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 105 MC/DCmcdc 0.0% 0 / 56 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 443 CC 35 SCAR 30.6
CC
35
Cov
0%
i_duplex_admin
42.0
ps1_status
30.0
ps2_status
30.0
CRAP 21.3
1 # SNMP::Info::Layer3::AlteonAD
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::Layer3::AlteonAD;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer3;
36  
37 @SNMP::Info::Layer3::AlteonAD::ISA = qw/SNMP::Info::Layer3 Exporter/;
38 @SNMP::Info::Layer3::AlteonAD::EXPORT_OK = qw//;
39  
40 our ($VERSION, %GLOBALS, %FUNCS, %MIBS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (
45 %SNMP::Info::Layer3::MIBS,
46 'ALTEON-ROOT-MIB' => 'aceswitch184',
47 'ALTEON-TIGON-SWITCH-MIB' => 'hwPowerSupplyStatus',
48 'ALTEON-CHEETAH-SWITCH-MIB' => 'hwFanStatus',
49 'ALTEON-TS-PHYSICAL-MIB' => 'agPortTableMaxEnt',
50 'ALTEON-CS-PHYSICAL-MIB' => 'vlanCurCfgLearn',
51 'ALTEON-TS-NETWORK-MIB' => 'ripCurCfgSupply',
52 'ALTEON-CHEETAH-NETWORK-MIB' => 'ripCurCfgIntfSupply',
53 );
54  
55 %GLOBALS = (
56 %SNMP::Info::Layer3::GLOBALS,
57 'old_sw_ver' => 'ALTEON_TIGON_SWITCH_MIB__agSoftwareVersion',
58 'new_sw_ver' => 'ALTEON_CHEETAH_SWITCH_MIB__agSoftwareVersion',
59 'old_tftp_action' => 'ALTEON_TIGON_SWITCH_MIB__agTftpAction',
60 'new_tftp_action' => 'ALTEON_CHEETAH_SWITCH_MIB__agTftpAction',
61 'old_tftp_host' => 'ALTEON_TIGON_SWITCH_MIB__agTftpServer',
62 'new_tftp_host' => 'ALTEON_CHEETAH_SWITCH_MIB__agTftpServer',
63 'old_tftp_file' => 'ALTEON_TIGON_SWITCH_MIB__agTftpCfgFileName',
64 'new_tftp_file' => 'ALTEON_CHEETAH_SWITCH_MIB__agTftpCfgFileName',
65 'old_tftp_result' => 'ALTEON_TIGON_SWITCH_MIB__agTftpLastActionStatus',
66 'new_tftp_result' => 'ALTEON_CHEETAH_SWITCH_MIB__agTftpLastActionStatus',
67 'old_ip_max' => 'ALTEON_TS_NETWORK_MIB__ipInterfaceTableMax',
68 'new_ip_max' => 'ALTEON_CHEETAH_NETWORK_MIB__ipInterfaceTableMax',
69 'fan' => 'ALTEON_CHEETAH_SWITCH_MIB__hwFanStatus',
70 'old_ps1_stat' => 'ALTEON_TIGON_SWITCH_MIB__hwPowerSupplyStatus',
71 'old_ps2_stat' => 'ALTEON_TIGON_SWITCH_MIB__hwRedundantPSStatus',
72 'new_ps_stat' => 'ALTEON_CHEETAH_SWITCH_MIB__hwPowerSupplyStatus',
73 );
74  
75 %FUNCS = (
76 %SNMP::Info::Layer3::FUNCS,
77  
78 # From agPortCurCfgTable
79 'old_ag_p_cfg_idx' => 'ALTEON_TS_PHYSICAL_MIB__agPortCurCfgIndx',
80 'new_ag_p_cfg_idx' => 'ALTEON_CHEETAH_SWITCH_MIB__agPortCurCfgIndx',
81 'old_ag_p_cfg_pref' => 'agPortCurCfgPrefLink',
82 'new_ag_p_cfg_pref' => 'agPortCurCfgPreferred',
83 'old_ag_p_cfg_pvid' => 'ALTEON_TS_PHYSICAL_MIB__agPortCurCfgPVID',
84 'new_ag_p_cfg_pvid' => 'ALTEON_CHEETAH_SWITCH_MIB__agPortCurCfgPVID',
85 'old_ag_p_cfg_fe_auto' =>
86 'ALTEON_TS_PHYSICAL_MIB__agPortCurCfgFastEthAutoNeg',
87 'new_ag_p_cfg_fe_auto' =>
88 'ALTEON_CHEETAH_SWITCH_MIB__agPortCurCfgFastEthAutoNeg',
89 'old_ag_p_cfg_fe_mode' =>
90 'ALTEON_TS_PHYSICAL_MIB__agPortCurCfgFastEthMode',
91 'new_ag_p_cfg_fe_mode' =>
92 'ALTEON_CHEETAH_SWITCH_MIB__agPortCurCfgFastEthMode',
93 'old_ag_p_cfg_ge_auto' =>
94 'ALTEON_TS_PHYSICAL_MIB__agPortCurCfgGigEthAutoNeg',
95 'new_ag_p_cfg_ge_auto' =>
96 'ALTEON_CHEETAH_SWITCH_MIB__agPortCurCfgGigEthAutoNeg',
97 'old_ag_p_cfg_name' => 'ALTEON_TS_PHYSICAL_MIB__agPortCurCfgPortName',
98 'new_ag_p_cfg_name' => 'ALTEON_CHEETAH_SWITCH_MIB__agPortCurCfgPortName',
99  
100 # From portInfoTable
101 'old_p_info_idx' => 'ALTEON_TS_PHYSICAL_MIB__portInfoIndx',
102 'new_p_info_idx' => 'ALTEON_CHEETAH_SWITCH_MIB__portInfoIndx',
103 'old_p_info_mode' => 'ALTEON_TS_PHYSICAL_MIB__portInfoMode',
104 'new_p_info_mode' => 'ALTEON_CHEETAH_SWITCH_MIB__portInfoMode',
105  
106 # From ipCurCfgIntfTable
107 'old_ip_cfg_vlan' => 'ALTEON_TS_NETWORK_MIB__ipCurCfgIntfVlan',
108 'new_ip_cfg_vlan' => 'ALTEON_CHEETAH_NETWORK_MIB__ipCurCfgIntfVlan',
109  
110 # From vlanCurCfgTable
111 'old_vlan_id' => 'ALTEON_TS_PHYSICAL_MIB__vlanCurCfgVlanId',
112 'new_vlan_id' => 'ALTEON_CS_PHYSICAL_MIB__vlanCurCfgVlanId',
113 'old_vlan_state' => 'ALTEON_TS_PHYSICAL_MIB__vlanCurCfgState',
114 'new_vlan_state' => 'ALTEON_CS_PHYSICAL_MIB__vlanCurCfgState',
115 'old_vlan_name' => 'ALTEON_TS_PHYSICAL_MIB__vlanCurCfgVlanName',
116 'new_vlan_name' => 'ALTEON_CS_PHYSICAL_MIB__vlanCurCfgVlanName',
117 'old_vlan_ports' => 'ALTEON_TS_PHYSICAL_MIB__vlanCurCfgPorts',
118 'new_vlan_ports' => 'ALTEON_CS_PHYSICAL_MIB__vlanCurCfgPorts',
119 );
120  
121 %MUNGE = ( %SNMP::Info::Layer3::MUNGE, );
122  
123 sub model {
124 my $alteon = shift;
125  
126 my $id = $alteon->id();
127  
128 unless ( defined $id ) {
129 print
130 " SNMP::Info::Layer3::AlteonAD::model() - Device does not support sysObjectID\n"
131 if $alteon->debug();
132 return;
133 }
134  
135 my $model = &SNMP::translateObj($id);
136  
137 return $id unless defined $model;
138  
139 $model =~ s/^(aceswitch|aws|ods)//;
140 $model =~ s/^acedirector/AD/;
141 $model =~ s/^(copper|fiber)Module/BladeCenter GbESM/;
142  
143 return $model;
144 }
145  
146 sub vendor {
147 return 'radware';
148 }
149  
150 sub os {
151 return 'alteon';
152 }
153  
154 sub os_ver {
155 my $alteon = shift;
156 my $version = $alteon->new_sw_ver() || $alteon->old_sw_ver();
157 return unless defined $version;
158  
159 return $version;
160 }
161  
162 sub ps1_status {
163 my $alteon = shift;
164 my $old_ps = $alteon->old_ps1_stat();
165 my $new_ps = $alteon->new_ps_stat();
166  
167 return $old_ps if $old_ps;
168  
169 if ($new_ps) {
170 return 'ok' if ($new_ps eq 'singlePowerSupplyOk');
171 return 'failed' if ($new_ps eq 'firstPowerSupplyFailed');
172 }
173  
174 return;
175 }
176  
177 sub ps2_status {
178 my $alteon = shift;
179 my $old_ps = $alteon->old_ps2_stat();
180 my $new_ps = $alteon->new_ps_stat();
181  
182 return $old_ps if $old_ps;
183  
184 if ($new_ps) {
185 return 'ok' if ($new_ps eq 'doublePowerSupplyOk');
186 return 'failed' if ($new_ps eq 'secondPowerSupplyFailed');
187 }
188  
189 return;
190 }
191  
192 sub interfaces {
193 my $alteon = shift;
194 my $interfaces = $alteon->i_index();
195 my $descriptions = $alteon->i_description();
196 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
197  
198 my %interfaces = ();
199 foreach my $iid ( keys %$interfaces ) {
200 my $desc = $descriptions->{$iid};
201 next unless defined $desc;
202  
203 if ( $desc =~ /(^net\d+)/ ) {
204 $desc = $1;
205 }
206  
207 # IP interfaces are first followed by physical, number possible
208 # varies by switch model
209 elsif ( defined $ip_max and $iid > $ip_max ) {
210 $desc = ( $iid % $ip_max );
211 $desc = 'mgmt' if $desc == 231;
212 }
213 $interfaces{$iid} = $desc;
214 }
215 return \%interfaces;
216 }
217  
218 sub i_duplex {
219 my $alteon = shift;
220  
221 my $p_mode = $alteon->new_p_info_mode()
222 || $alteon->old_p_info_mode()
223 || {};
224 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
225  
226 my %i_duplex;
227 foreach my $if ( keys %$p_mode ) {
228 my $duplex = $p_mode->{$if};
229 next unless defined $duplex;
230  
231 $duplex = 'half' if $duplex =~ /half/i;
232 $duplex = 'full' if $duplex =~ /full/i;
233  
234 my $idx;
235 $idx = $if + $ip_max if ( defined $ip_max );
236  
237 $i_duplex{$idx} = $duplex;
238 }
239 return \%i_duplex;
240 }
241  
242 sub i_duplex_admin {
243 my $alteon = shift;
244  
245 my $ag_pref
246 = $alteon->new_ag_p_cfg_pref()
247 || $alteon->old_ag_p_cfg_pref()
248 || {};
249 my $ag_fe_auto
250 = $alteon->new_ag_p_cfg_fe_auto()
251 || $alteon->old_ag_p_cfg_fe_auto()
252 || {};
253 my $ag_fe_mode
254 = $alteon->new_ag_p_cfg_fe_mode()
255 || $alteon->old_ag_p_cfg_fe_mode()
256 || {};
257 my $ag_ge_auto
258 = $alteon->new_ag_p_cfg_ge_auto()
259 || $alteon->old_ag_p_cfg_ge_auto()
260 || {};
261 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
262 my $i_speed = $alteon->i_speed() || {};
263  
264 my %i_duplex_admin;
265 foreach my $if ( keys %$ag_ge_auto ) {
266 my $pref = $ag_pref->{$if} || '';
267 my $speed = $i_speed->{$if} || '';
268 my $ge_auto = $ag_ge_auto->{$if} || '';
269 my $fe_auto = $ag_fe_auto->{$if} || '';
270 my $fe_mode = $ag_fe_mode->{$if} || '';
271  
272 # Default to auto
273 my $string = 'auto';
274  
275 if ( $ge_auto =~ /off/i
276 && ( $pref =~ /gigabit/i || $speed eq '1.0 Gbps' ) )
277 {
278 $string = 'full';
279 }
280 if ( $fe_auto =~ /off/i
281 && ( $pref =~ /fast/i || $speed =~ /100?\sMbps/ ) )
282 {
283 $string = 'half'
284 if ( $fe_mode =~ /half/i );
285 $string = 'full'
286 if ( $fe_mode =~ /full/i );
287 }
288  
289 my $idx;
290 $idx = $if + $ip_max if ( defined $ip_max );
291  
292 $i_duplex_admin{$idx} = $string;
293 }
294 return \%i_duplex_admin;
295 }
296  
297 sub i_name {
298 my $alteon = shift;
299  
300 my $p_name = $alteon->new_ag_p_cfg_name()
301 || $alteon->old_ag_p_cfg_name()
302 || {};
303 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
304  
305 my %i_name;
306 foreach my $iid ( keys %$p_name ) {
307 my $name = $p_name->{$iid};
308 next unless defined $name;
309 my $idx;
310 $idx = $iid + $ip_max if ( defined $ip_max );
311 $i_name{$idx} = $name;
312 }
313 return \%i_name;
314 }
315  
316 sub v_index {
317 my $alteon = shift;
318 my $partial = shift;
319  
320 return $alteon->new_vlan_id($partial) || $alteon->old_vlan_id($partial);
321 }
322  
323 sub v_name {
324 my $alteon = shift;
325 my $partial = shift;
326  
327 return $alteon->new_vlan_name($partial)
328 || $alteon->old_vlan_name($partial);
329 }
330  
331 sub i_vlan {
332 my $alteon = shift;
333  
334 my $ag_vlans = $alteon->new_ag_p_cfg_pvid()
335 || $alteon->old_ag_p_cfg_pvid()
336 || {};
337 my $ip_vlans = $alteon->new_ip_cfg_vlan()
338 || $alteon->old_ip_cfg_vlan()
339 || {};
340 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
341  
342 my %i_vlan;
343 foreach my $if ( keys %$ip_vlans ) {
344 my $ip_vlanid = $ip_vlans->{$if};
345 next unless defined $ip_vlanid;
346  
347 $i_vlan{$if} = $ip_vlanid;
348 }
349 foreach my $if ( keys %$ag_vlans ) {
350 my $ag_vlanid = $ag_vlans->{$if};
351 next unless defined $ag_vlanid;
352  
353 my $idx;
354 $idx = $if + $ip_max if ( defined $ip_max );
355 $i_vlan{$idx} = $ag_vlanid;
356 }
357 return \%i_vlan;
358 }
359  
360 sub i_vlan_membership {
361 my $alteon = shift;
362  
363 my $v_ports = $alteon->old_vlan_ports()
364 || $alteon->new_vlan_ports()
365 || {};
366 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
367  
368 my $i_vlan_membership = {};
369 foreach my $vlan ( keys %$v_ports ) {
370 my $portlist = [ split( //, unpack( "B*", $v_ports->{$vlan} ) ) ];
371 my $ret = [];
372  
373 # Convert portlist bit array to ifIndex array
374 for ( my $i = 0; $i <= scalar(@$portlist); $i++ ) {
375 my $idx;
376 $idx = $i + $ip_max if ( defined $ip_max );
377 push( @{$ret}, $idx ) if ( @$portlist[$i] );
378 }
379  
380 #Create HoA ifIndex -> VLAN array
381 foreach my $port ( @{$ret} ) {
382 push( @{ $i_vlan_membership->{$port} }, $vlan );
383 }
384 }
385 return $i_vlan_membership;
386 }
387  
388 sub i_vlan_membership_untagged {
389 my $alteon = shift;
390 my $partial = shift;
391  
392 my $vlans = $alteon->i_vlan($partial);
393 my $i_vlan_membership = {};
394 foreach my $port (keys %$vlans) {
395 my $vlan = $vlans->{$port};
396 push( @{ $i_vlan_membership->{$port} }, $vlan );
397 }
398  
399 return $i_vlan_membership;
400 }
401  
402 # Bridge MIB does not map Bridge Port to ifIndex correctly on some code
403 # versions
404 sub bp_index {
405 my $alteon = shift;
406  
407 my $b_index = $alteon->orig_bp_index();
408 my $ip_max = $alteon->new_ip_max() || $alteon->old_ip_max();
409  
410 my %bp_index;
411 foreach my $iid ( keys %$b_index ) {
412 my $port = $b_index->{$iid};
413 next unless defined $port;
414 $port = $port + $ip_max if ( defined $ip_max and $iid == $ip_max );
415  
416 $bp_index{$iid} = $port;
417 }
418 return \%bp_index;
419 }
420  
421 1;
422 __END__