[OpenSIPS-Users] limiting the number of gateways tried in lcr module

Bogdan-Andrei Iancu bogdan at voice-system.ro
Mon Jun 1 13:21:44 CEST 2009


Hi Andrew,

You can simply and get rid of the flag by simply testing if the AVP is 
present or not:

failure_route[1] {
         # -----------------------------------------------------------------
         # Failover to next gateway if any
         # -----------------------------------------------------------------
        if ( !is_avp_set("$avp(i:500)") ) {
                $avp(i:500) = 1; # Initialize counter of failed attempts
        } else {
                $avp(i:500) = $avp(i:500) + 1; # OR:
                # avp_op("$avp(i:500)", "add/1");
        }
        xlog("L_INFO", "----- Made $avp(i:500) failed attempts\n");



Regards,
Bogdan

Andrew Pogrebennyk wrote:
> Thanks for your input, Brett. I tried to initialize the counter from the 
> main route block, but it didn't work - somehow I ended up with rURI in 
> $avp(i:500). Then I rewrote the failure_route exactly like in the 
> example I have provided earlier - and it worked like a magic. Previously 
> I've had the same pieces of logic, just written in a different way, so I 
> don't know what was the problem with it. Anyway I'm happy with the way 
> it works now. In case anyone wonders, here is my working failure_route:
>
> failure_route[1] {
>          # -----------------------------------------------------------------
>          # Failover to next gateway if any
>          # -----------------------------------------------------------------
>         if (!isflagset(31)) {
>                 $avp(i:500) = 1; # Initialize counter of failed attempts
>                 setflag(31);
>         } else {
>                 $avp(i:500) = $avp(i:500) + 1; # OR:
>                 # avp_op("$avp(i:500)", "add/1");
>         }
>         xlog("L_INFO", "----- Made $avp(i:500) failed attempts\n");
>         if (t_check_status("403")) {
>                 xlog("L_INFO", "----- Got 403 response; no more gateways 
> will be tried\n");
>                 t_reply("403", "Forbidden");
>                 exit;
>         }
>         if ($avp(i:500) >= 2) { # limit on the search depth is set here
>                 xlog("L_INFO", "----- Didn't get positive response from 
> two gateways; giving up\n");
>                 t_reply("503", "Couldn't complete the call");
>                 exit;
>         }
>         if (next_gw()) {
>                 t_on_failure("1");
>                 t_relay();
>         } else {
>                 t_reply("503", "No gateways");
>                 exit;
>         };
> }
>
> Brett Nemeroff wrote:
>   
>> I don't entirely remember the way the arming of the flags works and how 
>> they persist across failure_routes. Maybe someone can comment on that?
>>
>> Instead of using flags, call:
>>                $avp(i:500) = 1; # Initialize counter of failed attempts
>>
>> from your main route block, before failure route is called. 
>>
>> Let us know how that works for you..
>> -Brett
>>     
>
>   




More information about the Users mailing list