Sub topic 1
Why networks are layered
This chapter assumes you know what a computer network and the Internet are, that you can work with bits and bytes, and that you know basic rate units such as bits per second. Layering is the core idea behind every protocol stack, so it comes first.
Prerequisites
You should be comfortable with bits, bytes, and bits per second, and with the idea that two computers exchange messages over links.
Why networks are layered
A network has many hard problems: finding a path, recovering lost data, and driving a cable. Layering splits these into separate jobs. Each layer offers a service to the layer above it and uses the service of the layer below. The layers can then change independently as long as their interfaces stay the same.
The OSI and TCP/IP models layer by layer
The OSI model has seven layers. The TCP/IP model used on the Internet has four or five. For GATE work, learn both:
- Application: user programs such as HTTP and DNS (OSI layers 5 to 7).
- Transport: end-to-end delivery, such as TCP and UDP.
- Network: routing packets across networks, such as IP.
- Link: moving frames across one link, such as Ethernet.
- Physical: sending raw bits over a medium.
Encapsulation and headers as data moves down the stack
As data goes down the stack, each layer adds its own header. The unit at each layer is called a protocol data unit (PDU). At the receiver, each layer strips its header and passes the rest upward.
stack = [("TCP", "src=5000"), ("IP", "dst=10.0.0.2"), ("Ethernet", "dst=AA:BB")]
def encapsulate(data, stack):
for name, header in stack: # innermost header is added first
data = f"<{name} {header}>{data}"
return data
def decapsulate(frame, stack):
for name, header in reversed(stack): # outermost header is removed first
frame = frame.removeprefix(f"<{name} {header}>")
return frame
frame = encapsulate("hello", stack)
print(frame)
print(decapsulate(frame, stack))Which device works at which layer
A hub works at the physical layer and repeats bits. A bridge or switch works at the link layer and forwards frames by MAC address. A router works at the network layer and forwards packets by IP address.
Sharing a link: FDM, TDM and statistical multiplexing
Multiplexing lets several flows share one link. Frequency-division multiplexing (FDM) gives each flow its own frequency band. Time-division multiplexing (TDM) gives each flow fixed time slots. Statistical multiplexing allocates capacity on demand, so idle flows use no slots.
Exercise
Exercise
At the receiver, which header is removed first, and why?
Show answer
The outermost header, which is the Ethernet (link-layer) header, is removed first. It was added last at the sender, so it must be stripped first to reach the IP and then the TCP headers.