Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / net / quic / congestion_control / tcp_cubic_sender.h
bloba919d027b1e13b799e007e62f8a8b283627583c2
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 // TCP cubic send side congestion algorithm, emulates the behavior of
6 // TCP cubic.
8 #ifndef NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
9 #define NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "net/base/net_export.h"
14 #include "net/quic/congestion_control/cubic.h"
15 #include "net/quic/congestion_control/hybrid_slow_start.h"
16 #include "net/quic/congestion_control/prr_sender.h"
17 #include "net/quic/congestion_control/send_algorithm_interface.h"
18 #include "net/quic/crypto/cached_network_parameters.h"
19 #include "net/quic/quic_bandwidth.h"
20 #include "net/quic/quic_connection_stats.h"
21 #include "net/quic/quic_protocol.h"
22 #include "net/quic/quic_time.h"
24 namespace net {
26 class RttStats;
28 namespace test {
29 class TcpCubicSenderPeer;
30 } // namespace test
32 class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface {
33 public:
34 // Reno option and max_tcp_congestion_window are provided for testing.
35 TcpCubicSender(const QuicClock* clock,
36 const RttStats* rtt_stats,
37 bool reno,
38 QuicPacketCount initial_tcp_congestion_window,
39 QuicPacketCount max_tcp_congestion_window,
40 QuicConnectionStats* stats);
41 ~TcpCubicSender() override;
43 // Start implementation of SendAlgorithmInterface.
44 void SetFromConfig(const QuicConfig& config,
45 bool is_server,
46 bool using_pacing) override;
47 bool ResumeConnectionState(
48 const CachedNetworkParameters& cached_network_params) override;
49 void SetNumEmulatedConnections(int num_connections) override;
50 void OnCongestionEvent(bool rtt_updated,
51 QuicByteCount bytes_in_flight,
52 const CongestionVector& acked_packets,
53 const CongestionVector& lost_packets) override;
54 bool OnPacketSent(QuicTime sent_time,
55 QuicByteCount bytes_in_flight,
56 QuicPacketSequenceNumber sequence_number,
57 QuicByteCount bytes,
58 HasRetransmittableData is_retransmittable) override;
59 void OnRetransmissionTimeout(bool packets_retransmitted) override;
60 void RevertRetransmissionTimeout() override;
61 QuicTime::Delta TimeUntilSend(
62 QuicTime now,
63 QuicByteCount bytes_in_flight,
64 HasRetransmittableData has_retransmittable_data) const override;
65 QuicBandwidth PacingRate() const override;
66 QuicBandwidth BandwidthEstimate() const override;
67 bool HasReliableBandwidthEstimate() const override;
68 QuicTime::Delta RetransmissionDelay() const override;
69 QuicByteCount GetCongestionWindow() const override;
70 bool InSlowStart() const override;
71 bool InRecovery() const override;
72 QuicByteCount GetSlowStartThreshold() const override;
73 CongestionControlType GetCongestionControlType() const override;
74 // End implementation of SendAlgorithmInterface.
76 private:
77 friend class test::TcpCubicSenderPeer;
79 // Compute the TCP Reno beta based on the current number of connections.
80 float RenoBeta() const;
82 // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
83 void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
84 QuicByteCount acked_bytes,
85 QuicByteCount bytes_in_flight);
86 void OnPacketLost(QuicPacketSequenceNumber largest_loss,
87 QuicByteCount bytes_in_flight);
89 void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number,
90 QuicByteCount bytes_in_flight);
91 bool IsCwndLimited(QuicByteCount bytes_in_flight) const;
93 HybridSlowStart hybrid_slow_start_;
94 Cubic cubic_;
95 PrrSender prr_;
96 const RttStats* rtt_stats_;
97 QuicConnectionStats* stats_;
99 // If true, Reno congestion control is used instead of Cubic.
100 const bool reno_;
102 // Number of connections to simulate.
103 uint32 num_connections_;
105 // ACK counter for the Reno implementation.
106 uint64 congestion_window_count_;
108 // Track the largest packet that has been sent.
109 QuicPacketSequenceNumber largest_sent_sequence_number_;
111 // Track the largest packet that has been acked.
112 QuicPacketSequenceNumber largest_acked_sequence_number_;
114 // Track the largest sequence number outstanding when a CWND cutback occurs.
115 QuicPacketSequenceNumber largest_sent_at_last_cutback_;
117 // Congestion window in packets.
118 QuicPacketCount congestion_window_;
120 // Congestion window before the last RTO.
121 // Must be 0 before or after RTO recovery.
122 QuicPacketCount previous_congestion_window_;
124 // Slow start congestion window in packets, aka ssthresh.
125 QuicPacketCount slowstart_threshold_;
127 // Slow start threshold before the last loss event or RTO.
128 QuicPacketCount previous_slowstart_threshold_;
130 // Whether the last loss event caused us to exit slowstart.
131 // Used for stats collection of slowstart_packets_lost
132 bool last_cutback_exited_slowstart_;
134 // Maximum number of outstanding packets for tcp.
135 QuicPacketCount max_tcp_congestion_window_;
137 const QuicClock* clock_;
139 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender);
142 } // namespace net
144 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_