Summary:ASTERISK-12635: CDR billsec value accuracy
Reporter:Eric Rousseau (erousseau)Labels:
Date Opened:2008-08-22 19:34:58Date Closed:2008-08-26 10:48:55
Versions:Frequency of
Description:We are using CDR for billing and we are now comparing billing information from Asterisk CDR and billing information bringed by our PSTN operator.

We have to face a minor but critical issue regarding the billsec value accuracy.

For some calls, the billsec value bringed by the operator is 1s more than the billsec value reported by Asterisk in CDR.

On the PSTN operator side, the billing process charges any second that has been initiated. Meaning that for a call that took (billsec) 62.3 s (62 s and 300 ms) the operator will report and charge a billsec value of 63.

I have looked the core code from Asterisk source and found the following in main/cdr.c :

cdr->billsec = ast_tvzero(cdr->answer) ? 0 : cdr->end.tv_sec - cdr->answer.tv_sec;

Imagine that cdr->end.tv_usec give 0.9s and that cdr->answer.tv_usec give 0.1s. The billsec value (as calculated by Asterisk) looks like simply ignore the 0.8s that come from the tv_usec value difference...


For the current issue (any second that has been initiated should be charged), billsec value would be more accurate with the following code:

cdr->billsec = ast_tvzero(cdr->answer) ? 0 : cdr->end.tv_sec - cdr->answer.tv_sec;
cdr->billsec += cdr->end.tv_usec > cdr->answer.tv_usec ? 1 : 0;

But I guess in some cases, user could prefer to get the billsec value rounded...
Comments:By: Tilghman Lesher (tilghman) 2008-08-24 10:36:01

Some of this is addressed in 1.6, where the accuracy of billsec and duration will be correct down to the millisecond, so appropriate rounding may take place at a later time.  Note that this is only available on CDR drivers which support the new accuracy (most of the stock drivers, actually) and on database tables which allow either decimals or floats in the duration/billsec columns.

By: Digium Subversion (svnbot) 2008-08-26 10:48:51

Repository: asterisk
Revision: 140057

U   trunk/CHANGES
U   trunk/configs/cdr.conf.sample
U   trunk/include/asterisk/options.h
U   trunk/main/cdr.c

r140057 | murf | 2008-08-26 10:48:50 -0500 (Tue, 26 Aug 2008) | 21 lines

(closes issue ASTERISK-12635)
Reported by: erousseau

This was a reasonable enhancement request, which was
easy to implement. Since it's an enhancement, it
could only be applied to trunk.

Basically, for accounting where "initiated" seconds
are billed for, if the microseconds field on the end
time is greater than the microseconds field for the
answer time, add one second to the billsec field.

The implementation was requested by erousseau, and
I've implemented it as requested. I've updated the
CHANGES, the cdr.conf.sample, and the .h files
accordingly, to accept and set a flag for the
corresponding new option. cdr.c adds in the extra
second based on the usec fields if the option is
set. Tested, seems to be working fine.