Info/NortelStack.pm untested

filter: Statementstmt 0.0% 0 / 265 Branchbran 0.0% 0 / 106 Conditioncond 0.0% 0 / 108 MC/DCmcdc 0.0% 0 / 61 Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 19 totaltotal 0.0% 0 / 582 CC 54 SCAR 39.7
CC
54
Cov
0%
ns_e_pos
132.0
ns_e_parent
110.0
ns_e_name
90.0
CRAP 53.0
1 # SNMP::Info::NortelStack
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::NortelStack;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info;
36  
37 @SNMP::Info::NortelStack::ISA = qw/SNMP::Info Exporter/;
38 @SNMP::Info::NortelStack::EXPORT_OK = qw//;
39  
40 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (
45  
46 # S5-ROOT-MIB and S5-TCS-MIB required by the MIBs below
47 'S5-AGENT-MIB' => 's5AgMyGrpIndx',
48 'S5-CHASSIS-MIB' => 's5ChasType',
49 'S5-REG-MIB' => 's5ChasTypeVal',
50 );
51  
52 %GLOBALS = (
53  
54 # From S5-AGENT-MIB
55 'ns_ag_ver' => 's5AgInfoVer',
56 'ns_op_mode' => 's5AgSysCurrentOperationalMode',
57 'ns_auto_pvid' => 's5AgSysAutoPvid',
58 'tftp_host' => 's5AgSysTftpServerAddress',
59 'tftp_file' => 's5AgSysBinaryConfigFilename',
60 'tftp_action' => 's5AgInfoFileAction',
61 'tftp_result' => 's5AgInfoFileStatus',
62 'vlan' => 's5AgSysManagementVlanId',
63  
64 # From S5-CHASSIS-MIB
65 'ns_serial' => 's5ChasSerNum',
66 'ns_ch_type' => 's5ChasType',
67 'ns_cfg_chg' => 's5ChasGblConfChngs',
68 'ns_cfg_time' => 's5ChasGblConfLstChng',
69 );
70  
71 %FUNCS = (
72  
73 # From S5-AGENT-MIB::s5AgMyIfTable
74 'i_cfg_file' => 's5AgMyIfCfgFname',
75 'i_cfg_host' => 's5AgMyIfLdSvrAddr',
76  
77 # From S5-CHASSIS-MIB::s5ChasGrpTable
78 'ns_grp_type' => 's5ChasGrpType',
79  
80 # From S5-CHASSIS-MIB::s5ChasComTable
81 'ns_com_grp_idx' => 's5ChasComGrpIndx',
82 'ns_com_idx' => 's5ChasComIndx',
83 'ns_com_sub_idx' => 's5ChasComSubIndx',
84 'ns_com_type' => 's5ChasComType',
85 'ns_com_descr' => 's5ChasComDescr',
86 'ns_com_ver' => 's5ChasComVer',
87 'ns_com_serial' => 's5ChasComSerNum',
88  
89 # From S5-CHASSIS-MIB::s5ChasStoreTable
90 'ns_store_grp_idx' => 's5ChasStoreGrpIndx',
91 'ns_store_com_idx' => 's5ChasStoreComIndx',
92 'ns_store_sub_idx' => 's5ChasStoreSubIndx',
93 'ns_store_idx' => 's5ChasStoreIndx',
94 'ns_store_type' => 's5ChasStoreType',
95 'ns_store_size' => 's5ChasStoreCurSize',
96 'ns_store_ver' => 's5ChasStoreCntntVer',
97 );
98  
99 %MUNGE = (
100 'ns_ch_type' => \&SNMP::Info::munge_e_type,
101 'ns_grp_type' => \&munge_ns_grp_type,
102 'ns_com_type' => \&SNMP::Info::munge_e_type,
103 'ns_store_type' => \&SNMP::Info::munge_e_type,
104 );
105  
106 sub os_ver {
107 my $stack = shift;
108  
109 my $ver = $stack->ns_ag_ver();
110 return unless defined $ver;
111  
112 if ( $ver =~ m/(\d+\.\d+\.\d+\.\d+)/ ) {
113 return $1;
114 }
115 if ( $ver =~ m/V(\d+\.\d+\.\d+)/i ) {
116 return $1;
117 }
118 return;
119 }
120  
121 sub os_bin {
122 my $stack = shift;
123  
124 my $ver = $stack->ns_ag_ver();
125 return unless defined $ver;
126  
127 if ( $ver =~ m/(\d+\.\d+\.\d+\.\d+)/i ) {
128 return $1;
129 }
130 if ( $ver =~ m/V(\d+\.\d+.\d+)/i ) {
131 return $1;
132 }
133 return;
134 }
135  
136 # Need to override here since overridden in Layer2 and Layer3 classes
137 sub serial {
138 my $stack = shift;
139  
140 my $ver = $stack->ns_serial();
141 return $ver unless !defined $ver;
142  
143 return;
144 }
145  
146 # Pseudo ENTITY-MIB methods for older switches with don't support ENTITY-MIB
147  
148 # This class supports both stackable and chassis based switches, identify if
149 # we have a stackable so that we return appropriate entPhysicalClass
150 sub _ns_e_is_virtual {
151 my $stack = shift;
152  
153 # We really only need one value, but we want this cached since most
154 # methods call it at least via ns_e_index()
155 my $v_test = $stack->s5ChasComRelPos() || {};
156 return $v_test->{'8.1.0'};
157 }
158  
159 # Identify is the stackable is actually a stack vs. single switch
160 sub _ns_e_is_stack {
161 my $stack = shift;
162  
163 my $s_test = $stack->ns_e_class() || {};
164  
165 foreach my $iid ( keys %$s_test ) {
166 my $class = $s_test->{$iid};
167 next unless defined $class;
168 return 1 if ( $class eq 'stack' );
169 }
170 return 0;
171 }
172  
173 sub ns_e_index {
174 my $stack = shift;
175 my $partial = shift;
176  
177 my $ns_e_idx = $stack->ns_com_grp_idx($partial) || {};
178 my $is_virtual = $stack->_ns_e_is_virtual();
179  
180 my %ns_e_index;
181 foreach my $iid ( keys %$ns_e_idx ) {
182  
183 # Skip backplane, power, sensor, fan, clock - these aren't in the
184 # newer devices ENTITY-MIB we're emulating
185 next if ( $iid =~ /^[24567]/ );
186 next if ( ($is_virtual) and ( $iid =~ /^8/ or $iid eq '1.0.0' ) );
187  
188 # Format into consistent integer format so that numeric sorting works
189 my $index = join( '', map { sprintf "%02d", $_ } split /\./, $iid );
190 $ns_e_index{$iid} = $index;
191 }
192 return \%ns_e_index;
193 }
194  
195 sub ns_e_class {
196 my $stack = shift;
197 my $partial = shift;
198  
199 my $ns_e_idx = $stack->ns_e_index($partial) || {};
200 my $classes = $stack->ns_grp_type();
201 my $ns_grp_enc = $stack->s5ChasGrpEncodeFactor($partial) || {};
202 my $is_virtual = $stack->_ns_e_is_virtual();
203  
204 my %ns_e_class;
205 foreach my $iid ( keys %$ns_e_idx ) {
206 my ( $grp, $idx, $sub ) = split( /\./, $iid );
207 next unless defined $grp;
208 my $class = $classes->{$grp};
209 next unless defined $class;
210 my $enc = $ns_grp_enc->{$grp};
211  
212 # Handle quirks of dealing with both stacks and chassis
213 if ( ( !$is_virtual ) and ( $grp == 1 ) ) {
214 $class = 'module';
215 }
216 if ( ($is_virtual) and ( $grp == 3 ) and !( $idx % $enc ) ) {
217 $class = 'chassis';
218 }
219  
220 $ns_e_class{$iid} = $class;
221 }
222 return \%ns_e_class;
223 }
224  
225 sub ns_e_descr {
226 my $stack = shift;
227 my $partial = shift;
228  
229 my $ns_e_idx = $stack->ns_e_index($partial) || {};
230 my $ns_e_descr = $stack->ns_com_descr($partial) || {};
231  
232 my %ns_e_descr;
233 foreach my $iid ( keys %$ns_e_idx ) {
234 my $descr = $ns_e_descr->{$iid};
235 next unless defined $descr;
236  
237 $ns_e_descr{$iid} = $descr;
238 }
239 return \%ns_e_descr;
240 }
241  
242 sub ns_e_name {
243 my $stack = shift;
244 my $partial = shift;
245  
246 my $ns_class = $stack->ns_e_class() || {};
247 my $ns_e_idx = $stack->ns_e_index() || {};
248 my $ns_grp_enc = $stack->s5ChasGrpEncodeFactor($partial) || {};
249 my $is_virtual = $stack->_ns_e_is_virtual();
250  
251 my %ns_e_name;
252 foreach my $iid ( keys %$ns_e_idx ) {
253  
254 my ( $grp, $idx, $sub ) = split( /\./, $iid );
255 my $class = $ns_class->{$iid};
256 next unless defined $class;
257 my $enc = $ns_grp_enc->{$grp};
258  
259 if ( ( !$is_virtual ) and ( $grp == 1 ) ) {
260 $ns_e_name{$iid} = 'Supervisory Module';
261 }
262 elsif ( $class eq 'stack' ) {
263 $ns_e_name{$iid} = 'Stack Master Unit';
264 }
265 elsif ( $class eq 'chassis' ) {
266 if ($is_virtual) {
267 my $unit = $idx / $enc;
268 $ns_e_name{$iid} = "Switch Unit $unit";
269 }
270 else {
271 $ns_e_name{$iid} = "Chassis";
272 }
273 }
274 elsif ( $class eq 'module' ) {
275 if ($is_virtual) {
276 my $unit = int( $idx / $enc );
277 my $mda = $idx % $enc;
278 $ns_e_name{$iid} = "Switch Unit $unit, MDA $mda";
279 }
280 elsif ( $sub != 0 ) {
281 $ns_e_name{$iid} = "Module Slot $idx, Subcomponent $sub";
282 }
283 else {
284 $ns_e_name{$iid} = "Module Slot $idx";
285 }
286 }
287 }
288 return \%ns_e_name;
289 }
290  
291 sub ns_e_hwver {
292 my $stack = shift;
293 my $partial = shift;
294  
295 my $ns_e_idx = $stack->ns_e_index($partial) || {};
296 my $ns_e_ver = $stack->ns_com_ver($partial) || {};
297  
298 my %ns_e_hwver;
299 foreach my $iid ( keys %$ns_e_idx ) {
300 my $ver = $ns_e_ver->{$iid};
301 next unless defined $ver;
302  
303 $ns_e_hwver{$iid} = $ver;
304 }
305 return \%ns_e_hwver;
306 }
307  
308 sub ns_e_vendor {
309 my $stack = shift;
310 my $partial = shift;
311  
312 my $ns_e_idx = $stack->ns_e_index($partial) || {};
313  
314 my %ns_e_vendor;
315 foreach my $iid ( keys %$ns_e_idx ) {
316 my $vendor = 'avaya';
317  
318 $ns_e_vendor{$iid} = $vendor;
319 }
320 return \%ns_e_vendor;
321 }
322  
323 sub ns_e_serial {
324 my $stack = shift;
325 my $partial = shift;
326  
327 my $ns_e_idx = $stack->ns_e_index($partial) || {};
328 my $ns_e_serial = $stack->ns_com_serial($partial) || {};
329  
330 my %ns_e_serial;
331 foreach my $iid ( keys %$ns_e_idx ) {
332 my $serial = $ns_e_serial->{$iid};
333 next unless defined $serial;
334  
335 $ns_e_serial{$iid} = $serial;
336 }
337 return \%ns_e_serial;
338 }
339  
340 sub ns_e_type {
341 my $stack = shift;
342 my $partial = shift;
343  
344 my $ns_e_idx = $stack->ns_e_index($partial) || {};
345 my $ns_e_type = $stack->ns_com_type($partial) || {};
346 my $is_stack = $stack->_ns_e_is_stack();
347 my $ch_type = $stack->ns_ch_type();
348  
349 my %ns_e_type;
350 foreach my $iid ( keys %$ns_e_idx ) {
351 my $type = $ns_e_type->{$iid};
352 next unless defined $type;
353  
354 if ( $is_stack and $iid =~ /^1/ ) {
355 $type = $ch_type;
356 }
357 $ns_e_type{$iid} = $type;
358 }
359 return \%ns_e_type;
360 }
361  
362 sub ns_e_pos {
363 my $stack = shift;
364 my $partial = shift;
365  
366 my $ns_e_idx = $stack->ns_e_index($partial) || {};
367 my $ns_grp_enc = $stack->s5ChasGrpEncodeFactor($partial) || {};
368 my $is_stack = $stack->_ns_e_is_stack();
369 my $is_virtual = $stack->_ns_e_is_virtual();
370  
371 my %ns_e_pos;
372 foreach my $iid ( keys %$ns_e_idx ) {
373 my ( $grp, $pos, $idx ) = split( /\./, $iid );
374 next unless defined $grp;
375 next unless defined $pos;
376  
377 if ( $grp == 1 ) {
378 if ($is_stack) {
379 $pos = -1;
380 }
381 else {
382 $pos = 99;
383 }
384 }
385 elsif ( $grp == 3 and $idx == 0 ) {
386 my $enc = $ns_grp_enc->{$grp};
387 if ( $is_virtual and ( $pos % $enc ) ) {
388 $pos = int( $pos % $enc );
389 }
390 elsif ( $is_virtual and !$is_stack and !( $pos % $enc ) ) {
391 $pos = -1;
392 }
393 elsif ( $is_virtual and !( $pos % $enc ) ) {
394 $pos = ( $pos / $enc );
395 }
396 }
397 elsif ( !$is_stack and $grp == 3 ) {
398 $pos = $idx;
399 }
400 elsif ( $grp == 8 ) {
401 $pos = -1;
402 }
403 $ns_e_pos{$iid} = $pos;
404 }
405 return \%ns_e_pos;
406 }
407  
408 # Storage area types, most preferred first. A unit has several matching
409 # areas (S5-REG-MIB), so take the best ranked rather than the last walked.
410 # OperSW is the running software; Flash, the image it boots, can carry
411 # trailing padding. PoLFlash is the PoE controller's image, not the switch
412 # software
413 my @_ns_sw_stores
414 = ( qr/StoreOperSW$/, qr/StoreFlash$/, qr/StoreSecondaryFlash$/,
415 qr/(?<!PoL)flash/i );
416 my @_ns_fw_stores = ( qr/StoreBootFW$/, qr/StoreInstalledFW$/,
417 qr/StoreBootLoader$/, qr/(rom|boot|fw)/i );
418  
419 sub _ns_e_store_ver {
420 my ( $stack, $partial, @ranked ) = @_;
421  
422 my $ns_e_ver = $stack->ns_store_ver($partial) || {};
423 my $ns_e_type = $stack->ns_store_type($partial) || {};
424 my $ns_grp_enc = $stack->s5ChasGrpEncodeFactor($partial) || {};
425 my $is_virt = $stack->_ns_e_is_virtual();
426  
427 my ( %store_ver, %store_rank );
428 foreach my $iid ( keys %$ns_e_type ) {
429 my $type = $ns_e_type->{$iid};
430 my $ver = $ns_e_ver->{$iid};
431 next unless defined $type and defined $ver and length $ver;
432 my ($rank) = grep { $type =~ $ranked[$_] } 0 .. $#ranked;
433 next unless defined $rank;
434  
435 my ( $unit, $area ) = $iid =~ /^(.+)\.(\d+)$/;
436 if ($is_virt) {
437 my ( $grp, $idx, $pos ) = split( /\./, $unit );
438 my $enc = $ns_grp_enc->{$grp};
439 $idx = $idx * $enc;
440 $unit = "3.$idx.$pos";
441 }
442 my $best = $store_rank{$unit};
443 next if $best and ( $best->[0] < $rank
444 or ( $best->[0] == $rank and $best->[1] < $area ) );
445  
446 $store_rank{$unit} = [ $rank, $area ];
447 $store_ver{$unit} = $ver;
448 }
449 return \%store_ver;
450 }
451  
452 sub ns_e_fwver {
453 my $stack = shift;
454 my $partial = shift;
455  
456 return $stack->_ns_e_store_ver( $partial, @_ns_fw_stores );
457 }
458  
459 sub ns_e_swver {
460 my $stack = shift;
461 my $partial = shift;
462  
463 return $stack->_ns_e_store_ver( $partial, @_ns_sw_stores );
464 }
465  
466 sub ns_e_parent {
467 my $stack = shift;
468 my $partial = shift;
469  
470 my $ns_e_idx = $stack->ns_e_index($partial) || {};
471 my $ns_grp_enc = $stack->s5ChasGrpEncodeFactor($partial) || {};
472 my $is_stack = $stack->_ns_e_is_stack();
473 my $is_virtual = $stack->_ns_e_is_virtual();
474  
475 my %ns_e_parent;
476 foreach my $iid ( keys %$ns_e_idx ) {
477 my $index = $ns_e_idx->{$iid};
478 my ( $grp, $idx, $pos ) = split( /\./, $iid );
479 next unless defined $grp;
480 if ( $grp == 8 ) {
481 $ns_e_parent{$iid} = '0';
482 }
483 if ( $grp == 1 ) {
484 if ($is_stack) {
485 $ns_e_parent{$iid} = '0';
486 }
487 else {
488 $ns_e_parent{$iid} = '080100';
489 }
490 }
491 if ( $grp == 3 ) {
492 my $enc = $ns_grp_enc->{$grp};
493 if ( $idx % $enc ) {
494 my $npos = ( $idx % $enc ) * $enc;
495 my @parent = ( $grp, $npos, $pos );
496 my $parent = join( '', map { sprintf "%02d", $_ } @parent );
497 $ns_e_parent{$iid} = $parent;
498 }
499 elsif ($is_stack) {
500 $ns_e_parent{$iid} = '010100';
501 }
502 elsif ( $is_virtual and !$is_stack ) {
503 $ns_e_parent{$iid} = 0;
504 }
505 elsif ( $pos == 0 ) {
506 $ns_e_parent{$iid} = '080100';
507 }
508 else {
509 my $parent = $iid;
510 $parent =~ s/\.\d+$/\.00/;
511 $parent = join( '', map { sprintf "%02d", $_ } split /\./,
512 $parent );
513 $ns_e_parent{$iid} = $parent;
514 }
515 }
516 next;
517 }
518 return \%ns_e_parent;
519 }
520  
521 sub munge_ns_grp_type {
522 my $oid = shift;
523  
524 my %e_class = (
525 Sup => 'stack',
526 Bkpl => 'backplane',
527 Brd => 'module',
528 Pwr => 'powerSupply',
529 TmpSnr => 'sensor',
530 Fan => 'fan',
531 Clk => 'other',
532 Unit => 'chassis',
533 );
534  
535 my $name = &SNMP::translateObj($oid);
536 $name =~ s/s5ChasGrp//;
537 if ( ( defined($name) ) and ( exists( $e_class{$name} ) ) ) {
538 $name = $e_class{$name};
539 }
540 return $name if defined($name);
541 return $oid;
542 }
543  
544 1;
545  
546 __END__