Sponge
CS144's user-space TCP library
tcp_state.cc
Go to the documentation of this file.
1 #include "tcp_state.hh"
2 
3 using namespace std;
4 
5 string TCPState::state_summary(const TCPReceiver &receiver) {
6  if (receiver.stream_out().error()) {
8  } else if (not receiver.ackno().has_value()) {
10  } else if (receiver.stream_out().input_ended()) {
12  } else {
14  }
15 }
16 
17 string TCPState::state_summary(const TCPSender &sender) {
18  if (sender.stream_in().error()) {
20  } else if (sender.next_seqno_absolute() == 0) {
22  } else if (sender.next_seqno_absolute() == sender.bytes_in_flight()) {
24  } else if (not sender.stream_in().eof()) {
26  } else if (sender.next_seqno_absolute() < sender.stream_in().bytes_written() + 2) {
28  } else if (sender.bytes_in_flight()) {
30  } else {
32  }
33 }
tcp_state.hh
TCPSenderStateSummary::SYN_SENT
const std::string SYN_SENT
Definition: tcp_state.hh:42
ByteStream::bytes_written
size_t bytes_written() const
Total number of bytes written.
Definition: byte_stream.cc:49
ByteStream::eof
bool eof() const
Definition: byte_stream.cc:47
TCPSenderStateSummary::FIN_SENT
const std::string FIN_SENT
Definition: tcp_state.hh:44
TCPReceiver::ackno
std::optional< WrappingInt32 > ackno() const
The ackno that should be sent to the peer.
Definition: tcp_receiver.cc:17
TCPSender
The "sender" part of a TCP implementation.
Definition: tcp_sender.hh:18
TCPReceiverStateSummary::FIN_RECV
const std::string FIN_RECV
Definition: tcp_state.hh:36
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
TCPReceiver
The "receiver" part of a TCP implementation.
Definition: tcp_receiver.hh:16
TCPReceiverStateSummary::LISTEN
const std::string LISTEN
Definition: tcp_state.hh:34
TCPSenderStateSummary::CLOSED
const std::string CLOSED
Definition: tcp_state.hh:41
TCPSenderStateSummary::ERROR
const std::string ERROR
Definition: tcp_state.hh:40
ByteStream::error
bool error() const
Definition: byte_stream.hh:62
std
TCPSender::stream_in
ByteStream & stream_in()
Definition: tcp_sender.hh:43
TCPReceiverStateSummary::SYN_RECV
const std::string SYN_RECV
Definition: tcp_state.hh:35
TCPSenderStateSummary::SYN_ACKED
const std::string SYN_ACKED
Definition: tcp_state.hh:43
TCPSender::next_seqno_absolute
uint64_t next_seqno_absolute() const
absolute seqno for the next byte to be sent
Definition: tcp_sender.hh:85
TCPReceiver::stream_out
ByteStream & stream_out()
Definition: tcp_receiver.hh:61
TCPState::state_summary
static std::string state_summary(const TCPReceiver &receiver)
Summarize the state of a TCPReceiver in a string.
Definition: tcp_state.cc:5
TCPSenderStateSummary::FIN_ACKED
const std::string FIN_ACKED
Definition: tcp_state.hh:45
ByteStream::input_ended
bool input_ended() const
Definition: byte_stream.cc:41
TCPReceiverStateSummary::ERROR
const std::string ERROR
Definition: tcp_state.hh:33