Class RttEstimator

java.lang.Object
io.github.mahmoudimus.quic.congestion.RttEstimator

public final class RttEstimator extends Object
Round-trip time estimation for one network path (RFC 9002 section 5): the latest sample, the smoothed RTT and its variance (RFC 6298), and the minimum RTT. All durations are nanoseconds.

Threads. Not thread-safe; an estimator belongs to one connection, which serializes access.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The initial RTT before any sample, 333 ms (RFC 9002 section 6.2.2).
    static final long
    The system timer granularity assumed by loss detection, 1 ms (RFC 9002 section 6.1.2).
  • Constructor Summary

    Constructors
    Constructor
    Description
    RttEstimator(long initialRtt)
    An estimator with no samples.
    A copy of another estimator.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    A conservative estimate, the larger of the smoothed and latest RTT (RFC 9002 section 6.1.2).
    long
    get()
    The best current estimate: the smoothed RTT, or the initial RTT before any sample.
    boolean
    Whether a sample has been taken.
    long
    The most recent sample.
    long
    min()
    The minimum RTT seen.
    long
    The probe timeout before backoff and max_ack_delay: smoothed_rtt + max(4 * rttvar, kGranularity) (RFC 9002 section 6.2.1).
    void
    update(long ackDelay, long rtt)
    Takes an RTT sample (RFC 9002 section 5.3).
    long
    The RTT variance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TIMER_GRANULARITY

      public static final long TIMER_GRANULARITY
      The system timer granularity assumed by loss detection, 1 ms (RFC 9002 section 6.1.2).
      See Also:
    • DEFAULT_INITIAL_RTT

      public static final long DEFAULT_INITIAL_RTT
      The initial RTT before any sample, 333 ms (RFC 9002 section 6.2.2).
      See Also:
  • Constructor Details

    • RttEstimator

      public RttEstimator(long initialRtt)
      An estimator with no samples.
      Parameters:
      initialRtt - the RTT to assume until the first sample, in nanoseconds
    • RttEstimator

      public RttEstimator(RttEstimator other)
      A copy of another estimator.
      Parameters:
      other - the estimator to copy
  • Method Details

    • get

      public long get()
      The best current estimate: the smoothed RTT, or the initial RTT before any sample.
      Returns:
      nanoseconds
    • conservative

      public long conservative()
      A conservative estimate, the larger of the smoothed and latest RTT (RFC 9002 section 6.1.2).
      Returns:
      nanoseconds
    • min

      public long min()
      The minimum RTT seen.
      Returns:
      nanoseconds
    • latest

      public long latest()
      The most recent sample.
      Returns:
      nanoseconds
    • variance

      public long variance()
      The RTT variance.
      Returns:
      nanoseconds
    • hasSample

      public boolean hasSample()
      Whether a sample has been taken.
      Returns:
      true after the first update(long, long)
    • ptoBase

      public long ptoBase()
      The probe timeout before backoff and max_ack_delay: smoothed_rtt + max(4 * rttvar, kGranularity) (RFC 9002 section 6.2.1).
      Returns:
      nanoseconds
    • update

      public void update(long ackDelay, long rtt)
      Takes an RTT sample (RFC 9002 section 5.3). The ACK delay is subtracted only when that does not take the sample below the minimum RTT; the first sample resets every estimate.
      Parameters:
      ackDelay - the peer's reported ACK delay, already limited to its max_ack_delay
      rtt - the time from sending the largest newly acknowledged packet to receiving the ACK