| 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_time_wait_list_manager.h" | 5 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
| 10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 QuicTimeWaitListManager* manager, | 74 QuicTimeWaitListManager* manager, |
| 75 QuicConnectionId connection_id) { | 75 QuicConnectionId connection_id) { |
| 76 return manager->GetQuicVersionFromConnectionId(connection_id); | 76 return manager->GetQuicVersionFromConnectionId(connection_id); |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 namespace { | 80 namespace { |
| 81 | 81 |
| 82 class MockFakeTimeEpollServer : public FakeTimeEpollServer { | 82 class MockFakeTimeEpollServer : public FakeTimeEpollServer { |
| 83 public: | 83 public: |
| 84 MOCK_METHOD2(RegisterAlarm, void(int64 timeout_in_us, | 84 MOCK_METHOD2(RegisterAlarm, |
| 85 EpollAlarmCallbackInterface* alarm)); | 85 void(int64 timeout_in_us, EpollAlarmCallbackInterface* alarm)); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class QuicTimeWaitListManagerTest : public ::testing::Test { | 88 class QuicTimeWaitListManagerTest : public ::testing::Test { |
| 89 protected: | 89 protected: |
| 90 QuicTimeWaitListManagerTest() | 90 QuicTimeWaitListManagerTest() |
| 91 : time_wait_list_manager_(&writer_, &visitor_, | 91 : time_wait_list_manager_(&writer_, |
| 92 &epoll_server_, QuicSupportedVersions()), | 92 &visitor_, |
| 93 &epoll_server_, |
| 94 QuicSupportedVersions()), |
| 93 framer_(QuicSupportedVersions(), QuicTime::Zero(), true), | 95 framer_(QuicSupportedVersions(), QuicTime::Zero(), true), |
| 94 connection_id_(45), | 96 connection_id_(45), |
| 95 client_address_(net::test::TestPeerIPAddress(), kTestPort), | 97 client_address_(net::test::TestPeerIPAddress(), kTestPort), |
| 96 writer_is_blocked_(false) {} | 98 writer_is_blocked_(false) {} |
| 97 | 99 |
| 98 virtual ~QuicTimeWaitListManagerTest() {} | 100 virtual ~QuicTimeWaitListManagerTest() {} |
| 99 | 101 |
| 100 virtual void SetUp() { | 102 virtual void SetUp() { |
| 101 EXPECT_CALL(writer_, IsWriteBlocked()) | 103 EXPECT_CALL(writer_, IsWriteBlocked()) |
| 102 .WillRepeatedly(ReturnPointee(&writer_is_blocked_)); | 104 .WillRepeatedly(ReturnPointee(&writer_is_blocked_)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 header.fec_flag = false; | 147 header.fec_flag = false; |
| 146 header.is_in_fec_group = NOT_IN_FEC_GROUP; | 148 header.is_in_fec_group = NOT_IN_FEC_GROUP; |
| 147 header.fec_group = 0; | 149 header.fec_group = 0; |
| 148 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector("data")); | 150 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector("data")); |
| 149 QuicFrame frame(&stream_frame); | 151 QuicFrame frame(&stream_frame); |
| 150 QuicFrames frames; | 152 QuicFrames frames; |
| 151 frames.push_back(frame); | 153 frames.push_back(frame); |
| 152 scoped_ptr<QuicPacket> packet( | 154 scoped_ptr<QuicPacket> packet( |
| 153 framer_.BuildUnsizedDataPacket(header, frames).packet); | 155 framer_.BuildUnsizedDataPacket(header, frames).packet); |
| 154 EXPECT_TRUE(packet != NULL); | 156 EXPECT_TRUE(packet != NULL); |
| 155 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(ENCRYPTION_NONE, | 157 QuicEncryptedPacket* encrypted = |
| 156 sequence_number, | 158 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *packet); |
| 157 *packet); | |
| 158 EXPECT_TRUE(encrypted != NULL); | 159 EXPECT_TRUE(encrypted != NULL); |
| 159 return encrypted; | 160 return encrypted; |
| 160 } | 161 } |
| 161 | 162 |
| 162 NiceMock<MockFakeTimeEpollServer> epoll_server_; | 163 NiceMock<MockFakeTimeEpollServer> epoll_server_; |
| 163 StrictMock<MockPacketWriter> writer_; | 164 StrictMock<MockPacketWriter> writer_; |
| 164 StrictMock<MockQuicServerSessionVisitor> visitor_; | 165 StrictMock<MockQuicServerSessionVisitor> visitor_; |
| 165 QuicTimeWaitListManager time_wait_list_manager_; | 166 QuicTimeWaitListManager time_wait_list_manager_; |
| 166 QuicFramer framer_; | 167 QuicFramer framer_; |
| 167 QuicConnectionId connection_id_; | 168 QuicConnectionId connection_id_; |
| 168 IPEndPoint server_address_; | 169 IPEndPoint server_address_; |
| 169 IPEndPoint client_address_; | 170 IPEndPoint client_address_; |
| 170 bool writer_is_blocked_; | 171 bool writer_is_blocked_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 class ValidatePublicResetPacketPredicate | 174 class ValidatePublicResetPacketPredicate |
| 174 : public MatcherInterface<const std::tr1::tuple<const char*, int> > { | 175 : public MatcherInterface<const std::tr1::tuple<const char*, int> > { |
| 175 public: | 176 public: |
| 176 explicit ValidatePublicResetPacketPredicate(QuicConnectionId connection_id, | 177 explicit ValidatePublicResetPacketPredicate(QuicConnectionId connection_id, |
| 177 QuicPacketSequenceNumber number) | 178 QuicPacketSequenceNumber number) |
| 178 : connection_id_(connection_id), sequence_number_(number) { | 179 : connection_id_(connection_id), sequence_number_(number) {} |
| 179 } | |
| 180 | 180 |
| 181 virtual bool MatchAndExplain( | 181 virtual bool MatchAndExplain( |
| 182 const std::tr1::tuple<const char*, int> packet_buffer, | 182 const std::tr1::tuple<const char*, int> packet_buffer, |
| 183 testing::MatchResultListener* /* listener */) const { | 183 testing::MatchResultListener* /* listener */) const { |
| 184 FramerVisitorCapturingPublicReset visitor; | 184 FramerVisitorCapturingPublicReset visitor; |
| 185 QuicFramer framer(QuicSupportedVersions(), | 185 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); |
| 186 QuicTime::Zero(), | |
| 187 false); | |
| 188 framer.set_visitor(&visitor); | 186 framer.set_visitor(&visitor); |
| 189 QuicEncryptedPacket encrypted(std::tr1::get<0>(packet_buffer), | 187 QuicEncryptedPacket encrypted(std::tr1::get<0>(packet_buffer), |
| 190 std::tr1::get<1>(packet_buffer)); | 188 std::tr1::get<1>(packet_buffer)); |
| 191 framer.ProcessPacket(encrypted); | 189 framer.ProcessPacket(encrypted); |
| 192 QuicPublicResetPacket packet = visitor.public_reset_packet(); | 190 QuicPublicResetPacket packet = visitor.public_reset_packet(); |
| 193 return connection_id_ == packet.public_header.connection_id && | 191 return connection_id_ == packet.public_header.connection_id && |
| 194 packet.public_header.reset_flag && !packet.public_header.version_flag && | 192 packet.public_header.reset_flag && |
| 195 sequence_number_ == packet.rejected_sequence_number && | 193 !packet.public_header.version_flag && |
| 196 net::test::TestPeerIPAddress() == packet.client_address.address() && | 194 sequence_number_ == packet.rejected_sequence_number && |
| 197 kTestPort == packet.client_address.port(); | 195 net::test::TestPeerIPAddress() == packet.client_address.address() && |
| 196 kTestPort == packet.client_address.port(); |
| 198 } | 197 } |
| 199 | 198 |
| 200 virtual void DescribeTo(::std::ostream* os) const { } | 199 virtual void DescribeTo(::std::ostream* os) const {} |
| 201 | 200 |
| 202 virtual void DescribeNegationTo(::std::ostream* os) const { } | 201 virtual void DescribeNegationTo(::std::ostream* os) const {} |
| 203 | 202 |
| 204 private: | 203 private: |
| 205 QuicConnectionId connection_id_; | 204 QuicConnectionId connection_id_; |
| 206 QuicPacketSequenceNumber sequence_number_; | 205 QuicPacketSequenceNumber sequence_number_; |
| 207 }; | 206 }; |
| 208 | 207 |
| 209 | |
| 210 Matcher<const std::tr1::tuple<const char*, int> > PublicResetPacketEq( | 208 Matcher<const std::tr1::tuple<const char*, int> > PublicResetPacketEq( |
| 211 QuicConnectionId connection_id, | 209 QuicConnectionId connection_id, |
| 212 QuicPacketSequenceNumber sequence_number) { | 210 QuicPacketSequenceNumber sequence_number) { |
| 213 return MakeMatcher(new ValidatePublicResetPacketPredicate(connection_id, | 211 return MakeMatcher( |
| 214 sequence_number)); | 212 new ValidatePublicResetPacketPredicate(connection_id, sequence_number)); |
| 215 } | 213 } |
| 216 | 214 |
| 217 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { | 215 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { |
| 218 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 216 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
| 219 AddConnectionId(connection_id_); | 217 AddConnectionId(connection_id_); |
| 220 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 218 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 221 } | 219 } |
| 222 | 220 |
| 223 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { | 221 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { |
| 224 size_t kConnectionCloseLength = 100; | 222 size_t kConnectionCloseLength = 100; |
| 225 AddConnectionId( | 223 AddConnectionId( |
| 226 connection_id_, | 224 connection_id_, |
| 227 QuicVersionMax(), | 225 QuicVersionMax(), |
| 228 new QuicEncryptedPacket( | 226 new QuicEncryptedPacket( |
| 229 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 227 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
| 230 const int kRandomSequenceNumber = 1; | 228 const int kRandomSequenceNumber = 1; |
| 231 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 229 EXPECT_CALL(writer_, |
| 232 server_address_.address(), | 230 WritePacket(_, |
| 233 client_address_)) | 231 kConnectionCloseLength, |
| 232 server_address_.address(), |
| 233 client_address_)) |
| 234 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 234 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 235 | 235 |
| 236 ProcessPacket(connection_id_, kRandomSequenceNumber); | 236 ProcessPacket(connection_id_, kRandomSequenceNumber); |
| 237 } | 237 } |
| 238 | 238 |
| 239 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { | 239 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { |
| 240 AddConnectionId(connection_id_); | 240 AddConnectionId(connection_id_); |
| 241 const int kRandomSequenceNumber = 1; | 241 const int kRandomSequenceNumber = 1; |
| 242 EXPECT_CALL(writer_, WritePacket(_, _, | 242 EXPECT_CALL(writer_, |
| 243 server_address_.address(), | 243 WritePacket(_, _, server_address_.address(), client_address_)) |
| 244 client_address_)) | 244 .With(Args<0, 1>( |
| 245 .With(Args<0, 1>(PublicResetPacketEq(connection_id_, | 245 PublicResetPacketEq(connection_id_, kRandomSequenceNumber))) |
| 246 kRandomSequenceNumber))) | |
| 247 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 246 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
| 248 | 247 |
| 249 ProcessPacket(connection_id_, kRandomSequenceNumber); | 248 ProcessPacket(connection_id_, kRandomSequenceNumber); |
| 250 } | 249 } |
| 251 | 250 |
| 252 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { | 251 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { |
| 253 AddConnectionId(connection_id_); | 252 AddConnectionId(connection_id_); |
| 254 for (int sequence_number = 1; sequence_number < 101; ++sequence_number) { | 253 for (int sequence_number = 1; sequence_number < 101; ++sequence_number) { |
| 255 if ((sequence_number & (sequence_number - 1)) == 0) { | 254 if ((sequence_number & (sequence_number - 1)) == 0) { |
| 256 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) | 255 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) |
| 257 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 256 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 258 } | 257 } |
| 259 ProcessPacket(connection_id_, sequence_number); | 258 ProcessPacket(connection_id_, sequence_number); |
| 260 // Send public reset with exponential back off. | 259 // Send public reset with exponential back off. |
| 261 if ((sequence_number & (sequence_number - 1)) == 0) { | 260 if ((sequence_number & (sequence_number - 1)) == 0) { |
| 262 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 261 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
| 263 &time_wait_list_manager_, sequence_number)); | 262 &time_wait_list_manager_, sequence_number)); |
| 264 } else { | 263 } else { |
| 265 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 264 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
| 266 &time_wait_list_manager_, sequence_number)); | 265 &time_wait_list_manager_, sequence_number)); |
| 267 } | 266 } |
| 268 } | 267 } |
| 269 } | 268 } |
| 270 | 269 |
| 271 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { | 270 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { |
| 272 const int kConnectionIdCount = 100; | 271 const int kConnectionIdCount = 100; |
| 273 const int kOldConnectionIdCount = 31; | 272 const int kOldConnectionIdCount = 31; |
| 274 | 273 |
| 275 // Add connection_ids such that their expiry time is kTimeWaitPeriod_. | 274 // Add connection_ids such that their expiry time is kTimeWaitPeriod_. |
| 276 epoll_server_.set_now_in_usec(0); | 275 epoll_server_.set_now_in_usec(0); |
| 277 for (int connection_id = 1; | 276 for (int connection_id = 1; connection_id <= kOldConnectionIdCount; |
| 278 connection_id <= kOldConnectionIdCount; | |
| 279 ++connection_id) { | 277 ++connection_id) { |
| 280 AddConnectionId(connection_id); | 278 AddConnectionId(connection_id); |
| 281 } | 279 } |
| 282 | 280 |
| 283 // Add remaining connection_ids such that their add time is | 281 // Add remaining connection_ids such that their add time is |
| 284 // 2 * kTimeWaitPeriod. | 282 // 2 * kTimeWaitPeriod. |
| 285 const QuicTime::Delta time_wait_period = | 283 const QuicTime::Delta time_wait_period = |
| 286 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 284 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
| 287 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds()); | 285 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds()); |
| 288 for (int connection_id = kOldConnectionIdCount + 1; | 286 for (int connection_id = kOldConnectionIdCount + 1; |
| 289 connection_id <= kConnectionIdCount; | 287 connection_id <= kConnectionIdCount; |
| 290 ++connection_id) { | 288 ++connection_id) { |
| 291 AddConnectionId(connection_id); | 289 AddConnectionId(connection_id); |
| 292 } | 290 } |
| 293 | 291 |
| 294 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); | 292 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); |
| 295 // Now set the current time as time_wait_period + offset usecs. | 293 // Now set the current time as time_wait_period + offset usecs. |
| 296 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); | 294 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); |
| 297 // After all the old connection_ids are cleaned up, check the next alarm | 295 // After all the old connection_ids are cleaned up, check the next alarm |
| 298 // interval. | 296 // interval. |
| 299 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + | 297 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + |
| 300 time_wait_period.Subtract(offset).ToMicroseconds(); | 298 time_wait_period.Subtract(offset).ToMicroseconds(); |
| 301 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); | 299 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); |
| 302 | 300 |
| 303 time_wait_list_manager_.CleanUpOldConnectionIds(); | 301 time_wait_list_manager_.CleanUpOldConnectionIds(); |
| 304 for (int connection_id = 1; | 302 for (int connection_id = 1; connection_id <= kConnectionIdCount; |
| 305 connection_id <= kConnectionIdCount; | |
| 306 ++connection_id) { | 303 ++connection_id) { |
| 307 EXPECT_EQ(connection_id > kOldConnectionIdCount, | 304 EXPECT_EQ(connection_id > kOldConnectionIdCount, |
| 308 IsConnectionIdInTimeWait(connection_id)) | 305 IsConnectionIdInTimeWait(connection_id)) |
| 309 << "kOldConnectionIdCount: " << kOldConnectionIdCount | 306 << "kOldConnectionIdCount: " << kOldConnectionIdCount |
| 310 << " connection_id: " << connection_id; | 307 << " connection_id: " << connection_id; |
| 311 } | 308 } |
| 312 } | 309 } |
| 313 | 310 |
| 314 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { | 311 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { |
| 315 QuicConnectionId connection_id = 1; | 312 QuicConnectionId connection_id = 1; |
| 316 AddConnectionId(connection_id); | 313 AddConnectionId(connection_id); |
| 317 QuicPacketSequenceNumber sequence_number = 234; | 314 QuicPacketSequenceNumber sequence_number = 234; |
| 318 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 315 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 319 ENCRYPTION_NONE, connection_id, sequence_number)); | 316 ENCRYPTION_NONE, connection_id, sequence_number)); |
| 320 // Let first write through. | 317 // Let first write through. |
| 321 EXPECT_CALL(writer_, WritePacket(_, _, | 318 EXPECT_CALL(writer_, |
| 322 server_address_.address(), | 319 WritePacket(_, _, server_address_.address(), client_address_)) |
| 323 client_address_)) | 320 .With(Args<0, 1>(PublicResetPacketEq(connection_id, sequence_number))) |
| 324 .With(Args<0, 1>(PublicResetPacketEq(connection_id, | |
| 325 sequence_number))) | |
| 326 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 321 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
| 327 ProcessPacket(connection_id, sequence_number); | 322 ProcessPacket(connection_id, sequence_number); |
| 328 | 323 |
| 329 // write block for the next packet. | 324 // write block for the next packet. |
| 330 EXPECT_CALL(writer_, WritePacket(_, _, | 325 EXPECT_CALL(writer_, |
| 331 server_address_.address(), | 326 WritePacket(_, _, server_address_.address(), client_address_)) |
| 332 client_address_)) | 327 .With(Args<0, 1>(PublicResetPacketEq(connection_id, sequence_number))) |
| 333 .With(Args<0, 1>(PublicResetPacketEq(connection_id, | 328 .WillOnce(DoAll(Assign(&writer_is_blocked_, true), |
| 334 sequence_number))) | 329 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); |
| 335 .WillOnce(DoAll( | |
| 336 Assign(&writer_is_blocked_, true), | |
| 337 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); | |
| 338 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 330 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
| 339 ProcessPacket(connection_id, sequence_number); | 331 ProcessPacket(connection_id, sequence_number); |
| 340 // 3rd packet. No public reset should be sent; | 332 // 3rd packet. No public reset should be sent; |
| 341 ProcessPacket(connection_id, sequence_number); | 333 ProcessPacket(connection_id, sequence_number); |
| 342 | 334 |
| 343 // write packet should not be called since we are write blocked but the | 335 // write packet should not be called since we are write blocked but the |
| 344 // should be queued. | 336 // should be queued. |
| 345 QuicConnectionId other_connection_id = 2; | 337 QuicConnectionId other_connection_id = 2; |
| 346 AddConnectionId(other_connection_id); | 338 AddConnectionId(other_connection_id); |
| 347 QuicPacketSequenceNumber other_sequence_number = 23423; | 339 QuicPacketSequenceNumber other_sequence_number = 23423; |
| 348 scoped_ptr<QuicEncryptedPacket> other_packet( | 340 scoped_ptr<QuicEncryptedPacket> other_packet(ConstructEncryptedPacket( |
| 349 ConstructEncryptedPacket( | 341 ENCRYPTION_NONE, other_connection_id, other_sequence_number)); |
| 350 ENCRYPTION_NONE, other_connection_id, other_sequence_number)); | 342 EXPECT_CALL(writer_, WritePacket(_, _, _, _)).Times(0); |
| 351 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) | |
| 352 .Times(0); | |
| 353 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 343 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
| 354 ProcessPacket(other_connection_id, other_sequence_number); | 344 ProcessPacket(other_connection_id, other_sequence_number); |
| 355 | 345 |
| 356 // Now expect all the write blocked public reset packets to be sent again. | 346 // Now expect all the write blocked public reset packets to be sent again. |
| 357 writer_is_blocked_ = false; | 347 writer_is_blocked_ = false; |
| 358 EXPECT_CALL(writer_, WritePacket(_, _, | 348 EXPECT_CALL(writer_, |
| 359 server_address_.address(), | 349 WritePacket(_, _, server_address_.address(), client_address_)) |
| 360 client_address_)) | 350 .With(Args<0, 1>(PublicResetPacketEq(connection_id, sequence_number))) |
| 361 .With(Args<0, 1>(PublicResetPacketEq(connection_id, | |
| 362 sequence_number))) | |
| 363 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 351 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
| 364 EXPECT_CALL(writer_, WritePacket(_, _, | 352 EXPECT_CALL(writer_, |
| 365 server_address_.address(), | 353 WritePacket(_, _, server_address_.address(), client_address_)) |
| 366 client_address_)) | 354 .With(Args<0, 1>( |
| 367 .With(Args<0, 1>(PublicResetPacketEq(other_connection_id, | 355 PublicResetPacketEq(other_connection_id, other_sequence_number))) |
| 368 other_sequence_number))) | 356 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length()))); |
| 369 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, | |
| 370 other_packet->length()))); | |
| 371 time_wait_list_manager_.OnCanWrite(); | 357 time_wait_list_manager_.OnCanWrite(); |
| 372 } | 358 } |
| 373 | 359 |
| 374 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { | 360 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { |
| 375 const int kConnectionId1 = 123; | 361 const int kConnectionId1 = 123; |
| 376 const int kConnectionId2 = 456; | 362 const int kConnectionId2 = 456; |
| 377 const int kConnectionId3 = 789; | 363 const int kConnectionId3 = 789; |
| 378 | 364 |
| 379 AddConnectionId(kConnectionId1, QuicVersionMin(), NULL); | 365 AddConnectionId(kConnectionId1, QuicVersionMin(), NULL); |
| 380 AddConnectionId(kConnectionId2, QuicVersionMax(), NULL); | 366 AddConnectionId(kConnectionId2, QuicVersionMax(), NULL); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 397 AddConnectionId(connection_id_); | 383 AddConnectionId(connection_id_); |
| 398 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 384 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 399 size_t kConnectionCloseLength = 100; | 385 size_t kConnectionCloseLength = 100; |
| 400 AddConnectionId( | 386 AddConnectionId( |
| 401 connection_id_, | 387 connection_id_, |
| 402 QuicVersionMax(), | 388 QuicVersionMax(), |
| 403 new QuicEncryptedPacket( | 389 new QuicEncryptedPacket( |
| 404 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 390 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
| 405 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 391 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 406 | 392 |
| 407 EXPECT_CALL(writer_, WritePacket(_, | 393 EXPECT_CALL(writer_, |
| 408 kConnectionCloseLength, | 394 WritePacket(_, |
| 409 server_address_.address(), | 395 kConnectionCloseLength, |
| 410 client_address_)) | 396 server_address_.address(), |
| 397 client_address_)) |
| 411 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 398 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 412 | 399 |
| 413 const int kRandomSequenceNumber = 1; | 400 const int kRandomSequenceNumber = 1; |
| 414 ProcessPacket(connection_id_, kRandomSequenceNumber); | 401 ProcessPacket(connection_id_, kRandomSequenceNumber); |
| 415 | 402 |
| 416 const QuicTime::Delta time_wait_period = | 403 const QuicTime::Delta time_wait_period = |
| 417 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 404 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
| 418 | 405 |
| 419 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); | 406 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); |
| 420 // Now set the current time as time_wait_period + offset usecs. | 407 // Now set the current time as time_wait_period + offset usecs. |
| 421 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); | 408 epoll_server_.set_now_in_usec(time_wait_period.Add(offset).ToMicroseconds()); |
| 422 // After the connection_ids are cleaned up, check the next alarm interval. | 409 // After the connection_ids are cleaned up, check the next alarm interval. |
| 423 int64 next_alarm_time = epoll_server_.ApproximateNowInUsec() + | 410 int64 next_alarm_time = |
| 424 time_wait_period.ToMicroseconds(); | 411 epoll_server_.ApproximateNowInUsec() + time_wait_period.ToMicroseconds(); |
| 425 | 412 |
| 426 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); | 413 EXPECT_CALL(epoll_server_, RegisterAlarm(next_alarm_time, _)); |
| 427 time_wait_list_manager_.CleanUpOldConnectionIds(); | 414 time_wait_list_manager_.CleanUpOldConnectionIds(); |
| 428 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 415 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
| 429 } | 416 } |
| 430 | 417 |
| 431 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { | 418 TEST_F(QuicTimeWaitListManagerTest, ConnectionIdsOrderedByTime) { |
| 432 // Simple randomization: the values of connection_ids are swapped based on the | 419 // Simple randomization: the values of connection_ids are swapped based on the |
| 433 // current seconds on the clock. If the container is broken, the test will be | 420 // current seconds on the clock. If the container is broken, the test will be |
| 434 // 50% flaky. | 421 // 50% flaky. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 451 EXPECT_CALL(epoll_server_, RegisterAlarm(_, _)); | 438 EXPECT_CALL(epoll_server_, RegisterAlarm(_, _)); |
| 452 | 439 |
| 453 time_wait_list_manager_.CleanUpOldConnectionIds(); | 440 time_wait_list_manager_.CleanUpOldConnectionIds(); |
| 454 EXPECT_FALSE(IsConnectionIdInTimeWait(kConnectionId1)); | 441 EXPECT_FALSE(IsConnectionIdInTimeWait(kConnectionId1)); |
| 455 EXPECT_TRUE(IsConnectionIdInTimeWait(kConnectionId2)); | 442 EXPECT_TRUE(IsConnectionIdInTimeWait(kConnectionId2)); |
| 456 } | 443 } |
| 457 } // namespace | 444 } // namespace |
| 458 } // namespace test | 445 } // namespace test |
| 459 } // namespace tools | 446 } // namespace tools |
| 460 } // namespace net | 447 } // namespace net |
| OLD | NEW |