University of Virginia
CS 457 - Computer Networks
Data Link Layer
Introduction Synchronization Error Detection Flow Control Error Control (via Retransmission)
© Jorg Liebeherr, 1998
1
University of Virginia
CS 457 - Computer Networks
Introduction Main Task of the data link layer: n Provide error-free transmission over a link
© Jorg Liebeherr, 1998
Network Layer
Network Layer
Data Link Layer
Data Link Layer
Physical Layer
Physical Layer
2
1
University of Virginia
CS 457 - Computer Networks
Introduction n
The PDU at the Data Link Layer (DL-PDU) is typically called a Frame. A Frame has a header, a data field, and a trailer
n
Example
01111110 8bits
Address 8bits
Control 8bits
Data >=0
Header
Checksum 16bits
01111110 8bits
Trailer
© Jorg Liebeherr, 1998
3
University of Virginia
CS 457 - Computer Networks
Framing n n
Problem: Identify the beginning and the end of a frame in a bit stream Solution (bit-oriented Framing): A special bit pattern (flag) signals the beginning and the end of a frame (e.g., "01111110") 01111110
n
Data
01111110
Problem: – The sequence '01111110' must not appear in the data of the frame
© Jorg Liebeherr, 1998
4
2
University of Virginia
CS 457 - Computer Networks
Bit-Oriented Framing and Bit Stuffing n
'Bit stuffing': If the sender detects five consecutive '1' it adds a '0' bit into the bit stream. The receiver removes the '0' from each occurrence of the sequence '111110' Original bit sequence:
After stuffing bits at sender: After stuffing bits are removed by receiver:
n
0110111111111111111100 011011111 0111110111110100 Stuffed bits
0110111111111111111100
Note: The flags itself are not bit-stuffed.
© Jorg Liebeherr, 1998
5
University of Virginia
CS 457 - Computer Networks
Error Control Two basic approaches to handle bit errors: –
Error-correcting codes -
–
Error-detecting codes plus retransmission -
© Jorg Liebeherr, 1998
Used if retransmission of the data is not possible Data are encoded with sufficient redundancy to correct bit errors Examples: Hamming Codes, Reed Solomon Codes, etc.
Used if retransmission of corrupted data is feasible Receiver detects error and requests retransmission of a frame. 6
3
University of Virginia
CS 457 - Computer Networks
Error Detection Techniques n
Error Detection Techniques: –
Parity Checks
–
Cyclic Redundancy Check
© Jorg Liebeherr, 1998
7
University of Virginia
CS 457 - Computer Networks
Parity Checks General Method: n Append a parity bit to the end of each character in a frame such that the total number of '1' in a character is: -
n
even (even parity) or odd (odd parity)
Example: – – –
© Jorg Liebeherr, 1998
With ASCII code, a parity bit can be attached to an 7-bit character ASCII "G" = 1 1 1 0 0 0 1 with even parity = with odd parity = 8
4
University of Virginia
CS 457 - Computer Networks
Cyclic-Redundancy Codes (CRC) General Method: n The transmitter generates an n-bit check sequence number from a given k-bit frame such that the resulting (k+n)-bit frame is divisible by some number n n
The receiver divides the incoming frame by the same number If the result of the division does not leave a remainder, the receiver assumes that there was no error
© Jorg Liebeherr, 1998
9
University of Virginia
CS 457 - Computer Networks
Cyclic-Redundancy Codes (CRC) n
CRC is used by all advanced data link protocols, for the following reasons: – Powerful error detection capability – CRC can be efficiently implemented in hardware
n
We discuss the CRC method in five easy steps: 1. Prerequisites 2. CRC Encoding Method 3. Example 4. Error Detection with CRC 5. Capabilities of CRC
© Jorg Liebeherr, 1998
10
5
University of Virginia
CS 457 - Computer Networks
Step 1: Prerequisites n
n
Modulo-2 Arithmetic: +
1
0
*
1
0
1
0
0
1
1
0
0
1
0
0
0
0
Examples of polynomials based on Modulo-2 operations: 1. (x+1)(x+1) = 2. (x2+1)(x3+x+1) = 3. If F(x) contains (x+1) as a factor, then F(1) = 0
© Jorg Liebeherr, 1998
11
University of Virginia
CS 457 - Computer Networks
Step 2: CRC Encoding Method n
Let us view each block of data as a polynomial with binary coefficients: 1 0 1 1 0 1 is viewed as x 5 + x 3 + x 2 + 1
Define: n M(x) Data block is a polynomial (= Message, Frame) n P(x) "Generator Polynomial" which is known to both sender and receiver (degree of P(x) is n)
© Jorg Liebeherr, 1998
12
6
University of Virginia
CS 457 - Computer Networks
Step 2: CRC Encoding Method (I) (II) (III)
Append n zeros to M(x), i.e., M(x) xn Divide M(x) xn by P(x) and obtain: M(x) xn = Q(x) P(x) + R(x) Set T(x) = M(x) xn + R(x). T(x) is the encoded message
Note:
n
T(x) is divisible by P(x). Therefore, if the received message does not contain an error then it can be divided by P(x).
Exercise: Encode the frame 1 1 0 1 0 1 1 0 1 1
© Jorg Liebeherr, 1998
13
University of Virginia
CS 457 - Computer Networks
Step 3: Encoding M (x) = x9 + x8 + x6 + x 4 + x3 + x + 1 -
(I) (II) (III)
Generator polynomial is P(x) = x4 + x + 1 Degree of P(x) is 4
M(x) x4 = x13 + x 12 + x10 + x8 + x7 + x 5 + x4 M(x) x4 = Q(x) P(x) + R(x) =(x9 + x8 + x3 + x) P(x) + x3 + x2 + x T(x) = M(x) x4 + R(x) = x13 + x12 + x10 + x8 + x7 + x5 + X4 + x3 + x2 + x
Transmitted Bit Sequence: 1 1 0 1 0 1 1 0 1 1 1 1 1 0 © Jorg Liebeherr, 1998
14
7
University of Virginia
CS 457 - Computer Networks
Step 4: Error Detection with CRC n
Errors can be expressed as Error Polynomials
n
For example, Sent Message: 1011101 Received Message: 1 1 1 1 0 0 1 ______________________________ Error: 0100100
n
In the example, the Error Polynomial E(x) is given by:
E(x) = x 5 + x 2 © Jorg Liebeherr, 1998
15
University of Virginia
CS 457 - Computer Networks
Step 5: Error Detection Capability of CRC Note: n Errors will not be detected by CRC if
E(x) / P (x) = B (x) + 0, i.e., E(x) contains P(x) as a factor n
Observe the following trade-off: – Large values of n introduce a lot of overhead, but improve the error detection capability.
© Jorg Liebeherr, 1998
16
8
University of Virginia
CS 457 - Computer Networks
Step 5: Error Detection Capability of CRC n
n
All single-bit errors are detected, if P(x) has a factor with at least 2 terms: E(x) = x i If P(x) = (x+1)P’(x), then x i cannot contain (x+1) All double-bit errors are detected if P(x) has a factor with at least 3 terms E(x) = x i+x j
n
= x j (x k+1)
(for k = i-j, j1
Sliding Window Flow Control – Allows transmission of multiple frames – Assigns each frame a k-bit sequence number – Range of sequence number is [0..2k-1], i.e., frames are counted modulo 2k
© Jorg Liebeherr, 1998
31
n
Sending Window: -
At any instant, the sender is permitted to send frames with sequence numbers in a certain range
-
The range of sequence numbers is called the sending window Frames already transmitted
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window
Window of frames that may be transmitted
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 Frame sequence number
© Jorg Liebeherr, 1998
Last frame transmitted Window shrinks as frames are sent
Window expands as acknowledgements are received 32
16
n
Receiving Window: -
The receiver maintains a receiving window corresponding to the sequence numbers of frames that are accepted
Frames already received
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window
Window of frames that are accepted by receiver
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 Last frame acknowledged Window shrinks as frames are received
Window expands as acknowledgements are sent
© Jorg Liebeherr, 1998
33
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window n
Operations at the sender: 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
send a single packet (with sequence number "0"):
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
© Jorg Liebeherr, 1998
34
17
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window n
Operations at the sender: 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
Receive a single acknowledgement (ACK 1)
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
© Jorg Liebeherr, 1998
35
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window n
Operations at the receiver: 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
Receive a single packet (with sequence number "0"):
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
© Jorg Liebeherr, 1998
36
18
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window n
Operations at the receiver: 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
Transmit a single acknowledgement ("ACK 1"):
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
© Jorg Liebeherr, 1998
37
n
n
How is “flow control” achieved? –
Receiver can control the size of the sending window
–
By limiting the size of the sending window data flow from sender to receiver can be limited
University of Virginia
CS 457 - Computer Networks
Operation of Sliding Window
Interpretation of ACK N message: –
© Jorg Liebeherr, 1998
Receiver acknowledges all packets until (but not including) sequence number N
38
19
University of Virginia
CS 457 - Computer Networks
Example Transmitter
Receiver
0 1 2 3 4 5 6 7 0 1 2 3 F0 F1 F2
0 1 2 3 4 5 6 7 0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3 ACK4 0 1 2 3 4 5 6 7 0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3
© Jorg Liebeherr, 1998
39
University of Virginia
CS 457 - Computer Networks
Example Continued Transmitter
Receiver
0 1 2 3 4 5 6 7 0 1 2 3 F3 0 1 2 3 4 5 6 7 0 1 2 3 F4 F5 F6 0 1 2 3 4 5 6 7 0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3
© Jorg Liebeherr, 1998
ACK3 0 1 2 3 4 5 6 7 0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3
40
20
n
Define: –
We use the same parameters for as in Stop-andWait
–
To simplify notation we set: F/C = 1 I =a
–
(Normalization)
W = Maximum window size (iddentical for sender and receiver)
© Jorg Liebeherr, 1998
41
University of Virginia
CS 457 - Computer Networks
Analysis of Sliding Windows 1st frame received a a+1
0
Wth frame received a+W
... 0
© Jorg Liebeherr, 1998
University of Virginia
CS 457 - Computer Networks
Analysis of Sliding Windows
1
2
W
Receiver
Sender 2a+1 1st ACK received
42
21
n
If the window size is sufficiently large the sender can continuously transmit packets:
n
W ≥ 2a+1: Sender can transmit continuously
University of Virginia
CS 457 - Computer Networks
Analysis of Sliding Windows
normalized efficiency = 1 n
W < 2a+1:Sender can transmit W frames every 2a+1 time units normalized efficiency =
© Jorg Liebeherr, 1998
W 1 + 2a 43
University of Virginia
CS 457 - Computer Networks
ARQ Error Control n
Two types of errors: – Lost frames – Damaged Frames
n
Most Error Control techniques are based on (1) Error Detection Scheme (e.g., Parity checks, CRC), and (2) Retransmission Scheme
n
Error control schemes that involve error detection and retransmission of lost or corrupted frames are referred to as Automatic Repeat Request (ARQ) error control
© Jorg Liebeherr, 1998
44
22
n
All retransmission schemes use all or a subset of the following procedures: – – – –
Receiver sends an acknowledgment (ACK) if a frame is correctly received Receiver sends a negative acknowledgment (NAK) if a frame is not correctly received The sender retransmits a packet if an ACK is not received within a timeout interval All retransmission schemes (using ACK, NAK or both) rely on the use of timers
© Jorg Liebeherr, 1998
University of Virginia
CS 457 - Computer Networks
ARQ Error Control
45
n
Note: Once retransmission is used, a sequence number is required for every data packet to prevent duplication of packets
n
Both ACKs and NAKs can be sent as special frames, or be attached to data frames going in the opposite direction (Piggybacking)
01111110
Address
Control
Data
Checksum
University of Virginia
CS 457 - Computer Networks
ARQ Error Control
01111110
0 Send Seq.-No. P/F Recv Seq.-No. For piggybacking © Jorg Liebeherr, 1998
46
23
University of Virginia
CS 457 - Computer Networks
ARQ Schemes n
n
The most common ARQ retransmission schemes: –
Stop-and-Wait ARQ
–
Go-Back-N ARQ
–
Selective Repeat ARQ
The protocol for sending ACKs in all ARQ protocols are based on the sliding window flow control scheme
© Jorg Liebeherr, 1998
47
n
Stop-and-Wait ARQ is an addition to the Stop-andWait flow control protocol:
•
Frames have 1-bit sequence numbers (SN = 0 or 1) Receiver sends an ACK (1-SN) if frame SN is correctly received Sender waits for an ACK (1-SN) before transmitting the next frame with sequence number 1-SN If sender does not receive anything before a timeout value expires, it retransmits frame SN
• • •
© Jorg Liebeherr, 1998
University of Virginia
CS 457 - Computer Networks
Stop-and-Wait ARQ
48
24
ACK 1 0 Frame
0 Frame
ACK 1
University of Virginia
Stop-and-Wait ARQ
Timeout
A CS 457 - Computer Networks
1 Frame
ACK 0
ACK 0 ACK 1 ACK 0
University of Virginia
1 Frame
1 Frame
49 © Jorg Liebeherr, 1998
50
© Jorg Liebeherr, 1998
0 Frame
1 Frame
Lost ACK n
Lost Frame n
Timeout
A
CS 457 - Computer Networks
Stop-and-Wait ARQ
B
B
25
n
Go-Back-N uses the sliding window flow control protocol. If no errors occur the operations are identical to Sliding Window
n
Operations: –
A station may send multiple frames as allowed by the window size
–
Receiver sends a NAK i if frame i is in error. After that, the receiver discards all incoming frames until the frame in error was correctly retransmitted
–
If sender receives a NAK i it will retransmit frame i and all packets i+1, i+2,... which have been sent, but not been acknowledged
© Jorg Liebeherr, 1998
51
University of Virginia
Frames 4,5,6 are retransmitted
Lost Frame
A
ACK 6
NAK 4
ACK 3
6 Frame
5 Frame 4 Frame 6 Frame
5 Frame 4 Frame 3 Frame
2 Frame 1 Frame 0 Frame
CS 457 - Computer Networks
Go-Back-N ARQ n
University of Virginia
CS 457 - Computer Networks
Go-Back-N ARQ
B Frames 5 and 6 are discarded © Jorg Liebeherr, 1998
52
26
University of Virginia
n
Frames 0-4 are retransmitted
Lost ACK Timeout
A
ACK 5
ACK 3
ACK 3
5 Frame 4 Frame 3 Frame
2 Frame 1 Frame 0 Frame
4 Frame 3 Frame
2 Frame 1 Frame 0 Frame
CS 457 - Computer Networks
Go-Back-N ARQ
B Frames 3 and 4 are discarded © Jorg Liebeherr, 1998
53
University of Virginia
CS 457 - Computer Networks
Details Go-Back-N ARQ A n
Frame
B
Scenario 1: A transmits frame i, and B detects error in frame i, but has received frames i-1, i-2,... correctly è B sends NAKi
n
Scenario 2: Frame i is lost or B does not recognize frame i Assume that A sends frame i+1 and B receives it è B sends NAKi, or A will timeout and retransmit frame i and all subsequent frames
© Jorg Liebeherr, 1998
54
27
Scenario 3: B receives frame i and sends ACK(i+1) which is lost è B may send an ACK(i+k) later which also acknowledges all frames 2I + Tt
U
n
n
W 1+ 2a
W Tt > 2I + Tt
U = 1− P
= 1
W Tt < 2I + Tt
U=
With Errors
n
W Tt < 2I + Tt
U=
W ⋅(1 − P ) 1 + 2a
© Jorg Liebeherr, 1998
63
University of Virginia
CS 457 - Computer Networks
Analysis of ARQ Protocols - Results P=10-3
© Jorg Liebeherr, 1998
64
32
n
XModem is a simple data link protocol which used to be popular for communications over modems
n
Xmodem uses Stop-and-Wait ARQ
SOH NUM 1byte
CNUM 1
1
Data