免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2196 | 回复: 0
打印 上一主题 下一主题

Asterisk RealTime [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-16 16:33 |只看该作者 |倒序浏览
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]
=> ,[,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]
=> ,[,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.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/101299/showart_2029249.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP