| 1 | # SNMP::Info::Layer3::HP9300 - SNMP Interface to HP Foundry OEM devices | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Eric Miller | ||
| 4 | # All rights reserved. | ||
| 5 | # | ||
| 6 | # Redistribution and use in source and binary forms, with or without | ||
| 7 | # modification, are permitted provided that the following conditions are met: | ||
| 8 | # | ||
| 9 | # * Redistributions of source code must retain the above copyright notice, | ||
| 10 | # this list of conditions and the following disclaimer. | ||
| 11 | # * Redistributions in binary form must reproduce the above copyright | ||
| 12 | # notice, this list of conditions and the following disclaimer in the | ||
| 13 | # documentation and/or other materials provided with the distribution. | ||
| 14 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 15 | # names of its contributors may be used to endorse or promote products | ||
| 16 | # derived from this software without specific prior written permission. | ||
| 17 | # | ||
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 22 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 28 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | package SNMP::Info::Layer3::HP9300; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::Layer3; | ||
| 36 | use SNMP::Info::FDP; | ||
| 37 | |||
| 38 | @SNMP::Info::Layer3::HP9300::ISA = qw/SNMP::Info::FDP | ||
| 39 | SNMP::Info::Layer3 Exporter/; | ||
| 40 | @SNMP::Info::Layer3::HP9300::EXPORT_OK = qw//; | ||
| 41 | |||
| 42 | our ($VERSION, %GLOBALS, %FUNCS, %MIBS, %MUNGE); | ||
| 43 | |||
| 44 | $VERSION = '3.985003'; | ||
| 45 | |||
| 46 | %MIBS = ( | ||
| 47 | %SNMP::Info::Layer3::MIBS, | ||
| 48 | %SNMP::Info::FDP::MIBS, | ||
| 49 | 'HP-SN-ROOT-MIB' => 'hp', | ||
| 50 | 'HP-SN-AGENT-MIB' => 'snChasPwrSupplyDescription', | ||
| 51 | 'HP-SN-SWITCH-GROUP-MIB' => 'snSwGroupOperMode', | ||
| 52 | ); | ||
| 53 | |||
| 54 | %GLOBALS = ( | ||
| 55 | %SNMP::Info::Layer3::GLOBALS, | ||
| 56 | %SNMP::Info::FDP::GLOBALS, | ||
| 57 | 'mac' => 'ifPhysAddress.1', | ||
| 58 | 'chassis' => 'entPhysicalDescr.1', | ||
| 59 | 'temp' => 'snChasActualTemperature', | ||
| 60 | 'ps1_type' => 'snChasPwrSupplyDescription.1', | ||
| 61 | 'ps1_status' => 'snChasPwrSupplyOperStatus.1', | ||
| 62 | 'fan' => 'snChasFanOperStatus.1', | ||
| 63 | |||
| 64 | ); | ||
| 65 | |||
| 66 | %FUNCS = ( | ||
| 67 | %SNMP::Info::Layer3::FUNCS, | ||
| 68 | %SNMP::Info::FDP::FUNCS, | ||
| 69 | |||
| 70 | # HP-SN-SWITCH-GROUP-MIB | ||
| 71 | # snSwPortInfoTable - Switch Port Information Group | ||
| 72 | # Fully qualify these since FDP class will load | ||
| 73 | # FOUNDRY-SN-SWITCH-GROUP-MIB which contains the same leaf names | ||
| 74 | 'sw_index' => 'HP_SN_SWITCH_GROUP_MIB__snSwPortIfIndex', | ||
| 75 | 'sw_duplex' => 'HP_SN_SWITCH_GROUP_MIB__snSwPortInfoChnMode', | ||
| 76 | 'sw_type' => 'HP_SN_SWITCH_GROUP_MIB__snSwPortInfoMediaType', | ||
| 77 | 'sw_speed' => 'HP_SN_SWITCH_GROUP_MIB__snSwPortInfoSpeed', | ||
| 78 | ); | ||
| 79 | |||
| 80 | %MUNGE = ( | ||
| 81 | %SNMP::Info::Layer3::MUNGE, | ||
| 82 | %SNMP::Info::FDP::MUNGE, | ||
| 83 | ); | ||
| 84 | |||
| 85 | sub i_ignore { | ||
| 86 | my $hp9300 = shift; | ||
| 87 | my $partial = shift; | ||
| 88 | |||
| 89 | my $interfaces = $hp9300->interfaces($partial) || {}; | ||
| 90 | |||
| 91 | my %i_ignore; | ||
| 92 | foreach my $if ( keys %$interfaces ) { | ||
| 93 | if ( $interfaces->{$if} =~ /(tunnel|loopback|\blo\b|lb|null)/i ) { | ||
| 94 | $i_ignore{$if}++; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | return \%i_ignore; | ||
| 98 | } | ||
| 99 | |||
| 100 | sub i_duplex { | ||
| 101 | my $hp9300 = shift; | ||
| 102 | my $partial = shift; | ||
| 103 | |||
| 104 | my $sw_index = $hp9300->sw_index($partial); | ||
| 105 | my $sw_duplex = $hp9300->sw_duplex($partial); | ||
| 106 | |||
| 107 | unless ( defined $sw_index and defined $sw_duplex ) { | ||
| 108 | return $hp9300->SUPER::i_duplex(); | ||
| 109 | } | ||
| 110 | |||
| 111 | my %i_duplex; | ||
| 112 | foreach my $sw_port ( keys %$sw_duplex ) { | ||
| 113 | my $iid = $sw_index->{$sw_port}; | ||
| 114 | my $duplex = $sw_duplex->{$sw_port}; | ||
| 115 | next if $duplex =~ /none/i; | ||
| 116 | $i_duplex{$iid} = 'half' if $duplex =~ /half/i; | ||
| 117 | $i_duplex{$iid} = 'full' if $duplex =~ /full/i; | ||
| 118 | } | ||
| 119 | return \%i_duplex; | ||
| 120 | } | ||
| 121 | |||
| 122 | sub model { | ||
| 123 | my $hp9300 = shift; | ||
| 124 | my $id = $hp9300->id(); | ||
| 125 | my $model = &SNMP::translateObj($id); | ||
| 126 | |||
| 127 | return $id unless defined $model; | ||
| 128 | |||
| 129 | $model =~ s/^hpSwitch//; | ||
| 130 | |||
| 131 | return $model; | ||
| 132 | } | ||
| 133 | |||
| 134 | sub os { | ||
| 135 | return 'hp'; | ||
| 136 | } | ||
| 137 | |||
| 138 | sub vendor { | ||
| 139 | return 'hp'; | ||
| 140 | } | ||
| 141 | |||
| 142 | sub os_ver { | ||
| 143 | my $hp9300 = shift; | ||
| 144 | |||
| 145 | return $hp9300->snAgImgVer() if ( defined $hp9300->snAgImgVer() ); | ||
| 146 | |||
| 147 | # Some older ones don't have this value,so we cull it from the description | ||
| 148 | my $descr = $hp9300->description(); | ||
| 149 | if ( $descr =~ m/Version (\d\S*)/ ) { | ||
| 150 | return $1; | ||
| 151 | } | ||
| 152 | |||
| 153 | # Last resort | ||
| 154 | return $hp9300->SUPER::os_ver(); | ||
| 155 | |||
| 156 | } | ||
| 157 | |||
| 158 | sub serial { | ||
| 159 | my $hp9300 = shift; | ||
| 160 | |||
| 161 | # Return chassis serial number if available | ||
| 162 | return $hp9300->snChasSerNum() if ( $hp9300->snChasSerNum() ); | ||
| 163 | |||
| 164 | # If no chassis serial use first module serial | ||
| 165 | my $mod_serials = $hp9300->snAgentConfigModuleSerialNumber(); | ||
| 166 | |||
| 167 | foreach my $mod ( sort keys %$mod_serials ) { | ||
| 168 | my $serial = $mod_serials->{$mod} || ''; | ||
| 169 | next unless defined $serial; | ||
| 170 | return $serial; | ||
| 171 | } | ||
| 172 | |||
| 173 | # Last resort | ||
| 174 | return $hp9300->SUPER::serial(); | ||
| 175 | } | ||
| 176 | |||
| 177 | sub interfaces { | ||
| 178 | my $hp9300 = shift; | ||
| 179 | my $partial = shift; | ||
| 180 | |||
| 181 | my $i_descr = $hp9300->i_description($partial) || {}; | ||
| 182 | my $i_name = $hp9300->i_name($partial) || {}; | ||
| 183 | |||
| 184 | # Use ifName for EdgeIrons else use ifDescr | ||
| 185 | foreach my $iid ( keys %$i_name ) { | ||
| 186 | my $name = $i_name->{$iid}; | ||
| 187 | next unless defined $name; | ||
| 188 | $i_descr->{$iid} = $name | ||
| 189 | if $name =~ /^port\d+/i; | ||
| 190 | } | ||
| 191 | |||
| 192 | return $i_descr; | ||
| 193 | } | ||
| 194 | |||
| 195 | # Default tree is not the common tree: Foundry OEM, per-VLAN STP | ||
| 196 | # (snPortStp*) | ||
| 197 | sub _stp_default_is_common { return 0; } | ||
| 198 | |||
| 199 | 1; | ||
| 200 | __END__ |