1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "quiche/quic/core/congestion_control/send_algorithm_interface.h"
6
7 #include "absl/base/attributes.h"
8 #include "quiche/quic/core/congestion_control/bbr2_sender.h"
9 #include "quiche/quic/core/congestion_control/bbr_sender.h"
10 #include "quiche/quic/core/congestion_control/tcp_cubic_sender_bytes.h"
11 #include "quiche/quic/core/quic_packets.h"
12 #include "quiche/quic/platform/api/quic_bug_tracker.h"
13 #include "quiche/quic/platform/api/quic_flag_utils.h"
14 #include "quiche/quic/platform/api/quic_flags.h"
15
16 namespace quic {
17
18 class RttStats;
19
20 // Factory for send side congestion control algorithm.
Create(const QuicClock * clock,const RttStats * rtt_stats,const QuicUnackedPacketMap * unacked_packets,CongestionControlType congestion_control_type,QuicRandom * random,QuicConnectionStats * stats,QuicPacketCount initial_congestion_window,SendAlgorithmInterface * old_send_algorithm)21 SendAlgorithmInterface* SendAlgorithmInterface::Create(
22 const QuicClock* clock, const RttStats* rtt_stats,
23 const QuicUnackedPacketMap* unacked_packets,
24 CongestionControlType congestion_control_type, QuicRandom* random,
25 QuicConnectionStats* stats, QuicPacketCount initial_congestion_window,
26 SendAlgorithmInterface* old_send_algorithm) {
27 QuicPacketCount max_congestion_window =
28 GetQuicFlag(quic_max_congestion_window);
29 switch (congestion_control_type) {
30 case kGoogCC: // GoogCC is not supported by quic/core, fall back to BBR.
31 case kBBR:
32 return new BbrSender(clock->ApproximateNow(), rtt_stats, unacked_packets,
33 initial_congestion_window, max_congestion_window,
34 random, stats);
35 case kBBRv2:
36 return new Bbr2Sender(
37 clock->ApproximateNow(), rtt_stats, unacked_packets,
38 initial_congestion_window, max_congestion_window, random, stats,
39 old_send_algorithm &&
40 old_send_algorithm->GetCongestionControlType() == kBBR
41 ? static_cast<BbrSender*>(old_send_algorithm)
42 : nullptr);
43 case kPCC:
44 // PCC is currently not supported, fall back to CUBIC instead.
45 ABSL_FALLTHROUGH_INTENDED;
46 case kCubicBytes:
47 return new TcpCubicSenderBytes(
48 clock, rtt_stats, false /* don't use Reno */,
49 initial_congestion_window, max_congestion_window, stats);
50 case kRenoBytes:
51 return new TcpCubicSenderBytes(clock, rtt_stats, true /* use Reno */,
52 initial_congestion_window,
53 max_congestion_window, stats);
54 }
55 return nullptr;
56 }
57
58 } // namespace quic
59