per-agent configuration of batch processors, #71837
[freeside.git] / torrus / perllib / Torrus / DevDiscover / RFC2670_DOCS_IF.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: RFC2670_DOCS_IF.pm,v 1.1 2010-12-27 00:03:55 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # DOCSIS interface statistics
21
22 package Torrus::DevDiscover::RFC2670_DOCS_IF;
23
24 use strict;
25 use Torrus::Log;
26
27
28 $Torrus::DevDiscover::registry{'RFC2670_DOCS_IF'} = {
29     'sequence'     => 100,
30     'checkdevtype' => \&checkdevtype,
31     'discover'     => \&discover,
32     'buildConfig'  => \&buildConfig
33     };
34
35
36 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
37     'DocsisUpSNRMonitor'} = 'RFC2670_DOCS_IF';
38 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
39     'DocsisUpSNRTokenset'} = 'RFC2670_DOCS_IF';
40
41 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
42     'DocsisUpFECCorMonitor'} = 'RFC2670_DOCS_IF';
43 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
44     'DocsisUpFECUncorMonitor'} = 'RFC2670_DOCS_IF';
45
46 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
47     'DocsisDownUtilMonitor'} = 'RFC2670_DOCS_IF';
48
49
50 our %oiddef =
51     (
52      # DOCS-IF-MIB
53      'docsIfDownstreamChannelTable' => '1.3.6.1.2.1.10.127.1.1.1',
54      'docsIfCmtsDownChannelCounterTable' => '1.3.6.1.2.1.10.127.1.3.10',
55      'docsIfSigQSignalNoise' => '1.3.6.1.2.1.10.127.1.1.4.1.5',
56      );
57
58
59
60 sub checkdevtype
61 {
62     my $dd = shift;
63     my $devdetails = shift;
64
65     my $session = $dd->session();
66     my $data = $devdetails->data();
67
68     if( $dd->checkSnmpTable( 'docsIfDownstreamChannelTable' ) )
69     {
70         return 1;
71     }
72
73     return 0;
74 }
75
76
77 sub discover
78 {
79     my $dd = shift;
80     my $devdetails = shift;
81
82     my $data = $devdetails->data();
83     my $session = $dd->session();
84
85     if( $dd->checkSnmpTable( 'docsIfCmtsDownChannelCounterTable' ) )
86     {
87         $devdetails->setCap('docsDownstreamUtil');
88     }
89
90     my $snrTable =
91         $session->get_table( -baseoid =>
92                              $dd->oiddef('docsIfSigQSignalNoise') );
93     if( defined( $snrTable ) )
94     {
95         $devdetails->storeSnmpVars( $snrTable );
96     }
97     
98     $data->{'docsCableMaclayer'} = [];
99     $data->{'docsCableDownstream'} = [];
100     $data->{'docsCableUpstream'} = [];
101
102     foreach my $ifIndex ( sort {$a<=>$b} keys %{$data->{'interfaces'}} )
103     {
104         my $interface = $data->{'interfaces'}{$ifIndex};
105         my $ifType = $interface->{'ifType'};
106
107         $interface->{'docsTemplates'} = [];
108         $interface->{'docsParams'} = {};
109
110         if( $devdetails->hasCap('interfaceIndexingPersistent') )
111         {
112             $interface->{'docsParams'}{'interface-index'} = $ifIndex;
113         }
114         
115         if( $ifType == 127 )
116         {
117             push( @{$data->{'docsCableMaclayer'}}, $ifIndex );
118         }
119         elsif(  $ifType == 128 )
120         {
121             push( @{$data->{'docsCableDownstream'}}, $ifIndex );
122             if( $devdetails->hasCap('docsDownstreamUtil') )
123             {
124                 push( @{$interface->{'docsTemplates'}},
125                       'RFC2670_DOCS_IF::docsis-downstream-util' );
126             }
127         }
128         elsif( $ifType == 129 or $ifType == 205 )
129         {
130             if( $devdetails->hasOID( $dd->oiddef('docsIfSigQSignalNoise') .
131                                      '.' . $ifIndex ) )
132             {
133                 push( @{$data->{'docsCableUpstream'}}, $ifIndex );
134                 push( @{$interface->{'docsTemplates'}},
135                       'RFC2670_DOCS_IF::docsis-upstream-stats' );
136                 
137             }
138         }
139     }
140     
141     if( $devdetails->param('RFC2670_DOCS_IF::upstreams-only') eq 'yes' )
142     {
143         $data->{'docsCableMaclayer'} = [];
144         $data->{'docsCableDownstream'} = [];
145     }
146
147     $data->{'docsConfig'} = {
148         'docsCableMaclayer' => {
149             'subtreeName' => 'Docsis_MAC_Layer',
150             'nodeidCategory' => 'docsmac',
151             'templates' => [],
152             'param' => {
153                 'node-display-name' => 'DOCSIS MAC Layer',
154             },            
155         },
156         'docsCableDownstream' => {
157             'subtreeName' => 'Docsis_Downstream',
158             'nodeidCategory' => 'docsds',
159             'templates' => [],
160             'param' => {
161                 'node-display-name' => 'DOCSIS Downstream',
162             },            
163         },
164         'docsCableUpstream' => {
165             'subtreeName' => 'Docsis_Upstream',
166             'nodeidCategory' => 'docsus',
167             'templates' => ['RFC2670_DOCS_IF::docsis-upstream-subtree'],
168             'param' => {
169                 'node-display-name' => 'DOCSIS Upstream',
170             },            
171         },
172     };
173
174     if( $devdetails->hasCap('docsDownstreamUtil') )
175     {
176         push( @{$data->{'docsConfig'}{'docsCableDownstream'}{'templates'}},
177               'RFC2670_DOCS_IF::docsis-downstream-subtree' );        
178     }
179     
180     return 1;
181 }
182
183
184 sub buildConfig
185 {
186     my $devdetails = shift;
187     my $cb = shift;
188     my $devNode = shift;
189
190     my $data = $devdetails->data();
191
192     foreach my $category ( sort keys %{$data->{'docsConfig'}} )
193     {
194         if( scalar( @{$data->{$category}} ) > 0 and
195             scalar( @{$data->{'docsConfig'}{$category}{'templates'}} ) > 0 )
196         {
197             # Count non-excluded interfaces
198             my $updatedInterfaceList = [];
199             foreach my $ifIndex ( @{$data->{$category}} )
200             {
201                 my $interface = $data->{'interfaces'}{$ifIndex};
202                 next if $interface->{'excluded'};
203                 push( @{$updatedInterfaceList}, $ifIndex );
204             }
205             $data->{$category} = $updatedInterfaceList;
206             
207             next if scalar( @{$data->{$category}} ) == 0;
208
209             my $subtreeNode =
210                 $cb->addSubtree( $devNode,
211                                  $data->{'docsConfig'}{$category}{
212                                      'subtreeName'},
213                                  $data->{'docsConfig'}{$category}{
214                                      'param'},
215                                  $data->{'docsConfig'}{$category}{
216                                      'templates'});
217
218             foreach my $ifIndex ( @{$data->{$category}} )
219             {
220                 my $interface = $data->{'interfaces'}{$ifIndex};
221
222                 my $param = $interface->{'docsParams'};
223
224                 $param->{'searchable'} = 'yes';
225
226                 # Copy some parameters from IF-MIB discovery results
227                 
228                 foreach my $p ('interface-name', 'interface-nick',
229                                'node-display-name', 'comment')
230                 {
231                     $param->{$p} = $interface->{'param'}{$p};
232                 }
233                 
234                 $param->{'nodeid-docsif'} =
235                     $data->{'docsConfig'}{$category}{'nodeidCategory'} .
236                     '//%nodeid-device%//' .
237                     $interface->{$data->{'nameref'}{'ifNodeid'}};
238                 
239                 $param->{'nodeid'} = '%nodeid-docsif%';
240                 
241                 my $intfNode = $cb->addSubtree
242                     ( $subtreeNode,
243                       $interface->{$data->{'nameref'}{'ifSubtreeName'}},
244                       $param, 
245                       $interface->{'docsTemplates'} );
246
247                 # Apply selector actions
248                 if( $category eq 'docsCableUpstream' )
249                 {
250                     my $monitor =
251                         $interface->{'selectorActions'}{'DocsisUpSNRMonitor'};
252                     my $tset =
253                         $interface->{'selectorActions'}{'DocsisUpSNRTokenset'};
254                     if( defined( $monitor ) or defined( $tset ) )
255                     {
256                         my $param = {};
257                         if( defined( $monitor ) )
258                         {
259                             $param->{'monitor'} = $monitor;
260                         }
261                         if( defined( $tset ) )
262                         {
263                             $param->{'tokenset-member'} = $tset;
264                         }
265                         $cb->addLeaf( $intfNode, 'SNR', $param );
266                     }
267
268                     $monitor = $interface->{'selectorActions'}{
269                         'DocsisUpFECCorMonitor'};
270                     if( defined( $monitor ) )
271                     {
272                         $cb->addLeaf( $intfNode, 'Correctable',
273                                       {'monitor' => $monitor } );
274                     }
275
276                     $monitor = $interface->{'selectorActions'}{
277                         'DocsisUpFECUncorMonitor'};
278                     if( defined( $monitor ) )
279                     {
280                         $cb->addLeaf( $intfNode, 'Uncorrectable',
281                                       {'monitor' => $monitor } );
282                     }                                        
283                 }
284                 elsif( $category eq 'docsCableDownstream')
285                 {
286                     my $monitor = $interface->{'selectorActions'}{
287                         'DocsisDownUtilMonitor'};
288                     if( defined( $monitor ) )
289                     {
290                         $cb->addLeaf( $intfNode, 'UsedBytes',
291                                       {'monitor' => $monitor } );
292                     }
293                 }
294             }
295         }
296     }
297 }
298
299
300 1;
301
302
303 # Local Variables:
304 # mode: perl
305 # indent-tabs-mode: nil
306 # perl-indent-level: 4
307 # End: