Home | History | Annotate | Download | only in test
      1 /*
      2  *  Copyright (c) 2013 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 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_H_
     12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_H_
     13 
     14 #include <map>
     15 #include <string>
     16 #include <vector>
     17 #include "testing/gtest/include/gtest/gtest.h"
     18 #include "webrtc/base/constructormagic.h"
     19 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
     20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h"
     21 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h"
     22 
     23 namespace webrtc {
     24 
     25 namespace testing {
     26 namespace bwe {
     27 
     28 class BweReceiver;
     29 class PacketReceiver;
     30 class PacketSender;
     31 
     32 class PacketProcessorRunner {
     33  public:
     34   explicit PacketProcessorRunner(PacketProcessor* processor);
     35   ~PacketProcessorRunner();
     36 
     37   bool RunsProcessor(const PacketProcessor* processor) const;
     38   void RunFor(int64_t time_ms, int64_t time_now_ms, Packets* in_out);
     39 
     40  private:
     41   void FindPacketsToProcess(const FlowIds& flow_ids, Packets* in, Packets* out);
     42   void QueuePackets(Packets* batch, int64_t end_of_batch_time_us);
     43 
     44   PacketProcessor* processor_;
     45   Packets queue_;
     46 };
     47 
     48 class Link : public PacketProcessorListener {
     49  public:
     50   virtual ~Link() {}
     51 
     52   virtual void AddPacketProcessor(PacketProcessor* processor,
     53                                   ProcessorType type);
     54   virtual void RemovePacketProcessor(PacketProcessor* processor);
     55 
     56   void Run(int64_t run_for_ms, int64_t now_ms, Packets* packets);
     57 
     58   const std::vector<PacketSender*>& senders() { return senders_; }
     59   const std::vector<PacketProcessorRunner>& processors() { return processors_; }
     60 
     61  private:
     62   std::vector<PacketSender*> senders_;
     63   std::vector<PacketReceiver*> receivers_;
     64   std::vector<PacketProcessorRunner> processors_;
     65 };
     66 
     67 class BweTest {
     68  public:
     69   BweTest();
     70   explicit BweTest(bool plot_capacity);
     71   ~BweTest();
     72 
     73   void RunChoke(BandwidthEstimatorType bwe_type,
     74                 std::vector<int> capacities_kbps);
     75 
     76   void RunVariableCapacity1SingleFlow(BandwidthEstimatorType bwe_type);
     77   void RunVariableCapacity2MultipleFlows(BandwidthEstimatorType bwe_type,
     78                                          size_t num_flows);
     79   void RunBidirectionalFlow(BandwidthEstimatorType bwe_type);
     80   void RunSelfFairness(BandwidthEstimatorType bwe_type);
     81   void RunRoundTripTimeFairness(BandwidthEstimatorType bwe_type);
     82   void RunLongTcpFairness(BandwidthEstimatorType bwe_type);
     83   void RunMultipleShortTcpFairness(BandwidthEstimatorType bwe_type,
     84                                    std::vector<int> tcp_file_sizes_bytes,
     85                                    std::vector<int64_t> tcp_starting_times_ms);
     86   void RunPauseResumeFlows(BandwidthEstimatorType bwe_type);
     87 
     88   void RunFairnessTest(BandwidthEstimatorType bwe_type,
     89                        size_t num_media_flows,
     90                        size_t num_tcp_flows,
     91                        int64_t run_time_seconds,
     92                        uint32_t capacity_kbps,
     93                        int64_t max_delay_ms,
     94                        int64_t rtt_ms,
     95                        int64_t max_jitter_ms,
     96                        const int64_t* offsets_ms);
     97 
     98   void RunFairnessTest(BandwidthEstimatorType bwe_type,
     99                        size_t num_media_flows,
    100                        size_t num_tcp_flows,
    101                        int64_t run_time_seconds,
    102                        uint32_t capacity_kbps,
    103                        int64_t max_delay_ms,
    104                        int64_t rtt_ms,
    105                        int64_t max_jitter_ms,
    106                        const int64_t* offsets_ms,
    107                        const std::string& title,
    108                        const std::string& flow_name);
    109 
    110   static std::vector<int> GetFileSizesBytes(int num_files);
    111   static std::vector<int64_t> GetStartingTimesMs(int num_files);
    112 
    113  protected:
    114   void SetUp();
    115 
    116   void VerboseLogging(bool enable);
    117   void RunFor(int64_t time_ms);
    118   std::string GetTestName() const;
    119 
    120   void PrintResults(double max_throughput_kbps,
    121                     Stats<double> throughput_kbps,
    122                     int flow_id,
    123                     Stats<double> flow_delay_ms,
    124                     Stats<double> flow_throughput_kbps);
    125 
    126   void PrintResults(double max_throughput_kbps,
    127                     Stats<double> throughput_kbps,
    128                     std::map<int, Stats<double>> flow_delay_ms,
    129                     std::map<int, Stats<double>> flow_throughput_kbps);
    130 
    131   Link downlink_;
    132   Link uplink_;
    133 
    134  private:
    135   void FindPacketsToProcess(const FlowIds& flow_ids, Packets* in,
    136                             Packets* out);
    137   void GiveFeedbackToAffectedSenders(PacketReceiver* receiver);
    138 
    139   int64_t run_time_ms_;
    140   int64_t time_now_ms_;
    141   int64_t simulation_interval_ms_;
    142   std::vector<Link*> links_;
    143   Packets packets_;
    144   bool plot_total_available_capacity_;
    145 
    146   RTC_DISALLOW_COPY_AND_ASSIGN(BweTest);
    147 };
    148 
    149 // Default Evaluation parameters:
    150 // Link capacity: 4000ms;
    151 // Queueing delay capacity: 300ms.
    152 // One-Way propagation delay: 50ms.
    153 // Jitter model: Truncated gaussian.
    154 // Maximum end-to-end jitter: 30ms = 2*standard_deviation.
    155 // Bottleneck queue type: Drop tail.
    156 // Path loss ratio: 0%.
    157 
    158 const int kOneWayDelayMs = 50;
    159 const int kMaxQueueingDelayMs = 300;
    160 const int kMaxCapacityKbps = 4000;
    161 const int kMaxJitterMs = 15;
    162 
    163 struct DefaultEvaluationFilter {
    164   DefaultEvaluationFilter(PacketProcessorListener* listener, int flow_id)
    165       : choke(listener, flow_id),
    166         delay(listener, flow_id),
    167         jitter(listener, flow_id) {
    168     SetDefaultParameters();
    169   }
    170 
    171   DefaultEvaluationFilter(PacketProcessorListener* listener,
    172                           const FlowIds& flow_ids)
    173       : choke(listener, flow_ids),
    174         delay(listener, flow_ids),
    175         jitter(listener, flow_ids) {
    176     SetDefaultParameters();
    177   }
    178 
    179   void SetDefaultParameters() {
    180     delay.SetOneWayDelayMs(kOneWayDelayMs);
    181     choke.set_max_delay_ms(kMaxQueueingDelayMs);
    182     choke.set_capacity_kbps(kMaxCapacityKbps);
    183     jitter.SetMaxJitter(kMaxJitterMs);
    184   }
    185 
    186   ChokeFilter choke;
    187   DelayFilter delay;
    188   JitterFilter jitter;
    189 };
    190 
    191 }  // namespace bwe
    192 }  // namespace testing
    193 }  // namespace webrtc
    194 
    195 #endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_TEST_H_
    196