Info/Layer3/AlcatelLucent.pm untested

filter: Statementstmt 0.0% 0 / 189 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 0.0% 0 / 32 Podpod 0.0% 0 / 25 totaltotal 0.0% 0 / 346 CC 28 SCAR 33.0
CC
28
Cov
0%
_alu8_vpa_walk
90.0
i_vlan
56.0
alu8_vpa_type
42.0
CRAP 27.2
1 # SNMP::Info::Layer3::AlcatelLucent
2 #
3 # Copyright (c) 2008 Bill Fenner
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the University of California, Santa Cruz nor the
14 # names of its contributors may be used to endorse or promote products
15 # derived from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28  
29 package SNMP::Info::Layer3::AlcatelLucent;
30  
31 use strict;
32 use warnings;
33  
34 use Exporter;
35 use SNMP::Info::Layer3;
36 use SNMP::Info::MAU;
37 use SNMP::Info::AMAP;
38 # Use LLDP
39 # (or at least try. The versions I've seen have two problems:
40 # 1. they report ifIndex values as 'local'; we don't support ifIndex
41 # but *could*
42 # 2. They report 0.0.0.0 as the management address
43 # )
44 use SNMP::Info::LLDP;
45  
46 @SNMP::Info::Layer3::AlcatelLucent::ISA = qw/SNMP::Info::AMAP SNMP::Info::LLDP
47 SNMP::Info::MAU SNMP::Info::Layer3 Exporter/;
48 @SNMP::Info::Layer3::AlcatelLucent::EXPORT_OK = qw//;
49  
50 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
51  
52 $VERSION = '3.985003';
53  
54 %MIBS = (
55 %SNMP::Info::Layer3::MIBS,
56 %SNMP::Info::MAU::MIBS,
57 %SNMP::Info::LLDP::MIBS,
58 %SNMP::Info::AMAP::MIBS,
59 'ALCATEL-IND1-DEVICES' => 'familyOmniSwitch7000',
60 'ALCATEL-IND1-CHASSIS-MIB' => 'chasEntPhysOperStatus',
61 'ALCATEL-IND1-VLAN-MGR-MIB' => 'vpaType',
62 'ALU-POWER-ETHERNET-MIB' => 'pethPsePortDetectionStatus',
63 );
64  
65 # Alcatel's AOS 6 copy of the POWER-ETHERNET-MIB lives in vendor space
66 # without renaming any objects, while AOS 8 implements the standard MIB.
67 # With both modules loaded a bare leaf name resolves to whichever loaded
68 # last, so every peth column is qualified with its MIB name.
69  
70 %GLOBALS = (
71 %SNMP::Info::Layer3::GLOBALS, %SNMP::Info::MAU::GLOBALS,
72 %SNMP::Info::LLDP::GLOBALS, %SNMP::Info::AMAP::GLOBALS,
73 );
74  
75 %FUNCS = (
76 %SNMP::Info::Layer3::FUNCS, %SNMP::Info::MAU::FUNCS,
77 %SNMP::Info::LLDP::FUNCS, %SNMP::Info::AMAP::FUNCS,
78  
79 # POWER-ETHERNET-MIB (standard, AOS 8)
80 'std_peth_port_admin' => 'POWER_ETHERNET_MIB__pethPsePortAdminEnable',
81 'std_peth_port_status' =>
82 'POWER_ETHERNET_MIB__pethPsePortDetectionStatus',
83 'std_peth_port_class' =>
84 'POWER_ETHERNET_MIB__pethPsePortPowerClassifications',
85 'std_peth_power_watts' => 'POWER_ETHERNET_MIB__pethMainPsePower',
86 'std_peth_power_status' => 'POWER_ETHERNET_MIB__pethMainPseOperStatus',
87 'std_peth_power_consumption' =>
88 'POWER_ETHERNET_MIB__pethMainPseConsumptionPower',
89 'std_peth_power_threshold' =>
90 'POWER_ETHERNET_MIB__pethMainPseUsageThreshold',
91  
92 # ALU-POWER-ETHERNET-MIB (vendor copy, AOS 6)
93 'alu_peth_port_admin' => 'ALU_POWER_ETHERNET_MIB__pethPsePortAdminEnable',
94 'alu_peth_port_status' =>
95 'ALU_POWER_ETHERNET_MIB__pethPsePortDetectionStatus',
96 'alu_peth_port_class' =>
97 'ALU_POWER_ETHERNET_MIB__pethPsePortPowerClassifications',
98 'alu_peth_power_watts' => 'ALU_POWER_ETHERNET_MIB__pethMainPsePower',
99 'alu_peth_power_status' =>
100 'ALU_POWER_ETHERNET_MIB__pethMainPseOperStatus',
101 'alu_peth_power_consumption' =>
102 'ALU_POWER_ETHERNET_MIB__pethMainPseConsumptionPower',
103 'alu_peth_power_threshold' =>
104 'ALU_POWER_ETHERNET_MIB__pethMainPseUsageThreshold',
105  
106 # ALCATEL-IND1-VLAN-MGR-MIB::vpaTable
107 'alu_vpa_type' => 'vpaType',
108 );
109  
110 %MUNGE = (
111 %SNMP::Info::Layer3::MUNGE, %SNMP::Info::MAU::MUNGE,
112 %SNMP::Info::LLDP::MUNGE, %SNMP::Info::AMAP::MUNGE,
113 );
114  
115 # use MAU-MIB for admin. duplex and admin. speed
116 *SNMP::Info::Layer3::AlcatelLucent::i_duplex_admin
117 = \&SNMP::Info::MAU::mau_i_duplex_admin;
118 *SNMP::Info::Layer3::AlcatelLucent::i_speed_admin
119 = \&SNMP::Info::MAU::mau_i_speed_admin;
120  
121 sub model {
122 my $alu = shift;
123 my $id = $alu->id();
124 my $model = &SNMP::translateObj($id);
125  
126 return $id unless defined $model;
127  
128 $model =~ s/^device//;
129  
130 return $model;
131 }
132  
133 sub os {
134 return 'AOS';
135 }
136  
137 sub vendor {
138 return 'alcatel-lucent';
139 }
140  
141 sub os_ver {
142 my $alu = shift;
143  
144 my $descr = $alu->description();
145 if (defined ($descr)) {
146 return $1 if $descr =~ m/\b(\d[\.\d]+R\d+) (?:GA|Service Release), /;
147 }
148  
149 # No clue what this will try but hey
150 return $alu->SUPER::os_ver();
151 }
152  
153 # ps1_type, ps1_status, ps2_type, ps2_status:
154 # Find the list of power supplies in the ENTITY-MIB
155 # e_class = powerSupply
156 # e_descr = ps_type
157 # chasEntPhysOperStatus = ps_status
158 sub _power_supplies {
159 my $alu = shift;
160  
161 my $e_class = $alu->e_class();
162 my @supplies = ();
163  
164 foreach my $key ( sort { int($a) cmp int($b) } keys %$e_class ) {
165 if ( $e_class->{$key} eq 'powerSupply' ) {
166 push( @supplies, int($key) );
167 }
168 }
169 return @supplies;
170 }
171  
172 sub _ps_type {
173 my $alu = shift;
174 my $psnum = shift;
175 my @ps = $alu->_power_supplies();
176  
177 if ( $psnum > $#ps ) {
178 return "none";
179 }
180 my $supply = $ps[$psnum];
181 my $descr = $alu->e_descr($supply);
182 return $descr->{$supply};
183 }
184  
185 sub _ps_status {
186 my $alu = shift;
187 my $psnum = shift;
188 my @ps = $alu->_power_supplies();
189  
190 if ( $psnum > $#ps ) {
191 return "not present";
192 }
193 my $supply = $ps[$psnum];
194 my $status = $alu->chasEntPhysOperStatus($supply);
195 return $status->{$supply};
196 }
197  
198 sub ps1_type {
199 my $alu = shift;
200 return $alu->_ps_type(0);
201 }
202  
203 sub ps2_type {
204 my $alu = shift;
205 return $alu->_ps_type(1);
206 }
207  
208 sub ps1_status {
209 my $alu = shift;
210 return $alu->_ps_status(0);
211 }
212  
213 sub ps2_status {
214 my $alu = shift;
215 return $alu->_ps_status(1);
216 }
217  
218 # The interface description contains the software version, so
219 # to avoid losing historical information through a software upgrade
220 # we use interface name instead.
221 sub interfaces {
222 my $alu = shift;
223 my $partial = shift;
224  
225 return $alu->orig_i_name($partial);
226 }
227  
228 # Work around buggy bp_index in 6.3.1.871.R01 and 6.3.1.975.R01
229 sub bp_index {
230 my $alu = shift;
231 my $partial = shift;
232  
233 my $bp_index = $alu->SUPER::bp_index($partial);
234  
235 #
236 # This device sometimes reports an ifIndex and sometimes reports
237 # dot1dBasePort for the dot1d port values - e.g.,
238 # in 6.3.1.871.R01 both dot1dTpFdbPort and dot1qTpFdbPort report
239 # the ifIndex; in 6.3.1.975.R01 dot1dTpFdbPort has been updated
240 # to report the dot1dBasePort but dot1qTpFdbPort still returns an
241 # ifIndex. For this reason, we augment the dot1dBasePort
242 # mapping with ifIndex->ifIndex mappings -- we can do this because
243 # the ifIndex and dot1dBasePort spaces don't overlap, at least for
244 # the ports we care about.
245 my @keys = keys %$bp_index;
246 foreach my $idx (@keys) {
247 my $ifIndex = $bp_index->{$idx};
248 $bp_index->{$ifIndex} = $ifIndex;
249 }
250  
251 #
252 # In addition, aggregates aren't reported at all in bp_index.
253 # We grab them from i_index.
254 my $i_index = $alu->i_index();
255 foreach my $idx ( keys %$i_index ) {
256 my $ifIndex = $i_index->{$idx};
257 if ( int($ifIndex) > 40000001 ) {
258 $bp_index->{$ifIndex} = $ifIndex;
259  
260 # dot1dTpFdbPort seems to use 4098, 4099, 4100 for
261 # 40000001, 40000002, 40000003. I guess this is
262 # 4096 + 1 + aggregate number.
263 my $tmp = sprintf( "%d", int($ifIndex) - 39995903 );
264 $bp_index->{$tmp} = $ifIndex;
265 }
266 }
267 return $bp_index;
268 }
269  
270 # AOS 8 (and some AOS 6 releases) leave dot1qPvid empty, so fall back to
271 # the configured default VLAN in vpaTable, indexed by vlan.ifIndex. A port
272 # listed as default in more than one VLAN is ambiguous and left out.
273 sub i_vlan {
274 my $alu = shift;
275 my $partial = shift;
276  
277 my $i_vlan = $alu->SUPER::i_vlan($partial);
278 return $i_vlan if ref $i_vlan eq 'HASH' and scalar keys %$i_vlan;
279  
280 my $vpa_type = $alu->alu_vpa_type();
281 unless ( ref $vpa_type eq 'HASH' and scalar keys %$vpa_type ) {
282 $vpa_type = $alu->alu8_vpa_type();
283 }
284 return {} unless ref $vpa_type eq 'HASH';
285  
286 my %defaults;
287 foreach my $iid ( keys %$vpa_type ) {
288 my $type = $vpa_type->{$iid};
289 next unless defined $type and $type =~ m/^(?:cfgDefault|1)$/;
290 my ( $vlan, $ifindex ) = split( m/\./, $iid );
291 next if defined $partial and $ifindex ne $partial;
292 push @{ $defaults{$ifindex} }, $vlan;
293 }
294  
295 my $default_vlan = {};
296 foreach my $ifindex ( keys %defaults ) {
297 my @vlans = @{ $defaults{$ifindex} };
298 $default_vlan->{$ifindex} = $vlans[0] if scalar @vlans == 1;
299 }
300 return $default_vlan;
301 }
302  
303 # AOS 8 serves vpaType under .6486.801, but netdisco-mibs only defines the
304 # AOS 6 tree under .6486.800. With no MIB node there net-snmp returns the
305 # whole instance OID as the tag and an empty iid, which AUTOLOAD's table
306 # walk cannot follow, so walk the numeric column here.
307 sub alu8_vpa_type {
308 my $alu = shift;
309  
310 return $alu->{store}{alu8_vpa_type} if $alu->{'_alu8_vpa_type'};
311 return if $alu->{Offline};
312 my $sess = $alu->session() or return;
313  
314 my $base = '.1.3.6.1.4.1.6486.801.1.2.1.3.1.1.2.1.1.3';
315 my ( $vpa_type, $failure ) = _alu8_vpa_walk( $sess, $base );
316 my ( $reason, $errornum, $error ) = @{$failure};
317  
318 my $rows = scalar keys %{$vpa_type};
319 $alu->_walk_outcome(
320 { method => 'alu8_vpa_type',
321 leaf => $base,
322 partial => undef,
323 complete => ( SNMP::Info::_walk_incomplete($reason) ? 0 : 1 ),
324 reason => $reason,
325 error => $error,
326 errornum => $errornum,
327 walk => 'getnext',
328 repeaters => undef,
329 rows => $rows,
330 recovery => [],
331 }
332 );
333  
334 if ( SNMP::Info::_walk_incomplete($reason) ) {
335 $alu->error_throw( "SNMP::Info::Layer3::AlcatelLucent: "
336 . "alu8_vpa_type incomplete: $reason after $rows rows. "
337 . ( $error || '' ) );
338 return if $alu->incomplete_walk() eq 'undef';
339 }
340 $alu->_cache( 'alu8_vpa_type', $vpa_type );
341 return $vpa_type;
342 }
343  
344 # Walks the numeric column. Returns the rows and a [reason, errornum, error]
345 # triple that is empty when the walk ended cleanly.
346 sub _alu8_vpa_walk {
347 my ( $sess, $base ) = @_;
348  
349 my $next_oid = $base;
350 my $vpa_type = {};
351 my %seen;
352 while (1) {
353  
354 # The returned tag cannot be resent, so ask again by number.
355 my $var = SNMP::Varbind->new( [$next_oid] );
356 $sess->getnext($var);
357 if ( $sess->{ErrorNum} ) {
358 return ( $vpa_type, [] ) if SNMP::Info::_nosuch_end($sess);
359 return ( $vpa_type, [ SNMP::Info::_walk_failure($sess) ] );
360 }
361 last if !defined $var->[0];
362 my $name = $var->[0];
363 $name .= ".$var->[1]" if defined $var->[1] and length $var->[1];
364 my $oid = $name =~ m/^[.]\d/
365 ? $name
366 : SNMP::translateObj($name) // $name;
367  
368 # endOfMibView repeats the last OID, so test it before the loop check
369 last if defined $var->[2] and $var->[2] eq 'ENDOFMIBVIEW';
370 if ( $seen{$oid}++ ) {
371 return ( $vpa_type,
372 [ 'loop', 0, "Looping on: alu8_vpa_type oid:$oid." ] );
373 }
374 last unless $oid =~ m/^\Q$base\E\.(\d+\.\d+)$/;
375 $vpa_type->{$1} = $var->[2];
376 $next_oid = $oid;
377 }
378 return ( $vpa_type, [] );
379 }
380  
381 # One PoE source per device: the standard MIB when its port table has
382 # rows, otherwise the AOS 6 vendor copy.
383 sub _peth_table {
384 my $alu = shift;
385 my $method = shift;
386 my $partial = shift;
387  
388 my $std_status = $alu->std_peth_port_status();
389 my $source
390 = ( ref $std_status eq 'HASH' and scalar keys %$std_status )
391 ? 'std'
392 : 'alu';
393 my $leaf_method = "${source}_$method";
394 my $table = $alu->$leaf_method($partial);
395 return $table;
396 }
397  
398 sub peth_port_admin {
399 my ( $alu, $partial ) = @_;
400 return $alu->_peth_table( 'peth_port_admin', $partial );
401 }
402  
403 sub peth_port_status {
404 my ( $alu, $partial ) = @_;
405 return $alu->_peth_table( 'peth_port_status', $partial );
406 }
407  
408 sub peth_port_class {
409 my ( $alu, $partial ) = @_;
410 return $alu->_peth_table( 'peth_port_class', $partial );
411 }
412  
413 sub peth_power_watts {
414 my ( $alu, $partial ) = @_;
415 return $alu->_peth_table( 'peth_power_watts', $partial );
416 }
417  
418 sub peth_power_status {
419 my ( $alu, $partial ) = @_;
420 return $alu->_peth_table( 'peth_power_status', $partial );
421 }
422  
423 sub peth_power_consumption {
424 my ( $alu, $partial ) = @_;
425 return $alu->_peth_table( 'peth_power_consumption', $partial );
426 }
427  
428 sub peth_power_threshold {
429 my ( $alu, $partial ) = @_;
430 return $alu->_peth_table( 'peth_power_threshold', $partial );
431 }
432  
433 # Power-Ethernet ifIndex mapping. I've only seen this from a
434 # fixed-config single-module system, so this is only a plausible
435 # guess as to the mapping on a stack or modular system.
436 sub peth_port_ifindex {
437 my $alu = shift;
438 my $partial = shift;
439  
440 my $peth_port_status = $alu->peth_port_status($partial);
441 my $peth_port_ifindex = {};
442  
443 foreach my $key ( keys %$peth_port_status ) {
444 my @oid = split( m/\./, $key );
445 $peth_port_ifindex->{$key} = int( $oid[0] ) * 1000 + int( $oid[1] );
446 }
447 return $peth_port_ifindex;
448 }
449  
450 1;
451 __END__