[asterisk-users] Load balancing SIP trunks?

Gordon Henderson gordon+asterisk at drogon.net
Thu Aug 16 02:58:44 CDT 2007


On Wed, 15 Aug 2007, Nicholas Blasgen wrote:

> I have 10 SIP trunks that I'd really like to round-robin load balance.
> Currently I have a macro that switches between available lines, but there
> really must be a function in Asterisk to do this on its own.  So my question
> is just that, are there any easy ways for Asterisk to either balance between
> SIP trunks or even just a built in function to find the next available SIP
> trunk.  I think using a macro to test the state of each trunk is silly, but
> it's the only method I've found.

I wonder (and sometimes question!) the wisdom of putting everything into 
asterisk when it can be implemented in the dial-plan (or as I posted 
recently putting stuff out of the dialplan into AGI when it can be done in 
the dialplan) I'm sure there are cases where both are valid, but I'm a 
great believer in the KISS principle, and if we keep the "core" of 
asterisk clean and simple, then we can develop add-ons in the dialplan, or 
elsewhere...

(And after saying that, I have to say that the dial-plan programming 
language is one of the more esoteric programming languages I've used in 
the 26 years or so I've been programming!)


So, if we have sip-outX as out 10 sip trunks (0-9), then: (untested ;-)

[globals]
sipTrunk=9


  ...


[macro-dialSipTrunk]
exten => s,1,Noop(Dialling out via round-robin SIP trunk)
exten => s,n,Set(sipTrunk=$[${sipTrunk}+1])
exten => s,n,GotoIf($[${sipTrunk}=10],skip)
exten => s,n,Set(sipTrunk=0)
exten => s,n(skip)Noop(SIP dialling on trunk: ${sipTrunk})
exten => s,n,Dial(SIP/sip-out${sipTrunk},${ARG1},${ARG2})

... maybe stuff here to deal with result of the DIAL.
... eg. on congestion you might to jump back to step 2
... but if you did that then you might want to start a 2nd counter
... which when it reached 10, you're SOL and can return congestion
... to the caller.....

Maybe I've just been writing too much dialplan stuff lately!!!

Gordon





More information about the asterisk-users mailing list