Transport Layer
Tags: #◇Computer Science #◇CSNETWK #◇Transport Layer #◇Code Snippets
◇Overview
The Transport Layer provides logical communication between application processes running on different hosts. While the network layer facilitates communication between hosts, the transport layer enhances it to enable communication between specific processes. The sender breaks application messages into segments and passes them to the network layer. The receiver reassembles these segments and passes them up to the application layer.
Multiplexing and Demultiplexing
To deliver data to the correct application, the transport layer uses specific header information. Multiplexing (Sender): Handling data from multiple sockets and adding a transport header to create segments. Demultiplexing (Receiver): Using header info to deliver received segments to the correct socket.
Demultiplexing relies on IP addresses and port numbers. UDP uses connectionless demultiplexing, relying only on the destination port number. TCP uses connection-oriented demultiplexing, identifying a socket uniquely by a 4-tuple: source IP, source port, destination IP, and destination port.
UDP: User Datagram Protocol
UDP is a bare-bones, connectionless transport protocol providing "best effort" service. It offers unreliable, unordered delivery. Features: No handshaking (avoids RTT delay for setup), no connection state, small header size (Source port, Dest port, Length, Checksum), and no congestion control. Use cases: Streaming multimedia, DNS, SNMP, and HTTP/3 (where reliability is implemented at the application layer). UDP Checksum: Used for error detection. The sender treats the UDP segment as a sequence of 16-bit integers and computes the one's complement sum. The receiver verifies this checksum to catch bit flips.
TCP: Transmission Control Protocol
TCP provides a connection-oriented, reliable, and in-order byte stream. Features: Pipelining, flow control (prevents sender from overwhelming receiver), congestion control, cumulative ACKs, full-duplex data. TCP Segment Structure: Includes source/dest ports, sequence number (byte stream number of the first byte of data), acknowledgment number (sequence number of the next expected byte), receive window (rwnd), header length, and checksum. Connection Management: Uses a 3-way handshake (SYN, SYN-ACK, ACK) to establish a connection safely, agreeing on initial sequence numbers. A connection is closed using segments with the FIN bit set. Flow Control: The receiver advertises its free buffer space in the rwnd field of the TCP header. The sender limits unACKed data to this value, guaranteeing the receiver's buffer won't overflow. Reliable Data Transfer: TCP uses timeouts and fast retransmit. If a segment's timer expires, it is retransmitted. If the sender receives 3 duplicate ACKs for the same data (indicating a gap), it performs a Fast Retransmit, resending the unACKed segment with the smallest sequence number before the timeout occurs.
RTT and Timeout Estimation
TCP dynamically adjusts its timeout interval based on measured Round Trip Times (SampleRTT). It uses an Exponential Weighted Moving Average (EWMA) to calculate an EstimatedRTT and estimates the variance (DevRTT). The TimeoutInterval is then set to the estimate plus a safety margin.
◇Important Formulas
Estimated RTT (Exponential Weighted Moving Average):
(Typical value: )
RTT Deviation (Safety Margin Calculation):
(Typical value: )
Timeout Interval:
Internet Checksum:
Computed by adding all 16-bit words of the segment and taking the 1's complement. During addition, any carryout from the most significant bit is wrapped around and added to the least significant bit.
◇Worked Examples
Example 1: Computing Estimated RTT
Suppose the current is , , and a new of is measured.
◇Example 2: 16-bit Checksum Addition (Wraparound)
Add two 16-bit binary numbers: 1110011001100110 and 1101010101010101.
Sum:
1110011001100110
1101010101010101
11011101110111011 (17 bits)
Wraparound the carry out (1):
1011101110111011 + 1 = 1011101110111100
1's complement (Checksum): 0100010001000011
◇References & Navigation
- Previous Topic: ◇Applications
- Next Topic: ◇Sockets Programming
- Related Notes: ◇Internetworking
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
What is the primary purpose of multiplexing in the transport layer?
Which 4-tuple is used by TCP for connection-oriented demultiplexing?
Which feature is NOT provided by UDP?
What is the purpose of the rwnd field in the TCP header?
How does TCP establish a connection safely?
When does a TCP Fast Retransmit occur?
What is the role of the parameter in estimating TCP's RTT?
If EstimatedRTT is 100 ms and DevRTT is 10 ms, what is the TimeoutInterval?
How is the Internet Checksum computed for a UDP segment?
What sequence numbers does the connection establishment handshake agree upon?