diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-02 06:15:37 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-02 06:15:37 +0000 |
commit | 310d37b979f36c4e36ee002ccab7d819a16a361d (patch) | |
tree | 4d6f03ff46b6dc9347eb46c642cd40bb9abe4abc /net/quic | |
parent | 36caed781a434ccea526e6c8e8debf9038147aff (diff) | |
download | chromium_src-310d37b979f36c4e36ee002ccab7d819a16a361d.zip chromium_src-310d37b979f36c4e36ee002ccab7d819a16a361d.tar.gz chromium_src-310d37b979f36c4e36ee002ccab7d819a16a361d.tar.bz2 |
Land Recent QUIC Changes.
Add case for PING frame in QuicFrame <<.
Merge internal change: 71908470
https://codereview.chromium.org/421963006/
Add methods to the QuicConnectionDebug visitor for tracking various
events which cause a QuicConnection to discard a packet.
Merge internal change: 71871881
https://codereview.chromium.org/421913015/
Change ReliableQuicStream::OnStreamFrame to return void since the method
already closes the connection when there are errors and callers are not
checking the return value
Make QuicStreamSequencer::OnStreamFrame return void instead of bool
since it is already closing the connect or resetting the stream when
there is an error.
Make two QUIC methods return void instead of bool.
Merge internal change: 71870242
https://codereview.chromium.org/420393004/
Create a visitor which can allow using both a trace... visitor and the
existing stats visitor.
Changed QuicConnection's QuicConnectionDebugVisitor to a scoped_ptr.
Merge internal change: 71863508
https://codereview.chromium.org/429453003/
Use 1350 byte QUIC packets by default.
Merge internal change: 71837432
https://codereview.chromium.org/427673005/
Improve debug logging of QUIC crypto handshake.
Merge internal change: 71833151
https://codereview.chromium.org/428803002/
Fix a bug in QuicUnackedPacketMap where an in flight packet could be
removed before being removed from bytes_in_flight.
Merge internal change: 71783653
https://codereview.chromium.org/422123005/
Inline the members of QUIC's ReceivedPacketInfo into QuicAckFrame now
that version 15 is gone.
Merge internal change: 71763611
https://codereview.chromium.org/424003002/
Remove FixRate congestion frame type.
Merge internal change: 71746617
https://codereview.chromium.org/424903002/
Remove QUIC_VERSION_15 now that Chrome Stable supports QUIC_VERSION_16.
Merge internal change: 71718286
https://codereview.chromium.org/413403008/
R=rch@chromium.org
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/420313005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic')
46 files changed, 736 insertions, 1916 deletions
diff --git a/net/quic/congestion_control/fix_rate_receiver.cc b/net/quic/congestion_control/fix_rate_receiver.cc deleted file mode 100644 index a13362f..0000000 --- a/net/quic/congestion_control/fix_rate_receiver.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// 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/fix_rate_receiver.h" - -#include "base/basictypes.h" -#include "net/quic/congestion_control/receive_algorithm_interface.h" - -namespace { - static const int kInitialBitrate = 100000; // In bytes per second. -} - -namespace net { - -FixRateReceiver::FixRateReceiver() - : configured_rate_(QuicBandwidth::FromBytesPerSecond(kInitialBitrate)) { -} - -bool FixRateReceiver::GenerateCongestionFeedback( - QuicCongestionFeedbackFrame* feedback) { - feedback->type = kFixRate; - feedback->fix_rate.bitrate = configured_rate_; - return true; -} - -void FixRateReceiver::RecordIncomingPacket( - QuicByteCount /*bytes*/, - QuicPacketSequenceNumber /*sequence_number*/, - QuicTime /*timestamp*/) { - // Nothing to do for this simple implementation. -} - -} // namespace net diff --git a/net/quic/congestion_control/fix_rate_receiver.h b/net/quic/congestion_control/fix_rate_receiver.h deleted file mode 100644 index 4ed24b9..0000000 --- a/net/quic/congestion_control/fix_rate_receiver.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Fix rate receive side congestion control, used for initial testing. - -#ifndef NET_QUIC_CONGESTION_CONTROL_FIX_RATE_RECEIVER_H_ -#define NET_QUIC_CONGESTION_CONTROL_FIX_RATE_RECEIVER_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "net/base/net_export.h" -#include "net/quic/congestion_control/receive_algorithm_interface.h" -#include "net/quic/quic_bandwidth.h" - -namespace net { - -namespace test { -class FixRateReceiverPeer; -} // namespace test - -class NET_EXPORT_PRIVATE FixRateReceiver : public ReceiveAlgorithmInterface { - public: - FixRateReceiver(); - - // Implements ReceiveAlgorithmInterface. - virtual bool GenerateCongestionFeedback( - QuicCongestionFeedbackFrame* feedback) OVERRIDE; - - // Implements ReceiveAlgorithmInterface. - virtual void RecordIncomingPacket(QuicByteCount bytes, - QuicPacketSequenceNumber sequence_number, - QuicTime timestamp) OVERRIDE; - private: - friend class test::FixRateReceiverPeer; - - QuicBandwidth configured_rate_; - - DISALLOW_COPY_AND_ASSIGN(FixRateReceiver); -}; - -} // namespace net -#endif // NET_QUIC_CONGESTION_CONTROL_FIX_RATE_RECEIVER_H_ diff --git a/net/quic/congestion_control/fix_rate_sender.cc b/net/quic/congestion_control/fix_rate_sender.cc deleted file mode 100644 index 51e16da..0000000 --- a/net/quic/congestion_control/fix_rate_sender.cc +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// 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/fix_rate_sender.h" - -#include <math.h> - -#include <algorithm> - -#include "base/logging.h" -#include "net/quic/congestion_control/rtt_stats.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. -} - -namespace net { - -FixRateSender::FixRateSender(const RttStats* rtt_stats) - : rtt_stats_(rtt_stats), - bitrate_(QuicBandwidth::FromBytesPerSecond(kInitialBitrate)), - max_segment_size_(kDefaultMaxPacketSize), - fix_rate_leaky_bucket_(bitrate_), - 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_); - } - // Silently ignore invalid messages in release mode. -} - -void FixRateSender::OnCongestionEvent(bool rtt_updated, - QuicByteCount bytes_in_flight, - const CongestionMap& acked_packets, - const CongestionMap& lost_packets) { -} - -bool FixRateSender::OnPacketSent( - QuicTime sent_time, - QuicByteCount /*bytes_in_flight*/, - QuicPacketSequenceNumber /*sequence_number*/, - QuicByteCount bytes, - HasRetransmittableData /*has_retransmittable_data*/) { - fix_rate_leaky_bucket_.Add(sent_time, bytes); - - return true; -} - -void FixRateSender::OnRetransmissionTimeout(bool packets_retransmitted) {} - -void FixRateSender::RevertRetransmissionTimeout() {} - -QuicTime::Delta FixRateSender::TimeUntilSend( - QuicTime now, - QuicByteCount /*bytes_in_flight*/, - HasRetransmittableData /*has_retransmittable_data*/) const { - return fix_rate_leaky_bucket_.TimeRemaining(now); -} - -QuicByteCount FixRateSender::CongestionWindow() const { - QuicByteCount window_size_bytes = bitrate_.ToBytesPerPeriod( - QuicTime::Delta::FromMicroseconds(kWindowSizeUs)); - // Make sure window size is not less than a packet. - return max(kDefaultMaxPacketSize, window_size_bytes); -} - -QuicBandwidth FixRateSender::BandwidthEstimate() const { - return bitrate_; -} - -bool FixRateSender::HasReliableBandwidthEstimate() const { - return true; -} - -QuicTime::Delta FixRateSender::RetransmissionDelay() const { - // TODO(pwestin): Calculate and return retransmission delay. - // Use 2 * the latest RTT for now. - return latest_rtt_.Add(latest_rtt_); -} - -QuicByteCount FixRateSender::GetCongestionWindow() const { - return 0; -} - -bool FixRateSender::InSlowStart() const { - return false; -} - -QuicByteCount FixRateSender::GetSlowStartThreshold() const { - return 0; -} - -CongestionControlType FixRateSender::GetCongestionControlType() const { - return kFixRateCongestionControl; -} - -} // namespace net diff --git a/net/quic/congestion_control/fix_rate_sender.h b/net/quic/congestion_control/fix_rate_sender.h deleted file mode 100644 index eb6d4b6..0000000 --- a/net/quic/congestion_control/fix_rate_sender.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Fix rate send side congestion control, used for testing. - -#ifndef NET_QUIC_CONGESTION_CONTROL_FIX_RATE_SENDER_H_ -#define NET_QUIC_CONGESTION_CONTROL_FIX_RATE_SENDER_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "net/base/net_export.h" -#include "net/quic/quic_clock.h" -#include "net/quic/quic_connection_stats.h" -#include "net/quic/quic_time.h" -#include "net/quic/congestion_control/leaky_bucket.h" -#include "net/quic/congestion_control/send_algorithm_interface.h" - -namespace net { - -class RttStats; - -class NET_EXPORT_PRIVATE FixRateSender : public SendAlgorithmInterface { - public: - explicit FixRateSender(const RttStats* rtt_stats); - virtual ~FixRateSender(); - - // Start implementation of SendAlgorithmInterface. - virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE; - virtual void OnIncomingQuicCongestionFeedbackFrame( - const QuicCongestionFeedbackFrame& feedback, - QuicTime feedback_receive_time) OVERRIDE; - virtual void OnCongestionEvent(bool rtt_updated, - QuicByteCount bytes_in_flight, - const CongestionMap& acked_packets, - const CongestionMap& lost_packets) OVERRIDE; - virtual bool OnPacketSent( - QuicTime sent_time, - QuicByteCount bytes_in_flight, - QuicPacketSequenceNumber sequence_number, - QuicByteCount bytes, - HasRetransmittableData has_retransmittable_data) OVERRIDE; - virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE; - virtual void RevertRetransmissionTimeout() OVERRIDE; - virtual QuicTime::Delta TimeUntilSend( - QuicTime now, - QuicByteCount bytes_in_flight, - HasRetransmittableData has_retransmittable_data) const OVERRIDE; - virtual QuicBandwidth BandwidthEstimate() const OVERRIDE; - virtual bool HasReliableBandwidthEstimate() const OVERRIDE; - virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE; - virtual QuicByteCount GetCongestionWindow() const OVERRIDE; - virtual bool InSlowStart() const OVERRIDE; - virtual QuicByteCount GetSlowStartThreshold() const OVERRIDE; - virtual CongestionControlType GetCongestionControlType() const OVERRIDE; - // End implementation of SendAlgorithmInterface. - - private: - QuicByteCount CongestionWindow() const; - - const RttStats* rtt_stats_; - QuicBandwidth bitrate_; - QuicByteCount max_segment_size_; - LeakyBucket fix_rate_leaky_bucket_; - QuicTime::Delta latest_rtt_; - - DISALLOW_COPY_AND_ASSIGN(FixRateSender); -}; - -} // namespace net - -#endif // NET_QUIC_CONGESTION_CONTROL_FIX_RATE_SENDER_H_ diff --git a/net/quic/congestion_control/fix_rate_test.cc b/net/quic/congestion_control/fix_rate_test.cc deleted file mode 100644 index c82bb60..0000000 --- a/net/quic/congestion_control/fix_rate_test.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Test for FixRate sender and receiver. - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "net/quic/congestion_control/fix_rate_receiver.h" -#include "net/quic/congestion_control/fix_rate_sender.h" -#include "net/quic/congestion_control/rtt_stats.h" -#include "net/quic/quic_protocol.h" -#include "net/quic/test_tools/mock_clock.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace net { -namespace test { - -// bytes_in_flight is unused by FixRateSender's OnPacketSent. -QuicByteCount kUnused = 0; - -class FixRateReceiverPeer : public FixRateReceiver { - public: - FixRateReceiverPeer() - : FixRateReceiver() { - } - void SetBitrate(QuicBandwidth fix_rate) { - FixRateReceiver::configured_rate_ = fix_rate; - } -}; - -class FixRateTest : public ::testing::Test { - protected: - FixRateTest() - : sender_(new FixRateSender(&rtt_stats_)), - receiver_(new FixRateReceiverPeer()), - start_(clock_.Now()) { - // Make sure clock does not start at 0. - clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); - } - RttStats rtt_stats_; - MockClock clock_; - scoped_ptr<FixRateSender> sender_; - scoped_ptr<FixRateReceiverPeer> receiver_; - const QuicTime start_; -}; - -TEST_F(FixRateTest, ReceiverAPI) { - QuicCongestionFeedbackFrame feedback; - QuicTime timestamp(QuicTime::Zero()); - receiver_->SetBitrate(QuicBandwidth::FromKBytesPerSecond(300)); - receiver_->RecordIncomingPacket(1, 1, timestamp); - ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); - EXPECT_EQ(kFixRate, feedback.type); - EXPECT_EQ(300000u, feedback.fix_rate.bitrate.ToBytesPerSecond()); -} - -TEST_F(FixRateTest, SenderAPI) { - QuicCongestionFeedbackFrame feedback; - feedback.type = kFixRate; - feedback.fix_rate.bitrate = QuicBandwidth::FromKBytesPerSecond(300); - sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now()); - EXPECT_EQ(300000, sender_->BandwidthEstimate().ToBytesPerSecond()); - EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), - 0, - HAS_RETRANSMITTABLE_DATA).IsZero()); - - sender_->OnPacketSent(clock_.Now(), kUnused, 1, kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA); - EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA).IsZero()); - clock_.AdvanceTime(sender_->TimeUntilSend(clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA)); - EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA).IsZero()); - sender_->OnPacketSent(clock_.Now(), kUnused, 2, kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA); - EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA).IsZero()); - // Advance the time twice as much and expect only one packet to be sent. - clock_.AdvanceTime(sender_->TimeUntilSend( - clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA).Multiply(2)); - EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA).IsZero()); - sender_->OnPacketSent(clock_.Now(), kUnused, 3, kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA); - EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), - kDefaultMaxPacketSize, - HAS_RETRANSMITTABLE_DATA).IsZero()); -} - -} // namespace test -} // namespace net diff --git a/net/quic/congestion_control/receive_algorithm_interface.cc b/net/quic/congestion_control/receive_algorithm_interface.cc index f5672f8..8d1a39c 100644 --- a/net/quic/congestion_control/receive_algorithm_interface.cc +++ b/net/quic/congestion_control/receive_algorithm_interface.cc @@ -4,7 +4,6 @@ #include "net/quic/congestion_control/receive_algorithm_interface.h" -#include "net/quic/congestion_control/fix_rate_receiver.h" #include "net/quic/congestion_control/tcp_receiver.h" namespace net { @@ -18,8 +17,6 @@ ReceiveAlgorithmInterface* ReceiveAlgorithmInterface::Create( case kInterArrival: LOG(DFATAL) << "InterArrivalSendAlgorithm no longer supported."; return NULL; - case kFixRate: - return new FixRateReceiver(); } return NULL; } diff --git a/net/quic/congestion_control/send_algorithm_interface.cc b/net/quic/congestion_control/send_algorithm_interface.cc index 5d0e032..784768a 100644 --- a/net/quic/congestion_control/send_algorithm_interface.cc +++ b/net/quic/congestion_control/send_algorithm_interface.cc @@ -4,7 +4,6 @@ #include "net/quic/congestion_control/send_algorithm_interface.h" -#include "net/quic/congestion_control/fix_rate_sender.h" #include "net/quic/congestion_control/tcp_cubic_sender.h" #include "net/quic/quic_protocol.h" @@ -27,8 +26,6 @@ SendAlgorithmInterface* SendAlgorithmInterface::Create( return new TcpCubicSender(clock, rtt_stats, true /* use Reno */, kMaxTcpCongestionWindow, stats); - case kFixRateCongestionControl: - return new FixRateSender(rtt_stats); case kBBR: LOG(DFATAL) << "BbrTcpSender is not supported."; return NULL; diff --git a/net/quic/quic_client_session.cc b/net/quic/quic_client_session.cc index b559521..2674013 100644 --- a/net/quic/quic_client_session.cc +++ b/net/quic/quic_client_session.cc @@ -156,7 +156,7 @@ QuicClientSession::QuicClientSession( num_total_streams_(0), task_runner_(task_runner), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), - logger_(net_log_), + logger_(new QuicConnectionLogger(net_log_)), num_packets_read_(0), going_away_(false), weak_factory_(this) { @@ -168,7 +168,7 @@ QuicClientSession::QuicClientSession( new ProofVerifyContextChromium(net_log_), crypto_config)); - connection->set_debug_visitor(&logger_); + connection->set_debug_visitor(logger_); // TODO(rch): pass in full host port proxy pair net_log_.BeginEvent( NetLog::TYPE_QUIC_SESSION, @@ -521,7 +521,7 @@ QuicDataStream* QuicClientSession::CreateIncomingDataStream( void QuicClientSession::CloseStream(QuicStreamId stream_id) { ReliableQuicStream* stream = GetStream(stream_id); if (stream) { - logger_.UpdateReceivedFrameCounts( + logger_->UpdateReceivedFrameCounts( stream_id, stream->num_frames_received(), stream->num_duplicate_frames_received()); } @@ -577,18 +577,18 @@ void QuicClientSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { void QuicClientSession::OnCryptoHandshakeMessageSent( const CryptoHandshakeMessage& message) { - logger_.OnCryptoHandshakeMessageSent(message); + logger_->OnCryptoHandshakeMessageSent(message); } void QuicClientSession::OnCryptoHandshakeMessageReceived( const CryptoHandshakeMessage& message) { - logger_.OnCryptoHandshakeMessageReceived(message); + logger_->OnCryptoHandshakeMessageReceived(message); } void QuicClientSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) { DCHECK(!connection()->connected()); - logger_.OnConnectionClosed(error, from_peer); + logger_->OnConnectionClosed(error, from_peer); if (from_peer) { UMA_HISTOGRAM_SPARSE_SLOWLY( "Net.QuicSession.ConnectionCloseErrorCodeServer", error); @@ -643,7 +643,7 @@ void QuicClientSession::OnConnectionClosed(QuicErrorCode error, void QuicClientSession::OnSuccessfulVersionNegotiation( const QuicVersion& version) { - logger_.OnSuccessfulVersionNegotiation(version); + logger_->OnSuccessfulVersionNegotiation(version); QuicSession::OnSuccessfulVersionNegotiation(version); } @@ -673,7 +673,7 @@ void QuicClientSession::OnProofVerifyDetailsAvailable( CertVerifyResult* result_copy = new CertVerifyResult; result_copy->CopyFrom(*cert_verify_result_other); cert_verify_result_.reset(result_copy); - logger_.OnCertificateVerified(*cert_verify_result_); + logger_->OnCertificateVerified(*cert_verify_result_); } void QuicClientSession::StartReading() { diff --git a/net/quic/quic_client_session.h b/net/quic/quic_client_session.h index b46c0ab..a82339c 100644 --- a/net/quic/quic_client_session.h +++ b/net/quic/quic_client_session.h @@ -236,7 +236,7 @@ class NET_EXPORT_PRIVATE QuicClientSession : public QuicClientSessionBase { base::TaskRunner* task_runner_; BoundNetLog net_log_; base::TimeTicks handshake_start_; // Time the handshake was started. - QuicConnectionLogger logger_; + QuicConnectionLogger* logger_; // Owned by |connection_|. // Number of packets read in the current read loop. size_t num_packets_read_; // True when the session is going away, and streams may no longer be created diff --git a/net/quic/quic_config.cc b/net/quic/quic_config.cc index b383230..90579d3 100644 --- a/net/quic/quic_config.cc +++ b/net/quic/quic_config.cc @@ -435,8 +435,8 @@ QuicConfig::QuicConfig() max_time_before_crypto_handshake_(QuicTime::Delta::Zero()), initial_congestion_window_(kSWND, PRESENCE_OPTIONAL), initial_round_trip_time_us_(kIRTT, PRESENCE_OPTIONAL), - // TODO(rjshade): Make this PRESENCE_REQUIRED when QUIC_VERSION_16 and - // QUIC_VERSION_15 are retired. + // TODO(rjshade): Make this PRESENCE_REQUIRED when QUIC_VERSION_16 is + // retired. initial_flow_control_window_bytes_(kIFCW, PRESENCE_OPTIONAL), // TODO(rjshade): Make this PRESENCE_REQUIRED when retiring // QUIC_VERSION_19. diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc index 2a091ca..9594fdd 100644 --- a/net/quic/quic_connection.cc +++ b/net/quic/quic_connection.cc @@ -220,7 +220,6 @@ QuicConnection::QuicConnection(QuicConnectionId connection_id, resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), - debug_visitor_(NULL), packet_generator_(connection_id_, &framer_, random_generator_, this), idle_network_timeout_( QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), @@ -309,7 +308,7 @@ void QuicConnection::OnPacket() { void QuicConnection::OnPublicResetPacket( const QuicPublicResetPacket& packet) { - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnPublicResetPacket(packet); } CloseConnection(QUIC_PUBLIC_RESET, true); @@ -330,7 +329,7 @@ bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) { } DCHECK_NE(version(), received_version); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnProtocolVersionMismatch(received_version); } @@ -381,7 +380,7 @@ void QuicConnection::OnVersionNegotiationPacket( CloseConnection(QUIC_INTERNAL_ERROR, false); return; } - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnVersionNegotiationPacket(packet); } @@ -429,7 +428,7 @@ void QuicConnection::OnDecryptedPacket(EncryptionLevel level) { } bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnPacketHeader(header); } @@ -444,6 +443,10 @@ bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " << header.public_header.connection_id << " instead of " << connection_id_; + if (debug_visitor_.get() != NULL) { + debug_visitor_->OnIncorrectConnectionId( + header.public_header.connection_id); + } return false; } @@ -462,8 +465,9 @@ bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { header.packet_sequence_number)) { DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number << " no longer being waited for. Discarding."; - // TODO(jri): Log reception of duplicate packets or packets the peer has - // told us to stop waiting for. + if (debug_visitor_.get() != NULL) { + debug_visitor_->OnDuplicatePacket(header.packet_sequence_number); + } return false; } @@ -512,7 +516,7 @@ void QuicConnection::OnFecProtectedPayload(StringPiece payload) { bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnStreamFrame(frame); } if (frame.stream_id != kCryptoStreamId && @@ -528,7 +532,7 @@ bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnAckFrame(incoming_ack); } DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; @@ -549,16 +553,12 @@ bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; - received_packet_manager_.UpdatePacketInformationReceivedByPeer( - incoming_ack.received_info); - if (version() <= QUIC_VERSION_15) { - ProcessStopWaitingFrame(incoming_ack.sent_info); - } + received_packet_manager_.UpdatePacketInformationReceivedByPeer(incoming_ack); sent_entropy_manager_.ClearEntropyBefore( received_packet_manager_.least_packet_awaited_by_peer() - 1); - sent_packet_manager_.OnIncomingAck(incoming_ack.received_info, + sent_packet_manager_.OnIncomingAck(incoming_ack, time_of_last_received_packet_); if (sent_packet_manager_.HasPendingRetransmissions()) { WriteIfNotBlocked(); @@ -585,7 +585,7 @@ void QuicConnection::ProcessStopWaitingFrame( bool QuicConnection::OnCongestionFeedbackFrame( const QuicCongestionFeedbackFrame& feedback) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnCongestionFeedbackFrame(feedback); } last_congestion_frames_.push_back(feedback); @@ -606,7 +606,7 @@ bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { return false; } - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnStopWaitingFrame(frame); } @@ -616,70 +616,62 @@ bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnPingFrame(frame); } return true; } bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { - if (incoming_ack.received_info.largest_observed > - packet_generator_.sequence_number()) { + if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" - << incoming_ack.received_info.largest_observed << " vs " + << incoming_ack.largest_observed << " vs " << packet_generator_.sequence_number(); // We got an error for data we have not sent. Error out. return false; } - if (incoming_ack.received_info.largest_observed < + if (incoming_ack.largest_observed < received_packet_manager_.peer_largest_observed_packet()) { DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" - << incoming_ack.received_info.largest_observed << " vs " + << incoming_ack.largest_observed << " vs " << received_packet_manager_.peer_largest_observed_packet(); // A new ack has a diminished largest_observed value. Error out. // If this was an old packet, we wouldn't even have checked. return false; } - if (version() <= QUIC_VERSION_15) { - if (!ValidateStopWaitingFrame(incoming_ack.sent_info)) { - return false; - } - } - - if (!incoming_ack.received_info.missing_packets.empty() && - *incoming_ack.received_info.missing_packets.rbegin() > - incoming_ack.received_info.largest_observed) { + if (!incoming_ack.missing_packets.empty() && + *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) { DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " - << *incoming_ack.received_info.missing_packets.rbegin() + << *incoming_ack.missing_packets.rbegin() << " which is greater than largest observed: " - << incoming_ack.received_info.largest_observed; + << incoming_ack.largest_observed; return false; } - if (!incoming_ack.received_info.missing_packets.empty() && - *incoming_ack.received_info.missing_packets.begin() < + if (!incoming_ack.missing_packets.empty() && + *incoming_ack.missing_packets.begin() < received_packet_manager_.least_packet_awaited_by_peer()) { DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " - << *incoming_ack.received_info.missing_packets.begin() + << *incoming_ack.missing_packets.begin() << " which is smaller than least_packet_awaited_by_peer_: " << received_packet_manager_.least_packet_awaited_by_peer(); return false; } if (!sent_entropy_manager_.IsValidEntropy( - incoming_ack.received_info.largest_observed, - incoming_ack.received_info.missing_packets, - incoming_ack.received_info.entropy_hash)) { + incoming_ack.largest_observed, + incoming_ack.missing_packets, + incoming_ack.entropy_hash)) { DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; return false; } for (SequenceNumberSet::const_iterator iter = - incoming_ack.received_info.revived_packets.begin(); - iter != incoming_ack.received_info.revived_packets.end(); ++iter) { - if (!ContainsKey(incoming_ack.received_info.missing_packets, *iter)) { + incoming_ack.revived_packets.begin(); + iter != incoming_ack.revived_packets.end(); ++iter) { + if (!ContainsKey(incoming_ack.missing_packets, *iter)) { DLOG(ERROR) << ENDPOINT << "Peer specified revived packet which was not missing."; return false; @@ -723,7 +715,7 @@ void QuicConnection::OnFecData(const QuicFecData& fec) { bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnRstStreamFrame(frame); } DVLOG(1) << ENDPOINT << "Stream reset with error " @@ -735,7 +727,7 @@ bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { bool QuicConnection::OnConnectionCloseFrame( const QuicConnectionCloseFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnConnectionCloseFrame(frame); } DVLOG(1) << ENDPOINT << "Connection " << connection_id() @@ -748,7 +740,7 @@ bool QuicConnection::OnConnectionCloseFrame( bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnGoAwayFrame(frame); } DVLOG(1) << ENDPOINT << "Go away received with error " @@ -760,7 +752,7 @@ bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnWindowUpdateFrame(frame); } DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: " @@ -771,7 +763,7 @@ bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { DCHECK(connected_); - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnBlockedFrame(frame); } DVLOG(1) << ENDPOINT << "Blocked frame received for stream: " @@ -904,8 +896,7 @@ void QuicConnection::ClearLastFrames() { QuicAckFrame* QuicConnection::CreateAckFrame() { QuicAckFrame* outgoing_ack = new QuicAckFrame(); received_packet_manager_.UpdateReceivedPacketInfo( - &(outgoing_ack->received_info), clock_->ApproximateNow()); - UpdateStopWaiting(&(outgoing_ack->sent_info)); + outgoing_ack, clock_->ApproximateNow()); DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; return outgoing_ack; } @@ -929,8 +920,7 @@ bool QuicConnection::ShouldLastPacketInstigateAck() const { return true; } - if (!last_ack_frames_.empty() && - last_ack_frames_.back().received_info.is_truncated) { + if (!last_ack_frames_.empty() && last_ack_frames_.back().is_truncated) { return true; } return false; @@ -943,9 +933,8 @@ void QuicConnection::UpdateStopWaitingCount() { // If the peer is still waiting for a packet that we are no longer planning to // send, send an ack to raise the high water mark. - if (!last_ack_frames_.back().received_info.missing_packets.empty() && - GetLeastUnacked() > - *last_ack_frames_.back().received_info.missing_packets.begin()) { + if (!last_ack_frames_.back().missing_packets.empty() && + GetLeastUnacked() > *last_ack_frames_.back().missing_packets.begin()) { ++stop_waiting_count_; } else { stop_waiting_count_ = 0; @@ -1089,7 +1078,7 @@ void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, if (!connected_) { return; } - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnPacketReceived(self_address, peer_address, packet); } last_packet_revived_ = false; @@ -1103,10 +1092,13 @@ void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, if (!framer_.ProcessPacket(packet)) { // If we are unable to decrypt this packet, it might be // because the CHLO or SHLO packet was lost. - if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && - framer_.error() == QUIC_DECRYPTION_FAILURE && - undecryptable_packets_.size() < kMaxUndecryptablePackets) { - QueueUndecryptablePacket(packet); + if (framer_.error() == QUIC_DECRYPTION_FAILURE) { + if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && + undecryptable_packets_.size() < kMaxUndecryptablePackets) { + QueueUndecryptablePacket(packet); + } else if (debug_visitor_.get() != NULL) { + debug_visitor_->OnUndecryptablePacket(); + } } DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " << last_header_.packet_sequence_number; @@ -1261,7 +1253,7 @@ void QuicConnection::WritePendingRetransmissions() { DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number << " as " << serialized_packet.sequence_number; - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnPacketRetransmitted( pending.sequence_number, serialized_packet.sequence_number); } @@ -1410,7 +1402,7 @@ bool QuicConnection::WritePacket(QueuedPacket packet) { if (result.error_code == ERR_IO_PENDING) { DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); } - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { // Pass the write result to the visitor. debug_visitor_->OnPacketSent(sequence_number, packet.encryption_level, @@ -1583,7 +1575,7 @@ void QuicConnection::SendPing() { if (retransmission_alarm_->IsSet()) { return; } - if (version() <= QUIC_VERSION_16) { + if (version() == QUIC_VERSION_16) { // TODO(rch): remove this when we remove version 15 and 16. // This is a horrible hideous hack which we should not support. IOVector data; @@ -1614,8 +1606,7 @@ void QuicConnection::SendAck() { send_feedback = true; } - packet_generator_.SetShouldSendAck(send_feedback, - version() > QUIC_VERSION_15); + packet_generator_.SetShouldSendAck(send_feedback, true); } void QuicConnection::OnRetransmissionTimeout() { @@ -1704,6 +1695,11 @@ void QuicConnection::MaybeProcessUndecryptablePackets() { // new keys installed and hence any undecryptable packets will // never be able to be decrypted. if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { + if (debug_visitor_ != NULL) { + for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { + debug_visitor_->OnUndecryptablePacket(); + } + } STLDeleteElements(&undecryptable_packets_); } } @@ -1732,7 +1728,7 @@ void QuicConnection::MaybeProcessRevivedPacket() { delete group; last_packet_revived_ = true; - if (debug_visitor_) { + if (debug_visitor_.get() != NULL) { debug_visitor_->OnRevivedPacket(revived_header, StringPiece(revived_payload, len)); } diff --git a/net/quic/quic_connection.h b/net/quic/quic_connection.h index a7e8a7e..a98458b 100644 --- a/net/quic/quic_connection.h +++ b/net/quic/quic_connection.h @@ -137,6 +137,17 @@ class NET_EXPORT_PRIVATE QuicConnectionDebugVisitor const IPEndPoint& peer_address, const QuicEncryptedPacket& packet) {} + // Called when a packet is recived with a connection id that does not + // match the ID of this connection. + virtual void OnIncorrectConnectionId( + QuicConnectionId connection_id) {} + + // Called when an undecryptable packet has been received. + virtual void OnUndecryptablePacket() {} + + // Called when a duplicate packet has been received. + virtual void OnDuplicatePacket(QuicPacketSequenceNumber sequence_number) {} + // Called when the protocol version on the received packet doensn't match // current protocol version of the connection. virtual void OnProtocolVersionMismatch(QuicVersion version) {} @@ -357,7 +368,7 @@ class NET_EXPORT_PRIVATE QuicConnection visitor_ = visitor; } void set_debug_visitor(QuicConnectionDebugVisitor* debug_visitor) { - debug_visitor_ = debug_visitor; + debug_visitor_.reset(debug_visitor); packet_generator_.set_debug_delegate(debug_visitor); sent_packet_manager_.set_debug_delegate(debug_visitor); } @@ -719,7 +730,7 @@ class NET_EXPORT_PRIVATE QuicConnection scoped_ptr<QuicAlarm> ping_alarm_; QuicConnectionVisitorInterface* visitor_; - QuicConnectionDebugVisitor* debug_visitor_; + scoped_ptr<QuicConnectionDebugVisitor> debug_visitor_; QuicPacketGenerator packet_generator_; // Network idle time before we kill of this connection. diff --git a/net/quic/quic_connection_logger.cc b/net/quic/quic_connection_logger.cc index 7deb269..8f2163b 100644 --- a/net/quic/quic_connection_logger.cc +++ b/net/quic/quic_connection_logger.cc @@ -104,16 +104,12 @@ base::Value* NetLogQuicStreamFrameCallback(const QuicStreamFrame* frame, base::Value* NetLogQuicAckFrameCallback(const QuicAckFrame* frame, NetLog::LogLevel /* log_level */) { base::DictionaryValue* dict = new base::DictionaryValue(); - base::DictionaryValue* received_info = new base::DictionaryValue(); - dict->Set("received_info", received_info); - received_info->SetString( - "largest_observed", - base::Uint64ToString(frame->received_info.largest_observed)); - received_info->SetBoolean("truncated", frame->received_info.is_truncated); + dict->SetString("largest_observed", + base::Uint64ToString(frame->largest_observed)); + dict->SetBoolean("truncated", frame->is_truncated); base::ListValue* missing = new base::ListValue(); - received_info->Set("missing_packets", missing); - const SequenceNumberSet& missing_packets = - frame->received_info.missing_packets; + dict->Set("missing_packets", missing); + const SequenceNumberSet& missing_packets = frame->missing_packets; for (SequenceNumberSet::const_iterator it = missing_packets.begin(); it != missing_packets.end(); ++it) { missing->AppendString(base::Uint64ToString(*it)); @@ -139,11 +135,6 @@ base::Value* NetLogQuicCongestionFeedbackFrameCallback( } break; } - case kFixRate: - dict->SetString("type", "FixRate"); - dict->SetInteger("bitrate_in_bytes_per_second", - frame->fix_rate.bitrate.ToBytesPerSecond()); - break; case kTCP: dict->SetString("type", "TCP"); dict->SetInteger("receive_window", frame->tcp.receive_window); @@ -383,7 +374,7 @@ void QuicConnectionLogger::OnFrameAddedToPacket(const QuicFrame& frame) { net_log_.AddEvent( NetLog::TYPE_QUIC_SESSION_ACK_FRAME_SENT, base::Bind(&NetLogQuicAckFrameCallback, frame.ack_frame)); - if (frame.ack_frame->received_info.is_truncated) + if (frame.ack_frame->is_truncated) ++num_truncated_acks_sent_; break; case CONGESTION_FEEDBACK_FRAME: @@ -526,13 +517,13 @@ void QuicConnectionLogger::OnAckFrame(const QuicAckFrame& frame) { last_received_packet_size_ < kApproximateLargestSoloAckBytes) received_acks_[last_received_packet_sequence_number_] = true; - if (frame.received_info.is_truncated) + if (frame.is_truncated) ++num_truncated_acks_received_; - if (frame.received_info.missing_packets.empty()) + if (frame.missing_packets.empty()) return; - SequenceNumberSet missing_packets = frame.received_info.missing_packets; + SequenceNumberSet missing_packets = frame.missing_packets; SequenceNumberSet::const_iterator it = missing_packets.lower_bound( largest_received_missing_packet_sequence_number_); if (it == missing_packets.end()) diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc index b868c98..7faafe7 100644 --- a/net/quic/quic_connection_test.cc +++ b/net/quic/quic_connection_test.cc @@ -657,13 +657,13 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { return outgoing_ack_.get(); } + QuicStopWaitingFrame* stop_waiting() { + stop_waiting_.reset( + QuicConnectionPeer::CreateStopWaitingFrame(&connection_)); + return stop_waiting_.get(); + } + QuicPacketSequenceNumber least_unacked() { - if (version() <= QUIC_VERSION_15) { - if (writer_->ack_frames().empty()) { - return 0; - } - return writer_->ack_frames()[0].sent_info.least_unacked; - } if (writer_->stop_waiting_frames().empty()) { return 0; } @@ -826,7 +826,7 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { } bool IsMissing(QuicPacketSequenceNumber number) { - return IsAwaitingPacket(outgoing_ack()->received_info, number); + return IsAwaitingPacket(*outgoing_ack(), number); } QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, @@ -889,12 +889,12 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { } // Initialize a frame acknowledging all packets up to largest_observed. - const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed, - QuicPacketSequenceNumber least_unacked) { - QuicAckFrame frame(MakeAckFrame(largest_observed, least_unacked)); + const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed) { + QuicAckFrame frame(MakeAckFrame(largest_observed)); if (largest_observed > 0) { - frame.received_info.entropy_hash = - QuicConnectionPeer::GetSentEntropyHash(&connection_, largest_observed); + frame.entropy_hash = + QuicConnectionPeer::GetSentEntropyHash(&connection_, + largest_observed); } return frame; } @@ -907,24 +907,24 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { } // Explicitly nack a packet. void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { - frame->received_info.missing_packets.insert(missing); - frame->received_info.entropy_hash ^= - QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); + frame->missing_packets.insert(missing); + frame->entropy_hash ^= + QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); if (missing > 1) { - frame->received_info.entropy_hash ^= - QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); + frame->entropy_hash ^= + QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); } } // Undo nacking a packet within the frame. void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) { - EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived)); - frame->received_info.missing_packets.erase(arrived); - frame->received_info.entropy_hash ^= - QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); + EXPECT_THAT(frame->missing_packets, Contains(arrived)); + frame->missing_packets.erase(arrived); + frame->entropy_hash ^= + QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); if (arrived > 1) { - frame->received_info.entropy_hash ^= - QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); + frame->entropy_hash ^= + QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); } } @@ -975,6 +975,7 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { QuicStreamFrame frame1_; QuicStreamFrame frame2_; scoped_ptr<QuicAckFrame> outgoing_ack_; + scoped_ptr<QuicStopWaitingFrame> stop_waiting_; QuicSequenceNumberLength sequence_number_length_; QuicConnectionIdLength connection_id_length_; @@ -991,33 +992,33 @@ TEST_P(QuicConnectionTest, PacketsInOrder) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessPacket(1); - EXPECT_EQ(1u, outgoing_ack()->received_info.largest_observed); - EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); + EXPECT_EQ(1u, outgoing_ack()->largest_observed); + EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); ProcessPacket(2); - EXPECT_EQ(2u, outgoing_ack()->received_info.largest_observed); - EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); + EXPECT_EQ(2u, outgoing_ack()->largest_observed); + EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); ProcessPacket(3); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); - EXPECT_EQ(0u, outgoing_ack()->received_info.missing_packets.size()); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); + EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); } TEST_P(QuicConnectionTest, PacketsOutOfOrder) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessPacket(3); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_TRUE(IsMissing(2)); EXPECT_TRUE(IsMissing(1)); ProcessPacket(2); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_FALSE(IsMissing(2)); EXPECT_TRUE(IsMissing(1)); ProcessPacket(1); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_FALSE(IsMissing(2)); EXPECT_FALSE(IsMissing(1)); } @@ -1026,14 +1027,14 @@ TEST_P(QuicConnectionTest, DuplicatePacket) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessPacket(3); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_TRUE(IsMissing(2)); EXPECT_TRUE(IsMissing(1)); // Send packet 3 again, but do not set the expectation that // the visitor OnStreamFrames() will be called. ProcessDataPacket(3, 0, !kEntropyFlag); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_TRUE(IsMissing(2)); EXPECT_TRUE(IsMissing(1)); } @@ -1042,16 +1043,16 @@ TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessPacket(3); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_TRUE(IsMissing(2)); EXPECT_TRUE(IsMissing(1)); ProcessPacket(2); - EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(3u, outgoing_ack()->largest_observed); EXPECT_TRUE(IsMissing(1)); ProcessPacket(5); - EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); + EXPECT_EQ(5u, outgoing_ack()->largest_observed); EXPECT_TRUE(IsMissing(1)); EXPECT_TRUE(IsMissing(4)); @@ -1060,7 +1061,7 @@ TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { // awaiting' is 4. The connection should then realize 1 will not be // retransmitted, and will remove it from the missing list. peer_creator_.set_sequence_number(5); - QuicAckFrame frame = InitAckFrame(1, 4); + QuicAckFrame frame = InitAckFrame(1); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _)); ProcessAckPacket(&frame); @@ -1102,7 +1103,7 @@ TEST_P(QuicConnectionTest, TruncatedAck) { SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); } - QuicAckFrame frame = InitAckFrame(num_packets, 1); + QuicAckFrame frame = InitAckFrame(num_packets); SequenceNumberSet lost_packets; // Create an ack with 256 nacks, none adjacent to one another. for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { @@ -1153,7 +1154,7 @@ TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { testing::Return(QuicTime::Delta::Zero())); // Skip a packet and then record an ack. peer_creator_.set_sequence_number(2); - QuicAckFrame frame = InitAckFrame(0, 3); + QuicAckFrame frame = InitAckFrame(0); ProcessAckPacket(&frame); } @@ -1186,7 +1187,7 @@ TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { .WillOnce(DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true))); connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); - QuicAckFrame frame = InitAckFrame(original, 1); + QuicAckFrame frame = InitAckFrame(original); NackPacket(original, &frame); // First nack triggers early retransmit. SequenceNumberSet lost_packets; @@ -1201,7 +1202,7 @@ TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { ProcessAckPacket(&frame); - QuicAckFrame frame2 = InitAckFrame(retransmission, 1); + QuicAckFrame frame2 = InitAckFrame(retransmission); NackPacket(original, &frame2); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) @@ -1226,11 +1227,7 @@ TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { HAS_RETRANSMITTABLE_DATA)); connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); // Ack bundled. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(3u, writer_->frame_count()); - } else { - EXPECT_EQ(2u, writer_->frame_count()); - } + EXPECT_EQ(3u, writer_->frame_count()); EXPECT_EQ(1u, writer_->stream_frames().size()); EXPECT_FALSE(writer_->ack_frames().empty()); @@ -1249,13 +1246,8 @@ TEST_P(QuicConnectionTest, LeastUnackedLower) { // Start out saying the least unacked is 2. peer_creator_.set_sequence_number(5); - if (version() > QUIC_VERSION_15) { - QuicStopWaitingFrame frame = InitStopWaitingFrame(2); - ProcessStopWaitingPacket(&frame); - } else { - QuicAckFrame frame = InitAckFrame(0, 2); - ProcessAckPacket(&frame); - } + QuicStopWaitingFrame frame = InitStopWaitingFrame(2); + ProcessStopWaitingPacket(&frame); // Change it to 1, but lower the sequence number to fake out-of-order packets. // This should be fine. @@ -1263,28 +1255,17 @@ TEST_P(QuicConnectionTest, LeastUnackedLower) { // The scheduler will not process out of order acks, but all packet processing // causes the connection to try to write. EXPECT_CALL(visitor_, OnCanWrite()); - if (version() > QUIC_VERSION_15) { - QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); - ProcessStopWaitingPacket(&frame2); - } else { - QuicAckFrame frame2 = InitAckFrame(0, 1); - ProcessAckPacket(&frame2); - } + QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); + ProcessStopWaitingPacket(&frame2); // Now claim it's one, but set the ordering so it was sent "after" the first // one. This should cause a connection error. EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); peer_creator_.set_sequence_number(7); - if (version() > QUIC_VERSION_15) { - EXPECT_CALL(visitor_, - OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); - QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); - ProcessStopWaitingPacket(&frame2); - } else { - EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); - QuicAckFrame frame2 = InitAckFrame(0, 1); - ProcessAckPacket(&frame2); - } + EXPECT_CALL(visitor_, + OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); + QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1); + ProcessStopWaitingPacket(&frame3); } TEST_P(QuicConnectionTest, LargestObservedLower) { @@ -1296,8 +1277,8 @@ TEST_P(QuicConnectionTest, LargestObservedLower) { EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); // Start out saying the largest observed is 2. - QuicAckFrame frame1 = InitAckFrame(1, 0); - QuicAckFrame frame2 = InitAckFrame(2, 0); + QuicAckFrame frame1 = InitAckFrame(1); + QuicAckFrame frame2 = InitAckFrame(2); ProcessAckPacket(&frame2); // Now change it to 1, and it should cause a connection error. @@ -1311,7 +1292,7 @@ TEST_P(QuicConnectionTest, AckUnsentData) { EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); - QuicAckFrame frame(MakeAckFrame(1, 0)); + QuicAckFrame frame(MakeAckFrame(1)); EXPECT_CALL(visitor_, OnCanWrite()).Times(0); ProcessAckPacket(&frame); } @@ -1321,7 +1302,7 @@ TEST_P(QuicConnectionTest, AckAll) { ProcessPacket(1); peer_creator_.set_sequence_number(1); - QuicAckFrame frame1 = InitAckFrame(0, 1); + QuicAckFrame frame1 = InitAckFrame(0); ProcessAckPacket(&frame1); } @@ -1443,7 +1424,7 @@ TEST_P(QuicConnectionTest, BasicSending) { EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); // Peer acks up to packet 3. - QuicAckFrame frame = InitAckFrame(3, 0); + QuicAckFrame frame = InitAckFrame(3); ProcessAckPacket(&frame); SendAckPacketToPeer(); // Packet 6 @@ -1454,7 +1435,7 @@ TEST_P(QuicConnectionTest, BasicSending) { EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); // Peer acks up to packet 4, the last packet. - QuicAckFrame frame2 = InitAckFrame(6, 0); + QuicAckFrame frame2 = InitAckFrame(6); ProcessAckPacket(&frame2); // Acks don't instigate acks. // Verify that we did not send an ack. @@ -1551,7 +1532,7 @@ TEST_P(QuicConnectionTest, DontAbandonAckedFEC) { connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL); connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); - QuicAckFrame ack_fec = InitAckFrame(2, 1); + QuicAckFrame ack_fec = InitAckFrame(2); // Data packet missing. // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was // received, it would cause the covered packet to be acked as well. @@ -1581,7 +1562,7 @@ TEST_P(QuicConnectionTest, AbandonAllFEC) { clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL); - QuicAckFrame ack_fec = InitAckFrame(5, 1); + QuicAckFrame ack_fec = InitAckFrame(5); // Ack all data packets, but no fec packets. NackPacket(2, &ack_fec); NackPacket(4, &ack_fec); @@ -1624,12 +1605,8 @@ TEST_P(QuicConnectionTest, FramePacking) { // Parse the last packet and ensure it's an ack and two stream frames from // two different streams. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(4u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(3u, writer_->frame_count()); - } + EXPECT_EQ(4u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); ASSERT_EQ(2u, writer_->stream_frames().size()); EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); @@ -1726,7 +1703,7 @@ TEST_P(QuicConnectionTest, FramePackingAckResponse) { // Process an ack to cause the visitor's OnCanWrite to be invoked. peer_creator_.set_sequence_number(2); - QuicAckFrame ack_one = InitAckFrame(0, 0); + QuicAckFrame ack_one = InitAckFrame(0); ProcessAckPacket(&ack_one); EXPECT_EQ(0u, connection_.NumQueuedPackets()); @@ -1734,12 +1711,8 @@ TEST_P(QuicConnectionTest, FramePackingAckResponse) { // Parse the last packet and ensure it's an ack and two stream frames from // two different streams. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(4u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(3u, writer_->frame_count()); - } + EXPECT_EQ(4u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); ASSERT_EQ(2u, writer_->stream_frames().size()); EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); @@ -1846,11 +1819,11 @@ TEST_P(QuicConnectionTest, RetransmitOnNack) { // Don't lose a packet on an ack, and nothing is retransmitted. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame ack_one = InitAckFrame(1, 0); + QuicAckFrame ack_one = InitAckFrame(1); ProcessAckPacket(&ack_one); // Lose a packet and ensure it triggers retransmission. - QuicAckFrame nack_two = InitAckFrame(3, 0); + QuicAckFrame nack_two = InitAckFrame(3); NackPacket(2, &nack_two); SequenceNumberSet lost_packets; lost_packets.insert(2); @@ -1872,7 +1845,7 @@ TEST_P(QuicConnectionTest, DiscardRetransmit) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); // Instigate a loss with an ack. - QuicAckFrame nack_two = InitAckFrame(3, 0); + QuicAckFrame nack_two = InitAckFrame(3); NackPacket(2, &nack_two); // The first nack should trigger a fast retransmission, but we'll be // write blocked, so the packet will be queued. @@ -1888,7 +1861,7 @@ TEST_P(QuicConnectionTest, DiscardRetransmit) { // Now, ack the previous transmission. EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) .WillOnce(Return(SequenceNumberSet())); - QuicAckFrame ack_all = InitAckFrame(3, 0); + QuicAckFrame ack_all = InitAckFrame(3); ProcessAckPacket(&ack_all); // Unblock the socket and attempt to send the queued packets. However, @@ -1912,7 +1885,7 @@ TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { Return(true))); connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); - QuicAckFrame frame = InitAckFrame(1, largest_observed); + QuicAckFrame frame = InitAckFrame(1); NackPacket(largest_observed, &frame); // The first nack should retransmit the largest observed packet. SequenceNumberSet lost_packets; @@ -1970,7 +1943,7 @@ TEST_P(QuicConnectionTest, WriteBlockedAckedThenSent) { // Ack the sent packet before the callback returns, which happens in // rare circumstances with write blocked sockets. - QuicAckFrame ack = InitAckFrame(1, 0); + QuicAckFrame ack = InitAckFrame(1); ProcessAckPacket(&ack); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); @@ -1992,7 +1965,7 @@ TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { // Ack the sent packet before the callback returns, which happens in // rare circumstances with write blocked sockets. - QuicAckFrame ack = InitAckFrame(1, 0); + QuicAckFrame ack = InitAckFrame(1); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); ProcessAckPacket(&ack); @@ -2031,7 +2004,7 @@ TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) { // Ack 15, nack 1-14. SequenceNumberSet lost_packets; - QuicAckFrame nack = InitAckFrame(15, 0); + QuicAckFrame nack = InitAckFrame(15); for (int i = 1; i < 15; ++i) { NackPacket(i, &nack); lost_packets.insert(i); @@ -2063,14 +2036,14 @@ TEST_P(QuicConnectionTest, MultipleAcks) { // Client will ack packets 1, 2, [!3], 4, 5. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame frame1 = InitAckFrame(5, 0); + QuicAckFrame frame1 = InitAckFrame(5); NackPacket(3, &frame1); EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessAckPacket(&frame1); // Now the client implicitly acks 3, and explicitly acks 6. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame frame2 = InitAckFrame(6, 0); + QuicAckFrame frame2 = InitAckFrame(6); ProcessAckPacket(&frame2); } @@ -2083,36 +2056,37 @@ TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame frame = InitAckFrame(1, 0); + QuicAckFrame frame = InitAckFrame(1); ProcessAckPacket(&frame); // Verify that our internal state has least-unacked as 2, because we're still // waiting for a potential ack for 2. - EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked); + + EXPECT_EQ(2u, stop_waiting()->least_unacked); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - frame = InitAckFrame(2, 0); + frame = InitAckFrame(2); ProcessAckPacket(&frame); - EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(3u, stop_waiting()->least_unacked); // When we send an ack, we make sure our least-unacked makes sense. In this // case since we're not waiting on an ack for 2 and all packets are acked, we // set it to 3. SendAckPacketToPeer(); // Packet 3 // Least_unacked remains at 3 until another ack is received. - EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(3u, stop_waiting()->least_unacked); // Check that the outgoing ack had its sequence number as least_unacked. EXPECT_EQ(3u, least_unacked()); // Ack the ack, which updates the rtt and raises the least unacked. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - frame = InitAckFrame(3, 0); + frame = InitAckFrame(3); ProcessAckPacket(&frame); ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) .WillByDefault(Return(true)); SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 - EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(4u, stop_waiting()->least_unacked); ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) .WillByDefault(Return(false)); SendAckPacketToPeer(); // Packet 5 @@ -2126,12 +2100,12 @@ TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { SendStreamDataToPeer(1, "bar", 9, false, NULL); // Packet 7 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - frame = InitAckFrame(7, 0); + frame = InitAckFrame(7); NackPacket(5, &frame); NackPacket(6, &frame); ProcessAckPacket(&frame); - EXPECT_EQ(6u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(6u, stop_waiting()->least_unacked); } TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { @@ -2147,9 +2121,9 @@ TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); // Set up a debug visitor to the connection. - scoped_ptr<FecQuicConnectionDebugVisitor> - fec_visitor(new FecQuicConnectionDebugVisitor); - connection_.set_debug_visitor(fec_visitor.get()); + FecQuicConnectionDebugVisitor* fec_visitor = + new FecQuicConnectionDebugVisitor(); + connection_.set_debug_visitor(fec_visitor); QuicPacketSequenceNumber fec_packet = 0; QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, @@ -2175,9 +2149,9 @@ TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); // Set up a debug visitor to the connection. - scoped_ptr<FecQuicConnectionDebugVisitor> - fec_visitor(new FecQuicConnectionDebugVisitor); - connection_.set_debug_visitor(fec_visitor.get()); + FecQuicConnectionDebugVisitor* fec_visitor = + new FecQuicConnectionDebugVisitor(); + connection_.set_debug_visitor(fec_visitor); QuicPacketSequenceNumber fec_packet = 0; QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, @@ -2251,7 +2225,7 @@ TEST_P(QuicConnectionTest, TLP) { QuicConnectionPeer::GetSentPacketManager(&connection_), 1); SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); - EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(1u, stop_waiting()->least_unacked); QuicTime retransmission_time = connection_.GetRetransmissionAlarm()->deadline(); EXPECT_NE(QuicTime::Zero(), retransmission_time); @@ -2264,14 +2238,14 @@ TEST_P(QuicConnectionTest, TLP) { connection_.GetRetransmissionAlarm()->Fire(); EXPECT_EQ(2u, writer_->header().packet_sequence_number); // We do not raise the high water mark yet. - EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(1u, stop_waiting()->least_unacked); } TEST_P(QuicConnectionTest, RTO) { QuicTime default_retransmission_time = clock_.ApproximateNow().Add( DefaultRetransmissionTime()); SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); - EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(1u, stop_waiting()->least_unacked); EXPECT_EQ(1u, writer_->header().packet_sequence_number); EXPECT_EQ(default_retransmission_time, @@ -2283,7 +2257,7 @@ TEST_P(QuicConnectionTest, RTO) { connection_.GetRetransmissionAlarm()->Fire(); EXPECT_EQ(2u, writer_->header().packet_sequence_number); // We do not raise the high water mark yet. - EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(1u, stop_waiting()->least_unacked); } TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { @@ -2494,7 +2468,7 @@ TEST_P(QuicConnectionTest, RetransmissionCountCalculation) { .Times(AnyNumber()); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) .WillOnce(DoAll(SaveArg<2>(&nack_sequence_number), Return(true))); - QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0); + QuicAckFrame ack = InitAckFrame(rto_sequence_number); // Nack the retransmitted packet. NackPacket(original_sequence_number, &ack); NackPacket(rto_sequence_number, &ack); @@ -2536,7 +2510,7 @@ TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { // packet to delay the RTO. clock_.AdvanceTime(DefaultRetransmissionTime()); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame ack = InitAckFrame(1, 0); + QuicAckFrame ack = InitAckFrame(1); ProcessAckPacket(&ack); EXPECT_TRUE(retransmission_alarm->IsSet()); EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); @@ -2583,13 +2557,8 @@ TEST_P(QuicConnectionTest, CloseFecGroup) { // Now send non-fec protected ack packet and close the group. peer_creator_.set_sequence_number(4); - if (version() > QUIC_VERSION_15) { - QuicStopWaitingFrame frame = InitStopWaitingFrame(5); - ProcessStopWaitingPacket(&frame); - } else { - QuicAckFrame frame = InitAckFrame(0, 5); - ProcessAckPacket(&frame); - } + QuicStopWaitingFrame frame = InitStopWaitingFrame(5); + ProcessStopWaitingPacket(&frame); ASSERT_EQ(0u, connection_.NumFecGroups()); } @@ -2600,15 +2569,13 @@ TEST_P(QuicConnectionTest, NoQuicCongestionFeedbackFrame) { TEST_P(QuicConnectionTest, WithQuicCongestionFeedbackFrame) { QuicCongestionFeedbackFrame info; - info.type = kFixRate; - info.fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(123); + info.type = kTCP; + info.tcp.receive_window = 0x4030; SetFeedback(&info); SendAckPacketToPeer(); ASSERT_FALSE(writer_->feedback_frames().empty()); - ASSERT_EQ(kFixRate, writer_->feedback_frames()[0].type); - ASSERT_EQ(info.fix_rate.bitrate, - writer_->feedback_frames()[0].fix_rate.bitrate); + ASSERT_EQ(kTCP, writer_->feedback_frames()[0].type); } TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { @@ -2668,7 +2635,7 @@ TEST_P(QuicConnectionTest, PingAfterSend) { // Now recevie and ACK of the previous packet, which will move the // ping alarm forward. clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); - QuicAckFrame frame = InitAckFrame(1, 0); + QuicAckFrame frame = InitAckFrame(1); EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); ProcessAckPacket(&frame); @@ -2842,7 +2809,7 @@ TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { // Now send non-retransmitting information, that we're not going to // retransmit 3. The far end should stop waiting for it. - QuicAckFrame frame = InitAckFrame(0, 1); + QuicAckFrame frame = InitAckFrame(0); EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly( testing::Return(QuicTime::Delta::Zero())); @@ -2867,7 +2834,7 @@ TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { // Now send non-retransmitting information, that we're not going to // retransmit 3. The far end should stop waiting for it. - QuicAckFrame frame = InitAckFrame(0, 1); + QuicAckFrame frame = InitAckFrame(0); EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillOnce( testing::Return(QuicTime::Delta::FromMicroseconds(1))); @@ -2956,12 +2923,8 @@ TEST_P(QuicConnectionTest, SendDelayedAck) { // Simulate delayed ack alarm firing. connection_.GetAckAlarm()->Fire(); // Check that ack is sent and that delayed ack alarm is reset. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(2u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(1u, writer_->frame_count()); - } + EXPECT_EQ(2u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); } @@ -2978,12 +2941,8 @@ TEST_P(QuicConnectionTest, SendEarlyDelayedAckForCrypto) { // Simulate delayed ack alarm firing. connection_.GetAckAlarm()->Fire(); // Check that ack is sent and that delayed ack alarm is reset. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(2u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(1u, writer_->frame_count()); - } + EXPECT_EQ(2u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); } @@ -2993,12 +2952,8 @@ TEST_P(QuicConnectionTest, SendDelayedAckOnSecondPacket) { ProcessPacket(1); ProcessPacket(2); // Check that ack is sent and that delayed ack alarm is reset. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(2u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(1u, writer_->frame_count()); - } + EXPECT_EQ(2u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); } @@ -3007,7 +2962,7 @@ TEST_P(QuicConnectionTest, NoAckOnOldNacks) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); // Drop one packet, triggering a sequence of acks. ProcessPacket(2); - size_t frames_per_ack = version() > QUIC_VERSION_15 ? 2 : 1; + size_t frames_per_ack = 2; EXPECT_EQ(frames_per_ack, writer_->frame_count()); EXPECT_FALSE(writer_->ack_frames().empty()); writer_->Reset(); @@ -3036,12 +2991,8 @@ TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { !kFin, NULL); // Check that ack is bundled with outgoing data and that delayed ack // alarm is reset. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(3u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(2u, writer_->frame_count()); - } + EXPECT_EQ(3u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); } @@ -3051,7 +3002,7 @@ TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { ProcessPacket(1); connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, NULL); // Check that ack is bundled with outgoing crypto data. - EXPECT_EQ(version() <= QUIC_VERSION_15 ? 2u : 3u, writer_->frame_count()); + EXPECT_EQ(3u, writer_->frame_count()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); } @@ -3067,12 +3018,8 @@ TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) { // immediately send an ack, due to the packet gap. ProcessPacket(2); // Check that ack is sent and that delayed ack alarm is reset. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(3u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(2u, writer_->frame_count()); - } + EXPECT_EQ(3u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_EQ(1u, writer_->stream_frames().size()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); @@ -3085,7 +3032,7 @@ TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, NULL); // Ack the second packet, which will retransmit the first packet. - QuicAckFrame ack = InitAckFrame(2, 0); + QuicAckFrame ack = InitAckFrame(2); NackPacket(1, &ack); SequenceNumberSet lost_packets; lost_packets.insert(1); @@ -3099,7 +3046,7 @@ TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { // Now ack the retransmission, which will both raise the high water mark // and see if there is more data to send. - ack = InitAckFrame(3, 0); + ack = InitAckFrame(3); NackPacket(1, &ack); EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) .WillOnce(Return(SequenceNumberSet())); @@ -3112,7 +3059,7 @@ TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { writer_->Reset(); // Send the same ack, but send both data and an ack together. - ack = InitAckFrame(3, 0); + ack = InitAckFrame(3); NackPacket(1, &ack); EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) .WillOnce(Return(SequenceNumberSet())); @@ -3124,12 +3071,8 @@ TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { // Check that ack is bundled with outgoing data and the delayed ack // alarm is reset. - if (version() > QUIC_VERSION_15) { - EXPECT_EQ(3u, writer_->frame_count()); - EXPECT_FALSE(writer_->stop_waiting_frames().empty()); - } else { - EXPECT_EQ(2u, writer_->frame_count()); - } + EXPECT_EQ(3u, writer_->frame_count()); + EXPECT_FALSE(writer_->stop_waiting_frames().empty()); EXPECT_FALSE(writer_->ack_frames().empty()); EXPECT_EQ(1u, writer_->stream_frames().size()); EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); @@ -3211,14 +3154,9 @@ TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { // Set the sequence number of the ack packet to be least unacked (4). peer_creator_.set_sequence_number(3); EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - if (version() > QUIC_VERSION_15) { - QuicStopWaitingFrame frame = InitStopWaitingFrame(4); - ProcessStopWaitingPacket(&frame); - } else { - QuicAckFrame ack = InitAckFrame(0, 4); - ProcessAckPacket(&ack); - } - EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); + QuicStopWaitingFrame frame = InitStopWaitingFrame(4); + ProcessStopWaitingPacket(&frame); + EXPECT_TRUE(outgoing_ack()->missing_packets.empty()); } TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { @@ -3228,7 +3166,7 @@ TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { ProcessDataPacket(4, 1, kEntropyFlag); ProcessDataPacket(3, 1, !kEntropyFlag); ProcessDataPacket(7, 1, kEntropyFlag); - EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); + EXPECT_EQ(146u, outgoing_ack()->entropy_hash); } TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { @@ -3239,7 +3177,7 @@ TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); ProcessDataPacket(3, 3, !kEntropyFlag); ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); - EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); + EXPECT_EQ(146u, outgoing_ack()->entropy_hash); } TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { @@ -3248,27 +3186,19 @@ TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { ProcessDataPacket(1, 1, kEntropyFlag); ProcessDataPacket(5, 1, kEntropyFlag); ProcessDataPacket(4, 1, !kEntropyFlag); - EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); + EXPECT_EQ(34u, outgoing_ack()->entropy_hash); // Make 4th packet my least unacked, and update entropy for 2, 3 packets. peer_creator_.set_sequence_number(5); QuicPacketEntropyHash six_packet_entropy_hash = 0; QuicPacketEntropyHash kRandomEntropyHash = 129u; - if (version() > QUIC_VERSION_15) { - QuicStopWaitingFrame frame = InitStopWaitingFrame(4); - frame.entropy_hash = kRandomEntropyHash; - if (ProcessStopWaitingPacket(&frame)) { - six_packet_entropy_hash = 1 << 6; - } - } else { - QuicAckFrame ack = InitAckFrame(0, 4); - ack.sent_info.entropy_hash = kRandomEntropyHash; - if (ProcessAckPacket(&ack)) { - six_packet_entropy_hash = 1 << 6; - } + QuicStopWaitingFrame frame = InitStopWaitingFrame(4); + frame.entropy_hash = kRandomEntropyHash; + if (ProcessStopWaitingPacket(&frame)) { + six_packet_entropy_hash = 1 << 6; } EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), - outgoing_ack()->received_info.entropy_hash); + outgoing_ack()->entropy_hash); } TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { @@ -3277,25 +3207,19 @@ TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { ProcessDataPacket(1, 1, kEntropyFlag); ProcessDataPacket(5, 1, !kEntropyFlag); ProcessDataPacket(22, 1, kEntropyFlag); - EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); + EXPECT_EQ(66u, outgoing_ack()->entropy_hash); peer_creator_.set_sequence_number(22); QuicPacketEntropyHash kRandomEntropyHash = 85u; // Current packet is the least unacked packet. QuicPacketEntropyHash ack_entropy_hash; - if (version() > QUIC_VERSION_15) { - QuicStopWaitingFrame frame = InitStopWaitingFrame(23); - frame.entropy_hash = kRandomEntropyHash; - ack_entropy_hash = ProcessStopWaitingPacket(&frame); - } else { - QuicAckFrame ack = InitAckFrame(0, 23); - ack.sent_info.entropy_hash = kRandomEntropyHash; - ack_entropy_hash = ProcessAckPacket(&ack); - } + QuicStopWaitingFrame frame = InitStopWaitingFrame(23); + frame.entropy_hash = kRandomEntropyHash; + ack_entropy_hash = ProcessStopWaitingPacket(&frame); EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), - outgoing_ack()->received_info.entropy_hash); + outgoing_ack()->entropy_hash); ProcessDataPacket(25, 1, kEntropyFlag); EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), - outgoing_ack()->received_info.entropy_hash); + outgoing_ack()->entropy_hash); } TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { @@ -3551,7 +3475,7 @@ TEST_P(QuicConnectionTest, CheckSendStats) { connection_.GetRetransmissionAlarm()->Fire(); // Retransmit due to explicit nacks. - QuicAckFrame nack_three = InitAckFrame(4, 0); + QuicAckFrame nack_three = InitAckFrame(4); NackPacket(3, &nack_three); NackPacket(1, &nack_three); SequenceNumberSet lost_packets; @@ -3735,7 +3659,7 @@ TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { // Process an ACK from the server which should trigger the callback. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame frame = InitAckFrame(1, 0); + QuicAckFrame frame = InitAckFrame(1); ProcessAckPacket(&frame); } @@ -3756,7 +3680,7 @@ TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 // which we registered to be notified about. - QuicAckFrame frame = InitAckFrame(3, 0); + QuicAckFrame frame = InitAckFrame(3); NackPacket(1, &frame); SequenceNumberSet lost_packets; lost_packets.insert(1); @@ -3780,7 +3704,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); // Now we receive ACK for packets 1, 3, and 4 and lose 2. - QuicAckFrame frame = InitAckFrame(4, 0); + QuicAckFrame frame = InitAckFrame(4); NackPacket(2, &frame); SequenceNumberSet lost_packets; lost_packets.insert(2); @@ -3795,7 +3719,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) .WillRepeatedly(Return(SequenceNumberSet())); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame second_ack_frame = InitAckFrame(5, 0); + QuicAckFrame second_ack_frame = InitAckFrame(5); ProcessAckPacket(&second_ack_frame); } @@ -3812,7 +3736,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { QuicTime default_retransmission_time = clock_.ApproximateNow().Add( DefaultRetransmissionTime()); connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); - EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(1u, stop_waiting()->least_unacked); EXPECT_EQ(1u, writer_->header().packet_sequence_number); EXPECT_EQ(default_retransmission_time, @@ -3824,19 +3748,19 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { connection_.GetRetransmissionAlarm()->Fire(); EXPECT_EQ(2u, writer_->header().packet_sequence_number); // We do not raise the high water mark yet. - EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); + EXPECT_EQ(1u, stop_waiting()->least_unacked); // Ack the original packet, which will revert the RTO. EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame ack_frame = InitAckFrame(1, 0); + QuicAckFrame ack_frame = InitAckFrame(1); ProcessAckPacket(&ack_frame); // Delegate is not notified again when the retransmit is acked. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame second_ack_frame = InitAckFrame(2, 0); + QuicAckFrame second_ack_frame = InitAckFrame(2); ProcessAckPacket(&second_ack_frame); } @@ -3857,7 +3781,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); // Now we receive ACK for packets 1, 3, and 4 and lose 2. - QuicAckFrame frame = InitAckFrame(4, 0); + QuicAckFrame frame = InitAckFrame(4); NackPacket(2, &frame); SequenceNumberSet lost_packets; lost_packets.insert(2); @@ -3873,7 +3797,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) .WillOnce(Return(no_lost_packets)); - QuicAckFrame second_ack_frame = InitAckFrame(4, 0); + QuicAckFrame second_ack_frame = InitAckFrame(4); ProcessAckPacket(&second_ack_frame); // Verify that the delegate is not notified again when the @@ -3881,7 +3805,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) .WillOnce(Return(no_lost_packets)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame third_ack_frame = InitAckFrame(5, 0); + QuicAckFrame third_ack_frame = InitAckFrame(5); ProcessAckPacket(&third_ack_frame); } @@ -3900,9 +3824,9 @@ TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { // Process an ACK from the server with a revived packet, which should trigger // the callback. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); - QuicAckFrame frame = InitAckFrame(2, 0); + QuicAckFrame frame = InitAckFrame(2); NackPacket(1, &frame); - frame.received_info.revived_packets.insert(1); + frame.revived_packets.insert(1); ProcessAckPacket(&frame); // If the ack is processed again, the notifier should not be called again. ProcessAckPacket(&frame); @@ -3926,7 +3850,7 @@ TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { // Should recover the Ack packet and trigger the notification callback. QuicFrames frames; - QuicAckFrame ack_frame = InitAckFrame(1, 0); + QuicAckFrame ack_frame = InitAckFrame(1); frames.push_back(QuicFrame(&ack_frame)); // Dummy stream frame to satisfy expectations set elsewhere. @@ -4024,9 +3948,9 @@ class MockQuicConnectionDebugVisitor TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { QuicPacketHeader header; - scoped_ptr<MockQuicConnectionDebugVisitor> - debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); - connection_.set_debug_visitor(debug_visitor.get()); + MockQuicConnectionDebugVisitor* debug_visitor = + new MockQuicConnectionDebugVisitor(); + connection_.set_debug_visitor(debug_visitor); EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); connection_.OnPacketHeader(header); } diff --git a/net/quic/quic_crypto_client_stream.cc b/net/quic/quic_crypto_client_stream.cc index 8c038ef..385df1a 100644 --- a/net/quic/quic_crypto_client_stream.cc +++ b/net/quic/quic_crypto_client_stream.cc @@ -97,8 +97,6 @@ QuicCryptoClientStream::~QuicCryptoClientStream() { void QuicCryptoClientStream::OnHandshakeMessage( const CryptoHandshakeMessage& message) { - DVLOG(1) << "Client: Received " << message.DebugString(); - QuicCryptoStream::OnHandshakeMessage(message); if (message.tag() == kSCUP) { @@ -225,7 +223,6 @@ void QuicCryptoClientStream::DoHandshakeLoop( } out.set_minimum_size(max_packet_size - kFramingOverhead); next_state_ = STATE_RECV_REJ; - DVLOG(1) << "Client: Sending " << out.DebugString(); SendHandshakeMessage(out); return; } @@ -256,7 +253,6 @@ void QuicCryptoClientStream::DoHandshakeLoop( *cached->proof_verify_details()); } next_state_ = STATE_RECV_SHLO; - DVLOG(1) << "Client: Sending " << out.DebugString(); SendHandshakeMessage(out); // Be prepared to decrypt with the new server write key. session()->connection()->SetAlternativeDecrypter( diff --git a/net/quic/quic_crypto_stream.cc b/net/quic/quic_crypto_stream.cc index d53b736..25467cb 100644 --- a/net/quic/quic_crypto_stream.cc +++ b/net/quic/quic_crypto_stream.cc @@ -18,10 +18,13 @@ using base::StringPiece; namespace net { +#define ENDPOINT (is_server_ ? "Server: " : " Client: ") + QuicCryptoStream::QuicCryptoStream(QuicSession* session) : ReliableQuicStream(kCryptoStreamId, session), encryption_established_(false), - handshake_confirmed_(false) { + handshake_confirmed_(false), + is_server_(session->is_server()) { crypto_framer_.set_visitor(this); if (version() <= QUIC_VERSION_20) { // Prior to QUIC_VERSION_21 the crypto stream is not subject to any flow @@ -39,6 +42,7 @@ void QuicCryptoStream::OnError(CryptoFramer* framer) { void QuicCryptoStream::OnHandshakeMessage( const CryptoHandshakeMessage& message) { + DVLOG(1) << ENDPOINT << "Received " << message.DebugString(); session()->OnCryptoHandshakeMessageReceived(message); } @@ -57,6 +61,7 @@ QuicPriority QuicCryptoStream::EffectivePriority() const { void QuicCryptoStream::SendHandshakeMessage( const CryptoHandshakeMessage& message) { + DVLOG(1) << ENDPOINT << "Sending " << message.DebugString(); session()->OnCryptoHandshakeMessageSent(message); const QuicData& data = message.GetSerialized(); // TODO(wtc): check the return value. diff --git a/net/quic/quic_crypto_stream.h b/net/quic/quic_crypto_stream.h index e9d575c..131e096 100644 --- a/net/quic/quic_crypto_stream.h +++ b/net/quic/quic_crypto_stream.h @@ -69,6 +69,8 @@ class NET_EXPORT_PRIVATE QuicCryptoStream private: CryptoFramer crypto_framer_; + bool is_server_; + DISALLOW_COPY_AND_ASSIGN(QuicCryptoStream); }; diff --git a/net/quic/quic_framer.cc b/net/quic/quic_framer.cc index 1a648b8..2ef5c7f 100644 --- a/net/quic/quic_framer.cc +++ b/net/quic/quic_framer.cc @@ -132,12 +132,10 @@ QuicSequenceNumberLength ReadSequenceNumberLength(uint8 flags) { } } -bool CanTruncate( - QuicVersion version, const QuicFrame& frame, size_t free_bytes) { +bool CanTruncate(const QuicFrame& frame, size_t free_bytes) { if ((frame.type == ACK_FRAME || frame.type == CONNECTION_CLOSE_FRAME) && free_bytes >= - QuicFramer::GetMinAckFrameSize(version, - PACKET_6BYTE_SEQUENCE_NUMBER, + QuicFramer::GetMinAckFrameSize(PACKET_6BYTE_SEQUENCE_NUMBER, PACKET_6BYTE_SEQUENCE_NUMBER)) { return true; } @@ -181,8 +179,7 @@ QuicFramer::QuicFramer(const QuicVersionVector& supported_versions, QuicFramer::~QuicFramer() {} // static -size_t QuicFramer::GetMinStreamFrameSize(QuicVersion version, - QuicStreamId stream_id, +size_t QuicFramer::GetMinStreamFrameSize(QuicStreamId stream_id, QuicStreamOffset offset, bool last_frame_in_packet, InFecGroup is_in_fec_group) { @@ -195,15 +192,10 @@ size_t QuicFramer::GetMinStreamFrameSize(QuicVersion version, // static size_t QuicFramer::GetMinAckFrameSize( - QuicVersion version, QuicSequenceNumberLength sequence_number_length, QuicSequenceNumberLength largest_observed_length) { - size_t len = kQuicFrameTypeSize + kQuicEntropyHashSize + + return kQuicFrameTypeSize + kQuicEntropyHashSize + largest_observed_length + kQuicDeltaTimeLargestObservedSize; - if (version <= QUIC_VERSION_15) { - len += sequence_number_length + kQuicEntropyHashSize; - } - return len; } // static @@ -214,7 +206,7 @@ size_t QuicFramer::GetStopWaitingFrameSize( } // static -size_t QuicFramer::GetMinRstStreamFrameSize(QuicVersion quic_version) { +size_t QuicFramer::GetMinRstStreamFrameSize() { return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize + kQuicErrorCodeSize + kQuicErrorDetailsLengthSize; @@ -310,7 +302,7 @@ size_t QuicFramer::GetSerializedFrameLength( if (!first_frame) { return 0; } - if (CanTruncate(quic_version_, frame, free_bytes)) { + if (CanTruncate(frame, free_bytes)) { // Truncate the frame so the packet will not exceed kMaxPacketSize. // Note that we may not use every byte of the writer in this case. DVLOG(1) << "Truncating large frame, free bytes: " << free_bytes; @@ -382,11 +374,6 @@ SerializedPacket QuicFramer::BuildDataPacket( } break; case STOP_WAITING_FRAME: - if (quic_version_ <= QUIC_VERSION_15) { - LOG(DFATAL) << "Attempt to add a StopWaitingFrame in " - << QuicVersionToString(quic_version_); - return kNoPacket; - } if (!AppendStopWaitingFrame( header, *frame.stop_waiting_frame, &writer)) { LOG(DFATAL) << "AppendStopWaitingFrame failed"; @@ -394,7 +381,7 @@ SerializedPacket QuicFramer::BuildDataPacket( } break; case PING_FRAME: - if (quic_version_ <= QUIC_VERSION_16) { + if (quic_version_ == QUIC_VERSION_16) { LOG(DFATAL) << "Attempt to add a PingFrame in " << QuicVersionToString(quic_version_); return kNoPacket; @@ -976,18 +963,14 @@ uint8 QuicFramer::GetSequenceNumberFlags( // static QuicFramer::AckFrameInfo QuicFramer::GetAckFrameInfo( const QuicAckFrame& frame) { - const ReceivedPacketInfo& received_info = frame.received_info; - AckFrameInfo ack_info; - if (!received_info.missing_packets.empty()) { - DCHECK_GE(received_info.largest_observed, - *received_info.missing_packets.rbegin()); + if (!frame.missing_packets.empty()) { + DCHECK_GE(frame.largest_observed, *frame.missing_packets.rbegin()); size_t cur_range_length = 0; - SequenceNumberSet::const_iterator iter = - received_info.missing_packets.begin(); + SequenceNumberSet::const_iterator iter = frame.missing_packets.begin(); QuicPacketSequenceNumber last_missing = *iter; ++iter; - for (; iter != received_info.missing_packets.end(); ++iter) { + for (; iter != frame.missing_packets.end(); ++iter) { if (cur_range_length != numeric_limits<uint8>::max() && *iter == (last_missing + 1)) { ++cur_range_length; @@ -1003,7 +986,7 @@ QuicFramer::AckFrameInfo QuicFramer::GetAckFrameInfo( ack_info.nack_ranges[last_missing - cur_range_length] = cur_range_length; // Include the range to the largest observed. ack_info.max_delta = max(ack_info.max_delta, - received_info.largest_observed - last_missing); + frame.largest_observed - last_missing); } return ack_info; } @@ -1114,7 +1097,7 @@ bool QuicFramer::ProcessFrameData(const QuicPacketHeader& header) { // Ack Frame if (frame_type & kQuicFrameTypeAckMask) { QuicAckFrame frame; - if (!ProcessAckFrame(header, frame_type, &frame)) { + if (!ProcessAckFrame(frame_type, &frame)) { return RaiseError(QUIC_INVALID_ACK_DATA); } if (!visitor_->OnAckFrame(frame)) { @@ -1219,11 +1202,6 @@ bool QuicFramer::ProcessFrameData(const QuicPacketHeader& header) { } case STOP_WAITING_FRAME: { - if (quic_version_ <= QUIC_VERSION_15) { - LOG(DFATAL) << "Trying to read a StopWaiting in " - << QuicVersionToString(quic_version_); - return RaiseError(QUIC_INTERNAL_ERROR); - } QuicStopWaitingFrame stop_waiting_frame; if (!ProcessStopWaitingFrame(header, &stop_waiting_frame)) { return RaiseError(QUIC_INVALID_STOP_WAITING_DATA); @@ -1236,7 +1214,7 @@ bool QuicFramer::ProcessFrameData(const QuicPacketHeader& header) { continue; } case PING_FRAME: { - if (quic_version_ <= QUIC_VERSION_16) { + if (quic_version_ == QUIC_VERSION_16) { LOG(DFATAL) << "Trying to read a Ping in " << QuicVersionToString(quic_version_); return RaiseError(QUIC_INTERNAL_ERROR); @@ -1318,22 +1296,7 @@ bool QuicFramer::ProcessStreamFrame(uint8 frame_type, return true; } -bool QuicFramer::ProcessAckFrame(const QuicPacketHeader& header, - uint8 frame_type, - QuicAckFrame* frame) { - if (quic_version_ <= QUIC_VERSION_15) { - if (!ProcessStopWaitingFrame(header, &frame->sent_info)) { - return false; - } - } - if (!ProcessReceivedInfo(frame_type, &frame->received_info)) { - return false; - } - return true; -} - -bool QuicFramer::ProcessReceivedInfo(uint8 frame_type, - ReceivedPacketInfo* received_info) { +bool QuicFramer::ProcessAckFrame(uint8 frame_type, QuicAckFrame* ack_frame) { // Determine the three lengths from the frame type: largest observed length, // missing sequence number length, and missing range length. const QuicSequenceNumberLength missing_sequence_number_length = @@ -1342,16 +1305,16 @@ bool QuicFramer::ProcessReceivedInfo(uint8 frame_type, const QuicSequenceNumberLength largest_observed_sequence_number_length = ReadSequenceNumberLength(frame_type); frame_type >>= kQuicSequenceNumberLengthShift; - received_info->is_truncated = frame_type & kQuicAckTruncatedMask; + ack_frame->is_truncated = frame_type & kQuicAckTruncatedMask; frame_type >>= kQuicAckTruncatedShift; bool has_nacks = frame_type & kQuicHasNacksMask; - if (!reader_->ReadBytes(&received_info->entropy_hash, 1)) { + if (!reader_->ReadBytes(&ack_frame->entropy_hash, 1)) { set_detailed_error("Unable to read entropy hash for received packets."); return false; } - if (!reader_->ReadBytes(&received_info->largest_observed, + if (!reader_->ReadBytes(&ack_frame->largest_observed, largest_observed_sequence_number_length)) { set_detailed_error("Unable to read largest observed."); return false; @@ -1364,9 +1327,9 @@ bool QuicFramer::ProcessReceivedInfo(uint8 frame_type, } if (delta_time_largest_observed_us == kUFloat16MaxValue) { - received_info->delta_time_largest_observed = QuicTime::Delta::Infinite(); + ack_frame->delta_time_largest_observed = QuicTime::Delta::Infinite(); } else { - received_info->delta_time_largest_observed = + ack_frame->delta_time_largest_observed = QuicTime::Delta::FromMicroseconds(delta_time_largest_observed_us); } @@ -1380,8 +1343,7 @@ bool QuicFramer::ProcessReceivedInfo(uint8 frame_type, return false; } - QuicPacketSequenceNumber last_sequence_number = - received_info->largest_observed; + QuicPacketSequenceNumber last_sequence_number = ack_frame->largest_observed; for (size_t i = 0; i < num_missing_ranges; ++i) { QuicPacketSequenceNumber missing_delta = 0; if (!reader_->ReadBytes(&missing_delta, missing_sequence_number_length)) { @@ -1395,7 +1357,7 @@ bool QuicFramer::ProcessReceivedInfo(uint8 frame_type, return false; } for (size_t i = 0; i <= range_length; ++i) { - received_info->missing_packets.insert(last_sequence_number - i); + ack_frame->missing_packets.insert(last_sequence_number - i); } // Subtract an extra 1 to ensure ranges are represented efficiently and // can't overlap by 1 sequence number. This allows a missing_delta of 0 @@ -1418,7 +1380,7 @@ bool QuicFramer::ProcessReceivedInfo(uint8 frame_type, return false; } - received_info->revived_packets.insert(revived_packet); + ack_frame->revived_packets.insert(revived_packet); } return true; @@ -1505,15 +1467,6 @@ bool QuicFramer::ProcessQuicCongestionFeedbackFrame( } break; } - case kFixRate: { - uint32 bitrate = 0; - if (!reader_->ReadUInt32(&bitrate)) { - set_detailed_error("Unable to read bitrate."); - return false; - } - frame->fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(bitrate); - break; - } case kTCP: { CongestionFeedbackMessageTCP* tcp = &frame->tcp; // TODO(ianswett): Remove receive window, since it's constant. @@ -1797,18 +1750,17 @@ size_t QuicFramer::GetAckFrameSize( QuicSequenceNumberLength sequence_number_length) { AckFrameInfo ack_info = GetAckFrameInfo(ack); QuicSequenceNumberLength largest_observed_length = - GetMinSequenceNumberLength(ack.received_info.largest_observed); + GetMinSequenceNumberLength(ack.largest_observed); QuicSequenceNumberLength missing_sequence_number_length = GetMinSequenceNumberLength(ack_info.max_delta); - size_t ack_size = GetMinAckFrameSize(quic_version_, - sequence_number_length, + size_t ack_size = GetMinAckFrameSize(sequence_number_length, largest_observed_length); if (!ack_info.nack_ranges.empty()) { ack_size += kNumberOfNackRangesSize + kNumberOfRevivedPacketsSize; ack_size += min(ack_info.nack_ranges.size(), kMaxNackRanges) * (missing_sequence_number_length + PACKET_1BYTE_SEQUENCE_NUMBER); - ack_size += min(ack.received_info.revived_packets.size(), + ack_size += min(ack.revived_packets.size(), kMaxRevivedPackets) * largest_observed_length; } return ack_size; @@ -1821,8 +1773,7 @@ size_t QuicFramer::ComputeFrameLength( QuicSequenceNumberLength sequence_number_length) { switch (frame.type) { case STREAM_FRAME: - return GetMinStreamFrameSize(quic_version_, - frame.stream_frame->stream_id, + return GetMinStreamFrameSize(frame.stream_frame->stream_id, frame.stream_frame->offset, last_frame_in_packet, is_in_fec_group) + @@ -1850,9 +1801,6 @@ size_t QuicFramer::ComputeFrameLength( } break; } - case kFixRate: - len += 4; // Bitrate. - break; case kTCP: len += 2; // Receive window. break; @@ -1869,7 +1817,7 @@ size_t QuicFramer::ComputeFrameLength( // Ping has no payload. return kQuicFrameTypeSize; case RST_STREAM_FRAME: - return GetMinRstStreamFrameSize(quic_version_) + + return GetMinRstStreamFrameSize() + frame.rst_stream_frame->error_details.size(); case CONNECTION_CLOSE_FRAME: return GetMinConnectionCloseFrameSize() + @@ -2007,8 +1955,7 @@ bool QuicFramer::AppendAckFrameAndTypeByte( const QuicAckFrame& frame, QuicDataWriter* writer) { AckFrameInfo ack_info = GetAckFrameInfo(frame); - QuicPacketSequenceNumber ack_largest_observed = - frame.received_info.largest_observed; + QuicPacketSequenceNumber ack_largest_observed = frame.largest_observed; QuicSequenceNumberLength largest_observed_length = GetMinSequenceNumberLength(ack_largest_observed); QuicSequenceNumberLength missing_sequence_number_length = @@ -2016,8 +1963,7 @@ bool QuicFramer::AppendAckFrameAndTypeByte( // Determine whether we need to truncate ranges. size_t available_range_bytes = writer->capacity() - writer->length() - kNumberOfRevivedPacketsSize - kNumberOfNackRangesSize - - GetMinAckFrameSize(quic_version_, - header.public_header.sequence_number_length, + GetMinAckFrameSize(header.public_header.sequence_number_length, largest_observed_length); size_t max_num_ranges = available_range_bytes / (missing_sequence_number_length + PACKET_1BYTE_SEQUENCE_NUMBER); @@ -2049,14 +1995,7 @@ bool QuicFramer::AppendAckFrameAndTypeByte( return false; } - if (quic_version_ <= QUIC_VERSION_15) { - if (!AppendStopWaitingFrame(header, frame.sent_info, writer)) { - return false; - } - } - - const ReceivedPacketInfo& received_info = frame.received_info; - QuicPacketEntropyHash ack_entropy_hash = received_info.entropy_hash; + QuicPacketEntropyHash ack_entropy_hash = frame.entropy_hash; NackRangeMap::reverse_iterator ack_iter = ack_info.nack_ranges.rbegin(); if (truncated) { // Skip the nack ranges which the truncated ack won't include and set @@ -2084,11 +2023,10 @@ bool QuicFramer::AppendAckFrameAndTypeByte( } uint64 delta_time_largest_observed_us = kUFloat16MaxValue; - if (!received_info.delta_time_largest_observed.IsInfinite()) { - DCHECK_LE(0u, - frame.received_info.delta_time_largest_observed.ToMicroseconds()); + if (!frame.delta_time_largest_observed.IsInfinite()) { + DCHECK_LE(0u, frame.delta_time_largest_observed.ToMicroseconds()); delta_time_largest_observed_us = - received_info.delta_time_largest_observed.ToMicroseconds(); + frame.delta_time_largest_observed.ToMicroseconds(); } if (!writer->WriteUFloat16(delta_time_largest_observed_us)) { @@ -2127,7 +2065,7 @@ bool QuicFramer::AppendAckFrameAndTypeByte( // Append revived packets. // If not all the revived packets fit, only mention the ones that do. - uint8 num_revived_packets = min(received_info.revived_packets.size(), + uint8 num_revived_packets = min(frame.revived_packets.size(), kMaxRevivedPackets); num_revived_packets = min( static_cast<size_t>(num_revived_packets), @@ -2136,10 +2074,9 @@ bool QuicFramer::AppendAckFrameAndTypeByte( return false; } - SequenceNumberSet::const_iterator iter = - received_info.revived_packets.begin(); + SequenceNumberSet::const_iterator iter = frame.revived_packets.begin(); for (int i = 0; i < num_revived_packets; ++i, ++iter) { - LOG_IF(DFATAL, !ContainsKey(received_info.missing_packets, *iter)); + LOG_IF(DFATAL, !ContainsKey(frame.missing_packets, *iter)); if (!AppendPacketSequenceNumber(largest_observed_length, *iter, writer)) { return false; @@ -2207,14 +2144,6 @@ bool QuicFramer::AppendCongestionFeedbackFrame( } break; } - case kFixRate: { - const CongestionFeedbackMessageFixRate& fix_rate = - frame.fix_rate; - if (!writer->WriteUInt32(fix_rate.bitrate.ToBytesPerSecond())) { - return false; - } - break; - } case kTCP: { const CongestionFeedbackMessageTCP& tcp = frame.tcp; DCHECK_LE(tcp.receive_window, 1u << 20); diff --git a/net/quic/quic_framer.h b/net/quic/quic_framer.h index 2551810..1349f93 100644 --- a/net/quic/quic_framer.h +++ b/net/quic/quic_framer.h @@ -255,21 +255,19 @@ class NET_EXPORT_PRIVATE QuicFramer { base::StringPiece payload); // Largest size in bytes of all stream frame fields without the payload. - static size_t GetMinStreamFrameSize(QuicVersion version, - QuicStreamId stream_id, + static size_t GetMinStreamFrameSize(QuicStreamId stream_id, QuicStreamOffset offset, bool last_frame_in_packet, InFecGroup is_in_fec_group); // Size in bytes of all ack frame fields without the missing packets. static size_t GetMinAckFrameSize( - QuicVersion version, QuicSequenceNumberLength sequence_number_length, QuicSequenceNumberLength largest_observed_length); // Size in bytes of a stop waiting frame. static size_t GetStopWaitingFrameSize( QuicSequenceNumberLength sequence_number_length); // Size in bytes of all reset stream frame without the error details. - static size_t GetMinRstStreamFrameSize(QuicVersion quic_version); + static size_t GetMinRstStreamFrameSize(); // Size in bytes of all connection close frame fields without the error // details and the missing packets from the enclosed ack frame. static size_t GetMinConnectionCloseFrameSize(); @@ -410,10 +408,7 @@ class NET_EXPORT_PRIVATE QuicFramer { QuicPacketSequenceNumber* sequence_number); bool ProcessFrameData(const QuicPacketHeader& header); bool ProcessStreamFrame(uint8 frame_type, QuicStreamFrame* frame); - bool ProcessAckFrame(const QuicPacketHeader& header, - uint8 frame_type, - QuicAckFrame* frame); - bool ProcessReceivedInfo(uint8 frame_type, ReceivedPacketInfo* received_info); + bool ProcessAckFrame(uint8 frame_type, QuicAckFrame* frame); bool ProcessStopWaitingFrame(const QuicPacketHeader& public_header, QuicStopWaitingFrame* stop_waiting); bool ProcessQuicCongestionFeedbackFrame( diff --git a/net/quic/quic_framer_test.cc b/net/quic/quic_framer_test.cc index bebaf4a..f8d1c5b 100644 --- a/net/quic/quic_framer_test.cc +++ b/net/quic/quic_framer_test.cc @@ -1683,120 +1683,7 @@ TEST_P(QuicFramerTest, StreamFrameInFecGroup) { CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); } -TEST_P(QuicFramerTest, AckFrame15) { - if (framer_.version() != QUIC_VERSION_15) { - return; - } - - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xA8, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags (entropy) - 0x01, - - // frame type (ack frame) - // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) - 0x6C, - // entropy hash of sent packets till least awaiting - 1. - 0xAB, - // least packet sequence number awaiting an ack, delta from sequence number. - 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, - // entropy hash of all received packets. - 0xBA, - // largest observed packet sequence number - 0xBF, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // Zero delta time. - 0x0, 0x0, - // num missing packets - 0x01, - // missing packet delta - 0x01, - // 0 more missing packets in range. - 0x00, - // Number of revived packets. - 0x00, - }; - - QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); - EXPECT_TRUE(framer_.ProcessPacket(encrypted)); - - EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); - ASSERT_TRUE(visitor_.header_.get()); - EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); - - EXPECT_EQ(0u, visitor_.stream_frames_.size()); - ASSERT_EQ(1u, visitor_.ack_frames_.size()); - const QuicAckFrame& frame = *visitor_.ack_frames_[0]; - EXPECT_EQ(0xAB, frame.sent_info.entropy_hash); - EXPECT_EQ(0xBA, frame.received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); - ASSERT_EQ(1u, frame.received_info.missing_packets.size()); - SequenceNumberSet::const_iterator missing_iter = - frame.received_info.missing_packets.begin(); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); - EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); - - const size_t kSentEntropyOffset = kQuicFrameTypeSize; - const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; - const size_t kReceivedEntropyOffset = kLeastUnackedOffset + - PACKET_6BYTE_SEQUENCE_NUMBER; - const size_t kLargestObservedOffset = kReceivedEntropyOffset + - kQuicEntropyHashSize; - const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + - PACKET_6BYTE_SEQUENCE_NUMBER; - const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + - kQuicDeltaTimeLargestObservedSize; - const size_t kMissingPacketsOffset = kNumMissingPacketOffset + - kNumberOfNackRangesSize; - const size_t kMissingPacketsRange = kMissingPacketsOffset + - PACKET_1BYTE_SEQUENCE_NUMBER; - const size_t kRevivedPacketsLength = kMissingPacketsRange + - PACKET_1BYTE_SEQUENCE_NUMBER; - // Now test framing boundaries - const size_t ack_frame_size = kRevivedPacketsLength + - PACKET_1BYTE_SEQUENCE_NUMBER; - for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { - string expected_error; - if (i < kLeastUnackedOffset) { - expected_error = "Unable to read entropy hash for sent packets."; - } else if (i < kReceivedEntropyOffset) { - expected_error = "Unable to read least unacked delta."; - } else if (i < kLargestObservedOffset) { - expected_error = "Unable to read entropy hash for received packets."; - } else if (i < kMissingDeltaTimeOffset) { - expected_error = "Unable to read largest observed."; - } else if (i < kNumMissingPacketOffset) { - expected_error = "Unable to read delta time largest observed."; - } else if (i < kMissingPacketsOffset) { - expected_error = "Unable to read num missing packet ranges."; - } else if (i < kMissingPacketsRange) { - expected_error = "Unable to read missing sequence number delta."; - } else if (i < kRevivedPacketsLength) { - expected_error = "Unable to read missing sequence number range."; - } else { - expected_error = "Unable to read num revived packets."; - } - CheckProcessingFails( - packet, - i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, - PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), - expected_error, QUIC_INVALID_ACK_DATA); - } -} - TEST_P(QuicFramerTest, AckFrame) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } - unsigned char packet[] = { // public flags (8 byte connection_id) 0x3C, @@ -1839,11 +1726,11 @@ TEST_P(QuicFramerTest, AckFrame) { EXPECT_EQ(0u, visitor_.stream_frames_.size()); ASSERT_EQ(1u, visitor_.ack_frames_.size()); const QuicAckFrame& frame = *visitor_.ack_frames_[0]; - EXPECT_EQ(0xBA, frame.received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); - ASSERT_EQ(1u, frame.received_info.missing_packets.size()); + EXPECT_EQ(0xBA, frame.entropy_hash); + EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed); + ASSERT_EQ(1u, frame.missing_packets.size()); SequenceNumberSet::const_iterator missing_iter = - frame.received_info.missing_packets.begin(); + frame.missing_packets.begin(); EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; @@ -1888,10 +1775,6 @@ TEST_P(QuicFramerTest, AckFrame) { } TEST_P(QuicFramerTest, AckFrameRevivedPackets) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } - unsigned char packet[] = { // public flags (8 byte connection_id) 0x3C, @@ -1937,11 +1820,11 @@ TEST_P(QuicFramerTest, AckFrameRevivedPackets) { EXPECT_EQ(0u, visitor_.stream_frames_.size()); ASSERT_EQ(1u, visitor_.ack_frames_.size()); const QuicAckFrame& frame = *visitor_.ack_frames_[0]; - EXPECT_EQ(0xBA, frame.received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); - ASSERT_EQ(1u, frame.received_info.missing_packets.size()); + EXPECT_EQ(0xBA, frame.entropy_hash); + EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.largest_observed); + ASSERT_EQ(1u, frame.missing_packets.size()); SequenceNumberSet::const_iterator missing_iter = - frame.received_info.missing_packets.begin(); + frame.missing_packets.begin(); EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; @@ -1991,180 +1874,7 @@ TEST_P(QuicFramerTest, AckFrameRevivedPackets) { } } -TEST_P(QuicFramerTest, AckFrameRevivedPackets15) { - if (framer_.version() != QUIC_VERSION_15) { - return; - } - - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xA8, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags (entropy) - 0x01, - - // frame type (ack frame) - // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) - 0x6C, - // entropy hash of sent packets till least awaiting - 1. - 0xAB, - // least packet sequence number awaiting an ack, delta from sequence number. - 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, - // entropy hash of all received packets. - 0xBA, - // largest observed packet sequence number - 0xBF, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // Zero delta time. - 0x0, 0x0, - // num missing packets - 0x01, - // missing packet delta - 0x01, - // 0 more missing packets in range. - 0x00, - // Number of revived packets. - 0x01, - // Revived packet sequence number. - 0xBE, 0x9A, 0x78, 0x56, - 0x34, 0x12, - }; - - QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); - EXPECT_TRUE(framer_.ProcessPacket(encrypted)); - - EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); - ASSERT_TRUE(visitor_.header_.get()); - EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); - - EXPECT_EQ(0u, visitor_.stream_frames_.size()); - ASSERT_EQ(1u, visitor_.ack_frames_.size()); - const QuicAckFrame& frame = *visitor_.ack_frames_[0]; - EXPECT_EQ(0xAB, frame.sent_info.entropy_hash); - EXPECT_EQ(0xBA, frame.received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); - ASSERT_EQ(1u, frame.received_info.missing_packets.size()); - SequenceNumberSet::const_iterator missing_iter = - frame.received_info.missing_packets.begin(); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); - EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); - - const size_t kSentEntropyOffset = kQuicFrameTypeSize; - const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; - const size_t kReceivedEntropyOffset = kLeastUnackedOffset + - PACKET_6BYTE_SEQUENCE_NUMBER; - const size_t kLargestObservedOffset = kReceivedEntropyOffset + - kQuicEntropyHashSize; - const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + - PACKET_6BYTE_SEQUENCE_NUMBER; - const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + - kQuicDeltaTimeLargestObservedSize; - const size_t kMissingPacketsOffset = kNumMissingPacketOffset + - kNumberOfNackRangesSize; - const size_t kMissingPacketsRange = kMissingPacketsOffset + - PACKET_1BYTE_SEQUENCE_NUMBER; - const size_t kRevivedPacketsLength = kMissingPacketsRange + - PACKET_1BYTE_SEQUENCE_NUMBER; - const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength + - PACKET_1BYTE_SEQUENCE_NUMBER; - // Now test framing boundaries - const size_t ack_frame_size = kRevivedPacketSequenceNumberLength + - PACKET_6BYTE_SEQUENCE_NUMBER; - for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { - string expected_error; - if (i < kLeastUnackedOffset) { - expected_error = "Unable to read entropy hash for sent packets."; - } else if (i < kReceivedEntropyOffset) { - expected_error = "Unable to read least unacked delta."; - } else if (i < kLargestObservedOffset) { - expected_error = "Unable to read entropy hash for received packets."; - } else if (i < kMissingDeltaTimeOffset) { - expected_error = "Unable to read largest observed."; - } else if (i < kNumMissingPacketOffset) { - expected_error = "Unable to read delta time largest observed."; - } else if (i < kMissingPacketsOffset) { - expected_error = "Unable to read num missing packet ranges."; - } else if (i < kMissingPacketsRange) { - expected_error = "Unable to read missing sequence number delta."; - } else if (i < kRevivedPacketsLength) { - expected_error = "Unable to read missing sequence number range."; - } else if (i < kRevivedPacketSequenceNumberLength) { - expected_error = "Unable to read num revived packets."; - } else { - expected_error = "Unable to read revived packet."; - } - CheckProcessingFails( - packet, - i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, - PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), - expected_error, QUIC_INVALID_ACK_DATA); - } -} - TEST_P(QuicFramerTest, AckFrameNoNacks) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xA8, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags (entropy) - 0x01, - - // frame type (ack frame) - // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) - 0x4C, - // entropy hash of all received packets. - 0xBA, - // largest observed packet sequence number - 0xBF, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // Zero delta time. - 0x0, 0x0, - }; - - QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); - EXPECT_TRUE(framer_.ProcessPacket(encrypted)); - - EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); - ASSERT_TRUE(visitor_.header_.get()); - EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); - - EXPECT_EQ(0u, visitor_.stream_frames_.size()); - ASSERT_EQ(1u, visitor_.ack_frames_.size()); - QuicAckFrame* frame = visitor_.ack_frames_[0]; - EXPECT_EQ(0xBA, frame->received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), - frame->received_info.largest_observed); - ASSERT_EQ(0u, frame->received_info.missing_packets.size()); - - // Verify that the packet re-serializes identically. - QuicFrames frames; - frames.push_back(QuicFrame(frame)); - scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); - ASSERT_TRUE(data != NULL); - - test::CompareCharArraysWithHexError("constructed packet", - data->data(), data->length(), - AsChars(packet), arraysize(packet)); -} - -TEST_P(QuicFramerTest, AckFrameNoNacks15) { - if (framer_.version() > QUIC_VERSION_15) { - return; - } unsigned char packet[] = { // public flags (8 byte connection_id) 0x3C, @@ -2180,11 +1890,6 @@ TEST_P(QuicFramerTest, AckFrameNoNacks15) { // frame type (ack frame) // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) 0x4C, - // entropy hash of sent packets till least awaiting - 1. - 0xAB, - // least packet sequence number awaiting an ack, delta from sequence number. - 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, // entropy hash of all received packets. 0xBA, // largest observed packet sequence number @@ -2204,12 +1909,9 @@ TEST_P(QuicFramerTest, AckFrameNoNacks15) { EXPECT_EQ(0u, visitor_.stream_frames_.size()); ASSERT_EQ(1u, visitor_.ack_frames_.size()); QuicAckFrame* frame = visitor_.ack_frames_[0]; - EXPECT_EQ(0xAB, frame->sent_info.entropy_hash); - EXPECT_EQ(0xBA, frame->received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), - frame->received_info.largest_observed); - ASSERT_EQ(0u, frame->received_info.missing_packets.size()); - EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame->sent_info.least_unacked); + EXPECT_EQ(0xBA, frame->entropy_hash); + EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed); + ASSERT_EQ(0u, frame->missing_packets.size()); // Verify that the packet re-serializes identically. QuicFrames frames; @@ -2223,9 +1925,6 @@ TEST_P(QuicFramerTest, AckFrameNoNacks15) { } TEST_P(QuicFramerTest, AckFrame500Nacks) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } unsigned char packet[] = { // public flags (8 byte connection_id) 0x3C, @@ -2273,98 +1972,16 @@ TEST_P(QuicFramerTest, AckFrame500Nacks) { EXPECT_EQ(0u, visitor_.stream_frames_.size()); ASSERT_EQ(1u, visitor_.ack_frames_.size()); QuicAckFrame* frame = visitor_.ack_frames_[0]; - EXPECT_EQ(0xBA, frame->received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), - frame->received_info.largest_observed); - EXPECT_EQ(0u, frame->received_info.revived_packets.size()); - ASSERT_EQ(500u, frame->received_info.missing_packets.size()); - SequenceNumberSet::const_iterator first_missing_iter = - frame->received_info.missing_packets.begin(); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter); - SequenceNumberSet::const_reverse_iterator last_missing_iter = - frame->received_info.missing_packets.rbegin(); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter); - - // Verify that the packet re-serializes identically. - QuicFrames frames; - frames.push_back(QuicFrame(frame)); - scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); - ASSERT_TRUE(data != NULL); - - test::CompareCharArraysWithHexError("constructed packet", - data->data(), data->length(), - AsChars(packet), arraysize(packet)); -} - -TEST_P(QuicFramerTest, AckFrame500Nacks15) { - if (framer_.version() != QUIC_VERSION_15) { - return; - } - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xA8, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags (entropy) - 0x01, - - // frame type (ack frame) - // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) - 0x6C, - // entropy hash of sent packets till least awaiting - 1. - 0xAB, - // least packet sequence number awaiting an ack, delta from sequence number. - 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, - // entropy hash of all received packets. - 0xBA, - // largest observed packet sequence number - 0xBF, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // Zero delta time. - 0x0, 0x0, - // num missing packet ranges - 0x02, - // missing packet delta - 0x01, - // 243 more missing packets in range. - // The ranges are listed in this order so the re-constructed packet matches. - 0xF3, - // No gap between ranges - 0x00, - // 255 more missing packets in range. - 0xFF, - // No revived packets. - 0x00, - }; - - QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); - EXPECT_TRUE(framer_.ProcessPacket(encrypted)); - - EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); - ASSERT_TRUE(visitor_.header_.get()); - EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); - - EXPECT_EQ(0u, visitor_.stream_frames_.size()); - ASSERT_EQ(1u, visitor_.ack_frames_.size()); - QuicAckFrame* frame = visitor_.ack_frames_[0]; - EXPECT_EQ(0xAB, frame->sent_info.entropy_hash); - EXPECT_EQ(0xBA, frame->received_info.entropy_hash); - EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), - frame->received_info.largest_observed); - EXPECT_EQ(0u, frame->received_info.revived_packets.size()); - ASSERT_EQ(500u, frame->received_info.missing_packets.size()); + EXPECT_EQ(0xBA, frame->entropy_hash); + EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame->largest_observed); + EXPECT_EQ(0u, frame->revived_packets.size()); + ASSERT_EQ(500u, frame->missing_packets.size()); SequenceNumberSet::const_iterator first_missing_iter = - frame->received_info.missing_packets.begin(); + frame->missing_packets.begin(); EXPECT_EQ(GG_UINT64_C(0x0123456789ABE) - 499, *first_missing_iter); SequenceNumberSet::const_reverse_iterator last_missing_iter = - frame->received_info.missing_packets.rbegin(); + frame->missing_packets.rbegin(); EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter); - EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame->sent_info.least_unacked); // Verify that the packet re-serializes identically. QuicFrames frames; @@ -2518,58 +2135,6 @@ TEST_P(QuicFramerTest, CongestionFeedbackFrameInterArrival) { } } -TEST_P(QuicFramerTest, CongestionFeedbackFrameFixRate) { - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xBC, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags - 0x00, - - // frame type (congestion feedback frame) - 0x20, - // congestion feedback type (fix rate) - 0x02, - // bitrate_in_bytes_per_second; - 0x01, 0x02, 0x03, 0x04, - }; - - QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); - EXPECT_TRUE(framer_.ProcessPacket(encrypted)); - - EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); - ASSERT_TRUE(visitor_.header_.get()); - EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); - - EXPECT_EQ(0u, visitor_.stream_frames_.size()); - ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); - const QuicCongestionFeedbackFrame& frame = - *visitor_.congestion_feedback_frames_[0]; - ASSERT_EQ(kFixRate, frame.type); - EXPECT_EQ(static_cast<uint32>(0x04030201), - frame.fix_rate.bitrate.ToBytesPerSecond()); - - // Now test framing boundaries - for (size_t i = kQuicFrameTypeSize; i < 6; ++i) { - string expected_error; - if (i < 2) { - expected_error = "Unable to read congestion feedback type."; - } else if (i < 6) { - expected_error = "Unable to read bitrate."; - } - CheckProcessingFails( - packet, - i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, - PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), - expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); - } -} - TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { unsigned char packet[] = { // public flags (8 byte connection_id) @@ -2596,9 +2161,6 @@ TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { } TEST_P(QuicFramerTest, StopWaitingFrame) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } unsigned char packet[] = { // public flags (8 byte connection_id) 0x3C, @@ -2701,7 +2263,7 @@ TEST_P(QuicFramerTest, RstStreamFrameQuic) { // Now test framing boundaries for (size_t i = kQuicFrameTypeSize; - i < QuicFramer::GetMinRstStreamFrameSize(version_); ++i) { + i < QuicFramer::GetMinRstStreamFrameSize(); ++i) { string expected_error; if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { expected_error = "Unable to read stream_id."; @@ -3582,9 +3144,6 @@ TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { } TEST_P(QuicFramerTest, BuildAckFramePacket) { - if (version_ <= QUIC_VERSION_15) { - return; - } QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); header.public_header.reset_flag = false; @@ -3595,10 +3154,10 @@ TEST_P(QuicFramerTest, BuildAckFramePacket) { header.fec_group = 0; QuicAckFrame ack_frame; - ack_frame.received_info.entropy_hash = 0x43; - ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); - ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); - ack_frame.received_info.missing_packets.insert( + ack_frame.entropy_hash = 0x43; + ack_frame.largest_observed = GG_UINT64_C(0x770123456789ABF); + ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); + ack_frame.missing_packets.insert( GG_UINT64_C(0x770123456789ABE)); QuicFrames frames; @@ -3644,82 +3203,9 @@ TEST_P(QuicFramerTest, BuildAckFramePacket) { AsChars(packet), arraysize(packet)); } -TEST_P(QuicFramerTest, BuildAckFramePacket15) { - if (version_ != QUIC_VERSION_15) { - return; - } - QuicPacketHeader header; - header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); - header.public_header.reset_flag = false; - header.public_header.version_flag = false; - header.fec_flag = false; - header.entropy_flag = true; - header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); - header.fec_group = 0; - - QuicAckFrame ack_frame; - ack_frame.received_info.entropy_hash = 0x43; - ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); - ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); - ack_frame.received_info.missing_packets.insert( - GG_UINT64_C(0x770123456789ABE)); - ack_frame.sent_info.entropy_hash = 0x14; - ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0); - - QuicFrames frames; - frames.push_back(QuicFrame(&ack_frame)); - - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xA8, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags (entropy) - 0x01, - - // frame type (ack frame) - // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) - 0x6C, - // entropy hash of sent packets till least awaiting - 1. - 0x14, - // least packet sequence number awaiting an ack, delta from sequence number. - 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, - // entropy hash of all received packets. - 0x43, - // largest observed packet sequence number - 0xBF, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // Zero delta time. - 0x0, 0x0, - // num missing packet ranges - 0x01, - // missing packet delta - 0x01, - // 0 more missing packets in range. - 0x00, - // 0 revived packets. - 0x00, - }; - - scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); - ASSERT_TRUE(data != NULL); - - test::CompareCharArraysWithHexError("constructed packet", - data->data(), data->length(), - AsChars(packet), arraysize(packet)); -} - // TODO(jri): Add test for tuncated packets in which the original ack frame had // revived packets. (In both the large and small packet cases below). TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) { - if (version_ <= QUIC_VERSION_15) { - return; - } QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); header.public_header.reset_flag = false; @@ -3733,11 +3219,11 @@ TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) { // This entropy hash is different from what shows up in the packet below, // since entropy is recomputed by the framer on ack truncation (by // TestEntropyCalculator for this test.) - ack_frame.received_info.entropy_hash = 0x43; - ack_frame.received_info.largest_observed = 2 * 300; - ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); + ack_frame.entropy_hash = 0x43; + ack_frame.largest_observed = 2 * 300; + ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); for (size_t i = 1; i < 2 * 300; i += 2) { - ack_frame.received_info.missing_packets.insert(i); + ack_frame.missing_packets.insert(i); } QuicFrames frames; @@ -3833,9 +3319,6 @@ TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) { TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) { - if (version_ <= QUIC_VERSION_15) { - return; - } QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); header.public_header.reset_flag = false; @@ -3849,11 +3332,11 @@ TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) { // This entropy hash is different from what shows up in the packet below, // since entropy is recomputed by the framer on ack truncation (by // TestEntropyCalculator for this test.) - ack_frame.received_info.entropy_hash = 0x43; - ack_frame.received_info.largest_observed = 2 * 300; - ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); + ack_frame.entropy_hash = 0x43; + ack_frame.largest_observed = 2 * 300; + ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); for (size_t i = 1; i < 2 * 300; i += 2) { - ack_frame.received_info.missing_packets.insert(i); + ack_frame.missing_packets.insert(i); } QuicFrames frames; @@ -4016,9 +3499,6 @@ TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInterArrival) { } TEST_P(QuicFramerTest, BuildStopWaitingPacket) { - if (version_ <= QUIC_VERSION_15) { - return; - } QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); header.public_header.reset_flag = false; @@ -4064,52 +3544,6 @@ TEST_P(QuicFramerTest, BuildStopWaitingPacket) { AsChars(packet), arraysize(packet)); } -TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketFixRate) { - QuicPacketHeader header; - header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); - header.public_header.reset_flag = false; - header.public_header.version_flag = false; - header.fec_flag = false; - header.entropy_flag = false; - header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); - header.fec_group = 0; - - QuicCongestionFeedbackFrame congestion_feedback_frame; - congestion_feedback_frame.type = kFixRate; - congestion_feedback_frame.fix_rate.bitrate - = QuicBandwidth::FromBytesPerSecond(0x04030201); - - QuicFrames frames; - frames.push_back(QuicFrame(&congestion_feedback_frame)); - - unsigned char packet[] = { - // public flags (8 byte connection_id) - 0x3C, - // connection_id - 0x10, 0x32, 0x54, 0x76, - 0x98, 0xBA, 0xDC, 0xFE, - // packet sequence number - 0xBC, 0x9A, 0x78, 0x56, - 0x34, 0x12, - // private flags - 0x00, - - // frame type (congestion feedback frame) - 0x20, - // congestion feedback type (fix rate) - 0x02, - // bitrate_in_bytes_per_second; - 0x01, 0x02, 0x03, 0x04, - }; - - scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); - ASSERT_TRUE(data != NULL); - - test::CompareCharArraysWithHexError("constructed packet", - data->data(), data->length(), - AsChars(packet), arraysize(packet)); -} - TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) { QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); @@ -4122,7 +3556,7 @@ TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) { QuicCongestionFeedbackFrame congestion_feedback_frame; congestion_feedback_frame.type = - static_cast<CongestionFeedbackType>(kFixRate + 1); + static_cast<CongestionFeedbackType>(kInterArrival + 1); QuicFrames frames; frames.push_back(QuicFrame(&congestion_feedback_frame)); @@ -4640,9 +4074,6 @@ TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { } TEST_P(QuicFramerTest, AckTruncationLargePacket) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); header.public_header.reset_flag = false; @@ -4671,21 +4102,18 @@ TEST_P(QuicFramerTest, AckTruncationLargePacket) { ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); ASSERT_EQ(1u, visitor_.ack_frames_.size()); QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; - EXPECT_TRUE(processed_ack_frame.received_info.is_truncated); - EXPECT_EQ(510u, processed_ack_frame.received_info.largest_observed); - ASSERT_EQ(255u, processed_ack_frame.received_info.missing_packets.size()); + EXPECT_TRUE(processed_ack_frame.is_truncated); + EXPECT_EQ(510u, processed_ack_frame.largest_observed); + ASSERT_EQ(255u, processed_ack_frame.missing_packets.size()); SequenceNumberSet::const_iterator missing_iter = - processed_ack_frame.received_info.missing_packets.begin(); + processed_ack_frame.missing_packets.begin(); EXPECT_EQ(1u, *missing_iter); SequenceNumberSet::const_reverse_iterator last_missing_iter = - processed_ack_frame.received_info.missing_packets.rbegin(); + processed_ack_frame.missing_packets.rbegin(); EXPECT_EQ(509u, *last_missing_iter); } TEST_P(QuicFramerTest, AckTruncationSmallPacket) { - if (framer_.version() <= QUIC_VERSION_15) { - return; - } QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); header.public_header.reset_flag = false; @@ -4714,68 +4142,17 @@ TEST_P(QuicFramerTest, AckTruncationSmallPacket) { ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); ASSERT_EQ(1u, visitor_.ack_frames_.size()); QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; - EXPECT_TRUE(processed_ack_frame.received_info.is_truncated); - EXPECT_EQ(476u, processed_ack_frame.received_info.largest_observed); - ASSERT_EQ(238u, processed_ack_frame.received_info.missing_packets.size()); + EXPECT_TRUE(processed_ack_frame.is_truncated); + EXPECT_EQ(476u, processed_ack_frame.largest_observed); + ASSERT_EQ(238u, processed_ack_frame.missing_packets.size()); SequenceNumberSet::const_iterator missing_iter = - processed_ack_frame.received_info.missing_packets.begin(); + processed_ack_frame.missing_packets.begin(); EXPECT_EQ(1u, *missing_iter); SequenceNumberSet::const_reverse_iterator last_missing_iter = - processed_ack_frame.received_info.missing_packets.rbegin(); + processed_ack_frame.missing_packets.rbegin(); EXPECT_EQ(475u, *last_missing_iter); } -TEST_P(QuicFramerTest, Truncation15) { - if (framer_.version() > QUIC_VERSION_15) { - return; - } - QuicPacketHeader header; - header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); - header.public_header.reset_flag = false; - header.public_header.version_flag = false; - header.fec_flag = false; - header.entropy_flag = false; - header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); - header.fec_group = 0; - - QuicAckFrame ack_frame; - ack_frame.received_info.largest_observed = 601; - ack_frame.sent_info.least_unacked = header.packet_sequence_number - 1; - for (uint64 i = 1; i < ack_frame.received_info.largest_observed; i += 2) { - ack_frame.received_info.missing_packets.insert(i); - } - - // Create a packet with just the ack. - QuicFrame frame; - frame.type = ACK_FRAME; - frame.ack_frame = &ack_frame; - QuicFrames frames; - frames.push_back(frame); - - scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); - ASSERT_TRUE(raw_ack_packet != NULL); - - scoped_ptr<QuicEncryptedPacket> ack_packet( - framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number, - *raw_ack_packet)); - - // Now make sure we can turn our ack packet back into an ack frame. - ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); - ASSERT_EQ(1u, visitor_.ack_frames_.size()); - const QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; - EXPECT_EQ(header.packet_sequence_number - 1, - processed_ack_frame.sent_info.least_unacked); - EXPECT_TRUE(processed_ack_frame.received_info.is_truncated); - EXPECT_EQ(510u, processed_ack_frame.received_info.largest_observed); - ASSERT_EQ(255u, processed_ack_frame.received_info.missing_packets.size()); - SequenceNumberSet::const_iterator missing_iter = - processed_ack_frame.received_info.missing_packets.begin(); - EXPECT_EQ(1u, *missing_iter); - SequenceNumberSet::const_reverse_iterator last_missing_iter = - processed_ack_frame.received_info.missing_packets.rbegin(); - EXPECT_EQ(509u, *last_missing_iter); -} - TEST_P(QuicFramerTest, CleanTruncation) { QuicPacketHeader header; header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); @@ -4787,10 +4164,9 @@ TEST_P(QuicFramerTest, CleanTruncation) { header.fec_group = 0; QuicAckFrame ack_frame; - ack_frame.received_info.largest_observed = 201; - ack_frame.sent_info.least_unacked = header.packet_sequence_number - 2; - for (uint64 i = 1; i < ack_frame.received_info.largest_observed; ++i) { - ack_frame.received_info.missing_packets.insert(i); + ack_frame.largest_observed = 201; + for (uint64 i = 1; i < ack_frame.largest_observed; ++i) { + ack_frame.missing_packets.insert(i); } // Create a packet with just the ack. diff --git a/net/quic/quic_packet_creator.cc b/net/quic/quic_packet_creator.cc index 3b86654..4ad38bb 100644 --- a/net/quic/quic_packet_creator.cc +++ b/net/quic/quic_packet_creator.cc @@ -207,14 +207,13 @@ bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, // is_in_fec_group a parameter. Same as with all public methods in // QuicPacketCreator. return BytesFree() > - QuicFramer::GetMinStreamFrameSize(framer_->version(), id, offset, true, + QuicFramer::GetMinStreamFrameSize(id, offset, true, should_fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); } // static size_t QuicPacketCreator::StreamFramePacketOverhead( - QuicVersion version, QuicConnectionIdLength connection_id_length, bool include_version, QuicSequenceNumberLength sequence_number_length, @@ -223,8 +222,7 @@ size_t QuicPacketCreator::StreamFramePacketOverhead( return GetPacketHeaderSize(connection_id_length, include_version, sequence_number_length, is_in_fec_group) + // Assumes this is a stream with a single lone packet. - QuicFramer::GetMinStreamFrameSize(version, 1u, offset, true, - is_in_fec_group); + QuicFramer::GetMinStreamFrameSize(1u, offset, true, is_in_fec_group); } size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, @@ -233,7 +231,7 @@ size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, bool fin, QuicFrame* frame) { DCHECK_GT(max_packet_length_, StreamFramePacketOverhead( - framer_->version(), PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, + PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, offset, IN_FEC_GROUP)); InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec(); @@ -241,8 +239,7 @@ size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset)) << "No room for Stream frame, BytesFree: " << BytesFree() << " MinStreamFrameSize: " - << QuicFramer::GetMinStreamFrameSize( - framer_->version(), id, offset, true, is_in_fec_group); + << QuicFramer::GetMinStreamFrameSize(id, offset, true, is_in_fec_group); if (data.Empty()) { LOG_IF(DFATAL, !fin) @@ -254,8 +251,7 @@ size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, const size_t data_size = data.TotalBufferSize(); size_t min_frame_size = QuicFramer::GetMinStreamFrameSize( - framer_->version(), id, offset, /*last_frame_in_packet=*/ true, - is_in_fec_group); + id, offset, /* last_frame_in_packet= */ true, is_in_fec_group); size_t bytes_consumed = min<size_t>(BytesFree() - min_frame_size, data_size); bool set_fin = fin && bytes_consumed == data_size; // Last frame. diff --git a/net/quic/quic_packet_creator.h b/net/quic/quic_packet_creator.h index cd6c587..ef466c8 100644 --- a/net/quic/quic_packet_creator.h +++ b/net/quic/quic_packet_creator.h @@ -69,7 +69,6 @@ class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface { // The overhead the framing will add for a packet with one frame. static size_t StreamFramePacketOverhead( - QuicVersion version, QuicConnectionIdLength connection_id_length, bool include_version, QuicSequenceNumberLength sequence_number_length, diff --git a/net/quic/quic_packet_creator_test.cc b/net/quic/quic_packet_creator_test.cc index 6612c78..c8d5686 100644 --- a/net/quic/quic_packet_creator_test.cc +++ b/net/quic/quic_packet_creator_test.cc @@ -118,8 +118,7 @@ class QuicPacketCreatorTest : public ::testing::TestWithParam<TestParams> { // Returns the number of bytes consumed by the non-data fields of a stream // frame, assuming it is the last frame in the packet size_t GetStreamFrameOverhead(InFecGroup is_in_fec_group) { - return QuicFramer::GetMinStreamFrameSize(client_framer_.version(), - kClientDataStreamId1, kOffset, + return QuicFramer::GetMinStreamFrameSize(kClientDataStreamId1, kOffset, true, is_in_fec_group); } @@ -151,7 +150,7 @@ INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests, ::testing::ValuesIn(GetTestParams())); TEST_P(QuicPacketCreatorTest, SerializeFrames) { - frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); + frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector()))); frames_.push_back(QuicFrame(new QuicStreamFrame(0u, true, 0u, IOVector()))); SerializedPacket serialized = creator_.SerializeAllFrames(frames_); @@ -223,7 +222,7 @@ TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { } TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { - frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); + frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); creator_.AddSavedFrame(frames_[0]); creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER); SerializedPacket serialized = creator_.SerializePacket(); @@ -264,9 +263,6 @@ TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { } TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { - if (GetParam().version <= QUIC_VERSION_15) { - return; - } // Changing the sequence number length with queued frames in the creator // should hold the change until after any currently queued frames are // serialized. @@ -274,7 +270,7 @@ TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { // Packet 1. // Queue a frame in the creator. EXPECT_FALSE(creator_.HasPendingFrames()); - QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u))); + QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); creator_.AddSavedFrame(ack_frame); // Now change sequence number length. @@ -353,7 +349,7 @@ TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) { // Should return false since we do not have enough packets in the FEC group to // trigger an FEC packet. ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); - frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); + frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); // Generate Packet 1. creator_.AddSavedFrame(frames_[0]); @@ -871,12 +867,13 @@ TEST_P(QuicPacketCreatorTest, AddFrameAndSerialize) { creator_.BytesFree()); // Add a variety of frame types and then a padding frame. - QuicAckFrame ack_frame(MakeAckFrame(0u, 0u)); + QuicAckFrame ack_frame(MakeAckFrame(0u)); EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); EXPECT_TRUE(creator_.HasPendingFrames()); QuicCongestionFeedbackFrame congestion_feedback; - congestion_feedback.type = kFixRate; + congestion_feedback.type = kTCP; + congestion_feedback.tcp.receive_window = 0x4030; EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&congestion_feedback))); EXPECT_TRUE(creator_.HasPendingFrames()); diff --git a/net/quic/quic_packet_generator_test.cc b/net/quic/quic_packet_generator_test.cc index a400833..081161e 100644 --- a/net/quic/quic_packet_generator_test.cc +++ b/net/quic/quic_packet_generator_test.cc @@ -136,13 +136,13 @@ class QuicPacketGeneratorTest : public ::testing::Test { QuicAckFrame* CreateAckFrame() { // TODO(rch): Initialize this so it can be verified later. - return new QuicAckFrame(MakeAckFrame(0, 0)); + return new QuicAckFrame(MakeAckFrame(0)); } QuicCongestionFeedbackFrame* CreateFeedbackFrame() { QuicCongestionFeedbackFrame* frame = new QuicCongestionFeedbackFrame; - frame->type = kFixRate; - frame->fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(42); + frame->type = kTCP; + frame->tcp.receive_window = 0x4030; return frame; } @@ -526,10 +526,8 @@ TEST_F(QuicPacketGeneratorTest, ConsumeData_FramesPreviouslyQueued) { NOT_IN_FEC_GROUP) + // Add an extra 3 bytes for the payload and 1 byte so BytesFree is larger // than the GetMinStreamFrameSize. - QuicFramer::GetMinStreamFrameSize(framer_.version(), 1, 0, false, - NOT_IN_FEC_GROUP) + 3 + - QuicFramer::GetMinStreamFrameSize(framer_.version(), 1, 0, true, - NOT_IN_FEC_GROUP) + 1; + QuicFramer::GetMinStreamFrameSize(1, 0, false, NOT_IN_FEC_GROUP) + 3 + + QuicFramer::GetMinStreamFrameSize(1, 0, true, NOT_IN_FEC_GROUP) + 1; creator_->set_max_packet_length(length); delegate_.SetCanWriteAnything(); { diff --git a/net/quic/quic_protocol.cc b/net/quic/quic_protocol.cc index f0b8b68..a197502 100644 --- a/net/quic/quic_protocol.cc +++ b/net/quic/quic_protocol.cc @@ -159,8 +159,6 @@ QuicVersionVector QuicSupportedVersions() { QuicTag QuicVersionToQuicTag(const QuicVersion version) { switch (version) { - case QUIC_VERSION_15: - return MakeQuicTag('Q', '0', '1', '5'); case QUIC_VERSION_16: return MakeQuicTag('Q', '0', '1', '6'); case QUIC_VERSION_18: @@ -197,7 +195,6 @@ return #x string QuicVersionToString(const QuicVersion version) { switch (version) { - RETURN_STRING_LITERAL(QUIC_VERSION_15); RETURN_STRING_LITERAL(QUIC_VERSION_16); RETURN_STRING_LITERAL(QUIC_VERSION_18); RETURN_STRING_LITERAL(QUIC_VERSION_19); @@ -241,25 +238,17 @@ ostream& operator<<(ostream& os, const QuicPacketHeader& header) { return os; } -ReceivedPacketInfo::ReceivedPacketInfo() - : entropy_hash(0), - largest_observed(0), - delta_time_largest_observed(QuicTime::Delta::Infinite()), - is_truncated(false) {} - -ReceivedPacketInfo::~ReceivedPacketInfo() {} - -bool IsAwaitingPacket(const ReceivedPacketInfo& received_info, +bool IsAwaitingPacket(const QuicAckFrame& ack_frame, QuicPacketSequenceNumber sequence_number) { - return sequence_number > received_info.largest_observed || - ContainsKey(received_info.missing_packets, sequence_number); + return sequence_number > ack_frame.largest_observed || + ContainsKey(ack_frame.missing_packets, sequence_number); } -void InsertMissingPacketsBetween(ReceivedPacketInfo* received_info, +void InsertMissingPacketsBetween(QuicAckFrame* ack_frame, QuicPacketSequenceNumber lower, QuicPacketSequenceNumber higher) { for (QuicPacketSequenceNumber i = lower; i < higher; ++i) { - received_info->missing_packets.insert(i); + ack_frame->missing_packets.insert(i); } } @@ -270,7 +259,13 @@ QuicStopWaitingFrame::QuicStopWaitingFrame() QuicStopWaitingFrame::~QuicStopWaitingFrame() {} -QuicAckFrame::QuicAckFrame() {} +QuicAckFrame::QuicAckFrame() + : entropy_hash(0), + largest_observed(0), + delta_time_largest_observed(QuicTime::Delta::Infinite()), + is_truncated(false) {} + +QuicAckFrame::~QuicAckFrame() {} CongestionFeedbackMessageTCP::CongestionFeedbackMessageTCP() : receive_window(0) { @@ -384,22 +379,20 @@ ostream& operator<<(ostream& os, const QuicStopWaitingFrame& sent_info) { return os; } -ostream& operator<<(ostream& os, const ReceivedPacketInfo& received_info) { - os << "entropy_hash: " << static_cast<int>(received_info.entropy_hash) - << " is_truncated: " << received_info.is_truncated - << " largest_observed: " << received_info.largest_observed +ostream& operator<<(ostream& os, const QuicAckFrame& ack_frame) { + os << "entropy_hash: " << static_cast<int>(ack_frame.entropy_hash) + << " is_truncated: " << ack_frame.is_truncated + << " largest_observed: " << ack_frame.largest_observed << " delta_time_largest_observed: " - << received_info.delta_time_largest_observed.ToMicroseconds() + << ack_frame.delta_time_largest_observed.ToMicroseconds() << " missing_packets: [ "; - for (SequenceNumberSet::const_iterator it = - received_info.missing_packets.begin(); - it != received_info.missing_packets.end(); ++it) { + for (SequenceNumberSet::const_iterator it = ack_frame.missing_packets.begin(); + it != ack_frame.missing_packets.end(); ++it) { os << *it << " "; } os << " ] revived_packets: [ "; - for (SequenceNumberSet::const_iterator it = - received_info.revived_packets.begin(); - it != received_info.revived_packets.end(); ++it) { + for (SequenceNumberSet::const_iterator it = ack_frame.revived_packets.begin(); + it != ack_frame.revived_packets.end(); ++it) { os << *it << " "; } os << " ]"; @@ -450,6 +443,10 @@ ostream& operator<<(ostream& os, const QuicFrame& frame) { os << "type { STOP_WAITING_FRAME } " << *(frame.stop_waiting_frame); break; } + case PING_FRAME: { + os << "type { PING_FRAME } "; + break; + } default: { LOG(ERROR) << "Unknown frame type: " << frame.type; break; @@ -501,12 +498,6 @@ ostream& operator<<(ostream& os, const QuicStreamFrame& stream_frame) { return os; } -ostream& operator<<(ostream& os, const QuicAckFrame& ack_frame) { - os << "sent info { " << ack_frame.sent_info << " } " - << "received info { " << ack_frame.received_info << " }\n"; - return os; -} - ostream& operator<<(ostream& os, const QuicCongestionFeedbackFrame& congestion_frame) { os << "type: " << congestion_frame.type; @@ -523,11 +514,6 @@ ostream& operator<<(ostream& os, os << "]"; break; } - case kFixRate: { - os << " bitrate_in_bytes_per_second: " - << congestion_frame.fix_rate.bitrate.ToBytesPerSecond(); - break; - } case kTCP: { const CongestionFeedbackMessageTCP& tcp = congestion_frame.tcp; os << " receive_window: " << tcp.receive_window; @@ -537,10 +523,6 @@ ostream& operator<<(ostream& os, return os; } -CongestionFeedbackMessageFixRate::CongestionFeedbackMessageFixRate() - : bitrate(QuicBandwidth::Zero()) { -} - QuicGoAwayFrame::QuicGoAwayFrame() : error_code(QUIC_NO_ERROR), last_good_stream_id(0) { diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h index e0c3c04..ec94e4c 100644 --- a/net/quic/quic_protocol.h +++ b/net/quic/quic_protocol.h @@ -49,7 +49,7 @@ typedef uint32 QuicPriority; // TODO(rch): Consider Quic specific names for these constants. // Default and initial maximum size in bytes of a QUIC packet. -const QuicByteCount kDefaultMaxPacketSize = 1200; +const QuicByteCount kDefaultMaxPacketSize = 1350; // The maximum packet size of any QUIC packet, based on ethernet's max size, // minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's @@ -273,7 +273,6 @@ enum QuicVersion { // Special case to indicate unknown/unsupported QUIC version. QUIC_VERSION_UNSUPPORTED = 0, - QUIC_VERSION_15 = 15, // Revived packets in ReceivedPacketInfo. QUIC_VERSION_16 = 16, // STOP_WAITING frame. QUIC_VERSION_18 = 18, // PING frame. QUIC_VERSION_19 = 19, // Connection level flow control. @@ -286,14 +285,13 @@ enum QuicVersion { // element, with subsequent elements in descending order (versions can be // skipped as necessary). // -// IMPORTANT: if you are addding to this list, follow the instructions at +// IMPORTANT: if you are adding to this list, follow the instructions at // http://sites/quic/adding-and-removing-versions static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_21, QUIC_VERSION_20, QUIC_VERSION_19, QUIC_VERSION_18, - QUIC_VERSION_16, - QUIC_VERSION_15}; + QUIC_VERSION_16}; typedef std::vector<QuicVersion> QuicVersionVector; @@ -633,12 +631,25 @@ typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet; // TODO(pwestin): Add a way to enforce the max size of this map. typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap; -struct NET_EXPORT_PRIVATE ReceivedPacketInfo { - ReceivedPacketInfo(); - ~ReceivedPacketInfo(); +struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { + QuicStopWaitingFrame(); + ~QuicStopWaitingFrame(); + + NET_EXPORT_PRIVATE friend std::ostream& operator<<( + std::ostream& os, const QuicStopWaitingFrame& s); + // Entropy hash of all packets up to, but not including, the least unacked + // packet. + QuicPacketEntropyHash entropy_hash; + // The lowest packet we've sent which is unacked, and we expect an ack for. + QuicPacketSequenceNumber least_unacked; +}; + +struct NET_EXPORT_PRIVATE QuicAckFrame { + QuicAckFrame(); + ~QuicAckFrame(); NET_EXPORT_PRIVATE friend std::ostream& operator<<( - std::ostream& os, const ReceivedPacketInfo& s); + std::ostream& os, const QuicAckFrame& s); // Entropy hash of all packets up to largest observed not including missing // packets. @@ -675,46 +686,21 @@ struct NET_EXPORT_PRIVATE ReceivedPacketInfo { // as missing. // Always returns false for sequence numbers less than least_unacked. bool NET_EXPORT_PRIVATE IsAwaitingPacket( - const ReceivedPacketInfo& received_info, + const QuicAckFrame& ack_frame, QuicPacketSequenceNumber sequence_number); // Inserts missing packets between [lower, higher). void NET_EXPORT_PRIVATE InsertMissingPacketsBetween( - ReceivedPacketInfo* received_info, + QuicAckFrame* ack_frame, QuicPacketSequenceNumber lower, QuicPacketSequenceNumber higher); -struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { - QuicStopWaitingFrame(); - ~QuicStopWaitingFrame(); - - NET_EXPORT_PRIVATE friend std::ostream& operator<<( - std::ostream& os, const QuicStopWaitingFrame& s); - - // Entropy hash of all packets up to, but not including, the least unacked - // packet. - QuicPacketEntropyHash entropy_hash; - // The lowest packet we've sent which is unacked, and we expect an ack for. - QuicPacketSequenceNumber least_unacked; -}; - -struct NET_EXPORT_PRIVATE QuicAckFrame { - QuicAckFrame(); - - NET_EXPORT_PRIVATE friend std::ostream& operator<<( - std::ostream& os, const QuicAckFrame& s); - - QuicStopWaitingFrame sent_info; - ReceivedPacketInfo received_info; -}; - // Defines for all types of congestion feedback that will be negotiated in QUIC, // kTCP MUST be supported by all QUIC implementations to guarantee 100% // compatibility. enum CongestionFeedbackType { kTCP, // Used to mimic TCP. kInterArrival, // Use additional inter arrival information. - kFixRate, // Provided for testing. }; // Defines for all types of congestion control algorithms that can be used in @@ -724,7 +710,6 @@ enum CongestionFeedbackType { enum CongestionControlType { kCubic, kReno, - kFixRateCongestionControl, // Provided for testing. kBBR, }; @@ -748,11 +733,6 @@ struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival { TimeMap received_packet_times; }; -struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate { - CongestionFeedbackMessageFixRate(); - QuicBandwidth bitrate; -}; - struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame { QuicCongestionFeedbackFrame(); ~QuicCongestionFeedbackFrame(); @@ -765,7 +745,6 @@ struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame { // is non-trivial, C++ prohibits it. CongestionFeedbackMessageTCP tcp; CongestionFeedbackMessageInterArrival inter_arrival; - CongestionFeedbackMessageFixRate fix_rate; }; struct NET_EXPORT_PRIVATE QuicRstStreamFrame { diff --git a/net/quic/quic_protocol_test.cc b/net/quic/quic_protocol_test.cc index 8eef5be..9f03900 100644 --- a/net/quic/quic_protocol_test.cc +++ b/net/quic/quic_protocol_test.cc @@ -35,23 +35,23 @@ TEST(QuicProtocolTest, MakeQuicTag) { } TEST(QuicProtocolTest, IsAawaitingPacket) { - ReceivedPacketInfo received_info; - received_info.largest_observed = 10u; - EXPECT_TRUE(IsAwaitingPacket(received_info, 11u)); - EXPECT_FALSE(IsAwaitingPacket(received_info, 1u)); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 10u; + EXPECT_TRUE(IsAwaitingPacket(ack_frame, 11u)); + EXPECT_FALSE(IsAwaitingPacket(ack_frame, 1u)); - received_info.missing_packets.insert(10); - EXPECT_TRUE(IsAwaitingPacket(received_info, 10u)); + ack_frame.missing_packets.insert(10); + EXPECT_TRUE(IsAwaitingPacket(ack_frame, 10u)); } TEST(QuicProtocolTest, InsertMissingPacketsBetween) { - ReceivedPacketInfo received_info; - InsertMissingPacketsBetween(&received_info, 4u, 10u); - EXPECT_EQ(6u, received_info.missing_packets.size()); + QuicAckFrame ack_frame; + InsertMissingPacketsBetween(&ack_frame, 4u, 10u); + EXPECT_EQ(6u, ack_frame.missing_packets.size()); QuicPacketSequenceNumber i = 4; - for (SequenceNumberSet::iterator it = received_info.missing_packets.begin(); - it != received_info.missing_packets.end(); ++it, ++i) { + for (SequenceNumberSet::iterator it = ack_frame.missing_packets.begin(); + it != ack_frame.missing_packets.end(); ++it, ++i) { EXPECT_EQ(i, *it); } } diff --git a/net/quic/quic_received_packet_manager.cc b/net/quic/quic_received_packet_manager.cc index 1a1a1d3..a915e62 100644 --- a/net/quic/quic_received_packet_manager.cc +++ b/net/quic/quic_received_packet_manager.cc @@ -135,8 +135,8 @@ QuicReceivedPacketManager::QuicReceivedPacketManager( time_largest_observed_(QuicTime::Zero()), receive_algorithm_(ReceiveAlgorithmInterface::Create(congestion_type)), stats_(stats) { - received_info_.largest_observed = 0; - received_info_.entropy_hash = 0; + ack_frame_.largest_observed = 0; + ack_frame_.entropy_hash = 0; } QuicReceivedPacketManager::~QuicReceivedPacketManager() {} @@ -149,19 +149,19 @@ void QuicReceivedPacketManager::RecordPacketReceived( DCHECK(IsAwaitingPacket(sequence_number)); InsertMissingPacketsBetween( - &received_info_, - max(received_info_.largest_observed + 1, peer_least_packet_awaiting_ack_), + &ack_frame_, + max(ack_frame_.largest_observed + 1, peer_least_packet_awaiting_ack_), sequence_number); - if (received_info_.largest_observed > sequence_number) { + if (ack_frame_.largest_observed > sequence_number) { // We've gotten one of the out of order packets - remove it from our // "missing packets" list. DVLOG(1) << "Removing " << sequence_number << " from missing list"; - received_info_.missing_packets.erase(sequence_number); + ack_frame_.missing_packets.erase(sequence_number); // Record how out of order stats. ++stats_->packets_reordered; - uint32 sequence_gap = received_info_.largest_observed - sequence_number; + uint32 sequence_gap = ack_frame_.largest_observed - sequence_number; stats_->max_sequence_reordering = max(stats_->max_sequence_reordering, sequence_gap); uint32 reordering_time_us = @@ -169,8 +169,8 @@ void QuicReceivedPacketManager::RecordPacketReceived( stats_->max_time_reordering_us = max(stats_->max_time_reordering_us, reordering_time_us); } - if (sequence_number > received_info_.largest_observed) { - received_info_.largest_observed = sequence_number; + if (sequence_number > ack_frame_.largest_observed) { + ack_frame_.largest_observed = sequence_number; time_largest_observed_ = receipt_time; } entropy_tracker_.RecordPacketEntropyHash(sequence_number, @@ -179,44 +179,43 @@ void QuicReceivedPacketManager::RecordPacketReceived( receive_algorithm_->RecordIncomingPacket( bytes, sequence_number, receipt_time); - received_info_.revived_packets.erase(sequence_number); + ack_frame_.revived_packets.erase(sequence_number); } void QuicReceivedPacketManager::RecordPacketRevived( QuicPacketSequenceNumber sequence_number) { LOG_IF(DFATAL, !IsAwaitingPacket(sequence_number)); - received_info_.revived_packets.insert(sequence_number); + ack_frame_.revived_packets.insert(sequence_number); } bool QuicReceivedPacketManager::IsMissing( QuicPacketSequenceNumber sequence_number) { - return ContainsKey(received_info_.missing_packets, sequence_number); + return ContainsKey(ack_frame_.missing_packets, sequence_number); } bool QuicReceivedPacketManager::IsAwaitingPacket( QuicPacketSequenceNumber sequence_number) { - return ::net::IsAwaitingPacket(received_info_, sequence_number); + return ::net::IsAwaitingPacket(ack_frame_, sequence_number); } void QuicReceivedPacketManager::UpdateReceivedPacketInfo( - ReceivedPacketInfo* received_info, - QuicTime approximate_now) { - *received_info = received_info_; - received_info->entropy_hash = EntropyHash(received_info_.largest_observed); + QuicAckFrame* ack_frame, QuicTime approximate_now) { + *ack_frame = ack_frame_; + ack_frame->entropy_hash = EntropyHash(ack_frame_.largest_observed); if (time_largest_observed_ == QuicTime::Zero()) { // We have received no packets. - received_info->delta_time_largest_observed = QuicTime::Delta::Infinite(); + ack_frame->delta_time_largest_observed = QuicTime::Delta::Infinite(); return; } if (approximate_now < time_largest_observed_) { // Approximate now may well be "in the past". - received_info->delta_time_largest_observed = QuicTime::Delta::Zero(); + ack_frame->delta_time_largest_observed = QuicTime::Delta::Zero(); return; } - received_info->delta_time_largest_observed = + ack_frame->delta_time_largest_observed = approximate_now.Subtract(time_largest_observed_); } @@ -231,28 +230,28 @@ QuicPacketEntropyHash QuicReceivedPacketManager::EntropyHash( } void QuicReceivedPacketManager::UpdatePacketInformationReceivedByPeer( - const ReceivedPacketInfo& received_info) { + const QuicAckFrame& ack_frame) { // ValidateAck should fail if largest_observed ever shrinks. - DCHECK_LE(peer_largest_observed_packet_, received_info.largest_observed); - peer_largest_observed_packet_ = received_info.largest_observed; + DCHECK_LE(peer_largest_observed_packet_, ack_frame.largest_observed); + peer_largest_observed_packet_ = ack_frame.largest_observed; - if (received_info.missing_packets.empty()) { + if (ack_frame.missing_packets.empty()) { least_packet_awaited_by_peer_ = peer_largest_observed_packet_ + 1; } else { - least_packet_awaited_by_peer_ = *(received_info.missing_packets.begin()); + least_packet_awaited_by_peer_ = *(ack_frame.missing_packets.begin()); } } bool QuicReceivedPacketManager::DontWaitForPacketsBefore( QuicPacketSequenceNumber least_unacked) { - received_info_.revived_packets.erase( - received_info_.revived_packets.begin(), - received_info_.revived_packets.lower_bound(least_unacked)); - size_t missing_packets_count = received_info_.missing_packets.size(); - received_info_.missing_packets.erase( - received_info_.missing_packets.begin(), - received_info_.missing_packets.lower_bound(least_unacked)); - return missing_packets_count != received_info_.missing_packets.size(); + ack_frame_.revived_packets.erase( + ack_frame_.revived_packets.begin(), + ack_frame_.revived_packets.lower_bound(least_unacked)); + size_t missing_packets_count = ack_frame_.missing_packets.size(); + ack_frame_.missing_packets.erase( + ack_frame_.missing_packets.begin(), + ack_frame_.missing_packets.lower_bound(least_unacked)); + return missing_packets_count != ack_frame_.missing_packets.size(); } void QuicReceivedPacketManager::UpdatePacketInformationSentByPeer( @@ -270,19 +269,19 @@ void QuicReceivedPacketManager::UpdatePacketInformationSentByPeer( } peer_least_packet_awaiting_ack_ = stop_waiting.least_unacked; } - DCHECK(received_info_.missing_packets.empty() || - *received_info_.missing_packets.begin() >= + DCHECK(ack_frame_.missing_packets.empty() || + *ack_frame_.missing_packets.begin() >= peer_least_packet_awaiting_ack_); } bool QuicReceivedPacketManager::HasMissingPackets() { - return !received_info_.missing_packets.empty(); + return !ack_frame_.missing_packets.empty(); } bool QuicReceivedPacketManager::HasNewMissingPackets() { return HasMissingPackets() && - (received_info_.largest_observed - - *received_info_.missing_packets.rbegin()) <= kMaxPacketsAfterNewMissing; + (ack_frame_.largest_observed - + *ack_frame_.missing_packets.rbegin()) <= kMaxPacketsAfterNewMissing; } } // namespace net diff --git a/net/quic/quic_received_packet_manager.h b/net/quic/quic_received_packet_manager.h index 1b28331..b63d292 100644 --- a/net/quic/quic_received_packet_manager.h +++ b/net/quic/quic_received_packet_manager.h @@ -115,7 +115,7 @@ class NET_EXPORT_PRIVATE QuicReceivedPacketManager : bool IsAwaitingPacket(QuicPacketSequenceNumber sequence_number); // Update the |received_info| for an outgoing ack. - void UpdateReceivedPacketInfo(ReceivedPacketInfo* received_info, + void UpdateReceivedPacketInfo(QuicAckFrame* ack_frame, QuicTime approximate_now); // Should be called before sending an ACK packet, to decide if we need @@ -132,8 +132,7 @@ class NET_EXPORT_PRIVATE QuicReceivedPacketManager : QuicPacketSequenceNumber sequence_number) const OVERRIDE; // Updates internal state based on |received_info|. - void UpdatePacketInformationReceivedByPeer( - const ReceivedPacketInfo& received_nfo); + void UpdatePacketInformationReceivedByPeer(const QuicAckFrame& ack_frame); // Updates internal state based on |stop_waiting|. void UpdatePacketInformationSentByPeer( const QuicStopWaitingFrame& stop_waiting); @@ -181,7 +180,7 @@ class NET_EXPORT_PRIVATE QuicReceivedPacketManager : QuicPacketSequenceNumber peer_least_packet_awaiting_ack_; // Received packet information used to produce acks. - ReceivedPacketInfo received_info_; + QuicAckFrame ack_frame_; // The time we received the largest_observed sequence number, or zero if // no sequence numbers have been received since UpdateReceivedPacketInfo. diff --git a/net/quic/quic_received_packet_manager_test.cc b/net/quic/quic_received_packet_manager_test.cc index b2a52c8..4d203a3f 100644 --- a/net/quic/quic_received_packet_manager_test.cc +++ b/net/quic/quic_received_packet_manager_test.cc @@ -307,18 +307,18 @@ TEST_F(QuicReceivedPacketManagerTest, UpdateReceivedPacketInfo) { QuicTime two_ms = QuicTime::Zero().Add(QuicTime::Delta::FromMilliseconds(2)); received_manager_.RecordPacketReceived(0u, header, two_ms); - ReceivedPacketInfo info; - received_manager_.UpdateReceivedPacketInfo(&info, QuicTime::Zero()); + QuicAckFrame ack; + received_manager_.UpdateReceivedPacketInfo(&ack, QuicTime::Zero()); // When UpdateReceivedPacketInfo with a time earlier than the time of the // largest observed packet, make sure that the delta is 0, not negative. - EXPECT_EQ(QuicTime::Delta::Zero(), info.delta_time_largest_observed); + EXPECT_EQ(QuicTime::Delta::Zero(), ack.delta_time_largest_observed); QuicTime four_ms = QuicTime::Zero().Add(QuicTime::Delta::FromMilliseconds(4)); - received_manager_.UpdateReceivedPacketInfo(&info, four_ms); + received_manager_.UpdateReceivedPacketInfo(&ack, four_ms); // When UpdateReceivedPacketInfo after not having received a new packet, // the delta should still be accurate. EXPECT_EQ(QuicTime::Delta::FromMilliseconds(2), - info.delta_time_largest_observed); + ack.delta_time_largest_observed); } TEST_F(QuicReceivedPacketManagerTest, UpdateReceivedConnectionStats) { @@ -337,12 +337,12 @@ TEST_F(QuicReceivedPacketManagerTest, RevivedPacket) { RecordPacketReceipt(3, 0); RecordPacketRevived(2); - ReceivedPacketInfo info; - received_manager_.UpdateReceivedPacketInfo(&info, QuicTime::Zero()); - EXPECT_EQ(1u, info.missing_packets.size()); - EXPECT_EQ(2u, *info.missing_packets.begin()); - EXPECT_EQ(1u, info.revived_packets.size()); - EXPECT_EQ(2u, *info.missing_packets.begin()); + QuicAckFrame ack; + received_manager_.UpdateReceivedPacketInfo(&ack, QuicTime::Zero()); + EXPECT_EQ(1u, ack.missing_packets.size()); + EXPECT_EQ(2u, *ack.missing_packets.begin()); + EXPECT_EQ(1u, ack.revived_packets.size()); + EXPECT_EQ(2u, *ack.missing_packets.begin()); } TEST_F(QuicReceivedPacketManagerTest, PacketRevivedThenReceived) { @@ -351,10 +351,10 @@ TEST_F(QuicReceivedPacketManagerTest, PacketRevivedThenReceived) { RecordPacketRevived(2); RecordPacketReceipt(2, 0); - ReceivedPacketInfo info; - received_manager_.UpdateReceivedPacketInfo(&info, QuicTime::Zero()); - EXPECT_TRUE(info.missing_packets.empty()); - EXPECT_TRUE(info.revived_packets.empty()); + QuicAckFrame ack; + received_manager_.UpdateReceivedPacketInfo(&ack, QuicTime::Zero()); + EXPECT_TRUE(ack.missing_packets.empty()); + EXPECT_TRUE(ack.revived_packets.empty()); } diff --git a/net/quic/quic_sent_packet_manager.cc b/net/quic/quic_sent_packet_manager.cc index c51b744..f233d8b 100644 --- a/net/quic/quic_sent_packet_manager.cc +++ b/net/quic/quic_sent_packet_manager.cc @@ -177,27 +177,26 @@ void QuicSentPacketManager::OnRetransmittedPacket( } } -void QuicSentPacketManager::OnIncomingAck( - const ReceivedPacketInfo& received_info, - QuicTime ack_receive_time) { +void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, + QuicTime ack_receive_time) { QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); // We rely on delta_time_largest_observed to compute an RTT estimate, so // we only update rtt when the largest observed gets acked. - bool largest_observed_acked = MaybeUpdateRTT(received_info, ack_receive_time); - if (largest_observed_ < received_info.largest_observed) { - largest_observed_ = received_info.largest_observed; + bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); + if (largest_observed_ < ack_frame.largest_observed) { + largest_observed_ = ack_frame.largest_observed; unacked_packets_.IncreaseLargestObserved(largest_observed_); } - HandleAckForSentPackets(received_info); + HandleAckForSentPackets(ack_frame); InvokeLossDetection(ack_receive_time); MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); // If we have received a truncated ack, then we need to clear out some // previous transmissions to allow the peer to actually ACK new packets. - if (received_info.is_truncated) { + if (ack_frame.is_truncated) { unacked_packets_.ClearPreviousRetransmissions( - received_info.missing_packets.size() / 2); + ack_frame.missing_packets.size() / 2); } // Anytime we are making forward progress and have a new RTT estimate, reset @@ -210,11 +209,11 @@ void QuicSentPacketManager::OnIncomingAck( } if (debug_delegate_ != NULL) { - debug_delegate_->OnIncomingAck(received_info, - ack_receive_time, - largest_observed_, - largest_observed_acked, - GetLeastUnackedSentPacket()); + debug_delegate_->OnIncomingAck(ack_frame, + ack_receive_time, + largest_observed_, + largest_observed_acked, + GetLeastUnackedSentPacket()); } } @@ -233,26 +232,26 @@ void QuicSentPacketManager::MaybeInvokeCongestionEvent( } void QuicSentPacketManager::HandleAckForSentPackets( - const ReceivedPacketInfo& received_info) { + const QuicAckFrame& ack_frame) { // Go through the packets we have not received an ack for and see if this // incoming_ack shows they've been seen by the peer. QuicTime::Delta delta_largest_observed = - received_info.delta_time_largest_observed; + ack_frame.delta_time_largest_observed; QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); while (it != unacked_packets_.end()) { QuicPacketSequenceNumber sequence_number = it->first; - if (sequence_number > received_info.largest_observed) { + if (sequence_number > ack_frame.largest_observed) { // These packets are still in flight. break; } - if (IsAwaitingPacket(received_info, sequence_number)) { + if (IsAwaitingPacket(ack_frame, sequence_number)) { // Consider it multiple nacks when there is a gap between the missing // packet and the largest observed, since the purpose of a nack // threshold is to tolerate re-ordering. This handles both StretchAcks // and Forward Acks. // The nack count only increases when the largest observed increases. - size_t min_nacks = received_info.largest_observed - sequence_number; + size_t min_nacks = ack_frame.largest_observed - sequence_number; // Truncated acks can nack the largest observed, so use a min of 1. if (min_nacks == 0) { min_nacks = 1; @@ -273,8 +272,8 @@ void QuicSentPacketManager::HandleAckForSentPackets( // Discard any retransmittable frames associated with revived packets. for (SequenceNumberSet::const_iterator revived_it = - received_info.revived_packets.begin(); - revived_it != received_info.revived_packets.end(); ++revived_it) { + ack_frame.revived_packets.begin(); + revived_it != ack_frame.revived_packets.end(); ++revived_it) { MarkPacketRevived(*revived_it, delta_largest_observed); } } @@ -705,15 +704,15 @@ void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { } bool QuicSentPacketManager::MaybeUpdateRTT( - const ReceivedPacketInfo& received_info, + const QuicAckFrame& ack_frame, const QuicTime& ack_receive_time) { - if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { + if (!unacked_packets_.IsUnacked(ack_frame.largest_observed)) { return false; } // We calculate the RTT based on the highest ACKed sequence number, the lower // sequence numbers will include the ACK aggregation delay. const TransmissionInfo& transmission_info = - unacked_packets_.GetTransmissionInfo(received_info.largest_observed); + unacked_packets_.GetTransmissionInfo(ack_frame.largest_observed); // Don't update the RTT if it hasn't been sent. if (transmission_info.sent_time == QuicTime::Zero()) { return false; @@ -722,7 +721,7 @@ bool QuicSentPacketManager::MaybeUpdateRTT( QuicTime::Delta send_delta = ack_receive_time.Subtract(transmission_info.sent_time); rtt_stats_.UpdateRtt( - send_delta, received_info.delta_time_largest_observed, ack_receive_time); + send_delta, ack_frame.delta_time_largest_observed, ack_receive_time); return true; } diff --git a/net/quic/quic_sent_packet_manager.h b/net/quic/quic_sent_packet_manager.h index 4ebe151..1bedf5a 100644 --- a/net/quic/quic_sent_packet_manager.h +++ b/net/quic/quic_sent_packet_manager.h @@ -65,7 +65,7 @@ class NET_EXPORT_PRIVATE QuicSentPacketManager { QuicTime time) {} virtual void OnIncomingAck( - const ReceivedPacketInfo& received_info, + const QuicAckFrame& ack_frame, QuicTime ack_receive_time, QuicPacketSequenceNumber largest_observed, bool largest_observed_acked, @@ -122,7 +122,7 @@ class NET_EXPORT_PRIVATE QuicSentPacketManager { QuicPacketSequenceNumber new_sequence_number); // Processes the incoming ack. - void OnIncomingAck(const ReceivedPacketInfo& received_info, + void OnIncomingAck(const QuicAckFrame& ack_frame, QuicTime ack_receive_time); // Returns true if the non-FEC packet |sequence_number| is unacked. @@ -250,7 +250,7 @@ class NET_EXPORT_PRIVATE QuicSentPacketManager { TransmissionType> PendingRetransmissionMap; // Process the incoming ack looking for newly ack'd data packets. - void HandleAckForSentPackets(const ReceivedPacketInfo& received_info); + void HandleAckForSentPackets(const QuicAckFrame& ack_frame); // Returns the current retransmission mode. RetransmissionTimeoutMode GetRetransmissionMode() const; @@ -272,7 +272,7 @@ class NET_EXPORT_PRIVATE QuicSentPacketManager { // Update the RTT if the ack is for the largest acked sequence number. // Returns true if the rtt was updated. - bool MaybeUpdateRTT(const ReceivedPacketInfo& received_info, + bool MaybeUpdateRTT(const QuicAckFrame& ack_frame, const QuicTime& ack_receive_time); // Invokes the loss detection algorithm and loses and retransmits packets if diff --git a/net/quic/quic_sent_packet_manager_test.cc b/net/quic/quic_sent_packet_manager_test.cc index 99ed479..275b210 100644 --- a/net/quic/quic_sent_packet_manager_test.cc +++ b/net/quic/quic_sent_packet_manager_test.cc @@ -44,7 +44,7 @@ class MockDebugDelegate : public QuicSentPacketManager::DebugDelegate { class QuicSentPacketManagerTest : public ::testing::TestWithParam<bool> { protected: QuicSentPacketManagerTest() - : manager_(true, &clock_, &stats_, kFixRateCongestionControl, kNack), + : manager_(true, &clock_, &stats_, kCubic, kNack), send_algorithm_(new StrictMock<MockSendAlgorithm>), network_change_visitor_(new StrictMock<MockNetworkChangeVisitor>) { QuicSentPacketManagerPeer::SetSendAlgorithm(&manager_, send_algorithm_); @@ -301,11 +301,11 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAck) { RetransmitAndSendPacket(1, 2); // Ack 2 but not 1. - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - received_info.missing_packets.insert(1); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + ack_frame.missing_packets.insert(1); ExpectAck(2); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); // Packet 1 is unacked, pending, but not retransmittable. QuicPacketSequenceNumber unacked[] = { 1 }; @@ -321,10 +321,10 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckBeforeSend) { EXPECT_TRUE(manager_.HasPendingRetransmissions()); // Ack 1. - ReceivedPacketInfo received_info; - received_info.largest_observed = 1; + QuicAckFrame ack_frame; + ack_frame.largest_observed = 1; ExpectAck(1); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); // There should no longer be a pending retransmission. EXPECT_FALSE(manager_.HasPendingRetransmissions()); @@ -343,9 +343,9 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPrevious) { // Ack 1 but not 2. ExpectAck(1); - ReceivedPacketInfo received_info; - received_info.largest_observed = 1; - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 1; + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); // 2 should be unacked, since it may provide an RTT measurement. QuicPacketSequenceNumber unacked[] = { 2 }; @@ -367,9 +367,9 @@ TEST_F(QuicSentPacketManagerTest, RetransmitAndSendThenAckPrevious) { // Ack 1 but not 2. ExpectAck(1); - ReceivedPacketInfo received_info; - received_info.largest_observed = 1; - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 1; + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); // 2 remains unacked, but no packets have retransmittable data. QuicPacketSequenceNumber unacked[] = { 2 }; @@ -392,9 +392,9 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPreviousThenNackRetransmit) { // First, ACK packet 1 which makes packet 2 non-retransmittable. ExpectAck(1); - ReceivedPacketInfo received_info; - received_info.largest_observed = 1; - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 1; + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); SendDataPacket(3); SendDataPacket(4); @@ -402,18 +402,18 @@ TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPreviousThenNackRetransmit) { clock_.AdvanceTime(rtt); // Next, NACK packet 2 three times. - received_info.largest_observed = 3; - received_info.missing_packets.insert(2); + ack_frame.largest_observed = 3; + ack_frame.missing_packets.insert(2); ExpectAck(3); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); - received_info.largest_observed = 4; + ack_frame.largest_observed = 4; ExpectAck(4); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); - received_info.largest_observed = 5; + ack_frame.largest_observed = 5; ExpectAckAndLoss(true, 5, 2); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); // No packets remain unacked. VerifyUnackedPackets(NULL, 0); @@ -440,11 +440,11 @@ TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckPreviousBeforeSend) { // Ack 1 but not 2, before 2 is able to be sent. // Since 1 has been retransmitted, it has already been lost, and so the // send algorithm is not informed that it has been ACK'd. - ReceivedPacketInfo received_info; - received_info.largest_observed = 1; + QuicAckFrame ack_frame; + ack_frame.largest_observed = 1; ExpectUpdatedRtt(1); EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); // Since 2 was marked for retransmit, when 1 is acked, 2 is kept for RTT. QuicPacketSequenceNumber unacked[] = { 2 }; @@ -471,9 +471,9 @@ TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckFirst) { // Ack 1 but not 2 or 3. ExpectAck(1); - ReceivedPacketInfo received_info; - received_info.largest_observed = 1; - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 1; + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); // 2 and 3 remain unacked, but no packets have retransmittable data. QuicPacketSequenceNumber unacked[] = { 2, 3 }; @@ -483,20 +483,20 @@ TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckFirst) { // Ensure packet 2 is lost when 4 is sent and 3 and 4 are acked. SendDataPacket(4); - received_info.largest_observed = 4; - received_info.missing_packets.insert(2); + ack_frame.largest_observed = 4; + ack_frame.missing_packets.insert(2); QuicPacketSequenceNumber acked[] = { 3, 4 }; ExpectAcksAndLosses(true, acked, arraysize(acked), NULL, 0); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); QuicPacketSequenceNumber unacked2[] = { 2 }; VerifyUnackedPackets(unacked2, arraysize(unacked2)); EXPECT_TRUE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); SendDataPacket(5); - received_info.largest_observed = 5; + ack_frame.largest_observed = 5; ExpectAckAndLoss(true, 5, 2); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); VerifyUnackedPackets(NULL, 0); EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); @@ -510,13 +510,13 @@ TEST_F(QuicSentPacketManagerTest, LoseButDontRetransmitRevivedPacket) { SendDataPacket(4); // Ack 2 and 3, and mark 1 as revived. - ReceivedPacketInfo received_info; - received_info.largest_observed = 3; - received_info.missing_packets.insert(1); - received_info.revived_packets.insert(1); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 3; + ack_frame.missing_packets.insert(1); + ack_frame.revived_packets.insert(1); QuicPacketSequenceNumber acked[] = { 2, 3 }; ExpectAcksAndLosses(true, acked, arraysize(acked), NULL, 0); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(manager_.HasPendingRetransmissions()); QuicPacketSequenceNumber unacked[] = { 1, 4 }; @@ -526,9 +526,9 @@ TEST_F(QuicSentPacketManagerTest, LoseButDontRetransmitRevivedPacket) { VerifyRetransmittablePackets(retransmittable, arraysize(retransmittable)); // Ack the 4th packet and expect the 1st to be considered lost. - received_info.largest_observed = 4; + ack_frame.largest_observed = 4; ExpectAckAndLoss(true, 4, 1); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(manager_.HasPendingRetransmissions()); VerifyRetransmittablePackets(NULL, 0); @@ -542,13 +542,13 @@ TEST_F(QuicSentPacketManagerTest, MarkLostThenReviveAndDontRetransmitPacket) { SendFecPacket(5); // Ack 2, 3, and 4, and expect the 1st to be considered lost. - ReceivedPacketInfo received_info; - received_info.largest_observed = 4; - received_info.missing_packets.insert(1); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 4; + ack_frame.missing_packets.insert(1); QuicPacketSequenceNumber acked[] = { 2, 3, 4 }; QuicPacketSequenceNumber lost[] = { 1 }; ExpectAcksAndLosses(true, acked, arraysize(acked), lost, arraysize(lost)); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_TRUE(manager_.HasPendingRetransmissions()); QuicPacketSequenceNumber unacked[] = { 1, 5 }; @@ -558,10 +558,10 @@ TEST_F(QuicSentPacketManagerTest, MarkLostThenReviveAndDontRetransmitPacket) { // Ack 5th packet (FEC) and revive 1st packet. 1st packet should now be // removed from pending retransmissions map. - received_info.largest_observed = 5; - received_info.revived_packets.insert(1); + ack_frame.largest_observed = 5; + ack_frame.revived_packets.insert(1); ExpectAck(5); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(manager_.HasPendingRetransmissions()); VerifyRetransmittablePackets(NULL, 0); @@ -575,17 +575,17 @@ TEST_F(QuicSentPacketManagerTest, TruncatedAck) { RetransmitAndSendPacket(4, 5); // Truncated ack with 4 NACKs, so the first packet is lost. - ReceivedPacketInfo received_info; - received_info.largest_observed = 4; - received_info.missing_packets.insert(1); - received_info.missing_packets.insert(2); - received_info.missing_packets.insert(3); - received_info.missing_packets.insert(4); - received_info.is_truncated = true; + QuicAckFrame ack_frame; + ack_frame.largest_observed = 4; + ack_frame.missing_packets.insert(1); + ack_frame.missing_packets.insert(2); + ack_frame.missing_packets.insert(3); + ack_frame.missing_packets.insert(4); + ack_frame.is_truncated = true; QuicPacketSequenceNumber lost[] = { 1 }; ExpectAcksAndLosses(true, NULL, 0, lost, arraysize(lost)); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); // High water mark will be raised. QuicPacketSequenceNumber unacked[] = { 2, 3, 4, 5 }; @@ -607,25 +607,25 @@ TEST_F(QuicSentPacketManagerTest, AckPreviousTransmissionThenTruncatedAck) { // Ack previous transmission { - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - received_info.missing_packets.insert(1); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + ack_frame.missing_packets.insert(1); ExpectAck(2); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_TRUE(manager_.IsUnacked(4)); } // Truncated ack with 4 NACKs { - ReceivedPacketInfo received_info; - received_info.largest_observed = 6; - received_info.missing_packets.insert(3); - received_info.missing_packets.insert(4); - received_info.missing_packets.insert(5); - received_info.missing_packets.insert(6); - received_info.is_truncated = true; + QuicAckFrame ack_frame; + ack_frame.largest_observed = 6; + ack_frame.missing_packets.insert(3); + ack_frame.missing_packets.insert(4); + ack_frame.missing_packets.insert(5); + ack_frame.missing_packets.insert(6); + ack_frame.is_truncated = true; ExpectAckAndLoss(false, 1, 3); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); } // High water mark will be raised. @@ -673,9 +673,9 @@ TEST_F(QuicSentPacketManagerTest, GetLeastUnackedPacketAndDiscard) { VerifyRetransmittablePackets(NULL, 0); // Ack 2, which has never been sent, so there's no rtt update. - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - manager_.OnIncomingAck(received_info, clock_.Now()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_EQ(3u, manager_.GetLeastUnackedSentPacket()); } @@ -713,20 +713,20 @@ TEST_F(QuicSentPacketManagerTest, AckAckAndUpdateRtt) { SendAckPacket(2); // Now ack the ack and expect an RTT update. - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - received_info.delta_time_largest_observed = + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + ack_frame.delta_time_largest_observed = QuicTime::Delta::FromMilliseconds(5); ExpectAck(1); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); SendAckPacket(3); // Now ack the ack and expect only an RTT update. - received_info.largest_observed = 3; + ack_frame.largest_observed = 3; ExpectUpdatedRtt(3); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); } TEST_F(QuicSentPacketManagerTest, Rtt) { @@ -736,11 +736,11 @@ TEST_F(QuicSentPacketManagerTest, Rtt) { clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); ExpectAck(sequence_number); - ReceivedPacketInfo received_info; - received_info.largest_observed = sequence_number; - received_info.delta_time_largest_observed = + QuicAckFrame ack_frame; + ack_frame.largest_observed = sequence_number; + ack_frame.delta_time_largest_observed = QuicTime::Delta::FromMilliseconds(5); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_EQ(expected_rtt, QuicSentPacketManagerPeer::GetRttStats(&manager_)->latest_rtt()); } @@ -755,11 +755,11 @@ TEST_F(QuicSentPacketManagerTest, RttWithInvalidDelta) { clock_.AdvanceTime(expected_rtt); ExpectAck(sequence_number); - ReceivedPacketInfo received_info; - received_info.largest_observed = sequence_number; - received_info.delta_time_largest_observed = + QuicAckFrame ack_frame; + ack_frame.largest_observed = sequence_number; + ack_frame.delta_time_largest_observed = QuicTime::Delta::FromMilliseconds(11); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_EQ(expected_rtt, QuicSentPacketManagerPeer::GetRttStats(&manager_)->latest_rtt()); } @@ -773,10 +773,10 @@ TEST_F(QuicSentPacketManagerTest, RttWithInfiniteDelta) { clock_.AdvanceTime(expected_rtt); ExpectAck(sequence_number); - ReceivedPacketInfo received_info; - received_info.largest_observed = sequence_number; - received_info.delta_time_largest_observed = QuicTime::Delta::Infinite(); - manager_.OnIncomingAck(received_info, clock_.Now()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = sequence_number; + ack_frame.delta_time_largest_observed = QuicTime::Delta::Infinite(); + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_EQ(expected_rtt, QuicSentPacketManagerPeer::GetRttStats(&manager_)->latest_rtt()); } @@ -790,10 +790,10 @@ TEST_F(QuicSentPacketManagerTest, RttZeroDelta) { clock_.AdvanceTime(expected_rtt); ExpectAck(sequence_number); - ReceivedPacketInfo received_info; - received_info.largest_observed = sequence_number; - received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); - manager_.OnIncomingAck(received_info, clock_.Now()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = sequence_number; + ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_EQ(expected_rtt, QuicSentPacketManagerPeer::GetRttStats(&manager_)->latest_rtt()); } @@ -831,19 +831,19 @@ TEST_F(QuicSentPacketManagerTest, TailLossProbeTimeout) { // Ack the third and ensure the first two are still pending. ExpectAck(3); - ReceivedPacketInfo received_info; - received_info.largest_observed = 3; - received_info.missing_packets.insert(1); - received_info.missing_packets.insert(2); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 3; + ack_frame.missing_packets.insert(1); + ack_frame.missing_packets.insert(2); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_TRUE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); // Acking two more packets will lose both of them due to nacks. - received_info.largest_observed = 5; + ack_frame.largest_observed = 5; QuicPacketSequenceNumber lost[] = { 1, 2 }; ExpectAcksAndLosses(false, NULL, 0, lost, arraysize(lost)); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(manager_.HasPendingRetransmissions()); EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); @@ -931,13 +931,13 @@ TEST_F(QuicSentPacketManagerTest, CryptoHandshakeTimeout) { // and ensure the first four crypto packets get abandoned, but not lost. QuicPacketSequenceNumber acked[] = { 3, 4, 5, 8, 9 }; ExpectAcksAndLosses(true, acked, arraysize(acked), NULL, 0); - ReceivedPacketInfo received_info; - received_info.largest_observed = 9; - received_info.missing_packets.insert(1); - received_info.missing_packets.insert(2); - received_info.missing_packets.insert(6); - received_info.missing_packets.insert(7); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 9; + ack_frame.missing_packets.insert(1); + ack_frame.missing_packets.insert(2); + ack_frame.missing_packets.insert(6); + ack_frame.missing_packets.insert(7); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(QuicSentPacketManagerPeer::HasUnackedCryptoPackets(&manager_)); } @@ -991,10 +991,10 @@ TEST_F(QuicSentPacketManagerTest, CryptoHandshakeSpuriousRetransmission) { // Now ack the second crypto packet, and ensure the first gets removed, but // the third does not. ExpectUpdatedRtt(2); - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - received_info.missing_packets.insert(1); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + ack_frame.missing_packets.insert(1); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(QuicSentPacketManagerPeer::HasUnackedCryptoPackets(&manager_)); QuicPacketSequenceNumber unacked[] = { 3 }; @@ -1064,12 +1064,12 @@ TEST_F(QuicSentPacketManagerTest, EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); // Ensure both packets get discarded when packet 2 is acked. - ReceivedPacketInfo received_info; - received_info.largest_observed = 3; - received_info.missing_packets.insert(1); - received_info.missing_packets.insert(2); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 3; + ack_frame.missing_packets.insert(1); + ack_frame.missing_packets.insert(2); ExpectUpdatedRtt(3); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); VerifyUnackedPackets(NULL, 0); VerifyRetransmittablePackets(NULL, 0); } @@ -1116,20 +1116,20 @@ TEST_F(QuicSentPacketManagerTest, ResetRecentMinRTTWithEmptyWindow) { clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); // Ack two packets with 100ms RTT observations. - ReceivedPacketInfo received_info; - received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); - received_info.largest_observed = 1; + QuicAckFrame ack_frame; + ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); + ack_frame.largest_observed = 1; ExpectAck(1); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); // First ack does not change recent min rtt. EXPECT_EQ(min_rtt, QuicSentPacketManagerPeer::GetRttStats( &manager_)->recent_min_rtt()); - received_info.largest_observed = 2; + ack_frame.largest_observed = 2; ExpectAck(2); - manager_.OnIncomingAck(received_info, clock_.Now()); + manager_.OnIncomingAck(ack_frame, clock_.Now()); EXPECT_EQ(min_rtt, QuicSentPacketManagerPeer::GetRttStats(&manager_)->min_rtt()); @@ -1258,12 +1258,12 @@ TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeRTO) { EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); // Ack a packet and ensure the RTO goes back to the original value. - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - received_info.missing_packets.insert(1); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + ack_frame.missing_packets.insert(1); ExpectUpdatedRtt(2); EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); - manager_.OnIncomingAck(received_info, clock_.ApproximateNow()); + manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); EXPECT_FALSE(manager_.HasPendingRetransmissions()); EXPECT_EQ(4 * kDefaultLength, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); @@ -1337,10 +1337,10 @@ TEST_F(QuicSentPacketManagerTest, GetLossDelay) { ExpectAck(2); EXPECT_CALL(*loss_algorithm, DetectLostPackets(_, _, _, _)) .WillOnce(Return(SequenceNumberSet())); - ReceivedPacketInfo received_info; - received_info.largest_observed = 2; - received_info.missing_packets.insert(1); - manager_.OnIncomingAck(received_info, clock_.Now()); + QuicAckFrame ack_frame; + ack_frame.largest_observed = 2; + ack_frame.missing_packets.insert(1); + manager_.OnIncomingAck(ack_frame, clock_.Now()); QuicTime timeout(clock_.Now().Add(QuicTime::Delta::FromMilliseconds(10))); EXPECT_CALL(*loss_algorithm, GetLossTimeout()) diff --git a/net/quic/quic_stream_sequencer.cc b/net/quic/quic_stream_sequencer.cc index 3a30395..5df81e5 100644 --- a/net/quic/quic_stream_sequencer.cc +++ b/net/quic/quic_stream_sequencer.cc @@ -30,18 +30,18 @@ QuicStreamSequencer::QuicStreamSequencer(ReliableQuicStream* quic_stream) QuicStreamSequencer::~QuicStreamSequencer() { } -bool QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { +void QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { ++num_frames_received_; if (IsDuplicate(frame)) { ++num_duplicate_frames_received_; // Silently ignore duplicates. - return true; + return; } if (FrameOverlapsBufferedData(frame)) { stream_->CloseConnectionWithDetails( QUIC_INVALID_STREAM_FRAME, "Stream frame overlaps with buffered data."); - return false; + return; } QuicStreamOffset byte_offset = frame.offset; @@ -50,13 +50,13 @@ bool QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { // Stream frames must have data or a fin flag. stream_->CloseConnectionWithDetails(QUIC_INVALID_STREAM_FRAME, "Empty stream frame without FIN set."); - return false; + return; } if (frame.fin) { CloseStreamAtOffset(frame.offset + data_len); if (data_len == 0) { - return true; + return; } } @@ -77,14 +77,14 @@ bool QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { stream_->AddBytesConsumed(bytes_consumed); if (MaybeCloseStream()) { - return true; + return; } if (bytes_consumed > data_len) { stream_->Reset(QUIC_ERROR_PROCESSING_STREAM); - return false; + return; } else if (bytes_consumed == data_len) { FlushBufferedFrames(); - return true; // it's safe to ack this frame. + return; // it's safe to ack this frame. } else { // Set ourselves up to buffer what's left. data_len -= bytes_consumed; @@ -102,7 +102,7 @@ bool QuicStreamSequencer::OnStreamFrame(const QuicStreamFrame& frame) { byte_offset += iov.iov_len; num_bytes_buffered_ += iov.iov_len; } - return true; + return; } void QuicStreamSequencer::CloseStreamAtOffset(QuicStreamOffset offset) { diff --git a/net/quic/quic_stream_sequencer.h b/net/quic/quic_stream_sequencer.h index a4580a9..5da2c0e 100644 --- a/net/quic/quic_stream_sequencer.h +++ b/net/quic/quic_stream_sequencer.h @@ -36,7 +36,7 @@ class NET_EXPORT_PRIVATE QuicStreamSequencer { // data is processed or the stream fails to consume data. Any unconsumed // data will be buffered. If the frame is not the next in line, it will be // buffered. - bool OnStreamFrame(const QuicStreamFrame& frame); + void OnStreamFrame(const QuicStreamFrame& frame); // Once data is buffered, it's up to the stream to read it when the stream // can handle more data. The following three functions make that possible. diff --git a/net/quic/quic_stream_sequencer_test.cc b/net/quic/quic_stream_sequencer_test.cc index 0d9e82b..c553fe5 100644 --- a/net/quic/quic_stream_sequencer_test.cc +++ b/net/quic/quic_stream_sequencer_test.cc @@ -106,22 +106,22 @@ class QuicStreamSequencerTest : public ::testing::Test { return true; } - bool OnFinFrame(QuicStreamOffset byte_offset, const char* data) { + void OnFinFrame(QuicStreamOffset byte_offset, const char* data) { QuicStreamFrame frame; frame.stream_id = 1; frame.offset = byte_offset; frame.data.Append(const_cast<char*>(data), strlen(data)); frame.fin = true; - return sequencer_->OnStreamFrame(frame); + sequencer_->OnStreamFrame(frame); } - bool OnFrame(QuicStreamOffset byte_offset, const char* data) { + void OnFrame(QuicStreamOffset byte_offset, const char* data) { QuicStreamFrame frame; frame.stream_id = 1; frame.offset = byte_offset; frame.data.Append(const_cast<char*>(data), strlen(data)); frame.fin = false; - return sequencer_->OnStreamFrame(frame); + sequencer_->OnStreamFrame(frame); } MockConnection* connection_; @@ -134,31 +134,31 @@ class QuicStreamSequencerTest : public ::testing::Test { TEST_F(QuicStreamSequencerTest, RejectOldFrame) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(3)); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(0u, buffered_frames_->size()); EXPECT_EQ(3u, sequencer_->num_bytes_consumed()); // Ignore this - it matches a past sequence number and we should not see it // again. - EXPECT_TRUE(OnFrame(0, "def")); + OnFrame(0, "def"); EXPECT_EQ(0u, buffered_frames_->size()); } TEST_F(QuicStreamSequencerTest, RejectBufferedFrame) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); // Ignore this - it matches a buffered frame. // Right now there's no checking that the payload is consistent. - EXPECT_TRUE(OnFrame(0, "def")); + OnFrame(0, "def"); EXPECT_EQ(1u, buffered_frames_->size()); } TEST_F(QuicStreamSequencerTest, FullFrameConsumed) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(3)); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(0u, buffered_frames_->size()); EXPECT_EQ(3u, sequencer_->num_bytes_consumed()); } @@ -166,7 +166,7 @@ TEST_F(QuicStreamSequencerTest, FullFrameConsumed) { TEST_F(QuicStreamSequencerTest, BlockedThenFullFrameConsumed) { sequencer_->SetBlockedUntilFlush(); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); @@ -177,13 +177,13 @@ TEST_F(QuicStreamSequencerTest, BlockedThenFullFrameConsumed) { EXPECT_CALL(stream_, ProcessRawData(StrEq("def"), 3)).WillOnce(Return(3)); EXPECT_CALL(stream_, OnFinRead()); - EXPECT_TRUE(OnFinFrame(3, "def")); + OnFinFrame(3, "def"); } TEST_F(QuicStreamSequencerTest, BlockedThenFullFrameAndFinConsumed) { sequencer_->SetBlockedUntilFlush(); - EXPECT_TRUE(OnFinFrame(0, "abc")); + OnFinFrame(0, "abc"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); @@ -197,14 +197,14 @@ TEST_F(QuicStreamSequencerTest, BlockedThenFullFrameAndFinConsumed) { TEST_F(QuicStreamSequencerTest, EmptyFrame) { EXPECT_CALL(stream_, CloseConnectionWithDetails(QUIC_INVALID_STREAM_FRAME, _)); - EXPECT_FALSE(OnFrame(0, "")); + OnFrame(0, ""); EXPECT_EQ(0u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); } TEST_F(QuicStreamSequencerTest, EmptyFinFrame) { EXPECT_CALL(stream_, OnFinRead()); - EXPECT_TRUE(OnFinFrame(0, "")); + OnFinFrame(0, ""); EXPECT_EQ(0u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); } @@ -212,7 +212,7 @@ TEST_F(QuicStreamSequencerTest, EmptyFinFrame) { TEST_F(QuicStreamSequencerTest, PartialFrameConsumed) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(2)); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(2u, sequencer_->num_bytes_consumed()); EXPECT_EQ("c", buffered_frames_->find(2)->second); @@ -221,14 +221,14 @@ TEST_F(QuicStreamSequencerTest, PartialFrameConsumed) { TEST_F(QuicStreamSequencerTest, NextxFrameNotConsumed) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(0)); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); EXPECT_EQ("abc", buffered_frames_->find(0)->second); } TEST_F(QuicStreamSequencerTest, FutureFrameNotProcessed) { - EXPECT_TRUE(OnFrame(3, "abc")); + OnFrame(3, "abc"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); EXPECT_EQ("abc", buffered_frames_->find(3)->second); @@ -236,12 +236,12 @@ TEST_F(QuicStreamSequencerTest, FutureFrameNotProcessed) { TEST_F(QuicStreamSequencerTest, OutOfOrderFrameProcessed) { // Buffer the first - EXPECT_TRUE(OnFrame(6, "ghi")); + OnFrame(6, "ghi"); EXPECT_EQ(1u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); EXPECT_EQ(3u, sequencer_->num_bytes_buffered()); // Buffer the second - EXPECT_TRUE(OnFrame(3, "def")); + OnFrame(3, "def"); EXPECT_EQ(2u, buffered_frames_->size()); EXPECT_EQ(0u, sequencer_->num_bytes_consumed()); EXPECT_EQ(6u, sequencer_->num_bytes_buffered()); @@ -252,7 +252,7 @@ TEST_F(QuicStreamSequencerTest, OutOfOrderFrameProcessed) { EXPECT_CALL(stream_, ProcessRawData(StrEq("ghi"), 3)).WillOnce(Return(3)); // Ack right away - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); EXPECT_EQ(9u, sequencer_->num_bytes_consumed()); EXPECT_EQ(0u, sequencer_->num_bytes_buffered()); @@ -264,7 +264,7 @@ TEST_F(QuicStreamSequencerTest, BasicHalfCloseOrdered) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(3)); EXPECT_CALL(stream_, OnFinRead()); - EXPECT_TRUE(OnFinFrame(0, "abc")); + OnFinFrame(0, "abc"); EXPECT_EQ(3u, QuicStreamSequencerPeer::GetCloseOffset(sequencer_.get())); } @@ -277,8 +277,8 @@ TEST_F(QuicStreamSequencerTest, BasicHalfCloseUnorderedWithFlush) { EXPECT_CALL(stream_, ProcessRawData(StrEq("def"), 3)).WillOnce(Return(3)); EXPECT_CALL(stream_, OnFinRead()); - EXPECT_TRUE(OnFrame(3, "def")); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(3, "def"); + OnFrame(0, "abc"); } TEST_F(QuicStreamSequencerTest, BasicHalfUnordered) { @@ -288,7 +288,7 @@ TEST_F(QuicStreamSequencerTest, BasicHalfUnordered) { EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(3)); EXPECT_CALL(stream_, OnFinRead()); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); } TEST_F(QuicStreamSequencerTest, TerminateWithReadv) { @@ -300,7 +300,7 @@ TEST_F(QuicStreamSequencerTest, TerminateWithReadv) { EXPECT_FALSE(sequencer_->IsClosed()); EXPECT_CALL(stream_, ProcessRawData(StrEq("abc"), 3)).WillOnce(Return(0)); - EXPECT_TRUE(OnFrame(0, "abc")); + OnFrame(0, "abc"); iovec iov = {&buffer[0], 3}; int bytes_read = sequencer_->Readv(&iov, 1); @@ -374,7 +374,7 @@ TEST_F(QuicSequencerRandomTest, RandomFramesNoDroppingNoBackup) { while (!list_.empty()) { int index = OneToN(list_.size()) - 1; LOG(ERROR) << "Sending index " << index << " " << list_[index].second; - EXPECT_TRUE(OnFrame(list_[index].first, list_[index].second.data())); + OnFrame(list_[index].first, list_[index].second.data()); list_.erase(list_.begin() + index); } diff --git a/net/quic/quic_unacked_packet_map.cc b/net/quic/quic_unacked_packet_map.cc index a07de8b..185d995 100644 --- a/net/quic/quic_unacked_packet_map.cc +++ b/net/quic/quic_unacked_packet_map.cc @@ -80,8 +80,13 @@ void QuicUnackedPacketMap::OnRetransmittedPacket( *(++transmission_info->all_transmissions->begin()) < largest_observed_) { QuicPacketSequenceNumber old_transmission = *transmission_info->all_transmissions->begin(); - transmission_info->all_transmissions->erase(old_transmission); - unacked_packets_.erase(old_transmission); + TransmissionInfo* old_transmission_info = + FindOrNull(unacked_packets_, old_transmission); + // Don't remove old packets if they're still in flight. + if (old_transmission_info == NULL || !old_transmission_info->in_flight) { + transmission_info->all_transmissions->erase(old_transmission); + unacked_packets_.erase(old_transmission); + } } unacked_packets_[new_sequence_number] = TransmissionInfo(frames, diff --git a/net/quic/quic_unacked_packet_map_test.cc b/net/quic/quic_unacked_packet_map_test.cc index 87c6ca8..6e680de 100644 --- a/net/quic/quic_unacked_packet_map_test.cc +++ b/net/quic/quic_unacked_packet_map_test.cc @@ -177,7 +177,7 @@ TEST_F(QuicUnackedPacketMapTest, RetransmittedPacket) { VerifyRetransmittablePackets(NULL, 0); } -TEST_F(QuicUnackedPacketMapTest, RetransmitTwice) { +TEST_F(QuicUnackedPacketMapTest, RetransmitThreeTimes) { // Simulate a retransmittable packet being sent and retransmitted twice. unacked_packets_.AddPacket(CreateRetransmittablePacket(1)); unacked_packets_.SetSent(1, now_, kDefaultLength, true); @@ -211,16 +211,31 @@ TEST_F(QuicUnackedPacketMapTest, RetransmitTwice) { unacked_packets_.IncreaseLargestObserved(4); unacked_packets_.RemoveFromInFlight(4); unacked_packets_.RemoveRetransmittability(4); - unacked_packets_.RemoveFromInFlight(3); unacked_packets_.OnRetransmittedPacket(3, 5, LOSS_RETRANSMISSION); unacked_packets_.SetSent(5, now_, kDefaultLength, true); + unacked_packets_.AddPacket(CreateRetransmittablePacket(6)); + unacked_packets_.SetSent(6, now_, kDefaultLength, true); - QuicPacketSequenceNumber unacked3[] = { 3, 5 }; + QuicPacketSequenceNumber unacked3[] = { 3, 5, 6 }; VerifyUnackedPackets(unacked3, arraysize(unacked3)); - QuicPacketSequenceNumber pending3[] = { 5 }; + QuicPacketSequenceNumber pending3[] = { 3, 5, 6 }; VerifyInFlightPackets(pending3, arraysize(pending3)); - QuicPacketSequenceNumber retransmittable3[] = { 5 }; + QuicPacketSequenceNumber retransmittable3[] = { 5, 6 }; VerifyRetransmittablePackets(retransmittable3, arraysize(retransmittable3)); + + // Early retransmit 5 as 7 and ensure in flight packet 3 is not removed. + unacked_packets_.IncreaseLargestObserved(6); + unacked_packets_.RemoveFromInFlight(6); + unacked_packets_.RemoveRetransmittability(6); + unacked_packets_.OnRetransmittedPacket(5, 7, LOSS_RETRANSMISSION); + unacked_packets_.SetSent(7, now_, kDefaultLength, true); + + QuicPacketSequenceNumber unacked4[] = { 3, 5, 7 }; + VerifyUnackedPackets(unacked4, arraysize(unacked4)); + QuicPacketSequenceNumber pending4[] = { 3, 5, 7 }; + VerifyInFlightPackets(pending4, arraysize(pending4)); + QuicPacketSequenceNumber retransmittable4[] = { 7 }; + VerifyRetransmittablePackets(retransmittable4, arraysize(retransmittable4)); } } // namespace diff --git a/net/quic/reliable_quic_stream.cc b/net/quic/reliable_quic_stream.cc index 7785e72..212b698 100644 --- a/net/quic/reliable_quic_stream.cc +++ b/net/quic/reliable_quic_stream.cc @@ -166,16 +166,16 @@ ReliableQuicStream::ReliableQuicStream(QuicStreamId id, QuicSession* session) ReliableQuicStream::~ReliableQuicStream() { } -bool ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) { +void ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) { if (read_side_closed_) { DVLOG(1) << ENDPOINT << "Ignoring frame " << frame.stream_id; // We don't want to be reading: blackhole the data. - return true; + return; } if (frame.stream_id != id_) { - LOG(ERROR) << "Error!"; - return false; + session_->connection()->SendConnectionClose(QUIC_INTERNAL_ERROR); + return; } if (frame.fin) { @@ -194,11 +194,11 @@ bool ReliableQuicStream::OnStreamFrame(const QuicStreamFrame& frame) { connection_flow_controller_->FlowControlViolation()) { session_->connection()->SendConnectionClose( QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA); - return false; + return; } } - return sequencer_.OnStreamFrame(frame); + sequencer_.OnStreamFrame(frame); } int ReliableQuicStream::num_frames_received() const { diff --git a/net/quic/reliable_quic_stream.h b/net/quic/reliable_quic_stream.h index 84eedec..b9aa8ee 100644 --- a/net/quic/reliable_quic_stream.h +++ b/net/quic/reliable_quic_stream.h @@ -38,9 +38,8 @@ class NET_EXPORT_PRIVATE ReliableQuicStream { virtual ~ReliableQuicStream(); // Called when a (potentially duplicate) stream frame has been received - // for this stream. Returns false if this frame can not be accepted - // because there is too much data already buffered. - virtual bool OnStreamFrame(const QuicStreamFrame& frame); + // for this stream. + virtual void OnStreamFrame(const QuicStreamFrame& frame); // Called when the connection becomes writeable to allow the stream // to write any pending data. diff --git a/net/quic/reliable_quic_stream_test.cc b/net/quic/reliable_quic_stream_test.cc index ea81d6e..f25011d 100644 --- a/net/quic/reliable_quic_stream_test.cc +++ b/net/quic/reliable_quic_stream_test.cc @@ -154,7 +154,7 @@ TEST_F(ReliableQuicStreamTest, WriteAllData) { Initialize(kShouldProcessData); size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( - connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, + PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( length); @@ -214,7 +214,7 @@ TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { EXPECT_FALSE(HasWriteBlockedStreams()); size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( - connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, + PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( length); @@ -249,7 +249,7 @@ TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithFecProtectAlways) { EXPECT_FALSE(HasWriteBlockedStreams()); size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( - connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, + PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, 0u, IN_FEC_GROUP); QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( length); @@ -285,7 +285,7 @@ TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithFecProtectOptional) { EXPECT_FALSE(HasWriteBlockedStreams()); size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( - connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, + PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( length); @@ -650,7 +650,7 @@ TEST_F(ReliableQuicStreamTest, // Stream should not accept the frame, and the connection should be closed. EXPECT_CALL(*connection_, SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)); - EXPECT_FALSE(stream_->OnStreamFrame(frame)); + stream_->OnStreamFrame(frame); } TEST_F(ReliableQuicStreamTest, FinalByteOffsetFromFin) { diff --git a/net/quic/test_tools/quic_connection_peer.cc b/net/quic/test_tools/quic_connection_peer.cc index c4c63c7..6847c1d 100644 --- a/net/quic/test_tools/quic_connection_peer.cc +++ b/net/quic/test_tools/quic_connection_peer.cc @@ -43,6 +43,12 @@ QuicAckFrame* QuicConnectionPeer::CreateAckFrame(QuicConnection* connection) { } // static +QuicStopWaitingFrame* QuicConnectionPeer::CreateStopWaitingFrame( + QuicConnection* connection) { + return connection->CreateStopWaitingFrame(); +} + +// static QuicConnectionVisitorInterface* QuicConnectionPeer::GetVisitor( QuicConnection* connection) { return connection->visitor_; diff --git a/net/quic/test_tools/quic_connection_peer.h b/net/quic/test_tools/quic_connection_peer.h index 11d4814..f6a0bf9 100644 --- a/net/quic/test_tools/quic_connection_peer.h +++ b/net/quic/test_tools/quic_connection_peer.h @@ -44,6 +44,9 @@ class QuicConnectionPeer { static QuicAckFrame* CreateAckFrame(QuicConnection* connection); + static QuicStopWaitingFrame* CreateStopWaitingFrame( + QuicConnection* connection); + static QuicConnectionVisitorInterface* GetVisitor( QuicConnection* connection); diff --git a/net/quic/test_tools/quic_test_packet_maker.cc b/net/quic/test_tools/quic_test_packet_maker.cc index 7f0835f..345b7b5 100644 --- a/net/quic/test_tools/quic_test_packet_maker.cc +++ b/net/quic/test_tools/quic_test_packet_maker.cc @@ -61,8 +61,8 @@ scoped_ptr<QuicEncryptedPacket> QuicTestPacketMaker::MakeAckAndRstPacket( header.fec_flag = false; header.fec_group = 0; - QuicAckFrame ack(MakeAckFrame(largest_received, least_unacked)); - ack.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); + QuicAckFrame ack(MakeAckFrame(largest_received)); + ack.delta_time_largest_observed = QuicTime::Delta::Zero(); QuicFrames frames; frames.push_back(QuicFrame(&ack)); QuicCongestionFeedbackFrame feedback; @@ -74,10 +74,8 @@ scoped_ptr<QuicEncryptedPacket> QuicTestPacketMaker::MakeAckAndRstPacket( } QuicStopWaitingFrame stop_waiting; - if (version_ > QUIC_VERSION_15) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(QuicFrame(&stop_waiting)); - } + stop_waiting.least_unacked = least_unacked; + frames.push_back(QuicFrame(&stop_waiting)); QuicRstStreamFrame rst(stream_id, error_code, 0); frames.push_back(QuicFrame(&rst)); @@ -122,8 +120,8 @@ scoped_ptr<QuicEncryptedPacket> QuicTestPacketMaker::MakeAckPacket( header.fec_flag = false; header.fec_group = 0; - QuicAckFrame ack(MakeAckFrame(largest_received, least_unacked)); - ack.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); + QuicAckFrame ack(MakeAckFrame(largest_received)); + ack.delta_time_largest_observed = QuicTime::Delta::Zero(); QuicCongestionFeedbackFrame feedback; feedback.type = kTCP; @@ -137,10 +135,8 @@ scoped_ptr<QuicEncryptedPacket> QuicTestPacketMaker::MakeAckPacket( } QuicStopWaitingFrame stop_waiting; - if (version_ > QUIC_VERSION_15) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(QuicFrame(&stop_waiting)); - } + stop_waiting.least_unacked = least_unacked; + frames.push_back(QuicFrame(&stop_waiting)); scoped_ptr<QuicPacket> packet( BuildUnsizedDataPacket(&framer, header, frames).packet); diff --git a/net/quic/test_tools/quic_test_utils.cc b/net/quic/test_tools/quic_test_utils.cc index 9b54f94..c781b23 100644 --- a/net/quic/test_tools/quic_test_utils.cc +++ b/net/quic/test_tools/quic_test_utils.cc @@ -43,23 +43,19 @@ class TestAlarm : public QuicAlarm { } // namespace -QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed, - QuicPacketSequenceNumber least_unacked) { +QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed) { QuicAckFrame ack; - ack.received_info.largest_observed = largest_observed; - ack.received_info.entropy_hash = 0; - ack.sent_info.least_unacked = least_unacked; - ack.sent_info.entropy_hash = 0; + ack.largest_observed = largest_observed; + ack.entropy_hash = 0; return ack; } QuicAckFrame MakeAckFrameWithNackRanges( size_t num_nack_ranges, QuicPacketSequenceNumber least_unacked) { - QuicAckFrame ack = MakeAckFrame(2 * num_nack_ranges + least_unacked, - least_unacked); + QuicAckFrame ack = MakeAckFrame(2 * num_nack_ranges + least_unacked); // Add enough missing packets to get num_nack_ranges nack ranges. for (QuicPacketSequenceNumber i = 1; i < 2 * num_nack_ranges; i += 2) { - ack.received_info.missing_packets.insert(least_unacked + i); + ack.missing_packets.insert(least_unacked + i); } return ack; } @@ -562,11 +558,11 @@ size_t GetPacketLengthForOneStream( const size_t stream_length = NullEncrypter().GetCiphertextSize(*payload_length) + QuicPacketCreator::StreamFramePacketOverhead( - version, PACKET_8BYTE_CONNECTION_ID, include_version, + PACKET_8BYTE_CONNECTION_ID, include_version, sequence_number_length, 0u, is_in_fec_group); const size_t ack_length = NullEncrypter().GetCiphertextSize( QuicFramer::GetMinAckFrameSize( - version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) + + sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version, sequence_number_length, is_in_fec_group); if (stream_length < ack_length) { @@ -575,7 +571,7 @@ size_t GetPacketLengthForOneStream( return NullEncrypter().GetCiphertextSize(*payload_length) + QuicPacketCreator::StreamFramePacketOverhead( - version, PACKET_8BYTE_CONNECTION_ID, include_version, + PACKET_8BYTE_CONNECTION_ID, include_version, sequence_number_length, 0u, is_in_fec_group); } diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h index 3bae37f..350bc37 100644 --- a/net/quic/test_tools/quic_test_utils.h +++ b/net/quic/test_tools/quic_test_utils.h @@ -92,8 +92,7 @@ QuicVersionVector SupportedVersions(QuicVersion version); // Testing convenience method to construct a QuicAckFrame with all packets // from least_unacked to largest_observed acked. -QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed, - QuicPacketSequenceNumber least_unacked); +QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed); // Testing convenience method to construct a QuicAckFrame with |num_nack_ranges| // nack ranges of width 1 packet, starting from |least_unacked|. |