Framing & Error Detection
Scenario
Imagine listening to someone speak a continuous, unbroken stream of letters without spaces or punctuation. You wouldn't know where one word ends and another begins, or if you misheard a letter. Framing adds the spaces; error detection ensures you heard it right.
Mental model
Framing chops a chaotic stream of raw bits into organized chunks (frames). Error detection attaches a mathematical receipt to each chunk to prove it wasn't corrupted in transit.
At the Data Link layer, a sender wraps data in a 'frame' by adding a start marker and an end marker. It also calculates a checksum (like a Cyclic Redundancy Check) and adds it to the frame trailer. The receiver recalculates this checksum to verify the data arrived intact.
Explanation
When computers send data over a physical medium like a copper wire, they transmit a continuous stream of electrical signals representing 1s and 0s. However, the receiving computer needs a way to make sense of this endless river of bits. It needs to know exactly where a message starts, where it ends, and whether any bits were flipped by electrical interference along the way.
Framing solves the first problem. It is the process of breaking the bit stream into discrete, manageable blocks called 'frames'. The sender achieves this by adding special bit patterns at the beginning and end of the frame. For example, a specific sequence like '01111110' might act as a flag indicating the start of a frame. If that same pattern naturally occurs in the actual data, the sender uses a technique called 'bit stuffing' to slightly alter the data pattern so it isn't accidentally mistaken for an end flag.
Once the receiver successfully identifies a frame, it must verify the data's integrity. Physical mediums are noisy; a sudden spike in voltage or a nearby magnetic field can easily flip a 0 to a 1. To catch this, the sender uses Error Detection. The most common method is the Cyclic Redundancy Check (CRC). The sender treats the frame's data as a massive binary number, divides it by a predetermined prime number using polynomial arithmetic, and attaches the remainder (the CRC checksum) to the end of the frame.
When the frame arrives, the receiver performs the exact same mathematical division on the data it received. If its calculated remainder matches the checksum attached to the frame, the data is highly likely to be intact. If the numbers don't match, the receiver knows the frame was corrupted in transit.
In standard Ethernet and Wi-Fi networks, corrupted frames are simply silently discarded by the Data Link layer. It does not ask for a resend. The network relies on higher-level protocols (like TCP at the Transport layer) to eventually notice the missing data and request a retransmission.
Key points
- Framing: Adding a Header (start flag, addresses) and a Trailer (error detection, end flag) to raw data to create a discrete packet at Layer 2.
- Bit Stuffing: Inserting extra bits into the data payload so that actual data doesn't accidentally mimic the start/end flags used for framing.
- Cyclic Redundancy Check (CRC): A robust mathematical algorithm used to generate a checksum based on the frame's contents, capable of detecting multi-bit errors.
Common mistakes
- Error detection fixes the errors: Error detection only identifies that corruption happened. Error correction (like Forward Error Correction) can fix small errors, but standard Layer 2 framing simply drops corrupted frames.
- Checksums guarantee 100% accuracy: While CRCs are extremely robust and catch over 99.9% of random errors, it is mathematically possible (though incredibly rare) for a specific pattern of multiple bit flips to produce a matching checksum.
Glossary
- physical medium
- The actual physical material used to send data, like copper wires, fiber optic cables, or radio waves in the air.
- bits
- The smallest pieces of computer information, represented simply as 1s and 0s.
- Framing
- The process of wrapping a continuous stream of data into neatly packaged chunks so the receiving computer knows exactly where a message starts and ends.
Recall questions
- What is the purpose of framing at the Data Link layer?
- How does bit stuffing work?
- What happens if a corrupted frame is detected using CRC in standard Ethernet?
Questions & answers
If a network link suffers from frequent electrical interference causing bit flips, at which layer is this corruption first detected and discarded?
The Data Link layer (Layer 2).
Approach: Recall that the Data Link layer receives raw bits, forms frames, and immediately uses CRC error detection to drop corrupted frames.
Why use CRC instead of a simple parity bit for network error detection?
A simple parity bit only detects odd numbers of bit flips. CRC can detect burst errors and multiple bit flips, which are common in network transmission.
Approach: Highlight the robustness of polynomial division in CRC versus the rudimentary addition of parity.
Continue learning
Next: MAC, Ethernet & CSMA/CD