[asterisk-users] Asterisk send calls to SIP Trunks with Round Robin Call Distribution

Steve Edwards asterisk.org at sedwards.com
Mon Apr 5 16:26:07 CDT 2010


On Mon, 5 Apr 2010, JR Richardson wrote:

>>> I have a special requirement that insist an Asterisk server, 1.6.1.x, 
>>> is used.? I will have 2 SIP trunks coming into the server and I will 
>>> have to send calls to these SIP trunks with a round robin distribution 
>>> pattern.? I was thinking of using a group count function, if call 
>>> count is even send call to SIP Trunk 1, if call count is odd, send 
>>> call to SIP Trunk 2.
>>
>> The "decimal" portion of ${UNIQUEID} is incremented every time Asterisk 
>> creates a channel. Applying your even/odd logic to this should work 
>> fine.
>>
> Thanks Steve, works great:
>
> exten => _X.,1,Set(uniqueidcut=${CUT(CDR(uniqueid),.,2)})
> exten => _X.,n,Set(result=${MATH(${uniqueidcut}%2)})
> exten => _X.,n,GotoIf($[${result} > 0 ]?siptrunk1,1:siptrunk2,1)

I don't have any empirical evidence, but I would suspect a variable 
reference ("${UNIQUEID}") would be insignificantly faster than invoking a 
function that references a variable ("CDR(uniqueid)").

Also, for the forseeable future, the Unix epoch will be 10 digits, so I 
suspect specifying the character offset in the variable reference (":11"*) 
will be insignificantly faster than invoking a function ("${CUT()}").

And, unless you have a specific need for the "decimal" portion of the 
UNIQUEID, you could roll it all into a single conditional like:

gotoif($[${MATH(${UNIQUEID:11} % 2,int)} > 0]?siptrunk1,1:siptrunk2,1)

*) Assuming you're not using the "systemname" prefix.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list