| 1 | # SNMP::Info::Layer3::Cumulus | ||
| 2 | # | ||
| 3 | # Copyright (c) 2018 Bill Fenner and Oliver Gorwits | ||
| 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::Cumulus; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::Layer3; | ||
| 36 | use SNMP::Info::IEEE802dot3ad 'agg_ports_lag'; | ||
| 37 | |||
| 38 | @SNMP::Info::Layer3::Cumulus::ISA = qw/ | ||
| 39 | SNMP::Info::IEEE802dot3ad | ||
| 40 | SNMP::Info::Layer3 | ||
| 41 | Exporter | ||
| 42 | /; | ||
| 43 | @SNMP::Info::Layer3::Cumulus::EXPORT_OK = qw/ agg_ports /; | ||
| 44 | |||
| 45 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 46 | |||
| 47 | $VERSION = '3.985003'; | ||
| 48 | |||
| 49 | %MIBS = ( | ||
| 50 | %SNMP::Info::Layer3::MIBS, | ||
| 51 | %SNMP::Info::IEEE802dot3ad::MIBS, | ||
| 52 | 'UCD-SNMP-MIB' => 'versionTag', | ||
| 53 | 'NET-SNMP-TC' => 'netSnmpAliasDomain', | ||
| 54 | 'HOST-RESOURCES-MIB' => 'hrSystem', | ||
| 55 | ); | ||
| 56 | |||
| 57 | %GLOBALS = ( | ||
| 58 | %SNMP::Info::Layer3::GLOBALS, | ||
| 59 | 'netsnmp_vers' => 'versionTag', | ||
| 60 | 'hrSystemUptime' => 'hrSystemUptime', | ||
| 61 | 'chassis' => 'entPhysicalDescr.1', | ||
| 62 | ); | ||
| 63 | |||
| 64 | %FUNCS = ( | ||
| 65 | %SNMP::Info::Layer3::FUNCS, | ||
| 66 | %SNMP::Info::IEEE802dot3ad::FUNCS, | ||
| 67 | ); | ||
| 68 | |||
| 69 | %MUNGE = ( | ||
| 70 | %SNMP::Info::Layer3::MUNGE, | ||
| 71 | %SNMP::Info::IEEE802dot3ad::MUNGE, | ||
| 72 | ); | ||
| 73 | |||
| 74 | sub vendor { return 'cumulus networks' } | ||
| 75 | |||
| 76 | sub os { return 'cumulus' } | ||
| 77 | |||
| 78 | sub os_ver { | ||
| 79 | my $netsnmp = shift; | ||
| 80 | my $descr = $netsnmp->description(); | ||
| 81 | |||
| 82 | # STRING: "Cumulus Linux version 3.5.1 running on innotek GmbH VirtualBox" | ||
| 83 | # STRING: "Cumulus-Linux 4.1.1 (Linux Kernel 4.19.94-1+cl4u3)" | ||
| 84 | return $1 if ( defined ($descr) && $descr =~ /^Cumulus(?: |-)Linux.+(\d+\.\d+\.\d+)\s/ ); | ||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub model { | ||
| 89 | my $netsnmp = shift; | ||
| 90 | my $chassis = $netsnmp->chassis(); | ||
| 91 | |||
| 92 | # STRING: "Cumulus Networks VX Chassis" | ||
| 93 | if (defined ($chassis)) { | ||
| 94 | return $1 if ($chassis =~ /^Cumulus Networks\s+(.+)/); | ||
| 95 | } | ||
| 96 | return $netsnmp->SUPER::model(); | ||
| 97 | } | ||
| 98 | |||
| 99 | # sysUptime gives us the time since the SNMP daemon has restarted, | ||
| 100 | # so return the system uptime since that's probably what the user | ||
| 101 | # wants. (Caution: this could cause trouble if using | ||
| 102 | # sysUptime-based discontinuity timers or other TimeStamp | ||
| 103 | # objects. | ||
| 104 | sub uptime { | ||
| 105 | my $netsnmp = shift; | ||
| 106 | my $uptime; | ||
| 107 | |||
| 108 | $uptime = $netsnmp->hrSystemUptime(); | ||
| 109 | return $uptime if defined $uptime; | ||
| 110 | |||
| 111 | return $netsnmp->SUPER::uptime(); | ||
| 112 | } | ||
| 113 | |||
| 114 | # ifDescr is the same for all interfaces in a class, but the ifName is | ||
| 115 | # unique, so let's use that for port name. If all else fails, | ||
| 116 | # concatenate ifDesc and ifIndex. | ||
| 117 | # (code from SNMP/Info/Layer2/Netgear.pm) | ||
| 118 | sub interfaces { | ||
| 119 | my $netsnmp = shift; | ||
| 120 | my $partial = shift; | ||
| 121 | |||
| 122 | my $interfaces = $netsnmp->i_index($partial) || {}; | ||
| 123 | my $i_descr = $netsnmp->i_description($partial) || {}; | ||
| 124 | my $i_name = $netsnmp->i_name($partial); | ||
| 125 | my $i_isset = (); | ||
| 126 | # Replace the description with the ifName field, if set | ||
| 127 | foreach my $iid ( keys %$i_name ) { | ||
| 128 | my $name = $i_name->{$iid}; | ||
| 129 | next unless defined $name; | ||
| 130 | if (defined $name and $name !~ /^\s*$/) { | ||
| 131 | $interfaces->{$iid} = $name; | ||
| 132 | $i_isset->{$iid} = 1; | ||
| 133 | } | ||
| 134 | } | ||
| 135 | # Replace the Index with the ifDescr field, appended with index | ||
| 136 | # number, to deal with devices with non-unique ifDescr. | ||
| 137 | foreach my $iid ( keys %$i_descr ) { | ||
| 138 | my $port = $i_descr->{$iid} . '-' . $iid; | ||
| 139 | next unless defined $port; | ||
| 140 | next if (defined $i_isset->{$iid} and $i_isset->{$iid} == 1); | ||
| 141 | $interfaces->{$iid} = $port; | ||
| 142 | } | ||
| 143 | |||
| 144 | return $interfaces; | ||
| 145 | } | ||
| 146 | |||
| 147 | sub i_ignore { | ||
| 148 | my $l3 = shift; | ||
| 149 | my $partial = shift; | ||
| 150 | |||
| 151 | my $interfaces = $l3->interfaces($partial) || {}; | ||
| 152 | |||
| 153 | my %i_ignore; | ||
| 154 | foreach my $if ( keys %$interfaces ) { | ||
| 155 | |||
| 156 | # vlan1@br0 or peerlink.4094@peerlink | ||
| 157 | if ( $interfaces->{$if} =~ /@/i ) { | ||
| 158 | $i_ignore{$if}++; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | return \%i_ignore; | ||
| 162 | } | ||
| 163 | |||
| 164 | sub agg_ports { return agg_ports_lag(@_) } | ||
| 165 | |||
| 166 | sub _agg_ports_walked { return qw/ad_lag_ports bp_index/ } | ||
| 167 | |||
| 168 | 1; | ||
| 169 | __END__ |