import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / CasaCMTS.pm
1 #  Copyright (C) 2010  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: CasaCMTS.pm,v 1.1 2010-12-27 00:03:47 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # DOCSIS interface, CASA specific
21
22 package Torrus::DevDiscover::CasaCMTS;
23
24 use strict;
25 use Torrus::Log;
26
27
28 $Torrus::DevDiscover::registry{'CasaCMTS'} = {
29     'sequence'     => 500,
30     'checkdevtype' => \&checkdevtype,
31     'discover'     => \&discover,
32     'buildConfig'  => \&buildConfig
33     };
34
35
36 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
37     'DocsisMacModemsMonitor'} = 'CasaCMTS';
38
39
40 our %oiddef =
41     (
42      'casaProducts' => '1.3.6.1.4.1.20858.2',
43      );
44
45
46 sub checkdevtype
47 {
48     my $dd = shift;
49     my $devdetails = shift;
50     
51     if( not $dd->oidBaseMatch
52         ( 'casaProducts',
53           $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) or
54         not $devdetails->isDevType('RFC2670_DOCS_IF') )
55     {
56         return 0;
57     }
58
59     return 1;
60 }
61
62
63 sub discover
64 {
65     my $dd = shift;
66     my $devdetails = shift;
67
68     my $data = $devdetails->data();
69     
70     push( @{$data->{'docsConfig'}{'docsCableMaclayer'}{'templates'}},
71           'CasaCMTS::casa-docsis-mac-subtree' );
72     
73     foreach my $ifIndex ( @{$data->{'docsCableMaclayer'}} )
74     {
75         my $interface = $data->{'interfaces'}{$ifIndex};
76
77         push( @{$interface->{'docsTemplates'}},
78               'CasaCMTS::casa-docsis-mac-util' );
79     }
80
81     foreach my $ifIndex ( @{$data->{'docsCableUpstream'}} )
82     {
83         my $interface = $data->{'interfaces'}{$ifIndex};
84
85         push( @{$interface->{'docsTemplates'}},
86               'CasaCMTS::casa-docsis-upstream-util' );
87     }
88     
89     foreach my $ifIndex ( @{$data->{'docsCableDownstream'}} )
90     {
91         my $interface = $data->{'interfaces'}{$ifIndex};
92         
93         push( @{$interface->{'docsTemplates'}},
94               'CasaCMTS::casa-docsis-downstream-util' );
95     }
96     
97     
98     return 1;
99 }
100
101
102 sub buildConfig
103 {
104     my $devdetails = shift;
105     my $cb = shift;
106     my $devNode = shift;
107
108     my $data = $devdetails->data();
109
110
111     if( scalar( @{$data->{'docsCableMaclayer'}} ) > 0 )
112     {
113         # Build All_Modems summary graph
114         my $param = {
115             'ds-type'              => 'rrd-multigraph',
116             'ds-names'             => 'total,active,registered',        
117             'graph-lower-limit'    => '0',
118             'precedence'           => '1000',                          
119             'vertical-label'       => 'Modems',
120                 
121             'graph-legend-total'   => 'Total',
122             'line-style-total'     => '##totalresource',
123             'line-color-total'     => '##totalresource',
124             'line-order-total'     => '1',
125             
126             'graph-legend-active'  => 'Active',
127             'line-style-active'    => '##resourcepartusage',
128             'line-color-active'    => '##resourcepartusage',
129             'line-order-active'    => '2',
130             
131             'graph-legend-registered'  => 'Registered',
132             'line-style-registered'    => '##resourceusage',
133             'line-color-registered'    => '##resourceusage',
134             'line-order-registered'    => '3',
135             'descriptive-nickname'     => '%system-id%: All modems'
136             };
137
138         # for the sake of better Emacs formatting
139         $param->{'comment'} =
140             'Registered, Active and Total modems on CMTS';
141         
142         $param->{'nodeid'} =
143             $data->{'docsConfig'}{'docsCableMaclayer'}{'nodeidCategory'} .
144             '//%nodeid-device%//modems';
145         
146         my $first = 1;
147         foreach my $ifIndex ( @{$data->{'docsCableMaclayer'}} )
148         {
149             my $interface = $data->{'interfaces'}{$ifIndex};
150             
151             my $intf = $interface->{$data->{'nameref'}{'ifSubtreeName'}};
152             
153             if( $first )
154             {
155                 $param->{'ds-expr-total'} =
156                     '{' . $intf . '/Modems_Total}';
157                 $param->{'ds-expr-active'} =
158                     '{' . $intf . '/Modems_Active}';
159                 $param->{'ds-expr-registered'} =
160                     '{' . $intf . '/Modems_Registered}';
161                 $first = 0;
162             }
163             else
164             {
165                 $param->{'ds-expr-total'} .=
166                     ',{' . $intf . '/Modems_Total},+';
167                 $param->{'ds-expr-active'} .=
168                     ',{' . $intf . '/Modems_Active},+';
169                 $param->{'ds-expr-registered'} .=
170                     ',{' . $intf . '/Modems_Registered},+';
171             }
172         }
173
174         my $macNode =
175             $cb->getChildSubtree( $devNode,
176                                   $data->{'docsConfig'}{
177                                       'docsCableMaclayer'}{
178                                           'subtreeName'} );
179         if( defined( $macNode ) )
180         {
181             $cb->addLeaf( $macNode, 'All_Modems', $param, [] );
182         }
183         else
184         {
185             Error('Could not find the MAC layer subtree');
186             exit 1;
187         }
188         
189         # Apply selector actions
190         foreach my $ifIndex ( @{$data->{'docsCableMaclayer'}} )
191         {
192             my $interface = $data->{'interfaces'}{$ifIndex};
193             
194             my $intf = $interface->{$data->{'nameref'}{'ifSubtreeName'}};
195             
196             my $monitor =
197                 $interface->{'selectorActions'}{'DocsisMacModemsMonitor'};
198             if( defined( $monitor ) )
199             {
200                 my $intfNode = $cb->getChildSubtree( $macNode, $intf );
201                 $cb->addLeaf( $intfNode, 'Modems_Registered',
202                               {'monitor' => $monitor } );
203             }
204         }
205     }
206
207     if( scalar( @{$data->{'docsCableUpstream'}} ) > 0 )
208     {
209         my $upstrNode =
210             $cb->getChildSubtree( $devNode,
211                                   $data->{'docsConfig'}{'docsCableUpstream'}{
212                                       'subtreeName'} );
213         
214         # Override the overview shortcus defined in rfc2670.docsis-if.xml
215         
216         my $shortcuts = 'snr,fec,freq,modems';
217         
218         my $param = {        
219             'overview-shortcuts' =>
220                 $shortcuts,
221                 
222                 'overview-subleave-name-modems' => 'Modems',
223                 'overview-direct-link-modems' => 'yes',
224                 'overview-direct-link-view-modems' => 'expanded-dir-html',
225                 'overview-shortcut-text-modems' => 'All modems',
226                 'overview-shortcut-title-modems'=>
227                 'Show modem quantities in one page',
228                 'overview-page-title-modems' => 'Modem quantities',
229             };
230         
231         $cb->addParams( $upstrNode, $param );
232     }
233     
234     if( scalar( @{$data->{'docsCableDownstream'}} ) > 0 )
235     {
236         my $downstrNode =
237             $cb->getChildSubtree( $devNode,
238                                   $data->{'docsConfig'}{'docsCableDownstream'}{
239                                       'subtreeName'} );
240         
241         # Override the overview shortcus defined in rfc2670.docsis-if.xml
242         
243         my $shortcuts = 'util,modems';
244         
245         my $param = {        
246             'overview-shortcuts' => $shortcuts,
247             'overview-subleave-name-modems' => 'Modems',
248             'overview-direct-link-modems' => 'yes',
249             'overview-direct-link-view-modems' => 'expanded-dir-html',
250             'overview-shortcut-text-modems' => 'All modems',
251             'overview-shortcut-title-modems' =>
252                 'Show modem quantities in one page',
253             'overview-page-title-modems' => 'Modem quantities',
254             };
255         
256         $cb->addParams( $downstrNode, $param );
257     }
258 }
259
260
261 1;
262
263
264 # Local Variables:
265 # mode: perl
266 # indent-tabs-mode: nil
267 # perl-indent-level: 4
268 # End: