Home | History | Annotate | Download | only in congestion_control
      1 // Copyright (c) 2012 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 // The pure virtual class for send side congestion control algorithm.
      6 
      7 #ifndef NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
      8 #define NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
      9 
     10 #include <algorithm>
     11 #include <map>
     12 
     13 #include "base/basictypes.h"
     14 #include "net/base/net_export.h"
     15 #include "net/quic/quic_bandwidth.h"
     16 #include "net/quic/quic_clock.h"
     17 #include "net/quic/quic_config.h"
     18 #include "net/quic/quic_protocol.h"
     19 #include "net/quic/quic_time.h"
     20 
     21 namespace net {
     22 
     23 class NET_EXPORT_PRIVATE SendAlgorithmInterface {
     24  public:
     25   class SentPacket {
     26    public:
     27     SentPacket(QuicByteCount bytes,
     28                QuicTime timestamp,
     29                HasRetransmittableData has_retransmittable_data)
     30         : bytes_sent_(bytes),
     31           send_timestamp_(timestamp),
     32           has_retransmittable_data_(has_retransmittable_data),
     33           nack_count_(0) {
     34     }
     35     QuicByteCount bytes_sent() const { return bytes_sent_; }
     36     const QuicTime& send_timestamp() const { return send_timestamp_; }
     37     HasRetransmittableData has_retransmittable_data() const {
     38       return has_retransmittable_data_;
     39     }
     40     size_t nack_count() const { return nack_count_; }
     41 
     42     void Nack(size_t min_nacks) {
     43       nack_count_ = std::max(min_nacks, nack_count_ + 1);
     44     }
     45 
     46    private:
     47     QuicByteCount bytes_sent_;
     48     QuicTime send_timestamp_;
     49     HasRetransmittableData has_retransmittable_data_;
     50     size_t nack_count_;
     51   };
     52 
     53   typedef std::map<QuicPacketSequenceNumber, SentPacket*> SentPacketsMap;
     54 
     55   static SendAlgorithmInterface* Create(const QuicClock* clock,
     56                                         CongestionFeedbackType type);
     57 
     58   virtual ~SendAlgorithmInterface() {}
     59 
     60   virtual void SetFromConfig(const QuicConfig& config, bool is_server) = 0;
     61 
     62   // Sets the maximum size of packets that will be sent.
     63   virtual void SetMaxPacketSize(QuicByteCount max_packet_size) = 0;
     64 
     65   // Called when we receive congestion feedback from remote peer.
     66   virtual void OnIncomingQuicCongestionFeedbackFrame(
     67       const QuicCongestionFeedbackFrame& feedback,
     68       QuicTime feedback_receive_time,
     69       const SentPacketsMap& sent_packets) = 0;
     70 
     71   // Called for each received ACK, with sequence number from remote peer.
     72   virtual void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
     73                              QuicByteCount acked_bytes,
     74                              QuicTime::Delta rtt) = 0;
     75 
     76   // Indicates a loss event of one packet. |sequence_number| is the
     77   // sequence number of the lost packet.
     78   virtual void OnPacketLost(QuicPacketSequenceNumber sequence_number,
     79                             QuicTime ack_receive_time) = 0;
     80 
     81   // Inform that we sent x bytes to the wire, and if that was a retransmission.
     82   // Returns true if the packet should be tracked by the congestion manager,
     83   // false otherwise. This is used by implementations such as tcp_cubic_sender
     84   // that do not count outgoing ACK packets against the congestion window.
     85   // Note: this function must be called for every packet sent to the wire.
     86   virtual bool OnPacketSent(QuicTime sent_time,
     87                             QuicPacketSequenceNumber sequence_number,
     88                             QuicByteCount bytes,
     89                             TransmissionType transmission_type,
     90                             HasRetransmittableData is_retransmittable) = 0;
     91 
     92   // Called when the retransmission timeout fires.
     93   virtual void OnRetransmissionTimeout() = 0;
     94 
     95   // Called when a packet is timed out.
     96   virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
     97                                 QuicByteCount abandoned_bytes) = 0;
     98 
     99   // Calculate the time until we can send the next packet.
    100   virtual QuicTime::Delta TimeUntilSend(
    101       QuicTime now,
    102       TransmissionType transmission_type,
    103       HasRetransmittableData has_retransmittable_data,
    104       IsHandshake handshake) = 0;
    105 
    106   // What's the current estimated bandwidth in bytes per second.
    107   // Returns 0 when it does not have an estimate.
    108   virtual QuicBandwidth BandwidthEstimate() const = 0;
    109 
    110   // TODO(satyamshekhar): Monitor MinRtt.
    111   virtual QuicTime::Delta SmoothedRtt() const = 0;
    112 
    113   // Get the send algorithm specific retransmission delay, called RTO in TCP,
    114   // Note 1: the caller is responsible for sanity checking this value.
    115   // Note 2: this will return zero if we don't have enough data for an estimate.
    116   virtual QuicTime::Delta RetransmissionDelay() const = 0;
    117 
    118   // Returns the size of the current congestion window in bytes.  Note, this is
    119   // not the *available* window.  Some send algorithms may not use a congestion
    120   // window and will return 0.
    121   virtual QuicByteCount GetCongestionWindow() const = 0;
    122 };
    123 
    124 }  // namespace net
    125 
    126 #endif  // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
    127