Show understanding of how protocol implementation can be viewed as a stack, where each layer has its own functionality

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – Protocols (Stack \cdot iew)

14.1 Protocols – The Stack \cdot iew

In networking, a protocol defines the rules for communication between two entities. Implementations of protocols are typically organised as a stack of layers, each providing a distinct set of services to the layer above it and using services from the layer below it.

Why a Stack?

  • Separation of concerns – each layer handles a specific aspect of communication.
  • Modularity – layers can be developed, tested and replaced independently.
  • Interoperability – standardised interfaces allow different vendors’ equipment to work together.

Typical Layer Models

The most widely referenced models are the OSI (Open Systems Interconnection) model and the TCP/IP model. Both present a vertical stack, but the number of layers and their responsibilities differ.

OSI Model – Seven Layers

Layer (Top‑down)NamePrimary Function
7ApplicationProvides network services to end‑user applications (e.g., HTTP, SMTP).
6PresentationData representation, encryption, compression.
5SessionEstablishes, manages and terminates sessions.
4TransportEnd‑to‑end reliability, flow control (e.g., TCP, UDP).
3NetworkLogical addressing and routing (e.g., IP).
2Data LinkPhysical addressing, error detection/correction on a link (e.g., Ethernet, PPP).
1PhysicalTransmission of raw bits over a medium (e.g., cables, radio).

TCP/IP Model – Four Layers

  • Application – Combines OSI’s Application, Presentation and Session layers.
  • Transport – Provides end‑to‑end services (TCP, UDP).
  • Internet – Handles logical addressing and routing (IP, ICMP).
  • Link – Encompasses OSI’s Data Link and Physical layers (Ethernet, Wi‑Fi).

How Data Moves Through the Stack

When a program sends data, the following steps occur (illustrated for the TCP/IP model):

  1. Application Layer: Data is generated and possibly encoded (e.g., HTTP request).
  2. Transport Layer: Data is segmented, a header with source/destination ports is added, and reliability mechanisms (ACK, retransmission) are applied if using TCP.
  3. Internet Layer: Each segment receives an IP header containing source/destination IP addresses.
  4. Link Layer: The packet is framed with MAC addresses and a CRC for error detection.
  5. Physical Layer: The frame is converted to electrical, optical or radio signals and transmitted over the medium.

At the receiving end, each layer strips off its own header/footer (the reverse process) and passes the remaining data upward.

Mathematical \cdot iew of Layer Interaction

If we denote the data generated by the application as \$D\$, and each layer’s encapsulation function as \$E_i\$, then the transmitted bit‑stream \$B\$ can be expressed as:

\$B = E{\text{Physical}}\bigl(E{\text{Link}}\bigl(E{\text{Internet}}\bigl(E{\text{Transport}}(D)\bigr)\bigr)\bigr)\$

Conversely, the receiver applies the inverse functions \$D_i\$ (decapsulation) to recover \$D\$:

\$D = D{\text{Transport}}\bigl(D{\text{Internet}}\bigl(D{\text{Link}}\bigl(D{\text{Physical}}(B)\bigr)\bigr)\bigr)\$

Key Functions of Individual Layers

  • Physical: Signal generation, bit timing, voltage levels.
  • Data Link: Frame delimitation, MAC addressing, error detection (CRC), flow control (e.g., Ethernet PAUSE frames).
  • Network: Routing, fragmentation/reassembly, logical addressing (IP).
  • Transport: Port multiplexing, reliability (TCP), connectionless service (UDP), congestion control.
  • Application: Protocols specific to user services (HTTP, FTP, DNS).

Implementation Considerations

When implementing a protocol stack, developers must decide:

  1. Whether to implement a monolithic stack (all layers in one codebase) or a modular stack (separate libraries).
  2. How to expose the interface between layers – usually via well‑defined function calls or message queues.
  3. Performance trade‑offs: adding headers increases overhead; deep stacks may introduce latency.
  4. Security: which layers need encryption or authentication (e.g., TLS at the Application layer, IPsec at the Network layer).

Suggested Diagram

Suggested diagram: A vertical stack showing the OSI/TCP‑IP layers with arrows indicating encapsulation (downward) and decapsulation (upward). Each layer box lists its main protocols and responsibilities.

Summary

Viewing protocol implementation as a stack clarifies how complex communication tasks are broken into manageable, reusable pieces. Each layer adds or removes its own control information, allowing the system to evolve, interoperate, and be debugged more easily.