login | register
Fri 03 of Jul, 2009 [21:13 UTC]

voip-info.org

History

Asterisk RealTime

Created by: utdrmac,Last modification on Sun 09 of Nov, 2008 [21:02 UTC] by seshkanuri

The Asterisk RealTime Architecture


ARA, the Asterisk Realtime Architecture is one of the major new features in Asterisk version 1.2.

Background Information

From docs/README.extconfig


The Asterisk external configuration engine is the result of work by Anthony Minessale II, Mark Spencer and Constantine Filin It is designed to provide a flexible, seamless integration between Asterisk's internal configuration structure and external SQL other databases (maybe even LDAP one day).

External configuration is configured in /etc/asterisk/extconfig.conf allowing you to map any configuration file (static mappings) to be pulled from the database, or to map special runtime entries which permit the dynamic creation of objects, entities, peers, etc. without the necessity of a reload.

Olle explains the world

In the new RealTime architecture, all database specific code is moved to database specific drivers. The channel just calls a generic routine to do database lookup. Much cleaner, simpler and manageable from a coding standpoint.

The database is accessed with three functions:
  • STATIC: This is used to load static configuration when a module is loaded
  • REALTIME: This is used to lookup objects during a call (or another event)
  • UPDATE: This is used to update objects

The database support in the channel is not changed. There are "normal" static peers/users and database peers/users. The static ones, regardless if these are loaded from a text file or a database configuration, are kept in-memory and in the SIP channel we provide them with NAT traversal support and message waiting indication if needed.

The database peers/users are not kept in memory. These are only loaded when we have a call and then deleted, so there's no support for NAT keep-alives (qualify=) or voicemail indications for these peers.
NOTE: If you enable RealTime caching in your sip.conf, Voicemail MWI works and so does 'sip show peers' - see rtcachefriends=yes. The downside to this is that if you change anything in the database, you need to do a 'sip reload' (for major changes) or 'sip prune realtime PEERNAME' (for single peer changes) before they become active.


In laymans terms

In the Stable 1.0.X branch of Asterisk, database storage of configuration files and parameters was done mostly by hardcoding connection and query code directly into the application. The best example of this is in app_voicemail, where you can see MySQL code and PostgreSQL code all meshed with the app_voicemail code.

This method of database retrevial proves to be ugly as all the asterisk code is now crammed with database specific code that is irrelevant to the function of the application at hand. Thus RealTime was developed as a means to remove the code and replace it with a unified (abstracted) database retrevial method.

Terminology/Files


There are 2 methods of using RealTime: ODBC and MySQL. Yes, you can use ODBC to connect to MySQL and many other ODBC supported databases. (Being an avid MySQL user and advocate, I didn't want to bother with ODBC so I wrote the RealTime MySQL driver over the weekend.)


How to configure RealTime - ODBC Method

(This paragraph assumes you have ODBC already running and installed on your box.)
When you start to compile Asterisk, the Makefile inside res/ should detect if you have ODBC properly installed and if so compile the res_config_odbc.so module for you (as long as you have the unixODBC-dev libraries installed - http://sourceforge.net/project/showfiles.php?group_id=1544&package_id=122072).
Go into /etc/asterisk/res_odbc.conf and configure your ODBC connections. Some sample configs are supplied in asterisk/configs/res_odbc.conf.sample NOTE: res_config_odbc.conf is deprecated and will not be loaded.

Skip to 'Extconfig'

How to configure RealTime - MySQL Method

(This page assumes you have the MySQL client libraries/headers installed on your box.)
Check out asterisk-addons from CVS:

cd /usr/src/
svn co http://svn.digium.com/svn/asterisk-addons/trunk asterisk-addons


Go into asterisk-addons and run the following commands


configure
make
make install (This will also compile and install the other stuff in addons so if you don't want/need it, just run 'make' and manually copy res_config_mysql.so to your modules directory.)



Copy asterisk-addons/configs/res_mysql.conf.sample to /etc/asterisk/res_mysql.conf
Edit this file to your liking. At this time, the MySQL drivers supports multiple databases on only one server.

Now edit /etc/asterisk/extconfig.conf


Extconfig - Static Configs

Static configuration is where you can store regular *.conf files into the database. These configurations are read at Asterisk startup/reload. Some modules may also re-read this info upon their own reload (Ex. sip reload).
Here is the format for a static config:

[settings]

<conf filename> => <driver>,<databasename>[,table_name]
queues.conf => odbc,asterisk,ast_config
sip.conf => mysql,asterisk
iax.conf => ldap,MyBaseDN,iax


Above we have 3 examples. The first example will bind 'queues.conf' to the table 'ast_config' located in the database context 'asterisk' using the ODBC driver. — NOTE (LN): this is NOT the database you specified in /etc/odbc.ini, rather it's the context in /etc/asterisk/res_odbc.conf that you are using to connect to the ODBC driver!
The second example will bind 'sip.conf' to the table 'sip.conf' (because we ommited the table name, it defaults to the file name) in the database 'asterisk' using the MySQL driver.
The 3rd one will bind iax.conf to the 'table' iax.conf in the ldap database using LDAP driver; MyBaseDN is the base DN for the query.
Using the above examples, now, when app_queue.so loads, the RealTime ODBC driver will execute a query and get the information it needs. The same is true for chan_sip.so, but with MySQL and chan_iax.so with LDAP.


Extconfig - RealTime

RealTime configuration is where configuration values are read/updated in real time.

Example: Lets say you have 2 SIP users defined in your sip.conf and you want to add a 3rd. You add them to the file then execute the command 'sip reload'. This re-reads your sip.conf and allows the 3rd to register.
With RealTime, all you do is add 1 new record to the table that sipusers has been bound to. No reloading necessary.

RealTime maps take the following fomat:

[settings]

<family name> => <driver>,<database name>[,table_name]
sippeers => mysql,asterisk,sip_peers
sipusers => mysql,asterisk,sip_users
queues => mysql,asterisk,queue_table
queue_members => mysql,asterisk,queue_member_table
meetme => mysql,asterisk,meetme_table
voicemail => mysql,asterisk


Above we have four examples. The first example will bind the family name "sippeers" to the table "sip_peers" in the database "asterisk" using the MySQL driver. The last example will bind the family name "voicemail" to the table "voicemail" (because we ommited the table name, it defaults to the family name) in the database "test" using the MySQL driver.

It is worth noting that sipusers and sippeers may both refer to the same table, if you wish.

NOTE: extconfig.conf is parsed each time you connect to the asterisk CLI.


Now that you have created all the necessary binds, it is time to create the tables. Since the tables are different to each family, I've broken the Wiki pages down to eliminate 1 huge RealTime page. Scroll down to the bottom to find the individual family pages.



:: NOTE: If you are setting up only IAX users (no peers), both iaxusers and iaxpeers entries in the above file need to be either included (uncommented) for iax users/peers to be loaded from the database.


Conclusions

RealTime is great. With a nice web interface you can allow customers limited ability to edit their own dialplan without needing a reload.

RealTime support is currently available for the following families:
  • sippeers
  • sipusers
  • iaxpeers
  • iaxusers
  • voicemail
  • queues and queue_members (used together for the Queue application).
  • extensions NOTE: The family name for RealTime extensions can be whatever you want. Please read Asterisk RealTime Extensions for more info.

More information will be posted as more apps become RealTime enabled.




See Also


Go back to Asterisk

Comments

Comments Filter
222

333asterisk.conf - and lib64 directory

by DrStein99, Monday 30 of June, 2008 [21:54:31 UTC]
If you are using mySQL connector (not odbc) - and you will get error loading:

CLI> MODULE LOAD RES_CONFIG_MYSQL



Then check ASTERISK.CONF

astmoddir => /usr/lib/asterisk/modules

If "res_config_mysql.so" does not exist in that path, then it wont work. Mine was set at "/usr/lib64/asterisk/modules" and this took me about 3 hours to troubleshoot.

-Erich Stein

222

333The question of "missing" mysql engine

by chenyuyen, Wednesday 16 of April, 2008 [06:55:51 UTC]
Hello,
I have the same problem too.
I step by step
./configure --with-mysqlclient=/usr
make menuselect
             unselected the already installed addons 
make
make install

When I enter ./configure --with-mysqlclient=/usr it have some question about haven't mysql_config.
I don't know how to solve this question.
Can anybody peslaehelp me with that??


222

333trixbox static realtime problem

by ahmedm, Tuesday 19 of February, 2008 [12:48:30 UTC]
Hello,
I am a bit new to linux and i don't fully understand some of the explanations in the tutorial.
I installed Trixbox 2.4.0 and i went step by step through the tutorial and the comments but i still didnt get the "static realtime" to work.
The problem is that i dont find a res_mysql.so although there is a res_mysql.conf ,, there is an res_odbc.so but no res_odbc.conf ...
can anybody please help me with that??
222

333

by ahmedm, Tuesday 19 of February, 2008 [12:47:51 UTC]
Hello,
I am a bit new to linux and i don't fully understand some of the explanations in the tutorial.
I installed Trixbox 2.4.0 and i went step by step through the tutorial and the comments but i still didnt get the "static realtime" to work.
The problem is that i dont find a res_mysql.so although there is a res_mysql.conf ,, there is an res_odbc.so but no res_odbc.conf ...
can anybody please help me with that??
222

333realtime problem with trixbox

by ahmedm, Tuesday 19 of February, 2008 [12:47:26 UTC]
Hello,
I I'm a bit new to linux and i don't fully understand some of the explanations in the tutorial.
I installed Trixbox 2.4.0 and i went step by step through the tutorial and the comments but i still didnt get the "static realtime" to work.
The problem is that i dont find a res_mysql.so although there is a res_mysql.conf ,, there is an res_odbc.so but no res_odbc.conf ...
can anybody please help me with that??
222

333Re: Solution for "missing" mysql engine

by mihaylov, Friday 01 of February, 2008 [21:43:25 UTC]
I had simmilar problem but with iaxpeers.
My modules.conf now is:
modules
autoload=yes
preload => res_config_mysql.so
preload => app_addon_sql_mysql.so
........
This solved problem with IAX peers.
222

333

by psm, Wednesday 16 of January, 2008 [15:16:53 UTC]
Erm, K Anderson... what exactly are you recompiling with addons there? I'm now 3 days into trying to make Asterisk and OpenSER talk to each other and I'm actually overloaded. If anybody has a copy of "How to install Asterisk 1.4 with OpenSER 1.3" let me know ;o)
222

333Re: Solution for

by Jemson, Sunday 12 of August, 2007 [05:21:15 UTC]
Thanks K Anderson!!

You have probably saved me at least a weeks worth of frustration also! :)
222

333Solution for "missing" mysql engine.

by kanderson, Saturday 30 of June, 2007 [22:34:25 UTC]
I have been trying to get realtime working on FC6 asterisk 1.2 and 1.4 after installing MySQL with YUM but I get the error message bellow:

WARNING5918: config.c:1059 find_engine: Realtime mapping for 'sippeers' found to engine 'mysql', but the engine is not available

My resolution was to compile the addons using
./configure --with-mysqlclient=/usr
make menuselect
              unselected the already installed addons
make
make install

AND IT WORKS FINALY!!!

This one was a weeks worth of fustration....

222

333

by nrqln, Tuesday 17 of October, 2006 [20:21:48 UTC]
I followed every step to configure RealTime but something is not working properly; the warning I am geting is:

WARNING5918: config.c:1059 find_engine: Realtime mapping for 'sippeers' found to engine 'mysql', but the engine is not available
Oct 17 14:19:12

NOTICE5918: chan_sip.c:13889 handle_request_register: Registration from '<sip:30106@voixtel-presario.homelinux.net;user=phone>' failed for '190.37.241.158' - No matching peer found

Mysql is working properly, I test it using the parameters included in res_mysql.conf.

Is there a way of checking the asterisk conection to the database manually?
How can I check that the driver was installed properly from the addonss?
Any idea, suggestion?

Regars, Enrique Leon