Department of Computer and IT Engineering
University of Kurdistan
Data Communication Netwotks (Graduate level)
Data Link Layer
By: Dr. Alireza Abdollahpouri
2
Data Link Layer
Data Link Layer
� Function: � Send blocks of data (frames)
between physical devices
� Regulate access to the physical media
� Key challenge: � How to delineate frames?
� How to detect errors?
� How to perform media access control (MAC)?
� How to recover from and avoid collisions ?
Application
Presentation
Session
Transport
Network
Data Link
Physical
3
Adaptors Communicating
� link layer implemented in
“adaptor” (NIC)
� Ethernet card, PCMCI card, 802.11 card
� sending side:
� encapsulates datagram in a frame
� adds error checking bits, rdt, flow control, etc.
� receiving side
� looks for errors, rdt, flow control, etc
� extracts datagram, passes to receiving node
� adapter is semi-
autonomous
� link & physical layers
sending node
frame
receiving node
datagram
frame
adapter adapter link layer protocol
4
Hop-to-hop delivery
5
6
Service provided by the data link layer for network layer:
Link-Layer Services
• Unacknowledged connectionless service • Acknowledged connectionless service • Acknowledged connection-oriented service
7
Link-Layer Duties
� Framing
� Encapsulating packet into frame, adding header, trailer
� Using MAC addresses, rather than IP addresses
� Error detection and/or correction
� Errors caused by signal attenuation, noise.
� Receiver detecting presence of errors
� Receiver correcting errors without retransmission
� Flow control
� Pacing between adjacent sending and receiving nodes
� Media access control (MAC)
� Pacing between adjacent sending and receiving nodes
8
Framing
9
Framing
Break sequence of bits into a frame
� Typically implemented by the network adaptor
10110101000011001….1000100110101010101
How to define the borders?
Byte Counting (character count)
� Sender: insert length of the data in bytes at the beginning of each frame
� Receiver: extract the length and read that many bytes
Data
132
132
what if the count field gets corrupted?
10
Byte Oriented: Byte stuffing
� Add START and END sentinels to the data
� Problem: what if END appear in the data?
� Add a special DLE (Data Link Escape) character before END
� What if DLE appears in the data? Add DLE before it.
� Used by Point-to-Point protocol, e.g. modem,
DSL, cellular
Data START END END DLE DLE DLE
11
Bit Oriented: Bit Stuffing
� Add sentinels to the start and end of data � Both sentinels are the same
� Example: 01111110 in High-level Data Link Protocol (HDLC)
� Sender: insert a 0 after each 11111 in data � Known as “bit stuffing”
� Receiver: after seeing 11111 in the data… � 111110 � remove the 0 (it was stuffed)
� 111111 � look at one more bit � 1111110 � end of frame � 1111111 � error! Discard the frame
� Disadvantage: 20% overhead at worst
Data 01111110 01111110
12
13
Bit Stuffing- example
14
• The combinations of low-low and high-high which are not
used for data may be used for marking frame boundaries.
• Only applicable if physical layer coding has some
redundancy
Physical Layer Coding Violations
e.g., in Manchester coding
15
Error Control
Transmission Errors
� Transmission errors are caused by: � Thermal noise {Shannon}
� impulse noise (e..g, arcing relays)
� signal distortion during transmission (attenuation)
� crosstalk
� voice amplitude signal compression (companding)
� quantization noise (PCM)
� jitter (variations in signal timings)
� receiver and transmitter out of synch. 16
Packet corruption
� single bit; only 1 bit in the data unit has changed
� burst error; 2 or more bits in the data unit have changed
Example:
0.01 s of burst impulse noise 1200 bps data rate 12 bits of errors
less likely
Types of errors:
17
18
Error Detection
� Error detection
� Transmit extra (redundant) information
� Use redundant information to detect errors
� Extreme case: send two copies of the data
� Trade-off: accuracy vs. overhead
� Techniques for detecting errors
� Parity checking
� Checksum
� Cyclic Redundancy Check (CRC)
Error detection
� Redundancy: adding extra bits for detecting
errors at the destination
19
Error detection techniques
20
Parity bits
� Detects 1-bit errors and some 2-bit errors
� Not reliable against bursty errors
� Idea: add extra bits to keep the number of 1s even
� Example: 7-bit ASCII characters + 1 parity bit
0101001 1 0 1 1 1 1011110 0110100 1101001 0001110
21
Two Dimensional Parity
� Can detect all 1-, 2-, and 3-bit errors, some 4-bit errors
� 14% overhead
0101001 1101001 1011110 0001110 0110100 1011111
1 0 1 1 1 0
1111011 0
Parity bit for
each row
Parity bit for
each column Parity bit for
the parity byte
22
Two Dimensional Parity Examples
0101001 1101001 1011110 0001110 0110100 1011111
1 0 1 1 1 0
1111011 0
Odd number of 1s
Odd Number of
1s
1
23
0101001 1101001 1011110 0001110 0110100 1011111
1 0 1 1 1 0
1111011 0
Odd Number of 1s
1 1
Odd number of
1s
Two Dimensional Parity Examples
0101001 1101001 1011110 0001110 0110100 1011111
1 0 1 1 1 0
1111011 0
1 1
Odd number of
1s
1
24
Odd number of 1s 0101001
1101001 1011110 0001110 0110100 1011111
1 0 1 1 1 0
1111011 0
1 1
1 0
Cannot be detected
Error detection techniques
25
Checksums
� Idea:
� Add up the bytes in the data
� Include the sum in the frame
� Use ones-complement arithmetic
� Lower overhead than parity: 16 bits per frame
� But, not resilient to errors
� Why?
� Used in UDP, TCP, and IP
Data START END Checksum
0101001 1101001= 10010010 +
0 1
26
Checksum
1. The data unit is divided into k sections, each of n bits
2. All sections are added using 1’s complement
3. The sum is complemented
4. The checksum is sent with data
Example:
IP header
27
1’s complement
� Suppose the following block of 16 bits is to be sent using a checksum of 8 bits.
10101001 00111001
� The numbers are added using one’s complement
10101001
00111001 ------------
Sum 11100010
Checksum 00011101
The pattern sent is 10101001 00111001 00011101
28
Checksum (cnt’d)
� Performance
� Can we use this technique to detect an error if 2 corresponding opposite bits in 2 data segments become corrupted?
� An example:
Transmitted sequence: 10101001 00111001
00011101 Received sequence: 00101001 10111001
00011101 29
Error detection techniques
30
Cyclic Redundancy Check (CRC)
� Uses field theory to compute a semi-unique value
for a given message
� Much better performance than previous
approaches
� Fixed size overhead per frame (usually 32-bits)
� Quick to implement in hardware
� Only 1 in 232 chance of missing an error with 32-bit CRC
� Details are in the book/on Wikipedia
31
Cyclic Redundancy Check (CRC)
• Represent a (n+1)-bit message as an n-degree polynomial M(x)
–E.g., 10101101 � M(x) = x7 + x5 + x3 + x2 + x0
• Choose a divisor k-degree polynomial G(x)
• Compute reminder R(x) of M(x)*xk / G(x), i.e., compute A(x) such that
M(x)*xk = A(x)*G(x) + R(x), where degree(R(x)) < k
• Let
T(x) = M(x)*xk – R(x) = A(x)*G(x)
• Then
–T(x) is divisible by G(x)
32
CRC check
� Based on binary division
� CRC added to the data unit so that the resulting data becomes exactly divisible by a predetermined number
� CRC
� exactly 1 less bit than the divisor
1. A string of n zeros added to the data unit
2. New data divided by divisor
3. Replace 0’s by CRC
33
� Modulo-2 division
CRC generator
34
CRC generator (cnt’d)
Name Polynomial Application
CRC-8 x8 + x2 + x + 1 ATM header
CRC-10 x10 + x9 + x5 + x4 + x 2 + 1 ATM AAL
ITU-16 x16 + x12 + x5 + 1 HDLC
ITU-32 x
32 + x26 + x23 + x22 + x16 + x12 + x11 + x10
+ x8 + x7 + x5 + x4 + x2 + x + 1 LANs
35
� CRC can detect
1. all burst errors that affect odd number of bits
2. all burst errors of length ≤≤≤≤ degree of polynomial
3. with high probability burst errors > degree of polynomial
Example:
CRC-12 (degree of 12)
1. OK
2. OK
3. 99.97 %
CRC performance
36
Error correction
1. By retransmission
� flow and error control protocols
2. Forward Error Correction (FEC)
� require more redundancy bits
� should locate the invalid bit or bits
� n-bit code word contains m data bits + r redundancy bits
n=m+r
� m+r+1 bits discoverable by r bits
Example:
� For m=5 data bits can r be 3?
12 ++≥ rmr
37
m r
Code-word
• The Hamming distance is the number of bits that have to
be changed to get from one bit pattern to another.
Example: 10010101 & 10010011 have a hamming
distance of 2
• For any coding whose members have a Hamming
distance of two, any one bit error can be detected.
Why?
Hamming distance
38
x = codewordso = non-codewords
x
x x
x
x
x
x
o
o o
o o
o o
o
o o
o
o x
x x
x
x x
x
o o o
o o
o o o o
o
o
o
A code with poor distance properties
A code with good distance properties
(a) (b)
Hamming distance
39
� To detect d single bit errors, you need a d+1 code distance.
� To correct d single bit errors, you need a 2d+1 code distance.
� In general, the price for redundant bits is too
expensive to do error correction for network
messages.
� Network protocols use error detection and
ARQ.
Error detection/correction
40
Hamming code
Example: 7-bit ASCII code + 4 bit redundancy
� Each r bit is the parity bit for one combination of data bits
r1: bits: 1, 3, 5, 7, 9, 11
r2: bits: 2, 3, 6, 7, 10, 11
r3: bits 4, 5, 6, 7
r4: bits 8, 9, 10, 11
20 1 1 1 1 1 1
21 2 2 2 2 2 2
22 4 4 4 4
23 8 8 8 8
Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ
1 2 3 4 5 6 7 8 9 10 11
41
Hamming code (cnt’d)
Example of redundancy bit calculation (even parity)
42
Hamming code (cnt’d)
Error detection using Hamming code
once the bit is identified the receiver can reverse its value
43
44
Flow Control
Flow Control
Transmission Link
Buffer
The process of managing the rate of data transmission between two nodes to prevent a fast sender from overwhelming a slow receiver
45
Categories of Flow Control
46
Stop-and-Wait Automatic Repeat reQuest
� Simplest flow and error control mechanism
� The sending device keeps a copy of the last frame
transmitted until it receives an acknowledgement
� identification of duplicate transmission (lost or
delayed ACK)
� A damaged or lost frame is treated in the same way
� Timers introduced
� Positive ACK sent only for frames received safe & sound
47
A Simplex Stop-and-Wait ARQ
1. Normal operation
2. The frame is lost
3. The ACK is lost
4. The ACK is delayed
48
Stop-and-Wait ARQ(Normal operation)
� The sender will not send the next piece of data until it is sure that the current one is correctly received
� sequence number necessary to check for duplicated packets
� No NACK – when packet is corrupted – duplicate ACKs instead
49
Stop-and-Wait ARQ(Lost or damaged frame)
roundtrip time + processing in the receiver
Should be as short as possible. Why?
50
Stop-and-Wait ARQ (Lost ACK)
Importance of frame
numbering
51
Numbering frames prevents the retaining of duplicate frames
Stop-and-Wait ARQ (Delayed ACK)
Importance of ACK
numbering
52
Numbered acknowledgments are needed if an acknowledgment is delayed and the next frame is lost.
Duplex Stop-and-Wait ARQ
� Piggybacking
� combine data with ACK (less overhead saves bandwidth)
53
Utilization = dtrans /( dtrans + 2 dprop), error free case
or
Utilization = (1-PE)dtrans /( dtrans + 2 dprop, ) error case
Performance of Stop-and-wait ARQ
dtrans= (Frame size)/Bandwidth
dptop= (Speed of signal)/ (Channel length)
RT
T
54
Stop-and-wait operation
first bit transmitted, t = 0
sender receiver
RTT
last bit transmitted, t = L / R
first bit arrives
last bit arrives, send ACK
ACK arrives, send next frame, t = RTT + L / R
U sender
= .008
30.008 = 0.00027
microsec
L / R
RTT + L / R =
Example: 1 Gbps link, 15 ms prop. delay, 8000 bit frame:
dsmicrosecon8bps10
bits80009
===R
Ld
trans
55
very low
Sliding window (Pipelined) protocols
Pipelining: sender allows multiple, “in-flight”, yet-to-be-
acknowledged frames
� range of sequence numbers must be increased
� buffering at sender and/or receiver
� Two generic forms of pipelined protocols:
Go-Back-N , Selective repeat 56
Sliding Window Protocols
� Sequence numbers � sent frames are numbered sequentially
� number of frames stored in the header � if the number of bits in the header is m than
sequence number goes from 0 to 2m-1
� Sliding window � to hold the unacknowledged
outstanding frames
sequence number
frame
acknowledged frames
57
Question
� What is the consequence of the window size
in the receiver on the order of the received
packets?
Answer:
� Window size 1 means that the packets are
received in order
� This is not the case for the larger window size 58
59
Sliding Window: Retransmission Strategies
How to deal with errors?
• Sender only retransmits frames for which a NAK
is received (the lost or corrupted frames)
(Selective repeat)
• If the ACK is not received then the sender must go back and retransmit earlier frames (from the lost
frame) (Go-Back-N)
Go-back-N (Control variables)
� S- holds the sequence number of the recently sent frame
� SF – holds sequence number of the first frame in the window
� SL – holds the sequence number of the last frame
� R – sequence number of the frame expected to be received
60
The name of Go-back-N: why?
� Re-sending frame
� when the frame is damaged the sender goes back and
sends a set of frames starting from the last one ACKn’d
� the number of retransmitted frames is N
Example: The window size is 4.
A sender has sent frame 6 and the timer expires for frame 3
(frame 3 not ACKn’d). The sender goes back and re-sends
the frames 3, 4, 5 and 6.
61
Go-back-N (normal operation)
� How many frames can be transmitted without acknowledgment?
� ACK1 – not necessary if ACK2 is sent
expected sequence number
62
Go-back-N (damaged or lost frame)
damaged frames are discarded!
Why are correctly received packets not buffered?
What is the disadvantage of this?
63
Go-back-N (sender window size)
sequence number
64
Go-back-N (drawback)
� Inefficient
� all out of order received packets are discarded
� This is a problem in a noisy link
� many frames must be retransmitted -> bandwidth consuming
� Solution
� re-send only the damaged frames
� Selective Repeat ARQ
� avoid unnecessary retransmissions 65
Selective Repeat ARQ
� Processing at the receiver more complex
� The window size is reduced to 2m-1 (at most)
� Both the transmitter and the receiver have the
same window size
� Receiver expects frames within the range of
the sequence numbers
66
Selective Repeat ARQ (lost frame)
67
68
Selective Repeat
Selective Repeat ARQ (sender window size)
69
Frame transmission time is normalized to a value of 1; thus, the propagation time is a.
Sliding window- analysis
70
71
The throughput on the line depends on both the window size W and the value of a
Sliding window- analysis
72
Error free channel
Selective repeat
with error
Go-back-N
with error
Sliding window- utilization
Assum
e a
fra
me is in
Assum
e a
fra
me is in
err
or
with p
robabili
ty P
a =dprop/dtrans
73
How many sequence numbers required?
Receiver window size
Transmitter window size
2 1 1 Stop-and-wait ARQ
1+W 1 W Go-back-N
2W W W Selective repeat
In SR protocol with the window size of 5, how many bits
required to numbering the sequence of frames?
2*5=10 sequence numbers, we need 4 bits
Sequence number and window size
Stop-and-wait utilization (example)
74
A channel has a bit rate of 4 kbps and a propagation delay of 20 ms. For what range of frame sizes does Stop-and-Wait give an efficiency (link utilization) > 50%?
Efficiency will be 50% when the time to transmit the frame
equals the roundtrip propagation delay. At a transmission rate
of 4 bits/ms, 160 bits takes 40 ms. For frame sizes above 160
bits, stop‐and‐wait is reasonably efficient.
75
Seven‐‐‐‐bit sequence numbers are needed
To operate efficiently, the sequence space (actually, the send window size) must be large enough to allow the transmitter to keep transmitting until the first acknowledgement has been received. The propagation time is 18 ms. At T1 speed, which is 1.536 Mbps (excluding the 1 header bit), a 64‐byte frame takes 0.300 msec. Therefore, the first frame fully arrives 18.3 msec after its transmission was started. The acknowledgement takes another 18 msec to get back, plus a small (negligible) time for the acknowledgement to arrive fully. In all, this time is 36.3 msec. The transmitter must have enough window space to keep going for 36.3 msec. A frame takes 0.3 ms, so it takes 121 frames to fill the pipe.
Sliding window utilization (example)
A 3000‐‐‐‐km‐‐‐‐long T1 trunk is used to transmit 64‐‐‐‐byte frames using selective-repeat protocol. If the propagation speed is 6 µsec/km, how many bits should the sequence numbers be?
76
Questions Questions
Top Related