Sponge
CS144's user-space TCP library
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LossyFdAdapter< AdapterT > Class Template Reference

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< TCPSegmentread ()
 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...
 

Detailed Description

template<typename AdapterT>
class LossyFdAdapter< AdapterT >

An adapter class that adds random dropping behavior to an FD adapter.

Definition at line 15 of file lossy_fd_adapter.hh.

Constructor & Destructor Documentation

◆ LossyFdAdapter()

template<typename AdapterT >
LossyFdAdapter< AdapterT >::LossyFdAdapter ( AdapterT &&  adapter)
inlineexplicit

Construct from a FileDescriptor appropriate to the AdapterT constructor.

Definition at line 37 of file lossy_fd_adapter.hh.

Member Function Documentation

◆ _should_drop()

template<typename AdapterT >
bool LossyFdAdapter< AdapterT >::_should_drop ( bool  uplink)
inlineprivate

Determine whether or not to drop a given read or write.

Parameters
[in]uplinkis true to use the uplink loss probability, else use the downlink loss probability
Returns
true if the segment should be dropped

Definition at line 26 of file lossy_fd_adapter.hh.

◆ operator const FileDescriptor &()

template<typename AdapterT >
LossyFdAdapter< AdapterT >::operator const FileDescriptor & ( ) const
inline

Conversion to a FileDescriptor by returning the underlying AdapterT.

Definition at line 34 of file lossy_fd_adapter.hh.

◆ read()

template<typename AdapterT >
std::optional<TCPSegment> LossyFdAdapter< AdapterT >::read ( )
inline

Read from the underlying AdapterT instance, potentially dropping the read datagram.

Returns
std::optional<TCPSegment> that is empty if the segment was dropped or if the underlying AdapterT returned an empty value

Definition at line 42 of file lossy_fd_adapter.hh.

◆ write()

template<typename AdapterT >
void LossyFdAdapter< AdapterT >::write ( TCPSegment seg)
inline

Write to the underlying AdapterT instance, potentially dropping the datagram to be written.

Parameters
[in]segis the packet to either write or drop

Definition at line 52 of file lossy_fd_adapter.hh.

Member Data Documentation

◆ _adapter

template<typename AdapterT >
AdapterT LossyFdAdapter< AdapterT >::_adapter
private

The underlying FD adapter.

Definition at line 21 of file lossy_fd_adapter.hh.

◆ _rand

template<typename AdapterT >
std::mt19937 LossyFdAdapter< AdapterT >::_rand {get_random_generator()}
private

Fast RNG used by _should_drop()

Definition at line 18 of file lossy_fd_adapter.hh.


The documentation for this class was generated from the following file: