Internal change PiperOrigin-RevId: 437244456
diff --git a/quic/core/quic_sent_packet_manager.cc b/quic/core/quic_sent_packet_manager.cc index 0d6c862..f7e91b9 100644 --- a/quic/core/quic_sent_packet_manager.cc +++ b/quic/core/quic_sent_packet_manager.cc
@@ -1504,6 +1504,13 @@ return QuicTime::Delta::Infinite(); } +QuicByteCount QuicSentPacketManager::GetAvailableCongestionWindowInBytes() + const { + QuicByteCount congestion_window = GetCongestionWindowInBytes(); + QuicByteCount bytes_in_flight = GetBytesInFlight(); + return congestion_window - std::min(congestion_window, bytes_in_flight); +} + std::string QuicSentPacketManager::GetDebugState() const { return send_algorithm_->GetDebugState(); }
diff --git a/quic/core/quic_sent_packet_manager.h b/quic/core/quic_sent_packet_manager.h index 7b127b5..22067ff 100644 --- a/quic/core/quic_sent_packet_manager.h +++ b/quic/core/quic_sent_packet_manager.h
@@ -285,6 +285,11 @@ return send_algorithm_->GetCongestionWindow(); } + // Returns the difference between current congestion window and bytes in + // flight. Returns 0 if bytes in flight is bigger than the current congestion + // window. + QuicByteCount GetAvailableCongestionWindowInBytes() const; + QuicBandwidth GetPacingRate() const { return send_algorithm_->PacingRate(GetBytesInFlight()); }
diff --git a/quic/core/quic_sent_packet_manager_test.cc b/quic/core/quic_sent_packet_manager_test.cc index 02ae04c..bf141e4 100644 --- a/quic/core/quic_sent_packet_manager_test.cc +++ b/quic/core/quic_sent_packet_manager_test.cc
@@ -4719,6 +4719,23 @@ kMinTrustedInitialRoundTripTimeUs); } +TEST_F(QuicSentPacketManagerTest, GetAvailableCongestionWindow) { + SendDataPacket(1); + EXPECT_EQ(kDefaultLength, manager_.GetBytesInFlight()); + + EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) + .WillOnce(Return(kDefaultLength + 10)); + EXPECT_EQ(10u, manager_.GetAvailableCongestionWindowInBytes()); + + EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) + .WillOnce(Return(kDefaultLength)); + EXPECT_EQ(0u, manager_.GetAvailableCongestionWindowInBytes()); + + EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) + .WillOnce(Return(kDefaultLength - 10)); + EXPECT_EQ(0u, manager_.GetAvailableCongestionWindowInBytes()); +} + } // namespace } // namespace test } // namespace quic