如下RFC文档所述:在SIP协议中,对话(Dialog)是由两个用户代理(User Agent,简称UA)之间持续一段时间的端到端关系,通过Call-ID、To-tag和From-tag来标识(即Dialog ID),用于对一个会话(Session)进行信令交互。对话代表一个上下文场景,据此来阐释相关的SIP消息(即一系列事务)。对话的建立通常是在收到响应消息(如180响应)时开始,收到2XX响应时才真正建立对话:
A dialog is a peer-to-peer SIP relationship between two user agents that persists for some time. A dialog is identified by a call identifier, local tag, and a remote tag. A dialog is established by SIP messages, such as a 2xx response to an INVITE request. The dialog facilitates sequencing of messages and proper routing of requests between the user agents. The dialog represents a context in which to interpret SIP messages. A dialog was formerly known as a call leg.
在RFC文档中出现了一些Dialog相关的概念: early dialog, confirmed dialog, inside of a dialog, outside of a dialog, mid-dialog。但这些概念在文档中模糊不清,没有严格定义。这里从中摘录了一些描述,个人了解有限,欢迎讨论。
> early dialog:早期对话
- A dialog established by a non-final response to a request is in the "early" state and it is called an early dialog, and then transition to the "confirmed" state when a 2xx final response arrives. 收到18x临时响应时建立的Dialog.
- For other responses, or if no response arrives at all on that dialog, the early dialog terminates.
- 早期对话通常由CANCEL终结.
> confirmed/final dialog:最终对话
- 收到对200 OK (Inivte)的ACK响应才建立最终对话.
- 最终对话通常由BYE终结.
-
The caller's UA MAY send a BYE for either confirmed or early dialogs, and the callee's UA MAY send a BYE on
confirmed dialogs, but MUST NOT send a BYE on early dialogs.
> outside of a dialog:对话外
-
表示消息处于对话之外。这些消息通常用于会话的初始建立或者在没有建立对话关联的情况下发送。
- Examples of requests sent outside of a dialog include an INVITE to establish a session and an OPTIONS to query for capabilities.
- A request outside of a dialog MUST NOT contain a To tag. 对话外的请求不含To-tag.
- 不确定200 OK (INVITE)之前的可靠性临时响应是否outside of a dialog。
> inside of a dialog:对话内
- 强调消息是在一个已经成功建立的对话内部.
- 不确定200 OK (INVITE)之前的可靠性临时响应是否inside of a dialog。
> mid-dialog:对话中
- mid - dialog指的是在一个已经建立的对话过程中发生的事务或消息。它用于在对话期间对会话进行修改、更新等操作。
-
mid-dialog requests may have been sent within the early dialog.
- The UAS will receive the request from the transaction layer. If the request has a tag in the To header field, the UAS core computes the dialog identifier corresponding to the request and compares it with existing dialogs. If there is a match, this is a mid-dialog request.
为方便理解,下图是IMS网络中比较完整的SIP对话建立和终止流程图:
- 有的流程中可能没有183响应和UPDATE请求。
- 180 Ring可能不带“100rel”参数,无需PRACK确认。
- ACK是一个独立的事务。
- 属于outside of a dialog的请求不只是流程图上的消息。
1)REGISTER流程是否算作一个对话?
RFC指明了REGISTER请求不会建立对话:A REGISTER request does not establish a dialog.
属于非对话消息处理:在对话建立之前或对话结束后的消息交换,如注册消息(REGISTER)和取消注册消息(DE-REGISTER),这些操作不在当前对话的上下文中进行。
2)如何区分初始邀请(INVITE)和再邀请(Re-INVITE)消息?
在SIP消息中,初始INVITE和Re-INVITE消息,都是同一个SIP方法(SIP method)"INVITE",区分如下:
初始INVITE不带To-tag,该参数通常是在1xx响应消息中分配的。而Re-INVITE带上了之前已经分配的To-tag信息。
参考文档:
1. SIP Introduction
2. RFC 3261: SIP: Session Initiation Protocol