| 1 | # SNMP::Info::Layer2::Catalyst | ||
| 2 | # | ||
| 3 | # Copyright (c) 2002,2003 Regents of the University of California | ||
| 4 | # Copyright (c) 2008 Max Baker changes from version 0.8 and beyond | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # Redistribution and use in source and binary forms, with or without | ||
| 8 | # modification, are permitted provided that the following conditions are met: | ||
| 9 | # | ||
| 10 | # * Redistributions of source code must retain the above copyright notice, | ||
| 11 | # this list of conditions and the following disclaimer. | ||
| 12 | # * Redistributions in binary form must reproduce the above copyright | ||
| 13 | # notice, this list of conditions and the following disclaimer in the | ||
| 14 | # documentation and/or other materials provided with the distribution. | ||
| 15 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 16 | # names of its contributors may be used to endorse or promote products | ||
| 17 | # derived from this software without specific prior written permission. | ||
| 18 | # | ||
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 22 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 23 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | |||
| 31 | package SNMP::Info::Layer2::Catalyst; | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | use Exporter; | ||
| 36 | use SNMP::Info::CiscoStack; | ||
| 37 | use SNMP::Info::Layer2::Cisco; | ||
| 38 | |||
| 39 | @SNMP::Info::Layer2::Catalyst::ISA | ||
| 40 | = qw/SNMP::Info::CiscoStack SNMP::Info::Layer2::Cisco Exporter/; | ||
| 41 | @SNMP::Info::Layer2::Catalyst::EXPORT_OK = qw//; | ||
| 42 | |||
| 43 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 44 | |||
| 45 | $VERSION = '3.985003'; | ||
| 46 | |||
| 47 | %MIBS = ( | ||
| 48 | %SNMP::Info::Layer2::Cisco::MIBS, | ||
| 49 | %SNMP::Info::CiscoStack::MIBS, | ||
| 50 | ); | ||
| 51 | |||
| 52 | %GLOBALS = ( | ||
| 53 | %SNMP::Info::Layer2::Cisco::GLOBALS, | ||
| 54 | %SNMP::Info::CiscoStack::GLOBALS, | ||
| 55 | ); | ||
| 56 | |||
| 57 | %FUNCS = ( | ||
| 58 | %SNMP::Info::Layer2::Cisco::FUNCS, | ||
| 59 | %SNMP::Info::CiscoStack::FUNCS, | ||
| 60 | ); | ||
| 61 | |||
| 62 | %MUNGE = ( | ||
| 63 | %SNMP::Info::Layer2::Cisco::MUNGE, | ||
| 64 | %SNMP::Info::CiscoStack::MUNGE, | ||
| 65 | ); | ||
| 66 | |||
| 67 | # Overridden Methods | ||
| 68 | |||
| 69 | # i_physical sets a hash entry as true if the iid is a physical port | ||
| 70 | sub i_physical { | ||
| 71 | my $cat = shift; | ||
| 72 | |||
| 73 | my $p_port = $cat->p_port() || {}; | ||
| 74 | |||
| 75 | my %i_physical; | ||
| 76 | foreach my $port ( keys %$p_port ) { | ||
| 77 | my $iid = $p_port->{$port}; | ||
| 78 | $i_physical{$iid} = 1; | ||
| 79 | } | ||
| 80 | return \%i_physical; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub vendor { | ||
| 84 | return 'cisco'; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub os { | ||
| 88 | return 'catalyst'; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub os_ver { | ||
| 92 | my $cat = shift; | ||
| 93 | my $os_ver = $cat->SUPER::os_ver(); | ||
| 94 | return $os_ver if defined $os_ver; | ||
| 95 | |||
| 96 | my $m_swver = $cat->m_swver(); | ||
| 97 | return unless defined $m_swver; | ||
| 98 | |||
| 99 | # assume .1 entry is the chassis and the sw version we want. | ||
| 100 | return $m_swver->{1} if defined $m_swver->{1}; | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | |||
| 104 | # Workaround for incomplete bp_index | ||
| 105 | sub bp_index { | ||
| 106 | my $cat = shift; | ||
| 107 | my $p_index = $cat->p_port() || {}; | ||
| 108 | my $b_index = $cat->p_oidx() || {}; | ||
| 109 | |||
| 110 | my %bp_index; | ||
| 111 | foreach my $iid ( keys %$p_index ) { | ||
| 112 | my $ifidx = $p_index->{$iid}; | ||
| 113 | next unless defined $ifidx; | ||
| 114 | my $bpidx = $b_index->{$iid} || 0; | ||
| 115 | |||
| 116 | $bp_index{$bpidx} = $ifidx; | ||
| 117 | } | ||
| 118 | return \%bp_index; | ||
| 119 | } | ||
| 120 | |||
| 121 | sub cisco_comm_indexing { | ||
| 122 | return 1; | ||
| 123 | } | ||
| 124 | |||
| 125 | sub interfaces { | ||
| 126 | my $cat = shift; | ||
| 127 | my $partial = shift; | ||
| 128 | |||
| 129 | my $i_index = $cat->i_index($partial); | ||
| 130 | my $portnames = $cat->p_port() || {}; | ||
| 131 | my %portmap = reverse %$portnames; | ||
| 132 | |||
| 133 | my %interfaces = (); | ||
| 134 | foreach my $iid ( keys %$i_index ) { | ||
| 135 | next unless defined $iid; | ||
| 136 | my $if = $i_index->{$iid}; | ||
| 137 | $if =~ s/\./\// if $if; | ||
| 138 | my $port = $portmap{$iid}; | ||
| 139 | $port =~ s/\./\// if $port; | ||
| 140 | $interfaces{$iid} = $port || $if; | ||
| 141 | } | ||
| 142 | return \%interfaces; | ||
| 143 | } | ||
| 144 | |||
| 145 | sub i_name { | ||
| 146 | my $cat = shift; | ||
| 147 | my $partial = shift; | ||
| 148 | |||
| 149 | my $p_port = $cat->p_port() || {}; | ||
| 150 | my $p_name = $cat->p_name() || {}; | ||
| 151 | |||
| 152 | my %i_name; | ||
| 153 | foreach my $port ( keys %$p_name ) { | ||
| 154 | my $iid = $p_port->{$port}; | ||
| 155 | next unless defined $iid; | ||
| 156 | next if ( defined $partial and $iid !~ /^$partial$/ ); | ||
| 157 | $i_name{$iid} = $p_name->{$port}; | ||
| 158 | } | ||
| 159 | return \%i_name; | ||
| 160 | } | ||
| 161 | |||
| 162 | 1; | ||
| 163 | __END__ |