How to Create PJSIP Endpoints with Templates on Asterisk

To Create PJSIP Endpoint With Templates On Asterisk

Introduction

PJSIP is a free and Open Source multimedia communication library based on C language that implements standard-based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE. Configuration templates are means to avoid repetitive sections in Asterisk configuration files, such as extensions.conf, sip.conf, or iax.conf.

Procedure

Step 1: Check the OS version by using the below command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:    22.04
Codename:    jammy

Step 2: Check the status of the Asterisk by using the below command

root@linuxhelp:~# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Wed 2023-07-19 09:51:07 IST; 4h 25min ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 79 (limit: 4537)
     Memory: 80.1M
        CPU: 3min 5.635s
     CGroup: /system.slice/asterisk.service
             └─1443 /usr/sbin/asterisk
Jul 19 09:51:07 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Jul 19 09:51:07 linuxhelp asterisk[1420]:  * Starting Asterisk PBX: asterisk
Jul 19 09:51:07 linuxhelp asterisk[1420]:    ...done.
Jul 19 09:51:07 linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Jul 19 09:51:14 linuxhelp asterisk[1443]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/r>
Jul 19 09:51:14 linuxhelp asterisk[1443]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/r>

**Step 3: Edit the pjsip.conf file to add the templates for endpoints by using the below command **

root@linuxhelp:~# vim /etc/asterisk/pjsip.conf
Add the below lines
[customtemplate](!)
language=en
deny=0.0.0.0/0.0.0.0
trust_id_inbound=yes
send_rpid=no
transport=tcp_transport
rtcp_mux=no
call_group=
pickup_group=
disallow=all
allow=ulaw,alaw,gsm
mailboxes=300
permit=0.0.0.0/0.0.0.0
ice_support=no
use_avpf=no
dtls_cert_file=
dtls_private_key=
dtls_ca_file=
dtls_setup=actpass
dtls_verify=no
media_encryption=no
message_context=
subscribe_context=
allow_subscribe=yes
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
direct_media=no
media_use_received_transport=no

[167](customtemplate)
context=internal
auth=167
aors=167
type=endpoint
callerid="linuxhelp" <167>

[168](customtemplate)
context=internal
auth=168
aors=168
type=endpoint
callerid="linuxhelp2" <168>

Step 4: Login to the Asterisk CLI mode by using the below command

root@linuxhelp:~# asterisk -rvvvvvvvvvvvvvvvvvvvv
Asterisk 20.3.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.3.1 currently running on linuxhelp (pid = 1443)

Step 5: Reload the pjsip.conf file by running the below command

linuxhelp*CLI> pjsip reload
Module 'res_pjsip.so' reloaded successfully.
Module 'res_pjsip_authenticator_digest.so' reloaded successfully.
Module 'res_pjsip_endpoint_identifier_ip.so' reloaded successfully.
Module 'res_pjsip_mwi.so' reloaded successfully.
Module 'res_pjsip_notify.so' reloaded successfully.
Module 'res_pjsip_outbound_publish.so' reloaded successfully.
Module 'res_pjsip_publish_asterisk.so' reloaded successfully.
Module 'res_pjsip_outbound_registration.so' reloaded successfully.
    -- Reloading module 'res_pjsip.so' (Basic SIP resource)
[Jul 19 14:24:14] NOTICE[14072]: res_pjsip/config_transport.c:768 transport_apply: Transport 'tcp_transport' is not fully reloadable, not reloading: protocol, bind, TLS (everything but certificate and private key if filename is unchanged), TCP, ToS, or CoS options.
[Jul 19 14:24:14] NOTICE[14072]: res_pjsip/config_transport.c:768 transport_apply: Transport 'udp_transport' is not fully reloadable, not reloading: protocol, bind, TLS (everything but certificate and private key if filename is unchanged), TCP, ToS, or CoS options.
[Jul 19 14:24:14] NOTICE[14072]: sorcery.c:1348 sorcery_object_load: Type 'system' is not reloadable, maintaining previous values
    -- Reloading module 'res_pjsip_authenticator_digest.so' (PJSIP authentication resource)
    -- Reloading module 'res_pjsip_endpoint_identifier_ip.so' (PJSIP IP endpoint identifier)
    -- Reloading module 'res_pjsip_mwi.so' (PJSIP MWI resource)
    -- Reloading module 'res_pjsip_notify.so' (CLI/AMI PJSIP NOTIFY Support)
    -- Reloading module 'res_pjsip_outbound_publish.so' (PJSIP Outbound Publish Support)
    -- Reloading module 'res_pjsip_publish_asterisk.so' (PJSIP Asterisk Event PUBLISH Support)
    -- Reloading module 'res_pjsip_outbound_registration.so' (PJSIP Outbound Registration Support)

Step 6: Show the endpoints by using the below command

linuxhelp*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:  167/167                                              Not in use    0 of inf
     InAuth:  167/167
        Aor:  167                                                1
      Contact:  167/sip:167@192.168.6.101:63382;transport= 3c2cd8e775 Avail         5.455
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060

 Endpoint:  168/168                                              Not in use    0 of inf
     InAuth:  168/168
        Aor:  168                                                1
      Contact:  168/sip:168@192.168.6.101:5060;ob          a377386ab4 Avail         1.783
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060


Objects found: 2

Result : 
    -- Executing [168@internal:1] Dial("PJSIP/167-00000016", "PJSIP/168") in new stack
    -- Called PJSIP/168
    -- PJSIP/168-00000017 is ringing
  == Everyone is busy/congested at this time (1:1/0/0)
    -- Auto fallthrough, channel 'PJSIP/167-00000016' status is 'BUSY'

Step 7: Now create 2 templates by editing the pjsip.conf file

root@linuxhelp:~# vim /etc/asterisk/pjsip.conf
Add the following lines 
[customtemplate](!)
language=en
deny=0.0.0.0/0.0.0.0
trust_id_inbound=yes
send_rpid=no
transport=tcp_transport
rtcp_mux=no
call_group=
pickup_group=
disallow=all
[customtemplate2](!)
allow=ulaw,alaw,gsm
mailboxes=300
permit=0.0.0.0/0.0.0.0
ice_support=no
use_avpf=no
dtls_cert_file=
dtls_private_key=
dtls_ca_file=
dtls_setup=actpass
dtls_verify=no
media_encryption=no
message_context=
subscribe_context=
allow_subscribe=yes
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
direct_media=no
media_use_received_transport=no

[167](customtemplate,customtemplate2)
context=internal
auth=167
aors=167
type=endpoint
callerid="linuxhelp" <167>

[168](customtemplate,cusomtemplate2)
context=internal
auth=168
aors=168
type=endpoint
callerid="linuxhelp2" <168>

Step 8: Login to the Asterisk CLI mode by using the below command

root@linuxhelp:~# asterisk -rvvvvvvvvvvvvvvvvvvvv
Asterisk 20.3.1, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.3.1 currently running on linuxhelp (pid = 1443)

Step 9: Reload the pjsip.conf file by running the below command

linuxhelp*CLI> pjsip reload
Module 'res_pjsip.so' reloaded successfully.
Module 'res_pjsip_authenticator_digest.so' reloaded successfully.
Module 'res_pjsip_endpoint_identifier_ip.so' reloaded successfully.
Module 'res_pjsip_mwi.so' reloaded successfully.
Module 'res_pjsip_notify.so' reloaded successfully.
Module 'res_pjsip_outbound_publish.so' reloaded successfully.
Module 'res_pjsip_publish_asterisk.so' reloaded successfully.
Module 'res_pjsip_outbound_registration.so' reloaded successfully.
    -- Reloading module 'res_pjsip.so' (Basic SIP resource)
[Jul 19 14:24:14] NOTICE[14072]: res_pjsip/config_transport.c:768 transport_apply: Transport 'tcp_transport' is not fully reloadable, not reloading: protocol, bind, TLS (everything but certificate and private key if filename is unchanged), TCP, ToS, or CoS options.
[Jul 19 14:24:14] NOTICE[14072]: res_pjsip/config_transport.c:768 transport_apply: Transport 'udp_transport' is not fully reloadable, not reloading: protocol, bind, TLS (everything but certificate and private key if filename is unchanged), TCP, ToS, or CoS options.
[Jul 19 14:24:14] NOTICE[14072]: sorcery.c:1348 sorcery_object_load: Type 'system' is not reloadable, maintaining previous values
    -- Reloading module 'res_pjsip_authenticator_digest.so' (PJSIP authentication resource)
    -- Reloading module 'res_pjsip_endpoint_identifier_ip.so' (PJSIP IP endpoint identifier)
    -- Reloading module 'res_pjsip_mwi.so' (PJSIP MWI resource)
    -- Reloading module 'res_pjsip_notify.so' (CLI/AMI PJSIP NOTIFY Support)
    -- Reloading module 'res_pjsip_outbound_publish.so' (PJSIP Outbound Publish Support)
    -- Reloading module 'res_pjsip_publish_asterisk.so' (PJSIP Asterisk Event PUBLISH Support)
    -- Reloading module 'res_pjsip_outbound_registration.so' (PJSIP Outbound Registration Support)

Step 10: Show endpoints by running the below command

linuxhelp*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:  167/167                                              Not in use    0 of inf
     InAuth:  167/167
        Aor:  167                                                1
      Contact:  167/sip:167@192.168.6.101:63382;transport= 3c2cd8e775 Avail         9.071
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060

 Endpoint:  168/168                                              Not in use    0 of inf
     InAuth:  168/168
        Aor:  168                                                1
      Contact:  168/sip:168@192.168.6.101:5060;ob          a377386ab4 Avail         1.486
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060


Objects found: 2

Conclusion

By this how to Create PJSIP Endpoints with Templates on Asterisk has come to an end.

FAQ
Q
What is Auth in pjsip?
A
Address of Record (AOR): According to the official Asterisk documentation, an AOR tells Asterisk "where an endpoint can be contacted."
Q
What is AOR in Pjsip?
A
Address of Record (AOR): According to the official Asterisk documentation, an AOR tells Asterisk "where an endpoint can be contacted."
Q
How to reload pjsip.conf ?
A
By running the following command pjsip reload
Q
What is the default port used by PJSIP?
A
Default UDP port 5160
Q
What is Pjsip in Asterisk?
A
pjsip. conf is a flat text file composed of sections like most configuration files used with Asterisk.