IPDR/Collection/CiscoSSL.pm untested

filter: Statementstmt 0.0% 0 / 328 Branchbran 0.0% 0 / 130 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 506 SCAR 83.9
CC
66
Cov
0%
new
342.0
get_data_segment
342.0
_process_docsis
210.0
CRAP 4422.0
1 package IPDR::Collection::CiscoSSL;
2  
3 use warnings;
4 use strict;
5 use IO::Select;
6 use IO::Socket;
7 #use IO::Socket::SSL qw(debug3);
8 use IO::Socket::SSL;
9 use POSIX;
10 use Time::HiRes qw( usleep ualarm gettimeofday tv_interval clock_gettime clock_getres );
11  
12 $SIG{CHLD}="IGNORE";
13  
14 =head1 NAME
15  
16 IPDR::Collection::CiscoSSL - IPDR Collection Client (Cisco Specification)
17  
18 =head1 VERSION
19  
20 Version 0.40
21  
22 =cut
23  
24 our $VERSION = '0.40';
25  
26 =head1 SYNOPSIS
27  
28 This is a IPDR module primarily written to connect and collect data
29 using IPDR from a Motorola BSR6400 CMTS. Some work is still required.
30  
31 It is not very pretty code, nor perhaps the best approach for some of
32 the code, but it does work and will hopefully save time for other people
33 attempting to decode the IPDR protocol (even using the specification it
34 is hard work).
35  
36 An example configuration for Cisco is
37  
38 cable metering destination 192.168.1.1 5000 192.168.1.2 4000 1 15 secure
39  
40 crypto ca trustpoint IPDR
41 enrollment terminal
42 crl optional
43 exit
44 crypto ca authenticate IPDR
45 <cut and paste your certficate key when promtped>
46 quit
47  
48 To generate a key pair (self signed cert and host key) use the following
49 openssl command
50  
51 openssl req -x509 -days 365 -newkey rsa:1024 -keyout hostkey.pem \
52 -nodes -out hostcert.pem
53  
54 You will be prompted to enter some information. If you wish you can just
55 leave them all blank (or default entries). Two files will be created
56 hostkey.pem and hostcert.pem, use these for the variables SSLKeyFile and
57 SSLCertFile respectively.
58  
59 The IP addresses and ports specified are those of a collector that
60 the CMTS will send data to. The Cisco implementation does not provide
61 all IPDR functionality.
62  
63 An example on how to use this module is shown below. It is relatively simple
64 use the different module for Cisco and CiscoSSL, all others use Client.
65  
66 #!/usr/local/bin/perl
67  
68 use strict;
69 use IPDR::Collection::CiscoSSL;
70  
71 my $ipdr_client = new IPDR::Collection::CiscoSSL (
72 [
73 VendorID => 'IPDR Client',
74 ServerIP => '192.168.1.1',
75 ServerPort => '5000',
76 SSLKeyFile => 'hostkey.pem',
77 SSLCertFile => 'hostcert.pem',
78 Timeout => 2,
79 Type => 'docsis',
80 DataHandler => \&display_data,
81 ]
82 );
83  
84 # Check for data from the IPDR server.
85 my $status = $ipdr_client->connect();
86  
87 if ( !$status )
88 {
89 print "Status was '".$ipdr_client->return_status()."'\n";
90 print "Error was '".$ipdr_client->return_error()."'\n";
91 exit(0);
92 }
93  
94 $ipdr_client->check_data_available();
95  
96 exit(0);
97  
98 sub display_data
99 {
100 my ( $remote_ip ) = shift;
101 my ( $remote_port ) = shift;
102 my ( $data ) = shift;
103 my ( $self ) = shift;
104  
105 foreach my $host ( sort { $a<=> $b } keys %{$data} )
106 {
107 print "Host is '$host' \n";
108 foreach my $document_attribute ( keys %{${$data}{$host}{'document'}} )
109 {
110 print "Document id '$document_attribute' ";
111 print "value is '${$data}{$host}{'document'}{$document_attribute}'\n";
112 }
113  
114 foreach my $sequence ( keys %{${$data}{$host}} )
115 {
116 next if $sequence=~/^document$/i;
117 foreach my $attribute ( keys %{${$data}{$host}{$sequence}} )
118 {
119 print "Sequence is '$sequence' Attribute is '$attribute' ";
120 print "value is '${$data}{$host}{$sequence}{$attribute}'\n";
121 }
122 }
123 }
124 return 1;
125 }
126  
127 This is the most basic way to access the data. There are multiple scripts in
128 the examples directory which will allow you to collect and process the IPDR
129 data.
130  
131 =head1 FUNCTIONS
132  
133 =head2 new
134  
135 The new construct builds an object ready to used by the rest of the module and
136 can be passed the following variables
137  
138 VendorID - This defaults to 'Generic Client' but can be set to any string
139  
140 ServerIP -
141  
142 Client: This is the IP address of the destination exporter.
143 Cisco: This is the IP address of the local server to receive the data
144  
145 ServerPort -
146  
147 Client: This is the port of the destination exporter.
148 Cisco: This is the port on the local server which will be used to
149 receive data
150  
151 Type -
152  
153 Cisco: Only applied to Cisco and currently only 'docsis' works.
154 If omitted then the raw XML data is returned
155  
156 XMLDirectory -
157  
158 Cisco: Only applied to the Cisco module and will force the writing
159 of the XML to the directory specific, filename being the IP
160 address of the sending router.
161  
162 SSLKeyFile
163
164 SSL Certificate file, should be fully pathed
165  
166 SSLHostFile
167  
168 SSL Host filename, should be fully pathed
169  
170 RemoteAddr
171
172 IP address of remote server to send on data to
173  
174 RemotePort
175  
176 Port of remote server to send on data to
177  
178 RemoteTimeOut
179  
180 Timeout for connection
181  
182 RemoteSpeed
183
184 Speed at which to send data. It is a number in Mbps, the
185 default is 10. You can use decimal such as 0.5 to mean 500kbps.
186  
187 RemoteMulti
188
189 This paramter allows multiple destinations to receive XML. The
190 list is a comma separate list of remote end points and their
191 parameters. An example would be
192  
193 10.1.1.1:9000:10,20.1.1.1:9000:50
194  
195 The parameters are as follows
196  
197 Destination IP:Destination Port:Destination Bandwidth
198  
199 You can omit destination bandwidth and it will default to 10
200  
201 Force32BitMode
202  
203 This turns OFF all 64bit checks. Useful for running with older
204 routers such as Cisco7200 UBRs.
205
206 KeepAlive - This defaults to 60, but can be set to any value.
207 Capabilities - This defaults to 0x01 and should not be set to much else.
208 TimeOut - This defaults to 5 and is passed to IO::Socket (usefulness ?!)
209 DataHandler - This MUST be set and a pointer to a function (see example)
210 DEBUG - Set at your peril, 5 being the highest value.
211  
212 An example of using new is
213  
214 my $ipdr_client = new IPDR::Collection::CiscoSSL (
215 [
216 VendorID => 'IPDR Client',
217 ServerIP => '192.168.1.1',
218 ServerPort => '5000',
219 SSLKeyFile => 'hostkey.pem',
220 SSLCertFile => 'hostcert.pem',
221 DataHandler => \&display_data,
222 Type => 'docsis',
223 Timeout => 2,
224 ]
225 );
226  
227 =head2 connect
228  
229 This uses the information set with new and attempts to connect/setup a
230 client/server configuration. The function returns 1 on success, 0
231 on failure. It should be called with
232  
233 $ipdr_client->connect();
234  
235 =head2 check_data_available
236  
237 This function controls all the communication for IPDR. It will, when needed,
238 send data to the DataHandler function. It should be called with
239  
240 $ipdr_client->check_data_available();
241  
242 =head2 ALL OTHER FUNCTIONs
243  
244 The remaining of the functions should never be called and are considered internal
245 only. They do differ between Client and Cisco however both module provide the same
246 generic methods, high level, so the internal workings should not concern the
247 casual user.
248  
249 =cut
250  
251 sub new {
252  
253 my $self = {};
254 bless $self;
255  
256 my ( $class , $attr ) =@_;
257  
258 my ( %handles );
259 my ( %complete_decoded_data );
260  
261 $self->{_GLOBAL}{'DEBUG'}=0;
262  
263 while (my($field, $val) = splice(@{$attr}, 0, 2))
264 { $self->{_GLOBAL}{$field}=$val; }
265  
266 $self->{_GLOBAL}{'STATUS'}="OK";
267  
268 if ( !$self->{_GLOBAL}{'VendorID'} )
269 { $self->{_GLOBAL}{'VendorID'}="Generic Client"; }
270  
271 if ( !$self->{_GLOBAL}{'ServerIP'} )
272 { die "ServerIP Required"; }
273  
274 if ( !$self->{_GLOBAL}{'ServerPort'} )
275 { die "ServerPort Required"; }
276  
277 if ( !$self->{_GLOBAL}{'KeepAlive'} )
278 { $self->{_GLOBAL}{'KeepAlive'}=60; }
279  
280 if ( !$self->{_GLOBAL}{'Timeout'} )
281 { $self->{_GLOBAL}{'Timeout'}=5; }
282  
283 if ( !$self->{_GLOBAL}{'Type'} )
284 { $self->{_GLOBAL}{'Type'}=0; }
285  
286 if ( !$self->{_GLOBAL}{'RemoteIP'} )
287 { $self->{_GLOBAL}{'RemoteIP'}=""; }
288  
289 if ( !$self->{_GLOBAL}{'RemotePort'} )
290 { $self->{_GLOBAL}{'RemotePort'}=""; }
291  
292 if ( !$self->{_GLOBAL}{'RemotePassword'} )
293 { $self->{_GLOBAL}{'RemotePassword'}=""; }
294  
295 if ( !$self->{_GLOBAL}{'RemoteTimeOut'} )
296 { $self->{_GLOBAL}{'RemoteTimeOut'}=120; }
297  
298 if ( !$self->{_GLOBAL}{'RemoteSpeed'} )
299 { $self->{_GLOBAL}{'RemoteSpeed'}=10; }
300  
301 if ( !$self->{_GLOBAL}{'RemoteSecure'} )
302 { $self->{_GLOBAL}{'RemoteSecure'}=0; }
303  
304 if ( !$self->{_GLOBAL}{'Force32BitMode'} )
305 { $self->{_GLOBAL}{'Force32BitMode'}=0; }
306  
307 if ( !$self->{_GLOBAL}{'RemoteMulti'} )
308 { $self->{_GLOBAL}{'RemoteMulti'}=""; }
309  
310 if ( !$self->{_GLOBAL}{'XMLDirectory'} )
311 { $self->{_GLOBAL}{'XMLDirectory'}=0; }
312  
313 if ( !$self->{_GLOBAL}{'DataHandler'} )
314 { die "DataHandler Function Must Be Defined"; }
315  
316 if ( !$self->{_GLOBAL}{'PollTime'} )
317 { $self->{_GLOBAL}{'PollTime'}=900 }
318  
319 $self->{_GLOBAL}{'handles'}= \%handles;
320 $self->{_GLOBAL}{'complete_decoded_data'} = \%complete_decoded_data;
321  
322 return $self;
323 }
324  
325  
326 sub get_data_segment
327 {
328 my ( $self ) = shift;
329 my ( $dataset ) = "";
330  
331 my ( $handles ) = $self->{_GLOBAL}{'handles'};
332 my ( $current_handles ) = $self->{_GLOBAL}{'ready_handles'};
333  
334 foreach my $handle ( @{$current_handles} )
335 {
336 # print "Handle is '$handle'\n";
337 if ( $handle==$self->{_GLOBAL}{'Handle'} )
338 {
339 my $new = $self->{_GLOBAL}{'Handle'}->accept;
340 $self->{_GLOBAL}{'Selector'}->add($new);
341 $self->send_connection_header($new);
342 }
343 else
344 {
345 my $link = 0;
346 $dataset="";
347 $link = sysread($handle,$dataset,1024);
348 if ( !$link )
349 {
350 my $child;
351 ${$handles}{$handle}{'data'}.=$dataset;
352 if ($child=fork)
353 { } elsif (defined $child)
354 {
355 if ( $self->{_GLOBAL}{'XMLDirectory'} )
356 {
357 if ( !${$handles}{$handle}{'data'} )
358 {} else {
359 if ( open (__FILE,">".$self->{_GLOBAL}{'XMLDirectory'}."/".${$handles}{$handle}{'addr'}) )
360 {
361 print __FILE ${$handles}{$handle}{'data'};
362 close __FILE; }
363 }
364 }
365 #$SIG{CHLD}="IGNORE";
366 #setsid;
367 foreach my $handler ( keys %{$handles} )
368 { if ( $handler ne $handle ) { delete ${$handles}{$handler}; } }
369 if ( !${$handles}{$handle} ) { waitpid($child,0); exit(0); }
370 if ( $self->{_GLOBAL}{'Type'}=~/^docsis/ig )
371 {
372 my %result = $self->_process_docsis(${$handles}{$handle}{'addr'},${$handles}{$handle}{'data'});
373 if ( scalar(keys %result)>0 )
374 {
375 $self->{_GLOBAL}{'DataHandler'}->(
376 ${$handles}{$handle}{'addr'},
377 ${$handles}{$handle}{'port'},
378 \%result,
379 $self
380 );
381 }
382 }
383 else
384 {
385 $self->{_GLOBAL}{'DataHandler'}->(
386 ${$handles}{$handle}{'addr'},
387 ${$handles}{$handle}{'port'},
388 ${$handles}{$handle}{'data'},
389 $self );
390 }
391 # remote sending needs to go here.
392 if ( $self->{_GLOBAL}{'RemoteIP'} && $self->{_GLOBAL}{'RemotePort'} )
393 {
394 $self->_send_to_clear_destination(${$handles}{$handle}{'data'});
395 }
396 #
397  
398 waitpid($child,0);
399 exit(0);
400 }
401 if ( ${$handles}{$handle}{'addr'} )
402 {
403 if ( $self->{_GLOBAL}{'complete_decoded_data'}{ ${$handles}{$handle}{'addr'} } )
404 { undef $self->{_GLOBAL}{'complete_decoded_data'}{ ${$handles}{$handle}{'addr'} }; }
405 }
406 delete ${$handles}{$handle};
407 $self->{_GLOBAL}{'Selector'}->remove($handle);
408 $handle->close();
409 }
410
411 if ( $link )
412 {
413 ${$handles}{$handle}{'data'}.=$dataset;
414 ${$handles}{$handle}{'addr'}=$handle->peerhost() if !${$handles}{$handle}{'addr'};
415 ${$handles}{$handle}{'port'}=$handle->peerport() if !${$handles}{$handle}{'port'};
416 }
417 }
418 }
419 return 1;
420 }
421  
422 sub ReturnPollTime
423 {
424 my ( $self ) = shift;
425 return $self->{_GLOBAL}{'PollTime'};
426 }
427  
428 sub return_error
429 {
430 my ( $self ) = shift;
431 return $self->{_GLOBAL}{'ERROR'};
432 }
433  
434 sub return_status
435 {
436 my ( $self ) = shift;
437 return $self->{_GLOBAL}{'STATUS'};
438 }
439  
440 sub connect
441 {
442 my ( $self ) = shift;
443  
444 if ( !$self->test_64_bit() && $self->{_GLOBAL}{'Force32BitMode'}==0 )
445 {
446 # if you forgot to run make test, this will clobber
447 # your run anyway.
448 die '64Bit support not available must stop.';
449 }
450  
451 my $lsn = IO::Socket::SSL->new
452 (
453 SSL_key_file => $self->{_GLOBAL}{'SSLKeyFile'},
454 SSL_cert_file => $self->{_GLOBAL}{'SSLCertFile'},
455 Listen => 1024,
456 LocalAddr => $self->{_GLOBAL}{'ServerIP'},
457 LocalPort => $self->{_GLOBAL}{'ServerPort'},
458 ReuseAddr => 1,
459 Proto => 'tcp',
460 Timeout => $self->{_GLOBAL}{'Timeout'}
461 );
462 if (!$lsn)
463 {
464 $self->{_GLOBAL}{'STATUS'}="Failed to bind to address '".$self->{_GLOBAL}{'ServerIP'}."' ";;
465 $self->{_GLOBAL}{'STATUS'}.="and port '".$self->{_GLOBAL}{'ServerPort'};
466 $self->{_GLOBAL}{'ERROR'}=$!;
467 return 0;
468 }
469  
470 $self->{_GLOBAL}{'Handle'} = $lsn;
471 $self->{_GLOBAL}{'Selector'}=new IO::Select( $lsn );
472 $self->{_GLOBAL}{'STATUS'}="Success Connected";
473 return 1;
474 }
475  
476 sub check_data_available
477 {
478 my ( $self ) = shift;
479  
480 while ( $self->check_data_handles )
481 { $self->get_data_segment(); }
482  
483 $self->{_GLOBAL}{'STATUS'}="Socket Closed";
484 $self->{_GLOBAL}{'ERROR'}="Socket Closed";
485 }
486  
487  
488 sub check_data_handles
489 {
490 my ( $self ) = shift;
491 my ( @handle ) = $self->{_GLOBAL}{'Selector'}->can_read;
492 $self->{_GLOBAL}{'ready_handles'}=\@handle;
493 }
494  
495 sub send_connection_header
496 {
497 my ( $self ) = shift;
498 my ( $handle ) = shift;
499 if ( !$handle ) { return 1; }
500 my ( $header ) = $self->{_GLOBAL}{'VendorID'};
501 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
502 { $header.=" Debug Level ".$self->{_GLOBAL}{'DEBUG'}; }
503 $header.="\n";
504 syswrite($handle,$header,length($header));
505 return 1;
506 }
507  
508 sub _process_docsis
509 {
510 my ( $self ) = shift;
511 my ( $host_ip ) = shift;
512 my ( $raw_data ) = shift;
513  
514 #print "Raw DAta was \n\n\n$raw_data\n\n\n";
515  
516  
517 my ( %result, $direction );
518 if ( $raw_data!~/ipdrdoc/ig )
519 { return %result; }
520  
521 # now we should really use a XML parser
522 # two problems
523 # i) this module really needs to be fast
524 # ii) Cisco CMTS depending on the IOS version send out
525 # unparsable XML.
526  
527 my ( $header,$body,$footer ) = (split(/<IPDRDoc/,$raw_data))[0,1,2];
528 my ( @body_parts ) = split(/\<IPDR\s/,$body);
529  
530 my @footer_params = qw [ count endTime ];
531 foreach my $footerp ( @footer_params )
532 {
533 my ( $value ) = (split(/\"/,(split(/$footerp=\"/,$footer))[1]))[0];
534 $result{$host_ip}{'document'}{$footerp}=$value;
535 }
536  
537 $header=$body_parts[0];
538  
539 my @header_params = qw [ docId creationTime IPDRRecorderInfo version xmlns xmlns:xsi xsi:schemaLocation ];
540 foreach my $headerp ( @header_params )
541 {
542 my ( $value ) = (split(/\"/,(split(/$headerp=\"/,$header))[1]))[0];
543 $result{$host_ip}{'document'}{$headerp}=$value;
544 }
545 #my $version=substr($result{$host_ip}{'document'}{'version'},0,3);
546  
547 my $version=$result{$host_ip}{'document'}{'version'}; $version = (split(/-/,$version))[0];
548  
549 my ( @direction_name )= qw [ blank Downstream Upstream ];
550  
551 # Load up the the different IPDR version templates we can use
552 # Currently supported is 3.1 and 3.5.
553 # There are no checks at present if a different version is sent to us.
554 my ( $template_data ) = return_template_data();
555 my ( $entry_count ) = 0;
556  
557 if ( !${$template_data}{$version} ) { return %result; };
558  
559 foreach my $entry ( @body_parts )
560 {
561 $direction="";
562 next if $entry=~/xmlns/;
563 $entry=~s/\<\/IPDR\>//g;
564 my ( $type ) = (split(/xsi:type=\"/, (split(/\">/,$entry))[0] ))[1];
565 next unless $type=~/^DOCSIS-Type/i;
566 $entry = (split(/\">/,$entry))[1];
567  
568 # now we have a clean ipdr line, all attributes with opens and closes
569  
570 my %inner_keys;
571 foreach my $attrib ( split(/\<\//,$entry) )
572 {
573 my ( $close_attrib ) = (split(/\</,$attrib))[1];
574 next unless $close_attrib;
575 my ( $name , $value ) = (split(/\>/,$close_attrib))[0,1];
576 next unless $name; $inner_keys{$name}=$value;
577 }
578  
579 if ( $version=~/^3.1/ )
580 {
581 next if scalar(keys %inner_keys)<16;
582 $direction = $inner_keys{'SFdirection'}; }
583  
584 if ( $version=~/^3.5/ )
585 {
586 next if scalar(keys %inner_keys)<22;
587 $direction = $direction_name[$inner_keys{'serviceDirection'}];
588 }
589  
590 if ( $version=~/^99.99/ )
591 {
592 $direction = $direction_name[$inner_keys{'serviceDirection'}];
593 }
594 next unless $direction;
595  
596 my $subscriber = $inner_keys{ ${$template_data}{$version}{'all-CMmacAddress'} };
597  
598 foreach my $attribute ( keys %{${$template_data}{$version}} )
599 {
600 my ( $parent, $test ) = (split(/-/,$attribute))[0,1];
601 next unless $inner_keys{ ${$template_data}{$version}{$attribute} };
602 $result{$host_ip}{$entry_count}{$test} = $inner_keys{ ${$template_data}{$version}{$attribute} };
603 }
604  
605 # foreach my $attribute ( keys %{${$template_data}{$version}} )
606 # {
607 # my ( $parent, $test ) = (split(/-/,$attribute))[0,1];
608 # #next if $parent=~/direction/i;
609 # next unless $inner_keys{ ${$template_data}{$version}{$attribute} };
610 # if ( $parent=~/^all/ )
611 # { $result{$subscriber}{ $test }=
612 # $inner_keys{ ${$template_data}{$version}{$attribute} }; }
613 # else
614 # { $result{$subscriber}{$direction}{ $test }=
615 # $inner_keys{ ${$template_data}{$version}{$attribute} }; }
616 # }
617  
618  
619 $entry_count++;
620 }
621  
622 return %result;
623 }
624  
625 sub _send_to_clear_destination
626 {
627 my ( $self ) = shift;
628 my ( $data ) = shift;
629 my ( $length_sent ) = 0;
630 my ( $send_size ) = 1000;
631  
632 #RemoteSecure
633 #RemoteMulti
634 #print "Sending data is \n\n$data\n\n";
635  
636 if ( $self->{_GLOBAL}{'RemoteMulti'} )
637 {
638 # Multi remote needs to fork out the sending so it can
639 # do all the destinations at once otherwise it *may*
640 # take a while to get through any number of
641 # destinations set.
642 #
643 # Multiple destination is set to the follow
644 #
645 # Destination IP:Destination Port:Destination Speed,
646 #
647 # if using secure then you need to make sure the
648 # keys are the same for each destination host.
649 #
650 my $child;
651 foreach my $destination ( split(/,/,$self->{_GLOBAL}{'RemoteMulti'}) )
652 {
653 if ($child=fork)
654 { } elsif (defined $child)
655 {
656 my ( $remoteip, $remoteport, $remotespeed ) = (split(/:/,$destination))[0,1,2];
657 if ( !$remoteip || !$remoteport )
658 {
659 waitpid($child,0);
660 exit(0);
661 }
662 if ( !$remotespeed )
663 { $remotespeed=10; }
664 my $lsr;
665 if ( $self->{_GLOBAL}{'RemoteSecure'} )
666 {
667 $lsr = IO::Socket::SSL->new
668 (
669 PeerAddr => $remoteip,
670 PeerPort => $remoteport,
671 SSL_key_file => $self->{_GLOBAL}{'SSLKeyFile'},
672 ReuseAddr => 1,
673 Proto => 'tcp',
674 Timeout => 5
675 );
676 }
677 else
678 {
679 $lsr = IO::Socket::INET->new
680 (
681 PeerAddr => $remoteip,
682 PeerPort => $remoteport,
683 ReuseAddr => 1,
684 Proto => 'tcp',
685 Timeout => 5
686 );
687 }
688 if ( !$lsr )
689 {
690 waitpid($child,0);
691 exit(0);
692 }
693 $lsr->autoflush(0);
694 my $selector = new IO::Select( $lsr );
695 my $timer = (1/($remotespeed/8) )*$send_size;
696 my $print_status = 1;
697 my $chunk;
698 while ( length($data)>0 && (my @ready = $selector->can_write ) )
699 {
700 foreach my $write ( @ready )
701 {
702 if ( $write == $lsr )
703 {
704 #print "handle is '$write'\n";
705 if ( length($data)<=$send_size)
706 {
707 #print "ASending '$data'\n\n\n";
708 $print_status = print $write $data;
709 $data = "";
710 }
711 else
712 {
713 $chunk = substr($data,0,$send_size);
714 $print_status = print $write $chunk;
715 #print "BSending '$chunk'\n\n\n";
716 $data = substr($data,$send_size,length($data)-$send_size);
717 }
718 }
719 }
720 # Timer added for remotesendspeed. Useful for management networks with limited
721 # speed, such as 10mb/s or even t1/e1 speeds of 1.6/2 Mbp/s
722 usleep($timer);
723 #print "Ending pass for send.\n";
724 }
725 usleep(100000);
726 $lsr->close();
727 waitpid($child,0);
728 exit(0);
729 }
730 }
731 }
732 else
733 {
734 my $lsr;
735 if ( $self->{_GLOBAL}{'RemoteSecure'} )
736 {
737 $lsr = IO::Socket::SSL->new
738 (
739 PeerAddr => $self->{_GLOBAL}{'RemoteIP'},
740 PeerPort => $self->{_GLOBAL}{'RemotePort'},
741 SSL_key_file => $self->{_GLOBAL}{'SSLKeyFile'},
742 ReuseAddr => 1,
743 Proto => 'tcp',
744 Timeout => 5
745 );
746 }
747 else
748 {
749 $lsr = IO::Socket::INET->new
750 (
751 PeerAddr => $self->{_GLOBAL}{'RemoteIP'},
752 PeerPort => $self->{_GLOBAL}{'RemotePort'},
753 ReuseAddr => 1,
754 Proto => 'tcp',
755 Timeout => 5
756 );
757 }
758 if (!$lsr)
759 {
760 return 0;
761 }
762 $lsr->autoflush(0);
763 my $selector = new IO::Select( $lsr );
764 my $timer = (1/($self->{_GLOBAL}{'RemoteSpeed'}/8) )*$send_size;
765 my $chunk;
766 my $print_status = 1;
767 while ( length($data)>0 && (my @ready = $selector->can_write ) )
768 {
769 foreach my $write ( @ready )
770 {
771 if ( $write == $lsr )
772 {
773 #print "handle is '$write'\n";
774 if ( length($data)<=$send_size)
775 {
776 #print "ASending '$data'\n\n\n";
777 $print_status = print $write $data;
778 $data = "";
779 }
780 else
781 {
782 $chunk = substr($data,0,$send_size);
783 $print_status = print $write $chunk;
784 #print "BSending '$chunk'\n\n\n";
785 $data = substr($data,$send_size,length($data)-$send_size);
786 }
787 }
788 }
789 usleep($timer);
790 }
791 usleep(100000);
792 $lsr->close();
793 }
794  
795 return 1;
796 }
797  
798  
799 sub return_template_data
800 {
801  
802 my ( %templates ) =
803 (
804 '3.1' =>
805 {
806 'all-CMmacAddress' => 'subscriberId',
807 'all-serviceTimeCreated' => 'IPDRcreationTime',
808 'all-serviceClassName' => 'serviceClassName',
809 'direction-serviceDirection' => 'SFdirection',
810 'all-CMcpeIpv4List' => 'CPEipAddress',
811 'all-CMipAddress' => 'CMipAddress',
812 'Upstream-servicePktsPassed' => 'pktsPassed',
813 'Downstream-servicePktsPassed' => 'pktsPassed',
814 'Upstream-serviceOctetsPassed' => 'octetsPassed',
815 'Downstream-serviceOctetsPassed' => 'octetsPassed',
816 'Upstream-serviceSlaDelayPkts' => 'SLAdelayPkts',
817 'Downstream-serviceSlaDelayPkts' => 'SLAdelayPkts',
818 'Upstream-serviceSlaDropPkts' => 'SLAdropPkts',
819 'Downstream-serviceSlaDropPkts' => 'SLAdropPkts',
820 'Upstream-serviceIdentifier' => 'SFID',
821 'Downstream-serviceIdentifier' => 'SFID',
822 'Upstream-serviceTimeActive' => 'serviceTimeActive',
823 'Downstream-serviceTimeActive' => 'serviceTimeActive',
824 'all-CMTShostname' => 'CMTShostname',
825 'all-CMdocsisMode' => 'CMdocsisMode',
826 'all-CMTSipAddress' => 'CMTSipAddress',
827 'all-CMTSsysUpTime' => 'CMTSsysUpTime'
828 }
829 ,
830 '3.5' =>
831 {
832 'all-CMmacAddress' => 'CMmacAddress',
833 'all-serviceClassName' => 'serviceClassName',
834 'all-serviceTimeCreated' => 'serviceTimeCreated',
835 'direction-serviceDirection' => 'serviceDirection',
836 'all-CMcpeIpv4List' => 'CMCPEipAddress',
837 'all-CMipAddress' => 'CMipAddress',
838 'Upstream-servicePktsPassed' => 'servicePktsPassed',
839 'Downstream-servicePktsPassed' => 'servicePktsPassed',
840 'Upstream-serviceOctetsPassed' => 'serviceOctetsPassed',
841 'Downstream-serviceOctetsPassed' => 'serviceOctetsPassed',
842 'Upstream-serviceIdentifier' => 'serviceIdentifier',
843 'Downstream-serviceIdentifier' => 'serviceIdentifier',
844 'Upstream-serviceSlaDelayPkts' => 'serviceSlaDelayPkts',
845 'Downstream-serviceSlaDelayPkts' => 'serviceSlaDelayPkts',
846 'Upstream-serviceSlaDropPkts' => 'serviceSlaDropPkts',
847 'Downstream-serviceSlaDropPkts' => 'serviceSlaDropPkts',
848 'Upstream-serviceTimeActive' => 'serviceTimeActive',
849 'Downstream-serviceTimeActive' => 'serviceTimeActive',
850 'all-CMTShostName' => 'CMTShostName',
851 'all-IPDRcreationTime' => 'IPDRcreationTime',
852 'all-RecType' => 'RecType',
853 'all-CMdocsisMode' => 'CMdocsisMode',
854 'all-CMTSdownIfName' => 'CMTSdownIfName',
855 'all-CMTSupIfName' => 'CMTSupIfName',
856 'all-CMTSipAddress' => 'CMTSipAddress',
857 'all-CMTSsysUpTime' => 'CMTSsysUpTime'
858 },
859 '99.99' =>
860 {
861 'all-CMmacAddress' => 'CMmacAddress',
862 'all-serviceClassName' => 'serviceClassName',
863 'all-serviceTimeCreated' => 'serviceTimeCreated',
864 'direction-serviceDirection' => 'serviceDirection',
865 'all-CMcpeIpv4List' => 'CMCPEipAddress',
866 'all-CMipAddress' => 'CMipAddress',
867 'Upstream-servicePktsPassed' => 'servicePktsPassed',
868 'Downstream-servicePktsPassed' => 'servicePktsPassed',
869 'Upstream-serviceOctetsPassed' => 'serviceOctetsPassed',
870 'Downstream-serviceOctetsPassed' => 'serviceOctetsPassed',
871 'Upstream-serviceIdentifier' => 'serviceIdentifier',
872 'Downstream-serviceIdentifier' => 'serviceIdentifier',
873 'Upstream-serviceSlaDelayPkts' => 'serviceSlaDelayPkts',
874 'Downstream-serviceSlaDelayPkts' => 'serviceSlaDelayPkts',
875 'Upstream-serviceSlaDropPkts' => 'serviceSlaDropPkts',
876 'Downstream-serviceSlaDropPkts' => 'serviceSlaDropPkts',
877 'Upstream-serviceTimeActive' => 'serviceTimeActive',
878 'Downstream-serviceTimeActive' => 'serviceTimeActive',
879 'all-CMTShostName' => 'CMTShostName',
880 'all-IPDRcreationTime' => 'IPDRcreationTime',
881 'all-RecType' => 'RecType',
882 'all-CMdocsisMode' => 'CMdocsisMode',
883 'all-CMTSdownIfName' => 'CMTSdownIfName',
884 'all-CMTSupIfName' => 'CMTSupIfName',
885 'all-CMTSipAddress' => 'CMTSipAddress',
886 'all-CMTSsysUpTime' => 'CMTSsysUpTime'
887 }
888 );
889  
890 return \%templates;
891 }
892  
893 sub test_64_bit
894 {
895 my $self = shift;
896 my $tester=576466952313524498;
897 my $origin = $tester;
898 #print "Tester is '$tester'\n";
899 my($test1) = $tester & 0xFFFFFFFF; $tester >>= 32;
900 my($test2) = $tester & 0xFFFFFFFF;
901 my $message = pack("NN",$test2,$test1);
902 my ($part1,$part2) = unpack("NN",$message);
903 $part1 = $part1<<32;
904 #$part1 & 0xFFFFFFFF;
905 $part1+=$part2;
906 if ( $origin!=$part1 )
907 {
908 return 0;
909 }
910 else
911 {
912 return 1;
913 }
914 }
915  
916 =head1 AUTHOR
917  
918 Andrew S. Kennedy, C<< <shamrock at cpan.org> >>
919  
920 =head1 BUGS
921  
922 Please report any bugs or feature requests to
923 C<bug-ipdr-cisco at rt.cpan.org>, or through the web interface at
924 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IPDR-Collection-Cisco>.
925 I will be notified, and then you'll automatically be notified of progress on
926 your bug as I make changes.
927  
928 =head1 SUPPORT
929  
930 You can find documentation for this module with the perldoc command.
931  
932 perldoc IPDR::Collection::CiscoSSL
933  
934 You can also look for information at:
935  
936 =over 4
937  
938 =item * AnnoCPAN: Annotated CPAN documentation
939  
940 L<http://annocpan.org/dist/IPDR-Collection-CiscoSSL>
941  
942 =item * CPAN Ratings
943  
944 L<http://cpanratings.perl.org/d/IPDR-Collection-CiscoSSL>
945  
946 =item * RT: CPAN's request tracker
947  
948 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IPDR-Collection-CiscoSSL>
949  
950 =item * Search CPAN
951  
952 L<http://search.cpan.org/dist/IPDR-Collection-CiscoSSL>
953  
954 =back
955  
956 =head1 ACKNOWLEDGEMENTS
957  
958 =head1 COPYRIGHT & LICENSE
959  
960 Copyright 2011 Andrew S. Kennedy, all rights reserved.
961  
962 This program is free software; you can redistribute it and/or modify it
963 under the same terms as Perl itself.
964  
965 =cut
966  
967 1; # End of IPDR::Collection::CiscoSSL