| 1 | # SNMP::Info::Layer2::HP4000 - SNMP Interface to older HP ProCurve Switches (1600, 2400, 2424M, 4000 and 8000) | ||
| 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::HP4000; | ||
| 33 | |||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use Exporter; | ||
| 37 | use SNMP::Info::Layer3; | ||
| 38 | use SNMP::Info::MAU; | ||
| 39 | use SNMP::Info::CDP; | ||
| 40 | |||
| 41 | @SNMP::Info::Layer2::HP4000::ISA | ||
| 42 | = qw/SNMP::Info::Layer3 SNMP::Info::MAU | ||
| 43 | SNMP::Info::CDP Exporter/; | ||
| 44 | @SNMP::Info::Layer2::HP4000::EXPORT_OK = qw//; | ||
| 45 | |||
| 46 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %PORTSTAT, %MODEL_MAP, %MUNGE); | ||
| 47 | |||
| 48 | $VERSION = '3.985003'; | ||
| 49 | |||
| 50 | %MIBS = ( | ||
| 51 | %SNMP::Info::Layer3::MIBS, | ||
| 52 | %SNMP::Info::MAU::MIBS, | ||
| 53 | %SNMP::Info::CDP::MIBS, | ||
| 54 | 'RFC1271-MIB' => 'logDescription', | ||
| 55 | 'HP-ICF-OID' => 'hpSwitch4000', | ||
| 56 | 'HP-VLAN' => 'hpVlanMemberIndex', | ||
| 57 | 'STATISTICS-MIB' => 'hpSwitchCpuStat', | ||
| 58 | 'NETSWITCH-MIB' => 'hpMsgBufFree', | ||
| 59 | 'CONFIG-MIB' => 'hpSwitchConfig', | ||
| 60 | 'SEMI-MIB' => 'hpHttpMgSerialNumber', | ||
| 61 | 'HP-ICF-CHASSIS' => 'hpicfSensorObjectId', | ||
| 62 | ); | ||
| 63 | |||
| 64 | %GLOBALS = ( | ||
| 65 | %SNMP::Info::Layer3::GLOBALS, | ||
| 66 | %SNMP::Info::MAU::GLOBALS, | ||
| 67 | %SNMP::Info::CDP::GLOBALS, | ||
| 68 | 'serial1' => 'hpHttpMgSerialNumber.0', | ||
| 69 | 'hp_cpu' => 'hpSwitchCpuStat.0', | ||
| 70 | 'hp_mem_total' => 'hpGlobalMemTotalBytes.1', | ||
| 71 | 'mem_free' => 'hpGlobalMemFreeBytes.1', | ||
| 72 | 'mem_used' => 'hpGlobalMemAllocBytes.1', | ||
| 73 | 'os_version' => 'hpSwitchOsVersion.0', | ||
| 74 | 'os_bin' => 'hpSwitchRomVersion.0', | ||
| 75 | 'mac' => 'hpSwitchBaseMACAddress.0', | ||
| 76 | 'hp_vlans' => 'hpVlanNumber', | ||
| 77 | ); | ||
| 78 | |||
| 79 | %FUNCS = ( | ||
| 80 | %SNMP::Info::Layer3::FUNCS, | ||
| 81 | %SNMP::Info::MAU::FUNCS, | ||
| 82 | %SNMP::Info::CDP::FUNCS, | ||
| 83 | 'bp_index2' => 'dot1dBasePortIfIndex', | ||
| 84 | 'i_type2' => 'ifType', | ||
| 85 | |||
| 86 | # RFC1271 | ||
| 87 | 'l_descr' => 'logDescription', | ||
| 88 | |||
| 89 | # HP-VLAN-MIB | ||
| 90 | 'hp_v_index' => 'hpVlanDot1QID', | ||
| 91 | 'hp_v_name' => 'hpVlanIdentName', | ||
| 92 | 'hp_v_state' => 'hpVlanIdentState', | ||
| 93 | 'hp_v_type' => 'hpVlanIdentType', | ||
| 94 | 'hp_v_status' => 'hpVlanIdentStatus', | ||
| 95 | 'hp_v_mac' => 'hpVlanAddrPhysAddress', | ||
| 96 | 'hp_v_if_index' => 'hpVlanMemberIndex', | ||
| 97 | 'hp_v_if_tag' => 'hpVlanMemberTagged2', | ||
| 98 | |||
| 99 | # CONFIG-MIB::hpSwitchPortTable | ||
| 100 | 'hp_duplex' => 'hpSwitchPortEtherMode', | ||
| 101 | 'hp_duplex_admin' => 'hpSwitchPortFastEtherMode', | ||
| 102 | 'vendor_i_type' => 'hpSwitchPortType', | ||
| 103 | |||
| 104 | # HP-ICF-CHASSIS | ||
| 105 | 'hp_s_oid' => 'hpicfSensorObjectId', | ||
| 106 | 'hp_s_name' => 'hpicfSensorDescr', | ||
| 107 | 'hp_s_status' => 'hpicfSensorStatus', | ||
| 108 | ); | ||
| 109 | |||
| 110 | %MUNGE = ( | ||
| 111 | |||
| 112 | # Inherit all the built in munging | ||
| 113 | %SNMP::Info::Layer3::MUNGE, | ||
| 114 | %SNMP::Info::MAU::MUNGE, | ||
| 115 | %SNMP::Info::CDP::MUNGE | ||
| 116 | ); | ||
| 117 | |||
| 118 | %MODEL_MAP = ( | ||
| 119 | 'J4093A' => '2424M', | ||
| 120 | 'J4110A' => '8000M', | ||
| 121 | 'J4120A' => '1600M', | ||
| 122 | 'J4121A' => '4000M', | ||
| 123 | 'J4122A' => '2400M', | ||
| 124 | 'J4122B' => '2424M', | ||
| 125 | ); | ||
| 126 | |||
| 127 | # Method Overrides | ||
| 128 | |||
| 129 | sub cpu { | ||
| 130 | my $hp = shift; | ||
| 131 | return $hp->hp_cpu(); | ||
| 132 | } | ||
| 133 | |||
| 134 | sub mem_total { | ||
| 135 | my $hp = shift; | ||
| 136 | return $hp->hp_mem_total(); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub os { | ||
| 140 | return 'hp'; | ||
| 141 | } | ||
| 142 | |||
| 143 | sub os_ver { | ||
| 144 | my $hp = shift; | ||
| 145 | my $os_version = $hp->os_version(); | ||
| 146 | return $os_version if defined $os_version; | ||
| 147 | |||
| 148 | # Some older ones don't have this value,so we cull it from the description | ||
| 149 | my $descr = $hp->description(); | ||
| 150 | if ( $descr =~ m/revision ([A-Z]{1}\.\d{2}\.\d{2})/ ) { | ||
| 151 | return $1; | ||
| 152 | } | ||
| 153 | return; | ||
| 154 | } | ||
| 155 | |||
| 156 | # Lookup model number, and translate the part number to the common number | ||
| 157 | sub model { | ||
| 158 | my $hp = shift; | ||
| 159 | my $id = $hp->id(); | ||
| 160 | return unless defined $id; | ||
| 161 | my $model = &SNMP::translateObj($id); | ||
| 162 | return $id unless defined $model; | ||
| 163 | |||
| 164 | $model =~ s/^hpswitch//i; | ||
| 165 | |||
| 166 | return defined $MODEL_MAP{$model} ? $MODEL_MAP{$model} : $model; | ||
| 167 | } | ||
| 168 | |||
| 169 | sub interfaces { | ||
| 170 | my $hp = shift; | ||
| 171 | my $interfaces = $hp->i_index(); | ||
| 172 | my $i_descr = $hp->i_description(); | ||
| 173 | |||
| 174 | my %if; | ||
| 175 | foreach my $iid ( keys %$interfaces ) { | ||
| 176 | my $descr = $i_descr->{$iid}; | ||
| 177 | next unless defined $descr; | ||
| 178 | $if{$iid} = $descr if ( defined $descr and length $descr ); | ||
| 179 | } | ||
| 180 | |||
| 181 | return \%if | ||
| 182 | } | ||
| 183 | |||
| 184 | sub i_name { | ||
| 185 | my $hp = shift; | ||
| 186 | my $i_alias = $hp->i_alias(); | ||
| 187 | my $e_name = $hp->e_name(); | ||
| 188 | my $e_port = $hp->e_port(); | ||
| 189 | |||
| 190 | my %i_name; | ||
| 191 | |||
| 192 | foreach my $port ( keys %$e_name ) { | ||
| 193 | my $iid = $e_port->{$port}; | ||
| 194 | next unless defined $iid; | ||
| 195 | my $alias = $i_alias->{$iid}; | ||
| 196 | next unless defined $iid; | ||
| 197 | $i_name{$iid} = $e_name->{$port}; | ||
| 198 | |||
| 199 | # Check for alias | ||
| 200 | $i_name{$iid} = $alias if ( defined $alias and length($alias) ); | ||
| 201 | } | ||
| 202 | |||
| 203 | return \%i_name; | ||
| 204 | } | ||
| 205 | |||
| 206 | sub i_duplex { | ||
| 207 | my $hp = shift; | ||
| 208 | |||
| 209 | return $hp->mau_i_duplex(); | ||
| 210 | } | ||
| 211 | |||
| 212 | sub i_duplex_admin { | ||
| 213 | my $hp = shift; | ||
| 214 | my $partial = shift; | ||
| 215 | |||
| 216 | # Try HP MIB first | ||
| 217 | my $hp_duplex = $hp->hp_duplex_admin($partial); | ||
| 218 | if ( defined $hp_duplex and scalar( keys %$hp_duplex ) ) { | ||
| 219 | |||
| 220 | my %i_duplex; | ||
| 221 | foreach my $if ( keys %$hp_duplex ) { | ||
| 222 | my $duplex = $hp_duplex->{$if}; | ||
| 223 | next unless defined $duplex; | ||
| 224 | |||
| 225 | $duplex = 'half' if $duplex =~ /half/i; | ||
| 226 | $duplex = 'full' if $duplex =~ /full/i; | ||
| 227 | $duplex = 'auto' if $duplex =~ /auto/i; | ||
| 228 | $i_duplex{$if} = $duplex; | ||
| 229 | } | ||
| 230 | return \%i_duplex; | ||
| 231 | } | ||
| 232 | else { | ||
| 233 | return $hp->mau_i_duplex_admin(); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | sub vendor { | ||
| 238 | return 'hp'; | ||
| 239 | } | ||
| 240 | |||
| 241 | sub log { | ||
| 242 | my $hp = shift; | ||
| 243 | |||
| 244 | my $log = $hp->l_descr(); | ||
| 245 | |||
| 246 | my $logstring = undef; | ||
| 247 | |||
| 248 | foreach my $val ( values %$log ) { | ||
| 249 | next if $val =~ /^Link\s+(Up|Down)/; | ||
| 250 | $logstring .= "$val\n"; | ||
| 251 | } | ||
| 252 | |||
| 253 | return $logstring; | ||
| 254 | } | ||
| 255 | |||
| 256 | sub slots { | ||
| 257 | my $hp = shift; | ||
| 258 | |||
| 259 | my $e_name = $hp->e_name(); | ||
| 260 | |||
| 261 | return unless defined $e_name; | ||
| 262 | |||
| 263 | my $slots; | ||
| 264 | foreach my $slot ( keys %$e_name ) { | ||
| 265 | $slots++ if $e_name->{$slot} =~ /slot/i; | ||
| 266 | } | ||
| 267 | |||
| 268 | return $slots; | ||
| 269 | } | ||
| 270 | |||
| 271 | sub fan { | ||
| 272 | my $hp = shift; | ||
| 273 | return &_sensor( $hp, 'fan' ); | ||
| 274 | } | ||
| 275 | |||
| 276 | sub ps1_status { | ||
| 277 | my $hp = shift; | ||
| 278 | return &_sensor( $hp, 'power', '^power supply 1' ) | ||
| 279 | || &_sensor( $hp, 'power', '^power supply sensor' ); | ||
| 280 | } | ||
| 281 | |||
| 282 | sub ps2_status { | ||
| 283 | my $hp = shift; | ||
| 284 | return &_sensor( $hp, 'power', '^power supply 2' ) | ||
| 285 | || &_sensor( $hp, 'power', '^redundant' ); | ||
| 286 | } | ||
| 287 | |||
| 288 | sub _sensor { | ||
| 289 | my $hp = shift; | ||
| 290 | my $search_type = shift || 'fan'; | ||
| 291 | my $search_name = shift || ''; | ||
| 292 | my $hp_s_oid = $hp->hp_s_oid(); | ||
| 293 | my $result; | ||
| 294 | foreach my $sensor ( keys %$hp_s_oid ) { | ||
| 295 | my $sensortype = &SNMP::translateObj( $hp_s_oid->{$sensor} ); | ||
| 296 | if ( $sensortype =~ /$search_type/i ) { | ||
| 297 | my $sensorname = $hp->hp_s_name()->{$sensor}; | ||
| 298 | my $sensorstatus = $hp->hp_s_status()->{$sensor}; | ||
| 299 | if ( $sensorname =~ /$search_name/i ) { | ||
| 300 | $result = $sensorstatus; | ||
| 301 | } | ||
| 302 | } | ||
| 303 | } | ||
| 304 | return $result; | ||
| 305 | } | ||
| 306 | |||
| 307 | # Bridge MIB does not map Bridge Port to ifIndex correctly on older models, but Bridge Port equals ifIndex in these devices | ||
| 308 | sub bp_index { | ||
| 309 | my $hp = shift; | ||
| 310 | my $partial = shift; | ||
| 311 | |||
| 312 | my $if_index = $hp->i_index($partial); | ||
| 313 | my %mod_bp_index; | ||
| 314 | foreach my $iid ( keys %$if_index ) { | ||
| 315 | $mod_bp_index{$iid} = $iid; | ||
| 316 | } | ||
| 317 | return \%mod_bp_index; | ||
| 318 | } | ||
| 319 | |||
| 320 | # VLAN methods. Devices in this class use the proprietary HP-VLAN-MIB. | ||
| 321 | |||
| 322 | sub v_index { | ||
| 323 | my $hp = shift; | ||
| 324 | my $partial = shift; | ||
| 325 | |||
| 326 | return $hp->hp_v_index($partial); | ||
| 327 | } | ||
| 328 | |||
| 329 | sub v_name { | ||
| 330 | my $hp = shift; | ||
| 331 | my $partial = shift; | ||
| 332 | |||
| 333 | return $hp->hp_v_name($partial); | ||
| 334 | } | ||
| 335 | |||
| 336 | sub i_vlan { | ||
| 337 | my $hp = shift; | ||
| 338 | |||
| 339 | # the hpvlanmembertagged2 table has an entry in the form of | ||
| 340 | # vlan.interface = /untagged/no/tagged/auto | ||
| 341 | my $i_vlan = {}; | ||
| 342 | my $hp_v_index = $hp->hp_v_index(); | ||
| 343 | my $hp_v_if_tag = $hp->hp_v_if_tag(); | ||
| 344 | foreach my $row ( keys %$hp_v_if_tag ) { | ||
| 345 | my ( $index, $if ) = split( /\./, $row ); | ||
| 346 | |||
| 347 | my $tag = $hp_v_if_tag->{$row}; | ||
| 348 | my $vlan = $hp_v_index->{$index}; | ||
| 349 | |||
| 350 | next unless ( defined $tag and $tag =~ /untagged/ ); | ||
| 351 | |||
| 352 | $i_vlan->{$if} = $vlan if defined $vlan; | ||
| 353 | } | ||
| 354 | |||
| 355 | return $i_vlan; | ||
| 356 | } | ||
| 357 | |||
| 358 | sub i_vlan_membership { | ||
| 359 | my $hp = shift; | ||
| 360 | |||
| 361 | my $i_vlan_membership = {}; | ||
| 362 | my $hp_v_index = $hp->hp_v_index(); | ||
| 363 | my $hp_v_if_tag = $hp->hp_v_if_tag(); | ||
| 364 | foreach my $row ( keys %$hp_v_if_tag ) { | ||
| 365 | my ( $index, $if ) = split( /\./, $row ); | ||
| 366 | |||
| 367 | my $tag = $hp_v_if_tag->{$row}; | ||
| 368 | my $vlan = $hp_v_index->{$index}; | ||
| 369 | |||
| 370 | next unless ( defined $tag ); | ||
| 371 | next if ( $tag eq 'no' ); | ||
| 372 | |||
| 373 | push( @{ $i_vlan_membership->{$if} }, $vlan ); | ||
| 374 | } | ||
| 375 | |||
| 376 | return $i_vlan_membership; | ||
| 377 | } | ||
| 378 | |||
| 379 | sub i_vlan_membership_untagged { | ||
| 380 | my $hp = shift; | ||
| 381 | my $partial = shift; | ||
| 382 | |||
| 383 | my $vlans = $hp->i_vlan($partial); | ||
| 384 | my $i_vlan_membership = {}; | ||
| 385 | foreach my $port (keys %$vlans) { | ||
| 386 | my $vlan = $vlans->{$port}; | ||
| 387 | push( @{ $i_vlan_membership->{$port} }, $vlan ); | ||
| 388 | } | ||
| 389 | |||
| 390 | return $i_vlan_membership; | ||
| 391 | } | ||
| 392 | |||
| 393 | sub set_i_vlan { | ||
| 394 | my $hp = shift; | ||
| 395 | my $rv; | ||
| 396 | |||
| 397 | my $hp_v_index = $hp->hp_v_index(); | ||
| 398 | my $hp_v_if_tag = $hp->hp_v_if_tag(); | ||
| 399 | if (defined $hp_v_index and scalar(keys %$hp_v_index)){ | ||
| 400 | my $vlan = shift; | ||
| 401 | my $iid = shift; | ||
| 402 | my $old_untagged; | ||
| 403 | # Hash to lookup VLAN index of the VID (dot1q tag) | ||
| 404 | my %vl_trans = reverse %$hp_v_index; | ||
| 405 | |||
| 406 | # Translate the VLAN identifier (tag) value to the index used by the HP-VLAN MIB | ||
| 407 | my $vlan_index = $vl_trans{$vlan}; | ||
| 408 | if (defined $vlan_index) { | ||
| 409 | |||
| 410 | # First, loop through table to determine current untagged vlan for the port we're about to change | ||
| 411 | foreach my $row (keys %$hp_v_if_tag){ | ||
| 412 | my ($index,$if) = split(/\./,$row); | ||
| 413 | if ($if == $iid and $hp_v_if_tag->{$row} =~ /untagged/) { | ||
| 414 | # Store the row information of the current untagged VLAN and temporarily set it to tagged | ||
| 415 | $old_untagged = $row; | ||
| 416 | $rv = $hp->set_hp_v_if_tag(1, $row); | ||
| 417 | last; | ||
| 418 | } | ||
| 419 | } | ||
| 420 | |||
| 421 | # Then set our port untagged in the desired VLAN | ||
| 422 | my $rv = $hp->set_hp_v_if_tag(2, "$vlan_index.$iid"); | ||
| 423 | if (defined $rv) { | ||
| 424 | # If vlan change is successful, remove VLAN that used to be untagged from the port | ||
| 425 | if (defined $old_untagged) { | ||
| 426 | $rv = $hp->set_hp_v_if_tag(3, $old_untagged); | ||
| 427 | $hp->error_throw("Error removing previous untagged vlan from port, should never happen...\n") unless defined $rv; | ||
| 428 | } | ||
| 429 | } else { | ||
| 430 | # If vlan change was not successful, try to revert to the old situation. | ||
| 431 | if (defined $old_untagged) { | ||
| 432 | $rv = $hp->set_hp_v_if_tag(2, $old_untagged) if defined $old_untagged; | ||
| 433 | if (defined $rv) { | ||
| 434 | $hp->error_throw("VLAN change failed, restored port to previous configuration.\n"); | ||
| 435 | } else { | ||
| 436 | $hp->error_throw("VLAN change failed, unable to restore old configuration. Check device.\n"); | ||
| 437 | } | ||
| 438 | } | ||
| 439 | } | ||
| 440 | } else { | ||
| 441 | $hp->error_throw("Requested VLAN (VLAN ID: $vlan) not available on device.\n"); | ||
| 442 | } | ||
| 443 | } else { | ||
| 444 | $hp->error_throw("Error retrieving VLAN information from device.\n"); | ||
| 445 | } | ||
| 446 | return $rv; | ||
| 447 | } | ||
| 448 | |||
| 449 | sub set_i_vlan_tagged { | ||
| 450 | my $hp = shift; | ||
| 451 | my $vlan = shift; | ||
| 452 | my $iid = shift; | ||
| 453 | my $rv; | ||
| 454 | |||
| 455 | my $hp_v_index = $hp->hp_v_index(); | ||
| 456 | if (defined $hp_v_index and scalar(keys %$hp_v_index)){ | ||
| 457 | # Hash to lookup VLAN index of the VID (dot1q tag) | ||
| 458 | my %vl_trans = reverse %$hp_v_index; | ||
| 459 | |||
| 460 | # Translate the VLAN identifier (tag) value to the index used by the HP-VLAN MIB | ||
| 461 | my $vlan_index = $vl_trans{$vlan}; | ||
| 462 | if (defined $vlan_index) { | ||
| 463 | # Set our port tagged in the desired VLAN | ||
| 464 | $rv = $hp->set_hp_v_if_tag(1, "$vlan_index.$iid"); | ||
| 465 | } else { | ||
| 466 | $hp->error_throw("Requested VLAN (VLAN ID: $vlan) not available on device.\n"); | ||
| 467 | } | ||
| 468 | } | ||
| 469 | return $rv; | ||
| 470 | } | ||
| 471 | |||
| 472 | 1; | ||
| 473 | __END__ |