Soft Phones

Since we are using VoIP and Asterisk, we have the option of using “soft phones”. Soft phones are VoIP phone implementations in software and they run on a desktop or laptop (other devices too but we will get to that later).

Normally someone would use a soft phone like Skype or Gizmo to contact a service provider (a TSP) on the internet and the calls would be routed through that network. Since we are using Asterisk, we can setup our soft phones to connect directly to our Asterisk server, in effect creating our own network.

As we discussed, Asterisk can work with a variety of different protocols (it even supports Skype – for a fee) so we can be pretty flexible with the choice of soft phones. Our Asterisk server is setup to deal with both SIP and IAX (pronounced eecks) protocols.

SIP stands for Session Initiation Protocol and has use in a variety of technologies (presence, VoIP, video conference and so on). Without getting too involved in describing SIP, it is a means to describe and invite software to connect a stream or other network service. It actually is quite a bit like an email invitation describing the location of the event and how to be dressed. You can look at the SIP messages that are coming to and from our Asterisk server by issuing the “sip set debug on” (“sip set debug off” to turn it off) in the Asterisk console.

SIP doesn’t actually transmit the audio of the call, it just explains how to get the audio of the call and so on. The audio is transmitted via a protocol called RTP (Realtime Transport Protocol) which is derived from UDP. UDP is chosen as it provides lower latency (no error correct) than TCP. In other words if a packet of audio data is lost, it doesn’t need to re-requested as it would have to be with TCP. If it arrives late, it is just discarded and the audio of the call doesn’t need to be held up waiting for all of the data to arrive intact. If that weren’t the case, we would have very strange calls indeed, with increasing delay between when we said something and when the other person hears it.

One of the big problems with UDP is that it is “stateless”, meaning that a constant connection is not maintained between the server and the client when transmitting. This means that SIP/RTP can have trouble routing audio through routers and firewalls (NAT is especially problematic).

The alternative that we have is IAX. IAX stands for Inter-Asterisk Exchange and was developed primarily for use with Asterisk. The benefits of using IAX over SIP is that it can easily route through home firewalls and NAT routers while SIP has problems with such. Unfortunately, by using IAX we are diverging from established standards. There is some more reading offered about IAX below.
Softphones
Zoiper Classic is going to be the Softphone of choice for this class. It’s free, well supported, and can do both IAX and SIP calls. You can, however, use any softphone you like. The setup on all SIP and IAX softphones should be very similar, once you get everything configured on Asterisk.

Zoiper Classic

DO NOT DOWNLOAD ZOIPER COMMUNICATOR! It may look all fancy and cool, but trust me, stick with the elegant simplicity of Zoiper Classic. Zoiper Communicator is way too bloated and buggy.

SIP Setup
To use Zoiper (or any other SIP softphone) you need to create an entry in sip.conf. Just like all of our other configuration files, you can edit the file in the asterisk_conf directory called “sip.conf”, and it will be automatically included in the main configuration when you “module reload”.

Here are the contents my sip.conf:

[ck987_sip]
type=friend
username=ck987_sip
secret=secretpassword
host=dynamic
dtmfmode=rfc2833
disallow=all
allow=gsm
nat=force_rport,comedia
qualify=yes
context=ck987_sip
  • “friend” means that this softphone can both make and receive calls. We will primarily be using this to make calls.
  • “secret” is the password
  • “context” is the context in the dialplan that is first used when this softphone dials our server.
  • “host=dynamic” means that the softphone will register from a non-specified IP address.
  • “dtmfmode=rfc2833” is the way that this call will send DTMF (button presses).
  • “nat=force_rport,comedia” will improve your chances of getting calls through your home router.

You will notice that a context from the dialplan is specified. In this case, I am using “ck987_sip” which is defined in my extensions.conf.

Here is the context inside my extensions.conf:

[ck987_sip]
exten => s,1,Goto(ck987_sip,1,1);
exten => _X,1,Answer();
exten => _X,n,Goto(itp-redial,s,1);

The first line tells Asterisk to answer the line when a call comes in. The second line is a regular expression that matches a dialed extension, In this case a single digit. Check out this page for more info on dialplan pattern matching.

It jumps to the “itp-redial” context which is the main context that is being used when we dial in from any normal phone. In a sense this context sets the softphone to behave as it is any normal phone coming in to our Asterisk setup by dialing 19175346464. (Don’t forget to “module reload” which will activate your sip.conf and your modified extensions.conf file.)

I would suggest that if you want to use a softphone to make it easier to create and work with your applications on Asterisk that you use a similar context in your SIP configuration.

In Zoiper’s account settings, (under Preferences), you should use the following settings in a new SIP account:

  • Server Hostname/IP:¬†asterisk.itp-redial.com
  • Username: the SIP username that you defined in the sip.conf file (which should be something like NETID_sip)
  • Password: the password which you defined in the sip.conf file.
  • Caller ID Name: Anything you want. This will get passed into asterisk as the CALLERID(name) variable.

Zoiper has some built-in options that may help you get around NAT routers and firewalls.

  • Click “Show Advanced Options” in the lower left corner of the Preferences window.
  • Select your SIP account
  • Check “Use rport”, “Use rport media”, and “Force RFC-3264”
  • Choose “Don’t use STUN” in the pulldown menu
  • “Use UDP Transport” and “Use DTMF RFC-2833” should be set by default

Here’s what my SIP preferences window looks like:

 

 

 

 

 

 

 

 

 

When you launch Zoiper you may need to “Register” to our Asterisk server by choosing your SIP Account from the pulldown menu and hitting “Register”. To make a call into the context as I have suggested, you just need to dial one digit and push the Green “Dial” button.

SIP TROUBLESHOOTING
If you are having problems, log into the asterisk manager interface and the following the commands:

“sip show peers” will show all SIP peers that are loaded into Asterisk. By setting your type as “friend” you also become a “peer”. If you don’t see your user name then your sip.conf file didn’t get imported into Asterisk for some reason.

“sip show registry” will also show all SIP clients that are registered to Asterisk. If you don’t see your user name then you aren’t registered.

“sip set debug on”. This will give you debugging output. To turn off debugging (which I would do quickly to be nice to everyone else using the interface, issue the command “sip set debug off”.
IAX Setup
To setup Zoiper Classic to connect to Asterisk with IAX we need to use an iax.conf file. Just like the other conf files that we are editing, I’ve setup a way to dynamically include our individual conf files into the main conf file. Edit your own iax.conf file in your asterisk_conf directory:

asterisk_conf/iax.conf

Mine contains the following:

[ck987_iax]
type=friend
host=dynamic
username=ck987_iax
secret=itsasecret
auth=md5
requirecalltoken=no
context=ck987_iax

While this shouldn’t be required, it seems that the top line (the IAX context) should match the username.

  • “friend” means that this softphone can both make and receive calls. We will primarily be using this to make calls.
  • “secret” is the password. Make it something that only you know.
  • “auth” is the type of encryption that is used when transferring the password over the network
  • “context” is the context in the dialplan that is first used when this softphone dials our server.

The extensions.conf context that I am using is defined as follows:

[ck987_iax]
exten => s,1,Goto(ck987_iax,1,1);
exten => _X,1,Answer();
exten => _X,n,Goto(itp-redial,s,1);

The first line tells Asterisk to answer the line when a call comes in. The second line is a regular expression that matches a dialed extension. In this case a single digit. It jumps to the “itp-redial” context which is the main context that is being used when we dial in from any normal phone. In a sense this context sets the softphone to behave as it is any normal phone coming in to our Asterisk setup by dialing 1-917-534-6464. (Don’t forget to “module reload” which will activate your iax.conf file.

I would suggest that if you want to use a softphone to make it easier to create and work with your applications on Asterisk that you use a similar context in your IAX configuration.

In Zoiper’s account settings, (under Preferences), set the following info for a new IAX account:

  • Server Hostname/IP:¬†asterisk.itp-redial.com
  • Username: the IAX username that you defined in the iax.conf file (which should be something like NETID_iax)
  • Password: the password which you defined in the iax.conf file.
  • Caller ID Name: Anything you want. This will get passed into asterisk as the CALLERID(name) variable.
  • Caller ID Number: Anything you want. This will get passed into asterisk as the CALLERID(num) variable.

Here is what my IAX preferences look like in Zoiper:

 

 

 

 

 

 

 

 

 

When you launch Zoiper you may need to “Register” to our Asterisk server by choosing your IAX Account from the pulldown menu and hitting “Register”. To make a call into the context as I have suggested, you just need to dial one digit and push the Green “Dial” button.

It does the exact same thing as ck987_sip, drops the caller into the itp-redial context so that everything behaves as if it was a normal incoming call.

IAX TROUBLESHOOTING
If you are having problems, log into the asterisk manager interface and try the following commands:
“iax2 show peers” will show all IAX peers that are loaded into Asterisk. By setting your type as “friend” you also become a “peer”. If you don’t see your user name then your iax.conf file didn’t get imported into Asterisk for some reason.

“iax2 show registry” will also show all IAX clients that are registered to Asterisk. If you don’t see your user name then you aren’t registered.

“iax2 set debug on”. This will give you debugging output. To turn off debugging (which I would do quickly to be nice to everyone else using the interface, issue the command “iax2 set debug off”.

There are a bunch more SIP and IAX based softphones. Please feel free to try another one if you like. Here is a good list.

More Information: