[SR-Users] load-balance to registered trunks?
Alex Balashov
abalashov at evaristesys.com
Mon Sep 3 01:22:54 CEST 2018
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/
More information about the sr-users
mailing list