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