MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / net / quic / congestion_control / tcp_cubic_sender.h
blobed0428a59c7f244dd96bca7d05d775a2f5f954f0
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/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"
22 namespace net {
24 class RttStats;
26 namespace test {
27 class TcpCubicSenderPeer;
28 } // namespace test
30 class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface {
31 public:
32 // Reno option and max_tcp_congestion_window are provided for testing.
33 TcpCubicSender(const QuicClock* clock,
34 const RttStats* rtt_stats,
35 bool reno,
36 QuicTcpCongestionWindow max_tcp_congestion_window,
37 QuicConnectionStats* stats);
38 ~TcpCubicSender() override;
40 // Start implementation of SendAlgorithmInterface.
41 void SetFromConfig(const QuicConfig& config, bool is_server) override;
42 void SetNumEmulatedConnections(int num_connections) override;
43 void OnIncomingQuicCongestionFeedbackFrame(
44 const QuicCongestionFeedbackFrame& feedback,
45 QuicTime feedback_receive_time) override;
46 void OnCongestionEvent(bool rtt_updated,
47 QuicByteCount bytes_in_flight,
48 const CongestionVector& acked_packets,
49 const CongestionVector& lost_packets) override;
50 bool OnPacketSent(QuicTime sent_time,
51 QuicByteCount bytes_in_flight,
52 QuicPacketSequenceNumber sequence_number,
53 QuicByteCount bytes,
54 HasRetransmittableData is_retransmittable) override;
55 void OnRetransmissionTimeout(bool packets_retransmitted) override;
56 void RevertRetransmissionTimeout() override;
57 QuicTime::Delta TimeUntilSend(
58 QuicTime now,
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.
72 private:
73 friend class test::TcpCubicSenderPeer;
75 // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
76 void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
77 QuicByteCount acked_bytes,
78 QuicByteCount bytes_in_flight);
79 void OnPacketLost(QuicPacketSequenceNumber largest_loss,
80 QuicByteCount bytes_in_flight);
82 QuicByteCount SendWindow() const;
83 void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number,
84 QuicByteCount bytes_in_flight);
85 bool IsCwndLimited(QuicByteCount bytes_in_flight) const;
86 // Methods for isolating PRR from the rest of TCP Cubic.
87 void PrrOnPacketLost(QuicByteCount bytes_in_flight);
88 void PrrOnPacketAcked(QuicByteCount acked_bytes);
89 QuicTime::Delta PrrTimeUntilSend(QuicByteCount bytes_in_flight) const;
92 HybridSlowStart hybrid_slow_start_;
93 Cubic cubic_;
94 const RttStats* rtt_stats_;
95 QuicConnectionStats* stats_;
97 // If true, Reno congestion control is used instead of Cubic.
98 const bool reno_;
100 // Number of connections to simulate.
101 int num_connections_;
103 // ACK counter for the Reno implementation.
104 int64 congestion_window_count_;
106 // Receiver side advertised window.
107 QuicByteCount receive_window_;
109 // Bytes sent and acked since the last loss event. Used for PRR.
110 QuicByteCount prr_out_;
111 QuicByteCount prr_delivered_;
112 size_t ack_count_since_loss_;
114 // The congestion window before the last loss event.
115 QuicByteCount bytes_in_flight_before_loss_;
117 // Track the largest packet that has been sent.
118 QuicPacketSequenceNumber largest_sent_sequence_number_;
120 // Track the largest packet that has been acked.
121 QuicPacketSequenceNumber largest_acked_sequence_number_;
123 // Track the largest sequence number outstanding when a CWND cutback occurs.
124 QuicPacketSequenceNumber largest_sent_at_last_cutback_;
126 // Congestion window in packets.
127 QuicTcpCongestionWindow congestion_window_;
129 // Congestion window before the last loss event or RTO.
130 QuicByteCount previous_congestion_window_;
132 // Slow start congestion window in packets, aka ssthresh.
133 QuicTcpCongestionWindow slowstart_threshold_;
135 // Slow start threshold before the last loss event or RTO.
136 QuicTcpCongestionWindow previous_slowstart_threshold_;
138 // Whether the last loss event caused us to exit slowstart.
139 // Used for stats collection of slowstart_packets_lost
140 bool last_cutback_exited_slowstart_;
142 // Maximum number of outstanding packets for tcp.
143 QuicTcpCongestionWindow max_tcp_congestion_window_;
145 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender);
148 } // namespace net
150 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_