[OpenSIPS-Users] Parallel forking and per branch manipulation

Jayesh Nambiar jayesh.voip at gmail.com
Tue Sep 4 15:36:46 CEST 2012


Hi Bogdan,
Firstly I am using Opensips 1.7.2. And here the observations after I tried
several things as suggested by you.
Observation 1:

lookup("location");
#$branch = $ru;

You suggested the above line is not required as it will automatically be
treated as branch 0 and hence I commented it, but is not behaving as
expected. So when I comment the above line and then add the code as below:

avp_db_query("SELECT cli, phone_number FROM users WHERE user_id = '$rU',
"$avp(cli), $avp(parallel_number)");

$rU = $avp(parallel_number);
$rd = my_gateway_ip;
$var(uri) = "sip:"+$rU+"@"+$rd;

$branch = $var(ruri);
xlog("L_INFO", "Branch URI 0=$(branch(uri)[0]) AND Branch URI
1=$(branch(uri)[1])");

The above line prints in syslog "Branch URI
0=sip:123456789 at mygateway_ipand Branch URI 1 = NULL"
This means that when I actually call "$branch = some_uri" that is when the
branch is created with an id. Because I checked adding that $branch = $ru
line again and then syslog printed  "Branch URI
0=sip:1111 at 1.2.3.4:25380and Branch URI 1=sip:123456789 at mygateway_ip
".

t_on_branch("1");
t_relay();
exit;

Observation 2:
Inside the branch route I write the following code:
       branch_route[1] {
              $var(branch_id) = $T_branch_idx;
              if($var(branch_id) == "1") {
                     xlog("L_INFO", "Branch-ID=$T_branch_idx")
                     insert_hf("Forwarded: Yes\r\n", "Call-ID");
                     uac_replace_from("sip:$avp(cli)@mydomain.com");
              }
       }


Now here I can confirm that when the branch_id is 1, it gets into this
condition since the xlog prints  "Branch-ID=1" properly when its inside the
branch route; but when branch_0 gets relayed out this header gets inserted
and From header gets replaced whereas when branch_1 is relayed the header
mentioned in this condition is not inserted and also the From header is not
replaced.
Basically, it behaves exactly opposite as expected !! Please note in this
case I am creating branch twice using the $branch command so that
$branch(uri)[0] is the one fetched from location and $branch(uri)[1] is the
PSTN uri where the call has to be parallel forwarded.
Is there something I am still doing wrong because as I understood; inside
the branch_route based on branch_id I am inserting a custom header and
replacing From header but this custom header and From header is being
replaced on the unintended branch !!
Could be that something is wrong in opensips-1.7.x. Please help me out here.

Thanks,

--- Jayesh


On Tue, Sep 4, 2012 at 12:18 AM, Jayesh Nambiar <jayesh.voip at gmail.com>wrote:

> Thanks Bogdan. Will definitely try this out.
>
> --- Jayesh
>
>
> On Monday, September 3, 2012, Bogdan-Andrei Iancu wrote:
>
>> **
>> Hi Jayesh,
>>
>> See my inline comments.
>>
>> Regards,
>>
>> Bogdan-Andrei Iancu
>> OpenSIPS Founder and Developerhttp://www.opensips-solutions.com
>>
>>
>> On 08/31/2012 03:02 PM, Jayesh Nambiar wrote:
>>
>>  Hi Binan,
>> Thank you very much for your reply. What you wrote is what I understand
>> from all the documentation present but probably the concept is not working
>> for me or probably just not getting into my head. This is a snippet of what
>> I'm trying to do:
>>
>>  lookup("location");
>> $branch = $ru;
>>
>> You do not need this last line as the $ru will be automatically be
>> considered branch 0.
>>
>>
>>  avp_db_query("SELECT cli, phone_number FROM users WHERE user_id =
>> '$rU', "$avp(cli), $avp(parallel_number)");
>> $rU = $avp(parallel_number);
>> $rd = my_gateway_ip;
>> $var(uri) = "sip:"+$rU+"@"+$rd;
>>
>>  $branch = $var(ruri);
>>
>>  t_on_branch("1"); # --This is confusing me---
>>
>> This is correct, you are arming the branch 1, which will be executed
>> inside t_relay(), once for each branch.
>>
>>  t_relay();
>> exit;
>>
>>  branch_route[1] { #---Need to know how to check for branch id here---
>>        if(branch_id == 1) { #--- How do I check for this condition??
>>
>> See $T_branch_idx (
>> http://www.opensips.org/html/docs/modules/1.8.x/tm.html#id294499)
>>
>>                uac_replace_from("sip:$avp(cli)@mydomain.com");
>>        }
>> }
>>
>>  The problem is I dont know how to identify the branch id in the branch
>> route. Even if I set branch flag for second branch using setbflag(1,1) and
>> I check for this flag in the branch route using isbflagset(1,1), by the
>> time the first branch goes into branch_route, the second branch is created
>> and the condition isbflagset(1,1) becomes true and the uac_replace_from()
>> gets executed for first branch also. My requirement is to execute this
>> branch_route only for second branch which is branch_id 1.
>> Isn't there any straight forward way of checking the id of the branch
>> when it comes to the branch route??
>>
>>  Any help is really appreciated. Thanks.
>>
>>  --- Jayesh
>>
>>> Hi,
>>>
>>> lets say you have 2 branches 0 towards user in location and 1 towards
>>> PSTN.
>>> ?
>>> I suggest to use branch flags which are used to activate some functions
>>> in branch level
>>>
>>> when creating the branches in main route use this variable $branch() to
>>> set branch flags to each indivisual branch depending on its index 0 for
>>> branch 0 and 1 for branch 1.
>>>
>>> use branch routing blocks to execute certain logic (it could be the
>>> manipulation ) for each branch before forwarding the request.
>>>
>>> // Binan
>>>
>>> --- On Thu, 8/30/12, Jayesh Nambiar <jayesh.voip at gmail.com> wrote:
>>>
>>> From: Jayesh Nambiar <jayesh.voip at gmail.com>
>>> Subject: [OpenSIPS-Users] Parallel forking and per branch manipulation
>>> To: "OpenSIPS users mailling list" <users at lists.opensips.org>
>>> Date: Thursday, August 30, 2012, 8:11 AM
>>>
>>> Hi All,I have a scenario to do parellel forking between the user found
>>> in location and towards a PSTN gateway. The requirement here is, I have
>>> unique manipulations to be done before routing the call which I believe can
>>> be done using branch routes, but I'm just wondering how.?
>>> For eg: The branch that goes to the user found from location should have
>>> no FROM Header manipulation and the branch that goes out to PSTN gateway
>>> needs a uac_replace_from("sip:123456789 at 1.2.3.4"), and
>>> insert_hf("P-Asserted_Identity: sip:123456789 at 1.2.3.4\r\n") before
>>> calling t_relay(). There are many other manipulations like this.
>>> How do I take the script logic to individual branch routes before
>>> calling t_relay, because whats happening with me is once the location is
>>> looked up, I go ahead for manipulations that is supposed to be done for the
>>> gateway branch, but it gets applicable for the branch that goes out to the
>>> user as well !!
>>>
>>> Probably I am missing something on my understanding on how to call
>>> branch_routes while doing parallel forking.
>>> Thanks for any help.
>>> --- Jayesh
>>>
>>>
>> _______________________________________________
>> Users mailing listUsers at lists.opensips.orghttp://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20120904/13067ff0/attachment.htm>


More information about the Users mailing list