This source file includes following definitions.
- stats_
- Reset
- UpdateCongestionControlStats
- CongestionWindowAfterPacketLoss
- CongestionWindowAfterAck
#include "net/quic/congestion_control/cubic.h"
#include <algorithm>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "net/quic/congestion_control/cube_root.h"
#include "net/quic/quic_protocol.h"
using std::max;
namespace net {
namespace {
const int kCubeScale = 40;
const int kCubeCongestionWindowScale = 410;
const uint64 kCubeFactor = (GG_UINT64_C(1) << kCubeScale) /
kCubeCongestionWindowScale;
const uint32 kNumConnections = 2;
const float kBeta = 0.7f;
const float kBetaLastMax = 0.85f;
const float kNConnectionBeta = (kNumConnections - 1 + kBeta) / kNumConnections;
const float kNConnectionAlpha = 3 * kNumConnections * kNumConnections *
(1 - kNConnectionBeta) / (1 + kNConnectionBeta);
}
Cubic::Cubic(const QuicClock* clock, QuicConnectionStats* stats)
: clock_(clock),
epoch_(QuicTime::Zero()),
last_update_time_(QuicTime::Zero()),
stats_(stats) {
Reset();
}
void Cubic::Reset() {
epoch_ = QuicTime::Zero();
last_update_time_ = QuicTime::Zero();
last_congestion_window_ = 0;
last_max_congestion_window_ = 0;
acked_packets_count_ = 0;
estimated_tcp_congestion_window_ = 0;
origin_point_congestion_window_ = 0;
time_to_origin_point_ = 0;
last_target_congestion_window_ = 0;
}
void Cubic::UpdateCongestionControlStats(
QuicTcpCongestionWindow new_cubic_mode_cwnd,
QuicTcpCongestionWindow new_reno_mode_cwnd) {
QuicTcpCongestionWindow highest_new_cwnd = std::max(new_cubic_mode_cwnd,
new_reno_mode_cwnd);
if (last_congestion_window_ < highest_new_cwnd) {
stats_->cwnd_increase_congestion_avoidance +=
highest_new_cwnd - last_congestion_window_;
if (new_cubic_mode_cwnd > new_reno_mode_cwnd) {
stats_->cwnd_increase_cubic_mode +=
new_cubic_mode_cwnd - last_congestion_window_;
}
}
}
QuicTcpCongestionWindow Cubic::CongestionWindowAfterPacketLoss(
QuicTcpCongestionWindow current_congestion_window) {
if (current_congestion_window < last_max_congestion_window_) {
last_max_congestion_window_ =
static_cast<int>(kBetaLastMax * current_congestion_window);
} else {
last_max_congestion_window_ = current_congestion_window;
}
epoch_ = QuicTime::Zero();
return static_cast<int>(current_congestion_window * kNConnectionBeta);
}
QuicTcpCongestionWindow Cubic::CongestionWindowAfterAck(
QuicTcpCongestionWindow current_congestion_window,
QuicTime::Delta delay_min) {
acked_packets_count_ += 1;
QuicTime current_time = clock_->ApproximateNow();
if (last_congestion_window_ == current_congestion_window &&
(current_time.Subtract(last_update_time_) <= MaxCubicTimeInterval())) {
return max(last_target_congestion_window_,
estimated_tcp_congestion_window_);
}
last_congestion_window_ = current_congestion_window;
last_update_time_ = current_time;
if (!epoch_.IsInitialized()) {
DVLOG(1) << "Start of epoch";
epoch_ = current_time;
acked_packets_count_ = 1;
estimated_tcp_congestion_window_ = current_congestion_window;
if (last_max_congestion_window_ <= current_congestion_window) {
time_to_origin_point_ = 0;
origin_point_congestion_window_ = current_congestion_window;
} else {
time_to_origin_point_ = CubeRoot::Root(kCubeFactor *
(last_max_congestion_window_ - current_congestion_window));
origin_point_congestion_window_ =
last_max_congestion_window_;
}
}
int64 elapsed_time =
(current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) /
base::Time::kMicrosecondsPerSecond;
int64 offset = time_to_origin_point_ - elapsed_time;
QuicTcpCongestionWindow delta_congestion_window = (kCubeCongestionWindowScale
* offset * offset * offset) >> kCubeScale;
QuicTcpCongestionWindow target_congestion_window =
origin_point_congestion_window_ - delta_congestion_window;
DCHECK_LT(0u, estimated_tcp_congestion_window_);
while (true) {
uint32 required_ack_count =
estimated_tcp_congestion_window_ / kNConnectionAlpha;
if (acked_packets_count_ < required_ack_count) {
break;
}
acked_packets_count_ -= required_ack_count;
estimated_tcp_congestion_window_++;
}
UpdateCongestionControlStats(target_congestion_window,
estimated_tcp_congestion_window_);
last_target_congestion_window_ = target_congestion_window;
if (target_congestion_window < estimated_tcp_congestion_window_) {
target_congestion_window = estimated_tcp_congestion_window_;
}
DVLOG(1) << "Target congestion_window: " << target_congestion_window;
return target_congestion_window;
}
}