OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/quic/quic_multipath_sent_packet_manager.h" | |
6 | |
7 #include "net/quic/test_tools/quic_multipath_sent_packet_manager_peer.h" | |
8 #include "net/quic/test_tools/quic_test_utils.h" | |
9 #include "net/test/gtest_util.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using testing::Return; | |
14 using testing::StrictMock; | |
15 using testing::_; | |
16 | |
17 namespace net { | |
18 namespace test { | |
19 | |
20 namespace { | |
21 | |
22 const QuicPathId kTestPathId1 = 1; | |
23 const QuicPathId kTestPathId2 = 2; | |
24 const QuicPathId kTestPathId3 = 3; | |
25 | |
26 class QuicMultipathSentPacketManagerTest : public testing::Test { | |
27 public: | |
28 QuicMultipathSentPacketManagerTest() | |
29 : manager_0_(new StrictMock<MockSentPacketManager>), | |
30 manager_1_(new StrictMock<MockSentPacketManager>), | |
31 manager_2_(new StrictMock<MockSentPacketManager>), | |
32 multipath_manager_(manager_0_, &delegate_) { | |
33 // Paths 0 and 1 are active, and path 2 is closing. | |
34 QuicMultipathSentPacketManagerPeer::AddPathWithActiveState( | |
35 &multipath_manager_, manager_1_); | |
36 QuicMultipathSentPacketManagerPeer::AddPathWithCloseState( | |
37 &multipath_manager_, manager_2_); | |
38 } | |
39 | |
40 ~QuicMultipathSentPacketManagerTest() override {} | |
41 | |
42 MockSentPacketManager* manager_0_; | |
43 MockSentPacketManager* manager_1_; | |
44 MockSentPacketManager* manager_2_; | |
45 QuicMultipathSentPacketManager multipath_manager_; | |
46 MockClock clock_; | |
47 StrictMock<MockConnectionCloseDelegate> delegate_; | |
48 }; | |
49 | |
50 TEST_F(QuicMultipathSentPacketManagerTest, SetFromConfig) { | |
51 EXPECT_CALL(*manager_0_, SetFromConfig(_)).Times(1); | |
52 EXPECT_CALL(*manager_1_, SetFromConfig(_)).Times(1); | |
53 EXPECT_CALL(*manager_2_, SetFromConfig(_)).Times(1); | |
54 QuicConfig config; | |
55 multipath_manager_.SetFromConfig(config); | |
56 } | |
57 | |
58 TEST_F(QuicMultipathSentPacketManagerTest, ResumeConnectionState) { | |
59 EXPECT_CALL(*manager_0_, ResumeConnectionState(_, true)); | |
60 multipath_manager_.ResumeConnectionState(CachedNetworkParameters(), true); | |
61 } | |
62 | |
63 TEST_F(QuicMultipathSentPacketManagerTest, SetNumOpenStreams) { | |
64 size_t kNumStreams = 10; | |
65 EXPECT_CALL(*manager_0_, SetNumOpenStreams(kNumStreams)); | |
66 EXPECT_CALL(*manager_1_, SetNumOpenStreams(kNumStreams)); | |
67 EXPECT_CALL(*manager_2_, SetNumOpenStreams(kNumStreams)); | |
68 multipath_manager_.SetNumOpenStreams(kNumStreams); | |
69 } | |
70 | |
71 TEST_F(QuicMultipathSentPacketManagerTest, SetMaxPacingRate) { | |
72 QuicBandwidth kBandwidth = QuicBandwidth::FromBitsPerSecond(1000); | |
73 EXPECT_CALL(*manager_0_, SetMaxPacingRate(kBandwidth)); | |
74 multipath_manager_.SetMaxPacingRate(kBandwidth); | |
75 } | |
76 | |
77 TEST_F(QuicMultipathSentPacketManagerTest, SetHandshakeConfirmed) { | |
78 EXPECT_CALL(*manager_0_, SetHandshakeConfirmed()); | |
79 multipath_manager_.SetHandshakeConfirmed(); | |
80 } | |
81 | |
82 TEST_F(QuicMultipathSentPacketManagerTest, OnIncomingAck) { | |
83 QuicAckFrame frame0; | |
84 QuicAckFrame frame1; | |
85 frame1.path_id = kTestPathId1; | |
86 QuicAckFrame frame2; | |
87 frame2.path_id = kTestPathId2; | |
88 QuicAckFrame frame3; | |
89 frame3.path_id = kTestPathId3; | |
90 EXPECT_CALL(*manager_0_, OnIncomingAck(_, QuicTime::Zero())); | |
91 EXPECT_CALL(*manager_1_, OnIncomingAck(_, QuicTime::Zero())); | |
92 EXPECT_CALL(*manager_2_, OnIncomingAck(_, QuicTime::Zero())).Times(0); | |
93 multipath_manager_.OnIncomingAck(frame0, QuicTime::Zero()); | |
94 multipath_manager_.OnIncomingAck(frame1, QuicTime::Zero()); | |
95 multipath_manager_.OnIncomingAck(frame2, QuicTime::Zero()); | |
96 multipath_manager_.OnIncomingAck(frame3, QuicTime::Zero()); | |
97 } | |
98 | |
99 TEST_F(QuicMultipathSentPacketManagerTest, RetransmitUnackedPackets) { | |
100 EXPECT_CALL(*manager_0_, RetransmitUnackedPackets(HANDSHAKE_RETRANSMISSION)); | |
101 multipath_manager_.RetransmitUnackedPackets(HANDSHAKE_RETRANSMISSION); | |
102 } | |
103 | |
104 TEST_F(QuicMultipathSentPacketManagerTest, MaybeRetransmitTailLossProbe) { | |
105 EXPECT_CALL(*manager_0_, MaybeRetransmitTailLossProbe()) | |
106 .WillOnce(Return(false)); | |
107 EXPECT_CALL(*manager_1_, MaybeRetransmitTailLossProbe()) | |
108 .WillOnce(Return(false)); | |
109 EXPECT_FALSE(multipath_manager_.MaybeRetransmitTailLossProbe()); | |
110 EXPECT_CALL(*manager_0_, MaybeRetransmitTailLossProbe()) | |
111 .WillOnce(Return(false)); | |
112 EXPECT_CALL(*manager_1_, MaybeRetransmitTailLossProbe()) | |
113 .WillOnce(Return(true)); | |
114 EXPECT_TRUE(multipath_manager_.MaybeRetransmitTailLossProbe()); | |
115 } | |
116 | |
117 TEST_F(QuicMultipathSentPacketManagerTest, NeuterUnencryptedPackets) { | |
118 EXPECT_CALL(*manager_0_, NeuterUnencryptedPackets()); | |
119 multipath_manager_.NeuterUnencryptedPackets(); | |
120 } | |
121 | |
122 TEST_F(QuicMultipathSentPacketManagerTest, HasPendingRetransmissions) { | |
123 EXPECT_CALL(*manager_0_, HasPendingRetransmissions()).WillOnce(Return(true)); | |
124 EXPECT_TRUE(multipath_manager_.HasPendingRetransmissions()); | |
125 } | |
126 | |
127 TEST_F(QuicMultipathSentPacketManagerTest, NextPendingRetransmission) { | |
128 SerializedPacket packet(kDefaultPathId, 1, PACKET_6BYTE_PACKET_NUMBER, | |
129 nullptr, 1250, 0u, false, false); | |
130 PendingRetransmission retransmission( | |
131 packet.path_id, packet.packet_number, LOSS_RETRANSMISSION, | |
132 packet.retransmittable_frames, packet.has_crypto_handshake, | |
133 packet.num_padding_bytes, packet.encryption_level, | |
134 packet.packet_number_length); | |
135 EXPECT_CALL(*manager_0_, NextPendingRetransmission()) | |
136 .WillOnce(Return(retransmission)); | |
137 multipath_manager_.NextPendingRetransmission(); | |
138 } | |
139 | |
140 TEST_F(QuicMultipathSentPacketManagerTest, HasUnackedPackets) { | |
141 EXPECT_CALL(*manager_0_, HasUnackedPackets()).WillOnce(Return(false)); | |
142 EXPECT_CALL(*manager_1_, HasUnackedPackets()).WillOnce(Return(false)); | |
143 EXPECT_CALL(*manager_2_, HasUnackedPackets()).Times(0); | |
144 EXPECT_FALSE(multipath_manager_.HasUnackedPackets()); | |
145 EXPECT_CALL(*manager_0_, HasUnackedPackets()).WillOnce(Return(false)); | |
146 EXPECT_CALL(*manager_1_, HasUnackedPackets()).WillOnce(Return(true)); | |
147 EXPECT_TRUE(multipath_manager_.HasUnackedPackets()); | |
148 } | |
149 | |
150 TEST_F(QuicMultipathSentPacketManagerTest, GetLeastUnacked) { | |
151 EXPECT_CALL(*manager_0_, GetLeastUnacked(kDefaultPathId)).WillOnce(Return(2)); | |
152 EXPECT_CALL(*manager_1_, GetLeastUnacked(kTestPathId1)).WillOnce(Return(3)); | |
153 EXPECT_CALL(*manager_2_, GetLeastUnacked(kTestPathId2)).WillOnce(Return(4)); | |
154 EXPECT_EQ(2u, multipath_manager_.GetLeastUnacked(kDefaultPathId)); | |
155 EXPECT_EQ(3u, multipath_manager_.GetLeastUnacked(kTestPathId1)); | |
156 EXPECT_EQ(4u, multipath_manager_.GetLeastUnacked(kTestPathId2)); | |
157 EXPECT_DFATAL(multipath_manager_.GetLeastUnacked(kTestPathId3), ""); | |
158 } | |
159 | |
160 TEST_F(QuicMultipathSentPacketManagerTest, OnPacketSent) { | |
161 SerializedPacket packet0(kDefaultPathId, 1, PACKET_6BYTE_PACKET_NUMBER, | |
162 nullptr, 1250, 0u, false, false); | |
163 SerializedPacket packet1(kTestPathId1, 1, PACKET_6BYTE_PACKET_NUMBER, nullptr, | |
164 1250, 0u, false, false); | |
165 SerializedPacket packet2(kTestPathId2, 1, PACKET_6BYTE_PACKET_NUMBER, nullptr, | |
166 1250, 0u, false, false); | |
167 SerializedPacket packet3(kTestPathId3, 1, PACKET_6BYTE_PACKET_NUMBER, nullptr, | |
168 1250, 0u, false, false); | |
169 EXPECT_CALL(*manager_0_, | |
170 OnPacketSent(&packet0, kInvalidPathId, 0, clock_.Now(), | |
171 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)); | |
172 multipath_manager_.OnPacketSent(&packet0, kInvalidPathId, 0, clock_.Now(), | |
173 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); | |
174 EXPECT_CALL(*manager_1_, | |
175 OnPacketSent(&packet1, kInvalidPathId, 0, clock_.Now(), | |
176 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)); | |
177 multipath_manager_.OnPacketSent(&packet1, kInvalidPathId, 0, clock_.Now(), | |
178 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); | |
179 EXPECT_CALL(*manager_2_, OnPacketSent(_, _, _, _, _, _)).Times(0); | |
180 EXPECT_CALL(delegate_, | |
181 OnUnrecoverableError(QUIC_MULTIPATH_PATH_NOT_ACTIVE, _, _)); | |
182 EXPECT_DFATAL(multipath_manager_.OnPacketSent( | |
183 &packet2, kInvalidPathId, 0, clock_.Now(), | |
184 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA), | |
185 ""); | |
186 EXPECT_CALL(delegate_, | |
187 OnUnrecoverableError(QUIC_MULTIPATH_PATH_DOES_NOT_EXIST, _, _)); | |
188 EXPECT_DFATAL(multipath_manager_.OnPacketSent( | |
189 &packet3, kInvalidPathId, 0, clock_.Now(), | |
190 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA), | |
191 ""); | |
192 } | |
193 | |
194 TEST_F(QuicMultipathSentPacketManagerTest, OnRetransmissionTimeout) { | |
195 QuicTime time0 = clock_.Now() + QuicTime::Delta::FromMilliseconds(50); | |
196 QuicTime time1 = clock_.Now() + QuicTime::Delta::FromMilliseconds(100); | |
197 EXPECT_CALL(*manager_0_, GetRetransmissionTime()).WillOnce(Return(time0)); | |
198 EXPECT_CALL(*manager_1_, GetRetransmissionTime()).WillOnce(Return(time1)); | |
199 EXPECT_CALL(*manager_0_, OnRetransmissionTimeout()); | |
200 multipath_manager_.OnRetransmissionTimeout(); | |
201 } | |
202 | |
203 TEST_F(QuicMultipathSentPacketManagerTest, TimeUntilSend) { | |
204 QuicPathId path_id = kInvalidPathId; | |
205 EXPECT_CALL(*manager_0_, | |
206 TimeUntilSend(clock_.Now(), HAS_RETRANSMITTABLE_DATA, &path_id)) | |
207 .WillOnce(Return(QuicTime::Delta::FromMilliseconds(200))); | |
208 EXPECT_CALL(*manager_1_, | |
209 TimeUntilSend(clock_.Now(), HAS_RETRANSMITTABLE_DATA, &path_id)) | |
210 .WillOnce(Return(QuicTime::Delta::FromMilliseconds(100))); | |
211 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(100), | |
212 multipath_manager_.TimeUntilSend( | |
213 clock_.Now(), HAS_RETRANSMITTABLE_DATA, &path_id)); | |
214 EXPECT_EQ(kTestPathId1, path_id); | |
215 } | |
216 | |
217 TEST_F(QuicMultipathSentPacketManagerTest, GetRetransmissionTime) { | |
218 QuicTime time0 = clock_.Now() + QuicTime::Delta::FromMilliseconds(200); | |
219 QuicTime time1 = clock_.Now() + QuicTime::Delta::FromMilliseconds(100); | |
220 EXPECT_CALL(*manager_0_, GetRetransmissionTime()).WillOnce(Return(time0)); | |
221 EXPECT_CALL(*manager_1_, GetRetransmissionTime()).WillOnce(Return(time1)); | |
222 EXPECT_EQ(time1, multipath_manager_.GetRetransmissionTime()); | |
223 } | |
224 | |
225 TEST_F(QuicMultipathSentPacketManagerTest, GetRttStats) { | |
226 EXPECT_CALL(*manager_0_, GetRttStats()); | |
227 multipath_manager_.GetRttStats(); | |
228 } | |
229 | |
230 TEST_F(QuicMultipathSentPacketManagerTest, BandwidthEstimate) { | |
231 QuicBandwidth bandwidth = QuicBandwidth::FromKBitsPerSecond(100); | |
232 EXPECT_CALL(*manager_0_, BandwidthEstimate()).WillOnce(Return(bandwidth)); | |
233 EXPECT_EQ(bandwidth, multipath_manager_.BandwidthEstimate()); | |
234 } | |
235 | |
236 TEST_F(QuicMultipathSentPacketManagerTest, GetCongestionWindowInTcpMss) { | |
237 EXPECT_CALL(*manager_0_, GetCongestionWindowInTcpMss()).WillOnce(Return(100)); | |
238 EXPECT_EQ(100u, multipath_manager_.GetCongestionWindowInTcpMss()); | |
239 } | |
240 | |
241 TEST_F(QuicMultipathSentPacketManagerTest, EstimateMaxPacketsInFlight) { | |
242 QuicByteCount max_packet_length = 1250; | |
243 EXPECT_CALL(*manager_0_, EstimateMaxPacketsInFlight(max_packet_length)) | |
244 .WillOnce(Return(100)); | |
245 EXPECT_CALL(*manager_1_, EstimateMaxPacketsInFlight(max_packet_length)) | |
246 .WillOnce(Return(200)); | |
247 EXPECT_CALL(*manager_2_, EstimateMaxPacketsInFlight(max_packet_length)) | |
248 .WillOnce(Return(300)); | |
249 EXPECT_EQ(300u, | |
250 multipath_manager_.EstimateMaxPacketsInFlight(max_packet_length)); | |
251 } | |
252 | |
253 TEST_F(QuicMultipathSentPacketManagerTest, GetSlowStartThresholdInTcpMss) { | |
254 EXPECT_CALL(*manager_0_, GetSlowStartThresholdInTcpMss()) | |
255 .WillOnce(Return(100)); | |
256 EXPECT_EQ(100u, multipath_manager_.GetSlowStartThresholdInTcpMss()); | |
257 } | |
258 | |
259 TEST_F(QuicMultipathSentPacketManagerTest, CancelRetransmissionsForStream) { | |
260 EXPECT_CALL(*manager_0_, CancelRetransmissionsForStream(1)); | |
261 EXPECT_CALL(*manager_1_, CancelRetransmissionsForStream(1)); | |
262 EXPECT_CALL(*manager_2_, CancelRetransmissionsForStream(1)); | |
263 multipath_manager_.CancelRetransmissionsForStream(1); | |
264 } | |
265 | |
266 TEST_F(QuicMultipathSentPacketManagerTest, OnConnectionMigration) { | |
267 EXPECT_CALL(*manager_0_, OnConnectionMigration(kDefaultPathId, PORT_CHANGE)); | |
268 EXPECT_CALL(*manager_2_, OnConnectionMigration(_, _)).Times(0); | |
269 multipath_manager_.OnConnectionMigration(kDefaultPathId, PORT_CHANGE); | |
270 EXPECT_CALL(delegate_, | |
271 OnUnrecoverableError(QUIC_MULTIPATH_PATH_NOT_ACTIVE, _, _)); | |
272 EXPECT_DFATAL( | |
273 multipath_manager_.OnConnectionMigration(kTestPathId2, PORT_CHANGE), ""); | |
274 EXPECT_CALL(delegate_, | |
275 OnUnrecoverableError(QUIC_MULTIPATH_PATH_DOES_NOT_EXIST, _, _)); | |
276 EXPECT_DFATAL( | |
277 multipath_manager_.OnConnectionMigration(kTestPathId3, PORT_CHANGE), ""); | |
278 } | |
279 | |
280 TEST_F(QuicMultipathSentPacketManagerTest, IsHandshakeConfirmed) { | |
281 EXPECT_CALL(*manager_0_, IsHandshakeConfirmed()).WillOnce(Return(true)); | |
282 EXPECT_TRUE(multipath_manager_.IsHandshakeConfirmed()); | |
283 } | |
284 | |
285 TEST_F(QuicMultipathSentPacketManagerTest, SetDebugDelegate) { | |
286 EXPECT_CALL(*manager_0_, SetDebugDelegate(nullptr)); | |
287 EXPECT_CALL(*manager_1_, SetDebugDelegate(nullptr)); | |
288 EXPECT_CALL(*manager_2_, SetDebugDelegate(nullptr)); | |
289 multipath_manager_.SetDebugDelegate(nullptr); | |
290 } | |
291 | |
292 TEST_F(QuicMultipathSentPacketManagerTest, GetLargestObserved) { | |
293 EXPECT_CALL(*manager_0_, GetLargestObserved(kDefaultPathId)) | |
294 .WillOnce(Return(10)); | |
295 EXPECT_CALL(*manager_1_, GetLargestObserved(kTestPathId1)) | |
296 .WillOnce(Return(11)); | |
297 EXPECT_CALL(*manager_2_, GetLargestObserved(kTestPathId2)) | |
298 .WillOnce(Return(12)); | |
299 EXPECT_EQ(10u, multipath_manager_.GetLargestObserved(kDefaultPathId)); | |
300 EXPECT_EQ(11u, multipath_manager_.GetLargestObserved(kTestPathId1)); | |
301 EXPECT_EQ(12u, multipath_manager_.GetLargestObserved(kTestPathId2)); | |
302 EXPECT_DFATAL(multipath_manager_.GetLargestObserved(kTestPathId3), ""); | |
303 } | |
304 | |
305 TEST_F(QuicMultipathSentPacketManagerTest, GetLargestSentPacket) { | |
306 EXPECT_CALL(*manager_0_, GetLargestSentPacket(kDefaultPathId)) | |
307 .WillOnce(Return(10)); | |
308 EXPECT_CALL(*manager_1_, GetLargestSentPacket(kTestPathId1)) | |
309 .WillOnce(Return(11)); | |
310 EXPECT_CALL(*manager_2_, GetLargestSentPacket(kTestPathId2)) | |
311 .WillOnce(Return(12)); | |
312 EXPECT_EQ(10u, multipath_manager_.GetLargestSentPacket(kDefaultPathId)); | |
313 EXPECT_EQ(11u, multipath_manager_.GetLargestSentPacket(kTestPathId1)); | |
314 EXPECT_EQ(12u, multipath_manager_.GetLargestSentPacket(kTestPathId2)); | |
315 EXPECT_DFATAL(multipath_manager_.GetLargestSentPacket(kTestPathId3), ""); | |
316 } | |
317 | |
318 TEST_F(QuicMultipathSentPacketManagerTest, GetLeastPacketAwaitedByPeer) { | |
319 EXPECT_CALL(*manager_0_, GetLeastPacketAwaitedByPeer(kDefaultPathId)) | |
320 .WillOnce(Return(10)); | |
321 EXPECT_CALL(*manager_1_, GetLeastPacketAwaitedByPeer(kTestPathId1)) | |
322 .WillOnce(Return(11)); | |
323 EXPECT_CALL(*manager_2_, GetLeastPacketAwaitedByPeer(kTestPathId2)) | |
324 .WillOnce(Return(12)); | |
325 EXPECT_EQ(10u, | |
326 multipath_manager_.GetLeastPacketAwaitedByPeer(kDefaultPathId)); | |
327 EXPECT_EQ(11u, multipath_manager_.GetLeastPacketAwaitedByPeer(kTestPathId1)); | |
328 EXPECT_EQ(12u, multipath_manager_.GetLeastPacketAwaitedByPeer(kTestPathId2)); | |
329 EXPECT_DFATAL(multipath_manager_.GetLeastPacketAwaitedByPeer(kTestPathId3), | |
330 ""); | |
331 } | |
332 | |
333 TEST_F(QuicMultipathSentPacketManagerTest, SetNetworkChangeVisitor) { | |
334 EXPECT_CALL(*manager_0_, SetNetworkChangeVisitor(nullptr)); | |
335 EXPECT_CALL(*manager_1_, SetNetworkChangeVisitor(nullptr)); | |
336 multipath_manager_.SetNetworkChangeVisitor(nullptr); | |
337 } | |
338 | |
339 TEST_F(QuicMultipathSentPacketManagerTest, InSlowStart) { | |
340 EXPECT_CALL(*manager_0_, InSlowStart()).WillOnce(Return(true)); | |
341 EXPECT_TRUE(multipath_manager_.InSlowStart()); | |
342 } | |
343 | |
344 TEST_F(QuicMultipathSentPacketManagerTest, GetConsecutiveRtoCount) { | |
345 EXPECT_CALL(*manager_0_, GetConsecutiveRtoCount()).WillOnce(Return(4)); | |
346 EXPECT_EQ(4u, multipath_manager_.GetConsecutiveRtoCount()); | |
347 } | |
348 | |
349 TEST_F(QuicMultipathSentPacketManagerTest, GetConsecutiveTlpCount) { | |
350 EXPECT_CALL(*manager_0_, GetConsecutiveTlpCount()).WillOnce(Return(3)); | |
351 EXPECT_EQ(3u, multipath_manager_.GetConsecutiveTlpCount()); | |
352 } | |
353 | |
354 } // namespace | |
355 } // namespace test | |
356 } // namespace net | |
OLD | NEW |