The transport layer acts as the logical bridge between the user-facing application layer and the packet-routing network layer of the TCP/IP suite. This module examines how the transport layer provides process-to-process communication, manages network congestion, handles packet errors, and ensures reliable stream delivery.
The primary objective of the transport layer is to provide logical, end-to-end process-to-process communication between application programs running on different hosts.
While the network layer manages host-to-host communication (routing packets from physical machine to physical machine ), it is unaware of which specific application process should receive those packets. The transport layer sits above the network layer, demultiplexing network packets down to individual application sockets.
+--------------------------------------------------------+
| APPLICATION LAYER |
| [HTTP Process] [DNS Process] [SMTP Process] |
+---------+---------------+---------------+--------------+
| | |
(Port 80/TCP) (Port 53/UDP) (Port 25/TCP) <-- Transport Sockets
| | |
+---------+---------------+---------------+--------------+
| TRANSPORT LAYER |
| [TCP Engine] [UDP Engine] |
+-------------------------+------------------------------+
|
+-------------------------v------------------------------+
| NETWORK LAYER |
| [IP Routing (Host-to-Host)] |
+--------------------------------------------------------+To map data to its designated process, the transport layer utilizes port numbers. Port numbers are 16-bit integers ranging from to . The Internet Assigned Numbers Authority (IANA) divides these numbers into three clear domains:
In UNIX and Unix-like operating systems, the binding of well-known ports to services is listed in /etc/services. For example, searching for trivial file transfer services via shell command:
grep -w 69 /etc/services
# Output: tftp 69/udpTo establish a unique network connection, a transport layer protocol requires both an IP address (network-level routing) and a port number (process-level routing). The combination of these two elements forms a Socket Address:
An active communication channel is uniquely identified by a 4-tuple consisting of:
The transport layer acts as a funnel. It must aggregate outgoing data flows from various application processes into a single channel (multiplexing) and separate incoming data packets back to their target applications (demultiplexing).
Sender-Side (Multiplexing) Receiver-Side (Demultiplexing)
[App 1] [App 2] [App 3] [App 1] [App 2] [App 3]
| | | ^ ^ ^
(Port A) (Port B) (Port C) (Port A) (Port B) (Port C)
\ | / \ | /
+-v----------v----------v-+ +-v----------v----------v-+
| Transport Layer | | Transport Layer |
+------------+------------+ +------------^------------+
| (Encapsulation) | (Decapsulation)
v |
To Network Layer From Network LayerDuring encapsulation, the application stream is segmented, and a transport-layer header (including the port addresses) is prepended. This segment is encapsulated within an IP datagram payload, which is then encapsulated inside a data-link layer frame.
Reliable transport requires mechanisms to handle speed disparities between the sender and receiver, as well as lossy network links.
Flow control balances the rate at which a producer generates data against the rate at which a consumer processes it.
At the transport layer, sliding window mechanisms utilize a pull/push hybrid feedback system to dynamically update the sender on how much data the receiver can accept.
Error control guarantees that the delivered data stream is complete, in-order, and uncorrupted.
To track packets, transport protocols utilize sequence numbers and acknowledgements. The sequence numbers are cyclic, governed by modulo arithmetic:
where represents the bit-size of the sequence number field.
To understand modern transport-layer design, we can examine a sequence of protocols moving from low to high complexity.
The Simple Protocol is an idealized, connectionless protocol with no flow control and no error control. It assumes that the underlying physical link is completely error-free and that the receiver's buffer is infinitely large. The sender simply pushes packets to the receiver as fast as they arrive from the application.
Sender Receiver
| |
|--- Packet 0 ------------------------>| (Process Immediately)
|--- Packet 1 ------------------------>| (Process Immediately)
| |The Stop-and-Wait Protocol introduces both flow and error control. The sender transmits a single packet and pauses, refusing to send more data until it receives an Acknowledgement (ACK) from the receiver.
Sender Receiver
| |
|--- Seq 0 --------------------------->| (Received OK)
|<-- ACK 1 ----------------------------| (Expects Seq 1 next)
| |
|--- Seq 1 -------------------> [X] | (Packet Lost)
| (Timer Starts) |
| (Timer Expires) |
|--- Seq 1 (Retransmitted) ----------->| (Received OK)
|<-- ACK 0 ----------------------------| (Expects Seq 0 next)The key drawback of the Stop-and-Wait protocol is its poor link utilization on networks with a high Bandwidth-Delay Product (BDP):
where is the transmission rate (bandwidth) of the channel, and is the Round-Trip Time.
Let be the packet length in bits. The transmission time () of the packet is:
The channel utilization () of a Stop-and-Wait system can be formulated as:
If , the utilization falls toward zero, leaving the link mostly idle.
To resolve the low efficiency of Stop-and-Wait, pipelining is introduced. The Go-Back-N protocol allows the sender to transmit multiple packets before waiting for an acknowledgment.
Go-Back-N Send Window Layout:
+--------------------------------------------------------------+
| ... | Sf | Sf+1 | ... | Sn-1 | ... | Sf + Ssize - 1 | ...
+--------------------------------------------------------------+
^ ^
|-- Sent, Unacknowledged |-- Next to Send
If was allowed to be , a complete window loss of ACKs would cause the receiver to confuse new packets with retransmissions of old packets.
The Selective-Repeat protocol optimizes GBN by avoiding unnecessary retransmissions of packets that have already arrived intact.
The User Datagram Protocol (UDP) is a minimal, connectionless, unreliable transport protocol. It acts as a direct interface to IP, adding only port addressing and basic error checking.
A UDP packet is called a User Datagram and contains a fixed 8-byte header followed by the payload.
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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data |
| ... |To calculate the checksum, UDP prepends a pseudoheader containing critical fields from the IP layer. This binds the transport layer segment to its routing parameters, ensuring that the packet was not misdelivered to the wrong destination host.
+--------------------------------------------------------+
| Source IP Address | (4 bytes)
+--------------------------------------------------------+
| Destination IP Address | (4 bytes)
+------------------------+-------------------------------+
| Zero (1 byte) | Protocol ID (17) | (2 bytes)
+------------------------+-------------------------------+
| UDP Length | (2 bytes)
+--------------------------------------------------------+The checksum is computed by dividing the combined pseudoheader, UDP header, and padded payload into 16-bit blocks, summing them using one's complement arithmetic, and taking the one's complement of the final sum.
The Transmission Control Protocol (TCP) is a connection-oriented, reliable, stream-oriented, full-duplex transport protocol. It abstractly transforms IP's best-effort delivery into a reliable pipeline.
TCP packets are called segments. The TCP header typically ranges from 20 to 60 bytes depending on options.
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 (0 to 40 bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+URG: Urgent pointer field is valid.ACK: Acknowledgment field is valid.PSH: Push function (deliver data immediately).RST: Reset the connection.SYN: Synchronize sequence numbers (connection setup).FIN: Terminate connection.rwnd) for flow control.TCP requires stateful handshakes to manage connection creation and destruction.
To ensure sequence numbers are synchronized and stale connections are avoided, TCP uses a three-way handshake:
Client Server
| |
|--- SYN (seq = x) ------------------------------->| [SYN_RCVD]
| |
|<-- SYN-ACK (seq = y, ack = x + 1) ---------------| [SYN_SENT]
| |
|--- ACK (seq = x + 1, ack = y + 1) -------------->| [ESTABLISHED]Note: A SYN segment consumes exactly one sequence number, even if it carries zero application payload bytes.
Because TCP is full-duplex, each unidirectional half of a connection must be terminated independently:
Client Server
| |
|--- FIN (seq = u) ------------------------------->| [CLOSE_WAIT]
|<-- ACK (ack = u + 1) ----------------------------|
| |
| (Server continues processing data...) |
| |
|<-- FIN (seq = v) --------------------------------| [LAST_ACK]
|--- ACK (ack = v + 1) --------------------------->| [CLOSED]Note: The host executing the active close enters the TIME_WAIT state, maintaining the port mapping for (Maximum Segment Lifetime). This ensures that any delayed, duplicate segments from the connection are cleared before a new connection utilizes the same port numbers.
TCP utilizes a sliding window for flow control, adjusting the sender's transmission rate based on the receiver's available buffer capacity.
TCP Sliding Window Layout:
+--------------------------------------------------------------+
| ... | Sent & ACKed | Sent, No ACK | Can Send | Cannot Send | ...
+--------------------------------------------------------------+
^ ^ ^
| | |
Left Right Max
Wall Wall EdgeTo prevent a receiver from shrinking its buffer and causing window conflicts, the following mathematical invariant is enforced:
Silly Window Syndrome occurs when TCP segments carry tiny payloads (e.g., of data wrapped in of header), significantly reducing throughput.
TCP handles packet corruption and loss through checksums, sliding-window buffering, and dynamic retransmission timers.
If a segment is lost in transit, subsequent in-order packets will cause the receiver to repeatedly send duplicate ACKs (dupACKs) indicating the sequence number of the missing segment. If the sender receives three duplicate ACKs for the same packet, it bypasses the timer and immediately retransmits the missing segment before the timer expires.
Sender Receiver
|--- Seg 1 ------------------------>|
|--- Seg 2 --------> [LOST] |
|--- Seg 3 ------------------------>| (Out-of-order, sends ACK 2)
|<-- ACK 2 -------------------------| (dupACK 1)
|--- Seg 4 ------------------------>| (Out-of-order, sends ACK 2)
|<-- ACK 2 -------------------------| (dupACK 2)
|--- Seg 5 ------------------------>| (Out-of-order, sends ACK 2)
|<-- ACK 2 -------------------------| (dupACK 3 -> Trigger Fast Retransmit!)
|--- Seg 2 (Retransmitted) -------->| (Success)To prevent the intermediate routers from dropping packets due to queue exhaustion, TCP maintains a Congestion Window (cwnd). The sender's effective transmission window () is bounded by:
The congestion control algorithm is modeled as an state machine with two core phases.
Upon initialization or after a packet loss timeout, cwnd is set to . During the Slow Start phase, cwnd increases exponentially:
This doubling of the window size every RTT continues until cwnd reaches the slow-start threshold (ssthresh).
cwnd (MSS)
^
| / (Congestion Avoidance)
| /
| /
| [ssthresh] /
| |_______/
| /
| / (Slow Start)
| /
| /
|_______________________/_______________________> Time (RTT)Once , TCP enters the Congestion Avoidance phase to probe the network's capacity more carefully. During this phase, cwnd increases linearly:
This increases the window size by approximately per RTT.
The sender then drops back into the Slow Start phase.
cwnd to , it enters Fast Recovery:
The sender then continues with the linear increase of Congestion Avoidance.
TCP dynamically computes its Retransmission Timeout (RTO) using continuous measurements of the round-trip time.
To filter out packet delay spikes, TCP calculates a smoothed RTT () and an RTT deviation ():
Standard filter constants: and .
Using these smoothed metrics, the retransmission timeout value is computed as:
When a packet is retransmitted and an ACK is eventually returned, it is impossible to determine whether the ACK corresponds to the original transmission or the retransmitted packet. To prevent these ambiguous samples from corrupting the RTT estimate, Karn's Algorithm dictates that any RTT sample from a retransmitted segment must be discarded and excluded from the and calculations. Instead, the RTO is temporarily doubled for each consecutive retransmission timeout.
The transport layer is responsible for delivering messages specifically between application processes running on different hosts, utilizing port numbers to distinguish between sockets.
Techniques like Go-Back-N (GBN) and Selective-Repeat (SR) that allow senders to transmit multiple packets before receiving an acknowledgment, maximizing link utilization.
A degradation in routing performance occurring when a sender transmits data in tiny fragments, or a receiver announces tiny window availability, resolved by algorithms like Nagle's and Clark's.
A fundamental connection-establishment mechanism in TCP that synchronizes sequence numbers between two hosts to prevent stale connections from disrupting communication.
The mechanism by which TCP dynamically adjusts its transmission rate (via congestion window adjustment) to avoid overloading the network path, featuring slow start and congestion avoidance.
Test your understanding with 5 questions
In a network system using the Stop-and-Wait protocol, the link bandwidth is $2 \text{ Mbps}$, and the round-trip time (RTT) is $40 \text{ ms}$. If the data packet size is $2,000 \text{ bits}$, what is the utilization efficiency of the channel?
If the sequence number field in a Go-Back-N (GBN) protocol is represented by $m = 4$ bits, what is the maximum allowable window size for the sender ($S_{\text{size}}$) and the receiver ($R_{\text{size}}$) respectively?
In standard TCP, if a computed one's complement checksum of the pseudoheader, TCP header, and data yields all 0s, what value is populated in the checksum field of the outgoing segment?
Consider a TCP implementation where a sender has an estimated smoothed RTT ($RTT_S$) of $2.0 \text{ ms}$ and a deviation ($RTT_D$) of $0.5 \text{ ms}$. If a new sample $RTT_M$ is measured as $4.0 \text{ ms}$, what is the newly updated Retransmission Timeout (RTO) assuming standard parameters ($\alpha = 0.125$ and $\beta = 0.25$)?
Which of the following is the primary mechanism utilized by Clark's solution to prevent Silly Window Syndrome caused by a slow-consuming receiver?
6 Modules
6 Modules