| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_TEST_FAKE_SOCKET_FACTORY_H_ | 5 #ifndef REMOTING_TEST_FAKE_SOCKET_FACTORY_H_ |
| 6 #define REMOTING_TEST_FAKE_SOCKET_FACTORY_H_ | 6 #define REMOTING_TEST_FAKE_SOCKET_FACTORY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // l = NormalRand(average, stddev) + bytes_buffered / bandwidth . | 46 // l = NormalRand(average, stddev) + bytes_buffered / bandwidth . |
| 47 // | 47 // |
| 48 // Where bytes_buffered is the current level in the leaky bucket used to | 48 // Where bytes_buffered is the current level in the leaky bucket used to |
| 49 // control bandwidth. | 49 // control bandwidth. |
| 50 void SetLatency(base::TimeDelta average, base::TimeDelta stddev); | 50 void SetLatency(base::TimeDelta average, base::TimeDelta stddev); |
| 51 | 51 |
| 52 void set_out_of_order_rate(double out_of_order_rate) { | 52 void set_out_of_order_rate(double out_of_order_rate) { |
| 53 out_of_order_rate_ = out_of_order_rate; | 53 out_of_order_rate_ = out_of_order_rate; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ResetStats(); |
| 57 |
| 58 base::TimeDelta average_buffer_delay() { |
| 59 return total_packets_received_ > 0 |
| 60 ? (total_buffer_delay_ / total_packets_received_) |
| 61 : base::TimeDelta(); |
| 62 } |
| 63 base::TimeDelta max_buffer_delay() { return max_buffer_delay_; } |
| 64 double drop_rate() { |
| 65 return static_cast<double>(total_packets_dropped_) / |
| 66 (total_packets_received_ + total_packets_dropped_); |
| 67 } |
| 68 |
| 56 // rtc::PacketSocketFactory interface. | 69 // rtc::PacketSocketFactory interface. |
| 57 rtc::AsyncPacketSocket* CreateUdpSocket( | 70 rtc::AsyncPacketSocket* CreateUdpSocket( |
| 58 const rtc::SocketAddress& local_address, | 71 const rtc::SocketAddress& local_address, |
| 59 uint16_t min_port, | 72 uint16_t min_port, |
| 60 uint16_t max_port) override; | 73 uint16_t max_port) override; |
| 61 rtc::AsyncPacketSocket* CreateServerTcpSocket( | 74 rtc::AsyncPacketSocket* CreateServerTcpSocket( |
| 62 const rtc::SocketAddress& local_address, | 75 const rtc::SocketAddress& local_address, |
| 63 uint16_t min_port, | 76 uint16_t min_port, |
| 64 uint16_t max_port, | 77 uint16_t max_port, |
| 65 int opts) override; | 78 int opts) override; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 std::unique_ptr<LeakyBucket> leaky_bucket_; | 125 std::unique_ptr<LeakyBucket> leaky_bucket_; |
| 113 base::TimeDelta latency_average_; | 126 base::TimeDelta latency_average_; |
| 114 base::TimeDelta latency_stddev_; | 127 base::TimeDelta latency_stddev_; |
| 115 double out_of_order_rate_; | 128 double out_of_order_rate_; |
| 116 | 129 |
| 117 UdpSocketsMap udp_sockets_; | 130 UdpSocketsMap udp_sockets_; |
| 118 uint16_t next_port_; | 131 uint16_t next_port_; |
| 119 | 132 |
| 120 std::list<PendingPacket> pending_packets_; | 133 std::list<PendingPacket> pending_packets_; |
| 121 | 134 |
| 135 int total_packets_received_ = 0; |
| 136 int total_packets_dropped_ = 0; |
| 137 base::TimeDelta total_buffer_delay_; |
| 138 base::TimeDelta max_buffer_delay_; |
| 139 |
| 122 base::WeakPtrFactory<FakePacketSocketFactory> weak_factory_; | 140 base::WeakPtrFactory<FakePacketSocketFactory> weak_factory_; |
| 123 | 141 |
| 124 DISALLOW_COPY_AND_ASSIGN(FakePacketSocketFactory); | 142 DISALLOW_COPY_AND_ASSIGN(FakePacketSocketFactory); |
| 125 }; | 143 }; |
| 126 | 144 |
| 127 } // namespace remoting | 145 } // namespace remoting |
| 128 | 146 |
| 129 #endif // REMOTING_TEST_FAKE_SOCKET_FACTORY_H_ | 147 #endif // REMOTING_TEST_FAKE_SOCKET_FACTORY_H_ |
| OLD | NEW |