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// TCP cubic send side congestion algorithm, emulates the behaviour of 6// TCP cubic. 7 8#ifndef NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_ 9#define NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_ 10 11#include "base/basictypes.h" 12#include "base/compiler_specific.h" 13#include "net/base/net_export.h" 14#include "net/quic/congestion_control/cubic.h" 15#include "net/quic/congestion_control/hybrid_slow_start.h" 16#include "net/quic/congestion_control/send_algorithm_interface.h" 17#include "net/quic/quic_bandwidth.h" 18#include "net/quic/quic_protocol.h" 19#include "net/quic/quic_time.h" 20 21namespace net { 22 23namespace test { 24class TcpCubicSenderPeer; 25} // namespace test 26 27class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface { 28 public: 29 // Reno option and max_tcp_congestion_window are provided for testing. 30 TcpCubicSender(const QuicClock* clock, 31 bool reno, 32 QuicTcpCongestionWindow max_tcp_congestion_window); 33 virtual ~TcpCubicSender(); 34 35 // Start implementation of SendAlgorithmInterface. 36 virtual void OnIncomingQuicCongestionFeedbackFrame( 37 const QuicCongestionFeedbackFrame& feedback, 38 QuicTime feedback_receive_time, 39 const SentPacketsMap& sent_packets) OVERRIDE; 40 virtual void OnIncomingAck(QuicPacketSequenceNumber acked_sequence_number, 41 QuicByteCount acked_bytes, 42 QuicTime::Delta rtt) OVERRIDE; 43 virtual void OnIncomingLoss(QuicTime ack_receive_time) OVERRIDE; 44 virtual void SentPacket(QuicTime sent_time, 45 QuicPacketSequenceNumber sequence_number, 46 QuicByteCount bytes, 47 Retransmission is_retransmission) OVERRIDE; 48 virtual void AbandoningPacket(QuicPacketSequenceNumber sequence_number, 49 QuicByteCount abandoned_bytes) OVERRIDE; 50 virtual QuicTime::Delta TimeUntilSend( 51 QuicTime now, 52 Retransmission is_retransmission, 53 HasRetransmittableData has_retransmittable_data, 54 IsHandshake handshake) OVERRIDE; 55 virtual QuicBandwidth BandwidthEstimate() OVERRIDE; 56 virtual QuicTime::Delta SmoothedRtt() OVERRIDE; 57 virtual QuicTime::Delta RetransmissionDelay() OVERRIDE; 58 // End implementation of SendAlgorithmInterface. 59 60 private: 61 friend class test::TcpCubicSenderPeer; 62 63 QuicByteCount AvailableCongestionWindow(); 64 QuicByteCount CongestionWindow(); 65 void Reset(); 66 void AckAccounting(QuicTime::Delta rtt); 67 void CongestionAvoidance(QuicPacketSequenceNumber ack); 68 bool IsCwndLimited() const; 69 void OnTimeOut(); 70 71 HybridSlowStart hybrid_slow_start_; 72 Cubic cubic_; 73 74 // Reno provided for testing. 75 const bool reno_; 76 77 // ACK counter for the Reno implementation. 78 int64 congestion_window_count_; 79 80 // Receiver side advertised window. 81 QuicByteCount receiver_congestion_window_; 82 83 // Receiver side advertised packet loss. 84 int last_received_accumulated_number_of_lost_packets_; 85 86 // Bytes in flight, aka bytes on the wire. 87 QuicByteCount bytes_in_flight_; 88 89 // We need to keep track of the end sequence number of each RTT "burst". 90 bool update_end_sequence_number_; 91 QuicPacketSequenceNumber end_sequence_number_; 92 93 // Congestion window in packets. 94 QuicTcpCongestionWindow congestion_window_; 95 96 // Slow start congestion window in packets. 97 QuicTcpCongestionWindow slowstart_threshold_; 98 99 // Maximum number of outstanding packets for tcp. 100 QuicTcpCongestionWindow max_tcp_congestion_window_; 101 102 // Min RTT during this session. 103 QuicTime::Delta delay_min_; 104 105 // Smoothed RTT during this session. 106 QuicTime::Delta smoothed_rtt_; 107 108 // Mean RTT deviation during this session. 109 // Approximation of standard deviation, the error is roughly 1.25 times 110 // larger than the standard deviation, for a normally distributed signal. 111 QuicTime::Delta mean_deviation_; 112 113 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender); 114}; 115 116} // namespace net 117 118#endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_ 119