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 <map>
     11 
     12 #include "base/basictypes.h"
     13 #include "net/base/net_export.h"
     14 #include "net/quic/quic_bandwidth.h"
     15 #include "net/quic/quic_clock.h"
     16 #include "net/quic/quic_protocol.h"
     17 #include "net/quic/quic_time.h"
     18 
     19 namespace net {
     20 
     21 class NET_EXPORT_PRIVATE SendAlgorithmInterface {
     22  public:
     23   class SentPacket {
     24    public:
     25     SentPacket(QuicByteCount bytes, QuicTime timestamp)
     26         : bytes_sent_(bytes),
     27           send_timestamp_(timestamp) {
     28     }
     29     QuicByteCount BytesSent() { return bytes_sent_; }
     30     QuicTime& SendTimestamp() { return send_timestamp_; }
     31 
     32    private:
     33     QuicByteCount bytes_sent_;
     34     QuicTime send_timestamp_;
     35   };
     36 
     37   typedef std::map<QuicPacketSequenceNumber, SentPacket*> SentPacketsMap;
     38 
     39   static SendAlgorithmInterface* Create(const QuicClock* clock,
     40                                         CongestionFeedbackType type);
     41 
     42   virtual ~SendAlgorithmInterface() {}
     43 
     44   // Called when we receive congestion feedback from remote peer.
     45   virtual void OnIncomingQuicCongestionFeedbackFrame(
     46       const QuicCongestionFeedbackFrame& feedback,
     47       QuicTime feedback_receive_time,
     48       const SentPacketsMap& sent_packets) = 0;
     49 
     50   // Called for each received ACK, with sequence number from remote peer.
     51   virtual void OnIncomingAck(QuicPacketSequenceNumber acked_sequence_number,
     52                              QuicByteCount acked_bytes,
     53                              QuicTime::Delta rtt) = 0;
     54 
     55   virtual void OnIncomingLoss(QuicTime ack_receive_time) = 0;
     56 
     57   // Inform that we sent x bytes to the wire, and if that was a retransmission.
     58   // Note: this function must be called for every packet sent to the wire.
     59   virtual void SentPacket(QuicTime sent_time,
     60                           QuicPacketSequenceNumber sequence_number,
     61                           QuicByteCount bytes,
     62                           Retransmission is_retransmission) = 0;
     63 
     64   // Called when a packet is timed out.
     65   virtual void AbandoningPacket(QuicPacketSequenceNumber sequence_number,
     66                                 QuicByteCount abandoned_bytes) = 0;
     67 
     68   // Calculate the time until we can send the next packet.
     69   virtual QuicTime::Delta TimeUntilSend(
     70       QuicTime now,
     71       Retransmission is_retransmission,
     72       HasRetransmittableData has_retransmittable_data,
     73       IsHandshake handshake) = 0;
     74 
     75   // What's the current estimated bandwidth in bytes per second.
     76   // Returns 0 when it does not have an estimate.
     77   virtual QuicBandwidth BandwidthEstimate() = 0;
     78 
     79   // TODO(satyamshekhar): Monitor MinRtt.
     80   virtual QuicTime::Delta SmoothedRtt() = 0;
     81 
     82   // Get the send algorithm specific retransmission delay, called RTO in TCP,
     83   // Note 1: the caller is responsible for sanity checking this value.
     84   // Note 2: this will return zero if we don't have enough data for an estimate.
     85   virtual QuicTime::Delta RetransmissionDelay() = 0;
     86 };
     87 
     88 }  // namespace net
     89 
     90 #endif  // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
     91