Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / congestion_control / cubic.h
blobeffa736264e0a4fe7c47fcbbbd73fb26051b364b
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 // Cubic algorithm, helper class to TCP cubic.
6 // For details see http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf.
8 #ifndef NET_QUIC_CONGESTION_CONTROL_CUBIC_H_
9 #define NET_QUIC_CONGESTION_CONTROL_CUBIC_H_
11 #include "base/basictypes.h"
12 #include "net/base/net_export.h"
13 #include "net/quic/quic_bandwidth.h"
14 #include "net/quic/quic_clock.h"
15 #include "net/quic/quic_connection_stats.h"
16 #include "net/quic/quic_time.h"
18 namespace net {
20 class NET_EXPORT_PRIVATE Cubic {
21 public:
22 explicit Cubic(const QuicClock* clock);
24 void SetNumConnections(int num_connections);
26 // Call after a timeout to reset the cubic state.
27 void Reset();
29 // Compute a new congestion window to use after a loss event.
30 // Returns the new congestion window in packets. The new congestion window is
31 // a multiplicative decrease of our current window.
32 QuicPacketCount CongestionWindowAfterPacketLoss(QuicPacketCount current);
34 // Compute a new congestion window to use after a received ACK.
35 // Returns the new congestion window in packets. The new congestion window
36 // follows a cubic function that depends on the time passed since last
37 // packet loss.
38 QuicPacketCount CongestionWindowAfterAck(QuicPacketCount current,
39 QuicTime::Delta delay_min);
41 // Call on ack arrival when sender is unable to use the available congestion
42 // window. Resets Cubic state during quiescence.
43 void OnApplicationLimited();
45 private:
46 static const QuicTime::Delta MaxCubicTimeInterval() {
47 return QuicTime::Delta::FromMilliseconds(30);
50 // Compute the TCP Cubic alpha and beta based on the current number of
51 // connections.
52 float Alpha() const;
53 float Beta() const;
55 const QuicClock* clock_;
57 // Number of connections to simulate.
58 int num_connections_;
60 // Time when this cycle started, after last loss event.
61 QuicTime epoch_;
63 // Time when we updated last_congestion_window.
64 QuicTime last_update_time_;
66 // Last congestion window (in packets) used.
67 QuicPacketCount last_congestion_window_;
69 // Max congestion window (in packets) used just before last loss event.
70 // Note: to improve fairness to other streams an additional back off is
71 // applied to this value if the new value is below our latest value.
72 QuicPacketCount last_max_congestion_window_;
74 // Number of acked packets since the cycle started (epoch).
75 QuicPacketCount acked_packets_count_;
77 // TCP Reno equivalent congestion window in packets.
78 QuicPacketCount estimated_tcp_congestion_window_;
80 // Origin point of cubic function.
81 QuicPacketCount origin_point_congestion_window_;
83 // Time to origin point of cubic function in 2^10 fractions of a second.
84 uint32 time_to_origin_point_;
86 // Last congestion window in packets computed by cubic function.
87 QuicPacketCount last_target_congestion_window_;
89 DISALLOW_COPY_AND_ASSIGN(Cubic);
92 } // namespace net
94 #endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_H_