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
3 // found in the LICENSE file.
5 // A send algorithm which adds pacing on top of an another send algorithm.
6 // It uses the underlying sender's bandwidth estimate to determine the
7 // pacing rate to be used. It also takes into consideration the expected
8 // resolution of the underlying alarm mechanism to ensure that alarms are
9 // not set too aggressively, and to smooth out variations.
11 #ifndef NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_
12 #define NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_
16 #include "base/basictypes.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "net/quic/congestion_control/send_algorithm_interface.h"
19 #include "net/quic/quic_bandwidth.h"
20 #include "net/quic/quic_config.h"
21 #include "net/quic/quic_protocol.h"
22 #include "net/quic/quic_time.h"
26 class NET_EXPORT_PRIVATE PacingSender : public SendAlgorithmInterface {
28 // Create a PacingSender to wrap the specified sender. |alarm_granularity|
29 // indicates to the pacer to send that far into the future, since it should
30 // not expect a callback before that time delta. |initial_packet_burst| is
31 // the number of packets sent without pacing after quiescence.
32 PacingSender(SendAlgorithmInterface* sender,
33 QuicTime::Delta alarm_granularity,
34 uint32 initial_packet_burst);
35 ~PacingSender() override;
37 // SendAlgorithmInterface methods.
38 void SetFromConfig(const QuicConfig& config, bool is_server) override;
39 void SetNumEmulatedConnections(int num_connections) override;
40 void OnCongestionEvent(bool rtt_updated,
41 QuicByteCount bytes_in_flight,
42 const CongestionVector& acked_packets,
43 const CongestionVector& lost_packets) override;
44 bool OnPacketSent(QuicTime sent_time,
45 QuicByteCount bytes_in_flight,
46 QuicPacketSequenceNumber sequence_number,
48 HasRetransmittableData is_retransmittable) override;
49 void OnRetransmissionTimeout(bool packets_retransmitted) override;
50 void RevertRetransmissionTimeout() override;
51 QuicTime::Delta TimeUntilSend(
53 QuicByteCount bytes_in_flight,
54 HasRetransmittableData has_retransmittable_data) const override;
55 QuicBandwidth PacingRate() const override;
56 QuicBandwidth BandwidthEstimate() const override;
57 bool HasReliableBandwidthEstimate() const override;
58 QuicTime::Delta RetransmissionDelay() const override;
59 QuicByteCount GetCongestionWindow() const override;
60 bool InSlowStart() const override;
61 bool InRecovery() const override;
62 QuicByteCount GetSlowStartThreshold() const override;
63 CongestionControlType GetCongestionControlType() const override;
66 scoped_ptr<SendAlgorithmInterface> sender_; // Underlying sender.
67 QuicTime::Delta alarm_granularity_;
68 uint32 initial_packet_burst_;
69 mutable uint32 burst_tokens_;
70 // Send time of the last packet considered delayed.
71 QuicTime last_delayed_packet_sent_time_;
72 QuicTime next_packet_send_time_; // When can the next packet be sent.
73 mutable bool was_last_send_delayed_; // True when the last send was delayed.
75 DISALLOW_COPY_AND_ASSIGN(PacingSender);
80 #endif // NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_