Freeswitch SIP Trunk 配置(网关gateway配置)

 
   

专注三网融合之接入网/核心网等技术,音视频信令和媒体传输相关协议,关注前沿技术 专家前辈入驻,谈笑有鸿儒,往来无白丁,共同学习探讨IMS/IPPBX相关技术

欢迎同行加入IMS/IPPBX/VoIP/SIP QQ交流群:255404741(猛戳直接加群)


查看freeswitch 默认sip trunk配置,即所谓的default_provider
freeswitch@internal> sofia status profile
    Profile::Gateway-Name Data State IB Calls(F/T) OB Calls(F/T)
=================================================================================================
    external::example.com sip:[email protected] NOREG 0/0 0/0
=================================================================================================
1 gateway: Inbound(Failed/Total): 0/0,Outbound(Failed/Total):0/0
freeswitch@internal>


查看example.com到底在那些文件里配置了
[root@localhost conf]# find . ! -wholename "*.svn*" | xargs grep -n --color=auto "example.com"
./dialplan/default/01_example.com.xml:3: 
./dialplan/default/01_example.com.xml:12: 
./dialplan/default/01_example.com.xml:21: 
./dialplan/default.xml:336: This extension is used by mod_portaudio so you can pa call sip:[email protected]
./autoload_configs/erlang_event.conf.xml:8: eg. freeswitch@example or [email protected].
./vars.xml:262: These are for conf/directory/default/example.com.xml
./vars.xml:264: 
./vars.xml:267: 
[root@localhost conf]#

(这些文件和配置之间的关系有待继续研究...)

sip trunk基本原理

    注册到freeswitch的internal内部终端之间显然可以互相拨打,比如公司内部话机可以互相通话。但公司内部话机要想主动跟外部话机通话怎么办?这是就需要进过公司软交换中心跟external外部建立通信链路,而软交换中心跟external外部建立得通信链路可以是SIP或者PSTN的运营商网络链接。Freeswitch引入所谓网关概念来处理与外部链接问题,这种链路一般称之为Trunk,故对应的有SIP Trunk和PSTN Trunk。

    在Freeswitch中配置在系统启动时注册到另一个sip服务器(即配置文件中所谓的gateway),此时Freeswitch作为一个sip client,跟其下面SIP终端注册到freeswitch是一样的。跟SIP终端一样,配置注册到网关需要用户名,密码,以及要注册到的sip服务器ip地址和端口等参数。

注册到网关的相关配置保存在目录/conf/sofia_profiles/external,/usr/local/freeswitch/conf/sip_profiles/external.xml为freeswitch作为客户端注册到另一个网关的全局配置,/usr/local/freeswitch/conf/sip_profiles/external/目录下可以添加多个网关。


sip trunk注册配置

添加注册到imclub.com的sip server上,增加imsclub.com_sip_trunk.xml内容

/usr/local/freeswitch/conf/sip_profiles/external/imsclub.com_sip_trunk.xml

   
       
       
       
       
   
说明:
1. 以上是基本配置,还有其他配置可参考example.xml
2. 确保gateways 上的sip server 已经添加指定的账号,否则毫无意义

重启external生效
freeswitch@internal> sofia profile external restart
Reload XML [Success]
restarting: external
2014-05-25 18:12:36.992758 [INFO] mod_enum.c:876 ENUM Reloaded
2014-05-25 18:12:36.992758 [INFO] switch_time.c:1191 Timezone reloaded 530 definitions
2014-05-25 18:12:37.192751 [NOTICE] sofia_reg.c:135 UN-Registering imsclub.com
2014-05-25 18:12:38.192755 [NOTICE] sofia.c:2682 Waiting for worker thread
2014-05-25 18:12:38.192755 [INFO] switch_core_sqldb.c:1495 sofia:external Destroying SQL queue.
2014-05-25 18:12:38.392750 [INFO] switch_core_sqldb.c:1439 sofia:external Stopping SQL thread.
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2737 Write lock external
2014-05-25 18:12:38.392750 [NOTICE] sofia_glue.c:6034 deleted gateway example.com from profile external
2014-05-25 18:12:38.392750 [NOTICE] sofia_glue.c:6034 deleted gateway imsclub.com from profile external
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2749 Write unlock external
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 debug [0]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-trace [no]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-capture [no]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rfc2833-pt [101]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-port [5080]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 dialplan [XML]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 context [public]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 dtmf-duration [2000]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-codec-prefs [G722,PCMU,PCMA,GSM]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 outbound-codec-prefs [PCMU,PCMA,GSM]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 hold-music [local_stream://moh]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-timer-name [soft]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 local-network-acl [localnet.auto]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 manage-presence [false]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-codec-negotiation [generous]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 nonce-ttl [60]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 auth-calls [false]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-late-negotiation [true]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-zrtp-passthru [true]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-ip [114.215.115.159]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-ip [114.215.115.159]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 ext-rtp-ip [auto-nat]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 ext-sip-ip [auto-nat]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-timeout-sec [300]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-hold-timeout-sec [1800]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls [false]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-only [false]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-bind-params [transport=tls]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-sip-port [5081]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-cert-dir [/usr/local/freeswitch/conf/ssl]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-passphrase []
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-date [true]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-policy [none]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-depth [2]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-in-subjects []
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-version [tlsv1,tlsv1.1,tlsv1.2]
2014-05-25 18:12:38.392750 [NOTICE] sofia.c:4874 Started Profile external [sofia_reg_external]
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2413 Creating agent for external
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2514 Created agent for external
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2557 Set params for external
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2601 Activated db for external
2014-05-25 18:12:38.392750 [INFO] switch_core_sqldb.c:1454 sofia:external Starting SQL thread.
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2639 Starting thread for external
2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2313 Launching worker thread for external
2014-05-25 18:12:38.392750 [NOTICE] sofia_reg.c:3071 Added gateway 'imsclub.com' to profile 'external'
2014-05-25 18:12:38.392750 [NOTICE] sofia_reg.c:3071 Added gateway 'example.com' to profile 'external'
2014-05-25 18:12:38.392750 [NOTICE] sofia_reg.c:423 Registering imsclub.com
freeswitch@internal> 

else:
sofia profile external restart reloadxml (deleted & add gateway)
sofia profile external rescan reloadxml (Ignoring duplicate gateway)

通过sofia status查看sip trunk注册状态
freeswitch@internal> sofia status
                     Name Type Data State
=================================================================================================
                 external profile sip:[email protected]:5080 RUNNING (0)
    external::example.com gateway sip:[email protected] NOREG
    external::imsclub.com gateway sip:[email protected] REGED
          114.215.115.159 alias internal ALIASED
                 internal profile sip:[email protected]:5060 RUNNING (0)
=================================================================================================
2 profiles 1 alias
freeswitch@internal> 


如果imsclub.com的sip server 也是freeswitch,查看internal reg
freeswitch@internal> sofia status profile internal reg
Registrations:
=================================================================================================
Call-ID: 1968b168-e3f5-11e3-bbfc-7b46ccff5596
User: [email protected]
Contact: "user" 
Agent: FreeSWITCH-mod_sofia/1.2.23~64bit
Status: Registered(UDP)(unknown) EXP(2014-05-26 03:13:38) EXPSECS(3477)
Host: localhost.localdomain
IP: 114.215.115.159
Port: 5080
Auth-User: 1019
Auth-Realm: 122.112.86.102
MWI-Account: [email protected]

Call-ID: cbcc3730-0443-cd2f-0506-40e32137a798
User: [email protected]
Contact: "user" 
Agent: unknown
Status: Registered(UDP)(unknown) EXP(2014-05-26 02:19:05) EXPSECS(204)
Host: localhost.localdomain
IP: 113.116.41.44
Port: 56688
Auth-User: 1001
Auth-Realm: 122.112.86.102
MWI-Account: [email protected]
Total items returned: 2
=================================================================================================
freeswitch@internal> 



增加呼叫路由dialplan
/usr/local/freeswitch/conf/dialplan/default/00_imsclub.com.xml
[root@localhost default]# ls
00_imsclub.com.xml 00_ladspa.xml 00_pizza_demo.xml 01_example.com.xml 01_Talking_Clock.xml

仿照示例的文件命名方式,增加 00_imsclub.com.xml:

   
     
       
       
     
   

或者在/usr/local/freeswitch/conf/dialplan/default.xml中靠前的位置增加内容
   
   
     
       
       
     
   


说明:
1. 此dialplan是到imsclub.com的gateway上的呼叫路由判别,例如拨01001时,呼叫会路由到imclub.com上的1001这个分机;
2. data="sofia/gateway/imsclub.com"中的gateway名字"imsclub.com"必须与/usr/local/freeswitch/conf/sip_profiles/external/imsclub.com_sip_trunk.xml里的保持一致;
3. 为了让此dialplan优先,文件名以"00_"开头。

SIP Trunk call 测试
本地freeswitch的分机1000拨01001发起呼叫;
imsclub gataway上注册的分级1001振铃,接起接通呼叫;

说明:
本地freeswitch IP: 114.215.115.159
imsclub gateway IP: 122.112.86.102

本地分机1000发起的INVITE包是这样的:

INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 172.16.0.5:53435;branch=z9hG4bK1244571202;rport
From: 1000@114.215.115.159>;tag=282499375
To: 01001@imsclub.com>
Contact: ;+g.oma.sip-im;language="en,fr";+g.3gpp.icsi-ref="urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"
Call-ID: 3243df7b-b99b-a4ce-8eab-807759750125
CSeq: 1859655307 INVITE
Content-Type: application/sdp
Content-Length: 458
Max-Forwards: 70
Accept-Contact: *;+g.3gpp.icsi-ref="urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"
P-Preferred-Service: urn:urn-7:3gpp-service.ims.icsi.mmtel
Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER
Privacy: none
P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000
User-Agent: IM-client/OMA1.0 android-ngn-stack/v2.548.870 (doubango r870 - HUAWEI P6-U06)
P-Preferred-Identity:
Supported: 100rel
v=0
o=doubango 1983 678901 IN IP4 172.16.0.5
s=-
c=IN IP4 172.16.0.5
t=0 0
a=tcap:1 RTP/AVPF
m=audio 47126 RTP/AVP 8 0 101
a=ptime:20
a=silenceSupp:off - - - -
a=rtpmap:8 PCMA/8000/1
a=rtpmap:0 PCMU/8000/1
a=rtpmap:101 telephone-event/8000/1
a=fmtp:101 0-16
a=pcfg:1 t=1
a=sendrecv
a=rtcp-mux
a=ssrc:1097005238 cname:doubango@1490770035
a=ssrc:1097005238 mslabel:6994f7d1-6ce9-4fbd-acfd-84e5131ca2e2
a=ssrc:1097005238 label:doubango@audio



imsclub收到的INVITE包是这样的

INVITE sip:[email protected] SIP/2.0
Via: SIP/2.0/UDP 114.215.115.159:5080;rport;branch=z9hG4bK83N9cQFj4pcZc
Max-Forwards: 69
From: "Extension 1000" 1019@122.112.86.102>;tag=Z2Sjy2Hc12cyH
To:
Call-ID: d8b8a9d1-5ea1-1232-8c8b-00163e0207e2
CSeq: 60172442 INVITE
Contact: <sip:gw+imsclub.com@114.215.115.159:5080;transport=udp;gw=imsclub.com>
User-Agent: FreeSWITCH-mod_sofia/1.2.23~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 209
P-Preferred-Service: urn:urn-7:3gpp-service.ims.icsi.mmtel
P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000
X-FS-Support: update_display,send_info
Remote-Party-ID: "Extension 1000" ;party=calling;screen=yes;privacy=off
v=0
o=FreeSWITCH 1400992094 1400992095 IN IP4 114.215.115.159
s=FreeSWITCH
c=IN IP4 114.215.115.159
t=0 0
m=audio 24918 RTP/AVP 8 0 101 13
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20


imsclub转发给1001的INVITE包是这样的:

INVITE sip:1001@113.116.41.44:56688;transport=udp SIP/2.0
Via: SIP/2.0/UDP 122.112.86.102;rport;branch=z9hG4bKZHZ17agD4jNeQ
Max-Forwards: 68
From: "Extension 1019" @122.112.86.102>;tag=vv8D9D0mD1N6D
To:
Call-ID: e661f55e-5ee4-1232-0e99-525400a16654
CSeq: 60186842 INVITE
Contact: <sip:mod_sofia@122.112.86.102:5060>
User-Agent: FreeSWITCH-mod_sofia/1.2.23~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 207
P-Preferred-Service: urn:urn-7:3gpp-service.ims.icsi.mmtel
P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000
X-FS-Support: update_display,send_info
Remote-Party-ID: "Extension 1019" ;party=calling;screen=yes;privacy=off
v=0
o=FreeSWITCH 1401020462 1401020463 IN IP4 122.112.86.102
s=FreeSWITCH
c=IN IP4 122.112.86.102
t=0 0
m=audio 25350 RTP/AVP 8 0 101 13
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20


转载请注明出处 http://blog.csdn.net/xuyunzhang/article/details/26975957 谢谢


你可能感兴趣的:(VoIP,tech,Freeswitch)