QUICHE team | 500e0aa | 2019-04-16 14:30:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2019 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_QUARTC_TEST_BIDI_TEST_RUNNER_H_ |
| 6 | #define QUICHE_QUIC_QUARTC_TEST_BIDI_TEST_RUNNER_H_ |
| 7 | |
| 8 | #include "net/third_party/quiche/src/quic/core/quic_time.h" |
| 9 | #include "net/third_party/quiche/src/quic/quartc/quartc_endpoint.h" |
| 10 | #include "net/third_party/quiche/src/quic/quartc/quartc_packet_writer.h" |
| 11 | #include "net/third_party/quiche/src/quic/quartc/test/quartc_data_source.h" |
| 12 | #include "net/third_party/quiche/src/quic/quartc/test/quartc_peer.h" |
| 13 | #include "net/third_party/quiche/src/quic/test_tools/simulator/simulator.h" |
| 14 | |
| 15 | namespace quic { |
| 16 | namespace test { |
| 17 | |
| 18 | // Interface for a component that intercepts endpoint callbacks before |
| 19 | // forwarding them to another delegate. |
| 20 | class QuartcEndpointInterceptor : public QuartcEndpoint::Delegate { |
| 21 | public: |
| 22 | ~QuartcEndpointInterceptor() override = default; |
| 23 | |
| 24 | // Passes the test's endpoint delegate to this interceptor. The interceptor |
| 25 | // must forward all callbacks to this delegate as soon as it finishes handling |
| 26 | // them. |
| 27 | virtual void SetDelegate(QuartcEndpoint::Delegate* delegate) = 0; |
| 28 | }; |
| 29 | |
| 30 | // Runner for bidirectional media flow tests. |
| 31 | // |
| 32 | // BidiTestRunner allows an external fixture to set up transports, then executes |
| 33 | // a test. During the test, it sets up two QuartcPeers, connects them through |
| 34 | // the transports, and sends data in both directions for a specified duration. |
| 35 | // It then stops sending, waits for any pending messages to finish transmission, |
| 36 | // and then computes and logs a few basic metrics. |
| 37 | // |
| 38 | // For now, the runner computes the maximum and average one-way delay, the total |
| 39 | // throughput (in bytes) and the average bandwidth (in bits per second). It |
| 40 | // logs these to the test's text logs. |
| 41 | // |
| 42 | // By default, the BidiTestRunner emulates one video stream and one audio stream |
| 43 | // in each direction. The audio stream runs with a 20 ms ptime, between 8 and |
| 44 | // 64 kbps. The video stream runs at 30 fps, between 25 kbps and 5 mbps. |
| 45 | // Individual tests can overwrite the configs. |
| 46 | // |
| 47 | // BidiTestRunner provides a way for the test to register an "interceptor" on |
| 48 | // each endpoint. This allows a test to reconfigure that endpoint's session |
| 49 | // prior to beginning the test. For example, interceptors may be used to attach |
| 50 | // debug visitors or change the congestion controller. |
| 51 | class BidiTestRunner { |
| 52 | public: |
| 53 | // TODO(b/130540842): Make this compatible with non-simulator execution. |
| 54 | BidiTestRunner(simulator::Simulator* simulator, |
| 55 | QuartcPacketTransport* client_transport, |
| 56 | QuartcPacketTransport* server_transport); |
| 57 | |
| 58 | virtual ~BidiTestRunner(); |
| 59 | |
| 60 | void set_client_configs(std::vector<QuartcDataSource::Config> configs) { |
| 61 | client_configs_ = std::move(configs); |
| 62 | } |
| 63 | |
| 64 | void set_server_configs(std::vector<QuartcDataSource::Config> configs) { |
| 65 | server_configs_ = std::move(configs); |
| 66 | } |
| 67 | |
| 68 | void set_client_interceptor(QuartcEndpointInterceptor* interceptor) { |
| 69 | client_interceptor_ = interceptor; |
| 70 | } |
| 71 | |
| 72 | void set_server_interceptor(QuartcEndpointInterceptor* interceptor) { |
| 73 | server_interceptor_ = interceptor; |
| 74 | } |
| 75 | |
| 76 | virtual bool RunTest(QuicTime::Delta test_duration); |
| 77 | |
| 78 | private: |
QUICHE team | 1b4afd1 | 2019-04-17 14:03:08 -0700 | [diff] [blame] | 79 | // Returns true when no pending packets are believed to be in-flight. |
| 80 | bool PacketsDrained(); |
| 81 | |
QUICHE team | 500e0aa | 2019-04-16 14:30:01 -0700 | [diff] [blame] | 82 | simulator::Simulator* simulator_; |
| 83 | QuartcPacketTransport* client_transport_; |
| 84 | QuartcPacketTransport* server_transport_; |
| 85 | |
| 86 | std::vector<QuartcDataSource::Config> client_configs_; |
| 87 | std::vector<QuartcDataSource::Config> server_configs_; |
| 88 | |
| 89 | QuartcEndpointInterceptor* client_interceptor_ = nullptr; |
| 90 | QuartcEndpointInterceptor* server_interceptor_ = nullptr; |
| 91 | |
| 92 | std::unique_ptr<QuartcServerEndpoint> server_endpoint_; |
| 93 | std::unique_ptr<QuartcClientEndpoint> client_endpoint_; |
| 94 | |
| 95 | std::unique_ptr<QuartcPeer> client_peer_; |
| 96 | std::unique_ptr<QuartcPeer> server_peer_; |
| 97 | }; |
| 98 | |
| 99 | } // namespace test |
| 100 | } // namespace quic |
| 101 | |
| 102 | #endif // QUICHE_QUIC_QUARTC_TEST_BIDI_TEST_RUNNER_H_ |