Network Types, Layers and Protocols

IB Computer Science · Networks

Types of network. A LAN covers a single site and is usually owned by one organisation. A WAN connects sites over a wide area and normally uses infrastructure leased from a carrier. A WLAN is a LAN using radio rather than cable. A VLAN divides one physical network into separate logical networks so that traffic from different departments is isolated without laying new cable. A PAN covers a few metres around one person; a SAN is a dedicated high-speed network for storage devices. A VPN creates an encrypted tunnel across a public network so that a remote user appears to be inside the organisation's network.

Why protocols and standards exist. A protocol is an agreed set of rules for communication: message format, ordering, timing, error handling and how data flow is controlled. Without shared protocols, equipment from different manufacturers could not interoperate, so standards are what make a network of networks possible at all.

Layering and encapsulation. Protocols are organised into layers. As data travels down the stack on the sending machine each layer adds its own header: the transport layer adds port numbers and sequence numbers, the network layer adds source and destination IP addresses, the data link layer adds the next-hop MAC address and an error check. The receiver removes these headers in reverse order. The reason for layering is independence: each layer only reads its own header and only talks to the layers immediately above and below it, so a technology can be replaced in one layer — cable to Wi-Fi, for example — without changing anything above it.

Packet switching. Data is divided into packets, each carrying addressing information, and each packet is routed independently. This shares links efficiently, because a link left idle by one conversation is immediately usable by another, and it is resilient, because packets route around a failed link. The costs are that packets can arrive out of order or be lost, and that delay varies. Circuit switching reserves a dedicated path for the whole conversation: it guarantees bandwidth and constant delay but wastes capacity while idle.

Key protocols and devices. TCP is connection-oriented and reliable: it numbers segments, requires acknowledgements and retransmits what is lost. UDP is connectionless and does not retransmit, which is chosen deliberately for live audio and video where a late packet is worse than a missing one. IP handles addressing and routing between networks. DNS translates domain names into IP addresses. A switch forwards frames within a LAN using MAC addresses; a router forwards packets between networks using IP addresses.

ENCAPSULATING DATA THROUGH THE PROTOCOL LAYERS SENDER — going down RECEIVER — going up APPLICATION DATA HTTP · FTP · SMTP TRANSPORT TCP data port · sequence number NETWORK IP TCP + data IP address · routing LINK MAC IP + TCP + data MAC address · error check APPLICATION — DATA TRANSPORT — remove TCP header reorder · acknowledge NETWORK — remove IP header right destination yet? LINK — remove MAC header check frame for errors PHYSICAL NETWORK packets travel INDEPENDENTLY Each layer reads ONLY its own header — that is why changing technology in one layer does not break the others The receiver removes headers in the OPPOSITE ORDER to the sender
This figure answers the two questions most often set in the networking topic: what is encapsulation, and why use layers. Encapsulation. Application data goes down, and each layer wraps on another layer of its own header. The transport layer adds port numbers and a sequence number so the receiver knows which application the data belongs to and can reassemble it in the right order. The network layer adds the source and destination IP addresses so routers know where to forward it. The link layer adds the MAC address of the next hop together with an error-check code. At the receiver, the process runs in reverse: each layer removes exactly its own header and passes the rest upward. Why layers, and this is the point that earns marks. Each layer reads only its own header and communicates only with the layer directly above and below. The consequence is that technology in one layer can be changed without modifying the other layers: switching from copper cable to Wi-Fi replaces the link layer, but the browser at the application layer does not need to know and does not need a single line of code changed. Layering also lets equipment from many different vendors work together, because each vendor only needs to comply with the interface between layers. The detail in the bottom middle box is also often asked about. On the physical network, the packets of one file travel independently and may take different routes, so they may arrive out of order or be lost. That is why the transport layer must carry sequence numbers and an acknowledgment mechanism — that is the job of TCP, and also what UDP deliberately drops in exchange for low latency.

Worked example: Why online voice calls use UDP instead of TCP

A voice-calling and online meeting application uses UDP for the audio and video streams, but uses TCP for text chat and for sending files. Explain this choice.

Solution

The key point: TCP is not "better" than UDP; the two protocols optimize for two different things. TCP optimizes for integrity, UDP optimizes for low latency, and you cannot have both at once.

The mechanism of TCP and its price. TCP numbers each segment, waits for acknowledgments, and retransmits if no acknowledgment is received within a time limit. It also holds back segments that have arrived while waiting for the missing one, in order to deliver them to the application in the correct order. The price is this: when a packet is lost, TCP must wait for the timeout, retransmit, then wait for that packet to arrive — and during all that time, every packet that arrived after it is held back and not yet delivered upward.

Why that is a disaster for live audio. Sound in a call is meaningful only if it arrives on time. If a packet containing 20 milliseconds of speech is lost, retransmitting it takes at least one round trip — often tens to hundreds of milliseconds — and by the time it arrives, that moment in the conversation has passed. Worse, waiting for it holds back all the sound after it, so the listener gets a silence followed by a burst. Whereas if the lost packet is simply IGNORED, the listener meets only a very brief defect that the ear hardly notices, especially when the decoder has a concealment mechanism. So a late packet is worse than a missing packet.

Why text chat and file sending are the opposite. Here integrity is absolute and latency hardly matters. A message missing a few characters is meaningless; a file missing a few bytes can be completely corrupted. Users fully accept a message arriving 200 milliseconds later, but do not accept it arriving wrong. So TCP is the right choice.

The general sentence for answering every question of this kind. Ask: for this data, which is worse, losing a small part or being slightly late. If late is worse, choose UDP; if loss is worse, choose TCP. Complex applications often use both for different streams, exactly as in the situation in the question.

Worked example: Tracing the journey of a web request

A user types a web page address into the browser. Describe what happens at the network level until the page begins to display, stating clearly the roles of DNS, IP, TCP, the switch and the router.

Solution

Step 1 — resolving the domain name. The browser has only a string of characters, but the network routes by numbers. The computer sends a query to a DNS server asking for the IP address corresponding to that domain name. If the result is already in the cache of the computer or the home router, this step is almost instant; if not, the query goes up the hierarchical system of name servers. This is why the first visit to an unfamiliar page is usually slower than later visits.

Step 2 — establishing the TCP connection. Once it has the IP address, the browser opens a TCP connection to the web server's port. TCP is connection-oriented, so before data is transmitted there is a handshake procedure for the two sides to agree on starting sequence numbers and confirm the other side is ready. This procedure costs one round trip, and is part of the latency the user perceives.

Step 3 — encapsulating and sending the request. The browser creates an HTTP request at the application layer. The transport layer wraps it in a TCP segment with port numbers and a sequence number. The network layer wraps it further into an IP packet carrying the source and destination IP addresses. The link layer wraps it into a frame carrying the MAC address of the next hop — usually the home router — together with an error-check code.

Step 4 — within the local network. The switch receives the frame and reads the destination MAC address to forward it to the right physical port. It works entirely at the link layer and does not care about the IP contents inside.

Step 5 — between networks. The router opens up the frame layer, reads the destination IP address, looks up the routing table to choose the next hop, then re-encapsulates it as a NEW frame with the MAC address of that next hop. A detail worth remembering: the source and destination IP addresses stay the same throughout the journey, while the MAC address is replaced at each hop. This is where the roles of the two kinds of address are clearly distinguished and it is a commonly asked question.

Step 6 — receiving and reassembling. The web page is divided into many packets, and these packets travel independently so they may take different routes and arrive out of order. The transport layer at the receiving machine uses the sequence numbers to put them back in the right order, sends acknowledgments for what has arrived, and requests retransmission of what is missing. Only when the data is complete and in order is it delivered up to the browser for display.

Common mistake

Trap 1 — saying TCP is better than UDP. The two protocols optimize for two opposing things: TCP for integrity, UDP for low latency. The right question is, for this data, which is worse: losing a small part or being slightly late.
Trap 2 — confusing the roles of the switch and the router. A switch works WITHIN a local network based on MAC addresses; a router works BETWEEN networks based on IP addresses. And remember that the IP address stays the same throughout the journey while the MAC address is replaced at each hop.
Trap 3 — stating layering without stating its BENEFIT. The benefit is independence: changing technology in one layer does not force changes in the other layers, and equipment from many vendors works together. Without this point you cannot earn the explanation mark.

Key takeaway

Lesson 1 summary. Four things to take into the exam. One, encapsulation — each layer adds its own header on the way down and the receiver removes them in reverse order — together with the reason for layering being independence. Two, packet switching versus circuit switching, with the advantages of efficient sharing of the link and good resilience, and the drawbacks of variable delay and packets possibly arriving out of order. Three, TCP versus UDP decided by whether loss or delay is worse. Four, a switch uses MAC within a network, a router uses IP between networks, and the MAC address is replaced at each hop while the IP address is not.

← Operating System Services, Application Software and Character Encoding · All IB Computer Science lessons · Practice IB Computer Science questions (free, instant scoring) · Transmission Performance, Wireless and Network Security →