xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/test_tools/simulator/port.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #ifndef QUICHE_QUIC_TEST_TOOLS_SIMULATOR_PORT_H_
6 #define QUICHE_QUIC_TEST_TOOLS_SIMULATOR_PORT_H_
7 
8 #include <string>
9 #include <utility>
10 
11 #include "quiche/quic/core/quic_packets.h"
12 #include "quiche/quic/test_tools/simulator/actor.h"
13 
14 namespace quic {
15 namespace simulator {
16 
17 struct Packet {
18   Packet();
19   ~Packet();
20   Packet(const Packet& packet);
21 
22   std::string source;
23   std::string destination;
24   QuicTime tx_timestamp;
25 
26   std::string contents;
27   QuicByteCount size;
28 };
29 
30 // An interface for anything that accepts packets at arbitrary rate.
31 class UnconstrainedPortInterface {
32  public:
~UnconstrainedPortInterface()33   virtual ~UnconstrainedPortInterface() {}
34   virtual void AcceptPacket(std::unique_ptr<Packet> packet) = 0;
35 };
36 
37 // An interface for any device that accepts packets at a specific rate.
38 // Typically one would use a Queue object in order to write into a constrained
39 // port.
40 class ConstrainedPortInterface {
41  public:
~ConstrainedPortInterface()42   virtual ~ConstrainedPortInterface() {}
43 
44   // Accept a packet for a port.  TimeUntilAvailable() must be zero before this
45   // method is called.
46   virtual void AcceptPacket(std::unique_ptr<Packet> packet) = 0;
47 
48   // Time until write for the next port is available.  Cannot be infinite.
49   virtual QuicTime::Delta TimeUntilAvailable() = 0;
50 };
51 
52 // A convenience class for any network endpoints, i.e. the objects which can
53 // both accept and send packets.
54 class Endpoint : public Actor {
55  public:
56   virtual UnconstrainedPortInterface* GetRxPort() = 0;
57   virtual void SetTxPort(ConstrainedPortInterface* port) = 0;
58 
59  protected:
60   Endpoint(Simulator* simulator, std::string name);
61 };
62 
63 }  // namespace simulator
64 }  // namespace quic
65 
66 #endif  // QUICHE_QUIC_TEST_TOOLS_SIMULATOR_PORT_H_
67