Unit-3_ Data Link Layer_Part -1(Notes) (1)
Unit-3_ Data Link Layer_Part -1(Notes) (1)
Frames are the units of digital transmission particularly in computer networks and telecommunications. Frames
are comparable to the packets of energy called photons in case of light energy. Frame is continuously used in
Time Division Multiplexing process.
Framing is a point-to-point connection between two computers or devices consists of a wire in which data is
transmitted as a stream of bits. However, these bits must be framed into discernible blocks of information.
Framing is a function of the data link layer. It provides a way for a sender to transmit a set of bits that are
meaningful to the receiver. Ethernet, token ring, frame relay, and other data link layer technologies have their
own frame structures. Frames have headers that contain information such as error-checking codes.
At data link layer, it extracts message from sender and provide it to receiver by providing sender’s and
receiver’s address. The advantage of using frames is that data is broken up into recoverable chunks that can
easily be checked for corruption.
Problems in Framing –
Detecting start of the frame: When a frame is transmitted, every station must be able to detect it.
Station detect frames by looking out for special sequence of bits that marks the beginning of the frame
i.e. SFD (Starting Frame Delimeter).
How do station detect a frame: Every station listen to link for SFD pattern through a sequential circuit.
If SFD is detected, sequential circuit alerts station. Station checks destination address to accept or reject
frame.
Detecting end of frame: When to stop reading the frame.
Types of framing – There are two types of framing:
1. Fixed size – The frame is of fixed size and there is no need to provide boundaries to the frame, length of the
frame itself acts as delimiter.
Drawback: It suffers from internal fragmentation if data size is less than frame size
Solution: Padding
2. Variable size – In this there is need to define end of frame as well as beginning of next frame to distinguish.
This can be done in two ways:
1. Length field – We can introduce a length field in the frame to indicate the length of the frame. Used in
Ethernet(802.3). The problem with this is that sometimes the length field might get corrupted.
2. End Delimeter (ED) – We can introduce an ED(pattern) to indicate the end of the frame. Used in
Token Ring. The problem with this is that ED can occur in the data. This can be solved by:
1. Character/Byte Stuffing: Used when frames consist of character. If data contains ED then, byte is
stuffed into data to diffentiate it from ED.
Let ED = “$” –> if data contains ‘$’ anywhere, it can be escaped using ‘\O’ character.
–> if data contains ‘\O$’ then, use ‘\O\O\O$'($ is escaped using \O and \O is escaped using \O).
Examples –
If Data –> 011100011110 and ED –> 0111 then, find data after bit stuffing ?
–> 01110000111010
If Data –> 110001001 and ED –> 1000 then, find data after bit stuffing ?
–> 11001010011
Gate CS 2014
Gate IT 2004
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self
Paced Course at a student-friendly price and become industry ready.
UNIT- II
FRAMING:
To provide service to the network layer, the data link layer must use the service
provided to it by the physical layer. What the physical layer does is accept a raw bit
stream and attempt to deliver it to the destination. This bit stream is not guaranteed to
be error free. The number of bits received may be less than, equal to, or more than the
number of bits transmitted, and they may have different values. It is up to the data
link layer to detect and, if necessary, correct errors. The usual approach is for the
data link layer to break the bit stream up into discrete frames and compute the
checksum for each frame (framing). When a frame arrives at the destination, the
checksum is recomputed. If the newly computed checksum is different from the one
contained in the frame, the data link layer knows that an error has occurred and takes
steps to deal with it (e.g., discarding the bad frame and possibly also sending back an
error report).We will look at four framing methods:
1. Character count.
2. Flag bytes with byte stuffing.
3. Starting and ending flags, with bit stuffing.
4. Physical layer coding violations.
Character count 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. (a) For four frames of sizes 5, 5, 8, and 8 characters,
respectively.
A character stream. (a) Without errors. (b) With one error
The 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. (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.
Flag bytes with byte stuffing 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. (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 (b) Four examples of byte sequences
before and after byte stuffing
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.
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. (b). In all cases,
the byte sequence delivered after de stuffing is exactly the same as the original
byte sequence.
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, so a new technique had to be developed to allow
arbitrary sized characters
Starting and ending flags, with bit stuffing 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 de- stuffs (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.
Fig: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.
Physical layer coding violations method of framing is only applicable to
networks in which the encoding on the physical medium contains some
redundancy. For example, some LANs encode 1 bit of data by using 2 physical bits.
Normally, a 1 bit is a high-low pair and a 0 bit is a low-high pair. The scheme
means that every data bit has a transition in the middle, making it easy for the
receiver to locate the bit boundaries. The combinations high-
high and low-low are not used for data but are used for delimiting frames in some
protocols.
As a final note on framing, many data link protocols use combination of a character
count with one of the other methods for extra safety. When a frame arrives, the count
field is used to locate the end of the frame. Only if the appropriate delimiter is
present at that position and the checksum is correct is the frame accepted as valid.
Otherwise, the input stream is scanned for the next delimiter
Simplest Protocol
It is very simple. The sender sends a sequence of frames without even thinking about
the receiver. Data are transmitted in one direction only. Both sender & receiver always
ready. Processing time can be ignored. Infinite buffer space is available. And best of all,
the communication channel between the data link layers never damages or loses frames.
This thoroughly unrealistic protocol, which we will nickname ‘‘Utopia,’’ .The utopia
protocol is unrealistic because it does not handle either flow control or error
correction
Stop-and-wait Protocol
It is still very simple. The sender sends one frame and waits for feedback from the
receiver. When the ACK arrives, the sender sends the next frame
It is Stop-and-Wait Protocol because the sender sends one frame, stops until it receives
confirmation from the receiver (okay to go ahead), and then sends the next frame. We
still have unidirectional communication for data frames, but auxiliary ACK frames
(simple tokens of acknowledgment) travel from the other direction. We add flow
control to our previous protocol.
NOISY CHANNELS
Although the Stop-and-Wait Protocol gives us an idea of how to add flow control to
its predecessor, noiseless channels are nonexistent. We can ignore the error (as we
sometimes do), or we need to add error control to our protocols. We discuss three
protocols in this section that use error control.
Sliding Window Protocols:
To detect and correct corrupted frames, we need to add redundancy bits to our
data frame. When the frame arrives at the receiver site, it is checked and if it is
corrupted, it is silently discarded. The detection of errors in this protocol is manifested
by the silence of the receiver.
Lost frames are more difficult to handle than corrupted ones. In our previous
protocols, there was no way to identify a frame. The received frame could be the
correct one, or a duplicate, or a frame out of order. The solution is to number the
frames. When the receiver receives a data frame that is out of order, this means that
frames were either lost or duplicated
The lost frames need to be resent in this protocol. If the receiver does not
respond when there is an error, how can the sender know which frame to resend? To
remedy this problem, the sender keeps a copy of the sent frame. At the same time, it
starts a timer. If the timer expires and there is no ACK for the sent frame, the frame is
resent, the copy is held, and the timer is restarted. Since the protocol uses the stop-
and-wait mechanism, there is only one specific frame that needs an ACK
Error correction in Stop-and-Wait ARQ is done by keeping a copy of the sent frame and
retransmitting of the frame when the timer expires
Assume that, in a Stop-and-Wait ARQ system, the bandwidth of the line is 1 Mbps,
and 1 bit takes 20 ms to make a round trip. What is the bandwidth-delay product? If
the system data frames are 1000 bits in length, what is the utilization percentage of the
link?
The link utilization is only 1000/20,000, or 5 percent. For this reason, for a link with a
high bandwidth or long delay, the use of Stop-and-Wait ARQ wastes the capacity of the
link.
Figure (b) shows how a send window can slide one or more slots to the right
when an acknowledgment arrives from the other end. The acknowledgments in this
protocol are cumulative, meaning that more than one frame can be acknowledged by
an ACK frame. In Figure, frames 0, I, and 2 are acknowledged, so the window has
slide to the right three slots. Note that the value of Sf is 3 because frame 3 is now
the first outstanding frame.The send window can slide one or more slots when a
valid acknowledgment arrives.
The sequence numbers to the left of the window belong to the frames already received
and acknowledged; the sequence numbers to the right of this window define the
frames that cannot be received. Any received frame with a sequence number in these
two regions is discarded. Only a frame with a sequence number matching the value of
Rn is accepted and acknowledged. The receive window also slides, but only one slot
at a time. When a correct frame is received (and a frame is received only one at a
time), the window slides.( see below figure for receiving window)
The receive window is an abstract concept defining an imaginary box of size 1 with
one single variable Rn. The window slides when a correct frame has arrived;
sliding occurs one slot at a time
Fig: Receiver window (before sliding (a), After sliding (b))
Timers
Although there can be a timer for each frame that is sent, in our protocol we use
only one. The reason is that the timer for the first outstanding frame always expires
first; we send all outstanding frames when this timer expires.
Acknowledgment
The receiver sends a positive acknowledgment if a frame has arrived safe and sound
and in order. If a frame is damaged or is received out of order, the receiver is silent
and will discard all subsequent frames until it receives the one it is expecting. The
silence of the receiver causes the timer of the unacknowledged frame at the sender
side to expire. This, in turn, causes the sender to go back and resend all frames,
beginning with the one with the expired timer. The receiver does not have to
acknowledge each frame received. It can send one cumulative acknowledgment for
several frames.
Resending a Frame
When the timer expires, the sender resends all outstanding frames. For example,
suppose the sender has already sent frame 6, but the timer for frame 3 expires.
This means that frame 3 has not been acknowledged; the sender goes back and
sends frames 3,4,5, and 6 again. That is why the protocol is called Go-Back-N
ARQ.
Below figure is an example(if ack lost) of a case where the forward channel is
reliable, but the reverse is not. No data frames are lost, but some ACKs are delayed
and one is lost. The example also shows how cumulative acknowledgments can
help if acknowledgments are delayed or lost
In Go-Back-N ARQ, The receiver keeps track of only one variable, and there is no
need to buffer out-of- order frames; they are simply discarded. However, this
protocol is very inefficient for a noisy link.
In a noisy link a frame has a higher probability of damage, which means the resending
of multiple frames. This resending uses up the bandwidth and slows down the
transmission.
For noisy links, there is another mechanism that does not resend N frames when
just one frame is damaged; only the damaged frame is resent. This mechanism is
called Selective Repeat ARQ.
It is more efficient for noisy links, but the processing at the receiver is more complex.
Sender Window (explain go-back N sender window concept (before & after
sliding.) The only difference in sender window between Go-back N and Selective
Repeat is Window size)
Receiver window
The receiver window in Selective Repeat is totally different from the one in Go Back-
N. First, the size of the receive window is the same as the size of the send window
(2m-1).
The Selective Repeat Protocol allows as many frames as the size of the receiver
window to arrive out of order and be kept until there is a set of in- order frames to be
delivered to the network layer. Because the sizes of the send window and receive
window are the same, all the frames in the send frame can arrive out of order and be
stored until they can be delivered. However the receiver never delivers packets out of
order to the network layer. Above Figure shows the receive window. Those slots inside
the window that are colored define frames that have arrived out of order and are
waiting for their neighbors to arrive before delivery to the network layer.
In Selective Repeat ARQ, the size of the sender and receiver window must be at most
one-half of 2m
Flow Diagram
Differences between Go-Back N & Selective Repeat
One main difference is the number of timers. Here, each frame sent or resent
needs a timer, which means that the timers need to be numbered (0, 1,2, and 3). The
timer for frame 0 starts at the first request, but stops when the ACK for this frame
arrives.
There are two conditions for the delivery of frames to the network layer: First, a
set of consecutive frames must have arrived. Second, the set starts from the beginning
of the window. After the first arrival, there was only one frame and it started from the
beginning of the window. After the last arrival, there are three frames and the first one
starts from the beginning of the window.
Another important point is that a NAK is sent.
The next point is about the ACKs. Notice that only two ACKs are sent here. The
first one acknowledges only the first frame; the second one acknowledges three
frames. In Selective Repeat, ACKs are sent when data are delivered to the network
layer. If the data belonging to n frames are delivered in one shot, only one ACK is
sent for all of them.
Piggybacking