Sub topic 1
Why networks are layered
Prerequisites
This chapter assumes you know the following:
- A computer network moves data between machines, and the Internet is a network of networks.
- Data is measured in bits and bytes, and rates in bits per second.
- Basic unit conversion (kilo, mega, milli).
No protocol details are needed yet. Later chapters cover the OSI and TCP/IP layers one by one, along with encapsulation, switching and delay calculations. This chapter explains the idea they all rest on.
The problem layering solves
Sending a web page from a server to your laptop involves many separate jobs:
- Turning bits into electrical, optical or radio signals.
- Detecting and handling transmission errors on each link.
- Choosing a path across many intermediate machines.
- Delivering data to the correct program on the destination machine.
- Recovering lost data and slowing down when the network is congested.
- Presenting the data in a form the application understands.
If one program handled all of this, every application would have to know about every kind of cable, radio and router. Changing the Wi-Fi hardware could break the browser.
Layering divides the work into a stack of levels. Each level does one well-defined job and relies on the level below it. The levels are called layers, and the set of rules a layer follows is its protocol.
Services, interfaces and protocols
Three terms appear in every GATE question on layering. Keep them distinct.
| Term | Meaning | Between whom |
|---|---|---|
| Service | What a layer offers to the layer above it, such as "deliver this segment to the remote process" | Adjacent layers on the same machine |
| Interface | The exact way the upper layer asks for the service (the operations and parameters) | Adjacent layers on the same machine |
| Protocol | The rules and message formats two peer layers on different machines use to implement the service | Same layer on two machines |
Layer N on the sender talks to layer N on the receiver. These two are peer entities. Peers never talk directly. Each message physically travels down the sender's stack, across the network, and up the receiver's stack. The peer conversation is a logical one.
Principles behind the design
Abstraction and information hiding
A layer exposes its service and hides how it is built. The layer above sees only "send this, and it arrives". It does not see whether the layer below uses copper, fiber or radio. This hiding is what allows each layer to change independently.
Modularity and independent change
Because layers talk only through narrow interfaces, you can replace one layer's implementation without touching the others. Examples:
- IP runs over Ethernet, Wi-Fi, fiber and cellular links. The layers above IP do not change.
- A browser using HTTP works the same over a wired or wireless link.
- A new transport protocol can be introduced without redesigning cables.
Reuse
Many applications share one lower-layer service. Email, web and file transfer all use the same transport and network layers. Without layering, each would carry its own copy of that code.
Easier design, testing and standardization
Each layer is small enough to specify and test on its own. Different vendors can build to the same layer specification and still interoperate. Standards bodies can also work on layers in parallel.
Each layer adds one set of functions
A layer typically adds some of the following to what it receives:
- Addressing, so the receiver is identified at that level.
- Error control, such as detecting corrupted data.
- Flow control, so a fast sender does not overwhelm a slow receiver.
- Multiplexing, so several upper-layer users share one lower-layer service.
Later chapters show which layer does which.
A small model of layering in code
The sketch below models a three-layer stack. Each layer exposes send and receive, wraps or unwraps its own header, and knows nothing about the layers' internals except through that call. It is a teaching model, not real networking code.
class Layer:
def __init__(self, name, lower=None):
self.name = name
self.lower = lower # service provider below
self.upper = None # service user above
if lower:
lower.upper = self
def send(self, data):
framed = f"[{self.name}]" + data # add this layer's header
if self.lower:
return self.lower.send(framed)
return framed # bottom layer: "the wire"
def receive(self, data):
header = f"[{self.name}]"
assert data.startswith(header), "peer protocol violated"
payload = data[len(header):] # strip this layer's header
return self.upper.receive(payload) if self.upper else payload
def build_stack():
link = Layer("link")
network = Layer("net", lower=link)
transport = Layer("transport", lower=network)
return transport, link
sender_top, _ = build_stack()
receiver_top, receiver_bottom = build_stack()
wire = sender_top.send("hello")
print(wire) # [link][net][transport]hello
print(receiver_bottom.receive(wire)) # helloRunning it prints [link][net][transport]hello and then hello. The transport layer added its header first, and the link layer's header is outermost. On the receiving side the headers are removed in reverse order. The idea of wrapping data with a header at each layer is called encapsulation, and a later chapter covers it in detail.
Each layer checks only its own header. The link layer never inspects the transport header. That is information hiding in practice.
Costs and criticisms of layering
Layering is a trade-off, not a free gain. Know these costs for conceptual questions.
- Overhead. Every layer adds a header, so more bytes travel per useful byte of data.
- Duplicated functions. Error detection can appear at several layers, which wastes work.
- Hidden information. A lower layer's knowledge (for example, that a wireless link lost a frame because of noise, not congestion) is not visible above. A higher layer may then react wrongly.
- Strict ordering. A layer may only call the layer directly below. Shortcuts across layers (cross-layer designs) break the clean model, though they are sometimes used for performance.
- Layer boundaries are a design choice. Not every function has an obvious home, and different models draw the lines differently.
Common errors
- Confusing service and protocol. A service is what a layer offers upward. A protocol is how peers on different machines implement it. Protocol messages are exchanged between peers, and service calls happen between adjacent layers.
- Thinking peers connect directly. Layer N on host A never has a physical link to layer N on host B (except at the physical layer).
- Assuming one layer's header is readable by all. A layer treats everything from above as opaque payload.
- Assuming a layer can be removed freely. Removing a layer means its functions must be provided elsewhere.
- Assuming more layers is always better. More layers give finer modularity but add header overhead and processing.
How this connects to what follows
- The next chapter names the layers of the OSI and TCP/IP models and the job of each.
- The chapter after that shows how headers are added and removed on the way down and up the stack.
- Later chapters show that network devices are classified by the highest layer they inspect.
- The delay and throughput chapters use header overhead and per-link behavior, which come directly from layering.
Exercise
Host A's transport layer sends a segment to Host B's transport layer. State which of the following is a service, an interface and a protocol: (a) the rules for the segment format exchanged between the two transport layers, (b) the set of calls the transport layer uses to ask the network layer to carry data, (c) the delivery of data to the remote process offered to the application layer.
Show answer
(a) is a protocol, because it governs messages between peer transport layers on two hosts. (b) is an interface, because it defines how adjacent layers on one host request a service. (c) is a service, because it is what the transport layer provides to the layer above.
Exercise
A network engineer replaces a copper Ethernet link with a fiber link, and no software above the link layer needs a change. Which design principle makes this possible, and what does the upper layer see?
Show answer
Information hiding (abstraction) with a stable interface. The network layer sees the same service from the link layer, namely frame delivery over a link, and does not see the medium used to implement it.
Exercise
Give two disadvantages of layering and one reason a designer still accepts them.
Show answer
Disadvantages: header overhead on every layer, and hidden lower-layer information that can lead higher layers to wrong decisions (also duplicated functions). A designer accepts them because modularity lets each layer be built, tested, replaced and standardized independently, and lets many applications reuse the same lower layers.