blob: 5d868b22ffdb412e7cd4ac14a7918b0cdae1bf36 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#include "net/third_party/quiche/src/quic/core/quic_bandwidth.h"
11#include "net/third_party/quiche/src/quic/core/quic_time.h"
12#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
13#include "net/third_party/quiche/src/quic/platform/api/quic_logging.h"
14
15namespace quic {
16
17namespace test {
18class 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.
25class QUIC_EXPORT_PRIVATE 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,
38 bool in_slow_start,
39 QuicBandwidth bandwidth,
40 QuicTime estimate_time,
41 QuicWallTime wall_time,
42 QuicTime::Delta srtt);
43
44 bool HasEstimate() const { return has_estimate_; }
45
46 QuicBandwidth BandwidthEstimate() const {
47 DCHECK(has_estimate_);
48 return bandwidth_estimate_;
49 }
50
51 QuicBandwidth MaxBandwidthEstimate() const {
52 DCHECK(has_estimate_);
53 return max_bandwidth_estimate_;
54 }
55
56 int64_t MaxBandwidthTimestamp() const {
57 DCHECK(has_estimate_);
58 return max_bandwidth_timestamp_;
59 }
60
61 bool EstimateRecordedDuringSlowStart() const {
62 DCHECK(has_estimate_);
63 return bandwidth_estimate_recorded_during_slow_start_;
64 }
65
66 private:
67 friend class test::QuicSustainedBandwidthRecorderPeer;
68
69 // True if we have been able to calculate sustained bandwidth, over at least
70 // one recording period (3 * rtt).
71 bool has_estimate_;
72
73 // True if the last call to RecordEstimate had a reliable estimate.
74 bool is_recording_;
75
76 // True if the current sustained bandwidth estimate was generated while in
77 // slow start.
78 bool bandwidth_estimate_recorded_during_slow_start_;
79
80 // The latest sustained bandwidth estimate.
81 QuicBandwidth bandwidth_estimate_;
82
83 // The maximum sustained bandwidth seen over the lifetime of the connection.
84 QuicBandwidth max_bandwidth_estimate_;
85
86 // Timestamp indicating when the max_bandwidth_estimate_ was seen.
87 int64_t max_bandwidth_timestamp_;
88
89 // Timestamp marking the beginning of the latest recording period.
90 QuicTime start_time_;
91};
92
93} // namespace quic
94
95#endif // QUICHE_QUIC_CORE_QUIC_SUSTAINED_BANDWIDTH_RECORDER_H_