Download as pdf or txt
Download as pdf or txt
You are on page 1of 114

Chapter 5

Peer-to-Peer Protocols
and Data Link Layer
PART I: Peer-to-Peer Protocols
Peer-to-Peer Protocols
ARQ Protocols and Reliable Data Transfer
Flow Control
PART II: Data Link Controls
Framing
Point-to-Point Protocol
High-Level Data Link Control
Chapter 5
Peer-to-Peer Protocols
and Data Link Layer
PART I: Peer-to-Peer Protocols
Peer-to-Peer Protocols
ARQ Protocols and Reliable Data Transfer
Flow Control
Peer-to-Peer protocols

Application Application
Communicating End Systems

End-to-End Protocols
Application Application
Layer Layer
Transport Transport
Layer Layer
Network Network Network Network
Layer Layer Layer Layer
Data Link Data Link Data Link Data Link
Layer Layer Layer Layer
Physical Physical Physical Physical
Layer Layer Layer Layer

One or More Network Nodes


Reliability & Sequencing
l Reliability: Are messages or information
stream delivered error-free and without loss
or duplication?
l Sequencing: Are messages or information
stream delivered in order?
l ARQ protocols combine error detection,
retransmission, and sequence numbering to
provide reliability & sequencing
l Examples: TCP and HDLC
End-to-End vs. Hop-by-Hop
l A service feature can be provided by implementing a
protocol
l end-to-end across the network
l across every hop in the network
l Example:
l Perform error control at every hop in the network or only
between the source and destination?
l Perform flow control between every hop in the network or
only between source & destination?
l We next consider the tradeoffs between the two
approaches
Error control in Data Link Layer
Packets Packets
(a) l Data Link operates
Data link Data link
over wire-like,
layer Frames layer directly-connected
A B systems
Physical Physical
layer layer
l Frames can be
corrupted or lost, but
arrive in order
(b)
1 1 l Data link performs
2 2
3 3 error-checking &
12 21 12 21
Medium retransmission
2 l Ensures error-free
A B 1
packet transfer
1 Physical layer entity between two systems
2 Data link layer entity

3 Network layer entity


Error Control in Transport Layer
l Transport layer protocol (e.g. TCP) sends segments across
network and performs end-to-end error checking &
retransmission
l Underlying network is assumed to be unreliable

Messages Messages

Transport Segments Transport


layer layer
Network Network Network Network
layer layer layer layer
Data link Data link Data link Data link
layer layer layer layer
End system End system
A Physical Physical Physical Physical
B
layer layer layer layer

Network
l Segments can experience long delays, can be lost, or
arrive out-of-order because packets can follow different
paths across network
l End-to-end error control protocol more difficult

C
1 2 3 2 1
2 2
1 1

End System
α 1 End System
1 2 1
2 2 β
4 3 21 12 3 2 1 1 2 3 2 1 1 2 3 4
Medium
2
A B 1
Network

3 Network layer entity

4 Transport layer entity


Comparisons
Hop-by-hop

Data Data Data Data


1 2 3 4 5 Faster recovery
ACK/ ACK/ ACK/ ACK/
NAK NAK NAK NAK

Simple
End-to-end
ACK/NAK
inside the
network

More scalable,
1 2 3 4 5 complexity at
Data Data Data Data the edge
Chapter 5
Peer-to-Peer Protocols
and Data Link Layer
PART I: Peer-to-Peer Protocols
Peer-to-Peer Protocols
ARQ Protocols and Reliable Data Transfer
Flow Control
Error Control
l Digital transmission systems introduce errors
l Applications require certain reliability level
l Data applications require error-free transfer
l Voice & video applications tolerate some errors
l Error control used when transmission system does not meet
application requirement
l Error control ensures a data stream is transmitted to a certain
level of accuracy despite errors
l Two basic approaches:
l Error detection & retransmission (ARQ)
l Forward error correction (FEC) (not covered in this
course)
Error Detection

(This topic is covered in Chapter 3 of the


book)
Key Idea of Error Detection
l All transmitted data blocks (“codewords”) satisfy a
pattern
l If received block doesn’t satisfy pattern, it is in error
l Redundancy: Only a subset of all possible blocks
can be codewords, eg, data block length=2 bits, 1
bit redundancy:

x
coding x x = codewords
x x
0 o = noncodewords
0 0
0

2-bit data blocks


2-bit data, 1 bit redundancy
l Blindspot: when channel transforms a
codeword into another codeword
All inputs to channel Channel
satisfy pattern or condition output
Deliver user
User Pattern
Encoder Channel information or
information checking
set error alarm
Single Parity Check
l Append an overall parity check to k information bits

Info Bits: b1, b2, b3, …, bk

Check Bit: bk+1= b1+ b2+ b3+ …+ bk modulo 2


Codeword: (b1, b2, b3, …, bk,, bk+1)
l All codewords have even # of 1s
l Receiver checks to see if # of 1s is even
l All error patterns that change an odd # of bits are
detectable
l All even-numbered patterns are undetectable
l Parity bit used in ASCII code
Example of Single Parity Code
l Information (7 bits): (0, 1, 0, 1, 1, 0, 0)
l Parity Bit: b8 = 0 + 1 +0 + 1 +1 + 0 = 1
l Codeword (8 bits): (0, 1, 0, 1, 1, 0, 0, 1)

l If single error in bit 3 : (0, 1, 1, 1, 1, 0, 0, 1)


l # of 1’s =5, odd
l Error detected

l If errors in bits 3 and 5: (0, 1, 1, 1, 0, 0, 0, 1)


l # of 1’s =4, even
l Error not detected
Checkbits & Error Detection

Received information bits


Information bits

Recalculate
check bits
k bits
Channel
Calculate
check bits Compare
Sent Received
Information
check check bits
accepted if
bits check bits
match
n – k bits
How good is the single parity
check code?
l Redundancy: Single parity check code adds 1
redundant bit per k information bits:
overhead = 1/(k + 1)
l Coverage: all error patterns with odd # of errors can
be detected
l An error pattern is a binary (k + 1)-tuple with 1s where
errors occur and 0’s elsewhere
l Of 2k+1 binary (k + 1)-tuples, ½ are odd, so 50% of error
patterns can be detected
l Is it possible to detect more errors if we add more
check bits?
l Yes, with the right codes
What if bit errors are random?
l Many transmission channels introduce bit errors at random,
independently of each other, and with probability p
l Some error patterns are more probable than others:

p
P[10000000] = p(1 – p)7 = (1 – p)8 and
1–p
P[11000000] = p (1 – p) = (1 – p)
2 6 8 p 2

1–p

l In any worthwhile channel p < 0.5, and so (p/(1 – p)) < 1


l It follows that patterns with 1 error are more likely than patterns
with 2 errors and so forth
l What is the probability that an undetectable error pattern
occurs?
Single parity check code with
random bit errors
l Undetectable error pattern if even # of bit errors:
P[error detection failure] = P[undetectable error pattern]
= P[error patterns with even number of 1s]
n 2 n
= p (1 – p)n-2 + p4(1 – p)n-4 + …
2 4

l Example: Evaluate above for n = 32, p = 10-3


32
P[undetectable error] = (10-3)2 (1 – 10-3)30 + 32 (10-3)4 (1 – 10-3)28
2 4
≈ 496 (10-6) + 35960 (10-12) ≈ 4.96 (10-4)

l For this example, roughly 1 in 2000 error patterns is


undetectable
What is a good code?
l Many channels have o o
o o
preference for error patterns x x Poor
that have fewer # of errors x x x o o distance
o
x x properties
l These error patterns map o o
transmitted codeword to o o o
nearby n-tuple
l If codewords close to each x = codewords
other then detection failures o = noncodewords
will occur
l Good codes should o x
maximize separation o x o Good
o o
between codewords x o x o x distance
properties
o o
o o
x o x
Two-Dimensional Parity Check
l More parity bits to improve coverage
l Arrange information as columns
l Add single parity bit to each column
l Add a final “parity” column
l Used in early error control systems

1 0 0 1 0 0
0 1 0 0 0 1
Last column consists
1 0 0 1 0 0 of check bits for each
1 1 0 1 1 0 row
1 0 0 1 1 1

Bottom row consists of


check bit for each column
Error-detecting capability
1 0 0 1 0 0 1 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 1
One error Two errors
1 0 0 1 0 0 1 0 0 1 0 0
1 1 0 1 1 0 1 0 0 1 1 0
1, 2, or 3 errors
1 0 0 1 1 1 1 0 0 1 1 1
can always be
detected; Not all
patterns >4 errors
1 0 0 1 0 0 1 0 0 1 0 0
can be detected
0 0 0 1 0 1 0 0 0 1 0 1
1 0 0 1 0 0 Three 1 0 0 1 0 0
errors Four errors
1 0 0 1 1 0 1 0 0 0 1 0 (undetectable)

1 0 0 1 1 1 1 0 0 1 1 1

Arrows indicate failed check bits


Other Error Detection Codes
l Many applications require very low error rate
l Need codes that detect the vast majority of errors
l Single parity check codes do not detect enough
errors
l Two-dimensional codes require too many check bits
l The following error detecting codes used in practice:
l Internet Check Sums

l CRC Polynomial Codes


Internet Checksum
0 4 8 16 19 24 31

Version IHL Type of Service Total Length

Identification Flags Fragment Offset

Time to Live Protocol Header Checksum

Source IP Address

Destination IP Address

Options Padding

how to calculate this?


Internet Checksum

l Several Internet protocols (e.g. IP, TCP, UDP) use


check bits to detect errors in the IP header (or in the
header and data for TCP/UDP)
l A checksum is calculated for header contents and
included in a special field.
l Checksum recalculated at every router, so algorithm
selected for ease of implementation in software
l Let header consist of L, 16-bit words,
b0, b1, b2, ..., bL-1
l The algorithm appends a 16-bit checksum bL
Checksum Calculation

The checksum bL is calculated as follows:


l Treating each 16-bit word as an integer, find

x = b0 + b1 + b2+ ...+ bL-1 modulo 216-1


l The checksum is then given by:

bL = - x modulo 216-1
Thus, the headers must satisfy the following pattern:
0 = b0 + b1 + b2+ ...+ bL-1 + bL modulo 216-1
l The checksum calculation is carried out in software
using one’s complement arithmetic
Internet Checksum Example
For simplicity, assuming 4-bit words
Use Binary Arithmetic
Use Modulo Arithmetic l Note 16 =1 mod15

l Use mod 24-1 arithmetic l So: 10000 = 0001 mod15

l b0=1100 = 12 l leading bit wraps around

l b1=1010 = 10 b0 + b1 = 1100+1010
l b0+b1=12+10=7 mod15 =10110
l b2 = -7 = 8 mod15 =10000+0110
=0001+0110
l Therefore
=0111
l b2=1000 =7
Take 1s complement
b2 = -0111 =1000
Polynomial Codes
l Polynomials instead of vectors for codewords
l Polynomial arithmetic instead of check sums
l Implemented using shift-register circuits
l Also called cyclic redundancy check (CRC)
codes
l Most data communications standards use
polynomial codes for error detection
l Polynomial codes also basis for powerful
error-correction methods
Binary Polynomial Arithmetic
l Binary vectors map to polynomials
(ik-1 , ik-2 ,…, i2 , i1 , i0) à ik-1xk-1 + ik-2xk-2 + … + i2x2 + i1x + i0

Addition:
(x7 + x6 + 1) + (x6 + x5) = x7 + x6 + x6 + x5 + 1
= x7 +(1+1)x6 + x5 + 1
= x7 +x5 + 1 since 1+1=0 mod2

Multiplication:
(x + 1) (x2 + x + 1) = x(x2 + x + 1) + 1(x2 + x + 1)
= (x3 + x2 + x) + (x2 + x + 1)
= x3 + 1
Binary Polynomial Division
l Division with Decimal Numbers
34 quotient dividend = quotient x divisor +remainder
35 ) 1222 dividend
105 1222 = 34 x 35 + 32
divisor 17 2
140
32 remainder

x3 + x2 + x = q(x) quotient
l Polynomial
Division x3 + x + 1 ) x6 + x5
x6 + x4 + x3 dividend
divisor
x5 + x4 + x3
x5 + x3 + x2
Note: Degree of r(x) is less than x4 + x2
degree of divisor
x4 + x2 + x
x = r(x) remainder
Polynomial Coding
l Code has binary generating polynomial of degree n–k
g(x) = xn-k + gn-k-1xn-k-1 + … + g2x2 + g1x + 1
l k information bits define polynomial of degree k – 1
i(x) = ik-1xk-1 + ik-2xk-2 + … + i2x2 + i1x + i0
l Find remainder polynomial of at most degree n – k – 1
q(x)
g(x) ) xn-k i(x) xn-ki(x) = q(x)g(x) + r(x)
r(x)
l Define the codeword polynomial of degree n – 1

b(x) = xn-ki(x) + r(x)


n bits k bits n-k bits
Polynomial example:
3
k = 4, n–k = 3
Generator polynomial: g(x)= x + x + 1
Information: (1,1,0,0) i(x) = x3 + x2
Encoding: x3i(x) = x6 + x5

x3 + x2 + x
1110
x3 + x + 1 ) x6 + x5 1011 ) 1100000
x6 + x 4 + x3 1011
x5 + x4 + x3 1110
x5 + x 3 + x2 1011
x4 + x2 1010
x4 + x2 + x 1011
x 010
Transmitted codeword:
b(x) = x6 + x5 + x
b = (1,1,0,0,0,1,0)
The Pattern in Polynomial Coding

l All codewords satisfy the following pattern:

b(x) = xn-ki(x) + r(x) = q(x)g(x) + r(x) + r(x) = q(x)g(x)

l All codewords are a multiple of g(x)!


l Receiver should divide received n-tuple by g(x) and
check if remainder is zero
l If remainder is nonzero, then received n-tuple is not a
codeword
Shift-Register Implementation
1. Accept information bits ik-1,ik-2,…,i2,i1,i0
2. Append n – k zeros to information bits
3. Feed sequence to shift-register circuit that
performs polynomial division
4. After n shifts, the shift register contains the
remainder
Division Circuit
Encoder for g(x) = x3 + x + 1
g0 = 1 g1 = 1 g3 = 1
0,0,0,i0,i1,i2,i3
+ Reg 0 + Reg 1 Reg 2

Clock Input Reg 0 Reg 1 Reg 2


0 - 0 0 0
1 1 = i3 1 0 0
2 1 = i2 1 1 0
3 0 = i1 0 1 1
4 0 = i0 1 1 1
5 0 1 0 1
6 0 1 0 0
7 0 0 1 0
Check bits: r0 = 0 r1 = 1 r2 = 0
r(x) = x
Undetectable error patterns
(Transmitter) (Receiver)
b(x) + R(x)=b(x)+e(x)

(Channel) e(x) Error polynomial

l e(x) has 1s in error locations & 0s elsewhere


l Receiver divides the received polynomial R(x) by g(x)
l Blindspot: If e(x) is a multiple of g(x), that is, e(x) is a nonzero
codeword, then
R(x) = b(x) + e(x) = q(x)g(x) + q’(x)g(x)
l The set of undetectable error polynomials is the set of
nonzero code polynomials
l Choose the generator polynomial so that selected error
patterns can be detected.
Designing good polynomial codes
l Select generator polynomial so that likely error
patterns are not multiples of g(x)
l Detecting Single Errors
l e(x) = xi for error in location i + 1
l If g(x) has more than 1 term, it cannot divide xi
l Detecting Double Errors
l e(x) = xi + xj = xi(xj-i+1) where j>i
l If g(x) has more than 1 term, it cannot divide xi
l If g(x) is a primitive polynomial, it cannot divide xm+1 for all
m<2n-k-1 (Need to keep codeword length less than 2n-k-1)
l Primitive polynomials can be found by consulting coding
theory books
Designing good polynomial codes
l Detecting Odd Numbers of Errors
l For odd number of errors, e(x) evaluated at x = 1
is 1, therefore (x+1) is not a factor of e(x)
l Suppose all codeword polynomials have an even
# of 1s, b(x) evaluated at x = 1 is zero because
b(x) has an even number of 1s
l This implies x + 1 must be a factor of all b(x)
l Pick g(x) = (x + 1) p(x) where p(x) is primitive
StandardCRCGenerator Polynomials
= cyclic redundancy check

l CRC-8: ATM
= x8 + x2 + x + 1

l CRC-16: Bisync
= x16 + x15 + x2 + 1
= (x + 1)(x15 + x + 1)

l CCITT-16: HDLC, XMODEM, V.41

= x16 + x12 + x5 + 1
l CCITT-32:
IEEE 802, DoD, V.42

= x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1


Error Control
l Two basic approaches:
l Error detection & retransmission (ARQ)

l Forward error correction (FEC)


Automatic Repeat Request (ARQ)
l Purpose: to ensure a sequence of information
packets is delivered in order and without errors or
duplications despite transmission errors & losses
l We will look at:
l Stop-and-Wait ARQ
l Go-Back N ARQ
l Selective Repeat ARQ
l Basic elements of ARQ:
l Error-detecting code with high error coverage
l ACKs (positive acknowledgments)
l NAKs (negative acknowlegments)
l Timeout mechanism
Stop-and-Wait ARQ
Transmit a frame, wait for ACK
Error-free
Packet
packet
Information frame
Transmitter Receiver
Timer set after (Process A) (Process B)
each frame
transmission Control frame

Header

CRC
Information Header
packet CRC
Information frame Control frame: ACKs
Need for Sequence Numbers
(a) Frame 1 lost Time-out
Time
A Frame Frame Frame Frame
0 1 1 2
ACK ACK
B

(b) ACK lost Time-out


Time
A Frame Frame Frame Frame
0 1 1 2
ACK ACK ACK
B

l In cases (a) & (b) the transmitting station A acts the same way
l But in case (b) the receiving station B accepts frame 1 twice
l Question: How is the receiver to know the second frame is also frame 1?
l Answer: Add frame sequence number in header
l Slast is sequence number of most recent transmitted frame
Sequence Numbers
(c) Premature Time-out

Time-out
Time
A Frame
0 Frame Frame Frame
ACK 0 1 2
ACK
B

l The transmitting station A misinterprets duplicate ACKs


l Incorrectly assumes second ACK acknowledges Frame 1
l Question: How is the transmitter to know second ACK is for frame 0?
l Answer: Add frame sequence number in ACK header
l Rnext is sequence number of next frame expected by the receiver
l Implicitly acknowledges receipt of all prior frames
1-Bit Sequence Numbering
Suffices
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

Slast Rnext
Timer

Transmitter Slast Receiver


A B
Rnext

Global State: Error-free frame 0


(Slast, Rnext) (0,0) (0,1)
arrives at receiver
ACK for
ACK for frame 0
frame 1 arrives at
arrives at transmitter
transmitter Error-free frame 1
arrives at receiver
(1,0) (1,1)
Stop-and-Wait ARQ
Transmitter Receiver
Ready state Always in Ready State
l Await request from higher layer for l Wait for arrival of new frame
packet transfer l When frame arrives, check for errors
l When request arrives, transmit l If no errors detected and sequence
frame with updated Slast and CRC number is correct (Slast=Rnext), then
l Go to Wait State l accept frame,
Wait state l update Rnext,
l Wait for ACK or timer to expire; l send ACK frame with Rnext,
block requests from higher layer l deliver packet to higher layer
l If timeout expires l If no errors detected and wrong
l retransmit frame and reset timer sequence number
l If ACK received: l discard frame
l send ACK frame with Rnext
l If sequence number is incorrect or if
errors detected: ignore ACK l If errors detected
l If sequence number is correct (Rnext l discard frame
= Slast +1): accept frame, go to
Ready state
Applications of Stop-and-Wait
ARQ
l IBM Binary Synchronous Communications
protocol (Bisync): character-oriented data
link control
l Xmodem: modem file transfer protocol
l Trivial File Transfer Protocol (RFC 1350):
simple protocol for file transfer over UDP
Stop-and-Wait Efficiency
Last frame bit ACK
First frame bit enters channel arrives
enters channel Channel idle while transmitter
waits for ACK
t
A

B t

First frame bit Receiver


arrives at Last frame bit processes frame
receiver arrives at and
receiver prepares ACK
l 10000 bit frame @ 1 Mbps takes 10 ms to transmit
l If wait for ACK = 1 ms, then efficiency = 10/11= 91%
l If wait for ACK = 20 ms, then efficiency =10/30 = 33%
Stop-and-Wait Model
t0 = total time to transmit 1 frame
A
tproc

B
frame
tprop tproc tack tprop
tf time

t0 2t prop 2t proc tf t ack bits/info frame

nf na bits/ACK frame
2t prop 2t proc
R R

channel transmission rate


S&W Efficiency on Error-free
channel
bits for header & CRC
Effective transmission rate:
0 number of information bits delivered to destination nf no
Reff ,
total time required to deliver the information bits t0

Transmission efficiency:
Effect of
n f no no
1 frame overhead
Reff t0 nf
0 .
R R na 2(t prop t proc ) R
1
nf nf

Effect of
Effect of Delay-Bandwidth Product
ACK frame
Example: Impact of Delay-
Bandwidth Product
nf=1250 bytes = 10000 bits, na=no=25 bytes = 200 bits
2xDelayxBW 1 ms 10 ms 100 ms 1 sec
Efficiency
200 km 2000 km 20000 km 200000 km
1 Mbps 103 104 105 106
88% 49% 9% 1%
1 Gbps 106 107 108 109
1% 0.1% 0.01% 0.001%

Stop-and-Wait does not work well for very high speeds


or long propagation delays
S&W Efficiency in Channel with
Errors
l Let 1 – Pf = probability frame arrives w/o errors
l Avg. # of transmissions to first correct arrival is then 1/ (1–Pf )
l “If 1-in-10 get through without error, then avg. 10 tries to success”
l Avg. Total Time per frame is then t0/(1 – Pf) (a proper derivation is
given in next two slides)

n f no
t0 no
1
Reff 1 Pf nf
SW (1 Pf )
R R na 2(t prop t proc ) R
1
nf nf
Effect of
frame loss
Just-in-time mathematics
l Let X be a random variable assuming the values of
x1, x2,… with corresponding probabilities p1, p2,....
The mean or expected value of X is defined by:

E( X ) pi xi
i

l eg: x1=1, x2=2, x3 =3, each with probability of 1/3


E(X ) = 1/3 + 2/3 + 3/3 = (1+2+3)/3 =2, which is the
simple average formula when X takes each value
with equal probability
Stop & Wait Performance
1 successful transmission i – 1 unsuccessful transmissions

E[ttotal ] t0 (i 1)tout P[nt i]


i 1

i 1
t0 (i 1)tout Pf (1 Pf )
i 1

tout Pf 1
t0 t0 .
1 Pf 1 Pf
Efficiency:
nf no no
1
E[ttotal ] nf
SW (1 Pf ) (1 Pf ) 0 .
R na 2(t prop t proc ) R
1
nf nf
Example: Impact Bit Error Rate
nf=1250 bytes = 10000 bits, na=no=25 bytes = 200 bits
Find efficiency for random bit errors with p=0, 10-6, 10-5, 10-4
nf nf p
1 Pf (1 p ) e for large n f and small p

1 – Pf 0 10-6 10-5 10-4


Efficiency
1 Mbps 1 0.99 0.905 0.368
& 1 ms 88% 86.6% 79.2% 32.2%

Bit errors impact performance as nfp approach 1


Go-Back-N
l Improve Stop-and-Wait by not waiting!
l Keep channel busy by continuing to send frames
l Allow a window of up to Ws outstanding frames
l Use m-bit sequence numbering
l Primitive version
l If ACK for oldest frame arrives before window is
exhausted, we can continue transmitting
l If window is exhausted, pull back and retransmit all
outstanding frames
l Alternative: Use timeout
Go-Back-N ARQ (primitive version)
Go-Back-4: 4 frames are outstanding; so go back 4

fr fr fr fr fr fr fr fr fr fr fr fr fr fr Time
0 1 2 3 4 5 6 3 4 5 6 7 8 9
A

B
A A A out of sequence A A A A A A
C C C frames C C C C C C
K K K K K K K K K
1 2 3 4 5 6 7 8 9

Rnext 0 1 2 3 3 4 5 6 7 8 9

l Frame transmission are pipelined to keep the channel busy


l Frame with errors and subsequent out-of-sequence frames are ignored
l Transmitter is forced to go back when window of 4 is exhausted
Window size long enough to cover round trip time
Time-out expires
Stop-and-Wait ARQ
fr fr fr Time
0 0 1
A

B
Receiver is A
looking for C
K
Rnext=0
1

Go-Back-N ARQ Four frames are outstanding; so go back 4


fr fr fr fr fr fr fr fr fr fr fr Time
0 1 2 3 0 1 2 3 4 5 6
A

B
A A A A A A
Receiver is Out-of- C C
C C C C
looking for sequence K K K K K K
Rnext=0 frames 1 2 3 4 5 6
Go-Back-N (with timeout)
l Problem with the primitive Go-Back-N as
presented:
l If frame is lost and source does not have frame to
send, then window will not be exhausted and
recovery will not commence
l Use a timeout with each frame
l When timeout expires, resend all outstanding
frames
Go-Back-N Transmitter & Receiver
Transmitter Receiver

Send Window
... Receive Window

Frames
transmitted S
last Srecent Slast+Ws-1
and ACKed
Frames
Buffers Rnext
received
oldest un-
Timer Slast ACKed frame
Timer
Slast+1 Receiver will only accept
... a frame that is error-free and
that has sequence number Rnext
Timer
Srecent most recent
transmission
When such frame arrives Rnext is
... incremented by one, so the
Slast+Ws-1 max Seq # receive window slides forward by
allowed one
Sliding Window Operation
Transmitter

Send Window m-bit Sequence Numbering


...

Frames
transmitted S 0
and ACKed
last Srecent Slast+Ws-1 2m – 1 1

2
Transmitter waits for error-free
ACK frame with sequence
number Slast Slast
send
When such ACK frame arrives,
window i
Slast is incremented by one, and
the send window slides forward i + Ws – 1 i+1
by one
Maximum Allowable Window Size is Ws = 2m-1
M = 22 = 4, Go-Back - 4: Transmitter goes back 4

fr fr fr fr fr fr fr fr Time
A 0 1 2 3 0 1 2 3

A A A A
B C C C C Receiver has Rnext= 0, but it does not
K K K K know whether its ACK for frame 0 was
1 2 3 0
received, so it does not know whether
Rnext 0 1 2 3 0 this is the old frame 0 or a new frame 0

M = 22 = 4, Go-Back-3: Transmitter goes back 3


fr fr fr fr fr fr
Time
A 0 1 2 0 1 2

A A A
B C C C
K K K Receiver has Rnext= 3 , so it
1 2 3
rejects the old frame 0
Rnext 0 1 2 3
Another View

Slast
SEND WINDOW

SEND WINDOW
SEND
SEND WINDOW
WINDOW
ACK Piggybacking in Bidirectional GBN
SArecent RA next
Transmitter Receiver
Receiver Transmitter
SBrecent RB next

“A” Receive Window “B” Receive Window

RA next RB next
“A” Send Window “B” Send Window
... ...

SA last SA last+WA s-1 SB last SB last+WB s-1


Buffers Buffers
Timer SA last Timer SB last
SA last+1 SBlast+1
Timer Note: Out-of- Timer
... ...
Timer
sequence error-free
SArecent Timer SBrecent
... frames discarded ...
after Rnext examined
Timer SA last+W s-1
A
Timer SB last+WB s-1
Applications of Go-Back-N ARQ
l HDLC (High-Level Data Link Control): bit-
oriented data link control
l V.42 modem: error control over telephone
modem links
Required Timeout & Window Size
Tout
Tproc

Tprop Tf Tf Tprop

l Timeout value should allow for:


l Two propagation times + 1 processing time: 2 Tprop + Tproc
l A frame that begins transmission right before our frame arrives
Tf
l Next frame carries the ACK, Tf
l Ws should be large enough to keep channel busy for Tout
Required Window Size for
Delay-Bandwidth Product

Frame = 1250 bytes =10,000 bits, R = 1 Mbps

2(tprop + tproc) 2 x Delay x BW Window

1 ms 1000 bits 1

10 ms 10,000 bits 2

100 ms 100,000 bits 11

1 second 1,000,000 bits 101


Efficiency of Go-Back-N
l GBN is completely efficient, if Ws large enough to keep
channel busy, and if channel is error-free
l Assume Pf frame loss probability, then time to deliver a frame
is:
l tf if first frame transmission succeeds (1 – Pf )
l tf + Wstf /(1-Pf) if the first transmission does not succeed Pf

Ws t f Ws t f
tGBN t f (1 Pf ) Pf {t f } tf Pf and
1 Pf 1 Pf
nf no no
1
tGBN nf
GBN (1 Pf )
R 1 (Ws 1) Pf

Delay-bandwidth product determines Ws


Go-Back-N Performance
1 successful transmission i – 1 unsuccessful transmissions

E[ttotal ] t f (i 1)Ws t f P[nt i]


i 1

i 1
tf Ws t f (i 1) Pf (1 Pf )
i 1

Ws t f Pf 1 (Ws 1) Pf
tf tf .
1 Pf 1 Pf

Efficiency:
nf no no
1
E[ttotal ] nf
GBN (1 Pf ) .
R 1 (Ws 1) Pf
Example: Impact Bit Error Rate on
GBN
nf=1250 bytes = 10000 bits, na=no=25 bytes = 200 bits
Compare S&W with GBN efficiency for random bit errors with
p = 0, 10-6, 10-5, 10-4 and R = 1 Mbps & 100 ms
1 Mbps x 100 ms = 100000 bits = 10 frames → Use Ws = 11
Efficiency 0 10-6 10-5 10-4

S&W 8.9% 8.8% 8.0% 3.3%

GBN 98% 88.2% 45.4% 4.9%

l Go-Back-N significant improvement over Stop-and-Wait for


large delay-bandwidth product
l Go-Back-N becomes inefficient as error rate increases
Selective Repeat ARQ
l Go-Back-N ARQ inefficient because multiple frames
are resent when errors or losses occur
l Selective Repeat retransmits only an individual frame
l Timeout causes individual corresponding frame to be resent
l NAK causes retransmission of oldest un-acked frame
l Receiver maintains a receive window of sequence
numbers that can be accepted
l Error-free, but out-of-sequence frames with sequence
numbers within the receive window are buffered
l Arrival of frame with Rnext causes window to slide forward by
1 or more
Selective Repeat ARQ

fr fr fr fr fr fr fr fr fr fr fr fr fr fr Time
0 1 2 3 4 5 6 2 7 8 9 10 11 12
A

B
A A N A A A A A A A A A
C C A C C C C C C C C C
K K K K K K K K K K K K
1 2 2 2 2 2 7 8 9 1 1 1
0 1 2
Selective Repeat ARQ
Transmitter Receiver

Send Window Receive Window


...

Frames Frames
transmitted S received Rnext Rnext + Wr-1
last Srecent Slast+ Ws-1
and ACKed

Buffers Buffers
Timer Slast Rnext+ 1
Timer Slast+ 1 Rnext+ 2
...
Timer
Srecent ...
Rnext+ Wr- 1 max Seq #
... accepted
Slast+ Ws - 1
Send & Receive Windows
Transmitter Receiver

0 0
2m-1 1 2m-1 1

2 2
Rnext
Slast
send receive j
window i window
i
i + Ws – 1 i+1
j + Wr – 1
Moves k forward when ACK Moves forward by 1 or more
arrives with Rnext = Slast + k when frame arrives with
k = 1, …, Ws-1 Seq. # = Rnext
What size Ws and Wr allowed?
l Example: M=22=4, Ws=3, Wr=3
Frame 0 resent
Send
{0,1,2} {1,2} {2} {.}
Window
fr0 fr1 fr2 fr0
A Time

B ACK1 ACK2 ACK3


Receive
{0,1,2} {1,2,3} {2,3,0} {3,0,1}
Window
Old frame 0 accepted as a
new frame because it falls
in the receive window
Ws + Wr = 2m is maximum allowed
l Example: M=22=4, Ws=2, Wr=2
Frame 0 resent
Send
{0,1} {1} {.}
Window
fr0 fr1 fr0
A Time

B ACK1 ACK2
Receive
{0,1} {1,2} {2,3}
Window
Old frame 0 rejected because it
falls outside the receive window
Why Ws + Wr = 2m works
l Transmitter sends frames 0 to l Receiver window starts at {0, …, Wr-1}
Ws-1; send window empty
l Window slides forward to
l All arrive at receiver {Ws,…,Ws+Wr-1}
l All ACKs lost
l Receiver rejects frame 0 because it
l Transmitter resends frame 0 is outside receive window

0 0
2m-1 1 2m-1 1

Slast Ws +Wr-1 2
2

receive Rnext Ws
send window
window Ws-1
Applications of Selective Repeat
ARQ
l TCP (Transmission Control Protocol):
transport layer protocol uses variation of
selective repeat to provide reliable stream
service
l Service Specific Connection Oriented
Protocol: error control for signaling
messages in ATM networks
Efficiency of Selective Repeat
l Assume Pf frame loss probability, then number of
transmissions required to deliver a frame is:
l tf / (1-Pf)

nf no
t f /(1 Pf ) no
SR (1 )(1 Pf )
R nf
Example: Impact Bit Error Rate on
Selective Repeat
nf=1250 bytes = 10000 bits, na=no=25 bytes = 200 bits
Compare S&W, GBN & SR efficiency for random bit errors with
p=0, 10-6, 10-5, 10-4 and R= 1 Mbps & 100 ms

Efficiency 0 10-6 10-5 10-4

S&W 8.9% 8.8% 8.0% 3.3%

GBN 98% 88.2% 45.4% 4.9%


SR 98% 97% 89% 36%

l Selective Repeat outperforms GBN and S&W, but


efficiency drops as error rate increases
Comparison of ARQ Efficiencies
Assume na and no are negligible relative to nf, and
L = 2(tprop+tproc)R/nf =(Ws-1), then
Selective-Repeat:
no
SR (1 Pf )(1 ) (1 Pf )
nf
Go-Back-N: For Pf≈0, SR & GBN same
1 Pf 1 Pf
GBN
1 (WS 1) Pf 1 LPf
For Pf→1, GBN & SW same
Stop-and-Wait:
(1 Pf ) 1 Pf
SW
na 2(t prop t proc ) R 1 L
1
nf nf
ARQ Efficiencies
ARQ Efficiency Comparison
Selective
1.5 Repeat
Go Back N 10
Efficiency

0.5 Stop and Wait


10
0 Go Back N 100
10-9 -8-8 10
-9 10 -7-7 10
-6-6 10-5-5 10
-4-4 10
-3-3 10
-2-2 10
-1-1
LOG(p)
p Stop and Wait
100
Delay-Bandwidth product = 10, 100
Chapter 5
Peer-to-Peer Protocols
and Data Link Layer
PART I: Peer-to-Peer Protocols
Peer-to-Peer Protocols
ARQ Protocols and Reliable Data Transfer
Flow Control
Pacing and Flow Control
l Messages can be lost if receiving system
does not have sufficient buffering to store
arriving messages
l If destination layer-(n+1) does not retrieve its
information fast enough, destination layer-n
buffers may overflow
l Pacing & Flow Control provide backpressure
mechanisms that control transfer according to
availability of buffers at the destination
l Examples: TCP and HDLC
Flow Control
buffer fill
Information frame
Transmitter
Receiver

Control frame

l Receiver has limited buffering to store arriving


frames
l Several situations cause buffer overflow
l Mismatch between sending rate & rate at which user can
retrieve data
l Surges in frame arrivals
l Flow control prevents buffer overflow by regulating
rate at which source is allowed to send information
X ON / X OFF
threshold
Information frame
Transmitter
Receiver

Transmit X OFF Transmit


Time
A

on off on off

B Time

2Tprop

Threshold must activate OFF signal while 2 Tprop R bits still


remain in buffer
Window Flow Control
Return of permits
tcycle
A
Time

B
Time
l Sliding Window ARQ method with Ws equal to buffer available
l Transmitter can never send more than Ws frames
l ACKs that slide window forward can be viewed as permits to transmit
more
l Can also pace ACKs as shown above
l Return permits (ACKs) at end of cycle regulates transmission rate
Chapter 5
Peer-to-Peer Protocols
and Data Link Layer
PART II: Data Link Controls
Framing
Point-to-Point Protocol
High-Level Data Link Control
Data Link Protocols
Packets Packets Data Links Services
l Framing
Data link Data link l Error control
layer layer
A Frames l Flow control
Physical Physical B
l Multiplexing
layer layer
l Link Maintenance
l Security: Authentication &
Encryption

Examples
l Directly connected, wire-like
l PPP
l Losses & errors, but no out-of-
l HDLC
sequence frames
l Ethernet LAN
l Applications: Direct Links;
LANs; Connections across l IEEE 802.11 (Wi Fi) LAN
WANs
Framing
transmitted received l Mapping stream of
frames frames physical layer bits into
frames
l Mapping frames into
Framing bit stream
l Frame boundaries can
be determined using:
l Character Counts
0111110101

0110110111

l Control Characters
l Flags
l CRC Checks
Character-Oriented Framing
Data to be sent
A DLE B ETX DLE STX E
After stuffing and framing
DLE STX A DLE DLE B ETX DLE DLE STX E DLE ETX

l Frames consist of integer number of bytes


l Asynchronous transmission systems using ASCII to transmit printable
characters
l Octets with HEX value <20 are nonprintable
l Special 8-bit patterns used as control characters
l STX (start of text) = 0x02; ETX (end of text) = 0x03;
l Byte used to carry non-printable characters in frame
l DLE (data link escape) = 0x10
l DLE STX (DLE ETX) used to indicate beginning (end) of frame
l Insert extra DLE in front of occurrence of DLE in frame – byte stuffing
l All DLEs occur in pairs except at frame boundaries
Framing & Bit Stuffing
HDLC frame

Flag Address Control Information FCS Flag


any number of bits

l Frame delineated by flag character


l HDLC uses bit stuffing to prevent occurrence of flag
01111110 inside the frame
l Transmitter inserts extra 0 after each consecutive
five 1s inside the frame
l Receiver checks for five consecutive 1s
l if next bit = 0, it is removed
l if next two bits are 10, then flag is detected
l If next two bits are 11, then frame has errors
Example: Bit stuffing & de-
stuffing
(a) Data to be sent

0110111111111100
After stuffing and framing

0111111001101111101111100001111110

(b) Data received

01111110000111011111011111011001111110
After destuffing and deframing

*000111011111-11111-110*
Chapter 5
Peer-to-Peer Protocols
and Data Link Layer
PART II: Data Link Controls
Framing
Point-to-Point Protocol
High-Level Data Link Control
PPP: Point-to-Point Protocol
l Data link protocol for point-to-point lines in Internet
l Router-router; dial-up to router
1. Provides Framing and Error Detection
l Character-oriented HDLC-like frame structure
2. Link Control Protocol
l Bringing up, testing, bringing down lines; negotiating
options
l Authentication: key capability in ISP access
3. A family of Network Control Protocols specific to
different network layer protocols
l IP, OSI network layer, IPX (Novell), Appletalk
PPP Applications
PPP used in many point-to-point applications
l Telephone Modem Links 30 kbps
l Packet over SONET 600 Mbps to 10 Gbps
l IP→PPP→SONET

l PPP is also used over shared links such as


Ethernet to provide LCP, NCP, and
authentication features
l PPP over Ethernet (RFC 2516)
l Used over DSL
PPP Frame
Flag Address Control Protocol Flag
Information CRC
01111110 1111111 00000011 01111110

integer # of bytes

All stations are to Unnumbered Specifies what kind of packet is contained in the
accept the frame frame payload, e.g., LCP, NCP, IP, OSI CLNP, IPX

l PPP uses similar frame structure as HDLC, except


l Protocol type field
l Payload contains an integer number of bytes
l PPP uses the same flag, but uses byte stuffing
Byte-Stuffing in PPP
l PPP is character-oriented version of HDLC
l Flag is 0x7E (01111110)
l Control escape 0x7D (01111101)
l Any occurrence of flag or control escape inside of frame is
replaced with 0x7D followed by
original octet XORed with 0x20 (00100000)

Data to be sent
41 7D 42 7E 50 70 46

7E 41 7D 5D 42 7D 5E 50 70 46 7E
After stuffing and framing
PPP Phases
Home PC to Internet Service
1. Carrier Provider
Dead detected
7. Carrier 1. PC calls router via modem
dropped 2. PC and router exchange LCP
packets to negotiate PPP
Failed parameters
Terminate Establish
3. Check on identities
2. Options 4. NCP packets exchanged to
negotiated configure the network layer, e.g.
6. Done TCP/IP ( requires IP address
Failed assignment)
5. Open Authenticate 5. Data transport, e.g. send/receive
IP packets
6. NCP used to tear down the
3. Authentication network layer connection (free up
4. NCP IP address); LCP used to shut
completed down data link layer connection
configuration Network
7. Modem hangs up
PPP Authentication
l Password Authentication Protocol
l Initiator must send ID & password
l Authenticator replies with authentication success/fail
l After several attempts, LCP closes link
l Transmitted unencrypted, susceptible to eavesdropping
l Challenge-Handshake Authentication Protocol
(CHAP)
l Initiator & authenticator share a secret key
l Authenticator sends a challenge (random # & ID)
l Initiator computes cryptographic checksum of random # &
ID using the shared secret key
l Authenticator also calculates cryptocgraphic checksum &
compares to response
l Authenticator can reissue challenge during session
Chapter 5
Peer-to-Peer Protocols
and Data Link Layer
PART II: Data Link Controls
Framing
Point-to-Point Protocol
High-Level Data Link Control
High-Level Data Link Control
(HDLC)
l Bit-oriented data link control
l Derived from IBM Synchronous Data Link
Control (SDLC)
l Related to Link Access Procedure Balanced
(LAPB)
l LAPD in ISDN
l LAPM in cellular telephone signaling
HDLC Data Transfer Modes
l Normal Response Mode
l Used in polling multidrop lines
Commands
Primary
Responses

Secondary Secondary Secondary

l Asynchronous Balanced Mode


l Used in full-duplex point-to-point links
Primary Commands Responses Secondary
Secondary Responses Commands Primary

l Mode is selected during connection establishment


HDLC Frame Format

Flag Address Control Information FCS Flag

l Control field gives HDLC its functionality


l Codes in fields have specific meanings and uses
l Flag: delineate frame boundaries
l Address: identify secondary station (1 or more octets)
l In ABM mode, a station can act as primary or secondary so
address changes accordingly
l Control: purpose & functions of frame (1 or 2 octets)
l Information: contains user data; length not standardized, but
implementations impose maximum
l Frame Check Sequence: 16- or 32-bit CRC
Control Field Format
Information Frame
1 2-4 5 6-8
0 N(S) P/F N(R)

Supervisory Frame

1 0 S S P/F N(R)

Unnumbered Frame

1 1 M M P/F M M M

l S: Supervisory Function Bits l M: Unnumbered Function Bits


l N(R): Receive Sequence Number l P/F: Poll/final bit used in interaction
l N(S): Send Sequence Number between primary and secondary
Information frames
l Each I-frame contains sequence number N(S)
l Positive ACK piggybacked
l N(R)=Sequence number of next frame expected
acknowledges all frames up to and including N(R)-1
l 3 or 7 bit sequence numbering
l Maximum window sizes 7 or 127
l Poll/Final Bit
l NRM: Primary polls station by setting P=1; Secondary
sets F=1 in last I-frame in response
l Primaries and secondaries always interact via paired P/F
bits
Error Detection & Loss Recovery
l Frames lost due to loss-of-synch or receiver buffer
overflow
l Frames may undergo errors in transmission
l CRCs detect errors and such frames are treated as
lost
l Recovery through ACKs, timeouts & retransmission
l Sequence numbering to identify out-of-sequence &
duplicate frames
l HDLC provides for options that implement several
ARQ methods
Supervisory frames
Used for error (ACK, NAK) and flow control (Don’t Send):
l Receive Ready (RR), SS=00
l ACKs frames up to N(R)-1 when piggyback not available
l REJECT (REJ), SS=01
l Negative ACK indicating N(R) is first frame not received
correctly. Transmitter must resend N(R) and later frames
l Receive Not Ready (RNR), SS=10
l ACKs frame N(R)-1 & requests that no more I-frames be sent
l Selective REJECT (SREJ), SS=11
l Negative ACK for N(R) requesting that N(R) be selectively
retransmitted
Unnumbered Frames
l Setting of Modes:
l SABM: Set Asynchronous Balanced Mode
l UA: acknowledges acceptance of mode setting commands
l DISC: terminates logical link connection
l Information Transfer between stations
l UI: Unnumbered information
l Recovery used when normal error/flow control fails
l FRMR: frame with correct FCS but impossible semantics
l RSET: indicates sending station is resetting sequence
numbers
l XID: exchange station id and characteristics
Connection Establishment &
Release
l Unnumbered frames used to establish and release
data link connection
l In HDLC
l Set Asynchronous Balanced Mode (SABM)
l Disconnect (DISC)
l Unnumbered Acknowledgment (UA)

SABM Data UA
UA
transfer DISC
Example: HDLC using NRM
(polling)Address of secondary
Primary A Secondaries B, C
A polls B B, RR, 0, P N(S) N(R)

B, I, 0, 0
N(R) B sends 3 info
X B, I, 1, 0
frames
B, I, 2, 0,F
A rejects fr1 B, SREJ, 1
A polls C C, RR, 0, P
C, RR, 0, F C nothing to
send
A polls B, B, SREJ, 1,P
requests
selective B, I, 1, 0 B resends fr1
retrans. fr1 B, I, 3, 0 Then fr 3 & 4
B, I, 4, 0, F
A send info fr0 B, I, 0, 5
to B, ACKs up to 4
Time
Frame Exchange using
Asynchronous Balanced Mode
Combined Station A Combined Station B
B, I, 0, 0 A, I, 0, 0

B, I, 1, 0 A, I, 1, 1 B ACKs fr0
X
A sends 5
frames B, I, 2, 1 A, I, 2, 1

B, I, 3, 2 B rejects
B, REJ, 1 fr1
B, I, 4, 3
A, I, 3, 1
A goes B, I, 1, 3
back to 1
B, I, 2, 4 B, RR, 2 B ACKs fr1

B, I, 3, 4
B, RR, 3 B ACKs fr2
Flow Control
l Flow control is required to prevent transmitter from
overrunning receiver buffers
l Receiver can control flow by delaying
acknowledgement messages
l Receiver can also use supervisory frames to
explicitly control transmitter
l Receive Not Ready (RNR) & Receive Ready (RR)

I3 I4 I5 RNR5 RR6 I6

You might also like