Trunk load balancing

Using Asterisk 1.8.27, I need to define two “clustered” trunks so that when one is down I can use the other.

Both trunks are defined in sip.conf. Calls come in via either trunk. As I transfer to internal agents, I need to be able to use whichever trunk is available/up. Automatically.

Come to think of it, “load balancing” is not a good description, the primary concern is resilience.

Please advise.

Thanks,

George

You specify load balancing, but I wonder if simple failover wouldn’t be more appropriate here. Do you want to send the call over whichever trunk is up? If so, then simply stacking your dial cmds would achieve this:

exten => _NXXNXXXX,1,Dial(SIP/trunk1/{$EXTEN})
exten => _NXXNXXXX,n,Dial(SIP/trunk2/{$EXTEN})

If you wanted to load balance you could work up some extensions.conf magic with variables and math, so each trunk takes turns getting calls ( basic algorithm might be something like if( ( calls % 2 ) == 1) THEN trunk1 else trunk2 ).

Is that what you were looking for? Or did I completely misunderstand the question :smiley:

Yes, you are right, and I have already corrected my wording.

So, if I get what you are suggesting, for the transfers I would only specify the, say, 5-digit extension without the “@IP_address:5060” postfix, and Asterisk would take care of the addressing using your extensions scheme?

[quote=“gdevelek”]Yes, you are right, and I have already corrected my wording.

So, if I get what you are suggesting, for the transfers I would only specify the, say, 5-digit extension without the “@IP_address:5060” postfix, and Asterisk would take care of the addressing using your extensions scheme?[/quote]If the trunks are properly defined in sip.conf, sure. Extensions.conf would simply contain two dial cmds, one after the other. If the first dial cmd fails, then asterisk will try the next one automatically.

By “properly defined”, do you mean anything besides making sure that the trunk names given in sip.conf match the ones given in your two extensions.conf lines (trunk1 and trunk2)?

[quote=“gdevelek”]By “properly defined”, do you mean anything besides making sure that the trunk names given in sip.conf match the ones given in your two extensions.conf lines (trunk1 and trunk2)?[/quote]I mean simply that they work.

There’s no special configuration you have to do to the trunks to get the above defined behavior.

OK, many thanks!