Computer Networking › Section C · The transport layer › Topic C.1
Transport-layer services
The network layer can get a packet to the right computer, but a computer runs dozens of networked programs at once. The transport layer finishes the job: it turns delivery between hosts into communication between processes, and it decides how much reliability that communication gets.
From hosts to processes
When your browser fetches a page, it behaves as if it had a private pipe to a web server process on another continent. That is logical communication: the two processes seem directly connected, although their data crosses many routers and links. Providing this illusion is the job of the transport layer, which sits between the application and network layers. The internet offers two main transport protocols, UDP and TCP, and a programmer chooses between them when creating a socket, as the topic Socket programming shows.
Segments and where they are built
On the sending host, the transport layer may split an application message into chunks and adds its own header to each, producing a segment. It hands each segment to the network layer, which wraps it in an IP datagram and sends it towards the destination. On the receiving host the steps run in reverse: the network layer unwraps the datagram and passes the segment up, and the transport layer delivers its data to the right process. Transport protocols run only in end systems. A router forwarding the datagram reads the network-layer header and, in the classic layered design, ignores the segment inside. Devices that do inspect transport headers, such as firewalls and NAT boxes, are covered in the topic Middleboxes.
Two layers, two kinds of delivery
The distinction between the layers is subtle but important. The network layer provides logical communication between hosts; the transport layer provides logical communication between processes on those hosts. Picture a large office block. The postal service brings every letter addressed to the building to its mail room, and a clerk there sorts the letters and carries each one to the right desk. The postal service plays the network layer, the clerk plays the transport layer, the building is the host and each desk is a process. The clerk has no say over how letters move between cities, just as transport protocols have no control over the network core.
IP's best-effort service
The internet's network-layer protocol is IP, the Internet Protocol, and every host has at least one IP address. IP offers a best-effort service: it tries to deliver each datagram but promises nothing. Datagrams may be lost, delivered out of order, duplicated, or have their bits corrupted on the way, and IP will not notice or repair any of it. For this reason IP is called an unreliable service, and anything better must be built by the end hosts.
What transport can and cannot add
The service below limits the service above. IP gives no bound on delay and no guaranteed bandwidth, so no transport protocol running over it can promise an application a maximum delay or a minimum throughput. The mail clerk cannot promise next-day delivery if the postal service does not. Some services, however, can be built at the ends even when the network lacks them. A transport protocol can deliver data reliably and in order over a network that loses and reorders packets, using acknowledgements, retransmission and sequence numbers. It can also encrypt data so eavesdroppers cannot read it, which the topic Securing TCP connections: TLS explains.
UDP: the minimum service
The most basic duty of both UDP and TCP is to extend IP's host-to-host delivery into process-to-process delivery, using port numbers in each segment header. This is called multiplexing and demultiplexing, the subject of the next topic. Both protocols also include a checksum, an error-detection field that lets the receiver spot corrupted bits. Those two services are all that UDP, the User Datagram Protocol, provides. Like IP it is unreliable: a UDP segment may never arrive, may arrive twice, or may arrive after a later one, and UDP will not tell the application. There is no handshake before data is sent, so UDP is called connectionless.
TCP: a reliable byte stream
TCP, the Transmission Control Protocol, adds much more. It is connection-oriented: the two hosts exchange setup messages before any data flows. It provides reliable data transfer, so the bytes one process writes arrive at the other complete, uncorrupted and in order, using sequence numbers, acknowledgements, timers and retransmission. It provides flow control, so a fast sender cannot overflow a slow receiver's buffer. It also provides congestion control, which serves the shared network more than the application: it slows a sender when the path is overloaded, so connections sharing a busy link each get a reasonable share. UDP senders face no such limit.
Worked example: one stream, two protocols
A sender transmits five segments, numbered 1 to 5. The network loses segment 4, delivers segment 3 before segment 2, and flips one bit in segment 5. What does each protocol hand to the receiving process? 1. Under UDP, the receiver checks each checksum. Segment 5 fails and is typically discarded. 2. The application receives segments 1, 3 and 2, in that order, and is never told that 4 and 5 existed. 3. Under TCP, the receiver also discards segment 5, holds segment 3 until segment 2 arrives, and the sender retransmits segments 4 and 5 when they are not acknowledged. 4. The application receives the data of 1, 2, 3, 4 and 5 in order. Check: TCP's result costs extra time for the retransmissions, which is the price of reliability.
Worked example: choosing a transport
Decide which protocol suits each application. 1. A file-transfer tool must deliver every byte exactly and can tolerate some extra delay, so it uses TCP. 2. A voice call sends a small audio chunk every 20 milliseconds; a chunk half a second late is useless, and losing an occasional one is barely audible, so it typically uses UDP. 3. A DNS query fits in a single segment; a TCP handshake would add a round trip before the question is even asked, so it normally uses UDP and asks again if no reply comes. Check: each choice matches the needs described in the topic Principles of network applications.
Segment or datagram?
Terminology varies between sources. The standards documents, called RFCs, usually call a TCP packet a segment and a UDP packet a datagram, but they also call the network-layer packet a datagram. To avoid confusion, this course calls every transport-layer packet, TCP or UDP, a segment, and keeps the word datagram for the IP packet that carries it.
Common mistakes to avoid
First, thinking routers run TCP or UDP for traffic passing through; transport protocols live in the end hosts. Second, believing TCP makes IP reliable; IP stays best effort, and TCP recovers losses at the ends. Third, expecting any transport protocol to guarantee delay or bandwidth over IP, which offers neither. Fourth, assuming UDP has no error checking at all; it has a checksum but does not repair or report errors. Fifth, treating congestion control as flow control: one protects the network, the other protects the receiver.
Key takeaways
The transport layer gives processes on different hosts logical communication, running only in end systems and wrapping data in segments carried inside IP datagrams. The network layer delivers between hosts, the transport layer between processes. IP is best effort: datagrams may be lost, reordered, duplicated or corrupted. Transport cannot add delay or bandwidth guarantees that IP lacks, but it can add reliability and encryption. UDP offers only multiplexing and a checksum, with no connection. TCP adds connection setup, reliable in-order delivery, flow control and congestion control.
Flashcards
Flashcard
Processes behave as if directly connected, though data crosses many routers
Test your understanding
Question 1 of 5
Which statement best describes the difference between the network layer and the transport layer?
Question 2 of 5
A developer wants her app to be guaranteed a delay under 100 ms across the public internet. Why can no transport protocol promise this?
Question 3 of 5
Which pair lists all the services UDP provides?
Question 4 of 5
Segments 1 to 4 are sent; segment 2 is lost and segment 4 arrives before segment 3. Over UDP, what does the receiving application get?
Question 5 of 5
Which TCP service mainly protects the network as a whole rather than the receiving application?
