This chapter describes the steps necessary to rate calls and export rated CDRs (call detail records) to external systems.
Service billing on the NGCP is based on billing profiles, which may be assigned to VoIP accounts and SIP peerings. The design focuses on a simple, yet flexible approach, to support arbitrary dial-plans without introducing administrative overhead for the system administrators. The billing profiles may define a base fee and free time or free money per billing interval. Unused free time or money automatically expires at the end of the billing interval.
Each profile may have call destinations (usually based on E.164 number prefix matching) with configurable fees attached. Call destination fees each support individual intervals and rates, with a different duration and/or rate for the first interval. (e.g.: charge the first minute when the call is opened, then every 30 seconds, or make it independent of the duration at all) It is also possible to specify different durations and/or rates for peak and off-peak hours. Peak time may be specified based on weekdays, with additional support for manually managed dates based on calendar days. The call destinations can finally be grouped for an overview on user’s invoices by specifying a zone in two detail levels. (E.g.: national landline, national mobile, foreign 1, foreign 2, etc.)
The first step when setting up billing data is to create a billing profile, which will be the container for all other billing related data. Go to System Administration→Billing and click on create new billing profile. You will be taken to a web form where you may enter the following parameters (all values except handle and name may be left empty):
To set up billing fees, go to System Administration→Billing and select edit fees next to the billing profile you want to configure. Billing fees may be uploaded using a configurable CSV file format, or entered directly via the web interface by selecting create new entry just below Stored Billing Fees. To configure the CSV field order for the file upload, rearrange the entries in the www_admin→fees_csv→element_order array in /etc/ngcp-config/config.yml and execute the command ngcpcfg apply
. For input via the web interface, just fill in the text fields accordingly. In both cases, the following information may be specified independently for every destination:
431
, sip.sipwise.com
or someone@sip.sipwise.com
) or a regular expression matching the complete E.164 number, SIP domain or SIP URI (e.g. ^431.*$
, ^.*@sip\.sipwise\.com$
or ^someone@sip\.sipwise\.com$
). Regular expressions will be stored unmodified, plain strings will be extended exactly as shown in the two examples. The web interface will remove the regular expression prefix and suffix from an entry in the list of store billing fees.
The destination needs to be unique for a billing profile. The system will return an error if a destination is specified twice, both for the file upload and the input via the web interface. |
There are several internal services (vsc, conference, voicebox) which will need a specific destination entry with a domain-based destination. If you don’t want to charge the same (or nothing) for those services, add a fee for destination |
foreign zone 1
)
germany landline
)
To be able to differentiate between on-peak and off-peak calls, the platform stores off-peak times for every billing profile based on weekdays and/or calendar days. To edit the settings for a billing profile, go to System Administration→Billing and select edit peak times next to the billing profile you want to configure.
To set off-peak times for a weekday, click on edit next to the according weekday. You will be presented with two input fields which both receive a timestamp in the form of hh:mm:ss specifying a time of day for the start and end of the off-peak period. If any of the fields is left empty, the system will automatically insert 00:00:00
(start field) or 23:59:59 (end field). Click on save to store the setting in the database. You may create more than one off-peak period per weekday, and you may edit existing entries using any of the input fields and clicking save next to it. To completely delete a range, just select delete next to the entry.
To specify off-peak ranges based on calendar dates, click on add new date just below Dates. Enter a date in the form of YYYY-MM-DD into the date input field and fill in the start and end timestamps as outlined above. Select save to store the entry, or cancel to close the input form. Existing dates will be listed below, grouped by year. Click on any of the years to view all dates which have been recorded for it. If an entry is added, the corresponding year is expanded automatically. If an already existing date is added, it will overwrite the existing entry.
Regular billing data export is done using CSV (comma separated values) files which may be downloaded from the platform using the cdrexport user which has been created during the installation.
In order to be able to easily identify billing files, the file name is constructed by the following fixed-length fields:
<prefix><separator><version><separator><timestamp><separator><sequence number><suffix>
The definition of the specific fields is as follows:
Table 1. CDR export file name format
File name element | Length | Description |
---|---|---|
| 7 | A fixed string. Always |
| 1 | A fixed character. Always |
| 3 | The format version. Always |
| 14 | The file creation timestamp in the format |
| 10 | A unique 10-digit zero-padded sequence number for quick identification. |
| 4 | A fixed string. Always |
A valid example filename for a billing file created at 2011-11-10 12:30:00 and being the fourth file exported by the system, is:
sipwise_003_20111110123000_0000000004.cdr
Each billing file consists of three parts: one header line, zero to 5000 body lines and one trailer line.
The billing file header is one single line, which is constructed by the following fields:
<version>,<number of records>
The definition of the specific fields is as follows:
Table 2. CDR export file header line format
Body Element | Length | Type | Description |
---|---|---|---|
| 3 | zero-padded uint | The format version. Always |
| 4 | zero-padded uint | The number of body lines contained in the file. |
A valid example for a Header is:
003,0738
The body consists of a minimum of zero and a maximum of 5000 lines. Each line holds one call detail record in CSV format and is constructed by the following fields, all of them enclosed in single quotes:
Table 3. CDR export file body line format
Body Element | Length | Type | Description |
---|---|---|---|
| 1-10 | uint | Internal CDR id. |
| 19 | timestamp | Timestamp of last modification. |
| 36 | string | Internal UUID of calling party. |
| 1-255 | string | Internal ID of calling party provider. |
| 0-255 | string | External ID of calling party subscriber. |
| 0-255 | string | External ID of calling party contract. |
| 1-10 | uint | Interal ID of calling party VoIP account. |
| 1-255 | string | SIP username of calling party. |
| 1-255 | string | SIP domain of calling party. |
| 1-64 | string | CLI of calling party in E.164 format. |
| 1 | uint |
|
| 1 / 36 | string | Internal UUID of called party or |
| 1-255 | string | Internal ID of called party provider. |
| 0-255 | string | External ID of called party subscriber. |
| 0-255 | string | External ID of called party contract. |
| 1-10 | uint | Interal ID of called party VoIP account. |
| 1-255 | string | Final SIP username of called party. |
| 1-255 | string | Final SIP domain of called party. |
| 1-255 | string | Incoming SIP username of called party. |
| 1-255 | string | Incoming SIP domain of called party. |
| 0-255 | string | User to authenticate towards peer. |
| 0-255 | string | Realm to authenticate towards peer. |
| 3-4 | string | The type of the call - one of:
|
| 2-7 | string | The final call status - one of:
|
| 3 | uint | The final SIP status code. |
| 23 | timestamp | Timestamp of call start. Seconds include fractional part (3 decimals). |
| 4-11 | fixed precision | Length of call in seconds with 3 decimals. |
| 1-255 | string | The SIP call-id. |
| 2-7 | string | The internal rating status - one of:
Currently always |
| 0 / 19 | timestamp | Timestamp of rating or empty if not rated. |
| 4-11 | fixed precision | The carrier termination cost or empty if not rated. In cent with two decimals. |
| 4-11 | fixed precision | The customer cost or empty if not rated. In cent with two decimals. |
| 0-127 | string | The carrier billing zone or empty if not rated. |
| 0-127 | string | The customer billing zone or empty if not rated. |
| 0-127 | string | The carrier billing destination or empty if not rated. |
| 0-127 | string | The customer billing destination or empty if not rated. |
| 1-255 | string | The user-part of the SIP Request URI as received by the soft-switch. |
| 4-11 | fixed precision | Currently unused. |
| 1-10 | uint | The number of free time seconds used on carrier side or empty if not rated. |
| 1-10 | uint | Currently unused. |
| 1-10 | uint | The number of free time seconds used from the customer’s account balance or empty if not rated. |
| 0-127 | string | Currently unused. |
| 0-127 | string | Currently unused. |
| 1 | string | A fixed character. Always |
A valid example of one body line of a rated CDR is (line breaks added for clarity):
'2055','2007-11-07 11:36:49','6b6977f9-6125-4339-a82c-3c5af04652d2','1',,,'1','test', 'sipwise.com','43720456700','0','0','3',,,'0','4315551234','192.168.101.17','4315551234', 'sipwise.com',,,'call','ok','200','2007-11-05 16:17:37.641','74.731', '7F2A3EA1-472F34108EE84@192.168.101.11','ok','2007-11-07 11:36:49','9.25','16.03', 'national landline','national landline','landline vienna','landline vienna','015551234', '0.00','0','0','0','',''
The billing file trailer is one single line, which is constructed by the following fields:
<md5 sum>
The <md5 sum>
is a 32 character hexadecimal MD5 hash of the Header and Body.
To validate the billing file, one must remove the Trailer before computing the MD5 sum of the file. An example bash script to validate the integrity of the file is given below:
#!/bin/sh error() { echo $@; exit 1; } test -n "$1" || error "Usage: $0 <cdr-file>" test -f "$1" || error "File '$1' not found" TMPFILE="/tmp/$(basename "$1")" MD5="$(sed -rn '$ s/^([a-z0-9]{32}).*$/\1/i p' "$1") $TMPFILE" sed '$d' "$1" > "$TMPFILE" echo "$MD5" | md5sum -c - rm -f "$TMPFILE"
Given the script is located in cdr-md5.sh
and the CDR-file is sipwise_001_20071110123000_0000000004.cdr
, the output of the integrity check for an intact CDR file would be:
$ ./cdr-md5.sh sipwise_001_20071110123000_0000000004.cdr /tmp/sipwise_001_20071110123000_0000000004.cdr: OK
If the file has been altered during transmission, the output of the integrity check would be:
$ ./cdr-md5.sh sipwise_001_20071110123000_0000000004.cdr /tmp/sipwise_001_20071110123000_0000000004.cdr: FAILED md5sum: WARNING: 1 of 1 computed checksum did NOT match
Billing files are created twice per hour at minutes 25
and 55
and are stored in the home directory of the cdrexport
user. If the amount of records within the transmission interval exceeds the threshold of 5000 records per file, multiple billing files are created. If no billing records are found for an interval, a billing file without body data is constructed for easy detection of lost billing files on the 3rd party side.
CDR files are fetched by a 3rd party billing system using SFTP or SCP with either public key or password authentication using the username cdrexport. If public key authentication is chosen, the public key file has to be stored in the file ~/.ssh/authorized_keys2
below the home directory of the cdrexport
user. Otherwise, a password has to be set for the user.
The 3rd party billing system is responsible for deleting CDR files after fetching them.
The |