Thursday, December 17, 2009

Best of New in Kamailio 3.0.0 - #3: route blocks with names

So far, the routing blocks defined in Kamailio (OpenSER) configuration file could get only integer IDs, for example:

route[10] {
$du = "sip:10.10.10.10";
t_relay();
exit;
}
That could make the big configs hard to understand after a while, when was need for troubleshooting or enhancements. It was a nightmare to check what route[24] was intended to do when you encountered the execution of it in another route.

In version 3.0.0, along with integer IDs, you can give string IDs to name the routes:

route[TO_ASTERISK] {
$du = "sip:10.10.10.10";
t_relay();
exit;
}
Previously, many people, including myself, used a text preprocessor like M4 to have string IDs for route names, but with some disadvantages: more files to manage (at least two m4 and one cfg), you had to edit all the time the m4 file, compile it with m4 in cfg, then the errors were reported by Kamailio relative to cfg file, resulting in mismatch of error's line number and the place you had to edit for fix.

However, the new embedded features with string names for routing blocks eliminates the restriction of up to 60 (40 in older versions) route blocks where the IDs must be in between 1 and 59. Instead of static array, the routing blocks are now in a hash table, allowing as many routing blocks as you need, with no constraints in naming.

Moreover, the string IDs can be used for any kind of routing block: route, failure_route, onreply_route, branch_route, ...

To call a route block, use the string name instead of integer ID:

route {
...
route(TO_ASTERISK);
...
}
The default configuration for Kamailio 3.0.0 uses this new feature: see it online .

Worth to mention that you can define now names for SIP message flags as well:

flags
FLAG_ACC : 1, # log in acc
FLAG_MISSED : 2; # log in missed_calls

...
route {
...
setflag(FLAG_ACC);
...
}
Next writing will be about new config parameters framework.

No comments:

Post a Comment