ICE

Version 58 (Adrian Georgescu, 05/28/2010 11:02 pm)

1 1 Redmine Admin
2 58 Adrian Georgescu
h1. MediaProxy ICE Support
3 1 Redmine Admin
4 1 Redmine Admin
5 1 Redmine Admin
6 58 Adrian Georgescu
h2. Background
7 58 Adrian Georgescu
8 58 Adrian Georgescu
9 58 Adrian Georgescu
"ICE methodology":http://tools.ietf.org/html/rfc5245 has been defined at IETF (RFC5245) to help end-points traverse NAT routers for  RTP media by finding the shortest available path between the end-points. Where the network topology does not allow for direct media path between the end-points, a TURN server has been standardized to provide the end-points with a visible public candidate that can be used to relay traffic  to the end-points behind an unfriendly NAT type (e.g. symmetric). TURN servers are not widely deployed today whereas solutions like SIP Proxies in tandem with RTP relays are. 
10 58 Adrian Georgescu
11 58 Adrian Georgescu
RTP relays that work in tandem with SIP Proxies perform similar function to the TURN protocol except that the reservation is done by the SIP Proxy rather than by the user agent. The SIP User Agent does not need to support TURN protocol in order to use the relay, which makes it compatible with any SIP User Agent available today. Such solution used widely today is the tandem *OpenSIPS/MediaProxy*. 
12 58 Adrian Georgescu
13 1 Redmine Admin
Until the addition of this functionality, MediaProxy module used to rewrite the SDP in order to present to the destination SIP User Agent a reachable IP:port number for sending RTP/RTCP. This had the dis-advantage that the session was always using a relay and it was mutually exclusive with the use of ICE. The rewriting of the SDP and the missing candiate correspondent to the c= line of the SDP caused the target SIP end-point to reply with ICE missmatch and the ICE negotiation always failed in its tracks.
14 36 Adrian Georgescu
15 1 Redmine Admin
16 58 Adrian Georgescu
h2. Features
17 58 Adrian Georgescu
18 58 Adrian Georgescu
19 1 Redmine Admin
By using the current solution, the SIP Proxy administrator can decide whether ICE is allowed and which priority the MediaProxy candidate has on a per call basis. There is no need for deploying a TURN server anymore in order to support ICE negotiation between end-points.
20 1 Redmine Admin
21 58 Adrian Georgescu
The client needs to implement STUN and the latest ICE specification. "Blink":http://icanblink.com is a SIP client that is fully compliant with these requirements.
22 1 Redmine Admin
  
23 31 Adrian Georgescu
24 58 Adrian Georgescu
h2. Implementation
25 58 Adrian Georgescu
26 58 Adrian Georgescu
27 55 Adrian Georgescu
To circumvent the failure of ICE negotiation, MediaProxy module in OpenSIPS is now:
28 55 Adrian Georgescu
29 58 Adrian Georgescu
# Creating a proper candidate based on the media relay IP:port allocation
30 58 Adrian Georgescu
# Appending the candidate to the offer/answer of the SDP
31 58 Adrian Georgescu
# Allowing an administrator to set a policy about how to use the relay candidate
32 1 Redmine Admin
33 42 Redmine Admin
OpenSIPS mediaproxy module has new settings:
34 1 Redmine Admin
35 58 Adrian Georgescu
<pre>
36 1 Redmine Admin
ice_candidate="none"
37 1 Redmine Admin
ice_candidate_avp="$avp(s:ice_priority)"
38 58 Adrian Georgescu
</pre>
39 56 Adrian Georgescu
40 56 Adrian Georgescu
"ice-candidate" defines a global setting whereas "ice_candidate_avp" allows the user to override that value by setting the specified AVP. It can take 3 different values: "none", "low-priority" or "high-priority". None means no candidate will be added at all, and low-priority or high-priority affect on the priority field of the ICE candidate being inserted. Example:
41 56 Adrian Georgescu
42 58 Adrian Georgescu
<pre>
43 1 Redmine Admin
route {
44 1 Redmine Admin
    ...
45 1 Redmine Admin
    $avp(s:ice_candidate) := "low-priority";
46 1 Redmine Admin
    ...
47 1 Redmine Admin
}
48 58 Adrian Georgescu
</pre>
49 43 Adrian Georgescu
50 43 Adrian Georgescu
For the initial INVITE and its reply, mediaproxy module now appends an ICE candidate to the SDP as follows:
51 43 Adrian Georgescu
52 58 Adrian Georgescu
<pre>
53 1 Redmine Admin
if ((ice_candidate != none and ice_candidate_avp != none) 
54 1 Redmine Admin
        and SDP offer contains a=ice-pwd 
55 1 Redmine Admin
        and a=ice-ufrag and a=candidate line(s) then: 
56 1 Redmine Admin
	append to the SDP the following line:
57 1 Redmine Admin
	a=candidate:R(random string) 1 UDP PRIORITY MP_IP MP_PORT typ relay
58 42 Redmine Admin
        a=candidate:R(random string) 2 UDP PRIORITY MP_IP MP_RTCP_PORT typ relay
59 58 Adrian Georgescu
</pre>
60 25 Redmine Admin
61 1 Redmine Admin
where
62 12 Redmine Admin
63 58 Adrian Georgescu
* R(random string) = we'll use 'R' plus a random string as the foundation. The random string is the hex representation of the chosen relay IP address. Having the 'R' as the first letter is just a convention to represent a relayed candidate.
64 58 Adrian Georgescu
* PRIORITY = 2!^24 * POLICY + 2!^8  * 65535 + 2!^0  * 256 - Candidate ID (1 for RTP, 2 for RTCP)
65 58 Adrian Georgescu
**** POLICY = 0  if $avp(s:ice_candidate) == low-priority and POLICY = 130  if $avp(s:ice_candidate) == high-priority. A value of 130 is being used as the high priority candidate type preference, as it will be even higher than host candidates priority.
66 42 Redmine Admin
67 23 Adrian Georgescu
NOTE: The AVP has precedence over the module parameter, that is, if module parameter is set to low-priority and the AVP is set to none, no candidate will be added.
68 42 Redmine Admin
69 30 Adrian Georgescu
If ICE negotiation succeeds and the MediaProxy relay candidate has not been selected by the end-points, MediaProxy deallocates its ports after the built-in timeout and does not terminate the dialog in case of missing BYEs. MediaProxy decides this, if both SDP offer and answer have ICE support and if STUN binding requests (which correspond to ICE probing) have been detected while no RTP has been subsequently sent through the relay. 
70 30 Adrian Georgescu
71 34 Adrian Georgescu
72 58 Adrian Georgescu
h2. Software versions 
73 58 Adrian Georgescu
74 58 Adrian Georgescu
75 38 Adrian Georgescu
You need the following software versions to support ICE:
76 48 Adrian Georgescu
77 58 Adrian Georgescu
* MediaProxy version >=2.4.2
78 58 Adrian Georgescu
* OpenSIPS version >= 1.6.0
79 50 Adrian Georgescu
80 50 Adrian Georgescu
CDRTool version >=7.1.0 can be used to display the media traces.
81 38 Adrian Georgescu
82 1 Redmine Admin