• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
7 
8 #ifndef NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
9 #define NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
10 
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"
21 
22 namespace net {
23 
24 class RttStats;
25 
26 namespace test {
27 class TcpCubicSenderPeer;
28 }  // namespace test
29 
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   virtual ~TcpCubicSender();
39 
40   // Start implementation of SendAlgorithmInterface.
41   virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE;
42   virtual void OnIncomingQuicCongestionFeedbackFrame(
43       const QuicCongestionFeedbackFrame& feedback,
44       QuicTime feedback_receive_time) OVERRIDE;
45   virtual void OnCongestionEvent(bool rtt_updated,
46                                  QuicByteCount bytes_in_flight,
47                                  const CongestionVector& acked_packets,
48                                  const CongestionVector& lost_packets) OVERRIDE;
49   virtual bool OnPacketSent(QuicTime sent_time,
50                             QuicByteCount bytes_in_flight,
51                             QuicPacketSequenceNumber sequence_number,
52                             QuicByteCount bytes,
53                             HasRetransmittableData is_retransmittable) OVERRIDE;
54   virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE;
55   virtual void RevertRetransmissionTimeout() OVERRIDE;
56   virtual QuicTime::Delta TimeUntilSend(
57       QuicTime now,
58       QuicByteCount bytes_in_flight,
59       HasRetransmittableData has_retransmittable_data) const OVERRIDE;
60   virtual QuicBandwidth BandwidthEstimate() const OVERRIDE;
61   virtual bool HasReliableBandwidthEstimate() const OVERRIDE;
62   virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE;
63   virtual QuicByteCount GetCongestionWindow() const OVERRIDE;
64   virtual bool InSlowStart() const OVERRIDE;
65   virtual bool InRecovery() const OVERRIDE;
66   virtual QuicByteCount GetSlowStartThreshold() const OVERRIDE;
67   virtual CongestionControlType GetCongestionControlType() const OVERRIDE;
68   // End implementation of SendAlgorithmInterface.
69 
70  private:
71   friend class test::TcpCubicSenderPeer;
72 
73   // TODO(ianswett): Remove these and migrate to OnCongestionEvent.
74   void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
75                      QuicByteCount acked_bytes,
76                      QuicByteCount bytes_in_flight);
77   void OnPacketLost(QuicPacketSequenceNumber largest_loss,
78                     QuicByteCount bytes_in_flight);
79 
80   QuicByteCount SendWindow() const;
81   void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number,
82                          QuicByteCount bytes_in_flight);
83   bool IsCwndLimited(QuicByteCount bytes_in_flight) 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) const;
88 
89 
90   HybridSlowStart hybrid_slow_start_;
91   Cubic cubic_;
92   const RttStats* rtt_stats_;
93   QuicConnectionStats* stats_;
94 
95   // Reno provided for testing.
96   const bool reno_;
97 
98   // ACK counter for the Reno implementation.
99   int64 congestion_window_count_;
100 
101   // Receiver side advertised window.
102   QuicByteCount receive_window_;
103 
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_;
108 
109   // The congestion window before the last loss event.
110   QuicByteCount bytes_in_flight_before_loss_;
111 
112   // Track the largest packet that has been sent.
113   QuicPacketSequenceNumber largest_sent_sequence_number_;
114 
115   // Track the largest packet that has been acked.
116   QuicPacketSequenceNumber largest_acked_sequence_number_;
117 
118   // Track the largest sequence number outstanding when a CWND cutback occurs.
119   QuicPacketSequenceNumber largest_sent_at_last_cutback_;
120 
121   // Congestion window in packets.
122   QuicTcpCongestionWindow congestion_window_;
123 
124   // Congestion window before the last loss event or RTO.
125   QuicByteCount previous_congestion_window_;
126 
127   // Slow start congestion window in packets, aka ssthresh.
128   QuicTcpCongestionWindow slowstart_threshold_;
129 
130   // Slow start threshold before the last loss event or RTO.
131   QuicTcpCongestionWindow previous_slowstart_threshold_;
132 
133   // Whether the last loss event caused us to exit slowstart.
134   // Used for stats collection of slowstart_packets_lost
135   bool last_cutback_exited_slowstart_;
136 
137   // Maximum number of outstanding packets for tcp.
138   QuicTcpCongestionWindow max_tcp_congestion_window_;
139 
140   DISALLOW_COPY_AND_ASSIGN(TcpCubicSender);
141 };
142 
143 }  // namespace net
144 
145 #endif  // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
146