How to create PJSIP endpoints with templates on Oracle Linux 9.3

To Create PJSIP Endpoints With Templates On Oracle Linux 9.3

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 ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.3"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.3"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:3:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.3
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.3

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

[root@linuxhelp ~]# systemctl status asterisk.service
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/rc.d/init.d/asterisk; generated)
     Active: active (running) since Mon 2024-02-19 04:02:05 IST; 1 day 21h ago
       Docs: man:systemd-sysv-generator(8)
    Process: 1001 ExecStart=/etc/rc.d/init.d/asterisk start (code=exited, status=0/SUCCESS)
   Main PID: 1062
      Tasks: 37 (limit: 21739)
     Memory: 64.9M
        CPU: 22.816s
     CGroup: /system.slice/asterisk.service
             ├─1056 /bin/sh /usr/sbin/safe_asterisk
             └─5831 /usr/sbin/asterisk -f -vvvg -c

Feb 19 04:02:05 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Feb 19 04:02:05 linuxhelp asterisk[1001]: Starting asterisk:
Feb 19 04:02:05 linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet?) after start: Operation not permitted
Feb 19 04:02:05 linuxhelp systemd[1]: asterisk.service: Supervising process 1062 which is not our child. We'll most likely not notice when it exits.
Feb 19 04:02:05 linuxhelp systemd[1]: Started LSB: Asterisk PBX.

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

[root@linuxhelp ~]# vim pjsip.conf
Insert the following lines
[tcp_transport] 
type=transport ; Must be of type 'transport' 
protocol=tcp 
bind=0.0.0.0 
tos=cs3 
cos=3 
allow_reload=false 
[udp_transport] 
type=transport ; Must be of type 'transport' 
protocol=udp 
bind=0.0.0.0 
tos=cs3 
cos=3 
allow_reload=false

[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> 

[167] 
auth_type=userpass 
type=auth 
username=167 
password=123456

[167] 
type=aor 
qualify_frequency=60 
max_contacts=1 
remove_existing=yes 
qualify_timeout=3.0 
authenticate_qualify=no


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

[168] 
auth_type=userpass 
type=auth 
username=168 
password=123456

[168] 
type=aor 
qualify_frequency=60 
max_contacts=1 
remove_existing=yes 
qualify_timeout=3.0 
authenticate_qualify=no

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

[root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvv
Asterisk 20.5.0, 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.5.0 currently running on linuxhelp (pid = 5831)
linuxhelp*CLI>

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

linuxhelp*CLI> core reload
    -- Reloading module 'extconfig' (Configuration)
    -- Reloading module 'logger' (Logger)
 Asterisk Queue Logger restarted
    -- Reloading module 'cdr' (CDR Engine)
[Feb 21 01:25:18] NOTICE[7503]: cdr.c:4568 cdr_toggle_runtime_options: CDR simple logging enabled.
    -- Reloading module 'cel' (CEL Engine)
    -- CEL logging disabled.
    -- Reloading module 'dnsmgr' (DNS Manager)
    -- Reloading module 'dsp' (DSP)
    -- Reloading module 'enum' (ENUM Support)
    -- Reloading module 'features' (Call Features)
    -- Reloading module 'http' (Built-in HTTP Server)
    -- Reloading module 'indications' (Indication Tone Handling)
    -- Reloading module 'acl' (Named ACL system)
    -- Reloading module 'manager' (Asterisk Manager Interface)
    -- Reloading module 'plc' (PLC)
    -- Reloading module 'udptl' (UDPTL)
    -- Reloading module 'res_pjproject.so' (PJPROJECT Log and Utility Support)
    -- Reloading module 'res_pjsip.so' (Basic SIP resource)
[Feb 21 01:25:18] NOTICE[7476]: 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_musiconhold.so' (Music On Hold Resource)
    -- Reloading module 'res_rtp_asterisk.so' (Asterisk RTP Stack)
    -- Reloading module 'res_pjsip_outbound_publish.so' (PJSIP Outbound Publish Support)
    -- Reloading module 'res_pjsip_mwi.so' (PJSIP MWI resource)
    -- Reloading module 'res_pjsip_publish_asterisk.so' (PJSIP Asterisk Event PUBLISH Support)
    -- Reloading module 'res_pjsip_notify.so' (CLI/AMI PJSIP NOTIFY Support)
    -- Reloading module 'res_pjsip_outbound_registration.so' (PJSIP Outbound Registration Support)
    -- Reloading module 'app_confbridge.so' (Conference Bridge Application)
    -- Reloading module 'cdr_custom.so' (Customizable Comma Separated Values CDR Backend)
    -- Reloading module 'app_playback.so' (Sound File Playback Application)
    -- Reloading module 'app_voicemail.so' (Comedian Mail (Voicemail System))
    -- Reloading module 'pbx_config.so' (Text Extension Configuration)
    -- Time to scan old dialplan and merge leftovers back into the new: 0.000005 sec
    -- Time to restore hints and swap in new dialplan: 0.000004 sec
    -- Time to delete the old dialplan: 0.000003 sec
    -- Total time merge_contexts_delete: 0.000012 sec
    -- pbx_config successfully loaded 1 contexts (enable debug for details).
    -- Reloading module 'app_queue.so' (True Call Queueing)
[Feb 21 01:25:18] NOTICE[7503]: app_queue.c:9576 reload_queue_rules: queuerules.conf has not changed since it was last loaded. Not taking any action.

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                                              Unavailable   0 of inf
     InAuth:  167/167
        Aor:  167                                                1
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060

 Endpoint:  168/168                                              Unavailable   0 of inf
     InAuth:  168/168
        Aor:  168                                                1
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060

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

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

[root@linuxhelp ~]# vim pjsip.conf
Insert the Following lines
[tcp_transport]
type=transport ; Must be of type 'transport'
protocol=tcp
bind=0.0.0.0
tos=cs3
cos=3
allow_reload=false
[udp_transport]
type=transport ; Must be of type 'transport'
protocol=udp
bind=0.0.0.0
tos=cs3
cos=3
allow_reload=false

[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>

[167]
auth_type=userpass
type=auth
username=167
password=123456




[167]
type=aor
qualify_frequency=60
max_contacts=1
remove_existing=yes
qualify_timeout=3.0
authenticate_qualify=no

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

[168]
auth_type=userpass
type=auth
username=168
password=123456

[168]
type=aor
qualify_frequency=60
max_contacts=1
remove_existing=yes
qualify_timeout=3.0
authenticate_qualify=no

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

[root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvv
Asterisk 20.5.0, 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.5.0 currently running on linuxhelp (pid = 7447)
linuxhelp*CLI>

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

linuxhelp*CLI> core reload
    -- Reloading module 'extconfig' (Configuration)
    -- Reloading module 'logger' (Logger)
 Asterisk Queue Logger restarted
    -- Reloading module 'cdr' (CDR Engine)
[Feb 21 01:31:49] NOTICE[7950]: cdr.c:4568 cdr_toggle_runtime_options: CDR simple logging enabled.
    -- Reloading module 'cel' (CEL Engine)
    -- CEL logging disabled.
    -- Reloading module 'dnsmgr' (DNS Manager)
    -- Reloading module 'dsp' (DSP)
    -- Reloading module 'enum' (ENUM Support)
    -- Reloading module 'features' (Call Features)
    -- Reloading module 'http' (Built-in HTTP Server)
    -- Reloading module 'indications' (Indication Tone Handling)
    -- Reloading module 'acl' (Named ACL system)
    -- Reloading module 'manager' (Asterisk Manager Interface)
    -- Reloading module 'plc' (PLC)
    -- Reloading module 'udptl' (UDPTL)
    -- Reloading module 'res_pjproject.so' (PJPROJECT Log and Utility Support)
    -- Reloading module 'res_pjsip.so' (Basic SIP resource)
[Feb 21 01:31:49] NOTICE[7925]: 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_musiconhold.so' (Music On Hold Resource)
    -- Reloading module 'res_rtp_asterisk.so' (Asterisk RTP Stack)
    -- Reloading module 'res_pjsip_outbound_publish.so' (PJSIP Outbound Publish Support)
    -- Reloading module 'res_pjsip_mwi.so' (PJSIP MWI resource)
    -- Reloading module 'res_pjsip_publish_asterisk.so' (PJSIP Asterisk Event PUBLISH Support)
    -- Reloading module 'res_pjsip_notify.so' (CLI/AMI PJSIP NOTIFY Support)
    -- Reloading module 'res_pjsip_outbound_registration.so' (PJSIP Outbound Registration Support)
    -- Reloading module 'app_confbridge.so' (Conference Bridge Application)
    -- Reloading module 'cdr_custom.so' (Customizable Comma Separated Values CDR Backend)
    -- Reloading module 'app_playback.so' (Sound File Playback Application)
    -- Reloading module 'app_voicemail.so' (Comedian Mail (Voicemail System))
    -- Reloading module 'pbx_config.so' (Text Extension Configuration)
    -- Time to scan old dialplan and merge leftovers back into the new: 0.000004 sec
    -- Time to restore hints and swap in new dialplan: 0.000004 sec
    -- Time to delete the old dialplan: 0.000003 sec
    -- Total time merge_contexts_delete: 0.000011 sec
    -- pbx_config successfully loaded 1 contexts (enable debug for details).
    -- Reloading module 'app_queue.so' (True Call Queueing)
[Feb 21 01:31:49] NOTICE[7950]: app_queue.c:9576 reload_queue_rules: queuerules.conf has not changed since it was last loaded. Not taking any action.

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.102:50787;transport= 94301cb95b Avail         4.915
  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.102:50788;transport= 7fb6ef6dc0 Avail         1.919
  Transport:  tcp_transport             tcp      3     96  0.0.0.0:5060
Objects found: 2

Result 
Remote UNIX connection
    -- Executing [167@internal:1] Dial("PJSIP/168-00000000", "PJSIP/167") in new stack
    -- Called PJSIP/167
    -- PJSIP/167-00000001 is ringing
  == Spawn extension (internal, 167, 1) exited non-zero on 'PJSIP/168-00000000'

Conclusion

We have reached the end of this article. In this guide, we have walked you through the steps required to create PJSIP with template on Oracle Linux 9.3. Your feedback is much welcome.

FAQ
Q
What is Auth in PJSIP?
A
Address of Record (AOR): The authentication response that which application needs to calculate the response digest.
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
The following command to reload is pjsip reload
Q
What is the default port used by PJSIP?
A
Default UDP port is 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.