Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 908623002: Revert of Landing Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_dispatcher.h" 5 #include "net/tools/quic/quic_dispatcher.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h" 10 #include "net/quic/crypto/crypto_handshake.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 *session = new MockSession(connection); 90 *session = new MockSession(connection);
91 ON_CALL(*connection, SendConnectionClose(_)).WillByDefault( 91 ON_CALL(*connection, SendConnectionClose(_)).WillByDefault(
92 WithoutArgs(Invoke( 92 WithoutArgs(Invoke(
93 connection, &MockServerConnection::UnregisterOnConnectionClosed))); 93 connection, &MockServerConnection::UnregisterOnConnectionClosed)));
94 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()), 94 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()),
95 ProcessUdpPacket(_, client_address, _)); 95 ProcessUdpPacket(_, client_address, _));
96 96
97 return *session; 97 return *session;
98 } 98 }
99 99
100 class MockTimeWaitListManager : public QuicTimeWaitListManager {
101 public:
102 MockTimeWaitListManager(QuicPacketWriter* writer,
103 QuicServerSessionVisitor* visitor,
104 EpollServer* eps)
105 : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) {
106 }
107
108 MOCK_METHOD5(ProcessPacket,
109 void(const IPEndPoint& server_address,
110 const IPEndPoint& client_address,
111 QuicConnectionId connection_id,
112 QuicPacketSequenceNumber sequence_number,
113 const QuicEncryptedPacket& packet));
114 };
115
116 class QuicDispatcherTest : public ::testing::Test { 100 class QuicDispatcherTest : public ::testing::Test {
117 public: 101 public:
118 QuicDispatcherTest() 102 QuicDispatcherTest()
119 : crypto_config_(QuicCryptoServerConfig::TESTING, 103 : crypto_config_(QuicCryptoServerConfig::TESTING,
120 QuicRandom::GetInstance()), 104 QuicRandom::GetInstance()),
121 dispatcher_(config_, crypto_config_, &eps_), 105 dispatcher_(config_, crypto_config_, &eps_),
122 time_wait_list_manager_(nullptr),
123 session1_(nullptr), 106 session1_(nullptr),
124 session2_(nullptr) { 107 session2_(nullptr) {
125 dispatcher_.Initialize(1); 108 dispatcher_.Initialize(1);
126 } 109 }
127 110
128 ~QuicDispatcherTest() override {} 111 ~QuicDispatcherTest() override {}
129 112
130 MockConnection* connection1() { 113 MockConnection* connection1() {
131 return reinterpret_cast<MockConnection*>(session1_->connection()); 114 return reinterpret_cast<MockConnection*>(session1_->connection());
132 } 115 }
(...skipping 10 matching lines...) Expand all
143 connection_id, has_version_flag, false, 1, data)); 126 connection_id, has_version_flag, false, 1, data));
144 data_ = string(packet->data(), packet->length()); 127 data_ = string(packet->data(), packet->length());
145 dispatcher_.ProcessPacket(server_address_, client_address, *packet); 128 dispatcher_.ProcessPacket(server_address_, client_address, *packet);
146 } 129 }
147 130
148 void ValidatePacket(const QuicEncryptedPacket& packet) { 131 void ValidatePacket(const QuicEncryptedPacket& packet) {
149 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); 132 EXPECT_EQ(data_.length(), packet.AsStringPiece().length());
150 EXPECT_EQ(data_, packet.AsStringPiece()); 133 EXPECT_EQ(data_, packet.AsStringPiece());
151 } 134 }
152 135
153 void CreateTimeWaitListManager() {
154 time_wait_list_manager_ = new MockTimeWaitListManager(
155 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_);
156 // dispatcher takes the ownership of time_wait_list_manager.
157 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
158 time_wait_list_manager_);
159 }
160
161 EpollServer eps_; 136 EpollServer eps_;
162 QuicConfig config_; 137 QuicConfig config_;
163 QuicCryptoServerConfig crypto_config_; 138 QuicCryptoServerConfig crypto_config_;
164 IPEndPoint server_address_; 139 IPEndPoint server_address_;
165 TestDispatcher dispatcher_; 140 TestDispatcher dispatcher_;
166 MockTimeWaitListManager* time_wait_list_manager_;
167 MockSession* session1_; 141 MockSession* session1_;
168 MockSession* session2_; 142 MockSession* session2_;
169 string data_; 143 string data_;
170 }; 144 };
171 145
172 TEST_F(QuicDispatcherTest, ProcessPackets) { 146 TEST_F(QuicDispatcherTest, ProcessPackets) {
173 IPEndPoint client_address(net::test::Loopback4(), 1); 147 IPEndPoint client_address(net::test::Loopback4(), 1);
174 IPAddressNumber any4; 148 IPAddressNumber any4;
175 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); 149 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4));
176 server_address_ = IPEndPoint(any4, 5); 150 server_address_ = IPEndPoint(any4, 5);
(...skipping 26 matching lines...) Expand all
203 &dispatcher_, 1, client_address, &session1_))); 177 &dispatcher_, 1, client_address, &session1_)));
204 178
205 ProcessPacket(client_address, 1, true, "foo"); 179 ProcessPacket(client_address, 1, true, "foo");
206 180
207 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 181 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
208 SendConnectionClose(QUIC_PEER_GOING_AWAY)); 182 SendConnectionClose(QUIC_PEER_GOING_AWAY));
209 183
210 dispatcher_.Shutdown(); 184 dispatcher_.Shutdown();
211 } 185 }
212 186
187 class MockTimeWaitListManager : public QuicTimeWaitListManager {
188 public:
189 MockTimeWaitListManager(QuicPacketWriter* writer,
190 QuicServerSessionVisitor* visitor,
191 EpollServer* eps)
192 : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) {
193 }
194
195 MOCK_METHOD5(ProcessPacket, void(const IPEndPoint& server_address,
196 const IPEndPoint& client_address,
197 QuicConnectionId connection_id,
198 QuicPacketSequenceNumber sequence_number,
199 const QuicEncryptedPacket& packet));
200 };
201
213 TEST_F(QuicDispatcherTest, TimeWaitListManager) { 202 TEST_F(QuicDispatcherTest, TimeWaitListManager) {
214 CreateTimeWaitListManager(); 203 MockTimeWaitListManager* time_wait_list_manager =
215 204 new MockTimeWaitListManager(
205 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_);
206 // dispatcher takes the ownership of time_wait_list_manager.
207 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
208 time_wait_list_manager);
216 // Create a new session. 209 // Create a new session.
217 IPEndPoint client_address(net::test::Loopback4(), 1); 210 IPEndPoint client_address(net::test::Loopback4(), 1);
218 QuicConnectionId connection_id = 1; 211 QuicConnectionId connection_id = 1;
219 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, _, client_address)) 212 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, _, client_address))
220 .WillOnce(testing::Return(CreateSession( 213 .WillOnce(testing::Return(CreateSession(
221 &dispatcher_, connection_id, client_address, &session1_))); 214 &dispatcher_, connection_id, client_address, &session1_)));
222 ProcessPacket(client_address, connection_id, true, "foo"); 215 ProcessPacket(client_address, connection_id, true, "foo");
223 216
224 // Close the connection by sending public reset packet. 217 // Close the connection by sending public reset packet.
225 QuicPublicResetPacket packet; 218 QuicPublicResetPacket packet;
226 packet.public_header.connection_id = connection_id; 219 packet.public_header.connection_id = connection_id;
227 packet.public_header.reset_flag = true; 220 packet.public_header.reset_flag = true;
228 packet.public_header.version_flag = false; 221 packet.public_header.version_flag = false;
229 packet.rejected_sequence_number = 19191; 222 packet.rejected_sequence_number = 19191;
230 packet.nonce_proof = 132232; 223 packet.nonce_proof = 132232;
231 scoped_ptr<QuicEncryptedPacket> encrypted( 224 scoped_ptr<QuicEncryptedPacket> encrypted(
232 QuicFramer::BuildPublicResetPacket(packet)); 225 QuicFramer::BuildPublicResetPacket(packet));
233 EXPECT_CALL(*session1_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)).Times(1) 226 EXPECT_CALL(*session1_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)).Times(1)
234 .WillOnce(WithoutArgs(Invoke( 227 .WillOnce(WithoutArgs(Invoke(
235 reinterpret_cast<MockServerConnection*>(session1_->connection()), 228 reinterpret_cast<MockServerConnection*>(session1_->connection()),
236 &MockServerConnection::UnregisterOnConnectionClosed))); 229 &MockServerConnection::UnregisterOnConnectionClosed)));
237 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 230 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
238 ProcessUdpPacket(_, _, _)) 231 ProcessUdpPacket(_, _, _))
239 .WillOnce(Invoke( 232 .WillOnce(Invoke(
240 reinterpret_cast<MockConnection*>(session1_->connection()), 233 reinterpret_cast<MockConnection*>(session1_->connection()),
241 &MockConnection::ReallyProcessUdpPacket)); 234 &MockConnection::ReallyProcessUdpPacket));
242 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *encrypted); 235 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *encrypted);
243 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 236 EXPECT_TRUE(time_wait_list_manager->IsConnectionIdInTimeWait(connection_id));
244 237
245 // Dispatcher forwards subsequent packets for this connection_id to the time 238 // Dispatcher forwards subsequent packets for this connection_id to the time
246 // wait list manager. 239 // wait list manager.
247 EXPECT_CALL(*time_wait_list_manager_, 240 EXPECT_CALL(*time_wait_list_manager,
248 ProcessPacket(_, _, connection_id, _, _)).Times(1); 241 ProcessPacket(_, _, connection_id, _, _)).Times(1);
249 ProcessPacket(client_address, connection_id, true, "foo"); 242 ProcessPacket(client_address, connection_id, true, "foo");
250 } 243 }
251 244
252 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { 245 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) {
253 CreateTimeWaitListManager(); 246 MockTimeWaitListManager* time_wait_list_manager =
247 new MockTimeWaitListManager(
248 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_);
249 // dispatcher takes the ownership of time_wait_list_manager.
250 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
251 time_wait_list_manager);
254 252
255 IPEndPoint client_address(net::test::Loopback4(), 1); 253 IPEndPoint client_address(net::test::Loopback4(), 1);
256 QuicConnectionId connection_id = 1; 254 QuicConnectionId connection_id = 1;
257 // Dispatcher forwards all packets for this connection_id to the time wait 255 // Dispatcher forwards all packets for this connection_id to the time wait
258 // list manager. 256 // list manager.
259 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); 257 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0);
260 EXPECT_CALL(*time_wait_list_manager_, 258 EXPECT_CALL(*time_wait_list_manager,
261 ProcessPacket(_, _, connection_id, _, _)).Times(1); 259 ProcessPacket(_, _, connection_id, _, _)).Times(1);
262 string data = "foo"; 260 string data = "foo";
263 ProcessPacket(client_address, connection_id, false, "foo"); 261 ProcessPacket(client_address, connection_id, false, "foo");
264 } 262 }
265 263
266 TEST_F(QuicDispatcherTest, ProcessPacketWithBogusPort) {
267 CreateTimeWaitListManager();
268
269 IPEndPoint client_address(net::test::Loopback4(), 0);
270 IPAddressNumber any4;
271 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4));
272 server_address_ = IPEndPoint(any4, 5);
273
274 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)).Times(0);
275 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
276 ProcessPacket(client_address, 1, true, "foo");
277 EXPECT_EQ(client_address, dispatcher_.current_client_address());
278 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
279 }
280
281 class BlockingWriter : public QuicPacketWriterWrapper { 264 class BlockingWriter : public QuicPacketWriterWrapper {
282 public: 265 public:
283 BlockingWriter() : write_blocked_(false) {} 266 BlockingWriter() : write_blocked_(false) {}
284 267
285 bool IsWriteBlocked() const override { return write_blocked_; } 268 bool IsWriteBlocked() const override { return write_blocked_; }
286 void SetWritable() override { write_blocked_ = false; } 269 void SetWritable() override { write_blocked_ = false; }
287 270
288 WriteResult WritePacket(const char* buffer, 271 WriteResult WritePacket(const char* buffer,
289 size_t buf_len, 272 size_t buf_len,
290 const IPAddressNumber& self_client_address, 273 const IPAddressNumber& self_client_address,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 // And we'll resume where we left off when we get another call. 452 // And we'll resume where we left off when we get another call.
470 EXPECT_CALL(*connection2(), OnCanWrite()); 453 EXPECT_CALL(*connection2(), OnCanWrite());
471 dispatcher_.OnCanWrite(); 454 dispatcher_.OnCanWrite();
472 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 455 EXPECT_FALSE(dispatcher_.HasPendingWrites());
473 } 456 }
474 457
475 } // namespace 458 } // namespace
476 } // namespace test 459 } // namespace test
477 } // namespace tools 460 } // namespace tools
478 } // namespace net 461 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698