Sponge
CS144's user-space TCP library
tcp_sender.hh
Go to the documentation of this file.
1 #ifndef SPONGE_LIBSPONGE_TCP_SENDER_HH
2 #define SPONGE_LIBSPONGE_TCP_SENDER_HH
3 
4 #include "byte_stream.hh"
5 #include "tcp_config.hh"
6 #include "tcp_segment.hh"
7 #include "wrapping_integers.hh"
8 
9 #include <functional>
10 #include <queue>
11 
13 
18 class TCPSender {
19  private:
22 
25 
28 
31 
33  uint64_t _next_seqno{0};
34 
35  public:
37  TCPSender(const size_t capacity = TCPConfig::DEFAULT_CAPACITY,
38  const uint16_t retx_timeout = TCPConfig::TIMEOUT_DFLT,
39  const std::optional<WrappingInt32> fixed_isn = {});
40 
43  ByteStream &stream_in() { return _stream; }
44  const ByteStream &stream_in() const { return _stream; }
46 
49 
51  void ack_received(const WrappingInt32 ackno, const uint16_t window_size);
52 
54  void send_empty_segment();
55 
57  void fill_window();
58 
60  void tick(const size_t ms_since_last_tick);
62 
65 
69  size_t bytes_in_flight() const;
70 
72  unsigned int consecutive_retransmissions() const;
73 
80 
83 
85  uint64_t next_seqno_absolute() const { return _next_seqno; }
86 
90 };
91 
92 #endif // SPONGE_LIBSPONGE_TCP_SENDER_HH
TCPSender::consecutive_retransmissions
unsigned int consecutive_retransmissions() const
Number of consecutive retransmissions that have occurred in a row.
Definition: tcp_sender.cc:36
tcp_segment.hh
TCPSender::_segments_out
std::queue< TCPSegment > _segments_out
outbound queue of segments that the TCPSender wants sent
Definition: tcp_sender.hh:24
wrap
WrappingInt32 wrap(uint64_t n, WrappingInt32 isn)
Definition: wrapping_integers.cc:16
WrappingInt32
A 32-bit integer, expressed relative to an arbitrary initial sequence number (ISN)
Definition: wrapping_integers.hh:9
TCPSender
The "sender" part of a TCP implementation.
Definition: tcp_sender.hh:18
TCPSender::_initial_retransmission_timeout
unsigned int _initial_retransmission_timeout
retransmission timer for the connection
Definition: tcp_sender.hh:27
byte_stream.hh
std::queue< TCPSegment >
TCPSender::send_empty_segment
void send_empty_segment()
Generate an empty-payload segment (useful for creating empty ACK segments)
Definition: tcp_sender.cc:38
TCPSender::bytes_in_flight
size_t bytes_in_flight() const
How many sequence numbers are occupied by segments sent but not yet acknowledged?
Definition: tcp_sender.cc:25
ByteStream
An in-order byte stream.
Definition: byte_stream.hh:11
tcp_config.hh
TCPSender::segments_out
std::queue< TCPSegment > & segments_out()
TCPSegments that the TCPSender has enqueued for transmission.
Definition: tcp_sender.hh:78
wrapping_integers.hh
TCPSender::_stream
ByteStream _stream
outgoing stream of bytes that have not yet been sent
Definition: tcp_sender.hh:30
TCPSender::_isn
WrappingInt32 _isn
our initial sequence number, the number for our SYN.
Definition: tcp_sender.hh:21
TCPSender::_next_seqno
uint64_t _next_seqno
the (absolute) sequence number for the next byte to be sent
Definition: tcp_sender.hh:33
TCPSender::stream_in
ByteStream & stream_in()
Definition: tcp_sender.hh:43
TCPSender::stream_in
const ByteStream & stream_in() const
Definition: tcp_sender.hh:44
TCPConfig::TIMEOUT_DFLT
static constexpr uint16_t TIMEOUT_DFLT
Default re-transmit timeout is 1 second.
Definition: tcp_config.hh:16
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.
Definition: tcp_sender.cc:20
TCPSender::ack_received
void ack_received(const WrappingInt32 ackno, const uint16_t window_size)
A new acknowledgment was received.
Definition: tcp_sender.cc:31
TCPSender::next_seqno_absolute
uint64_t next_seqno_absolute() const
absolute seqno for the next byte to be sent
Definition: tcp_sender.hh:85
TCPConfig::DEFAULT_CAPACITY
static constexpr size_t DEFAULT_CAPACITY
Default capacity.
Definition: tcp_config.hh:14
TCPSender::tick
void tick(const size_t ms_since_last_tick)
Notifies the TCPSender of the passage of time.
Definition: tcp_sender.cc:34
TCPSender::fill_window
void fill_window()
create and send segments to fill as much of the window as possible
Definition: tcp_sender.cc:27
TCPSender::next_seqno
WrappingInt32 next_seqno() const
relative seqno for the next byte to be sent
Definition: tcp_sender.hh:88