[RT: #78232] Extend cdpCacheCapabilities to show more CDP bits

Add cdp_cap() which returns hash of arrays with each array containing the system capabilities supported by the remote system.
This commit is contained in:
Eric A. Miller
2013-12-15 10:11:34 -05:00
parent c6abd7b62b
commit d39dc76949

View File

@@ -40,7 +40,8 @@ use SNMP::Info;
@SNMP::Info::CDP::ISA = qw/SNMP::Info Exporter/; @SNMP::Info::CDP::ISA = qw/SNMP::Info Exporter/;
@SNMP::Info::CDP::EXPORT_OK = qw//; @SNMP::Info::CDP::EXPORT_OK = qw//;
use vars qw/$VERSION $DEBUG %FUNCS %GLOBALS %MIBS %MUNGE $INIT/; use vars
qw/$VERSION $DEBUG %FUNCS %GLOBALS %MIBS %MUNGE $INIT %CDP_CAPABILITIES/;
$VERSION = '3.08'; $VERSION = '3.08';
@@ -65,6 +66,7 @@ $VERSION = '3.08';
'cdp_port' => 'cdpCacheDevicePort', 'cdp_port' => 'cdpCacheDevicePort',
'cdp_platform' => 'cdpCachePlatform', 'cdp_platform' => 'cdpCachePlatform',
'cdp_capabilities' => 'cdpCacheCapabilities', 'cdp_capabilities' => 'cdpCacheCapabilities',
'cdp_cap_hex' => 'cdpCacheCapabilities',
'cdp_domain' => 'cdpCacheVTPMgmtDomain', 'cdp_domain' => 'cdpCacheVTPMgmtDomain',
'cdp_vlan' => 'cdpCacheNativeVLAN', 'cdp_vlan' => 'cdpCacheNativeVLAN',
'cdp_duplex' => 'cdpCacheDuplex', 'cdp_duplex' => 'cdpCacheDuplex',
@@ -76,7 +78,8 @@ $VERSION = '3.08';
); );
%MUNGE = ( %MUNGE = (
'cdp_capabilities' => \&SNMP::Info::munge_caps, 'cdp_cap_hex' => \&SNMP::Info::munge_octet2hex,
'cdp_capabilities' => \&SNMP::Info::munge_bits,
'cdp_platform' => \&SNMP::Info::munge_null, 'cdp_platform' => \&SNMP::Info::munge_null,
'cdp_domain' => \&SNMP::Info::munge_null, 'cdp_domain' => \&SNMP::Info::munge_null,
'cdp_port' => \&SNMP::Info::munge_null, 'cdp_port' => \&SNMP::Info::munge_null,
@@ -87,6 +90,20 @@ $VERSION = '3.08';
); );
%CDP_CAPABILITIES = (
'Router' => 0x001,
'Trans-Bridge' => 0x002,
'Source-Route-Bridge' => 0x004,
'Switch' => 0x008,
'Host' => 0x010,
'IGMP' => 0x020,
'Repeater' => 0x040,
'VoIP-Phone' => 0x080,
'Remotely-Managed-Device' => 0x100,
'Supports-STP-Dispute' => 0x200,
'Two-port Mac Relay' => 0x400,
);
sub munge_power { sub munge_power {
my $power = shift; my $power = shift;
my $decimal = substr( $power, -3 ); my $decimal = substr( $power, -3 );
@@ -160,6 +177,26 @@ sub cdp_ip {
return \%cdp_ip; return \%cdp_ip;
} }
sub cdp_cap {
my $cdp = shift;
my $partial = shift;
my $cdp_caps = $cdp->cdp_cap_hex($partial) || {};
my %cdp_cap;
foreach my $key ( keys %$cdp_caps ) {
my $cap_hex = $cdp_caps->{$key};
next unless $cap_hex;
foreach my $capability (keys %CDP_CAPABILITIES) {
if ( (hex $cap_hex) & $CDP_CAPABILITIES{$capability}) {
push ( @{$cdp_cap{$key}}, $capability);
}
}
}
return \%cdp_cap;
}
1; 1;
__END__ __END__
@@ -283,15 +320,24 @@ to a hash.
=item $cdp->cdp_capabilities() =item $cdp->cdp_capabilities()
Returns Device Functional Capabilities. Results are munged into an ascii Returns Device Functional Capabilities. Results are munged into an ascii
binary string, 7 digits long, MSB. Each digit represents a bit from the binary string, MSB. Each digit represents a bit from the table below from
table below. the CDP Capabilities Mapping to Smartport Type table within the
Cisco Small Business 200 Series Smart Switch Administration Guide,
From L<http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843>: L<http://www.cisco.com/c/en/us/support/switches/small-business-200-series-smart-switches/products-maintenance-guides-list.html>:
(Bit) - Description (Bit) - Description
=over =over
=item (0x400) - Two-Port MAC Relay.
=item (0x200) - CAST Phone Port / CVTA / Supports-STP-Dispute depending
upon platform.
=item (0x100) - Remotely-Managed Device.
=item (0x80) - VoIP Phone.
=item (0x40) - Provides level 1 functionality. =item (0x40) - Provides level 1 functionality.
=item (0x20) - The bridge or switch does not forward IGMP Report packets on =item (0x20) - The bridge or switch does not forward IGMP Report packets on
@@ -314,8 +360,8 @@ protocol.
=back =back
Thanks to Martin Lorensen C<martin -at- lorensen.dk> for a pointer to this Thanks to Martin Lorensen for a pointer to the original information and
information. CPAN user Alex for updates.
(C<cdpCacheCapabilities>) (C<cdpCacheCapabilities>)
@@ -427,6 +473,14 @@ for decimal placement.
(C<cdpCachePowerConsumption>) (C<cdpCachePowerConsumption>)
=item $cdp->cdp_cap()
Returns hash of arrays with each array containing the system capabilities
supported by the remote system. Possible elements in the array are
C<Router>, C<Trans-Bridge>, C<Source-Route-Bridge>, C<Switch>, C<Host>,
C<IGMP>, C<Repeater>, C<VoIP-Phone>, C<Remotely-Managed-Device>,
C<Supports-STP-Dispute>, and C<Two-port Mac Relay>.
=back =back
=head1 Data Munging Callback Subroutines =head1 Data Munging Callback Subroutines