| 1 | # SNMP::Info::Layer2::C1900 | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Max Baker changes from version 0.8 and beyond. | ||
| 4 | # | ||
| 5 | # Copyright (c) 2002,2003 Regents of the University of California | ||
| 6 | # All rights reserved. | ||
| 7 | # | ||
| 8 | # Redistribution and use in source and binary forms, with or without | ||
| 9 | # modification, are permitted provided that the following conditions are met: | ||
| 10 | # | ||
| 11 | # * Redistributions of source code must retain the above copyright notice, | ||
| 12 | # this list of conditions and the following disclaimer. | ||
| 13 | # * Redistributions in binary form must reproduce the above copyright | ||
| 14 | # notice, this list of conditions and the following disclaimer in the | ||
| 15 | # documentation and/or other materials provided with the distribution. | ||
| 16 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 17 | # names of its contributors may be used to endorse or promote products | ||
| 18 | # derived from this software without specific prior written permission. | ||
| 19 | # | ||
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 24 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 30 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 31 | |||
| 32 | package SNMP::Info::Layer2::C1900; | ||
| 33 | |||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use Exporter; | ||
| 37 | use SNMP::Info::CDP; | ||
| 38 | use SNMP::Info::CiscoStats; | ||
| 39 | use SNMP::Info::CiscoConfig; | ||
| 40 | use SNMP::Info::CiscoStpExtensions; | ||
| 41 | use SNMP::Info::CiscoAgg; | ||
| 42 | use SNMP::Info::Layer2; | ||
| 43 | |||
| 44 | @SNMP::Info::Layer2::C1900::ISA = qw/SNMP::Info::CDP SNMP::Info::CiscoStats | ||
| 45 | SNMP::Info::CiscoConfig SNMP::Info::CiscoStpExtensions SNMP::Info::CiscoAgg SNMP::Info::Layer2 | ||
| 46 | Exporter/; | ||
| 47 | @SNMP::Info::Layer2::C1900::EXPORT_OK = qw//; | ||
| 48 | |||
| 49 | our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE); | ||
| 50 | |||
| 51 | $VERSION = '3.985003'; | ||
| 52 | |||
| 53 | %GLOBALS = ( | ||
| 54 | %SNMP::Info::Layer2::GLOBALS, | ||
| 55 | %SNMP::Info::CiscoAgg::GLOBALS, | ||
| 56 | %SNMP::Info::CiscoStpExtensions::GLOBALS, | ||
| 57 | %SNMP::Info::CiscoConfig::GLOBALS, | ||
| 58 | %SNMP::Info::CiscoStats::GLOBALS, | ||
| 59 | %SNMP::Info::CDP::GLOBALS, | ||
| 60 | 'c1900_flash_status' => 'upgradeFlashBankStatus', | ||
| 61 | ); | ||
| 62 | |||
| 63 | %FUNCS = ( | ||
| 64 | %SNMP::Info::Layer2::FUNCS, | ||
| 65 | %SNMP::Info::CiscoAgg::FUNCS, | ||
| 66 | %SNMP::Info::CiscoStpExtensions::FUNCS, | ||
| 67 | %SNMP::Info::CiscoConfig::FUNCS, | ||
| 68 | %SNMP::Info::CiscoStats::FUNCS, | ||
| 69 | %SNMP::Info::CDP::FUNCS, | ||
| 70 | |||
| 71 | # ESSWITCH-MIB | ||
| 72 | 'c1900_p_index' => 'swPortIndex', | ||
| 73 | 'c1900_p_ifindex' => 'swPortIfIndex', | ||
| 74 | 'c1900_p_duplex' => 'swPortDuplexStatus', | ||
| 75 | 'c1900_p_duplex_admin' => 'swPortFullDuplex', | ||
| 76 | 'c1900_p_name' => 'swPortName', | ||
| 77 | 'c1900_p_up_admin' => 'swPortAdminStatus', | ||
| 78 | 'c1900_p_type' => 'swPortMediaCapability', | ||
| 79 | 'c1900_p_media' => 'swPortConnectorType', | ||
| 80 | ); | ||
| 81 | |||
| 82 | %MIBS = ( | ||
| 83 | %SNMP::Info::Layer2::MIBS, | ||
| 84 | %SNMP::Info::CiscoAgg::MIBS, | ||
| 85 | %SNMP::Info::CiscoStpExtensions::MIBS, | ||
| 86 | %SNMP::Info::CiscoConfig::MIBS, | ||
| 87 | %SNMP::Info::CiscoStats::MIBS, | ||
| 88 | %SNMP::Info::CDP::MIBS, | ||
| 89 | |||
| 90 | # Also known as the ESSWITCH-MIB | ||
| 91 | 'STAND-ALONE-ETHERNET-SWITCH-MIB' => 'series2000' | ||
| 92 | ); | ||
| 93 | |||
| 94 | %MUNGE = ( | ||
| 95 | %SNMP::Info::Layer2::MUNGE, %SNMP::Info::CiscoAgg::MUNGE, | ||
| 96 | %SNMP::Info::CiscoStpExtensions::MUNGE, %SNMP::Info::CiscoConfig::MUNGE, | ||
| 97 | %SNMP::Info::CiscoStats::MUNGE, %SNMP::Info::CDP::MUNGE, | ||
| 98 | ); | ||
| 99 | |||
| 100 | sub bulkwalk_no { return 1; } | ||
| 101 | sub cisco_comm_indexing { return 1; } | ||
| 102 | |||
| 103 | sub vendor { | ||
| 104 | return 'cisco'; | ||
| 105 | } | ||
| 106 | |||
| 107 | sub os { | ||
| 108 | return 'catalyst'; | ||
| 109 | } | ||
| 110 | |||
| 111 | sub os_ver { | ||
| 112 | my $c1900 = shift; | ||
| 113 | |||
| 114 | # Check for superclass one | ||
| 115 | my $os_ver = $c1900->SUPER::os_ver(); | ||
| 116 | return $os_ver if defined $os_ver; | ||
| 117 | |||
| 118 | my $c1900_flash_status = $c1900->c1900_flash_status(); | ||
| 119 | return unless defined $c1900_flash_status; | ||
| 120 | |||
| 121 | if ( $c1900_flash_status =~ m/V(\d+\.\d+(\.\d+)?)/ ) { | ||
| 122 | return $1; | ||
| 123 | } | ||
| 124 | return; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub interfaces { | ||
| 128 | my $c1900 = shift; | ||
| 129 | my $partial = shift; | ||
| 130 | |||
| 131 | my $i_descr = $c1900->i_description($partial) || {}; | ||
| 132 | |||
| 133 | foreach my $iid ( keys %$i_descr ) { | ||
| 134 | $i_descr->{$iid} =~ s/\s*$//; | ||
| 135 | } | ||
| 136 | return $i_descr; | ||
| 137 | } | ||
| 138 | |||
| 139 | sub i_duplex { | ||
| 140 | my $c1900 = shift; | ||
| 141 | my $partial = shift; | ||
| 142 | |||
| 143 | my $c1900_p_duplex = $c1900->c1900_p_duplex($partial) || {}; | ||
| 144 | |||
| 145 | my %i_duplex; | ||
| 146 | foreach my $if ( keys %$c1900_p_duplex ) { | ||
| 147 | my $duplex = $c1900_p_duplex->{$if}; | ||
| 148 | next unless defined $duplex; | ||
| 149 | |||
| 150 | $duplex = 'half' if $duplex =~ /half/i; | ||
| 151 | $duplex = 'full' if $duplex =~ /full/i; | ||
| 152 | $i_duplex{$if} = $duplex; | ||
| 153 | } | ||
| 154 | return \%i_duplex; | ||
| 155 | } | ||
| 156 | |||
| 157 | sub i_duplex_admin { | ||
| 158 | my $c1900 = shift; | ||
| 159 | my $partial = shift; | ||
| 160 | |||
| 161 | my $c1900_p_admin = $c1900->c1900_p_duplex_admin($partial) || {}; | ||
| 162 | |||
| 163 | my %i_duplex_admin; | ||
| 164 | foreach my $if ( keys %$c1900_p_admin ) { | ||
| 165 | my $duplex = $c1900_p_admin->{$if}; | ||
| 166 | next unless defined $duplex; | ||
| 167 | |||
| 168 | $duplex = 'half' if $duplex =~ /disabled/i; | ||
| 169 | $duplex = 'full' if $duplex =~ /flow control/i; | ||
| 170 | $duplex = 'full' if $duplex =~ /enabled/i; | ||
| 171 | $duplex = 'auto' if $duplex =~ /auto/i; | ||
| 172 | $i_duplex_admin{$if} = $duplex; | ||
| 173 | } | ||
| 174 | return \%i_duplex_admin; | ||
| 175 | } | ||
| 176 | |||
| 177 | sub i_name { | ||
| 178 | my $c1900 = shift; | ||
| 179 | my $partial = shift; | ||
| 180 | |||
| 181 | my $i_name = $c1900->orig_i_name($partial) || {}; | ||
| 182 | my $c1900_p_name = $c1900->c1900_p_name($partial) || {}; | ||
| 183 | |||
| 184 | foreach my $port ( keys %$c1900_p_name ) { | ||
| 185 | my $name = $c1900_p_name->{$port}; | ||
| 186 | next unless defined $name; | ||
| 187 | next unless $name !~ /^\s*$/; | ||
| 188 | $i_name->{$port} = $name; | ||
| 189 | } | ||
| 190 | |||
| 191 | return $i_name; | ||
| 192 | } | ||
| 193 | |||
| 194 | sub set_i_duplex_admin { | ||
| 195 | my $c1900 = shift; | ||
| 196 | my ( $duplex, $port ) = @_; | ||
| 197 | |||
| 198 | # map a textual duplex to an integer one the switch understands | ||
| 199 | my %duplexes = qw/full 1 half 2 auto 3/; | ||
| 200 | |||
| 201 | my $iid = $c1900->c1900_p_ifindex($port); | ||
| 202 | |||
| 203 | return 0 unless $iid->{$port}; | ||
| 204 | |||
| 205 | $duplex = lc($duplex); | ||
| 206 | |||
| 207 | return 0 unless defined $duplexes{$duplex}; | ||
| 208 | |||
| 209 | return $c1900->set_c1900_p_duplex_admin( $duplexes{$duplex}, $iid ); | ||
| 210 | } | ||
| 211 | |||
| 212 | sub i_vlan { | ||
| 213 | my $c1900 = shift; | ||
| 214 | my $partial = shift; | ||
| 215 | |||
| 216 | # Overlap allows more than one VLAN per port. Unable to determine default | ||
| 217 | my $overlap | ||
| 218 | = $c1900->bridgeGroupAllowMembershipOverlap() | ||
| 219 | || $c1900->vlanAllowMembershipOverlap() | ||
| 220 | || 'disabled'; | ||
| 221 | |||
| 222 | if ( $overlap eq 'enabled' ) { | ||
| 223 | return {}; | ||
| 224 | } | ||
| 225 | |||
| 226 | my $member_of = $c1900->bridgeGroupMemberPortOfBridgeGroup() | ||
| 227 | || $c1900->vlanMemberPortOfVlan() || {}; | ||
| 228 | |||
| 229 | my $i_pvid = {}; | ||
| 230 | foreach my $idx ( keys %$member_of ) { | ||
| 231 | my @values = split( /\./, $idx ); | ||
| 232 | my ( $vlan, $port ) = @values; | ||
| 233 | next unless $vlan; | ||
| 234 | next unless $port; | ||
| 235 | next if ( defined $partial and $port !~ /^$partial$/ ); | ||
| 236 | my $value = $member_of->{$idx}; | ||
| 237 | next if ( $value eq 'false' ); | ||
| 238 | |||
| 239 | $i_pvid->{$port} = $vlan; | ||
| 240 | } | ||
| 241 | return $i_pvid; | ||
| 242 | } | ||
| 243 | |||
| 244 | sub i_vlan_membership { | ||
| 245 | my $c1900 = shift; | ||
| 246 | my $partial = shift; | ||
| 247 | |||
| 248 | my $member_of = $c1900->bridgeGroupMemberPortOfBridgeGroup() | ||
| 249 | || $c1900->vlanMemberPortOfVlan() || {}; | ||
| 250 | |||
| 251 | my $i_vlan_membership = {}; | ||
| 252 | foreach my $idx ( keys %$member_of ) { | ||
| 253 | my @values = split( /\./, $idx ); | ||
| 254 | my ( $vlan, $port ) = @values; | ||
| 255 | next unless $vlan; | ||
| 256 | next unless $port; | ||
| 257 | next if ( defined $partial and $port !~ /^$partial$/ ); | ||
| 258 | my $value = $member_of->{$idx}; | ||
| 259 | next if ( $value eq 'false' ); | ||
| 260 | |||
| 261 | push( @{ $i_vlan_membership->{$port} }, $vlan ); | ||
| 262 | } | ||
| 263 | return $i_vlan_membership; | ||
| 264 | } | ||
| 265 | |||
| 266 | sub i_vlan_membership_untagged { return {}; } | ||
| 267 | |||
| 268 | sub bp_index { | ||
| 269 | my $c1900 = shift; | ||
| 270 | my $partial = shift; | ||
| 271 | |||
| 272 | my $if_index = $c1900->i_index($partial); | ||
| 273 | my $index = $c1900->orig_bp_index($partial) || {}; | ||
| 274 | foreach my $iid ( keys %$if_index ) { | ||
| 275 | $index->{$iid} = $iid if ( !defined $index->{$iid} ); | ||
| 276 | } | ||
| 277 | return $index; | ||
| 278 | } | ||
| 279 | |||
| 280 | 1; | ||
| 281 | __END__ |