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: 28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) typedef std::map<QuicPacketSequenceNumber, TransmissionInfo> CongestionMap; 29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static SendAlgorithmInterface* Create(const QuicClock* clock, 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const RttStats* rtt_stats, 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CongestionFeedbackType type, 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) QuicConnectionStats* stats); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~SendAlgorithmInterface() {} 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void SetFromConfig(const QuicConfig& config, bool is_server) = 0; 380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when we receive congestion feedback from remote peer. 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnIncomingQuicCongestionFeedbackFrame( 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const QuicCongestionFeedbackFrame& feedback, 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) QuicTime feedback_receive_time) = 0; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Indicates an update to the congestion state, caused either by an incoming 45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // ack or loss event timeout. |rtt_updated| indicates whether a new 46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // latest_rtt sample has been taken, |byte_in_flight| the bytes in flight 47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // prior to the congestion event. |acked_packets| and |lost_packets| are 48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // any packets considered acked or lost as a result of the congestion event. 49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void OnCongestionEvent(bool rtt_updated, 50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const CongestionMap& acked_packets, 52010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const CongestionMap& lost_packets) = 0; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Inform that we sent |bytes| to the wire, and if the packet is 55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // retransmittable. Returns true if the packet should be tracked by the 56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // congestion manager and included in bytes_in_flight, false otherwise. 57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |bytes_in_flight| is the number of bytes in flight before the packet was 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // sent. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note: this function must be called for every packet sent to the wire. 6068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual bool OnPacketSent(QuicTime sent_time, 61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 6268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) QuicPacketSequenceNumber sequence_number, 6368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) QuicByteCount bytes, 6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) HasRetransmittableData is_retransmittable) = 0; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Called when the retransmission timeout fires. Neither OnPacketAbandoned 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // nor OnPacketLost will be called for these packets. 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnRetransmissionTimeout(bool packets_retransmitted) = 0; 69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Calculate the time until we can send the next packet. 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual QuicTime::Delta TimeUntilSend( 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) QuicTime now, 73010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) QuicByteCount bytes_in_flight, 7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) HasRetransmittableData has_retransmittable_data) const = 0; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // What's the current estimated bandwidth in bytes per second. 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns 0 when it does not have an estimate. 78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicBandwidth BandwidthEstimate() const = 0; 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 80558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Get the send algorithm specific retransmission delay, called RTO in TCP, 81558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Note 1: the caller is responsible for sanity checking this value. 82558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Note 2: this will return zero if we don't have enough data for an estimate. 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicTime::Delta RetransmissionDelay() const = 0; 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Returns the size of the current congestion window in bytes. Note, this is 86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // not the *available* window. Some send algorithms may not use a congestion 87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // window and will return 0. 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual QuicByteCount GetCongestionWindow() const = 0; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ 94