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