diff --git a/tests/test_cubic.py b/tests/test_cubic.py index 39750c8a5..6252be188 100644 --- a/tests/test_cubic.py +++ b/tests/test_cubic.py @@ -1,5 +1,4 @@ from aioquic.quic.congestion.cubic import CubicCongestionControl, K_CUBIC_C, K_CUBIC_LOSS_REDUCTION_FACTOR, QuicSentPacket -from aioquic.quic.congestion import K_MAX_DATAGRAM_SIZE import unittest def W_cubic(t, K, W_max): @@ -9,6 +8,11 @@ def cube_root(x): if (x < 0): return -((-x)**(1/3)) else: return x**(1/3) +class RecoveryStaticRtt: + def __init__(self): + self._rtt_smoothed = 0 + + class CubicTests(unittest.TestCase): def test_congestion_avoidance(self): @@ -16,6 +20,8 @@ def test_congestion_avoidance(self): Check if the cubic implementation respects the mathematical formula defined in the rfc 9438 """ + max_datagram_size = 1440 + n = 400 # number of ms to check W_max = 5 # starting W_max @@ -27,25 +33,25 @@ def test_congestion_avoidance(self): test_range = range(n) for i in test_range: - correct.append(W_cubic(i/1000, K, W_max) * K_MAX_DATAGRAM_SIZE) + correct.append(W_cubic(i/1000, K, W_max) * max_datagram_size) - cubic = CubicCongestionControl() - cubic._W_max = W_max * K_MAX_DATAGRAM_SIZE + cubic = CubicCongestionControl(max_datagram_size, RecoveryStaticRtt()) + cubic._W_max = W_max * max_datagram_size cubic._starting_congestion_avoidance = True - cubic.congestion_window = cwnd * K_MAX_DATAGRAM_SIZE - cubic.slow_start.ssthresh = cubic.congestion_window + cubic.congestion_window = cwnd * max_datagram_size + cubic.ssthresh = cubic.congestion_window cubic._W_est = 0 results = [] for i in test_range: - cwnd = cubic.congestion_window // K_MAX_DATAGRAM_SIZE # number of segments + cwnd = cubic.congestion_window // max_datagram_size # number of segments # simulate the reception of cwnd packets (a full window of acks) for _ in range(int(cwnd)): packet = QuicSentPacket(None, True, True, True, 0, 0) packet.sent_bytes = 0 # won't affect results - rtt = 0 - cubic.on_packet_acked_timed(packet, i/1000, rtt) + + cubic.on_packet_acked(packet, i/1000) results.append(cubic.congestion_window)