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 bool 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 QuicPacketSequenceNumber sequence_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 bool HasReliableBandwidthEstimate() const override
;
66 QuicTime::Delta
RetransmissionDelay() const override
;
67 QuicByteCount
GetCongestionWindow() const override
;
68 bool InSlowStart() const override
;
69 bool InRecovery() const override
;
70 QuicByteCount
GetSlowStartThreshold() const override
;
71 CongestionControlType
GetCongestionControlType() const override
;
72 // End implementation of SendAlgorithmInterface.
75 friend class test::TcpCubicSenderPeer
;
77 // Compute the TCP Reno beta based on the current number of connections.
78 float RenoBeta() const;
80 // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
81 void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number
,
82 QuicByteCount acked_bytes
,
83 QuicByteCount bytes_in_flight
);
84 void OnPacketLost(QuicPacketSequenceNumber largest_loss
,
85 QuicByteCount bytes_in_flight
);
87 void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number
,
88 QuicByteCount bytes_in_flight
);
89 bool IsCwndLimited(QuicByteCount bytes_in_flight
) const;
91 HybridSlowStart hybrid_slow_start_
;
94 const RttStats
* rtt_stats_
;
95 QuicConnectionStats
* stats_
;
97 // If true, Reno congestion control is used instead of Cubic.
100 // Number of connections to simulate.
101 uint32 num_connections_
;
103 // ACK counter for the Reno implementation.
104 uint64 congestion_window_count_
;
106 // Track the largest packet that has been sent.
107 QuicPacketSequenceNumber largest_sent_sequence_number_
;
109 // Track the largest packet that has been acked.
110 QuicPacketSequenceNumber largest_acked_sequence_number_
;
112 // Track the largest sequence number outstanding when a CWND cutback occurs.
113 QuicPacketSequenceNumber largest_sent_at_last_cutback_
;
115 // Congestion window in packets.
116 QuicPacketCount congestion_window_
;
118 // Minimum congestion window in packets.
119 QuicPacketCount min_congestion_window_
;
121 // Slow start congestion window in packets, aka ssthresh.
122 QuicPacketCount slowstart_threshold_
;
124 // Whether the last loss event caused us to exit slowstart.
125 // Used for stats collection of slowstart_packets_lost
126 bool last_cutback_exited_slowstart_
;
128 // Maximum number of outstanding packets for tcp.
129 QuicPacketCount max_tcp_congestion_window_
;
131 const QuicClock
* clock_
;
133 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender
);
138 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_