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

Unified Diff: remoting/test/fake_network_dispatcher.cc

Issue 427613005: Implement network performance simulation for remoting perf tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | « remoting/test/fake_network_dispatcher.h ('k') | remoting/test/fake_network_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/test/fake_network_dispatcher.cc
diff --git a/remoting/test/fake_network_dispatcher.cc b/remoting/test/fake_network_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2076abb04b4b14fbbcfd7742635cab19b14e235
--- /dev/null
+++ b/remoting/test/fake_network_dispatcher.cc
@@ -0,0 +1,88 @@
+// 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.
+
+#include "remoting/test/fake_network_dispatcher.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
+#include "net/base/io_buffer.h"
+
+namespace remoting {
+
+FakeNetworkDispatcher::FakeNetworkDispatcher()
+ : allocated_address_(0) {
+}
+
+FakeNetworkDispatcher::~FakeNetworkDispatcher() {
+ CHECK(nodes_.empty());
+}
+
+rtc::IPAddress FakeNetworkDispatcher::AllocateAddress() {
+ in6_addr addr;
+ memset(&addr, 0, sizeof(addr));
+
+ // fc00::/7 is reserved for unique local addresses.
+ addr.s6_addr[0] = 0xfc;
+
+ // Copy |allocated_address_| to the end of |addr|.
+ ++allocated_address_;
+ for (size_t i = 0; i < sizeof(allocated_address_); ++i) {
+ addr.s6_addr[15 - i] = (allocated_address_ >> (8 * i)) & 0xff;
+ }
+
+ return rtc::IPAddress(addr);
+}
+
+void FakeNetworkDispatcher::AddNode(Node* node) {
+ DCHECK(node->GetThread()->BelongsToCurrentThread());
+
+ base::AutoLock auto_lock(nodes_lock_);
+ DCHECK(nodes_.find(node->GetAddress()) == nodes_.end());
+ nodes_[node->GetAddress()] = node;
+}
+
+void FakeNetworkDispatcher::RemoveNode(Node* node) {
+ DCHECK(node->GetThread()->BelongsToCurrentThread());
+
+ base::AutoLock auto_lock(nodes_lock_);
+ DCHECK(nodes_[node->GetAddress()] == node);
+ nodes_.erase(node->GetAddress());
+}
+
+void FakeNetworkDispatcher::DeliverPacket(
+ const rtc::SocketAddress& from,
+ const rtc::SocketAddress& to,
+ const scoped_refptr<net::IOBuffer>& data,
+ int data_size) {
+ Node* node;
+ {
+ base::AutoLock auto_lock(nodes_lock_);
+
+ NodesMap::iterator node_it = nodes_.find(to.ipaddr());
+ if (node_it == nodes_.end()) {
+ LOG(ERROR) << "Tried to deliver packet to unknown target: "
+ << to.ToString();
+ return;
+ }
+
+ node = node_it->second;
+
+ // Check if |node| belongs to a different thread and post a task in that
+ // case.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner = node->GetThread();
+ if (!task_runner->BelongsToCurrentThread()) {
+ task_runner->PostTask(FROM_HERE,
+ base::Bind(&FakeNetworkDispatcher::DeliverPacket,
+ this, from, to, data, data_size));
+ return;
+ }
+ }
+
+ // Call ReceivePacket() without lock held. It's safe because at this point we
+ // know that |node| belongs to the current thread.
+ node->ReceivePacket(from, to, data, data_size);
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/test/fake_network_dispatcher.h ('k') | remoting/test/fake_network_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698