| 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_sent_packet_manager.h" | 5 #include "net/quic/quic_sent_packet_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME)) { | 132 ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME)) { |
| 133 loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); | 133 loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); |
| 134 } | 134 } |
| 135 send_algorithm_->SetFromConfig(config, is_server_); | 135 send_algorithm_->SetFromConfig(config, is_server_); |
| 136 | 136 |
| 137 if (network_change_visitor_ != NULL) { | 137 if (network_change_visitor_ != NULL) { |
| 138 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); | 138 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 // TODO(ianswett): Combine this method with OnPacketSent once packets are always | |
| 143 // sent in order and the connection tracks RetransmittableFrames for longer. | |
| 144 void QuicSentPacketManager::OnSerializedPacket( | |
| 145 const SerializedPacket& serialized_packet) { | |
| 146 if (serialized_packet.retransmittable_frames) { | |
| 147 ack_notifier_manager_.OnSerializedPacket(serialized_packet); | |
| 148 } | |
| 149 unacked_packets_.AddPacket(serialized_packet); | |
| 150 | |
| 151 if (debug_delegate_ != NULL) { | |
| 152 // TODO(ianswett): Merge calls in the debug delegate. | |
| 153 debug_delegate_->OnSerializedPacket(serialized_packet); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 void QuicSentPacketManager::OnRetransmittedPacket( | 142 void QuicSentPacketManager::OnRetransmittedPacket( |
| 158 QuicPacketSequenceNumber old_sequence_number, | 143 QuicPacketSequenceNumber old_sequence_number, |
| 159 QuicPacketSequenceNumber new_sequence_number) { | 144 QuicPacketSequenceNumber new_sequence_number) { |
| 160 TransmissionType transmission_type; | 145 TransmissionType transmission_type; |
| 161 PendingRetransmissionMap::iterator it = | 146 PendingRetransmissionMap::iterator it = |
| 162 pending_retransmissions_.find(old_sequence_number); | 147 pending_retransmissions_.find(old_sequence_number); |
| 163 if (it != pending_retransmissions_.end()) { | 148 if (it != pending_retransmissions_.end()) { |
| 164 transmission_type = it->second; | 149 transmission_type = it->second; |
| 165 pending_retransmissions_.erase(it); | 150 pending_retransmissions_.erase(it); |
| 166 } else { | 151 } else { |
| 167 DLOG(DFATAL) << "Expected sequence number to be in " | 152 DLOG(DFATAL) << "Expected sequence number to be in " |
| 168 "pending_retransmissions_. sequence_number: " << old_sequence_number; | 153 "pending_retransmissions_. sequence_number: " << old_sequence_number; |
| 169 transmission_type = NOT_RETRANSMISSION; | 154 transmission_type = NOT_RETRANSMISSION; |
| 170 } | 155 } |
| 171 | 156 |
| 172 // A notifier may be waiting to hear about ACKs for the original sequence | 157 // A notifier may be waiting to hear about ACKs for the original sequence |
| 173 // number. Inform them that the sequence number has changed. | 158 // number. Inform them that the sequence number has changed. |
| 174 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, | 159 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, |
| 175 new_sequence_number); | 160 new_sequence_number); |
| 176 | 161 |
| 177 unacked_packets_.OnRetransmittedPacket(old_sequence_number, | 162 unacked_packets_.OnRetransmittedPacket(old_sequence_number, |
| 178 new_sequence_number, | 163 new_sequence_number, |
| 179 transmission_type); | 164 transmission_type); |
| 180 | |
| 181 if (debug_delegate_ != NULL) { | |
| 182 debug_delegate_->OnRetransmittedPacket(old_sequence_number, | |
| 183 new_sequence_number, | |
| 184 transmission_type, | |
| 185 clock_->ApproximateNow()); | |
| 186 } | |
| 187 } | 165 } |
| 188 | 166 |
| 189 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, | 167 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, |
| 190 QuicTime ack_receive_time) { | 168 QuicTime ack_receive_time) { |
| 191 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); | 169 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); |
| 192 | 170 |
| 193 UpdatePacketInformationReceivedByPeer(ack_frame); | 171 UpdatePacketInformationReceivedByPeer(ack_frame); |
| 194 // We rely on delta_time_largest_observed to compute an RTT estimate, so | 172 // We rely on delta_time_largest_observed to compute an RTT estimate, so |
| 195 // we only update rtt when the largest observed gets acked. | 173 // we only update rtt when the largest observed gets acked. |
| 196 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); | 174 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 SerializedPacket* serialized_packet, | 485 SerializedPacket* serialized_packet, |
| 508 QuicPacketSequenceNumber original_sequence_number, | 486 QuicPacketSequenceNumber original_sequence_number, |
| 509 QuicTime sent_time, | 487 QuicTime sent_time, |
| 510 QuicByteCount bytes, | 488 QuicByteCount bytes, |
| 511 TransmissionType transmission_type, | 489 TransmissionType transmission_type, |
| 512 HasRetransmittableData has_retransmittable_data) { | 490 HasRetransmittableData has_retransmittable_data) { |
| 513 QuicPacketSequenceNumber sequence_number = serialized_packet->sequence_number; | 491 QuicPacketSequenceNumber sequence_number = serialized_packet->sequence_number; |
| 514 DCHECK_LT(0u, sequence_number); | 492 DCHECK_LT(0u, sequence_number); |
| 515 DCHECK(!unacked_packets_.IsUnacked(sequence_number)); | 493 DCHECK(!unacked_packets_.IsUnacked(sequence_number)); |
| 516 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; | 494 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; |
| 495 if (debug_delegate_ != NULL) { |
| 496 debug_delegate_->OnSentPacket(*serialized_packet, |
| 497 original_sequence_number, |
| 498 sent_time, |
| 499 bytes, |
| 500 transmission_type); |
| 501 } |
| 502 |
| 517 if (original_sequence_number == 0) { | 503 if (original_sequence_number == 0) { |
| 518 OnSerializedPacket(*serialized_packet); | 504 if (serialized_packet->retransmittable_frames) { |
| 505 ack_notifier_manager_.OnSerializedPacket(*serialized_packet); |
| 506 } |
| 507 unacked_packets_.AddPacket(*serialized_packet); |
| 519 serialized_packet->retransmittable_frames = NULL; | 508 serialized_packet->retransmittable_frames = NULL; |
| 520 } else { | 509 } else { |
| 521 OnRetransmittedPacket(original_sequence_number, sequence_number); | 510 OnRetransmittedPacket(original_sequence_number, sequence_number); |
| 522 } | 511 } |
| 523 | 512 |
| 524 if (pending_timer_transmission_count_ > 0) { | 513 if (pending_timer_transmission_count_ > 0) { |
| 525 --pending_timer_transmission_count_; | 514 --pending_timer_transmission_count_; |
| 526 } | 515 } |
| 527 | 516 |
| 528 if (unacked_packets_.bytes_in_flight() == 0) { | 517 if (unacked_packets_.bytes_in_flight() == 0) { |
| 529 // TODO(ianswett): Consider being less aggressive to force a new | 518 // TODO(ianswett): Consider being less aggressive to force a new |
| 530 // recent_min_rtt, likely by not discarding a relatively new sample. | 519 // recent_min_rtt, likely by not discarding a relatively new sample. |
| 531 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" | 520 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" |
| 532 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; | 521 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; |
| 533 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); | 522 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); |
| 534 } | 523 } |
| 535 | 524 |
| 536 // Only track packets as in flight that the send algorithm wants us to track. | 525 // Only track packets as in flight that the send algorithm wants us to track. |
| 537 const bool in_flight = | 526 const bool in_flight = |
| 538 send_algorithm_->OnPacketSent(sent_time, | 527 send_algorithm_->OnPacketSent(sent_time, |
| 539 unacked_packets_.bytes_in_flight(), | 528 unacked_packets_.bytes_in_flight(), |
| 540 sequence_number, | 529 sequence_number, |
| 541 bytes, | 530 bytes, |
| 542 has_retransmittable_data); | 531 has_retransmittable_data); |
| 543 unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight); | 532 unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight); |
| 544 | 533 |
| 545 if (debug_delegate_ != NULL) { | |
| 546 debug_delegate_->OnSentPacket( | |
| 547 sequence_number, sent_time, bytes, transmission_type); | |
| 548 } | |
| 549 | |
| 550 // Reset the retransmission timer anytime a pending packet is sent. | 534 // Reset the retransmission timer anytime a pending packet is sent. |
| 551 return in_flight; | 535 return in_flight; |
| 552 } | 536 } |
| 553 | 537 |
| 554 void QuicSentPacketManager::OnRetransmissionTimeout() { | 538 void QuicSentPacketManager::OnRetransmissionTimeout() { |
| 555 DCHECK(unacked_packets_.HasInFlightPackets()); | 539 DCHECK(unacked_packets_.HasInFlightPackets()); |
| 556 DCHECK_EQ(0u, pending_timer_transmission_count_); | 540 DCHECK_EQ(0u, pending_timer_transmission_count_); |
| 557 // Handshake retransmission, timer based loss detection, TLP, and RTO are | 541 // Handshake retransmission, timer based loss detection, TLP, and RTO are |
| 558 // implemented with a single alarm. The handshake alarm is set when the | 542 // implemented with a single alarm. The handshake alarm is set when the |
| 559 // handshake has not completed, the loss alarm is set when the loss detection | 543 // handshake has not completed, the loss alarm is set when the loss detection |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 | 869 |
| 886 // Set up a pacing sender with a 5 millisecond alarm granularity. | 870 // Set up a pacing sender with a 5 millisecond alarm granularity. |
| 887 using_pacing_ = true; | 871 using_pacing_ = true; |
| 888 send_algorithm_.reset( | 872 send_algorithm_.reset( |
| 889 new PacingSender(send_algorithm_.release(), | 873 new PacingSender(send_algorithm_.release(), |
| 890 QuicTime::Delta::FromMilliseconds(5), | 874 QuicTime::Delta::FromMilliseconds(5), |
| 891 kInitialUnpacedBurst)); | 875 kInitialUnpacedBurst)); |
| 892 } | 876 } |
| 893 | 877 |
| 894 } // namespace net | 878 } // namespace net |
| OLD | NEW |