MMUSIC J. Rosenberg Internet-Draft Cisco Obsoletes: 4091 (if approved) July 9, 2007 Intended status: Standards Track Expires: January 10, 2008 Interactive Connectivity Establishment (ICE): A Protocol for Network Address Translator (NAT) Traversal for Offer/Answer Protocols draft-ietf-mmusic-ice-17 Status of this Memo By submitting this Internet-Draft, each author represents that any applicable patent or other IPR claims of which he or she is aware have been or will be disclosed, and any of which he or she becomes aware will be disclosed, in accordance with Section 6 of BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet- Drafts. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt. The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html. This Internet-Draft will expire on January 10, 2008. Copyright Notice Copyright (C) The IETF Trust (2007). Abstract This document describes a protocol for Network Address Translator (NAT) traversal for 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 Rosenberg Expires January 10, 2008 [Page 1] Internet-Draft ICE July 2007 offer/answer model, such as the Session Initiation Protocol (SIP). Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 6 2. Overview of ICE . . . . . . . . . . . . . . . . . . . . . . . 7 2.1. Gathering Candidate Addresses . . . . . . . . . . . . . . 9 2.2. Connectivity Checks . . . . . . . . . . . . . . . . . . . 11 2.3. Sorting Candidates . . . . . . . . . . . . . . . . . . . 12 2.4. Frozen Candidates . . . . . . . . . . . . . . . . . . . . 13 2.5. Security for Checks . . . . . . . . . . . . . . . . . . . 14 2.6. Concluding ICE . . . . . . . . . . . . . . . . . . . . . 14 2.7. Lite Implementations . . . . . . . . . . . . . . . . . . 16 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 16 4. Sending the Initial Offer . . . . . . . . . . . . . . . . . . 19 4.1. Full Implementation Requirements . . . . . . . . . . . . 19 4.1.1. Gathering Candidates . . . . . . . . . . . . . . . . 19 4.1.1.1. Host Candidates . . . . . . . . . . . . . . . . . 20 4.1.1.2. Server Reflexive and Relayed Candidates . . . . . 20 4.1.1.3. Eliminating Redundant Candidates . . . . . . . . 21 4.1.1.4. Computing Foundations . . . . . . . . . . . . . . 22 4.1.1.5. Keeping Candidates Alive . . . . . . . . . . . . 22 4.1.2. Prioritizing Candidates . . . . . . . . . . . . . . . 22 4.1.2.1. Recommended Formula . . . . . . . . . . . . . . . 23 4.1.2.2. Guidelines for Choosing Type and Local Preferences . . . . . . . . . . . . . . . . . . . 24 4.1.3. Choosing Default Candidates . . . . . . . . . . . . . 25 4.2. Lite Implementation . . . . . . . . . . . . . . . . . . . 25 4.3. Encoding the SDP . . . . . . . . . . . . . . . . . . . . 26 5. Receiving the Initial Offer . . . . . . . . . . . . . . . . . 28 5.1. Verifying ICE Support . . . . . . . . . . . . . . . . . . 28 5.2. Determining Role . . . . . . . . . . . . . . . . . . . . 29 5.3. Gathering Candidates . . . . . . . . . . . . . . . . . . 30 5.4. Prioritizing Candidates . . . . . . . . . . . . . . . . . 30 5.5. Choosing Default Candidates . . . . . . . . . . . . . . . 30 5.6. Encoding the SDP . . . . . . . . . . . . . . . . . . . . 30 5.7. Forming the Check Lists . . . . . . . . . . . . . . . . . 31 5.7.1. Forming Candidate Pairs . . . . . . . . . . . . . . . 31 5.7.2. Computing Pair Priority and Ordering Pairs . . . . . 33 5.7.3. Pruning the Pairs . . . . . . . . . . . . . . . . . . 33 5.7.4. Computing States . . . . . . . . . . . . . . . . . . 33 5.8. Scheduling Checks . . . . . . . . . . . . . . . . . . . . 36 6. Receipt of the Initial Answer . . . . . . . . . . . . . . . . 38 6.1. Verifying ICE Support . . . . . . . . . . . . . . . . . . 38 6.2. Determining Role . . . . . . . . . . . . . . . . . . . . 38 6.3. Forming the Check List . . . . . . . . . . . . . . . . . 39 6.4. Performing Ordinary Checks . . . . . . . . . . . . . . . 39 Rosenberg Expires January 10, 2008 [Page 2] Internet-Draft ICE July 2007 7. Performing Connectivity Checks . . . . . . . . . . . . . . . 39 7.1. STUN Client Procedures . . . . . . . . . . . . . . . . . 39 7.1.1. Sending the Request . . . . . . . . . . . . . . . . . 39 7.1.1.1. PRIORITY and USE-CANDIDATE . . . . . . . . . . . 40 7.1.1.2. ICE-CONTROLLED and ICE-CONTROLLING . . . . . . . 40 7.1.1.3. Forming Credentials . . . . . . . . . . . . . . . 40 7.1.1.4. DiffServ Treatment . . . . . . . . . . . . . . . 40 7.1.2. Processing the Response . . . . . . . . . . . . . . . 41 7.1.2.1. Failure Cases . . . . . . . . . . . . . . . . . . 41 7.1.2.2. Success Cases . . . . . . . . . . . . . . . . . . 41 7.1.2.2.1. Discovering Peer Reflexive Candidates . . . . 42 7.1.2.2.2. Constructing a Valid Pair . . . . . . . . . . 42 7.1.2.2.3. Updating Pair States . . . . . . . . . . . . 43 7.1.2.2.4. Updating the Nominated Flag . . . . . . . . . 44 7.1.2.3. Check List and Timer State Updates . . . . . . . 44 7.2. STUN Server Procedures . . . . . . . . . . . . . . . . . 45 7.2.1. Additional Procedures for Full Implementations . . . 46 7.2.1.1. Detecting and Repairing Role Conflicts . . . . . 46 7.2.1.2. Computing Mapped Address . . . . . . . . . . . . 47 7.2.1.3. Learning Peer Reflexive Candidates . . . . . . . 47 7.2.1.4. Triggered Checks . . . . . . . . . . . . . . . . 48 7.2.1.5. Updating the Nominated Flag . . . . . . . . . . . 49 7.2.2. Additional Procedures for Lite Implementations . . . 49 8. Concluding ICE Processing . . . . . . . . . . . . . . . . . . 49 8.1. Procedures for Full Implementations . . . . . . . . . . . 50 8.1.1. Nominating Pairs . . . . . . . . . . . . . . . . . . 50 8.1.1.1. Regular Nomination . . . . . . . . . . . . . . . 50 8.1.1.2. Aggressive Nomination . . . . . . . . . . . . . . 51 8.1.2. Updating States . . . . . . . . . . . . . . . . . . . 51 8.2. Procedures for Lite Implementations . . . . . . . . . . . 52 8.2.1. Peer is Full . . . . . . . . . . . . . . . . . . . . 53 8.2.2. Peer is Lite . . . . . . . . . . . . . . . . . . . . 53 8.3. Freeing Candidates . . . . . . . . . . . . . . . . . . . 54 8.3.1. Full Implementation Procedures . . . . . . . . . . . 54 8.3.2. Lite Implementations . . . . . . . . . . . . . . . . 54 9. Subsequent Offer/Answer Exchanges . . . . . . . . . . . . . . 54 9.1. Generating the Offer . . . . . . . . . . . . . . . . . . 55 9.1.1. Procedures for All Implementations . . . . . . . . . 55 9.1.1.1. ICE Restarts . . . . . . . . . . . . . . . . . . 55 9.1.1.2. Removing a Media Stream . . . . . . . . . . . . . 56 9.1.1.3. Adding a Media Stream . . . . . . . . . . . . . . 56 9.1.2. Procedures for Full Implementations . . . . . . . . . 56 9.1.2.1. Existing Media Streams with ICE Running . . . . . 56 9.1.2.2. Existing Media Streams with ICE Completed . . . . 57 9.1.3. Procedures for Lite Implementations . . . . . . . . . 57 9.1.3.1. Existing Media Streams with ICE Running . . . . . 57 9.1.3.2. Existing Media Streams with ICE Completed . . . . 58 9.2. Receiving the Offer and Generating an Answer . . . . . . 58 Rosenberg Expires January 10, 2008 [Page 3] Internet-Draft ICE July 2007 9.2.1. Procedures for All Implementations . . . . . . . . . 58 9.2.1.1. Detecting ICE Restart . . . . . . . . . . . . . . 58 9.2.1.2. New Media Stream . . . . . . . . . . . . . . . . 59 9.2.1.3. Removed Media Stream . . . . . . . . . . . . . . 59 9.2.2. Procedures for Full Implementations . . . . . . . . . 59 9.2.2.1. Existing Media Streams with ICE Running and no remote-candidates . . . . . . . . . . . . . . . . 59 9.2.2.2. Existing Media Streams with ICE Completed and no remote-candidates . . . . . . . . . . . . . . 59 9.2.2.3. Existing Media Streams and remote-candidates . . 59 9.2.3. Procedures for Lite Implementations . . . . . . . . . 60 9.3. Updating the Check and Valid Lists . . . . . . . . . . . 61 9.3.1. Procedures for Full Implementations . . . . . . . . . 61 9.3.1.1. ICE Restarts . . . . . . . . . . . . . . . . . . 61 9.3.1.2. New Media Stream . . . . . . . . . . . . . . . . 61 9.3.1.3. Removed Media Stream . . . . . . . . . . . . . . 62 9.3.1.4. ICE Continuing for Existing Media Stream . . . . 62 9.3.2. Procedures for Lite Implementations . . . . . . . . . 62 10. Keepalives . . . . . . . . . . . . . . . . . . . . . . . . . 63 11. Media Handling . . . . . . . . . . . . . . . . . . . . . . . 64 11.1. Sending Media . . . . . . . . . . . . . . . . . . . . . . 64 11.1.1. Procedures for Full Implementations . . . . . . . . . 64 11.1.2. Procedures for Lite Implementations . . . . . . . . . 65 11.1.3. Procedures for All Implementations . . . . . . . . . 65 11.2. Receiving Media . . . . . . . . . . . . . . . . . . . . . 65 12. Usage with SIP . . . . . . . . . . . . . . . . . . . . . . . 66 12.1. Latency Guidelines . . . . . . . . . . . . . . . . . . . 66 12.1.1. Offer in INVITE . . . . . . . . . . . . . . . . . . . 66 12.1.2. Offer in Response . . . . . . . . . . . . . . . . . . 67 12.2. SIP Option Tags and Media Feature Tags . . . . . . . . . 68 12.3. Interactions with Forking . . . . . . . . . . . . . . . . 68 12.4. Interactions with Preconditions . . . . . . . . . . . . . 68 12.5. Interactions with Third Party Call Control . . . . . . . 69 13. Relationship with ANAT . . . . . . . . . . . . . . . . . . . 69 14. Extensibility Considerations . . . . . . . . . . . . . . . . 69 15. Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 15.1. "candidate" Attribute . . . . . . . . . . . . . . . . . . 71 15.2. "remote-candidates" Attribute . . . . . . . . . . . . . . 73 15.3. "ice-lite" and "ice-mismatch" Attributes . . . . . . . . 73 15.4. "ice-ufrag" and "ice-pwd" Attributes . . . . . . . . . . 73 15.5. "ice-options" Attribute . . . . . . . . . . . . . . . . . 74 16. Setting Ta and RTO . . . . . . . . . . . . . . . . . . . . . 74 17. Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 18. Security Considerations . . . . . . . . . . . . . . . . . . . 82 18.1. Attacks on Connectivity Checks . . . . . . . . . . . . . 82 18.2. Attacks on Server Reflexive Address Gathering . . . . . . 84 18.3. Attacks on Relayed Candidate Gathering . . . . . . . . . 85 18.4. Attacks on the Offer/Answer Exchanges . . . . . . . . . . 86 Rosenberg Expires January 10, 2008 [Page 4] Internet-Draft ICE July 2007 18.5. Insider Attacks . . . . . . . . . . . . . . . . . . . . . 86 18.5.1. The Voice Hammer Attack . . . . . . . . . . . . . . . 86 18.5.2. STUN Amplification Attack . . . . . . . . . . . . . . 86 18.6. Interactions with Application Layer Gateways and SIP . . 87 19. STUN Extensions . . . . . . . . . . . . . . . . . . . . . . . 88 19.1. New Attributes . . . . . . . . . . . . . . . . . . . . . 88 19.2. New Error Response Codes . . . . . . . . . . . . . . . . 89 20. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 89 20.1. SDP Attributes . . . . . . . . . . . . . . . . . . . . . 89 20.1.1. candidate Attribute . . . . . . . . . . . . . . . . . 89 20.1.2. remote-candidates Attribute . . . . . . . . . . . . . 90 20.1.3. ice-lite Attribute . . . . . . . . . . . . . . . . . 90 20.1.4. ice-mismatch Attribute . . . . . . . . . . . . . . . 91 20.1.5. ice-pwd Attribute . . . . . . . . . . . . . . . . . . 91 20.1.6. ice-ufrag Attribute . . . . . . . . . . . . . . . . . 91 20.1.7. ice-options Attribute . . . . . . . . . . . . . . . . 92 20.2. STUN Attributes . . . . . . . . . . . . . . . . . . . . . 92 20.3. STUN Error Responses . . . . . . . . . . . . . . . . . . 93 21. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 93 21.1. Problem Definition . . . . . . . . . . . . . . . . . . . 93 21.2. Exit Strategy . . . . . . . . . . . . . . . . . . . . . . 93 21.3. Brittleness Introduced by ICE . . . . . . . . . . . . . . 94 21.4. Requirements for a Long Term Solution . . . . . . . . . . 95 21.5. Issues with Existing NAPT Boxes . . . . . . . . . . . . . 95 22. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 96 23. References . . . . . . . . . . . . . . . . . . . . . . . . . 96 23.1. Normative References . . . . . . . . . . . . . . . . . . 96 23.2. Informative References . . . . . . . . . . . . . . . . . 97 Appendix A. Lite and Full Implementations . . . . . . . . . . . 99 Appendix B. Design Motivations . . . . . . . . . . . . . . . . . 100 B.1. Pacing of STUN Transactions . . . . . . . . . . . . . . . 101 B.2. Candidates with Multiple Bases . . . . . . . . . . . . . 102 B.3. Purpose of the and Attributes . . . 104 B.4. Importance of the STUN Username . . . . . . . . . . . . . 104 B.5. The Candidate Pair Sequence Number Formula . . . . . . . 105 B.6. The remote-candidates attribute . . . . . . . . . . . . . 106 B.7. Why are Keepalives Needed? . . . . . . . . . . . . . . . 107 B.8. Why Prefer Peer Reflexive Candidates? . . . . . . . . . . 108 B.9. Why Send an Updated Offer? . . . . . . . . . . . . . . . 108 B.10. Why are Binding Indications Used for Keepalives? . . . . 108 B.11. Why is the Conflict Resolution Mechanism Needed? . . . . 109 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 110 Intellectual Property and Copyright Statements . . . . . . . . . 111 Rosenberg Expires January 10, 2008 [Page 5] Internet-Draft ICE July 2007 1. Introduction RFC 3264 [RFC3264] defines a two-phase exchange of Session Description Protocol (SDP) messages [RFC4566] for the purposes of establishment of multimedia sessions. This offer/answer mechanism is used by protocols such as the Session Initiation Protocol (SIP) [RFC3261]. 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 [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. Numerous solutions have been proposed for allowing these protocols to operate through NAT. These include Application Layer Gateways (ALGs), the Middlebox Control Protocol [RFC3303], Simple Traversal Underneath NAT (STUN) [RFC3489] and its revision, retitled Session Traversal Utilities for NAT [I-D.ietf-behave-rfc3489bis], Traversal Using Relay NAT (TURN) [I-D.ietf-behave-turn], and Realm Specific IP [RFC3102] [RFC3103] along with session description extensions needed to make them work, such as the Session Description Protocol (SDP) [RFC4566] attribute for the Real Time Control Protocol (RTCP) [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. This specification defines Interactive Connectivity Establishment (ICE) as a technique for NAT traversal for media streams 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 STUN exchanges. The IP addresses and ports included in the SDP are gathered using STUN [I-D.ietf-behave-rfc3489bis] and Traversal Using Relay NAT (TURN) [I-D.ietf-behave-turn]. 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 Rosenberg Expires January 10, 2008 [Page 6] Internet-Draft ICE July 2007 it deprecates RFC 4091 [RFC4091]. 2. Overview of ICE 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 [RFC3264] messages. Note that ICE is not intended for NAT traversal for SIP, which is assumed to be provided via another mechanism [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. Figure 1 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. 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. Rosenberg Expires January 10, 2008 [Page 7] Internet-Draft ICE July 2007 +-------+ | SIP | +-------+ | Srvr | +-------+ | STUN | | | | STUN | | Srvr | +-------+ | Srvr | | | / \ | | +-------+ / \ +-------+ / \ / \ / \ / \ / <- Signalling -> \ / \ / \ +--------+ +--------+ | NAT | | NAT | +--------+ +--------+ / \ / \ / \ +-------+ +-------+ | Agent | | Agent | | L | | R | | | | | +-------+ +-------+ Figure 1: ICE Deployment Scenario The basic idea behind ICE is as follows: each agent has a variety of candidate TRANSPORT ADDRESSES (combination of IP address and port) it could use to communicate with the other agent. These might include: o A transport address on a directly attached network interface o A translated transport address on the public side of a NAT (a "server reflexive" address) o The transport address allocated from a TURN server(a "relayed address". 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) Rosenberg Expires January 10, 2008 [Page 8] Internet-Draft ICE July 2007 until it finds one or more that works. 2.1. Gathering Candidate Addresses 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. 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 a candidate) can be allocated. If an agent is multihomed, it obtains a candidate from each interface. 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 interfaces. Consider, for example, an agent which has a local interface to 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 interface will work prior to sending an offer, the offering agent includes both candidates in its offer. 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 canddiates are obtained from them. The relationship of these candidates to the host candidate is shown in Figure 2. In this figure, both types of candidates are discovered using TURN. In the figure, the notation X:x means IP address X and port x. Rosenberg Expires January 10, 2008 [Page 9] Internet-Draft ICE July 2007 To Internet | | | /------------ Relayed Y:y | / Address +--------+ | | | TURN | | Server | | | +--------+ | | | /------------ Server X1':x1'|/ Reflexive +------------+ Address | NAT | +------------+ | | /------------ Local X:x |/ Address +--------+ | | | Agent | | | +--------+ Figure 2: Candidate Relationships 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 relexive 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. 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. 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 Rosenberg Expires January 10, 2008 [Page 10] Internet-Draft ICE July 2007 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. The Allocate request then arrives at the TURN server. The TURN server allocates a port y from its local interface 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. When only STUN servers are utilized, the agent sends a STUN Binding Request [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. 2.2. Connectivity Checks 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, the 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. The basic principle of the connectivity checks is simple: 1. Sort the candidate pairs in priority order. 2. Send checks on each candidate pair in priority order. 3. Acknowledge checks received from the other agent. With both agents performing a check on a candidate pair, the result is a 4-way handshake: Rosenberg Expires January 10, 2008 [Page 11] Internet-Draft ICE July 2007 L R - - STUN request -> \ L's <- STUN response / check <- STUN request \ R's STUN response -> / check Figure 3: Basic Connectivity Check 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. 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. 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. At the end of this handshake, both L and R know that they can send (and receive) messages end-to-end in both directions. 2.3. Sorting Candidates 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 Section 4.1.2 but follows two general principles: o Each agent gives its candidates a numeric priority which is sent along with the candidate to the peer o The local and remote priorities are combined so that each agent has the same ordering for the candidate pairs. Rosenberg Expires January 10, 2008 [Page 12] Internet-Draft ICE July 2007 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. 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. 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. 2.4. Frozen Candidates 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. 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." 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 interface 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. Rosenberg Expires January 10, 2008 [Page 13] Internet-Draft ICE July 2007 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. 2.5. Security for Checks 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. The MAC also aids in disambiguating ICE exchanges from forked calls when ICE is used with SIP [RFC3261]. 2.6. Concluding ICE 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 packet losses 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. 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. 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 Figure 4. Rosenberg Expires January 10, 2008 [Page 14] Internet-Draft ICE July 2007 L R - - STUN request -> \ L's <- STUN response / check <- STUN request \ R's STUN response -> / check STUN request + flag -> \ L's <- STUN response / check Figure 4: Regular Nomination 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. 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 succeeeded. Aggressive nomination is faster than regular nomination, but gives less flexibility. Aggressive nomination is shown in Figure 5. L R - - STUN request + flag -> \ L's <- STUN response / check <- STUN request \ R's STUN response -> / check Figure 5: Aggressive Nomination 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. 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. Rosenberg Expires January 10, 2008 [Page 15] Internet-Draft ICE July 2007 2.7. Lite Implementations 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. For guidance on when a lite implementation is appropriate, see the discussion in Appendix A. 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. 3. Terminology 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 RFC 2119 [RFC2119]. Readers should be familiar with the terminology defined in the offer/ answer model [RFC3264], STUN [I-D.ietf-behave-rfc3489bis] and NAT Behavioral requirements for UDP [RFC4787] This specification makes use of the following additional terminology: 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. 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. Rosenberg Expires January 10, 2008 [Page 16] Internet-Draft ICE July 2007 Transport Address: The combination of an IP address and transport protocol (such as UDP or TCP) port. 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. 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. Host Candidate: A candidate obtained by binding to a specific port from an interface on the host. This includes both physical interfaces and logical ones, such as ones obtained through Virtual Private Networks (VPNs) and Realm Specific IP (RSIP) [RFC3102] (which lives at the operating system level). 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. 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. 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. 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. 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. Rosenberg Expires January 10, 2008 [Page 17] Internet-Draft ICE July 2007 Local Candidate: A candidate that an agent has obtained and included in an offer or answer it sent. Remote Candidate: A candidate that an agent received in an offer or answer from its peer. 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. Candidate Pair: A pairing containing a local candidate and a remote candidate. 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. Check List: An ordered set of candidate pairs that an agent will use to generate checks. Ordinary Check: A connectivity check generated by an agent as a consequence of a timer that fires periodically, instructing it to send a check. Triggered Check: A connectivity check generated as a consequence of the receipt of a connectivity check from the peer. Valid List: An ordered set of candidate pairs for a media stream that have been validated by a successful STUN transaction. Full: An ICE implementation that performs the complete set of functionality defined by this specification. 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. Rosenberg Expires January 10, 2008 [Page 18] Internet-Draft ICE July 2007 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. Controlled Agent: An ICE agent which waits for the controlling agent to select the final choice of candidate pairs. 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. 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. 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. 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. 4. Sending the Initial Offer 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. The first of these four steps differ for full and lite implementations. 4.1. Full Implementation Requirements 4.1.1. Gathering Candidates 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. Three types are defined and gathered by this specification - host candidates, server reflexive candidates, and relayed candidates. The server reflexive and relayed candidates are gathered using STUN or TURN, and relayed candidates are obtained through TURN. The base of a candidate is the candidate that an agent must send from when using that candidate. Rosenberg Expires January 10, 2008 [Page 19] Internet-Draft ICE July 2007 4.1.1.1. Host Candidates The first step is to gather host candidates. Host candidates are obtained by binding to ports (typically ephemeral) on an interface (physical or virtual, including VPN interfaces) on the host. The process for gathering host candidates depends on the transport protocol. Procedures are specified here for UDP. 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 interface that the host has. It obtains each candidate by binding to a UDP port on the specific interface. 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 interfaces. The base for each host candidate is set to the candidate itself. 4.1.1.2. Server Reflexive and Relayed Candidates 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. 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. 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 Rosenberg Expires January 10, 2008 [Page 20] Internet-Draft ICE July 2007 [I-D.ietf-behave-rfc3489bis] (using SRV records with the "stun" service) be used to discover the STUN server, and the DNS procedures in [I-D.ietf-behave-turn] (using SRV records with the "turn" service) be used to discover the TURN server. 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 [I-D.ietf-behave-rfc3489bis]. Allocate requests SHOULD be authenticated using a long-term credential provisioned into the client. 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 Section 16 for guidance on how to set Ta and the STUN retransmit timer, RTO. 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. 4.1.1.3. Eliminating Redundant Candidates Next, the agent eliminates redundant candidates. A candidate is redundant if its transport address equals another candidate, and its Rosenberg Expires January 10, 2008 [Page 21] Internet-Draft ICE July 2007 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. 4.1.1.4. Computing Foundations 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: o they are of the same type (host, relayed, server reflexive, or peer reflexive) o their bases have the same IP address (the ports can be different) o for reflexive and relayed candidates, the STUN or TURN servers used to obtain them have the same IP address. o they were obtained using the same transport protocol (TCP, UDP, etc.) 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. 4.1.1.5. Keeping Candidates Alive Once server reflexive and relayed candidates are allocated, they MUST be kept alive until ICE processing has completed, as described in Section 8.3. For server reflexive candidates learned through a Binding request, the bindings MUST be kept alive by another Binding Request to the server. For relayed candidates learned through an Allocate request, the keepalive MUST be a new Allocate request. The Allocate request will also refresh the server reflexive candidate. 4.1.2. Prioritizing Candidates 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**32 - 1). This priority will be used by ICE to determine the order of the connectivity checks and the relative preference for candidates. An agent SHOULD compute this priority using the formula in Section 4.1.2.1 and choose its parameters using the guidelines in Rosenberg Expires January 10, 2008 [Page 22] Internet-Draft ICE July 2007 Section 4.1.2.2. 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. 4.1.2.1. Recommended Formula 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 interfaces. These two preferences are then combined to compute the priority for a candidate. That priority is computed using the following formula: priority = (2^24)*(type preference) + (2^8)*(local preference) + (2^0)*(256 - component ID) 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 Section 4.1.1 will never be peer reflexive candidates; candidates of these type are learned from the connectivity checks performed by ICE. The local preference MUST be an integer from 0 to 65535 inclusive. It represents a preference for the particular interface 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 interface, 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. The component ID is the component ID for the candidate, and MUST be between 1 and 256 inclusive. Rosenberg Expires January 10, 2008 [Page 23] Internet-Draft ICE July 2007 4.1.2.2. Guidelines for Choosing Type and Local Preferences 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 interfaces, the local preference for host candidates from a VPN interface SHOULD have a priority of 0. 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) [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 interface, followed by the 6to4 interfaces, followed by the v4 interfaces. 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. 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 interface would have a higher local preference than any other interface. 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 Rosenberg Expires January 10, 2008 [Page 24] Internet-Draft ICE July 2007 preferences to candidates obtained from closer intermediaries. 4.1.3. Choosing Default Candidates 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. 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 [RFC4566] or has a bandwidth value of zero. 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. 4.2. Lite Implementation 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 interfaces, 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. 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. Each candidate is assigned a foundation. The foundation MUST be Rosenberg Expires January 10, 2008 [Page 25] Internet-Draft ICE July 2007 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: priority = (2^24)*(126) + (2^8)*(IP precedence) + (2^0)*(256 - component ID) 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 is the precedence value for IP addresses described in RFC 3484 [RFC3484]. 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. 4.3. Encoding the SDP The process of encoding the SDP is identical between full and lite implementations. 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. There will be a candidate attribute for each candidate for a particular media stream. Section 15 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. Rosenberg Expires January 10, 2008 [Page 26] Internet-Draft ICE July 2007 STUN connectivity checks between agents are authenticated using the short term credential mechanism defined for STUN [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 Appendix B.4 for motivation. 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. 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 [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 [RFC3556]. 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. 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. The following is an example SDP message that includes ICE attributes (lines folded for readability): Rosenberg Expires January 10, 2008 [Page 27] Internet-Draft ICE July 2007 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 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 Section 11.1, media packets can be sent to a candidate prior to its appearance as the default destination for media in an offer or answer. 5. Receiving the Initial Offer 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. 5.1. Verifying ICE Support 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. 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: 1. The agent MUST follow the rules of Section 10, which describe keepalive procedures for all agents. Rosenberg Expires January 10, 2008 [Page 28] Internet-Draft ICE July 2007 2. 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. 5.2. Determining Role 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. The rules for determining the role and the impact on behavior are as follows: 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 Section 8.1 to nominate pairs that will be selected by ICE, and then both agents end ICE as described in Section 8.1.2. In unusual cases, described in Appendix B.11, 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 Section 7.1.1.2. 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 Section 8.1 to nominate pairs that will be selected by ICE, and use the logic in Section 8.1.2 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 Rosenberg Expires January 10, 2008 [Page 29] Internet-Draft ICE July 2007 Section 8.2. 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. 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 Section 8 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. Once roles are determined for a session, they persist unless ICE is restarted. A ICE restart (Section 9.1) causes a new selection of roles and tie-breakers. 5.3. Gathering Candidates The process for gathering candidates at the answerer is identical to the process for the offerer as described in Section 4.1.1 for full implementations and Section 4.2 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. 5.4. Prioritizing Candidates The process for prioritizing candidates at the answerer is identical to the process followed by the offerer, as described in Section 4.1.2 for full implementations and Section 4.2 for lite implementations. 5.5. Choosing Default Candidates The process for selecting default candidates at the answerer is identical to the process followed by the offerer, as described in Section 4.1.3 for full implementations and Section 4.2 for lite implementations. 5.6. Encoding the SDP 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 Section 4.3. Rosenberg Expires January 10, 2008 [Page 30] Internet-Draft ICE July 2007 5.7. Forming the Check Lists Forming check lists is done only by full implementations. Lite implementations MUST skip the steps defined in this section. 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. 5.7.1. Forming Candidate Pairs 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 Section 18.5.2, 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. 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 [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. 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. Rosenberg Expires January 10, 2008 [Page 31] Internet-Draft ICE July 2007 In order to aid understanding, Figure 9 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. +------------------------------------------+ | | | +---------------------+ | | |+----+ +----+ +----+ | +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 Rosenberg Expires January 10, 2008 [Page 32] Internet-Draft ICE July 2007 Figure 9: Conceptual Diagram of a Check List 5.7.2. Computing Pair Priority and Ordering Pairs 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: pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0) Where G>D?1:0 is an expression whose value is 1 if G is greater than D, and 0 otherwise. This formula ensures a unique priority for each pair. 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. 5.7.3. Pruning the Pairs 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. In addition, in order to limit the attacks described in Section 18.5.2, an agent SHOULD limit the total number of connectivity checks they perform across all check lists to 100, by discarding the lower priority candidate pairs until there are less than 100. 5.7.4. Computing States 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: Rosenberg Expires January 10, 2008 [Page 33] Internet-Draft ICE July 2007 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. In-Progress: A check has been sent for this pair, but the transaction is in progress. Succeeded: A check for this pair was already done and produced a successful result. Failed: A check for this pair was already done and failed, either never producing any response or producing an unrecoverable failure response. 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. As ICE runs, the pairs will move between states as shown in Figure 10. Rosenberg Expires January 10, 2008 [Page 34] Internet-Draft ICE July 2007 +-----------+ | | | | | Frozen | | | | | +-----------+ | |unfreeze | V +-----------+ +-----------+ | | | | | | perform | | | Waiting |-------->|In-Progress| | | | | | | | | +-----------+ +-----------+ / | // | // | // | / | // | failure // |success // | / | // | // | // | V V +-----------+ +-----------+ | | | | | | | | | Failed | | Succeeded | | | | | | | | | +-----------+ +-----------+ Figure 10: Pair State FSM The initial states for each pair in a check list are computed by performing the following sequence of steps: 1. The agent sets all of the pairs in each check list to the Frozen state. Rosenberg Expires January 10, 2008 [Page 35] Internet-Draft ICE July 2007 2. 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, it: * Groups together all of the pairs with the same foundation, * 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. 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. The check list itself is associated with a state, which captures the state of ICE checks for that media stream. There are three states: Running: In this state, ICE checks are still in progress for this media stream. 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. Failed: In this state, the ICE checks have not completed successfully for this media stream. When a check list is first constructed as the consequence of an offer/answer exchange, it is placed in the Running state. 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. 5.8. Scheduling Checks Checks are generated only by full implementations. Lite implementations MUST skip the steps described in this section. 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 Rosenberg Expires January 10, 2008 [Page 36] Internet-Draft ICE July 2007 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. Once the agent has computed the check lists as described in Section 5.7, 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 Section 16. 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). When the timer fires, and there is no triggered check to be sent, the agent MUST choose an ordinary check as follows: o Find the highest priority pair in that check list that is in the Waiting state. o If there is such a pair: * 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 Section 7.1.1. * Set the state of the candidate pair to In-Progress. o If there is no such pair: * Find the highest priority pair in that check list that is in the Frozen state. * If there is such a pair: + Unfreeze the pair. + Perform a check for that pair, causing its state to transition to In-Progress. Rosenberg Expires January 10, 2008 [Page 37] Internet-Draft ICE July 2007 * If there is no such pair: + Terminate the timer for that check list. 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. 6. Receipt of the Initial Answer 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. 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 Section 8.3. 6.1. Verifying ICE Support The logic at the offerer is identical to that of the answerer as described in Section 5.1, with the exception that an offerer would not ever generate a=ice-mismatch attributes in an SDP. 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 Section 18 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. 6.2. Determining Role The offerer follows the same procedures described for the answerer in Section 5.2. Rosenberg Expires January 10, 2008 [Page 38] Internet-Draft ICE July 2007 6.3. Forming the Check List Formation of check lists is performed only by full implementations. The offerer follows the same procedures described for the answerer in Section 5.7. 6.4. Performing Ordinary Checks Ordinary checks are performed only by full implementations. The offerer follows the same procedures described for the answerer in Section 5.8. 7. Performing Connectivity Checks This section describes how connectivity checks are performed. All ICE implementations are required to be compliant to [I-D.ietf-behave-rfc3489bis], as opposed to the older [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. 7.1. STUN Client Procedures 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. 7.1.1. Sending the Request The check is generated by sending a Binding Request from a local candidate, to a remote candidate. [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. ICE extends STUN by defining several new attributes, including PRIORITY, USE-CANDIDATE, ICE-CONTROLLED, and ICE-CONTROLLING. These new attributes are formally defined in Section 19.1, and their usage is described in the subsections below. These STUN extensions are applicable only to connectivity checks used for ICE. Rosenberg Expires January 10, 2008 [Page 39] Internet-Draft ICE July 2007 7.1.1.1. PRIORITY and USE-CANDIDATE 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 Section 4.1.2, to a peer reflexive candidate, should one be learned as a consequence of this check (see Section 7.1.2.2.1 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 derived candidate types. 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. Section 8.1.1 provides guidance on determining when to include it. 7.1.1.2. ICE-CONTROLLED and ICE-CONTROLLING 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 Section 5.2. These attributes are defined fully in Section 19.1. 7.1.1.3. Forming Credentials 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. 7.1.1.4. DiffServ Treatment If the agent is using Diffserv Codepoint markings [RFC2475] in its media packets, it SHOULD apply those same markings to its Rosenberg Expires January 10, 2008 [Page 40] Internet-Draft ICE July 2007 connectivity checks. 7.1.2. Processing the Response When a Binding Response is received, it is correlated to its Binding Request using the transaction ID, as defined in [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. 7.1.2.1. Failure Cases 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. 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 [I-D.ietf-behave-rfc3489bis]), or times out, the agent sets the state of the pair to Failed. 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. 7.1.2.2. Success Cases A check is considered to be a success if all of the following are true: Rosenberg Expires January 10, 2008 [Page 41] Internet-Draft ICE July 2007 o the STUN transaction generated a success response o the source IP address and port of the response equals the destination IP address and port that the Binding Request was sent to o the destination IP address and port of the response match the source IP address and port that the Binding Request was sent from 7.1.2.2.1. Discovering Peer Reflexive Candidates 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: o Its type is equal to peer reflexive. o Its base is set equal to the local candidate of the candidate pair from which the STUN check was sent. o Its priority is set equal to the value of the PRIORITY attribute in the Binding Request. o Its foundation is selected as described in Section 4.1.1. 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 Section 7.1.2.2.2. 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. 7.1.2.2.2. Constructing a Valid Pair 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 Rosenberg Expires January 10, 2008 [Page 42] Internet-Draft ICE July 2007 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. 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. 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 Section 5.7. 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. 7.1.2.2.3. Updating Pair States 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: 1. 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. 2. 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 Rosenberg Expires January 10, 2008 [Page 43] Internet-Draft ICE July 2007 that valid list. The agent examines the check list for each other media stream in turn: * 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. * 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 Section 5.8. * 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 + Groups together all of the pairs with the same foundation, + 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. 7.1.2.2.4. Updating the Nominated Flag 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 Section 8. If the agent is the controlled agent, the response may result in the valid pair having its nominated flag set. See Section 7.2.1.5 for the procedure. 7.1.2.3. Check List and Timer State Updates Regardless of whether the check was successful or failed, the completion of the transaction may require updating of check list and timer states. If all of the pairs in the check list are now either in the Failed or Succeeded state: Rosenberg Expires January 10, 2008 [Page 44] Internet-Draft ICE July 2007 o 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. o For each frozen check list, the agent: * Groups together all of the pairs with the same foundation, * 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. 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 Section 5.8. 7.2. STUN Server Procedures 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. 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 Section 7.2.1.2. 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 Section 7.2.1.3, Section 7.2.1.4, and Section 7.2.1.5 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. 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. If the agent is using Diffserv Codepoint markings [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. Rosenberg Expires January 10, 2008 [Page 45] Internet-Draft ICE July 2007 7.2.1. Additional Procedures for Full Implementations This subsection defines the additional server procedures applicable to full implementations. 7.2.1.1. Detecting and Repairing Role Conflicts Normally, the rules for selection of a role in Section 5.2 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. An agent MUST examine the Binding Request for either the ICE- CONTROLLING or ICE-CONTROLLED attribute. It MUST follow these procedures: o 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. o If the agent is in the controlling role, and the ICE-CONTROLLING attribute is present in the request: * 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. * If the agent's tie-breaker is less than the contents of the ICE-CONTROLLING attribute, the agent switches to the controlled role. o If the agent is in the controlled role, and the ICE-CONTROLLED attribute is present in the request: * 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. * 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. Rosenberg Expires January 10, 2008 [Page 46] Internet-Draft ICE July 2007 o 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. A change in roles will require an agent to recompute pair priorities Section 5.7.2, 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. The remaining sections in Section 7.2.1 are followed if the server generated a successful response to the Binding Request, even if the agent changed roles. 7.2.1.2. Computing Mapped Address 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. 7.2.1.3. Learning Peer Reflexive Candidates 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: o The priority of the candidate is set to the PRIORITY attribute from the request. o The type of the candidate is set to peer reflexive. o 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. o The component ID of this candidate is set to the component ID for the local candidate to which the request was sent. Rosenberg Expires January 10, 2008 [Page 47] Internet-Draft ICE July 2007 This candidate is added to the list of remote candidates. However, the agent does not pair this candidate with any local candidates. 7.2.1.4. Triggered Checks 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: o If the pair is already on the check list: * If the state of that pair is Waiting or Frozen, a check for that pair is enqueued into the triggered check queue. * 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. * 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. * If the state of that pair is Succeeded, nothing further is done. o These steps are done to facilitate rapid completion of ICE when both agents are behind NAT. o If the pair is not already on the check list: * The pair is inserted into the check list based on its priority * Its state is set to Waiting * The pair is enqueued into the triggered check queue. Rosenberg Expires January 10, 2008 [Page 48] Internet-Draft ICE July 2007 When a triggered check is to be sent, it is constructed and processed as described in Section 7.1.1. 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. 7.2.1.5. Updating the Nominated Flag 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 Section 7.2.1.4: o 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 Section 7.1.2.2.2). The agent now sets the nominated flag in the valid pair to true. This may end ICE processing for this media stream; see Section 8. o 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 Section 8. 7.2.2. Additional Procedures for Lite Implementations 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. 8. Concluding ICE Processing This section describes how an agent completes ICE. Rosenberg Expires January 10, 2008 [Page 49] Internet-Draft ICE July 2007 8.1. Procedures for Full Implementations Concluding ICE involves nominating pairs by the controlling agent and updating of state machinery. 8.1.1. Nominating Pairs 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. 8.1.1.1. Regular Nomination 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. 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. 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 Section 14). Regular nomination is also more stable, allowing both agents to converge on a single pair for media without any transient selections, which can Rosenberg Expires January 10, 2008 [Page 50] Internet-Draft ICE July 2007 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. 8.1.1.2. Aggressive Nomination 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. 8.1.2. Updating States 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: o 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. o 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: * 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 * 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 o 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: * The agent MUST change the state of processing for its check list for that media stream to Completed. Rosenberg Expires January 10, 2008 [Page 51] Internet-Draft ICE July 2007 * 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 Section 7.2. * The agent MAY begin transmitting media for this media stream as described in Section 11.1 o Once the state of each check list is Completed: * The agent sets the state of ICE processing overall to Completed. * 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 Section 9. 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. o 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: * 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. * 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. * If none of the check lists for other media streams are Completed, but at least one is Running, the agent SHOULD let ICE continue. 8.2. Procedures for Lite Implementations Concluding ICE for a lite implementation is relatively straightforward. There are two cases to consider: The implementation is lite, and its peer is full. Rosenberg Expires January 10, 2008 [Page 52] Internet-Draft ICE July 2007 The implementation is lite, and its peer is lite. The effect of ICE concluding is that the agent can free any allocated host candidates that were not utilized by ICE, as described in Section 8.3. 8.2.1. Peer is Full 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. 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. 8.2