For BBRv2,
- Change the default STARTUP and DRAIN cwnd gain to 2.0.
- Change the meaning of BBQ2 to use 2.885 cwnd gain for STARTUP and DRAIN.

Flag is default true since cwnd gain 2.0 has been tried in a finch experiment for a long time.

Protected by FLAGS_quic_reloadable_flag_quic_bbr2_flip_bbq2.

PiperOrigin-RevId: 336296878
Change-Id: I8e14586fe92313c0418d03ea5f4ffae610e2ece1
diff --git a/quic/core/congestion_control/bbr2_misc.h b/quic/core/congestion_control/bbr2_misc.h
index 8732118..f68092b 100644
--- a/quic/core/congestion_control/bbr2_misc.h
+++ b/quic/core/congestion_control/bbr2_misc.h
@@ -76,8 +76,9 @@
    */
 
   // The gain for both CWND and PacingRate at startup.
+  float startup_cwnd_gain =
+      GetQuicReloadableFlag(quic_bbr2_flip_bbq2) ? 2.0 : 2.885;
   // TODO(wub): Maybe change to the newly derived value of 2.773 (4 * ln(2)).
-  float startup_cwnd_gain = 2.885;
   float startup_pacing_gain = 2.885;
 
   // Full bandwidth is declared if the total bandwidth growth is less than
@@ -94,7 +95,8 @@
   /*
    * DRAIN parameters.
    */
-  float drain_cwnd_gain = 2.885;
+  float drain_cwnd_gain =
+      GetQuicReloadableFlag(quic_bbr2_flip_bbq2) ? 2.0 : 2.885;
   float drain_pacing_gain = 1.0 / 2.885;
 
   /*
diff --git a/quic/core/congestion_control/bbr2_sender.cc b/quic/core/congestion_control/bbr2_sender.cc
index fe32835..6de304a 100644
--- a/quic/core/congestion_control/bbr2_sender.cc
+++ b/quic/core/congestion_control/bbr2_sender.cc
@@ -142,9 +142,14 @@
 void Bbr2Sender::ApplyConnectionOptions(
     const QuicTagVector& connection_options) {
   if (ContainsQuicTag(connection_options, kBBQ2)) {
-    // 2 is the lower, derived gain for CWND.
-    params_.startup_cwnd_gain = 2;
-    params_.drain_cwnd_gain = 2;
+    if (GetQuicReloadableFlag(quic_bbr2_flip_bbq2)) {
+      params_.startup_cwnd_gain = 2.885;
+      params_.drain_cwnd_gain = 2.885;
+    } else {
+      // 2 is the lower, derived gain for CWND.
+      params_.startup_cwnd_gain = 2;
+      params_.drain_cwnd_gain = 2;
+    }
   }
   if (ContainsQuicTag(connection_options, kBSAO)) {
     model_.EnableOverestimateAvoidance();
diff --git a/quic/core/congestion_control/bbr2_simulator_test.cc b/quic/core/congestion_control/bbr2_simulator_test.cc
index 1f5db20..ca8ac7e 100644
--- a/quic/core/congestion_control/bbr2_simulator_test.cc
+++ b/quic/core/congestion_control/bbr2_simulator_test.cc
@@ -589,10 +589,18 @@
   ASSERT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
   EXPECT_APPROX_EQ(sender_->BandwidthEstimate() * (1 / 2.885f),
                    sender_->PacingRate(0), 0.01f);
-  // BBR uses CWND gain of 2.88 during STARTUP, hence it will fill the buffer
-  // with approximately 1.88 BDPs.  Here, we use 1.5 to give some margin for
-  // error.
-  EXPECT_GE(queue->bytes_queued(), 1.5 * params.BDP());
+
+  if (GetQuicReloadableFlag(quic_bbr2_flip_bbq2)) {
+    // BBR uses CWND gain of 2 during STARTUP, hence it will fill the buffer
+    // with approximately 1 BDP.  Here, we use 0.95 to give some margin for
+    // error.
+    EXPECT_GE(queue->bytes_queued(), 0.95 * params.BDP());
+  } else {
+    // BBR uses CWND gain of 2.88 during STARTUP, hence it will fill the buffer
+    // with approximately 1.88 BDPs.  Here, we use 1.5 to give some margin for
+    // error.
+    EXPECT_GE(queue->bytes_queued(), 1.5 * params.BDP());
+  }
 
   // Observe increased RTT due to bufferbloat.
   const QuicTime::Delta queueing_delay =
diff --git a/quic/core/crypto/crypto_protocol.h b/quic/core/crypto/crypto_protocol.h
index bf3a97c..d272aeb 100644
--- a/quic/core/crypto/crypto_protocol.h
+++ b/quic/core/crypto/crypto_protocol.h
@@ -100,8 +100,8 @@
 const QuicTag kBBRS = TAG('B', 'B', 'R', 'S');   // DEPRECATED
 const QuicTag kBBQ1 = TAG('B', 'B', 'Q', '1');   // BBR with lower 2.77 STARTUP
                                                  // pacing and CWND gain.
-const QuicTag kBBQ2 = TAG('B', 'B', 'Q', '2');   // BBR with lower 2.0 STARTUP
-                                                 // CWND gain.
+const QuicTag kBBQ2 = TAG('B', 'B', 'Q', '2');   // BBRv2 with 2.885 STARTUP and
+                                                 // DRAIN CWND gain.
 const QuicTag kBBQ3 = TAG('B', 'B', 'Q', '3');   // BBR with ack aggregation
                                                  // compensation in STARTUP.
 const QuicTag kBBQ5 = TAG('B', 'B', 'Q', '5');   // Expire ack aggregation upon