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