OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Cubic algorithm, helper class to TCP cubic. | 5 // Cubic algorithm, helper class to TCP cubic. |
6 // For details see http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf. | 6 // For details see http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf. |
7 | 7 |
8 #ifndef NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ | 8 #ifndef NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ |
9 #define NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ | 9 #define NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/quic/quic_bandwidth.h" |
13 #include "net/quic/quic_clock.h" | 14 #include "net/quic/quic_clock.h" |
14 #include "net/quic/quic_connection_stats.h" | 15 #include "net/quic/quic_connection_stats.h" |
15 #include "net/quic/quic_time.h" | 16 #include "net/quic/quic_time.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 // TCP congestion window in QUIC is in packets, not bytes. | |
20 typedef uint32 QuicTcpCongestionWindow; | |
21 | |
22 class NET_EXPORT_PRIVATE Cubic { | 20 class NET_EXPORT_PRIVATE Cubic { |
23 public: | 21 public: |
24 Cubic(const QuicClock* clock, QuicConnectionStats* stats); | 22 Cubic(const QuicClock* clock, QuicConnectionStats* stats); |
25 | 23 |
26 void SetNumConnections(int num_connections); | 24 void SetNumConnections(int num_connections); |
27 | 25 |
28 // Call after a timeout to reset the cubic state. | 26 // Call after a timeout to reset the cubic state. |
29 void Reset(); | 27 void Reset(); |
30 | 28 |
31 // Compute a new congestion window to use after a loss event. | 29 // Compute a new congestion window to use after a loss event. |
32 // Returns the new congestion window in packets. The new congestion window is | 30 // Returns the new congestion window in packets. The new congestion window is |
33 // a multiplicative decrease of our current window. | 31 // a multiplicative decrease of our current window. |
34 QuicTcpCongestionWindow CongestionWindowAfterPacketLoss( | 32 QuicPacketCount CongestionWindowAfterPacketLoss(QuicPacketCount current); |
35 QuicTcpCongestionWindow current); | |
36 | 33 |
37 // Compute a new congestion window to use after a received ACK. | 34 // Compute a new congestion window to use after a received ACK. |
38 // Returns the new congestion window in packets. The new congestion window | 35 // Returns the new congestion window in packets. The new congestion window |
39 // follows a cubic function that depends on the time passed since last | 36 // follows a cubic function that depends on the time passed since last |
40 // packet loss. | 37 // packet loss. |
41 QuicTcpCongestionWindow CongestionWindowAfterAck( | 38 QuicPacketCount CongestionWindowAfterAck(QuicPacketCount current, |
42 QuicTcpCongestionWindow current, | 39 QuicTime::Delta delay_min); |
43 QuicTime::Delta delay_min); | |
44 | 40 |
45 private: | 41 private: |
46 static const QuicTime::Delta MaxCubicTimeInterval() { | 42 static const QuicTime::Delta MaxCubicTimeInterval() { |
47 return QuicTime::Delta::FromMilliseconds(30); | 43 return QuicTime::Delta::FromMilliseconds(30); |
48 } | 44 } |
49 | 45 |
50 // Compute the TCP Cubic alpha and beta based on the current number of | 46 // Compute the TCP Cubic alpha and beta based on the current number of |
51 // connections. | 47 // connections. |
52 float Alpha() const; | 48 float Alpha() const; |
53 float Beta() const; | 49 float Beta() const; |
54 | 50 |
55 // Update congestion control variables in QuicConnectionStats. | 51 // Update congestion control variables in QuicConnectionStats. |
56 void UpdateCongestionControlStats(QuicTcpCongestionWindow new_cubic_mode_cwnd, | 52 void UpdateCongestionControlStats(QuicPacketCount new_cubic_mode_cwnd, |
57 QuicTcpCongestionWindow new_reno_mode_cwnd); | 53 QuicPacketCount new_reno_mode_cwnd); |
58 const QuicClock* clock_; | 54 const QuicClock* clock_; |
59 | 55 |
60 // Number of connections to simulate. | 56 // Number of connections to simulate. |
61 int num_connections_; | 57 int num_connections_; |
62 | 58 |
63 // Time when this cycle started, after last loss event. | 59 // Time when this cycle started, after last loss event. |
64 QuicTime epoch_; | 60 QuicTime epoch_; |
65 | 61 |
66 // Time when we updated last_congestion_window. | 62 // Time when we updated last_congestion_window. |
67 QuicTime last_update_time_; | 63 QuicTime last_update_time_; |
68 | 64 |
69 // Last congestion window (in packets) used. | 65 // Last congestion window (in packets) used. |
70 QuicTcpCongestionWindow last_congestion_window_; | 66 QuicPacketCount last_congestion_window_; |
71 | 67 |
72 // Max congestion window (in packets) used just before last loss event. | 68 // Max congestion window (in packets) used just before last loss event. |
73 // Note: to improve fairness to other streams an additional back off is | 69 // Note: to improve fairness to other streams an additional back off is |
74 // applied to this value if the new value is below our latest value. | 70 // applied to this value if the new value is below our latest value. |
75 QuicTcpCongestionWindow last_max_congestion_window_; | 71 QuicPacketCount last_max_congestion_window_; |
76 | 72 |
77 // Number of acked packets since the cycle started (epoch). | 73 // Number of acked packets since the cycle started (epoch). |
78 uint32 acked_packets_count_; | 74 uint32 acked_packets_count_; |
79 | 75 |
80 // TCP Reno equivalent congestion window in packets. | 76 // TCP Reno equivalent congestion window in packets. |
81 QuicTcpCongestionWindow estimated_tcp_congestion_window_; | 77 QuicPacketCount estimated_tcp_congestion_window_; |
82 | 78 |
83 // Origin point of cubic function. | 79 // Origin point of cubic function. |
84 QuicTcpCongestionWindow origin_point_congestion_window_; | 80 QuicPacketCount origin_point_congestion_window_; |
85 | 81 |
86 // Time to origin point of cubic function in 2^10 fractions of a second. | 82 // Time to origin point of cubic function in 2^10 fractions of a second. |
87 uint32 time_to_origin_point_; | 83 uint32 time_to_origin_point_; |
88 | 84 |
89 // Last congestion window in packets computed by cubic function. | 85 // Last congestion window in packets computed by cubic function. |
90 QuicTcpCongestionWindow last_target_congestion_window_; | 86 QuicPacketCount last_target_congestion_window_; |
91 | 87 |
92 // QuicConnectionStats includes congestion control related stats. | 88 // QuicConnectionStats includes congestion control related stats. |
93 QuicConnectionStats* stats_; | 89 QuicConnectionStats* stats_; |
94 | 90 |
95 DISALLOW_COPY_AND_ASSIGN(Cubic); | 91 DISALLOW_COPY_AND_ASSIGN(Cubic); |
96 }; | 92 }; |
97 | 93 |
98 } // namespace net | 94 } // namespace net |
99 | 95 |
100 #endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ | 96 #endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ |
OLD | NEW |