<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2176/18/9/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/AST/SIP+Direct+Media+Reinvite+Glare+Avoidance">SIP Direct Media Reinvite Glare Avoidance</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~mmichelson">Mark Michelson</a>
</h4>
<br/>
<h4>Changes (1)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{warning} <br>This page is a work in progress. Please refrain from making comments on this page until this warning is removed. <br>{warning} <br> <br></td></tr>
<tr><td class="diff-unchanged" >h1. Overview <br> <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<h1><a name="SIPDirectMediaReinviteGlareAvoidance-Overview"></a>Overview</h1>
<p>When SIP endpoints communicate by way of Asterisk, Asterisk will attempt to send SIP reinvites in order to allow the endpoints to communicate directly. This allows for the computational load on the Asterisk server to be decreased while also lessening the latency of the media streams between the endpoints. Typical SIP traffic for a call might look like this: </p>
<table width="100%">
<tr>
<td align="left" >
<table>
<caption align="bottom">
</caption>
<tr>
<td>
<img style="border: none; width: 716px;"
usemap="#gliffy-map-21757955-5084"
src="/wiki/download/attachments/21463142/DirectMediaOneServer.png?version=4&modificationDate=1346271762860"
alt=""/>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>When multiple Asterisk servers are in the path between the endpoints, then both Asterisk servers will attempt to send direct media reinvites. If it happens to be that the two Asterisk servers direct their reinvites to each other at the same time, then each of the Asterisk servers will respond to the reinvites with 491 responses. After a delay, the downstream Asterisk server will attempt its reinvite again and succeed. A diagram of this situation looks like this:</p>
<table width="100%">
<tr>
<td align="left" >
<table>
<caption align="bottom">
</caption>
<tr>
<td>
<img style="border: none; width: 983px;"
usemap="#gliffy-map-21757961-9345"
src="/wiki/download/attachments/21463142/DirectMediaGlare.png?version=1&modificationDate=1346271744443"
alt=""/>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>The problematic area is higlighted in red. While this eventually results in direct media flowing between the endpoints, the delay between the 491 responses and the re-attempt at reinviting the media may be noticeable to the end users. If more than two Asterisk servers are in the path between callers, this delay can be longer. In Asterisk 11, a new option has been added to chan_sip in an attempt to address this.</p>
<h1><a name="SIPDirectMediaReinviteGlareAvoidance-%7B%7Bdirectmedia%3Doutgoing%7D%7D"></a><tt>directmedia = outgoing</tt></h1>
<p>The problem in the second diagram was that both Asterisk servers assumed control of the path between them. In reality, it is only required that one of the Asterisk servers does this. The <tt>outgoing</tt> setting for the <tt>directmedia</tt> option addresses this problem.</p>
<p>The way this option works is when the SIP channel driver is told by the RTP layer to send a direct media reinvite out, we check to see if the <tt>directmedia</tt> setting is set to <tt>outgoing</tt> for the dialog. If it is, and the call direction is not outgoing, then the SIP channel driver will refrain from sending a reinvite. After this first denial to send the direct media reinvite, the SIP channel driver will no longer refuse to send if the RTP layer requests it again. Here is a diagram showing how this works if Asterisk 2 has <tt>directmedia = outgoing</tt> set:</p>
<table width="100%">
<tr>
<td align="left" >
<table>
<caption align="bottom">
</caption>
<tr>
<td>
<img style="border: none; width: 983px;"
usemap="#gliffy-map-21757965-7868"
src="/wiki/download/attachments/21463142/DirectMediaNoGlare.png?version=1&modificationDate=1346272232464"
alt=""/>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>If Asterisk 1 also has <tt>directmedia</tt> set to <tt>outgoing</tt> then calls from Asterisk 2 to Asterisk 1 will also avoid reinvite glares.</p>
<h1><a name="SIPDirectMediaReinviteGlareAvoidance-Caveats"></a>Caveats</h1>
<p>Since this option is a new value accepted for the <tt>directmedia</tt> setting in <tt>sip.conf</tt>, this setting can be applied globally. This is almost assuredly not what you want to do. You should only ever set <tt>directmedia</tt> to <tt>outgoing</tt> on individual peers.</p>
<p>When choosing which peers to set this option on, you should be careful. It is best to only set this option on peers that are also under your control and that will also have this option set. For instance, if your setup has multiple peered Asterisk servers, then it is a great idea to use this option for those peers. If, on the other hand, you have had SIP reinvite glare issues with a SIP provider, then you should be hesitant to set this option without thoroughly testing with your provider first.</p>
<p>When setting <tt>directmedia = outgoing</tt> on your peered Asterisk servers, it is a good idea to set the option in the sip.conf file (or realtime storage) of all the Asterisk servers in question. This way calls can go from any Asterisk server to any other Asterisk server and glares will be prevented.</p>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/SIP+Direct+Media+Reinvite+Glare+Avoidance">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=21463142&revisedVersion=16&originalVersion=15">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/SIP+Direct+Media+Reinvite+Glare+Avoidance?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>