[ N O C T E R N I T Y ] Contributing to the general pollution of the internet

19Mar/130

Playing with Asterisk (1/?)

The long term "plan" here at home is to switch over to VoIP for all phone calls. This includes getting rid of our old POTS phones, using softphones on the PCs, possibly buying hardware VoIP phones or, if I ever get the time to finish playing with the STM32 board, making our own; it also implies subscribing to a pair of SIP lines and using a board to connect our POTS line to the network.

There's a catch, tho: I've never used Asterisk (or any other kind of VoIP software), and it seems to be rather complex. So before we do anything, I'm going to be exploring its configuration a little when I have some time and nothing more important to do.

Since I'm basically a complete newbie when it comes to it, I'll try and post about it as it might be useful to someone in a similar situation.

System

Before I go on, it should be noted that I am working with a Debian Squeeze system, running inside a Xen VM. That VM is on a network that has both IPv4 and IPv6 stacks. The idea is to have everything local going through IPv6, with support for IPv4 through NAT (which means the Linux routers here need to have nf_conntrack_sip and nf_nat_sip loaded; the VM itself only has nf_conntrack_sip). While I've read that NAT is terrible when it comes to SIP (and for everything else), I'm afraid I don't have much choice on the matter.

For now I won't be doing anything that requires specific hardware, as it is a bit pointless to buy a €700 board if you're not even remotely sure you can do what you need to with it.

I have ordered a pair of webcams that include microphones, and they should arrive in a few days. At the moment, however, the PCs here have no way to record sound, so my ability to test with them is limited. I figured I could use my mobile phone for testing, though. I installed Linphone on both my PC and my smartphone.

Installing Asterisk

This is a Debian system so  it's rather easy to install Asterisk and its various dependencies:

apt-get install asterisk

Ok, I actually removed some recommended dependencies I won't be needing (either "for now" or "permanently").

The Debian package comes with a metric ton of sample configuration files under /etc/asterisk; while these are rather handy to have around as they are very well commented, I moved them out of the way as I prefer writing my own configuration from scratch.

First steps

So, the first thing I want to do is set up the server so it is possible to connect to it. That's the definition of "minimal configuration", but one has to start somewhere.

I left both asterisk.conf and modules.conf mostly untouched (with the exception of comments being removed), although I'll probably have to remove some modules when I have a better idea of what I'm doing. Most of the action here takes place in sip.conf:

[general]
        context=default
        allowoverlap=no
        udpbindaddr=0.0.0.0
        tcpenable=no
        srvlookup=yes

[test1]
        type=friend
        host=dynamic
        canreinvite=no
        nat=yes
        context=default
        dtmfmode=rfc2833
        allow=all
        username=test1
        secret=...

The general section is basically the default, followed by a test user which I can use to try and connect to the server. I also included an empty dial plan (while I'm not sure it was necessary, I figured it wouldn't hurt):

[general]
static=yes
writeprotect=no
clearglobalvars=no

[globals]
; No variables

[default]
; Empty context

After some tinkering with the Linphone configuration (I needed to add a proxy account, using sip:test1@server-ip as the identity and sip:server-ip as the proxy address), I was able to get it to connect to the server.

A basic dial plan

The next logical step was to try and have the client dialing, with the server responding with something. Fortunately, Asterisk comes with a lovely hello-world.gsm file.

First I modified my test user so that its default context would be something other than default. I called that new context test. For some reason.  Then I created a simple dial plan that would cause the server to answer, play the "hello world" sound, and hangup, when the client dials "1".

[test]
exten => 1,1,Answer()
exten => 1,2,Playback(hello-world)
exten => 1,3,Hangup

And "1" was dialed, and "Hello world" was heard, and it was good.

Two accounts

Having done that, I decided to try implementing calls between SIP clients. Of course, since only one of the two SIP clients has a microphone, my ability to test is limited.

So, I wanted to add a second SIP client. Since its configuration would end up being mostly the same as the one I already had, I decided to use a template for the clients. Here's the resulting sip.conf:

[test-template](!)
        type=friend
        host=dynamic
        canreinvite=no
        nat=yes
        context=test
        dtmfmode=rfc2833
        allow=all

[test1](test-template)
        username=test1
        secret=...

[test2](test-template)
        username=test2
        secret=...

Then I had to add a few lines to the dial plan in order to allow dialing between one client and the other. It only takes two new lines in the dial plan:

exten => 100,1,Dial(SIP/test1)
exten => 101,1,Dial(SIP/test2)

Because I don't have WiFi here, I had to whitelist the phone carrier's IP range on the firewall to let it connect to the server. The configuration of Linphone uses the server's internal IPv4 address (i.e. its address on the LAN here) as the domain, and the IPv4 address of the DSL connection as the proxy. With this configuration, I was able to call the phone from the PC and vice-versa.

Posted by Emmanuel Benoît

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

 

No trackbacks yet.