Transcript sip.conf

454-319/1: Voice over IP
Lecture No.12
SW PBX Asterisk
Miroslav Vozňák
VŠB - Technical University of Ostrava
Department of Telecommunications
Faculty of Electrical Engineering and Computer Science
17. listopadu 15, 708 33 Ostrava – Poruba
mailto:[email protected]
http://homel.vsb.cz/~voz29
Miroslav Voznak, Lecture No.12
1
Asterisk
Asterisk
• is SW PBX, Gateway, Feature server, Media server, Call center
• for GNU/Linux, Open BSD, Free BSD, Mac OS
• using SIP, H.323, IAX2, MGCP, SCCP
• and supporting ZAPATA telephony (Zaptel drivers)
The famous customized Linux distributions including Asterisk are
• AsteriskNOW , http://www.asterisknow.org/
• and Trixbox, http://www.trixbox.org
Miroslav Voznak, Lecture No.12
2
Install Asterisk 1.4
Ubuntu 7.10
# sudo ln -s /usr/share/asterisk /var/lib/asterisk
# sudo apt-get install asterisk
Debian SID
# apt-get install asterisk
Asterisk Installation - Tutorial
• http://www.asteriskguru.com/tutorials/asterisk_installation.html
Miroslav Voznak, Lecture No.12
3
Start
Asterisk is running and we need to connect to a running Asterisk
# su
# asterisk –vvvr
v – increases the level of verboseness
r – to connect to a running Asterisk
If we obtained following answer: Unable to connect to remote asterisk (does
/var/run/asterisk/asterisk.ctl exist? we should start Asterisk with this command
# su
# asterisk –vvvgc
g - remove resource limit on core size
c – provide a control console
Connected to Asterisk 1.4.16.2~dfsg-1 currently running on pca023a (pid = 2937)
Verbosity is at least 3
pca023a*CLI> help
/* list of command
Miroslav Voznak, Lecture No.12
4
Compiling from the source code
The main packages for Asterisk
• asterisk, the main program
• zaptel, Zapata telephony drivers
• libpri, PRI libraries
• asterisk-sounds, sound promtpts
The package requirements
• GCC compiler, version 3.x or later)
• bison, a parser generator program
• ncurses, CLI functionality
• openssl, cryptographic library
• libnewt, development package for zttool
• usb-uhci, module for ztdummy (timming)
Miroslav Voznak, Lecture No.12
5
Compiling from the source code
download, extract and compile Asterisk sources
# cd /usr/src/
# wget -–passive-ftp ftp.digium.com/pub/asterisk/asterisk-1.*.tar.gz
# wget -–passive-ftp ftp.digium.com/pub/asterisk/asterisk-sounds-*.tar.gz
# wget -–passive-ftp ftp.digium.com/pub/zaptel/zaptel-*.tar.gz
# wget -–passive-ftp ftp.digium.com/pub/libpri/libpri-*.tar.gz
# cd /usr/src/
# tar zxvf zaptel-*.tar.gz
# tar zxvf libpri-*.tar.gz
# tar zxvf asterisk-*.tar.gz
# tar zxvf asterisk-sounds*.tar.gz
# ln –s /usr/src/`uname –r` /usr/src/linux-2.4
/ *Computers running Linux 2.6 kernel–based distributions do not usually
require the use of the symbolic link
Miroslav Voznak, Lecture No.12
6
# cd /usr/src/zaptel-version
# make clean
# make
# make install
# cd /usr/src/libpri-version
# make clean
# make
# make install
# cd /usr/src/asterisk-version
# make clean
# make
# make install
# make samples
# cd /usr/src/asterisk-sounds
# make install
Miroslav Voznak, Lecture No.12
7
Verify USB, UHCI USB controller must be available
# lsmod
# dmesg | grep –i usb
Loading Zaptel module, must be loaded before any of the other modules
# modprobe zaptel
# lsmod | grep zaptel
Loading Ztdummy, interface that provides timming
# modprobe ztdummy
# lsmod | grep ztdummy
Loading Asterisk
# /usr/sbin/asterisk –vvvgc # /usr/sbin/asterisk –vvvr /* if is already running
# /usr/sbin/asterisk –rx "restart now“
/* execute
Miroslav Voznak, Lecture No.12
8
Configuration files in /etc/asterisk
/etc/zaptel.conf
zapata.conf
extension.conf
sip.conf
iax.conf
mgcp.conf
h323.conf
skinny.conf
/* physical interface of ZAPATA telephony
/* configuration of ZAPTEL interface (e.g. ISDN PRI)
/* conf. of dialplans
/* conf. of sip channel
/* conf. of iax channel
/* conf. of mgcp channel
/* conf. of h323 channel
/* conf. of sccp channel
meetme.conf
voicemail.conf
followme.conf
dundi.conf
enum.conf
...
/* suppl. service – Conference room
/* suppl. service - voice mail
/* suppl. service – forwarding
/* routing protocol between Asterisk’s
/* e.164 number mapping
Miroslav Voznak, Lecture No.12
9
SIP configuration in /etc/asterisk/sip.conf
# nano /etc/asterisk/sip.conf
[general]
/* general section contains default option
[veronika] this name configured in sip.conf matches the name of the context in extensions.conf
type=friend ; user is for incomming calls, peer for outgoing, friend for both
secret=heslo ; password for account veronika
nat=no ; this phone is not natted
host=dynamic ; registration is required, host=static is not required to register, to limit an endpoint to a
single IP is used host=IPaddress of FQDN
canreinvite=no ; forces Asterisk to stay in the media path
context=internal ; the internal context controls what we can do
callerid=veronika <200> ; additional information
[klara]
type=friend
secret=heslo
nat=no
host=dynamic
canreinvite=no
context=internal
callerid=klara <201>
Miroslav Voznak, Lecture No.12
10
Dialplan configuration in /etc/asterisk/extension.conf
# nano /etc/asterisk/extensions.conf
we can use extension 499 for phonetic test and for
SIP users we use SIP channel
add into section [globals]
sounds_exten = /var/lib/asterisk/sounds/
sounds_phonetic = /var/lib/asterisk/sounds/phonetic/
sounds_letters = /var/lib/asterisk/sounds/letters/
sounds_silence = /var/lib/asterisk/sounds/silence/
create new macro [macro-basic]
exten => s,1,Dial(${ARG1})
exten => s,2,Congestion
exten => s,3,Hangup
create new section [internal]
exten => _200,1,Macro(basic,SIP/veronika)
exten => _201,1,Macro(basic,SIP/klara)
exten => _499,1,Answer()
exten => _499,2,Playback(${sounds_phonetic}bravo)
exten => _499,3,Wait(1)
exten => _499,4,Playback(${sounds_phonetic}charlie)
exten => _499,5,Wait(1)
exten => _499,6,Playback(${sounds_phonetic}tango)
exten => _499,7,Wait(2)
exten => _499,8,Hangup()
Miroslav Voznak, Lecture No.12
11
Debug
# daniel-desktop*CLI> sip set debug
<--- SIP read from 192.168.1.20:5060 --->
INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 192.168.1.20;branch=z9hG4bKc0a80114000001704781777c000033d20000017c;rport
From: "unknown" <sip:[email protected]>;tag=4aa04d7c2e
To: <sip:[email protected]>
Contact: <sip:[email protected]>
Call-ID: D8A867565C244D2DA029B54F961F7D6E0xc0a80114
CSeq: 1 INVITE
Max-Forwards: 70
User-Agent: SJphone/1.65.377a (SJ Labs)
Content-Length: 365
Content-Type: application/sdp
Supported: replaces,norefersub,timer
v=0
o=- 3408655868 3408655868 IN IP4 192.168.1.20
s=SJphone
c=IN IP4 192.168.1.20
t=0 0
m=audio 49200 RTP/AVP 3 97 98 8 0 101
c=IN IP4 192.168.1.20
a=rtpmap:3 GSM/8000
a=rtpmap:97 iLBC/8000
a=rtpmap:98 iLBC/8000
a=fmtp:98 mode=20
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=setup:active
Miroslav
a=sendrecv
Voznak, Lecture No.12
12
Example
outgoing prefix: 0048
outgoing prefix: 00420
Asterisk-CZ
Asterisk-PL
192.168.123.130
192.168.123.131
SIP -trunk
PBX
SIP
ISDN
VoIP
SIP
VoGW
ISDN
alice
430
klara
431
bob
435
Miroslav Voznak, Lecture No.12
PSTN
13
Step No.1: install Asterisk (version 1.6) / Debian
/* Debian/Squeeze contains Asterisk 1.6 package – change sources.list
# nano /etc/apt/sources.list
deb http://ftp.debian.org/debian squeeze main
deb-src http://ftp.debian.org/debian squeeze main
deb http://security.debian.org/ squeeze/updates main
deb-src http://security.debian.org/ squeeze/updates main
# apt-get update
# apt-get upgrade
/* now we can easily install Asterisk 1.6 and check the version
# apt-get install asterisk
# asterisk -r
Asterisk 1.6.2.0-1, Copyright (C) 1999 - 2009 Digium, Inc. and others.
=========================================================================
Connected to Asterisk 1.6.2.0-1 currently running on debian (pid = 22475)
Verbosity is at least 1
debian*CLI> exit or reload if changed
debian:~#
Miroslav Voznak, Lecture No.12
14
Step No.2: configure SIP accounts
# nano /etc/asterisk/sip.conf
[alice]
type=friend
context=from-sip
callerid=Alice <430>
secret=heslo
host=dynamic
disallow=all
allow=ulaw
# nano /etc/asterisk/sip.conf
[alice]
type=friend
context=from-sip
callerid=Bob <435>
secret=heslo
host=dynamic
disallow=all
allow=ulaw
/* in Asterisk-CZ
[klara]
type=friend
context=from-sip
callerid=Klara <431>
secret=heslo
host=dynamic
disallow=all
allow=ulaw
/* in Asterisk-PL
# nano /etc/asterisk/extensions.conf
[from-sip]
exten => 430,1,Dial(SIP/alice)
exten => 431,1,Dial(SIP/klara)
# nano /etc/asterisk/extensions.conf
[from-sip]
exten => 435,1,Dial(SIP/bob)
Miroslav Voznak, Lecture No.12
15
Step No.3: configure SIP trunk
/* in Asterisk-PL
# nano /etc/asterisk/sip.conf
[trunk-CZ]
type=peer
host=192.168.123.130
context=from-sip
username=trunk-PL
secret=heslojeveslo
# nano /etc/asterisk/extensions.conf
[from-sip]
exten => 435,1,Dial(SIP/bob)
exten => _00420.,1,Set(CALLERID(num)=0048${CALLERID(num)})
exten => _00420.,2,Dial(SIP/trunk-CZ/${EXTEN:5})
/* in Asterisk-CZ
# nano /etc/asterisk/sip.conf
[trunk-PL]
type=peer
host=192.168.123.131
context=from-sip
username=trunk-CZ
secret=heslojeveslo
# nano /etc/asterisk/extensions.conf
[from-sip]
exten => 430,1,Dial(SIP/alice)
exten => 431,1,Dial(SIP/klara)
exten => _0048.,1,Set(CALLERID(num)=00420${CALLERID(num)})
exten => _0048.,2,Dial(SIP/trunk-PL/${EXTEN:4})
Miroslav Voznak, Lecture No.12
16
Step No.4: debug
debian*CLI> sip set debug on
SIP Debugging enabled
/* from Asterisk-CZ dial 0048435
-- Executing [0048435@from-sip:1] Set("SIP/alice-0000001b", "CALLERID(num)=00420430") in new stack
look up in dial plan – extensions.conf
exten => _0048.,1,Set(CALLERID(num)=00420${CALLERID(num)})
/* the rule is valid for digits starting with 0048
/* 1, the first step
/* Set variable CALLERID(num)= 00420${CALLERID(num)} , i.e. to add 00420 at beginning
-- Executing [0048435@from-sip:2] Dial("SIP/alice-0000001b", "SIP/trunk-PL/435") in new stack
exten => _0048.,2,Dial(SIP/trunk-PL/${EXTEN:4})
/* 2, in the second step Dial() application is used with arguments
SIP – technology, trunk-PL is dedicated resouce in technology and ${EXTEN} is a variable
represents the dialed digits, the syntax ${EXTEN:x} is used for stripping a certain number of digits,
in our case 4 digits are stripped
/* result = use resource “trunk-PL” in sip.conf and dial 435
-- Called trunk-PL/435
-- SIP/trunk-PL-0000001c is ringing
-- SIP/trunk-PL-0000001c answered SIP/alice-0000001b
Miroslav Voznak, Lecture No.12
17
Step No.4: debug
debian*CLI> sip set debug ip 192.168.123.130
/* capture SIP messages
<--- SIP read from UDP:192.168.123.130:5060 --->
INVITE sip:[email protected] SIP/2.0
<--- SIP read from UDP:192.168.123.130:5060 --->
SIP/2.0 401 Unauthorized
/* the request is not authorized Digest method will be used
<--- SIP read from UDP:192.168.123.130:5060 --->
ACK sip:[email protected] SIP/2.0
<--- SIP read from UDP:192.168.123.130:5060 --->
INVITE sip:[email protected] SIP/2.0
User-Agent: Asterisk PBX 1.6.2.0-1
Authorization: Digest username="trunk-CZ", realm="asterisk", algorithm=MD5, uri="sip:[email protected]",
nonce="74ffd18b", response="032bce57fe0c34b2f4d97a6fb22f3bac“
/* username “trunk-CZ” and secret are set in sip.conf
Miroslav Voznak, Lecture No.12
18
Thank you for your attention
[email protected]
Miroslav Voznak, Lecture No.12
19