Computer Networks - Transport Layer: TCP and UDP Protocols

Why Study TCP and UDP Protocols?

  1. The Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are the two most widely used protocols on the Internet. Therefore, it is impossible to use, manage, or develop code for an IP-based application without interacting with either or both TCP and UDP.
  2. Theory: Key functional and performance aspects of contemporary networks depend on the functions provided by TCP and UDP.
  3. Practice: Designing and coding any networked application requires an understanding of TCP and UDP functionality.
  4. Practice: Debugging any networked application requires an understanding of TCP and UDP functionality.

TCP and UDP Protocols

  • UDP: User Datagram Protocol
  • RTP: Real-time Transport Protocol
  • RTCP: Real-time Transport Control Protocol
  • TCP: Transmission Control Protocol

UDP: User Datagram Protocol

The Internet Transport Protocols: UDP

  • Introduction to UDP
  • Real-time transport over UDP
    • RTP—the Real-time Transport Protocol
    • RTCP—the Real-time Transport Control Protocol
    • Playout with buffering and jitter control

UDP Attributes

  • UDP is a connectionless protocol - state information is wholly in a packet
  • UDP is an unreliable protocol – no guarantees on packet delivery
  • UDP does not deliver packets in order - packets may arrive out of order
  • UDP is a datagram protocol – data is in discrete datagrams
  • UDP does not provide congestion control – upper layers must do this
  • UDP is a lightweight protocol – a minimum of overhead is required
  • UDP is defined in IETF RFC 768 (1980)
  • UDP is widely used in common applications such as VoIP or NFS
  • Variants exist for IPv4 and IPv6

Introduction to UDP

The UDP header consists of:

  • Source port (16 bits)
  • Destination port (16 bits)
  • UDP length (16 bits)
  • UDP checksum (16 bits)

The IP pseudo header used for the UDP checksum calculation consists of:

  • Source address (32 bits)
  • Destination address (32 bits)
  • 8 bits of zero padding
  • 8 bits of protocol number (17 for UDP)
  • 16 bits of the UDP length.

RTP and RTCP Protocols

Real-Time Transport Protocols

RTP resides in the application layer. An example of RTP usage is VoIP.

The RTP header consists of:

  • Version (Ver.): 2 bits
  • Padding (P): 1 bit
  • Extension (X): 1 bit
  • Contributing Source Identifier Count (CC): 4 bits
  • Marker (M): 1 bit
  • Payload Type: 7 bits
  • Sequence Number: 16 bits
  • Timestamp: 32 bits
  • Synchronization Source Identifier (SSRC): 32 bits
  • Contributing Source Identifiers (CSRC): 0 to 15 items, each 32 bits

Jitter Measurement

  • RTT is 11 msec for an ICMP ping.
  • Jitter is 11 msec for multiple ICMP pings.
  • Question: How much jitter is tolerable?

TCP: Transmission Control Protocol

The Internet Transport Protocols: TCP

  • Introduction to TCP
  • The TCP service model
  • The TCP protocol
  • The TCP segment header
  • TCP connection establishment
  • TCP connection release
  • TCP connection management modeling
  • TCP sliding window
  • TCP timer management
  • TCP congestion control
  • TCP CUBIC congestion avoidance algorithm

TCP Attributes

  • TCP is a connection-oriented protocol – virtual circuits are used.
  • TCP is an reliable protocol – packet delivery is guaranteed (at a cost!).
  • TCP delivers packets in order - packets always arrive in order.
  • TCP is a stream-oriented protocol – data flows as a stream (FIFO).
  • TCP provides congestion control – discussed below.
  • TCP is a heavyweight protocol – much overhead is required.
  • TCP is defined in IETF RFC 9293 (2022), initially in RFC 675 (1974).
  • TCP is widely used in common applications such as FTP, ssh, http.
  • Variants exist for IPv4 and IPv6.

The TCP Service Model

Some assigned ports:

  • 20, 21: FTP (File transfer)
  • 22: SSH (Remote login, replacement for Telnet)
  • 25: SMTP (Email)
  • 80: HTTP (World Wide Web)
  • 110: POP-3 (Remote email access)
  • 143: IMAP (Remote email access)
  • 443: HTTPS (Secure Web (HTTP over SSL/TLS))
  • 543: RTSP (Media player control)
  • 631: IPP (Printer sharing)

The TCP Segment Header

The TCP header consists of:

  • Source port (16 bits)
  • Destination port (16 bits)
  • Sequence number (32 bits)
  • Acknowledgement number (32 bits)
  • TCP header length (4 bits)
  • Reserved (3 bits)
  • Flags (9 bits): CEUAPRSF WCRCSSYI REGKHTNN
  • Window size (16 bits)
  • Checksum (16 bits)
  • Urgent pointer (16 bits)
  • Options (variable, 0 or more 32-bit words)
  • Data (optional)

TCP Connection Establishment

TCP connection establishment uses a three-way handshake:

  1. Host 1 sends a SYN (synchronize) segment to Host 2 with an initial sequence number xx.
  2. Host 2 responds with a SYN-ACK (synchronize-acknowledge) segment, acknowledging Host 1's SYN (ACK = x+1x + 1) and including its own initial sequence number yy.
  3. Host 1 sends an ACK segment to acknowledge Host 2's SYN (ACK = y+1y + 1).

Simultaneous connection establishment is possible when both hosts send SYN segments to each other at the same time. In this case, each host acknowledges the other's SYN in their SYN-ACK segment.

TCP Connection Management Modeling

States used in the TCP connection management finite state machine:

  • CLOSED: No connection is active or pending.
  • LISTEN: The server is waiting for an incoming call.
  • SYN RCVD: A connection request has arrived; wait for ACK.
  • SYN SENT: The application has started to open a connection.
  • ESTABLISHED: The normal data transfer state.
  • FIN WAIT 1: The application has said it is finished.
  • FIN WAIT 2: The other side has agreed to release.
  • TIME WAIT: Wait for all packets to die off.
  • CLOSING: Both sides have tried to close simultaneously.
  • CLOSE WAIT: The other side has initiated a release.
  • LAST ACK: Wait for all packets to die off.

The heavy solid line is the normal path for a client. The heavy dashed line is the normal path for a server. The light lines are unusual events. Each transition is labeled with the event causing it and the action resulting from it, separated by a slash.

TCP Sliding Window

TCP uses a sliding window mechanism to control the flow of data between sender and receiver. The receiver advertises a window size to the sender, indicating the amount of data it is willing to receive.

Window management in TCP, including sender blocking and receiver buffer management.

Silly window syndrome, and how small updates can cause low network utilisation.

TCP Timer Management

Probability density of acknowledgement arrival times in the data link layer vs. for TCP.

TCP Congestion Control

  1. A burst of packets is sent on a fast link.
  2. The burst queues at the router and drains onto the slow link (bottleneck).
  3. The receiver acknowledges packets at the slow link rate.
  4. Acknowledgements preserve slow link timing at the sender (ack clock).

Slow start increases the congestion window (cwnd) exponentially until it reaches the slow start threshold. After that, it increases the cwnd linearly (additive increase).

  • Slow start from an initial congestion window of one segment, doubling every RTT.
  • Additive increase from an initial congestion window of one segment, increasing by one segment every RTT.
TCP Tahoe and Reno

TCP Tahoe and Reno versions respond to packet loss differently:

  • Tahoe: Reduces congestion window to 1 MSS and performs slow start
  • Reno: Halves the congestion window and enters fast recovery.
Selective Acknowledgements (SACK)

Selective acknowledgements allow the receiver to inform the sender about specific segments that have been received, allowing the sender to retransmit only the lost segments.

TCP CUBIC Congestion Avoidance Algorithm

TCP CUBIC is a congestion control algorithm that uses a cubic function to adjust the congestion window size. The evolution of TCP CUBIC Congestion Window over time since the last congestion event.

Transport Protocols and Congestion Control

  • QUIC: Quick UDP Internet Connections
  • BBR: Congestion control based on bottleneck bandwidth
  • The future of TCP

BBR: Congestion Control Based on Bottleneck Bandwidth

BBR (Bottleneck Bandwidth and Round-trip propagation time) estimates the bottleneck bandwidth and round-trip propagation time to control the sending rate. It operates at the point where the delivery rate is maximized while minimizing the data in flight.

The Future of TCP

  • TCP will continue to evolve.
  • TCP issues:
    • Does not provide transport semantics applications want
    • Application must deal with problems not solved by TCP
  • Proposals providing a slightly different interface:
    • SCTP and SST
  • Must deal with “If it ain’t broke, don’t fix it’’ mentality