1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef NET_DCSCTP_TX_RETRANSMISSION_TIMEOUT_H_ 11 #define NET_DCSCTP_TX_RETRANSMISSION_TIMEOUT_H_ 12 13 #include <cstdint> 14 #include <functional> 15 16 #include "net/dcsctp/public/dcsctp_options.h" 17 18 namespace dcsctp { 19 20 // Manages updating of the Retransmission Timeout (RTO) SCTP variable, which is 21 // used directly as the base timeout for T3-RTX and for other timers, such as 22 // delayed ack. 23 // 24 // When a round-trip-time (RTT) is calculated (outside this class), `Observe` 25 // is called, which calculates the retransmission timeout (RTO) value. The RTO 26 // value will become larger if the RTT is high and/or the RTT values are varying 27 // a lot, which is an indicator of a bad connection. 28 class RetransmissionTimeout { 29 public: 30 static constexpr int kRttShift = 3; 31 static constexpr int kRttVarShift = 2; 32 explicit RetransmissionTimeout(const DcSctpOptions& options); 33 34 // To be called when a RTT has been measured, to update the RTO value. 35 void ObserveRTT(DurationMs measured_rtt); 36 37 // Returns the Retransmission Timeout (RTO) value, in milliseconds. rto()38 DurationMs rto() const { return DurationMs(rto_); } 39 40 // Returns the smoothed RTT value, in milliseconds. srtt()41 DurationMs srtt() const { return DurationMs(scaled_srtt_ >> kRttShift); } 42 43 private: 44 const int32_t min_rto_; 45 const int32_t max_rto_; 46 const int32_t max_rtt_; 47 const int32_t min_rtt_variance_; 48 // If this is the first measurement 49 bool first_measurement_ = true; 50 // Smoothed Round-Trip Time, shifted by kRttShift 51 int32_t scaled_srtt_; 52 // Round-Trip Time Variation, shifted by kRttVarShift 53 int32_t scaled_rtt_var_ = 0; 54 // Retransmission Timeout 55 int32_t rto_; 56 }; 57 } // namespace dcsctp 58 59 #endif // NET_DCSCTP_TX_RETRANSMISSION_TIMEOUT_H_ 60