| 1 | # SNMP::Info::Layer1::Bayhub | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Eric Miller, Max Baker | ||
| 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::Layer1::Bayhub; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::SONMP; | ||
| 36 | use SNMP::Info::NortelStack; | ||
| 37 | use SNMP::Info::Layer2; | ||
| 38 | |||
| 39 | @SNMP::Info::Layer1::Bayhub::ISA | ||
| 40 | = qw/SNMP::Info::SONMP SNMP::Info::NortelStack SNMP::Info::Layer2 Exporter/; | ||
| 41 | @SNMP::Info::Layer1::Bayhub::EXPORT_OK = qw//; | ||
| 42 | |||
| 43 | our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE); | ||
| 44 | |||
| 45 | $VERSION = '3.985003'; | ||
| 46 | |||
| 47 | %MIBS = ( | ||
| 48 | %SNMP::Info::Layer2::MIBS, | ||
| 49 | %SNMP::Info::NortelStack::MIBS, | ||
| 50 | %SNMP::Info::SONMP::MIBS, | ||
| 51 | 'S5-ETHERNET-COMMON-MIB' => 's5EnPortTable', | ||
| 52 | 'S5-COMMON-STATS-MIB' => 's5CmStat', | ||
| 53 | ); | ||
| 54 | |||
| 55 | %GLOBALS = ( | ||
| 56 | %SNMP::Info::Layer2::GLOBALS, %SNMP::Info::NortelStack::GLOBALS, | ||
| 57 | %SNMP::Info::SONMP::GLOBALS, | ||
| 58 | ); | ||
| 59 | |||
| 60 | %FUNCS = ( | ||
| 61 | %SNMP::Info::Layer2::FUNCS, | ||
| 62 | %SNMP::Info::NortelStack::FUNCS, | ||
| 63 | %SNMP::Info::SONMP::FUNCS, | ||
| 64 | |||
| 65 | # S5-ETHERNET-COMMON-MIB::s5EnPortTable | ||
| 66 | 'bayhub_pb_index' => 's5EnPortBrdIndx', | ||
| 67 | 'bayhub_pp_index' => 's5EnPortIndx', | ||
| 68 | 'bayhub_up_admin' => 's5EnPortPartStatus', | ||
| 69 | 'bayhub_up' => 's5EnPortLinkStatus', | ||
| 70 | |||
| 71 | # S5-ETHERNET-COMMON-MIB::s5EnPortExtTable | ||
| 72 | 'bayhub_p_speed' => 's5EnPortExtActiveSpeed', | ||
| 73 | 'bayhub_p_cap' => 's5EnPortExtHwCapability', | ||
| 74 | 'bayhub_p_adv' => 's5EnPortExtAutoNegAdv', | ||
| 75 | |||
| 76 | # S5-COMMON-STATS-MIB::s5CmSNodeTable | ||
| 77 | 'bayhub_nb_index' => 's5CmSNodeBrdIndx', | ||
| 78 | 'bayhub_np_index' => 's5CmSNodePortIndx', | ||
| 79 | 'fw_mac' => 's5CmSNodeMacAddr', | ||
| 80 | ); | ||
| 81 | |||
| 82 | %MUNGE = ( | ||
| 83 | %SNMP::Info::Layer2::MUNGE, %SNMP::Info::NortelStack::MUNGE, | ||
| 84 | %SNMP::Info::SONMP::MUNGE, | ||
| 85 | ); | ||
| 86 | |||
| 87 | sub layers { | ||
| 88 | return '00000011'; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub os { | ||
| 92 | return 'bay_hub'; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub vendor { | ||
| 96 | return 'avaya'; | ||
| 97 | } | ||
| 98 | |||
| 99 | sub model { | ||
| 100 | my $bayhub = shift; | ||
| 101 | my $id = $bayhub->id(); | ||
| 102 | return unless defined $id; | ||
| 103 | my $model = &SNMP::translateObj($id); | ||
| 104 | return $id unless defined $model; | ||
| 105 | $model =~ s/^sreg-//i; | ||
| 106 | |||
| 107 | return 'Baystack Hub' if ( $model =~ /BayStack/ ); | ||
| 108 | return '5000' if ( $model =~ /5000/ ); | ||
| 109 | return '5005' if ( $model =~ /5005/ ); | ||
| 110 | return $model; | ||
| 111 | } | ||
| 112 | |||
| 113 | # Hubs do not support ifMIB requirements for get MAC | ||
| 114 | # and port status | ||
| 115 | |||
| 116 | sub i_index { | ||
| 117 | my $bayhub = shift; | ||
| 118 | my $partial = shift; | ||
| 119 | |||
| 120 | my $b_index = $bayhub->bayhub_pb_index($partial) || {}; | ||
| 121 | my $p_index = $bayhub->bayhub_pp_index($partial) || {}; | ||
| 122 | my $model = $bayhub->model() || 'Baystack Hub'; | ||
| 123 | |||
| 124 | my %i_index; | ||
| 125 | foreach my $iid ( keys %$b_index ) { | ||
| 126 | my $board = $b_index->{$iid}; | ||
| 127 | next unless defined $board; | ||
| 128 | my $port = $p_index->{$iid} || 0; | ||
| 129 | |||
| 130 | if ( $model eq 'Baystack Hub' ) { | ||
| 131 | my $comidx = $board; | ||
| 132 | if ( !( $comidx % 5 ) ) { | ||
| 133 | $board = ( $board / 5 ); | ||
| 134 | } | ||
| 135 | elsif ( $comidx =~ /[16]$/ ) { | ||
| 136 | $board = int( $board / 5 ); | ||
| 137 | $port = 25; | ||
| 138 | } | ||
| 139 | elsif ( $comidx =~ /[27]$/ ) { | ||
| 140 | $board = int( $board / 5 ); | ||
| 141 | $port = 26; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | my $index = ( $board * 256 ) + $port; | ||
| 146 | |||
| 147 | $i_index{$iid} = $index; | ||
| 148 | } | ||
| 149 | return \%i_index; | ||
| 150 | } | ||
| 151 | |||
| 152 | # Partials don't really help in this class, but implemented | ||
| 153 | # for consistency | ||
| 154 | |||
| 155 | sub interfaces { | ||
| 156 | my $bayhub = shift; | ||
| 157 | my $partial = shift; | ||
| 158 | |||
| 159 | my $i_index = $bayhub->i_index() || {}; | ||
| 160 | |||
| 161 | my %if; | ||
| 162 | foreach my $iid ( keys %$i_index ) { | ||
| 163 | my $index = $i_index->{$iid}; | ||
| 164 | next unless defined $index; | ||
| 165 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 166 | |||
| 167 | # Index numbers are deterministic slot * 256 + port | ||
| 168 | my $port = $index % 256; | ||
| 169 | my $slot = int( $index / 256 ); | ||
| 170 | |||
| 171 | my $slotport = "$slot.$port"; | ||
| 172 | |||
| 173 | $if{$index} = $slotport; | ||
| 174 | } | ||
| 175 | |||
| 176 | return \%if; | ||
| 177 | } | ||
| 178 | |||
| 179 | sub i_duplex { | ||
| 180 | my $bayhub = shift; | ||
| 181 | my $partial = shift; | ||
| 182 | |||
| 183 | my $port_index = $bayhub->i_index() || {}; | ||
| 184 | |||
| 185 | my %i_duplex; | ||
| 186 | foreach my $iid ( keys %$port_index ) { | ||
| 187 | my $index = $port_index->{$iid}; | ||
| 188 | next unless defined $index; | ||
| 189 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 190 | |||
| 191 | my $duplex = 'half'; | ||
| 192 | $i_duplex{$index} = $duplex; | ||
| 193 | } | ||
| 194 | return \%i_duplex; | ||
| 195 | } | ||
| 196 | |||
| 197 | sub i_duplex_admin { | ||
| 198 | my $bayhub = shift; | ||
| 199 | my $partial = shift; | ||
| 200 | |||
| 201 | my $port_index = $bayhub->i_index() || {}; | ||
| 202 | |||
| 203 | my %i_duplex_admin; | ||
| 204 | foreach my $iid ( keys %$port_index ) { | ||
| 205 | my $index = $port_index->{$iid}; | ||
| 206 | next unless defined $index; | ||
| 207 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 208 | |||
| 209 | my $duplex = 'half'; | ||
| 210 | $i_duplex_admin{$index} = $duplex; | ||
| 211 | } | ||
| 212 | return \%i_duplex_admin; | ||
| 213 | } | ||
| 214 | |||
| 215 | sub i_speed { | ||
| 216 | my $bayhub = shift; | ||
| 217 | my $partial = shift; | ||
| 218 | |||
| 219 | my $port_index = $bayhub->i_index() || {}; | ||
| 220 | my $port_speed = $bayhub->bayhub_p_speed() || {}; | ||
| 221 | |||
| 222 | my %i_speed; | ||
| 223 | foreach my $iid ( keys %$port_index ) { | ||
| 224 | my $index = $port_index->{$iid}; | ||
| 225 | next unless defined $index; | ||
| 226 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 227 | my $speed = $port_speed->{$iid} || '10 Mbps'; | ||
| 228 | |||
| 229 | $speed = '10 Mbps' if $speed =~ /bps10M/i; | ||
| 230 | $speed = '100 Mbps' if $speed =~ /bps100M/i; | ||
| 231 | $i_speed{$index} = $speed; | ||
| 232 | } | ||
| 233 | return \%i_speed; | ||
| 234 | } | ||
| 235 | |||
| 236 | sub i_up { | ||
| 237 | my $bayhub = shift; | ||
| 238 | my $partial = shift; | ||
| 239 | |||
| 240 | my $port_index = $bayhub->i_index() || {}; | ||
| 241 | my $link_stat = $bayhub->bayhub_up() || {}; | ||
| 242 | |||
| 243 | my %i_up; | ||
| 244 | foreach my $iid ( keys %$port_index ) { | ||
| 245 | my $index = $port_index->{$iid}; | ||
| 246 | next unless defined $index; | ||
| 247 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 248 | my $link_stat = $link_stat->{$iid}; | ||
| 249 | next unless defined $link_stat; | ||
| 250 | |||
| 251 | $link_stat = 'up' if $link_stat =~ /on/i; | ||
| 252 | $link_stat = 'down' if $link_stat =~ /off/i; | ||
| 253 | |||
| 254 | $i_up{$index} = $link_stat; | ||
| 255 | } | ||
| 256 | return \%i_up; | ||
| 257 | } | ||
| 258 | |||
| 259 | sub i_up_admin { | ||
| 260 | my $bayhub = shift; | ||
| 261 | my $partial = shift; | ||
| 262 | |||
| 263 | my $i_index = $bayhub->i_index() || {}; | ||
| 264 | my $link_stat = $bayhub->bayhub_up_admin() || {}; | ||
| 265 | |||
| 266 | my %i_up_admin; | ||
| 267 | foreach my $iid ( keys %$i_index ) { | ||
| 268 | my $index = $i_index->{$iid}; | ||
| 269 | next unless defined $index; | ||
| 270 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 271 | my $link_stat = $link_stat->{$iid}; | ||
| 272 | next unless defined $link_stat; | ||
| 273 | |||
| 274 | $i_up_admin{$index} = $link_stat; | ||
| 275 | } | ||
| 276 | return \%i_up_admin; | ||
| 277 | } | ||
| 278 | |||
| 279 | sub set_i_up_admin { | ||
| 280 | |||
| 281 | # map setting to those the hub will understand | ||
| 282 | my %setting = qw/up 2 down 3/; | ||
| 283 | |||
| 284 | my $bayhub = shift; | ||
| 285 | my ( $setting, $iid ) = @_; | ||
| 286 | |||
| 287 | my $i_index = $bayhub->i_index() || {}; | ||
| 288 | my %reverse_i_index = reverse %$i_index; | ||
| 289 | |||
| 290 | $setting = lc($setting); | ||
| 291 | |||
| 292 | return 0 unless defined $setting{$setting}; | ||
| 293 | |||
| 294 | $iid = $reverse_i_index{$iid}; | ||
| 295 | |||
| 296 | return $bayhub->set_bayhub_up_admin( $setting{$setting}, $iid ); | ||
| 297 | } | ||
| 298 | |||
| 299 | # Hubs do not support the standard Bridge MIB | ||
| 300 | sub bp_index { | ||
| 301 | my $bayhub = shift; | ||
| 302 | my $partial = shift; | ||
| 303 | |||
| 304 | my $b_index = $bayhub->bayhub_nb_index() || {}; | ||
| 305 | my $p_index = $bayhub->bayhub_np_index() || {}; | ||
| 306 | my $model = $bayhub->model() || 'Baystack Hub'; | ||
| 307 | |||
| 308 | my %bp_index; | ||
| 309 | foreach my $iid ( keys %$b_index ) { | ||
| 310 | my $board = $b_index->{$iid}; | ||
| 311 | next unless defined $board; | ||
| 312 | my $port = $p_index->{$iid} || 0; | ||
| 313 | |||
| 314 | if ( $model eq 'Baystack Hub' ) { | ||
| 315 | my $comidx = $board; | ||
| 316 | if ( !( $comidx % 5 ) ) { | ||
| 317 | $board = ( $board / 5 ); | ||
| 318 | } | ||
| 319 | elsif ( $comidx =~ /[16]$/ ) { | ||
| 320 | $board = int( $board / 5 ); | ||
| 321 | $port = 25; | ||
| 322 | } | ||
| 323 | elsif ( $comidx =~ /[27]$/ ) { | ||
| 324 | $board = int( $board / 5 ); | ||
| 325 | $port = 26; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | my $index = ( $board * 256 ) + $port; | ||
| 330 | next if ( defined $partial and $index !~ /^$partial$/ ); | ||
| 331 | |||
| 332 | $bp_index{$index} = $index; | ||
| 333 | } | ||
| 334 | return \%bp_index; | ||
| 335 | } | ||
| 336 | |||
| 337 | sub fw_mac { | ||
| 338 | my $bayhub = shift; | ||
| 339 | my $partial = shift; | ||
| 340 | |||
| 341 | return $bayhub->SUPER::fw_mac($partial); | ||
| 342 | } | ||
| 343 | |||
| 344 | sub fw_port { | ||
| 345 | my $bayhub = shift; | ||
| 346 | my $partial = shift; | ||
| 347 | |||
| 348 | my $b_index = $bayhub->bayhub_nb_index($partial) || {}; | ||
| 349 | my $p_index = $bayhub->bayhub_np_index($partial) || {}; | ||
| 350 | my $model = $bayhub->model() || 'Baystack Hub'; | ||
| 351 | |||
| 352 | my %fw_port; | ||
| 353 | foreach my $iid ( keys %$b_index ) { | ||
| 354 | my $board = $b_index->{$iid}; | ||
| 355 | next unless defined $board; | ||
| 356 | my $port = $p_index->{$iid} || 0; | ||
| 357 | |||
| 358 | if ( $model eq 'Baystack Hub' ) { | ||
| 359 | my $comidx = $board; | ||
| 360 | if ( !( $comidx % 5 ) ) { | ||
| 361 | $board = ( $board / 5 ); | ||
| 362 | } | ||
| 363 | elsif ( $comidx =~ /[16]$/ ) { | ||
| 364 | $board = int( $board / 5 ); | ||
| 365 | $port = 25; | ||
| 366 | } | ||
| 367 | elsif ( $comidx =~ /[27]$/ ) { | ||
| 368 | $board = int( $board / 5 ); | ||
| 369 | $port = 26; | ||
| 370 | } | ||
| 371 | } | ||
| 372 | |||
| 373 | my $index = ( $board * 256 ) + $port; | ||
| 374 | |||
| 375 | $fw_port{$iid} = $index; | ||
| 376 | } | ||
| 377 | return \%fw_port; | ||
| 378 | } | ||
| 379 | |||
| 380 | sub index_factor { | ||
| 381 | return 256; | ||
| 382 | } | ||
| 383 | |||
| 384 | sub slot_offset { | ||
| 385 | return 0; | ||
| 386 | } | ||
| 387 | |||
| 388 | # Devices do not support ENTITY-MIB use proprietary methods. | ||
| 389 | |||
| 390 | sub e_index { | ||
| 391 | my $stack = shift; | ||
| 392 | my $partial = shift; | ||
| 393 | |||
| 394 | return $stack->ns_e_index($partial); | ||
| 395 | } | ||
| 396 | |||
| 397 | sub e_class { | ||
| 398 | my $stack = shift; | ||
| 399 | my $partial = shift; | ||
| 400 | |||
| 401 | return $stack->ns_e_class($partial); | ||
| 402 | } | ||
| 403 | |||
| 404 | sub e_descr { | ||
| 405 | my $stack = shift; | ||
| 406 | my $partial = shift; | ||
| 407 | |||
| 408 | return $stack->ns_e_descr($partial); | ||
| 409 | } | ||
| 410 | |||
| 411 | sub e_name { | ||
| 412 | my $stack = shift; | ||
| 413 | my $partial = shift; | ||
| 414 | |||
| 415 | return $stack->ns_e_name($partial); | ||
| 416 | } | ||
| 417 | |||
| 418 | sub e_fwver { | ||
| 419 | my $stack = shift; | ||
| 420 | my $partial = shift; | ||
| 421 | |||
| 422 | return $stack->ns_e_fwver($partial); | ||
| 423 | } | ||
| 424 | |||
| 425 | sub e_hwver { | ||
| 426 | my $stack = shift; | ||
| 427 | my $partial = shift; | ||
| 428 | |||
| 429 | return $stack->ns_e_hwver($partial); | ||
| 430 | } | ||
| 431 | |||
| 432 | sub e_parent { | ||
| 433 | my $stack = shift; | ||
| 434 | my $partial = shift; | ||
| 435 | |||
| 436 | return $stack->ns_e_parent($partial); | ||
| 437 | } | ||
| 438 | |||
| 439 | sub e_pos { | ||
| 440 | my $stack = shift; | ||
| 441 | my $partial = shift; | ||
| 442 | |||
| 443 | return $stack->ns_e_pos($partial); | ||
| 444 | } | ||
| 445 | |||
| 446 | sub e_serial { | ||
| 447 | my $stack = shift; | ||
| 448 | my $partial = shift; | ||
| 449 | |||
| 450 | return $stack->ns_e_serial($partial); | ||
| 451 | } | ||
| 452 | |||
| 453 | sub e_swver { | ||
| 454 | my $stack = shift; | ||
| 455 | my $partial = shift; | ||
| 456 | |||
| 457 | return $stack->ns_e_swver($partial); | ||
| 458 | } | ||
| 459 | |||
| 460 | sub e_type { | ||
| 461 | my $stack = shift; | ||
| 462 | my $partial = shift; | ||
| 463 | |||
| 464 | return $stack->ns_e_type($partial); | ||
| 465 | } | ||
| 466 | |||
| 467 | sub e_vendor { | ||
| 468 | my $stack = shift; | ||
| 469 | my $partial = shift; | ||
| 470 | |||
| 471 | return $stack->ns_e_vendor($partial); | ||
| 472 | } | ||
| 473 | |||
| 474 | 1; | ||
| 475 | __END__ |