LCR tool for i4l

Least Cost Routing

Tools for i4l, asterisk and others

Asterisk addon rate-engine

From Voop (previously Trollphone) comes the Rate-engine to allow smart LCR routing. For more info, see link above

Meta-ENUM lookup for combined Call and LCR routing

This website aggregates ENUM information from different sources and mixes them up with Call-by-Call LCR data from the german market. You may interface to this service by ENUM itself. An AGI script for Dialplan integration is provided.
The website is in german language only.

Asterisk LCR Routing for Germany

As of 2005-04-11, this site is updated hourly from the providers' web pages. It has an LCR tool for Asterisk (go to "LCR Download") which works very well and includes hour-by-hour tariff variations.

Note: It appears that chan_capi 0.3.5 does not differentiate between provider busy ("Gassenbesetzt") and enduser busy, which makes the Asterisk dialplan a bit uncomfortable in this respect; zaphfc (bristuff) on the other hand appears to handly this issue very well.

rates4linux web site

The rates file is not as up-to-date as one could hope.
xdial.de has more accurate information, although it updated only weekly. Now, all we need is a programm transferring the information xdial provides into a database readable form. And a way to automatically receive updates from xdial. Anyone?!

Taken from the i4l FAQ:

Yes, this feature is now being supported by isdnlog. What it does is that it allows isdnlog to choose your telephone provider when placing a call through your ISDN card, depending on the time of day and the current rate information. Since isdnlog 4.16 an external script is called (if configured) to change various ISP settings (e.g. DNS lookup, proxy setup,...).

Note: the ABC-extensions (s. docu_abc) must be installed. Also, isdnlog should always be running (otherwise your dialout will be delayed by 3 seconds). If the ABC-extensions are not installed, isdnlog prints hints to the log file, which provider would have been chosen.

More tips:

Get isdn4k-utils from isdn4linux.de; don't worry, you don't actually need to have ISDN, we just need the isdnrate utility for finding the best provider. The "stable" versions won't work, so get some CVS snapshot instead.

Get recent provider data from ** rates4linux.sourceforge.net **. Fix /etc/isdn/rates.conf to list the providers of your choice.


Here is what I've done to make my asterisk* act as a LCR. First, you'll have to install isdnrate (part of isdnutils) and get a recent rate-??.dat (check rates4linux.sourceforge.net for that.)

to test isdnrate just try the following command:

isdnrate -o -b3 -l60 *any_number_you_want_to_test*

the -o tells isdnrate to only use provides activated in /etc/isdn/rate.conf (e.g. if you have some preselection providers or tisdn-xxl) -b3 is for the best 3 providers -l60 says call duration 60 seconds (the default-value I also used in my AGI is 153 secs. so if you want to use annother duration please change the commandline in the agi)

then I wrote a very little (and simple) AGI.


  1. !/usr/bin/perl
while(<STDIN>) {
last unless length($_);
if (/^agi_(\w+)\:\s+(.*)$/) {
$AGI{$1} = $2;

$number = $ARGV[0];
$length = 60;

$raw = `/usr/bin/isdnrate -o -b1 -L -l$length $number`;
$raw =~ /([0-9]*)_.;(.*?);/;
$prefix = $1;
$provider = $2;

print "VERBOSE \"Using LCR Provider $provider - $prefix!\"\n";
$result = <STDIN>;

print "SET VARIABLE LCR $prefix\n";
$result = <STDIN>;

as you can see, my AGI just sets a variable called LCR. here is how I use it in my dialplan:

exten => _0.,1,Answer
exten => _0.,2,DigitTimeout,5 ; Set Digit Timeout to 5 seconds
exten => _0.,3,ResponseTimeout,10 ; Set Response Timeout to 10 seconds
exten => _0.,4,agi,/lcr.agi|${EXTEN:${TRUNKMSD}}
exten => _0.,5,Dial,CAPI/@6294096:b${LCR}${EXTEN:${TRUNKMSD}}|60|T

I know that this is all very simple - and maybe there are some errors in my setup but I just wanted to share my expirence with you.

... thorsten aka FastJack

I've just changed my LCR.agi script so it uses 3 CBC-provides so it can fallback to the next most least one in case the other is to busy or not working anyway. I'm using it at home and I hope it may work for others, too.

Here is the new script:

  1. !/usr/bin/perl
while(<STDIN>) {
last unless length($_);
if (/^agi_(\w+)\:\s+(.*)$/) {
$AGI{$1} = $2;

$number = $ARGV[0];
$length = 60;

$x = 1;
foreach (`/usr/bin/isdnrate -o -b3 -L -l$length $number`) {
$_ =~ /([0-9]*)_.;(.*?);/;
$prefix = $1;
$provider = $2;
print "VERBOSE \"Using LCR Provider($x) $provider - $prefix!\"\n";
$result = <STDIN>;

print "SET VARIABLE LCR$x $prefix\n";
$result = <STDIN>;

and here is a sample how to use it in your extensions.conf

; LCR for outgoing calls
exten => _0.,1,AGI,lcr.agi|${EXTEN:${TRUNKMSD}}
exten => _0.,2,Dial,CAPI/${CALLERIDNUM}:${LCR1}${EXTEN:${TRUNKMSD}}|60|T
exten => _0.,3,Dial,CAPI/${CALLERIDNUM}:${LCR2}${EXTEN:${TRUNKMSD}}|60|T
exten => _0.,4,Dial,CAPI/${CALLERIDNUM}:${LCR3}${EXTEN:${TRUNKMSD}}|60|T
exten => _0.,5,Congestion

you see, we now have 3 vars (LCR1-3) and can use them in our dialplan.

Note: After reinstalling my asterisk-machine and trying to use my own scripts from this page I had to find out, that the wikki didn't display the '[' and ']'. But I hope this is fixed now!!

... bye
thorsten aka FastJack

Additional info in German

Linux Magazin

Der Least Cost Router (LCR) Isdnrate ist Bestandteil von Isdn4linux. Damit der LCR korrekte Daten liefert, ist es wichtig, dass das ISDN-System korrekt konfiguriert ist. Vor allem muss in /etc/isdn/isdn.conf unter AREACODE die eigene Vorwahl eingetragen sein. Ob der LCR korrekt konfiguriert ist, lsst sich feststellen:

isdnrate -b 0 -H 04181
Eine 153 Sekunden lange Verbindung von +49 40/ Hamburg
nach +49 4181/ Buchholz kostet am Mon Jan 22 10:18:46 2001

Hierbei sollte statt Hamburg der Ort angezeigt werden, in dem sich das Gateway befindet. Ist der LCR richtig konfiguriert, kann er als Daemon gestartet werden:

isdnrate -D2

Wenn der Daemon korrekt l�uft, funktioniert folgender Befehl ohne Probleme:

isdnrate -C -b 1 04181 01013_1:Tele 2 Preselection DEM 0.153


9. Least Cost Router
9.1. Einf�hrung in die Theorie

Ein W�hlvorgang wird vom ISDN Treiber normalerweise direkt erledigt. Durch aktivieren des Least Cost Routers wird dieses verhindert. Bei Ausl�sung eines Wahlvorganges �bergibt der ISDN Treiber die anzurufende Telefonnumer an den ISDNLOG weiter. Der ISDNLOG sucht nun wiederum in einer Providerdatenbank nach dem zu diesem Ziel (Unter einbeziehung der Uhrzeit) preiswertesten Telefon netzanbieter. Wird er fandig baut er die Rufnummer um inklusive der Providervorwahl und gibt diese Telefonnummer an den ISDN Treiber zur�ck, der dann wiederum diese neue Telefonnummer anw�hlt. Sicherheitshalber wurde das Zeitfenster, welches der ISDNLOG zum suchen eines Providers hat auf 3 Sekunden beschr�nkt. Das hei�t sollte der ISDNLOG crashen oder die Information nicht schnellgenug zur�ckliefern so w�hlt der ISDN Treiber von sich aus die urspr�ngliche Rufnummer.

9.2 Konfiguration des ISDNLOG f�r LCR Support

Zur Zeit ist der LCR Support im Kernel ISDN-Treiber implementiert,
die eigentliche Arbeit im ISDNLOG ist noch nicht abgeschlo�en, daher
ist dieses Feature zur Zeit noch nicht benutzbar.

See also

Go back to Asterisk

Created by: JustRumours, Last modification: Sun 01 of Jan, 2006 (19:39 UTC) by rkarlsba
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+