12
2019
12
15:59:43

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

查看freeswitch 默认sip trunk配置,即所谓的default_provider
[plain] view plain copy
  1. freeswitch@internal> sofia status profile  

  2.     Profile::Gateway-Name Data State IB Calls(F/T) OB Calls(F/T)  

  3. =================================================================================================  

  4.     external::example.com sip:joeuser@example.com NOREG 0/0 0/0  

  5. =================================================================================================  

  6. 1 gateway: Inbound(Failed/Total): 0/0,Outbound(Failed/Total):0/0  

  7. freeswitch@internal>  



查看example.com到底在那些文件里配置了
[plain] view plain copy
  1. [root@localhost conf]# find . ! -wholename "*.svn*" | xargs grep -n --color=auto "example.com"  

  2. ./dialplan/default/01_example.com.xml:3: <extension name="local.example.com">  

  3. ./dialplan/default/01_example.com.xml:12: <extension name="domestic.example.com">  

  4. ./dialplan/default/01_example.com.xml:21: <extension name="international.example.com">  

  5. ./dialplan/default.xml:336: This extension is used by mod_portaudio so you can pa call sip:someone@example.com  

  6. ./autoload_configs/erlang_event.conf.xml:8: eg. freeswitch@example or freeswitch@example.com.  

  7. ./vars.xml:262: These are for conf/directory/default/example.com.xml  

  8. ./vars.xml:264: <X-PRE-PROCESS cmd="set" data="default_provider=example.com"/>  

  9. ./vars.xml:267: <X-PRE-PROCESS cmd="set" data="default_provider_from_domain=example.com"/>  

  10. [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

<include>
    <gateway name="imsclub.com">
        <param name="username" value="1019"/>
        <param name="password" value="1234"/>
        <param name="realm" value="imsclub.com"/>
        <param name="proxy" value="imsclub.com"/>
    </gateway>
</include>
说明:
1. 以上是基本配置,还有其他配置可参考example.xml
2. 确保gateways 上的sip server 已经添加指定的账号,否则毫无意义

重启external生效
freeswitch@internal> sofia profile external restart
[plain] view plain copy
  1. Reload XML [Success]  

  2. restarting: external  

  3. 2014-05-25 18:12:36.992758 [INFO] mod_enum.c:876 ENUM Reloaded  

  4. 2014-05-25 18:12:36.992758 [INFO] switch_time.c:1191 Timezone reloaded 530 definitions  

  5. 2014-05-25 18:12:37.192751 [NOTICE] sofia_reg.c:135 UN-Registering imsclub.com  

  6. 2014-05-25 18:12:38.192755 [NOTICE] sofia.c:2682 Waiting for worker thread  

  7. 2014-05-25 18:12:38.192755 [INFO] switch_core_sqldb.c:1495 sofia:external Destroying SQL queue.  

  8. 2014-05-25 18:12:38.392750 [INFO] switch_core_sqldb.c:1439 sofia:external Stopping SQL thread.  

  9. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2737 Write lock external  

  10. 2014-05-25 18:12:38.392750 [NOTICE] sofia_glue.c:6034 deleted gateway example.com from profile external  

  11. 2014-05-25 18:12:38.392750 [NOTICE] sofia_glue.c:6034 deleted gateway imsclub.com from profile external  

  12. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2749 Write unlock external  

  13. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 debug [0]  

  14. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-trace [no]  

  15. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-capture [no]  

  16. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rfc2833-pt [101]  

  17. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-port [5080]  

  18. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 dialplan [XML]  

  19. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 context [public]  

  20. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 dtmf-duration [2000]  

  21. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-codec-prefs [G722,PCMU,PCMA,GSM]  

  22. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 outbound-codec-prefs [PCMU,PCMA,GSM]  

  23. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 hold-music [local_stream://moh]  

  24. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-timer-name [soft]  

  25. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 local-network-acl [localnet.auto]  

  26. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 manage-presence [false]  

  27. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-codec-negotiation [generous]  

  28. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 nonce-ttl [60]  

  29. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 auth-calls [false]  

  30. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-late-negotiation [true]  

  31. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 inbound-zrtp-passthru [true]  

  32. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-ip [114.215.115.159]  

  33. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 sip-ip [114.215.115.159]  

  34. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 ext-rtp-ip [auto-nat]  

  35. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 ext-sip-ip [auto-nat]  

  36. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-timeout-sec [300]  

  37. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 rtp-hold-timeout-sec [1800]  

  38. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls [false]  

  39. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-only [false]  

  40. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-bind-params [transport=tls]  

  41. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-sip-port [5081]  

  42. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-cert-dir [/usr/local/freeswitch/conf/ssl]  

  43. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-passphrase []  

  44. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-date [true]  

  45. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-policy [none]  

  46. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-depth [2]  

  47. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-verify-in-subjects []  

  48. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:3725 tls-version [tlsv1,tlsv1.1,tlsv1.2]  

  49. 2014-05-25 18:12:38.392750 [NOTICE] sofia.c:4874 Started Profile external [sofia_reg_external]  

  50. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2413 Creating agent for external  

  51. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2514 Created agent for external  

  52. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2557 Set params for external  

  53. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2601 Activated db for external  

  54. 2014-05-25 18:12:38.392750 [INFO] switch_core_sqldb.c:1454 sofia:external Starting SQL thread.  

  55. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2639 Starting thread for external  

  56. 2014-05-25 18:12:38.392750 [DEBUG] sofia.c:2313 Launching worker thread for external  

  57. 2014-05-25 18:12:38.392750 [NOTICE] sofia_reg.c:3071 Added gateway 'imsclub.com' to profile 'external'  

  58. 2014-05-25 18:12:38.392750 [NOTICE] sofia_reg.c:3071 Added gateway 'example.com' to profile 'external'  

  59. 2014-05-25 18:12:38.392750 [NOTICE] sofia_reg.c:423 Registering imsclub.com  

  60. 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
[plain] view plain copy
  1.                      Name Type Data State  

  2. =================================================================================================  

  3.                  external profile sip:mod_sofia@114.215.115.159:5080 RUNNING (0)  

  4.     external::example.com gateway sip:joeuser@example.com NOREG  

  5.     external::imsclub.com gateway sip:1019@122.112.86.102 REGED  

  6.           114.215.115.159 alias internal ALIASED  

  7.                  internal profile sip:mod_sofia@114.215.115.159:5060 RUNNING (0)  

  8. =================================================================================================  

  9. 2 profiles 1 alias  

  10. freeswitch@internal>   



如果imsclub.com的sip server 也是freeswitch,查看internal reg
freeswitch@internal> sofia status profile internal reg
[plain] view plain copy
  1. Registrations:  

  2. =================================================================================================  

  3. Call-ID: 1968b168-e3f5-11e3-bbfc-7b46ccff5596  

  4. User: 1019@122.112.86.102  

  5. Contact: "user" <sip:gw+imsclub.com@114.215.115.159:5080;transport=udp;gw=imsclub.com>  

  6. Agent: FreeSWITCH-mod_sofia/1.2.23~64bit  

  7. Status: Registered(UDP)(unknown) EXP(2014-05-26 03:13:38) EXPSECS(3477)  

  8. Host: localhost.localdomain  

  9. IP: 114.215.115.159  

  10. Port: 5080  

  11. Auth-User: 1019  

  12. Auth-Realm: 122.112.86.102  

  13. MWI-Account: 1019@122.112.86.102  

  14.   

  15. Call-ID: cbcc3730-0443-cd2f-0506-40e32137a798  

  16. User: 1001@122.112.86.102  

  17. Contact: "user" <sip:1001@113.116.41.44:56688;transport=udp>  

  18. Agent: unknown  

  19. Status: Registered(UDP)(unknown) EXP(2014-05-26 02:19:05) EXPSECS(204)  

  20. Host: localhost.localdomain  

  21. IP: 113.116.41.44  

  22. Port: 56688  

  23. Auth-User: 1001  

  24. Auth-Realm: 122.112.86.102  

  25. MWI-Account: 1001@122.112.86.102  

  26. Total items returned: 2  

  27. =================================================================================================  

  28. 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:
<!-- Added by vinco at 2014-05-25 -->
<include>
    <extension name="extension-imsclub.com">
      <condition field="destination_number" expression="^0(\d+)$">
        <action application="set" data="dialed_extension=$1"/>
        <action application="bridge" data="sofia/gateway/imsclub.com/$1"/>
      </condition>
    </extension>
</include>

或者在/usr/local/freeswitch/conf/dialplan/default.xml中靠前的位置增加内容
    <!-- Added by vinco at 2014-05-25 -->
    <extension name="extension-imsclub.com">
      <condition field="destination_number" expression="^0(\d+)$">
        <action application="set" data="dialed_extension=$1"/>
        <action application="bridge" data="sofia/gateway/imsclub.com/$1"/>
      </condition>
    </extension>


说明:
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里的<gateway name="imsclub.com">保持一致;
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:01001@imsclub.com SIP/2.0
Via: SIP/2.0/UDP 172.16.0.5:53435;branch=z9hG4bK1244571202;rport
From: <sip:1000@114.215.115.159>;tag=282499375
To: <sip:01001@imsclub.com>
Contact: <sip:1000@172.16.0.5:53435;transport=udp>;+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: <sip:1000@114.215.115.159>
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:1001@122.112.86.102 SIP/2.0
Via: SIP/2.0/UDP 114.215.115.159:5080;rport;branch=z9hG4bK83N9cQFj4pcZc
Max-Forwards: 69
From: "Extension 1000" <sip:1019@122.112.86.102>;tag=Z2Sjy2Hc12cyH
To: <sip:1001@122.112.86.102>
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" <sip:1000@122.112.86.102>;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" <sip:1019@122.112.86.102>;tag=vv8D9D0mD1N6D
To: <sip:1001@113.116.41.44:56688;transport=udp>
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" <sip:1019@122.112.86.102>;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




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://hqyman.cn/post/1110.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: