Move Bbr2ProbeBwMode::CyclePhase to bbr2_misc.h and rename it to ProbePhase.

PiperOrigin-RevId: 900792019
diff --git a/quiche/quic/core/congestion_control/bbr2_misc.cc b/quiche/quic/core/congestion_control/bbr2_misc.cc
index 7aab8ed..43c6f8c 100644
--- a/quiche/quic/core/congestion_control/bbr2_misc.cc
+++ b/quiche/quic/core/congestion_control/bbr2_misc.cc
@@ -18,6 +18,24 @@
 
 namespace quic {
 
+const char* ProbePhaseToString(ProbePhase phase) {
+  switch (phase) {
+    case ProbePhase::PROBE_NOT_STARTED:
+      return "PROBE_NOT_STARTED";
+    case ProbePhase::PROBE_UP:
+      return "PROBE_UP";
+    case ProbePhase::PROBE_DOWN:
+      return "PROBE_DOWN";
+    case ProbePhase::PROBE_CRUISE:
+      return "PROBE_CRUISE";
+    case ProbePhase::PROBE_REFILL:
+      return "PROBE_REFILL";
+    default:
+      break;
+  }
+  return "<Invalid ProbePhase>";
+}
+
 RoundTripCounter::RoundTripCounter() : round_trip_count_(0) {}
 
 void RoundTripCounter::OnPacketSent(QuicPacketNumber packet_number) {
diff --git a/quiche/quic/core/congestion_control/bbr2_misc.h b/quiche/quic/core/congestion_control/bbr2_misc.h
index 84ba709..d57b6be 100644
--- a/quiche/quic/core/congestion_control/bbr2_misc.h
+++ b/quiche/quic/core/congestion_control/bbr2_misc.h
@@ -226,6 +226,21 @@
   bool decrease_startup_pacing_at_end_of_round = false;
 };
 
+enum class ProbePhase : uint8_t {
+  PROBE_NOT_STARTED,
+  PROBE_UP,
+  PROBE_DOWN,
+  PROBE_CRUISE,
+  PROBE_REFILL,
+};
+
+QUICHE_EXPORT const char* ProbePhaseToString(ProbePhase phase);
+
+QUICHE_EXPORT inline std::ostream& operator<<(std::ostream& os,
+                                              ProbePhase phase) {
+  return os << ProbePhaseToString(phase);
+}
+
 class QUICHE_EXPORT RoundTripCounter {
  public:
   RoundTripCounter();
diff --git a/quiche/quic/core/congestion_control/bbr2_probe_bw.cc b/quiche/quic/core/congestion_control/bbr2_probe_bw.cc
index 369b339..d15617b 100644
--- a/quiche/quic/core/congestion_control/bbr2_probe_bw.cc
+++ b/quiche/quic/core/congestion_control/bbr2_probe_bw.cc
@@ -20,19 +20,19 @@
 
 void Bbr2ProbeBwMode::Enter(QuicTime now,
                             const Bbr2CongestionEvent* /*congestion_event*/) {
-  if (cycle_.phase == CyclePhase::PROBE_NOT_STARTED) {
+  if (cycle_.phase == ProbePhase::PROBE_NOT_STARTED) {
     // First time entering PROBE_BW. Start a new probing cycle.
     EnterProbeDown(/*probed_too_high=*/false, /*stopped_risky_probe=*/false,
                    now);
   } else {
     // Transitioning from PROBE_RTT to PROBE_BW. Re-enter the last phase before
     // PROBE_RTT.
-    QUICHE_DCHECK(cycle_.phase == CyclePhase::PROBE_CRUISE ||
-                  cycle_.phase == CyclePhase::PROBE_REFILL);
+    QUICHE_DCHECK(cycle_.phase == ProbePhase::PROBE_CRUISE ||
+                  cycle_.phase == ProbePhase::PROBE_REFILL);
     cycle_.cycle_start_time = now;
-    if (cycle_.phase == CyclePhase::PROBE_CRUISE) {
+    if (cycle_.phase == ProbePhase::PROBE_CRUISE) {
       EnterProbeCruise(now);
-    } else if (cycle_.phase == CyclePhase::PROBE_REFILL) {
+    } else if (cycle_.phase == ProbePhase::PROBE_REFILL) {
       EnterProbeRefill(cycle_.probe_up_rounds, now);
     }
   }
@@ -43,7 +43,7 @@
     const AckedPacketVector& /*acked_packets*/,
     const LostPacketVector& /*lost_packets*/,
     const Bbr2CongestionEvent& congestion_event) {
-  QUICHE_DCHECK_NE(cycle_.phase, CyclePhase::PROBE_NOT_STARTED);
+  QUICHE_DCHECK_NE(cycle_.phase, ProbePhase::PROBE_NOT_STARTED);
 
   if (congestion_event.end_of_round_trip) {
     if (cycle_.cycle_start_time != event_time) {
@@ -56,18 +56,18 @@
 
   bool switch_to_probe_rtt = false;
 
-  if (cycle_.phase == CyclePhase::PROBE_UP) {
+  if (cycle_.phase == ProbePhase::PROBE_UP) {
     UpdateProbeUp(prior_in_flight, congestion_event);
-  } else if (cycle_.phase == CyclePhase::PROBE_DOWN) {
+  } else if (cycle_.phase == ProbePhase::PROBE_DOWN) {
     UpdateProbeDown(prior_in_flight, congestion_event);
     // Maybe transition to PROBE_RTT at the end of this cycle.
-    if (cycle_.phase != CyclePhase::PROBE_DOWN &&
+    if (cycle_.phase != ProbePhase::PROBE_DOWN &&
         model_->MaybeExpireMinRtt(congestion_event)) {
       switch_to_probe_rtt = true;
     }
-  } else if (cycle_.phase == CyclePhase::PROBE_CRUISE) {
+  } else if (cycle_.phase == ProbePhase::PROBE_CRUISE) {
     UpdateProbeCruise(congestion_event);
-  } else if (cycle_.phase == CyclePhase::PROBE_REFILL) {
+  } else if (cycle_.phase == ProbePhase::PROBE_REFILL) {
     UpdateProbeRefill(congestion_event);
   }
 
@@ -82,12 +82,12 @@
 }
 
 Limits<QuicByteCount> Bbr2ProbeBwMode::GetCwndLimits() const {
-  if (cycle_.phase == CyclePhase::PROBE_CRUISE) {
+  if (cycle_.phase == ProbePhase::PROBE_CRUISE) {
     return NoGreaterThan(
         std::min(model_->inflight_lo(), model_->inflight_hi_with_headroom()));
   }
   if (Params().probe_up_ignore_inflight_hi &&
-      cycle_.phase == CyclePhase::PROBE_UP) {
+      cycle_.phase == ProbePhase::PROBE_UP) {
     // Similar to STARTUP.
     return NoGreaterThan(model_->inflight_lo());
   }
@@ -96,8 +96,8 @@
 }
 
 bool Bbr2ProbeBwMode::IsProbingForBandwidth() const {
-  return cycle_.phase == CyclePhase::PROBE_REFILL ||
-         cycle_.phase == CyclePhase::PROBE_UP;
+  return cycle_.phase == ProbePhase::PROBE_REFILL ||
+         cycle_.phase == ProbePhase::PROBE_UP;
 }
 
 Bbr2Mode Bbr2ProbeBwMode::OnExitQuiescence(QuicTime now,
@@ -113,7 +113,7 @@
 void Bbr2ProbeBwMode::UpdateProbeDown(
     QuicByteCount prior_in_flight,
     const Bbr2CongestionEvent& congestion_event) {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_DOWN);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_DOWN);
 
   if (cycle_.rounds_in_phase == 1 && congestion_event.end_of_round_trip) {
     cycle_.is_sample_from_probing = false;
@@ -331,7 +331,7 @@
 }
 
 void Bbr2ProbeBwMode::RaiseInflightHighSlope() {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_UP);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_UP);
   uint64_t growth_this_round = 1 << cycle_.probe_up_rounds;
   // The number 30 below means |growth_this_round| is capped at 1G and the lower
   // bound of |probe_up_bytes| is (practically) 1 mss, at this speed inflight_hi
@@ -347,7 +347,7 @@
 
 void Bbr2ProbeBwMode::ProbeInflightHighUpward(
     const Bbr2CongestionEvent& congestion_event) {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_UP);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_UP);
   if (Params().probe_up_ignore_inflight_hi) {
     // When inflight_hi is disabled in PROBE_UP, it increases when
     // the number of bytes delivered in a round is larger inflight_hi.
@@ -412,7 +412,7 @@
 
 void Bbr2ProbeBwMode::UpdateProbeCruise(
     const Bbr2CongestionEvent& congestion_event) {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_CRUISE);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_CRUISE);
   MaybeAdaptUpperBounds(congestion_event);
   QUICHE_DCHECK(!cycle_.is_sample_from_probing);
 
@@ -424,7 +424,7 @@
 
 void Bbr2ProbeBwMode::UpdateProbeRefill(
     const Bbr2CongestionEvent& congestion_event) {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_REFILL);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_REFILL);
   MaybeAdaptUpperBounds(congestion_event);
   QUICHE_DCHECK(!cycle_.is_sample_from_probing);
 
@@ -437,7 +437,7 @@
 void Bbr2ProbeBwMode::UpdateProbeUp(
     QuicByteCount prior_in_flight,
     const Bbr2CongestionEvent& congestion_event) {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_UP);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_UP);
   if (MaybeAdaptUpperBounds(congestion_event) == ADAPTED_PROBED_TOO_HIGH) {
     EnterProbeDown(/*probed_too_high=*/true, /*stopped_risky_probe=*/false,
                    congestion_event.event_time);
@@ -501,7 +501,7 @@
 void Bbr2ProbeBwMode::EnterProbeDown(bool probed_too_high,
                                      bool stopped_risky_probe, QuicTime now) {
   QUIC_DVLOG(2) << sender_ << " Phase change: " << cycle_.phase << " ==> "
-                << CyclePhase::PROBE_DOWN << " after "
+                << ProbePhase::PROBE_DOWN << " after "
                 << now - cycle_.phase_start_time << ", or "
                 << cycle_.rounds_in_phase
                 << " rounds. probed_too_high:" << probed_too_high
@@ -511,7 +511,7 @@
   last_cycle_stopped_risky_probe_ = stopped_risky_probe;
 
   cycle_.cycle_start_time = now;
-  cycle_.phase = CyclePhase::PROBE_DOWN;
+  cycle_.phase = ProbePhase::PROBE_DOWN;
   cycle_.rounds_in_phase = 0;
   cycle_.phase_start_time = now;
   ++sender_->connection_stats_->bbr_num_cycles;
@@ -538,32 +538,32 @@
 }
 
 void Bbr2ProbeBwMode::EnterProbeCruise(QuicTime now) {
-  if (cycle_.phase == CyclePhase::PROBE_DOWN) {
+  if (cycle_.phase == ProbePhase::PROBE_DOWN) {
     ExitProbeDown();
   }
   QUIC_DVLOG(2) << sender_ << " Phase change: " << cycle_.phase << " ==> "
-                << CyclePhase::PROBE_CRUISE << " after "
+                << ProbePhase::PROBE_CRUISE << " after "
                 << now - cycle_.phase_start_time << ", or "
                 << cycle_.rounds_in_phase << " rounds.  @ " << now;
 
   model_->cap_inflight_lo(model_->inflight_hi());
-  cycle_.phase = CyclePhase::PROBE_CRUISE;
+  cycle_.phase = ProbePhase::PROBE_CRUISE;
   cycle_.rounds_in_phase = 0;
   cycle_.phase_start_time = now;
   cycle_.is_sample_from_probing = false;
 }
 
 void Bbr2ProbeBwMode::EnterProbeRefill(uint64_t probe_up_rounds, QuicTime now) {
-  if (cycle_.phase == CyclePhase::PROBE_DOWN) {
+  if (cycle_.phase == ProbePhase::PROBE_DOWN) {
     ExitProbeDown();
   }
   QUIC_DVLOG(2) << sender_ << " Phase change: " << cycle_.phase << " ==> "
-                << CyclePhase::PROBE_REFILL << " after "
+                << ProbePhase::PROBE_REFILL << " after "
                 << now - cycle_.phase_start_time << ", or "
                 << cycle_.rounds_in_phase
                 << " rounds. probe_up_rounds:" << probe_up_rounds << "  @ "
                 << now;
-  cycle_.phase = CyclePhase::PROBE_REFILL;
+  cycle_.phase = ProbePhase::PROBE_REFILL;
   cycle_.rounds_in_phase = 0;
   cycle_.phase_start_time = now;
   cycle_.is_sample_from_probing = false;
@@ -577,12 +577,12 @@
 }
 
 void Bbr2ProbeBwMode::EnterProbeUp(QuicTime now) {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_REFILL);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_REFILL);
   QUIC_DVLOG(2) << sender_ << " Phase change: " << cycle_.phase << " ==> "
-                << CyclePhase::PROBE_UP << " after "
+                << ProbePhase::PROBE_UP << " after "
                 << now - cycle_.phase_start_time << ", or "
                 << cycle_.rounds_in_phase << " rounds.  @ " << now;
-  cycle_.phase = CyclePhase::PROBE_UP;
+  cycle_.phase = ProbePhase::PROBE_UP;
   cycle_.rounds_in_phase = 0;
   cycle_.phase_start_time = now;
   cycle_.is_sample_from_probing = true;
@@ -592,7 +592,7 @@
 }
 
 void Bbr2ProbeBwMode::ExitProbeDown() {
-  QUICHE_DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_DOWN);
+  QUICHE_DCHECK_EQ(cycle_.phase, ProbePhase::PROBE_DOWN);
   if (!cycle_.has_advanced_max_bw) {
     QUIC_DVLOG(2) << sender_ << " Advancing max bw filter at end of cycle.";
     model_->AdvanceMaxBandwidthFilter();
@@ -600,29 +600,7 @@
   }
 }
 
-// static
-const char* Bbr2ProbeBwMode::CyclePhaseToString(CyclePhase phase) {
-  switch (phase) {
-    case CyclePhase::PROBE_NOT_STARTED:
-      return "PROBE_NOT_STARTED";
-    case CyclePhase::PROBE_UP:
-      return "PROBE_UP";
-    case CyclePhase::PROBE_DOWN:
-      return "PROBE_DOWN";
-    case CyclePhase::PROBE_CRUISE:
-      return "PROBE_CRUISE";
-    case CyclePhase::PROBE_REFILL:
-      return "PROBE_REFILL";
-    default:
-      break;
-  }
-  return "<Invalid CyclePhase>";
-}
 
-std::ostream& operator<<(std::ostream& os,
-                         const Bbr2ProbeBwMode::CyclePhase phase) {
-  return os << Bbr2ProbeBwMode::CyclePhaseToString(phase);
-}
 
 Bbr2ProbeBwMode::DebugState Bbr2ProbeBwMode::ExportDebugState() const {
   DebugState s;
@@ -642,12 +620,11 @@
 
 const Bbr2Params& Bbr2ProbeBwMode::Params() const { return sender_->Params(); }
 
-float Bbr2ProbeBwMode::PacingGainForPhase(
-    Bbr2ProbeBwMode::CyclePhase phase) const {
-  if (phase == Bbr2ProbeBwMode::CyclePhase::PROBE_UP) {
+float Bbr2ProbeBwMode::PacingGainForPhase(ProbePhase phase) const {
+  if (phase == ProbePhase::PROBE_UP) {
     return Params().probe_bw_probe_up_pacing_gain;
   }
-  if (phase == Bbr2ProbeBwMode::CyclePhase::PROBE_DOWN) {
+  if (phase == ProbePhase::PROBE_DOWN) {
     return Params().probe_bw_probe_down_pacing_gain;
   }
   return Params().probe_bw_default_pacing_gain;
diff --git a/quiche/quic/core/congestion_control/bbr2_probe_bw.h b/quiche/quic/core/congestion_control/bbr2_probe_bw.h
index b5a1703..83c5764 100644
--- a/quiche/quic/core/congestion_control/bbr2_probe_bw.h
+++ b/quiche/quic/core/congestion_control/bbr2_probe_bw.h
@@ -38,18 +38,9 @@
   Bbr2Mode OnExitQuiescence(QuicTime now,
                             QuicTime quiescence_start_time) override;
 
-  enum class CyclePhase : uint8_t {
-    PROBE_NOT_STARTED,
-    PROBE_UP,
-    PROBE_DOWN,
-    PROBE_CRUISE,
-    PROBE_REFILL,
-  };
-
-  static const char* CyclePhaseToString(CyclePhase phase);
 
   struct QUICHE_EXPORT DebugState {
-    CyclePhase phase;
+    ProbePhase phase;
     QuicTime cycle_start_time = QuicTime::Zero();
     QuicTime phase_start_time = QuicTime::Zero();
   };
@@ -58,7 +49,7 @@
 
  private:
   const Bbr2Params& Params() const;
-  float PacingGainForPhase(CyclePhase phase) const;
+  float PacingGainForPhase(ProbePhase phase) const;
 
   void UpdateProbeUp(QuicByteCount prior_in_flight,
                      const Bbr2CongestionEvent& congestion_event);
@@ -108,7 +99,7 @@
 
   struct QUICHE_EXPORT Cycle {
     QuicTime cycle_start_time = QuicTime::Zero();
-    CyclePhase phase = CyclePhase::PROBE_NOT_STARTED;
+    ProbePhase phase = ProbePhase::PROBE_NOT_STARTED;
     uint64_t rounds_in_phase = 0;
     QuicTime phase_start_time = QuicTime::Zero();
     QuicRoundTripCount rounds_since_probe = 0;
@@ -130,9 +121,6 @@
 QUICHE_EXPORT std::ostream& operator<<(
     std::ostream& os, const Bbr2ProbeBwMode::DebugState& state);
 
-QUICHE_EXPORT std::ostream& operator<<(std::ostream& os,
-                                       const Bbr2ProbeBwMode::CyclePhase phase);
-
 }  // namespace quic
 
 #endif  // QUICHE_QUIC_CORE_CONGESTION_CONTROL_BBR2_PROBE_BW_H_
diff --git a/quiche/quic/core/congestion_control/bbr2_simulator_test.cc b/quiche/quic/core/congestion_control/bbr2_simulator_test.cc
index 205f102..6214aff 100644
--- a/quiche/quic/core/congestion_control/bbr2_simulator_test.cc
+++ b/quiche/quic/core/congestion_control/bbr2_simulator_test.cc
@@ -48,7 +48,6 @@
 
 namespace quic {
 
-using CyclePhase = Bbr2ProbeBwMode::CyclePhase;
 
 namespace test {
 
@@ -1549,7 +1548,7 @@
         QuicRoundTripCount rounds_passed =
             debug_state.round_trip_count - start_round_trip;
         return rounds_passed >= 4 && debug_state.mode == Bbr2Mode::PROBE_BW &&
-               debug_state.probe_bw.phase == CyclePhase::PROBE_REFILL;
+               debug_state.probe_bw.phase == ProbePhase::PROBE_REFILL;
       },
       timeout);
   ASSERT_TRUE(simulator_result);
@@ -1573,7 +1572,7 @@
   simulator_result = SendUntilOrTimeout(
       [this]() {
         return sender_->ExportDebugState().probe_bw.phase ==
-               CyclePhase::PROBE_REFILL;
+               ProbePhase::PROBE_REFILL;
       },
       timeout);
   ASSERT_TRUE(simulator_result);
@@ -1585,7 +1584,7 @@
   for (int i = 0; i < 2; i++) {
     SendBursts(params, 5, target_bandwidth * burst_interval, burst_interval);
     EXPECT_EQ(Bbr2Mode::PROBE_BW, sender_->ExportDebugState().mode);
-    EXPECT_EQ(CyclePhase::PROBE_UP, sender_->ExportDebugState().probe_bw.phase);
+    EXPECT_EQ(ProbePhase::PROBE_UP, sender_->ExportDebugState().probe_bw.phase);
     EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
                      sender_->ExportDebugState().bandwidth_hi, 0.02f);
   }
@@ -1604,13 +1603,13 @@
   simulator_result = simulator_.RunUntilOrTimeout(
       [this]() {
         return sender_->ExportDebugState().probe_bw.phase ==
-               CyclePhase::PROBE_DOWN;
+               ProbePhase::PROBE_DOWN;
       },
       timeout);
   ASSERT_TRUE(simulator_result);
   simulator_.RunFor(0.75 * sender_->ExportDebugState().min_rtt);
   EXPECT_EQ(Bbr2Mode::PROBE_BW, sender_->ExportDebugState().mode);
-  EXPECT_EQ(CyclePhase::PROBE_CRUISE,
+  EXPECT_EQ(ProbePhase::PROBE_CRUISE,
             sender_->ExportDebugState().probe_bw.phase);
 }
 
@@ -1775,7 +1774,7 @@
   sender_->OnCongestionEvent(
       /*rtt_updated=*/true, sender_unacked_map()->bytes_in_flight(), now,
       acked_packets, {}, 0, 0);
-  ASSERT_EQ(CyclePhase::PROBE_REFILL,
+  ASSERT_EQ(ProbePhase::PROBE_REFILL,
             sender_->ExportDebugState().probe_bw.phase);
 
   // Send and Ack one packet to exit app limited and enter PROBE_UP.
@@ -1786,7 +1785,7 @@
       /*rtt_updated=*/true, kDefaultMaxPacketSize, now,
       {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, now)}, {}, 0,
       0);
-  ASSERT_EQ(CyclePhase::PROBE_UP, sender_->ExportDebugState().probe_bw.phase);
+  ASSERT_EQ(ProbePhase::PROBE_UP, sender_->ExportDebugState().probe_bw.phase);
 
   // Send 2 packets and lose the first one(50% loss) to exit PROBE_UP.
   for (uint64_t i = 0; i < 2; ++i) {
@@ -1940,7 +1939,7 @@
   simulator_result = SendUntilOrTimeout(
       [this]() {
         return sender_->ExportDebugState().probe_bw.phase ==
-               CyclePhase::PROBE_REFILL;
+               ProbePhase::PROBE_REFILL;
       },
       timeout);
   ASSERT_TRUE(simulator_result);