Skip to content

Commit

Permalink
modified cubic test
Browse files Browse the repository at this point in the history
  • Loading branch information
Aperence committed Dec 13, 2023
1 parent 6a17a74 commit c866921
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tests/test_cubic.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -9,13 +8,20 @@ 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):
"""
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
Expand All @@ -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)

Expand Down

0 comments on commit c866921

Please sign in to comment.