Allow injection of time controller to NetworkEmulationManagerImpl.

Bug: webrtc:10365
Change-Id: I6a0e04459f75e8134787e605057dcb03cae55cd8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132780
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27631}
This commit is contained in:
Sebastian Jansson
2019-04-15 14:43:03 +02:00
committed by Commit Bot
parent 2f92b414ae
commit 5d97f552ba
4 changed files with 18 additions and 2 deletions

View File

@ -9,6 +9,7 @@
*/
#include "test/scenario/network/network_emulation_manager.h"
#include "test/time_controller/real_time_controller.h"
#include <algorithm>
#include <memory>
@ -31,10 +32,16 @@ constexpr uint32_t kMaxIPv4Address = 0xC0A8FFFF;
} // namespace
NetworkEmulationManagerImpl::NetworkEmulationManagerImpl()
: clock_(Clock::GetRealTimeClock()),
: NetworkEmulationManagerImpl(GlobalRealTimeController()) {}
NetworkEmulationManagerImpl::NetworkEmulationManagerImpl(
TimeController* time_controller)
: clock_(time_controller->GetClock()),
next_node_id_(1),
next_ip4_address_(kMinIPv4Address),
task_queue_("network_emulation_manager") {
task_queue_(time_controller->GetTaskQueueFactory()->CreateTaskQueue(
"NetworkEmulation",
TaskQueueFactory::Priority::NORMAL)) {
process_task_handle_ = RepeatingTaskHandle::Start(task_queue_.Get(), [this] {
ProcessNetworkPackets();
return TimeDelta::ms(kPacketProcessingIntervalMs);

View File

@ -30,6 +30,7 @@
#include "test/scenario/network/fake_network_socket_server.h"
#include "test/scenario/network/network_emulation.h"
#include "test/scenario/network/traffic_route.h"
#include "test/time_controller/time_controller.h"
namespace webrtc {
namespace test {
@ -37,6 +38,7 @@ namespace test {
class NetworkEmulationManagerImpl : public NetworkEmulationManager {
public:
NetworkEmulationManagerImpl();
explicit NetworkEmulationManagerImpl(TimeController* time_controller);
~NetworkEmulationManagerImpl();
EmulatedNetworkNode* CreateEmulatedNode(

View File

@ -38,4 +38,9 @@ void RealTimeController::InvokeWithControlledYield(
closure();
}
RealTimeController* GlobalRealTimeController() {
static RealTimeController* time_controller = new RealTimeController();
return time_controller;
}
} // namespace webrtc

View File

@ -25,6 +25,8 @@ class RealTimeController : public TimeController {
void InvokeWithControlledYield(std::function<void()> closure) override;
};
RealTimeController* GlobalRealTimeController();
} // namespace webrtc
#endif // TEST_TIME_CONTROLLER_REAL_TIME_CONTROLLER_H_