Summary: | ASTERISK-26566: res_rtp_asterisk: RTT miscalculation in RTCP | ||
Reporter: | Hector Royo Concepcion (HectorRoyo92) | Labels: | |
Date Opened: | 2016-11-08 07:15:45.000-0600 | Date Closed: | 2016-11-23 11:56:35.000-0600 |
Priority: | Major | Regression? | |
Status: | Closed/Complete | Components: | Resources/res_rtp_asterisk |
Versions: | 13.9.0 13.11.2 | Frequency of Occurrence | |
Related Issues: | |||
Environment: | Attachments: | ||
Description: | I have an Asterisk, with PJSIP. We are saving the RTCP stats to a CDR database, and I've found that RTT values are mostly wrong, showing values over 4.000 seconds.
I've been reading how the RTT is calculated on the RTCP RFC, and I think that the code on res_rtp_asterisk.c is miscalculating the LSW of the RTT. {quote} rtt_lsw = (rtt & 0x0000ffff) << 16; // This will cause overflow rtt_tv.tv_usec = ((rtt_lsw << 6) / 3650) - (rtt_lsw >> 12) - (rtt_lsw >> 8); // This will lose precision rtp->rtcp->rtt = (double)rtt_tv.tv_sec + (double)(rtt_tv.tv_usec/1000000.); {quote} This lines above can easily overflow the LSW. Since it is a *fixed point* value, I think it should be calculated like this (probably not the most efficient way): {quote} rtt_lsw = (rtt & 0x0000ffff); // No shift!! rtt_tv.tv_usec = (rtt_lsw * 999985)/65535; // Better precision rtp->rtcp->rtt = (double)rtt_tv.tv_sec + (double)(rtt_tv.tv_usec/1000000.); {quote} Using this version of the code, values that were 4000~ seconds are now 60-70ms. This new values matches the RTT values I'm getting from Wireshark. Values 65535 and 999985 came from: {quote} 655535 = 0xffff = 0b1111111111111111 999985 = (2⁻¹ + 2⁻² + ... +2⁻¹⁵ + 2⁻¹⁶)*1000000 {quote} | ||
Comments: | By: Asterisk Team (asteriskteam) 2016-11-08 07:15:46.137-0600 Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution. A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report. Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process]. By: Rusty Newton (rnewton) 2016-11-10 08:28:18.453-0600 Would you like to submit a patch to Gerrit so that others can review it there? That would help speed it through the process! :) Once you've followed the Code Review process [1] and submitted your code to Gerrit [2] be sure to edit this JIRA issue and add the Gerrit review URL in the appropriate field. Thanks! [1] https://wiki.asterisk.org/wiki/display/AST/Code+Review [2] https://wiki.asterisk.org/wiki/display/AST/Gerrit+Usage By: Hector Royo Concepcion (HectorRoyo92) 2016-11-22 02:01:54.453-0600 I've submitted a patch https://gerrit.asterisk.org/#/c/4397/ By: Friendly Automation (friendly-automation) 2016-11-23 11:56:36.813-0600 Change 4491 merged by zuul: res_rtp_asterisk: RTT miscalculation in RTCP [https://gerrit.asterisk.org/4491|https://gerrit.asterisk.org/4491] By: Friendly Automation (friendly-automation) 2016-11-23 12:10:47.598-0600 Change 4397 merged by Joshua Colp: res_rtp_asterisk: RTT miscalculation in RTCP [https://gerrit.asterisk.org/4397|https://gerrit.asterisk.org/4397] By: Friendly Automation (friendly-automation) 2016-11-23 12:11:07.893-0600 Change 4490 merged by Joshua Colp: res_rtp_asterisk: RTT miscalculation in RTCP [https://gerrit.asterisk.org/4490|https://gerrit.asterisk.org/4490] |