Commit 497bfb2b authored by rch@chromium.org's avatar rch@chromium.org

Various QUIC cleanups to sync with internal code.

Review URL: https://codereview.chromium.org/125403006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243462 0039d316-1c4b-4281-b951-d872f2087c98
parent ee985fd7
......@@ -9,9 +9,14 @@
#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 {
// Constants based on TCP defaults.
// The following constants are in 2^10 fractions of a second instead of ms to
// allow a 10 shift right to divide.
......@@ -25,52 +30,6 @@ const uint32 kBetaSPDY = 939; // Back off factor after loss for SPDY, reduces
// the CWND by 1/12th.
const uint32 kBetaLastMax = 871; // Additional back off factor after loss for
// the stored max value.
namespace {
// Find last bit in a 64-bit word.
int FindMostSignificantBit(uint64 x) {
if (!x) {
return 0;
}
int r = 0;
if (x & 0xffffffff00000000ull) {
x >>= 32;
r += 32;
}
if (x & 0xffff0000u) {
x >>= 16;
r += 16;
}
if (x & 0xff00u) {
x >>= 8;
r += 8;
}
if (x & 0xf0u) {
x >>= 4;
r += 4;
}
if (x & 0xcu) {
x >>= 2;
r += 2;
}
if (x & 0x02u) {
x >>= 1;
r++;
}
if (x & 0x01u) {
r++;
}
return r;
}
// 6 bits table [0..63]
const uint32 cube_root_table[] = {
0, 54, 54, 54, 118, 118, 118, 118, 123, 129, 134, 138, 143, 147, 151,
156, 157, 161, 164, 168, 170, 173, 176, 179, 181, 185, 187, 190, 192, 194,
197, 199, 200, 202, 204, 206, 209, 211, 213, 215, 217, 219, 221, 222, 224,
225, 227, 229, 231, 232, 234, 236, 237, 239, 240, 242, 244, 245, 246, 248,
250, 251, 252, 254
};
} // namespace
Cubic::Cubic(const QuicClock* clock)
......@@ -80,34 +39,6 @@ Cubic::Cubic(const QuicClock* clock)
Reset();
}
// Calculate the cube root using a table lookup followed by one Newton-Raphson
// iteration.
uint32 Cubic::CubeRoot(uint64 a) {
uint32 msb = FindMostSignificantBit(a);
DCHECK_LE(msb, 64u);
if (msb < 7) {
// MSB in our table.
return ((cube_root_table[static_cast<uint32>(a)]) + 31) >> 6;
}
// MSB 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ...
// cubic_shift 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, ...
uint32 cubic_shift = (msb - 4);
cubic_shift = ((cubic_shift * 342) >> 10); // Div by 3, biased high.
// 4 to 6 bits accuracy depending on MSB.
uint32 down_shifted_to_6bit = (a >> (cubic_shift * 3));
uint64 root = ((cube_root_table[down_shifted_to_6bit] + 10) << cubic_shift)
>> 6;
// Make one Newton-Raphson iteration.
// Since x has an error (inaccuracy due to the use of fix point) we get a
// more accurate result by doing x * (x - 1) instead of x * x.
root = 2 * root + (a / (root * (root - 1)));
root = ((root * 341) >> 10); // Div by 3, biased low.
return static_cast<uint32>(root);
}
void Cubic::Reset() {
epoch_ = QuicTime::Zero(); // Reset time.
last_update_time_ = QuicTime::Zero(); // Reset time.
......@@ -143,8 +74,8 @@ QuicTcpCongestionWindow Cubic::CongestionWindowAfterAck(
// Cubic is "independent" of RTT, the update is limited by the time elapsed.
if (last_congestion_window_ == current_congestion_window &&
(current_time.Subtract(last_update_time_) <= MaxCubicTimeInterval())) {
return std::max(last_target_congestion_window_,
estimated_tcp_congestion_window_);
return max(last_target_congestion_window_,
estimated_tcp_congestion_window_);
}
last_congestion_window_ = current_congestion_window;
last_update_time_ = current_time;
......@@ -160,7 +91,7 @@ QuicTcpCongestionWindow Cubic::CongestionWindowAfterAck(
time_to_origin_point_ = 0;
origin_point_congestion_window_ = current_congestion_window;
} else {
time_to_origin_point_ = CubeRoot(kCubeFactor *
time_to_origin_point_ = CubeRoot::Root(kCubeFactor *
(last_max_congestion_window_ - current_congestion_window));
origin_point_congestion_window_ =
last_max_congestion_window_;
......
......@@ -39,11 +39,6 @@ class NET_EXPORT_PRIVATE Cubic {
QuicTcpCongestionWindow current,
QuicTime::Delta delay_min);
protected:
// Calculates the cubic root using a table lookup followed by one Newton-
// Raphson iteration.
uint32 CubeRoot(uint64 a);
private:
static const QuicTime::Delta MaxCubicTimeInterval() {
return QuicTime::Delta::FromMilliseconds(30);
......@@ -84,4 +79,5 @@ class NET_EXPORT_PRIVATE Cubic {
};
} // namespace net
#endif // NET_QUIC_CONGESTION_CONTROL_CUBIC_H_
......@@ -4,7 +4,6 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "net/quic/congestion_control/cubic.h"
#include "net/quic/test_tools/mock_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -12,57 +11,19 @@
namespace net {
namespace test {
class CubicPeer : public Cubic {
public:
explicit CubicPeer(QuicClock* clock)
: Cubic(clock) {
}
using Cubic::CubeRoot;
};
class CubicTest : public ::testing::Test {
protected:
CubicTest()
: one_ms_(QuicTime::Delta::FromMilliseconds(1)),
hundred_ms_(QuicTime::Delta::FromMilliseconds(100)) {
}
virtual void SetUp() {
cubic_.reset(new CubicPeer(&clock_));
hundred_ms_(QuicTime::Delta::FromMilliseconds(100)),
cubic_(&clock_) {
}
const QuicTime::Delta one_ms_;
const QuicTime::Delta hundred_ms_;
MockClock clock_;
scoped_ptr<CubicPeer> cubic_;
Cubic cubic_;
};
TEST_F(CubicTest, CubeRootLow) {
for (uint32 i = 1; i < 256; ++i) {
uint64 cube = i * i * i;
uint8 cube_root = cubic_->CubeRoot(cube);
EXPECT_EQ(i, cube_root);
}
}
TEST_F(CubicTest, CubeRootHigh) {
// Test the range we will opperate in, 1300 to 130 000.
// We expect some loss in accuracy, accepting +-0.2%.
for (uint64 i = 1300; i < 20000; i += 100) {
uint64 cube = i * i * i;
uint32 cube_root = cubic_->CubeRoot(cube);
uint32 margin = cube_root >> 9; // Calculate 0.2% roughly by
// dividing by 512.
EXPECT_LE(i - margin, cube_root);
EXPECT_GE(i + margin, cube_root);
}
for (uint64 i = 20000; i < 130000; i *= 2) {
uint64 cube = i * i * i;
uint32 cube_root = cubic_->CubeRoot(cube);
uint32 margin = cube_root >> 9;
EXPECT_LE(i - margin, cube_root);
EXPECT_GE(i + margin, cube_root);
}
}
TEST_F(CubicTest, AboveOrgin) {
// Convex growth.
const QuicTime::Delta rtt_min = hundred_ms_;
......@@ -71,17 +32,17 @@ TEST_F(CubicTest, AboveOrgin) {
// Initialize the state.
clock_.AdvanceTime(one_ms_);
EXPECT_EQ(expected_cwnd,
cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min));
cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
current_cwnd = expected_cwnd;
// Normal TCP phase.
for (int i = 0; i < 48; ++i) {
for (uint32 n = 1; n < current_cwnd; ++n) {
// Call once per ACK.
EXPECT_EQ(current_cwnd,
cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min));
cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
}
clock_.AdvanceTime(hundred_ms_);
current_cwnd = cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min);
current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
EXPECT_EQ(expected_cwnd, current_cwnd);
expected_cwnd++;
}
......@@ -90,10 +51,10 @@ TEST_F(CubicTest, AboveOrgin) {
for (uint32 n = 1; n < current_cwnd; ++n) {
// Call once per ACK.
EXPECT_EQ(current_cwnd,
cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min));
cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
}
clock_.AdvanceTime(hundred_ms_);
current_cwnd = cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min);
current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
}
float elapsed_time_s = 10.0f + 0.1f; // We need to add the RTT here.
expected_cwnd = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410)
......@@ -108,13 +69,13 @@ TEST_F(CubicTest, LossEvents) {
// Initialize the state.
clock_.AdvanceTime(one_ms_);
EXPECT_EQ(expected_cwnd,
cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min));
cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
expected_cwnd = current_cwnd * 939 / 1024;
EXPECT_EQ(expected_cwnd,
cubic_->CongestionWindowAfterPacketLoss(current_cwnd));
cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
expected_cwnd = current_cwnd * 939 / 1024;
EXPECT_EQ(expected_cwnd,
cubic_->CongestionWindowAfterPacketLoss(current_cwnd));
cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
}
TEST_F(CubicTest, BelowOrgin) {
......@@ -125,26 +86,26 @@ TEST_F(CubicTest, BelowOrgin) {
// Initialize the state.
clock_.AdvanceTime(one_ms_);
EXPECT_EQ(expected_cwnd,
cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min));
cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
expected_cwnd = current_cwnd * 939 / 1024;
EXPECT_EQ(expected_cwnd,
cubic_->CongestionWindowAfterPacketLoss(current_cwnd));
cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
current_cwnd = expected_cwnd;
// First update after epoch.
current_cwnd = cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min);
current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
// Cubic phase.
for (int i = 0; i < 54; ++i) {
for (uint32 n = 1; n < current_cwnd; ++n) {
// Call once per ACK.
EXPECT_EQ(current_cwnd,
cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min));
cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
}
clock_.AdvanceTime(hundred_ms_);
current_cwnd = cubic_->CongestionWindowAfterAck(current_cwnd, rtt_min);
current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
}
expected_cwnd = 440;
EXPECT_EQ(expected_cwnd, current_cwnd);
}
} // namespace testing
} // namespace test
} // namespace net
......@@ -11,6 +11,8 @@
#include "base/logging.h"
#include "net/quic/quic_protocol.h"
using std::max;
namespace {
const int kInitialBitrate = 100000; // In bytes per second.
const uint64 kWindowSizeUs = 10000; // 10 ms.
......@@ -118,7 +120,7 @@ QuicByteCount FixRateSender::CongestionWindow() {
QuicByteCount window_size_bytes = bitrate_.ToBytesPerPeriod(
QuicTime::Delta::FromMicroseconds(kWindowSizeUs));
// Make sure window size is not less than a packet.
return std::max(kDefaultMaxPacketSize, window_size_bytes);
return max(kDefaultMaxPacketSize, window_size_bytes);
}
QuicBandwidth FixRateSender::BandwidthEstimate() const {
......
......@@ -6,6 +6,9 @@
#include <algorithm>
using std::max;
using std::min;
namespace net {
// Note(pwestin): the magic clamping numbers come from the original code in
......@@ -86,10 +89,10 @@ void HybridSlowStart::Update(QuicTime::Delta rtt, QuicTime::Delta delay_min) {
if (sample_count_ == kHybridStartMinSamples) {
int accepted_variance_us = delay_min.ToMicroseconds() >>
kHybridStartDelayFactorExp;
accepted_variance_us = std::min(accepted_variance_us,
kHybridStartDelayMaxThresholdUs);
accepted_variance_us = min(accepted_variance_us,
kHybridStartDelayMaxThresholdUs);
QuicTime::Delta accepted_variance = QuicTime::Delta::FromMicroseconds(
std::max(accepted_variance_us, kHybridStartDelayMinThresholdUs));
max(accepted_variance_us, kHybridStartDelayMinThresholdUs));
if (current_rtt_ > delay_min.Add(accepted_variance)) {
found_delay_ = true;
......
......@@ -4,8 +4,6 @@
#include "net/quic/congestion_control/inter_arrival_bitrate_ramp_up.h"
#include <algorithm>
#include "base/basictypes.h"
#include "base/logging.h"
#include "net/quic/congestion_control/cube_root.h"
......
......@@ -62,4 +62,5 @@ class NET_EXPORT_PRIVATE InterArrivalBitrateRampUp {
};
} // namespace net
#endif // NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_BITRATE_RAMP_UP_H_
......@@ -10,6 +10,8 @@
#include "net/quic/test_tools/mock_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
using std::min;
namespace net {
namespace test {
......@@ -116,14 +118,14 @@ TEST_F(InterArrivalBitrateRampUpTest, GoodEstimatesLimitedSendRate) {
for (int i = 0; i < 25; ++i) {
clock_.AdvanceTime(hundred_ms_);
// Cap our previus sent rate.
sent_bitrate = std::min(sent_bitrate, max_sent_rate);
sent_bitrate = min(sent_bitrate, max_sent_rate);
sent_bitrate = bitrate_ramp_up_.GetNewBitrate(sent_bitrate);
EXPECT_GE(available_channel_estimate, sent_bitrate);
EXPECT_LE(start_rate, sent_bitrate);
}
clock_.AdvanceTime(hundred_ms_);
// Cap our previus sent rate.
sent_bitrate = std::min(sent_bitrate, max_sent_rate);
sent_bitrate = min(sent_bitrate, max_sent_rate);
sent_bitrate = bitrate_ramp_up_.GetNewBitrate(sent_bitrate);
EXPECT_LE(available_channel_estimate, sent_bitrate);
......@@ -131,13 +133,13 @@ TEST_F(InterArrivalBitrateRampUpTest, GoodEstimatesLimitedSendRate) {
for (int j = 0; j < 25; ++j) {
clock_.AdvanceTime(hundred_ms_);
// Cap our previus sent rate.
sent_bitrate = std::min(sent_bitrate, max_sent_rate);
sent_bitrate = min(sent_bitrate, max_sent_rate);
sent_bitrate = bitrate_ramp_up_.GetNewBitrate(sent_bitrate);
EXPECT_LE(available_channel_estimate, sent_bitrate);
EXPECT_GE(halfway_point, sent_bitrate);
}
clock_.AdvanceTime(hundred_ms_);
sent_bitrate = std::min(sent_bitrate, max_sent_rate);
sent_bitrate = min(sent_bitrate, max_sent_rate);
sent_bitrate = bitrate_ramp_up_.GetNewBitrate(sent_bitrate);
// We expect 2 * sent_bitrate to cap the rate.
EXPECT_LE(max_sent_rate.Add(max_sent_rate), sent_bitrate);
......
......@@ -269,7 +269,7 @@ TEST_F(InterArrivalOveruseDetectorTest, DISABLED_TestNoise) {
count[GaussianRandom(mean, standard_deviation).ToMilliseconds()]++;
}
for (int j = 0; j < 100; ++j) {
DLOG(INFO) << j << ":" << count[j];
DVLOG(1) << j << ":" << count[j];
}
}
......
......@@ -4,18 +4,22 @@
#include "net/quic/congestion_control/inter_arrival_probe.h"
#include <algorithm>
#include "base/basictypes.h"
#include "base/logging.h"
using std::max;
namespace net {
namespace {
const int kProbeSizePackets = 10;
const net::QuicByteCount kMinPacketSize = 500;
const QuicByteCount kMinPacketSize = 500;
const int64 kDefaultBytesPerSecond = 40000;
const float kUncertainScaleFactor = 0.5; // TODO(pwestin): revisit this factor.
}
namespace net {
InterArrivalProbe::InterArrivalProbe(QuicByteCount max_segment_size)
: max_segment_size_(max_segment_size),
estimate_available_(false),
......@@ -108,8 +112,8 @@ void InterArrivalProbe::OnIncomingFeedback(
break;
case kAvailableChannelEstimateSenderLimited:
available_channel_estimate_ =
std::max(available_channel_estimate,
QuicBandwidth::FromBytesPerSecond(kDefaultBytesPerSecond));
max(available_channel_estimate,
QuicBandwidth::FromBytesPerSecond(kDefaultBytesPerSecond));
break;
}
estimate_available_ = true;
......
......@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/congestion_control/inter_arrival_probe.h"
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "net/quic/congestion_control/inter_arrival_probe.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
......
......@@ -4,6 +4,11 @@
#include "net/quic/congestion_control/inter_arrival_sender.h"
#include <algorithm>
using std::max;
using std::min;
namespace net {
namespace {
......@@ -192,8 +197,8 @@ bool InterArrivalSender::ProbingPhase(QuicTime feedback_receive_time) {
// Do nothing.
break;
}
new_rate = std::max(new_rate,
QuicBandwidth::FromKBitsPerSecond(kMinBitrateKbit));
new_rate = max(new_rate,
QuicBandwidth::FromKBitsPerSecond(kMinBitrateKbit));
bitrate_ramp_up_->Reset(new_rate, available_channel_estimate,
channel_estimate);
......@@ -407,9 +412,9 @@ void InterArrivalSender::EstimateNewBandwidthAfterDraining(
} else {
// Use our drain rate and our kMinBitrateReduction to go to our
// new estimate.
new_estimate = std::max(current_bandwidth_,
current_bandwidth_.Add(draining_rate).Scale(
1.0f - kMinBitrateReduction));
new_estimate = max(current_bandwidth_,
current_bandwidth_.Add(draining_rate).Scale(
1.0f - kMinBitrateReduction));
DVLOG(1) << "Draining calculation; current rate:"
<< current_bandwidth_.ToKBitsPerSecond() << " Kbits/s "
<< "draining rate:"
......@@ -465,8 +470,8 @@ void InterArrivalSender::EstimateBandwidthAfterDelayEvent(
float decrease_factor =
draining_rate_per_rtt / current_bandwidth_.ToBytesPerSecond();
decrease_factor = std::max(decrease_factor, kMinBitrateReduction);
decrease_factor = std::min(decrease_factor, kMaxBitrateReduction);
decrease_factor = max(decrease_factor, kMinBitrateReduction);
decrease_factor = min(decrease_factor, kMaxBitrateReduction);
back_down_congestion_delay_ = estimated_congestion_delay;
QuicBandwidth new_target_bitrate =
current_bandwidth_.Scale(1.0f - decrease_factor);
......@@ -474,7 +479,7 @@ void InterArrivalSender::EstimateBandwidthAfterDelayEvent(
// While in delay sensing mode send at least one packet per RTT.
QuicBandwidth min_delay_bitrate =
QuicBandwidth::FromBytesAndTimeDelta(max_segment_size_, SmoothedRtt());
new_target_bitrate = std::max(new_target_bitrate, min_delay_bitrate);
new_target_bitrate = max(new_target_bitrate, min_delay_bitrate);
ResetCurrentBandwidth(feedback_receive_time, new_target_bitrate);
......@@ -498,8 +503,8 @@ void InterArrivalSender::EstimateBandwidthAfterLossEvent(
void InterArrivalSender::ResetCurrentBandwidth(QuicTime feedback_receive_time,
QuicBandwidth new_rate) {
new_rate = std::max(new_rate,
QuicBandwidth::FromKBitsPerSecond(kMinBitrateKbit));
new_rate = max(new_rate,
QuicBandwidth::FromKBitsPerSecond(kMinBitrateKbit));
QuicBandwidth channel_estimate = QuicBandwidth::Zero();
ChannelEstimateState channel_estimator_state =
channel_estimator_->GetChannelEstimate(&channel_estimate);
......
......@@ -153,7 +153,7 @@ TEST_F(InterArrivalSenderTest, ProbeFollowedByFullRampUpCycle) {
acc_arrival_time.ToMicroseconds();
EXPECT_NEAR(0.7f * probe_rate,
sender_.BandwidthEstimate().ToBytesPerSecond(), 1000);
DLOG(INFO) << "After probe";
DVLOG(1) << "After probe";
// Send 50 bursts, make sure that we move fast in the beginning.
for (int i = 0; i < 50; ++i) {
SendAvailableCongestionWindow();
......@@ -198,7 +198,7 @@ TEST_F(InterArrivalSenderTest, ProbeFollowedByFullRampUpCycle) {
EXPECT_NEAR(0.99f * probe_rate,
sender_.BandwidthEstimate().ToBytesPerSecond(), 1000);
EXPECT_NEAR(SenderDeltaSinceStart().ToMilliseconds(), 1560, 10);
DLOG(INFO) << "Near available channel estimate";
DVLOG(1) << "Near available channel estimate";
// Send 50 bursts, make sure that we move very slow close to the probe rate.
for (int i = 0; i < 50; ++i) {
......@@ -214,7 +214,7 @@ TEST_F(InterArrivalSenderTest, ProbeFollowedByFullRampUpCycle) {
EXPECT_NEAR(1.00f * probe_rate,
sender_.BandwidthEstimate().ToBytesPerSecond(), 2000);
EXPECT_NEAR(SenderDeltaSinceStart().ToMilliseconds(), 2000, 100);
DLOG(INFO) << "At available channel estimate";
DVLOG(1) << "At available channel estimate";
// Send 50 bursts, make sure that we move very slow close to the probe rate.
for (int i = 0; i < 50; ++i) {
......@@ -280,7 +280,7 @@ TEST_F(InterArrivalSenderTest, ProbeFollowedByFullRampUpCycle) {
EXPECT_NEAR(halfway_rate,
sender_.BandwidthEstimate().ToBytesPerSecond(), 5000);
EXPECT_NEAR(SenderDeltaSinceStart().ToMilliseconds(), 6600, 100);
DLOG(INFO) << "Near halfway point";
DVLOG(1) << "Near halfway point";
// Send until we reach max channel capacity.
for (int i = 0; i < 1500; ++i) {
......
......@@ -13,7 +13,6 @@
#include "base/basictypes.h"
#include "net/base/net_export.h"
#include "net/quic/quic_bandwidth.h"
#include "net/quic/quic_clock.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_time.h"
......
......@@ -17,7 +17,6 @@
#include "base/memory/scoped_ptr.h"
#include "net/quic/congestion_control/send_algorithm_interface.h"
#include "net/quic/quic_bandwidth.h"
#include "net/quic/quic_clock.h"
#include "net/quic/quic_config.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_time.h"
......
......@@ -5,6 +5,7 @@
#include "net/quic/congestion_control/receive_algorithm_interface.h"
#include "net/quic/congestion_control/fix_rate_receiver.h"
#include "net/quic/congestion_control/inter_arrival_receiver.h"
#include "net/quic/congestion_control/tcp_receiver.h"
namespace net {
......@@ -16,7 +17,7 @@ ReceiveAlgorithmInterface* ReceiveAlgorithmInterface::Create(
case kTCP:
return new TcpReceiver();
case kInterArrival:
break; // TODO(pwestin) Implement.
return new InterArrivalReceiver();
case kFixRate:
return new FixRateReceiver();
}
......
......@@ -5,6 +5,7 @@
#include "net/quic/congestion_control/send_algorithm_interface.h"
#include "net/quic/congestion_control/fix_rate_sender.h"
#include "net/quic/congestion_control/inter_arrival_sender.h"
#include "net/quic/congestion_control/tcp_cubic_sender.h"
#include "net/quic/quic_protocol.h"
......@@ -20,7 +21,7 @@ SendAlgorithmInterface* SendAlgorithmInterface::Create(
case kTCP:
return new TcpCubicSender(clock, kUseReno, kMaxTcpCongestionWindow);
case kInterArrival:
break; // TODO(pwestin) Implement.
return new InterArrivalSender(clock);
case kFixRate:
return new FixRateSender(clock);
}
......
......@@ -9,6 +9,7 @@
#include "base/metrics/histogram.h"
using std::max;
using std::min;
namespace net {
......@@ -197,7 +198,7 @@ QuicByteCount TcpCubicSender::AvailableSendWindow() {
QuicByteCount TcpCubicSender::SendWindow() {
// What's the current send window in bytes.
return std::min(receive_window_, GetCongestionWindow());
return min(receive_window_, GetCongestionWindow());
}
QuicBandwidth TcpCubicSender::BandwidthEstimate() const {
......@@ -268,7 +269,7 @@ void TcpCubicSender::CongestionAvoidance(QuicPacketSequenceNumber ack) {
}
DVLOG(1) << "Reno; congestion window:" << congestion_window_;
} else {
congestion_window_ = std::min(
congestion_window_ = min(
max_tcp_congestion_window_,
cubic_.CongestionWindowAfterAck(congestion_window_, delay_min_));
DVLOG(1) << "Cubic; congestion window:" << congestion_window_;
......
......@@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/congestion_control/tcp_cubic_sender.h"
#include <algorithm>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "net/quic/congestion_control/tcp_cubic_sender.h"
#include "net/quic/congestion_control/tcp_receiver.h"
#include "net/quic/test_tools/mock_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
using std::min;
namespace net {
namespace test {
......@@ -50,7 +53,7 @@ class TcpCubicSenderTest : public ::testing::Test {
void SendAvailableSendWindow() {
QuicByteCount bytes_to_send = sender_->AvailableSendWindow();
while (bytes_to_send > 0) {
QuicByteCount bytes_in_packet = std::min(kDefaultTCPMSS, bytes_to_send);
QuicByteCount bytes_in_packet = min(kDefaultTCPMSS, bytes_to_send);
sender_->OnPacketSent(clock_.Now(), sequence_number_++, bytes_in_packet,
NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA);
bytes_to_send -= bytes_in_packet;
......@@ -394,7 +397,7 @@ TEST_F(TcpCubicSenderTest, SendWindowNotAffectedByAcks) {
// Send a packet with no retransmittable data, and ensure that the congestion
// window doesn't change.
QuicByteCount bytes_in_packet = std::min(kDefaultTCPMSS, send_window);
QuicByteCount bytes_in_packet = min(kDefaultTCPMSS, send_window);
sender_->OnPacketSent(clock_.Now(), sequence_number_++, bytes_in_packet,
NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA);
EXPECT_EQ(send_window, sender_->AvailableSendWindow());
......
......@@ -7,8 +7,8 @@
namespace net {
// Originally 64K bytes, but increased it to 256K to support higher bitrates.
// static
// Originally 64K bytes for TCP, setting it to 256K to support higher bitrates.
const QuicByteCount TcpReceiver::kReceiveWindowTCP = 256000;
TcpReceiver::TcpReceiver()
......
......@@ -15,7 +15,6 @@ namespace net {
typedef uint64 QuicByteCount;
class NET_EXPORT_PRIVATE QuicBandwidth {
public:
// Creates a new QuicBandwidth with an internal value of 0.
static QuicBandwidth Zero();
......
......@@ -35,12 +35,7 @@ using std::vector;
using std::set;
using std::string;
int FLAGS_fake_packet_loss_percentage = 0;
// If true, then QUIC connections will bundle acks with any outgoing packet when
// an ack is being delayed. This is an optimization to reduce ack latency and
// packet count of pure ack packets.
bool FLAGS_bundle_ack_with_outgoing_packet = false;
extern bool FLAGS_quic_allow_oversized_packets_for_test;
namespace net {
......@@ -66,7 +61,6 @@ bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) {
return delta <= kMaxPacketGap;
}
// An alarm that is scheduled to send an ack if a timeout occurs.
class AckAlarm : public QuicAlarm::Delegate {
public:
......@@ -137,17 +131,17 @@ class TimeoutAlarm : public QuicAlarm::Delegate {
// Indicates if any of the frames are intended to be sent with FORCE.
// Returns FORCE when one of the frames is a CONNECTION_CLOSE_FRAME.
net::QuicConnection::Force HasForcedFrames(
QuicConnection::Force HasForcedFrames(
const RetransmittableFrames* retransmittable_frames) {
if (!retransmittable_frames) {
return net::QuicConnection::NO_FORCE;
return QuicConnection::NO_FORCE;
}
for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
return net::QuicConnection::FORCE;
return QuicConnection::FORCE;
}
}
return net::QuicConnection::NO_FORCE;
return QuicConnection::NO_FORCE;
}
} // namespace
......@@ -828,7 +822,6 @@ QuicConsumedData QuicConnection::SendStreamData(
void QuicConnection::SendRstStream(QuicStreamId id,
QuicRstStreamErrorCode error) {
DVLOG(1) << "Sending RST_STREAM: " << id << " code: " << error;
// Opportunistically bundle an ack with this outgoing packet.
ScopedPacketBundler ack_bundler(this, true);
packet_generator_.AddControlFrame(
......@@ -1137,7 +1130,8 @@ bool QuicConnection::WritePacket(EncryptionLevel level,
DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl
<< QuicUtils::StringToHexASCIIDump(packet->AsStringPiece());
DCHECK(encrypted->length() <= kMaxPacketSize)
DCHECK(encrypted->length() <= kMaxPacketSize ||
FLAGS_quic_allow_oversized_packets_for_test)
<< "Packet " << sequence_number << " will not be read; too large: "
<< packet->length() << " " << encrypted->length() << " "
<< " forced: " << (forced == FORCE ? "yes" : "no");
......@@ -1592,8 +1586,8 @@ void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) {
bool QuicConnection::CheckForTimeout() {
QuicTime now = clock_->ApproximateNow();
QuicTime time_of_last_packet = std::max(time_of_last_received_packet_,
time_of_last_sent_new_packet_);
QuicTime time_of_last_packet = max(time_of_last_received_packet_,
time_of_last_sent_new_packet_);
// |delta| can be < 0 as |now| is approximate time but |time_of_last_packet|
// is accurate time. However, this should not change the behavior of
......
......@@ -41,9 +41,6 @@
#include "net/quic/quic_sent_entropy_manager.h"
#include "net/quic/quic_sent_packet_manager.h"
NET_EXPORT_PRIVATE extern int FLAGS_fake_packet_loss_percentage;
NET_EXPORT_PRIVATE extern bool FLAGS_bundle_ack_with_outgoing_packet;
namespace net {
class QuicClock;
......
......@@ -27,8 +27,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
extern int FLAGS_fake_packet_loss_percentage;
using base::StringPiece;
using net::tools::QuicInMemoryCache;
using net::tools::test::QuicInMemoryCachePeer;
......@@ -48,7 +46,6 @@ class TestTransactionFactory : public HttpTransactionFactory {
: session_(new HttpNetworkSession(params)) {}
virtual ~TestTransactionFactory() {
FLAGS_fake_packet_loss_percentage = 0;
}
// HttpTransactionFactory methods
......
......@@ -18,6 +18,8 @@ using std::min;
using std::numeric_limits;
using std::string;
bool FLAGS_quic_allow_oversized_packets_for_test = false;
namespace net {
namespace {
......@@ -266,6 +268,8 @@ size_t QuicFramer::GetSerializedFrameLength(
// Note that we may not use every byte of the writer in this case.
DVLOG(1) << "Truncating large frame";
return free_bytes;
} else if (!FLAGS_quic_allow_oversized_packets_for_test) {
return 0;
}
}
return frame_len;
......@@ -1729,7 +1733,7 @@ bool QuicFramer::AppendPacketSequenceNumber(
packet_sequence_number & k6ByteSequenceNumberMask);
break;
default:
NOTREACHED() << "sequence_number_length: " << sequence_number_length;
DCHECK(false) << "sequence_number_length: " << sequence_number_length;
return false;
}
}
......
......@@ -42,6 +42,12 @@ const size_t kGuidOffset = kPublicFlagsSize;
// Index into the version string in the header. (if present).
const size_t kVersionOffset = kGuidOffset + PACKET_8BYTE_GUID;
// Size in bytes of the stream frame fields for an arbitrary StreamID and
// offset and the last frame in a packet.
size_t GetMinStreamFrameSize(QuicVersion version) {
return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
}
// Index into the sequence number offset in the header.
size_t GetSequenceNumberOffset(QuicGuidLength guid_length,
bool include_version) {
......@@ -200,8 +206,8 @@ class TestQuicVisitor : public ::net::QuicFramerVisitorInterface {
}
virtual void OnError(QuicFramer* f) OVERRIDE {
DLOG(INFO) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error())
<< " (" << f->error() << ")";
DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error())
<< " (" << f->error() << ")";
error_count_++;
}
......@@ -222,17 +228,11 @@ class TestQuicVisitor : public ::net::QuicFramerVisitorInterface {
}
virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE {
DLOG(INFO) << "QuicFramer Version Mismatch, version: " << version;
DVLOG(1) << "QuicFramer Version Mismatch, version: " << version;
version_mismatch_++;
return true;
}
virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE {
packet_count_++;
header_.reset(new QuicPacketHeader(header));
return accept_packet_;
}
virtual bool OnUnauthenticatedPublicHeader(
const QuicPacketPublicHeader& header) OVERRIDE {
public_header_.reset(new QuicPacketPublicHeader(header));
......@@ -244,6 +244,12 @@ class TestQuicVisitor : public ::net::QuicFramerVisitorInterface {
return true;
}
virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE {
packet_count_++;
header_.reset(new QuicPacketHeader(header));
return accept_packet_;
}
virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE {
frame_count_++;
stream_frames_.push_back(new QuicStreamFrame(frame));
......@@ -2302,7 +2308,7 @@ TEST_P(QuicFramerTest, PublicResetPacket) {
// Now test framing boundaries
for (size_t i = 0; i < GetPublicResetPacketSize(); ++i) {
string expected_error;
DLOG(INFO) << "iteration: " << i;
DVLOG(1) << "iteration: " << i;
if (i < kGuidOffset) {
expected_error = "Unable to read public flags.";
CheckProcessingFails(packet, i, expected_error,
......@@ -3281,8 +3287,7 @@ TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
}
// TODO(rch) enable after landing the revised truncation CL.
TEST_P(QuicFramerTest, DISABLED_Truncation) {
TEST_P(QuicFramerTest, Truncation) {
QuicPacketHeader header;
header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
header.public_header.reset_flag = false;
......
......@@ -43,6 +43,8 @@ typedef uint32 QuicHeaderId;
// QuicTag is the type of a tag in the wire protocol.
typedef uint32 QuicTag;
typedef std::vector<QuicTag> QuicTagVector;
// TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and
// QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION.
typedef uint32 QuicPriority;
// TODO(rch): Consider Quic specific names for these constants.
......
......@@ -4,6 +4,7 @@
#include "net/quic/reliable_quic_stream.h"
#include "base/logging.h"
#include "net/quic/quic_session.h"
#include "net/quic/quic_spdy_decompressor.h"
#include "net/spdy/write_blocked_list.h"
......
......@@ -511,12 +511,6 @@ size_t GetPacketLengthForOneStream(
sequence_number_length, is_in_fec_group);
}
// Size in bytes of the stream frame fields for an arbitrary StreamID and
// offset and the last frame in a packet.
size_t GetMinStreamFrameSize(QuicVersion version) {
return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
}
TestEntropyCalculator::TestEntropyCalculator() { }
TestEntropyCalculator::~TestEntropyCalculator() { }
......
......@@ -56,10 +56,6 @@ size_t GetPacketLengthForOneStream(
InFecGroup is_in_fec_group,
size_t* payload_length);
// Size in bytes of the stream frame fields for an arbitrary StreamID and
// offset and the last frame in a packet.
size_t GetMinStreamFrameSize(QuicVersion version);
// Returns QuicConfig set to default values.
QuicConfig DefaultQuicConfig();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment