(Solved)(PJSIP) Inbound SIP call not routing to the defined context in endpoint

I just switched from Asterisk 13 to 16.2.0 and try now the existing setup with pjsip instead of sip .
So far it works more or less with the same functionality as before.

The unwanted effect I have now, is that calls to the number 0442222222 or number 0443333333 are ending always in the context inbound-sc-0441111111 instead of the configured contexts inbound-sc-0442222222 or inbound-sc-0443333333.

Every call goes always to the context which is defined in the first endpoint.

What I am doing wrong? What I have overlooked?

Due this issue, currently I have to handle all extensions within the context inbound-sc-0441111111 .

Current initial situation I have:

  • 3 different SIP accounts from the same provider for the phonenumbers 0441111111, 0442222222, 0443333333 (all fictitious within the supplied configs).
  • for each account I have defined an individual context within the endpoint. So each phonenumber should have an individual context within the dialplan.
  • Asterisk is behind a NAT

For information I have supplied pjsip.conf / pjsip_wizard.conf / generated pjsip config / CLI outputs. I hope this helps.

Thanks a lot for every hint for solving this issue

-Felix

pjsip.conf:

[global]
type = global
language = de
endpoint_identifier_order = ip,username

[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060
local_net = 192.168.1.0/16

pjsip_wizard.conf:

[swisscom-template](!)
type = wizard
transport = transport-udp

sends_auth = yes
sends_registrations = yes
remote_hosts = swisscom.ch

endpoint/allow=!all,g722,alaw
endpoint/from_domain=swisscom.ch
endpoint/outbound_proxy = sip:fs1.ims.swisscom.ch:5060\;lr
endpoint/user_eq_phone = true

identify/match = fs1.ims.swisscom.ch

registration/server_uri=sip:swisscom.ch
registration/outbound_proxy = sip:fs1.ims.swisscom.ch:5060\;lr

[sc-0441111111](swisscom-template)
client_uri_pattern = sip:+41441111111@${REMOTE_HOST}
endpoint/from_user=+41441111111
aor/contact=sip:+41441111111@swisscom.ch
outbound_auth/username =USERNAME40441111111
outbound_auth/password =PASSWORD40441111111
registration/contact_user=sc-0441111111
endpoint/context=inbound-sc-0441111111

[sc-0442222222](swisscom-template)
client_uri_pattern = sip:+41442222222@${REMOTE_HOST}
endpoint/from_user=+41442222222
aor/contact=sip:+41442222222@swisscom.ch
outbound_auth/username =USERNAME40442222222
outbound_auth/password =PASSWORD40442222222
registration/contact_user=sc-0442222222
endpoint/context=inbound-sc-0442222222

[sc-0443333333](swisscom-template)
client_uri_pattern = sip:+41443333333@${REMOTE_HOST}
endpoint/from_user=+41443333333
aor/contact=sip:+41443333333@swisscom.ch
outbound_auth/username =USERNAME40443333333
outbound_auth/password =PASSWORD40443333333
registration/contact_user=sc-0443333333

Generated pjsip config based on pjsip_wizard.conf (‘pjsip export config_wizard primitives’):

[sc-0441111111-oauth]
type = auth
username = USERNAME40441111111
@pjsip_wizard = sc-0441111111
auth_type = userpass
password = PASSWORD40441111111
nonce_lifetime = 32

[sc-0443333333-oauth]
type = auth
username = USERNAME40443333333
@pjsip_wizard = sc-0443333333
auth_type = userpass
password = PASSWORD40443333333
nonce_lifetime = 32

[sc-0442222222-oauth]
type = auth
username = USERNAME40442222222
@pjsip_wizard = sc-0442222222
auth_type = userpass
password = PASSWORD40442222222
nonce_lifetime = 32

[sc-0443333333]
type = endpoint
rpid_immediate = false
webrtc = no
device_state_busy_at = 0
t38_udptl_maxdatagram = 0
dtls_rekey = 0
direct_media_method = invite
send_rpid = false
sdp_session = Asterisk
dtls_verify = No
record_on_feature = automixmon
dtls_fingerprint = SHA-256
from_domain = swisscom.ch
timers_sess_expires = 1800
media_encryption_optimistic = false
suppress_q850_reason_headers = false
aors = sc-0443333333
identify_by = username,ip
callerid_privacy = allowed_not_screened
mwi_subscribe_replaces_unsolicited = no
cos_audio = 0
follow_early_media_fork = true
context = inbound-sc-0443333333
rtp_symmetric = false
transport = transport-udp
moh_suggest = default
t38_udptl = false
fax_detect = false
tos_video = 0
srtp_tag_32 = false
refer_blind_progress = true
max_audio_streams = 1
bundle = false
use_avpf = false
send_connected_line = yes
fax_detect_timeout = 0
sdp_owner = -
force_rport = true
rtp_timeout_hold = 0
@pjsip_wizard = sc-0443333333
use_ptime = false
rtp_timeout = 0
preferred_codec_only = false
force_avp = false
record_off_feature = automixmon
from_user = +41443333333
send_diversion = true
t38_udptl_ipv6 = false
allow_subscribe = true
rtp_ipv6 = false
callerid = <unknown>
moh_passthrough = false
cos_video = 0
dtls_auto_generate_cert = No
asymmetric_rtp_codec = false
ice_support = false
aggregate_mwi = true
one_touch_recording = false
allow = (g722|alaw)
rewrite_contact = false
user_eq_phone = true
rtp_engine = asterisk
notify_early_inuse_ringing = false
direct_media_glare_mitigation = none
trust_id_inbound = false
bind_rtp_to_media_address = false
disable_direct_media_on_nat = false
media_encryption = no
media_use_received_transport = false
allow_overlap = true
dtmf_mode = rfc4733
outbound_auth = sc-0443333333-oauth
tos_audio = 0
dtls_setup = active
connected_line_method = invite
g726_non_standard = false
100rel = yes
timers = yes
direct_media = true
timers_min_se = 90
trust_id_outbound = false
sub_min_expiry = 0
rtcp_mux = false
max_video_streams = 1
accept_multiple_sdp_answers = false
trust_connected_line = yes
send_pai = false
rtp_keepalive = 0
t38_udptl_ec = none
t38_udptl_nat = false
allow_transfer = true
outbound_proxy = sip:fs1.ims.swisscom.ch:5060;lr
inband_progress = false

[sc-0441111111]
type = endpoint
rpid_immediate = false
webrtc = no
device_state_busy_at = 0
t38_udptl_maxdatagram = 0
dtls_rekey = 0
direct_media_method = invite
send_rpid = false
sdp_session = Asterisk
dtls_verify = No
record_on_feature = automixmon
dtls_fingerprint = SHA-256
from_domain = swisscom.ch
timers_sess_expires = 1800
media_encryption_optimistic = false
suppress_q850_reason_headers = false
aors = sc-0441111111
identify_by = username,ip
callerid_privacy = allowed_not_screened
mwi_subscribe_replaces_unsolicited = no
cos_audio = 0
follow_early_media_fork = true
context = inbound-sc-0441111111
rtp_symmetric = false
transport = transport-udp
moh_suggest = default
t38_udptl = false
fax_detect = false
tos_video = 0
srtp_tag_32 = false
refer_blind_progress = true
max_audio_streams = 1
bundle = false
use_avpf = false
send_connected_line = yes
fax_detect_timeout = 0
sdp_owner = -
force_rport = true
rtp_timeout_hold = 0
@pjsip_wizard = sc-0441111111
use_ptime = false
rtp_timeout = 0
preferred_codec_only = false
force_avp = false
record_off_feature = automixmon
from_user = +41441111111
send_diversion = true
t38_udptl_ipv6 = false
allow_subscribe = true
rtp_ipv6 = false
callerid = <unknown>
moh_passthrough = false
cos_video = 0
dtls_auto_generate_cert = No
asymmetric_rtp_codec = false
ice_support = false
aggregate_mwi = true
one_touch_recording = true
allow = (g722|alaw)
rewrite_contact = false
user_eq_phone = true
rtp_engine = asterisk
notify_early_inuse_ringing = false
direct_media_glare_mitigation = none
trust_id_inbound = false
bind_rtp_to_media_address = false
disable_direct_media_on_nat = false
media_encryption = no
media_use_received_transport = false
allow_overlap = true
dtmf_mode = rfc4733
outbound_auth = sc-0441111111-oauth
tos_audio = 0
dtls_setup = active
connected_line_method = invite
g726_non_standard = false
100rel = yes
timers = yes
direct_media = true
timers_min_se = 90
trust_id_outbound = false
sub_min_expiry = 0
rtcp_mux = false
max_video_streams = 1
accept_multiple_sdp_answers = false
trust_connected_line = yes
send_pai = false
rtp_keepalive = 0
t38_udptl_ec = none
t38_udptl_nat = false
allow_transfer = true
outbound_proxy = sip:fs1.ims.swisscom.ch:5060;lr
inband_progress = false

[sc-0442222222]
type = endpoint
rpid_immediate = false
webrtc = no
device_state_busy_at = 0
t38_udptl_maxdatagram = 0
dtls_rekey = 0
direct_media_method = invite
send_rpid = false
sdp_session = Asterisk
dtls_verify = No
record_on_feature = automixmon
dtls_fingerprint = SHA-256
from_domain = swisscom.ch
timers_sess_expires = 1800
media_encryption_optimistic = false
suppress_q850_reason_headers = false
aors = sc-0442222222
identify_by = username,ip
callerid_privacy = allowed_not_screened
mwi_subscribe_replaces_unsolicited = no
cos_audio = 0
follow_early_media_fork = true
context = inbound-sc-0442222222
rtp_symmetric = false
transport = transport-udp
moh_suggest = default
t38_udptl = false
fax_detect = false
tos_video = 0
srtp_tag_32 = false
refer_blind_progress = true
max_audio_streams = 1
bundle = false
use_avpf = false
send_connected_line = yes
fax_detect_timeout = 0
sdp_owner = -
force_rport = true
rtp_timeout_hold = 0
@pjsip_wizard = sc-0442222222
use_ptime = false
rtp_timeout = 0
preferred_codec_only = false
force_avp = false
record_off_feature = automixmon
from_user = +41442222222
send_diversion = true
t38_udptl_ipv6 = false
allow_subscribe = true
rtp_ipv6 = false
callerid = <unknown>
moh_passthrough = false
cos_video = 0
dtls_auto_generate_cert = No
asymmetric_rtp_codec = false
ice_support = false
aggregate_mwi = true
one_touch_recording = false
allow = (g722|alaw)
rewrite_contact = false
user_eq_phone = true
rtp_engine = asterisk
notify_early_inuse_ringing = false
direct_media_glare_mitigation = none
trust_id_inbound = false
bind_rtp_to_media_address = false
disable_direct_media_on_nat = false
media_encryption = no
media_use_received_transport = false
allow_overlap = true
dtmf_mode = rfc4733
outbound_auth = sc-0442222222-oauth
tos_audio = 0
dtls_setup = active
connected_line_method = invite
g726_non_standard = false
100rel = yes
timers = yes
direct_media = true
timers_min_se = 90
trust_id_outbound = false
sub_min_expiry = 0
rtcp_mux = false
max_video_streams = 1
accept_multiple_sdp_answers = false
trust_connected_line = yes
send_pai = false
rtp_keepalive = 0
t38_udptl_ec = none
t38_udptl_nat = false
allow_transfer = true
outbound_proxy = sip:fs1.ims.swisscom.ch:5060;lr
inband_progress = false

[sc-0443333333]
type = aor
minimum_expiration = 60
default_expiration = 3600
qualify_timeout = 3.000000
support_path = false
@pjsip_wizard = sc-0443333333
max_contacts = 0
authenticate_qualify = false
contact = sip:+41443333333@swisscom.ch
maximum_expiration = 7200
qualify_frequency = 0
remove_existing = false

[sc-0441111111]
type = aor
minimum_expiration = 60
default_expiration = 3600
qualify_timeout = 3.000000
support_path = false
@pjsip_wizard = sc-0441111111
max_contacts = 0
authenticate_qualify = false
contact = sip:+41441111111@swisscom.ch
maximum_expiration = 7200
qualify_frequency = 0
remove_existing = false

[sc-0442222222]
type = aor
minimum_expiration = 60
default_expiration = 3600
qualify_timeout = 3.000000
support_path = false
@pjsip_wizard = sc-0442222222
max_contacts = 0
authenticate_qualify = false
contact = sip:+41442222222@swisscom.ch
maximum_expiration = 7200
qualify_frequency = 0
remove_existing = false

[sc-0441111111-identify]
type = identify
match = 195.186.128.164/255.255.255.255
srv_lookups = true
@pjsip_wizard = sc-0441111111
endpoint = sc-0441111111

[sc-0443333333-identify]
type = identify
match = 195.186.128.164/255.255.255.255
srv_lookups = true
@pjsip_wizard = sc-0443333333
endpoint = sc-0443333333

[sc-0442222222-identify]
type = identify
match = 195.186.128.164/255.255.255.255
srv_lookups = true
@pjsip_wizard = sc-0442222222
endpoint = sc-0442222222

[sc-0441111111-reg-0]
type = registration
max_retries = 10
client_uri = sip:+41441111111@swisscom.ch
auth_rejection_permanent = true
server_uri = sip:swisscom.ch
support_path = false
retry_interval = 60
expiration = 3600
transport = transport-udp
line = false
contact_user = sc-0441111111
@pjsip_wizard = sc-0441111111
forbidden_retry_interval = 0
outbound_auth = sc-0441111111-oauth
outbound_proxy = sip:fs1.ims.swisscom.ch:5060;lr
fatal_retry_interval = 0

[sc-0443333333-reg-0]
type = registration
max_retries = 10
client_uri = sip:+41443333333@swisscom.ch
auth_rejection_permanent = true
server_uri = sip:swisscom.ch
support_path = false
retry_interval = 60
expiration = 3600
transport = transport-udp
line = false
contact_user = sc-0443333333
@pjsip_wizard = sc-0443333333
forbidden_retry_interval = 0
outbound_auth = sc-0443333333-oauth
outbound_proxy = sip:fs1.ims.swisscom.ch:5060;lr
fatal_retry_interval = 0

[sc-0442222222-reg-0]
type = registration
max_retries = 10
client_uri = sip:+41442222222@swisscom.ch
auth_rejection_permanent = true
server_uri = sip:swisscom.ch
support_path = false
retry_interval = 60
expiration = 3600
transport = transport-udp
line = false
contact_user = sc-0442222222
@pjsip_wizard = sc-0442222222
forbidden_retry_interval = 0
outbound_auth = sc-0442222222-oauth
outbound_proxy = sip:fs1.ims.swisscom.ch:5060;lr
fatal_retry_interval = 0

Simplified extensions.conf:

[outbound]
exten = _X.,1,Verbose(1, "outbound call...")
same = n,Set(CALLERID(all)=+41441111111)
same = n,Dial(PJSIP/${EXTEN}@sc-0441111111)
same = n,Hangup()

;Hardphones
exten = _2[0-4]X,1,Verbose(1,"Hardphone called")
same = n,Dial(PJSIP/${EXTEN})
same = n,Hangup()

; Pickup call
exten = _*8X.,1,Set(nst=${EXTEN:2})
same = n,Verbose(1,${CALLERID(num)} will Anruf von ${nst} holen)
same = n,PickupChan(PJSIP/${nst})
same = n,Verbose(1,Pickup result: ${PICKUPRESULT})
same = n,Hangup()

[inbound-sc-0441111111]
exten = sc-0441111111,1,Verbose(1, "inbound call from swisscom...")
same = n,Dial(PJSIP/211)
same = n,Hangup()

[inbound-sc-0442222222]
exten = sc-0442222222,1,Verbose(1, "inbound call from swisscom...")
same = n,Dial(PJSIP/222)
same = n,Hangup()

[inbound-sc-0443333333]
exten = sc-0443333333,1,Verbose(1, "inbound call from swisscom...")
same = n,Dial(PJSIP/223)
same = n,Hangup()

CLI output if I call to Number 0441111111:

pbx*CLI>
  == Setting global variable 'SIPDOMAIN' to '192.168.1.168'
    -- Executing [sc-0441111111@inbound-sc-0441111111:1] Verbose("PJSIP/sc-0441111111-00000002", "1, "inbound call from swisscom..."") in new stack
  "inbound call from swisscom..."
    -- Executing [sc-0441111111@inbound-sc-0441111111:2] Dial("PJSIP/sc-0441111111-00000002", "PJSIP/211") in new stack
    -- Called PJSIP/211
    -- PJSIP/211-00000003 is ringing
    -- PJSIP/211-00000003 is ringing
  == Spawn extension (inbound-sc-0441111111, sc-0441111111, 2) exited non-zero on 'PJSIP/sc-0441111111-00000002'
pbx*CLI>

CLI output if I call to Number 0442222222:

pbx*CLI>
[Mar 28 10:35:05] NOTICE[3698]: res_pjsip_session.c:2991 new_invite: Call from 'sc-0441111111' (UDP:195.186.128.164:5060) to extension 'sc-0442222222' rejected because extension not found in context 'inbound-sc-0441111111'.
[Mar 28 10:35:06] NOTICE[3698]: res_pjsip_session.c:2991 new_invite: Call from 'sc-0441111111' (UDP:195.186.128.164:5060) to extension 'sc-0442222222' rejected because extension not found in context 'inbound-sc-0441111111'.
pbx*CLI>

CLI output if I call to Number 0443333333:

pbx*CLI>
[Mar 28 10:33:05] NOTICE[3698]: res_pjsip_session.c:2991 new_invite: Call from 'sc-0441111111' (UDP:195.186.128.164:5060) to extension 'sc-0443333333' rejected because extension not found in context 'inbound-sc-0441111111'.
[Mar 28 10:33:05] NOTICE[3698]: res_pjsip_session.c:2991 new_invite: Call from 'sc-0441111111' (UDP:195.186.128.164:5060) to extension 'sc-0443333333' rejected because extension not found in context 'inbound-sc-0441111111'.
pbx*CLI>

Using IP based inbound matching you can’t have them go to different contexts or be matched to different endpoints - an IP alone isn’t enough to differentiate each one, as they’d come from the same source.

You may be able to turn on line support for each instead of using IP based matching, an example follows:

registration/line = yes
registration/endpoint = sc-0441111111

Thanks a lot!!! It works. You saved my day :grinning: