Info.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Info/Layer7/Liebert.pm ↑ Summary
1 # SNMP::Info
2 #
3 # Copyright (c) 2003-2012 Max Baker and SNMP::Info Developers
4 # All rights reserved.
5 #
6 # Portions Copyright (c) 2002-2003, Regents of the University of California
7 # All rights reserved.
8 #
9 # See COPYRIGHT at bottom
10  
11 package SNMP::Info;
12  
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0 ▶use SNMP;
Subroutine BEGIN: called CC=1 SCAR=2.6
17 use Carp;
18 use Scalar::Util ();
19 use Math::BigInt;
20 use NetAddr::IP::Lite ':lower';
21  
22 @SNMP::Info::ISA = qw/Exporter/;
23 @SNMP::Info::EXPORT_OK = qw//;
24  
25 our
26 ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE, $AUTOLOAD, $INIT, $DEBUG, %SPEED_MAP,
27 $NOSUCH, $BIGINT, $REPEATERS,
28 $BACKOFF_FLOOR, $MAX_FAILED_BULKWALKS, $SLOW_DEVICE_TABLES);
29  
30 $VERSION = '3.985003';
31  
32 =head1 NAME
33  
34 SNMP::Info - OO Interface to Network devices and MIBs through SNMP
35  
36 =head1 VERSION
37  
38 SNMP::Info - Version 3.985003
39  
40 =head1 AUTHOR
41  
42 SNMP::Info is maintained by team of Open Source authors headed by Eric Miller,
43 Bill Fenner, Max Baker, Jeroen van Ingen and Oliver Gorwits.
44  
45 Please visit L<https://github.com/netdisco/snmp-info/> for the most up-to-date
46 list of developers.
47  
48 SNMP::Info was originally created at UCSC for the Netdisco project L<http://netdisco.org>
49 by Max Baker.
50  
51 =head1 DEVICES SUPPORTED
52  
53 There are now generic classes for most types of device and so the authors
54 recommend loading SNMP::Info with AutoSpecify, and then reporting to the mail
55 list any missing functionality (such as neighbor discovery tables).
56  
57 =head1 SYNOPSIS
58  
59 use SNMP::Info;
60  
61 my $info = SNMP::Info->new({
62 # Auto Discover your Device Class (Cisco, Juniper, etc ...)
63 AutoSpecify => 1,
64 Debug => 1,
65  
66 # The rest is passed to SNMP::Session
67 DestHost => 'router',
68 Community => 'public',
69 Version => 2
70  
71 # Parameter reference for SNMPv3
72 # Version => 3
73 # SecLevel => 'authPriv', # authPriv|authNoPriv|noAuthNoPriv
74 # SecName => 'myuser',
75 # AuthProto => 'MD5', # MD5|SHA|SHA512|SHA384|SHA256|SHA224
76 # AuthPass => 'authp4ss',
77 # PrivProto => 'DES', # DES|AES|AES128|AES192|AES256
78 # PrivPass => 'pr1vp4ss',
79  
80 # Rarer options - see https://metacpan.org/pod/SNMP for full list
81 # Timeout => 15 * 1000000, # microseconds
82 # RemotePort => 161,
83 # NonIncreasing => 1
84 });
85  
86 my $err = $info->error();
87 die $err if defined $err;
88 # usually a wrong DestHost or Community or Version if you have trouble here
89  
90 my $name = $info->name();
91 my $class = $info->class();
92 print "SNMP::Info is using this device class : $class\n";
93  
94 # Find out the Duplex status for the ports
95 my $interfaces = $info->interfaces();
96 my $i_duplex = $info->i_duplex();
97  
98 # Get CDP Neighbor info
99 my $c_if = $info->c_if();
100 my $c_ip = $info->c_ip();
101 my $c_port = $info->c_port();
102  
103 # Print out data per port
104 foreach my $iid (keys %$interfaces){
105 my $duplex = $i_duplex->{$iid};
106 # Print out physical port name, not snmp iid
107 my $port = $interfaces->{$iid};
108  
109 print "$port: ";
110 print "$duplex duplex" if defined $duplex;
111  
112 # The CDP Table has table entries different than the interface tables.
113 # So we use c_if to get the map from cdp table to interface table.
114  
115 my %c_map = reverse %$c_if;
116 my $c_key = $c_map{$iid};
117 unless (defined $c_key) {
118 print "\n\n";
119 next;
120 }
121 my $neighbor_ip = $c_ip->{$c_key};
122 my $neighbor_port = $c_port->{$c_key};
123  
124 print " connected to $neighbor_ip / $neighbor_port\n" if defined $neighbor_ip;
125 print "\n";
126  
127 }
128  
129 =head1 SUPPORT
130  
131 Please direct all support, help, and bug requests to the snmp-info-users
132 Mailing List at L<http://lists.sourceforge.net/lists/listinfo/snmp-info-users>.
133  
134 =head1 DESCRIPTION
135  
136 SNMP::Info gives an object oriented interface to information obtained through
137 SNMP.
138  
139 This module is geared towards network devices. Subclasses exist for a number
140 of network devices and common MIBs.
141  
142 The idea behind this module is to give a common interface to data from network
143 devices, leaving the device-specific hacks behind the scenes in subclasses.
144  
145 In the SYNOPSIS example we fetch the name of all the ports on the device and
146 the duplex setting for that port with two methods -- interfaces() and
147 i_duplex().
148  
149 The information may be coming from any number of MIB files and is very vendor
150 specific. SNMP::Info provides you a common method for all supported devices.
151  
152 Adding support for your own device is easy, and takes little SNMP knowledge.
153  
154 The module is not limited to network devices. Any MIB or device can be given
155 an objected oriented front-end by making a module that consists of a couple
156 hashes. See EXTENDING SNMP::INFO.
157  
158 =head1 REQUIREMENTS
159  
160 =over
161  
162 =item 1. Net-SNMP
163  
164 To use this module, you must have Net-SNMP installed on your system.
165 More specifically you need the Perl modules that come with it.
166  
167 DO NOT INSTALL SNMP:: or Net::SNMP from CPAN!
168  
169 The SNMP module is matched to an install of net-snmp, and must be installed
170 from the net-snmp source tree.
171  
172 The Perl module C<SNMP> is found inside the net-snmp distribution. Go to the
173 F<perl/> directory of the distribution to install it, or run
174 C<./configure --with-perl-modules> from the top directory of the net-snmp
175 distribution. The net-snmp version and configuration will also determine
176 which authentication and privacy protocols are available when using snmpv3.
177  
178 Net-SNMP can be found at L<http://net-snmp.sourceforge.net>.
179  
180 No minimum Net-SNMP version is enforced. The walk code SNMP::Info uses has
181 been stable since Net-SNMP 5.7.3.
182  
183 B<Redhat Users>: Some versions that come with certain versions of
184 Redhat/Fedora don't have the Perl library installed. Uninstall the RPM and
185 install by hand.
186  
187 =item 2. MIBS
188  
189 SNMP::Info operates on textual descriptors found in MIBs.
190  
191 If you are using SNMP::Info separate from Netdisco,
192 download the Netdisco MIB package at L<https://github.com/netdisco/netdisco-mibs/releases/latest/>
193  
194 Make sure that your snmp.conf is updated to point to your MIB directory
195 and that the MIBs are world-readable.
196  
197 =back
198  
199 =head1 DESIGN GOALS
200  
201 =over
202  
203 =item 1. Use of textual MIB leaf identifier and enumerated values
204  
205 =over
206  
207 =item * All values are retrieved via MIB Leaf node names
208  
209 For example SNMP::Info has an entry in its %GLOBALS hash for ``sysName''
210 instead of 1.3.6.1.2.1.1.5.
211  
212 =item * Data returned is in the enumerated value form.
213  
214 For Example instead of looking up 1.3.6.1.2.1.2.2.1.3 and getting back C<23>
215  
216 SNMP::Info will ask for C<RFC1213-MIB::ifType> and will get back C<ppp>.
217  
218 =back
219  
220 =item 2. SNMP::Info is easily extended to new devices
221  
222 You can create a new subclass for a device by providing four hashes :
223 %GLOBALS, %MIBS, %FUNCS, and %MUNGE.
224  
225 Or you can override any existing methods from a parent class by making a short
226 subroutine.
227  
228 See the section EXTENDING SNMP::INFO for more details.
229  
230 When you make a new subclass for a device, please be sure to send it back
231 to the developers (via a github pull request or the mailing list) for inclusion
232 in the next version.
233  
234 =back
235  
236 =head1 SUBCLASSES
237  
238 These are the subclasses that implement MIBs and support devices:
239  
240 Required MIBs not included in the install instructions above are noted here.
241  
242 =head2 MIB Subclasses
243  
244 These subclasses implement method to access one or more MIBs. These are not
245 used directly, but rather inherited from device subclasses.
246  
247 For more info run C<perldoc> on any of the following module names.
248  
249 =over
250  
251 =item SNMP::Info::AdslLine
252  
253 SNMP Interface to the ADSL-LINE-MIB for ADSL interfaces.
254  
255 Requires the F<ADSL-LINE-MIB>, down loadable from Cisco.
256  
257 See documentation in L<SNMP::Info::AdslLine> for details.
258  
259 =item SNMP::Info::Aggregate
260  
261 SNMP Interface to F<IF-MIB> C<ifStackTable> Aggregated Links
262  
263 See documentation in L<SNMP::Info::Aggregate> for details.
264  
265 =item SNMP::Info::Airespace
266  
267 F<AIRESPACE-WIRELESS-MIB> and F<AIRESPACE-SWITCHING-MIB>. Inherited by
268 devices based on the Airespace wireless platform.
269  
270 See documentation in L<SNMP::Info::Airespace> for details.
271  
272 =item SNMP::Info::AMAP
273  
274 F<ALCATEL-IND1-INTERSWITCH-PROTOCOL-MIB>. Alcatel Mapping Adjacency
275 Protocol (AMAP) Support.
276  
277 See documentation in L<SNMP::Info::AMAP> for details.
278  
279 =item SNMP::Info::Bridge
280  
281 F<BRIDGE-MIB> (RFC1286). F<Q-BRIDGE-MIB>. Inherited by devices with Layer2
282 support.
283  
284 See documentation in L<SNMP::Info::Bridge> for details.
285  
286 =item SNMP::Info::CDP
287  
288 F<CISCO-CDP-MIB>. Cisco Discovery Protocol (CDP) Support. Inherited by
289 Cisco, Enterasys, and HP devices.
290  
291 See documentation in L<SNMP::Info::CDP> for details.
292  
293 =item SNMP::Info::CiscoAgg
294  
295 SNMP Interface to Cisco Aggregated Links
296  
297 See documentation in L<SNMP::Info::CiscoAgg> for details.
298  
299 =item SNMP::Info::CiscoAuthFramework
300  
301 F<CISCO-AUTH-FRAMEWORK-MIB>. Cisco Authentication Framework session
302 information, including dynamically assigned authentication VLANs.
303  
304 See documentation in L<SNMP::Info::CiscoAuthFramework> for details.
305  
306 =item SNMP::Info::CiscoBGP
307  
308 F<CISCO-BGP4-MIB>. Cisco BGPv4 support. Inherited by Cisco devices with
309 Layer3 support.
310  
311 See documentation in L<SNMP::Info::CiscoBGP> for details.
312  
313 =item SNMP::Info::CiscoConfig
314  
315 F<CISCO-CONFIG-COPY-MIB>, F<CISCO-FLASH-MIB>, and F<OLD-CISCO-SYS-MIB>.
316 These OIDs facilitate the writing of configuration files.
317  
318 See documentation in L<SNMP::Info::CiscoConfig> for details.
319  
320 =item SNMP::Info::CiscoPortSecurity
321  
322 F<CISCO-PORT-SECURITY-MIB> and F<CISCO-PAE-MIB>.
323  
324 See documentation in L<SNMP::Info::CiscoPortSecurity> for details.
325  
326 =item SNMP::Info::CiscoPower
327  
328 F<CISCO-POWER-ETHERNET-EXT-MIB>.
329  
330 See documentation in L<SNMP::Info::CiscoPower> for details.
331  
332 =item SNMP::Info::CiscoQOS
333  
334 F<CISCO-CLASS-BASED-QOS-MIB>. A collection of OIDs providing information about
335 a Cisco device's QOS config.
336  
337 See documentation in L<SNMP::Info::CiscoQOS> for details.
338  
339 =item SNMP::Info::CiscoRTT
340  
341 F<CISCO-RTTMON-MIB>. A collection of OIDs providing information about a Cisco
342 device's RTT values.
343  
344 See documentation in L<SNMP::Info::CiscoRTT> for details.
345  
346 =item SNMP::Info::CiscoStack
347  
348 F<CISCO-STACK-MIB>.
349  
350 See documentation in L<SNMP::Info::CiscoStack> for details.
351  
352 =item SNMP::Info::CiscoStats
353  
354 F<OLD-CISCO-CPU-MIB>, F<CISCO-PROCESS-MIB>, and F<CISCO-MEMORY-POOL-MIB>.
355 Provides common interfaces for memory, cpu, and os statistics for Cisco
356 devices.
357  
358 See documentation in L<SNMP::Info::CiscoStats> for details.
359  
360 =item SNMP::Info::CiscoStpExtensions
361  
362 F<CISCO-STP-EXTENSIONS-MIB>
363  
364 See documentation in L<SNMP::Info::CiscoStpExtensions> for details.
365  
366 =item SNMP::Info::CiscoVTP
367  
368 F<CISCO-VTP-MIB>, F<CISCO-VLAN-MEMBERSHIP-MIB>,
369 F<CISCO-VLAN-IFTABLE-RELATIONSHIP-MIB>
370  
371 See documentation in L<SNMP::Info::CiscoVTP> for details.
372  
373 =item SNMP::Info::DocsisCM
374  
375 SNMP Interface for DOCSIS Cable Modems
376  
377 See documentation in L<SNMP::Info::DocsisCM> for details.
378  
379 =item SNMP::Info::DocsisHE
380  
381 SNMP Interface for DOCSIS CMTS
382  
383 See documentation in L<SNMP::Info::DocsisHE> for details.
384  
385 =item SNMP::Info::EDP
386  
387 Extreme Discovery Protocol. F<EXTREME-EDP-MIB>
388  
389 See documentation in L<SNMP::Info::EDP> for details.
390  
391 =item SNMP::Info::Entity
392  
393 F<ENTITY-MIB>. Used for device info in Cisco and other vendors.
394  
395 See documentation in L<SNMP::Info::Entity> for details.
396  
397 =item SNMP::Info::EtherLike
398  
399 F<EtherLike-MIB> (RFC1398) - Some Layer3 devices implement this MIB, as well
400 as some Aironet Layer 2 devices (non Cisco).
401  
402 See documentation in L<SNMP::Info::EtherLike> for details.
403  
404 =item SNMP::Info::FDP
405  
406 Foundry (Brocade) Discovery Protocol. F<FOUNDRY-SN-SWITCH-GROUP-MIB>
407  
408 See documentation in L<SNMP::Info::FDP> for details.
409  
410 =item SNMP::Info::IEEE802_Bridge
411  
412 SNMP Interface to data available through the F<IEEE8021-Q-BRIDGE-MIB>
413  
414 See documentation in L<SNMP::Info::IEEE802_Bridge> for details.
415  
416 =item SNMP::Info::IEEE802dot11
417  
418 F<IEEE802dot11-MIB>. A collection of OIDs providing information about
419 standards based 802.11 wireless devices.
420  
421 See documentation in L<SNMP::Info::IEEE802dot11> for details.
422  
423 =item SNMP::Info::IEEE802dot3ad
424  
425 SNMP Interface to IEEE Aggregated Links. F<IEEE8023-LAG-MIB>
426  
427 See documentation in L<SNMP::Info::IEEE802dot3ad> for details.
428  
429 =item SNMP::Info::L2Service
430  
431 Bindings between local VLANs and layer 2 service IDs, such as SPB I-SIDs
432 and VXLAN VNIs, from the device class's own sources.
433  
434 See documentation in L<SNMP::Info::L2Service> for details.
435  
436 =item SNMP::Info::IPv6
437  
438 SNMP Interface for obtaining configured IPv6 addresses and mapping IPv6
439 addresses to MAC addresses and interfaces, using information from F<IP-MIB>,
440 F<IPV6-MIB> and/or F<CISCO-IETF-IP-MIB>.
441  
442 See documentation in L<SNMP::Info::IPv6> for details.
443  
444 =item SNMP::Info::LLDP
445  
446 F<LLDP-MIB>, F<LLDP-EXT-DOT1-MIB>, and F<LLDP-EXT-DOT3-MIB>. Link Layer
447 Discovery Protocol (LLDP) Support.
448  
449 See documentation in L<SNMP::Info::LLDP> for details.
450  
451 =item SNMP::Info::MAU
452  
453 F<MAU-MIB> (RFC2668). Some Layer2 devices use this for extended Ethernet
454 (Medium Attachment Unit) interface information.
455  
456 See documentation in L<SNMP::Info::MAU> for details.
457  
458 =item SNMP::Info::MRO
459  
460 Method resolution introspection for SNMP::Info
461  
462 See documentation in L<SNMP::Info::MRO> for details.
463  
464 =item SNMP::Info::NortelStack
465  
466 F<S5-AGENT-MIB>, F<S5-CHASSIS-MIB>.
467  
468 See documentation in L<SNMP::Info::NortelStack> for details.
469  
470 =item SNMP::Info::PortAccessEntity
471  
472 F<IEEE8021-PAE-MIB>
473  
474 See documentation in L<SNMP::Info::PortAccessEntity> for details.
475  
476 =item SNMP::Info::PowerEthernet
477  
478 F<POWER-ETHERNET-MIB>
479  
480 See documentation in L<SNMP::Info::PowerEthernet> for details.
481  
482 =item SNMP::Info::RapidCity
483  
484 F<RAPID-CITY>. Inherited by Avaya switches and, through
485 L<SNMP::Info::Layer3::VOSS>, VOSS and Fabric Engine switches, for duplex and
486 VLAN information.
487  
488 See documentation in L<SNMP::Info::RapidCity> for details.
489  
490 =item SNMP::Info::RapidCityLegacy
491  
492 F<RAPID-CITY>. The tables used by the Passport 8600 era, ERS and
493 BayStack families. Inherited by Avaya switches ahead of
494 L<SNMP::Info::RapidCity>.
495  
496 See documentation in L<SNMP::Info::RapidCityLegacy> for details.
497  
498 =item SNMP::Info::RapidCityVRF
499  
500 F<RAPID-CITY>. The VRFs of VOSS and Fabric Engine switches, read as
501 contexts. Inherited by L<SNMP::Info::Layer3::VOSS> ahead of
502 L<SNMP::Info::RapidCity>.
503  
504 See documentation in L<SNMP::Info::RapidCityVRF> for details.
505  
506 =item SNMP::Info::SONMP
507  
508 SynOptics Network Management Protocol (SONMP) F<SYNOPTICS-ROOT-MIB>,
509 F<S5-ETH-MULTISEG-TOPOLOGY-MIB>. Inherited by
510 Avaya/Nortel/Bay/Synoptics switches and hubs.
511  
512 See documentation in L<SNMP::Info::SONMP> for details.
513  
514 =item SNMP::Info::VRF
515  
516 VRF instances, their ports, neighbors, interface addresses and subnets,
517 from F<MPLS-L3VPN-STD-MIB> and F<IP-FORWARD-MIB>. Inherited by
518 SNMP::Info::Layer3.
519  
520 See documentation in L<SNMP::Info::VRF> for details.
521  
522 =back
523  
524 =head2 Device Subclasses
525  
526 These subclasses inherit from one or more classes to provide a common
527 interface to data obtainable from network devices.
528  
529 All the required MIB files are included in the netdisco-mib package.
530 (See Above).
531  
532 =over 4
533  
534 =item SNMP::Info::Layer1
535  
536 Generic Layer1 Device subclass.
537  
538 See documentation in L<SNMP::Info::Layer1> for details.
539  
540 =over 4
541  
542 =item SNMP::Info::Layer1::Allied
543  
544 Subclass for Allied Telesis Repeaters / Hubs.
545  
546 Requires F<ATI-MIB>
547  
548 See documentation in L<SNMP::Info::Layer1::Allied> for details.
549  
550 =item SNMP::Info::Layer1::Asante
551  
552 Subclass for Asante 1012 Hubs.
553  
554 Requires F<ASANTE-HUB1012-MIB>
555  
556 See documentation in L<SNMP::Info::Layer1::Asante> for details.
557  
558 =item SNMP::Info::Layer1::Bayhub
559  
560 Subclass for Nortel/Bay hubs. This includes System 5000, 100 series,
561 200 series, and probably more.
562  
563 See documentation in L<SNMP::Info::Layer1::Bayhub> for details.
564  
565 =item SNMP::Info::Layer1::Cyclades
566  
567 Subclass for Cyclades/Avocent terminal servers.
568  
569 See documentation in L<SNMP::Info::Layer1::Cyclades> for details.
570  
571 =item SNMP::Info::Layer1::S3000
572  
573 Subclass for Bay/Synoptics hubs. This includes System 3000, 281X, and
574 probably more.
575  
576 See documentation in L<SNMP::Info::Layer1::S3000> for details.
577  
578 =back
579  
580 =item SNMP::Info::Layer2
581  
582 Generic Layer2 Device subclass.
583  
584 See documentation in L<SNMP::Info::Layer2> for details.
585  
586 =over
587  
588 =item SNMP::Info::Layer2::3Com
589  
590 Subclass for L2 3Com Switches.
591  
592 See documentation in L<SNMP::Info::Layer2::3Com> for details.
593  
594 =item SNMP::Info::Layer2::Adtran
595  
596 Subclass for Adtran devices.
597  
598 See documentation in L<SNMP::Info::Layer2::Adtran> for details.
599  
600 =item SNMP::Info::Layer2::Aerohive
601  
602 Subclass for Aerohive / Extreme access points.
603  
604 See documentation in L<SNMP::Info::Layer2::Aerohive> for details.
605  
606 =item SNMP::Info::Layer2::Airespace
607  
608 Subclass for Cisco (Airespace) wireless controllers.
609  
610 See documentation in L<SNMP::Info::Layer2::Airespace> for details.
611  
612 =item SNMP::Info::Layer2::Aironet
613  
614 Class for Cisco Aironet wireless devices that run IOS. See also
615 L<SNMP::Info::Layer3::Aironet> for Aironet devices that don't run IOS.
616  
617 See documentation in L<SNMP::Info::Layer2::Aironet> for details.
618  
619 =item SNMP::Info::Layer2::Allied
620  
621 Allied Telesis switches.
622  
623 See documentation in L<SNMP::Info::Layer2::Allied> for details.
624  
625 =item SNMP::Info::Layer2::Atmedia
626  
627 Subclass for atmedia encryptors.
628  
629 See documentation in L<SNMP::Info::Layer2::Atmedia> for details.
630  
631 =item SNMP::Info::Layer2::Baystack
632  
633 Subclass for Avaya/Nortel/Bay Ethernet Switch/Baystack switches. This
634 includes 303, 304, 350, 380, 410, 420, 425, 450, 460, 470 series,
635 2500 series, 4000 series, 5000 series, Business Ethernet Switch (BES),
636 Business Policy Switch (BPS), VSP 7000 series, and probably others.
637  
638 See documentation in L<SNMP::Info::Layer2::Baystack> for details.
639  
640 =item SNMP::Info::Layer2::C1900
641  
642 Subclass for Cisco Catalyst 1900 and 1900c Devices running CatOS.
643  
644 See documentation in L<SNMP::Info::Layer2::C1900> for details.
645  
646 =item SNMP::Info::Layer2::C2900
647  
648 Subclass for Cisco Catalyst 2900, 2950, 3500XL, and 3548 devices running IOS.
649  
650 See documentation in L<SNMP::Info::Layer2::C2900> for details.
651  
652 =item SNMP::Info::Layer2::Catalyst
653  
654 Subclass for Cisco Catalyst switches running CatOS. These switches usually
655 report a model number that starts with C<wsc>. Note that this class
656 does not support everything that has the name Catalyst.
657  
658 See documentation in L<SNMP::Info::Layer2::Catalyst> for details.
659  
660 =item SNMP::Info::Layer2::Centillion
661  
662 Subclass for Nortel/Bay Centillion and 5000BH ATM switches.
663  
664 See documentation in L<SNMP::Info::Layer2::Centillion> for details.
665  
666 =item SNMP::Info::Layer2::Cisco
667  
668 Generic Cisco subclass for layer 2 devices that are not yet supported
669 in more specific subclasses and the base layer 2 Cisco class for
670 other device specific layer 2 Cisco classes.
671  
672 See documentation in L<SNMP::Info::Layer2::Cisco> for details.
673  
674 =item SNMP::Info::Layer2::CiscoSB
675  
676 Subclass for Cisco's "Small Business" product line, acquired from
677 Linksys. This currently comprises the Sx300/500 line of switches.
678  
679 See documentation in L<SNMP::Info::Layer2::CiscoSB> for details.
680  
681 =item SNMP::Info::Layer2::Exinda
682  
683 Subclass for Exinda / GFI Network Orchestrator traffic shapers.
684  
685 See documentation in L<SNMP::Info::Layer2::Exinda> for details.
686  
687 =item SNMP::Info::Layer2::FortiAP
688  
689 Subclass for Fortinet FortiAP access points.
690  
691 See documentation in L<SNMP::Info::Layer2::FortiAP> for details.
692  
693 =item SNMP::Info::Layer2::Hirschmann
694  
695 Subclass for Hirschmann switches
696  
697 See documentation in L<SNMP::Info::Layer2::Hirschmann> for details.
698  
699 =item SNMP::Info::Layer2::HP
700  
701 Subclass for more recent HP Procurve Switches.
702  
703 Requires F<HP-ICF-OID> and F<ENTITY-MIB> downloaded from HP.
704  
705 See documentation in L<SNMP::Info::Layer2::HP> for details.
706  
707 =item SNMP::Info::Layer2::HP4000
708  
709 Subclass for older HP Procurve Switches
710  
711 Requires F<HP-ICF-OID> and F<ENTITY-MIB> downloaded from HP.
712  
713 See documentation in L<SNMP::Info::Layer2::HP4000> for details.
714  
715 =item SNMP::Info::Layer2::HPVC
716  
717 Subclass for HP Virtual Connect Switches
718  
719 See documentation in L<SNMP::Info::Layer2::HPVC> for details.
720  
721 =item SNMP::Info::Layer2::Kentrox
722  
723 Class for Kentrox DataSMART DSU/CSU.
724  
725 See documentation in L<SNMP::Info::Layer2::Kentrox> for details.
726  
727 =item SNMP::Info::Layer2::LigoWave
728  
729 SNMP interface to LigoWave DLB radios.
730  
731 See documentation in L<SNMP::Info::Layer2::LigoWave> for details.
732  
733 =item SNMP::Info::Layer2::Microsens
734  
735 Subclass for MICROSENS managed switches, including G6 and G6+.
736  
737 See documentation in L<SNMP::Info::Layer2::Microsens> for details.
738  
739 =item SNMP::Info::Layer2::N2270
740  
741 Subclass for Nortel 2270 wireless switches.
742  
743 See documentation in L<SNMP::Info::Layer2::N2270> for details.
744  
745 =item SNMP::Info::Layer2::NAP222x
746  
747 Subclass for Nortel 222x series wireless access points.
748  
749 See documentation in L<SNMP::Info::Layer2::NAP222x> for details.
750  
751 =item SNMP::Info::Layer2::Netgear
752  
753 Subclass for Netgear switches
754  
755 See documentation in L<SNMP::Info::Layer2::Netgear> for details.
756  
757 =item SNMP::Info::Layer2::Nexans
758  
759 Subclass for Nexans switches
760  
761 See documentation in L<SNMP::Info::Layer2::Nexans> for details.
762  
763 =item SNMP::Info::Layer2::NWSS2300
764  
765 SNMP Interface to Avaya (Trapeze) Wireless Controllers
766  
767 See documentation in L<SNMP::Info::Layer2::NWSS2300> for details.
768  
769 =item SNMP::Info::Layer2::Orinoco
770  
771 Subclass for Orinoco/Proxim wireless access points.
772  
773 See documentation in L<SNMP::Info::Layer2::Orinoco> for details.
774  
775 =item SNMP::Info::Layer2::RuckusAP
776  
777 Subclass for Ruckus wireless access points.
778  
779 See documentation in L<SNMP::Info::Layer2::RuckusAP> for details.
780  
781 =item SNMP::Info::Layer2::TPLink
782  
783 SNMP Interface to TPLink devices
784  
785 See documentation in L<SNMP::Info::Layer2::TPLink> for details.
786  
787 =item SNMP::Info::Layer2::Trapeze
788  
789 SNMP Interface to Juniper (Trapeze) Wireless Controllers
790  
791 See documentation in L<SNMP::Info::Layer2::Trapeze> for details.
792  
793 =item SNMP::Info::Layer2::Sixnet
794  
795 SNMP Interface to Sixnet industrial switches
796  
797 See documentation in L<SNMP::Info::Layer2::Sixnet> for details.
798  
799 =item SNMP::Info::Layer2::Ubiquiti
800  
801 SNMP Interface to Ubiquiti Access Points and other devices
802  
803 See documentation in L<SNMP::Info::Layer2::Ubiquiti> for details.
804  
805 =item SNMP::Info::Layer2::ZyXEL_DSLAM
806  
807 Zyxel DSLAMs. Need I say more?
808  
809 See documentation in L<SNMP::Info::Layer2::ZyXEL_DSLAM> for details.
810  
811 =back
812  
813 =item SNMP::Info::Layer3
814  
815 Generic Layer3 and Layer2+3 Device subclass.
816  
817 See documentation in L<SNMP::Info::Layer3> for details.
818  
819 =over
820  
821 =item SNMP::Info::Layer3::Aironet
822  
823 Subclass for Cisco Aironet wireless access points (AP) not running IOS. These
824 are usually older devices.
825  
826 Note L<SNMP::Info::Layer2::Aironet>
827  
828 See documentation in L<SNMP::Info::Layer3::Aironet> for details.
829  
830 =item SNMP::Info::Layer3::AlcatelLucent
831  
832 Alcatel-Lucent OmniSwitch Class.
833  
834 See documentation in L<SNMP::Info::Layer3::AlcatelLucent> for details.
835  
836 =item SNMP::Info::Layer3::AlteonAD
837  
838 Subclass for Radware Alteon Series ADC switches and Nortel BladeCenter
839 Layer2-3 GbE Switch Modules.
840  
841 See documentation in L<SNMP::Info::Layer3::AlteonAD> for details.
842  
843 =item SNMP::Info::Layer3::Altiga
844  
845 See documentation in L<SNMP::Info::Layer3::Altiga> for details.
846  
847 =item SNMP::Info::Layer3::Arista
848  
849 See documentation in L<SNMP::Info::Layer3::Arista> for details.
850  
851 =item SNMP::Info::Layer3::Aruba
852  
853 Subclass for Aruba wireless switches.
854  
855 See documentation in L<SNMP::Info::Layer3::Aruba> for details.
856  
857 =item SNMP::Info::Layer3::ArubaInstant
858  
859 SNMP Interface to Aruba Instant 8.x access points.
860 See L<SNMP::Info::Layer3::ArubaInstant> for details.
861  
862 =item SNMP::Info::Layer3::ArubaCX
863  
864 SNMP Interface to L3 Devices running ArubaOS-CX
865  
866 See documentation in L<SNMP::Info::Layer3::ArubaCX> for details.
867  
868 =item SNMP::Info::Layer3::BayRS
869  
870 Subclass for Avaya/Nortel/Bay Multiprotocol/BayRS routers. This includes
871 BCN, BLN, ASN, ARN, AN, 2430, and 5430 routers.
872  
873 See documentation in L<SNMP::Info::Layer3::BayRS> for details.
874  
875 =item SNMP::Info::Layer3::BlueCoatSG
876  
877 Subclass for BlueCoat SG series proxy devices.
878  
879 See documentation in L<SNMP::Info::Layer3::BlueCoatSG> for details.
880  
881 =item SNMP::Info::Layer3::C1300
882  
883 See documentation in L<SNMP::Info::Layer3::C1300> for details.
884  
885 =item SNMP::Info::Layer3::C3550
886  
887 Subclass for Cisco Catalyst 3550,3540,3560 2/3 switches running IOS.
888  
889 See documentation in L<SNMP::Info::Layer3::C3550> for details.
890  
891 =item SNMP::Info::Layer3::C4000
892  
893 This class covers Catalyst 4000s and 4500s.
894  
895 See documentation in L<SNMP::Info::Layer3::C4000> for details.
896  
897 =item SNMP::Info::Layer3::C6500
898  
899 This class covers Catalyst 6500 series running CatOS or IOS, as well as
900 Catalyst 2960, 2970, 3750 and 3850 series, including blade switches
901 CBS30x0 and CBS31x0 series, all running IOS.
902  
903 See documentation in L<SNMP::Info::Layer3::C6500> for details.
904  
905 =item SNMP::Info::Layer3::C9800
906  
907 Subclass for Cisco Catalyst 9800 Wireless Controllers.
908  
909 See documentation in L<SNMP::Info::Layer3::C9800> for details.
910  
911 =item SNMP::Info::Layer3::Cambium
912  
913 Subclass for Cambium devices (ePMP/cnPilot).
914  
915 See documentation in L<SNMP::Info::Layer3::Cambium> for details.
916  
917 =item SNMP::Info::Layer3::CheckPoint
918  
919 Subclass for CheckPoint devices.
920  
921 See documentation in L<SNMP::Info::Layer3::CheckPoint> for details.
922  
923 =item SNMP::Info::Layer3::Ciena
924  
925 Subclass for Ciena devices.
926  
927 See documentation in L<SNMP::Info::Layer3::Ciena> for details.
928  
929 =item SNMP::Info::Layer3::Cisco
930  
931 This is a simple wrapper around layer 3 for IOS devices and the base layer 3
932 Cisco class for other device specific layer 3 Cisco classes.
933  
934 See documentation in L<SNMP::Info::Layer3::Cisco> for details.
935  
936 =item SNMP::Info::Layer3::CiscoASA
937  
938 Subclass for Cisco Adaptive Security Appliances.
939  
940 See documentation in L<SNMP::Info::Layer3::CiscoASA> for details.
941  
942 =item SNMP::Info::Layer3::CiscoFWSM
943  
944 Subclass for Cisco Firewall Services Modules.
945  
946 See documentation in L<SNMP::Info::Layer3::CiscoFWSM> for details.
947  
948 =item SNMP::Info::Layer3::CiscoSwitch
949  
950 Base class for L3 Cisco switches. See documentation in
951 L<SNMP::Info::Layer3::CiscoSwitch> for details.
952  
953 =item SNMP::Info::Layer3::Contivity
954  
955 Subclass for Avaya/Nortel Contivity/VPN Routers.
956  
957 See documentation in L<SNMP::Info::Layer3::Contivity> for details.
958  
959 =item SNMP::Info::Layer3::Cumulus
960  
961 Subclass for Cumulus Networks Routers.
962  
963 See documentation in L<SNMP::Info::Layer3::Cumulus> for details.
964  
965 =item SNMP::Info::Layer3::Dell
966  
967 Subclass for Dell PowerConnect switches. The IBM BladeCenter
968 Gigabit Ethernet Switch Module and some Linksys switches
969 also use this module based upon MIB support.
970  
971 See documentation in L<SNMP::Info::Layer3::Dell> for details.
972  
973 =item SNMP::Info::Layer3::DLink
974  
975 Subclass for DLink devices.
976  
977 See documentation in L<SNMP::Info::Layer3::DLink> for details.
978  
979 =item SNMP::Info::Layer3::EdgeSwitch
980  
981 Subclass for Broadcom EdgeSwitch devices.
982  
983 See documentation in L<SNMP::Info::Layer3::EdgeSwitch> for details.
984  
985 =item SNMP::Info::Layer3::Enterasys
986  
987 Subclass for Enterasys devices.
988  
989 See documentation in L<SNMP::Info::Layer3::Enterasys> for details.
990  
991 =item SNMP::Info::Layer3::ERX
992  
993 Subclass for Juniper ERX switches.
994  
995 See documentation in L<SNMP::Info::Layer3::ERX> for details.
996  
997 =item SNMP::Info::Layer3::Extreme
998  
999 Subclass for Extreme Networks switches.
1000  
1001 See documentation in L<SNMP::Info::Layer3::Extreme> for details.
1002  
1003 =item SNMP::Info::Layer3::ExtremeWing
1004  
1005 Subclass for Extreme WiNG APs.
1006  
1007 See documentation in L<SNMP::Info::Layer3::ExtremeWing> for details.
1008  
1009 =item SNMP::Info::Layer3::F5
1010  
1011 Subclass for F5 devices.
1012  
1013 See documentation in L<SNMP::Info::Layer3::F5> for details.
1014  
1015 =item SNMP::Info::Layer3::F5OS
1016  
1017 Subclass for F5OS devices.
1018  
1019 See documentation in L<SNMP::Info::Layer3::F5OS> for details.
1020  
1021 =item SNMP::Info::Layer3::Force10
1022  
1023 Subclass for Force10 devices.
1024  
1025 See documentation in L<SNMP::Info::Layer3::Force10> for details.
1026  
1027 =item SNMP::Info::Layer3::Fortinet
1028  
1029 Subclass for Fortinet devices.
1030  
1031 See documentation in L<SNMP::Info::Layer3::Fortinet> for details.
1032  
1033 =item SNMP::Info::Layer3::Foundry
1034  
1035 Subclass for Ruckus / Brocade / Foundry switches.
1036  
1037 See documentation in L<SNMP::Info::Layer3::Foundry> for details.
1038  
1039 =item SNMP::Info::Layer3::Genua
1040  
1041 Subclass for Genua security devices.
1042  
1043 See documentation in L<SNMP::Info::Layer3::Genua> for details.
1044  
1045 =item SNMP::Info::Layer3::H3C
1046  
1047 SNMP Interface to Layer 3 Devices, H3C & HP A-series.
1048  
1049 See documentation in L<SNMP::Info::Layer3::H3C> for details.
1050  
1051 =item SNMP::Info::Layer3::HP9300
1052  
1053 Subclass for HP network devices which Foundry Networks was the
1054 Original Equipment Manufacturer (OEM) such as the HP ProCurve 9300 and 6300 series.
1055  
1056 See documentation in L<SNMP::Info::Layer3::HP9300> for details.
1057  
1058 =item SNMP::Info::Layer3::Huawei
1059  
1060 SNMP Interface to Huawei Layer 3 switches and routers.
1061  
1062 See documentation in L<SNMP::Info::Layer3::Huawei> for details.
1063  
1064 =item SNMP::Info::Layer3::IBMGbTor
1065  
1066 SNMP Interface to IBM Rackswitch (formerly Blade Network Technologies)
1067 network devices. Lenovo acquired these from IBM and is now selling
1068 them under the Lenovo brand.
1069  
1070 See documentation in L<SNMP::Info::Layer3::IBMGbTor> for details.
1071  
1072 =item SNMP::Info::Layer3::Juniper
1073  
1074 Subclass for Juniper devices.
1075  
1076 See documentation in L<SNMP::Info::Layer3::Juniper> for details.
1077  
1078 =item SNMP::Info::Layer3::Lancom
1079  
1080 Subclass for LANCOM devices running LCOS.
1081  
1082 See documentation in L<SNMP::Info::Layer3::Lancom> for details.
1083  
1084 =item SNMP::Info::Layer3::Lantronix
1085  
1086 Subclass for Lantronix devices.
1087  
1088 See documentation in L<SNMP::Info::Layer3::Lantronix> for details.
1089  
1090 =item SNMP::Info::Layer3::Lenovo
1091  
1092 Subclass for Lenovo switches running CNOS.
1093  
1094 See documentation in L<SNMP::Info::Layer3::Lenovo> for details.
1095  
1096 =item SNMP::Info::Layer3::Meraki
1097  
1098 See documentation in L<SNMP::Info::Layer3::Meraki> for details.
1099  
1100 =item SNMP::Info::Layer3::Microsoft
1101  
1102 Subclass for Generic Microsoft Routers running Microsoft Windows OS.
1103  
1104 See documentation in L<SNMP::Info::Layer3::Microsoft> for details.
1105  
1106 =item SNMP::Info::Layer3::Mikrotik
1107  
1108 Subclass for Mikrotik devices running RouterOS.
1109  
1110 See documentation in L<SNMP::Info::Layer3::Mikrotik> for details.
1111  
1112 =item SNMP::Info::Layer3::N1600
1113  
1114 Subclass for Avaya/Nortel Ethernet Routing Switch 1600 series.
1115  
1116 See documentation in L<SNMP::Info::Layer3::N1600> for details.
1117  
1118 =item SNMP::Info::Layer3::Netonix
1119  
1120 Subclass for Netonix switches.
1121  
1122 See documentation in L<SNMP::Info::Layer3::Netonix> for details.
1123  
1124 =item SNMP::Info::Layer3::Netscreen
1125  
1126 Subclass for Juniper NetScreen.
1127  
1128 See documentation in L<SNMP::Info::Layer3::Netscreen> for details.
1129  
1130 =item SNMP::Info::Layer3::NetSNMP
1131  
1132 Subclass for host systems running Net-SNMP.
1133  
1134 See documentation in L<SNMP::Info::Layer3::NetSNMP> for details.
1135  
1136 =item SNMP::Info::Layer3::Nexus
1137  
1138 Subclass for Cisco Nexus devices running NX-OS.
1139  
1140 See documentation in L<SNMP::Info::Layer3::Nexus> for details.
1141  
1142 =item SNMP::Info::Layer3::OneAccess
1143  
1144 Subclass for OneAccess routers.
1145  
1146 See documentation in L<SNMP::Info::Layer3::OneAccess> for details.
1147  
1148 =item SNMP::Info::Layer3::Onyx
1149  
1150 Subclass for Mellanox/NVIDIA Onyx switches.
1151  
1152 See documentation in L<SNMP::Info::Layer3::Onyx> for details.
1153  
1154 =item SNMP::Info::Layer3::PacketFront
1155  
1156 Subclass for PacketFront DRG series CPE.
1157  
1158 See documentation in L<SNMP::Info::Layer3::PacketFront> for details.
1159  
1160 =item SNMP::Info::Layer3::PaloAlto
1161  
1162 Subclass for Palo Alto firewalls.
1163  
1164 See documentation in L<SNMP::Info::Layer3::PaloAlto> for details.
1165  
1166 =item SNMP::Info::Layer3::Passport
1167  
1168 Subclass for Avaya/Nortel Ethernet Routing Switch/Passport 8000 series,
1169 Accelar, and VSP 9000 series switches.
1170  
1171 See documentation in L<SNMP::Info::Layer3::Passport> for details.
1172  
1173 =item SNMP::Info::Layer3::Pf
1174  
1175 Subclass for FreeBSD-Based Firewalls using Pf /Pf Sense
1176  
1177 See documentation in L<SNMP::Info::Layer3::Pf> for details.
1178  
1179 =item SNMP::Info::Layer3::Pica8
1180  
1181 Subclass for Pica8 devices.
1182  
1183 See documentation in L<SNMP::Info::Layer3::Pica8> for details.
1184  
1185 =item SNMP::Info::Layer3::Redlion
1186  
1187 Subclass for redlion routers.
1188  
1189 See documentation in L<SNMP::Info::Layer3::Redlion> for details.
1190  
1191 =item SNMP::Info::Layer3::RuckusController
1192  
1193 Subclass for Ruckus SmartZone and SmartCell Gateway controllers.
1194  
1195 See documentation in L<SNMP::Info::Layer3::RuckusController> for details.
1196  
1197 =item SNMP::Info::Layer3::Scalance
1198  
1199 Subclass for Siemens Scalance devices.
1200  
1201 See documentation in L<SNMP::Info::Layer3::Scalance> for details.
1202  
1203 =item SNMP::Info::Layer3::Siemens
1204  
1205 Subclass for Siemens SIMATIC, SINAMICS, and soft starter devices.
1206  
1207 See documentation in L<SNMP::Info::Layer3::Siemens> for details.
1208  
1209 =item SNMP::Info::Layer3::SilverPeak
1210  
1211 Subclass for SilverPeak devices.
1212  
1213 See documentation in L<SNMP::Info::Layer3::SilverPeak> for details.
1214  
1215 =item SNMP::Info::Layer3::SONiC
1216  
1217 SONiC switches, community and enterprise distributions.
1218  
1219 See documentation in L<SNMP::Info::Layer3::SONiC> for details.
1220  
1221 =item SNMP::Info::Layer3::SonicWALL
1222  
1223 Subclass for generic SonicWALL devices.
1224  
1225 See documentation in L<SNMP::Info::Layer3::SonicWALL> for details.
1226  
1227 =item SNMP::Info::Layer3::Sophos
1228  
1229 Subclass for Sophos SFOS firewalls.
1230  
1231 See documentation in L<SNMP::Info::Layer3::Sophos> for details.
1232  
1233 =item SNMP::Info::Layer3::Steelfusion
1234  
1235 Subclass for Riverbed Steelfusion WAN optimization appliances.
1236  
1237 See documentation in L<SNMP::Info::Layer3::Steelfusion> for details.
1238  
1239 =item SNMP::Info::Layer3::Steelhead
1240  
1241 Subclass for Riverbed Steelhead WAN optimization appliances.
1242  
1243 See documentation in L<SNMP::Info::Layer3::Steelhead> for details.
1244  
1245 =item SNMP::Info::Layer3::SteelheadEx
1246  
1247 Subclass for Riverbed SteelheadEx WAN optimization appliances.
1248  
1249 See documentation in L<SNMP::Info::Layer3::SteelheadEx> for details.
1250  
1251 =item SNMP::Info::Layer3::Sun
1252  
1253 Subclass for Generic Sun Routers running SunOS.
1254  
1255 See documentation in L<SNMP::Info::Layer3::Sun> for details.
1256  
1257 =item SNMP::Info::Layer3::Tachyon
1258  
1259 Subclass for Tachyon TNA-series devices.
1260  
1261 See documentation in L<SNMP::Info::Layer3::Tachyon> for details.
1262  
1263 =item SNMP::Info::Layer3::Tasman
1264  
1265 Subclass for Avaya Secure Routers.
1266  
1267 See documentation in L<SNMP::Info::Layer3::Tasman> for details.
1268  
1269 =item SNMP::Info::Layer3::Teltonika
1270  
1271 Subclass for legacy Teltonika RUT9xx series routers.
1272  
1273 See documentation in L<SNMP::Info::Layer3::Teltonika> for details.
1274  
1275 =item SNMP::Info::Layer3::TeltonikaRutOS
1276  
1277 Subclass for Teltonika devices using the current RutOS SNMP enterprise OID
1278 layout.
1279  
1280 See documentation in L<SNMP::Info::Layer3::TeltonikaRutOS> for details.
1281  
1282 =item SNMP::Info::Layer3::Timetra
1283  
1284 Alcatel-Lucent SR Class.
1285  
1286 See documentation in L<SNMP::Info::Layer3::Timetra> for details.
1287  
1288 =item SNMP::Info::Layer3::VMware
1289  
1290 Subclass for VMware ESXi hosts.
1291  
1292 See documentation in L<SNMP::Info::Layer3::VMware> for details.
1293  
1294 =item SNMP::Info::Layer3::VOSS
1295  
1296 Subclass for Extreme VOSS / Fabric Engine switches that report the Extreme
1297 enterprise.
1298  
1299 See documentation in L<SNMP::Info::Layer3::VOSS> for details.
1300  
1301 =item SNMP::Info::Layer3::VyOS
1302  
1303 Subclass for VyOS routers.
1304  
1305 See documentation in L<SNMP::Info::Layer3::VyOS> for details.
1306  
1307 =item SNMP::Info::Layer3::Whiterabbit
1308  
1309 Subclass for whiterabbit devices.
1310  
1311 See documentation in L<SNMP::Info::Layer3::Whiterabbit> for details.
1312  
1313 =back
1314  
1315 =back
1316  
1317 =over 4
1318  
1319 =item SNMP::Info::Layer7
1320  
1321 Generic Layer7 Devices.
1322  
1323 See documentation in L<SNMP::Info::Layer7> for details.
1324  
1325 =over 4
1326  
1327 =item SNMP::Info::Layer7::APC
1328  
1329 Subclass for APC UPS devices.
1330  
1331 See documentation in L<SNMP::Info::Layer7::APC> for details.
1332  
1333 =item SNMP::Info::Layer7::Arbor
1334  
1335 Subclass for Arbor appliances.
1336  
1337 See documentation in L<SNMP::Info::Layer7::Arbor> for details.
1338  
1339 =item SNMP::Info::Layer7::CiscoIPS
1340  
1341 Subclass for Cisco IPS devices.
1342  
1343 See documentation in L<SNMP::Info::Layer7::CiscoIPS> for details.
1344  
1345 =item SNMP::Info::Layer7::Gigamon
1346  
1347 Subclass for Gigamon devices.
1348  
1349 See documentation in L<SNMP::Info::Layer7::Gigamon> for details.
1350  
1351 =item SNMP::Info::Layer7::HWGroup
1352  
1353 Subclass for HW Group devices.
1354  
1355 See documentation in L<SNMP::Info::Layer7::HWGroup> for details.
1356  
1357 =item SNMP::Info::Layer7::Liebert
1358  
1359 Subclass for Liebert devices.
1360  
1361 See documentation in L<SNMP::Info::Layer7::Liebert> for details.
1362  
1363 =item SNMP::Info::Layer7::Neoteris
1364  
1365 Subclass for Ivanti / Pulse Secure / Juniper SSL VPN appliances.
1366  
1367 See documentation in L<SNMP::Info::Layer7::Neoteris> for details.
1368  
1369 =item SNMP::Info::Layer7::Netscaler
1370  
1371 Subclass for Citrix Netscaler appliances.
1372  
1373 See documentation in L<SNMP::Info::Layer7::Netscaler> for details.
1374  
1375 =item SNMP::Info::Layer7::QNAP
1376  
1377 Subclass for QNAP NAS devices running QTS or QuTS hero. The operating-system
1378 family is reported as C<qts> or C<quts hero>.
1379  
1380 See documentation in L<SNMP::Info::Layer7::QNAP> for details.
1381  
1382 =item SNMP::Info::Layer7::Synology
1383  
1384 Subclass for Synology NAS devices running DiskStation Manager (DSM).
1385  
1386 See documentation in L<SNMP::Info::Layer7::Synology> for details.
1387  
1388 =item SNMP::Info::Layer7::Kemp
1389  
1390 Subclass for Kemp LoadMaster appliances.
1391  
1392 See documentation in L<SNMP::Info::Layer7::Kemp> for details.
1393  
1394 =item SNMP::Info::Layer7::Stormshield
1395  
1396 Subclass for Stormshield Network Security appliances.
1397  
1398 See documentation in L<SNMP::Info::Layer7::Stormshield> for details.
1399  
1400  
1401 =back
1402  
1403 =back
1404  
1405 =head1 Thanks
1406  
1407 Thanks for testing and coding help (in no particular order) to :
1408 Alexander Barthel, Andy Ford, Alexander Hartmaier, Andrew Herrick, Alex
1409 Kramarov, Bernhard Augenstein, Bradley Baetz, Brian Chow, Brian Wilson,
1410 Carlos Vicente, Dana Watanabe, David Pinkoski, David Sieborger, Douglas
1411 McKeown, Greg King, Ivan Auger, Jean-Philippe Luiggi, Jeroen van Ingen,
1412 Justin Hunter, Kent Hamilton, Matthew Tuttle, Michael Robbert, Mike Hunter,
1413 Nicolai Petri, Ralf Gross, Robert Kerr, Nick Nauwelaerts and people listed
1414 on the Netdisco README!
1415  
1416 =head1 USAGE
1417  
1418 =head2 Constructor
1419  
1420 =over
1421  
1422 =item new()
1423  
1424 Creates a new object and connects via SNMP::Session.
1425  
1426 Always returns an SNMP::Info instance, and you should always check for
1427 error() as in SYNOPSIS above to be sure of success.
1428  
1429 Will take a bare list of key/value options but we recommend a HASH ref
1430 as in the example below and SYNOPSIS, to catch syntax errors.
1431  
1432 my $info = SNMP::Info->({ 'Debug' => 1,
1433 'AutoSpecify' => 1,
1434 'BigInt' => 1,
1435 'BulkWalk' => 1,
1436 'BulkRepeaters' => 20,
1437 'LoopDetect' => 1,
1438 'IgnoreNetSNMPConf' => 1,
1439 'DestHost' => 'myrouter',
1440 'Community' => 'public',
1441 'Version' => 2,
1442 'MibDirs' => ['dir1','dir2','dir3'],
1443 });
1444  
1445 SNMP::Info Specific Arguments :
1446  
1447 =over
1448  
1449 =item AutoSpecify
1450  
1451 Returns an object of a more specific device class
1452  
1453 (default 0, which means "off")
1454  
1455 =item BigInt
1456  
1457 Return Math::BigInt objects for 64 bit counters. Sets on a global scope,
1458 not object.
1459  
1460 (default 0, which means "off")
1461  
1462 =item BulkWalk
1463  
1464 Set to C<0> to turn off BULKWALK commands for SNMPv2 connections.
1465  
1466 (default 1, which means "on")
1467  
1468 =item BulkRepeaters
1469  
1470 Set number of MaxRepeaters for BULKWALK operation. See
1471 C<perldoc SNMP> -> bulkwalk() for more info.
1472  
1473 (default 20)
1474  
1475 =item LoopDetect
1476  
1477 Detects looping during getnext table column walks by comparing IIDs for each
1478 instance. A loop is detected if the same IID is seen more than once and the
1479 walk is aborted. Note: This will not detect loops during a bulkwalk
1480 operation, Net-SNMP's internal bulkwalk function must detect the loop.
1481  
1482 Set to C<0> to turn off loop detection.
1483  
1484 (default 1, which means "on")
1485  
1486 =item BulkOrderCheck
1487  
1488 Checks that the rows a bulkwalk returns are in increasing OID order, and
1489 recovers when they are not. Set to C<0> to restore the 3.980000 behavior.
1490  
1491 When on, SNMP::Info sets the session's C<NonIncreasing> to 1 for each of its
1492 own bulkwalk calls, and restores the caller's value afterwards. A table whose
1493 rows come back out of order is walked again by GETNEXT, and that table uses
1494 GETNEXT for the rest of the object, in every later context. Later tables
1495 are unaffected, unless the object has reached its limit of failed
1496 bulkwalks (see L</BulkBackoff>). An agent that repeats the last OID of its
1497 previous reply also counts as out of order. Net-SNMP checks the order only
1498 from the second reply of a bulkwalk on, so a table that fits in one reply is
1499 never checked, and rows out of order inside the first reply are
1500 not detected.
1501  
1502 When off, SNMP::Info leaves C<NonIncreasing> as the caller set it. With it
1503 unset, Net-SNMP keeps a row only when its OID is higher than the highest OID
1504 kept so far in that walk. Any other row is dropped with no error, so the
1505 table comes back with rows missing and the walk is recorded as complete.
1506 When every row of a reply is dropped, Net-SNMP asks again from the same
1507 OID, gets the same reply, and the walk never ends.
1508  
1509 (default 1, which means "on")
1510  
1511 =item BulkBackoff
1512  
1513 Lowers the number of MaxRepeaters, and falls back to GETNEXT, when a
1514 bulkwalk fails with tooBig or times out. Set to C<0> to restore the
1515 3.980000 behavior, where such a table method returns undef.
1516  
1517 When on, the failed bulkwalk is retried with half the MaxRepeaters. When the
1518 halved value would be below C<$BACKOFF_FLOOR> (5), the table is walked by
1519 GETNEXT instead. With the default L</BulkRepeaters> of 20, the attempts are
1520 20, 10, 5 and then GETNEXT. After tooBig, the lowered value, and the switch
1521 to GETNEXT, are kept for every later table on the object. After a
1522 timeout they are kept for that table only, which starts from its lowered
1523 value, or uses GETNEXT, in every later context on the object.
1524  
1525 Before the first halving for a timeout in a VLAN, VRF or SNMPv3 context,
1526 one GETNEXT is sent for the table's first row. When it also times out, the
1527 context is taken to be unreachable, such as a VLAN community
1528 the agent ignores: the method returns undef, and the lowered value and the
1529 switch to GETNEXT are left as they were. The context is marked unreachable.
1530 Every later table in it is walked by GETNEXT without a bulkwalk or a probe,
1531 and other contexts are unaffected. A GETNEXT walk in the context that
1532 returns rows clears the mark, and later tables bulkwalk again. An
1533 unreachable context counts toward neither C<$MAX_FAILED_BULKWALKS> nor
1534 C<$SLOW_DEVICE_TABLES>. The context the object connected with is never
1535 marked and gets no probe: there the timeout is backed off as any other.
1536  
1537 A table that timed out on bulkwalk without its context being marked
1538 unreachable counts as slow. Once C<$SLOW_DEVICE_TABLES> (3) tables are slow,
1539 every later table starts at the smallest value with which one of them
1540 completed by bulkwalk, or at C<$BACKOFF_FLOOR> when none did.
1541  
1542 An object tolerates at most C<$MAX_FAILED_BULKWALKS> (9) failed
1543 bulkwalks, counting tooBig, timeouts that reach a live agent and the
1544 out-of-order failures of L</BulkOrderCheck> together. The table whose
1545 bulkwalk fails for the ninth time is walked by GETNEXT, and so is every
1546 later table on the object.
1547 Other errors, and a MIB object the device does not implement, are not
1548 retried.
1549  
1550 (default 1, which means "on")
1551  
1552 =item IncompleteWalk
1553  
1554 What a table method does when its walk ends before the whole table was read,
1555 because of a timeout, an SNMP error or a detected loop. Either way the walk is
1556 recorded, see L</Incomplete Walks>.
1557  
1558 C<'partial'> returns, and caches, the rows collected before the walk ended.
1559  
1560 C<'undef'> returns undef and caches nothing for any incomplete walk, as a
1561 failed bulkwalk that is not recovered does. This includes a getnext walk or
1562 a bulkwalk cut short by a detected loop.
1563  
1564 Any other value is treated as C<'partial'>.
1565  
1566 (default C<'partial'>. Callers that rewrite stored data from a table should
1567 set C<'undef'> rather than rely on the default.)
1568  
1569 =item IgnoreNetSNMPConf
1570  
1571 Net-SNMP version 5.0 and higher read configuration files, snmp.conf or
1572 snmp.local.conf, from /etc/snmp, /usr/share/snmp, /usr/lib(64)/snmp, or
1573 $HOME/.snmp and uses those settings to automatically parse MIB files, etc.
1574  
1575 Set to C<1> "on" to ignore Net-SNMP configuration files by overriding the
1576 C<SNMPCONFPATH> environmental variable during object initialization. Note:
1577 MibDirs must be defined or Net-SNMP will not be able to load MIBs and
1578 initialize the object.
1579  
1580 (default 0, which means "off")
1581  
1582 =item Debug
1583  
1584 Prints Lots of debugging messages.
1585 Pass 2 to print even more debugging messages.
1586  
1587 (default 0, which means "off")
1588  
1589 =item DebugSNMP
1590  
1591 Set $SNMP::debugging level for Net-SNMP.
1592  
1593 See F<SNMP> for more details.
1594  
1595 =item MibDirs
1596  
1597 Array ref to list of directories in which to look for MIBs. Note this will
1598 be in addition to the ones setup in snmp.conf at the system level.
1599  
1600 (default use net-snmp settings only)
1601  
1602 =item RetryNoSuch
1603  
1604 When using SNMP Version 1, try reading values even if they come back as "no
1605 such variable in this MIB". Set to false if so desired. This feature lets
1606 you read SNMPv2 data from an SNMP version 1 connection, and should probably
1607 be left on.
1608  
1609 (default 1, which means "on")
1610  
1611 =item Session
1612  
1613 SNMP::Session object to use instead of connecting on own.
1614  
1615 (default creates session automatically)
1616  
1617 =item Offline
1618  
1619 Causes SNMP::Info to avoid network activity and return data only from its
1620 cache. If you ask for something not in the cache, an error is thrown. See
1621 also the C<cache()> and C<offline()> methods.
1622  
1623 (default 0, which means "online")
1624  
1625 =item Cache
1626  
1627 Pass in a HashRef to prime the cache of retrieved data. Useful for creating an
1628 instance in C<Offline> mode from a previously dumped cache. See also the
1629 C<cache()> method to retrieve a cache after running actual queries.
1630  
1631 =item OTHER
1632  
1633 All other arguments are passed to SNMP::Session.
1634  
1635 See SNMP::Session for a list of other possible arguments.
1636  
1637 =back
1638  
1639 A Note about the wrong Community string or wrong SNMP Version:
1640  
1641 If a connection is using the wrong community string or the wrong SNMP version,
1642 the creation of the object will not fail. The device still answers the call
1643 on the SNMP port, but will not return information. Check the error() method
1644 after you create the device object to see if there was a problem in
1645 connecting.
1646  
1647 A note about SNMP Versions :
1648  
1649 Some older devices don't support SNMP version 2, and will not return anything
1650 when a connection under Version 2 is attempted.
1651  
1652 Some newer devices will support Version 1, but will not return all the data
1653 they might have if you had connected under Version 1.
1654  
1655 When trying to get info from a new device, you may have to try version 2 and
1656 then fallback to version 1.
1657  
1658 =cut
1659  
1660 sub new {
1661 my $proto = shift;
1662 my $class = ref($proto) || $proto;
1663 my %args = (ref $_[0] ? %{ $_[0] } : @_);
1664 my %sess_args = %args;
1665 my $new_obj = {};
1666 bless $new_obj, $class;
1667  
1668 $new_obj->{class} = $class;
1669  
1670 # load references to all the subclass data structures
1671 {
1672 no strict 'refs'; ## no critic (ProhibitNoStrict ProhibitProlongedStrictureOverride)
1673 $new_obj->{init} = \${ $class . '::INIT' };
1674 $new_obj->{mibs} = \%{ $class . '::MIBS' };
1675 $new_obj->{globals} = \%{ $class . '::GLOBALS' };
1676 $new_obj->{funcs} = \%{ $class . '::FUNCS' };
1677 $new_obj->{munge} = \%{ $class . '::MUNGE' };
1678 }
1679  
1680 # SNMP::Info specific args :
1681 if ( defined $args{Debug} ) {
1682 $new_obj->debug( $args{Debug} );
1683 delete $sess_args{Debug};
1684 }
1685 else {
1686 $new_obj->debug( defined $DEBUG ? $DEBUG : 0 );
1687 }
1688  
1689 if ( defined $args{DebugSNMP} ) {
1690 $SNMP::debugging = $args{DebugSNMP};
1691 delete $sess_args{DebugSNMP};
1692 }
1693  
1694 my $auto_specific = 0;
1695 if ( defined $args{AutoSpecify} ) {
1696 $auto_specific = $args{AutoSpecify} || 0;
1697 delete $sess_args{AutoSpecify};
1698 }
1699  
1700 if ( defined $args{BulkRepeaters} ) {
1701 $new_obj->{BulkRepeaters} = $args{BulkRepeaters};
1702 delete $sess_args{BulkRepeaters};
1703 }
1704  
1705 if ( defined $args{BulkWalk} ) {
1706 $new_obj->{BulkWalk} = $args{BulkWalk};
1707 delete $sess_args{BulkWalk};
1708 }
1709  
1710 if ( defined $args{LoopDetect} ) {
1711 $new_obj->{LoopDetect} = $args{LoopDetect};
1712 delete $sess_args{LoopDetect};
1713 }
1714  
1715 if ( defined $args{IncompleteWalk} ) {
1716 $new_obj->{IncompleteWalk} = $args{IncompleteWalk};
1717 delete $sess_args{IncompleteWalk};
1718 }
1719  
1720 foreach my $option (qw(BulkOrderCheck BulkBackoff)) {
1721 next unless defined $args{$option};
1722 $new_obj->{$option} = $args{$option};
1723 delete $sess_args{$option};
1724 }
1725  
1726 if ( defined $args{IgnoreNetSNMPConf} ) {
1727 $new_obj->{IgnoreNetSNMPConf} = $args{IgnoreNetSNMPConf} || 0;
1728 delete $sess_args{IgnoreNetSNMPConf};
1729 }
1730  
1731 if ( defined $args{Offline} ) {
1732 $new_obj->{Offline} = $args{Offline} || 0;
1733 delete $sess_args{Offline};
1734 }
1735  
1736 if ( defined $args{Cache} and ref {} eq ref $args{Cache} ) {
1737 $new_obj->{$_} = $args{Cache}->{$_} for keys %{$args{Cache}};
1738 delete $sess_args{Cache};
1739 }
1740  
1741 my $sess = undef;
1742 if ( defined $args{Session} ) {
1743 $sess = $args{Session};
1744 delete $sess_args{Session};
1745 }
1746 if ( defined $args{BigInt} ) {
1747 $BIGINT = $args{BigInt};
1748 delete $sess_args{BigInt};
1749 }
1750 if ( defined $args{MibDirs} ) {
1751 $new_obj->{mibdirs} = $args{MibDirs};
1752 delete $sess_args{MibDirs};
1753 }
1754  
1755 # For IPv6 hosts set transport
1756 if ( defined $sess_args{DestHost} ) {
1757 $sess_args{DestHost} = resolve_desthost($sess_args{DestHost});
1758 }
1759  
1760 $new_obj->{nosuch} = $args{RetryNoSuch} || $NOSUCH;
1761  
1762 # this will have the cleartext community, enable when needed
1763 #if ($args{Debug}) {
1764 # use Data::Dumper;
1765 # print "SNMP::Info::new sess_args for SNMP::Session : ", Dumper(\%sess_args);
1766 #}
1767  
1768 # Initialize mibs if not done
1769 my $init_ref = $new_obj->{init};
1770 unless ( defined $$init_ref and $$init_ref ) {
1771 $new_obj->init();
1772 $$init_ref = 1;
1773 }
1774  
1775 $new_obj->{walk_target} = _walk_target( \%args );
1776  
1777 # Connects to device unless open session is provided.
1778 $sess = SNMP::Session->new(
1779 'UseEnums' => 1,
1780 %sess_args, 'RetryNoSuch' => $new_obj->{nosuch}
1781 ) unless defined $sess;
1782  
1783 # No session object created
1784 unless ( defined $sess ) {
1785 $new_obj->error_throw("SNMP::Info::new() Net-SNMP session creation failed completely.");
1786 return $new_obj;
1787 }
1788  
1789 # Session object created but SNMP connection failed.
1790 if ($sess->{ErrorStr}) {
1791 my $sess_err = $sess->{ErrorStr} || 'no specific error';
1792 $new_obj->error_throw(
1793 "SNMP::Info::new() Net-SNMP session creation failed: $sess_err");
1794 return $new_obj;
1795 }
1796  
1797 # Save Args for later
1798 $new_obj->{store} ||= {};
1799 $new_obj->{sess} = $sess;
1800 $new_obj->{args} = \%args;
1801 $new_obj->{snmp_ver} = $sess->{Version} || $args{Version} || 2;
1802 $new_obj->{snmp_comm} = $sess->{Community} || $args{Community} || 'public';
1803 $new_obj->{snmp_user} = $sess->{SecName} || $args{SecName} || 'initial';
1804  
1805 my $info = $auto_specific ? $new_obj->specify() : $new_obj;
1806  
1807 if (defined $info and ($info->debug() > 1)) {
1808 require mro;
1809 print STDERR (ref $info) ." has resolution order: \n";
1810 print STDERR " $_\n" foreach @{ mro::get_linear_isa( ref $info ) };
1811 }
1812  
1813 return $info;
1814 }
1815  
1816 =item update()
1817  
1818 Replace the existing session with a new one with updated values,
1819 without re-identifying the device. It is meant for changes to Community
1820 or Context, which keep the walk recovery state. A change to DestHost,
1821 Version or RemotePort resets that state.
1822  
1823 Clears the object cache.
1824  
1825 This is useful, e.g., when a device supports multiple contexts
1826 (via changes to the Community string, or via the SNMPv3 Context
1827 parameter), but a context that you want to access does not support
1828 the objects (e.g., C<sysObjectID>, C<sysDescr>) that we use to identify
1829 the device.
1830  
1831 =cut
1832  
1833 sub update {
1834 my $obj = shift;
1835 my %update_args = @_;
1836 my %sess_args = ( %{ $obj->{args} }, %update_args );
1837  
1838 # silently only update "the right" args
1839 delete $sess_args{Debug};
1840 delete $sess_args{DebugSNMP};
1841 delete $sess_args{AutoSpecify};
1842 delete $sess_args{BulkRepeaters};
1843 delete $sess_args{BulkWalk};
1844 delete $sess_args{LoopDetect};
1845 delete $sess_args{IncompleteWalk};
1846 delete $sess_args{BulkOrderCheck};
1847 delete $sess_args{BulkBackoff};
1848 delete $sess_args{IgnoreNetSNMPConf};
1849 delete $sess_args{BigInt};
1850 delete $sess_args{MibDirs};
1851  
1852 my $sess = SNMP::Session->new(
1853 'UseEnums' => 1,
1854 %sess_args, 'RetryNoSuch' => $obj->{nosuch}
1855 );
1856 unless ( defined $sess ) {
1857 $obj->error_throw(
1858 "SNMP::Info::update() Failed to Create new Session. ");
1859 return;
1860 }
1861  
1862 # Session object created but SNMP connection failed.
1863 my $sess_err = $sess->{ErrorStr} || '';
1864 if ($sess_err) {
1865 $obj->error_throw(
1866 "SNMP::Info::update() Net-SNMP session creation failed. $sess_err"
1867 );
1868 return;
1869 }
1870 my $target = _walk_target( \%sess_args );
1871 $obj->{walk_recovery} = undef
1872 unless _same_target( $obj->{walk_target}, $target );
1873 $obj->{walk_target} = $target;
1874 $obj->clear_cache();
1875 return $obj->session($sess);
1876 }
1877  
1878 =back
1879  
1880 =head2 Data is Cached
1881  
1882 Methods and subroutines requesting data from a device will only load the data
1883 once, and then return cached versions of that data.
1884  
1885 Run $info->load_METHOD() where method is something like 'i_name' to reload
1886 data from a method.
1887  
1888 Run $info->clear_cache() to clear the cache to allow reload of both globals
1889 and table methods.
1890  
1891 The cache can be retrieved or set using the $info->cache() method. This works
1892 together with the C<Offline> option.
1893  
1894 =head2 Incomplete Walks
1895  
1896 Each table walk records whether it collected the whole table. A walk that
1897 ends on a timeout, an SNMP error or a detected loop is incomplete. After a
1898 failed getnext walk or a detected loop, the method returns the rows
1899 collected before the walk ended, unless the C<IncompleteWalk> option says
1900 otherwise. After a failed bulkwalk that is not recovered (see
1901 C<BulkOrderCheck> and C<BulkBackoff>) it returns undef in either mode. A
1902 recovered bulkwalk whose GETNEXT re-walk ends early counts as a failed
1903 getnext walk instead, so in C<partial> mode it returns the rows collected
1904 before then. These records and the option survive $info->clear_cache(),
1905 $info->cache() and $info->update(), and carry over to the object returned
1906 by $info->specify(). Only $info->clear_walk_status() clears the records.
1907 The records never contain the community string.
1908  
1909 The bulkwalk recovery state (see C<BulkOrderCheck> and C<BulkBackoff>) is
1910 kept the same way, except that $info->update() resets it when it changes
1911 C<DestHost>, C<Version> or C<RemotePort>.
1912  
1913 Each outcome is a reference to a hash with these keys:
1914  
1915 =over 4
1916  
1917 =item method
1918  
1919 The table method, without any C<load_>, C<orig_> or C<_raw> affix.
1920  
1921 =item leaf
1922  
1923 The qualified leaf name, or the OID when it could not be translated.
1924  
1925 =item partial
1926  
1927 The partial fetch argument given to the method, if any.
1928  
1929 =item context
1930  
1931 The SNMPv3 Context. On SNMPv1 and SNMPv2c, C<X> when the session community
1932 is the constructor's Community followed by C<@X>, such as a VLAN number or a
1933 VRF name, or C<X> followed by C<@> and the Community (C<default::20@public>).
1934 Otherwise an empty string.
1935  
1936 =item complete
1937  
1938 1 when the whole table was read, 0 otherwise.
1939  
1940 =item reason
1941  
1942 Undef for a complete walk, C<'absent'> when the object is not implemented or
1943 could not be resolved, otherwise one of C<'timeout'>, C<'loop'>, C<'toobig'>,
1944 C<'nonincreasing'> or C<'error'>. On a GET or GETNEXT, C<'absent'> means
1945 Net-SNMP could not translate the object locally and sent nothing, which is a
1946 problem with the poller's MIBs rather than a fact about the device.
1947  
1948 =item error
1949  
1950 The Net-SNMP error string of an incomplete walk or an C<'absent'> outcome.
1951  
1952 =item errornum
1953  
1954 The Net-SNMP error number at the end of the walk.
1955  
1956 =item walk
1957  
1958 C<'getnext'>, C<'bulkwalk'>, or C<'get'> when a partial fetch was answered by
1959 a single GET.
1960  
1961 =item repeaters
1962  
1963 The MaxRepeaters value of the final bulkwalk attempt, which is the lowered
1964 value after a back-off (see C<BulkBackoff>), otherwise undef.
1965  
1966 =item recovery
1967  
1968 A reference to an array of the recovery steps this walk took before its
1969 final attempt, in order, empty when there were none. Each step is a
1970 reference to a hash with the C<walk>, C<repeaters>, C<reason> and
1971 C<errornum> of the attempt that failed. With C<BulkOrderCheck> on, a
1972 bulkwalk that fails with C<'nonincreasing'> adds the step
1973 C<< { walk => 'bulkwalk', repeaters => N, reason => 'nonincreasing',
1974 errornum => -65 } >>, and the table is walked again by GETNEXT. With
1975 C<BulkBackoff> on, each bulkwalk that fails with C<'toobig'> or
1976 C<'timeout'> adds a step with the repeaters it was sent with, such as
1977 C<< { walk => 'bulkwalk', repeaters => 20, reason => 'toobig',
1978 errornum => 1 } >>, before the retry with fewer repeaters or by GETNEXT.
1979  
1980 =item rows
1981  
1982 The number of rows collected before the walk ended.
1983  
1984 =back
1985  
1986 =over
1987  
1988 =item $info->walk_status([method])
1989  
1990 Returns a reference to a hash, keyed by method, of the latest walk outcome
1991 for each table method. With a method name, returns that outcome, or undef
1992 if the method has not been walked.
1993  
1994 =cut
1995  
1996 sub walk_status {
1997 my $self = shift;
1998 my $method = shift;
1999  
2000 $self->{walk_status} ||= {};
2001 return $self->{walk_status} unless defined $method;
2002 return $self->{walk_status}{$method};
2003 }
2004  
2005 =item $info->walk_failures()
2006  
2007 Returns a reference to an array of the incomplete walk outcomes, in the
2008 order they happened. A later successful walk of the same method does not
2009 remove a failure.
2010  
2011 =cut
2012  
2013 sub walk_failures {
2014 my $self = shift;
2015 return $self->{walk_failures} ||= [];
2016 }
2017  
2018 =item $info->clear_walk_status()
2019  
2020 Clears both $info->walk_status() and $info->walk_failures().
2021  
2022 =cut
2023  
2024 sub clear_walk_status {
2025 my $self = shift;
2026 $self->{walk_status} = {};
2027 $self->{walk_failures} = [];
2028 return;
2029 }
2030  
2031 =item $info->bulkwalk_recovery()
2032  
2033 Returns a copy of what this object has learned from failed bulkwalks (see
2034 C<BulkOrderCheck> and C<BulkBackoff>), as a reference to a hash. Changing
2035 the copy does not change how later walks run. C<update()> resets the state
2036 when C<DestHost>, C<Version> or C<RemotePort> changes, and keeps it when
2037 only C<Community> or C<Context> changes. Keys may be added in later
2038 releases; ignore any you do not know.
2039  
2040 =over
2041  
2042 =item toobig_repeaters
2043  
2044 The repeaters every table starts from after a tooBig back-off, otherwise
2045 undef.
2046  
2047 =item slow_repeaters
2048  
2049 The repeaters every table starts from once C<slow_tables> reached three,
2050 otherwise undef.
2051  
2052 =item slow_tables
2053  
2054 The number of tables that needed timeout recovery.
2055  
2056 =item failed
2057  
2058 The number of failed bulkwalks, not counting those in unreachable
2059 contexts. At C<$MAX_FAILED_BULKWALKS> (9) the object stops bulkwalking.
2060  
2061 =item getnext
2062  
2063 1 when every later table is walked by GETNEXT: after the failed bulkwalk
2064 cap, or when tooBig back-off reached the floor.
2065  
2066 =item contexts
2067  
2068 A reference to a sorted array of the contexts marked unreachable, as in the
2069 C<context> of a walk outcome.
2070  
2071 =item tables
2072  
2073 A reference to a hash, keyed by qualified leaf, of what each table learned:
2074 C<repeaters>, the repeaters a timeout back-off lowered it to, or undef;
2075 C<getnext>, 1 when the table is walked by GETNEXT; C<getnext_reason>,
2076 C<'nonincreasing'> or C<'timeout'>, why it was; and C<slow>, 1 when the
2077 table needed timeout recovery.
2078  
2079 =back
2080  
2081 =cut
2082  
2083 sub bulkwalk_recovery {
2084 my $self = shift;
2085 my $state = $self->_walk_recovery();
2086 my %tables;
2087 foreach my $leaf ( keys %{ $state->{tables} } ) {
2088 my $entry = $state->{tables}{$leaf};
2089 $tables{$leaf} = {
2090 map { $_ => $entry->{$_} }
2091 qw(repeaters getnext getnext_reason slow)
2092 };
2093 }
2094 return {
2095 ( map { $_ => $state->{$_} }
2096 qw(toobig_repeaters slow_repeaters slow_tables failed getnext) ),
2097 contexts => [ sort keys %{ $state->{contexts} } ],
2098 tables => \%tables,
2099 };
2100 }
2101  
2102 =back
2103  
2104 =head2 SNMP Contexts
2105  
2106 Some devices serve part of a feature only in non-default SNMP contexts.
2107 Cisco IOS serves each VLAN's forwarding table in that VLAN's context.
2108 SNMPv2c reaches a context by a community suffix (C<public@10>), or on
2109 Extreme VOSS by a vrfid suffix (C<public::1>). SNMPv3 reaches it by a
2110 context name (C<vlan-10>).
2111  
2112 =over
2113  
2114 =item context
2115  
2116 A view of the device's MIB data that the agent serves under one name.
2117 A session reads one context at a time.
2118  
2119 =item default context
2120  
2121 The context a session reaches with the constructor's C<Community>, or
2122 with an empty SNMPv3 Context. It serves most data.
2123  
2124 =item context kind
2125  
2126 What a device's contexts stand for: C<vlan>, one context per VLAN;
2127 C<mst>, one per MST instance; C<vrf>, one per VRF.
2128  
2129 =back
2130  
2131 To read such a feature:
2132  
2133 =over
2134  
2135 =item 1.
2136  
2137 Call C<context_kinds($feature)>. Nothing means the default context
2138 serves the whole feature: read it as usual.
2139  
2140 =item 2.
2141  
2142 In the default context, list what to visit: VLAN ids from C<v_index()>
2143 for C<fdb>, tree keys from C<stp_trees()> for C<stp>, instance names from
2144 C<vrf_instances()> for C<vrf>. Keep the lists:
2145 C<update()> clears the cache on every switch.
2146  
2147 =item 3.
2148  
2149 For each one, find its contexts. For C<fdb>, call
2150 C<snmp_context('vlan', $vlan)>. For C<stp> and C<vrf>, use the
2151 record's C<contexts>, which can name a context C<snmp_context()> does
2152 not, as on Junos (L<SNMP::Info::Layer3::Juniper>). Switch with
2153 C<update()>, and read.
2154  
2155 =item 4.
2156  
2157 Call C<update()> with no arguments to return to the default context.
2158  
2159 =back
2160  
2161 A context whose C<v2c> or C<v3> is undef cannot be reached over that
2162 SNMP version. NX-OS refuses community suffixes, so its VLAN and MST
2163 contexts need SNMPv3 (L<SNMP::Info::Layer3::Nexus>).
2164  
2165 A site can map a plain community to a VRF context in the device
2166 configuration (NX-OS C<snmp-server mib community-map>). The VRF readers
2167 recognize such a session only where the class can read the mapping from
2168 the device: NX-OS (L<SNMP::Info::Layer3::Nexus>) and VOSS
2169 (L<SNMP::Info::Layer3::VOSS>). Elsewhere a community-mapped session
2170 reads as the default context, so read VRF contexts over SNMPv3. See
2171 L<SNMP::Info::VRF/"Reading Instances">.
2172  
2173 The examples below switch with this helper. C<kind> C<none> is the
2174 default context.
2175  
2176 # Switch to $context; false where this session's SNMP version cannot
2177 # reach it
2178 sub enter_context {
2179 my ( $info, $context, $community ) = @_;
2180  
2181 return $info->update() if $context->{kind} eq 'none';
2182 if ( $info->snmp_ver() == 3 ) {
2183 return unless defined $context->{v3};
2184 return $info->update( Context => $context->{v3} );
2185 }
2186 return unless defined $context->{v2c};
2187 return $info->update(
2188 Community => sprintf( $context->{v2c}, $community ) );
2189 }
2190  
2191 my $community = $info->snmp_comm(); # before the first switch
2192  
2193 Forwarding table, per VLAN where the device needs it:
2194  
2195 my %fw_mac; # VLAN => { iid => MAC }, or 'all' => { ... }
2196 if ( $info->context_kinds('fdb') ) {
2197 my @vlans = sort { $a <=> $b } values %{ $info->v_index() || {} };
2198 foreach my $vlan (@vlans) {
2199 my $context = $info->snmp_context( 'vlan', $vlan ) or next;
2200 enter_context( $info, $context, $community ) or next;
2201 $fw_mac{$vlan} = { %{ $info->fw_mac() || {} } };
2202 }
2203 $info->update();
2204 }
2205 else {
2206 $fw_mac{all} = { %{ $info->fw_mac() || {} } };
2207 }
2208  
2209 MST instance ports. NX-OS serves each instance in its own C<mst-N>
2210 context. IOS serves it in the context of each VLAN the instance carries,
2211 and VLAN 1 in the default context, so the rows of every listed context
2212 are merged (L<SNMP::Info::CiscoStpExtensions>). The SYNOPSIS of
2213 L<SNMP::Info::Bridge> reads every tree the same way:
2214  
2215 my $trees = $info->stp_trees() || {};
2216 my $switch = $info->context_kinds('stp');
2217 my %msti_ports; # tree key => { iid => port record }
2218 my @mstis = grep { $trees->{$_}{type} eq 'msti' } sort keys %$trees;
2219 foreach my $key (@mstis) {
2220 unless ($switch) {
2221 $msti_ports{$key} = { %{ $info->stp_tree_ports($key) || {} } };
2222 next;
2223 }
2224 foreach my $context ( @{ $trees->{$key}{contexts} } ) {
2225 enter_context( $info, $context, $community ) or next;
2226 my $ports = $info->stp_tree_ports($key) || {};
2227 $msti_ports{$key}{$_} = $ports->{$_} foreach keys %$ports;
2228 }
2229 }
2230 $info->update() if $switch;
2231  
2232 Per-VRF neighbors. Where the device reads each VRF in its own context,
2233 switch to it; otherwise read every VRF in the default context:
2234  
2235 # Where the device lists no VRF, as EXOS, pass vrf_instances(\@names)
2236 my $instances = $info->vrf_instances() || {};
2237 my %vrf_neighbors; # VRF name => { iid => neighbor record }
2238 foreach my $name ( sort keys %$instances ) {
2239 if ( $info->context_kinds('vrf') and $name ne 'default' ) {
2240 # No context: the device gives this instance none to read in
2241 my $context = $instances->{$name}{contexts}[0] or next;
2242 enter_context( $info, $context, $community ) or next;
2243 $vrf_neighbors{$name}
2244 = { %{ $info->vrf_neighbors($name) || {} } };
2245 $info->update();
2246 next;
2247 }
2248 $vrf_neighbors{$name} = { %{ $info->vrf_neighbors($name) || {} } };
2249 }
2250  
2251 =head3 For Class Authors
2252  
2253 A device class answers C<context_kinds()> and C<snmp_context()> through
2254 two private hooks, since a role such as L<SNMP::Info::Bridge> sits behind
2255 SNMP::Info in every class's method resolution and cannot override them:
2256  
2257 =over
2258  
2259 =item C<_context_kinds($feature)>
2260  
2261 Returns the C<context_kinds()> answer for C<$feature>: a reference to an
2262 array of kinds, or nothing. C<context_kinds('fdb')> returns C<['vlan']>
2263 without calling it where C<cisco_comm_indexing()> is true
2264 (L<SNMP::Info::Layer3::CiscoSwitch>). See L<SNMP::Info::Layer3::Nexus>
2265 for a class that answers several features.
2266  
2267 =item C<_snmp_context($kind, $id)>
2268  
2269 Returns the C<snmp_context()> record, or nothing where the device has no
2270 such context (L<SNMP::Info::Layer3::Juniper>).
2271  
2272 =back
2273  
2274 =head2 Object Scalar Methods
2275  
2276 These are for package related data, not directly supplied
2277 from SNMP.
2278  
2279 =over
2280  
2281 =item $info->clear_cache()
2282  
2283 Clears the cached data. This includes GLOBALS data and TABLE METHOD data.
2284  
2285 =cut
2286  
2287 sub clear_cache {
2288 my $self = shift;
2289  
2290 print "SNMP::Info::clear_cache() - Cache Cleared.\n" if $self->debug();
2291  
2292 # Clear cached global values and table method flag for being cached
2293 foreach my $key ( keys %$self ) {
2294 next unless defined $key;
2295 next unless $key =~ /^_/;
2296 delete $self->{$key};
2297 }
2298  
2299 # Clear store for tables
2300 return $self->store( {} );
2301  
2302 }
2303  
2304 =item $info->debug(1)
2305  
2306 Returns current debug status, and optionally toggles debugging info for this
2307 object.
2308  
2309 =cut
2310  
2311 sub debug {
2312 my $self = shift;
2313 my $debug = shift;
2314  
2315 if ( defined $debug ) {
2316 $self->{debug} = $debug;
2317 }
2318  
2319 return $self->{debug};
2320 }
2321  
2322 =item $info->offline([1|0])
2323  
2324 Returns if offline mode is currently turned on for this object.
2325  
2326 Optionally sets the Offline parameter.
2327  
2328 =cut
2329  
2330 sub offline {
2331 my $self = shift;
2332 my $ol = shift;
2333  
2334 if ( defined $ol ) {
2335 $self->{Offline} = $ol;
2336 }
2337 return $self->{Offline};
2338 }
2339  
2340 =item $info->cache([new_cache])
2341  
2342 Returns a HashRef of all cached data in this object. There will be a C<store>
2343 key for table data and then one key for each leaf.
2344  
2345 Optionally sets the cache parameters if passed a HashRef.
2346  
2347 =cut
2348  
2349 sub cache {
2350 my $self = shift;
2351 my $data = shift;
2352  
2353 if ( defined $data and ref {} eq ref $data ) {
2354 $self->{$_} = $data->{$_} for keys %$data;
2355 }
2356  
2357 my $cache = { store => $self->{store} };
2358 foreach my $key ( keys %$self ) {
2359 next unless defined $key;
2360 next unless $key =~ /^_/;
2361 $cache->{$key} = $self->{$key};
2362 }
2363 return $cache;
2364 }
2365  
2366 =item $info->bulkwalk([1|0])
2367  
2368 Returns if bulkwalk is currently turned on for this object.
2369  
2370 Optionally sets the bulkwalk parameter.
2371  
2372 =cut
2373  
2374 sub bulkwalk {
2375 my $self = shift;
2376 my $bw = shift;
2377  
2378 if ( defined $bw ) {
2379 $self->{BulkWalk} = $bw;
2380 }
2381 return $self->{BulkWalk};
2382 }
2383  
2384 =item $info->loopdetect([1|0])
2385  
2386 Returns if loopdetect is currently turned on for this object.
2387  
2388 Optionally sets the loopdetect parameter.
2389  
2390 =cut
2391  
2392 sub loopdetect {
2393 my $self = shift;
2394 my $ld = shift;
2395  
2396 if ( defined $ld ) {
2397 $self->{LoopDetect} = $ld;
2398 }
2399 return $self->{LoopDetect};
2400 }
2401  
2402 =item $info->bulk_order_check([1|0])
2403  
2404 Returns whether the C<BulkOrderCheck> option is on for this object, 1 unless
2405 set to a false value. Optionally sets it. C<0> restores the 3.980000
2406 behavior.
2407  
2408 =cut
2409  
2410 sub bulk_order_check {
2411 my $self = shift;
2412 my $check = shift;
2413  
2414 $self->{BulkOrderCheck} = $check if defined $check;
2415 return ( defined $self->{BulkOrderCheck} and !$self->{BulkOrderCheck} )
2416 ? 0
2417 : 1;
2418 }
2419  
2420 =item $info->bulk_backoff([1|0])
2421  
2422 Returns whether the C<BulkBackoff> option is on for this object, 1 unless
2423 set to a false value. Optionally sets it. C<0> restores the 3.980000
2424 behavior.
2425  
2426 =cut
2427  
2428 sub bulk_backoff {
2429 my $self = shift;
2430 my $backoff = shift;
2431  
2432 $self->{BulkBackoff} = $backoff if defined $backoff;
2433 return ( defined $self->{BulkBackoff} and !$self->{BulkBackoff} )
2434 ? 0
2435 : 1;
2436 }
2437  
2438 =item $info->incomplete_walk(['partial'|'undef'])
2439  
2440 Returns the C<IncompleteWalk> mode of this object, C<'partial'> when unset or
2441 set to any other value. Optionally sets the mode. See the C<IncompleteWalk>
2442 constructor option.
2443  
2444 =cut
2445  
2446 sub incomplete_walk {
2447 my $self = shift;
2448 my $mode = shift;
2449  
2450 $self->{IncompleteWalk} = $mode if defined $mode;
2451 return ( $self->{IncompleteWalk} || '' ) eq 'undef' ? 'undef' : 'partial';
2452 }
2453  
2454 =item $info->device_type()
2455  
2456 Returns the Subclass name for this device. C<SNMP::Info> is returned if no
2457 more specific class is available.
2458  
2459 First the device is checked for Layer 3 support and a specific subclass,
2460 then Layer 2 support and subclasses are checked.
2461  
2462 This means that Layer 2 / 3 switches and routers will fall under the
2463 SNMP::Info::Layer3 subclasses.
2464  
2465 If the device still can be connected to via SNMP::Info, then
2466 SNMP::Info is returned.
2467  
2468 =cut
2469  
2470 sub device_type {
2471 my $info = shift;
2472  
2473 my $objtype = "SNMP::Info";
2474  
2475 my $layers = $info->layers() || '00000000';
2476  
2477 my $desc = $info->description() || 'undef';
2478 $desc =~ s/[\r\n\l]+/ /g;
2479  
2480 # Some devices don't implement sysServices, but do return a description.
2481 # In that case, log a warning and continue.
2482 if ( $layers eq '00000000' ) {
2483 if ($desc ne 'undef') {
2484 carp("Device doesn't implement sysServices but did return sysDescr. Might give unexpected results.\n") if $info->debug();
2485 } else {
2486 # No sysServices, no sysDescr
2487 return;
2488 }
2489 }
2490  
2491 my $id = $info->id() || 'undef';
2492 my $soid = $id;
2493  
2494 # Ruckus controller product branches are distinct from the AP branch.
2495 return 'SNMP::Info::Layer3::RuckusController'
2496 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.25053\.3\.1\.(?:10|11)(?:\.|$)/;
2497  
2498 # Hash for generic fallback to a device class if unable to determine using
2499 # the sysDescr regex.
2500 my %l3sysoidmap = (
2501 9 => 'SNMP::Info::Layer3::CiscoSwitch',
2502 11 => 'SNMP::Info::Layer2::HP',
2503 18 => 'SNMP::Info::Layer3::BayRS',
2504 42 => 'SNMP::Info::Layer3::Sun',
2505 43 => 'SNMP::Info::Layer2::3Com',
2506 45 => 'SNMP::Info::Layer2::Baystack',
2507 96 => 'SNMP::Info::Layer3::Whiterabbit',
2508 171 => 'SNMP::Info::Layer3::DLink',
2509 207 => 'SNMP::Info::Layer2::Allied',
2510 244 => 'SNMP::Info::Layer3::Lantronix',
2511 311 => 'SNMP::Info::Layer3::Microsoft',
2512 664 => 'SNMP::Info::Layer2::Adtran',
2513 674 => 'SNMP::Info::Layer3::Dell',
2514 1588 => 'SNMP::Info::Layer3::Foundry',
2515 1872 => 'SNMP::Info::Layer3::AlteonAD',
2516 1890 => 'SNMP::Info::Layer3::Redlion',
2517 1916 => 'SNMP::Info::Layer3::Extreme',
2518 1991 => 'SNMP::Info::Layer3::Foundry',
2519 2011 => 'SNMP::Info::Layer3::Huawei',
2520 2021 => 'SNMP::Info::Layer3::NetSNMP',
2521 2272 => 'SNMP::Info::Layer3::Passport',
2522 2356 => 'SNMP::Info::Layer3::Lancom',
2523 2604 => 'SNMP::Info::Layer3::Sophos',
2524 2620 => 'SNMP::Info::Layer3::CheckPoint',
2525 2636 => 'SNMP::Info::Layer3::Juniper',
2526 2925 => 'SNMP::Info::Layer1::Cyclades',
2527 3076 => 'SNMP::Info::Layer3::Altiga',
2528 3224 => 'SNMP::Info::Layer3::Netscreen',
2529 3375 => 'SNMP::Info::Layer3::F5',
2530 3417 => 'SNMP::Info::Layer3::BlueCoatSG',
2531 3717 => 'SNMP::Info::Layer3::Genua',
2532 4413 => 'SNMP::Info::Layer2::Ubiquiti',
2533 4526 => 'SNMP::Info::Layer2::Netgear',
2534 4874 => 'SNMP::Info::Layer3::ERX',
2535 5624 => 'SNMP::Info::Layer3::Enterasys',
2536 6027 => 'SNMP::Info::Layer3::Force10',
2537 6141 => 'SNMP::Info::Layer3::Ciena',
2538 6486 => 'SNMP::Info::Layer3::AlcatelLucent',
2539 6527 => 'SNMP::Info::Layer3::Timetra',
2540 6876 => 'SNMP::Info::Layer3::VMware',
2541 8072 => 'SNMP::Info::Layer3::NetSNMP',
2542 9303 => 'SNMP::Info::Layer3::PacketFront',
2543 10002 => 'SNMP::Info::Layer2::Ubiquiti',
2544 10418 => 'SNMP::Info::Layer1::Cyclades',
2545 11256 => 'SNMP::Info::Layer7::Stormshield',
2546 12196 => 'SNMP::Info::Layer7::Kemp',
2547 12276 => 'SNMP::Info::Layer3::F5OS',
2548 12325 => 'SNMP::Info::Layer3::Pf',
2549 12356 => 'SNMP::Info::Layer3::Fortinet',
2550 13191 => 'SNMP::Info::Layer3::OneAccess',
2551 14179 => 'SNMP::Info::Layer2::Airespace',
2552 14525 => 'SNMP::Info::Layer2::Trapeze',
2553 14823 => 'SNMP::Info::Layer3::Aruba',
2554 14988 => 'SNMP::Info::Layer3::Mikrotik',
2555 17163 => 'SNMP::Info::Layer3::Steelhead',
2556 17713 => 'SNMP::Info::Layer3::Cambium',
2557 19046 => 'SNMP::Info::Layer3::Lenovo',
2558 21091 => 'SNMP::Info::Layer2::Exinda',
2559 23867 => 'SNMP::Info::Layer3::SilverPeak',
2560 25461 => 'SNMP::Info::Layer3::PaloAlto',
2561 25506 => 'SNMP::Info::Layer3::H3C',
2562 26543 => 'SNMP::Info::Layer3::IBMGbTor',
2563 26928 => 'SNMP::Info::Layer2::Aerohive',
2564 29671 => 'SNMP::Info::Layer3::Meraki',
2565 30065 => 'SNMP::Info::Layer3::Arista',
2566 30803 => 'SNMP::Info::Layer3::VyOS',
2567 35098 => 'SNMP::Info::Layer3::Pica8',
2568 40310 => 'SNMP::Info::Layer3::Cumulus',
2569 41112 => 'SNMP::Info::Layer2::Ubiquiti',
2570 44641 => 'SNMP::Info::Layer3::VyOS',
2571 46242 => 'SNMP::Info::Layer3::Netonix',
2572 47196 => 'SNMP::Info::Layer3::ArubaCX',
2573 48690 => 'SNMP::Info::Layer3::Teltonika',
2574 );
2575  
2576 my %l2sysoidmap = (
2577 9 => 'SNMP::Info::Layer2::Cisco',
2578 11 => 'SNMP::Info::Layer2::HP',
2579 43 => 'SNMP::Info::Layer2::3Com',
2580 45 => 'SNMP::Info::Layer2::Baystack',
2581 96 => 'SNMP::Info::Layer3::Whiterabbit',
2582 171 => 'SNMP::Info::Layer3::DLink',
2583 207 => 'SNMP::Info::Layer2::Allied',
2584 248 => 'SNMP::Info::Layer2::Hirschmann',
2585 266 => 'SNMP::Info::Layer2::Nexans',
2586 664 => 'SNMP::Info::Layer2::Adtran',
2587 674 => 'SNMP::Info::Layer3::Dell',
2588 1872 => 'SNMP::Info::Layer3::AlteonAD',
2589 1890 => 'SNMP::Info::Layer3::Redlion',
2590 1916 => 'SNMP::Info::Layer3::Extreme',
2591 1991 => 'SNMP::Info::Layer3::Foundry',
2592 2011 => 'SNMP::Info::Layer3::Huawei',
2593 2272 => 'SNMP::Info::Layer3::Passport',
2594 2925 => 'SNMP::Info::Layer1::Cyclades',
2595 3181 => 'SNMP::Info::Layer2::Microsens',
2596 3224 => 'SNMP::Info::Layer3::Netscreen',
2597 3375 => 'SNMP::Info::Layer3::F5',
2598 4526 => 'SNMP::Info::Layer2::Netgear',
2599 5624 => 'SNMP::Info::Layer3::Enterasys',
2600 6141 => 'SNMP::Info::Layer3::Ciena',
2601 6486 => 'SNMP::Info::Layer3::AlcatelLucent',
2602 9303 => 'SNMP::Info::Layer3::PacketFront',
2603 10418 => 'SNMP::Info::Layer1::Cyclades',
2604 11863 => 'SNMP::Info::Layer2::TPLink',
2605 11898 => 'SNMP::Info::Layer2::Orinoco',
2606 13458 => 'SNMP::Info::Layer2::Atmedia',
2607 14179 => 'SNMP::Info::Layer2::Airespace',
2608 14525 => 'SNMP::Info::Layer2::Trapeze',
2609 14823 => 'SNMP::Info::Layer3::Aruba',
2610 17163 => 'SNMP::Info::Layer3::Steelhead',
2611 17713 => 'SNMP::Info::Layer3::Cambium',
2612 20540 => 'SNMP::Info::Layer2::Sixnet',
2613 21091 => 'SNMP::Info::Layer2::Exinda',
2614 26543 => 'SNMP::Info::Layer3::IBMGbTor',
2615 26928 => 'SNMP::Info::Layer2::Aerohive',
2616 46242 => 'SNMP::Info::Layer3::Netonix',
2617 47196 => 'SNMP::Info::Layer3::ArubaCX',
2618 48690 => 'SNMP::Info::Layer3::Teltonika',
2619 );
2620  
2621 my %l1sysoidmap = (
2622 2925 => 'SNMP::Info::Layer1::Cyclades',
2623 10418 => 'SNMP::Info::Layer1::Cyclades',
2624 );
2625  
2626 my %l7sysoidmap = (
2627 318 => 'SNMP::Info::Layer7::APC',
2628 476 => 'SNMP::Info::Layer7::Liebert',
2629 5951 => 'SNMP::Info::Layer7::Netscaler',
2630 9694 => 'SNMP::Info::Layer7::Arbor',
2631 11256 => 'SNMP::Info::Layer7::Stormshield',
2632 12196 => 'SNMP::Info::Layer7::Kemp',
2633 12532 => 'SNMP::Info::Layer7::Neoteris',
2634 14525 => 'SNMP::Info::Layer2::Trapeze',
2635 21796 => 'SNMP::Info::Layer7::HWGroup',
2636 24681 => 'SNMP::Info::Layer7::QNAP',
2637 26866 => 'SNMP::Info::Layer7::Gigamon',
2638 55062 => 'SNMP::Info::Layer7::QNAP',
2639 );
2640  
2641 # Get just the enterprise number for generic mapping
2642 $id = $1 if ( defined($id) && $id =~ /^\.1\.3\.6\.1\.4\.1\.(\d+)/ );
2643  
2644 if ($info->debug()) {
2645 print "SNMP::Info $VERSION\n";
2646 print "SNMP::Info::device_type() layers:$layers id:$id sysDescr:\"$desc\"\n";
2647 }
2648  
2649 # Ruckus access points use a generic sysDescr and may not implement
2650 # sysServices, so identify their registered product OIDs directly.
2651 return 'SNMP::Info::Layer2::RuckusAP'
2652 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.25053\.3\.1\.[1-4]\.\d+$/;
2653  
2654 # Unleashed APs report a null or ZoneDirector sysObjectID, and an R850
2655 # shares 25053.3.1.5.15 with the ZD1200. Their sysDescr names the AP
2656 # model, where a ZoneDirector's names "ZD" and four digits.
2657 return 'SNMP::Info::Layer2::RuckusAP'
2658 if $desc =~ /^Ruckus Wireless [A-Z]\d{3}/;
2659  
2660 # FortiAPs register under 12356.120 and serve no sysServices; the rest
2661 # of the enterprise keeps Layer3::Fortinet.
2662 return 'SNMP::Info::Layer2::FortiAP'
2663 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.12356\.120(?:\.|$)/;
2664  
2665 # Tachyon TNA radios register under 57344.1 and may not implement
2666 # sysServices; the TNS switches under 57344.2 keep the generic classes.
2667 return 'SNMP::Info::Layer3::Tachyon'
2668 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.57344\.1(?:\.|$)/;
2669  
2670 # SONiC reports a fixed sysServices of 72 and, by distribution, Net-SNMP's,
2671 # Dell's or Broadcom's sysObjectID, so only sysDescr identifies it. Some
2672 # releases wrap sysDescr in double quotes.
2673 return 'SNMP::Info::Layer3::SONiC'
2674 if $desc =~ /^"?SONiC Software Version:/;
2675  
2676 # Teltonika devices commonly report Net-SNMP's generic sysObjectID, so
2677 # identify current RutOS devices by the product code in Teltonika's
2678 # enterprise tree. Legacy RUT9xx detection remains in the enterprise maps
2679 # and sysDescr checks below. TSW212 switches report the PROFINET
2680 # enterprise (24686, PROFIBUS Nutzerorganisation) instead; other PROFINET
2681 # devices share it, so probe only when sysDescr names a TSW switch.
2682 if (
2683 defined($id)
2684 && ( $soid eq '.1.3.6.1.4.1.8072.3.2.10'
2685 || $id eq '48690'
2686 || ( $soid eq '.1.3.6.1.4.1.24686' && $desc =~ /^TSW\d/ ) )
2687 )
2688 {
2689 my $product_code
2690 = _global( 'teltonika_model', '.1.3.6.1.4.1.48690.1.3.0' )->($info)
2691 // '';
2692 if ( $product_code =~ /^(?:RUT[A-Z]{0,2}|TRB|OTD|TCR|TSW|TAP)\d/i ) {
2693 print "SNMP::Info::device_type() detected Teltonika RutOS "
2694 . "product:$product_code\n"
2695 if $info->debug();
2696 return 'SNMP::Info::Layer3::TeltonikaRutOS';
2697 }
2698 }
2699  
2700 # LigoDLB radios report a generic enterprise sysObjectID and sysServices
2701 # that does not identify them as a Layer 2 device. Match their product
2702 # description before the generic layer-based fallbacks.
2703 if ( defined $id and $id eq '32750' and $desc =~ /^LigoDLB\b/i ) {
2704 return 'SNMP::Info::Layer2::LigoWave';
2705 }
2706  
2707 # Layer 3 Supported
2708 # (usually has layer2 as well, so we check for 3 first)
2709 if ( $info->has_layer(3) ) {
2710 $objtype = 'SNMP::Info::Layer3';
2711  
2712 # Device Type Overrides
2713  
2714 return $objtype unless ( defined $desc and length($desc) );
2715  
2716 $objtype = 'SNMP::Info::Layer3::C1300' if $desc =~ /Catalyst 1300 Series Managed Switch/;
2717 $objtype = 'SNMP::Info::Layer3::C3550' if $desc =~ /(C3550|C3560)/;
2718 $objtype = 'SNMP::Info::Layer3::C4000' if $desc =~ /Catalyst 4[05]00/;
2719 $objtype = 'SNMP::Info::Layer3::Foundry' if $desc =~ /foundry/i;
2720 $objtype = 'SNMP::Info::Layer3::ERX' if $desc =~ /erx/i;
2721  
2722 # Aironet - older non-IOS
2723 $objtype = 'SNMP::Info::Layer3::Aironet'
2724 if ($desc =~ /Cisco/
2725 and $desc =~ /\D(CAP340|AP340|CAP350|350|1200)\D/ );
2726 $objtype = 'SNMP::Info::Layer3::Aironet'
2727 if ( $desc =~ /Aironet/ and $desc =~ /\D(AP4800)\D/ );
2728  
2729 # Override voice gateway device (VG350) showing up as Aironet
2730 $objtype = 'SNMP::Info::Layer3::Cisco' if $desc =~ /VG350/;
2731  
2732 # Cat6k with older SUPs (hybrid CatOS/IOS?)
2733 $objtype = 'SNMP::Info::Layer3::C6500' if $desc =~ /(c6sup2|c6sup1)/;
2734  
2735 # Cat6k with Sup720, Sup720 or Sup2T (and Sup2 running native IOS?)
2736 $objtype = 'SNMP::Info::Layer3::C6500'
2737 if $desc =~ /(s72033_rp|s3223_rp|s32p3_rp|s222_rp|s2t54)/;
2738  
2739 # Next one untested. Reported working by DA
2740 $objtype = 'SNMP::Info::Layer3::C6500'
2741 if ( $desc =~ /cisco/i and $desc =~ /3750/ );
2742  
2743 # IOS 15.x on Catalyst 3850
2744 $objtype = 'SNMP::Info::Layer3::C6500'
2745 if ( $desc =~ /cisco/i and $desc =~ /CAT3K/ );
2746  
2747 # Cisco 2970
2748 $objtype = 'SNMP::Info::Layer3::C6500'
2749 if ( $desc =~ /(C2970|C2960)/ );
2750  
2751 # Cisco 3400 w/ Layer3 capable image
2752 $objtype = 'SNMP::Info::Layer3::C3550'
2753 if ( $desc =~ /(ME340x)/ );
2754  
2755 # Various Cisco blade switches, CBS30x0 and CBS31x0 models
2756 $objtype = 'SNMP::Info::Layer3::C6500'
2757 if ( $desc =~ /cisco/i and $desc =~ /CBS3[0-9A-Za-z]{3}/ );
2758  
2759 # Cisco Nexus running NX-OS
2760 $objtype = 'SNMP::Info::Layer3::Nexus'
2761 if ( $desc =~ /^Cisco\s+NX-OS/ );
2762  
2763 # HP, older ProCurve models (1600, 2400, 2424m, 4000, 8000)
2764 $objtype = 'SNMP::Info::Layer2::HP4000'
2765 if $desc =~ /\b(J4093A|J4110A|J4120A|J4121A|J4122A|J4122B)\b/;
2766  
2767 # HP, Foundry OEM
2768 $objtype = 'SNMP::Info::Layer3::HP9300'
2769 if $desc =~ /\b(J4874A|J4138A|J4139A|J4840A|J4841A)\b/;
2770  
2771 # Nortel ERS (Passport) 1600 Series < version 2.1
2772 $objtype = 'SNMP::Info::Layer3::N1600'
2773 if $desc =~ /(Passport|Ethernet\s+Routing\s+Switch)-16/i;
2774  
2775 # ERS - BayStack Numbered
2776 $objtype = 'SNMP::Info::Layer2::Baystack'
2777 if ( $desc
2778 =~ /^(BayStack|Ethernet\s+Routing\s+Switch)\s[2345](\d){2,3}/i );
2779  
2780 # Nortel Contivity
2781 $objtype = 'SNMP::Info::Layer3::Contivity'
2782 if $desc =~ /(\bCES\b|\bNVR\sV\d)/
2783 and (!defined $id or !defined $l3sysoidmap{$id});
2784  
2785 # SonicWALL
2786 $objtype = 'SNMP::Info::Layer3::SonicWALL' if $desc =~ /SonicWALL/i;
2787  
2788 # Allied Telesis Layer2 managed switches. They report they have L3 support
2789 $objtype = 'SNMP::Info::Layer2::Allied'
2790 if ( $desc =~ /Allied.*AT-80\d{2}\S*/i );
2791  
2792 # Cisco ASA, newer versions which report layer 3 functionality
2793 # version >= 8.2 are known to do this
2794 $objtype = 'SNMP::Info::Layer3::CiscoASA'
2795 if ( $desc =~ /Cisco Adaptive Security Appliance/i );
2796  
2797 # Cisco FTD includes an ASA running as lina process
2798 $objtype = 'SNMP::Info::Layer3::CiscoASA'
2799 if ( $desc =~ /Cisco Firepower Threat Defense/i );
2800  
2801 # Cisco FWSM
2802 $objtype = 'SNMP::Info::Layer3::CiscoFWSM'
2803 if ( $desc =~ /Cisco Firewall Services Module/i );
2804  
2805 # Cisco Small Business (300 500) series override
2806 # This is for enterprises(1).cisco(9).otherEnterprises(6).ciscosb(1)
2807 $objtype = 'SNMP::Info::Layer2::CiscoSB'
2808 if ( $soid =~ /^\.?1\.3\.6\.1\.4\.1\.9\.6\.1/ );
2809  
2810 # Extreme WiNG APs (formerly Motorola)
2811 $objtype = 'SNMP::Info::Layer3::ExtremeWing'
2812 if ( $soid =~ /^\.?1\.3\.6\.1\.4\.1\.388\.50/ );
2813  
2814 # Avaya Secure Router
2815 $objtype = 'SNMP::Info::Layer3::Tasman'
2816 if ( $desc =~ /^(avaya|nortel)\s+(SR|secure\srouter)\s+\d{4}/i );
2817  
2818 # HP Virtual Connect blade switches
2819 $objtype = 'SNMP::Info::Layer2::HPVC'
2820 if ( $desc =~ /HP\sVC\s/ );
2821  
2822 # Aironet - IOS
2823 # Starting with IOS 15, Aironet reports sysServices 6, even though
2824 # it still is the same layer2 access point.
2825 $objtype = 'SNMP::Info::Layer2::Aironet'
2826 if ($desc =~ /\b(C1100|C1130|C1140|AP1200|C350|C1200|C1240|C1250|C2700|C3700)\b/
2827 and $desc =~ /\bIOS\b/ );
2828  
2829 # Airespace (WLC) Module
2830 $objtype = 'SNMP::Info::Layer2::Airespace'
2831 if ( $desc =~ /^Cisco Controller$/ );
2832  
2833 # Cisco Catalyst 9800 Wireless Controller
2834 $objtype = 'SNMP::Info::Layer3::C9800'
2835 if ( $desc =~ /^Cisco IOS Software.*\b(?:CW9800|C9800(?:-[A-Z0-9]+)?) Software\b/i );
2836  
2837 #Nortel 2270
2838 $objtype = 'SNMP::Info::Layer2::N2270'
2839 if (
2840 $desc =~ /Nortel\s+(Networks\s+)??WLAN\s+-\s+Security\s+Switch/ );
2841  
2842 # Nortel (Trapeze) WSS 2300 Series
2843 $objtype = 'SNMP::Info::Layer2::NWSS2300'
2844 if (
2845 $desc =~ /^(Nortel\s)??Wireless\sSecurity\sSwitch\s23[568][012]\b/);
2846
2847 # Siemens Simatic Scalance
2848 # Scalance overwrites layers later,
2849 # so if we don't add it here (layer3) and at other
2850 # it would flip/flop between those
2851 $objtype = 'SNMP::Info::Layer3::Scalance'
2852 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.4329\.6\.1\.2/i );
2853  
2854 # Siemens automation devices which identify themselves in sysDescr.
2855 # Keep Scalance on its dedicated class above; Siemens PLCs, SIMOCODE
2856 # devices, drives, HMIs, and soft starters use this fallback.
2857 $objtype = 'SNMP::Info::Layer3::Siemens'
2858 if ( $desc =~ /^Siemens,?\s*(?:SIMATIC\s+(?:S7|HMI)\b|SIMOCODE\b|SINAMICS\b|Soft\s+starter\b)/i );
2859  
2860 # Aruba wireless switches (issue #403)
2861 $objtype = 'SNMP::Info::Layer3::Aruba'
2862 if ( $desc =~ /ArubaOS/ );
2863  
2864 # Teltonika RUT9xx Series
2865 $objtype = 'SNMP::Info::Layer3::Teltonika'
2866 if (
2867 $desc =~ /\bTeltonika.*RUT9\d{2}\b/);
2868  
2869 # Riverbed Steelfusion
2870 $objtype = 'SNMP::Info::Layer3::SteelheadEx'
2871 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.17163\.1\.51/i );
2872 $objtype = 'SNMP::Info::Layer3::Steelfusion'
2873 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.17163\.1\.52/i );
2874  
2875 # Whiterabbit Timing
2876 $objtype = 'SNMP::Info::Layer3::Whiterabbit'
2877 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.96\.100\.1000/i );
2878  
2879 # Broadcom Edge Switches
2880 $objtype = 'SNMP::Info::Layer3::EdgeSwitch'
2881 if ( $desc =~ /^EFOS/ and $soid =~ /\.1\.3\.6\.1\.4\.1\.4413/i );
2882  
2883 # Generic device classification based upon sysObjectID
2884 if ( ( $objtype eq 'SNMP::Info::Layer3' )
2885 and ( defined($id) )
2886 and ( exists( $l3sysoidmap{$id} ) ) )
2887 {
2888 $objtype = $l3sysoidmap{$id};
2889 }
2890 # Layer 2 Supported
2891 }
2892 elsif ( $info->has_layer(2) ) {
2893 $objtype = 'SNMP::Info::Layer2';
2894  
2895 return $objtype unless ( defined $desc and $desc !~ /^\s*$/ );
2896  
2897 # Device Type Overrides
2898  
2899 # Bay Hub (Needed here for layers override)
2900 $objtype = 'SNMP::Info::Layer1::Bayhub'
2901 if ( $desc =~ /\bNMM.*Agent/ );
2902 $objtype = 'SNMP::Info::Layer1::Bayhub'
2903 if ( $desc =~ /\bBay\s*Stack.*Hub/i );
2904  
2905 # Synoptics Hub (Needed here for layers override)
2906 # This will override Bay Hub only for specific devices supported
2907 # by this class
2908 $objtype = 'SNMP::Info::Layer1::S3000'
2909 if ( $desc =~ /\bNMM\s+(281|3000|3030)/i );
2910  
2911 # Catalyst 1900 series override
2912 $objtype = 'SNMP::Info::Layer2::C1900'
2913 if ( $desc =~ /catalyst/i and $desc =~ /\D19\d{2}/ );
2914  
2915 # Catalyst 2900 and 3500XL (IOS) series override
2916 $objtype = 'SNMP::Info::Layer2::C2900'
2917 if ( $desc =~ /(C2900XL|C2950|C3500XL|C2940|CGESM|CIGESM)/i );
2918  
2919 # Catalyst WS-C series override 2926,4k,5k,6k in Hybrid
2920 $objtype = 'SNMP::Info::Layer2::Catalyst' if ( $desc =~ /WS-C\d{4}/ );
2921  
2922 # Catalyst 3550 / 3548 Layer2 only switches
2923 # Cisco 3400 w/ MetroBase Image
2924 $objtype = 'SNMP::Info::Layer3::C3550'
2925 if ( $desc =~ /(C3550|ME340x)/ );
2926  
2927 # Cisco blade switches, CBS30x0 and CBS31x0 models with L2 only
2928 $objtype = 'SNMP::Info::Layer3::C6500'
2929 if ( $desc =~ /cisco/i and $desc =~ /CBS3[0-9A-Za-z]{3}/ );
2930  
2931 # Cisco 2970
2932 $objtype = 'SNMP::Info::Layer3::C6500'
2933 if ( $desc =~ /(C2970|C2960)/ );
2934  
2935 # Cisco Small Business (300 500) series override
2936 # This is for enterprises(1).cisco(9).otherEnterprises(6).ciscosb(1)
2937 $objtype = 'SNMP::Info::Layer2::CiscoSB'
2938 if ( $soid =~ /^\.1\.3\.6\.1\.4\.1\.9\.6\.1/ );
2939  
2940 # HP, older ProCurve models (1600, 2400, 2424m, 4000, 8000)
2941 $objtype = 'SNMP::Info::Layer2::HP4000'
2942 if $desc =~ /\b(J4093A|J4110A|J4120A|J4121A|J4122A|J4122B)\b/;
2943  
2944 # HP, Foundry OEM
2945 $objtype = 'SNMP::Info::Layer3::HP9300'
2946 if $desc =~ /\b(J4874A|J4138A|J4139A|J4840A|J4841A)\b/;
2947  
2948 # IBM BladeCenter 4-Port GB Ethernet Switch Module
2949 $objtype = 'SNMP::Info::Layer3::Dell'
2950 if ( $desc =~ /^IBM Gigabit Ethernet Switch Module$/ );
2951  
2952 # Linksys 2024/2048
2953 $objtype = 'SNMP::Info::Layer3::Dell'
2954 if (
2955 $desc =~ /^(24|48)-Port 10\/100\/1000 Gigabit Switch (with |w\/)WebView$/ );
2956  
2957 # Centillion ATM
2958 $objtype = 'SNMP::Info::Layer2::Centillion' if ( $desc =~ /MCP/ );
2959  
2960 # BPS
2961 $objtype = 'SNMP::Info::Layer2::Baystack'
2962 if ( $desc =~ /Business\sPolicy\sSwitch/i );
2963  
2964 # BayStack Numbered
2965 $objtype = 'SNMP::Info::Layer2::Baystack'
2966 if ( $desc
2967 =~ /^(BayStack|Ethernet\s+(Routing\s+)??Switch)\s[2345](\d){2,3}/i
2968 );
2969  
2970 # Kentrox DataSMART DSU/CSU
2971 $objtype = 'SNMP::Info::Layer2::Kentrox'
2972 if ( $desc =~ /^DataSMART/i );
2973  
2974 # Nortel Business Ethernet Switch
2975 $objtype = 'SNMP::Info::Layer2::Baystack'
2976 if ( $desc =~ /^Business Ethernet Switch\s[12]\d\d/i );
2977  
2978 # Nortel AP 222X
2979 $objtype = 'SNMP::Info::Layer2::NAP222x'
2980 if ( $desc =~ /Access\s+Point\s+222/ );
2981  
2982 # Orinoco
2983 $objtype = 'SNMP::Info::Layer2::Orinoco'
2984 if ( $desc =~ /(AP-\d{3}|WavePOINT)/ );
2985  
2986 # Aironet - IOS
2987 $objtype = 'SNMP::Info::Layer2::Aironet'
2988 if ($desc =~ /\b(C1100|C1130|C1140|AP1200|C350|C1200|C1240|C1250)\b/
2989 and $desc =~ /\bIOS\b/ );
2990  
2991 # Aironet - non IOS
2992 $objtype = 'SNMP::Info::Layer3::Aironet'
2993 if ( $desc =~ /Cisco/ and $desc =~ /\D(BR500)\D/ );
2994  
2995 # Airespace (WLC) Module
2996 $objtype = 'SNMP::Info::Layer2::Airespace'
2997 if ( $desc =~ /^Cisco Controller$/ );
2998  
2999 # Cisco Catalyst 9800 Wireless Controller
3000 $objtype = 'SNMP::Info::Layer3::C9800'
3001 if ( $desc =~ /^Cisco IOS Software.*\b(?:CW9800|C9800(?:-[A-Z0-9]+)?) Software\b/i );
3002  
3003 #Nortel 2270
3004 $objtype = 'SNMP::Info::Layer2::N2270'
3005 if (
3006 $desc =~ /Nortel\s+(Networks\s+)??WLAN\s+-\s+Security\s+Switch/ );
3007  
3008 # HP Virtual Connect blade switches
3009 $objtype = 'SNMP::Info::Layer2::HPVC'
3010 if ( $desc =~ /HP\sVC\s/ );
3011  
3012 $objtype = 'SNMP::Info::Layer2::ZyXEL_DSLAM'
3013 if ( $desc =~ /8-port .DSL Module\(Annex .\)/i );
3014  
3015 # Generic DOCSIS Cable Modem override
3016 # If sysDescr follows the DOCSIS standard
3017 $objtype = 'SNMP::Info::DocsisCM'
3018 if ( $desc =~ /<<HW_REV: .*; VENDOR: .*; BOOTR: .*; SW_REV: .*; MODEL: .*>>/i);
3019  
3020 # Generic device classification based upon sysObjectID
3021 if ( ( $objtype eq 'SNMP::Info::Layer2' )
3022 and ( defined($id) )
3023 and ( exists( $l2sysoidmap{$id} ) ) )
3024 {
3025 $objtype = $l2sysoidmap{$id};
3026 }
3027  
3028 }
3029 elsif ( $info->has_layer(1) ) {
3030 $objtype = 'SNMP::Info::Layer1';
3031  
3032 # Allied crap-o-hub
3033 $objtype = 'SNMP::Info::Layer1::Allied' if ( $desc =~ /allied/i );
3034 $objtype = 'SNMP::Info::Layer1::Asante' if ( $desc =~ /asante/i );
3035  
3036 # Bay Hub
3037 $objtype = 'SNMP::Info::Layer1::Bayhub'
3038 if ( $desc =~ /\bNMM.*Agent/ );
3039 $objtype = 'SNMP::Info::Layer1::Bayhub'
3040 if ( $desc =~ /\bBay\s*Stack.*Hub/i );
3041  
3042 # Synoptics Hub
3043 # This will override Bay Hub only for specific devices supported
3044 # by this class
3045 $objtype = 'SNMP::Info::Layer1::S3000'
3046 if ( $desc =~ /\bNMM\s+(281|3000|3030)/i );
3047  
3048 # Generic device classification based upon sysObjectID
3049 if ( ( $objtype eq 'SNMP::Info::Layer1' )
3050 and ( defined($id) )
3051 and ( exists( $l1sysoidmap{$id} ) ) )
3052 {
3053 $objtype = $l1sysoidmap{$id};
3054 }
3055 }
3056 # These devices don't claim to have Layer1-3 but we like em anyways.
3057 else {
3058 $objtype = 'SNMP::Info::Layer2::ZyXEL_DSLAM'
3059 if ( $desc =~ /8-port .DSL Module\(Annex .\)/i );
3060  
3061 # Aruba wireless switches
3062 $objtype = 'SNMP::Info::Layer3::Aruba'
3063 if ( $desc =~ /(ArubaOS|AirOS)/ );
3064  
3065 # Alcatel-Lucent branded Aruba
3066 $objtype = 'SNMP::Info::Layer3::Aruba'
3067 if ( $desc =~ /^AOS-W/ );
3068  
3069 # Cisco PIX
3070 $objtype = 'SNMP::Info::Layer3::Cisco'
3071 if ( $desc =~ /Cisco PIX Security Appliance/i );
3072  
3073 # Cisco ASA, older version which doesn't report layer 3 functionality
3074 $objtype = 'SNMP::Info::Layer3::CiscoASA'
3075 if ( $desc =~ /Cisco Adaptive Security Appliance/i );
3076  
3077 # HP Virtual Connect blade switches
3078 $objtype = 'SNMP::Info::Layer2::HPVC'
3079 if ( $desc =~ /HP\sVC\s/ );
3080  
3081 # Nortel (Trapeze) WSS 2300 Series
3082 $objtype = 'SNMP::Info::Layer2::NWSS2300'
3083 if (
3084 $desc =~ /^(Nortel\s)??Wireless\sSecurity\sSwitch\s23[568][012]\b/);
3085  
3086 # Cisco IPS, older version which doesn't report layer 3 functionality
3087 $objtype = 'SNMP::Info::Layer7::CiscoIPS'
3088 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.9\.1\.1545/i );
3089  
3090 # Siemens Simatic Scalance
3091 # Scalance overwrites layers later,
3092 # so if we don't add it here (layer3) and at other
3093 # it would flip/flop between those
3094 $objtype = 'SNMP::Info::Layer3::Scalance'
3095 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.4329\.6\.1\.2/i );
3096  
3097 # Siemens automation devices which identify themselves in sysDescr.
3098 # Keep Scalance on its dedicated class above; Siemens PLCs, SIMOCODE
3099 # devices, drives, HMIs, and soft starters use this fallback.
3100 $objtype = 'SNMP::Info::Layer3::Siemens'
3101 if ( $desc =~ /^Siemens,?\s*(?:SIMATIC\s+(?:S7|HMI)\b|SIMOCODE\b|SINAMICS\b|Soft\s+starter\b)/i );
3102
3103 # Whiterabbit Timing
3104 $objtype = 'SNMP::Info::Layer3::Whiterabbit'
3105 if ( $soid =~ /\.1\.3\.6\.1\.4\.1\.96\.100\.1000/i );
3106  
3107 # Teltonika RUT9xx Series
3108 $objtype = 'SNMP::Info::Layer3::Teltonika'
3109 if (
3110 $desc =~ /\bTeltonika.*RUT9\d{2}\b/);
3111  
3112 # D-Link DGS switches without sysServices, such as the DGS-F3008P,
3113 # which also reports a sysObjectID outside D-Link's enterprise
3114 $objtype = 'SNMP::Info::Layer3::DLink'
3115 if ( $desc =~ /^D-Link\s+DGS-/i );
3116  
3117 # DSM uses a generic Linux sysDescr and commonly uses Net-SNMP's
3118 # generic Linux sysObjectID. Probe one DSM-specific scalar only for
3119 # those devices or Synology's own enterprise.
3120 if (
3121 $soid
3122 =~ /^\.?1\.3\.6\.1\.4\.1\.(?:6574(?:\.|$)|8072\.3\.2\.10$)/
3123 )
3124 {
3125 my $version = _global('synology_ver', '.1.3.6.1.4.1.6574.1.5.3.0')->($info) // '';
3126 $objtype = 'SNMP::Info::Layer7::Synology'
3127 if $version =~ /^\s*DSM\s+\S+/i;
3128 }
3129  
3130 # Generic device classification based upon sysObjectID
3131 if ( defined($id) and $objtype eq 'SNMP::Info') {
3132 if ( defined $l3sysoidmap{$id} ) {
3133 $objtype = $l3sysoidmap{$id};
3134 } elsif ( defined $l2sysoidmap{$id}) {
3135 $objtype = $l2sysoidmap{$id};
3136 } elsif ( defined $l7sysoidmap{$id}) {
3137 $objtype = $l7sysoidmap{$id};
3138 } elsif ($info->has_layer(7)) {
3139 $objtype = 'SNMP::Info::Layer7'
3140 }
3141 }
3142 }
3143  
3144 # switchXFamily also contains InfiniBand switches and gateways.
3145 $objtype = 'SNMP::Info::Layer3::Onyx'
3146 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.33049\.1\.1\.1\./
3147 && $desc =~ /^Onyx,/i;
3148  
3149 # Extreme VOSS / Fabric Engine report "<model> (a.b.c.d)" under the
3150 # Extreme enterprise. Layer 2 only devices reach here too, so this sits
3151 # after the layer branches. VOSS reporting the Avaya enterprise stays
3152 # with Passport
3153 $objtype = 'SNMP::Info::Layer3::VOSS'
3154 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.1916\./
3155 && $desc =~ /^\S+\s+\(\d+(?:\.\d+){3}/;
3156  
3157 # Instant APs use AI-AP-MIB, not the mobility controller WLAN tables.
3158 # Restrict this initial support to the 8.x evidence in issue #536.
3159 $objtype = 'SNMP::Info::Layer3::ArubaInstant'
3160 if $soid =~ /^\.?1\.3\.6\.1\.4\.1\.14823\.1\.2\.\d+$/
3161 && $desc =~ /(?:ArubaOS|AOS-8).*Version\s+8\./;
3162  
3163 return $objtype;
3164 }
3165  
3166 =item $info->error(no_clear)
3167  
3168 Returns Error message if there is an error, or undef if there is not.
3169  
3170 Reading the error will clear the error unless you set the no_clear flag.
3171  
3172 =cut
3173  
3174 sub error {
3175 my $self = shift;
3176 my $no_clear = shift;
3177 my $err = $self->{error};
3178  
3179 $self->{error} = undef unless defined $no_clear and $no_clear;
3180 return $err;
3181 }
3182  
3183 =item $info->has_layer(3)
3184  
3185 Returns non-zero if the device has the supplied layer in the OSI Model
3186  
3187 Returns if the device doesn't support the layers() call.
3188  
3189 =cut
3190  
3191 sub has_layer {
3192 my $self = shift;
3193 my $check_for = shift;
3194  
3195 my $layers = $self->layers();
3196 return unless defined $layers;
3197 return unless length($layers);
3198 return substr( $layers, 8 - $check_for, 1 );
3199 }
3200  
3201 =item $info->snmp_comm()
3202  
3203 Returns SNMP Community string used in connection.
3204  
3205 =cut
3206  
3207 sub snmp_comm {
3208 my $self = shift;
3209 if ( $self->{snmp_ver} == 3 ) {
3210 return $self->{snmp_user};
3211 }
3212 else {
3213 return $self->{snmp_comm};
3214 }
3215 }
3216  
3217 =item $info->snmp_ver()
3218  
3219 Returns SNMP Version used for this connection
3220  
3221 =cut
3222  
3223 sub snmp_ver {
3224 my $self = shift;
3225 return $self->{snmp_ver};
3226 }
3227  
3228 =item $info->specify()
3229  
3230 Returns an object of a more-specific subclass.
3231  
3232 my $info = new SNMP::Info(...);
3233 # Returns more specific object type
3234 my $specific = $info->specify();
3235  
3236 Usually this method is called internally from new(AutoSpecify => 1)
3237  
3238 See device_type() entry for how a subclass is chosen.
3239  
3240 =cut
3241  
3242 sub specify {
3243 my $self = shift;
3244  
3245 my $device_type = $self->device_type();
3246 unless ( defined $device_type ) {
3247 $self->error_throw(
3248 "SNMP::Info::specify() - fatal error: connect failed or missing sysServices and/or sysDescr");
3249 return $self;
3250 }
3251 return $self if $device_type eq 'SNMP::Info';
3252  
3253 # Load Subclass
3254 # By evaling a string the contents of device_type now becomes a bareword.
3255 eval "require $device_type;"; ## no critic
3256 if ($@) {
3257 croak "SNMP::Info::specify() Loading $device_type Failed. $@\n";
3258 }
3259  
3260 my $args = $self->args();
3261 my $session = $self->session();
3262 my $sub_obj = $device_type->new(
3263 %$args,
3264 'Session' => $session,
3265 'AutoSpecify' => 0
3266 );
3267  
3268 unless ( defined $sub_obj ) {
3269 $self->error_throw(
3270 "SNMP::Info::specify() - Could not connect with new class ($device_type)"
3271 );
3272 return $self;
3273 }
3274  
3275 $sub_obj->{walk_status} = $self->{walk_status};
3276 $sub_obj->{walk_failures} = $self->{walk_failures};
3277 $sub_obj->{IncompleteWalk} = $self->{IncompleteWalk};
3278 $sub_obj->{walk_recovery} = $self->{walk_recovery};
3279 $sub_obj->{walk_target} = $self->{walk_target};
3280 $sub_obj->{BulkOrderCheck} = $self->{BulkOrderCheck};
3281 $sub_obj->{BulkBackoff} = $self->{BulkBackoff};
3282  
3283 $self->debug()
3284 and print "SNMP::Info::specify() - Changed Class to $device_type.\n";
3285  
3286 return $sub_obj;
3287 }
3288  
3289 =item $info->cisco_comm_indexing()
3290  
3291 Returns 0. Is an overridable method used for vlan indexing for
3292 snmp calls on certain Cisco devices.
3293  
3294 See L<ftp://ftp.cisco.com/pub/mibs/supportlists/wsc5000/wsc5000-communityIndexing.html>
3295  
3296 To ask the same of any feature, use C<context_kinds()>.
3297  
3298 =cut
3299  
3300 sub cisco_comm_indexing {
3301 return 0;
3302 }
3303  
3304 =item $info->context_kinds($feature)
3305  
3306 Returns a reference to an array of the kinds of SNMP context the device
3307 uses to serve C<$feature>, or nothing when the default context serves it
3308 all. See L</"SNMP Contexts">.
3309  
3310 Features: C<fdb>, the forwarding table (C<fw_mac()>, C<fw_port()>);
3311 C<stp>, the spanning tree ports (C<stp_tree_ports()>); C<vrf>, the
3312 per-instance readers of L<SNMP::Info::VRF>.
3313  
3314 Kinds: C<vlan>, one context per VLAN; C<mst>, one context per MST
3315 instance; C<vrf>, one context per VRF. The answer names kinds of context,
3316 not the trees or VLANs the device has now. It can change when the device
3317 changes protocol: L<SNMP::Info::Layer3::Juniper> answers for C<stp> only
3318 while VSTP runs.
3319  
3320 if (my $kinds = $info->context_kinds('fdb')) {
3321 # Read the forwarding table once per VLAN
3322 }
3323  
3324 =cut
3325  
3326 # A feature role sits behind SNMP::Info in every class's method
3327 # resolution, so classes answer through _context_kinds and _snmp_context.
3328 sub context_kinds {
3329 my ( $self, $feature ) = @_;
3330  
3331 return unless defined $feature;
3332 return ['vlan'] if $feature eq 'fdb' and $self->cisco_comm_indexing();
3333 return $self->_context_kinds($feature) if $self->can('_context_kinds');
3334 return;
3335 }
3336  
3337 =item $info->snmp_context($kind, $id)
3338  
3339 Returns how to reach one SNMP context on this device, as a reference to
3340 hash, or nothing where the device has no such context. C<$kind> is a
3341 kind from C<context_kinds()>; C<$id> is a VLAN id for C<vlan>, an MST
3342 instance for C<mst> and a VRF name from C<vrf_instances()> for C<vrf>.
3343 See L</"SNMP Contexts">.
3344  
3345 my $context = $info->snmp_context('vlan', 10);
3346 # { kind => 'vlan', id => 10, v2c => '%s@10', v3 => 'vlan-10' }
3347  
3348 =over
3349  
3350 =item C<kind>, C<id>
3351  
3352 As passed.
3353  
3354 =item C<v2c>
3355  
3356 A C<sprintf> format for the SNMPv2c community: C<sprintf($context-E<gt>{v2c},
3357 'public')> gives C<public@10>. Undef where SNMPv2c cannot reach the
3358 context.
3359  
3360 =item C<v3>
3361  
3362 The SNMPv3 context name. Undef where SNMPv3 cannot reach the context.
3363 The device answers only for the names its configuration binds. Where a
3364 site binds other names, pass those to C<update(Context =E<gt> ...)>
3365 instead.
3366  
3367 =back
3368  
3369 =cut
3370  
3371 sub snmp_context {
3372 my $self = shift;
3373  
3374 return $self->_snmp_context(@_) if $self->can('_snmp_context');
3375 return;
3376 }
3377  
3378 =back
3379  
3380 =head2 GLOBALS (Scalar Methods)
3381  
3382 These are methods to return scalar data from RFC1213.
3383  
3384 Some subset of these is probably available for any network device that speaks
3385 SNMP.
3386  
3387 =over
3388  
3389 =item $info->uptime()
3390  
3391 Uptime in hundredths of seconds since device became available.
3392  
3393 (C<sysUpTime>)
3394  
3395 =item $info->contact()
3396  
3397 (C<sysContact>)
3398  
3399 =item $info->name()
3400  
3401 (C<sysName>)
3402  
3403 =item $info->location()
3404  
3405 (C<sysLocation>)
3406  
3407 =item $info->layers()
3408  
3409 This returns a binary encoded string where each
3410 digit represents a layer of the OSI model served
3411 by the device.
3412  
3413 eg: 01000010 means layers 2 (physical) and 7 (Application)
3414 are served.
3415  
3416 Note: This string is 8 digits long.
3417  
3418 See $info->has_layer()
3419  
3420 (C<sysServices>)
3421  
3422 =item $info->ports()
3423  
3424 Number of interfaces available on this device.
3425  
3426 Not too useful as the number of SNMP interfaces usually does not
3427 correspond with the number of physical ports
3428  
3429 (C<ifNumber>)
3430  
3431 =item $info->ipforwarding()
3432  
3433 The indication of whether the entity is acting as an IP gateway
3434  
3435 Returns either forwarding or not-forwarding
3436  
3437 (C<ipForwarding>)
3438  
3439 =back
3440  
3441 =head2 Table Methods
3442  
3443 Each of these methods returns a hash_reference to a hash keyed on the
3444 interface index in SNMP.
3445  
3446 Example : $info->interfaces() might return
3447  
3448 { '1.12' => 'FastEthernet/0',
3449 '2.15' => 'FastEthernet/1',
3450 '9.99' => 'FastEthernet/2'
3451 }
3452  
3453 The key is what you would see if you were to do an snmpwalk, and in some cases
3454 changes between reboots of the network device.
3455  
3456 =head2 Partial Table Fetches
3457  
3458 If you want to get only a part of an SNMP table or a single instance from the
3459 table and you know the IID for the part of the table that you want, you can
3460 specify it in the call:
3461  
3462 $local_routes = $info->ipr_route('192.168.0');
3463  
3464 This will only fetch entries in the table that start with C<192.168.0>, which
3465 in this case are routes on the local network.
3466  
3467 Remember that you must supply the partial IID (a numeric OID).
3468  
3469 Partial table results are not cached.
3470  
3471 =head2 Interface Information
3472  
3473 =over
3474  
3475 =item $info->interfaces()
3476  
3477 This methods is overridden in each subclass to provide a
3478 mapping between the Interface Table Index (iid) and the physical port name.
3479  
3480 =item $info->if_ignore()
3481  
3482 Returns a reference to a hash where key values that exist are
3483 interfaces to ignore.
3484  
3485 Ignored interfaces are ones that are usually not physical ports or Virtual
3486 Lans (VLANs) such as the Loopback interface, or the CPU interface.
3487  
3488 =cut
3489  
3490 sub if_ignore {
3491 my %nothing;
3492 return \%nothing;
3493 }
3494  
3495 =item $info->bulkwalk_no()
3496  
3497 Returns 0. Is an overridable method used for turn off bulkwalk for the
3498 device class.
3499  
3500 =cut
3501  
3502 sub bulkwalk_no {
3503 return 0;
3504 }
3505  
3506 =item $info->i_index()
3507  
3508 Default SNMP IID to Interface index.
3509  
3510 (C<ifIndex>)
3511  
3512 =item $info->i_description()
3513  
3514 Description of the interface. Usually a little longer single word name that is
3515 both human and machine friendly. Not always.
3516  
3517 (C<ifDescr>)
3518  
3519 =item $info->i_type()
3520  
3521 Interface type, such as Vlan, Ethernet, Serial
3522  
3523 (C<ifType>)
3524  
3525 =item $info->i_mtu()
3526  
3527 INTEGER. Interface MTU value.
3528  
3529 (C<ifMtu>)
3530  
3531 =item $info->i_speed()
3532  
3533 Speed of the link, human format. See munge_speed() later in document for
3534 details.
3535  
3536 (C<ifSpeed>, C<ifHighSpeed> if necessary)
3537  
3538 =cut
3539  
3540 sub i_speed {
3541 my $info = shift;
3542 my $partial = shift;
3543  
3544 my $i_speed = $info->orig_i_speed($partial);
3545  
3546 my $i_speed_high = undef;
3547 foreach my $i ( keys %$i_speed ) {
3548 if ( $i_speed->{$i} eq "4294967295" ) {
3549 $i_speed_high = $info->i_speed_high($partial)
3550 unless defined($i_speed_high);
3551 $i_speed->{$i} = $i_speed_high->{$i} if ( $i_speed_high->{$i} );
3552 }
3553 }
3554 return $i_speed;
3555 }
3556  
3557 =item $info->i_speed_raw()
3558  
3559 Speed of the link in bits per second without munging.
3560 If i_speed_high is available it will be used and multiplied by 1_000_000.
3561  
3562 (C<ifSpeed>, C<ifHighSpeed> if necessary)
3563  
3564 =cut
3565  
3566 sub i_speed_raw {
3567 my $info = shift;
3568 my $partial = shift;
3569  
3570 # remove the speed formatting
3571 my $munge_i_speed = delete $info->{munge}{i_speed};
3572 # also for highspeed interfaces e.g. TenGigabitEthernet
3573 my $munge_i_speed_high = delete $info->{munge}{i_speed_high};
3574  
3575 my $i_speed_raw = $info->orig_i_speed($partial);
3576  
3577 my $i_speed_high = undef;
3578 foreach my $i ( keys %$i_speed_raw ) {
3579 if ( $i_speed_raw->{$i} eq "4294967295" ) {
3580 $i_speed_high = $info->i_speed_high($partial)
3581 unless defined($i_speed_high);
3582 $i_speed_raw->{$i} = ( $i_speed_high->{$i} * 1_000_000 )
3583 if ( $i_speed_high->{$i} );
3584 }
3585 }
3586  
3587 # restore the speed formatting
3588 $info->{munge}{i_speed} = $munge_i_speed;
3589 $info->{munge}{i_speed_high} = $munge_i_speed_high;
3590  
3591 return $i_speed_raw;
3592 }
3593  
3594 =item $info->i_speed_high()
3595  
3596 Speed of a high-speed link, human format. See munge_highspeed() later in
3597 document for details. You should not need to call this directly, as
3598 i_speed() will call it if it needs to.
3599  
3600 (C<ifHighSpeed>)
3601  
3602 =item $info->i_mac()
3603  
3604 MAC address of the interface. Note this is just the MAC of the port, not
3605 anything connected to it.
3606  
3607 (C<ifPhysAddress>)
3608  
3609 =item $info->i_up()
3610  
3611 Link Status of the interface. Typical values are 'up' and 'down'.
3612  
3613 (C<ifOperStatus>)
3614  
3615 =item $info->i_up_admin()
3616  
3617 Administrative status of the port. Typical values are 'enabled' and 'disabled'.
3618  
3619 (C<ifAdminStatus>)
3620  
3621 =item $info->i_lastchange()
3622  
3623 The value of C<sysUpTime> when this port last changed states (up,down).
3624  
3625 (C<ifLastChange>)
3626  
3627 =item $info->i_name()
3628  
3629 Interface Name field. Supported by a smaller subset of devices, this fields
3630 is often human set.
3631  
3632 (C<ifName>)
3633  
3634 =item $info->i_alias()
3635  
3636 Interface Name field. For certain devices this is a more human friendly form
3637 of i_description(). For others it is a human set field like i_name().
3638  
3639 (C<ifAlias>)
3640  
3641 =back
3642  
3643 =head2 Interface Statistics
3644  
3645 =over
3646  
3647 =item $info->i_octet_in(), $info->i_octet_out(),
3648 $info->i_octet_in64(), $info->i_octet_out64()
3649  
3650 Bandwidth.
3651  
3652 Number of octets sent/received on the interface including framing characters.
3653  
3654 64 bit version may not exist on all devices.
3655  
3656 NOTE: To manipulate 64 bit counters you need to use Math::BigInt, since the
3657 values are too large for a normal Perl scalar. Set the global
3658 $SNMP::Info::BIGINT to 1 , or pass the BigInt value to new() if you want
3659 SNMP::Info to do it for you.
3660  
3661  
3662 (C<ifInOctets>) (C<ifOutOctets>)
3663 (C<ifHCInOctets>) (C<ifHCOutOctets>)
3664  
3665 =item $info->i_errors_in(), $info->i_errors_out()
3666  
3667 Number of packets that contained an error preventing delivery. See C<IF-MIB>
3668 for more info.
3669  
3670 (C<ifInErrors>) (C<ifOutErrors>)
3671  
3672 =item $info->i_pkts_ucast_in(), $info->i_pkts_ucast_out(),
3673 $info->i_pkts_ucast_in64(), $info->i_pkts_ucast_out64()
3674  
3675 Number of packets not sent to a multicast or broadcast address.
3676  
3677 64 bit version may not exist on all devices.
3678  
3679 (C<ifInUcastPkts>) (C<ifOutUcastPkts>)
3680 (C<ifHCInUcastPkts>) (C<ifHCOutUcastPkts>)
3681  
3682 =item $info->i_pkts_nucast_in(), $info->i_pkts_nucast_out(),
3683  
3684 Number of packets sent to a multicast or broadcast address.
3685  
3686 These methods are deprecated by i_pkts_multi_in() and i_pkts_bcast_in()
3687 according to C<IF-MIB>. Actual device usage may vary.
3688  
3689 (C<ifInNUcastPkts>) (C<ifOutNUcastPkts>)
3690  
3691 =item $info->i_pkts_multi_in() $info->i_pkts_multi_out(),
3692 $info->i_pkts_multi_in64(), $info->i_pkts_multi_out64()
3693  
3694 Number of packets sent to a multicast address.
3695  
3696 64 bit version may not exist on all devices.
3697  
3698 (C<ifInMulticastPkts>) (C<ifOutMulticastPkts>)
3699 (C<ifHCInMulticastPkts>) (C<ifHCOutMulticastPkts>)
3700  
3701 =item $info->i_pkts_bcast_in() $info->i_pkts_bcast_out(),
3702 $info->i_pkts_bcast_in64() $info->i_pkts_bcast_out64()
3703  
3704 Number of packets sent to a broadcast address on an interface.
3705  
3706 64 bit version may not exist on all devices.
3707  
3708 (C<ifInBroadcastPkts>) (C<ifOutBroadcastPkts>)
3709 (C<ifHCInBroadcastPkts>) (C<ifHCOutBroadcastPkts>)
3710  
3711 =item $info->i_discards_in() $info->i_discards_out()
3712  
3713 "The number of inbound packets which were chosen to be discarded even though
3714 no errors had been detected to prevent their being deliverable to a
3715 higher-layer protocol. One possible reason for discarding such a packet could
3716 be to free up buffer space." (C<IF-MIB>)
3717  
3718 (C<ifInDiscards>) (C<ifOutDiscards>)
3719  
3720 =item $info->i_bad_proto_in()
3721  
3722 "For packet-oriented interfaces, the number of packets received via the
3723 interface which were discarded because of an unknown or unsupported protocol.
3724 For character-oriented or fixed-length interfaces that support protocol
3725 multiplexing the number of transmission units received via the interface which
3726 were discarded because of an unknown or unsupported protocol. For any
3727 interface that does not support protocol multiplexing, this counter will always
3728 be 0."
3729  
3730 (C<ifInUnknownProtos>)
3731  
3732 =item $info->i_qlen_out()
3733  
3734 "The length of the output packet queue (in packets)."
3735  
3736 (C<ifOutQLen>)
3737  
3738 =item $info->i_specific()
3739  
3740 See C<IF-MIB> for full description
3741  
3742 (C<ifSpecific>)
3743  
3744 =back
3745  
3746 =head2 IPv4 Address Table
3747  
3748 Each entry in this table is an IPv4 address in use on this device. Usually
3749 this is implemented in Layer3 Devices. These methods try the deprecated IPv4
3750 address table C<IP-MIB::ipAddrTable> first due to its prevalence and will try
3751 the current C<IP-MIB::ipAddressTable> if it doesn't return any results.
3752 C<IP-MIB::ipAddressTable> results are filtered to only return IPv4 unicast
3753 addresses and modified to match the return format of the older table for
3754 backwards compatibility.
3755  
3756 See documentation in L<SNMP::Info::IPv6> for IPv6 Address Table.
3757  
3758 =over
3759  
3760 =item $info->ip_index()
3761  
3762 Maps the IPv4 addresses to the interface index
3763  
3764 (C<ipAdEntIfIndex>) or filtered and index modified (C<ipAddressIfIndex>)
3765  
3766 =item $info->ip_table()
3767  
3768 Maps the Table to the IPv4 address
3769  
3770 (C<ipAdEntAddr>) or address extracted from (C<ipAddressIfIndex>)
3771  
3772 =item $info->ip_netmask()
3773  
3774 Gives netmask setting for IPv4 table entry.
3775  
3776 (C<ipAdEntNetMask>) or netmask calculated from (C<ipAddressPrefix>)
3777  
3778 =item $info->ip_broadcast()
3779  
3780 Gives the value of the least-significant bit in the IPv4 broadcast address
3781 either 1 or 0.
3782  
3783 (C<ipAdEntBcastAddr>), there is no equivalent from the
3784 C<IP-MIB::ipAddressTable>
3785  
3786 =back
3787  
3788 =head2 IP Routing Table
3789  
3790 =over
3791  
3792 =item $info->ipr_route()
3793  
3794 The route in question. A value of 0.0.0.0 is the default gateway route.
3795  
3796 (C<ipRouteDest>)
3797  
3798 =item $info->ipr_if()
3799  
3800 The interface (IID) that the route is on. Use interfaces() to map.
3801  
3802 (C<ipRouteIfIndex>)
3803  
3804 =item $info->ipr_1()
3805  
3806 Primary routing metric for this route.
3807  
3808 (C<ipRouteMetric1>)
3809  
3810 =item $info->ipr_2()
3811  
3812 If metrics are not used, they should be set to -1
3813  
3814 (C<ipRouteMetric2>)
3815  
3816 =item $info->ipr_3()
3817  
3818 (C<ipRouteMetric3>)
3819  
3820 =item $info->ipr_4()
3821  
3822 (C<ipRouteMetric4>)
3823  
3824 =item $info->ipr_5()
3825  
3826 (C<ipRouteMetric5>)
3827  
3828 =item $info->ipr_dest()
3829  
3830 From RFC1213:
3831  
3832 "The IP address of the next hop of this route.
3833 (In the case of a route bound to an interface
3834 which is realized via a broadcast media, the value
3835 of this field is the agent's IP address on that
3836 interface.)"
3837  
3838 (C<ipRouteNextHop>)
3839  
3840 =item $info->ipr_type()
3841  
3842 From RFC1213:
3843  
3844 other(1), -- none of the following
3845 invalid(2), -- an invalidated route
3846 -- route to directly
3847 direct(3), -- connected (sub-)network
3848 -- route to a non-local
3849 indirect(4) -- host/network/sub-network
3850  
3851  
3852 "The type of route. Note that the values
3853 direct(3) and indirect(4) refer to the notion of
3854 direct and indirect routing in the IP
3855 architecture.
3856  
3857 Setting this object to the value invalid(2) has
3858 the effect of invalidating the corresponding entry
3859 in the ipRouteTable object. That is, it
3860 effectively disassociates the destination
3861 identified with said entry from the route
3862 identified with said entry. It is an
3863 implementation-specific matter as to whether the
3864 agent removes an invalidated entry from the table.
3865 Accordingly, management stations must be prepared
3866 to receive tabular information from agents that
3867 corresponds to entries not currently in use.
3868 Proper interpretation of such entries requires
3869 examination of the relevant ipRouteType object."
3870  
3871 (C<ipRouteType>)
3872  
3873 =item $info->ipr_proto()
3874  
3875 From RFC1213:
3876  
3877 other(1), -- none of the following
3878 -- non-protocol information,
3879 -- e.g., manually configured
3880 local(2), -- entries
3881 -- set via a network
3882 netmgmt(3), -- management protocol
3883 -- obtained via ICMP,
3884 icmp(4), -- e.g., Redirect
3885 -- the remaining values are
3886 -- all gateway routing
3887 -- protocols
3888 egp(5),
3889 ggp(6),
3890 hello(7),
3891 rip(8),
3892 is-is(9),
3893 es-is(10),
3894 ciscoIgrp(11),
3895 bbnSpfIgp(12),
3896 ospf(13),
3897 bgp(14)
3898  
3899 (C<ipRouteProto>)
3900  
3901 =item $info->ipr_age()
3902  
3903 Seconds since route was last updated or validated.
3904  
3905 (C<ipRouteAge>)
3906  
3907 =item $info->ipr_mask()
3908  
3909 Subnet Mask of route. 0.0.0.0 for default gateway.
3910  
3911 (C<ipRouteMask>)
3912  
3913 =item $info->ipr_info()
3914  
3915 Reference to MIB definition specific to routing protocol.
3916  
3917 (C<ipRouteInfo>)
3918  
3919 =back
3920  
3921 =head2 Topology Information
3922  
3923 Based upon the manufacturer and software version devices may support some
3924 combination of Layer 2 topology protocol information. SNMP::Info
3925 supports querying Link Layer Discovery Protocol (LLDP), Cisco Discovery
3926 Protocol (CDP), SynOptics/Bay/Nortel/Avaya Network Management Protocol
3927 (SONMP), Foundry/Brocade Discovery Protocol (FDP), Extreme Discovery
3928 Protocol (EDP), and Alcatel Mapping Adjacency Protocol (AMAP).
3929  
3930 For protocol specific information and implementation:
3931  
3932 =over
3933  
3934 =item AMAP: See L<SNMP::Info::AMAP> for details.
3935  
3936 =item CDP: See L<SNMP::Info::CDP> for details.
3937  
3938 =item EDP: See L<SNMP::Info::EDP> for details.
3939  
3940 =item FDP: See L<SNMP::Info::FDP> for details.
3941  
3942 =item LLDP: See L<SNMP::Info::LLDP> for details.
3943  
3944 =item SONMP: See L<SNMP::Info::SONMP> for details.
3945  
3946 =back
3947  
3948 =head3 Topology Capabilities
3949  
3950 =over
3951  
3952 =item $info->has_topo()
3953  
3954 Reports Layer 2 topology protocols which are supported and running on
3955 a device.
3956  
3957 Returns either a reference to an array of protocols, possible values
3958 being: C<lldp>, C<cdp>, C<sonmp>, C<fdp>, C<edp>, C<amap>, C<mndp> or
3959 C<undef> if no protocols are supported or running.
3960  
3961 =back
3962  
3963 =cut
3964  
3965 sub ip_index {
3966 my $self = shift;
3967  
3968 my $o_ip_idx = $self->old_ip_index();
3969 return $o_ip_idx
3970 if ( ref {} eq ref $o_ip_idx and scalar keys %$o_ip_idx );
3971  
3972 # Since callers may be using the old iid to get the IP, strip protocol
3973 # and length from the index
3974 my $n_ip_idx = $self->new_ip_index() || {};
3975 my $n_ip_type = $self->new_ip_type() || {};
3976  
3977 my %ip_index;
3978 foreach my $iid ( keys %$n_ip_idx ) {
3979 next unless $n_ip_type->{$iid} and $n_ip_type->{$iid} eq 'unicast';
3980 my @parts = split( /\./, $iid );
3981 my $type = shift(@parts);
3982 my $len = shift(@parts);
3983 next unless ( ( $type == 1 ) and ( $len == 4 ) );
3984  
3985 my $new_iid = join( ".", @parts );
3986 $ip_index{$new_iid} = $n_ip_idx->{$iid};
3987 }
3988 return \%ip_index;
3989 }
3990  
3991 sub ip_table {
3992 my $self = shift;
3993  
3994 my $o_ip_table = $self->old_ip_table();
3995 return $o_ip_table
3996 if ( ref {} eq ref $o_ip_table and scalar keys %$o_ip_table );
3997  
3998 my $n_ip_idx = $self->new_ip_index() || {};
3999 my $n_ip_type = $self->new_ip_type() || {};
4000  
4001 my %ip_table;
4002 foreach my $iid ( keys %$n_ip_idx ) {
4003 next unless $n_ip_type->{$iid} and $n_ip_type->{$iid} eq 'unicast';
4004 my @parts = split( /\./, $iid );
4005 my $type = shift(@parts);
4006 my $len = shift(@parts);
4007 next unless ( ( $type == 1 ) and ( $len == 4 ) );
4008  
4009 my $new_iid = join( ".", @parts );
4010 $ip_table{$new_iid} = $new_iid;
4011 }
4012 return \%ip_table;
4013 }
4014  
4015 sub ip_netmask {
4016 my $self = shift;
4017  
4018 my $o_ip_mask = $self->old_ip_netmask();
4019 return $o_ip_mask
4020 if ( ref {} eq ref $o_ip_mask and scalar keys %$o_ip_mask );
4021  
4022 my $n_ip_pfx = $self->new_ip_prefix() || {};
4023 my $n_ip_type = $self->new_ip_type() || {};
4024  
4025 my %ip_netmask;
4026 foreach my $iid ( keys %$n_ip_pfx ) {
4027 next unless $n_ip_type->{$iid} and $n_ip_type->{$iid} eq 'unicast';
4028 my @parts = split( /\./, $iid );
4029 my $type = shift(@parts);
4030 my $len = shift(@parts);
4031 next unless ( ( $type == 1 ) and ( $len == 4 ) );
4032  
4033 my $prefix = $n_ip_pfx->{$iid};
4034 next if ( !$prefix || $prefix =~ /0\.0$/ );
4035 if ( $prefix =~ /\.(\d+)$/ ) {
4036 $prefix = $1;
4037 }
4038 my $new_iid = join( ".", @parts );
4039 my $mask = eval { NetAddr::IP::Lite->new( $new_iid . '/' . $prefix )->mask() }
4040 || undef;
4041  
4042 $ip_netmask{$new_iid} = $mask;
4043 }
4044 return \%ip_netmask;
4045 }
4046  
4047 sub has_topo {
4048 my $self = shift;
4049  
4050 my @topo_cap;
4051 push( @topo_cap, 'lldp' )
4052 if ( $self->can('hasLLDP') && $self->hasLLDP() );
4053 push( @topo_cap, 'cdp' ) if $self->can('hasCDP') && $self->hasCDP();
4054 push( @topo_cap, 'sonmp' )
4055 if $self->can('hasSONMP') && $self->hasSONMP();
4056 push( @topo_cap, 'fdp' ) if $self->can('hasFDP') && $self->hasFDP();
4057 push( @topo_cap, 'edp' ) if $self->can('hasEDP') && $self->hasEDP();
4058 push( @topo_cap, 'amap' ) if $self->can('hasAMAP') && $self->hasAMAP();
4059 push( @topo_cap, 'mndp' ) if $self->can('hasMNDP') && $self->hasMNDP();
4060  
4061 if (@topo_cap) {
4062 return \@topo_cap;
4063 }
4064 else {
4065 return;
4066 }
4067 }
4068  
4069 sub _get_topo_data {
4070 my $self = shift;
4071 my $partial = shift;
4072 my $topo_cap = shift;
4073 my $method = shift || '';
4074  
4075 return unless $method =~ /(ip|if|port|id|platform|cap)/;
4076  
4077 my %t_data;
4078 foreach my $proto (@$topo_cap) {
4079 next unless $proto =~ /(lldp|cdp|sonmp|fdp|edp|amap|mndp)/;
4080 my $method_name = "$proto" . "_$method";
4081 my $cdp = $self->$method_name($partial) || {};
4082  
4083 foreach my $iid ( keys %$cdp ) {
4084 my $ip = $cdp->{$iid};
4085 next unless defined $ip;
4086  
4087 $t_data{$iid} = $ip;
4088 }
4089 }
4090 return \%t_data;
4091 }
4092  
4093 =head3 Common Topology Table Information
4094  
4095 The common topology table methods below will query the
4096 device for information from the specified topology protocols and return a
4097 single hash combining all information. As a result, there may be identical
4098 topology information returned from the two protocols causing duplicate
4099 entries. It is the calling program's responsibility to identify any
4100 duplicate entries and remove duplicates if necessary. If it is necessary
4101 to understand which protocol provided the information, utilize the protocol
4102 specific methods directly rather than the generic methods.
4103  
4104 The methods support partial table fetches by providing a partial as the
4105 first argument.
4106  
4107 If a reference to an array is provided as the second argument, those
4108 protocols will be queried for information. The supported array values are:
4109 C<lldp>, C<cdp>, C<sonmp>, C<fdp>, C<edp>, C<amap>, C<mndp>.
4110  
4111 If nothing is passed in as the second argument, the methods will call
4112 has_topo() to determine supported and running topology protocols on the
4113 device.
4114  
4115 =over
4116  
4117 =item $info->c_ip(partial, topology_protocol_arrayref)
4118  
4119 Returns reference to hash. Key: iid, Value: remote IPv4 address
4120  
4121 If multiple entries exist with the same local port, c_if(), with the
4122 same IPv4 address, c_ip(), it may be a duplicate entry.
4123  
4124 If multiple entries exist with the same local port, c_if(), with different
4125 IPv4 addresses, c_ip(), there is either a device in between two or
4126 more devices utilizing a different topology protocol or multiple devices
4127 which are not directly connected.
4128  
4129 Use the protocol specific methods to dig deeper.
4130  
4131 =cut
4132  
4133 sub c_ip {
4134 my $self = shift;
4135 my $partial = shift;
4136 my $topo_cap = shift;
4137  
4138 # Default to old behavior if not called with topo_cap
4139 if ( !$topo_cap ) {
4140 my $topo_test = $self->has_topo();
4141 if ($topo_test) {
4142 $topo_cap = $topo_test;
4143 }
4144 else {
4145 return;
4146 }
4147 }
4148 return _get_topo_data ($self, $partial, $topo_cap, 'ip');
4149 }
4150  
4151 =item $info->c_if(partial, topology_protocol_arrayref)
4152  
4153 Returns reference to hash. Key: iid, Value: local device port (interfaces)
4154  
4155 =cut
4156  
4157 sub c_if {
4158 my $self = shift;
4159 my $partial = shift;
4160 my $topo_cap = shift;
4161  
4162 # Default to old behavior if not called with topo_cap
4163 if ( !$topo_cap ) {
4164 my $topo_test = $self->has_topo();
4165 if ($topo_test) {
4166 $topo_cap = $topo_test;
4167 }
4168 else {
4169 return;
4170 }
4171 }
4172 return _get_topo_data ($self, $partial, $topo_cap, 'if');
4173 }
4174  
4175 =item $info->c_port(partial, topology_protocol_arrayref)
4176  
4177 Returns reference to hash. Key: iid, Value: remote port (interfaces)
4178  
4179 =cut
4180  
4181 sub c_port {
4182 my $self = shift;
4183 my $partial = shift;
4184 my $topo_cap = shift;
4185  
4186 # Default to old behavior if not called with topo_cap
4187 if ( !$topo_cap ) {
4188 my $topo_test = $self->has_topo();
4189 if ($topo_test) {
4190 $topo_cap = $topo_test;
4191 }
4192 else {
4193 return;
4194 }
4195 }
4196 return _get_topo_data ($self, $partial, $topo_cap, 'port');
4197 }
4198  
4199 =item $info->c_id(partial, topology_protocol_arrayref)
4200  
4201 Returns reference to hash. Key: iid, Value: string value used to identify the
4202 chassis component associated with the remote system.
4203  
4204 Note: SONMP does not return this information.
4205  
4206 =cut
4207  
4208 sub c_id {
4209 my $self = shift;
4210 my $partial = shift;
4211 my $topo_cap = shift;
4212  
4213 # Default to old behavior if not called with topo_cap
4214 if ( !$topo_cap ) {
4215 my $topo_test = $self->has_topo();
4216 if ($topo_test) {
4217 $topo_cap = $topo_test;
4218 }
4219 else {
4220 return;
4221 }
4222 }
4223 return _get_topo_data ($self, $partial, $topo_cap, 'id');
4224 }
4225  
4226 =item $info->c_platform(partial, topology_protocol_arrayref)
4227  
4228 Returns reference to hash. Key: iid, Value: Remote Device Type
4229  
4230 Note: EDP does not provide this information. LLDP uses (C<lldpRemSysDesc>)
4231 or C<lldp_rem_sysname> as the closest match.
4232  
4233 =cut
4234  
4235 sub c_platform {
4236 my $self = shift;
4237 my $partial = shift;
4238 my $topo_cap = shift;
4239  
4240 # Default to old behavior if not called with topo_cap
4241 if ( !$topo_cap ) {
4242 my $topo_test = $self->has_topo();
4243 if ($topo_test) {
4244 $topo_cap = $topo_test;
4245 }
4246 else {
4247 return;
4248 }
4249 }
4250 return _get_topo_data ($self, $partial, $topo_cap, 'platform');
4251 }
4252  
4253 =item $info->c_cap(partial, topology_protocol_arrayref)
4254  
4255 Returns reference to hash of arrays. Key: iid, Value: Array of capabilities
4256 supported by the device. See the specific protocol class for string values
4257 which could be elements within the array.
4258  
4259 Note: Only CDP and LLDP support this method.
4260  
4261 =cut
4262  
4263 sub c_cap {
4264 my $self = shift;
4265 my $partial = shift;
4266 my $topo_cap = shift;
4267  
4268 # Default to old behavior if not called with topo_cap
4269 if ( !$topo_cap ) {
4270 my $topo_test = $self->has_topo();
4271 if ($topo_test) {
4272 $topo_cap = $topo_test;
4273 }
4274 else {
4275 return;
4276 }
4277 }
4278 return _get_topo_data ($self, $partial, $topo_cap, 'cap');
4279 }
4280  
4281 =back
4282  
4283 =head1 SETTING DATA VIA SNMP
4284  
4285 This section explains how to use SNMP::Info to do SNMP Set operations.
4286  
4287 =over
4288  
4289 =item $info->set_METHOD($value)
4290  
4291 Sets the global METHOD to value. Assumes that iid is .0
4292  
4293 Returns if failed, or the return value from SNMP::Session::set() (snmp_errno)
4294  
4295 $info->set_location("Here!");
4296  
4297 =item $info->set_METHOD($value,$iid)
4298  
4299 Table Methods. Set iid of method to value.
4300  
4301 Returns if failed, or the return value from SNMP::Session::set() (snmp_errno)
4302  
4303 # Disable a port administratively
4304 my %if_map = reverse %{$info->interfaces()}
4305 $info->set_i_up_admin('down', $if_map{'FastEthernet0/0'})
4306 or die "Couldn't disable the port. ",$info->error(1);
4307  
4308 =back
4309  
4310 NOTE: You must be connected to your device with a C<ReadWrite> community
4311 string in order for set operations to work.
4312  
4313 NOTE: This will only set data listed in %FUNCS and %GLOBALS. For data
4314 acquired from overridden methods (subroutines) specific set_METHOD()
4315 subroutines will need to be added if they haven't been already.
4316  
4317 =head1 Quiet Mode
4318  
4319 SNMP::Info will not chirp anything to STDOUT unless there is a serious error
4320 (in which case it will probably die).
4321  
4322 To get lots of debug info, set the Debug flag when calling new() or
4323 call $info->debug(1);
4324  
4325 When calling a method check the return value. If the return value is undef
4326 then check $info->error()
4327  
4328 Beware, calling $info->error() clears the error.
4329  
4330 my $name = $info->name() or die "Couldn't get sysName!" . $name->error();
4331  
4332 =head1 EXTENDING SNMP::INFO
4333  
4334 To support a new class (vendor or platform) of device, add a Perl package with
4335 the data structures and methods listed below.
4336  
4337 If this seems a little scary, then the SNMP::Info developers are usually happy
4338 to accept the SNMP data from your device and make an attempt at the class
4339 themselves. Usually a "beta" release will go to CPAN for you to verify the
4340 implementation.
4341  
4342 =head2 AI coding agents
4343  
4344 To write or change a device class, start by cloning the
4345 L<github repository|https://github.com/netdisco/snmp-info> and develop
4346 there, then open a pull request. The repository includes guidance for AI
4347 coding agents:
4348  
4349 =over
4350  
4351 =item * L<AGENTS.md|https://github.com/netdisco/snmp-info/blob/master/AGENTS.md>:
4352 how the library works, the tests CI runs, and the pull request checklist.
4353  
4354 =item * L<device-class-authoring|https://github.com/netdisco/snmp-info/blob/master/.claude/skills/device-class-authoring/SKILL.md>:
4355 writing or changing a device class, its detection, tests and POD.
4356  
4357 =item * L<device-class-review|https://github.com/netdisco/snmp-info/blob/master/.claude/skills/device-class-review/SKILL.md>:
4358 reviewing a device class change, including your own before you open a
4359 pull request.
4360  
4361 =back
4362  
4363 Claude Code and GitHub Copilot pick these up when run in the clone. Keep
4364 personal agent instructions in an untracked F<CLAUDE.local.md>.
4365  
4366 =head2 Gathering MIB data for SNMP::Info Developers
4367  
4368 The preference is to open an issue or pull request in the github project.
4369 This allows all developers to have visibility into the request. Please
4370 include pointers to the applicable platform MIBs. For development we will
4371 need a numeric C<snmpwalk> of the whole device:
4372  
4373 snmpwalk -v2c -c community -ObentU device_ip .1
4374  
4375 or, with SNMPv3:
4376  
4377 snmpwalk -v3 -l authPriv -u user -a SHA -A authpass -x AES -X privpass \
4378 -ObentU device_ip .1
4379  
4380 Numeric output keeps the objects that no loaded MIB defines, and developers
4381 can serve it from an SNMP simulator to emulate the device without needing
4382 access to it. C<snmpbulkwalk> takes the same options and is faster on large
4383 devices; if the walk times out, raise the timeout and retries with
4384 C<-t 5 -r 2>.
4385  
4386 =head3 Removing sensitive data
4387  
4388 A full walk can contain:
4389  
4390 =over
4391  
4392 =item * Names and descriptions: C<sysName>, C<sysContact>, C<sysLocation>,
4393 interface descriptions (C<ifAlias>), VLAN names, SSIDs, neighbor names.
4394  
4395 =item * Addresses: the device's own IP and MAC addresses, and those of
4396 neighbors, ARP and forwarding table entries, and wireless clients. These
4397 often appear in the OID index as well as in the value.
4398  
4399 =item * Serial numbers, user names, and any keys or passwords that a vendor
4400 MIB exposes.
4401  
4402 =back
4403  
4404 Replace each sensitive value consistently: map each distinct value to one
4405 stand-in and use it everywhere, in values and in OID indexes, so that tables
4406 still join on the same keys. Documentation ranges make good stand-ins:
4407 C<192.0.2.0/24>, C<198.51.100.0/24>, C<203.0.113.0/24>, C<2001:db8::/32>,
4408 and MAC addresses such as C<02:00:00:00:00:01>. Keep the OIDs, value types,
4409 and index shapes unchanged, and do not delete rows or tables; if something
4410 must go, say what was removed. Read the result before sharing it.
4411  
4412 Compress the file and attach it to the github issue or pull request.
4413 However, if you do not feel comfortable uploading the output to the tracker
4414 you could e-mail it to the developer that has claimed the ticket.
4415  
4416 =head2 Data Structures required in new Subclass
4417  
4418 A class inheriting this class must implement these data structures :
4419  
4420 =over
4421  
4422 =item $INIT
4423  
4424 Used to flag if the MIBs have been loaded yet.
4425  
4426 =cut
4427  
4428 $INIT = 0;
4429  
4430 =item %GLOBALS
4431  
4432 Contains a hash in the form ( method_name => SNMP MIB leaf name )
4433 These are scalar values such as name, uptime, etc.
4434  
4435 To resolve MIB leaf name conflicts between private MIBs, you may prefix the
4436 leaf name with the MIB replacing each - (dash) and : (colon) with
4437 an _ (underscore). For example, ALTEON_TIGON_SWITCH_MIB__agSoftwareVersion
4438 would be used as the hash value instead of the net-snmp notation
4439 ALTEON-TIGON-SWITCH-MIB::agSoftwareVersion.
4440  
4441 When choosing the name for the methods, be aware that other new
4442 Sub Modules might inherit this one to get it's features. Try to
4443 choose a prefix for methods that will give it's own name space inside
4444 the SNMP::Info methods.
4445  
4446 =cut
4447  
4448 %GLOBALS = (
4449  
4450 # from SNMPv2-MIB
4451 'id' => 'sysObjectID',
4452 'description' => 'sysDescr',
4453 'uptime' => 'sysUpTime',
4454 'contact' => 'sysContact',
4455 'name' => 'sysName',
4456 'location' => 'sysLocation',
4457 'layers' => 'sysServices',
4458 # IF-MIB
4459 'ports' => 'ifNumber',
4460 # IP-MIB
4461 'ipforwarding' => 'ipForwarding',
4462 );
4463  
4464 =item %FUNCS
4465  
4466 Contains a hash in the form ( method_name => SNMP MIB leaf name)
4467 These are table entries, such as the C<ifIndex>
4468  
4469 To resolve MIB leaf name conflicts between private MIBs, you may prefix the
4470 leaf name with the MIB replacing each - (dash) and : (colon) with
4471 an _ (underscore). For example, ALTEON_TS_PHYSICAL_MIB__agPortCurCfgPortName
4472 would be used as the hash value instead of the net-snmp notation
4473 ALTEON-TS-PHYSICAL-MIB::agPortCurCfgPortName.
4474  
4475 =cut
4476  
4477 %FUNCS = (
4478 # IF-MIB::IfEntry
4479 'interfaces' => 'ifIndex',
4480 # IF-MIB::IfXEntry
4481 'i_name' => 'ifName',
4482  
4483 # IF-MIB::IfEntry
4484 'i_index' => 'ifIndex',
4485 'i_description' => 'ifDescr',
4486 'i_type' => 'ifType',
4487 'i_mtu' => 'ifMtu',
4488 'i_speed' => 'ifSpeed',
4489 'i_mac' => 'ifPhysAddress',
4490 'i_up_admin' => 'ifAdminStatus',
4491 'i_up' => 'ifOperStatus',
4492 'i_lastchange' => 'ifLastChange',
4493 'i_octet_in' => 'ifInOctets',
4494 'i_pkts_ucast_in' => 'ifInUcastPkts',
4495 'i_pkts_nucast_in' => 'ifInNUcastPkts',
4496 'i_discards_in' => 'ifInDiscards',
4497 'i_errors_in' => 'ifInErrors',
4498 'i_bad_proto_in' => 'ifInUnknownProtos',
4499 'i_octet_out' => 'ifOutOctets',
4500 'i_pkts_ucast_out' => 'ifOutUcastPkts',
4501 'i_pkts_nucast_out' => 'ifOutNUcastPkts',
4502 'i_discards_out' => 'ifOutDiscards',
4503 'i_errors_out' => 'ifOutErrors',
4504 'i_qlen_out' => 'ifOutQLen',
4505 'i_specific' => 'ifSpecific',
4506  
4507 # IF-MIB::IfStackTable
4508 'i_stack_status' => 'ifStackStatus',
4509  
4510 # IP-MIB::ipAddrTable (deprecated IPv4 address table)
4511 'old_ip_index' => 'ipAdEntIfIndex',
4512 'old_ip_table' => 'ipAdEntAddr',
4513 'old_ip_netmask' => 'ipAdEntNetMask',
4514 'ip_broadcast' => 'ipAdEntBcastAddr',
4515  
4516 # IP-MIB::ipAddressTable
4517 'new_ip_index' => 'ipAddressIfIndex',
4518 'new_ip_prefix' => 'ipAddressPrefix',
4519 'new_ip_type' => 'ipAddressType',
4520  
4521 # IF-MIB::ifXTable - Extension Table
4522 'i_speed_high' => 'ifHighSpeed',
4523 'i_pkts_multi_in' => 'ifInMulticastPkts',
4524 'i_pkts_multi_out' => 'ifOutMulticastPkts',
4525 'i_pkts_bcast_in' => 'ifInBroadcastPkts',
4526 'i_pkts_bcast_out' => 'ifOutBroadcastPkts',
4527 'i_octet_in64' => 'ifHCInOctets',
4528 'i_octet_out64' => 'ifHCOutOctets',
4529 'i_pkts_ucast_in64' => 'ifHCInUcastPkts',
4530 'i_pkts_ucast_out64' => 'ifHCOutUcastPkts',
4531 'i_pkts_multi_in64' => 'ifHCInMulticastPkts',
4532 'i_pkts_multi_out64' => 'ifHCOutMulticastPkts',
4533 'i_pkts_bcast_in64' => 'ifHCInBroadcastPkts',
4534 'i_pkts_bcast_out64' => 'ifHCOutBroadcastPkts',
4535 'i_alias' => 'ifAlias',
4536  
4537 # RFC-1213::ipRoute (deprecated Table IP Routing Table)
4538 'ipr_route' => 'ipRouteDest',
4539 'ipr_if' => 'ipRouteIfIndex',
4540 'ipr_1' => 'ipRouteMetric1',
4541 'ipr_2' => 'ipRouteMetric2',
4542 'ipr_3' => 'ipRouteMetric3',
4543 'ipr_4' => 'ipRouteMetric4',
4544 'ipr_5' => 'ipRouteMetric5',
4545 'ipr_dest' => 'ipRouteNextHop',
4546 'ipr_type' => 'ipRouteType',
4547 'ipr_proto' => 'ipRouteProto',
4548 'ipr_age' => 'ipRouteAge',
4549 'ipr_mask' => 'ipRouteMask',
4550 'ipr_info' => 'ipRouteInfo',
4551 );
4552  
4553 =item %MIBS
4554  
4555 A list of each mib needed.
4556  
4557 ('MIB-NAME' => 'itemToTestForPresence')
4558  
4559 The value for each entry should be a MIB object to check for to make sure
4560 that the MIB is present and has loaded correctly.
4561  
4562 $info->init() will throw an exception if a MIB does not load.
4563  
4564 =cut
4565  
4566 %MIBS = (
4567  
4568 # Include these here for cases where the Net-SNMP default MIB list has
4569 # been overridden during the compilation of the local Net-SNMP library.
4570 # These cover the globals and funcs defined in this file.
4571 'SNMPv2-MIB' => 'sysObjectID',
4572 # (#325) 'RFC1213-MIB' => 'ipRouteIfIndex',
4573 'IP-MIB' => 'ipAdEntAddr',
4574 'IF-MIB' => 'ifIndex',
4575 );
4576  
4577 =item %MUNGE
4578  
4579 A map between method calls (from %FUNCS or %GLOBALS) and subroutine methods.
4580 The subroutine called will be passed the data as it gets it from SNMP and
4581 it should return that same data in a more human friendly format.
4582  
4583 Sample %MUNGE:
4584  
4585 (my_ip => \&munge_ip,
4586 my_mac => \&munge_mac,
4587 my_layers => \&munge_dec2bin
4588 )
4589  
4590 =cut
4591  
4592 %MUNGE = (
4593 'ip' => \&munge_ip,
4594 'mac' => \&munge_mac,
4595 'i_mac' => \&munge_mac,
4596 'layers' => \&munge_dec2bin,
4597 'i_speed' => \&munge_speed,
4598 'i_speed_high' => \&munge_highspeed,
4599 'i_octet_in64' => \&munge_counter64,
4600 'i_octet_out64' => \&munge_counter64,
4601 'i_pkts_ucast_in64' => \&munge_counter64,
4602 'i_pkts_ucast_out64' => \&munge_counter64,
4603 'i_pkts_mutli_in64' => \&munge_counter64,
4604 'i_pkts_multi_out64' => \&munge_counter64,
4605 'i_pkts_bcast_in64' => \&munge_counter64,
4606 'i_pkts_bcast_out64' => \&munge_counter64,
4607 'i_up' => \&munge_i_up,
4608 );
4609  
4610 =back
4611  
4612 =head2 Sample Subclass
4613  
4614 Let's make a sample Layer 2 Device subclass. This class
4615 will inherit the Cisco Vlan module as an example.
4616  
4617 ----------------------- snip --------------------------------
4618  
4619 # SNMP::Info::Layer2::Sample
4620  
4621 package SNMP::Info::Layer2::Sample;
4622  
4623 $VERSION = 0.1;
4624  
4625 use strict;
4626 use warnings;
4627  
4628 use Exporter;
4629 use SNMP::Info::Layer2;
4630 use SNMP::Info::CiscoVTP;
4631  
4632 @SNMP::Info::Layer2::Sample::ISA = qw/SNMP::Info::Layer2
4633 SNMP::Info::CiscoVTP Exporter/;
4634 @SNMP::Info::Layer2::Sample::EXPORT_OK = qw//;
4635  
4636 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE, $AUTOLOAD, $INIT, $DEBUG);
4637  
4638 %MIBS = (%SNMP::Info::Layer2::MIBS,
4639 %SNMP::Info::CiscoVTP::MIBS,
4640 'SUPER-DOOPER-MIB' => 'supermibobject',
4641 );
4642  
4643 %GLOBALS = (%SNMP::Info::Layer2::GLOBALS,
4644 %SNMP::Info::CiscoVTP::GLOBALS,
4645 'name' => 'supermib_supername',
4646 'favorite_color' => 'supermib_fav_color_object',
4647 'favorite_movie' => 'supermib_fav_movie_val',
4648 );
4649  
4650 %FUNCS = (%SNMP::Info::Layer2::FUNCS,
4651 %SNMP::Info::CiscoVTP::FUNCS,
4652 # Super Dooper MIB - Super Hero Table
4653 'super_hero_index' => 'SuperHeroIfIndex',
4654 'super_hero_name' => 'SuperHeroIfName',
4655 'super_hero_powers' => 'SuperHeroIfPowers',
4656 );
4657  
4658  
4659 %MUNGE = (%SNMP::Info::Layer2::MUNGE,
4660 %SNMP::Info::CiscoVTP::MUNGE,
4661 'super_hero_powers' => \&munge_powers,
4662 );
4663  
4664 # Override uptime() method from %SNMP::Info::GLOBALS
4665 sub uptime {
4666 my $sample = shift;
4667  
4668 my $name = $sample->name();
4669  
4670 # this is silly but you get the idea
4671 return '600' if defined $name ;
4672 }
4673  
4674 # Create our own munge function
4675 sub munge_powers {
4676 my $power = shift;
4677  
4678 # Take the returned obscure value and return something useful.
4679 return 'Fire' if $power =~ /reallyhot/i;
4680 return 'Ice' if $power =~ /reallycold/i;
4681  
4682 # Else
4683 return $power;
4684 }
4685  
4686 # Copious Documentation here!!!
4687 =head1 NAME
4688 =head1 AUTHOR
4689 =head1 SYNOPSIS
4690 =head1 DESCRIPTION
4691 =head2 Inherited Classes
4692 =head2 Required MIBs
4693 =head1 GLOBALS
4694 =head2 Overrides
4695 =head1 TABLE METHODS
4696 =head2 Overrides
4697 =cut
4698  
4699 1; # don't forget this line
4700 ----------------------- snip --------------------------------
4701  
4702  
4703 =head1 SNMP::INFO INTERNALS
4704  
4705 =head2 Object Namespace
4706  
4707 Internal data is stored with bareword keys. For example $info->{debug}
4708  
4709 SNMP Data is stored or marked cached with keys starting with an underscore.
4710 For example $info->{_name} is the cache for $info->name().
4711  
4712 Cached Table data is stored in $info->store() and marked cached per above.
4713  
4714 =head2 Package Globals
4715  
4716 These set the default value for an object upon creation.
4717  
4718 =over
4719  
4720 =item $DEBUG
4721  
4722 Default 0. Sends copious debug info to stdout. This global sets the object's
4723 debug status in new() unless 'Debug' argument passed in new(). Change
4724 objects' debug status with $info->debug().
4725  
4726 =cut
4727  
4728 $DEBUG = 0;
4729  
4730 =item $BIGINT
4731  
4732 Default 0. Set to true to have 64 bit counters return Math::BigInt objects
4733 instead of scalar string values. See note under Interface Statistics about
4734 64 bit values.
4735  
4736 =cut
4737  
4738 $BIGINT = 0;
4739  
4740 =item $NOSUCH
4741  
4742 Default 1. Set to false to disable RetryNoSuch option for SNMP::Session. Or
4743 see method in new() to do it on an object scope.
4744  
4745 =cut
4746  
4747 $NOSUCH = 1;
4748  
4749 =item $REPEATERS
4750  
4751 Default 20. MaxRepeaters for BULKWALK operations. See C<perldoc SNMP> for
4752 more info. Can change by passing L</BulkRepeaters> option in new()
4753  
4754 =cut
4755  
4756 $REPEATERS = 20;
4757  
4758 =item $BACKOFF_FLOOR
4759  
4760 Default 5. The lowest MaxRepeaters value a bulkwalk is retried with when
4761 L</BulkBackoff> is on.
4762  
4763 =cut
4764  
4765 $BACKOFF_FLOOR = 5;
4766  
4767 =item $MAX_FAILED_BULKWALKS
4768  
4769 Default 9. How many failed bulkwalks an object tolerates before it walks
4770 every later table with GETNEXT, counting every bulkwalk failure that
4771 L</BulkBackoff> or L</BulkOrderCheck> acts on. Failures in a context marked
4772 unreachable are not counted.
4773  
4774 =cut
4775  
4776 $MAX_FAILED_BULKWALKS = 9;
4777  
4778 =item $SLOW_DEVICE_TABLES
4779  
4780 Default 3. How many distinct tables must time out on bulkwalk without their
4781 context being marked unreachable before the object is treated as slow, and
4782 every later table starts from the smallest repeaters with which one of them
4783 completed by bulkwalk (or C<$BACKOFF_FLOOR> when none did). Tables in a
4784 context marked unreachable are not counted.
4785  
4786 =cut
4787  
4788 $SLOW_DEVICE_TABLES = 3;
4789  
4790 =back
4791  
4792 =head2 Data Munging Callback Subroutines
4793  
4794 =over
4795  
4796 =item munge_speed()
4797  
4798 Makes human friendly speed ratings using C<%SPEED_MAP>.
4799  
4800 %SPEED_MAP = (
4801 '56000' => '56 kbps',
4802 '64000' => '64 kbps',
4803 '115000' => '115 kbps',
4804 '1500000' => '1.5 Mbps',
4805 '1536000' => 'T1',
4806 '1544000' => 'T1',
4807 '2000000' => '2.0 Mbps',
4808 '2048000' => '2.048 Mbps',
4809 '3072000' => 'Dual T1',
4810 '3088000' => 'Dual T1',
4811 '4000000' => '4.0 Mbps',
4812 '10000000' => '10 Mbps',
4813 '11000000' => '11 Mbps',
4814 '16000000' => '16 Mbps',
4815 '16777216' => '16 Mbps',
4816 '20000000' => '20 Mbps',
4817 '44210000' => 'T3',
4818 '44736000' => 'T3',
4819 '45000000' => '45 Mbps',
4820 '45045000' => 'DS3',
4821 '46359642' => 'DS3',
4822 '51850000' => 'OC-1',
4823 '54000000' => '54 Mbps',
4824 '64000000' => '64 Mbps',
4825 '100000000' => '100 Mbps',
4826 '149760000' => 'ATM on OC-3',
4827 '155000000' => 'OC-3',
4828 '155519000' => 'OC-3',
4829 '155520000' => 'OC-3',
4830 '200000000' => '200 Mbps',
4831 '400000000' => '400 Mbps',
4832 '599040000' => 'ATM on OC-12',
4833 '622000000' => 'OC-12',
4834 '622080000' => 'OC-12',
4835 '1000000000' => '1.0 Gbps',
4836 '2000000000' => '2.0 Gbps',
4837 '2488000000' => 'OC-48',
4838 '2500000000' => '2.5 Gbps',
4839 )
4840  
4841 Note: high speed interfaces (usually 1 Gbps or faster) have their link
4842 speed in C<ifHighSpeed>. i_speed() automatically determines whether to use
4843 C<ifSpeed> or C<ifHighSpeed>; if the latter is used, the value is munged by
4844 munge_highspeed(). SNMP::Info can return speeds up to terabit levels this way.
4845  
4846 =cut
4847  
4848 %SPEED_MAP = (
4849 '56000' => '56 kbps',
4850 '64000' => '64 kbps',
4851 '115000' => '115 kbps',
4852 '1500000' => '1.5 Mbps',
4853 '1536000' => 'T1',
4854 '1544000' => 'T1',
4855 '2000000' => '2.0 Mbps',
4856 '2048000' => '2.048 Mbps',
4857 '3072000' => 'Dual T1',
4858 '3088000' => 'Dual T1',
4859 '4000000' => '4.0 Mbps',
4860 '10000000' => '10 Mbps',
4861 '11000000' => '11 Mbps',
4862 '16000000' => '16 Mbps',
4863 '16777216' => '16 Mbps',
4864 '20000000' => '20 Mbps',
4865 '44210000' => 'T3',
4866 '44736000' => 'T3',
4867 '45000000' => '45 Mbps',
4868 '45045000' => 'DS3',
4869 '46359642' => 'DS3',
4870 '51850000' => 'OC-1',
4871 '54000000' => '54 Mbps',
4872 '64000000' => '64 Mbps',
4873 '100000000' => '100 Mbps',
4874 '149760000' => 'ATM on OC-3',
4875 '155000000' => 'OC-3',
4876 '155519000' => 'OC-3',
4877 '155520000' => 'OC-3',
4878 '200000000' => '200 Mbps',
4879 '400000000' => '400 Mbps',
4880 '599040000' => 'ATM on OC-12',
4881 '622000000' => 'OC-12',
4882 '622080000' => 'OC-12',
4883 '1000000000' => '1.0 Gbps',
4884 '2000000000' => '2.0 Gbps',
4885 '2488000000' => 'OC-48',
4886 '2500000000' => '2.5 Gbps',
4887 );
4888  
4889 sub munge_speed {
4890 my $speed = shift;
4891 my $map = $SPEED_MAP{$speed};
4892  
4893 #print " $speed -> $map " if (defined $map);
4894 return $map || $speed;
4895 }
4896  
4897 =item munge_highspeed()
4898  
4899 Makes human friendly speed ratings for C<ifHighSpeed>.
4900  
4901 =cut
4902  
4903 sub munge_highspeed {
4904 my $speed = shift;
4905 my $fmt = "%d Mbps";
4906  
4907 if ( $speed > 9999999 ) {
4908 $fmt = "%d Tbps";
4909 $speed /= 1000000;
4910 }
4911 elsif ( $speed > 999999 ) {
4912 $fmt = "%.1f Tbps";
4913 $speed /= 1000000.0;
4914 }
4915 elsif ( $speed > 9999 ) {
4916 $fmt = "%d Gbps";
4917 $speed /= 1000;
4918 }
4919 elsif ( $speed > 999 ) {
4920 $fmt = "%.1f Gbps";
4921 $speed /= 1000.0;
4922 }
4923 return sprintf( $fmt, $speed );
4924 }
4925  
4926 =item munge_ip()
4927  
4928 Takes a binary IP and makes it dotted ASCII.
4929  
4930 =cut
4931  
4932 sub munge_ip {
4933 my $ip = shift;
4934 return join( '.', unpack( 'C4', $ip ) );
4935 }
4936  
4937 =item munge_inetaddress()
4938  
4939 Takes a binary IP address as defined by the SNMP InetAddress type and returns
4940 it as human readable string.
4941  
4942 =cut
4943  
4944 sub munge_inetaddress {
4945 my $ip = shift;
4946 # 4 bytes = IPv4
4947 if (length($ip) == 4) {
4948 return SNMP::Info::munge_ip($ip);
4949 }
4950 # 16 bytes = IPv6
4951 elsif (length($ip) == 16) {
4952 return sprintf( "%x:%x:%x:%x:%x:%x:%x:%x",
4953 unpack( 'n8', $ip ));
4954 }
4955 return '';
4956 }
4957  
4958 =item munge_mac()
4959  
4960 Takes an octet stream (HEX-STRING) and returns a colon separated ASCII hex
4961 string.
4962  
4963 =cut
4964  
4965 sub munge_mac {
4966 my $mac = shift;
4967 return unless defined $mac;
4968 return unless length $mac;
4969 $mac = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $mac ) );
4970 return $mac if $mac =~ /^([0-9A-F][0-9A-F]:){5}[0-9A-F][0-9A-F]$/i;
4971 return;
4972 }
4973  
4974 =item munge_prio_mac()
4975  
4976 Takes an 8-byte octet stream (HEX-STRING) and returns a colon separated ASCII
4977 hex string.
4978  
4979 =cut
4980  
4981 sub munge_prio_mac {
4982 my $mac = shift;
4983 return unless defined $mac;
4984 return unless length $mac;
4985 $mac = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $mac ) );
4986 return $mac if $mac =~ /^([0-9A-F][0-9A-F]:){7}[0-9A-F][0-9A-F]$/i;
4987 return;
4988 }
4989  
4990 =item munge_stpx_port_role()
4991  
4992 Changes the served C<stpxRSTPPortRoleValue> of CISCO-STP-EXTENSIONS-MIB to the
4993 shared port role vocabulary: C<disabled>, C<root>, C<designated>,
4994 C<alternate>, C<backup>, C<boundary> or C<master>. Accepts the label or the
4995 number, C<disabled(1)> to C<master(7)>. The label C<backUp> becomes
4996 C<backup>. Returns undef for anything else. The served value is returned by
4997 the same method with a C<_raw> suffix.
4998  
4999 =cut
5000  
5001 my %STPX_PORT_ROLE = (
5002 1 => 'disabled', 2 => 'root', 3 => 'designated', 4 => 'alternate',
5003 5 => 'backup', 6 => 'boundary', 7 => 'master',
5004 );
5005  
5006 sub munge_stpx_port_role {
5007 return _munge_port_role( shift, \%STPX_PORT_ROLE );
5008 }
5009  
5010 =item munge_dot1s_port_role()
5011  
5012 Changes the served 802.1s port role of JUNIPER-MIMSTP-MIB and
5013 NORTEL-NETWORKS-MULTIPLE-SPANNING-TREE-MIB to the shared port role vocabulary
5014 (see C<munge_stpx_port_role()>). Accepts the label or the number:
5015  
5016 0 disabled 1 alternate 2 backup
5017 3 root 4 designated 5 master
5018  
5019 Returns undef for anything else. The served value is returned by the same
5020 method with a C<_raw> suffix.
5021  
5022 =cut
5023  
5024 my %DOT1S_PORT_ROLE = (
5025 0 => 'disabled', 1 => 'alternate', 2 => 'backup',
5026 3 => 'root', 4 => 'designated', 5 => 'master',
5027 );
5028  
5029 sub munge_dot1s_port_role {
5030 return _munge_port_role( shift, \%DOT1S_PORT_ROLE );
5031 }
5032  
5033 =item munge_dot1w_port_role()
5034  
5035 Changes the served port role of NORTEL-NETWORKS-RAPID-SPANNING-TREE-MIB to
5036 the shared port role vocabulary (see C<munge_stpx_port_role()>). Accepts the
5037 label or the number, and drops the C<Port> suffix of the label:
5038  
5039 0 disabledPort 1 alternatePort 2 backupPort
5040 3 rootPort 4 designatedPort
5041  
5042 Returns undef for anything else. The served value is returned by the same
5043 method with a C<_raw> suffix.
5044  
5045 =cut
5046  
5047 my %DOT1W_PORT_ROLE = (
5048 0 => 'disabled', 1 => 'alternate', 2 => 'backup',
5049 3 => 'root', 4 => 'designated',
5050 );
5051  
5052 sub munge_dot1w_port_role {
5053 my $served = shift;
5054 $served =~ s/Port\z// if defined $served;
5055 return _munge_port_role( $served, \%DOT1W_PORT_ROLE );
5056 }
5057  
5058 # A label is only valid if it is a value of the table; backUp is the one label
5059 # whose spelling differs from the shared vocabulary
5060 sub _munge_port_role {
5061 my ( $served, $by_number ) = @_;
5062 return unless defined $served;
5063 return $by_number->{$served} if exists $by_number->{$served};
5064 return 'backup' if $served eq 'backUp';
5065 my %valid = map { $_ => 1 } values %$by_number;
5066 return $valid{$served} ? $served : undef;
5067 }
5068  
5069 =item munge_prio_port()
5070  
5071 Takes an 2-byte octet stream (HEX-STRING) and returns a colon separated ASCII
5072 hex string.
5073  
5074 =cut
5075  
5076 sub munge_prio_port {
5077 my $priop = shift;
5078 return unless defined $priop;
5079 return unless length $priop;
5080 $priop = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $priop ) );
5081 return $priop if $priop =~ /^([0-9A-F][0-9A-F]:){1}[0-9A-F][0-9A-F]$/i;
5082 return;
5083 }
5084  
5085 =item munge_octet2hex()
5086  
5087 Takes a binary octet stream and returns an ASCII hex string.
5088  
5089 =cut
5090  
5091 sub munge_octet2hex {
5092 my $oct = shift;
5093 return join( '', map { sprintf "%x", $_ } unpack( 'C*', $oct ) );
5094 }
5095  
5096 =item munge_dec2bin()
5097  
5098 Takes a binary char and returns its ASCII binary representation.
5099  
5100 =cut
5101  
5102 sub munge_dec2bin {
5103 my $num = shift;
5104 return unless defined $num;
5105  
5106 #return unless length($num);
5107 $num = unpack( "B32", pack( "N", $num ) );
5108  
5109 # return last 8 characters only
5110 $num =~ s/.*(.{8})$/$1/;
5111 return $num;
5112 }
5113  
5114 =item munge_bits()
5115  
5116 Takes a SNMP2 'BITS' field and returns the ASCII bit string.
5117  
5118 =cut
5119  
5120 sub munge_bits {
5121 my $bits = shift;
5122 return unless defined $bits;
5123  
5124 return unpack( "B*", $bits );
5125 }
5126  
5127 =item munge_counter64()
5128  
5129 If $BIGINT is set to true, then a Math::BigInt object is returned.
5130 See Math::BigInt for details.
5131  
5132 =cut
5133  
5134 sub munge_counter64 {
5135 my $counter = shift;
5136 return unless defined $counter;
5137 return $counter unless $BIGINT;
5138 my $bigint = Math::BigInt->new($counter);
5139 return $bigint;
5140 }
5141  
5142 =item munge_i_up()
5143  
5144 Net-SNMP tends to load C<RFC1213-MIB> first, and so ignores the
5145 updated enumeration for C<ifOperStatus> in C<IF-MIB>. This munge
5146 handles the "newer" definitions for the enumeration in IF-MIB.
5147  
5148 TODO: Get the precedence of MIBs and overriding of MIB data in Net-SNMP
5149 figured out. Hierarchy/precedence of MIBS in SNMP::Info.
5150  
5151 =cut
5152  
5153 sub munge_i_up {
5154 my $i_up = shift;
5155 return unless defined $i_up;
5156  
5157 my %ifOperStatusMap = ( '4' => 'unknown',
5158 '5' => 'dormant',
5159 '6' => 'notPresent',
5160 '7' => 'lowerLayerDown' );
5161 return $ifOperStatusMap{$i_up} || $i_up;
5162 }
5163  
5164 =item munge_port_list()
5165  
5166 Takes an octet string representing a set of ports and returns a reference
5167 to an array of binary values each array element representing a port.
5168  
5169 If the element has a value of '1', then that port is included in the set of
5170 ports; the port is not included if it has a value of '0'.
5171  
5172 =cut
5173  
5174 sub munge_port_list {
5175 my $oct = shift;
5176 return unless defined $oct;
5177  
5178 my $list = [ split( //, unpack( "B*", $oct ) ) ];
5179  
5180 return $list;
5181 }
5182  
5183 =item munge_null()
5184  
5185 Removes control characters from a string.
5186  
5187 =cut
5188  
5189 # munge_null() - removes nulls (\0) and other control characters
5190 sub munge_null {
5191 my $text = shift || return;
5192  
5193 $text =~ s/[[:cntrl:]]//g;
5194 return $text;
5195 }
5196  
5197 =item munge_e_type()
5198  
5199 Takes an OID and return the object name if the right MIB is loaded.
5200  
5201 =cut
5202  
5203 sub munge_e_type {
5204 my $oid = shift;
5205 return unless $oid;
5206 return $oid if $oid =~ m/^\.0/;
5207  
5208 my $name = &SNMP::translateObj($oid);
5209 return $name if defined($name);
5210 return $oid;
5211 }
5212  
5213 =back
5214  
5215 =head2 Internally Used Functions
5216  
5217 =over
5218  
5219 =item resolve_desthost()
5220  
5221 Takes the SNMP::Session C<DestHost> argument and determines if it is an
5222 'IPv4' or 'IPv6' host. 'IPv6' hosts are prefixed with the C<udp6:>
5223 C<transport-specifier> as required by the underlying C<Net-SNMP> library.
5224 If unable to determine the type of address or resolve a DNS name, dies with
5225 C<croak>.
5226  
5227 =cut
5228  
5229 sub resolve_desthost {
5230 my $desthost = shift;
5231  
5232 # If we have an IPv6 transport-specifier strip it
5233 $desthost =~ s/^(?:udp6:|udpv6:|udpipv6:)//x;
5234  
5235 my $ip = NetAddr::IP::Lite->new($desthost);
5236  
5237 if ($ip and $ip->bits == 32) {
5238 return $ip->addr;
5239 }
5240 elsif ($ip and $ip->bits == 128) {
5241 return 'udp6:' . $ip->addr;
5242 }
5243 else {
5244 croak "Unable to resolve DestHost: $desthost to an IP\n";
5245 }
5246 }
5247  
5248 =item $info->init()
5249  
5250 Used internally. Loads all entries in %MIBS.
5251  
5252 =cut
5253  
5254 sub init {
5255 my $self = shift;
5256  
5257 # Get MibDirs if provided
5258 my $mibdirs = $self->{mibdirs} || [];
5259  
5260 # SNMP::initMib and SNMP::addMibDirs both look for some initial MIBs
5261 # so if we are not using Net-SNMP configuration files we need to
5262 # specify where the MIBs are before those calls.
5263  
5264 # Ignore snmp.conf and snmp.local.conf files if IgnoreNetSNMPConf
5265 # specified
5266 local $ENV{'SNMPCONFPATH'} = '' if $self->{IgnoreNetSNMPConf};
5267 # We need to provide MIBDIRS if we are not getting them from a
5268 # configuration file
5269 my $mibdir = join (':', @$mibdirs);
5270 local $ENV{'MIBDIRS'} = "$mibdir" if $self->{IgnoreNetSNMPConf};
5271  
5272 SNMP::initMib;
5273  
5274 my $version = $SNMP::VERSION;
5275 my ( $major, $minor, $rev ) = split( '\.', $version );
5276  
5277 if ( $major < 5 ) {
5278  
5279 # Seems to work under 4.2.0
5280 }
5281 elsif ( $major == 5 and $minor == 0 and $rev < 2 ) {
5282 carp("Net-SNMP 5.0.1 seems to be rather buggy. Upgrade.\n");
5283  
5284 # This is a bug in net-snmp 5.0.1 perl module
5285 # see http://groups.google.com/groups?th=47aed6bf7be6a0f5
5286 SNMP::init_snmp("perl");
5287 }
5288  
5289 foreach my $d (@$mibdirs) {
5290 next unless -d $d;
5291 print "SNMP::Info::init() - Adding new mibdir:$d\n"
5292 if $self->debug() > 1;
5293 SNMP::addMibDirs($d);
5294 }
5295  
5296 my $mibs = $self->mibs();
5297  
5298 foreach my $mib ( keys %$mibs ) {
5299  
5300 #print "SNMP::Info::init() - Loading mib:$mib\n" if $self->debug();
5301 SNMP::loadModules("$mib");
5302  
5303 unless ( defined $SNMP::MIB{ $mibs->{$mib} } ) {
5304 croak "The $mib did not load. See README for $self->{class}\n";
5305 }
5306 }
5307 return;
5308 }
5309  
5310 =item $info->args()
5311  
5312 Returns a reference to the argument hash supplied to SNMP::Session
5313  
5314 =cut
5315  
5316 sub args {
5317 my $self = shift;
5318 return $self->{args};
5319 }
5320  
5321 =item $info->class()
5322  
5323 Returns the class name of the object.
5324  
5325 =cut
5326  
5327 sub class {
5328 my $self = shift;
5329 return $self->{class};
5330 }
5331  
5332 =item $info->error_throw(error message)
5333  
5334 Stores the error message for use by $info->error()
5335  
5336 If $info->debug() is true, then the error message is carped too.
5337  
5338 =cut
5339  
5340 sub error_throw {
5341 my $self = shift;
5342 my $error = shift;
5343  
5344 return unless defined $error;
5345 $self->{error} = $error;
5346  
5347 if ( $self->debug() ) {
5348 $error =~ s/\n+$//;
5349 carp($error);
5350 }
5351 return;
5352 }
5353  
5354 =item $info->funcs()
5355  
5356 Returns a reference to the %FUNCS hash.
5357  
5358 =cut
5359  
5360 sub funcs {
5361 my $self = shift;
5362 return $self->{funcs};
5363 }
5364  
5365 =item $info->globals()
5366  
5367 Returns a reference to the %GLOBALS hash.
5368  
5369 =cut
5370  
5371 sub globals {
5372 my $self = shift;
5373 return $self->{globals};
5374 }
5375  
5376 =item $info->mibs()
5377  
5378 Returns a reference to the %MIBS hash.
5379  
5380 =cut
5381  
5382 sub mibs {
5383 my $self = shift;
5384 return $self->{mibs};
5385 }
5386  
5387 =item $info->munge()
5388  
5389 Returns a reference of the %MUNGE hash.
5390  
5391 =cut
5392  
5393 sub munge {
5394 my $self = shift;
5395 return $self->{munge};
5396 }
5397  
5398 =item $info->nosuch()
5399  
5400 Returns NoSuch value set or not in new()
5401  
5402 =cut
5403  
5404 sub nosuch {
5405 my $self = shift;
5406 return $self->{nosuch};
5407 }
5408  
5409 =item $info->session()
5410  
5411 Gets or Sets the SNMP::Session object.
5412  
5413 =cut
5414  
5415 sub session {
5416 my $self = shift;
5417 $self->{sess} = $_[0] if @_;
5418 return $self->{sess};
5419 }
5420  
5421 =item $info->store(new_store)
5422  
5423 Returns or sets hash store for Table functions.
5424  
5425 Store is a hash reference in this format :
5426  
5427 $info->store = { attribute => { iid => value , iid2 => value2, ... } };
5428  
5429 =cut
5430  
5431 sub store {
5432 my $self = shift;
5433 $self->{store} = $_[0] if @_;
5434 return $self->{store};
5435 }
5436  
5437 =item $info->_global()
5438  
5439 Used internally by AUTOLOAD to create dynamic methods from %GLOBALS or a
5440 single instance MIB Leaf node name from a loaded MIB.
5441  
5442 Example: $info->name() on the first call dispatches to AUTOLOAD() which
5443 calls $info->_global('name') creating the method name().
5444  
5445 These methods return data as a scalar.
5446  
5447 =cut
5448  
5449 sub _global {
5450 my $method = shift;
5451 my $oid = shift;
5452  
5453 return sub {
5454 my $self = shift;
5455  
5456 my $sess = $self->session();
5457 return unless defined $sess;
5458  
5459 my $load = $method =~ /^load/;
5460 my $raw = $method =~ /raw$/;
5461  
5462 my $attr = $method;
5463 $attr =~ s/^(load|orig)_//;
5464 $attr =~ s/_raw$//;
5465  
5466 # Return cached data unless loading
5467 # We now store in raw format so munge before returning
5468 # unless expecting raw data
5469 if ( exists $self->{"_$attr"} && !$load ) {
5470 my $val = $self->{"_$attr"};
5471  
5472 if ( !$raw ) {
5473 return $self->_munge($attr, $val);
5474 } else{
5475 return $val;
5476 }
5477 }
5478  
5479 if ( $self->{Offline} ) {
5480 $self->error_throw(
5481 "SNMP::Info::_global: Offline but $attr is not in cache\n" );
5482 return;
5483 }
5484  
5485 if ( $self->debug() ) {
5486 # Let's get the MIB Module and leaf name along with the OID
5487 my $qual_leaf = SNMP::translateObj($oid,0,1) || '';
5488 print "SNMP::Info::_global $method : $qual_leaf : $oid\n";
5489 }
5490 my $val = $sess->get($oid);
5491  
5492 # Mark as gotten. Even if it fails below, we don't want to keep failing.
5493 $self->{"_$attr"} = undef;
5494  
5495 if ( $sess->{ErrorStr} ) {
5496 $self->error_throw(
5497 "SNMP::Info::_global($method) $sess->{ErrorStr}");
5498 return;
5499 }
5500  
5501 if ( defined $val and $val eq 'NOSUCHOBJECT' ) {
5502 $self->error_throw("SNMP::Info::_global($method) NOSUCHOBJECT");
5503 return;
5504 }
5505  
5506 if ( defined $val and $val eq 'NOSUCHINSTANCE' ) {
5507 $self->error_throw("SNMP::Info::_global($method) NOSUCHINSTANCE");
5508 return;
5509 }
5510  
5511 # Save Cached Value
5512 $self->_cache($attr, $val);
5513  
5514 # Data Munging
5515 if ( !$raw ) {
5516 $val = $self->_munge($attr, $val);
5517 }
5518  
5519 return $val;
5520 }
5521 }
5522  
5523 =item $info->_set(attr,val,iid,type)
5524  
5525 Used internally by set_multi() to run an SNMP set command. When run
5526 clears attr cache.
5527  
5528 Attr can be passed as either a scalar or a reference to an array or array
5529 of arrays when used with set_multi().
5530  
5531 Example: $info->set_name('dog',3) uses autoload to resolve to
5532 $info->_set('name','dog',3);
5533  
5534 =cut
5535  
5536 sub _set {
5537 my ( $self, $attr, $val, $iid, $type ) = @_;
5538 my $varbind_list_ref;
5539  
5540 if ( !ref($attr) ) {
5541 $varbind_list_ref = [ [ $attr, $iid, $val, $type ] ];
5542 }
5543 elsif ( ref($attr) =~ /ARRAY/ ) {
5544 $varbind_list_ref = [$attr];
5545 $varbind_list_ref = $attr if ref( $$attr[0] ) =~ /ARRAY/;
5546 }
5547 else {
5548 $self->error_throw(
5549 "SNMP::Info::_set - Failed. Invalid arguments"
5550 );
5551 return;
5552 }
5553  
5554 my $sess = $self->session();
5555 return unless defined $sess;
5556  
5557 my $funcs = $self->funcs();
5558 my $globals = $self->globals();
5559  
5560 foreach my $var_list (@$varbind_list_ref) {
5561 my $list_attr = $var_list->[0];
5562 my $list_iid = $var_list->[1];
5563 my $list_val = $var_list->[2];
5564  
5565 # Get rid of non-printable chars in $list_val for debug statements
5566 $list_val =~ s/\W//;
5567  
5568 # Instance is 0 for scalars without a supplied instance
5569 $var_list->[1] = $list_iid = defined $list_iid ? $list_iid : '0';
5570  
5571 # Lookup oid
5572 my $oid = undef;
5573 $oid = $list_attr if SNMP::translateObj($list_attr);
5574 $oid = $globals->{$list_attr} if defined $globals->{$list_attr};
5575 $oid = $funcs->{$list_attr} if defined $funcs->{$list_attr};
5576  
5577 unless ( defined $oid ) {
5578 $self->error_throw(
5579 "SNMP::Info::_set($list_attr,$list_val) - Failed to find $list_attr in \%GLOBALS or \%FUNCS or loaded MIB."
5580 );
5581 return;
5582 }
5583  
5584 # Check for fully qualified attr
5585 if ( $oid =~ /__/ ) {
5586 $oid =~ s/__/::/;
5587 $oid =~ s/_/-/g;
5588 }
5589  
5590 $var_list->[0] = $oid;
5591  
5592 $self->debug()
5593 and print
5594 "SNMP::Info::_set $list_attr.$list_iid ($oid.$list_iid) = $list_val\n";
5595 delete $self->{"_$list_attr"};
5596 }
5597  
5598 my $rv = $sess->set($varbind_list_ref);
5599  
5600 if ( $sess->{ErrorStr} ) {
5601 $self->error_throw("SNMP::Info::_set $sess->{ErrorStr}");
5602 return;
5603 }
5604  
5605 return $rv;
5606 }
5607  
5608 =item $info->_make_setter(val,iid)
5609  
5610 Used internally by AUTOLOAD to create dynamic methods from either %GLOBALS,
5611 %FUNCS, or a valid mib leaf from a loaded MIB which runs an SNMP set command.
5612 When run clears the attribute cache.
5613  
5614 Example: $info->set_name('dog',3) dispatches to autoload to resolve to
5615 $info->_set('name','dog',3) and _make_setter creates the set_name() method.
5616  
5617 =cut
5618  
5619 sub _make_setter {
5620 my $method = shift;
5621 my $oid = shift;
5622  
5623 return sub {
5624 my $self = shift;
5625 my $val = shift;
5626 my $iid = shift;
5627  
5628 my $set_oid = $oid;
5629 my $globals = $self->globals();
5630 my $attr = $method;
5631 $attr =~ s/^set_//;
5632  
5633 # The only thing which may give us the iid in $oid should be
5634 # a %GLOBALS entry appended with a number. In that case strip it
5635 # from the OID and use it as $iid
5636 if ( defined $globals->{$attr} && $globals->{$attr} =~ /(\.\d+$)/ ) {
5637 $iid = $1;
5638 $set_oid =~ s/$iid//;
5639 }
5640  
5641 # If we don't have $iid now we should be a %GLOBALS entry or single
5642 # instance MIB leaf so default to zero
5643 $iid = defined $iid ? $iid : '.0';
5644  
5645 # prepend dot if necessary to $iid
5646 $iid = ".$iid" unless $iid =~ /^\./;
5647  
5648 my $sess = $self->session();
5649 return unless defined $sess;
5650  
5651 $set_oid .= "$iid";
5652  
5653 $self->debug()
5654 and print "SNMP::Info::_set $method$iid ($set_oid) = $val\n";
5655 delete $self->{"_$attr"};
5656  
5657 my $rv = $sess->set( $set_oid, $val );
5658  
5659 if ( $sess->{ErrorStr} ) {
5660 $self->error_throw("SNMP::Info::_set $sess->{ErrorStr}");
5661 return;
5662 }
5663 return $rv;
5664 }
5665 }
5666  
5667 =item $info->set_multi(arrayref)
5668  
5669 Used to run an SNMP set command on several new values in the one request.
5670 Returns the result of $info->_set(method).
5671  
5672 Pass either a reference to a 4 element array [<obj>, <iid>, <val>, <type>] or
5673 a reference to an array of 4 element arrays to specify multiple values.
5674  
5675 <obj> - One of the following forms:
5676 1) leaf identifier (e.g., C<'sysContact'>)
5677 2) An entry in either %FUNCS, %GLOBALS (e.g., 'contact')
5678 <iid> - The dotted-decimal, instance identifier. For scalar MIB objects
5679 use '0'
5680 <val> - The SNMP data value being set (e.g., 'netdisco')
5681 <type> - Optional as the MIB should be loaded.
5682  
5683 If one of the set assignments is invalid, then the request will be rejected
5684 without applying any of the new values - regardless of the order they appear
5685 in the list.
5686  
5687 Example:
5688 my $vlan_set = [
5689 ['qb_v_untagged',"$old_vlan_id","$old_untagged_portlist"],
5690 ['qb_v_egress',"$new_vlan_id","$new_egress_portlist"],
5691 ['qb_v_egress',"$old_vlan_id","$old_egress_portlist"],
5692 ['qb_v_untagged',"$new_vlan_id","$new_untagged_portlist"],
5693 ['qb_i_vlan',"$port","$new_vlan_id"],
5694 ];
5695  
5696 $info->set_multi($vlan_set);
5697  
5698 =cut
5699  
5700 sub set_multi {
5701 my $self = shift;
5702  
5703 return $self->_set(@_);
5704 }
5705  
5706 =item $info->load_all()
5707  
5708 Debugging routine. This does not include any overridden method or method
5709 implemented by subroutine.
5710  
5711 Runs $info->load_METHOD() for each entry in $info->funcs();
5712  
5713 Returns $info->store() -- See store() entry.
5714  
5715 Note return value has changed since version 0.3
5716  
5717 =cut
5718  
5719 sub load_all {
5720 my $self = shift;
5721 my $sess = $self->session();
5722 return unless defined $sess;
5723  
5724 my $funcs = $self->funcs();
5725  
5726 foreach my $attrib ( keys %$funcs ) {
5727 $attrib = "load_$attrib";
5728 $self->$attrib();
5729 }
5730  
5731 $self->{_all}++;
5732  
5733 return unless defined wantarray;
5734  
5735 return $self->store();
5736 }
5737  
5738 =item $info->all()
5739  
5740 Runs $info->load_all() once then returns $info->store();
5741  
5742 Use $info->load_all() to reload the data.
5743  
5744 Note return value has changed since version 0.3
5745  
5746 =cut
5747  
5748 sub all {
5749 my $self = shift;
5750 my $sess = $self->session();
5751 return unless defined $sess;
5752  
5753 $self->load_all() unless defined $self->{_all};
5754  
5755 return $self->store();
5756 }
5757  
5758 =item $info->_load_attr()
5759  
5760 Used internally by AUTOLOAD to create dynamic methods from %FUNCS
5761 or a MIB Leaf node name contained within a table of a loaded MIB.
5762  
5763 Supports partial table fetches and single instance table fetches.
5764 See L<SNMP::Info/"Partial Table Fetches">.
5765  
5766 These methods return data as a reference to a hash.
5767  
5768 =cut
5769  
5770 sub _load_attr {
5771 my $method = shift;
5772 my $oid = shift;
5773  
5774 return sub {
5775 my $self = shift;
5776 my $partial = shift;
5777  
5778 my $sess = $self->session();
5779 return unless defined $sess;
5780  
5781 my $ver = $self->snmp_ver();
5782  
5783 my $load = $method =~ /^load/;
5784 my $raw = $method =~ /raw$/;
5785  
5786 my $attr = $method;
5787 $attr =~ s/^(load|orig)_//;
5788 $attr =~ s/_raw$//;
5789  
5790 # Return cached data unless loading or partial
5791 # We now store in raw format so munge before returning
5792 # unless expecting raw data
5793 return $self->_show_attr($attr, $raw)
5794 if ( defined $self->{"_${attr}"}
5795 && !$load
5796 && !defined $partial );
5797  
5798 if ( $self->{Offline} ) {
5799 $self->error_throw(
5800 "SNMP::Info::_load_attr: Offline but $attr is not in cache\n" );
5801 return;
5802 }
5803  
5804 # So devices speaking SNMP v.1 are not supposed to give out
5805 # data from SNMP2, but most do. Net-SNMP, being very precise
5806 # will tell you that the SNMP OID doesn't exist for the device.
5807 # They have a flag RetryNoSuch that is used for get() operations,
5808 # but not for getnext(). We set this flag normally, and if we're
5809 # using V1, let's try and fetch the data even if we get one of those.
5810  
5811 my $w = {
5812 method => $method,
5813 oid => $oid,
5814 sess => $sess,
5815 ver => $ver,
5816 raw => $raw,
5817 attr => $attr,
5818 partial => $partial,
5819 localstore => undef,
5820 errornum => 0,
5821 seen => {},
5822 walk => 'getnext',
5823 reason => undef,
5824 walk_error => undef,
5825 walk_errno => 0,
5826 bulkwalk_failed => 0,
5827 probed => 0,
5828 vars => [],
5829 recovery => [],
5830 };
5831  
5832 $self->_walk_setup($w);
5833 $self->_walk_partial_get($w);
5834 $self->_walk_bulk($w);
5835 $self->_walk_rows($w);
5836 return $self->_walk_finish($w);
5837 }
5838 }
5839  
5840 =item $info->_walk_setup(\%w)
5841  
5842 Fills in the walk state for one C<_load_attr> call: the qualified and bare
5843 leaf names, the varbind, the repeaters, and whether to bulkwalk.
5844  
5845 =cut
5846  
5847 sub _walk_setup {
5848 my ( $self, $w ) = @_;
5849 my ( $method, $oid, $partial, $ver ) = @{$w}{qw(method oid partial ver)};
5850  
5851 # We want the qualified leaf name so that we can
5852 # specify the Module (MIB) in the case of private leaf naming
5853 # conflicts. Example: ALTEON-TIGON-SWITCH-MIB::agSoftwareVersion
5854 # and ALTEON-CHEETAH-SWITCH-MIB::agSoftwareVersion
5855 # Third argument to translateObj specifies the Module prefix
5856  
5857 $w->{qual_leaf} = SNMP::translateObj($oid,0,1) || '';
5858  
5859 # We still want just the leaf since a SNMP get in the case of a
5860 # partial fetch may strip the Module portion upon return. We need
5861 # the match to make sure we didn't leave the table during getnext
5862 # requests
5863  
5864 ( $w->{leaf} ) = $w->{qual_leaf} =~ /::(.+)$/;
5865  
5866 # If we weren't able to translate, we'll only have an OID
5867 $w->{leaf} = $oid unless defined $w->{leaf};
5868  
5869 $self->debug()
5870 and print "SNMP::Info::_load_attr $method : $w->{qual_leaf}",
5871 defined $partial ? "($partial)" : '', " : $oid" ,
5872 defined $partial ? ".$partial" : '', "\n";
5873  
5874 $w->{var} = SNMP::Varbind->new( [$w->{qual_leaf}, $partial] );
5875  
5876 my $bulkwalk_no
5877 = $self->can('bulkwalk_no') ? $self->bulkwalk_no() : 0;
5878 my $bulkwalk_on = defined $self->{BulkWalk} ? $self->{BulkWalk} : 1;
5879 my $can_bulkwalk = $bulkwalk_on && !$bulkwalk_no;
5880 my $state = $self->_walk_recovery();
5881 $w->{repeaters} = $self->_walk_start_repeaters($w);
5882 $w->{bulkwalk}
5883 = $can_bulkwalk
5884 && $ver != 1
5885 && !$state->{getnext}
5886 && !$self->_walk_table($w)->{getnext}
5887 && !$state->{contexts}{ $self->_walk_context() }
5888 && !$self->_walk_at_cap();
5889 $w->{loopdetect}
5890 = defined $self->{LoopDetect} ? $self->{LoopDetect} : 1;
5891 return;
5892 }
5893  
5894 =item $info->_walk_partial_get(\%w)
5895  
5896 For a partial fetch, tries a GET first in case the partial is a leaf OID,
5897 and records its result or failure in the walk state.
5898  
5899 =cut
5900  
5901 sub _walk_partial_get {
5902 my ( $self, $w ) = @_;
5903 my ( $sess, $ver, $var ) = @{$w}{qw(sess ver var)};
5904  
5905 if ( defined $w->{partial} ) {
5906  
5907 # Try a GET, in case the partial is a leaf OID.
5908 # Would like to only do this if we know the OID is
5909 # long enough; implementing that would require a
5910 # lot of MIB mucking.
5911 my $try = $sess->get($var);
5912 $w->{errornum} = $sess->{ErrorNum};
5913 if ( defined($try) && $w->{errornum} == 0 && $try !~ /^NOSUCH/ ) {
5914 $var->[2] = $try;
5915 $w->{vars} = [$var];
5916 $w->{bulkwalk} = 1; # fake a bulkwalk return
5917 $w->{walk} = 'get';
5918 }
5919  
5920 # We want to execute the while loop below for the getnext request.
5921 if ( _v1_nosuch( $sess, $ver ) ) {
5922 $w->{errornum} = 0;
5923 }
5924 elsif ( $w->{errornum} ) {
5925 $w->{walk} = 'get';
5926 @{$w}{qw(reason walk_errno walk_error)} = _walk_failure($sess)
5927 unless _nosuch_end($sess);
5928 }
5929 }
5930 return;
5931 }
5932  
5933 =item $info->_walk_bulk(\%w)
5934  
5935 Runs the bulkwalk when the walk state allows one. A bulkwalk that fails
5936 with C<toobig> or C<timeout> while C<BulkBackoff> is on is retried with
5937 half the repeaters, unless C<_walk_unreachable> finds the context does not
5938 answer at all. That check runs only in a VLAN, VRF or SNMPv3 context. When
5939 the halved value is below C<$BACKOFF_FLOOR>, the object has failed
5940 C<$MAX_FAILED_BULKWALKS> bulkwalks, or a bulkwalk fails with
5941 C<nonincreasing> while C<BulkOrderCheck> is on, sets the walk state up to
5942 re-walk the table by GETNEXT instead.
5943  
5944 =cut
5945  
5946 sub _walk_bulk {
5947 my ( $self, $w ) = @_;
5948 my $sess = $w->{sess};
5949  
5950 # Use BULKWALK if we can because its faster
5951 return unless $w->{bulkwalk} && @{ $w->{vars} } == 0 && !$w->{errornum};
5952 $w->{walk} = 'bulkwalk';
5953  
5954 while (1) {
5955 ( $w->{vars} ) = $self->_walk_bulkwalk_call($w);
5956 return unless $sess->{ErrorNum};
5957  
5958 $w->{errornum} = $sess->{ErrorNum};
5959 @{$w}{qw(reason walk_errno walk_error)} = _walk_failure($sess)
5960 unless _nosuch_end($sess);
5961 $self->error_throw(
5962 "SNMP::Info::_load_attr: BULKWALK " . $sess->{ErrorStr}, "\n" );
5963  
5964 my $retry = $self->_walk_bulk_retry_reason($w);
5965 if ( !$retry or $self->_walk_unreachable( $w, $retry ) ) {
5966 $w->{bulkwalk_failed} = 1;
5967 return;
5968 }
5969 $self->_walk_bulk_step($w);
5970 next
5971 if $retry ne 'nonincreasing'
5972 and $self->_walk_backoff( $w, $retry );
5973  
5974 $self->_walk_getnext_fallback( $w, $retry );
5975 return;
5976 }
5977 }
5978  
5979 =item $info->_walk_unreachable(\%w, retry)
5980  
5981 On the table's first bulkwalk C<timeout> in a VLAN, VRF or SNMPv3 context,
5982 sends one GETNEXT for the table's first row. When that also times out,
5983 marks the context unreachable and returns true: the table is not
5984 recovered, and later tables in the context skip the bulkwalk. Nothing
5985 counts toward C<$MAX_FAILED_BULKWALKS>. Otherwise returns false. In the
5986 base context (C<_walk_context> returns an empty string) no probe is sent
5987 and the context is never marked, so the table backs off as for any
5988 timeout.
5989  
5990 =cut
5991  
5992 sub _walk_unreachable {
5993 my ( $self, $w, $retry ) = @_;
5994 my $sess = $w->{sess};
5995  
5996 return 0 if $retry ne 'timeout' or $w->{probed};
5997 my $context = $self->_walk_context();
5998 return 0 if $context eq '';
5999 $w->{probed} = 1;
6000  
6001 my $probe = SNMP::Varbind->new( [ $w->{qual_leaf}, $w->{partial} ] );
6002 $sess->getnext($probe);
6003 return 0 unless ( $sess->{ErrorNum} || 0 ) == -24; # SNMPERR_TIMEOUT
6004  
6005 $self->_walk_recovery()->{contexts}{$context} = 1;
6006 return 1;
6007 }
6008  
6009 =item $info->_walk_bulk_retry_reason(\%w)
6010  
6011 Returns the reason of the bulkwalk that just failed when SNMP::Info
6012 recovers from it: C<nonincreasing> with C<BulkOrderCheck> on, C<toobig> or
6013 C<timeout> with C<BulkBackoff> on. Otherwise returns undef.
6014  
6015 =cut
6016  
6017 sub _walk_bulk_retry_reason {
6018 my ( $self, $w ) = @_;
6019 my $errornum = $w->{errornum};
6020  
6021 # SNMPERR_OID_NONINCREASING
6022 return 'nonincreasing' if $errornum == -65 and $self->bulk_order_check();
6023 return unless $self->bulk_backoff();
6024 return 'toobig' if $errornum == 1; # SNMP_ERR_TOOBIG
6025 return 'timeout' if $errornum == -24; # SNMPERR_TIMEOUT
6026 return;
6027 }
6028  
6029 =item $info->_walk_bulkwalk_call(\%w)
6030  
6031 The only place C<_load_attr> calls C<bulkwalk> on the session. With
6032 C<BulkOrderCheck> on, sets the session's C<NonIncreasing> to 1 for this
6033 call only, so out-of-order rows fail with C<-65> instead of being dropped.
6034  
6035 =cut
6036  
6037 sub _walk_bulkwalk_call {
6038 my ( $self, $w ) = @_;
6039 my $sess = $w->{sess};
6040  
6041 return $sess->bulkwalk( 0, $w->{repeaters}, $w->{var} )
6042 unless $self->bulk_order_check();
6043  
6044 local $sess->{NonIncreasing} = 1;
6045 return $sess->bulkwalk( 0, $w->{repeaters}, $w->{var} );
6046 }
6047  
6048 =item $info->_walk_bulk_step(\%w)
6049  
6050 After a bulkwalk failed in a way SNMP::Info recovers from: records the
6051 recovery step, counts the failure against the object, and resets the
6052 walk state for the next attempt.
6053  
6054 =cut
6055  
6056 sub _walk_bulk_step {
6057 my ( $self, $w ) = @_;
6058  
6059 push @{ $w->{recovery} },
6060 {
6061 walk => 'bulkwalk',
6062 repeaters => $w->{repeaters},
6063 reason => $w->{reason},
6064 errornum => $w->{walk_errno},
6065 };
6066 $self->_walk_recovery()->{failed}++;
6067  
6068 @{$w}{qw(errornum walk_errno reason walk_error)} = ( 0, 0, undef, undef );
6069 $w->{vars} = [];
6070 $w->{var} = SNMP::Varbind->new( [ $w->{qual_leaf}, $w->{partial} ] );
6071 return;
6072 }
6073  
6074 =item $info->_walk_backoff(\%w, reason)
6075  
6076 Halves the repeaters of the walk and returns true, unless the halved value
6077 is below C<$BACKOFF_FLOOR> or the object has failed
6078 C<$MAX_FAILED_BULKWALKS> (9) bulkwalks. The halved value is kept for the
6079 object when C<reason> is C<toobig>, and for the table alone when it is
6080 C<timeout>. When it returns false, the limit that stopped it, C<floor> or
6081 C<cap>, is left in C<< $w->{backoff_stop} >>. The floor is checked first.
6082  
6083 =cut
6084  
6085 sub _walk_backoff {
6086 my ( $self, $w, $reason ) = @_;
6087 my $state = $self->_walk_recovery();
6088 my $repeaters = int( $w->{repeaters} / 2 );
6089  
6090 $w->{backoff_stop} = 'floor';
6091 return 0 if $repeaters < $BACKOFF_FLOOR;
6092 $w->{backoff_stop} = 'cap';
6093 return 0 if $self->_walk_at_cap();
6094  
6095 delete $w->{backoff_stop};
6096 $w->{repeaters} = $repeaters;
6097 if ( $reason eq 'timeout' ) {
6098 $self->_walk_table_set( $w, repeaters => $repeaters );
6099 }
6100 else {
6101 $state->{toobig_repeaters} = $repeaters;
6102 }
6103 return 1;
6104 }
6105  
6106 =item $info->_walk_at_cap()
6107  
6108 Returns true when the object has failed C<$MAX_FAILED_BULKWALKS>
6109 bulkwalks, so no table is walked by bulkwalk any more.
6110  
6111 =cut
6112  
6113 sub _walk_at_cap {
6114 my $self = shift;
6115 return $self->_walk_recovery()->{failed} >= $MAX_FAILED_BULKWALKS;
6116 }
6117  
6118 =item $info->_walk_getnext_fallback(\%w, reason)
6119  
6120 Sets the walk state up so that C<_walk_rows> re-walks the table from its
6121 start by GETNEXT. A C<timeout> that stopped at the floor, and a
6122 C<nonincreasing> failure, switch only the table to GETNEXT, unless the
6123 object has failed C<$MAX_FAILED_BULKWALKS> bulkwalks, which counts as the
6124 C<cap> whatever stopped the walk. Every other reason, and any walk stopped by
6125 the cap, switches the object.
6126  
6127 =cut
6128  
6129 sub _walk_getnext_fallback {
6130 my ( $self, $w, $reason ) = @_;
6131 my $state = $self->_walk_recovery();
6132 $w->{backoff_stop} = 'cap' if $self->_walk_at_cap();
6133 my $table_only = ( $w->{backoff_stop} || '' ) ne 'cap'
6134 && ( $reason eq 'timeout' or $reason eq 'nonincreasing' );
6135  
6136 if ($table_only) {
6137 $self->_walk_table_set( $w, getnext => 1, getnext_reason => $reason );
6138 }
6139 else {
6140 $state->{getnext} = 1;
6141 }
6142 $w->{bulkwalk} = 0;
6143 $w->{walk} = 'getnext';
6144 return;
6145 }
6146  
6147 =item $info->_walk_rows(\%w)
6148  
6149 Reads rows from the bulkwalk result or by GETNEXT into the walk state's
6150 C<localstore>, stopping at the end of the table, the partial, or a loop.
6151  
6152 =cut
6153  
6154 sub _walk_rows {
6155 my ( $self, $w ) = @_;
6156 my ( $sess, $ver, $method, $oid ) = @{$w}{qw(sess ver method oid)};
6157 my ( $leaf, $partial, $seen ) = @{$w}{qw(leaf partial seen)};
6158  
6159 while ( !$w->{errornum} ) {
6160 if ( $w->{bulkwalk} ) {
6161 $w->{var} = shift @{ $w->{vars} } or last;
6162 }
6163 else {
6164  
6165 # GETNEXT instead of BULKWALK
6166 $sess->getnext( $w->{var} );
6167 $w->{errornum} = $sess->{ErrorNum};
6168  
6169 # A failed request leaves the varbind as it was sent, so
6170 # leave before it is read. noSuchName ends the view.
6171 if ( $w->{errornum} ) {
6172 @{$w}{qw(reason walk_errno walk_error)}
6173 = _walk_failure($sess)
6174 unless _nosuch_end($sess)
6175 or _v1_nosuch( $sess, $ver );
6176 last;
6177 }
6178 }
6179  
6180 if ( $self->debug() > 1 ) {
6181 use Data::Dumper;
6182 print "SNMP::Info::_load_attr $method : leaf = $oid , var = ",
6183 Dumper( $w->{var} );
6184 }
6185  
6186 _split_non_leaf_tag( $w->{var}, $w->{qual_leaf}, $leaf );
6187  
6188 # Check if we've left the requested subtree
6189 last if $w->{var}->[0] !~ /$leaf$/;
6190 my $iid = $w->{var}->[1];
6191 my $val = $w->{var}->[2];
6192  
6193 unless ( defined $iid ) {
6194 $self->error_throw(
6195 "SNMP::Info::_load_attr: $method not here");
6196 next;
6197 }
6198  
6199 # Check to make sure we are still in partial land
6200 if ( defined $partial
6201 and $iid !~ /^$partial$/
6202 and $iid !~ /^$partial\./ )
6203 {
6204 $self->debug()
6205 and print "$iid makes us leave partial land.\n";
6206 last;
6207 }
6208  
6209 # Check if last element, V2 devices may report ENDOFMIBVIEW even if
6210 # instance or object doesn't exist.
6211 if ( $val eq 'ENDOFMIBVIEW' ) {
6212 last;
6213 }
6214  
6215 # Similarly for SNMPv1 - noSuchName return results in both $iid
6216 # and $val being empty strings.
6217 if ( $val eq '' and $iid eq '' ) {
6218 last;
6219 }
6220  
6221 # Another check for SNMPv1 - noSuchName return may results in an $iid
6222 # we've already seen and $val an empty string. If we don't catch
6223 # this here we erroneously report a loop below.
6224 if ( defined $seen->{$iid} and $seen->{$iid} and $val eq '' ) {
6225 last;
6226 }
6227  
6228 if ( $w->{loopdetect} ) {
6229  
6230 # Check to see if we've already seen this IID (looping)
6231 if ( defined $seen->{$iid} and $seen->{$iid} ) {
6232 $w->{walk_error} = "Looping on: $method iid:$iid.";
6233 $self->error_throw("$w->{walk_error} ");
6234 $w->{reason} = 'loop';
6235 last;
6236 }
6237 else {
6238 $seen->{$iid}++;
6239 }
6240 }
6241  
6242 if ( $val eq 'NOSUCHOBJECT' ) {
6243 $self->error_throw(
6244 "SNMP::Info::_load_attr: $method : NOSUCHOBJECT");
6245 next;
6246 }
6247 if ( $val eq 'NOSUCHINSTANCE' ) {
6248 $self->error_throw(
6249 "SNMP::Info::_load_attr: $method : NOSUCHINSTANCE");
6250 next;
6251 }
6252  
6253 $w->{localstore}->{$iid} = $val;
6254  
6255 }
6256 return;
6257 }
6258  
6259 =item _split_non_leaf_tag($varbind, $qual_leaf, $leaf)
6260  
6261 When no loaded MIB defines the column, net-snmp cannot tell where the
6262 instance starts, so it returns the whole OID as the tag and an empty iid.
6263 GETNEXT keeps the module prefix on that tag and GET and bulkwalk drop it.
6264 When the tag extends C<$qual_leaf> or C<$leaf>, moves the remainder into
6265 the iid.
6266  
6267 =cut
6268  
6269 sub _split_non_leaf_tag {
6270 my ( $var, @columns ) = @_;
6271 return if length( $var->[1] // '' );
6272  
6273 foreach my $column ( grep { defined and length } @columns ) {
6274 my $prefix = "$column.";
6275 next if index( $var->[0], $prefix ) != 0;
6276 $var->[1] = substr( $var->[0], length $prefix );
6277 $var->[0] = $column;
6278 return;
6279 }
6280 return;
6281 }
6282  
6283 =item $info->_walk_note_slow(\%w)
6284  
6285 Called once per walk, after its last bulkwalk or GETNEXT attempt. When the
6286 walk recovered from a C<timeout> on a live agent (a C<timeout> step in
6287 C<recovery>) and its table is not yet slow, marks the table slow, keeping
6288 the repeaters of the bulkwalk that completed it, or undef when it ended on
6289 GETNEXT or on a failed bulkwalk, and counts it in C<slow_tables>. When
6290 C<slow_tables> reaches C<$SLOW_DEVICE_TABLES> and C<slow_repeaters> is not
6291 set, sets it to the smallest repeaters kept by a slow table, or to
6292 C<$BACKOFF_FLOOR> when there is none.
6293  
6294 =cut
6295  
6296 sub _walk_note_slow {
6297 my ( $self, $w ) = @_;
6298 my $state = $self->_walk_recovery();
6299 my $final
6300 = ( $w->{walk} eq 'bulkwalk' && !$w->{bulkwalk_failed} )
6301 ? $w->{repeaters}
6302 : undef;
6303  
6304 return unless grep { $_->{reason} eq 'timeout' } @{ $w->{recovery} };
6305 return if $self->_walk_table($w)->{slow};
6306  
6307 $self->_walk_table_set( $w, slow => 1, slow_final => $final );
6308 $state->{slow_tables}++;
6309 return
6310 if $state->{slow_tables} < $SLOW_DEVICE_TABLES
6311 or defined $state->{slow_repeaters};
6312  
6313 my ($smallest) = sort { $a <=> $b } grep {defined}
6314 map { $_->{slow_final} } values %{ $state->{tables} };
6315 $state->{slow_repeaters} = defined $smallest ? $smallest : $BACKOFF_FLOOR;
6316 return;
6317 }
6318  
6319 =item $info->_walk_heal_context(\%w, rows)
6320  
6321 Called once per walk, beside C<_walk_note_slow>. When the walk ended by
6322 GETNEXT with at least one row, clears the unreachable mark of the current
6323 context, so later tables in it bulkwalk again.
6324  
6325 =cut
6326  
6327 sub _walk_heal_context {
6328 my ( $self, $w, $rows ) = @_;
6329 return unless $w->{walk} eq 'getnext' and $rows;
6330 delete $self->_walk_recovery()->{contexts}{ $self->_walk_context() };
6331 return;
6332 }
6333  
6334 =item $info->_walk_finish(\%w)
6335  
6336 Records the walk outcome, applies C<IncompleteWalk>, caches a full walk and
6337 munges the rows. Returns what C<_load_attr> returns.
6338  
6339 =cut
6340  
6341 sub _walk_finish {
6342 my ( $self, $w ) = @_;
6343 my ( $attr, $method, $partial, $raw )
6344 = @{$w}{qw(attr method partial raw)};
6345 my ( $reason, $walk, $repeaters ) = @{$w}{qw(reason walk repeaters)};
6346 my $localstore = $w->{localstore};
6347  
6348 $self->_walk_note_slow($w);
6349 my $rows = scalar keys %{ $localstore || {} };
6350 $self->_walk_heal_context( $w, $rows );
6351 $self->_walk_outcome(
6352 { method => $attr,
6353 leaf => $w->{qual_leaf} || $w->{oid},
6354 partial => $partial,
6355 complete => ( _walk_incomplete($reason) ? 0 : 1 ),
6356 reason => $reason,
6357 error => $w->{walk_error},
6358 errornum => $w->{walk_errno},
6359 walk => $walk,
6360 repeaters => ( $walk eq 'bulkwalk' ? $repeaters : undef ),
6361 rows => $rows,
6362 recovery => $w->{recovery},
6363 }
6364 );
6365  
6366 # A failed bulkwalk caches nothing and returns undef, as it always did
6367 return if $w->{bulkwalk_failed};
6368  
6369 if ( _walk_incomplete($reason) ) {
6370 $self->error_throw( "SNMP::Info::_load_attr: $method incomplete: "
6371 . "$reason after $rows rows. "
6372 . ( $w->{walk_error} || '' ) );
6373 return if $self->incomplete_walk() eq 'undef';
6374 }
6375  
6376 # Cache data if we are not getting partial data:
6377 if ( !defined $partial ) {
6378 $self->_cache($attr, $localstore);
6379 }
6380  
6381 # Data Munging
6382 if ( !$raw ) {
6383 $localstore = $self->_munge($attr, $localstore);
6384 }
6385  
6386 return $localstore;
6387 }
6388  
6389 =item _v1_nosuch(sess, ver)
6390  
6391 Returns true when an SNMPv1 request failed with noSuchName. A partial GET
6392 answered this way goes on to walk the table; on other versions it returns
6393 nothing, as it always has.
6394  
6395 =cut
6396  
6397 sub _v1_nosuch {
6398 my ( $sess, $ver ) = @_;
6399 return ( $ver == 1
6400 and $sess->{ErrorNum}
6401 and ( $sess->{ErrorStr} || '' ) =~ /nosuch/i );
6402 }
6403  
6404 =item _nosuch_end(sess)
6405  
6406 Returns true when the request that just failed on the session got error
6407 status noSuchName, which ends a walk cleanly on any SNMP version.
6408  
6409 =cut
6410  
6411 sub _nosuch_end {
6412 my $sess = shift;
6413 return ( ( $sess->{ErrorNum} || 0 ) == 2 ); # SNMP_ERR_NOSUCHNAME
6414 }
6415  
6416 =item _walk_failure(sess)
6417  
6418 Returns the C<reason>, C<ErrorNum> and C<ErrorStr> of the request that just
6419 failed on the session, read before a later request can replace them.
6420  
6421 =cut
6422  
6423 sub _walk_failure {
6424 my $sess = shift;
6425 my $errornum = $sess->{ErrorNum};
6426  
6427 # ErrorNum: negative values are Net-SNMP library errors (SNMPERR_* in
6428 # net-snmp/library/snmp_api.h), positive values the PDU error-status
6429 # (SNMP_ERR_* in net-snmp/library/snmp.h).
6430 my %reasons = (
6431 -24 => 'timeout', # SNMPERR_TIMEOUT
6432 1 => 'toobig', # SNMP_ERR_TOOBIG
6433 -65 => 'nonincreasing', # SNMPERR_OID_NONINCREASING
6434 -58 => 'absent', # SNMPERR_UNKNOWN_OBJID
6435 );
6436 return ( $reasons{$errornum} || 'error', $errornum, $sess->{ErrorStr} );
6437 }
6438  
6439 =item _walk_incomplete(reason)
6440  
6441 Returns true when C<reason> means the walk did not finish. An undefined
6442 reason and C<absent> (the object is not on the device) are both complete.
6443  
6444 =cut
6445  
6446 sub _walk_incomplete {
6447 my $reason = shift;
6448 return ( defined $reason and $reason ne 'absent' );
6449 }
6450  
6451 =item $info->_walk_recovery()
6452  
6453 Returns the hash of bulkwalk recovery state for this object, creating it on
6454 first use as C<< { toobig_repeaters => undef, getnext => 0, failed => 0,
6455 slow_tables => 0, slow_repeaters => undef, contexts => {}, tables => {} } >>.
6456 C<toobig_repeaters> is the object-wide value a tooBig back-off lowered, and
6457 keeps it after C<getnext> is set. C<getnext> is the object-wide GETNEXT
6458 switch and C<failed> counts failed bulkwalks. C<slow_tables> and
6459 C<slow_repeaters> track tables that timed out and recovered. C<contexts>
6460 holds unreachable contexts keyed by C<_walk_context>. C<tables> holds a
6461 per-table entry, keyed by qualified leaf, of
6462 C<< { repeaters, getnext, getnext_reason, slow, slow_final } >>.
6463 C<slow_final> is the repeaters a slow table's last bulkwalk used, undef
6464 when it ended on getnext.
6465  
6466 =cut
6467  
6468 sub _walk_recovery {
6469 my $self = shift;
6470 return $self->{walk_recovery} ||= {
6471 toobig_repeaters => undef,
6472 getnext => 0,
6473 failed => 0,
6474 slow_tables => 0,
6475 slow_repeaters => undef,
6476 contexts => {},
6477 tables => {},
6478 };
6479 }
6480  
6481 =item $info->_walk_table(\%w)
6482  
6483 Returns the recovery entry of the table being walked, keyed by
6484 C<< $w->{qual_leaf} >>, as
6485 C<< { repeaters, getnext, getnext_reason, slow, slow_final } >>.
6486 Returns an empty hashref when the table has none, and never creates one.
6487  
6488 =cut
6489  
6490 sub _walk_table {
6491 my ( $self, $w ) = @_;
6492 return $self->_walk_recovery()->{tables}{ $w->{qual_leaf} } || {};
6493 }
6494  
6495 =item $info->_walk_table_set(\%w, %fields)
6496  
6497 Creates the recovery entry of the table being walked if needed and sets
6498 C<%fields> in it.
6499  
6500 =cut
6501  
6502 sub _walk_table_set {
6503 my ( $self, $w, %fields ) = @_;
6504 my $entry = $self->_walk_recovery()->{tables}{ $w->{qual_leaf} } ||= {};
6505 @{$entry}{ keys %fields } = values %fields;
6506 return $entry;
6507 }
6508  
6509 =item $info->_walk_start_repeaters(\%w)
6510  
6511 Returns the repeaters a walk of the table starts with: the smallest defined
6512 of the caller's C<BulkRepeaters> (or C<$REPEATERS>), the object's
6513 C<toobig_repeaters> and C<slow_repeaters>, and the table's own learned
6514 C<repeaters>.
6515  
6516 =cut
6517  
6518 sub _walk_start_repeaters {
6519 my ( $self, $w ) = @_;
6520 my $state = $self->_walk_recovery();
6521 my @values = grep {defined} (
6522 $self->{BulkRepeaters} || $REPEATERS,
6523 @{$state}{qw(toobig_repeaters slow_repeaters)},
6524 $self->_walk_table($w)->{repeaters},
6525 );
6526 my ($smallest) = sort { $a <=> $b } @values;
6527 return $smallest;
6528 }
6529  
6530 =item _walk_target(\%session_args)
6531  
6532 Returns the C<DestHost>, C<Version> and C<RemotePort> a session was asked
6533 for, the target that the walk recovery state belongs to.
6534  
6535 =cut
6536  
6537 sub _walk_target {
6538 my $session_args = shift;
6539 return { map { $_ => $session_args->{$_} }
6540 qw(DestHost Version RemotePort) };
6541 }
6542  
6543 =item _same_target(\%old, \%new)
6544  
6545 True when two targets from C<_walk_target> are equal.
6546  
6547 =cut
6548  
6549 sub _same_target {
6550 my ( $old, $new ) = @_;
6551 foreach my $key ( keys %$new ) {
6552 my ( $was, $now ) = ( $old->{$key}, $new->{$key} );
6553 return 0 if defined $was xor defined $now;
6554 return 0 if defined $was and $was ne $now;
6555 }
6556 return 1;
6557 }
6558  
6559 =item $info->_walk_outcome(\%outcome)
6560  
6561 Records the outcome of one table walk as the latest for its method, and
6562 appends it to the failures when the walk is incomplete. Fills in
6563 C<context>, and C<recovery> when the outcome has none.
6564  
6565 =cut
6566  
6567 sub _walk_outcome {
6568 my ( $self, $outcome ) = @_;
6569  
6570 $outcome->{context} = $self->_walk_context();
6571 $outcome->{recovery} ||= [];
6572  
6573 $self->{walk_status}{ $outcome->{method} } = $outcome;
6574 push @{ $self->{walk_failures} }, $outcome unless $outcome->{complete};
6575 return;
6576 }
6577  
6578 =item $info->_walk_context()
6579  
6580 Returns the SNMPv3 Context of the session. On SNMPv1 and SNMPv2c, returns
6581 C<X> when the session community is the constructor's Community followed by
6582 C<@X>, or C<X> followed by C<@> and the Community (Junos puts the context
6583 first, C<default::20@public>). Otherwise, and always when the constructor's
6584 Community is empty or undefined, returns an empty string. Never returns any
6585 part of the community itself.
6586  
6587 =cut
6588  
6589 sub _walk_context {
6590 my $self = shift;
6591 my $sess = $self->session() || {};
6592  
6593 my $context = $sess->{Context};
6594 return $context if defined $context and length $context;
6595 return '' if ( $sess->{Version} || '' ) eq '3';
6596  
6597 my $base = ( $self->{args} || {} )->{Community};
6598 my $community = $sess->{Community};
6599 return '' unless defined $base
6600 and length $base
6601 and defined $community;
6602  
6603 my $prefix = $base . '@';
6604 return substr( $community, length $prefix )
6605 if length $community > length $prefix
6606 and substr( $community, 0, length $prefix ) eq $prefix;
6607  
6608 my $suffix = '@' . $base;
6609 return substr( $community, 0, length($community) - length $suffix )
6610 if length $community > length $suffix
6611 and substr( $community, -length $suffix ) eq $suffix;
6612 return '';
6613 }
6614  
6615 =item $info->_show_attr()
6616  
6617 Used internally by AUTOLOAD to return data called by methods listed in %FUNCS.
6618  
6619 =cut
6620  
6621 sub _show_attr {
6622 my $self = shift;
6623 my $attr = shift;
6624 my $raw = shift;
6625  
6626 my $store = $self->store();
6627  
6628 if ( !$raw ) {
6629 my $localstore = $store->{$attr};
6630 return $self->_munge($attr, $localstore);
6631 }
6632 else {
6633 return $store->{$attr};
6634 }
6635 }
6636  
6637 =item $info->snmp_connect_ip(ip)
6638  
6639 Returns true or false based upon snmp connectivity to an IP.
6640  
6641 =cut
6642  
6643 sub snmp_connect_ip {
6644 my $self = shift;
6645 my $ip = shift;
6646 my $ver = $self->snmp_ver();
6647 my $comm = $self->snmp_comm();
6648  
6649 return if $self->{Offline};
6650  
6651 $ip = resolve_desthost($ip);
6652 return if ( $ip eq '0.0.0.0' ) or ( $ip =~ /^127\./ );
6653  
6654 # Create session object
6655 my $snmp_test = SNMP::Session->new(
6656 'DestHost' => $ip,
6657 'Community' => $comm,
6658 'Version' => $ver
6659 );
6660  
6661 # No session object created
6662 unless ( defined $snmp_test ) {
6663 return;
6664 }
6665  
6666 # Session object created but SNMP connection failed.
6667 my $sess_err = $snmp_test->{ErrorStr} || '';
6668 if ($sess_err) {
6669 return;
6670 }
6671  
6672 # Try to get some data from IP
6673 my $layers = $snmp_test->get('sysServices.0');
6674  
6675 $sess_err = $snmp_test->{ErrorStr} || '';
6676 if ($sess_err) {
6677 return;
6678 }
6679  
6680 return 1;
6681 }
6682  
6683 =item modify_port_list(portlist,offset,replacement)
6684  
6685 Replaces the specified bit in a port_list array and
6686 returns the packed bitmask
6687  
6688 =cut
6689  
6690 sub modify_port_list {
6691 my ( $self, $portlist, $offset, $replacement ) = @_;
6692  
6693 print "Original port list: @$portlist \n" if $self->debug();
6694 @$portlist[$offset] = $replacement;
6695  
6696 # Some devices do not populate the portlist with all possible ports.
6697 # If we have lengthened the list fill all undefined elements with zero.
6698 foreach my $item (@$portlist) {
6699 $item = '0' unless ( defined($item) );
6700 }
6701 print "Modified port list: @$portlist \n" if $self->debug();
6702  
6703 return pack( "B*", join( '', @$portlist ) );
6704 }
6705  
6706 =item $info->_cache(attr, data)
6707  
6708 Cache retrieved data so that if it's asked for again, we use the cache instead
6709 of going back to Net-SNMP. Data is cached inside the blessed hashref C<$self>.
6710  
6711 Accepts the leaf and value (scalar, or hashref for a table). Does not return
6712 anything useful.
6713  
6714 =cut
6715  
6716 sub _cache {
6717 my $self = shift;
6718 my ($attr, $data) = @_;
6719 my $store = $self->store();
6720  
6721 if (ref {} eq ref $data) {
6722 if (! Scalar::Util::looks_like_number($self->{"_${attr}"})) {
6723 # https://github.com/netdisco/snmp-info/issues/464
6724 # perhaps this is being set twice and first time gets $data ??
6725 $self->{"_${attr}"} = 0;
6726 }
6727 $self->{"_${attr}"}++;
6728 $store->{$attr} = $data;
6729 }
6730 else {
6731 $self->{"_$attr"} = $data;
6732 }
6733 }
6734  
6735 =item $info->_munge(attr, data)
6736  
6737 Raw data returned from Net-SNMP might not be formatted correctly or might have
6738 platform-specific bugs or mistakes. The MUNGE feature of SNMP::Info allows for
6739 fixups to take place.
6740  
6741 Accepts the leaf and value (scalar, or hashref for a table) and returns the raw
6742 or the munged data, as appropriate. That is, you do not need to know whether
6743 MUNGE is installed, and it's safe to call this method regardless.
6744  
6745 =cut
6746  
6747 sub _munge {
6748 my $self = shift;
6749 my ($attr, $data) = @_;
6750 my $munge = $self->munge();
6751  
6752 return $data unless defined $munge->{$attr};
6753  
6754 if (ref {} eq ref $data) {
6755 my $subref = $munge->{$attr};
6756 my %munged;
6757 foreach my $key ( keys %$data ) {
6758 my $value = $data->{$key};
6759 next unless defined $value;
6760 $munged{$key} = $subref->($value);
6761 }
6762 return \%munged;
6763 }
6764 else {
6765 return unless $data;
6766 my $subref = $munge->{$attr};
6767 return $subref->($data);
6768 }
6769 }
6770  
6771 =item _validate_autoload_method(method)
6772  
6773 Used internally by AUTOLOAD to validate that a dynamic method should be
6774 created. Returns the OID of the MIB leaf node the method will get or set.
6775  
6776 =over
6777  
6778 =item 1. Returns unless method is listed in %FUNCS, %GLOBALS, or is MIB Leaf
6779 node name in a loaded MIB for given class.
6780  
6781 =item 2. Translates the MIB Leaf node name to an OID.
6782  
6783 =item 3. Checks to see if the method access type is allowed for the resolved
6784 OID. Write access for set_ methods, read access for others.
6785  
6786 =back
6787  
6788 =cut
6789  
6790 sub _validate_autoload_method {
6791 my $self = shift;
6792 my $method = shift;
6793  
6794 my $setter = $method =~ /^set/;
6795 my $attr = $method;
6796 $attr =~ s/^(load|set|orig)_//;
6797 $attr =~ s/_raw$//;
6798  
6799 my $globals = $self->globals();
6800 my $funcs = $self->funcs();
6801  
6802 my $leaf_name = $globals->{$attr} || $funcs->{$attr} || $attr;
6803  
6804 # Check for fully qualified name
6805 if ( $leaf_name =~ /__/ ) {
6806 $leaf_name =~ s/__/::/;
6807 $leaf_name =~ s/_/-/g;
6808 }
6809  
6810 # skip if offline
6811 if ( $self->{Offline} ) {
6812 return [1,(exists $self->{store}->{$method} ? 1: 0)];
6813 }
6814  
6815 # (#325) lazy load legacy RFC1213-MIB only if needed
6816 SNMP::loadModules('RFC1213-MIB')
6817 if $leaf_name =~ m/^(?:RFC1213-MIB::|ipr_|ipRoute)/
6818 and not SNMP::translateObj($leaf_name);
6819  
6820 # Translate MIB leaf node name to OID
6821 my $oid = SNMP::translateObj($leaf_name);
6822  
6823 if ( $leaf_name =~ /^[.]?\d[\.\d]+$/ ) {
6824 $oid = $leaf_name;
6825 }
6826  
6827 unless ( defined $oid ) {
6828 print
6829 "SNMP::Info::_validate_autoload_method($leaf_name) Unable to resolve method.\n"
6830 if $self->debug();
6831 return;
6832 }
6833  
6834 # Validate that we have proper access for the operation
6835 my $access = '';
6836  
6837 # Prevent autovivification by checking that MIB leaf exists
6838 if (exists $SNMP::MIB{$oid}) {
6839 $access = $SNMP::MIB{$oid}{'access'} || '';
6840 }
6841  
6842 # If we were given a fully qualified OID because we don't have the MIB
6843 # file, it will translate above but we won't be able to check access so
6844 # skip the check and return
6845 if ($access && ($method =~ /^set/ && $access !~ /Write|Create/)
6846 || ($method !~ /^set/ && $access eq 'NoAccess')) {
6847  
6848 print
6849 "SNMP::Info::_validate_autoload_method($attr : $oid) Not accessible for requested operation.\n"
6850 if $self->debug();
6851 return;
6852  
6853 }
6854  
6855 my $table_leaf = 0;
6856  
6857 # This is an expensive check so we assume anything in the funcs and globals
6858 # hashes are known. Only for actual MIB leafs should we have to check the
6859 # MIB. If the parent of the leaf has indexes it is contained within a table.
6860 if ($funcs->{$attr}) {
6861 $table_leaf = 1;
6862 }
6863 elsif (!$globals->{$attr}) {
6864  
6865 # Prevent autovivification
6866 if (exists $SNMP::MIB{$oid} &&
6867 exists $SNMP::MIB{$oid}{'parent'} &&
6868 exists $SNMP::MIB{$oid}{'parent'}{'indexes'} &&
6869 defined $SNMP::MIB{$oid}{'parent'}{'indexes'} &&
6870 scalar( @{$SNMP::MIB{$oid}{'parent'}{'indexes'}} ) > 0)
6871 {
6872 $table_leaf = 1;
6873 }
6874 }
6875  
6876 # Tag on .0 for %GLOBALS and single instance MIB leafs unless
6877 # the leaf ends in a digit or we are going to use for a set operation
6878 if ( $table_leaf == 0 && ( $globals->{$attr} || $leaf_name ne $oid ) ) {
6879  
6880 unless ( $leaf_name =~ /\d$/ || $setter ) {
6881 $oid .= ".0";
6882 }
6883 }
6884  
6885 my $return = [ $oid, $table_leaf ];
6886 return $return;
6887 }
6888  
6889 =item $info->can()
6890  
6891 Overrides UNIVERSAL::can() so that objects will correctly report their
6892 capabilities to include dynamic methods generated at run time via AUTOLOAD.
6893  
6894 Calls parent can() first to see if method exists, if not validates that a
6895 method should be created then dispatches to the appropriate internal method
6896 for creation.
6897  
6898 Returns undef if the method does not exist and can not be created.
6899  
6900 =cut
6901  
6902 sub can {
6903 my $self = shift;
6904 my $method = shift;
6905  
6906 # use results of parent can()
6907 return $self->SUPER::can($method) if $self->SUPER::can($method);
6908  
6909 return if $method eq 'CARP_TRACE';
6910  
6911 my $validated = $self->_validate_autoload_method($method);
6912 return unless $validated;
6913  
6914 my ($oid, $table) = @$validated;
6915  
6916 # _validate_autoload_method validates, so we need to check for
6917 # set_ , funcs, table leafs, and everything else goes to _global
6918 my $funcs = $self->funcs();
6919  
6920 # We need to resolve funcs with a prefix or suffix
6921 my $base_method = $method;
6922 $base_method =~ s/^(load|orig)_//;
6923 $base_method =~ s/_raw$//;
6924  
6925 no strict 'refs'; ## no critic (ProhibitNoStrict )
6926  
6927 # We could add load_/orig_/_raw alternatives to symbol table here on
6928 # first call of any type for a global or func since they all use the same
6929 # destination code, but they aren't used heavily in main code base so
6930 # we'll just create if/when they are called rather than pollute the
6931 # symbol table with entries that never get called.
6932  
6933 # Between 2012-2020 we actually added the methods generated below to the
6934 # symbol table, but they were global to the SNMP::Info class, while
6935 # methods for different device classes may point to different SNMP
6936 # objects. This made interacting with multiple device types from a single
6937 # script somewhat unreliable.
6938  
6939 # Check for set_ ing.
6940 if ( $method =~ /^set_/ ) {
6941 return _make_setter( $method, $oid, @_ );
6942 }
6943 elsif ( defined $funcs->{$base_method} || $table ) {
6944 return _load_attr( $method, $oid, @_ );
6945 }
6946 else {
6947 return _global( $method, $oid );
6948 }
6949 }
6950  
6951 =back
6952  
6953 =head2 AUTOLOAD
6954  
6955 Each entry in either %FUNCS, %GLOBALS, or MIB Leaf node names present in
6956 loaded MIBs are used by AUTOLOAD() to create dynamic methods.
6957  
6958 =over
6959  
6960 =item 1. Returns unless method is listed in %FUNCS, %GLOBALS, or is a MIB
6961 Leaf node name in a loaded MIB for given class.
6962  
6963 =item 2. If the method exists in %GLOBALS or is a single instance MIB Leaf
6964 node name from a loaded MIB, _global() generates the method.
6965  
6966 =item 3. If a set_ prefix is present _make_setter() generates the method.
6967  
6968 =item 4. If the method exists in %FUNCS or is a MIB Leaf node name contained
6969 within a table from a loaded MIB, _load_attr() generates the method.
6970  
6971 =item 5. A load_ prefix forces reloading of data and does not use cached data.
6972  
6973 =item 6. A _raw suffix returns data ignoring any munge routines.
6974  
6975 =back
6976  
6977 Override any dynamic method listed in %GLOBALS, %FUNCS, or MIB Leaf node
6978 name a by creating a subroutine with the same name.
6979  
6980 For example to override $info->name() create `` sub name {...}'' in your
6981 subclass.
6982  
6983 =cut
6984  
6985 sub AUTOLOAD {
6986 my $self = shift;
6987 my ($sub_name) = $AUTOLOAD =~ /::([a-zA-Z0-9_-]+)$/;
6988  
6989 return if $sub_name eq 'CARP_TRACE';
6990  
6991 # Typos in function calls in SNMP::Info subclasses turn into
6992 # AUTOLOAD requests for non-methods. While this is deprecated,
6993 # we'll still get called, so report a less confusing error.
6994 if ( ref($self) !~ /SNMP::Info/ ) {
6995  
6996 # croak reports one level too high. die reports here.
6997 # I would really like to get the place that's likely to
6998 # have the typo, but perl doesn't want me to.
6999 croak(
7000 "SNMP::Info::AUTOLOAD($AUTOLOAD) called with no class (probably typo of function call to $sub_name)"
7001 );
7002 }
7003  
7004 # This enables us to use SUPER:: for AUTOLOAD methods as well
7005 # as the true OO methods. Method needs to be renamed to prevent
7006 # namespace collision when we insert into the symbol table later.
7007 if ( $AUTOLOAD =~ /SUPER::$sub_name$/ ) {
7008 $AUTOLOAD =~ s/SUPER::$sub_name/orig_$sub_name/;
7009 $sub_name = "orig_$sub_name";
7010 }
7011  
7012 return unless my $meth_ref = $self->can($sub_name, @_);
7013  
7014 # can() returns a bodyless stub like any other sub, and calling one
7015 # lands back here, so this would otherwise recurse until memory runs out
7016 croak( "$AUTOLOAD is declared but has no body, so the inherited or "
7017 . "generated $sub_name method cannot be reached. A reference "
7018 . "such as \\&$AUTOLOAD, or a forward declaration "
7019 . "'sub $sub_name;', declares the stub. Define the sub, or test "
7020 . "whether it exists with defined(&$AUTOLOAD), which declares "
7021 . "nothing" )
7022 unless defined &$meth_ref;
7023 return $self->$meth_ref(@_);
7024  
7025 }
7026  
7027 # Skip AUTOLOAD()
7028 sub DESTROY {}
7029  
7030 1;
7031  
7032 =head1 COPYRIGHT AND LICENSE
7033  
7034 Changes from SNMP::Info Version 0.7 and on are:
7035 Copyright (c) 2003-2010 Max Baker and SNMP::Info Developers
7036 All rights reserved.
7037  
7038 Original Code is:
7039 Copyright (c) 2002-2003, Regents of the University of California
7040 All rights reserved.
7041  
7042 Redistribution and use in source and binary forms, with or without
7043 modification, are permitted provided that the following conditions are met:
7044  
7045 * Redistributions of source code must retain the above copyright notice,
7046 this list of conditions and the following disclaimer.
7047 * Redistributions in binary form must reproduce the above copyright
7048 notice, this list of conditions and the following disclaimer in the
7049 documentation and/or other materials provided with the distribution.
7050 * Neither the name of the University of California, Santa Cruz nor the
7051 names of its contributors may be used to endorse or promote products
7052 derived from this software without specific prior written permission.
7053  
7054 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
7055 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7056 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7057 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
7058 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7059 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7060 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7061 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7062 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
7063 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7064  
7065 =cut
« Info/Layer7/Liebert.pm ↑ Summary