This source file includes following definitions.
- latest_rtt_
- SetFromConfig
- OnIncomingQuicCongestionFeedbackFrame
- OnPacketAcked
- OnPacketLost
- OnPacketSent
- OnRetransmissionTimeout
- OnPacketAbandoned
- TimeUntilSend
- CongestionWindow
- BandwidthEstimate
- UpdateRtt
- RetransmissionDelay
- GetCongestionWindow
#include "net/quic/congestion_control/fix_rate_sender.h"
#include <math.h>
#include <algorithm>
#include "base/logging.h"
#include "net/quic/quic_protocol.h"
using std::max;
namespace {
const int kInitialBitrate = 100000;
const uint64 kWindowSizeUs = 10000;
}
namespace net {
FixRateSender::FixRateSender(const QuicClock* clock)
: bitrate_(QuicBandwidth::FromBytesPerSecond(kInitialBitrate)),
max_segment_size_(kDefaultMaxPacketSize),
fix_rate_leaky_bucket_(bitrate_),
paced_sender_(bitrate_, max_segment_size_),
data_in_flight_(0),
latest_rtt_(QuicTime::Delta::Zero()) {
DVLOG(1) << "FixRateSender";
}
FixRateSender::~FixRateSender() {
}
void FixRateSender::SetFromConfig(const QuicConfig& config, bool is_server) {
}
void FixRateSender::OnIncomingQuicCongestionFeedbackFrame(
const QuicCongestionFeedbackFrame& feedback,
QuicTime feedback_receive_time) {
LOG_IF(DFATAL, feedback.type != kFixRate) <<
"Invalid incoming CongestionFeedbackType:" << feedback.type;
if (feedback.type == kFixRate) {
bitrate_ = feedback.fix_rate.bitrate;
fix_rate_leaky_bucket_.SetDrainingRate(feedback_receive_time, bitrate_);
paced_sender_.UpdateBandwidthEstimate(feedback_receive_time, bitrate_);
}
}
void FixRateSender::OnPacketAcked(
QuicPacketSequenceNumber ,
QuicByteCount bytes_acked) {
DCHECK_GE(data_in_flight_, bytes_acked);
data_in_flight_ -= bytes_acked;
}
void FixRateSender::OnPacketLost(QuicPacketSequenceNumber ,
QuicTime ) {
}
bool FixRateSender::OnPacketSent(
QuicTime sent_time,
QuicPacketSequenceNumber ,
QuicByteCount bytes,
HasRetransmittableData ) {
fix_rate_leaky_bucket_.Add(sent_time, bytes);
paced_sender_.OnPacketSent(sent_time, bytes);
data_in_flight_ += bytes;
return true;
}
void FixRateSender::OnRetransmissionTimeout(bool packets_retransmitted) { }
void FixRateSender::OnPacketAbandoned(
QuicPacketSequenceNumber ,
QuicByteCount bytes_abandoned) {
DCHECK_GE(data_in_flight_, bytes_abandoned);
data_in_flight_ -= bytes_abandoned;
}
QuicTime::Delta FixRateSender::TimeUntilSend(
QuicTime now,
HasRetransmittableData ) {
if (CongestionWindow() > fix_rate_leaky_bucket_.BytesPending(now)) {
if (CongestionWindow() <= data_in_flight_) {
return QuicTime::Delta::Infinite();
}
return paced_sender_.TimeUntilSend(now, QuicTime::Delta::Zero());
}
QuicTime::Delta time_remaining = fix_rate_leaky_bucket_.TimeRemaining(now);
if (time_remaining.IsZero()) {
return QuicTime::Delta::Infinite();
}
return paced_sender_.TimeUntilSend(now, time_remaining);
}
QuicByteCount FixRateSender::CongestionWindow() {
QuicByteCount window_size_bytes = bitrate_.ToBytesPerPeriod(
QuicTime::Delta::FromMicroseconds(kWindowSizeUs));
return max(kDefaultMaxPacketSize, window_size_bytes);
}
QuicBandwidth FixRateSender::BandwidthEstimate() const {
return bitrate_;
}
void FixRateSender::UpdateRtt(QuicTime::Delta rtt_sample) {
DCHECK_LE(0, rtt_sample.ToMicroseconds());
if (rtt_sample.IsInfinite()) {
return;
}
latest_rtt_ = rtt_sample;
}
QuicTime::Delta FixRateSender::RetransmissionDelay() const {
return latest_rtt_.Add(latest_rtt_);
}
QuicByteCount FixRateSender::GetCongestionWindow() const {
return 0;
}
}