« Previous - Version 25/61 (diff) - Next » - Current version
Anonymous, 02/11/2010 01:46 pm

= ICE negotiation through OpenSIPS/Mediaproxy =


ICE negotiation is used to solve the NAT traversal issue of RTP media as much as possible in the SIP end-points. Where the topology does not allow, a TURN server has been standardized to provide end-points with a visible public presence that can be used to relay traffic to SIP 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.

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.

MediaProxy module rewrites the SDP in order to present to the destination SIP User Agent a reachable IP:port number for sending RTP/RTCP. This has the dis-advantage that is always using a relay and is mutually exclusive with the use of ICE. The rewriting of the SDP and the missing candiate correspondent to the c= line of the SDP causes the target SIP end-point to reply with ICE missmatch and the ICE negotiation fails in its tracks.


To circumvent the failure of ICE negotiation, mediaproxy module must:

  • Create a proper candidate based on the media relay IP:port allocation
  • Append the candidate to the offer/answer of the SDP
  • Allow an administrator to set a policy about when to use of the relay candidate
  • Solve the accounting issues and BYE sending depending on the use of ICE

Add a new setting to mediaproxy module:


Add new setting (flag) to mediaproxy module:

This will override default module parameter, if it's not set to none.

For the initial INVITE and its reply append an ICE candidate to the SDP as follows:

if mediaproxy_ice_candidate != none and SDP offer contains ice-offer (has a=candidate line(s)) then
append to the SDP the following line:
a=candidate:R 1 UDP PRIORITY MP_IP MP_PORT typ relay
a=candidate:R 2 UDP PRIORITY MP_IP MP_RTCP_PORT typ relay


  • R (foundation) = we'll use 'R' to represent we are emulating a relayed candidate
  • PRIORITY = 2!^24 * POLICY + 2!^8 * 65535 + 2!^0 * 256 - Candidate ID (1 for RTP, 2 for RTCP) * POLICY = 0 if mediaproxy_ice_candidate = low and POLICY = 126 if mediaproxy_ice_candidate = high * Policy value can be altered arbitrarily by setting the ice_priority AVP to none/low/high

Once the ICE negotiation is completed and the IP selected for media differs from what it has been indicated in the c= line of the original INVITE, a re-INVITE initiated by the controlling (in the sense of ICE) agent indicates this fact. The re-INVITE contains the selected candidate in the c= line. Mediaproxy module should analyze this re-INVITE (or the lack thereof) and figure out whether the relay IP:port has been chosen for the RTP media. If the answer is negative than MediaProxy should deallocate its ports and cancel subsequent actions related to the accounting and dialog terminating purposes.

ICE standard mandates that the re-INVITE is required only if the IP in the c= line differs from the IP selected by ICE negotiation. This means that if two hosts decide to use the local IP in c= line and they can use those IPs to communicate with each other then no re-invite will be sent out. In this case the SIP Proxy does not have an indication if ICE has been successful or not. MediaProxy can in this case decide on its own that the end-points selected another candidate than the relay based on the fact that after the initial exchange of STUN packets via the mediaproxy, not further RTP packets followed.