Include LLDP information in output from cdp methods in C6500.pm. Same strategy as in HP.pm

This commit is contained in:
Carlos Vicente
2012-06-05 13:11:55 -04:00
parent e2a314b553
commit cd1acd023e

View File

@@ -33,6 +33,7 @@ package SNMP::Info::Layer3::C6500;
use strict;
use Exporter;
use SNMP::Info::CiscoStack;
use SNMP::Info::LLDP;
use SNMP::Info::CDP;
use SNMP::Info::CiscoStats;
use SNMP::Info::CiscoImage;
@@ -50,6 +51,7 @@ use vars qw/$VERSION %GLOBALS %MIBS %FUNCS %MUNGE/;
SNMP::Info::CiscoVTP
SNMP::Info::CiscoStpExtensions
SNMP::Info::CiscoStack
SNMP::Info::LLDP
SNMP::Info::CDP
SNMP::Info::CiscoImage
SNMP::Info::CiscoStats
@@ -64,7 +66,7 @@ use vars qw/$VERSION %GLOBALS %MIBS %FUNCS %MUNGE/;
use vars qw/$VERSION %GLOBALS %MIBS %FUNCS %MUNGE/;
$VERSION = '2.06';
$VERSION = '2.07';
# NOTE: Order creates precedence
# Example: v_name exists in Bridge.pm and CiscoVTP.pm
@@ -76,8 +78,9 @@ $VERSION = '2.06';
%SNMP::Info::Layer3::MIBS, %SNMP::Info::CiscoPower::MIBS,
%SNMP::Info::CiscoConfig::MIBS, %SNMP::Info::CiscoPortSecurity::MIBS,
%SNMP::Info::CiscoImage::MIBS, %SNMP::Info::CiscoStats::MIBS,
%SNMP::Info::CDP::MIBS, %SNMP::Info::CiscoStack::MIBS,
%SNMP::Info::CiscoStpExtensions::MIBS, %SNMP::Info::CiscoVTP::MIBS,
%SNMP::Info::CDP::MIBS, %SNMP::Info::LLDP::MIBS,
%SNMP::Info::CiscoStack::MIBS, %SNMP::Info::CiscoStpExtensions::MIBS,
%SNMP::Info::CiscoVTP::MIBS,
);
%GLOBALS = (
@@ -88,6 +91,7 @@ $VERSION = '2.06';
%SNMP::Info::CiscoImage::GLOBALS,
%SNMP::Info::CiscoStats::GLOBALS,
%SNMP::Info::CDP::GLOBALS,
%SNMP::Info::LLDP::GLOBALS,
%SNMP::Info::CiscoStack::GLOBALS,
%SNMP::Info::CiscoStpExtensions::GLOBALS,
%SNMP::Info::CiscoVTP::GLOBALS,
@@ -97,8 +101,9 @@ $VERSION = '2.06';
%SNMP::Info::Layer3::FUNCS, %SNMP::Info::CiscoPower::FUNCS,
%SNMP::Info::CiscoConfig::FUNCS, %SNMP::Info::CiscoPortSecurity::FUNCS,
%SNMP::Info::CiscoImage::FUNCS, %SNMP::Info::CiscoStats::FUNCS,
%SNMP::Info::CDP::FUNCS, %SNMP::Info::CiscoStack::FUNCS,
%SNMP::Info::CiscoStpExtensions::FUNCS, %SNMP::Info::CiscoVTP::FUNCS,
%SNMP::Info::CDP::FUNCS, %SNMP::Info::LLDP::FUNCS,
%SNMP::Info::CiscoStack::FUNCS, %SNMP::Info::CiscoStpExtensions::FUNCS,
%SNMP::Info::CiscoVTP::FUNCS,
);
@@ -106,8 +111,9 @@ $VERSION = '2.06';
%SNMP::Info::Layer3::MUNGE, %SNMP::Info::CiscoPower::MUNGE,
%SNMP::Info::CiscoConfig::MUNGE, %SNMP::Info::CiscoPortSecurity::MUNGE,
%SNMP::Info::CiscoImage::MUNGE, %SNMP::Info::CiscoStats::MUNGE,
%SNMP::Info::CDP::MUNGE, %SNMP::Info::CiscoStack::MUNGE,
%SNMP::Info::CiscoStpExtensions::MUNGE, %SNMP::Info::CiscoVTP::MUNGE,
%SNMP::Info::CDP::MUNGE, %SNMP::Info::LLDP::MUNGE,
%SNMP::Info::CiscoStack::MUNGE, %SNMP::Info::CiscoStpExtensions::MUNGE,
%SNMP::Info::CiscoVTP::MUNGE,
);
sub vendor {
@@ -201,6 +207,132 @@ sub set_i_duplex_admin {
}
}
# Use CDP and/or LLDP
sub hasCDP {
my $c6500 = shift;
return $c6500->hasLLDP() || $c6500->SUPER::hasCDP();
}
sub c_ip {
my $c6500 = shift;
my $partial = shift;
my $cdp = $c6500->SUPER::c_ip($partial) || {};
my $lldp = $c6500->lldp_ip($partial) || {};
my %c_ip;
foreach my $iid ( keys %$cdp ) {
my $ip = $cdp->{$iid};
next unless defined $ip;
$c_ip{$iid} = $ip;
}
foreach my $iid ( keys %$lldp ) {
my $ip = $lldp->{$iid};
next unless defined $ip;
$c_ip{$iid} = $ip;
}
return \%c_ip;
}
sub c_if {
my $c6500 = shift;
my $partial = shift;
my $lldp = $c6500->lldp_if($partial) || {};
my $cdp = $c6500->SUPER::c_if($partial) || {};
my %c_if;
foreach my $iid ( keys %$cdp ) {
my $if = $cdp->{$iid};
next unless defined $if;
$c_if{$iid} = $if;
}
foreach my $iid ( keys %$lldp ) {
my $if = $lldp->{$iid};
next unless defined $if;
$c_if{$iid} = $if;
}
return \%c_if;
}
sub c_port {
my $c6500 = shift;
my $partial = shift;
my $lldp = $c6500->lldp_port($partial) || {};
my $cdp = $c6500->SUPER::c_port($partial) || {};
my %c_port;
foreach my $iid ( keys %$cdp ) {
my $port = $cdp->{$iid};
next unless defined $port;
$c_port{$iid} = $port;
}
foreach my $iid ( keys %$lldp ) {
my $port = $lldp->{$iid};
next unless defined $port;
$c_port{$iid} = $port;
}
return \%c_port;
}
sub c_id {
my $c6500 = shift;
my $partial = shift;
my $lldp = $c6500->lldp_id($partial) || {};
my $cdp = $c6500->SUPER::c_id($partial) || {};
my %c_id;
foreach my $iid ( keys %$cdp ) {
my $id = $cdp->{$iid};
next unless defined $id;
$c_id{$iid} = $id;
}
foreach my $iid ( keys %$lldp ) {
my $id = $lldp->{$iid};
next unless defined $id;
$c_id{$iid} = $id;
}
return \%c_id;
}
sub c_platform {
my $c6500 = shift;
my $partial = shift;
my $lldp = $c6500->lldp_rem_sysdesc($partial) || {};
my $cdp = $c6500->SUPER::c_platform($partial) || {};
my %c_platform;
foreach my $iid ( keys %$cdp ) {
my $platform = $cdp->{$iid};
next unless defined $platform;
$c_platform{$iid} = $platform;
}
foreach my $iid ( keys %$lldp ) {
my $platform = $lldp->{$iid};
next unless defined $platform;
$c_platform{$iid} = $platform;
}
return \%c_platform;
}
1;
__END__
@@ -399,6 +531,53 @@ Crosses $c6500->p_port() with $c6500->p_duplex() to utilize port C<ifIndex>.
=back
=head2 Topology information
Based upon the firmware version Cisco devices may support Link Layer Discover
Protocol (LLDP) in addition to the Cisco-proprietary CDP. These methods
will query both and return the combination of all information. As a result,
there may be identical topology information returned from the two protocols
causing duplicate entries. It is the calling program's responsibility to
identify any duplicate entries and remove duplicates if necessary.
=over
=item $c6500->hasCDP()
Returns true if the device is running either CDP or LLDP.
=item $c6500->c_if()
Returns reference to hash. Key: iid Value: local device port (interfaces)
=item $c6500->c_ip()
Returns reference to hash. Key: iid Value: remote IPv4 address
If multiple entries exist with the same local port, c_if(), with the same IPv4
address, c_ip(), it may be a duplicate entry.
If multiple entries exist with the same local port, c_if(), with different
IPv4 addresses, c_ip(), there is either a non-CDP/LLDP device in between two
or more devices or multiple devices which are not directly connected.
Use the data from the Layer2 Topology Table below to dig deeper.
=item $c6500->c_port()
Returns reference to hash. Key: iid Value: remote port (interfaces)
=item $c6500->c_id()
Returns reference to hash. Key: iid Value: string value used to identify the
chassis component associated with the remote system.
=item $c6500->c_platform()
Returns reference to hash. Key: iid Value: Remote Device Type
=back
=head2 Table Methods imported from SNMP::Info::CiscoVTP
See documentation in L<SNMP::Info::CiscoVTP/"TABLE METHODS"> for details.