[SR-Users] Who can tell me how to get the dialog-based CDRs ?

Timo Reimann sr at foo-lounge.de
Wed Dec 21 19:54:24 CET 2011


Hey there,

I added the list to CC as others may be interested in your findings as well.


"sunny_day" <416415455 at qq.com> schrieb:
>     Thank you very much for your detailed analysis !
> According to your analysis I have been getting more understand the
> kamailio. :-)
> After submitting the issue, I have done many experiments. And now,  I
> may find the reason about my script.
> 
> 1. somebody seems like having said dialog is tracing and dealed with
> after loose_route()--(May be I didn't understand it correctly. And now
> I am also not sure the relationship between dialog and loose_route() ).
> And the dialog will be destroyed after receiving the "BYE" message.
> So, I place the "insert" after loose_route() and "is_method("BYE")" .
> ------it may have problem.

Calling loose_route() makes sure that for a given sequential request (which includes BYE messages) it is properly linked to its dialog. This is carried out by either adding cookies to Route headers or trying to match the dialog-identifying SIP headers (From-Tag, To-Tag, and Call-ID).

This so-called "matching mode" is set to "DID only" which corresponds to using cookies in Route headers. For this to work, you must ensure that calls are being enriched with Record-Route headers. So one possible reason why things didn't work for you is that you used "DID only" matching mode (which you apparently did as you configuration didn't deviate from the default) but forgot to add Record-Route headers. Alternatively, you could set matching mode to 2 (SIP header-based matching only) or 1 (cookie-based but fallback to header-based) to get things going dialog-wise.

See the dlg_match_mode modparam documentation here: http://sip-router.org/docbook/sip-router/branch/master/modules_k/dialog/dialog.html#id2580386 .


> The main reason "insert" can not insert the data into cdr table is
> loose_route() returns "0", which has no "Route:" header , and the
> "insert" will never be executed.

Which may be the case because you did not instruct Kamailio to add Record-Route headers along the signaling way.


> 2. At last, I place the "insert" in the "route(RELAY);".   And data can
> be inserted into the cdr table again. Originally, I was considering the
> dialog will be destroyed immediately when then "BYE" message received.
> The results of my experiments prove that it isn't.  But I am not sure
> whether my conclusion is right.

In the old days, dialogs would indeed be destroyed as soon as the transaction correlating to the first BYE request was deleted. This was changed a while in ago in order to be able to handle responses to such BYE requests too. So these days, dialogs do not get destroyed until a BYE-completing response is seen. (More specifically, until the transaction related to a BYE-completing response is terminated. Or, if that BYE request never sees a response and its transaction times out, whichever comes first. But that's just details.)

You probably shouldn't be satisfied with updating database entries during route[RELAY] (at least not only). If it's not working on processing of a final BYE request, this indicates that dialog tracking isn't properly working for you (see my explanation above as to why). Whatever you store in dialog variables during an INVITE may not be valid by the time you persist to database.

And regarding CDR generation using Kamailio's built-in mechanism: It's part of the acc (accounting) module (not dialog as I initially claimed). You may want to look at the documentation to see if it's a fit for you:

http://sip-router.org/docbook/sip-router/branch/master/modules_k/acc/acc.html#id3041546


HTH,

--Timo



> ------------------ Original ------------------
> From:  "Timo Reimann"<sr at foo-lounge.de>;
> Date:  Wed, Dec 21, 2011 06:51 PM
> To:  "SIP Router - Kamailio (OpenSER) and SIP Express Router (SER) -
> Users Mailing List"<sr-users at lists.sip-router.org>;
> Cc:  "sunny_day"<416415455 at qq.com>;
> Subject:  Re: [SR-Users] Who can tell me how to get the dialog-based
> CDRs ?
> 
> 
> Hey,
> 
> 
> Am 21.12.2011 um 07:03 schrieb sunny_day:
>> My object:    get the dialog-based CDRs
>> 
>> SIP proxy:   kamailio-3.2.0
>> 
>> My script:
>> 
>> loadmodule "dialog.so"
>> ......
>> modparam("dialog","dlg_flag",4)#Must be set to create the dialog
> associated to an initial request.
>> modparam("dialog","db_url","mysql://xxx:xxx@localhost/albert")
>> modparam("dialog","table_name","dialog")
>> .......
>> request_route{
>>    if( is_method("INVITE") && !has_totag())
>>    {
>>           dlg_setflag(4);
>>           dlg_var(start_time)=$TS;
>>           dlg_var(caller)=$fU;
>>           dlg_var(caller)=$tU;
>>    }
>>    dlg_manage();
>>    ......
>>    # dispatch destinations to PSTN
>>     route(PSTN);
>>    # user location service
>>      route(LOCATION);
>>      route(RELAY);
>> }
>> .........
>> route[WITHINDLG] {
>>     if (has_totag()) {
>>             # sequential request withing a dialog should
>>             # take the path determined by record-routing
>>     if (loose_route()) {
>>              if (is_method("BYE")) {
>>                    setflag(FLT_ACC); # do accounting ...
>>                   setflag(FLT_ACCFAILED); # ... even if the
> transaction fails
>> 
>>                   sql_query("cd", "insert into
> cdr(caller,callee,start_time,duration)
> values($dlg_var(caller),$dlg_var(callee),$dlg_var(start_time),$DLG_lifetime)",
> "rd");
>>                   sql_result_free("rd");
>>     }
>>     if (is_method("ACK")) {
>>     route(NATMANAGE); # ACK is forwarded statelessy
>>    }
>>    route(RELAY);
>> }
>> ........
>> 
>> 
>> My issue is :
>> 
>>        The dialog records can be wrritten into the dialog table.
> But , the sql_query can not executed. So the cdr table will not get the
> CDRs.  I don't know why. Who can help me ?
>>        This is a simple script for testing.
>> 
>>        Any suggestion will be appreciated.
>> 
>>        Thank you in advance.
> 
> It's very hard to help with any Kamailio error unless you provide the
> actual error message. Whatever the issue is with the sqlops module,
> Kamailio will tell you, so please tell us.
> 
> Until then, I can only speculate what's gone wrong: Did you possibly
> forget to specify the sqlcon module parameter? You need to setup the
> MySQL connection parameters in there. See
> 
> http://sip-router.org/docbook/sip-router/branch/master/modules_k/sqlops/sqlops.html#id2793249
> 
> for sqlcon's documentation and
> 
> http://sip-router.org/docbook/sip-router/branch/master/modules_k/sqlops/sqlops.html#id2794430
> 
> for the reference regarding sql_query(). Please note how that part
> states that "the result parameter should normally only be omitted when
> no result is expected (INSERT, UPDATE, DELETE)" (which is the case in
> your test script). In consequence, you won't need to free the result
> set which could be another source of error.
> 
> 
> Finally, please note that the dialog module itself is capable of
> producing CDRs directly from the dialog machinery. It's yet lacking
> support for direct output to a database (AFAIK), however, so you'd have
> to post-process the CDR results (which are being written to file as of
> now) in order to get them persisted into a database.
> For some reason, the CDR documentation I wrote seems to have
> disappeared from the git repository. I'll investigate that further and
> provide you with a link to the dialog-way-of-creating-CDRs when
> available (and desired from your side).
> 
> 
> HTH,
> 
> --Timo



More information about the sr-users mailing list