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.
5 #ifndef NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_
6 #define NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_
8 #include "base/logging.h"
9 #include "net/quic/quic_bandwidth.h"
10 #include "net/quic/quic_time.h"
15 class QuicSustainedBandwidthRecorderPeer
;
18 // This class keeps track of a sustained bandwidth estimate to ultimately send
19 // to the client in a server config update message. A sustained bandwidth
20 // estimate is only marked as valid if the QuicSustainedBandwidthRecorder has
21 // been given uninterrupted reliable estimates over a certain period of time.
22 class NET_EXPORT_PRIVATE QuicSustainedBandwidthRecorder
{
24 QuicSustainedBandwidthRecorder();
26 // As long as |in_recovery| is consistently false, multiple calls to this
27 // method over a 3 * srtt period results in storage of a valid sustained
28 // bandwidth estimate.
29 // |time_now| is used as a max bandwidth timestamp if needed.
30 void RecordEstimate(bool in_recovery
,
32 QuicBandwidth bandwidth
,
33 QuicTime estimate_time
,
34 QuicWallTime wall_time
,
35 QuicTime::Delta srtt
);
37 bool HasEstimate() const {
41 QuicBandwidth
BandwidthEstimate() const {
42 DCHECK(has_estimate_
);
43 return bandwidth_estimate_
;
46 QuicBandwidth
MaxBandwidthEstimate() const {
47 DCHECK(has_estimate_
);
48 return max_bandwidth_estimate_
;
51 int64
MaxBandwidthTimestamp() const {
52 DCHECK(has_estimate_
);
53 return max_bandwidth_timestamp_
;
56 bool EstimateRecordedDuringSlowStart() const {
57 DCHECK(has_estimate_
);
58 return bandwidth_estimate_recorded_during_slow_start_
;
62 friend class test::QuicSustainedBandwidthRecorderPeer
;
64 // True if we have been able to calculate sustained bandwidth, over at least
65 // one recording period (3 * rtt).
68 // True if the last call to RecordEstimate had a reliable estimate.
71 // True if the current sustained bandwidth estimate was generated while in
73 bool bandwidth_estimate_recorded_during_slow_start_
;
75 // The latest sustained bandwidth estimate.
76 QuicBandwidth bandwidth_estimate_
;
78 // The maximum sustained bandwidth seen over the lifetime of the connection.
79 QuicBandwidth max_bandwidth_estimate_
;
81 // Timestamp indicating when the max_bandwidth_estimate_ was seen.
82 int64 max_bandwidth_timestamp_
;
84 // Timestamp marking the beginning of the latest recording period.
87 DISALLOW_COPY_AND_ASSIGN(QuicSustainedBandwidthRecorder
);
92 #endif // NET_QUIC_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_