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.
5 // TCP cubic send side congestion algorithm, emulates the behavior of TCP cubic.
7 #ifndef NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
8 #define NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "net/base/net_export.h"
13 #include "net/quic/congestion_control/cubic.h"
14 #include "net/quic/congestion_control/hybrid_slow_start.h"
15 #include "net/quic/congestion_control/prr_sender.h"
16 #include "net/quic/congestion_control/send_algorithm_interface.h"
17 #include "net/quic/quic_bandwidth.h"
18 #include "net/quic/quic_connection_stats.h"
19 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_time.h"
27 class TcpCubicSenderPeer
;
30 class NET_EXPORT_PRIVATE TcpCubicSender
: public SendAlgorithmInterface
{
32 // Reno option and max_tcp_congestion_window are provided for testing.
33 TcpCubicSender(const QuicClock
* clock
,
34 const RttStats
* rtt_stats
,
36 QuicPacketCount initial_tcp_congestion_window
,
37 QuicPacketCount max_tcp_congestion_window
,
38 QuicConnectionStats
* stats
);
39 ~TcpCubicSender() override
;
41 // Start implementation of SendAlgorithmInterface.
42 void SetFromConfig(const QuicConfig
& config
,
43 Perspective perspective
) override
;
44 void ResumeConnectionState(
45 const CachedNetworkParameters
& cached_network_params
,
46 bool max_bandwidth_resumption
) override
;
47 void SetNumEmulatedConnections(int num_connections
) override
;
48 void SetMaxCongestionWindow(QuicByteCount max_congestion_window
) override
;
49 void OnCongestionEvent(bool rtt_updated
,
50 QuicByteCount bytes_in_flight
,
51 const CongestionVector
& acked_packets
,
52 const CongestionVector
& lost_packets
) override
;
53 bool OnPacketSent(QuicTime sent_time
,
54 QuicByteCount bytes_in_flight
,
55 QuicPacketNumber packet_number
,
57 HasRetransmittableData is_retransmittable
) override
;
58 void OnRetransmissionTimeout(bool packets_retransmitted
) override
;
59 QuicTime::Delta
TimeUntilSend(
61 QuicByteCount bytes_in_flight
,
62 HasRetransmittableData has_retransmittable_data
) const override
;
63 QuicBandwidth
PacingRate() const override
;
64 QuicBandwidth
BandwidthEstimate() const override
;
65 QuicTime::Delta
RetransmissionDelay() const override
;
66 QuicByteCount
GetCongestionWindow() const override
;
67 bool InSlowStart() const override
;
68 bool InRecovery() const override
;
69 QuicByteCount
GetSlowStartThreshold() const override
;
70 CongestionControlType
GetCongestionControlType() const override
;
71 // End implementation of SendAlgorithmInterface.
74 friend class test::TcpCubicSenderPeer
;
76 // Compute the TCP Reno beta based on the current number of connections.
77 float RenoBeta() const;
79 // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
80 void OnPacketAcked(QuicPacketNumber acked_packet_number
,
81 QuicByteCount acked_bytes
,
82 QuicByteCount bytes_in_flight
);
83 void OnPacketLost(QuicPacketNumber largest_loss
,
84 QuicByteCount bytes_in_flight
);
86 void MaybeIncreaseCwnd(QuicPacketNumber acked_packet_number
,
87 QuicByteCount bytes_in_flight
);
88 bool IsCwndLimited(QuicByteCount bytes_in_flight
) const;
90 HybridSlowStart hybrid_slow_start_
;
93 const RttStats
* rtt_stats_
;
94 QuicConnectionStats
* stats_
;
96 // If true, Reno congestion control is used instead of Cubic.
99 // Number of connections to simulate.
100 uint32 num_connections_
;
102 // ACK counter for the Reno implementation.
103 uint64 congestion_window_count_
;
105 // Track the largest packet that has been sent.
106 QuicPacketNumber largest_sent_packet_number_
;
108 // Track the largest packet that has been acked.
109 QuicPacketNumber largest_acked_packet_number_
;
111 // Track the largest packet number outstanding when a CWND cutback occurs.
112 QuicPacketNumber largest_sent_at_last_cutback_
;
114 // Congestion window in packets.
115 QuicPacketCount congestion_window_
;
117 // Minimum congestion window in packets.
118 QuicPacketCount min_congestion_window_
;
120 // Whether to use 4 packets as the actual min, but pace lower.
123 // Slow start congestion window in packets, aka ssthresh.
124 QuicPacketCount slowstart_threshold_
;
126 // Whether the last loss event caused us to exit slowstart.
127 // Used for stats collection of slowstart_packets_lost
128 bool last_cutback_exited_slowstart_
;
130 // Maximum number of outstanding packets for tcp.
131 QuicPacketCount max_tcp_congestion_window_
;
133 const QuicClock
* clock_
;
135 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender
);
140 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_