Chap 3 CN
Chap 3 CN
Sendi'Q machine
\ p- I
Receiving machine
I
I
,- -- -- -- ,- -~ -- -- ,,- -- -~ / Frame
\ Pac ket
E I 1
Pa ya d-
L_ _
I I
T~ ~. Header Payload field Trailer
_ _ _J
Flp re 3-1. Relationship betwe
en packets and frames.
Although this chapter is explic
itly ab ou t the da ta lin k·lay er
pro toc olS, many of the princi antl the data link
flow control. ples we will stu dy he re su ch
are &,,..._ ... · as err or control and
10-U.l
ne tw ~...,~ the I!.~ -.-. !lU m transp ort '
an d oth er ·p rot oc ols as well. · 01an Y
Via u, se 1 UJ.LuOOs arc found In fact, 10 .
only in the up pe r lay ers an d • h data
lin k lay er. However, no ma tte not 10 t e ,
r where they are fou nd the
mucb the same, so it does not rea principles are pre_tl (
lly matter where we s~ dy the
lay er they of~ show up in the m. In th e.d~ta ,1l~~d
pla ce to ex.ammc them in detail ir sim ple st an d pu res t for ms , ma kin g th1 s a g
.
l
~,.., 1
~ .-- l~- 1
~,..; l
~,.., 1
-,..;
~-
4 4 4
4
u 3 3 4
It 3
II
3
Virtual -
data path 2
) 2 2
2
'---· ---------- -
1
1 1
Actual
data path ,I
(b)
(a)
~
oata link Routing
layer process
Data link
Frames Packets protocol
here here
Transmission
line to a router
. Te Provide service · to the network layer, the data link layer must use the serv-
~ce Pf?vided to it by the physical layer. What the physical layer does is accept a
f~
:~teed
aw btt Siream and attempt to deliver it to the destination. This bit stream is not
0 to be error free. The number of bits received may be less tha_n ._ ~qual
vaJu mo~e than the number of bits transmitted , and they may have ditterenc
; ~ It 18 up to the data link layer to detect and, if necessary, c?ITect errors ..
discJi e usual approach is for the data link layer to brea k the btt st ream up mtl)
i~rn:: .frame~ and compute the checksum for each. fra me. _tCl~~c ~~um ,~go_r-
hon tl · 111 be dtscussed lat:er in this c hapte r.) When a trnme arnves c\t th e d~~ttrM
1e check
f•rorn' the . · . . 1 , ttll t, Jtl tert>nt
sum 1s recomputed. It the ne wly-compute<1 l:1,\e1.: "' s t
,1,,
- ,. .
0 ccurr one contained in the frame, the data link laye r knows t_h at ~•11 cnor h.t.-.
biy a1::i : 0 : . lakes steps to deal with it (e .g ., d iscarding th<> bad tram,· auJ P0 " '
8
n 108 back an error report) .
18 8 TH E DA T A LI NK LA
YE R CH AP . 3
Br ea ki ng ·the b1.t stream
. up 1·nto fram.
es is m ore difficult th an
it at fi rst ap pears
0 ne w ay to ach1e h' fram i· ng .
is to msert tim
th e ~paces betw een wove t 1s e ga ps be tw ee n fr am es , m uc h hk. .
rds in ordinary text. H 1 e
gu ar an te es about timing, ow ev er ,. ne tw or ks rare
so it is possible these ga y m ake any
er ga ps might be inserte ps m ig ht be sq ue ez ed ou
d durin t or oth-
Si nc e it is too risky to g transmission.
count on timing to ~a
fr am e, ot he r methods
have been devised. In rk t? e start a~d en d of
this se cu on w e will lo each
m et ho ds : ok at fou r
1. Ch ar ac te r count.
2. Fl ag bytes with byte
stuffing.
3. St ar tin g and ending
flags, with bi t stuffing.
4 . Ph ys ic al la ye r codi
ng violations.
Th ~ first fra m in g m et ho
d uses a field in the he
ch ar ac te rs in th e frame. ad er to sp ec ify th e num
W he n the data lin k laye ber of
.a ct er co un t, it kn ow s ho r at th e de st in at io n se es the
w many characters follo char-
frame is . T is te ch ni qu w and he nc e w he re th e
e is shown in Fi g. 3-4( en d of the
an d 8 charac.~er s, respec a) for four fram~s of siz
tively. es 5, 5, 8,
Character c o u n
t~
On e character
tal \s \ 1 \2\3\4\ s\ s\1\e\ g\e\o\
1 \2\3\4\s\s\e\1\e\9\ o\ 1 ~
F"1'ame '1 Frame 2
I
5 characters 5 characters Frame 3
8 characters Frame 4
8 characters
Error
(b) \ s\1 \2 \3 \4 \1
Frame 1
fu 1 \ I
a \ 0 \ a o \ 1J:_2 \ 3 \ 4\ s \ & \ e \ 1 \ e\ 9 \ o \ 1 \
2 I 3]
Frame 2 •· Now a
(Wrong) character count
Figure J. 4, A ch aracte r
stream. (a) W ith ou t err
ors. (b) W ith on e error.
. Th e tro ub le w ith th is
~lgo rithm is th at the co
s1o n er ro r. Fo r ex ampl un t ca n be ga rb le d by 1 11
e, tf the ch ar ac te r coun a
4(b ) beco m es a 7 , th t of 5 in th e seco nd fr am tr~n~~ ~~
e de st ination w ill ge t e of Ftg. -
un ab le to lo cate the st out of sy nchr on iz at io n
art of th e ne xt fran1e . and will ~,
th e de st inat io n kn ows Even if the ch ecks um
th at the fram e is ba d, it is inco nect so
ne xt frame starts . Se nd still ha s no way of telling
ing a fra me back to the wh ere ~he
do es not he lp either, sin so urce as ki ng fo r a re tra
ce the destinatio n do es nsm is s 100
not kno w ho w m an y ch
arac ters to
-
DATA LINK LAYER DESI ON
sEC. 3.1 Iss ue s
. . 189
1,ip over to get to the stadn of the retra nsm1ss 1on F .
siv . od . I . or this reason, the ch
count meth ts rare ~ use anymo
re. aracter
ond framm g me tho d get s a d
1be sec . roun the probl em of resynchron· .
hav mg eac h fram e sta rt and end wit_h . · 1zat1on
er an error by . b cial bytes. In the
aft ferent ; but m. recespe past,
the starting an d en dmg ytes were dif nt
mo st pro tocoJ
th e sam e byte , ca 11 ed a flag byte b h st years
hav ede us
~s ot !he arting and end ing dehm~
·ter as sho wn in Fig. . 3-5(a) as FLAG . In th' ts way if th .
l. ' . .
rch for the flag byte ~o fin~ rece ive r ever lose s syn -
cbfO Dizatio n, 1t can J~s t sea th
bytes ind ica te the d f e end of the curren t
sec uti ve flag
[ram e. Tw o con en o one frame and start of the
next one.
0EJ0 -0EJEJG
0EJ80-0EJEJEJB 0
0EJEJ0-0EJEJEJ EJ 0 (b)
ples of byte se-
(b) Four exam
bytes.
Figure 3-5. (a) A frame delimited by flag
.
quences before and after byte stuffing. d hen bin ary data, such as obJpen e~t
A . h
r o w . d · It ni·iy eas il) hap
senous problem occ urs with this me tte ' ~
Prog r!un . g-pom . t numbers, are et·ng transm1
b . . r·on will usu al! \- 1nter-
th n - 11 s or tlo atm · h d ta Tht s sJtu a l •
sen der
·,
s d.H.1
uLctt th, 11- urs m t e. a · .. to hav e the
~ Ha g by te's bit pat tern occ
fi
solve this problemtore _1s ' h .. ,u:cidental " tt1g
~re Wtth the framing One way to eaL
(ESC) 1·ust be nd removes the e~~·apt> b) ce
ink J, . . esc ape byt e - . ·.
b' _ayer insert a spe cial
recei~in~ \n iqu e is n dk,l b}le stuff·
~te m the data. The data link ]ayer on the er. T '~ ; ~ c 1n he dis tinguish ed ttom
lay
I ore the data are given to the network c
bg character stuffing. Thus,
?r a framin~ fl ag_. y t: b' ce beforr it.
b) tc ""':Ur'.'~/~.
ne~ the data by the absenc e or presen
0 ce ol an es_c ~P: n :scape
Wh al ha~p~n~ s stuffoJ with "" ct"{;,~, are
J;,ut'
llJiddJ f course, the next qu estion is: t ou pl.,~
at it, o ,·eq.ltence, wherea s a•xa
1'h,, e of the data? The answer is t·th. escape ~ dara. Son e
1
rn . ., ~
us a an . II . 1 the c:
inct· . , ny single escape byte is part o d natura Y u
8 that a single escape occ urre ·
1cate
THE D A T A L IN K
LAYER
190 Ci-IA?
•n Fig. ) In all cases, the by te sequ en ce de li ve re d af . \
shown 1 3-S(b · . .. te r de st f .
rl th e sart,e as t he o ngtna1 byte se qu ence. · u fing
~xacJe byte-stuffing d pi cted in Fi·g. 3- 5 · - r h
sch e: ~ th :t mos t ho is a s ig t s1· m ph·hc · at I\
m e co m pu te rs u_s io
sed in the PPP proto_ e t~ comrnun ic: t~)f
one u . provider. W w ill di sc u ss lhe
their Internet servic e P P P la te r m th is ch ap te
e f ·og this fr am . h d · th · · r. ¼1th
A major di sadvanta
ge o uNs1 t all ch ar in g m et o is at It 1s cl os ely t'
the use of 8-b.it l -harac ters. 0 ac te r co de s us e
16-bit characters, A 8- bi t ch ar acte ieu
s ne tw or k s d ev el
lri
example. UNIC ODE r~. h
~ses h ra ct"r co de op ed , th e di \ad ·, ir
tag:es of embedding le ng th in th e fr am
more and more obvi _t e .c .a a ,;e w te ch ni qu e ha d in g m ec ha ni sm be \a n.
ous. so to be de ve lo pe d
trary sized charac te to allowcainbe
rs. ar 1.
The new tee hm.que allows data fr am es • b.
· to co nt am an ar 1trary
and a11ows character codes with an ar bi.tr ar y number of b.
works like this. Each nu m be r o f bi.ts
frame begins an d en · h · pe r character. It\It
tin fac~ a flag byte). d,s w it a_ sp ec 1a ' l b
Whenever the se nd 1t pa ttern, 0111 l I
secutive 1s in the da er s da ta l_m~ la ye 10
ta, it automatically r en cou~1ter s fi ve con-
This bit stuffing is st uf fs a O bi t m to
analogous to byte st th e ou tg oi ng bit str
into the outgoing char uf fi ng , in w hi ch eam.
acter stream be fo re an es ca pe byte is
When the receiver se a fl ag by te in th e stu ffe d
es five co ns ec ut iv e da ta .
it automatically dest in co m in g l bi ts ,
uffs (i.e., deletes) th fo ll ow ed by a Obit.
transparent to the ne e O bi t. Ju st as by te st uf
twork layer in bo th fi ng is complete\
co m pu te rs , so is
data contain the flag
pa ttern , 01 11 bi t st uf fi ng . If the 1
store.din th 1110, th is fl ag is tr user
e receiver's memor an sm it te d as Ol l
stuffing. y as 01111110. F 111010 but
ig ur e 3- 6 gi ve s an
exampl e of bit
(a) O 1 1 O 1 1 1 1
11 1111111111
oo 1 o
(b) O 1 1 O 1 1 1 1 1
O 111110 1111
1 O 1 OO 1 O
:t · en the sender transmits a frame, it generally also starts a timer. The timer is
to expire after an interval long enough for the frame to reach th e destinati on.
N processed there, and have ·the acknowl edgemen t propagat e back to the sen<ler.
b;~ly, the fr~me will be correctly received and the acknowl edge ment will ge t
H fore the timer runs out, in which case the timer w ill be canceled .
off a~w~ver, if e ither the frame or the ac kno wledgem ent is lost, the ti rner ,, ill g\,
tra~ srn~rting the sender to a po te ntial pro ble n1. T he obvious solution is tr~ Ju , t
t!rn~s t~e~~e. ~~ame again . Ho we ver_, whe~ fra mes may be tn._m smittt"d n\ll ltip k
1
times and , ~ .a· dange r th at the rece ive r w ill acce pt the sa mt· t1ame t,, o 0 1 m1..Ht'
~ening, it fts:i-s it t_o the ne twork laye r ~1ore than once . Tn pre, t· nt th i: fr1.. ,~n h"lp
so that th ge_ne,ally necessary to ass1.g n seque nce numben, 11..) l'll tgorng tra nws .
.
' . u1. s I1 rctra nsnu. ss10ns
e receive r ca n d 1strng . .
trom nn gurnb .
192 TH E DA TA LIN K LA YE R
CH AP . 3
•.
The whoIe issu e o f managing the timers and seq uen ce num bers so as to ensure
· lt'm . .
that each frame 1s u 1 ately passed to the net.wo rk lay er at the destma tton exactly
.
once no more and no less is an imp orta nt par t of the dat a hnk lay er , s duties .
er in' this chapter, we will, look at a ser . . . . Lat-
ies of inc rea sm gly sop his tica ted exa
to see how this management is don e. mp les
Networ k designe rs have develop ed two basic strategies for dealing with er-
rors. One way is to include enough redundant information along with each block
of data sent, to enable the receiver to deduce what the transmitted data must have
been. _ The other way is to include only enough redundancy to allow the receive r
to de<;luce that an error occurre d, but not which error, and have it request a
retransmission. The former strategy uses error-correcting codes and the latter
uses error-detecting codes. The use of error-correcting codes is often referred to
as forward error correction.
Each of these techniq ues occupies a different ecological niche. On channel s
that are highly reliable , such as fiber, it is cheaper to use an error detecting c<Xie
and just retransm it the occasio nal block found to be faulty. Howeve r, on channel s
such as wireless links that make many errors, it is better to add enough redun-
dancy to each block for the receive r to be able to figure out what the original
block was, rather than relying on a retransmission, which itself may be in error.
To underst and how errors can be handled, it is necessary to look closely at
what an error really is. Normally, a frame consists of m data (i.e., message) bits
and r redundant, or check, bits. Let the total length be n (i.e., n = m + r ). An n-
bit unit contain ing data and check bits is often referred to as an n-~it _c odew~r d .
Given any two codewo rds, say, I 000 I 00 I and IO 1 I 0001 , 1t 1s poss1 ble to
detennine how many corresp onding bits differ. In this case, 3 bits differ. To
determine how many bits differ, just exclusive OR the two codewords and count
the number of I bits in the result, for example :
10001001
10110001
001110 00
The n~ber of bit positions in which two codewo~ds di f~·er is called the Ham-
ming distance (Hamming, 1950). Its signific ance 1s that 1f two codewords are a
II
TtfBDATA
LINK LA YER CHAP. 3 sec- 3.2 ERROR DETECTION AND
CORRECTION
t'4 . d single-bit errors to convert one 1n1
. · h thc m data b'its. Each chec k b. f 195
. will requ1re 0 filled up wit
11 · I d' · If b It orces th e ·
panty of some coll .
· dii.tanct' d apart. • of bits, me u· mg ttse ' to e even (or odd J· Ab'1t may b - ect1on
. r·ons all zm possible data messages, are T h'
Hamnung ·
otbCf . · - app1IC8 I · • itY compu tations. of see w tch check bit~ the data bit..ine inc•1uded . . in several par-
tilt ~ data ~ sm1ss1on k b'ts are computed, not all of the 2n possibl rewrite k as a sum o powers of 2. For exampl 11 - 1 pos1t1on k contributes to
1" bu due the way the cheC -~m for computing the check bits, it is pos _e
10
+ 16. A bit is checked by just those check b.t
•
e. - + 2 + 8 and 29 = J + 4 +
1 s occumng · 8
l~~ · _.!, art used- Gi\'efl t!1e a)gOfthn legal codewords, and from this list find 1~• - JI is checked by bi ts I, 2, and 8). m its expansion (e.g.. bit
C\,~WUtu ~ lete list o e . . Th. d' . e
1..l a fO coc,stn1Ct a comp . d' ranee is m1mmum. IS !Stance IS the Harn When a codeword _arrives, the receiver initializes
l'"- ~ whOSC Harnnung is - amines each check bit, k (k = I, 2 4 8 J a c_ounter to zero. It then
_ of the complete code. . ex . • · · · · · • to c;ee 1f tt h th
1w-0
. · d rror-correcting properties of a code depend on its If not the receiver adds k to the counter If the . as e correct parity.
ming di~ ' . . . · counter 1s zero afte 11 th
-dctectJDg an e d errors, you n~d a d'1stance d + 1 code _because bits have been examined (1.e., if they were all corr t) h r a . e check
~~ . To deted
~ ft! distan(lethere . 00 way that d single-bit errors can change a vahd code-
as valid. If the counter is nonzero. it contains the n:~be· t Oef~~word 1s ac_cepted
I 2 · r uie mcorrect b1t F
1
"''lh such I code · id ~word When the receiver sees an invalid codeword ' 1·t example, 1'f c hec k b'its , , .and 8 are m error· the inverted b.1t 1s 11 because· .,t oris
word u,to 3110ther V81 wu<- • · • h
the only one c ec e k d b b
y .its 1, 2, and 8· f igure 3- 7 5hows some· 7-b,t. ASCU
CID !di dial uansmission error has occurred. S1mdarly, to correct d errors, you
I
need a distanee 'liJ + 1 code because that way th~ le~al codewords are so far apart characters e~codde~ asb _11 -bi_t _codewords using a Hamming code. Remember that
the data are ,oun m it pos1t1ons 3, 5, 6, 7, 9, 10. and 11.
!bat .even with d changes, the original codeword 1s stdl closer than any other code-
wad, ;o it CID be uniquely determined Char. ASCII Check 01ts
15 th
~IIIC that we want to desi . . r y. Hamming codes can only correct single errors. However. there a tnck at
~ 1 w,U allow all single erro : 8 code with m message bits and r check bits can be used to permit Hamm ino codes to correct burst errors. A sequence of k
n Illegal codewords at a did~-~ COfflleted. Each of the 2m legal messages has consecutive codewords are arra~ oed as a macn'(, one codeword per row. Nor-
tnVffliilg cach· of the n bits-uce 1 from it Th · I
the ., in the n-bit · ese are formed by systemaucal Y mally, the data would be transmi;ted one codeword at a time, from le~l to nght.
2 . · d ne column at a nme, start-
number legal .messages requires n + . codeword formed from it. Thus, each of To correct burst errors the data should be rram,rrune O 1
1
requ~ n J)atlems is 2", we m st~ patterns dedicated to it. Since the total ing with the leftmost c'olumn. Whe n all k bits ha\e been sent, _th e secoo<l co ~mn
. 'h th frame amves at the receiver.
oumbcr of ~ (m + r +I): 2, ~~ (n + 1)2"' S 2n. Using n =m + r, this
. . 7
IS sent, and so on as indicated in Fig . :,- - 'w en e f 1 th k
th · . ' ~ If a burst error o eng
This theort: . bus Deeded to.co~· . tvcn m, this puts a lower limit on the e matnx ts reconstructed. one column at a ume: been affected but the
Haauning(I9~i caJ loWer limit can . smgle errors.
~the
wilh bit t ai die
1
bits of the ~ fact, be achieved using a method due to
P<>wcrs of 2 (I 2 eod, bit 2 to its · w~ are numbered consecutively starting
occurs, at most l bit in each of the k codewords will haveth
Hit--·
- • 11 111ng code can correct one error per l:O
- de wordl~ks
so e en
u·re block can be
of km data bits immune
' l'CSlOfed. This method uses kr check bi ts to make b
4
· • , 8, 16 Ulllnedia&e ......
· etc.) arc check b' n~..t, and so on. The bits that are to 8 single burst error of length k or less.
ns. The rest (3, 5, 6, 7, 9, etc.) are
LINK LAYER Cl-!Ap_ 3
THE DATA
196 · SEC. 3.2 ERROR DETECTION AND C
. .
ting codes . which .are notor1._
0RR ECT!ON 197
d n wire less Imks modulo
, ., Error-Ottec 'd ly use o . Polyno rrn·al an· th met1·c 1·~ done
'l,J;
•• . odes are
w1 e d to copper wire or opttcal fiber
ugh .· lio~~
2 I of algeb raic
. according to th rue~
fi Id theo ry. 'fh ere are no carn.e~ for addition or borrow~ for e btr .
&ror.~ rrectt ng c prone when comdpbearehard to get anything thro d .
1e n and subtracti.on are identical to exclusive OR F 5u act ion. Both ad-
and error 1·t woul r, so erro r etect 1on anct d'tio • or example:
t is much lowe · h h occa sion al
ously nmsy -conccting codes, the error ra e 1· t e 1 1001101 I 00! 1()()1I
error mg wit
- - -- --
. there for dea I1II00oo
W itholll
ever. over cop!> · t:r WI•re or llyfiber.
more efficient . + 1100101 0 + I l()()J IOI 01010101
.ssion is usua - 10100110
- 10101 II I
h errors are ·isolated and the
rerransrni 'der a channel on whicbits. To provide error corre c. 01010001 Ill I 111 0 010101 I()
k •ze be 1000
. le example, consi
abit of data would bina II I 11010
emir.
As a
emir rate i
si;ro~ per bit. Let
k 10
the blkoc b'st~ are needed; •ah meg. I I b'
chec J
rel detect a block wit a smg
e - It error, one
Lon o di vision is carri ed out the ~ame way as it is ,n
t d u lo 2, as above. A divis . . or 1.s said ''to go ry exce d' the
int ,,pt that d subtr. ac-
tion for 1000-bit bloc . s. a block (IOO J ion e,is done mo as the · ·d1v1 ~or. 0 a 1v, end 1f the
bits. To meOync e every 1000 bloc ks, an
h
extr
d · dividend has as many btts .
uirc 10.000 check k ·u suffice. The
f
e erro r etec11on + od i~ emp loyed the send er a d
t
req
parity bit per bloc wi . d total over head or When the pol yno mial code meth recei ver must
low-
~in;O Ol bits per megabit of data, vers
us I 0,000 bits
gen erat or poly nom . C(xJ. in adva·nce. Both then high- and
ial,
bits) will
smiss have
ion to beodtrans
meth is on y agree upon a
the chec ksum for-,o me fram e
retran t be I. To compute
garbled by a order bits of the gene rator mus the fram e mu~t be longer than
a block and the block is badly the poly nom ial M (x ).
for a Hamming c~e. . . dd d to is only 0.5, which is with m bits , correspo ndin g to the end of the
will be dete cted idea is to append a checbum to
If a single panty bitbisb.al.t 11 ethat the error
bl 'f h bl k be the generator polynomia l. The d by the chec ksummed frame
I burst error ' the Th pro a y be improved considera y I eac oc to poly nom ial repre sente
odd can k b' h' h d · 'b frame in such a way that the frame, it tries
ong
hardly acceptable . e tangu s · · , as escn
d ed the rece iver gets the checksummed
lar matr ix n bits wide and its 1g ff- is divisible by G (x). When a tran, mis\ ion error .
sent 1s. regard ed as a rec mn and a _•xe to the a remainde r, there has been
above . A parity bit is comp uted sepa ratel y for e~ch colu dividing it by G (x). If there is the checksum is as follo i.. s:
time . Whe_n The algorithm for com pu ting
then transmitted one row at a
matrix as the last row. The matrix is a~~ one of them. 1s the low- order end
all the parity bits. If C (x). Append r zero btts to
the block arrives, the receiver checks Add 1t1o nal retransmis- I. Let r be the deg ree of and corre sponds to the
ssion of the bloc k. e so it now cont ains m + r bits
wrong. the receiver requests a retransmi is received without any parit y
of the fram
nom ial x'M (x).
sions are
. reque sted as needed until an entire block poly
errors stnng
sponding to Grx, 1mo the bit
of length n, since only I bit per
column 2. Divide the bit string corre modulo 2 divrs 10n
This method can detect a single burst tecte d, how ever , if the first correspondin g to x r M (x ). using
will be changed. A burst of length n
+ l will pass unde the b11
are correct. (A burSl ch is always r or fei..er b1ts 1 from
bit is invened, the last bit is inver ted, arri ~11 the othe r bits
t the fir;t
3. Subtract the rem ai nder (whi modu lo 2 ~ubtr acuo n. The
(x) using
wrong; it just implies that at leas string correspond ing to x r M
error does not imply that all the bits are long burs t or by multiple med fram e to be trans mine d. C11l Its pol:,no-
and last are wrong.) lf the block is
badly garbled by a result is the chec ksum
of the n colu mns will have the correct par- · mial T(x) .
'd , the1 o bility that
·5proba any
11y byr bursts
~hone
bloc k bein o acce pted whe n It
IS r . .S, so the probability
of a bad e,
' d not
shoul ace,bee~t, 01 011 011 using the generator
Figure 3-8 4 illustrate
s the calculati on for a frame 11 ...
s be adequate ' in practice, another
thde above schemthe e may some.time C (C lie G(x) == x + x + I ct· ._
d1v1s 1on
mctli~th_o~ghw1 . (m od u1O -" l b} G( r) In any
~
I • .
I a CR . ye . . 1ble
·
is Ill espre a(! use·
Ynonua code, also known as · r th at T (x ) is dl\'1s
ll.tdlllldancy Check' ·
s are base d upon treat ing bit stnngs as
It should be clea
p,oblem, if you dim inish the
. ed b) the rem,rn
d inde · d '::d, ,
what is, left JO.
over
by 1s941.1vbi-
the
rcJ>l'esentations of { /olynom1al code of O and l only . A k-bit fram ek -1~ ple. in bast' 10. if you di 1 . ·- 78.
- 10 ("07 879)
regar ded as the c:riic1en /. onula
t
ls wub
ist for a coef
pol
ficients.I ble by the divisor. For exam 2199 trom -..,1 0·-17g · what i,· 1elt over - .
lo o S Ynom1a With k terms, ranging
from x ~ema 10cter is 2399. By subtract ing
IS d' .. 'bl
.
. x_18· th uch a polynomial is s .
11
l. The high -ord er (leftm oS t) Whm kind, of mo~ w;JJ_ be
d~gree k - ..
~ e coeffi cient of x*- 1_aid to be of_ ficie nt of xk -2' and so on. >¥>st e by I 0. 94 I. th,~ mt'rhod. . . d of the bi t stnng
For example, 110001 has 6 b-U1e next b11 is the coef · -1 with Now let us anal yze the pow er of
- • ·urs so that a s to a bit that
in,1e·pond
thus • ·
COcffic1ents I 1 o 0, and l ·its sand 4 • repre ia .
d_etected? Imagine that a transm1ss 1on erroi
nom '. ' _
sents a six-t erm poly Ol l .
) L Llrres
· · •0. -x +x +xo _ • E h I b11111 .
f(r
b't error~ have occurred.
to T( x) artiving, T(x) + £(.r) am\ es. ·;ir£ ( •) k srn°
J h"s
A
"
r
· le ~Urst erro
fi ~ing c
· r is chara_
na1 I, W1th all other bi ts berng
.
tenz
0.
ed
·
by
111
3 n
·
1111
1 • e 1e-. 1
be en inverted If there are k I bits · ·tial• I· a mixt ure of Os and Is.
and a
LINK LA YER CHAP. 3
THE DATA SEC. 3.2 ERROR DETECTION AND CORRECTION
198 199
If there have been two isolated si ngle-bit ' + x J , where i >).
as E(x ) == xi(errors,
.
. ly, th'1s can be written E(x ) -x
Frt!TII
c,er,erator.
. 1101011011
~ atter 4 zen>
1 0011 . 1 1O101 1 0 1 1000 0
bits are appended-
Altematrve
is not divisible by x , a sufficient condition for
i-j
:u
d+ ~j
-
If we
that G(x) does not divide xk + I for any k up to th ou ~ errors to be detected
assu me that G(x)
is
1100001 010 . f e maximum value of 1. - 1. (.i.e.,
up to the maximum rame length ). Simple low-de gree po 1ynorruals .
that give. P:0 _
' ·
1.1101011 0110000
100 1 1I l
~
l . f
tection to long rames are known. For example x ts ... x 14 + 1 w·
xk + l for any value of k below 32,768. ' ' ill not d1 v1de
If there are an odd number of bits in error E (X ) contains a dd b f
10 0 1 1 5 2 b 2 ' no num er o
tenns (e.g. , x + x + l , ut not x + l). Interestingly, no polynomial with an odd
~ number of terms has x + I as a factor in the modulo 2 system. By making x + 1 a
OOOO 1 factor of G(x), we can catch all errors consisting of an odd number of inverted
~ bits. -
0 0 0 1 0 To see that no polynomial with an odd number of tenns is divisible by x + 1.
assume that E (x) has an odd number of terms and is divisible by x + I. Facwr
~
E(x) into (x + l) Q(x). Now evaluate £ (1 ) == ( I+ l)Q( I). Since I + I == o
0 0 1 0 1
(modulo 2), E( l) must be zero. If E (x) has an odd number of tenns, substituting I
0 0 0 0 0
for x everywhere will always yield I as the result. Thus. no polynomial with an
0 1 0 1 1 odd number of terms is divisible by x + I.
0 0 0 0 0 Finally, and most importantly, a polynomial code with r check bits will detect
all burst errors of length $ r. A burst error of length k can be represented by
x;(xk- I + .. . + I), where i detennines how far from the right-hand end of the
1 0 1 1 0
1 0 0 1 1 0
---- received frame the burst is located. If G (x) contains an x tenn. it will noc have
0 1 0 1 0 xi as a factor, so if the degree of the parenthesized expression is less
than the
0 0 0 0 0 degree of G(x), the remainder can never be zero. .
If the burst length is r + I , the remainder of the d_i:ision b) G(x) will be zero
th st
0 1 0 0
if and only if the burst is identical to G (x). By defi nmon of a bursL e fir "."d
0 0 last bits must be I , so whether it matches depends on Lhe r - I i~c_ermediace bi ts.
0 1 0 l f all combinations are regarded as equ all Y lI.keIY· the probab1hty of such an
incorrect frame being accepted as valid is w- · ,
1
h . we no lonoer a~~ume
.b
,•
d·
that the network
bl the network
,n
e tncomrng
L)NK LA YER CHAP 3
n 1EDATA . .. . . . 5EC. 3.3 ELEM ENTARY DATA LI NK
·eccn'cr2 1s th at after deli vcrin " . PROTocoLs
• 1•I and I t' t, "
,os
~ . t,d weeO 2 . nds an a, cknow ledgement
recc11·c
h rame . back to 4 The du pli·cate f rame also arrives at th d . 209
t,ffcr<•nc~ r,eirer ~e . Because only t e arrival of th e • . . e ata li nk la
Th. ,,n h ' k h ver. r . op agai n. . and is un wittingly passed to the netwo k yer on B perfectly
I
' 11;cne1w11r · '. · the wait 1o ' . contents, the receiver need not Plll a fi le to B, part of the fil e wi ll be dupJi~at ~~r th ere. If A is sending
p:J,k<' t 1,1 bef<,re entenng . ,portant. not its
the ,,·nder h sender i, in . made by B will be incorrect and thee 1.e., th e copy of the fi le
' k at I e . . . IL
frJ111e b,tr . f rn1auon in detec ted ). In other wo rds, the protocol willerror
fail will not have been
1111' particular ,n () N . y Channel
. . I . Protocol for a ois. Clearl y. what is needed is some way for the rece· b
. g fo r the fi rst time from a retra tver.to e abl e tO d'1Slingu1sh
. .
,u
·..
A SirnP ex . . of a communication channel that
I s1tuat10n H a ra f , me that it is seein
nsm1ss1on The 0 b ·
.1der the norma ·damage d or lost complete1y. . owever. we chi eve thi s is to have the sender put a ,equence nu b . · v1ous way
I 11, con~ • h r to. ane it se nds. The n the receiver• can check the sequence m er inbthe header
f of .eac h
Now et · Frame'·' maY Wt 11 detect this fra1
· be e1ld ·e transit,
. the receiver hardware
. . . . f .
frame 10 see 1f 11 1s a new rame or _a duplicate to be discarded.
num er o each amvi
no0
makes erro~.f f me is damage in f 111e is damaged m such a way that the
that , a r,i If the ra · 1 Since a small frame header 1s desirable the questio . . Wh .
;L,~ume· c0 mputes. the checksum.t an un 1I.kely occurrence, this protoco (and all . needed fo r the seq uence· number~ nThe anses. at 1s. the
I 11 •,nimum number of bits b. .
w,en . e,·ertheless correc_· . orrect packet to the network layer). m . . · on Iy [famf 1gmty in
h ·k<um is n . deliver an me Id k thl·s protocol 1s between a frame, m, and lls direct , ucces,or m -'- .
c e, · •01, 1 can fail (1.e.. •ation of protocol 2 wou wor : addi ng . . · • . 1 rame m 1s
()ther p[()t(X . . I em that a van . Id I lost or damaged, the receiver will not acknowledg_e it. so the sender will keep try-
. ._ 1fir<I
1 ~lance it mig it se f me but the recei ver wou on Y send an
. · ·The sender could seod a ra c.orrectly received . If a damaged frame ing 10 send ti. Once 1t has been correctly recei ved. the recei ver will send an
a umer. ·rI the data were acknowledgement to the sender. ft 1s here that the potential trouble crops up.
. knowledgement .frame- would be d.1scarded · After a while the sender
ac d -would
h time
1
anived at the receiver. 1 . Th.. ocess would be repeate unt1 1 t e frame Depending upon whether the acknowledgement frame gets back 10 the sender
ClUI and ·
·end the frame again. is pr correctly or not, the sender may try to send m or m + I.
'
finall y ani"ed intact. fl · it Think about the problem and try to The event that triggers the sender to start sending frame m + 2 is the arrival of
The above scheme has a fata 1 aw id0 _ . f rther an acknowledgement fo r frame m + I . But this implies that m has been correctly
• ht go wrong before rea mg u · .
disco,·er what mig . mber that it is the task of the data lmk layer received. aoo furthermore that its acknow ledgement has also been correctly
T0 hat m1oht go wrong. reme k received by the sender (otherwise. the sender would not have begun with m + 1.
seetowprovide . " error- free, Iran sparent communication between networ. · layer
processes , k machine A gives a series of packets to its data let alone m + 2). As a consequence, the only ambiguity is between a frame and its
rocesses. The net11, or 1ayer 011 . . d 1· d immediate predecessor or successor. not between the predecessor and successor
plink layer whJCh · must ensure that an identical senes of packets . are he 1vere tok themsel ves.
the netwo~k layer on machi ne B by its data link layer. In particular,_t e networ
m
layer on B ha.~ no way of knowing that a packet has been lost d_uphcated , so the A I-bit sequence number (0 or l ) is therefo re sufficient. At each instant of
time, the receiver expects a particular sequence number next. Any arri ving frame
data link layer must guarantee that no combination of transm1ss1on errors , how-
ever unlikely. can cause a duplicate packet to be deli vered to a network layer. containin g the wrong sequence nu mber is rejec ted as a duplicate. When a frame
Consider the following scenario: containing the correct sequence nu mber arri ves. it is accepted and passed to the
network layer. Then the expec ted sequence number 1s incremented modulo 2
I. The network layer on A gives packet I to its data link laye r. The (i.e ., 0 becomes I and I becomes 0).
packet is correctly received at B and passed to the network layer on An example of thi s kind of protocol is shown in Fig. 3-12. Protocols in which
8. B ,end~ an acknowledgement frame back to A. the sender waits for a positive acknowledgeme nt before advan~ing to the n~xt
data item are often called PAR (Positive Acknowledgement with Retransmis-
2. The ackn0\1ledgement frame gets lost completely . It j ust never
sion) or ARQ (Automatic Repeat reQuest ). Like protocol 2. this one also
arri,e, :it all. Life would be a great deal simpler if the channel man-
transmits data onl y in one di rec tion. .
gk<l and lost only data frames and not control frames. but sad to say.
the channel is not very di ,criminating. Protocol 3 differs fro m its predecessors in that both sender and receiver_have a
variable whose value is remembered while the data link layer is in the wait state.
The data link !aver on A II • · · · ·d The sender remembers the sequence number of the next frame to se nd m
.~n .i,·kno,1ledge . · •eventua y lime~ out. Not hav rn g rece1,c..
1o,1()r damaged ment
and .,n d.
(incorrectl y) a~s umes
. . that its data fram
. e I\"' nexr-Jra,11e _ro_send · the recei ver remembe rs the sequence number of_th e next
~ n s the frame contarnrng packet I agam. fram e expected in/rome_expecred
• .· . Each prutOL0. I h·a,. a , hort initiahzauon phase
before enteri ng the infinite loop.
.A UNK LA YER Cl-!Ap Ff.F:. \II ENT AR'/ f>AT.\ I I\K
THEDA 1 s£C 3 1 · PRfJTr,..- ri1 ,;
210 . 211
flow over an unrel iable chan nel • / A he r cran<;m11 t1 ng a fra me the ,ender ,r.i r- rhe '•me· ru
d1rect1onal data , d\ runni ng. 1t wd I be re,et to Jllo'-" mnrher f nnrng If rr wa.\ 11-
must be 1 tor protocol 3 • / 11 11
• protocol 3 lpa rl 811ows unr I• rea -
~hould be c ho<;en to aII ow enou 2 h rime fo he {lmer f
rnrerv::it n.._ , , ic: l1mt n-
MAX. SEO 1 ksurTLerr. timeout) evenUype ,
te r\,d 1 - r r ramc ro •et 1 .__
- ihe rece1\<er to proce,'i 1t m the ""ON a,;e d - o t,,c ;ecene,.
lld6fine
typedef enum
(frame arrival. c
•- tor b k ~ 1n t1,r •~ «:icnow r...1
_ me ro propagate ac 10 the ,ender (J nl·, ,11he rh- ""'tt:DC:ll
tmeiude •protocol.h tra
_ r ~aie to a, , ume I hat ell her the rran\mllted f.., men dt 111ne irner,al ~ e-,,~ '•~--•
vood sen<!er3(VOld)
,, I '" •>r 11, JCknow ed
'-oen los t. and to send a duplicate If the ti meout nt _ eeniem :-i;i,
1• seq number of next outgoing frame •! l"- . e. .11 ., -.er •.oo hort the
\ seq_nr next.JrameJo_send; /• scratch variable • / nder will 1ransm11 unneces;sary frame , While 'he,;e •
,e i:~rra rame, lii1 II no; rtfect
1n1me s /• buffer for an outbound packet • / rhe correctne <;s of the protoco l. they will huri pertnrmance
pecl(el blJlfer: Afte r tran smitting a frame and , tanm11 rhe tuner ·he -- "-·
evenuype event: . . - -..c , iuc. w 1111, for some -
/• initialize outbound sequence numbers •/ ihing exc_,ting to happen . Only th ree po, .,,b,hue, ::~•~t .m iJCkno-.~ement
ne,ct.JrameJo_send = O; /• fetch first packet • / frame arn \'e , und amaged . a damaged Jck.nowleJi1ement t.,..,m_ ..," -
0
trom...netwo111Jayer(&buffer): . . - ·-•-- -~;en Ln. o; tne
timer expires: If a vali d ack.now ledgemen1 come, m. •tie .ender tetc!'l;;, the r~ ,
wftite(true) ( /• construct a frame for transmission •/
s.info =buffer. packet from 11s network la yer and put, 11 m the riutfor n en\r.nn~ nc prCYiOO-,
s.seq = next.Jrame_to_send;
/• insert sequence number in frame •/
/• send it on its way • /
packet. It also advances the ,equence number If a damaged irame ~ \ e, or
00
to_physicl!Uayer(&s):
starU imer(s.seq); /• if answer takes too long, time out • / frame at aJI arri ves. neither the bu ffer nor the -equen~ nurnl:ler ., cb.mreJ 11W '°
/• frame _arrival, cksum_err, timeout •I a dupl icate can be sent. -
wa1U or_8Y8111(&event):
=
It tewnt frame_anival) ( When a va lid frame arri ve~ at the rece,.,,er. us -.equence numoer s ~;ic:c,_aJ to
trorn4'hysica1Jayer(&s); I• get the acknowledgement • / see if it is a dupli cate . If not. 1t I!, accep1ed. pa., -.ec 10 the net ,on. !Jyer. .ind &11
If (s.ack = nexUrame_to_send) { acknow ledgement is generated. Duphcates and damaged trame, .ITe O{.; ~-ed ;0
stop_timer(s.ack); I• turn the timer off •/
the network layer.
from _network..layer(&buffer) ; I• get the nex1 one to send • /
lnc(next_frameJo_send); /• invert nexLframe_to_send • /
\'Old recerver3(void) In the pre viou!, pro tocol,. da1a lrame, \\.ere tr:ubnurtc.-<l n one ~rre~uon onl\
(
In mo~t prac1ical ~itua11on~. there •~ a neeJ tor 1ran,m1mn" JJl:.I n bolh Jm:.:llon,
&eQ...nr trame_expected;
trame r, s; One way of achieving fu ll-duple\ data tran:,nm :,1on 1~ to :l.Jve l\\ o -..:p.intt: L0ffi-
evenLtype 81111!lt munication channels anJ u~e each one tor ,1mple\ L!J!J uJttlL 11n J11terCJ1t duee-
trame..sXl)eCled = 0. tions). If this i:, done. v,e have tV. Ll --cp.irJtt' pn"11:al ~ircu1h . .::11.n ,,ch J ·tor-
wtlilettrueJI ' ward " chan ne l ( for data / anJ J " re\eN: · ..:hannel ,,r J1.~nu"' lcJgemcnt, 1 In
w1t1..1oc even1(&eveot)· both case" the bandw idth oi the re\ er,c , hJnnd " .ilmo, 1 enurel\ \\.1.,tell. In
=
ff (event lrame..amv'a1) I I • possibilities: frame _arrival , cksum_err •/ effect, rhc u.1,er i~ paying for t\\L1..:rrcu1h but u, ing ,,nl\ the ~JflJdt\ ,,t , Hi..:
I• a valid frame has arrived . • /
trom..J)hysicafJa~&r).
A be-Her idea i, to u~e 1he ,a me, irL" uH r,,r J.ira 111 bt_,rh Ju't'\:Uon, \ ttcr all. in
~ (r.seq =a:: fr1me_e~) { /• go get the newly arrived frame •/
I• this Is what we have been waiting tor •/ Protocol._ 2 and 3 11 wa!> alre,llh beinl! u~eJ to tran:,m11 trJme, b.>Lh V.J}:., .i.ml tbe
i~ ~ laver(&r.info); rev en.._. c. h~inncl ha., the , ame L-' ap.1u l\~ J., tht' tL•m JIJ ' h.urn c•I In th,~ model the
·~ ~ -8Xl)eote(j); /• pass the data to the network layer •/
/• next lime expect the other sequence nr ' da1a 1·rarne~ trom· A to B are 111rerm1,L·J 1, 1th rht' Ju,, mrn Ic•Ju =-c·mcnl trnml!.'> trum A
~ad( "' 1 - frll'Tle -8-P6ct8d· to 8 B . J 1 • min " tr.ime the rece1vc:r
1* tell Which frame is being acked •/ • ) 101.1!-. m g al the /..111d l1t'ld 1n tht' hcJ er L' Jll IIH.:ll =- •
~Yllci1Jayer(&1); ,
) 1 can tell \\ ht"tht•r !ht' irunw ,, JJl.l t> r Jd lh1\' k J ~cmenl
* senc1 acknowledgement•/ • ' l1l rhc: ,amc ClfCU II I\ J nr
I Al rh,iugh mterlt',t\ in )! d.1rJ JnJ , unrr. 11 11.1111c,
in1p - ~ ~ct JOlllh<!r 1mprovemen
Ylp n-3, 12 A ro,t'111e111 m er ha\l n" r,1l1 ,t'p.tratc' ph) , ll'J 1 .:ir~ui 1.. - d parare
. ~ 1ove acluowledgcnien1 . . ,, po:,;~iblt-, \\' ht"n u Jt11u~lra111t' JITI\L' ' · 111,teJJ or imm.:Jiarc:l y ,<!n mg J , .:
Wllh re1rans1111:.s10n pro1U<.·ul.
TH E DATA LI NK LA YER
Cll,\ 1, SLI DI NG WINDOW PR
1 5f,C. J.4 OTOCOLS
, . . itself and waits until the network I· ··
21.. . restrains - . ayer . 213
, the receiver
cknow Ie
dgement ,s attac hed to the out go ing d· .. r ,l\1e1
ft. I k at<1 f
Although these protocol ,; give the data I k
. _, in layer m f
1I frJnii.:, in whi ch Jt may senu an d receive frames h ore reedom about th
, 1,nu1 ket The a header) . In e eel, t 1e ac nowledge r<1riie er h . we ave d ti . e ord-
ext pnc . . th frame . n1en1 irern ent that t e pro tocol mu,t deli ver p k. e in1tely not dro d
,, the n , k field ,n e . d ta frame . The techmque of temporaril gets' req u ac ets to the d . . ppe the
1u~1ng che a~he next outpJ1ng athat they can be hooked onto the nex~ delaying . the same orde r th ey were pa~'>ed to the dat 1· k e\t1nat1on network I
free nde on wledgemints so . outgoin, ,n d h . a in layer h ayer
outi!oing ackno as piggybackmg. . . . . , No r have we ., change
. . t e requ irement
. that th e phys1cal
.· coon t e .sendino . c mach·me.
" wire- li ke . th at is. it mu, t deliver all frame, ·1 th mmunication channel i·s
- f-
data ,..,.. . me is known ·
d antage o - fusing piggybackrng
. over having . di stinct ackno111
, •
The seq ue nce nu mbers within the '>e nder·
n e order s
ent.
The principal a v . . of the available channel bandwidth. The k _ · 'i wrndow repre f
is a better m,e . . . . ac held bee n sent or ca n be sent b~t are as _yet not acknowledged. W~ent rame~ that have
,ctgement frames ly a few bits, whereas a sepat ate trame would
r der costs on ., need arri ves from th e network_layer. It J', given the next hiohest' ene ver a new packet
in the frame hea d ent and a checksum . In add1tton , fewer frani a
knowle gem · " es \ent the upper edge of th e winuo w 1, ad\anced hv ~. . equence number, and
11eader, the ac . al" interrupts. and perhaps 1ewer buffers in the re .· . - one vv hen .in a k I
"frame arnv . ce1ver Comes in , the .
lowe r edge I \ auvanced by one I h.
. • n t 1s way th
c now edgement
·d .
means fewer ·h ceiver's software is orgamzed . In the nex t protocol · ously maintains a I 1st of unackno¼ ledaed frame, F e wm ow co ntrnu-
d . 00 bow t e re . . to be
depen mg . b k field costs only I bit m the frame header. It rarely "' . igu re 3-13 ,how, an example.
examined. the piggy ac cos11
more than a few bits. . . . . . Sender
.ooybacking introduces a comphcat10n not pt.esent w1th sep·irat
.11)<,
·(~)'
0
6_0 _1 s_r-;
However. Plec- . ' 1 0
"nts How long should the data hnk layer wa it for a packet ont
acknowIedge m" · ? . . . . o
which to piggyback the acknowledgement. If_the data hnk _!aye, wa11s longer I i
than the sender's timeout period, the frame will be retr~nsm1tted, defeating the
whole purpose of having acknowledgements. If the data hnk layer were an oracle
and could foretell the future, it would know when the next network layer packet
5
4
,
3
2 "
:J ~
4 3
I
2
/~ 2
.l
J 2
was going to come in and could decide either lo wait for it or send a separate ac-
knowledgement immediately, depending on how lo ng the projected wait 11·a1 Receiver
going to be. Of course, the data hnk layer cannot foretell the future, so it mu,1 7 0 0
·(~y
I
4
2 5~ x- 2 5
..____/ x_J 2
The next three protocols are bidirectional protocols that belonc,.O to a clasi 3 4 3
called sliding · d . .
ffj
. wm ow protocols. The three differ among themselves rn terms of (a) (b ) (C) (d}
e c1ency, comple ·1 db .
all lid. . xi Y, an uffer requirements as discu ssed later. In these. as 111
s mg wmdow p t I ' br
rani:rin fro ro oco s, each outbound frame contains a seq uence num e· Figure 3- 13. A slid ing winJu"' of , 1ze I "',th J 3-bir ,cquence number.
"~.g m O up to some · · 2" I so the (a) Ini ti a ll y. (b) Afte r the fiN fr:ime has been ,ent. .:1 -\ tier the 11N fr.1JT1e ha,
segue.nee numbe fi · ~axllllum. The maximum is usuall y - . .
protocol uses ~ ts ex~tly 10 an n-bit field . The stop-and-wait sliding w1nd011 bee n recei ved . ( J } After rhe fiN Jckncl\\ kdgement hJ, bet·n recmed.
· ' n - 1• restn · his·
ticated versions · ct~ng the sequence numbers to O and 1, but more sop
Tb can use arbitrary d Since frames curren tl y within the :,e nder·s ¼indo"" may ultimately be lo:,t or
. d e es_sence of all slidin . n. . . . 1e, the b~~:ged in transit. the sende r must keep al l these fr~e~ _in its memory for possi-
seo er maintains a g Wmdow protocols 1s that at any mstant of on ·
led to set of sequ .11 1.5 pernut· b transmission . Thu s. if the ma.\ imum wrndo'-" size ,~ n. the sender needs n
send. These fr · ence numbers corresponding to fram es .
the rece· amesare 'd s mdaf1l, .1uffers to hold the un acknO\\ led oeJ fr::ime ~. If the ,,indo"" ever grows to its max·
it is sv~r also maintain ' s sai_ to fall within the sending window· 1. .,1,n~' mum
llellltitted a recetvi · h t o11r, . size,
· t h e sendin P- data link=- l:ner mu~r torciblj
• · shut Oft· I1ie ne rwork layer
1101 hav h . to accept Th
ct e · e send •
ng wmdow
·
corresponding to t e se 1, 11
, · 1d 0 \
,,J unti l ano h . ;:;,
t er buffer becomes lree.
. .
. .
protocols th same lower and er .s window and the receiver s Wll ,un11 The rec · · . . \\111dow
· , , ds to the trames tt may
a e1v111g data lml-- layers LOrrespon
cou~ of . ey are ftXed in . upper limits or even have the same size. 1n r tli! ccept A . . . d.. . ·ded without comment.
• f
t11ne 45 Stze b 1 · · k 01'( Wh · ny tra me fa lling outs ide th.:- "111dow i~ iscai . .d .
rames arc ' u IIl others they can grow or shrtn en a frame whose se4uence ~
number ,~ .
.:-qua! to the Iower edoe0
of the wm ow
sent and received.
LINK LAYER
THE DATA sec. 3.4 SLIDING WI NDOW PROT
OCOLS
n acknowledgement is gene.
14 k layer. a rated 215
2 d to the netwo~ h sender' s window, the receiver ' s . .
. · assl.! Unlike t e · . • f · Win. . col 4 (sl iding window) is bidirectional. */
~Proto
i~ received. it is_~•rotated b~ ?ne:. Note that a_window s1~e o I means that the
d the window '·. . tits ininal sIZ~- d r but tor larger w indows thi s is not 1
an mains a s 10 or e , d ,o d8 fine MAX_SEQ I* must b
downlwnr re I accepts frame. 'ed data in the proper or er, regardles, f. # d f enum {fram e_a rrival , cksum_err, timeout} e 110r protocol 4 */
. . Iayer on Y.n contrast, is· always 1' •• o type e h" evenLtype·,
data hnk #include "protoco I:
rk layer. I . e . d .. '
'd protocol4 (void)
Toe ne1wo r10k layer,s window s1z .le Wll. h a maximum w111 ow . st ze of I . l ni ti·,11
' y VOi
the data
F ure 3· 13 . shows .an examp the lower
and upper edges ot the sender ' s wind ·
. ow { nr nexUrame_to_send ;
ig are outstanding. so . ation progresses as show n . seq_ t d
no frames . oes 00 , the situ
seq_nr frame_expec e ;
I* 0 or 1 only *I
ual but as time g I* 0 or 1 only */
are eq · tocol framer, s;
I* scratch variables */
B·t Sliding Window Pro packet buffer;
WA~• . . . . . evenLtype event; I* current packet being sent *I
. 1he general case, let us first exam111e a shdmg w111dow. proto. nexUrame_to_send = O;
Before tackling . . f Such a protocol uses stop-and-wan since
. window size o I . d b t· frame_expected = O; I* next frame on the outbound stream •/
col with a maximum d waits for its acknowle gement e ore sending from_networlLlayer( &buffer); I* frame expected next •/
the sender transmits a frame an
=
s.info buffer; I*
1
fetch a packet from the network layer •/
. sueh a protocol . Like the others, it starts ou t .by defi
. ning s.seq = nexLframe_to_send ; * prepare to send the initial frame •/
. one.
the next 3 14 depicts 1
·
Figure·ables 1 end tell s which frame the sender Is try ing to s.ack = 1 - frame_expected ; * insert sequence number into frame •/
Nett-frame_ OJ · · • /• piggybacked ack *I
send. van
some ·
· frame_expec
Similarl·y. ted tells . . . frame the receiver 1s expecting. In
. . which to_physicaUayer( &s) ;
I• transmit the frame •/
bo1h .. 0 and I are the only poss1b1h11es. . . starUimer(s.seq) ;
/• start the timer running •/
ca.~es. norma1 mcum
Under • stances , one of the two data hnk layers
. goes fr rst and while ftrue) {
· the fi1rst frame. t11 other words· only one. of the data lmk layer
transmits . program
.. ! waiLfor_event( &event);
if (event== frame_arrival) { I* frame_arrivaJ. cksum_err, or timeout •/
should contain the to_physicaU ayer and start_t1111er pr~c~dure call s outside the I* a frame has arrived undamaged. •/
main loop. In the event that both data link layers start oft _s1multaneously :. a pecu- from_physicaUayer(&r) ; I• go get it •/
liar situation arises. as discussed later. The starting machme fetches the ti rst pac- if (r.seq ==frame_expected) {
/• handle inbound frame stream. •/
ket from its network layer, builds a frame from it, and sends it. When this {or to_network_layer(&r.info); /• pass packet to network layer •/
any) frame arrives, the receiving data link layer checks to see if it is a dupl icate, inc(frame_expected); I* invert seq number expected next •!
just as in protocol 3. If the frame is the one expected , it is passed to the network
layer and the recei ver's window is slid up. .
if (r.ack ==
nexLframe~to_send) { /• handle outbound frame stream. •!
The acknowledgement field contains the number of the last frame rece ived stop_timer(r.ack) ; /• turn the timer off *I
without error. If this number agrees with the sequence number of the frame the from_networlclayer(&buffer); /• fetch new pkt from network layer•/
sender is trying to send, the sender knows it is done wi th the fram e stored 111 inc(next_frame_to_send); /• invert sender' s sequence number •/
ln,ffer and can fetch the next packet from its network layer. If the sequence
numbe~ disagrees. it must continue trying to send the same fram e. Whenever a }
frame is received, a frame is also sent back. s.info = butter; /• construct outbound frame •/
.
Now let us examine p t 1 4
scenanos . . Assum h· ro oco
. .. . .
· see how resi lient 1t 1s to pat 0
to
h logical
B
=
s.seq next_frame_to_send; /• insert sequence number into it •/
and that 8. .1 . e t at computer A is trying lo send its frame O to computer s.ack = 1 - frame_expected; seq number of last received frame •/
, ..
~ trving to send 1 -ts f · to B to_physicaUayer( &s); /• transmit a frame •/
~
but A' ·s t'inieout•.interval i~ a r .I r.une Oto A. Suppose
that A se nds a trame e·1t··
starLtimer(s.seq); I* start the timer running •/
edly. ,ending a ~erie f .·d Ht e 100 short. Consequently, A m ay time out rep ' }
' o , en1tcat fra . II . I }
When the ti r,t ,. 1.d f mes. a With seq = 0 and ack = . d
a I ramc · . I ·111
frmne_n 1>eu,.,c1 will be arnves at computer B, it will be acceptet ' ,J
bee·uu,e n·" now expe • ~et . to I · Al l tiie sub sequent frame s w I·11 be i·eJ~cte Figu re 3-14. A I-bi t slid ing window protocol.
Cling tra . · . ore.
me~ With sequence number I . not 0. Furibenn
A L(NK LA YER CHl\p_ l
rHE DA T
d 8 is still waiting for an ack now i 5EC. J.4 SLID ING WINDOW PROTOCOLS
216 have ack "' I ant_ m it s network layer. edge. 217
JicateS • acket ro · . n these situ ation, the long round-trip time c h .
11 thC dur · ~ tch a new P . •n B sends A a tram e co ntaining , false . I f th b· d . . . an ave rmpona t .
qn,·e a_ ficien cy o 1· .
B ,·ill not e I' ate conics t .
nrnt ol O. , ' ·ectcd dup JC hese arrives correct Iy at A ' causing .· Wq ::: [) f rt he e f . e an width utili zation . A•, an ex.a mple c n.dim p 1-cat1on5
,1 to be ,· o ellite chann e l wJth a 500-m5ec round- trip propagatio n de!~ on51 er a :i0-kbp5
, Aller c,·e1j rt;J tunllY• one oft b' tio11 of lost frames or premature ti111 gin sat _ to use protoco l 4 to ,e nd I 000-bJt frames via th
0 En:n N com
anJ a,·l ~ . ·t packet. o d ina .h
Jicate packets to e1t er network laye r, toeou1, 1ry1ng . Y-_ Let U5 imagrne
!llling tht ncx sk . starts send111 g the fi1r~t fram e. At t = 20 m,;e, the \alellite At 1 _ 0 th
110 deli ver up . ip sen de r - - " e
f
rame
·
has b
- e
st the protoeo . _ · ly sent. Not until t = 270 msec ha<; the fra me fully
can cau.<e deadlock- . . s if p1ete . 520 d een com-
l;et or w . ·tuatwn anse. both sides sunultane ou sly send .1 . . ot until t = msec ha<, the acknov.,led .
gement arnvarnve at
d b k the receiver
apac • . a pei:uhar s1_ . difficulty is illustrate d b y F.1g. 3-15 . In , n in1 . an d n . e ac at the \ende ,
Howe1er. ch 1za11on part ( r the best of circumsta, n ce5 ( no v., altmg
.. .
m the receive d
. k I This syn ron I is shown. In (b) the pec u ianty
1· . . . a),
is illustrat d
d
un e .
ent frame ). Thi » mean <. that the <,ender - r an a ~ hon acknowlr,
ual P3' e . . f the protoco edgem wa, blocked d
unng :, 00/520 or 96-
1
· . h . ~
al 0 perauon o b f re sendino one o its own, t e sequence is e. .
ihc norm . first frame e o "' . ·1· A d B . pe rc ent of the ttm e. In other . .word ,. on ly -+ percent of the ava·ilahl e ban dw1 <l t h was
If B waits for As I
d every
f I accepted. However. I
·s an s1_multaneous"'h· sed. Clearly. the co mb111at1 on of a long tran<;it time. high bandwidth d h
rame
chown in (a). an . th . first frame s cross. an d the d ata · 1111
· k Iayers then ' u . d' .
- get frame length 1s 1sastrous 111 terms o f e ffi1c1ency.
. . an s ort
iniuaie commu 01·canon• elf·h frame arrival brmgs ·
a new pac k et "1or the network The problem desc nbed above can be viewed as a con~equence of the rule
inio situation (b). In (ali) eat\ In (b} half of the frames contain duplicates even
........ are no dup ca e . . . . . requiring a sender to wait for an ack nowledge ment before sending another frame
layer: u~~ •ssion errors. Similar s1tuat1ons '
h can occur as a result of If we relax that restn ~t1on. muc h better effi ciency can be ach1eved. Basicallv. the
thoug there. are no rransm1.when one side clearly starts f irst. ' In f act, ..
1f multiple solution lies in allow111g the sender to transmit up to 1~ frame<; before bl~kirn1:.
ture umeouts. even .
prema . cur
premature umeouts oc • frames mav• be sent three or more times. instead of just I. With an appropriate choice of 1-\ the ,ender -,., ll be able to
:;L
1 co;.
tinuously transmit frames fo r a time equal to the ro und-tnp transit time without
Asenos (0. 1. AO)---- A sends (0 , 1, AO)? ; B sends (0, 1, BO)
--._ B gets (0, 1. AOr B gets (0 , 1, AO)"
filling up the. window. In the ex ample above. ~v ~hould be at least 26. The <,ender
B sends (0. O. BO) B sends (0, 0, BO) begins sending frame O as before. By the time it ha~ fini<,hed sending 26 frame~.
Agets (0. 0. BO)" --------- A gets (0 , 1, BO)'
at t =520, the acknowle dge ment fo r frame O will have just armed. Thereafter.
Asends(1 , 0, A 1 ) - - B gets (l, O, Alr A sends (0 , 0, AO) acknowle dgements arrive every 20 msec. so the sender aJv.,a:,,'i gets perrmsswn
to
- - B sends (1 . 1, B1 l 0 continue just when it needs it. At all times. 25 or 26 unackno-,.,led2ed frames
Agets (1 . 1. B1)" : ; !~sdi (·t o~~t) are
outstanding. Put in other terms, the sender' s maximum window ,1z; i!> 26.
Asends (O, l A2)- - - B gets (0, 1, A2r ~ ;!~~~ 0
i1~l~1~
The need for a large window on the sending side occurs whene\er the product
Agets (O. o, • - - B sends (0, 0, B2)
Asends (1 . 821
B gets (1, 0, A1)'
0
A3) B sends (1, 1, 81 ) of bandwidth x round-l!ip -delay is large If the bandwidth I\ high. e\en
for a
- - - - Bgets(1 , 0, A3)" A gets (1 , 0, B1)" moderate delay, the sender will exhaust its v. indow quick.1 unk,~ it ha, a
Bsends(1, 1, B3) 1 large
A sends (1, 1, A 1 ) ~ B gets (1. 1,A1 ) window. If the delay is high (e.g .. on a geostatJ onary , atellne channel 1. the ,ender
B sends (0, 1, 82) will exhaust its window even for a moderate bandv. idth. The produ.:t of the,e
t\\O
fa~t?rs basically tell s what th e capac ity of the pipe i,. and the sender need<,
the
abiltty ~o fill it without stopp ing in order to operate at peak effic1enc)
(2) Time
(b) This technique is kn own as pipelining . If the ,·hannel c:.1pac1t~ b h b1h/,ec.
r~ure 3-15, 1'11 .. \(' t ll.lr f th e frame size I bits. and
1 the round-trip propagation ume R ,ec. the nme required
•N Thl' 11 ,, "' or protocol 4. (al Norm al case. (bJ Abnormal
1 11 to transmit a single frame is lib ~c'C . .-\ fter the la:-t bit L'f J J:.ita frame ha~
""""rl.1,,,l'r : /'n ' ' '·s:y, ark. packet number). An asteri sk indicates where a been
. ,tp 1' a PJ,ket. sent, there is a delay of R I?. be fo re that bit an-i, e:- at the recmer and another
14.2 A Pr t delay of at least R 12 for the ackn owkd\!e men1 to come bad.. tor •1 total Jel.i:
of
o ocol Using Go Back N R. In st op-and-w ait the line is bu~y for ///, :i.nJ idk for R. gt\ ing
l.':,1 i1 ~\)\\ \\ . line utili ,a tion = / 11/
re JU , ., ' ha I e n . d -r hR)
, ir," I ,r J 'r· la e the ta ·
le,,, . 4m, ro arn 1 ,
l. 11 •;1 en assumption that the transmi.ss ion · 1iine
. lf I< bR , t he efficienc - pt' rl·t' nt. s ·· there i, .1!11J1:. 3
~,•-~•"Ill t,, ' at the rece · . f · 1he ac · y ,, ill be" le:s:, th.111 :,Ll llll l · .·
l"Jne b:ick i . . iver plus the transmiss ion time nonzero d I
or
. this assumptio- n 1·5 clean1·, . . e ay for the acknO\\ leJgelllc' ll l to ~m ip.ig:i.tt' t, ,lL·k· pipel 1111 no can. in
e. sornet11nes
~ neghg1bJ
1 .
Pnnc1pl b .• · ."' .
s
111
e. e used to keep the line - hth\ dunn . h
g t 1' inten a.l · bu t 11 the 111 tef\-J is
all • the a ctct·111onal
· co mplexity is not \\O. ri h th..: 11·L'U t,I t.•
• •s
.h
n 1E PI\
TA LINK LA YER
l'rth"'"~ ff\\ ,hat happens if . eeding fram es will a rri ve at the . darn.
F,~. " . he-fS of ~ucc . ~ . .
,i1r.- ,-.<11C'.S- ., u r~r oun1 • that anything ,s wrong .
- -~ (\! I<'-' ' .an <'vcn finds out
Wh
C
HAr 1
liuble coimnunic~ti o n c ha nne l rai ses so me .
. nll'-~ orer an unre a frame in lhe middle of a lo ng stream is ,eri.
rece1,
en a c..l arn aged f , er
1 should be discarded , but w hat sho Irun1e
sf.C - J.4
kJ1
c~w~
.
10
0wle g
SLID ING W INDO W PROTOCOL')
.
~,v ...., ..rn.,.r . obvious y . . ? R b
r Frame s O a nd I a re correctly received and k recei ve r " window
u d th . 1arge. ac Mw ledged F
i,r<,,rr "" rrceivr r, 11 f ~s following 11. emem e r tha t the re . e 15 r is damaged or lost. The ,ender unaware of th
31 tilt' _ rrect rarn k . ceiv n weve , · . · · rame 2.
8!Tl"'5 ,th all the co h d packets IO the networ 1aye r in sequen 1 g hond fame s until lhe time r fo r fr ame 2 expire<; Then . 1b·c; problem k· · continue., to
,-er d,1 \\ I ted to an W . ce. In se r J over with . 1t.. sen d .m g 2 . 3 . 4 . etc ' 1
ac > up to frame 1 d
JT'l."t'J ,. ,·er 1~ ob 1g~ _ ·pelining on error recove ry . e w ll] now all o ver again ~ an
~rn 1;11~ 1a. the efteclS ol pt exam. startS ale other
;.tt> "''(' !'OC genera l s tra tegy f o r handling errors~ when f . _
t:·
' t~ C'm e detail.
Th Wh . . rame, are pipe li ned '"
,nr11in ' -j called selective repe~t - e n It is used. _a bad frame that i, received ,.., d1,;card d
\\l\t\~D\\L!l\~~\Z}ft
ood frames recei ved afte r 1t are bu tfered . When the "·nd e
out g . . "' er times out. only·
est unacknowledged frame 1s retransmitted. If that frame
the Old . . am ves correctly.
the receiver can . deliver to . the ne twork _layer. in s;equence all the frames; it ha<;
buffered. Selective repea t 1s o ften combmed with having the receiver s,end a neo.
ative acknowledgement (NAK ) when it detects an error fo r ex.ample. when r;-
11
1;J')j ' 0 0 0 0 0 0 [a] 0 [iJ
ceives a checksum error or a frame out of sequence. ~AK., ,ti mu late retran\mi,;-
sion before the corresponding timer expi res and thus improve performance.
In fig . 3-16(b), frames O and L are again correctl y received and acknowledeed
Erro( Frames discarded by data link layer
and frame 2 is los!. When frame 3 arrives at the recei ver. the data link ]aver th~re
Time--- notices that is has missed a fr ame. so it sends back a '.'iAK fo r : but buf~er; 3.
When frames 4 and 5 arrive, the y, too. are buffered by the data mk layer m,tead
(a)
of being passed to the network layer. Eventually. the ~ .\K 2 gets back to the
sender, which immediately resend s frame 2. When that arm e~. the Jata li nk !aver
now has 2, 3, 4, and 5 and can pass a ll of them to the network layer in the corr'ect
... - ~ ~,~ -~
li:'if./'xi;<&3/-}!)X/:{ ~
5 order. It can also acknowledge all frames up to and including 5. as ... hown m the
figure. If the NAK should get lo st, e ve ntually the sender ..... ill ume ou1 fo r frame 2
~~\'f'\~,
I~ I~ I~ / and send it (and only it) of its own accord. but that may be a qmte J. whil e later.
,~~
, 1\.: ~ ~ ~ "<'~ "<'~ In effect, the NAK speeds up the retransmission of one ..,pec1fic fnme
C
r THE DATA LI NKLAYER
I* should be 2 ' n - 1 */
. ime
CHAP. 3
iy
trans~.
c et tos,-,
.,_
SEC. 3.4
whil e (true) {
waiL fo r _eve nt(&event) ;
switc h(event) {
SLfDf NG WINDOW PROTOCOLS
f* the network
' r ,ties: see evenLtype above •!
1
I* Accept, save , and transmit a new frame .,,1 ayer has a packet to send•/
221
5eq_nr next__frame Jo_send· case timeout: 1- troubl e; retransmit all ourstanamg frames • 1
S€(;J1r aeicexpecied· , I• MAX_SEQ > 1; used for outbound st ream· nexLframe_to_s end = ack_expected ; * start retransmitting here •
5eq_r.r l:arne _expect , d· f* oldest frame as yet unacknowledged• , • for (i = 1 ; i <= nbuff e red ; i++ ) {
frame r: e,
I• next frame expected on inbound strearn send_data(next_ frame_to_send, frame_expectea, buffer),, .. resend frame ..,
Dael.et outte~MAX 1
!'.eQ..ru nbuftered· SEQ ➔ 1]; I• scratch variable •/ inc(next_frame_ to_send); I- prepare to send the next one •
~ nr, , /• buffers for the outbound stream •/
'='t!nt t~ I• # output buffers currently in use •/
· - ,..., ev1:nt;
1* used to index into the buffer array •1
eri2b!c r etwor1,
ac~ e ~e . _ Jayf:r( J. if (nbuttere d <: MAX_SEQ )
ne~ f o. O·
fram1; 7irne
ex
10 ,.
aenrj " 0 ~: allow network_layer _ ready events •/ enable_ n e twork_ laye r() ;
else
ribvtt Pee1ea ·" o · next ack expected inbound *1
t rea " 0. ,
I• next frame going out *I d ,f ) d is a b le_ n e two rk_la ye r() ;
1
" nu mber of frame expected inboun )
/• initially no packets are buffered •/