Processor.pm untested

filter: Statementstmt 0.0% 0 / 313 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 527 CC 56 SCAR 48.4
CC
56
Cov
0%
extract_rdr
272.0
decode_type
240.0
convert_mac_address
72.0
CRAP 127.0
1 package RDR::Processor;
2  
3 use warnings;
4 use strict;
5 use IO::Select;
6 use IO::Socket;
7  
8 =head1 NAME
9  
10 RDR::Processor - Decodes RDRv1 packets
11  
12 =head1 VERSION
13  
14 Version 1.0000
15  
16 =cut
17  
18 our $VERSION = '1.0000';
19  
20 =head1 SYNOPSIS
21  
22 =head1 EXPORT
23  
24 None
25  
26 =head1 FUNCTIONS
27  
28 =head2 function1
29  
30 =cut
31  
32 sub new {
33  
34 my $self = {};
35 bless $self;
36  
37 my ( %handles );
38  
39 my ( $class , $attr ) =@_;
40  
41 $self->{_GLOBAL}{'DEBUG'}=0;
42  
43 while (my($field, $val) = splice(@{$attr}, 0, 2))
44 { $self->{_GLOBAL}{$field}=$val; }
45  
46 $self->{_GLOBAL}{'STATUS'}="OK";
47  
48 if ( !$self->{_GLOBAL}{'VendorID'} )
49 { $self->{_GLOBAL}{'VendorID'}="Generic Client"; }
50  
51 if ( !$self->{_GLOBAL}{'DataHandler'} )
52 { die "DataHandler Function Must Be Defined"; }
53  
54 if ( !$self->{_GLOBAL}{'Filename'} )
55 { die "Filename Must Be Defined"; }
56  
57 if ( $self->{_GLOBAL}{'ProtocolFile'} )
58 {
59 if ( !open(__FILE,"<".$self->{_GLOBAL}{'ProtocolFile'}) )
60 {
61 die "ProtocolFile specified, but not found.";
62 exit(0);
63 }
64 close (__FILE);
65 $self->{_GLOBAL}{'protocol_ids'} = load_protocol_file ( $self->{_GLOBAL}{'ProtocolFile'} );
66 }
67 else
68 {
69 $self->{_GLOBAL}{'protocol_ids'} = { } ;
70 }
71  
72 $self->{_GLOBAL}{'fields'} = fields_rdr( );
73 $self->{_GLOBAL}{'field_types'} = field_types_rdr( );
74 $self->{_GLOBAL}{'rdr_types'} = transpose_rdr_types( );
75 return $self;
76 }
77  
78 sub load_protocol_file
79 {
80 my ( $filename ) = shift;
81 my %protocol_results;
82 open (__FILE,"<$filename");
83 while (<__FILE>)
84 {
85 $_=~s/^\s*//; $_=~ s/\s*$//;
86 my ( $protocol_name, $protocol_number );
87 ( $protocol_name, $protocol_number ) = ( split( /,/,$_) )[0,1];
88 $protocol_results{$protocol_number} = $protocol_name;
89 }
90 close (__FILE);
91 return \%protocol_results;
92 }
93  
94 sub return_error
95 {
96 my ( $self ) = shift;
97  
98 return $self->{_GLOBAL}{'ERROR'};
99 }
100  
101 sub process_file
102 {
103 my ( $self ) = shift;
104 my ( $filename ) = $self->{_GLOBAL}{'Filename'};
105  
106 if ( !$filename )
107 {
108 exit(0);
109 }
110  
111 my ( $handler_file );
112  
113 if ( !open ($handler_file,"<$filename") )
114 {
115 exit(0);
116 }
117
118 # This is a little hacky, but works
119 # This has been speeded up, now only large reads
120 # it was killing the disc due to the short read method.
121 # Still a bit hacky though.
122  
123 my $buffer;
124 my $buffer2;
125 my $length = 2000 ;
126  
127 while ( ( my $len = sysread ( $handler_file,$buffer2, 4096 )) > 0 )
128 {
129 print "Reading 4k.\n";
130 $buffer=$buffer.$buffer2;
131 while ( ($length+5) < length($buffer) )
132 {
133 print "We entered here.\n";
134 my ( $proc ) = unpack ("C",$buffer );
135 ( $length ) = substr($buffer,1,4);
136 $length = convert_chars_value ( $length );
137 # $length = hex(substr($length,0,1)).hex(substr($length,1,1)).hex(substr($length,2,1)).hex(substr($length,3,1));
138 if ( ($length)+5<=length($buffer) )
139 {
140 my $body = substr($buffer,0,$length+5);
141 $buffer = substr($buffer, length($body), length($buffer)-length($body) );
142 my ($deader) = $self->check_data_available($body);
143 }
144 }
145 }
146  
147 close ($handler_file);
148  
149 return 1;
150 }
151  
152 sub convert_chars_value
153 {
154 # this is just crazy stuff. Is PERL suited to this stuff, not really.
155 # This is a safety handler for the RDR Packets as *sometimes* they are
156 # full of crap.
157 my ($length) = @_;
158 my $char1;
159 my $char2;
160 my $char3;
161 my $char4;
162 my $failed=0;
163  
164 #print "Conversion is '".ord(substr($length,0,1))."' '".ord(substr($length,1,1))."' '".ord(substr($length,2,1))."' '".ord(substr($length,3,1))."'\n";
165  
166 if ( (ord(substr($length,1,1))>=48 && ord(substr($length,1,1))<=57) ||
167 (ord(substr($length,1,1))>=65 && ord(substr($length,1,1))<=70) )
168 {
169 $char2 = hex(substr($length,1,1));
170 }
171 else
172 {
173 $failed=1;
174 }
175  
176 if ( (ord(substr($length,0,1))>=48 && ord(substr($length,0,1))<=57) ||
177 (ord(substr($length,0,1))>=65 && ord(substr($length,0,1))<=70) )
178 {
179 $char1 = hex(substr($length,0,1));
180 }
181 else
182 {
183 $failed=1;
184 }
185  
186 if ( (ord(substr($length,2,1))>=48 && ord(substr($length,2,1))<=57) ||
187 (ord(substr($length,2,1))>=65 && ord(substr($length,2,1))<=70) )
188 {
189 $char3 = hex(substr($length,2,1));
190 }
191 else
192 {
193 $failed=1;
194 }
195
196  
197 if ( (ord(substr($length,3,1))>=48 && ord(substr($length,3,1))<=57) ||
198 (ord(substr($length,3,1))>=65 && ord(substr($length,3,1))<=70) )
199 {
200 $char4 = hex(substr($length,3,1));
201 }
202 else
203 {
204 $failed=1;
205 }
206  
207 if ( $failed==1 )
208 {
209 return "DEAD";
210 }
211 else
212 {
213 return $char1.$char2.$char3.$char4;
214 }
215 }
216  
217 sub get_data_segment
218 {
219 my ( $self ) = shift;
220 my ( $dataset ) = shift;
221  
222 my ( $fields ) = $self->{_GLOBAL}{'fields'};
223 my ( $field_types ) = $self->{_GLOBAL}{'field_types'};
224 my ( $rdr_types ) = $self->{_GLOBAL}{'rdr_types'};
225  
226 #print "Dataset length is '".length($dataset)."'\n";
227  
228 if ( length($dataset)<15 )
229 {
230 #print "Skipping data set here.\n";
231 return "";
232 }
233  
234 my ( $proc ) = unpack ("C",$dataset);
235  
236 my ( $length ) = substr($dataset,1,4);
237  
238 return "" if !$length;
239  
240 if ( length($length)<4 )
241 {
242 #print "Length should be 4 it is '".length($length)."'\n";
243 return "";
244 }
245  
246 $length = convert_chars_value ( $length );
247  
248 #$length = hex(substr($length,0,1)).hex(substr($length,1,1)).hex(substr($length,2,1)).hex(substr($length,3,1));
249 if ( $length=~/^dead/i )
250 {
251 #print "Bad length found length is '$length'.\n";
252 return "";
253 }
254  
255 $length+=1;
256 #print "Dataset length is '".length($dataset)."'\n";
257  
258 $dataset = substr( $dataset,5,length($dataset)-5 );
259  
260 #print "Dataset length is '".length($dataset)."'\n";
261  
262 my ( $src, $dst, $src_port, $dst_port, $flow_id, $type,$fieldcount ) = unpack ("CCSSH8H8C",$dataset );
263  
264 #print "src '$src' dst '$dst' src_port '$src_port' dst_port '$dst_port' flow id '$flow_id' type '$type' fieldcount '$fieldcount'\n";
265 $type = hex($type);
266 my %result;
267 my $return_value="";
268  
269 if ( length($dataset)>=15 )
270 {
271 $return_value = $self->extract_rdr(
272 $type,
273 $fieldcount,
274 substr($dataset, 15,length($dataset)-15),
275 \%result
276 );
277  
278 $self->{_GLOBAL}{'DataHandler'}->(
279 $self->{_GLOBAL},
280 "localprocessor",
281 "localprocessor",
282 \%result
283 );
284 }
285 undef %result;
286  
287 #print "Remaining return value is '".length($return_value)."'\n";
288  
289 return $return_value;
290 }
291  
292  
293 sub check_data_available
294 {
295 my ( $self ) = shift;
296 my ( $data_segment ) = shift;
297  
298 my $remaining = $self->get_data_segment( $data_segment );
299  
300 #print "Remaining data set is '".length($remaining)."'\n";
301  
302 return $remaining;
303  
304 }
305  
306  
307 sub check_data_handles
308 {
309 my ( $self ) = shift;
310 my ( @handle ) = $self->{_GLOBAL}{'Selector'}->can_read;
311 $self->{_GLOBAL}{'ready_handles'}=\@handle;
312 }
313  
314  
315 sub extract_rdr
316 {
317 my ( $self ) = shift;
318 my ( $type ) = shift;
319 my ( $count ) = shift;
320 my ( $data_block ) = shift;
321 my ( $pointer ) = shift;
322  
323 return "" if !$data_block;
324  
325 my ( $fields ) = $self->{_GLOBAL}{'fields'};
326 my ( $field_types ) = $self->{_GLOBAL}{'field_types'};
327 my ( $rdr_types ) = $self->{_GLOBAL}{'rdr_types'};
328 my ( $protocol_ids ) = $self->{_GLOBAL}{'protocol_ids'};
329  
330 my ( $trans_fields );
331 my ( $name ) = ${$rdr_types}{$type};
332 if ( !$name )
333 {
334 #print "RDR type not found was '$type'\n";
335 return "";
336 }
337 if ( ${$fields}{$name} )
338 {
339 #print "Name is '$name'\n";
340 ( $trans_fields ) = ${$fields}{$name};
341 }
342  
343 #return unless $name=~/^SubscriberUsage$/i;
344  
345 #print "Size of keys is '".scalar(keys %{$trans_fields})."'\n";
346  
347 #print "RDR name is '$name'\n";
348  
349 if ( scalar(keys %{$trans_fields})> 0 )
350 {
351 for( $a=0;$a<scalar(keys %{$trans_fields});$a++ )
352 {
353 #next if length($data_block)<5;
354 my ( $block_start ) = substr( $data_block,0,5);
355  
356 #print "Length of block_start is '".length($block_start)."'\n";
357  
358 my ( $type, $data_length ) = unpack("CN",$block_start);
359  
360 #print "Type is '$type' length is '$data_length'\n";
361  
362 my ( $current_block ) = substr($data_block,5,$data_length);
363  
364 if ( length($data_block)>=($data_length+5) )
365 {
366 $data_block = substr($data_block,$data_length+5,length($data_block)-($data_length+5));
367 }
368 else
369 {
370 next;
371 }
372  
373 if ( !$type )
374 {
375 #print "Type not found was '$type'.\n";
376 next;
377 }
378  
379 if ( !${$field_types}{$type} )
380 {
381 #print "RDR field not found was '$type' count was '$a' max is '".scalar(keys %{$trans_fields})."'\n";
382 #print "Length is '$data_length'\n";
383 if ( length($current_block)<$data_length )
384 {
385 next;
386 }
387 }
388  
389 my ( $real_type ) = ${$field_types}{$type};
390  
391 #print "Name is '".${$trans_fields}{$a}."' length is '".$data_length."'\n";
392  
393 if ( !$real_type )
394 {
395 #print "Real type failed with '$real_type'\n";
396 }
397  
398 #print "Type was '$type' Real type was '$real_type' \n";
399  
400 my ( $value ) = substr($current_block,0,$data_length);
401  
402 if ( ${$trans_fields}{$a}=~/\_ip$/i )
403 { $value = decode_type ( $name, $real_type, $value, ${$trans_fields}{$a} ); $value = _IpIntToQuad($value); }
404  
405 if ( ${$trans_fields}{$a}=~/\_mac$/i )
406 { $value = $self->convert_mac_address ( $value ); }
407  
408 if ( ${$trans_fields}{$a}!~/\_ip$/i && ${$trans_fields}{$a}!~/\_mac$/ )
409 {
410 $value = decode_type ( $name, $real_type, $value, ${$trans_fields}{$a} );
411 }
412  
413 if ( $value=~/^dead/i )
414 {
415 ${$pointer}{ ${$trans_fields}{$a} } ="DEAD";
416 next;
417 }
418  
419  
420 # if ( ${$trans_fields}{$a}=~/\_mac$/i )
421 # { $value = $self->convert_mac_address ( $value ); }
422  
423 if ( ${$trans_fields}{$a}=~/^protocol_id$/i )
424 {
425 my $protocol_id_found = ${$protocol_ids}{$value};
426 if ( !$protocol_id_found )
427 {
428 $value = $value."(".$value.")";
429 }
430 else
431 {
432 $value = $protocol_id_found."(".$value.")";
433 }
434 }
435  
436  
437 ${$pointer}{ ${$trans_fields}{$a} } = $value;
438 #next if length($data_block)<($data_length+5);
439 }
440 }
441 else
442 {
443 #print "RDR record is just plain broken or unknown.\n";
444 }
445 ${$pointer}{'RDR_Record'}=$name;
446 return "";
447 }
448  
449 sub _IpIntToQuad { my($Int) = shift;
450 if (!$Int) { return "0.0.0.0"; }
451 my($Ip1) = $Int & 0xFF; $Int >>= 8;
452 my($Ip2) = $Int & 0xFF; $Int >>= 8;
453 my($Ip3) = $Int & 0xFF; $Int >>= 8;
454 my($Ip4) = $Int & 0xFF; return("$Ip4.$Ip3.$Ip2.$Ip1");
455 }
456  
457 sub decode_type
458 {
459 my ( $rdr_name ) = shift;
460 my ( $type ) = shift;
461 my ( $value ) = shift;
462 my ( $field_name ) = shift;
463  
464 my ( $return_value );
465  
466 #print "Decoder running for RDR '$rdr_name' fieldname '$field_name' type '$type' value is ";
467  
468 if ( !$value ) { return 1; }
469 if ( !$type ) { return 1; }
470 if ( $type=~/^int8$/i ) { $return_value = unpack("c",$value); }
471 if ( $type=~/^uint8$/i ) { $return_value = unpack("C",$value); }
472  
473 # this is just crazy
474 if ( $type=~/^int16$/i ) {
475 # now we should just have 2 bytes, so swap them and decode as s
476 # this is slow as you like, but hey thats life !!!
477 my $byte1 = substr($value,0,1);
478 my $byte2 = substr($value,1,1);
479 my $done = $byte2.$byte1;
480 $return_value = unpack("s",$done);
481 }
482  
483 # this is now correct
484 if ( $type=~/^uint16$/i ) {
485 $return_value = unpack("n",$value);
486 }
487  
488 # more crazy stuff
489 if ( $type=~/^int32$/i ) {
490 # this needs all four bytes changing in order
491 my $byte1 = substr($value,0,1);
492 my $byte2 = substr($value,1,1);
493 my $byte3 = substr($value,2,1);
494 my $byte4 = substr($value,3,1);
495 my $done = $byte4.$byte3.$byte2.$byte1;
496 $return_value = unpack("l",$done);
497 }
498  
499 # back to being normal
500 if ( $type=~/^uint32$/i ) { $return_value = unpack("N",$value); }
501  
502 if ( $type=~/^float$/i ) { $return_value = unpack("f",$value); }
503 if ( $type=~/^boolean$/i ) { $return_value = unpack("C",$value); }
504  
505 if ( $type=~/^string$/i ) {
506 if ( length($value)==0 )
507 {
508 $return_value="";
509 }
510 if ( $value!~/^[0-9\.a-zA-Z\\|\s\@\_\/\?\&\=\%\+\-,\^\:\[\]\{\}\$\"\;\<\>\*\~\£]+$/ && length($value)>0 )
511 {
512 #print "actual value before death was '$value' length '".length($value)."'\n";
513 $return_value ="DEAD";
514 }
515 else
516 {
517 $return_value = $value;
518 }
519 }
520  
521 if ( !$return_value ) { $return_value=0; }
522  
523 #print "Mapped value was '".$return_value."'\n";
524  
525 return $return_value;
526 }
527  
528 sub fields_rdr
529 {
530 my ( %rdr_fields )
531 = (
532 'HTTPTransaction' =>
533 {
534 0 => 'subscriber_id',
535 1 => 'package_id',
536 2 => 'service_id',
537 3 => 'protocol_id',
538 4 => 'skipped_sessions',
539 5 => 'server_ip',
540 6 => 'server_port',
541 7 => 'access_string',
542 8 => 'info_string',
543 9 => 'client_ip',
544 10 => 'client_port',
545 11 => 'initiating_side',
546 12 => 'report_time',
547 13 => 'millisec_duration',
548 14 => 'time_frame',
549 15 => 'session_upstream_volume',
550 16 => 'session_downstream_volume',
551 17 => 'subscriber_counter_id',
552 18 => 'global_counter_id',
553 19 => 'package_counter_id',
554 20 => 'ip_protocol',
555 21 => 'protocol_signature',
556 22 => 'zone_id',
557 23 => 'flavor_id',
558 24 => 'flow_close_mode',
559 25 => 'user_agent',
560 26 => 'http_url'
561 },
562 'RTSPTransaction' =>
563 {
564 0 => 'subscriber_id',
565 1 => 'package_id',
566 2 => 'service_id',
567 3 => 'protocol_id',
568 4 => 'skipped_sessions',
569 5 => 'server_ip',
570 6 => 'server_port',
571 7 => 'access_string',
572 8 => 'info_string',
573 9 => 'client_ip',
574 10 => 'client_port',
575 11 => 'initiating_side',
576 12 => 'report_time',
577 13 => 'millisec_duration',
578 14 => 'time_frame',
579 15 => 'session_upstream_volume',
580 16 => 'session_downstream_volume',
581 17 => 'subscriber_counter_id',
582 18 => 'global_counter_id',
583 19 => 'package_counter_id',
584 20 => 'ip_protocol',
585 21 => 'protocol_signature',
586 22 => 'zone_id',
587 23 => 'flavor_id',
588 24 => 'flow_close_mode',
589 25 => 'rtsp_session_id',
590 26 => 'rtsp_url',
591 27 => 'response_date',
592 28 => 'total_encoding_rate',
593 29 => 'number_of_video_streams',
594 30 => 'number_of_audio_streams',
595 31 => 'session_title',
596 32 => 'server_name'
597 },
598 'VoIPTransaction' =>
599 {
600 0 => 'subscriber_id',
601 1 => 'package_id',
602 2 => 'service_id',
603 3 => 'protocol_id',
604 4 => 'skipped_sessions',
605 5 => 'server_ip',
606 6 => 'server_port',
607 7 => 'access_string',
608 8 => 'info_string',
609 9 => 'client_ip',
610 10 => 'client_port',
611 11 => 'initiating_side',
612 12 => 'report_time',
613 13 => 'millisec_duration',
614 14 => 'time_frame',
615 15 => 'session_upstream_volume',
616 16 => 'session_downstream_volume',
617 17 => 'subscriber_counter_id',
618 18 => 'global_counter_id',
619 19 => 'package_counter_id',
620 20 => 'ip_protocol',
621 21 => 'protocol_signature',
622 22 => 'zone_id',
623 23 => 'flavor_id',
624 24 => 'flow_close_mode',
625 25 => 'application_id',
626 26 => 'upstream_packet_loss',
627 27 => 'downstream_packet_loss',
628 28 => 'upstream_average_jitter',
629 29 => 'downstream_average_jitter',
630 30 => 'call_destination',
631 31 => 'call_source',
632 32 => 'upstream_payload_type',
633 33 => 'downstream_payload_type',
634 34 => 'call-type',
635 35 => 'media_channels'
636 },
637 'SubscriberUsage' =>
638 {
639 0 => 'subscriber_id',
640 1 => 'package_id',
641 2 => 'service_usage_counter_id',
642 3 => 'breach_state',
643 4 => 'reason',
644 5 => 'configured_duration',
645 6 => 'duration',
646 7 => 'end_time',
647 8 => 'upstream_volume',
648 9 => 'downstream_volume',
649 10 => 'sessions',
650 11 => 'seconds'
651 },
652 'Transaction' =>
653 {
654 0 => 'subscriber_id',
655 1 => 'package_id',
656 2 => 'service_id',
657 3 => 'protocol_id',
658 4 => 'skipped_sessions',
659 5 => 'server_ip',
660 6 => 'server_port',
661 7 => 'access_string',
662 8 => 'info_string',
663 9 => 'client_ip',
664 10 => 'client_port',
665 11 => 'initiating_side',
666 12 => 'report_time',
667 13 => 'millisec_duration',
668 14 => 'time_frame',
669 15 => 'session_upstream_volume',
670 16 => 'session_downstream_volume',
671 17 => 'subscriber_counter_id',
672 18 => 'global_counter_id',
673 19 => 'package_counter_id',
674 20 => 'ip_protocol',
675 21 => 'protocol_signature',
676 22 => 'zone_id',
677 23 => 'flavour_id',
678 24 => 'flow_close_mode'
679 },
680 'TransactionUsage' =>
681 {
682 0 => 'subscriber_id',
683 1 => 'package_id',
684 2 => 'service_id',
685 3 => 'protocol_id',
686 4 => 'skipped_sessions',
687 5 => 'server_ip',
688 6 => 'server_port',
689 7 => 'access_string',
690 8 => 'info_string',
691 9 => 'client_ip',
692 10 => 'client_port',
693 11 => 'initiating_side',
694 12 => 'report_time',
695 13 => 'millisec_duration',
696 14 => 'time_frame',
697 15 => 'session_upstream_volume',
698 16 => 'session_downstream_volume',
699 17 => 'subscriber_counter_id',
700 18 => 'global_counter_id',
701 19 => 'package_counter_id',
702 20 => 'ip_protocol',
703 21 => 'protocol_signature',
704 22 => 'zone_id',
705 23 => 'flavor_id',
706 24 => 'flow_close_mode'
707 },
708 'RealTimeSubscriberUsage' =>
709 {
710 0 => 'subscriber_id',
711 1 => 'package_id',
712 2 => 'service_usage_counter_id',
713 3 => 'aggregation_object_id',
714 4 => 'breach_state',
715 5 => 'reason',
716 6 => 'configured_duration',
717 7 => 'duration',
718 8 => 'end_time',
719 9 => 'upstream_volume',
720 10 => 'downstream_volume',
721 11 => 'sessions',
722 12 => 'seconds'
723 },
724 'LinkUsage' =>
725 {
726 0 => 'link_id',
727 1 => 'generator_id',
728 2 => 'service_usage_counter_id',
729 3 => 'configured_duration',
730 4 => 'duration',
731 5 => 'end_time',
732 6 => 'upstream_volume',
733 7 => 'downstream_volume',
734 8 => 'sessions',
735 9 => 'seconds',
736 10 => 'concurrent_sessions',
737 11 => 'active_subscribers',
738 12 => 'total_active_subscribers'
739 },
740 'PackageUsage' =>
741 {
742 0 => 'package_counter_id',
743 1 => 'generator_id',
744 2 => 'service_usage_counter_id',
745 3 => 'configured_duration',
746 4 => 'duration',
747 5 => 'end_time',
748 6 => 'upstream_volume',
749 7 => 'downstream_volume',
750 8 => 'sessions',
751 9 => 'seconds',
752 10 => 'concurrent_sessions',
753 11 => 'active_subscribers',
754 12 => 'total_active_subscribers'
755 },
756 'VirtualLink' =>
757 {
758 0 => 'vlink_id',
759 1 => 'vlink_direction',
760 2 => 'generator_id',
761 3 => 'service_usage_counter_id',
762 4 => 'configured_duration',
763 5 => 'duration',
764 6 => 'end_time',
765 7 => 'upstream_volume',
766 8 => 'downstream_volume',
767 9 => 'sessions',
768 10 => 'seconds',
769 11 => 'concurrent_sessions',
770 12 => 'active_subscribers',
771 13 => 'total_active_subscribers'
772 },
773 'Blocking' =>
774 {
775 0 => 'subscriber_id',
776 1 => 'package_id',
777 2 => 'service_id',
778 3 => 'protocol_id',
779 4 => 'client_ip',
780 5 => 'client_port',
781 6 => 'server_ip',
782 7 => 'server_port',
783 8 => 'initiating_side',
784 9 => 'access_string',
785 10 => 'info_string',
786 11 => 'block_reason',
787 12 => 'block_rdr_count',
788 13 => 'redirected',
789 14 => 'report_time'
790 },
791 'QuotaBreach' =>
792 {
793 0 => 'subscriber_id',
794 1 => 'package_id',
795 2 => 'bucket_id',
796 3 => 'end_time',
797 4 => 'bucket_quota',
798 5 => 'aggregaton_period_type'
799 },
800 'RemainingQuota' =>
801 {
802 0 => 'subscriber_id',
803 1 => 'package_id',
804 2 => 'rdr_reason',
805 3 => 'end_time',
806 4 => 'remaining_quota_1',
807 5 => 'remaining_quota_2',
808 6 => 'remaining_quota_3',
809 7 => 'remaining_quota_4',
810 8 => 'remaining_quota_5',
811 9 => 'remaining_quota_6',
812 10 => 'remaining_quota_7',
813 11 => 'remaining_quota_8',
814 12 => 'remaining_quota_9',
815 13 => 'remaining_quota_10',
816 14 => 'remaining_quota_11',
817 15 => 'remaining_quota_12',
818 16 => 'remaining_quota_13',
819 17 => 'remaining_quota_14',
820 18 => 'remaining_quota_15',
821 19 => 'remaining_quota_16'
822 },
823 'QuotaThreshold' =>
824 {
825 0 => 'subscriber_id',
826 1 => 'package_id',
827 2 => 'bucket_id',
828 3 => 'global_threshold',
829 4 => 'end_time',
830 5 => 'bucket_quota'
831 },
832 'QuotaStateRestore' =>
833 {
834 0 => 'subscriber_id',
835 1 => 'package_id',
836 2 => 'rdr_reason',
837 3 => 'end_time'
838 },
839 'DHCP' =>
840 {
841 0 => 'cpe_mac',
842 1 => 'cmts_ip',
843 2 => 'assigned_ip',
844 3 => 'released_ip',
845 4 => 'transaction_id',
846 5 => 'message_type',
847 6 => 'option_type_0',
848 7 => 'option_type_1',
849 8 => 'option_type_2',
850 9 => 'option_type_3',
851 10 => 'option_type_4',
852 11 => 'option_type_5',
853 12 => 'option_type_6',
854 13 => 'option_type_7',
855 14 => 'option_type_0',
856 15 => 'option_type_1',
857 16 => 'option_type_2',
858 17 => 'option_type_3',
859 18 => 'option_type_4',
860 19 => 'option_type_5',
861 20 => 'option_type_6',
862 21 => 'option_type_7',
863 22 => 'end_time'
864 },
865 'RADIUS' =>
866 {
867 0 => 'server_ip',
868 1 => 'server_port',
869 2 => 'client_ip',
870 3 => 'client_port',
871 4 => 'initiating_side',
872 5 => 'radius_packet_code',
873 6 => 'radius_id',
874 7 => 'attribute_value_1',
875 8 => 'attribute_value_2',
876 9 => 'attribute_value_3',
877 10 => 'attribute_value_4',
878 11 => 'attribute_value_5',
879 12 => 'attribute_value_6',
880 13 => 'attribute_value_7',
881 14 => 'attribute_value_8',
882 15 => 'attribute_value_9',
883 16 => 'attribute_value_10',
884 17 => 'attribute_value_11',
885 18 => 'attribute_value_12',
886 19 => 'attribute_value_13',
887 20 => 'attribute_value_14',
888 21 => 'attribute_value_15',
889 22 => 'attribute_value_16',
890 23 => 'attribute_value_17',
891 24 => 'attribute_value_18',
892 25 => 'attribute_value_19',
893 26 => 'attribute_value_20',
894 27 => 'end_time'
895 },
896 'FlowStart' =>
897 {
898 0 => 'subscriber_id',
899 1 => 'package_id',
900 2 => 'service_id',
901 3 => 'ip_protocol',
902 4 => 'server_ip',
903 5 => 'server_port',
904 6 => 'client_ip',
905 7 => 'client_port',
906 8 => 'initiating_side',
907 9 => 'start_time',
908 10 => 'report_time',
909 11 => 'breach_state',
910 12 => 'flow_id',
911 13 => 'generator_id'
912 },
913 'FlowEnd' =>
914 {
915 0 => 'subscriber_id',
916 1 => 'package_id',
917 2 => 'service_id',
918 3 => 'ip_protocol',
919 4 => 'server_ip',
920 5 => 'server_port',
921 6 => 'client_ip',
922 7 => 'client_port',
923 8 => 'initiating_side',
924 9 => 'start_time',
925 10 => 'report_time',
926 11 => 'breach_state',
927 12 => 'flow_id',
928 13 => 'generator_id'
929 },
930 'FlowOnGoing' =>
931 {
932 0 => 'subscriber_id',
933 1 => 'package_id',
934 2 => 'service_id',
935 3 => 'ip_protocol',
936 4 => 'server_ip',
937 5 => 'server_port',
938 6 => 'client_ip',
939 7 => 'client_port',
940 8 => 'initiating_side',
941 9 => 'start_time',
942 10 => 'report_time',
943 11 => 'breach_state',
944 12 => 'flow_id',
945 13 => 'generator_id'
946 },
947 'MediaFlow' =>
948 {
949 0 => 'subscriber_id',
950 1 => 'package_id',
951 2 => 'service_id',
952 3 => 'protocol_id',
953 4 => 'destination_ip',
954 5 => 'destination_port',
955 6 => 'source_ip',
956 7 => 'source_port',
957 8 => 'initiating_side',
958 9 => 'zone_id',
959 10 => 'flavor_id',
960 11 => 'sip_domain',
961 12 => 'sip_user_agent',
962 13 => 'start_time',
963 14 => 'report_time',
964 15 => 'duration_seconds',
965 16 => 'upstream_volume',
966 17 => 'downstream_volume',
967 18 => 'ip_protocol',
968 19 => 'flow_type',
969 20 => 'session_id',
970 21 => 'upstream_jitter',
971 22 => 'downstream_jitter',
972 23 => 'upstream_packet_loss',
973 24 => 'downstream_packet_loss',
974 25 => 'upstream_payload_type',
975 26 => 'downstream_payload_type'
976 },
977 'AttackStart' =>
978 {
979 0 => 'attack_id',
980 1 => 'subscriber_id',
981 2 => 'attacking_ip',
982 3 => 'attacked_ip',
983 4 => 'attacked_port',
984 5 => 'attacking_side',
985 6 => 'ip_protocol',
986 7 => 'attack_type',
987 8 => 'generator_id',
988 9 => 'attack_time',
989 10 => 'report_time'
990 },
991 'AttackEnd' =>
992 {
993 0 => 'attack_id',
994 1 => 'subscriber_id',
995 2 => 'attacking_ip',
996 3 => 'attacked_ip',
997 4 => 'attacked_port',
998 5 => 'attacking_side',
999 6 => 'ip_protocol',
1000 7 => 'attack_type',
1001 8 => 'generator_id',
1002 9 => 'attack_time',
1003 10 => 'report_time'
1004 },
1005 'MaliciousTraffic' =>
1006 {
1007 0 => 'attack_id',
1008 1 => 'subscriber_id',
1009 2 => 'attack_ip',
1010 3 => 'other_ip',
1011 4 => 'port_number',
1012 5 => 'attack_type',
1013 6 => 'side',
1014 7 => 'ip_protocol',
1015 8 => 'configured_duration',
1016 9 => 'duration',
1017 10 => 'end_time',
1018 11 => 'attack',
1019 12 => 'malicious_sessions'
1020 }
1021  
1022 );
1023 return \%rdr_fields;
1024 }
1025  
1026 sub field_types_rdr
1027 {
1028 my ( %rdr_types )
1029 =
1030 (
1031 11 => 'INT8',
1032 12 => 'INT16',
1033 13 => 'INT32',
1034 14 => 'UINT8',
1035 15 => 'UINT16',
1036 16 => 'UINT32',
1037 21 => 'FLOAT',
1038 31 => 'BOOLEAM',
1039 41 => 'STRING'
1040 );
1041  
1042 return \%rdr_types;
1043 }
1044  
1045 sub transpose_rdr_types
1046 {
1047 my ( %rdr_values ) = (
1048 '4042321920' => 'SubscriberUsage',
1049 '4042321922' => 'RealTimeSubscriberUsage',
1050 '4042321924' => 'PackageUsage',
1051 '4042321925' => 'LinkUsage',
1052 '4042321926' => 'VirtualLink',
1053 '4042321936' => 'Transaction',
1054 '4042323000' => 'TransactionUsage',
1055 '4042323004' => 'HTTPTransaction',
1056 '4042323008' => 'RTSPTransaction',
1057 '4042323050' => 'VoIPTransaction',
1058 '4042321984' => 'Blocking',
1059 '4042321954' => 'QuotaBreach',
1060 '4042321968' => 'RemainingQuota',
1061 '4042321969' => 'QuotaThreshold',
1062 '4042321970' => 'QuotaStateRestore',
1063 '4042321987' => 'Radius',
1064 '4042321986' => 'DHCP',
1065 '4042321942' => 'FlowStart',
1066 '4042321944' => 'FlowEnd',
1067 '4042323052' => 'MediaFlow',
1068 '4042321943' => 'FlowOnGoing',
1069 '4042321945' => 'AttackStart',
1070 '4042321946' => 'AttackEnd',
1071 '4042322000' => 'MaliciousTraffic',
1072 '8456' => 'PrivateOne',
1073 '77771' => 'PrivateTwo',
1074 '77775' => 'PrivateThree',
1075 '77776' => 'PrivateFour',
1076 '1000000' => 'PrivateFive',
1077 '11110001' => 'PrivateSix',
1078 '11110002' => 'PrivateSeven',
1079 '11110003' => 'PrivateEight',
1080 '11110004' => 'PrivateNine',
1081 '11111001' => 'PrivateTen',
1082 '11120001' => 'PrivateEleven',
1083 '11140001' => 'PrivateTwelve',
1084 '11150001' => 'PrivateThirteen',
1085 '11160001' => 'PrivateFourteen',
1086 '11170001' => 'PrivateFifteen',
1087 '4294967295' => 'TestRDR'
1088  
1089 );
1090 return \%rdr_values;
1091 }
1092  
1093 sub convert_mac_address
1094 {
1095 my ( $self ) = shift;
1096 my ( $raw_input) = shift;
1097 return "" if !$raw_input;
1098 my ( $char1, $char2, $char3, $char4, $char5, $char6) = unpack ('CCCCCC', $raw_input);
1099 $char1=sprintf ("%#.2x",$char1); $char1=(split(/0x/,$char1))[1] if $char1=~/x/g;
1100 $char2=sprintf ("%#.2x",$char2); $char2=(split(/0x/,$char2))[1] if $char2=~/x/g;
1101 $char3=sprintf ("%#.2x",$char3); $char3=(split(/0x/,$char3))[1] if $char3=~/x/g;
1102 $char4=sprintf ("%#.2x",$char4); $char4=(split(/0x/,$char4))[1] if $char4=~/x/g;
1103 $char5=sprintf ("%#.2x",$char5); $char5=(split(/0x/,$char5))[1] if $char5=~/x/g;
1104 $char6=sprintf ("%#.2x",$char6); $char6=(split(/0x/,$char6))[1] if $char6=~/x/g;
1105 return ("$char1$char2.$char3$char4.$char5$char6");
1106 }
1107  
1108  
1109 =head1 AUTHOR
1110  
1111 Andrew S. Kennedy, C<< <shamrock at cpan.org> >>
1112  
1113 =head1 BUGS
1114  
1115 Please report any bugs or feature requests to C<bug-rdr-collector at rt.cpan.org>, or through
1116 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RDR-Processor>. I will be notified, and then you'll
1117 automatically be notified of progress on your bug as I make changes.
1118  
1119 =head1 SUPPORT
1120  
1121 You can find documentation for this module with the perldoc command.
1122  
1123 perldoc RDR::Processor
1124  
1125 You can also look for information at:
1126  
1127 =over 4
1128  
1129 =item * RT: CPAN's request tracker
1130  
1131 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RDR-Processor>
1132  
1133 =item * AnnoCPAN: Annotated CPAN documentation
1134  
1135 L<http://annocpan.org/dist/RDR-Processor>
1136  
1137 =item * CPAN Ratings
1138  
1139 L<http://cpanratings.perl.org/d/RDR-Processor>
1140  
1141 =item * Search CPAN
1142  
1143 L<http://search.cpan.org/dist/RDR-Processor>
1144  
1145 =back
1146  
1147  
1148 =head1 ACKNOWLEDGEMENTS
1149  
1150  
1151 =head1 COPYRIGHT & LICENSE
1152  
1153 Copyright 2008 Andrew S. Kennedy, all rights reserved.
1154  
1155 This program is free software; you can redistribute it and/or modify it
1156 under the same terms as Perl itself.
1157  
1158  
1159 =cut
1160  
1161 1; # End of RDR::Processor