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/quic/quic_received_packet_manager.h" | 5 #include "net/quic/quic_received_packet_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "net/quic/quic_connection_stats.h" | 10 #include "net/quic/quic_connection_stats.h" |
11 #include "net/quic/test_tools/quic_received_packet_manager_peer.h" | 11 #include "net/quic/test_tools/quic_received_packet_manager_peer.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using std::make_pair; | |
16 using std::pair; | 15 using std::pair; |
17 using std::vector; | 16 using std::vector; |
18 | 17 |
19 namespace net { | 18 namespace net { |
20 namespace test { | 19 namespace test { |
21 | 20 |
22 class EntropyTrackerPeer { | 21 class EntropyTrackerPeer { |
23 public: | 22 public: |
24 static QuicPacketSequenceNumber first_gap( | 23 static QuicPacketSequenceNumber first_gap( |
25 const QuicReceivedPacketManager::EntropyTracker& tracker) { | 24 const QuicReceivedPacketManager::EntropyTracker& tracker) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 void RecordPacketRevived(QuicPacketSequenceNumber sequence_number) { | 206 void RecordPacketRevived(QuicPacketSequenceNumber sequence_number) { |
208 received_manager_.RecordPacketRevived(sequence_number); | 207 received_manager_.RecordPacketRevived(sequence_number); |
209 } | 208 } |
210 | 209 |
211 QuicConnectionStats stats_; | 210 QuicConnectionStats stats_; |
212 QuicReceivedPacketManager received_manager_; | 211 QuicReceivedPacketManager received_manager_; |
213 }; | 212 }; |
214 | 213 |
215 TEST_F(QuicReceivedPacketManagerTest, ReceivedPacketEntropyHash) { | 214 TEST_F(QuicReceivedPacketManagerTest, ReceivedPacketEntropyHash) { |
216 vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies; | 215 vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies; |
217 entropies.push_back(make_pair(1, 12)); | 216 entropies.push_back(std::make_pair(1, 12)); |
218 entropies.push_back(make_pair(7, 1)); | 217 entropies.push_back(std::make_pair(7, 1)); |
219 entropies.push_back(make_pair(2, 33)); | 218 entropies.push_back(std::make_pair(2, 33)); |
220 entropies.push_back(make_pair(5, 3)); | 219 entropies.push_back(std::make_pair(5, 3)); |
221 entropies.push_back(make_pair(8, 34)); | 220 entropies.push_back(std::make_pair(8, 34)); |
222 | 221 |
223 for (size_t i = 0; i < entropies.size(); ++i) { | 222 for (size_t i = 0; i < entropies.size(); ++i) { |
224 RecordPacketReceipt(entropies[i].first, entropies[i].second); | 223 RecordPacketReceipt(entropies[i].first, entropies[i].second); |
225 } | 224 } |
226 | 225 |
227 sort(entropies.begin(), entropies.end()); | 226 std::sort(entropies.begin(), entropies.end()); |
228 | 227 |
229 QuicPacketEntropyHash hash = 0; | 228 QuicPacketEntropyHash hash = 0; |
230 size_t index = 0; | 229 size_t index = 0; |
231 for (size_t i = 1; i <= (*entropies.rbegin()).first; ++i) { | 230 for (size_t i = 1; i <= (*entropies.rbegin()).first; ++i) { |
232 if (entropies[index].first == i) { | 231 if (entropies[index].first == i) { |
233 hash ^= entropies[index].second; | 232 hash ^= entropies[index].second; |
234 ++index; | 233 ++index; |
235 } | 234 } |
236 if (i < 3) continue; | 235 if (i < 3) continue; |
237 EXPECT_EQ(hash, received_manager_.EntropyHash(i)); | 236 EXPECT_EQ(hash, received_manager_.EntropyHash(i)); |
(...skipping 11 matching lines...) Expand all Loading... |
249 } | 248 } |
250 | 249 |
251 TEST_F(QuicReceivedPacketManagerTest, EntropyHashAboveLargestObserved) { | 250 TEST_F(QuicReceivedPacketManagerTest, EntropyHashAboveLargestObserved) { |
252 EXPECT_EQ(0, received_manager_.EntropyHash(0)); | 251 EXPECT_EQ(0, received_manager_.EntropyHash(0)); |
253 RecordPacketReceipt(4, 5); | 252 RecordPacketReceipt(4, 5); |
254 EXPECT_EQ(0, received_manager_.EntropyHash(3)); | 253 EXPECT_EQ(0, received_manager_.EntropyHash(3)); |
255 } | 254 } |
256 | 255 |
257 TEST_F(QuicReceivedPacketManagerTest, SetCumulativeEntropyUpTo) { | 256 TEST_F(QuicReceivedPacketManagerTest, SetCumulativeEntropyUpTo) { |
258 vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies; | 257 vector<pair<QuicPacketSequenceNumber, QuicPacketEntropyHash> > entropies; |
259 entropies.push_back(make_pair(1, 12)); | 258 entropies.push_back(std::make_pair(1, 12)); |
260 entropies.push_back(make_pair(2, 1)); | 259 entropies.push_back(std::make_pair(2, 1)); |
261 entropies.push_back(make_pair(3, 33)); | 260 entropies.push_back(std::make_pair(3, 33)); |
262 entropies.push_back(make_pair(4, 3)); | 261 entropies.push_back(std::make_pair(4, 3)); |
263 entropies.push_back(make_pair(6, 34)); | 262 entropies.push_back(std::make_pair(6, 34)); |
264 entropies.push_back(make_pair(7, 29)); | 263 entropies.push_back(std::make_pair(7, 29)); |
265 | 264 |
266 QuicPacketEntropyHash entropy_hash = 0; | 265 QuicPacketEntropyHash entropy_hash = 0; |
267 for (size_t i = 0; i < entropies.size(); ++i) { | 266 for (size_t i = 0; i < entropies.size(); ++i) { |
268 RecordPacketReceipt(entropies[i].first, entropies[i].second); | 267 RecordPacketReceipt(entropies[i].first, entropies[i].second); |
269 entropy_hash ^= entropies[i].second; | 268 entropy_hash ^= entropies[i].second; |
270 } | 269 } |
271 EXPECT_EQ(entropy_hash, received_manager_.EntropyHash(7)); | 270 EXPECT_EQ(entropy_hash, received_manager_.EntropyHash(7)); |
272 | 271 |
273 // Now set the entropy hash up to 5 to be 100. | 272 // Now set the entropy hash up to 5 to be 100. |
274 entropy_hash ^= 100; | 273 entropy_hash ^= 100; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 QuicAckFrame ack; | 356 QuicAckFrame ack; |
358 received_manager_.UpdateReceivedPacketInfo(&ack, QuicTime::Zero()); | 357 received_manager_.UpdateReceivedPacketInfo(&ack, QuicTime::Zero()); |
359 EXPECT_TRUE(ack.missing_packets.empty()); | 358 EXPECT_TRUE(ack.missing_packets.empty()); |
360 EXPECT_TRUE(ack.revived_packets.empty()); | 359 EXPECT_TRUE(ack.revived_packets.empty()); |
361 } | 360 } |
362 | 361 |
363 | 362 |
364 } // namespace | 363 } // namespace |
365 } // namespace test | 364 } // namespace test |
366 } // namespace net | 365 } // namespace net |
OLD | NEW |