blob: 15da6384f722e05f451a3bc9cd615302f37d1ea8 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
14namespace quic {
15namespace simulator {
16
17struct Packet {
18 Packet();
19 ~Packet();
20 Packet(const Packet& packet);
21
vasilvvc48c8712019-03-11 13:38:16 -070022 std::string source;
23 std::string destination;
QUICHE teama6ef0a62019-03-07 20:34:33 -050024 QuicTime tx_timestamp;
25
vasilvvc48c8712019-03-11 13:38:16 -070026 std::string contents;
QUICHE teama6ef0a62019-03-07 20:34:33 -050027 QuicByteCount size;
28};
29
30// An interface for anything that accepts packets at arbitrary rate.
31class 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.
40class 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.
54class Endpoint : public Actor {
55 public:
56 virtual UnconstrainedPortInterface* GetRxPort() = 0;
57 virtual void SetTxPort(ConstrainedPortInterface* port) = 0;
58
59 protected:
vasilvvc48c8712019-03-11 13:38:16 -070060 Endpoint(Simulator* simulator, std::string name);
QUICHE teama6ef0a62019-03-07 20:34:33 -050061};
62
63} // namespace simulator
64} // namespace quic
65
66#endif // QUICHE_QUIC_TEST_TOOLS_SIMULATOR_PORT_H_