1 // Copyright (c) 2015 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_BYTES_SENDER_H_
8 #define NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_BYTES_SENDER_H_
10 #include "base/basictypes.h"
11 #include "net/base/net_export.h"
12 #include "net/quic/congestion_control/cubic_bytes.h"
13 #include "net/quic/congestion_control/hybrid_slow_start.h"
14 #include "net/quic/congestion_control/prr_sender.h"
15 #include "net/quic/congestion_control/send_algorithm_interface.h"
16 #include "net/quic/quic_bandwidth.h"
17 #include "net/quic/quic_connection_stats.h"
18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_time.h"
26 class TcpCubicBytesSenderPeer
;
29 class NET_EXPORT_PRIVATE TcpCubicBytesSender
: public SendAlgorithmInterface
{
31 TcpCubicBytesSender(const QuicClock
* clock
,
32 const RttStats
* rtt_stats
,
34 QuicPacketCount initial_tcp_congestion_window
,
35 QuicPacketCount max_congestion_window
,
36 QuicConnectionStats
* stats
);
37 ~TcpCubicBytesSender() override
;
39 // Start implementation of SendAlgorithmInterface.
40 void SetFromConfig(const QuicConfig
& config
,
41 Perspective perspective
) override
;
42 bool ResumeConnectionState(
43 const CachedNetworkParameters
& cached_network_params
,
44 bool max_bandwidth_resumption
) override
;
45 void SetNumEmulatedConnections(int num_connections
) override
;
46 void SetMaxCongestionWindow(QuicByteCount max_congestion_window
) override
;
47 void OnCongestionEvent(bool rtt_updated
,
48 QuicByteCount bytes_in_flight
,
49 const CongestionVector
& acked_packets
,
50 const CongestionVector
& lost_packets
) override
;
51 bool OnPacketSent(QuicTime sent_time
,
52 QuicByteCount bytes_in_flight
,
53 QuicPacketSequenceNumber sequence_number
,
55 HasRetransmittableData is_retransmittable
) override
;
56 void OnRetransmissionTimeout(bool packets_retransmitted
) override
;
57 QuicTime::Delta
TimeUntilSend(
59 QuicByteCount bytes_in_flight
,
60 HasRetransmittableData has_retransmittable_data
) const override
;
61 QuicBandwidth
PacingRate() const override
;
62 QuicBandwidth
BandwidthEstimate() const override
;
63 bool HasReliableBandwidthEstimate() const override
;
64 QuicTime::Delta
RetransmissionDelay() const override
;
65 QuicByteCount
GetCongestionWindow() const override
;
66 bool InSlowStart() const override
;
67 bool InRecovery() const override
;
68 QuicByteCount
GetSlowStartThreshold() const override
;
69 CongestionControlType
GetCongestionControlType() const override
;
70 // End implementation of SendAlgorithmInterface.
73 friend class test::TcpCubicBytesSenderPeer
;
75 // Compute the TCP Reno beta based on the current number of connections.
76 float RenoBeta() const;
78 // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
79 void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number
,
80 QuicByteCount acked_bytes
,
81 QuicByteCount bytes_in_flight
);
82 void OnPacketLost(QuicPacketSequenceNumber largest_loss
,
83 QuicByteCount bytes_in_flight
);
85 void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number
,
86 QuicByteCount acked_bytes
,
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 num_acked_packets_
;
105 // Track the largest packet that has been sent.
106 QuicPacketSequenceNumber largest_sent_sequence_number_
;
108 // Track the largest packet that has been acked.
109 QuicPacketSequenceNumber largest_acked_sequence_number_
;
111 // Track the largest sequence number outstanding when a CWND cutback occurs.
112 QuicPacketSequenceNumber largest_sent_at_last_cutback_
;
114 // Congestion window in bytes.
115 QuicByteCount congestion_window_
;
117 // Minimum congestion window in bytes.
118 QuicByteCount min_congestion_window_
;
120 // Maximum congestion window in bytes.
121 QuicByteCount max_congestion_window_
;
123 // Slow start congestion window in bytes, aka ssthresh.
124 QuicByteCount slowstart_threshold_
;
126 // Whether the last loss event caused us to exit slowstart. Used for stats
127 // collection of slowstart_packets_lost.
128 bool last_cutback_exited_slowstart_
;
130 const QuicClock
* clock_
;
132 DISALLOW_COPY_AND_ASSIGN(TcpCubicBytesSender
);
137 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_BYTES_SENDER_H_