2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
12 #define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_
16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/system_wrappers/interface/event_wrapper.h"
18 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
19 #include "webrtc/typedefs.h"
23 class CriticalSectionWrapper;
27 // Class faking a network link. This is a simple and naive solution just faking
28 // capacity and adding an extra transport delay in addition to the capacity
31 // TODO(mflodman) Add random and bursty packet loss.
32 class FakeNetworkPipe {
36 : queue_length_packets(0),
38 delay_standard_deviation_ms(0),
39 link_capacity_kbps(0),
42 // Queue length in number of packets.
43 size_t queue_length_packets;
44 // Delay in addition to capacity induced delay.
46 // Standard deviation of the extra delay.
47 int delay_standard_deviation_ms;
48 // Link capacity in kbps.
49 int link_capacity_kbps;
50 // Random packet loss.
54 explicit FakeNetworkPipe(const FakeNetworkPipe::Config& config);
57 // Must not be called in parallel with SendPacket or Process.
58 void SetReceiver(PacketReceiver* receiver);
60 // Sets a new configuration. This won't affect packets already in the pipe.
61 void SetConfig(const FakeNetworkPipe::Config& config);
63 // Sends a new packet to the link.
64 void SendPacket(const uint8_t* packet, size_t packet_length);
66 // Processes the network queues and trigger PacketReceiver::IncomingPacket for
67 // packets ready to be delivered.
69 int TimeUntilNextProcess() const;
72 float PercentageLoss();
74 size_t dropped_packets() { return dropped_packets_; }
75 size_t sent_packets() { return sent_packets_; }
78 scoped_ptr<CriticalSectionWrapper> lock_;
79 PacketReceiver* packet_receiver_;
80 std::queue<NetworkPacket*> capacity_link_;
81 std::queue<NetworkPacket*> delay_link_;
83 // Link configuration.
87 size_t dropped_packets_;
89 int total_packet_delay_;
91 int64_t next_process_time_;
93 DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe);
98 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_