Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Protocol hierarchies and services

Protocol hierarchies organize network functions in layers where each layer offers services to the layer above via a well-defined interface and implements protocols visible to its peer layer on another host.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Engineers use protocol hierarchies and services to design, debug and reason about networks: layering lets you separate concerns (e.g., routing in the Network layer, reliability in the Transport layer), while clearly defined services and primitives let software call lower-layer functions without knowing the protocol details. Understanding encapsulation, service primitives, SDU/PDU relationships and multiplexing is essential for estimating overheads, building socket servers, and explaining behaviours like fragmentation and reassembly.

Key ideas

Start with definitions (each bolded term defined before use):

  • Protocol: a set of rules that govern the format, timing, sequencing and error control of messages exchanged between peer entities at the same layer on two different systems. (Example: TCP is a transport-layer protocol.)

  • Service: what a layer provides to its immediate upper layer; described in terms of operations (primitives), expected behavior (reliable/unreliable, connection-oriented/connectionless) and parameters. The service abstracts away the details of the protocol.

  • Layering / Protocol hierarchy: organizing network functionality into a stack of layers where each layer uses the services of the layer below and offers services to the layer above. (Example stack to draw: top-to-bottom — Application, Transport, Network, Data Link, Physical.) Multiplexing/demultiplexing: lower layers carry multiple higher-layer protocols, distinguished by fields such as EtherType (L2), IP Protocol (L3), and TCP/UDP port numbers (L4).

  • Service Access Point (SAP): a conceptual point where the service of a lower layer is accessed by the upper layer. Label SAPs at each interface between two adjacent layers in your stack diagram. Examples: at the transport layer, SAPs are port numbers; at the network layer, SAPs are IP addresses; at the data link layer, SAPs are MAC addresses.

  • Service Data Unit (SDU): the unit of data passed from an upper layer to a lower layer via the service interface. It is the data the upper layer wants the lower layer to transmit.

  • Protocol Data Unit (PDU): the unit of data exchanged between peer protocol entities at the same layer over the network; the PDU is the SDU plus the header (and possibly trailer) added by the layer that creates it. Common names by layer: frame (Data Link, L2), packet/datagram (Network, L3), and segment (TCP) or datagram (UDP) at Transport (L4).

  • Encapsulation: the process by which a layer wraps an upper-layer SDU with protocol control information (header/trailer) to form a PDU. Decapsulation is the reverse.

Exact statements commonly required in exams:

  • Encapsulation rule (definition form): When an SDU is passed from layer N+1 to layer N, layer N adds header (and optionally trailer) fields to form the layer-N PDU. That PDU becomes the SDU for layer N-1. Assumption: each layer only relies on the service contract, not on peer implementation.

  • Relationship of SDU/PDU sizes and fragmentation: If the lower layer has a maximum transmission unit (MTU) smaller than the SDU size, the lower layer must segment the SDU into smaller SDUs (fragments) so that each resulting PDU fits within the MTU. Assumption: fragmentation divides data into pieces that the receiver can reassemble; if offsets are required (e.g., IP), they follow protocol-specific rules (IP requires 8-octet multiples for fragment offsets).

  • Service primitive taxonomy: Most textbooks use four primitive types — REQUEST (upper layer asks lower layer to do something), INDICATION (lower layer notifies upper layer of an event), RESPONSE (upper layer replies to an indication), CONFIRM (lower layer confirms a previous request). Exact names may vary by source, but the semantics are as above.

  • Connectionless vs connection-oriented services (formal):

    • Connectionless service: each message is sent independently with no prior setup; there is no per-connection state maintained by the lower layer. Example: UDP provides connectionless transport service.
    • Connection-oriented service: a connection setup phase creates state in the lower layer (addresses, sequence control, timers); data transfer then occurs over that connection; a teardown phase releases state. Example: TCP provides a connection-oriented transport service.
  • Reliable vs unreliable service:

    • Reliable service: the service guarantees delivery of data (possibly in-order) or reports an error; typically implemented using acknowledgements, retransmissions and sequencing.
    • Unreliable service: data may be lost, duplicated or reordered; no guarantee is made.

Diagrams to draw in answers (describe exactly):

  1. Protocol stack and encapsulation: draw five horizontal boxes stacked vertically and label them (top to bottom) Application, Transport, Network, Data Link, Physical. To the right of each box draw a small rectangle labelled SDU_i where i is the layer number (e.g., SDU_4 for Transport). Show arrow downwards: each lower layer adds a header (write +H_i) and forms PDU_i. At the bottom show bits on the wire.

  2. Fragmentation example (IP): draw one large SDU at Transport entering Network layer; draw three output IP fragments labelled Fragment 1: IP header + data part1 (offset=0), Fragment 2: IP header + data part2 (offset=...), Fragment 3: IP header + data part3 (MF flag cleared on last). Label fragment offsets and MF (more fragments) bit.

Assumptions to state in derivations: always state MTU size, header sizes, and whether headers are included in MTU accounting (e.g., IP MTU includes IP header), and whether offsets must be multiples (e.g., 8 bytes for IPv4).

Formulas

PDU_size = SDU_size + H — SDU_size is size of upper-layer data (bytes), H is header+trailer size added by this layer (bytes). Applies when no fragmentation.

fragments = ceil(SDU_size / max_payload_per_fragment) — where max_payload_per_fragment = MTU - H (bytes). Symbols: fragments (dimensionless count), SDU_size (bytes), MTU (bytes), H (bytes). Applies when fragmentation is needed.

payload_fraction = payload_bytes / (payload_bytes + total_header_bytes) — fraction of transmitted bytes that are useful application data. Units: dimensionless. Use to compute effective throughput.

effective_rate = raw_link_rate · payload_fraction — effective data (application) rate in bits/s. raw_link_rate in bits/s.

When offsets require alignment (IPv4): fragment_data_i_size must be multiple of 8 bytes except possibly the last fragment.

Worked examples

Example 1 — IP fragmentation and link overhead (numerical)

Given: application message = 5000 bytes. Assume TCP header = 20 B, IP header = 20 B. Link MTU = 1500 bytes (Ethernet). Ethernet adds header 14 B and trailer 4 B. Assume IPv4 fragmentation requires data fragments in multiples of 8 bytes. Compute number of IP fragments, sizes on the wire, and overall payload fraction.

Step 1: compute total SDU passed to IP (TCP segment size = application + TCP header):

TCP segment (SDU for IP) = 5000 + 20 = 5020 bytes.

Step 2: available payload per IP packet = MTU - IP_header = 1500 - 20 = 1480 bytes. But IPv4 fragment data must be multiple of 8 bytes, so use largest multiple ≤ 1480: 1480 ÷ 8 = 185 exactly, so 1480 is okay.

Step 3: number of IP fragments = ceil(5020 / 1480) = ceil(3.3919...) = 4 fragments.

Step 4: compute sizes of IP fragments (each includes IP header 20 B):

  • Fragment 1 data = 1480, total = 1480 + 20 = 1500 bytes (fits MTU)
  • Fragment 2 data = 1480, total = 1500 bytes
  • Fragment 3 data = 1480, total = 1500 bytes
  • Fragment 4 data = remaining = 5020 - 3·1480 = 580 bytes, total = 580 + 20 = 600 bytes

Step 5: on-wire size includes Ethernet header+trailer per fragment: add 14 + 4 = 18 bytes per frame.

  • Frames 1–3 on wire: 1500 + 18 = 1518 bytes each
  • Frame 4 on wire: 600 + 18 = 618 bytes

Step 6: total bytes on wire = 3·1518 + 618 = 4554 + 618 = 5172 bytes. Total useful application bytes = 5000 bytes.

Step 7: payload fraction = 5000 / 5172 = 0.9667 → 96.67% (rounded). Effective overhead is small here because application large; but fragmentation added extra IP headers and link overhead.

Final answers (bold): number of IP fragments = 4; total bytes on wire = 5172 bytes; payload fraction ≈ 96.7%.

Notes: if you include Ethernet preamble & IFG, add about 20 bytes per frame — verify if needed for exact link-layer accounting.

Example 2 — Multiplexing and demultiplexing (trace)

Scenario: A host runs two TCP servers: Server A listening on port 1000, Server B on port 2000. Two incoming TCP segments arrive at the transport layer with destination ports 1000 and 2000 respectively. Show demultiplexing steps.

Step-by-step trace:

  1. Segment S1 arrives with dst port = 1000. Transport layer looks up endpoint table keyed by (protocol, dst port). It finds Server A's socket. S1 passed to Server A's receive buffer; an indication primitive (DATA.indication) is delivered to the application.
  2. Segment S2 arrives with dst port = 2000. Transport matches to Server B's socket and delivers S2 similarly.

If no socket exists for a dst port, transport sends an error (e.g., TCP sends RST); for UDP, the host typically sends an ICMP Port Unreachable (may be filtered or rate-limited). For exam diagram: draw transport layer with two socket entries (port 1000 -> A, port 2000 -> B), and arrows from incoming segments showing matching.

Example 3 — Service primitives for connection setup (model answer)

Model the three-way handshake of TCP as service primitives between Transport and Application (conceptual):

  • Active opener: Application issues CONNECT.request to Transport
  • Transport sends SYN to peer (wire protocol)
  • Passive opener: upon receiving SYN, Transport delivers CONNECT.indication to the Application; the Application issues CONNECT.response (accept or refuse)
  • After the SYN/SYN-ACK/ACK exchange completes, Transport delivers CONNECT.confirm to the active opener’s Application; the passive opener proceeds to ESTABLISHED after issuing CONNECT.response

A correct exam answer should map the protocol messages (SYN, SYN-ACK, ACK) to the request/indication/confirm primitives and state transitions (CLOSED → SYN-SENT → ESTABLISHED on the active opener).

Common mistakes

  • Forgetting the fragmentation offset alignment (IPv4 requires 8-byte multiples). This changes fragment counts when data sizes are near boundaries.

  • Assuming connection-oriented means reliable. They are independent properties: e.g., a connection-oriented service can be unreliable (in theory) and connectionless services can be made reliable by higher layers.

  • Ignoring link-layer per-frame overhead (Ethernet header/trailer, preamble, IFG) when asked for exact byte counts.

For your exam

Types of questions:

  • Definitions: define protocol, service, SDU, PDU, encapsulation, SAP, primitive types.
  • Short notes: explain encapsulation, explain difference between service and protocol, describe multiplexing/demultiplexing.
  • Derivations: show formula and steps to compute fragment counts and payload fraction given headers and MTU.
  • Numericals: given message sizes and header/MTU values, compute fragments, on-wire bytes, payload fraction.
  • Diagrams: draw a protocol stack showing SDU/PDU and label headers; draw fragmentation and offsets.

What a full-marks answer includes:

  • Precise definitions using bolded terms (protocol vs service);
  • Correct statement of assumptions (MTU value, whether headers included in MTU, alignment requirements);
  • Step-by-step computation with formulas stated before substitution and units carried through;
  • If a diagram is required, draw and label the stack or fragmentation picture exactly as described above;
  • Mention corner cases (e.g., last fragment size, header overhead per fragment) and any protocol-specific constraints (e.g., IPv4 offset multiple).

Quick check

  1. What is the difference between an SDU and a PDU?
  2. Name the four common service primitive types and one sentence about their role.
  3. If MTU = 1200 B, IP header = 20 B, and SDU = 2500 B, how many IP fragments are needed (assume no 8-byte alignment requirement)?

Answers: 1) SDU is data given to a lower layer; PDU is the SDU plus header/trailer created by that lower layer. 2) REQUEST (upper asks lower), INDICATION (lower notifies upper), RESPONSE (upper replies to indication), CONFIRM (lower confirms request). 3) fragments = ceil(2500 / (1200 - 20)) = ceil(2500 / 1180) = 3.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?