TCP

Work in Progress

Summary

TCP vs pipelined protocols

ProtocolTimeoutRetransmitHandle out-of-order
Go-Back-Noldest unACKed packetall unACKed, >=ndiscard
Selective repeatindividual unACKed packetsone, nbuffer, discard only if too far
TCPoldest unACKed packetone, oldest unACKed packetunspecified

Timeout

  • ideally, timeout > RTT

the exponential weighted moving average(EWMA) encodes all the sampled RTTs into a single value

Concept

Transmission Control Protocol(TCP)

  • connection-oriented, have to use source information to determine which socket to direct to
  • reliable
  • byte-stream, TCP divides the data into segments
  • flow control
  • congestion control
  • full duplex - bi-directional data flow
0                   1                   2                   3   
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Sequence Number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Acknowledgment Number                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Data |           |U|A|P|R|S|F|                               |
| Offset| Reserved  |R|C|S|S|Y|I|            Window             |
|       |           |G|K|H|T|N|N|                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options (if offset > 5)                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             data                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Pasted image 20260306112758.png

Sequence and acknowledgement numbers

  • sequence: first byte in this segment’s data
  • acknowledgement: next byte of data expected, receiver sends this as the cumulative ACK

Pasted image 20260304170512.png

  • fast retransmission - if 3 duplicates ACKs are received, resend that segment immediately, without waiting for timeout

3-way handshake

  • establishing a connection

Pasted image 20260304172524.png

  • SYN flooding - send SYN, but not ACK
  • SYN/ACK - send SYN-ACK packets that don’t belong to any session, server has to lookup everytime

Closing connection

  • send signal to close
  • wait for leftover data

Pasted image 20260304172627.png