天天看點

SIP協定中臨時響應的可靠性

這次測試的過程中,出現困擾最多的問題是網關在呼叫過程中,沒有收到Alerting事件,導緻狀态機的紊亂。實際上,SIP協定已經定義了臨時響應的可靠性。 在SIP标準中規定,規定了在呼叫建立過程中對臨時消息可靠傳輸的定義,在其他過程中,可以借鑒這種機制,但是不是作為标準制定。如果呼叫建立需要支援臨時消息的可靠性,需要加上SIP頭——supported或者require,該頭部任選參數為100rel。require表明需要對端支援,supported表明本次呼叫不要求可靠傳輸,但本端支援,由UAS決定。如果對斷不支援,需要回420消息,并且在頭部中加上Unsupported字段,并且該字段的參數為100rel。 舉例說明,如果Invite消息中包含require或者supported字段,并且為100rel,則對端在100 Trying後,發送後續101-199事件需要設定指數類型的定時器。此時鐘和invite應答的重傳時鐘應該互相獨立。 當收到PRACK後,需要對進行比對,如果比對的話,重傳時鐘就可以中止了。所謂比對就是指PRACK和臨時響應處于同一個會話,且RAck中的方法,CSeq-num,response-num在此一對消息中都是吻合的。所謂吻合,咋一看不容易了解,通過以下的例子說明。

C->S: INVITE sip:[email protected] SIP/2.0      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         Supported: 100rel      
         From: sip:[email protected]      
         To: sip:[email protected]      
        Call-ID: [email protected]      
         CSeq: 1 INVITE      
         Subject: Come here Watson      
S->C: SIP/2.0 100 Trying      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected]      
         Call-ID: [email protected]      
         CSeq: 1 INVITE      

S->C: SIP/2.0 183 Proceeding

         Require: 100rel

         Via: SIP/2.0/UDP saturn.bell-tel.com

         RSeq: 776655

         From: sip:[email protected]

         To: sip:[email protected];tag=11

         Call-ID: [email protected]

         CSeq: 1 INVITE

         Content-Type: application/sdp

         v=0

         s=Let's talk

         b=CT:128

         c=IN IP4 north.east.isi.edu

         m=audio 3456 RTP/AVP 5 0 7

         m=video 2232 RTP/AVP 31  

C->S: PRACK sip:[email protected] SIP/2.0      
         RAck: 776655 1 INVITE      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 2 PRACK      
         Content-Type: application/sdp      
         v=0      
         s=Let's talk      
         b=CT:128      
         c=IN IP4 machine.bell-tel.com      
         m=audio 3456 RTP/AVP 5 0 7      
         m=video 2232 RTP/AVP 31      
S->C: SIP/2.0 200 OK      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 2 PRACK      
S->C: SIP/2.0 182 Two in the Queue      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         Require: 100rel      
         RSeq: 776656      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 1 INVITE      
S->C: SIP/2.0 182 One in the Queue      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         Require: 100rel      
         RSeq: 776657      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 1 INVITE      
C->S: PRACK sip:[email protected] SIP/2.0      
         RAck: 776656 1 INVITE      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]saturn.bell-tel.com      
         CSeq: 3 PRACK      
C->S: PRACK sip:[email protected] SIP/2.0      
         RAck: 776657 1 INVITE      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 4 PRACK      
S->C: SIP/2.0 200 OK      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 3 PRACK      
S->C: SIP/2.0 200 OK      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 4 PRACK      
S->C: SIP/2.0 200 OK      
        Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 1 INVITE      
         Content-Type: application/sdp      
         v=0      
         s=Let's talk      
         b=CT:128      
         c=IN IP4 north.east.isi.edu      
         m=audio 3456 RTP/AVP 5 0 7      
         m=video 2232 RTP/AVP 31      
C->S: ACK sip:[email protected] SIP/2.0      
         Via: SIP/2.0/UDP saturn.bell-tel.com      
         From: sip:[email protected]      
         To: sip:[email protected];tag=11      
         Call-ID: [email protected]      
         CSeq: 1 INVITE      

以上的例子摘自draft-ietf-sip-100rel-02.txt,從這個例子中可以看到PRACK發送的原理和參數要求。PRACK首先是作為一個請求,并以200 OK作為響應。PRACK發送的所針對的是一個臨時響應。 以183為例,參數為 Require: 100rel RSeq: 776655 那麼對應的PRACK的參數為

       RAck: 776655 1 INVITE

CSeq: 2 PRACK 對應的200 OK的參數是 CSeq: 2 PRACK 如果收到的PRACK得不到任何的比對,需要發送481作為響應。如果得到正确的響應,應該從響應清單中删除該響應。