| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/congestion_control/send_algorithm_simulator.h" | 5 #include "net/quic/congestion_control/send_algorithm_simulator.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (!sent_packets_.empty() && | 231 if (!sent_packets_.empty() && |
| 232 !sent_packets_.back().ack_time.IsInitialized() && | 232 !sent_packets_.back().ack_time.IsInitialized() && |
| 233 loss_correlation_ * kuint64max > simple_random_.RandUint64()) { | 233 loss_correlation_ * kuint64max > simple_random_.RandUint64()) { |
| 234 packet_lost = true; | 234 packet_lost = true; |
| 235 } | 235 } |
| 236 | 236 |
| 237 QuicTime ack_time = clock_->Now().Add(rtt_); | 237 QuicTime ack_time = clock_->Now().Add(rtt_); |
| 238 // If the number of bytes in flight are less than the bdp, there's | 238 // If the number of bytes in flight are less than the bdp, there's |
| 239 // no buffering delay. Bytes lost from the buffer are not counted. | 239 // no buffering delay. Bytes lost from the buffer are not counted. |
| 240 QuicByteCount bdp = bandwidth_.ToBytesPerPeriod(rtt_); | 240 QuicByteCount bdp = bandwidth_.ToBytesPerPeriod(rtt_); |
| 241 if (sent_packets_.size() * kPacketSize > bdp) { | 241 if ((sent_packets_.size() + 1) * kPacketSize > bdp) { |
| 242 QuicByteCount qsize = sent_packets_.size() * kPacketSize - bdp; | 242 QuicByteCount qsize = (sent_packets_.size() + 1) * kPacketSize - bdp; |
| 243 ack_time = ack_time.Add(bandwidth_.TransferTime(qsize)); | 243 ack_time = ack_time.Add(bandwidth_.TransferTime(qsize)); |
| 244 } | 244 } |
| 245 // If the packet is lost, give it an ack time of Zero. | 245 // If the packet is lost, give it an ack time of Zero. |
| 246 sent_packets_.push_back(SentPacket( | 246 sent_packets_.push_back(SentPacket( |
| 247 next_sent_, clock_->Now(), packet_lost ? QuicTime::Zero() : ack_time)); | 247 next_sent_, clock_->Now(), packet_lost ? QuicTime::Zero() : ack_time)); |
| 248 } | 248 } |
| 249 ++next_sent_; | 249 ++next_sent_; |
| 250 bytes_in_flight_ += kPacketSize; | 250 bytes_in_flight_ += kPacketSize; |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 void SendAlgorithmSimulator::AdvanceTime(QuicTime::Delta delta) { | 264 void SendAlgorithmSimulator::AdvanceTime(QuicTime::Delta delta) { |
| 265 clock_->AdvanceTime(delta); | 265 clock_->AdvanceTime(delta); |
| 266 } | 266 } |
| 267 | 267 |
| 268 // Elapsed time from the start of the connection. | 268 // Elapsed time from the start of the connection. |
| 269 QuicTime SendAlgorithmSimulator::ElapsedTime() { | 269 QuicTime SendAlgorithmSimulator::ElapsedTime() { |
| 270 return clock_->Now(); | 270 return clock_->Now(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace net | 273 } // namespace net |
| OLD | NEW |