[asterisk-commits] oej: branch oej/sipchanstats r121592 - in /team/oej/sipchanstats: channels/ i...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 10 11:02:47 CDT 2008
Author: oej
Date: Tue Jun 10 11:02:46 2008
New Revision: 121592
URL: http://svn.digium.com/view/asterisk?view=rev&rev=121592
Log:
Add a first implementation of "sip show channelstats" to show some QoS statistics
about ongoing SIP calls.
Note: This is based on Asterisk 1.4 now.
Modified:
team/oej/sipchanstats/channels/chan_sip.c
team/oej/sipchanstats/include/asterisk/rtp.h
team/oej/sipchanstats/main/rtp.c
Modified: team/oej/sipchanstats/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/sipchanstats/channels/chan_sip.c?view=diff&rev=121592&r1=121591&r2=121592
==============================================================================
--- team/oej/sipchanstats/channels/chan_sip.c (original)
+++ team/oej/sipchanstats/channels/chan_sip.c Tue Jun 10 11:02:46 2008
@@ -1376,6 +1376,7 @@
static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions);
static int sip_show_channels(int fd, int argc, char *argv[]);
+static int sip_show_channelstats(int fd, int argc, char *argv[]);
static int sip_show_subscriptions(int fd, int argc, char *argv[]);
static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions);
static char *complete_sipch(const char *line, const char *word, int pos, int state);
@@ -10909,6 +10910,61 @@
#undef FORMAT3
}
+/*! \brief SIP show channelstats CLI (main function) */
+ /*Print some info on the call here */
+ //ast_verbose(" RTP-stats\n");
+ //ast_verbose("* Our Receiver:\n");
+ //ast_verbose(" SSRC: %u\n", rtp->themssrc);
+ //ast_verbose(" Received packets: %u\n", rtp->rxcount);
+ //ast_verbose(" Lost packets: %u\n", rtp->rtcp->expected_prior - rtp->rtcp->received_prior);
+ //ast_verbose(" Jitter: %.4f\n", rtp->rxjitter);
+ //ast_verbose(" Transit: %.4f\n", rtp->rxtransit);
+ //ast_verbose(" RR-count: %u\n", rtp->rtcp->rr_count);
+ //ast_verbose("* Our Sender:\n");
+ //ast_verbose(" SSRC: %u\n", rtp->ssrc);
+ //ast_verbose(" Sent packets: %u\n", rtp->txcount);
+ //ast_verbose(" Lost packets: %u\n", rtp->rtcp->reported_lost);
+ //ast_verbose(" Jitter: %u\n", rtp->rtcp->reported_jitter / (unsigned int)65536.0);
+ //ast_verbose(" SR-count: %u\n", rtp->rtcp->sr_count);
+ //ast_verbose(" RTT: %f\n", rtp->rtcp->rtt);
+
+static int sip_show_channelstats(int fd, int argc, char *argv[])
+{
+#define FORMAT2 "%-15.15s %-11.11s %-10.10s %-10.10s (%-2.2s) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n"
+#define FORMAT "%-15.15s %-11.11s %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u\n"
+ struct sip_pvt *cur;
+ int numchans = 0;
+
+ if (argc != 3)
+ return RESULT_SHOWUSAGE;
+ ast_mutex_lock(&iflock);
+ cur = iflist;
+ ast_cli(fd, FORMAT2, "Peer", "Call ID", "Recv: Pack", "Lost", "%", "Jitter", "Send: Pack", "Lost", "Jitter");
+ for (; cur && cur->rtp; cur = cur->next) {
+ unsigned int rxcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXCOUNT);
+ unsigned int txcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXCOUNT);
+ ast_cli(fd, FORMAT, ast_inet_ntoa(cur->sa.sin_addr),
+ cur->callid,
+ rxcount > (unsigned int) 100000 ? (unsigned int) (rxcount)/(unsigned int) 1000 : rxcount,
+ rxcount > (unsigned int) 100000 ? "K":" ",
+ ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS),
+ rxcount > ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS) ? (unsigned int) (ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS) / rxcount * 100) : 0,
+ ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXJITTER),
+ txcount > (unsigned int) 100000 ? (unsigned int) (txcount)/(unsigned int) 1000 : txcount,
+ txcount > (unsigned int) 100000 ? "K":" ",
+ ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS),
+ txcount > ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS) ? (unsigned int) (ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS)/ txcount * 100) : 0,
+ ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXJITTER)
+ );
+ numchans++;
+ }
+ ast_mutex_unlock(&iflock);
+ ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : "");
+ return RESULT_SUCCESS;
+#undef FORMAT
+#undef FORMAT2
+}
+
/*! \brief Support routine for 'sip show channel' CLI */
static char *complete_sipch(const char *line, const char *word, int pos, int state)
{
@@ -11702,6 +11758,10 @@
static char show_channels_usage[] =
"Usage: sip show channels\n"
" Lists all currently active SIP channels.\n";
+
+static char show_channelstats_usage[] =
+"Usage: sip show channelstats\n"
+" Lists all currently active SIP channel's RTCP statistics.\n";
static char show_channel_usage[] =
"Usage: sip show channel <channel>\n"
@@ -18038,6 +18098,10 @@
sip_show_channels, "List active SIP channels",
show_channels_usage },
+ { { "sip", "show", "channelstats", NULL },
+ sip_show_channelstats, "List active SIP channel statistics (based on RTCP)",
+ show_channelstats_usage },
+
{ { "sip", "show", "domains", NULL },
sip_show_domains, "List our local SIP domains.",
show_domains_usage },
Modified: team/oej/sipchanstats/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/team/oej/sipchanstats/include/asterisk/rtp.h?view=diff&rev=121592&r1=121591&r2=121592
==============================================================================
--- team/oej/sipchanstats/include/asterisk/rtp.h (original)
+++ team/oej/sipchanstats/include/asterisk/rtp.h Tue Jun 10 11:02:46 2008
@@ -61,6 +61,17 @@
AST_RTP_TRY_PARTIAL,
/*! RTP structure exists and native bridge can occur */
AST_RTP_TRY_NATIVE,
+};
+
+/*! \brief Variables used in ast_rtcp_get function */
+enum ast_rtp_qos_vars {
+ AST_RTP_TXCOUNT,
+ AST_RTP_RXCOUNT,
+ AST_RTP_TXJITTER,
+ AST_RTP_RXJITTER,
+ AST_RTP_RXPLOSS,
+ AST_RTP_TXPLOSS,
+ AST_RTP_RTT
};
struct ast_rtp;
@@ -227,6 +238,9 @@
/*! \brief Return RTCP quality string */
char *ast_rtp_get_quality(struct ast_rtp *rtp, struct ast_rtp_quality *qual);
+
+/*! \brief Return RTP and RTCP QoS values */
+unsigned int ast_rtp_get_qosvalue(struct ast_rtp *rtp, enum ast_rtp_qos_vars value);
/*! \brief Send an H.261 fast update request. Some devices need this rather than the XML message in SIP */
int ast_rtcp_send_h261fur(void *data);
Modified: team/oej/sipchanstats/main/rtp.c
URL: http://svn.digium.com/view/asterisk/team/oej/sipchanstats/main/rtp.c?view=diff&rev=121592&r1=121591&r2=121592
==============================================================================
--- team/oej/sipchanstats/main/rtp.c (original)
+++ team/oej/sipchanstats/main/rtp.c Tue Jun 10 11:02:46 2008
@@ -2075,6 +2075,27 @@
rtp->dtmfsamples = 0;
rtp->seqno = 0;
rtp->rxseqno = 0;
+}
+
+unsigned int ast_rtp_get_qosvalue(struct ast_rtp *rtp, enum ast_rtp_qos_vars value)
+{
+ switch (value) {
+ case AST_RTP_TXCOUNT:
+ return rtp->txcount;
+ case AST_RTP_RXCOUNT:
+ return rtp->rxcount;
+ case AST_RTP_TXJITTER:
+ return (unsigned int) (rtp->rxjitter * 100.0);
+ case AST_RTP_RXJITTER:
+ return (unsigned int) (rtp->rtcp->reported_jitter / (unsigned int) 65536.0);
+ case AST_RTP_RXPLOSS:
+ return (rtp->rtcp->expected_prior - rtp->rtcp->received_prior);
+ case AST_RTP_TXPLOSS:
+ return rtp->rtcp->reported_lost;
+ case AST_RTP_RTT:
+ return (unsigned int) rtp->rtcp->rtt * 100;
+ }
+ return 0; /* To make the compiler happy */
}
char *ast_rtp_get_quality(struct ast_rtp *rtp, struct ast_rtp_quality *qual)
More information about the asterisk-commits
mailing list