send_algorithm_interface.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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,
325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                        CongestionControlType 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)
70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Called when the last retransmission timeout was spurious.
71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void RevertRetransmissionTimeout() = 0;
72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculate the time until we can send the next packet.
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual QuicTime::Delta TimeUntilSend(
75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      QuicTime now,
76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      QuicByteCount bytes_in_flight,
7746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      HasRetransmittableData has_retransmittable_data) const = 0;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // What's the current estimated bandwidth in bytes per second.
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns 0 when it does not have an estimate.
81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual QuicBandwidth BandwidthEstimate() const = 0;
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
83116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns true if the current bandwidth estimate is reliable.
84116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual bool HasReliableBandwidthEstimate() const = 0;
85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
86558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Get the send algorithm specific retransmission delay, called RTO in TCP,
87558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Note 1: the caller is responsible for sanity checking this value.
88558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Note 2: this will return zero if we don't have enough data for an estimate.
89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual QuicTime::Delta RetransmissionDelay() const = 0;
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
91f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns the size of the current congestion window in bytes.  Note, this is
92f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // not the *available* window.  Some send algorithms may not use a congestion
93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // window and will return 0.
94f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual QuicByteCount GetCongestionWindow() const = 0;
95116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Whether the send algorithm is currently in slow start.  When true, the
97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // BandwidthEstimate is expected to be too low.
98116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual bool InSlowStart() const = 0;
99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
10003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Whether the send algorithm is currently in recovery.
10103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual bool InRecovery() const = 0;
10203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns the size of the slow start congestion window in bytes,
104116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // aka ssthresh.  Some send algorithms do not define a slow start
105116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // threshold and will return 0.
106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual QuicByteCount GetSlowStartThreshold() const = 0;
1075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual CongestionControlType GetCongestionControlType() const = 0;
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
114