[SIP01]SIP Header Fields裡面各欄位用途

寫著寫著就懂了發表於2014-05-03
INVITE sip:bob@biloxi.com SIP/2.0
      Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds
      Max-Forwards: 70
      To: Bob <sip:bob@biloxi.com>
      From: Alice <sip:alice@atlanta.com>;tag=1928301774
      Call-ID: a84b4c76e66710@pc33.atlanta.com
      CSeq: 314159 INVITE
      Contact: <sip:alice@pc33.atlanta.com>
      Content-Type: application/sdp
      Content-Length: 142

      (Alice’s SDP not shown)

1. Via

Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds

1.1 用來標識Responeses訊息的返回路徑(todo:各router的區別),包含SIP版本,通過的路徑,branch;每個Request-Line(請求訊息)路過代理Server時都會記錄,然後原路返回;

1.2 用來檢查路由環,因為每經過server都會把他放在via裡面,每都一個Server裡先檢查via頭裡面有沒有這個server如果有,出現了路由環Spiral:Alice calls Bob@example.com ,example.com 把資訊傳給Bob的PC,返回時又轉給了Joe@example.com,這樣又回到了example.com proxy上,所以這不是一個死迴圈【PS: 和loop不一樣】;

1.3 Branch是一個事務ID(Transaction ID),用於區分同一個Client所發起的不同Transaction,它不會對未來的request 或者是response造成影響,對於遵循RFC3261規範的實現,這個branch引數的值必須用magic cookie”z9hG4bK”打頭. 其它部分是對“To, From, Call-ID頭域和Request-URI”按一定的演算法加密後得到;

1.4 與CallID的區別:CallID是用來在session層,branch用在transation層

Call-ID contains a globally unique identifier for this call,generated by the combination of a random string and the softphone's host name or IP address. The combination of the To tag, From tag,and Call-ID completely defines a peer-to-peer SIP relationship between Alice and Bob and is referred to as a dialog.

2.Max-Forwards

Max-Forwards: 70

serves to limit the number of hops a request can make on the way to its destination. It consists of an integer that is decremented by one at each hop.

2.1 用於表示這個包最多可以傳送多少跳,當Max-Forwards==0&&沒到達目的地時,系統會返回483(Too many hops);一般會在有Request的包裡面;

2.2 預設為70;

2.3 原理:每經過一跳時【Todo:一個代理?】都會減一向下一跳傳去.

 

3. To

To: Bob <sip:bob@biloxi.com>

3.1 目的地的絕對地址,包含補叫的display name 和被 叫URL,&前面帶的是裝置號或被叫號碼,&後帶的是Proxy地址;

3.2 這個地址用於給Proxy們找路由的,一般會經過Proxy一步步定位到最精確的位置【改為其它精確地址】.

4. From

From: Alice <sip:alice@atlanta.com>;tag=1928301774

4.1 格式與To一樣,表示Caller的絕對地址,但是會加一個Tag標籤;

4.2 Tag 他是一個隨機碼【Todo:可不可變?】用於 identification purposes.

5. Call-ID

Call-ID: a84b4c76e66710@pc33.atlanta.com

5.1 Call-ID由本地裝置(Client)生成,全域性唯一,每次呼叫這個值唯一不變,與其它的session是不同的;

5.2 對於使用者發出Invite訊息,本地會生成From Tag 和Call-ID全域性唯一碼,被叫方代理生成 To tag全域性唯一碼,這三個隨機碼做為整個對話中對話標識(dialog indentifier).

6. Cseq

CSeq: 314159 INVITE

6.1 又叫Command Seqence(命令佇列),每發一個新的請求,這個數就會+1,最大2*31;

6.2 用來標識命令和命令順序,整數部用於同一session(CallID決定)中不同的請求排序,它會與將請求和應答想匹配:比如:Alice 發1 Invite 沒返回--->再發 2 Invite--->沒返回--->再發3 Invite--->這時返回了2 Invite就知道是第2個請求得到了響應(這個數是一直遞增1的); 【因為在同一個transtation裡面,所以invite其它訊息都沒有變化的,就用cseq來區別了】
- Ack的CSeq:這個是與Invite裡面的一樣的,這使代理為非成功最終應答產生Ack時不用再建立新的CSeq,保證唯一性,只用client代理建立哦;
- Cancel的CSeq:這個也是與Invite裡面的一樣的,這也是為什麼CSeq裡面要加Method的原因,如果不加,client就不知道這個是cancel還是invite的應答了;

以上幾個欄位是所有 SIP 訊息體所必須的,其它頭欄位有些是可選的,有些在特定請求也是必須

 

7. Contact

Contact: <sip:alice@pc33.atlanta.com>

Contact contains a SIP or SIPS URI that represents a direct route to contact Alice, usually composed of a username at a fully qualified domain name (FQDN). While an FQDN is preferred, many end systems do not have registered domain names, so IP addresses are permitted. While the Via header field tells other elements where to send the response, the Contact header field tells other elements where to send future requests.

7.1 包含源的URI資訊,用來給響應訊息直接和源建立連線用;

7.2 注意和From的差別:這個是可以讓被叫方Bob直接找到呼叫方的絕對地址。

8. Content-Type,Content-Length

Content-Type: application/sdp %%指明訊息體的型別為SDP【Todo: SDP會話描述協議】

Content-Length: 142 %%指明訊息體的位元組大小

相關文章