OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // A send algorithm that adds pacing on top of an another send algorithm. | 5 // A send algorithm that adds pacing on top of an another send algorithm. |
6 // It uses the underlying sender's pacing rate to schedule packets. | 6 // It uses the underlying sender's pacing rate to schedule packets. |
7 // It also takes into consideration the expected granularity of the underlying | 7 // It also takes into consideration the expected granularity of the underlying |
8 // alarm to ensure that alarms are not set too aggressively, and err towards | 8 // alarm to ensure that alarms are not set too aggressively, and err towards |
9 // sending packets too early instead of too late. | 9 // sending packets too early instead of too late. |
10 | 10 |
11 #ifndef NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ | 11 #ifndef NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ |
12 #define NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ | 12 #define NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ |
13 | 13 |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 | 15 |
16 #include <map> | 16 #include <map> |
17 #include <memory> | 17 #include <memory> |
18 | 18 |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "net/quic/core/congestion_control/send_algorithm_interface.h" | 20 #include "net/quic/core/congestion_control/send_algorithm_interface.h" |
21 #include "net/quic/core/quic_bandwidth.h" | 21 #include "net/quic/core/quic_bandwidth.h" |
22 #include "net/quic/core/quic_config.h" | 22 #include "net/quic/core/quic_config.h" |
23 #include "net/quic/core/quic_protocol.h" | 23 #include "net/quic/core/quic_protocol.h" |
24 #include "net/quic/core/quic_time.h" | 24 #include "net/quic/core/quic_time.h" |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 | 27 |
28 class NET_EXPORT_PRIVATE PacingSender : public SendAlgorithmInterface { | 28 class NET_EXPORT_PRIVATE PacingSender { |
29 public: | 29 public: |
30 // Create a PacingSender to wrap the specified sender. |alarm_granularity| | 30 PacingSender(); |
31 // indicates to the pacer to send that far into the future, since it should | 31 ~PacingSender(); |
32 // not expect a callback before that time delta. |initial_packet_burst| is | |
33 // the number of packets sent without pacing after quiescence. | |
34 PacingSender(SendAlgorithmInterface* sender, | |
35 QuicTime::Delta alarm_granularity, | |
36 uint32_t initial_packet_burst); | |
37 ~PacingSender() override; | |
38 | 32 |
39 void SetMaxPacingRate(QuicBandwidth max_pacing_rate); | 33 // Sets the underlying sender. Does not take ownership of |sender|. |sender| |
| 34 // must not be null. This must be called before any of the |
| 35 // SendAlgorithmInterface wrapper methods are called. |
| 36 void set_sender(SendAlgorithmInterface* sender); |
40 | 37 |
41 // SendAlgorithmInterface methods. | 38 void set_max_pacing_rate(QuicBandwidth max_pacing_rate) { |
42 void SetFromConfig(const QuicConfig& config, | 39 max_pacing_rate_ = max_pacing_rate; |
43 Perspective perspective) override; | 40 } |
44 void ResumeConnectionState( | 41 |
45 const CachedNetworkParameters& cached_network_params, | 42 void OnCongestionEvent( |
46 bool max_bandwidth_resumption) override; | 43 bool rtt_updated, |
47 void SetNumEmulatedConnections(int num_connections) override; | 44 QuicByteCount bytes_in_flight, |
48 void OnCongestionEvent(bool rtt_updated, | 45 const SendAlgorithmInterface::CongestionVector& acked_packets, |
49 QuicByteCount bytes_in_flight, | 46 const SendAlgorithmInterface::CongestionVector& lost_packets); |
50 const CongestionVector& acked_packets, | |
51 const CongestionVector& lost_packets) override; | |
52 bool OnPacketSent(QuicTime sent_time, | 47 bool OnPacketSent(QuicTime sent_time, |
53 QuicByteCount bytes_in_flight, | 48 QuicByteCount bytes_in_flight, |
54 QuicPacketNumber packet_number, | 49 QuicPacketNumber packet_number, |
55 QuicByteCount bytes, | 50 QuicByteCount bytes, |
56 HasRetransmittableData is_retransmittable) override; | 51 HasRetransmittableData is_retransmittable); |
57 void OnRetransmissionTimeout(bool packets_retransmitted) override; | |
58 void OnConnectionMigration() override; | |
59 QuicTime::Delta TimeUntilSend(QuicTime now, | 52 QuicTime::Delta TimeUntilSend(QuicTime now, |
60 QuicByteCount bytes_in_flight) const override; | 53 QuicByteCount bytes_in_flight) const; |
61 QuicBandwidth PacingRate(QuicByteCount bytes_in_flight) const override; | 54 QuicBandwidth PacingRate(QuicByteCount bytes_in_flight) const; |
62 QuicBandwidth BandwidthEstimate() const override; | |
63 QuicTime::Delta RetransmissionDelay() const override; | |
64 QuicByteCount GetCongestionWindow() const override; | |
65 bool InSlowStart() const override; | |
66 bool InRecovery() const override; | |
67 QuicByteCount GetSlowStartThreshold() const override; | |
68 CongestionControlType GetCongestionControlType() const override; | |
69 std::string GetDebugState() const override; | |
70 void OnApplicationLimited(QuicByteCount bytes_in_flight) override; | |
71 // End implementation of SendAlgorithmInterface. | |
72 | 55 |
73 private: | 56 private: |
74 std::unique_ptr<SendAlgorithmInterface> sender_; // Underlying sender. | 57 // Underlying sender. Not owned. |
75 // The estimated system alarm granularity. | 58 SendAlgorithmInterface* sender_; |
76 const QuicTime::Delta alarm_granularity_; | |
77 // Configured maximum size of the burst coming out of quiescence. The burst | |
78 // is never larger than the current CWND in packets. | |
79 const uint32_t initial_packet_burst_; | |
80 // If not QuicBandidth::Zero, the maximum rate the PacingSender will use. | 59 // If not QuicBandidth::Zero, the maximum rate the PacingSender will use. |
81 QuicBandwidth max_pacing_rate_; | 60 QuicBandwidth max_pacing_rate_; |
82 | 61 |
83 // Number of unpaced packets to be sent before packets are delayed. | 62 // Number of unpaced packets to be sent before packets are delayed. |
84 uint32_t burst_tokens_; | 63 uint32_t burst_tokens_; |
85 // Send time of the last packet considered delayed. | 64 // Send time of the last packet considered delayed. |
86 QuicTime last_delayed_packet_sent_time_; | 65 QuicTime last_delayed_packet_sent_time_; |
87 QuicTime ideal_next_packet_send_time_; // When can the next packet be sent. | 66 QuicTime ideal_next_packet_send_time_; // When can the next packet be sent. |
88 mutable bool was_last_send_delayed_; // True when the last send was delayed. | 67 mutable bool was_last_send_delayed_; // True when the last send was delayed. |
89 | 68 |
90 DISALLOW_COPY_AND_ASSIGN(PacingSender); | 69 DISALLOW_COPY_AND_ASSIGN(PacingSender); |
91 }; | 70 }; |
92 | 71 |
93 } // namespace net | 72 } // namespace net |
94 | 73 |
95 #endif // NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ | 74 #endif // NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ |
OLD | NEW |