本文來自csdn lidp http://blog.csdn.net/perfectpdl,轉載注明出處,謝謝。
我建了一個 Freeswitch 內核研究 交流群, 45211986, 歡迎加入, 另外,提供基於SIP的通信服務器及客戶端解決方案,
承接 sip/ims 視頻客戶端開發,支持接入sip軟交換,ims核心網,支持 語音,視頻,即時通信功能,視頻格式支持 h263,h264,mpeg4 軟編軟解,提供硬件編解碼接口對接,提供服務器,有興趣請聯系我。
注冊到freeswitch的客戶端可以互相撥打,但是當客戶端想通過freeswitch呼叫那些並沒有注冊到freeswitch上的客戶端怎么辦?這就需要freeswitch與外部網關鏈接,比如與另一個sip server或者pstn測的運營商網絡鏈接。Freeswitch引入網關概念來處理與外部鏈接問題。
Freeswitch中配置的網關在系統啟動時注冊到另一個sip服務器,類似於sip客戶端注冊到freeswitch。
配置網關通常需要用戶名,密碼,以及要注冊到的sip服務器ip地址。
網關相關配置保存在目錄/conf/sofia_profiles/external
/usr/local/freeswitch/conf/sip_profiles/external.xml為freeswitch作為客戶端注冊到另一個網關的全局配置,
/usr/local/freeswitch/conf/sip_profiles/external/目錄下可以添加網關。
比如添加注冊到asterisk得網關,/usr/local/freeswitch/conf/sip_profiles/external/reg_to_asterisk.xml
reg_to_asterisk.xml內容:
<include>
<gatewayname="asterisk">
<paramname="username" value="freeswitch"/>
<paramname="password" value="freeswitch"/>
<paramname="realm" value="demo.asterisk.org"/>
<paramname="proxy" value="demo.asterisk.org"/>
</gateway>
</include>
~
保存,控制台重啟 sipprofile
freeswitch@openser-dev>sofia profile external restart
2012-08-18 20:21:47.254868[INFO] mod_enum.c:871 ENUM Reloaded
2012-08-18 20:21:47.254868[INFO] switch_time.c:1163 Timezone reloaded 530 definitions
Reload XML [Success]
restarting: external
freeswitch@openser-dev>2012-08-18 20:21:47.295211 [NOTICE] sofia.c:2500 Waiting for worker thread
2012-08-18 20:21:47.956692[NOTICE] sofia_glue.c:5707 deleted gateway example.com from profile external
2012-08-18 20:21:47.956692[NOTICE] sofia.c:5202 Started Profile external [sofia_reg_external]
2012-08-18 20:21:47.984023[NOTICE] sofia_reg.c:2944 Added gateway 'asterisk' to profile 'external'
2012-08-18 20:21:47.984023[NOTICE] sofia_reg.c:2944 Added gateway 'example.com' to profile 'external'
2012-08-18 20:21:49.975233[NOTICE] sofia_reg.c:415 Registering asterisk
freeswitch@openser-dev>
freeswitch@openser-dev>
查看注冊狀態
freeswitch@internal> sofiastatus
Name Type Data State
=================================================================================================
internal-ipv6 profile sip:mod_sofia@[::1]:5060 RUNNING (0)
internal profile sip:mod_sofia@192.168.16.111:5060 RUNNING (0)
external profile sip:mod_sofia@192.168.16.111:5080 RUNNING (0)
external::example.com gateway sip:joeuser@example.com NOREG
external::asterisk gateway sip:freeswitch@demo.asterisk.org TRYING (retry: NEVER)
192.168.16.111 alias internal ALIASED
=================================================================================================
3 profiles 1 alias
a.通過網關呼出去
需要修改dialplan,在conf/dialplan/default/目錄下添加 route_to_asterisk.xml
<include>
<extension name="Dial Out asteriskGateway">
<condition field="destination_number"expression="^9(11)$">
<actionapplication="bridge"data="sofia/gateway/asterisk/$1"/>
</condition>
</extension>
</include>
Fs_cli 執行 reloadxml,客戶端呼叫 911,呼叫會路由到asterisk網關上。
b.接收網關送過來的呼叫
通常,對於那些未經認證的呼叫,freeswitch認為是不安全的,包括網關送過來的呼叫,freeswitch會把這類呼叫路由到publicdialplan context中。
/usr/local/freeswitch/conf/dialplan/public.xml為此類呼叫的dialplan,可以在
/usr/local/freeswitch/conf/dialplan/public/目錄添加對應網關送過來的dialplan
如:
Vim /usr/local/freeswitch/conf/dialplan/public/asterisk.xml
<include>
<extensionname="asterisk-inbound">
<condition field="destination_number"
expression="^(freeswitch)$">
<actionapplication="set" data="domain_name=$${domain}"/>
<actionapplication="transfer" data="1000 XML default"/>
</condition>
</extension>
</include>
當asterisk送過來的被叫號碼為freeswitch注冊到asterisk上的用戶號時,freeswitch轉移到其用戶1000。
(3)不需要手動配置網關,但與外部鏈接
如果外部網關需要diguest認證,則需要在freeswitch上配置網關,如果外部網關並不需要digesut認證,則不需要再freeswitch上手動配置(2)中的過程,有一些網關通過ip驗證,這種方式相對更簡單,但不如(2)中的安全。
比如default.xmldialplan中的
<actionapplication="bridge"data="sofia/${use_profile}/$1@conference.freeswitch.org"/>
即通過 internalsip profile送到freeswitch.org的網關上。