aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/remote_bitrate_estimator/bwe_simulations.cc
blob: 11fd64f84e77dcbedbb56ab879432fe1e1e29fca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test.h"
#include "webrtc/modules/remote_bitrate_estimator/test/packet_receiver.h"
#include "webrtc/modules/remote_bitrate_estimator/test/packet_sender.h"
#include "webrtc/test/testsupport/fileutils.h"


namespace webrtc {
namespace testing {
namespace bwe {
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
// This test fixture is used to instantiate tests running with adaptive video
// senders.
class BweSimulation : public BweTest,
                      public ::testing::TestWithParam<BandwidthEstimatorType> {
 public:
  BweSimulation()
      : BweTest(), random_(Clock::GetRealTimeClock()->TimeInMicroseconds()) {}
  virtual ~BweSimulation() {}

 protected:
  void SetUp() override {
    BweTest::SetUp();
    VerboseLogging(true);
  }

  Random random_;

 private:
  RTC_DISALLOW_COPY_AND_ASSIGN(BweSimulation);
};

INSTANTIATE_TEST_CASE_P(VideoSendersTest,
                        BweSimulation,
                        ::testing::Values(kRembEstimator,
                                          kFullSendSideEstimator,
                                          kNadaEstimator));

TEST_P(BweSimulation, SprintUplinkTest) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  VideoSender sender(&uplink_, &source, GetParam());
  RateCounterFilter counter1(&uplink_, 0, "sender_output",
                             bwe_names[GetParam()]);
  TraceBasedDeliveryFilter filter(&uplink_, 0, "link_capacity");
  RateCounterFilter counter2(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  ASSERT_TRUE(filter.Init(test::ResourcePath("sprint-uplink", "rx")));
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, Verizon4gDownlinkTest) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  VideoSender sender(&downlink_, &source, GetParam());
  RateCounterFilter counter1(&downlink_, 0, "sender_output",
                             bwe_names[GetParam()] + "_up");
  TraceBasedDeliveryFilter filter(&downlink_, 0, "link_capacity");
  RateCounterFilter counter2(&downlink_, 0, "Receiver",
                             bwe_names[GetParam()] + "_down");
  PacketReceiver receiver(&downlink_, 0, GetParam(), true, true);
  ASSERT_TRUE(filter.Init(test::ResourcePath("verizon4g-downlink", "rx")));
  RunFor(22 * 60 * 1000);
}

TEST_P(BweSimulation, Choke1000kbps500kbps1000kbpsBiDirectional) {
  const int kFlowIds[] = {0, 1};
  const size_t kNumFlows = sizeof(kFlowIds) / sizeof(kFlowIds[0]);

  AdaptiveVideoSource source(kFlowIds[0], 30, 300, 0, 0);
  VideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter choke(&uplink_, kFlowIds[0]);
  RateCounterFilter counter(&uplink_, kFlowIds[0], "Receiver_0",
                            bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, kFlowIds[0], GetParam(), true, false);

  AdaptiveVideoSource source2(kFlowIds[1], 30, 300, 0, 0);
  VideoSender sender2(&downlink_, &source2, GetParam());
  ChokeFilter choke2(&downlink_, kFlowIds[1]);
  DelayFilter delay(&downlink_, CreateFlowIds(kFlowIds, kNumFlows));
  RateCounterFilter counter2(&downlink_, kFlowIds[1], "Receiver_1",
                             bwe_names[GetParam()]);
  PacketReceiver receiver2(&downlink_, kFlowIds[1], GetParam(), true, false);

  choke2.set_capacity_kbps(500);
  delay.SetOneWayDelayMs(0);

  choke.set_capacity_kbps(1000);
  choke.set_max_delay_ms(500);
  RunFor(60 * 1000);
  choke.set_capacity_kbps(500);
  RunFor(60 * 1000);
  choke.set_capacity_kbps(1000);
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, Choke1000kbps500kbps1000kbps) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  VideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter choke(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, false);

  choke.set_capacity_kbps(1000);
  choke.set_max_delay_ms(500);
  RunFor(60 * 1000);
  choke.set_capacity_kbps(500);
  RunFor(60 * 1000);
  choke.set_capacity_kbps(1000);
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, PacerChoke1000kbps500kbps1000kbps) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  PacedVideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter filter(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  filter.set_capacity_kbps(1000);
  filter.set_max_delay_ms(500);
  RunFor(60 * 1000);
  filter.set_capacity_kbps(500);
  RunFor(60 * 1000);
  filter.set_capacity_kbps(1000);
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, PacerChoke10000kbps) {
  PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000);
  PacedVideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter filter(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  filter.set_capacity_kbps(10000);
  filter.set_max_delay_ms(500);
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, PacerChoke200kbps30kbps200kbps) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  PacedVideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter filter(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  filter.set_capacity_kbps(200);
  filter.set_max_delay_ms(500);
  RunFor(60 * 1000);
  filter.set_capacity_kbps(30);
  RunFor(60 * 1000);
  filter.set_capacity_kbps(200);
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, Choke200kbps30kbps200kbps) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  VideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter filter(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  filter.set_capacity_kbps(200);
  filter.set_max_delay_ms(500);
  RunFor(60 * 1000);
  filter.set_capacity_kbps(30);
  RunFor(60 * 1000);
  filter.set_capacity_kbps(200);
  RunFor(60 * 1000);
}

TEST_P(BweSimulation, GoogleWifiTrace3Mbps) {
  AdaptiveVideoSource source(0, 30, 300, 0, 0);
  VideoSender sender(&uplink_, &source, GetParam());
  RateCounterFilter counter1(&uplink_, 0, "sender_output",
                             bwe_names[GetParam()]);
  TraceBasedDeliveryFilter filter(&uplink_, 0, "link_capacity");
  filter.set_max_delay_ms(500);
  RateCounterFilter counter2(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx")));
  RunFor(300 * 1000);
}

TEST_P(BweSimulation, LinearIncreasingCapacity) {
  PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000000);
  PacedVideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter filter(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  filter.set_max_delay_ms(500);
  const int kStartingCapacityKbps = 150;
  const int kEndingCapacityKbps = 1500;
  const int kStepKbps = 5;
  const int kStepTimeMs = 1000;

  for (int i = kStartingCapacityKbps; i <= kEndingCapacityKbps;
       i += kStepKbps) {
    filter.set_capacity_kbps(i);
    RunFor(kStepTimeMs);
  }
}

TEST_P(BweSimulation, LinearDecreasingCapacity) {
  PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000000);
  PacedVideoSender sender(&uplink_, &source, GetParam());
  ChokeFilter filter(&uplink_, 0);
  RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  filter.set_max_delay_ms(500);
  const int kStartingCapacityKbps = 1500;
  const int kEndingCapacityKbps = 150;
  const int kStepKbps = -5;
  const int kStepTimeMs = 1000;

  for (int i = kStartingCapacityKbps; i >= kEndingCapacityKbps;
       i += kStepKbps) {
    filter.set_capacity_kbps(i);
    RunFor(kStepTimeMs);
  }
}

TEST_P(BweSimulation, PacerGoogleWifiTrace3Mbps) {
  PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000);
  PacedVideoSender sender(&uplink_, &source, GetParam());
  RateCounterFilter counter1(&uplink_, 0, "sender_output",
                             bwe_names[GetParam()]);
  TraceBasedDeliveryFilter filter(&uplink_, 0, "link_capacity");
  filter.set_max_delay_ms(500);
  RateCounterFilter counter2(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
  PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
  ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx")));
  RunFor(300 * 1000);
}

TEST_P(BweSimulation, SelfFairnessTest) {
  Random prng(Clock::GetRealTimeClock()->TimeInMicroseconds());
  const int kAllFlowIds[] = {0, 1, 2, 3};
  const size_t kNumFlows = sizeof(kAllFlowIds) / sizeof(kAllFlowIds[0]);
  rtc::scoped_ptr<VideoSource> sources[kNumFlows];
  rtc::scoped_ptr<VideoSender> senders[kNumFlows];
  for (size_t i = 0; i < kNumFlows; ++i) {
    // Streams started 20 seconds apart to give them different advantage when
    // competing for the bandwidth.
    sources[i].reset(new AdaptiveVideoSource(kAllFlowIds[i], 30, 300, 0,
                                             i * prng.Rand(39999)));
    senders[i].reset(new VideoSender(&uplink_, sources[i].get(), GetParam()));
  }

  ChokeFilter choke(&uplink_, CreateFlowIds(kAllFlowIds, kNumFlows));
  choke.set_capacity_kbps(1000);

  rtc::scoped_ptr<RateCounterFilter> rate_counters[kNumFlows];
  for (size_t i = 0; i < kNumFlows; ++i) {
    rate_counters[i].reset(
        new RateCounterFilter(&uplink_, CreateFlowIds(&kAllFlowIds[i], 1),
                              "Receiver", bwe_names[GetParam()]));
  }

  RateCounterFilter total_utilization(
      &uplink_, CreateFlowIds(kAllFlowIds, kNumFlows), "total_utilization",
      "Total_link_utilization");

  rtc::scoped_ptr<PacketReceiver> receivers[kNumFlows];
  for (size_t i = 0; i < kNumFlows; ++i) {
    receivers[i].reset(new PacketReceiver(&uplink_, kAllFlowIds[i], GetParam(),
                                          i == 0, false));
  }

  RunFor(30 * 60 * 1000);
}

TEST_P(BweSimulation, PacedSelfFairness50msTest) {
  const int64_t kAverageOffsetMs = 20 * 1000;
  const int kNumRmcatFlows = 4;
  int64_t offsets_ms[kNumRmcatFlows];
  offsets_ms[0] = random_.Rand(2 * kAverageOffsetMs);
  for (int i = 1; i < kNumRmcatFlows; ++i) {
    offsets_ms[i] = offsets_ms[i - 1] + random_.Rand(2 * kAverageOffsetMs);
  }
  RunFairnessTest(GetParam(), kNumRmcatFlows, 0, 1000, 3000, 50, 50, 0,
                  offsets_ms);
}

TEST_P(BweSimulation, PacedSelfFairness500msTest) {
  const int64_t kAverageOffsetMs = 20 * 1000;
  const int kNumRmcatFlows = 4;
  int64_t offsets_ms[kNumRmcatFlows];
  offsets_ms[0] = random_.Rand(2 * kAverageOffsetMs);
  for (int i = 1; i < kNumRmcatFlows; ++i) {
    offsets_ms[i] = offsets_ms[i - 1] + random_.Rand(2 * kAverageOffsetMs);
  }
  RunFairnessTest(GetParam(), kNumRmcatFlows, 0, 1000, 3000, 500, 50, 0,
                  offsets_ms);
}

TEST_P(BweSimulation, PacedSelfFairness1000msTest) {
  const int64_t kAverageOffsetMs = 20 * 1000;
  const int kNumRmcatFlows = 4;
  int64_t offsets_ms[kNumRmcatFlows];
  offsets_ms[0] = random_.Rand(2 * kAverageOffsetMs);
  for (int i = 1; i < kNumRmcatFlows; ++i) {
    offsets_ms[i] = offsets_ms[i - 1] + random_.Rand(2 * kAverageOffsetMs);
  }
  RunFairnessTest(GetParam(), 4, 0, 1000, 3000, 1000, 50, 0, offsets_ms);
}

TEST_P(BweSimulation, TcpFairness50msTest) {
  const int64_t kAverageOffsetMs = 20 * 1000;
  int64_t offset_ms[] = {random_.Rand(2 * kAverageOffsetMs), 0};
  RunFairnessTest(GetParam(), 1, 1, 1000, 2000, 50, 50, 0, offset_ms);
}

TEST_P(BweSimulation, TcpFairness500msTest) {
  const int64_t kAverageOffsetMs = 20 * 1000;
  int64_t offset_ms[] = {random_.Rand(2 * kAverageOffsetMs), 0};
  RunFairnessTest(GetParam(), 1, 1, 1000, 2000, 500, 50, 0, offset_ms);
}

TEST_P(BweSimulation, TcpFairness1000msTest) {
  const int kAverageOffsetMs = 20 * 1000;
  int64_t offset_ms[] = {random_.Rand(2 * kAverageOffsetMs), 0};
  RunFairnessTest(GetParam(), 1, 1, 1000, 2000, 1000, 50, 0, offset_ms);
}

// The following test cases begin with "Evaluation" as a referrence to the
// Internet draft https://tools.ietf.org/html/draft-ietf-rmcat-eval-test-01.

TEST_P(BweSimulation, Evaluation1) {
  RunVariableCapacity1SingleFlow(GetParam());
}

TEST_P(BweSimulation, Evaluation2) {
  const size_t kNumFlows = 2;
  RunVariableCapacity2MultipleFlows(GetParam(), kNumFlows);
}

TEST_P(BweSimulation, Evaluation3) {
  RunBidirectionalFlow(GetParam());
}

TEST_P(BweSimulation, Evaluation4) {
  RunSelfFairness(GetParam());
}

TEST_P(BweSimulation, Evaluation5) {
  RunRoundTripTimeFairness(GetParam());
}

TEST_P(BweSimulation, Evaluation6) {
  RunLongTcpFairness(GetParam());
}

// Different calls to the Evaluation7 will create the same FileSizes
// and StartingTimes as long as the seeds remain unchanged. This is essential
// when calling it with multiple estimators for comparison purposes.
TEST_P(BweSimulation, Evaluation7) {
  const int kNumTcpFiles = 10;
  RunMultipleShortTcpFairness(GetParam(),
                              BweTest::GetFileSizesBytes(kNumTcpFiles),
                              BweTest::GetStartingTimesMs(kNumTcpFiles));
}

TEST_P(BweSimulation, Evaluation8) {
  RunPauseResumeFlows(GetParam());
}

// Following test cases begin with "GccComparison" run the
// evaluation test cases for both GCC and other calling RMCAT.

TEST_P(BweSimulation, GccComparison1) {
  RunVariableCapacity1SingleFlow(GetParam());
  BweTest gcc_test(false);
  gcc_test.RunVariableCapacity1SingleFlow(kFullSendSideEstimator);
}

TEST_P(BweSimulation, GccComparison2) {
  const size_t kNumFlows = 2;
  RunVariableCapacity2MultipleFlows(GetParam(), kNumFlows);
  BweTest gcc_test(false);
  gcc_test.RunVariableCapacity2MultipleFlows(kFullSendSideEstimator, kNumFlows);
}

TEST_P(BweSimulation, GccComparison3) {
  RunBidirectionalFlow(GetParam());
  BweTest gcc_test(false);
  gcc_test.RunBidirectionalFlow(kFullSendSideEstimator);
}

TEST_P(BweSimulation, GccComparison4) {
  RunSelfFairness(GetParam());
  BweTest gcc_test(false);
  gcc_test.RunSelfFairness(GetParam());
}

TEST_P(BweSimulation, GccComparison5) {
  RunRoundTripTimeFairness(GetParam());
  BweTest gcc_test(false);
  gcc_test.RunRoundTripTimeFairness(kFullSendSideEstimator);
}

TEST_P(BweSimulation, GccComparison6) {
  RunLongTcpFairness(GetParam());
  BweTest gcc_test(false);
  gcc_test.RunLongTcpFairness(kFullSendSideEstimator);
}

TEST_P(BweSimulation, GccComparison7) {
  const int kNumTcpFiles = 10;

  std::vector<int> tcp_file_sizes_bytes =
      BweTest::GetFileSizesBytes(kNumTcpFiles);
  std::vector<int64_t> tcp_starting_times_ms =
      BweTest::GetStartingTimesMs(kNumTcpFiles);

  RunMultipleShortTcpFairness(GetParam(), tcp_file_sizes_bytes,
                              tcp_starting_times_ms);

  BweTest gcc_test(false);
  gcc_test.RunMultipleShortTcpFairness(
      kFullSendSideEstimator, tcp_file_sizes_bytes, tcp_starting_times_ms);
}

TEST_P(BweSimulation, GccComparison8) {
  RunPauseResumeFlows(GetParam());
  BweTest gcc_test(false);
  gcc_test.RunPauseResumeFlows(kFullSendSideEstimator);
}

TEST_P(BweSimulation, GccComparisonChoke) {
  int array[] = {1000, 500, 1000};
  std::vector<int> capacities_kbps(array, array + 3);
  RunChoke(GetParam(), capacities_kbps);

  BweTest gcc_test(false);
  gcc_test.RunChoke(kFullSendSideEstimator, capacities_kbps);
}

#endif  // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
}  // namespace bwe
}  // namespace testing
}  // namespace webrtc