Thanks for replying!

Interesting approach! Though i don't think that will work for me. I've been looking into my requirements, and I'd need to do weight-based distribution instead of load-balance,  also what i need is to add destinations to the dispatcher lists dynamically. I was thinking of adding them dynamically when they register, but the module doesn't have a function to reload the list via the config script, or a db_mode as on other modules. This one is going to be tricky...

Any ideas?

David


On Mon, Sep 3, 2018, 00:26 Alex Balashov <abalashov@evaristesys.com> wrote:
On Sun, Sep 02, 2018 at 11:58:37PM +0100, David Villasmil wrote:

> I've got this scenario where some gateways will register on my
> kamailio and i need to send them calls on a load-balance fashion.  is
> this possible?

Sure, anything is possible in Kamailio if you write the logic for it.
:-)

I like stateless load-balancing methods where possible - the fewer
moving parts, the better. 

You can do a lookup() and then t_load_contacts(),

   https://kamailio.org/docs/modules/5.1.x/modules/tm.html#tm.f.t_load_contacts

and examine the size of the `contacts_avp`, e.g. by iterating through it
with a while loop as you would any XAVP:

   $var(num_contacts) = 0;

   while(defined $xavp(whatever[$var(num_contacts)]))
      $var(num_contacts) = $var(num_contacts) + 1;

or you can reg_fetch_contacts() and do the same with the $ulc PV:

   https://kamailio.org/docs/modules/5.1.x/modules/registrar.html#registrar.f.reg_fetch_contacts

and access the number of registrants for the AOR via profile=>count:

   if(reg_fetch_contacts("location", "$ru", "blah")) {
       # Concurrent contact count is available as $ulc(blah=>count);

       ...
   }

I prefer the latter.

Either way, once you have a count, judicious use of cfgutils:$RANDOM

   https://www.kamailio.org/wiki/cookbooks/5.1.x/pseudovariables#random_-_random_number

will have you on your way to sending the call to a random contact of the
bunch. For sufficiently large samples, random distribution is
substantially similar to round-robin load balancing.

If you need failover with that load-balancing, you'll have to buffer
these contacts into an XAVP and serially fork through them with a
failure_route. Either way, it's all quite doable.

If what you're asking is whether there is a built-in facility to effect
load balancing across registrants, I'm not aware of one, though it could
be my ignorance.

-- Alex

--
Alex Balashov | Principal | Evariste Systems LLC

Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free)
Web: http://www.evaristesys.com/, http://www.csrpswitch.com/

_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users