89e9bd63ab876164e43dd4f08c5d77623ecd8376
[platform/framework/web/crosswalk.git] / src / net / quic / congestion_control / tcp_cubic_sender.h
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 // Default maximum packet size used in Linux TCP implementations.
25 const QuicByteCount kDefaultTCPMSS = 1460;
26
27 class RttStats;
28
29 namespace test {
30 class TcpCubicSenderPeer;
31 }  // namespace test
32
33 class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface {
34  public:
35   // Reno option and max_tcp_congestion_window are provided for testing.
36   TcpCubicSender(const QuicClock* clock,
37                  const RttStats* rtt_stats,
38                  bool reno,
39                  QuicTcpCongestionWindow max_tcp_congestion_window,
40                  QuicConnectionStats* stats);
41   virtual ~TcpCubicSender();
42
43   // Start implementation of SendAlgorithmInterface.
44   virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE;
45   virtual void OnIncomingQuicCongestionFeedbackFrame(
46       const QuicCongestionFeedbackFrame& feedback,
47       QuicTime feedback_receive_time) OVERRIDE;
48   virtual void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
49                              QuicByteCount acked_bytes) OVERRIDE;
50   virtual void OnPacketLost(QuicPacketSequenceNumber largest_loss,
51                             QuicTime ack_receive_time) OVERRIDE;
52   virtual bool OnPacketSent(QuicTime sent_time,
53                             QuicPacketSequenceNumber sequence_number,
54                             QuicByteCount bytes,
55                             TransmissionType transmission_type,
56                             HasRetransmittableData is_retransmittable) OVERRIDE;
57   virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE;
58   virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
59                                  QuicByteCount abandoned_bytes) OVERRIDE;
60   virtual QuicTime::Delta TimeUntilSend(
61       QuicTime now,
62       TransmissionType transmission_type,
63       HasRetransmittableData has_retransmittable_data,
64       IsHandshake handshake) OVERRIDE;
65   virtual QuicBandwidth BandwidthEstimate() const OVERRIDE;
66   virtual void UpdateRtt(QuicTime::Delta rtt_sample) OVERRIDE;
67   virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE;
68   virtual QuicByteCount GetCongestionWindow() const OVERRIDE;
69   // End implementation of SendAlgorithmInterface.
70
71  private:
72   friend class test::TcpCubicSenderPeer;
73
74   QuicByteCount AvailableSendWindow();
75   QuicByteCount SendWindow();
76   void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number);
77   bool IsCwndLimited() const;
78   bool InRecovery() const;
79
80   HybridSlowStart hybrid_slow_start_;
81   Cubic cubic_;
82   const RttStats* rtt_stats_;
83
84   // Reno provided for testing.
85   const bool reno_;
86
87   // ACK counter for the Reno implementation.
88   int64 congestion_window_count_;
89
90   // Receiver side advertised window.
91   QuicByteCount receive_window_;
92
93   // Bytes in flight, aka bytes on the wire.
94   QuicByteCount bytes_in_flight_;
95
96   // Bytes sent and acked since the last loss event.  Used for PRR.
97   QuicByteCount prr_out_;
98   QuicByteCount prr_delivered_;
99   size_t ack_count_since_loss_;
100
101   // The congestion window before the last loss event.
102   QuicByteCount bytes_in_flight_before_loss_;
103
104   // We need to keep track of the end sequence number of each RTT "burst".
105   bool update_end_sequence_number_;
106   QuicPacketSequenceNumber end_sequence_number_;
107
108   // Track the largest packet that has been sent.
109   QuicPacketSequenceNumber largest_sent_sequence_number_;
110
111   // Track the largest packet that has been acked.
112   QuicPacketSequenceNumber largest_acked_sequence_number_;
113
114   // Track the largest sequence number outstanding when a CWND cutback occurs.
115   QuicPacketSequenceNumber largest_sent_at_last_cutback_;
116
117   // Congestion window in packets.
118   QuicTcpCongestionWindow congestion_window_;
119
120   // Slow start congestion window in packets, aka ssthresh.
121   QuicTcpCongestionWindow slowstart_threshold_;
122
123   // Maximum number of outstanding packets for tcp.
124   QuicTcpCongestionWindow max_tcp_congestion_window_;
125
126   DISALLOW_COPY_AND_ASSIGN(TcpCubicSender);
127 };
128
129 }  // namespace net
130
131 #endif  // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_