Least Cost Routing A
From Etel
Contents |
[edit]
Title
Least Cost Routing
[edit]
Problem
You have several different VoIP providers, each with a table of data specifying their rates and you want to select the provider with the lowest cost for each call.
[edit]
Solution
First, we'll need a database table in which to store the rate settings. Note that you'll want to repeat this table layout for each provider you're using.
CREATE TABLE providerA ( prefix CHAR(30), rate DECIMAL(10,6), stamp timestamp, PRIMARY KEY (prefix) );
Now we build a dialplan function to query this table. Again, repeat this for each provider you'll provision.
func_odbc:
[PROVIDER_A]
dsn=mysql-asterisk
read=SELECT rate FROM providerA WHERE prefix LIKE CONCAT('${ARG1}', '%') ORDER BY LEN(prefix) DESC LIMIT 1
Finally, you'll query the providers from your dialplan:
extensions.conf:
[incoming]
exten => _1-NXX-NXX-XXXX,1,Set(providerlist=${SORT(providerA:${ODBC_PROVIDER_A(${EXTEN}},providerB:${ODBC_PROVIDER_B(${EXTEN})})})
exten => _1-NXX-NXX-XXXX,n,Gosub(${CUT(providerlist,\,,1)})
exten => _1-NXX-NXX-XXXX,n,GotoIf($[${DIALSTATUS} = BUSY]?busy:congestion)
exten => _1-NXX-NXX-XXXX,n(busy),Busy
exten => _1-NXX-NXX-XXXX,n(congestion),Congestion
exten => _1-NXX-NXX-XXXX,n(providerA),Dial(SIP/${EXTEN}@providerA)
exten => _1-NXX-NXX-XXXX,n,Return
exten => _1-NXX-NXX-XXXX,n(providerB),Dial(IAX2/providerB/${EXTEN})
exten => _1-NXX-NXX-XXXX,n,Return
[edit]
Discussion
[edit]
See Also
[edit]
Metadata
- By: TilghmanLesher
