Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m54s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 12m33s
Foundation / checks (network) (push) Canceled after 10m23s
Foundation / checks (client) (push) Canceled after 12m33s
evo-motion-trace drives the engineering client's own session code through the owned impairment relay against a real-time 50 ms loopback region: exact without loss, 94-99 % exact at 60-200 ms RTT with 2-5 % loss, every profile converging after stopping, restart resync about 2-3 s (docs/networking/M10_PREDICTION_TRACES.md). The CTest motion-trace-smoke checks convergence, bounds and a majority of exact predictions. The relay lets a new sender take over after the current client has been silent for 1 s (reconnects); the client counts refusal receipts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
2.0 KiB
C++
45 lines
2.0 KiB
C++
#pragma once
|
|
// M10.2 owned UDP impairment relay (ADR-0090) for tests and measurements; never shipped.
|
|
// Listens on 127.0.0.1:<port> for one client at a time (a new sender takes over after the
|
|
// current one has been silent for 1 s: a reconnect) and forwards to 127.0.0.1:<target>, applying
|
|
// seeded loss, duplication, reordering, delay/jitter, a payload-size (MTU) limit and
|
|
// corruption to each packet in each direction. Impairment decisions come from SplitMix64
|
|
// in packet order; wall-clock delivery times are not deterministic. Runs its own thread.
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
|
|
namespace evo::network::impair {
|
|
struct Impairment {
|
|
double loss{}; // Probability a packet is dropped.
|
|
double duplicate{}; // Probability a packet is sent twice.
|
|
double reorder{}; // Probability a packet is held back by `reorder_delay`.
|
|
double corrupt{}; // Probability one byte is flipped.
|
|
std::chrono::milliseconds delay{}, jitter{}, reorder_delay{10};
|
|
std::size_t max_payload{65507}; // Larger UDP payloads are dropped (path MTU).
|
|
};
|
|
struct RelayCounters {
|
|
std::uint64_t forwarded{}, dropped{}, duplicated{}, reordered{}, corrupted{}, oversized{};
|
|
};
|
|
class UdpRelay {
|
|
public:
|
|
// Upstream (client -> server) and downstream (server -> client) impairments.
|
|
[[nodiscard]] static std::unique_ptr<UdpRelay> start(std::uint16_t target_port,
|
|
Impairment upstream, Impairment downstream,
|
|
std::uint64_t seed);
|
|
UdpRelay(const UdpRelay&) = delete;
|
|
UdpRelay& operator=(const UdpRelay&) = delete;
|
|
~UdpRelay();
|
|
[[nodiscard]] std::uint16_t port() const noexcept;
|
|
// Changes impairments while running (e.g. a total outage to exercise idle timeout).
|
|
void set(Impairment upstream, Impairment downstream);
|
|
[[nodiscard]] RelayCounters counters() const;
|
|
|
|
struct Impl;
|
|
|
|
private:
|
|
explicit UdpRelay(std::unique_ptr<Impl> impl);
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
} // namespace evo::network::impair
|