OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/tools/quic/quic_server_session.h" | 5 #include "net/tools/quic/quic_server_session.h" |
6 | 6 |
7 #include "net/quic/crypto/quic_crypto_server_config.h" | 7 #include "net/quic/crypto/quic_crypto_server_config.h" |
8 #include "net/quic/crypto/quic_random.h" | 8 #include "net/quic/crypto/quic_random.h" |
9 #include "net/quic/crypto/source_address_token.h" | 9 #include "net/quic/crypto/source_address_token.h" |
10 #include "net/quic/quic_connection.h" | 10 #include "net/quic/quic_connection.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 kMaxStreamsForTest); | 72 kMaxStreamsForTest); |
73 config_.SetInitialFlowControlWindowToSend( | 73 config_.SetInitialFlowControlWindowToSend( |
74 kInitialSessionFlowControlWindowForTest); | 74 kInitialSessionFlowControlWindowForTest); |
75 config_.SetInitialStreamFlowControlWindowToSend( | 75 config_.SetInitialStreamFlowControlWindowToSend( |
76 kInitialStreamFlowControlWindowForTest); | 76 kInitialStreamFlowControlWindowForTest); |
77 config_.SetInitialSessionFlowControlWindowToSend( | 77 config_.SetInitialSessionFlowControlWindowToSend( |
78 kInitialSessionFlowControlWindowForTest); | 78 kInitialSessionFlowControlWindowForTest); |
79 | 79 |
80 connection_ = | 80 connection_ = |
81 new StrictMock<MockConnection>(true, SupportedVersions(GetParam())); | 81 new StrictMock<MockConnection>(true, SupportedVersions(GetParam())); |
82 session_.reset(new QuicServerSession(config_, connection_, &owner_)); | 82 session_.reset(new QuicServerSession(config_, connection_, &owner_, |
| 83 /*is_secure=*/false)); |
83 MockClock clock; | 84 MockClock clock; |
84 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 85 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
85 QuicRandom::GetInstance(), &clock, | 86 QuicRandom::GetInstance(), &clock, |
86 QuicCryptoServerConfig::ConfigOptions())); | 87 QuicCryptoServerConfig::ConfigOptions())); |
87 session_->InitializeSession(crypto_config_); | 88 session_->InitializeSession(crypto_config_); |
88 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 89 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
89 } | 90 } |
90 | 91 |
91 QuicVersion version() const { return connection_->version(); } | 92 QuicVersion version() const { return connection_->version(); } |
92 | 93 |
(...skipping 29 matching lines...) Expand all Loading... |
122 // Open a stream, then reset it. | 123 // Open a stream, then reset it. |
123 // Send two bytes of payload to open it. | 124 // Send two bytes of payload to open it. |
124 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); | 125 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); |
125 vector<QuicStreamFrame> frames; | 126 vector<QuicStreamFrame> frames; |
126 frames.push_back(data1); | 127 frames.push_back(data1); |
127 session_->OnStreamFrames(frames); | 128 session_->OnStreamFrames(frames); |
128 EXPECT_EQ(1u, session_->GetNumOpenStreams()); | 129 EXPECT_EQ(1u, session_->GetNumOpenStreams()); |
129 | 130 |
130 // Send a reset (and expect the peer to send a RST in response). | 131 // Send a reset (and expect the peer to send a RST in response). |
131 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); | 132 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); |
132 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, | 133 EXPECT_CALL(*connection_, |
133 QUIC_RST_FLOW_CONTROL_ACCOUNTING, 0)); | 134 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
134 visitor_->OnRstStream(rst1); | 135 visitor_->OnRstStream(rst1); |
135 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 136 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
136 | 137 |
137 // Send the same two bytes of payload in a new packet. | 138 // Send the same two bytes of payload in a new packet. |
138 visitor_->OnStreamFrames(frames); | 139 visitor_->OnStreamFrames(frames); |
139 | 140 |
140 // The stream should not be re-opened. | 141 // The stream should not be re-opened. |
141 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 142 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
142 EXPECT_TRUE(connection_->connected()); | 143 EXPECT_TRUE(connection_->connected()); |
143 } | 144 } |
144 | 145 |
145 TEST_P(QuicServerSessionTest, NeverOpenStreamDueToReset) { | 146 TEST_P(QuicServerSessionTest, NeverOpenStreamDueToReset) { |
146 // Send a reset (and expect the peer to send a RST in response). | 147 // Send a reset (and expect the peer to send a RST in response). |
147 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); | 148 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); |
148 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, | 149 EXPECT_CALL(*connection_, |
149 QUIC_RST_FLOW_CONTROL_ACCOUNTING, 0)); | 150 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
150 visitor_->OnRstStream(rst1); | 151 visitor_->OnRstStream(rst1); |
151 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 152 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
152 | 153 |
153 // Send two bytes of payload. | 154 // Send two bytes of payload. |
154 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); | 155 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT")); |
155 vector<QuicStreamFrame> frames; | 156 vector<QuicStreamFrame> frames; |
156 frames.push_back(data1); | 157 frames.push_back(data1); |
157 visitor_->OnStreamFrames(frames); | 158 visitor_->OnStreamFrames(frames); |
158 | 159 |
159 // The stream should never be opened, now that the reset is received. | 160 // The stream should never be opened, now that the reset is received. |
160 EXPECT_EQ(0u, session_->GetNumOpenStreams()); | 161 EXPECT_EQ(0u, session_->GetNumOpenStreams()); |
161 EXPECT_TRUE(connection_->connected()); | 162 EXPECT_TRUE(connection_->connected()); |
162 } | 163 } |
163 | 164 |
164 TEST_P(QuicServerSessionTest, AcceptClosedStream) { | 165 TEST_P(QuicServerSessionTest, AcceptClosedStream) { |
165 vector<QuicStreamFrame> frames; | 166 vector<QuicStreamFrame> frames; |
166 // Send (empty) compressed headers followed by two bytes of data. | 167 // Send (empty) compressed headers followed by two bytes of data. |
167 frames.push_back(QuicStreamFrame(kClientDataStreamId1, false, 0, | 168 frames.push_back(QuicStreamFrame(kClientDataStreamId1, false, 0, |
168 MakeIOVector("\1\0\0\0\0\0\0\0HT"))); | 169 MakeIOVector("\1\0\0\0\0\0\0\0HT"))); |
169 frames.push_back(QuicStreamFrame(kClientDataStreamId2, false, 0, | 170 frames.push_back(QuicStreamFrame(kClientDataStreamId2, false, 0, |
170 MakeIOVector("\2\0\0\0\0\0\0\0HT"))); | 171 MakeIOVector("\2\0\0\0\0\0\0\0HT"))); |
171 visitor_->OnStreamFrames(frames); | 172 visitor_->OnStreamFrames(frames); |
172 EXPECT_EQ(2u, session_->GetNumOpenStreams()); | 173 EXPECT_EQ(2u, session_->GetNumOpenStreams()); |
173 | 174 |
174 // Send a reset (and expect the peer to send a RST in response). | 175 // Send a reset (and expect the peer to send a RST in response). |
175 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); | 176 QuicRstStreamFrame rst(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0); |
176 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, | 177 EXPECT_CALL(*connection_, |
177 QUIC_RST_FLOW_CONTROL_ACCOUNTING, 0)); | 178 SendRstStream(kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
178 visitor_->OnRstStream(rst); | 179 visitor_->OnRstStream(rst); |
179 | 180 |
180 // If we were tracking, we'd probably want to reject this because it's data | 181 // If we were tracking, we'd probably want to reject this because it's data |
181 // past the reset point of stream 3. As it's a closed stream we just drop the | 182 // past the reset point of stream 3. As it's a closed stream we just drop the |
182 // data on the floor, but accept the packet because it has data for stream 5. | 183 // data on the floor, but accept the packet because it has data for stream 5. |
183 frames.clear(); | 184 frames.clear(); |
184 frames.push_back( | 185 frames.push_back( |
185 QuicStreamFrame(kClientDataStreamId1, false, 2, MakeIOVector("TP"))); | 186 QuicStreamFrame(kClientDataStreamId1, false, 2, MakeIOVector("TP"))); |
186 frames.push_back( | 187 frames.push_back( |
187 QuicStreamFrame(kClientDataStreamId2, false, 2, MakeIOVector("TP"))); | 188 QuicStreamFrame(kClientDataStreamId2, false, 2, MakeIOVector("TP"))); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 void(const CachedNetworkParameters* cached_network_parameters)); | 299 void(const CachedNetworkParameters* cached_network_parameters)); |
299 | 300 |
300 private: | 301 private: |
301 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); | 302 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); |
302 }; | 303 }; |
303 | 304 |
304 TEST_P(QuicServerSessionTest, BandwidthEstimates) { | 305 TEST_P(QuicServerSessionTest, BandwidthEstimates) { |
305 if (version() <= QUIC_VERSION_21) { | 306 if (version() <= QUIC_VERSION_21) { |
306 return; | 307 return; |
307 } | 308 } |
| 309 |
308 // Test that bandwidth estimate updates are sent to the client, only after the | 310 // Test that bandwidth estimate updates are sent to the client, only after the |
309 // bandwidth estimate has changes sufficiently, and enough time has passed. | 311 // bandwidth estimate has changes sufficiently, and enough time has passed. |
310 | 312 |
311 int32 bandwidth_estimate_kbytes_per_second = 123; | 313 int32 bandwidth_estimate_kbytes_per_second = 123; |
312 int32 max_bandwidth_estimate_kbytes_per_second = 134; | 314 int32 max_bandwidth_estimate_kbytes_per_second = 134; |
313 int32 max_bandwidth_estimate_timestamp = 1122334455; | 315 int32 max_bandwidth_estimate_timestamp = 1122334455; |
314 const string serving_region = "not a real region"; | 316 const string serving_region = "not a real region"; |
315 session_->set_serving_region(serving_region); | 317 session_->set_serving_region(serving_region); |
316 | 318 |
317 MockQuicCryptoServerStream* crypto_stream = | 319 MockQuicCryptoServerStream* crypto_stream = |
318 new MockQuicCryptoServerStream(crypto_config_, session_.get()); | 320 new MockQuicCryptoServerStream(crypto_config_, session_.get()); |
319 QuicServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 321 QuicServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
320 | 322 |
321 // Set some initial bandwidth values. | 323 // Set some initial bandwidth values. |
322 QuicSentPacketManager* sent_packet_manager = | 324 QuicSentPacketManager* sent_packet_manager = |
323 QuicConnectionPeer::GetSentPacketManager(session_->connection()); | 325 QuicConnectionPeer::GetSentPacketManager(session_->connection()); |
324 QuicSustainedBandwidthRecorder& bandwidth_recorder = | 326 QuicSustainedBandwidthRecorder& bandwidth_recorder = |
325 QuicSentPacketManagerPeer::GetBandwidthRecorder(sent_packet_manager); | 327 QuicSentPacketManagerPeer::GetBandwidthRecorder(sent_packet_manager); |
| 328 // Seed an rtt measurement equal to the initial default rtt. |
| 329 RttStats* rtt_stats = |
| 330 QuicSentPacketManagerPeer::GetRttStats(sent_packet_manager); |
| 331 rtt_stats->UpdateRtt(QuicTime::Delta::FromMicroseconds( |
| 332 rtt_stats->initial_rtt_us()), QuicTime::Delta::Zero(), QuicTime::Zero()); |
326 QuicSustainedBandwidthRecorderPeer::SetBandwidthEstimate( | 333 QuicSustainedBandwidthRecorderPeer::SetBandwidthEstimate( |
327 &bandwidth_recorder, bandwidth_estimate_kbytes_per_second); | 334 &bandwidth_recorder, bandwidth_estimate_kbytes_per_second); |
328 QuicSustainedBandwidthRecorderPeer::SetMaxBandwidthEstimate( | 335 QuicSustainedBandwidthRecorderPeer::SetMaxBandwidthEstimate( |
329 &bandwidth_recorder, max_bandwidth_estimate_kbytes_per_second, | 336 &bandwidth_recorder, max_bandwidth_estimate_kbytes_per_second, |
330 max_bandwidth_estimate_timestamp); | 337 max_bandwidth_estimate_timestamp); |
331 | 338 |
332 // There will be no update sent yet - not enough time has passed. | 339 // There will be no update sent yet - not enough time has passed. |
333 QuicTime now = QuicTime::Zero(); | 340 QuicTime now = QuicTime::Zero(); |
334 session_->OnCongestionWindowChange(now); | 341 session_->OnCongestionWindowChange(now); |
335 | 342 |
336 // Bandwidth estimate has now changed sufficiently but not enough time has | 343 // Bandwidth estimate has now changed sufficiently but not enough time has |
337 // passed to send a Server Config Update. | 344 // passed to send a Server Config Update. |
338 bandwidth_estimate_kbytes_per_second = | 345 bandwidth_estimate_kbytes_per_second = |
339 bandwidth_estimate_kbytes_per_second * 1.6; | 346 bandwidth_estimate_kbytes_per_second * 1.6; |
340 session_->OnCongestionWindowChange(now); | 347 session_->OnCongestionWindowChange(now); |
341 | 348 |
342 // Bandwidth estimate has now changed sufficiently and enough time has passed, | 349 // Bandwidth estimate has now changed sufficiently and enough time has passed, |
343 // but not enough packets have been sent. | 350 // but not enough packets have been sent. |
344 int64 srtt_ms = | 351 int64 srtt_ms = |
345 sent_packet_manager->GetRttStats()->SmoothedRtt().ToMilliseconds(); | 352 sent_packet_manager->GetRttStats()->smoothed_rtt().ToMilliseconds(); |
346 now = now.Add(QuicTime::Delta::FromMilliseconds( | 353 now = now.Add(QuicTime::Delta::FromMilliseconds( |
347 kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms)); | 354 kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms)); |
348 session_->OnCongestionWindowChange(now); | 355 session_->OnCongestionWindowChange(now); |
349 | 356 |
350 // Bandwidth estimate has now changed sufficiently, enough time has passed, | 357 // Bandwidth estimate has now changed sufficiently, enough time has passed, |
351 // and enough packets have been sent. | 358 // and enough packets have been sent. |
352 QuicConnectionPeer::SetSequenceNumberOfLastSentPacket( | 359 QuicConnectionPeer::SetSequenceNumberOfLastSentPacket( |
353 session_->connection(), kMinPacketsBetweenServerConfigUpdates); | 360 session_->connection(), kMinPacketsBetweenServerConfigUpdates); |
354 | 361 |
355 // Verify that the proto has exactly the values we expect. | 362 // Verify that the proto has exactly the values we expect. |
356 CachedNetworkParameters expected_network_params; | 363 CachedNetworkParameters expected_network_params; |
357 expected_network_params.set_bandwidth_estimate_bytes_per_second( | 364 expected_network_params.set_bandwidth_estimate_bytes_per_second( |
358 bandwidth_recorder.BandwidthEstimate().ToBytesPerSecond()); | 365 bandwidth_recorder.BandwidthEstimate().ToBytesPerSecond()); |
359 expected_network_params.set_max_bandwidth_estimate_bytes_per_second( | 366 expected_network_params.set_max_bandwidth_estimate_bytes_per_second( |
360 bandwidth_recorder.MaxBandwidthEstimate().ToBytesPerSecond()); | 367 bandwidth_recorder.MaxBandwidthEstimate().ToBytesPerSecond()); |
361 expected_network_params.set_max_bandwidth_timestamp_seconds( | 368 expected_network_params.set_max_bandwidth_timestamp_seconds( |
362 bandwidth_recorder.MaxBandwidthTimestamp()); | 369 bandwidth_recorder.MaxBandwidthTimestamp()); |
363 expected_network_params.set_min_rtt_ms(session_->connection() | 370 expected_network_params.set_min_rtt_ms(session_->connection() |
364 ->sent_packet_manager() | 371 ->sent_packet_manager() |
365 .GetRttStats() | 372 .GetRttStats() |
366 ->MinRtt() | 373 ->min_rtt() |
367 .ToMilliseconds()); | 374 .ToMilliseconds()); |
368 expected_network_params.set_previous_connection_state( | 375 expected_network_params.set_previous_connection_state( |
369 CachedNetworkParameters::CONGESTION_AVOIDANCE); | 376 CachedNetworkParameters::CONGESTION_AVOIDANCE); |
370 expected_network_params.set_timestamp( | 377 expected_network_params.set_timestamp( |
371 session_->connection()->clock()->WallNow().ToUNIXSeconds()); | 378 session_->connection()->clock()->WallNow().ToUNIXSeconds()); |
372 expected_network_params.set_serving_region(serving_region); | 379 expected_network_params.set_serving_region(serving_region); |
373 | 380 |
374 EXPECT_CALL(*crypto_stream, | 381 EXPECT_CALL(*crypto_stream, |
375 SendServerConfigUpdate(EqualsProto(expected_network_params))) | 382 SendServerConfigUpdate(EqualsProto(expected_network_params))) |
376 .Times(1); | 383 .Times(1); |
377 session_->OnCongestionWindowChange(now); | 384 session_->OnCongestionWindowChange(now); |
378 } | 385 } |
379 | 386 |
380 } // namespace | 387 } // namespace |
381 } // namespace test | 388 } // namespace test |
382 } // namespace tools | 389 } // namespace tools |
383 } // namespace net | 390 } // namespace net |
OLD | NEW |