<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc toc='yes'?>
<?rfc tocdepth='5'?>
<?rfc symrefs='yes'?>

<?rfc compact='yes'?>
<?rfc subcompact='no'?>

<rfc ipr="full3978" category="std" obsoletes="4091">


    <front>
        <title abbrev="ICE">
Interactive Connectivity Establishment (ICE):
A Protocol for Network Address Translator (NAT) Traversal for
Offer/Answer Protocols</title>
    
        <author initials="J.R." surname="Rosenberg"
                fullname="Jonathan Rosenberg">
            <organization>Cisco</organization>
    
            <address>
                <postal>
                    <city>Edison</city> <region>NJ</region>
                    <country>US</country>
                </postal>
    
                <phone>+1 973 952-5000</phone>
                <email>jdrosen@cisco.com</email>
                <uri>http://www.jdrosen.net</uri>
            </address>
        </author>
    
        <date month="October" year="2007" />
    
        <area>RAI</area>
        <workgroup>MMUSIC</workgroup>
        <keyword>SIP</keyword>
        <keyword>NAT</keyword>
        <abstract>
            <t>This document describes a protocol for Network Address
            Translator (NAT) traversal for UDP-based multimedia
            sessions established with the offer/answer model. This
            protocol is called Interactive Connectivity Establishment
            (ICE). ICE makes use of the Session Traversal Utilities
            for NAT (STUN) protocol and its extension, Traversal Using
            Relay NAT (TURN). ICE can be used by any protocol
            utilizing the offer/answer model, such as the Session
            Initiation Protocol (SIP).</t>
        </abstract>
    </front>

<middle>

<!-- rationalize and validate 50ms Ta timer -->

<!-- in example flow, add tables for priorities before the peer
allocation and then after, per magnus comment -->

<!-- in security considerations section, mention that p2p connectivity
checks use password and that brings some security considerations, per
magnus comment -->

<!-- clarify that trapezoid turn case works, on purpose -->

<!-- desire a situation whereby there is a centralized turn service
provider, and you have endpoints behind different enterprises, and you
want both endpoints to pick the same turn server -->

<!-- dealing with ICE hammer attack: time limit total duration of this
attack. reduce number of retransmits -->

<!-- francois private address hiding idea -->

<!-- from 3489bis-04 - should move to 436 instead of 430 resposne -->

<!-- determining stun server address from SIP AOR - is that in here -->

<!-- open issue: can eliminate remote-candidates entirely, if we
always generated a triggered check when the use-candidate flag is
present, and furthermore delay responding to the use-candidate check
until the triggered check completes. Would also make the verification
procedures identical for offerer and answerer; they are different now
because if the updated offer shows up while answerer is still running,
answer might have m/c-line that doesn't match any candidates, if a
peer-derived one yet-to-be-discovered was used. However cost of this
simplification is extra RTT and a extra bandwidth of retransmits -->

<section title="Introduction">

<t> RFC 3264 <xref target="RFC3264"/> defines a two-phase exchange of
Session Description Protocol (SDP) messages <xref
target="RFC4566"/> for the purposes of establishment
of multimedia sessions. This offer/answer mechanism is used by
protocols such as the <xref target="RFC3261">Session Initiation
Protocol (SIP)</xref>.  </t>

<t>Protocols using offer/answer are difficult to operate through
Network Address Translators (NAT). Because their purpose is to
establish a flow of media packets, they tend to carry the IP addresses
and ports of media sources and sinks within their messages, which is
known to be problematic through NAT <xref target="RFC3235"/>. The
protocols also seek to create a media flow directly between
participants, so that there is no application layer intermediary
between them. This is done to reduce media latency, decrease packet
loss, and reduce the operational costs of deploying the
application. However, this is difficult to accomplish through NAT. A
full treatment of the reasons for this is beyond the scope of this
specification.  </t>

<t> Numerous solutions have been defined for allowing these protocols
to operate through NAT. These include Application Layer Gateways
(ALGs), the <xref target="RFC3303"> Middlebox Control Protocol</xref>,
the original <xref target="RFC3489">Simple Traversal of UDP Through NAT
(STUN)</xref> specification, and <xref target="RFC3102">Realm Specific
IP</xref> <xref target="RFC3103"/> along with session description
extensions needed to make them work, such as the Session Description
Protocol (SDP) <xref target="RFC4566"/> attribute for
the Real Time 
Control Protocol (RTCP) <xref target="RFC3605"/>. Unfortunately, these
techniques all have pros and cons which make each one optimal in some
network topologies, but a poor choice in others. The result is that
administrators and implementors are making assumptions about the
topologies of the networks in which their solutions will be
deployed. This introduces complexity and brittleness into the
system. What is needed is a single solution which is flexible enough
to work well in all situations.  </t>

<t> This specification defines Interactive Connectivity Establishment
(ICE) as a technique for NAT traversal for UDP-based media streams
(though ICE can be extended to handle other transport protocols, such
as TCP <xref target="I-D.ietf-mmusic-ice-tcp"/>) established by the
offer/answer model. ICE is an extension to the offer/answer model, and
works by including a multiplicity of IP addresses and ports in SDP
offers and answers, which are then tested for connectivity by
peer-to-peer connectivity checks. The IP addresses and ports included
in the SDP and the connectivity checks are performed using the revised
STUN specification <xref target="I-D.ietf-behave-rfc3489bis"/>, now
renamed to Session Traversal Utilities for NAT. The new name and new
specification reflect its new role as a tool that is used with other
NAT traversal techniques (namely ICE) rather than a standalone NAT
traversal solution, as the original STUN specification was. ICE also
makes use of Traversal Using Relay NAT (TURN)
<xref target="I-D.ietf-behave-turn"/>, an extension to STUN.  Because
ICE exchanges a multiplicity of IP addresses and ports for each media
stream, it also allows for address selection for multi-homed and
dual-stack hosts, and for this reason it deprecates RFC 4091
<xref target="RFC4091"/>.
</t>

</section>

<section title="Overview of ICE">

<t> In a typical ICE deployment, we have two endpoints (known
as AGENTS in RFC 3264 terminology) which want to communicate.
They are able to communicate indirectly via some signaling
protocol (such as SIP), by which they can perform an offer/answer exchange
of SDP <xref target="RFC3264"/> messages. Note that ICE is not
intended for NAT traversal for SIP, which is assumed to be provided
via another mechanism <xref target="I-D.ietf-sip-outbound"/>. At
the beginning 
of the ICE process, the agents are ignorant of their own topologies.
In particular, they might or might not be behind a NAT (or
multiple tiers of NATs). ICE allows the agents to discover
enough information about their topologies to potentially find one or
more paths by which they can communicate.
</t>

<t>
<xref target="fig-ice-ref-arch"/> shows a typical environment for ICE
deployment. The two endpoints are labelled L and R (for left and
right, which helps visualize call flows). Both L and R are behind
their own respective NATs though they may not be aware of it. The type
of NAT and its properties are also 
unknown. Agents L and R are capable of engaging in an offer/answer
exchange by which they can exchange SDP messages, whose purpose is to
set up a media session between L and R. Typically, this exchange will
occur through a SIP server.
</t>

<t>
In addition to the agents, a SIP server and NATs, ICE is typically
used in concert with STUN or TURN servers in the network. Each agent can have
its own STUN or TURN server, or they can be the same. 
</t>

<figure title="ICE Deployment Scenario" anchor="fig-ice-ref-arch"><artwork>
<![CDATA[
                                                                          
                           +-------+                                      
                           | SIP   |                                      
        +-------+          | Srvr  |          +-------+                   
        | STUN  |          |       |          | STUN  |                   
        | Srvr  |          +-------+          | Srvr  |                   
        |       |         /         \         |       |                   
        +-------+        /           \        +-------+                   
                        /             \                                      
                       /               \                                     
                      /                 \                                    
                     /                   \                                   
                    /  <-  Signalling ->  \                                  
                   /                       \                                  
                  /                         \                                 
            +--------+                   +--------+                       
            |  NAT   |                   |  NAT   |                       
            +--------+                   +--------+                       
              /                                \                            
             /                                  \                           
            /                                    \                          
        +-------+                             +-------+                   
        | Agent |                             | Agent |                   
        |   L   |                             |   R   |                   
        |       |                             |       |                   
        +-------+                             +-------+                   
]]></artwork></figure>


<t>The basic idea behind ICE is as follows: each agent has
a variety of candidate TRANSPORT ADDRESSES (combination of IP address
and port for a particular transport protocol, which is always UDP in
  this specification)) it could use to
communicate with the other agent. These might include:
<list style="symbols">
<t>A transport address on a directly attached network interface</t> 

<t>A translated transport address on the public side of a NAT (a "server
reflexive" address)</t> 

<t>The transport address allocated from a TURN server(a "relayed
  address".</t>

</list>
</t>

<t>
Potentially, any of L's candidate transport addresses can be used to
communicate with any of R's candidate transport addresses. In practice, however,
many combinations will not work. For instance, if L and R are both
behind NATs, their directly attached interface addresses are unlikely to be
able to communicate directly (this is why ICE is needed, after
all!). The purpose of ICE is to discover which pairs of addresses will
work.  The way that ICE does this is to systematically try all
possible pairs (in a carefully sorted order) until it finds one or
more that works.
</t>

<section title="Gathering Candidate Addresses">
<t>
In order to execute ICE, an agent has to identify all of its address
candidates. A CANDIDATE is a transport address - a combination of IP
address and port for a particular transport protocol (with only UDP
specified here). This document
defines three types of candidates, some derived from physical or
logical network interfaces, others discoverable via STUN and TURN.  Naturally,
one viable candidate is a transport address obtained directly from a
local interface. Such a candidate is called a HOST CANDIDATE. The
local interface could be ethernet or WiFi, or it could be one that is
obtained through a tunnel mechanism, such as a Virtual Private Network
(VPN) or Mobile IP (MIP). In all cases, such a network interface
appears to the agent as a local interface from which ports (and thus
candidates) can be allocated. 
</t>

<t> If an agent is multihomed, it obtains a candidate from each
IP address. Depending on the location of the PEER (the other agent in
the session) on the IP network
relative to the agent, the agent may be reachable by the peer through
one or more of those IP addresses. Consider, for example, an
agent which has a local IP address on a private net 10 network (I1), and
a second connected to the public Internet (I2). A candidate from I1 will
be directly reachable when communicating with a peer on the same
private net 10 network, while a candidate from I2 will be directly
reachable when communicating with a peer on the 
public Internet. Rather than trying to guess which IP address will work
prior to sending an offer, the offering agent includes both candidates
in its offer.
</t>

<t> Next, the agent uses STUN or TURN to obtain additional
candidates. These come in two flavors: translated addresses on the
public side of a NAT (SERVER REFLEXIVE CANDIDATES) and addresses on
TURN servers (RELAYED CANDIDATES). When TURN servers are utilized,
both types of candidates are obtained from the TURN server. If only
STUN servers are utilized, only server reflexive candidates are
obtained from them.  The relationship of these candidates to the host candidate
is shown in <xref target="fig-address-types"/>.  In this figure, both
types of candidates are discovered using TURN. In the figure, the
notation X:x means IP address X and UDP port x.
</t>

<figure title="Candidate Relationships" anchor="fig-address-types">
<artwork>
<![CDATA[
                                                                          
              To Internet                                                 
                                                                          
                  |                                                       
                  |                                                       
                  |  /------------  Relayed                               
              Y:y | /               Address                               
              +--------+                                                  
              |        |                                                  
              |  TURN  |                                                  
              | Server |                                                  
              |        |                                                  
              +--------+                                                  
                  |                                                       
                  |                                                       
                  | /------------  Server                                 
           X1':x1'|/               Reflexive                              
            +------------+         Address                                
            |    NAT     |                                                
            +------------+                                                
                  |                                                       
                  | /------------  Local                                  
              X:x |/               Address                                
              +--------+                                                  
              |        |                                                  
              | Agent  |                                                  
              |        |                                                  
              +--------+                                                  

]]></artwork></figure>

<t> When the agent sends the TURN
Allocate Request from IP address and port X:x, the NAT (assuming there
is one) will create a 
binding X1':x1', mapping this server reflexive candidate to the host
candidate X:x. Outgoing packets sent from the host candidate will
be translated by the NAT to the server reflexive candidate.
Incoming packets sent to the server reflexive candidate will
be translated by the NAT to the host candidate and forwarded
to the agent. We call the host candidate associated with a
given server reflexive candidate the BASE.
</t>

<t><list style="empty">
<t>NOTE: "Base" refers to the address an agent sends from for a particular
candidate. Thus, as a degenerate case host candidates also have a base,
but it's the same as the host candidate. 
</t></list></t>

<t>
When there are multiple NATs between the agent and the TURN server,
the TURN request will create a binding on each NAT, but only the
outermost server reflexive candidate (the one nearest the TURN server)
will be discovered by the agent. If the agent is not behind a NAT,
then the base candidate will be the same as the server reflexive
candidate and the server reflexive candidate is redundant and will be
eliminated.
</t>

<t>
The Allocate request then arrives at the TURN server. The TURN server
allocates a port y from its local IP address Y, and generates an
Allocate response, informing the agent of this relayed candidate. The
TURN server also informs the agent of the server reflexive candidate,
X1':x1' by copying the source transport address of the Allocate
request into the Allocate response. The TURN server acts as a packet
relay, forwarding traffic between L and R. In order to send traffic to
L, R sends traffic to the TURN server at Y:y, and the TURN server forwards
that to X1':x1', which passes through the NAT where it is mapped to
X:x and delivered to L.
</t>

<t>
When only STUN servers are utilized, the agent sends a STUN Binding
Request <xref target="I-D.ietf-behave-rfc3489bis"/> to its STUN
server. The STUN server will inform the agent of the server reflexive
candidate X1':x1' by copying the source transport address of the
Binding request into the Binding response. 
</t>

</section>

<section title="Connectivity Checks">
<t>
Once L has gathered all of its candidates, it orders them in highest
to lowest priority and sends them to R over the signalling
channel. The candidates are carried in attributes in the SDP offer.
When R receives the offer, it performs the same gathering process and
responds with its own list of candidates. At the end of this process,
each agent has a complete list of both its candidates and its peer's
candidates. It pairs them up, resulting in CANDIDATE PAIRS. To see
which pairs work, each agent schedules a series of CHECKS. Each check
is a STUN request/response transaction that the client will perform on
a particular candidate pair by sending a STUN request from the local
candidate to the remote candidate.
</t>

<t>
The basic principle of the connectivity checks is simple:
<list style="numbers">
<t>Sort the candidate pairs in priority order.</t>
<t>Send checks on each candidate pair in priority order.</t>
<t>Acknowledge checks received from the other agent.</t>
</list>
With both agents performing a check on a candidate pair, the result is
a 4-way handshake:
</t>

<figure title="Basic Connectivity Check" 
anchor="fig:connectivity-checks"><artwork>
<![CDATA[
L                        R
-                        -
STUN request ->             \  L's 
          <- STUN response  /  check

           <- STUN request  \  R's
STUN response ->            /  check
]]></artwork></figure>  

<t>
It is important to note that the STUN requests are sent to and from
the exact same IP addresses and ports that will be used for media
(e.g., RTP and RTCP). Consequently, agents demultiplex STUN and
RTP/RTCP using contents of the packets, rather than the port on which
they are received. Fortunately, this demultiplexing is easy to do,
especially for RTP and RTCP.
</t>

<t>
Because a STUN Binding Request is used for the connectivity check, the
STUN Binding response will contain the agent's translated transport address on
the public side any NATs between the agent and its peer. If this
transport address is different from other candidates the agent already
learned, it represents a new candidate, called a PEER REFLEXIVE
CANDIDATE, which then gets tested by ICE just the same as any other
candidate.  
</t>

<t>
As an optimization, as soon as R gets L's check message, R schedules a
connectivity check message to be sent to L on the same candidate
pair. This accelerates the process of finding a valid candidate, and
is called a TRIGGERED CHECK.
</t>

<t>
At the end of this handshake, both L and R know that they can
send (and receive) messages end-to-end in both directions.
</t>

</section>


<section title="Sorting Candidates">

<t>
Because the algorithm above searches all candidate pairs, if
a working pair exists it will eventually find it no matter
what order the candidates are tried in. In order to produce
faster (and better) results, the candidates are sorted in 
a specified order. The resulting list of sorted candidate pairs is
called the CHECK LIST. The algorithm is described in <xref
target="sec-prioritizing"/>
but follows two general principles:
<list style="symbols">
<t>Each agent gives its candidates a numeric priority which is sent
along with the candidate to the peer</t> 
<t>The local and remote priorities are combined so that each 
agent has the same ordering for the candidate pairs.</t>
</list>
</t>

<t>
The second property is important for getting ICE to work when there
are NATs in front of L and R. Frequently, NATs will not allow packets
in from a host until the agent behind the NAT has sent a packet
towards that host. Consequently, ICE checks in each direction will not
succeed until both sides have sent a check through their respective
NATs. 
</t>

<t>
The agent works through this check list by sending a STUN request for
the next candidate pair on the list periodically. These are called ORDINARY
CHECKS. 
</t>

<t>
In general the priority algorithm is designed so that candidates of
similar type get similar priorities and so that more direct routes
(that is, through fewer media relays and through fewer NATs) are
preferred over indirect ones (ones with more media relays and more
NATs).  Within those guidelines, however, agents have a fair amount of
discretion about how to tune their algorithms.
</t>

</section>

<section title="Frozen Candidates">

<t>
The previous description only addresses the case where the agents wish
to establish a media session with one COMPONENT (a piece of a media
stream requiring a single transport address; a media stream may
require multiple components, each of which has to work for the media
stream as a whole to be work). Typically, (e.g., with RTP and RTCP) the
agents actually need to establish connectivity for more than one flow.
</t>

<t>
The network properties are likely to be very similar for each
component (especially because RTP and RTCP are sent and received 
from the same IP address). It is usually possible to leverage
information from one media component in order to determine the best
candidates for another. ICE does this with a mechanism called "frozen
candidates."
</t>

<t>
Each candidate is associated with a property called its
FOUNDATION. Two candidates have the same foundation when they are
"similar" - of the same type and obtained from the same host candidate and
STUN server using the same protocol. Otherwise, their foundation is
different. A candidate pair has a foundation too, which is just the
concatenation of the foundations of its two candidates. Initially,
only the candidate pairs with unique foundations are tested.  The
other candidate pairs are marked "frozen". When the connectivity
checks for a candidate pair succeed, the other candidate pairs with
the same foundation are unfrozen. This avoids repeated checking of
components which are superficially more attractive but in fact are
likely to fail.
</t>

<t>
While we've described "frozen" here as a separate
mechanism for expository purposes, in fact it is an integral
part of ICE and the the ICE prioritization algorithm
automatically ensures that the right candidates are unfrozen and 
checked in the right order.
</t>

</section>

<section title="Security for Checks">

<t>
Because ICE is used to discover which addresses can be used to send
media between two agents, it is important to ensure that the process
cannot be hijacked to send media to the wrong location. Each STUN
connectivity check is covered by a message authentication code (MAC)
computed using a key exchanged in the signalling channel. This MAC
provides message integrity and data origin authentication, thus
stopping an attacker from forging or modifying connectivity check
messages. Furthermore, if the SIP <xref target="RFC3261"/> caller is
using ICE, and their call forks, the ICE exchanges happen
independently with each forked recipient. In such a case, the keys
exchanged in the signaling help associate each ICE exchange with each
forked recipient.

</t>

</section>

<section title="Concluding ICE">

<t>
ICE checks are performed in a specific sequence, so that high priority
candidate pairs are checked first, followed by lower priority
ones. One way to conclude ICE is to declare victory as soon as a check
for each component of each media stream completes
successfully. Indeed, this is a reasonable algorithm, and details for
it are provided below. However, it is possible that a packet loss will
cause a higher priority check to take longer to complete.  In that
case, allowing ICE to run a little longer might produce better
results. More fundamentally, however, the prioritization defined by
this specification may not yield "optimal" results. As an example, if
the aim is to select low latency media paths, usage of a relay is a
hint that latencies may be higher, but it is nothing more than a
hint. An actual RTT measurement could be made, and it might
demonstrate that a pair with lower priority is actually better than
one with higher priority.
</t>

<t>
Consequently, ICE assigns one of the agents in the role of the
CONTROLLING AGENT, and the other of the CONTROLLED AGENT. The
controlling agent gets to nominate which candidate pairs will get used for
media amongst the ones that are valid. It can do this in one of two
ways - using REGULAR NOMINATION or AGGRESSIVE NOMINATION.
</t>

<t>
With regular nomination, the controlling agent lets the checks continue
until at least one valid candidate pair for each media stream is
found. Then, it picks amongst those that are valid, and sends a second
STUN request on its NOMINATED candidate pair, but this time with a
flag set to tell the peer that this pair has been nominated for use. 
This is shown in <xref target="fig-regular-select"/>.
</t>

<figure title="Regular Nomination" 
anchor="fig-regular-select"><artwork>
<![CDATA[
L                        R
-                        -
STUN request ->             \  L's 
          <- STUN response  /  check

           <- STUN request  \  R's
STUN response ->            /  check

STUN request + flag ->      \  L's 
          <- STUN response  /  check

]]></artwork></figure>  

<t>
Once the STUN transaction with the flag completes, both sides cancel
any future checks for that media stream. ICE will now send media using
this pair. The pair an ICE agent is using for media is called the
SELECTED PAIR.
</t>

<t>
In aggressive nomination, the controlling agent puts the flag in every
STUN request it sends. This way, once the first check succeeds, ICE
processing is complete for that media stream and the controlling agent
doesn't have to send a second STUN request. The selected pair will be
the highest priority valid pair whose check succeeded. Aggressive
nomination is faster than regular nomination, but gives less
flexibility. Aggressive nomination is shown in <xref
target="fig-aggressive-select"/>.
</t>

<figure title="Aggressive Nomination" 
anchor="fig-aggressive-select"><artwork>
<![CDATA[
L                        R
-                        -
STUN request + flag ->      \  L's 
          <- STUN response  /  check

           <- STUN request  \  R's
STUN response ->            /  check

]]></artwork></figure>  


<t>Once all of the media streams are
completed, the controlling endpoint sends an updated offer if the
candidates in the m and c lines for the media stream (called the
DEFAULT CANDIDATES) don't match ICE's SELECTED CANDIDATES.
</t>

<t>
Once ICE is concluded, it can be restarted at any time for one or all
of the media streams by either agent. This is done by sending an updated
offer indicating a restart.
</t>

</section>

<section title="Lite Implementations">

<t>
In order for ICE to be used in a call, both agents need to support it.
However, certain agents will always be connected to the public
Internet and have a public IP address at which it can receive packets
from any correspondent. To make it easier for these devices to support
ICE, ICE defines a special type of implementation called LITE (in
contrast to the normal FULL implementation). A lite implementation
doesn't gather candidates; it includes only host candidates for any
media stream.  Lite agents do not generate connectivity checks or run
the state machines, though they need to be able to respond to
connectivity checks. When a lite implementation connects with a full
implementation, the full agent takes the role of the controlling
agent, and the lite agent takes on the controlled role. When two lite
implementations connect, no checks are sent.
</t>

<t>For guidance on when a
lite implementation is appropriate, see the discussion in <xref
target="sec-liteandfull"/>. 
</t>

<t>
It is important to note that the lite implementation was
added to this specification to provide a stepping stone to full
implementation. Even for devices 
that are always connected to the public Internet, a full
implementation is preferable if achievable.
</t>

</section>

</section>

<section title="Terminology">

<t> The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in
this document are to be interpreted as described in <xref
target="RFC2119">RFC 2119</xref>.  </t>

<t>
Readers should be familiar with the terminology defined in the
offer/answer model <xref target="RFC3264"/>, STUN <xref
target="I-D.ietf-behave-rfc3489bis"/> and NAT Behavioral requirements
for UDP <xref target="RFC4787"/>
</t>

<t>
This specification makes use of the following additional terminology:
</t>

<t><list style="hanging">

<t hangText="Agent:">As defined in RFC 3264, an agent is the protocol
implementation involved in the offer/answer exchange.  There are two
agents involved in an offer/answer exchange.  </t>

<t hangText="Peer:">From the perspective of one of the agents in a
session, its peer is the other agent. Specifically, from the
perspective of the offerer, the peer is the answerer. From the
perspective of the answerer, the peer is the offerer. </t>

<t hangText="Transport Address:"> The
combination of an IP address and transport protocol (such as UDP or
TCP) port.</t> 

<t hangText="Candidate:"> A transport address that is a potential
point of contact for receipt of media. Candidates also have properties
- their type (server reflexive, relayed or host), priority,
foundation, and base.
</t>

<t hangText="Component:"> A component is a piece of a media
stream requiring a single transport address; a media stream may
require multiple components, each of which has to work for the media
stream as a whole to work. For media streams based on
RTP, there are two components per media stream - one for RTP, and one
for RTCP. 
</t>

<t hangText="Host Candidate:"> A candidate obtained by binding to a
specific port from an IP address on the host. This includes IP
addresses on physical interfaces and logical ones, such as ones
obtained through Virtual Private Networks (VPNs) and Realm Specific IP
(RSIP) <xref target="RFC3102"/> (which lives at the operating system
level).
</t>

<t hangText="Server Reflexive Candidate:"> A candidate whose IP
address and port are a binding allocated by a NAT for an agent when it
sent a packet through the NAT to a server. Server reflexive candidates
can be learned by STUN servers using the Binding Request, or TURN
servers, which provides both a Relayed and Server Reflexive candidate.
</t>

<t hangText="Peer Reflexive Candidate:"> A candidate whose IP
address and port are a binding allocated by a NAT for an agent when it
sent a STUN Binding Request through the NAT to its peer.
</t>

<t hangText="Relayed Candidate:"> A candidate obtained by sending a
TURN Allocate request from a host candidate to a TURN server. The
relayed candidate is resident on the TURN server, and the TURN server
relays packets back towards the agent.
</t>

<t hangText="Base:"> The base of a server reflexive candidate is the
host candidate from which it was derived. A host candidate is also
said to have a base, equal to that candidate itself. Similarly, the
base of a relayed candidate is that candidate itself.
</t>

<t hangText="Foundation:"> An arbitrary string that is the same for
two candidates that have the same type, base IP address, protocol
(UDP, TCP, etc.) and STUN or TURN
server.  If any of these are different then the foundation will be
different. Two candidate pairs with the same foundation pairs are
likely to have similar network characteristics.  Foundations are used
in the frozen algorithm.
</t>

<t hangText="Local Candidate:">A candidate that an agent has obtained
and included in an offer or answer it sent.
</t>

<t hangText="Remote Candidate:">A candidate that an agent received in
an offer or answer from its peer.
</t>

<t hangText="Default Destination/Candidate:"> The default destination
for a component of a media stream is the transport address that would
be used by an agent that is not ICE aware. For the RTP component, the
default IP address is in the c line of the SDP, and the port in the m
line. For the RTCP component it is in the rtcp attribute when
present, and when not present, the IP address in the c line and 1
plus the port in the m line. A default candidate for a component is
one whose transport address matches the default destination for that
component.
</t>

<t hangText="Candidate Pair:"> A pairing containing a local candidate
and a remote candidate. 
</t>

<t hangText="Check, Connectivity Check, STUN Check:"> A STUN Binding
Request transaction for the purposes of verifying connectivity. A
check is sent from the local candidate to the remote candidate of a
candidate pair.
</t>

<t hangText="Check List:"> An ordered set of candidate pairs that an agent
will use to generate checks.
</t>

<t hangText="Ordinary Check:"> A connectivity check generated by an
agent as a consequence of a timer that fires periodically, instructing
it to send a check.
</t>

<t hangText="Triggered Check:"> A connectivity check generated as a
consequence of the receipt of a connectivity check from the peer.
</t>

<t hangText="Valid List:"> An ordered set of candidate pairs for a
media stream that have been validated by a successful STUN
transaction. 
</t>

<t hangText="Full:"> An ICE implementation that performs the complete
set of functionality defined by this specification.
</t>

<t hangText="Lite:"> An ICE implementation that omits certain
functions, implementing only as much as is necessary for a peer
implementation that is full to gain the benefits of ICE. Lite
implementations do not maintain any of the state machines and do not
generate connectivity checks.
</t>

<t hangText="Controlling Agent:"> The ICE agent which is responsible
for selecting the final choice of candidate pairs and signaling them
through STUN and an updated offer, if needed. In any session, one
agent is always controlling. The other is the controlled agent.
</t>

<t hangText="Controlled Agent:"> An ICE agent which waits for the
controlling agent to select the final choice of candidate pairs. 
</t>

<t hangText="Regular Nomination:"> The process of picking a valid
candidate pair for media traffic by validating the pair with one
STUN request, and then picking it by sending a second STUN request
with a flag indicating its nomination. 
</t>

<t hangText="Aggressive Nomination:"> The process of picking a valid
candidate pair for media traffic by including a flag in every STUN
request, such that the first one to produce a valid candidate pair is
used for media. 
</t>

<t hangText="Nominated:"> If a valid candidate pair has its nominated flag
set, it means that it may be selected by ICE for sending and receiving
media. 
</t>

<t hangText="Selected Pair, Selected Candidate:"> The candidate pair
selected by ICE for sending and receiving media is called the selected
pair, and each of its candidates is called the selected candidate. 
</t>

</list></t>

</section>


<section title="Sending the Initial Offer">

<t>
In order to send the initial offer in an offer/answer exchange, an
agent must (1) gather candidates, (2) prioritize them, (3) choose default
candidates, and then (4) formulate and send the
SDP offer. All but the last of these four steps differ for full and lite
implementations.  
</t>

<section title="Full Implementation Requirements">


<section anchor="sec-gathering" title="Gathering Candidates">

<t>
An agent gathers candidates when it believes that communications is
imminent. An offerer can do this based on a user interface cue, or
based on an explicit request to initiate a session. Every candidate is
a transport address. It also has a type and a base. Four types are
defined and gathered by this specification - host candidates, server
reflexive candidates, peer reflexive candidates, and relayed
candidates. The server reflexive and relayed candidates are gathered
using STUN or TURN, and relayed candidates are obtained through
TURN. Peer reflexive candidates are obtained in later phases of ICE,
as a consequence of connectivity checks. The base of a candidate is
the candidate that an agent must send from when using that candidate.
</t>

<section title="Host Candidates">

<t> The first step is to gather host candidates. Host candidates are
obtained by binding to ports (typically ephemeral) on a IP address
attached to an interface (physical or virtual, including VPN
interfaces) on the host. 
</t>

<t>For each UDP media stream the agent wishes to use, the agent SHOULD
obtain a candidate for each component of the media stream on each
IP address that the host has. It obtains each candidate by binding to a
UDP port on the specific IP address. A host candidate (and indeed every
candidate) is always associated with a specific component for which it
is a candidate. Each component has an ID assigned to it, called the
component ID. For RTP-based media streams, the RTP itself has a
component ID of 1, and RTCP a component ID of 2. If an agent is using
RTCP it MUST obtain a candidate for it. If an agent is using both RTP
and RTCP, it would end up with 2*K host candidates if an agent has K
IP addresses.
</t>

<t>
The base for each host candidate is set to the candidate itself.
</t>

</section>

<section title="Server Reflexive and Relayed Candidates">

<t>
Agents SHOULD obtain relayed candidates and SHOULD obtain server
reflexive candidates. These requirements are at SHOULD strength to
allow for provider variation. Use of STUN and TURN servers may be unnecessary
in closed networks where agents are never connected to the public
Internet or to endpoints outside of the closed network. In such cases,
a full implementation would be used for agents that are dual-stack or
multi-homed, to select a host candidate. Use of TURN servers is expensive,
and when ICE is being used, they will only be utilized when both
endpoints are behind NATs that perform address and port dependent
mapping. Consequently, some deployments might consider this use case
to be marginal, and elect not to use TURN servers. If an agent does not
gather server reflexive or relayed candidates, it is RECOMMENDED that
the functionality be implemented and just disabled through
configuration, so that it can re-enabled through configuration if
conditions change in the future.
</t>

<t>
If an agent is gathering both relayed and server reflexive candidates,
it uses a TURN server. If it is gathering just server reflexive
candidates, it uses a STUN server. 
</t>

<t>
The agent next pairs each host candidate with the STUN or TURN server with
which it is configured or has discovered by some means. If a STUN or
TURN server is configured, it is RECOMMENDED that a domain name be
configured, and the DNS procedures in
<xref target="I-D.ietf-behave-rfc3489bis"/> (using SRV records with
the "stun" service) be used to discover the STUN server, and the DNS
procedures in <xref target="I-D.ietf-behave-turn"/> (using SRV records
with the "turn" service) be used to discover the TURN server. 
</t>

<t>This specification only considers usage of a single STUN or TURN
server. When there are multiple choices for that single STUN or TURN
server (when, for example, they are learned through DNS records and
multiple results are returned), an agent SHOULD use a single STUN or
TURN server (based on its IP address) for all candidates for a
particular session. This improves the performance of ICE. The result
is a set of pairs of host candidates with STUN or TURN servers. The
agent then chooses one pair, and sends a Binding or Allocate request
to the server from that host candidate. Binding Requests to a STUN
server are not authenticated, and any ALTERNATE-SERVER attribute in a
response is ignored. Agents MUST support the backwards compatibility
mode for the Binding Request defined in
<xref target="I-D.ietf-behave-rfc3489bis"/>. Allocate requests SHOULD
be authenticated using a long-term credential obtained by the client
through some other means.
</t>

<t>
Every Ta milliseconds thereafter, the agent can generate another new
STUN or TURN transaction. This transaction can either be a retry of a previous
transaction which failed with a recoverable error (such as
authentication failure), or a transaction for a new host candidate and STUN
or TURN server pair. The agent SHOULD NOT generate transactions more
frequently than one every Ta milliseconds. See <xref target="sec-ta"/>
for guidance on how to set Ta and the STUN retransmit timer, RTO.
</t>

<t>The agent will receive a Binding or Allocate response. A
successful Allocate Response will provide the agent with a server reflexive
candidate (obtained from the mapped address) and a relayed candidate
in the RELAY-ADDRESS attribute. If the Allocate request is rejected
because the server lacks resources to fulfill it, the agent SHOULD
instead send a Binding Request to obtain a server reflexive
candidate. A Binding Response will provide the
agent with only a server reflexive candidate (also obtained from the
mapped address). The base of the server reflexive candidate is the
host candidate from which the Allocate or Binding request was
sent. The base of a relayed candidate is that candidate itself. If a relayed
candidate is identical to a host candidate (which can happen in rare
cases), the relayed candidate MUST be discarded. 
</t>

</section>

<section title="Computing Foundations">

<t>
Finally, the agent assigns each candidate a foundation. The foundation
is an identifier, scoped within a session. Two candidates MUST have
the same foundation ID when all of the following are true:
</t>

<t><list style="symbols">

<t> they are of the same type (host, relayed,
server reflexive, or peer reflexive)</t>

<t>their bases have the
same IP address (the ports can be different)</t>

<t>for reflexive and relayed candidates, the STUN or TURN servers used to
obtain them have the same IP address.
</t>

<t>they were obtained using the same transport protocol (TCP, UDP,
  etc.) 
</t>

</list></t>

<t> Similarly, two candidates MUST have different foundations
if their types are different, their bases have different IP
addresses, the STUN or TURN servers used to obtain them have different IP
addresses, or their transport protocols are different.
</t>

</section>

<section title="Keeping Candidates Alive">

<t>
Once server reflexive and relayed candidates are allocated, they MUST
be kept alive until ICE processing has completed, as described in
<xref target="sec-freeing"/>. For server reflexive candidates learned
through a Binding request, the bindings MUST be kept alive by additional
Binding Requests to the server. For relayed candidates learned through
an Allocate request, the keepalive MUST be new Allocate requests. The
Allocate requests will also refresh the server reflexive candidate.
</t>

</section>

<!-- end gathering -->
</section>

<section anchor="sec-prioritizing" title="Prioritizing Candidates">

<t>
The prioritization process results in the assignment of a priority to
each candidate. Each candidate for a media stream MUST have a unique
priority that MUST be a positive integer between 1 and (2**31 - 1). 
This priority will be used by ICE to determine the order of
the connectivity checks and the relative preference for
candidates. 
</t>

<t>
An agent SHOULD compute this priority using the formula in <xref
target="sec-rec-form"/> and choose its parameters using the guidelines
in <xref target="sec-guidelines"/>.
If an agent elects to use a
different formula, ICE will take longer to converge since both
agents will not be coordinated in their checks.
</t>

<section anchor="sec-rec-form" title="Recommended Formula">

<t>When using the formula, an agent computes the priority by
determining a preference for each type of candidate (server reflexive,
peer reflexive, relayed and host), and, when the agent is multihomed,
choosing a preference for its IP addresses. These two preferences are
then combined to compute the priority for a candidate. That priority
is computed using the following formula:
</t>

<figure><artwork>
<![CDATA[
priority = (2^24)*(type preference) +
           (2^8)*(local preference) +
           (2^0)*(256 - component ID) 

]]></artwork></figure>

<t>
The type preference MUST be an integer from 0 to 126 inclusive, and
represents the preference for the type of the candidate (where the
types are local, server reflexive, peer reflexive and relayed). A 126 is
the highest preference, and a 0 is the lowest. Setting the value to a
0 means that candidates of this type will only be used as a last
resort. The type preference MUST be identical for all candidates of
the same type and MUST be different for candidates of different
types. The type preference for peer reflexive candidates MUST be higher
than that of server reflexive candidates. Note that candidates
gathered based on the procedures of <xref target="sec-gathering"/>
will never be peer reflexive candidates; candidates of these type are
learned from the connectivity checks performed by ICE. 
</t>

<t>The local preference MUST be an integer
from 0 to 65535 inclusive. It represents a preference for the
particular IP address from which the candidate was obtained, in cases
where an agent is multihomed. 65535 represents the highest preference,
and a zero, the 
lowest. When there is only a single IP address, this value SHOULD be
set to 65535. More generally, if there are multiple candidates for
a particular component for a particular media stream which have the
same type, the local preference MUST be unique for each one. In this
specification, this only happens for multi-homed hosts. If a host is
multi-homed because it is dual stacked, the local preference SHOULD be
set equal to the precedence value
for IP addresses described in RFC 3484 <xref target="RFC3484"/>.
</t>


<t>The
component ID is the component ID for the candidate, and MUST be
between 1 and 256 inclusive.
</t>


</section>

<section anchor="sec-guidelines" title="Guidelines for Choosing Type
					and Local Preferences"> 

<t> One criteria for selection of the type and local preference values
is the use of a media intermediary, such as a TURN server, VPN server or
NAT. With a media intermediary, if media is sent to that candidate, it will
first transit the media intermediary before being received. Relayed
candidates are one type of candidate that involves a
media intermediary. Another are host candidates obtained from a VPN
interface. When media is transited through a media intermediary, it can
increase the latency between transmission and reception. It can
increase the packet losses, because of the additional router hops that
may be taken. It may increase the cost of providing service, since
media will be routed in and right back out of a media intermediary run by a
provider. If these concerns are important, the type preference for
relayed candidates SHOULD be lower than host candidates. The
RECOMMENDED values are 126 for host candidates, 100 for server
reflexive candidates, 110 for peer reflexive candidates, and 0 for
relayed candidates. Furthermore, if an agent is multi-homed and has
multiple IP addresses, the local preference for host candidates from a
VPN interface SHOULD have a priority of 0. </t>

<t>
Another criteria for selection of preferences is IP address
family. ICE works with both IPv4 and IPv6. It therefore provides a
transition mechanism that allows dual-stack hosts to prefer
connectivity over IPv6, but to fall back to IPv4 in case the v6
networks are disconnected (due, for example, to a failure in a 6to4
relay) <xref target="RFC3056"/>. It can also help with hosts that have
both a native IPv6 address and a 6to4 address. In such a case, higher
local preferences could be assigned to the v6 addresses, followed by
the 6to4 addresses, followed by the v4 addresses. This allows a site
to obtain and begin using native v6 addresses immediately, yet still
fallback to 6to4 addresses when communicating with agents in other
sites that do not yet have native v6 connectivity.
</t>

<t>
Another criteria for selecting preferences is security. If
a user is a telecommuter, and therefore connected to their corporate
network and a local home network, they may prefer their voice traffic
to be routed over the VPN in order to keep it on the corporate network
when communicating within the enterprise, but use the local network
when communicating with users outside of the enterprise. In such a
case, a VPN address would have a higher local preference than any
other address.
</t>

<t>
Another criteria for selecting preferences is topological
awareness. This is most useful for candidates that make use
of intermediaries. In those cases, if an agent has
preconfigured or dynamically discovered knowledge of the topological
proximity of the intermediaries to itself, it can use that to assign higher
local preferences to candidates obtained from closer intermediaries. 
</t>

</section>

<!-- end prioritization -->

</section>

<section anchor="sec-el-red" title="Eliminating Redundant Candidates">

<t>
Next, the agent eliminates redundant candidates. A candidate
is redundant if its transport address equals another candidate, and
its base equals the base of that other candidate. Note that two
candidates can have the same transport address yet have different
bases, and these would not be considered redundant. Frequently, a
server reflexive candidate and a host candidate will be redundant when
the agent is not behind a NAT. The agent SHOULD eliminate the
redundant candididate with the lower priority. 
</t>


</section>



<section anchor="sec-inuse" title="Choosing Default Candidates">

<t>
A candidate is said to be default if it would be the target of media
from a non-ICE peer; that target being called the DEFAULT
DESTINATION. If the default candidates are not selected by the ICE
algorithm when communicating with an ICE-aware peer, an updated
offer/answer will be required after ICE processing completes in order
to "fix-up" the SDP so that the default destination for media matches
the candidates selected by ICE. If ICE happens to select the default
candidates, no updated offer/answer is required.
</t>

<t>An agent MUST choose a set of candidates, one for each component of
each in-use media stream, to be default. A media stream is in-use if it
does not have a port of zero (which is used in RFC 3264 to reject a media
stream). Consequently, a media stream is in-use even if it is marked
as a=inactive <xref target="RFC4566"/> or has a bandwidth value of
zero.
</t>

<t>It is RECOMMENDED that default candidates be chosen based on the
likelihood of those candidates to work with the peer that is being
contacted. It is RECOMMENDED that the default candidates are the
relayed candidates (if relayed candidates are available), server
reflexive candidates (if server reflexive candidates are available),
and finally host candidates.
</t>

</section>

<!-- end full implementation -->
</section> 

<section anchor="sec-offer-lite" title="Lite Implementation">

<t>
Lite implementations only utilize host candidates. A lite
implementation MUST, for each component of each media stream, allocate
zero or one IPv4 candidates. It MAY allocate zero or more IPv6
candidates, but no more than one per each IPv6 address utilized by the
host. Since there can be no more than one IPv4 candidate per component
of each media stream, if an agent has multiple IPv4 addresses, it
MUST choose one for allocating the candidate. If a host is dual-stack,
it is RECOMMENDED that it allocate one IPv4 candidate and one global
IPv6 address. With the lite implementation, ICE cannot be used 
to dynamically choose amongst candidates. Therefore, including
more than one candidate from a particular scope is NOT RECOMMENDED,
since only a connectivity check can truly determine whether to use one
address or the other.
</t>

<t>Each component has an ID assigned to it, called the component
ID. For RTP-based media streams the RTP itself has a component ID of
1, and RTCP a component ID of 2. If an agent is using RTCP it MUST
obtain candidates for it.
</t>

<t>
Each candidate is assigned a foundation. The foundation MUST be
different for two candidates allocated from different IP addresses,
and MUST be the same otherwise. A simple integer that increments for
each IP address will suffice. In addition, each candidate MUST be
assigned a unique priority amongst all candidates for the same media
stream. This priority SHOULD be equal to:
</t>

<figure><artwork>
<![CDATA[
priority = (2^24)*(126) +
           (2^8)*(IP precedence) +
           (2^0)*(256 - component ID) 

]]></artwork></figure>

<t>
If a host is v4-only, it SHOULD set the IP precedence to 65535. If a
host is v6 or dual-stack, the IP precedence SHOULD be the precedence value
for IP addresses described in RFC 3484 <xref target="RFC3484"/>.
</t>

<t>
Next, an agent chooses a default candidate for each component of each
media stream. If a host is IPv4 only, there would only be one
candidate for each component of each media stream, and therefore that
candidate is the default. If a host is IPv6 or dual stack, the
selection of default is a matter of local policy. This default SHOULD
be chosen, such that, it is the candidate most likely to be used with
a peer. For IPv6-only hosts, this would typically by a globally scoped
IPv6 address. For dual-stack hosts, the IPv4 address is RECOMMENDED. 
</t>

</section>


<section anchor="sec-encoding" title="Encoding the SDP">

<t>
The process of encoding the SDP is identical between full and
lite implementations.
</t>

<t>
The agent will include an m-line for each media stream it wishes to
use. The ordering of media streams in the SDP is relevant for ICE. ICE
will perform its connectivity checks for the first m-line first, and
consequently media will be able to flow for that stream first. Agents
SHOULD place their most important media stream, if there is one, first
in the SDP.
</t>

<t>
There will be a candidate attribute for each candidate for a
particular media stream. <xref target="sec-grammar"/> provides
detailed rules for constructing this attribute. The attribute carries
the IP address, port and transport protocol for the candidate, in
addition to its properties that need to be signaled to the peer for
ICE to work: the priority, foundation, and component ID. The candidate
attribute also carries information about the candidate that is useful
for diagnostics and other functions: its type and related transport
addresses. 
</t>

<t>
STUN connectivity checks between agents are authenticated using the
short term credential mechanism defined for STUN
<xref target="I-D.ietf-behave-rfc3489bis"/>. This mechanism relies on
a username and password that are exchanged through protocol machinery
between the client and server. With ICE, the offer/answer exchange is
used to exchange them. The username
part of this credential is formed by concatenating a username fragment
from each agent, separated by a colon. Each agent also provides a
password, used to compute the message integrity for requests it
receives. The username fragment and password are exchanged in the
ice-ufrag and ice-pwd attributes, respectively. In addition to
providing security, the username provides disambiguation and
correlation of checks to media streams. See <xref
target="sec-why-uname"/> for motivation.
</t>


<t>
If an agent is a lite implementation, it MUST include an
"a=ice-lite" session level attribute in its SDP. If an agent is
a full implementation, it MUST NOT include this attribute.
</t>

<t>
The default candidates are added to the SDP as the default destination
for media.  For streams based on RTP, this is done by placing the IP
address and port of the RTP candidate into the c and m lines,
respectively.  If the agent is utilizing RTCP, it MUST encode the RTCP
candidate using the a=rtcp attribute as defined in RFC 3605 <xref
target="RFC3605"/>. If RTCP is not in use, the agent MUST signal that
using b=RS:0 and b=RR:0 as defined in RFC 3556 <xref
target="RFC3556"/>. 
</t>

<t>
The transport addresses that will be the default destination for media
when communicating with non-ICE peers MUST also be present as
candidates in one or more a=candidate lines.  
</t>

<t>
ICE provides for extensibility by allowing an offer or answer to
contain a series of tokens which identify the ICE extensions used by
that agent. If an agent supports an ICE extension, it MUST include the
token defined for that extension in the ice-options attribute.
</t>

<t>
The following is an example SDP message that includes ICE attributes
(lines folded for readability):
</t>

<figure><artwork>
<![CDATA[
    v=0
    o=jdoe 2890844526 2890842807 IN IP4 10.0.1.1
    s=
    c=IN IP4 192.0.2.3
    t=0 0
    a=ice-pwd:asd88fgpdd777uzjYhagZg
    a=ice-ufrag:8hhY
    m=audio 45664 RTP/AVP 0
    b=RS:0
    b=RR:0
    a=rtpmap:0 PCMU/8000
    a=candidate:1 1 UDP 2130706431 10.0.1.1 8998 typ host
    a=candidate:2 1 UDP 1694498815 192.0.2.3 45664 typ srflx raddr
10.0.1.1 rport 8998
]]></artwork></figure>

<t>
Once an agent has sent its offer or sent its answer, that agent MUST
be prepared to receive both STUN and media packets on
each candidate. As discussed in <xref target="sec-send-media"/>, media
packets can be sent to a candidate prior to its appearance as the
default destination for media in an offer or answer.
</t>

</section>

</section>

<section title="Receiving the Initial Offer">

<t>
When an agent receives an initial offer, it will check if the offerer
supports ICE, determine its own role, gather candidates, prioritize
them, choose default candidates, encode and send an answer, and for
full implementations, form the check lists and begin connectivity
checks.
</t>

<section anchor="sec-verify" title="Verifying ICE Support">

<t>
The agent will proceed with the ICE procedures defined in this
specification if, for each media stream in the SDP it received, the
default destination for each component of that media stream appears in
a candidate attribute. For example, in the case of RTP, the IP address
and port in the c and m line, respectively, appears in a candidate
attribute and the value in the rtcp attribute appears in a candidate
attribute.
</t>

<t>
If this condition is not met, the agent MUST process the
SDP based on normal RFC 3264 procedures, without using any of the ICE
mechanisms described in the remainder of this specification with the
following exceptions:
</t>

<t><list style="numbers">
<t> The agent MUST follow the rules of
<xref target="sec-keepalives"/>, which describe keepalive procedures
for all agents.
</t>

<t>If the agent is not proceeding with ICE
because there were a=candidate attributes, but none that matched the
default destination of the media stream, the agent MUST include an
a=ice-mismatch attribute in its answer.
</t>

<t>
If the default candidates were relayed candidates learned through a
TURN server, the agent MUST create permissions in the TURN server for
the IP addresses learned from its peer in the SDP it just received. If
this is not done, initial packets in the media stream from the peer
may be lost. 
</t>

</list></t>

</section>

<section anchor="sec-role" title="Determining Role">

<t>
For each session, each agent takes on a role. There are two roles -
controlling, and controlled. The controlling agent is responsible for
the choice of the final candidate pairs used for communications. For a
full agent, this means nominating the candidate pairs that can be used
by ICE for each media stream, and for generating the updated offer
based on ICE's selection, when needed. For a lite implementation,
being the controlling agent means selecting a candidate pair based on
the ones in the offer and answer (for IPv4, there is only ever one
pair), and then generating an updated offer reflecting that selection,
when needed (it is never needed for an IPv4 only host). The controlled
agent is told which candidate pairs to use for each media stream, and
does not generate an updated offer to signal this information. The
sections below describe in detail the actual procedures following by
controlling and controlled nodes.
</t>

<t>
The rules for determining the role and the impact on behavior are as
follows:
</t>

<t><list style="hanging">
<t hangText="Both agents are full:"> The agent which generated the
offer which started the ICE processing MUST take the controlling role,
and the other MUST take the controlled role. Both agents will form
check lists, run the ICE state machines, and generate connectivity
checks. The controlling agent will execute the logic in <xref
target="sec-conclude-full"/> to nominate pairs that will be selected
by ICE, and then both agents end ICE as described in <xref
target="sec-conc-state"/>. In unusual cases, described in <xref
target="sec-glare"/>, it is possible for both agents to mistakenly
believe they are controlled or controlling. To resolve this, each
agent MUST select a random number, called the tie-breaker, uniformly
distributed between 0 and (2**64) - 1 (that is, a 64 bit positive
integer). This number is used in connectivity checks to detect and repair this
case, as described in <xref target="sec-tie-client"/>.
</t>

<t hangText="One agent Full, one Lite:"> The full agent MUST take the
controlling role, and the lite agent MUST take the controlled
role. The full agent will form
check lists, run the ICE state machines, and generate connectivity
checks. That agent will execute the logic in <xref
target="sec-conclude-full"/> to nominate pairs that will be selected
by ICE, and use the logic in <xref
target="sec-conc-state"/> to end ICE. The lite implementation will
just listen for connectivity checks, receive them and respond to them,
and then conclude ICE as described in <xref
target="sec-lite-conclude"/>. For the lite implementation, the state
of ICE processing for each media stream is considered to be Running,
and the state of ICE overall is Running.
</t>

<t hangText="Both Lite:"> The agent which generated the offer which
started the ICE processing MUST take the controlling role, and the
other MUST take the controlled role. In this case, no connectivity
checks are ever sent. Rather, once the offer/answer exchange
completes, each agent performs the processing described in <xref
target="sec-conclude"/> without connectivity checks. It is possible
that both agents will believe they are controlled or controlling. In
the latter case, the conflict is resolved through glare detection
capabilities in the signaling protocol carrying the offer/answer
exchange. The state of ICE processing for each media stream is
considered to be Running, and the state of ICE overall is Running.
</t>

</list></t>

<t>
Once roles are determined for a session,
they persist unless ICE is restarted. A ICE restart
(<xref target="sec-suboffer"/>) causes a new selection of roles and
tie-breakers.
</t>

</section>

<section title="Gathering Candidates">

<t>
The process for gathering candidates at the answerer is identical to
the process for the offerer as described in <xref
target="sec-gathering"/> for full implementations and <xref
target="sec-offer-lite"/> for lite implementations. It is RECOMMENDED
that this process begin immediately on receipt of the offer, prior to
alerting the user. Such gathering MAY begin when an agent starts.
</t>

</section>

<section title="Prioritizing Candidates">

<t>
The process for prioritizing candidates at the answerer is identical
to the process followed by the offerer, as described in <xref
target="sec-prioritizing"/> for full implementations and <xref
target="sec-offer-lite"/> for lite implementations.
</t>

</section>

<section title="Choosing Default Candidates">

<t>
The process for selecting default candidates at the answerer is
identical to the process followed by the offerer, as described in
<xref target="sec-inuse"/> for full implementations and <xref
target="sec-offer-lite"/> for lite implementations.
</t>

</section>

<section title="Encoding the SDP">

<t>
The process for encoding the SDP at the answerer is identical to the
process followed by the offerer for both full and lite
implementations, as described in <xref target="sec-encoding"/>.
</t>

</section>

<section anchor="sec-forming" title="Forming the Check Lists">

<t>
Forming check lists is done only by full implementations. Lite
implementations MUST skip the steps defined in this section.
</t>

<t>
There is one check list per in-use media stream resulting from the
offer/answer exchange. 
To form the check list for a media stream, the agent forms
candidate pairs, computes a candidate pair priority, orders the pairs
by priority, prunes them, and sets their states. These steps are
described in this section.
</t>

<section title="Forming Candidate Pairs">

<t>
First, the agent takes each of its candidates for a media stream
(called LOCAL CANDIDATES) and pairs them with the candidates it
received from its peer (called REMOTE CANDIDATES) for that media
stream. In order to prevent the attacks described in <xref
target="sec-ice-hammer"/>, agents MAY limit the number of candidates
they'll accept in an offer or answer. A local candidate is paired
with a remote candidate if and only if the two candidates have the
same component ID and have the same IP address version. It is possible
that some of the local candidates don't get paired with a remote
candidate, and some of the remote candidates don't get paired with
local candidates. This can happen if one agent didn't include
candidates for the all of the components for a media stream. If this
happens, the 
number of components for that media stream is effectively reduced, and
considered to be equal to the minimum across both agents of the
maximum component ID provided by each agent across all components for
the media stream.
</t>

<t>In the case of RTP, this would happen when one agent provided
candidates for RTCP, and the other did not. As another example, the
offerer can multiplex RTP and RTCP on the same port and signals it can
do that in the SDP through an SDP attribute <xref
target="I-D.ietf-avt-rtp-and-rtcp-mux"/>. However, since the offerer
doesn't know if the answerer can perform such multiplexing, the
offerer includes candidates for RTP and RTCP on separate ports, so
that the offer has two components per media stream. If the
answerer can perform such multiplexing, it would include just a single
component for each candidate - for the combined RTP/RTCP mux. ICE
would end up acting as if there was just a single component for this
candidate. 
</t>


<t>
The candidate pairs whose local and remote candidates were both the
default candidates for a particular component is called,
unsurprisingly, the default candidate pair for that component. This is
the pair that would be used to transmit media if both agents had not
been ICE aware. 
</t>

<t>
In order to aid understanding, <xref target="fig-check-model"/> shows
the relationships between several key concepts - transport addresses,
candidates, candidate pairs, and check lists, in addition to
indicating the main properties of candidates and candidate pairs.
</t>

<figure title="Conceptual Diagram of a Check List"
	anchor="fig-check-model"><artwork> 
<![CDATA[
    +------------------------------------------+                          
    |                                          |                          
    | +---------------------+                  |                          
    | |+----+ +----+ +----+ |   +Type          |                          
    | || IP | |Port| |Tran| |   +Priority      |                          
    | ||Addr| |    | |    | |   +Foundation    |                          
    | |+----+ +----+ +----+ |   +ComponentiD   |                          
    | |      Transport      |   +RelatedAddr   |                          
    | |        Addr         |                  |                          
    | +---------------------+   +Base          |                          
    |             Candidate                    |                          
    +------------------------------------------+                          
    *                                         *                           
    *    *************************************                            
    *    *                                                                
  +-------------------------------+                                       
 .|                               |                                       
  | Local     Remote              |                                       
  | +----+    +----+   +default?  |                                       
  | |Cand|    |Cand|   +valid?    |                                       
  | +----+    +----+   +nominated?|                                       
  |                    +State     |                                       
  |                               |                                       
  |                               |                                       
  |          Candidate Pair       |                                       
  +-------------------------------+                                       
  *                              *                                        
  *                  ************                                         
  *                  *                                                    
  +------------------+                                                    
  |  Candidate Pair  |                                                    
  +------------------+                                                    
  +------------------+                                                    
  |  Candidate Pair  |                                                    
  +------------------+                                                    
  +------------------+                                                    
  |  Candidate Pair  |                                                    
  +------------------+                                                    
                                                                          
                                                                          
         Check                                                            
         List                                                             

]]></artwork></figure>


</section>

<section anchor="sec-comp-pair-prio" title="Computing Pair Priority
					    and Ordering Pairs"> 

<t>
Once the pairs are formed, a candidate pair priority is
computed. Let G be the priority for the candidate provided
by the controlling agent. Let D be the priority for the candidate
provided by the controlled agent. The priority for a
pair is computed as:
</t>

<t><list style="empty">
<t>
pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0)
</t>
</list></t>

<t>
Where G>D?1:0 is an expression whose value is 1 if G is greater than
D, and 0 otherwise. Once the priority is assigned, the agent sorts the
candidate pairs in decreasing order of priority. If two pairs have
identical priority, the ordering amongst them is arbitrary.
</t>

</section>

<section title="Pruning the Pairs">

<t>
This sorted list of candidate pairs is used to determine a sequence of
connectivity checks that will be performed. Each check involves
sending a request from a local candidate to a remote candidate. Since
an agent cannot send requests directly from a reflexive candidate, but
only from its base, the agent next goes through the sorted list of
candidate pairs. For each pair where the local candidate is server
reflexive, the server reflexive candidate MUST be replaced by its
base. Once this has been done, the agent MUST prune the list. This is
done by removing a pair if its local and remote candidates are
identical to the local and remote candidates of a pair higher up on
the priority list. The result is a sequence of ordered candidate
pairs, called the check list for that media stream.
</t>

<t>
In addition, in order to limit the attacks described in
<xref target="sec-ice-hammer"/>, an agent MUST limit the total number
of connectivity checks they perform across all check lists to a
specific value, adn this value MUST be configurable. A default of 100
is RECOMMENDED. This limit is enforced by discarding the lower
priority candidate pairs until there are less than 100. It is
RECOMMENDED that a lower value be utilized when possible, set to the
maximum number of plausible checks that might be seen in an actual
deployment configuration. The requirement for configuration is meant
to provided a tool for fixing this value in the field if, once
deployed, it is found to be problematic.
</t>

</section>

<section title="Computing States">

<t>
Each candidate pair in the check list has a foundation and a state. The
foundation is the combination of the foundations of the local and
remote candidates in the pair. The state is assigned once the check
list for each media stream has been computed. There
are five potential values that the state can have:
</t>

<t><list style="hanging">
<t hangText="Waiting:"> A check has not been performed for this pair, and can be
performed as soon as it is the highest priority Waiting pair on the check
list.
</t>

<t hangText="In-Progress:"> A check has been sent for this pair, but
the transaction is in progress.
</t>

<t hangText="Succeeded:"> A check for this pair was already done and
produced a successful result.
</t>

<t hangText="Failed:"> A check for this pair was already done and
failed, either
never producing any response or producing an unrecoverable failure
response. 
</t>

<t hangText="Frozen:"> A check for this pair hasn't been performed, and it can't
yet be performed until some other check succeeds, allowing this pair
to unfreeze and move into the Waiting state.
</t>
</list></t>

<t>
As ICE runs, the pairs will move between states as shown in <xref
target="fig-state-fsm"/>. 
</t>

<figure title="Pair State FSM" anchor="fig-state-fsm"><artwork>
<![CDATA[
   +-----------+                                                          
   |           |                                                          
   |           |                                                          
   |  Frozen   |                                                          
   |           |                                                          
   |           |                                                          
   +-----------+                                                          
         |                                                                
         |unfreeze                                                        
         |                                                                
         V                                                                
   +-----------+         +-----------+                                    
   |           |         |           |                                    
   |           | perform |           |                                    
   |  Waiting  |-------->|In-Progress|                                    
   |           |         |           |                                    
   |           |         |           |                                    
   +-----------+         +-----------+                                    
                               / |                                        
                             //  |                                        
                           //    |                                        
                         //      |                                        
                        /        |                                        
                      //         |                                        
            failure //           |success                                 
                  //             |                                        
                 /               |                                        
               //                |                                        
             //                  |                                        
           //                    |                                        
          V                      V                                        
   +-----------+         +-----------+                                    
   |           |         |           |                                    
   |           |         |           |                                    
   |   Failed  |         | Succeeded |                                    
   |           |         |           |                                    
   |           |         |           |                                    
   +-----------+         +-----------+                                    
]]></artwork></figure>

<t>
The initial states for each pair in a check list are computed by
performing the following sequence of steps:
</t>

<t><list style="numbers">

<t>The agent sets all of the pairs in each check list to the Frozen
state.
</t>

<t>The agent examines the check list for the first media stream (a
media stream is the first media stream when it is 
described by the first m-line in the SDP offer and answer). For that
media stream:
<list style="symbols">
<t>For all pairs with the same foundation, it sets the state of the
pair with the lowest component ID to Waiting. If there is more than
one such pair, the one with the highest priority is used.
</t>
</list></t>

</list></t>

<t>One of
the check lists will have some number of pairs in the Waiting state,
and the other check lists will have all of their pairs in the Frozen
state. A check list with at least one pair that is Waiting is
called an active check list, and a check list with all pairs frozen is
called a frozen check list.
</t>

<t>
The check list itself is associated with a state, which
captures the state of ICE checks for that media stream. There are
three states:</t>

<t><list style="hanging">

<t hangText="Running:"> In this state, ICE checks are still in
progress for this media stream. 
</t>

<t hangText="Completed:"> In this state, ICE checks have produced
nominated pairs for each component of the media stream. Consequently,
ICE has succeeded and media can be sent.
</t>

<t hangText="Failed:"> In this state, the ICE checks have not
completed successfully for this media stream. 
</t>

</list></t>

<t>
When a check list is first constructed as the consequence of an
offer/answer exchange, it is placed in the Running state.
</t>

<t>
ICE processing across all media streams also has a state associated
with it. This state is equal to Running while ICE processing is
underway. The state is Completed when ICE processing is complete and
Failed if it failed without success.
Rules for transitioning between states are described below.
</t>

</section>

</section>

<section anchor="sec-periodic" title="Scheduling Checks">

<t>
Checks are generated only by full implementations. Lite
implementations MUST skip the steps described in this section.
</t>

<t>
An agent performs ordinary checks and triggered checks. The generation
of both checks is governed by a timer which fires periodically for
each media stream. The agent maintains a FIFO queue, called the
triggered check queue, which contains candidate pairs for which checks
are to be sent at
the next available opportunity. When the timer fires, the agent
removes the top pair from triggered check queue, performs a
connectivity check on that pair, and
sets the state of the candidate pair to In-Progress. If
there are no 
pairs in the triggered check queue, an ordinary check is
sent. 
</t>

<t>
Once the agent has computed the check lists as described in <xref
target="sec-forming"/>, it sets a timer for each active check
list. The timer fires every Ta*N seconds, where N is the number of
active check lists (initially, there is only one active check
list). Implementations MAY set the timer to fire less frequently than
this. Implementations SHOULD take care to spread out these timers so
that they do not fire at the same time for each media stream. Ta and
the retransmit timer RTO are computed as described in
<xref target="sec-ta"/>. Multiplying by N allows this
aggregate check throughput to be split between all active check
lists. The first timer fires immediately,
so that the agent performs a connectivity check the moment the
offer/answer exchange has been done, followed by the next check Ta
seconds later (since there is only one active check list). 
</t>


<t>
When the timer fires, and there is no triggered check to be sent, the
agent MUST choose an ordinary check as follows: 

<list style="symbols">
<t>Find the highest priority pair in that check list that is in the
Waiting state. 
</t>

<t>If there is such a pair:
<list style="symbols">
<t>Send a STUN check from the local candidate of
that pair to the remote candidate of that pair. The procedures for
forming the STUN request for this purpose are described in <xref
target="sec-send-check"/>. 
</t>
<t>Set the state of the candidate pair to In-Progress.
</t>

</list></t>

<t>If there is no such pair:
<list style="symbols">
<t>Find the highest priority pair in that check list that is in the
Frozen state.
</t>

<t>If there is such a pair:
<list style="symbols">
<t>Unfreeze the pair.</t>
<t>Perform a check for that pair, causing its state to transition to
In-Progress.
</t>
</list></t>

<t>If there is no such pair:
<list style="symbols">
<t>Terminate the timer for that check list.</t>
</list></t>
</list></t></list></t>


<t>
To compute the message integrity for the check, the agent uses the
remote username fragment and password learned from the SDP from its
peer. The local username fragment is known directly by the agent for
its own candidate.
</t>

</section>

</section>

<section title="Receipt of the Initial Answer">

<t>
This section describes the procedures that an agent follows when it
receives the answer from the peer. It verifies that its peer supports
ICE, determines its role, and for full implementations, forms the
check list and begins performing ordinary checks.
</t>

<t>
When ICE is used with SIP, forking may result in a single offer
generating a multiplicity of answers. In that each, ICE proceeds
completely in parallel and independently for each answer, treating the
combination of its offer and each answer as an independent
offer/answer exchange, with its own set of pairs, check lists, states,
and so on. The only case in which processing of one pair impacts
another is freeing of candidates, discussed below in <xref
target="sec-freeing"/>.
</t>

<section anchor="sec-overify" title="Verifying ICE Support">

<t>
The logic at the offerer is identical to that of the answerer as
described in <xref target="sec-verify"/>, with the exception that an
offerer would not ever generate a=ice-mismatch attributes in an SDP. 
</t>

<t>
In some cases, the answer may omit a=candidate attributes for the
media streams, and instead include an a=ice-mismatch attribute for one
or more of the media streams in the SDP. This signals to the offerer
that the answerer supports ICE, but that ICE processing was not used
for the session because a signaling intermediary modified the default
destination for media components without modifying the corresponding
candidate attributes. See <xref target="sec-security"/> for a
discussion of cases where this can happen. This specification provides
no guidance on how an agent should proceed in such a failure case.
</t>

</section>

<section title="Determining Role">

<t>
The offerer follows the same procedures described for the answerer in
<xref target="sec-role"/>.
</t>

</section>

<section title="Forming the Check List">

<t>
Formation of check lists is performed only by full
implementations. The offerer follows the same procedures described for
the answerer in 
<xref target="sec-forming"/>.
</t>

</section>

<section title="Performing Ordinary Checks">

<t>Ordinary checks are performed only by full implementations. The
offerer follows the same procedures described for the answerer 
in <xref target="sec-periodic"/>.
</t>

</section>

</section>

<section anchor="sec-connectivity_check" title="Performing
						Connectivity Checks"> 

<t>
This section describes how connectivity checks are
performed. All ICE implementations are required to be compliant to
<xref target="I-D.ietf-behave-rfc3489bis"/>, as opposed to the older
<xref target="RFC3489"/>. However, whereas a full implementation will
both generate checks (acting as a STUN client) and receive them
(acting as a STUN server), a lite implementation will only ever
receive checks, and thus will only act as a STUN server. 
</t>

<section anchor="sec-client" title="STUN Client Procedures">

<t>
These procedures define how an agent sends a connectivity check,
whether it is an ordinary or a triggered check. These procedures are
only applicable to full implementations.
</t>

<section anchor="sec-send-check" title="Sending the Request">

<t>
The check is generated by sending a Binding Request from a local
candidate, to a remote candidate. <xref
target="I-D.ietf-behave-rfc3489bis"/> describes how Binding Requests are
constructed and generated. A connectivity check MUST utilize the STUN
short term credential mechanism. Support for backwards compatibility
with RFC 3489 MUST NOT be used or assumed with connectivity
checks. The FINGERPRINT mechanism MUST be used for connectivity
checks. 
</t>

<t>
ICE extends STUN by defining several new attributes, including
PRIORITY, USE-CANDIDATE, ICE-CONTROLLED, and ICE-CONTROLLING. These
new attributes are formally defined in
<xref target="sec-ice-newatts"/>, and their usage is 
described in the subsections below. These STUN extensions are
applicable only to connectivity checks used for ICE.
</t>

<section title="PRIORITY and USE-CANDIDATE">

<t>
An agent MUST include the PRIORITY attribute in its Binding
Request. The attribute
MUST be set equal to the priority that would 
be assigned, based on the algorithm in <xref
target="sec-prioritizing"/>, to a peer reflexive candidate, should one
be learned as a consequence of this check (see <xref
target="sec-learn-peer-client"/> for how peer reflexive candidates are
learned). This priority value will be computed identically to how the
priority for the local candidate of the pair was computed, except that
the type preference is set to the value for peer reflexive candidate
types. 
</t>

<t>
The controlling agent MAY include the USE-CANDIDATE attribute in the
Binding Request. The controlled agent MUST NOT include it in its Binding
Request. This attribute signals that the controlling agent wishes to
cease checks for this component, and use the candidate pair resulting
from the check for this component. <xref target="sec-choose-favor"/> provides
guidance on determining when to include it.
</t>

</section>

<section anchor="sec-tie-client" title="ICE-CONTROLLED and ICE-CONTROLLING">

<t>
The agent MUST include the ICE-CONTROLLED attribute in the request if
it is in the controlled role, and MUST include the ICE-CONTROLLING
attribute in the request if it is in the controlling role. The content
of either attribute MUST be the tie breaker that was determined in
<xref target="sec-role"/>. These attributes are defined fully in <xref
target="sec-ice-newatts"/>.
</t>

</section>

<section title="Forming Credentials">

<t>
A Binding Request serving as a connectivity check MUST utilize the
STUN short term credential mechanism. The username for the credential
is formed by concatenating the username fragment provided by the peer
with the username fragment of the agent sending the request, separated
by a colon (":"). The password is equal to the password provided by
the peer. For example, consider the case where agent L is the offerer,
and agent R is the answerer. Agent L included a username fragment of
LFRAG for its candidates, and a password of LPASS. Agent R provided a
username fragment of RFRAG and a password of RPASS. A connectivity
check from L to R (and its response of course) utilize the username
RFRAG:LFRAG and a password of RPASS. A connectivity check from R to L
(and its response) utilize the username LFRAG:RFRAG and a password of
LPASS.
</t>

</section>

<section title="DiffServ Treatment">

<t>
If the agent is using Diffserv Codepoint markings <xref
target="RFC2475"/> in its media packets, it SHOULD apply those same
markings to its connectivity checks.
</t>

</section>


</section>

<section anchor="sec-recv-response" title="Processing the Response">

<t>
When a Binding Response is received, it is correlated to its Binding
Request using the transaction ID, as defined in <xref
target="I-D.ietf-behave-rfc3489bis"/>, which then ties it to the
candidate pair for which the Binding Request was sent. This section
defines additional procedures for processing Binding Responses,
specific to this usage of STUN.
</t>

<section title="Failure Cases">

<t>
If the STUN transaction generates a 487 (Role Conflict) error
response, the agent checks whether it had included the ICE-CONTROLLED
or ICE-CONTROLLING attribute in the Binding Request. If the request
had contained the ICE-CONTROLLED attribute, the agent MUST switch to
the controlling role if it has not already done so. If the request had
contained the ICE-CONTROLLING attribute, the agent MUST switch to the
controlled role if it has not already done so. Once it has switched,
the agent MUST enqueue the candidate pair whose check generated the
487 into the triggered check queue. The state of that pair is set to
Waiting. When the triggered check is sent, it will contain an
ICE-CONTROLLING or ICE-CONTROLLED attribute reflecting its 
new role. Note, however, that the tie-breaker value MUST NOT be
reselected.
</t>

<t>
Agents MAY support receipt of ICMP errors for connectivity
checks. If the STUN transaction generates an ICMP error, the agent
sets the state of the pair to Failed.  If the STUN transaction
generates a STUN error response that is unrecoverable (as defined in
<xref target="I-D.ietf-behave-rfc3489bis"/>), or times out, the agent
sets the state of the pair to Failed.
</t>

<t>
The agent MUST check that the source IP address and port of the
response equals the destination IP address and port that the Binding
Request was sent to, and that the destination IP address and port of
the response match the source IP address and port that the Binding
Request was sent from.  In other words, the source and destination
transport addresses in the request and responses are the symmetric. If
they are not symmetric, the agent sets the state of the pair to Failed.  
</t>

</section>

<section title="Success Cases">

<t>A check is considered to be a success if all of the following are
true:
<list style="symbols">
<t>the STUN transaction generated a success response</t>
<t>the source IP address and port of the response equals the
destination IP address and port that the Binding Request was sent
to</t>
<t>the destination IP address and port of
the response match the source IP address and port that the Binding
Request was sent from</t>
</list></t>

<section anchor="sec-learn-peer-client" title="Discovering Peer
					       Reflexive Candidates"> 

<t>
The agent checks the mapped address from the STUN response. If the
transport address does not match any of the local candidates that the
agent knows about, the mapped address represents a new candidate - a
peer reflexive candidate. Like other candidates, it has a type, base,
priority and foundation. They are computed as follows:
</t>

<t><list style="symbols">
<t>Its type is equal to peer reflexive.</t>
<t>Its base is set equal to the local candidate of the candidate pair
from which the STUN check was sent.</t>
<t>Its priority is set equal to the value of the PRIORITY attribute in
the Binding Request.</t>
<t>Its foundation is selected as
described in <xref target="sec-gathering"/>.</t>
</list></t>

<t>
This peer reflexive candidate is then added to the list of local
candidates for the media stream. Its username fragment and password
are the same as all other local candidates for that media
stream. However, the peer reflexive candidate is not paired with other
remote candidates. This is not necessary; a valid pair will
be generated from it momentarily based on the procedures in <xref
target="sec-valid-cons"/>. If an agent wishes to pair the peer
reflexive candidate with other remote candidates besides the one in
the valid pair that will be generated, the agent MAY generate an
updated offer which includes the peer reflexive candidate. This will
cause it to be paired with all other remote candidates. 
</t>

</section>

<section anchor="sec-valid-cons" title="Constructing a Valid Pair">

<t>
The agent constructs a
candidate pair whose local candidate 
equals the mapped address of the response, and whose remote candidate
equals the destination address to which the request was sent. This is
called a valid pair, since it has been validated by a STUN
connectivity check. The valid pair may equal the pair that generated the
check, may equal a different pair in the check list, or may be a pair
not currently on any check list. If the pair equals the pair that
generated the check or is on a check list currently, it is also added
to the VALID LIST, which is maintained by the
agent for each media stream. This list is empty at the start of ICE
processing, and fills as checks are performed, resulting in valid
candidate pairs. 
</t>

<t>
It will be very common that the pair will not be on any check list. 
Recall that the check list has pairs whose local candidates are never
server reflexive; those pairs had their local candidates converted to
the base of the server reflexive candidates, and then pruned if they
were redundant. When the response to the STUN check arrives, the
mapped address will be reflexive if there is a NAT between the two. In
that case, the valid pair will have a local candidate that doesn't
match any of the pairs in the check list. 
</t>

<t>
If the pair is not on any check list, the agent computes the priority
for the pair based on the priority of each candidate, using the
algorithm in <xref target="sec-forming"/>. The priority of the local
candidate depends on its type. If it is not peer reflexive, it is
equal to the priority signaled for that candidate in the SDP. If it is
peer reflexive, it is equal to the PRIORITY attribute the agent placed
in the Binding Request which just completed. The priority of the
remote candidate is taken from the SDP of the peer. If the candidate
does not appear there, then the check must have been a triggered check
to a new remote candidate. In that case, the priority is taken as the
value of the PRIORITY attribute in the Binding Request which triggered
the check that just completed. The pair is then added to the VALID
LIST.
</t>

</section>


<section title="Updating Pair States">

<t>
The agent sets the state of the pair that generated the check to
Succeeded. The success of this check might also cause the state of
other checks to change as well. The agent MUST perform the following
two steps:
</t>

<t><list style="numbers">
<t>The agent changes the states for all other Frozen pairs for the
same media stream and same foundation to Waiting. Typically these other pairs
will have different component IDs but not always. </t>

<t>If there is a pair in the valid list for every component of this
media stream (where this is the actual number of components being
used, in cases where the number of components signaled in the SDP
differs from offerer to answerer), the success of this check may
unfreeze checks for other media streams. Note that this step is
followed not just the first time the valid list under consideration
has a pair for every component, but every subsequent time a check
succeeds and adds yet another pair to that valid list. The agent
examines the check list for each other media stream in turn:
<list style="symbols">
<t>If the check list is active, the agent changes the state of all
Frozen pairs in that check list whose foundation matches a pair in the
valid list under consideration, to Waiting. </t>
<t>If the check list is frozen, and there is at least one pair in the
check list whose foundation matches a pair in the valid list under
consideration, the state of all pairs in the check list whose
foundation matches a pair in the valid list under consideration are set
to Waiting. This will cause the check list to become active, and
ordinary checks will begin for it, as described in <xref
target="sec-periodic"/>.</t>
<t>If the check list is frozen, and there are no pairs in the check
list whose foundation matches a pair in the valid list under
consideration, the agent 
<list style="symbols">
<t>Groups together all of the pairs with the same foundation,</t>
<t>For each group, sets the state of the pair with the lowest
component ID to Waiting. If there is more than one such pair, the one
with the highest priority is used. 
</t>
</list>
</t>
</list>
</t>
</list></t>

</section>


<section title="Updating the Nominated Flag">

<t>
If the agent was a controlling agent, and it had included a
USE-CANDIDATE attribute in the Binding Request, the valid pair
generated from that check has its nominated flag set to true. This flag
indicates that this valid pair should be used for media if it is the
highest priority one amongst those whose nominated flag is set. This
may conclude ICE 
processing for this media stream or all media streams; see <xref
target="sec-conclude"/>.
</t>

<t>
If the agent is the controlled agent, the response may be the result
of a triggered check which was sent in response to a request which itself had
the USE-CANDIDATE attribute. This case is described in
<xref target="sec-up-fav"/>, and may now result in setting the
nominated flag for the pair learned from the original request. 
</t>

<!-- if we ever pair this peer reflexive candidate with other
candidates we'll need to come up with a way for both sides to obtain
the same foundation -->

</section>


<!-- end success cases -->
</section>

<section title="Check List and Timer State Updates">

<t>
Regardless of whether the check was successful or failed, the
completion of the transaction may require updating of check list and
timer states.
</t>

<t>
If all of the pairs in the check
list are now either in the Failed or Succeeded state:
<list style="symbols">
<t>If there is not a
pair in the valid list for each component of the media stream, the
state of the check list is set to Failed. </t>
<t>For each frozen check list,
the agent:
<list style="symbols">
<t>Groups together all of the pairs with the same foundation,</t>
<t>For each group, sets the state of the pair with the lowest
component ID to Waiting. If there is more than one such pair, the one
with the highest priority is used. 
</t>
</list>
</t>
</list></t>

<t>
If none of the pairs in the check list are in the Waiting or Frozen
state, the check list is no longer considered active, and will not
count towards the value of N in the computation of timers for ordinary
checks as described in <xref target="sec-periodic"/>.
</t>

</section>

<!-- end processing response -->
</section>

<!-- end client procedures -->
</section>

<section anchor="sec-serverproc" title="STUN Server Procedures">

<t>
An agent MUST be prepared to receive a Binding Request on the base of
each candidate it included in its most recent offer or answer. This
requirement holds even if the peer is a lite implementation. 
</t>

<t>
The agent MUST use a short term credential to authenticate the request
and perform a message integrity check. The agent MUST consider the
username to be valid if it consists of two values separated by a
colon, where the first value is equal to the username fragment
generated by the agent in an offer or answer for a session
in-progress. It is possible (and in fact very likely) that an offerer
will receive a Binding Request prior to receiving the answer from its
peer. If this happens, the agent MUST immediately generate a response
(including computation of the mapped address as described in
<xref target="sec-compute-mapped"/>. The agent has sufficient
information at this point to generate the response; the password from
the peer is not required. Once the answer is received, it MUST proceed
with the remaining steps required, namely
<xref target="sec-learn-peer-server"/>,
<xref target="sec-triggered"/>, and <xref target="sec-up-fav"/> for
full implementations. In cases where multiple STUN requests are
received before the answer, this may cause several pairs to be queued
up in the triggered check queue.
</t>

<t>
An agent MUST NOT utilize the ALTERNATE-SERVER mechanism, and MUST NOT
support the backwards compatibility mechanisms to RFC 3489. It MUST
utilize the FINGERPRINT mechanism.
</t>

<t>
If the agent is using Diffserv Codepoint markings <xref
target="RFC2475"/> in its media packets, it SHOULD apply those same
markings to its responses to Binding Requests. The same would apply to
any layer 2 markings the endpoint might be applying to media packets.
</t>

<section anchor="sec-add-server-full" title="Additional Procedures for
					     Full Implementations"> 

<t>This subsection defines the additional server procedures applicable
to full implementations.
</t>

<section title="Detecting and Repairing Role Conflicts">

<t>
Normally, the rules for selection of a role in <xref
target="sec-role"/> will result in each agent selecting a different
role - one controlling, and one controlled. However, in unusual call
flows, typically utilizing third party call control, it is possible
for both agents to select the same role. This section describes
procedures for checking for this case and repairing it.
</t>

<t>
An agent MUST examine the Binding Request for either the
ICE-CONTROLLING or ICE-CONTROLLED attribute. It MUST follow these
procedures:
<list style="symbols">
<t>If neither ICE-CONTROLLING or ICE-CONTROLLED are present in the
request, the peer agent may have implemented a previous version of
this specification. There may be a conflict, but it cannot be
detected. </t> 

<t>If the agent is in the controlling role, and the ICE-CONTROLLING
attribute is present in the request:
<list style="symbols">
<t>If the agent's tie-breaker is larger than or equal to the contents
of the ICE-CONTROLLING attribute, the agent generates a Binding
Error Response and includes an ERROR-CODE attribute with a value of 487
(Role Conflict) but retains its role.
</t>
<t>If the agent's tie-breaker is less than the contents of the
ICE-CONTROLLING attribute, the agent switches to the controlled
role.
</t>
</list>
</t>

<t>If the agent is in the controlled role, and the ICE-CONTROLLED
attribute is present in the request:
<list style="symbols">
<t>If the agent's tie-breaker is larger than or equal to the contents
of the ICE-CONTROLLED attribute, the agent switches to the
controlling role.
</t>
<t>If the agent's tie-breaker is less than the contents of the
ICE-CONTROLLED attribute, the agent generates a Binding Error
Response and includes an ERROR-CODE attribute with a value of 487 (Role
Conflict) but retains its role.
</t>
</list></t>

<t>If the agent is in the controlled role and the ICE-CONTROLLING
attribute was present in the request, or the agent was in the
controlling role and the ICE-CONTROLLED attribute was present in the
request, there is no conflict.
</t>

</list></t>

<t>
A change in roles will require an agent to recompute pair priorities
<xref target="sec-comp-pair-prio"/>, since those priorities are a
function of controlling and controlled role. The change in role will
also impact whether the agent is responsible for selecting nominated
pairs and generated updated offers upon conclusion of ICE.
</t>

<t>
The remaining sections in <xref target="sec-add-server-full"/> are
followed if the server generated a successful response to the Binding
Request, even if the agent changed roles.
</t>

</section>

<section anchor="sec-compute-mapped" title="Computing Mapped Address">

<t>
For requests being received on a relayed candidate, the source
transport address used for STUN processing (namely, generation of the
XOR-MAPPED-ADDRESS attribute) is the transport address as seen by the
TURN server. That source transport address will be present in the
REMOTE-ADDRESS attribute of a Data Indication message, if the
Binding Request was delivered through a Data Indication (a TURN server
delivers packets encapsulated in a Data Indication when no active
destination is set). If the Binding Request was not encapsulated in a
Data Indication, that source address is equal to the current active
destination for the TURN session.
</t>

</section>

<section anchor="sec-learn-peer-server" title="Learning Peer Reflexive
					       Candidates"> 

<t>
If the source transport address of the
request does not match any existing remote candidates, it represents a
new peer reflexive remote candidate. This candidate is constructed as
follows: 
<list style="symbols">
<t>The priority of the candidate is set to the PRIORITY attribute from the
request.</t>
<t>The type of the candidate is set to peer reflexive. </t>
<t>The foundation of the candidate is set to an arbitrary value,
different from the foundation for all other remote candidates. If any
subsequent offer/answer exchanges contain this peer reflexive
candidate in the SDP, it will signal the actual foundation for the
candidate.</t>
<t>The component ID of this candidate is set to the component ID for
the local candidate to which the request was sent.
</t>
</list>
</t>

<t>This
candidate is added to the list of remote candidates. However, the
agent does not pair this candidate with any local candidates.
</t>

</section>

<section anchor="sec-triggered" title="Triggered Checks">

<t>
Next, the agent constructs a pair whose local candidate is equal to
the transport address on which the STUN request was received, and a
remote candidate equal to the source transport address where the
request came from (which may be peer-reflexive remote candidate that
was just learned). Since both candidates are known to the agent, it
can obtain their priorities and compute the candidate pair
priority. This pair is then looked up in the check list. There can be
one of several outcomes:
</t>

<t><list style="symbols">
<t>If the pair is already on the check list:
<list style="symbols">
<t>If the state of that pair
is Waiting or Frozen, a check for that pair is enqueued into the
triggered check queue if not already present.  
</t>

<t>If the state of that pair is In-Progress, the agent cancels the
in-progress transaction. Cancellation means that the agent will not
retransmit the request, will not treat the lack of response to be a
failure, but will wait the duration of the transaction
timeout for a response. In addition, the agent MUST create a new
connectivity check for that pair (representing a new STUN Binding
Request transaction) by enqueueing the pair in the triggered check queue. The
state of the pair is then changed to Waiting.
</t>

<t>
If the state of the pair is Failed, it is changed to Waiting and the
agent MUST create a new connectivity check for that pair (representing
a new STUN Binding Request transaction), by enqueueing the pair in the
triggered check queue.
</t>

<t>If the state of that pair is Succeeded, nothing further is done.
</t>
</list>
</t>

<t>These steps are done to facilitate rapid completion of ICE when
both agents are behind NAT.
</t>


<t>If the pair is not already on the check list:
<list style="symbols">
<t>The pair is inserted into the check list based on its priority</t>
<t>Its state is set to Waiting</t>
<t>The pair is enqueued into the triggered check queue. </t>
</list>
</t>
</list>
</t>

<t>
When a triggered check is to be sent, it is constructed and processed as
described in <xref target="sec-send-check"/>. These procedures require
the agent to know the transport address, username fragment and
password for the peer. The username fragment for the remote candidate
is equal to the part after the colon of the USERNAME in the Binding
Request that was just received. Using that username fragment, the
agent can check the SDP messages received from its peer (there may be
more than one in cases of forking), and find this username
fragment. The corresponding password is then selected. 
</t>

<!-- end triggered checks -->
</section>

<section anchor="sec-up-fav" title="Updating the Nominated Flag">

<t>
If the Binding Request received by the agent had the USE-CANDIDATE
attribute set, and the agent is in the controlled role, the agent
looks at the state of the pair computed in <xref
target="sec-triggered"/>:
<list style="symbols">
<t>If the state of this pair is Succeeded, it
means that the check generated by this pair produced a successful
response. This would have caused the agent to construct a valid pair
when that success response was received (see <xref
target="sec-valid-cons"/>). The agent now sets the nominated flag in
the valid pair to true. This may end ICE processing for this media
stream; see <xref target="sec-conclude"/>. 
</t>
<t>If the state of this pair is In-Progress, if its check produces a
successful result, the resulting valid pair has its nominated flag set
when the response arrives. This may end ICE processing for this media
stream when it 
arrives; see <xref target="sec-conclude"/>. 
</t>
</list>
</t>

</section>

<!-- end full implementation requirements -->
</section>

<section title="Additional Procedures for Lite Implementations">

<t>
If the check that was just received contained a USE-CANDIDATE
attribute, the agent constructs a candidate pair whose local candidate
is equal to the transport address on which the request was received,
and whose remote candidate is equal to the source transport address of
the request that was received. This candidate pair is assigned an
arbitrary priority, and placed into a list of valid candidates called
the valid list. The agent sets the nominated flag for that pair to
true. ICE processing is 
considered complete for a media stream if the valid list contains a
candidate pair for each component.
</t>

</section>


<!-- end server procedures -->
</section>


<!-- end connectivity checks -->
</section>

<section anchor="sec-conclude" title="Concluding ICE Processing">

<t>This section describes how an agent completes ICE.
</t>

<section anchor="sec-conclude-full" title="Procedures for Full
					   Implementations"> 

<t>
Concluding ICE involves nominating pairs
by the controlling agent and updating of state machinery.
</t>

<section anchor="sec-choose-favor" title="Nominating Pairs">

<t>
The controlling agent nominates pairs to be selected by ICE by using
one of two techniques: regular nomination or aggressive nomination. If
its peer has a lite 
implementation, an agent MUST use a regular nomination algorithm. If
its peer is using ICE options (present in an ice-options attribute
from the peer) that the agent does not understand, the agent MUST use
a regular nomination algorithm. If its peer is a full implementation
and isn't using any ICE options or is using ICE options understood by
the agent, the agent MAY use either the aggressive or the regular
nomination algorithm. However, the regular algorithm is RECOMMENDED
since it provides greater stability.
</t>

<section title="Regular Nomination">

<t>
With regular nomination, the agent lets some number of checks complete,
each of which omit the USE-CANDIDATE attribute. Once one or
more checks complete successfully for a component of a media stream,
valid pairs are generated and added to the valid list. The agent lets
the checks continue until some stopping criteria is met, and then
picks amongst the valid pairs based on an evaluation criteria. The
criteria for stopping the checks and for evaluating the valid pairs is
entirely a matter of local optimization. 
</t>

<t>
When the controlling agent selects the valid pair, it repeats the
check that produced this valid pair (by enqueuing the pair that
generated the check into the triggered check queue), this time with
the USE-CANDIDATE attribute. This check should succeed (since the
previous did), causing the nominated flag of that and only that pair
to be set. Consequently, there will be only a single nominated pair in
the valid list for each component, and when the state of the check
list moves to completed, that exact pair is selected by ICE for
sending and receiving media for that component.
</t>

<t>
Regular nomination provides the most flexibility, since the agent has
control over the stopping and selection criteria for checks. The only
requirement is that the agent MUST eventually pick one and only one
candidate pair and generate a check for that pair with the
USE-CANDIDATE attribute present. Regular nomination also improves ICE's
resilience to variations in implementation (see <xref
target="sec-futureproof"/>). Regular nomination is also more stable,
allowing both agents to converge on a single pair for media without any
transient selections, which can happen with the aggressive
algorithm. The drawback of regular nomination is that it is guaranteed
to increase latencies because it requires an additional check to be done.
</t>

</section>

<section title="Aggressive Nomination">

<t>
With aggressive nomination, the
controlling agent includes the USE-CANDIDATE attribute in every check
it sends. Once the first check for a component succeeds, it will be
added to the valid list, and have its nominated flag set. When all
components have a nominated pair in the valid list, it will cause ICE
processing to cease for this check list. However, because the agent
included the USE-CANDIDATE attribute in all of its checks, another
check may yet complete, causing another valid pair to have its
nominated flag set. ICE always selects the highest priority nominated
candidate pair from the valid list as the one used for
media. Consequently, the selected pair may actually change briefly as
ICE checks complete, resulting in a set of transient selections until
it stabilizes. 
</t>

</section>

</section>

<section anchor="sec-conc-state" title="Updating States">

<t>
For both controlling and controlled agents, the state of ICE
processing depends on the presence of nominated candidate pairs in the
valid list and on the state of the check list. Note that, at any time,
more than one of the following cases can apply:
</t>

<t><list style="symbols">

<t>If there are no nominated pairs in the valid list for a
media stream and the state of the check list is Running, ICE
processing continues. 
</t>


<t>If there is at least one nominated pair in the valid list for a
media stream and the state of the check list is Running:
<list style="symbols">
<t>The agent MUST remove all Waiting and Frozen pairs in the check
list and triggered check queue for the same component as the nominated
pairs for that media stream
</t>
<t>If an In-Progress pair in the check list is for the same component
as a nominated pair, the agent SHOULD cease retransmissions for its check if
its pair priority is lower than the lowest priority nominated pair for
that component
</t></list>
</t>

<t>Once there is at least one nominated pair in the valid list for
every component of at least one media stream and the state of the
check list is Running: 
<list style="symbols">
<t>The agent MUST change the state of processing for its check list
for that media stream to Completed. </t>
<t>The agent MUST continue to respond to any checks it may still
receive for that media stream, and MUST perform triggered checks if
required by the processing of <xref target="sec-serverproc"/>.
</t>
<t>The agent MAY begin transmitting media for this media stream as
described in <xref target="sec-send-media"/>
</t>
</list>
</t>

<t>Once the state of each check list is Completed:
<list style="symbols">
<t>The agent sets the state of ICE processing overall to Completed.</t>
<t>If an agent is controlling, it examines the highest priority
nominated candidate pair for each component of each media stream. If any
of those candidate pairs differ from the default candidate pairs in the
most recent offer/answer exchange, the controlling 
agent MUST generate an updated offer as described in <xref
target="sec-subsequent"/>. If the controlling agent is using an
aggressive nomination algorithm, this may result in several updated
offers as the pairs selected for media change. An agent MAY delay
sending the offer for a brief interval (one second is RECOMMENDED) in
order to allow the selected pairs to stabilize.</t>
</list>
</t>

<t>If the state of the check list is Failed, ICE has not been
able to complete for this media stream. The correct behavior depends
on the state of the check lists for other media streams:
<list style="symbols">
<t>If all check lists are Failed, ICE processing overall is considered
to be in the Failed state, and the agent SHOULD consider the session a
failure, SHOULD NOT restart ICE, and the controlling agent SHOULD
terminate the entire session. </t>
<t>If at least one of the check lists for other media streams is
Completed, the controlling agent 
SHOULD remove the failed media stream from the session in its updated
offer.</t>
<t> If none of the check lists for other media streams are
Completed, but at least one is Running, the agent SHOULD let ICE
continue.</t>
</list>
</t>

</list></t>

</section>

</section>

<section anchor="sec-lite-conclude" title="Procedures for Lite
					   Implementations"> 

<t>
Concluding ICE for a lite implementation is relatively
straightforward. There are two cases to consider:
<list style="empty">
<t>The implementation is lite, and its peer is full. </t>
<t>The implementation is lite, and its peer is lite. </t>
</list></t>

<t>
The effect of ICE concluding is that the agent can free any allocated
host candidates that were not utilized by ICE, as described in <xref
target="sec-freeing"/>.
</t>

<section title="Peer is Full">

<t>
In this case, the agent will receive connectivity checks from its
peer. When an agent has received a connectivity check that includes
the USE-CANDIDATE attribute for each component of a media stream, the
state of ICE processing for that media stream moves from Running to
Completed. When the state of ICE processing for all media streams is
Completed, the state of ICE processing overall is Completed.
</t>

<t>
The lite implementation will never itself determine that ICE processing
has failed for a media stream; rather, the full peer will make that
determination and then remove or restart the failed media stream in a
subsequent offer.
</t>

</section>

<section anchor="sec-lite-conc2" title="Peer is Lite"> 

<t>
Once the offer/answer exchange has completed, both agents
examine their candidates and those of its peer. For each media
stream, each agent pairs up its own candidates with the candidates of its peer
for that media stream. Two candidates are paired up when they are for
the same component, utilize the same transport protocol (UDP in this
specification), and are from the same IP address family (IPv4 or
IPv6). 
<list style="symbols">
<t>If there is a single pair per component, that pair is added to the
  Valid list. If all of the components for a media stream had one
  pair, the state of ICE processing for that media stream is set to
  Completed. If all media streams are Completed, the state of ICE
  processing is set to Completed overall. This will always be the case
  for implementations that are IPv4 only.
</t>
<t>
If there is more than one pair per component:
<list style="symbols">
<t>The agent MUST select a
pair based on local policy. Since this case only arises for IPv6, it
is RECOMMENDED that an agent follow the procedures of RFC 3484 <xref
target="RFC3484"/> to select a single pair. </t>
<t>The agent adds the selected pair for each
component to the valid list. As described
in <xref target="sec-send-media"/>, this will permit media to begin
flowing. However, it is possible (and in fact likely) that both agents
have chosen different pairs. </t>
<t>To reconcile this, the controlling agent
MUST send an updated offer as described in <xref
target="sec-sub-lite"/>, which will include the remote-candidates
attribute. 
</t>
<t>The agent MUST NOT update the state of ICE processing when the
offer is sent. If this subsequent offer completes, the controlling
agent MUST change the state of ICE processing to Completed for all
media streams, and the state of ICE processing overall to
Completed. The states for the controlled agent are set based on the
logic in <xref target="sec-this-sucks"/>.
</t></list></t>
</list></t>

<!-- peer is lite -->
</section>

<!-- procedures for lite -->
</section>

<section anchor="sec-freeing" title="Freeing Candidates">

<section title="Full Implementation Procedures">

<t>
The procedures in <xref target="sec-conclude"/> require that an
agent continue to listen for STUN requests and continue to generate
triggered checks for a media stream, even once processing for that
stream completes. The rules in this section describe when it is safe
for an agent to cease sending or receiving checks on a candidate that
was not selected by ICE, and then free the candidate.
</t>

<t>
When ICE is used with SIP, and an offer is forked to multiple
recipients, ICE proceeds in parallel and independently with each
answerer, all using the same local candidates. Once ICE processing has
reached the Completed state for all peers for media streams using
those candidates, the agent SHOULD wait an additional three seconds,
and then it MAY cease responding to checks or generating triggered
checks on that candidate. It MAY free the candidate at that
time. Freeing of server reflexive candidates is never explicit; it
happens by lack of a keepalive. The three second delay handles cases
when aggressive nomination is used, and the selected pairs can quickly
change after ICE has completed.
</t>

</section>

<section title="Lite Implementations">

<t>
A lite implementation MAY free candidates not selected by ICE as soon
as ICE processing has reached the completed state for all peers for
all media streams using those candidates. 
</t>

</section>

<!-- freeing -->
</section>

<!-- concluding -->
</section>

<section anchor="sec-subsequent" title="Subsequent Offer/Answer Exchanges">

<t>
Either agent MAY generate a subsequent offer at any time allowed by
RFC 3264 <xref target="RFC3264"/>. The
rules in <xref target="sec-conclude"/> will cause the controlling
agent to send an updated offer at the conclusion of ICE processing
when ICE has selected different candidate pairs from the default
pairs. This section defines rules for construction of subsequent
offers and answers.
</t>

<t>
Should a subsequent offer be rejected, ICE processing continues as if
the subsequent offer had never been made.
</t>

<section anchor="sec-suboffer" title="Generating the Offer">

<section title="Procedures for All Implementations">

<section title="ICE Restarts">

<t>An agent MAY restart ICE processing for an existing media
stream. An ICE restart, as the name implies, will cause all previous
state of ICE processing to be flushed and checks to start anew. The
only difference between an ICE restart and a brand new media session
is that, during the restart, media can continue to be sent to the
previously validated pair. 
</t>

<t>
An agent MUST restart ICE for a media stream if:
</t>

<list style="symbols">
<t>The offer is being generated
for the purposes of changing the target of the media stream. In other
words, if an agent wants to generated an updated offer which, had ICE
not been in use, would result in a new value for the destination of a
media component. 
</t>

<t>An agent is changing its implementation level. This typically only
happens in third party call control use cases, where the entity
performing the signaling is not the entity receiving the media, and it
has changed the target of media mid-session to another entity that has
a different ICE implementation.
</t>
</list>

<t>These rules imply that setting the IP address in the c line to
0.0.0.0 will cause an ICE restart. Consequently, ICE implementations
MUST NOT utilize this mechanism for call hold, and instead MUST use
a=inactive and a=sendonly as described in <xref target="RFC3264"/>
</t>

<t>
To restart ICE, an agent MUST change both the ice-pwd and the
ice-ufrag for the media stream in an offer. Note that it is
permissible to use a session-level attribute in one offer, but to
provide the same ice-pwd or ice-ufrag as a media-level attribute in a
subsequent offer.  This is not a change in password, just a change in
its representation, and does not cause an ICE restart.
</t>

<t>
An agent sets the rest of the fields in the SDP for this media stream
as it would in an initial offer of this media stream (see <xref
target="sec-encoding"/>). Consequently, the set of candidates MAY
include some, none, or all of the previous candidates for that stream
and MAY include a totally new set of candidates gathered as described
in <xref target="sec-gathering"/>.
</t>

</section>

<section title="Removing a Media Stream">

<t>
If an agent removes a media stream by setting its port to zero, it
MUST NOT include any candidate attributes for that media st