Requesting help on basic pjsip dialplan

I’d like to configure a simple setup using 2 asterisk servers.

The first server A at 192.168.1.101, is configured to accept any extension, playback a sound clip, and hangup. This works perfectly if I dial into A using a sip phone.

pjsip.conf

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

[receiver]
type=endpoint
context=receiver-answer
auth=receiver
aors=receiver
allow=all
direct_media=no

[receiver]
type=auth
auth_type=userpass
username=receiver
password=receiver

[receiver]
type=aor
max_contacts=10

[receiver]
type=identify
endpoint=receiver
match=192.168.1.102

extensions.conf

[receiver-answer]
exten => _.!,1,Verbose(0, "${EXTEN} answered")
    same => n,Set(NUMBER=${EXTEN})
    same => n,Answer()
    same => n,Playback(xencall/kennedy-inaugural-speech-15-min)
    same => n,Hangup()

exten => h,1,Verbose(0, "${NUMBER} hung up (cause: ${HANGUPCAUSE})")
    same => n,Hangup()

The second server B at 192.168.1.102, is configured to accept any extension and route it to A, so that the result will be the same as above (i.e. the caller will hear the sound clip and then auto-hangup).

pjsip.conf

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

[sender]
type=endpoint
context=sender-forward
auth=sender
aors=sender
allow=all
direct_media=no

[sender]
type=auth
auth_type=userpass
username=sender
password=sender

[sender]
type=aor
max_contacts=10

[receiver]
type=endpoint
outbound_auth=receiver
aors=receiver
allow=all
direct_media=no

[receiver]
type=auth
auth_type=userpass
username=receiver
password=receiver

[receiver]
type=aor
contact=sip:192.168.1.101:5060

extensions.conf

[sender-forward]
exten => _.!,1,Verbose(0, "${EXTEN} forwarded")
    same => n,Set(NUMBER=${EXTEN})
    same => n,Dial(PJSIP/${EXTEN}@receiver)
    same => n,Playback(invalid)
    same => n,Hangup()

exten => h,1,Verbose(0, "${NUMBER} hung up (cause: ${HANGUPCAUSE})")
    same => n,Hangup()

But when I use a SIP phone to call into B, I get disconnected immediately. These are the logs.

A

  == Setting global variable 'SIPDOMAIN' to '192.168.1.101'
    -- Executing [002@receiver-answer:1] Verbose("PJSIP/receiver-00000003", "0, "002 answered"") in new stack
 "002 answered"
    -- Executing [002@receiver-answer:2] Set("PJSIP/receiver-00000003", "NUMBER=002") in new stack
    -- Executing [002@receiver-answer:3] Answer("PJSIP/receiver-00000003", "") in new stack
  == Spawn extension (receiver-answer, 002, 3) exited non-zero on 'PJSIP/receiver-00000003'
    -- Executing [h@receiver-answer:1] Verbose("PJSIP/receiver-00000003", "0, "002 hung up (cause: 127)"") in new stack
 "002 hung up (cause: 127)"
    -- Executing [h@receiver-answer:2] Hangup("PJSIP/receiver-00000003", "") in new stack
  == Spawn extension (receiver-answer, h, 2) exited non-zero on 'PJSIP/receiver-00000003'

B

  == Setting global variable 'SIPDOMAIN' to '192.168.1.102'
    -- Executing [002@sender-forward:1] Verbose("PJSIP/sender-00000023", "0, "002 forwarded"") in new stack
 "002 forwarded"
    -- Executing [002@sender-forward:2] Set("PJSIP/sender-00000023", "NUMBER=002") in new stack
    -- Executing [002@sender-forward:3] Dial("PJSIP/sender-00000023", "PJSIP/002@receiver") in new stack
    -- Called PJSIP/002@receiver
    -- PJSIP/receiver-00000024 answered PJSIP/sender-00000023
    -- Channel PJSIP/receiver-00000024 joined 'simple_bridge' basic-bridge <b2905cff-fa9d-4d84-9192-f5439d55ffda>
    -- Channel PJSIP/sender-00000023 joined 'simple_bridge' basic-bridge <b2905cff-fa9d-4d84-9192-f5439d55ffda>
[May 30 22:32:06] WARNING[1384]: res_pjsip_session.c:1826 sip_session_refresh: Failed to create reinvite properly.
    -- Channel PJSIP/receiver-00000024 left 'simple_bridge' basic-bridge <b2905cff-fa9d-4d84-9192-f5439d55ffda>
    -- Channel PJSIP/sender-00000023 left 'simple_bridge' basic-bridge <b2905cff-fa9d-4d84-9192-f5439d55ffda>
  == Spawn extension (sender-forward, 002, 3) exited non-zero on 'PJSIP/sender-00000023'
    -- Executing [h@sender-forward:1] Verbose("PJSIP/sender-00000023", "0, "002 hung up (cause: 127)"") in new stack
 "002 hung up (cause: 127)"
    -- Executing [h@sender-forward:2] Hangup("PJSIP/sender-00000023", "") in new stack
  == Spawn extension (sender-forward, h, 2) exited non-zero on 'PJSIP/sender-00000023'

It seems that server A successfully connects to B, and the calls are bridged, but then they are immediately disconnected (with hangup code 127).

What am I doing wrong?

I think your first mistake becomes how you are defined dial plan, both system it use same pattern

Better if you can defined specific numbers for each system.

_.! isn’t a valid pattern. My guess is that it is being treated as _.

That is not your problem.

I think we need to see to see the actual SIP messages, but, without looking at the code to see where that message is generated, my suspicion is you have a NAT problem and the client Asterisk cannot resolve the contact address from the server one.

Thanks for the reply, Rmcgrath

If I define specific extensions, then my specific requirement isn’t met. But testing with specific extension numbers is a good idea.

So I replaced the catch-all _.! extension with specific ones. Unfortunately, the same thing happened. I’m wondering if the following line is a clue to what’s going wrong.

WARNING[1384]: res_pjsip_session.c:1826 sip_session_refresh: Failed to create reinvite properly.

The Warning is what I was assumed was the first indication of a problem.

Thanks for the reply, david551.

There is no NAT. Both asterisk servers are running in the same local-area-network.

But you are right, looking at the actual SIP messages should give me a better clue. I’ll turn on sip logging and check them out.

(BTW, I tried googling that “re-invite” error message, but got nowhere. So would appreciate some insight in that direction, if any).

So I checked out the SIP packets.

  • Server B received an INVITE from my sip phone, and proceeded to send an INVITE to Server A, and got a response OK.

  • However, immediately after, both Server A and Server B proceed to send BYE to each other, and then both respond OK to each other. I don’t understand why.

  • This is when the WARNING[1581]: res_pjsip_session.c:1826 sip_session_refresh: Failed to create reinvite properly. error is logged.

  • Finally, Server A sends BYE to my sip phone.

I’m thinking I have some fundamental misunderstanding of the dialplan that is causing this instant BYE to each other.

Any ideas?

It is PJSIP itself that is faulting. The failing call is:

if (pjsip_inv_reinvite(inv_session, NULL, new_sdp, &tdata)) {

and the interface specification for that is https://www.pjsip.org/pjsip/docs/html/group__PJSIP__INV.htm#ga7f7f847cbb1135ca5c023f2ee0687be8

I’m not exactly sure the routine in Asterisk that is calling it is being called, but, at the moment I can only think that that the request URI is not usable.

The standard PJSIP code is in https://svn.pjsip.org/repos/pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c It looks more like it is SDP related, but it looks like Asterisk throws away the detailed error status. I’m not sure if Asterisk modifies the PJSIP code.

Thanks for the responses david551.

I’m using a fresh installation of standard Asterisk 16.10. I would be wary of thinking this is because of an issue with Asterisk or PJSIP. :slight_smile: I am assuming it has to be something wrong with the way I configured pjsip or my dialplan. I’ve changed nothing else.

I hope someone spots my mistake.

Also, the HANGUPCAUSE is 127, which is Connectivity Error according to https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause+Mappings.

I reckon this means I’m probably missing some necessary configuration for the pjsip endpoints or authentication.

Well is quite hard to understand your scenario, but based what you said “
It seems that server A successfully connects to B, and the calls are bridged, but then they are immediately disconnected (with hangup code 127). “ Could be possibility call originated to B and return back again to A and A return to B again.

So if that happens you need to define context.

I do appreciate all the advise people provided. Unfortunately, I was unable to resolve my original problem.

HOWEVER, I switched to using SIP instead of PJSIP, and everything worked perfectly. I suspect I may have a buggy installation of Asterisk. I’ll stick with SIP for now, and then upgrade to the latest Asterisk 16.10 LTS later.

1 Like

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