<p dir="ltr">Thanks for replying!</p>
<p dir="ltr">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...</p>
<p dir="ltr">Any ideas?</p>
<p dir="ltr">David</p>
<br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 3, 2018, 00:26 Alex Balashov <<a href="mailto:abalashov@evaristesys.com">abalashov@evaristesys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Sep 02, 2018 at 11:58:37PM +0100, David Villasmil wrote:<br>
<br>
> I've got this scenario where some gateways will register on my<br>
> kamailio and i need to send them calls on a load-balance fashion.  is<br>
> this possible?<br>
<br>
Sure, anything is possible in Kamailio if you write the logic for it.<br>
:-)<br>
<br>
I like stateless load-balancing methods where possible - the fewer<br>
moving parts, the better.  <br>
<br>
You can do a lookup() and then t_load_contacts(), <br>
<br>
   <a href="https://kamailio.org/docs/modules/5.1.x/modules/tm.html#tm.f.t_load_contacts" rel="noreferrer" target="_blank">https://kamailio.org/docs/modules/5.1.x/modules/tm.html#tm.f.t_load_contacts</a><br>
<br>
and examine the size of the `contacts_avp`, e.g. by iterating through it<br>
with a while loop as you would any XAVP:<br>
<br>
   $var(num_contacts) = 0;<br>
<br>
   while(defined $xavp(whatever[$var(num_contacts)]))<br>
      $var(num_contacts) = $var(num_contacts) + 1;<br>
<br>
or you can reg_fetch_contacts() and do the same with the $ulc PV:<br>
<br>
   <a href="https://kamailio.org/docs/modules/5.1.x/modules/registrar.html#registrar.f.reg_fetch_contacts" rel="noreferrer" target="_blank">https://kamailio.org/docs/modules/5.1.x/modules/registrar.html#registrar.f.reg_fetch_contacts</a><br>
<br>
and access the number of registrants for the AOR via profile=>count:<br>
<br>
   if(reg_fetch_contacts("location", "$ru", "blah")) {<br>
       # Concurrent contact count is available as $ulc(blah=>count);<br>
<br>
       ...<br>
   }<br>
<br>
I prefer the latter.<br>
<br>
Either way, once you have a count, judicious use of cfgutils:$RANDOM<br>
<br>
   <a href="https://www.kamailio.org/wiki/cookbooks/5.1.x/pseudovariables#random_-_random_number" rel="noreferrer" target="_blank">https://www.kamailio.org/wiki/cookbooks/5.1.x/pseudovariables#random_-_random_number</a><br>
<br>
will have you on your way to sending the call to a random contact of the<br>
bunch. For sufficiently large samples, random distribution is<br>
substantially similar to round-robin load balancing.<br>
<br>
If you need failover with that load-balancing, you'll have to buffer<br>
these contacts into an XAVP and serially fork through them with a<br>
failure_route. Either way, it's all quite doable.<br>
<br>
If what you're asking is whether there is a built-in facility to effect<br>
load balancing across registrants, I'm not aware of one, though it could<br>
be my ignorance.<br>
<br>
-- Alex<br>
<br>
-- <br>
Alex Balashov | Principal | Evariste Systems LLC<br>
<br>
Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free) <br>
Web: <a href="http://www.evaristesys.com/" rel="noreferrer" target="_blank">http://www.evaristesys.com/</a>, <a href="http://www.csrpswitch.com/" rel="noreferrer" target="_blank">http://www.csrpswitch.com/</a><br>
<br>
_______________________________________________<br>
Kamailio (SER) - Users Mailing List<br>
<a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a><br>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
</blockquote></div>