Home | History | Annotate | Download | only in test_tools
      1 // Copyright (c) 2012 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_connection_peer.h"
      6 
      7 #include "base/stl_util.h"
      8 #include "net/quic/congestion_control/receive_algorithm_interface.h"
      9 #include "net/quic/congestion_control/send_algorithm_interface.h"
     10 #include "net/quic/quic_connection.h"
     11 #include "net/quic/quic_packet_writer.h"
     12 #include "net/quic/quic_received_packet_manager.h"
     13 #include "net/quic/test_tools/quic_framer_peer.h"
     14 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
     15 #include "net/quic/test_tools/quic_test_writer.h"
     16 
     17 namespace net {
     18 namespace test {
     19 
     20 // static
     21 void QuicConnectionPeer::SendAck(QuicConnection* connection) {
     22   connection->SendAck();
     23 }
     24 
     25 // static
     26 void QuicConnectionPeer::SetReceiveAlgorithm(
     27     QuicConnection* connection,
     28     ReceiveAlgorithmInterface* receive_algorithm) {
     29   connection->received_packet_manager_.receive_algorithm_.reset(
     30       receive_algorithm);
     31 }
     32 
     33 // static
     34 void QuicConnectionPeer::SetSendAlgorithm(
     35     QuicConnection* connection,
     36     SendAlgorithmInterface* send_algorithm) {
     37   connection->sent_packet_manager_.send_algorithm_.reset(send_algorithm);
     38 }
     39 
     40 // static
     41 QuicAckFrame* QuicConnectionPeer::CreateAckFrame(QuicConnection* connection) {
     42   return connection->CreateAckFrame();
     43 }
     44 
     45 // static
     46 QuicConnectionVisitorInterface* QuicConnectionPeer::GetVisitor(
     47     QuicConnection* connection) {
     48   return connection->visitor_;
     49 }
     50 
     51 // static
     52 QuicPacketCreator* QuicConnectionPeer::GetPacketCreator(
     53     QuicConnection* connection) {
     54   return &connection->packet_creator_;
     55 }
     56 
     57 // static
     58 QuicReceivedPacketManager* QuicConnectionPeer::GetReceivedPacketManager(
     59     QuicConnection* connection) {
     60   return &connection->received_packet_manager_;
     61 }
     62 
     63 // static
     64 QuicTime::Delta QuicConnectionPeer::GetNetworkTimeout(
     65     QuicConnection* connection) {
     66   return connection->idle_network_timeout_;
     67 }
     68 
     69 // static
     70 bool QuicConnectionPeer::IsSavedForRetransmission(
     71     QuicConnection* connection,
     72     QuicPacketSequenceNumber sequence_number) {
     73   return connection->sent_packet_manager_.IsUnacked(sequence_number) &&
     74       connection->sent_packet_manager_.HasRetransmittableFrames(
     75           sequence_number);
     76 }
     77 
     78 // static
     79 bool QuicConnectionPeer::IsRetransmission(
     80     QuicConnection* connection,
     81     QuicPacketSequenceNumber sequence_number) {
     82   return QuicSentPacketManagerPeer::IsRetransmission(
     83       &connection->sent_packet_manager_, sequence_number);
     84 }
     85 
     86 // static
     87 // TODO(ianswett): Create a GetSentEntropyHash which accepts an AckFrame.
     88 QuicPacketEntropyHash QuicConnectionPeer::GetSentEntropyHash(
     89     QuicConnection* connection,
     90     QuicPacketSequenceNumber sequence_number) {
     91   return connection->sent_entropy_manager_.EntropyHash(sequence_number);
     92 }
     93 
     94 // static
     95 bool QuicConnectionPeer::IsValidEntropy(
     96     QuicConnection* connection,
     97     QuicPacketSequenceNumber largest_observed,
     98     const SequenceNumberSet& missing_packets,
     99     QuicPacketEntropyHash entropy_hash) {
    100   return connection->sent_entropy_manager_.IsValidEntropy(
    101       largest_observed, missing_packets, entropy_hash);
    102 }
    103 
    104 // static
    105 QuicPacketEntropyHash QuicConnectionPeer::ReceivedEntropyHash(
    106     QuicConnection* connection,
    107     QuicPacketSequenceNumber sequence_number) {
    108   return connection->received_packet_manager_.EntropyHash(
    109       sequence_number);
    110 }
    111 
    112 // static
    113 bool QuicConnectionPeer::IsWriteBlocked(QuicConnection* connection) {
    114   return connection->write_blocked_;
    115 }
    116 
    117 // static
    118 void QuicConnectionPeer::SetIsWriteBlocked(QuicConnection* connection,
    119                                            bool write_blocked) {
    120   connection->write_blocked_ = write_blocked;
    121 }
    122 
    123 // static
    124 bool QuicConnectionPeer::IsServer(QuicConnection* connection) {
    125   return connection->is_server_;
    126 }
    127 
    128 // static
    129 void QuicConnectionPeer::SetIsServer(QuicConnection* connection,
    130                                      bool is_server) {
    131   connection->is_server_ = is_server;
    132   QuicFramerPeer::SetIsServer(&connection->framer_, is_server);
    133 }
    134 
    135 // static
    136 void QuicConnectionPeer::SetSelfAddress(QuicConnection* connection,
    137                                         const IPEndPoint& self_address) {
    138   connection->self_address_ = self_address;
    139 }
    140 
    141 // static
    142 void QuicConnectionPeer::SetPeerAddress(QuicConnection* connection,
    143                                         const IPEndPoint& peer_address) {
    144   connection->peer_address_ = peer_address;
    145 }
    146 
    147 // static
    148 void QuicConnectionPeer::SwapCrypters(QuicConnection* connection,
    149                                       QuicFramer* framer) {
    150   framer->SwapCryptersForTest(&connection->framer_);
    151 }
    152 
    153 // static
    154 QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper(
    155     QuicConnection* connection) {
    156   return connection->helper_;
    157 }
    158 
    159 // static
    160 QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) {
    161   return &connection->framer_;
    162 }
    163 
    164 QuicFecGroup* QuicConnectionPeer::GetFecGroup(QuicConnection* connection,
    165                                               int fec_group) {
    166   connection->last_header_.fec_group = fec_group;
    167   return connection->GetFecGroup();
    168 }
    169 
    170 // static
    171 QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) {
    172   return connection->ack_alarm_.get();
    173 }
    174 
    175 // static
    176 QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm(
    177     QuicConnection* connection) {
    178   return connection->retransmission_alarm_.get();
    179 }
    180 
    181 // static
    182 QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) {
    183   return connection->send_alarm_.get();
    184 }
    185 
    186 // static
    187 QuicAlarm* QuicConnectionPeer::GetResumeWritesAlarm(
    188     QuicConnection* connection) {
    189   return connection->resume_writes_alarm_.get();
    190 }
    191 
    192 // static
    193 QuicAlarm* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection* connection) {
    194   return connection->timeout_alarm_.get();
    195 }
    196 
    197 // static
    198 QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) {
    199   return connection->writer_;
    200 }
    201 
    202 // static
    203 void QuicConnectionPeer::SetWriter(QuicConnection* connection,
    204                                    QuicTestWriter* writer) {
    205   connection->writer_ = writer;
    206 }
    207 
    208 }  // namespace test
    209 }  // namespace net
    210