Asterisk Billsec Round Up/Down?

Hi There Community,

Does somebody know how billsec cdr field calculates the billed seconds?
Im currently having differences with multiple endpoints, not in call amount but billed seconds,

2/3 of the amount of calls seems to be adding 1 seconds to the total billed seconds.

Does billsec
Always round up? Ex: 0.1s → +1sec
Round up after 0.5 seconds? Ex: 0.4s → 0s, Ex: 0.5s → +1sec
Always round down? Ex: 0.9s → 0s

If billsec is rounding, is there a way to modify rounding mechanics?

Any suggestions or advices will be greatly appreciated
Warm Regards

The code states how billsec is actually calculated[1] and here is the function that does it[2]. You should be able to use those to better understand what is going on, and if modifications are desired where they would need to occur.

[1] https://github.com/asterisk/asterisk/blob/6a4f2a7cf7c934a2d03d220bfe92cdf61fbb05c2/main/cdr.c#L170
[2] https://github.com/asterisk/asterisk/blob/6a4f2a7cf7c934a2d03d220bfe92cdf61fbb05c2/main/cdr.c#L1274

Does billsec
Always round up? Ex: 0.1s → +1sec
Round up after 0.5 seconds? Ex: 0.4s → 0s, Ex: 0.5s → +1sec
Always round down? Ex: 0.9s → 0s

I believe that “always round up” is the standard answer for Telcos, therefore
is probably what Asterisk does (but I’ve not looked at the source code).

If billsec is rounding, is there a way to modify rounding mechanics?

Well, it’s definitely rounding by one means or another. Which CDR storage
system are you using? There are ways to get it to include microseconds, which
you can then round however you like.

Antony.

The code seems to round down, or to nearest, with 0.5 going to 1.

Historically, telcos used to round up to minutes, or to meter pulses, rather than to seconds. I think some used sub-multiples of the meter pulse interval in the actual measurements.

Also, the two ends will never exactly agree on when calls start and end, so there will always be discrepancies.

@jcolp , @Pooh & @david551
Thanks a lot for your replies!

Another question (If you can answer of course)

Im seeing that initiatedseconds parameter might help rounding up,

Source: Asterisk 19 Configuration_cdr

Has someone used this value before?
Warm Regards

Please use text, not images. That description is wrong. The actual code, which is very simple, uses milliseconds, not microseconds, always uses them, and that option selects between round down and round to nearest, with 0.5 rounding up.

Dear David,

Do you mean, modifying the base code and recompiling asterisk would do the trick?
Assuming I know how to modify it properly…

Warm Regards

You can do almost anything that way, and in this case the code is simple.

Thanks a lot,
I will give it a try

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.