Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 27 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, |
| 28 const FakeNetworkPipe::Config& config, | 28 const FakeNetworkPipe::Config& config, |
| 29 uint64_t seed) | 29 uint64_t seed) |
| 30 : clock_(clock), | 30 : clock_(clock), |
| 31 packet_receiver_(NULL), | 31 packet_receiver_(NULL), |
| 32 random_(seed), | 32 random_(seed), |
| 33 config_(config), | 33 config_(config), |
| 34 dropped_packets_(0), | 34 dropped_packets_(0), |
| 35 sent_packets_(0), | 35 sent_packets_(0), |
| 36 total_packet_delay_(0), | 36 total_packet_delay_(0), |
| 37 next_process_time_(clock_->TimeInMilliseconds()) {} | 37 bursting_(false), |
| 38 next_process_time_(clock_->TimeInMilliseconds()) { | |
| 39 double prob_loss = config.loss_percent / 100.0; | |
| 40 if (config_.avg_burst_loss_length == -1) { | |
| 41 // Uniform loss | |
| 42 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.
| |
| 43 prob_start_bursting_ = prob_loss; | |
| 44 } else { | |
| 45 // Lose packets according to geometric distribution. | |
| 46 int avg_burst_loss_length = config.avg_burst_loss_length; | |
| 47 int min_avg_burst_loss_length = std::ceil(prob_loss / (1 - prob_loss)); | |
| 48 | |
| 49 RTC_CHECK_GT(avg_burst_loss_length, min_avg_burst_loss_length) | |
| 50 << "For a total packet loss of " << config.loss_percent << "%% then" | |
| 51 << " avg_burst_loss_length must be " << min_avg_burst_loss_length + 1 | |
| 52 << " or higher."; | |
| 53 | |
| 54 prob_loss_bursting_ = (1.0 - 1.0 / avg_burst_loss_length); | |
| 55 prob_start_bursting_ = prob_loss / (1 - prob_loss) / avg_burst_loss_length; | |
| 56 } | |
| 57 } | |
| 38 | 58 |
| 39 FakeNetworkPipe::~FakeNetworkPipe() { | 59 FakeNetworkPipe::~FakeNetworkPipe() { |
| 40 while (!capacity_link_.empty()) { | 60 while (!capacity_link_.empty()) { |
| 41 delete capacity_link_.front(); | 61 delete capacity_link_.front(); |
| 42 capacity_link_.pop(); | 62 capacity_link_.pop(); |
| 43 } | 63 } |
| 44 while (!delay_link_.empty()) { | 64 while (!delay_link_.empty()) { |
| 45 delete *delay_link_.begin(); | 65 delete *delay_link_.begin(); |
| 46 delay_link_.erase(delay_link_.begin()); | 66 delay_link_.erase(delay_link_.begin()); |
| 47 } | 67 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 std::queue<NetworkPacket*> packets_to_deliver; | 131 std::queue<NetworkPacket*> packets_to_deliver; |
| 112 { | 132 { |
| 113 rtc::CritScope crit(&lock_); | 133 rtc::CritScope crit(&lock_); |
| 114 // Check the capacity link first. | 134 // Check the capacity link first. |
| 115 while (!capacity_link_.empty() && | 135 while (!capacity_link_.empty() && |
| 116 time_now >= capacity_link_.front()->arrival_time()) { | 136 time_now >= capacity_link_.front()->arrival_time()) { |
| 117 // Time to get this packet. | 137 // Time to get this packet. |
| 118 NetworkPacket* packet = capacity_link_.front(); | 138 NetworkPacket* packet = capacity_link_.front(); |
| 119 capacity_link_.pop(); | 139 capacity_link_.pop(); |
| 120 | 140 |
| 121 // Packets are randomly dropped after being affected by the bottleneck. | 141 // Drop packets at an average rate of |config_.loss_percent| with |
| 122 if (random_.Rand(100) < static_cast<uint32_t>(config_.loss_percent)) { | 142 // and average loss burst length of |config_.avg_burst_loss_length|. |
| 143 if ((bursting_ && random_.Rand<double>() < prob_loss_bursting_) || | |
| 144 (!bursting_ && random_.Rand<double>() < prob_start_bursting_)) { | |
| 145 bursting_ = true; | |
| 123 delete packet; | 146 delete packet; |
| 124 continue; | 147 continue; |
| 148 } else { | |
| 149 bursting_ = false; | |
| 125 } | 150 } |
| 126 | 151 |
| 127 int arrival_time_jitter = random_.Gaussian( | 152 int arrival_time_jitter = random_.Gaussian( |
| 128 config_.queue_delay_ms, config_.delay_standard_deviation_ms); | 153 config_.queue_delay_ms, config_.delay_standard_deviation_ms); |
| 129 | 154 |
| 130 // If reordering is not allowed then adjust arrival_time_jitter | 155 // If reordering is not allowed then adjust arrival_time_jitter |
| 131 // to make sure all packets are sent in order. | 156 // to make sure all packets are sent in order. |
| 132 if (!config_.allow_reordering && !delay_link_.empty() && | 157 if (!config_.allow_reordering && !delay_link_.empty() && |
| 133 packet->arrival_time() + arrival_time_jitter < | 158 packet->arrival_time() + arrival_time_jitter < |
| 134 (*delay_link_.rbegin())->arrival_time()) { | 159 (*delay_link_.rbegin())->arrival_time()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { | 192 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { |
| 168 rtc::CritScope crit(&lock_); | 193 rtc::CritScope crit(&lock_); |
| 169 const int64_t kDefaultProcessIntervalMs = 30; | 194 const int64_t kDefaultProcessIntervalMs = 30; |
| 170 if (capacity_link_.empty() || delay_link_.empty()) | 195 if (capacity_link_.empty() || delay_link_.empty()) |
| 171 return kDefaultProcessIntervalMs; | 196 return kDefaultProcessIntervalMs; |
| 172 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), | 197 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), |
| 173 0); | 198 0); |
| 174 } | 199 } |
| 175 | 200 |
| 176 } // namespace webrtc | 201 } // namespace webrtc |
| OLD | NEW |