forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBbrTest.cpp
More file actions
2222 lines (1881 loc) · 82.8 KB
/
Copy pathBbrTest.cpp
File metadata and controls
2222 lines (1881 loc) · 82.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
Abstract:
Unit tests for BBR congestion control.
--*/
#include "main.h"
#ifdef QUIC_CLOG
#include "BbrTest.cpp.clog.h"
#endif
extern "C" {
void BbrCongestionControlInitialize(QUIC_CONGESTION_CONTROL* Cc, const QUIC_SETTINGS_INTERNAL* Settings);
uint64_t BbrCongestionControlGetBandwidth(const QUIC_CONGESTION_CONTROL* Cc);
uint32_t BbrCongestionControlGetTargetCwnd(QUIC_CONGESTION_CONTROL* Cc, uint32_t Gain);
}
//
// State definitions mirrored from bbr.c for readable assertions.
//
enum BBR_STATE {
BBR_STATE_STARTUP = 0,
BBR_STATE_DRAIN = 1,
BBR_STATE_PROBE_BW = 2,
BBR_STATE_PROBE_RTT = 3
};
enum RECOVERY_STATE {
RECOVERY_STATE_NOT_RECOVERY = 0,
RECOVERY_STATE_CONSERVATIVE = 1,
RECOVERY_STATE_GROWTH = 2
};
//
// Reuse helpers matching CubicTest.cpp conventions.
//
static void InitBbrMockConnection(
QUIC_CONNECTION& Connection,
uint16_t Mtu)
{
Connection.Paths[0].Mtu = Mtu;
Connection.Paths[0].IsActive = TRUE;
Connection.Send.NextPacketNumber = 0;
Connection.Settings.PacingEnabled = FALSE;
Connection.Settings.HyStartEnabled = FALSE;
Connection.Settings.NetStatsEventEnabled = FALSE;
Connection.Paths[0].GotFirstRttSample = FALSE;
Connection.Paths[0].SmoothedRtt = 0;
Connection.Paths[0].OneWayDelay = 0;
Connection.Stats.Send.CongestionCount = 0;
Connection.Stats.Send.PersistentCongestionCount = 0;
Connection.Send.PeerMaxData = UINT64_MAX;
Connection.Send.OrderedStreamBytesSent = 0;
Connection.SendBuffer.PostedBytes = 0;
Connection.SendBuffer.IdealBytes = 0;
Connection.Stats.Send.TotalBytes = 0;
Connection.LossDetection.LargestSentPacketNumber = 0;
}
static QUIC_ACK_EVENT MakeBbrAckEvent(
uint64_t TimeNow,
uint64_t LargestAck,
uint64_t LargestSentPacketNumber,
uint32_t BytesAcked,
uint64_t SmoothedRtt = 50000,
uint64_t MinRtt = 45000,
BOOLEAN MinRttValid = TRUE)
{
QUIC_ACK_EVENT Ack{};
Ack.TimeNow = TimeNow;
Ack.LargestAck = LargestAck;
Ack.LargestSentPacketNumber = LargestSentPacketNumber;
Ack.NumRetransmittableBytes = BytesAcked;
Ack.NumTotalAckedRetransmittableBytes = BytesAcked;
Ack.SmoothedRtt = SmoothedRtt;
Ack.MinRtt = MinRtt;
Ack.MinRttValid = MinRttValid;
Ack.AdjustedAckTime = TimeNow;
return Ack;
}
static QUIC_LOSS_EVENT MakeBbrLossEvent(
uint32_t LostBytes,
uint64_t LargestPacketNumberLost,
uint64_t LargestSentPacketNumber,
BOOLEAN PersistentCongestion = FALSE)
{
QUIC_LOSS_EVENT Loss{};
Loss.NumRetransmittableBytes = LostBytes;
Loss.LargestPacketNumberLost = LargestPacketNumberLost;
Loss.LargestSentPacketNumber = LargestSentPacketNumber;
Loss.PersistentCongestion = PersistentCongestion;
return Loss;
}
static QUIC_MAX_SENT_PACKET_METADATA MakeBbrPacket(
uint16_t PacketLength,
BOOLEAN HasLastAckedPacketInfo,
BOOLEAN IsAppLimited,
uint64_t TotalBytesSent,
uint64_t SentTime,
uint64_t LastTotalBytesSent = 0,
uint64_t LastSentTime = 0,
uint64_t LastTotalBytesAcked = 0,
uint64_t LastAdjustedAckTime = 0,
uint64_t LastAckTime = 0)
{
QUIC_MAX_SENT_PACKET_METADATA PacketBuf{};
auto& Pkt = PacketBuf.Metadata;
Pkt.PacketLength = PacketLength;
Pkt.Flags.HasLastAckedPacketInfo = HasLastAckedPacketInfo;
Pkt.Flags.IsAppLimited = IsAppLimited;
Pkt.TotalBytesSent = TotalBytesSent;
Pkt.SentTime = SentTime;
Pkt.LastAckedPacketInfo.TotalBytesSent = LastTotalBytesSent;
Pkt.LastAckedPacketInfo.SentTime = LastSentTime;
Pkt.LastAckedPacketInfo.TotalBytesAcked = LastTotalBytesAcked;
Pkt.LastAckedPacketInfo.AdjustedAckTime = LastAdjustedAckTime;
Pkt.LastAckedPacketInfo.AckTime = LastAckTime;
Pkt.Next = NULL;
return PacketBuf;
}
//
// GoogleTest fixture for BBR congestion control tests.
//
class BbrTest_DeepTest : public ::testing::Test {
protected:
bool NetStatsCallbackInvoked = false;
QUIC_NETWORK_STATISTICS LastNetStats = {};
QUIC_CONNECTION Connection{};
QUIC_SETTINGS_INTERNAL Settings{};
QUIC_CONGESTION_CONTROL_BBR* Bbr;
QUIC_CONGESTION_CONTROL* CC;
static
_IRQL_requires_max_(PASSIVE_LEVEL)
_Function_class_(QUIC_CONNECTION_CALLBACK)
QUIC_STATUS
QUIC_API
DummyConnectionCallback(
_In_ HQUIC /* Connection */,
_In_opt_ void* Context,
_Inout_ QUIC_CONNECTION_EVENT* Event
)
{
auto* Self = static_cast<BbrTest_DeepTest*>(Context);
if (Event->Type == QUIC_CONNECTION_EVENT_NETWORK_STATISTICS) {
Self->NetStatsCallbackInvoked = true;
Self->LastNetStats = Event->NETWORK_STATISTICS;
}
return QUIC_STATUS_SUCCESS;
}
void InitializeWithDefaults(
uint32_t WindowPackets = 10,
uint16_t Mtu = 1280,
bool PacingEnabled = false,
bool NetStatsEnabled = false)
{
Settings.InitialWindowPackets = WindowPackets;
InitBbrMockConnection(Connection, Mtu);
Connection.Settings.PacingEnabled = PacingEnabled ? TRUE : FALSE;
Connection.Settings.NetStatsEventEnabled = NetStatsEnabled ? TRUE : FALSE;
if (NetStatsEnabled) {
Connection.ClientCallbackHandler = DummyConnectionCallback;
// The callback receives Connection->ClientContext which lives inside the
// QUIC_HANDLE base struct (embedded as the unnamed union member '_').
// We point it back to 'this' so the callback can set fixture members.
Connection._.ClientContext = this;
NetStatsCallbackInvoked = false;
LastNetStats = {};
}
CC = &Connection.CongestionControl;
BbrCongestionControlInitialize(CC, &Settings);
Bbr = &CC->Bbr;
}
//
// Helper: Pump a bandwidth sample into the BBR filter via OnDataAcknowledged.
// Constructs packet metadata so that BbrBandwidthFilterOnPacketAcked
// computes DeliveryRate = BW_UNIT * SendRate_BytesPerSec.
// Returns the TimeNow used so callers can build on it.
//
// Key invariant: SendRate == AckRate == BW_UNIT * SendRate_BytesPerSec.
// SendElapsedUs = BytesAcked * 1e6 / SendRate_BytesPerSec
// AckElapsed = SendElapsedUs (by construction: LastAdjustedAckTime = TimeNow - SendElapsedUs)
//
uint64_t PumpBandwidthSample(
uint64_t TimeNow,
uint64_t PacketNumber,
uint32_t BytesAcked,
uint64_t SendRate_BytesPerSec,
uint64_t MinRttUs = 45000)
{
uint64_t SendElapsedUs = (uint64_t)BytesAcked * 1000000ULL / SendRate_BytesPerSec;
// Note: SendElapsedUs is floored to 1; callers with small BytesAcked
// vs large SendRate get an approximated rate.
if (SendElapsedUs == 0) SendElapsedUs = 1;
auto PacketBuf = MakeBbrPacket(
(uint16_t)BytesAcked, TRUE, FALSE,
10000 + BytesAcked, TimeNow - MinRttUs,
10000, TimeNow - MinRttUs - SendElapsedUs,
0, TimeNow - SendElapsedUs, TimeNow - SendElapsedUs);
auto& Packet = PacketBuf.Metadata;
CC->QuicCongestionControlOnDataSent(CC, BytesAcked);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(
TimeNow, PacketNumber, PacketNumber + 1, BytesAcked,
50000, (uint32_t)MinRttUs, TRUE);
Ack.AckedPackets = &Packet;
Ack.IsLargestAckedPacketAppLimited = FALSE;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
return TimeNow;
}
//
// Helper: drive BBR through STARTUP to detect BtlbwFound by sending
// rounds with non-growing bandwidth. Returns the TimeNow after transitions.
//
// To trigger BtlbwFound:
// 1. NewRoundTrip must be TRUE: LargestAck must exceed EndOfRoundTrip
// 2. LastAckedPacketAppLimited must be FALSE: AckedPackets != NULL
// 3. After initial bandwidth sets LastEstimatedStartupBandwidth,
// the next 3 rounds must have CurrentBandwidth < LastEstimatedStartupBandwidth * 5/4
//
uint64_t DriveToBtlbwFound(uint64_t StartTime = 1000000)
{
uint64_t TimeNow = StartTime;
// Each "round" needs: send data, ack it with a bandwidth sample,
// and LargestAck > previous EndOfRoundTrip (= previous LargestSentPacketNumber).
// Round 1: Establish bandwidth in the filter.
// Send 12000 bytes over 100ms => rate ~120KB/s => BW_UNIT*120000 bps in filter
{
auto PacketBuf = MakeBbrPacket(
1200, TRUE, FALSE,
12000, TimeNow,
0, TimeNow - 100000,
0, TimeNow - 50000, TimeNow - 50000);
auto& Pkt = PacketBuf.Metadata;
CC->QuicCongestionControlOnDataSent(CC, 1200);
TimeNow += 50000;
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(TimeNow, 10, 20, 1200, 50000, 45000, TRUE);
Ack.AckedPackets = &Pkt;
Ack.IsLargestAckedPacketAppLimited = FALSE;
Ack.NumTotalAckedRetransmittableBytes = 12000;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
}
// Now LastEstimatedStartupBandwidth = CurrentBandwidth (some value)
// BandwidthTarget for next round = LastEstimatedStartupBandwidth * 320/256 = 1.25x
// Rounds 2-4: Same bandwidth => CurrentBandwidth < BandwidthTarget (1.25x)
// Each round must trigger NewRoundTrip by having LargestAck > EndOfRoundTrip.
// EndOfRoundTrip was set to LargestSentPacketNumber from previous ack.
uint64_t LargestAck = 25; // Must exceed previous EndOfRoundTrip (20)
uint64_t LargestSent = 30;
for (int round = 0; round < 4; round++) {
auto PacketBuf = MakeBbrPacket(
1200, TRUE, FALSE,
12000, TimeNow,
0, TimeNow - 100000,
0, TimeNow - 50000, TimeNow - 50000);
auto& Pkt = PacketBuf.Metadata;
CC->QuicCongestionControlOnDataSent(CC, 1200);
TimeNow += 50000;
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(TimeNow, LargestAck, LargestSent, 1200, 50000, 45000, TRUE);
Ack.AckedPackets = &Pkt;
Ack.IsLargestAckedPacketAppLimited = FALSE;
Ack.NumTotalAckedRetransmittableBytes = 12000;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
LargestAck = LargestSent + 5; // Ensure next round's LargestAck > EndOfRoundTrip
LargestSent += 10;
if (Bbr->BtlbwFound) break;
}
return TimeNow;
}
//
// Helper: enter recovery by sending data then losing some.
//
void EnterRecovery(uint32_t SendBytes = 5000, uint32_t LostBytes = 1200)
{
CC->QuicCongestionControlOnDataSent(CC, SendBytes);
Connection.Send.NextPacketNumber = 10;
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(LostBytes, 5, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
}
//
// Helper: drive BBR to PROBE_RTT state by establishing MinRtt then
// expiring it with a second ACK 11 seconds later.
// Returns the ExpiredTime used so callers can build on it.
//
uint64_t DriveToProbeRtt()
{
CC->QuicCongestionControlOnDataSent(CC, 2000);
QUIC_ACK_EVENT Ack1 = MakeBbrAckEvent(1000000, 1, 2, 2000, 50000, 30000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack1);
CC->QuicCongestionControlOnDataSent(CC, 1000);
uint64_t ExpiredTime = 1000000 + 11000000;
QUIC_ACK_EVENT Ack2 = MakeBbrAckEvent(ExpiredTime, 3, 4, 1000, 50000, 35000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack2);
return ExpiredTime;
}
};
//====================================================================
//
// Specification-conformance tests
//
// These tests validate behavior defined by the BBR congestion
// control algorithm (draft-cardwell-iccrg-bbr-congestion-control).
// They verify the state machine, bandwidth estimation, recovery,
// and pacing gain cycle behavior. They would remain valid across
// any conforming BBR implementation.
//
// Reference:
// https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control
//
//====================================================================
//
// Test: OnDataLost - Enter CONSERVATIVE Recovery
// Scenario: Sends 5000 bytes via OnDataSent, then triggers a loss event of 1200 bytes
// with LargestPacketNumberLost=5 and LargestSentPacketNumber=10. BBR should enter
// CONSERVATIVE recovery on the first loss event.
TEST_F(BbrTest_DeepTest, OnDataLost_EnterRecovery)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 5000);
Connection.Send.NextPacketNumber = 10;
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(1200, 5, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_CONSERVATIVE);
ASSERT_TRUE(Bbr->EndOfRecoveryValid);
ASSERT_EQ(Bbr->BytesInFlight, 5000u - 1200u);
}
//
// Test: OnDataLost - Persistent Congestion Sets MinCW
// Scenario: Sends 10000 bytes via OnDataSent, then triggers a loss of 3000 bytes with
// PersistentCongestion=TRUE. When persistent congestion is detected, BBR should reset
// RecoveryWindow to the minimum congestion window (4 * DatagramPayloadLength = 4928).
//
TEST_F(BbrTest_DeepTest, OnDataLost_PersistentCongestion)
{
InitializeWithDefaults();
const uint16_t DatagramPayloadLength =
QuicPathGetDatagramPayloadSize(&Connection.Paths[0]);
uint32_t MinCW = 4 * DatagramPayloadLength;
CC->QuicCongestionControlOnDataSent(CC, 10000);
Connection.Send.NextPacketNumber = 10;
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(3000, 5, 10, TRUE);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
ASSERT_EQ(Bbr->RecoveryWindow, MinCW);
ASSERT_EQ(Connection.Stats.Send.PersistentCongestionCount, 1u);
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_CONSERVATIVE);
}
//
// Test: OnDataLost - Non-Persistent Loss Reduces RecoveryWindow
// Scenario: Sends 10000 bytes via OnDataSent, then triggers a non-persistent loss of
// 1200 bytes. After loss, BytesInFlight=8800, RecoveryWindow = max(BIF=8800, MinCW=4928)
// - 1200 = 7600.
//
TEST_F(BbrTest_DeepTest, OnDataLost_NonPersistent)
{
InitializeWithDefaults();
const uint16_t DatagramPayloadLength =
QuicPathGetDatagramPayloadSize(&Connection.Paths[0]);
uint32_t MinCW = 4 * DatagramPayloadLength;
CC->QuicCongestionControlOnDataSent(CC, 10000);
Connection.Send.NextPacketNumber = 10;
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(1200, 5, 10, FALSE);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
// BIF after loss = 10000 - 1200 = 8800
// RW = max(BIF, MinCW) = 8800, then RW = (RW > 1200 + MinCW) ? RW - 1200 : MinCW
uint32_t BIF = 10000u - 1200u;
uint32_t RW = (BIF > MinCW) ? BIF : MinCW;
uint32_t ExpectedRW = (RW > 1200u + MinCW) ? RW - 1200u : MinCW;
ASSERT_EQ(Bbr->RecoveryWindow, ExpectedRW);
ASSERT_EQ(Connection.Stats.Send.CongestionCount, 1u);
}
//
// Test: OnDataLost - No Re-Entry When Already in Recovery
// Scenario: Sends 10000 bytes, triggers a first loss of 1200 bytes entering CONSERVATIVE
// recovery, then triggers a second loss of 600 bytes while still in recovery. BBR should
// not re-enter recovery but should adjust the RecoveryWindow.
//
TEST_F(BbrTest_DeepTest, OnDataLost_AlreadyInRecovery)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 10000);
Connection.Send.NextPacketNumber = 10;
// First loss
QUIC_LOSS_EVENT Loss1 = MakeBbrLossEvent(1200, 5, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss1);
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_CONSERVATIVE);
// Second loss while in recovery
QUIC_LOSS_EVENT Loss2 = MakeBbrLossEvent(600, 8, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss2);
// Still in recovery, window adjusted
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_CONSERVATIVE);
// RecoveryWindow after first loss: BIF=8800, RW_local=max(8800,MinCW)=8800,
// then RW = (8800 > 1200+MinCW) ? 8800-1200 : MinCW = 7600.
// Second loss: RW_local=7600 (already in recovery, no reset),
// RW = (7600 > 600+MinCW) ? 7600-600 : MinCW = 7000.
const uint16_t DatagramPayloadLength =
QuicPathGetDatagramPayloadSize(&Connection.Paths[0]);
uint32_t MinCW = 4 * DatagramPayloadLength;
// First loss result
uint32_t RW1 = (8800u > 1200u + MinCW) ? 8800u - 1200u : MinCW;
// Second loss result (already in recovery, RW not reset to BIF)
uint32_t ExpectedRW = (RW1 > 600u + MinCW) ? RW1 - 600u : MinCW;
ASSERT_EQ(Bbr->RecoveryWindow, ExpectedRW);
}
//
// Test: OnDataAcknowledged - MinRtt Update on Valid Sample
// Scenario: Sends 5000 bytes via OnDataSent, then acknowledges 1200 bytes with
// MinRtt=30000us and MinRttValid=TRUE. BBR should update its MinRtt to the new
// sample.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_MinRttUpdate)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(1050000, 5, 10, 1200, 50000, 30000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
ASSERT_EQ(Bbr->MinRtt, 30000u);
ASSERT_TRUE(Bbr->MinRttTimestampValid);
}
//
// Test: OnDataAcknowledged - MinRtt Expires and Updates to New Value
// Scenario: First ACK establishes MinRtt=30000us. Second ACK arrives 11 seconds later
// (past kBbrMinRttExpirationInMicroSecs=10s) with MinRtt=50000us. Since the old MinRtt
// has expired, BBR accepts the new (larger) value.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_MinRttExpired)
{
InitializeWithDefaults();
// First ACK establishes MinRtt
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack1 = MakeBbrAckEvent(1000000, 1, 2, 1200, 50000, 30000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack1);
ASSERT_EQ(Bbr->MinRtt, 30000u);
// Second ACK 11 seconds later - MinRtt expires (kBbrMinRttExpirationInMicroSecs = 10s)
CC->QuicCongestionControlOnDataSent(CC, 5000);
uint64_t ExpiredTime = 1000000 + 11000000; // 11 seconds later
QUIC_ACK_EVENT Ack2 = MakeBbrAckEvent(ExpiredTime, 3, 4, 1200, 50000, 50000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack2);
// MinRtt should be updated to the new (larger) value since old one expired
ASSERT_EQ(Bbr->MinRtt, 50000u);
}
//
// Test: OnDataAcknowledged - MinRtt Not Updated When MinRttValid is FALSE
// Scenario: Sends 5000 bytes, then acknowledges with MinRttValid=FALSE. When the RTT
// sample is marked invalid, BBR should not update MinRtt.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_MinRttNotValid)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(1050000, 5, 10, 1200, 50000, 30000, FALSE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
// MinRtt should remain at UINT64_MAX since MinRttValid is FALSE
ASSERT_EQ(Bbr->MinRtt, UINT64_MAX);
}
//
// Test: OnDataAcknowledged - MinRtt Not Updated When New Sample is Larger
// Scenario: First ACK sets MinRtt=30000us. Second ACK arrives within the expiration
// window with MinRtt=40000us. Since the new sample (40000) is larger than the
// existing MinRtt (30000) and the timer has not expired, BBR keeps the old value.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_MinRttNoUpdate)
{
InitializeWithDefaults();
// First ACK sets MinRtt = 30000
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack1 = MakeBbrAckEvent(1000000, 1, 2, 1200, 50000, 30000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack1);
ASSERT_EQ(Bbr->MinRtt, 30000u);
// Second ACK within expiration time with larger MinRtt
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack2 = MakeBbrAckEvent(2000000, 3, 4, 1200, 50000, 40000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack2);
// MinRtt should NOT be updated (30000 < 40000 and not expired)
ASSERT_EQ(Bbr->MinRtt, 30000u);
}
//
// Test: OnDataAcknowledged - New Round Trip Detection
// Scenario: Sends 5000 bytes via OnDataSent, then acknowledges 1200 bytes with
// LargestAck=5. Since this is the first ACK, it triggers a new round trip.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_NewRoundTrip)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(1050000, 5, 10, 1200);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
// EndOfRoundTripValid should now be TRUE, RoundTripCounter incremented
ASSERT_TRUE(Bbr->EndOfRoundTripValid);
ASSERT_EQ(Bbr->RoundTripCounter, 1u);
}
//
// Test: OnDataAcknowledged - Recovery Exit on No-Loss ACK Past Recovery Point
// Scenario: Enters CONSERVATIVE recovery via a 1200-byte loss. Then ACKs with
// HasLoss=FALSE and LargestAck=15 (exceeding EndOfRecovery). With no ongoing loss
// and the ACK past the recovery point, BBR should exit recovery.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_RecoveryExit)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 10000);
Connection.Send.NextPacketNumber = 10;
// Enter recovery
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(1200, 5, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_CONSERVATIVE);
// ACK past recovery point with no loss
Connection.Send.NextPacketNumber = 20;
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(1200000, 15, 25, 1200);
Ack.HasLoss = FALSE;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_NOT_RECOVERY);
}
//
// Test: OnDataAcknowledged - Stay in Recovery When Loss Continues
// Scenario: Enters CONSERVATIVE recovery via a 1200-byte loss from 10000 bytes in
// flight. Then ACKs 1200 bytes with HasLoss=TRUE and LargestAck=3 (below EndOfRecovery).
// Since loss is still present and the ACK hasn't passed the recovery point, BBR stays
// in recovery and updates the RecoveryWindow.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_RecoveryStayUpdateWindow)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 10000);
Connection.Send.NextPacketNumber = 10;
// Enter recovery
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(1200, 5, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
// ACK while still in recovery (HasLoss=TRUE, LargestAck < EndOfRecovery)
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(1100000, 3, 12, 1200);
Ack.HasLoss = TRUE;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
// Should still be in recovery
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_CONSERVATIVE);
// RecoveryWindow: on first entry, RW = max(BIF_after_loss, MinCW) = 8800.
// On this ACK in CONSERVATIVE: RW = max(RW, BIF - AckBytes + AckBytes) = max(8800, 8800)
uint32_t BytesAfterLoss = 10000u - 1200u;
ASSERT_EQ(Bbr->RecoveryWindow, BytesAfterLoss);
}
//
// Test: OnDataAcknowledged - Transition to PROBE_RTT When MinRtt Expires
// Scenario: First ACK at T=1000000 establishes MinRtt=30000 and sets MinRttTimestamp.
// Second ACK arrives 11 seconds later (past the 10s expiration). With
// ExitingQuiescence=FALSE, the expired MinRtt triggers a transition to BBR_STATE_PROBE_RTT.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_TransitToProbeRtt)
{
InitializeWithDefaults();
DriveToProbeRtt();
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_PROBE_RTT);
}
//
// Test: OnDataAcknowledged - ExitingQuiescence Suppresses PROBE_RTT
// Scenario: Establishes MinRtt via first ACK, then drains BytesInFlight to 0 and sets
// AppLimited. The next OnDataSent sets ExitingQuiescence=TRUE (BytesInFlight was 0 and
// AppLimited). An ACK 11 seconds later with expired MinRtt would normally trigger
// PROBE_RTT, but ExitingQuiescence suppresses the transition and is then cleared.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_ExitingQuiescenceSuppressesProbeRtt)
{
InitializeWithDefaults();
// First ACK establishes MinRtt
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack1 = MakeBbrAckEvent(1000000, 1, 2, 1200, 50000, 30000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack1);
// Now set app limited + zero BytesInFlight to trigger ExitingQuiescence on next send.
// ACK all in-flight bytes (send Remaining more, then ack everything).
uint32_t Remaining = Bbr->BytesInFlight;
CC->QuicCongestionControlOnDataSent(CC, Remaining);
QUIC_ACK_EVENT AckAll = MakeBbrAckEvent(1050000, 5, 6, Remaining * 2);
CC->QuicCongestionControlOnDataAcknowledged(CC, &AckAll);
ASSERT_EQ(Bbr->BytesInFlight, 0u);
CC->QuicCongestionControlSetAppLimited(CC);
// Now send+ack with expired MinRtt but ExitingQuiescence = TRUE
CC->QuicCongestionControlOnDataSent(CC, 5000); // This should set ExitingQuiescence
uint64_t ExpiredTime = 1000000 + 11000000;
QUIC_ACK_EVENT Ack2 = MakeBbrAckEvent(ExpiredTime, 10, 12, 1200, 50000, 35000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack2);
// ExitingQuiescence suppressed PROBE_RTT, then was cleared
ASSERT_FALSE(Bbr->ExitingQuiescence);
// The key assertion: BbrState should NOT be PROBE_RTT
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_STARTUP);
}
//
// Test: OnDataAcknowledged - BtlbwFound Detection in STARTUP
// Scenario: Drives BBR through STARTUP using DriveToBtlbwFound(), which pumps multiple
// rounds of stagnant bandwidth (below the 1.25x growth target). After enough consecutive
// non-growing rounds, BBR detects that bottleneck bandwidth has been found.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_BtlbwFoundDetection)
{
InitializeWithDefaults();
DriveToBtlbwFound();
// After driving with stagnant bandwidth, BtlbwFound should be TRUE
ASSERT_TRUE(Bbr->BtlbwFound);
}
//
// Test: OnDataAcknowledged - STARTUP to DRAIN Transition
// Scenario: Manually replicates BtlbwFound detection but inflates BytesInFlight to
// 100000 before the final round, so BytesInFlight > TargetCwnd and the DRAIN→PROBE_BW
// transition does NOT fire immediately. BBR should be in DRAIN after BtlbwFound.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_StartupToDrain)
{
InitializeWithDefaults();
uint64_t TimeNow = 1000000;
// Round 1: Establish bandwidth in the filter.
{
auto PacketBuf = MakeBbrPacket(
1200, TRUE, FALSE,
12000, TimeNow,
0, TimeNow - 100000,
0, TimeNow - 50000, TimeNow - 50000);
auto& Pkt = PacketBuf.Metadata;
CC->QuicCongestionControlOnDataSent(CC, 1200);
TimeNow += 50000;
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(TimeNow, 10, 20, 1200, 50000, 45000, TRUE);
Ack.AckedPackets = &Pkt;
Ack.IsLargestAckedPacketAppLimited = FALSE;
Ack.NumTotalAckedRetransmittableBytes = 12000;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
}
// Rounds 2-4: Same bandwidth → triggers BtlbwFound after 3 non-growing rounds.
uint64_t LargestAck = 25;
uint64_t LargestSent = 30;
for (int round = 0; round < 4; round++) {
auto PacketBuf = MakeBbrPacket(
1200, TRUE, FALSE,
12000, TimeNow,
0, TimeNow - 100000,
0, TimeNow - 50000, TimeNow - 50000);
auto& Pkt = PacketBuf.Metadata;
CC->QuicCongestionControlOnDataSent(CC, 1200);
// Before the last round, inflate BytesInFlight so DRAIN doesn't immediately
// transition to PROBE_BW (requires BytesInFlight > TargetCwnd).
if (round == 3 || (round >= 2 && Bbr->SlowStartupRoundCounter >= 2)) {
CC->QuicCongestionControlOnDataSent(CC, 100000);
}
TimeNow += 50000;
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(TimeNow, LargestAck, LargestSent, 1200, 50000, 45000, TRUE);
Ack.AckedPackets = &Pkt;
Ack.IsLargestAckedPacketAppLimited = FALSE;
Ack.NumTotalAckedRetransmittableBytes = 12000;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
LargestAck = LargestSent + 5;
LargestSent += 10;
if (Bbr->BtlbwFound) break;
}
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_DRAIN);
}
//
// Test: OnDataAcknowledged - DRAIN to PROBE_BW Transition
// Scenario: Calls DriveToBtlbwFound() which transitions through STARTUP → DRAIN.
// Because BytesInFlight is near zero after the helper completes, the DRAIN → PROBE_BW
// transition fires immediately upon entering DRAIN.
//
TEST_F(BbrTest_DeepTest, OnDataAcknowledged_DrainToProbeBw)
{
InitializeWithDefaults();
DriveToBtlbwFound();
// BytesInFlight=0 after DriveToBtlbwFound so DRAIN->PROBE_BW happens immediately
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_PROBE_BW);
}
//
// Test: HandleAckInProbeRtt - Start ProbeRtt Timer
// Scenario: Drives BBR to PROBE_RTT by establishing MinRtt, then sending an ACK 11
// seconds later to expire the MinRtt timer. Once in PROBE_RTT, sends 100 bytes and
// ACKs to trigger the probe RTT timer start (BytesInFlight falls below the probe
// threshold of 4*DatagramPayloadLength).
//
TEST_F(BbrTest_DeepTest, HandleAckInProbeRtt_StartTimer)
{
InitializeWithDefaults();
uint64_t ExpiredTime = DriveToProbeRtt();
CC->QuicCongestionControlOnDataSent(CC, 100);
QUIC_ACK_EVENT ProbeAck = MakeBbrAckEvent(ExpiredTime + 1000, 7, 8, 100);
CC->QuicCongestionControlOnDataAcknowledged(CC, &ProbeAck);
ASSERT_TRUE(Bbr->ProbeRttEndTimeValid);
}
//
// Test: HandleAckInProbeRtt - Exit PROBE_RTT to STARTUP
// Scenario: Drives BBR to PROBE_RTT state via expired MinRtt. Then pumps small
// send/ack pairs (100 bytes each) over 20 iterations until the ProbeRtt timer expires
// and BBR exits. With BtlbwFound=FALSE (never detected bottleneck bandwidth), BBR
// transitions back to STARTUP.
//
TEST_F(BbrTest_DeepTest, HandleAckInProbeRtt_ExitToStartup)
{
InitializeWithDefaults();
uint64_t ExpiredTime = DriveToProbeRtt();
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_PROBE_RTT);
uint64_t T = ExpiredTime;
for (int i = 0; i < 20; i++) {
T += 50000;
CC->QuicCongestionControlOnDataSent(CC, 100);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(T, 10 + i, 20 + i, 100);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
if (Bbr->BbrState != (uint32_t)BBR_STATE_PROBE_RTT) break;
}
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_STARTUP);
}
//
// Test: HandleAckInProbeRtt - Exit PROBE_RTT to PROBE_BW
// Scenario: Drives BBR to PROBE_BW via DriveToBtlbwFound() (BtlbwFound=TRUE), then
// triggers PROBE_RTT by waiting 11 seconds for MinRtt expiration. Pumps small send/ack
// pairs over 30 iterations until the ProbeRtt timer expires. With BtlbwFound=TRUE, BBR
// transitions to PROBE_BW instead of STARTUP.
//
TEST_F(BbrTest_DeepTest, HandleAckInProbeRtt_ExitToProbeBw)
{
InitializeWithDefaults();
// Drive to BtlbwFound then to PROBE_RTT
uint64_t TimeNow = DriveToBtlbwFound();
// Drive to PROBE_BW first
for (int i = 0; i < 20; i++) {
TimeNow += 50000;
CC->QuicCongestionControlOnDataSent(CC, 1200);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(TimeNow, 200 + i, 210 + i, 1200);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
if (Bbr->BbrState == (uint32_t)BBR_STATE_PROBE_BW) break;
}
// Now trigger PROBE_RTT by waiting 10+ seconds
uint64_t ExpiredTime = TimeNow + 11000000;
CC->QuicCongestionControlOnDataSent(CC, 1000);
QUIC_ACK_EVENT AckExpired = MakeBbrAckEvent(ExpiredTime, 300, 310, 1000, 50000, 35000, TRUE);
CC->QuicCongestionControlOnDataAcknowledged(CC, &AckExpired);
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_PROBE_RTT);
uint64_t T = ExpiredTime;
for (int i = 0; i < 30; i++) {
T += 50000;
CC->QuicCongestionControlOnDataSent(CC, 100);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(T, 400 + i, 410 + i, 100);
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
if (Bbr->BbrState != (uint32_t)BBR_STATE_PROBE_RTT) break;
}
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_PROBE_BW);
}
//
// Test: BtlbwFound - Growing Bandwidth Resets Stagnation Counter
// Scenario: Pumps 5 rounds of exponentially growing bandwidth (doubling each round from
// 500000). Since each round's bandwidth exceeds the 1.25x growth target relative to the
// previous round, the SlowStartupRoundCounter resets and BtlbwFound never triggers.
//
TEST_F(BbrTest_DeepTest, BtlbwFound_BandwidthGrowingResetsCounter)
{
InitializeWithDefaults();
uint64_t TimeNow = 1000000;
uint64_t PktNum = 1;
uint64_t Rate = 500000;
// Keep growing bandwidth → SlowStartupRoundCounter should stay at 0
for (int i = 0; i < 5; i++) {
Rate = Rate * 2; // Double each round → well above kStartupGrowthTarget
TimeNow += 50000;
PumpBandwidthSample(TimeNow, PktNum++, 1200, Rate, 45000);
}
// BtlbwFound should still be FALSE since bandwidth keeps growing
ASSERT_FALSE(Bbr->BtlbwFound);
ASSERT_EQ(Bbr->BbrState, (uint32_t)BBR_STATE_STARTUP);
ASSERT_EQ(Bbr->SlowStartupRoundCounter, 0u);
}
//
// Test: UpdateRecoveryWindow - GROWTH State Adds Bytes
// Scenario: Enters CONSERVATIVE recovery via 1200-byte loss from 10000 bytes in flight.
// Then sends 5000 more bytes and ACKs 2000 with HasLoss=TRUE and LargestAck=15
// (new round trip triggers CONSERVATIVE → GROWTH). In GROWTH state, RecoveryWindow
// increases by BytesAcked: max(RecoveryWindow + BytesAcked, BytesInFlight + BytesAcked).
//
TEST_F(BbrTest_DeepTest, RecoveryWindow_GrowthAddsBytes)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 10000);
Connection.Send.NextPacketNumber = 10;
// Enter recovery
QUIC_LOSS_EVENT Loss = MakeBbrLossEvent(1200, 5, 10);
CC->QuicCongestionControlOnDataLost(CC, &Loss);
// ACK in recovery with new round trip → CONSERVATIVE → GROWTH
Connection.Send.NextPacketNumber = 20;
CC->QuicCongestionControlOnDataSent(CC, 5000);
QUIC_ACK_EVENT Ack = MakeBbrAckEvent(1100000, 15, 25, 2000);
Ack.HasLoss = TRUE;
CC->QuicCongestionControlOnDataAcknowledged(CC, &Ack);
ASSERT_EQ(Bbr->RecoveryState, (uint32_t)RECOVERY_STATE_GROWTH);
// In GROWTH: RecoveryWindow = max(oldRW + BytesAcked, BytesInFlight + BytesAcked)
// oldRW = max(BIF_after_loss, MinCW) = max(8800, 4928) = 8800
// BIF now = 10000 - 1200 + 5000 - 2000 = 11800 (after loss, send, ack)
// max(8800 + 2000, 11800 + 2000) = max(10800, 13800) = 13800
uint32_t BifAfterLoss = 10000u - 1200u; // 8800
uint32_t BifNow = BifAfterLoss + 5000u - 2000u; // 11800
uint32_t ExpectedRW = BifAfterLoss + 2000u; // 10800
if (BifNow + 2000u > ExpectedRW) ExpectedRW = BifNow + 2000u; // 13800
ASSERT_EQ(Bbr->RecoveryWindow, ExpectedRW);
}
//====================================================================
//
// Implementation-specific tests - loosely coupled
//
// These tests exercise MsQuic-specific features (pacing API,
// exemptions, statistics, blocked state) but assert only through
// public CC vtable outputs. They would survive an internal refactor.
//
//====================================================================
//
// Test: CanSend - Returns TRUE When BytesInFlight Below CongestionWindow
// Scenario: Initializes BBR with defaults (BytesInFlight=0). With no data in flight,
// BytesInFlight < CongestionWindow so sending is allowed.
//
TEST_F(BbrTest_DeepTest, CanSend_BelowCW)
{
InitializeWithDefaults();
ASSERT_TRUE(CC->QuicCongestionControlCanSend(CC));
}
//
// Test: CanSend - Returns TRUE With Exemptions Despite Full Window
// Scenario: Sets 5 exemptions via SetExemption, then sends CW bytes to fill the
// congestion window. Even though BytesInFlight == CW, the remaining exemptions bypass
// the congestion blocked check.
//
TEST_F(BbrTest_DeepTest, CanSend_WithExemptions)
{
InitializeWithDefaults();
uint32_t CW = CC->QuicCongestionControlGetCongestionWindow(CC);
CC->QuicCongestionControlSetExemption(CC, 5);
CC->QuicCongestionControlOnDataSent(CC, CW);
// BytesInFlight == CW, but exemptions remain (5-1 from send = 4 if decremented,
// or still > 0)
ASSERT_TRUE(CC->QuicCongestionControlCanSend(CC));
}
//
// Test: GetSendAllowance - Returns 0 When Congestion Blocked
// Scenario: Sends CW bytes to fill the congestion window, then calls
// GetSendAllowance with TimeSinceLastSend=1000 and SlowStartup=TRUE. When the
// connection is congestion blocked (BytesInFlight >= CW), the allowance is 0.
//
TEST_F(BbrTest_DeepTest, GetSendAllowance_CcBlocked)
{
InitializeWithDefaults();
uint32_t CW = CC->QuicCongestionControlGetCongestionWindow(CC);
CC->QuicCongestionControlOnDataSent(CC, CW);
uint32_t Allowance = CC->QuicCongestionControlGetSendAllowance(CC, 1000, TRUE);
ASSERT_EQ(Allowance, 0u);
}
//
// Test: GetSendAllowance - No Pacing With Invalid TimeSinceLastSend
// Scenario: Sends 1000 bytes with pacing disabled, then calls GetSendAllowance with
// TimeSinceLastSend=0 and SlowStartup=FALSE. Without pacing, the allowance is simply
// CW - BytesInFlight regardless of timing.
//
TEST_F(BbrTest_DeepTest, GetSendAllowance_NoPacing_TimeSinceLastSendInvalid)
{
InitializeWithDefaults();
CC->QuicCongestionControlOnDataSent(CC, 1000);
uint32_t Allowance = CC->QuicCongestionControlGetSendAllowance(CC, 0, FALSE);
uint32_t CW = CC->QuicCongestionControlGetCongestionWindow(CC);
ASSERT_EQ(Allowance, CW - 1000u);
}
//
// Test: GetSendAllowance - Pacing Disabled Falls Back to Window