| 1 | # SNMP::Info::Layer3::Maipu - SNMP interface to Maipu switches | ||
| 2 | # | ||
| 3 | # Copyright (c) 2026 by SNMP::Info Developers. | ||
| 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::Maipu; | ||
| 30 | |||
| 31 | use strict; | ||
| 32 | use warnings; | ||
| 33 | use Exporter; | ||
| 34 | use SNMP::Info::Layer3; | ||
| 35 | |||
| 36 | @SNMP::Info::Layer3::Maipu::ISA = qw/SNMP::Info::Layer3 Exporter/; | ||
| 37 | @SNMP::Info::Layer3::Maipu::EXPORT_OK = qw//; | ||
| 38 | |||
| 39 | our ( $VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE ); | ||
| 40 | |||
| 41 | $VERSION = '3.985005'; | ||
| 42 | |||
| 43 | %MIBS = (%SNMP::Info::Layer3::MIBS); | ||
| 44 | %GLOBALS = (%SNMP::Info::Layer3::GLOBALS); | ||
| 45 | %FUNCS = ( | ||
| 46 | %SNMP::Info::Layer3::FUNCS, | ||
| 47 | |||
| 48 | # netdisco-mibs has no Maipu MIB, so these are read by numeric OID. | ||
| 49 | # MAIPU-SYS-MIB::mpSysDeviceSerialNumber | ||
| 50 | 'mp_device_serial' => '.1.3.6.1.4.1.5651.3.600.14.1.1.2', | ||
| 51 | |||
| 52 | # MAIPU-SYS-MIB::mpSysPowerType | ||
| 53 | 'mp_power_type' => '.1.3.6.1.4.1.5651.3.600.7.1.1.2', | ||
| 54 | |||
| 55 | # MAIPU-SYS-MIB::mpSysPowerOnlineStatus | ||
| 56 | 'mp_power_online' => '.1.3.6.1.4.1.5651.3.600.7.1.1.8', | ||
| 57 | |||
| 58 | # MAIPU-SYS-MIB::mpSysPowerAlarmStatus | ||
| 59 | 'mp_power_alarm' => '.1.3.6.1.4.1.5651.3.600.7.1.1.10', | ||
| 60 | |||
| 61 | # MAIPU-SYS-MIB::mpSysFanCardOnlineStatus | ||
| 62 | 'mp_fan_online' => '.1.3.6.1.4.1.5651.3.600.8.1.1.7', | ||
| 63 | |||
| 64 | # MAIPU-SYS-MIB::mpSysFanCardAlarmStatus | ||
| 65 | 'mp_fan_alarm' => '.1.3.6.1.4.1.5651.3.600.8.1.1.9', | ||
| 66 | ); | ||
| 67 | %MUNGE = (%SNMP::Info::Layer3::MUNGE); | ||
| 68 | |||
| 69 | sub vendor { return 'maipu'; } | ||
| 70 | |||
| 71 | sub os { return 'mypower'; } | ||
| 72 | |||
| 73 | sub os_ver { | ||
| 74 | my $maipu = shift; | ||
| 75 | my $descr = $maipu->description() // ''; | ||
| 76 | |||
| 77 | return $1 if $descr =~ /\bversion\s+(\d+(?:\.\d+)+)/i; | ||
| 78 | return $maipu->SUPER::os_ver(); | ||
| 79 | } | ||
| 80 | |||
| 81 | sub model { | ||
| 82 | my $maipu = shift; | ||
| 83 | |||
| 84 | my $chassis_model = $maipu->_chassis_model(); | ||
| 85 | return $chassis_model if defined $chassis_model; | ||
| 86 | |||
| 87 | my $descr = $maipu->description() // ''; | ||
| 88 | return $1 if $descr =~ /\bMyPower\s+([A-Z][\w-]*\d[\w-]*)\s+version\b/i; | ||
| 89 | return $maipu->SUPER::model(); | ||
| 90 | } | ||
| 91 | |||
| 92 | # The S3230 names its model in the chassis entPhysicalDescr and leaves | ||
| 93 | # entPhysicalModelName empty. | ||
| 94 | sub _chassis_model { | ||
| 95 | my $maipu = shift; | ||
| 96 | |||
| 97 | my $e_class = $maipu->e_class() || {}; | ||
| 98 | my $e_model = $maipu->e_model() || {}; | ||
| 99 | my $e_descr = $maipu->e_descr() || {}; | ||
| 100 | foreach my $index ( sort { $a <=> $b } keys %$e_class ) { | ||
| 101 | next unless $e_class->{$index} eq 'chassis'; | ||
| 102 | foreach my $model ( $e_model->{$index}, $e_descr->{$index} ) { | ||
| 103 | return $model if defined $model and $model =~ /\S/; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | return; | ||
| 107 | } | ||
| 108 | |||
| 109 | # The S3230 serves sysServices 4, so add layer 2 when it has bridge ports. | ||
| 110 | sub layers { | ||
| 111 | my $maipu = shift; | ||
| 112 | |||
| 113 | my $layers = $maipu->SUPER::layers() || '00000100'; | ||
| 114 | substr( $layers, 6, 1, '1' ) if $maipu->b_ports(); | ||
| 115 | return $layers; | ||
| 116 | } | ||
| 117 | |||
| 118 | # The agent indexes dot1qTpFdbTable as FDB ID, a length octet 6, then the | ||
| 119 | # MAC, as if the MacAddress were a variable-length string. | ||
| 120 | sub qb_fw_mac { | ||
| 121 | my $maipu = shift; | ||
| 122 | my $partial = shift; | ||
| 123 | |||
| 124 | my $qb_fw_port = $maipu->qb_fw_port($partial) || {}; | ||
| 125 | my %qb_fw_mac; | ||
| 126 | foreach my $idx ( keys %$qb_fw_port ) { | ||
| 127 | my ( $fdb_id, @octets ) = split /\./, $idx; | ||
| 128 | shift @octets if @octets == 7 and $octets[0] == 6; | ||
| 129 | next unless @octets == 6; | ||
| 130 | $qb_fw_mac{$idx} = join ':', map { sprintf '%02x', $_ } @octets; | ||
| 131 | } | ||
| 132 | return \%qb_fw_mac; | ||
| 133 | } | ||
| 134 | |||
| 135 | # Forwarding entries learned on a link aggregation name its ifIndex as the | ||
| 136 | # bridge port, which dot1dBasePortTable leaves out. | ||
| 137 | sub bp_index { | ||
| 138 | my $maipu = shift; | ||
| 139 | my $partial = shift; | ||
| 140 | |||
| 141 | my $bp_index = $maipu->SUPER::bp_index($partial) || {}; | ||
| 142 | my $interfaces = $maipu->interfaces() || {}; | ||
| 143 | my %mapped = map { $_ => 1 } values %$bp_index; | ||
| 144 | my @iids = defined $partial ? ($partial) : keys %$interfaces; | ||
| 145 | foreach my $iid (@iids) { | ||
| 146 | next unless exists $interfaces->{$iid}; | ||
| 147 | next if exists $bp_index->{$iid} or $mapped{$iid}; | ||
| 148 | $bp_index->{$iid} = $iid; | ||
| 149 | } | ||
| 150 | return $bp_index; | ||
| 151 | } | ||
| 152 | |||
| 153 | # Net-SNMP translates enumerations only for values served as INTEGER, and | ||
| 154 | # the agent serves entPhysicalClass as a Gauge32. | ||
| 155 | sub e_class { | ||
| 156 | my $maipu = shift; | ||
| 157 | my $partial = shift; | ||
| 158 | |||
| 159 | my $e_class = $maipu->SUPER::e_class($partial) || {}; | ||
| 160 | my $oid = SNMP::translateObj( 'ENTITY-MIB::entPhysicalClass', 0, 1 ) | ||
| 161 | || ''; | ||
| 162 | my $enums | ||
| 163 | = ref {} eq ref $SNMP::MIB{$oid}{'enums'} | ||
| 164 | ? $SNMP::MIB{$oid}{'enums'} | ||
| 165 | : {}; | ||
| 166 | my %labels = reverse %$enums; | ||
| 167 | |||
| 168 | my %translated; | ||
| 169 | foreach my $index ( keys %$e_class ) { | ||
| 170 | my $class = $e_class->{$index}; | ||
| 171 | $translated{$index} | ||
| 172 | = defined $class && exists $labels{$class} | ||
| 173 | ? $labels{$class} | ||
| 174 | : $class; | ||
| 175 | } | ||
| 176 | return \%translated; | ||
| 177 | } | ||
| 178 | |||
| 179 | sub serial { | ||
| 180 | my $maipu = shift; | ||
| 181 | |||
| 182 | my $serials = $maipu->mp_device_serial() || {}; | ||
| 183 | foreach my $index ( sort { $a <=> $b } keys %$serials ) { | ||
| 184 | my $serial = $serials->{$index}; | ||
| 185 | return $serial if defined $serial and $serial =~ /\S/; | ||
| 186 | } | ||
| 187 | return $maipu->SUPER::serial(); | ||
| 188 | } | ||
| 189 | |||
| 190 | my %POWER_CURRENT = ( 1 => 'AC', 2 => 'DC', 3 => 'AC', 4 => 'DC' ); | ||
| 191 | |||
| 192 | # Status of the supply or fan at position $n, in index order. | ||
| 193 | sub _mp_status { | ||
| 194 | my ( $online, $alarm, $index ) = @_; | ||
| 195 | |||
| 196 | return 'offline' if ( $online->{$index} // 0 ) == 2; | ||
| 197 | my $state = $alarm->{$index} // 0; | ||
| 198 | return $state == 1 ? 'normal' : $state == 2 ? 'alarm' : undef; | ||
| 199 | } | ||
| 200 | |||
| 201 | sub _mp_power_index { | ||
| 202 | my ( $maipu, $n ) = @_; | ||
| 203 | |||
| 204 | my %indexes = map { %{ $maipu->$_() || {} } } | ||
| 205 | qw/mp_power_type mp_power_online mp_power_alarm/; | ||
| 206 | my @indexes = sort { $a <=> $b } keys %indexes; | ||
| 207 | return $indexes[ $n - 1 ]; | ||
| 208 | } | ||
| 209 | |||
| 210 | sub _mp_power_type { | ||
| 211 | my ( $maipu, $n ) = @_; | ||
| 212 | |||
| 213 | my $index = $maipu->_mp_power_index($n); | ||
| 214 | return unless defined $index; | ||
| 215 | my $types = $maipu->mp_power_type() || {}; | ||
| 216 | return $POWER_CURRENT{ $types->{$index} // '' }; | ||
| 217 | } | ||
| 218 | |||
| 219 | sub _mp_power_status { | ||
| 220 | my ( $maipu, $n ) = @_; | ||
| 221 | |||
| 222 | my $index = $maipu->_mp_power_index($n); | ||
| 223 | return unless defined $index; | ||
| 224 | return _mp_status( $maipu->mp_power_online() || {}, | ||
| 225 | $maipu->mp_power_alarm() || {}, $index ); | ||
| 226 | } | ||
| 227 | |||
| 228 | sub ps1_type { return $_[0]->_mp_power_type(1); } | ||
| 229 | sub ps2_type { return $_[0]->_mp_power_type(2); } | ||
| 230 | sub ps1_status { return $_[0]->_mp_power_status(1); } | ||
| 231 | sub ps2_status { return $_[0]->_mp_power_status(2); } | ||
| 232 | |||
| 233 | sub fan { | ||
| 234 | my $maipu = shift; | ||
| 235 | |||
| 236 | my $online = $maipu->mp_fan_online() || {}; | ||
| 237 | my $alarm = $maipu->mp_fan_alarm() || {}; | ||
| 238 | my @indexes = sort { $a <=> $b } keys %{ { %$online, %$alarm } }; | ||
| 239 | return unless @indexes; | ||
| 240 | |||
| 241 | my @faults; | ||
| 242 | foreach my $position ( 1 .. @indexes ) { | ||
| 243 | my $state = _mp_status( $online, $alarm, $indexes[ $position - 1 ] ) | ||
| 244 | // 'unknown'; | ||
| 245 | push @faults, "Fan $position: $state" unless $state eq 'normal'; | ||
| 246 | } | ||
| 247 | return @faults ? join( ', ', @faults ) : 'normal'; | ||
| 248 | } | ||
| 249 | |||
| 250 | # The agent serves no dot3adAggPortListPorts, so members come from the | ||
| 251 | # aggregator each port is attached to. | ||
| 252 | sub agg_ports { | ||
| 253 | my $maipu = shift; | ||
| 254 | |||
| 255 | my $attached = $maipu->lag_port_attached() || {}; | ||
| 256 | my $interfaces = $maipu->interfaces() || {}; | ||
| 257 | my %members; | ||
| 258 | foreach my $member ( keys %$attached ) { | ||
| 259 | my $aggregate = $attached->{$member}; | ||
| 260 | next unless defined $aggregate and $aggregate =~ /^\d+$/; | ||
| 261 | next if $aggregate == 0 or $member eq $aggregate; | ||
| 262 | next unless exists $interfaces->{$aggregate}; | ||
| 263 | $members{$member} = $aggregate; | ||
| 264 | } | ||
| 265 | return \%members if scalar keys %members; | ||
| 266 | return SNMP::Info::IEEE802dot3ad::agg_ports_lag( $maipu, @_ ); | ||
| 267 | } | ||
| 268 | |||
| 269 | sub _agg_ports_walked { | ||
| 270 | return qw/lag_port_attached ad_lag_ports bp_index/; | ||
| 271 | } | ||
| 272 | |||
| 273 | 1; | ||
| 274 | __END__ |