SIP - Proxies and Routing
As we know, a proxy server can be either stateless or stateful. Here, in this chapter, we will discuss more on proxy servers and SIP routing.
Stateless Proxy Server
A stateless proxy server simply forwards the message it receives. This kind of server does not store any information of the call or transaction.
- Stateless proxies forget about the SIP request once it has been forwarded.
- Transaction will be fast via stateless proxies.
Stateful Proxy Server
A stateful proxy server keeps track of every request and response that it receives. It can use the stored information in future, if required. It can retransmit the request if it does not receive a response from the other side.
Stateful proxies remember the request after it has been forwarded, so they can use it for advance routing. Stateful proxies maintain transaction state. Transaction implies transaction state, not call state.
Transaction is not as fast with stateful proxies as stateless.
Stateful proxies can fork and retransmit if required.(e.g.: call forward busy, for example).
Via and Record-route
The Record-Route header is inserted into requests by proxies that wanted to be in the path of subsequent requests for the same call-id. It is then used by the user agent to route subsequent requests.
Via headers are inserted by servers into requests to detect loops and to help responses to find their way back to the client. This is helpful for only responses to reach their destination.
A UA himself generate and add its own address in a Via header field while sending request.
A proxy forwarding the request adds a Via header field containing its own address to the top of the list of Via header fields.
A proxy or UA generating a response to a request copies all the Via header fields from the request in order into the response, then sends the response to the address specified in the top Via header field.
A proxy receiving a response checks the top Via header field and matches its own address. If it does not match, the response has been discarded.
The top Via header field is then removed, and the response forwarded to the address specified in the next Via header field.
Via header fields contain protocolname, versionnumber, and transport (SIP/2.0/UDP, SIP/2.0/TCP, etc.) and contain portnumbers and parameters such as received, rport, branch.
A received tag is added to a Via header field if a UA or proxy receives the request from a different address than that specified in the top Via header field.
A branch parameter is added to Via header fields by UAs and proxies, which is computed as a hash function of the Request-URI, and the To, From, Call-ID, and CSeq number.