Add manager events for RTCP statistics.
authorJason Parker <jparker@digium.com>
Thu, 21 Jun 2007 23:07:20 +0000 (23:07 +0000)
committerJason Parker <jparker@digium.com>
Thu, 21 Jun 2007 23:07:20 +0000 (23:07 +0000)
Also adds a new "reporting" permission for manager, since it can be incredibly spammy.
  This permission was discussed on the -dev mailing list some months back.

Issue 8613, patch by johann8384, with some minor changes by me.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@70961 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configs/manager.conf.sample
include/asterisk/manager.h
main/manager.c
main/rtp.c

index 93657fd..dceec13 100644 (file)
@@ -71,5 +71,5 @@ bindaddr = 0.0.0.0
 ;displayconnects = yes ; Display on CLI user login/logoff
 ;
 ; Authorization for various classes 
 ;displayconnects = yes ; Display on CLI user login/logoff
 ;
 ; Authorization for various classes 
-;read = system,call,log,verbose,command,agent,user,config,dtmf
-;write = system,call,log,verbose,command,agent,user,config,dtmf
+;read = system,call,log,verbose,command,agent,user,config,dtmf,reporting
+;write = system,call,log,verbose,command,agent,user,config,dtmf,reporting
index 1cbfb5d..0a77697 100644 (file)
@@ -61,7 +61,7 @@
 #define EVENT_FLAG_USER                 (1 << 6) /* Ability to read/set user info */
 #define EVENT_FLAG_CONFIG              (1 << 7) /* Ability to modify configurations */
 #define EVENT_FLAG_DTMF                (1 << 8) /* Ability to read DTMF events */
 #define EVENT_FLAG_USER                 (1 << 6) /* Ability to read/set user info */
 #define EVENT_FLAG_CONFIG              (1 << 7) /* Ability to modify configurations */
 #define EVENT_FLAG_DTMF                (1 << 8) /* Ability to read DTMF events */
-
+#define EVENT_FLAG_REPORTING           (1 << 9) /* Reporting events such as rtcp sent */
 /* Export manager structures */
 #define AST_MAX_MANHEADERS 128
 
 /* Export manager structures */
 #define AST_MAX_MANHEADERS 128
 
index 0124005..c6b36ca 100644 (file)
@@ -317,6 +317,7 @@ static struct permalias {
        { EVENT_FLAG_USER, "user" },
        { EVENT_FLAG_CONFIG, "config" },
        { EVENT_FLAG_DTMF, "dtmf" },
        { EVENT_FLAG_USER, "user" },
        { EVENT_FLAG_CONFIG, "config" },
        { EVENT_FLAG_DTMF, "dtmf" },
+       { EVENT_FLAG_REPORTING, "reporting" },
        { -1, "all" },
        { 0, "none" },
 };
        { -1, "all" },
        { 0, "none" },
 };
index f3e0ccb..de2308e 100644 (file)
@@ -55,6 +55,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/utils.h"
 #include "asterisk/netsock.h"
 #include "asterisk/cli.h"
 #include "asterisk/utils.h"
 #include "asterisk/netsock.h"
 #include "asterisk/cli.h"
+#include "asterisk/manager.h"
 #include "asterisk/unaligned.h"
 #include "asterisk/utils.h"
 
 #include "asterisk/unaligned.h"
 #include "asterisk/utils.h"
 
@@ -1037,6 +1038,56 @@ struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
                                if (rtt)
                                        ast_verbose("  RTT: %lu(sec)\n", (unsigned long) rtt);
                        }
                                if (rtt)
                                        ast_verbose("  RTT: %lu(sec)\n", (unsigned long) rtt);
                        }
+                       if (rtt) {
+                               manager_event(EVENT_FLAG_REPORTING, "RTCPReceived", "From %s:%d\r\n"
+                                                                   "PT: %d(%s)\r\n"
+                                                                   "ReceptionReports: %d\r\n"
+                                                                   "SenderSSRC: %u\r\n"
+                                                                   "FractionLost: %ld\r\n"
+                                                                   "PacketsLost: %d\r\n"
+                                                                   "HighestSequence: %ld\r\n"
+                                                                   "SequenceNumberCycles: %ld\r\n"
+                                                                   "IAJitter: %u\r\n"
+                                                                   "LastSR: %lu.%010lu\r\n"
+                                                                   "DLSR: %4.4f(sec)\r\n"
+                                                                   "RTT: %lu(sec)\r\n",
+                                                                   ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port),
+                                                                   pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown",
+                                                                   rc,
+                                                                   rtcpheader[i + 1],
+                                                                   (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24),
+                                                                   rtp->rtcp->reported_lost,
+                                                                   (long) (ntohl(rtcpheader[i + 2]) & 0xffff),
+                                                                   (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16,
+                                                                   rtp->rtcp->reported_jitter,
+                                                                   (unsigned long) ntohl(rtcpheader[i + 4]) >> 16, ((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096,
+                                                                   ntohl(rtcpheader[i + 5])/65536.0,
+                                                                   rtt);
+                       } else {
+                               manager_event(EVENT_FLAG_REPORTING, "RTCPReceived", "From %s:%d\r\n"
+                                                                   "PT: %d(%s)\r\n"
+                                                                   "ReceptionReports: %d\r\n"
+                                                                   "SenderSSRC: %u\r\n"
+                                                                   "FractionLost: %ld\r\n"
+                                                                   "PacketsLost: %d\r\n"
+                                                                   "HighestSequence: %ld\r\n"
+                                                                   "SequenceNumberCycles: %ld\r\n"
+                                                                   "IAJitter: %u\r\n"
+                                                                   "LastSR: %lu.%010lu\r\n"
+                                                                   "DLSR: %4.4f(sec)\r\n",
+                                                                   ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port),
+                                                                   pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown",
+                                                                   rc,
+                                                                   rtcpheader[i + 1],
+                                                                   (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24),
+                                                                   rtp->rtcp->reported_lost,
+                                                                   (long) (ntohl(rtcpheader[i + 2]) & 0xffff),
+                                                                   (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16,
+                                                                   rtp->rtcp->reported_jitter,
+                                                                   (unsigned long) ntohl(rtcpheader[i + 4]) >> 16,
+                                                                   ((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096,
+                                                                   ntohl(rtcpheader[i + 5])/65536.0);
+                       }
                        break;
                case RTCP_PT_FUR:
                        if (rtcp_debug_test_addr(&sin))
                        break;
                case RTCP_PT_FUR:
                        if (rtcp_debug_test_addr(&sin))
@@ -2200,6 +2251,30 @@ void ast_rtp_destroy(struct ast_rtp *rtp)
                ast_verbose("  RTT:              %f\n", rtp->rtcp->rtt);
        }
 
                ast_verbose("  RTT:              %f\n", rtp->rtcp->rtt);
        }
 
+       manager_event(EVENT_FLAG_REPORTING, "RTPReceiverStat", "SSRC: %u\r\n"
+                                           "ReceivedPackets: %u\r\n"
+                                           "LostPackets: %u\r\n"
+                                           "Jitter: %.4f\r\n"
+                                           "Transit: %.4f\r\n"
+                                           "RRCount: %u\r\n",
+                                           rtp->themssrc,
+                                           rtp->rxcount,
+                                           rtp->rtcp->expected_prior - rtp->rtcp->received_prior,
+                                           rtp->rxjitter,
+                                           rtp->rxtransit,
+                                           rtp->rtcp->rr_count);
+       manager_event(EVENT_FLAG_REPORTING, "RTPSenderStat", "SSRC: %u\r\n"
+                                           "SentPackets: %u\r\n"
+                                           "LostPackets: %u\r\n"
+                                           "Jitter: %u\r\n"
+                                           "SRCount: %u\r\n"
+                                           "RTT: %f\r\n",
+                                           rtp->ssrc,
+                                           rtp->txcount,
+                                           rtp->rtcp->reported_lost,
+                                           rtp->rtcp->reported_jitter,
+                                           rtp->rtcp->sr_count,
+                                           rtp->rtcp->rtt);
        if (rtp->smoother)
                ast_smoother_free(rtp->smoother);
        if (rtp->ioid)
        if (rtp->smoother)
                ast_smoother_free(rtp->smoother);
        if (rtp->ioid)
@@ -2519,6 +2594,29 @@ static int ast_rtcp_write_sr(void *data)
                ast_verbose("  Their last SR: %u\n", rtp->rtcp->themrxlsr);
                ast_verbose("  DLSR: %4.4f (sec)\n\n", (double)(ntohl(rtcpheader[12])/65536.0));
        }
                ast_verbose("  Their last SR: %u\n", rtp->rtcp->themrxlsr);
                ast_verbose("  DLSR: %4.4f (sec)\n\n", (double)(ntohl(rtcpheader[12])/65536.0));
        }
+       manager_event(EVENT_FLAG_REPORTING, "RTCPSent", "To %s:%d\r\n"
+                                           "OurSSRC: %u\r\n"
+                                           "SentNTP: %u.%010u\r\n"
+                                           "SentRTP: %u\r\n"
+                                           "SentPackets: %u\r\n"
+                                           "SentOctets: %u\r\n"
+                                           "ReportBlock:\r\n"
+                                           "FractionLost: %u\r\n"
+                                           "CumulativeLoss: %u\r\n"
+                                           "IAJitter: %.4f\r\n"
+                                           "TheirLastSR: %u\r\n"
+                                           "DLSR: %4.4f (sec)\r\n",
+                                           ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port),
+                                           rtp->ssrc,
+                                           (unsigned int)now.tv_sec, (unsigned int)now.tv_usec*4096,
+                                           rtp->lastts,
+                                           rtp->txcount,
+                                           rtp->txoctetcount,
+                                           fraction,
+                                           lost,
+                                           rtp->rxjitter,
+                                           rtp->rtcp->themrxlsr,
+                                           (double)(ntohl(rtcpheader[12])/65536.0));
        return res;
 }
 
        return res;
 }