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_packet_generator_peer.h"
     15 #include "net/quic/test_tools/quic_sent_packet_manager_peer.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 QuicPacketGeneratorPeer::GetPacketCreator(
     55       &connection->packet_generator_);
     56 }
     57 
     58 // static
     59 QuicPacketGenerator* QuicConnectionPeer::GetPacketGenerator(
     60     QuicConnection* connection) {
     61   return &connection->packet_generator_;
     62 }
     63 
     64 // static
     65 QuicSentPacketManager* QuicConnectionPeer::GetSentPacketManager(
     66     QuicConnection* connection) {
     67   return &connection->sent_packet_manager_;
     68 }
     69 
     70 // static
     71 QuicReceivedPacketManager* QuicConnectionPeer::GetReceivedPacketManager(
     72     QuicConnection* connection) {
     73   return &connection->received_packet_manager_;
     74 }
     75 
     76 // static
     77 QuicTime::Delta QuicConnectionPeer::GetNetworkTimeout(
     78     QuicConnection* connection) {
     79   return connection->idle_network_timeout_;
     80 }
     81 
     82 // static
     83 bool QuicConnectionPeer::IsSavedForRetransmission(
     84     QuicConnection* connection,
     85     QuicPacketSequenceNumber sequence_number) {
     86   return connection->sent_packet_manager_.IsUnacked(sequence_number) &&
     87       connection->sent_packet_manager_.HasRetransmittableFrames(
     88           sequence_number);
     89 }
     90 
     91 // static
     92 bool QuicConnectionPeer::IsRetransmission(
     93     QuicConnection* connection,
     94     QuicPacketSequenceNumber sequence_number) {
     95   return QuicSentPacketManagerPeer::IsRetransmission(
     96       &connection->sent_packet_manager_, sequence_number);
     97 }
     98 
     99 // static
    100 // TODO(ianswett): Create a GetSentEntropyHash which accepts an AckFrame.
    101 QuicPacketEntropyHash QuicConnectionPeer::GetSentEntropyHash(
    102     QuicConnection* connection,
    103     QuicPacketSequenceNumber sequence_number) {
    104   return connection->sent_entropy_manager_.EntropyHash(sequence_number);
    105 }
    106 
    107 // static
    108 bool QuicConnectionPeer::IsValidEntropy(
    109     QuicConnection* connection,
    110     QuicPacketSequenceNumber largest_observed,
    111     const SequenceNumberSet& missing_packets,
    112     QuicPacketEntropyHash entropy_hash) {
    113   return connection->sent_entropy_manager_.IsValidEntropy(
    114       largest_observed, missing_packets, entropy_hash);
    115 }
    116 
    117 // static
    118 QuicPacketEntropyHash QuicConnectionPeer::ReceivedEntropyHash(
    119     QuicConnection* connection,
    120     QuicPacketSequenceNumber sequence_number) {
    121   return connection->received_packet_manager_.EntropyHash(
    122       sequence_number);
    123 }
    124 
    125 // static
    126 bool QuicConnectionPeer::IsServer(QuicConnection* connection) {
    127   return connection->is_server_;
    128 }
    129 
    130 // static
    131 void QuicConnectionPeer::SetIsServer(QuicConnection* connection,
    132                                      bool is_server) {
    133   connection->is_server_ = is_server;
    134   QuicFramerPeer::SetIsServer(&connection->framer_, is_server);
    135 }
    136 
    137 // static
    138 void QuicConnectionPeer::SetSelfAddress(QuicConnection* connection,
    139                                         const IPEndPoint& self_address) {
    140   connection->self_address_ = self_address;
    141 }
    142 
    143 // static
    144 void QuicConnectionPeer::SetPeerAddress(QuicConnection* connection,
    145                                         const IPEndPoint& peer_address) {
    146   connection->peer_address_ = peer_address;
    147 }
    148 
    149 // static
    150 void QuicConnectionPeer::SwapCrypters(QuicConnection* connection,
    151                                       QuicFramer* framer) {
    152   QuicFramerPeer::SwapCrypters(framer, &connection->framer_);
    153 }
    154 
    155 // static
    156 QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper(
    157     QuicConnection* connection) {
    158   return connection->helper_;
    159 }
    160 
    161 // static
    162 QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) {
    163   return &connection->framer_;
    164 }
    165 
    166 QuicFecGroup* QuicConnectionPeer::GetFecGroup(QuicConnection* connection,
    167                                               int fec_group) {
    168   connection->last_header_.fec_group = fec_group;
    169   return connection->GetFecGroup();
    170 }
    171 
    172 // static
    173 QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) {
    174   return connection->ack_alarm_.get();
    175 }
    176 
    177 // static
    178 QuicAlarm* QuicConnectionPeer::GetPingAlarm(QuicConnection* connection) {
    179   return connection->ping_alarm_.get();
    180 }
    181 
    182 // static
    183 QuicAlarm* QuicConnectionPeer::GetResumeWritesAlarm(
    184     QuicConnection* connection) {
    185   return connection->resume_writes_alarm_.get();
    186 }
    187 
    188 // static
    189 QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm(
    190     QuicConnection* connection) {
    191   return connection->retransmission_alarm_.get();
    192 }
    193 
    194 // static
    195 QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) {
    196   return connection->send_alarm_.get();
    197 }
    198 
    199 // static
    200 QuicAlarm* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection* connection) {
    201   return connection->timeout_alarm_.get();
    202 }
    203 
    204 // static
    205 QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) {
    206   return connection->writer_;
    207 }
    208 
    209 // static
    210 void QuicConnectionPeer::SetWriter(QuicConnection* connection,
    211                                    QuicPacketWriter* writer) {
    212   connection->writer_ = writer;
    213 }
    214 
    215 // static
    216 void QuicConnectionPeer::CloseConnection(QuicConnection* connection) {
    217   connection->connected_ = false;
    218 }
    219 
    220 // static
    221 QuicEncryptedPacket* QuicConnectionPeer::GetConnectionClosePacket(
    222     QuicConnection* connection) {
    223   return connection->connection_close_packet_.get();
    224 }
    225 
    226 // static
    227 void QuicConnectionPeer::SetSupportedVersions(QuicConnection* connection,
    228                                               QuicVersionVector versions) {
    229   connection->framer_.SetSupportedVersions(versions);
    230 }
    231 
    232 }  // namespace test
    233 }  // namespace net
    234