[OpenSIPS-Users] I need some help in attr matching while forming the Branch .

Sasmita Panda spanda at 3clogic.com
Thu Nov 2 13:34:18 UTC 2023


Hi Ben ,



failure_route[1] {
   if ( t_check_status("404|477|480|481|408|486|50[234]")){
if (next_branches())
{
    t_on_branch("attr");
         }

    }
}


branch_route[attr]
{
$var(count) = $(hdr(Call-Info){csv.count});

$var(i) = 0;
$var(match-count) = 0;

while($var(i) < $(var(count))){

         if ($(avp(attr){s.index, $(hdr(Call-Info){csv.value,$var(i)})}) !=
NULL){
          xlog("counter: $var(i)th  index matched in attribute \n");
           $var(match-count)= $var(match-count) + 1;
          }
        xlog("counter: $var(i)\n");
        $var(i) = $var(i) + 1;
}

        if ($var(i) == $var(match-count)){
## Here I want to give call to that contact .. if that fails then again it
should come to next branch and again compare
            t_on_failure("1");
            route(1);
      }
      else{
# Here if the condition does not match . then i want to do the comparison
again
      if (next_branches()){
             t_on_branch("attr");
           }
  #      drop();
       }
}

As for my expectation, it's not working . How does it work ? Where should I
use T_branch_Idx ? Can I get some examples of this ?


*Thanks & Regards*
*Sasmita Panda*
*Senior Network Testing and Software Engineer*
*3CLogic , ph:07827611765*


On Fri, Oct 27, 2023 at 7:10 PM Ben Newlin <Ben.Newlin at genesys.com> wrote:

> Just wanted to add that with the solution I recommended below, you would
> want to make sure you properly handle the case where all branches were
> dropped because none matched. The proper handling in that case for your
> system would be defined by your requirements.
>
>
>
> Ben Newlin
>
>
>
> *From: *Users <users-bounces at lists.opensips.org> on behalf of Ben Newlin <
> Ben.Newlin at genesys.com>
> *Date: *Friday, October 27, 2023 at 9:33 AM
> *To: *OpenSIPS users mailling list <users at lists.opensips.org>
> *Subject: *Re: [OpenSIPS-Users] I need some help in attr matching while
> forming the Branch .
> ------------------------------
>
> Without seeing the specific exact code, I can’t say what is causing that
> error. It seems like it may be a syntax issue. For example, in your email
> you are missing the semicolon after the line setting the count. I don’t
> know if it is that way in your config script. I recommend double checking
> all your syntax, and if you still get the error please provide the exact
> code from your script for review.
>
>
>
> For #2, I can’t really be very specific there because I don’t know all of
> your logic, nor am I very knowledgeable about the registrar module. My
> first thought is to not do any filtering/checking in the request route.
> Just allow the registrar module to load all contacts in branches, but arm a
> branch_route. Then perform the check in the branch route for each branch.
> If the Contact for the branch doesn’t match what you want, you can drop the
> branch [1].
>
>
>
> [1] https://www.opensips.org/Documentation/Script-Routes-3-2#toc2
>
>
>
> Ben Newlin
>
>
>
> *From: *Users <users-bounces at lists.opensips.org> on behalf of Sasmita
> Panda <spanda at 3clogic.com>
> *Date: *Friday, October 27, 2023 at 6:17 AM
> *To: *OpenSIPS users mailling list <users at lists.opensips.org>
> *Subject: *Re: [OpenSIPS-Users] I need some help in attr matching while
> forming the Branch .
> ------------------------------
>
> Ahhh , Ok .
>
> Now it's very  complicated . When you said a loop that's looping in my
> mind . Sorry for the bad joke .
>
>
>
> In case , the number of elements in each Invite won't be fixed . So the
> number of loops will vary from one Invite to another .
>
> I was thinking of counting the number of elements first , then as the
> index starts from 0 I will loop till *count-1* to fetch every element
> properly .
>
>
>
> Example :
>
> $var(count) = $(hdr(Call-Info){csv.count})    ## if the number is 3 then
> loop will be for 3 times starting from 0 to 2
>
>
>
>  $var(i) = 0;
>     while($var(i) < $var(count) )
>     {
>         xlog("counter: $var(i)\n");
>         $var(i) = $var(i) + 1;
>     }
>
>
>
> This was my initial thought . But while finding the count it gave me an
> error . * $var(count) = $(hdr(Call-Info){csv.count})  Is this not in the
> correct format ? *
>
>
>
> *parse error in /usr/local/etc/opensips/opensips-p2p.cfg:267:26-55:
> unknown script variable*
>
>
>
> *As I have earlier mentioned my header will look like . *
>
> *Call-Info: sales,en,level20,en (this can be anything but format will be
> like this . )  . How do I count the number of values ?*
>
>
>
> *2. As I am doing this matching to filter out contacts, where should I do
> this ? If I am doing this while giving a call to the contacts , for the 1st
> transaction it is doing the comparison , after that for the next branch it
> processes the call without matching . Which is not right . For every
> contact this comparison should loop *
>
>
> *Thanks & Regards*
>
> *Sasmita Panda*
>
> *Senior Network Testing and Software Engineer*
>
> *3CLogic , ph:07827611765*
>
>
>
>
>
> On Thu, Oct 26, 2023 at 7:19 PM Ben Newlin <Ben.Newlin at genesys.com> wrote:
>
> Sasmita,
>
>
>
> Apologies, I replied yesterday but the message is being held by the list
> as the quoted replies have made it too large. I’ve removed some of the
> quoted replies and I’m copying my response below:
>
>
>
> Yes, a substring match means the exact complete string exists somewhere in
> the string being searched . In your example, the $avp(attr) does not
> contain any substring that matches $hdr(Call-Info), so it is correctly
> failing.
>
>
>
> If you want to check for the presence of each element, you need to loop
> through the elements in $hdr(Call-Info) and check for each one in the
> $avp(attr) using the s.index mechanism.
>
>
>
> The best options for looping on the header are probably s.select [1] or
> the csv tranformations [2].
>
>
>
> [1] https://www.opensips.org/Documentation/Script-Tran-3-2#toc7
>
> [2] https://www.opensips.org/Documentation/Script-Tran-3-2#toc82
>
>
>
> Ben Newlin
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20231102/8e757aad/attachment.html>


More information about the Users mailing list