Move CheckBandwidthGrowth in QUIC from Bbr2Startup to Bbr2NetworkModel.  No functional change.

PiperOrigin-RevId: 347472199
Change-Id: I3737c5bce0d42f084b4297b92d5af3fa342c26e1
diff --git a/quic/core/congestion_control/bbr2_misc.cc b/quic/core/congestion_control/bbr2_misc.cc
index 700995f..0be3253 100644
--- a/quic/core/congestion_control/bbr2_misc.cc
+++ b/quic/core/congestion_control/bbr2_misc.cc
@@ -311,4 +311,38 @@
   return inflight_hi_ > headroom ? inflight_hi_ - headroom : 0;
 }
 
+bool Bbr2NetworkModel::CheckBandwidthGrowth(
+    const Bbr2CongestionEvent& congestion_event) {
+  DCHECK(!full_bandwidth_reached_);
+  DCHECK(congestion_event.end_of_round_trip);
+  if (congestion_event.last_sample_is_app_limited) {
+    // Return true such that when Params().always_exit_startup_on_excess_loss is
+    // false, we'll not check excess loss, which is the behavior of QUIC BBRv1.
+    return true;
+  }
+
+  QuicBandwidth threshold =
+      full_bandwidth_baseline_ * Params().startup_full_bw_threshold;
+
+  if (MaxBandwidth() >= threshold) {
+    QUIC_DVLOG(3) << " CheckBandwidthGrowth at end of round. max_bandwidth:"
+                  << MaxBandwidth() << ", threshold:" << threshold
+                  << " (Still growing)  @ " << congestion_event.event_time;
+    full_bandwidth_baseline_ = MaxBandwidth();
+    rounds_without_bandwidth_growth_ = 0;
+    return true;
+  }
+
+  ++rounds_without_bandwidth_growth_;
+  full_bandwidth_reached_ =
+      rounds_without_bandwidth_growth_ >= Params().startup_full_bw_rounds;
+  QUIC_DVLOG(3) << " CheckBandwidthGrowth at end of round. max_bandwidth:"
+                << MaxBandwidth() << ", threshold:" << threshold
+                << " rounds_without_growth:" << rounds_without_bandwidth_growth_
+                << " full_bw_reached:" << full_bandwidth_reached_ << "  @ "
+                << congestion_event.event_time;
+
+  return false;
+}
+
 }  // namespace quic
diff --git a/quic/core/congestion_control/bbr2_misc.h b/quic/core/congestion_control/bbr2_misc.h
index f81d3cd..c26d2f9 100644
--- a/quic/core/congestion_control/bbr2_misc.h
+++ b/quic/core/congestion_control/bbr2_misc.h
@@ -409,6 +409,13 @@
   bool IsInflightTooHigh(const Bbr2CongestionEvent& congestion_event,
                          int64_t max_loss_events) const;
 
+  // Check bandwidth growth in the past round. Must be called at the end of a
+  // round.
+  // Return true if the bandwidth growed as expected.
+  // Return false otherwise, if enough rounds have elapsed without expected
+  // growth, also sets |full_bandwidth_reached_| to true.
+  bool CheckBandwidthGrowth(const Bbr2CongestionEvent& congestion_event);
+
   QuicPacketNumber last_sent_packet() const {
     return round_trip_counter_.last_sent_packet();
   }
@@ -465,6 +472,15 @@
   float pacing_gain() const { return pacing_gain_; }
   void set_pacing_gain(float pacing_gain) { pacing_gain_ = pacing_gain; }
 
+  bool full_bandwidth_reached() const { return full_bandwidth_reached_; }
+  void set_full_bandwidth_reached() { full_bandwidth_reached_ = true; }
+  QuicBandwidth full_bandwidth_baseline() const {
+    return full_bandwidth_baseline_;
+  }
+  QuicRoundTripCount rounds_without_bandwidth_growth() const {
+    return rounds_without_bandwidth_growth_;
+  }
+
  private:
   const Bbr2Params& Params() const { return *params_; }
   const Bbr2Params* const params_;
@@ -502,6 +518,11 @@
 
   float cwnd_gain_;
   float pacing_gain_;
+
+  // STARTUP-centric fields which experimentally used by PROBE_UP.
+  bool full_bandwidth_reached_ = false;
+  QuicBandwidth full_bandwidth_baseline_ = QuicBandwidth::Zero();
+  QuicRoundTripCount rounds_without_bandwidth_growth_ = 0;
 };
 
 enum class Bbr2Mode : uint8_t {
diff --git a/quic/core/congestion_control/bbr2_sender.cc b/quic/core/congestion_control/bbr2_sender.cc
index a71dbdf..c12c4e2 100644
--- a/quic/core/congestion_control/bbr2_sender.cc
+++ b/quic/core/congestion_control/bbr2_sender.cc
@@ -303,7 +303,7 @@
   }
 
   QuicBandwidth target_rate = model_.pacing_gain() * model_.BandwidthEstimate();
-  if (startup_.FullBandwidthReached()) {
+  if (model_.full_bandwidth_reached()) {
     pacing_rate_ = target_rate;
     return;
   }
@@ -317,7 +317,7 @@
   QuicByteCount target_cwnd = GetTargetCongestionWindow(model_.cwnd_gain());
 
   const QuicByteCount prior_cwnd = cwnd_;
-  if (startup_.FullBandwidthReached()) {
+  if (model_.full_bandwidth_reached()) {
     target_cwnd += model_.MaxAckHeight();
     cwnd_ = std::min(prior_cwnd + bytes_acked, target_cwnd);
   } else if (prior_cwnd < target_cwnd || prior_cwnd < 2 * initial_cwnd_) {
@@ -332,7 +332,7 @@
 
   QUIC_DVLOG(3) << this << " Updating CWND. target_cwnd:" << target_cwnd
                 << ", max_ack_height:" << model_.MaxAckHeight()
-                << ", full_bw:" << startup_.FullBandwidthReached()
+                << ", full_bw:" << model_.full_bandwidth_reached()
                 << ", bytes_acked:" << bytes_acked
                 << ", inflight_lo:" << model_.inflight_lo()
                 << ", inflight_hi:" << model_.inflight_hi() << ". (prior_cwnd) "
diff --git a/quic/core/congestion_control/bbr2_startup.cc b/quic/core/congestion_control/bbr2_startup.cc
index 479c66b..5d02de7 100644
--- a/quic/core/congestion_control/bbr2_startup.cc
+++ b/quic/core/congestion_control/bbr2_startup.cc
@@ -15,10 +15,7 @@
 Bbr2StartupMode::Bbr2StartupMode(const Bbr2Sender* sender,
                                  Bbr2NetworkModel* model,
                                  QuicTime now)
-    : Bbr2ModeBase(sender, model),
-      full_bandwidth_reached_(false),
-      full_bandwidth_baseline_(QuicBandwidth::Zero()),
-      rounds_without_bandwidth_growth_(0) {
+    : Bbr2ModeBase(sender, model) {
   // Clear some startup stats if |sender_->connection_stats_| has been used by
   // another sender, which happens e.g. when QuicConnection switch send
   // algorithms.
@@ -43,10 +40,10 @@
     const AckedPacketVector& /*acked_packets*/,
     const LostPacketVector& /*lost_packets*/,
     const Bbr2CongestionEvent& congestion_event) {
-  if (!full_bandwidth_reached_ && congestion_event.end_of_round_trip) {
+  if (!model_->full_bandwidth_reached() && congestion_event.end_of_round_trip) {
     // TCP BBR always exits upon excessive losses. QUIC BBRv1 does not exits
     // upon excessive losses, if enough bandwidth growth is observed.
-    bool has_enough_bw_growth = CheckBandwidthGrowth(congestion_event);
+    bool has_enough_bw_growth = model_->CheckBandwidthGrowth(congestion_event);
 
     if (Params().always_exit_startup_on_excess_loss || !has_enough_bw_growth) {
       CheckExcessiveLosses(congestion_event);
@@ -57,50 +54,14 @@
   model_->set_cwnd_gain(Params().startup_cwnd_gain);
 
   // TODO(wub): Maybe implement STARTUP => PROBE_RTT.
-  return full_bandwidth_reached_ ? Bbr2Mode::DRAIN : Bbr2Mode::STARTUP;
-}
-
-bool Bbr2StartupMode::CheckBandwidthGrowth(
-    const Bbr2CongestionEvent& congestion_event) {
-  DCHECK(!full_bandwidth_reached_);
-  DCHECK(congestion_event.end_of_round_trip);
-  if (congestion_event.last_sample_is_app_limited) {
-    // Return true such that when Params().always_exit_startup_on_excess_loss is
-    // false, we'll not check excess loss, which is the behavior of QUIC BBRv1.
-    return true;
-  }
-
-  QuicBandwidth threshold =
-      full_bandwidth_baseline_ * Params().startup_full_bw_threshold;
-
-  if (model_->MaxBandwidth() >= threshold) {
-    QUIC_DVLOG(3) << sender_
-                  << " CheckBandwidthGrowth at end of round. max_bandwidth:"
-                  << model_->MaxBandwidth() << ", threshold:" << threshold
-                  << " (Still growing)  @ " << congestion_event.event_time;
-    full_bandwidth_baseline_ = model_->MaxBandwidth();
-    rounds_without_bandwidth_growth_ = 0;
-    return true;
-  }
-
-  ++rounds_without_bandwidth_growth_;
-  full_bandwidth_reached_ =
-      rounds_without_bandwidth_growth_ >= Params().startup_full_bw_rounds;
-  QUIC_DVLOG(3) << sender_
-                << " CheckBandwidthGrowth at end of round. max_bandwidth:"
-                << model_->MaxBandwidth() << ", threshold:" << threshold
-                << " rounds_without_growth:" << rounds_without_bandwidth_growth_
-                << " full_bw_reached:" << full_bandwidth_reached_ << "  @ "
-                << congestion_event.event_time;
-
-  return false;
+  return model_->full_bandwidth_reached() ? Bbr2Mode::DRAIN : Bbr2Mode::STARTUP;
 }
 
 void Bbr2StartupMode::CheckExcessiveLosses(
     const Bbr2CongestionEvent& congestion_event) {
   DCHECK(congestion_event.end_of_round_trip);
 
-  if (full_bandwidth_reached_) {
+  if (model_->full_bandwidth_reached()) {
     return;
   }
 
@@ -117,17 +78,17 @@
                   << new_inflight_hi;
     // TODO(ianswett): Add a shared method to set inflight_hi in the model.
     model_->set_inflight_hi(new_inflight_hi);
-
-    full_bandwidth_reached_ = true;
+    model_->set_full_bandwidth_reached();
     sender_->connection_stats_->bbr_exit_startup_due_to_loss = true;
   }
 }
 
 Bbr2StartupMode::DebugState Bbr2StartupMode::ExportDebugState() const {
   DebugState s;
-  s.full_bandwidth_reached = full_bandwidth_reached_;
-  s.full_bandwidth_baseline = full_bandwidth_baseline_;
-  s.round_trips_without_bandwidth_growth = rounds_without_bandwidth_growth_;
+  s.full_bandwidth_reached = model_->full_bandwidth_reached();
+  s.full_bandwidth_baseline = model_->full_bandwidth_baseline();
+  s.round_trips_without_bandwidth_growth =
+      model_->rounds_without_bandwidth_growth();
   return s;
 }
 
diff --git a/quic/core/congestion_control/bbr2_startup.h b/quic/core/congestion_control/bbr2_startup.h
index 75ec71e..f753a1e 100644
--- a/quic/core/congestion_control/bbr2_startup.h
+++ b/quic/core/congestion_control/bbr2_startup.h
@@ -45,8 +45,6 @@
     return Bbr2Mode::STARTUP;
   }
 
-  bool FullBandwidthReached() const { return full_bandwidth_reached_; }
-
   struct QUIC_EXPORT_PRIVATE DebugState {
     bool full_bandwidth_reached;
     QuicBandwidth full_bandwidth_baseline = QuicBandwidth::Zero();
@@ -58,18 +56,7 @@
  private:
   const Bbr2Params& Params() const;
 
-  // Check bandwidth growth in the past round. Must be called at the end of a
-  // round.
-  // Return true if the bandwidth growed as expected.
-  // Return false otherwise, if enough rounds have elapsed without expected
-  // growth, also sets |full_bandwidth_reached_| to true.
-  bool CheckBandwidthGrowth(const Bbr2CongestionEvent& congestion_event);
-
   void CheckExcessiveLosses(const Bbr2CongestionEvent& congestion_event);
-
-  bool full_bandwidth_reached_;
-  QuicBandwidth full_bandwidth_baseline_;
-  QuicRoundTripCount rounds_without_bandwidth_growth_;
 };
 
 QUIC_EXPORT_PRIVATE std::ostream& operator<<(