Sydney Staff SRE or something.

Asterisk – Specifying outbound routes for fun and profit

· by Robert Mibus · Read in about 2 min · (306 Words)
asterisk sysadmin voip

…or at least a little savings.

You’re in a quandry. You’ve found VSP1, with brilliant general rates. VSP2 has fantastic rates for mobile calls. VSP3 has the cheapest calls of all to England, where you have family. You can’t use just the best bits of each… can you?

With Asterisk, yes you can!

The extension configs here assume that you’ve set up your VSP peers already as vsp1, vsp2, and vsp3.

Starting with your usual outbound context:

[regular_outbound]
; Handle calls out
exten => _XX.,1,Dial(SIP/${EXTEN}@vsp1,,)
;

Add in some new patterns for the different call types. (0011 is the code to dial an international number from Australia, 44 is the UK “country code”, and 04 is the prefix for all mobile phones, which are always ten digits).

[regular_outbound]
; Mobiles go via VSP2
exten => _04XXXXXXXX,1,Dial(SIP/${EXTEN}@vsp2,,)
; UK numbers via VSP3
exten => _001144.,1,Dial(SIP/${EXTEN}@vsp3,,)
; Handle all other calls out
exten => _XX.,1,Dial(SIP/${EXTEN}@vsp1,,)
;

After some time, you find out that VSP3 isn’t terribly reliable. Rather than just disallow the call at all, instead let’s use VSP1 as a fallback.

Instead of:

; UK numbers via VSP3
exten => _001144.,1,Dial(SIP/${EXTEN}@vsp3,,)
;

Do:

; UK numbers via VSP3, fallback to VSP1
exten => _001144.,1,Dial(SIP/${EXTEN}@vsp3,,)
exten => _001144.,2,Dial(SIP/${EXTEN}@vsp1,,)
;

If the first Dial() statement succeeds, the dialplan execution will not continue. If it fails, the next statement will execute, thus running the second Dial() via VSP1. (This functionality is more commonly used to implement line hunting, or to redirect to voicemail on busy and no-answer).

Note that in some cases, the call may actually happen twice - if the remote end is genuinely busy, for instance. You can check the contents of ${DIALSTATUS} and only redirect in some cases - but then you might not fall through if VSP3 incorrectly gives you a busy tone instead of ringing!