webrtc/call/simulated_network.h
Rasmus Brandt baf5c9fabd Revert "Add documentation, tests and simplify webrtc::SimulatedNetwork."
This reverts commit c1d5fda22c.

Reason for revert: This CL created thousands of metric alerts in the perf tests. It's possible that these are all expected, but since mbonadei@ is OOO right now, I think it's better to revert, and have him re-land when he is back.

Most alerts are here: https://bugs.chromium.org/p/webrtc/issues/detail?id=14549

Original change's description:
> Add documentation, tests and simplify webrtc::SimulatedNetwork.
>
> This CL increases the test coverage for webrtc::SimualtedNetwork, adds
> some more comments to the class and the interface it implements and
> simplify the logic around capacity and delay management in the
> simulated network.
>
> More CLs will follow to continue the refactoring but this is the
> ground work to make this more modular in the future.
>
> Bug: webrtc:14525, b/243202138
> Change-Id: Ib0408cf6e2c1cdceb71f8bec3202d2960c5b4d3c
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/278042
> Reviewed-by: Artem Titov <titovartem@webrtc.org>
> Reviewed-by: Per Kjellander <perkj@webrtc.org>
> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Reviewed-by: Björn Terelius <terelius@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#38388}

Bug: webrtc:14525, b/243202138
Change-Id: I5bc56c954bb12e7c27cb859e838f0b7a89e006f8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279522
Owners-Override: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38415}
2022-10-17 13:11:34 +00:00

101 lines
3.4 KiB
C++

/*
* Copyright 2018 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.
*/
#ifndef CALL_SIMULATED_NETWORK_H_
#define CALL_SIMULATED_NETWORK_H_
#include <stdint.h>
#include <deque>
#include <queue>
#include <vector>
#include "absl/types/optional.h"
#include "api/sequence_checker.h"
#include "api/test/simulated_network.h"
#include "api/units/data_size.h"
#include "api/units/timestamp.h"
#include "rtc_base/race_checker.h"
#include "rtc_base/random.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
// Class simulating 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 SimulatedNetwork : public SimulatedNetworkInterface {
public:
using Config = BuiltInNetworkBehaviorConfig;
explicit SimulatedNetwork(Config config, uint64_t random_seed = 1);
~SimulatedNetwork() override;
// Sets a new configuration. This won't affect packets already in the pipe.
void SetConfig(const Config& config) override;
void UpdateConfig(std::function<void(BuiltInNetworkBehaviorConfig*)>
config_modifier) override;
void PauseTransmissionUntil(int64_t until_us) override;
// NetworkBehaviorInterface
bool EnqueuePacket(PacketInFlightInfo packet) override;
std::vector<PacketDeliveryInfo> DequeueDeliverablePackets(
int64_t receive_time_us) override;
absl::optional<int64_t> NextDeliveryTimeUs() const override;
private:
struct PacketInfo {
PacketInFlightInfo packet;
int64_t arrival_time_us;
};
// Contains current configuration state.
struct ConfigState {
// Static link configuration.
Config config;
// 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;
// Used for temporary delay spikes.
int64_t pause_transmission_until_us = 0;
};
// Moves packets from capacity- to delay link.
void UpdateCapacityQueue(ConfigState state, int64_t time_now_us)
RTC_RUN_ON(&process_checker_);
ConfigState GetConfigState() const;
mutable Mutex config_lock_;
// `process_checker_` guards the data structures involved in delay and loss
// processes, such as the packet queues.
rtc::RaceChecker process_checker_;
std::queue<PacketInfo> capacity_link_ RTC_GUARDED_BY(process_checker_);
Random random_;
std::deque<PacketInfo> delay_link_ RTC_GUARDED_BY(process_checker_);
ConfigState config_state_ RTC_GUARDED_BY(config_lock_);
// Are we currently dropping a burst of packets?
bool bursting_;
int64_t queue_size_bytes_ RTC_GUARDED_BY(process_checker_) = 0;
int64_t pending_drain_bits_ RTC_GUARDED_BY(process_checker_) = 0;
absl::optional<int64_t> last_capacity_link_visit_us_
RTC_GUARDED_BY(process_checker_);
absl::optional<int64_t> next_process_time_us_
RTC_GUARDED_BY(process_checker_);
};
} // namespace webrtc
#endif // CALL_SIMULATED_NETWORK_H_