Sub topic 1
What the transport layer adds to IP
Prerequisites
This chapter assumes you know the following:
- The layered network model: application, transport, network and link layers.
- What an IP address is and what a packet is.
- Basic programming. The later chapters use Python, but this one has no code.
What IP gives you, and what it does not
IP, the Internet Protocol, moves packets from one host to another. It is a best-effort service. Each packet is routed on its own, and the network makes no promises about it.
Specifically, IP does not guarantee that:
- A packet arrives. Routers drop packets when queues fill up or when a header is damaged.
- Packets arrive in the order they were sent. Two packets can take different paths.
- A packet arrives only once. A retransmission at a lower layer can produce duplicates.
- The data inside a packet is intact. IP checks only its own header, not the payload.
- The receiver can handle the traffic. IP has no notion of how fast the receiver or the network can go.
IP also addresses only a host. An IP address says which machine should get a packet. It does not say which program on that machine should get it.
The two jobs of the transport layer
The transport layer sits above IP and runs only on the end hosts. Routers in the middle do not look at it. It adds two things.
- Process-to-process delivery. A port number is a 16-bit number that identifies a communication endpoint on a host. The pair of an IP address and a port lets many programs share one machine. Sending data from many programs onto one network connection is called multiplexing. Handing each arriving packet to the right program is called demultiplexing.
- A choice of service quality. The transport protocol decides how much of the missing IP guarantees to rebuild. UDP adds almost nothing beyond ports and an optional error check. TCP adds a connection, ordering, retransmission, flow control and congestion control.
Why the work belongs at the ends
The network core stays simple because the transport layer does its work only on the two end hosts. Routers forward packets quickly without tracking each conversation. Applications that need reliability get it from TCP. Applications that would only be slowed by it can use UDP. This split follows the end-to-end principle: put a function at the ends when only the ends can do it correctly.
A worked example
Suppose your laptop (192.0.2.10) has a browser and a chat client open. Both talk to the same server (198.51.100.5).
| Program | Source IP and port | Destination IP and port |
|---|---|---|
| Browser | 192.0.2.10:51000 | 198.51.100.5:80 |
| Chat client | 192.0.2.10:51001 | 198.51.100.5:5222 |
Both flows use the same IP addresses. IP delivers every packet to the server host. The server's transport layer then reads the destination port in each packet. Port 80 goes to the web server program, and port 5222 goes to the chat server program. Without ports, the server would have no way to separate the two conversations.
Common mistakes
- Treating "reliable" as a property of the network. The network is unreliable by design. Reliability is built by TCP on the end hosts.
- Assuming a port identifies a host. A port only means something together with an IP address. The same port number on two hosts is two different endpoints.
- Assuming TCP and UDP share ports. A TCP port 53 and a UDP port 53 are separate. Each protocol keeps its own port space.
The next chapters take these ideas further. First come ports and sockets in detail, then the two delivery models.
Exercise
A server host receives two packets with the same destination IP address. One has destination port 80 and the other has destination port 5222. Which layer separates them and delivers each to the correct program? Why can IP alone not do it?
Show answer
The transport layer does it, using the destination port number in the transport header. IP only identifies the host and does not read ports, so it cannot tell which program on the host should get each packet.
Exercise
List three things IP does not guarantee that TCP can add.
Show answer
Any three of: delivery of every packet (through retransmission), in-order delivery, no duplicates, intact data (through checksums), and matching the sending rate to the receiver (flow control) and to the network (congestion control).