| 1 | # SNMP::Info::Layer3::ArubaCX | ||
| 2 | # | ||
| 3 | # Copyright (c) 2021 Jeroen van Ingen | ||
| 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::ArubaCX; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::IEEE802dot3ad 'agg_ports_lag'; | ||
| 36 | use SNMP::Info::Layer3; | ||
| 37 | use SNMP::Info::IEEE802_Bridge; | ||
| 38 | |||
| 39 | @SNMP::Info::Layer3::ArubaCX::ISA = qw/ | ||
| 40 | SNMP::Info::IEEE802dot3ad | ||
| 41 | SNMP::Info::Layer3 | ||
| 42 | SNMP::Info::IEEE802_Bridge | ||
| 43 | Exporter | ||
| 44 | /; | ||
| 45 | @SNMP::Info::Layer3::ArubaCX::EXPORT_OK = qw/ | ||
| 46 | agg_ports | ||
| 47 | /; | ||
| 48 | |||
| 49 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MODEL_MAP, %MUNGE); | ||
| 50 | |||
| 51 | $VERSION = '3.985003'; | ||
| 52 | |||
| 53 | %MIBS = ( | ||
| 54 | %SNMP::Info::Layer3::MIBS, | ||
| 55 | %SNMP::Info::IEEE802dot3ad::MIBS, | ||
| 56 | %SNMP::Info::IEEE802_Bridge::MIBS, | ||
| 57 | 'ARUBAWIRED-CIPT-MIB' => 'arubaWiredCiptClientIpAddress', | ||
| 58 | 'ARUBAWIRED-FAN-MIB' => 'arubaWiredFanName', | ||
| 59 | 'ARUBAWIRED-VSF-MIB' => 'arubaWiredVsfTrapEnable', | ||
| 60 | 'ARUBAWIRED-POE-MIB' => 'arubaWiredPoePethPsePortAveragePower', | ||
| 61 | 'ARUBAWIRED-POWERSUPPLY-MIB' => 'arubaWiredPSUName', | ||
| 62 | 'ARUBAWIRED-PM-MIB' => 'arubaWiredPmXcvrDescription', | ||
| 63 | ); | ||
| 64 | |||
| 65 | %GLOBALS = ( | ||
| 66 | %SNMP::Info::Layer3::GLOBALS, | ||
| 67 | %SNMP::Info::IEEE802_Bridge::GLOBALS, | ||
| 68 | 'ps1_type' => 'arubaWiredPSUProductName.1.1', | ||
| 69 | 'ps2_type' => 'arubaWiredPSUProductName.1.2', | ||
| 70 | 'ps1_status' => 'arubaWiredPSUState.1.1', | ||
| 71 | 'ps2_status' => 'arubaWiredPSUState.1.2', | ||
| 72 | 'vsf_topology' => 'arubaWiredVsfTopology', | ||
| 73 | ); | ||
| 74 | |||
| 75 | %FUNCS = ( | ||
| 76 | %SNMP::Info::Layer3::FUNCS, | ||
| 77 | %SNMP::Info::IEEE802dot3ad::FUNCS, | ||
| 78 | %SNMP::Info::IEEE802_Bridge::FUNCS, | ||
| 79 | 'peth_port_power' => 'arubaWiredPoePethPsePortAveragePower', | ||
| 80 | 'fan_names' => 'arubaWiredFanName', | ||
| 81 | 'fan_states' => 'arubaWiredFanState', | ||
| 82 | 'psu_names' => 'arubaWiredPSUName', | ||
| 83 | 'psu_types' => 'arubaWiredPSUProductName', | ||
| 84 | 'psu_states' => 'arubaWiredPSUState', | ||
| 85 | 'vsf_prod_names' => 'arubaWiredVsfMemberProductName', | ||
| 86 | 'cipt_addr_type' => 'arubaWiredCiptClientIpAddrType', | ||
| 87 | 'cipt_addr' => 'arubaWiredCiptClientIpAddress', | ||
| 88 | 'cipt_ifindex' => 'arubaWiredCiptClientPortIfIndex', | ||
| 89 | 'raw_ad_lag_ports' => 'dot3adAggPortListPorts', # unmunged raw data | ||
| 90 | 'pm_xcvr_port' => 'arubaWiredPmXcvrPortDesc', | ||
| 91 | 'pm_xcvr_descr' => 'arubaWiredPmXcvrDescription', | ||
| 92 | 'pm_xcvr_product' => 'arubaWiredPmXcvrProductNum', | ||
| 93 | 'pm_xcvr_serial' => 'arubaWiredPmXcvrSerialNum', | ||
| 94 | 'pm_xcvr_type' => 'arubaWiredPmXcvrType', | ||
| 95 | ); | ||
| 96 | |||
| 97 | %MUNGE = ( | ||
| 98 | %SNMP::Info::Layer3::MUNGE, | ||
| 99 | %SNMP::Info::IEEE802dot3ad::MUNGE, | ||
| 100 | %SNMP::Info::IEEE802_Bridge::MUNGE, | ||
| 101 | ); | ||
| 102 | |||
| 103 | # Product codes reported by ENTITY-MIB or the product OID. | ||
| 104 | %MODEL_MAP = ( | ||
| 105 | 'JL719C' => '8360-48Y6C v2', | ||
| 106 | ); | ||
| 107 | |||
| 108 | sub _at_pbb_one { | ||
| 109 | my $in = shift // {}; | ||
| 110 | my $ret = {}; | ||
| 111 | foreach my $key (keys %$in) { | ||
| 112 | if ($key =~ /^1\.(\d+)$/) { | ||
| 113 | $ret->{$1} = $in->{$key}; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | return $ret; | ||
| 117 | } | ||
| 118 | |||
| 119 | sub fan { | ||
| 120 | my $cx = shift; | ||
| 121 | my $names = $cx->fan_names() || {}; | ||
| 122 | my $states = $cx->fan_states() || {}; | ||
| 123 | my @ary = (); | ||
| 124 | foreach my $idx (sort keys %$names) { | ||
| 125 | my $name = $names->{$idx} // 'n/a'; | ||
| 126 | my $state = $states->{$idx} // 'n/a'; | ||
| 127 | push @ary, sprintf("%s: %s", $name, $state); | ||
| 128 | } | ||
| 129 | return join (', ', @ary); | ||
| 130 | } | ||
| 131 | |||
| 132 | sub vendor { | ||
| 133 | my $cx = shift; | ||
| 134 | my $mfg = $cx->entPhysicalMfgName(1) || {}; | ||
| 135 | my $vendor = $mfg->{1} || "aruba"; | ||
| 136 | return lc($vendor); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub mac { | ||
| 140 | my $cx = shift; | ||
| 141 | my $b_mac = $cx->b_mac(); | ||
| 142 | return $b_mac if defined $b_mac and $b_mac !~ /^[0:]+$/; | ||
| 143 | return $cx->orig_mac(); | ||
| 144 | } | ||
| 145 | |||
| 146 | sub stack_info { | ||
| 147 | my $cx = shift; | ||
| 148 | my $vsf_topo = $cx->vsf_topology(); | ||
| 149 | if (defined $vsf_topo and $vsf_topo ne 'standalone') { | ||
| 150 | my $member_prod_names = $cx->vsf_prod_names() || {}; | ||
| 151 | my $num_members = scalar keys %$member_prod_names; | ||
| 152 | my $fullname = (values %$member_prod_names)[0]; | ||
| 153 | my $modelname = ''; | ||
| 154 | if ($fullname =~ /^(\S+)/) { | ||
| 155 | $modelname = $1; | ||
| 156 | } | ||
| 157 | return sprintf("%s (stack of %d)", $modelname, $num_members); | ||
| 158 | } else { | ||
| 159 | return; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | sub model { | ||
| 164 | my $cx = shift; | ||
| 165 | my $model = $cx->entPhysicalModelName(1) || {}; | ||
| 166 | my $id = $cx->id(); | ||
| 167 | my $translated_id = &SNMP::translateObj($id) || $id; | ||
| 168 | $translated_id =~ s/arubaWiredSwitch//i; | ||
| 169 | my $name = $cx->stack_info() || $model->{1} || $translated_id; | ||
| 170 | return defined $MODEL_MAP{$name} ? $MODEL_MAP{$name} : $name; | ||
| 171 | } | ||
| 172 | |||
| 173 | # Keep client tracking rows separate from the standard neighbour-table indexes. | ||
| 174 | # InetAddress is an OCTET STRING; check its length against the address type. | ||
| 175 | sub _cipt_clients { | ||
| 176 | my ($cx, $family, $partial) = @_; | ||
| 177 | my $types = $cx->cipt_addr_type() || {}; | ||
| 178 | my $addrs = $cx->cipt_addr() || {}; | ||
| 179 | my $ports = $cx->cipt_ifindex() || {}; | ||
| 180 | my %clients; | ||
| 181 | foreach my $idx (keys %$types) { | ||
| 182 | my $type = $types->{$idx}; | ||
| 183 | next unless defined $type; | ||
| 184 | next unless ($family == 1 && ($type eq '1' || $type eq 'ipv4')) | ||
| 185 | || ($family == 2 && ($type eq '2' || $type eq 'ipv6')); | ||
| 186 | next unless $idx =~ /^6\.((?:\d+\.){5}\d+)\.(\d+)\.(\d+)$/; | ||
| 187 | my ($mac_index, $vlan, $ip_index) = ($1, $2, $3); | ||
| 188 | my @mac = split /\./, $mac_index; | ||
| 189 | next if grep { $_ > 255 } @mac; | ||
| 190 | next if ($mac[0] & 1) || !grep { $_ } @mac; | ||
| 191 | next unless $vlan >= 1 && $vlan <= 4094 && $ip_index > 0; | ||
| 192 | my $addr = $addrs->{$idx}; | ||
| 193 | next unless defined $addr && length($addr) == ($family == 1 ? 4 : 16); | ||
| 194 | my $port = $ports->{$idx}; | ||
| 195 | next unless defined $port && $port =~ /^\d+$/ && $port > 0; | ||
| 196 | my $row = "cipt.$idx"; | ||
| 197 | next if defined $partial && $row !~ /^\Q$partial\E(?:\.|$)/; | ||
| 198 | $clients{$row} = { | ||
| 199 | mac => join(':', map { sprintf '%02x', $_ } @mac), | ||
| 200 | addr => SNMP::Info::munge_inetaddress($addr), | ||
| 201 | port => $port, | ||
| 202 | }; | ||
| 203 | } | ||
| 204 | return \%clients; | ||
| 205 | } | ||
| 206 | |||
| 207 | sub _cipt_merge { | ||
| 208 | my ($cx, $base, $family, $field, $partial) = @_; | ||
| 209 | my %result = %{ $base || {} }; | ||
| 210 | my $clients = $cx->_cipt_clients($family, $partial); | ||
| 211 | $result{$_} = $clients->{$_}{$field} for keys %$clients; | ||
| 212 | return \%result; | ||
| 213 | } | ||
| 214 | |||
| 215 | sub at_paddr { | ||
| 216 | my ($cx, $partial) = @_; | ||
| 217 | return $cx->_cipt_merge($cx->SUPER::at_paddr($partial), 1, 'mac', $partial); | ||
| 218 | } | ||
| 219 | |||
| 220 | sub at_netaddr { | ||
| 221 | my ($cx, $partial) = @_; | ||
| 222 | return $cx->_cipt_merge($cx->SUPER::at_netaddr($partial), 1, 'addr', $partial); | ||
| 223 | } | ||
| 224 | |||
| 225 | sub ipv6_n2p_mac { | ||
| 226 | my ($cx, $partial) = @_; | ||
| 227 | return $cx->_cipt_merge($cx->SUPER::ipv6_n2p_mac(), 2, 'mac', $partial); | ||
| 228 | } | ||
| 229 | |||
| 230 | sub ipv6_n2p_addr { | ||
| 231 | my ($cx, $partial) = @_; | ||
| 232 | return $cx->_cipt_merge($cx->SUPER::ipv6_n2p_addr(), 2, 'addr', $partial); | ||
| 233 | } | ||
| 234 | |||
| 235 | sub ipv6_n2p_if { | ||
| 236 | my ($cx, $partial) = @_; | ||
| 237 | return $cx->_cipt_merge($cx->SUPER::ipv6_n2p_if(), 2, 'port', $partial); | ||
| 238 | } | ||
| 239 | |||
| 240 | # Transceivers are absent from ENTITY-MIB; add one module row per | ||
| 241 | # arubaWiredPmXcvrTable row, indexed above any real entPhysicalIndex. | ||
| 242 | my $XCVR_BASE = 1_000_000_000; | ||
| 243 | |||
| 244 | sub _xcvr_entities { | ||
| 245 | my $cx = shift; | ||
| 246 | my $descr = $cx->pm_xcvr_descr() || {}; | ||
| 247 | return {} unless %$descr; | ||
| 248 | my $real = $cx->SUPER::e_index() || {}; | ||
| 249 | my $class = $cx->SUPER::e_class() || {}; | ||
| 250 | my $name = $cx->SUPER::e_name() || {}; | ||
| 251 | my $port = $cx->pm_xcvr_port() || {}; | ||
| 252 | my $product = $cx->pm_xcvr_product() || {}; | ||
| 253 | my $serial = $cx->pm_xcvr_serial() || {}; | ||
| 254 | my $type = $cx->pm_xcvr_type() || {}; | ||
| 255 | my ($chassis) = sort { $a <=> $b } | ||
| 256 | grep { ($class->{$_} // '') eq 'chassis' } keys %$class; | ||
| 257 | my %port_entity = map { $name->{$_} => $_ } | ||
| 258 | grep { ($class->{$_} // '') eq 'port' && defined $name->{$_} } | ||
| 259 | keys %$class; | ||
| 260 | my %rows; | ||
| 261 | foreach my $ifindex (grep { /^\d+$/ } keys %$descr) { | ||
| 262 | my $idx = $XCVR_BASE + $ifindex; | ||
| 263 | next if exists $real->{$idx}; | ||
| 264 | my $port_name = $port->{$ifindex} // $ifindex; | ||
| 265 | $rows{$idx} = { | ||
| 266 | e_index => $idx, | ||
| 267 | e_class => 'module', | ||
| 268 | e_descr => $descr->{$ifindex}, | ||
| 269 | e_name => "Transceiver $port_name", | ||
| 270 | e_model => $product->{$ifindex}, | ||
| 271 | e_serial => $serial->{$ifindex}, | ||
| 272 | e_type => $type->{$ifindex}, | ||
| 273 | e_fru => 'true', | ||
| 274 | e_parent => $port_entity{$port_name} // $chassis // 0, | ||
| 275 | }; | ||
| 276 | } | ||
| 277 | return \%rows; | ||
| 278 | } | ||
| 279 | |||
| 280 | sub _xcvr_merge { | ||
| 281 | my ($cx, $method, $partial) = @_; | ||
| 282 | my $super = "SUPER::$method"; | ||
| 283 | return $cx->$super($partial) if defined $partial; | ||
| 284 | my $rows = $cx->_xcvr_entities(); | ||
| 285 | return $cx->$super() unless %$rows; | ||
| 286 | my $base = $cx->$super(); | ||
| 287 | my %result = %{ $base || {} }; | ||
| 288 | $result{$_} = $rows->{$_}{$method} for keys %$rows; | ||
| 289 | return \%result; | ||
| 290 | } | ||
| 291 | |||
| 292 | sub e_index { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_index', $p) } | ||
| 293 | sub e_class { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_class', $p) } | ||
| 294 | sub e_descr { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_descr', $p) } | ||
| 295 | sub e_name { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_name', $p) } | ||
| 296 | sub e_model { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_model', $p) } | ||
| 297 | sub e_serial { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_serial', $p) } | ||
| 298 | sub e_type { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_type', $p) } | ||
| 299 | sub e_fru { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_fru', $p) } | ||
| 300 | sub e_parent { my ($cx, $p) = @_; return $cx->_xcvr_merge('e_parent', $p) } | ||
| 301 | |||
| 302 | sub os { | ||
| 303 | return "arubaos-cx"; | ||
| 304 | } | ||
| 305 | |||
| 306 | sub os_ver { | ||
| 307 | my $cx = shift; | ||
| 308 | my $ver_release = $cx->entPhysicalSoftwareRev(1) || {}; | ||
| 309 | return $ver_release->{1}; | ||
| 310 | } | ||
| 311 | |||
| 312 | # agg_ports should return a hash with | ||
| 313 | # ifindex of member -> ifindex of aggregation | ||
| 314 | # | ||
| 315 | # arabuaos-cx has a broken implementation of | ||
| 316 | # dot3adAggPortListPorts / 1.2.840.10006.300.43.1.1.2.1.1 | ||
| 317 | # it return a comma seperated String with interface names | ||
| 318 | # (rfc states a PortList / bitmask of member ports) | ||
| 319 | # | ||
| 320 | # fetch value, split at comma, reverse search the interface hash | ||
| 321 | # for the interface index | ||
| 322 | |||
| 323 | sub agg_ports { | ||
| 324 | my $cx = shift; | ||
| 325 | my $ret = {}; | ||
| 326 | my $ports = $cx->raw_ad_lag_ports(); | ||
| 327 | my $interfaces = $cx->interfaces(); | ||
| 328 | foreach my $m ( keys %$ports ) { | ||
| 329 | my $idx = $m; | ||
| 330 | my $portlist = $ports->{$m}; | ||
| 331 | next unless $portlist; | ||
| 332 | |||
| 333 | foreach my $ifname ( split(/,/, $portlist) ) { | ||
| 334 | foreach my $ifindex ( keys %$interfaces) { | ||
| 335 | if ($interfaces->{$ifindex} eq $ifname) { | ||
| 336 | $ret->{$ifindex} = $idx; | ||
| 337 | } | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | return $ret; | ||
| 342 | } | ||
| 343 | |||
| 344 | sub _agg_ports_walked { return qw/raw_ad_lag_ports/ } | ||
| 345 | |||
| 346 | # Overrides for VLAN & forwarding table methods | ||
| 347 | sub v_name { | ||
| 348 | my $cx = shift; | ||
| 349 | return _at_pbb_one($cx->iqb_v_name()) || $cx->SUPER::v_name(); | ||
| 350 | } | ||
| 351 | sub qb_i_vlan { | ||
| 352 | my $cx = shift; | ||
| 353 | return _at_pbb_one($cx->iqb_i_vlan()) || $cx->SUPER::qb_i_vlan(); | ||
| 354 | } | ||
| 355 | sub i_vlan_type { | ||
| 356 | my $cx = shift; | ||
| 357 | return _at_pbb_one($cx->iqb_i_vlan_type()) || $cx->SUPER::qb_i_vlan_type(); | ||
| 358 | } | ||
| 359 | sub qb_v_egress { | ||
| 360 | my $cx = shift; | ||
| 361 | return $cx->iqb_v_egress() || $cx->SUPER::qb_v_egress(); | ||
| 362 | } | ||
| 363 | sub qb_cv_egress { | ||
| 364 | my $cx = shift; | ||
| 365 | return $cx->iqb_cv_egress() || $cx->SUPER::qb_cv_egress(); | ||
| 366 | } | ||
| 367 | sub qb_v_untagged { | ||
| 368 | my $cx = shift; | ||
| 369 | return $cx->iqb_v_untagged() || $cx->SUPER::qb_v_untagged(); | ||
| 370 | } | ||
| 371 | sub qb_cv_untagged { | ||
| 372 | my $cx = shift; | ||
| 373 | return $cx->iqb_cv_untagged() || $cx->SUPER::qb_cv_untagged(); | ||
| 374 | } | ||
| 375 | |||
| 376 | 1; | ||
| 377 | __END__ |