Data Link Layer Functionality z
Data Link Layer
Services provided by the link layer
Frame creation Error detection and/or correction Flow control Reliable delivery
Creating the illusion of a reliable link 1
2
Framing
Frame Delineation
The data unit at the data link layer is called a “frame” z A frame is a group of bits, typically in sequence z Issues: z
z
How to tell when a new frame starts: Frame
tags with character stuffing Frame tags with bit stuffing
Frame
creation Frame delineation 3
4
1
Frame tagging with character stuffing
Character stuffing z
Frame tags (special characters)
z z
Use starting and ending characters (tags) to mark boundaries of frame Problem: What if tag characters occur in the data or control portions of the frame?
Insert extra escape characters when a tag appears in data field DLE
STX
Start Tag
DLE
ETX
End Tag
DLE
DLE
Character Stuffed DLE code
5
6
Character Stuffing
Character Stuffing Example I am a
DLE
jerk trying to DLE
PPP
ETX crash your network!
z
Tagging and Character Stuffing
DLE
STX I am a DLE
DLE
jerk trying to DLE
DLE
z
ETX crash your network! DLE
PPP = Point-to-Point Protocol, used widely in the Internet PPP uses frame tags with character or byte stuffing
ETX
PPP Frame Format 01111110
Control Fields
Payload (up to 1500 bytes)
Checksum
01111110
Untagging and Character Unstuffing
I am a
DLE
jerk trying to DLE
ETX crash your network!
Character Frame Tags
7
8
2
Frame tagging with bit stuffing
Bit stuffing
Bit strings may be used instead of character sequences to delineate frames z More efficient
Each frame begins with a start and end bit sequence, e.g., 01111110 z When sender’s data link layer sees five 1’s in a row, it stuffs a zero bit z The receiver “unstuffs” a zero after five consecutive 1’s.
z
z
9
Bit unstuffing
Bit Stuffing Example
When a pattern of five 1s appears, examine sixth bit z If the sixth bit is 0, remove it (stuffed bit) z If the sixth bit is 1, check seventh bit z
If If
10
0, accept as flag (BOF or EOF) 1, error
00110010111111100010100
Tagging and Bit Stuffing
0111111000110010111110110001010001111110
Untagging and Bit Unstuffing
00110010111111100010100
11
12
3
Bit Stuffing
Error Control
HDLC z z
HDLC = High-level Data Link Control. Used in X.25 networks HDLC uses frame tags with bit stuffing
No physical link is perfect z Bits will be corrupted z We can either: z
detect
HDLC Frame Format 01111110
Control Fields
Payload (arbitrarily long)
Checksum
or
01111110
errors and request retransmission correct errors without retransmission
Character Frame Tags
13
14
Error Detection
Parity bits Append a single parity bit to a sequence of bits z If using “odd” parity, the parity bit is chosen to make the total number of 1’s in the bit sequence odd. z If “even” parity, the parity bit makes the total number of 1’s in the bit sequence even
Parity bits z Polynomial codes or checksums
z
z
15
16
4
Parity bits: Example
Parity Bits Only detects when there are an odd number of bit errors z Does not detect an even number of bit errors z It also has high overhead; it requires 1 extra bit for every several bits transmitted z
Transmitted Sequence
Parity
00010101
even
01111
even
11111111
odd
10011
odd
Parity Bit
17
18
Checksum
Polynomial Codes
Consider data as 16 bit words. z Add all the data values (1s complement of this sum is the checksum) z Receiver adds all the words and the checksum. z If no errors, then sum is all 1s
z
z
z z z
Can detect errors on large chunks of data Has low overhead More robust than parity bit Requires the use of a “code polynomial”
19
Example: x2 + 1
20
5
Generating a CRC
Cyclic Redundancy Check z z
Example Message: 1011
CRC: Example of a polynomial code Procedure: 1. Let r be the degree of the code polynomial. Append r zero bits to the end of the transmitted bit string. Call the entire bit string S(x) 2. Divide S(x) by the code polynomial using modulo 2 division. 3. Subtract the remainder from S(x) using modulo 2 subtraction.
z
The result is the checksummed message
1 x x3 + 0 x x2 + 1 x x + 1 = x3 + x + 1
Code Polynomial: x2 + 1 (101)
Step 1: Compute S(x) r=2 S(x) = 101100
21
22
Generating a CRC
Generating a CRC
Example (cont’d)
Example (cont’d) Step 3: Modulo 2 subtract the remainder from S(x)
Step 2: Modulo 2 divide 1001 101
101100 101 001 000 010 000 100 101 01
101100 01 101101
Checksummed Message
Remainder
23
24
6
Decoding a CRC
Decoding a CRC z
Example
Procedure 1. Let n be the length of the checksummed message in bits 2. Divide the checksummed message by the code polynomial using modulo 2 division. If the remainer is zero, there is no error detected.
101101
Checksummed message (n = 6)
1011
Original message (if there are no errors)
1001 101
101101 101 001 000 010 000 101 101 00
25
Decoding a CRC Another Example
Choosing a CRC polynomial
When a bit error occurs, there is a large probability that it will produce a polynomial that is not an even multiple of the code polynomial, and thus errors can usually be detected. 1000 101
The longer the polynomial, the smaller the probability of undetected error z Common standard polynomials: z
(1) CRC-12: x12 + x11 + x3 + x2 + x1 + 1 (2) CRC-16: x16 + x15 + x2 + 1 (3) CRC-CCITT: x16 + x12 + x5 + 1
101001 101 000 000 000 000 001 000 01
Remainder = 0 (No error detected) 26
Remainder = 1 (Error detected)
27
28
7
Flow Control
Controlling the Flow of Data
What happens if the sender tries to transmit faster than the receiver can accept? z Data will be lost unless flow control is implemented z
Slow Joe Fast Frank
29
Some Flow Control Algorithms
30
Flow control in the ideal network
Flow
control for the ideal network and Wait for noiseless channels Stop and Wait for noisy channels Sliding window protocols Sliding window with error control
Assumptions: Error free transmission link, Infinite buffer at the receiver
Stop
– Go Back N – Selective Repeat
No acknowledgement of frames necessary
31
Since the data link is error-free and the receiver can buffer as many frames as it likes, no frame will ever be lost 32
8
Stop and Wait with Noiseless Channels
Flow control in the ideal network (cont’d)
Assumptions: Error free transmission link, Finite buffer at the receiver
Slow Joe Fast Frank
Problem of Buffer overflow at the receiver Infinite bucket
Buffer overflow may happen at the receiver when the sending router sends frames at a rate faster than the receiving router
33
34
Stop and Wait with Noiseless Channels (cont’d)
Stop and Wait with Noiseless Channels (cont’d) z
Solution: Stop-and-Wait The
receiver sends an acknowledgement frame telling the sender to transmit the next data frame. The sender waits for the ACK, and if the ACK comes, it transmits the next data frame.
Slow Joe Fast Frank
Finite bucket (once full, ball is lost)
35
36
9
Stop and Wait with Noiseless Channels (cont’d)
Stop and Wait (cont’d)
Data
z
ACK
z
Data
Note that we assume an error-free transmission link and therefore ACK frames will not be lost In this flow control protocol, there are two types of frames: data frames and ACK frames. The ACK frames don’t contain any particular information, since only the arrival of the ACK frame at the sender is important.
37
Stop and Wait for Noisy Channels
38
Problems introduced by a noisy line
Assumptions:
Problem 1: Loss of a data or ACK frame
Transmission link may cause errors in frames, Finite buffer at the receiver
Since
the transmission link is not error-free, a data or ACK frame may be lost, causing the sender to wait indefinitely for an ACK
ACK frames may now be lost
39
40
10
Loss of an ACK frame
Problems introduced by a noisy line
Data
ACK
Can we solve problem 1 by introducing a timeout period for the sender? Yes, but... Problem 2: Duplicated frames error
If the ACK frame for a certain data frame is lost, the sender will retransmit the same frame after a time-out period, and the receiver will then have two copies of the same frame
? 41
42
Stop and Wait for Noisy Channels
Duplicated data frames
(cont’d) z
Data
Solution: The
ACK
Data
Duplicate data
sender uses a timer to retransmit data frames when an ACK has not arrived The sender includes a sequence number in each frame to distinguish one frame from another. This way, the receiver knows when it has received duplicate frames.
Timed Out
43
44
11
Stop and Wait for Noisy Channels
Is Stop and Wait the best we can do?
(cont’d)
Stop and Wait is an effective form of flow control, but…
Data 1
1
ACK
receiver knows to discard this data
Data 1
Better solution? Sliding Window 1
Timed Out
It’s not very efficient. 1. Only one data frame can be in transit on the link at a time 2. When waiting for an acknowledgement, the sender cannot transmit any frames
1
45
46
Simple Sliding Window with Window Size of 1
Sliding Window Protocols Definitions Sequence Number: Each frame is assigned a sequence number that is incremented as each frame is transmitted Sender Window: Keeps track of sequence numbers for frames that have been sent but not yet acknowledged Receiver Window: Keeps track of sequence numbers for frames the receiver is allowed to accept Maximum Sender Window size: The maximum number of frames the sender may transmit without receiving any acknowledgements Maximum Receiver Window size: The maximum number of frames the receiver may receive before returning an acknowledgement to the sender 47
A sliding window with a maximum window size of 1 frame 7
0 1
6
2
5 4
3
Window for a 3-bit sequence number 48
12
Simple Sliding Window with Window size 1 (cont’d)
Sliding Window example Sender window 7
7
0
6
1
5
2
1
5
3
4
7
0
6
2
1
5
3
4
7
0
6
2
This protocol behaves identically to stop and wait for a noisy channel
1
5
3
4
0
6
2 3
4
Receiver window 7
7
0
6
1
5
2 3
4
(a)
7
0
6
1
5
2 3
4
(b)
7
0
6
1
5
2
1
5
3
4
0
6
(c)
2 3
4
(d)
(a) Initial state, no frames transmitted, receiver expects frame 0 (b) Sender transmits frame 0, receiver buffers frame 0 (c) Receiver ACKS frame 0 (d) Sender receives ACK, removes frame 0 49
Sliding Window Protocols
Sliding Window Protocols
General Remarks
Piggybacking Acknowledgements
z
The sending and receiving windows do not necessarily have the same maximum size
z
Any frame whose sequence number falls outside the receiver window is discarded at the receiver
z
The sender window’s size grows and shrinks as frames are transmitted and acknowledged
z
50
Since we have full duplex transmission, we can “piggyback” an ACK onto the header of an outgoing data frame to make better use of the channel
When a data frame arrives at a router, instead of immediately sending a separate ACK frame, the router waits until it is passed the next data frame to send. The acknowledgement is attached to the outgoing data frame.
Unlike the sender window, the receiver window always remains at its maximum size
51
52
13
Sliding Window with Maximum Sender Window Size WS
Sender-Side Window with WS=2
With a maximum window size of 1, the sender waits for an ACK before sending another frame
7
7
0
6
1
5
2
1
5
3
4
2
7 6
1
5
This allows the sender to transmit several frames before waiting for an acknowledgement
2 3
4
(e)
1
5
2
6
1
5
2 3
4
(f)
(a) Initial window state (b) Send frame 0 (c) Send frame 1 (d) ACK for frame 0 arrives
1
5
2
(d) 7
0
6
1
5
2 3
4
(g)
3
4
(c) 7
0
0
6
3
4
(b) 7
0
7
0
6
3
4
(a)
With a maximum window size of WS, the sender can transmit up to WS frames before “being blocked”
7
0
6
0
6
1
5
2 3
4
(h)
(e) Send frame 2 (f ) ACK for frame 1 arrives (g) ACK for frame 2 arrives, send frame 3 (h) ACK for frame 3 arrives
53
54
Sliding Window with Maximum Receiver Window Size WR
Pipelining Sliding window with WS > 1 is also called “pipelined” communication
With a maximum window size of 1, the receiver must receive and process every frame in sequence
data stream
With a maximum window size of WR, the receiver can receive and process up to WR frames before acknowledging them
A
99 0
51 1
50 49
B
ACK stream
By allowing several frames onto the link before receiving an acknowledgement, pipelining keeps the link from being idle 55
This is useful when frames are lost: the receiver can still accept and buffer frames after the missing frame
56
14
What about Errors?
Receiver-Side Window with WR=2 7
7
0
6
1
5
2
1
5
3
4
2
7
0 1
5
2 3
4
(e)
1
5
2
7
0 1
5
2 3
4
2
(f)
(a) Initial window state (b) Nothing happens (c) Frame 0 arrives, ACK frame 0 (d) Nothing happens
7
0 1
5
2 3
(g)
3
4
(d)
6
4
What if a data or acknowledgement frame is lost when using a sliding window protocol?
1
5
(c)
6
0
6
3
4
(b)
6
7
0
6
3
4
(a) 7
7
0
6
0
6
1
5
Two Solutions: Go Back N Selective Repeat
2 3
4
(h)
(e) Frame 1 arrives, ACK frame 1 (f) Frame 2 arrives, ACK frame 2 (g) Nothing happens (h) Frame 3 arrives, ACK frame 3 57
58
Sliding Window with Go Back N
0
1
3
4
3
4
5
ACK 6
2
ACK 5
1
ACK 3
0
ACK 4
Sender
ACK 2
Timeout interval
ACK 1
z
When the receiver notices a missing or erroneous frame, it simply discards all frames with greater sequence numbers and sends no ACK The sender will eventually time out and retransmit all the frames in its sending window
ACK 0
z
Go Back N 2
6
2
3
4
5
6
Maximum window size = 8
Receiver Maximum window size = 8
E
D
D
Discarded by receiver Frame with error 59
Time 60
15
Sliding Window with Selective Repeat
Go Back N (cont’d) Go Back N can recover from erroneous or missing frames But… It is wasteful. If there are errors, the sender will spend time retransmitting frames the receiver has already seen 61
The sender retransmits only the frame with errors z The receiver stores all the correct frames that arrive following the bad one. (Note that the receiver requires a frame buffer for each sequence number in its receiver window.) z When the receiver notices a skipped sequence number, it keeps acknowledging the last good sequence number z When the sender times out waiting for an acknowledgement, it just retransmits the one unacknowledged frame, not all its successors. 62
Selective Repeat
ACK 6
1
5
ACK 5
0
2
ACK 4
2
ACK 1
1
ACK 1
0
ACK 1
Sender
ACK 0
Timeout interval 3
4
6
3
4
2
5
6
Maximum window size = 8
Receiver Maximum window size = 8
E
Buffered by receiver Frame with error
Time 63
16