Sponge
CS144's user-space TCP library
|
An adapter class that adds random dropping behavior to an FD adapter. More...
#include <lossy_fd_adapter.hh>
Public Member Functions | |
LossyFdAdapter (AdapterT &&adapter) | |
Construct from a FileDescriptor appropriate to the AdapterT constructor. More... | |
operator const FileDescriptor & () const | |
Conversion to a FileDescriptor by returning the underlying AdapterT. More... | |
std::optional< TCPSegment > | read () |
Read from the underlying AdapterT instance, potentially dropping the read datagram. More... | |
void | write (TCPSegment &seg) |
Write to the underlying AdapterT instance, potentially dropping the datagram to be written. More... | |
Private Member Functions | |
bool | _should_drop (bool uplink) |
Determine whether or not to drop a given read or write. More... | |
Private Attributes | |
AdapterT | _adapter |
The underlying FD adapter. More... | |
std::mt19937 | _rand {get_random_generator()} |
Fast RNG used by _should_drop() More... | |
An adapter class that adds random dropping behavior to an FD adapter.
Definition at line 15 of file lossy_fd_adapter.hh.
|
inlineexplicit |
Construct from a FileDescriptor appropriate to the AdapterT constructor.
Definition at line 37 of file lossy_fd_adapter.hh.
|
inlineprivate |
Determine whether or not to drop a given read or write.
[in] | uplink | is true to use the uplink loss probability, else use the downlink loss probability |
true
if the segment should be dropped Definition at line 26 of file lossy_fd_adapter.hh.
|
inline |
Conversion to a FileDescriptor by returning the underlying AdapterT.
Definition at line 34 of file lossy_fd_adapter.hh.
|
inline |
Read from the underlying AdapterT instance, potentially dropping the read datagram.
Definition at line 42 of file lossy_fd_adapter.hh.
|
inline |
Write to the underlying AdapterT instance, potentially dropping the datagram to be written.
[in] | seg | is the packet to either write or drop |
Definition at line 52 of file lossy_fd_adapter.hh.
|
private |
The underlying FD adapter.
Definition at line 21 of file lossy_fd_adapter.hh.
|
private |
Fast RNG used by _should_drop()
Definition at line 18 of file lossy_fd_adapter.hh.