1 /*
2 * Copyright (c) 2018 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
11 #include <queue>
12
13 #include "absl/strings/string_view.h"
14 #include "api/test/network_emulation/create_cross_traffic.h"
15 #include "api/test/network_emulation/cross_traffic.h"
16 #include "api/transport/goog_cc_factory.h"
17 #include "api/transport/network_types.h"
18 #include "api/units/data_rate.h"
19 #include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
20 #include "test/field_trial.h"
21 #include "test/gtest.h"
22 #include "test/scenario/scenario.h"
23
24 using ::testing::NiceMock;
25
26 namespace webrtc {
27 namespace test {
28 namespace {
29 // Count dips from a constant high bandwidth level within a short window.
CountBandwidthDips(std::queue<DataRate> bandwidth_history,DataRate threshold)30 int CountBandwidthDips(std::queue<DataRate> bandwidth_history,
31 DataRate threshold) {
32 if (bandwidth_history.empty())
33 return true;
34 DataRate first = bandwidth_history.front();
35 bandwidth_history.pop();
36
37 int dips = 0;
38 bool state_high = true;
39 while (!bandwidth_history.empty()) {
40 if (bandwidth_history.front() + threshold < first && state_high) {
41 ++dips;
42 state_high = false;
43 } else if (bandwidth_history.front() == first) {
44 state_high = true;
45 } else if (bandwidth_history.front() > first) {
46 // If this is toggling we will catch it later when front becomes first.
47 state_high = false;
48 }
49 bandwidth_history.pop();
50 }
51 return dips;
52 }
CreateFeedbackOnlyFactory()53 GoogCcNetworkControllerFactory CreateFeedbackOnlyFactory() {
54 GoogCcFactoryConfig config;
55 config.feedback_only = true;
56 return GoogCcNetworkControllerFactory(std::move(config));
57 }
58
59 const uint32_t kInitialBitrateKbps = 60;
60 const DataRate kInitialBitrate = DataRate::KilobitsPerSec(kInitialBitrateKbps);
61 const float kDefaultPacingRate = 2.5f;
62
CreateVideoSendingClient(Scenario * s,CallClientConfig config,std::vector<EmulatedNetworkNode * > send_link,std::vector<EmulatedNetworkNode * > return_link)63 CallClient* CreateVideoSendingClient(
64 Scenario* s,
65 CallClientConfig config,
66 std::vector<EmulatedNetworkNode*> send_link,
67 std::vector<EmulatedNetworkNode*> return_link) {
68 auto* client = s->CreateClient("send", std::move(config));
69 auto* route = s->CreateRoutes(client, send_link,
70 s->CreateClient("return", CallClientConfig()),
71 return_link);
72 s->CreateVideoStream(route->forward(), VideoStreamConfig());
73 return client;
74 }
75
CreateRouteChange(Timestamp time,absl::optional<DataRate> start_rate=absl::nullopt,absl::optional<DataRate> min_rate=absl::nullopt,absl::optional<DataRate> max_rate=absl::nullopt)76 NetworkRouteChange CreateRouteChange(
77 Timestamp time,
78 absl::optional<DataRate> start_rate = absl::nullopt,
79 absl::optional<DataRate> min_rate = absl::nullopt,
80 absl::optional<DataRate> max_rate = absl::nullopt) {
81 NetworkRouteChange route_change;
82 route_change.at_time = time;
83 route_change.constraints.at_time = time;
84 route_change.constraints.min_data_rate = min_rate;
85 route_change.constraints.max_data_rate = max_rate;
86 route_change.constraints.starting_rate = start_rate;
87 return route_change;
88 }
89
CreatePacketResult(Timestamp arrival_time,Timestamp send_time,size_t payload_size,PacedPacketInfo pacing_info)90 PacketResult CreatePacketResult(Timestamp arrival_time,
91 Timestamp send_time,
92 size_t payload_size,
93 PacedPacketInfo pacing_info) {
94 PacketResult packet_result;
95 packet_result.sent_packet = SentPacket();
96 packet_result.sent_packet.send_time = send_time;
97 packet_result.sent_packet.size = DataSize::Bytes(payload_size);
98 packet_result.sent_packet.pacing_info = pacing_info;
99 packet_result.receive_time = arrival_time;
100 return packet_result;
101 }
102
103 // Simulate sending packets and receiving transport feedback during
104 // `runtime_ms`.
PacketTransmissionAndFeedbackBlock(NetworkControllerInterface * controller,int64_t runtime_ms,int64_t delay,Timestamp & current_time)105 absl::optional<DataRate> PacketTransmissionAndFeedbackBlock(
106 NetworkControllerInterface* controller,
107 int64_t runtime_ms,
108 int64_t delay,
109 Timestamp& current_time) {
110 NetworkControlUpdate update;
111 absl::optional<DataRate> target_bitrate;
112 int64_t delay_buildup = 0;
113 int64_t start_time_ms = current_time.ms();
114 while (current_time.ms() - start_time_ms < runtime_ms) {
115 constexpr size_t kPayloadSize = 1000;
116 PacketResult packet =
117 CreatePacketResult(current_time + TimeDelta::Millis(delay_buildup),
118 current_time, kPayloadSize, PacedPacketInfo());
119 delay_buildup += delay;
120 update = controller->OnSentPacket(packet.sent_packet);
121 if (update.target_rate) {
122 target_bitrate = update.target_rate->target_rate;
123 }
124 TransportPacketsFeedback feedback;
125 feedback.feedback_time = packet.receive_time;
126 feedback.packet_feedbacks.push_back(packet);
127 update = controller->OnTransportPacketsFeedback(feedback);
128 if (update.target_rate) {
129 target_bitrate = update.target_rate->target_rate;
130 }
131 current_time += TimeDelta::Millis(50);
132 update = controller->OnProcessInterval({.at_time = current_time});
133 if (update.target_rate) {
134 target_bitrate = update.target_rate->target_rate;
135 }
136 }
137 return target_bitrate;
138 }
139
140 // Scenarios:
141
UpdatesTargetRateBasedOnLinkCapacity(absl::string_view test_name="")142 void UpdatesTargetRateBasedOnLinkCapacity(absl::string_view test_name = "") {
143 auto factory = CreateFeedbackOnlyFactory();
144 Scenario s("googcc_unit/target_capacity" + std::string(test_name), false);
145 CallClientConfig config;
146 config.transport.cc_factory = &factory;
147 config.transport.rates.min_rate = DataRate::KilobitsPerSec(10);
148 config.transport.rates.max_rate = DataRate::KilobitsPerSec(1500);
149 config.transport.rates.start_rate = DataRate::KilobitsPerSec(300);
150 auto send_net = s.CreateMutableSimulationNode([](NetworkSimulationConfig* c) {
151 c->bandwidth = DataRate::KilobitsPerSec(500);
152 c->delay = TimeDelta::Millis(100);
153 c->loss_rate = 0.0;
154 });
155 auto ret_net = s.CreateMutableSimulationNode(
156 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(100); });
157 StatesPrinter* truth = s.CreatePrinter(
158 "send.truth.txt", TimeDelta::PlusInfinity(), {send_net->ConfigPrinter()});
159
160 auto* client = CreateVideoSendingClient(&s, config, {send_net->node()},
161 {ret_net->node()});
162
163 truth->PrintRow();
164 s.RunFor(TimeDelta::Seconds(25));
165 truth->PrintRow();
166 EXPECT_NEAR(client->target_rate().kbps(), 450, 100);
167
168 send_net->UpdateConfig([](NetworkSimulationConfig* c) {
169 c->bandwidth = DataRate::KilobitsPerSec(800);
170 c->delay = TimeDelta::Millis(100);
171 });
172
173 truth->PrintRow();
174 s.RunFor(TimeDelta::Seconds(20));
175 truth->PrintRow();
176 EXPECT_NEAR(client->target_rate().kbps(), 750, 150);
177
178 send_net->UpdateConfig([](NetworkSimulationConfig* c) {
179 c->bandwidth = DataRate::KilobitsPerSec(100);
180 c->delay = TimeDelta::Millis(200);
181 });
182 ret_net->UpdateConfig(
183 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(200); });
184
185 truth->PrintRow();
186 s.RunFor(TimeDelta::Seconds(50));
187 truth->PrintRow();
188 EXPECT_NEAR(client->target_rate().kbps(), 90, 25);
189 }
190
RunRembDipScenario(absl::string_view test_name)191 DataRate RunRembDipScenario(absl::string_view test_name) {
192 Scenario s(test_name);
193 NetworkSimulationConfig net_conf;
194 net_conf.bandwidth = DataRate::KilobitsPerSec(2000);
195 net_conf.delay = TimeDelta::Millis(50);
196 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
197 c->transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
198 });
199 auto send_net = {s.CreateSimulationNode(net_conf)};
200 auto ret_net = {s.CreateSimulationNode(net_conf)};
201 auto* route = s.CreateRoutes(
202 client, send_net, s.CreateClient("return", CallClientConfig()), ret_net);
203 s.CreateVideoStream(route->forward(), VideoStreamConfig());
204
205 s.RunFor(TimeDelta::Seconds(10));
206 EXPECT_GT(client->send_bandwidth().kbps(), 1500);
207
208 DataRate RembLimit = DataRate::KilobitsPerSec(250);
209 client->SetRemoteBitrate(RembLimit);
210 s.RunFor(TimeDelta::Seconds(1));
211 EXPECT_EQ(client->send_bandwidth(), RembLimit);
212
213 DataRate RembLimitLifted = DataRate::KilobitsPerSec(10000);
214 client->SetRemoteBitrate(RembLimitLifted);
215 s.RunFor(TimeDelta::Seconds(10));
216
217 return client->send_bandwidth();
218 }
219
220 } // namespace
221
222 class NetworkControllerTestFixture {
223 public:
NetworkControllerTestFixture()224 NetworkControllerTestFixture() : factory_() {}
225
CreateController()226 std::unique_ptr<NetworkControllerInterface> CreateController() {
227 NetworkControllerConfig config = InitialConfig();
228 std::unique_ptr<NetworkControllerInterface> controller =
229 factory_.Create(config);
230 return controller;
231 }
232
233 private:
InitialConfig(int starting_bandwidth_kbps=kInitialBitrateKbps,int min_data_rate_kbps=0,int max_data_rate_kbps=5* kInitialBitrateKbps)234 NetworkControllerConfig InitialConfig(
235 int starting_bandwidth_kbps = kInitialBitrateKbps,
236 int min_data_rate_kbps = 0,
237 int max_data_rate_kbps = 5 * kInitialBitrateKbps) {
238 NetworkControllerConfig config;
239 config.constraints.at_time = Timestamp::Zero();
240 config.constraints.min_data_rate =
241 DataRate::KilobitsPerSec(min_data_rate_kbps);
242 config.constraints.max_data_rate =
243 DataRate::KilobitsPerSec(max_data_rate_kbps);
244 config.constraints.starting_rate =
245 DataRate::KilobitsPerSec(starting_bandwidth_kbps);
246 config.event_log = &event_log_;
247 return config;
248 }
249
250 NiceMock<MockRtcEventLog> event_log_;
251 GoogCcNetworkControllerFactory factory_;
252 };
253
TEST(GoogCcNetworkControllerTest,InitializeTargetRateOnFirstProcessInterval)254 TEST(GoogCcNetworkControllerTest, InitializeTargetRateOnFirstProcessInterval) {
255 NetworkControllerTestFixture fixture;
256 std::unique_ptr<NetworkControllerInterface> controller =
257 fixture.CreateController();
258
259 NetworkControlUpdate update =
260 controller->OnProcessInterval({.at_time = Timestamp::Millis(123456)});
261
262 EXPECT_EQ(update.target_rate->target_rate, kInitialBitrate);
263 EXPECT_EQ(update.pacer_config->data_rate(),
264 kInitialBitrate * kDefaultPacingRate);
265 EXPECT_EQ(update.probe_cluster_configs[0].target_data_rate,
266 kInitialBitrate * 3);
267 EXPECT_EQ(update.probe_cluster_configs[1].target_data_rate,
268 kInitialBitrate * 5);
269 }
270
TEST(GoogCcNetworkControllerTest,ReactsToChangedNetworkConditions)271 TEST(GoogCcNetworkControllerTest, ReactsToChangedNetworkConditions) {
272 NetworkControllerTestFixture fixture;
273 std::unique_ptr<NetworkControllerInterface> controller =
274 fixture.CreateController();
275 Timestamp current_time = Timestamp::Millis(123);
276 NetworkControlUpdate update =
277 controller->OnProcessInterval({.at_time = current_time});
278 update = controller->OnRemoteBitrateReport(
279 {.receive_time = current_time, .bandwidth = kInitialBitrate * 2});
280
281 current_time += TimeDelta::Millis(25);
282 update = controller->OnProcessInterval({.at_time = current_time});
283 EXPECT_EQ(update.target_rate->target_rate, kInitialBitrate * 2);
284 EXPECT_EQ(update.pacer_config->data_rate(),
285 kInitialBitrate * 2 * kDefaultPacingRate);
286
287 update = controller->OnRemoteBitrateReport(
288 {.receive_time = current_time, .bandwidth = kInitialBitrate});
289 current_time += TimeDelta::Millis(25);
290 update = controller->OnProcessInterval({.at_time = current_time});
291 EXPECT_EQ(update.target_rate->target_rate, kInitialBitrate);
292 EXPECT_EQ(update.pacer_config->data_rate(),
293 kInitialBitrate * kDefaultPacingRate);
294 }
295
TEST(GoogCcNetworkControllerTest,OnNetworkRouteChanged)296 TEST(GoogCcNetworkControllerTest, OnNetworkRouteChanged) {
297 NetworkControllerTestFixture fixture;
298 std::unique_ptr<NetworkControllerInterface> controller =
299 fixture.CreateController();
300 Timestamp current_time = Timestamp::Millis(123);
301 DataRate new_bitrate = DataRate::BitsPerSec(200000);
302 NetworkControlUpdate update = controller->OnNetworkRouteChange(
303 CreateRouteChange(current_time, new_bitrate));
304 EXPECT_EQ(update.target_rate->target_rate, new_bitrate);
305 EXPECT_EQ(update.pacer_config->data_rate(), new_bitrate * kDefaultPacingRate);
306 EXPECT_EQ(update.probe_cluster_configs.size(), 2u);
307
308 // If the bitrate is reset to -1, the new starting bitrate will be
309 // the minimum default bitrate.
310 const DataRate kDefaultMinBitrate = DataRate::KilobitsPerSec(5);
311 update = controller->OnNetworkRouteChange(CreateRouteChange(current_time));
312 EXPECT_EQ(update.target_rate->target_rate, kDefaultMinBitrate);
313 EXPECT_NEAR(update.pacer_config->data_rate().bps<double>(),
314 kDefaultMinBitrate.bps<double>() * kDefaultPacingRate, 10);
315 EXPECT_EQ(update.probe_cluster_configs.size(), 2u);
316 }
317
TEST(GoogCcNetworkControllerTest,ProbeOnRouteChange)318 TEST(GoogCcNetworkControllerTest, ProbeOnRouteChange) {
319 NetworkControllerTestFixture fixture;
320 std::unique_ptr<NetworkControllerInterface> controller =
321 fixture.CreateController();
322 Timestamp current_time = Timestamp::Millis(123);
323 NetworkControlUpdate update = controller->OnNetworkRouteChange(
324 CreateRouteChange(current_time, 2 * kInitialBitrate, DataRate::Zero(),
325 20 * kInitialBitrate));
326
327 EXPECT_TRUE(update.pacer_config.has_value());
328 EXPECT_EQ(update.target_rate->target_rate, kInitialBitrate * 2);
329 EXPECT_EQ(update.probe_cluster_configs.size(), 2u);
330 EXPECT_EQ(update.probe_cluster_configs[0].target_data_rate,
331 kInitialBitrate * 6);
332 EXPECT_EQ(update.probe_cluster_configs[1].target_data_rate,
333 kInitialBitrate * 12);
334
335 update = controller->OnProcessInterval({.at_time = current_time});
336 }
337
338 // Bandwidth estimation is updated when feedbacks are received.
339 // Feedbacks which show an increasing delay cause the estimation to be reduced.
TEST(GoogCcNetworkControllerTest,UpdatesDelayBasedEstimate)340 TEST(GoogCcNetworkControllerTest, UpdatesDelayBasedEstimate) {
341 NetworkControllerTestFixture fixture;
342 std::unique_ptr<NetworkControllerInterface> controller =
343 fixture.CreateController();
344 const int64_t kRunTimeMs = 6000;
345 Timestamp current_time = Timestamp::Millis(123);
346
347 // The test must run and insert packets/feedback long enough that the
348 // BWE computes a valid estimate. This is first done in an environment which
349 // simulates no bandwidth limitation, and therefore not built-up delay.
350 absl::optional<DataRate> target_bitrate_before_delay =
351 PacketTransmissionAndFeedbackBlock(controller.get(), kRunTimeMs, 0,
352 current_time);
353 ASSERT_TRUE(target_bitrate_before_delay.has_value());
354
355 // Repeat, but this time with a building delay, and make sure that the
356 // estimation is adjusted downwards.
357 absl::optional<DataRate> target_bitrate_after_delay =
358 PacketTransmissionAndFeedbackBlock(controller.get(), kRunTimeMs, 50,
359 current_time);
360 EXPECT_LT(*target_bitrate_after_delay, *target_bitrate_before_delay);
361 }
362
TEST(GoogCcNetworkControllerTest,PaceAtMaxOfLowerLinkCapacityAndBwe)363 TEST(GoogCcNetworkControllerTest, PaceAtMaxOfLowerLinkCapacityAndBwe) {
364 ScopedFieldTrials trial(
365 "WebRTC-Bwe-PaceAtMaxOfBweAndLowerLinkCapacity/Enabled/");
366 NetworkControllerTestFixture fixture;
367 std::unique_ptr<NetworkControllerInterface> controller =
368 fixture.CreateController();
369 Timestamp current_time = Timestamp::Millis(123);
370 NetworkControlUpdate update =
371 controller->OnProcessInterval({.at_time = current_time});
372 current_time += TimeDelta::Millis(100);
373 NetworkStateEstimate network_estimate = {.link_capacity_lower =
374 10 * kInitialBitrate};
375 update = controller->OnNetworkStateEstimate(network_estimate);
376 // OnNetworkStateEstimate does not trigger processing a new estimate. So add a
377 // dummy loss report to trigger a BWE update in the next process interval.
378 TransportLossReport loss_report;
379 loss_report.start_time = current_time;
380 loss_report.end_time = current_time;
381 loss_report.receive_time = current_time;
382 loss_report.packets_received_delta = 50;
383 loss_report.packets_lost_delta = 1;
384 update = controller->OnTransportLossReport(loss_report);
385 update = controller->OnProcessInterval({.at_time = current_time});
386 ASSERT_TRUE(update.pacer_config);
387 ASSERT_TRUE(update.target_rate);
388 ASSERT_LT(update.target_rate->target_rate,
389 network_estimate.link_capacity_lower);
390 EXPECT_EQ(update.pacer_config->data_rate().kbps(),
391 network_estimate.link_capacity_lower.kbps() * kDefaultPacingRate);
392
393 current_time += TimeDelta::Millis(100);
394 // Set a low link capacity estimate and verify that pacing rate is set
395 // relative to loss based/delay based estimate.
396 network_estimate = {.link_capacity_lower = 0.5 * kInitialBitrate};
397 update = controller->OnNetworkStateEstimate(network_estimate);
398 // Again, we need to inject a dummy loss report to trigger an update of the
399 // BWE in the next process interval.
400 loss_report.start_time = current_time;
401 loss_report.end_time = current_time;
402 loss_report.receive_time = current_time;
403 loss_report.packets_received_delta = 50;
404 loss_report.packets_lost_delta = 0;
405 update = controller->OnTransportLossReport(loss_report);
406 update = controller->OnProcessInterval({.at_time = current_time});
407 ASSERT_TRUE(update.target_rate);
408 ASSERT_GT(update.target_rate->target_rate,
409 network_estimate.link_capacity_lower);
410 EXPECT_EQ(update.pacer_config->data_rate().kbps(),
411 update.target_rate->target_rate.kbps() * kDefaultPacingRate);
412 }
413
414 // Test congestion window pushback on network delay happens.
TEST(GoogCcScenario,CongestionWindowPushbackOnNetworkDelay)415 TEST(GoogCcScenario, CongestionWindowPushbackOnNetworkDelay) {
416 auto factory = CreateFeedbackOnlyFactory();
417 ScopedFieldTrials trial(
418 "WebRTC-CongestionWindow/QueueSize:800,MinBitrate:30000/");
419 Scenario s("googcc_unit/cwnd_on_delay", false);
420 auto send_net =
421 s.CreateMutableSimulationNode([=](NetworkSimulationConfig* c) {
422 c->bandwidth = DataRate::KilobitsPerSec(1000);
423 c->delay = TimeDelta::Millis(100);
424 });
425 auto ret_net = s.CreateSimulationNode(
426 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(100); });
427 CallClientConfig config;
428 config.transport.cc_factory = &factory;
429 // Start high so bandwidth drop has max effect.
430 config.transport.rates.start_rate = DataRate::KilobitsPerSec(300);
431 config.transport.rates.max_rate = DataRate::KilobitsPerSec(2000);
432 config.transport.rates.min_rate = DataRate::KilobitsPerSec(10);
433
434 auto* client = CreateVideoSendingClient(&s, std::move(config),
435 {send_net->node()}, {ret_net});
436
437 s.RunFor(TimeDelta::Seconds(10));
438 send_net->PauseTransmissionUntil(s.Now() + TimeDelta::Seconds(10));
439 s.RunFor(TimeDelta::Seconds(3));
440
441 // After 3 seconds without feedback from any sent packets, we expect that the
442 // target rate is reduced to the minimum pushback threshold
443 // kDefaultMinPushbackTargetBitrateBps, which is defined as 30 kbps in
444 // congestion_window_pushback_controller.
445 EXPECT_LT(client->target_rate().kbps(), 40);
446 }
447
448 // Test congestion window pushback on network delay happens.
TEST(GoogCcScenario,CongestionWindowPushbackDropFrameOnNetworkDelay)449 TEST(GoogCcScenario, CongestionWindowPushbackDropFrameOnNetworkDelay) {
450 auto factory = CreateFeedbackOnlyFactory();
451 ScopedFieldTrials trial(
452 "WebRTC-CongestionWindow/QueueSize:800,MinBitrate:30000,DropFrame:true/");
453 Scenario s("googcc_unit/cwnd_on_delay", false);
454 auto send_net =
455 s.CreateMutableSimulationNode([=](NetworkSimulationConfig* c) {
456 c->bandwidth = DataRate::KilobitsPerSec(1000);
457 c->delay = TimeDelta::Millis(100);
458 });
459 auto ret_net = s.CreateSimulationNode(
460 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(100); });
461 CallClientConfig config;
462 config.transport.cc_factory = &factory;
463 // Start high so bandwidth drop has max effect.
464 config.transport.rates.start_rate = DataRate::KilobitsPerSec(300);
465 config.transport.rates.max_rate = DataRate::KilobitsPerSec(2000);
466 config.transport.rates.min_rate = DataRate::KilobitsPerSec(10);
467
468 auto* client = CreateVideoSendingClient(&s, std::move(config),
469 {send_net->node()}, {ret_net});
470
471 s.RunFor(TimeDelta::Seconds(10));
472 send_net->PauseTransmissionUntil(s.Now() + TimeDelta::Seconds(10));
473 s.RunFor(TimeDelta::Seconds(3));
474
475 // As the dropframe is set, after 3 seconds without feedback from any sent
476 // packets, we expect that the target rate is not reduced by congestion
477 // window.
478 EXPECT_GT(client->target_rate().kbps(), 300);
479 }
480
TEST(GoogCcScenario,PaddingRateLimitedByCongestionWindowInTrial)481 TEST(GoogCcScenario, PaddingRateLimitedByCongestionWindowInTrial) {
482 ScopedFieldTrials trial(
483 "WebRTC-CongestionWindow/QueueSize:200,MinBitrate:30000/");
484
485 Scenario s("googcc_unit/padding_limited", false);
486 auto send_net =
487 s.CreateMutableSimulationNode([=](NetworkSimulationConfig* c) {
488 c->bandwidth = DataRate::KilobitsPerSec(1000);
489 c->delay = TimeDelta::Millis(100);
490 });
491 auto ret_net = s.CreateSimulationNode(
492 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(100); });
493 CallClientConfig config;
494 // Start high so bandwidth drop has max effect.
495 config.transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
496 config.transport.rates.max_rate = DataRate::KilobitsPerSec(2000);
497 auto* client = s.CreateClient("send", config);
498 auto* route =
499 s.CreateRoutes(client, {send_net->node()},
500 s.CreateClient("return", CallClientConfig()), {ret_net});
501 VideoStreamConfig video;
502 video.stream.pad_to_rate = config.transport.rates.max_rate;
503 s.CreateVideoStream(route->forward(), video);
504
505 // Run for a few seconds to allow the controller to stabilize.
506 s.RunFor(TimeDelta::Seconds(10));
507
508 // Check that padding rate matches target rate.
509 EXPECT_NEAR(client->padding_rate().kbps(), client->target_rate().kbps(), 1);
510
511 // Check this is also the case when congestion window pushback kicks in.
512 send_net->PauseTransmissionUntil(s.Now() + TimeDelta::Seconds(1));
513 EXPECT_NEAR(client->padding_rate().kbps(), client->target_rate().kbps(), 1);
514 }
515
TEST(GoogCcScenario,LimitsToFloorIfRttIsHighInTrial)516 TEST(GoogCcScenario, LimitsToFloorIfRttIsHighInTrial) {
517 // The field trial limits maximum RTT to 2 seconds, higher RTT means that the
518 // controller backs off until it reaches the minimum configured bitrate. This
519 // allows the RTT to recover faster than the regular control mechanism would
520 // achieve.
521 const DataRate kBandwidthFloor = DataRate::KilobitsPerSec(50);
522 ScopedFieldTrials trial("WebRTC-Bwe-MaxRttLimit/limit:2s,floor:" +
523 std::to_string(kBandwidthFloor.kbps()) + "kbps/");
524 // In the test case, we limit the capacity and add a cross traffic packet
525 // burst that blocks media from being sent. This causes the RTT to quickly
526 // increase above the threshold in the trial.
527 const DataRate kLinkCapacity = DataRate::KilobitsPerSec(100);
528 const TimeDelta kBufferBloatDuration = TimeDelta::Seconds(10);
529 Scenario s("googcc_unit/limit_trial", false);
530 auto send_net = s.CreateSimulationNode([=](NetworkSimulationConfig* c) {
531 c->bandwidth = kLinkCapacity;
532 c->delay = TimeDelta::Millis(100);
533 });
534 auto ret_net = s.CreateSimulationNode(
535 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(100); });
536 CallClientConfig config;
537 config.transport.rates.start_rate = kLinkCapacity;
538
539 auto* client = CreateVideoSendingClient(&s, config, {send_net}, {ret_net});
540 // Run for a few seconds to allow the controller to stabilize.
541 s.RunFor(TimeDelta::Seconds(10));
542 const DataSize kBloatPacketSize = DataSize::Bytes(1000);
543 const int kBloatPacketCount =
544 static_cast<int>(kBufferBloatDuration * kLinkCapacity / kBloatPacketSize);
545 // This will cause the RTT to be large for a while.
546 s.TriggerPacketBurst({send_net}, kBloatPacketCount, kBloatPacketSize.bytes());
547 // Wait to allow the high RTT to be detected and acted upon.
548 s.RunFor(TimeDelta::Seconds(6));
549 // By now the target rate should have dropped to the minimum configured rate.
550 EXPECT_NEAR(client->target_rate().kbps(), kBandwidthFloor.kbps(), 5);
551 }
552
TEST(GoogCcScenario,UpdatesTargetRateBasedOnLinkCapacity)553 TEST(GoogCcScenario, UpdatesTargetRateBasedOnLinkCapacity) {
554 UpdatesTargetRateBasedOnLinkCapacity();
555 }
556
TEST(GoogCcScenario,StableEstimateDoesNotVaryInSteadyState)557 TEST(GoogCcScenario, StableEstimateDoesNotVaryInSteadyState) {
558 auto factory = CreateFeedbackOnlyFactory();
559 Scenario s("googcc_unit/stable_target", false);
560 CallClientConfig config;
561 config.transport.cc_factory = &factory;
562 NetworkSimulationConfig net_conf;
563 net_conf.bandwidth = DataRate::KilobitsPerSec(500);
564 net_conf.delay = TimeDelta::Millis(100);
565 auto send_net = s.CreateSimulationNode(net_conf);
566 auto ret_net = s.CreateSimulationNode(net_conf);
567
568 auto* client = CreateVideoSendingClient(&s, config, {send_net}, {ret_net});
569 // Run for a while to allow the estimate to stabilize.
570 s.RunFor(TimeDelta::Seconds(30));
571 DataRate min_stable_target = DataRate::PlusInfinity();
572 DataRate max_stable_target = DataRate::MinusInfinity();
573 DataRate min_target = DataRate::PlusInfinity();
574 DataRate max_target = DataRate::MinusInfinity();
575
576 // Measure variation in steady state.
577 for (int i = 0; i < 20; ++i) {
578 auto stable_target_rate = client->stable_target_rate();
579 auto target_rate = client->target_rate();
580 EXPECT_LE(stable_target_rate, target_rate);
581
582 min_stable_target = std::min(min_stable_target, stable_target_rate);
583 max_stable_target = std::max(max_stable_target, stable_target_rate);
584 min_target = std::min(min_target, target_rate);
585 max_target = std::max(max_target, target_rate);
586 s.RunFor(TimeDelta::Seconds(1));
587 }
588 // We should expect drops by at least 15% (default backoff.)
589 EXPECT_LT(min_target / max_target, 0.85);
590 // We should expect the stable target to be more stable than the immediate one
591 EXPECT_GE(min_stable_target / max_stable_target, min_target / max_target);
592 }
593
TEST(GoogCcScenario,LossBasedControlUpdatesTargetRateBasedOnLinkCapacity)594 TEST(GoogCcScenario, LossBasedControlUpdatesTargetRateBasedOnLinkCapacity) {
595 ScopedFieldTrials trial("WebRTC-Bwe-LossBasedControl/Enabled/");
596 // TODO(srte): Should the behavior be unaffected at low loss rates?
597 UpdatesTargetRateBasedOnLinkCapacity("_loss_based");
598 }
599
TEST(GoogCcScenario,LossBasedControlDoesModestBackoffToHighLoss)600 TEST(GoogCcScenario, LossBasedControlDoesModestBackoffToHighLoss) {
601 ScopedFieldTrials trial("WebRTC-Bwe-LossBasedControl/Enabled/");
602 Scenario s("googcc_unit/high_loss_channel", false);
603 CallClientConfig config;
604 config.transport.rates.min_rate = DataRate::KilobitsPerSec(10);
605 config.transport.rates.max_rate = DataRate::KilobitsPerSec(1500);
606 config.transport.rates.start_rate = DataRate::KilobitsPerSec(300);
607 auto send_net = s.CreateSimulationNode([](NetworkSimulationConfig* c) {
608 c->bandwidth = DataRate::KilobitsPerSec(2000);
609 c->delay = TimeDelta::Millis(200);
610 c->loss_rate = 0.1;
611 });
612 auto ret_net = s.CreateSimulationNode(
613 [](NetworkSimulationConfig* c) { c->delay = TimeDelta::Millis(200); });
614
615 auto* client = CreateVideoSendingClient(&s, config, {send_net}, {ret_net});
616
617 s.RunFor(TimeDelta::Seconds(120));
618 // Without LossBasedControl trial, bandwidth drops to ~10 kbps.
619 EXPECT_GT(client->target_rate().kbps(), 100);
620 }
621
AverageBitrateAfterCrossInducedLoss(absl::string_view name)622 DataRate AverageBitrateAfterCrossInducedLoss(absl::string_view name) {
623 Scenario s(name, false);
624 NetworkSimulationConfig net_conf;
625 net_conf.bandwidth = DataRate::KilobitsPerSec(1000);
626 net_conf.delay = TimeDelta::Millis(100);
627 // Short queue length means that we'll induce loss when sudden TCP traffic
628 // spikes are induced. This corresponds to ca 200 ms for a packet size of 1000
629 // bytes. Such limited buffers are common on for instance wifi routers.
630 net_conf.packet_queue_length_limit = 25;
631
632 auto send_net = {s.CreateSimulationNode(net_conf)};
633 auto ret_net = {s.CreateSimulationNode(net_conf)};
634
635 auto* client = s.CreateClient("send", CallClientConfig());
636 auto* callee = s.CreateClient("return", CallClientConfig());
637 auto* route = s.CreateRoutes(client, send_net, callee, ret_net);
638 // TODO(srte): Make this work with RTX enabled or remove it.
639 auto* video = s.CreateVideoStream(route->forward(), [](VideoStreamConfig* c) {
640 c->stream.use_rtx = false;
641 });
642 s.RunFor(TimeDelta::Seconds(10));
643 for (int i = 0; i < 4; ++i) {
644 // Sends TCP cross traffic inducing loss.
645 auto* tcp_traffic = s.net()->StartCrossTraffic(CreateFakeTcpCrossTraffic(
646 s.net()->CreateRoute(send_net), s.net()->CreateRoute(ret_net),
647 FakeTcpConfig()));
648 s.RunFor(TimeDelta::Seconds(2));
649 // Allow the ccongestion controller to recover.
650 s.net()->StopCrossTraffic(tcp_traffic);
651 s.RunFor(TimeDelta::Seconds(20));
652 }
653
654 // Querying the video stats from within the expected runtime environment
655 // (i.e. the TQ that belongs to the CallClient, not the Scenario TQ that
656 // we're currently on).
657 VideoReceiveStreamInterface::Stats video_receive_stats;
658 auto* video_stream = video->receive();
659 callee->SendTask([&video_stream, &video_receive_stats]() {
660 video_receive_stats = video_stream->GetStats();
661 });
662 return DataSize::Bytes(
663 video_receive_stats.rtp_stats.packet_counter.TotalBytes()) /
664 s.TimeSinceStart();
665 }
666
TEST(GoogCcScenario,LossBasedRecoversFasterAfterCrossInducedLoss)667 TEST(GoogCcScenario, LossBasedRecoversFasterAfterCrossInducedLoss) {
668 // This test acts as a reference for the test below, showing that without the
669 // trial, we have worse behavior.
670 DataRate average_bitrate_without_loss_based =
671 AverageBitrateAfterCrossInducedLoss("googcc_unit/no_cross_loss_based");
672
673 // We recover bitrate better when subject to loss spikes from cross traffic
674 // when loss based controller is used.
675 ScopedFieldTrials trial("WebRTC-Bwe-LossBasedControl/Enabled/");
676 DataRate average_bitrate_with_loss_based =
677 AverageBitrateAfterCrossInducedLoss("googcc_unit/cross_loss_based");
678
679 EXPECT_GT(average_bitrate_with_loss_based,
680 average_bitrate_without_loss_based);
681 }
682
TEST(GoogCcScenario,LossBasedEstimatorCapsRateAtModerateLoss)683 TEST(GoogCcScenario, LossBasedEstimatorCapsRateAtModerateLoss) {
684 ScopedFieldTrials trial("WebRTC-Bwe-LossBasedControl/Enabled/");
685 Scenario s("googcc_unit/moderate_loss_channel", false);
686 CallClientConfig config;
687 config.transport.rates.min_rate = DataRate::KilobitsPerSec(10);
688 config.transport.rates.max_rate = DataRate::KilobitsPerSec(5000);
689 config.transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
690
691 NetworkSimulationConfig network;
692 network.bandwidth = DataRate::KilobitsPerSec(2000);
693 network.delay = TimeDelta::Millis(100);
694 // 3% loss rate is in the moderate loss rate region at 2000 kbps, limiting the
695 // bitrate increase.
696 network.loss_rate = 0.03;
697 auto send_net = s.CreateMutableSimulationNode(network);
698 auto* client = s.CreateClient("send", std::move(config));
699 auto* route = s.CreateRoutes(client, {send_net->node()},
700 s.CreateClient("return", CallClientConfig()),
701 {s.CreateSimulationNode(network)});
702 s.CreateVideoStream(route->forward(), VideoStreamConfig());
703 // Allow the controller to stabilize at the lower bitrate.
704 s.RunFor(TimeDelta::Seconds(1));
705 // This increase in capacity would cause the target bitrate to increase to
706 // over 4000 kbps without LossBasedControl.
707 send_net->UpdateConfig([](NetworkSimulationConfig* c) {
708 c->bandwidth = DataRate::KilobitsPerSec(5000);
709 });
710 s.RunFor(TimeDelta::Seconds(20));
711 // Using LossBasedControl, the bitrate will not increase over 2500 kbps since
712 // we have detected moderate loss.
713 EXPECT_LT(client->target_rate().kbps(), 2500);
714 }
715
TEST(GoogCcScenario,MaintainsLowRateInSafeResetTrial)716 TEST(GoogCcScenario, MaintainsLowRateInSafeResetTrial) {
717 const DataRate kLinkCapacity = DataRate::KilobitsPerSec(200);
718 const DataRate kStartRate = DataRate::KilobitsPerSec(300);
719
720 ScopedFieldTrials trial("WebRTC-Bwe-SafeResetOnRouteChange/Enabled/");
721 Scenario s("googcc_unit/safe_reset_low");
722 auto* send_net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
723 c->bandwidth = kLinkCapacity;
724 c->delay = TimeDelta::Millis(10);
725 });
726 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
727 c->transport.rates.start_rate = kStartRate;
728 });
729 auto* route = s.CreateRoutes(
730 client, {send_net}, s.CreateClient("return", CallClientConfig()),
731 {s.CreateSimulationNode(NetworkSimulationConfig())});
732 s.CreateVideoStream(route->forward(), VideoStreamConfig());
733 // Allow the controller to stabilize.
734 s.RunFor(TimeDelta::Millis(500));
735 EXPECT_NEAR(client->send_bandwidth().kbps(), kLinkCapacity.kbps(), 50);
736 s.ChangeRoute(route->forward(), {send_net});
737 // Allow new settings to propagate.
738 s.RunFor(TimeDelta::Millis(100));
739 // Under the trial, the target should be unchanged for low rates.
740 EXPECT_NEAR(client->send_bandwidth().kbps(), kLinkCapacity.kbps(), 50);
741 }
742
TEST(GoogCcScenario,CutsHighRateInSafeResetTrial)743 TEST(GoogCcScenario, CutsHighRateInSafeResetTrial) {
744 const DataRate kLinkCapacity = DataRate::KilobitsPerSec(1000);
745 const DataRate kStartRate = DataRate::KilobitsPerSec(300);
746
747 ScopedFieldTrials trial("WebRTC-Bwe-SafeResetOnRouteChange/Enabled/");
748 Scenario s("googcc_unit/safe_reset_high_cut");
749 auto send_net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
750 c->bandwidth = kLinkCapacity;
751 c->delay = TimeDelta::Millis(50);
752 });
753 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
754 c->transport.rates.start_rate = kStartRate;
755 });
756 auto* route = s.CreateRoutes(
757 client, {send_net}, s.CreateClient("return", CallClientConfig()),
758 {s.CreateSimulationNode(NetworkSimulationConfig())});
759 s.CreateVideoStream(route->forward(), VideoStreamConfig());
760 // Allow the controller to stabilize.
761 s.RunFor(TimeDelta::Millis(500));
762 EXPECT_NEAR(client->send_bandwidth().kbps(), kLinkCapacity.kbps(), 300);
763 s.ChangeRoute(route->forward(), {send_net});
764 // Allow new settings to propagate.
765 s.RunFor(TimeDelta::Millis(50));
766 // Under the trial, the target should be reset from high values.
767 EXPECT_NEAR(client->send_bandwidth().kbps(), kStartRate.kbps(), 30);
768 }
769
TEST(GoogCcScenario,DetectsHighRateInSafeResetTrial)770 TEST(GoogCcScenario, DetectsHighRateInSafeResetTrial) {
771 ScopedFieldTrials trial("WebRTC-Bwe-SafeResetOnRouteChange/Enabled,ack/");
772 const DataRate kInitialLinkCapacity = DataRate::KilobitsPerSec(200);
773 const DataRate kNewLinkCapacity = DataRate::KilobitsPerSec(800);
774 const DataRate kStartRate = DataRate::KilobitsPerSec(300);
775
776 Scenario s("googcc_unit/safe_reset_high_detect");
777 auto* initial_net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
778 c->bandwidth = kInitialLinkCapacity;
779 c->delay = TimeDelta::Millis(50);
780 });
781 auto* new_net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
782 c->bandwidth = kNewLinkCapacity;
783 c->delay = TimeDelta::Millis(50);
784 });
785 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
786 c->transport.rates.start_rate = kStartRate;
787 });
788 auto* route = s.CreateRoutes(
789 client, {initial_net}, s.CreateClient("return", CallClientConfig()),
790 {s.CreateSimulationNode(NetworkSimulationConfig())});
791 s.CreateVideoStream(route->forward(), VideoStreamConfig());
792 // Allow the controller to stabilize.
793 s.RunFor(TimeDelta::Millis(2000));
794 EXPECT_NEAR(client->send_bandwidth().kbps(), kInitialLinkCapacity.kbps(), 50);
795 s.ChangeRoute(route->forward(), {new_net});
796 // Allow new settings to propagate, but not probes to be received.
797 s.RunFor(TimeDelta::Millis(50));
798 // Under the field trial, the target rate should be unchanged since it's lower
799 // than the starting rate.
800 EXPECT_NEAR(client->send_bandwidth().kbps(), kInitialLinkCapacity.kbps(), 50);
801 // However, probing should have made us detect the higher rate.
802 // NOTE: This test causes high loss rate, and the loss-based estimator reduces
803 // the bitrate, making the test fail if we wait longer than one second here.
804 s.RunFor(TimeDelta::Millis(1000));
805 EXPECT_GT(client->send_bandwidth().kbps(), kNewLinkCapacity.kbps() - 300);
806 }
807
TEST(GoogCcScenario,TargetRateReducedOnPacingBufferBuildupInTrial)808 TEST(GoogCcScenario, TargetRateReducedOnPacingBufferBuildupInTrial) {
809 // Configure strict pacing to ensure build-up.
810 ScopedFieldTrials trial(
811 "WebRTC-CongestionWindow/QueueSize:100,MinBitrate:30000/"
812 "WebRTC-Video-Pacing/factor:1.0/"
813 "WebRTC-AddPacingToCongestionWindowPushback/Enabled/");
814
815 const DataRate kLinkCapacity = DataRate::KilobitsPerSec(1000);
816 const DataRate kStartRate = DataRate::KilobitsPerSec(1000);
817
818 Scenario s("googcc_unit/pacing_buffer_buildup");
819 auto* net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
820 c->bandwidth = kLinkCapacity;
821 c->delay = TimeDelta::Millis(50);
822 });
823 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
824 c->transport.rates.start_rate = kStartRate;
825 });
826 auto* route = s.CreateRoutes(
827 client, {net}, s.CreateClient("return", CallClientConfig()),
828 {s.CreateSimulationNode(NetworkSimulationConfig())});
829 s.CreateVideoStream(route->forward(), VideoStreamConfig());
830 // Allow some time for the buffer to build up.
831 s.RunFor(TimeDelta::Seconds(5));
832
833 // Without trial, pacer delay reaches ~250 ms.
834 EXPECT_LT(client->GetStats().pacer_delay_ms, 150);
835 }
836
TEST(GoogCcScenario,NoBandwidthTogglingInLossControlTrial)837 TEST(GoogCcScenario, NoBandwidthTogglingInLossControlTrial) {
838 ScopedFieldTrials trial("WebRTC-Bwe-LossBasedControl/Enabled/");
839 Scenario s("googcc_unit/no_toggling");
840 auto* send_net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
841 c->bandwidth = DataRate::KilobitsPerSec(2000);
842 c->loss_rate = 0.2;
843 c->delay = TimeDelta::Millis(10);
844 });
845
846 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
847 c->transport.rates.start_rate = DataRate::KilobitsPerSec(300);
848 });
849 auto* route = s.CreateRoutes(
850 client, {send_net}, s.CreateClient("return", CallClientConfig()),
851 {s.CreateSimulationNode(NetworkSimulationConfig())});
852 s.CreateVideoStream(route->forward(), VideoStreamConfig());
853 // Allow the controller to initialize.
854 s.RunFor(TimeDelta::Millis(250));
855
856 std::queue<DataRate> bandwidth_history;
857 const TimeDelta step = TimeDelta::Millis(50);
858 for (TimeDelta time = TimeDelta::Zero(); time < TimeDelta::Millis(2000);
859 time += step) {
860 s.RunFor(step);
861 const TimeDelta window = TimeDelta::Millis(500);
862 if (bandwidth_history.size() >= window / step)
863 bandwidth_history.pop();
864 bandwidth_history.push(client->send_bandwidth());
865 EXPECT_LT(
866 CountBandwidthDips(bandwidth_history, DataRate::KilobitsPerSec(100)),
867 2);
868 }
869 }
870
TEST(GoogCcScenario,NoRttBackoffCollapseWhenVideoStops)871 TEST(GoogCcScenario, NoRttBackoffCollapseWhenVideoStops) {
872 ScopedFieldTrials trial("WebRTC-Bwe-MaxRttLimit/limit:2s/");
873 Scenario s("googcc_unit/rttbackoff_video_stop");
874 auto* send_net = s.CreateSimulationNode([&](NetworkSimulationConfig* c) {
875 c->bandwidth = DataRate::KilobitsPerSec(2000);
876 c->delay = TimeDelta::Millis(100);
877 });
878
879 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
880 c->transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
881 });
882 auto* route = s.CreateRoutes(
883 client, {send_net}, s.CreateClient("return", CallClientConfig()),
884 {s.CreateSimulationNode(NetworkSimulationConfig())});
885 auto* video = s.CreateVideoStream(route->forward(), VideoStreamConfig());
886 // Allow the controller to initialize, then stop video.
887 s.RunFor(TimeDelta::Seconds(1));
888 video->send()->Stop();
889 s.RunFor(TimeDelta::Seconds(4));
890 EXPECT_GT(client->send_bandwidth().kbps(), 1000);
891 }
892
TEST(GoogCcScenario,NoCrashOnVeryLateFeedback)893 TEST(GoogCcScenario, NoCrashOnVeryLateFeedback) {
894 Scenario s;
895 auto ret_net = s.CreateMutableSimulationNode(NetworkSimulationConfig());
896 auto* route = s.CreateRoutes(
897 s.CreateClient("send", CallClientConfig()),
898 {s.CreateSimulationNode(NetworkSimulationConfig())},
899 s.CreateClient("return", CallClientConfig()), {ret_net->node()});
900 auto* video = s.CreateVideoStream(route->forward(), VideoStreamConfig());
901 s.RunFor(TimeDelta::Seconds(5));
902 // Delay feedback by several minutes. This will cause removal of the send time
903 // history for the packets as long as kSendTimeHistoryWindow is configured for
904 // a shorter time span.
905 ret_net->PauseTransmissionUntil(s.Now() + TimeDelta::Seconds(300));
906 // Stopping video stream while waiting to save test execution time.
907 video->send()->Stop();
908 s.RunFor(TimeDelta::Seconds(299));
909 // Starting to cause addition of new packet to history, which cause old
910 // packets to be removed.
911 video->send()->Start();
912 // Runs until the lost packets are received. We expect that this will run
913 // without causing any runtime failures.
914 s.RunFor(TimeDelta::Seconds(2));
915 }
916
TEST(GoogCcScenario,IsFairToTCP)917 TEST(GoogCcScenario, IsFairToTCP) {
918 Scenario s("googcc_unit/tcp_fairness");
919 NetworkSimulationConfig net_conf;
920 net_conf.bandwidth = DataRate::KilobitsPerSec(1000);
921 net_conf.delay = TimeDelta::Millis(50);
922 auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
923 c->transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
924 });
925 auto send_net = {s.CreateSimulationNode(net_conf)};
926 auto ret_net = {s.CreateSimulationNode(net_conf)};
927 auto* route = s.CreateRoutes(
928 client, send_net, s.CreateClient("return", CallClientConfig()), ret_net);
929 s.CreateVideoStream(route->forward(), VideoStreamConfig());
930 s.net()->StartCrossTraffic(CreateFakeTcpCrossTraffic(
931 s.net()->CreateRoute(send_net), s.net()->CreateRoute(ret_net),
932 FakeTcpConfig()));
933 s.RunFor(TimeDelta::Seconds(10));
934
935 // Currently only testing for the upper limit as we in practice back out
936 // quite a lot in this scenario. If this behavior is fixed, we should add a
937 // lower bound to ensure it stays fixed.
938 EXPECT_LT(client->send_bandwidth().kbps(), 750);
939 }
940
TEST(GoogCcScenario,FastRampupOnRembCapLifted)941 TEST(GoogCcScenario, FastRampupOnRembCapLifted) {
942 DataRate final_estimate =
943 RunRembDipScenario("googcc_unit/default_fast_rampup_on_remb_cap_lifted");
944 EXPECT_GT(final_estimate.kbps(), 1500);
945 }
946
TEST(GoogCcScenario,SlowRampupOnRembCapLiftedWithFieldTrial)947 TEST(GoogCcScenario, SlowRampupOnRembCapLiftedWithFieldTrial) {
948 ScopedFieldTrials trial("WebRTC-Bwe-ReceiverLimitCapsOnly/Disabled/");
949 DataRate final_estimate =
950 RunRembDipScenario("googcc_unit/legacy_slow_rampup_on_remb_cap_lifted");
951 EXPECT_LT(final_estimate.kbps(), 1000);
952 }
953
954 } // namespace test
955 } // namespace webrtc
956