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 // This class is a helper class to TcpCubicSender.
      6 // Slow start is the initial startup phase of TCP, it lasts until first packet
      7 // loss. This class implements hybrid slow start of the TCP cubic send side
      8 // congestion algorithm. The key feaure of hybrid slow start is that it tries to
      9 // avoid running into the wall too hard during the slow start phase, which
     10 // the traditional TCP implementation does.
     11 // http://netsrv.csc.ncsu.edu/export/hybridstart_pfldnet08.pdf
     12 // http://research.csc.ncsu.edu/netsrv/sites/default/files/hystart_techreport_2008.pdf
     13 
     14 #ifndef NET_QUIC_CONGESTION_CONTROL_HYBRID_SLOW_START_H_
     15 #define NET_QUIC_CONGESTION_CONTROL_HYBRID_SLOW_START_H_
     16 
     17 #include "base/basictypes.h"
     18 #include "net/base/net_export.h"
     19 #include "net/quic/quic_clock.h"
     20 #include "net/quic/quic_protocol.h"
     21 #include "net/quic/quic_time.h"
     22 
     23 namespace net {
     24 
     25 class NET_EXPORT_PRIVATE HybridSlowStart {
     26  public:
     27   explicit HybridSlowStart(const QuicClock* clock);
     28 
     29   void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
     30                      bool in_slow_start);
     31 
     32   void OnPacketSent(QuicPacketSequenceNumber sequence_number);
     33 
     34   // ShouldExitSlowStart should be called on every new ack frame, since a new
     35   // RTT measurement can be made then.
     36   // rtt: the RTT for this ack packet.
     37   // min_rtt: is the lowest delay (RTT) we have seen during the session.
     38   // congestion_window: the congestion window in packets.
     39   bool ShouldExitSlowStart(QuicTime::Delta rtt,
     40                            QuicTime::Delta min_rtt,
     41                            int64 congestion_window);
     42 
     43   // Start a new slow start phase.
     44   void Restart();
     45 
     46   // TODO(ianswett): The following methods should be private, but that requires
     47   // a follow up CL to update the unit test.
     48   // Returns true if this ack the last sequence number of our current slow start
     49   // round.
     50   // Call Reset if this returns true.
     51   bool IsEndOfRound(QuicPacketSequenceNumber ack) const;
     52 
     53   // Call for the start of each receive round (burst) in the slow start phase.
     54   void StartReceiveRound(QuicPacketSequenceNumber last_sent);
     55 
     56   // Whether slow start has started.
     57   bool started() const {
     58     return started_;
     59   }
     60 
     61  private:
     62   // Whether a condition for exiting slow start has been found.
     63   enum HystartState {
     64     NOT_FOUND,
     65     ACK_TRAIN,  // A closely spaced ack train is too long.
     66     DELAY,  // Too much increase in the round's min_rtt was observed.
     67   };
     68 
     69   const QuicClock* clock_;
     70   // Whether the hybrid slow start has been started.
     71   bool started_;
     72   HystartState hystart_found_;
     73   // Last sequence number sent which was CWND limited.
     74   QuicPacketSequenceNumber last_sent_sequence_number_;
     75 
     76   // Variables for tracking acks received during a slow start round.
     77   QuicTime round_start_;  // Beginning of each slow start receive round.
     78   QuicPacketSequenceNumber end_sequence_number_;  // End of the receive round.
     79   // Last time when the spacing between ack arrivals was less than 2 ms.
     80   // Defaults to the beginning of the round.
     81   QuicTime last_close_ack_pair_time_;
     82   uint32 rtt_sample_count_;  // Number of rtt samples in the current round.
     83   QuicTime::Delta current_min_rtt_;  // The minimum rtt of current round.
     84 
     85   DISALLOW_COPY_AND_ASSIGN(HybridSlowStart);
     86 };
     87 
     88 }  // namespace net
     89 
     90 #endif  // NET_QUIC_CONGESTION_CONTROL_HYBRID_SLOW_START_H_
     91