<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][17395] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=17395">17395</a></dd>
<dt>Author</dt> <dd>mike</dd>
<dt>Date</dt> <dd>2010-04-26 03:14:57 -0500 (Mon, 26 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>mod_sofia: add failed call statistics to gateways (<a href="http://jira.freeswitch.org/browse/MODENDP-238">MODENDP-238</a>)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (17394 => 17395)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2010-04-26 07:21:41 UTC (rev 17394)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2010-04-26 08:14:57 UTC (rev 17395)
</span><span class="lines">@@ -392,7 +392,13 @@
</span><span class="cx">         switch_call_cause_t cause = switch_channel_get_cause(channel);
</span><span class="cx">         int sip_cause = hangup_cause_to_sip(cause);
</span><span class="cx">         const char *ps_cause = NULL, *use_my_cause;
</span><ins>+        const char *gateway_name = NULL;
+        sofia_gateway_t *gateway_ptr = NULL;
</ins><span class="cx"> 
</span><ins>+        if ((gateway_name = switch_channel_get_variable(channel, &quot;sip_gateway_name&quot;))) {
+                gateway_ptr = sofia_reg_find_gateway(gateway_name);
+        }
+        
</ins><span class="cx">         switch_mutex_lock(tech_pvt-&gt;sofia_mutex);
</span><span class="cx"> 
</span><span class="cx">         sofia_clear_flag(tech_pvt, TFLAG_RECOVERING);
</span><span class="lines">@@ -405,7 +411,19 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         tech_pvt-&gt;profile-&gt;ib_failed_calls++;
</span><span class="cx">                 }
</span><ins>+                
+                if (gateway_ptr) {
+                        if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
+                                gateway_ptr-&gt;ob_failed_calls++;
+                        } else {
+                                gateway_ptr-&gt;ib_failed_calls++;
+                        }
+                }                
</ins><span class="cx">         }
</span><ins>+        
+        if (gateway_ptr) {
+                sofia_reg_release_gateway(gateway_ptr);
+        }
</ins><span class="cx"> 
</span><span class="cx">         if (!((use_my_cause = switch_channel_get_variable(channel, &quot;sip_ignore_remote_cause&quot;)) &amp;&amp; switch_true(use_my_cause))) {
</span><span class="cx">                 ps_cause = switch_channel_get_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE);
</span><span class="lines">@@ -2175,7 +2193,56 @@
</span><span class="cx"> 
</span><span class="cx">         if (argc &gt; 0) {
</span><span class="cx">                 if (argc == 1) {
</span><del>-                        stream-&gt;write_function(stream, &quot;Invalid Syntax!\n&quot;);
</del><ins>+                        /* show summary of all gateways*/
+
+                        uint32_t ib_failed = 0;
+                        uint32_t ib = 0;
+                        uint32_t ob_failed = 0;
+                        uint32_t ob = 0;
+
+                        stream-&gt;write_function(stream, &quot;%25s\t%32s\t%s\t%s\t%s\n&quot;, &quot;Profile::Gateway-Name&quot;, &quot;    Data    &quot;, &quot;State&quot;, &quot;IB Calls(F/T)&quot;, &quot;OB Calls(F/T)&quot;);
+                        stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
+                        switch_mutex_lock(mod_sofia_globals.hash_mutex);
+                        for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+                                switch_hash_this(hi, &amp;vvar, NULL, &amp;val);
+                                profile = (sofia_profile_t *) val;
+                                if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
+
+                                        if (!strcmp(vvar, profile-&gt;name)) { /* not an alias */
+                                                for (gp = profile-&gt;gateways; gp; gp = gp-&gt;next) {
+                                                        char *pkey = switch_mprintf(&quot;%s::%s&quot;, profile-&gt;name, gp-&gt;name);
+
+                                                        switch_assert(gp-&gt;state &lt; REG_STATE_LAST);
+
+                                                        c++;
+                                                        ib_failed += gp-&gt;ib_failed_calls;
+                                                        ib += gp-&gt;ib_calls;
+                                                        ob_failed += gp-&gt;ob_failed_calls;
+                                                        ob += gp-&gt;ob_calls;
+
+                                                        stream-&gt;write_function(stream, &quot;%25s\t%32s\t%s\t%ld/%ld\t%ld/%ld&quot;, 
+                                                                pkey, gp-&gt;register_to, sofia_state_names[gp-&gt;state],
+                                                                gp-&gt;ib_failed_calls, gp-&gt;ib_calls, gp-&gt;ob_failed_calls, gp-&gt;ob_calls);
+
+                                                        if (gp-&gt;state == REG_STATE_FAILED || gp-&gt;state == REG_STATE_TRYING) {
+                                                                time_t now = switch_epoch_time_now(NULL);
+                                                                if (gp-&gt;retry &gt; now) {
+                                                                        stream-&gt;write_function(stream, &quot; (retry: %ds)&quot;, gp-&gt;retry - now);
+                                                                } else {
+                                                                        stream-&gt;write_function(stream, &quot; (retry: NEVER)&quot;);
+                                                                }
+                                                        }
+                                                        stream-&gt;write_function(stream, &quot;\n&quot;);
+                                                }
+                                        }
+                                }
+                        }
+                        switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+                        stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
+                        stream-&gt;write_function(stream, &quot;%d gateway%s: Inound(Failed/Total): %ld/%ld,&quot;
+                                &quot;Outbound(Failed/Total):%ld/%ld\n&quot;, c, c == 1 ? &quot;&quot; : &quot;s&quot;,
+                                ib_failed, ib, ob_failed, ob);
+
</ins><span class="cx">                         return SWITCH_STATUS_SUCCESS;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -2205,6 +2272,8 @@
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;Status  \t%s%s\n&quot;, status_names[gp-&gt;status], gp-&gt;pinging ? &quot; (ping)&quot; : &quot;&quot;);
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;CallsIN \t%d\n&quot;, gp-&gt;ib_calls);
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;CallsOUT\t%d\n&quot;, gp-&gt;ob_calls);
</span><ins>+                                stream-&gt;write_function(stream, &quot;FailedCallsIN\t%d\n&quot;, gp-&gt;ib_failed_calls);
+                                stream-&gt;write_function(stream, &quot;FailedCallsOUT\t%d\n&quot;, gp-&gt;ob_failed_calls);
</ins><span class="cx">                                 stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
</span><span class="cx">                                 sofia_reg_release_gateway(gp);
</span><span class="cx">                         } else {
</span><span class="lines">@@ -2412,7 +2481,46 @@
</span><span class="cx"> 
</span><span class="cx">         if (argc &gt; 0) {
</span><span class="cx">                 if (argc == 1) {
</span><del>-                        stream-&gt;write_function(stream, &quot;Invalid Syntax!\n&quot;);
</del><ins>+                         /* show summary of all gateways */
+
+                         stream-&gt;write_function(stream, &quot;%s\n&quot;, header);
+                         stream-&gt;write_function(stream, &quot;&lt;gateways&gt;\n&quot;, header);
+                         
+                         switch_mutex_lock(mod_sofia_globals.hash_mutex);
+                         for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+                                 switch_hash_this(hi, &amp;vvar, NULL, &amp;val);
+                                 profile = (sofia_profile_t *) val;
+                                 if (sofia_test_pflag(profile, PFLAG_RUNNING)) {

+                                         if (!strcmp(vvar, profile-&gt;name)) { /* not an alias */
+                                                 for (gp = profile-&gt;gateways; gp; gp = gp-&gt;next) {
+                                                         switch_assert(gp-&gt;state &lt; REG_STATE_LAST);
+                                                         
+                                                         stream-&gt;write_function(stream, &quot;\t&lt;gateway&gt;\n&quot;);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;profile&gt;%s&lt;/profile&gt;\n&quot;, profile-&gt;name);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;to&gt;%s&lt;/to&gt;\n&quot;, gp-&gt;register_to);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;state&gt;%s&lt;/state&gt;\n&quot;, sofia_state_names[gp-&gt;state]);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;calls-in&gt;%ld&lt;/calls-in&gt;\n&quot;, gp-&gt;ib_calls);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;calls-out&gt;%ld&lt;/calls-out&gt;\n&quot;, gp-&gt;ob_calls);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;failed-calls-in&gt;%ld&lt;/failed-calls-in&gt;\n&quot;, gp-&gt;ib_failed_calls);
+                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;failed-calls-out&gt;%ld&lt;/failed-calls-out&gt;\n&quot;, gp-&gt;ob_failed_calls);

+                                                         if (gp-&gt;state == REG_STATE_FAILED || gp-&gt;state == REG_STATE_TRYING) {
+                                                                 time_t now = switch_epoch_time_now(NULL);
+                                                                 if (gp-&gt;retry &gt; now) {
+                                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;retry&gt;%ds&lt;/retry&gt;\n&quot;, gp-&gt;retry - now);
+                                                                 } else {
+                                                                         stream-&gt;write_function(stream, &quot;\t\t&lt;retry&gt;NEVER&lt;/retry&gt;\n&quot;);
+                                                                 }
+                                                         }
+                                                         stream-&gt;write_function(stream, &quot;\t&lt;/gateway&gt;\n&quot;);
+                                                 }
+                                         }
+                                 }
+                         }
+                         switch_mutex_unlock(mod_sofia_globals.hash_mutex);                         
+                         stream-&gt;write_function(stream, &quot;&lt;/gateways&gt;\n&quot;);
+
</ins><span class="cx">                         return SWITCH_STATUS_SUCCESS;
</span><span class="cx">                 }
</span><span class="cx">                 if (!strcasecmp(argv[0], &quot;gateway&quot;)) {
</span><span class="lines">@@ -2440,7 +2548,8 @@
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;    &lt;status&gt;%s%s&lt;/status&gt;\n&quot;, status_names[gp-&gt;status], gp-&gt;pinging ? &quot; (ping)&quot; : &quot;&quot;);
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;    &lt;calls-in&gt;%d&lt;/calls-in&gt;\n&quot;, gp-&gt;ib_calls);
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;    &lt;calls-out&gt;%d&lt;/calls-out&gt;\n&quot;, gp-&gt;ob_calls);
</span><del>-
</del><ins>+                                stream-&gt;write_function(stream, &quot;    &lt;failed-calls-in&gt;%d&lt;/calls-in&gt;\n&quot;, gp-&gt;ib_failed_calls);
+                                stream-&gt;write_function(stream, &quot;    &lt;failed-calls-out&gt;%d&lt;/calls-out&gt;\n&quot;, gp-&gt;ob_failed_calls);
</ins><span class="cx">                                 stream-&gt;write_function(stream, &quot;  &lt;/gateway&gt;\n&quot;);
</span><span class="cx">                                 sofia_reg_release_gateway(gp);
</span><span class="cx">                         } else {
</span><span class="lines">@@ -3255,6 +3364,7 @@
</span><span class="cx">                 if (gateway_ptr-&gt;status != SOFIA_GATEWAY_UP) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Gateway is down!\n&quot;);
</span><span class="cx">                         cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
</span><ins>+                        gateway_ptr-&gt;ob_failed_calls++;
</ins><span class="cx">                         sofia_reg_release_gateway(gateway_ptr);
</span><span class="cx">                         gateway_ptr = NULL;
</span><span class="cx">                         goto error;
</span><span class="lines">@@ -3280,6 +3390,7 @@
</span><span class="cx">                                 tech_pvt-&gt;transport = sofia_glue_str2transport(tp_param);
</span><span class="cx">                                 if (tech_pvt-&gt;transport == SOFIA_TRANSPORT_UNKNOWN) {
</span><span class="cx">                                         cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
</span><ins>+                                        gateway_ptr-&gt;ob_failed_calls++;
</ins><span class="cx">                                         goto error;
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (17394 => 17395)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-04-26 07:21:41 UTC (rev 17394)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-04-26 08:14:57 UTC (rev 17395)
</span><span class="lines">@@ -402,6 +402,8 @@
</span><span class="cx">         switch_event_t *ob_vars;
</span><span class="cx">         uint32_t ib_calls;
</span><span class="cx">         uint32_t ob_calls;
</span><ins>+        uint32_t ib_failed_calls;
+        uint32_t ob_failed_calls;
</ins><span class="cx">         char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
</span><span class="cx">         int failures;
</span><span class="cx">         struct sofia_gateway *next;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (17394 => 17395)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-04-26 07:21:41 UTC (rev 17394)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-04-26 08:14:57 UTC (rev 17395)
</span><span class="lines">@@ -1758,6 +1758,10 @@
</span><span class="cx">                         gateway-&gt;ping_max = 0;
</span><span class="cx">                         gateway-&gt;ping_min = 0;
</span><span class="cx">                         gateway-&gt;ping_count = 0;
</span><ins>+                        gateway-&gt;ib_calls = 0;
+                        gateway-&gt;ob_calls = 0;
+                        gateway-&gt;ib_failed_calls = 0;
+                        gateway-&gt;ob_failed_calls = 0;
</ins><span class="cx"> 
</span><span class="cx">                         if ((x_params = switch_xml_child(gateway_tag, &quot;variables&quot;))) {
</span><span class="cx">                                 param = switch_xml_child(x_params, &quot;variable&quot;);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>