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-3/ |
Configuration for Outbound calling
Part 2 looked only at the configuration for receiving inbound calls, but the SIP Trunk configuration form in Trixbox/FreePBX has to also include the settings for making outbound calls. It may not even work at all if you only use the inbound call settings shown in part 2.
You will need a peer definition in sip.conf that includes "type=peer" and has the user ID and password required by your VoIP service provider. I also recommend that you duplicate the settings for "context=" and "insecure=" that were described in part 2 because Asterisk can be annoyingly unpredictable about separation of inbound and outbound call handling.
Outbound calls are authenticated with "username" and "secret" during call set up. Some service providers may also check that your PBX is registered, but this is usually unnecessary for outbound calls. Where the user ID assigned to you by the VoIP service provider is also your DID number, then assign that value both to the "username=" and the "fromuser=" as shown above. Otherwise, set "fromuser" as your DID number. The "host=" parameter tells Asterisk where to send the INVITE request when making a call. The "qualify=yes" parameter tells Asterisk to ping the service provider at frequent intervals - this allows Asterisk to monitor the connection and to maintain some measure of its latency (the time it takes for packets to get from one end of the connection to the other).
For those of you who prefer to use raw Asterisk instead of Trixbox or FreePBX, you will need to add a similar section in sip.conf to the one shown above for FreePBX:
[smartvox-out]
type=peer
username=432112345
secret=mysecret
fromuser=43212345
fromdomain=mysipsp.com
qualify=yes
context=from-trunk
insecure=invite
host=mysipsp.com
In fact, the above peer definition (plus the registration) should be all you need for handling both inbound and outbound calls. Inbound calls are matched against known peers by checking the address given for "host=". When there are two peers defined in sip.conf with the same host address, it is usually the last one that takes precedence. However, in the latest release 1.6 of Asterisk, this unwritten rule seems to have been reversed - the first matching peer is used. If you only have one peer definition capable of handling both inbound and outbound calls (as shown above) then there is less scope for confusion.
Matching the DDI/DID number for inbound calls
SIP trunks are likely to support multiple inbound DID numbers so your dial plan will have to be able to match each number and route the call correctly. However, different service providers use different techniques to send the dialled number to your PBX. It is very likely that you will have to add some special code to the Asterisk dial plan to extract the dialled number from the To header in the SIP INVITE. There is no point re-inventing the wheel, so I recommend you check out this link for details of how to use the CUT function in Asterisk to get the dialled number:
http://www.freepbx.org/support/documentation/howtos/how-to-get-the-did-of-a-sip-trunk-when-the-provider-doesnt-send-it-and-
Diagnosing problems and monitoring your connection
The following Asterisk CLI commands are extremely useful for checking if things are working:
To check it has registered with the VoIP service provider: sip show registry
To see information about defined sip peers: sip show peers
To see detailed information about one peer: sip show peer <peer_name>
To view all SIP packets sent to-from Asterisk: sip set debug on
To view SIP packets sent to-from one peer: sip set debug peer <peer_name>
To switch off sip debug: sip set debug off
I recommended you add the parameter "qualify=yes" in your peer definition. If you did, then the command "sip show peers" will be able to show you if the peer is reachable and what the approximate delay is for packets sent to that peer. This is shown in the last column, "Status". Note that, if this status appears as "unreachable", then Asterisk will not attempt to send any SIP requests to it - an outbound call via that peer will fail as soon as it is dialled.
If you are getting problems with one-way audio or simply with making or receiving calls over your SIP Trunk, then the chances are it will be because your Asterisk server is behind NAT. This is a very common problem and usually can be cleared by setting a couple of parameters in the general sectio of the sip.conf file (sip_general_custom.conf on Trixbox/FreePBX) and possibly setting some port forwarding on your firewall. Read my article here for details:
http://www.smartvox.co.uk/astfaq_configbehindnat.htm
Internet Bandwidth
So you've got your SIP trunk working and in theory it can carry several simultaneous calls. One thing you must remember is that each call requires a significant amount of bandwidth on your broadband connection. If you are using one broadband connection for both data and voice, then there will probably be times when the voice quality suffers because there is too much contention for the bandwidth available. If possible (and if you want to carry several simultaneous calls) it is best to use a dedicated broadband connection for voice traffic. Remember that voice uses equal amounts of upload and download bandwidth whereas ADSL has much more download capacity then upload. Try one of the many free web based broadband speed comparison tests to see how your broadband connection is performing at different times of the day. Ideally, use SDSL or a leased line solution. If you are using one Internet connection for voice and data, consider using QoS mechanisms to manage the bandwidth and prioritise voice over data. Also consider using the more compressed codecs such as GSM or G.729 instead of the uncompressed G.711 codecs (A-Law and u-Law), even if it does mean you'll have to purchase some G.729 licenses for your Asterisk server.
The following links provide useful data about the bandwidth demands for various codecs:
http://www.ozvoip.com/voip-codecs/
http://www.cisco.com/en/US/tech/tk652/tk698/technologies_tech_note09186a0080094ae2.shtml
"When there are two peers defined in sip.conf with the same host address, it is usually the last one that takes precedence."
ReplyDeleteDoes this stop you from having more than one trunk from the same provider? I have three DID numbers from the same provider and each DID has it's own trunk for the want of a better way of putting it.
Seems as thought the inbound 'user' detail will be the same for all trunks. Should there be only one 'user' details defined in the asterisk sip.conf file, or should there be three i.e. [trunkuserIN-1], [trunkuserIN-2] and [trunkuserIN-3].
If you have three different sets of registration data - user ID and password - then you will need to add three three register lines into sip.conf. Give each a different number at the end. For example:
ReplyDeleteregister => userid1:mysecret1@mysipsp.com/123451
register => userid2:mysecret2@mysipsp.com/123452
register => userid3:mysecret3@mysipsp.com/123453
If you only have one set of user ID and password then you should only have one trunk defined and then you'll need some extra code to extract the dialed number (the DID) from the To header as mentioned in part 3.
For incoming calls, the peer definitions are matched by checking the "host" setting against the IP of the sender - so if all your trunks are with the same sender, then only one peer definition will ever be used.