This commit is contained in:
Eric Miller
2008-07-20 03:30:56 +00:00
parent 6c7df418af
commit 158596cede
69 changed files with 7547 additions and 6963 deletions

View File

@@ -1,23 +1,23 @@
# SNMP::Info::CiscoStack
# $Id$
#
# Copyright (c) 2008 Max Baker
# All rights reserved.
# Copyright (c) 2008 Max Baker
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the University of California, Santa Cruz nor the
# names of its contributors may be used to endorse or promote products
# * Neither the name of the University of California, Santa Cruz nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
@@ -34,87 +34,91 @@ use strict;
use Exporter;
use SNMP::Info;
@SNMP::Info::CiscoStack::ISA = qw/SNMP::Info Exporter/;
@SNMP::Info::CiscoStack::ISA = qw/SNMP::Info Exporter/;
@SNMP::Info::CiscoStack::EXPORT_OK = qw//;
use vars qw/$VERSION %MIBS %FUNCS %GLOBALS %MUNGE %PORTSTAT/;
$VERSION = '1.09';
%MIBS = (
'CISCO-STACK-MIB' => 'ciscoStackMIB',
);
%MIBS = ( 'CISCO-STACK-MIB' => 'ciscoStackMIB', );
%GLOBALS = (
'sysip' => 'sysIpAddr',
'netmask' => 'sysNetMask',
'broadcast' => 'sysBroadcast',
'serial1' => 'chassisSerialNumber',
'serial2' => 'chassisSerialNumberString',
'model1' => 'chassisModel',
'ps1_type' => 'chassisPs1Type',
'ps1_status' => 'chassisPs1Status',
'ps2_type' => 'chassisPs2Type',
'ps2_status' => 'chassisPs2Status',
'slots' => 'chassisNumSlots',
'fan' => 'chassisFanStatus',
);
'sysip' => 'sysIpAddr',
'netmask' => 'sysNetMask',
'broadcast' => 'sysBroadcast',
'serial1' => 'chassisSerialNumber',
'serial2' => 'chassisSerialNumberString',
'model1' => 'chassisModel',
'ps1_type' => 'chassisPs1Type',
'ps1_status' => 'chassisPs1Status',
'ps2_type' => 'chassisPs2Type',
'ps2_status' => 'chassisPs2Status',
'slots' => 'chassisNumSlots',
'fan' => 'chassisFanStatus',
);
%FUNCS = (
# CISCO-STACK-MIB::moduleEntry
# These are blades in a catalyst device
'm_type' => 'moduleType',
'm_model' => 'moduleModel',
'm_serial' => 'moduleSerialNumber',
'm_status' => 'moduleStatus',
'm_name' => 'moduleName',
'm_ports' => 'moduleNumPorts',
'm_ports_status' => 'modulePortStatus',
'm_hwver' => 'moduleHwVersion',
'm_fwver' => 'moduleFwVersion',
'm_swver' => 'moduleSwVersion',
# Router Blades :
'm_ip' => 'moduleIPAddress',
'm_sub1' => 'moduleSubType',
'm_sub2' => 'moduleSubType2',
# CISCO-STACK-MIB::portEntry
'p_name' => 'portName',
'p_type' => 'portType',
'p_status' => 'portOperStatus',
'p_status2' => 'portAdditionalStatus',
'p_speed' => 'portAdminSpeed',
'p_duplex' => 'portDuplex',
'p_port' => 'portIfIndex',
'p_rx_flow_control' => 'portOperRxFlowControl',
'p_tx_flow_control' => 'portOperTxFlowControl',
'p_rx_flow_control_admin' => 'portAdminRxFlowControl',
'p_tx_flow_control_admin' => 'portAdminTxFlowControl',
'p_oidx' => 'portCrossIndex',
# CISCO-STACK-MIB::PortCpbEntry
'p_speed_admin' => 'portCpbSpeed',
'p_duplex_admin' => 'portCpbDuplex',
);
%FUNCS = (
%MUNGE = (
'm_ports_status' => \&munge_port_status,
'p_duplex_admin' => \&SNMP::Info::munge_bits,
);
# CISCO-STACK-MIB::moduleEntry
# These are blades in a catalyst device
'm_type' => 'moduleType',
'm_model' => 'moduleModel',
'm_serial' => 'moduleSerialNumber',
'm_status' => 'moduleStatus',
'm_name' => 'moduleName',
'm_ports' => 'moduleNumPorts',
'm_ports_status' => 'modulePortStatus',
'm_hwver' => 'moduleHwVersion',
'm_fwver' => 'moduleFwVersion',
'm_swver' => 'moduleSwVersion',
%PORTSTAT = (1 => 'other',
2 => 'ok',
3 => 'minorFault',
4 => 'majorFault');
# Router Blades :
'm_ip' => 'moduleIPAddress',
'm_sub1' => 'moduleSubType',
'm_sub2' => 'moduleSubType2',
# CISCO-STACK-MIB::portEntry
'p_name' => 'portName',
'p_type' => 'portType',
'p_status' => 'portOperStatus',
'p_status2' => 'portAdditionalStatus',
'p_speed' => 'portAdminSpeed',
'p_duplex' => 'portDuplex',
'p_port' => 'portIfIndex',
'p_rx_flow_control' => 'portOperRxFlowControl',
'p_tx_flow_control' => 'portOperTxFlowControl',
'p_rx_flow_control_admin' => 'portAdminRxFlowControl',
'p_tx_flow_control_admin' => 'portAdminTxFlowControl',
'p_oidx' => 'portCrossIndex',
# CISCO-STACK-MIB::PortCpbEntry
'p_speed_admin' => 'portCpbSpeed',
'p_duplex_admin' => 'portCpbDuplex',
);
%MUNGE = (
'm_ports_status' => \&munge_port_status,
'p_duplex_admin' => \&SNMP::Info::munge_bits,
);
%PORTSTAT = (
1 => 'other',
2 => 'ok',
3 => 'minorFault',
4 => 'majorFault'
);
# Changes binary byte describing each port into ascii, and returns
# an ascii list separated by spaces.
sub munge_port_status {
my $status = shift;
my @vals = map($PORTSTAT{$_},unpack('C*',$status));
return join(' ',@vals);
my @vals = map( $PORTSTAT{$_}, unpack( 'C*', $status ) );
return join( ' ', @vals );
}
sub serial {
my $stack = shift;
my $stack = shift;
my $serial1 = $stack->serial1();
my $serial2 = $stack->serial2();
@@ -126,12 +130,12 @@ sub serial {
# Rules for older CatOS devices using CiscoStack
#
# You can configure Ethernet and Fast Ethernet interfaces to either full
# duplex or half duplex.
# duplex or half duplex.
#
# You cannot configure the duplex mode on Gigabit Ethernet ports (they are
# always in full-duplex mode).
#
# If you set the port speed to auto, duplex mode is automatically set to auto.
# If you set the port speed to auto, duplex mode is automatically set to auto.
#
# For operational duplex if portCpbDuplex is all zeros the port is a gigabit
# port and duplex is always full. If the port is not operational and auto
@@ -141,31 +145,33 @@ sub serial {
# checked in the device class.
sub i_duplex {
my $stack = shift;
my $stack = shift;
my $partial = shift;
my $p_port = $stack->p_port() || {};
my $p_duplex = $stack->p_duplex() || {};
my $p_port = $stack->p_port() || {};
my $p_duplex = $stack->p_duplex() || {};
my $p_duplex_cap = $stack->p_duplex_admin() || {};
my $i_duplex = {};
foreach my $port (keys %$p_duplex) {
foreach my $port ( keys %$p_duplex ) {
my $iid = $p_port->{$port};
next unless defined $iid;
next if (defined $partial and $iid !~ /^$partial$/);
# Test for gigabit
if ($p_duplex_cap->{$port} == 0) {
next if ( defined $partial and $iid !~ /^$partial$/ );
# Test for gigabit
if ( $p_duplex_cap->{$port} == 0 ) {
$i_duplex->{$iid} = 'full';
}
# Auto is not a valid operational state
elsif ($p_duplex->{$port} eq 'auto') {
elsif ( $p_duplex->{$port} eq 'auto' ) {
next;
}
else {
$i_duplex->{$iid} = $p_duplex->{$port};
}
}
return $i_duplex;
return $i_duplex;
}
# For administrative duplex if portCpbDuplex is all zeros the port is a gigabit
@@ -173,63 +179,68 @@ sub i_duplex {
# duplex will be auto, otherwise use portDuplex.
sub i_duplex_admin {
my $stack = shift;
my $stack = shift;
my $partial = shift;
my $p_port = $stack->p_port() || {};
my $p_duplex = $stack->p_duplex() || {};
my $p_port = $stack->p_port() || {};
my $p_duplex = $stack->p_duplex() || {};
my $p_duplex_cap = $stack->p_duplex_admin() || {};
my $p_speed = $stack->p_speed() || {};
my $p_speed = $stack->p_speed() || {};
my $i_duplex_admin = {};
foreach my $port (keys %$p_duplex) {
foreach my $port ( keys %$p_duplex ) {
my $iid = $p_port->{$port};
next unless defined $iid;
next if (defined $partial and $iid !~ /^$partial$/);
# Test for gigabit
if ($p_duplex_cap->{$port} == 0) {
next if ( defined $partial and $iid !~ /^$partial$/ );
# Test for gigabit
if ( $p_duplex_cap->{$port} == 0 ) {
$i_duplex_admin->{$iid} = 'full';
}
# Check admin speed for auto
elsif ($p_speed->{$port} =~ /auto/) {
elsif ( $p_speed->{$port} =~ /auto/ ) {
$i_duplex_admin->{$iid} = 'auto';
}
else {
$i_duplex_admin->{$iid} = $p_duplex->{$port};
}
}
return $i_duplex_admin;
return $i_duplex_admin;
}
sub i_speed_admin {
my $stack = shift;
my $stack = shift;
my $partial = shift;
my %i_speed_admin;
my $p_port = $stack->p_port();
my %mapping = reverse %$p_port;
my $p_speed = $stack->p_speed($mapping{$partial});
my $p_speed = $stack->p_speed( $mapping{$partial} );
my %speeds = ('autoDetect' => 'auto',
'autoDetect10100' => 'auto',
's10000000' => '10 Mbps',
's100000000' => '100 Mbps',
's1000000000' => '1.0 Gbps',
's10G' => '10 Gbps',
);
my %speeds = (
'autoDetect' => 'auto',
'autoDetect10100' => 'auto',
's10000000' => '10 Mbps',
's100000000' => '100 Mbps',
's1000000000' => '1.0 Gbps',
's10G' => '10 Gbps',
);
%i_speed_admin = map { $p_port->{$_} => $speeds{$p_speed->{$_}} } keys %$p_port;
%i_speed_admin
= map { $p_port->{$_} => $speeds{ $p_speed->{$_} } } keys %$p_port;
return \%i_speed_admin;
}
sub set_i_speed_admin {
# map speeds to those the switch will understand
my %speeds = qw/auto 1 10 10000000 100 100000000 1000 1000000000/;
my $stack = shift;
my ($speed, $iid) = @_;
my $p_port = $stack->p_port() || {};
my ( $speed, $iid ) = @_;
my $p_port = $stack->p_port() || {};
my %reverse_p_port = reverse %$p_port;
$speed = lc($speed);
@@ -238,24 +249,27 @@ sub set_i_speed_admin {
$iid = $reverse_p_port{$iid};
return $stack->set_p_speed ($speeds{$speed}, $iid);
return $stack->set_p_speed( $speeds{$speed}, $iid );
}
sub set_i_duplex_admin {
# map a textual duplex to an integer one the switch understands
my %duplexes = qw/half 1 full 2 auto 4/;
my $stack = shift;
my ($duplex, $iid) = @_;
if ($duplex eq 'auto') {
$stack->error_throw("Software doesn't support setting auto duplex with
my ( $duplex, $iid ) = @_;
if ( $duplex eq 'auto' ) {
$stack->error_throw(
"Software doesn't support setting auto duplex with
set_i_duplex_admin() you must use
set_i_speed_admin() and set both speed and duplex
to auto");
to auto"
);
return 0;
}
my $p_port = $stack->p_port() || {};
my $p_port = $stack->p_port() || {};
my %reverse_p_port = reverse %$p_port;
$duplex = lc($duplex);
@@ -264,7 +278,7 @@ sub set_i_duplex_admin {
$iid = $reverse_p_port{$iid};
return $stack->set_p_duplex($duplexes{$duplex}, $iid);
return $stack->set_p_duplex( $duplexes{$duplex}, $iid );
}
1;
@@ -553,9 +567,9 @@ To see the status of port 4 :
Can be either C<on> C<off> or C<disagree>
"Indicates the receive flow control operational status of the port. If the port
could not agree with the far end on a link protocol, its operational status
will be disagree(3)."
"Indicates the receive flow control operational status of the port. If the
port could not agree with the far end on a link protocol, its operational
status will be disagree(3)."
C<portOperRxFlowControl>
@@ -576,8 +590,8 @@ Can be either C<on> C<off> or C<desired>
"Indicates the receive flow control administrative status set on the port. If
the status is set to on(1), the port will require the far end to send flow
control. If the status is set to off(2), the port will not allow far end to
send flow control. If the status is set to desired(3), the port will allow the
far end to send the flow control."
send flow control. If the status is set to desired(3), the port will allow
the far end to send the flow control."
C<portAdminRxFlowControl>
@@ -585,11 +599,11 @@ C<portAdminRxFlowControl>
Can be either C<on> C<off> or C<desired>
"Indicates the transmit flow control administrative status set on the port. If
the status is set to on(1), the port will send flow control to the far end. If
"Indicates the transmit flow control administrative status set on the port.
If the status is set to on(1), the port will send flow control to the far end. If
the status is set to off(2), the port will not send flow control to the far
end. If the status is set to desired(3), the port will send flow control to the
far end if the far end supports it."
end. If the status is set to desired(3), the port will send flow control to
the far end if the far end supports it."
C<portAdminTxFlowControl>