1 // Copyright (c) 2015 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.
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_BYTES_H_
9 #define NET_QUIC_CONGESTION_CONTROL_CUBIC_BYTES_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"
20 class NET_EXPORT_PRIVATE CubicBytes
{
22 explicit CubicBytes(const QuicClock
* clock
);
24 void SetNumConnections(int num_connections
);
26 // Call after a timeout to reset the cubic state.
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 QuicByteCount
CongestionWindowAfterPacketLoss(QuicPacketCount current
);
34 // Compute a new congestion window to use after a received ACK.
35 // Returns the new congestion window in bytes. The new congestion window
36 // follows a cubic function that depends on the time passed since last packet
38 QuicByteCount
CongestionWindowAfterAck(QuicByteCount acked_bytes
,
39 QuicByteCount current
,
40 QuicTime::Delta delay_min
);
42 // Call on ack arrival when sender is unable to use the available congestion
43 // window. Resets Cubic state during quiescence.
44 void OnApplicationLimited();
47 static const QuicTime::Delta
MaxCubicTimeInterval() {
48 return QuicTime::Delta::FromMilliseconds(30);
51 // Compute the TCP Cubic alpha and beta based on the current number of
56 const QuicClock
* clock_
;
58 // Number of connections to simulate.
61 // Time when this cycle started, after last loss event.
64 // Time when we updated last_congestion_window.
65 QuicTime last_update_time_
;
67 // Last congestion window used.
68 QuicByteCount last_congestion_window_
;
70 // Max congestion window used just before last loss event.
71 // Note: to improve fairness to other streams an additional back off is
72 // applied to this value if the new value is below our latest value.
73 QuicByteCount last_max_congestion_window_
;
75 // Number of acked bytes since the cycle started (epoch).
76 QuicByteCount acked_bytes_count_
;
78 // TCP Reno equivalent congestion window in packets.
79 QuicByteCount estimated_tcp_congestion_window_
;
81 // Origin point of cubic function.
82 QuicByteCount origin_point_congestion_window_
;
84 // Time to origin point of cubic function in 2^10 fractions of a second.
85 uint32 time_to_origin_point_
;
87 // Last congestion window in packets computed by cubic function.
88 QuicByteCount last_target_congestion_window_
;
90 DISALLOW_COPY_AND_ASSIGN(CubicBytes
);
95 #endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_BYTES_H_