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 // Provides a simple interface for QUIC tests to create a variety of packets. 6 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_ 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_ 9 10 #include "base/memory/scoped_ptr.h" 11 #include "net/base/request_priority.h" 12 #include "net/quic/quic_protocol.h" 13 #include "net/quic/test_tools/mock_random.h" 14 #include "net/spdy/spdy_framer.h" 15 #include "net/spdy/spdy_protocol.h" 16 17 namespace net { 18 namespace test { 19 20 class QuicTestPacketMaker { 21 public: 22 QuicTestPacketMaker(QuicVersion version, QuicConnectionId connection_id); 23 ~QuicTestPacketMaker(); 24 25 scoped_ptr<QuicEncryptedPacket> MakeRstPacket( 26 QuicPacketSequenceNumber num, 27 bool include_version, 28 QuicStreamId stream_id, 29 QuicRstStreamErrorCode error_code); 30 scoped_ptr<QuicEncryptedPacket> MakeAckAndRstPacket( 31 QuicPacketSequenceNumber num, 32 bool include_version, 33 QuicStreamId stream_id, 34 QuicRstStreamErrorCode error_code, 35 QuicPacketSequenceNumber largest_received, 36 QuicPacketSequenceNumber least_unacked, 37 bool send_feedback); 38 scoped_ptr<QuicEncryptedPacket> MakeConnectionClosePacket( 39 QuicPacketSequenceNumber num); 40 scoped_ptr<QuicEncryptedPacket> MakeAckPacket( 41 QuicPacketSequenceNumber sequence_number, 42 QuicPacketSequenceNumber largest_received, 43 QuicPacketSequenceNumber least_unacked, 44 bool send_feedback); 45 scoped_ptr<QuicEncryptedPacket> MakeDataPacket( 46 QuicPacketSequenceNumber sequence_number, 47 QuicStreamId stream_id, 48 bool should_include_version, 49 bool fin, 50 QuicStreamOffset offset, 51 base::StringPiece data); 52 scoped_ptr<QuicEncryptedPacket> MakeRequestHeadersPacket( 53 QuicPacketSequenceNumber sequence_number, 54 QuicStreamId stream_id, 55 bool should_include_version, 56 bool fin, 57 const SpdyHeaderBlock& headers); 58 scoped_ptr<QuicEncryptedPacket> MakeResponseHeadersPacket( 59 QuicPacketSequenceNumber sequence_number, 60 QuicStreamId stream_id, 61 bool should_include_version, 62 bool fin, 63 const SpdyHeaderBlock& headers); 64 65 SpdyHeaderBlock GetRequestHeaders(const std::string& method, 66 const std::string& scheme, 67 const std::string& path); 68 SpdyHeaderBlock GetResponseHeaders(const std::string& status); 69 70 private: 71 scoped_ptr<QuicEncryptedPacket> MakePacket( 72 const QuicPacketHeader& header, 73 const QuicFrame& frame); 74 75 void InitializeHeader(QuicPacketSequenceNumber sequence_number, 76 bool should_include_version); 77 78 QuicVersion version_; 79 QuicConnectionId connection_id_; 80 SpdyFramer spdy_request_framer_; 81 SpdyFramer spdy_response_framer_; 82 MockRandom random_generator_; 83 QuicPacketHeader header_; 84 85 DISALLOW_COPY_AND_ASSIGN(QuicTestPacketMaker); 86 }; 87 88 } // namespace test 89 } // namespace net 90 91 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_ 92