Transcript Slide 1

Data Link Layer
Savera Tanwir
Data Link Layer Design Issues
•
•
•
•
Services Provided to the Network
Layer
Framing
Error Control
Flow Control
Functions of the Data Link Layer
•
•
•
Provide service interface to the
network layer
Dealing with transmission errors
Regulating data flow
•
Slow receivers not swamped by fast
senders
Functions of the Data Link Layer (2)
Relationship between packets and frames.
Services Provided to Network Layer
(a) Virtual communication.
(b) Actual communication.
Services Provided to Network Layer

Unacknowledged Connectionless Service




Acknowledged connectionless Service




No logical connection is established beforehand and
released
No re-transmission in case of loss
Appropriate when the error rate is very low
Each frame is individually acknowledged
Packet acknowledgement vs frame ack?
Wireless systems
Acknowledged Connection Oriented Service

Connection establishment and termination
Services Provided to Network Layer (2)
Placement of the data link protocol.
Framing
A character stream.
(a) Without errors. (b) With one error.
Framing (2)
(a) A frame delimited by flag bytes.
(b) Four examples of byte sequences before and
after stuffing.
Framing (3)
Bit stuffing
(a) The original data.
(b) The data as they appear on the line.
(c) The data as they are stored in receiver’s memory
after destuffing.
Errors
In a single-bit error, only 1 bit in the data
unit has changed.
A burst error means that 2 or more bits
in the data unit have changed.
Error detection/correction

Error detection




Check if any error has occurred
Don’t care the number of errors
Don’t care the positions of errors
Error correction



Need to know the number of errors
Need to know the positions of errors
More difficult
Error Detection and Correction

Used on many link types

Can be used anytime you don’t trust the media


Caches ,memories, disks
Major Algorithmic Strategies:

Parity




1 and 2 dimensional
Hamming codes (Interleaved Parity Codes)
Checksums
Cyclic Redundancy Codes (CRC)
To detect or correct errors, we need to
send extra (redundant) bits with data.
Parity Codes
Single Bit Parity:
Detect single bit errors
Two Dimensional Bit Parity:
Detect and correct single bit errors
0
0
Hamming Distance


The Hamming distance between two words is the
number of differences between corresponding bits.
The minimum Hamming distance is the smallest
Hamming distance between
all possible pairs in a set of words.
We can count the number of 1s in the Xoring of two
words
1. The Hamming distance d(000, 011) is 2 because
2. The Hamming distance d(10101, 11110) is 3 because
Example
Find the minimum Hamming distance of the coding
scheme in Table 10.1.
Solution
We first find all Hamming distances.
The dmin in this case is 2.
Minimum Distance for
Error Detection


To guarantee the detection of up to s errors in all
cases, the minimum Hamming distance in a block
code must be dmin = s + 1.
Why?
Example 10.7
•The minimum Hamming distance for our first code
scheme is 2. This code guarantees detection of only a single
error.
•For example, if the third codeword (101) is sent and one
error occurs, the received codeword does not match any
valid codeword. If two errors occur, however, the received
codeword may match a valid codeword and the errors are
not detected.
Example 10.8
•Table has dmin = 3. This code can detect up to two errors.
When any of the valid codewords is sent, two errors create
a codeword which is not in the table of valid codewords.
The receiver cannot be fooled.
•What if there are three error occurrance?
Hamming Codes



Want to be able to correct error with less overhead
than 2D parity
Hamming codes correct all single bit errors with
only log(M) extra bits and detect double bit errors
Uses an interleaved parity scheme
Calculating a Hamming Code

Procedure:



Place message bits in their non-power-of-two Hamming
positions
Build a table listing the binary representation for each of
the message bit positions
Calculate the check bits
Hamming Code Example
1 0 1 1
Message to be sent:
Position
2n: check bits
1
2
20
21
1
3
4
22
0
5
1
6
1
7
Hamming Code Example
1 0 1 1
Message to be sent:
Position
2n: check bits
1
2
20
21
1
3
0
5
4
22
Calculate check bits:
3
5
6
7
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21 +
+ 2 1 + 20
=
=
=
=
0
1
1
1
1
0
1
1
1
1
0
1
1
6
1
7
Hamming Code Example
1 0 1 1
Message to be sent:
Position
2n: check bits
1
1
2
20
21
1
3
0
5
4
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21 +
+ 2 1 + 20
=
=
=
=
0
1
1
1
1
7
Starting with the 20 position:
Look at positions with 1’s
in them
22
Calculate check bits:
3
5
6
7
1
6
1
0
1
1
1
1
0
1
Count the number of 1’s in the
corresponding message bits
If even, place a 1 in the 20
check bit, i.e., use odd parity
Otherwise, place a 0
Hamming Code Example
1 0 1 1
Message to be sent:
Position
2n: check bits
1
1
0
2
20
21
1
3
0
5
4
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21 +
+ 2 1 + 20
=
=
=
=
0
1
1
1
1
7
Repeat with the 21 position:
Look at positions those
positions with 1’s in them
22
Calculate check bits:
3
5
6
7
1
6
1
0
1
1
1
1
0
1
Count the number of 1’s in the
corresponding message bits
If even, place a 1 in the 21
check bit
Otherwise, place a 0
Hamming Code Example
1 0 1 1
Message to be sent:
Position
2n: check bits
1
1
0
2
20
21
1
4
1
3
0
5
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21 +
+ 2 1 + 20
=
=
=
=
0
1
1
1
1
7
Repeat with the 22 position:
Look at positions those
positions with 1’s in them
22
Calculate check bits:
3
5
6
7
1
6
1
0
1
1
1
1
0
1
Count the number of 1’s in the
corresponding message bits
If even, place a 1 in the 22
check bit
Otherwise, place a 0
Hamming Code Example
Original message = 1011
Sent message = 1011011
Now, how do we check for a single-bit error in the
sent message using the Hamming code?
Using Hamming Codes to Correct
Single-Bit Errors
Received message:
Position
2n: check bits
1 0 1 1 0 0 1
1
1
0
2
20
21
1
3
1
4
0
5
22
Calculate check bits:
3
5
6
7
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21
+ 2 1 + 20
=
=
=
=
0
1
1
1
1
0
1
1
1
1
0
1
0
6
1
7
Using Hamming Codes to Correct
Single-Bit Errors
Received message:
Position
2n: check bits
1 0 1 1 0 0 1
1
1
0
2
20
21
1
3
1
4
0
5
0
6
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21
+ 2 1 + 20
=
=
=
=
0
1
1
1
Starting with the 20 position:
Look at positions with 1’s
in them
22
Calculate check bits:
3
5
6
7
1
7
1
0
1
1
1
1
0
1
Odd parity: No error in bits 1, 3, 5, 7
Count the number of 1’s in
both the corresponding
message bits and the 20 check
bit and compute the parity.
If even parity, there is an error
in one of the four bits that were
checked.
Using Hamming Codes to Correct
Single-Bit Errors
Received message:
Position
2n: check bits
1 0 1 1 0 0 1
1
1
0
2
20
21
1
3
1
4
0
5
0
6
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21
+ 2 1 + 20
=
=
=
=
0
1
1
1
Repeat with the 21 position:
Look at positions with 1’s
in them
22
Calculate check bits:
3
5
6
7
1
7
1
0
1
1
1
1
0
1
Even parity: ERROR in bit 2, 3, 6 or 7!
Count the number of 1’s in
both the corresponding
message bits and the 21 check
bit and compute the parity.
If even parity, there is an error
in one of the four bits that were
checked.
Using Hamming Codes to Correct
Single-Bit Errors
Received message:
Position
2n: check bits
1 0 1 1 0 0 1
1
1
0
2
20
21
1
3
1
4
0
5
0
6
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21
+ 2 1 + 20
=
=
=
=
0
1
1
1
Repeat with the 22 position:
Look at positions with 1’s
in them
22
Calculate check bits:
3
5
6
7
1
7
1
0
1
1
1
1
0
1
Even parity: ERROR in bit 4, 5, 6 or 7!
Count the number of 1’s in
both the corresponding
message bits and the 22 check
bit and compute the parity.
If even parity, there is an error
in one of the four bits that were
checked.
Finding the error’s location
Position
1
1
0
2
1
3
1
4
0
5
0
6
1
7
Finding the error’s location
Position
1
1
0
2
1
3
1
4
0
5
No error in bits 1, 3, 5, 7
0
6
1
7
Finding the error’s location
erroneous bit, change to 1
Position
1
1
0
2
1
3
1
4
0
5
ERROR in bit 2, 3, 6 or 7
ERROR in bit 4, 5, 6 or 7
0
6
1
7
Error must be in bit 6
because bits 3, 5, 7
are correct, and all the
remaining information
agrees on bit 6
Finding the error’s location
An Easier Alternative to the Last Slide
3
5
6
7
=
=
=
=
22
22
22
2 1 + 20
+ 20
+ 21
+ 2 1 + 20
E = error in column
NE = no error in column
=
=
=
=
0
1
1
1
1
0
1
1
1
1
0
1
E
E NE
1
1
0
=6
Hamming Codes



Hamming codes can be used to locate and correct a
single-bit error
If more than one bit is in error, then a Hamming
code cannot correct it
Hamming codes, like parity bits, are only useful on
short messages
Error Detecting Codes

Error correcting codes are simply too expensive for reliable
links


Usually we only use error detection combined with retransmissions
CRC (Cyclic Redundancy Check)
 Frame bits are seen as polynomial M(x)





e.g. 101001 => M(x) = x5 + x3 + 1
Sender/receiver use generator polynomial G(x) of degree r
Append r ‘0’ bits to lower end of frame generated by M(x)
Perform polynomial division using G(x) and append remainder
to M(x), to get T(x)
Receiver computes T(x) / G(x) and checks remainder
Error-Detecting Codes
Calculation of the polynomial
code checksum.
Standard Polynomials
Name
Polynomial
Application
CRC-8
x8 + x2 + x + 1
ATM header
CRC-10
x10 + x9 + x5 + x4 + x 2 + 1
ATM AAL
ITU-16
x16 + x12 + x5 + 1
HDLC
ITU-32
x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 +
x4 + x2 + x + 1
IEEE 802
Elementary Data Link Protocols
•
•
•
An Unrestricted Simplex Protocol
A Simplex Stop-and-Wait Protocol
A Simplex Protocol for a Noisy
Channel
Protocol Definitions
Continued 
Some definitions needed in the protocols to follow.
These are located in the file protocol.h.
Protocol
Definitions
(ctd.)
Some definitions
needed in the
protocols to follow.
These are located in
the file protocol.h.
Unrestricted Simplex Protocol






Communication is simplex
No errors take place on the physical channel
The sender/receiver can generate/consume an
infinite amount of data
Infinite buffer space is available
Processing time can be ignored
Always ready for sending/receiving
Unrestricted
Simplex
Protocol
Simplex Stop-and-Wait Protocol




Most unrealistic assumption is dropped i.e. receiver can process
incoming data infinitely fast
Channel is still assumed to be error free
Data traffic is still simplex
Problem: How to prevent the sender from flooding the receiver
(Flow Control)?


Solution




The receiver requires a time (t) to execute
The sender must transmit at an average rate less than one frame per t
Calculate the worst case behavior of the receiver e.g. each frame
encounters the same delay
Problem: There will be no overruns, but the link utilization will be
extremely poor
Solution

Sender ships one frame and then waits for acknowledgment (stop and
wait)


The contents of the acknowledgment frame are unimportant
Data transmission cannot be one directional

Requires Half-duplex physical channel
Simplex
Stop-andWait
Protocol
A Simplex Protocol for a Noisy
Channel
A positive
acknowledgement
with retransmission
protocol.
Continued 
A Simplex Protocol for a Noisy Channel
(ctd.)
A positive acknowledgement with retransmission protocol.
Unresolved Problems of Simplex
Protocols

Timer duration : How long should the timer be?



What if too long? (inefficient)
What if too short? (unnecessary retransmission)
Poor Link Utilization results due to Stop-and-Wait
Sliding Window Protocols
•
•
•
A One-Bit Sliding Window Protocol
A Protocol Using Go Back N
A Protocol Using Selective Repeat
Sliding Window Protocol

There is a need for transmitting data in both directions




Different channels for data in each direction
Same channel for data in both directions
For example, using a kind field in the header of an
incoming frame, the receiver can tell if frame is data or
ACK
Piggybacking



Instead of sending a separate control (ACK) frame, the ACK is
attached to the outgoing data frame
Advantage: Better use of the channel bandwidth (just a few
extra bits)
Issue: How long should the data link layer wait for a packet
onto which to piggyback the acknowledgement?
Piggybacking
Sliding Window Protocol

Concept behind all sliding window protocols

Each frame contains a sequence number




Maximum number is 2n –1 (to fit in an n bit field)
At any instant of time, the sender maintains a set of
sequence numbers it is permitted to send called
sending window
The receiver also maintains a receiving window,
corresponding to the frames it is permitted to accept
Both windows need not have same upper and lower
limits and can grow or shrink as frames are sent and
received
Sliding Window Protocol

Sender’s perspective

The frames in the sender’s window represent frames that ‘have
been sent but not yet acknowledged’ or ‘can be sent’

Frames in sender’s window may be lost or damaged, the sender
must keep all these frames in its memory for possible
retransmissions
If max window size is n, the sender needs n buffer spaces to hold
the unacknowledged frames


Whenever a new packet arrives from the network layer, it is



Given the next highest sequence number
The upper boundary of the window is advanced by one
When an acknowledgement comes in, the lower boundary is
advanced by one
Example – 3-bit Sender Sliding
Window
After receiving ACKs for Frame 0 and 1
Sliding Window Protocol

Receiver’s Perspective

The receiver’s window corresponds to the frames it may accept


If a frame comes that lies outside the receiver’s window, its discarded
If it receives a frame whose sq. no. matches its expectation, it is
Passed to the NL
 ACK is generated
 Complete window is moved by 1


Receiver’s window always reserves its size

NL is always given data in-order, regardless of receiver’s window size
Example – 1-bit Receiver Sliding
Window
After receiving Frame 0 from Sender
A One-Bit Sliding Window Protocol
Continued 
A One-Bit Sliding Window Protocol
(ctd.)
A One-Bit Sliding Window Protocol (2)
Two scenarios for protocol 4. (a) Normal case. (b)
Abnormal case. The notation is (seq, ack, packet number).
An asterisk indicates where a network layer accepts a packet.
Link Utilization Problem

In 1-bit protocol, the sender can only have one unACKed frame
outstanding






Consider a 50 kbps channel with 500 msec round-trip propagation delay used
to send 1000 bit frames
Transmission time t = 20 ms
Frame will arrive at destination after 270 ms
ACK will get back after 520 ms (Assuming no delay at receiver)
So sender was idle for 500/520 ≈ 96% of the time
Thus, a combination of long propagation delay, high bandwidth and short
frame length destroys efficiency

One solution, use larger frames, but the maximum size is limited by the bit
error rate (BER) of the channel
Solution  Pipelining


Allow more frames to be in transmission simultaneously, instead of
just 1 frame
If channel bandwidth is b bits/sec, frame length is ℓ bits & round-trip
propagation is R sec



Time to transmit single frame = ℓ /b bits
Line utilization = ℓ /( ℓ + bR )
Issues with pipelining


Provides more efficient use of bandwidth, but error handling is more complex
If 20 frames are transmitted and only the 2nd had an error


Will frames 3 - 20 be ignored at receiver side?
Will the sender have to retransmit all frames again?
A Protocol Using Go-Back-N

Discard all subsequent frames, sending no
acknowledgement for the discarded frames
timeout interval
sender
receiver
0
1
2
0
3
1
4
5
6
7
8
2
3
4
E D D D D D D 2
5
3
discarded by
receiver
frame with
error
Time
6
4
7
5
8
6
9 10
7
8
9
A Protocol Using Go-Back-N


Corresponds to receive window size of 1
Go-back-N works fine if the retransmissions rarely
occur


Wastes a lot of bandwidth if error rate is high
Requires lesser buffer size at the receiver
Selective-Repeat


Receiver sends a NAK when it detects an error
Sender sends the required frame on receiving NAK
Sliding
Window
Protocol
Using Go
Back N
Continued 
Sliding Window Protocol Using Go Back
N
Continued 
Sliding Window Protocol Using Go
Back N
Continued 
Sliding Window Protocol Using Go
Back N
Sliding Window Protocol Using Go Back N
(2)
Simulation of multiple timers in software.
A Sliding Window Protocol Using Selective Repeat
Continued 
A Sliding Window Protocol Using Selective Repeat (2)
Continued 
A Sliding Window Protocol Using Selective Repeat (3)
Continued 
A Sliding Window Protocol Using Selective Repeat (4)
A Sliding Window Protocol Using Selective Repeat (5)
(a) Initial situation with a window size seven.
(b) After seven frames sent and received, but not
acknowledged.
(c) Initial situation with a window size of four.
(d) After four frames sent and received, but not
acknowledged.
Acknowledgements

Ali Sajjad’s lectures