OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 last_seq_num = -1; | 372 last_seq_num = -1; |
373 for (int seq_num : receiver->delivered_sequence_numbers_) { | 373 for (int seq_num : receiver->delivered_sequence_numbers_) { |
374 if (last_seq_num > seq_num) { | 374 if (last_seq_num > seq_num) { |
375 reordering_has_occured = true; | 375 reordering_has_occured = true; |
376 break; | 376 break; |
377 } | 377 } |
378 last_seq_num = seq_num; | 378 last_seq_num = seq_num; |
379 } | 379 } |
380 EXPECT_TRUE(reordering_has_occured); | 380 EXPECT_TRUE(reordering_has_occured); |
381 } | 381 } |
382 | |
383 TEST_F(FakeNetworkPipeTest, BurstLoss) { | |
384 const int kLossPercent = 5; | |
385 const int kAvgBurstLength = 3; | |
386 const int kNumPackets = 10000; | |
387 const int kPacketSize = 10; | |
388 | |
389 FakeNetworkPipe::Config config; | |
390 config.queue_length_packets = kNumPackets; | |
391 config.loss_percent = kLossPercent; | |
392 config.avg_burst_loss_length = kAvgBurstLength; | |
393 std::unique_ptr<FakeNetworkPipe> pipe( | |
394 new FakeNetworkPipe(&fake_clock_, config)); | |
395 ReorderTestReceiver* receiver = new ReorderTestReceiver(); | |
396 receiver_.reset(receiver); | |
397 pipe->SetReceiver(receiver_.get()); | |
398 | |
399 SendPackets(pipe.get(), kNumPackets, kPacketSize); | |
400 fake_clock_.AdvanceTimeMilliseconds(1000); | |
401 pipe->Process(); | |
402 | |
403 // Check that the average loss is |kLossPercent| percent. | |
404 double loss_percent = | |
terelius
2016/05/30 15:40:23
nit: maybe call it loss_fraction to make it clear
philipel
2016/05/30 16:05:40
Done.
| |
405 (kNumPackets - receiver->delivered_sequence_numbers_.size()) / | |
406 static_cast<double>(kNumPackets); | |
407 | |
408 EXPECT_NEAR(kLossPercent / 100.0, loss_percent, 0.01); | |
terelius
2016/05/30 15:40:23
nit: 0.01 is the relative error, right? Seems rath
philipel
2016/05/30 16:05:40
It's a bit tight, adjusted it to 0.05. Also tried
| |
409 | |
410 // Find the number of bursts that has occurred. | |
411 size_t received_packets = receiver->delivered_sequence_numbers_.size(); | |
412 int num_bursts = 0; | |
413 for (size_t i = 0; i < received_packets - 1; ++i) { | |
414 int diff = receiver->delivered_sequence_numbers_[i + 1] - | |
415 receiver->delivered_sequence_numbers_[i]; | |
416 if (diff > 1) | |
417 ++num_bursts; | |
418 } | |
419 | |
420 int lost_packets = kNumPackets - receiver->delivered_sequence_numbers_.size(); | |
terelius
2016/05/30 15:40:23
Move this up and reuse in computation of loss_perc
philipel
2016/05/30 16:05:39
Done.
| |
421 double average_burst_length = static_cast<double>(lost_packets) / num_bursts; | |
422 | |
423 EXPECT_NEAR(kAvgBurstLength, average_burst_length, 0.2); | |
424 } | |
382 } // namespace webrtc | 425 } // namespace webrtc |
OLD | NEW |