@@ -790,25 +790,64 @@ fn on_packet_lost_persistent_congestion() {
790790#[ test]
791791fn on_mtu_update_increase ( ) {
792792 let mut mtu = 5000 ;
793- let cwnd_in_packets = 100_000f32 ;
794- let cwnd_in_bytes = cwnd_in_packets / mtu as f32 ;
793+ let cwnd_in_bytes = 100_000f32 ;
795794 let mut cc = CubicCongestionController :: new ( mtu, Default :: default ( ) ) ;
796795 let mut publisher = event:: testing:: Publisher :: snapshot ( ) ;
797796 let mut publisher = PathPublisher :: new ( & mut publisher, path:: Id :: test_id ( ) ) ;
798- cc. congestion_window = cwnd_in_packets ;
797+ cc. congestion_window = cwnd_in_bytes ;
799798
800799 mtu = 10000 ;
801800 cc. on_mtu_update ( mtu, & mut publisher) ;
802801 assert_eq ! ( cc. max_datagram_size, mtu) ;
803802 assert_eq ! ( cc. cubic. max_datagram_size, mtu) ;
804803
805804 assert_delta ! ( cc. congestion_window, 200_000.0 , 0.001 ) ;
805+ }
806806
807- //= https://www.rfc-editor.org/rfc/rfc8899#section-3
808- //= type=test
809- //# An update to the PLPMTU (or MPS) MUST NOT increase the congestion
810- //# window measured in bytes [RFC4821].
811- assert_delta ! ( cc. congestion_window / mtu as f32 , cwnd_in_bytes, 0.001 ) ;
807+ //= https://www.rfc-editor.org/rfc/rfc9002#section-7.2
808+ //= type=test
809+ //# If the maximum datagram size changes during the connection, the
810+ //# initial congestion window SHOULD be recalculated with the new size.
811+
812+ //= https://www.rfc-editor.org/rfc/rfc9002#section-7.2
813+ //= type=test
814+ //# If the maximum datagram size is decreased in order to complete the
815+ //# handshake, the congestion window SHOULD be set to the new initial
816+ //# congestion window.
817+ #[ test]
818+ fn on_mtu_update_decrease_smaller_than_initial_window ( ) {
819+ let mut mtu = 9000 ;
820+ let cwnd_in_bytes = 18_000f32 ;
821+ let mut cc = CubicCongestionController :: new ( mtu, Default :: default ( ) ) ;
822+ let mut publisher = event:: testing:: Publisher :: snapshot ( ) ;
823+ let mut publisher = PathPublisher :: new ( & mut publisher, path:: Id :: test_id ( ) ) ;
824+ cc. congestion_window = cwnd_in_bytes;
825+
826+ mtu = 1350 ;
827+ cc. on_mtu_update ( mtu, & mut publisher) ;
828+ assert_eq ! ( cc. max_datagram_size, mtu) ;
829+ assert_eq ! ( cc. cubic. max_datagram_size, mtu) ;
830+
831+ // updated initial window is 10 x MTU = 10 x 1350
832+ assert_delta ! ( cc. congestion_window, 13_500.0 , 0.001 ) ;
833+ }
834+
835+ #[ test]
836+ fn on_mtu_update_decrease_larger_than_initial_window ( ) {
837+ let mut mtu = 9000 ;
838+ let cwnd_in_bytes = 180_000f32 ;
839+ let mut cc = CubicCongestionController :: new ( mtu, Default :: default ( ) ) ;
840+ let mut publisher = event:: testing:: Publisher :: snapshot ( ) ;
841+ let mut publisher = PathPublisher :: new ( & mut publisher, path:: Id :: test_id ( ) ) ;
842+ cc. congestion_window = cwnd_in_bytes;
843+
844+ mtu = 1350 ;
845+ cc. on_mtu_update ( mtu, & mut publisher) ;
846+ assert_eq ! ( cc. max_datagram_size, mtu) ;
847+ assert_eq ! ( cc. cubic. max_datagram_size, mtu) ;
848+
849+ // Congestion window is still 20 packets based on the updated MTU
850+ assert_delta ! ( cc. congestion_window, 27_000.0 , 0.001 ) ;
812851}
813852
814853//= https://www.rfc-editor.org/rfc/rfc9002#section-6.4
0 commit comments