java.lang.Object
net.i2p.client.streaming.impl.SimpleBandwidthEstimator
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate intMessages acked so far, the kernel's bk counter.private floatEstimate excluding zero-hop connections, the kernel's bw_ns_est.private floatFiltered bandwidth estimate from the acks, the kernel's bw_est.private final I2PAppContextThe app context.private final LogLogger for the bandwidth estimator.private final ConnectionOptionsThe connection options being estimated.private longWhen the last ack arrived.private static intCurrent decay factor from the config.private static final intDefault decay factor of the estimate, as in the kernel Westwood code, matching the TCP alpha.private static final intSmallest RTT used in the estimate, in ms.Constructor Summary
ConstructorsConstructorDescriptionNew estimator bound to the given options.Method Summary
Modifier and TypeMethodDescriptionvoidaddSample(int acked) Records an arriving ack.private floatcomputeBWE(long now) Computes the current bandwidth estimate.private voiddecay()Optimized version of updateBK with packets == 0.floatCurrent bandwidth estimate.static intReturns the current EWMA decay factor.static voidsetDecayFactor(int factor) EWMA decay factor for new estimators.toString()Debug representation of the estimate state.private voidupdateBK(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 floatwestwood_do_filter(float a, float b) As in kernel tcp_westwood.c.
Field Details
_context
The app context._log
Logger for the bandwidth estimator._opts
The connection options being estimated._tAck
private long _tAckWhen the last ack arrived._bKFiltered
private float _bKFilteredFiltered bandwidth estimate from the acks, the kernel's bw_est._bK_ns_est
private float _bK_ns_estEstimate excluding zero-hop connections, the kernel's bw_ns_est._acked
private int _ackedMessages acked so far, the kernel's bk counter.DEFAULT_DECAY_FACTOR
private static final int DEFAULT_DECAY_FACTORDefault decay factor of the estimate, as in the kernel Westwood code, matching the TCP alpha.- See Also:
decayFactor
private static volatile int decayFactorCurrent decay factor from the config.WESTWOOD_RTT_MIN
private static final int WESTWOOD_RTT_MINSmallest 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 timestampopts- 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:
addSamplein interfaceBandwidthEstimator- Parameters:
acked- how many packets were acked with this ack
getBandwidthEstimate
public float getBandwidthEstimate()Current bandwidth estimate.- Specified by:
getBandwidthEstimatein interfaceBandwidthEstimator- 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 measurementpackets- 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 millisecondb- the new sample in packets per millisecond- Returns:
- the exponentially decayed average of a and b, in packets per millisecond
toString