| 1 | # SNMP::Info::Layer3::Cisco | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Max Baker | ||
| 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::Cisco; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::CiscoBGP; | ||
| 36 | use SNMP::Info::CiscoVTP; | ||
| 37 | use SNMP::Info::CDP; | ||
| 38 | use SNMP::Info::CiscoStats; | ||
| 39 | use SNMP::Info::CiscoRTT; | ||
| 40 | use SNMP::Info::CiscoQOS; | ||
| 41 | use SNMP::Info::CiscoConfig; | ||
| 42 | use SNMP::Info::CiscoPower; | ||
| 43 | use SNMP::Info::CiscoStpExtensions; | ||
| 44 | use SNMP::Info::Layer3; | ||
| 45 | |||
| 46 | @SNMP::Info::Layer3::Cisco::ISA = qw/ | ||
| 47 | SNMP::Info::CiscoBGP | ||
| 48 | SNMP::Info::CiscoVTP | ||
| 49 | SNMP::Info::CDP | ||
| 50 | SNMP::Info::CiscoStats SNMP::Info::CiscoRTT | ||
| 51 | SNMP::Info::CiscoQOS SNMP::Info::CiscoConfig | ||
| 52 | SNMP::Info::CiscoPower SNMP::Info::CiscoStpExtensions | ||
| 53 | SNMP::Info::Layer3 | ||
| 54 | Exporter/; | ||
| 55 | @SNMP::Info::Layer3::Cisco::EXPORT_OK = qw//; | ||
| 56 | |||
| 57 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE); | ||
| 58 | |||
| 59 | $VERSION = '3.985003'; | ||
| 60 | |||
| 61 | %MIBS = ( | ||
| 62 | %SNMP::Info::Layer3::MIBS, | ||
| 63 | %SNMP::Info::CiscoBGP::MIBS, | ||
| 64 | %SNMP::Info::CiscoStpExtensions::MIBS, | ||
| 65 | %SNMP::Info::CiscoPower::MIBS, | ||
| 66 | %SNMP::Info::CiscoConfig::MIBS, | ||
| 67 | %SNMP::Info::CiscoQOS::MIBS, | ||
| 68 | %SNMP::Info::CiscoRTT::MIBS, | ||
| 69 | %SNMP::Info::CiscoStats::MIBS, | ||
| 70 | %SNMP::Info::CDP::MIBS, | ||
| 71 | %SNMP::Info::CiscoVTP::MIBS, | ||
| 72 | 'CISCO-EIGRP-MIB' => 'cEigrpAsRouterId', | ||
| 73 | 'CISCO-VRF-MIB' => 'cvVrfName', | ||
| 74 | ); | ||
| 75 | |||
| 76 | %GLOBALS = ( | ||
| 77 | %SNMP::Info::Layer3::GLOBALS, | ||
| 78 | %SNMP::Info::CiscoBGP::GLOBALS, | ||
| 79 | %SNMP::Info::CiscoStpExtensions::GLOBALS, | ||
| 80 | %SNMP::Info::CiscoPower::GLOBALS, | ||
| 81 | %SNMP::Info::CiscoConfig::GLOBALS, | ||
| 82 | %SNMP::Info::CiscoQOS::GLOBALS, | ||
| 83 | %SNMP::Info::CiscoRTT::GLOBALS, | ||
| 84 | %SNMP::Info::CiscoStats::GLOBALS, | ||
| 85 | %SNMP::Info::CDP::GLOBALS, | ||
| 86 | %SNMP::Info::CiscoVTP::GLOBALS, | ||
| 87 | 'eigrp_id' => 'cEigrpAsRouterId', | ||
| 88 | ); | ||
| 89 | |||
| 90 | %FUNCS = ( | ||
| 91 | %SNMP::Info::Layer3::FUNCS, | ||
| 92 | %SNMP::Info::CiscoBGP::FUNCS, | ||
| 93 | %SNMP::Info::CiscoStpExtensions::FUNCS, | ||
| 94 | %SNMP::Info::CiscoPower::FUNCS, | ||
| 95 | %SNMP::Info::CiscoConfig::FUNCS, | ||
| 96 | %SNMP::Info::CiscoQOS::FUNCS, | ||
| 97 | %SNMP::Info::CiscoRTT::FUNCS, | ||
| 98 | %SNMP::Info::CiscoStats::FUNCS, | ||
| 99 | %SNMP::Info::CDP::FUNCS, | ||
| 100 | %SNMP::Info::CiscoVTP::FUNCS, | ||
| 101 | |||
| 102 | # CISCO-EIGRP-MIB::cEigrpPeerTable | ||
| 103 | 'c_eigrp_peer_types' => 'cEigrpPeerAddrType', | ||
| 104 | 'c_eigrp_peers' => 'cEigrpPeerAddr', | ||
| 105 | |||
| 106 | # CISCO-VRF-MIB::cvVrfTable and cvVrfInterfaceTable | ||
| 107 | 'vrf_cv_name' => 'cvVrfName', | ||
| 108 | 'vrf_cv_if' => 'cvVrfInterfaceRowStatus', | ||
| 109 | ); | ||
| 110 | |||
| 111 | %MUNGE = ( | ||
| 112 | %SNMP::Info::Layer3::MUNGE, | ||
| 113 | %SNMP::Info::CiscoBGP::MUNGE, | ||
| 114 | %SNMP::Info::CiscoStpExtensions::MUNGE, | ||
| 115 | %SNMP::Info::CiscoPower::MUNGE, | ||
| 116 | %SNMP::Info::CiscoConfig::MUNGE, | ||
| 117 | %SNMP::Info::CiscoQOS::MUNGE, | ||
| 118 | %SNMP::Info::CiscoRTT::MUNGE, | ||
| 119 | %SNMP::Info::CiscoStats::MUNGE, | ||
| 120 | %SNMP::Info::CDP::MUNGE, | ||
| 121 | %SNMP::Info::CiscoVTP::MUNGE, | ||
| 122 | ); | ||
| 123 | |||
| 124 | |||
| 125 | # the i_vlan in SUPER is just fine; this exists to catch any dotted vlan | ||
| 126 | # subinterfaces not caught by CiscoVTP | ||
| 127 | sub i_vlan { | ||
| 128 | my $cisco = shift; | ||
| 129 | my $partial = shift; | ||
| 130 | |||
| 131 | my $i_type = $cisco->i_type($partial); | ||
| 132 | my $i_descr = $cisco->i_description($partial); | ||
| 133 | my $i_vlan = $cisco->SUPER::i_vlan($partial); | ||
| 134 | |||
| 135 | foreach my $idx ( keys %$i_descr ) { | ||
| 136 | next unless $i_type->{$idx}; | ||
| 137 | next unless (($i_type->{$idx} eq 'l2vlan' or $i_type->{$idx} eq '135') | ||
| 138 | and !defined $i_vlan->{$idx}); | ||
| 139 | |||
| 140 | # Not sure where this regex came from, anchored at end? | ||
| 141 | if ( $i_descr->{$idx} =~ /\.(\d+)$/ ) { | ||
| 142 | $i_vlan->{$idx} = $1; | ||
| 143 | } | ||
| 144 | |||
| 145 | # This matches 101 in 'Ethernet0.101-802.1Q vLAN subif' | ||
| 146 | elsif ( $i_descr->{$idx} =~ /\.(\d+)-/ ) { | ||
| 147 | $i_vlan->{$idx} = $1; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | return $i_vlan; | ||
| 151 | } | ||
| 152 | |||
| 153 | sub cisco_comm_indexing { | ||
| 154 | my $cisco = shift; | ||
| 155 | |||
| 156 | # If we get a VTP version, it's *extremely* likely that the device needs | ||
| 157 | # community based indexing | ||
| 158 | my $vtp = $cisco->vtp_version() || '0'; | ||
| 159 | return $vtp ? 1 : 0; | ||
| 160 | } | ||
| 161 | |||
| 162 | sub eigrp_peers { | ||
| 163 | my $cisco = shift; | ||
| 164 | |||
| 165 | my $peers = $cisco->c_eigrp_peers() || {}; | ||
| 166 | my $types = $cisco->c_eigrp_peer_types() || {}; | ||
| 167 | |||
| 168 | my %eigrp_peers; | ||
| 169 | foreach my $idx ( keys %$peers ) { | ||
| 170 | my $type = $types->{$idx}; | ||
| 171 | next unless $type; | ||
| 172 | my $peer = $peers->{$idx}; | ||
| 173 | next unless $peer; | ||
| 174 | |||
| 175 | my $ip = NetAddr::IP::Lite->new($peer); | ||
| 176 | |||
| 177 | if ($ip) { | ||
| 178 | $eigrp_peers{$idx} = $ip->addr; | ||
| 179 | } | ||
| 180 | elsif ( $type eq 'ipv4' ) { | ||
| 181 | $eigrp_peers{$idx} = SNMP::Info::munge_ip($peer); | ||
| 182 | } | ||
| 183 | next; | ||
| 184 | } | ||
| 185 | return \%eigrp_peers; | ||
| 186 | } | ||
| 187 | |||
| 188 | sub _vrf_subnets_from_routes { return 1; } | ||
| 189 | |||
| 190 | # CISCO-VRF-MIB lists the VRFs where MPLS-L3VPN-STD-MIB serves none. The | ||
| 191 | # index of cvVrfName is cvVrfIndex. Any row it serves lists default. | ||
| 192 | sub _vrf_vendor_instances { | ||
| 193 | my $cisco = shift; | ||
| 194 | |||
| 195 | my $names = $cisco->vrf_cv_name() || {}; | ||
| 196 | my %instances; | ||
| 197 | foreach my $name ( grep { defined && length } values %$names ) { | ||
| 198 | next if $name eq 'default'; | ||
| 199 | next if $cisco->_vrf_internal_instance($name); | ||
| 200 | my $record = SNMP::Info::VRF::_vrf_record( $name, 'vrf', 'device' ); | ||
| 201 | $record->{sources}{list} = 'CISCO-VRF-MIB'; | ||
| 202 | $instances{$name} = $record; | ||
| 203 | } | ||
| 204 | $cisco->_vrf_list_default( \%instances, 'CISCO-VRF-MIB' ) if %$names; | ||
| 205 | return \%instances; | ||
| 206 | } | ||
| 207 | |||
| 208 | sub _vrf_vendor_list_methods { return ( 'vrf_cv_name', 'vrf_cv_if' ); } | ||
| 209 | |||
| 210 | # The index of cvVrfInterfaceRowStatus is cvVrfIndex.ifIndex | ||
| 211 | sub _vrf_vendor_membership { | ||
| 212 | my $cisco = shift; | ||
| 213 | |||
| 214 | my $names = $cisco->vrf_cv_name() || {}; | ||
| 215 | my $rows = $cisco->vrf_cv_if() || {}; | ||
| 216 | my %ports; | ||
| 217 | foreach my $iid ( keys %$rows ) { | ||
| 218 | next unless $rows->{$iid} =~ /^(?:active|1)$/; | ||
| 219 | my ( $vrf_index, $ifindex, @extra ) = split /\./, $iid; | ||
| 220 | next if !defined $ifindex or @extra; | ||
| 221 | my $name = $names->{$vrf_index}; | ||
| 222 | next if !defined $name or !length $name or $name eq 'default'; | ||
| 223 | next if $cisco->_vrf_internal_instance($name); | ||
| 224 | $ports{$ifindex} = $name; | ||
| 225 | } | ||
| 226 | return \%ports; | ||
| 227 | } | ||
| 228 | |||
| 229 | 1; | ||
| 230 | __END__ |