Unit-2 Data Link Layer L1-3
Unit-2 Data Link Layer L1-3
2
Data Link Layer
Design Issues :
The various services provided/Design Issues of Data link layer are :
1. Service Provided to the Network Layer
2. Framing
3. Error Detection and Correction
4. Flow Control
3
Data Link Layer
i ) Un acknowledged Connectionless Service
• Source sends independent frames to the destination with out any
acknowledgement .
• Not a reliable service .
• Used in the systems where error rate is low. Ex : LANS
ii ) Acknowledged Connectionless Service
• Source sends independent frames to the destination with an
acknowledgement .
• Reliable service .
• Used in Unreliable channels . Ex : Wireless Systems
iii ) Acknowledged Connection – Oriented Service
• Here source and destination establish a connection before any data is
transferred and send an acknowledgement to the source after receiving
each frame in order .
• Most reliable service and Used in more noisy channels. e.g. : Video
4
Data Link Layer
Framing :
• Grouping the bits together from the physical layer and constructing a
frame is called framing .
• The frames are created by the adding a header and trailer to the packet
which specify the source and destination addresses .
• Frames are used to perform the error detection and correction
operations .
• Framing is of two types :
1. Fixed size framing or static framing
- size of frame is fixed
- no need to specify the start of the frame .
2. Variable size framing or Dynamic
- Size of the frames changed .
- It is necessary to specify the start of each frame .
5
Data Link Layer
• Methods to Break the Bit Stream into Frames .
1. Character Count
2. Character Stuffing or Byte Stuffing
3. Bit Stuffing
Character Count
• Here a field in the header ,Specifies the number of characters in the
frame .
• Data link layer at the destination looks the character count and decide
the end of frame .
• The main draw back of this method is if any count is garbled by a
transmission error then the destination is unable to decide the frames .
6
Data Link Layer
7
Data Link Layer
8
Data Link Layer
9
Data Link Layer
Bit Stuffing
• In this method each frame starts and ends with a special bit pattern like
01111110 called a flag byte .
• When the sender data link layer encounters a five consecutive ones in
the data it automatically stuffs a 0 bit into the out going bit stream .
• When the receiver sees five consecutive 1’s followed by a 0 bit it
automatically destuffs the 0 bit and send data to network layer
11
Data Link Layer
2. Multiple Bit
- Two or more non consecutive bits in data unit have
changed from 1 to 0 or 0 to1 .
Example :
12
Data Link Layer
3. Burst Errors
• Two or more consecutive bits in the data unit have changed from 1 to 0
and 0 to 1 .
13
Data Link Layer
Error Detection
1. Redundancy
• To detect the errors we use a mechanism called redundancy.
• It involves the transmission of each data unit twice.
• Same data unit is not received twice in succession a transmission error
occurred .
• The disadvantage of this system is slow and if an error occurred at the
same position of both data units .
• To avoid the disadvantage of this method a shorter group of bits added
to the end of each data unit ,this technique is called redundancy
• Data unit is passed through a generating unit and it adds an appropriate
redundancy check bits .
• This data unit send to the receiver and receiver puts the entire stream
into a checking function .
• If there is no error data is accepted other wise rejected .
14
Data Link Layer
Fig : Redundancy
2. Exact –Count Encoding :
• The Number of 1’s in the data unit are same .
• In the destination side it count the number of 1’s received same or not
to determine the transmission error .
15
Data Link Layer
Error Correction
• Error correction can be handled in two ways :
1. When the error is discovered ,the receiver asks the sender to retransmit the
same data unit .
2. Receiver can use an error correcting codes to Detect and Correct the errors.
• There are different types of Error Detecting and correcting Techniques :
1. Parity Checker
2. Hamming Code
3. Cyclic Redundancy Check
1. Parity Checker
• It is the simplest technique for detecting and correcting errors.
• The MSB of an 8-bits word is used as the parity bit and the remaining 7 bits
are used as data or message bits.
16
Data Link Layer
• The parity of 8-bits transmitted word can be either even parity or odd
parity.
• Even parity : Even parity means the number of 1's in the given word
including the parity bit should be even (2,4,6,....).
• Odd parity : Odd parity means the number of 1's in the given word
including the parity bit should be odd (1,3,5,....).
17
Data Link Layer
Example :
Drawbacks
• It does not detect all types of errors .
• Not suitable for multiple bit errors .
18
Data Link Layer
2. Hamming Code
• Hamming code can be applied to data units of any length .
• Hamming code is used to detect and correct single bit errors .
• The distance between two words of the same size is called Hamming
distance.
Example :
• 1. The Hamming distance d(000, 011) is 2 because 000 +011 is 011
(two 1’s).
• 2. The Hamming distance d(10101, 11110) is 3 because 10101 +11110
is 01011 (three 1’s).
2r>=m+r+1 19
Data Link Layer
21
Data Link Layer
• If any combination the number of 1’s even number ,assign the
corresponding r value as 0 else 1 .
• Like this after knowing the values of r1,r2,r4 and r8 the error bit
location can be identified by r’s position ( r8 r4 r2 r1).
• All values of r’s zero indicates no error has occurred .
Example 1: Consider the message 1001101 is transmitted through the
channel ,obtain the redundancy bits and transmitting unit needed.
Assume bit number 8 has been changed .how to locate it.
Example 2: Consider the message 1010111 is transmitted through the
channel ,obtain the redundancy bits and transmitting unit needed.
Assume bit number 3 has been changed .how to locate it.
Example 3: Consider the message 1101100 is transmitted through the
channel ,obtain the redundancy bits and transmitting unit needed.
Assume bit number 5 has been changed .how to locate it.
22
Data Link Layer
CRC (Cyclic Redundancy Check)
• Most power full redundancy technique based on the binary division .
• It uses polynomial codes for generating check bits in the form of cyclic
redundancy check .
• CRC bits are appended at the end of each data unit so that the resulting
data unit becomes exactly divisible by a second, predetermined number
.
• At the receiver the incoming data unit is divided by the same number .
• If there is no reminder the data unit is intact and it is accepted .
• A reminder indicates that data unit has damaged .
23
Data Link Layer
25
Data Link Layer
26
Data Link Layer
27
Data Link Layer
Example 1: What is the frame transmitted if the message i(x) is x7 + x4 + x3+x
and generator polynomial g(x) is x3 + x2 +1 .
11111001
28
Data Link Layer
11111011
29
Data Link Layer
30
Flow Control
• Flow control coordinates the amount of data that can be
sent before receiving acknowledgement
• It is one of the most important functions of data link layer.
• Flow control is a set of procedures that tells the sender how
much data it can transmit before it must wait for an
acknowledgement from the receiver.
• Receiver has a limited speed at which it can process
incoming data and a limited amount of memory in which
to store incoming data.
• Receiver must inform the sender before the limits are
reached and request that the transmitter to send fewer
frames or stop temporarily.
• Since the rate of processing is often slower than the rate of
transmission, receiver has a block of memory (buffer) for
storing incoming data until they are processed.
31
Error Control
32
Note
11.33
Note
11.34
PROTOCOLS
Now let us see how the data link layer can combine
framing, flow control, and error control to achieve the
delivery of data from one node to another.
11.35
Taxonomy of protocols discussed in this chapter
11.36
NOISELESS CHANNELS
11.37
The design of the simplest protocol with no flow or error control
11.38
Figure 11.7 Flow diagram for Example 11.1
11.39
Figure 11.8 Design of Stop-and-Wait Protocol
11.40
Figure 11.9 Flow diagram for Example 11.2
11.41
NOISY CHANNELS
11.42
• Sender keeps a copy of the last frame
Stop-and-Wait (One until it receives an acknowledgement.
bit Sliding window • For identification, both data frames and
acknowledgements (ACK) frames are
Protocol) numbered alternatively 0 and 1.
• Sender has a control variable (S) that
holds the number of the recently sent
frame. (0 or 1)
• Receiver has a control variable (R) that
holds the number of the next frame
expected (0 or 1).
• Sender starts a timer when it sends a
frame. If an ACK is not received within a
allocated time period, the sender
assumes that the frame was lost or
damaged and resends it
• Receiver send only positive ACK if the
frame is intact.
• ACK number always defines the number
of the next expected frame
43
Stop-and-Wait ARQ, lost ACK frame
44
Stop-and-Wait, lost ACK frame
45
Stop-and-Wait, delayed ACK frame
• The ACK can be delayed at
the receiver or due to
some problem
• It is received after the
timer for frame 0 has
expired.
• Sender retransmitted a
copy of frame 0. However,
R=1 means receiver
expects to see frame 1.
Receiver discards the
duplicate frame 0.
• Sender receives 2 ACKs, it
discards the second ACK.
46
Piggybacking
• A method to
combine a data
frame with ACK.
• Station A and B both
have data to send.
• Instead of sending
separately, station A
sends a data frame
that includes an ACK.
• Station B does the
same thing.
• Piggybacking saves
bandwidth.
47
Disadvantage of Stop-and-Wait
• In stop-and-wait, at any point in time, there is only one frame that is
sent and waiting to be acknowledged. This is not a good use of
transmission medium.
• To improve efficiency, multiple frames should be in transition while
waiting for ACK. That is called Sliding Window Protocols.
• Several frames can be sent at once the channel capacity can be used
efficiently .
• The receiver acknowledges only some of the frames , using a single ACK
to confirm the receipt of multiple data frames .
48
Go-Back-N ARQ
49
Sequence Numbers
50
Sender Sliding Window
• At the sending site, to
hold the outstanding
frames until they are
acknowledged, we use
the concept of a window.
• The size of the window is
at most 2m -1 where m is
the number of bits for
the sequence number.
• Size of the window can
be variable, e.g. TCP.
• The window slides to
include new unsent
frames when the correct
ACKs are received 51
Receiver Sliding Window
52
Control Variables
• Sender has 3 variables: S, SF, and SL
• S holds the sequence number of recently sent frame
• SF holds the sequence number of the first frame
• SL holds the sequence number of the last frame
• Receiver only has the one variable, R, that holds the sequence
number of the frame it expects to receive. If the seq. no. is the
same as the value of R, the frame is accepted, otherwise rejected.
53
Acknowledgement
• Receiver sends positive ACK if a frame arrived safe and in order.
• If the frames are damaged/out of order, receiver is silent and
discard all subsequent frames until it receives the one it is
expecting.
• The silence of the receiver causes the timer of the unacknowledged
frame to expire.
• Then the sender resends all frames, beginning with the one with
the expired timer.
• For example, suppose the sender has sent frame 6, but the timer
for frame 3 expires (i.e. frame 3 has not been acknowledged), then
the sender goes back and sends frames 3, 4, 5, 6 again. Thus it is
called Go-Back-N-ARQ
54
Go-Back-N ARQ, normal operation
• The sender keeps track of the outstanding frames and
updates the variables and windows as the ACKs arrive.
55
Go-Back-N ARQ, lost frame
• Frame 2 is lost
• When the
receiver receives
frame 3, it
discards frame 3
as it is expecting
frame 2
(according to
window).
• After the timer
for frame 2
expires at the
sender site, the
sender sends
frame 2 and 3.
(go back to 2)56
Go-Back-N ARQ, damaged/lost/delayed ACK
57
Go-Back-N ARQ
58
Selective Repeat ARQ, sender and receiver windows
• Go-Back-N ARQ simplifies the process at the receiver site. Receiver only keeps
track of only one variable, and there is no need to buffer out-of-order frames,
they are simply discarded.
• However, Go-Back-N ARQ protocol is inefficient for noisy link. It bandwidth
inefficient and slows down the transmission.
• In Selective Repeat ARQ, only the damaged frame is resent. More bandwidth
efficient but more complex processing at receiver.
• It defines a negative ACK (NAK) to report the sequence number of a damaged
frame before the timer expires.
59
Selective Repeat ARQ, lost frame • Frames 0 and 1 are
accepted when received
because they are in the
range specified by the
receiver window. Same
for frame 3.
• Receiver sends a NAK2
to show that frame 2
has not been received
and then sender
resends only frame 2
and it is accepted as it is
in the range of the
window.
60
Selective Repeat ARQ, sender window size
• Size of the sender and receiver windows must be at most one-half of 2 m. If m =
2, window size should be 2 m /2 = 2. Fig compares a window size of 2 with a
window size of 3. Window size is 3 and all ACKs are lost, sender sends duplicate
of frame 0, window of the receiver expect to receive frame 0 (part of the
window), so accepts frame 0, as the 1st frame of the next cycle – an error.
61
Selective Repeat ARQ
62