Sie sind auf Seite 1von 5

Lecture Notes on Computer Networks

Frame Synchronization
Copyright Kenneth L. Calvert Revised August 2001

(i) Framing: The Problem

(ii) Fixed-length Frames

(iii) Unique Markers

(iv) Explicit Length

1 The Problem

The framing problem is the following. We have a “garden hose channel”, which emits a
steady (i.e. constant-rate) stream of red/blue marbles (representing 1’s and 0’s). Some-
times the marbles represent random noise, and sometimes they represent information.
The general problem is to find the information in the stream of marbles, starting from
whenevenr you happen to walk up to the garden hose.

It is given that the information is encoded in groups of marbles called frames (hence the
name). That is, in general the stream consists of frames separated by zero or more bits of
noise. The problem has two parts:

1. Find the beginning of the (next) frame.

2. Recognize the end of the frame once you’ve found the beginning.

The problem of framing occurs at essentially all levels of the reference model. The so-
lutions used at higher levels invariably depend on the solutions used at lower levels, so
we’ll talk about the basic ideas.

2 Fixed-length Frames

When frames are all the same length and are not separated by any random bits, and you
know what the length is, the problem reduces to finding the beginning of some frame.

1
Once you have identified the first bit of a frame, you just have to count bits to find the
beginning of the next frame.

This is what is done in time-division multiplexing systems, such as those used in the
telephone network. For example, on a DS1 circuit, every 125 seconds a frame containing
24 8-bit samples is transmitted. To enable the receiver to find the beginning of the frame,
a framing bit is added to each frame; the framing bits follow a particular pattern in
successive frames. For example, the framing bit might always be 1, or it might follow a
repeating pattern 001011001011001011001... The receiver looks for that pattern made up
of bits 193 bits apart.

Obviously there is a possibility that the actual “data” of successive frames might form
this pattern. That probability decreases with the length of the pattern. Assuming that the
data in the frames is random, the probability of this “false sync” can be made arbitrarily
small.

3 Variable-length Frames

When the frames being transmitted are variable-length, the problem is a little harder. The
receiver must be able to reliably detect both the beginning and end of the frame. There
are two basic methods for delimiting variable-length frames: unique markers and length
encoding.

3.1 Unique Markers

The most common method of framing is to insert unique markers into the stream to mark
the beginning and end of the frame. The principle is simply that unique markers do not
appear in the data. It is the responsibility of the sender to ensure this; the technique
depends on the form of the unique marker.

 Special symbols. Some channels can carry symbols other than ones and zeroes,
and these can be assigned as start and end delimiters. (This is equivalent to having
more colors of marbles, but only using red and blue for data.)
Example. If you have four colors of marbles, use blue and red for 0 and 1, green
and yellow for start and end. The receiver simply looks for a green marble when it
starts up.

 Special bit patterns. If the channel carries only bits, special sequences can be used
to mark the beginning and end of the frames.

2
The challenge with special bit patterns (the most common approach) is to ensure that
they do not occur in the data.

3.1.1 Byte- (or Character-)Stuffing

The ASCII character code has special (non-printing) characters for framing. These include
STX, ETX, and DLE. The receiver looks for an STX character to start the frame, and ETX
marks the end.

To prevent these from showing up in the data, the sender looks at each character. If
an ETX is in the data stream, the sender “stuffs” an extra DLE character before it. The
receiver, if it sees a DLE character in the stream, knows that any following ETX is not
really the end, and throws away the DLE.

Example. Suppose the frame format is:

SYN SYN SOH [header] STX [data] ETX

and the frame to be transmitted (consisting of ascii characters) is:

a b c ETX BEL 1 2 3

The actual sequence of bytes sent would be:

a b c DLE ETX BEL 123

The “DLE” character tells the receiver “the next character is to be interpreted as part of
the frame. The DLE character itself is thrown away by the receiver.

Now, the alert student should say, “But that’s begging the question! What if DLE ap-
pears in the text?” The answer is that DLE itself is byte-stuffed when it appears in the
data. Thus the receiver algorithm is:

while (syn not acquired) hunt for <syn> <syn>;


while (byte != <soh>) read next byte;
while (byte != <stx>) read next byte and process header;
while (byte != <etx>)
if (byte==<dle>) {
next byte;
if (byte is not <dle> or <etx>) signal ‘‘Protocol Error’’
continue;
} else output byte;

3
3.1.2 Bit-Stuffing

The byte-stuffing algorithm given above is useful when the framing is being done in
software — i.e., when the pipe is really a “byte pipe” rather than a “bit pipe”. But it
is possible to do it much simpler. The technique used in HDLC (High-level Data Link
Control) is to prevent the unique marker from appearing with bit-stuffing. That means
that whenever a long-enough prefix of the unique marker pattern appears in the data
stream, an extra bit is inserted so that the receiver doesn’t think it’s the real end-of-frame.

In HDLC the beginnings and ends of frames are both marked with the “flag” character
0x7e, i.e. a zero followed by six ones followed by another zero. (This symbol is also
used when the link is idle; it is transmitted back to back. Also, it is a separator and not a
terminator, i.e. only one flag character is required between frames.

The flag is prevented from occuring in transmitted data by the sender. During frame
transmission, the sender guarantees that no more than five ones appear in a row. When-
ever five ones have already been transmitted, and the next bit to transmit is a one, the
sender “stuffs” a zero bit into the transmitted stream, to prevent the receiver from recog-
nizing the flag character.

Note. Technically the receiver shouldn’t recognize the flag character until
it sees six ones and then a zero. However, six ones followed by a seventh
one represents “abort”; therefore a hardware implementation will flag End-
of-Frame as soon as it sees six ones.

The receiver has to un-stuff bits. It maintains a state machine based on how many ones
in a row have been seen. When five is reached, if the next bit is a one, the receiver recog-
nizes end-of-frame. Otherwise it removes the following zero from the stream and starts
counting again.

3.2 Explicit-Length Framing

In explicit-length framing, each frame is preceded by the number of bytes (or characters,
or words, or whatever unit you want to make it) it contains. There is usually a preset
maximum frame length. For example, if the maximum frame length is 255, a single byte
can precede each frame and encode its length. The receiver reads that byte, counts off the
indicated amount of data, and then reads the next length byte.

One question about variable-length frames is what to do when there’s no data to send. In
the case of length-encoded, the sender can simply send zeroes.

4
The problem with length encoding is of course how to acquire sync initially when you
walk up to the garden hose. Without some additional mechanism, you have no way
of knowing which bytes are data and which are length bytes. For this reason, length
encoding is invariably used in combination with some other mechanism.

Das könnte Ihnen auch gefallen