15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The pure virtual class for send side congestion control algorithm. 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <algorithm> 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <map> 12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/quic_bandwidth.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_clock.h" 170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "net/quic/quic_config.h" 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "net/quic/quic_connection_stats.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_protocol.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_time.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class RttStats; 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT_PRIVATE SendAlgorithmInterface { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // A sorted vector of packets. 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef std::vector<std::pair<QuicPacketSequenceNumber, TransmissionInfo>> 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci CongestionVector; 31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static SendAlgorithmInterface* Create(const QuicClock* clock, 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const RttStats* rtt_stats, 345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) CongestionControlType type, 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) QuicConnectionStats* stats); 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~SendAlgorithmInterface() {} 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void SetFromConfig(const QuicConfig& config, bool is_server) = 0; 400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when we receive congestion feedback from remote peer. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnIncomingQuicCongestionFeedbackFrame( 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const QuicCongestionFeedbackFrame& feedback, 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) QuicTime feedback_receive_time) = 0; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Indicates an update to the congestion state, caused either by an incoming 47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // ack or loss event timeout. |rtt_updated| indicates whether a new 48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // latest_rtt sample has been taken, |byte_in_flight| the bytes in flight 49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // prior to the congestion event. |acked_packets| and |lost_packets| are 50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // any packets considered acked or lost as a result of the congestion event. 51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void OnCongestionEvent(bool rtt_updated, 52010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const CongestionVector& acked_packets, 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const CongestionVector& lost_packets) = 0; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Inform that we sent |bytes| to the wire, and if the packet is 57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // retransmittable. Returns true if the packet should be tracked by the 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // congestion manager and included in bytes_in_flight, false otherwise. 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |bytes_in_flight| is the number of bytes in flight before the packet was 60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // sent. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note: this function must be called for every packet sent to the wire. 6268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual bool OnPacketSent(QuicTime sent_time, 63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) QuicPacketSequenceNumber sequence_number, 6568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) QuicByteCount bytes, 6668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) HasRetransmittableData is_retransmittable) = 0; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Called when the retransmission timeout fires. Neither OnPacketAbandoned 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // nor OnPacketLost will be called for these packets. 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnRetransmissionTimeout(bool packets_retransmitted) = 0; 71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Called when the last retransmission timeout was spurious. 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void RevertRetransmissionTimeout() = 0; 74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Calculate the time until we can send the next packet. 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual QuicTime::Delta TimeUntilSend( 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) QuicTime now, 78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 7946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) HasRetransmittableData has_retransmittable_data) const = 0; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // What's the current estimated bandwidth in bytes per second. 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns 0 when it does not have an estimate. 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicBandwidth BandwidthEstimate() const = 0; 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns true if the current bandwidth estimate is reliable. 86116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool HasReliableBandwidthEstimate() const = 0; 87116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 88558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Get the send algorithm specific retransmission delay, called RTO in TCP, 89558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Note 1: the caller is responsible for sanity checking this value. 90558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Note 2: this will return zero if we don't have enough data for an estimate. 91f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicTime::Delta RetransmissionDelay() const = 0; 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Returns the size of the current congestion window in bytes. Note, this is 94f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // not the *available* window. Some send algorithms may not use a congestion 95f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // window and will return 0. 96f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicByteCount GetCongestionWindow() const = 0; 97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 98116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Whether the send algorithm is currently in slow start. When true, the 99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // BandwidthEstimate is expected to be too low. 100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool InSlowStart() const = 0; 101116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 10203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Whether the send algorithm is currently in recovery. 10303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual bool InRecovery() const = 0; 10403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 105116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Returns the size of the slow start congestion window in bytes, 106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // aka ssthresh. Some send algorithms do not define a slow start 107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // threshold and will return 0. 108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual QuicByteCount GetSlowStartThreshold() const = 0; 1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual CongestionControlType GetCongestionControlType() const = 0; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ 116