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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/test/fake_network_pipe.cc » ('j') | webrtc/test/fake_network_pipe.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/test/fake_network_pipe.h
diff --git a/webrtc/test/fake_network_pipe.h b/webrtc/test/fake_network_pipe.h
index 1af63b074983a35746b1a364ab00eea91b708f75..d0b078cf4a3f43aeab6fcef85d322499bc9526ab 100644
--- a/webrtc/test/fake_network_pipe.h
+++ b/webrtc/test/fake_network_pipe.h
@@ -11,6 +11,8 @@
#ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
#define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
+#include <set>
+#include <string.h>
#include <queue>
#include "webrtc/base/constructormagic.h"
@@ -22,9 +24,42 @@ namespace webrtc {
class Clock;
class CriticalSectionWrapper;
-class NetworkPacket;
class PacketReceiver;
+class NetworkPacket {
+ public:
+ NetworkPacket(const uint8_t* data, size_t length, int64_t send_time,
+ int64_t arrival_time)
+ : data_(NULL),
+ data_length_(length),
+ send_time_(send_time),
+ arrival_time_(arrival_time) {
+ data_ = new uint8_t[length];
+ memcpy(data_, data, length);
+ }
+ ~NetworkPacket() {
+ delete [] data_;
+ }
+
+ uint8_t* data() const { return data_; }
+ size_t data_length() const { return data_length_; }
+ int64_t send_time() const { return send_time_; }
+ int64_t arrival_time() const { return arrival_time_; }
+ void IncrementArrivalTime(int64_t extra_delay) {
+ arrival_time_+= extra_delay;
+ }
+
+ private:
+ // The packet data.
+ uint8_t* data_;
stefan-webrtc 2016/01/20 10:57:33 Please change this to a scoped_ptr<uint8_t[]>, or
philipel 2016/01/20 14:22:57 Done.
+ // Length of data_.
+ size_t data_length_;
+ // The time the packet was sent out on the network.
+ const int64_t send_time_;
+ // The time the packet should arrive at the reciver.
+ int64_t arrival_time_;
+};
+
// Class faking a network link. This is a simple and naive solution just faking
// capacity and adding an extra transport delay in addition to the capacity
// introduced delay.
@@ -44,6 +79,8 @@ class FakeNetworkPipe {
int link_capacity_kbps = 0;
// Random packet loss.
int loss_percent = 0;
+ // If packets are allowed to be reordered.
+ bool allow_reordering = false;
};
FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config);
@@ -74,7 +111,13 @@ class FakeNetworkPipe {
mutable rtc::CriticalSection lock_;
PacketReceiver* packet_receiver_;
std::queue<NetworkPacket*> capacity_link_;
- std::queue<NetworkPacket*> delay_link_;
+
+ struct PacketArrivalTimeComperator {
stefan-webrtc 2016/01/20 10:57:33 Comparator
philipel 2016/01/20 14:22:57 Done.
+ bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) {
+ return p1->arrival_time() < p2->arrival_time();
+ }
+ };
+ std::multiset<NetworkPacket*, PacketArrivalTimeComperator> delay_link_;
stefan-webrtc 2016/01/20 10:57:33 Maybe add a comment on why this needs to be sorted
philipel 2016/01/20 14:22:57 Done.
// Link configuration.
Config config_;
« no previous file with comments | « no previous file | webrtc/test/fake_network_pipe.cc » ('j') | webrtc/test/fake_network_pipe.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698