I am unable to connect to another Asterisk using PJSIP (realtime)

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?

Asterisk can not find the proper contact to dial.

Check that the enpoint has a valid aor you can dial.

Should show up in the output of pjsip show aor torronto.

Hello @Chano,
I believe you are referring to this message:

[2023-08-29 09:53:24] ERROR[5207]: res_pjsip_registrar.c:861 register_aor_core: Unable to bind contact 'sip:osaka@172.16.1.39:5060' to AOR 'toronto'

Here is the output of the command pjsip show aor torronto:

asterisk20*CLI> pjsip show aor toronto

      Aor:  <Aor..............................................>  <MaxContact>
    Contact:  <Aor/ContactUri............................> <Hash....> <Status> <RTT(ms)..>
==========================================================================================

      Aor:  toronto                                              1
    Contact:  toronto/sip:172.16.1.39                      6cdb8cc927 NonQual         nan


 ParameterName        : ParameterValue
 ======================================
 authenticate_qualify : false
 contact              : sip:172.16.1.39
 default_expiration   : 3600
 mailboxes            :
 max_contacts         : 1
 maximum_expiration   : 7200
 minimum_expiration   : 60
 outbound_proxy       :
 qualify_frequency    : 0
 qualify_timeout      : 3.000000
 remove_existing      : false
 remove_unavailable   : false
 support_path         : false
 voicemail_extension  :

I added the information to the contact column in the database that didn’t exist before, but I still continue to have the same problem.

asterisk=# SELECT id, contact, max_contacts  FROM public.ps_aors WHERE id='toronto';
   id    |     contact     | max_contacts
---------+-----------------+--------------
 toronto | sip:172.16.1.39 |            1
(1 row)

I still lack knowledge in PJSIP, so I’m not sure what I need to fill in or leave blank for it to work. I do know that using pjsip.conf works, but it’s not functioning when using realtime configuration.

I don’t really have a lot of experience with realtime… However, I would try making it work without realtime first, then move on to realtime after I got it working.

Might make it much easier to troubleshoot, as you don’t have to worry about the database.

When that’s said, there’s more or less a 1:1 relation between the config files.

If you register to the toronto server, there’s no need to add a contact to the configuration. You should just leave that to asterisk.

You can verify the registration using pjsip show registration reg_172.16.1.39

I’m using pjsip_wizard for setting up my trunk lines, here’s the config I use:

[trunk_line]
type                                  = wizard
sends_auth                            = yes
sends_registrations                   = yes
accepts_auth                          = no
accepts_registrations                 = no
remote_hosts                          = <sipserver>
endpoint/disallow                     = all
endpoint/allow                        = alaw
endpoint/context                      = inbound
endpoint/direct_media                 = no
endpoint/language                     = da
endpoint/transport                    = transport-udp
endpoint/t38_udptl                    = yes
registration/expiration               = 60
registration/line                     = yes
registration/auth_rejection_permanent = no
registration/forbidden_retry_interval = 30
outbound_auth/username                 = <username>
outbound_auth/password                 = <password>
registration/contact_user              = <phonenumber>
registration/endpoint                  = <endpointname>

It’s possible to translate the above to the pjsip.conf file instead, if you prefer, but you could also just try the above with the wizard module, and see how it works out.

I have a few instances of Asterisk Realtime running on Docker, using registration through realtime configuration. I don’t have access to its configuration at this moment, but I think you’re missing this line in the sorcery.conf file.

[res_pjsip_outbound_registration]

registration=realtime,ps_registrations

Also, if the ‘pjsip show registration’ command returns empty, it’s clear that there is a misconfiguration in the registration section. It doesn’t matter if it’s through plain text or realtime.

1 Like

As I mentioned at the beginning, it’s working configured in pjsip.conf. I had never used pjsip_wizard.conf before, however, I didn’t come across anything that could assist me with realtime configurations.

However, when I looked for more information about pjsip_wizard.conf, I came across this post:

The PJSIP Configuration Wizard

I had initially configured it this way 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 changed the pjsip.conf using the provided example and adapting the information that I will be using. I simply had to add max_contacts=1 to the aor and disallow = all, allow = ulaw to the endpoint to eliminate errors.

This way, some configurations were eliminated.

[toronto]
type = endpoint
aors = toronto
outbound_auth = toronto-auth
context = default
disallow = all
allow = ulaw


[toronto]
type = aor
max_contacts = 1
contact = sip:172.16.1.120
qualify_frequency = 15

[toronto-auth]
type = auth
auth_type = userpass
username = osaka
password = welcome

[toronto-reg]
type = registration
outbound_auth = toronto-auth
server_uri = sip:172.16.1.120
client_uri = sip:osaka@172.16.1.120

[toronto-identify]
type = identify
endpoint = toronto
match = 172.16.1.120

At this point, I can make and receive calls.

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-auth/osaka
        Aor:  toronto                                            1
      Contact:  toronto/sip:osaka@172.16.1.120:5060        4b13f8e760 Avail         3.033
      Contact:  toronto/sip:172.16.1.120                   bbf339100d Avail         3.351
   Identify:  toronto-identify/toronto
        Match: 172.16.1.120/32


Objects found: 1
asterisk20*CLI> pjsip show registrations

 <Registration/ServerURI..............................>  <Auth....................>  <Status.......>
==========================================================================================

 toronto-reg/sip:172.16.1.120                            toronto-auth                Registered        (exp. 3011s)

Objects found: 1

I migrated this new configuration to the database, and it looks like this:

asterisk=# SELECT id, aors, outbound_auth, context, disallow, allow  FROM public.ps_endpoints;
   id    |  aors   | outbound_auth | context | disallow | allow
---------+---------+---------------+---------+----------+-------
 toronto | toronto | toronto-auth  | default | all      | ulaw
(1 row)
asterisk=# SELECT id, max_contacts, contact, qualify_frequency FROM public.ps_aors;
   id    | max_contacts |     contact      | qualify_frequency
---------+--------------+------------------+-------------------
 toronto |            1 | sip:172.16.1.120 |                15
(1 row)
asterisk=# SELECT id, auth_type, username, password  FROM public.ps_auths;
      id      | auth_type | username | password
--------------+-----------+----------+----------
 toronto-auth | userpass  | osaka    | welcome
(1 row)
asterisk=# SELECT id, outbound_auth, server_uri, client_uri  FROM public.ps_registrations;
     id      | outbound_auth |    server_uri    |       client_uri
-------------+---------------+------------------+------------------------
 toronto-reg | toronto-auth  | sip:172.16.1.120 | sip:osaka@172.16.1.120
(1 row)
asterisk=# SELECT id, endpoint, match  FROM public.ps_endpoint_id_ips;
        id        | endpoint |    match
------------------+----------+--------------
 toronto-identify | toronto  | 172.16.1.120
(1 row)

The endpoint is showing as available.

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-auth/osaka
        Aor:  toronto                                            1
      Contact:  toronto/sip:172.16.1.120                   bbf339100d Avail         2.683
   Identify:  toronto-identify/toronto
        Match: 172.16.1.120/32


Objects found: 1

However, there are no registrations.

asterisk20*CLI> pjsip show registrations
No objects found.

With the tables configured in this way, I was able to make and receive calls.

However, there is still an error that appears from time to time.

[2023-08-30 10:20:09] ERROR[6398]: res_pjsip_registrar.c:861 register_aor_core: Unable to bind contact 'sip:osaka@172.16.1.120:5060' to AOR 'toronto'

I just noticed this one… There appears to be a typo in the ps_contacts entry, it says ansterisk instead of asterisk. If that’s present in the original file, I strongly suspect that’s the source of your problem.

Thank you for letting me know. I’ve already made the correction, but as I suspected, this table wasn’t the issue since it’s responsible for storing the data of the extensions that are currently registered.

Hi @ambiorixg12
I added the lines you suggested in my sorcery.conf file, and that resolved the issue with real-time registrations and the “Unable to bind contact” error.

My sorcery.conf now looks like this:

[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

[res_pjsip_outbound_registration]
registration=realtime,ps_registrations
asterisk20*CLI> pjsip show registrations

 <Registration/ServerURI..............................>  <Auth....................>  <Status.......>
==========================================================================================

 toronto-reg/sip:172.16.1.120                            toronto-auth                Registered        (exp. 3272s)

Objects found: 1

I still haven’t quite grasped how to configure pjsip. Whenever I need to, I end up using the sip_to_pjsip.py script. When I manage to make it work in pjsip.conf, I transfer the configurations to a database. As for sorcery.conf, I’ve mostly just uncommented parts of it and it starts working. So, I haven’t paid much attention to its configurations. However, this is now the second time I’ve faced difficulties due to missing configurations in it. I used to believe that the default settings were sufficient, but it seems like I’ll need to study and understand how sorcery.conf works, as I’m sure this won’t be the last time I encounter problems with it.

Thanks @ambiorixg12

3 Likes

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