Repository navigation
Expand file tree
/
Copy pathcongestion_bbr3_test.go
More file actions
1902 lines (1841 loc) · 77.6 KB
/
Copy pathcongestion_bbr3_test.go
File metadata and controls
1902 lines (1841 loc) · 77.6 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
package mipstack
import (
"bytes"
"context"
"encoding/binary"
"fmt"
"net/netip"
"sort"
"sync"
"sync/atomic"
"testing"
"time"
)
type bbr3TailProbeRecorder struct {
algorithm *bbr3CongestionControl
seen atomic.Bool
acks atomic.Uint64
recovery atomic.Uint64
}
type bbr3RenegingRecorder struct {
algorithm *bbr3CongestionControl
validLoss atomic.Uint64
staleLoss atomic.Uint64
lostBytes atomic.Uint64
onPacketSent func()
}
type bbr3Retransmission struct {
flight uint32
snapshot uint32
bytes int
phase CongestionPhase
}
type bbr3RetransmissionRecorder struct {
algorithm *bbr3CongestionControl
published chan bbr3Retransmission
}
func (r *bbr3RetransmissionRecorder) HandleCongestionEvent(event *CongestionEvent) {
r.algorithm.HandleCongestionEvent(event)
if event.Type == CongestionEventPacketRetransmitted {
r.published <- bbr3Retransmission{flight: event.State.BytesInFlight, snapshot: bbr3DecodePacketState(event.PacketState).inflight, bytes: event.PacketBytes, phase: event.State.Phase}
}
}
type bbr3RTOAcknowledgment struct {
before, after, snapshot, acknowledged uint32
losses uint64
valid bool
}
type bbr3RTORecorder struct {
algorithm *bbr3CongestionControl
published chan bbr3Retransmission
sent chan bbr3Retransmission
acked chan bbr3RTOAcknowledgment
}
func (r *bbr3RTORecorder) HandleCongestionEvent(event *CongestionEvent) {
before := r.algorithm.inflightHigh
r.algorithm.HandleCongestionEvent(event)
switch event.Type {
case CongestionEventInitialize:
// Seed a mature model so a safe ACK can widen an existing upper bound.
r.algorithm.mode, r.algorithm.probePhase = bbrProbeBandwidth, bbr3ProbeCruise
r.algorithm.fullBandwidthReached = true
r.algorithm.inflightHigh = uint32(4 * event.State.MaximumSegmentSize)
r.algorithm.bandwidthHigh[1] = 1_000_000
r.algorithm.probeStarted = event.Time
case CongestionEventPacketRetransmitted:
r.published <- bbr3Retransmission{flight: event.State.BytesInFlight, snapshot: bbr3DecodePacketState(event.PacketState).inflight, bytes: event.PacketBytes, phase: event.State.Phase}
case CongestionEventPacketSent:
if r.sent != nil {
r.sent <- bbr3Retransmission{flight: event.State.BytesInFlight, snapshot: bbr3DecodePacketState(event.PacketState).inflight, bytes: event.PacketBytes, phase: event.State.Phase}
}
case CongestionEventACK:
if sample := event.RateSample; sample != nil {
r.acked <- bbr3RTOAcknowledgment{
before: before, after: r.algorithm.inflightHigh,
snapshot: bbr3DecodePacketState(sample.PacketState()).inflight,
acknowledged: sample.AcknowledgedBytes(), losses: sample.LostBytes(), valid: sample.Valid(),
}
}
}
}
func (r *bbr3RenegingRecorder) HandleCongestionEvent(event *CongestionEvent) {
if event.Type == CongestionEventPacketLost {
if event.PacketLossEvidenceValid {
r.validLoss.Add(1)
} else {
r.staleLoss.Add(1)
}
r.lostBytes.Add(uint64(event.PacketBytes))
}
r.algorithm.HandleCongestionEvent(event)
if event.Type == CongestionEventPacketSent && r.onPacketSent != nil {
r.onPacketSent()
}
}
func (r *bbr3TailProbeRecorder) HandleCongestionEvent(event *CongestionEvent) {
if event.Type == CongestionEventACK && event.RateSample != nil {
r.acks.Add(1)
if event.RateSample.TailLossProbeACK() {
r.seen.Store(true)
}
}
if event.Type == CongestionEventTailLossProbeRecovered {
r.recovery.Add(1)
}
r.algorithm.HandleCongestionEvent(event)
}
func bbr3RateSample(now time.Time, delivered, acked, flight uint32, interval time.Duration) *tcpDeliveryRateSample {
remaining := uint32(0)
if acked < flight {
remaining = flight - acked
}
return &tcpDeliveryRateSample{
priorDelivered: 1,
delivered: delivered,
acked: acked,
priorInFlight: flight,
inFlight: remaining,
interval: interval,
rtt: interval,
smoothedRTT: interval,
ackTime: now,
valid: interval > 0,
}
}
func TestBBR3PacketStatePreservesLossInputs(t *testing.T) {
state := CongestionState{
BytesInFlight: 20_000,
LostBytes: uint64(^uint32(0)) + 123,
ApplicationLimited: true,
}
encoded := bbr3EncodePacketState(&state, 1000)
decoded := bbr3DecodePacketState(encoded)
if decoded.inflight != 21_000 || decoded.lost != 122 || !decoded.applicationLimited {
t.Fatalf("decoded packet state = %+v", decoded)
}
state.BytesInFlight = bbr3PacketInflightMask
decoded = bbr3DecodePacketState(bbr3EncodePacketState(&state, 1000))
if decoded.inflight != bbr3PacketInflightMask {
t.Fatalf("saturated tx.in_flight = %d, want %d", decoded.inflight, bbr3PacketInflightMask)
}
}
func TestBBR3InitialWindowFollowsControllerInitialization(t *testing.T) {
const mss = 1000
bbr := newBBR3CongestionControl()
state := CongestionState{CongestionWindow: 40 * mss, MaximumSegmentSize: mss, SmoothedRTT: time.Millisecond}
bbr.HandleCongestionEvent(&CongestionEvent{Type: CongestionEventInitialize, Time: time.Unix(100, 0), State: &state})
if bbr.initialWindowMSS != 40 || bbr.modelWindowForBandwidth(0, 1, mss) != 40*mss {
t.Fatalf("initial window = %d MSS/%d bytes", bbr.initialWindowMSS, bbr.modelWindowForBandwidth(0, 1, mss))
}
if got := bbr3InitialWindowMSS(tcpMaximumScaledWindow, mss); got != 127 {
t.Fatalf("capped initial window = %d MSS, want 127", got)
}
}
func TestBBR3StartupWindowIncludesACKAggregation(t *testing.T) {
const mss = 1000
bbr := newBBR3CongestionControl()
bbr.initialWindowMSS = bbrInitialCongestionMSS
bbr.minimumRTT = 10 * time.Millisecond
bbr.bandwidthHigh[1] = 1_000_000
bbr.extraACKed[0] = 10_000
sample := bbr3RateSample(time.Unix(100, 0), mss, mss, 25*mss, time.Millisecond)
if window := bbr.setCongestionWindow(25*mss, sample, mss); window != 26*mss {
t.Fatalf("Startup ACK-aggregation window = %d, want %d", window, 26*mss)
}
}
func TestBBR3UsesLinuxDefaultGains(t *testing.T) {
bbr := newBBR3CongestionControl()
if gain := bbr.pacingGain(); gain != 710.0/256 {
t.Fatalf("Startup pacing gain = %v", gain)
}
bbr.mode = bbrDrain
if gain := bbr.pacingGain(); gain != 88.0/256 {
t.Fatalf("Drain pacing gain = %v", gain)
}
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeDown
if gain := bbr.pacingGain(); gain != 232.0/256 {
t.Fatalf("ProbeDOWN pacing gain = %v", gain)
}
bbr.probePhase = bbr3ProbeUp
if gain := bbr.pacingGain(); gain != 1.25 || bbr.congestionWindowGain() != 2.25 {
t.Fatalf("ProbeUP gains = pacing %v cwnd %v", gain, bbr.congestionWindowGain())
}
}
func TestBBR3StartupPlateauEntersDrain(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.minimumRTT = 10 * time.Millisecond
bbr.bandwidthHigh[1] = 1_000_000
bbr.fullBandwidth = 1_000_000
for round := 0; round < bbrFullBandwidthRounds; round++ {
bbr.roundStart = true
bbr.checkFullBandwidth(bbr3RateSample(now.Add(time.Duration(round)*time.Millisecond), 1000, 1000, 10_000, time.Millisecond), 1_000_000)
}
if !bbr.fullBandwidthReached {
t.Fatal("three stagnant rounds did not fill the pipe")
}
sample := bbr3RateSample(now, 1000, 1000, 1000, time.Millisecond)
threshold := bbr.checkDrain(sample, mss)
if bbr.mode != bbrProbeBandwidth || bbr.probePhase != bbr3ProbeDown || threshold == 0 {
t.Fatalf("post-Startup state = mode %v phase %v threshold %d", bbr.mode, bbr.probePhase, threshold)
}
}
func TestBBR3ProbeBandwidthCycle(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.minimumRTT = 10 * time.Millisecond
bbr.bandwidthHigh[1] = 1_000_000
bbr.fullBandwidthReached = true
bbr.enterProbePhase(bbr3ProbeDown, now)
bbr.probeWait = 2 * time.Second
sample := bbr3RateSample(now, 1000, 1000, 4000, time.Millisecond)
bbr.updateProbeBandwidth(sample, bbr3PacketSnapshot{}, 1_000_000, 20_000, mss)
if bbr.probePhase != bbr3ProbeCruise {
t.Fatalf("drained phase = %s", bbr.probePhase.String())
}
sample.ackTime = now.Add(2*time.Second + time.Microsecond)
bbr.updateProbeBandwidth(sample, bbr3PacketSnapshot{}, 1_000_000, 20_000, mss)
if bbr.probePhase != bbr3ProbeRefill || bbr.ackPhase != bbr3ACKsRefilling {
t.Fatalf("scheduled probe = phase %s ACK phase %d", bbr.probePhase.String(), bbr.ackPhase)
}
bbr.roundStart = true
bbr.roundCount++
bbr.updateProbeBandwidth(sample, bbr3PacketSnapshot{}, 1_000_000, 20_000, mss)
if bbr.probePhase != bbr3ProbeUp || !bbr.probeSamples {
t.Fatalf("refill completion = phase %s samples %t", bbr.probePhase.String(), bbr.probeSamples)
}
}
func TestBBR3BandwidthFilterRotatesAfterProbeFeedback(t *testing.T) {
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.fullBandwidthReached = true
bbr.ackPhase = bbr3ACKsProbeStopping
bbr.probeSamples = true
bbr.roundStart = true
bbr.bandwidthHigh = [2]float64{800_000, 1_000_000}
sample := bbr3RateSample(time.Unix(100, 0), 1000, 1000, 10_000, time.Millisecond)
bbr.adaptUpperBounds(sample, bbr3PacketSnapshot{}, 20_000, 1000)
if bbr.probeSamples || bbr.ackPhase != bbr3ACKsInitial || bbr.bandwidthHigh != [2]float64{1_000_000, 0} {
t.Fatalf("rotated probe feedback = samples %t phase %d bw %v", bbr.probeSamples, bbr.ackPhase, bbr.bandwidthHigh)
}
}
func TestBBR3LossBoundsAndProbePrefix(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeUp
bbr.probeSamples = true
bbr.bandwidthHigh[1] = 1_000_000
bbr.minimumRTT = 10 * time.Millisecond
state := CongestionState{CongestionWindow: 20_000, MaximumSegmentSize: mss, LostBytes: 500}
packetState := bbr3EncodePacketState(&CongestionState{BytesInFlight: 19_000}, mss)
event := CongestionEvent{Type: CongestionEventPacketLost, Time: now, State: &state, PacketBytes: mss, PacketState: packetState, PacketLossEvidenceValid: true}
bbr.onPacketLost(&event)
if bbr.inflightHigh == 0 || bbr.inflightHigh >= 20_000 || bbr.probeSamples || bbr.probePhase != bbr3ProbeDown {
t.Fatalf("probe loss response = inflight_hi %d samples %t phase %s", bbr.inflightHigh, bbr.probeSamples, bbr.probePhase.String())
}
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeCruise
bbr.bandwidthLow = 1_000_000
bbr.inflightLow = 20_000
bbr.latestBandwidth = 800_000
bbr.latestInflight = 16_000
bbr.lossInRound = true
bbr.lossRoundStart = true
bbr.updateCongestionSignals(bbr3RateSample(now, 1000, 1000, 10_000, time.Millisecond), 1_000_000, 20_000)
if bbr.bandwidthLow != 800_000 || bbr.inflightLow != 16_000 {
t.Fatalf("lower bounds = %v/%d", bbr.bandwidthLow, bbr.inflightLow)
}
}
func TestBBR3RenegingLossDoesNotUseProbeEvidence(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode, bbr.probePhase = bbrProbeBandwidth, bbr3ProbeUp
bbr.fullBandwidthReached, bbr.probeSamples = true, true
bbr.minimumRTT, bbr.minimumRTTStamp = 10*time.Millisecond, now
bbr.bandwidthHigh[1], bbr.probeStarted = 1_000_000, now
state := CongestionState{CongestionWindow: 20_000, MaximumSegmentSize: mss, LostBytes: 500}
event := CongestionEvent{
Type: CongestionEventPacketLost,
Time: now,
State: &state,
PacketBytes: mss,
PacketState: bbr3EncodePacketState(&CongestionState{BytesInFlight: 19_000}, mss),
PacketLossEvidenceValid: false,
}
bbr.onPacketLost(&event)
if !bbr.lossInRound || bbr.lost != state.LostBytes || !bbr.probeSamples || bbr.probePhase != bbr3ProbeUp || bbr.inflightHigh != 0 {
t.Fatalf("reneging loss feedback = lossInRound:%v samples:%v phase:%s inflight_hi:%d", bbr.lossInRound, bbr.probeSamples, bbr.probePhase.String(), bbr.inflightHigh)
}
}
func TestTCPBBR3SACKRenegingLossEvidence(t *testing.T) {
local, remote := netip.MustParseAddr("192.0.2.192"), netip.MustParseAddr("198.51.100.192")
link, stack := newTestStack(t, local, remote)
defer stack.Close()
recorder := &bbr3RenegingRecorder{algorithm: newBBR3CongestionControl()}
builtin, _ := registeredCongestionControlFactory(CongestionControlBBR3)
definition := builtin.definition
definition.Name = "BBRv3-reneging"
definition.New = func(CongestionControlContext) CongestionController { return recorder }
factory, err := NewCongestionControlFactory(definition)
if err != nil {
t.Fatal(err)
}
if err = stack.UpdateConfig(Config{LocalAddresses: []netip.Prefix{netip.PrefixFrom(local, 32)},
TCP: TCPSocketDefaults{CongestionControlFactory: factory}}); err != nil {
t.Fatal(err)
}
link.mu.Lock()
link.echoTCP, link.sackTCP, link.sackReneging = true, true, true
link.dropTCPOrdinals = map[int]bool{1: true}
link.mu.Unlock()
connection, err := stack.DialTCP(context.Background(), "tcp4", netip.AddrPort{}, netip.AddrPortFrom(remote, 8103))
if err != nil {
t.Fatal(err)
}
defer connection.Close()
if err = connection.SetDeadline(time.Now().Add(5 * time.Second)); err != nil {
t.Fatal(err)
}
writeAndReadTCPEcho(t, connection, make([]byte, 16*1024))
link.mu.Lock()
renege := !link.sackRenegingAt.IsZero()
link.mu.Unlock()
if !renege || recorder.staleLoss.Load() < 2 || recorder.validLoss.Load() == 0 || recorder.lostBytes.Load() == 0 {
t.Fatalf("reneging:%t stale-loss:%d ordinary-loss:%d bytes:%d", renege, recorder.staleLoss.Load(), recorder.validLoss.Load(), recorder.lostBytes.Load())
}
if undos := connection.(*TCPConn).Info().SpuriousRecoveryUndos; undos != 0 {
t.Fatalf("reneging produced %d spurious undos", undos)
}
}
// TestTCPBBR3SACKRenegingAfterHostQueueDeparture exercises the Linux-style
// host-queue barrier around SACK reneging. After the first loss is recovered,
// the peer reneges on the second SACKed range, which must wait for its
// departure before publishing loss without stale probe evidence.
func TestTCPBBR3SACKRenegingAfterHostQueueDeparture(t *testing.T) {
link, stack, connection := newManuallyPumpedTCPConnection(t)
defer connection.Close()
recorder := &bbr3RenegingRecorder{algorithm: newBBR3CongestionControl()}
builtin, _ := registeredCongestionControlFactory(CongestionControlBBR3)
definition := builtin.definition
definition.Name = "BBRv3-host-queue-reneging"
// Park after both original publications so the peer's SACK is queued
// before the actor can run a loss timer.
flightReady, releaseFlight := make(chan struct{}), make(chan struct{})
var releaseOnce sync.Once
defer releaseOnce.Do(func() { close(releaseFlight) })
sent := 0
recorder.onPacketSent = func() {
sent++
if sent == 2 {
close(flightReady)
<-releaseFlight
}
}
definition.New = func(CongestionControlContext) CongestionController { return recorder }
factory, err := NewCongestionControlFactory(definition)
if err != nil {
t.Fatal(err)
}
if err = connection.SetCongestionControlFactory(factory); err != nil {
t.Fatal(err)
}
info := connection.Info()
if info.CongestionControl != definition.Name {
t.Fatalf("congestion controller = %q, want %q", info.CongestionControl, definition.Name)
}
link.mu.Lock()
link.dropTCPOrdinals = map[int]bool{1: true}
link.sackReneging = true
link.mu.Unlock()
type queuedData struct {
raw []byte
slot uint16
sequence uint32
generation uint64
}
snapshotData := func() []queuedData {
scheduler := stack.outbound.scheduler
if scheduler == nil {
return nil
}
scheduler.mu.Lock()
defer scheduler.mu.Unlock()
packets := make([]queuedData, 0, scheduler.queued)
for slot := range scheduler.nodes {
entry := scheduler.nodes[slot].entry
if len(entry.packet) == 0 {
continue
}
packet, parseErr := ParseIPPacket(entry.packet)
if parseErr != nil || packet.Protocol != ProtocolTCP {
continue
}
segment, parseErr := packet.TCPSegment()
if parseErr != nil || len(segment.Payload) == 0 {
continue
}
packets = append(packets, queuedData{
raw: append([]byte(nil), entry.packet...), slot: uint16(slot), sequence: segment.SequenceNumber,
generation: stack.outbound.slots[slot].Load() >> packetQueueSlotGenerationShift,
})
}
sort.Slice(packets, func(i, j int) bool {
return tcpSequenceLess(packets[i].sequence, packets[j].sequence)
})
return packets
}
payload := bytes.Repeat([]byte{0x7a}, 2*info.MaximumSegmentSize)
if n, err := connection.Write(payload); err != nil || n != len(payload) {
t.Fatalf("TCP Write = %d, %v", n, err)
}
select {
case <-flightReady:
case <-time.After(time.Second):
t.Fatal("initial flight was not published")
}
initial := snapshotData()
if len(initial) != 2 {
t.Fatalf("initial queued ranges = %d, want 2", len(initial))
}
first, second := initial[0], initial[1]
// The first original leaves the queue before the peer can SACK the second.
// Recovery may then start on the ACK path or the RACK timer path without
// relying on the fixture's handshake RTT or packet-publication spacing.
entry, available := stack.outbound.tryDequeue()
if !available || entry.slot != first.slot {
if available {
stack.outbound.release(entry)
}
t.Fatalf("first host-queue departure slot = %d/%t, want %d", entry.slot, available, first.slot)
}
firstWire := consumeTestPacket(&stack.outbound, entry)
firstPacket, err := ParseIPPacket(firstWire)
if err != nil {
t.Fatal(err)
}
firstSegment, err := firstPacket.TCPSegment()
if err != nil || firstSegment.SequenceNumber != first.sequence {
t.Fatalf("departed first segment = %+v, %v", firstSegment, err)
}
if err = link.handleOutboundPacket(firstWire); err != nil {
t.Fatal(err)
}
// Keep the second original queue-owned while the peer observes its copy.
if err = link.handleOutboundPacket(second.raw); err != nil {
t.Fatal(err)
}
waitFor(t, time.Second, func() bool { return connection.inbound.len() != 0 })
// Resume with the SACK already queued. The second original remains
// host-owned throughout the first recovery.
releaseOnce.Do(func() { close(releaseFlight) })
_ = connection.Info()
var firstRetransmission queuedData
waitFor(t, time.Second, func() bool {
for _, packet := range snapshotData() {
if packet.sequence == first.sequence {
firstRetransmission = packet
return true
}
}
return false
})
if err = link.handleOutboundPacket(firstRetransmission.raw); err != nil {
t.Fatal(err)
}
_ = connection.Info()
waitFor(t, 2*info.RetransmissionTimeout+time.Second, func() bool {
waiters := stack.outbound.departureWaiters.Load()
if waiters == nil {
return false
}
waiter := waiters.slots[second.slot].Load()
return waiter != nil && waiter.generation == second.generation && waiter.departedAt.Load() == 0
})
if recorder.staleLoss.Load() != 0 {
t.Fatal("reneging loss was reported before the second original departed")
}
entry, available = stack.outbound.tryDequeue()
if !available || entry.slot != second.slot {
if available {
stack.outbound.release(entry)
}
t.Fatalf("second host-queue departure slot = %d/%t, want %d", entry.slot, available, second.slot)
}
secondWire := consumeTestPacket(&stack.outbound, entry)
secondPacket, err := ParseIPPacket(secondWire)
if err != nil {
t.Fatal(err)
}
secondSegment, err := secondPacket.TCPSegment()
if err != nil || secondSegment.SequenceNumber != second.sequence {
t.Fatalf("departed second segment = %+v, %v", secondSegment, err)
}
waitFor(t, time.Second, func() bool { return recorder.staleLoss.Load() != 0 })
if recorder.validLoss.Load() == 0 {
t.Fatal("initial RACK loss did not retain valid evidence")
}
var secondRetransmission queuedData
waitFor(t, time.Second, func() bool {
for _, packet := range snapshotData() {
if packet.sequence == second.sequence {
secondRetransmission = packet
return true
}
}
return false
})
if err = link.handleOutboundPacket(secondRetransmission.raw); err != nil {
t.Fatal(err)
}
link.mu.Lock()
renege := !link.sackRenegingAt.IsZero()
link.mu.Unlock()
if !renege {
t.Fatal("SACK reneging was not observed")
}
_ = connection.Info()
}
func TestBBR3LossThresholdIsStrictlyAboveTwoPercent(t *testing.T) {
bbr := newBBR3CongestionControl()
if bbr.inflightTooHigh(1000, 51_200) {
t.Fatal("exact fixed-point two-percent threshold was treated as excessive")
}
if !bbr.inflightTooHigh(1001, 51_200) {
t.Fatal("loss above the fixed-point two-percent threshold was accepted")
}
}
func TestBBR3ACKLossRateUsesTransmissionSnapshot(t *testing.T) {
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeUp
bbr.fullBandwidthReached = true
bbr.probeSamples = true
bbr.minimumRTT = 10 * time.Millisecond
bbr.bandwidthHigh[1] = 1_000_000
bbr.lost = 5000
sample := bbr3RateSample(time.Unix(100, 0), 1000, 1000, 20_000, time.Millisecond)
packet := bbr3PacketSnapshot{inflight: 20_000, lost: 3000}
if transitioned := bbr.adaptUpperBounds(sample, packet, 20_000, 1000); transitioned {
t.Fatal("loss response was reported as an independent state transition")
}
if bbr.inflightHigh == 0 || bbr.probeSamples || bbr.probePhase != bbr3ProbeDown {
t.Fatalf("cumulative loss response = inflight_hi %d samples %t phase %s", bbr.inflightHigh, bbr.probeSamples, bbr.probePhase.String())
}
}
func TestBBR3ACKWithoutDeliveryDoesNotInventProbeLoss(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
for _, hasSnapshot := range []bool{false, true} {
bbr := newBBR3CongestionControl()
bbr.mode, bbr.probePhase = bbrProbeBandwidth, bbr3ProbeUp
bbr.fullBandwidthReached, bbr.probeSamples = true, true
bbr.minimumRTT, bbr.minimumRTTStamp = 10*time.Millisecond, now
bbr.bandwidthHigh[1], bbr.probeStarted = 1_000_000, now
bbr.lost = 1000
sample := tcpDeliveryRateSample{ackTime: now, priorInFlight: 20_000, inFlight: 20_000, smoothedRTT: 10 * time.Millisecond}
if hasSnapshot {
// A valid transmission can have tx.lost=0 even when its rate
// interval is unusable. Its actual loss proof must still apply.
sample.packetState = bbr3EncodePacketState(&CongestionState{BytesInFlight: 19_000}, mss)
}
_, _ = bbr.onRateSample(20_000, mss, &sample)
if hasSnapshot {
if bbr.probeSamples || bbr.probePhase != bbr3ProbeDown || bbr.inflightHigh == 0 {
t.Fatalf("real transmission loss was ignored: %+v", bbr)
}
} else if !bbr.probeSamples || bbr.probePhase != bbr3ProbeUp || bbr.inflightHigh != 0 {
t.Fatalf("ACK without a transmission snapshot invented probe loss: %+v", bbr)
}
}
}
func TestBBR3SACKDeliveryDoesNotUseStaleProbeSnapshot(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode, bbr.probePhase = bbrProbeBandwidth, bbr3ProbeUp
bbr.fullBandwidthReached, bbr.probeSamples = true, true
bbr.minimumRTT, bbr.minimumRTTStamp = 10*time.Millisecond, now
bbr.bandwidthHigh[1], bbr.probeStarted = 1_000_000, now
bbr.inflightHigh = 10_000
bbr.lost = 1000
sample := tcpDeliveryRateSample{ackTime: now, priorInFlight: 20_000, inFlight: 20_000, smoothedRTT: 10 * time.Millisecond}
sample.observe(sentTCPSegment{
state: sentTCPSegmentTransmitted | sentTCPSegmentSACKed,
congestionPacketState: bbr3EncodePacketState(&CongestionState{BytesInFlight: 18_000}, mss),
hostQueue: packetQueueTicket{queuedAt: 1},
delivery: tcpDeliverySnapshot{firstSent: 1, deliveredStamp: 1},
})
if sample.PacketLossEvidenceValid() {
t.Fatal("SACK-selected transmission retained loss evidence")
}
_, _ = bbr.onRateSample(20_000, mss, &sample)
if !bbr.probeSamples || bbr.probePhase != bbr3ProbeUp || bbr.inflightHigh != 19_000 {
t.Fatalf("SACK-selected transmission feedback = samples %t phase %s inflight_hi %d, want no loss response and 19000 upper bound", bbr.probeSamples, bbr.probePhase.String(), bbr.inflightHigh)
}
}
func TestTCPSACKPreservesCongestionTransmissionState(t *testing.T) {
segment := sentTCPSegment{
sequence: 100, end: 200,
state: sentTCPSegmentInitialState(false, false, false, false),
congestionPacketState: 0x1234,
}
outstanding, _, _, newInformation, newlySACKed := applyTCPSACK(
[]sentTCPSegment{segment}, []TCPSACKBlock{{LeftEdge: 100, RightEdge: 200}},
)
if !newInformation || len(outstanding) != 1 {
t.Fatalf("SACK application = information %t ranges %d", newInformation, len(outstanding))
}
if !outstanding[0].state.has(sentTCPSegmentSACKed) {
t.Fatal("SACKed range did not enter the scoreboard")
}
if outstanding[0].congestionPacketState != 0x1234 {
t.Fatalf("SACKed congestion transmission state = %#x, want original", outstanding[0].congestionPacketState)
}
if len(newlySACKed) != 1 || newlySACKed[0].congestionPacketState != 0x1234 || !newlySACKed[0].state.has(sentTCPSegmentSACKed) {
t.Fatalf("SACK delivery sample state = %#v, want original metadata and SACK mark", newlySACKed)
}
// A retransmission is a new generation and may install fresh controller
// metadata without being confused with the SACKed transmission.
outstanding[0].state.set(sentTCPSegmentSACKed, false)
outstanding[0].advanceTransmissionGeneration()
if !outstanding[0].state.has(sentTCPSegmentTransmitted) || !outstanding[0].state.has(sentTCPSegmentRetransmitted) || outstanding[0].congestionPacketState != 0x1234 {
t.Fatalf("retransmission generation = state %#x metadata %#x", outstanding[0].state, outstanding[0].congestionPacketState)
}
outstanding[0].congestionPacketState = 0x5678
if outstanding[0].congestionPacketState != 0x5678 {
t.Fatal("retransmission did not accept fresh controller metadata")
}
}
func TestBBR3LossRoundAdvancesIndependently(t *testing.T) {
bbr := newBBR3CongestionControl()
bbr.lossRoundDelivered = 100
bbr.delivered = 200
first := bbr3RateSample(time.Unix(100, 0), 100, 100, 1000, time.Millisecond)
first.priorDelivered = 100
bbr.updateLatestDeliverySignals(first, 100_000)
if !bbr.lossRoundStart || bbr.lossRoundDelivered != 200 {
t.Fatalf("first loss round = start %t boundary %d", bbr.lossRoundStart, bbr.lossRoundDelivered)
}
second := bbr3RateSample(time.Unix(100, 0), 50, 50, 1000, time.Millisecond)
second.priorDelivered = 150
bbr.updateLatestDeliverySignals(second, 50_000)
if bbr.lossRoundStart {
t.Fatal("an ACK inside the current loss round started another round")
}
}
func TestBBR3TailLossProbeACKIsSampleScoped(t *testing.T) {
bbr := newBBR3CongestionControl()
bbr.lossRoundStart = true
bbr.latestBandwidth = 900_000
bbr.latestInflight = 9000
sample := bbr3RateSample(time.Unix(100, 0), 1000, 1000, 10_000, time.Millisecond)
sample.tailLossProbeACK = true
bbr.advanceLatestDeliverySignals(sample, 500_000)
if bbr.latestBandwidth != 900_000 || bbr.latestInflight != 9000 {
t.Fatalf("TLP ACK discarded prior delivery signals: %v/%d", bbr.latestBandwidth, bbr.latestInflight)
}
sample.tailLossProbeACK = false
bbr.advanceLatestDeliverySignals(sample, 500_000)
if bbr.latestBandwidth != 500_000 || bbr.latestInflight != 1000 {
t.Fatalf("TLP ACK state leaked into the next sample: %v/%d", bbr.latestBandwidth, bbr.latestInflight)
}
}
func TestBBR3TailLossProbeRecoveryBoundsRiskyProbe(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeUp
bbr.probeSamples = true
bbr.latestInflight = 20_000
bbr.bandwidthHigh[1] = 1_000_000
bbr.minimumRTT = 10 * time.Millisecond
state := CongestionState{
CongestionWindow: 20_000, MaximumSegmentSize: mss,
DeliveredBytes: 100_000,
}
packetState := bbr3EncodePacketState(&CongestionState{BytesInFlight: 19_000}, mss)
bbr.HandleCongestionEvent(&CongestionEvent{
Type: CongestionEventTailLossProbeRecovered, Time: now, State: &state,
PacketBytes: mss, PacketState: packetState,
})
if bbr.lossRoundDelivered != 100_000 {
t.Fatalf("TLP loss-round boundary = %d, want 100000", bbr.lossRoundDelivered)
}
if bbr.inflightHigh == 0 || bbr.probeSamples || bbr.probePhase != bbr3ProbeDown {
t.Fatalf("TLP probe response = inflight_hi %d samples %t phase %s", bbr.inflightHigh, bbr.probeSamples, bbr.probePhase.String())
}
}
func TestTCPBBR3ObservesAmbiguousTailLossProbeACK(t *testing.T) {
local := netip.MustParseAddr("192.0.2.190")
remote := netip.MustParseAddr("192.0.2.191")
recorder := &bbr3TailProbeRecorder{algorithm: newBBR3CongestionControl()}
name := nextCongestionAPITestName()
factory, err := NewCongestionControlFactory(CongestionControlDefinition{
Name: name,
New: func(CongestionControlContext) CongestionController { return recorder },
Features: CongestionControlFeatureDeliveryRate |
CongestionControlFeatureTransmissionEvents |
CongestionControlFeatureCustomPacing |
CongestionControlFeatureCustomRecovery |
CongestionControlFeatureLossEvents,
SendBufferMultiplier: 3,
})
if err != nil {
t.Fatal(err)
}
if err = RegisterCongestionControl(factory); err != nil {
t.Fatal(err)
}
link, stack := newTestStack(t, local, remote)
if err := stack.UpdateConfig(Config{
LocalAddresses: []netip.Prefix{netip.PrefixFrom(local, 32)},
MTU: 1400,
TCP: TCPSocketDefaults{CongestionControl: name},
}); err != nil {
t.Fatal(err)
}
link.mu.Lock()
link.echoTCP = true
link.mu.Unlock()
connection, err := stack.DialTCP(context.Background(), "tcp4", netip.AddrPort{}, netip.AddrPortFrom(remote, 8389))
if err != nil {
t.Fatal(err)
}
defer connection.Close()
_ = connection.SetDeadline(time.Now().Add(3 * time.Second))
writeAndReadTCPEcho(t, connection, []byte("warmup"))
link.mu.Lock()
link.holdTCPACKs = 2
link.dropTCPOrdinals = map[int]bool{3: true}
link.mu.Unlock()
writeAndReadTCPEcho(t, connection, make([]byte, 2000))
if !recorder.seen.Load() {
link.mu.Lock()
retransmitted := link.tailRetransmission
link.mu.Unlock()
info := connection.(*TCPConn).Info()
t.Fatalf("BBRv3 did not observe the ACK matching a retransmitted tail-loss probe: algorithm=%q RTT=%v ACKs=%d recovery=%d retransmitted=%t probes=%d retransmissions=%d", info.CongestionControl, info.RTT, recorder.acks.Load(), recorder.recovery.Load(), retransmitted, stack.Stats().TCPTailLossProbes, info.Retransmissions)
}
}
func TestBBR3WindowBoundsFollowMode(t *testing.T) {
const mss = 1000
bbr := newBBR3CongestionControl()
bbr.inflightHigh = 10_000
bbr.mode = bbrDrain
if got := bbr.boundWindow(20_000, mss); got != 20_000 {
t.Fatalf("Drain was capped by inflight_hi: %d", got)
}
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeDown
if got := bbr.boundWindow(20_000, mss); got != 10_000 {
t.Fatalf("ProbeDOWN inflight_hi cap = %d", got)
}
bbr.probePhase = bbr3ProbeCruise
if got := bbr.boundWindow(20_000, mss); got != 8516 {
t.Fatalf("Cruise headroom cap = %d, want 8516", got)
}
}
func TestBBR3ProbeLossDoesNotReduceLowerBounds(t *testing.T) {
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeRefill
bbr.bandwidthLow = 1_000_000
bbr.inflightLow = 20_000
bbr.latestBandwidth = 700_000
bbr.latestInflight = 14_000
bbr.lossInRound = true
bbr.lossRoundStart = true
bbr.updateCongestionSignals(bbr3RateSample(time.Unix(100, 0), 1000, 1000, 10_000, time.Millisecond), 1_000_000, 20_000)
if bbr.bandwidthLow != 1_000_000 || bbr.inflightLow != 20_000 {
t.Fatalf("probe loss reduced lower bounds to %v/%d", bbr.bandwidthLow, bbr.inflightLow)
}
}
func TestBBR3StartupLossExitRequiresRecoveryRound(t *testing.T) {
const mss = 1000
bbr := newBBR3CongestionControl()
bbr.bandwidthHigh[1] = 1_000_000
bbr.latestInflight = 20_000
bbr.lossRoundStart = true
bbr.lossEventsInRound = bbr3FullLossEvents
sample := bbr3RateSample(time.Unix(100, 0), 1000, 1000, 20_000, time.Millisecond)
sample.losses = 1000
bbr.lost = 1000
packet := bbr3PacketSnapshot{inflight: 20_000}
bbr.checkStartupLoss(sample, packet, mss)
if bbr.fullBandwidthReached {
t.Fatal("Startup exited on loss outside fast recovery")
}
bbr.lossEventsInRound = bbr3FullLossEvents
sample.fastRecovery = true
bbr.handleRecoveryEvent(&CongestionEvent{
State: &CongestionState{CongestionWindow: 24_000},
Recovery: CongestionRecovery{Stage: CongestionRecoveryCheckpoint},
})
bbr.checkStartupLoss(sample, packet, mss)
if !bbr.fullBandwidthReached || bbr.inflightHigh == 0 || bbr.undoState != bbr3UndoStartup {
t.Fatal("lossy Startup recovery round did not bound inflight")
}
bbr.checkDrain(sample, mss)
bbr.undoRecovery(sample.ackTime)
if bbr.fullBandwidthReached || bbr.mode != bbrStartup {
t.Fatal("undo did not restart loss-terminated Startup")
}
}
func TestBBR3StartupLossDuringProbeRTT(t *testing.T) {
for _, undo := range []bool{false, true} {
name := "retain loss"
if undo {
name = "undo loss"
}
t.Run(name, func(t *testing.T) {
const mss = 1000
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.bandwidthHigh[1] = 1_000_000
bbr.minimumRTT = 5 * time.Millisecond
bbr.minimumRTTStamp = now.Add(-6 * time.Second)
bbr.probeRTTMinimum, bbr.probeRTTStamp = bbr.minimumRTT, bbr.minimumRTTStamp
sample := bbr3RateSample(now, 1000, 1000, 20_000, bbr.minimumRTT)
window := bbr.updateMinimumRTT(24_000, sample, mss)
if bbr.mode != bbrProbeRTT || bbr.fullBandwidthReached {
t.Fatal("ProbeRTT did not suspend unfinished Startup")
}
bbr.handleRecoveryEvent(&CongestionEvent{
Time: now,
State: &CongestionState{CongestionWindow: window, MaximumSegmentSize: mss},
Recovery: CongestionRecovery{Stage: CongestionRecoveryCheckpoint},
})
bbr.latestInflight, bbr.lost = 20_000, 1000
bbr.lossRoundStart, bbr.lossEventsInRound = true, bbr3FullLossEvents
sample.losses, sample.fastRecovery = 1000, true
bbr.checkStartupLoss(sample, bbr3PacketSnapshot{inflight: 20_000}, mss)
if !bbr.fullBandwidthReached {
t.Fatal("loss evidence did not end Startup during ProbeRTT")
}
if undo {
bbr.handleRecoveryEvent(&CongestionEvent{
Time: now.Add(time.Millisecond),
State: &CongestionState{CongestionWindow: window, MaximumSegmentSize: mss},
Recovery: CongestionRecovery{Stage: CongestionRecoveryUndo},
})
}
if bbr.mode != bbrProbeRTT || bbr.fullBandwidthReached == undo {
t.Fatal("recovery changed ProbeRTT or retained spurious Startup completion")
}
sample.inFlight = 0
sample.ackTime = now.Add(2 * time.Millisecond)
window = bbr.updateMinimumRTT(window, sample, mss)
if bbr.probeDone.IsZero() {
t.Fatal("ProbeRTT did not start its measurement interval")
}
sample.ackTime = now.Add(time.Second)
bbr.roundStart = true
bbr.updateMinimumRTT(window, sample, mss)
wantMode := bbrProbeBandwidth
if undo {
wantMode = bbrStartup
}
if bbr.mode != wantMode {
t.Fatalf("ProbeRTT exit resumed %s, want %s", bbr.mode, wantMode)
}
})
}
}
func TestBBR3ProbeRTTUsesIndependentFiveSecondWindow(t *testing.T) {
const mss = 1000
start := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode = bbrProbeBandwidth
bbr.probePhase = bbr3ProbeCruise
bbr.fullBandwidthReached = true
bbr.bandwidthHigh[1] = 1_000_000
bbr.minimumRTT = 10 * time.Millisecond
bbr.minimumRTTStamp = start
bbr.probeRTTMinimum = 10 * time.Millisecond
bbr.probeRTTStamp = start
sample := bbr3RateSample(start.Add(bbr3ProbeRTTWindow+time.Millisecond), 1000, 1000, 20_000, time.Millisecond)
window := bbr.updateMinimumRTT(20_000, sample, mss)
if bbr.mode != bbrProbeRTT || window != 20_000 || !bbr.requestAppLimited {
t.Fatalf("ProbeRTT entry = mode %v window %d app-limited %t", bbr.mode, window, bbr.requestAppLimited)
}
bbr.probeDone = sample.ackTime.Add(-time.Millisecond)
bbr.probeRound = true
bbr.priorWindow = 20_000
bbr.roundStart = true
window = bbr.updateMinimumRTT(4000, sample, mss)
if window != 20_000 || bbr.mode != bbrProbeBandwidth || bbr.probePhase != bbr3ProbeCruise {
t.Fatalf("ProbeRTT exit = window %d mode %v phase %s", window, bbr.mode, bbr.probePhase.String())
}
}
func TestBBR3ProbeRTTExitClearsLowerBounds(t *testing.T) {
for _, idle := range []bool{false, true} {
for _, fullBandwidth := range []bool{false, true} {
t.Run(fmt.Sprintf("idle-%t/full-bandwidth-%t", idle, fullBandwidth), func(t *testing.T) {
now := time.Unix(100, 0)
bbr := newBBR3CongestionControl()
bbr.mode, bbr.fullBandwidthReached, bbr.applicationLimited = bbrProbeRTT, fullBandwidth, true
bbr.probeDone = now.Add(-time.Millisecond)
bbr.priorWindow = 20_000
bbr.bandwidthHigh[1], bbr.bandwidthLow, bbr.inflightLow, bbr.inflightHigh = 1_000_000, 500_000, 8000, 30_000
window := uint32(4000)
if idle {
window = bbr.onDeliverySend(now, 0, window)
} else {
bbr.probeRound, bbr.roundStart = true, true
bbr.probeRTTStamp, bbr.minimumRTTStamp = now, now
window = bbr.updateMinimumRTT(window, bbr3RateSample(now, 1000, 1000, 4000, time.Millisecond), 1000)
}
wantMode := bbrStartup
if fullBandwidth {
wantMode = bbrProbeBandwidth
}
if bbr.mode != wantMode || window != 20_000 || bbr.bandwidthLow != 0 || bbr.inflightLow != 0 || bbr.inflightHigh != 30_000 || bbr.maximumBandwidth() != 1_000_000 || bbr.effectiveBandwidth() != 1_000_000 {
t.Fatalf("ProbeRTT exit = mode %v window %d bandwidth %g bounds %g/%d/%d", bbr.mode, window, bbr.effectiveBandwidth(), bbr.bandwidthLow, bbr.inflightLow, bbr.inflightHigh)
}
if fullBandwidth && (bbr.probePhase != bbr3ProbeCruise || bbr.boundWindow(uint64(window), 1000) != uint64(window)) {
t.Fatalf("ProbeBW restart = phase %v bounded window %d", bbr.probePhase, bbr.boundWindow(uint64(window), 1000))
}
})
}
}
}
func TestTCPBBR3PublishedRetransmissionFlight(t *testing.T) {
for _, test := range []struct {
name string
count int
pathMTU bool
repeated bool
}{
{name: "RACK", count: 2},
{name: "SACK threshold", count: 5},
{name: "PMTU first replacement", count: 5, pathMTU: true},
{name: "PMTU repeated replacement", count: 5, pathMTU: true, repeated: true},
} {
t.Run(test.name, func(t *testing.T) {
link, stack, connection := newManuallyPumpedTCPConnection(t)
recorder := &bbr3RetransmissionRecorder{algorithm: newBBR3CongestionControl(), published: make(chan bbr3Retransmission, 64)}
base, _ := registeredCongestionControlFactory(CongestionControlBBR3)
definition := base.definition
definition.Name = "test-BBR3-flight"
definition.New = func(CongestionControlContext) CongestionController { return recorder }
factory, err := NewCongestionControlFactory(definition)
if err != nil {
t.Fatal(err)
}
if err = connection.SetCongestionControlFactory(factory); err != nil {
t.Fatal(err)