login | register
Wed 09 of Jul, 2008 [04:41 UTC]

voip-info.org

Discuss [11] History

Asterisk RealTime Sip

Created by: utdrmac,Last modification on Tue 13 of May, 2008 [14:14 UTC] by arf_

Asterisk RealTime SIP


sip.conf Setup

You can keep any sip users in the flatfile AND use RealTime. How cool is that?

Extconfig.conf Setup

Add the following line, swapping your own personal values if you wish:


sipusers => mysql,asterisk,sip_buddies
sippeers => mysql,asterisk,sip_buddies
(note: If you were using sipbuddies, add an exact copy of your sipbuddies line. Change one of them to sipusers and the other to sippeers, that is all ther is to change to the new format.)


You can change mysql to odbc if you want to use odbc (don't forget to compile the asterisk-addons package for MySQL support!).
You can change asterisk to be the name of your database.
You can change sip_buddies to be the name of the sip table we will create below.

Note: regseconds is the time the peer was registered PLUS the expiration time. It is placed in the table as unix time.

Database Config

put the following in res_mysql.conf

[general]
dbhost = 127.0.0.1
dbname = asterisk
dbuser = myuser
dbpass = mypass
dbport = 3306

Values in sip.conf or iax.conf like in older versions of * are no longer used.


Database Table

Lets create the table we need:

NOTE: You can use any table name you wish, just make sure the table name matches what you have the family name bound to.

NOTE: General principles: the column names in your database table correspond to the option names in sip.conf. You do not have to have all option names defined in your table; you only have to define those columns you actually use in sip.conf. Exceptions to this are 'regserver' and 'regseconds', which the channel driver's realtime routines use for internal book-keeping. The 'name' field must also be present to hold equivalent of the category name in the sip.conf file. It is easily possible that different versions of Asterisk will require different tables. For instance, a 1.6 version of Asterisk would not use the "cancallforward", or 'restrictcid', or 'mask', or 'qualify', or "musiconhold" columns, but might require 'mohinterpret', 'mohsuggest', etc. etc. options instead. Options (column names) that not offered in sip.conf are ignored. Some options in sip.conf are OK to have multiple entries, but in a real-time database, Only one column is available. In these cases, you can add multiple values separated by semicolons. This occurs with setvar, allow/disallow, and permit/deny. One more point: in allow/disallow and permit/deny, the order of these statements is crucial in the config file, as they are applied in order. In the realtime db, the order is determined by the order of the columns in the table. You will note that the deny/disallow entries come before the allow/permit entries, to support the common usage of 'deny all', then permit '192.168.....'.



#
# Table structure for table `sip_buddies`
#

CREATE TABLE `sip_buddies` (
 `id` int(11) NOT NULL auto_increment,
 `name` varchar(80) NOT NULL default '',
 `host` varchar(31) NOT NULL default '',
 `nat` varchar(5) NOT NULL default 'no',
 `type` enum('user','peer','friend') NOT NULL default 'friend',
 `accountcode` varchar(20) default NULL,
 `amaflags` varchar(13) default NULL,
 `call-limit` smallint(5) unsigned default NULL,
 `callgroup` varchar(10) default NULL,
 `callerid` varchar(80) default NULL,
 `cancallforward` char(3) default 'yes',
 `canreinvite` char(3) default 'yes',
 `context` varchar(80) default NULL,
 `defaultip` varchar(15) default NULL,
 `dtmfmode` varchar(7) default NULL,
 `fromuser` varchar(80) default NULL,
 `fromdomain` varchar(80) default NULL,
 `insecure` varchar(4) default NULL,
 `language` char(2) default NULL,
 `mailbox` varchar(50) default NULL,
 `md5secret` varchar(80) default NULL,
 `deny` varchar(95) default NULL,
 `permit` varchar(95) default NULL,
 `mask` varchar(95) default NULL,
 `musiconhold` varchar(100) default NULL,
 `pickupgroup` varchar(10) default NULL,
 `qualify` char(3) default NULL,
 `regexten` varchar(80) default NULL,
 `restrictcid` char(3) default NULL,
 `rtptimeout` char(3) default NULL,
 `rtpholdtimeout` char(3) default NULL,
 `secret` varchar(80) default NULL,
 `setvar` varchar(100) default NULL,
 `disallow` varchar(100) default 'all',
 `allow` varchar(100) default 'g729;ilbc;gsm;ulaw;alaw',
 `fullcontact` varchar(80) NOT NULL default '',
 `ipaddr` varchar(15) NOT NULL default '',
 `port` smallint(5) unsigned NOT NULL default '0',
 `regserver` varchar(100) default NULL,
 `regseconds` int(11) NOT NULL default '0',
 `username` varchar(80) NOT NULL default '',
 `defaultuser` varchar(80) NOT NULL default '',
 `subscribecontext` varchar(80) default NULL,
 PRIMARY KEY  (`id`),
 UNIQUE KEY `name` (`name`),
 KEY `name_2` (`name`)
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;


May 14/08 arf_
Added 'subscribecontext' to the above as it's may be needed in some case (and it works a least with asterisk 1.4.18)

Apr 15/08 bcnit
Added 'defaultuser' to the above as it's needed in Asterisk 1.6.

Jul 9/07 bcnit
Note that 'regserver' has been added to the above this doesn't appear to be used by anything other than the initial call RealTime makes to clear the record, but including it gets rid of a WARNING on the console!

Jun 8/07 bcnit
If you are going to access the table above using MS Access and MyODBC, define port as:

 `port` mediumint(8) unsigned NOT NULL default '0'

Or you'll have all sorts of problems trying to update rows!

Jan 4/06 mhaynes
I ran into problems using the Message Waiting Indicator with my Cisco 7960g phone using the realtime system under Asterisk 1.2.0. Turns out you need to set the rtcachefriends=yes in the general context of your flat file sip.conf. Once this is done, MWI starts working as usual.

Nov 9/05 hfwang
Note: It seems that since asterisk 1.0.2RC1 there is 1 additional field for SIP accounts called 'fullcontact'. Added this field in the table above.

Updated by: DHuang

(3/16/05) Updated by: utdrmac - incominglimit and outgoinglimit are deprecated. Use Asterisk cmd SetGroup instead.

Jan 2/06 misak
Added setvar column


NOTE: The index created on the column 'name' is because RealTime does its SELECT query using that column everytime. That column must also be unique.

You do not need every column listed above. If you wish, you can remove those columns you know you will never use. The columns in your tables should line up with the fields you would specify in the given entity declaration. If an entry would appear more than once, in the column it should be separated by a semicolon. For example, an entity that looks like:

[foo]
host=dynamic
secret=bar
context=default
allow=gsm
allow=ulaw


could be stored in a table like this:


namehostsecretcontextipaddrportallow
foodynamicbardefault127.0.0.14569gsm;ulaw




You do not need to insert the ipaddr, port or regseconds information. These columns will be updated periodicaly by RealTime.




Testing


Throw some data into the above table and try to register an extension. The /var/log/asterisk/debug should give info on any problems.

Realtime Caching...

As of CVS-HEAD 3/16/05, if you enable RealTime caching in your sip.conf, Voicemail MWI works and so does 'sip show peers'. To do so, add "rtcachefriends=yes" to the general section of your sip.conf file.

As the name implies, this caches the "RealTime" information from the database. As a result, there is a delay in updating some (if not all) fields in the SIP entry when you update the database. For instance, if you create an entry with a context = "context1" and Asterisk loads it from the database (perhaps the phone registered or tried to make a call), Asterisk holds on to that information as far as I can tell, indefinitely until a sip reload occurs.

This also means that you will have to do a sip reload to clear out any entries. Removing them from the database does not seem to work. You can still add new entries though without reloading Asterisk.

RealTime caching...isn't that an oxymoron anyways? :-) — (Someone check to see if this affects IAX too, I don't have any IAX phones at the moment. - Flobi) — (RealTime caching does affect IAX as well, works the same way. - Josh)

Update : use "sip prune realtime PEERNAME" then "sip show peer PEERNAME load" to flush the peer and reload from db - (Voicemeup)




See Also


Comments

Comments Filter
222

333Re: Asterisk as a SIP user agent to a SIP proxy

by glennfrazier, Wednesday 23 of January, 2008 [20:37:17 UTC]
Panos,

I'm doing the same type of setup as you and am having the same type of problem.

Did you ever figure out how to add the sip proxy settings into the mysql database?


222

333Realtime

by bossrunner1, Monday 12 of November, 2007 [19:25:35 UTC]
Hi All,
I have my database connected to asterisk and this is working but the extensions and sip peers dont get added in realtime.. Does anyone have a working copy of the relevant files or canhelp me out?

The command at the CLI - "realtime mysql status" showed the database was connected plus i can make a query and it works..
i..e realtime load sippeers name Fred

The database is working but cannot get anything else to happen. Nothing is added from the database to the extensions or sippeers when i do : show sip peers

Be great to get a little guidance here.

Many Thanks in advance
222

333Asterisk as a SIP user agent to a SIP proxy

by panpan, Saturday 03 of February, 2007 [03:02:07 UTC]
Hello

I have managed to register users at my asterisk. But my asterisk is a sip user agent to a sip proxy. The classic way to register users was to add a line at sip.conf that looks like that register => mynumber@sipproxy/mynumber . But how can i do something like that using mysql-realtime? Please help..
222

333Engine is not available warning

by nrqln, Thursday 19 of October, 2006 [11:49:03 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

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 ideas, suggestions are very much welcome..!!

Regars, Leon
222

333Re: Cant register SIP phone

by amethystw, Monday 29 of May, 2006 [08:43:05 UTC]
just to prove if you have configured successed, pls just use your added data to register asterisk,certainly you also can use it to complete a dial.
According my result, although successful, sip show peers also doesn't work.


222

333No sound on phone from SQL till canreinvite=no

by xsilver, Friday 26 of May, 2006 [14:47:56 UTC]
I run 1.2.7.1 and 1.2.2 addons and finaly found this howto working properly (thanx guys!).
But I can't hear any sound on station configured from sql until canreinvite in sql config is set to 'no'. Even if that is not necessary when station was configured in flat file sip.conf.

2>limleechin
for realtime try to use in step 2 this:
sipusers => mysql,asterisk,sip_conf
sippeers => mysql,asterisk,sip_conf

your sintax is for static config from sql (if I remeber that correctly)
and sip.conf is used with realtime together so you can hav config of phone in both (sql and flatfile), but it looks that flatfile is preferred and used if you have same records on both places
222

333Cant register SIP phone

by sllc, Thursday 05 of January, 2006 [07:25:15 UTC]
I followed the steps above, but after I restart asterisk, all my sip phone is not registered.
Below are the steps I had done.

(1) Make, make install asterisk-addons then copy res_mysql.conf.sample to res_mysql.conf and edit the res_mysql.conf with my databases parameter
(2) Edit extconfig.conf ---add
sip.conf => mysql,asterisk,sipfriends
(3) Create a sipfriends table in asterisk database and register some sip phone into the table
(4) then restart asterisk...

But no sip phone is register when i run CLI>sip show peers

When I comment the sip.conf=>mysql,asterisk,sipfriends line in extconfig.conf then i can see the sip phone is register....any ideas??thanks.
222

333Change the amaflags row

by mati, Monday 12 of December, 2005 [14:20:45 UTC]
You have to change the amaflag row to:
amaflags` varchar(13) default NULL,

to store values like "documentation" in it.
222

3331.2.0-beta2

by tod_detre, Tuesday 01 of November, 2005 [21:23:09 UTC]
I ran into a problem with 1.2-beta2 with using realtime sip. It looks
like chan_sip.c has a new field called fullcontact. I had to add this column
to my database as a VARCHAR(128) to get it working.
222

333Allow and Disallow columns

by , Thursday 16 of December, 2004 [07:37:04 UTC]
The order of the Allow and Disallow columns in the table DOES matter as in the sip.conf