B Establishment of the VoIP link » History » Version 12

piat, charles ugo, 03/21/2015 11:26 AM

1 1 piat, charles ugo
h1. B Establishment of the VoIP link
2 1 piat, charles ugo
3 10 piat, charles ugo
---
4 10 piat, charles ugo
5 10 piat, charles ugo
{{>toc}}
6 10 piat, charles ugo
7 2 VEILLARD GAROZ, Loïc
h3. Asterisk IP PBX
8 2 VEILLARD GAROZ, Loïc
9 2 VEILLARD GAROZ, Loïc
We had implemented as explained before, a working server running Asterisk 13.2.0 over Ubuntu Server 14.04.2. In order to connect to the asterisk server we can choose one of the following procedures:
10 2 VEILLARD GAROZ, Loïc
11 9 VEILLARD GAROZ, Loïc
* 1.Link through the router
12 5 VEILLARD GAROZ, Loïc
13 12 piat, charles ugo
Any component in the local LAN generated by the mikrotik server (by Ethernet or WiFi) may be able to connect to the asterisk server by ssh.
14 12 piat, charles ugo
For example with a computer running linux we can just type the following: 
15 4 VEILLARD GAROZ, Loïc
16 1 piat, charles ugo
   shh kasat@192.168.88.242
17 4 VEILLARD GAROZ, Loïc
18 1 piat, charles ugo
The credentials for our case are the following:
19 1 piat, charles ugo
   
20 12 piat, charles ugo
   Server IP: 192.168.88.242: This address can be changed in the DCHP server of the mikrotik router. 
21 12 piat, charles ugo
A local static address can be configured, while we discourage it
22 2 VEILLARD GAROZ, Loïc
Client: kasat
23 2 VEILLARD GAROZ, Loïc
Password: gogolgogol
24 2 VEILLARD GAROZ, Loïc
25 1 piat, charles ugo
In order to get root privileges during the session we can add "sudo" to the command that we want to run, or type the following command:
26 3 VEILLARD GAROZ, Loïc
27 2 VEILLARD GAROZ, Loïc
   sudo -i
28 1 piat, charles ugo
29 1 piat, charles ugo
Which will grant to kasat root privileges during all the ssh session.
30 1 piat, charles ugo
31 9 VEILLARD GAROZ, Loïc
 * 2.Direct configuration
32 5 VEILLARD GAROZ, Loïc
33 8 VEILLARD GAROZ, Loïc
The server can be configured directly with a screen and a keyboard connected to the Intel NUC.
34 7 VEILLARD GAROZ, Loïc
35 7 VEILLARD GAROZ, Loïc
While the asterisk server will run at system start-up, an asterisk terminal may be open with the following command:
36 7 VEILLARD GAROZ, Loïc
 
37 7 VEILLARD GAROZ, Loïc
 Asterisk -rvvvvvv 
38 7 VEILLARD GAROZ, Loïc
39 9 VEILLARD GAROZ, Loïc
This will open an asterisk terminal, where it may be configured or restarted, and we may be able to see logs in real time from it.
40 1 piat, charles ugo
41 11 piat, charles ugo
h3. Configuration of the internal calls
42 1 piat, charles ugo
43 1 piat, charles ugo
The configuration of the asterisk for the 3 handsets is implemented in the files sip.conf and extensions.conf. We register the 3 handsets in the file sip.conf and we build the channels in the extensions.conf. We had the choice to configure asterisk through the web interface or directly in the configuration files. We had chosen the second options because the first one generates errors in the handset registering. 
44 1 piat, charles ugo
45 1 piat, charles ugo
_sip.conf_
46 1 piat, charles ugo
47 1 piat, charles ugo
<pre>
48 1 piat, charles ugo
[general]
49 1 piat, charles ugo
context=unauthenticated
50 1 piat, charles ugo
allowguest=no
51 1 piat, charles ugo
srvlookup=no
52 1 piat, charles ugo
udpbindaddr=0.0.0.0
53 1 piat, charles ugo
tcpenable=no
54 1 piat, charles ugo
</pre>
55 1 piat, charles ugo
56 1 piat, charles ugo
We have set the default context to "unauthenticated" to ensure that unauthenticated guest calls will enter the dialplan. It will be useful for external call since we don't always know the caller. We have set allowguest to "no" to exclusively allow phone call from registered device in our local network. We put the udpbindaddr field equal to 0.0.0.0 to be sure that the VoIP server listen to all interfaces (nevertheless we could have udpbindaddr=192.168.35.0/24). We wanted to cancel the more restrictions as possible. 
57 1 piat, charles ugo
58 1 piat, charles ugo
In the same file we have created the template for our devices.
59 1 piat, charles ugo
60 1 piat, charles ugo
<pre>
61 1 piat, charles ugo
[office-phone](!)
62 1 piat, charles ugo
type=friend
63 1 piat, charles ugo
context=LocalSets
64 1 piat, charles ugo
host=dynamic
65 1 piat, charles ugo
nat=force_rport,comedia
66 1 piat, charles ugo
dtmfmode=auto
67 1 piat, charles ugo
disallow=all
68 1 piat, charles ugo
allow=g722 
69 1 piat, charles ugo
allow=ulaw 
70 1 piat, charles ugo
allow=alaw
71 1 piat, charles ugo
</pre>
72 1 piat, charles ugo
73 1 piat, charles ugo
We have set the type to friend so that the channel driver will match on the username and the IP. Next we have register the context as "LocalSets", this is where, calls from the device will enter the dialplan (it is not a default value, it is chosen by the user. It will correspond to the name of the template in the extensions.conf). The host parameter defines the IP address of the far end for this channel; we define the value as dynamic so we let Asterisk know that the phones will tell him where they are on the network. The NAT filed meaning network address translation; it is needed when the remote device is behind a firewall. The rport parameter signal to the far end that it should respond to the source IP and port the request originated from and respectively the comedia parameter is used to instruct Asterisk to send media (RTP) to the address and port that the far-end media came from.
74 1 piat, charles ugo
75 1 piat, charles ugo
<pre>
76 1 piat, charles ugo
[1001](office-phone)
77 1 piat, charles ugo
secret=1001 
78 1 piat, charles ugo
[1003](office-phone)
79 1 piat, charles ugo
secret=1002 
80 1 piat, charles ugo
[1003](office-phone)
81 1 piat, charles ugo
secret=1003
82 1 piat, charles ugo
</pre>
83 1 piat, charles ugo
84 1 piat, charles ugo
Here we have defined the device name and its secret's code for the 3 handsets.
85 1 piat, charles ugo
86 1 piat, charles ugo
87 1 piat, charles ugo
_extensions.conf_
88 1 piat, charles ugo
89 1 piat, charles ugo
<pre>
90 1 piat, charles ugo
[LocalSets] 
91 1 piat, charles ugo
exten => 1001,1,Dial(SIP/1001) 
92 1 piat, charles ugo
exten => 1002,1,Dial(SIP/1002) 
93 1 piat, charles ugo
exten => 1003,1,Dial(SIP/1003)
94 1 piat, charles ugo
</pre> 
95 1 piat, charles ugo
96 1 piat, charles ugo
In the file extensions.conf we create a template call "LocalSets" corresponding to the value of the context field in the sip.conf. The field “exten” means when the number 1001 (for instance in the second code line)  is dial, asterisk will call the SIP/1001. The number 1 between commas corresponds to the priority. 
97 1 piat, charles ugo
98 11 piat, charles ugo
h3. Configuration of the External calls
99 1 piat, charles ugo
100 1 piat, charles ugo
In our configuration we differentiate the InComing call from the OutGoing call. Likewise the internal call, we implement the configuration in the sip.conf to register our line from our provider and the extensions.conf to manage the calls. 
101 1 piat, charles ugo
102 1 piat, charles ugo
*InComing Call*
103 1 piat, charles ugo
104 1 piat, charles ugo
_sip.conf_
105 1 piat, charles ugo
106 1 piat, charles ugo
<pre>
107 1 piat, charles ugo
[general]
108 1 piat, charles ugo
register => 0033XXXXXXXXX:password@sip.ovh.fr
109 1 piat, charles ugo
</pre> 
110 1 piat, charles ugo
111 1 piat, charles ugo
We register our phone line with our phone number, our password and the domain provided from ovh. 
112 1 piat, charles ugo
113 1 piat, charles ugo
114 1 piat, charles ugo
<pre>
115 1 piat, charles ugo
[forfait-ovh]
116 1 piat, charles ugo
type=peer
117 1 piat, charles ugo
host=sip.ovh.fr
118 1 piat, charles ugo
context=ovh-sip
119 1 piat, charles ugo
defaultuser=0033XXXXXXXXX
120 1 piat, charles ugo
fromuser=0033XXXXXXXXX
121 1 piat, charles ugo
secret=password
122 1 piat, charles ugo
directmedia=no
123 1 piat, charles ugo
nat=force_rport,comedia
124 1 piat, charles ugo
canreinvite=no
125 1 piat, charles ugo
qualify=yes
126 1 piat, charles ugo
dtmfmode=auto
127 1 piat, charles ugo
</pre> 
128 1 piat, charles ugo
129 1 piat, charles ugo
Here we have save information corresponding to our line. The context field refers to the template in the dialplan. We retrieve almost the same filed than those presented in the internal call.
130 1 piat, charles ugo
131 1 piat, charles ugo
_extensions.conf_
132 1 piat, charles ugo
133 1 piat, charles ugo
<pre>
134 1 piat, charles ugo
[ovh-sip] ; nom du plan
135 1 piat, charles ugo
exten => s,1,Ringing(1)
136 1 piat, charles ugo
exten => s,2,Answer
137 1 piat, charles ugo
exten => s,3,Dial(SIP/1001,30,tm) 
138 1 piat, charles ugo
exten => s,4,Hangup(16) 
139 1 piat, charles ugo
</pre> 
140 1 piat, charles ugo
141 1 piat, charles ugo
In the file extensions.conf we create a template call "ovh-sip" corresponding to the value of the context field in the sip.conf. In The field “exten” we replace the number dialed by "s" which means asterisk will answer to all incoming call and the device SIP/1001 will received all the external calls. Here we can see in more details the priority rules, first Ringing, Answering, Dial and Hang-up.
142 1 piat, charles ugo
143 1 piat, charles ugo
144 1 piat, charles ugo
*OutGoing Call*
145 1 piat, charles ugo
146 1 piat, charles ugo
In this part, we will just  modified the file extensions.conf. 
147 1 piat, charles ugo
148 1 piat, charles ugo
_extensions.conf_
149 1 piat, charles ugo
150 1 piat, charles ugo
<pre>
151 1 piat, charles ugo
[external]
152 1 piat, charles ugo
exten => _0.,1,Dial(SIP/${EXTEN}@forfait-ovh) 
153 1 piat, charles ugo
[LocalSets]
154 1 piat, charles ugo
include => external
155 1 piat, charles ugo
</pre>
156 1 piat, charles ugo
157 4 VEILLARD GAROZ, Loïc
In the LocalSets we have included the template external to authorize external call to the handsets. The template “external” calls on the section [forfait-ovh] to provide the outgoing call. Only calls begining by zero (the aim is to block the international call but can be remove depending of the situation) are allowed by our configuration.