OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 #ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ | 5 #ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
6 #define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ | 6 #define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/quic/quic_bandwidth.h" | 9 #include "net/quic/quic_bandwidth.h" |
10 #include "net/quic/quic_time.h" | 10 #include "net/quic/quic_time.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 // This class keeps track of a sustained bandwidth estimate to ultimately send | 14 // This class keeps track of a sustained bandwidth estimate to ultimately send |
15 // to the client in a server config update message. A sustained bandwidth | 15 // to the client in a server config update message. A sustained bandwidth |
16 // estimate is only marked as valid if the QuicSustainedBandwidthRecorder has | 16 // estimate is only marked as valid if the QuicSustainedBandwidthRecorder has |
17 // been given uninterrupted reliable estimates over a certain period of time. | 17 // been given uninterrupted reliable estimates over a certain period of time. |
18 class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder { | 18 class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder { |
19 public: | 19 public: |
20 QuicSustainedBandwidthRecorder(); | 20 QuicSustainedBandwidthRecorder(); |
21 | 21 |
22 // As long as |is_reliable_estimate| is consistently true, multiple calls to | 22 // As long as |is_reliable_estimate| is consistently true, multiple calls to |
23 // this method over a 3 * srtt period results in storage of a valid sustained | 23 // this method over a 3 * srtt period results in storage of a valid sustained |
24 // bandwidth estimate. | 24 // bandwidth estimate. |
25 // |time_now| is used as a max bandwidth timestamp if needed. | 25 // |time_now| is used as a max bandwidth timestamp if needed. |
26 void RecordEstimate(bool is_reliable_estimate, | 26 void RecordEstimate(bool is_reliable_estimate, |
| 27 bool in_slow_start, |
27 QuicBandwidth bandwidth, | 28 QuicBandwidth bandwidth, |
28 QuicTime estimate_time, | 29 QuicTime estimate_time, |
29 QuicWallTime wall_time, | 30 QuicWallTime wall_time, |
30 QuicTime::Delta srtt); | 31 QuicTime::Delta srtt); |
31 | 32 |
32 bool HasEstimate() const { | 33 bool HasEstimate() const { |
33 return has_estimate_; | 34 return has_estimate_; |
34 } | 35 } |
35 | 36 |
36 QuicBandwidth BandwidthEstimate() const { | 37 QuicBandwidth BandwidthEstimate() const { |
37 DCHECK(has_estimate_); | 38 DCHECK(has_estimate_); |
38 return bandwidth_estimate_; | 39 return bandwidth_estimate_; |
39 } | 40 } |
40 | 41 |
41 QuicBandwidth MaxBandwidthEstimate() const { | 42 QuicBandwidth MaxBandwidthEstimate() const { |
42 DCHECK(has_estimate_); | 43 DCHECK(has_estimate_); |
43 return max_bandwidth_estimate_; | 44 return max_bandwidth_estimate_; |
44 } | 45 } |
45 | 46 |
46 int32 MaxBandwidthTimestamp() const { | 47 int32 MaxBandwidthTimestamp() const { |
47 DCHECK(has_estimate_); | 48 DCHECK(has_estimate_); |
48 return max_bandwidth_timestamp_; | 49 return max_bandwidth_timestamp_; |
49 } | 50 } |
50 | 51 |
| 52 bool EstimateRecordedDuringSlowStart() const { |
| 53 DCHECK(has_estimate_); |
| 54 return bandwidth_estimate_recorded_during_slow_start_; |
| 55 } |
| 56 |
51 private: | 57 private: |
52 // True if we have been able to calculate sustained bandwidth, over at least | 58 // True if we have been able to calculate sustained bandwidth, over at least |
53 // one recording period (3 * rtt). | 59 // one recording period (3 * rtt). |
54 bool has_estimate_; | 60 bool has_estimate_; |
55 | 61 |
56 // True if the last call to RecordEstimate had a reliable estimate. | 62 // True if the last call to RecordEstimate had a reliable estimate. |
57 bool is_recording_; | 63 bool is_recording_; |
58 | 64 |
| 65 // True if the current sustained bandwidth estimate was generated while in |
| 66 // slow start. |
| 67 bool bandwidth_estimate_recorded_during_slow_start_; |
| 68 |
59 // The latest sustained bandwidth estimate. | 69 // The latest sustained bandwidth estimate. |
60 QuicBandwidth bandwidth_estimate_; | 70 QuicBandwidth bandwidth_estimate_; |
61 | 71 |
62 // The maximum sustained bandwidth seen over the lifetime of the connection. | 72 // The maximum sustained bandwidth seen over the lifetime of the connection. |
63 QuicBandwidth max_bandwidth_estimate_; | 73 QuicBandwidth max_bandwidth_estimate_; |
64 | 74 |
65 // Timestamp indicating when the max_bandwidth_estimate_ was seen. | 75 // Timestamp indicating when the max_bandwidth_estimate_ was seen. |
66 int32 max_bandwidth_timestamp_; | 76 int32 max_bandwidth_timestamp_; |
67 | 77 |
68 // Timestamp marking the beginning of the latest recording period. | 78 // Timestamp marking the beginning of the latest recording period. |
69 QuicTime start_time_; | 79 QuicTime start_time_; |
70 | 80 |
71 DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder); | 81 DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder); |
72 }; | 82 }; |
73 | 83 |
74 } // namespace net | 84 } // namespace net |
75 | 85 |
76 #endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ | 86 #endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_ |
OLD | NEW |