Computer Networking › Section F · The link layer and LANs › Topic F.1
Link-layer services
A datagram never crosses the internet in one leap. It is handed from node to node over a chain of separate links, and the link layer is the part of the stack that carries it across each single link.
One hop at a time
A datagram sent from your laptop to a distant server may cross a Wi-Fi hop to the home router, a fibre hop to the internet service provider, many links between routers, and finally an Ethernet hop to the server. The link layer is responsible for exactly one of those hops at a time. Its vocabulary is small. Any device on a link, whether host, router or switch, is a node. The channel between adjacent nodes is a link. The link layer's packet is a frame, which wraps a network-layer datagram for that one hop. Different links may use different link-layer protocols, such as Ethernet or Wi-Fi.
What a link layer may offer
Link layers differ, and none is required to offer everything. The possible services are: framing, which marks where each frame starts and ends and wraps the datagram in a header and trailer; link access, meaning rules for sharing a channel; reliable delivery, in which each frame is acknowledged and resent if lost; flow control, which stops a fast sender swamping a slow neighbour; error detection, so the receiver can spot flipped bits; and sometimes error correction, which repairs them. A link can also be half duplex, where both ends transmit but not at the same moment, or full duplex, where both transmit at once.
Framing and link-layer addresses
A frame has a header, a payload that holds the datagram, and a trailer. The receiver must also find where each frame begins: Ethernet sends a synchronising preamble first, while some other links mark boundaries with a flag pattern and stuff extra bits or bytes into the data so the flag never appears by accident. On a link shared by several nodes the header must say which node the frame is for, so it carries link-layer addresses, usually called MAC addresses. A MAC address names a network interface on one link, whereas an IP address names a position in the internet. Not counting the preamble, Ethernet adds 18 bytes of header and trailer around a payload of up to 1,500 bytes: 6 each for the destination and source addresses, 2 for a type field and 4 for the error-check trailer. The topic Switched LANs: MAC addresses, ARP, switches, and VLANs returns to this.
Why some links add reliable delivery
Wired links such as fibre and twisted pair rarely corrupt a frame, so Ethernet does not acknowledge frames at all; if one is lost, a higher layer notices. Radio is different, because interference, walls and movement garble bits regularly. Wi-Fi therefore has the receiver acknowledge each unicast frame, and the sender repeats the frame if no acknowledgement arrives. Fixing a loss on the one hop where it occurred is far cheaper than waiting for an end-to-end protocol to resend across the whole path. The general principles are covered in Principles of reliable data transfer, and Wireless LANs: 802.11 applies them.
Worked example: how often is a frame corrupted?
A frame of \(L\) bits survives only if every bit does. If each bit is flipped independently with probability \(p\) (the bit error rate),
Take a 1,500-byte frame. 1. In bits, \(L = 1500 \times 8 = 12{,}000\). 2. On fibre with \(p = 10^{-12}\), the result is about \(1.2 \times 10^{-8}\): essentially never. 3. On a noisy radio link, assume \(p = 10^{-5}\). Then \(1 - (1-10^{-5})^{12000} \approx 0.113\), so about 11% of frames are bad. 4. With resending, the average number of transmissions per frame is \(1/(1-0.113) \approx 1.13\). Without hop-level repair, a path of five such links delivers a frame first time only \(0.887^5 \approx 55\)% of the time.
Where the link layer lives
Most of the link layer is implemented in the network interface controller (NIC), also called the network adapter. It is a chip or card, built into the motherboard in most computers, that combines dedicated hardware with a small amount of firmware, plus a driver in the operating system. On sending, the NIC takes a datagram from the host, builds the frame, adds the error-detection bits and transmits. On receiving, it checks for errors, strips the header and passes the datagram up, interrupting the processor only when a good frame needs attention. Doing this in hardware keeps the link layer fast. The manufacturer assigns each NIC its MAC address, although software can override it.
Worked example: one datagram, three frames
A laptop sends a 1,500-byte datagram to a server. It crosses three links: Wi-Fi to the home router, a fibre link to a router, and Ethernet to the server. 1. The datagram's source and destination IP addresses stay the same on every hop (assuming the home router does no address translation, which DHCP and network address translation covers). 2. Each hop uses a new frame with its own header: the first is a Wi-Fi frame addressed to the router's interface, and, if we assume Ethernet on the other two links, the second and third are Ethernet frames whose MAC addresses name the two nodes on that link. 3. Suppose the links deliver 50 Mbit/s, 1 Gbit/s and 10 Gbit/s. Ignoring frame headers, pushing 12,000 bits onto each takes 240 µs, 12 µs and 1.2 µs. 4. The total is 253.2 µs, and the slowest link dominates, so a modest Wi-Fi hop can set the cost of the whole path. This ignores propagation and queuing delay.
Broadcast and point-to-point links
A point-to-point link joins exactly two nodes, as when one host is wired to one port of a switch with a full-duplex cable; nobody else can interfere. A broadcast link has many nodes attached to one shared channel, as with Wi-Fi, cable internet access and the original Ethernet bus. Whatever one node sends, every other node on the channel can hear, and two nodes that transmit together collide, so the frames are garbled. Broadcast links therefore need a rule for taking turns, called a multiple access protocol, which the topic Multiple access links and protocols explains. Point-to-point links need no such rule.
Common mistakes to avoid
First, thinking the link layer delivers data end to end: it only covers one hop, and the frame is rebuilt at every router. Second, mixing up the addresses: IP addresses stay fixed along the path while MAC addresses change from link to link. Third, assuming every link guarantees delivery; Ethernet detects errors but does not repair them. Fourth, forgetting to convert bytes to bits when working out frame error rates, as in \(L = 1500 \times 8\). Fifth, treating error detection and reliable delivery as the same service: detection only tells the receiver a frame is bad.
Key takeaways
The link layer moves a datagram across a single link, wrapped in a frame. Possible services are framing, link access, reliable delivery, flow control, error detection and error correction, and each link offers its own subset. MAC addresses name interfaces on a link, whereas IP addresses stay constant end to end. Reliable delivery is common on error-prone radio links and absent on Ethernet. The NIC implements most of the link layer in hardware. Broadcast links need a multiple access protocol, and point-to-point links do not. The probability that a frame is corrupted is \(1 - (1-p)^L\) for bit error rate \(p\) and \(L\) bits.
Flashcards
Flashcard
Any device on a link: host, router or switch
Test your understanding
Question 1 of 5
A datagram crosses three links on its way to a server. What stays the same on every hop?
Question 2 of 5
Why does Wi-Fi acknowledge each unicast frame while Ethernet does not?
Question 3 of 5
A 1,000-byte frame crosses a link with bit error rate 10^-6, with bits corrupted independently. About what fraction of frames are corrupted?
Question 4 of 5
Which statement about the network interface controller (NIC) is correct?
Question 5 of 5
What distinguishes a broadcast link from a point-to-point link?
