IPDR/Collection/Client.pm untested

filter: Statementstmt 0.0% 0 / 1304 Branchbran 0.0% 0 / 484 Conditioncond 0.0% 0 / 63 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 85 Podpod 0.0% 0 / 76 totaltotal 0.0% 0 / 2012 SCAR 109.9
CC
243
Cov
0%
decode_message_type
2256.0
new
756.0
decode_data
756.0
CRAP 59292.0
1 package IPDR::Collection::Client;
2  
3 use warnings;
4 use strict;
5 use IO::Select;
6 use IO::Socket;
7 use IO::Socket::SSL qw(debug3);
8 use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);
9 use Time::localtime;
10 use Time::HiRes qw( usleep ualarm gettimeofday tv_interval clock_gettime clock_getres );
11 use Math::BigInt;
12 $SIG{CHLD}="IGNORE";
13  
14 =head1 NAME
15  
16 IPDR::Collection::Client - IPDR Collection Client
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 non-secure
39  
40 The IP addresses and ports specified are those of a collector that
41 the CMTS will send data to. The Cisco implementation does not provide
42 all IPDR functionality. Setting up a secure connection is not too difficult
43 (this release does not support it) from a collector point of view however
44 the Cisco implementation for secure keys is somewhat painful.
45 This Cisco module opens a socket on the local server waiting for a connection
46 from a Cisco router.
47  
48 An example configuration for Motorola BSR is
49  
50 ipdr enable
51 ipdr collector 192.168.1.1 5000 3
52 ipdr collector 192.168.1.2 4000 2
53  
54 The IP addresses and ports specicified are those of a collector that will
55 connect to the CMTS. You can have multiple collectors connected but only
56 the highest priority collector will receive data, all others will received
57 keep alives.
58 The Client module makes a connection to the destination IP/Port specified.
59  
60 An example on how to use this module is shown below. It is relatively simple
61 use the different module for Cisco, all others use Client.
62  
63 #!/usr/local/bin/perl
64  
65 use strict;
66 use IPDR::Collection::Client;
67  
68 my $ipdr_client = new IPDR::Collection::Client (
69 [
70 VendorID => 'IPDR Client',
71 ServerIP => '192.168.1.1',
72 ServerPort => '5000',
73 KeepAlive => 60,
74 Capabilities => 0x01,
75 DataHandler => \&display_data,
76 Timeout => 2,
77 ]
78 );
79  
80 # We send a connect message to the IPDR server
81 $ipdr_client->connect();
82  
83 # If we do not connect stop.
84 if ( !$ipdr_client->connected )
85 {
86 print "Can not connect to destination.\n";
87 exit(0);
88 }
89  
90 # We now send a connect message
91 $ipdr_client->check_data_available();
92  
93 print "Error was '".$ipdr_client->get_error()."'\n";
94  
95 exit(0);
96  
97 sub display_data
98 {
99 my ( $remote_ip ) = shift;
100 my ( $remote_port ) = shift;
101 my ( $data ) = shift;
102 my ( $self ) = shift;
103  
104 foreach my $sequence ( sort { $a<=>$b } keys %{$data} )
105 {
106 print "Sequence is '$sequence'\n";
107 foreach my $attribute ( keys %{${$data}{$sequence}} )
108 {
109 print "Sequence '$sequence' attribute '$attribute'";
110 print " value '${$data}{$sequence}{$attribute}'\n";
111 }
112 }
113  
114 }
115  
116 This is the most basic way to access the data. There are multiple scripts in
117 the examples directory which will allow you to collect and process the IPDR
118 data.
119  
120 =head1 FUNCTIONS
121  
122 =head2 new
123  
124 The new construct builds an object ready to used by the rest of the module and
125 can be passed the following varaibles
126  
127 VendorID - This defaults to 'Generic Client' but can be set to any string
128  
129 ServerIP -
130  
131 Client: This is the IP address of the destination exporter.
132 Cisco: This is the IP address of the local server to receive the data
133  
134 ServerPort -
135  
136 Client: This is the port of the destination exporter.
137 Cisco: This is the port on the local server which will be used to
138 receive data
139  
140 KeepAlive - This defaults to 60, but can be set to any value.
141 Capabilities - This defaults to 0x01 and should not be set to much else.
142 TimeOut - This defaults to 5 and is passed to IO::Socket (usefulness ?!)
143 DataHandler - This MUST be set and a pointer to a function (see example)
144 DEBUG - Set at your peril, 5 being the highest value.
145  
146 An example of using new is
147  
148 my $ipdr_client = new IPDR::Collection::Client (
149 [
150 VendorID => 'IPDR Client',
151 ServerIP => '192.168.1.1',
152 ServerPort => '5000',
153 KeepAlive => 60,
154 Capabilities => 0x01,
155 DataHandler => \&display_data,
156 Timeout => 2,
157 ]
158 );
159  
160 =head2 connect
161  
162 This uses the information set with new and attempts to connect/setup a
163 client/server configuration. The function returns 1 on success, 0
164 on failure. It should be called with
165  
166 $ipdr_client->connect();
167  
168 =head2 connected
169  
170 You can check if the connect function succeeded. It should return 0
171 on not connected and 1 if the socket/connection was opened. It can be
172 checked with
173  
174 if ( !$ipdr_client->connected )
175 {
176 print "Can not connect to destination.\n";
177 exit(0);
178 }
179  
180 =head2 check_data_available
181  
182 This function controls all the communication for IPDR. It will, when needed,
183 send data to the DataHandler function. It should be called with
184  
185 $ipdr_client->check_data_available();
186  
187 =head2 ALL OTHER FUNCTIONs
188  
189 The remaining of the functions should never be called and are considered internal
190 only. They do differ between Client and Cisco however both module provide the same
191 generic methods, high level, so the internal workings should not concern the
192 casual user.
193  
194 XDR File Location http://www.ipdr.org/public/DocumentMap/XDR3.6.pdf
195  
196 =cut
197  
198 sub new {
199  
200 my $self = {};
201 bless $self;
202  
203 my ( $class , $attr ) =@_;
204  
205 my ( %template );
206 my ( %session );
207 my ( %current_data );
208 my ( %complete_decoded_data );
209 my ( @handles );
210  
211 $self->{_GLOBAL}{'DEBUG'}=0;
212  
213 while (my($field, $val) = splice(@{$attr}, 0, 2))
214 { $self->{_GLOBAL}{$field}=$val; }
215  
216 $self->{_GLOBAL}{'STATUS'}="OK";
217  
218 if ( !$self->{_GLOBAL}{'VendorID'} )
219 { $self->{_GLOBAL}{'VendorID'}="Generic Client"; }
220  
221 if ( !$self->{_GLOBAL}{'ServerIP'} )
222 { die "ServerIP Required"; }
223  
224 if ( !$self->{_GLOBAL}{'ServerPort'} )
225 { die "ServerPort Required"; }
226  
227 if ( !$self->{_GLOBAL}{'KeepAlive'} )
228 { $self->{_GLOBAL}{'KeepAlive'}=60; }
229  
230 if ( !$self->{_GLOBAL}{'Capabilities'} )
231 { $self->{_GLOBAL}{'Capabilities'} = 0x01; }
232  
233 if ( !$self->{_GLOBAL}{'Timeout'} )
234 { $self->{_GLOBAL}{'Timeout'}=10; }
235  
236 if ( !$self->{_GLOBAL}{'SessionName'} )
237 { $self->{_GLOBAL}{'SessionName'}=""; }
238  
239 if ( !$self->{_GLOBAL}{'MaxRecords'} )
240 { $self->{_GLOBAL}{'MaxRecords'}=0; }
241  
242 if ( !$self->{_GLOBAL}{'DataHandler'} )
243 { die "DataHandler Function Must Be Defined"; }
244  
245 if ( !$self->{_GLOBAL}{'RemoteIP'} )
246 { $self->{_GLOBAL}{'RemoteIP'}=""; }
247  
248 if ( !$self->{_GLOBAL}{'RemotePort'} )
249 { $self->{_GLOBAL}{'RemotePort'}=""; }
250  
251 if ( !$self->{_GLOBAL}{'RemotePassword'} )
252 { $self->{_GLOBAL}{'RemotePassword'}=""; }
253  
254 if ( !$self->{_GLOBAL}{'RemoteSpeed'} )
255 { $self->{_GLOBAL}{'RemoteSpeed'}=10; }
256  
257 if ( !$self->{_GLOBAL}{'PacketDirectory'} )
258 { $self->{_GLOBAL}{'PacketDirectory'}=""; }
259  
260 if ( !$self->{_GLOBAL}{'XMLDirectory'} )
261 { $self->{_GLOBAL}{'XMLDirectory'}=""; }
262  
263 if ( !$self->{_GLOBAL}{'AckTimeOverride'} )
264 { $self->{_GLOBAL}{'AckTimeOverride'}=0; }
265  
266 if ( !$self->{_GLOBAL}{'AckSequenceOverride'} )
267 { $self->{_GLOBAL}{'AckSequenceOverride'}=0; }
268  
269 if ( !$self->{_GLOBAL}{'PollTime'} )
270 { $self->{_GLOBAL}{'PollTime'}=900 }
271  
272 if ( !$self->{_GLOBAL}{'MACFormat'} )
273 { $self->{_GLOBAL}{'MACFormat'}=1 }
274  
275 if ( !$self->{_GLOBAL}{'LogDirectory'} )
276 { $self->{_GLOBAL}{'LogDirectory'}=""; }
277  
278 if ( !$self->{_GLOBAL}{'LocalAddr'} )
279 { $self->{_GLOBAL}{'LocalAddr'}=""; }
280  
281 if ( !$self->{_GLOBAL}{'LogEnabled'} )
282 { $self->{_GLOBAL}{'LogEnabled'}=0; }
283  
284 if ( !$self->{_GLOBAL}{'BigLittleEndian'} )
285 { $self->{_GLOBAL}{'BigLittleEndian'}=0; }
286  
287 if ( !$self->{_GLOBAL}{'Warning64BitOff'} )
288 { $self->{_GLOBAL}{'Warning64BitOff'}=0; }
289  
290 if ( !$self->{_GLOBAL}{'hexBinarySingle'} )
291 { $self->{_GLOBAL}{'hexBinarySingle'}=0; }
292  
293 if ( !$self->{_GLOBAL}{'InitiatorID'} )
294 { $self->{_GLOBAL}{'InitiatorID'}=""; }
295  
296  
297 $self->{_GLOBAL}{'data_ack'}=0;
298 $self->{_GLOBAL}{'ERROR'}="" ;
299 $self->{_GLOBAL}{'data_processing'}=0;
300  
301 $self->{_GLOBAL}{'template'}= \%template;
302 $self->{_GLOBAL}{'sessioninfo'}= \%session;
303 $self->{_GLOBAL}{'current_data'}= \%current_data;
304 $self->{_GLOBAL}{'complete_decoded_data'} = \%complete_decoded_data;
305  
306 $self->{_GLOBAL}{'AckTime'}=0;
307 $self->{_GLOBAL}{'AckSequence'}=0;
308 $self->{_GLOBAL}{'data_capture_running'}=0;
309 $self->{_GLOBAL}{'data_capture_running_time'}=0;
310 $self->{_GLOBAL}{'data_capture_data_count'}=0;
311 $self->{_GLOBAL}{'data_capture_keep_alive'}=0;
312 $self->{_GLOBAL}{'Session'}=0;
313  
314 return $self;
315 }
316  
317 sub return_keep_alive
318 {
319 my ( $self ) = shift;
320 return $self->{_GLOBAL}{'KeepAlive'};
321 }
322  
323 sub construct_capabilities
324 {
325 my ( $self ) = shift;
326 my ( $required_capabilities ) = shift;
327  
328 my ($set_capabilities);
329 # This must be a hash pointer, so that we can then
330 # generate the value required.
331  
332 my ( %capabilities ) = (
333 'STRUCTURE' => 0x01,
334 'MULTISESSION' => 0x02,
335 'TEMPLATENEGO' => 0x03,
336 'REQUESTRESPONSE' => 0x04
337 );
338  
339 foreach my $requested ( keys %{$required_capabilities} )
340 { $set_capabilities+=$capabilities{$requested}; }
341 return $set_capabilities;
342 }
343  
344 sub create_vendor_id
345 {
346 my ($vendor_name) =@_;
347 my $utf8string = to_utf8({ -string => $vendor_name, -charset => 'ISO-8859-1' });
348 return $utf8string;
349 }
350  
351 sub generate_ipdr_message_header
352 {
353 my ( $self ) = shift;
354 my ( $version ) = shift;
355 my ( $message_id ) = shift;
356 my ( $length ) = shift;
357 # now we assume the length given is that of the payload
358 # we return the header, with the new length in the header.
359  
360 my ( $session_id );
361  
362 if ( $self->{_GLOBAL}{'Session'}>0 )
363 {
364 print "IPDR Header session is greater than 0 of '".$self->{_GLOBAL}{'Session'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
365 $session_id = $self->{_GLOBAL}{'Session'};
366 }
367 else
368 {
369 $session_id=0;
370 }
371  
372 print "IPDR Header session id is '".$session_id."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
373  
374 $message_id = _transpose_message_names($message_id);
375  
376 # We know the header is 8 long, so we need to add that to
377 # the length of the payload size, thus making the total
378 # correct.
379  
380 $length+=8;
381 my ($header) = pack("CCCCN", $version, $message_id, $session_id, 0, $length);
382 if ($self->{_GLOBAL}{'DEBUG'}>0 )
383 {
384 print "Version is '$version'\n";
385 print "Message type is '"._transpose_message_numbers($message_id)."'\n";
386 print "Message length is '$length'\n";
387 }
388 return ($header);
389 }
390  
391 sub return_current_type
392 {
393 my ( $self ) = shift;
394 my ( $test ) = $self->{_GLOBAL}{'current_data'};
395 if ( !$test ) { return ""; }
396 if ( !${$test}{'Type'} ) { return "NULL"; }
397 return ${$test}{'Type'};
398 }
399  
400 sub decode_message_type
401 {
402 my ( $self ) = shift;
403 $self->{_GLOBAL}{'current_data'}={};
404 my ( $decode_data ) = $self->{_GLOBAL}{'current_data'};
405 # First we get the version and type
406 # version is not important ( but might be later )
407 # type is the message ID
408 # session is the current session ID
409 # flags should always be 0 at the moment
410 # length is the total message length
411  
412 my ( $message ) = $self->{_GLOBAL}{'data_received'};
413  
414 if ( !$message ) { return 0; }
415 if ( length($message)<8 ) { return 0; }
416 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
417 { ${$decode_data}{'RAWDATARETURNED'}=$message; }
418 my ( $version, $type, $session, $flags, $length ) = unpack ("CCCCN",$message);
419 ${$decode_data}{'Version'}=$version;
420 ${$decode_data}{'Type'}=_transpose_message_numbers($type);
421 ${$decode_data}{'Session'}=$session;
422 ${$decode_data}{'Flags'}=$flags;
423 ${$decode_data}{'Length'}=$length;
424  
425 $self->{_GLOBAL}{'data_processing'}=0;
426  
427 if ( !${$decode_data}{'Type'} )
428 {
429 ${$decode_data}{'Type'}="";
430 }
431  
432 print "Message type in decoder is '".${$decode_data}{'Type'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
433 print "Message length in decode is '".${$decode_data}{'Length'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
434 print "Message length is '".length($message)."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
435  
436 if ( length($message)<${$decode_data}{'Length'} )
437 {
438 print "Data lengths are incorrect skipping data.\n" if $self->{_GLOBAL}{'DEBUG'}>0;
439 ${$decode_data}{'Type'}="DEAD";
440 return 1;
441 }
442  
443 print "Length of data received is '".length( $self->{_GLOBAL}{'data_received'} )."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
444  
445 $self->{_GLOBAL}{'data_received'} = substr( $self->{_GLOBAL}{'data_received'}, ${$decode_data}{'Length'},
446 length($self->{_GLOBAL}{'data_received'})-(${$decode_data}{'Length'}) );
447  
448 print "Length of data after new block is '".length( $self->{_GLOBAL}{'data_received'} )."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
449 if ( length($message)>${$decode_data}{'Length'} )
450 {
451 $self->{_GLOBAL}{'data_processing'}=1;
452 }
453  
454 $message=substr($message,8,length($message)-8);
455  
456 if ( ${$decode_data}{'Type'}=~/^connect_response$/i )
457 {
458 my ( $caps, $keepalive ) = unpack ( "SN",$message );
459 my ( $vendor ) = substr($message,6,length($message)-6);
460 ${$decode_data}{'Capabilities'}=$caps;
461 ${$decode_data}{'KeepAlive'}=$keepalive;
462 ${$decode_data}{'VendorID'}=$vendor;
463 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
464 {
465 print "Connect response decoded.\n";
466 foreach my $key ( keys %{$decode_data} )
467 {
468 next if $key=~/^RAWDATARETURNED$/i;
469 next if $key=~/^Next_Message$/i;
470 print "Variable is '$key' value is '${$decode_data}{$key}'\n";
471 }
472 }
473 return 1;
474 }
475  
476 if ( ${$decode_data}{'Type'}=~/^template_data$/i )
477 {
478 my ( $config, $template_flags,$something ) = unpack ( "SCN",$message );
479 ${$decode_data}{'Template_Config'} = $config;
480 ${$decode_data}{'Template_Flags'} = $template_flags;
481 ${$decode_data}{'Template_PreData'} = $something;
482 #${$decode_data}{'Template_Data'} = substr($message,7,length($message)-7);
483 $self->_extract_template_data( substr($message,7,length($message)-7), $self->{_GLOBAL}{'template'} );
484 #$self->_extract_template_data( substr($message,7,length($message)-7), $decode_data );
485 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
486 {
487 print "Template Data response decoded.\n";
488 foreach my $key ( keys %{$decode_data} )
489 {
490 next if $key=~/^RAWDATARETURNED$/i;
491 print "Variable is '$key' value is '${$decode_data}{$key}'\n";
492 }
493 foreach my $key ( keys %{$self->{_GLOBAL}{'template'}} )
494 {
495 print "Key is '$key'\n";
496 }
497 }
498 #$self->template_store( $template_info );
499 return 1;
500 }
501  
502 if ( ${$decode_data}{'Type'}=~/^session_start$/i )
503 {
504 my ( $uptime ) = unpack("N",$message); $message = substr($message,4,length($message)-4);
505 my ( $records ) = decode_64bit_number($message); $message = substr($message,8,length($message)-8);
506 my ( $gap_records ) = decode_64bit_number($message); $message = substr($message,8,length($message)-8);
507 my ( $primary, $ack_time, $ack_sequence, $document_id ) = unpack ( "CNNS",$message );
508  
509 ${$decode_data}{'Uptime'} = $uptime;
510 ${$decode_data}{'Records'} = $records;
511 ${$decode_data}{'GapRecords'} = $gap_records;
512 ${$decode_data}{'Primary'} = $primary;
513 ${$decode_data}{'AckTime'} = $ack_time;
514 ${$decode_data}{'AckSequence'} = $ack_sequence;
515 ${$decode_data}{'DocumentID'} = $document_id;
516  
517 # added timer for acktime
518 # Added some timer margin so AckTime should not fail
519 my ( $margin_time ) = $ack_time*0.05;
520 if ( $margin_time>15 ) { $margin_time=15; }
521 $ack_time = $ack_time-$margin_time;
522 if ( !$self->{_GLOBAL}{'AckTime'} || $self->{_GLOBAL}{'AckTime'}==0 || $ack_time<$self->{_GLOBAL}{'AckTime'})
523 {
524 $self->{_GLOBAL}{'AckTime'} = $ack_time;
525 print "Ack time is set to '".$self->{_GLOBAL}{'AckTime'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
526 }
527  
528 if ( !$self->{_GLOBAL}{'AckSequence'} || $self->{_GLOBAL}{'AckSequence'}==0 || $ack_sequence<$self->{_GLOBAL}{'AckSequence'} )
529 {
530 $self->{_GLOBAL}{'AckSequence'} = $ack_sequence;
531 print "Ack time is set to '".$self->{_GLOBAL}{'AckSequence'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
532 }
533  
534 if ( $self->{_GLOBAL}{'AckSequenceOverride'}>0 )
535 {
536 $self->{_GLOBAL}{'AckSequence'} = $self->{_GLOBAL}{'AckSequenceOverride'};
537 }
538
539 if ( $self->{_GLOBAL}{'AckTimeOverride'} > 0 )
540 {
541 $self->{_GLOBAL}{'AckTime'} = $self->{_GLOBAL}{'AckTimeOverride'};
542 }
543  
544 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
545 {
546 print "Session start decoded.\n";
547 foreach my $key ( keys %{$decode_data} )
548 {
549 next if $key=~/^RAWDATARETURNED$/i;
550 print "Variable is '$key' value is '${$decode_data}{$key}'\n";
551 }
552 }
553 return 1;
554 }
555  
556 if ( ${$decode_data}{'Type'}=~/^get_sessions_response$/i )
557 {
558 # There is something odd here, the spec says it should be a short
559 # the data returned signifies an int ...
560 my ( $request_id ) = unpack ("S",$message );
561 print "Request id is '$request_id'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
562 ${$decode_data}{'SESSIONS_RequestID'} = $request_id;
563 $self->_extract_session_data( substr($message,2,length($message)-2), $self->{_GLOBAL}{'sessioninfo'} );
564 $self->update_session_parameters();
565 return 1;
566 }
567  
568 if ( ${$decode_data}{'Type'}=~/^data$/i )
569 {
570 if ( !$self->{_GLOBAL}{'data_capture_running'} )
571 {
572 $self->{_GLOBAL}{'data_capture_running_time'}=time();
573 $self->{_GLOBAL}{'data_capture_running'}=0;
574 }
575 if ( !$self->{_GLBOAL}{'data_capture_keep_alive'} )
576 {
577 $self->{_GLBOAL}{'data_capture_keep_alive'}=time();
578 }
579  
580 $self->{_GLOBAL}{'data_capture_running'}++;
581 $self->{_GLOBAL}{'data_capture_data_count'}++;
582 my ( $template_id, $config_id, $flags ) = unpack("SSC",$message);
583 $message = substr($message,5,length($message)-5);
584 my ( $sequence_num ) = decode_64bit_number($message); $message = substr($message,8,length($message)-8);
585 my ( $record_type );
586 ${$decode_data}{'DATA_TemplateID'}=$template_id;
587 ${$decode_data}{'DATA_ConfigID'}=$config_id;
588 ${$decode_data}{'DATA_Flags'}=$flags;
589 ${$decode_data}{'DATA_Sequence'}=$sequence_num;
590 ${$decode_data}{'DATA_Data'} = $message;
591 print "Data Epoch is '".time()."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
592 print "TemplateID is '${$decode_data}{'DATA_TemplateID'}'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
593 print "ConfigID is '${$decode_data}{'DATA_ConfigID'}'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
594 print "Flags is '${$decode_data}{'DATA_Flags'}'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
595 print "Sequence is '${$decode_data}{'DATA_Sequence'}'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
596 #${$decode_data}{'records'}=_decode_data_record( ${$decode_data}{'DATA_Data'} );
597 return 1;
598 }
599  
600 if ( ${$decode_data}{'Type'}=~/^session_stop$/i )
601 {
602 my ( $reason_code ) = unpack ("S", $message ); $message = substr($message,2,length($message)-2);
603 my ( $reason , $message ) = _extract_utf8_string ( $message );
604 ${$decode_data}{'reasonCode'} = $reason_code;
605 ${$decode_data}{'reason'} = $reason;
606 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
607 {
608 print "SessionStop response decoded.\n";
609 foreach my $key ( keys %{$decode_data} )
610 {
611 next if $key=~/^RAWDATARETURNED$/i;
612 print "Variable is '$key' value is '${$decode_data}{$key}'\n";
613 }
614 }
615 return 1;
616 }
617  
618 if ( ${$decode_data}{'Type'}=~/^error$/i )
619 {
620 my ( $time, $error_code ) = unpack ("NS",$message ) ; $message = substr($message,6,length($message)-6);
621 my ( $reason , $message ) = _extract_utf8_string ( $message );
622 ${$decode_data}{'timeStamp'} = $time;
623 ${$decode_data}{'errorCode'} = $error_code;
624 ${$decode_data}{'reason'} = $reason;
625 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
626 {
627 print "Error response decoded.\n";
628 foreach my $key ( keys %{$decode_data} )
629 {
630 next if $key=~/^RAWDATARETURNED$/i;
631 print "Variable is '$key' value is '${$decode_data}{$key}'\n";
632 }
633 }
634 return 1;
635 }
636  
637 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
638 {
639 print "Message received '${$decode_data}{'Type'}'\n";
640 }
641  
642 return 0;
643 }
644  
645 sub send_disconnect
646 {
647 my ( $self ) = shift;
648 my ( $data ) = shift;
649 my ( $result ) = $self->send_message( $self->construct_disconnect() );
650 return $result;
651 }
652  
653 sub send_flow_stop
654 {
655 my ( $self ) = shift;
656 my ( $data ) = shift;
657 my ( $code ) = shift;
658 my ( $reason ) = shift;
659 my ( $result ) = $self->send_message( $self->construct_flow_stop($code,$reason) );
660 return $result;
661 }
662  
663 sub max_records_segment
664 {
665 my ( $self ) = shift;
666 $self->{_GLOBAL}{'data_capture_running'}=0;
667 my $child;
668 if ($child=fork)
669 { } elsif (defined $child)
670 {
671 my $xml_transform;
672 #print "Remote IP is '".$self->{_GLOBAL}{'RemoteIP'}."'\n";
673 #print "Remote Port is '".$self->{_GLOBAL}{'RemotePort'}."'\n";
674 if ( ($self->{_GLOBAL}{'RemoteIP'} &&
675 $self->{_GLOBAL}{'RemotePort'}) || length($self->{_GLOBAL}{'XMLDirectory'})>5 )
676 {
677 print "Transformed into XML\n\n$xml_transform\n\n" if $self->{_GLOBAL}{'DEBUG'}>0;
678 $xml_transform = $self->_transform_into_xml($self->{_GLOBAL}{'complete_decoded_data'});
679 }
680 if ( $self->{_GLOBAL}{'RemoteIP'} && $self->{_GLOBAL}{'RemotePort'} )
681 {
682 $self->_send_to_clear_destination ($xml_transform);
683 }
684 if ( length($self->{_GLOBAL}{'XMLDirectory'})>5 )
685 {
686 if ( open (__FILE,">".$self->{_GLOBAL}{'XMLDirectory'}."/".$$self->{_GLOBAL}{'ServerIP'} ) )
687 {
688 print __FILE $xml_transform;
689 close __FILE;
690 }
691 }
692 $self->{_GLOBAL}{'DataHandler'}->(
693 $self->{_GLOBAL}{'ServerIP'},
694 $self->{_GLOBAL}{'ServerPort'},
695 $self->{_GLOBAL}{'complete_decoded_data'},
696 $self
697 );
698 waitpid($child,0);
699 exit(0);
700 }
701 $self->{_GLOBAL}{'current_data'}={};
702 $self->{_GLOBAL}{'complete_decoded_data'}={};
703 return 1;
704 }
705  
706  
707 sub send_get_keepalive
708 {
709 my ( $self ) = shift;
710 my ( $data ) = shift;
711 if ( $self->get_internal_value('data_ack') )
712 {
713 print "Data ACK is set\n" if $self->{_GLOBAL}{'DEBUG'}>0;
714 $self->send_data_ack(
715 $self->get_internal_value('dsn_configID'),
716 $self->get_internal_value('dsn_sequence')
717 );
718 # we also need to reset the capture_count
719 $self->{_GLOBAL}{'data_capture_running'}=0;
720 $self->{_GLOBAL}{'data_capture_running_time'}=0;
721 $self->{_GLOBAL}{'data_capture_data_count'}=0;
722  
723 # here we need to add the remote sending of the extracted
724 # data. More than likely a fork is required so not to stall
725 # the collection process. A fork maybe needed anyway as if
726 # the dataset exceeds, say 10,000 entries ( easily done )
727 # and being processed locally, any data store *may* not be
728 # quick enough.
729 my $child;
730 if ($child=fork)
731 { } elsif (defined $child)
732 {
733 my $xml_transform="";
734 #print "Remote IP is '".$self->{_GLOBAL}{'RemoteIP'}."'\n";
735 #print "Remote Port is '".$self->{_GLOBAL}{'RemotePort'}."'\n";
736 if ( ($self->{_GLOBAL}{'RemoteIP'} &&
737 $self->{_GLOBAL}{'RemotePort'}) || length($self->{_GLOBAL}{'XMLDirectory'})>5 )
738 {
739 print "Transformed into XML\n\n$xml_transform\n\n" if $self->{_GLOBAL}{'DEBUG'}>0;
740 $xml_transform = $self->_transform_into_xml($self->{_GLOBAL}{'complete_decoded_data'});
741 }
742 if ( $self->{_GLOBAL}{'RemoteIP'} && $self->{_GLOBAL}{'RemotePort'} )
743 {
744 $self->_send_to_clear_destination ($xml_transform);
745 }
746  
747 if ( length($self->{_GLOBAL}{'XMLDirectory'})>5 )
748 {
749 if ( open (__FILE,">".$self->{_GLOBAL}{'XMLDirectory'}."/".$$self->{_GLOBAL}{'ServerIP'} ) )
750 {
751 print __FILE $xml_transform;
752 close __FILE;
753 }
754 }
755  
756 $self->{_GLOBAL}{'DataHandler'}->(
757 $self->{_GLOBAL}{'ServerIP'},
758 $self->{_GLOBAL}{'ServerPort'},
759 $self->{_GLOBAL}{'complete_decoded_data'},
760 $self
761 );
762 waitpid($child,0);
763 exit(0);
764 }
765  
766 $self->{_GLOBAL}{'complete_decoded_data'}={};
767 $self->set_internal_value('data_ack',0);
768 $self->{_GLOBAL}{'current_data'}={};
769 }
770  
771 my ( $result ) = $self->send_message( $self->construct_get_keepalive() );
772 return $result;
773 }
774  
775 sub send_get_sessions
776 {
777 my ( $self ) = shift;
778 my ( $data ) = shift;
779 my ( $result ) = $self->send_message( $self->construct_get_sessions() );
780 return $result;
781 }
782  
783 sub send_data_ack
784 {
785 my ( $self ) = shift;
786 my ( $config_id ) = shift;
787 my ( $seq_number ) = shift;
788 print "ACK data config_id is '$config_id' sequence number is '$seq_number'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
789 my ( $result ) = $self->send_message( $self->construct_data_ack($config_id,$seq_number) );
790 return $result;
791 }
792  
793 sub send_final_template_data_ack
794 {
795 my ( $self ) = shift;
796 my ( $data ) = shift;
797 my ( $result ) = $self->send_message( $self->construct_final_template_data_ack() );
798 return $result;
799 }
800  
801 sub send_flow_start_message
802 {
803 my ( $self ) = shift;
804 my ( $data ) = shift;
805 my ( $result ) = $self->send_message( $self->construct_flow_start() );
806 return $result;
807 }
808  
809 sub send_connect_message
810 {
811 my ( $self ) = shift;
812 my $result = $self->send_message( $self->construct_connect_message() );
813 return $result;
814 }
815  
816 sub construct_data_ack
817 {
818 my ( $self ) = shift;
819 my ( $config_id ) = shift;
820 my ( $sequence ) = shift;
821 print "Constructed id is '$config_id'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
822 print "Constructed sequence us '$sequence'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
823 my ( $message ) = pack("S",$config_id);
824 my ( $sequence_encode ) = encode_64bit_number($sequence);
825 $message.=$sequence_encode;
826 if ( $self->{_GLOBAL}{'DEBUG'}>0 )
827 {
828 print "Packed message is - " if $self->{_GLOBAL}{'DEBUG'}>0;
829 for($a=0;$a<length($message);$a++)
830 {
831 print ord (substr($message,$a,1))." ";
832 }
833 print "\n";
834 }
835  
836 my ( $header ) = $self->generate_ipdr_message_header(
837 2,"DATA_ACK",length($message));
838 $header.=$message;
839 return $header;
840 }
841  
842  
843 sub construct_final_template_data_ack
844 {
845 my ( $self ) = shift;
846 my ( $header ) = $self->generate_ipdr_message_header(
847 2,"FINAL_TEMPLATE_DATA_ACK",0);
848 return $header;
849 }
850  
851 sub construct_flow_stop
852 {
853 my ( $self ) = shift;
854 my ( $code ) = shift;
855 my ( $reason ) = shift;
856 my ( $message ) = pack("S",$code); $message.=$reason;
857 my ( $header ) = $self->generate_ipdr_message_header(
858 2,"FLOW_STOP",length($message));
859 $header.=$message;
860 return $header;
861 }
862  
863 sub construct_disconnect
864 {
865 my ( $self ) = shift;
866 my ( $header ) = $self->generate_ipdr_message_header(
867 2,"DISCONNECT",0);
868 return $header;
869 }
870  
871  
872 sub construct_get_sessions
873 {
874 my ( $self ) = shift;
875 my ( $message ) = pack("S",4096);
876 my ( $header ) = $self->generate_ipdr_message_header(
877 2,"GET_SESSIONS",length($message));
878 $header.=$message;
879 return $header;
880 }
881  
882 sub construct_get_keepalive
883 {
884 my ( $self ) = shift;
885 my ( $header ) = $self->generate_ipdr_message_header(
886 2,"KEEP_ALIVE",0);
887 return $header;
888 }
889  
890  
891 sub construct_flow_start
892 {
893 my ( $self ) = shift;
894 if ( !$self->create_initiator_id() )
895 { return 0; }
896 my ( $header ) = $self->generate_ipdr_message_header(
897 2,"FLOW_START",0);
898 return $header;
899 }
900  
901 sub construct_connect_message
902 {
903 my ( $self ) = shift;
904  
905 if ( !$self->create_initiator_id() )
906 {
907 return 0;
908 }
909 # so we know all the below
910 my ( $message ) = pack("NSNN",
911 $self->create_initiator_id(),
912 $self->{_GLOBAL}{'LocalPort'},
913 $self->{_GLOBAL}{'Capabilities'},
914 $self->{_GLOBAL}{'KeepAlive'} );
915 $message.=$self->{_GLOBAL}{'VendorID'};
916 my ( $header ) = $self->generate_ipdr_message_header(
917 2,"CONNECT",length($message));
918 $header.=$message;
919  
920 return $header;
921 }
922  
923 sub disconnect
924 {
925 my ( $self ) = shift;
926 $self->{_GLOBAL}{'Handle'}->close();
927 return 1;
928 }
929  
930 sub connect
931 {
932 my ( $self ) = shift;
933  
934 if ( !$self->test_64_bit() )
935 {
936 # if you forgot to run make test, this will clobber
937 # your run anyway.
938 if ( $self->{_GLOBAL}{'Warning64BitOff'}!=1 )
939 {
940 warn '64Bit support not available using BigInt - Milleage will vary! Turn off with Warning64BitOff => 1.';
941 }
942 }
943  
944 my $lsn;
945  
946 if ( length($self->{_GLOBAL}{'LocalAddr'})>0 )
947 {
948 $lsn = IO::Socket::INET->new
949 (
950 PeerAddr => $self->{_GLOBAL}{'ServerIP'},
951 PeerPort => $self->{_GLOBAL}{'ServerPort'},
952 LocalAddr => $self->{_GLOBAL}{'LocalAddr'},
953 ReuseAddr => 1,
954 Proto => 'tcp',
955 Timeout => $self->{_GLOBAL}{'Timeout'}
956 );
957 }
958 else
959 {
960 $lsn = IO::Socket::INET->new
961 (
962 PeerAddr => $self->{_GLOBAL}{'ServerIP'},
963 PeerPort => $self->{_GLOBAL}{'ServerPort'},
964 ReuseAddr => 1,
965 Proto => 'tcp',
966 Timeout => $self->{_GLOBAL}{'Timeout'}
967 );
968 }
969 if (!$lsn)
970 {
971 $self->{_GLOBAL}{'STATUS'}="Failed To Connect";
972 $self->{_GLOBAL}{'ERROR'}=$!;
973 return 0;
974 }
975  
976 if ( length($self->{_GLOBAL}{'InitiatorID'})>0 )
977 {
978 $self->{_GLOBAL}{'LocalIP'}=$self->{_GLOBAL}{'InitiatorID'};
979 }
980 else
981 {
982 $self->{_GLOBAL}{'LocalIP'}=$lsn->sockhost();
983 }
984 $self->{_GLOBAL}{'LocalPort'}=$lsn->sockport();
985 $self->{_GLOBAL}{'Handle'} = $lsn;
986 $self->{_GLOBAL}{'Selector'}=new IO::Select( $lsn );
987 $self->{_GLOBAL}{'STATUS'}="Success Connected";
988  
989 $self->{_GLOBAL}{'data_ack'}=0;
990 $self->{_GLOBAL}{'ERROR'}="" ;
991 $self->{_GLOBAL}{'data_processing'}=0;
992  
993 $self->{_GLOBAL}{'template'}= {};
994 $self->{_GLOBAL}{'sessioninfo'}= {};
995 $self->{_GLOBAL}{'current_data'}= {};
996 $self->{_GLOBAL}{'complete_decoded_data'} = {};
997  
998 $self->{_GLOBAL}{'AckTime'}=0;
999 $self->{_GLOBAL}{'AckSequence'}=0;
1000 $self->{_GLOBAL}{'data_capture_running'}=0;
1001 $self->{_GLOBAL}{'data_capture_running_time'}=0;
1002 $self->{_GLOBAL}{'data_capture_data_count'}=0;
1003 $self->{_GLOBAL}{'data_capture_keep_alive'}=0;
1004 $self->{_GLOBAL}{'Session'}=0;
1005  
1006 if ( $self->{_GLOBAL}{'DEBUG'} > 0 )
1007 {
1008 my $test = $self->{_GLOBAL};
1009 foreach my $setting ( keys %{$test} )
1010 {
1011 print "Global setting '$setting' value is '${$test}{$setting}'\n";
1012 }
1013 }
1014  
1015 return 1;
1016 }
1017  
1018 sub connected
1019 {
1020 my ( $self ) = shift;
1021 return $self->{_GLOBAL}{'Selector'};
1022 }
1023  
1024 sub send_message
1025 {
1026 my ( $self ) = shift;
1027 my ( $message ) = shift;
1028 if ( !$self->{_GLOBAL}{'Handle'} ) { return 0; }
1029 my ( $length_sent ) = 0;
1030 eval {
1031 local $SIG{ALRM} = sub { die "alarm\n" };
1032 alarm 5;
1033 $length_sent = syswrite ( $self->{_GLOBAL}{'Handle'}, $message );
1034 alarm 0;
1035 };
1036  
1037 if ( $@=~/alarm/i )
1038 { return 0; }
1039  
1040 print "Sending message of size '".length($message)."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1041  
1042 if ( $self->{_GLOBAL}{'DEBUG'}>4 )
1043 {
1044 for($a=0;$a<length($message);$a++)
1045 {
1046 printf("%02x-", ord(substr($message,$a,2)));
1047 }
1048 print "\n";
1049 }
1050  
1051 if ( $length_sent==length($message) )
1052 { return 1; }
1053 return 0;
1054 }
1055  
1056 sub create_initiator_id
1057 {
1058 my ( $self ) = @_;
1059 my ( $initiator_id ) = $self->_IpQuadToInt( $self->{_GLOBAL}{'LocalIP'} );
1060 return $initiator_id;
1061 }
1062  
1063 sub _IpQuadToInt
1064 {
1065 my ($self)= shift;
1066 my($Quad) = shift;
1067 if ( !$Quad ) { return 0; }
1068 my($Ip1, $Ip2, $Ip3, $Ip4) = split(/\./, $Quad);
1069 my($IpInt) = (($Ip1 << 24) | ($Ip2 << 16) | ($Ip3 << 8) | $Ip4);
1070 return($IpInt);
1071 }
1072  
1073 sub _IpIntToQuad { my($Int) = @_;
1074 my($Ip1) = $Int & 0xFF; $Int >>= 8;
1075 my($Ip2) = $Int & 0xFF; $Int >>= 8;
1076 my($Ip3) = $Int & 0xFF; $Int >>= 8;
1077 my($Ip4) = $Int & 0xFF; return("$Ip4.$Ip3.$Ip2.$Ip1");
1078 }
1079  
1080 sub _message_types
1081 {
1082 my ( %messages ) = (
1083 'FLOW_START' => 0x01,
1084 'FLOW_STOP' => 0x03,
1085 'CONNECT' => 0x05,
1086 'CONNECT_RESPONSE' => 0x06,
1087 'DISCONNECT' => 0x07,
1088 'SESSION_START' => 0x08,
1089 'SESSION_STOP' => 0x09,
1090 'KEEP_ALIVE' => 0x40,
1091 'TEMPLATE_DATA' => 0x10,
1092 'MODIFY_TEMPLATE' => 0x1a,
1093 'MODIFY_TEMPLATE_RESPONSE' => 0x1b,
1094 'FINAL_TEMPLATE_DATA_ACK' => 0x13,
1095 'START_NEGOTIATION' => 0x1d,
1096 'START_NEGOTIATION_REJECT' => 0x1e,
1097 'GET_SESSIONS' => 0x14,
1098 'GET_SESSIONS_RESPONSE' => 0x15,
1099 'GET_TEMPLATES' => 0x16,
1100 'GET_TEMPLATES_RESPONSE' => 0x17,
1101 'DATA' => 0x20,
1102 'DATA_ACK' => 0x21,
1103 'ERROR' => 0x23,
1104 'REQUEST' => 0x30,
1105 'RESPONSE' => 0x31
1106 );
1107 return \%messages;
1108 }
1109  
1110 sub _transpose_message_numbers
1111 {
1112 my ( $message_number ) =@_;
1113 my $messages = _message_types();
1114 my %reverse_pack;
1115 foreach my $message ( keys %{$messages} )
1116 { $reverse_pack{ ${$messages}{$message} } = $message; }
1117 return $reverse_pack{$message_number};
1118 }
1119  
1120 sub _transpose_message_names
1121 {
1122 my ( $message_name ) =@_;
1123 my $messages = _message_types();
1124 return ${$messages}{$message_name};
1125 }
1126  
1127 sub _extract_session_data
1128 {
1129 my ( $self ) = shift;
1130 my ( $session_data ) = shift;
1131 my ( $session_extract ) = shift;
1132  
1133 print "Length of session data is '".length($session_data)."'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1134 if ( $self->{_GLOBAL}{'DEBUG'}>4 )
1135 {
1136 print "Session data segment - ";
1137 for($a=0;$a<length($session_data);$a++)
1138 {
1139 printf("%02x-", ord(substr($session_data,$a,2)));
1140 }
1141 print "\n";
1142 }
1143 my ( $sessions_count ) = unpack("N",$session_data);
1144 $session_data = substr($session_data,4,length($session_data)-4);
1145  
1146 print "Sessions count '$sessions_count'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1147 for ( my $session_decode=0; $session_decode<$sessions_count; $session_decode++ )
1148 {
1149 my ( $session_id, $reserved ) = unpack("CC",$session_data);
1150 my ( $sessionName ) = "";
1151 my ( $sessionDescription ) = "";
1152 my ( $ackTime ) = 0;
1153 my ( $ackSeq ) = 0 ;
1154  
1155 $session_data = substr($session_data,2,length($session_data)-2);
1156  
1157 ( $sessionName, $session_data ) = _extract_utf8_string ( $session_data );
1158 ( $sessionDescription, $session_data ) = _extract_utf8_string ( $session_data );
1159 ( $ackTime, $ackSeq ) = unpack ("NN", $session_data );
1160  
1161 print "Session id is '$session_id'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1162 print "Session name is '$sessionName'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1163 print "Session description is '$sessionDescription'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1164 print "Session ackTime '$ackTime'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1165 print "Session ackSeq '$ackSeq'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1166  
1167 ${$session_extract}{$session_decode}{'SessionID'} = $session_id;
1168 ${$session_extract}{$session_decode}{'SessionName'} = $sessionName;
1169 ${$session_extract}{$session_decode}{'SessionDescription'} = $sessionDescription;
1170 ${$session_extract}{$session_decode}{'ackTime'} = $ackTime;
1171 ${$session_extract}{$session_decode}{'ackSeq'} = $ackSeq;
1172  
1173 $session_data = substr($session_data,8,length($session_data)-8);
1174  
1175 }
1176 return 1;
1177 }
1178  
1179 sub update_session_parameters
1180 {
1181 my ( $self ) = shift;
1182 my ( $session_extract ) = $self->{_GLOBAL}{'sessioninfo'};
1183 my ( $debug ) = $self->{_GLOBAL}{'DEBUG'};
1184 my ( @sessions ) = keys %{$session_extract};
1185 my ( $session_name_lock ) = 0;
1186  
1187 print "Session Update\n\n" if $debug>0;
1188 print "Number of sessions is '".scalar(@sessions)."'\n" if $debug>0;
1189  
1190 if ( $debug>0 )
1191 {
1192 if ( scalar(@sessions)>1 )
1193 {
1194 print "More than one session found. Using First.\n";
1195 print "Or selecting by name if configured.\n";
1196 }
1197 }
1198  
1199 if ( length($self->{_GLOBAL}{'SessionName'})>2 )
1200 {
1201 foreach my $sessions ( keys %{$session_extract} )
1202 {
1203 if ( ${$session_extract}{$sessions}{'SessionName'} eq $self->{_GLOBAL}{'SessionName'} )
1204 {
1205 print "Session name locked to value '".$sessions."'\n" if $debug>3;
1206 $session_name_lock = $sessions;
1207 }
1208 }
1209 }
1210  
1211 print "Session Update\n\n" if $debug>0;
1212  
1213 print "Session name in use is '".${$session_extract}{$session_name_lock}{'SessionName'}."'\n" if $debug>0;
1214 print "Session description in use us '".${$session_extract}{$session_name_lock}{'SessionDescription'}."'\n" if $debug>0;
1215  
1216 $self->{_GLOBAL}{'AckSequence'} = ${$session_extract}{$session_name_lock}{'ackSeq'};
1217 print "Setting Ack Seq to '".$self->{_GLOBAL}{'AckSequence'}."'\n" if $debug>0;
1218  
1219 my ( $margin_time ) = ${$session_extract}{$session_name_lock}{'ackTime'}*0.05;
1220 if ( $margin_time>15 ) { $margin_time=15; }
1221 if ( !$self->{_GLOBAL}{'AckTime'} || $self->{_GLOBAL}{'AckTime'}==0 )
1222 {
1223 $self->{_GLOBAL}{'AckTime'} = ${$session_extract}{$session_name_lock}{'ackTime'}-$margin_time;
1224 print "Ack time is set to '".$self->{_GLOBAL}{'AckTime'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1225 }
1226  
1227 if ( !$self->{_GLOBAL}{'Session'} || $self->{_GLOBAL}{'Session'}==0 )
1228 {
1229 $self->{_GLOBAL}{'Session'} = ${$session_extract}{$session_name_lock}{'SessionID'};
1230 print "Session ID is set to '".$self->{_GLOBAL}{'Session'}."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1231 }
1232  
1233 print "Session Update\n\n" if $debug>0;
1234  
1235 return 1;
1236 }
1237  
1238  
1239 sub _extract_template_data
1240 {
1241 my ( $self ) = shift;
1242 my ( $template_data ) = shift;
1243 my ( $template_extract) = shift;
1244  
1245 my ( $record_type );
1246 my ( $record_configuration );
1247 my ( $field_id, $field_count, $field_name, $field_enabled );
1248  
1249 while ( length($template_data)>10 )
1250 {
1251 my ( $template_id ) = unpack("S",$template_data);
1252 $template_data=substr($template_data,2,length($template_data)-2);
1253  
1254 print "Template found is '$template_id'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1255  
1256 ( $record_type, $template_data ) = _extract_utf8_string ( $template_data );
1257 ( $record_configuration , $template_data ) = _extract_utf8_string ( $template_data );
1258  
1259 ${$template_extract}{'Templates'}{$template_id}{'schemaName'}=$record_type;
1260 ${$template_extract}{'Templates'}{$template_id}{'typeName'}=$record_configuration;
1261  
1262 print "schemaName found is '$record_type'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1263 print "typeName found is '$record_configuration'\n" if $self->{_GLOBAL}{'DEBUG'}>1;
1264  
1265 ( $field_count ) = unpack("N", $template_data ); $template_data=substr($template_data,4,length($template_data)-4);
1266  
1267 ${$template_extract}{'Templates'}{$template_id}{'fieldCount'}=$field_count;
1268  
1269 for ($a=0;$a<$field_count;$a++)
1270 {
1271 my ( $typeid, $fieldid ) = unpack("NN",$template_data);
1272 $template_data=substr($template_data,8,length($template_data)-8);
1273 ( $field_name , $template_data ) = _extract_utf8_string ( $template_data );
1274 ( $field_enabled ) = unpack("C",$template_data);
1275 $template_data=substr($template_data,1,length($template_data)-1);
1276 ${$template_extract}{'Templates'}{$template_id}{'fields'}{$a}{'name'}=$field_name;
1277 ${$template_extract}{'Templates'}{$template_id}{'fields'}{$a}{'typeID'}=$typeid;
1278 ${$template_extract}{'Templates'}{$template_id}{'fields'}{$a}{'fieldID'}=$fieldid;
1279 ${$template_extract}{'Templates'}{$template_id}{'fields'}{$a}{'enabled'}=$field_enabled;
1280 print "Field name '$field_name' type '$typeid' fieldid '$fieldid' enabled '$field_enabled' count '$a'\n"
1281 if $self->{_GLOBAL}{'DEBUG'}>1;
1282 }
1283 }
1284 return 1;
1285 }
1286  
1287 sub _extract_utf8_string
1288 {
1289 my ( $data ) = @_;
1290 my ( $string_len ) = unpack("N",$data); $data=substr($data,4,length($data)-4);
1291 my ( $new_string ) = substr($data,0,$string_len);
1292 #print "String length is '$string_len' string is '$new_string'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1293 if ( ( length($data)-$string_len ) < 0 )
1294 {
1295 $data="";
1296 }
1297 else
1298 {
1299 $data=substr($data,$string_len,length($data)-$string_len);
1300 }
1301 return ($new_string,$data);
1302 }
1303  
1304 sub _extract_ip_string
1305 {
1306 my ( $data ) = @_;
1307 my ( $new_string );
1308 if ( !$data ) { return ("",""); }
1309 ( $new_string, $data ) = _extract_int_u ( $data );
1310 ( $new_string ) = _IpIntToQuad ( $new_string );
1311 return ($new_string,$data);
1312 }
1313  
1314 sub _extract_int_u
1315 {
1316 # This is forced to be 32bits wide.
1317 my ( $data ) = @_;
1318 if ( length($data)<4 )
1319 {
1320 return ( length($data), $data );
1321 }
1322 my ( $ip_int ) = unpack("N",$data); $data=substr($data,4,length($data)-4);
1323 return ($ip_int,$data);
1324 }
1325  
1326 sub _extract_boolean
1327 {
1328 my ( $data ) = @_;
1329 my ( $char);
1330 ( $char, $data ) = _extract_char($data);
1331 return ($char,$data);
1332 }
1333  
1334 sub _extract_double
1335 {
1336 my ( $data ) = @_;
1337 if ( length($data)<8 )
1338 {
1339 return ( length($data), $data );
1340 }
1341 my ( $ip_int ) = unpack("NN",$data); $data=substr($data,8,length($data)-8);
1342 return ($ip_int,$data);
1343 }
1344  
1345 sub _extract_float
1346 {
1347 # This is forced to be a single precision float
1348 # the specification makes no reference to the
1349 # float type.
1350 my ( $data ) = @_;
1351 if ( length($data)<4 )
1352 {
1353 return ( length($data), $data );
1354 }
1355 my ( $ip_int ) = unpack("f",$data); $data=substr($data,4,length($data)-4);
1356 return ($ip_int,$data);
1357 }
1358  
1359 sub _extract_int
1360 {
1361 my ( $self ) = shift;
1362 my ( $data ) = shift;
1363 if ( length($data)<4 )
1364 {
1365 return ( length($data), $data );
1366 }
1367 my ( $flash_data ) = substr($data,1,4);
1368 if ( $self->{_GLOBAL}{'DEBUG'} == 5 )
1369 {
1370 print "data is ".sprintf("%02x%02x%02x%02x",ord(substr($flash_data,1,1)),ord(substr($flash_data,2,1)),ord(substr($flash_data,3,1)),
1371 ord(substr($flash_data,4,1)) );
1372 }
1373 if ( $self->{_GLOBAL}{'BigLittleEndian'}==1 )
1374 { $flash_data = _reverse_pattern($flash_data); }
1375 if ( $self->{_GLOBAL}{'DEBUG'} == 5 )
1376 {
1377 print "data is ".sprintf("%02x%02x%02x%02x",ord(substr($flash_data,1,1)),ord(substr($flash_data,2,1)),ord(substr($flash_data,3,1)),
1378 ord(substr($flash_data,4,1)) );
1379 }
1380  
1381 my ( $ip_int ) = unpack("I",$flash_data); $data=substr($data,4,length($data)-4);
1382 return ($ip_int,$data);
1383 }
1384  
1385 sub _extract_short
1386 {
1387 my ( $data ) = @_;
1388 my ( $ip_int ) = unpack("S",$data); $data=substr($data,2,length($data)-2);
1389 return ($ip_int,$data);
1390 }
1391  
1392 sub _extract_short_u
1393 {
1394 my ( $data ) = @_;
1395 my ( $ip_int ) = unpack("S",$data); $data=substr($data,2,length($data)-2);
1396 return ($ip_int,$data);
1397 }
1398  
1399 sub _extract_datetimeusec
1400 {
1401 my ( $data ) = @_;
1402  
1403 my ($part1,$part2) = unpack("NN",$data);
1404 $part1 = $part1<<32;
1405 $part1+=$part2;
1406  
1407 $data=substr($data,8,length($data)-8);
1408  
1409 return ($part1, $data);
1410 }
1411  
1412 sub _extract_uuid
1413 {
1414 my ( $data ) = @_;
1415  
1416 my ($length,$one_o, $one_t, $two_o, $two_t, $three_o, $three_t,
1417 $four_o, $four_t, $five_o, $five_t, $six_o, $six_t,
1418 $seven_o, $seven_t, $eight_o, $eight_t) = unpack("NCCCCCCCCCCCCCCCC",$data );
1419  
1420 my ($ipv6addr) = sprintf("%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x",
1421 $one_o, $one_t, $two_t, $two_t,
1422 $three_o, $three_t, $four_o, $four_t,
1423 $five_o, $five_t, $six_o, $six_t,
1424 $seven_o, $seven_t, $eight_o, $eight_t);
1425  
1426 $data=substr($data,20,length($data)-20);
1427 return ($ipv6addr,$data);
1428 }
1429  
1430 sub _extract_ipaddr
1431 {
1432 my ( $data ) = @_;
1433 my ( $length ) = unpack("N",$data);
1434 my ( $ipaddr ) = "";
1435 if ( $length == 16 )
1436 { ( $ipaddr, $data ) = _extract_ipv6addr ( $data ); }
1437  
1438 if ( $length == 4 )
1439 { ( $ipaddr, $data ) = _extract_ip_string ( $data ); }
1440  
1441 return ( $ipaddr , $data );
1442 }
1443  
1444 sub _extract_ipv6addr
1445 {
1446 my ( $data ) = @_;
1447  
1448 my ($length,$one_o, $one_t, $two_o, $two_t, $three_o, $three_t,
1449 $four_o, $four_t, $five_o, $five_t, $six_o, $six_t,
1450 $seven_o, $seven_t, $eight_o, $eight_t) = unpack("NCCCCCCCCCCCCCCCC",$data );
1451  
1452 my ($ipv6addr) = sprintf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
1453 $one_o, $one_t, $two_t, $two_t,
1454 $three_o, $three_t, $four_o, $four_t,
1455 $five_o, $five_t, $six_o, $six_t,
1456 $seven_o, $seven_t, $eight_o, $eight_t);
1457  
1458 $data=substr($data,20,length($data)-20);
1459 return ($ipv6addr,$data);
1460 }
1461  
1462 sub _extract_unknown
1463 {
1464 my ( $data, $count ) = @_;
1465 ( $count ) = (split(/\_/,$count))[1];
1466 $data=substr($data,$count,length($data)-$count);
1467 return ($data);
1468 }
1469  
1470 sub _extract_char
1471 {
1472 my ( $data ) = @_;
1473 my ( $char ) = unpack("C",$data);
1474 $data=substr($data,1,length($data)-1);
1475 return ($char,$data);
1476 }
1477  
1478 sub _extract_char_u
1479 {
1480 my ( $data ) = @_;
1481 my ( $char ) = unpack("C",$data);
1482 $data=substr($data,1,length($data)-1);
1483 return ($char,$data);
1484 }
1485  
1486 sub _extract_mac
1487 {
1488 my ( $self ) = shift;
1489 my ( $data ) = @_;
1490 my ( $return_data ) = "";
1491 my ( $empty, $empty2, $mac1, $mac2, $mac3, $mac4, $mac5, $mac6 ) = unpack ("CCCCCCCC",$data);
1492 if ( $self->{_GLOBAL}{'MACFormat'} == 1 )
1493 { ( $return_data ) = sprintf("%02x%02x.%02x%02x.%02x%02x",$mac1,$mac2,$mac3,$mac4,$mac5,$mac6); }
1494 if ( $self->{_GLOBAL}{'MACFormat'} == 2 )
1495 {
1496 ( $return_data ) = sprintf("%02x-%02x-%02x-%02x-%02x-%02x",$mac1,$mac2,$mac3,$mac4,$mac5,$mac6);
1497 $return_data=~tr/[a-z]/[A-Z]/;
1498 }
1499 $data=substr($data,8,length($data)-8);
1500 return ($return_data,$data);
1501 }
1502  
1503 sub _extract_long_u
1504 {
1505 my ( $data ) = @_;
1506 my ( $long ) = decode_64bit_number ( $data );
1507 $data=substr($data,8,length($data)-8);
1508 return ($long,$data);
1509 }
1510  
1511 sub _extract_long
1512 {
1513 my ( $data ) = @_;
1514 my ( $long ) = decode_64bit_number ( $data );
1515 $data=substr($data,8,length($data)-8);
1516 return ($long,$data);
1517 }
1518  
1519 sub _extract_list
1520 {
1521 my ( $self ) = shift;
1522 my ( $data ) = shift;
1523 my ( $type ) = shift;
1524  
1525 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1526 {
1527  
1528 print "Check self is '".$self."'\n";
1529 print "Check data len is '".length($data)."'\n";
1530 print "Check type is '$type'\n";
1531 }
1532  
1533 my ( $string_len ) = 0;
1534  
1535 # Looks like a field length is 16 bit
1536 # if the field type is serviceflowchSet
1537 # otherwise I am setting it to be 32bits
1538 # per the default speficiation for field
1539 # type list.
1540 ( $string_len ) = unpack ("N",$data);
1541 # snarf the header
1542 $data=substr($data,4,length($data)-4);
1543  
1544 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1545 {
1546 print "List Debug length is '".$string_len."'\n";
1547 print "List type is '$type'\n";
1548 }
1549  
1550 # Remove the list data and return
1551 #
1552 my ( $returned_list ) = "";
1553  
1554 #if ( $type =~/^ServiceFlowChSet$/i )
1555 # {
1556 # This is bascially a list of numbers so we do that
1557 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1558 {
1559 print "ServiceFlowChSet field being used.\n";
1560 print "Data extracted.\n";
1561 }
1562 if ( $string_len%2 > 0 )
1563 {
1564 # Here we have to capture the error but also
1565 # make the data available.
1566 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1567 {
1568 print "Something serious happened here as length is wrong.\n";
1569
1570 for ( $a=0; $a<$string_len; $a++ )
1571 {
1572 $returned_list.=ord(substr($data,$a,1)).",";
1573 }
1574 }
1575 }
1576 else
1577 {
1578 # We know we have a good data length so now we decode it
1579 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1580 {
1581 print "ServiceFlowChSet length is correct modulus.\n";
1582 }
1583 # The default is the correct 16bit snarfing of a hexBinary
1584 # data string. Now, it appears that using the data as an 8bit
1585 # dataset is sometimes preferred, so by setting hexBinarySingle
1586 # we do that too.
1587 if ( $self->{_GLOBAL}{'hexBinarySingle'}==1 )
1588 {
1589 for ( $a=0; $a<$string_len; $a++ )
1590 {
1591 $returned_list.=ord(substr($data,$a,1)).",";
1592 }
1593 }
1594 else
1595 {
1596 for ( $a=0;$a<$string_len; $a+=2 )
1597 {
1598 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1599 {
1600 print "Count routine is '".$a."'\n";
1601 }
1602 my $partial = substr($data,$a,2);
1603 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1604 {
1605 print "Length of partial is '".length($partial)."'\n";
1606 }
1607 if ( length($partial)==2)
1608 {
1609 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1610 {
1611 print "Partial length correct.\n";
1612 }
1613 my ($unpp) = unpack("n",$partial);
1614 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1615 {
1616 print "Value of decoded is '".$unpp."'\n";
1617 }
1618 $returned_list .=$unpp.",";
1619 }
1620 else
1621 {
1622 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1623 {
1624 print "Partial extract wrong, ignoring.\n";
1625 }
1626 }
1627 }
1628 }
1629 }
1630  
1631 # }
1632  
1633 #if ( $type !~/^ServiceFlowChSet$/i )
1634 # {
1635 # if ($self->{_GLOBAL}{'DEBUG'}>0 )
1636 # {
1637 # print "Field type '$type' being used.\n";
1638 # }
1639 #
1640 # my ( $ip_list ) = substr($data,0,$string_len);
1641 # while ( length($ip_list)>0 )
1642 # {
1643 # my $structure = substr($ip_list,0,4);
1644 #
1645 # $ip_list = substr($ip_list,4,length($ip_list)-4);
1646 #
1647 # if ($self->{_GLOBAL}{'DEBUG'}>0 )
1648 # {
1649 # print "List Debug structure length is '".length($structure)."'\n";
1650 # print "Length of ip_list is '".length($ip_list)."'\n";
1651 # for($a=0;$a<length($structure);$a++)
1652 # {
1653 # print ord (substr($structure,$a,1))." ";
1654 # }
1655 # }
1656 # $returned_list.=ord(substr($structure,0,1)).".".ord(substr($structure,1,1)).".".ord(substr($structure,2,1)).".".ord(substr($structure,3,1)).",";
1657 # }
1658 # }
1659  
1660 if ( length($returned_list)>0 )
1661 {
1662 chop($returned_list);
1663 if ($self->{_GLOBAL}{'DEBUG'}>0 )
1664 {
1665 print "\n\n$returned_list\n\n";
1666 }
1667 }
1668  
1669 $data=substr($data,$string_len,length($data)-$string_len);
1670 return ($returned_list,$data);
1671 }
1672  
1673 sub template_store
1674 {
1675 my ( $self ) = shift;
1676 my ( $data ) = shift;
1677 $self->{_GLOBAL}{'data_template'} = $data;
1678 }
1679  
1680 sub template_return
1681 {
1682 my ( $self ) = shift;
1683 return $self->{_GLOBAL}{'data_template'};
1684 }
1685  
1686 sub template_value_definitions
1687 {
1688 # this template is no longer needed and was
1689 # originally put in for development purposes
1690 # in the next few versions this will be removed.
1691 #
1692 # point of note, signed values *may* not be
1693 # correct due to endianess of a platform. Currently
1694 # all set to unsigned. Tried on multiple platforms
1695 # and something not conforming to spec.
1696 my %template_params;
1697  
1698 $template_params{33}="network_int_u";
1699 $template_params{34}="network_int_u";
1700 $template_params{35}="long_u";
1701 $template_params{36}="long_u";
1702 $template_params{37}="float";
1703 $template_params{38}="double";
1704 $template_params{39}="ip_list";
1705 $template_params{40}="string";
1706 $template_params{41}="boolean";
1707 $template_params{42}="byte_u";
1708 $template_params{43}="byte_u";
1709 $template_params{44}="short_u";
1710 $template_params{45}="short_u";
1711  
1712 $template_params{290}="network_int_u";
1713 $template_params{548}="long";
1714 $template_params{802}="network_ip";
1715 $template_params{1063}="ipv6addr";
1716 $template_params{1319}="uuid";
1717 $template_params{1571}="datetimeusec";
1718 $template_params{1827}="mac";
1719 $template_params{2087}="ipaddr";
1720  
1721 return %template_params;
1722 }
1723  
1724 sub decode_64bit_number_u
1725 {
1726 # see comments on 64bit stuff.
1727 my ( $message ) =@_;
1728 my ($part1,$part2) = unpack("NN",$message);
1729 $part1 = $part1<<32;
1730 $part1+=$part2;
1731 return $part1;
1732 }
1733  
1734 sub decode_64bit_number
1735 {
1736 # see comments on 64bit stuff.
1737 my ( $message ) =@_;
1738 my ($part1,$part2) = unpack("NN",$message);
1739 if ( !test_64_bit() )
1740 {
1741 return (
1742 Math::BigInt
1743 ->new("0x" . unpack("H*", pack("N2", $part1, $part2)))
1744 );
1745 }
1746 $part1 = $part1<<32;
1747 $part1+=$part2;
1748 return $part1;
1749 }
1750  
1751 #sub decode_64bit_number_u
1752 #{
1753 ## see comments on 64bit stuff.
1754 #my ( $message ) =@_;
1755 #my ($part1,$part2) = unpack("NN",$message);
1756 #$part1 = $part1<<32;
1757 #$part1+=$part2;
1758 #return $part1;
1759 #}
1760  
1761 sub encode_64bit_number
1762 {
1763 # It seems Q does not work, well not for me
1764 # and this is the quickest way to fix it.
1765 # You STILL NEED 64 BIT SUPPORT!!
1766 my ( $number ) = @_;
1767 if ( !test_64_bit() )
1768 {
1769 my $i = Math::BigInt->new($number);
1770 my $j = Math::BigInt->new($number)->brsft(32);
1771 return pack('NN', $j, $i );
1772 }
1773 # any bit to 64bit number in.
1774 my($test1) = $number & 0xFFFFFFFF; $number >>= 32;
1775 my($test2) = $number & 0xFFFFFFFF;
1776 my $message = pack("NN",$test2,$test1);
1777 return $message;
1778 }
1779  
1780 #sub encode_64bit_number
1781 #{
1782 ## It seems Q does not work, well not for me
1783 ## and this is the quickest way to fix it.
1784 ## You STILL NEED 64 BIT SUPPORT!!
1785 #my ( $number ) = @_;
1786 ## any bit to 64bit number in.
1787 #my($test1) = $number & 0xFFFFFFFF; $number >>= 32;
1788 #my($test2) = $number & 0xFFFFFFFF;
1789 #my $message = pack("NN",$test2,$test1);
1790 #return $message;
1791 #}
1792  
1793 sub check_data_available
1794 {
1795 my ( $self ) = shift;
1796  
1797 $self->send_connect_message();
1798  
1799 # Check for data from the IPDR server.
1800 while ( $self->check_data_handles && $self->{_GLOBAL}{'ERROR'}!~/not connected/i )
1801 {
1802 $self->get_data_segment();
1803  
1804 while ( $self->{_GLOBAL}{'data_processing'}==1 )
1805 {
1806  
1807 # If we manage to get some data correctly, decode the message
1808 # during decoding we may also store information, such as template
1809 # and data sequencing, however this is done internally to avoid
1810 # complex code here.
1811 $self->decode_message_type();
1812  
1813 my $last_message = $self->return_current_type();
1814  
1815 print "Last message was '$last_message'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1816  
1817 if ( $last_message=~/NULL/i || !$last_message )
1818 {
1819 $self->{_GLOBAL}{'data_processing'}=0;
1820 }
1821  
1822 # If the message is a connect_response, send a flow_start
1823 if ( $last_message=~/^CONNECT_RESPONSE$/i )
1824 {
1825 $self->log("CONNECT_RESPONSE");
1826 $self->send_get_sessions();
1827 # $self->update_session_parameters();
1828 }
1829  
1830 if ( $last_message=~/^GET_SESSIONS_RESPONSE$/i )
1831 { $self->send_flow_start_message(); }
1832  
1833 # If the message is a template data, store the template
1834 # and ack the template
1835 if ( $last_message=~/^TEMPLATE_DATA$/i )
1836 {
1837 $self->log("TEMPLATE_DATA");
1838 $self->send_final_template_data_ack();
1839 }
1840  
1841 # If the message is a session_start just send a keep
1842 # alive.
1843 if ( $last_message=~/^SESSION_START$/i )
1844 {
1845 $self->log("SESSION_START");
1846 $self->send_get_keepalive();
1847 }
1848  
1849 # If the message is a keep alive, send one back.
1850 # This function does a little more, but has been
1851 # made a wrapper to keep the code clean.
1852 if ( $self->return_current_type()=~/^KEEP_ALIVE$/i )
1853 {
1854 $self->log("KEEP_ALIVE");
1855 $self->send_get_keepalive();
1856 }
1857  
1858 # If the message is a data message, process it.
1859 # This also sends one keepalive upon receipt
1860 # of the first data segment, so keeping to the
1861 # specification and allowing DSN generation.
1862 if ( $self->return_current_type()=~/^DATA$/i )
1863 {
1864 $self->decode_data( );
1865 }
1866  
1867 # We need to make sure we decoded the last message
1868 # before checking if we can throw it out.
1869 if ( $self->{_GLOBAL}{'data_capture_running'}>=$self->{_GLOBAL}{'MaxRecords'}
1870 && $self->{_GLOBAL}{'MaxRecords'}>0)
1871 {
1872 print "Max records reached was '".$self->{_GLOBAL}{'data_capture_running'}."'\n";
1873 print "Max records limit was '".$self->{_GLOBAL}{'MaxRecords'}."\n\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1874 $self->{_GLOBAL}{'data_capture_running'}=0;
1875 $self->max_records_segment();
1876 }
1877  
1878 # so if you are receiving more data than a keepalive you may need
1879 # to send a data_ack
1880 if ( ((time()-$self->{_GLOBAL}{'data_capture_running_time'})
1881 > $self->{_GLOBAL}{'AckTime'})
1882 && $self->return_current_type()=~/^DATA$/i )
1883 {
1884 if ( defined( $self->get_internal_value('dsn_sequence')) )
1885 {
1886 $self->{_GLOBAL}{'data_capture_running_time'}=time();
1887 $self->{_GLOBAL}{'data_capture_data_count'}=0;
1888 print "Sending AckTime data ack.\n\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1889 $self->send_data_ack(
1890 $self->get_internal_value('dsn_configID'),
1891 $self->get_internal_value('dsn_sequence')
1892 );
1893 }
1894 }
1895  
1896 if ( ($self->{_GLOBAL}{'data_capture_data_count'}
1897 >= $self->{_GLOBAL}{'AckSequence'})
1898 && $self->return_current_type()=~/^DATA$/i )
1899 {
1900 if ( defined( $self->get_internal_value('dsn_sequence')) )
1901 {
1902 $self->{_GLOBAL}{'data_capture_data_count'}=0;
1903 print "Sending AckSequence data ack.\n\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1904 $self->send_data_ack(
1905 $self->get_internal_value('dsn_configID'),
1906 $self->get_internal_value('dsn_sequence')
1907 );
1908 }
1909 }
1910
1911 if ( (time()-$self->{_GLOBAL}{'data_capture_keep_alive'})
1912 > $self->{_GLOBAL}{'KeepAlive'} )
1913 {
1914 $self->send_message( $self->construct_get_keepalive() );
1915 $self->{_GLOBAL}{'data_capture_keep_alive'}=time();
1916 }
1917  
1918 # If the message is a session_stop, we should probably
1919 # send a disconnect, but we dont as yet.
1920 # with session stop you need to send a keepalive, as
1921 # session stop is not always a disconnect.
1922 if ( $self->return_current_type()=~/^SESSION_STOP$/i )
1923 {
1924 $self->log("SESSION_STOP");
1925 $self->send_get_keepalive();
1926 #$ipdr_client->{_GLOBAL}{'Selector'}->remove( $ipdr_client->{_GLOBAL}{'Handle'} );
1927 }
1928  
1929 # If the message is an error message, stop, something
1930 # went wrong somewhere.
1931 if ( $self->return_current_type()=~/^ERROR$/i )
1932 {
1933 $self->log("ERROR");
1934 print "Disconnect and closed TCP.\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1935 return 0;
1936 }
1937 }
1938 }
1939  
1940 print "Disconnect and closed TCP.\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1941  
1942 return 1;
1943 }
1944  
1945 # ***************************************************************
1946  
1947 sub log
1948 {
1949 my ( $self ) = shift;
1950 my ( $message ) = shift;
1951 my ( $decode_data ) = $self->{_GLOBAL}{'current_data'};
1952 my ( $time ) = time();
1953  
1954 return 1;
1955 }
1956  
1957 sub check_data_handles
1958 {
1959 my ( $self ) = shift;
1960 my ( @handle ) = $self->{_GLOBAL}{'Selector'}->can_read( $self->{_GLOBAL}{'KeepAlive'} );
1961 if ( !@handle ) { $self->{_GLOBAL}{'ERROR'}="Not Connected"; }
1962 $self->{_GLOBAL}{'ready_handles'}=\@handle;
1963 }
1964  
1965 sub get_data_segment
1966 {
1967 my ( $self ) = shift;
1968 my ( $header );
1969 my ( $buffer ) = "";
1970 my ( $dataset ) ;
1971  
1972 #$self->{_GLOBAL}{'data_received'} = "";
1973  
1974 my $link;
1975 my ( $version, $type, $session, $flags, $length );
1976 my ( $handles ) = $self->{_GLOBAL}{'ready_handles'};
1977  
1978 foreach my $handle ( @{$handles} )
1979 {
1980  
1981 eval {
1982 local $SIG{ALRM} = sub { die "alarm\n" };
1983 alarm 5;
1984 $link = sysread($handle,$buffer,1024);
1985 alarm 0;
1986 };
1987  
1988 if ( $@=~/alarm/i )
1989 { $handle->close(); return 1; }
1990  
1991 print "Read buffer size of '".length($buffer)."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
1992  
1993 if ( !$self->connected )
1994 {
1995 $handle->close(); return 1;
1996 }
1997  
1998 if ( length($buffer) == 0 )
1999 {
2000 $handle->close(); return 1;
2001 }
2002  
2003 $self->{_GLOBAL}{'data_received'} .=$buffer;
2004 }
2005 print "Length in buffer is '".length($self->{_GLOBAL}{'data_received'})."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
2006 $self->{_GLOBAL}{'data_processing'}=1;
2007 }
2008  
2009 sub ReturnPollTime
2010 {
2011 my ( $self ) = shift;
2012 return $self->{_GLOBAL}{'PollTime'};
2013 }
2014  
2015 sub get_error
2016 {
2017 my ( $self ) = shift;
2018 return $self->{_GLOBAL}{'ERROR'};
2019 }
2020  
2021 sub get_internal_value
2022 {
2023 my ( $self ) = shift;
2024 my ( $attribute ) = shift;
2025 return $self->{_GLOBAL}{$attribute};
2026 }
2027  
2028 sub set_internal_value
2029 {
2030 my ( $self ) = shift;
2031 my ( $attrib ) = shift;
2032 my ( $value ) = shift;
2033 $self->{_GLOBAL}{$attrib}=$value;
2034 }
2035  
2036 sub decode_data
2037 {
2038 my ( $self ) = shift;
2039 my ( %template_params ) = template_value_definitions();
2040 my ( $resulting_value ) = "";
2041  
2042 my ( $exported_data ) = $self->{_GLOBAL}{'complete_decoded_data'};
2043 my ( $record ) = $self->{_GLOBAL}{'current_data'};
2044 my ( $template ) = $self->{_GLOBAL}{'template'};
2045 my ( $template_id ) = ${$record}{'DATA_TemplateID'};
2046 my ( $data ) = ${$record}{'DATA_Data'};
2047  
2048 if ( length( $self->{_GLOBAL}{'PacketDirectory'} ) > 0 )
2049 {
2050 my $location = $self->{_GLOBAL}{'PacketDirectory'};
2051 my $epoch = time();
2052 my $rand = int(rand(100000));
2053 open (__PACKET_DATA,">$location/packet_$epoch\_$rand");
2054 print __PACKET_DATA $data;
2055 close (__PACKET_DATA);
2056 }
2057  
2058 $self->set_internal_value('dsn_sequence',${$record}{'DATA_Sequence'} );
2059 $self->set_internal_value('dsn_configID',${$record}{'DATA_ConfigID'} );
2060  
2061 if ( !$self->get_internal_value('data_ack') )
2062 {
2063 $self->set_internal_value('data_ack',1);
2064 $self->send_message( $self->construct_get_keepalive() );
2065 }
2066  
2067 my ( $int_or_dir ) = unpack("N",$data);
2068  
2069 # If you can figure out the first line, better person than I
2070 # All i figured out was 'possibly' direction, but this
2071 # might also be interface number so it has not been added
2072  
2073 $data = substr($data,4,length($data)-4);
2074  
2075 #${$template}{'Templates'}{$template_id}{'fields'}{$a}{'name'}=$field_name;
2076  
2077 foreach my $variable ( sort {$a<=> $b } keys %{${$template}{'Templates'}{$template_id}{'fields'}} )
2078 {
2079 print "Type id is '${$template}{'Templates'}{$template_id}{'fields'}{$variable}{'typeID'}' field is '$variable'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
2080 my $type = $template_params{ ${$template}{'Templates'}{$template_id}{'fields'}{$variable}{'typeID'} };
2081 my $template_type = ${$template}{'Templates'}{$template_id}{'fields'}{$variable}{'name'};
2082  
2083 print "Type name is '".$type."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
2084 print "Template variable name is '".$template_type."'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
2085  
2086 if ( $type=~/^string$/i )
2087 { ( $resulting_value, $data ) = _extract_utf8_string ( $data ); }
2088 if ( $type=~/^network_ip$/i )
2089 { ( $resulting_value, $data ) = _extract_ip_string ( $data ); }
2090  
2091 if ( $type=~/^network_int_u$/i )
2092 { ( $resulting_value, $data ) = _extract_int_u ( $data ); }
2093  
2094 if ( $type=~/^network_int$/i )
2095 { ( $resulting_value, $data ) = $self->_extract_int ( $data ); }
2096  
2097 if ( $type=~/^unknown_/i )
2098 { ( $data ) = _extract_unknown ( $data, $type ); }
2099 if ( $type=~/^mac$/i )
2100 { ( $resulting_value, $data ) = _extract_mac ( $self, $data ); }
2101  
2102 if ( $type=~/^long$/i )
2103 { ( $resulting_value, $data ) = _extract_long ( $data ); }
2104 if ( $type=~/^long_u$/i )
2105 { ( $resulting_value, $data ) = _extract_long_u ( $data ); }
2106  
2107 if ( $type=~/^float$/i )
2108 { ( $resulting_value, $data ) = _extract_float ( $data ); }
2109  
2110 if ( $type=~/^double$/i )
2111 { ( $resulting_value, $data ) = _extract_double ( $data ); }
2112  
2113 if ( $type=~/^boolean$/i )
2114 { ( $resulting_value, $data ) = _extract_boolean ( $data ); }
2115  
2116 if ( $type=~/^byte$/i )
2117 { ( $resulting_value, $data ) = _extract_char ( $data ); }
2118 if ( $type=~/^byte_u$/i )
2119 { ( $resulting_value, $data ) = _extract_char_u ( $data ); }
2120  
2121 if ( $type=~/^short$/i )
2122 { ( $resulting_value, $data ) = _extract_short ( $data ); }
2123 if ( $type=~/^short_u$/i )
2124 { ( $resulting_value, $data ) = _extract_short_u ( $data ); }
2125  
2126 if ( $type=~/^ipv6addr$/i )
2127 { ( $resulting_value, $data ) = _extract_ipv6addr ( $data ); }
2128  
2129 if ( $type=~/^uuid$/i )
2130 { ( $resulting_value, $data ) = _extract_uuid ( $data ); }
2131  
2132 if ( $type=~/^datetimeusec$/i )
2133 { ( $resulting_value, $data ) = _extract_datetimeusec ( $data ); }
2134  
2135 if ( $type=~/^ipaddr$/i )
2136 { ( $resulting_value, $data ) = _extract_ipaddr ( $data ); }
2137  
2138  
2139 if ( $type=~/^ip_list$/i )
2140 { ( $resulting_value, $data ) = $self->_extract_list ( $data , $template_type); }
2141 print "Resulting value is '$resulting_value'\n" if $self->{_GLOBAL}{'DEBUG'}>0;
2142 ${$exported_data}{ ${$record}{'DATA_Sequence'} }{ ${$template}{'Templates'}{$template_id}{'fields'}{$variable}{'name'} }=$resulting_value;
2143 }
2144 return 1;
2145 }
2146  
2147 sub _reverse_pattern
2148 {
2149 my ( $data ) = @_;
2150 my ( $result ) = "";
2151 my ( $data_length ) = length($data);
2152 for ( my $loop=0; $loop<$data_length; $loop++ )
2153 {
2154 $result.= substr( $data, ($data_length-$loop)-1, 1);
2155 }
2156 return $result;
2157 }
2158  
2159 sub test_64_bit
2160 {
2161 my $self = shift;
2162  
2163 my $tester=576466952313524498;
2164  
2165 my $origin = $tester;
2166  
2167 #print "Tester is '$tester'\n";
2168  
2169 my($test1) = $tester & 0xFFFFFFFF; $tester >>= 32;
2170 my($test2) = $tester & 0xFFFFFFFF;
2171  
2172 my $message = pack("NN",$test2,$test1);
2173  
2174 my ($part1,$part2) = unpack("NN",$message);
2175  
2176 $part1 = $part1<<32;
2177 #$part1 & 0xFFFFFFFF;
2178 $part1+=$part2;
2179  
2180 if ( $origin!=$part1 )
2181 {
2182 return 0;
2183 }
2184 else
2185 {
2186 return 1;
2187 }
2188 }
2189  
2190  
2191 sub _transform_into_xml
2192 {
2193 my $self = shift;
2194 my $data_pointer = shift;
2195 my $complete;
2196 my $xml;
2197 my $header;
2198 my $footer;
2199  
2200 my $ipdrrecorder;
2201 my $ipdrcreationtime;
2202  
2203 foreach my $sequence ( sort { $a<=>$b } keys %{$data_pointer} )
2204 {
2205 if ( !${$data_pointer}{$sequence}{'CMcpeIpv4List'} )
2206 { ${$data_pointer}{$sequence}{'CMcpeIpv4List'}=""; }
2207 $xml.="<IPDR xsi:type=\"DOCSIS-Type\">";
2208 $xml.="<IPDRcreationTime>".${$data_pointer}{$sequence}{'RecCreationTime'}."</IPDRcreationTime>";
2209 $xml.="<CMTShostName>".${$data_pointer}{$sequence}{'CMTShostName'}."</CMTShostName>";
2210 $xml.="<CMTSipAddress>".${$data_pointer}{$sequence}{'CMTSipAddress'}."</CMTSipAddress>";
2211 $xml.="<CMTSsysUpTime>".${$data_pointer}{$sequence}{'CMTSsysUpTime'}."</CMTSsysUpTime>";
2212 $xml.="<CMTScatvIfName>".${$data_pointer}{$sequence}{'CMTScatvIfName'}."</CMTScatvIfName>";
2213 $xml.="<CMTScatvIfIndex>".${$data_pointer}{$sequence}{'CMTScatvIfIndex'}."</CMTScatvIfIndex>";
2214 $xml.="<CMTSdownIfName>".${$data_pointer}{$sequence}{'CMTSdownIfName'}."</CMTSdownIfName>";
2215 $xml.="<CMTSupIfName>".${$data_pointer}{$sequence}{'CMTSupIfName'}."</CMTSupIfName>";
2216 $xml.="<CMTSupIfType>".${$data_pointer}{$sequence}{'CMTSupIfType'}."</CMTSupIfType>";
2217 $xml.="<CMmacAddress>".${$data_pointer}{$sequence}{'CMMacAddress'}."</CMmacAddress>";
2218 $xml.="<CMipAddress>".${$data_pointer}{$sequence}{'CMipAddress'}."</CMipAddress>";
2219 $xml.="<CMdocsisMode>".${$data_pointer}{$sequence}{'CMdocsisMode'}."</CMdocsisMode>";
2220 $xml.="<CMCPEipAddress>".${$data_pointer}{$sequence}{'CMcpeIpv4List'}."</CMCPEipAddress>";
2221 $xml.="<RecType>".${$data_pointer}{$sequence}{'RecType'}."</RecType>";
2222 $xml.="<serviceIdentifier>".${$data_pointer}{$sequence}{'serviceIdentifier'}."</serviceIdentifier>";
2223 $xml.="<serviceClassName>".${$data_pointer}{$sequence}{'serviceClassName'}."</serviceClassName>";
2224 $xml.="<serviceDirection>".${$data_pointer}{$sequence}{'serviceDirection'}."</serviceDirection>";
2225 $xml.="<serviceOctetsPassed>".${$data_pointer}{$sequence}{'serviceOctetsPassed'}."</serviceOctetsPassed>";
2226 $xml.="<servicePktsPassed>".${$data_pointer}{$sequence}{'servicePktsPassed'}."</servicePktsPassed>";
2227 $xml.="<serviceSlaDropPkts>".${$data_pointer}{$sequence}{'serviceSlaDropPkts'}."</serviceSlaDropPkts>";
2228 $xml.="<serviceSlaDelayPkts>".${$data_pointer}{$sequence}{'serviceSlaDelayPkts'}."</serviceSlaDelayPkts>";
2229 $xml.="<serviceTimeCreated>".${$data_pointer}{$sequence}{'serviceTimeCreated'}."</serviceTimeCreated>";
2230 $xml.="<serviceTimeActive>".${$data_pointer}{$sequence}{'serviceTimeActive'}."</serviceTimeActive>";
2231 $xml.="</IPDR>";
2232 $ipdrrecorder = ${$data_pointer}{$sequence}{'CMTShostName'};
2233 }
2234 $ipdrcreationtime = ctime();
2235 $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
2236 $header .= "<IPDRDoc ";
2237 $header .= "xmlns=\"http://www.ipdr.org/namespaces/ipdr\" ";
2238 $header .= "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
2239 $header .= "xsi:schemaLocation=\"DOCSIS-3.1-B.0.xsd\" ";
2240 $header .= "docId=\"CEABBE99-0000-0000-0000-000000000000\" ";
2241 $header .= "creationTime=\"".$ipdrcreationtime."\" ";
2242 $header .= "IPDRRecorderInfo=\"$ipdrrecorder\" ";
2243 $header .= "version=\"99.99\">";
2244 $footer .= "<IPDRDoc.End count=\"".scalar( keys %{$data_pointer})."\" endTime=\"".$ipdrcreationtime."\"/>";
2245 $footer .= "</IPDRDoc>";
2246 $complete = $header.$xml.$footer;
2247  
2248 return $complete;
2249 }
2250  
2251 sub _send_to_clear_destination
2252 {
2253 my ( $self ) = shift;
2254 my ( $data ) = shift;
2255 my ( $length_sent ) = 0;
2256 my ( $send_size ) = 1000;
2257  
2258 my $child;
2259  
2260 if ( $self->{_GLOBAL}{'RemoteMulti'} )
2261 {
2262 # Multi remote needs to fork out the sending so it can
2263 # do all the destinations at once otherwise it *may*
2264 # take a while to get through any number of
2265 # destinations set.
2266 #
2267 # Multiple destination is set to the follow
2268 #
2269 # Destination IP:Destination Port:Destination Speed,
2270 #
2271 # if using secure then you need to make sure the
2272 # keys are the same for each destination host.
2273 #
2274 foreach my $destination ( split(/,/,$self->{_GLOBAL}{'RemoteMulti'}) )
2275 {
2276 if ($child=fork)
2277 { } elsif (defined $child)
2278 {
2279 my ( $remoteip, $remoteport, $remotespeed ) = (split(/:/,$destination))[0,1,2];
2280 if ( !$remoteip || !$remoteport )
2281 {
2282 waitpid($child,0);
2283 exit(0);
2284 }
2285 if ( !$remotespeed )
2286 {
2287 $remotespeed=10;
2288 }
2289 my $lsr;
2290 if ( $self->{_GLOBAL}{'RemoteSecure'} )
2291 {
2292 $lsr = IO::Socket::SSL->new
2293 (
2294 PeerAddr => $remoteip,
2295 PeerPort => $remoteport,
2296 SSL_key_file => $self->{_GLOBAL}{'SSLKeyFile'},
2297 ReuseAddr => 1,
2298 Proto => 'tcp',
2299 Timeout => 5
2300 );
2301 }
2302 else
2303 {
2304 $lsr = IO::Socket::INET->new
2305 (
2306 PeerAddr => $remoteip,
2307 PeerPort => $remoteport,
2308 ReuseAddr => 1,
2309 Proto => 'tcp',
2310 Timeout => 5
2311 );
2312 }
2313 # $lsr->autoflush(0);
2314 if ( !$lsr )
2315 {
2316 waitpid($child,0);
2317 exit(0);
2318 }
2319 my $selector = new IO::Select( $lsr );
2320 my $timer = (1/($remotespeed/8) )*$send_size;
2321 my $print_status = 1;
2322 my $chunk;
2323 while ( length($data)>0 && (my @ready = $selector->can_write ) )
2324 {
2325 foreach my $write ( @ready )
2326 {
2327 if ( $write == $lsr )
2328 {
2329 #print "handle is '$write'\n";
2330 if ( length($data)<=$send_size)
2331 {
2332 #print "ASending '$data'\n\n\n";
2333 $print_status = print $write $data;
2334 $data = "";
2335 }
2336 else
2337 {
2338 $chunk = substr($data,0,$send_size);
2339 $print_status = print $write $chunk;
2340 #print "BSending '$chunk'\n\n\n";
2341 $data = substr($data,$send_size,length($data)-$send_size);
2342 }
2343 }
2344 }
2345 # Timer added for remotesendspeed. Useful for management networks with limited
2346 # speed, such as 10mb/s or even t1/e1 speeds of 1.6/2 Mbp/s
2347 usleep($timer);
2348 #print "Ending pass for send.\n";
2349 }
2350 usleep(100000);
2351 $lsr->close();
2352 waitpid($child,0);
2353 exit(0);
2354 }
2355 }
2356 }
2357 else
2358 {
2359 if ($child=fork)
2360 { } elsif (defined $child)
2361 {
2362 my $lsr;
2363 if ( $self->{_GLOBAL}{'RemoteSecure'} )
2364 {
2365 $lsr = IO::Socket::SSL->new
2366 (
2367 PeerAddr => $self->{_GLOBAL}{'RemoteIP'},
2368 PeerPort => $self->{_GLOBAL}{'RemotePort'},
2369 SSL_key_file => $self->{_GLOBAL}{'SSLKeyFile'},
2370 ReuseAddr => 1,
2371 Proto => 'tcp',
2372 Timeout => 5
2373 );
2374 }
2375 else
2376 {
2377 #print "Remote IP is '".$self->{_GLOBAL}{'RemoteIP'}."'\n";
2378 #print "Remote Port is '".$self->{_GLOBAL}{'RemotePort'}."'\n";
2379 $lsr = IO::Socket::INET->new
2380 (
2381 PeerAddr => $self->{_GLOBAL}{'RemoteIP'},
2382 PeerPort => $self->{_GLOBAL}{'RemotePort'},
2383 ReuseAddr => 1,
2384 Proto => 'tcp',
2385 Timeout => 5
2386 );
2387 }
2388 if (!$lsr)
2389 {
2390 waitpid($child,0);
2391 return 0;
2392 }
2393 # $lsr->autoflush(0);
2394 my $selector = new IO::Select( $lsr );
2395 my $timer = (1/($self->{_GLOBAL}{'RemoteSpeed'}/8) )*$send_size;
2396 my $chunk;
2397 my $print_status = 1;
2398 while ( length($data)>0 && (my @ready = $selector->can_write ) && $print_status )
2399 {
2400 foreach my $write ( @ready )
2401 {
2402 if ( $write == $lsr )
2403 {
2404 #print "handle is '$write'\n";
2405 if ( length($data)<=$send_size)
2406 {
2407 print "ASending '$data'\n\n\n";
2408 $print_status = print $write $data;
2409 # we need the last data chunk
2410 #$padding = $data;
2411 $data = "";
2412 # we need the final write handle.
2413 }
2414 else
2415 {
2416 $chunk = substr($data,0,$send_size);
2417 $print_status = print $write $chunk;
2418 print "BSending '$chunk'\n\n\n";
2419 $data = substr($data,$send_size,length($data)-$send_size);
2420 }
2421 }
2422 }
2423 usleep($timer);
2424 }
2425 # ok so why does this work ?
2426 # from experiments the final chunk does not seem to be sent, so here
2427 # we send it again ....
2428 usleep(100000);
2429 $lsr->close();
2430 waitpid($child,0);
2431 }
2432  
2433 }
2434  
2435 return 1;
2436 }
2437  
2438  
2439 =head1 AUTHOR
2440  
2441 Andrew S. Kennedy, C<< <shamrock at cpan.org> >>
2442  
2443 =head1 BUGS
2444  
2445 Please report any bugs or feature requests to
2446 C<bug-ipdr-cisco at rt.cpan.org>, or through the web interface at
2447 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IPDR-Collection-Client>.
2448 I will be notified, and then you'll automatically be notified of progress on
2449 your bug as I make changes.
2450  
2451 =head1 SUPPORT
2452  
2453 You can find documentation for this module with the perldoc command.
2454  
2455 perldoc IPDR::Collection::Client
2456  
2457 You can also look for information at:
2458  
2459 =over 4
2460  
2461 =item * AnnoCPAN: Annotated CPAN documentation
2462  
2463 L<http://annocpan.org/dist/IPDR-Collection-Client>
2464  
2465 =item * CPAN Ratings
2466  
2467 L<http://cpanratings.perl.org/d/IPDR-Collection-Client>
2468  
2469 =item * RT: CPAN's request tracker
2470  
2471 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IPDR-Collection-Client>
2472  
2473 =item * Search CPAN
2474  
2475 L<http://search.cpan.org/dist/IPDR-Collection-Client>
2476  
2477 =back
2478  
2479 =head1 ACKNOWLEDGEMENTS
2480  
2481 Thanks to http://www.streamsolutions.co.uk/ for my Flash Streaming Server
2482  
2483 =head1 COPYRIGHT & LICENSE
2484  
2485 Copyright 2011 Andrew S. Kennedy, all rights reserved.
2486  
2487 This program is free software; you can redistribute it and/or modify it
2488 under the same terms as Perl itself.
2489  
2490 =cut
2491  
2492 1; # End of IPDR::Collection::Client