java.lang.Object
net.i2p.client.streaming.impl.SimpleBandwidthEstimator
All Implemented Interfaces:
BandwidthEstimator

class SimpleBandwidthEstimatorextends Object implements BandwidthEstimator
A Westwood+ bandwidth estimator with a first stage anti-aliasing low pass filter based on RTT, and the time-varying Westwood filter based on inter-arrival time.

Ref: TCP Westwood: End-to-End Congestion Control for Wired/Wireless Networks Casetti et al (Westwood)

Ref: End-to-End Bandwidth Estimation for Congestion Control in Packet Networks Grieco and Mascolo (Westwood+)

Adapted from: Linux kernel tcp_westwood.c (GPLv2).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Messages acked so far, the kernel's bk counter.
    private float
    Estimate excluding zero-hop connections, the kernel's bw_ns_est.
    private float
    Filtered bandwidth estimate from the acks, the kernel's bw_est.
    private final I2PAppContext
    The app context.
    private final Log
    Logger for the bandwidth estimator.
    private final ConnectionOptions
    The connection options being estimated.
    private long
    When the last ack arrived.
    private static int
    Current decay factor from the config.
    private static final int
    Default decay factor of the estimate, as in the kernel Westwood code, matching the TCP alpha.
    private static final int
    Smallest RTT used in the estimate, in ms.
  • Constructor Summary

    Constructors
    Constructor
    Description
    New estimator bound to the given options.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addSample(int acked)
    Records an arriving ack.
    private float
    computeBWE(long now)
    Computes the current bandwidth estimate.
    private void
    Optimized version of updateBK with packets == 0.
    float
    Current bandwidth estimate.
    static int
    Returns the current EWMA decay factor.
    static void
    setDecayFactor(int factor)
    EWMA decay factor for new estimators.
    Debug representation of the estimate state.
    private void
    updateBK(long time, int packets)
    Here we insert virtual null samples if necessary as in Westwood, And use a very simple EWMA (exponential weighted moving average) time-varying filter, as in kernel tcp_westwood.c.
    private float
    westwood_do_filter(float a, float b)
    As in kernel tcp_westwood.c.

    Methods inherited from class Object

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

    • _context

      private final I2PAppContext _context
      The app context.
    • _log

      private final Log _log
      Logger for the bandwidth estimator.
    • _opts

      private final ConnectionOptions _opts
      The connection options being estimated.
    • _tAck

      private long _tAck
      When the last ack arrived.
    • _bKFiltered

      private float _bKFiltered
      Filtered bandwidth estimate from the acks, the kernel's bw_est.
    • _bK_ns_est

      private float _bK_ns_est
      Estimate excluding zero-hop connections, the kernel's bw_ns_est.
    • _acked

      private int _acked
      Messages acked so far, the kernel's bk counter.
    • DEFAULT_DECAY_FACTOR

      private static final int DEFAULT_DECAY_FACTOR
      Default decay factor of the estimate, as in the kernel Westwood code, matching the TCP alpha.
      See Also:
    • decayFactor

      private static volatile int decayFactor
      Current decay factor from the config.
    • WESTWOOD_RTT_MIN

      private static final int WESTWOOD_RTT_MIN
      Smallest RTT used in the estimate, in ms.
      See Also:
  • Constructor Details

    • SimpleBandwidthEstimator

      SimpleBandwidthEstimator(I2PAppContext ctx, ConnectionOptions opts)
      New estimator bound to the given options.
      Parameters:
      ctx - application context, used for the log and the initial timestamp
      opts - connection options supplying the RTT floor and maximum message size
  • Method Details

    • getDecayFactor

      public static int getDecayFactor()
      Returns the current EWMA decay factor.
      Returns:
      the current decay factor
    • setDecayFactor

      public static void setDecayFactor(int factor)
      EWMA decay factor for new estimators. Higher = more smoothing, lower = faster adaptation. Runtime changes apply to all estimators via the static field.
      Parameters:
      factor - the new decay factor (clamped to 2..16)
    • addSample

      public void addSample(int acked)
      Records an arriving ack.
      Specified by:
      addSample in interface BandwidthEstimator
      Parameters:
      acked - how many packets were acked with this ack
    • getBandwidthEstimate

      public float getBandwidthEstimate()
      Current bandwidth estimate.
      Specified by:
      getBandwidthEstimate in interface BandwidthEstimator
      Returns:
      the current bandwidth estimate in packets/ms.
    • computeBWE

      private float computeBWE(long now)
      Computes the current bandwidth estimate.
      Parameters:
      now - the current time
      Returns:
      the estimate in bytes per second
    • decay

      private void decay()
      Optimized version of updateBK with packets == 0.
    • updateBK

      private void updateBK(long time, int packets)
      Here we insert virtual null samples if necessary as in Westwood, And use a very simple EWMA (exponential weighted moving average) time-varying filter, as in kernel tcp_westwood.c.
      Parameters:
      time - the time of the measurement
      packets - number of packets acked
    • westwood_do_filter

      private float westwood_do_filter(float a, float b)
      As in kernel tcp_westwood.c.
      Parameters:
      a - the previous filtered estimate in packets per millisecond
      b - the new sample in packets per millisecond
      Returns:
      the exponentially decayed average of a and b, in packets per millisecond
    • toString

      public String toString()
      Debug representation of the estimate state.
      Overrides:
      toString in class Object