1 /* 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 */ 10 #ifndef TEST_NETWORK_FEEDBACK_GENERATOR_H_ 11 #define TEST_NETWORK_FEEDBACK_GENERATOR_H_ 12 13 #include <cstdint> 14 #include <queue> 15 #include <utility> 16 #include <vector> 17 18 #include "api/transport/network_types.h" 19 #include "api/transport/test/feedback_generator_interface.h" 20 #include "call/simulated_network.h" 21 #include "test/network/network_emulation.h" 22 #include "test/network/network_emulation_manager.h" 23 #include "test/time_controller/simulated_time_controller.h" 24 25 namespace webrtc { 26 27 class FeedbackGeneratorImpl 28 : public FeedbackGenerator, 29 public TwoWayFakeTrafficRoute<SentPacket, std::vector<PacketResult>>:: 30 TrafficHandlerInterface { 31 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 43 void OnRequest(SentPacket packet, Timestamp arrival_time) override; 44 void OnResponse(std::vector<PacketResult> packet_results, 45 Timestamp arrival_time) override; 46 47 private: 48 Config conf_; 49 ::webrtc::test::NetworkEmulationManagerImpl net_; 50 SimulatedNetwork* const send_link_; 51 SimulatedNetwork* const ret_link_; 52 TwoWayFakeTrafficRoute<SentPacket, std::vector<PacketResult>> route_; 53 54 std::queue<SentPacket> sent_packets_; 55 std::vector<PacketResult> received_packets_; 56 std::vector<TransportPacketsFeedback> feedback_; 57 int64_t sequence_number_ = 1; 58 }; 59 } // namespace webrtc 60 #endif // TEST_NETWORK_FEEDBACK_GENERATOR_H_ 61