| 1 | # SNMP::Info::CiscoBGP | ||
| 2 | # | ||
| 3 | # Copyright (c) 2022 Alexander Hartmaier | ||
| 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::CiscoBGP; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info; | ||
| 36 | |||
| 37 | @SNMP::Info::CiscoBGP::ISA = qw( SNMP::Info Exporter ); | ||
| 38 | @SNMP::Info::CiscoBGP::EXPORT_OK = qw( | ||
| 39 | parse_cisco_bgp_peer2_entry_index | ||
| 40 | ); | ||
| 41 | |||
| 42 | our ($VERSION, %MIBS, %FUNCS, %GLOBALS, %MUNGE); | ||
| 43 | |||
| 44 | $VERSION = '3.985003'; | ||
| 45 | |||
| 46 | %MIBS = ( 'CISCO-BGP4-MIB' => 'cbgpPeer2State', ); | ||
| 47 | |||
| 48 | %GLOBALS = (); | ||
| 49 | |||
| 50 | %FUNCS = ( | ||
| 51 | # cbgpPeer2Table | ||
| 52 | 'cisco_bgp_peer2_state' => 'cbgpPeer2State', | ||
| 53 | 'cisco_bgp_peer2_adminstatus' => 'cbgpPeer2AdminStatus', | ||
| 54 | 'cisco_bgp_peer2_localaddr' => 'cbgpPeer2LocalAddr', | ||
| 55 | 'cisco_bgp_peer2_localport' => 'cbgpPeer2LocalPort', | ||
| 56 | 'cisco_bgp_peer2_localas' => 'cbgpPeer2LocalAs', | ||
| 57 | 'cisco_bgp_peer2_localidentifier' => 'cbgpPeer2LocalIdentifier', | ||
| 58 | 'cisco_bgp_peer2_remoteport' => 'cbgpPeer2RemotePort', | ||
| 59 | 'cisco_bgp_peer2_remoteas' => 'cbgpPeer2RemoteAs', | ||
| 60 | 'cisco_bgp_peer2_remoteidentifier' => 'cbgpPeer2RemoteIdentifier', | ||
| 61 | 'cisco_bgp_peer2_inupdates' => 'cbgpPeer2InUpdates', | ||
| 62 | 'cisco_bgp_peer2_outupdates' => 'cbgpPeer2OutUpdates', | ||
| 63 | 'cisco_bgp_peer2_intotalmessages' => 'cbgpPeer2InTotalMessages', | ||
| 64 | 'cisco_bgp_peer2_outtotalmessages' => 'cbgpPeer2OutTotalMessages', | ||
| 65 | 'cisco_bgp_peer2_lasterror' => 'cbgpPeer2LastError', | ||
| 66 | 'cisco_bgp_peer2_fsmestablishedtransitions' | ||
| 67 | => 'cbgpPeer2FsmEstablishedTransitions', | ||
| 68 | 'cisco_bgp_peer2_fsmestablishedtime' => 'cbgpPeer2FsmEstablishedTime', | ||
| 69 | 'cisco_bgp_peer2_connectretryinterval'=> 'cbgpPeer2ConnectRetryInterval', | ||
| 70 | 'cisco_bgp_peer2_holdtime' => 'cbgpPeer2HoldTime', | ||
| 71 | 'cisco_bgp_peer2_keepalive' => 'cbgpPeer2KeepAlive', | ||
| 72 | 'cisco_bgp_peer2_holdtimeconfigured' => 'cbgpPeer2HoldTimeConfigured', | ||
| 73 | 'cisco_bgp_peer2_keepaliveconfigured' => 'cbgpPeer2KeepAliveConfigured', | ||
| 74 | 'cisco_bgp_peer2_minasoriginationinterval' | ||
| 75 | => 'cbgpPeer2MinASOriginationInterval', | ||
| 76 | 'cisco_bgp_peer2_inupdatelapsedtime' => 'cbgpPeer2InUpdateElapsedTime', | ||
| 77 | 'cisco_bgp_peer2_lasterrortxt' => 'cbgpPeer2LastErrorTxt', | ||
| 78 | 'cisco_bgp_peer2_prevstate' => 'cbgpPeer2PrevState', | ||
| 79 | |||
| 80 | # cbgpPeer2AddrFamilyPrefixTable | ||
| 81 | 'cisco_bgp_peer2_acceptedprefixes' => 'cbgpPeer2AcceptedPrefixes', | ||
| 82 | 'cisco_bgp_peer2_deniedprefixes' => 'cbgpPeer2DeniedPrefixes', | ||
| 83 | 'cisco_bgp_peer2_prefixadminlimit' => 'cbgpPeer2PrefixAdminLimit', | ||
| 84 | 'cisco_bgp_peer2_prefixthreshold' => 'cbgpPeer2PrefixThreshold', | ||
| 85 | 'cisco_bgp_peer2_prefixclearthreshold'=> 'cbgpPeer2PrefixClearThreshold', | ||
| 86 | 'cisco_bgp_peer2_advertisedprefixes' => 'cbgpPeer2AdvertisedPrefixes', | ||
| 87 | 'cisco_bgp_peer2_suppressedprefixes' => 'cbgpPeer2SuppressedPrefixes', | ||
| 88 | 'cisco_bgp_peer2_withdrawnprefixes' => 'cbgpPeer2WithdrawnPrefixes', | ||
| 89 | ); | ||
| 90 | |||
| 91 | %MUNGE = ( | ||
| 92 | 'cisco_bgp_peer2_localaddr' => \&SNMP::Info::munge_inetaddress, | ||
| 93 | 'cisco_bgp_peer2_lasterror' => \&SNMP::Info::munge_octet2hex, | ||
| 94 | ); | ||
| 95 | |||
| 96 | sub parse_cisco_bgp_peer2_entry_index { | ||
| 97 | my ($self, $index) = @_; | ||
| 98 | my ($type, $addrlength, $ip) = split(/\./, $index, 3); | ||
| 99 | # decode IPv6 remote address | ||
| 100 | if ($addrlength == 16) { | ||
| 101 | # copied from SNMP::Info::IPv6/ipv6_addr | ||
| 102 | my @parts = split(/\./, $ip); | ||
| 103 | $ip = sprintf("%x:%x:%x:%x:%x:%x:%x:%x", | ||
| 104 | unpack('n8', pack('C*', @parts))); | ||
| 105 | } | ||
| 106 | return $type, $addrlength, $ip; | ||
| 107 | } | ||
| 108 | |||
| 109 | 1; | ||
| 110 | __END__ |