Template is not defined.

Asterisk chan_sip Vs chan_pjsip: What’s the difference and which should you use?

Introduction

When it comes to VoIP telephony, Asterisk is one of the most popular open-source platforms out there. One of the key features of Asterisk is its ability to support various SIP drivers that handle SIP signalling and media streams between endpoints. Two of the most commonly used SIP drivers in Asterisk are chan_pjsip and chan_sip. In this article, we’ll explore the differences between these two SIP drivers and help you understand which one might be the best fit for your needs.

Architecture

chan_sip and chan_pjsip Architecture

chan_sip is a monolithic driver that is responsible for all SIP-related tasks, including parsing SIP messages, negotiating codecs, and handling transport protocols. This can make it difficult to customize or extend chan_sip behaviour.

In contrast, chan_pjsip is built on top of the PJSIP library, which is a highly customizable multimedia communication library implementing standard-based protocols such as SIP, SDP, RTP, STUN, TURN, ICE and etcetera (See PJSIP Datasheet). It combines signalling protocol (SIP) with multimedia framework and NAT traversal functionality into a high-level multimedia communication API that is portable and suitable for almost any type of system ranging from desktops, and embedded systems, to mobile handsets. it allows developers to add or remove functionality as needed, this makes it easier to customize or extend chan_pjsip behaviour by modifying or adding PJSIP modules.

Advantages and disadvantages of each architecture

One advantage of chan_pjsip‘s modular architecture is that it allows for better separation of concerns. Each module is responsible for a specific task, such as handling a specific codec or transport protocol. This can make it easier to troubleshoot and maintain chan_pjsip systems.

Transport Protocol Support

chan_sip only supports the UDP transport protocol, which is the most common transport used in SIP networks. In contrast, chan_pjsip supports multiple transport protocols, including TCP, TLS, and WebSocket. This can be useful in scenarios where UDP is not an option, such as when SIP traffic needs to traverse a firewall or NAT.

Another advantage of chan_pjsip‘s transport protocol support is that it allows for more granular control over transport settings. For example, you can configure chan_pjsip to use a specific transport for a specific endpoint, which can help optimize call quality.

Codec Support

When two endpoints (such as phones or softphones) communicate over a VoIP system, they need to agree on the same codec to use for the call. A codec is a method of encoding and decoding audio or video data, and different codecs have different levels of compression and quality.

chan_sip has a limited range of supported codecs, including G.711, G.729, and GSM. In contrast, chan_pjsip supports a wider range of codecs, including the Opus codec, which is known for its high quality and low latency. This can be useful in scenarios where high-quality audio is important, such as in voice or video conferencing.

Another advantage of chan_pjsip‘s codec support is that it allows for better negotiation of codecs between endpoints. For example, if one endpoint supports Opus and another endpoint only supports G.711, chan_pjsip can negotiate the use of Opus to improve call quality. If chan_sip were used, the call would be limited to using G.711 since it’s the only codec supported by both endpoints. This means that the call quality may be lower than if Opus were used since G.711 has lower bandwidth and quality compared to Opus.

Security Features

Security is a critical aspect of any VoIP system. Both chan_pjsip and chan_sip support various security features, but chan_pjsip has some advantages in this area.

chan_pjsip supports TLS encryption for both signalling and media, which can help protect against eavesdropping and other security threats. In addition, it supports SRTP (Secure Real-time Transport Protocol) for media encryption, which can help protect against attacks like packet injection and tampering.

Compatibility

One area where chan_sip has an advantage over chan_pjsip is its compatibility with legacy SIP devices and providers. Since chan_sip has been around for a long time, it is widely supported by many SIP devices and providers. In contrast, chan_pjsip is a newer technology and may not be supported by all devices and providers.

If you’re planning to switch from chan_sip to chan_pjsip, it’s important to test

the compatibility of your devices and providers beforehand to ensure a smooth transition.

Ease of Configuration

Configuring Asterisk can be a complex task, and both chan_sip and chan_pjsip have their own configuration syntax. However, many users find chan_pjsip to be easier to configure due to its more modern and intuitive syntax.

For example, in chan_sip, you would define a SIP endpoint like this:

[1000]
type=peer
username=1000
secret=supersecret
host=dynamic

In chan_pjsip, you would define the same endpoint like this:

[1000]
type=endpoint
auth=1000
aors=1000

Many users find the chan_pjsip syntax to be more straightforward and easier to understand, especially if they are new to Asterisk.

Performance

Performance is another important consideration when choosing between chan_pjsip and chan_sip. While both drivers are designed to handle large volumes of SIP traffic, there are some performance differences to keep in mind.

chan_sip is generally considered to be faster than chan_pjsip due to its monolithic architecture. Since all SIP-related tasks are handled by a single driver, there is less overhead and fewer context switches involved. This can be important in scenarios where you need to handle a large volume of SIP traffic.

However, chan_pjsip has made significant performance improvements over the years, and in many cases, the performance difference between the two drivers is negligible. In addition, chan_pjsip‘s modular architecture can make it easier to optimize performance by selectively enabling or disabling certain modules.

Conclusion

Both chan_pjsip and chan_sip have their own strengths and weaknesses, and the best choice for your VoIP system will depend on your specific needs and requirements. If you’re looking for a more flexible and extensible SIP driver with support for multiple transport protocols and codecs, chan_pjsip might be the way to go. On the other hand, if you need compatibility with legacy devices and providers, or if you’re looking for the fastest possible performance, chan_sip might be the better choice.

Ultimately, the choice between chan_pjsip and chan_sip is a matter of trade-offs, and it’s important to carefully consider your needs and requirements before making a decision. By understanding the differences between these two drivers, you can make an informed decision that will help you build a robust and reliable VoIP system.

Table of Contents