This source file includes following definitions.
- max_tcp_congestion_window_
- InSlowStart
- SetFromConfig
- OnIncomingQuicCongestionFeedbackFrame
- OnPacketAcked
- OnPacketLost
- OnPacketSent
- OnPacketAbandoned
- TimeUntilSend
- AvailableSendWindow
- SendWindow
- BandwidthEstimate
- RetransmissionDelay
- GetCongestionWindow
- IsCwndLimited
- InRecovery
- MaybeIncreaseCwnd
- OnRetransmissionTimeout
- UpdateRtt
#include "net/quic/congestion_control/tcp_cubic_sender.h"
#include <algorithm>
#include "base/metrics/histogram.h"
#include "net/quic/congestion_control/rtt_stats.h"
using std::max;
using std::min;
namespace net {
namespace {
const QuicTcpCongestionWindow kMinimumCongestionWindow = 2;
const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS;
const QuicByteCount kDefaultReceiveWindow = 64000;
const int64 kInitialCongestionWindow = 10;
const int kMaxBurstLength = 3;
};
TcpCubicSender::TcpCubicSender(
const QuicClock* clock,
const RttStats* rtt_stats,
bool reno,
QuicTcpCongestionWindow max_tcp_congestion_window,
QuicConnectionStats* stats)
: hybrid_slow_start_(clock),
cubic_(clock, stats),
rtt_stats_(rtt_stats),
reno_(reno),
congestion_window_count_(0),
receive_window_(kDefaultReceiveWindow),
bytes_in_flight_(0),
prr_out_(0),
prr_delivered_(0),
ack_count_since_loss_(0),
bytes_in_flight_before_loss_(0),
largest_sent_sequence_number_(0),
largest_acked_sequence_number_(0),
largest_sent_at_last_cutback_(0),
congestion_window_(kInitialCongestionWindow),
slowstart_threshold_(max_tcp_congestion_window),
max_tcp_congestion_window_(max_tcp_congestion_window) {
}
TcpCubicSender::~TcpCubicSender() {
UMA_HISTOGRAM_COUNTS("Net.QuicSession.FinalTcpCwnd", congestion_window_);
}
bool TcpCubicSender::InSlowStart() const {
return congestion_window_ < slowstart_threshold_;
}
void TcpCubicSender::SetFromConfig(const QuicConfig& config, bool is_server) {
if (is_server) {
congestion_window_ = config.server_initial_congestion_window();
}
}
void TcpCubicSender::OnIncomingQuicCongestionFeedbackFrame(
const QuicCongestionFeedbackFrame& feedback,
QuicTime feedback_receive_time) {
receive_window_ = feedback.tcp.receive_window;
}
void TcpCubicSender::OnPacketAcked(
QuicPacketSequenceNumber acked_sequence_number, QuicByteCount acked_bytes) {
DCHECK_GE(bytes_in_flight_, acked_bytes);
bytes_in_flight_ -= acked_bytes;
prr_delivered_ += acked_bytes;
++ack_count_since_loss_;
largest_acked_sequence_number_ = max(acked_sequence_number,
largest_acked_sequence_number_);
MaybeIncreaseCwnd(acked_sequence_number);
hybrid_slow_start_.OnPacketAcked(acked_sequence_number, InSlowStart());
}
void TcpCubicSender::OnPacketLost(QuicPacketSequenceNumber sequence_number,
QuicTime ) {
if (sequence_number <= largest_sent_at_last_cutback_) {
DVLOG(1) << "Ignoring loss for largest_missing:" << sequence_number
<< " because it was sent prior to the last CWND cutback.";
return;
}
prr_out_ = 0;
bytes_in_flight_before_loss_ = bytes_in_flight_;
prr_delivered_ = kMaxPacketSize;
ack_count_since_loss_ = 1;
if (reno_) {
congestion_window_ = congestion_window_ >> 1;
} else {
congestion_window_ =
cubic_.CongestionWindowAfterPacketLoss(congestion_window_);
}
slowstart_threshold_ = congestion_window_;
if (congestion_window_ < kMinimumCongestionWindow) {
congestion_window_ = kMinimumCongestionWindow;
}
largest_sent_at_last_cutback_ = largest_sent_sequence_number_;
congestion_window_count_ = 0;
DVLOG(1) << "Incoming loss; congestion window: " << congestion_window_
<< " slowstart threshold: " << slowstart_threshold_;
}
bool TcpCubicSender::OnPacketSent(QuicTime ,
QuicPacketSequenceNumber sequence_number,
QuicByteCount bytes,
HasRetransmittableData is_retransmittable) {
if (is_retransmittable != HAS_RETRANSMITTABLE_DATA) {
return false;
}
bytes_in_flight_ += bytes;
prr_out_ += bytes;
if (largest_sent_sequence_number_ < sequence_number) {
largest_sent_sequence_number_ = sequence_number;
}
hybrid_slow_start_.OnPacketSent(sequence_number, AvailableSendWindow());
return true;
}
void TcpCubicSender::OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
QuicByteCount abandoned_bytes) {
DCHECK_GE(bytes_in_flight_, abandoned_bytes);
bytes_in_flight_ -= abandoned_bytes;
}
QuicTime::Delta TcpCubicSender::TimeUntilSend(
QuicTime ,
HasRetransmittableData has_retransmittable_data) {
if (has_retransmittable_data == NO_RETRANSMITTABLE_DATA) {
return QuicTime::Delta::Zero();
}
if (AvailableSendWindow() > 0) {
if (InRecovery() &&
prr_delivered_ + ack_count_since_loss_ * kMaxSegmentSize < prr_out_) {
return QuicTime::Delta::Infinite();
}
return QuicTime::Delta::Zero();
}
if (InRecovery() &&
prr_delivered_ * slowstart_threshold_ * kMaxSegmentSize >
prr_out_ * bytes_in_flight_before_loss_) {
return QuicTime::Delta::Zero();
}
return QuicTime::Delta::Infinite();
}
QuicByteCount TcpCubicSender::AvailableSendWindow() {
if (bytes_in_flight_ > SendWindow()) {
return 0;
}
return SendWindow() - bytes_in_flight_;
}
QuicByteCount TcpCubicSender::SendWindow() {
return min(receive_window_, GetCongestionWindow());
}
QuicBandwidth TcpCubicSender::BandwidthEstimate() const {
return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(),
rtt_stats_->SmoothedRtt());
}
QuicTime::Delta TcpCubicSender::RetransmissionDelay() const {
if (!rtt_stats_->HasUpdates()) {
return QuicTime::Delta::Zero();
}
return QuicTime::Delta::FromMicroseconds(
rtt_stats_->SmoothedRtt().ToMicroseconds() +
4 * rtt_stats_->mean_deviation().ToMicroseconds());
}
QuicByteCount TcpCubicSender::GetCongestionWindow() const {
return congestion_window_ * kMaxSegmentSize;
}
bool TcpCubicSender::IsCwndLimited() const {
const QuicByteCount congestion_window_bytes = congestion_window_ *
kMaxSegmentSize;
if (bytes_in_flight_ >= congestion_window_bytes) {
return true;
}
const QuicByteCount tcp_max_burst = kMaxBurstLength * kMaxSegmentSize;
const QuicByteCount left = congestion_window_bytes - bytes_in_flight_;
return left <= tcp_max_burst;
}
bool TcpCubicSender::InRecovery() const {
return largest_acked_sequence_number_ <= largest_sent_at_last_cutback_ &&
largest_acked_sequence_number_ != 0;
}
void TcpCubicSender::MaybeIncreaseCwnd(
QuicPacketSequenceNumber acked_sequence_number) {
if (!IsCwndLimited()) {
return;
}
if (acked_sequence_number <= largest_sent_at_last_cutback_) {
return;
}
if (InSlowStart()) {
if (congestion_window_ < max_tcp_congestion_window_) {
++congestion_window_;
}
DVLOG(1) << "Slow start; congestion window: " << congestion_window_
<< " slowstart threshold: " << slowstart_threshold_;
return;
}
if (congestion_window_ >= max_tcp_congestion_window_) {
return;
}
if (reno_) {
++congestion_window_count_;
if (congestion_window_count_ >= congestion_window_) {
++congestion_window_;
congestion_window_count_ = 0;
}
DVLOG(1) << "Reno; congestion window: " << congestion_window_
<< " slowstart threshold: " << slowstart_threshold_
<< " congestion window count: " << congestion_window_count_;
} else {
congestion_window_ = min(max_tcp_congestion_window_,
cubic_.CongestionWindowAfterAck(
congestion_window_, rtt_stats_->min_rtt()));
DVLOG(1) << "Cubic; congestion window: " << congestion_window_
<< " slowstart threshold: " << slowstart_threshold_;
}
}
void TcpCubicSender::OnRetransmissionTimeout(bool packets_retransmitted) {
bytes_in_flight_ = 0;
largest_sent_at_last_cutback_ = 0;
if (packets_retransmitted) {
cubic_.Reset();
congestion_window_ = kMinimumCongestionWindow;
}
}
void TcpCubicSender::UpdateRtt(QuicTime::Delta rtt) {
if (InSlowStart() &&
hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_, congestion_window_)) {
slowstart_threshold_ = congestion_window_;
}
}
}