1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file. 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// A send algorithm which adds pacing on top of an another send algorithm. 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// It uses the underlying sender's bandwidth estimate to determine the 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// pacing rate to be used. It also takes into consideration the expected 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// resolution of the underlying alarm mechanism to ensure that alarms are 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// not set too aggressively, and to smooth out variations. 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <map> 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/basictypes.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/congestion_control/send_algorithm_interface.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/quic_bandwidth.h" 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/quic_config.h" 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/quic_protocol.h" 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/quic_time.h" 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace net { 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class NET_EXPORT_PRIVATE PacingSender : public SendAlgorithmInterface { 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Create a PacingSender to wrap the specified sender. |alarm_granularity| 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // indicates to the pacer to send that far into the future, since it should 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // not expect a callback before that time delta. |initial_packet_burst| is 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // the number of packets sent without pacing after quiescence. 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) PacingSender(SendAlgorithmInterface* sender, 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch QuicTime::Delta alarm_granularity, 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch uint32 initial_packet_burst); 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual ~PacingSender(); 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // SendAlgorithmInterface methods. 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE; 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void OnIncomingQuicCongestionFeedbackFrame( 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const QuicCongestionFeedbackFrame& feedback, 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) QuicTime feedback_receive_time) OVERRIDE; 42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void OnCongestionEvent(bool rtt_updated, 43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const CongestionVector& acked_packets, 451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const CongestionVector& lost_packets) OVERRIDE; 46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual bool OnPacketSent(QuicTime sent_time, 47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) QuicPacketSequenceNumber sequence_number, 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) QuicByteCount bytes, 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) HasRetransmittableData is_retransmittable) OVERRIDE; 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE; 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void RevertRetransmissionTimeout() OVERRIDE; 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicTime::Delta TimeUntilSend( 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) QuicTime now, 55010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 5646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) HasRetransmittableData has_retransmittable_data) const OVERRIDE; 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicBandwidth BandwidthEstimate() const OVERRIDE; 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool HasReliableBandwidthEstimate() const OVERRIDE; 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE; 60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicByteCount GetCongestionWindow() const OVERRIDE; 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool InSlowStart() const OVERRIDE; 6203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual bool InRecovery() const OVERRIDE; 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual QuicByteCount GetSlowStartThreshold() const OVERRIDE; 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual CongestionControlType GetCongestionControlType() const OVERRIDE; 65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_ptr<SendAlgorithmInterface> sender_; // Underlying sender. 68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) QuicTime::Delta alarm_granularity_; 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch uint32 initial_packet_burst_; 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch mutable uint32 burst_tokens_; 7146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Send time of the last packet considered delayed. 7246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) QuicTime last_delayed_packet_sent_time_; 73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) QuicTime next_packet_send_time_; // When can the next packet be sent. 7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) mutable bool was_last_send_delayed_; // True when the last send was delayed. 75010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) bool has_valid_rtt_; // True if we have at least one RTT update. 76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PacingSender); 78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} // namespace net 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif // NET_QUIC_CONGESTION_CONTROL_PACING_SENDER_H_ 83