Layering and Switching
Networking is a large subject held together by one structural idea and one performance idea.
The organising fact is that a layer is a contract with three parts: it offers a service to the layer above, uses the service of the layer below, and speaks a protocol with its peer on the other machine.
Almost every conceptual question in networking is deciding which layer owns a problem. Error detection appears at the data link layer and again at the transport layer, and the reason they are not redundant is that they protect different spans.
The second organising fact is that end-to-end delay has four independent components, and confusing them is the single largest source of lost marks in this subject. Transmission delay depends on message size and link rate. Propagation delay depends on distance and signal speed. The two have nothing to do with each other.
The third is that switching is a decision about when resources are committed. Circuit switching commits them before any data flows. Packet switching commits nothing and lets packets contend. Virtual circuits commit a path but not a rate.
1. Why Layering
Layering decomposes a hard problem into pieces with stable interfaces, so that a change inside one layer does not propagate outward.
Replacing copper with fibre changes the physical layer alone. Replacing IPv4 with IPv6 changes the network layer, and applications largely continue working.
The cost is efficiency. Each layer adds a header, and information one layer discards may be exactly what another needs, which is why cross-layer optimisation keeps being proposed.
A wireless link makes the cost concrete. The data link layer sees a lost frame and retransmits; the transport layer sees the resulting delay and infers congestion that does not exist, and slows down for no reason.
Neither layer is wrong. Each is doing exactly what its contract specifies, and the loss of information at the boundary is what produces the bad outcome.
A protocol data unit at layer becomes the payload of layer , a process called encapsulation. Headers accumulate on the way down and are stripped on the way up.
The names differ by layer: a segment at the transport layer, a packet or datagram at the network layer, a frame at the data link layer, and bits at the physical layer.
2. The OSI Model
Seven layers, from the bottom up.
Physical transmits raw bits over a medium, defining voltages, connectors and data rates.
Data link turns a raw bit stream into a reliable link between adjacent nodes, handling framing, error detection, flow control and medium access.
Network moves packets from source to destination across multiple links, handling routing, addressing and congestion.
Transport provides end-to-end delivery between processes, handling segmentation, reliability, flow control and multiplexing.
Session manages dialogues, including checkpointing and recovery.
Presentation handles syntax: encoding, encryption and compression.
Application provides services directly to user programs.
The mnemonic worth having is the addressing at each level. Physical has none, data link uses MAC addresses, network uses IP addresses, transport uses port numbers, and application uses names.
3. TCP/IP and the Comparison
The TCP/IP model has four layers: link, internet, transport and application, with the physical layer sometimes separated to give five.
Session and presentation have no counterpart and their functions are left to applications.
The models differ in more than layer count.
| Aspect | OSI | TCP/IP |
|---|---|---|
| Origin | Designed first, then implemented | Protocols first, model described later |
| Layers | 7 | 4 or 5 |
| Network layer service | Both connectionless and connection-oriented | Connectionless only |
| Transport layer service | Connection-oriented only originally | Both, through TCP and UDP |
| Practical status | Reference model | What actually runs |
OSI's lasting contribution is the vocabulary, since the layer numbers are still how engineers describe where a problem lives.
4. Services and Primitives
A connection-oriented service establishes a connection, transfers data, and releases it, guaranteeing ordered delivery within that connection.
A connectionless service sends each unit independently, with no setup and no ordering guarantee.
Reliability is a separate axis from connection orientation. A service can be connection-oriented and unreliable, or connectionless and acknowledged, though the common combinations are reliable connection-oriented and unreliable connectionless.
Five service primitives describe the interface: listen, connect, accept, send or receive, and disconnect.
5. Switching
Circuit switching reserves a dedicated path with a guaranteed rate for the whole conversation.
Three phases occur: setup, data transfer, and teardown.
Its advantage is a guaranteed rate with no per-packet header and no queueing delay. Its cost is that the reservation is held whether or not data flows, so bursty traffic wastes most of the capacity.
Packet switching sends independently routed packets with no reservation.
Statistical multiplexing is what makes it efficient: because sources are bursty and rarely peak together, a link can serve far more users than its capacity divided by peak rate would suggest.
Its cost is queueing delay and the possibility of loss, since nothing is reserved and a burst can exceed a link's capacity.
Store-and-forward means a router must receive a packet entirely before forwarding it, which is why each hop adds a full transmission delay.
Virtual circuit switching is the middle position. A setup phase establishes a path and installs forwarding table entries, and every packet carries a short circuit identifier rather than a full destination address.
| Property | Datagram | Virtual circuit |
|---|---|---|
| Setup phase | None | Required |
| Addressing | Full destination in every packet | Short circuit identifier |
| Router state | Per destination | Per connection |
| Path | May differ per packet | Fixed for the connection |
| Ordering | Not guaranteed | Preserved |
| Router failure | Affects packets in transit only | Terminates all circuits through it |
6. Delay and Throughput
Four delay components exist at each hop.
Processing delay is the time to examine the header and decide an output link, typically microseconds.
Queueing delay is the time waiting behind other packets, and is the only component that varies with load.
Transmission delay is packet length divided by link rate, the time to push the bits onto the wire.
Propagation delay is distance divided by signal speed, the time for a bit to travel, typically two thirds the speed of light in copper or fibre.
Transmission and propagation delay are independent. Doubling the link rate halves transmission delay and leaves propagation delay untouched.
The bandwidth-delay product is the link rate times the propagation delay, and it measures how many bits are in flight on the link at once.
It is the right way to think about a link as a pipe: rate is the diameter and propagation delay is the length, so the product is the volume.
Throughput is bounded by the slowest link on the path, called the bottleneck, regardless of how fast the others are.
Round-trip time is twice the propagation delay plus the transmission and queueing delays in both directions, and it is the quantity most protocol behaviour is timed against.
Multiplexing
Multiplexing shares one medium among several conversations, and the four schemes differ in what they divide.
Frequency division multiplexing gives each conversation its own frequency band for the whole time, with guard bands between them to limit interference.
Time division multiplexing gives each the whole bandwidth for a fixed recurring slot. A slot is reserved whether or not its owner has data, which is what makes it synchronous.
Wavelength division multiplexing is frequency division applied to optical fibre, with each wavelength carrying an independent channel.
Statistical time division multiplexing allocates slots on demand rather than by rotation, which is what packet switching does and why it supports more users than the sum of their peak rates would allow.
The distinction between synchronous and statistical multiplexing is exactly the distinction between circuit and packet switching, viewed at the level of the link rather than the network.
7. Worked Examples
Example 1. A message of 10 megabits is sent from source to destination across 3 links, each of rate 10 megabits per second, with propagation delay ignored and store-and-forward routers. Compare sending it as one packet against splitting it into 10 packets of 1 megabit.
As one packet, each of the 3 links must transmit the entire 10 megabits.
Transmission delay per link is second.
Because routers are store-and-forward, the hops are sequential, so the total is seconds.
As 10 packets of 1 megabit, each transmission takes seconds.
Now the hops overlap. While the second link transmits packet 1, the first link is already transmitting packet 2.
The first packet arrives after 3 transmissions, taking seconds. Each subsequent packet arrives seconds later, and there are 9 more.
Total is seconds.
The general formula for packets over links is times the per-packet transmission time.
Checking: seconds.
The improvement from 3 seconds to 1.2 is pipelining, and it is the fundamental argument for packetisation.
Example 2. Why is there an optimal packet size, and what happens on either side of it?
Smaller packets pipeline better, as the previous example showed, since the first link starts on packet two sooner.
But every packet carries a header, so smaller packets mean the same payload costs more total bits.
Consider a message of bits, header bits per packet, and payload bits per packet, over links at rate .
The number of packets is , and each transmission takes .
Total time is .
As grows, the pipelining term shrinks but the per-packet cost grows. The product has a minimum.
As approaches zero, the header dominates completely and the total time diverges, since almost every bit transmitted is overhead.
As approaches the whole message, pipelining vanishes and the time approaches times the full transmission, the one-packet case.
Real networks resolve this empirically. Ethernet settled on a 1500-byte payload with a 14-byte header, giving about one percent overhead while keeping packets small enough that one flow cannot monopolise a link for long.
Example 3. A link has rate 1 gigabit per second and a one-way propagation delay of 10 milliseconds. Compute the bandwidth-delay product and explain what it means for a sender.
The product is rate times delay.
bits, which is 10 megabits, or 1.25 megabytes.
This is the number of bits in flight when the sender is transmitting continuously.
Interpret the link as a pipe. Rate is the cross-sectional area and propagation delay is the length, so the product is the volume the pipe holds.
The consequence for a sender is decisive. If the protocol requires an acknowledgement before sending more, and the window is smaller than 10 megabits, the sender goes idle waiting.
With a window of 64 kilobytes, which is 512 kilobits, the sender transmits for 0.5 milliseconds and then waits 20 milliseconds for the round trip.
Utilisation is roughly , about 2.4 percent, on a gigabit link.
This is exactly why TCP needed the window scaling option, since the original 16-bit window field caps at 64 kilobytes and cannot fill a modern long-distance link.
Example 4. A user sends a 1000-byte file. Compute the total bytes on the wire given a 20-byte TCP header, a 20-byte IP header and an 18-byte Ethernet header and trailer, with a maximum payload of 1460 bytes.
The file fits in one segment, since 1000 is below 1460.
At the transport layer, the segment is 1000 bytes of data plus a 20-byte TCP header, giving 1020 bytes.
At the network layer, that whole segment becomes the payload of an IP packet, adding 20 bytes, giving 1040.
At the data link layer, the packet becomes the payload of an Ethernet frame, adding 18 bytes, giving 1058 bytes on the wire.
Overhead is 58 bytes out of 1058, about 5.5 percent.
Now repeat with a 1-byte payload, as an interactive keystroke produces.
The total is bytes to carry one byte, an overhead of 98.3 percent.
This is the encapsulation cost that layering imposes, and it is why interactive protocols batch keystrokes and why header compression exists on slow links.
Example 5. A network has 5 routers on the path. Under datagram switching, how much state does each router hold, and how does that change under virtual circuits with 1000 active connections?
Under datagram switching, a router holds one forwarding entry per destination prefix, not per connection.
The table size depends on the size of the network, not on the traffic, so it is the same whether 10 or 10 million connections are active.
Under virtual circuits, each router on a path holds one entry per circuit passing through it.
With 1000 active connections through this router, it holds 1000 entries.
The trade is clear. Virtual circuits move work from the packet to the setup: each packet carries a short identifier and needs only a table lookup, while a datagram carries a full address and may need a longest-prefix match.
But virtual circuit state is per-connection, so it scales with traffic, and a busy core router would need millions of entries.
Failure behaviour differs sharply too. If this router fails under datagram switching, packets in transit are lost but routing reconverges and the flows continue on another path.
Under virtual circuits, every circuit through the failed router is torn down and each must be re-established, because the state that defined the path is gone.
That difference is why the internet chose datagrams, having been designed for survivability, and why virtual circuits survive mainly inside carrier networks where state is manageable and guarantees are sold.
Example 6. For each of the following, name the layer that owns it and say why: converting bits to voltages, retransmitting a lost segment end-to-end, choosing a next hop, detecting a corrupted frame, distinguishing two browser tabs on one host.
Converting bits to voltages is the physical layer, since it concerns the medium and nothing above it.
Retransmitting a lost segment end-to-end is the transport layer. The network layer may drop packets freely, and only the endpoints know the conversation is incomplete.
Choosing a next hop is the network layer, which is the only layer that sees the whole path rather than a single link.
Detecting a corrupted frame is the data link layer, protecting one hop, though the transport layer's checksum protects the whole path.
Both are needed and neither is redundant. A link checksum catches corruption on the wire but not corruption inside a router's memory after the check; the end-to-end checksum catches that, which is the practical content of the end-to-end argument.
Distinguishing two browser tabs on one host is the transport layer, using port numbers, since the IP address identifies only the machine.
Summary
A layer offers a service upward, uses a service downward and speaks a protocol with its peer, and most conceptual questions are about which layer owns a problem.
Encapsulation makes each layer's unit the payload of the layer below: segment, packet, frame, bits.
OSI has seven layers with session and presentation absent from TCP/IP. Addressing runs MAC at the link layer, IP at the network layer, ports at the transport layer, names at the application layer.
Connection orientation and reliability are independent axes.
Circuit switching reserves capacity before data flows, giving guarantees and wasting idle capacity. Packet switching reserves nothing and relies on statistical multiplexing, paying with queueing delay and loss. Virtual circuits install path state at setup and carry short identifiers.
Datagram routers hold state per destination and survive failures gracefully; virtual circuit routers hold state per connection and lose every circuit when one fails.
The four delay components are processing, queueing, transmission and propagation. Transmission is length over rate; propagation is distance over speed; they are independent.
Store-and-forward makes a message over links with packets take transmission times, which is the pipelining result that justifies packetisation.
Packet size has an optimum, because smaller packets pipeline better while headers cost proportionally more.
Bandwidth-delay product is rate times propagation delay and measures bits in flight. A window smaller than it leaves the sender idle, which is why TCP window scaling exists.
Encapsulation overhead is a few percent for bulk transfers and over ninety percent for single-keystroke traffic.
Multiplexing divides frequency, time or wavelength. Synchronous time division reserves a slot whether or not it is used, while statistical time division allocates on demand, and that distinction is circuit versus packet switching seen from the link.
Throughput is set by the bottleneck link, and round-trip time is what protocol timers are measured against.
