Dial out using Trunk Extension

Hi, my setup is verry simple, only 3 SIPextensions for home use…
I also have one cloud PBX, with 3 SIP extensions … if i want to call to those extensions, i use 1 extension as a trunk and then i call the other 2 left…
This was working perfect in FreePBX, but now i want to convert it to Asterisk … but cant figure it out

What i did in FreePBX:
reated 3 chan_sip extensions (local use), this is all working fine,…
Then created a chan_sip trunk , just outgoing is enough, dont need incoming…
This is what FreePBX created for the trunk in the sip files:

[64673-sip]
host=xxxx
username=64673
secret=xxx
type=peer
context=from-trunk-sip-64673-sip

My local extensions are 4 digits, the cloud extensions are 5 digits long…
So i created an outbound route in freePBX with pattern XXXXX

When i call from a local extension to another local ! Works
When i call from a local extension to another extension on cloud PBX, works!! it uses the above trunk

Below is what FreePBX created in extensions file, … I tried copying it to asterisk extensions file, but doesnt work

there is probably a lot of unneeded lines below…
How can i make a simple extensions file, that uses a dialplan like
When i call 4 digits, it needs to call to another local extension
When i call 5 digits, it needs to use that trunk that i specified in the sip.conf file

The trunk works, when i do a “Sip show peers” , i see it as state OK , the same as in freePBX

thnx for all the help!!


[globals]
OUT_2 = SIP/64673-sip
OUTCID_2 = 64673

[from-trunk-sip-64673-sip]
include => from-trunk-sip-64673-sip-custom
exten => _.,1,Set(GROUP()=OUT_2)
exten => _.,n,Goto(from-trunk,${EXTEN},1)

;--== end of [from-trunk-sip-64673-sip] ==--;

[ext-trunk]
include => ext-trunk-custom
exten => 2,1,Set(TDIAL_STRING=SIP/64673-sip)
exten => 2,n,Set(DIAL_TRUNK=2)
exten => 2,n,Goto(ext-trunk,tdial,1)

exten => tdial,1,Set(OUTBOUND_GROUP=OUT_${DIAL_TRUNK})
exten => tdial,n,GotoIf($["${OUTMAXCHANS_${DIAL_TRUNK}}" = ""]?nomax)
exten => tdial,n,GotoIf($[${GROUP_COUNT(OUT_${DIAL_TRUNK})} >= ${OUTMAXCHANS_${DIAL_TRUNK}}]?hangit)
exten => tdial,n(nomax),ExecIf($["${CALLINGNAMEPRES_SV}" != ""]?Set(CALLERPRES(name-pres)=${CALLINGNAMEPRES_SV}))
exten => tdial,n,ExecIf($["${CALLINGNUMPRES_SV}" != ""]?Set(CALLERPRES(num-pres)=${CALLINGNUMPRES_SV}))
exten => tdial,n,Set(DIAL_NUMBER=${FROM_DID})
exten => tdial,n,GosubIf($["${PREFIX_TRUNK_${DIAL_TRUNK}}" != ""]?sub-flp-${DIAL_TRUNK},s,1())
exten => tdial,n,Set(OUTNUM=${OUTPREFIX_${DIAL_TRUNK}}${DIAL_NUMBER})
exten => tdial,n,Set(DIAL_TRUNK_OPTIONS=${IF($["${DB_EXISTS(TRUNK/${DIAL_TRUNK}/dialopts)}" = "1"]?${DB_RESULT}:${TRUNK_OPTIONS})})
exten => tdial,n,Dial(${TDIAL_STRING}/${OUTNUM}${TDIAL_SUFFIX},${TRUNK_RING_TIMER},${DIAL_TRUNK_OPTIONS})
exten => tdial,n,Set(CALLERID(number)=${CALLERID(number):0:40})
exten => tdial,n,Set(CALLERID(name)=${CALLERID(name):0:40})
exten => tdial,n(hangit),Hangup

;--== end of [ext-trunk] ==--;

[outbound-allroutes]
include => outbound-allroutes-custom
include => outrt-2 ; 64673
exten => foo,1,Noop(bar)

;--== end of [outbound-allroutes] ==--;

[outrt-2] ; 64673
include => outrt-2-custom
exten => _XXXXX,1,Macro(user-callerid,LIMIT,EXTERNAL,)
exten => _XXXXX,n,Gosub(sub-record-check,s,1(out,${EXTEN},dontcare))
exten => _XXXXX,n,ExecIf($[ "${CALLEE_ACCOUNCODE}" != "" ] ?Set(CDR(accountcode)=${CALLEE_ACCOUNCODE}))
exten => _XXXXX,n,Set(_ROUTEID=2)
exten => _XXXXX,n,Set(_ROUTENAME=64673)
exten => _XXXXX,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _XXXXX,n,Set(_CALLERIDNAMEINTERNAL=${CALLERID(name)})
exten => _XXXXX,n,Set(_CALLERIDNUMINTERNAL=${CALLERID(num)})
exten => _XXXXX,n,Set(_EMAILNOTIFICATION=FALSE)
exten => _XXXXX,n,Set(_NODEST=)
exten => _XXXXX,n,Macro(dialout-trunk,2,${EXTEN},,off)
exten => _XXXXX,n,Macro(outisbusy,)

;--== end of [outrt-2] ==--;

I have found a good article, described here…

so in my sip.conf i have:

[trunk]
host=XXXX
username=64673
secret=XXXX
type=peer
context=from-trunk

All ok so far:

In my extensions i have:

[default]
; internal calls between extensions
exten => 8000,1,Dial(SIP/8000)
exten => 8000,n,Hangup()
exten => 8001,1,Dial(SIP/8001)
exten => 8001,n,Hangup()
exten => 8002,1,Dial(SIP/8002)
exten => 8002,n,Hangup()

; send all other numbers to outbound trunk
exten => _[0-9].,1,NoOp(#### [default] ####)
exten => _[0-9].,n,Set(CALLERID(num)=64673) ; set Caller ID
exten => _[0-9].,n,Dial(SIP/+${EXTEN}@trunk)       ; send call to trunk peer defined in sip.conf
exten => _[0-9].,n,Hang

I can call from 8002 to 8000 and 8001 = OK
When i call from 8002 to one of my cloud extensions i get below:

[Feb 28 10:49:15]     -- Registered SIP '8002' at 192.168.0.232:5060
[Feb 28 10:49:33]   == Using SIP VIDEO CoS mark 6
[Feb 28 10:49:33]   == Using SIP RTP CoS mark 5
[Feb 28 10:49:33]     -- Executing [64668@default:1] NoOp("SIP/8002-00000000", "#### [from-internal] ####") in new stack
[Feb 28 10:49:33]     -- Executing [64668@default:2] Set("SIP/8002-00000000", "CALLERID(num)=64673") in new stack
[Feb 28 10:49:33]     -- Executing [64668@default:3] Dial("SIP/8002-00000000", "SIP/+64668@trunk") in new stack
[Feb 28 10:49:33]   == Using SIP RTP CoS mark 5
[Feb 28 10:49:33]     -- Called SIP/+64668@trunk
[Feb 28 10:49:33]   == Everyone is busy/congested at this time (1:0/0/1)
[Feb 28 10:49:33]     -- Executing [64668@default:4] Hangup("SIP/8002-00000000", "") in new stack
[Feb 28 10:49:33]   == Spawn extension (default, 64668, 4) exited non-zero on 'SIP/8002-00000000'

What am i missing? this setup works on freePBX, but i want to use asterisk now :slight_smile:

sip debug log:


<------------->
--- (10 headers 0 lines) ---
Transmitting (no NAT) to 135.181.100.219:5060:
ACK sip:+64668@hostxxxx SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;branch=z9hG4bK3455e5f7
Max-Forwards: 70
From: "8002" <sip:64673@192.168.0.17>;tag=as05c9934b
To: <sip:+64668@hostxxxx>;tag=as32a8c8ca
Contact: <sip:64673@192.168.0.17:5060>
Call-ID: 558cb6f95c9bd93762b2c55824940c4d@192.168.0.17:5060
CSeq: 103 ACK
User-Agent: Asterisk PBX 18.2.2
Content-Length: 0


---
Scheduling destruction of SIP dialog '558cb6f95c9bd93762b2c55824940c4d@192.168.0.17:5060' in 32000 ms (Method: INVITE)
  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing [64668@default:4] Hangup("SIP/8002-00000006", "") in new stack
  == Spawn extension (default, 64668, 4) exited non-zero on 'SIP/8002-00000006'
Scheduling destruction of SIP dialog 'gtY8Jl7U1K' in 32000 ms (Method: INVITE)

<--- Reliably Transmitting (no NAT) to 192.168.0.232:5060 --->
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.0.232:5060;branch=z9hG4bK.icX7Om0AQ;received=192.168.0.232;rport=5060
From: "8002" <sip:8002@192.168.0.17>;tag=PaYObQr-2
To: sip:64668@192.168.0.17;tag=as577e6c84
Call-ID: gtY8Jl7U1K
CSeq: 21 INVITE
Server: Asterisk PBX 18.2.2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


<------------>

<--- SIP read from UDP:192.168.0.232:5060 --->
ACK sip:64668@192.168.0.17 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.232:5060;branch=z9hG4bK.icX7Om0AQ;rport
Call-ID: gtY8Jl7U1K
From: "8002" <sip:8002@192.168.0.17>;tag=PaYObQr-2
To: <sip:64668@192.168.0.17>;tag=as577e6c84
Contact: <sip:8002@192.168.0.232;transport=udp>;expires=3600;+sip.instance="<urn:uuid:f95ada1c-90bb-0060-b75e-4f7e6d20508b>"
Max-Forwards: 70
CSeq: 21 ACK

With FreePBX you should have been using intra-company trunks, not using a FreePBX extension as a “trunk”.

The first thing you should do is to move to chan_pjsip as chan_sip is unsupported, deprecated, and scheduled for removal next year.

Please read the documentation for username carefully. It shuldn’t do anything useful in your case, and its name was changed a very long time ago.

You have a bogus “+” in front of the SIP user being DIaled on the “trunk”.

Your SIP trace starts too late, but you can see the bogus + in the request URI in the ACK.

I don’t understand why you are not passing the originating extension number through as the caller ID.

Normally intracompany trunks

1 Like

omg that was it!! Much appreciated it now works, …
next step is indeed to change to pjsip!

i just copy pasted that example from that webpage…
the config files and the coding is al new to me

thnx, much appreciated!!

@david551

1 last question , with the code above it works!! witout that + sign
Now i want to add a queue config
How can i add that member there?

calling 64669 works, but how can i add it to a ring group?

i now have:

exten => _XXXX!,1,Dial(SIP/${EXTEN},45)
; send all other numbers to outbound trunk
exten => _XXXXX!,1,NoOp(#### [default] ####)
exten => _XXXXX!,n,Set(CALLERID(num)=64668)
exten => _XXXXX!,n,Dial(SIP/${EXTEN}@trunk,45)
exten => _XXXXX!,n,Hangup()

above works , calling to 8003 or 8001 or 64669

now added a queue:

exten => 8100,1,Answer
exten => 8100,n,Queue(ring,t,,,45)
exten => 8100,n,PlayBack(vm-goodbye)
exten => 8100,n,HangUp()

in queues.conf i have, but i think the syntax is wrong , 8003 and 8001 is being called, but not 64669

[ring]
strategy = ringall
member => SIP/8003
member => SIP/8001
member => SIP/64669@trunk

THNX!!

if i just clear out the 2 local members from queue , the 8003 and 8001 , i get an:
NOTICE[568][C-00000001]: chan_sip.c:24398 handle_response_invite: Failed to authenticate on INVITE to '“8002”

i think its because i dont specify the callerID , i think that one is important here

I don’t see where 8002 comes from.

You could always use a local channel to dial in the same way as if you called the number diectly.

yes, 8002 is the originator , i call from 8002 to 8100

not sure what you mean by:
You could always use a local channel to dial in the same way as if you called the number diectly.

can you translate that in syntax? :slight_smile:

or can i use somethig like (not queues)

exten => 666,1,NoOp(#### [default] ####)
exten => 666,n,Set(CALLERID(num)=64668)
exten => 666,n,Dial(SIP/64669@trunk,SIP/8003,SIP/8001,45)
exten => 666,n,Hangup()

i think its because , if i call that remote extension using trunk i need to set a different callerid , thats why i think it fails?

You seem to have set up the remote end to match by from user, which is a strange thing to do on an internal trunk. The best thing is to fix that.

Also, given that you are matching that way, you are setting the from user indirectly, by setting caller ID, which is also not sensible. You should set it directly.

https://wiki.asterisk.org/wiki/display/AST/Trivial+Local+Channel+Example

hmm, is this in the right direction? sorry, all new to me , never used this syntax lines :slight_smile:

exten => 666,1,NoOp(#### [default] ####)
exten => 666,n,Set(CALLERID(num)=64668)
exten => 666,n,Dial(SIP/64669@trunk,local@8003,local@8001,45)
exten => 666,n,Hangup()

https://wiki.asterisk.org/wiki/display/AST/Local+Channel

ok, think i got it!

much appreciated for the help!!

exten => 8100,1,Verbose(2,Call desk phone and mobile but with delay)
exten => 8100,n,Dial(Local/indoor-8003@extensions&Local/mobile-64675@extensions,30)
exten => 8100,n,Hangup()
 
[extensions]
; Dial the indoor station
exten => indoor-8003,1,Verbose(2,Dialing desk phone of extension 8003)
exten => indoor-8003,n,Dial(SIP/8003) 
                                               
; Dial the mobile 64675
exten => mobile-64675,1,Verbose(2,Dialing mobile of extension 201)
exten => mobile-64675,n,Verbose(2,-- Waiting 6 seconds before dialing)
exten => mobile-64675,n,Wait(2)
exten => mobile-64675,n,Set(CALLERID(num)=64668)
exten => mobile-64675,n,Dial(SIP/64675@trunk)

Just a drive by suggestion…

You can use the ‘same’ extension to increase the readability and robustness of your dialplan. Consider re-writing:

exten => 8100,1,Verbose(2,Call desk phone and mobile but with delay)
exten => 8100,n,Dial(Local/indoor-8003@extensions&Local/mobile-64675@extensions,30)
exten => 8100,n,Hangup()

as

exten = 8100,1,        verbose(2,Call desk phone and mobile but with delay)
 same = n,             dial(Local/indoor-8003@extensions&Local/mobile-64675@extensions,30)
 same = n,             hangup()

Less typing, less opportunities for errors.

Also, a little white space never hurts. :slight_smile:

1 Like

the only small problem left, is that when i abort the call, the other one stays ringing

ok, will write the code

any idea how i can abort the calls?
lets say, 8003 aborts the call, in the case above, the mobile 64675 stays ringng

You would need to provide protocol logs to understand what was going wrong.

Hey,

its not that there is an issue , or some problem
i just dont know how i need to implement the dialup in the syntax below
lets say, i call 8100 , 8003 starts ringing … if i abort the call before (no pickup), i want the call to 64675 abort too


exten => 8100,1,Verbose(2,Call desk phone and mobile but with delay)
exten => 8100,n,Dial(Local/indoor-8003@extensions&Local/mobile-64675@extensions,30)
exten => 8100,n,Hangup()
 
[extensions]
; Dial the indoor station
exten => indoor-8003,1,Verbose(2,Dialing desk phone of extension 8003)
exten => indoor-8003,n,Dial(SIP/8003) 
                                               
; Dial the mobile 64675
exten => mobile-64675,1,Verbose(2,Dialing mobile of extension 201)
exten => mobile-64675,n,Verbose(2,-- Waiting 6 seconds before dialing)
exten => mobile-64675,n,Wait(2)
exten => mobile-64675,n,Set(CALLERID(num)=64668)
exten => mobile-64675,n,Dial(SIP/64675@trunk)

That is how I’d expect it to behave. If that doesn’t happen, there is something wrong.