import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / AxxessIT.pm
1 #  Copyright (C) 2002  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: AxxessIT.pm,v 1.1 2010-12-27 00:03:55 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # AxxessIT Ethernet over SDH switches, also known as
21 # Cisco ONS 15305 and 15302 (by January 2005)
22 # Probably later Cisco will update the software and it will need
23 # another Torrus discovery module.
24 # Company website: http://www.axxessit.no/
25
26 # Tested with:
27 #
28 # Cisco ONS 15305 software release 1.1.1
29 # Cisco ONS 15302
30
31
32     
33
34 package Torrus::DevDiscover::AxxessIT;
35
36 use strict;
37 use Torrus::Log;
38
39
40 $Torrus::DevDiscover::registry{'AxxessIT'} = {
41     'sequence'     => 500,
42     'checkdevtype' => \&checkdevtype,
43     'discover'     => \&discover,
44     'buildConfig'  => \&buildConfig
45     };
46
47
48 our %oiddef =
49     (
50      # AXXEDGE-MIB
51      'axxEdgeTypes'                  => '1.3.6.1.4.1.7546.1.4.1.1',
52      
53      'axxEdgeWanPortMapTable'         => '1.3.6.1.4.1.7546.1.4.1.2.5.1.2',
54      'axxEdgeWanPortMapSlotNumber'    => '1.3.6.1.4.1.7546.1.4.1.2.5.1.2.1.1',
55      'axxEdgeWanPortMapPortNumber'    => '1.3.6.1.4.1.7546.1.4.1.2.5.1.2.1.2',
56
57      'axxEdgeWanXPortMapTable'        => '1.3.6.1.4.1.7546.1.4.1.2.5.1.11',
58      'axxEdgeWanXPortMapSlotNumber'   => '1.3.6.1.4.1.7546.1.4.1.2.5.1.11.1.1',
59      'axxEdgeWanXPortMapPortNumber'   => '1.3.6.1.4.1.7546.1.4.1.2.5.1.11.1.2',
60      
61      'axxEdgeWanPortDescription'      => '1.3.6.1.4.1.7546.1.4.1.2.5.1.3.1.4',
62      'axxEdgeWanXPortDescription'     => '1.3.6.1.4.1.7546.1.4.1.2.5.1.12.1.4',
63      
64      'axxEdgeEthPortMapTable'         => '1.3.6.1.4.1.7546.1.4.1.2.6.1.2',
65      'axxEdgeEthPortMapSlotNumber'    => '1.3.6.1.4.1.7546.1.4.1.2.6.1.2.1.1',
66      'axxEdgeEthPortMapPortNumber'    => '1.3.6.1.4.1.7546.1.4.1.2.6.1.2.1.2',
67
68      'axxEdgeEthLanXPortMapTable'     => '1.3.6.1.4.1.7546.1.4.1.2.6.1.4',
69      'axxEdgeEthLanXPortMapSlotNumber' => '1.3.6.1.4.1.7546.1.4.1.2.6.1.4.1.1',
70      'axxEdgeEthLanXPortMapPortNumber' => '1.3.6.1.4.1.7546.1.4.1.2.6.1.4.1.2',
71      
72      'axxEdgeEthPortDescription'      => '1.3.6.1.4.1.7546.1.4.1.2.6.1.3.1.4',
73      'axxEdgeEthLanXPortDescription'  => '1.3.6.1.4.1.7546.1.4.1.2.6.1.5.1.4',
74      
75      'axxEdgeDcnManagementPortMode'    => '1.3.6.1.4.1.7546.1.4.1.2.3.2.1.0',
76      'axxEdgeDcnManagementPortIfIndex' => '1.3.6.1.4.1.7546.1.4.1.2.3.2.2.0',
77
78      # AXX155E-MIB (ONS 15302)
79      'axx155EDevices'                 => '1.3.6.1.4.1.7546.1.5.1.1',
80
81      'axx155EEthPortTable'            => '1.3.6.1.4.1.7546.1.5.1.2.6.1.2',
82      'axx155EEthPortIfIndex'          => '1.3.6.1.4.1.7546.1.5.1.2.6.1.2.1.2',
83      'axx155EEthPortName'             => '1.3.6.1.4.1.7546.1.5.1.2.6.1.2.1.3',
84      'axx155EEthPortType'             => '1.3.6.1.4.1.7546.1.5.1.2.6.1.2.1.4',
85
86      'axx155EDcnManagementPortMode'   => '1.3.6.1.4.1.7546.1.5.1.2.2.2.2.0',
87      'axx155EDcnManagementPortIfIndex' => '1.3.6.1.4.1.7546.1.5.1.2.2.2.3.0'
88      );
89
90
91 sub checkdevtype
92 {
93     my $dd = shift;
94     my $devdetails = shift;
95
96     my $sysObjID = $devdetails->snmpVar( $dd->oiddef('sysObjectID') );
97     if( index( $sysObjID, $dd->oiddef('axxEdgeTypes') ) == 0 )
98     {
99         $devdetails->setCap('axxEdge');
100     }
101     elsif( index( $sysObjID, $dd->oiddef('axx155EDevices') ) == 0 )
102     {
103         $devdetails->setCap('axx155E');
104     }
105     else
106     {
107         return 0;
108     }
109
110     $devdetails->setCap('interfaceIndexingManaged');
111
112     return 1;
113 }
114
115
116 sub discover
117 {
118     my $dd = shift;
119     my $devdetails = shift;
120
121     my $data = $devdetails->data();
122     my $session = $dd->session();
123
124     $data->{'param'}{'ifindex-map'} = '$IFIDX_IFINDEX';
125     
126     $data->{'nameref'}{'ifNick'}        = 'axxInterfaceNick';
127     $data->{'nameref'}{'ifSubtreeName'} = 'axxInterfaceNick';
128     $data->{'nameref'}{'ifComment'}     = 'axxInterfaceComment';
129     $data->{'nameref'}{'ifReferenceName'}  = 'axxInterfaceHumanName';
130
131     if( $devdetails->hasCap('axxEdge') )
132     {
133         my %map =
134             ( 'Wan' => {
135                 'MapTable'      => 'axxEdgeWanPortMapTable',
136                 'MapSlotNumber' => 'axxEdgeWanPortMapSlotNumber',
137                 'MapPortNumber' => 'axxEdgeWanPortMapPortNumber',
138                 'Description'   => 'axxEdgeWanPortDescription',
139                 'ifNick'        => 'Wan_%d_%d',
140                 'ifHuman'       => 'WAN %d/%d',
141                 'ifComment'     => 'WAN slot %d, port %d' },
142
143               'WanX' => {
144                 'MapTable'      => 'axxEdgeWanXPortMapTable',
145                 'MapSlotNumber' => 'axxEdgeWanXPortMapSlotNumber',
146                 'MapPortNumber' => 'axxEdgeWanXPortMapPortNumber',
147                 'Description'   => 'axxEdgeWanXPortDescription',
148                 'ifNick'        => 'WanX_%d_%d',
149                 'ifHuman'       => 'WANX %d/%d',
150                 'ifComment'     => 'WANX slot %d, port %d'  },
151               
152               'Eth' => {
153                 'MapTable'      => 'axxEdgeEthPortMapTable',
154                 'MapSlotNumber' => 'axxEdgeEthPortMapSlotNumber',
155                 'MapPortNumber' => 'axxEdgeEthPortMapPortNumber',
156                 'Description'   => 'axxEdgeEthPortDescription',
157                 'ifNick'        => 'Eth_%d_%d',
158                 'ifHuman'       => 'Ethernet %d/%d',
159                 'ifComment'     => 'Ethernet interface: slot %d, port %d' },
160               
161               'EthLanX' => {
162                 'MapTable'      => 'axxEdgeEthLanXPortMapTable',
163                 'MapSlotNumber' => 'axxEdgeEthLanXPortMapSlotNumber',
164                 'MapPortNumber' => 'axxEdgeEthLanXPortMapPortNumber',
165                 'Description'   => 'axxEdgeEthLanXPortDescription',
166                 'ifNick'        => 'EthLanX_%d_%d',
167                 'ifHuman'       => 'Ethernet LANX %d/%d',
168                 'ifComment'  => 'Ethernet LANX interface: slot %d, port %d' }
169               );
170
171         foreach my $type ( keys %map )
172         {
173             my $mapTable =
174                 $session->get_table( -baseoid =>
175                                      $dd->oiddef($map{$type}{'MapTable'}) );
176             $devdetails->storeSnmpVars( $mapTable );
177             
178             my $descTable =
179                 $session->get_table( -baseoid =>
180                                      $dd->oiddef($map{$type}{'Description'}) );
181             $devdetails->storeSnmpVars( $descTable );
182         
183             foreach my $ifIndex
184                 ( $devdetails->
185                   getSnmpIndices($dd->oiddef($map{$type}{'MapSlotNumber'})) )
186             {
187                 my $interface = $data->{'interfaces'}{$ifIndex};
188                 next if not defined( $interface );
189
190                 my $slot =
191                     $devdetails->snmpVar
192                     ($dd->oiddef($map{$type}{'MapSlotNumber'}) .'.'. $ifIndex);
193                 my $port =
194                     $devdetails->snmpVar
195                     ($dd->oiddef($map{$type}{'MapPortNumber'}) .'.'. $ifIndex);
196             
197                 my $desc =
198                     $devdetails->snmpVar
199                     ($dd->oiddef($map{$type}{'Description'}) .'.'.
200                      $slot .'.'. $port);
201                 
202                 $interface->{'param'}{'interface-index'} = $ifIndex;
203
204                 $interface->{'axxInterfaceNick'} =
205                     sprintf( $map{$type}{'ifNick'}, $slot, $port );
206                 
207                 $interface->{'axxInterfaceHumanName'} =
208                     sprintf( $map{$type}{'ifHuman'}, $slot, $port );
209
210                 $interface->{'axxInterfaceComment'} =
211                     sprintf( $map{$type}{'ifComment'}, $slot, $port );
212                 if( length( $desc ) > 0 )
213                 {
214                     $interface->{'axxInterfaceComment'} .= ' (' . $desc . ')';
215                 }
216             }
217         }
218         
219         # Management interface
220         {
221             my $result = $dd->retrieveSnmpOIDs
222                 ( 'axxEdgeDcnManagementPortMode',
223                   'axxEdgeDcnManagementPortIfIndex');
224
225             if( defined( $result ) )
226             {
227                 if( $result->{'axxEdgeDcnManagementPortMode'} != 2 )
228                 {
229                     Warning('Non-IP mode of Management port is not supported');
230                 }
231                 else
232                 {
233                     my $ifIndex = $result->{'axxEdgeDcnManagementPortIfIndex'};
234                     
235                     my $interface = $data->{'interfaces'}{$ifIndex};
236             
237                     $interface->{'param'}{'interface-index'} = $ifIndex;
238
239                     $interface->{'axxInterfaceNick'} = 'Management';
240
241                     $interface->{'axxInterfaceHumanName'} = 'Management';
242
243                     $interface->{'axxInterfaceComment'} = 'Management port';
244                 }
245             }
246         }
247     }
248     
249     if( $devdetails->hasCap('axx155E') )
250     {
251         my $ethTable =
252             $session->get_table( -baseoid =>
253                                  $dd->oiddef('axx155EEthPortTable') );
254         $devdetails->storeSnmpVars( $ethTable );
255
256         foreach my $port
257             ( $devdetails->
258               getSnmpIndices($dd->oiddef('axx155EEthPortIfIndex')) )
259         {
260             my $ifIndex =
261                 $devdetails->snmpVar
262                 ($dd->oiddef('axx155EEthPortIfIndex') .'.'. $port);
263
264             my $interface = $data->{'interfaces'}{$ifIndex};
265             next if not defined( $interface );
266
267             my $portName =
268                 $devdetails->snmpVar
269                 ($dd->oiddef('axx155EEthPortName') .'.'. $port);
270             
271             my $portType =
272                 $devdetails->snmpVar
273                 ($dd->oiddef('axx155EEthPortType') .'.'. $port);
274
275             $interface->{'param'}{'interface-index'} = $ifIndex;
276             
277             my $type = $portType == 1 ? 'Eth':'Wan';
278             
279             $interface->{'axxInterfaceNick'} =
280                 sprintf( '%s_%d', $type, $port );
281             
282             $interface->{'axxInterfaceHumanName'} =
283                 sprintf( '%s %d', $type, $port );
284             
285             $interface->{'axxInterfaceComment'} = '';
286             if( length( $portName ) > 0 )
287             {
288                 $interface->{'axxInterfaceComment'} = $portName;
289             }
290         }
291         
292         # Management interface
293         {
294             my $result = $dd->retrieveSnmpOIDs
295                 ( 'axx155EDcnManagementPortMode',
296                   'axx155EDcnManagementPortIfIndex');
297
298             if( defined( $result ) )
299             {
300                 if( $result->{'axx155EDcnManagementPortMode'} != 2 )
301                 {
302                     Warning('Non-IP mode of Management port is not supported');
303                 }
304                 else
305                 {
306                     my $ifIndex = $result->{'axx155EDcnManagementPortIfIndex'};
307                     
308                     my $interface = $data->{'interfaces'}{$ifIndex};
309                     
310                     $interface->{'param'}{'interface-index'} = $ifIndex;
311                     
312                     $interface->{'axxInterfaceNick'} = 'Management';
313                     
314                     $interface->{'axxInterfaceHumanName'} = 'Management';
315                     
316                     $interface->{'axxInterfaceComment'} = 'Management port';
317                 }
318             }
319         }
320     }
321     
322     foreach my $ifIndex ( keys %{$data->{'interfaces'}} )
323     {
324         if( not defined( $data->{'interfaces'}{$ifIndex}->
325                          {'param'}{'interface-index'} ) )
326         {
327             delete $data->{'interfaces'}{$ifIndex};
328         }
329     }    
330     
331     return 1;
332 }
333
334
335 sub buildConfig
336 {
337     my $devdetails = shift;
338     my $cb = shift;
339     my $devNode = shift;
340
341 }
342
343
344 1;
345
346
347 # Local Variables:
348 # mode: perl
349 # indent-tabs-mode: nil
350 # perl-indent-level: 4
351 # End: