-
Notifications
You must be signed in to change notification settings - Fork 1
/
pcc_monitor_interval_queue.h
138 lines (115 loc) · 5.28 KB
/
pcc_monitor_interval_queue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef THIRD_PARTY_PCC_QUIC_PCC_MONITOR_QUEUE_H_
#define THIRD_PARTY_PCC_QUIC_PCC_MONITOR_QUEUE_H_
#include <deque>
#include <utility>
#include <vector>
#include "third_party/quic/core/congestion_control/send_algorithm_interface.h"
#include "third_party/quic/core/quic_time.h"
#include "third_party/quic/core/quic_types.h"
namespace quic {
// MonitorInterval, as the queue's entry struct, stores the information
// of a PCC monitor interval (MonitorInterval) that can be used to
// - pinpoint a acked/lost packet to the corresponding MonitorInterval,
// - calculate the MonitorInterval's utility value.
struct MonitorInterval {
MonitorInterval();
MonitorInterval(QuicBandwidth sending_rate,
bool is_useful,
float rtt_fluctuation_tolerance_ratio,
QuicTime::Delta rtt);
~MonitorInterval() {}
// Sending rate.
QuicBandwidth sending_rate;
// True if calculating utility for this MonitorInterval.
bool is_useful;
// The tolerable rtt fluctuation ratio.
float rtt_fluctuation_tolerance_ratio;
// Sent time of the first packet.
QuicTime first_packet_sent_time;
// Sent time of the last packet.
QuicTime last_packet_sent_time;
// PacketNumber of the first sent packet.
QuicPacketNumber first_packet_number;
// PacketNumber of the last sent packet.
QuicPacketNumber last_packet_number;
// Number of bytes which are sent in total.
QuicByteCount bytes_sent;
// Number of bytes which have been acked.
QuicByteCount bytes_acked;
// Number of bytes which are considered as lost.
QuicByteCount bytes_lost;
// Smoothed RTT when the first packet is sent.
QuicTime::Delta rtt_on_monitor_start;
// RTT when all sent packets are either acked or lost.
QuicTime::Delta rtt_on_monitor_end;
};
// A delegate interface for further processing when all
// 'useful' MonitorIntervals' utilities are available.
class QUIC_EXPORT_PRIVATE PccMonitorIntervalQueueDelegateInterface {
public:
virtual ~PccMonitorIntervalQueueDelegateInterface() {}
virtual void OnUtilityAvailable(
const std::vector<const MonitorInterval *>& useful_intervals) = 0;
};
// PccMonitorIntervalQueue contains a queue of MonitorIntervals.
// New MonitorIntervals are added to the tail of the queue.
// Existing MonitorIntervals are removed from the queue when all
// 'useful' intervals' utilities are available.
class PccMonitorIntervalQueue {
public:
explicit PccMonitorIntervalQueue(
PccMonitorIntervalQueueDelegateInterface* delegate);
PccMonitorIntervalQueue(const PccMonitorIntervalQueue&) = delete;
PccMonitorIntervalQueue& operator=(const PccMonitorIntervalQueue&) = delete;
PccMonitorIntervalQueue(PccMonitorIntervalQueue&&) = delete;
PccMonitorIntervalQueue& operator=(PccMonitorIntervalQueue&&) = delete;
~PccMonitorIntervalQueue() {}
// Creates a new MonitorInterval and add it to the tail of the
// monitor interval queue, provided the necessary variables
// for MonitorInterval initialization.
void EnqueueNewMonitorInterval(QuicBandwidth sending_rate,
bool is_useful,
float rtt_fluctuation_tolerance_ratio,
QuicTime::Delta rtt);
// Called when a packet belonging to current monitor interval is sent.
void OnPacketSent(QuicTime sent_time,
QuicPacketNumber packet_number,
QuicByteCount bytes);
// Called when packets are acked or considered as lost.
void OnCongestionEvent(const AckedPacketVector& acked_packets,
const LostPacketVector& lost_packets,
QuicTime::Delta rtt);
// Called when RTT inflation ratio is greater than
// max_rtt_fluctuation_tolerance_ratio_in_starting.
void OnRttInflationInStarting();
// Returns the fisrt MonitorInterval in the front of the queue. The caller
// needs to make sure the queue is not empty before calling this function.
const MonitorInterval& front() const;
// Returns the most recent MonitorInterval in the tail of the queue. The
// caller needs to make sure the queue is not empty before calling this
// function.
const MonitorInterval& current() const;
size_t num_useful_intervals() const { return num_useful_intervals_; }
size_t num_available_intervals() const { return num_available_intervals_; }
bool empty() const;
size_t size() const;
private:
// Returns true if the utility of |interval| is available, i.e.,
// when all the interval's packets are either acked or lost.
bool IsUtilityAvailable(const MonitorInterval& interval) const;
// Retruns true if |packet_number| belongs to |interval|.
bool IntervalContainsPacket(const MonitorInterval& interval,
QuicPacketNumber packet_number) const;
// Returns true if the utility of |interval| is invalid, i.e., if it only
// contains a single sent packet.
bool HasInvalidUtility(const MonitorInterval* interval) const;
std::deque<MonitorInterval> monitor_intervals_;
// Number of useful intervals in the queue.
size_t num_useful_intervals_;
// Number of useful intervals in the queue with available utilities.
size_t num_available_intervals_;
// Delegate interface, not owned.
PccMonitorIntervalQueueDelegateInterface* delegate_;
};
} // namespace quic
#endif // THIRD_PARTY_PCC_QUIC_PCC_MONITOR_QUEUE_H_