diff --git a/modules/congestion_controller/bbr/bbr_network_controller.cc b/modules/congestion_controller/bbr/bbr_network_controller.cc index dec762770d..033b13a868 100644 --- a/modules/congestion_controller/bbr/bbr_network_controller.cc +++ b/modules/congestion_controller/bbr/bbr_network_controller.cc @@ -84,6 +84,11 @@ constexpr int64_t kDefaultMaxCongestionWindowBytes = (kMaxRttMs * kMaxBandwidthKbps) / 8; } // namespace +BbrNetworkController::UpdateState::UpdateState() = default; +BbrNetworkController::UpdateState::UpdateState( + const BbrNetworkController::UpdateState&) = default; +BbrNetworkController::UpdateState::~UpdateState() = default; + BbrNetworkController::BbrControllerConfig BbrNetworkController::BbrControllerConfig::DefaultConfig() { BbrControllerConfig config; @@ -187,10 +192,10 @@ void BbrNetworkController::Reset() { rounds_without_bandwidth_gain_ = 0; is_at_full_bandwidth_ = false; last_update_state_.mode = Mode::STARTUP; - last_update_state_.bandwidth = DataRate(); - last_update_state_.rtt = TimeDelta(); - last_update_state_.pacing_rate = DataRate(); - last_update_state_.target_rate = DataRate(); + last_update_state_.bandwidth.reset(); + last_update_state_.rtt.reset(); + last_update_state_.pacing_rate.reset(); + last_update_state_.target_rate.reset(); last_update_state_.probing_for_bandwidth = false; EnterStartupMode(); } @@ -299,8 +304,9 @@ bool BbrNetworkController::InSlowStart() const { NetworkControlUpdate BbrNetworkController::OnSentPacket(SentPacket msg) { last_send_time_ = msg.send_time; - if (!aggregation_epoch_start_time_.IsInitialized()) { + if (!aggregation_epoch_start_time_) { aggregation_epoch_start_time_ = msg.send_time; + aggregation_epoch_bytes_ = DataSize::Zero(); } return NetworkControlUpdate(); } @@ -418,7 +424,7 @@ NetworkControlUpdate BbrNetworkController::OnTransportPacketsFeedback( MaybeEnterOrExitProbeRtt(msg, is_round_start, min_rtt_expired); // Calculate number of packets acked and lost. - DataSize bytes_lost = DataSize(); + DataSize bytes_lost = DataSize::Zero(); for (const PacketResult& packet : lost_packets) { bytes_lost += packet.sent_packet->size; } @@ -668,14 +674,14 @@ void BbrNetworkController::MaybeEnterOrExitProbeRtt( pacing_gain_ = 1; // Do not decide on the time to exit PROBE_RTT until the |bytes_in_flight| // is at the target small value. - exit_probe_rtt_at_ = Timestamp(); + exit_probe_rtt_at_.reset(); } if (mode_ == PROBE_RTT) { is_app_limited_ = true; end_of_app_limited_phase_ = last_send_time_; - if (!exit_probe_rtt_at_.IsInitialized()) { + if (!exit_probe_rtt_at_) { // If the window has reached the appropriate size, schedule exiting // PROBE_RTT. The CWND during PROBE_RTT is kMinimumCongestionWindow, but // we allow an extra packet since QUIC checks CWND before sending a @@ -688,7 +694,7 @@ void BbrNetworkController::MaybeEnterOrExitProbeRtt( if (is_round_start) { probe_rtt_round_passed_ = true; } - if (msg.feedback_time >= exit_probe_rtt_at_ && probe_rtt_round_passed_) { + if (msg.feedback_time >= *exit_probe_rtt_at_ && probe_rtt_round_passed_) { min_rtt_timestamp_ = msg.feedback_time; if (!is_at_full_bandwidth_) { EnterStartupMode(); @@ -733,7 +739,8 @@ void BbrNetworkController::UpdateRecoveryState(Timestamp last_acked_send_time, RTC_FALLTHROUGH(); case GROWTH: // Exit recovery if appropriate. - if (!has_losses && last_acked_send_time > end_recovery_at_) { + if (!has_losses && end_recovery_at_ && + last_acked_send_time > *end_recovery_at_) { recovery_state_ = NOT_IN_RECOVERY; } @@ -744,10 +751,16 @@ void BbrNetworkController::UpdateRecoveryState(Timestamp last_acked_send_time, void BbrNetworkController::UpdateAckAggregationBytes( Timestamp ack_time, DataSize newly_acked_bytes) { + if (!aggregation_epoch_start_time_) { + RTC_LOG(LS_ERROR) + << "Received feedback before information about sent packets."; + RTC_DCHECK(aggregation_epoch_start_time_.has_value()); + return; + } // Compute how many bytes are expected to be delivered, assuming max bandwidth // is correct. DataSize expected_bytes_acked = - max_bandwidth_.GetBest() * (ack_time - aggregation_epoch_start_time_); + max_bandwidth_.GetBest() * (ack_time - *aggregation_epoch_start_time_); // Reset the current aggregation epoch as soon as the ack arrival rate is less // than or equal to the max bandwidth. if (aggregation_epoch_bytes_ <= expected_bytes_acked) { @@ -785,7 +798,7 @@ void BbrNetworkController::CalculatePacingRate() { return; } // Slow the pacing rate in STARTUP once loss has ever been detected. - const bool has_ever_detected_loss = end_recovery_at_.IsInitialized(); + const bool has_ever_detected_loss = end_recovery_at_.has_value(); if (config_.slower_startup && has_ever_detected_loss) { pacing_rate_ = kStartupAfterLossGain * BandwidthEstimate(); return; diff --git a/modules/congestion_controller/bbr/bbr_network_controller.h b/modules/congestion_controller/bbr/bbr_network_controller.h index e9321ca72e..5b96961c58 100644 --- a/modules/congestion_controller/bbr/bbr_network_controller.h +++ b/modules/congestion_controller/bbr/bbr_network_controller.h @@ -159,11 +159,14 @@ class BbrNetworkController : public NetworkControllerInterface { }; // Containing values that when changed should trigger an update. struct UpdateState { + UpdateState(); + UpdateState(const UpdateState&); + ~UpdateState(); Mode mode = Mode::STARTUP; - DataRate bandwidth; - TimeDelta rtt; - DataRate pacing_rate; - DataRate target_rate; + rtc::Optional bandwidth; + rtc::Optional rtt; + rtc::Optional pacing_rate; + rtc::Optional target_rate; bool probing_for_bandwidth = false; }; @@ -273,11 +276,7 @@ class BbrNetworkController : public NetworkControllerInterface { BbrControllerConfig config_; // The total number of congestion controlled bytes which were acknowledged. - DataSize total_bytes_acked_; - - // The total number of congestion controlled bytes sent during the connection. - DataSize total_bytes_sent_; - + DataSize total_bytes_acked_ = DataSize::Zero(); // The time at which the last acknowledged packet was sent. Set to // Timestamp::ms(0) if no valid timestamp is available. Timestamp last_acked_packet_sent_time_ = Timestamp::ms(0); @@ -311,12 +310,12 @@ class BbrNetworkController : public NetworkControllerInterface { MaxAckHeightFilter max_ack_height_; // The time this aggregation started and the number of bytes acked during it. - Timestamp aggregation_epoch_start_time_; - DataSize aggregation_epoch_bytes_; + rtc::Optional aggregation_epoch_start_time_; + DataSize aggregation_epoch_bytes_ = DataSize::Zero(); // The number of bytes acknowledged since the last time bytes in flight // dropped below the target window. - DataSize bytes_acked_since_queue_drained_; + DataSize bytes_acked_since_queue_drained_ = DataSize::Zero(); // The muliplier for calculating the max amount of extra CWND to add to // compensate for ack aggregation. @@ -360,7 +359,7 @@ class BbrNetworkController : public NetworkControllerInterface { // pacing gain cycle. int cycle_current_offset_ = 0; // The time at which the last pacing gain cycle was started. - Timestamp last_cycle_start_; + Timestamp last_cycle_start_ = Timestamp::ms(0); // Indicates whether the connection has reached the full bandwidth mode. bool is_at_full_bandwidth_ = false; @@ -372,7 +371,7 @@ class BbrNetworkController : public NetworkControllerInterface { // Time at which PROBE_RTT has to be exited. Setting it to zero indicates // that the time is yet unknown as the number of packets in flight has not // reached the required value. - Timestamp exit_probe_rtt_at_; + rtc::Optional exit_probe_rtt_at_; // Indicates whether a round-trip has passed since PROBE_RTT became active. bool probe_rtt_round_passed_ = false; @@ -385,7 +384,7 @@ class BbrNetworkController : public NetworkControllerInterface { // Receiving acknowledgement of a packet after |end_recovery_at_| will cause // BBR to exit the recovery mode. A value after epoch indicates at least one // loss has been detected, so it must not be set back to epoch. - Timestamp end_recovery_at_ = Timestamp::ms(0); + rtc::Optional end_recovery_at_; // A window used to limit the number of bytes in flight during loss recovery. DataSize recovery_window_; diff --git a/modules/congestion_controller/bbr/data_transfer_tracker.h b/modules/congestion_controller/bbr/data_transfer_tracker.h index 1c2d117224..1de8c8a177 100644 --- a/modules/congestion_controller/bbr/data_transfer_tracker.h +++ b/modules/congestion_controller/bbr/data_transfer_tracker.h @@ -20,9 +20,9 @@ namespace bbr { class DataTransferTracker { public: struct Result { - TimeDelta ack_timespan; - TimeDelta send_timespan; - DataSize acked_data; + TimeDelta ack_timespan = TimeDelta::Zero(); + TimeDelta send_timespan = TimeDelta::Zero(); + DataSize acked_data = DataSize::Zero(); }; DataTransferTracker(); ~DataTransferTracker(); @@ -36,10 +36,10 @@ class DataTransferTracker { private: struct Sample { - Timestamp ack_time; - Timestamp send_time; - DataSize size_delta; - DataSize size_sum; + Timestamp ack_time = Timestamp::Infinity(); + Timestamp send_time = Timestamp::Infinity(); + DataSize size_delta = DataSize::Zero(); + DataSize size_sum = DataSize::Zero(); }; std::deque samples_; DataSize size_sum_ = DataSize::Zero();