This page documents any useful tools, tips or examples on moving from the old chan_sip channel driver to the new chan_pjsip/res_pjsip added in Asterisk 12.
Configuration Conversion Script
Contained within a download of Asterisk, there is a Python script, sip_to_pjsip.py, found within the contrib/scripts/sip_to_pjsip subdirectory, that provides a basic conversion of a sip.conf config to a pjsip.conf config. It is not intended to work for every scenario or configuration; for basic configurations it should provide a good example of how to convert it over to pjsip.conf style config.
To insure that the script can read any #include'd files, run it from the /etc/asterisk directory or in another location with a copy of the sip.conf and any included files. The default input file is sip.conf, and the default output file is pjsip.conf. Any included files will also be converted, and written out with a pjsip_ prefix, unless changed with the --prefix=xxx option.
Command line usage
# /path/to/asterisk/source/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py --help Usage: sip_to_pjsip.py [options] [input-file [output-file]] input-file defaults to 'sip.conf' output-file defaults to 'pjsip.conf' Options: -h, --help show this help message and exit -p PREFIX, --prefix=PREFIX output prefix for include files
Example of Use
# cd /etc/asterisk # /path/to/asterisk/source/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py Reading sip.conf Converting to PJSIP... Writing pjsip.conf
Side by Side Examples of sip.conf and pjsip.conf Configuration
These examples contain only the configuration required for sip.conf/pjsip.conf as the configuration for other files should be the same, excepting the Dial statements in your extensions.conf. Dialing with PJSIP is discussed in Dialing PJSIP Channels.
Example Endpoint Configuration
This examples shows the configuration required for:
- two SIP phones need to make calls to or through Asterisk, we also want to be able to call them from Asterisk
- for them to be identified as users (in the old chan_sip) or endpoints (in the new res_sip/chan_pjsip)
- both devices need to use username and password authentication
- 6001 is setup to allow registration to Asterisk, and 6002 is setup with a static host/contact
Example SIP Trunk Configuration
This shows configuration for a SIP trunk as would typically be provided by an ITSP. That is registration to a remote server, authentication to it and a peer/endpoint setup to allow inbound calls from the provider.
- SIP provider requires registration to their server with a username of "myaccountname" and a password of "1234567890"
- SIP provider requires registration to their server at the address of 203.0.113.1:5060
- SIP provider requires outbound calls to their server at the same address of registration, plus using same authentication details.
- SIP provider will call your server with a user name of "mytrunk". Their traffic will only be coming from 203.0.113.1
Disabling res_pjsip and chan_pjsip
You may want to keep using chan_sip for a short time in Asterisk 12+ while you migrate to res_pjsip. In that case, it is best to disable res_pjsip unless you understand how to configure them both together.
There are several methods to disable or remove modules in Asterisk. Which method is best depends on your intent.
If you have built Asterisk with the PJSIP modules, but don't intend to use them at this moment, you might consider the following:
Edit the file modules.conf in your Asterisk configuration directory. (typically /etc/asterisk/)
Having a noload for the above modules should (at the moment of writing this) prevent any PJSIP related modules from loading.
- Restart Asterisk!
Other possibilities would be:
- Remove all PJSIP modules from the modules directory (often, /usr/lib/asterisk/modules)
- Remove the configuration file (pjsip.conf)
- Un-install and re-install Asterisk with no PJSIP related modules.
- If you are wanting to use chan_pjsip alongside chan_sip, you could change the port or bind interface of your chan_pjsip transport in pjsip.conf
Network Address Translation (NAT)
When configured with chan_sip, peers that are, relative to Asterisk, located behind a NAT are configured using the nat parameter. In versions 1.8 and greater of Asterisk, the following nat parameter options are available:
|no||Do not perform NAT handling other than RFC 3581.|
|force_rport||When the rport parameter is not present, send responses to the source IP address and port anyway, as though the rport parameter was present|
|comedia||Send media to the address and port from which Asterisk received it, regardless of where SDP indicates that it should be sent|
|auto_force_rport||Automatically enable the sending of responses to the source IP address and port, as though rport were present, if Asterisk detects NAT. Default.|
|auto_comedia||Automatically send media to the port from which Asterisk received it, regardless of where SDP indicates that it should be sent, if Asterisk detects NAT.|
Versions of Asterisk prior to 1.8 had less granularity for the nat parameter:
|no||Do not perform NAT handling other than RFC 3581|
|yes||Send media to the port from which Asterisk received it, regardless of where SDP indicates that it should be sent; send responses to the source IP address and port as though rport were present; and rewrite the SIP Contact to the source address and port of the request so that subsequent requests go to that address and port.|
|never||Do not perform any NAT handling|
|route||Send media to the port from which Asterisk received it, regardless of where SDP indicates that it should be sent and rewrite the SIP Contact to the source address and port of the request so that subsequent requests go to that address and port.|
In chan_pjsip, the endpoint options that control NAT behavior are:
- rtp_symmetric - Send media to the address and port from which Asterisk receives it, regardless of where SDP indicates that it should be sent
- force_rport - Send responses to the source IP address and port as though port were present, even if it's not
- rewrite_contact - Rewrite SIP Contact to the source address and port of the request so that subsequent requests go to that address and port.
Thus, the following are equivalent:
|chan_sip (sip.conf)||chan_pjsip (pjsip.conf)|
In the pjsip trunk configuration shouldn't the server_uri be the provider's IP and the client_uri my IP?
Shouldn't they be different?
Joshua C. Colp
No. The server_uri is the URI that is used to resolve and contact the server. The client_uri is the URI that tells the server what we want to register to. What you are thinking of is the Contact URI. This is automatically produced by res_pjsip_outbound_registration.
Thanks for the quick response,
I'm not sure I got that right. Are you telling me that I am sending to the provider my IP so he can route the calls where I ask?
I am still confused about the difference between the server_uri and client_uri...
Joshua C. Colp
A SIP REGISTER is for telling a remote server where you can be reached. It works by doing the following:
While in many cases server_uri and client_uri could be the same, in some SIP environments they may be different. It depends on how the remote side is set up.
There is nothing Asterisk or PJSIP specific about this really, as a REGISTER is a defined thing in SIP.
I think I get it now, thank you very much!
I see both "type=" and "type = " (so with and without a space around the equal signs). Are both allowed? I ask because those lines show up red in vim.