| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_BYTES_H_ |
| 9 #define NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ | 9 #define NET_QUIC_CONGESTION_CONTROL_CUBIC_BYTES_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_bandwidth.h" |
| 14 #include "net/quic/quic_clock.h" | 14 #include "net/quic/quic_clock.h" |
| 15 #include "net/quic/quic_connection_stats.h" | 15 #include "net/quic/quic_connection_stats.h" |
| 16 #include "net/quic/quic_time.h" | 16 #include "net/quic/quic_time.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class NET_EXPORT_PRIVATE Cubic { | 20 class NET_EXPORT_PRIVATE CubicBytes { |
| 21 public: | 21 public: |
| 22 explicit Cubic(const QuicClock* clock); | 22 explicit CubicBytes(const QuicClock* clock); |
| 23 | 23 |
| 24 void SetNumConnections(int num_connections); | 24 void SetNumConnections(int num_connections); |
| 25 | 25 |
| 26 // Call after a timeout to reset the cubic state. | 26 // Call after a timeout to reset the cubic state. |
| 27 void Reset(); | 27 void Reset(); |
| 28 | 28 |
| 29 // Compute a new congestion window to use after a loss event. | 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 | 30 // Returns the new congestion window in packets. The new congestion window is |
| 31 // a multiplicative decrease of our current window. | 31 // a multiplicative decrease of our current window. |
| 32 QuicPacketCount CongestionWindowAfterPacketLoss(QuicPacketCount current); | 32 QuicByteCount CongestionWindowAfterPacketLoss(QuicPacketCount current); |
| 33 | 33 |
| 34 // Compute a new congestion window to use after a received ACK. | 34 // Compute a new congestion window to use after a received ACK. |
| 35 // Returns the new congestion window in packets. The new congestion window | 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 | 36 // follows a cubic function that depends on the time passed since last packet |
| 37 // packet loss. | 37 // loss. |
| 38 QuicPacketCount CongestionWindowAfterAck(QuicPacketCount current, | 38 QuicByteCount CongestionWindowAfterAck(QuicByteCount acked_bytes, |
| 39 QuicTime::Delta delay_min); | 39 QuicByteCount current, |
| 40 QuicTime::Delta delay_min); |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 static const QuicTime::Delta MaxCubicTimeInterval() { | 43 static const QuicTime::Delta MaxCubicTimeInterval() { |
| 43 return QuicTime::Delta::FromMilliseconds(30); | 44 return QuicTime::Delta::FromMilliseconds(30); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Compute the TCP Cubic alpha and beta based on the current number of | 47 // Compute the TCP Cubic alpha and beta based on the current number of |
| 47 // connections. | 48 // connections. |
| 48 float Alpha() const; | 49 float Alpha() const; |
| 49 float Beta() const; | 50 float Beta() const; |
| 50 | 51 |
| 51 const QuicClock* clock_; | 52 const QuicClock* clock_; |
| 52 | 53 |
| 53 // Number of connections to simulate. | 54 // Number of connections to simulate. |
| 54 int num_connections_; | 55 int num_connections_; |
| 55 | 56 |
| 56 // Time when this cycle started, after last loss event. | 57 // Time when this cycle started, after last loss event. |
| 57 QuicTime epoch_; | 58 QuicTime epoch_; |
| 58 | 59 |
| 59 // Time when we updated last_congestion_window. | 60 // Time when we updated last_congestion_window. |
| 60 QuicTime last_update_time_; | 61 QuicTime last_update_time_; |
| 61 | 62 |
| 62 // Last congestion window (in packets) used. | 63 // Last congestion window used. |
| 63 QuicPacketCount last_congestion_window_; | 64 QuicByteCount last_congestion_window_; |
| 64 | 65 |
| 65 // Max congestion window (in packets) used just before last loss event. | 66 // Max congestion window used just before last loss event. |
| 66 // Note: to improve fairness to other streams an additional back off is | 67 // Note: to improve fairness to other streams an additional back off is |
| 67 // applied to this value if the new value is below our latest value. | 68 // applied to this value if the new value is below our latest value. |
| 68 QuicPacketCount last_max_congestion_window_; | 69 QuicByteCount last_max_congestion_window_; |
| 69 | 70 |
| 70 // Number of acked packets since the cycle started (epoch). | 71 // Number of acked bytes since the cycle started (epoch). |
| 71 QuicPacketCount acked_packets_count_; | 72 QuicByteCount acked_bytes_count_; |
| 72 | 73 |
| 73 // TCP Reno equivalent congestion window in packets. | 74 // TCP Reno equivalent congestion window in packets. |
| 74 QuicPacketCount estimated_tcp_congestion_window_; | 75 QuicByteCount estimated_tcp_congestion_window_; |
| 75 | 76 |
| 76 // Origin point of cubic function. | 77 // Origin point of cubic function. |
| 77 QuicPacketCount origin_point_congestion_window_; | 78 QuicByteCount origin_point_congestion_window_; |
| 78 | 79 |
| 79 // Time to origin point of cubic function in 2^10 fractions of a second. | 80 // Time to origin point of cubic function in 2^10 fractions of a second. |
| 80 uint32 time_to_origin_point_; | 81 uint32 time_to_origin_point_; |
| 81 | 82 |
| 82 // Last congestion window in packets computed by cubic function. | 83 // Last congestion window in packets computed by cubic function. |
| 83 QuicPacketCount last_target_congestion_window_; | 84 QuicByteCount last_target_congestion_window_; |
| 84 | 85 |
| 85 DISALLOW_COPY_AND_ASSIGN(Cubic); | 86 DISALLOW_COPY_AND_ASSIGN(CubicBytes); |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 } // namespace net | 89 } // namespace net |
| 89 | 90 |
| 90 #endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_H_ | 91 #endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_BYTES_H_ |
| OLD | NEW |