Asterisk
From Smop.co.uk
Contents |
Plan
- basic dialing
- conference bridge (meetme)
- hunt groups
- followme
- outbound
- voicemail
- including IMAP
- LDAP config (aka "realtime" - what a crap name)
- ENUM
- misc tips and tricks
- announce call via soundbridge
- cheap US, US-toll free
- incoming - wait 3 rings then pickup, background music, MoH, use * and #
- send BT 08003289393 to http://uc.org/read/ZoIP
Software
I use Debian etch which ship asterisk 1.2. 1.6 is in beta but given the scarcity of packages for it I think it might be a bit _too_ new, so I've gone with 1.4.
Callweaver looks interesting - they claim better scalability (hashes rather than linked lists do have that benefit), more importantly to me they drop the RTC requirement.
Setup
asterisk
- create /etc/apt/sources.list.d/asterisk.list:
- deb http://rapid.dotsrc.org/rapid etch main
- apt-get install asterisk asterisk-doc asterisk-h323 speex
- apt-get install asterisk-sounds-main asterisk-sounds-extra
zaptel
Zaptel module is used for providing timing. It is best with hardware (such as a Digium card), but you can use a software "ztdummy" module - however you may have issues with this on a Xen box and you need a kernel with HZ=1000.
Alternatively it might be worth looking at callweaver who use a better timing method.
- prepare modules:
- apt-get install zaptel zaptel-source
- m-a a-i zaptel (prepare, then build zaptel)
- modprobe zaptel (API between Asterisk and Kernel) module
- modprobe ztdummy (provides 1KHz timing signal if no telephony hardware is present)
- see Xen page for kernel details
- see: http://bugs.digium.com/view.php?id=9592 - basically edit ztdummy.c and comment out "#define USE_RTC" but you must also have HZ=1000 in your kernel
- use "m-a" to build the zaptel modules - wait until you see the "expanding zaptel.tar.bz2" message
- then quickly comment out the "#define USE_RTC" line in kernel/ztdummy.c (under /usr/src/modass/usr_src/modules/zaptel)
- NB: if asterisk complains about /dev/zap, ensure you have udev installed
- "zttest" shows accuracy, it's 99%+ accurate when idle, but if I hit my webserver it drops to 80%, or even as low as -650%!
To improve the accuracy, I read xen scheduling and the (excellent as always gentoo guide.
- Xen must be booted with "sched=sedf"
- then after boot run:
- xm sched-sedf domainname 0 0 0 0 ?
callweaver
For a slicehost VPS we don't have control over the kernel, so I'm looking at callweaver there. I used these three pages:
- http://www.callweaver.org/wiki/Callweaver+deb
- http://www.callweaver.org/wiki/CallWeaver+Debian+Install+Script
- http://www.callweaver.org/wiki/Fast+Route+to+installing+CallWeaver
What I did:
- backport spandsp-0.0.4 from sid to etch
- update: it actually needs 0.0.5pre3 now!
- build callweaver from http://svn.callweaver.org/callweaver/branches/rel/1.2/
- NB: trunk is _older_ than the branch....
- build callweaver-sounds from http://svn.callweaver.org/callweaver-sounds/trunk/
- NB: there are no branches or tags
- the install script also had needed an "echo" removing from in front of the "cp" command
firewall settings
- forward "rtp" (firehol default is udp/10000-20000 which is what asterisk has in rtp.conf from everywhere
- forward "sip" from everywhere
- forward "iax2" from any IAX sources
- forward "asterisk" from any managing machines
- forward rtp2 (udp 8000-8001) since twinkle soft-client advertises that to asterisk
- I altered my gigaset handset to the same (was 5004/5005)
sip.conf
context=default ; Default context for incoming calls allowoverlap=no ; Disable overlap dialing support. (Default is yes) realm=smop.co.uk ; for digest authentication domain=smop.co.uk ; ???? TODO bindaddr=0.0.0.0 ; IP address to bind to (0.0.0.0 binds to all) srvlookup=yes ; Enable DNS SRV lookups on outbound calls externip=81.5.177.201 ; external IP localnet=192.168.0.0/24 ; local subnet ; what user other end uses as digest username register => fwdusername:fwdpassword@fwd.pulver.com/adrianfwd nat=yes canreinvite=no ; keeps asterisk in the RTP path (unless no NAT)
We now set a template for our phones:
[phone](!) ; template context=phones type=friend ; inbound and outbound calls host=dynamic ; no fixed IP qualify=yes ; send SIP OPTIONS every N(2) seconds canreinvite=nonat ; keeps asterisk in the RTP path (unless no NAT) nat=no ; use RFC3581 to determine NAT status
Then use the template:
[adrian](phone) username=adrian secret=passwordgoeshere callerid="Adrian's Caller ID"
- now add FWD:
[fwd-out-sip] ; see register line above for where _incoming_ calls go to type=peer host=fwd.pulver.com context=incoming username=fwdusername secret=fwdpassword fromdomain=fwd.pulver.com ;insecure=invite ; do not require INVITE to authenticate canreinvite=no ; keep * in the middle nat=yes ;fromuser=fwdusername ; replaces From: and Contact: in header ;context=incoming_calls ;dtmfmode=rfc2833 ;disallow=all ;allow=gsm ;allow=ulaw ;deny=0.0.0.0/0 ;permit=10.251.55.100/32
Notes:
- "type" is one of:
- peer (asterisk talks to it)
- user (it talks to asterisk
- friend (both peer and user)
- sections do _not_ inherit [general] settings (namely nat etc)
extensions.conf
This contains all the dial plans. You can reload these in asterisk with "dialplan reload". TODO
dialplans: exten => extension, priority, application
- standard extensions:
- s = start, i = invalid, t = timeout
- if the extension begins with an underscore, it is a regexp:
- X=[0-9],Z=[1-9],N=[2-9],[a-z],.=one or more, !=zero of more
- be careful not to match "i","s","t" by mistake...
- priority: 1, or "n" for next
- commands
conferencing (meetme)
If meetme says "Invalid conference number" check that it isn't also reporting "app_meetme.c: Unable to open pseudo device". In which case check /dev/zap/zapctl - if it's missing, install udev.
Links
To fix NAT problems with Asterisk, you simply tell your router to forward all data received on UDP ports 5004 to 5037, 5039 to 5082 to the private IP address of your Asterisk server.
Echo
Phoning 0203.... (out via sipdiscount, back in via sipgate), I could hear myself (talking on the initiating gigaset SIP phone) 2 seconds later - even with no microphone plugged in and with headphones plugged into the laptop (where I accepted the call). Muting the laptop stopped the echo. Now sipdiscount are returning 480 "Temporarily not available" :(
Usage notes
asterisk -rvvvvvvvv to connect to asterisk:
- module reload (reloads everything)
- dialplan reload (reload just dialplan)
- sip show peers (sip show peer ....) for a specific one
- sip show registry (shows registrations)
- sip show channels
- sip set debug [|off|peer|ip]
- iax2 show channels
Sounds
/usr/share/asterisk/sounds
- phonetic/ both "a" and "alpha"
- dictate/ enter_filename etc
- letters/
- wx/ weather
- digits - and a few more
- followme
- silence
- ha
Rates
- local = 7.6ppm
- UK = 1p/min
- mobile = 18.1 three, 17.4 O2, 16.7 Orange, 13.2 T-mobile, 16.8 vodafone
- UK = 1.19ppm
- UK 0844 = 5ppm, 0845 = 3ppm, 0870=7.51ppm, 0871=10ppm, mobile=9.9ppm
- 300mins/week to UK landline free, 1p/min thereafter
- mobile = 21.4ppm, 0845=4.8ppm
- 300mins/week, see sipdiscount
- 14.1ppm to mobile, 1.175ppm landline
- something like £3/month for trunk + £7/number
- 1.25ppm, mobile from 10ppm, 0800 inbound 3ppm
- don't say - I'm enquiring
- Daviey and DM both strongly recommends magrathea over gradwell
CODECs
comparison suggest gigaset defaults are sane
VoIP-info link and in particular wideband page.
To see asterisk transcoding speeds: "show translation recalc 10"
Gigaset default: G711 alaw, G711 ulaw, G726, G729
| CODEC | MOS (0%, 1%, 5% loss) | bitrate | Notes |
|---|---|---|---|
| G711 alaw | 4.29, 4.25, 4.11 | 64Kbps | |
| G711 ulaw | 4.30, 4.24, 4.13 | 64Kbps | |
| G726 | 4.21, 4.14, 3.79 | 16-40Kbps (32) | |
| G729 | 3.76, 3.74, 3.51 | 8-12Kbps | |
| GSM | 13Kbps | sending this to netvis was being dropped | |
| iLBC | better than G.729 | 13Kbps | being dropped from asterisk |
| Speex | 5xCPU, 50ms latency but good quality config |
Gigaset
I have a Siemens Gigaset C450/460IP DECT phone which has a SIP capable base station (handy). The HTTP server is pants and seems to dislike HTTP pipelining (or sumesuch).
- Telephony-> Connections (wait patiently - eventually the right hand side will get extra options:
- authentication name = username = gigaset
- domain = proxy server = registrar server = outbound proxy = smop.co.uk
- STUN disabled
- VOIP volume normal
- Annex B for G729 disabled (silence suppresion)
- codecs: G711 alaw, G711 ulaw, G726, G729
- Telephony -> Advanced Settings:
- DTMF over VoIP - I've turned on "Audio", "RFC2833" and "SIP Info"
- Hook-flash left to dtmf-relay/16
- Listen ports SIP: 5060
- Listen ports RTP: 8000 (and 8001) - changed from default 5004 (and 5005)
- Use random ports: no
Gradwell
- Sign up for an IAX trunk, pick the first option for destination
- login, goto "account balance" and set "maximum daily spend"
Cisco/Linksys/Sipura ATA
Setting up a Linksys 3102 in particular:
If the menus aren't there, ensure you have clicked "advanced" at the top-right.
Firmware upgrade
- goto 192.168.0.1
- upgrade firmware from 3.3.6 [1]
- Note that the utterly useless "v1.0 or v2.0" choice is irrelevant, v2.0 only gives you the "admin guide", v1.0 gives you the firmware
- cheat by putting firmware on a webserver and then visiting:
- firmware now at 5.1.7
Passwords
There are two logins - user and admin - if you see "User login" at the top-right then it means you are logged in as the _admin_ user.
- goto Voice -> System to set the "User password" (the username is hardcoded to "user")
- now relogin using "user" and the password you just set
- goto Voice -> System and you will see "User password" is already set
- but now you can set "Admin password" which it kindly prints in plaintext (over the HTTP link)
Network
The SPA3000 has two network ports - Internet and LAN.
- LAN runs a DHCP server by default (ouch!)
- LAN cannot use DHCP and cannot have a gateway (double ouch)
- Internet can use DHCP and can have a gateway
I was going to try and use the LAN only:
- Router -> LAN setup -> Enable DHCP Server = no
- hardcode the IP address and netmask
That won't work for me though as my asterisk box is on a different subnet so I had to setup Internet:
- Router -> WAN setup -> Connection Type = DHCP
- Router -> WAN setup -> Enable WAN web server = yes (default is no)
Linking to Asterisk
Select "Router" page. You will see amongst other tabs, "Line 1" and "PSTN Line". We are going to setup SIP accounts for _both_ these:
- "Line 1" is for the port labelled "phone" - i.e. where your phone handset is plugged in
- "PSTN Line" is for the port labelled "line" - i.e. the one you plug into the phone wall socket
- Router -> Line1
- Line Enable -> yes (default)
- Proxy and Registration -> Proxy: IP of asterisk server
- Subscriber Information:
- Display Name: anything you like
- User ID: dect
- Password: what you have in asterisk
/etc/asterisk/sip.conf
[dect] type=friend context=dect username=dect secret=... insecure=invite ; do not require INVITE to authenticate canreinvite=no ; keep * in the middle nat=no qualify=yes ; I like to know ; host must be dynamic to avoid: ; Peer 'dect' is trying to register, but not configured as host=dynamic host=dynamic ;host=ata.smop.co.uk
Now repeat this for the "PSTN Line" tab, (I used "landline" rather than "dect" this time). Note that the PSTN Line defaults to port 5061, not 5060 for the SIP port it uses - you may need to adjust firewalls appropriately.
The Dialplan on each of the two tabs controls what phone numbers are sent to asterisk:
- "Line 1" defaults to: (*xx|[3469]11|0|00|[2-9]xxxxxx|1xxx[2-9]xxxxxxS0|xxxxxxxxxxxx.)
- "PSTN Line" defaults to: (xx.) (for all 8 dialplans)
- dialplan guide
Now we have this setup:
- Dial(SIP/dect) will dial the phone attached to the ATA
- Incoming calls will go to the "landline" context ... (to what EXTEN? s?) TODO
- To dial out on the ATA, .... TODO
TODO: dialing dect I was receiving one-way audio. twinkle->DECT was fine, DECT->twinkle was not
UK tones
- (not done yet) UK tones
