Kamailio Advanced Training
Click here for more details!

Learn how to build RTC services with Kamailio!

Thursday, April 29, 2010

Kamailio 3.0.x - DYK-08 - udp mtu

Fallback to other transport protocol based on UDP

See also: Kamailio 3.0.x - DYK - Table of Content

Kamailio 3.0.0 offers several options to control the outgoing transport protocol based on MTU of UDP packets.

Although the RFC3261 requires to use TCP (or TLS or SCTP) if the size of UDP payload exceeds 1300 bytes, this may bring some issues with SIP UA not supporting something else than UDP. Following the high-flexibility policy with the SER and Kamailio applications, this setting is customizable as global parameter or per SIP request.

Here are the parameters if you want to control globally:
  • pmtu_discovery - set the bit for non-fragmentation to outbound packets, to enforce MTU if needed
  • udp_mtu - the size in bytes when to switch to the fallback protocol if exceeded
  • udp_mtu_try_proto - set the new transport protocol to be used if udp_mtu is exceeded
To set it on a per SIP request manner, you can use the core function:
  • udp_mtu_try_proto(proto)
Example:
pmtu_discovery = yes
udp_mtu = 1400
udp_mtu_try_proto = TCP
...
route {
...
if($rU=~"^\+49")
udp_mtu_try_proto(SCTP);
...
}
For more about this topic, see the Core Cookbook.

Friday, April 23, 2010

Kamailio 3.0.x - DYK - ToC

There are several neat enhancements in Kamailio 3.0.0 (released January 11, 2010) that make your config looking better and some operations optimized.

During the winter I wrote the series Best of New in Kamailio 3.0.0, focused on detailing major features brought by 3.0, this is going to be kind of mini-blogging series (max 15 lines about the topic itself?!?!), looking at tips for your config made possible only by 3.0.x, named: "Did you know?".

Here is the table of content:
The series is not finished, new posts will be published soon.

Kamailio 3.0.x - DYK-07 - custom cfg parameters

Define your own config parameters

See also: Kamailio 3.0.x - DYK - Table of Content

Kamailio 3.0.0 introduced custom config global parameters. These are variables that can be declared in the global parameters part and can be used inside the routing logic. Very useful as well is the features of being able to change its value at runtime via RPC commands, without SIP server restart.

Defining a new cfg parameter has a special format:
group.id = value 'desc' description
Then you can get access to them via pseudo-variables as $sel(cfg_get.group.id) or selects as @cfg_get.group.id.

Example - define a variable that can be used to control printing of some custom log messages:
...
local.dbg = 0 desc "Custom debug mode"
...
route {
...
if($sel(cfg_get.local.dbg)==1)
xlog("My extra log message\n");
...
}
You can update it at runtime with sercmd:
sercmd cfg.set_now_int local dbg 1
I wrote a bit more in a previous post.

Thursday, April 22, 2010

Kamailio 3.0.x - DYK-06 - comments with define

Comment big blocks with defines

See also: Kamailio 3.0.x - DYK - Table of Content

Kamailio 3.0.0 brought #!define directive support. This can be used as a neat and easy way to comment big blocks of config. Using multi-lines comment format in between /* */ is not convenient for nested cases.

Trying to enclose in multi-line comment a snippet like next (well, not that big in this example) is not straightforward:
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
Clearly is broken to do it like:
/*
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
*/
The option in 3.0.x is:
#!ifdef EXTRACOMMENT
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
#!endif
You can use anything you haven't defined instead of EXTRACOMMENT.

Enabling it is:
#!define EXTRACOMMENT
#!ifdef EXTRACOMMENT
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
#!endif

Wednesday, April 21, 2010

Kamailio 3.0.x - DYK-05 - switch and break

Break out from inside case block within switch

See also: Kamailio 3.0.x - DYK - Table of Content

Another enhancement Kamailio 3.0.x brought is usage of break inside case branches of switch statement. With older versions, break can be used only at the end of case branch:
switch($ru) {
case "101":
# actions here
break;
case "102":
# actions here
break;
}
It was no way to break out from inside the actions list. With 3.0 you can do it:
switch($ru) {
case "101":
# some actions here
if(condition) {
break;
}
# other actions here
break;
case "102":
# some actions here
break;
}
Very good to make the execution of switch more optimized and the actions list inside simpler.

Tuesday, April 20, 2010

Prosody - lightweight XMPP server

Thanks to volcano or not, this week I finally found the time to write about some projects present at FOSDEM 2010 (happened in Bruxelles, Belgium, February 6-7, 2010) which I like and use.

First is Prosody, a lightweight XMPP server, the second is SIP Communicator, a multi-protocol communication suite, mainly focusing on SIP.
Days before the conference I started to play a bit more with Lua (as a matter of fact Kamailio has now support for embedded Lua in config file). Moreover, I was looking for a simple to install and manage XMPP server for usage in small companies.

Guess what, I run into Prosody web site (iirc, via xmpp.org site) and discovered is written in Lua, which made my day, perfect match. From the project site:

"Prosody is a flexible communications server for Jabber/XMPP written in Lua. It aims to be easy to use, and light on resources. For developers it aims to be easy to extend and give a flexible system on which to rapidly develop added functionality, or prototype new protocols."

Back in 2003, SIP Express Router (SER) times, I coded first SIP-to-XMPP gateway for instant messaging and presence (even started an IETF draft about it). I used Jabberd server (v1.x), later I played with Jabberd2 and never got really into erlang to play with eJabberd, although looks an amazing application. Jabberd2 got a bit too complex for my taste, with all those specific processes running at the same time.

Back in January I was looking for something really light, not guided by performance, but more by simplicity and easiness in management - the motto of Prosody suited perfectly at first sight. Reading more about it and doing few tests, it became my favorite very shortly.

If it was a presentation about Prosody in XMPP dev room, then I missed it, however, I could spot Matthew Wild by t-shirt, greeting him just before running to my Kamailio talk. I changed some emails afterwards, looking to do a seamless integration between Kamailio and Prosody. Now I am looking forward to version 0.8 (0.7 rc is already out), hopefully to bring database support for user profiles and roster, which should make things much simpler.

Meanwhile, if you need your own XMPP server, enjoy Prosody, it has lot of extensions and support for secure communication via TLS.

There are many reasons I would strongly recommend using your own real-time communication server (XMPP or SIP), I will write more about that topic soon, this post is getting too long.

Check back this site in few days for SIP Communicator post, another amazing application out there.

Kamailio 3.0.x - DYK-04 - switch

Match regular expressions with switch statement

See also: Kamailio 3.0.x - DYK - Table of Content

Starting with 3.0.0, you can use regular expressions to match switch cases - you have to use a '/' (slash) before case value to tell it is regular expression. For example, match dialed number against country codes:
switch($rU) {
case /"^\+1": # calls to USA
...
break;
case /"^\+49": # calls to Germany
...
break;
default: # calls to other destinations
}
First, it is one statement construct, therefore is faster than a set of IFs:
if($rU=~"^\+1") {...}
else if($rU=~"^\+49") {...}
else {...}
Then, the config file is better structured, being easier now to manage and follow prefix based routing rules.

Monday, April 19, 2010

Kamailio 3.0.x - DYK-03 - while

Break out of while loop

See also: Kamailio 3.0.x - DYK - Table of Content

In 1.5.x or lower, the only way to end the while cycling was through loop condition.
while(loop condition) { actions; }
Starting with 3.0.0, you can use break statement to jump out of while loop.

For example, checking if the source IP is in a white list stored in AVPs (e.g., loaded from DB):
$var(i) = 0;
while($(avp(wlist)[$var(i)])) {
if($si == $(avp(wlist)[$var(i)])) {
$var(i) = -1;
break;
}
$var(i) = $var(i) + 1;
}
if($var(i)>=0) { # not found
sl_send_reply("403", "Forbidden");
exit;
}
In 1.5.x or older, break cannot be used and the loop condition would have to be ($var(i)>=0 && $(avp(wlist)[$var(i)])). At runtime, for each loop the evaluation of condition is now faster with 3.0.0+ since it is simpler. Of course, the advantages are many more than this one, once you get a more complex logic inside the while, like being able to break from many places inside the loop, simplify the structure by avoiding many if-then-else to wrap action not to be executed when the condition is met inside the while, a.s.o.

Sunday, April 18, 2010

Kamailio 3.0.x - DYK-02 - expressions

Constant expressions are pre-computed at startup.

See also: Kamailio 3.0.x - DYK - Table of Content
# dialed number 1234*493012345678
$var(minlen) = 4 + 1 + 7;
$var(minlen) = 12;
The above two lines are equivalent in performance at runtime. In 1.5.x or older, the right side constant expressions were computer every time a SIP message was processed.

I have some configs where I do lot of customer-code oriented routing and I use the minimum length in order to detect fast whether is a dialing error. In order to remember over the time why I chose a particular value for a minimum length, I like to write it detailed:
if($rU =~ "^1")
{ # first bunch of client codes - 3 digits
$var(minlen) = 3 /* client code */ + 1 /* separator */ + 7 /* min DID len */;
} else {
# next bunch of client codes - 4 digits
$var(minlen) = 4 /* client code */ + 1 /* separator */ + 7 /* min DID len */;
}

Saturday, April 17, 2010

Kamailio 3.0.x - DYK-01 - long strings

Break long strings

See also: Kamailio 3.0.x - DYK - Table of Content

You can break long strings in your config starting with Kamailio 3.0.0, by just closing the double quotes and opening new ones on the next line. For example:

xlog("this message is sent by caller [$fu], source address [$si], local interface [$ri], targeting user [$ru], server time [$Tf]\n");

Can be written as:

xlog("this message is sent by caller [$fu],"
" source address [$si], local interface [$ri],"
" targeting user [$ru], server time [$Tf]\n");

Super-duper for a guy like me liking old style 80 chars long line, config structure is much cleaner, easier to follow than with auto line wrapping.

It works everywhere in config, most used by me in xlog() and sql_query() functions. Enjoy!

Thursday, April 15, 2010

Kamailio 3.1.0 at the horizon

The IRC devel meeting from yesterday set the main milestones for the next major release 3.1.0. With a pleasantly very stable outcome with 3.0.0, we could focus on adding new features, lot of them being already in GIT repository:
  • Lua scripting support
  • Interactive configuration file repository
  • Generic tree-indexed caching system
  • Message Queuing system for configuration file
  • Geoip location system via config variables
  • Registration to remote SIP servers for inbound calls
  • Xlog extensions to print location - line and file - of message
  • and more - check at: http://sip-router.org/wiki/features/new-in-devel
Andrei Pelinescu-Onciul updated about his work with asynchronous TLS, to get in repository in 2-4 weeks. Also, there is work to a new module interface that will allow giving expressions as parameters to functions.

Apart of new features direction, some effort will be done to merge some modules that are more or less duplicate in features, to offer a better Kamailio and SER integration.

Details about the IRC meeting, with link to minutes at the end, at:
Time lime wise regarding next major version, Kamailio 3.1.0, we look to freeze after end of June with target release date in September.

Wednesday, April 14, 2010

New Nagios SIP Plugin

IƱaki Baz Castillo, member of Kamailio management team, announced availability of a new SIP plugin for Nagios.

The homepage of plugin is:
Among features:
  • SIP UDP and TCP transport protocols
  • Customizable parameters (From URI, Request URI, server address, local UDP port, timeout internal)
  • The replied status code can be matched against an expected value to be considered valid
Nagios is an open source powerful monitoring system, with the new plugin you have a flexible way to watch your running Kamailio SIP server.

Monday, April 12, 2010

MC Edit Syntax Highlighting for Kamailio

Shpinev Konstantin set the Midnight Commander syntax file for Kamailio v1.5.x, which is used when editing configuration file using this powerful Unix/Linux file manager. The same file is effective as well when using directly the mcedit command.

To install it on Debian:

file ..\*\\.cfg$ Kamailio\sconfig
include kamailio.syntax

To enable it enable it only for your user, add above two line to ~/.mc/cedit/Syntax.

An update for version 3.0.x should follow soon.

Here is an screenshot taken on Mac OS X:

Saturday, April 10, 2010

Users mailing list merged

As of April 10, 2010, users@lists.kamailio.org and sr-users@lists.sip-router.org have been unified. Although messages can still be posted to both addresses, the one to be primary is sr-users@lists.sip-router.org. You can subscribe or change options via web at:

Now the project is offering a single place for community discussions via email related to stable versions and generic topics, ensuring access to knowledgeable people from both Kamailio (OpenSER) and SIP Express Router (SER).

With the release of version 3.0.0, you can blend extensions from Kamailio (OpenSER) and SIP Express Router (SER) in same SIP server instance, having a common public forum for emails is a natural evolution step.

Friday, April 9, 2010

IRC Devel Meeting, Apr 14, 2010

Next IRC meeting for Kamailio (OpenSER) and SIP Router is going to take place next Wednesday, April 14, 15:00UTC. The channel is #sip-router on irc.freenode.net.

Manny members of development team announced the presence, you are welcome to join and participate to discussions. A draft agenda is available at:

Wednesday, April 7, 2010

Asterisk SIP Masterclass, April 19-23, UK

For first time in UK, Asterisk SIP Masterclass is a professional training program dedicated to Asterisk and integration with SIP Router (Kamailio/OpenSER). This class focuses on building a carrier-class scalable network architecture with Asterisk and Kamailio (OpenSER).

The course will be taught by two teachers that have all the insights you need to learn the details of Asterisk and Kamailio (OpenSER):

  • Olle E. Johansson - Asterisk SIP Developer and Kamailio (OpenSER) contributor
  • Daniel-Constatin Mierla - Kamailio (OpenSER) Developer and co-founder

Registration and more details at:

http://www.telespeak.co.uk/
http://www.telespeak.co.uk/course-detail.php?id=19

Tuesday, April 6, 2010

FreeSWITCH added licensed G729

Expected for some time, FreeSWITCH announced the availability of G729 codec. It was an important piece missing, although everyone looks at wideband codecs for the future, still most of PSTN gateways like the old narrowband G729.

Coming on 1st of April, some were reticent not to be a "specific story" for fools' day. But it is real, at a fair price of 10USD per channel.

More on FreeSwitch site:

Monday, April 5, 2010

SEMS 1.2.0 Released

Yesterday, Stefan Sayer announces the release of SEMS 1.2.0 (SIP Express Media Server).

Get the source at:
http://ftp.iptel.org/pub/sems/sems-1.2.0.tar.gz
Some debian packages at:
http://ftp.iptel.org/pub/sems/1.2/1.2.0/packages/
Changelog:
http://ftp.iptel.org/pub/sems/doc/current/changelog.html
Documentation got some new getting started tutorials:
http://ftp.iptel.org/pub/sems/doc/current/index.html

For more information see the home page at: http://iptel.org/sems