blob: 0e174a84af416e74996e9fc99584313a3e9c5e98 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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.
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.
7
8#ifndef QUICHE_QUIC_CORE_CONGESTION_CONTROL_CUBIC_BYTES_H_
9#define QUICHE_QUIC_CORE_CONGESTION_CONTROL_CUBIC_BYTES_H_
10
11#include <cstdint>
12
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include "net/third_party/quiche/src/quic/core/quic_bandwidth.h"
vasilvv89713d02020-02-11 14:33:26 -080014#include "net/third_party/quiche/src/quic/core/quic_clock.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050015#include "net/third_party/quiche/src/quic/core/quic_connection_stats.h"
16#include "net/third_party/quiche/src/quic/core/quic_time.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050017#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
18
19namespace quic {
20
21namespace test {
22class CubicBytesTest;
23} // namespace test
24
25class QUIC_EXPORT_PRIVATE CubicBytes {
26 public:
27 explicit CubicBytes(const QuicClock* clock);
28 CubicBytes(const CubicBytes&) = delete;
29 CubicBytes& operator=(const CubicBytes&) = delete;
30
31 void SetNumConnections(int num_connections);
32
33 // Call after a timeout to reset the cubic state.
34 void ResetCubicState();
35
36 // Compute a new congestion window to use after a loss event.
37 // Returns the new congestion window in packets. The new congestion window is
38 // a multiplicative decrease of our current window.
39 QuicByteCount CongestionWindowAfterPacketLoss(QuicPacketCount current);
40
41 // Compute a new congestion window to use after a received ACK.
42 // Returns the new congestion window in bytes. The new congestion window
43 // follows a cubic function that depends on the time passed since last packet
44 // loss.
45 QuicByteCount CongestionWindowAfterAck(QuicByteCount acked_bytes,
46 QuicByteCount current,
47 QuicTime::Delta delay_min,
48 QuicTime event_time);
49
50 // Call on ack arrival when sender is unable to use the available congestion
51 // window. Resets Cubic state during quiescence.
52 void OnApplicationLimited();
53
54 private:
55 friend class test::CubicBytesTest;
56
57 static const QuicTime::Delta MaxCubicTimeInterval() {
58 return QuicTime::Delta::FromMilliseconds(30);
59 }
60
61 // Compute the TCP Cubic alpha, beta, and beta-last-max based on the
62 // current number of connections.
63 float Alpha() const;
64 float Beta() const;
65 float BetaLastMax() const;
66
67 QuicByteCount last_max_congestion_window() const {
68 return last_max_congestion_window_;
69 }
70
71 const QuicClock* clock_;
72
73 // Number of connections to simulate.
74 int num_connections_;
75
76 // Time when this cycle started, after last loss event.
77 QuicTime epoch_;
78
79 // Max congestion window used just before last loss event.
80 // Note: to improve fairness to other streams an additional back off is
81 // applied to this value if the new value is below our latest value.
82 QuicByteCount last_max_congestion_window_;
83
84 // Number of acked bytes since the cycle started (epoch).
85 QuicByteCount acked_bytes_count_;
86
87 // TCP Reno equivalent congestion window in packets.
88 QuicByteCount estimated_tcp_congestion_window_;
89
90 // Origin point of cubic function.
91 QuicByteCount origin_point_congestion_window_;
92
93 // Time to origin point of cubic function in 2^10 fractions of a second.
94 uint32_t time_to_origin_point_;
95
96 // Last congestion window in packets computed by cubic function.
97 QuicByteCount last_target_congestion_window_;
98};
99
100} // namespace quic
101
102#endif // QUICHE_QUIC_CORE_CONGESTION_CONTROL_CUBIC_BYTES_H_