Passing calls between asterisk boxes using IAX

I’ve looked high and low on how to do this but I keep coming up empty, maybe I just haven’t found the right search phrase.

Anyway, what I’m trying to do is pass calls for different carriers/providers between asterisk boxes. So, for example, I’ve a PSTN line on one asterisk box (box 1) and voip provider on another (box 2) and none (just extensions) on a third (box 3).

I want to pass calls from box 3 that are destined for say 411 and Northamerican area codes to the box with the PSTN (box 1) and pass international calls to second box (box 2).

I need to figure out how to turn the call around from an inbound trunk to an outbound trunk. I’ve gotten plain extensions passing just fine but not off-net calls.

Any help is appreciated! :laughing:

[quote=“rdpierce”]I’ve looked high and low on how to do this but I keep coming up empty, maybe I just haven’t found the right search phrase.

Anyway, what I’m trying to do is pass calls for different carriers/providers between asterisk boxes. So, for example, I’ve a PSTN line on one asterisk box (box 1) and voip provider on another (box 2) and none (just extensions) on a third (box 3).

I want to pass calls from box 3 that are destined for say 411 and Northamerican area codes to the box with the PSTN (box 1) and pass international calls to second box (box 2).

I need to figure out how to turn the call around from an inbound trunk to an outbound trunk. I’ve gotten plain extensions passing just fine but not off-net calls.

Any help is appreciated! :laughing:[/quote]

I have several servers set up this way. In my example below, I take long distance calls from my PBX01 server and I route them to my PBX04 server utilizing an IAX trunk. On PBX04 I have a PRI card that is connected to yet another PBX (an NEC in this case) where I get physical dialtone. Using my example below, you could do this for any number of servers. Here is how I do it:

Two * servers, pbx01 and pbx04

pbx01

(iax.conf)

[pbx04]
type=friend
secret=blahblah
trunk=yes
context=inbound_866
trunk=yes
host=x.x.x.x
username=pbx01
disallow=all
allow=ulaw

(extensions.conf)

[globals]
OUTBOUND_TRUNK=IAX2/pbx01@pbx04

[pstn_outbound]
exten => _1NXXNXXXXXX,1,Dial,${OUTBOUND_TRUNK}/${EXTEN},tr
exten => _NXXXXXX,1,Dial,${OUTBOUND_TRUNK}/${EXTEN},tr

and on PBX04

(iax.conf)

[pbx01]
type=friend
secret=blahblah
context=from_pbx01
trunk=yes
host=x.x.x.x
setvar=HOMEAREACODE=858 ; What is this users home area code…?
setvar=INTERNATIONAL=YES ; Is this user allowed to make international calls
accountcode = PBX01 ; What is this users account code for tracking calls…?
username=pbx04
dissallow=all
allow=ulaw

(extensions.conf)

[globals]
OUT_1=ZAP/g1

[from_pbx01]

exten => _1NXXNXXXXXX,1,Dial,${OUT_1}/${EXTEN},tr
exten => _NXXXXXX,1,Dial,${OUT_1}/${EXTEN},tr

As a side note - there are many mays to do this, this is just the way I do it.

Hope this helps.

Richard, thanks for the help on that. We were able to get it to work following your example.

Out of curiosity, did you find that in a doco somewhere or just figure it out for yourself? The Asterisk scripting is really tough to follow, calling routines and applications without being clear on where they reside and passing variables that you don’t know exist… I’d be nice to find an good advanced config doc. somewhere.

Thanks Again!

Hey,

While I’ve got you here, is there a recommended method to perform trunk group access from certain extensions aside from passwording those trunks?

The thought being to permit certain extensions to, say, dial out while others can only dial SIP… seems like it should be a basic security feature, but the document seems to be mostly about auth codes and changing passwords.

Thanks! :confused:

[quote=“rdpierce”]Richard, thanks for the help on that. We were able to get it to work following your example.

Out of curiosity, did you find that in a doco somewhere or just figure it out for yourself? The Asterisk scripting is really tough to follow, calling routines and applications without being clear on where they reside and passing variables that you don’t know exist… I’d be nice to find an good advanced config doc. somewhere.

Thanks Again![/quote]

Actually I cannot remember how I came across it, but I spend a lot of time in the wiki and the docs (as well as the Asterisk book) when I am researching something and trying to make it work. The concept of trunking is covered in all three places and basically all we are doing is creating an IAX trunk between the systems and passing certain calls to different systems based on the dialplan.

[quote=“rdpierce”]Hey,

While I’ve got you here, is there a recommended method to perform trunk group access from certain extensions aside from passwording those trunks?

The thought being to permit certain extensions to, say, dial out while others can only dial SIP… seems like it should be a basic security feature, but the document seems to be mostly about auth codes and changing passwords.

Thanks! :confused:[/quote]

While I am sure there are many ways to do this, I would create a context and allow only those extensions that are in that context the ability to utilize that trunk. This is how I do it with my international traffic:

in sip.conf:

[1001]
type=friend
username="TJones"
secret=1001
qualify=500
host=dynamic
fromuser=“TJones Home” <8664231504>
dtmfmode=rfc2833
nat=yes ; This phone may be natted
canreinvite=no
disallow=all ; First disallow all codecs
allow=g729
callerid=“TJones Home” <8664231504>
context=ok_international

In my extensions.conf:

[ok_international]
include => international_calls_ok
include => normal_extensions

[normal_extensions]
include => pstn_outbound
include => system_extensions

[system_extensions]
include => no_international_calls
include => operator
include => conferences
etc, etc, etc

So in this case, this phone is dropped into the [ok_international] context any time he makes a call. That context includes access to the [international_calls_ok] context as well as all normal extensions. Regular extensions are placed into the [normal_extensions] context which includes system extensions and that includes the [no_international_calls] context which gives those folks a recording saying they are not allowed to make international calls.

Another way I do it on another system is a lot cleaner:

in sip.conf:

[rjs_linksys]
type = friend
host = dynamic
nat=yes
callerid = “Richard J. Sears” <2377>
secret = xxxxxxxxx
context = from-internal
mailbox = 2377@default
setvar=USERID=rjs
setvar=HOMEAREACODE=760 ; What is this users home area code…?
setvar=INTERNATIONAL=YES ; Is this user allowed to make international calls
accountcode = 18884 ; What is this users account code for tracking calls…?

Notice in this instance that I am setting a variable in the actual sip entry showing if international calls are allowed to be made by this extension. In my extensions.conf here is how I trap that info:

; For international calls, we have to check and see if the caller is allowed to
; make international calls or not.

exten => _011N.,1,GotoIf($["${INTERNATIONAL}" = “YES”]?international_ok:)
exten => _011N.,n,Answer
exten => _011N.,n,Wait,1
exten => _011N.,n,Playback(digium/pbx01_no_international_calls)
exten => _011N.,n,Playback(goodbye)
exten => _011N.,n,Macro(hangupcall)
exten => _011N.,n(international_ok),NoOp(International Call is ALLOWED from ${CALLERID} to ${EXTEN})
exten => _011N.,n,Macro(hangupcall)

In this particular case, you would replace the Macro(hangupcall) with whatever dial string you wanted.

If the variable is not set at all or set to NO they get a recordning letting them know they cannot make international calls.

All of this could be changed to allow access to an outside trunk or dialtone as opposed to internal only.

Hope this helps.

Richard,

I appreciate you taking the time to answer the question rather than flaming me and asking why I haven’t read some obscure article on an expired website which seems to happen the few times I’ve posted in the past!

Anyway, I’m having some issues implementing what you’ve taught me here.

I think I’ve followed the intention of what you’re getting at but I’m getting a 603 declined message on my soft phone when I try to access the protected route. Here’s what I’ve done:

extensions.conf:
[outrt-002-8]
;include => outrt-002-8-custom
;exten => _8.,1,Macro(dialout-trunk,3,${EXTEN:1},)
;exten => _8.,n,Macro(outisbusy,)
include => outrt-002-8_Work-custom
exten => _8.,1,GotoIf($["${INTERNATIONAL}" = “YES”]?international_ok:)
exten => _8.,n,Answer
exten => _8.,n,Wait,1
exten => _8.,n,Playback(digium/pbx01_no_international_calls)
exten => _8.,n,Playback(goodbye)
exten => _8.,n,Macro(hangupcall)
exten => _8.,n,(international_ok),NoOp(International Call is ALLOWED from ${CALLERID} to ${EXTEN})
exten => _8.,1,Macro(dialout-trunk,3,${EXTEN:1},)
exten => _8.,n,Macro(outisbusy,)

; end of [outrt-002-8]

sip.conf
[210]
username=210
type=friend
secret=blahblah
record_out=Adhoc
record_in=Adhoc
qualify=no
port=5060
nat=never
mailbox=210@device
host=dynamic
dtmfmode=rfc2833
context=from-internal
canreinvite=no
callerid=Bobs Desk <210>
setvar=INTERNATIONAL=YES

This is the dialing trace that shows on the asterisk console:asterisk1CLI>
– Executing GotoIf(“SIP/210-cf2a”, “1?international_ok:”) in new stack
– Executing Macro(“SIP/210-cf2a”, “hangupcall”) in new stack
– Executing ResetCDR(“SIP/210-cf2a”, “w”) in new stack
– Executing NoCDR(“SIP/210-cf2a”, “”) in new stack
– Executing Wait(“SIP/210-cf2a”, “5”) in new stack
– Executing Hangup(“SIP/210-cf2a”, “”) in new stack
asterisk1
CLI>

What the heck did I misunderstand?

Thanks

Couple of questions:

What does your from-internal context look like…? (not sure its an issue, just want to see it).

Next, Change the first three lines in you outrt-002-8-custom (all other lines remain unchanged)

exten => _8.,1,NoOp(International Call Allowed is set to ${INTERNATIONAL}

exten => _8.,n,GotoIf($["${INTERNATIONAL}" = "YES"]?international_ok:) 

exten => _8.,n,NoOp(International Call is DENIED from ${CALLERID} to ${EXTEN}) 

Also, when you run asterisk -rvvvvvvvvvvvvv from the command line and then try to make a call, paste what you see from that in here and let me take a look at it.

Make sure you issue the cli> set debug 0

before shutting down your cli access to *.

Sorry for the delay. I got distracted trying to figure out NAT and SIP… I’ve put everything back to the way it was and I’m ready to try again.

Here’s my SIP.conf for the extension:
[210]
username=210
type=friend
secret=blahblah
record_out=Adhoc
record_in=Adhoc
qualify=yes
port=5060
nat=yes
mailbox=210@device
host=dynamic
dtmfmode=rfc2833
context=from-internal
canreinvite=no
callerid=Bobs Desk <210>
setvar=INTERNATIONAL=YES

The extensions.conf with the route security:
[outrt-001-outgoing]
exten => _999.,1,NoOp(International Call Allowed is set to ${INTERNATIONAL})
exten => _999.,n,GotoIf($["${INTERNATIONAL}" = “YES”]?international_ok:)
exten => _999.,n,NoOp(International Call is DENIED from ${CALLERID} to ${EXTEN}) include => outrt-002-8_Work-custom
exten => _999.,1,GotoIf($["${INTERNATIONAL}" = “YES”]?international_ok:)
exten => _999.,n,Answer
exten => _999.,n,Wait,1
exten => _999.,n,Playback(digium/pbx01_no_international_calls)
exten => _999.,n,Playback(goodbye)
exten => _999.,n,Macro(hangupcall)
exten => _999.,n,(international_ok),NoOp(International Call is ALLOWED from ${CALLERID} to ${EXTEN})
exten => _999.,1,Macro(dialout-trunk,1,${EXTEN:3},)
exten => _999.,n,Macro(outisbusy,)

and the output of the verbose CLI:
asterisk1*CLI>
== Manager ‘admin’ logged on from 127.0.0.1
– Executing NoOp(“SIP/210-02eb”, “International Call Allowed is set to YES”) in new stack
– Executing GotoIf(“SIP/210-02eb”, “1?international_ok:”) in new stack
– Executing Macro(“SIP/210-02eb”, “hangupcall”) in new stack
– Executing ResetCDR(“SIP/210-02eb”, “w”) in new stack
– Executing NoCDR(“SIP/210-02eb”, “”) in new stack
– Executing Wait(“SIP/210-02eb”, “5”) in new stack
– Executing Hangup(“SIP/210-02eb”, “”) in new stack
– Executing NoOp(“SIP/210-3421”, “International Call Allowed is set to YES”) in new stack
– Executing GotoIf(“SIP/210-3421”, “1?international_ok:”) in new stack
– Executing Macro(“SIP/210-3421”, “hangupcall”) in new stack
– Executing ResetCDR(“SIP/210-3421”, “w”) in new stack
– Executing NoCDR(“SIP/210-3421”, “”) in new stack
– Executing Wait(“SIP/210-3421”, “5”) in new stack
– Executing Hangup(“SIP/210-3421”, “”) in new stack

It looks like the variable is getting passed along due to the output you had me add but it’s not jumping to the right section. I’ll check for all the brackets and what not, I had one missing earlier keeping the system from using the route at all…

Well, played with it for a bit and pretty much got it figured out. I used exact priority instead of the labels and that seemed to help.

The only thing left is getting Asterisk to use a route that wasn’t created through the GUI. Looks like when a route is created in the gui the route name is installed in extensions_additional as an include statement. I can’t seem to find where that gets placed outside that file; manual changes to that file get overwritten when you make a GUI config change.

Anyway, here’s what I changed to get working:
[outrt-001-outgoing]
exten => _999.,1,NoOp(International Call Allowed is set to ${INTERNATIONAL})
exten => _999.,n,GotoIf($["${INTERNATIONAL}" = “YES”]?100:)
exten => _999.,n,NoOp(International Call is DENIED from ${CALLERID} to ${EXTEN}) include => outrt-002-8_Work-custom
exten => _999.,n,Answer
exten => _999.,n,Wait,1
exten => _999.,n,Playback(welcome)
exten => _999.,n,Playback(goodbye)
exten => _999.,n,Macro(hangupcall)
exten => _999.,100,NoOp(International Call is ALLOWED from ${CALLERID} to ${EXTEN})
exten => _999.,n,Macro(dialout-trunk,1,${EXTEN:3},)
exten => _999.,n,Macro(outisbusy,)