Since the code measuring the RTT has been converted to using TimeDelta which internally stores the duration in microseconds, from DurationMs which uses milliseconds, the RTO calculation can use the higher precision to calculate lower non-zero durations on really fast networks such within a data center. Before this CL, which is from the initial drop of dcSCTP, the RTO calculation was done using the algorithm from the paper "V. Jacobson: Congestion avoidance and control", but now we're using the original algorith from https://tools.ietf.org/html/rfc4960#section-6.3.1, which comes from https://datatracker.ietf.org/doc/html/rfc6298#section-2. Two issues were found and corrected: 1. The min RTT variance that is specified in the config file was previously incorrectly divided by 8. That was not its intention, but we're keeping that behaviour as other clients have actually measured a good value to put there. This represents "G" in the "basic algorithm" above, and since that is multiplied with K, which is four, the default value of 220 wouldn't make sense if it wasn't scaled down, as that would make the RTO easily saturate to the RTO_max (800ms). 2. The previous algorithm had large round-off errors (probably because the code used milliseconds), which makes fairly big changes to the calculated RTO in some situations. Bug: webrtc:15593 Change-Id: I95a3e137c2bbbe7bf8b99c016381e9e63fd01d87 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/349000 Reviewed-by: Florent Castelli <orphis@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Victor Boivie <boivie@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42170}
67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
#include "net/dcsctp/tx/retransmission_timeout.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
|
|
#include "api/units/time_delta.h"
|
|
#include "net/dcsctp/public/dcsctp_options.h"
|
|
|
|
namespace dcsctp {
|
|
|
|
// https://datatracker.ietf.org/doc/html/rfc4960#section-15.
|
|
constexpr double kRtoAlpha = 0.125;
|
|
constexpr double kRtoBeta = 0.25;
|
|
|
|
// A factor that the `min_rtt_variance` configuration option will be divided by
|
|
// (before later multiplied with K, which is 4 according to RFC6298). When this
|
|
// value was introduced, it was unintentionally divided by 8 since that code
|
|
// worked with scaled numbers (to avoid floating point math). That behavior is
|
|
// kept as downstream users have measured good values for their use-cases.
|
|
constexpr double kHeuristicVarianceAdjustment = 8.0;
|
|
|
|
RetransmissionTimeout::RetransmissionTimeout(const DcSctpOptions& options)
|
|
: min_rto_(options.rto_min.ToTimeDelta()),
|
|
max_rto_(options.rto_max.ToTimeDelta()),
|
|
max_rtt_(options.rtt_max.ToTimeDelta()),
|
|
min_rtt_variance_(options.min_rtt_variance.ToTimeDelta() /
|
|
kHeuristicVarianceAdjustment),
|
|
srtt_(options.rto_initial.ToTimeDelta()),
|
|
rto_(options.rto_initial.ToTimeDelta()) {}
|
|
|
|
void RetransmissionTimeout::ObserveRTT(webrtc::TimeDelta rtt) {
|
|
// Unrealistic values will be skipped. If a wrongly measured (or otherwise
|
|
// corrupt) value was processed, it could change the state in a way that would
|
|
// take a very long time to recover.
|
|
if (rtt < webrtc::TimeDelta::Zero() || rtt > max_rtt_) {
|
|
return;
|
|
}
|
|
|
|
// https://tools.ietf.org/html/rfc4960#section-6.3.1.
|
|
if (first_measurement_) {
|
|
srtt_ = rtt;
|
|
rtt_var_ = rtt / 2;
|
|
first_measurement_ = false;
|
|
} else {
|
|
webrtc::TimeDelta rtt_diff = (srtt_ - rtt).Abs();
|
|
rtt_var_ = (1 - kRtoBeta) * rtt_var_ + kRtoBeta * rtt_diff;
|
|
srtt_ = (1 - kRtoAlpha) * srtt_ + kRtoAlpha * rtt;
|
|
}
|
|
|
|
if (rtt_var_ < min_rtt_variance_) {
|
|
rtt_var_ = min_rtt_variance_;
|
|
}
|
|
|
|
rto_ = srtt_ + 4 * rtt_var_;
|
|
rto_ = std::clamp(rto_, min_rto_, max_rto_);
|
|
}
|
|
} // namespace dcsctp
|