send_algorithm_interface.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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)
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <map>
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/quic_bandwidth.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_clock.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_protocol.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_time.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT_PRIVATE SendAlgorithmInterface {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class SentPacket {
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   public:
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    SentPacket(QuicByteCount bytes, QuicTime timestamp)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        : bytes_sent_(bytes),
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          send_timestamp_(timestamp) {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicByteCount BytesSent() { return bytes_sent_; }
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicTime& SendTimestamp() { return send_timestamp_; }
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   private:
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicByteCount bytes_sent_;
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicTime send_timestamp_;
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef std::map<QuicPacketSequenceNumber, SentPacket*> SentPacketsMap;
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static SendAlgorithmInterface* Create(const QuicClock* clock,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        CongestionFeedbackType type);
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~SendAlgorithmInterface() {}
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Called when we receive congestion feedback from remote peer.
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnIncomingQuicCongestionFeedbackFrame(
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const QuicCongestionFeedbackFrame& feedback,
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      QuicTime feedback_receive_time,
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const SentPacketsMap& sent_packets) = 0;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called for each received ACK, with sequence number from remote peer.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnIncomingAck(QuicPacketSequenceNumber acked_sequence_number,
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             QuicByteCount acked_bytes,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             QuicTime::Delta rtt) = 0;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnIncomingLoss(QuicTime ack_receive_time) = 0;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Inform that we sent x bytes to the wire, and if that was a retransmission.
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns true if the packet should be tracked by the congestion manager,
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // false otherwise. This is used by implementations such as tcp_cubic_sender
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // that do not count outgoing ACK packets against the congestion window.
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,
6368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                            QuicPacketSequenceNumber sequence_number,
6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                            QuicByteCount bytes,
6568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                            TransmissionType transmission_type,
6668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                            HasRetransmittableData is_retransmittable) = 0;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Called when a packet is timed out.
6968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                QuicByteCount abandoned_bytes) = 0;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculate the time until we can send the next packet.
73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual QuicTime::Delta TimeUntilSend(
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      QuicTime now,
7568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      TransmissionType transmission_type,
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      HasRetransmittableData has_retransmittable_data,
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      IsHandshake handshake) = 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.
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual QuicBandwidth BandwidthEstimate() = 0;
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TODO(satyamshekhar): Monitor MinRtt.
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual QuicTime::Delta SmoothedRtt() = 0;
85558790d6acca3451cf3a6b497803a5f07d0bec58Ben 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.
89558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  virtual QuicTime::Delta RetransmissionDelay() = 0;
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Returns the size of the current congestion window.  Note, this
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // is not the *available* window.  Some send algorithms may not use a
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // congestion window and will return 0.
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual QuicByteCount GetCongestionWindow() = 0;
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Sets the value of the current congestion window to |window|.
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetCongestionWindow(QuicByteCount window) = 0;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
103