<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/en/2176/18/9/_/styles/combined.css?spaceKey=AST&amp;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 (3)</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;">{gliffy:name=DirectMediaNoGlare|align=left|size=L|version=1} <br></td></tr>
            <tr><td class="diff-unchanged" >{warning} <br>This page is a work in progress. Please refrain from making comments on this page until this warning is removed. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >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. This is where the {{directmedia = outgoing}} setting becomes useful. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >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 <span class="diff-changed-words"><span class="diff-added-chars"style="background-color: #dfd;">{{</span>directmedia<span class="diff-added-chars"style="background-color: #dfd;">}}</span></span> setting is set to outgoing for the dialog. If it is, and the call direction is not outgoing, then we will refrain from sending a reinvite. After this first denial to send the direct media reinvite, we 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 {{directmedia = outgoing}} set: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;"> <br>{gliffy:name=DirectMediaNoGlare|align=left|size=L|version=1} <br> <br>h1. Caveats <br> <br>Since this option is a new value accepted for the {{directmedia}} setting in {{sip.conf}}, this setting can be applied globally. This is almost assuredly not what you want to do. You should only ever set {{directmedia}} to {{outgoing}} on individual peers. <br> <br>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 the 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. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>This page is a work in progress. Please refrain from making comments on this page until this warning is removed.</td></tr></table></div>

<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. A typical situation 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-5817"
                                                          src="/wiki/download/attachments/21463142/DirectMediaOneServer.png?version=4&amp;modificationDate=1346271762860"
                             alt=""/>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>




<p>When multiple Asterisk servers exist 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 this time. 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-8305"
                                                          src="/wiki/download/attachments/21463142/DirectMediaGlare.png?version=1&amp;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 user. 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. This is where the <tt>directmedia = outgoing</tt> setting becomes useful.</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 outgoing for the dialog. If it is, and the call direction is not outgoing, then we will refrain from sending a reinvite. After this first denial to send the direct media reinvite, we 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-1549"
                                                          src="/wiki/download/attachments/21463142/DirectMediaNoGlare.png?version=1&amp;modificationDate=1346272232464"
                             alt=""/>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>




<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 the 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.</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=13&originalVersion=12">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/AST/SIP+Direct+Media+Reinvite+Glare+Avoidance?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>