QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 12 | #include "net/third_party/quiche/src/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 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 22 | std::string source; |
| 23 | std::string destination; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | QuicTime tx_timestamp; |
| 25 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 26 | std::string contents; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | QuicByteCount size; |
| 28 | }; |
| 29 | |
| 30 | // An interface for anything that accepts packets at arbitrary rate. |
| 31 | class UnconstrainedPortInterface { |
| 32 | public: |
| 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: |
| 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: |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 60 | Endpoint(Simulator* simulator, std::string name); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace simulator |
| 64 | } // namespace quic |
| 65 | |
| 66 | #endif // QUICHE_QUIC_TEST_TOOLS_SIMULATOR_PORT_H_ |