Support partial table fetches on overridden table methods.

Add set_i_duplex_admin ( ) method.
Document new set method and other doc updates.
This commit is contained in:
Eric Miller
2006-09-29 01:42:34 +00:00
parent e60a1a6931
commit 81f5534a6a

View File

@@ -30,37 +30,36 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::Layer2::C1900; package SNMP::Info::Layer2::C1900;
$VERSION = '1.04'; $VERSION = '1.05';
# $Id$ # $Id$
use strict; use strict;
use Exporter; use Exporter;
use SNMP::Info::Layer2;
use SNMP::Info::CiscoVTP; use SNMP::Info::CiscoVTP;
use SNMP::Info::CDP; use SNMP::Info::CDP;
use SNMP::Info::CiscoStats; use SNMP::Info::CiscoStats;
use SNMP::Info::Layer2;
@SNMP::Info::Layer2::C1900::ISA = qw/SNMP::Info::Layer2 SNMP::Info::CiscoVTP @SNMP::Info::Layer2::C1900::ISA = qw/SNMP::Info::CiscoVTP SNMP::Info::CDP
SNMP::Info::CDP SNMP::Info::CiscoStats Exporter/; SNMP::Info::CiscoStats SNMP::Info::Layer2 Exporter/;
@SNMP::Info::Layer2::C1900::EXPORT_OK = qw//; @SNMP::Info::Layer2::C1900::EXPORT_OK = qw//;
use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/; use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/;
# Set for No CDP
%GLOBALS = ( %GLOBALS = (
%SNMP::Info::Layer2::GLOBALS, %SNMP::Info::Layer2::GLOBALS,
%SNMP::Info::CiscoVTP::GLOBALS,
%SNMP::Info::CiscoStats::GLOBALS, %SNMP::Info::CiscoStats::GLOBALS,
%SNMP::Info::CDP::GLOBALS, %SNMP::Info::CDP::GLOBALS,
%SNMP::Info::CiscoVTP::GLOBALS,
'c1900_flash_status' => 'upgradeFlashBankStatus', 'c1900_flash_status' => 'upgradeFlashBankStatus',
); );
%FUNCS = (%SNMP::Info::Layer2::FUNCS, %FUNCS = (
%SNMP::Info::CiscoVTP::FUNCS, %SNMP::Info::Layer2::FUNCS,
%SNMP::Info::CiscoStats::FUNCS, %SNMP::Info::CiscoStats::FUNCS,
%SNMP::Info::CDP::FUNCS, %SNMP::Info::CDP::FUNCS,
'i_type2' => 'ifType', %SNMP::Info::CiscoVTP::FUNCS,
'i_name2' => 'ifName',
# ESSWITCH-MIB # ESSWITCH-MIB
'c1900_p_index' => 'swPortIndex', 'c1900_p_index' => 'swPortIndex',
'c1900_p_ifindex' => 'swPortIfIndex', 'c1900_p_ifindex' => 'swPortIfIndex',
@@ -74,22 +73,25 @@ use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/;
%MIBS = ( %MIBS = (
%SNMP::Info::Layer2::MIBS, %SNMP::Info::Layer2::MIBS,
%SNMP::Info::CiscoVTP::MIBS,
%SNMP::Info::CiscoStats::MIBS, %SNMP::Info::CiscoStats::MIBS,
%SNMP::Info::CDP::MIBS, %SNMP::Info::CDP::MIBS,
%SNMP::Info::CiscoVTP::MIBS,
# Also known as the ESSWITCH-MIB # Also known as the ESSWITCH-MIB
'STAND-ALONE-ETHERNET-SWITCH-MIB' => 'series2000' 'STAND-ALONE-ETHERNET-SWITCH-MIB' => 'series2000'
); );
%MUNGE = (%SNMP::Info::Layer2::MUNGE, %MUNGE = (
%SNMP::Info::CiscoVTP::MUNGE, %SNMP::Info::Layer2::MUNGE, %SNMP::Info::CiscoStats::MUNGE,
%SNMP::Info::CDP::MUNGE, %SNMP::Info::CDP::MUNGE, %SNMP::Info::CiscoVTP::MUNGE,
%SNMP::Info::CiscoStats::MUNGE,
); );
sub bulkwalk_no { 1; }
sub cisco_comm_indexing { 1; }
sub vendor { sub vendor {
return 'cisco'; return 'cisco';
} }
sub os { sub os {
return 'catalyst'; return 'catalyst';
} }
@@ -104,20 +106,19 @@ sub os_ver {
my $c1900_flash_status = $c1900->c1900_flash_status(); my $c1900_flash_status = $c1900->c1900_flash_status();
return undef unless defined $c1900_flash_status; return undef unless defined $c1900_flash_status;
if ($c1900_flash_status =~ m/V(\d+\.\d+(\.\d+)?)/){ if ( $c1900_flash_status =~ m/V(\d+\.\d+(\.\d+)?)/ ) {
return $1; return $1;
} }
return undef; return undef;
} }
sub bulkwalk_no { 1; }
sub cisco_comm_indexing { 1; }
sub interfaces { sub interfaces {
my $c1900 = shift; my $c1900 = shift;
my $i_descr = $c1900->i_description(); my $partial = shift;
foreach my $iid (keys %$i_descr){ my $i_descr = $c1900->i_description($partial) || {};
foreach my $iid ( keys %$i_descr ) {
$i_descr->{$iid} =~ s/\s*$//; $i_descr->{$iid} =~ s/\s*$//;
} }
return $i_descr; return $i_descr;
@@ -125,64 +126,54 @@ sub interfaces {
sub i_duplex { sub i_duplex {
my $c1900 = shift; my $c1900 = shift;
my $partial = shift;
my $interfaces = $c1900->interfaces(); my $c1900_p_duplex = $c1900->c1900_p_duplex($partial) || {};
my $c1900_p_index = $c1900->c1900_p_index();
my $c1900_p_duplex = $c1900->c1900_p_duplex();
my %reverse_1900 = reverse %$c1900_p_index;
my %i_duplex; my %i_duplex;
foreach my $if (keys %$interfaces){ foreach my $if ( keys %$c1900_p_duplex ) {
my $port_1900 = $reverse_1900{$if}; my $duplex = $c1900_p_duplex->{$if};
next unless defined $port_1900;
my $duplex = $c1900_p_duplex->{$port_1900};
next unless defined $duplex; next unless defined $duplex;
$duplex = 'half' if $duplex =~ /half/i; $duplex = 'half' if $duplex =~ /half/i;
$duplex = 'full' if $duplex =~ /full/i; $duplex = 'full' if $duplex =~ /full/i;
$i_duplex{$if}=$duplex; $i_duplex{$if} = $duplex;
} }
return \%i_duplex; return \%i_duplex;
} }
sub i_duplex_admin { sub i_duplex_admin {
my $c1900 = shift; my $c1900 = shift;
my $partial = shift;
my $interfaces = $c1900->interfaces(); my $c1900_p_admin = $c1900->c1900_p_duplex_admin($partial) || {};
my $c1900_p_index = $c1900->c1900_p_index();
my $c1900_p_admin = $c1900->c1900_p_duplex_admin();
my %reverse_1900 = reverse %$c1900_p_index;
my %i_duplex_admin; my %i_duplex_admin;
foreach my $if (keys %$interfaces){ foreach my $if ( keys %$c1900_p_admin ) {
my $port_1900 = $reverse_1900{$if}; my $duplex = $c1900_p_admin->{$if};
next unless defined $port_1900;
my $duplex = $c1900_p_admin->{$port_1900};
next unless defined $duplex; next unless defined $duplex;
$duplex = 'half' if $duplex =~ /disabled/i; $duplex = 'half' if $duplex =~ /disabled/i;
$duplex = 'full' if $duplex =~ /flow control/i; $duplex = 'full' if $duplex =~ /flow control/i;
$duplex = 'full' if $duplex =~ /enabled/i; $duplex = 'full' if $duplex =~ /enabled/i;
$duplex = 'auto' if $duplex =~ /auto/i; $duplex = 'auto' if $duplex =~ /auto/i;
$i_duplex_admin{$if}=$duplex; $i_duplex_admin{$if} = $duplex;
} }
return \%i_duplex_admin; return \%i_duplex_admin;
} }
sub i_type { sub i_type {
my $c1900 = shift; my $c1900 = shift;
my $partial = shift;
my $i_type = $c1900->i_type2(); my $i_type = $c1900->orig_i_type($partial) || {};
my $c1900_p_index = $c1900->c1900_p_index(); my $c1900_p_index = $c1900->c1900_p_index($partial) || {};
my $c1900_p_type = $c1900->c1900_p_type(); my $c1900_p_type = $c1900->c1900_p_type($partial) || {};
my $c1900_p_media = $c1900->c1900_p_media(); my $c1900_p_media = $c1900->c1900_p_media($partial) || {};
foreach my $p_iid (keys %$c1900_p_index){ foreach my $p_iid ( keys %$c1900_p_index ) {
my $port = $c1900_p_index->{$p_iid}; my $port = $c1900_p_index->{$p_iid};
next if ( defined $partial and $port !~ /^$partial$/ );
my $type = $c1900_p_type->{$p_iid}; my $type = $c1900_p_type->{$p_iid};
my $media = $c1900_p_media->{$p_iid}; my $media = $c1900_p_media->{$p_iid};
@@ -198,10 +189,12 @@ sub i_type {
sub i_name { sub i_name {
my $c1900 = shift; my $c1900 = shift;
my $i_name = $c1900->i_name2(); my $partial = shift;
my $c1900_p_name = $c1900->c1900_p_name();
foreach my $port (keys %$c1900_p_name){ my $i_name = $c1900->orig_i_name($partial) || {};
my $c1900_p_name = $c1900->c1900_p_name($partial) || {};
foreach my $port ( keys %$c1900_p_name ) {
my $name = $c1900_p_name->{$port}; my $name = $c1900_p_name->{$port};
next unless defined $name; next unless defined $name;
next unless $name !~ /^\s*$/; next unless $name !~ /^\s*$/;
@@ -211,12 +204,28 @@ sub i_name {
return $i_name; return $i_name;
} }
sub set_i_duplex_admin {
my $c1900 = shift;
my ( $duplex, $port ) = @_;
# map a textual duplex to an integer one the switch understands
my %duplexes = qw/full 1 half 2 auto 3/;
my $iid = $c1900->c1900_p_ifindex($port);
$duplex = lc($duplex);
return 0 unless defined $duplexes{$duplex};
return $c1900->set_c1900_p_duplex_admin( $duplexes{$duplex}, $iid );
}
1; 1;
__END__ __END__
=head1 NAME =head1 NAME
SNMP::Info::Layer2::C1900 - Perl5 Interface to SNMP data from Cisco Catlyst 1900 Network Switches running CatOS SNMP::Info::Layer2::C1900 - SNMP Interface to data from Cisco Catlyst 1900 Network Switches running CatOS
=head1 AUTHOR =head1 AUTHOR
@@ -254,6 +263,12 @@ a more specific class using the method above.
=over =over
=item SNMP::Info::CiscoVTP
=item SNMP::Info::CDP
=item SNMP::Info::CiscoStats
=item SNMP::Info::Layer2 =item SNMP::Info::Layer2
=back =back
@@ -268,22 +283,24 @@ ESSWITCH-MIB is included in the Version 1 MIBS from Cisco.
They can be found at ftp://ftp.cisco.com/pub/mibs/v1/v1.tar.gz They can be found at ftp://ftp.cisco.com/pub/mibs/v1/v1.tar.gz
=item Inherited Classes' MIBs
MIBs listed in SNMP::Info::Layer2
=back =back
=head2 Inherited MIBs
See L<SNMP::Info::CiscoVTP/"Required MIBs"> for its MIB requirements.
See L<SNMP::Info::CDP/"Required MIBs"> for its MIB requirements.
See L<SNMP::Info::CiscoStats/"Required MIBs"> for its MIB requirements.
See L<SNMP::Info::Layer2/"Required MIBs"> for its MIB requirements.
=head1 GLOBALS =head1 GLOBALS
These are methods that return scalar value from SNMP These are methods that return scalar value from SNMP
=over =over
=item $c1900->bulkwalk_no
Return C<1>. Bulkwalk is turned off for this class.
=item $c1900->c1900_flash_status() =item $c1900->c1900_flash_status()
Usually contains the version of the software loaded in flash. Usually contains the version of the software loaded in flash.
@@ -308,12 +325,37 @@ Returns 'cisco' :)
=back =back
=head2 Overrides
=over
=item $c1900->bulkwalk_no
Return C<1>. Bulkwalk is turned off for this class.
=back
=head2 Globals imported from SNMP::Info::CiscoVTP
See L<SNMP::Info::CiscoVTP/"GLOBALS"> for details.
=head2 Globals imported from SNMP::Info::CDP
See L<SNMP::Info::CDP/"GLOBALS"> for details.
=head2 Globals imported from SNMP::Info::CiscoStats
See L<SNMP::Info::CiscoStats/"GLOBALS"> for details.
=head2 Globals imported from SNMP::Info::Layer2 =head2 Globals imported from SNMP::Info::Layer2
See documentation in SNMP::Info::Layer2 for details. See L<SNMP::Info::Layer2/"GLOBALS"> for details.
=head1 TABLE ENTRIES =head1 TABLE ENTRIES
These are methods that return tables of information in the form of a reference
to a hash.
=head2 Overrides =head2 Overrides
=over =over
@@ -322,14 +364,10 @@ See documentation in SNMP::Info::Layer2 for details.
Returns reference to map of IIDs to current link duplex Returns reference to map of IIDs to current link duplex
Crosses $c1900->c1900_p_index() with $c1900->c1900_p_duplex;
=item $c1900->i_duplex_admin() =item $c1900->i_duplex_admin()
Returns reference to hash of IIDs to admin duplex setting Returns reference to hash of IIDs to admin duplex setting
Crosses $c1900->c1900_p_index() with $c1900->c1900_p_duplex_admin;
=item $c1900->i_name() =item $c1900->i_name()
Crosses ifName with c1900_p_name() and returns the human set port name if exists. Crosses ifName with c1900_p_name() and returns the human set port name if exists.
@@ -392,8 +430,41 @@ B<swPortConnectorType>
=back =back
=head2 Table Methods imported from SNMP::Info::CiscoVTP
See L<SNMP::Info::CiscoVTP/"TABLE ENTRIES"> for details.
=head2 Table Methods imported from SNMP::Info::CDP
See L<SNMP::Info::CDP/"TABLE ENTRIES"> for details.
=head2 Table Methods imported from SNMP::Info::CiscoStats
See L<SNMP::Info::CiscoStats/"TABLE ENTRIES"> for details.
=head2 Table Methods imported from SNMP::Info::Layer2 =head2 Table Methods imported from SNMP::Info::Layer2
See documentation in SNMP::Info::Layer2 for details. See L<SNMP::Info::Layer2/"TABLE ENTRIES"> for details.
=back
=head1 SET METHODS
These are methods that provide SNMP set functionality for overridden methods or
provide a simpler interface to complex set operations. See
L<SNMP::Info/"SETTING DATA VIA SNMP"> for general information on set operations.
=over
=item $c1900->set_i_duplex_admin(duplex, ifIndex)
Sets port duplex, must be supplied with duplex and port ifIndex. Speed choices
are 'auto', 'half', 'full'.
Example:
my %if_map = reverse %{$c1900->interfaces()};
$c1900->set_i_duplex_admin('auto', $if_map{'1'})
or die "Couldn't change port duplex. ",$c1900->error(1);
=cut =cut