blob: ecd4597d3f4b84701bc8300409b1a24666b62e9a [file] [log] [blame]
Sebastian Jansson3525f862019-05-17 17:44:04 +02001/*
2 * Copyright 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Artem Titov386802e2019-07-05 10:48:17 +020010#ifndef TEST_NETWORK_FEEDBACK_GENERATOR_H_
11#define TEST_NETWORK_FEEDBACK_GENERATOR_H_
Sebastian Jansson3525f862019-05-17 17:44:04 +020012
Per Kjellander1ca57b92022-01-19 14:14:02 +010013#include <cstdint>
14#include <queue>
Sebastian Jansson3525f862019-05-17 17:44:04 +020015#include <utility>
16#include <vector>
17
Per Kjellander1ca57b92022-01-19 14:14:02 +010018#include "api/transport/network_types.h"
Sebastian Jansson3525f862019-05-17 17:44:04 +020019#include "api/transport/test/feedback_generator_interface.h"
20#include "call/simulated_network.h"
Artem Titov386802e2019-07-05 10:48:17 +020021#include "test/network/network_emulation.h"
22#include "test/network/network_emulation_manager.h"
Sebastian Jansson3525f862019-05-17 17:44:04 +020023#include "test/time_controller/simulated_time_controller.h"
24
25namespace webrtc {
26
Sebastian Janssonb13ccc52019-06-07 13:06:00 +020027class FeedbackGeneratorImpl
28 : public FeedbackGenerator,
Per Kjellander1ca57b92022-01-19 14:14:02 +010029 public TwoWayFakeTrafficRoute<SentPacket, std::vector<PacketResult>>::
Sebastian Janssonb13ccc52019-06-07 13:06:00 +020030 TrafficHandlerInterface {
Sebastian Jansson3525f862019-05-17 17:44:04 +020031 public:
32 explicit FeedbackGeneratorImpl(Config config);
33 Timestamp Now() override;
34 void Sleep(TimeDelta duration) override;
35 void SendPacket(size_t size) override;
36 std::vector<TransportPacketsFeedback> PopFeedback() override;
37
38 void SetSendConfig(BuiltInNetworkBehaviorConfig config) override;
39 void SetReturnConfig(BuiltInNetworkBehaviorConfig config) override;
40
41 void SetSendLinkCapacity(DataRate capacity) override;
42
Sebastian Janssonb13ccc52019-06-07 13:06:00 +020043 void OnRequest(SentPacket packet, Timestamp arrival_time) override;
Per Kjellander1ca57b92022-01-19 14:14:02 +010044 void OnResponse(std::vector<PacketResult> packet_results,
Sebastian Janssonb13ccc52019-06-07 13:06:00 +020045 Timestamp arrival_time) override;
46
Sebastian Jansson3525f862019-05-17 17:44:04 +020047 private:
Sebastian Jansson3525f862019-05-17 17:44:04 +020048 Config conf_;
Sebastian Jansson3525f862019-05-17 17:44:04 +020049 ::webrtc::test::NetworkEmulationManagerImpl net_;
50 SimulatedNetwork* const send_link_;
51 SimulatedNetwork* const ret_link_;
Per Kjellander1ca57b92022-01-19 14:14:02 +010052 TwoWayFakeTrafficRoute<SentPacket, std::vector<PacketResult>> route_;
Sebastian Jansson3525f862019-05-17 17:44:04 +020053
Per Kjellander1ca57b92022-01-19 14:14:02 +010054 std::queue<SentPacket> sent_packets_;
55 std::vector<PacketResult> received_packets_;
Sebastian Jansson3525f862019-05-17 17:44:04 +020056 std::vector<TransportPacketsFeedback> feedback_;
Sebastian Janssonad9113f2019-08-13 18:18:29 +020057 int64_t sequence_number_ = 1;
Sebastian Jansson3525f862019-05-17 17:44:04 +020058};
59} // namespace webrtc
Artem Titov386802e2019-07-05 10:48:17 +020060#endif // TEST_NETWORK_FEEDBACK_GENERATOR_H_