<!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, "sip_gateway_name"))) {
+                gateway_ptr = sofia_reg_find_gateway(gateway_name);
+        }
+        
</ins><span class="cx">         switch_mutex_lock(tech_pvt->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->profile->ib_failed_calls++;
</span><span class="cx">                 }
</span><ins>+                
+                if (gateway_ptr) {
+                        if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
+                                gateway_ptr->ob_failed_calls++;
+                        } else {
+                                gateway_ptr->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, "sip_ignore_remote_cause")) && 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 > 0) {
</span><span class="cx">                 if (argc == 1) {
</span><del>-                        stream->write_function(stream, "Invalid Syntax!\n");
</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->write_function(stream, "%25s\t%32s\t%s\t%s\t%s\n", "Profile::Gateway-Name", " Data ", "State", "IB Calls(F/T)", "OB Calls(F/T)");
+                        stream->write_function(stream, "%s\n", 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, &vvar, NULL, &val);
+                                profile = (sofia_profile_t *) val;
+                                if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
+
+                                        if (!strcmp(vvar, profile->name)) { /* not an alias */
+                                                for (gp = profile->gateways; gp; gp = gp->next) {
+                                                        char *pkey = switch_mprintf("%s::%s", profile->name, gp->name);
+
+                                                        switch_assert(gp->state < REG_STATE_LAST);
+
+                                                        c++;
+                                                        ib_failed += gp->ib_failed_calls;
+                                                        ib += gp->ib_calls;
+                                                        ob_failed += gp->ob_failed_calls;
+                                                        ob += gp->ob_calls;
+
+                                                        stream->write_function(stream, "%25s\t%32s\t%s\t%ld/%ld\t%ld/%ld",
+                                                                pkey, gp->register_to, sofia_state_names[gp->state],
+                                                                gp->ib_failed_calls, gp->ib_calls, gp->ob_failed_calls, gp->ob_calls);
+
+                                                        if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
+                                                                time_t now = switch_epoch_time_now(NULL);
+                                                                if (gp->retry > now) {
+                                                                        stream->write_function(stream, " (retry: %ds)", gp->retry - now);
+                                                                } else {
+                                                                        stream->write_function(stream, " (retry: NEVER)");
+                                                                }
+                                                        }
+                                                        stream->write_function(stream, "\n");
+                                                }
+                                        }
+                                }
+                        }
+                        switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+                        stream->write_function(stream, "%s\n", line);
+                        stream->write_function(stream, "%d gateway%s: Inound(Failed/Total): %ld/%ld,"
+                                "Outbound(Failed/Total):%ld/%ld\n", c, c == 1 ? "" : "s",
+                                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->write_function(stream, "Status \t%s%s\n", status_names[gp->status], gp->pinging ? " (ping)" : "");
</span><span class="cx">                                 stream->write_function(stream, "CallsIN \t%d\n", gp->ib_calls);
</span><span class="cx">                                 stream->write_function(stream, "CallsOUT\t%d\n", gp->ob_calls);
</span><ins>+                                stream->write_function(stream, "FailedCallsIN\t%d\n", gp->ib_failed_calls);
+                                stream->write_function(stream, "FailedCallsOUT\t%d\n", gp->ob_failed_calls);
</ins><span class="cx">                                 stream->write_function(stream, "%s\n", 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 > 0) {
</span><span class="cx">                 if (argc == 1) {
</span><del>-                        stream->write_function(stream, "Invalid Syntax!\n");
</del><ins>+                         /* show summary of all gateways */
+
+                         stream->write_function(stream, "%s\n", header);
+                         stream->write_function(stream, "<gateways>\n", 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, &vvar, NULL, &val);
+                                 profile = (sofia_profile_t *) val;
+                                 if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
+
+                                         if (!strcmp(vvar, profile->name)) { /* not an alias */
+                                                 for (gp = profile->gateways; gp; gp = gp->next) {
+                                                         switch_assert(gp->state < REG_STATE_LAST);
+                                                         
+                                                         stream->write_function(stream, "\t<gateway>\n");
+                                                         stream->write_function(stream, "\t\t<profile>%s</profile>\n", profile->name);
+                                                         stream->write_function(stream, "\t\t<to>%s</to>\n", gp->register_to);
+                                                         stream->write_function(stream, "\t\t<state>%s</state>\n", sofia_state_names[gp->state]);
+                                                         stream->write_function(stream, "\t\t<calls-in>%ld</calls-in>\n", gp->ib_calls);
+                                                         stream->write_function(stream, "\t\t<calls-out>%ld</calls-out>\n", gp->ob_calls);
+                                                         stream->write_function(stream, "\t\t<failed-calls-in>%ld</failed-calls-in>\n", gp->ib_failed_calls);
+                                                         stream->write_function(stream, "\t\t<failed-calls-out>%ld</failed-calls-out>\n", gp->ob_failed_calls);
+
+                                                         if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
+                                                                 time_t now = switch_epoch_time_now(NULL);
+                                                                 if (gp->retry > now) {
+                                                                         stream->write_function(stream, "\t\t<retry>%ds</retry>\n", gp->retry - now);
+                                                                 } else {
+                                                                         stream->write_function(stream, "\t\t<retry>NEVER</retry>\n");
+                                                                 }
+                                                         }
+                                                         stream->write_function(stream, "\t</gateway>\n");
+                                                 }
+                                         }
+                                 }
+                         }
+                         switch_mutex_unlock(mod_sofia_globals.hash_mutex);                         
+                         stream->write_function(stream, "</gateways>\n");
+
</ins><span class="cx">                         return SWITCH_STATUS_SUCCESS;
</span><span class="cx">                 }
</span><span class="cx">                 if (!strcasecmp(argv[0], "gateway")) {
</span><span class="lines">@@ -2440,7 +2548,8 @@
</span><span class="cx">                                 stream->write_function(stream, " <status>%s%s</status>\n", status_names[gp->status], gp->pinging ? " (ping)" : "");
</span><span class="cx">                                 stream->write_function(stream, " <calls-in>%d</calls-in>\n", gp->ib_calls);
</span><span class="cx">                                 stream->write_function(stream, " <calls-out>%d</calls-out>\n", gp->ob_calls);
</span><del>-
</del><ins>+                                stream->write_function(stream, " <failed-calls-in>%d</calls-in>\n", gp->ib_failed_calls);
+                                stream->write_function(stream, " <failed-calls-out>%d</calls-out>\n", gp->ob_failed_calls);
</ins><span class="cx">                                 stream->write_function(stream, " </gateway>\n");
</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->status != SOFIA_GATEWAY_UP) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Gateway is down!\n");
</span><span class="cx">                         cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
</span><ins>+                        gateway_ptr->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->transport = sofia_glue_str2transport(tp_param);
</span><span class="cx">                                 if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN) {
</span><span class="cx">                                         cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
</span><ins>+                                        gateway_ptr->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->ping_max = 0;
</span><span class="cx">                         gateway->ping_min = 0;
</span><span class="cx">                         gateway->ping_count = 0;
</span><ins>+                        gateway->ib_calls = 0;
+                        gateway->ob_calls = 0;
+                        gateway->ib_failed_calls = 0;
+                        gateway->ob_failed_calls = 0;
</ins><span class="cx">
</span><span class="cx">                         if ((x_params = switch_xml_child(gateway_tag, "variables"))) {
</span><span class="cx">                                 param = switch_xml_child(x_params, "variable");
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>