diff --git a/test/scenario/network/network_emulation.h b/test/scenario/network/network_emulation.h index 9486a806ea..cc1aec4af5 100644 --- a/test/scenario/network/network_emulation.h +++ b/test/scenario/network/network_emulation.h @@ -174,6 +174,19 @@ class EmulatedEndpoint : public EmulatedNetworkReceiverInterface { absl::optional connected_endpoint_id_; }; +class EmulatedRoute { + public: + EmulatedRoute(EmulatedEndpoint* from, + std::vector via_nodes, + EmulatedEndpoint* to) + : from(from), via_nodes(std::move(via_nodes)), to(to), active(true) {} + + EmulatedEndpoint* from; + std::vector via_nodes; + EmulatedEndpoint* to; + bool active; +}; + } // namespace test } // namespace webrtc diff --git a/test/scenario/network/network_emulation_manager.cc b/test/scenario/network/network_emulation_manager.cc index 16f4187237..604bd1267b 100644 --- a/test/scenario/network/network_emulation_manager.cc +++ b/test/scenario/network/network_emulation_manager.cc @@ -96,7 +96,7 @@ EmulatedEndpoint* NetworkEmulationManager::CreateEndpoint( return out; } -void NetworkEmulationManager::CreateRoute( +EmulatedRoute* NetworkEmulationManager::CreateRoute( EmulatedEndpoint* from, std::vector via_nodes, EmulatedEndpoint* to) { @@ -112,21 +112,28 @@ void NetworkEmulationManager::CreateRoute( } cur_node->SetReceiver(to->GetId(), to); from->SetConnectedEndpointId(to->GetId()); + + std::unique_ptr route = + absl::make_unique(from, std::move(via_nodes), to); + EmulatedRoute* out = route.get(); + routes_.push_back(std::move(route)); + return out; } -void NetworkEmulationManager::ClearRoute( - EmulatedEndpoint* from, - std::vector via_nodes, - EmulatedEndpoint* to) { +void NetworkEmulationManager::ClearRoute(EmulatedRoute* route) { + RTC_CHECK(route->active) << "Route already cleared"; + // Remove receiver from intermediate nodes. - for (auto* node : via_nodes) { - node->RemoveReceiver(to->GetId()); + for (auto* node : route->via_nodes) { + node->RemoveReceiver(route->to->GetId()); } // Detach endpoint from current send node. - if (from->GetSendNode()) { - from->GetSendNode()->RemoveReceiver(to->GetId()); - from->SetSendNode(nullptr); + if (route->from->GetSendNode()) { + route->from->GetSendNode()->RemoveReceiver(route->to->GetId()); + route->from->SetSendNode(nullptr); } + + route->active = false; } TrafficRoute* NetworkEmulationManager::CreateTrafficRoute( diff --git a/test/scenario/network/network_emulation_manager.h b/test/scenario/network/network_emulation_manager.h index 8c408f5fb7..3c1c148a66 100644 --- a/test/scenario/network/network_emulation_manager.h +++ b/test/scenario/network/network_emulation_manager.h @@ -57,12 +57,10 @@ class NetworkEmulationManager { EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config); - void CreateRoute(EmulatedEndpoint* from, - std::vector via_nodes, - EmulatedEndpoint* to); - void ClearRoute(EmulatedEndpoint* from, - std::vector via_nodes, - EmulatedEndpoint* to); + EmulatedRoute* CreateRoute(EmulatedEndpoint* from, + std::vector via_nodes, + EmulatedEndpoint* to); + void ClearRoute(EmulatedRoute* route); TrafficRoute* CreateTrafficRoute(std::vector via_nodes); RandomWalkCrossTraffic* CreateRandomWalkCrossTraffic( @@ -92,6 +90,7 @@ class NetworkEmulationManager { // All objects can be added to the manager only when it is idle. std::vector> endpoints_; std::vector> network_nodes_; + std::vector> routes_; std::vector> traffic_routes_; std::vector> random_cross_traffics_; std::vector> pulsed_cross_traffics_;