xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/test_tools/packet_reordering_writer.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #ifndef QUICHE_QUIC_TEST_TOOLS_PACKET_REORDERING_WRITER_H_
6 #define QUICHE_QUIC_TEST_TOOLS_PACKET_REORDERING_WRITER_H_
7 
8 #include "quiche/quic/core/quic_packet_writer.h"
9 #include "quiche/quic/core/quic_packet_writer_wrapper.h"
10 
11 namespace quic {
12 
13 namespace test {
14 
15 // This packet writer allows delaying writing the next packet after
16 // SetDelay(num_packets_to_wait)
17 // is called and buffer this packet and write it after it writes next
18 // |num_packets_to_wait| packets. It doesn't support delaying a packet while
19 // there is already a packet delayed.
20 class PacketReorderingWriter : public QuicPacketWriterWrapper {
21  public:
22   PacketReorderingWriter();
23 
24   ~PacketReorderingWriter() override;
25 
26   WriteResult WritePacket(const char* buffer, size_t buf_len,
27                           const QuicIpAddress& self_address,
28                           const QuicSocketAddress& peer_address,
29                           PerPacketOptions* options,
30                           const QuicPacketWriterParams& params) override;
31 
32   void SetDelay(size_t num_packets_to_wait);
33 
34  private:
35   bool delay_next_ = false;
36   size_t num_packets_to_wait_ = 0;
37   std::string delayed_data_;
38   QuicIpAddress delayed_self_address_;
39   QuicSocketAddress delayed_peer_address_;
40   std::unique_ptr<PerPacketOptions> delayed_options_;
41   QuicPacketWriterParams delayed_params_;
42 };
43 
44 }  // namespace test
45 }  // namespace quic
46 
47 #endif  // QUICHE_QUIC_TEST_TOOLS_PACKET_REORDERING_WRITER_H_
48