| 1 | # SNMP::Info::Layer3::Onyx | ||
| 2 | # | ||
| 3 | # Copyright (c) 2026 Hannes Eberhardt | ||
| 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::Onyx; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::Layer3; | ||
| 36 | use SNMP::Info::PortAccessEntity; | ||
| 37 | |||
| 38 | @SNMP::Info::Layer3::Onyx::ISA = qw/ | ||
| 39 | SNMP::Info::Layer3 | ||
| 40 | SNMP::Info::PortAccessEntity | ||
| 41 | Exporter | ||
| 42 | /; | ||
| 43 | @SNMP::Info::Layer3::Onyx::EXPORT_OK = qw//; | ||
| 44 | |||
| 45 | use vars qw/$VERSION %GLOBALS %MIBS %FUNCS %MUNGE/; | ||
| 46 | |||
| 47 | $VERSION = '3.985003'; | ||
| 48 | |||
| 49 | %MIBS = ( | ||
| 50 | %SNMP::Info::PortAccessEntity::MIBS, | ||
| 51 | %SNMP::Info::Layer3::MIBS, | ||
| 52 | ); | ||
| 53 | |||
| 54 | %GLOBALS = ( | ||
| 55 | %SNMP::Info::PortAccessEntity::GLOBALS, | ||
| 56 | %SNMP::Info::Layer3::GLOBALS, | ||
| 57 | 'mac' => 'dot1dBaseBridgeAddress', | ||
| 58 | ); | ||
| 59 | |||
| 60 | %FUNCS = ( | ||
| 61 | %SNMP::Info::PortAccessEntity::FUNCS, | ||
| 62 | %SNMP::Info::Layer3::FUNCS, | ||
| 63 | ); | ||
| 64 | |||
| 65 | %MUNGE = ( | ||
| 66 | %SNMP::Info::PortAccessEntity::MUNGE, | ||
| 67 | %SNMP::Info::Layer3::MUNGE, | ||
| 68 | 'mac' => \&SNMP::Info::munge_mac, | ||
| 69 | ); | ||
| 70 | |||
| 71 | # Onyx serves sysServices 72 (layers 4 and 7) despite its bridge and IP | ||
| 72 | # tables. Include layers 2 and 3 so callers collect forwarding and ARP data. | ||
| 73 | sub layers { | ||
| 74 | my $dev = shift; | ||
| 75 | |||
| 76 | my $layers = $dev->SUPER::layers() || '00000000'; | ||
| 77 | substr( $layers, 5, 2, '11' ); | ||
| 78 | return $layers; | ||
| 79 | } | ||
| 80 | |||
| 81 | sub vendor { return 'mellanox'; } | ||
| 82 | |||
| 83 | sub os { return 'onyx'; } | ||
| 84 | |||
| 85 | sub os_ver { | ||
| 86 | my $dev = shift; | ||
| 87 | my $descr = $dev->description(); | ||
| 88 | return unless defined $descr; | ||
| 89 | return $1 if $descr =~ /SWv([\d.]+)/; | ||
| 90 | return; | ||
| 91 | } | ||
| 92 | |||
| 93 | sub model { | ||
| 94 | my $dev = shift; | ||
| 95 | my $descr = $dev->description(); | ||
| 96 | return $1 if defined $descr && $descr =~ /^Onyx,\s*([^,]+),/; | ||
| 97 | return $dev->SUPER::model(); | ||
| 98 | } | ||
| 99 | |||
| 100 | # Onyx returns MAC chassis IDs as text rather than the six octets LLDP-MIB | ||
| 101 | # defines. Keep the common decoder for binary MACs and other ID types. | ||
| 102 | sub _lldp_id_string { | ||
| 103 | my ( $dev, $id, $type ) = @_; | ||
| 104 | |||
| 105 | return lc $id | ||
| 106 | if defined $id and defined $type and $type eq 'macAddress' | ||
| 107 | and $id =~ /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i; | ||
| 108 | return $dev->SUPER::_lldp_id_string( $id, $type ); | ||
| 109 | } | ||
| 110 | |||
| 111 | # lldpRemLocalPortNum is a bridge port number. A port with no bridge port | ||
| 112 | # row (a LAG member) is found by its lldpLocPortId, which Onyx sets to the | ||
| 113 | # ifName; a neighbor matching neither is left out rather than guessed | ||
| 114 | sub lldp_if { | ||
| 115 | my $dev = shift; | ||
| 116 | my $partial = shift; | ||
| 117 | |||
| 118 | return $dev->SUPER::lldp_if($partial) | ||
| 119 | if ( $dev->_lldp_source() || '' ) eq 'v2'; | ||
| 120 | |||
| 121 | my $id_type = $dev->_lldp_rem( 'lldp_rem_id_type', $partial ); | ||
| 122 | my $bp_index = $dev->bp_index() || {}; | ||
| 123 | my $lport_id = $dev->lldp_lport_id() || {}; | ||
| 124 | my %by_name = reverse %{ $dev->orig_i_name() || {} }; | ||
| 125 | |||
| 126 | my %if; | ||
| 127 | foreach my $key ( keys %$id_type ) { | ||
| 128 | my ( $time, $lport, $remote ) = split /\./, $key; | ||
| 129 | next unless defined $lport; | ||
| 130 | |||
| 131 | my $name = $lport_id->{$lport}; | ||
| 132 | my $ifindex = $bp_index->{$lport} | ||
| 133 | // ( defined $name ? $by_name{$name} : undef ); | ||
| 134 | next unless defined $ifindex; | ||
| 135 | |||
| 136 | $if{$key} = $ifindex; | ||
| 137 | } | ||
| 138 | return \%if; | ||
| 139 | } | ||
| 140 | |||
| 141 | # A neighbor with no management address gets 0.0.0.0, which the calling | ||
| 142 | # application looks up by c_id; an entry with no c_ip is dropped | ||
| 143 | sub c_ip { | ||
| 144 | my ( $dev, $partial, $topo_cap ) = @_; | ||
| 145 | |||
| 146 | $topo_cap ||= $dev->has_topo() || []; | ||
| 147 | my $c_ip = $dev->SUPER::c_ip( $partial, $topo_cap ) || {}; | ||
| 148 | return $c_ip unless grep { $_ eq 'lldp' } @$topo_cap; | ||
| 149 | |||
| 150 | my $id_type = $dev->_lldp_rem( 'lldp_rem_id_type', $partial ); | ||
| 151 | |||
| 152 | foreach my $key ( keys %$id_type ) { | ||
| 153 | $c_ip->{$key} = '0.0.0.0' unless defined $c_ip->{$key}; | ||
| 154 | } | ||
| 155 | |||
| 156 | return $c_ip; | ||
| 157 | } | ||
| 158 | |||
| 159 | 1; | ||
| 160 | |||
| 161 | __END__ |