[SR-Users] loop through variables

Alex Balashov abalashov at evaristesys.com
Tue Nov 2 14:40:36 CET 2010


On 11/02/2010 09:35 AM, Sergey Okhapkin wrote:

> htable module should do the trick to you.
>
> On Tuesday 02 November 2010, Bernhard Suttner wrote:
>> Hi,
>>
>> I want something like that:
>>
>> # define some router to use later in the script (global section)
>> Mod_param(router(1), "10.10.10.1")
>> mod_param(router(2), "10.10.10.2")
>> mod_param(router(3), "10.10.10.3")
>> Mod_param(router_count, "3")
>>
>> within the different routes I want to loop through the routers like that:
>>
>> $var(i)
>> while($(var(i)<  $var(router_count)) {
>>   if ($var(router($var(i)) == src_ip") {
>>     .. do something
>>    }
>> }

Another option is to push the constants into AVP arrays at startup (I 
assume there is some sort of init route at this point, otherwise a 
module init event-route):

    $(avp(s:routers)[0]) = "10.10.10.1";
    $(avp(s:routers)[1]) = "10.10.10.2";
    $(avp(s:routers)[2]) = "10.10.10.3";

You can then iterate through them, using is_avp_set() to check if 
something exists at the current index/array subscript:

    $var(i) = 0;

    while(is_avp_set("$(avp(s:routers)[$var(i)])")) {
       xlog("L_INFO", "Router is: $(avp(s:routers)[$var(i)])\n";
       $var(i) = $var(i) + 1;
    }

-- 
Alex Balashov - Principal
Evariste Systems LLC
1170 Peachtree Street
12th Floor, Suite 1200
Atlanta, GA 30309
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/



More information about the sr-users mailing list