| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_epoll_connection_helper.h" | 5 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/crypto_protocol.h" | 7 #include "net/quic/crypto/crypto_protocol.h" |
| 8 #include "net/quic/crypto/quic_decrypter.h" | 8 #include "net/quic/crypto/quic_decrypter.h" |
| 9 #include "net/quic/crypto/quic_encrypter.h" | 9 #include "net/quic/crypto/quic_encrypter.h" |
| 10 #include "net/quic/crypto/quic_random.h" | 10 #include "net/quic/crypto/quic_random.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const bool kFromPeer = true; | 32 const bool kFromPeer = true; |
| 33 | 33 |
| 34 class TestConnectionHelper : public QuicEpollConnectionHelper { | 34 class TestConnectionHelper : public QuicEpollConnectionHelper { |
| 35 public: | 35 public: |
| 36 TestConnectionHelper(int fd, EpollServer* eps) | 36 TestConnectionHelper(int fd, EpollServer* eps) |
| 37 : QuicEpollConnectionHelper(fd, eps) { | 37 : QuicEpollConnectionHelper(fd, eps) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, | 40 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, |
| 41 int* error) OVERRIDE { | 41 int* error) OVERRIDE { |
| 42 QuicFramer framer(kQuicVersion1, QuicTime::Zero(), true); | 42 QuicFramer framer(QuicVersionMax(), QuicTime::Zero(), true); |
| 43 FramerVisitorCapturingFrames visitor; | 43 FramerVisitorCapturingFrames visitor; |
| 44 framer.set_visitor(&visitor); | 44 framer.set_visitor(&visitor); |
| 45 EXPECT_TRUE(framer.ProcessPacket(packet)); | 45 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 46 header_ = *visitor.header(); | 46 header_ = *visitor.header(); |
| 47 *error = 0; | 47 *error = 0; |
| 48 return packet.length(); | 48 return packet.length(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 QuicPacketHeader* header() { return &header_; } | 51 QuicPacketHeader* header() { return &header_; } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 QuicPacketHeader header_; | 54 QuicPacketHeader header_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class TestConnection : public QuicConnection { | 57 class TestConnection : public QuicConnection { |
| 58 public: | 58 public: |
| 59 TestConnection(QuicGuid guid, | 59 TestConnection(QuicGuid guid, |
| 60 IPEndPoint address, | 60 IPEndPoint address, |
| 61 TestConnectionHelper* helper) | 61 TestConnectionHelper* helper) |
| 62 : QuicConnection(guid, address, helper, false) { | 62 : QuicConnection(guid, address, helper, false, QuicVersionMax()) { |
| 63 } | 63 } |
| 64 | 64 |
| 65 void SendAck() { | 65 void SendAck() { |
| 66 QuicConnectionPeer::SendAck(this); | 66 QuicConnectionPeer::SendAck(this); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 69 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 70 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 70 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 71 } | 71 } |
| 72 | 72 |
| 73 using QuicConnection::SendOrQueuePacket; | 73 using QuicConnection::SendOrQueuePacket; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 class QuicEpollConnectionHelperTest : public ::testing::Test { | 76 class QuicEpollConnectionHelperTest : public ::testing::Test { |
| 77 protected: | 77 protected: |
| 78 QuicEpollConnectionHelperTest() | 78 QuicEpollConnectionHelperTest() |
| 79 : guid_(42), | 79 : guid_(42), |
| 80 framer_(kQuicVersion1, QuicTime::Zero(), false), | 80 framer_(QuicVersionMax(), QuicTime::Zero(), false), |
| 81 send_algorithm_(new testing::StrictMock<MockSendAlgorithm>), | 81 send_algorithm_(new testing::StrictMock<MockSendAlgorithm>), |
| 82 helper_(new TestConnectionHelper(0, &epoll_server_)), | 82 helper_(new TestConnectionHelper(0, &epoll_server_)), |
| 83 connection_(guid_, IPEndPoint(), helper_), | 83 connection_(guid_, IPEndPoint(), helper_), |
| 84 frame1_(1, false, 0, data1) { | 84 frame1_(1, false, 0, data1) { |
| 85 connection_.set_visitor(&visitor_); | 85 connection_.set_visitor(&visitor_); |
| 86 connection_.SetSendAlgorithm(send_algorithm_); | 86 connection_.SetSendAlgorithm(send_algorithm_); |
| 87 epoll_server_.set_timeout_in_us(-1); | 87 epoll_server_.set_timeout_in_us(-1); |
| 88 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( | 88 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( |
| 89 QuicTime::Delta::Zero())); | 89 QuicTime::Delta::Zero())); |
| 90 } | 90 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 113 TestConnectionHelper* helper_; | 113 TestConnectionHelper* helper_; |
| 114 TestConnection connection_; | 114 TestConnection connection_; |
| 115 testing::StrictMock<MockConnectionVisitor> visitor_; | 115 testing::StrictMock<MockConnectionVisitor> visitor_; |
| 116 | 116 |
| 117 QuicPacketHeader header_; | 117 QuicPacketHeader header_; |
| 118 QuicStreamFrame frame1_; | 118 QuicStreamFrame frame1_; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 TEST_F(QuicEpollConnectionHelperTest, DISABLED_TestRetransmission) { | 121 TEST_F(QuicEpollConnectionHelperTest, DISABLED_TestRetransmission) { |
| 122 //FLAGS_fake_packet_loss_percentage = 100; | 122 //FLAGS_fake_packet_loss_percentage = 100; |
| 123 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 124 Return(QuicTime::Delta::Zero())); |
| 123 const int64 kDefaultRetransmissionTimeMs = 500; | 125 const int64 kDefaultRetransmissionTimeMs = 500; |
| 124 | 126 |
| 125 const char buffer[] = "foo"; | 127 const char buffer[] = "foo"; |
| 126 const size_t packet_size = | 128 const size_t packet_size = |
| 127 GetPacketHeaderSize(PACKET_8BYTE_GUID, kIncludeVersion, | 129 GetPacketHeaderSize(PACKET_8BYTE_GUID, kIncludeVersion, |
| 128 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + | 130 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + |
| 129 QuicFramer::GetMinStreamFrameSize() + arraysize(buffer) - 1; | 131 QuicFramer::GetMinStreamFrameSize() + arraysize(buffer) - 1; |
| 130 EXPECT_CALL(*send_algorithm_, | 132 EXPECT_CALL(*send_algorithm_, |
| 131 SentPacket(_, 1, packet_size, NOT_RETRANSMISSION)); | 133 SentPacket(_, 1, packet_size, NOT_RETRANSMISSION)); |
| 132 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, packet_size)); | 134 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, packet_size)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); | 173 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); |
| 172 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION)); | 174 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION)); |
| 173 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 175 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
| 174 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, | 176 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, |
| 175 epoll_server_.NowInUsec()); | 177 epoll_server_.NowInUsec()); |
| 176 EXPECT_FALSE(connection_.connected()); | 178 EXPECT_FALSE(connection_.connected()); |
| 177 } | 179 } |
| 178 | 180 |
| 179 TEST_F(QuicEpollConnectionHelperTest, SendSchedulerDelayThenSend) { | 181 TEST_F(QuicEpollConnectionHelperTest, SendSchedulerDelayThenSend) { |
| 180 // Test that if we send a packet with a delay, it ends up queued. | 182 // Test that if we send a packet with a delay, it ends up queued. |
| 183 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 184 Return(QuicTime::Delta::Zero())); |
| 181 QuicPacket* packet = ConstructDataPacket(1, 0); | 185 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 182 EXPECT_CALL( | 186 EXPECT_CALL( |
| 183 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce( | 187 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce( |
| 184 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 188 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 185 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, | 189 connection_.SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, |
| 186 HAS_RETRANSMITTABLE_DATA); | 190 HAS_RETRANSMITTABLE_DATA); |
| 187 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); | 191 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); |
| 188 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 192 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 189 | 193 |
| 190 // Advance the clock to fire the alarm, and configure the scheduler | 194 // Advance the clock to fire the alarm, and configure the scheduler |
| 191 // to permit the packet to be sent. | 195 // to permit the packet to be sent. |
| 192 EXPECT_CALL( | 196 EXPECT_CALL( |
| 193 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( | 197 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( |
| 194 testing::Return(QuicTime::Delta::Zero())); | 198 testing::Return(QuicTime::Delta::Zero())); |
| 195 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); | 199 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); |
| 196 epoll_server_.AdvanceByAndCallCallbacks(1); | 200 epoll_server_.AdvanceByAndCallCallbacks(1); |
| 197 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 201 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 198 } | 202 } |
| 199 | 203 |
| 200 } // namespace | 204 } // namespace |
| 201 } // namespace test | 205 } // namespace test |
| 202 } // namespace tools | 206 } // namespace tools |
| 203 } // namespace net | 207 } // namespace net |
| OLD | NEW |