Outgoing context for foo provider

I’m trying to understand why I can’t dial out through a SIP peer acting as a trunk.

In what way are these two attempts to dial an outbound number different? The first at least reaches the peer for trunking? What’s happening, in particular, with the first call?

My inclination is for three contexts: internal, inbound and outbound. I don’t quite understand why https://www.beardy.se/how-to-set-up-a-sip-trunk-in-the-asterisk-pbx only has incoming and myphones, with myphones also directing to…foo provider? In sip.conf foo provider has a context of incoming but then is being used to dial out…which makes my head hurt.

Having difficulty following the chain of events from the last few lines of myphones context where foo provider is invoked. Good, yes, use foo provider to dial out…but shouldn’t foo provider not have an incoming context if it’s being used for outgoing calls?

mordor*CLI> 
mordor*CLI> channel originate SIP/thufir extension 918002506510@myphones
  == Using SIP RTP CoS mark 5
    -- Called thufir
    -- SIP/thufir-0000002c is ringing
    -- SIP/thufir-0000002c answered
    -- Executing [918002506510@myphones:1] Log("SIP/thufir-0000002c", "NOTICE, Dialing out from "" <> to 18002506510 through 12345678GW1") in new stack
[Jul  2 04:52:14] NOTICE[6787][C-00000026]: Ext. 918002506510:1 @ myphones:  Dialing out from "" <> to 18002506510 through 12345678GW1
    -- Executing [918002506510@myphones:2] Dial("SIP/thufir-0000002c", "SIP/12345678GW1/18002506510,60") in new stack
  == Using SIP RTP CoS mark 5
    -- Called SIP/12345678GW1/18002506510
    -- SIP/12345678GW1-0000002d answered SIP/thufir-0000002c
    -- Channel SIP/thufir-0000002c joined 'simple_bridge' basic-bridge <6ed476b6-9c9e-4833-bc04-70e405f43dd2>
    -- Channel SIP/12345678GW1-0000002d joined 'simple_bridge' basic-bridge <6ed476b6-9c9e-4833-bc04-70e405f43dd2>
    -- Channel SIP/thufir-0000002c left 'native_rtp' basic-bridge <6ed476b6-9c9e-4833-bc04-70e405f43dd2>
  == Spawn extension (myphones, 918002506510, 2) exited non-zero on 'SIP/thufir-0000002c'
    -- Channel SIP/12345678GW1-0000002d left 'native_rtp' basic-bridge <6ed476b6-9c9e-4833-bc04-70e405f43dd2>
mordor*CLI> 
mordor*CLI> 
mordor*CLI> channel originate SIP/thufir extension 918002506510@incoming
  == Using SIP RTP CoS mark 5
    -- Called thufir
    -- SIP/thufir-0000002e is ringing
    -- SIP/thufir-0000002e answered
[Jul  2 04:52:44] WARNING[6792][C-00000027]: pbx.c:6492 __ast_pbx_run: Channel 'SIP/thufir-0000002e' sent to invalid extension but no invalid handler: context,exten,priority=incoming,918002506510,1
mordor*CLI> 
mordor*CLI> 

peers and trunk:

mordor*CLI> 
mordor*CLI> sip show peers
Name/username             Host                                    Dyn Forcerport Comedia    ACL Port     Status      Description                      
12345678GW1/42654565      63.247.69.226                               Yes        Yes            5060     OK (85 ms)                                   
12345678GW2/42654565      63.247.69.226                               Yes        Yes            5060     OK (82 ms)                                   
demo_alice                (Unspecified)                            D  Yes        Yes            0        UNKNOWN                                      
demo_bob                  (Unspecified)                            D  Yes        Yes            0        UNKNOWN                                      
hawat/hawat               192.168.1.6                              D  Yes        Yes            5060     OK (410 ms)                                  
thufir/thufir             192.168.1.5                              D  Yes        Yes            5062     OK (9 ms)                                    
6 sip peers [Monitored: 4 online, 2 offline Unmonitored: 0 online, 0 offline]
mordor*CLI> 
mordor*CLI> sip show peer 12345678GW1


  * Name       : 12345678GW1
  Description  : 
  Secret       : <Set>
  MD5Secret    : <Not set>
  Remote Secret: <Not set>
  Context      : incoming
  Record On feature : automon
  Record Off feature : automon
  Subscr.Cont. : <Not set>
  Language     : 
  Tonezone     : <Not set>
  AMA flags    : Unknown
  Transfer mode: open
  CallingPres  : Presentation Allowed, Not Screened
  FromDomain   : gw1.siptrunk.com Port 5060
  Callgroup    : 
  Pickupgroup  : 
  Named Callgr : 
  Nam. Pickupgr: 
  MOH Suggest  : 
  Mailbox      : 
  VM Extension : asterisk
  LastMsgsSent : 0/0
  Call limit   : 0
  Max forwards : 0
  Dynamic      : No
  Callerid     : "" <>
  MaxCallBR    : 384 kbps
  Expire       : -1
  Insecure     : invite
  Force rport  : Yes
  Symmetric RTP: Yes
  ACL          : No
  DirectMedACL : No
  T.38 support : No
  T.38 EC mode : Unknown
  T.38 MaxDtgrm: 4294967295
  DirectMedia  : No
  PromiscRedir : No
  User=Phone   : No
  Video Support: No
  Text Support : No
  Ign SDP ver  : No
  Trust RPID   : Yes
  Send RPID    : No
  Path support : No
  Path         : N/A
  TrustIDOutbnd: Legacy
  Subscriptions: Yes
  Overlap dial : No
  DTMFmode     : rfc2833
  Timer T1     : 500
  Timer B      : 32000
  ToHost       : gw1.siptrunk.com
  Addr->IP     : 63.247.69.226:5060
  Defaddr->IP  : (null)
  Prim.Transp. : UDP
  Allowed.Trsp : UDP
  Def. Username: 42654565
  SIP Options  : (none)
  Codecs       : (ulaw|alaw|gsm)
  Auto-Framing : No
  Status       : OK (85 ms)
  Useragent    : 
  Reg. Contact : 
  Qualify Freq : 30000 ms
  Keepalive    : 0 ms
  Sess-Timers  : Refuse
  Sess-Refresh : uas
  Sess-Expires : 1800 secs
  Min-Sess     : 90 secs
  RTP Engine   : asterisk
  Parkinglot   : 
  Use Reason   : No
  Encryption   : No

dialplan:

mordor*CLI> 
mordor*CLI> dialplan show 
__func_periodic_hook_context__  ael-builtin-h-bubble            ael-default                     ael-demo                        
ael-dundi-e164                  ael-dundi-e164-canonical        ael-dundi-e164-customers        ael-dundi-e164-local            
ael-dundi-e164-lookup           ael-dundi-e164-switch           ael-dundi-e164-via-pstn         ael-iaxprovider                 
ael-iaxtel700                   ael-international               ael-local                       ael-longdistance                
ael-std-exten-ael               ael-trunkint                    ael-trunkld                     ael-trunklocal                  
ael-trunktollfree               chanvar                         default                         demo                            
globals                         local                           myphones                        parkedcalls                     
public                          incoming                        
mordor*CLI> dialplan show myphones 
[ Context 'myphones' created by 'pbx_config' ]
  '1000' =>         1. Dial(SIP/1000)                             [pbx_config]
                    2. Hangup()                                   [pbx_config]
  '1001' =>         1. Dial(SIP/1001)                             [pbx_config]
                    2. Hangup()                                   [pbx_config]
  '201' =>          1. Answer()                                   [pbx_config]
                    2. Playback(tt-monty-knights)                 [pbx_config]
                    3. Hangup()                                   [pbx_config]
  '202' =>          1. Answer()                                   [pbx_config]
                    2. Playback(welcome)                          [pbx_config]
                    3. Playback(demo-echotest)                    [pbx_config]
                    4. Echo()                                     [pbx_config]
                    5. Playback(demo-echodone)                    [pbx_config]
                    6. Playback(vm-goodbye)                       [pbx_config]
                    7. Hangup()                                   [pbx_config]
  '4000' =>         1. Playback(tt-monkeys)                       [pbx_config]
  '5000' =>         1. Playback(tt-monkeysintro)                  [pbx_config]
  '555' =>          1. Playback(hello-world)                      [pbx_config]
                    2. Playback(echo-test)                        [pbx_config]
                    3. Echo()                                     [pbx_config]
                    4. Playback(demo-echodone)                    [pbx_config]
  '6001' =>         1. Dial(SIP/demo_alice,20)                    [pbx_config]
  '6002' =>         1. Dial(SIP/demo_bob,20)                      [pbx_config]
  '6003' =>         1. Dial(SIP/thufir,20)                        [pbx_config]
  '6004' =>         1. Dial(SIP/hawat,20)                         [pbx_config]
  '_9XXXX.' =>      1. Log(NOTICE, Dialing out from ${CALLERID(all)} to ${EXTEN:1} through 12345678GW1) [pbx_config]
                    2. Dial(SIP/12345678GW1/${EXTEN:1},60)        [pbx_config]
                    3. Playtones(congestion)                      [pbx_config]
                    4. Hangup()                                   [pbx_config]

-= 12 extensions (28 priorities) in 1 context. =-
mordor*CLI> 
mordor*CLI> 
mordor*CLI> dialplan show incoming
[ Context 'incoming' created by 'pbx_config' ]
  's' =>            1. Log(NOTICE, Incoming call from ${CALLERID(all)}) [pbx_config]
                    2. Dial(SIP/1000)                             [pbx_config]
                    3. Hangup()                                   [pbx_config]

-= 1 extension (3 priorities) in 1 context. =-
mordor*CLI> 

I’ve tried many variations on dialing the number to match the pattern. this is largely based on:

What do you want to do, why do you try to dial out from the cli? Give more details or else noone can help you.

I’m just trying to dial from either thufir or hawat, both attached devices. The thufir device is on a hardphone, the hawat device is on a softphone (Csip) on Android. The doc I’m also referencing is:

which seems to omit the dialplan specifics. However:

says that they just need ten digits, basically.

I was on the CLI trying to initiate calls with variations to find out which worked. Prepend with a 9, don’t prepend, etc. My conclusion was that there’s something wrong, most likely, with the dialplan, specifically relating to the myphones context.

Rather than trying to put a system together from half understood examples, please go to http://www.asteriskdocs.org/ and read up how Asterisk configurations really work.

Seem to have solved it to a degree in by using include => outgoing in myphones so that there’s not any duplicated code.

mordor*CLI> 
mordor*CLI> channel originate SIP/thufir extension 18003569377@outgoing
  == Using SIP RTP CoS mark 5
    -- Called thufir
    -- SIP/thufir-0000002e is ringing
    -- SIP/thufir-0000002e answered
    -- Executing [18003569377@outgoing:1] NoOp("SIP/thufir-0000002e", "") in new stack
    -- Executing [18003569377@outgoing:2] Log("SIP/thufir-0000002e", "NOTICE, Dialing out from "" <> to 8003569377 through TELNYX") in new stack
[Jul  3 00:23:36] NOTICE[5328][C-00000022]: Ext. 18003569377:2 @ outgoing:  Dialing out from "" <> to 8003569377 through TELNYX
    -- Executing [18003569377@outgoing:3] Dial("SIP/thufir-0000002e", "SIP/TELNYX/8003569377,60") in new stack
  == Using SIP RTP CoS mark 5
    -- Called SIP/TELNYX/8003569377
       > 0x7f25a0060900 -- Probation passed - setting RTP source address to 192.168.1.5:16390
    -- SIP/TELNYX-0000002f is ringing
    -- SIP/TELNYX-0000002f is making progress passing it to SIP/thufir-0000002e
       > 0x7f2590008a80 -- Probation passed - setting RTP source address to 64.16.240.36:27938
    -- SIP/TELNYX-0000002f answered SIP/thufir-0000002e
    -- Channel SIP/thufir-0000002e joined 'simple_bridge' basic-bridge <8dc1f203-8fc8-4791-bc5b-0f1517b9449d>
    -- Channel SIP/TELNYX-0000002f joined 'simple_bridge' basic-bridge <8dc1f203-8fc8-4791-bc5b-0f1517b9449d>
       > Bridge 8dc1f203-8fc8-4791-bc5b-0f1517b9449d: switching from simple_bridge technology to native_rtp
    -- Channel SIP/thufir-0000002e left 'native_rtp' basic-bridge <8dc1f203-8fc8-4791-bc5b-0f1517b9449d>
    -- Channel SIP/TELNYX-0000002f left 'native_rtp' basic-bridge <8dc1f203-8fc8-4791-bc5b-0f1517b9449d>
  == Spawn extension (outgoing, 18003569377, 3) exited non-zero on 'SIP/thufir-0000002e'
mordor*CLI> 
  == Using SIP RTP CoS mark 5
    -- Executing [18003563977@myphones:1] NoOp("SIP/thufir-00000030", "") in new stack
    -- Executing [18003563977@myphones:2] Log("SIP/thufir-00000030", "NOTICE, Dialing out from "thufir" <thufir> to 8003563977 through TELNYX") in new stack
[Jul  3 00:23:55] NOTICE[5330][C-00000023]: Ext. 18003563977:2 @ myphones:  Dialing out from "thufir" <thufir> to 8003563977 through TELNYX
    -- Executing [18003563977@myphones:3] Dial("SIP/thufir-00000030", "SIP/TELNYX/8003563977,60") in new stack
  == Using SIP RTP CoS mark 5
    -- Called SIP/TELNYX/8003563977
    -- SIP/TELNYX-00000031 is ringing
    -- SIP/TELNYX-00000031 is making progress passing it to SIP/thufir-00000030
    -- SIP/TELNYX-00000031 answered SIP/thufir-00000030
    -- Channel SIP/thufir-00000030 joined 'simple_bridge' basic-bridge <9a346de5-64eb-480b-8d6c-d0253fceeb7f>
    -- Channel SIP/TELNYX-00000031 joined 'simple_bridge' basic-bridge <9a346de5-64eb-480b-8d6c-d0253fceeb7f>
       > Bridge 9a346de5-64eb-480b-8d6c-d0253fceeb7f: switching from simple_bridge technology to native_rtp
       > 0x7f25d0009dd0 -- Probation passed - setting RTP source address to 192.168.1.5:16392
       > 0x7f259000ae20 -- Probation passed - setting RTP source address to 64.16.240.36:19754
    -- Channel SIP/thufir-00000030 left 'native_rtp' basic-bridge <9a346de5-64eb-480b-8d6c-d0253fceeb7f>
    -- Channel SIP/TELNYX-00000031 left 'native_rtp' basic-bridge <9a346de5-64eb-480b-8d6c-d0253fceeb7f>
  == Spawn extension (myphones, 18003563977, 3) exited non-zero on 'SIP/thufir-00000030'
mordor*CLI> 
mordor*CLI> 
mordor*CLI> dialplan show 
__func_periodic_hook_context__  ael-builtin-h-bubble            ael-default                     ael-demo                        
ael-dundi-e164                  ael-dundi-e164-canonical        ael-dundi-e164-customers        ael-dundi-e164-local            
ael-dundi-e164-lookup           ael-dundi-e164-switch           ael-dundi-e164-via-pstn         ael-iaxprovider                 
ael-iaxtel700                   ael-international               ael-local                       ael-longdistance                
ael-std-exten-ael               ael-trunkint                    ael-trunkld                     ael-trunklocal                  
ael-trunktollfree               chanvar                         default                         demo                            
globals                         local                           outgoing                        parkedcalls                     
public                          myphones                        
mordor*CLI> dialplan show myphones 
[ Context 'myphones' created by 'pbx_config' ]
  '1000' =>         1. Dial(SIP/1000)                             [pbx_config]
                    2. Hangup()                                   [pbx_config]
  '1001' =>         1. Dial(SIP/1001)                             [pbx_config]
                    2. Hangup()                                   [pbx_config]
  '201' =>          1. Answer()                                   [pbx_config]
                    2. Playback(tt-monty-knights)                 [pbx_config]
                    3. Hangup()                                   [pbx_config]
  '202' =>          1. Answer()                                   [pbx_config]
                    2. Playback(welcome)                          [pbx_config]
                    3. Playback(demo-echotest)                    [pbx_config]
                    4. Echo()                                     [pbx_config]
                    5. Playback(demo-echodone)                    [pbx_config]
                    6. Playback(vm-goodbye)                       [pbx_config]
                    7. Hangup()                                   [pbx_config]
  '4000' =>         1. Playback(tt-monkeys)                       [pbx_config]
  '5000' =>         1. Playback(tt-monkeysintro)                  [pbx_config]
  '555' =>          1. Playback(hello-world)                      [pbx_config]
                    2. Playback(echo-test)                        [pbx_config]
                    3. Echo()                                     [pbx_config]
                    4. Playback(demo-echodone)                    [pbx_config]
  '6001' =>         1. Dial(SIP/demo_alice,20)                    [pbx_config]
  '6002' =>         1. Dial(SIP/demo_bob,20)                      [pbx_config]
  '6003' =>         1. Dial(SIP/thufir,20)                        [pbx_config]
  '6004' =>         1. Dial(SIP/hawat,20)                         [pbx_config]
  Include =>        'outgoing'                                    [pbx_config]

-= 11 extensions (24 priorities) in 1 context. =-
mordor*CLI> 
mordor*CLI> dialplan show outgoing 
[ Context 'outgoing' created by 'pbx_config' ]
  '_1NXXNXXXXXX' => 1. NoOp()                                     [pbx_config]
                    2. Log(NOTICE, Dialing out from ${CALLERID(all)} to ${EXTEN:1} through TELNYX) [pbx_config]
                    3. Dial(SIP/TELNYX/${EXTEN:1},60)             [pbx_config]
                    4. Playtones(congestion)                      [pbx_config]
                    5. Hangup()                                   [pbx_config]

-= 1 extension (5 priorities) in 1 context. =-
mordor*CLI> 

Not sure that this is at all robust, but works for at least one test call, and allows dialing from the hard phone. Still don’t know how to configure the incoming context, however.