From 3f4d6fb21ca7e255b0055e349e38261bf8e1a719 Mon Sep 17 00:00:00 2001 From: Max Baker <> Date: Mon, 30 Dec 2002 20:17:46 +0000 Subject: [PATCH] Initial Import. Ver 0.1 --- Info/Bridge.pm | 196 ++++++++++++++ Info/CDP.pm | 258 +++++++++++++++++++ Info/EtherLike.pm | 141 +++++++++++ Info/Layer1.pm | 294 +++++++++++++++++++++ Info/Layer1/Allied.pm | 218 ++++++++++++++++ Info/Layer1/Asante.pm | 261 +++++++++++++++++++ Info/Layer2.pm | 263 +++++++++++++++++++ Info/Layer2/Bay.pm | 428 +++++++++++++++++++++++++++++++ Info/Layer2/C1900.pm | 293 +++++++++++++++++++++ Info/Layer2/C2900.pm | 264 +++++++++++++++++++ Info/Layer2/Catalyst.pm | 508 +++++++++++++++++++++++++++++++++++++ Info/Layer2/HP.pm | 547 ++++++++++++++++++++++++++++++++++++++++ Info/Layer3.pm | 377 +++++++++++++++++++++++++++ Info/Layer3/Aironet.pm | 327 ++++++++++++++++++++++++ Info/Layer3/Foundry.pm | 428 +++++++++++++++++++++++++++++++ Info/MAU.pm | 274 ++++++++++++++++++++ 16 files changed, 5077 insertions(+) create mode 100644 Info/Bridge.pm create mode 100644 Info/CDP.pm create mode 100644 Info/EtherLike.pm create mode 100644 Info/Layer1.pm create mode 100644 Info/Layer1/Allied.pm create mode 100644 Info/Layer1/Asante.pm create mode 100644 Info/Layer2.pm create mode 100644 Info/Layer2/Bay.pm create mode 100644 Info/Layer2/C1900.pm create mode 100644 Info/Layer2/C2900.pm create mode 100644 Info/Layer2/Catalyst.pm create mode 100644 Info/Layer2/HP.pm create mode 100644 Info/Layer3.pm create mode 100644 Info/Layer3/Aironet.pm create mode 100644 Info/Layer3/Foundry.pm create mode 100644 Info/MAU.pm diff --git a/Info/Bridge.pm b/Info/Bridge.pm new file mode 100644 index 00000000..60b7090f --- /dev/null +++ b/Info/Bridge.pm @@ -0,0 +1,196 @@ +# SNMP::Info::Bridge +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Bridge; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; + +use vars qw/$VERSION $DEBUG %MIBS %FUNCS %GLOBALS %MUNGE $INIT/; +@SNMP::Info::Bridge::ISA = qw/SNMP::Info Exporter/; +@SNMP::Info::Bridge::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +$INIT = 0; +%MIBS = ('BRIDGE-MIB' => 'dot1dBaseBridgeAddress'); +%GLOBALS = ( + 'b_mac' => 'dot1dBaseBridgeAddress', + 'b_ports' => 'dot1dBaseNumPorts', + 'b_type' => 'dot1dBaseType' + ); + +%FUNCS = ( + # Forwarding Table: Dot1dTpFdbEntry + 'fw_mac' => 'dot1dTpFdbAddress', + 'fw_port' => 'dot1dTpFdbPort', + 'fw_status' => 'dot1dTpFdbStatus', + # Bridge Port Table: Dot1dBasePortEntry + 'bp_index' => 'dot1dBasePortIfIndex', + 'bp_port' => 'dot1dBasePortCircuit ', + # Bridge Static (Destination-Address Filtering) Database + 'bs_mac' => 'dot1dStaticAddress', + 'bs_port' => 'dot1dStaticReceivePort', + 'bs_to' => 'dot1dStaticAllowedToGoTo', + 'bs_status' => 'dot1dStaticStatus', + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::MUNGE, + # Add ones for our class + 'fw_mac' => \&SNMP::Info::munge_mac, + 'bs_mac' => \&SNMP::Info::munge_mac, + ); + +1; +__END__ + + +=head1 NAME + +SNMP::Info::Bridge - Perl5 Interface to BRIDGE-MIB + +=head1 DESCRIPTION + +BRIDGE-MIB is used by most Layer 2 devices like Switches + +Inherits all methods from SNMP::Info + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $bridge = new SNMP::Info::Bridge(DestHost => 'myswitch', + Community => 'public'); + my $mac = $bridge->mac(); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Bridge() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $bridge = new SNMP::Info::Bridge( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $bridge; + +=item $bridge->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $bridge->session(); + + # Set + my $newsession = new SNMP::Session(...); + $bridge->session($newsession); + +=back + +=head1 Bridge Global Configuration Values + +=over + +=item $bridge->b_mac() + +Returns the MAC Address of the root bridge port + +(B) + +=item $bridge->b_ports() + +Returns the number of ports in device + +(B) + +=item $bridge->b_type() + +Returns the type? of the device + +(B) + +=back + +=head1 TABLE ENTRIES + +=head2 Forwarding Table (dot1dTpFdbEntry) + +=over + +=item $bridge->fw_mac() + +Returns reference to hash of forwarding table MAC Addresses + +(B) + +=item $bridge->fw_port() + +Returns reference to hash of forwarding table entries port interface identifier (iid) + +(B) + +=item $bridge->fw_status() + +Returns reference to hash of forwading table entries status + +(B) + +=back + +=head2 Bridge Port Table (dot1dBasePortEntry) + +=over + +=item $bridge->bp_index() + +Returns reference to hash of bridge port table entries map back to interface identifier (iid) + +(B) + +=item $bridge->bp_port() + +Returns reference to hash of bridge port table entries physical port name. + +(B) + +=back +=cut diff --git a/Info/CDP.pm b/Info/CDP.pm new file mode 100644 index 00000000..53c940cf --- /dev/null +++ b/Info/CDP.pm @@ -0,0 +1,258 @@ +# SNMP::Info::CDP +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::CDP; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; +use Carp; + +@SNMP::Info::CDP::ISA = qw/SNMP::Info Exporter/; +@SNMP::Info::CDP::EXPORT_OK = qw//; + +use vars qw/$VERSION $DEBUG %FUNCS %GLOBALS %MIBS %MIBS_V1 %MUNGE $INIT/; +# Debug +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +# Five data structures required by SNMP::Info +$INIT = 0; +%MIBS = ( 'CISCO-CDP-MIB' => 'cdpGlobalRun' ); +%MIBS_V1 = ( 'CISCO-CDP-MIB-V1SMI' => 'cdpGlobalRun' ); +# Notice we dont inherit the default GLOBALS and FUNCS +# only the default MUNGE. +%GLOBALS = ( + 'cdp_run' => 'cdpGlobalRun', + 'cdp_interval' => 'cdpGlobalMessageInterval', + 'cdp_holdtime' => 'cdpGlobalHoldTime', + 'cdp_id' => 'cdpGlobalDeviceId', + ); + +%FUNCS = ( + 'c_if' => 'cdpCacheIfIndex', + 'c_proto' => 'cdpCacheAddressType', + 'c_ip' => 'cdpCacheAddress', + 'c_ver' => 'cdpCacheVersion', + 'c_id' => 'cdpCacheDeviceId', + 'c_port' => 'cdpCacheDevicePort', + 'c_platform' => 'cdpCachePlatform', + 'c_capabilities' => 'cdpCacheCapabilities', + 'c_domain' => 'cdpCacheVTPMgmtDomain', + 'c_vlan' => 'cdpCacheNativeVLAN', + 'c_duplex' => 'cdpCacheDuplex' + ); + +%MUNGE = ( + 'c_capabilities' => \&SNMP::Info::munge_octet2hex, + 'c_ip' => \&SNMP::Info::munge_ip + ); + + +sub hasCDP { + my $cdp = shift; + + my $ver = $cdp->{_version}; + + + # SNMP v1 clients dont have the globals + if (defined $ver and $ver == 1){ + my $c_ip = $cdp->c_ip(); + # See if anything in cdp cache, if so we have cdp + return 1 if (defined $c_ip and scalar(keys %$c_ip)) ; + return undef; + } + + return $cdp->cdp_run(); +} +1; +__END__ + +=head1 NAME + +SNMP::Info::CDP - Perl5 Interface to Cisco Discovery Protocol (CDP) using SNMP + +=head1 DESCRIPTION + +CDP provides Layer 2 discovery of attached devices that also +speak CDP, including switches, routers and hubs. + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $cdp = new SNMP::Info::CDP( DestHost => 'router' , + Community => 'public' ); + $hascdp = $cdp->hasCDP() ? 'yes' : 'no'; + @neighbor_ips = values( %{$cdp->ip()} ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::CDP() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $cdp = new SNMP::Info::CDP( + DestHost => $host, + Community => 'public' + ) + die "Couldn't connect.\n" unless defined $cdp; + +=item $cdp->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $cdp->session(); + + # Set + my $newsession = new SNMP::Session(...); + $cdp->session($newsession); + +=back + +=head2 Your Device May Vary + +Each device implements a subset of the global and cache entries. +Check the return value to see if that data is held by the device. + +=head1 CDP GLOBAL VALUES + +=over + +=item $cdp->hasCDP() + +Is CDP is active in this device? + +Accounts for SNMP version 1 devices which may have CDP but not cdp_run() + +=item $cdp->cdp_run() + +Is CDP enabled on this device? + +(B) + +=item $cdp->cdp_interval() + +Interval in seconds at which CDP messages are generated. + +(B) + +=item $cdp->cdp_holdtime() + +Time in seconds that CDP messages are kept. + +(B) + +=item $cdp->cdp_id() + +Returns CDP device ID. + +This is the device id broadcast via CDP to other devices, and is what is retrieved from remote devices with $cdp->id(). + +(B) + +=back + +=head1 CDP CACHE ENTRIES + +=over + +=item $cdp->c_proto() + +Returns remote address type received. Usually IP. + +(B) + +=item $cdp->c_ip() + +Returns remote IP address + +(B) + +=item $cdp->c_ver() + +Returns remote hardware version + +(B) + +=item $cdp->c_id() + +Returns remote device id string + +(B) + +=item $cdp->c_port() + +Returns remote port ID + +(B) + +=item $cdp->c_platform() + +Returns remote platform id + +(B) + +=item $cdp->c_capabilities() + +Returns Device Functional Capabilities bitmap. + +Anyone know where I can get info on how to decode this? + +(B) + +=item $cdp->c_domain() + +Returns remote VTP Management Domain as defined in CISCO-VTP-MIB::managementDomainName + +(B) + +=item $cdp->c_vlan() + +Returns the remote interface native VLAN. + +(B) + +=item $cdp->c_duplex() + +Returns the port duplex status from remote devices. + +(B) + +=back + +=cut diff --git a/Info/EtherLike.pm b/Info/EtherLike.pm new file mode 100644 index 00000000..6412528f --- /dev/null +++ b/Info/EtherLike.pm @@ -0,0 +1,141 @@ +# SNMP::Info::EtherLike +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::EtherLike; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; + +use vars qw/$VERSION $DEBUG %MIBS %FUNCS %GLOBALS %MUNGE $INIT/; +@SNMP::Info::EtherLike::ISA = qw/SNMP::Info Exporter/; +@SNMP::Info::EtherLike::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +$INIT = 0; + +# Same info in both rfc1398 and this? +%MIBS = ('ETHERLIKE-MIB' => 'etherMIB' ); + +%GLOBALS = (); + +%FUNCS = ( + # EtherLike StatsTable + 'el_index' => 'dot3StatsIndex', + 'el_duplex' => 'dot3StatsDuplexStatus', + ); + +%MUNGE = ( %SNMP::Info::MUNGE ); + +1; +__END__ + + +=head1 NAME + +SNMP::Info::EtherLike - Perl5 Interface to SNMP ETHERLIKE-MIB + +=head1 DESCRIPTION + +ETHERLIKE-MIB is used by some Layer 3 Devices such as Cisco routers. + +Inherits all methods from SNMP::Info + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $el = new SNMP::Info::EtherLike(DestHost => 'myrouter', + Community => 'public'); + + my $el_decoder = $el->el_index(); + my $el_duplex = $el->el_duplex(); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::EtherLike() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $el = new SNMP::Info::EtherLike( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $el; + +=item $el->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $el->session(); + + # Set + my $newsession = new SNMP::Session(...); + $el->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item None + +=back + +=head1 ETHERLIKE STATS TABLE (dot3StatsTable) + +=over + +=item $el->el_index() + +Returns reference to hash. Indexes Stats Table to the interface index (iid). + +(B) + +=item $el->el_duplex() + +Returns reference to hash. Indexes Stats Table to Duplex Status of port. + +(B) + +=back + +=cut diff --git a/Info/Layer1.pm b/Info/Layer1.pm new file mode 100644 index 00000000..e095463c --- /dev/null +++ b/Info/Layer1.pm @@ -0,0 +1,294 @@ +# SNMP::Info::Layer1 - SNMP Interface to Layer1 Devices +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer1; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; + +use vars qw/$VERSION $DEBUG %GLOBALS %MIBS %FUNCS %PORTSTAT %MUNGE $INIT/; + +@SNMP::Info::Layer1::ISA = qw/SNMP::Info Exporter/; +@SNMP::Info::Layer1::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +# See SNMP::Info for the details of these data structures and +# the interworkings. +$INIT = 0; + +%MIBS = ( %SNMP::Info::MIBS, + 'SNMP-REPEATER-MIB' => 'rptrPortGroupIndex' + ); + +%GLOBALS = ( + %SNMP::Info::GLOBALS, + 'ports_managed' => 'ifNumber', + 'rptr_slots' => 'rptrGroupCapacity', + 'slots' => 'rptrGroupCapacity' + ); + +%FUNCS = ( + %SNMP::Info::FUNCS, + 'i_up2' => 'ifOperStatus', + 'i_up_admin2' => 'ifAdminStatus', + 'rptr_ports' => 'rptrGroupPortCapacity', + 'rptr_port' => 'rptrPortIndex', + 'rptr_slot' => 'rptrPortGroupIndex', + 'rptr_up_admin' => 'rptrPortAdminStatus', + 'rptr_up' => 'rptrPortOperStatus', + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::MUNGE, + ); + +# Method OverRides + +# assuming managed ports aren't in repeater ports? +sub ports { + my $l1 = shift; + + my $ports = $l1->ports_managed(); + my $rptr_ports = $l1->rptr_ports(); + + foreach my $group (keys %$rptr_ports){ + $ports += $rptr_ports->{$group}; + } + + return $ports; +} + +# $l1->model() - Looks at sysObjectID which gives the oid of the system +# name, contained in a propriatry MIB. +sub model { + my $l1 = shift; + my $id = $l1->id(); + my $model = &SNMP::translateObj($id); + + # HP + $model =~ s/^hpswitch//i; + + # Cisco + $model =~ s/sysid$//i; + + return $model; +} + +sub vendor { + my $l1 = shift; + my $descr = $l1->description(); + + return 'hp' if ($descr =~ /hp/i); + return 'cisco' if ($descr =~ /(catalyst|cisco|ios)/i); + return 'allied' if ($descr =~ /allied/i); + return 'asante' if ($descr =~ /asante/i); + +} + +# By Default we'll use the description field +sub interfaces { + my $l1 = shift; + my $interfaces = $l1->i_index(); + my $rptr_port = $l1->rptr_port(); + + foreach my $port (keys %$rptr_port){ + $interfaces->{$port} = $port; + } + return $interfaces; +} + +sub i_up_admin { + my $l1 = shift; + + my $i_up_admin = $l1->i_up_admin2(); + my $rptr_up_admin = $l1->rptr_up_admin(); + + foreach my $key (keys %$rptr_up_admin){ + my $up = $rptr_up_admin->{$key}; + $i_up_admin->{$key} = 'up' if $up =~ /enabled/; + $i_up_admin->{$key} = 'down' if $up =~ /disabled/; + } + + return $i_up_admin; +} + +sub i_up { + my $l1 = shift; + my $i_up = $l1->i_up2(); + my $rptr_up = $l1->rptr_up(); + + foreach my $key (keys %$rptr_up){ + my $up = $rptr_up->{$key}; + $i_up->{$key} = 'up' if $up =~ /operational/; + } + + return $i_up; + +} +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer1 - Perl5 Interface to Layer1 network devices. + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +Layer1 device through SNMP. Information is stored in a number of MIBs. + +See super classes for descriptions of other available methods. + +Inherits from: + + SNMP::Info + +MIBS: + + MIBS listed in SNMP::Info + +Cisco MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $l1 = new SNMP::Info::Layer1(DestHost => 'mybridge' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer1() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $l1 = new SNMP::Info::Layer1( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $l1; + +=item $l1->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $l1->session(); + + # Set + my $newsession = new SNMP::Session(...); + $l1->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $l1->vendor() + +Trys to discover the vendor from $l1->model() and $l1->vendor() + +=item $l1->ports_managed() + +Gets the number of ports under the interface mib + +(B) + +=item $l1->ports() + +Adds the values from rptr_ports() and ports_managed() + +=item $l1->slots() + +Number of 'groups' in the Repeater MIB + +(B) + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $l1->interfaces() + +=item $l1->i_up() + +=item $l1->i_up_admin() + +=back + +=head2 Repeater MIB + +=over + +=item $l1->rptr_ports() + +Number of ports in each group. + +(B) + +=item $l1->rptr_port() + +Port number in Group + +(B) + +=item $l1->rptr_slot() + +Group (slot) Number for given port. + +(B) + +=item $l1->rptr_up_admin() + +(B) + +=item $l1->rptr_up() + +(B) + +=back + +=cut diff --git a/Info/Layer1/Allied.pm b/Info/Layer1/Allied.pm new file mode 100644 index 00000000..6c63b0ca --- /dev/null +++ b/Info/Layer1/Allied.pm @@ -0,0 +1,218 @@ +# SNMP::Info::Layer1::Allied +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer1::Allied; +$VERSION = 0.1; +use strict; + +use Exporter; +use SNMP::Info::Layer1; + +@SNMP::Info::Layer1::Allied::ISA = qw/SNMP::Info::Layer1 Exporter/; +@SNMP::Info::Layer1::Allied::EXPORT_OK = qw//; + +use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/; + +# Set for No CDP +%GLOBALS = ( + %SNMP::Info::Layer1::GLOBALS, + 'root_ip' => 'actualIPAddr', + ); + +%FUNCS = (%SNMP::Info::Layer1::FUNCS, + 'i_name2' => 'ifName', + 'ati_p_name' => 'portName', + 'ati_up' => 'linkTestLED', + ); + +%MIBS = ( + %SNMP::Info::Layer1::MIBS, + 'ATI-MIB' => 'atiPortGroupIndex' + ); + +%MUNGE = (%SNMP::Info::Layer1::MUNGE, + ); + +sub vendor { + return 'allied'; +} + +sub model { + my $allied = shift; + + my $desc = $allied->description(); + + if ($desc =~ /(AT-\d{4}\S{1}?)/){ + return $1; + } + return undef; +} + +sub i_name{ + my $allied = shift; + + my $i_name = $allied->i_name2(); + + my $ati_p_name = $allied->ati_p_name(); + + foreach my $port (keys %$ati_p_name){ + my $name = $ati_p_name->{$port}; + $i_name->{$port} = $name if (defined $name and $name !~ /^\s*$/); + } + + return $i_name; +} + +sub i_up { + my $allied = shift; + + my $i_up = SNMP::Info::Layer1::i_up($allied); + my $ati_up = $allied->ati_up(); + + foreach my $port (keys %$ati_up){ + my $up = $ati_up->{$port}; + $i_up->{$port} = 'down' if $up eq 'linktesterror'; + $i_up->{$port} = 'up' if $up eq 'nolinktesterror'; + } + + return $i_up; +} +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer1::Allied - SNMP Interface to old Allied Hubs + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +Allied device through SNMP. See inherited classes' documentation for +inherited methods. + +Inherits from: + + SNMP::Info::Layer1 + +Required MIBs: + + ATI-MIB - Download for your device from http://www.allied-telesyn.com/allied/support/ + + MIBs listed in SNMP::Info::Layer1 + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $allied = new SNMP::Info::Layer1::Allied(DestHost => 'mycat1900' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer1::Allied() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $allied = new SNMP::Info::Layer1::Allied( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $allied; + +=item $allied->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $allied->session(); + + # Set + my $newsession = new SNMP::Session(...); + $allied->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $allied->vendor() + +Returns 'allied' :) + +=item $allied->root_ip() + +Returns IP Address of Managed Hub. + +(B) + +=item $allied->model() + +Trys to cull out AT-nnnnX out of the description field. + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $allied->i_name() + +Returns reference to map of IIDs to human-set port name. + +=item $allied->i_up() + +Returns reference to map of IIDs to link status. Changes +the values of ati_up() to 'up' and 'down'. + +=back + +=head2 Allied MIB + +=over + +=item $allied->ati_p_name() + +(B) + +=item $allied->ati_up() + +(B) + +=back + +=cut diff --git a/Info/Layer1/Asante.pm b/Info/Layer1/Asante.pm new file mode 100644 index 00000000..a381586d --- /dev/null +++ b/Info/Layer1/Asante.pm @@ -0,0 +1,261 @@ +# SNMP::Info::Layer1::Asante +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer1::Asante; +$VERSION = 0.1; +use strict; + +use Exporter; +use SNMP::Info::Layer1; + +@SNMP::Info::Layer1::Asante::ISA = qw/SNMP::Info::Layer1 Exporter/; +@SNMP::Info::Layer1::Asante::EXPORT_OK = qw//; + +use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/; + +# Set for No CDP +%GLOBALS = ( + %SNMP::Info::Layer1::GLOBALS, + ); + +%FUNCS = (%SNMP::Info::Layer1::FUNCS, + 'i_speed2' => 'ifSpeed', + 'i_mac2' => 'ifPhysAddress', + 'i_descr2' => 'ifDescr', + 'i_name2' => 'ifName', + 'asante_port' => 'ePortIndex', + 'asante_group' => 'ePortGrpIndex', + 'i_type' => 'ePortStateType', + 'asante_up' => 'ePortStateLinkStatus', + ); + +%MIBS = ( + %SNMP::Info::Layer1::MIBS, + 'ASANTE-HUB1012-MIB' => 'asante' + ); + +%MUNGE = (%SNMP::Info::Layer1::MUNGE, + 'i_mac2' => \&SNMP::Info::munge_mac, + 'i_speed2' => \&SNMP::Info::munge_speed, + ); + +sub interfaces { + my $asante = shift; + + my $rptr_port = $asante->rptr_port(); + + my %interfaces; + + foreach my $port (keys %$rptr_port){ + $interfaces{$port} = $port; + } + + return \%interfaces; +} + +sub vendor { + return 'asante'; +} + +sub model { + my $asante = shift; + + my $id = $asante->id(); + my $model = &SNMP::translateObj($id); + + return $model; +} + +sub i_up { + my $asante = shift; + + my $asante_up = $asante->asante_up(); + + my $i_up = {}; + foreach my $port (keys %$asante_up){ + my $up = $asante_up->{$port}; + $i_up->{$port} = 'down' if $up =~ /on/; + $i_up->{$port} = 'up' if $up =~ /off/; + } + + return $i_up; +} + +sub i_speed { + my $asante = shift; + + my $i_speed = $asante->i_speed2(); + + my %i_speed; + + $i_speed{"1.2"} = $i_speed->{1}; + + return \%i_speed; +} + +sub i_mac { + my $asante = shift; + + my $i_mac = $asante->i_mac2(); + + my %i_mac; + + $i_mac{"1.2"} = $i_mac->{1}; + + return \%i_mac; +} + +sub i_description { + return undef; +} + +sub i_name { + my $asante = shift; + + my $i_name = $asante->i_descr2(); + + my %i_name; + + $i_name{"1.2"} = $i_name->{1}; + + return \%i_name; +} +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer1::Asante - SNMP Interface to old Asante 1012 Hubs + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +Asante device through SNMP. See inherited classes' documentation for +inherited methods. + +Inherits from: + + SNMP::Info::Layer1 + +Required MIBs: + +ASANTE-HUB1012-MIB - Download from http://www.mibdepot.com + + MIBs listed in SNMP::Info::Layer1 + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $asante = new SNMP::Info::Layer1::Asante(DestHost => 'mycat1900' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer1::Asante() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $asante = new SNMP::Info::Layer1::Asante( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $asante; + +=item $asante->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $asante->session(); + + # Set + my $newsession = new SNMP::Session(...); + $asante->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $asante->vendor() + +Returns 'asante' :) + +=item $asante->root_ip() + +Returns IP Address of Managed Hub. + +(B) + +=item $asante->model() + +Trys to cull out AT-nnnnX out of the description field. + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $asante->i_name() + +Returns reference to map of IIDs to human-set port name. + +=item $asante->i_up() + +Returns reference to map of IIDs to link status. Changes +the values of ati_up() to 'up' and 'down'. + +=back + +=head2 Asante MIB + +=over + +=item $asante->ati_p_name() + +(B) + +=item $asante->ati_up() + +(B) + +=back + +=cut diff --git a/Info/Layer2.pm b/Info/Layer2.pm new file mode 100644 index 00000000..b38f77e0 --- /dev/null +++ b/Info/Layer2.pm @@ -0,0 +1,263 @@ +# SNMP::Info::Layer2 - SNMP Interface to Layer2 Devices +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer2; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; +use SNMP::Info::Bridge; +use SNMP::Info::CDP; + +use vars qw/$VERSION $DEBUG %GLOBALS %MIBS %FUNCS %PORTSTAT %MUNGE $INIT/; + +@SNMP::Info::Layer2::ISA = qw/SNMP::Info SNMP::Info::Bridge SNMP::Info::CDP Exporter/; +@SNMP::Info::Layer2::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +# See SNMP::Info for the details of these data structures and +# the interworkings. +$INIT = 0; + +%MIBS = ( %SNMP::Info::MIBS, + %SNMP::Info::Bridge::MIBS, + %SNMP::Info::CDP::MIBS, + 'CISCO-PRODUCTS-MIB' => 'sysName', + 'CISCO-STACK-MIB' => 'wsc1900sysID', + 'HP-ICF-OID' => 'hpSwitch4000', + ); + +%GLOBALS = ( + %SNMP::Info::GLOBALS, + %SNMP::Info::Bridge::GLOBALS, + %SNMP::Info::CDP::GLOBALS, + ); + +%FUNCS = ( + %SNMP::Info::FUNCS, + %SNMP::Info::Bridge::FUNCS, + %SNMP::Info::CDP::FUNCS, + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::MUNGE, + %SNMP::Info::Bridge::MUNGE, + %SNMP::Info::CDP::MUNGE, + ); + +# Method OverRides + +# $l2->model() - Looks at sysObjectID which gives the oid of the system +# name, contained in a propriatry MIB. +sub model { + my $l2 = shift; + my $id = $l2->id(); + my $model = &SNMP::translateObj($id); + + # HP + $model =~ s/^hpswitch//i; + + # Cisco + $model =~ s/sysid$//i; + + return $model; +} + +sub vendor { + my $l2 = shift; + my $model = $l2->model(); + my $descr = $l2->description(); + + if ($model =~ /hp/i or $descr =~ /hp/i) { + return 'hp'; + } + + if ($model =~ /catalyst/i or $descr =~ /(catalyst|cisco)/i) { + return 'cisco'; + } + +} + +sub i_ignore { + my $l2 = shift; + + my $i_type = $l2->i_type(); + + my %i_ignore = (); + + foreach my $if (keys %$i_type){ + my $type = $i_type->{$if}; + $i_ignore{$if}++ + if $type =~ /(loopback|propvirtual|other|cpu)/i; + } + + return \%i_ignore; +} + +# By Default we'll use the description field +sub interfaces { + my $l2 = shift; + my $interfaces = $l2->i_index(); + my $i_descr = $l2->i_description(); + my $i_name = $l2->i_name(); + + my %if; + foreach my $iid (keys %$interfaces){ + my $port = $i_descr->{$iid}; + my $name = $i_name->{$iid}; + $port = $name if (defined $name and $name !~ /^\s*$/); + next unless defined $port; + + # Cisco 1900 has a space in some of its port descr. + # get rid of any weird characters + $port =~ s/[^\d\/,()\w]+//gi; + + # Translate Cisco 2926,etc. from 1/5 to 1.5 + $port =~ s/\//\./ if ($port =~ /^\d+\/\d+$/); + + $if{$iid} = $port; + } + + return \%if +} + +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer2 - Perl5 Interface to Layer2 network devices. + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +Layer2 device through SNMP. Information is stored in a number of MIBs. + +See super classes for descriptions of other available methods. + +Inherits from: + + SNMP::Info + SNMP::Info::Bridge + SNMP::Info::CDP + +MIBS: + + CISCO-PRODUCTS-MIB - Needed for ID of Cisco Products + CISCO-STACK-MIB - Needed for ID of Cisco Products + HP-ICF-OID - Needed for ID of HP Products + MIBS listed in SNMP::Info::Bridge and SNMP::Info::CDP + +Cisco MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz + +HP MIBs can be found at http://www.hp.com/rnd/software + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $l2 = new SNMP::Info::Layer2(DestHost => 'mybridge' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer2() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $l2 = new SNMP::Info::Layer2( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $l2; + +=item $l2->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $l2->session(); + + # Set + my $newsession = new SNMP::Session(...); + $l2->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $l2->model() + +Cross references $l2->id() with product IDs in the +Cisco and HP specific MIBs. + +For HP devices, removes 'hpswitch' from the name + +For Cisco devices, removes 'sysid' from the name + +=item $l2->vendor() + +Trys to discover the vendor from $l2->model() and $l2->vendor() + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $l2->interfaces() + +Creates a map between the interface identifier (iid) and the physical port name. + +Defaults to B but checks and overrides with B + +=item $l2->i_ignore() + +Returns reference to hash. Increments value of IID if port is to be ignored. + +Ignores ports with B of loopback,propvirtual,other, and cpu + +=back + +=cut diff --git a/Info/Layer2/Bay.pm b/Info/Layer2/Bay.pm new file mode 100644 index 00000000..1413d216 --- /dev/null +++ b/Info/Layer2/Bay.pm @@ -0,0 +1,428 @@ +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# SNMP::Info::Layer2::Bay +# Max Baker + +package SNMP::Info::Layer2::Bay; +$VERSION = 0.1; +use strict; + +use Exporter; +use SNMP::Info::Layer2; + +@SNMP::Info::Layer2::Bay::ISA = qw/SNMP::Info::Layer2 Exporter/; +@SNMP::Info::Layer2::Bay::EXPORT_OK = qw//; + +use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/; + +# Set for No CDP +%GLOBALS = ( %SNMP::Info::Layer2::GLOBALS, + 'cdp_id' => 's5EnMsTopIpAddr', + 'cdp_run' => 's5EnMsTopStatus', + ); + +%FUNCS = (%SNMP::Info::Layer2::FUNCS, + 'imac2' => 'ifPhysAddress', + # S5-ETH-MULTISEG-TOPOLOGY-MIB::s5EnMsTopNmmTable + 'bay_topo_slot' => 's5EnMsTopNmmSlot', + 'bay_topo_port' => 's5EnMsTopNmmPort', + 'bay_topo_ip' => 's5EnMsTopNmmIpAddr', + 'bay_topo_seg' => 's5EnMsTopNmmSegId', + 'bay_topo_mac' => 's5EnMsTopNmmMacAddr', + 'bay_topo_platform' => 's5EnMsTopNmmChassisType', + 'bay_topo_localseg' => 's5EnMsTopNmmLocalSeg', + ); + +%MIBS = ( + %SNMP::Info::Layer2::MIBS, + 'SYNOPTICS-ROOT-MIB' => 'synoptics', + 'S5-ETH-MULTISEG-TOPOLOGY-MIB' => 's5EnMsTop' + ); + +delete $MIBS{'CISCO-CDP-MIB'}; +# 450's report full duplex as speed = 20mbps?! +$SNMP::Info::SPEED_MAP{20_000_000} = '10 Mbps'; +$SNMP::Info::SPEED_MAP{200_000_000} = '100 Mbps'; + +%MUNGE = (%SNMP::Info::Layer2::MUNGE, + 'i_mac2' => \&SNMP::Info::munge_mac , + ); + +sub vendor { + # or nortel, or synopsis? + return 'bay'; +} + +sub i_ignore { + my $bay = shift; + my $descr = $bay->description(); + + my $i_type = $bay->i_type(); + + my %i_ignore; + foreach my $if (keys %$i_type){ + my $type = $i_type->{$if}; + $i_ignore{$if}++ if $type =~ /(loopback|propvirtual|cpu)/i; + } + + return \%i_ignore; +} + +sub interfaces { + my $bay = shift; + my $i_index = $bay->i_index(); + + return $i_index; +} + +sub i_mac { + my $bay = shift; + my $i_mac = $bay->i_mac2(); + + # Bay 303's with a hw rev < 2.11.4.5 report the mac as all zeros + foreach my $iid (keys %$i_mac){ + my $mac = $i_mac->{$iid}; + delete $i_mac->{$iid} if $mac eq '00:00:00:00:00:00'; + } + return $i_mac; +} + + +sub model { + my $bay = shift; + my $id = $bay->id(); + my $model = &SNMP::translateObj($id); + $model =~ s/^sreg-//i; + + my $descr = $bay->description(); + + return '303' if ($descr =~ /\D303\D/); + return '304' if ($descr =~ /\D304\D/); + return $model; +} + +# Hack in some CDP type stuff + +sub c_if { + my $bay = shift; + my $bay_topo_port = $bay->bay_topo_port(); + + my %c_if; + foreach my $entry (keys %$bay_topo_port){ + my $port = $bay_topo_port->{$entry}; + next if $port == 0; + $c_if{"$port.1"} = $port; + } + return \%c_if; +} + +sub c_ip { + my $bay = shift; + my $bay_topo_ip = $bay->bay_topo_ip(); + my $bay_topo_port = $bay->bay_topo_port(); + my $ip = $bay->cdp_ip(); + + # Count the number of devices seen on each port. + # more than one device seen means connected to a non-bay + # device, but other bay devices are squawking further away. + my %ip_port; + foreach my $entry (keys %$bay_topo_ip){ + my $port = $bay_topo_port->{$entry}; + next if $port == 0; + my $ip = $bay_topo_ip->{$entry}; + push(@{$ip_port{$port}},$ip); + } + + my %c_ip; + foreach my $port (keys %ip_port){ + my $ips = $ip_port{$port}; + if (scalar @$ips == 1) { + $c_ip{"$port.1"} = $ips->[0]; + } else { + $c_ip{"$port.1"} = $ips; + } + } + + return \%c_ip; +} + +sub c_port { + my $bay = shift; + my $bay_topo_port = $bay->bay_topo_port(); + my $bay_topo_seg = $bay->bay_topo_seg(); + + my %c_port; + foreach my $entry (keys %$bay_topo_seg){ + my $port = $bay_topo_port->{$entry}; + next if $port == 0; + + # For fake remotes (multiple IPs for a c_ip), use first found + next if defined $c_port{"$port.1"}; + + my $seg = $bay_topo_seg->{$entry}; + + # Segment id is (256 * remote slot_num) + (remote_port) + my $remote_port = $seg % 256; + + $c_port{"$port.1"} = $remote_port; + } + + return \%c_port; +} + +sub c_platform { + my $bay = shift; + my $bay_topo_port = $bay->bay_topo_port(); + my $bay_topo_platform = $bay->bay_topo_platform(); + + + my %c_platform; + foreach my $entry (keys %$bay_topo_platform){ + my $port = $bay_topo_port->{$entry}; + next if $port == 0; + + # For fake remotes (multiple IPs for a c_ip), use first found + next if defined $c_platform{"$port.1"}; + + my $platform = $bay_topo_platform->{$entry}; + + $c_platform{"$port.1"} = $platform; + } + + return \%c_platform; +} + + +__END__ + +=head1 NAME + +SNMP::Info::Layer2::Bay - SNMP Interface to old Bay Network Switches + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +Bay device through SNMP. + +Inherits from + + SNMP::Info::Layer2 + +Required MIBs: + + SYNOPTICS-ROOT-MIB + S5-ETH-MULTISEG-TOPOLOGY-MIB + MIBS listed in SNMP::Info::Layer2 + +Bay MIBs can be found on the CD that came with your product. + +Or, if you still have a service contract they can be downloaded at +www.nortelnetworks.com + +They have also been seen at : http://www.inotech.com/mibs/vendor/baynetworks/synoptics/synoptics.asp + +Or http://www.oidview.com/mibs/detail.html under Synoptics. + +You will need at least the two listed above, and probably a few more. + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $bay = new SNMP::Info::Layer2::Bay(DestHost => 'mybayswitch' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer2::Bay() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $bay = new SNMP::Info::Layer2::Bay( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $bay; + +=item $bay->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $bay->session(); + + # Set + my $newsession = new SNMP::Session(...); + $bay->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $bay->vendor() + +Returns 'bay' :) + +=item $bay->model() + +Cross references $bay->id() to the SYNOPTICS-MIB and returns +the results. 303s and 304s have the same ID, so we have a hack +to return depending on which it is. + +Removes sreg- from the model name + +=item $bay->cdp_id() + +Returns the IP that the device is sending out for its Nmm topology info. + +(B) + +=item $bay->cdp_run() + +Returns if the S5-ETH-MULTISEG-TOPOLOGY info is on for this device. + +(B) + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $bay->interfaces() + +Returns reference to map of IIDs to physical ports. + +Currently simply returns the B + +=item $bay->i_ignore() + +Returns reference to hash of IIDs to ignore. + +Simply calls the SNMP::Info::Layer2::i_ignore() fn for this. + +=item $bay->i_mac() + +Returns the B table entries. + +Removes all entries matching '00:00:00:00:00:00' -- Certain +older revisions of Bay 303 and 304 firmware report all zeros +for each port mac. + +=back + +=head2 Psuedo CDP information + +All entries with port=0 are local and ignored. + +=over + +=item $bay->c_if() + +Returns referenece to hash. Key: port.1 Value: port (iid) + +=item $bay->c_ip() + +Returns referenece to hash. Key: port.1 + +The value of each hash entry can either be a scalar or an array. +A scalar value is most likely a direct neighbor to that port. +It is possible that there is a non-bay device in between this device and the remote device. + +An array value represents a list of seen devices. The only time you will get an array +of nieghbors, is if there is a non-bay device in between two or more devices. + +Use the data from the Layer2 Topology Table below to dig deeper. + +=item $bay->port() + +Returns reference to hash. Key: port.1 Value: port + +=item $bay->platform() + +Returns reference to hash. Key: port.1 Value: Remote Device Type + +=back + +=head2 Layer2 Topology info (s5EnMsTopNmmTable) + +=over + +=item $bay->bay_topo_slot() + +Returns reference to hash. Key: Table entry, Value:slot number + +(B) + +=item $bay->bay_topo_port() + +Returns reference to hash. Key: Table entry, Value:Port Number (interface iid) + +(B) + +=item $bay->bay_topo_ip() + +Returns reference to hash. Key: Table entry, Value:Remote IP address of entry + +(B) + +=item $bay->bay_topo_seg() + +Returns reference to hash. Key: Table entry, Value:Remote Segment ID + +(B) + +=item $bay->bay_topo_mac +(B) + +Returns reference to hash. Key: Table entry, Value:Remote MAC address + +=item $bay->bay_topo_platform + +Returns reference to hash. Key: Table entry, Value:Remote Device Type + +(B) + +=item $bay->bay_topo_localseg + +Returns reference to hash. Key: Table entry, Value:Boolean, if bay_topo_seg() is local + +(B) + +=back + +=cut diff --git a/Info/Layer2/C1900.pm b/Info/Layer2/C1900.pm new file mode 100644 index 00000000..2900896a --- /dev/null +++ b/Info/Layer2/C1900.pm @@ -0,0 +1,293 @@ +# SNMP::Info::Layer2::C1900 +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer2::C1900; +$VERSION = 0.1; +use strict; + +use Exporter; +use SNMP::Info::Layer2; + +@SNMP::Info::Layer2::C1900::ISA = qw/SNMP::Info::Layer2 Exporter/; +@SNMP::Info::Layer2::C1900::EXPORT_OK = qw//; + +use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/; + +# Set for No CDP +%GLOBALS = ( + %SNMP::Info::Layer2::GLOBALS + ); + +%FUNCS = (%SNMP::Info::Layer2::FUNCS, + 'i_type2' => 'ifType', + # ESSWITCH-MIB + 'c1900_p_index' => 'swPortIndex', + 'c1900_p_ifindex' => 'swPortIfIndex', + 'c1900_p_duplex' => 'swPortDuplexStatus', + 'c1900_p_duplex_admin' => 'swPortFullDuplex', + 'c1900_p_name' => 'swPortName', + 'c1900_p_up_admin' => 'swPortAdminStatus', + 'c1900_p_type' => 'swPortMediaCapability', + 'c1900_p_media' => 'swPortConnectorType', + ); + +%MIBS = ( + %SNMP::Info::Layer2::MIBS, + # Also known as the ESSWITCH-MIB + 'STAND-ALONE-ETHERNET-SWITCH-MIB' => 'series2000' + ); + +%MUNGE = (%SNMP::Info::Layer2::MUNGE, + ); + +sub vendor { + return 'cisco'; +} + +sub i_duplex { + my $c1900 = shift; + + my $interfaces = $c1900->interfaces(); + 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; + foreach my $if (keys %$interfaces){ + my $port_1900 = $reverse_1900{$if}; + next unless defined $port_1900; + my $duplex = $c1900_p_duplex->{$port_1900}; + next unless defined $duplex; + + $duplex = 'half' if $duplex =~ /half/i; + $duplex = 'full' if $duplex =~ /full/i; + $i_duplex{$if}=$duplex; + } + return \%i_duplex; +} + +sub i_duplex_admin { + my $c1900 = shift; + + my $interfaces = $c1900->interfaces(); + 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; + foreach my $if (keys %$interfaces){ + my $port_1900 = $reverse_1900{$if}; + next unless defined $port_1900; + my $duplex = $c1900_p_admin->{$port_1900}; + next unless defined $duplex; + + $duplex = 'half' if $duplex =~ /disabled/i; + $duplex = 'full' if $duplex =~ /flow control/i; + $duplex = 'full' if $duplex =~ /enabled/i; + $duplex = 'auto' if $duplex =~ /auto/i; + $i_duplex_admin{$if}=$duplex; + } + return \%i_duplex_admin; +} + +sub i_type { + my $c1900 = shift; + + my $i_type = $c1900->i_type2(); + my $c1900_p_index = $c1900->c1900_p_index(); + my $c1900_p_type = $c1900->c1900_p_type(); + my $c1900_p_media = $c1900->c1900_p_media(); + + foreach my $p_iid (keys %$c1900_p_index){ + my $port = $c1900_p_index->{$p_iid}; + my $type = $c1900_p_type->{$p_iid}; + my $media = $c1900_p_media->{$p_iid}; + + next unless defined $port; + next unless defined $type; + next unless defined $media; + + $i_type->{$port} = "$type $media"; + } + + return $i_type; +} +__END__ + +=head1 NAME + +SNMP::Info::Layer2::C1900 - SNMP Interface to old C1900 Network Switches + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +C1900 device through SNMP. See inherited classes' documentation for +inherited methods. + +Inherits from: + + SNMP::Info::Layer2 + +Required MIBs: + + STAND-ALONE-ETHERNET-SWITCH-MIB (ESSWITCH-MIB) + MIBs listed in SNMP::Info::Layer2 + +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 + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $c1900 = new SNMP::Info::Layer2::C1900(DestHost => 'mycat1900' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer2::C1900() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $c1900 = new SNMP::Info::Layer2::C1900( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $c1900; + +=item $c1900->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $c1900->session(); + + # Set + my $newsession = new SNMP::Session(...); + $c1900->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $c1900->vendor() + +Returns 'cisco' :) + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $c1900->i_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() + +Returns reference to hash of IIDs to admin duplex setting + +Crosses $c1900->c1900_p_index() with $c1900->c1900_p_duplex_admin; + +=item $c1900->i_type() + +Returns reference to hash of IID to port type + +Takes the default ifType and overrides it with + +c1900_p_type() and c1900_p_media() if they exist. + +=back + +=head2 STAND-ALONE-ETHERNET-SWITCH-MIB Switch Port Table Entries: + +=over + +=item $c1900->c1900_p_index() + +Maps the Switch Port Table to the IID + +B + +=item $c1900->c1900_p_duplex() + +Gives Port Duplex Info + +B + +=item $c1900->c1900_p_duplex_admin() + +Gives admin setting for Duplex Info + +B + +=item $c1900->c1900_p_name() + +Gives human set name for port + +B + +=item $c1900->c1900_p_up_admin() + +Gives Admin status of port enabled. + +B + +=item $c1900->c1900_p_type() + +Gives Type of port, ie. "general-ethernet" + +B + +=item $c1900->c1900_p_media() + +Gives the media of the port , ie "fiber-sc" + +B + +=back + +=cut diff --git a/Info/Layer2/C2900.pm b/Info/Layer2/C2900.pm new file mode 100644 index 00000000..e90af809 --- /dev/null +++ b/Info/Layer2/C2900.pm @@ -0,0 +1,264 @@ +# SNMP::Info::Layer2::C2900 +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer2::C2900; +$VERSION = 0.1; +use strict; + +use Exporter; +use SNMP::Info::Layer2; + +@SNMP::Info::Layer2::C2900::ISA = qw/SNMP::Info::Layer2 Exporter/; +@SNMP::Info::Layer2::C2900::EXPORT_OK = qw//; + +use vars qw/$VERSION %FUNCS %GLOBALS %MIBS %MUNGE $AUTOLOAD $INIT $DEBUG/; + +# Set for No CDP +%GLOBALS = ( + %SNMP::Info::Layer2::GLOBALS + ); + +%FUNCS = (%SNMP::Info::Layer2::FUNCS, + # C2900PortEntry + 'c2900_p_index' => 'c2900PortIfIndex', + 'c2900_p_duplex' => 'c2900PortDuplexStatus', + 'c2900_p_duplex_admin' => 'c2900PortDuplexState', + 'c2900_p_speed_admin' => 'c2900PortAdminSpeed', + ); + +%MIBS = ( + %SNMP::Info::Layer2::MIBS, + 'CISCO-C2900-MIB' => 'ciscoC2900MIB' + ); + +%MUNGE = (%SNMP::Info::Layer2::MUNGE, + ); + +sub vendor { + return 'cisco'; +} + +sub i_duplex { + my $c2900 = shift; + + my $interfaces = $c2900->interfaces(); + my $c2900_p_index = $c2900->c2900_p_index(); + my $c2900_p_duplex = $c2900->c2900_p_duplex(); + + + my %reverse_2900 = reverse %$c2900_p_index; + + my %i_duplex; + foreach my $if (keys %$interfaces){ + my $port_2900 = $reverse_2900{$if}; + next unless defined $port_2900; + my $duplex = $c2900_p_duplex->{$port_2900}; + next unless defined $duplex; + + $duplex = 'half' if $duplex =~ /half/i; + $duplex = 'full' if $duplex =~ /full/i; + $i_duplex{$if}=$duplex; + } + return \%i_duplex; +} + +sub i_duplex_admin { + my $c2900 = shift; + + my $interfaces = $c2900->interfaces(); + my $c2900_p_index = $c2900->c2900_p_index(); + my $c2900_p_admin = $c2900->c2900_p_duplex_admin(); + + + my %reverse_2900 = reverse %$c2900_p_index; + + my %i_duplex_admin; + foreach my $if (keys %$interfaces){ + my $port_2900 = $reverse_2900{$if}; + next unless defined $port_2900; + my $duplex = $c2900_p_admin->{$port_2900}; + next unless defined $duplex; + + $duplex = 'half' if $duplex =~ /half/i; + $duplex = 'full' if $duplex =~ /full/i; + $duplex = 'auto' if $duplex =~ /auto/i; + $i_duplex_admin{$if}=$duplex; + } + return \%i_duplex_admin; +} + +# Use i_descritption for port key, cuz i_name can be manually entered. +sub interfaces { + my $c2900 = shift; + my $interfaces = $c2900->i_index(); + my $i_descr = $c2900->i_description(); + + my %if; + foreach my $iid (keys %$interfaces){ + my $port = $i_descr->{$iid}; + next unless defined $port; + + $port =~ s/\./\//g if( $port =~ /\d+\.\d+$/); + $port =~ s/[^\d\/,()\w]+//gi; + + $if{$iid} = $port; + } + + return \%if +} + +__END__ + +=head1 NAME + +SNMP::Info::Layer2::C2900 - SNMP Interface to Cisco Catalyst 2900 Network Switches + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +C2900 device through SNMP. + +MIBS: CISCO-C2900-MIB + +Inherits all SNMP::Info::Layer2 methods. + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $c2900 = new SNMP::Info::Layer2::C2900(DestHost => 'mycat2900' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer2::C2900() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $c2900 = new SNMP::Info::Layer2::C2900( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $c2900; + +=item $c2900->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $c2900->session(); + + # Set + my $newsession = new SNMP::Session(...); + $c2900->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $c2900->vendor() + + Returns 'cisco' :) + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $c2900->interfaces() + + Returns reference to the map between IID and physical Port. + + On the 2900 devices i_name isn't reliable, so we override to just the description. + + Next all dots are changed for forward slashes so that the physical port name + is the same as the broadcasted CDP port name. + (Ethernet0.1 -> Ethernet0/1) + + Also, any weird characters are removed, as I saw a few pop up. + +=item $c2900->i_duplex() + + Returns reference to map of IIDs to current link duplex + + Crosses $c2900->c2900_p_index() with $c2900->c2900_p_duplex; + +=item $c2900->i_duplex_admin() + + Returns reference to hash of IIDs to admin duplex setting + + Crosses $c2900->c2900_p_index() with $c2900->c2900_p_duplex_admin; + + +=back + +=head2 C2900-MIB Port Entry Table + +=over + +=item $c2900->c2900_p_index() + + Maps the Switch Port Table to the IID + + B + +=item $c2900->c2900_p_duplex() + + Gives Port Duplex Info + + B + +=item $c2900->c2900_p_duplex_admin() + + Gives admin setting for Duplex Info + + B + + +=item $c2900->c2900_p_speed_admin() + + Gives Admin speed of port + + B + +=back + +=cut + diff --git a/Info/Layer2/Catalyst.pm b/Info/Layer2/Catalyst.pm new file mode 100644 index 00000000..2ae3657c --- /dev/null +++ b/Info/Layer2/Catalyst.pm @@ -0,0 +1,508 @@ +# SNMP::Info::Layer2::Catalyst +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer2::Catalyst; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info::Layer2; + +use vars qw/$VERSION $DEBUG %GLOBALS %MIBS %FUNCS %PORTSTAT + %MYGLOBALS %MYMIBS %MYFUNCS %MYMUNGE %MUNGE $INIT/ ; +@SNMP::Info::Layer2::Catalyst::ISA = qw/SNMP::Info::Layer2 Exporter/; +@SNMP::Info::Layer2::Catalyst::EXPORT_OK = qw//; + +$DEBUG=0; + +# See SNMP::Info for the details of these data structures and +# the interworkings. +$INIT = 0; + +%MYMIBS = ( + 'CISCO-STACK-MIB' => 'moduleType', + 'CISCO-VTP-MIB' => 'vtpVlanIndex' + ); + +%MIBS = ( %SNMP::Info::Layer2::MIBS, + %MYMIBS ); + +%MYGLOBALS = ( + # these are in CISCO-STACK-MIB + 'sysip' => 'sysIpAddr', + 'netmask' => 'sysNetMask', + 'broadcast' => 'sysBroadcast', + 'serial' => 'chassisSerialNumberString', + 'model' => 'chassisModel', + 'ps1_type' => 'chassisPs1Type', + 'ps1_status' => 'chassisPs1Status', + 'ps2_type' => 'chassisPs2Type', + 'ps2_status' => 'chassisPs2Status', + 'slots' => 'chassisNumSlots', + 'fan' => 'chassisFanStatus' + ); +%GLOBALS = ( + %SNMP::Info::Layer2::GLOBALS, + %MYGLOBALS + ); + +%MYFUNCS = ( + 'i_type2' => 'ifType', + # 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', + # CISCO-STACK-MIB::PortCpbEntry + 'p_speed_admin' => 'portCpbSpeed', + 'p_duplex_admin' => 'portCpbDuplex', + # CISCO-VTP-MIB::VtpVlanEntry + 'v_state' => 'vtpVlanState', + 'v_type' => 'vtpVlanType', + 'v_name' => 'vtpVlanName', + 'v_mtu' => 'vtpVlanMtu', + ); +%FUNCS = ( + %SNMP::Info::Layer2::FUNCS, + %MYFUNCS + ); + +%MYMUNGE = ( + 'm_ports_status' => \&munge_port_status, + 'p_duplex_admin' => \&SNMP::Info::munge_bits, + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::Layer2::MUNGE, + %MYMUNGE + ); + +%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); +} + +# Overidden Methods + +# i_physical sets a hash entry as true if the iid is a physical port +sub i_physical { + my $cat = shift; + + my $p_port = $cat->p_port(); + + my %i_physical; + foreach my $port (keys %$p_port) { + my $iid = $p_port->{$port}; + $i_physical{$iid} = 1; + } + return \%i_physical; +} + +sub i_type { + my $cat = shift; + + my $p_port = $cat->p_port(); + my $p_type = $cat->p_type(); + + # Get more generic port types from IF-MIB + my $i_type = $cat->i_type2(); + + # Now Override w/ port entries + foreach my $port (keys %$p_type) { + my $iid = $p_port->{$port}; + $i_type->{$iid} = $p_type->{$port}; + } + + return $i_type; +} + +# p_* functions are indexed to physical port. let's index these +# to snmp iid +sub i_name { + my $cat = shift; + + my $p_port = $cat->p_port(); + my $p_name = $cat->p_name(); + + my %i_name; + foreach my $port (keys %$p_name) { + my $iid = $p_port->{$port}; + $i_name{$iid} = $p_name->{$port}; + } + return \%i_name; +} + +sub i_duplex { + my $cat = shift; + + my $p_port = $cat->p_port(); + my $p_duplex = $cat->p_duplex(); + + my %i_duplex; + foreach my $port (keys %$p_duplex) { + my $iid = $p_port->{$port}; + $i_duplex{$iid} = $p_duplex->{$port}; + } + return \%i_duplex; +} + +sub i_duplex_admin { + my $cat = shift; + + my $p_port = $cat->p_port(); + my $p_duplex_admin = $cat->p_duplex_admin(); + + my %i_duplex_admin; + foreach my $port (keys %$p_duplex_admin) { + my $iid = $p_port->{$port}; + next unless defined $iid; + my $duplex = $p_duplex_admin->{$port}; + next unless defined $duplex; + + my $string = 'other'; + # see CISCO-STACK-MIB for a description of the bits + $string = 'half' if ($duplex =~ /001$/ or $duplex =~ /0100.$/); + $string = 'full' if ($duplex =~ /010$/ or $duplex =~ /100.0$/); + # we'll call it auto if both full and half are turned on, or if the + # specifically 'auto' flag bit is set. + $string = 'auto' + if ($duplex =~ /1..$/ or $duplex =~ /110..$/ or $duplex =~ /..011$/); + + $i_duplex_admin{$iid} = $string; + } + return \%i_duplex_admin; +} + +# $cat->interfaces() - Maps the ifIndex table to a physical port +sub interfaces { + my $self = shift; + my $interfaces = $self->i_index(); + my $portnames = $self->p_port(); + my %portmap = reverse %$portnames; + + my %interfaces = (); + foreach my $iid (keys %$interfaces) { + my $if = $interfaces->{$iid}; + $interfaces{$if} = $portmap{$iid}; + } + + return \%interfaces; +} + +sub vendor { + return 'cisco'; +} + +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer2::Catalyst - Perl5 Interface to Cisco devices running Catalyst OS + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +Catalyst device through SNMP. Information is stored in a number of +MIB's such as IF-MIB, CISCO-CDP-MIB, CISCO-STACK-MIB, CISCO-VTP-MIB, +and SWITCH-MIB. + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $cat = new SNMP::Info::Layer2::Catalyst(DestHost => 'router' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer2::Catalyst() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $cat = new SNMP::Info::Layer2::Catalyst( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $cat; + +=item $cat->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $cat->session(); + + # Set + my $newsession = new SNMP::Session(...); + $cat->session($newsession); + +=back + +=head1 GLOBAL Values + +=over + +=item $cat->netmask() +(B) + +=item $cat->broadcast() +(B) + +=item $cat->serial() +(B) + +=item $cat->model() +(B) + +=item $cat->ps1_type() +(B) + +=item $cat->ps2_type() +(B) + +=item $cat->ps1_status() +(B) + +=item $cat->ps2_status() +(B) + +=item $cat->slots() +(B) + +=item $cat->fan() +(B) + +=item $cat->vendor() + + Returns 'cisco' + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $cat->interfaces() + + Crosses p_port() with i_index() to get physical names. + +=item $cat->i_physical() + + Returns a map to IID for ports that are physical ports, not vlans, etc. + +=item $cat->i_type() + + Crosses p_port() with p_type() and returns the results. + + Overrides with ifType if p_type() isn't available. + +=item $cat->i_name() + + Crosses p_name with p_port and returns results. + +=item $cat->i_duplex() + + Crosses p_duplex with p_port and returns results. + +=item $cat->i_duplex_admin() + + Crosses p_duplex_admin with p_port. + + Munges bit_string returned from p_duplex_admin to get duplex settings. + +=back + +=head2 Module table + +This table holds configuration information for each of the blades installed in +the Catalyst device. + +=over + +=item $cat->m_type() +(B) + +=item $cat->m_model() +(B) + +=item $cat->m_serial() +(B) + +=item $cat->m_status() +(B) + +=item $cat->m_name() +(B) + +=item $cat->m_ports() +(B) + +=item $cat->m_ports_status() + Returns a list of space separated status strings for the ports. + To see the status of port 4 : + @ports_status = split(' ', $cat->m_ports_status() ); + $port4 = $ports_status[3]; + +(B) + +=item $cat->m_ports_hwver() +(B) + +=item $cat->m_ports_fwver() +(B) + +=item $cat->m_ports_swver() +(B) + +=item $cat->m_ports_ip() +(B) + +=item $cat->m_ports_sub1() +(B) + +=item $cat->m_ports_sub2() +(B) + +=back + +=head2 Modules - Router Blades + +=over + +=item $cat->m_ip() +(B) + +=item $cat->m_sub1() +(B) + +=item $cat->m_sub2() +(B) + +=back + +=head2 Port Entry Table (CISCO-STACK-MIB::portTable) + +=over + +=item $cat->p_name() +(B) + +=item $cat->p_type() +(B) + +=item $cat->p_status() +(B) + +=item $cat->p_status2() +(B) + +=item $cat->p_speed() +(B) + +=item $cat->p_duplex() +(B) + +=item $cat->p_port() +(B) + +=back + +=head2 Port Capability Table (CISCO-STACK-MIB::portCpbTable) + +=over + +=item $cat->p_speed_admin() +(B) + +=item $cat->p_duplex_admin() +(B) + +=back + +=head2 VLAN Entry Table + +See ftp://ftp.cisco.com/pub/mibs/supportlists/wsc5000/wsc5000-communityIndexing.html +for a good treaty of how to connect to the VLANs + + +=over + +=item $cat->v_state() +(B) + +=item $cat->v_type() +(B) + +=item $cat->v_name() +(B) + +=item $cat->v_mtu() +(B) + +=back + +=cut diff --git a/Info/Layer2/HP.pm b/Info/Layer2/HP.pm new file mode 100644 index 00000000..180e6794 --- /dev/null +++ b/Info/Layer2/HP.pm @@ -0,0 +1,547 @@ +# SNMP::Info::Layer2::HP - SNMP Interface to HP ProCurve Switches +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer2::HP; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info::Layer2; +use SNMP::Info::MAU; + +use vars qw/$VERSION $DEBUG %GLOBALS %MIBS %FUNCS %PORTSTAT + %MYGLOBALS %MYMIBS %MYFUNCS %MYMUNGE %MUNGE $INIT/ ; +@SNMP::Info::Layer2::HP::ISA = qw/SNMP::Info::Layer2 SNMP::Info::MAU Exporter/; +@SNMP::Info::Layer2::HP::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +# See SNMP::Info for the details of these data structures and +# the interworkings. +$INIT = 0; + +%MYMIBS = ( 'ENTITY-MIB' => 'entPhysicalSerialNum', + 'RFC1271-MIB' => 'logDescription', + 'HP-ICF-OID' => 'hpSwitch4000', + ); + +%MIBS = ( %SNMP::Info::Layer2::MIBS, + %SNMP::Info::MAU::MIBS, + %MYMIBS ); + +%MYGLOBALS = ('serial1' => 'entPhysicalSerialNum.1', +# 'model' => 'entPhysicalModelName.1', + ); +%GLOBALS = ( + %SNMP::Info::Layer2::GLOBALS, + %SNMP::Info::MAU::GLOBALS, + %MYGLOBALS + ); + +%MYFUNCS = ( + 'i_type2' => 'ifType', + 'e_map' => 'entAliasMappingIdentifier', + 'e_name' => 'entPhysicalName', + 'e_class' => 'entPhysicalClass', + 'e_parent' => 'entPhysicalContainedIn', + 'e_descr' => 'entPhysicalDescr', + 'e_type' => 'entPhysicalVendorType', + 'e_model' => 'entPhysicalModelName', + 'e_hwver' => 'entPhysicalHardwareRev', + 'e_swver' => 'entPhysicalSoftwareRev', + 'e_fwver' => 'entPhysicalFirmwareRev', + 'e_serial' => 'entPhysicalSerialNum', + # RFC1271 + 'l_descr' => 'logDescription' + + ); +%FUNCS = ( + %SNMP::Info::Layer2::FUNCS, + %SNMP::Info::MAU::FUNCS, + %MYFUNCS + ); + +%MYMUNGE = ( + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::Layer2::MUNGE, + %SNMP::Info::MAU::MUNGE, + %MYMUNGE + ); + + +# Method Overrides + +# Some have the serial num in entity mib, some dont. +sub serial { + my $hp = shift; + + # procurve 2xxx have this + my $serial = $hp->serial1(); + + # 4xxx dont + return undef if $serial =~ /nosuchobject/i; + + return $serial; +} + +sub interfaces { + my $hp = shift; + my $interfaces = $hp->i_index(); + my $i_descr = $hp->i_description(); + + my %if; + foreach my $iid (keys %$interfaces){ + my $descr = $i_descr->{$iid}; + next unless defined $descr; + #$if{$iid} = $iid; + $if{$iid} = $descr if (defined $descr and length $descr); + } + + return \%if + +} + +# e_port maps EntityTable entries to IfTable +sub e_port { + my $hp = shift; + my $e_map = $hp->e_map(); + + my %e_port; + + foreach my $e_id (keys %$e_map) { + my $id = $e_id; + $id =~ s/\.0$//; + + my $iid = $e_map->{$e_id}; + $iid =~ s/.*\.//; + + $e_port{$id} = $iid; + } + + return \%e_port; +} + +sub i_type { + my $hp = shift; + my $e_descr = $hp->e_descr(); + my $e_port = $hp->e_port(); + + # Grab default values to pass through + my $i_type = $hp->i_type2(); + + # Now Stuff in the entity-table values + foreach my $port (keys %$e_descr){ + my $iid = $e_port->{$port}; + next unless defined $iid; + my $type = $e_descr->{$port}; + $type =~ s/^HP ?//; + $i_type->{$iid} = $type; + } + + return $i_type; + +} + +sub i_name { + my $hp = shift; + my $i_alias = $hp->i_alias(); + my $e_name = $hp->e_name(); + my $e_port = $hp->e_port(); + + my %i_name; + + foreach my $port (keys %$e_name){ + my $iid = $e_port->{$port}; + next unless defined $iid; + my $alias = $i_alias->{$iid}; + next unless defined $iid; + $i_name{$iid} = $e_name->{$port}; + + # Check for alias + $i_name{$iid} = $alias if (defined $alias and length($alias)); + } + + return \%i_name; +} + +sub vendor { + return 'hp'; +} + +sub log { + my $hp=shift; + + my $log = $hp->l_descr(); + + my $logstring = undef; + + foreach my $val (values %$log){ + next if $val =~ /^Link\s+(Up|Down)/; + $logstring .= "$val\n"; + } + + return $logstring; +} + +sub slots { + my $hp=shift; + + my $e_name = $hp->e_name(); + + return undef unless defined $e_name; + + my $slots; + foreach my $slot (keys %$e_name) { + $slots++ if $e_name->{$slot} =~ /slot/i; + } + + return $slots; +} + +#sub fan { +# my $hp = shift; +# +# my %ents = reverse %{$hp->e_name()}; +# +# my $fan = $ents{'Fan'}; +# +#} + +sub i_duplex { + my $hp = shift; + + my $mau_index = $hp->mau_index(); + my $mau_link = $hp->mau_link(); + + my %i_duplex; + foreach my $mau_port (keys %$mau_link){ + my $iid = $mau_index->{$mau_port}; + next unless defined $iid; + + my $linkoid = $mau_link->{$mau_port}; + my $link = &SNMP::translateObj($linkoid); + next unless defined $link; + + my $duplex = undef; + + if ($link =~ /fd$/i) { + $duplex = 'full'; + } elsif ($link =~ /hd$/i){ + $duplex = 'half'; + } + + $i_duplex{$iid} = $duplex if defined $duplex; + } + return \%i_duplex; +} + + +sub i_duplex_admin { + my $hp = shift; + + my $interfaces = $hp->interfaces(); + my $mau_index = $hp->mau_index(); + my $mau_auto = $hp->mau_auto(); + my $mau_autostat = $hp->mau_autostat(); + my $mau_typeadmin = $hp->mau_type_admin(); + my $mau_autosent = $hp->mau_autosent(); + + my %mau_reverse = reverse %$mau_index; + + my %i_duplex_admin; + foreach my $iid (keys %$interfaces){ + my $mau_index = $mau_reverse{$iid}; + next unless defined $mau_index; + + my $autostat = $mau_autostat->{$mau_index}; + + # HP25xx has this value + if (defined $autostat and $autostat =~ /enabled/i){ + $i_duplex_admin{$iid} = 'auto'; + next; + } + + my $type = $mau_autosent->{$mau_index}; + + next unless defined $type; + + if ($type == 0) { + $i_duplex_admin{$iid} = 'none'; + next; + } + + my $full = $hp->_isfullduplex($type); + my $half = $hp->_ishalfduplex($type); + + if ($full and !$half){ + $i_duplex_admin{$iid} = 'full'; + } elsif ($half) { + $i_duplex_admin{$iid} = 'half'; + } + } + + return \%i_duplex_admin; +} + +#sub i_up_admin { +# my $hp = shift; +# +# my $mau_index = $hp->mau_index(); +# my $mau_status = $hp->mau_status(); +# +# my %i_up_admin; +# foreach my $mau_port (keys %$mau_status){ +# my $iid = $mau_index->{$mau_port}; +# next unless defined $iid; +# my $status = $mau_status->{$mau_port}; +# +# $i_up_admin{$iid} = ($status =~ /shutdown/i) ? +# 'down' : 'up'; +# } +# +# return \%i_up_admin; +# +#} + +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer2::HP - SNMP Interface to HP Procurve Switches + +=head1 DESCRIPTION + +Provides abstraction to the configuration information obtainable from a +HP device through SNMP. Information is stored in a number of +MIB's such as IF-MIB, ENTITY-MIB, RFC1271-MIB, HP-ICF-OID, MAU-MIB + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $hp = new SNMP::Info::Layer2::HP(DestHost => 'router' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer2::HP() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $hp = new SNMP::Info::Layer2::HP( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $hp; + +=item $hp->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $hp->session(); + + # Set + my $newsession = new SNMP::Session(...); + $hp->session($newsession); + +=item $hp->all(), $hp->load_all() + +Runs each of the HP List methods and returns a hash reference. + +$hp->all() will call $hp->load_all() once and then return cahced valued. +Use $hp->load_all() to reload from the device. + +=back + +=head1 HP Global Configuration Values + +=over + +=item $hp->name() +(B) + +=item $hp->ip() +(B) + +=item $hp->netmask() +(B) + +=item $hp->broadcast() +(B) + +=item $hp->location() +(B) + +=item $hp->contact() +(B) + +=item $hp->description() +(B) + +=item $hp->layers() +(B) + +=item $hp->serial() +(B) + +=item $hp->model() +(B) + +=item $hp->ps1_type() +(B) + +=item $hp->ps2_type() +(B) + +=item $hp->ps1_status() +(B) + +=item $hp->ps2_status() +(B) + +=item $hp->slots() +(B) + +=item $hp->fan() +(B) + +=back + +=head1 CATALYST TABLE ENTRIES + +=head2 Module table + +=over + +=item $hp->m_type(), $hp->load_m_type() +(B) + +=item $hp->m_model(), $hp->load_m_model() +(B) + +=item $hp->m_serial(), $hp->load_m_serial() +(B) + +=item $hp->m_status(), $hp->load_m_status() +(B) + +=item $hp->m_name(), $hp->load_m_name() +(B) + +=item $hp->m_ports(), $hp->load_m_ports() +(B) + +=item $hp->m_ports_status(), $hp->load_m_ports_status() + Returns a list of space separated status strings for the ports. + To see the status of port 4 : + @ports_status = split(' ', $hp->m_ports_status() ); + $port4 = $ports_status[3]; + +(B) + +=item $hp->m_ports_hwver(), $hp->load_m_ports_hwver() +(B) + +=item $hp->m_ports_fwver(), $hp->load_m_ports_fwver() +(B) + +=item $hp->m_ports_swver(), $hp->load_m_ports_swver() +(B) + +=item $hp->m_ports_ip(), $hp->load_m_ports_ip() +(B) + +=item $hp->m_ports_sub1(), $hp->load_m_ports_sub1() +(B) + +=item $hp->m_ports_sub2(), $hp->load_m_ports_sub2() +(B) + + +=back + +=head2 Port Entry Table + +=over + +=item $hp->p_name(), $hp->load_p_name() +(B) + +=item $hp->p_type(), $hp->load_p_type() +(B) + +=item $hp->p_status(), $hp->load_p_status() +(B) + +=item $hp->p_status2(), $hp->load_p_status2() +(B) + +=item $hp->p_speed(), $hp->load_p_speed() +(B) + +=item $hp->p_duplex(), $hp->load_p_duplex() +(B) + +=item $hp->p_port(), $hp->load_p_port() +(B) + +=back + +=head2 VLAN Entry Table + +ftp://ftp.cisco.com/pub/mibs/supportlists/wsc5000/wsc5000-communityIndexing.html + +=over + +=item $hp->v_state(), $hp->load_v_state() +(B) + +=item $hp->v_type(), $hp->load_v_type() +(B) + +=item $hp->v_name(), $hp->load_v_name() +(B) + +=item $hp->v_mtu(), $hp->load_v_mtu() +(B) + +=back diff --git a/Info/Layer3.pm b/Info/Layer3.pm new file mode 100644 index 00000000..d5a1e888 --- /dev/null +++ b/Info/Layer3.pm @@ -0,0 +1,377 @@ +# SNMP::Info::Layer3 - SNMP Interface to Layer3 devices +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer3; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; +use SNMP::Info::CDP; +use SNMP::Info::Bridge; +use SNMP::Info::EtherLike; + +use vars qw/$VERSION $DEBUG %GLOBALS %FUNCS $INIT %MIBS %MUNGE/; + +@SNMP::Info::Layer3::ISA = qw/SNMP::Info SNMP::Info::CDP SNMP::Info::Bridge SNMP::Info::EtherLike Exporter/; +@SNMP::Info::Layer3::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +$INIT = 0; + +%MIBS = ( %SNMP::Info::MIBS, + %SNMP::Info::CDP::MIBS, + %SNMP::Info::Bridge::MIBS, + %SNMP::Info::EtherLike::MIBS, + 'ENTITY-MIB' => 'entPhysicalName', + 'HP-ICF-OID' => 'hpSwitch4000', + 'CISCO-PRODUCTS-MIB' => 'sysName', + 'OSPF-MIB' => 'ospfRouterId', + ); + +%GLOBALS = ( + # Inherit the super class ones + %SNMP::Info::GLOBALS, + %SNMP::Info::CDP::GLOBALS, + %SNMP::Info::Bridge::GLOBALS, + %SNMP::Info::EtherLike::GLOBALS, + 'mac' => 'ifPhysAddress.1', + 'chassis' => 'entPhysicalDescr.1', + 'router_ip' => 'ospfRouterId.0', + ); + +%FUNCS = ( + %SNMP::Info::FUNCS, + %SNMP::Info::CDP::FUNCS, + %SNMP::Info::Bridge::FUNCS, + %SNMP::Info::EtherLike::FUNCS, + # IFMIB + 'i_name2' => 'ifName', + # Address Translation Table (ARP Cache) + 'at_index' => 'atIfIndex', + 'at_paddr' => 'atPhysAddress', + 'at_netaddr' => 'atNetAddress', + 'ospf_ip' => 'ospfHostIpAddress' + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::MUNGE, + %SNMP::Info::CDP::MUNGE, + %SNMP::Info::Bridge::MUNGE, + %SNMP::Info::EtherLike::MUNGE, + 'at_paddr' => \&SNMP::Info::munge_mac, + ); + + +# Method OverRides + +sub root_ip { + my $l3 = shift; + + my $router_ip = $l3->router_ip(); + my $ospf_ip = $l3->ospf_ip(); + + # return the first one found here (should be only) + if (defined $ospf_ip and scalar(keys %$ospf_ip)){ + foreach my $key (keys %$ospf_ip){ + my $ip = $ospf_ip->{$key}; + print " SNMP::Layer3::root_ip() using $ip\n" if $DEBUG; + return $ip; + } + } + + return $router_ip if defined $router_ip; + return undef; +} + +sub i_ignore { + my $l3 = shift; + + my $interfaces = $l3->interfaces(); + + my %i_ignore; + foreach my $if (keys %$interfaces) { + # lo -> cisco aironet 350 loopback + if ($interfaces->{$if} =~ /(tunnel|loopback|lo|null)/i){ + $i_ignore{$if}++; + } + } + return \%i_ignore; +} + +sub serial { + my $l3 = shift; + + my $chassis = $l3->chassis(); + + return $1 if (defined $chassis and $chassis =~ /serial#?:\s*([a-z0-9]+)/i); + +} + +# $l3->model() - the sysObjectID returns an IID to an entry in +# the CISCO-PRODUCT-MIB. Look it up and return it. +sub model { + my $l3 = shift; + my $id = $l3->id(); + my $model = &SNMP::translateObj($id); + + $model =~ s/^cisco//i; + return $model; +} + +sub i_name { + my $l3 = shift; + my $i_index = $l3->i_index(); + my $i_alias = $l3->i_alias(); + my $i_name2 = $l3->i_name2(); + + my %i_name; + foreach my $iid (keys %$i_name2){ + my $name = $i_name2->{$iid}; + my $alias = $i_alias->{$iid}; + $i_name{$iid} = (defined $alias and $alias !~ /^\s*$/) ? + $alias : + $name; + } + + return \%i_name; +} + +sub i_duplex { + my $l3 = shift; + + my $el_index = $l3->el_index(); + my $el_duplex = $l3->el_duplex(); + + my %i_index; + foreach my $el_port (keys %$el_duplex){ + my $iid = $el_index->{$el_port}; + next unless defined $iid; + my $duplex = $el_duplex->{$el_port}; + next unless defined $duplex; + + $i_index{$iid} = 'half' if $duplex =~ /half/i; + $i_index{$iid} = 'full' if $duplex =~ /full/i; + $i_index{$iid} = 'auto' if $duplex =~ /auto/i; + } + + return \%i_index; +} + +# $l3->interfaces() - Map the Interfaces to their physical names +sub interfaces { + my $l3 = shift; + my $interfaces = $l3->i_index(); + my $descriptions = $l3->i_description(); + + my %interfaces = (); + foreach my $iid (keys %$interfaces){ + my $desc = $descriptions->{$iid}; + next unless defined $desc; + + $interfaces{$iid} = $desc; + } + + return \%interfaces; +} + +sub vendor { + my $l3 = shift; + + my $descr = $l3->description(); + + return 'cisco' if ($descr =~ /(cisco|ios)/i); + return 'foundry' if ($descr =~ /foundry/i); + +} +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer3 - Perl5 Interface to network devices using Layer3 + +=head1 DESCRIPTION + +Provides generic methods for accessing SNMP data for Layer 3 network devices. +Includes support for Layer2+3 devices. See super classes for other inherited +methods. + +Inherits from: + + SNMP::Info + SNMP::Info::Bridge + SNMP::Info::CDP + SNMP::Info::EtherLike + +Required MIBs: + + ENTITY-MIB - For model identification + CISCO-PRODUCTS-MIB - For model identification + HP-ICF-OID - For model identification + MIBS listed in SNMP::Info::CDP, SNMP::Info::Bridge, and SNMP::Info::Etherlike + +Cisco MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz + +HP MIBs can be found at http://www.hp.com/rnd/software + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $l3 = new SNMP::Info::Layer3(DestHost => 'router' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer3() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $l3 = new SNMP::Info::Layer3( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $l3; + +=item $l3->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $l3->session(); + + # Set + my $newsession = new SNMP::Session(...); + $l3->session($newsession); + +=back + +=head1 GLOBALS + +=over + +=item $l3->mac() + +Returns root port mac address + +(B) + +=item $l3->chassis() + +Returns Chassis type (model). + +(B) + +=item $l3->serial() + +Trys to cull a serial number from $l3->chassis() + +=item $l3->model() + +Trys to reference $l3->id() to one of the product MIBs listed above + +Removes 'cisco' from cisco devices for readability. + +=item $l3->vendor() + +Trys to cull a Vendor name from B + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $l3->interfaces() + +Returns the map between SNMP Interface Identifier (iid) and physical port name. + +Only returns those iids that have a description listed in $l3->i_description() + +=item $l3->i_ignore() + +Returns reference to hash. Creates a key for each IID that should be ignored. + +Currently looks for tunnel,loopback,lo,null from $l3->interfaces() + +=item $l3->i_name() + +Returns reference to hash of iid to human set name. + +Defaults to B, but checks for an B + +=item $l3->i_duplex() + +Returns reference to hash of iid to current link duplex setting. + +Maps $l3->el_index() to $l3->el_duplex, then culls out +full,half, or auto and sets the map to that value. + +see SNMP::Info::Etherlike for the el_index() and el_duplex() methods. + +=back + +=head2 ARP Cache Entries + +=over + +=item $l3->at_index() + +Returns reference to map of IID to Arp Cache Entry + +(B) + +=item $l3->at_paddr() + +Returns reference to hash of Arp Cache Entries to MAC address + +(B) + +=item $l3->at_netaddr() + +Returns reference to hash of Arp Cache Entries to IP Address + +(B) + +=back + +=cut diff --git a/Info/Layer3/Aironet.pm b/Info/Layer3/Aironet.pm new file mode 100644 index 00000000..8d64c7f6 --- /dev/null +++ b/Info/Layer3/Aironet.pm @@ -0,0 +1,327 @@ +# SNMP::Info::Layer3::Aironet +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer3::Aironet; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info::Layer3; + +use vars qw/$VERSION $DEBUG %MIBS %FUNCS %GLOBALS %MUNGE $INIT/; +@SNMP::Info::Layer3::Aironet::ISA = qw/SNMP::Info::Layer3 Exporter/; +@SNMP::Info::Layer3::Aironet::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +$INIT = 0; +%MIBS = ( + %SNMP::Info::Layer3::MIBS, + 'AWCVX-MIB' => 'awcIfTable', + 'IEEE802dot11-MIB' => 'dot11StationID', + ); + +%GLOBALS = ( + %SNMP::Info::Layer3::GLOBALS, + 'mac' => 'dot11StationID.2', + # AWC Ethernet Table + 'awc_duplex' => 'awcEtherDuplex.0', + ); + +%FUNCS = ( + %SNMP::Info::Layer3::FUNCS, + 'i_mac2' => 'ifPhysAddress', + 'i_mtu2' => 'ifMtu', + 'i_ssid' => 'dot11DesiredSSID', + # Bridge-mib overrides + 'fw_mac2' => 'dot1dTpFdbAddress', + 'fw_port2' => 'dot1dTpFdbPort', + 'bp_index2' => 'dot1dBasePortIfIndex', + # AWC Interface Table (awcIfTable) + 'awc_default_mac' => 'awcIfDefaultPhyAddress', + 'awc_mac' => 'awcIfPhyAddress', + 'awc_ip' => 'awcIfIpAddress', + 'awc_netmask' => 'awcIfIpNetMask', + 'awc_msdu' => 'awcIfMSDUMaxLength', + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::Layer3::MUNGE, + 'i_mac2' => \&SNMP::Info::munge_mac, + 'awc_mac' => \&SNMP::Info::munge_mac, + 'fw_mac2' => \&SNMP::Info::munge_mac, + ); + +# Override wireless port with static info +sub bp_index { + my $aironet = shift; + my $interfaces = $aironet->interfaces(); + my $bp_index = $aironet->bp_index2(); + + foreach my $iid (keys %$interfaces){ + my $port = $interfaces->{$iid}; + + # Hardwire the wireless port to the transparent bridge port + if ($port =~ /awc/){ + $bp_index->{0}=$iid; + } + } + + return $bp_index; +} + +# Add the static table to the forwarding table +sub fw_mac { + my $aironet = shift; + my $fw_mac = $aironet->fw_mac2(); + my $fw_port = $aironet->fw_port2(); + my $bs_mac = $aironet->bs_mac(); + + # remove port 0 forwarding table entries, only port 0 static entries + foreach my $fw (keys %$fw_mac){ + my $port = $fw_port->{$fw}; + delete $fw_mac->{$fw} if $port == 0; + } + + foreach my $bs (keys %$bs_mac){ + $fw_mac->{$bs} = $bs_mac->{$bs}; + } + + return $fw_mac; +} + +# Add the static table to the forwarding table +sub fw_port { + my $aironet = shift; + my $fw_port = $aironet->fw_port2(); + my $bs_port = $aironet->bs_port(); + + + foreach my $bs (keys %$bs_port){ + $fw_port->{$bs} = $bs_port->{$bs}; + } + + return $fw_port; +} + + +sub i_duplex { + my $aironet = shift; + my $interfaces = $aironet->interfaces(); + my $awc_duplex = $aironet->awc_duplex(); + + my %i_duplex; + + foreach my $iid (keys %$interfaces){ + my $name = $interfaces->{$iid}; + + if ($name =~ /fec/){ + $i_duplex{$iid} = $awc_duplex; + } + } + + return \%i_duplex; +} + +sub i_mac { + my $aironet = shift; + + my $i_mac = $aironet->i_mac2(); + my $awc_mac = $aironet->awc_mac(); + + foreach my $iid (keys %$awc_mac){ + next unless defined $i_mac->{$iid}; + $i_mac->{$iid} = $awc_mac->{$iid}; + } + + return $i_mac; +} + +sub i_ignore { + my $aironet = shift; + my $interfaces = $aironet->interfaces(); + + my %i_ignore; + foreach my $if (keys %$interfaces){ + $i_ignore{$if}++ if ($interfaces->{$if} =~ /(rptr|lo)/); + } + + return \%i_ignore; +} + +sub vendor { + return 'cisco'; +} + +1; +__END__ + + +=head1 NAME + +SNMP::Info::Layer3::Aironet - Perl5 Interface to Cisco Aironet Wireless Devices + +=head1 DESCRIPTION + +Inherits all methods from SNMP::Info::Layer3 + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $aironet = new SNMP::Info::Layer3::Aironet(DestHost => 'myswitch', + Community => 'public'); + my $mac = $aironet->mac(); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer3::Aironet() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $aironet = new SNMP::Info::Layer3::Aironet( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $aironet; + +=item $aironet->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $aironet->session(); + + # Set + my $newsession = new SNMP::Session(...); + $aironet->session($newsession); + +=back + +=head1 Globals + +=over + +=item $aironet->mac() + +Gives the MAC Address of the wireless side + +B + +=item $aironet->awc_duplex() + +Gives the admin duplex setting for the Ethernet Port. + +B + +=item $aironet->vendor() + +Returns 'cisco'. + +=back + +=head1 TABLE ENTRIES + +=head2 Aironet specific items + +=over + +=item $aironet->awc_default_mac() + +Gives the default MAC address of each interface. + +B + +=item $aironet->awc_mac() + +Gives the actual MAC address of each interface. + +B + +=item $aironet->awc_ip() + +Gives the IP Address assigned to each interface. + +B + +=item $aironet->awc_netmask() + +Gives the NetMask for each interface. + +B + +=item $aironet->awc_msdu() + +B + +=back + +=head2 Overrides + +=over + +=item $aironet->bp_index() + +Takes the bp_index() value from SNMP::Info::Bridge and overrides the wireless port +to be assigned to the transparent bridge port (port 0) + +=item $aironet->fw_mac() + +Adds static table entries from bs_mac() to port 0 so that wireless MAC addresses will +be reported. Forwarding table entries for port 0 are removed. + +=item $aironet->fw_port() + +Adds the static table port mappings to the forwarding table port mappings by adding +bs_port() to fw_port() + +=item $aironet->i_duplex() + +Adds the value of awc_duplex() to each Ethernet port seen. + +=item $aironet->i_mac() + +Overrides the values for i_mac with the value from awc_mac() if they are set. + +=item $aironet->i_ignore() + +Ignores ports that are of type ``rptr'' and ``lo''. + +=back + +=cut diff --git a/Info/Layer3/Foundry.pm b/Info/Layer3/Foundry.pm new file mode 100644 index 00000000..fb8f7f41 --- /dev/null +++ b/Info/Layer3/Foundry.pm @@ -0,0 +1,428 @@ +# SNMP::Info::Layer3::Foundry - SNMP Interface to Foundry devices +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::Layer3::Foundry; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; +use SNMP::Info::Bridge; + +use vars qw/$VERSION $DEBUG %GLOBALS %FUNCS $INIT %MIBS %MUNGE/; + +@SNMP::Info::Layer3::Foundry::ISA = qw/SNMP::Info SNMP::Info::Bridge Exporter/; +@SNMP::Info::Layer3::Foundry::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +$INIT = 0; + +%MIBS = ( %SNMP::Info::MIBS, + %SNMP::Info::Bridge::MIBS, + 'FOUNDRY-SN-ROOT-MIB' => 'foundry', + # IP-FORWARD-MIB + # ETHERLIKE-MIB + # RFC1398-MIB + # RMON-MIB + # IF-MIB + ); + +%GLOBALS = ( + # Inherit the super class ones + %SNMP::Info::GLOBALS, + %SNMP::Info::Bridge::GLOBALS, + 'mac' => 'ifPhysAddress.1', + 'chassis' => 'entPhysicalDescr.1', + 'serial' => 'snChasSerNum', + 'temp' => 'snChasActualTemperature', + 'ps1_type' => 'snChasPwrSupplyDescription.1', + 'ps1_status' => 'snChasPwrSupplyOperStatus.1', + 'fan' => 'snChasFanOperStatus.1', + #'serial' => 'enterprises.1991.1.1.1.1.2.0', + #'temp' => 'enterprises.1991.1.1.1.1.18.0', + #'ps1_type' => 'enterprises.1991.1.1.1.2.1.1.2.1', + #'ps1_status' => 'enterprises.1991.1.1.1.2.1.1.3.1', + #'fan' => 'enterprises.1991.1.1.1.3.1.1.3.1' + ); + +%FUNCS = ( + %SNMP::Info::FUNCS, + %SNMP::Info::Bridge::FUNCS, + 'i_name2' => 'ifName', + # From RFC1213-MIB + 'at_index' => 'ipNetToMediaIfIndex', + 'at_paddr' => 'ipNetToMediaPhysAddress', + 'at_netaddr' => 'ipNetToMediaNetAddress', + # FOUNDRY-MIB + # snSwPortInfoTable - Switch Port Information Group + 'sw_index' => 'snSwPortIfIndex', + 'sw_duplex' => 'snSwPortInfoChnMode', + 'sw_type' => 'snSwPortInfoMediaType', + 'sw_speed' => 'snSwPortInfoSpeed', + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::MUNGE, + %SNMP::Info::Bridge::MUNGE, + 'at_paddr' => \&SNMP::Info::munge_mac, + ); + + +# Method OverRides + +# Add our i_aliases if they are set (manually) +sub i_name { + my $foundry = shift; + my $i_name = $foundry->i_name2(); + + my $i_alias = $foundry->i_alias(); + + foreach my $iid (keys %$i_name){ + my $alias = $i_alias->{$iid}; + next unless defined $alias; + next unless length($alias); + $i_name->{$iid} = $i_alias->{$iid}; + } + + return $i_name; +} + +sub i_ignore { + my $foundry = shift; + + my $interfaces = $foundry->interfaces(); + my $i_descr = $foundry->i_descr(); + + my %i_ignore; + foreach my $if (keys %$interfaces) { + # lo -> cisco aironet 350 loopback + if ($interfaces->{$if} =~ /(tunnel|loopback|lo|lb|null)/i){ + $i_ignore{$if}++; + } + } + return \%i_ignore; +} + +sub i_duplex { + my $foundry = shift; + my $sw_index = $foundry->sw_index(); + my $sw_duplex= $foundry->sw_duplex(); + + my %i_duplex; + foreach my $sw_port (keys %$sw_duplex){ + my $iid = $sw_index->{$sw_port}; + my $duplex = $sw_duplex->{$sw_port}; + next if $duplex =~ /none/i; + $i_duplex{$iid} = 'half' if $duplex =~ /half/i; + $i_duplex{$iid} = 'full' if $duplex =~ /full/i; + } + return \%i_duplex; +} + +sub i_type { + my $foundry = shift; + my $sw_index = $foundry->sw_index(); + my $sw_type= $foundry->sw_type(); + + my %i_type; + foreach my $sw_port (keys %$sw_type){ + my $iid = $sw_index->{$sw_port}; + my $type = $sw_type->{$sw_port}; + next unless defined $type; + $i_type{$iid} = $type; + } + return \%i_type; +} + +sub i_speed { + my $foundry = shift; + my $sw_index = $foundry->sw_index(); + my $sw_speed= $foundry->sw_speed(); + + my %i_speed; + foreach my $sw_port (keys %$sw_speed){ + my $iid = $sw_index->{$sw_port}; + my $speed = $sw_speed->{$sw_port}; + next unless defined $speed; + $speed = 'auto' if $speed =~ /auto/i; + $speed = '10 Mbps' if $speed =~ /s10m/i; + $speed = '100 Mbps' if $speed =~ /s100m/i; + $speed = '1.0 Gbps' if $speed =~ /s1g/i; + $speed = '45 Mbps' if $speed =~ /s45M/i; + $speed = '155 Mbps' if $speed =~ /s155M/i; + $i_speed{$iid} = $speed; + } + return \%i_speed; +} + +# $foundry->model() - looks for xxnnnn in the description +sub model { + my $foundry = shift; + my $id = $foundry->id(); + my $desc = $foundry->description(); + my $model = &SNMP::translateObj($id); + + $model = $1 if $desc =~ /\s+([a-z]{2}\d{4})\D/i; + + + return $model; +} + +# $foundry->interfaces() - Map the Interfaces to their physical names +sub interfaces { + my $foundry = shift; + my $interfaces = $foundry->i_index(); + + my $descriptions = $foundry->i_description(); + + my %ifs = (); + foreach my $iid (keys %$interfaces){ + $ifs{$iid} = $descriptions->{$iid}; + } + + return \%ifs; +} + +sub vendor { + return 'foundry'; +} +1; +__END__ + +=head1 NAME + +SNMP::Info::Layer3::Foundry - Perl5 Interface to Foundry Network Devices + +=head1 DESCRIPTION + +This module provides limited functionality from older Foundry devices. +Specifically designed for a FI4802 + +Data comes RFC1213 and FOUNDRY-SN-ROOT-MIB + +Inherits all methods from both SNMP::Info and SNMP::Info::Bridge + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $foundry = new SNMP::Info::Layer3::Foundry(DestHost => 'switch' , + Community => 'public' ); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::Layer3::Foundry() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $foundry = new SNMP::Info::Layer3::Foundry( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $foundry; + +=item $foundry->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $foundry->session(); + + # Set + my $newsession = new SNMP::Session(...); + $foundry->session($newsession); + +=back + +=head1 GLOBAL VALUES + +=over + +=item $foundry->model() + + Returns model type. Checks $foundry->id() against the + FOUNDRY-SN-ROOT-MIB and then parses out xxNNNN + +=item $foundry->vendor() + + Returns 'foundry' :) + +=item $foundry->mac() + + Returns MAC Address of root port. + + (B) + +=item $foundry->chassis() + + Returns Chassis type. + + (B) + +=item $foundry->serial() + + Returns serial number of device. + + (B) + +=item $foundry->temp() + + Returns the chassis temperature + + (B) + +=item $foundry->ps1_type() + + Returns the Description for the power supply + + (B) + +=item $foundry->ps1_status() + + Returns the status of the power supply. + + (B) + +=item $foundry->fan() + + Returns the status of the chassis fan. + + (B) + +=back + +=head1 TABLE ENTRIES + +=head2 Overrides + +=over + +=item $foundry->interfaces() + + Returns reference to hash of interface names to iids. + + Uses B. + +=item $foundry->i_name() + + Returns reference to hash of interface names. + Trys for B and Defaults to B + +=item $foundry->i_ignore() + + Returns reference to hash of interfaces to be ignored. + + Ignores interfaces with descriptions of tunnel,loopback,null + +=item $foundry->i_duplex() + + Returns reference to hash of interface link duplex status. + + Crosses $foundry->sw_duplex() with $foundry->sw_index() + +=item $foundry->i_type() + + Returns reference to hash of interface types. + + Crosses $foundry->sw_type() with $foundry->sw_index() + +=item $foundry->i_speed() + + Returns reference to hash of interface speeds . + + Crosses $foundry->sw_speeD() with $foundry->sw_index() and + does a little munging. + +=back + +=head2 RFC1213 Arp Cache Table (B) + +=over + +=item $foundry->at_index() + + Returns reference to hash. Maps ARP table entries to Interface IIDs + + (B) + +=item $foundry->at_paddr() + + Returns reference to hash. Maps ARP table entries to MAC addresses. + + (B) + +=item $foundry->at_netaddr() + + Returns reference to hash. Maps ARP table entries to IPs + + (B) + +=back + +=head2 Foundry Switch Port Information Table (B) + +=over + +=item $foundry->sw_index() + + Returns reference to hash. Maps Table to Interface IID. + + (B) + +=item $foundry->sw_duplex() + + Returns reference to hash. Current duplex status for switch ports. + + (B) + +=item $foundry->sw_type() + + Returns reference to hash. Current Port Type . + + (B) + +=item $foundry->sw_speed() + + Returns reference to hash. Current Port Speed. + + (B) + +=back + +=cut diff --git a/Info/MAU.pm b/Info/MAU.pm new file mode 100644 index 00000000..ddb9fbfd --- /dev/null +++ b/Info/MAU.pm @@ -0,0 +1,274 @@ +# SNMP::Info::MAU - Media Access Unit - RFC2668 +# Max Baker +# +# Copyright (c) 2002, Regents of the University of California +# All rights reserved. +# +# 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 +# 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 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 CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package SNMP::Info::MAU; +$VERSION = 0.1; + +use strict; + +use Exporter; +use SNMP::Info; + +use vars qw/$VERSION $DEBUG %MIBS %FUNCS %GLOBALS %MUNGE $INIT/; +@SNMP::Info::MAU::ISA = qw/SNMP::Info Exporter/; +@SNMP::Info::MAU::EXPORT_OK = qw//; + +$DEBUG=0; +$SNMP::debugging=$DEBUG; + +$INIT = 0; + +%MIBS = ('MAU-MIB' => 'mauMod'); + +%GLOBALS = ( + ); + +%FUNCS = ( + # Interface MAU Table + 'mau_index' => 'ifMauIfIndex', + 'mau_link' => 'ifMauType', + 'mau_status' => 'ifMauStatus', + 'mau_up' => 'ifMauMediaAvailable', + 'mau_type' => 'ifMauTypeList', + 'mau_type_admin' => 'ifMauDefaultType', + # Interface Auto-Negotiation Table + 'mau_auto' => 'ifMauAutoNegSupported', + 'mau_autostat' => 'ifMauAutoNegAdminStatus', + 'mau_autosent' => 'ifMauAutoNegCapAdvertised', + 'mau_autorec' => 'ifMauAutoNegCapReceived', + ); + +%MUNGE = ( + # Inherit all the built in munging + %SNMP::Info::MUNGE, + # Add ones for our class + 'mau_type' => \&munge_int2bin, + 'mau_autosent' => \&munge_int2bin, + 'mau_autorec' => \&munge_int2bin, + ); + + +sub munge_int2bin { + my $int = shift; + return undef unless defined $int; + return unpack("B32", pack("N", $int)); +} + +sub _isfullduplex{ + my $mau = shift; + my $mautype = shift; + + my @full_types = qw/11 13 16 18 20/; + foreach my $type ( @full_types ) { + return 1 if (substr($mautype,32-$type,1) eq '1') + } + return 0; +} + +sub _ishalfduplex{ + my $mau = shift; + my $mautype = shift; + + my @half_types = qw/10 12 15 17 19/; + foreach my $type ( @half_types ) { + return 1 if (substr($mautype,32-$type,1) eq '1') + } + return 0; +} + +1; +__END__ + + +=head1 NAME + +SNMP::Info::MAU - Perl5 Interface to SNMP Medium Access Unit (MAU) MIB (RFC2668) + +=head1 DESCRIPTION + +MAU-MIB is used by Layer 2 devices like HP Switches . The MAU table +contains link and duplex info for the port itself and the device +connected to that port. + +Inherits all methods from SNMP::Info + +=head1 AUTHOR + +Max Baker (C) + +=head1 SYNOPSIS + + my $mau = new SNMP::Info::MAU( DestHost => 'myswitch', + Community => 'public'); + +=head1 CREATING AN OBJECT + +=over + +=item new SNMP::Info::MAU() + +Arguments passed to new() are passed on to SNMP::Session::new() + + + my $mau = new SNMP::Info::MAU( + DestHost => $host, + Community => 'public', + Version => 3,... + ) + die "Couldn't connect.\n" unless defined $mau; + +=item $mau->session() + +Sets or returns the SNMP::Session object + + # Get + my $sess = $mau->session(); + + # Set + my $newsession = new SNMP::Session(...); + $mau->session($newsession); + +=item $mau->all(), $mau->load_all() + +Queries each of the methods listed in %FUNCS and returns a hash reference. + +$mau->all() will call $mau->load_all() once and then return cahced valued. +Use $mau->load_all() to reload from the device. + +=back + +=head1 MAU Global Configuration Values + +=over + +=item None + +=back + +=head1 MAU INTERFACE TABLE ENTRIES + +=over + +=item $mau->mau_index() - Returns a list of interfaces +and their index in the MAU IF Table. + +(B) + +=item $mau->mau_link() - Returns the type of Media Access used. + + This is essentially the type of link in use. + eg. dot3MauType100BaseTXFD - 100BaseT at Full Duplex + +(B) + +=item $mau->mau_status() - Returns the admin link condition as + + 1 - other + 2 - unknown + 3 - operational + 4 - standby + 5 - shutdown + 6 - reset + +Use 5 and !5 to see if the link is up or down on the admin side. + +(B) + +=item $mau->mau_up() - Returns the current link condition + + (B) + +=item $mau->mau_type() - Returns a 32bit string reporting the capabilities +of the port from a MAU POV. + + Directly from the MAU-MIB : + Bit Capability + 0 other or unknown + 1 AUI + 2 10BASE-5 + 3 FOIRL + 4 10BASE-2 + 5 10BASE-T duplex mode unknown + 6 10BASE-FP + 7 10BASE-FB + 8 10BASE-FL duplex mode unknown + 9 10BROAD36 + 10 10BASE-T half duplex mode + 11 10BASE-T full duplex mode + 12 10BASE-FL half duplex mode + 13 10BASE-FL full duplex mode + 14 100BASE-T4 + 15 100BASE-TX half duplex mode + 16 100BASE-TX full duplex mode + 17 100BASE-FX half duplex mode + 18 100BASE-FX full duplex mode + 19 100BASE-T2 half duplex mode + 20 100BASE-T2 full duplex mode + +(B) + +=item $mau->mau_auto() - Returns status of auto-negotiation mode for ports. + +(B) + +=item $mau->mau_autosent() - Returns a 32 bit bit-string representing the +capabilities we are broadcasting on that port + + Uses the same decoder as $mau->mau_type(). + +(B) + + +=item $mau->mau_autorec() - Returns a 32 bit bit-string representing the +capabilities of the device on the other end. + + Uses the same decoder as $mau->mau_type(). + +(B) + +=back + +=head1 Utility Functions + +=over + +=item munge_int2bin() - Unpacks an integer into a 32bit bit string. + +=item $mau->_isfullduplex(bitstring) + + Boolean. Checks to see if any of the full_duplex types from mau_type() are + high. Currently bits 11,13,16,18,20. + +=item $mau->_ishalfduplex(bitstring) + + Boolean. Checks to see if any of the half_duplex types from mau_type() are + high. Currently bits 10,12,15,17,19. + +=back +=cut