Call rating
This application serves rate_req
AMQP requests.
Rates are stored in a system-wide “ratedeck” database.
Each rate is a separate document:
{
"_id": "f36cac061205f7a0f7fde6b4d3370bf9",
"_rev": "1-1b67fb507c69c35200178a9b1e0e6cfc",
"routes": [
"^\\+1[0-9]+$"
],
"weight": "1",
"rate_name": "outbound_US_1",
"pvt_type": "rate",
"prefix": "1",
"rate_cost": "1.27",
"ratedeck_name": "ratedeck_1",
"iso_country_code": "US",
"description": "USA prefix 1",
"direction": [
"outbound"
],
"rate_increment": "60",
"rate_minimum": "60",
"rate_nocharge_time": "0",
"options": [
"Opt1",
"Opt2"
]
}
Schema for these rate documents is described in the rates reference doc.
System Configuration
Key | Description | Type | Default |
---|---|---|---|
default_rate_cost | Cost used when rate_cost is not defined in rate | float | 0.0 |
default_rate_increment | Increment call duration when rate_increment is not defined in rate | integer | 60 |
default_rate_minimum | Minimum call duration when rate_minimum is not defined in rate | integer | 60 |
default_rate_nocharge_time | No charge time when rate_nocharge_time is not defined in rate | integer | 0 |
default_rate_surcharge | Surcharge used when rate_surcharge is not defined in rate | float | 0.0 |
filter_list.[] | string | ||
filter_list | List additional filters (after prefix match) | array(string) | ["direction", "route_options", "routes", "caller_id_numbers"] |
sort_by_weight | Sort matched filters by weight (true ) or by rate_cost (false ) | boolean | true |
use_trie | Use in-memory prefix dictionary for search rates | boolean | false |
Using the Trie
Rate lookups, by default, will use the CouchDB view rates/lookup
and a list of prefixes generated by the dialed number to find any matching rates in the database. This is generally “fast enough” for most purposes. However, if the cluster is doing a lot of rate lookups, it may make sense to preload the rate table into memory for fast lookups. For reference, the trie implementation was ~128x faster in testing.
Starting the ‘hon_trie’ process will result in increased memory usage (~115 bytes per prefix in the database) on the VMs running hotornot. It would be advisable, if you have large ratedecks, to run a VM with just hotornot running to ensure memory is allocated properly.
To enable the trie, update the system_config
: sup kapps_config set_default hotornot use_trie true
and restart any VMs running hotornot: sup kapps_controller restart_app hotornot
Enabling the Trie
Enable the trie by setting use_trie
to true
in the system_config/hotornot
document:
sup kapps_config set_boolean hotornot use_trie true
Filters
filter_list
option is used to define additional filters when matching rates.
direction
If direction
filter defined in filter_list
then “Direction” value from rate request compared with direction
value in rates. Undefined value in rate means “match any direction”.
route_options
If route_options
filter defined in filter_list
then “Options”, “Outbound-Flags” and resource ID from rate request compared with options
value in rates. Rate matched when all flags in “Options”, “Outbound-Flags” and resource ID exist in options
list in rate. Empty or undefined options
list in rate means “match any route options”.
routes
If routes
filter defined in filter_list
then “To-DID” from rate request compared with list of regexps in routes
value of rates. Rate matched if any of regexps matched. Empty regexps list or undefined value in rate means “match nobody” and this rate will never be used.
caller_id_numbers
If caller_id_numbers
filter defined in filter_list
then “From-DID” from rate request compared with list of regexps in caller_id_numbers
value of rates. Rate matched if any of regexps matched. Undefined regexps list value in rate means “match all”.
ratedeck_name
If ratedeck_name
filter defined in filter_list
then ratedeck assigned to account compared with ratedeck_name
value of rates. Ratedeck name assigned to account via service plan. If rate request doesn’t have “Account-ID” or account doesn’t have ratedeck name in their service plan, then it match rates with undefined ratedeck_name
value.
reseller
If the reseller
filter is defined in filter_list
, then the reseller’s account ID is compared with the account_id
value of the rates. If rate request doesn’t have “Account-ID” then it matches rates with undefined account_id
value.
version
If version
filter defined in filter_list
then rate_version
from system_config/hotornot
compared with rate_version
value of rates.