| 1 | package RDR::Collector; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use IO::File; | ||
| 6 | use IO::Select; | ||
| 7 | use IO::Socket; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | RDR::Collector - Collect RDRv1 packets | ||
| 12 | |||
| 13 | =head1 VERSION | ||
| 14 | |||
| 15 | Version 1.0000 | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | our $VERSION = '1.0000'; | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | This module is designed to capture and process raw RDR packets from a Cisco | ||
| 24 | SCE series device. | ||
| 25 | |||
| 26 | The configuration for the SCE device is very simple and consists of one line | ||
| 27 | of configuration per priority. | ||
| 28 | |||
| 29 | An example configuration is shown below | ||
| 30 | |||
| 31 | RDR-formatter forwarding-mode multicast | ||
| 32 | RDR-formatter destination 192.168.1.1 port 33110 category number 1 priority 70 | ||
| 33 | RDR-formatter destination 192.168.1.1 port 33120 category number 2 priority 70 | ||
| 34 | RDR-formatter destination 192.168.1.1 port 33130 category number 3 priority 70 | ||
| 35 | RDR-formatter destination 192.168.1.1 port 33140 category number 4 priority 70 | ||
| 36 | |||
| 37 | The RDR collector is not designed to accept multiple connections so each | ||
| 38 | priority needs to be sent to a different port. You then need to set up a | ||
| 39 | receiver on 4 different ports (run the example script 4 times) so you can collect | ||
| 40 | the RDRs. In the example above the collecting host is on IP 192.168.1.1. Alternatively | ||
| 41 | if you have multiple SCE devices then you need to configure each one to send to | ||
| 42 | different ports. | ||
| 43 | |||
| 44 | An example on how to use this module is shown below. It is relatively simple and | ||
| 45 | sets up a listening port bound to the IP and Port specified. | ||
| 46 | |||
| 47 | #!/usr/bin/perl | ||
| 48 | |||
| 49 | use strict; | ||
| 50 | use RDR::Collector; | ||
| 51 | use IO::File; | ||
| 52 | |||
| 53 | my $rdr_client = new RDR::Collector( | ||
| 54 | [ | ||
| 55 | ServerIP => '192.168.1.1', | ||
| 56 | ServerPort => '10000', | ||
| 57 | Timeout => 2, | ||
| 58 | DataHandler => \&display_data | ||
| 59 | ] | ||
| 60 | ); | ||
| 61 | |||
| 62 | # Setup the local RDR listener | ||
| 63 | my $status = $rdr_client->connect(); | ||
| 64 | |||
| 65 | # If we could not listen tell us why. | ||
| 66 | if ( !$status ) | ||
| 67 | { | ||
| 68 | print "Status was '".$rdr_client->return_status()."'\n"; | ||
| 69 | print "Error was '".$rdr_client->return_error()."'\n"; | ||
| 70 | exit(0); | ||
| 71 | } | ||
| 72 | |||
| 73 | # Now just wait for RDR data. | ||
| 74 | $rdr_client->check_data_available(); | ||
| 75 | |||
| 76 | exit(0); | ||
| 77 | |||
| 78 | # This routine is called from DataHandler when the module | ||
| 79 | # instance is initialised. | ||
| 80 | # 4 parameters are returned, internal ref, remote IP, remote Port and | ||
| 81 | # the raw data | ||
| 82 | sub display_data | ||
| 83 | { | ||
| 84 | my ( $glob ) = shift; | ||
| 85 | my ( $remote_ip ) = shift; | ||
| 86 | my ( $remote_port ) = shift; | ||
| 87 | my ( $data ) = shift; | ||
| 88 | my $attribute_line; | ||
| 89 | my $data_line; | ||
| 90 | my @keys = keys %{$data}; | ||
| 91 | foreach my $key_name ( @keys ) | ||
| 92 | { | ||
| 93 | $attribute_line.="$key_name,"; | ||
| 94 | $data_line.=${$data}{$key_name}.","; | ||
| 95 | } | ||
| 96 | print "#$attribute_line\n"; | ||
| 97 | print "$data_line\n"; | ||
| 98 | } | ||
| 99 | |||
| 100 | This is the most basic way to access the data. There are multiple scripts in | ||
| 101 | the examples directory which will allow you to collect and process the RDR | ||
| 102 | data. | ||
| 103 | |||
| 104 | =head1 EXPORT | ||
| 105 | |||
| 106 | None | ||
| 107 | |||
| 108 | =head1 FUNCTIONS | ||
| 109 | |||
| 110 | =head2 new | ||
| 111 | |||
| 112 | The parameters for new are below | ||
| 113 | |||
| 114 | ServerIP | ||
| 115 | |||
| 116 | This is the IP address the client should listen on. | ||
| 117 | |||
| 118 | ServerPort | ||
| 119 | |||
| 120 | This is the port the client should listen on. | ||
| 121 | |||
| 122 | Timeout | ||
| 123 | |||
| 124 | This is the amount of time to wait for a TCP timeout. Not entirely sure this | ||
| 125 | works so do not rely on it. | ||
| 126 | |||
| 127 | DataHandler | ||
| 128 | |||
| 129 | This should contain a pointer to a user defined function. An example would be | ||
| 130 | |||
| 131 | DataHandler => \&display_data | ||
| 132 | |||
| 133 | The function should accept for entry points, | ||
| 134 | |||
| 135 | $glob - pointer to the internal _GLOBAL variables | ||
| 136 | $remote_ip - IP address of the connected client | ||
| 137 | $remote_port - Port of the connected client | ||
| 138 | $data - hash of the current RDR record | ||
| 139 | |||
| 140 | function display_data | ||
| 141 | { | ||
| 142 | my ( $glob ) = shift; | ||
| 143 | my ( $remote_ip ) = shift; | ||
| 144 | my ( $remote_port ) = shift; | ||
| 145 | my ( $data ) = shift; | ||
| 146 | # do something | ||
| 147 | } | ||
| 148 | |||
| 149 | =head2 connect | ||
| 150 | |||
| 151 | This function attempts to set up the listening socket on the IP and Port specified | ||
| 152 | in the new function. The parameters | ||
| 153 | |||
| 154 | ServerIP | ||
| 155 | ServerPort | ||
| 156 | Timeout | ||
| 157 | |||
| 158 | If the socket can not be setup the function returns 0 and sets error message, if it | ||
| 159 | is successful it return 1. | ||
| 160 | |||
| 161 | =head2 return_error | ||
| 162 | |||
| 163 | This function returns the current error. | ||
| 164 | |||
| 165 | =head2 check_data_available | ||
| 166 | |||
| 167 | This function sets up the listener loop for data on the socket. It calls the user | ||
| 168 | specified function in the new object setup. | ||
| 169 | |||
| 170 | =cut | ||
| 171 | |||
| 172 | sub new { | ||
| 173 | |||
| 174 | my $self = {}; | ||
| 175 | bless $self; | ||
| 176 | |||
| 177 | my ( %handles ); | ||
| 178 | |||
| 179 | my ( $class , $attr ) =@_; | ||
| 180 | |||
| 181 | $self->{_GLOBAL}{'DEBUG'}=0; | ||
| 182 | |||
| 183 | while (my($field, $val) = splice(@{$attr}, 0, 2)) | ||
| 184 | { $self->{_GLOBAL}{$field}=$val; } | ||
| 185 | |||
| 186 | $self->{_GLOBAL}{'STATUS'}="OK"; | ||
| 187 | |||
| 188 | if ( !$self->{_GLOBAL}{'VendorID'} ) | ||
| 189 | { $self->{_GLOBAL}{'VendorID'}="Generic Client"; } | ||
| 190 | |||
| 191 | if ( !$self->{_GLOBAL}{'ServerIP'} ) | ||
| 192 | { die "ServerIP Required"; } | ||
| 193 | |||
| 194 | if ( !$self->{_GLOBAL}{'ServerPort'} ) | ||
| 195 | { die "ServerPort Required"; } | ||
| 196 | |||
| 197 | if ( !$self->{_GLOBAL}{'Timeout'} ) | ||
| 198 | { $self->{_GLOBAL}{'Timeout'}=5; } | ||
| 199 | |||
| 200 | if ( !$self->{_GLOBAL}{'DataHandler'} ) | ||
| 201 | { die "DataHandler Function Must Be Defined"; } | ||
| 202 | |||
| 203 | if ( !$self->{_GLOBAL}{'Faster'} ) | ||
| 204 | { $self->{_GLOBAL}{'Faster'}=0; } | ||
| 205 | |||
| 206 | if ( $self->{_GLOBAL}{'Faster'} ) | ||
| 207 | { | ||
| 208 | if ( !$self->{_GLOBAL}{'Faster_Limit'} ) | ||
| 209 | { die "Fast Limit Required"; } | ||
| 210 | } | ||
| 211 | |||
| 212 | $self->{_GLOBAL}{'handles'}= \%handles; | ||
| 213 | |||
| 214 | $self->{_GLOBAL}{'ProcessLength'} = 2000; | ||
| 215 | $self->{_GLOBAL}{'ProcessBuffer'} = ""; | ||
| 216 | |||
| 217 | $self->{_GLOBAL}{'fields'} = fields_rdr( ); | ||
| 218 | $self->{_GLOBAL}{'field_types'} = field_types_rdr( ); | ||
| 219 | $self->{_GLOBAL}{'rdr_types'} = transpose_rdr_types( ); | ||
| 220 | |||
| 221 | return $self; | ||
| 222 | } | ||
| 223 | |||
| 224 | sub connect | ||
| 225 | { | ||
| 226 | my ( $self ) = shift; | ||
| 227 | |||
| 228 | # We need to add binding to specific addresses at | ||
| 229 | # some point. | ||
| 230 | # The new construct can slurp them in now anyway | ||
| 231 | # they are just ignored. | ||
| 232 | |||
| 233 | my $lsn = IO::Socket::INET->new | ||
| 234 | ( | ||
| 235 | Listen => 5, | ||
| 236 | LocalAddr => $self->{_GLOBAL}{'ServerIP'}, | ||
| 237 | LocalPort => $self->{_GLOBAL}{'ServerPort'}, | ||
| 238 | ReuseAddr => 1, | ||
| 239 | Proto => 'tcp', | ||
| 240 | Timeout => $self->{_GLOBAL}{'Timeout'} | ||
| 241 | ); | ||
| 242 | if (!$lsn) | ||
| 243 | { | ||
| 244 | $self->{_GLOBAL}{'STATUS'}="Failed to bind to address '".$self->{_GLOBAL}{'ServerIP'}."' ";; | ||
| 245 | $self->{_GLOBAL}{'STATUS'}.="and port '".$self->{_GLOBAL}{'ServerPort'}; | ||
| 246 | $self->{_GLOBAL}{'ERROR'}=$!; | ||
| 247 | return 0; | ||
| 248 | } | ||
| 249 | |||
| 250 | $lsn->sockopt(SO_RCVBUF, 2621440); | ||
| 251 | |||
| 252 | if ( $self->{_GLOBAL}{'Faster'}==1 ) | ||
| 253 | { | ||
| 254 | $self->{_GLOBAL}{'Faster_Count'}=0; | ||
| 255 | $self->return_file_handle(); | ||
| 256 | } | ||
| 257 | |||
| 258 | $self->{_GLOBAL}{'Handle'} = $lsn; | ||
| 259 | $self->{_GLOBAL}{'Selector'}=new IO::Select( $lsn ); | ||
| 260 | $self->{_GLOBAL}{'STATUS'}="Success Connected"; | ||
| 261 | return 1; | ||
| 262 | } | ||
| 263 | |||
| 264 | sub return_file_handle | ||
| 265 | { | ||
| 266 | my $self = shift; | ||
| 267 | if ( $self->{_GLOBAL}{'Faster_File'} ) | ||
| 268 | { | ||
| 269 | my $current_file = $self->{_GLOBAL}{'Faster_File'}; | ||
| 270 | $current_file->close(); | ||
| 271 | $self->{_GLOBAL}{'Faster_Previous'} = $self->{_GLOBAL}{'Faster_Name'}; | ||
| 272 | } | ||
| 273 | my $random_name = "rdr_collect_".time(); | ||
| 274 | my $handle = IO::File->new("/tmp/$random_name","w"); | ||
| 275 | $self->{_GLOBAL}{'Faster_Name'}="/tmp/$random_name"; | ||
| 276 | $self->{_GLOBAL}{'Faster_File'}=$handle; | ||
| 277 | } | ||
| 278 | |||
| 279 | sub return_status | ||
| 280 | { | ||
| 281 | my ( $self ) = shift; | ||
| 282 | |||
| 283 | return $self->{_GLOBAL}{'STATUS'}; | ||
| 284 | } | ||
| 285 | |||
| 286 | sub return_error | ||
| 287 | { | ||
| 288 | my ( $self ) = shift; | ||
| 289 | |||
| 290 | return $self->{_GLOBAL}{'ERROR'}; | ||
| 291 | } | ||
| 292 | |||
| 293 | |||
| 294 | sub get_data_segment3 | ||
| 295 | { | ||
| 296 | my ( $self ) = shift; | ||
| 297 | my ( $dataset ) ; | ||
| 298 | |||
| 299 | my ( $handles ) = $self->{_GLOBAL}{'handles'}; | ||
| 300 | my ( $current_handles ) = $self->{_GLOBAL}{'ready_handles'}; | ||
| 301 | |||
| 302 | foreach my $handle ( @{$current_handles} ) | ||
| 303 | { | ||
| 304 | if ( $handle==$self->{_GLOBAL}{'Handle'} ) | ||
| 305 | { | ||
| 306 | my $new = $self->{_GLOBAL}{'Handle'}->accept; | ||
| 307 | $self->{_GLOBAL}{'Selector'}->add($new); | ||
| 308 | print "Connection established.\n"; | ||
| 309 | } | ||
| 310 | else | ||
| 311 | { | ||
| 312 | my $blah; | ||
| 313 | my $link= sysread($handle, $blah ,1024); | ||
| 314 | if ( $link==0 ) | ||
| 315 | { | ||
| 316 | delete ${$handles}{$handle}; | ||
| 317 | $self->{_GLOBAL}{'Selector'}->remove($handle); | ||
| 318 | $handle->close(); | ||
| 319 | } | ||
| 320 | if ( $link>0 ) | ||
| 321 | { | ||
| 322 | $self->{_GLOBAL}{'DataHandler'}->( | ||
| 323 | $self->{_GLOBAL}, | ||
| 324 | $handle->peerhost(), | ||
| 325 | $handle->peerport(), | ||
| 326 | $blah | ||
| 327 | ); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | } | ||
| 331 | return 1; | ||
| 332 | } | ||
| 333 | |||
| 334 | |||
| 335 | sub get_data_segment2 | ||
| 336 | { | ||
| 337 | my ( $self ) = shift; | ||
| 338 | my ( $dataset ) = shift; | ||
| 339 | |||
| 340 | my ( $fields ) = $self->{_GLOBAL}{'fields'}; | ||
| 341 | my ( $field_types ) = $self->{_GLOBAL}{'field_types'}; | ||
| 342 | my ( $rdr_types ) = $self->{_GLOBAL}{'rdr_types'}; | ||
| 343 | |||
| 344 | #print "Dataset length is '".length($dataset)."'\n"; | ||
| 345 | |||
| 346 | if ( length($dataset)<15 ) | ||
| 347 | { | ||
| 348 | #print "Skipping data set here.\n"; | ||
| 349 | return ""; | ||
| 350 | } | ||
| 351 | |||
| 352 | my ( $proc ) = unpack ("C",$dataset); | ||
| 353 | |||
| 354 | my ( $length ) = substr($dataset,1,4); | ||
| 355 | |||
| 356 | return "" if !$length; | ||
| 357 | |||
| 358 | if ( length($length)<4 ) | ||
| 359 | { | ||
| 360 | #print "Length should be 4 it is '".length($length)."'\n"; | ||
| 361 | return ""; | ||
| 362 | } | ||
| 363 | |||
| 364 | $length = convert_chars_value ( $length ); | ||
| 365 | |||
| 366 | #$length = hex(substr($length,0,1)).hex(substr($length,1,1)).hex(substr($length,2,1)).hex(substr($length,3,1)); | ||
| 367 | if ( $length=~/^dead/i ) | ||
| 368 | { | ||
| 369 | #print "Bad length found length is '$length'.\n"; | ||
| 370 | return ""; | ||
| 371 | } | ||
| 372 | |||
| 373 | $length+=1; | ||
| 374 | #print "Dataset length is '".length($dataset)."'\n"; | ||
| 375 | |||
| 376 | $dataset = substr( $dataset,5,length($dataset)-5 ); | ||
| 377 | |||
| 378 | #print "Dataset length is '".length($dataset)."'\n"; | ||
| 379 | |||
| 380 | my ( $src, $dst, $src_port, $dst_port, $flow_id, $type,$fieldcount ) = unpack ("CCSSH8H8C",$dataset ); | ||
| 381 | |||
| 382 | #print "src '$src' dst '$dst' src_port '$src_port' dst_port '$dst_port' flow id '$flow_id' type '$type' fieldcount '$fieldcount'\n"; | ||
| 383 | $type = hex($type); | ||
| 384 | my %result; | ||
| 385 | my $return_value=""; | ||
| 386 | |||
| 387 | if ( length($dataset)>=15 ) | ||
| 388 | { | ||
| 389 | $return_value = $self->extract_rdr( | ||
| 390 | $type, | ||
| 391 | $fieldcount, | ||
| 392 | substr($dataset, 15,length($dataset)-15), | ||
| 393 | \%result | ||
| 394 | ); | ||
| 395 | |||
| 396 | $self->{_GLOBAL}{'DataHandler'}->( | ||
| 397 | $self->{_GLOBAL}, | ||
| 398 | $self->{_GLOBAL}{'ServerIP'}, | ||
| 399 | $self->{_GLOBAL}{'ServerPort'}, | ||
| 400 | \%result | ||
| 401 | ); | ||
| 402 | } | ||
| 403 | undef %result; | ||
| 404 | |||
| 405 | #print "Remaining return value is '".length($return_value)."'\n"; | ||
| 406 | |||
| 407 | return $return_value; | ||
| 408 | } | ||
| 409 | |||
| 410 | |||
| 411 | sub get_data_segment | ||
| 412 | { | ||
| 413 | my ( $self ) = shift; | ||
| 414 | my ( $dataset ) ; | ||
| 415 | |||
| 416 | my ( $handles ) = $self->{_GLOBAL}{'handles'}; | ||
| 417 | my ( $current_handles ) = $self->{_GLOBAL}{'ready_handles'}; | ||
| 418 | |||
| 419 | foreach my $handle ( @{$current_handles} ) | ||
| 420 | { | ||
| 421 | if ( $handle==$self->{_GLOBAL}{'Handle'} ) | ||
| 422 | { | ||
| 423 | my $new = $self->{_GLOBAL}{'Handle'}->accept; | ||
| 424 | $self->{_GLOBAL}{'Selector'}->add($new); | ||
| 425 | print "Connection established.\n"; | ||
| 426 | } | ||
| 427 | else | ||
| 428 | { | ||
| 429 | my $blah=""; | ||
| 430 | my $link= sysread($handle, $blah ,4096); | ||
| 431 | if ( $link==0 ) | ||
| 432 | { | ||
| 433 | print "Connection removed.\n"; | ||
| 434 | $self->{_GLOBAL}{'Selector'}->remove($handle); | ||
| 435 | $handle->close(); | ||
| 436 | } | ||
| 437 | if ( $link>0 ) | ||
| 438 | { | ||
| 439 | if ( $self->{_GLOBAL}{'Faster'}==1 ) | ||
| 440 | { | ||
| 441 | $self->{_GLOBAL}{'Faster_Count'}++; | ||
| 442 | my $handle = $self->{_GLOBAL}{'Faster_File'}; | ||
| 443 | print $handle $blah; | ||
| 444 | if ( $self->{_GLOBAL}{'Faster_Count'}>= $self->{_GLOBAL}{'Faster_Limit'} ) | ||
| 445 | { | ||
| 446 | $self->return_file_handle(); | ||
| 447 | $self->{_GLOBAL}{'Faster_Count'}=0; | ||
| 448 | } | ||
| 449 | |||
| 450 | } | ||
| 451 | } | ||
| 452 | if ( $self->{_GLOBAL}{'Faster'}==0 ) | ||
| 453 | { | ||
| 454 | $self->{_GLOBAL}{'ProcessBuffer'} = $self->{_GLOBAL}{'ProcessBuffer'}.$blah; | ||
| 455 | while ( ($self->{_GLOBAL}{'ProcessLength'}+5) < length($self->{_GLOBAL}{'ProcessBuffer'}) ) | ||
| 456 | { | ||
| 457 | my ( $proc ) = unpack ("C",$self->{_GLOBAL}{'ProcessBuffer'} ); | ||
| 458 | my ( $length ) = substr($self->{_GLOBAL}{'ProcessBuffer'},1,4); | ||
| 459 | $length = convert_chars_value ( $length ); | ||
| 460 | $self->{_GLOBAL}{'ProcessLength'} = $length; | ||
| 461 | if ( $length=~/^dead/i ) | ||
| 462 | { | ||
| 463 | while ( $length=~/^dead/i && length($self->{_GLOBAL}{'ProcessBuffer'})>0 ) | ||
| 464 | { | ||
| 465 | $self->{_GLOBAL}{'ProcessBuffer'} = substr($self->{_GLOBAL}{'ProcessBuffer'},1,length($self->{_GLOBAL}{'ProcessBuffer'})-1); | ||
| 466 | $proc = unpack ("C",$self->{_GLOBAL}{'ProcessBuffer'} ); | ||
| 467 | $length = substr($self->{_GLOBAL}{'ProcessBuffer'},1,4); | ||
| 468 | $length = convert_chars_value ( $length ); | ||
| 469 | $self->{_GLOBAL}{'ProcessLength'} = $length; | ||
| 470 | #print "Entering fix loop length now '$length'\n"; | ||
| 471 | } | ||
| 472 | if ( $self->{_GLOBAL}{'ProcessLength'}=~/^dead/i ) | ||
| 473 | { | ||
| 474 | #print "This is really broken now.\n"; | ||
| 475 | } | ||
| 476 | } | ||
| 477 | if ( ($self->{_GLOBAL}{'ProcessLength'})+5<length($self->{_GLOBAL}{'ProcessBuffer'}) ) | ||
| 478 | { | ||
| 479 | my $body = substr($self->{_GLOBAL}{'ProcessBuffer'},0,$self->{_GLOBAL}{'ProcessLength'}+5); | ||
| 480 | $self->{_GLOBAL}{'PreviousDataSegment'} = $self->{_GLOBAL}{'ProcessBuffer'}; | ||
| 481 | $self->{_GLOBAL}{'PreviousDataSize'} = length($self->{_GLOBAL}{'ProcessBuffer'}); | ||
| 482 | $self->{_GLOBAL}{'PreviousDataLength'} = $self->{_GLOBAL}{'ProcessLength'}; | ||
| 483 | $self->{_GLOBAL}{'PreviousDataChunked'} = length($self->{_GLOBAL}{'ProcessBuffer'})-length($body); | ||
| 484 | $self->{_GLOBAL}{'ProcessBuffer'} = substr($self->{_GLOBAL}{'ProcessBuffer'}, length($body), length($self->{_GLOBAL}{'ProcessBuffer'})-length($body) ); | ||
| 485 | my ($deader) = $self->get_data_segment2($body); | ||
| 486 | } | ||
| 487 | } | ||
| 488 | } | ||
| 489 | } | ||
| 490 | } | ||
| 491 | return 1; | ||
| 492 | } | ||
| 493 | |||
| 494 | sub check_data_available3 | ||
| 495 | { | ||
| 496 | my ( $self ) = shift; | ||
| 497 | |||
| 498 | while ( $self->check_data_handles ) | ||
| 499 | { $self->get_data_segment3(); } | ||
| 500 | |||
| 501 | $self->{_GLOBAL}{'STATUS'}="Socket Closed"; | ||
| 502 | $self->{_GLOBAL}{'ERROR'}="Socket Closed"; | ||
| 503 | } | ||
| 504 | |||
| 505 | |||
| 506 | |||
| 507 | sub check_data_available | ||
| 508 | { | ||
| 509 | my ( $self ) = shift; | ||
| 510 | |||
| 511 | while ( $self->check_data_handles ) | ||
| 512 | { | ||
| 513 | $self->get_data_segment(); } | ||
| 514 | |||
| 515 | $self->{_GLOBAL}{'STATUS'}="Socket Closed"; | ||
| 516 | $self->{_GLOBAL}{'ERROR'}="Socket Closed"; | ||
| 517 | } | ||
| 518 | |||
| 519 | |||
| 520 | sub check_data_handles | ||
| 521 | { | ||
| 522 | my ( $self ) = shift; | ||
| 523 | my ( @handle ) = $self->{_GLOBAL}{'Selector'}->can_read; | ||
| 524 | $self->{_GLOBAL}{'ready_handles'}=\@handle; | ||
| 525 | } | ||
| 526 | |||
| 527 | sub extract_rdr | ||
| 528 | { | ||
| 529 | my ( $self ) = shift; | ||
| 530 | my ( $type ) = shift; | ||
| 531 | my ( $count ) = shift; | ||
| 532 | my ( $data_block ) = shift; | ||
| 533 | my ( $pointer ) = shift; | ||
| 534 | |||
| 535 | return "" if !$data_block; | ||
| 536 | |||
| 537 | my ( $fields ) = $self->{_GLOBAL}{'fields'}; | ||
| 538 | my ( $field_types ) = $self->{_GLOBAL}{'field_types'}; | ||
| 539 | my ( $rdr_types ) = $self->{_GLOBAL}{'rdr_types'}; | ||
| 540 | my ( $protocol_ids ) = $self->{_GLOBAL}{'protocol_ids'}; | ||
| 541 | |||
| 542 | my ( $trans_fields ); | ||
| 543 | my ( $name ) = ${$rdr_types}{$type}; | ||
| 544 | if ( !$name ) | ||
| 545 | { | ||
| 546 | #print "RDR type not found was '$type'\n"; | ||
| 547 | return ""; | ||
| 548 | } | ||
| 549 | if ( ${$fields}{$name} ) | ||
| 550 | { | ||
| 551 | #print "Name is '$name'\n"; | ||
| 552 | ( $trans_fields ) = ${$fields}{$name}; | ||
| 553 | } | ||
| 554 | |||
| 555 | #return unless $name=~/^SubscriberUsage$/i; | ||
| 556 | |||
| 557 | #print "Size of keys is '".scalar(keys %{$trans_fields})."'\n"; | ||
| 558 | |||
| 559 | #print "RDR name is '$name'\n"; | ||
| 560 | |||
| 561 | $self->{_GLOBAL}{'PreviousRDRName'} = $name; | ||
| 562 | $self->{_GLOBAL}{'PreviousRDRCount'} = scalar(keys %{$trans_fields}); | ||
| 563 | |||
| 564 | if ( scalar(keys %{$trans_fields})> 0 ) | ||
| 565 | { | ||
| 566 | for( $a=0;$a<scalar(keys %{$trans_fields});$a++ ) | ||
| 567 | { | ||
| 568 | next if length($data_block)<5; | ||
| 569 | my ( $block_start ) = substr( $data_block,0,5); | ||
| 570 | |||
| 571 | #print "Length of block_start is '".length($block_start)."'\n"; | ||
| 572 | |||
| 573 | my ( $type, $data_length ) = unpack("CN",$block_start); | ||
| 574 | |||
| 575 | #print "Type is '$type' length is '$data_length'\n"; | ||
| 576 | |||
| 577 | my ( $current_block ) = substr($data_block,5,$data_length); | ||
| 578 | |||
| 579 | if ( length($data_block)>=($data_length+5) ) | ||
| 580 | { | ||
| 581 | $data_block = substr($data_block,$data_length+5,length($data_block)-($data_length+5)); | ||
| 582 | } | ||
| 583 | else | ||
| 584 | { | ||
| 585 | next; | ||
| 586 | } | ||
| 587 | |||
| 588 | if ( !$type ) | ||
| 589 | { | ||
| 590 | #print "Type not found was '$type'.\n"; | ||
| 591 | next; | ||
| 592 | } | ||
| 593 | |||
| 594 | if ( !${$field_types}{$type} ) | ||
| 595 | { | ||
| 596 | #print "RDR field not found was '$type' count was '$a' max is '".scalar(keys %{$trans_fields})."'\n"; | ||
| 597 | #print "Length is '$data_length'\n"; | ||
| 598 | if ( length($current_block)<$data_length ) | ||
| 599 | { | ||
| 600 | next; | ||
| 601 | } | ||
| 602 | } | ||
| 603 | |||
| 604 | my ( $real_type ) = ${$field_types}{$type}; | ||
| 605 | |||
| 606 | #print "Name is '".${$trans_fields}{$a}."' length is '".$data_length."'\n"; | ||
| 607 | |||
| 608 | if ( !$real_type ) | ||
| 609 | { | ||
| 610 | #print "Real type failed with '$real_type'\n"; | ||
| 611 | } | ||
| 612 | |||
| 613 | #print "Type was '$type' Real type was '$real_type' \n"; | ||
| 614 | |||
| 615 | my ( $value ) = substr($current_block,0,$data_length); | ||
| 616 | |||
| 617 | if ( ${$trans_fields}{$a}=~/\_ip$/i ) | ||
| 618 | { $value = decode_type ( $name, $real_type, $value, ${$trans_fields}{$a} ); $value = _IpIntToQuad($value); } | ||
| 619 | |||
| 620 | if ( ${$trans_fields}{$a}=~/\_mac$/i ) | ||
| 621 | { $value = $self->convert_mac_address ( $value ); } | ||
| 622 | |||
| 623 | if ( ${$trans_fields}{$a}!~/\_ip$/i && ${$trans_fields}{$a}!~/\_mac$/ ) | ||
| 624 | { | ||
| 625 | $value = decode_type ( $name, $real_type, $value, ${$trans_fields}{$a} ); | ||
| 626 | } | ||
| 627 | |||
| 628 | if ( $value=~/^dead/i ) | ||
| 629 | { | ||
| 630 | #print "Value was DEAD return outbound.\n"; | ||
| 631 | # return $data_block; | ||
| 632 | ${$pointer}{ ${$trans_fields}{$a} } ="DEAD"; | ||
| 633 | next; | ||
| 634 | } | ||
| 635 | |||
| 636 | |||
| 637 | # if ( ${$trans_fields}{$a}=~/\_mac$/i ) | ||
| 638 | # { $value = $self->convert_mac_address ( $value ); } | ||
| 639 | |||
| 640 | if ( ${$trans_fields}{$a}=~/^protocol_id$/i ) | ||
| 641 | { | ||
| 642 | my $protocol_id_found = ${$protocol_ids}{$value}; | ||
| 643 | if ( !$protocol_id_found ) | ||
| 644 | { | ||
| 645 | $value = $value."(".$value.")"; | ||
| 646 | } | ||
| 647 | else | ||
| 648 | { | ||
| 649 | $value = $protocol_id_found."(".$value.")"; | ||
| 650 | } | ||
| 651 | } | ||
| 652 | |||
| 653 | |||
| 654 | ${$pointer}{ ${$trans_fields}{$a} } = $value; | ||
| 655 | #next if length($data_block)<($data_length+5); | ||
| 656 | } | ||
| 657 | } | ||
| 658 | else | ||
| 659 | { | ||
| 660 | #print "RDR record is just plain broken or unknown.\n"; | ||
| 661 | } | ||
| 662 | ${$pointer}{'RDR_Record'}=$name; | ||
| 663 | return $data_block; | ||
| 664 | } | ||
| 665 | |||
| 666 | sub _IpIntToQuad { my($Int) = shift; | ||
| 667 | if (!$Int) { return "0.0.0.0"; } | ||
| 668 | my($Ip1) = $Int & 0xFF; $Int >>= 8; | ||
| 669 | my($Ip2) = $Int & 0xFF; $Int >>= 8; | ||
| 670 | my($Ip3) = $Int & 0xFF; $Int >>= 8; | ||
| 671 | my($Ip4) = $Int & 0xFF; return("$Ip4.$Ip3.$Ip2.$Ip1"); | ||
| 672 | } | ||
| 673 | |||
| 674 | sub decode_type | ||
| 675 | { | ||
| 676 | my ( $rdr_name ) = shift; | ||
| 677 | my ( $type ) = shift; | ||
| 678 | my ( $value ) = shift; | ||
| 679 | my ( $field_name ) = shift; | ||
| 680 | |||
| 681 | my ( $return_value ); | ||
| 682 | |||
| 683 | #print "Decoder running for RDR '$rdr_name' fieldname '$field_name' type '$type' value is "; | ||
| 684 | |||
| 685 | if ( !$value ) { return 1; } | ||
| 686 | if ( !$type ) { return 1; } | ||
| 687 | if ( $type=~/^int8$/i ) { $return_value = unpack("c",$value); } | ||
| 688 | if ( $type=~/^uint8$/i ) { $return_value = unpack("C",$value); } | ||
| 689 | |||
| 690 | # this is just crazy | ||
| 691 | if ( $type=~/^int16$/i ) { | ||
| 692 | # now we should just have 2 bytes, so swap them and decode as s | ||
| 693 | # this is slow as you like, but hey thats life !!! | ||
| 694 | my $byte1 = substr($value,0,1); | ||
| 695 | my $byte2 = substr($value,1,1); | ||
| 696 | my $done = $byte2.$byte1; | ||
| 697 | $return_value = unpack("s",$done); | ||
| 698 | } | ||
| 699 | |||
| 700 | # this is now correct | ||
| 701 | if ( $type=~/^uint16$/i ) { | ||
| 702 | $return_value = unpack("n",$value); | ||
| 703 | } | ||
| 704 | |||
| 705 | # more crazy stuff | ||
| 706 | if ( $type=~/^int32$/i ) { | ||
| 707 | # this needs all four bytes changing in order | ||
| 708 | my $byte1 = substr($value,0,1); | ||
| 709 | my $byte2 = substr($value,1,1); | ||
| 710 | my $byte3 = substr($value,2,1); | ||
| 711 | my $byte4 = substr($value,3,1); | ||
| 712 | my $done = $byte4.$byte3.$byte2.$byte1; | ||
| 713 | $return_value = unpack("l",$done); | ||
| 714 | } | ||
| 715 | |||
| 716 | # back to being normal | ||
| 717 | if ( $type=~/^uint32$/i ) { $return_value = unpack("N",$value); } | ||
| 718 | |||
| 719 | if ( $type=~/^float$/i ) { $return_value = unpack("f",$value); } | ||
| 720 | if ( $type=~/^boolean$/i ) { $return_value = unpack("C",$value); } | ||
| 721 | |||
| 722 | if ( $type=~/^string$/i ) { | ||
| 723 | if ( length($value)==0 ) | ||
| 724 | { | ||
| 725 | $return_value=""; | ||
| 726 | } | ||
| 727 | if ( $value!~/^[0-9\.a-zA-Z\\|\s\@\_\/\?\&\=\%\+\-,\^\:\[\]\{\}\$\"\;\<\>\*\~\£]+$/ && length($value)>0 ) | ||
| 728 | { | ||
| 729 | #print "actual value before death was '$value' length '".length($value)."'\n"; | ||
| 730 | $return_value ="DEAD"; | ||
| 731 | } | ||
| 732 | else | ||
| 733 | { | ||
| 734 | $return_value = $value; | ||
| 735 | } | ||
| 736 | } | ||
| 737 | |||
| 738 | if ( !$return_value ) { $return_value=0; } | ||
| 739 | |||
| 740 | #print "Mapped value was '".$return_value."'\n"; | ||
| 741 | |||
| 742 | return $return_value; | ||
| 743 | } | ||
| 744 | |||
| 745 | sub fields_rdr | ||
| 746 | { | ||
| 747 | my ( %rdr_fields ) | ||
| 748 | = ( | ||
| 749 | 'HTTPTransaction' => | ||
| 750 | { | ||
| 751 | 0 => 'subscriber_id', | ||
| 752 | 1 => 'package_id', | ||
| 753 | 2 => 'service_id', | ||
| 754 | 3 => 'protocol_id', | ||
| 755 | 4 => 'skipped_sessions', | ||
| 756 | 5 => 'server_ip', | ||
| 757 | 6 => 'server_port', | ||
| 758 | 7 => 'access_string', | ||
| 759 | 8 => 'info_string', | ||
| 760 | 9 => 'client_ip', | ||
| 761 | 10 => 'client_port', | ||
| 762 | 11 => 'initiating_side', | ||
| 763 | 12 => 'report_time', | ||
| 764 | 13 => 'millisec_duration', | ||
| 765 | 14 => 'time_frame', | ||
| 766 | 15 => 'session_upstream_volume', | ||
| 767 | 16 => 'session_downstream_volume', | ||
| 768 | 17 => 'subscriber_counter_id', | ||
| 769 | 18 => 'global_counter_id', | ||
| 770 | 19 => 'package_counter_id', | ||
| 771 | 20 => 'ip_protocol', | ||
| 772 | 21 => 'protocol_signature', | ||
| 773 | 22 => 'zone_id', | ||
| 774 | 23 => 'flavor_id', | ||
| 775 | 24 => 'flow_close_mode', | ||
| 776 | 25 => 'user_agent', | ||
| 777 | 26 => 'http_url' | ||
| 778 | }, | ||
| 779 | 'RTSPTransaction' => | ||
| 780 | { | ||
| 781 | 0 => 'subscriber_id', | ||
| 782 | 1 => 'package_id', | ||
| 783 | 2 => 'service_id', | ||
| 784 | 3 => 'protocol_id', | ||
| 785 | 4 => 'skipped_sessions', | ||
| 786 | 5 => 'server_ip', | ||
| 787 | 6 => 'server_port', | ||
| 788 | 7 => 'access_string', | ||
| 789 | 8 => 'info_string', | ||
| 790 | 9 => 'client_ip', | ||
| 791 | 10 => 'client_port', | ||
| 792 | 11 => 'initiating_side', | ||
| 793 | 12 => 'report_time', | ||
| 794 | 13 => 'millisec_duration', | ||
| 795 | 14 => 'time_frame', | ||
| 796 | 15 => 'session_upstream_volume', | ||
| 797 | 16 => 'session_downstream_volume', | ||
| 798 | 17 => 'subscriber_counter_id', | ||
| 799 | 18 => 'global_counter_id', | ||
| 800 | 19 => 'package_counter_id', | ||
| 801 | 20 => 'ip_protocol', | ||
| 802 | 21 => 'protocol_signature', | ||
| 803 | 22 => 'zone_id', | ||
| 804 | 23 => 'flavor_id', | ||
| 805 | 24 => 'flow_close_mode', | ||
| 806 | 25 => 'rtsp_session_id', | ||
| 807 | 26 => 'rtsp_url', | ||
| 808 | 27 => 'response_date', | ||
| 809 | 28 => 'total_encoding_rate', | ||
| 810 | 29 => 'number_of_video_streams', | ||
| 811 | 30 => 'number_of_audio_streams', | ||
| 812 | 31 => 'session_title', | ||
| 813 | 32 => 'server_name' | ||
| 814 | }, | ||
| 815 | 'VoIPTransaction' => | ||
| 816 | { | ||
| 817 | 0 => 'subscriber_id', | ||
| 818 | 1 => 'package_id', | ||
| 819 | 2 => 'service_id', | ||
| 820 | 3 => 'protocol_id', | ||
| 821 | 4 => 'skipped_sessions', | ||
| 822 | 5 => 'server_ip', | ||
| 823 | 6 => 'server_port', | ||
| 824 | 7 => 'access_string', | ||
| 825 | 8 => 'info_string', | ||
| 826 | 9 => 'client_ip', | ||
| 827 | 10 => 'client_port', | ||
| 828 | 11 => 'initiating_side', | ||
| 829 | 12 => 'report_time', | ||
| 830 | 13 => 'millisec_duration', | ||
| 831 | 14 => 'time_frame', | ||
| 832 | 15 => 'session_upstream_volume', | ||
| 833 | 16 => 'session_downstream_volume', | ||
| 834 | 17 => 'subscriber_counter_id', | ||
| 835 | 18 => 'global_counter_id', | ||
| 836 | 19 => 'package_counter_id', | ||
| 837 | 20 => 'ip_protocol', | ||
| 838 | 21 => 'protocol_signature', | ||
| 839 | 22 => 'zone_id', | ||
| 840 | 23 => 'flavor_id', | ||
| 841 | 24 => 'flow_close_mode', | ||
| 842 | 25 => 'application_id', | ||
| 843 | 26 => 'upstream_packet_loss', | ||
| 844 | 27 => 'downstream_packet_loss', | ||
| 845 | 28 => 'upstream_average_jitter', | ||
| 846 | 29 => 'downstream_average_jitter', | ||
| 847 | 30 => 'call_destination', | ||
| 848 | 31 => 'call_source', | ||
| 849 | 32 => 'upstream_payload_type', | ||
| 850 | 33 => 'downstream_payload_type', | ||
| 851 | 34 => 'call-type', | ||
| 852 | 35 => 'media_channels' | ||
| 853 | }, | ||
| 854 | 'SubscriberUsage' => | ||
| 855 | { | ||
| 856 | 0 => 'subscriber_id', | ||
| 857 | 1 => 'package_id', | ||
| 858 | 2 => 'service_usage_counter_id', | ||
| 859 | 3 => 'breach_state', | ||
| 860 | 4 => 'reason', | ||
| 861 | 5 => 'configured_duration', | ||
| 862 | 6 => 'duration', | ||
| 863 | 7 => 'end_time', | ||
| 864 | 8 => 'upstream_volume', | ||
| 865 | 9 => 'downstream_volume', | ||
| 866 | 10 => 'sessions', | ||
| 867 | 11 => 'seconds' | ||
| 868 | }, | ||
| 869 | 'Transaction' => | ||
| 870 | { | ||
| 871 | 0 => 'subscriber_id', | ||
| 872 | 1 => 'package_id', | ||
| 873 | 2 => 'service_id', | ||
| 874 | 3 => 'protocol_id', | ||
| 875 | 4 => 'skipped_sessions', | ||
| 876 | 5 => 'server_ip', | ||
| 877 | 6 => 'server_port', | ||
| 878 | 7 => 'access_string', | ||
| 879 | 8 => 'info_string', | ||
| 880 | 9 => 'client_ip', | ||
| 881 | 10 => 'client_port', | ||
| 882 | 11 => 'initiating_side', | ||
| 883 | 12 => 'report_time', | ||
| 884 | 13 => 'millisec_duration', | ||
| 885 | 14 => 'time_frame', | ||
| 886 | 15 => 'session_upstream_volume', | ||
| 887 | 16 => 'session_downstream_volume', | ||
| 888 | 17 => 'subscriber_counter_id', | ||
| 889 | 18 => 'global_counter_id', | ||
| 890 | 19 => 'package_counter_id', | ||
| 891 | 20 => 'ip_protocol', | ||
| 892 | 21 => 'protocol_signature', | ||
| 893 | 22 => 'zone_id', | ||
| 894 | 23 => 'flavour_id', | ||
| 895 | 24 => 'flow_close_mode' | ||
| 896 | }, | ||
| 897 | 'TransactionUsage' => | ||
| 898 | { | ||
| 899 | 0 => 'subscriber_id', | ||
| 900 | 1 => 'package_id', | ||
| 901 | 2 => 'service_id', | ||
| 902 | 3 => 'protocol_id', | ||
| 903 | 4 => 'skipped_sessions', | ||
| 904 | 5 => 'server_ip', | ||
| 905 | 6 => 'server_port', | ||
| 906 | 7 => 'access_string', | ||
| 907 | 8 => 'info_string', | ||
| 908 | 9 => 'client_ip', | ||
| 909 | 10 => 'client_port', | ||
| 910 | 11 => 'initiating_side', | ||
| 911 | 12 => 'report_time', | ||
| 912 | 13 => 'millisec_duration', | ||
| 913 | 14 => 'time_frame', | ||
| 914 | 15 => 'session_upstream_volume', | ||
| 915 | 16 => 'session_downstream_volume', | ||
| 916 | 17 => 'subscriber_counter_id', | ||
| 917 | 18 => 'global_counter_id', | ||
| 918 | 19 => 'package_counter_id', | ||
| 919 | 20 => 'ip_protocol', | ||
| 920 | 21 => 'protocol_signature', | ||
| 921 | 22 => 'zone_id', | ||
| 922 | 23 => 'flavor_id', | ||
| 923 | 24 => 'flow_close_mode' | ||
| 924 | }, | ||
| 925 | 'RealTimeSubscriberUsage' => | ||
| 926 | { | ||
| 927 | 0 => 'subscriber_id', | ||
| 928 | 1 => 'package_id', | ||
| 929 | 2 => 'service_usage_counter_id', | ||
| 930 | 3 => 'aggregation_object_id', | ||
| 931 | 4 => 'breach_state', | ||
| 932 | 5 => 'reason', | ||
| 933 | 6 => 'configured_duration', | ||
| 934 | 7 => 'duration', | ||
| 935 | 8 => 'end_time', | ||
| 936 | 9 => 'upstream_volume', | ||
| 937 | 10 => 'downstream_volume', | ||
| 938 | 11 => 'sessions', | ||
| 939 | 12 => 'seconds' | ||
| 940 | }, | ||
| 941 | 'LinkUsage' => | ||
| 942 | { | ||
| 943 | 0 => 'link_id', | ||
| 944 | 1 => 'generator_id', | ||
| 945 | 2 => 'service_usage_counter_id', | ||
| 946 | 3 => 'configured_duration', | ||
| 947 | 4 => 'duration', | ||
| 948 | 5 => 'end_time', | ||
| 949 | 6 => 'upstream_volume', | ||
| 950 | 7 => 'downstream_volume', | ||
| 951 | 8 => 'sessions', | ||
| 952 | 9 => 'seconds', | ||
| 953 | 10 => 'concurrent_sessions', | ||
| 954 | 11 => 'active_subscribers', | ||
| 955 | 12 => 'total_active_subscribers' | ||
| 956 | }, | ||
| 957 | 'PackageUsage' => | ||
| 958 | { | ||
| 959 | 0 => 'package_counter_id', | ||
| 960 | 1 => 'generator_id', | ||
| 961 | 2 => 'service_usage_counter_id', | ||
| 962 | 3 => 'configured_duration', | ||
| 963 | 4 => 'duration', | ||
| 964 | 5 => 'end_time', | ||
| 965 | 6 => 'upstream_volume', | ||
| 966 | 7 => 'downstream_volume', | ||
| 967 | 8 => 'sessions', | ||
| 968 | 9 => 'seconds', | ||
| 969 | 10 => 'concurrent_sessions', | ||
| 970 | 11 => 'active_subscribers', | ||
| 971 | 12 => 'total_active_subscribers' | ||
| 972 | }, | ||
| 973 | 'VirtualLink' => | ||
| 974 | { | ||
| 975 | 0 => 'vlink_id', | ||
| 976 | 1 => 'vlink_direction', | ||
| 977 | 2 => 'generator_id', | ||
| 978 | 3 => 'service_usage_counter_id', | ||
| 979 | 4 => 'configured_duration', | ||
| 980 | 5 => 'duration', | ||
| 981 | 6 => 'end_time', | ||
| 982 | 7 => 'upstream_volume', | ||
| 983 | 8 => 'downstream_volume', | ||
| 984 | 9 => 'sessions', | ||
| 985 | 10 => 'seconds', | ||
| 986 | 11 => 'concurrent_sessions', | ||
| 987 | 12 => 'active_subscribers', | ||
| 988 | 13 => 'total_active_subscribers' | ||
| 989 | }, | ||
| 990 | 'Blocking' => | ||
| 991 | { | ||
| 992 | 0 => 'subscriber_id', | ||
| 993 | 1 => 'package_id', | ||
| 994 | 2 => 'service_id', | ||
| 995 | 3 => 'protocol_id', | ||
| 996 | 4 => 'client_ip', | ||
| 997 | 5 => 'client_port', | ||
| 998 | 6 => 'server_ip', | ||
| 999 | 7 => 'server_port', | ||
| 1000 | 8 => 'initiating_side', | ||
| 1001 | 9 => 'access_string', | ||
| 1002 | 10 => 'info_string', | ||
| 1003 | 11 => 'block_reason', | ||
| 1004 | 12 => 'block_rdr_count', | ||
| 1005 | 13 => 'redirected', | ||
| 1006 | 14 => 'report_time' | ||
| 1007 | }, | ||
| 1008 | 'QuotaBreach' => | ||
| 1009 | { | ||
| 1010 | 0 => 'subscriber_id', | ||
| 1011 | 1 => 'package_id', | ||
| 1012 | 2 => 'bucket_id', | ||
| 1013 | 3 => 'end_time', | ||
| 1014 | 4 => 'bucket_quota', | ||
| 1015 | 5 => 'aggregaton_period_type' | ||
| 1016 | }, | ||
| 1017 | 'RemainingQuota' => | ||
| 1018 | { | ||
| 1019 | 0 => 'subscriber_id', | ||
| 1020 | 1 => 'package_id', | ||
| 1021 | 2 => 'rdr_reason', | ||
| 1022 | 3 => 'end_time', | ||
| 1023 | 4 => 'remaining_quota_1', | ||
| 1024 | 5 => 'remaining_quota_2', | ||
| 1025 | 6 => 'remaining_quota_3', | ||
| 1026 | 7 => 'remaining_quota_4', | ||
| 1027 | 8 => 'remaining_quota_5', | ||
| 1028 | 9 => 'remaining_quota_6', | ||
| 1029 | 10 => 'remaining_quota_7', | ||
| 1030 | 11 => 'remaining_quota_8', | ||
| 1031 | 12 => 'remaining_quota_9', | ||
| 1032 | 13 => 'remaining_quota_10', | ||
| 1033 | 14 => 'remaining_quota_11', | ||
| 1034 | 15 => 'remaining_quota_12', | ||
| 1035 | 16 => 'remaining_quota_13', | ||
| 1036 | 17 => 'remaining_quota_14', | ||
| 1037 | 18 => 'remaining_quota_15', | ||
| 1038 | 19 => 'remaining_quota_16' | ||
| 1039 | }, | ||
| 1040 | 'QuotaThreshold' => | ||
| 1041 | { | ||
| 1042 | 0 => 'subscriber_id', | ||
| 1043 | 1 => 'package_id', | ||
| 1044 | 2 => 'bucket_id', | ||
| 1045 | 3 => 'global_threshold', | ||
| 1046 | 4 => 'end_time', | ||
| 1047 | 5 => 'bucket_quota' | ||
| 1048 | }, | ||
| 1049 | 'QuotaStateRestore' => | ||
| 1050 | { | ||
| 1051 | 0 => 'subscriber_id', | ||
| 1052 | 1 => 'package_id', | ||
| 1053 | 2 => 'rdr_reason', | ||
| 1054 | 3 => 'end_time' | ||
| 1055 | }, | ||
| 1056 | 'DHCP' => | ||
| 1057 | { | ||
| 1058 | 0 => 'cpe_mac', | ||
| 1059 | 1 => 'cmts_ip', | ||
| 1060 | 2 => 'assigned_ip', | ||
| 1061 | 3 => 'released_ip', | ||
| 1062 | 4 => 'transaction_id', | ||
| 1063 | 5 => 'message_type', | ||
| 1064 | 6 => 'option_type_0', | ||
| 1065 | 7 => 'option_type_1', | ||
| 1066 | 8 => 'option_type_2', | ||
| 1067 | 9 => 'option_type_3', | ||
| 1068 | 10 => 'option_type_4', | ||
| 1069 | 11 => 'option_type_5', | ||
| 1070 | 12 => 'option_type_6', | ||
| 1071 | 13 => 'option_type_7', | ||
| 1072 | 14 => 'option_type_0', | ||
| 1073 | 15 => 'option_type_1', | ||
| 1074 | 16 => 'option_type_2', | ||
| 1075 | 17 => 'option_type_3', | ||
| 1076 | 18 => 'option_type_4', | ||
| 1077 | 19 => 'option_type_5', | ||
| 1078 | 20 => 'option_type_6', | ||
| 1079 | 21 => 'option_type_7', | ||
| 1080 | 22 => 'end_time' | ||
| 1081 | }, | ||
| 1082 | 'RADIUS' => | ||
| 1083 | { | ||
| 1084 | 0 => 'server_ip', | ||
| 1085 | 1 => 'server_port', | ||
| 1086 | 2 => 'client_ip', | ||
| 1087 | 3 => 'client_port', | ||
| 1088 | 4 => 'initiating_side', | ||
| 1089 | 5 => 'radius_packet_code', | ||
| 1090 | 6 => 'radius_id', | ||
| 1091 | 7 => 'attribute_value_1', | ||
| 1092 | 8 => 'attribute_value_2', | ||
| 1093 | 9 => 'attribute_value_3', | ||
| 1094 | 10 => 'attribute_value_4', | ||
| 1095 | 11 => 'attribute_value_5', | ||
| 1096 | 12 => 'attribute_value_6', | ||
| 1097 | 13 => 'attribute_value_7', | ||
| 1098 | 14 => 'attribute_value_8', | ||
| 1099 | 15 => 'attribute_value_9', | ||
| 1100 | 16 => 'attribute_value_10', | ||
| 1101 | 17 => 'attribute_value_11', | ||
| 1102 | 18 => 'attribute_value_12', | ||
| 1103 | 19 => 'attribute_value_13', | ||
| 1104 | 20 => 'attribute_value_14', | ||
| 1105 | 21 => 'attribute_value_15', | ||
| 1106 | 22 => 'attribute_value_16', | ||
| 1107 | 23 => 'attribute_value_17', | ||
| 1108 | 24 => 'attribute_value_18', | ||
| 1109 | 25 => 'attribute_value_19', | ||
| 1110 | 26 => 'attribute_value_20', | ||
| 1111 | 27 => 'end_time' | ||
| 1112 | }, | ||
| 1113 | 'FlowStart' => | ||
| 1114 | { | ||
| 1115 | 0 => 'subscriber_id', | ||
| 1116 | 1 => 'package_id', | ||
| 1117 | 2 => 'service_id', | ||
| 1118 | 3 => 'ip_protocol', | ||
| 1119 | 4 => 'server_ip', | ||
| 1120 | 5 => 'server_port', | ||
| 1121 | 6 => 'client_ip', | ||
| 1122 | 7 => 'client_port', | ||
| 1123 | 8 => 'initiating_side', | ||
| 1124 | 9 => 'start_time', | ||
| 1125 | 10 => 'report_time', | ||
| 1126 | 11 => 'breach_state', | ||
| 1127 | 12 => 'flow_id', | ||
| 1128 | 13 => 'generator_id' | ||
| 1129 | }, | ||
| 1130 | 'FlowEnd' => | ||
| 1131 | { | ||
| 1132 | 0 => 'subscriber_id', | ||
| 1133 | 1 => 'package_id', | ||
| 1134 | 2 => 'service_id', | ||
| 1135 | 3 => 'ip_protocol', | ||
| 1136 | 4 => 'server_ip', | ||
| 1137 | 5 => 'server_port', | ||
| 1138 | 6 => 'client_ip', | ||
| 1139 | 7 => 'client_port', | ||
| 1140 | 8 => 'initiating_side', | ||
| 1141 | 9 => 'start_time', | ||
| 1142 | 10 => 'report_time', | ||
| 1143 | 11 => 'breach_state', | ||
| 1144 | 12 => 'flow_id', | ||
| 1145 | 13 => 'generator_id' | ||
| 1146 | }, | ||
| 1147 | 'FlowOnGoing' => | ||
| 1148 | { | ||
| 1149 | 0 => 'subscriber_id', | ||
| 1150 | 1 => 'package_id', | ||
| 1151 | 2 => 'service_id', | ||
| 1152 | 3 => 'ip_protocol', | ||
| 1153 | 4 => 'server_ip', | ||
| 1154 | 5 => 'server_port', | ||
| 1155 | 6 => 'client_ip', | ||
| 1156 | 7 => 'client_port', | ||
| 1157 | 8 => 'initiating_side', | ||
| 1158 | 9 => 'start_time', | ||
| 1159 | 10 => 'report_time', | ||
| 1160 | 11 => 'breach_state', | ||
| 1161 | 12 => 'flow_id', | ||
| 1162 | 13 => 'generator_id' | ||
| 1163 | }, | ||
| 1164 | 'MediaFlow' => | ||
| 1165 | { | ||
| 1166 | 0 => 'subscriber_id', | ||
| 1167 | 1 => 'package_id', | ||
| 1168 | 2 => 'service_id', | ||
| 1169 | 3 => 'protocol_id', | ||
| 1170 | 4 => 'destination_ip', | ||
| 1171 | 5 => 'destination_port', | ||
| 1172 | 6 => 'source_ip', | ||
| 1173 | 7 => 'source_port', | ||
| 1174 | 8 => 'initiating_side', | ||
| 1175 | 9 => 'zone_id', | ||
| 1176 | 10 => 'flavor_id', | ||
| 1177 | 11 => 'sip_domain', | ||
| 1178 | 12 => 'sip_user_agent', | ||
| 1179 | 13 => 'start_time', | ||
| 1180 | 14 => 'report_time', | ||
| 1181 | 15 => 'duration_seconds', | ||
| 1182 | 16 => 'upstream_volume', | ||
| 1183 | 17 => 'downstream_volume', | ||
| 1184 | 18 => 'ip_protocol', | ||
| 1185 | 19 => 'flow_type', | ||
| 1186 | 20 => 'session_id', | ||
| 1187 | 21 => 'upstream_jitter', | ||
| 1188 | 22 => 'downstream_jitter', | ||
| 1189 | 23 => 'upstream_packet_loss', | ||
| 1190 | 24 => 'downstream_packet_loss', | ||
| 1191 | 25 => 'upstream_payload_type', | ||
| 1192 | 26 => 'downstream_payload_type' | ||
| 1193 | }, | ||
| 1194 | 'AttackStart' => | ||
| 1195 | { | ||
| 1196 | 0 => 'attack_id', | ||
| 1197 | 1 => 'subscriber_id', | ||
| 1198 | 2 => 'attacking_ip', | ||
| 1199 | 3 => 'attacked_ip', | ||
| 1200 | 4 => 'attacked_port', | ||
| 1201 | 5 => 'attacking_side', | ||
| 1202 | 6 => 'ip_protocol', | ||
| 1203 | 7 => 'attack_type', | ||
| 1204 | 8 => 'generator_id', | ||
| 1205 | 9 => 'attack_time', | ||
| 1206 | 10 => 'report_time' | ||
| 1207 | }, | ||
| 1208 | 'AttackEnd' => | ||
| 1209 | { | ||
| 1210 | 0 => 'attack_id', | ||
| 1211 | 1 => 'subscriber_id', | ||
| 1212 | 2 => 'attacking_ip', | ||
| 1213 | 3 => 'attacked_ip', | ||
| 1214 | 4 => 'attacked_port', | ||
| 1215 | 5 => 'attacking_side', | ||
| 1216 | 6 => 'ip_protocol', | ||
| 1217 | 7 => 'attack_type', | ||
| 1218 | 8 => 'generator_id', | ||
| 1219 | 9 => 'attack_time', | ||
| 1220 | 10 => 'report_time' | ||
| 1221 | }, | ||
| 1222 | 'MaliciousTraffic' => | ||
| 1223 | { | ||
| 1224 | 0 => 'attack_id', | ||
| 1225 | 1 => 'subscriber_id', | ||
| 1226 | 2 => 'attack_ip', | ||
| 1227 | 3 => 'other_ip', | ||
| 1228 | 4 => 'port_number', | ||
| 1229 | 5 => 'attack_type', | ||
| 1230 | 6 => 'side', | ||
| 1231 | 7 => 'ip_protocol', | ||
| 1232 | 8 => 'configured_duration', | ||
| 1233 | 9 => 'duration', | ||
| 1234 | 10 => 'end_time', | ||
| 1235 | 11 => 'attack', | ||
| 1236 | 12 => 'malicious_sessions' | ||
| 1237 | } | ||
| 1238 | ); | ||
| 1239 | return \%rdr_fields; | ||
| 1240 | } | ||
| 1241 | |||
| 1242 | sub field_types_rdr | ||
| 1243 | { | ||
| 1244 | my ( %rdr_types ) | ||
| 1245 | = | ||
| 1246 | ( | ||
| 1247 | 11 => 'INT8', | ||
| 1248 | 12 => 'INT16', | ||
| 1249 | 13 => 'INT32', | ||
| 1250 | 14 => 'UINT8', | ||
| 1251 | 15 => 'UINT16', | ||
| 1252 | 16 => 'UINT32', | ||
| 1253 | 21 => 'FLOAT', | ||
| 1254 | 31 => 'BOOLEAM', | ||
| 1255 | 41 => 'STRING' | ||
| 1256 | ); | ||
| 1257 | |||
| 1258 | return \%rdr_types; | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | sub transpose_rdr_types | ||
| 1262 | { | ||
| 1263 | my ( %rdr_values ) = ( | ||
| 1264 | '4042321920' => 'SubscriberUsage', | ||
| 1265 | '4042321922' => 'RealTimeSubscriberUsage', | ||
| 1266 | '4042321924' => 'PackageUsage', | ||
| 1267 | '4042321925' => 'LinkUsage', | ||
| 1268 | '4042321926' => 'VirtualLink', | ||
| 1269 | '4042321936' => 'Transaction', | ||
| 1270 | '4042323000' => 'TransactionUsage', | ||
| 1271 | '4042323004' => 'HTTPTransaction', | ||
| 1272 | '4042323008' => 'RTSPTransaction', | ||
| 1273 | '4042323050' => 'VoIPTransaction', | ||
| 1274 | '4042321984' => 'Blocking', | ||
| 1275 | '4042321954' => 'QuotaBreach', | ||
| 1276 | '4042321968' => 'RemainingQuota', | ||
| 1277 | '4042321969' => 'QuotaThreshold', | ||
| 1278 | '4042321970' => 'QuotaStateRestore', | ||
| 1279 | '4042321987' => 'Radius', | ||
| 1280 | '4042321986' => 'DHCP', | ||
| 1281 | '4042321942' => 'FlowStart', | ||
| 1282 | '4042321944' => 'FlowEnd', | ||
| 1283 | '4042323052' => 'MediaFlow', | ||
| 1284 | '4042321943' => 'FlowOnGoing', | ||
| 1285 | '4042321945' => 'AttackStart', | ||
| 1286 | '4042321946' => 'AttackEnd', | ||
| 1287 | '4042322000' => 'MaliciousTraffic', | ||
| 1288 | '8456' => 'PrivateOne', | ||
| 1289 | '77771' => 'PrivateTwo', | ||
| 1290 | '77775' => 'PrivateThree', | ||
| 1291 | '77776' => 'PrivateFour', | ||
| 1292 | '1000000' => 'PrivateFive', | ||
| 1293 | '11110001' => 'PrivateSix', | ||
| 1294 | '11110002' => 'PrivateSeven', | ||
| 1295 | '11110003' => 'PrivateEight', | ||
| 1296 | '11110004' => 'PrivateNine', | ||
| 1297 | '11111001' => 'PrivateTen', | ||
| 1298 | '11120001' => 'PrivateEleven', | ||
| 1299 | '11140001' => 'PrivateTwelve', | ||
| 1300 | '11150001' => 'PrivateThirteen', | ||
| 1301 | '11160001' => 'PrivateFourteen', | ||
| 1302 | '11170001' => 'PrivateFifteen', | ||
| 1303 | '4294967295' => 'TestRDR' | ||
| 1304 | |||
| 1305 | ); | ||
| 1306 | return \%rdr_values; | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | sub convert_mac_address | ||
| 1310 | { | ||
| 1311 | my ( $self ) = shift; | ||
| 1312 | my ( $raw_input) = shift; | ||
| 1313 | return "" if !$raw_input; | ||
| 1314 | my ( $char1, $char2, $char3, $char4, $char5, $char6) = unpack ('CCCCCC', $raw_input); | ||
| 1315 | $char1=sprintf ("%#.2x",$char1); $char1=(split(/0x/,$char1))[1] if $char1=~/x/g; | ||
| 1316 | $char2=sprintf ("%#.2x",$char2); $char2=(split(/0x/,$char2))[1] if $char2=~/x/g; | ||
| 1317 | $char3=sprintf ("%#.2x",$char3); $char3=(split(/0x/,$char3))[1] if $char3=~/x/g; | ||
| 1318 | $char4=sprintf ("%#.2x",$char4); $char4=(split(/0x/,$char4))[1] if $char4=~/x/g; | ||
| 1319 | $char5=sprintf ("%#.2x",$char5); $char5=(split(/0x/,$char5))[1] if $char5=~/x/g; | ||
| 1320 | $char6=sprintf ("%#.2x",$char6); $char6=(split(/0x/,$char6))[1] if $char6=~/x/g; | ||
| 1321 | return ("$char1$char2.$char3$char4.$char5$char6"); | ||
| 1322 | } | ||
| 1323 | |||
| 1324 | sub convert_chars_value | ||
| 1325 | { | ||
| 1326 | # this is just crazy stuff. Is PERL suited to this stuff, not really. | ||
| 1327 | # This is a safety handler for the RDR Packets as *sometimes* they are | ||
| 1328 | # full of crap. | ||
| 1329 | my ($length) = @_; | ||
| 1330 | my $char1; | ||
| 1331 | my $char2; | ||
| 1332 | my $char3; | ||
| 1333 | my $char4; | ||
| 1334 | my $failed=0; | ||
| 1335 | |||
| 1336 | #print "Conversion is '".ord(substr($length,0,1))."' '".ord(substr($length,1,1))."' '".ord(substr($length,2,1))."' '".ord(substr($length,3,1))."'\n"; | ||
| 1337 | |||
| 1338 | if ( (ord(substr($length,1,1))>=48 && ord(substr($length,1,1))<=57) || | ||
| 1339 | (ord(substr($length,1,1))>=65 && ord(substr($length,1,1))<=70) ) | ||
| 1340 | { | ||
| 1341 | $char2 = hex(substr($length,1,1)); | ||
| 1342 | } | ||
| 1343 | else | ||
| 1344 | { | ||
| 1345 | $failed=1; | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | if ( (ord(substr($length,0,1))>=48 && ord(substr($length,0,1))<=57) || | ||
| 1349 | (ord(substr($length,0,1))>=65 && ord(substr($length,0,1))<=70) ) | ||
| 1350 | { | ||
| 1351 | $char1 = hex(substr($length,0,1)); | ||
| 1352 | } | ||
| 1353 | else | ||
| 1354 | { | ||
| 1355 | $failed=1; | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | if ( (ord(substr($length,2,1))>=48 && ord(substr($length,2,1))<=57) || | ||
| 1359 | (ord(substr($length,2,1))>=65 && ord(substr($length,2,1))<=70) ) | ||
| 1360 | { | ||
| 1361 | $char3 = hex(substr($length,2,1)); | ||
| 1362 | } | ||
| 1363 | else | ||
| 1364 | { | ||
| 1365 | $failed=1; | ||
| 1366 | } | ||
| 1367 | |||
| 1368 | |||
| 1369 | if ( (ord(substr($length,3,1))>=48 && ord(substr($length,3,1))<=57) || | ||
| 1370 | (ord(substr($length,3,1))>=65 && ord(substr($length,3,1))<=70) ) | ||
| 1371 | { | ||
| 1372 | $char4 = hex(substr($length,3,1)); | ||
| 1373 | } | ||
| 1374 | else | ||
| 1375 | { | ||
| 1376 | $failed=1; | ||
| 1377 | } | ||
| 1378 | |||
| 1379 | if ( $failed==1 ) | ||
| 1380 | { | ||
| 1381 | print "Failed to decode packet length here.\n"; | ||
| 1382 | return "DEAD"; | ||
| 1383 | } | ||
| 1384 | else | ||
| 1385 | { | ||
| 1386 | my $data_length= $char1.$char2.$char3.$char4; | ||
| 1387 | $data_length+=0; | ||
| 1388 | return $data_length; | ||
| 1389 | } | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | =head1 AUTHOR | ||
| 1393 | |||
| 1394 | Andrew S. Kennedy, C<< <shamrock at cpan.org> >> | ||
| 1395 | |||
| 1396 | =head1 BUGS | ||
| 1397 | |||
| 1398 | Please report any bugs or feature requests to C<bug-rdr-collector at rt.cpan.org>, or through | ||
| 1399 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RDR-Collector>. I will be notified, and then you'll | ||
| 1400 | automatically be notified of progress on your bug as I make changes. | ||
| 1401 | |||
| 1402 | |||
| 1403 | |||
| 1404 | |||
| 1405 | =head1 SUPPORT | ||
| 1406 | |||
| 1407 | You can find documentation for this module with the perldoc command. | ||
| 1408 | |||
| 1409 | perldoc RDR::Collector | ||
| 1410 | |||
| 1411 | |||
| 1412 | You can also look for information at: | ||
| 1413 | |||
| 1414 | =over 4 | ||
| 1415 | |||
| 1416 | =item * RT: CPAN's request tracker | ||
| 1417 | |||
| 1418 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RDR-Collector> | ||
| 1419 | |||
| 1420 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 1421 | |||
| 1422 | L<http://annocpan.org/dist/RDR-Collector> | ||
| 1423 | |||
| 1424 | =item * CPAN Ratings | ||
| 1425 | |||
| 1426 | L<http://cpanratings.perl.org/d/RDR-Collector> | ||
| 1427 | |||
| 1428 | =item * Search CPAN | ||
| 1429 | |||
| 1430 | L<http://search.cpan.org/dist/RDR-Collector> | ||
| 1431 | |||
| 1432 | =back | ||
| 1433 | |||
| 1434 | |||
| 1435 | =head1 ACKNOWLEDGEMENTS | ||
| 1436 | |||
| 1437 | |||
| 1438 | =head1 COPYRIGHT & LICENSE | ||
| 1439 | |||
| 1440 | Copyright 2008 Andrew S. Kennedy, all rights reserved. | ||
| 1441 | |||
| 1442 | This program is free software; you can redistribute it and/or modify it | ||
| 1443 | under the same terms as Perl itself. | ||
| 1444 | |||
| 1445 | |||
| 1446 | =cut | ||
| 1447 | |||
| 1448 | 1; # End of RDR::Collector |