java.lang.Object
net.i2p.router.transport.udp.SimpleBandwidthEstimator
- All Implemented Interfaces:
BandwidthEstimator
A Westwood+ bandwidth estimator with: <ul> <li>A first-stage anti-aliasing low-pass filter based on RTT</li> <li>A time-varying EWMA filter based on inter-arrival time</li> </ul>
<p>This estimator is adapted from the Linux kernel's <code>tcp_westwood.c</code> implementation and the Westwood+ research paper.</p>
<p>Ref: <em>TCP Westwood: End-to-End Congestion Control for Wired/Wireless Networks</em> - Casetti et al.</p> <p>Ref: <em>End-to-End Bandwidth Estimation for Congestion Control in Packet Networks</em> - Grieco and Mascolo.</p>
<p>Adapted for I2P streaming transport in 0.9.49.</p>
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intMessages acked so far.private floatEstimate excluding the zero-hop peers.private floatFiltered bandwidth estimate from the acks.private final I2PAppContextThe app context.private static intCurrent decay factor from the config.private final intDecay factor used for the zero-hop peers, snapshotted at construction so runtime tuning never perturbs a live stream.private final LogLogger for the bandwidth estimator.private final PeerStateThe peer state being estimated.private longWhen the last ack arrived.private static final intDefault decay factor of the estimate.private static final intSmallest RTT used in the estimate, in ms.Constructor Summary
ConstructorsConstructorDescriptionSimpleBandwidthEstimator(I2PAppContext ctx, PeerState state) Creates a new bandwidth estimator for the given peer.Method Summary
Modifier and TypeMethodDescriptionvoidaddSample(int acked) Records a new bandwidth sample based on the number of bytes acknowledged.private voidaddSample(int acked, long now, int rtt) Internal synchronized version of addSample that also takes the current time and RTT.private floatcomputeBWE(long now, int rtt) Synchronized version of the bandwidth computation method.private voiddecay()Applies exponential decay to the bandwidth estimate when no new data is received.private StringformatRate(double value) Formats a byte rate for the debug log.floatReturns the current bandwidth estimate in bytes per millisecond.floatgetBandwidthEstimate(long now) Returns the current bandwidth estimate at the specified time.static intReturns the current EWMA decay factor.static voidsetDecayFactor(int factor) The EWMA decay factor for new estimators.toString()Returns a string representation of this estimator's current state.private voidupdateBK(long time, int packets, int rtt) Updates the bandwidth estimate using the latest sample.private floatwestwood_do_filter(float a, float b) Applies an exponential weighted moving average (EWMA) filter to the bandwidth estimate.
Field Details
_context
The app context._log
Logger for the bandwidth estimator._state
The peer state being estimated._tAck
private long _tAckWhen the last ack arrived._bKFiltered
private float _bKFilteredFiltered bandwidth estimate from the acks._bK_ns_est
private float _bK_ns_estEstimate excluding the zero-hop peers._acked
private int _ackedMessages acked so far.DEFAULT_DECAY_FACTOR
private static final int DEFAULT_DECAY_FACTORDefault decay factor of the estimate.- 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:
_localDecayFactor
private final int _localDecayFactorDecay factor used for the zero-hop peers, snapshotted at construction so runtime tuning never perturbs a live stream.
Constructor Details
SimpleBandwidthEstimator
SimpleBandwidthEstimator(I2PAppContext ctx, PeerState state) Creates a new bandwidth estimator for the given peer.- Parameters:
ctx- I2P application contextstate- peer state for RTT and other transport metrics
Method Details
getDecayFactor
public static int getDecayFactor()Returns the current EWMA decay factor.- Returns:
- the decay factor
setDecayFactor
public static void setDecayFactor(int factor) The EWMA decay factor for new estimators. Higher = more smoothing, lower = faster adaptation.- Parameters:
factor- EWMA decay factor to apply to new estimators, 2-16; values
addSample
public void addSample(int acked) Records a new bandwidth sample based on the number of bytes acknowledged.- Specified by:
addSamplein interfaceBandwidthEstimator- Parameters:
acked- number of bytes newly acknowledged
addSample
private void addSample(int acked, long now, int rtt) Internal synchronized version of addSample that also takes the current time and RTT.- Parameters:
acked- number of bytes newly acknowledgednow- current time in millisecondsrtt- current round-trip time estimate
getBandwidthEstimate
public float getBandwidthEstimate()Returns the current bandwidth estimate in bytes per millisecond.- Specified by:
getBandwidthEstimatein interfaceBandwidthEstimator- Returns:
- bandwidth estimate in bytes per millisecond
getBandwidthEstimate
public float getBandwidthEstimate(long now) Returns the current bandwidth estimate at the specified time.- Parameters:
now- current time in milliseconds- Returns:
- bandwidth estimate in bytes per millisecond
computeBWE
private float computeBWE(long now, int rtt) Synchronized version of the bandwidth computation method.- Parameters:
now- current time in millisecondsrtt- current round-trip time- Returns:
- updated bandwidth estimate
decay
private void decay()Applies exponential decay to the bandwidth estimate when no new data is received.updateBK
private void updateBK(long time, int packets, int rtt) Updates the bandwidth estimate using the latest sample. If no recent acknowledgments were received, virtual null samples are inserted.- Parameters:
time- time of the measurementpackets- number of bytes acknowledgedrtt- current round-trip time
formatRate
Formats a byte rate for the debug log.- Parameters:
value- the rate in bytes per second- Returns:
- the formatted rate
westwood_do_filter
private float westwood_do_filter(float a, float b) Applies an exponential weighted moving average (EWMA) filter to the bandwidth estimate.- Parameters:
a- the previous estimate in bytes per millisecond, weighted bydecayFactor - 1b- the new measurement in bytes per millisecond, weight 1- Returns:
- the filtered estimate, with the weight of
aset by the decay factor snapshotted at construction
toString