一、UAC创建sip消息
二、UAC发送sip消息
当sip消息创建好后,就可以进行发送sip消息,在发送sip消息之前UA需要做的最主要的事就是通过DNS查询确定下一跳地址(rfc3261中规定,除非本地策略明确说明,否则必须通过DNS确定下一跳地址),但是进行DNS查询时以什么作为输入条件呢?我们知道确定下一跳地址可以通过To、Request-URI或者route set的第一条记录。那么sip标准文档中是怎么规定的呢?
sip标准是这样规定的:
如果route头域中存在记录,就以route头域中的第一条记录作为DNS查询的输入条件,如果route头域不存在,就以Request-URI作为DNS查询的输入条件获取下一跳记录,如果route头域存在且其第一条记录不包含 "lr" 属性(严格路由),那么就以Request-URI作为DNS查询的输入条件获取下一跳记录(参见rfc3261-8.1.2)。
rfc3261-8.1.2
The destination for the request is then computed. Unless there is local policy specifying otherwise, the destination MUST be determined by applying the DNS procedures described in [4] as follows. If the first element in the route set indicated a strict router (resulting in forming the request as described in Section 12.2.1.1), the procedures MUST be applied to the Request-URI of the request. Otherwise, the procedures are applied to the first Route header field value in the request (if one exists), or to the request’s Request-URI if there is no Route header field present. These procedures yield an ordered set of address, port, and transports to attempt. Independent of which URI is used as input to the procedures of [4], if the Request-URI specifies a SIPS resource, the UAC MUST follow the procedures of [4] as if the input URI were a SIPS URI
三、proxy路由sip消息
proxy收到sip消息后,按照如下步骤处理:(参见rfc3261-16.12)
1、proxy会检查Request-URI,如果Request-URI指示的资源属于本proxy,那么proxy就会通过查询本地服务将Request-URI替换为更确切的值。否则proxy不会改变Request-URI。(如将 "sip:callee@domain.com" 替换为 "sip:callee@u2.domain.com")
2、proxy会检查Route头域的第一条记录,如果该记录指示的就是本proxy,那么proxy会将该记录删除掉,因为消息已经到达该节点。
3、proxy会将该消息发送给route头域的第一条记录所指示的节点,如果route为空,就将该消息发送给Request-URI所指示的节点去,proxy发送消息前通过DNS查询获得下一跳地址的IP地址、端口号和传输协议。
rfc3261-16.12
1. The proxy will inspect the Request-URI. If it indicates a resource owned by this proxy, the proxy will replace it with
the results of running a location service. Otherwise, the proxy will not change the Request-URI.
2. The proxy will inspect the URI in the topmost Route header field value. If it indicates this proxy, the proxy removes it
from the Route header field (this route node has been reached).
3. The proxy will forward the request to the resource indicated by the URI in the topmost Route header field value or in the Request-URI if no Route header field is present. The proxy determines the address, port and transport to use when forwarding the request by applying the procedures in [4] to that URI.
一个完整的消息路由,参见rfc3261-16.12.1(对理解sip消息路由有天大的帮助)