torrus, RT#10574
[freeside.git] / torrus / perllib / Torrus / DevDiscover / RFC2011_IP_MIB.pm
1 #  Copyright (C) 2005  Stanislav Sinyagin
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; either version 2 of the License, or
6 #  (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: RFC2011_IP_MIB.pm,v 1.1 2010-12-27 00:03:56 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Discovery module for IP-MIB (RFC 2011)
21 # This module does not generate any XML, but provides information
22 # for other discovery modules. For the sake of discovery time and traffic,
23 # it is not implicitly executed during the normal discovery process.
24
25 package Torrus::DevDiscover::RFC2011_IP_MIB;
26
27 use strict;
28 use Torrus::Log;
29
30
31 our %oiddef =
32     (
33      # IP-MIB
34      'ipNetToMediaTable'       => '1.3.6.1.2.1.4.22',
35      'ipNetToMediaPhysAddress' => '1.3.6.1.2.1.4.22.1.2',
36      );
37
38
39
40
41 sub discover
42 {
43     my $dd = shift;
44     my $devdetails = shift;
45
46     my $data = $devdetails->data();
47     my $session = $dd->session();
48
49     my $table = $session->get_table( -baseoid =>
50                                      $dd->oiddef('ipNetToMediaPhysAddress'));
51     
52     if( not defined( $table ) or scalar( %{$table} ) == 0 )
53     {
54         return 0;
55     }
56     
57     $devdetails->storeSnmpVars( $table );
58
59     foreach my $INDEX
60         ( $devdetails->
61           getSnmpIndices( $dd->oiddef('ipNetToMediaPhysAddress') ) )
62     {
63         my( $ifIndex, @ipAddrOctets ) = split( '\.', $INDEX );
64         my $ipAddr = join('.', @ipAddrOctets);
65
66         my $interface = $data->{'interfaces'}{$ifIndex};
67         next if not defined( $interface );
68
69         my $phyAddr =
70             $devdetails->snmpVar($dd->oiddef('ipNetToMediaPhysAddress') .
71                                  '.' . $INDEX);
72
73         $interface->{'ipNetToMedia'}{$ipAddr} = $phyAddr;
74         $interface->{'mediaToIpNet'}{$phyAddr} = $ipAddr;
75
76         # Cisco routers assign ARP to subinterfaces, but MAC accounting
77         # to main interfaces. Let them search in a global table
78         $data->{'ipNetToMedia'}{$ipAddr} = $phyAddr;
79         $data->{'mediaToIpNet'}{$phyAddr} = $ipAddr;
80     }
81                             
82     return 1;
83 }
84
85
86
87 1;
88
89
90 # Local Variables:
91 # mode: perl
92 # indent-tabs-mode: nil
93 # perl-indent-level: 4
94 # End: