OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 Socket* CreateSocket(int family, int type) override; | 105 Socket* CreateSocket(int family, int type) override; |
106 | 106 |
107 AsyncSocket* CreateAsyncSocket(int type) override; | 107 AsyncSocket* CreateAsyncSocket(int type) override; |
108 AsyncSocket* CreateAsyncSocket(int family, int type) override; | 108 AsyncSocket* CreateAsyncSocket(int family, int type) override; |
109 | 109 |
110 // SocketServer: | 110 // SocketServer: |
111 void SetMessageQueue(MessageQueue* queue) override; | 111 void SetMessageQueue(MessageQueue* queue) override; |
112 bool Wait(int cms, bool process_io) override; | 112 bool Wait(int cms, bool process_io) override; |
113 void WakeUp() override; | 113 void WakeUp() override; |
114 | 114 |
| 115 void SetDelayOnAddress(const rtc::SocketAddress& address, int delay_ms) { |
| 116 delay_by_ip_[address.ipaddr()] = delay_ms; |
| 117 } |
| 118 |
115 typedef std::pair<double, double> Point; | 119 typedef std::pair<double, double> Point; |
116 typedef std::vector<Point> Function; | 120 typedef std::vector<Point> Function; |
117 | 121 |
118 static Function* CreateDistribution(uint32_t mean, | 122 static Function* CreateDistribution(uint32_t mean, |
119 uint32_t stddev, | 123 uint32_t stddev, |
120 uint32_t samples); | 124 uint32_t samples); |
121 | 125 |
122 // Similar to Thread::ProcessMessages, but it only processes messages until | 126 // Similar to Thread::ProcessMessages, but it only processes messages until |
123 // there are no immediate messages or pending network traffic. Returns false | 127 // there are no immediate messages or pending network traffic. Returns false |
124 // if Thread::Stop() was called. | 128 // if Thread::Stop() was called. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 size_t data_size, | 191 size_t data_size, |
188 size_t header_size, | 192 size_t header_size, |
189 bool ordered); | 193 bool ordered); |
190 | 194 |
191 // Removes stale packets from the network | 195 // Removes stale packets from the network |
192 void PurgeNetworkPackets(VirtualSocket* socket, int64_t cur_time); | 196 void PurgeNetworkPackets(VirtualSocket* socket, int64_t cur_time); |
193 | 197 |
194 // Computes the number of milliseconds required to send a packet of this size. | 198 // Computes the number of milliseconds required to send a packet of this size. |
195 uint32_t SendDelay(uint32_t size); | 199 uint32_t SendDelay(uint32_t size); |
196 | 200 |
197 // Returns a random transit delay chosen from the appropriate distribution. | 201 // If the delay has been set for the address of the socket, returns the set |
198 uint32_t GetRandomTransitDelay(); | 202 // delay. Otherwise, returns a random transit delay chosen from the |
| 203 // appropriate distribution. |
| 204 uint32_t GetTransitDelay(Socket* socket); |
199 | 205 |
200 // Basic operations on functions. Those that return a function also take | 206 // Basic operations on functions. Those that return a function also take |
201 // ownership of the function given (and hence, may modify or delete it). | 207 // ownership of the function given (and hence, may modify or delete it). |
202 static Function* Accumulate(Function* f); | 208 static Function* Accumulate(Function* f); |
203 static Function* Invert(Function* f); | 209 static Function* Invert(Function* f); |
204 static Function* Resample(Function* f, | 210 static Function* Resample(Function* f, |
205 double x1, | 211 double x1, |
206 double x2, | 212 double x2, |
207 uint32_t samples); | 213 uint32_t samples); |
208 static double Evaluate(Function* f, double x); | 214 static double Evaluate(Function* f, double x); |
(...skipping 27 matching lines...) Expand all Loading... |
236 // Sending was previously blocked, but now isn't. | 242 // Sending was previously blocked, but now isn't. |
237 sigslot::signal0<> SignalReadyToSend; | 243 sigslot::signal0<> SignalReadyToSend; |
238 | 244 |
239 typedef std::map<SocketAddress, VirtualSocket*> AddressMap; | 245 typedef std::map<SocketAddress, VirtualSocket*> AddressMap; |
240 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap; | 246 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap; |
241 | 247 |
242 SocketServer* server_; | 248 SocketServer* server_; |
243 bool server_owned_; | 249 bool server_owned_; |
244 MessageQueue* msg_queue_; | 250 MessageQueue* msg_queue_; |
245 bool stop_on_idle_; | 251 bool stop_on_idle_; |
246 int64_t network_delay_; | |
247 in_addr next_ipv4_; | 252 in_addr next_ipv4_; |
248 in6_addr next_ipv6_; | 253 in6_addr next_ipv6_; |
249 uint16_t next_port_; | 254 uint16_t next_port_; |
250 AddressMap* bindings_; | 255 AddressMap* bindings_; |
251 ConnectionMap* connections_; | 256 ConnectionMap* connections_; |
252 | 257 |
253 IPAddress default_route_v4_; | 258 IPAddress default_route_v4_; |
254 IPAddress default_route_v6_; | 259 IPAddress default_route_v6_; |
255 | 260 |
256 uint32_t bandwidth_; | 261 uint32_t bandwidth_; |
257 uint32_t network_capacity_; | 262 uint32_t network_capacity_; |
258 uint32_t send_buffer_capacity_; | 263 uint32_t send_buffer_capacity_; |
259 uint32_t recv_buffer_capacity_; | 264 uint32_t recv_buffer_capacity_; |
260 uint32_t delay_mean_; | 265 uint32_t delay_mean_; |
261 uint32_t delay_stddev_; | 266 uint32_t delay_stddev_; |
262 uint32_t delay_samples_; | 267 uint32_t delay_samples_; |
263 Function* delay_dist_; | 268 |
| 269 std::map<rtc::IPAddress, int> delay_by_ip_; |
| 270 std::unique_ptr<Function> delay_dist_; |
| 271 |
264 CriticalSection delay_crit_; | 272 CriticalSection delay_crit_; |
265 | 273 |
266 double drop_prob_; | 274 double drop_prob_; |
267 bool sending_blocked_ = false; | 275 bool sending_blocked_ = false; |
268 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); | 276 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); |
269 }; | 277 }; |
270 | 278 |
271 // Implements the socket interface using the virtual network. Packets are | 279 // Implements the socket interface using the virtual network. Packets are |
272 // passed as messages using the message queue of the socket server. | 280 // passed as messages using the message queue of the socket server. |
273 class VirtualSocket : public AsyncSocket, | 281 class VirtualSocket : public AsyncSocket, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Set to false if the last attempt to send resulted in EWOULDBLOCK. | 359 // Set to false if the last attempt to send resulted in EWOULDBLOCK. |
352 // Set back to true when the socket can send again. | 360 // Set back to true when the socket can send again. |
353 bool ready_to_send_ = true; | 361 bool ready_to_send_ = true; |
354 | 362 |
355 // Critical section to protect the recv_buffer and queue_ | 363 // Critical section to protect the recv_buffer and queue_ |
356 CriticalSection crit_; | 364 CriticalSection crit_; |
357 | 365 |
358 // Network model that enforces bandwidth and capacity constraints | 366 // Network model that enforces bandwidth and capacity constraints |
359 NetworkQueue network_; | 367 NetworkQueue network_; |
360 size_t network_size_; | 368 size_t network_size_; |
| 369 // The scheduled delivery time of the last packet sent on this socket. |
| 370 // It is used to ensure ordered delivery of packets sent on this socket. |
| 371 int64_t last_delivery_time_ = 0; |
361 | 372 |
362 // Data which has been received from the network | 373 // Data which has been received from the network |
363 RecvBuffer recv_buffer_; | 374 RecvBuffer recv_buffer_; |
364 // The amount of data which is in flight or in recv_buffer_ | 375 // The amount of data which is in flight or in recv_buffer_ |
365 size_t recv_buffer_size_; | 376 size_t recv_buffer_size_; |
366 | 377 |
367 // Is this socket bound? | 378 // Is this socket bound? |
368 bool bound_; | 379 bool bound_; |
369 | 380 |
370 // When we bind a socket to Any, VSS's Bind gives it another address. For | 381 // When we bind a socket to Any, VSS's Bind gives it another address. For |
371 // dual-stack sockets, we want to distinguish between sockets that were | 382 // dual-stack sockets, we want to distinguish between sockets that were |
372 // explicitly given a particular address and sockets that had one picked | 383 // explicitly given a particular address and sockets that had one picked |
373 // for them by VSS. | 384 // for them by VSS. |
374 bool was_any_; | 385 bool was_any_; |
375 | 386 |
376 // Store the options that are set | 387 // Store the options that are set |
377 OptionsMap options_map_; | 388 OptionsMap options_map_; |
378 | 389 |
379 friend class VirtualSocketServer; | 390 friend class VirtualSocketServer; |
380 }; | 391 }; |
381 | 392 |
382 } // namespace rtc | 393 } // namespace rtc |
383 | 394 |
384 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ | 395 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ |
OLD | NEW |