Chromium Code Reviews| Index: webrtc/test/fake_network_pipe.cc |
| diff --git a/webrtc/test/fake_network_pipe.cc b/webrtc/test/fake_network_pipe.cc |
| index ea4e551f7ba7a52046bb3856d0266a639ce3a4dc..ab4354f58f1f605b8d14eee0ed3781b19808c946 100644 |
| --- a/webrtc/test/fake_network_pipe.cc |
| +++ b/webrtc/test/fake_network_pipe.cc |
| @@ -34,7 +34,27 @@ FakeNetworkPipe::FakeNetworkPipe(Clock* clock, |
| dropped_packets_(0), |
| sent_packets_(0), |
| total_packet_delay_(0), |
| - next_process_time_(clock_->TimeInMilliseconds()) {} |
| + bursting_(false), |
| + next_process_time_(clock_->TimeInMilliseconds()) { |
| + double prob_loss = config.loss_percent / 100.0; |
| + if (config_.avg_burst_loss_length == -1) { |
| + // Uniform loss |
| + prob_loss_bursting_ = 0; |
|
terelius
2016/05/30 15:40:23
This won't really be uniform. After each loss, the
philipel
2016/05/30 16:05:39
Fixed.
|
| + prob_start_bursting_ = prob_loss; |
| + } else { |
| + // Lose packets according to geometric distribution. |
| + int avg_burst_loss_length = config.avg_burst_loss_length; |
| + int min_avg_burst_loss_length = std::ceil(prob_loss / (1 - prob_loss)); |
| + |
| + RTC_CHECK_GT(avg_burst_loss_length, min_avg_burst_loss_length) |
| + << "For a total packet loss of " << config.loss_percent << "%% then" |
| + << " avg_burst_loss_length must be " << min_avg_burst_loss_length + 1 |
| + << " or higher."; |
| + |
| + prob_loss_bursting_ = (1.0 - 1.0 / avg_burst_loss_length); |
| + prob_start_bursting_ = prob_loss / (1 - prob_loss) / avg_burst_loss_length; |
| + } |
| +} |
| FakeNetworkPipe::~FakeNetworkPipe() { |
| while (!capacity_link_.empty()) { |
| @@ -118,10 +138,15 @@ void FakeNetworkPipe::Process() { |
| NetworkPacket* packet = capacity_link_.front(); |
| capacity_link_.pop(); |
| - // Packets are randomly dropped after being affected by the bottleneck. |
| - if (random_.Rand(100) < static_cast<uint32_t>(config_.loss_percent)) { |
| + // Drop packets at an average rate of |config_.loss_percent| with |
| + // and average loss burst length of |config_.avg_burst_loss_length|. |
| + if ((bursting_ && random_.Rand<double>() < prob_loss_bursting_) || |
| + (!bursting_ && random_.Rand<double>() < prob_start_bursting_)) { |
| + bursting_ = true; |
| delete packet; |
| continue; |
| + } else { |
| + bursting_ = false; |
| } |
| int arrival_time_jitter = random_.Gaussian( |