[asterisk-dev] Dundi library

Klaus Darilion klaus.mailinglists at pernau.at
Mon Apr 28 05:15:21 CDT 2014

Thanks for the feedback. Corey, thanks for the work on the library.

Meanwhile I implemented the workaround: let Kamailio forward the request 
to an Asterisk server which does the lookup and responds with a 302 
redirect to (Transfer()) the proper Asterisk server.

Using SIP for the query has the advantage that the query is handled 
asynchronous inside Kamailio. For INVITEs it is quite easy (as they are 
handled in the Asterisk dialplan of the Asterisk server which does the 
DUNDI query). But it was a bit more complicated than expected as I also 
have to do the lookups also for REGISTERs, SUBSCRIBE .... Therefore I 
implemented a "hack" in Kamailio, faking another INVITE transaction 
while putting the original transcation on hold. (yes there are plenty of 
hacks you can do in Kamailio).

Basically it works but I have not tested it in detail. If you are 
interested take a look at the Kamailio config below.


dundi.host = "" desc "Asterisk which performs the DUNDI 
query. Host:Port"
dundi.deftarget = "" desc "Default Asterisk server if DUNDI 
lookup failed. Host:Port"

         $var(dundicache) = $sht(dundicache=>$tU);
         if( $var(dundicache) == 0) {
                 xlogl("L_INFO","$tU not found in cache, quering 
Dundi-Asterisk for DUNDI lookup...");
                 if(t_suspend()) {
                         # build a new transaction, use From and To URI 
to store
                         # the transaction identifiers
                         xlogl("L_INFO","transaction suspended 
                         $uac_req(ruri)="sip:" + $tU + "@" + 
                         $uac_req(furi)="sip:" + $T(id_index) + "@proxy";
                         $uac_req(turi)="sip:" + $T(id_label) + "@proxy";
                 } else {
                         xlogl("L_ERR","Failed to suspend transaction 
... 500");
                         send_reply("500","Failed to suspend transaction");
         } else if( $var(dundicache) == "unknown" ) {
                 xlogl("L_INFO","$tU found in cache but unknown, sending 
to $(sel(cfg_get.dundi.deftarget))");
                 $du="sip:" + $sel(cfg_get.dundi.deftarget);
         } else {
                 xlogl("L_INFO","$tU found in cache, sending to 
                 $du="sip:" + $var(dundicache);

         if (!t_relay()) {

event_route [tm:local-request] {
         # Handle locally generated requests
         xlogl("L_INFO", "local-request: Routing locally generated $rm 
to <$ru>:");
         # 2 seconds prober timeout
         t_set_fr(0, 2000);
onreply_route[REPLY_DUNDI] {
         xlogl("L_INFO","REPLY_DUNDI: response received from $si:");

         $var(index) = $(fU{s.int});
         $var(label) = $(tU{s.int});
         if (t_check_status("3[0-9][0-9]")) {
                 # this reply route is only executed for DUNDI 
responses, thus, no need to check the source
                 $var(target)= @msg.header.Contact[0].nameaddr.uri.host;
                 xlogl("L_INFO","REPLY_DUNDI: Tindex=$var(index), 
Tlabel=$var(label), target=$var(target)");
                 t_continue("$var(index)", "$var(label)", "AFTER_DUNDI");
         } else {
                 xlogl("L_ERR", "Unexpected response from Dundi server");
                 t_continue("$var(index)", "$var(label)", "AFTER_DUNDI");


route[AFTER_DUNDI] {
         xlogl("L_INFO","AFTER_DUNDI: transaction 
$T(id_index):$T(id_label) continues ....");
         $var(target) = $sht(dundicache=>$T(id_index):$T(id_label));
         if ($(var(target){s.len}) > 1) {
                 $du = "sip:" + $var(target);
                 $ru = $ou;
                 xlogl("L_INFO", "Got redirect from Dundi server, target 
is $ru, sending to $du");
         } else {
                 xlogl("L_ERROR","AFTER_DUNDI: no target found ... using 
                 $du="sip:" + $sel(cfg_get.dundi.deftarget);
                 $ru = $ou;

More information about the asterisk-dev mailing list