I’m migrating the Asterisk systems I have from SIP to PJSIP. The entire system I have is in a PostgreSQL database. I always test the PJSIP configurations in the pjsip.conf
files to make sure the configuration is correct before migrating to the database, I already have extensions and trunks working in PJSIP realtime.
But I’m facing a scenario where I’m unable to make it work in realtime, and I need assistance.
The scenario I have is very similar to the one explained in this tutorial, where registration is required.
Connecting Two Asterisk Boxes Together via SIP
Toronto is where I will be connecting; there is an Asterisk 13 with SIP there.
I am in Osaka, where I have an Asterisk 20 with PJSIP.
Below is the configuration I made in pjsip.conf
:
[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060
[reg_172.16.1.39]
type = registration
retry_interval = 20
max_retries = 10
expiration = 120
transport = transport-udp
outbound_auth = auth_reg_172.16.1.39
client_uri = sip:osaka@172.16.1.39
server_uri = sip:172.16.1.39
[auth_reg_172.16.1.39]
type = auth
password = welcome
username = osaka
[toronto]
type = aor
max_contacts = 1
[toronto]
type = identify
endpoint = toronto
match = 172.16.1.39
[toronto]
type = auth
username = toronto
password = welcome
[toronto]
type = endpoint
context = toronto_incoming
disallow = all
allow = ulaw
auth = toronto
outbound_auth = toronto
aors = toronto
I don’t have issues with this configuration; the trunk registers, and the extension is created, I am able to make and receive calls.
asterisk20*CLI> pjsip show registrations
<Registration/ServerURI..............................> <Auth....................> <Status.......>
==========================================================================================
reg_172.16.1.39/sip:172.16.1.39 auth_reg_172.16.1.39 Registered (exp. 103s)
Objects found: 1
asterisk20*CLI> pjsip show endpoints
Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.>
I/OAuth: <AuthId/UserName...........................................................>
Aor: <Aor............................................> <MaxContact>
Contact: <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
Transport: <TransportId........> <Type> <cos> <tos> <BindAddress..................>
Identify: <Identify/Endpoint.........................................................>
Match: <criteria.........................>
Channel: <ChannelId......................................> <State.....> <Time.....>
Exten: <DialedExten...........> CLCID: <ConnectedLineCID.......>
==========================================================================================
Endpoint: toronto Not in use 0 of inf
OutAuth: toronto/toronto
InAuth: toronto/toronto
Aor: toronto 1
Contact: toronto/sip:osaka@172.16.1.39:5060 392f6dbbf9 NonQual nan
Identify: toronto/toronto
Match: 172.16.1.39/32
Objects found: 1
When I transfer these configurations to the database, they stop working.
pjsip.conf
[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060
sorcery.conf
[test_sorcery_section]
test=memory
[test_sorcery_cache]
test/cache=test
test=memory
[res_pjsip]
endpoint=realtime,ps_endpoints
auth=realtime,ps_auths
aor=realtime,ps_aors
domain_alias=realtime,ps_domain_aliases
contact=realtime,ps_contacts
[res_pjsip_endpoint_identifier_ip]
identify=realtime,ps_endpoint_id_ips
[res_pjsip_outbound_publish]
outbound-publish=realtime,ps_outbound_publishes
[res_pjsip_pubsub]
inbound-publication=realtime,ps_inbound_publications
[res_pjsip_publish_asterisk]
asterisk-publication=realtime,ps_asterisk_publications
extconfig.conf
[settings]
ps_endpoints => odbc,asterisk
ps_auths => odbc,asterisk
ps_aors => odbc,asterisk
ps_domain_aliases => odbc,asterisk
ps_endpoint_id_ips => odbc,asterisk
ps_outbound_publishes => odbc,asterisk
ps_inbound_publications = odbc,asterisk
ps_asterisk_publications = odbc,asterisk
ps_contacts = odbc,ansterisk
ps_registrations = odbc,asterisk
REALTIME Table: ps_registrations
asterisk=# SELECT id, retry_interval, max_retries, expiration, transport, outbound_auth, client_uri, server_uri FROM public.ps_registrations;
id | retry_interval | max_retries | expiration | transport | outbound_auth | client_uri | server_uri
-----------------+----------------+-------------+------------+---------------+----------------------+-----------------------+-----------------
reg_172.16.1.39 | 20 | 10 | 120 | transport-udp | auth_reg_172.16.1.39 | sip:osaka@172.16.1.39 | sip:172.16.1.39
(1 row)
REALTIME Table: ps_auths
asterisk=# SELECT id, password, username FROM public.ps_auths WHERE id='auth_reg_172.16.1.39';
id | password | username
----------------------+----------+----------
auth_reg_172.16.1.39 | welcome | osaka
(1 row)
REALTIME Table: ps_aors
asterisk=# SELECT id, max_contacts FROM public.ps_aors WHERE id='toronto';
id | max_contacts
---------+--------------
toronto | 1
(1 row)
REALTIME Table: ps_endpoint_id_ips
asterisk=# SELECT id, endpoint, match FROM public.ps_endpoint_id_ips WHERE id='toronto';
id | endpoint | match
---------+----------+-------------
toronto | toronto | 172.16.1.39
(1 row)
REALTIME Table: ps_auths
asterisk=# SELECT id, password, username FROM public.ps_auths WHERE id='toronto';
id | password | username
---------+----------+----------
toronto | welcome | toronto
(1 row)
REALTIME Table: ps_endpoints
asterisk=# SELECT id, context, disallow, allow, auth, outbound_auth, aors FROM public.ps_endpoints WHERE id='toronto';
id | context | disallow | allow | auth | outbound_auth | aors
---------+------------------+----------+-------+---------+---------------+---------
toronto | toronto_incoming | all | ulaw | toronto | toronto | toronto
(1 row)
The registrations become empty.
asterisk20*CLI> pjsip show registrations
No objects found.
It creates the endpoints
, but they remain in an Unavailable
status.
asterisk20*CLI> pjsip show endpoints
Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.>
I/OAuth: <AuthId/UserName...........................................................>
Aor: <Aor............................................> <MaxContact>
Contact: <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
Transport: <TransportId........> <Type> <cos> <tos> <BindAddress..................>
Identify: <Identify/Endpoint.........................................................>
Match: <criteria.........................>
Channel: <ChannelId......................................> <State.....> <Time.....>
Exten: <DialedExten...........> CLCID: <ConnectedLineCID.......>
==========================================================================================
Endpoint: toronto Unavailable 0 of inf
OutAuth: toronto/toronto
InAuth: toronto/toronto
Aor: toronto 1
Identify: toronto/toronto
Match: 172.16.1.39/32
If I try to make a call to Toronto, I receive the following error:
extensions.conf
[teste]
exten => 1,1,Dial(PJSIP/1000@toronto)
asterisk -r
asterisk20*CLI> console dial 1@teste
-- Executing [1@teste:1] Dial("Console/default", "PJSIP/1000@toronto") in new stack
[2023-08-28 10:21:34] ERROR[29164]: res_pjsip.c:852 ast_sip_create_dialog_uac: Endpoint 'toronto': Could not create dialog to invalid URI 'toronto'. Is endpoint registered and reachable?
[2023-08-28 10:21:34] ERROR[29164]: chan_pjsip.c:2698 request: Failed to create outgoing session to endpoint 'toronto'
[2023-08-28 10:21:34] NOTICE[29174][C-00000004]: app_dial.c:2709 dial_exec_full: Unable to create channel of type 'PJSIP' (cause 3 - No route to destination)
== Everyone is busy/congested at this time (1:0/0/1)
-- Auto fallthrough, channel 'Console/default' status is 'CHANUNAVAIL'
From time to time, I receive this message in the terminal:
[2023-08-28 10:48:39] ERROR[29349]: res_pjsip_registrar.c:861 register_aor_core: Unable to bind contact 'sip:osaka@172.16.1.39:5060' to AOR 'toronto'
One way I found to make it work partially is by keeping the registration
configuration in pjsip.conf
.
[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060
[reg_172.16.1.39]
type = registration
retry_interval = 20
max_retries = 10
expiration = 120
transport = transport-udp
outbound_auth = auth_reg_172.16.1.39
client_uri = sip:osaka@172.16.1.39
server_uri = sip:172.16.1.39
And removing the INSERT created in the ps_registrations table.
This way, at least I can receive calls, but I still can’t make them.
extensions.conf
[toronto_incoming]
exten => _X.,1,Answer()
same => n,Wait(10)
same => n,HangUp()
-- Executing [1000@toronto_incoming:1] Answer("PJSIP/toronto-00000001", "") in new stack
-- Executing [1000@toronto_incoming:2] Wait("PJSIP/toronto-00000001", "10") in new stack
-- Executing [1000@toronto_incoming:3] Hangup("PJSIP/toronto-00000001", "") in new stack
== Spawn extension (toronto_incoming, 1000, 3) exited non-zero on 'PJSIP/toronto-00000001'
Why is the registration
not working in the ps_registrations
table?
Why can I receive calls but not make them?
Can someone help me?