The Data Link Layer

framing

A wire or radio link carries a continuous stream of bits, one after another, with nothing built in to say where one message ends and the next begins. It is like receiving a long telegram with no spaces or punctuation: thisisallonelongrunofletters. Framing is the trick of inserting markers into that stream so the receiver can tell where each chunk starts and stops. Each chunk, with its markers, is a frame.

There are a few standard ways to do it. One is to put a special flag byte at the start and end of every frame, for example the bit pattern 01111110; whenever the receiver sees that flag, it knows a frame boundary is there. The catch is that the same pattern might appear by accident inside the data, so the sender uses bit stuffing or byte stuffing — it inserts an extra harmless bit or escape byte to break up any data that looks like the flag, and the receiver strips it back out. Another method puts a length count in the header that says exactly how many bytes follow, so the receiver counts them off. Either way, the receiver gains a reliable answer to one question: where does this frame end?

Framing matters because every other link-layer job depends on it. You cannot check a frame for errors, read its address, or acknowledge it if you cannot first tell where it begins and ends. A common misconception is that framing adds reliability — it does not; framing only delineates. Detecting and recovering from errors are separate jobs layered on top of clean framing.

Sender wants to send the bytes ...7E... where 7E is also the flag. With byte stuffing it sends an escape byte first, so the receiver knows the next 7E is real data, not a frame boundary, and removes the escape on the way in.

Byte stuffing lets a flag pattern appear safely inside the data.

Framing only marks boundaries; it does not by itself guarantee the contents arrived intact. Bit/byte stuffing is the price you pay for using a reserved flag pattern.

Also called
封框訊框化