Friday 13 November 2009

Taking the plunge with SIP Trunks - part 2

Recap
In part 1, I explained how a SIP Trunk is really just a virtual connection between your Asterisk PBX and the VoIP service provider. Standard SIP signalling is used on the trunk, but more than one simultaneous call is allowed and you may have more than one DDI number.

We're moving!

Blogspot has been a great way to start blogging, but it has limitations. We've just completed a brand new annex to the smartvox web site called the Smartvox Knowledgebase - it is a combined blog plus a complete archive of all the blogs and VoIP articles I've written in the last few years. Please visit the new Smartvox Knowledgebase at:
http://kb.smartvox.co.uk/.

To read the latest revision of this article on SIP trunks in Asterisk at the new site, follow this link:
http://kb.smartvox.co.uk/index.php/asterisk/telephony-connections/sip-trunks-telephony-connections/taking-the-plunge-with-sip-trunks-part-2/



Basic requirements to enable your SIP trunk
A SIP Trunk may be used for both inbound and outbound call traffic. To make outbound calls, your Asterisk or other PBX has to send a SIP INVITE request to the VoIP service provider's equipment; when you receive an inbound call, the service provider is sending an INVITE to your PBX. While there are some subtle differences between the delivery of outbound calls and receipt of inbound calls, both share the following basic requirements:
  1. Location - knowing the address of the far-end equipment
  2. Authentication - the ability to confirm the identity of the sender


Authentication is especially important for outbound calls because these will generally incur service provider charges.

Resolving equipment location
The address of the VoIP service provider's equipment is very predictable and unlikely to change over time. But how does the VoIP service provider know the address of your PBX? Some users will have a static IP address, but this is not universal and NAT can add further complications. For this reason, most VoIP service providers will require that your PBX registers itself on their equipment.

Your PBX does this by sending a SIP REGISTER request to the service provider at regular intervals (typically every 30 to 60 minutes). In so doing it provides up-to-date information about the location of your PBX. Keep-alive messages may also be sent to keep the route open through a NAT device or firewall.

Registration for Asterisk or Trixbox
In Asterisk, registration information is provided in a single line placed in the general section of sip.conf. Using Trixbox, this line appears at the end of the trunk definition form. Here is an example of the register line:

register => 43212345:mysecret@mysipsp.com/1234

The register line includes a host name (mysipsp.com) which tells Asterisk where to send the registration request; the number at the beginning of the line (43212345) is the user ID and mysecret is the password; finally, the number 1234 shown at the end of the line - after a forward slash - is an optional parameter that tells the service provider to use this number when sending INVITE requests to Asterisk.

Authentication
The user ID and password included in the registration line above are used to provide authentication during registration - to identify to the provider that you are the correct account holder. However, take note that inbound calls do not use password authentication at the time the call is delivered - instead, Asterisk knows the request is coming from your service provider by matching the sending IP address with the host parameter stored in sip.conf.

Some examples of Asterisk configuration
In Trixbox or FreePBX, the sections for dealing with inbound calls and registration are found at the end of the SIP trunk configuation form:



If you are using raw Asterisk, the register string will look the same and the equivalent peer section in sip.conf would look like this:

[smartvox-in]
type=user
context=from-trunk
insecure=invite
host=mysipsp.com

The use of the insecure parameter as shown above is simply a way of telling Asterisk that it should not challenge for user ID and password when a new inbound call INVITE arrives. Omitting this parameter can break delivery of inbound calls.

More on dealing with inbound calls in part 3.

Sunday 1 November 2009

Taking the plunge with SIP Trunks


We're moving!

Blogspot has been a great way to start blogging, but it has limitations. We've just completed a brand new annex to the smartvox web site called the Smartvox Knowledgebase - it is a combined blog plus a complete archive of all the blogs and VoIP articles I've written in the last few years. Please visit the new Smartvox Knowledgebase at:
http://kb.smartvox.co.uk/.

To read the latest revision of this article on SIP trunks in Asterisk at the new site, follow this link:
http://kb.smartvox.co.uk/index.php/asterisk/telephony-connections/sip-trunks-telephony-connections/taking-the-plunge-with-sip-trunks-part-1/

SIP Trunks are often talked about on the Asterisk wiki and forum pages; Many VoIP service providers offer them as a standard product; But just what is a SIP trunk and what can you use it for and how do you make it work with Asterisk? I will attempt to answer these questions in what I anticipate will be a 3 part blog, starting with the basics.

What is a SIP Trunk?
A SIP trunk uses standard SIP signalling, but the endpoints of the trunk are fixed - typically one end point is the ITSP - Internet Telephony Service Provider - and the other is your PBX (e.g. Asterisk).


The SIP Trunk will usually just be one segment in the entire end-to-end pathway of a call. It may be used for inbound/outbound or both types of call and a number of different calls can be active at the same time, all using the same SIP Trunk connection. However, to truly qualify as a SIP Trunk, it should be possible to associate more than one incoming number (DDI or DID) with the same account.

What do you connect to a SIP Trunk?
Normally, the equipment at the customer's premises will be some kind of SIP-enabled PBX. An Asterisk PBX is ideal for this role.

Although possible, it would be unusual and probably impractical to connect an IP Phone or softphone directly to a SIP Trunk. However, there is just about no difference in terms of the SIP signalling. The Asterisk configuration to connect to a personal VoIP account - the type normally used for a single IP phone or softphone - is almost identical to that used for a SIP Trunk account. The differences between personal SIP accounts and SIP Trunks are as much commercial as they are technical - greater capacity for simultaneous calls and greater provision of inbound numbers managed through a single SIP connection. The main technical difference is the ability of a PBX to extract the target DDI number and use it to correctly route inbound calls.

How do you connect to a SIP Trunk?
Sometimes it is necessary for the PBX to register with the ITSP, primarily because this allows the service provider to know where the PBX is located - its IP address. The service provider then knows to send your inbound calls to that IP address. Sometimes the connection is achieved without registration, simply using a pre-defined IP address. This latter option is more likely to be used for direct connections to carriers or for other high-end connections involving wholesale services.

Making and receiving calls over a SIP Trunk
Inbound calls delivered by the ITSP to your PBX will contain the DDI number that was called. This must be interpreted by the PBX to determine the routing of the call to a device - typically a phone, but could be to a ring group or ACD queue. More about the setup for inbound calls in part 2.

Outbound calls are sent to the ITSP by the PBX and, in response to an authentication challenge, it will also need to send credentials for authentication/authorisation. The challenge authentication/authorisation is required even if the PBX has registered. Again, there will be some more on this later.