1
- use crate :: recovery:: {
2
- congestion_controller:: CongestionController ,
3
- cubic:: { FastRetransmission :: * , State :: * } ,
4
- hybrid_slow_start:: HybridSlowStart ,
1
+ use crate :: {
2
+ counter:: Counter ,
3
+ recovery:: {
4
+ congestion_controller:: CongestionController ,
5
+ cubic:: { FastRetransmission :: * , State :: * } ,
6
+ hybrid_slow_start:: HybridSlowStart ,
7
+ RTTEstimator ,
8
+ } ,
9
+ time:: Timestamp ,
5
10
} ;
6
11
use core:: {
7
12
cmp:: { max, min} ,
8
13
time:: Duration ,
9
14
} ;
10
- use s2n_quic_core:: { counter:: Counter , recovery:: RTTEstimator , time:: Timestamp } ;
15
+ #[ cfg( not( feature = "std" ) ) ]
16
+ use num_traits:: Float as _;
11
17
12
18
//= https://tools.ietf.org/id/draft-ietf-quic-recovery-32.txt#7.3
13
19
//# New Path or +------------+
@@ -81,6 +87,10 @@ pub struct CubicCongestionController {
81
87
type BytesInFlight = Counter < u32 > ;
82
88
83
89
impl CongestionController for CubicCongestionController {
90
+ fn congestion_window ( & self ) -> u32 {
91
+ self . congestion_window
92
+ }
93
+
84
94
fn is_congestion_limited ( & self ) -> bool {
85
95
let available_congestion_window =
86
96
self . congestion_window . saturating_sub ( * self . bytes_in_flight ) ;
@@ -563,18 +573,12 @@ impl Cubic {
563
573
564
574
#[ cfg( test) ]
565
575
mod test {
566
- use crate :: recovery:: {
567
- cubic:: {
568
- BytesInFlight , Cubic , CubicCongestionController ,
569
- FastRetransmission :: { Idle , RequiresTransmission } ,
570
- State :: { CongestionAvoidance , Recovery , SlowStart } ,
571
- BETA_CUBIC ,
572
- } ,
573
- CongestionController ,
574
- } ;
575
- use s2n_quic_core:: {
576
- packet:: number:: PacketNumberSpace , recovery:: RTTEstimator , time:: Duration ,
576
+ use super :: * ;
577
+ use crate :: {
578
+ packet:: number:: PacketNumberSpace ,
579
+ time:: { Clock , NoopClock } ,
577
580
} ;
581
+ use core:: time:: Duration ;
578
582
579
583
macro_rules! assert_delta {
580
584
( $x: expr, $y: expr, $d: expr) => {
@@ -739,7 +743,7 @@ mod test {
739
743
fn on_packet_sent ( ) {
740
744
let mut cc = CubicCongestionController :: new ( 1000 ) ;
741
745
let mut rtt_estimator = RTTEstimator :: new ( Duration :: from_millis ( 0 ) ) ;
742
- let now = s2n_quic_platform :: time :: now ( ) ;
746
+ let now = NoopClock . get_time ( ) ;
743
747
744
748
cc. congestion_window = 100_000 ;
745
749
@@ -793,7 +797,7 @@ mod test {
793
797
#[ test]
794
798
fn on_packet_sent_application_limited ( ) {
795
799
let mut cc = CubicCongestionController :: new ( 1000 ) ;
796
- let now = s2n_quic_platform :: time :: now ( ) ;
800
+ let now = NoopClock . get_time ( ) ;
797
801
798
802
cc. congestion_window = 100_000 ;
799
803
cc. bytes_in_flight = BytesInFlight :: new ( 96_500 ) ;
@@ -833,7 +837,7 @@ mod test {
833
837
#[ test]
834
838
fn on_packet_sent_fast_retransmission ( ) {
835
839
let mut cc = CubicCongestionController :: new ( 1000 ) ;
836
- let now = s2n_quic_platform :: time :: now ( ) ;
840
+ let now = NoopClock . get_time ( ) ;
837
841
838
842
cc. congestion_window = 100_000 ;
839
843
cc. bytes_in_flight = BytesInFlight :: new ( 99900 ) ;
@@ -853,7 +857,7 @@ mod test {
853
857
#[ test]
854
858
fn congestion_avoidance_after_idle_period ( ) {
855
859
let mut cc = CubicCongestionController :: new ( 1000 ) ;
856
- let now = s2n_quic_platform :: time :: now ( ) ;
860
+ let now = NoopClock . get_time ( ) ;
857
861
let rtt_estimator = & RTTEstimator :: new ( Duration :: from_secs ( 0 ) ) ;
858
862
859
863
cc. congestion_window = 3000 ;
@@ -890,7 +894,7 @@ mod test {
890
894
fn congestion_avoidance_after_fast_convergence ( ) {
891
895
let max_datagram_size = 1200 ;
892
896
let mut cc = CubicCongestionController :: new ( max_datagram_size) ;
893
- let now = s2n_quic_platform :: time :: now ( ) ;
897
+ let now = NoopClock . get_time ( ) ;
894
898
cc. bytes_in_flight = BytesInFlight :: new ( 100 ) ;
895
899
cc. congestion_window = 80_000 ;
896
900
cc. cubic . w_last_max = bytes_to_packets ( 100_000 , max_datagram_size) ;
@@ -927,7 +931,7 @@ mod test {
927
931
#[ test]
928
932
fn on_packet_lost ( ) {
929
933
let mut cc = CubicCongestionController :: new ( 1000 ) ;
930
- let now = s2n_quic_platform :: time :: now ( ) ;
934
+ let now = NoopClock . get_time ( ) ;
931
935
cc. congestion_window = 100_000 ;
932
936
cc. bytes_in_flight = BytesInFlight :: new ( 100_000 ) ;
933
937
cc. state = SlowStart ;
@@ -957,7 +961,7 @@ mod test {
957
961
#[ test]
958
962
fn on_packet_lost_below_minimum_window ( ) {
959
963
let mut cc = CubicCongestionController :: new ( 1000 ) ;
960
- let now = s2n_quic_platform :: time :: now ( ) ;
964
+ let now = NoopClock . get_time ( ) ;
961
965
cc. congestion_window = cc. minimum_window ( ) ;
962
966
cc. bytes_in_flight = BytesInFlight :: new ( cc. minimum_window ( ) ) ;
963
967
cc. state = CongestionAvoidance ( now) ;
@@ -970,7 +974,7 @@ mod test {
970
974
#[ test]
971
975
fn on_packet_lost_already_in_recovery ( ) {
972
976
let mut cc = CubicCongestionController :: new ( 1000 ) ;
973
- let now = s2n_quic_platform :: time :: now ( ) ;
977
+ let now = NoopClock . get_time ( ) ;
974
978
cc. congestion_window = 10000 ;
975
979
cc. bytes_in_flight = BytesInFlight :: new ( 1000 ) ;
976
980
cc. state = Recovery ( now, Idle ) ;
@@ -990,7 +994,7 @@ mod test {
990
994
#[ test]
991
995
fn on_packet_lost_persistent_congestion ( ) {
992
996
let mut cc = CubicCongestionController :: new ( 1000 ) ;
993
- let now = s2n_quic_platform :: time :: now ( ) ;
997
+ let now = NoopClock . get_time ( ) ;
994
998
cc. congestion_window = 10000 ;
995
999
cc. bytes_in_flight = BytesInFlight :: new ( 1000 ) ;
996
1000
cc. state = Recovery ( now, Idle ) ;
@@ -1059,7 +1063,7 @@ mod test {
1059
1063
#[ test]
1060
1064
fn on_packet_ack_limited ( ) {
1061
1065
let mut cc = CubicCongestionController :: new ( 5000 ) ;
1062
- let now = s2n_quic_platform :: time :: now ( ) ;
1066
+ let now = NoopClock . get_time ( ) ;
1063
1067
cc. congestion_window = 100_000 ;
1064
1068
cc. bytes_in_flight = BytesInFlight :: new ( 10000 ) ;
1065
1069
cc. state = SlowStart ;
@@ -1079,7 +1083,7 @@ mod test {
1079
1083
#[ compliance:: tests( "https://tools.ietf.org/id/draft-ietf-quic-recovery-32.txt#7.3.2" ) ]
1080
1084
fn on_packet_ack_recovery_to_congestion_avoidance ( ) {
1081
1085
let mut cc = CubicCongestionController :: new ( 5000 ) ;
1082
- let now = s2n_quic_platform :: time :: now ( ) ;
1086
+ let now = NoopClock . get_time ( ) ;
1083
1087
1084
1088
cc. cubic . w_max = bytes_to_packets ( 25000 , 5000 ) ;
1085
1089
cc. state = Recovery ( now, Idle ) ;
@@ -1102,7 +1106,7 @@ mod test {
1102
1106
#[ compliance:: tests( "https://tools.ietf.org/id/draft-ietf-quic-recovery-32.txt#7.3.2" ) ]
1103
1107
fn on_packet_ack_slow_start_to_congestion_avoidance ( ) {
1104
1108
let mut cc = CubicCongestionController :: new ( 5000 ) ;
1105
- let now = s2n_quic_platform :: time :: now ( ) ;
1109
+ let now = NoopClock . get_time ( ) ;
1106
1110
1107
1111
cc. state = SlowStart ;
1108
1112
cc. congestion_window = 10000 ;
@@ -1128,7 +1132,7 @@ mod test {
1128
1132
#[ test]
1129
1133
fn on_packet_ack_recovery ( ) {
1130
1134
let mut cc = CubicCongestionController :: new ( 5000 ) ;
1131
- let now = s2n_quic_platform :: time :: now ( ) ;
1135
+ let now = NoopClock . get_time ( ) ;
1132
1136
1133
1137
cc. state = Recovery ( now, Idle ) ;
1134
1138
cc. congestion_window = 10000 ;
@@ -1151,7 +1155,7 @@ mod test {
1151
1155
let max_datagram_size = 5000 ;
1152
1156
let mut cc = CubicCongestionController :: new ( max_datagram_size) ;
1153
1157
let mut cc2 = CubicCongestionController :: new ( max_datagram_size) ;
1154
- let now = s2n_quic_platform :: time :: now ( ) ;
1158
+ let now = NoopClock . get_time ( ) ;
1155
1159
1156
1160
cc. state = CongestionAvoidance ( now + Duration :: from_millis ( 3300 ) ) ;
1157
1161
cc. congestion_window = 10000 ;
0 commit comments