blib/lib/CDR/Parser/SI3000.pm

filter: Statementstmt 73.1% 273 / 373 Branchbran 45.0% 27 / 60 Conditioncond 50.0% 21 / 42 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 75.0% 24 / 32 Podpod 3.8% 1 / 26 totaltotal 62.4% 346 / 554 CC 52 SCAR 19.9
CC
52
Cov
68%
block_127
16.3
block_119
12.0
parse_reboot_record
12.0
CRAP 7.3
↑ Summary
1 package CDR::Parser::SI3000;
2  
3 3 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 CDR::Parser::SI3000 - parser for binary CDR files (*.ama) produced by Iskratel SI3000 MSCN telephony product
11  
12 CDR = Call Detail Records
13  
14 =head1 VERSION
15  
16 Version 0.01
17  
18 =cut
19  
20 3 our $VERSION = '0.03';
21  
22 3 our $VERBOSE = 0;
23  
24 =head1 SYNOPSIS
25  
26 Whis module parses the binary file format and returns it as Perl data.
27  
28 Usage example
29  
30 use CDR::Parser::SI3000;
31  
32 my ($cdr_list, $num_failed) = CDR::Parser::SI3000->parse_file('somefile.ama');
33  
34 There
35 $cdr_list is a array-reference containing individual records as hash-ref.
36 $num_failed is a number of unparseable records
37  
38  
39 =head1 SUBROUTINES/METHODS
40  
41 =head2 parse_file
42  
43 Get filename as input, open it, read it, returns the parsed result
44  
45 =cut
46  
47  
48 #--
49  
50 # $| = 1;
51  
52 931 ▶sub _log {
Subroutine _log: called CC=2 SCAR=8.1
53 931 my($format, @args) = @_;
54 931 ▶ return if(! $VERBOSE);
Branch: 1 branch
BranchTrueFalseTotal
unless $CDR::Parser::SI3000::VERBOSE 931 0 931
55 0 printf $format."\n", @args;
56 }
57  
58 # public
59 1 ▶sub parse_file {
Subroutine parse_file: called CC=5 SCAR=16.3
Pod documented
60 1 my($class, $filename) = @_;
61 1 ▶ die "No filename argument" if(! $filename);
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 1 1
62 1 _log('Parsing file %s', $filename);
63  
64 1 ▶ my $fh = IO::File->new($filename) || die "Failed to open $filename - $!";
Condition50%1/2
'IO::File'->new($filename) || die("Failed to open $filename - $!")
l!l
10
MC/DC0%0/1
'IO::File'->new($filename) || die("Failed to open $filename - $!")
'IO::File'->new($filename)
Truth table50%1/2
A
A= 'IO::File'->new($filename)
Aresult
11
00
65 1 binmode($fh, ':bytes');
66  
67 1 my @records = ();
68  
69 1 my $rows = 0;
70 1 my $failed = 0;
71  
72 1 while(1) {
73 16 my $call = parse_record($fh);
74 16 ▶ if($call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call) { } 15 1 16
75 15 push @records, $call;
76 }
77 else {
78 1 ▶ last if($call == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $call == 0 1 0 1
79 0 $failed++;
80 }
81 }
82  
83 1 $fh->close;
84  
85 1 return (\@records, $failed);
86 }
87  
88 #------ private implementation ------
89  
90 # 100. Called number
91 15 ▶sub block_100 {
Subroutine block_100: called CC=3 SCAR=11.0
Pod undocumented
92 15 my($call,$variable) = @_;
93  
94 15 _log('100. Called number');
95 15 my $cld_len;
96 15 ($cld_len, $$variable) = unpack('C a*', $$variable);
97 15 my $cut = $cld_len;
98 15 ▶ $cut++ if($cld_len % 2 == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $cld_len % 2 == 1 15 0 15
99 15 my $cld;
100 15 ($cld, $$variable) = unpack("H$cut a*", $$variable);
101 15 ▶ if($cut > $cld_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cut > $cld_len) 15 0 15
102 15 $cld = substr($cld, 0, -1);
103 }
104 15 _log(' CLD: %s', $cld);
105 15 $call->{cld} = $cld;
106 }
107  
108 # 101. Call accepting party number
109 # 102. Start Date and Time
110 15 ▶sub block_102 {
Subroutine block_102: called CC=1 SCAR=0.0
Pod undocumented
111 15 my($call, $var) = @_;
112 15 _log("102. Start Date and Time");
113 15 my($year,$month,$day,$hour,$min,$sec,$msec,$reserved);
114 15 ($year,$month,$day,$hour,$min,$sec,$msec,$reserved,$$var) = unpack('CCCCCCC H2 a*', $$var);
115 15 $year += 2000;
116 15 my $start_time = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
117 15 _log(' Start Time: %s', $start_time);
118 15 $call->{start_time} = $start_time;
119 }
120 # 103. End Date and Time
121 15 ▶sub block_103 {
Subroutine block_103: called CC=1 SCAR=0.0
Pod undocumented
122 15 my($call, $var) = @_;
123 15 _log("103. End Date and Time");
124 15 my($year,$month,$day,$hour,$min,$sec,$msec,$reliable);
125 15 ($year,$month,$day,$hour,$min,$sec,$msec,$reliable,$$var) = unpack('CCCCCCC H2 a*', $$var);
126 15 $year += 2000;
127 15 my $end_time = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
128 15 _log(' End Time: %s', $end_time);
129 15 $call->{end_time} = $end_time;
130 }
131 # 104. Number of charging units
132 15 ▶sub block_104 {
Subroutine block_104: called CC=1 SCAR=0.0
Pod undocumented
133 15 my($call, $var) = @_;
134 15 _log("104. Number of charging units");
135 15 my($unit1,$unit2,$unit3);
136 15 ($unit1,$unit2,$unit3,$$var) = unpack('CCC a*', $$var);
137 15 my $units = ($unit1 << 16) + ($unit2 << 8) + $unit3;
138 15 _log(' Units: %d', $units);
139 15 $call->{charging_units} = $units;
140 }
141 # 105. Basic service
142 15 ▶sub block_105 {
Subroutine block_105: called CC=5 SCAR=16.5
Pod undocumented
143 15 my($call, $var) = @_;
144 15 _log("105. Basic service");
145 15 my %bearer_label = (
146 0 => '64 kbit/s for speech information transfer',
147 8 => '64 kbit/s unrestricted',
148 16 => '64 kbit/s for 3.1kHz audio information transfer',
149 );
150 15 my %service_label = (
151 1 => 'Telephony',
152 # .... TODO
153 );
154 15 my($bearer,$service);
155 15 ($bearer,$service,$$var) = unpack('C C a*', $$var);
156 15 ▶ _log(" Bearer: %d / %s", $bearer, $bearer_label{ $bearer } // 'UNKNOWN');
Condition50%1/2
$bearer_label{$bearer} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$bearer_label{$bearer} // "UNKNOWN"
$bearer_label{$bearer}
Truth table50%1/2
A
A= $bearer_label{$bearer}
Aresult
11
00
157 15 ▶ _log(" Service: %d / %s", $service, $service_label{ $service } // 'UNKNOWN');
Condition50%1/2
$service_label{$service} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$service_label{$service} // "UNKNOWN"
$service_label{$service}
Truth table50%1/2
A
A= $service_label{$service}
Aresult
11
00
158 15 ▶ $call->{bearer} = $bearer_label{ $bearer } // 'UNKNOWN';
Condition50%1/2
$bearer_label{$bearer} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$bearer_label{$bearer} // "UNKNOWN"
$bearer_label{$bearer}
Truth table50%1/2
A
A= $bearer_label{$bearer}
Aresult
11
00
159 15 $call->{bearer_code} = $bearer;
160 15 ▶ $call->{service} = $service_label{ $service } // 'UNKNOWN';
Condition50%1/2
$service_label{$service} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$service_label{$service} // "UNKNOWN"
$service_label{$service}
Truth table50%1/2
A
A= $service_label{$service}
Aresult
11
00
161 15 $call->{service_code} = $service;
162 }
163 # 106. Supplementary service used by calling subscriber
164 0 ▶sub block_106 {
Subroutine block_106: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my($call, $var) = @_;
166 0 _log('106. Supplementary service used by calling subscriber');
167 0 my($sup_service);
168 0 ($sup_service, $$var) = unpack('C a*', $$var);
169 0 _log(' Supplementary calling service: %d', $sup_service);
170 0 $call->{supplementary_calling_service} = $sup_service;
171 }
172 # 107. Supplementary service used by called subscriber
173 0 ▶sub block_107 {
Subroutine block_107: not called CC=1 SCAR=6.9
Pod undocumented
174 0 my($call, $var) = @_;
175 0 _log('106. Supplementary service used by called subscriber');
176 0 my($sup_service);
177 0 ($sup_service, $$var) = unpack('C a*', $$var);
178 0 _log(' Supplementary called service: %d', $sup_service);
179 0 $call->{supplementary_called_service} = $sup_service;
180 }
181 # 108. Subscriber controlled input
182 # 109. Dialed digits
183 # 110. Origin category
184 15 ▶sub block_110 {
Subroutine block_110: called CC=1 SCAR=0.0
Pod undocumented
185 15 my($call, $var) = @_;
186 15 _log("110. Origin category");
187 15 my($origin);
188 15 ($origin,$$var) = unpack('C a*', $$var);
189 15 _log(" Origin category: %d", $origin);
190 15 $call->{origin_category} = $origin;
191 }
192 # 111. Tariff direction
193 15 ▶sub block_111 {
Subroutine block_111: called CC=1 SCAR=0.0
Pod undocumented
194 15 my($call, $var) = @_;
195 15 _log("111. Tariff direction");
196 15 my($tariff);
197 15 ($tariff,$$var) = unpack('C a*', $$var);
198 15 _log(" Tariff direction: %d", $tariff);
199 15 $call->{tariff_direction} = $tariff;
200 }
201 # 112. Call failure cause
202 # 113. Incoming trunk data
203 15 ▶sub block_113 {
Subroutine block_113: called CC=1 SCAR=0.0
Pod undocumented
204 15 my($call, $var) = @_;
205 15 _log("113. Incoming trunk data");
206 15 my($group,$id,$shelf,$port,$channel);
207 15 ($group,$id,$shelf,$port,$channel,$$var) = unpack('n n C n C a*', $$var);
208 15 _log(" Trunk group: %d\n Trunk identification: %d\n Shelf identification: %d\n Port identification: %d\n Channel identification: %d",
209 $group,$id,$shelf,$port,$channel);
210 15 $call->{incoming_trunk_group} = $group;
211 15 $call->{incoming_trunk} = $id;
212 15 $call->{incoming_shelf} = $shelf;
213 15 $call->{incoming_port} = $port;
214 15 $call->{incoming_channel} = $channel;
215 }
216 # 114. Outgoing trunk data
217 15 ▶sub block_114 {
Subroutine block_114: called CC=1 SCAR=0.0
Pod undocumented
218 15 my($call, $var) = @_;
219 15 _log("114. Outgoing trunk data");
220 15 my($group,$id,$shelf,$port,$channel);
221 15 ($group,$id,$shelf,$port,$channel,$$var) = unpack('n n C n C a*', $$var);
222 15 _log(" Trunk group: %d\n Trunk identification: %d\n Shelf identification: %d\n Port identification: %d\n Channel identification: %d",
223 $group,$id,$shelf,$port,$channel);
224 15 $call->{outgoing_trunk_group} = $group;
225 15 $call->{outgoing_trunk} = $id;
226 15 $call->{outgoing_shelf} = $shelf;
227 15 $call->{outgoing_port} = $port;
228 15 $call->{outgoing_channel} = $channel;
229 }
230 # 115. Call duration
231 15 ▶sub block_115 {
Subroutine block_115: called CC=1 SCAR=0.0
Pod undocumented
232 15 my($call, $var) = @_;
233 15 _log("115. Call duration");
234 15 my($duration);
235 15 ($duration,$$var) = unpack('N a*', $$var);
236 15 _log(" Call duration: %d msec / %.5f sec", $duration, $duration / 1000.0);
237 15 $call->{call_duration} = sprintf '%.5f', $duration / 1000.0;
238 15 $call->{call_duration_ms} = $duration;
239 }
240 # 116. Checksum
241 15 ▶sub block_116 {
Subroutine block_116: called CC=1 SCAR=0.0
Pod undocumented
242 15 my($call, $var) = @_;
243 15 _log("116. Checksum");
244 15 my($len,$checksum);
245 15 ($len,$checksum,$$var) = unpack('C a2 a*', $$var);
246 15 _log(" Checksum: 0x%s", unpack('H*', $checksum));;
247 15 $call->{checksum} = unpack('H*', $checksum);
248 }
249 # 117. Business and Centrex group ID
250 0 ▶sub block_117 {
Subroutine block_117: not called CC=1 SCAR=6.9
Pod undocumented
251 0 my($call, $var) = @_;
252 0 _log("117. Business and Centrex group ID");
253 0 my($len,$business,$centrex);
254 0 ($len,$business,$centrex,$$var) = unpack('C N N a*', $$var);
255 0 _log(" Business group ID: %d", $business);
256 0 _log(" Centrex group ID: %d", $centrex);
257 0 $call->{business_group} = $business;
258 0 $call->{centrex_group} = $centrex;
259 }
260 # 118. Carrier access code
261 # 119. Original calling party number
262 0 ▶sub block_119 {
Subroutine block_119: not called CC=3 SCAR=24.8
Pod undocumented
263 0 my($call, $var) = @_;
264 0 _log("119. Original calling party number");
265 0 my($len,$num_len);
266 0 ($len,$num_len,$$var) = unpack('C C a*', $$var);
267 0 my $cut = $num_len;
268 0 ▶ $cut++ if($num_len %2 == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $num_len % 2 == 1 0 0 0
269 0 my $num;
270 0 ($num,$$var) = unpack("H$cut a*", $$var);
271 0 ▶ if($cut > $num_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cut > $num_len) 0 0 0
272 0 $num = substr($num, 0, -1);
273 }
274 0 _log(" Original CLI: %s", $num);
275 0 $call->{original_cli} = $num;
276 }
277 # 120. Prepaid account recharge data
278 # 121. Call release cause
279 15 ▶sub block_121 {
Subroutine block_121: called CC=7 SCAR=20.0
Pod undocumented
280 15 my($call, $var) = @_;
281 15 _log("121. Call release cause");
282 15 my %cause_label = (
283 16 => 'normal call clearing',
284 41 => 'temporary failure',
285 );
286 15 my %coding_label = (
287 0 => 'ITU-T standard',
288 );
289 15 my %location_label = (
290 0 => 'user',
291 1 => 'private network serving the local user',
292 2 => 'public network serving the local user',
293 3 => 'transit network',
294 4 => 'public network serving the remote user',
295 5 => 'private network serving the remote user',
296 7 => 'international network',
297 10 => 'network beyond interworking point',
298 );
299 15 my($len,$cause,$flag);
300 15 ($len,$cause,$flag,$$var) = unpack('C n C a*', $$var);
301 15 my $coding = (($flag & 0xF0) >> 4);
302 15 my $location = ($flag & 0x0F);
303 15 ▶ _log(" Cause: %d / %s", $cause, $cause_label{ $cause } // 'UNKNOWN');;
Condition50%1/2
$cause_label{$cause} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$cause_label{$cause} // "UNKNOWN"
$cause_label{$cause}
Truth table50%1/2
A
A= $cause_label{$cause}
Aresult
11
00
304 15 ▶ _log(" Coding standard: %d / %s", $coding, $coding_label{ $coding } // 'UNKNOWN');
Condition50%1/2
$coding_label{$coding} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$coding_label{$coding} // "UNKNOWN"
$coding_label{$coding}
Truth table50%1/2
A
A= $coding_label{$coding}
Aresult
11
00
305 15 ▶ _log(" Location: %d / %s", $location, $location_label{ $location } // 'UNKNOWN');
Condition50%1/2
$location_label{$location} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$location_label{$location} // "UNKNOWN"
$location_label{$location}
Truth table50%1/2
A
A= $location_label{$location}
Aresult
11
00
306 15 ▶ $call->{call_release_cause} = $cause_label{ $cause } // 'UNKNOWN';
Condition50%1/2
$cause_label{$cause} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$cause_label{$cause} // "UNKNOWN"
$cause_label{$cause}
Truth table50%1/2
A
A= $cause_label{$cause}
Aresult
11
00
307 15 $call->{call_release_cause_code} = $cause;
308 15 ▶ $call->{call_coding_standard} = $coding_label{ $coding } // 'UNKNOWN';
Condition50%1/2
$coding_label{$coding} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$coding_label{$coding} // "UNKNOWN"
$coding_label{$coding}
Truth table50%1/2
A
A= $coding_label{$coding}
Aresult
11
00
309 15 $call->{call_coding_standard_code} = $coding;
310 15 ▶ $call->{call_location} = $location_label{ $location } // 'UNKNOWN';
Condition50%1/2
$location_label{$location} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$location_label{$location} // "UNKNOWN"
$location_label{$location}
Truth table50%1/2
A
A= $location_label{$location}
Aresult
11
00
311 15 $call->{call_location_code} = $location;
312 }
313 # 122. CBNO (Charge Band Number)
314 # 123. Common call ID
315 # 124. Durations before answer
316 # 125. VoIP Info (old)
317 # 126. Amount of Transferred Data (old)
318 # 127. IP Address
319 15 ▶sub block_127 {
Subroutine block_127: called CC=9 SCAR=27.9
Pod undocumented
320 15 my($call, $var) = @_;
321 15 _log("127. IP Address");
322 15 my($len,$ip_data);
323 15 ($len,$$var) = unpack('C a*', $$var);
324 15 $len -= 2;
325 15 ($ip_data,$$var) = unpack("a$len a*", $$var);
326 15 my($flag,$reserved,@ip);
327 15 ($flag,$reserved,@ip) = unpack('C C N*', $ip_data);
328 15 @ip = map { join '.', unpack 'C4', pack 'N', $_ } @ip;
329 15 ▶ if($flag & 0x1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 1) 15 0 15
330 15 my $ip = shift(@ip);
331 15 _log(" Origin side remote RTP IP: %s", $ip);
332 15 $call->{origin_remote_rtp} = $ip;
333 }
334 15 ▶ if($flag & 0x2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 2) 0 15 15
335 0 my $ip = shift(@ip);
336 0 _log(" Origin side local RTP IP: %s", $ip);
337 0 $call->{origin_local_rtp} = $ip;
338 }
339 15 ▶ if($flag & 0x4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 4) 15 0 15
340 15 my $ip = shift(@ip);
341 15 _log(" Terminating side remote RTP IP: %s", $ip);
342 15 $call->{terminating_remote_rtp} = $ip;
343 }
344 15 ▶ if($flag & 0x8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 8) 0 15 15
345 0 my $ip = shift(@ip);
346 0 _log(" Terminating side local RTP IP: %s", $ip);
347 0 $call->{terminating_local_rtp} = $ip;
348 }
349 15 ▶ if($flag & 0x10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 16) 0 15 15
350 0 my $ip = shift(@ip);
351 0 _log(' Origin side remote signaling IP: %s', $ip);
352 0 $call->{origin_remote_signaling} = $ip;
353 }
354 15 ▶ if($flag & 0x20) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 32) 0 15 15
355 0 my $ip = shift(@ip);
356 0 _log(' Origin side local signaling IP: %s', $ip);
357 0 $call->{origin_local_signaling} = $ip;
358 }
359 15 ▶ if($flag & 0x40) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 64) 0 15 15
360 0 my $ip = shift(@ip);
361 0 _log(' Terminating side remote signaling IP: %s', $ip);
362 0 $call->{terminating_remote_signaling} = $ip;
363 }
364 15 ▶ if($flag & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 128) 0 15 15
365 0 my $ip = shift(@ip);
366 0 _log(' Terminating side local signaling IP: %s', $ip);
367 0 $call->{terminating_local_signaling} = $ip;
368 }
369 }
370 # 128. VoIP info
371 15 ▶sub block_128 {
Subroutine block_128: called CC=9 SCAR=22.4
Pod undocumented
372 15 my($call, $var) = @_;
373 15 _log("128. VoIP info");
374 15 my($len,$rx_codec,$tx_codec,$rx_period,$tx_period,$rx_bandwidth,$tx_bandwidth,$max_jitter,$flag);
375 15 ($len,$rx_codec,$tx_codec,$rx_period,$tx_period,$rx_bandwidth,$tx_bandwidth,$max_jitter,$flag,$$var) = unpack('CCCCCnnnC a*', $$var);
376 15 my %codec_label = (
377 0 => 'Undefined',
378 8 => 'G711Alaw64k',
379 9 => 'G711Ulaw64k',
380 66 => 'G728',
381 67 => 'G729',
382 68 => 'G729annexA',
383 70 => 'G729wAnnexB',
384 71 => 'G729AnnexAwAnnexB',
385 72 => 'GsmFullRate',
386 80 => 'G7231A5_3k',
387 81 => 'G7231A6_3k',
388 129 => 'FaxT38',
389 );
390 15 my %side_label = ( 0 => 'origin side', 1 => 'terminating side');
391 15 my %type_label = (
392 0 => 'Undefined',
393 1 => 'Audio',
394 2 => 'Data',
395 3 => 'Fax',
396 );
397  
398 15 ▶ _log(" Rx codec: %d / %s", $rx_codec, $codec_label{ $rx_codec } // 'UNKNOWN');
Condition50%1/2
$codec_label{$rx_codec} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$codec_label{$rx_codec} // "UNKNOWN"
$codec_label{$rx_codec}
Truth table50%1/2
A
A= $codec_label{$rx_codec}
Aresult
11
00
399 15 ▶ _log(" Tx codec: %d / %s", $tx_codec, $codec_label{ $tx_codec } // 'UNKNOWN');
Condition50%1/2
$codec_label{$tx_codec} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$codec_label{$tx_codec} // "UNKNOWN"
$codec_label{$tx_codec}
Truth table50%1/2
A
A= $codec_label{$tx_codec}
Aresult
11
00
400 15 _log(" Rx packetization period: %d ms", $rx_period);
401 15 _log(" Tx packetization period: %d ms", $tx_period);
402 15 _log(" Rx bandwidth: %d kbit/s", $rx_bandwidth);
403 15 _log(" Tx bandwidth: %d kbit/s", $tx_bandwidth);
404 15 _log(" Max. jitter buffer size: %d ms", $max_jitter);
405 15 my $call_side = ($flag & 0x80) >> 7;
406 15 my $call_type = $flag & 0x7F;
407 15 ▶ _log(" Call side: %d / %s", $call_side, $side_label{ $call_side } // 'UNKNOWN');
Condition50%1/2
$side_label{$call_side} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$side_label{$call_side} // "UNKNOWN"
$side_label{$call_side}
Truth table50%1/2
A
A= $side_label{$call_side}
Aresult
11
00
408 15 ▶ _log(" VoIP call type: %d / %s", $call_type, $type_label{ $call_type } // 'UNKNOWN');
Condition50%1/2
$type_label{$call_type} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$type_label{$call_type} // "UNKNOWN"
$type_label{$call_type}
Truth table50%1/2
A
A= $type_label{$call_type}
Aresult
11
00
409  
410 15 ▶ $call->{voip_rx_codec} = $codec_label{ $rx_codec } // 'UNKNOWN';
Condition50%1/2
$codec_label{$rx_codec} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$codec_label{$rx_codec} // "UNKNOWN"
$codec_label{$rx_codec}
Truth table50%1/2
A
A= $codec_label{$rx_codec}
Aresult
11
00
411 15 $call->{voip_rx_codec_code} = $rx_codec;
412 15 ▶ $call->{voip_tx_codec} = $codec_label{ $tx_codec } // 'UNKNOWN';
Condition50%1/2
$codec_label{$tx_codec} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$codec_label{$tx_codec} // "UNKNOWN"
$codec_label{$tx_codec}
Truth table50%1/2
A
A= $codec_label{$tx_codec}
Aresult
11
00
413 15 $call->{voip_tx_codec_code} = $tx_codec;
414 15 $call->{voip_rx_packetization} = $rx_period;
415 15 $call->{voip_tx_packetization} = $tx_period;
416 15 $call->{voip_rx_bandwidth} = $rx_bandwidth;
417 15 $call->{voip_tx_bandwidth} = $tx_bandwidth;
418 15 $call->{voip_max_jitter} = $max_jitter;
419 15 ▶ $call->{voip_call_side} = $side_label{ $call_side } // 'UNKNOWN';
Condition50%1/2
$side_label{$call_side} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$side_label{$call_side} // "UNKNOWN"
$side_label{$call_side}
Truth table50%1/2
A
A= $side_label{$call_side}
Aresult
11
00
420 15 $call->{voip_call_side_code} = $call_side;
421 15 ▶ $call->{voip_call_type} = $type_label{ $call_type } // 'UNKNOWN';
Condition50%1/2
$type_label{$call_type} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$type_label{$call_type} // "UNKNOWN"
$type_label{$call_type}
Truth table50%1/2
A
A= $type_label{$call_type}
Aresult
11
00
422 15 $call->{voip_call_type_code} = $call_type;
423 }
424 # 129. Amount of transferred data
425 15 ▶sub block_129 {
Subroutine block_129: called CC=3 SCAR=11.0
Pod undocumented
426 15 my($call, $var) = @_;
427 15 _log("129. Amount of transferred data");
428 15 my($len,$side,$rx_packets,$tx_packets,$rx_octets,$tx_octets,$lost,$jitter,$latency);
429 15 ($len,$side,$rx_packets,$tx_packets,$rx_octets,$tx_octets,$lost,$jitter,$latency,$$var) = unpack('CCNNNNNCC a*', $$var);
430 15 my %side_label = ( 0 => 'origin side', 1 => 'terminating side');
431 15 ▶ _log(" Call side: %d / %s", $side, $side_label{ $side } // 'UNKNOWN');
Condition50%1/2
$side_label{$side} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$side_label{$side} // "UNKNOWN"
$side_label{$side}
Truth table50%1/2
A
A= $side_label{$side}
Aresult
11
00
432 15 _log(" Rx packets: %d", $rx_packets);
433 15 _log(" Tx packets: %d", $tx_packets);
434 15 _log(" Rx octets: %d", $rx_octets);
435 15 _log(" Tx octets: %d", $tx_octets);
436 15 _log(" Packets lost: %d", $lost);
437 15 _log(" Average jitter: %d ms", $jitter);
438 15 _log(" Average latency: %d ms", $latency);
439 15 ▶ $call->{call_side} = $side_label{ $side } // 'UNKNOWN';
Condition50%1/2
$side_label{$side} // "UNKNOWN"
l!l
150
MC/DC0%0/1
$side_label{$side} // "UNKNOWN"
$side_label{$side}
Truth table50%1/2
A
A= $side_label{$side}
Aresult
11
00
440 15 $call->{rx_packets} = $rx_packets;
441 15 $call->{tx_packets} = $tx_packets;
442 15 $call->{rx_octets} = $rx_octets;
443 15 $call->{tx_octets} = $tx_octets;
444 15 $call->{packets_lost} = $lost;
445 15 $call->{average_jitter} = $jitter;
446 15 $call->{everage_latency} = $latency;
447 }
448 # 130. Service control data
449 # 131. New destination number
450 # 132. VoIP Quality of Service data (QoS VoIP Data)
451 # 133. Additional Centrex data
452 # 134. Additional statistics data
453 15 ▶sub block_134 {
Subroutine block_134: called CC=1 SCAR=0.0
Pod undocumented
454 15 my($call, $var) = @_;
455 15 _log("134. Additional statistics data");
456 15 my($len,$stats);
457 15 ($len,$$var) = unpack('C a*', $$var);
458 15 $len -= 2;
459 15 ($stats,$$var) = unpack("a$len a*", $$var);
460 15 _log(" Stats: 0x%s (len %d)", unpack('H*', $stats), $len);
461 # no useful info?
462 }
463 # TODO NOT IMPLEMENTED YET:
464 # 135. IMS charging identifier
465 # 136. Inter Operator Identifiers – IOI)
466 # 137. Supplementary service additional info
467 # 138. Calling Party Number
468 # 139. Additional calling number
469 # 140. Called party number
470 # 141. Sent called party number
471 # 142. Third party number
472 # 143. Redirecting party number
473 # 144. Incoming trunk data - Name
474 # 145. Outgoing trunk data - name
475 # 146. Node info
476 # 147. Global call reference
477 # 148. MLPP Data
478 # 149. Customer Data
479 # 150. Received Called Party Number
480 # 151. Call Type
481 # 152. IN Service Data
482 # 153. URI (Universal Resource Identification)
483 # 154. Free Format Operator Specific Data
484 # 155. -----
485 # 156. Additional Numbers
486  
487 0 ▶sub dump_var {
Subroutine dump_var: not called CC=1 SCAR=6.9
Pod undocumented
488 0 my $var = shift;
489 0 _log("---- Variable data (%d) ----", length($var));
490 0 _log('%s', unpack('H*', $var));
491 }
492  
493 # Parse individual record
494 #
495 # Each record has fixed part 16+(2..19) bytes
496 # and optional set of additional blocks
497 16 ▶sub parse_record {
Subroutine parse_record: called CC=11 SCAR=24.8
Pod undocumented
498 16 my $fh = shift;
499  
500 16 my $type_id;
501 16 ▶ sysread($fh, $type_id, 1) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $type_id, 1 or return 0 15 1 16
502 15 my $code = unpack('H2', $type_id);
503  
504 # Recort type:
505 # d2 -- Record at date and time changes (parsed but ignored)
506 # d3 -- Record of the loss of a certain amount of records
507 # d4 -- Restart record
508 # c8 -- Call record
509 15 ▶ if($code eq 'd2') {
Branch: 4 branches
BranchTrueFalseTotal
if ($code eq 'd2') { } 0 15 15
elsif ($code eq 'd3') { } 0 15 15
elsif ($code eq 'd4') { } 0 15 15
elsif ($code ne 'c8') { } 0 15 15
510 # record of date and time changes
511 0 parse_time_change_record($fh, $code);
512 0 return parse_record($fh);
513 }
514 elsif($code eq 'd3'){
515 # record of the loss of a certain amount of records
516 0 parse_loss_record($fh, $code);
517 0 return parse_record($fh);
518 }
519 elsif($code eq 'd4') {
520 # restart/reboot
521 0 parse_reboot_record($fh, $code);
522 0 return parse_record($fh);
523 }
524 elsif($code ne 'c8') {
525 0 die "Unknown record type: $code";
526 }
527 15 _log('Found Call Record marker %s', $code);
528  
529 15 my %call = ();
530  
531 # Statis header
532 # 1 - c8
533 # 2 - record length
534 # 4 - record index (in file?)
535 # 4 - call identifier (sequentially incremented number, unique -
536 # but incomplete calls can have call-id repeated again in later file)
537 # 3 - flags
538 # 1 - Sequence (4bits) / Charge status (4bits)
539 # 1 - Area code length (3bits) / Subscriber number length (5bits)
540 # ... - Area code and subscriber number of record owner
541 15 my $len;
542 15 ▶ sysread($fh, $len, 2) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $len, 2 or die $! 15 0 15
543 15 $len = unpack('n', $len);
544 #printf "Record lengh: %d bytes\n", $len;
545  
546 15 my $data;
547 15 ▶ sysread($fh, $data, $len - 3) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $data, $len - 3 or die $! 15 0 15
548 #print unpack('H*', $data), "\n";
549  
550 15 my($rec_index,$call_id,$flags,$seq,$area,$variable) = unpack('N N H6 H2 C a*', $data);
551 15 _log("Header");
552 15 _log(" Record index: %d", $rec_index);
553 15 _log(" Call ID: %d / %s", $call_id, unpack('H*', pack('N', $call_id)));
554 15 _log(" Flags: 0x%s", unpack('H6', pack('H6', $flags)));
555 15 _log(" Record sequence: %d", (($seq & 0xF0) >> 4));
556 15 _log(" Charge status: %d", ($seq & 0x0F));
557  
558 15 $call{record_index} = $rec_index;
559 15 $call{call_id} = $call_id;
560 15 $call{flags} = $flags;
561 15 $call{record_sequence} = (($seq & 0xF0) >> 4);
562 15 $call{charge_status} = ($seq & 0x0F);
563  
564 15 my($area_len) = ($area & 0xE0) >> 5;
565 15 my($subscriber_len) = ($area & 0x1F);
566 15 _log(" Area code length: %d", $area_len);
567 15 _log(" Subscriber num len: %d", $subscriber_len);
568 #my($subscriber_len) = ($area & 0x07);
569 #printf "Area/Subscriber: %s / %d . %d\n", $area, $area_len, $subscriber_len;
570 #printf " Area code length: %d\n", $area_len;
571 #printf " Subscriber number length: %d\n", $subscriber_len;
572  
573 #printf "---- Variable data (%d) ----\n", length($variable);
574 #print unpack('H*', $variable), "\n";
575  
576 15 my $cli_len = $area_len + $subscriber_len;
577 15 ▶ if($cli_len % 2 == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cli_len % 2 == 1) 15 0 15
578 # padding, each octet for cli contains 2 digits
579 15 $cli_len++;
580 }
581 15 my $cli;
582 15 ($cli, $variable) = unpack("H$cli_len a*", $variable);
583 15 ▶ if($cli_len > ($area_len + $subscriber_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cli_len > $area_len + $subscriber_len) 15 0 15
584 15 $cli = substr($cli, 0, -1);
585 }
586 15 _log(" CLI: %s", $cli);
587 15 $call{cli} = $cli;
588  
589 # dynamic part:
590 15 my $block_marker;
591 15 ▶ while( length($variable) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $variable > 0) 240 15 255
592 # each block has type marker + variable data, which depends on type
593 240 ($block_marker, $variable) = unpack('C a*', $variable);
594 #_log('Found block marker: %s', $block_marker);
595 {
596 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
597 240 my $sub = 'block_' . $block_marker;
598 240 $sub->(\%call, \$variable);
599 }
600 #dump_var($variable);
601 }
602  
603 15 _log('');
604 15 return \%call;
605 }
606  
607 # d2 - time change event
608 0 ▶sub parse_time_change_record {
Subroutine parse_time_change_record: not called CC=2 SCAR=17.9
Pod undocumented
609 0 my ($fh, $code) = @_;
610  
611 0 _log('Found Date Time Change marker %s', $code);
612  
613 0 my $data;
614 # 7 - old date and time
615 # 7 - new date and time
616 # 1 - cause of change
617 0 ▶ sysread($fh, $data, 15) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $data, 15 or die $! 0 0 0
618 0 my($year,$month,$day,$hour,$min,$sec,$msec,$reason);
619 0 ($year,$month,$day,$hour,$min,$sec,$msec,$data) = unpack('CCCCCCC a*', $data);
620 0 $year += 2000;
621 0 my $dtime = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
622 0 _log(' Old Time: %s', $dtime);
623  
624 0 ($year,$month,$day,$hour,$min,$sec,$msec,$reason) = unpack('CCCCCCC C', $data);
625 0 $year += 2000;
626 0 $dtime = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
627 0 _log(' New Time: %s', $dtime);
628  
629 # 1 - The real-time clock correction
630 # 2 - Summer / winter time changes
631 0 _log(' Change reason: %s', $reason);
632 }
633  
634 # d3 - loss record
635 0 ▶sub parse_loss_record {
Subroutine parse_loss_record: not called CC=2 SCAR=17.9
Pod undocumented
636 0 my ($fh, $code) = @_;
637  
638 0 _log('Found Loss marker %s', $code);
639  
640 0 my $data;
641 # 7 - start date and time
642 # 7 - end date and time
643 # 4 - number of records lost
644 0 ▶ sysread($fh, $data, 18) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $data, 18 or die $! 0 0 0
645 0 my($year,$month,$day,$hour,$min,$sec,$msec,$amount);
646 0 ($year,$month,$day,$hour,$min,$sec,$msec,$data) = unpack('CCCCCCC a*', $data);
647 0 $year += 2000;
648 0 my $dtime = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
649 0 _log(' Start Time: %s', $dtime);
650  
651 0 ($year,$month,$day,$hour,$min,$sec,$msec,$amount) = unpack('CCCCCCC L', $data);
652 0 $year += 2000;
653 0 $dtime = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
654 0 _log(' End Time: %s', $dtime);
655  
656 0 _log(' Amount of record loss: %s', $amount);
657 }
658  
659 # d4 - System was rebooted
660 0 ▶sub parse_reboot_record {
Subroutine parse_reboot_record: not called CC=3 SCAR=24.8
Pod undocumented
661 0 my ($fh, $code) = @_;
662 0 _log('Found Restart marker %s', $code);
663  
664 0 my $data;
665 # 7 - restart date and time
666 # 4 - reserved
667 0 ▶ sysread($fh, $data, 7) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $data, 7 or die $! 0 0 0
668 0 my($year,$month,$day,$hour,$min,$sec,$msec);
669 0 ($year,$month,$day,$hour,$min,$sec,$msec) = unpack('CCCCCCC', $data);
670 0 $year += 2000;
671 0 my $reboot_time = sprintf "%04d-%02d-%02d %02d:%02d:%02d.%02d", $year,$month,$day,$hour,$min,$sec,$msec;
672 0 _log(' Restart time: %s', $reboot_time);
673  
674 # ignored...
675 0 ▶ sysread($fh, $data, 4) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
sysread $fh, $data, 4 or die $! 0 0 0
676 }
677  
678 3 1;
679 #--
680  
681 =head1 AUTHOR
682  
683 Sergey Leschenko, C<< <sergle.ua at gmail.com> >>
684  
685 =head1 BUGS
686  
687 Please note that some blocks are not implemented, as I haven't seen them in real data files.
688  
689 Please report any bugs or feature requests to C<bug-cdr-parser-si3000 at rt.cpan.org>, or through
690 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CDR-Parser-SI3000>. I will be notified, and then you'll
691 automatically be notified of progress on your bug as I make changes.
692  
693  
694  
695  
696 =head1 SUPPORT
697  
698 You can find documentation for this module with the perldoc command.
699  
700 perldoc CDR::Parser::SI3000
701  
702  
703 You can also look for information at:
704  
705 =over 4
706  
707 =item * RT: CPAN's request tracker (report bugs here)
708  
709 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CDR-Parser-SI3000>
710  
711 =item * AnnoCPAN: Annotated CPAN documentation
712  
713 L<http://annocpan.org/dist/CDR-Parser-SI3000>
714  
715 =item * CPAN Ratings
716  
717 L<http://cpanratings.perl.org/d/CDR-Parser-SI3000>
718  
719 =item * Search CPAN
720  
721 L<http://search.cpan.org/dist/CDR-Parser-SI3000/>
722  
723 =back
724  
725  
726 =head1 ACKNOWLEDGEMENTS
727  
728  
729 =head1 LICENSE AND COPYRIGHT
730  
731 Copyright 2013 Sergey Leschenko.
732  
733 This program is free software; you can redistribute it and/or modify it
734 under the terms of the the Artistic License (2.0). You may obtain a
735 copy of the full license at:
736  
737 L<http://www.perlfoundation.org/artistic_license_2_0>
738  
739 Any use, modification, and distribution of the Standard or Modified
740 Versions is governed by this Artistic License. By using, modifying or
741 distributing the Package, you accept this license. Do not use, modify,
742 or distribute the Package, if you do not accept this license.
743  
744 If your Modified Version has been derived from a Modified Version made
745 by someone other than you, you are nevertheless required to ensure that
746 your Modified Version complies with the requirements of this license.
747  
748 This license does not grant you the right to use any trademark, service
749 mark, tradename, or logo of the Copyright Holder.
750  
751 This license includes the non-exclusive, worldwide, free-of-charge
752 patent license to make, have made, use, offer to sell, sell, import and
753 otherwise transfer the Package with respect to any patent claims
754 licensable by the Copyright Holder that are necessarily infringed by the
755 Package. If you institute patent litigation (including a cross-claim or
756 counterclaim) against any party alleging that the Package constitutes
757 direct or contributory patent infringement, then this Artistic License
758 to you shall terminate on the date that such litigation is filed.
759  
760 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
761 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
762 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
763 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
764 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
765 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
766 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
767 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
768  
769  
770 =cut
771  
772 3 1; # End of CDR::Parser::SI3000
↑ Summary