Home | History | Annotate | Download | only in congestion_control
      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_protocol.h"
     19 #include "net/quic/quic_time.h"
     20 
     21 namespace net {
     22 
     23 // Default maximum packet size used in Linux TCP implementations.
     24 const QuicByteCount kDefaultTCPMSS = 1460;
     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                  bool reno,
     35                  QuicTcpCongestionWindow max_tcp_congestion_window);
     36   virtual ~TcpCubicSender();
     37 
     38   // Start implementation of SendAlgorithmInterface.
     39   virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE;
     40   virtual void SetMaxPacketSize(QuicByteCount max_packet_size) OVERRIDE;
     41   virtual void OnIncomingQuicCongestionFeedbackFrame(
     42       const QuicCongestionFeedbackFrame& feedback,
     43       QuicTime feedback_receive_time,
     44       const SentPacketsMap& sent_packets) OVERRIDE;
     45   virtual void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
     46                              QuicByteCount acked_bytes,
     47                              QuicTime::Delta rtt) OVERRIDE;
     48   virtual void OnPacketLost(QuicPacketSequenceNumber largest_loss,
     49                             QuicTime ack_receive_time) OVERRIDE;
     50   virtual bool OnPacketSent(QuicTime sent_time,
     51                             QuicPacketSequenceNumber sequence_number,
     52                             QuicByteCount bytes,
     53                             TransmissionType transmission_type,
     54                             HasRetransmittableData is_retransmittable) OVERRIDE;
     55   virtual void OnRetransmissionTimeout() OVERRIDE;
     56   virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
     57                                  QuicByteCount abandoned_bytes) OVERRIDE;
     58   virtual QuicTime::Delta TimeUntilSend(
     59       QuicTime now,
     60       TransmissionType transmission_type,
     61       HasRetransmittableData has_retransmittable_data,
     62       IsHandshake handshake) OVERRIDE;
     63   virtual QuicBandwidth BandwidthEstimate() const OVERRIDE;
     64   virtual QuicTime::Delta SmoothedRtt() const OVERRIDE;
     65   virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE;
     66   virtual QuicByteCount GetCongestionWindow() const OVERRIDE;
     67   // End implementation of SendAlgorithmInterface.
     68 
     69  private:
     70   friend class test::TcpCubicSenderPeer;
     71 
     72   QuicByteCount AvailableSendWindow();
     73   QuicByteCount SendWindow();
     74   void Reset();
     75   void AckAccounting(QuicTime::Delta rtt);
     76   void CongestionAvoidance(QuicPacketSequenceNumber ack);
     77   bool IsCwndLimited() const;
     78   void OnTimeOut();
     79 
     80   HybridSlowStart hybrid_slow_start_;
     81   Cubic cubic_;
     82 
     83   // Reno provided for testing.
     84   const bool reno_;
     85 
     86   // ACK counter for the Reno implementation.
     87   int64 congestion_window_count_;
     88 
     89   // Receiver side advertised window.
     90   QuicByteCount receive_window_;
     91 
     92   // Receiver side advertised packet loss.
     93   int last_received_accumulated_number_of_lost_packets_;
     94 
     95   // Bytes in flight, aka bytes on the wire.
     96   QuicByteCount bytes_in_flight_;
     97 
     98   // We need to keep track of the end sequence number of each RTT "burst".
     99   bool update_end_sequence_number_;
    100   QuicPacketSequenceNumber end_sequence_number_;
    101 
    102   // Track the largest packet that has been sent.
    103   QuicPacketSequenceNumber largest_sent_sequence_number_;
    104 
    105   // Track the largest packet that has been acked.
    106   QuicPacketSequenceNumber largest_acked_sequence_number_;
    107 
    108   // Track the largest sequence number outstanding when a CWND cutback occurs.
    109   QuicPacketSequenceNumber largest_sent_at_last_cutback_;
    110 
    111   // Congestion window in packets.
    112   QuicTcpCongestionWindow congestion_window_;
    113 
    114   // Slow start congestion window in packets.
    115   QuicTcpCongestionWindow slowstart_threshold_;
    116 
    117   // Maximum number of outstanding packets for tcp.
    118   QuicTcpCongestionWindow max_tcp_congestion_window_;
    119 
    120   // Min RTT during this session.
    121   QuicTime::Delta delay_min_;
    122 
    123   // Smoothed RTT during this session.
    124   QuicTime::Delta smoothed_rtt_;
    125 
    126   // Mean RTT deviation during this session.
    127   // Approximation of standard deviation, the error is roughly 1.25 times
    128   // larger than the standard deviation, for a normally distributed signal.
    129   QuicTime::Delta mean_deviation_;
    130 
    131   DISALLOW_COPY_AND_ASSIGN(TcpCubicSender);
    132 };
    133 
    134 }  // namespace net
    135 
    136 #endif  // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_
    137