Data Link Layer 1
Data Link Layer 1
The first framing method uses a field in the header to specify the number of
characters in the frame. When the data link layer at the destination sees
the character count, it knows how many characters follow and hence where
the end of the frame is. This technique is shown in Fig. 3-4(a) for four
frames of sizes 5, 5, 8, and 8 characters, respectively.
A character stream. (a) Without errors. (b) With one
error.
The second framing method gets around the problem
of resynchronization after an error by having each
frame start and end with special bytes. In the past, the
starting and ending bytes were different, but in recent
years most protocols have used the same byte, called
a flag byte, as both the starting and ending delimiter,
as shown in Fig. 3-5(a) as FLAG. In this way, if the
receiver ever loses synchronization, it can just search
for the flag byte to find the end of the current frame.
Two consecutive flag bytes indicate the end of one
frame and start of the next one.
Figure 3-5. (a) A frame delimited by flag bytes. (b) Four
examples of byte sequences before and after byte
stuffing.
A serious problem occurs with this method when binary data, such as object programs or
floating-point numbers, are being transmitted. It may easily happen that the flag byte's bit pattern
occurs in the data. This situation will usually interfere with the framing. One way to solve this
problem is to have the sender's data link layer insert a special escape byte (ESC) just before
each ''accidental'' flag byte in the data. The data link layer on the receiving end removes the
escape byte before the data are given to the network layer. This technique is called byte stuffing
or character stuffing. Thus, a framing flag byte can be distinguished from one in the data by the
absence or presence of an escape byte before it.
Of course, the next question is: What happens if an escape byte occurs in the middle of the
data? The answer is that it, too, is stuffed with an escape byte. Thus, any single escape byte is
part of an escape sequence, whereas a doubled one indicates that a single escape occurred
naturally in the data. Some examples are shown in Fig. 3-5(b). In all cases, the byte sequence
delivered after destuffing is exactly the same as the original byte sequence.
The byte-stuffing scheme depicted in Fig. 3-5 is a slight simplification of the one used in the PPP
protocol that most home computers use to communicate with their Internet service provider. We
will discuss PPP later in this chapter.
A major disadvantage of using this framing method is that it is closely tied to the use of 8-bit
characters. Not all character codes use 8-bit characters. For example. UNICODE uses 16-bit
characters, As networks developed, the disadvantages of embedding the character code length
in the framing mechanism became more and more obvious, so a new technique had to be
developed to allow arbitrary sized characters.
A character stream. (a) Without errors. (b) With one
error.
he trouble with this algorithm is that the count can be garbled by a transmission
error. For example, if the character count of 5 in the second frame of Fig. 3-4(b)
becomes a 7, the destination will get out of synchronization and will be unable to
locate the start of the next frame. Even if the checksum is incorrect so the
destination knows that the frame is bad, it still has no way of telling where the
next frame starts. Sending a frame back to the source asking for a
retransmission does not help either, since the destination does not know how
many characters to skip over to get to the start of the retransmission. For this
reason, the character count method is rarely used anymore.
The second framing method gets around the problem of resynchronization after
an error by having each frame start and end with special bytes. In the past, the
starting and ending bytes were different, but in recent years most protocols have
used the same byte, called a flag byte, as both the starting and ending delimiter,
as shown in Fig. 3-5(a) as FLAG. In this way, if the receiver ever loses
synchronization, it can just search for the flag byte to find the end of the current
frame. Two consecutive flag bytes indicate the end of one frame and start of the
next one.
a) A frame delimited by flag bytes
The new technique allows data frames to contain an arbitrary number
of bits and allows character codes with an arbitrary number of bits per
character. It works like this. Each frame begins and ends with a
special bit pattern, 01111110 (in fact, a flag byte). Whenever the
sender's data link layer encounters five consecutive 1s in the data, it
automatically stuffs a 0 bit into the outgoing bit stream. This bit stuffing
is analogous to byte stuffing, in which an escape byte is stuffed into
the outgoing character stream before a flag byte in the data.
When the receiver sees five consecutive incoming 1 bits, followed by
a 0 bit, it automatically destuffs (i.e., deletes) the 0 bit. Just as byte
stuffing is completely transparent to the network layer in both
computers, so is bit stuffing. If the user data contain the flag pattern,
01111110, this flag is transmitted as 011111010 but stored in the
receiver's memory as 01111110. Figure 3-6 gives an example of bit
stuffing.
Figure 3-6. Bit stuffing. (a) The original data. (b)
The data as they appear on the line. (c) The data as
they are stored in the receiver's memory after
destuffing.
With bit stuffing, the boundary between two frames can be
unambiguously recognized by the flag pattern. Thus, if the receiver
loses track of where it is, all it has to do is scan the input for flag
sequences, since they can only occur at frame boundaries and never
within the data.
ERRORDETECTION
Why we need it ?
To avoid retransmissionof whole packet or
message
What to do if error detected ?
Discard, and request a new copy of the
frame:
explicitly or implicitly
Try to correcterror, if possible
2
Data can be corrupted during
transmission.
Some applications require that errors be
detected and corrected
REDUNDANCY
To detect or correct errors, we need to send extra
(redundant) bits with data.
SENDERSITE
1. The message is divided into 16-bit words.
2. The value of the checksum word is set to
O.
3. All words including the checksum are
added using one's complement addition.
4. The sum is complemented and becomes
the checksum.
5. The checksum is sent with the data
3
RECEIVERSITE
1. The message (including checksum) is
divided into 16-bit words.
2. All words are added using one's
complement addition.
3. The sum is complemented and becomes
the new checksum.
4. If the value of checksum is 0, the message
is accepted; otherwise, it is rejected.
4
Elementary Data Link Protocols
Continued
A Simplex Protocol for a Noisy Channel
(ctd.)
Continued
A One-Bit Sliding Window Protocol
(ctd.)
A One-Bit Sliding Window Protocol (2)