IPDR/Collection/Cisco.pm untested

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