Sponge
CS144's user-space TCP library
Public Member Functions | Private Attributes | List of all members
TCPSender Class Reference

The "sender" part of a TCP implementation. More...

#include <tcp_sender.hh>

Public Member Functions

 TCPSender (const size_t capacity=TCPConfig::DEFAULT_CAPACITY, const uint16_t retx_timeout=TCPConfig::TIMEOUT_DFLT, const std::optional< WrappingInt32 > fixed_isn={})
 Initialize a TCPSender. More...
 
"Input" interface for the writer
ByteStreamstream_in ()
 
const ByteStreamstream_in () const
 
Methods that can cause the TCPSender to send a segment
void ack_received (const WrappingInt32 ackno, const uint16_t window_size)
 A new acknowledgment was received. More...
 
void send_empty_segment ()
 Generate an empty-payload segment (useful for creating empty ACK segments) More...
 
void fill_window ()
 create and send segments to fill as much of the window as possible More...
 
void tick (const size_t ms_since_last_tick)
 Notifies the TCPSender of the passage of time. More...
 
Accessors
size_t bytes_in_flight () const
 How many sequence numbers are occupied by segments sent but not yet acknowledged? More...
 
unsigned int consecutive_retransmissions () const
 Number of consecutive retransmissions that have occurred in a row. More...
 
std::queue< TCPSegment > & segments_out ()
 TCPSegments that the TCPSender has enqueued for transmission. More...
 
What is the next sequence number? (used for testing)
uint64_t next_seqno_absolute () const
 absolute seqno for the next byte to be sent More...
 
WrappingInt32 next_seqno () const
 relative seqno for the next byte to be sent More...
 

Private Attributes

unsigned int _initial_retransmission_timeout
 retransmission timer for the connection More...
 
WrappingInt32 _isn
 our initial sequence number, the number for our SYN. More...
 
uint64_t _next_seqno {0}
 the (absolute) sequence number for the next byte to be sent More...
 
std::queue< TCPSegment_segments_out {}
 outbound queue of segments that the TCPSender wants sent More...
 
ByteStream _stream
 outgoing stream of bytes that have not yet been sent More...
 

Detailed Description

The "sender" part of a TCP implementation.

Accepts a ByteStream, divides it up into segments and sends the segments, keeps track of which segments are still in-flight, maintains the Retransmission Timer, and retransmits in-flight segments if the retransmission timer expires.

Definition at line 18 of file tcp_sender.hh.

Constructor & Destructor Documentation

◆ TCPSender()

TCPSender::TCPSender ( const size_t  capacity = TCPConfig::DEFAULT_CAPACITY,
const uint16_t  retx_timeout = TCPConfig::TIMEOUT_DFLT,
const std::optional< WrappingInt32 fixed_isn = {} 
)

Initialize a TCPSender.

Parameters
[in]capacitythe capacity of the outgoing byte stream
[in]retx_timeoutthe initial amount of time to wait before retransmitting the oldest outstanding segment
[in]fixed_isnthe Initial Sequence Number to use, if set (otherwise uses a random ISN)

Definition at line 20 of file tcp_sender.cc.

Member Function Documentation

◆ ack_received()

void TCPSender::ack_received ( const WrappingInt32  ackno,
const uint16_t  window_size 
)

A new acknowledgment was received.

Parameters
acknoThe remote receiver's ackno (acknowledgment number)
window_sizeThe remote receiver's advertised window size

Definition at line 31 of file tcp_sender.cc.

◆ bytes_in_flight()

uint64_t TCPSender::bytes_in_flight ( ) const

How many sequence numbers are occupied by segments sent but not yet acknowledged?

Note
count is in "sequence space," i.e. SYN and FIN each count for one byte (see TCPSegment::length_in_sequence_space())

Definition at line 25 of file tcp_sender.cc.

◆ consecutive_retransmissions()

unsigned int TCPSender::consecutive_retransmissions ( ) const

Number of consecutive retransmissions that have occurred in a row.

Definition at line 36 of file tcp_sender.cc.

◆ fill_window()

void TCPSender::fill_window ( )

create and send segments to fill as much of the window as possible

Definition at line 27 of file tcp_sender.cc.

◆ next_seqno()

WrappingInt32 TCPSender::next_seqno ( ) const
inline

relative seqno for the next byte to be sent

Definition at line 88 of file tcp_sender.hh.

◆ next_seqno_absolute()

uint64_t TCPSender::next_seqno_absolute ( ) const
inline

absolute seqno for the next byte to be sent

Definition at line 85 of file tcp_sender.hh.

◆ segments_out()

std::queue<TCPSegment>& TCPSender::segments_out ( )
inline

TCPSegments that the TCPSender has enqueued for transmission.

Note
These must be dequeued and sent by the TCPConnection, which will need to fill in the fields that are set by the TCPReceiver (ackno and window size) before sending.

Definition at line 78 of file tcp_sender.hh.

◆ send_empty_segment()

void TCPSender::send_empty_segment ( )

Generate an empty-payload segment (useful for creating empty ACK segments)

Definition at line 38 of file tcp_sender.cc.

◆ stream_in() [1/2]

ByteStream& TCPSender::stream_in ( )
inline

Definition at line 43 of file tcp_sender.hh.

◆ stream_in() [2/2]

const ByteStream& TCPSender::stream_in ( ) const
inline

Definition at line 44 of file tcp_sender.hh.

◆ tick()

void TCPSender::tick ( const size_t  ms_since_last_tick)

Notifies the TCPSender of the passage of time.

Parameters
[in]ms_since_last_tickthe number of milliseconds since the last call to this method

Definition at line 34 of file tcp_sender.cc.

Member Data Documentation

◆ _initial_retransmission_timeout

unsigned int TCPSender::_initial_retransmission_timeout
private

retransmission timer for the connection

Definition at line 27 of file tcp_sender.hh.

◆ _isn

WrappingInt32 TCPSender::_isn
private

our initial sequence number, the number for our SYN.

Definition at line 21 of file tcp_sender.hh.

◆ _next_seqno

uint64_t TCPSender::_next_seqno {0}
private

the (absolute) sequence number for the next byte to be sent

Definition at line 33 of file tcp_sender.hh.

◆ _segments_out

std::queue<TCPSegment> TCPSender::_segments_out {}
private

outbound queue of segments that the TCPSender wants sent

Definition at line 24 of file tcp_sender.hh.

◆ _stream

ByteStream TCPSender::_stream
private

outgoing stream of bytes that have not yet been sent

Definition at line 30 of file tcp_sender.hh.


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