Hi Bogdan,

The problem could be from setting db_mode to 3.  As you said earlier, this is 
always required when using a shared location table.
My DB table would have two records - one where the socket is for server A and 
the other with the socket for server B.
It is possible that when the lookup() function loads matching contacts into 
memory, the first contact has a local socket and the second one has non-local. 
My log statement would only print the socket info for the first branch. Perhaps 
it should print the info for the main R-URI but I was not sure how to get to 
that item of data.
The order that is used to load contacts into memory would be somewhat random - 
sometimes it might be the local contact first and sometimes not. I could use Q 
to force a consistent load order, but it would still be wrong on one site and 
right on the other. I would prefer that there was an option to only load 
contacts where the socket was a local one. That would be *much* more useful 
than loading the contact and discarding its socket data. Could you add this to 
the road map please?

Frankly, this is all a bit academic now. I have changed to use a location table 
per site and have also changed db_mode back to 1. There were too many problems 
with sharing one location table for two different sites.

So this discussion is only relevant if you and the other developers want to 
rationalise the usrloc module so it can be used in the scenario where two 
different OpenSIPS servers (both active) can share a single location table. 
Perhaps you just need to add a few notes to the documentation to warn users 
that this is not a recommended scenario. I am writing a new knowledgebase 
article that covers this topic. I will attempt to explain the problems there in 
more detail.

John Quick
Smartvox Limited


-----Original Message-----
From: Bogdan-Andrei Iancu [mailto:[email protected]] 
Sent: 06 June 2017 16:51
To: [email protected]; 'OpenSIPS users mailling list' 
<[email protected]>
Subject: Re: [OpenSIPS-Users] Location table - how to use socket

John,

I tested with 2.4 (dev branch) having:
     modparam("usrloc", "db_mode",   2)

It might be from the DB mode 3.....are you sure that the socket info you have 
in DB is local to the OpenSIPS loading the record ? otherwise the socket info 
may be discarded when the OpenSIPS is loading the record in memory (during the 
lookup(location) )

Regards,

Bogdan-Andrei Iancu
   OpenSIPS Founder and Developer
   http://www.opensips-solutions.com

OpenSIPS Bootcamp 2017, Houston, US
   http://opensips.org/training/OpenSIPS_Bootcamp_2017.html

On 06/06/2017 05:51 PM, John Quick wrote:
> Hi Bogdan,
>
> Thanks for testing that. However, something must be different between your 
> test and mine. I didn't make this up!
> Were you using db_mode=3?   Were you using v2.2.x ?
>
> By the way, I have moved on with this problem by creating a location table 
> for each site. This works well, but I had to add a record to the 'version' 
> table for each new location table as otherwise OpenSIPS fails during module 
> initialisation with "wrong table version". It must be pre-scanning the 
> script, looking at the argument passed to the save and lookup functions - how 
> else could it know the name of the location table during initialisation.
>
> Another observation, but of little importance: Some records in the old 
> location table were not deleted when they expired. Does OpenSIPS internally 
> create a timer task (to clear expired records) at run-time when the save() 
> function is called? As I say, this is out of curiosity only and is not 
> important.
>
> John Quick
> Smartvox Limited
>
>
> -----Original Message-----
> From: Bogdan-Andrei Iancu [mailto:[email protected]]
> Sent: 06 June 2017 15:25
> To: [email protected]; 'OpenSIPS users mailling list' 
> <[email protected]>
> Subject: Re: [OpenSIPS-Users] Location table - how to use socket
>
> Hi John,
>
> I just tried your logic and it seems to work. I had 2 phones registered under 
> [email protected] and made a call to that account:
>
> Jun  6 16:20:19 voip opensips_proxy[2584]: test - 1 branches found while 
> routing INVITE to sip:[email protected] Jun  6 16:20:19 voip 
> opensips_proxy[2584]: test - R3 IN:
> Req.type=INVITE
> R-URI=sip:[email protected]:59565;rinstance=f5b110f9258cd910;transp
> ort=UDP
> Br.cnt=1  Sock[0]=udp:172.16.36.74:5060 Sock[1]=<null> 
> Call-ID=313439363735383831383130383437-mw5gjx27ee3d
>
> The first registration was uploaded directly into the SIP msg (as 
> RURI, DURI, etc), while the additional one was pushed as branch (see 
> the "test
> - 1 branches found" log). Printing the Sock[0] seems to provide the correct 
> value.
>
> Best regards,
>
> Bogdan-Andrei Iancu
>     OpenSIPS Founder and Developer
>     http://www.opensips-solutions.com
>
> OpenSIPS Bootcamp 2017, Houston, US
>     http://opensips.org/training/OpenSIPS_Bootcamp_2017.html
>
> On 05/31/2017 01:01 PM, John Quick wrote:
>> Hello Bogdan,
>>
>> Here is the code I used to check $(branch(socket)[N]):
>>
>>      if (lookup("location")) {
>>           set_count("$branch(uri)", "$var(brcnt)");
>>           if ($var(brcnt) > 0) {
>>               # More than one contact - not possible to check socket data
>>               xlog("L_WARN", "    R3 IN: Req.type=$rm  R-URI=$ru  
>> Br.cnt=$var(brcnt)  Sock[0]=$(branch(socket)[0]) 
>> Sock[1]=$(branch(socket)[1])  Call-ID=$ci\n");
>>           } else  ...
>>
>> And here is the log file output when I have two registrations on the 
>> same username
>>
>> R3 IN: Req.type=INVITE  R-URI=sip:[email protected]:5060  
>> Br.cnt=1 Sock[0]=<null> Sock[1]=<null> 
>> [email protected]
>>
>> The records in the location table both have data in the socket field.
>> This is running on version 2.2.4 of OpenSIPS
>>
>> John Quick
>> Smartvox Limited
>> Tel:   01727-221221
>>
>>
>> -----Original Message-----
>> From: Bogdan-Andrei Iancu [mailto:[email protected]]
>> Sent: 29 May 2017 11:32
>> To: [email protected]; 'OpenSIPS users mailling list'
>> <[email protected]>
>> Subject: Re: [OpenSIPS-Users] Location table - how to use socket
>>
>> Hi John,
>>
>> the only way to share records via DB is to use DB only - the other modes are 
>> using the DB just for restart persistence reason (they do not read from DB 
>> at runtime, only once, at startup). In DB-only mode, all reads and writes 
>> (related to contacts) are done against the DB.
>>
>> In regards to $(branch(socket)[N]) - do you use it after a
>> lookup(location) ? are you sure that the N'th branch exists and have a 
>> socket ?
>>
>> You may consider saving some extra attributes next to the contact ( 
>> see
>> http://www.opensips.org/html/docs/modules/2.2.x/registrar.html#idp556
>> 8
>> 288) to identify the pop/host which produced that record.
>>
>> Best regards,
>>
>> Bogdan-Andrei Iancu
>>      OpenSIPS Founder and Developer
>>      http://www.opensips-solutions.com
>>
>> OpenSIPS Bootcamp 2017, Huston, US
>>      http://opensips.org/training/OpenSIPS_Bootcamp_2017.html
>>
>> On 05/26/2017 07:38 PM, John Quick wrote:
>>> Hi Bogdan,
>>>
>>> Yes. I tried with db_mode=1 and it behaved very strangely so I changed it 
>>> to db_mode=3 (DB only).
>>>
>>> Also tried $(branch(socket)[N]) to read the socket data within my script, 
>>> but it always returns <null>.
>>>
>>> I am now thinking it will be necessary to have one location table per site, 
>>> but perhaps you could consider adding options in future releases to allow 
>>> the lookup function to only select contacts where the socket matches one 
>>> that this server is listening on.
>>>
>>> John Quick
>>> Smartvox Limited
>>>
>>>
>>> -----Original Message-----
>>> From: Bogdan-Andrei Iancu [mailto:[email protected]]
>>> Sent: 26 May 2017 17:30
>>> To: [email protected]; OpenSIPS users mailling list 
>>> <[email protected]>
>>> Subject: Re: [OpenSIPS-Users] Location table - how to use socket
>>>
>>> Hi John,
>>>
>>> I suppose you are using usrloc with DB-only to share registrations between 
>>> multiples sites, otherwise the socket filter will not make sense, right ?
>>>
>>> Best regards,
>>>
>>> Bogdan-Andrei Iancu
>>>       OpenSIPS Founder and Developer
>>>       http://www.opensips-solutions.com
>>>
>>> OpenSIPS Bootcamp 2017, Huston, US
>>>       http://opensips.org/training/OpenSIPS_Bootcamp_2017.html
>>>
>>> On 05/25/2017 06:16 PM, John Quick wrote:
>>>> The socket field in the location table sometimes contains very 
>>>> useful information such as:
>>>> - to see which server received the Registration in a dual site 
>>>> scenario
>>>> - to see if the UA registered over UDP, TCP or TLS
>>>>
>>>> However, there does not seem to be any mechanism for using the 
>>>> socket information in the USRLOC or REGISTRAR modules.
>>>> For example, it is not possible to call lookup and filter for 
>>>> contacts made on the local server's socket or for contacts that used TLS.
>>>>
>>>> Please could the developers look at options to leverage this useful 
>>>> data, especially for the lookup function.
>>>>
>>>> Are there any tricks I could employ to achieve the same result. For 
>>>> example, if I set a branch flag to indicate which site received 
>>>> this registration would it then be possible to filter the results 
>>>> returned by lookup and extract the registrations received at site A 
>>>> while discarding those received at site B?
>>>>
>>>> To give a practical example: Dual site; Shared location table; 
>>>> User's device is registered at site B; Call arrives at site A so I 
>>>> want to use 302 redirect to send it over to site B, but I cannot 
>>>> tell from the results of a lookup whether the registration was made 
>>>> at A or B even though the data is there in the socket field.
>>>>
>>>> John Quick
>>>> Smartvox Limited
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Users mailing list
>>>> [email protected]
>>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
[email protected]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

Reply via email to