You are on page 1of 66

ECE

436 Computer
Communication Networks II

Link Layer I
Link Layer
Learning Layers: We started with the Physical Layer

Application
Transport
Network
Link
Physical
Physical Layer
Topics

Properties of media: Wires, fiber optics, wireless

Simple signal propagation: Bandwidth,


attenuation, noise

Modulation schemes: Representing bits, noise

Fundamental limits: Nyquist, Shannon


Link Layer
Learning Layers: Now, we continue with the Link Layer

Application
Transport
Network
Link
Physical
Link Layer
Scope of the Link Layer
Concerns how to transfer messages over one or
more connected links
Messages are frames, of limited size
Builds on the physical layer

Frame
Link Layer
Frames
Link layer accepts packets from the network layer, and
encapsulates them into frames that it sends using the physical
layer; reception is the opposite process

Network

Link
Virtual data path

Physical Actual data path


Link Layer
Typical Implementation of Layers

User Level Application

Transport
Operating Network
System

Link

Hardware
Physical
Link Layer
Typical Implementation of Layers
Link Layer
Topics
Framing
Delimiting start/end of frames

Error detection and correction


Handling errors

Retransmissions
Handling loss

Multiple Access
802.11, classic Ethernet

Switching
Modern Ethernet
Link Layer - Framing
Topic
The Physical Layer gives us a stream of bits. How do we
interpret it as a sequence of frames?

1100101100011
????
Link Layer - Framing
Framing Methods
We will consider the following framing methods:
Byte count
Byte stuffing
Bit stuffing

In practice, the physical layer often helps to identify frame


boundaries
E.g., Ethernet, 802.11
Link Layer - Framing
Byte Count
Frame begins with a count of the number of bytes in it

How well does it work?


Link Layer - Framing
Byte Count
Frame begins with a count of the number of bytes in it
Difficult to resynchronize after an error

Expected
case

Error
case
Link Layer - Framing
Byte Stuffing
Better idea
Have a special flag byte value that means start/end of
frame
Replace (stuff) the flag inside the frame with an escape
code
Complication: have to escape the escape code

Flag Header Payload Field Trailer Flag


Link Layer - Framing
Byte Stuffing

Frame
format

A ESC FLAG B

Stuffing
A ESC ESC B
examples
A ESC ESC ESC FLAG B
A ESC ESC ESC ESC B
Link Layer - Framing
Bit Stuffing
Can stuff at the bit level too
Call a flag six consecutive 1s
On transmit, after five 1s in the data, insert a 0
On receive, a 0 after five 1s is deleted
Link Layer - Framing
Bit Stuffing
Can stuff at the bit level too
Call a flag six consecutive 1s
On transmit, after five 1s in the data, insert a 0
On receive, a 0 after five 1s is deleted

Data bits

Transmitted bits
with stuffing
Link Layer - Framing
PPP over SONET

PPP is Point-to-Point Protocol


Widely used for link framing
E.g., it is used to frame IP packets that are sent over SONET
optical links
Link Layer - Framing
PPP over SONET

Think of SONET as a bit stream, and PPP as the framing that


carries an IP packet over the link

Protocol stacks PPP frames may be split over


SONET payloads
Link Layer - Framing
PPP over SONET

Framing uses byte stuffing


FLAG is 07E and ESC is 07D

0x21 for IPv4 IP packet


Link Layer
Topics
Framing
Delimiting start/end of frames

Error detection and correction


Handling errors

Retransmissions
Handling loss

Multiple Access
802.11, classic Ethernet

Switching
Modern Ethernet
Link Layer - Error Control
Topic

Some bits will be received in error due to noise. What can we


do?
Detect errors with codes
Correct errors with codes
Retransmit lost frames

Reliability is a concern of ~all layers


Link Layer - Error Control
Erroneous bits due to noise

1 1 1
Signal 0 0 0 0 0

Noisy 1 1 1
Signal 0 0 0 0 0

Very
Noisy 1 1 1
0 0 0 0 0
Signal
Link Layer - Error Control
Solution Add Redundancy

Error detection codes


Add check bits to the message bits to let some errors be
detected

Error correction codes


Add more check bits to let some errors be corrected

How to construct the codes to detect many errors with few


check and modest computation?
Link Layer - Error Control
Motivating Example

A simple code to handle errors:


Send two copies!
010 010
At the receiver side, if the two copies are different, then
we can understand that there is error in one of them.

Is this a good code?


How many errors can it detect/correct
How many errors will make it fail?
Link Layer - Error Control
Motivating Example

A simple code to handle errors:


Send two copies!
010 010
At the receiver side, if the two copies are different, then
we can understand that there is error in one of them.

Is this a good code?


Cannot correct any errors
Can detect 3 errors if they are different positions
2 errors at the same location will make it fail
50% redundancy
Link Layer - Error Control
Motivating Example

We want to handle more errors with less overhead


Will look at better codes; arise from applied mathematics
They also cant handle all errors
They focus on random/accidental errors
Link Layer - Error Control
Using Error Codes

Codeword consists of D data + R check bits

Data Bits Check Bits


D R

Sender computes R check bits based on the D data bits, and


sends codeword of D+R bits
Link Layer - Error Control
Using Error Codes

Receiver
Receive D+R bits with unknown errors
Recompute R check bits based on the D data bits; error if R does not
match R

Data Bits Check Bits


D R

R = f(D)
???
Link Layer - Error Control
Intuition for Error Codes

For D data bits, R check bits:

All
codewords 2D+R codewords

Correct
codewords
2D codewords

Randomly chosen codeword is unlikely to be correct/good;


overhead is low
Link Layer - Error Control
Error Bounds Hamming Distance
Hamming distance is the minimum bit flips to turn one valid
codeword into any other valid one.
111 and 000. Distance = 3.
111, 100, and 010. Distance = 2.
Example with 4 codewords of 10 bits (D=2, R=8):
0000000000,
0000011111,
1111100000,
1111111111
Hamming distance is 5
Link Layer - Error Control
Error Bounds Hamming Distance
Bounds for a code with distance:
d+1 can detect d errors
2d+1 can correct up to d errors by mapping to the
closest codeword

Example I: 111 and 000.


Hamming distance = 3. Detect 2 errors.
2 bit flips 001, 010, 011, 100, 101, 110 not valid
codewords, error is detected
3 bit flips 000, 111 also valid codewords cannot
detect 3 bit flips
Link Layer - Error Control
Error Bounds Hamming Distance
Bounds for a code with distance:
d+1 can detect d errors
2d+1 can correct up to d errors by mapping to the closest
codeword

Example II: Example with 4 codewords of 10 bits (D=2, R=8):


0000000000, 0000011111, 1111100000, and 1111111111
Hamming distance is 5
d+1 = 5 detect 4 errors
Link Layer - Error Control
Error Bounds Hamming Distance
Bounds for a code with distance:
d+1 can detect d errors
2d+1 can correct up to d errors by mapping to the closest codeword

Example I: 111 and 000.


Hamming distance = 3. Correct 1 bit flips.
1 bit flip on 111 110, 101, 011 mapped to 111 error is corrected
1 bit flip on 000 001, 010, 100 mapped to 000 error is corrected
2 bit flips on 111 100, 001, 010 mapped to 000 error is not
corrected
2 bit flips on 000 011, 101, 110 mapped to 111 error is not
corrected
Similarly, 3 bit flips cannot be corrected. Check it by yourself.
Link Layer - Error Control
Error Bounds Hamming Distance
Bounds for a code with distance:
d+1 can detect d errors
2d+1 can correct up to d errors by mapping to the closest
codeword

Example II: Example with 4 codewords of 10 bits (D=2, R=8):


0000000000, 0000011111, 1111100000, and 1111111111
Hamming distance is 5
2d+1 = 5 correct 2 errors
Link Layer - Error Detection

Some bits may be received in error due to noise. We can


detect this
Parity
Checksums
CRCs

After detecting errors, we can make a decision to correct the


errors or retransmit the erroneous packets
Link Layer - Error Detection
Parity
Parity bit is added as the modulo 2 sum of
data bits
Equivalent to XOR; this is even parity
Ex: 1110000 11100001
Detection checks if the sum is wrong (an error)
Distance = 2
Correct 0 bits (2d+1 = 2)
Detect 1 bits (d+1=2)
This is a lower bound, can do better
Detect all odd number of errors
Link Layer - Error Detection
Parity
Parity bit is added as the modulo 2 sum of data
bits
Equivalent to XOR; this is even parity
Ex: 1110000 11100001
Detection checks if the sum is wrong (an error)

Simple way to detect an odd number of errors


Ex: 1 error, 11100101; detected, sum is wrong
Ex: 3 errors, 11011001; detected sum is wrong
Ex: 2 errors, 11101101; not detected, sum is right!
Error can also be in the parity bit itself
Random errors are detected with probability
Link Layer - Error Detection
Checksums
Checksum treats data as N-bit words and
adds N check bits that are the modulo 2N
sum of the words
Improved error detection over parity bits
E.g., TCP/IP/UDP they all use 16-bit checksum
Link Layer - Error Detection
Internet Checksum - Sender
The IP checksum is the 16 bit one's complement of the
one's complement sum of all 16 bit words in the header.
Example data: 0000 0010 1000 0001 1111 1101 1010
0011 0011 0001 1000 0010 1101 1101 1100 0100
0000 0010 1000 0001 0281 - Negate (complement): 0f6c f093
1111 1101 1010 0011 fda3
0011 0001 1000 0010 3182 - f093 is the Internet Checksum
1101 1101 1100 0100 ddc4
0000 0000 0000 0000 0000 - Send:
+
--------------------------------------------- 0281
20f6a fda3
--------------------------------------------- 3182
0f6a ddc4
2 f093
+
---------------------------------------------
0f6c
Link Layer - Error Detection
Internet Checksum - Receiver
Example data: 0000 0010 1000 0001 1111 1101 1010
0011 0011 0001 1000 0010 1101 1101 1100 0100
Received data 0281, fda3, 3182, ddc4, f093
Check for errors
0000 0010 1000 0001 0281 - Negate (complement): ffff
1111 1101 1010 0011 fda3 0000
0011 0001 1000 0010 3182
1101 1101 1100 0100 ddc4
1111 0000 1001 0011 f093 - No errors are detected.
+
---------------------------------------------
2fffd
---------------------------------------------
fffd
2
+
---------------------------------------------
ffff
Link Layer - Error Detection
Internet Checksum - Receiver
How well does the checksum work?
Distance is 2
Can detect up to 1 error
However;
Detects bursts up to N errors
Detects random errors with probability 1-2-N
Stronger than parity check
But not as strong as we would like
Vulnerable to systematic errors; e.g., added zeros
Link Layer - Error Detection
In Practice
CRCs are widely used on links
Ethernet, 802.11, ADSL, Cable,
Checksum used in the Internet
IP, TCP, UDP, but it is weak
Parity
Limited use
Link Layer - Error Correction
Why error correction is hard
If we had reliable check bits we could use them to narrow
down the position of the error
Then correction would be easy

But error could be in the check bits as well as the data bits.
Data might even be correct
Link Layer - Error Correction
Intuition for Error Correcting Code
Suppose we construct a code with a Hamming distance of at
least 3
Need 3 bit errors to change one valid codeword into
another
Single bit errors will be closest to a unique valid codeword

If we assume errors are only 1 bit, we can correct them by


mapping an error to the closest valid codeword
Works for d errors if HD 2d+1
Link Layer - Error Correction
Intuition for Error Correcting Code

A C

B D
Link Layer - Error Correction
Intuition for Error Correcting Code

A C

B D
Link Layer Error Control
Error Correction in Practice
Heavily used in physical layer
LDPC is the future used for demanding links like 802.11, WIMAX, LTE,
power-line,
Convolution codes widely used in practice

Error detection with retransmission is used in the link layer


and above for residual errors

Correction also used in the application layer


Called Forward Error Correction (FEC)
Normally with and erasure model
E.g., Reed Solomon Codes (CDs, DVDs, etc.), network coding for storage
Link Layer
Topics
Framing
Delimiting start/end of frames

Error detection and correction


Handling errors

Retransmissions
Handling loss

Multiple Access
802.11, classic Ethernet

Switching
Modern Ethernet
Link Layer Retransmissions
Two strategies to handle errors
Detect errors and retransmit frame;
Automatic Repeat reQuest ARQ

Correct errors with an error correcting code


Link Layer
Context on Reliability
Where in the protocol stack should we place reliability
functions?

Application
Transport
Network
Link
Physical
Link Layer
Context on Reliability
Everywhere. It is a key issue
Different layers contribute differently

Application
Transport
Network With increasing level of
Link application-awareness
Physical
Link Layer -ARQ
ARQ often used when errors are common or must be corrected
E.g., WiFi, and TCP

Rules at sender and receiver


Receiver automatically acknowledges correct frames with
an ACK
Sender automatically resends after timeout, or until an ACK
is received, or until maximum number of retransmissions is
achieved
Link Layer -ARQ
Normal operation (no loss)

Sender Receiver

Frame

Timeout Time

ACK
Link Layer -ARQ
Loss and retransmission

Sender Receiver

Frame

Timeout Time

Frame

Timeout
ACK
Link Layer -ARQ
Why are frames lost over the links?
Frame could be received by the receiver, but error is
detected
Noise/resulting error so severe that receiver may not detect
frame
Link Layer -ARQ
Why automatic repeat request?

Sender Receiver

Frame

Timeout Time

Frame

Timeout
ACK
Link Layer -ARQ
What is tricky about ARQ?
Non-trivial issues
How long to set the timeout?
How to avoid accepting duplicate frames as new frames

Want
Performance in the common case
Correctness always
Link Layer ARQ
Timeouts
Timeouts should be
Not too big (link goes idle)
Not too small (too many retransmissions)

Fairly easy on a LAN


Clear worst case, little variation

Fairly difficult over the Internet


Much variation, no obvious bound
Link Layer ARQ
Duplicates
What happens if an ACK is lost?

Sender Receiver

Frame

Timeout
ACK
Frame
The same frame?
New frame?
ACK
Link Layer ARQ
Duplicates
Or the timeout is early?

Sender Receiver

Frame

Timeout Frame
ACK
The same frame?
New frame?
ACK
Link Layer ARQ
Sequence Numbers
Frames and ACKs must both carry sequence numbers for
correctness

To distinguish the current frame from the next one, a single


bit (two numbers) is sufficient
Called Stop-and-Wait
Link Layer ARQ
Stop-and-Wait
In the normal case:

Sender Receiver
Frame - 0
Frame - 0

ACK - 0

Frame - 1
Frame - 1

ACK - 1
Link Layer ARQ
Stop-and-Wait
With ACK loss:

Sender Receiver
Frame - 0
Frame - 0

ACK - 0

Frame - 0
Frame 0
Resend
ACK - 0
Link Layer ARQ
Limitation of Stop-and-Wait
It allows only a single frame to be outstanding from the
sender
Good for LAN, not efficient for high BD

Example: R = 1 Mbps, D = 50ms


RTT = 2D = 100ms
How many frames/sec? Frame = 10000 bits
1Mbps 100ms = 100kbps
100kbps / 10000 bits = 10 frames/sec
Link Layer ARQ
Sliding Window
Generalization of stop-and-wait
Allows W frames to be outstanding
Can send W frames per RTT

Various options for numbering frames/ACKs and


handling loss

You might also like