TCP

Transport Control Protocol

Feature

  • Connection-oriented, reliable
  • Unicast only
  • Stream oriented
  • Error Control, Flow Control, Congestion Control

TCP Header

  • Sequence number: Identifies the byte in the stream of data from the sending TCP to the receiving TCP that the first byte of data in this segment represents(offset)
  • Acknowledgement Number: The next sequence number that the host wants to receive
  • Flags
    • URG: an urgent message is being carried.
    • ACK: the acknowledgment number is valid.
    • PSH: a notification from the sender to the receiver that it should pass all the data received to the application as soon as possible.
    • RST: signals a request to reset the TCP connection.
    • SYN: set when initiating a connection.
    • FIN: set to terminate a connection.

TCP Connection

Establishment

Termination

Error Control

Each data byte has a unique sequence number. The receiver uses cumulative acknowledgments(by default) to inform the sender of the last correctly received byte in order.

Error detection is performed in each layer of the TCP/IP stack by means of header checksums, and errored packets are dropped.

Selective acknowledgment (SACK)

SACK is used to report multiple lost segments. The receiver uses the TCP SACK option to acknowledge all segments that has been successfully received in the last window of segments, and the sender can retransmit more than one lost segment at a time.

In this example, left edge of SACK is seq=1126009, which means that seq = 1126009 is received, but seq = 1126009-1448 = 1124561 is lost, so the sender will retransmit this datagram.

Retransmisson Timer

TCP will also set a Timer to measure whether the sended message will be received. If no ack received when the timer expires, this segment will be retransmitted.

  • The Timer value should be larger than but of the same order of magnitude as a measurement of the Round Trip Time (RTT).
  • TCP continuously measure the RTT and updates the retransmission timer value, defined as Retransmission TimeOut (RTO), dynamically.

Interactive data flow

TCP supports interactive data flow for interactive user applications, such as telnet and ssh.

To reduce the number of small segments to be more efficient:

Delayed ACK

Set a Timer: goes off every K ms. Send all acks every K ms.

Nagle Algorithm

Set a Window: when reach MSS, all buffered bytes are sent in a single segment.

Congestion Control

Sliding window buffer for both sender(cwnd) and receiver(awnd/rwnd).

For sender:

Here is a graph to show that the process of congestion control:

Serveral phases:

  1. Slow Start(cwnd $\leq$ ssthresh):
    • cwnd = cwnd + segsize(= MSS), when receives an ACK
    • Exponentially increases
    • When timeout, it enters this phase again
  2. Congestion Avoidance(cwnd > ssthresh):
    • cwnd = cwnd + segsize x segsize / cwnd + segsize / 8
    • Linearly increases
  3. Fast Recovery(Three duplicate ACKs are received)
    • ssthresh = max [ 2 segsize, min (cwnd, awnd)/2 ]
    • Retransmit a segment if allowed by the window size

For receiver:

Event Action
In-order segment, already ACKed delayed ACK, wait up to 500ms for another segment, if not, send ACK
In-order segment, ACK pending Immediately send single cumulative ACK
Out-of-order, Gap detected Immediately send duplicate ACK, indicating next expected ACK
Partially or completely fills gap Immediately send ACK, provided that segment starts at lower end of gap
Next