Worldwide Community AdvocateDavid Duffett
If you are using (or want to use) SignalWire for SIP trunking with Asterisk or FreePBX, then you will get the best results on inbound calls with PJSIP.
As my friend and industry colleague, Matt Fredrickson, Director of Open Source Software Development at Sangoma, says:
“PJSIP is the future of SIP in Asterisk, and has been available since Asterisk 12. As of the release of Asterisk 17, chan_sip has been marked as deprecated, and will receive no further development work.”
That is a great reason to make sure you are using PJSIP, but there is a technical reason too...
A good number of Asterisk and FreePBX users are hooking up with SignalWire to take advantage of our highly disruptive pricing for SIP connectivity and US and Canadian DIDs - but there is something you need to know…
When your Asterisk or FreePBX registers to SignalWire to receive inbound calls, those calls will arrive from a number of different IP addresses, not just the one your Asterisk registered to.
This is not uncommon with modern SIP providers, and is a product of our elastic infrastructure.
This is, however, an issue for Asterisk’s (from now on when you see Asterisk read Asterisk & FreePBX) older SIP channel, chan_sip - but for some reason, people continue to use it!!!
The technical issue
In chan_sip there are two types of SIP connection, one is called a ‘user’ and the other is called a ‘peer’. You may be thinking what about ‘type=friend’? That simply means that the SIP connection in question can be seen as a user OR a peer at any given point in time.
Generally speaking, we tend to think of a user sending calls to Asterisk and a peer accepting calls from Asterisk, but this is not strictly true, as peers can also send calls to Asterisk.
One of the differences between users and peers is the way that they authenticate with Asterisk:
Peers are authenticated by IP address
Users are authenticated by username and password/secret
This is where issues can arise, as when a SIP call comes into Asterisk, it first tries to match it to any Peer profiles it has (based on IP address), so calls that arrive from IP addresses other than the *single IP address* that Asterisk has associated with SignalWire will be counted as unrecognized.
One could, in theory, create a SIP peer profile in Asterisk for every single IP address that SignalWire may send calls from, but that is highly impractical as, due to our elastic infrastructure, new IP addresses could be introduced at any point in time.
Once an inbound call has been checked against Asterisk’s list of peers, it will then try matching against any user profiles it has, and there is a problem here too - as SignalWire is not expecting to be challenged for a username and password as it delivers the calls, and therefore does not respond to such a challenge from Asterisk.
So chan_sip in Asterisk is just not very good at recognizing incoming calls from SignalWire (or any other SIP provider that sends calls from multiple IP addresses).
The way around this is to set up the default context that Asterisk will send inbound calls into to process calls that come from SignalWire, and that will include obtaining the dialed number from within the SIP header.
The answer is simple...
The BEST thing to do would be to use PJSIP in Asterisk.
This is because PJSIP gives you the opportunity to set an AOR profile with a SIP domain, and this provides a way to identify any inbound calls from that SIP domain as being from SignalWire, and then direct them into the appropriate context.
You will still need to extract the dialed number from the SIP header for routing purposes. That is very straight-forward to do, and is demonstrated in our Asterisk (and FreePBX) knowledge base articles and guides.
Need further help?
I am here to help you, and with Asterisk being a specialism of mine, I am happy for you to reach out to me for assistance on the Community Slack channel (just tag @david duffett) or via email at firstname.lastname@example.org