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
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"
24 // Default maximum packet size used in Linux TCP implementations.
25 const QuicByteCount kDefaultTCPMSS = 1460;
30 class TcpCubicSenderPeer;
33 class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface {
35 // Reno option and max_tcp_congestion_window are provided for testing.
36 TcpCubicSender(const QuicClock* clock,
37 const RttStats* rtt_stats,
39 QuicTcpCongestionWindow max_tcp_congestion_window,
40 QuicConnectionStats* stats);
41 virtual ~TcpCubicSender();
43 bool InSlowStart() const;
45 // Start implementation of SendAlgorithmInterface.
46 virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE;
47 virtual void OnIncomingQuicCongestionFeedbackFrame(
48 const QuicCongestionFeedbackFrame& feedback,
49 QuicTime feedback_receive_time) OVERRIDE;
50 virtual void OnCongestionEvent(bool rtt_updated,
51 QuicByteCount bytes_in_flight,
52 const CongestionMap& acked_packets,
53 const CongestionMap& lost_packets) OVERRIDE;
54 virtual bool OnPacketSent(QuicTime sent_time,
55 QuicByteCount bytes_in_flight,
56 QuicPacketSequenceNumber sequence_number,
58 HasRetransmittableData is_retransmittable) OVERRIDE;
59 virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE;
60 virtual QuicTime::Delta TimeUntilSend(
62 QuicByteCount bytes_in_flight,
63 HasRetransmittableData has_retransmittable_data) OVERRIDE;
64 virtual QuicBandwidth BandwidthEstimate() const OVERRIDE;
65 virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE;
66 virtual QuicByteCount GetCongestionWindow() const OVERRIDE;
67 // End implementation of SendAlgorithmInterface.
70 friend class test::TcpCubicSenderPeer;
72 // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
73 void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
74 QuicByteCount acked_bytes,
75 QuicByteCount bytes_in_flight);
76 void OnPacketLost(QuicPacketSequenceNumber largest_loss,
77 QuicByteCount bytes_in_flight);
79 QuicByteCount SendWindow();
80 void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number,
81 QuicByteCount bytes_in_flight);
82 bool IsCwndLimited(QuicByteCount bytes_in_flight) const;
83 bool InRecovery() const;
84 // Methods for isolating PRR from the rest of TCP Cubic.
85 void PrrOnPacketLost(QuicByteCount bytes_in_flight);
86 void PrrOnPacketAcked(QuicByteCount acked_bytes);
87 QuicTime::Delta PrrTimeUntilSend(QuicByteCount bytes_in_flight);
90 HybridSlowStart hybrid_slow_start_;
92 const RttStats* rtt_stats_;
93 QuicConnectionStats* stats_;
95 // Reno provided for testing.
98 // ACK counter for the Reno implementation.
99 int64 congestion_window_count_;
101 // Receiver side advertised window.
102 QuicByteCount receive_window_;
104 // Bytes sent and acked since the last loss event. Used for PRR.
105 QuicByteCount prr_out_;
106 QuicByteCount prr_delivered_;
107 size_t ack_count_since_loss_;
109 // The congestion window before the last loss event.
110 QuicByteCount bytes_in_flight_before_loss_;
112 // Track the largest packet that has been sent.
113 QuicPacketSequenceNumber largest_sent_sequence_number_;
115 // Track the largest packet that has been acked.
116 QuicPacketSequenceNumber largest_acked_sequence_number_;
118 // Track the largest sequence number outstanding when a CWND cutback occurs.
119 QuicPacketSequenceNumber largest_sent_at_last_cutback_;
121 // Congestion window in packets.
122 QuicTcpCongestionWindow congestion_window_;
124 // Slow start congestion window in packets, aka ssthresh.
125 QuicTcpCongestionWindow slowstart_threshold_;
127 // Whether the last loss event caused us to exit slowstart.
128 // Used for stats collection of slowstart_packets_lost
129 bool last_cutback_exited_slowstart_;
131 // Maximum number of outstanding packets for tcp.
132 QuicTcpCongestionWindow max_tcp_congestion_window_;
134 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender);
139 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_