| 1 | # SNMP::Info::Layer3::Timetra | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Bill Fenner | ||
| 4 | # | ||
| 5 | # Redistribution and use in source and binary forms, with or without | ||
| 6 | # modification, are permitted provided that the following conditions are met: | ||
| 7 | # | ||
| 8 | # * Redistributions of source code must retain the above copyright notice, | ||
| 9 | # this list of conditions and the following disclaimer. | ||
| 10 | # * Redistributions in binary form must reproduce the above copyright | ||
| 11 | # notice, this list of conditions and the following disclaimer in the | ||
| 12 | # documentation and/or other materials provided with the distribution. | ||
| 13 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 14 | # names of its contributors may be used to endorse or promote products | ||
| 15 | # derived from this software without specific prior written permission. | ||
| 16 | # | ||
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 21 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | |||
| 29 | package SNMP::Info::Layer3::Timetra; | ||
| 30 | |||
| 31 | use strict; | ||
| 32 | use warnings; | ||
| 33 | use Exporter; | ||
| 34 | use SNMP::Info::Layer3; | ||
| 35 | use SNMP::Info::Aggregate; | ||
| 36 | |||
| 37 | @SNMP::Info::Layer3::Timetra::ISA | ||
| 38 | = qw/SNMP::Info::Aggregate SNMP::Info::Layer3 | ||
| 39 | Exporter/; | ||
| 40 | @SNMP::Info::Layer3::Timetra::EXPORT_OK = qw//; | ||
| 41 | |||
| 42 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 43 | |||
| 44 | $VERSION = '3.985003'; | ||
| 45 | |||
| 46 | %MIBS = ( | ||
| 47 | %SNMP::Info::Layer3::MIBS, | ||
| 48 | %SNMP::Info::Aggregate::MIBS, | ||
| 49 | 'TIMETRA-GLOBAL-MIB' => 'timetraReg', | ||
| 50 | 'TIMETRA-LLDP-MIB' => 'tmnxLldpAdminStatus', | ||
| 51 | 'TIMETRA-PORT-MIB' => 'tmnxPortEtherDuplex', | ||
| 52 | 'TIMETRA-CHASSIS-MIB' => 'tmnxChassisFanOperStatus', | ||
| 53 | ); | ||
| 54 | |||
| 55 | %GLOBALS = ( %SNMP::Info::Layer3::GLOBALS, ); | ||
| 56 | |||
| 57 | %FUNCS = ( | ||
| 58 | %SNMP::Info::Layer3::FUNCS, | ||
| 59 | |||
| 60 | # For some reason LLDP-MIB::lldpLocManAddrTable is populated | ||
| 61 | # but LLDP-MIB::lldpRemTable is not and we need to use the | ||
| 62 | # proprietary TIMETRA-LLDP-MIB Note: these tables are | ||
| 63 | # indexed differently than LLDP-MIB | ||
| 64 | # TIMETRA-LLDP-MIB::tmnxLldpRemTable | ||
| 65 | 'lldp_rem_id_type' => 'tmnxLldpRemChassisIdSubtype', | ||
| 66 | 'lldp_rem_id' => 'tmnxLldpRemChassisId', | ||
| 67 | 'lldp_rem_pid_type' => 'tmnxLldpRemPortIdSubtype', | ||
| 68 | 'lldp_rem_pid' => 'tmnxLldpRemPortId', | ||
| 69 | 'lldp_rem_desc' => 'tmnxLldpRemPortDesc', | ||
| 70 | 'lldp_rem_sysname' => 'tmnxLldpRemSysName', | ||
| 71 | 'lldp_rem_sysdesc' => 'tmnxLldpRemSysDesc', | ||
| 72 | 'lldp_rem_sys_cap' => 'tmnxLldpRemSysCapEnabled', | ||
| 73 | 'lldp_rem_cap_spt' => 'tmnxLldpRemSysCapSupported', | ||
| 74 | |||
| 75 | # TIMETRA-LLDP-MIB::tmnxLldpRemManAddrTable | ||
| 76 | 'lldp_rman_addr' => 'tmnxLldpRemManAddrIfSubtype', | ||
| 77 | |||
| 78 | # TIMETRA-PORT-MIB::tmnxPortEtherTable | ||
| 79 | 'tmnx_eth_speed_admin' => 'tmnxPortEtherSpeed', | ||
| 80 | 'tmnx_eth_duplex' => 'tmnxPortEtherOperDuplex', | ||
| 81 | 'tmnx_eth_duplex_admin' => 'tmnxPortEtherDuplex', | ||
| 82 | 'tmnx_eth_auto' => 'tmnxPortEtherAutoNegotiate', | ||
| 83 | |||
| 84 | # TIMETRA-CHASSIS-MIB::tmnxChassisFanTable | ||
| 85 | 'tmnx_fan_state' => 'tmnxChassisFanOperStatus', | ||
| 86 | |||
| 87 | # TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyTable | ||
| 88 | 'tmnx_ps1_state' => 'tmnxChassisPowerSupply1Status', | ||
| 89 | 'tmnx_ps2_state' => 'tmnxChassisPowerSupply2Status', | ||
| 90 | |||
| 91 | # TIMETRA-CHASSIS-MIB::tmnxHwTable | ||
| 92 | 'e_descr' => 'tmnxHwName', | ||
| 93 | 'e_parent' => 'tmnxHwContainedIn', | ||
| 94 | 'e_name' => 'tmnxHwName', | ||
| 95 | 'e_class' => 'tmnxHwClass', | ||
| 96 | 'e_pos' => 'tmnxHwParentRelPos', | ||
| 97 | 'e_swver' => 'tmnxHwSoftwareCodeVersion', | ||
| 98 | 'e_model' => 'tmnxHwMfgBoardNumber', | ||
| 99 | 'e_serial' => 'tmnxHwSerialNumber', | ||
| 100 | 'e_fru' => 'tmnxHwIsFRU', | ||
| 101 | 'e_fwver' => 'tmnxHwFirmwareCodeVersion', | ||
| 102 | ); | ||
| 103 | |||
| 104 | %MUNGE = ( | ||
| 105 | %SNMP::Info::Layer3::MUNGE, | ||
| 106 | 'tmnx_fan_state' => \&SNMP::Info::Layer3::Timetra::munge_tmnx_state, | ||
| 107 | 'tmnx_ps1_state' => \&SNMP::Info::Layer3::Timetra::munge_tmnx_state, | ||
| 108 | 'tmnx_ps2_state' => \&SNMP::Info::Layer3::Timetra::munge_tmnx_state, | ||
| 109 | 'e_type' => \&SNMP::Info::munge_e_type, | ||
| 110 | 'e_class' => \&SNMP::Info::Layer3::Timetra::munge_tmnx_e_class, | ||
| 111 | 'e_swver' => \&SNMP::Info::Layer3::Timetra::munge_tmnx_e_swver, | ||
| 112 | ); | ||
| 113 | |||
| 114 | sub model { | ||
| 115 | my $timetra = shift; | ||
| 116 | my $id = $timetra->id(); | ||
| 117 | my $model = SNMP::translateObj($id); | ||
| 118 | my $descr = $timetra->description(); | ||
| 119 | |||
| 120 | my $str; | ||
| 121 | |||
| 122 | if ( defined ($descr) && $descr =~ /\s+(7\d{3})/ ) { | ||
| 123 | $str = $1; | ||
| 124 | } | ||
| 125 | |||
| 126 | if ( defined $model && $model =~ /^tmnxModel/ ) { | ||
| 127 | $model =~ s/^tmnxModel//; | ||
| 128 | $model =~ s/Reg$//; | ||
| 129 | $str .= $str ? " " : ""; | ||
| 130 | $str .= $model; | ||
| 131 | } | ||
| 132 | |||
| 133 | return $str || $id; | ||
| 134 | } | ||
| 135 | |||
| 136 | sub os { | ||
| 137 | return 'TiMOS'; | ||
| 138 | } | ||
| 139 | |||
| 140 | sub vendor { | ||
| 141 | return 'nokia'; | ||
| 142 | } | ||
| 143 | |||
| 144 | sub os_ver { | ||
| 145 | my $timetra = shift; | ||
| 146 | |||
| 147 | my $descr = $timetra->description(); | ||
| 148 | if ( defined ($descr) && $descr =~ m/^TiMOS-(\S+)/x ) { | ||
| 149 | return $1; | ||
| 150 | } | ||
| 151 | return; | ||
| 152 | } | ||
| 153 | |||
| 154 | # The interface description contains the SFP type, so | ||
| 155 | # to avoid losing historical information through a configuration change | ||
| 156 | # we use interface name instead. | ||
| 157 | sub interfaces { | ||
| 158 | my $alu = shift; | ||
| 159 | my $partial = shift; | ||
| 160 | |||
| 161 | return $alu->orig_i_name($partial); | ||
| 162 | } | ||
| 163 | |||
| 164 | # The TIMETRA-LLDP-MIB::tmnxLldpRemTable unambiguously states it uses ifIndex | ||
| 165 | # Trying to cross reference to ifDescr or ifAlias would cause unpredictable | ||
| 166 | # results based upon how the device names ports. | ||
| 167 | sub lldp_if { | ||
| 168 | my $alu = shift; | ||
| 169 | my $partial = shift; | ||
| 170 | |||
| 171 | my $addr = $alu->lldp_rem_pid($partial) || {}; | ||
| 172 | |||
| 173 | my %lldp_if; | ||
| 174 | foreach my $key ( keys %$addr ) { | ||
| 175 | my @aOID = split( '\.', $key ); | ||
| 176 | my $port = $aOID[1]; | ||
| 177 | next unless $port; | ||
| 178 | |||
| 179 | $lldp_if{$key} = $port; | ||
| 180 | } | ||
| 181 | return \%lldp_if; | ||
| 182 | } | ||
| 183 | |||
| 184 | # The proprietary TIMETRA-LLDP-MIB tables are indexed differently than LLDP-MIB | ||
| 185 | # We overwrite the private function so that the we don't have to replicate | ||
| 186 | # the code in SNMP::Info::LLDP that uses it. | ||
| 187 | |||
| 188 | sub _lldp_addr_index { | ||
| 189 | my $alu = shift; | ||
| 190 | my $idx = shift; | ||
| 191 | |||
| 192 | my @oids = split( /\./, $idx ); | ||
| 193 | |||
| 194 | # Index has extra field compared to LLDP-MIB | ||
| 195 | my $index = join( '.', splice( @oids, 0, 4 ) ); | ||
| 196 | my $proto = shift(@oids); | ||
| 197 | shift(@oids) if scalar @oids > 4; # $length | ||
| 198 | |||
| 199 | return unless defined $proto and @oids; | ||
| 200 | |||
| 201 | # IPv4 | ||
| 202 | if ( $proto == 1 ) { | ||
| 203 | return ( $index, $proto, join( '.', @oids ) ); | ||
| 204 | } | ||
| 205 | |||
| 206 | # IPv6 | ||
| 207 | elsif ( $proto == 2 ) { | ||
| 208 | return ( $index, $proto, | ||
| 209 | join( ':', unpack( '(H4)*', pack( 'C*', @oids ) ) ) ); | ||
| 210 | } | ||
| 211 | |||
| 212 | # MAC | ||
| 213 | elsif ( $proto == 6 ) { | ||
| 214 | return ( $index, $proto, | ||
| 215 | join( ':', map { sprintf "%02x", $_ } @oids ) ); | ||
| 216 | } | ||
| 217 | |||
| 218 | # TODO - Other protocols may be used as well; implement when needed? | ||
| 219 | else { | ||
| 220 | return; | ||
| 221 | } | ||
| 222 | }; | ||
| 223 | |||
| 224 | sub i_duplex { | ||
| 225 | my $alu = shift; | ||
| 226 | my $partial = shift; | ||
| 227 | |||
| 228 | my $hw_duplex = $alu->tmnx_eth_duplex($partial) || {}; | ||
| 229 | |||
| 230 | my %i_duplex; | ||
| 231 | if ( ref {} eq ref $hw_duplex and scalar keys %$hw_duplex ) { | ||
| 232 | foreach my $if ( keys %$hw_duplex ) { | ||
| 233 | my $duplex = $hw_duplex->{$if}; | ||
| 234 | next unless defined $duplex; | ||
| 235 | next if $duplex eq 'notApplicable'; | ||
| 236 | my ( $slot, $ifindex ) = split( /\./, $if ); | ||
| 237 | |||
| 238 | $duplex = 'half' | ||
| 239 | if ( $duplex =~ /half/i ); | ||
| 240 | $duplex = 'full' | ||
| 241 | if ( $duplex =~ /full/i ); | ||
| 242 | |||
| 243 | $i_duplex{$ifindex} = $duplex; | ||
| 244 | } | ||
| 245 | return \%i_duplex; | ||
| 246 | } | ||
| 247 | return $alu->SUPER::i_duplex($partial); | ||
| 248 | } | ||
| 249 | |||
| 250 | sub i_duplex_admin { | ||
| 251 | my $alu = shift; | ||
| 252 | my $partial = shift; | ||
| 253 | |||
| 254 | my $hw_duplex_admin = $alu->tmnx_eth_duplex_admin($partial) || {}; | ||
| 255 | my $hw_auto = $alu->tmnx_eth_auto($partial) || {}; | ||
| 256 | |||
| 257 | my %i_duplex_admin; | ||
| 258 | foreach my $if ( keys %$hw_duplex_admin ) { | ||
| 259 | my $duplex = $hw_duplex_admin->{$if}; | ||
| 260 | next unless defined $duplex; | ||
| 261 | next if $duplex eq 'notApplicable'; | ||
| 262 | my $auto = $hw_auto->{$if} || 'false'; | ||
| 263 | my ( $slot, $ifindex ) = split( /\./, $if ); | ||
| 264 | |||
| 265 | my $string = 'other'; | ||
| 266 | $string = 'half' | ||
| 267 | if ( $duplex =~ /half/i and $auto =~ /false/i ); | ||
| 268 | $string = 'full' | ||
| 269 | if ( $duplex =~ /full/i and $auto =~ /false/i ); | ||
| 270 | $string = 'auto' if $auto =~ /true/i; | ||
| 271 | |||
| 272 | $i_duplex_admin{$ifindex} = $string; | ||
| 273 | } | ||
| 274 | return \%i_duplex_admin; | ||
| 275 | } | ||
| 276 | |||
| 277 | sub agg_ports { | ||
| 278 | my $alu = shift; | ||
| 279 | |||
| 280 | return $alu->agg_ports_ifstack(); | ||
| 281 | } | ||
| 282 | |||
| 283 | sub _agg_ports_walked { return qw/ifStackStatus ifType/ } | ||
| 284 | |||
| 285 | sub fan { | ||
| 286 | my $alu = shift; | ||
| 287 | |||
| 288 | my $state = $alu->tmnx_fan_state() || {}; | ||
| 289 | |||
| 290 | if ( scalar keys %$state ) { | ||
| 291 | my @messages = (); | ||
| 292 | |||
| 293 | foreach my $k ( keys %$state ) { | ||
| 294 | next if $state->{$k} and $state->{$k} eq 'Ok'; | ||
| 295 | my ( $chassis, $fan ) = split( /\./, $k ); | ||
| 296 | push @messages, "Fan $fan, Chassis $chassis: $state->{$k}"; | ||
| 297 | } | ||
| 298 | |||
| 299 | push @messages, ( ( scalar keys %$state ) . " fans OK" ) | ||
| 300 | if scalar @messages == 0; | ||
| 301 | |||
| 302 | return ( join ", ", @messages ); | ||
| 303 | } | ||
| 304 | return; | ||
| 305 | } | ||
| 306 | |||
| 307 | sub ps1_status { | ||
| 308 | my $alu = shift; | ||
| 309 | |||
| 310 | my $pwr_state = $alu->tmnx_ps1_state() || {}; | ||
| 311 | |||
| 312 | my $ret = ""; | ||
| 313 | my $s = ""; | ||
| 314 | foreach my $i ( sort keys %$pwr_state ) { | ||
| 315 | my ( $chassis, $num ) = split( /\./, $i ); | ||
| 316 | $ret | ||
| 317 | .= $s | ||
| 318 | . "Chassis " | ||
| 319 | . $chassis . " PS " | ||
| 320 | . $num . ": " | ||
| 321 | . $pwr_state->{$i}; | ||
| 322 | $s = ", "; | ||
| 323 | } | ||
| 324 | return if ( $s eq "" ); | ||
| 325 | return $ret; | ||
| 326 | } | ||
| 327 | |||
| 328 | sub ps2_status { | ||
| 329 | my $alu = shift; | ||
| 330 | |||
| 331 | my $pwr_state = $alu->tmnx_ps2_state() || {}; | ||
| 332 | |||
| 333 | my $ret = ""; | ||
| 334 | my $s = ""; | ||
| 335 | foreach my $i ( sort keys %$pwr_state ) { | ||
| 336 | my ( $chassis, $num ) = split( /\./, $i ); | ||
| 337 | $ret | ||
| 338 | .= $s | ||
| 339 | . "Chassis " | ||
| 340 | . $chassis . " PS " | ||
| 341 | . $num . ": " | ||
| 342 | . $pwr_state->{$i}; | ||
| 343 | $s = ", "; | ||
| 344 | } | ||
| 345 | return if ( $s eq "" ); | ||
| 346 | return $ret; | ||
| 347 | } | ||
| 348 | |||
| 349 | sub e_index { | ||
| 350 | my $alu = shift; | ||
| 351 | my $partial = shift; | ||
| 352 | |||
| 353 | # Use MIB leaf to force load here | ||
| 354 | my $e_descr = $alu->tmnxHwID($partial); | ||
| 355 | |||
| 356 | return unless ( ref {} eq ref $e_descr and scalar keys %$e_descr ); | ||
| 357 | |||
| 358 | my %e_index; | ||
| 359 | |||
| 360 | # The iid is tmnxChassisIndex.tmnxHwIndex; tmnxHwContainedIn (e_parent) | ||
| 361 | # holds the bare tmnxHwIndex | ||
| 362 | foreach my $iid ( keys %$e_descr ) { | ||
| 363 | my ( undef, $hw_index ) = split /\./, $iid; | ||
| 364 | next unless defined $hw_index; | ||
| 365 | $e_index{$iid} = $hw_index; | ||
| 366 | } | ||
| 367 | return \%e_index; | ||
| 368 | } | ||
| 369 | |||
| 370 | sub munge_tmnx_state { | ||
| 371 | my $state = shift; | ||
| 372 | |||
| 373 | $state =~ s/deviceState//; | ||
| 374 | $state =~ s/device//; | ||
| 375 | return $state; | ||
| 376 | } | ||
| 377 | |||
| 378 | sub munge_tmnx_e_class { | ||
| 379 | my $class = shift; | ||
| 380 | |||
| 381 | if ($class eq 'physChassis') { | ||
| 382 | $class = 'chassis'; | ||
| 383 | } | ||
| 384 | elsif ($class =~ /Module/i) { | ||
| 385 | $class = 'module'; | ||
| 386 | } | ||
| 387 | return $class; | ||
| 388 | } | ||
| 389 | |||
| 390 | sub munge_tmnx_e_swver { | ||
| 391 | my $swver = shift; | ||
| 392 | |||
| 393 | if ( $swver =~ m/^TiMOS-(\S+)/x ) { | ||
| 394 | return $1; | ||
| 395 | } | ||
| 396 | return $swver; | ||
| 397 | } | ||
| 398 | |||
| 399 | 1; | ||
| 400 | __END__ |