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. 4 // 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. 10 11 #ifndef NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ 12 #define NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ 13 14 #include <map> 15 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_clock.h" 21 #include "net/quic/quic_config.h" 22 #include "net/quic/quic_protocol.h" 23 #include "net/quic/quic_time.h" 24 25 namespace net { 26 27 class NET_EXPORT_PRIVATE PacingSender : public SendAlgorithmInterface { 28 public: 29 PacingSender(SendAlgorithmInterface* sender, 30 QuicTime::Delta alarm_granularity); 31 virtual ~PacingSender(); 32 33 // SendAlgorithmInterface methods. 34 virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE; 35 virtual void SetMaxPacketSize(QuicByteCount max_packet_size) OVERRIDE; 36 virtual void OnIncomingQuicCongestionFeedbackFrame( 37 const QuicCongestionFeedbackFrame& feedback, 38 QuicTime feedback_receive_time, 39 const SendAlgorithmInterface::SentPacketsMap& sent_packets) OVERRIDE; 40 virtual void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number, 41 QuicByteCount acked_bytes, 42 QuicTime::Delta rtt) OVERRIDE; 43 virtual void OnPacketLost(QuicPacketSequenceNumber sequence_number, 44 QuicTime ack_receive_time) OVERRIDE; 45 virtual bool OnPacketSent(QuicTime sent_time, 46 QuicPacketSequenceNumber sequence_number, 47 QuicByteCount bytes, 48 TransmissionType transmission_type, 49 HasRetransmittableData is_retransmittable) OVERRIDE; 50 virtual void OnRetransmissionTimeout() OVERRIDE; 51 virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number, 52 QuicByteCount abandoned_bytes) OVERRIDE; 53 virtual QuicTime::Delta TimeUntilSend( 54 QuicTime now, 55 TransmissionType transmission_type, 56 HasRetransmittableData has_retransmittable_data, 57 IsHandshake handshake) OVERRIDE; 58 virtual QuicBandwidth BandwidthEstimate() const OVERRIDE; 59 virtual QuicTime::Delta SmoothedRtt() const OVERRIDE; 60 virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE; 61 virtual QuicByteCount GetCongestionWindow() const OVERRIDE; 62 63 private: 64 QuicTime::Delta GetTransferTime(QuicByteCount bytes); 65 66 scoped_ptr<SendAlgorithmInterface> sender_; // Underlying sender. 67 QuicTime::Delta alarm_granularity_; 68 QuicTime next_packet_send_time_; // When can the next packet be sent. 69 bool was_last_send_delayed_; // True when the last send was delayed. 70 QuicByteCount max_segment_size_; 71 72 DISALLOW_COPY_AND_ASSIGN(PacingSender); 73 }; 74 75 } // namespace net 76 77 #endif // NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ 78