05 - Data Link Layer
05 - Data Link Layer
1. Group the physical layer bit stream into units called frames.
2. Sender checksums the frame and transmits checksum together with data.
3. Receiver re-computes the checksum and compares it with the received value. If they differ, an error
has occurred and the frame is discarded.
5. Flow control. Prevent a fast sender from overpowering a slower receiver. For example, a
supercomputer can easily generate data faster than a PC can consume it.
2
1. SERVICES PROVIDED TO THE NETWORK LAYER
There are several possible kinds of services that can be provided to network
layers.
3
Three types of services provided to network layer:
• Unacknowledged Connection-less Service -- Best Effort
• Acknowledged Connection-less Service -- Acknowledged Delivery
• Acknowledged Connection-Oriented Service -- Reliable Delivery
The receiver does not return acknowledgments to the sender, so the sender has
no way of knowing if a frame has been successfully delivered.
1. When higher layers can recover from errors with little loss in performance.
2. For real-time applications requiring "better never than late" semantics. Old data
may be worse than no data.
4
Acknowledged Connection-less Service -- Acknowledged Delivery:
• Likewise, the receiver may hand received frames to higher layers in the order
in which they arrive, regardless of the original sending order.
5
Acknowledged Connection-Oriented Service -- Reliable Delivery:
• Frames are delivered to the receiver reliably and in the same order as
generated by the sender.
• Connection state keeps track of sending order and which frames require
retransmission. For example, receiver state includes which frames have been
received, which ones have not, etc.
6
2. FRAMING
The DLL translates the physical layer's raw bit stream into discrete units (messages) called
frames.
How can frame be transmitted so the receiver can detect frame boundaries? That is, how
can the receiver recognize the start and end of a frame?
We will discuss four ways of framing:
Character Count
Encoding Violations
7
Character Count:
• Make the first field in the frame's header be the length of the frame. That way
the receiver knows how big the current frame is and can determine where the
next frame ends.
• Although checksum will detect the frames are incorrect, the receiver will have
difficulty re-synchronizing to the start of a new frame. This technique is not
used anymore, since better techniques are available.
5 1 2 3 4 5 6 7 8 9 8 0 1 2 5 6 9 1
Without error
5 1 2 3 4 7 6 7 8 9 8 0 1 2 5 6 9 1
Disadvantage: use of 8-bit character. Not all character code uses 8-bit character. E.g. Unicode
uses 16-bit char.
9
Starting and Ending Flag with Bit Stuffing:
Each frame uses reserved bit patterns 01111110 to indicate the start and end of a
frame. Whenever the sender data link layer encounters five consecutive 1s in
the data, it automatically stuffs a 0 bit after five 1s into the outgoing bit stream.
Whenever the receiver sees the five consecutive incoming 1 bits, followed by a 0
bit, it automatically delete the 0 bit.
10
Encoding Violations:
Encoding uses at physical medium. In Manchester encoding, for instance, 1-bits
are represented by a – to + voltage, and 0-bits by + to - voltage. The start/end
of a frame could be represented by the signal low-low or high-high.
11
3. ERROR CONTROL
Must insure that all frames are delivered (possibly in order) to a destination. Three
components are required to do this:
Acknowledgments:
12
Timers:
• One problem that simple ACK/NACK schemes fail to address is recovering from a frame
that is lost, and as a result, fails to seek an ACK or NACK.
• What happens if an ACK or NACK becomes lost?
• Retransmission timers are used to resend frames that don't produce an ACK. When
sending a frame, schedule a timer to expire at some time after the ACK should have
been returned. If the timer goes off, retransmit the frame.
Sequence Numbers:
13
4. FLOW CONTROL
Flow control deals with throttling the speed of the sender to match that of the receiver.
There are two approaches use to control the transmission rate of sender.
Feedback-based flow:
The receiver sends back information to the sender giving it permission to send more data or at least
telling the sender how the receiver is doing.
14
Error Detection & Correction Control
• Types of Errors
single bit error, burst error
• Error Detection
Error detection is performed by calculating an error-detection code that is a function of bits being transmitted. The
code is appended to the transmitted bits. The receiver calculates the code based on the incoming bits and
compare it to the incoming code to check for errors.
• Error Correction
operates in a fashion similar to error detection but is capable of correcting certain errors in a transmitted bit stream.
15
There are two type of errors may occur during the transmission. Single bit error and burst
error.
Single Bit Error: Only one bit in the data unit has changed.
Burst Error: Two or more bits in the data unit have changed. The length of the burst is
measured from the first corrupted bit to the last corrupted bit.
Sent 0 1 0 0 0 1 0 0 1 0 1 0 1 0
Bits corrupted
received 0 1 0 1 1 1 0 0 1 1 0 0 1 0
16
Redundancy
redundancy means adding extra bits to data unit for detecting errors at the receiver.
Error Detection and correction: Include enough redundancy to detect and correct errors.
Error Detection and retransmission:. Include enough redundancy bits to detect errors and use
ACKs and retransmissions to recover from the errors.
17
Error Detection
Detection Methods
A parity bit is added to every data unit so that the total number of 1s becomes even.
Even
Checking
function
11000011 parity
generator
1100001 data
VRC can detect all single bit errors. It can detect burst errors only if the total number of
errors in each data unit is odd.
18
Longitudinal Redundancy Check (LRC)
A block of bits is arranged in the matrix form and redundancy check (parity) is computed column wise. A
redundant row of bits is added to the whole block.
LRC
1 1 1 0 0 1 1 1
1 1 0 1 1 1 0 1
0 0 1 1 1 0 0 1
1 0 1 0 1 0 0 1
Direction of movement
19
Cyclic Redundancy Check (CRC): Modulo 2 Arithmetic
Given a k-bit block of bits or message, the sender generate an n – k bit sequence, known as a CRC, such that the resulting
frame consisting of n bits, is exactly divisible by some predetermined number (divisor) of length n - k +1. The receiver then
divides the incoming frame by that number and , if there is no remainder, assumes there is no error.
k n-k
T 2 n k D R
20
The errors in an n-bit frame can be presented by an n-bit filed with 1s in each error position.
Tr T E XOR
T = Transmitted frame
E = Error pattern with 1s in positions where errors occur.
Tr = Received frame
If there is an error ( E ≠ 0), the receiver will fail to detect the error if and only if Tr is divisible by
P, which is equivalent to E divisible by P
Modulo 2 Arithmetic:
Module 2 arithmetic uses binary addition with no carries (XOR), and binary subtraction with no carries
also interpreted as the (XOR) operation.
1111 1111
+1010 -0101
0101 1010
21
Example of CRC using Modulo 2 Arithmetic
Message D = 1010001101
1101010110
Pattern P = 110101
P 110101 101000110100000 2 n k D
CRC R = to be calculated
110101
Thus n = 15, k = 10, and (n – k) = 5
111011
The message is multiply by 25 :
110101
25 D = 101000110100000
111010
This product is divided by P,
gives the remainder R = 01110
110101
111110
The remainder is added to 25D ( T = 25D + R) 110101
to give 101100
T = 1010001101 01110 , which is transmitted. 110101
110010
110101
01110 CRC
Sender
22
At the receiver
If receiver receives the frame T, which is divided by P
1101010110
P 110101 101000110101110 T
110101
111011
110101
111010
110101
111110
110101
101111
110101
110101
110101
0 remainder
23
Example
In a CRC detection scheme, choose P = 10011, message M = 10010011011. find the CRC and frame T.
a. Suppose the channel introduces an error pattern 100010000000000. (a flip from 1 to 0 or 0 to 1in
position 1 and 5). What is received. Can the error be detected?
Sol.
After calculation, CRC bits are 1100. The frame T= 100100110111100 is sent.
a. Tr = E T
Tr = 100010000000000
100100110111100
Frame 000110110111100 is received. Tr is divided by P,
The remainder after division by P is 1110 ,which is nonzero. The errors are detected.
b. Tr = E T
Tr = 100110000000000 100100110111100
The string 000010110111100 is received, The remainder after division by P is zero. The errors
are not detected
24
Cyclic Redundancy Check (CRC): Polynomial Method
All values of CRC process can be express as polynomials in a dummy variable X, with binary coefficients.
Thus for ,
Arithmetic operations are modulo 2. The CRC process can now be described as:
X n k DX RX
QX where D Data, P generator polynomial
PX PX
T X X n k DX RX R remainder , T frame to be transmitted
n- no of bits in a frame to be transmitted
k- no of bits block of data or message
(n - k) bits CRC
(n-k+1) bits divisor (generator polynomial)
25
Example of CRC using polynomial division:
Data D 1010001101, we have DX X 9 X 7 X 3 X 2 1
Generator polynomial P 110101, PX X 5 X 4 X 2 1
27
Example of checksum
Suppose the following block of 24 bits is to be sent using a checksum of 8 bits.
10101011 00101101 10010101, what is the resulting frame to be transmitted?
Sender Receiver 28
Error Correction Codes
Relationship between data bits and redundancy bits to correct single bit error:
A frame consists of m data bits and r redundant or check bits. Let the total length of frame be n
( i.e. n = m + r). A n-bit unit containing data and check bit is often referred to as an n-bit codeword.
m r
r
2 m r 1
29
Hamming code
This method uses extra parity bits to allow the identification of a single bit error. Create the codeword
as follows:
1. Mark all bit positions that are powers of two as parity bits (1, 2, 4, 8, 16, 32, 64, 128, etc).
2. All other bit positions are for the data to be encoded (3, 5, 6, 7, 9, 10, 11, etc).
3. Each parity bit calculates the parity for some of the bits in the codeword. The position of the
parity bit determines the sequence of bits that it alternately checks and skips.
Position 1: ckeck1 bit, skip 1 bit, check 1 bit, skip 1 bit, ...
(1, 3, 5, 7, 9, 11, …)
Position 2: check 2 bit, skip 2 bit, check 2 bit, skip 2 bit,…
(2, 3, 6, 7, 10, 11, 14, 15, …)
Position 4: check 4 bit, skip 4 bit, check 4 bit, skip 4 bit,…
(4,5,6,7, 12,13,14,15, 20,21,22,24, …)
position 8: check 8 bit, skip 8 bit, check 8 bit, skip 8 bit,…
(8,9,10,11,12,13,14,15, 24,25,26,27,28,29,30,31, …)
…………
4. Set the parity bit 1 if the total number of 1s in the potions it check is odd.
set the parity bit 0 if the total number of 1s in the potions it check is even.
30
Example: Hamming codeword
To construct the even parity hamming codeword for a data byte : 10011010.
1. To create the codeword, leaving the spaces for the parity bits.
_ _ 1 _ 0 01_1010
Position 1: check data bits 1, 3, 5, 7, 9, 11.
? _ 1 _ 0 01_1010 even parity, set bit position 1 to 0.
0 _ 1 _ 0 01_1010
Position 2: check bit 2, 3, 6, 7, 10, 11.
0 ? 1 _ 0 0 1 _ 1 0 1 0 odd parity, set bit position 2 to 1.
0 1 1 _ 0 01_1010
Position 4: check bit, 4,5,6,7.
0 1 1 ? 0 0 1 _ 1 0 1 0 odd parity, set bit position 4 to 1.
0 1 1 1 0 01_1010
position 8: check bit 8,9,10,11,12
0 1 1 1 0 01?1010 even parity, set bit position 8 to 0
0 1 1 1 0 0101010
Codeword : 0 1 1 1 0 0 1 01 0 1 0
31
Finding and Fixing a bad bit in Hamming codeword
Check each parity bit, and add the positions that are wrong, this will give you the location of the bad
bit.
Example:
The last example created a codeword 011100101010.
Suppose the codeword was received as 011100101110.
Verify each check bits, you will discover that parity bits 2 and 8 are incorrect. so,
2 + 8 = 10.
10th position is the location of the bad bit. So correct codeword is : 011100101010
32