Chapter 3 The Data Link Layer

advertisement
Chapter 3
The Data Link Layer
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
Services provided:
•
•
•
Unacknowledged connectionless service
(e.g. if error rate low, for voice transmission, or for LANs)
Acknowledged connectionless service
(e.g. for wireless systems: retransmissions are possible)
Acknowledged connection-oriented service
 frames guaranteed to be received in right order and exactly
once
 3 phases: initialization, transmission, release
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 (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 (e.g. 01111110 is delimiter)
(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.
Error Detection and Correction
• Types of Errors
• Error-Correcting Codes
• Error-Detecting Codes
Types of Errors
Single-Bit Error:
Burst Error:
(a)
(b)
Redundancy
 All error detection/correction methods are based on redundancy
Error Detection
•
Four basic detection methods:
•
•
•
•
•
Vertical Redundancy Check (VRC)
Longitudinal Redundancy Check (LRC)
Cyclic Redundancy Check (CRC)
Checksum
VRC (Parity Bit Method):
Single-Bit errors are always detected.
Burst errors detected, if number of errors is odd.
LRC
Original data
11100111
11011101
LRC
11100111
00111001
10101001
11100111
11011101
00111001
10101001
10101010
11011101
00111001
10101001
10101010
Original data plus LRC
LRC detects burst errors better than VRC:
 Bursts less than number of columns are detected with a high probability
Some error patterns remain undetected:
 e.g. 2 bits in the same position but in different rows change their values
CRC
r bits
r+1 bits
r bits
CRC
•
CRC Algorithm:
•
•
•
•
•
•
Let M be the frame to be sent. M is interpreted as a binary number.
Let G (divisor) be a binary number agreed on between sender and
receiver. G should have r + 1 bits (G is the so-called generator
polynomial of degree r).
Append r zero bits to right-end of the frame M and get f:
f = M.2r
Divide the “bit string” f by G (using modulo 2 division):
f = p.G + R
(R has r or fewer bits and is the CRC)
Get T = f + R (= f – R = p.G, which is divisible by G)
T is now the checksummed frame to be transmitted.
CRC
Example:
G
M
Message transmitted: T = 100100001
CRC
Why polynomials?
Standard polynomials:
(IEEE 802)
CRC
•
CRC Performance:
•
•
•
•
Assume an error is described as a bit string E:
e.g. E = 001010 means 2 error in second and fourth bit (from the right)
Receiver gets: T + E
Since T is divisible by G, E/G will determine whether or not an error can be
detected.
Cases:
•
•
•
Single-Bit Error: E = 2i for some i.
 Choose G with 2 or more terms (e.g. G = 2p +1). G does not divide 2i
Two-Bit Error: E = 2i + 2j = (2i-j +1)2i (with i > j).
 G should include 2p + 1(to avoid the 2i term, see above)
 Also, G should not divide 2i-j +1 for any (i-j=) k <= frame length
 For example: G = 215 +214 +1 works for frames with length <= 32768
E has an odd number of 1s:
 Choose a G - as a number - that is divisible by 3
CRC
•
CRC Performance (contd):
•
Burst Error: E = (2k-1 + … + 1).2i (E of length k).
G should be odd (i.e. it ends with 1) to avoid the factor 2i
Cases:
• k-1 < r: burst length less than length of G:
Error always detected, since A mod B != 0 for any A < B and A != 0
• k-1 = r: burst length equal length of G:
Error is not detected iff E = G. However, because G begins/ends with 1,
only the middle k-2 (= r-1) bits are decisive in this case. This
constellation happens then with probability 1/2r-1
• k-1 > r: burst is arbitrarily long:
The length of the remainder (of E/G) is r. Hence, the probability of the
error not being detected is 1/2r (remainder has r zeros)
CRC
•
Hardware Implementation:
•
•
•
•
Shift register of length r initialized to zero.
XOR gates added between cells where there is 1 in G (except for leftmost 1)
In each step, a bit is read from the message, the XOR operations activated, and then the shift
operations.
1
0
1
1
Our example:
Adder
0
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
0
Register
Data
000
001
010
100
100
101
111
011
110
001
100100000
00100000
0100000
100000
00000
0000
000
00
0
remainder
0
100100000
Checksum
Error Correction
•
Two methods:
•
•
•
Sender-based: First error detection, then ask sender to retransmit data in case
of an error.
Automatic or Receiver-based: Here, receiver tries to find out after an error
what the correct data might have been.
 Error-correcting codes
In theory, it is possible to correct any detected error automatically,
however, this is not done in practice, because it requires lots of
redundancy (which is overhead).
How many redundant bits are needed to allow for correction?
•
•
Example for single-bit errors:
• ASCII character = 7 Bits
• Situations: No error, Error in 1st bit, Error in 2nd bit, …, Error in 7th bit.
• At first glance, we would need 3 redundant bits to perform correction.
• However, errors can affect the redundant bits, too.
Error Correction
•
How many redundant bits are needed? (Contd)
•
•
•
Number of redundant bits r should be chosen in such a way that all
single-bit errors, and these are m+r+1 ones, can be corrected.
Since r bits can have 2r different states, a sufficient condition is:
2r >= m+r+1
For example, for ASCII code (m=7) the smallest value of r is 4:
16 = 24 >= 7+4+1 = 12
Error Correction
•
We now know how many redundant bits to use. The remaining
question is how to use them to identify the bit in error.
 Hamming code
Idea:
•
•
•
•
•
Place the redundant bits (r-bits) in different positions.
Each r-bit is the parity bit (or VRC bit) for a subset of the entire data.
Receiver checks the parity bits again, and can identify the bit in error (if any).
Placement of the r-bits for ASCII characters:
 r-bits are placed in positions which are power of 2.
Error Correction
•
•
Details of the r-bit placement:
Let bi the binary representation of (position i). Pj the set of bits, which rj is
responsible for.
 Pj = {i, bi has a 1 at position j and i !=j}
Our example again:
Error Correction
•
Our example: (contd)
Error Correction
•
Calculating the values of the r-bits (sender side):
Error Correction
•
Correcting a single-bit error (receiver side):
 Assume bit 7 changed it value: received message = 10010100101
Error Correction
•
Burst errors:
•
•
Hamming code can correct single-bit errors. In principle, same method can
be applied for burst errors, too. However, the number of the r-bits may grow
prohibitively for practical use.
However, there is a trick that makes Hamming code practical enough also for
burst errors:
Idea:
1. Use Hamming method for
k data units.
2. Send those k codes column
by column.
3. If |burst| <= k occurs, it would
affect different codes by
changing at most one bit.
4. Thus, correct data can be
reconstructed, since Hamming
code can correct single-bit errors
Data Link Layer Protocols
•
Main task of these protocols:
•
•
•
•
Flow control: Curb (fast) sender so that it does not overwhelm receiver.
Error control: Handle errors
Types of flow control:
•
Stop-and-wait: Wait for acknowledgement of sent frame prior to sending a
new one.
 individual acknowledgement for each frame
•
Sliding Window: Multiple frames can be sent without acknowledgement
 acknowledgement is not individual for each frame
Error control:
•
Adds error handling to protocols for flow control.
•
Types of errors:
• Frame is damaged (and no correction is used or possible)
• Frame is lost
• Acknowledgement is lost
• Negative acknowledgement is lost (if used)
Data Link Layer Protocols
Flow Control
•
Stop-and-Wait:
•
•
Sender waits after each sent frame until corresponding acknowledgement
arrives
In this way, receiver will not be overwhelmed with frames
+ Simple
- Inefficient:
 transmission time
doubled
 Bandwidth wasted
Flow Control
•
Sliding Window:
•
•
•
•
Multiple frames may be in transit at a time
Window prevents sender from overwhelming the receiver
More precisely:
• Both sender and receiver have a window with same size n.
• Frames are numbered modulo n+1
• Acknowledgements also carry a number (mod n+1), which identifies the
next frame expected by the receiver
• The window can hold n frames at either ends, hence at most n frames can
be sent without a need for acknowledgement.
Example: n = 7
• Frames are numbered mod 8 e.g.
01234567012345670…
• If receiver sends ACK 5, the sender would understand that all frames up to
number 4 have been successfully received.
Flow Control
•
Sender Sliding Window:
•
•
Assume data are fed (by network layer) from the right, then:
• Sender window shrinks from the left when frames are sent
• Sender window expands to the right when acknowledgements are received
Example: If frame 0, 1, 2, 3, 4 have been sent  W = {5, 6}
If ACK 4 arrives later  W = {5, 6, 7, 0, 1, 2}
to physical
layer
from network
layer
Flow Control
•
Receiver Sliding Window:
•
•
Assume data are fed (by physical layer) from the left, then:
• Receiver window shrinks from the left when frames are received
• Receiver window expands to the right when acknowledgements are sent
Example: If frame 0, 1, 2, 3, 4, 5 have been received  W = {6}
If ACK 2 has been sent  W = {6, 7, 0}
If ACK 5 has been sent  W = {6, 7, 0, 1, 2, 3}
(new win size = old win size + (current ACK# - previous ACK#) mod 8)
from physical
layer
to network
layer
Flow Control: Example
Error Control
•
Idea:
•
•
•
•
•
•
•
Integrate error handling with flow control.
Error control refers mainly to methods of error detection and retransmission.
Error control is based on ARQ (Automatic Repeat Request).
ARQ policy: On error detection, send NAK and let sender retransmit a frame.
Sender uses in general a timer to detect errors (lost ACK/NAK).
Again, errors are: corrupted frame, lost frame, or lost ACK/NAK
Classification:
Error Control
•
Stop-and-Wait ARQ:
•
•
•
Simple Stop-and-Wait flow control + retransmission in case of errors
Rules for retransmission:
• Sender keeps copy of last transmitted frame until an ACK arrives
• Both data frames and ACK are numbered alternatively 0 and 1. For
example, ACK1 means that receiver accepted data frame 0 and is
expecting data frame 1.
• If an error is detected in a frame, a NAK is send by receiver. NAKs are
not numbered and tell sender to retransmit last frame.
• Sender uses a timer, after a timeout (without ACK) sender retransmits last
frame.
Error handling:
•
•
•
Damaged frame
Lost frame
Lost ACK/NAK
Stop-and-Wait ARQ : Damaged Frame
Example
for a
damaged
frame
0
1
0
Retransmission
0
Error in frame 0
Stop-and-Wait ARQ: Lost Frame
ACK 0
Stop-and-Wait ARQ: Lost ACK/NAK
0
ACK 0
ACK 0
Second copy
discarded
Sliding Window ARQ
•
New Features (added to basic sliding window flow control):
•
•
•
•
•
•
Sender keeps copies of frames which are not acknowledged yet.
In addition to ACK receivers uses also NAKs.
Both are numbered:
• ACK carries the number of next frame expected.
• NAK carries the number of the damaged frame itself (which is the
expected one).
• Examples:
• If last ACK was numbered 4, an ACK 7 means that frames 4, 5, and 6
have been received correctly.
• If frame 8 and 9 were damaged, both NAK 8 and NAK 9 are returned,
but NAK 8 tells sender that previous frames were intact.
Sender has a timer. Since n (window size) frames can be sent without
acknowledgement, sender starts the timer after sending n frames if their ACK
is still missing.
On timeout, sender resends one/multiple frames (depending on protocol).
Receiver must be able to recognize duplicates.
Two protocols: Go-Back-n ARQ and Selective Reject ARQ
•
•
Go-Back-n ARQ
Idea: If frame is lost/damaged all frames since the last ACK are resent.
Damaged frame:
Resent
Resent
Resent
•
Go-Back-n ARQ
Lost frame:
Receiver detects 2 is skipped
Resent
Resent
Resent
•
Go-Back-n ARQ
Lost ACK:
Sender has to send 3 frames only
(otherwise window size is decisive)
Resent
Resent
Resent
discard
discard
discard
ACK 3 Resent
Selective Reject ARQ
•
Idea:
•
•
•
•
Resend only the specific lost/damaged frame.
If NAK is returned, sender retransmits only specified frame (out of sequence).
This means that receiver must be able to sort frames and insert a retransmitted
frame in its proper place in the sequence.
Requirements:
•
•
•
•
•
•
Receiver should have a sorting logic to enable to reorder frames received out
of sequence.
Receiver must be able to store frames after a NAK has been sent until the
damaged frame has been replaced.
A buffer in the receiver must keep all frames until all retransmissions have
been sorted and any duplicate frames have been identified and discarded.
To aid selectivity, ACK numbers, like NAK numbers should refer to the frame
received (or lost) instead of the next frame expected.
Sender must have a searching logic that allow to find and select the frame to
be retransmitted.
For efficiency, window size is recommended to be less than or equal 1+n/2
where n is the Go-Back-n window size.
Selective Reject ARQ
•
Damaged frame:
Receiver accepts further frames but must not
return an ACK until frame 2 is retransmitted
ACK 5
Selective Reject ARQ
•
Lost frame:
If frame 2 was last frame, sender treats this
case as a lost ACK
Receiver detects 2 is skipped
Data 3
Resent
Data 2
NAK 2
Data 4
Data 5
Data 2
Data 5
Selective Reject ARQ
•
Lost ACK/NAK:
•
•
•
•
Like in Go-Back-n.
When sender reaches capacity of window or the end of its transmission, it sets
a timer.
•
If after timeout no ACK arrives, sender retransmits all frames that are not
acknowledged yet.
•
Receiver should recognize duplicates and discard them.
Go-Back-n vs. Selective Reject:
•
Communication overhead:
Go-Back-n > Selective Reject
•
Logic complexity:
Selective Reject > Go-Back-n
•
However, in practice Go-Back-n is used more often (due to its simplicity).
Remark:
Note that stop-and-wait is a special case of the sliding window protocol with a
window size of 1.
High-Level Data Link Control
•
HDLC:
•
•
•
•
•
•
Origin: IBM mainframe protocol SDLC (Synchronous Data Link Control)
Various variants:
• ANSI: ADCCP
• ISO: HDLC
• CCITT: LAPB
Bit-oriented protocol (not character-oriented)
Bit stuffing for transparency and sliding window (n=7) for flow control.
Point-to-point links and multi-point links (e.g. computer with different
terminals)
Structure of a frame:
Frame
Only for multipoint Sequence
delimiter links (e.g. terminal id) number,
ACKs, …
Actual
data
CRC
HDLC: Control Field
•
•
•
•
3 Types: information (a), supervisory (b), and unnumbered frame (c)
Information frame:
•
Seq: sequence number
•
Next: piggybacked ACK (next expected frame) if there is reverse traffic.
•
P/F: Poll/Final bit; used if computer asks terminal to send data (P-frame).
Terminal replies with P-frames except the last one is an F-frame.
Supervisory frame:
•
Type 0: ACK, Next= expected frame, used piggybacking not possible.
•
Type 1: NAK, Next=frame in error, sender resends all outstanding frames.
•
Type 2: ACK + asking sender to temporarily stop sending.
•
Type 3: Receiver asks sender to resend specified frame (in Next).
Unnumbered frame:
•
No common use of it, but it may
include information like:
- Disconnect/connect machine
- Fame has impossible semantics
- ACK for control frames
Download