login | register
Fri 05 of Sep, 2008 [23:43 UTC]

voip-info.org

History

Application LCDial

Created by: wuwu,Last modification on Mon 04 of Aug, 2008 [10:48 UTC] by mesfet

Application LCDial() - Least Cost Dial

Synopsis

Does a mysql Database lookup to find the cheapest Provider for a given destination number, and than it invokes the dial command. If the channel is unavailable then it will fall back to the next configured Provider.

Description

  • LCDial(number to dial,timeout,options,URL) — dial one channel

Parameters:

  • number to dial specifes the number which should get dial.
  • all other options are the same as within the standard Asterisk cmd dial command (the are directly passed to the dial comand)

Return codes

Behaves exactly like Asterisk cmd dial

Example:
exten => 4000,1,LCDial(${EXTEN},15)

mysql Database Layout

tabledescription
providerInformations about each Provider (name,id,dialstr,status)
providerdestinationWhich destinations (countryprefixid) are available with which provider
providerrateThe tariffrate for the given provider / destination
countryprefixTable with dial codes
countryoptional - not really needed - but if you want to have nice names for the countries



CREATE TABLE `countryprefix` (
 `countryprefixid` int(11) NOT NULL auto_increment,
 `prefix` text NOT NULL,
 `countrycode` char(3) default NULL,
 `subcode` varchar(10) NOT NULL default '',
 PRIMARY KEY  (`countryprefixid`)
) TYPE=MyISAM;

CREATE TABLE `provider` (
 `providerid` int(11) NOT NULL auto_increment,
 `providername` text NOT NULL,
 `dialstr` varchar(200) NOT NULL default '',
 `status` tinyint(3) unsigned NOT NULL default '0',
 PRIMARY KEY  (`providerid`)
) TYPE=MyISAM;

CREATE TABLE `providerdestination` (
 `providerdestinationid` int(11) NOT NULL auto_increment,
 `countryprefixid` int(11) NOT NULL default '0',
 `providerid` int(11) NOT NULL default '0',
 PRIMARY KEY  (`providerdestinationid`)
) TYPE=MyISAM;

CREATE TABLE `providerrate` (
 `providerrateid` int(11) NOT NULL auto_increment,
 `providerid` int(11) NOT NULL default '0',
 `countryprefixid` int(11) NOT NULL default '0',
 `rate` double NOT NULL default '0',
 PRIMARY KEY  (`providerrateid`)
) TYPE=MyISAM;

CREATE TABLE `country` (
 `countrycode` char(3) default NULL,
 `countryname` text NOT NULL,
 `countryid` int(11) default NULL
) TYPE=MyISAM;


Configuration

LCDial needs a configuration file called lcdial.conf in the standard asterisk configuration directory.
Example Configuration:

global
hostname=localhost
dbname=asterisk
user=asterisk
password=asterisk
port=3306

sql
getproviders=SELECT providerrate.rate, dialstr, countryprefix.countryprefixid, provider.providerid, provider.providername FROM countryprefix LEFT JOIN providerdestination USING ( countryprefixid ) LEFT JOIN provider USING ( providerid ) LEFT JOIN providerrate ON concat( provider.providerid, countryprefix.countryprefixid ) = concat( providerrate.providerid, providerrate.countryprefixid ) WHERE prefix = substring( '%s', 1, length( prefix ) ) AND provider.status=0 ORDER BY length( prefix ) DESC , providerrate.rate ASC


Get it

Here <- Here you will find the new version which is now based on MysqlPool - please take a look at the documentation.

Compile It

It assumes that the asterisk sources can be found at /usr/src/asterisk, that the asterisk modules directory is at /usr/lib/asterisk/modules and that the asterisk configuration is at /etc/asterisk/.
For compiling it you need to have already installed asterisk ;-) - and the mysql client libary and header files.
From asterisk stable to asterisk cvs head the channel structure has changed a little bit - so if you want to compile against asterisk stable then you have to comment this "CFLAGS+=-DUSE_CVS" line to get it to compile (else you would get an error like "error: structure has no member named `cid'"

Help

If you are having trouble getting the application up and running and need professional help, feel free to drop us a line at support@yosd.at

Management Interface

If you are looking for a management frontend or a turn-key-solution please get in touch with us: support@yosd.at



A modified version of LCDial() which uses REGEXP prefix and only 2 simple tables

Description

LCDial is very powerful and versatile solution for least cost routing, because it get information about routing from database using only one SQL statement which is defined in lcdial.conf configuration file.
I've modified the original SQL query to use only two tables:
  • lcdial_providers, within the provider name, dial string, and a flag to enable/disable it
  • lcdial_rates, within the regexp prefix, provider name, rate, and a comment
In this way is very very simple to compile the LCR database by hand, using phpmyadmin or other tool: you can compile a complete lcdial_rates table with several provider costs, and enable only the providers you want into lcdial_providers table.
lcdial_providers table structure/example
id provider dialstr enabled
1fastwebZap/g1/%s|401
2freevoipIAX2/freevoip/%s|200
3wind-leonardoSIP/%s@100|401
4voipvoiceIAX2/voipvoicenumber/%s|401

lcdial_rates table structure/example
prefixproviderratenote
^005521freevoip0.03brazil rio de janeiro
^32.......wind-leonardo0wind cellulars
^3[3469].......wind-leonardo0.06italian cellulars (not wind)


When LCDial(number,options) is called, the LCDial application perform a regular expression search into lcdial_rates, and order all records by expression length, taking only one record per provider, then sort by cost.
In this way I can, for example, add records like
^00393[234689] to match italian cellular phones
^0039 to match all italian phones but not italian cellulars, because they will match the previous rule

Download LCDial application


Support for LCDial application

This is free software and only limited support is provided for it by email to psubiaco@creasol.it
If you add rates information to the provided database, please send the modification to psubiaco@creasol.it so they will be added to the lcdial-psubiaco.tgz archive.



See also


Asterisk | Asterisk cmd dial

Comments

Comments Filter
222

333very wrong code

by Dringme, Saturday 10 of June, 2006 [02:17:28 UTC]
  1. 1 the sql command in the distro is bad.. talks about tarrif's instead of providers.

then #2..

un 9 22:11:40 DEBUG58317 config.c: Parsing /usr/local/etc/asterisk/lcdial.conf
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: got hostname of localhost
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: got port of 3306
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: got user of bob
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: got dbname of cdr
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: got password of SOMETHINGSECRETIWOTPOSTHERE
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: got getproviders query of 'somecustomized SQL string'
Jun 9 22:11:40 WARNING58317 app_lcdial.c: LCDIAL using database 'cdr'.
Jun 9 22:11:40 DEBUG58317 app_lcdial.c: LCDial: Successfully connected to database 'cdr@localhost'.


right ?

WRONG.. LCD still tryed asterisk DB..

check this log.


Jun  9 22:16:24 DEBUG58317 app_lcdial.c: LCDial:  FATAL DB ERROR AT QUERY: SELECT THISISJUSTTHESQLSTRING - 
(Table 'asterisk.cdr' doesn't exist)


NOW.. WHY it tries asterisk DB is out of hands.. the defaults have been changed.. no where in code i see reference to it.. it still does..


222

333

by Dringme, Friday 09 of June, 2006 [21:29:27 UTC]
222

333Re: No time-based tarriffs

by NetSyncro, Saturday 03 of June, 2006 [18:05:01 UTC]
I've got complete and 95% production ready patches for this if anyone is running PostgreSQL :) I'm also willing to tweak for those who need time-based and or other features/more performance. cbergstrom {åt] netsyncro döt com
222

333How to deal with LCDial not finding a provider

by gafana, Saturday 11 of March, 2006 [23:48:00 UTC]
In the event a number is dialed and LCDial cannot find a provider, it skips to n+101. However, there is no direct info indicating the problem (DIALSTATUS is always blank in this case). Here is a little snippet that will set DIALSTATUS to "NOPROVIDER" if the call fails because LCDial could not find a provider:

exten => s,s+101,Set(DIALSTATUS=${IF($ ${ISNULL(${DIALSTATUS})}=1 ?"NOPROVIDER":${DIALSTATUS})})


222

333Compiling on Fedora Core 4

by digi, Friday 13 of January, 2006 [13:30:33 UTC]
Just a note when compiling LCDial on FC4 you will need to move the line #include <stdio.h> to be the first include above #include <asterisk/lock.h> in the filename app_lcdial.c file otherwise LCDial will not compile.
222

333Compiling on Fedora Core 4

by digi, Friday 13 of January, 2006 [13:29:42 UTC]
Just a note when compiling LCDial on FC4 you will need to move the line #include <stdio.h> to be the first include above #include <asterisk/lock.h> in the filename app_lcdial.c file otherwise LCDial will not compile.
222

333No time-based tarriffs

by smurfix, Saturday 09 of April, 2005 [14:13:59 UTC]
In Germany, "which provider is cheapest" changes, depending on which day it is (or even time-of-day).

Unfortunately this tool can't process this.