| 1 | # SNMP::Info::Layer3::Ciena - SNMP Interface to Ciena Devices | ||
| 2 | # | ||
| 3 | # Copyright (c) 2019 by The Netdisco Developer Team. | ||
| 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 | |||
| 30 | package SNMP::Info::Layer3::Ciena; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::Layer3; | ||
| 36 | |||
| 37 | @SNMP::Info::Layer3::Ciena::ISA = qw/SNMP::Info::Layer3 Exporter/; | ||
| 38 | @SNMP::Info::Layer3::Ciena::EXPORT_OK = qw//; | ||
| 39 | |||
| 40 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 41 | |||
| 42 | $VERSION = '3.985003'; | ||
| 43 | |||
| 44 | %MIBS = ( | ||
| 45 | %SNMP::Info::Layer3::MIBS, | ||
| 46 | 'WWP-LEOS-SW-XGRADE-MIB' => 'wwpLeosBladeRunPackageVer', | ||
| 47 | 'WWP-LEOS-BLADE-MIB' => 'wwpLeosBladeId', | ||
| 48 | 'WWP-LEOS-CHASSIS-MIB' => 'wwpLeosChassisDeviceId', | ||
| 49 | 'WWP-LEOS-FLOW-MIB' => 'wwpLeosFlowLearnType', | ||
| 50 | 'WWP-LEOS-PORT-MIB' => 'wwpLeosEtherIngressPvid', | ||
| 51 | 'WWP-LEOS-VLAN-TAG-MIB' => 'wwpLeosNumVlans', | ||
| 52 | 'WWP-PRODUCTS-MIB' => 'wwpProductsMIB' | ||
| 53 | ); | ||
| 54 | |||
| 55 | %GLOBALS = ( | ||
| 56 | %SNMP::Info::Layer3::GLOBALS, | ||
| 57 | 'ciena_serial' => 'wwpLeosSystemSerialNumber', | ||
| 58 | 'mac' => 'dot1dBaseBridgeAddress' | ||
| 59 | ); | ||
| 60 | |||
| 61 | %FUNCS = ( | ||
| 62 | %SNMP::Info::Layer3::FUNCS, | ||
| 63 | 'v_name' => 'wwpLeosVlanName', | ||
| 64 | 'ps_type' => 'wwpLeosChassisPowerSupplyType', | ||
| 65 | 'ps_status' => 'wwpLeosChassisPowerSupplyState', | ||
| 66 | 'ps_name' => 'wwpLeosChassisPowerSupplyModuleLabel', | ||
| 67 | 'fan_type' => 'wwpLeosChassisFanModuleType', | ||
| 68 | 'fan_status' => 'wwpLeosChassisFanModuleStatus', | ||
| 69 | 'fan_name' => 'wwpLeosChassisFanModuleNum' | ||
| 70 | ); | ||
| 71 | |||
| 72 | %MUNGE = ( | ||
| 73 | %SNMP::Info::Layer3::MUNGE | ||
| 74 | ); | ||
| 75 | |||
| 76 | sub vendor { | ||
| 77 | return 'ciena'; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub os { | ||
| 81 | return 'saos'; | ||
| 82 | } | ||
| 83 | |||
| 84 | sub os_ver { | ||
| 85 | my $ciena = shift; | ||
| 86 | my $version = $ciena->wwpLeosBladeRunPackageVer || {}; | ||
| 87 | return values(%$version); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub serial { | ||
| 91 | my $ciena = shift; | ||
| 92 | return $ciena->ciena_serial(); | ||
| 93 | } | ||
| 94 | |||
| 95 | # The local LLDP port number is a bridge port, so translate it with bp_index. | ||
| 96 | # Translate the raw port from the index, never the parent's result, which | ||
| 97 | # may already be an ifIndex from the lldpLocPortDesc cross reference. | ||
| 98 | sub lldp_if { | ||
| 99 | my $ciena = shift; | ||
| 100 | my $partial = shift; | ||
| 101 | |||
| 102 | my $lldp = $ciena->SUPER::lldp_if($partial) || {}; | ||
| 103 | |||
| 104 | # LLDP-V2-MIB rows are keyed by ifIndex, not by bridge port | ||
| 105 | return $lldp if ( $ciena->_lldp_source() || '' ) eq 'v2'; | ||
| 106 | |||
| 107 | my $bp_index = $ciena->bp_index() || {}; | ||
| 108 | foreach my $key ( keys %$lldp ) { | ||
| 109 | my $port = ( split /\./x, $key )[1]; | ||
| 110 | next unless defined $port and defined $bp_index->{$port}; | ||
| 111 | $lldp->{$key} = $bp_index->{$port}; | ||
| 112 | } | ||
| 113 | return $lldp; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub i_vlan { | ||
| 117 | my $ciena = shift; | ||
| 118 | my $i_vlan = {}; | ||
| 119 | my $pvid = $ciena->wwpLeosEtherIngressPvid() || undef; | ||
| 120 | |||
| 121 | # bp_index needed to resolve correct port id | ||
| 122 | my $bp_index = $ciena->bp_index; | ||
| 123 | if (defined $pvid) { | ||
| 124 | foreach my $i (keys %$pvid) { | ||
| 125 | $i_vlan->{$bp_index->{$i}} = $pvid->{$i}; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | return $i_vlan; | ||
| 129 | } | ||
| 130 | |||
| 131 | sub i_vlan_membership { | ||
| 132 | my $ciena = shift; | ||
| 133 | my $i_vlan_membership = {}; | ||
| 134 | |||
| 135 | my $vlans = $ciena->wwpLeosVlanMemberPortId(); | ||
| 136 | # bp_index needed to resolve correct port id | ||
| 137 | my $bp_index = $ciena->bp_index; | ||
| 138 | foreach my $vlan (keys %$vlans) { | ||
| 139 | push @{$i_vlan_membership->{$bp_index->{$vlans->{$vlan}}}} , (split(/\./,$vlan))[0]; | ||
| 140 | } | ||
| 141 | return $i_vlan_membership; | ||
| 142 | } | ||
| 143 | |||
| 144 | sub qb_fw_vlan { | ||
| 145 | my $ciena = shift; | ||
| 146 | my $qb_fw_vlan = {}; | ||
| 147 | my $learn_entries = $ciena->wwpLeosFlowLearnType(); | ||
| 148 | foreach my $entry (keys %$learn_entries) { | ||
| 149 | my @params = (split(/\./, $entry)); | ||
| 150 | $qb_fw_vlan->{join('.', @params[1..6])} = $params[8]; | ||
| 151 | } | ||
| 152 | return $qb_fw_vlan; | ||
| 153 | } | ||
| 154 | |||
| 155 | sub fan { | ||
| 156 | my $ciena = shift; | ||
| 157 | |||
| 158 | my $fan_status = $ciena->fan_status || {}; | ||
| 159 | my $fan_type = $ciena->fan_type; | ||
| 160 | my $fan_name = $ciena->fan_name; | ||
| 161 | my @messages; | ||
| 162 | |||
| 163 | foreach my $fan (keys %$fan_status) { | ||
| 164 | if ($fan_status->{$fan} ne "ok") { | ||
| 165 | push @messages, sprintf("%s fan %s failed.", $fan_type->{$fan}, $fan_name->{$fan}); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | return sprintf("%s fans OK", scalar keys %$fan_status) if scalar @messages == 0; | ||
| 169 | |||
| 170 | return join(", ", @messages); | ||
| 171 | } | ||
| 172 | sub ps1_type { | ||
| 173 | my $ciena = shift; | ||
| 174 | my $ps_type = $ciena->ps_type; | ||
| 175 | return $ps_type->{'1'} if defined $ps_type->{'1'}; | ||
| 176 | } | ||
| 177 | |||
| 178 | sub ps1_status { | ||
| 179 | my $ciena = shift; | ||
| 180 | my $ps_status = $ciena->ps_status; | ||
| 181 | return $ps_status->{'1'} if defined $ps_status->{'1'}; | ||
| 182 | } | ||
| 183 | sub ps2_type { | ||
| 184 | my $ciena = shift; | ||
| 185 | my $ps_type = $ciena->ps_type; | ||
| 186 | return $ps_type->{'2'} if defined $ps_type->{'2'}; | ||
| 187 | } | ||
| 188 | |||
| 189 | sub ps2_status { | ||
| 190 | my $ciena = shift; | ||
| 191 | my $ps_status = $ciena->ps_status; | ||
| 192 | return $ps_status->{'2'} if defined $ps_status->{'2'}; | ||
| 193 | } | ||
| 194 | |||
| 195 | 1; | ||
| 196 | |||
| 197 | __END__ |