2012-12-11 11:47:22 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef TEST_FAKE_NETWORK_PIPE_H_
|
|
|
|
|
#define TEST_FAKE_NETWORK_PIPE_H_
|
2012-12-11 11:47:22 +00:00
|
|
|
|
2016-01-26 08:41:53 -08:00
|
|
|
#include <string.h>
|
2017-04-10 16:57:57 -07:00
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
2012-12-11 11:47:22 +00:00
|
|
|
#include <queue>
|
2017-04-10 16:57:57 -07:00
|
|
|
#include <set>
|
2012-12-11 11:47:22 +00:00
|
|
|
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/constructormagic.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/random.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2012-12-11 11:47:22 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-12-09 11:20:58 +01:00
|
|
|
class Clock;
|
2013-12-18 20:28:25 +00:00
|
|
|
class PacketReceiver;
|
Reland of Don't hardcode MediaType::ANY in FakeNetworkPipe. (patchset #1 id:1 of https://codereview.webrtc.org/2784543002/ )
Reason for revert:
Intend to fix perf failures and reland.
Original issue's description:
> Revert of Don't hardcode MediaType::ANY in FakeNetworkPipe. (patchset #4 id:60001 of https://codereview.webrtc.org/2774463003/ )
>
> Reason for revert:
> Reverting since this seems to break multiple WebRTC Perf buildbots
>
> Original issue's description:
> > Don't hardcode MediaType::ANY in FakeNetworkPipe.
> >
> > Instead let each test set the appropriate media type. This simplifies
> > demuxing in Call and later in RtpTransportController.
> >
> > BUG=webrtc:7135
> >
> > Review-Url: https://codereview.webrtc.org/2774463003
> > Cr-Commit-Position: refs/heads/master@{#17418}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/9c47b00e24da2941eb095df5a4459c6d98a8a88d
>
> TBR=stefan@webrtc.org,deadbeef@webrtc.org,solenberg@webrtc.org,pbos@webrtc.org,sprang@webrtc.org,nisse@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:7135
>
> Review-Url: https://codereview.webrtc.org/2784543002
> Cr-Commit-Position: refs/heads/master@{#17427}
> Committed: https://chromium.googlesource.com/external/webrtc/+/3a3bd5061089da5327fc549337a8430054d66057
TBR=stefan@webrtc.org,deadbeef@webrtc.org,solenberg@webrtc.org,pbos@webrtc.org,sprang@webrtc.org,lliuu@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7135
Review-Url: https://codereview.webrtc.org/2783853002
Cr-Commit-Position: refs/heads/master@{#17459}
2017-03-29 23:57:43 -07:00
|
|
|
enum class MediaType;
|
2012-12-11 11:47:22 +00:00
|
|
|
|
2016-01-26 08:41:53 -08:00
|
|
|
class NetworkPacket {
|
|
|
|
|
public:
|
|
|
|
|
NetworkPacket(const uint8_t* data,
|
|
|
|
|
size_t length,
|
|
|
|
|
int64_t send_time,
|
|
|
|
|
int64_t arrival_time)
|
|
|
|
|
: data_(new uint8_t[length]),
|
|
|
|
|
data_length_(length),
|
|
|
|
|
send_time_(send_time),
|
|
|
|
|
arrival_time_(arrival_time) {
|
|
|
|
|
memcpy(data_.get(), data, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t* data() const { return data_.get(); }
|
|
|
|
|
size_t data_length() const { return data_length_; }
|
|
|
|
|
int64_t send_time() const { return send_time_; }
|
|
|
|
|
int64_t arrival_time() const { return arrival_time_; }
|
|
|
|
|
void IncrementArrivalTime(int64_t extra_delay) {
|
|
|
|
|
arrival_time_ += extra_delay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// The packet data.
|
2016-05-01 14:53:46 -07:00
|
|
|
std::unique_ptr<uint8_t[]> data_;
|
2016-01-26 08:41:53 -08:00
|
|
|
// Length of data_.
|
|
|
|
|
size_t data_length_;
|
|
|
|
|
// The time the packet was sent out on the network.
|
|
|
|
|
const int64_t send_time_;
|
|
|
|
|
// The time the packet should arrive at the receiver.
|
|
|
|
|
int64_t arrival_time_;
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-10 16:57:57 -07:00
|
|
|
class Demuxer {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~Demuxer() = default;
|
|
|
|
|
virtual void SetReceiver(PacketReceiver* receiver) = 0;
|
|
|
|
|
virtual void DeliverPacket(const NetworkPacket* packet,
|
|
|
|
|
const PacketTime& packet_time) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DemuxerImpl final : public Demuxer {
|
|
|
|
|
public:
|
|
|
|
|
explicit DemuxerImpl(const std::map<uint8_t, MediaType>& payload_type_map);
|
|
|
|
|
|
|
|
|
|
void SetReceiver(PacketReceiver* receiver) override;
|
|
|
|
|
void DeliverPacket(const NetworkPacket* packet,
|
|
|
|
|
const PacketTime& packet_time) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PacketReceiver* packet_receiver_;
|
|
|
|
|
const std::map<uint8_t, MediaType> payload_type_map_;
|
|
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(DemuxerImpl);
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-11 11:47:22 +00:00
|
|
|
// Class faking a network link. This is a simple and naive solution just faking
|
|
|
|
|
// capacity and adding an extra transport delay in addition to the capacity
|
|
|
|
|
// introduced delay.
|
|
|
|
|
|
|
|
|
|
class FakeNetworkPipe {
|
|
|
|
|
public:
|
2013-12-18 20:28:25 +00:00
|
|
|
struct Config {
|
2015-12-09 11:20:58 +01:00
|
|
|
Config() {}
|
2013-12-18 20:28:25 +00:00
|
|
|
// Queue length in number of packets.
|
2015-12-09 11:20:58 +01:00
|
|
|
size_t queue_length_packets = 0;
|
2012-12-13 15:53:11 +00:00
|
|
|
// Delay in addition to capacity induced delay.
|
2015-12-09 11:20:58 +01:00
|
|
|
int queue_delay_ms = 0;
|
2012-12-13 15:53:11 +00:00
|
|
|
// Standard deviation of the extra delay.
|
2015-12-09 11:20:58 +01:00
|
|
|
int delay_standard_deviation_ms = 0;
|
2012-12-13 15:53:11 +00:00
|
|
|
// Link capacity in kbps.
|
2015-12-09 11:20:58 +01:00
|
|
|
int link_capacity_kbps = 0;
|
2014-07-31 12:30:18 +00:00
|
|
|
// Random packet loss.
|
2015-12-09 11:20:58 +01:00
|
|
|
int loss_percent = 0;
|
2016-01-26 08:41:53 -08:00
|
|
|
// If packets are allowed to be reordered.
|
|
|
|
|
bool allow_reordering = false;
|
2016-05-31 03:20:23 -07:00
|
|
|
// The average length of a burst of lost packets.
|
|
|
|
|
int avg_burst_loss_length = -1;
|
2012-12-13 15:53:11 +00:00
|
|
|
};
|
|
|
|
|
|
2016-01-26 08:41:53 -08:00
|
|
|
FakeNetworkPipe(Clock* clock,
|
2017-04-10 16:57:57 -07:00
|
|
|
const FakeNetworkPipe::Config& config,
|
|
|
|
|
std::unique_ptr<Demuxer> demuxer);
|
|
|
|
|
FakeNetworkPipe(Clock* clock,
|
|
|
|
|
const FakeNetworkPipe::Config& config,
|
|
|
|
|
std::unique_ptr<Demuxer> demuxer,
|
2016-01-26 08:41:53 -08:00
|
|
|
uint64_t seed);
|
2017-10-24 16:26:49 +02:00
|
|
|
virtual ~FakeNetworkPipe();
|
2013-12-18 20:28:25 +00:00
|
|
|
|
2014-02-26 13:34:52 +00:00
|
|
|
// Sets a new configuration. This won't affect packets already in the pipe.
|
|
|
|
|
void SetConfig(const FakeNetworkPipe::Config& config);
|
|
|
|
|
|
2012-12-11 11:47:22 +00:00
|
|
|
// Sends a new packet to the link.
|
2017-10-24 16:26:49 +02:00
|
|
|
virtual void SendPacket(const uint8_t* packet, size_t packet_length);
|
2012-12-11 11:47:22 +00:00
|
|
|
|
2017-04-10 16:57:57 -07:00
|
|
|
// Must not be called in parallel with SendPacket or Process.
|
|
|
|
|
void SetReceiver(PacketReceiver* receiver);
|
|
|
|
|
|
2012-12-11 11:47:22 +00:00
|
|
|
// Processes the network queues and trigger PacketReceiver::IncomingPacket for
|
|
|
|
|
// packets ready to be delivered.
|
2017-10-24 16:26:49 +02:00
|
|
|
virtual void Process();
|
2014-12-15 22:09:40 +00:00
|
|
|
int64_t TimeUntilNextProcess() const;
|
2012-12-11 11:47:22 +00:00
|
|
|
|
|
|
|
|
// Get statistics.
|
|
|
|
|
float PercentageLoss();
|
|
|
|
|
int AverageDelay();
|
2013-12-18 20:28:25 +00:00
|
|
|
size_t dropped_packets() { return dropped_packets_; }
|
|
|
|
|
size_t sent_packets() { return sent_packets_; }
|
2012-12-11 11:47:22 +00:00
|
|
|
|
2017-10-24 16:26:49 +02:00
|
|
|
protected:
|
2015-12-09 11:20:58 +01:00
|
|
|
Clock* const clock_;
|
2016-01-25 03:52:44 -08:00
|
|
|
rtc::CriticalSection lock_;
|
2017-04-10 16:57:57 -07:00
|
|
|
const std::unique_ptr<Demuxer> demuxer_;
|
2012-12-11 11:47:22 +00:00
|
|
|
std::queue<NetworkPacket*> capacity_link_;
|
2016-01-26 08:41:53 -08:00
|
|
|
Random random_;
|
|
|
|
|
|
|
|
|
|
// Since we need to access both the packet with the earliest and latest
|
|
|
|
|
// arrival time we need to use a multiset to keep all packets sorted,
|
|
|
|
|
// hence, we cannot use a priority queue.
|
|
|
|
|
struct PacketArrivalTimeComparator {
|
|
|
|
|
bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) {
|
|
|
|
|
return p1->arrival_time() < p2->arrival_time();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
std::multiset<NetworkPacket*, PacketArrivalTimeComparator> delay_link_;
|
2012-12-11 11:47:22 +00:00
|
|
|
|
|
|
|
|
// Link configuration.
|
2013-12-18 20:28:25 +00:00
|
|
|
Config config_;
|
2012-12-11 11:47:22 +00:00
|
|
|
|
|
|
|
|
// Statistics.
|
2013-12-18 20:28:25 +00:00
|
|
|
size_t dropped_packets_;
|
|
|
|
|
size_t sent_packets_;
|
2016-01-14 10:00:21 +01:00
|
|
|
int64_t total_packet_delay_;
|
2012-12-11 11:47:22 +00:00
|
|
|
|
2016-05-31 03:20:23 -07:00
|
|
|
// Are we currently dropping a burst of packets?
|
|
|
|
|
bool bursting_;
|
|
|
|
|
|
|
|
|
|
// The probability to drop the packet if we are currently dropping a
|
|
|
|
|
// burst of packet
|
|
|
|
|
double prob_loss_bursting_;
|
|
|
|
|
|
|
|
|
|
// The probability to drop a burst of packets.
|
|
|
|
|
double prob_start_bursting_;
|
|
|
|
|
|
2013-12-18 20:28:25 +00:00
|
|
|
int64_t next_process_time_;
|
|
|
|
|
|
2017-02-10 06:09:28 -08:00
|
|
|
int64_t last_log_time_;
|
|
|
|
|
|
2017-09-07 09:08:50 -07:00
|
|
|
int64_t capacity_delay_error_bytes_ = 0;
|
|
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe);
|
2012-12-11 11:47:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // TEST_FAKE_NETWORK_PIPE_H_
|