| 1 | # SNMP::Info::Layer3::C3550 | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008-2009 Max Baker changes from version 0.8 and beyond. | ||
| 4 | # Copyright (c) 2004 Regents of the University of California | ||
| 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::Layer3::C3550; | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | use Exporter; | ||
| 36 | use SNMP::Info::CiscoStack; | ||
| 37 | use SNMP::Info::Layer3::CiscoSwitch; | ||
| 38 | |||
| 39 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 40 | |||
| 41 | # NOTE : Top-most items gets precedence for @ISA | ||
| 42 | @SNMP::Info::Layer3::C3550::ISA = qw/ | ||
| 43 | SNMP::Info::CiscoStack | ||
| 44 | SNMP::Info::Layer3::CiscoSwitch | ||
| 45 | Exporter/; | ||
| 46 | |||
| 47 | @SNMP::Info::Layer3::C3550::EXPORT_OK = qw//; | ||
| 48 | |||
| 49 | $VERSION = '3.985003'; | ||
| 50 | |||
| 51 | # NOTE: Order creates precedence | ||
| 52 | # Example: v_name exists in Bridge.pm and CiscoVTP.pm | ||
| 53 | # Bridge is called from Layer3 and CiscoStpExtensions | ||
| 54 | # So we want CiscoVTP to come last to get the right one. | ||
| 55 | # The @ISA order should match these orders. | ||
| 56 | |||
| 57 | %MIBS | ||
| 58 | = ( %SNMP::Info::Layer3::CiscoSwitch::MIBS, %SNMP::Info::CiscoStack::MIBS, | ||
| 59 | ); | ||
| 60 | |||
| 61 | %GLOBALS = ( | ||
| 62 | %SNMP::Info::Layer3::CiscoSwitch::GLOBALS, | ||
| 63 | %SNMP::Info::CiscoStack::GLOBALS, | ||
| 64 | ); | ||
| 65 | |||
| 66 | %FUNCS = ( | ||
| 67 | %SNMP::Info::Layer3::CiscoSwitch::FUNCS, | ||
| 68 | %SNMP::Info::CiscoStack::FUNCS, | ||
| 69 | ); | ||
| 70 | |||
| 71 | %MUNGE = ( | ||
| 72 | %SNMP::Info::Layer3::CiscoSwitch::MUNGE, | ||
| 73 | %SNMP::Info::CiscoStack::MUNGE, | ||
| 74 | ); | ||
| 75 | |||
| 76 | sub vendor { | ||
| 77 | return 'cisco'; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub model { | ||
| 81 | my $c3550 = shift; | ||
| 82 | my $id = $c3550->id(); | ||
| 83 | my $model = &SNMP::translateObj($id) || $id; | ||
| 84 | $model =~ s/^catalyst//; | ||
| 85 | |||
| 86 | # turn 355048 into 3550-48 | ||
| 87 | if ( $model =~ /^(35\d\d)(\d\d(T|G)?)$/ ) { | ||
| 88 | $model = "$1-$2"; | ||
| 89 | } | ||
| 90 | return $model; | ||
| 91 | } | ||
| 92 | |||
| 93 | # Ports is encoded into the model number | ||
| 94 | sub ports { | ||
| 95 | my $c3550 = shift; | ||
| 96 | |||
| 97 | my $id = $c3550->id(); | ||
| 98 | my $model = SNMP::translateObj($id); | ||
| 99 | if ( defined $model && $model =~ /(12|24|48)(C|T|TS|G|TS-E|TS-S|T-E)?$/ ) { | ||
| 100 | return $1; | ||
| 101 | } | ||
| 102 | |||
| 103 | my $ports = $c3550->orig_ports(); | ||
| 104 | return $ports; | ||
| 105 | } | ||
| 106 | |||
| 107 | # Versions prior to 12.1(22)EA1a use the older CiscoStack method | ||
| 108 | # Newer versions use the ETHERLIKE-MIB to report operational duplex. | ||
| 109 | # See http://www.ciscosystems.com/en/US/products/hw/switches/ps646/prod_release_note09186a00802a08ee.html | ||
| 110 | |||
| 111 | sub i_duplex { | ||
| 112 | my $c3550 = shift; | ||
| 113 | my $partial = shift; | ||
| 114 | |||
| 115 | my $el_duplex = $c3550->el_duplex($partial); | ||
| 116 | |||
| 117 | # Newer software | ||
| 118 | if ( defined $el_duplex and scalar( keys %$el_duplex ) ) { | ||
| 119 | my %i_duplex; | ||
| 120 | foreach my $el_port ( keys %$el_duplex ) { | ||
| 121 | my $duplex = $el_duplex->{$el_port}; | ||
| 122 | next unless defined $duplex; | ||
| 123 | |||
| 124 | $i_duplex{$el_port} = 'half' if $duplex =~ /half/i; | ||
| 125 | $i_duplex{$el_port} = 'full' if $duplex =~ /full/i; | ||
| 126 | } | ||
| 127 | return \%i_duplex; | ||
| 128 | } | ||
| 129 | |||
| 130 | # Fall back to CiscoStack method | ||
| 131 | else { | ||
| 132 | return $c3550->SUPER::i_duplex($partial); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | # Software >= 12.1(22)EA1a uses portDuplex as admin setting | ||
| 137 | |||
| 138 | sub i_duplex_admin { | ||
| 139 | my $c3550 = shift; | ||
| 140 | my $partial = shift; | ||
| 141 | |||
| 142 | my $el_duplex = $c3550->el_duplex($partial); | ||
| 143 | |||
| 144 | # Newer software | ||
| 145 | if ( defined $el_duplex and scalar( keys %$el_duplex ) ) { | ||
| 146 | my $p_port = $c3550->p_port() || {}; | ||
| 147 | my $p_duplex = $c3550->p_duplex() || {}; | ||
| 148 | |||
| 149 | my $i_duplex_admin = {}; | ||
| 150 | foreach my $port ( keys %$p_duplex ) { | ||
| 151 | my $iid = $p_port->{$port}; | ||
| 152 | next unless defined $iid; | ||
| 153 | next if ( defined $partial and $iid !~ /^$partial$/ ); | ||
| 154 | |||
| 155 | $i_duplex_admin->{$iid} = $p_duplex->{$port}; | ||
| 156 | } | ||
| 157 | return $i_duplex_admin; | ||
| 158 | } | ||
| 159 | |||
| 160 | # Fall back to CiscoStack method | ||
| 161 | else { | ||
| 162 | return $c3550->SUPER::i_duplex_admin($partial); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | sub set_i_duplex_admin { | ||
| 167 | |||
| 168 | # map a textual duplex to an integer one the switch understands | ||
| 169 | my %duplexes = qw/half 1 full 2 auto 4/; | ||
| 170 | |||
| 171 | my $c3550 = shift; | ||
| 172 | my ( $duplex, $iid ) = @_; | ||
| 173 | |||
| 174 | my $el_duplex = $c3550->el_duplex($iid); | ||
| 175 | |||
| 176 | # Auto duplex only supported on newer software | ||
| 177 | if ( defined $el_duplex and scalar( keys %$el_duplex ) ) { | ||
| 178 | my $p_port = $c3550->p_port() || {}; | ||
| 179 | my %reverse_p_port = reverse %$p_port; | ||
| 180 | |||
| 181 | $duplex = lc($duplex); | ||
| 182 | |||
| 183 | return 0 unless defined $duplexes{$duplex}; | ||
| 184 | |||
| 185 | $iid = $reverse_p_port{$iid}; | ||
| 186 | |||
| 187 | return $c3550->set_p_duplex( $duplexes{$duplex}, $iid ); | ||
| 188 | } | ||
| 189 | else { | ||
| 190 | return $c3550->SUPER::set_i_duplex_admin; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | 1; | ||
| 195 | __END__ |