Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: webrtc/test/fake_network_pipe.h

Issue 1606183002: Allow packets to be reordered in the fake network pipe. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ 11 #ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
12 #define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ 12 #define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
13 13
14 #include <set>
15 #include <string.h>
14 #include <queue> 16 #include <queue>
15 17
16 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/base/criticalsection.h" 19 #include "webrtc/base/criticalsection.h"
18 #include "webrtc/base/scoped_ptr.h" 20 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/typedefs.h" 21 #include "webrtc/typedefs.h"
20 22
21 namespace webrtc { 23 namespace webrtc {
22 24
23 class Clock; 25 class Clock;
24 class CriticalSectionWrapper; 26 class CriticalSectionWrapper;
25 class NetworkPacket;
26 class PacketReceiver; 27 class PacketReceiver;
27 28
29 class NetworkPacket {
30 public:
31 NetworkPacket(const uint8_t* data, size_t length, int64_t send_time,
32 int64_t arrival_time)
33 : data_(new uint8_t[length]),
34 data_length_(length),
35 send_time_(send_time),
36 arrival_time_(arrival_time) {
37 memcpy(data_.get(), data, length);
38 }
39
40 uint8_t* data() const { return data_.get(); }
41 size_t data_length() const { return data_length_; }
42 int64_t send_time() const { return send_time_; }
43 int64_t arrival_time() const { return arrival_time_; }
44 void IncrementArrivalTime(int64_t extra_delay) {
45 arrival_time_+= extra_delay;
46 }
47
48 private:
49 // The packet data.
50 rtc::scoped_ptr<uint8_t> data_;
51 // Length of data_.
52 size_t data_length_;
53 // The time the packet was sent out on the network.
54 const int64_t send_time_;
55 // The time the packet should arrive at the reciver.
stefan-webrtc 2016/01/25 13:16:57 s/reciver/receiver
philipel 2016/01/26 10:50:47 Done.
56 int64_t arrival_time_;
57 };
58
28 // Class faking a network link. This is a simple and naive solution just faking 59 // Class faking a network link. This is a simple and naive solution just faking
29 // capacity and adding an extra transport delay in addition to the capacity 60 // capacity and adding an extra transport delay in addition to the capacity
30 // introduced delay. 61 // introduced delay.
31 62
32 // TODO(mflodman) Add random and bursty packet loss. 63 // TODO(mflodman) Add random and bursty packet loss.
33 class FakeNetworkPipe { 64 class FakeNetworkPipe {
34 public: 65 public:
35 struct Config { 66 struct Config {
36 Config() {} 67 Config() {}
37 // Queue length in number of packets. 68 // Queue length in number of packets.
38 size_t queue_length_packets = 0; 69 size_t queue_length_packets = 0;
39 // Delay in addition to capacity induced delay. 70 // Delay in addition to capacity induced delay.
40 int queue_delay_ms = 0; 71 int queue_delay_ms = 0;
41 // Standard deviation of the extra delay. 72 // Standard deviation of the extra delay.
42 int delay_standard_deviation_ms = 0; 73 int delay_standard_deviation_ms = 0;
43 // Link capacity in kbps. 74 // Link capacity in kbps.
44 int link_capacity_kbps = 0; 75 int link_capacity_kbps = 0;
45 // Random packet loss. 76 // Random packet loss.
46 int loss_percent = 0; 77 int loss_percent = 0;
78 // If packets are allowed to be reordered.
79 bool allow_reordering = false;
47 }; 80 };
48 81
49 FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config); 82 FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config);
50 ~FakeNetworkPipe(); 83 ~FakeNetworkPipe();
51 84
52 // Must not be called in parallel with SendPacket or Process. 85 // Must not be called in parallel with SendPacket or Process.
53 void SetReceiver(PacketReceiver* receiver); 86 void SetReceiver(PacketReceiver* receiver);
54 87
55 // Sets a new configuration. This won't affect packets already in the pipe. 88 // Sets a new configuration. This won't affect packets already in the pipe.
56 void SetConfig(const FakeNetworkPipe::Config& config); 89 void SetConfig(const FakeNetworkPipe::Config& config);
(...skipping 10 matching lines...) Expand all
67 float PercentageLoss(); 100 float PercentageLoss();
68 int AverageDelay(); 101 int AverageDelay();
69 size_t dropped_packets() { return dropped_packets_; } 102 size_t dropped_packets() { return dropped_packets_; }
70 size_t sent_packets() { return sent_packets_; } 103 size_t sent_packets() { return sent_packets_; }
71 104
72 private: 105 private:
73 Clock* const clock_; 106 Clock* const clock_;
74 mutable rtc::CriticalSection lock_; 107 mutable rtc::CriticalSection lock_;
75 PacketReceiver* packet_receiver_; 108 PacketReceiver* packet_receiver_;
76 std::queue<NetworkPacket*> capacity_link_; 109 std::queue<NetworkPacket*> capacity_link_;
77 std::queue<NetworkPacket*> delay_link_; 110
111 // Since we need to access both the packet with the earliest and latest
112 // arrival time we need to use a multiset to keep all packets sorted,
113 // hence, we cannot use a priority queue.
stefan-webrtc 2016/01/25 13:16:57 I guess it's also a way to make sure that the pack
philipel 2016/01/26 10:50:47 The packets are always delivered in arrival time o
stefan-webrtc 2016/01/26 11:50:46 Yes, and that's one of the reasons why you need a
114 struct PacketArrivalTimeComparator {
115 bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) {
116 return p1->arrival_time() < p2->arrival_time();
117 }
118 };
119 std::multiset<NetworkPacket*, PacketArrivalTimeComparator> delay_link_;
78 120
79 // Link configuration. 121 // Link configuration.
80 Config config_; 122 Config config_;
81 123
82 // Statistics. 124 // Statistics.
83 size_t dropped_packets_; 125 size_t dropped_packets_;
84 size_t sent_packets_; 126 size_t sent_packets_;
85 int total_packet_delay_; 127 int total_packet_delay_;
86 128
87 int64_t next_process_time_; 129 int64_t next_process_time_;
88 130
89 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); 131 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe);
90 }; 132 };
91 133
92 } // namespace webrtc 134 } // namespace webrtc
93 135
94 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ 136 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/test/fake_network_pipe.cc » ('j') | webrtc/test/fake_network_pipe_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698