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

Summary of a TCPConnection's internal state. More...

#include <tcp_state.hh>

Public Types

enum  State {
  State::LISTEN = 0, State::SYN_RCVD, State::SYN_SENT, State::ESTABLISHED,
  State::CLOSE_WAIT, State::LAST_ACK, State::FIN_WAIT_1, State::FIN_WAIT_2,
  State::CLOSING, State::TIME_WAIT, State::CLOSED, State::RESET
}
 Official state names from the TCP specification. More...
 

Public Member Functions

 TCPState (const TCPSender &sender, const TCPReceiver &receiver, const bool active, const bool linger)
 Construct a TCPState given a sender, a receiver, and the TCPConnection's active and linger bits. More...
 
 TCPState (const TCPState::State state)
 Construct a TCPState that corresponds to one of the "official" TCP state names. More...
 
std::string name () const
 Summarize the TCPState in a string. More...
 
bool operator!= (const TCPState &other) const
 
bool operator== (const TCPState &other) const
 

Static Public Member Functions

static std::string state_summary (const TCPReceiver &receiver)
 Summarize the state of a TCPReceiver in a string. More...
 
static std::string state_summary (const TCPSender &receiver)
 Summarize the state of a TCPSender in a string. More...
 

Private Attributes

bool _active {true}
 
bool _linger_after_streams_finish {true}
 
std::string _receiver {}
 
std::string _sender {}
 

Detailed Description

Summary of a TCPConnection's internal state.

Most TCP implementations have a global per-connection state machine, as described in the TCP specification. Sponge is a bit different: we have factored the connection into two independent parts (the sender and the receiver). The TCPSender and TCPReceiver maintain their interval state variables independently (e.g. next_seqno, number of bytes in flight, or whether each stream has ended). There is no notion of a discrete state machine or much overarching state outside the sender and receiver. To test that Sponge follows the TCP spec, we use this class to compare the "official" states with Sponge's sender/receiver states and two variables that belong to the overarching TCPConnection object.

Definition at line 23 of file tcp_state.hh.

Member Enumeration Documentation

◆ State

enum TCPState::State
strong

Official state names from the TCP specification.

Enumerator
LISTEN 

Listening for a peer to connect.

SYN_RCVD 

Got the peer's SYN.

SYN_SENT 

Sent a SYN to initiate a connection.

ESTABLISHED 

Three-way handshake complete.

CLOSE_WAIT 

Remote side has sent a FIN, connection is half-open.

LAST_ACK 

Local side sent a FIN from CLOSE_WAIT, waiting for ACK.

FIN_WAIT_1 

Sent a FIN to the remote side, not yet ACK'd.

FIN_WAIT_2 

Received an ACK for previously-sent FIN.

CLOSING 

Received a FIN just after we sent one.

TIME_WAIT 

Both sides have sent FIN and ACK'd, waiting for 2 MSL.

CLOSED 

A connection that has terminated normally.

RESET 

A connection that terminated abnormally.

Definition at line 35 of file tcp_state.hh.

Constructor & Destructor Documentation

◆ TCPState() [1/2]

TCPState::TCPState ( const TCPSender sender,
const TCPReceiver receiver,
const bool  active,
const bool  linger 
)

Construct a TCPState given a sender, a receiver, and the TCPConnection's active and linger bits.

Definition at line 76 of file tcp_state.cc.

◆ TCPState() [2/2]

TCPState::TCPState ( const TCPState::State  state)

Construct a TCPState that corresponds to one of the "official" TCP state names.

Definition at line 17 of file tcp_state.cc.

Member Function Documentation

◆ name()

string TCPState::name ( ) const

Summarize the TCPState in a string.

Definition at line 12 of file tcp_state.cc.

◆ operator!=()

bool TCPState::operator!= ( const TCPState other) const

Definition at line 10 of file tcp_state.cc.

◆ operator==()

bool TCPState::operator== ( const TCPState other) const

Definition at line 5 of file tcp_state.cc.

◆ state_summary() [1/2]

string TCPState::state_summary ( const TCPReceiver receiver)
static

Summarize the state of a TCPReceiver in a string.

Definition at line 82 of file tcp_state.cc.

◆ state_summary() [2/2]

string TCPState::state_summary ( const TCPSender receiver)
static

Summarize the state of a TCPSender in a string.

Definition at line 94 of file tcp_state.cc.

Member Data Documentation

◆ _active

bool TCPState::_active {true}
private

Definition at line 27 of file tcp_state.hh.

◆ _linger_after_streams_finish

bool TCPState::_linger_after_streams_finish {true}
private

Definition at line 28 of file tcp_state.hh.

◆ _receiver

std::string TCPState::_receiver {}
private

Definition at line 26 of file tcp_state.hh.

◆ _sender

std::string TCPState::_sender {}
private

Definition at line 25 of file tcp_state.hh.


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