|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file. 1 #ifndef SPONGE_LIBSPONGE_LOSSY_FD_ADAPTER_HH
2 #define SPONGE_LIBSPONGE_LOSSY_FD_ADAPTER_HH
14 template <
typename AdapterT>
28 const uint16_t loss = uplink ? cfg.loss_rate_up : cfg.loss_rate_dn;
29 return loss != 0 && uint16_t(
_rand()) < loss;
42 std::optional<TCPSegment>
read() {
63 void set_listening(
const bool l) {
_adapter.set_listening(l); }
66 void tick(
const size_t ms_since_last_tick) {
72 #endif // SPONGE_LIBSPONGE_LOSSY_FD_ADAPTER_HH
std::optional< TCPSegment > read()
Read from the underlying AdapterT instance, potentially dropping the read datagram.
mt19937 get_random_generator()
Seed a fast random generator.
A reference-counted handle to a file descriptor.
void write(TCPSegment &seg)
Write to the underlying AdapterT instance, potentially dropping the datagram to be written.
Config for classes derived from FdAdapter.
An adapter class that adds random dropping behavior to an FD adapter.
LossyFdAdapter(AdapterT &&adapter)
Construct from a FileDescriptor appropriate to the AdapterT constructor.
AdapterT _adapter
The underlying FD adapter.
bool _should_drop(bool uplink)
Determine whether or not to drop a given read or write.
std::mt19937 _rand
Fast RNG used by _should_drop()