| 1 | |
|---|
| 2 | CDRTool rating engine |
|---|
| 3 | --------------------- |
|---|
| 4 | |
|---|
| 5 | CDRTool provides on-the-fly rating of CDRs from multiple data-sources like |
|---|
| 6 | OpenSER, Asterisk or Cisco gateways based on an easy to build rating plan, |
|---|
| 7 | which can be imported from external data sources. |
|---|
| 8 | |
|---|
| 9 | A Call Detail Record (CDR) is one record from the radius radacct table. The |
|---|
| 10 | CDR record contains all information related to a session, like session |
|---|
| 11 | duration, calling, called party and media information. The rating engine |
|---|
| 12 | calculates the price of the session, which is applied in real-time to the |
|---|
| 13 | web output and saved to the database containing the CDRs. |
|---|
| 14 | |
|---|
| 15 | Based on exceptions, different rates may be applied per caller party |
|---|
| 16 | identified by source IP, domain or subscriber. |
|---|
| 17 | |
|---|
| 18 | Rating is applied only after the call has ended. CDRTool considers that a |
|---|
| 19 | call has ended when there is a stop time. In case of missing BYEs, CDRTool |
|---|
| 20 | relies on the fact that MediaProxy will update the CDR with the proper stop |
|---|
| 21 | time information based on the last moment the media stream passed through |
|---|
| 22 | the media proxy. |
|---|
| 23 | |
|---|
| 24 | The rates are linked with profiles corresponding with different time of the |
|---|
| 25 | day, day of the week or holidays. For rating calls, which span multiple |
|---|
| 26 | profiles, the right rate is selected and applied for the call duration |
|---|
| 27 | within each profile. Each customer may be assigned its own dedicated rating |
|---|
| 28 | plans destination id and names. Chained profiles are possible to enable |
|---|
| 29 | exception based rating. Multiple customers may share a common rate list, |
|---|
| 30 | while some destinations may be rated differently, only the differences must |
|---|
| 31 | be provisioned. Multiple time zones are supported for multiple billing |
|---|
| 32 | parties hosted on the same platform. |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | Rating logic |
|---|
| 36 | ------------ |
|---|
| 37 | |
|---|
| 38 | The following steps are performed to rate a CDR: |
|---|
| 39 | |
|---|
| 40 | 1. Determination of application type |
|---|
| 41 | 2. Determination of the billing party |
|---|
| 42 | 3. Determination of the destination id |
|---|
| 43 | 4. Determination of the costs |
|---|
| 44 | |
|---|
| 45 | Each step must succeed in order to calculate the price for the session. The |
|---|
| 46 | steps are described in detail below. |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | 1. Determination of application type |
|---|
| 50 | ------------------------------------ |
|---|
| 51 | |
|---|
| 52 | The only supported application type is 'audio'. |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | 2. Determination of the billing party |
|---|
| 56 | ------------------------------------- |
|---|
| 57 | |
|---|
| 58 | CDRTool identifies the rating plan associated with a session based on a |
|---|
| 59 | billing party entity, which is calculated on the fly. The calculus is based |
|---|
| 60 | on the first successful match of the BillingPartyId field from the CDR |
|---|
| 61 | database (radacct.UserName for radius data sources) in the following order: |
|---|
| 62 | |
|---|
| 63 | 1. SIP account user@domain |
|---|
| 64 | 2. SIP domain of the SIP account |
|---|
| 65 | 3. Source IP of the SIP session |
|---|
| 66 | 4. Default (when none of the above matches) |
|---|
| 67 | |
|---|
| 68 | The longest match is done against entries present in the billing_customers |
|---|
| 69 | table. The match yields a set of profiles to be used further depending on |
|---|
| 70 | the type of session and day of the week. |
|---|
| 71 | |
|---|
| 72 | The billing_customers table field that matches the Source IP is called |
|---|
| 73 | gateway. Do not use hostnames for this field. "gateway" or "trusted peer" |
|---|
| 74 | terms are used interchangebly in this document. They both relate to the |
|---|
| 75 | source IP address that generated the SIP session. |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | 3. Determination of the destination id |
|---|
| 79 | -------------------------------------- |
|---|
| 80 | |
|---|
| 81 | CDRTool identifies the destination for which to perform the rating based on |
|---|
| 82 | one of the destination fields from the accounting table. The destination |
|---|
| 83 | field is taken from the first non-empty field in this order: |
|---|
| 84 | |
|---|
| 85 | 1. CanonicalURI (the destination after all lookups inside the SIP Proxy) |
|---|
| 86 | 2. SipTranslatedRequestURI (the Request URI as presented by the SIP UA) |
|---|
| 87 | 3. CalledStationId (the content of the To header) |
|---|
| 88 | |
|---|
| 89 | The CanonicalURI is preferred because the destination field must contain the |
|---|
| 90 | real SIP destination after all possible lookups performed by the SIP Proxy |
|---|
| 91 | as this is something reliable and the dialing user cannot control it. |
|---|
| 92 | OpenSER must be configured to send CanonicalURI Radius attribute when doing |
|---|
| 93 | accounting (instructions are available in INSTALL.txt). |
|---|
| 94 | |
|---|
| 95 | The destination id is then calculated based on the longest match of this |
|---|
| 96 | destination field in the billing_destinations table and the billing party. |
|---|
| 97 | |
|---|
| 98 | The longest match for the chosen destination field is performed by the |
|---|
| 99 | E164_Europe class from cdr_generic.php. It assumes the destination always |
|---|
| 100 | starts with a zero for a national call and with double zero for an |
|---|
| 101 | international call. If your dialing plan is different you must design a |
|---|
| 102 | custom class and function to and defined in global.inc as follows: |
|---|
| 103 | |
|---|
| 104 | $CDRTool['normalize']['E164class']='MyE164Class'; |
|---|
| 105 | |
|---|
| 106 | For an example see E164_USA class from cdr_generic.php that matches American |
|---|
| 107 | dialing plan. |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | 4. Determination of one time and recurrent costs |
|---|
| 111 | ------------------------------------------------ |
|---|
| 112 | |
|---|
| 113 | The following steps are taken to rate the calls terminated to PSTN based on |
|---|
| 114 | the destination id and the billing party found in previous steps. |
|---|
| 115 | |
|---|
| 116 | 1. Lookup the billing Profile in cdrtool.billing_customers table in the |
|---|
| 117 | following order: subscriber,domain,gateway (based on $this->dayofweek): |
|---|
| 118 | (as explained in "Determination of the billing party" above) |
|---|
| 119 | |
|---|
| 120 | - profile_name1 matches week days [1-5] |
|---|
| 121 | - profile_name1_alt matches week days [1-5] if no rates for profile_name1 |
|---|
| 122 | are found |
|---|
| 123 | - profile_name2 matches week-ends [6-0] |
|---|
| 124 | - profile_name2_alt matches week-ends [6-0] if no rates for profile_name2 |
|---|
| 125 | are found |
|---|
| 126 | - profile_name2 matches also holidays from billing_holidays table |
|---|
| 127 | |
|---|
| 128 | The week starts with 0 (Sunday) and ends with 6 (Saturday) |
|---|
| 129 | |
|---|
| 130 | 2. Using the profile_name found, lookup the rate_name based |
|---|
| 131 | on $this->hourofday in cdrtool.billing_profiles table |
|---|
| 132 | |
|---|
| 133 | If no rate_name is found for the given profiles a second set of profiles |
|---|
| 134 | are used, profile_name1_alt and profile_name2_alt. |
|---|
| 135 | |
|---|
| 136 | - the day may be split in maximum 4 periods |
|---|
| 137 | - the days starts with hour 0 and ends with hour 24 |
|---|
| 138 | - rate_name1 defines the first interval after hour 0 |
|---|
| 139 | - rate_name2 defines the first interval after rate_name1 |
|---|
| 140 | - rate_name3 defines the first interval after rate_name2 |
|---|
| 141 | - rate_name4 defines the first interval after rate_name3 |
|---|
| 142 | |
|---|
| 143 | When the hour matches an interval use the rate_nameX found to lookup the |
|---|
| 144 | rate in billing_rates, if no record is found use the rate called |
|---|
| 145 | 'default' |
|---|
| 146 | |
|---|
| 147 | 3. Lookup in the cdrtool.billing_rates table the record having same name |
|---|
| 148 | found at point 2 having billing_rates.destination = destination Id |
|---|
| 149 | and billing_rates.application = application type found in the steps above. |
|---|
| 150 | |
|---|
| 151 | - return an array with all the rating values and the duration rated |
|---|
| 152 | |
|---|
| 153 | No rate will be returned if no destination Id is found. Make sure each |
|---|
| 154 | possible destination has a corresponding Id and name in destinations |
|---|
| 155 | table. |
|---|
| 156 | |
|---|
| 157 | 4. If the duration rated at point 3 is less than total call duration, apply |
|---|
| 158 | point 3 again for the remaining call duration in next profile. A maximum |
|---|
| 159 | of 10 spans (different rates depending of time of day, day of the week) |
|---|
| 160 | can be calculated using this mechanism. |
|---|
| 161 | |
|---|
| 162 | 5. Lookup the call rate based on time (peak/of-peak, day of week, holiday) |
|---|
| 163 | |
|---|
| 164 | 6. Calculate the call Price based on duration. In global.inc there are |
|---|
| 165 | several variables that affect how the price is calculated. These |
|---|
| 166 | settings are global per CDRTool installation but some can be overwritten |
|---|
| 167 | with per customer values in the billing_customers table. |
|---|
| 168 | |
|---|
| 169 | $RatingEngine=array( |
|---|
| 170 | "priceDenominator" => 10000, // Rates units (global setting) |
|---|
| 171 | "priceDecimalDigits" => 4, // Decimal information (global setting) |
|---|
| 172 | "minimumDurationCharged" => 0, // Rate a minimum of X seconds (per customer) |
|---|
| 173 | "minimumDuration" => 0, // Minimum duration to rate, if call duration is shorter the price is zero (per customer) |
|---|
| 174 | "durationPeriodRated" => 60 // Rate is per 60 seconds (global setting) |
|---|
| 175 | "trafficSizeRated" => 1024, // Default we rate per 1 MB (global setting) |
|---|
| 176 | "reportMissingRates" => 0 // Send emails to administrator in case of missing rates |
|---|
| 177 | ); |
|---|
| 178 | |
|---|
| 179 | Pricing formula |
|---|
| 180 | --------------- |
|---|
| 181 | |
|---|
| 182 | if min_duration then |
|---|
| 183 | minimumDurationCharged = min_duration |
|---|
| 184 | else if minimumDurationCharged set in global inc |
|---|
| 185 | use minimumDurationCharged from global.inc |
|---|
| 186 | else |
|---|
| 187 | minimumDurationCharged = call duration |
|---|
| 188 | |
|---|
| 189 | if increment then |
|---|
| 190 | durationForRating = round to the next increment |
|---|
| 191 | else |
|---|
| 192 | durationForRating = call duration |
|---|
| 193 | |
|---|
| 194 | if durationForRating >= minimumDurationCharged then |
|---|
| 195 | Price = connectCost/priceDenominator+ |
|---|
| 196 | durationRate*durationForRating/durationPeriodRated/priceDenominator+ |
|---|
| 197 | trafficRate/priceDenominator*(inputTraffic+outputTraffic)/8+ |
|---|
| 198 | applicationRate/priceDenominator |
|---|
| 199 | else |
|---|
| 200 | Price = 0 |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | ENUM discounts |
|---|
| 204 | -------------- |
|---|
| 205 | |
|---|
| 206 | The rating engine can apply a discount associated with the ENUM top |
|---|
| 207 | level domain that returned the final destination. |
|---|
| 208 | |
|---|
| 209 | Price = Price - Price * ENUM discount /100 |
|---|
| 210 | |
|---|
| 211 | To apply ENUM based discounts, the ENUM TLD must be saved with each CDR |
|---|
| 212 | and the TLDs with their corespondent discounts must be provisioned in the |
|---|
| 213 | Rating tables section. See ENUM TLD discounts section for more |
|---|
| 214 | information. |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | 8. Save the calculated price, Billing Party and Destination Id for each call |
|---|
| 218 | in the CDRs. Having the price stored in database, it is possible to build |
|---|
| 219 | statistics to display consolidated revenues per country code, network or |
|---|
| 220 | subscriber. |
|---|
| 221 | |
|---|
| 222 | Update the normalized caller and destination for each CDR. |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | Importing and exporting of rating files |
|---|
| 226 | --------------------------------------- |
|---|
| 227 | |
|---|
| 228 | There are different data files needed for rating CDRs. The data files are |
|---|
| 229 | imported into corresponding MySQL tables. The files must be uploaded to |
|---|
| 230 | /var/spool/cdrtool directory. To load the files into the database run |
|---|
| 231 | the following command: |
|---|
| 232 | |
|---|
| 233 | /var/www/CDRTool/scripts/importRatingTables.php |
|---|
| 234 | |
|---|
| 235 | The import script knows to import the files only once so you may dump |
|---|
| 236 | several files there and safely run the import script from cron. The import |
|---|
| 237 | script detects whether the files have been imported by building a unique key |
|---|
| 238 | out of the filename and the hash of the file content. So you may use the |
|---|
| 239 | same filenames as long as the content differs and viceversa. If the import |
|---|
| 240 | file has changed any records, the rating engine is automatically instructed |
|---|
| 241 | to reload the changes. |
|---|
| 242 | |
|---|
| 243 | Sample csv files are found in the setup directory. The CSV field order is |
|---|
| 244 | described in setup/*.csv sample files. The first element on each line |
|---|
| 245 | specifies the operation will be performed with the current record. The |
|---|
| 246 | operation can be 2 (update/insert), 1 (insert) or 3 (delete). |
|---|
| 247 | |
|---|
| 248 | The updates are performed based on a unique key present in each table: |
|---|
| 249 | |
|---|
| 250 | billing_customers - cust_idx (gateway,domain,subscriber) |
|---|
| 251 | destinations - cust_dest_idx (gateway,domain,subscriber,dest_id) |
|---|
| 252 | billing_profiles - profile_idx (gateway,domain,subscriber,name) |
|---|
| 253 | billing_rates - rate_idx (gateway,domain,subscriber,name,destination,application) |
|---|
| 254 | billing_rates_history - rate_idx (gateway,domain,subscriber,name,destination,application,startDate,endDate) |
|---|
| 255 | |
|---|
| 256 | The content of the rating tables can be exported in the Rating tables page. |
|---|
| 257 | |
|---|
| 258 | The import script detects the type of file to import based on its filename. |
|---|
| 259 | |
|---|
| 260 | The filename must comply with the following naming convention: |
|---|
| 261 | |
|---|
| 262 | 1. Must start with the name of the table without the billing_ |
|---|
| 263 | 2. May optionally contain extra characters after the name |
|---|
| 264 | 3. Must end with .csv extension |
|---|
| 265 | |
|---|
| 266 | Examples: |
|---|
| 267 | |
|---|
| 268 | - rates.csv or rates20061201.cvs will be loaded into the rates table |
|---|
| 269 | - profiles.csv or profiles20061201.cvs will be loaded into the profiles table |
|---|
| 270 | - destinations200601.csv will be loaded in the destinations table |
|---|
| 271 | - ratesHistory200801.csv will be loaded in the rates_history table |
|---|
| 272 | |
|---|
| 273 | Do not use 'billing_' prefix in front of the file name. |
|---|
| 274 | |
|---|
| 275 | It is advisable to name the files in a consistent manner like tableYYYYMMDD.csv |
|---|
| 276 | |
|---|
| 277 | The results of the import operation is logged in the database and can be |
|---|
| 278 | viewed in the Log section of the web interface and the syslog. |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | MySQL schema |
|---|
| 282 | ------------ |
|---|
| 283 | |
|---|
| 284 | To see the rating tables and their structures connect to the cdrtool |
|---|
| 285 | database using mysql client. |
|---|
| 286 | |
|---|
| 287 | Run 'show tables' and 'describe table_name': |
|---|
| 288 | |
|---|
| 289 | billing_customers |
|---|
| 290 | +-------------------+ |
|---|
| 291 | | Field | |
|---|
| 292 | +-------------------+ |
|---|
| 293 | | id | |
|---|
| 294 | | gateway | |
|---|
| 295 | | domain | |
|---|
| 296 | | subscriber | |
|---|
| 297 | | profile_name1 | |
|---|
| 298 | | profile_name1_alt | |
|---|
| 299 | | profile_name2 | |
|---|
| 300 | | profile_name2_alt | |
|---|
| 301 | | timezone | |
|---|
| 302 | | increment | |
|---|
| 303 | | min_duration | |
|---|
| 304 | | country_code | |
|---|
| 305 | +-------------------+ |
|---|
| 306 | |
|---|
| 307 | billing_profiles |
|---|
| 308 | +------------+ |
|---|
| 309 | | Field | |
|---|
| 310 | +------------+ |
|---|
| 311 | | id | |
|---|
| 312 | | gateway | |
|---|
| 313 | | domain | |
|---|
| 314 | | subscriber | |
|---|
| 315 | | name | |
|---|
| 316 | | rate_name1 | |
|---|
| 317 | | hour1 | |
|---|
| 318 | | rate_name2 | |
|---|
| 319 | | hour2 | |
|---|
| 320 | | rate_name3 | |
|---|
| 321 | | hour3 | |
|---|
| 322 | | rate_name4 | |
|---|
| 323 | | hour4 | |
|---|
| 324 | +------------+ |
|---|
| 325 | |
|---|
| 326 | billing_rates |
|---|
| 327 | +-----------------+ |
|---|
| 328 | | Field | |
|---|
| 329 | +-----------------+ |
|---|
| 330 | | id | |
|---|
| 331 | | gateway | |
|---|
| 332 | | domain | |
|---|
| 333 | | subscriber | |
|---|
| 334 | | name | |
|---|
| 335 | | destination | |
|---|
| 336 | | durationRate | |
|---|
| 337 | | trafficRate | |
|---|
| 338 | | application | |
|---|
| 339 | | connectCost | |
|---|
| 340 | +-----------------+ |
|---|
| 341 | |
|---|
| 342 | billing_rates_history |
|---|
| 343 | +-----------------+ |
|---|
| 344 | | Field | |
|---|
| 345 | +-----------------+ |
|---|
| 346 | | id | |
|---|
| 347 | | gateway | |
|---|
| 348 | | domain | |
|---|
| 349 | | subscriber | |
|---|
| 350 | | name | |
|---|
| 351 | | destination | |
|---|
| 352 | | durationRate | |
|---|
| 353 | | trafficRate | |
|---|
| 354 | | application | |
|---|
| 355 | | connectCost | |
|---|
| 356 | | startDate | |
|---|
| 357 | | endDate | |
|---|
| 358 | +-----------------+ |
|---|
| 359 | |
|---|
| 360 | destinations |
|---|
| 361 | +------------+ |
|---|
| 362 | | Field | |
|---|
| 363 | +------------+ |
|---|
| 364 | | id | |
|---|
| 365 | | gateway | |
|---|
| 366 | | domain | |
|---|
| 367 | | subscriber | |
|---|
| 368 | | dest_id | |
|---|
| 369 | | dest_name | |
|---|
| 370 | | asr | |
|---|
| 371 | +------------+ |
|---|
| 372 | |
|---|
| 373 | billing_holidays |
|---|
| 374 | +-------+ |
|---|
| 375 | | Field | |
|---|
| 376 | +-------+ |
|---|
| 377 | | day | |
|---|
| 378 | +-------+ |
|---|
| 379 | |
|---|
| 380 | prepaid |
|---|
| 381 | +------------------+ |
|---|
| 382 | | Field | |
|---|
| 383 | +------------------+ |
|---|
| 384 | | id | |
|---|
| 385 | | account | |
|---|
| 386 | | balance | |
|---|
| 387 | | change_date | |
|---|
| 388 | | call_lock | |
|---|
| 389 | | last_call_price | |
|---|
| 390 | | destination | |
|---|
| 391 | | active_sessions | |
|---|
| 392 | | maxsessiontime | |
|---|
| 393 | | call_in_progress | |
|---|
| 394 | | session_counter | |
|---|
| 395 | +------------------+ |
|---|
| 396 | |
|---|
| 397 | prepaid_history |
|---|
| 398 | +----------+ |
|---|
| 399 | | Field | |
|---|
| 400 | +----------+ |
|---|
| 401 | | id | |
|---|
| 402 | | username | |
|---|
| 403 | | domain | |
|---|
| 404 | | action | |
|---|
| 405 | | number | |
|---|
| 406 | | value | |
|---|
| 407 | | balance | |
|---|
| 408 | | date | |
|---|
| 409 | +----------+ |
|---|
| 410 | |
|---|
| 411 | billing_enum_tlds |
|---|
| 412 | +-------------+ |
|---|
| 413 | | Field | |
|---|
| 414 | +-------------+ |
|---|
| 415 | | id | |
|---|
| 416 | | gateway | |
|---|
| 417 | | domain | |
|---|
| 418 | | subscriber | |
|---|
| 419 | | enum_tld | |
|---|
| 420 | | e164_regexp | |
|---|
| 421 | | discount | |
|---|
| 422 | +-------------+ |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | Web based rating tables management |
|---|
| 426 | ---------------------------------- |
|---|
| 427 | |
|---|
| 428 | The rating tables can be edited from the web, click on Rating tables link. |
|---|
| 429 | One may insert/update/delete records or apply changes on selections. For |
|---|
| 430 | example it is possible to increase with XX units the rate for a specific |
|---|
| 431 | destination. |
|---|
| 432 | |
|---|
| 433 | Numeric fields support mathematical operators [+-*/], one may update |
|---|
| 434 | using absolute or relative values the fields in the rating tables. |
|---|
| 435 | |
|---|
| 436 | The rates may be copied in bulk and start quickly working with a fresh |
|---|
| 437 | new rating table. Select in the Rates PSTN table by filtering on rate |
|---|
| 438 | name. A new button appears which allows the copy of all selected rates |
|---|
| 439 | into a new set. The rates are copied under the old rate id with _N |
|---|
| 440 | suffix where N is the next available number for which same rate id does |
|---|
| 441 | not exist. |
|---|
| 442 | |
|---|
| 443 | The content of the rating tables can be exported into comma separated |
|---|
| 444 | files. The CSV format has the same structure as the import file, is |
|---|
| 445 | fairly easy to modify an exported batch file into an external |
|---|
| 446 | application and load it back into CDRTool. |
|---|
| 447 | |
|---|
| 448 | Note |
|---|
| 449 | |
|---|
| 450 | When $RatingEngine['split_rating_table'] is true, after changing the rates |
|---|
| 451 | in the web interface or by importing them, you must run the script |
|---|
| 452 | scripts/splitRatingTables.php to split the central billing_rates table into |
|---|
| 453 | individual tables for each rate id. You do not need this feature if you have |
|---|
| 454 | less than 100K rates in your system. |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | ENUM TLD discounts |
|---|
| 458 | ------------------ |
|---|
| 459 | |
|---|
| 460 | To apply discounts based on ENUM certain conditions must be met. |
|---|
| 461 | |
|---|
| 462 | 1. The username part of the result of the ENUM lookup must be numeric and |
|---|
| 463 | contain a fully qualified E164 number, optional with a numeric prefix. |
|---|
| 464 | |
|---|
| 465 | Example: |
|---|
| 466 | |
|---|
| 467 | The user dialed 020800001, the SIP Proxy has normalized the destination |
|---|
| 468 | based on local policy by stripping 0 and adding country code 31 to obtain |
|---|
| 469 | the fully qualified E164 number 3120800001, than it performed an ENUM |
|---|
| 470 | lookup under top level domain e164.example.com for +3120800001. The ENUM |
|---|
| 471 | server responsable for e164.example.com returned a response with the |
|---|
| 472 | destination sip:01131208000011@gateway.example.com |
|---|
| 473 | |
|---|
| 474 | In the CDR, ENUMtld is stored as e164.example.com |
|---|
| 475 | |
|---|
| 476 | The rating logic checks if the TLD exists in the billing_enum_tlds table. |
|---|
| 477 | If it does, the rating engine tries to match the regexp field against the |
|---|
| 478 | username part of the destination from the ENUM response, which has been |
|---|
| 479 | saved in the Canonical URI. The match must return a fully qualified E164 |
|---|
| 480 | number otherwise the call is considered to have ended to a no E164 |
|---|
| 481 | destination and the call will be free of charge. |
|---|
| 482 | |
|---|
| 483 | 2. In the ENUM tld table you must provision (for the example above): |
|---|
| 484 | |
|---|
| 485 | - TLD: e164.example.com |
|---|
| 486 | - Regexp: 011([1-9][0-9]{7,}) |
|---|
| 487 | - Discount: 25 |
|---|
| 488 | |
|---|
| 489 | The paranthezis of the Regexp field indicate the E164 number returned by |
|---|
| 490 | the match and discount is a percentage that will be substracted form the |
|---|
| 491 | total price of the call. The formula is described in the PSTN rating |
|---|
| 492 | section. |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | Reloading rating tables |
|---|
| 496 | ----------------------- |
|---|
| 497 | |
|---|
| 498 | The rating engine loads some of the rating tables in the memory, when the |
|---|
| 499 | tables change a reload is needed. Reload of rating tables is possible |
|---|
| 500 | without stopping the daemon by connecting to it and issuing the reload |
|---|
| 501 | command. The init.d script can also be used for reloading the rating engine |
|---|
| 502 | with the current values from the rating database. |
|---|
| 503 | |
|---|
| 504 | There are 3 ways of reloading the rating tables: |
|---|
| 505 | |
|---|
| 506 | a. Each change executed in the WEB interface for rate management may update |
|---|
| 507 | the rating tables. If there is a change made to the database that requires a |
|---|
| 508 | reload the link 'Reload rating tables' appears in red color on web page. |
|---|
| 509 | Click on the link to execute the reload. |
|---|
| 510 | |
|---|
| 511 | b. Telnet to the IP address and port number specified for the Rating engine |
|---|
| 512 | in global.inc. Type help to see the list of commands available. Locate the |
|---|
| 513 | reload rates command and execute it followed by \n. You may see the result |
|---|
| 514 | of the command in syslog. The results displayed by syslog will show how many |
|---|
| 515 | entries have been reloaded from the rating table. |
|---|
| 516 | |
|---|
| 517 | c. Run /etc/init.d/cdrtool reload command |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | Troubleshooting |
|---|
| 521 | --------------- |
|---|
| 522 | |
|---|
| 523 | To examine the rate information for a rated call click on the Id field on |
|---|
| 524 | the leftmost column. (Java script support in browser is required). A blue |
|---|
| 525 | area will open under the CDR line containing more information about the SIP |
|---|
| 526 | session. |
|---|
| 527 | |
|---|
| 528 | If you see no price in the CDR or no rating information appears in the call |
|---|
| 529 | details it means that either no destination was found in the destinations |
|---|
| 530 | table or no rate has been associated with that destination. Make sure that |
|---|
| 531 | for each entry in the destinations table there is a corespondent entry in |
|---|
| 532 | the rates table. CDRTool rating engine can send warning emails if it finds |
|---|
| 533 | missing entries in the rating tables if the system where CDRTool runs is |
|---|
| 534 | properly configured to send emails and the e-mail notification addresses are |
|---|
| 535 | set in global.inc: |
|---|
| 536 | |
|---|
| 537 | $CDRTool['provider']['toEmail'] = "support@example.com"; |
|---|
| 538 | $CDRTool['provider']['bccEmail'] = "cdrtool@example.com"; |
|---|
| 539 | |
|---|
| 540 | To log to syslog about missing rates or incorrect setup of the rating tables |
|---|
| 541 | enable 'reportMissingRates' in $CDRTool['rating'] section of global.inc |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | Renormalizing CDRs and historical rating |
|---|
| 545 | ---------------------------------------- |
|---|
| 546 | |
|---|
| 547 | Sometime is useful to be able to change the rates for calls that have been |
|---|
| 548 | already normalized and rated, for example after changing the rating tables |
|---|
| 549 | you wish to apply the changes for the previous month for a customer. |
|---|
| 550 | |
|---|
| 551 | To re-rate the CDRs do the following: |
|---|
| 552 | |
|---|
| 553 | 1. Change the current rates by using cvs files/WEB interface or add rates |
|---|
| 554 | valid for specific dates/destinations in the rates_history table |
|---|
| 555 | |
|---|
| 556 | 2. Re-normalize the calls to be re-rated by either selecting ReNormalize |
|---|
| 557 | check-box in the search screen or by changing the Normalized field in the |
|---|
| 558 | CDR MySQL table (e.g. radacct): |
|---|
| 559 | |
|---|
| 560 | Examples: |
|---|
| 561 | |
|---|
| 562 | a) Re-rate calls for this month (2004-12) SIP domain example.com: |
|---|
| 563 | UPDATE radacct set Normalized = '0' where Realm = 'example.com' |
|---|
| 564 | and AcctStartTime >= '2004-12-01' |
|---|
| 565 | |
|---|
| 566 | b) Re-rate calls for SIP subscriber sip01@example.com: |
|---|
| 567 | UPDATE radacct set Normalized = '0' where UserName = 'sip01@example.com' |
|---|
| 568 | |
|---|
| 569 | 3. Apply rating again using command: |
|---|
| 570 | |
|---|
| 571 | /var/www/CDRTool/scripts/normalize.php |
|---|
| 572 | |
|---|
| 573 | Notes |
|---|
| 574 | |
|---|
| 575 | Renormalization process can take long time during which your database |
|---|
| 576 | (radacct table) will be intermitently locked. Perform this operation |
|---|
| 577 | only during low traffic periods. |
|---|
| 578 | |
|---|
| 579 | It is advisable to re-rate only the CDRs for destinations that have |
|---|
| 580 | different rates. To do this, select a filter in the CDR search screen, if |
|---|
| 581 | the selection is right re-run the query by selecting Re-normalize button. |
|---|
| 582 | |
|---|
| 583 | After renormalization, the monthly usage information used by the quota |
|---|
| 584 | system will be out of date. At the next run of the quotaCheck script, a full |
|---|
| 585 | table scan will be performed. See QuoatSystem.txt for more information about |
|---|
| 586 | quota. |
|---|
| 587 | |
|---|
| 588 | Holidays must be added as individual days YYYY-MM-DD in table |
|---|
| 589 | billing_holidays. The profile applied for holidays is the same as for |
|---|
| 590 | week-ends. Holidays are global and cannot be specified per customer. |
|---|
| 591 | |
|---|
| 592 | Renormalization process does not affect the balance of prepaid users. |
|---|
| 593 | Prepaid is a real time un-reversible process, it goes in one direction. The |
|---|
| 594 | prepaid balance is changed only by placing a call or adding credit to it. |
|---|
| 595 | There are several reasons for this: |
|---|
| 596 | |
|---|
| 597 | - The balance before and after each CDR is not known to be able to roll it |
|---|
| 598 | back at a later time |
|---|
| 599 | - Re-rating correctly is mathematically not possible for prepaid users that |
|---|
| 600 | have calls in progress |
|---|
| 601 | - If the prices are higher than previously debited and end up with a |
|---|
| 602 | negative balance, the software cannot force the user to pay more |
|---|
| 603 | retroactively |
|---|
| 604 | |
|---|
| 605 | Re-normalization for the purpose of re-rating is useful only for postpaid |
|---|
| 606 | accounts where you send an invoice at the end of the month and your can |
|---|
| 607 | change things back and forth. If you need to perform manual credit/debit |
|---|
| 608 | operations to some prepaid users because of faulty pricing, you can edit in |
|---|
| 609 | CDRTool in the prepaid table the balance by using + or -. |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | Known limitations |
|---|
| 613 | ----------------- |
|---|
| 614 | |
|---|
| 615 | The rating engine does not calculate prices based on the outbound carriers |
|---|
| 616 | or outbound gateways, the rating plan is is assigned by the calling party |
|---|
| 617 | and not by called party. |
|---|
| 618 | |
|---|
| 619 | Price discounts (except those based on ENUM tld) must be applied outside |
|---|
| 620 | CDRTool, in the billing system that prints the actual invoices. CDRTool has |
|---|
| 621 | no possibility to rate only calls after X minutes per month for subscriber |
|---|
| 622 | Y, all calls are rated uniformly. |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | Performance |
|---|
| 626 | ----------- |
|---|
| 627 | |
|---|
| 628 | Rating is part of the normalization process that happens every time a query |
|---|
| 629 | is executed in the web interface or when the rating engine is contacted by |
|---|
| 630 | the SIP Proxy or by the User Agent that performs the prepaid application. |
|---|
| 631 | |
|---|
| 632 | The following tests have been performed between two machines with 3 GHz CPU |
|---|
| 633 | and 1 GB memory located on the same LAN having a round trip time of 0.2 ms. |
|---|
| 634 | |
|---|
| 635 | The rating tables have been populated durring the tests with: |
|---|
| 636 | |
|---|
| 637 | Aug 11 11:25:43 sip03 CDRTool[4945]: Loaded 8135 destinations |
|---|
| 638 | Aug 11 11:25:43 sip03 CDRTool[4945]: Loaded 6 profilesPSTN |
|---|
| 639 | Aug 11 11:25:43 sip03 CDRTool[4945]: Loaded 4 holidays |
|---|
| 640 | Aug 11 11:25:44 sip03 CDRTool[4945]: Loaded 7273 prepaid accounts |
|---|
| 641 | |
|---|
| 642 | Tests results for the postpaid application: |
|---|
| 643 | |
|---|
| 644 | Clients Rating command Execution speed |
|---|
| 645 | ---------------------------------------------------------------- |
|---|
| 646 | 1 ShowPrice 390/s per client |
|---|
| 647 | 5 ShowPrice 100/s per client |
|---|
| 648 | 10 ShowPrice 60/s per client |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | Tests results for the prepaid application |
|---|
| 652 | |
|---|
| 653 | Clients Rating command Execution speed |
|---|
| 654 | ---------------------------------------------------------------- |
|---|
| 655 | 1 MaxSessionTime/DebitBalance 250/s per client |
|---|
| 656 | 5 MaxSessionTime/DebitBalance 80/s per client |
|---|
| 657 | 10 MaxSessionTime/DebitBalance 40/s per client |
|---|
| 658 | |
|---|
| 659 | Client means either a SIP Proxy entity or a CDRTool server, which performs |
|---|
| 660 | the normalization process. |
|---|
| 661 | |
|---|
| 662 | The rates are read directly from MySQL from version 6.1 instead of |
|---|
| 663 | beeing cached as they are found based on a known index. |
|---|
| 664 | |
|---|
| 665 | To monitor the connections to the rating engin server telnet to |
|---|
| 666 | the rating engine port and issse the ShowClients command. Example output: |
|---|
| 667 | |
|---|
| 668 | ShowClients |
|---|
| 669 | |
|---|
| 670 | Clients: |
|---|
| 671 | |
|---|
| 672 | 1. 91.20.228.143:32837 |
|---|
| 673 | 2. 85.1.86.71:57945 |
|---|
| 674 | 3. 91.20.228.146:35098 |
|---|
| 675 | 4. 91.20.228.150:34285 |
|---|
| 676 | 5. 91.20.228.129:55090 |
|---|
| 677 | 6. 91.20.228.164:34147 |
|---|
| 678 | |
|---|
| 679 | Requests: |
|---|
| 680 | |
|---|
| 681 | 12 requests from 91.20.228.129 |
|---|
| 682 | 11 requests from 91.20.228.150 |
|---|
| 683 | 8 requests from 85.11.86.71 |
|---|
| 684 | 2 requests from 91.20.228.164 |
|---|
| 685 | |
|---|
| 686 | Statistics: |
|---|
| 687 | |
|---|
| 688 | Total requests: 33 |
|---|
| 689 | Uptime: 169 seconds |
|---|
| 690 | Load: 0.20/s |
|---|