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