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 3 // found in the LICENSE file. 4 5 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 6 7 #include "base/stl_util.h" 8 #include "net/quic/congestion_control/loss_detection_interface.h" 9 #include "net/quic/congestion_control/send_algorithm_interface.h" 10 #include "net/quic/quic_protocol.h" 11 #include "net/quic/quic_sent_packet_manager.h" 12 13 namespace net { 14 namespace test { 15 16 // static 17 void QuicSentPacketManagerPeer::SetMaxTailLossProbes( 18 QuicSentPacketManager* sent_packet_manager, size_t max_tail_loss_probes) { 19 sent_packet_manager->max_tail_loss_probes_ = max_tail_loss_probes; 20 } 21 22 // static 23 void QuicSentPacketManagerPeer::SetSendAlgorithm( 24 QuicSentPacketManager* sent_packet_manager, 25 SendAlgorithmInterface* send_algorithm) { 26 sent_packet_manager->send_algorithm_.reset(send_algorithm); 27 } 28 29 // static 30 const LossDetectionInterface* QuicSentPacketManagerPeer::GetLossAlgorithm( 31 QuicSentPacketManager* sent_packet_manager) { 32 return sent_packet_manager->loss_algorithm_.get(); 33 } 34 35 // static 36 const SendAlgorithmInterface* 37 QuicSentPacketManagerPeer::GetCongestionControlAlgorithm( 38 const QuicSentPacketManager& sent_packet_manager) { 39 return sent_packet_manager.send_algorithm_.get(); 40 } 41 42 // static 43 void QuicSentPacketManagerPeer::SetLossAlgorithm( 44 QuicSentPacketManager* sent_packet_manager, 45 LossDetectionInterface* loss_detector) { 46 sent_packet_manager->loss_algorithm_.reset(loss_detector); 47 } 48 49 // static 50 RttStats* QuicSentPacketManagerPeer::GetRttStats( 51 QuicSentPacketManager* sent_packet_manager) { 52 return &sent_packet_manager->rtt_stats_; 53 } 54 55 // static 56 size_t QuicSentPacketManagerPeer::GetNackCount( 57 const QuicSentPacketManager* sent_packet_manager, 58 QuicPacketSequenceNumber sequence_number) { 59 return sent_packet_manager->unacked_packets_. 60 GetTransmissionInfo(sequence_number).nack_count; 61 } 62 63 // static 64 size_t QuicSentPacketManagerPeer::GetPendingRetransmissionCount( 65 const QuicSentPacketManager* sent_packet_manager) { 66 return sent_packet_manager->pending_retransmissions_.size(); 67 } 68 69 // static 70 bool QuicSentPacketManagerPeer::HasPendingPackets( 71 const QuicSentPacketManager* sent_packet_manager) { 72 return sent_packet_manager->unacked_packets_.HasInFlightPackets(); 73 } 74 75 // static 76 QuicTime QuicSentPacketManagerPeer::GetSentTime( 77 const QuicSentPacketManager* sent_packet_manager, 78 QuicPacketSequenceNumber sequence_number) { 79 DCHECK(sent_packet_manager->unacked_packets_.IsUnacked(sequence_number)); 80 81 return sent_packet_manager->unacked_packets_.GetTransmissionInfo( 82 sequence_number).sent_time; 83 } 84 85 // static 86 bool QuicSentPacketManagerPeer::IsRetransmission( 87 QuicSentPacketManager* sent_packet_manager, 88 QuicPacketSequenceNumber sequence_number) { 89 DCHECK(sent_packet_manager->HasRetransmittableFrames(sequence_number)); 90 return sent_packet_manager->HasRetransmittableFrames(sequence_number) && 91 sent_packet_manager->unacked_packets_.GetTransmissionInfo( 92 sequence_number).all_transmissions != NULL; 93 } 94 95 // static 96 void QuicSentPacketManagerPeer::MarkForRetransmission( 97 QuicSentPacketManager* sent_packet_manager, 98 QuicPacketSequenceNumber sequence_number, 99 TransmissionType transmission_type) { 100 sent_packet_manager->MarkForRetransmission(sequence_number, 101 transmission_type); 102 } 103 104 // static 105 QuicTime::Delta QuicSentPacketManagerPeer::GetRetransmissionDelay( 106 const QuicSentPacketManager* sent_packet_manager) { 107 return sent_packet_manager->GetRetransmissionDelay(); 108 } 109 110 // static 111 bool QuicSentPacketManagerPeer::HasUnackedCryptoPackets( 112 const QuicSentPacketManager* sent_packet_manager) { 113 return sent_packet_manager->unacked_packets_.HasPendingCryptoPackets(); 114 } 115 116 // static 117 size_t QuicSentPacketManagerPeer::GetNumRetransmittablePackets( 118 const QuicSentPacketManager* sent_packet_manager) { 119 size_t num_unacked_packets = 0; 120 for (QuicUnackedPacketMap::const_iterator it = 121 sent_packet_manager->unacked_packets_.begin(); 122 it != sent_packet_manager->unacked_packets_.end(); ++it) { 123 if (it->retransmittable_frames != NULL) { 124 ++num_unacked_packets; 125 } 126 } 127 return num_unacked_packets; 128 } 129 130 // static 131 QuicByteCount QuicSentPacketManagerPeer::GetBytesInFlight( 132 const QuicSentPacketManager* sent_packet_manager) { 133 return sent_packet_manager->unacked_packets_.bytes_in_flight(); 134 } 135 136 // static 137 QuicSentPacketManager::NetworkChangeVisitor* 138 QuicSentPacketManagerPeer::GetNetworkChangeVisitor( 139 const QuicSentPacketManager* sent_packet_manager) { 140 return sent_packet_manager->network_change_visitor_; 141 } 142 143 // static 144 QuicSustainedBandwidthRecorder& QuicSentPacketManagerPeer::GetBandwidthRecorder( 145 QuicSentPacketManager* sent_packet_manager) { 146 return sent_packet_manager->sustained_bandwidth_recorder_; 147 } 148 149 } // namespace test 150 } // namespace net 151