Kamailio 是否有类似 FreeSWITCH 的 uuid_kill 命令
试了试,发现还真的有
如果正在振铃,那么 tm.cancel 可以结束呼叫,参考链接:
https://kamailio.org/docs/modules/5.5.x/modules/tm.html#tm.rpc.cancel
如果已经应答,那么 dlg.terminate_dlg 可以结束呼叫,参考链接:
https://kamailio.org/docs/modules/5.5.x/modules/dialog.html#dlg.r.terminate_dlg
以官方的配置文件 https://github.com/kamailio/kamailio/blob/master/etc/kamailio.cfg 为基础,增加 dialog 模块
测试步骤如下:
1)192.168.1.131 上启动 kamailio
2)1000(ip 是 192.168.1.132)注册到 kamailio
3)1001(ip 是 192.168.1.120)注册到 kamailio
4)1000 呼叫 1001,振铃
5)kamcmd tm.list
{
         cell: 0x7f7756ef3000
         tindex: 37537
         tlabel: 494791369
         method: INVITE
         from: From: <sip:1000@192.168.1.131>;tag=N4y7FrQy60Bva
to: To: <sip:1001@192.168.1.131>
callid: Call-ID: 0264de75-e7d3-123a-cb9d-08002722ff3e
        cseq: CSeq: 46086918
         uas_request: yes
         tflags: 65
         outgoings: 1
         ref_count: 1
         lifetime: 22968048
 }
 kamcmd dlg.list
{
         h_entry: 289
         h_id: 50
         ref: 1
         call-id: 0264de75-e7d3-123a-cb9d-08002722ff3e
         from_uri: sip:1000@192.168.1.131
         to_uri: sip:1001@192.168.1.131
         state: 2
         start_ts: 0
         init_ts: 1641281418
         end_ts: 0
         timeout: 0
         lifetime: 43200
         dflags: 512
         sflags: 0
         iflags: 0
         caller: {
                 tag: N4y7FrQy60Bva
                 contact: sip:gw+kam@192.168.1.132:5080;transport=udp;gw=kam
                 cseq: 46086918
                 route_set:
                 socket: udp:192.168.1.131:5060
         }
         callee: {
                 tag: <null string>
                 contact: <null string>
                 cseq: <null string>
                 route_set: <null string>
                 socket: <null string>
        }
         profiles: {
         }
         variables: {
         }
 }
 6)如果运行下面这个命令(tm.cancel callid cseq)
kamcmd tm.cancel 0264de75-e7d3-123a-cb9d-08002722ff3e s:46086918 # 这里要加 s:,否则rpc 会认为是一个整数
那么 kamailio 向 uac 回 487,向 uas 发 cancel
7)如果 uas 正常应答
kamcmd tm.list 什么都不显示,现在没有了 Transaction
kamcmd dlg.list
{
         h_entry: 289
         h_id: 50
         ref: 2
         call-id: 0264de75-e7d3-123a-cb9d-08002722ff3e
         from_uri: sip:1000@192.168.1.131
         to_uri: sip:1001@192.168.1.131
         state: 4
         start_ts: 1641281434
         init_ts: 1641281418
         end_ts: 0
         timeout: 1641324634
         lifetime: 43200
         dflags: 515
         sflags: 0
         iflags: 0
         caller: {
                 tag: N4y7FrQy60Bva
                 contact: sip:gw+kam@192.168.1.132:5080;transport=udp;gw=kam
                 cseq: 46086918
                 route_set:
                 socket: udp:192.168.1.131:5060
         }
         callee: {
                 tag: 8a7b336a
                 contact: sip:1001@192.168.1.120:8320;rinstance=64005a538988814c
                 cseq: 0
                 route_set:
                 socket: udp:192.168.1.131:5060
         }
         profiles: {
         }
         variables: {
         }
 }
 dlg 的 state 发生了改变,而且 callee 里面有内容了
8) 运行下面命令
kamcmd dlg.terminate_dlg 0264de75-e7d3-123a-cb9d-08002722ff3e N4y7FrQy60Bva 8a7b336a #Callid, from tag, to tag
kamailio 同时向 uac 和 uas 发 bye 消息