Sponge
CS144's user-space TCP library
|
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 | |
ByteStream & | stream_in () |
const ByteStream & | stream_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... | |
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.
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.
[in] | capacity | the capacity of the outgoing byte stream |
[in] | retx_timeout | the initial amount of time to wait before retransmitting the oldest outstanding segment |
[in] | fixed_isn | the Initial Sequence Number to use, if set (otherwise uses a random ISN) |
Definition at line 20 of file tcp_sender.cc.
void TCPSender::ack_received | ( | const WrappingInt32 | ackno, |
const uint16_t | window_size | ||
) |
A new acknowledgment was received.
ackno | The remote receiver's ackno (acknowledgment number) |
window_size | The remote receiver's advertised window size |
Definition at line 31 of file tcp_sender.cc.
uint64_t TCPSender::bytes_in_flight | ( | ) | const |
How many sequence numbers are occupied by segments sent but not yet acknowledged?
Definition at line 25 of file tcp_sender.cc.
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.
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.
|
inline |
relative seqno for the next byte to be sent
Definition at line 88 of file tcp_sender.hh.
|
inline |
absolute seqno for the next byte to be sent
Definition at line 85 of file tcp_sender.hh.
|
inline |
TCPSegments that the TCPSender has enqueued for transmission.
Definition at line 78 of file tcp_sender.hh.
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.
|
inline |
Definition at line 43 of file tcp_sender.hh.
|
inline |
Definition at line 44 of file tcp_sender.hh.
void TCPSender::tick | ( | const size_t | ms_since_last_tick | ) |
Notifies the TCPSender of the passage of time.
[in] | ms_since_last_tick | the number of milliseconds since the last call to this method |
Definition at line 34 of file tcp_sender.cc.
|
private |
retransmission timer for the connection
Definition at line 27 of file tcp_sender.hh.
|
private |
our initial sequence number, the number for our SYN.
Definition at line 21 of file tcp_sender.hh.
|
private |
the (absolute) sequence number for the next byte to be sent
Definition at line 33 of file tcp_sender.hh.
|
private |
outbound queue of segments that the TCPSender wants sent
Definition at line 24 of file tcp_sender.hh.
|
private |
outgoing stream of bytes that have not yet been sent
Definition at line 30 of file tcp_sender.hh.