
\section{Reliability of Provisional Responses}
\label{sec:relp}


Normally, provisional responses are not transmitted reliably. The TU
generates a single provisional response and passes it to the server
transaction, which sends it once. RFC~2543 provided no means for
reliable transmission of these messages.

It was later observed that reliability was important in several cases,
including interoperability scenarios with the PSTN. Therefore, an
optional capability was added in this specification to support
reliable transmission of provisional responses.

The reliability mechanism works by mirroring the current reliability
mechanisms for 2xx final responses to {\INVITE}. Those requests are
transmitted periodically by the TU until a separate transaction,
{\ACK}, is received that indicates reception of the 2xx by the
UAC. The reliability for the 2xx responses to {\INVITE} and {\ACK} messages are
end-to-end. In order to achieve reliability for provisional responses,
we do nearly the same thing. Reliable provisional responses are
retransmitted by the TU with an exponential backoff. Those
retransmissions cease when a {\PRACK} message is received. The {\PRACK}
request plays the same role as {\ACK}, but for provisional
responses. There is an important difference, however. {\PRACK} is a
normal SIP message, like {\BYE}. As such, its own reliability is
ensured hop-by-hop through each stateful proxy. Similarly, {\PRACK}
has its own response. If this were not the case, the {\PRACK} message
could not traverse existing proxy servers.

Each provisional response is given a sequence number, carried in the
\header{RSeq} header field in the response. The {\PRACK} messages contain
an \header{RAck} header field, which indicates the sequence number of the
provisional response that is being acknowledged. The acknowledgements
are not cumulative, and the specifications recommend a single
outstanding provisional response at a time, for purposes of congestion
control.

\subsection{UAS Behavior}
\label{sec:relp:uas}

A UAS {\MAY} send any non-100 provisional response to {\INVITE}
reliably, so long as the initial {\INVITE} request (the request whose
provisional response is being sent reliably) contained a
\header{Supported} header field with the option tag \header{100rel}. While this
specification does not allow reliable provisional responses for any
method but {\INVITE}, extensions that define new methods that can
establish dialogs may make use of the mechanism. 

The UAS {\MUST} send any non-100 provisional response reliably if the
initial request contained a \header{Require} header field with the option tag
\header{100rel}.  If the UAS is unwilling to do so, it {\MUST} reject the
initial request with a 420 (Bad Extension) and include an
\header{Unsupported} header field containing the option tag \header{100rel}. 

A UAS {\MUSTNOT} attempt to send a 100 (Trying) response reliably.  Only
provisional responses numbered 101 to 199 may be sent reliably.  If the
request did not include either a \header{Supported} or \header{Require}
header field indicating this feature, the UAS {\MUSTNOT} send the provisional
response reliably.

\motivation{100 (Trying) responses are hop-by-hop only.  For this
reason, the reliability mechanisms described here, which are end-to-end,
cannot be used.}

An element that can act as a proxy can also send reliable provisional
responses. In this case, it acts as a UAS for purposes of that
transaction. However, it {\MUSTNOT} attempt to do so for any request
that contains a tag in the \header{To} field. That is, a proxy cannot
generate reliable provisional responses to requests sent within the
context of a dialog. Of course, unlike a UAS, when the proxy element
receives a {\PRACK} that does not match any outstanding reliable
provisional response, the {\PRACK} {\MUST} be proxied.

The rest of this discussion assumes that the initial request contained
a \header{Supported} or \header{Require} header field listing \header{100rel},
and that there is a provisional response to be sent reliably.

The provisional response to be sent reliably is constructed by the UAS
core according
to the procedures of Section~\ref{sec:general:serv-resp} and 
Section~\ref{sec:dialog}. Specifically, the provisional response {\MUST}
establish a dialog if one is not yet created. In addition,
it {\MUST} contain a \header{Require} header field containing the option tag
\header{100rel}, and  {\MUST} include an
\header{RSeq} header field. The value of the header field for the first reliable
provisional response in a transaction {\MUST} be between 1 and 2**31 -
1. It is {\RECOMMENDED} that it be chosen uniformly in this range. The
\header{RSeq} numbering space is within a single transaction. This means
that provisional responses for different requests {\MAY} use the same
values for the \header{RSeq} number.

The reliable provisional response is passed to the transaction layer
periodically with an interval that starts at T1 seconds and doubles
for each retransmission (T1 is defined in 
Section~\ref{sec:transactions}). Once passed to the server transaction, it is
added to an internal list of unacknowledged reliable provisional
responses.

\motivation{This differs from retransmissions of 2xx responses, which
cap at T2 seconds. This is because retransmissions of {\ACK} are
triggered on receipt of a 2xx, but retransmissions of {\PRACK} take
place independently of reception of 1xx.}

Retransmissions cease when 
a matching {\PRACK} is received. {\PRACK} is like any other request
within a dialog, and the UAS core processes it according to the
procedures of Sections~\ref{sec:general:req-process} and
\ref{sec:midcalluas}. A matching {\PRACK} is defined as one within the
same dialog as the response, and whose method, \header{CSeq-num}, and
\header{response-num} in the
\header{RAck} header field match, respectively, the method
and sequence number from the \header{CSeq} and sequence number from
the \header{RSeq} of the reliable provisional response.

If a {\PRACK} request is received that does not match any unacknowledged
reliable provisional response, the UAS {\MUST} respond to the {\PRACK} with a
481 response. If the {\PRACK} does match an unacknowledged reliable
provisional response, it {\MUST} be responded to with a 2xx response. The UAS
can be certain at this point that the provisional response has
been received in order. It {\SHOULD} cease retransmissions of the
reliable provisional response, and {\MUST} remove it from the list of
unacknowledged provisional responses.

If a reliable provisional response is retransmitted for 64*T1 seconds
without reception of a corresponding {\PRACK}, the UAS {\SHOULD}
reject the original request with a 5xx response.

If the {\PRACK} contained a body, the body is treated in the same way a
body in an {\ACK} is treated.

After the first reliable provisional response for a request has been
acknowledged, the UAS {\MAY} send additional reliable provisional
responses. The UAS {\MUSTNOT} send a second reliable provisional
response until the first is acknowledged. After the first, it is
{\RECOMMENDED} that the UAS not send an additional reliable provisional
response until the previous is acknowledged. The first reliable
provisional response receives special treatment because it conveys the
initial sequence number. If additional reliable provisional responses
were sent before the first was acknowledged, the UAS could not be
certain these were received in order. 

The value of the \header{RSeq} in each subsequent reliable provisional
response for the same request {\MUST} be greater by exactly one. 
\header{RSeq} numbers {\MUSTNOT} wrap around.  Because the initial one
is chosen to be less than 2**31 - 1, but the maximum is 2**32 - 1, there
can be up to 2**31 reliable provisional responses per request, which is
more than sufficient. 

Note that the UAS {\MAY} send a final response to the initial request
before having received {\PRACK}s for all unacknowledged reliable
provisional responses.  In that case, it {\SHOULDNOT} continue to
retransmit the unacknowledged reliable provisional responses, but it
{\MUST} be prepared to process {\PRACK} requests for those outstanding
responses.  A UAS {\MUSTNOT} send new reliable provisional responses (as
opposed to retransmissions of unacknowledged ones) after sending a final
response to a request.

\subsection{UAC Behavior}
\label{sec:relp:uac}

If a provisional response is received for the initial request, and that
response contains a \header{Require} header field containing the option tag
\header{100rel}, the response is to be sent reliably.  If the response is a
100 (Trying) (as opposed to 101 to 199), this option tag {\MUST} be
ignored, and the procedures below {\MUSTNOT} be used.

Assuming the response is to be transmitted reliably, the UAC {\MUST}
create a new request with method {\PRACK}. This request is sent within
the dialog associated with the provisional response (indeed, the
provisional response may have created the dialog). {\PRACK} requests
{\MAY} contain bodies, which are interpreted according to their type
and disposition.

Note that the {\PRACK} is like any other non-{\INVITE} request within
a dialog. In particular, a UAC {\SHOULDNOT} retransmit the
{\PRACK} request when it receives a retransmission of the provisional
response being acknowledged, although doing so does not create a
protocol error. 

Once a reliable provisional response is received, retransmissions of
that response {\MUST} be discarded. A response is a retransmission
when its dialog ID, \header{CSeq}, and \header{RSeq} match the original
response. The UAC {\MUST} maintain a sequence number that indicates
the most recently received in-order reliable provisional response for
the initial request. This sequence number {\MUST} be maintained until
a final response is received for the initial request. Its value
{\MUST} be initialized to the \header{RSeq} header field in the first
reliable provisional response received for the initial request.

Handling of subsequent reliable provisional responses for the same
initial request follows the same rules as above, with the following
difference: reliable provisional responses are guaranteed to be in
order. As a result, if the UAC receives another reliable provisional
response to the same request, and its \header{RSeq} value is not one
higher than the value of the sequence number, that response {\MUSTNOT}
be acknowledged with a {\PRACK}, and {\MUSTNOT} be processed further
by the TU. An implementation {\MAY} discard the response, or {\MAY} cache
the response in the hopes of receiving the missing responses.

The UAC {\MAY} acknowledge reliable provisional responses received after
the final response or {\MAY} discard them.

