Chapter3 DataLinkLayer Withnotes
Chapter3 DataLinkLayer Withnotes
Chapter 3
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
The Data Link Layer
• Responsible for delivering frames of
information over a single link (node-to-
node delivery)
Application
• Use services of the Physical Layer Transport
(which delivers bits) to deliver frames
Network
Link
Physical
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Frames
Network
Link
Virtual data path
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Link Layer Protocols
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Possible Services
• Framing
− Encapsulated packets into frames
− Establishes frame synchronization
• Error Control
− Ensuring that all frames are eventually delivered to the
network layer at the destination and in the proper order.
• Flow Control
− Ensuring that the sender does not overwhelm the receiver
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Outline
• Framing
• Error Control
• Error Detection
• Elementary Data Link Protocols
• Sliding Window Protocols
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Framing
• Byte count
• Flag bytes with byte stuffing
• Flag bits with bit stuffing
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Framing
• Blocks of data (termed frames at data link layer)
exchanged between nodes
• Typical frame structure
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Framing – Byte count
Expected
case
Error
case
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Framing – Byte stuffing
Frame
format
Need to escape
extra ESCAPE
bytes too!
Stuffing
examples
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Framing – Bit stuffing
Transmitted bits
with stuffing
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Control
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Control
What cause errors?
• Distortion of signals due to frequency dependent
attenuation, noise (PHY layer)
• Random single-bit vs Burst errors
Error control repairs frames that are received in error
• Requires errors to be detected at the receiver
• After detection:
− Drop Frame
» Higher layers (e.g., TCP) will recover or few losses don’t hurt
applications (e.g., audio)
− Recover Frame
» Error Correction
» Retransmission
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Correction vs Retransmission
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Framework
• Add redundant information to a frame to detect or correct
errors
• At sender: add k bits of redundant data to a m bit
message, where k is derived from the original message
through some algorithm
• At receiver: reapply same algorithm as sender to detect
errors; take corrective action if necessary
• Code rate: m/(m+k)
• Detection: k<<m; k=32; m ~ 12,000 for Ethernet
• Correction: Wi-Fi code rates range from ½ to 5/6
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Bounds – Hamming distance (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Bounds – Hamming distance (2)
Number of possible codewords: 2𝑚+𝑘
Number of legal codewords: 2𝑚
Hamming distance of a code (=d):
• Minimum bit flips to turn one valid codeword into any
other valid one.
• Among the list of legal codewords, find the smallest
hamming distance between two codewords
• Example:
− 0000000000, 0000011111, 1111100000, and 1111111111
− Hamming distance is 5
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Bounds – Hamming distance (3)
Example:
• 0 -> 000; 1 -> 111
• m=1, k=2, m+k = 3
• Hamming distance is 3, code rate is 1/3
• Can detect up to 2 errors and correct up to 1 error
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Design Considerations of a Code
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 1
Data link layer services
Framing: how to detect beginning and end of frames
• Byte count, byte stuffing, bit stuffing
Error Control
• Error Detection
• Error Recovery: Error correction or Retransmission
Framework of Error Detection/Correction
• Hamming distance-> error detection/correction
capabilities
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Error Detection
• Parity
• Cyclic Redundancy Checks (CRCs)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Parity (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Parity (2)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Cyclic Redundancy Check (CRC)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Polynomial Arithmetic
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
CRC
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Key Idea
• Sender:
• Append a CRC (k bits) to the end of the frame =>
Transmitted message T(x),
• where T(x) is divisible by G(x).
• Receiver:
• Divide the received frame R(x) by G(x).
• If there is no remainder, there are no transmission
errors
• If there is a remainder, there are transmission errors.
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Algorithm for Computing T(x)
• You have M(x) and G(x). How to compute T(x)
1. Append k zero bits to the low-order end of the frame,
which is 𝑥 𝑘 𝑀(𝑥)
2. Divide 𝑥 𝑘 𝑀 𝑥 by G(x) to get remainder C(x)
3. Subtract remainder C(x) from 𝑥 𝑘 𝑀 𝑥 to get T(x)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Example
Start by adding
0s to frame
and try dividing
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Elementary Data Link Protocols
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Motivation
Node-to-node delivery of frames
• Frames can get corrupted or lost
• Error Detection helps detect corrupted frames
• What next?
Recover the corrupted/lost frames
• Reliable data transfer protocols (RDT) are needed
Implementation
Service Receiving
Sending
Network
process process
Sending Receiving
Network
process process
Data Link Sending Receiving
side RDT side RDT
Data Link Reliable Channel
Unreliable Channel
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Utopian Simplex Protocol (p1)
Assumptions:
Functionalities:
• Receiver as fast as sender
• None
• No errors
• No losses
TX RX
Frame0
• No error control
Frame1 • No flow control
Frame2
…
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p2)
Assumptions:
Functionalities:
• Receiver may not run as
fast as sender • Receiver feedback
• No errors
• No losses
TX RX
Frame0
• Flow control added
• No error control
ACK
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p3.1)
Assumptions: Functionalities:
• Receiver may not run as fast • Receiver feedback
as sender
• Error detection
• Errors exist
• No losses
TX RX TX RX
Frame0 Frame0
• Flow control added
• Error control added
ACK NACK
Frame1 Frame0
What if ACK/NACK
get corrupted?
…
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p3.2)
Assumptions: Functionalities:
• Receiver may not run as fast as • Receiver feedback
sender • Error detection
• Errors exist • Data sequence
• ACK/NACK can get corrupted number
• No losses
TX RX TX RX TX RX TX RX
…
…
…
Duplicate RX accepts
RX discards
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p3.3)
What is the sequence number space?
• Two numbers, ”0, 1”, will suffice
Can we get rid of NACK?
• Instead of NACK, receiver sends ACK of last correctly
received frame
TX RX
Frame0
ACK0
Frame1
ACK0
Duplicate ACK
Retransmit frame Frame1
…
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p4)
Assumptions: Functionalities:
• Errors exist • Receiver feedback
• Receiver may not run as fast as • Error detection
sender • Data sequence
• Losses can happen number
• Timeout mechanism
TX RX TX RX
Frame0 Frame0
ACK
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p4)
TX RX TX RX
Frame0 Frame0
ACK0
Timeout
Frame1 Frame0
Retransmit frame
ACK1 ACK0
…
…
a) No loss b) Lost frame
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Stop-and-Wait (p4)
TX RX
Frame0
ACK0
Timeout Frame0
c) Lost ACK
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Summary of Stop-and-Wait
• Source transmits frame
• Destination receives frame and replies with
acknowledgement (ACK)
• Source waits for ACK before sending next
• Destination can stop flow by not sending ACK
• Works well for a few large frames
• Stop and wait becomes inadequate if large block of
data is split into small frames
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 2
• Error detection
• Parity & CRC
• Reliable data transfer protocols provide “reliable
channel” service abstraction to higher layers.
• We incrementally determined the required functionalities
needed in RDT protocols (stop-and-wait).
• Receiver feedback
• Error detection
• Data sequence number
• Timeout mechanism
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Performance of Stop-and-Wait
What is the achieved throughput?
• 10 Mbps link, 10ms propagation delay, 1KB frame,
small ACK (with negligible transmission time)
Sender Receiver
RTT ACK0
Utilization = 384.6Kbps/10^7 =
(8000/10^7)/(8000/10^7+2*0.01) = 3.8%
Frame1
…
𝑇𝑋 𝑇𝑖𝑚𝑒
Utilization =
𝑇𝑋 𝑇𝑖𝑚𝑒+𝑅𝑇𝑇
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Sliding Window Protocols
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Key Idea
…
Frame6 Utilization = Utilization =
Frame7 4∗𝑇𝑋 𝑇𝑖𝑚𝑒 𝑇𝑋 𝑇𝑖𝑚𝑒
𝑇𝑋 𝑇𝑖𝑚𝑒+𝑅𝑇𝑇 𝑇𝑋 𝑇𝑖𝑚𝑒+𝑅𝑇𝑇
…
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Sliding Window Concept
Sender maintains window of frames it can send
• Needs to buffer them for possible retransmission
• Window advances with next acknowledgements
Receiver maintains window of frames it can receive
• Needs to keep buffer space for arrivals
• Window advances with in-order arrivals
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Sender
Assign a sequence number to each frame
Maintain 3 variables:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
…
• BD = Bandwidth *Propagation
Utilization =
Delay/FrameSize 4∗𝑇𝑋 𝑇𝑖𝑚𝑒
𝑇𝑋 𝑇𝑖𝑚𝑒+𝑅𝑇𝑇
BD: bandwidth-delay CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Discussions
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Receiver Actions
Frame “SeqNum” arrives
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Acceptable, not
Received, but out-of-order received yet
LFR LAF
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
0 1 2 3 4 5 6 7 4
0 1 2 3 E 5
0 1 2 3 4 5 6 7 4
0 1 2 3 E 5 E 7
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Cumulative ACK-Example (2)
Example:
• frames 0,1,2,3,5,7 arrive in that order
• State: receiver acked frame 3, assume RWS is 4
(3) When 4 arrives: accept 4, pass up frames till 5, ack 5, LFR = 5, LAF = 9
0 1 2 3 4 5 6 7 4
0 1 2 3 E 5 E 7 4
0 1 2 3 E 5 E 7 4 E E E 6
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Selective ACK
ACK sequence number of whatever packet accepted
In previous example:
• When 5 arrives, ack 3, sack 5
• When 7 arrives, ack 3, sack 7, 5
• When 4 arrives, ack 5, sack 7
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Sender Actions (1)
On receiving frames from higher layers:
• If SeqNum – LAR <= SWS, send the frame, else buffer or inform
application
LAR Sent, but not yet acknowledged LFS Can send, but not yet sent
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
LAR Sent, but not yet acknowledged LFS Can send, but not yet sent
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Go-Back-N (2)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Selective Repeat (1)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Selective Repeat (2)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Selective Repeat (3)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Automatic Repeat Request (ARQ)
Collective name for error control mechanisms that use
acknowledgements and timers to achieve reliable data
transmission over an unreliable service.
Types of ARQ:
• Stop-and-Wait
• Go-Back-N
• Selective Repeat
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Duplex Data Transmission
Transfers data in both directions
• Piggybacks acks on reverse data frames for efficiency
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011
Review - 3
• Sliding window protocols rely on ”window of frames” to
improve performance
• Go-back-N (RWS=1), selective repeat (RWS>1)
• More complex (range of sequence numbers, types of
ACK, action at sender/receiver
• In addition to reliability, they provide
• In-order delivery
• Flow control
• Milestone: achieve point-to-point reliable and efficient
data transfer (building block)
CN5E by Tanenbaum & Wetherall, © Pearson Education-Prentice Hall and D. Wetherall, 2011