You are on page 1of 79

The Data Link Layer

r Framing
r Error Control
m Error Correction
m Error Detection

r Flow Control
r Retransmission with Sliding Window
Protocols
r Protocol Specification and Verification
r Example Data Link Protocols

Computer Networks Fall 2002 Page 1


Computer Networks Fall 2002 Page 2
DATA LINK LAYER Services
r Unacknowledged connectionless service
m Voice

r Acknowledged connectionless service


m wireless

r Acknowledged connection-oriented service


m no out-of-order

Computer Networks Fall 2002 Page 3


Data Link Protocol

Computer Networks Fall 2002 Page 4


Framing
r To break the bit stream up into discrete
frames and compute the checksum for each
frame. When a frame arrives at the
destination, the checksum is recomputed
and validated.
r One way to achieve this framing is to insert
time gaps between frames. However,
networks rarely make any guarantees about
timing.

Computer Networks Fall 2002 Page 5


Data Framing
r Character count
r Starting and ending characters with
character stuffing
r Starting and ending flags with bit stuffing
r Physical layer coding violations

Computer Networks Fall 2002 Page 6


Character Count
character count

5 1 2 3 4 5 6 7 8 9 8 0 1 2 3 4 5 6 8 7 8 9 0 1 2 3
frame 1 frame 2 frame 3 frame 4
5 characters 5 characters 8 characters 8 characters

one-bit error
5 1 2 3 4 7 6 7 8 9 8 0 1 2 3 4 5 6 8 7 8 9 0 1 2 3

frame 1 frame 2 Now a character count


5 characters (wrong)
Even if the checksum is incorrect so the destination knows that the frame is
bad, it still has no way of telling where the next frame starts.
Computer Networks Fall 2002 Page 7
Starting and Ending Characters
with Character Stuffing
DLE(0x10): Data Link Escape
DLE STX user data DLE ETX STX(0x02): Start of TeXt
ETX(0x03): End of TeXt
beginning end of
of frame frame

user data 0x10


DLE STX A DLE B DLE ETX
DLE stuffed at the sender
DLE STX A DLE DLE B DLE ETX
DLE destuffed at the receiver
DLE STX A DLE B DLE ETX

Computer Networks Fall 2002 Page 8


Starting and Ending Flags with
Bit Stuffing
flag
01111110 user data 01111110
beginning end of
of frame frame

011011111111111111110010 original data


bits stuffed at the sender
011011111011111011111010010
bits destuffed at the receiver
011011111111111111110010

Computer Networks Fall 2002 Page 9


Physical Layer Coding Violations

1000110

Starting Ending
Delimiter Delimiter
VV1VV000 user VV0VV000
data
beginning of frame end of frame

V: Violation bit

Computer Networks Fall 2002 Page 10


Error Control
r Three types of frames at a receiver’s end
m Damaged frame : Negative acknowledgment /
retransmission
m Lost frame : Time-out mechanism
m Valid frame : Sequence numbering / discarding
for valid but duplicate frames

Computer Networks Fall 2002 Page 11


Flow Control
r A technique for assuring that a transmitting
station does not overwhelm a receiving
station with data

Computer Networks Fall 2002 Page 12


Error Detection and Correction
r Error-correcting codes
r Error-detecting codes

Computer Networks Fall 2002 Page 13


Codeword
r n-bit codewords with n =m+r and
m m data bits
m r redundant or check bits

r Not all the 2n codewords are legal. In


general, only 2m codewords are legal.
r ASCII codes of 7 bits with 1 even parity bit
m ASCII code for “A”: 1000001
m codeword for “A”: 10000010 or 01000001
m Codeword 10000011 or 11000001 is illegal.

Computer Networks Fall 2002 Page 14


Hamming Distance
r The number of bit positions in which two
codewords differ is called the Hamming
distance between these two codewords.
r The Hamming distance of the complete code
is the minimum Hamming distance between
all pairs of legal codewords.

Computer Networks Fall 2002 Page 15


Codeword Space
r To detect d-bit errors, a distance d +1 code is
needed.
r To correct d-bit errors, a distance 2d +1 code is
needed.

1-bit error detection 1-bit error correction


Computer Networks Fall 2002 Page 16
Codeword Space : 3-bits

Computer Networks Fall 2002 Page 17


Error Correction with
Codewords: An Example

Computer Networks Fall 2002 Page 18


Determine the Number of
Check bits
r To correct single bit errors with m bits
message and r check bits (n=m+r)
m Code space : 2m n-bit legal messages(codewords)
m For an n-bit legal codeword, all its n neighbors at
a distance 1 from it are illegal
m n+1 bit patterns are dedicated to each legal
message
m (n+1)2m <= 2n and consequently (m+r+1)2m <= 2m+r.
we have : (m+r+1) <= 2r

Computer Networks Fall 2002 Page 19


Hamming Code
r The bits that are powers of 2 (1, 2, 4, 8, 16,
etc.) are check or parity bits of some data
bits.
r For example, m=7 (ASCII) and r=4 (7+4+1 <=
2 4) 1 001 000 “H”
xx1x001x000
m B1 : B3 B5 B7 B9 B11 0 1 0 1 0 0
m B2 : B3 B6 B7 B10 B11 01 01 00
m B4 : B 5 B 6 B 7 1001
m B8 : B9 B10 B11 0000
00110010000 codeword
Computer Networks Fall 2002 Page 20
Hamming Code : Example

Computer Networks Fall 2002 Page 21


To Correct Burst Errors
r A sequence of k consecutive codewords are
arranged as a matrix, one codeword per row.
To correct burst errors, the data should be
transmitted one column at a time, i.e.,
column by column.
r If a burst error of length k bits occurs, at
most 1 bit in each of the k consecutive
codewords will have been affected, but the
Hamming code can correct one error per
codeword, so the entire block can be
restored.

Computer Networks Fall 2002 Page 22


To Correct Burst Errors

Computer Networks Fall 2002 Page 23


When a Burst Error Occurs

Computer Networks Fall 2002 Page 24


To Correct Burst Errors: An
Example
B1 : B3 B5 B7 B9 B11
ASCII Codeword
1001000 00110010000 B2 : B3 B6 B7 B10 B11
1100001 10111001001 B4 : B 5 B6 B7
1101101 11101010101 B8 : B9 B10 B11
1 2 3 4 5 6 7 8 9 10 11 column
011 001 111 110 011 000 101 010 001 000 011
burst error
011 001 111 111 101 000 101 010 001 000 011
Codeword Codeword
00111010000 B1(011100)+B4(1101) => B5 00110010000
10110001001 B1(110001)+B4(1000) => B5 10111001001
11111010101 B4(1101) => B4 11101010101
Computer Networks Fall 2002 Page 25
Error Detection
r Parity bit
m low error rate

r Longitudinal redundancy check (LRC) and


Vertical redundancy check (VRC)
r Cyclic redundancy code (CRC code) /
Polynomial code
m Easy hardware implementation
m Can detect burst errors

Computer Networks Fall 2002 Page 26


Parity Bit
r block size: 1000 bits
m Hamming code: 1000+10 bits (m+r+1 <= 2n)
m parity bit: 1000+1 bits

r a message: 106 bits


m without no error
• Hamming code: 106+10000 bits
• parity bit: 106+1000 bits
m with a low error rate 10-6
• Hamming code: 106+10000 bits
• parity bit: 106+1000+(1000+1) bits ( one error occurs)

retransmitted block
Computer Networks Fall 2002 Page 27
Longitudinal Redundancy Check
and Vertical Redundancy Check

VRC
10110111
11010111
00111010
11110000
10001011
01011111
01111110 LRC

Computer Networks Fall 2002 Page 28


Cyclic Redundancy Code (CRC) /
Polynomial Code
r A m-bit frame is regarded as the
coefficient list for a polynomial, M(x), with
m terms, ranging from xm-1 to x0. For
example, 110001 represents a polynomial
x5+x4+x0.
r Addition and subtraction are identical to
EXCLUSIVE OR. For example,
10011011 11110000
+ 11001010 -10100110
= 01010001 =01010110

Computer Networks Fall 2002 Page 29


Computing Cyclic Redundancy
Code
r Both the sender and the receiver must
agree upon a generator polynomial, G(x),
with the degree r in advance.
r Append r zero bits into M(x) => xrM(x)
r Divide xrM(x) by G(x)
r Subtract the remainder from xrM(x) and let
the result be T(x)

Computer Networks Fall 2002 Page 30


CRC Example

Computer Networks Fall 2002 Page 31


CRC at Receiver End
r T(x) is received with no error.
m T(x) is divisible by G(x)

r When errors represented by error bit


pattern E, ( ie. E(x)), occur,
m (T(x) +E(x)) /G(x) has zero reminder only if E(x)
is divisible by G(x)
m Carefully selects G(x) such that E(x) is not
divisible by G(x)

Computer Networks Fall 2002 Page 32


CRC with Single and Double
Errors
r Single-bit error
m E(x)= xj
m If G(x) contains tow or more terms, it will never
divided E(x)
r Two isolate single-bits errors
m E(x)= xi +xj = xj ( xi-j+ 1) ….. i>j
m Assume G(x) is not divisible by x
• Select G(x) that does not divide xk+1,
where 1< k ≤ i-j

Computer Networks Fall 2002 Page 33


CRC with Odd-Number-bit
Errors

Computer Networks Fall 2002 Page 34


CRC with Burst Errors

Computer Networks Fall 2002 Page 35


Well-Known Generator
Polynomials
r CRC-12: x12+x11+x3+x2+x+1
r CRC-16: x16+x15+x2+1
r CRC-CCITT: x16+x12+x5+1
r CRC-32: x32+x26+x23+x22+x16+x12+x11+x10+ x8+
x7+x5+x4+x2+x+1
r CRC-16 and CRC-CCITT
m Catch all single and double errors, all errors with
an odd number of bits, all burst errors of length
16 or less, 99.997% of 17-bit error burst,
99.998% of 18-bit error and longer bursts

Computer Networks Fall 2002 Page 36


Flow Control Techniques
r Stop-and-wait
m The receiver provide feedback to the sender
m The sender sends one frame and then waits for
an acknowledgement before proceeding

Computer Networks Fall 2002 Page 37


Dealing with the Damaged
Frames
r Adding a timer ( on sender )
m The receiver would only send an ack if the data
were correctly received
m After time out, the sender send the frame again

Computer Networks Fall 2002 Page 38


Dealing with the Lost Frames
r A lost data frame can be resent by using a
timer
r When an acknowledgement is lost
m The sender’s timer eventually time-out
m The sender resends the same data frame
m After the data frame is received, the receiver
sends acknowledgement again

Computer Networks Fall 2002 Page 39


Duplicate Frames : Two Cases

Computer Networks Fall 2002 Page 40


Dealing with Duplicate Frames

Computer Networks Fall 2002 Page 41


When Sender’s Time-out is Too
Short

Computer Networks Fall 2002 Page 42


Solution: Put Sequence Number
in the Acknowledgement

Computer Networks Fall 2002 Page 43


Piggybacking

Computer Networks Fall 2002 Page 44


Acknowledgement
r Techniques
m Control Frame
m Data Frame: Piggybacking
• The technique of temporarily delaying outgoing
acknowledgements so that they can be hooked onto the
next outgoing data frame is known as piggybacking.
r Types
m Positive Acknowledgement: The received frame
has no error.
m Negative Acknowledgement: The received frame
has errors.

Computer Networks Fall 2002 Page 45


Flow Control
r Flow control is a technique for assuring that
a transmitting station does not overwhelm a
receiving station with data.
r Sliding Window Protocols: At any instant of
time, the sender maintains a set of sequence
numbers corresponding to frames it is
permitted to send. These frames are said to
fall within the sending window. Similarly, the
receiver also maintain a receiving window
corresponding to the set of frames it is
permitted to accept.

Computer Networks Fall 2002 Page 46


Sliding Windows
r Each outbound frame contain a sequence
number ranging from 0 to 2n-1
r Sending window
m Maintained by the sender
m A set of sequence numbers corresponding to
frames the sender is permitted to send
r Receiving window
m Maintained by the receiver
m Corresponds the set of frames the receiver is
permitted to accept

Computer Networks Fall 2002 Page 47


Maintain Sliding Windows
r Sending window
m When a frame is sent, the upper edge of the
window is advanced by one
m When an acknowledgement is received, the lower
edge of the window is advanced by one
r Receiving window
m Any received frame the sequence number
outside the window is discarded
m When a frame whose sequence number is equal
to lower edge of the window is received, the
window is rotated by one
Computer Networks Fall 2002 Page 48
A Sliding Window Size of One

Computer Networks Fall 2002 Page 49


Sliding Window Protocols
r One bit sliding window protocol (
Stop-and-Wait)
r Go-back-N Protocol
r Selective Repeat Protocol

Computer Networks Fall 2002 Page 50


One Bit Sliding Window
Protocol
r Stop –and-Wait
m A protocol in which the sender sends one frame
and then waits for an acknowledgement before
proceeding.
r a sliding window protocol with maximum
window size = 1
m Sequence number {0, 1} is sufficient
r Frame header fields
m Seq : the sequence number of this frame
m Ack : the number of the last frame is received

Computer Networks Fall 2002 Page 51


Efficiency of Stop-and-Wait
Stop-and-Wait 50 kbps data rate
500 msec round-trip delay
1000 bits per frame
time (msec)
t=0 start sending
t=20 completely sent
t=250 frame arrival
t=270 completely received
t=270 acknowledge without delay
t=520 acknowledgement arrival

26000 bits could be transmitted in 520 msec.


Efficiency: 1000/26000=20/520 < 4% used
Computer Networks Fall 2002 Page 52
Efficiency of Stop-and-Wait

Computer Networks Fall 2002 Page 53


Pipelining
50 kbps data rate
500 msec round-trip delay
1000 bits per frame
time (msec)
t=0 start sending the first frame
t=20 the first completely sent
t=250 frame arrival
t=270 the first completely received
t=270 acknowledge without delay
t=520 acknowledgement arrival

To pipeline frames without waiting for acknowledgements.

Computer Networks Fall 2002 Page 54


Pipelining

Computer Networks Fall 2002 Page 55


Line of Utilization for
Stop-and-Wait
r Capacity : b bits/sec, frame size : l bits,
round-trip delay : R seconds
m Transmission time : l/b
m Total duration : R + l/b
m Utilization : (l/b) / (R + l/b) = l / (l+bR)

Computer Networks Fall 2002 Page 56


Go-back-N
r Sender’s window size is n (n >1)
m At most n outstanding frames can be sent

r After receiving a damaged frame


m Receiver discards all subsequent frames
m Sender retransmits the damaged frame and all
its successors after the times out

Computer Networks Fall 2002 Page 57


Go-back-N : An Example

Computer Networks Fall 2002 Page 58


Selective Repeat
r Receiver’s window size is n ( n >1 )
m At most n frames can be buffered

r Receiver stores all the correct frames


following the bad one
r The sender retransmits only the bad frame
not all its successors

Computer Networks Fall 2002 Page 59


Selective Repeat : An Example

Computer Networks Fall 2002 Page 60


Retransmission with Sliding
Window Protocols
r ARQ (Automatic Repeat reQuest): When an
error is detected, the receiver requests
that the frame be retransmitted.
m Stop-and-wait ARQ
m Go-back-N continuous ARQ
m Selective-repeat continuous ARQ
r All of them belong to the sliding window
protocols.
r Both Go-back-N and Selective-repeat ARQs
uses the pipelining technique.
Computer Networks Fall 2002 Page 61
ARQ
r Instead of using positive or negative
acknowledgement, the receiver sends back
only the frame number of the next frame is
expects
r On the receipt of each frame (including
damaged)
m It may speed up the transmission of lost or
damaged frames, if the time-out value is “loose”

Computer Networks Fall 2002 Page 62


Stop-and-Wait with ARQ

Computer Networks Fall 2002 Page 63


Window Size
r The optimal sender’s windows size is
1+(round-trip delay / transmission time)
r Maximum window size of Go-back-N ARQ is
MaxSeq, where the sequence number are 0,
1, ... , MaxSeq.
r Maximum window size of Selective-repeat
ARQ is (MaxSeq+1)/2.

Computer Networks Fall 2002 Page 64


Protocol Specification and
Verification
r Finite State Machine Model
r Petri Net Model

Computer Networks Fall 2002 Page 65


Finite State Machine Model
r States
m Instants that the protocol machine is waiting for
the next event to happen
r Transitions
m Occur when some event occurs
m Change form some state to another

Computer Networks Fall 2002 Page 66


Finite State Machine Model for
Bit Destuffing
Bit destuffing input/output
0/11110
0/110
1/ 1/ 1/ 1/ 1/ 1/ 0/
end of
S 1 2 3 4 5 6 E frame
0/0 0/10 1/
0/1110
bit destuffed T beginn
error ing
0/11111
of the
next
frame
Computer Networks Fall 2002 Page 67
State Digram for
Stop-and-Wait

Computer Networks Fall 2002 Page 68


Example Data Link Protocols
r HDLC
m bit oriented
m bit stuffing

r SLIP
r PPP
m character oriented
m character stuffing
m multiprotocol framing

Computer Networks Fall 2002 Page 69


High-level Data Link Control
r derived from SDLC (Synchronous Data Link
Control) of IBM’s SNA
r ADCCP (Advanced Data Communication
Control Procedure): ANSI
r HDLC: ISO
r LAP (Link Access Procedure): X.25 of
CCITT
r LAPB: CCITT
r http://members.tripod.com/~vkalra/hdlc.ht
ml
Computer Networks Fall 2002 Page 70
HDLC Frame Format

bits 8 8 8 >=0 16 8
01111110 Address Control Data Checksum 01111110

r A frame is delimited with the flag sequence


01111110. On idle point-to-point lines, flag
sequences are transmitted continuously.
r Address
m to identify one of multiple terminals for
point-to-multipoint lines
m to distinguish commands from responses for point-to-point
lines

Computer Networks Fall 2002 Page 71


HDLC Frame Addressing

DTE DCE PDN

address=0xC0, command
Address A
address=0xC0, response

address=0x80, command
Address B
address=0x80, response

Computer Networks Fall 2002 Page 72


HDLC Frame Type

Control Field

* not defined in LAPB


Computer Networks Fall 2002 Page 73
HDLC P/F Bit
r In Command frames: P (POLL) bit
r In Response frames: F (FINAL) bit
r Each Command frame with the POLL bit set
to 1 must receive a Response frame with the
FINAL bit set to 1.

Computer Networks Fall 2002 Page 74


HDLC Supervisory Frame
r RR (Receive Ready): acknowledgement frame
mN(R): the next frame expected to be received
r REJ (Reject): negative acknowledgement frame
m N(R): the first frame in sequence not received
correctly (Go-back-N protocol)
r RNR (Receive not Ready): same as Type 0 and
telling the sender to stop sending
r SR (Selective Reject): acknowledgement frame
m N(R): the frame expected to be retransmitted
(Selective Repeat protocol)

Computer Networks Fall 2002 Page 75


HDLC Unnumbered Frame

Link Initiation Link Termination

SABM DISC
accept
UA UA

SABM
reject UA Unnumbered/Acknowledgement
SABM Set Asynchronous Balanced Mode
DM DISC Disconnect
DM Disconnected Mode
Computer Networks Fall 2002 Page 76
Serial Line IP
r SLIP (Serial Line IP): to connect SUN
workstations to the Internet over a dial-up
line using a modem in 1984
r RFC 1055
r Sending IP packets over the line, with a
special flag byte at the end for framing.
Using character stuffing.
r Many problems: no error detection,
supporting only IP, no authentication, etc.

Computer Networks Fall 2002 Page 77


Point-to-Point Protocol
r PPP: RFC 1661, RFC 1662, RFC 1663
r A multiprotocol framing mechanism suitable
for use over modems, HDLC lines, SONET ,
and other physical layers.
r Supports error detection, option
negotiation, header compression, and
optionally, reliable transmission using HDLC
framing.
r Character-oriented

Computer Networks Fall 2002 Page 78


Homework
r #2, #3, #6, #9,#11

Computer Networks Fall 2002 Page 79

You might also like