summaryrefslogtreecommitdiffstats
path: root/remoting/test/fake_socket_factory.h
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-16 08:12:32 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-16 08:13:46 +0000
commitc44593fa600ad351e927bc838d133b78928daf6e (patch)
tree5e5a7a46221ea64153fc9d9dd9afcafbebd761e6 /remoting/test/fake_socket_factory.h
parentc4f1833e9879510843bfe9ba595b56bd50f74106 (diff)
downloadchromium_src-c44593fa600ad351e927bc838d133b78928daf6e.zip
chromium_src-c44593fa600ad351e927bc838d133b78928daf6e.tar.gz
chromium_src-c44593fa600ad351e927bc838d133b78928daf6e.tar.bz2
Implement network performance simulation for remoting perf tests.
The new FakePacketSocketFactory allows to simulate fake network with given latency/bandwidth parameters. BUG=394067 Review URL: https://codereview.chromium.org/427613005 Cr-Commit-Position: refs/heads/master@{#290128} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290128 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/test/fake_socket_factory.h')
-rw-r--r--remoting/test/fake_socket_factory.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/remoting/test/fake_socket_factory.h b/remoting/test/fake_socket_factory.h
new file mode 100644
index 0000000..c7efdab
--- /dev/null
+++ b/remoting/test/fake_socket_factory.h
@@ -0,0 +1,123 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_TEST_FAKE_SOCKET_FACTORY_H_
+#define REMOTING_TEST_FAKE_SOCKET_FACTORY_H_
+
+#include <list>
+
+#include "base/callback_forward.h"
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "remoting/test/fake_network_dispatcher.h"
+#include "third_party/libjingle/source/talk/p2p/base/packetsocketfactory.h"
+
+namespace remoting {
+
+class FakeNetworkDispatcher;
+class LeakyBucket;
+
+class FakePacketSocketFactory : public rtc::PacketSocketFactory,
+ public FakeNetworkDispatcher::Node {
+ public:
+ // |dispatcher| must outlive the factory.
+ explicit FakePacketSocketFactory(FakeNetworkDispatcher* dispatcher);
+ virtual ~FakePacketSocketFactory();
+
+ void OnSocketDestroyed(int port);
+
+ // |bandwidth| - simulated link bandwidth in bytes/second. 0 indicates that
+ // bandwidth is unlimited.
+ // |max_buffer| - size of buffers in bytes. Ignored when |bandwidth| is 0.
+ void SetBandwidth(int bandwidth, int max_buffer);
+
+ // Specifies parameters for simulated network latency. Latency is generated
+ // with normal distribution around |average| with the given |stddev|. Random
+ // latency calculated based on these parameters is added to the buffering
+ // delay (which is calculated based on the parameters passed to
+ // SetBandwidth()). I.e. total latency for each packet is calculated using the
+ // following formula
+ //
+ // l = NormalRand(average, stddev) + bytes_buffered / bandwidth .
+ //
+ // Where bytes_buffered is the current level in the leaky bucket used to
+ // control bandwidth.
+ void SetLatency(base::TimeDelta average, base::TimeDelta stddev);
+
+ void set_out_of_order_rate(double out_of_order_rate) {
+ out_of_order_rate_ = out_of_order_rate;
+ }
+
+ // rtc::PacketSocketFactory interface.
+ virtual rtc::AsyncPacketSocket* CreateUdpSocket(
+ const rtc::SocketAddress& local_address,
+ int min_port, int max_port) OVERRIDE;
+ virtual rtc::AsyncPacketSocket* CreateServerTcpSocket(
+ const rtc::SocketAddress& local_address,
+ int min_port, int max_port,
+ int opts) OVERRIDE;
+ virtual rtc::AsyncPacketSocket* CreateClientTcpSocket(
+ const rtc::SocketAddress& local_address,
+ const rtc::SocketAddress& remote_address,
+ const rtc::ProxyInfo& proxy_info,
+ const std::string& user_agent,
+ int opts) OVERRIDE;
+ virtual rtc::AsyncResolverInterface* CreateAsyncResolver() OVERRIDE;
+
+ // FakeNetworkDispatcher::Node interface.
+ virtual const scoped_refptr<base::SingleThreadTaskRunner>& GetThread()
+ const OVERRIDE;
+ virtual const rtc::IPAddress& GetAddress() const OVERRIDE;
+ virtual void ReceivePacket(const rtc::SocketAddress& from,
+ const rtc::SocketAddress& to,
+ const scoped_refptr<net::IOBuffer>& data,
+ int data_size) OVERRIDE;
+
+ private:
+ struct PendingPacket {
+ PendingPacket();
+ PendingPacket(
+ const rtc::SocketAddress& from,
+ const rtc::SocketAddress& to,
+ const scoped_refptr<net::IOBuffer>& data,
+ int data_size);
+ ~PendingPacket();
+
+ rtc::SocketAddress from;
+ rtc::SocketAddress to;
+ scoped_refptr<net::IOBuffer> data;
+ int data_size;
+ };
+
+ typedef base::Callback<void(const rtc::SocketAddress& from,
+ const rtc::SocketAddress& to,
+ const scoped_refptr<net::IOBuffer>& data,
+ int data_size)> ReceiveCallback;
+ typedef std::map<uint16_t, ReceiveCallback> UdpSocketsMap;
+
+ void DoReceivePacket();
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ scoped_refptr<FakeNetworkDispatcher> dispatcher_;
+
+ rtc::IPAddress address_;
+
+ scoped_ptr<LeakyBucket> leaky_bucket_;
+ base::TimeDelta latency_average_;
+ base::TimeDelta latency_stddev_;
+ double out_of_order_rate_;
+
+ UdpSocketsMap udp_sockets_;
+ uint16_t next_port_;
+
+ std::list<PendingPacket> pending_packets_;
+
+ base::WeakPtrFactory<FakePacketSocketFactory> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakePacketSocketFactory);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_TEST_FAKE_SOCKET_FACTORY_H_