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 // This does not implement ack train detection because it interacts poorly with
12 // pacing.
13 // http://netsrv.csc.ncsu.edu/export/hybridstart_pfldnet08.pdf
14 // http://research.csc.ncsu.edu/netsrv/sites/default/files/hystart_techreport_2008.pdf
15 
16 #ifndef QUICHE_QUIC_CORE_CONGESTION_CONTROL_HYBRID_SLOW_START_H_
17 #define QUICHE_QUIC_CORE_CONGESTION_CONTROL_HYBRID_SLOW_START_H_
18 
19 #include <cstdint>
20 
21 #include "quiche/quic/core/quic_packets.h"
22 #include "quiche/quic/core/quic_time.h"
23 #include "quiche/quic/platform/api/quic_export.h"
24 
25 namespace quic {
26 
27 class QUICHE_EXPORT HybridSlowStart {
28  public:
29   HybridSlowStart();
30   HybridSlowStart(const HybridSlowStart&) = delete;
31   HybridSlowStart& operator=(const HybridSlowStart&) = delete;
32 
33   void OnPacketAcked(QuicPacketNumber acked_packet_number);
34 
35   void OnPacketSent(QuicPacketNumber packet_number);
36 
37   // ShouldExitSlowStart should be called on every new ack frame, since a new
38   // RTT measurement can be made then.
39   // rtt: the RTT for this ack packet.
40   // min_rtt: is the lowest delay (RTT) we have seen during the session.
41   // congestion_window: the congestion window in packets.
42   bool ShouldExitSlowStart(QuicTime::Delta rtt, QuicTime::Delta min_rtt,
43                            QuicPacketCount congestion_window);
44 
45   // Start a new slow start phase.
46   void Restart();
47 
48   // TODO(ianswett): The following methods should be private, but that requires
49   // a follow up CL to update the unit test.
50   // Returns true if this ack the last packet number of our current slow start
51   // round.
52   // Call Reset if this returns true.
53   bool IsEndOfRound(QuicPacketNumber ack) const;
54 
55   // Call for the start of each receive round (burst) in the slow start phase.
56   void StartReceiveRound(QuicPacketNumber last_sent);
57 
58   // Whether slow start has started.
started()59   bool started() const { return started_; }
60 
61  private:
62   // Whether a condition for exiting slow start has been found.
63   enum HystartState {
64     NOT_FOUND,
65     DELAY,  // Too much increase in the round's min_rtt was observed.
66   };
67 
68   // Whether the hybrid slow start has been started.
69   bool started_;
70   HystartState hystart_found_;
71   // Last packet number sent which was CWND limited.
72   QuicPacketNumber last_sent_packet_number_;
73 
74   // Variables for tracking acks received during a slow start round.
75   QuicPacketNumber end_packet_number_;  // End of the receive round.
76   uint32_t rtt_sample_count_;  // Number of rtt samples in the current round.
77   QuicTime::Delta current_min_rtt_;  // The minimum rtt of current round.
78 };
79 
80 }  // namespace quic
81 
82 #endif  // QUICHE_QUIC_CORE_CONGESTION_CONTROL_HYBRID_SLOW_START_H_
83