Outbound Routes/Carrier Failover (solved)

I’ve setup the outbound routes and they work correctly, but what I’d like to do is on congestion to try an alternate outbound carrier. So I’ve tried using custom extensions and customer destinations.

Within extensions_customer.conf, I’ve added this script:

exten => _901152X.,1,Answer
exten => _901152X.,n,Macro(user-callerid,LIMIT,EXTERNAL,)
exten => _901152X.,n,Gosub(sub-record-check,s,1(out,${EXTEN},dontcare))
exten => _901152X.,n,ExecIf($[ “${CALLEE_ACCOUNCODE}” != “” ] ?Set(CDR(accountcode)=${CALLEE_ACCOUNCODE}))
exten => _901152X.,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _901152X.,n,Macro(dialout-trunk,3,10#52${EXTEN:5},on)
exten => _901152X.,n,Macro(dialout-trunk,4,40#52${EXTEN:5},off)
exten => _901152X.,n,Set(CALLERID(all)=${ROUTE_CIDSAVE})
exten => _901152X.,n,Set(_KEEPCID=TRUE)
exten => _901152X.,n,Hangup()
exten => _901152X.,n,Wait(1)

[2019-03-01 17:49:36] VERBOSE[32568][C-00000024] pbx.c: Executing [[email protected]:25] Dial(“PJSIP/222-00000035”, “PJSIP/10#5252X.@mysip,300,Tb(func-apply-sipheaders^s^1,(3))”) in new stack

When the congestion occurs, I can see the macro is being called properly, but it’s not pulling the DIAL_NUMBER from the initial outbound route. I believe it’s due to this line:

exten => _901152X.,n,Macro(dialout-trunk,3,10#52${EXTEN:5},on)

The EXTEN:5 isn’t proper I think? How do I pull the DIAL_NUMBER from the first outbound route?

Also if someone can explain how EXTEN is used and how that number following EXTEN is selected it would really clarify a few things.

Normally, you don’t need a special script. You simply list two or more trunks in the Outbound Route. If the trunking provider returns an error or if the number of concurrent calls exceeds the limit you specified, FreePBX will automatically try the next trunk in sequence.

If this doesn’t work for you, please explain what goes wrong or why it doesn’t meet your needs, and what your script is trying to do differently.

I already use multiple trunks to dial out, but would like to use a failover carrier if my carrier fails to complete.

For Mexico prefix, I would have agents dial 901152X, which then tries my SBC1, then SBC2 using a specific carrier. This is the outbound route I’ve created and this works perfectly.

However, if that specific carrier fails to complete the call, I’d like to retry with two other carriers to the same destination number.

What do you mean by ‘fails to complete’? If the carrier returns e.g. a 503 error, FreePBX should fail over automatically. If it’s a more subtle problem (poor voice quality, one-way audio, etc.), will the agent specify a different route by dialing differently when he tries again, or do you want the system to automatically choose a different path when the agent retries?

Also, what are SBC1 and SBC2? If these are your own security or load balancing devices, there should be no issue configuring trunks that select the appropriate carrier, e.g. by sending a prefix to the SBC. If they are devices supplied by your carrier(s), please explain the setup.

By fail to complete, I mean we get a 5XX or 6XX response from my outbound carrier. Agents are dialing a prefix to chose the route. I just want that route to retry with an alternate carrier if we get a 5XX/6XX from the first carrier.

The SBCs take the tech prefixes to determine the carrier we went to dial out with and then setup a new call leg with the specific carrier. However, I’m not getting that far because on the tech prefix and country code is being passed.

The call should flow like this:

Agent -> Outbound route to china using Sprint -> 6XX -> Try again with AT&T -> 6XX -> Try again with Verizon and then hangup if no answer

So again the problem with script is this:

Outbound route yields this SIP URI:

"PJSIP/80#[email protected]

After the script from my first post runs, I get this URI

Where am I going wrong in my script and how do I pull the DIAL_NUMBER from the outbound route?

I fixed it.

exten => _901152X.,n,Macro(dialout-trunk,3,10#52${DIAL_NUMBER:5},on)

Dial number sends the number dialed from the original macro and :5 trimmed the inital digits off of the string.

I’m glad to hear that you got it working, but I believe that you are doing mainstream failover, built into FreePBX, which does not require any coding.

Create Trunk1 with Outbound Dial Prefix 80# and Trunk2 with Outbound Dial Prefix 10#.
Then, create an Outbound Route with Trunk Sequence for Matched Routes: Trunk1, Trunk2 and Dial Pattern: prepend (blank) prefix 9011 match pattern 52X.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.