CCN M5 Notes1
CCN M5 Notes1
e5:Tr
anspor
tlayer
MODULE5
1)Whatar
ethedi
ff
erentser
vicespr
ovi
dedbyt
het
ranspor
tlayer
?
1.Pr
ocess-
to-
ProcessCommuni
cat
ion
Thef
ir
stdut
yofat
ranspor
t-
layerpr
otocoli
stopr
ovi
depr
ocess-
to-
process
communi
cat
ion.Apr
ocessi
sanappl
icat
ion-
layerent
it
y(r
unni
ngpr
ogr
am)t
hat
usest
heser
vicesoft
het
ranspor
tlayer
.Thenet
wor
klayer i
sresponsi
blef
or
communi
cat
ionatt
hecomput
erl
evel(
host
-t
o-hostcommuni
cat
ion)
.Anet
wor
k-
l
ayerpr
otocolcan del
ivert
he message onl
ytot
he dest
inat
ion comput
er.
However
,thi
sisani
ncompl
etedel
iver
y.Themessagest
il
lneedst
obehanded
t
othecor
rectpr
ocess.Thi
siswher
eat
ranspor
t-
layerpr
otocolt
akesover
.A
t
ranspor
t-
layerpr
otocoli
sresponsi
blef
ordel
iver
y oft
he message t
othe
appr
opr
iat
e pr
ocess.Fi
gur
e shows t
he domai
ns ofa net
wor
klayerand a
t
ranspor
tlayer
.
Fi
gur
e1:Net
wor
klayerver
sust
ranspor
tlayer
2.Encapsul
ati
onandDecapsul
ati
on
Tosendamessagef
rom onepr
ocesst
oanot
her
,thet
ranspor
t-
layerpr
otocol
encapsul
atesanddecapsul
atesmessages(
Figur
e2)
.Encapsul
ati
onhappensat
t
hesendersi
te.Whenapr
ocesshasamessaget
osend,
itpassest
hemessage
t
othet
ranspor
tlayeral
ongwi
thapai
rofsocketaddr
essesandsomeot
her
pi
eces ofi
nfor
mat
ion,whi
ch depend on t
he t
ranspor
t-
layerpr
otocol
.The
t
ranspor
tlayerr
ecei
vest
hedat
a and addst
het
ranspor
t-
layerheader
.The
packet
s att
he t
ranspor
tlayeri
nthe I
nter
netar
e cal
led userdat
agr
ams,
segment
s,orpacket
s,dependi
ngonwhatt
ranspor
t-
layerpr
otocolweuse.I
n
Dept
.ofECE,
RNSI
TPage1
CCNModul
e5:Tr
anspor
tlayer
gener
al,
tr
anspor
t-
layerpayl
oadsar
ecal
ledaspacket
s.
Decapsul
ati
onhappensatt
her
ecei
versi
te.Whent
hemessagear
ri
vesatt
he
dest
inat
ion t
ranspor
tlayer
,the headeri
s dr
opped and t
he t
ranspor
tlayer
del
iver
sthemessaget
othepr
ocessr
unni
ngatt
heappl
icat
ionl
ayer
.Thesender
socketaddr
essi
spassedt
othepr
ocessi
ncasei
tneedst
orespondt
othe
messager
ecei
ved.
Fi
gur
e2:Encapsul
ati
onanddecapsul
ati
on
3.Mul
ti
plexi
ngandDemul
ti
plexi
ng
Wheneveran ent
it
y accept
sit
ems f
rom mor
ethan one sour
ce,t
hisi
s
r
efer
redt
oasmul
ti
plexi
ng(
manyt
oone)
;wheneveranent
it
ydel
iver
sit
emst
o
mor
ethanonesour
ce,t
hisi
sref
err
edt
oasdemul
ti
plexi
ng(
onet
omany)
.The
t
ranspor
tlayeratt
hesour
ceper
for
msmul
ti
plexi
ng;t
het
ranspor
tlayeratt
he
dest
inat
ionper
for
msdemul
ti
plexi
ng
Fi
gur
e3 showscommuni
cat
ion bet
ween acl
ientand t
wo ser
ver
s.
Thr
eecl
ientpr
ocessesar
erunni
ng att
hecl
ientsi
te,P1,P2,and P3.The
pr
ocesses P1 and P3 need t
o send r
equest
stot
he cor
respondi
ng ser
ver
pr
ocessr
unni
ngi
naser
ver
.Thecl
ientpr
ocessP2needst
osendar
equestt
o
t
hecor
respondi
ngser
verpr
ocessr
unni
ngatanot
herser
ver
.Thet
ranspor
tlayer
att
hecl
ientsi
teaccept
sthr
eemessagesf
rom t
het
hreepr
ocessesandcr
eat
es
t
hreepacket
s.I
tact
sasamul
ti
plexer
.Thepacket
s1and3uset
hesamel
ogi
cal
channelt
oreacht
het
ranspor
tlayeroft
hef
ir
stser
ver
.Whent
heyar
ri
veatt
he
ser
ver
,thet
ranspor
tlayerdoest
hej
obofademul
ti
plexeranddi
str
ibut
est
he
messagest
otwodi
ff
erentpr
ocesses.Thet
ranspor
tlayeratt
hesecondser
ver
r
ecei
vespacket2anddel
iver
sitt
othecor
respondi
ngpr
ocess.Not
ethatwest
il
l
Dept
.ofECE,
RNSI
TPage2
CCNModul
e5:Tr
anspor
tlayer
havedemul
ti
plexi
ngal
thought
her
eisonl
yonemessage.
Fi
gur
e3:Mul
ti
plexi
nganddemul
ti
plexi
ng
4.Fl
owCont
rol
Wheneveranent
it
ypr
oducesi
temsandanot
herent
it
yconsumest
hem,
ther
e
shoul
dbeabal
ancebet
weenpr
oduct
ionandconsumpt
ionr
ates.I
fthei
tems
ar
e pr
oduced f
ast
ert
han t
hey can be consumed,t
he consumercan be
over
whel
medandmayneedt
odi
scar
dsomei
tems.I
fthei
temsar
epr
oduced
mor
esl
owl
ythant
heycanbeconsumed,t
heconsumermustwai
t,andt
he
syst
em becomesl
essef
fi
cient
.Fl
owcont
roli
srel
atedt
othef
ir
sti
ssue.Weneed
t
opr
eventl
osi
ngt
hedat
ait
emsatt
heconsumersi
te.
Pushi
ngorPul
li
ng
Del
iver
yofi
temsf
rom apr
oducert
oaconsumercanoccuri
noneoft
woways:
pushi
ng orpul
li
ng.I
fthesenderdel
iver
sit
emswhenevert
heyar
epr
oduced
wi
thoutapr
iorr
equestf
rom t
heconsumert
hedel
iver
yisr
efer
r oaspushi
edt ng.
I
fthepr
oducerdel
iver
sthei
temsaf
tert
heconsumerhasr
equest
edt
hem,t
he
del
iver
yisr
efer
r oaspul
edt li
ng.Fi
gur
e4showst
heset
wot
ypesofdel
iver
y.
Dept
.ofECE,
RNSI
TPage3
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e4:Pushi
ngorpul
li
ng
Fl
owCont
rolatTr
anspor
tLayer
I
ncommuni
cat
ionatt
het
ranspor
tlayer
,wear
edeal
ingwi
thf
ourent
it
ies:
senderpr
ocess,sendert
ranspor
tlayer
,recei
vert
ranspor
tlayer
,and r
ecei
ver
pr
ocess.The sendi
ng pr
ocess att
he appl
icat
ion l
ayeri
s onl
y a pr
oducer
.It
pr
oducesmessagechunksandpushest
hem t
othet
ranspor
tlayer
.
Thesendi
ngt
ranspor
tlayerhasadoubl
erol
e:I
tisbot
haconsumeranda
pr
oducer
.Itconsumest
hemessagespushedbyt
hepr
oducer
.Itencapsul
atest
he
messages i
n packet
s and pushes t
hem t
othe r
ecei
ving t
ranspor
tlayer
.The
r
ecei
vingt
ranspor
tlayeral
sohasadoubl
erol
e:i
tist
heconsumerf
ort
hepacket
s
r
ecei
vedf
rom t
hesenderandt
hepr
oducert
hatdecapsul
atest
hemessagesand
del
iver
sthem t
otheappl
icat
ionl
ayer
.Thel
astdel
iver
y,however
,isnor
mal
lya
pul
li
ngdel
iver
y;t
het
ranspor
tlayerwai
tsunt
ilt
heappl
icat
ion-
layerpr
ocessasksf
or
messages.
Fi
gur
e5showst
hatweneedatl
eastt
wocasesoff
low cont
rol
:fr
om t
he
sendi
ngt
ranspor
tlayert
othesendi
ngappl
icat
ionl
ayerandf
rom t
her
ecei
ving
t
ranspor
tlayert
othesendi
ngt
ranspor
tlayer
.
Fi
gur
e5:Fl
owcont
rolatt
het
ranspor
tlayer
5.Er
rorCont
rol
I
ntheI
nter
net
,si
ncet
heunder
lyi
ngnet
wor
klayer(
IP)i
sunr
eli
abl
e,weneedt
o
Dept
.ofECE,
RNSI
TPage4
CCNModul
e5:Tr
anspor
tlayer
maket
het
ranspor
tlayerr
eli
abl
eift
heappl
icat
ionr
equi
resr
eli
abi
li
ty.Rel
iabi
li
ty
canbeachi
evedt
oadder
rorcont
rolser
vicest
othet
ranspor
tlayer
.Er
rorcont
rol
att
het
ranspor
tlayeri
sresponsi
blef
or
1.Det
ect
inganddi
scar
dingcor
rupt
edpacket
s.
2.Keepi
ngt
rackofl
ostanddi
scar
dedpacket
sandr
esendi
ngt
hem.
3.Recogni
zingdupl
icat
epacket
sanddi
scar
dingt
hem.
4.Buf
fer
ingout
-of
-or
derpacket
sunt
ilt
hemi
ssi
ngpacket
sar
ri
ve.
Er
rorcont
rol
,unl
i
kef
low cont
rol
,invol
vesonl
ythesendi
ngandr
ecei
ving
t
ranspor
tlayer
s.Assumet
hatt
hemessagechunksexchangedbet
weent
he
appl
icat
ionandt
ranspor
tlayer
sar
eer
rorf
ree.Fi
gur
e6showst
heer
rorcont
rol
bet
weent
hesendi
ngandr
ecei
vingt
ranspor
tlayer
s.Aswi
tht
hecaseoff
low
cont
rol
,ther
ecei
vingt
ranspor
tlayermanageser
rorcont
rol
,mostoft
het
ime,
by
i
nfor
mingt
hesendi
ngt
ranspor
tlayeraboutt
hepr
obl
ems.
Fi
gur
e6:Er
rorcont
rolatt
het
ranspor
tlayer
SequenceNumber
s
Er
rorcont
rolr
equi
rest
hatt
hesendi
ngt
ranspor
tlayerknowswhi
chpacketi
s
t
ober
esentandt
her
ecei
vingt
ranspor
tlayerknowswhi
chpacketi
sadupl
icat
e,or
whi
ch packethas ar
ri
ved outofor
der
.Thi
s can be done i
fthe packet
s ar
e
number
ed.Wecanaddaf
iel
dtot
het
ranspor
t-
layerpackett
ohol
dthesequence
numberoft
hepacket
.Whenapacketi
scor
rupt
edorl
ost
,ther
ecei
vingt
ranspor
t
l
ayercansomehowi
nfor
mthesendi
ngt
ranspor
tlayert
oresendt
hatpacketusi
ng
t
hesequencenumber
.Ther
ecei
ving t
ranspor
tlayercan al
so det
ectdupl
icat
e
packet
sift
wor
ecei
vedpacket
shavet
hesamesequencenumber
.Theout
-of
-or
der
packet
scanber
ecogni
zedbyobser
vinggapsi
nthesequencenumber
s.Packet
s
ar
enumber
edsequent
ial
ly.However
,becauseweneedt
oincl
udet
hesequence
numberofeachpacketi
ntheheader
,weneedt
osetal
imi
t.I
ftheheaderoft
he
packetal
lowsm bi
tsf
ort
hesequencenumber
,thesequencenumber
srangef
rom 0
o2m -
t 1.
Dept
.ofECE,
RNSI
TPage5
CCNModul
e5:Tr
anspor
tlayer
Forexampl fm i
e,i s4,t
heonl
ysequencenumber
sar
e0t
hrough15,i
ncl
usi
ve.
However
,we
canwr
apar
oundt
hesequence.Sot
hesequencenumber
sint
hiscasear
e
I
not
herwor
ds,
thesequencenumber
sar o2m.
emodul
Acknowl
edgment
The r
ecei
versi
de can send an acknowl
edgment(
ACK)f
oreach ofa
col
lect
ionofpacket
sthathavear
ri
vedsaf
eandsound.Ther
ecei
vercansi
mpl
y
di
scar
dthecor
rupt
edpacket
s.Thesendercandet
ectl
ostpacket
sifi
tusesat
imer
.
Whenapacketi
ssent
,thesenderst
art
sat
imer
.IfanACKdoesnotar
ri
vebef
ore
t
het
imerexpi
res,t
hesenderr
esendst
hepacket
.Dupl
icat
epacket
scanbesi
lent
ly
di
scar
dedbyt
her
ecei
ver
.Out
-of
-or
derpacket
scanbeei
therdi
scar
ded(
tobe
t
reat
edasl
ostpacket
sbyt
hesender
),orst
oredunt
ilt
hemi
ssi
ngonear
ri
ves.
6.Congest
ionCont
rol
Congest
ioni
nanet
wor
kmayoccuri
fthel
oadont
henet
wor
k—t
henumberof
packet
ssentt
othenet
wor
kisgr
eat
ert
hant
hecapaci
tyoft
henet
wor
k,t
henumber
ofpacket
sanet
wor
kcanhandl
e.Congest
ioncont
rolr
efer
stot
hemechani
smsand
t
echni
quest
hatcont
rolt
hecongest
ionandkeept
hel
oadbel
owt
hecapaci
ty.
Congest
ion happens i
n anysyst
em t
hati
nvol
ves wai
ti
ng.Forexampl
e,
congest
ionhappensonaf
reewaybecauseanyabnor
mal
it
yint
hef
low,
suchasan
acci
dent dur
ing r
ush hour
,cr
eat
es bl
ockage.Congest
ion i
n a net
wor
k or
i
nter
net
wor
koccur
sbecauser
out
ersandswi
tcheshavequeues—buf
fer
sthathol
d
t
hepacket
sbef
oreandaf
terpr
ocessi
ng.Ar
out
er,f
orexampl
e,hasani
nputqueue
andanout
putqueuef
oreachi
nter
face.I
far
out
ercannotpr
ocesst
hepacket
sat
t
hesamer
ateatwhi
cht
heyar
ri
ve,t
hequeuesbecomeover
loadedandcongest
ion
occur
s.Congest
ionatt
het
ranspor
tlayeri
sact
ual
lyt
her
esul
tofcongest
ionatt
he
net
wor
klayer
,whi
chmani
fest
sit
sel
fatt
het
ranspor
tlayer
.
2)Expl
aint
heconceptofsl
idi
ngwi
ndowwi
thaneatdi
agr
am.
Sl
idi
ngWi
ndow
Si
nce t
he sequence number o 2m,a ci
s use modul rcl
e can r
epr
esentt
he
sequencenumber
sfr o2m −1(
om 0t Figur
e7)
.Thebuf
feri
srepr
esent
edasa
setofsl
ices,cal
l hesl
edt idi
ngwi
ndow,t
hatoccupi
espar
toft
heci
rcl
eatany
Dept
.ofECE,
RNSI
TPage6
CCNModul
e5:Tr
anspor
tlayer
t
ime.Att
hesendersi
te,whenapacketi
ssent
,thecor
respondi
ngsl
icei
s
mar
ked.Whenal
lthesl
icesar
emar
ked,i
tmeanst
hatt
hebuf
feri
sful
landno
f
urt
hermessagescanbeaccept
edf
rom t
heappl
icat
ionl
ayer
.
Whenanacknowl
edgmentar
ri
ves,t
hecor
respondi
ngsl
icei
sunmar
ked.I
f
someconsecut
ivesl
icesf
rom t
hebegi
nni
ngoft
hewi
ndow ar
eunmar
ked,t
he
wi
ndowsl
idesovert
her
angeoft
hecor
respondi
ngsequencenumber
stoal
low
mor
efr
eesl
icesatt
heendoft
hewi
ndow.Fi
gur
e7showst
hesl
idi
ngwi
ndowat
t
hesender
.Thesequencenumber
sar
einmodul m =4)andt
o16( hesi
zeoft
he
wi
ndowi
s7.Thesl
idi
ngwi
ndowi
sjustanabst
ract
ion:t
heact
ualsi
tuat
ionuses
comput
ervar
iabl
est
ohol
dthesequencenumber
soft
henextpackett
obesent
andt
hel
astpacketsent
.
Fi
gur
e7:Sl
idi
ngwi
ndowi
nci
rcul
arf
ormat
Mostpr
otocol
sshowt
hesl
idi
ngwi
ndowusi
ngl
inearr
epr
esent
ati
on.Thei
deai
s
t
he same,buti
tnor
mal
lyt
akes l
ess space on paper
.Fi
gur
e 8 shows t
his
r
epr
esent
ati
on.
Dept
.ofECE,
RNSI
TPage7
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e8:Sl
idi
ngwi
ndowi
nli
nearf
ormat
3.Wr
it
eout
li
neandexpl
ainsendwi
ndow andr
ecei
vewi
ndow f
orGobackN
pr
otocol
/sel
ect
iver
epeatpr
otocol
.
Go-
BackNpr
otocol
Toi
mpr
ovet
heef
fi
ciencyoft
ransmi
ssi
on(
tof
il
lthepi
pe)
,mul
ti
plepacket
s
mustbei
ntr
ansi
ti
onwhi
let
hesenderi
swai
ti
ngf
oracknowl
edgment
.Inot
her
wor
ds,
weneedt
oletmor
ethanonepacketbeout
standi
ngt
okeept
hechannel
busywhi
let
hesenderi
swai
ti
ngf
oracknowl
edgment
.Oneoft
hepr
otocoli
s
cal
led Go-
Back-
N(GBN)
.Thekeyt
oGo- Ni
back- st
hatwecansendsever
al
packet
sbef
orer
ecei
vingacknowl
edgment
s,butt
her
ecei
vercanonl
ybuf
fer
onepacket
.Wekeepacopyoft
hesentpacket
sunt
ilt
heacknowl
edgment
s
ar
ri
ve.Fi
gur
e9showst
heout
li
neoft
hepr
otocol
.
Dept
.ofECE,
RNSI
TPage8
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e9:Go-
Back-
Npr
otocol
SendWi
ndow
Thesendwi
ndowi
sani
magi
nar
yboxcover
ingt
hesequencenumber
soft
he
dat
apacket
sthatcanbei
ntr
ansi
torcanbesent
.Ineachwi
ndowposi
ti
on,
someof
t
hesequencenumber
sdef
inet
hepacket
sthathavebeensent
;ot
her
sdef
inet
hose
t
hatcanbesent
.Themaxi
mum si
zeoft
hewi s2m -1,
ndowi wel
ett
hesi
zebef
ixed
andsett
othemaxi
mum val
ue,Fi
gur
e10showsasl
idi
ngwi
ndowofsi
ze7(
m =3)
f
ort
heGo-
Back-
Npr
otocol
.
Fi
gur
e10:Sendwi
ndowf
orGo-
Back-
N
Thesendwi
ndow atanyt
imedi
videst
hepossi
blesequencenumber
sint
o
f
ourr
egi
ons.Thef
ir
str
egi
on,l
eftoft
hewi
ndow,def
inest
hesequencenumber
s
bel
ongi
ngt
opacket
sthatar
eal
readyacknowl
edged.Thesenderdoesnotwor
ry
aboutt
hesepacket
sandkeepsnocopi
esoft
hem.Thesecondr
egi
on,col
ored,
def
inest
her
angeofsequencenumber
sbel
ongi
ngt
othepacket
sthathavebeen
sent
,buthaveanunknownst
atus.Thesenderneedst
owai
ttof
indouti
fthese
packet
shavebeenr
ecei
vedorwer
elost
.Thesear
ecal
ledasout
standi
ngpacket
s.
Thet
hir
drange,whi
tei
nthef
igur
e,def
inest
her
angeofsequencenumber
sfor
packet
sthatcanbesent
;however
,thecor
respondi
ngdat
ahavenotyetbeen
r
ecei
vedf
rom t
heappl
icat
ionl
ayer
.Fi
nal
ly,t
hef
our
thr
egi
on,r
ightoft
hewi
ndow,
def
inessequencenumber
sthatcannotbeusedunt
ilt
hewi
ndowsl
ides.
Dept
.ofECE,
RNSI
TPage9
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e11:Sl
idi
ngt
hesendwi
ndow
Fi
gur
e11showshowasendwi
ndowcansl
ideoneormor
esl
otst
other
ight
when an acknowl
edgment ar
ri
ves f
rom t
he ot
her end. I
n t
he f
igur
e,an
acknowl
edgmentwi
thack
No = 6 hasar
ri
ved.Thi
smeanst
hatt
her
ecei
veri
swai
ti
ng f
orpacket
swi
th
sequenceno6.
Recei
veWi
ndow
Ther
ecei
vewi
ndow makessur
ethatt
hecor
rectdat
apacket
sar
erecei
ved
andt
hatt
hecor
rectacknowl
edgment
sar
esent
.InGo-
Back-
N,t
hesi
zeoft
he
r
ecei
vewi
ndow i
sal
ways1.Ther
ecei
veri
sal
waysl
ooki
ngf
ort
hear
ri
valofa
speci
fi
cpacket
.Anypacketar
ri
vingoutofor
deri
sdi
scar
dedandneedst
obe
r
esent
.Fi
gur
e12showst
her
ecei
vewi
ndow.I
tneedsonl
yonevar
iabl
e,Rn(
recei
ve
wi
ndow,nextpacketexpect
ed)
,todef
inet
hisabst
ract
ion.Thesequencenumber
s
t
othel
eftoft
hewi
ndowbel
ongt
othepacket
sal
readyr
ecei
vedandacknowl
edged;
t
hesequencenumber
stot
her
ightoft
hiswi
ndowdef
inet
hepacket
sthatcannotbe
r
ecei
ved.Anyr
ecei
vedpacketwi
thasequencenumberi
ntheset
wor
egi
onsi
s
di
scar
ded.Onl
yapacketwi
thasequencenumbermat
chi
ngt
heval
ueofRni
s
accept
edandacknowl
edged.Ther
ecei
vewi
ndowal
sosl
ides,
butonl
yonesl
otata
t
ime.Whenacor
rectpacketi
srecei
ved,
thewi
ndowsl
ides,
Rn=( o2m.
Rn+1)modul
Dept
.ofECE,
RNSI
TPage10
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e12:Recei
vewi
ndowf
orGo-
Back-
N
FSMs
Fi
gur
e13showst
heFSMsf
ort
heGBNpr
otocol
.
Sender
Thesenderst
art
sint
her
eadyst
ate,
butt
her
eaf
teri
tcanbei
noneoft
het
wost
ates:
r
eadyorbl
ocki
ng.Thet
wovar
iabl
esar
enor
mal
l
yini
ti
ali
zedt
o0(
Sf=Sn=0)
.
Readyst
ate.Fourevent
smayoccurwhent
hesenderi
sinr
eadyst
ate.
a.I
far
equestcomesf
rom t
heappl
icat
ionl
ayer
,thesendercr
eat
esapacketwi
th
t
hesequence numbersett
oSn.Acopyoft
hepacketi
sst
ored,andt
hepacket
i
ssent
.Thesenderal
sost
art
stheonl
yti
meri
fiti
snotr
unni
ng.Theval
ueofSn
i
snow i
ncr
ement
ed,( o2m.I
Sn=Sn+1)modul fthewi
ndow i
sful
l,Sn=(
Sf+
Ssi o2m,
ze)modul thesendergoest
othebl
ocki
ngst
ate.
b.I
fan er
ror
-f
ree ACK ar
ri
ves wi
th ackNo r
elat
ed t
o one oft
he out
standi
ng
packet
s,t
hesendersl
idest
hewi
ndow (
setSf=ackNo)
,andi
fal
lout
standi
ng
packet
s ar
e acknowl
edged (
ackNo = Sn)
,then t
he t
imeri
s st
opped.I
fal
l
out
standi
ngpacket
sar
enotacknowl
edged,
thet
imeri
srest
art
ed.
c.I
facor
rupt
edACK oraner
ror
-f
reeACK wi
thacknumbernotr
elat
edt
othe
out
standi
ngpacketar
ri
ves,
iti
sdi
scar
ded.
d.I
fat
ime-
outoccur
s,t
hesenderr
esendsal
lout
standi
ngpacket
sandr
est
art
sthe
t
imer
.
Bl
ocki
ngst
ate.Thr
eeevent
smayoccuri
nthi
scase:
a.I
faner
ror
-f
reeACKar
ri
veswi
thackNor
elat
edt
ooneoft
heout
standi
ngpacket
s,
t
hesendersl
idest
hewi
ndow(
setSf=ackNo)andi
fal
lout
standi
ngpacket
sar
e
acknowl
edged(
ackNo=Sn)
,thent
het
imeri
sst
opped.I
fal
lout
standi
ngpacket
s
Dept
.ofECE,
RNSI
TPage11
CCNModul
e5:Tr
anspor
tlayer
ar
enotacknowl
edged,
thet
imeri
srest
art
ed.Thesendert
henmovest
other
eady
st
ate.
b.I
facor
rupt
ed ACK oran er
ror
-f
reeACK wi
tht
heackNo notr
elat
ed t
othe
out
standi
ngpacket
sar
ri
ves,
theACKi
sdi
scar
ded.
c.I
fat
ime-
outoccur
s,t
hesendersendsal
lout
standi
ngpacket
sandr
est
art
sthe
t
imer
.
Fi
gur
e13FSMsf
ort
heGo-
Back-
Npr
otocol
Recei
ver
Ther
ecei
veri
sal
waysi
nther
eadyst
ate.Theonl
yvar
iabl
e,Rn,i
sini
ti
ali
zedt
o0.
Thr
eeevent
smayoccur
:
a.I
faner
ror
-f
reepacketwi
thseqNo=Rnar
ri
ves,t
hemessagei
nthepacketi
s
del
iver
ed
Dept
.ofECE,
RNSI
TPage12
CCNModul
e5:Tr
anspor
tlayer
t
otheappl
icat
ionl
ayer
.Thewi
ndowt
hensl
ides,
Rn=(
Rn+1)modul
o2m.
Fi
nal
lyanACKi
ssentwi
thackNo=Rn.
b.I
faner
ror
-f
reepacketwi
thseqNoout
sidet
hewi
ndow ar
ri
ves,t
hepacketi
s
di
scar
ded,
butanACKwi
thackNo=Rni
ssent
.
c.I
facor
rupt
edpacketar
ri
ves,
iti
sdi
scar
ded.
SendWi
ndowSi
ze
Thesi
zeoft
hesendwi
ndowmustbel han2m i
esst sbecausef
orexampl
e,choose
m =2,
whi
chmeanst
hesi
zeoft ndowcanbe2m -1,
hewi or3.Fi
gur
e14compar
es
awi
ndowsi
zeof3agai
nstawi
ndowsi
zeof4.I
fthesi
zeoft
hewi
ndowi
s3(
less
han2m)andal
t lthr
eeacknowl
edgment
sar
elost
,theonl
yti
merexpi
resandal
lthr
ee
packet
sar
eresent
.Ther
ecei
veri
snow expect
ingpacket3,notpacket0,sot
he
dupl
icat
epacketi
scor
rect
lydi
scar
ded.Ont
heot
herhand,
ift
hesi
zeoft
hewi
ndow
i
s4(
equalt
o22)andal
lacknowl
edgment
sar
elost
,thesenderwi
llsendadupl
icat
e
ofpacket0.However
,thi
sti
met
hewi
ndowoft
her
ecei
verexpect
stor
ecei
vepacket
0(
int
henextcycl
e),soi
taccept
spacket0,notasadupl
icat
e,butast
hef
ir
st
packeti
nthenextcycl
e.Thi
sisaner
ror
.Thi
sshowst
hatt
hesi
zeoft
hesend
wi
ndowmustbel han2m.
esst
Fi
gur
e14Sendwi
ndowsi
zef
orGo-
Back-
N
Exampl
e1
Dept
.ofECE,
RNSI
TPage13
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e15showsanexampl
eofGo- N.Thi
Back- sisanexampl
eofacasewher
ethe
f
orwar
dchanneli
srel
iabl
e,butt
her
ever
sei
snot
.Nodat
apacket
sar
elost
,but
someACKsar
edel
ayedandonei
slost
.Theexampl
eal
soshowshowcumul
ati
ve
acknowl
edgment
scanhel
pifacknowl
edgment
sar
edel
ayedorl
ost
.
Fi
gur
e15:Fl
owdi
agr
am f
orExampl
e1
Af
teri
nit
ial
izat
ion,t
her
e ar
e some senderevent
s.Requestevent
s ar
e
t
ri
gger
edbymessagechunksf
rom t
heappl
icat
ionl
ayer
;ar
ri
valevent
sar
etr
igger
ed
byACKsr
ecei
vedf
rom t
henet
wor
klayer
.Ther
eisnot
ime-
outeventher
ebecause
al
lout
standi
ngpacket
sar
eacknowl
edgedbef
oret
het
imerexpi
res.Al
thoughACK2
i
slost
,ACK3i
scumul
ati
veandser
vesasbot
hACK2andACK3.Ther
ear
efour
event
satt
her
ecei
versi
te.
Exampl
e2
Fi
gur
e16showswhathappenswhenapacketi
slost
.Packet
s0,
1,2,
and3ar
esent
.
However
,packet1i
slost
.Ther
ecei
verr
ecei
vespacket
s2and3,butt
heyar
e
di
scar
dedbecauset
heyar
erecei
vedoutofor
der(
packet1i
sexpect
ed)
.Whent
he
r
ecei
verr
ecei
vespacket
s2and3,i
tsendsACK1t
oshowt
hati
texpect
stor
ecei
ve
packet1.However
,theseACKsar
enotusef
ulf
ort
hesenderbecauset
heackNoi
s
oSf,notgr
equalt eat hanSf
ert .Sot
hesenderdi
scar
dst
hem.Whent
het
ime-
out
Dept
.ofECE,
RNSI
TPage14
CCNModul
e5:Tr
anspor
tlayer
occur
s,t
hesenderr
esendspacket
s1,
2,and3,
whi
char
eacknowl
edged.
Go-
Back-
Nver
susSt
op-
and-
Wai
t
TheSt
op-
and-
Wai
tpr
otocoli
sact
ual
lyaGo-
Back-
Npr
otocoli
nwhi
cht
her
ear
eonl
y
t
wosequencenumber
sandt
hesendwi
ndowsi
zei
s1.I
not
herwor m =1and2m
ds,
−1=1.I
nGo-
Back-
N,wesai
dthatt
hear
it
hmet
ici o2m;i
smodul nSt
op-
and-
Wai
tit
i
smodul
o2,
whi
chi
sthesameas2m whenm =1.
Dept
.ofECE,
RNSI
TPage15
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e16:Fl
owdi
agr
am f
orExampl
e2
Sel
ect
ive-
RepeatPr
otocol
TheGo- N pr
Back- otocolsi
mpl
if
iest
hepr
ocessatt
her
ecei
ver
.Ther
ecei
ver
keepst
rackofonl
yonevar
iabl
e,andt
her
eisnoneedt
obuf
ferout
-of
-or
derpacket
s;
t
heyar
esi
mpl
ydi
scar
ded.However
,thi
spr
otocoli
sinef
fi
cienti
ftheunder
lyi
ng
net
wor
kpr
otocoll
osesal
otofpacket
s.Each t
imeasi
ngl
epacketi
slostor
cor
rupt
ed,t
hesenderr
esendsal
lout
standi
ngpacket
s,event
houghsomeoft
hese
packet
smayhavebeenr
ecei
vedsaf
eandsoundbutoutofor
der
.Ift
henet
wor
k
l
ayeri
slosi
ngmanypacket
sbecauseofcongest
ioni
nthenet
wor
k,t
her
esendi
ng
ofal
loft
heseout
standi
ngpacket
smakest
hecongest
ionwor
se,andevent
ual
ly
mor
epacket
sar
elost
.Thi
shasanaval
ancheef
fectt
hatmayr
esul
tint
het
otal
col
lapseoft
henet
wor
k.
Anot
herpr
otocol
,cal
led t
he Sel
ect
ive-
Repeat(
SR)pr
otocol
,has been
devi
sed,whi
ch,ast
henamei
mpl
ies,r
esendsonl
ysel
ect
ivepacket
s,t
hoset
hatar
e
act
ual
l
ylost
.
Theout
li
neoft
hispr
otocoli
sshowni
nFi
gur
e17.
Fi
gur
e17:
Out
li
neofSel
ect
ive-
Repeat
Wi
ndows
TheSel
ect
ive-
Repeatpr
otocolal
sousest
wowi
ndows:asendwi
ndowanda
r
ecei
ve wi
ndow.However
,ther
e ar
e di
ff
erences bet
ween t
he wi
ndows i
nthi
s
Dept
.ofECE,
RNSI
TPage16
CCNModul
e5:Tr
anspor
tlayer
pr
otocolandt
heonesi
nGo-
Back-
N.Fi
rst
,themaxi
mum si
zeoft
hesendwi
ndowi
s
muchsmal
ler
;i s2m-
ti 1.Ther
easonf
ort
hiswi
llbedi
scussedl
ater
.Second,t
he
r
ecei
vewi
ndowi
sthesamesi
zeast
hesendwi
ndow.
Thesendwi
ndow maxi zecanbe2m-
mum si 1.Forexampl
e,i
fm =4,t
he
sequencenumber
sgof
rom 0t
o15,butt
hemaxi
mum si
zeoft
hewi
ndowi
sjust8
(
iti
s15i
ntheGo-
Back-
N Pr
otocol
).TheSel
ect
ive-
Repeatsendwi
ndow i
nFi
gur
e
18.
1toemphasi
zet
hesi
ze.
Ther
ecei
vewi
ndowi
nSel
ect
ive-
Repeati
stot
all
ydi
ff
erentf
rom t
heonei
nGo
-
Back-
N.Thesi
zeoft
her
ecei
vewi
ndowi
sthesameast
hesi
zeoft
hesendwi
ndow
max2m-
( 1).TheSel
ect
ive-
Repeatpr
otocolal
lowsasmanypacket
sast
hesi
zeof
t
her
ecei
vewi
ndow t
o ar
ri
veoutofor
derand bekeptunt
ilt
her
eisasetof
consecut
ivepacket
stobedel
iver
edt
otheappl
icat
ionl
ayer
.Becauset
hesi
zesof
t
hesendwi
ndow andr
ecei
vewi
ndow ar
ethesame,al
lthepacket
sint
hesend
packetcan ar
ri
veoutofor
derand best
ored unt
ilt
heycan bedel
iver
ed.To
emphasi
zet
hati
nar
eli
abl
epr
otocolt
her
ecei
verneverdel
iver
spacket
soutof
or
dert
otheappl
icat
ionl
ayer
.
Fi
gur
e18.
2showst
her
ecei
vewi
ndow i
nSel
ect
ive-
Repeat
.Thosesl
otsi
nsi
det
he
wi
ndow t
hatar
eshadeddef
inepacket
sthathavear
ri
vedoutofor
derandar
e
wai
ti
ngf
ort
heear
li
ert
ransmi
tt
edpackett
oar
ri
vebef
oredel
iver
ytot
heappl
icat
ion
l
ayer
.
Fi
gur
e18.
1:Sendwi
ndowf
orSel
ect
ive-
Repeatpr
otocol
Dept
.ofECE,
RNSI
TPage17
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e18.
2:Recei
vewi
ndowf
orSel
ect
ive-
Repeatpr
otocol
Exampl
e3
Assumeasendersends6packet
s:packet
s0,
1,2,
3,4,
and5.Thesenderr
ecei
ves
anACKwi
thackNo=3.Whati
sthei
nter
pret
ati
oni
fthesyst
em i
susi
ngGBNorSR?
Sol
uti
on
I
fthesyst
em i
susi
ngGBN,i
tmeanst
hatpacket
s0,1,and2havebeenr
ecei
ved
uncor
rupt
edandt
her
ecei
veri
sexpect
ingpacket3.I
fthesyst
em i
susi
ngSR,i
t
meanst
hatpacket3hasbeenr
ecei
veduncor
rupt
ed;t
heACKdoesnotsayanyt
hing
aboutot
herpacket
s.
FSMs
Fi
gur
e19showst
heFSMsf
ort
heSel
ect
ive-
Repeatpr
otocol
.Iti
ssi
mil
art
othe
onesf
ort
heGBN,
butt
her
ear
esomedi
ff
erences.
Sender
Thesenderst
art
sint
her
eadyst
ate,butl
ateri
tcanbei
noneoft
het
wost
ates:
r
eadyorbl
ocki
ng.Thef
oll
owi
ngshowst
heevent
sandt
hecor
respondi
ngact
ionsi
n
eachst
ate.
Readyst
ate.Fourevent
smayoccuri
nthi
scase:
a.I
far
equestcomesf
rom t
heappl
icat
ionl
ayer
,thesendercr
eat
esapacketwi
th
t oSn.Acopyoft
hesequencenumbersett hepacketi
sst
ored,
andt
hepacketi
s
sent
.Ift
het
imeri
snotr
unni
ng,t
hesenderst
art
sthet
imer ueofSni
.Theval s
nowi
ncr
ement Sn=(
ed, Sn+1)modul
o2m.I
fthewi
ndowi
sful
lSn=(
, Sf+Ssi
ze)
o2m,
modul thesendergoest
othebl
ocki
ngst
ate.
b.I
faner
ror
-f
reeACKar
ri
veswi
thackNor
elat
edt
ooneoft
heout
standi
ngpacket
s,
Dept
.ofECE,
RNSI
TPage18
CCNModul
e5:Tr
anspor
tlayer
t
hat packeti
smar
kedasacknowl
edged.I
ftheackNo=Sf
,thewi
ndowsl
idest
o
t
her
ightunt
i heSfpoi
lt ntst
othef
ir
stunacknowl
edgedpacket(
allconsecut
ive
acknowl
edgedpacket
sar
enow out
sidet
hewi
ndow)
.Ift
her
ear
eout
standi
ng
packet
s,t
het
imeri
srest
art
ed;ot
her
wise,
thet
imeri
sst
opped.
c.I
facor
rupt
edACKoraner
ror
-f
reeACKwi
thackNonotr
elat
edt
oanout
standi
ng
packetar
ri
ves,
iti
sdi
scar
ded.
d.I
fat
ime-
outoccur
s,t
hesenderr
esendsal
lunacknowl
edgedpacket
sint
he
wi
ndowandr
est
art
sthet
imer
.
Bl
ocki
ngst
ate.Thr
eeevent
smayoccuri
nthi
scase:
a.I
faner
ror
-f
reeACKar
ri
veswi
thackNor
elat
edt
ooneoft
heout
standi
ngpacket
s,
t
hatpacketi
smar
kedasacknowl
edged.I
naddi
ti
on,i
ftheackNo= Sf
,the
wi
ndowi
ssl
idt
other
ightunt
i heSfpoi
lt ntst
othef
ir
stunacknowl
edgedpacket
(
allconsecut
iveacknowl
edged packet
sar
enow out
sidet
hewi
ndow)
.Ift
he
wi
ndow
hassl
id,
thesendermovest
other
eadyst
ate.
b.I
facor
rupt
edACKoraner
ror
-f
reeACKwi
tht
heackNonotr
elat
edt
oout
standi
ng
packet
sar
ri
ves,
theACKi
sdi
scar
ded.
c.I
fat
ime-
outoccur
s,t
hesenderr
esendsal
lunacknowl
edgedpacket
sint
he
wi
ndowand r
est
art
sthet
imer
.
Dept
.ofECE,
RNSI
TPage19
CCNModul
e5:Tr
anspor
tlayer
Recei
ver
Ther
ecei
veri
sal
waysi
nther
eadyst
ate.Thr
eeevent
smayoccur
:
a.I
faner
ror
-f
reepacketwi
thseqNoi
nthewi
ndowar
ri
ves,
thepacketi
sst
oredand
anACKwi
thackNo=seqNoi
ssent
.Inaddi
ti
on,i
ftheseqNo=Rn,t
hent
he
packetand al
lpr
evi
ousl
y ar
ri
ved consecut
ive packet
s ar
e del
iver
ed t
othe
appl
icat
ionl
ayerandt
hewi
ndowsl
idessot heRnpoi
hatt ntst
othef
ir
stempt
y
sl
ot.
Dept
.ofECE,
RNSI
TPage20
CCNModul
e5:Tr
anspor
tlayer
b.I
faner
ror
-f
reepacketwi
thseqNoout
sidet
hewi
ndow ar
ri
ves,t
hepacketi
s
di
scar
ded,
butanACKwi
thackNo=Rni
sret
urnedt
othesender
.Thi
sisneeded
t
olett
hesendersl
idei
tswi
ndowi
fsomeACKsr
elat
edt
opacket
swi
thseqNo<
Rnwer
elost
.
c.I
facor
rupt
edpacketar
ri
ves,
thepacketi
sdi
scar
ded.
Exampl
e4
Thi
sexampl
eissi
mil
art
oExampl
e2(
Figur
e16)i
nwhi
chpacket1i
slost
.Sel
ect
ive-
Repeatbehavi
ouri
sshowni
nthi
scase.Fi
gur
e19showst
hesi
tuat
ion.
Fi
gur
e19:Fl
owdi
agr
am f
orExampl
e4
Att
hesender
,packet0i
str
ansmi
tt
edandacknowl
edged.Packet1i
slost
.
Packet
s2and3ar
ri
veoutofor
derandar
eacknowl
edged.Whent
het
imert
imes
out
,packet1(
theonl
yunacknowl
edgedpacket
)isr
esentandi
sacknowl
edged.The
sendwi
ndowt
hensl
ides.
Att
her
ecei
versi
teweneedt
odi
sti
ngui
shbet
weent
heaccept
anceofa
packetandi
tsdel
iver
ytot
heappl
icat
ionl
ayer
.Att
hesecondar
ri
val
,packet2
Dept
.ofECE,
RNSI
TPage21
CCNModul
e5:Tr
anspor
tlayer
ar
ri
vesandi
sst
oredandmar
ked(
shadedsl
ot)
,buti
tcannotbedel
iver
edbecause
packet1i
smi
ssi
ng.Att
henextar
ri
val
,packet3ar
ri
vesandi
smar
kedandst
ored,
butst
il
lnoneoft
hepacket
scanbedel
iver
ed.Onl
yatt
hel
astar
ri
val
,whenf
inal
lya
copyofpacket1ar
ri
ves,canpacket
s1,2,and3bedel
iver
edt
otheappl
icat
ion
l
ayer
.Ther
ear
etwocondi
ti
onsf
ort
hedel
iver
yofpacket
stot
heappl
icat
ionl
ayer
:
Fi
rst
,asetofconsecut
ivepacket
smusthavear
ri
ved.Second,t
hesetst
art
sfr
om
t
hebegi
nni
ngoft
hewi
ndow.Af
tert
hef
ir
star
ri
val
,ther
ewasonl
yonepacketandi
t
st
art
edf
rom t
hebegi
nni
ngoft
hewi
ndow.Af
tert
hel
astar
ri
val
,ther
ear
ethr
ee
packet
sandt
hef
ir
stonest
art
sfr
om t
hebegi
nni
ngoft
hewi
ndow.Thekeyi
sthata
r
eli
abl
etr
anspor
tlayerpr
omi
sest
odel
iverpacket
sinor
der
.
Wi
ndowSi
zes
Wecannowshowwhyt
hesi
zeoft
hesenderand r
ecei
verwi
ndowscanbe
atmostone- fof2m.Foranexampl
hal e,wechoosem =2,
whi
chmeanst
hesi
zeof
t
hewi s2m/
ndowi 2or2(m−1)=2.Fi
gur
e23.
36compar
esawi
ndowsi
zeof2wi
tha
wi
ndowsi
zeof3.I
fthesi
zeoft
hewi
ndowi
s2andal
lacknowl
edgment
sar
elost
,
t
het
imerf
orpacket0expi
resandpacket0i
sresent
.However
,thewi
ndow oft
he
r
ecei
veri
snow expect
ing packet2,notpacket0,so t
hisdupl
icat
epacketi
s
cor
rect
lydi
scar
ded(
thesequencenumber0i
snoti
nthewi
ndow)
.Whent
hesi
zeof
t
hewi
ndowi
s3andal
lacknowl
edgment
sar
elost
,thesendersendsadupl
icat
eof
packet0.However
,thi
sti
me,
thewi
ndowoft
her
ecei
verexpect
stor
ecei
vepacket0
(
0ispar
toft
hewi
ndow)
,soi
taccept
spacket0,
notasadupl
icat
e,butasapacket
i
nthenextcycl
e.Thi
siscl
ear
lyaner
ror
.
4.Whatar
etheser
vicespr
ovi
dedbyUDP?Ment
ionanyf
ourt
ypi
calappl
icat
ionsof
UDP.
Pr
ocess-
to-
ProcessCommuni
cat
ion
UDP pr
ovi
des pr
ocess-
to-
process communi
cat
ion usi
ng socketaddr
esses,a
combi
nat
ionofI
Paddr
essesandpor
tnumber
s.
Connect
ionl
essSer
vices
UDPpr
ovi
desaconnect
ionl
essser
vice.Thi
smeanst
hateachuserdat
agr
am sent
byUDPi
sani
ndependentdat
agr
am.Ther
eisnor
elat
ionshi
pbet
weent
hedi
ff
erent
userdat
agr
amseveni
ftheyar
ecomi
ngf
rom t
hesamesour
cepr
ocessandgoi
ng
t
othesamedest
inat
ionpr
ogr
am.Theuserdat
agr
amsar
enotnumber
ed.Al
so,
Dept
.ofECE,
RNSI
TPage22
CCNModul
e5:Tr
anspor
tlayer
unl
ikeTCP,t
her
eisnoconnect
ionest
abl
ishmentandnoconnect
iont
ermi
nat
ion.
Thi
smeanst
hateachuserdat
agr
am cant
ravelonadi
ff
erentpat
h.Oneoft
he
r
ami
fi
cat
ionsofbei
ngconnect
ionl
essi
sthatt
hepr
ocesst
hatusesUDPcannot
sendast
ream ofdat
atoUDPandexpectUDPt
ochopt
hem i
ntodi
ff
erent
,rel
ated
userdat
agr
ams.I
nst
eadeachr
equestmustbesmal
lenought
ofi
tint
ooneuser
dat
agr
am.Onl
ythosepr
ocessessendi
ngshor
tmessages,messagesl
esst
han
65,
507byt
es(
65,
535mi
nus8byt
esf
ort
heUDPheaderandmi
nus20byt
esf
ort
he
I
Pheader
),canuseUDP.
Fl
owCont
rol
UDP i
saver
ysi
mpl
epr
otocol
.Ther
eisnof
low cont
rol
,andhencenowi
ndow
mechani
sm.Ther
ecei
vermayover
fl
owwi
thi
ncomi
ngmessages.Thel
ackoff
low
cont
rolmeanst
hatt
hepr
ocessusi
ngUDPshoul
dpr
ovi
def
ort
hisser
vice,
ifneeded.
Er
rorCont
rol
Ther
eisnoer
rorcont
rolmechani
sm i
nUDPexceptf
ort
hechecksum.Thi
smeans
t
hatt
hesenderdoesnotknowi
famessagehasbeenl
ostordupl
icat
ed.Whent
he
r
ecei
verdet
ect
san er
rort
hrough t
hechecksum,t
heuserdat
agr
am i
ssi
lent
ly
di
scar
ded.Thel
ackofer
rorcont
rolmeanst
hatt
hepr
ocessusi
ngUDP shoul
d
pr
ovi
def
ort
hisser
vice,
ifneeded.
Checksum
UDP checksum cal
cul
ati
on i
ncl
udest
hreesect
ions:a pseudoheader
,theUDP
header
,andt
hedat
acomi
ngf
rom t
heappl
icat
ionl
ayer
.Thepseudoheaderi
sthe
par
toft
heheaderoft
heI
Ppacketi
nwhi
cht
heuserdat
agr
am i
stobeencapsul
ated
wi
thsomef
iel
dsf
il
ledwi
th0s(
seeFi
gur
e20)
.
Fi
gur
e20:Pseudoheaderf
orchecksum cal
cul
ati
on
Dept
.ofECE,
RNSI
TPage23
CCNModul
e5:Tr
anspor
tlayer
I
fthechecksum doesnoti
ncl
udet
hepseudoheader
,auserdat
agr
am may
ar
ri
vesaf
eandsound.However
,ift
heI
Pheaderi
scor
rupt
ed,
itmaybedel
iver
edt
o
t
hewr
onghost
.Thepr
otocolf
iel
disaddedt
oensur
ethatt
hepacketbel
ongst
o
UDP,
andnott
oTCP.Wewi
llseel
atert
hati
fapr
ocesscanuseei
therUDPorTCP,
t
hedest
inat
ionpor
tnumbercanbet
hesame.Theval
ueoft
hepr
otocolf
iel
dfor
UDPi
s17.I
fthi
sval
uei
schangeddur
ingt
ransmi
ssi
on,t
hechecksum cal
cul
ati
on
att
her
ecei
verwi
lldet
ecti
tandUDPdr
opst
hepacket
.Iti
snotdel
iver
edt
othe
wr
ongpr
otocol
.
Congest
ionCont
rol
Si
nceUDPi
saconnect
ionl
esspr
otocol
,itdoesnotpr
ovi
decongest
ioncont
rol
.
UDP assumest
hatt
hepacket
ssentar
esmal
landspor
adi
candcannotcr
eat
e
congest
ioni
nthenet
wor
k.Thi
sassumpt
ionmayormaynotbet
ruet
oday,when
UDPi
susedf
ori
nter
act
iver
eal
-t
imet
ransf
erofaudi
oandvi
deo.
Encapsul
ati
onandDecapsul
ati
on
Tosendamessagef
rom onepr
ocesst
oanot
her
,theUDPpr
otocolencapsul
ates
anddecapsul
atesmessages.
Queui
ng
I
nUDP,queuesar
eassoci
atedwi
thpor
ts.Att
hecl
ientsi
te,whenapr
ocessst
art
s,
i
trequest
sapor
tnumberf
rom t
heoper
ati
ng syst
em.Somei
mpl
ement
ati
ons
cr
eat
ebot
hani
ncomi
ngandanout
goi
ngqueue.associ
atedwi
theachpr
ocess.
Ot
heri
mpl
ement
ati
ons cr
eat
e onl
y an i
ncomi
ng queue associ
ated wi
th each
pr
ocess.
Mul
ti
plexi
ngandDemul
ti
plexi
ng
I
nahostr
unni
ngaTCP/
IP pr
otocolsui
te,t
her
eisonl
yoneUDP butpossi
bly
sever
alpr
ocessest
hatmaywantt
o uset
heser
vicesofUDP.To handl
ethi
s
si
tuat
ion,
UDPmul
ti
plexesanddemul
ti
plexes.
Typi
calAppl
icat
ions
Thef
oll
owi
ngshowssomet
ypi
calappl
icat
ionst
hatcanbenef
itmor
efr
om t
he
ser
vicesofUDPt
hanf
rom t
hoseofTCP.
UDP i
s sui
tabl
efor a pr
ocess t
hat r
equi
res si
mpl
erequest
-r
esponse
communi
cat
ionwi
thl
it
tl
econcer
nforf
low ander
rorcont
rol
.Iti
snotusual
ly
usedf
orapr
ocesssuchasFTPt
hatneedst
osendbul
kdat
a.
UDPi
ssui
tabl
eforapr
ocesswi
thi
nter
nalf
low-ander
ror
-cont
rolmechani
sms.
Forexampl
e,t
heTr
ivi
alFi
leTr
ansf
erPr
otocol(
TFTP)pr
ocessi
ncl
udesf
lowand
Dept
.ofECE,
RNSI
TPage24
CCNModul
e5:Tr
anspor
tlayer
er
rorcont
rol
.Itcaneasi
lyuseUDP.
UDPi
sasui
tabl
etr
anspor
tpr
otocolf
ormul
ti
cast
ing.Mul
ti
cast
ingcapabi
li
tyi
s
embeddedi
ntheUDPsof
twar
ebutnoti
ntheTCPsof
twar
e.
UDPi
susedf
ormanagementpr
ocessessuchasSNMP.
UDPi
susedf
orsomer
out
eupdat
ingpr
otocol
ssuchasRout
ingI
nfor
mat
ion
Pr
otocol(
RIP)
.
UDPi
snor
mal
lyusedf
ori
nter
act
iver
eal
-t
imeappl
icat
ionst
hatcannott
oler
ate
unevendel
aybet
weensect
ionsofar
ecei
vedmessage.
5.Whatar
ethedi
ff
erentTCPser
vicesandf
eat
ures?Expl
aint
hem
Pr
ocess-
to-
ProcessCommuni
cat
ion
TCPpr
ovi
despr
ocess-
to-
processcommuni
cat
ionusi
ngpor
tnumber
s.
St
ream Del
iver
ySer
vice
TCP,
unl
ikeUDP,
isast
ream-
ori
ent
edpr
otocol
.InUDP,
apr
ocesssendsmessages
wi
thpr
edef
inedboundar
iest
oUDPf
ordel
iver
y.UDPaddsi
tsownheadert
oeachof
t
hesemessagesanddel
iver
sitt
oIPf
ort
ransmi
ssi
on.Eachmessagef
rom t
he
pr
ocessi
scal
ledauserdat
agr
am,andbecomes,event
ual
ly,oneI
P dat
agr
am.
Nei
therI
PnorUDPr
ecogni
zesanyr
elat
ionshi
pbet
weent
hedat
agr
ams.
TCP,ont
heot
herhand,al
lowst
hesendi
ngpr
ocesst
odel
iverdat
aasa
st
ream ofbyt
esandal
l
owst
her
ecei
vingpr
ocesst
oobt
aindat
aasast
ream of
byt
es.TCP cr
eat
es an envi
ronmenti
n whi
ch t
he t
wo pr
ocesses seem t
o be
connect
edbyani
magi
nar
y“t
ube”t
hatcar
ri
est
hei
rbyt
esacr
osst
heI
nter
net
.Thi
s
i
magi
nar
yenvi
ronmenti
sdepi
ctedi
nFi
gur
e21.Thesendi
ngpr
ocesspr
oduces
(
wri
test
o)t
hest
ream andt
her
ecei
vingpr
ocessconsumes(
readsf
rom)i
t.
Fi
gur
e21:St
ream del
iver
y
Sendi
ngandRecei
vingBuf
fer
s
Onewayt
oimpl
ementabuf
feri
stouseaci
rcul
arar
rayof1-
byt
elocat
ions
Dept
.ofECE,
RNSI
TPage25
CCNModul
e5:Tr
anspor
tlayer
asshowni
nFi
gur
e22.Forsi
mpl
ici
ty,i
tisshown ast
wobuf
fer
sof20byt
eseach;
nor
mal
lyt
he buf
fer
s ar
e hundr
eds ort
housands ofbyt
es,dependi
ng on t
he
i
mpl
ement
ati
on.Weal
soshow t
hebuf
fer
sast
hesamesi
ze,whi
chi
snotal
ways
t
hecase.Thef
igur
eshowst
hemovementoft
hedat
ainonedi
rect
ion.Att
hesender
,
t
he buf
ferhas t
hree t
ypes ofchamber
s.The whi
te sect
ion cont
ains empt
y
chamber
sthatcanbef
il
ledbyt
hesendi
ngpr
ocess(
producer
).Thecol
oredar
ea
hol
dsbyt
est
hathavebeensentbutnotyetacknowl
edged.TheTCPsenderkeeps
t
hesebyt
esi
nthebuf
ferunt
ili
trecei
vesanacknowl
edgment
.Theshadedar
ea
cont
ainsbyt
est
obesentbyt
hesendi
ngTCP.However
,aswewi
llseel
ateri
nthi
s
chapt
er,TCPmaybeabl
etosendonl
ypar
toft
hisshadedsect
ion.Thi
scoul
dbe
duet
othesl
ownessoft
her
ecei
vingpr
ocessort
ocongest
ioni
nthenet
wor
k.Al
so
not
ethat
,af
tert
hebyt
esi
nthecol
oredchamber
sar
eacknowl
edged,
thechamber
s
ar
erecycl
edandavai
labl
eforusebyt
hesendi
ngpr
ocess.
Theoper
ati
onoft
hebuf
feratt
her
ecei
veri
ssi
mpl
er.Theci
rcul
arbuf
feri
s
di
videdi
ntot
woar
eas(
shownaswhi
teandcol
ored)
.Thewhi
tear
eacont
ains
empt
ychamber
stobef
il
ledbybyt
esr
ecei
vedf
rom t
henet
wor
k.Thecol
ored
sect
ionscont
ainr
ecei
vedbyt
est
hatcanber
eadbyt
her
ecei
vingpr
ocess.Whena
byt
eisr
eadbyt
her
ecei
vingpr
ocess,
thechamberi
srecycl
edandaddedt
othepool
ofempt
ychamber
s.
Fi
gur
e22:Sendi
ngandr
ecei
vingbuf
fer
s
Segment
s
Al
thoughbuf
fer
inghandl
est
hedi
spar
it
ybet
weent
hespeedoft
hepr
oduci
ngand
consumi
ngpr
ocesses,weneedonemor
est
epbef
orewecansenddat
a.The
net
wor
klayer
,asaser
vicepr
ovi
derf
orTCP,
needst
osenddat
ainpacket
s,notasa
st
ream ofbyt
es.Att
het
ranspor
tlayer
,TCPgr
oupsanumberofbyt
est
oget
heri
nto
apacketcal
l
edasegment
.
TCPaddsaheadert
oeachsegment(
forcont
rolpur
poses)anddel
iver
sthe
Dept
.ofECE,
RNSI
TPage26
CCNModul
e5:Tr
anspor
tlayer
segmentt
othenet
wor
klayerf
ort
ransmi
ssi
on.Thesegment
sar
eencapsul
atedi
n
an I
P dat
agr
am and t
ransmi
tt
ed.Thi
s ent
ir
e oper
ati
on i
str
anspar
entt
othe
r
ecei
vingpr
ocess.Segment
smayber
ecei
vedoutofor
der
,lostorcor
rupt
ed,and
r
esent
.Al
loft
hesear
ehandl
edbyt
heTCPr
ecei
verwi
tht
her
ecei
vingappl
icat
ion
pr
ocessunawar
eofTCP’
sact
ivi
ti
es.Fi
gur
e23showshow segment
sar
ecr
eat
ed
f
rom t
hebyt
esi
nthebuf
fer
s.
Segment
sar
enotnecessar
il
yal
lthesamesi
ze.I
nthef
igur
e,f
orsi
mpl
ici
ty,
it
i
sshownonesegmentcar
ryi
ng3byt
esandt
heot
hercar
ryi
ng5byt
es.I
nreal
it
y,
segment
scar
ryhundr
eds,
ifnott
housands,
ofbyt
es.
Fi
gur
e23:TCPsegment
s
Ful
l-
Dupl
exCommuni
cat
ion
TCPof
fer
sful
l-
dupl
exser
vice,wher
edat
acanf
low i
nbot
hdi
rect
ionsatt
hesame
t
ime.Each TCP endpoi
ntt
hen hasi
tsown sendi
ng and r
ecei
ving buf
fer
,and
segment
smovei
nbot
hdi
rect
ions.
Mul
ti
plexi
ngandDemul
ti
plexi
ng
Li
keUDP,TCP per
for
msmul
ti
plexi
ng att
hesenderand demul
ti
plexi
ng att
he
r
ecei
ver
.However
,si
nceTCPi
saconnect
ion-
ori
ent
edpr
otocol
,aconnect
ionneeds
t
obeest
abl
ishedf
oreachpai
rofpr
ocesses.
Connect
ion-
Ori
ent
edSer
vice
TCP,
unl
ikeUDP,
isaconnect
ion-
ori
ent
edpr
otocol
.Whenapr
ocessatsi
teAwant
s
t
osendt
oandr
ecei
vedat
afr
om anot
herpr
ocessatsi
teB,t
hef
oll
owi
ngt
hree
phasesoccur
:
1.Thet
woTCP’
sest
abl
ishal
ogi
calconnect
ionbet
weent
hem.
2.Dat
aar
eexchangedi
nbot
hdi
rect
ions.
3.Theconnect
ioni
ster
minat
ed.
Dept
.ofECE,
RNSI
TPage27
CCNModul
e5:Tr
anspor
tlayer
Thi
sisa l
ogi
calconnect
ion,nota physi
calconnect
ion.TheTCP segmenti
s
encapsul
atedi
nanI
Pdat
agr
am andcanbesentoutofor
der
,orl
ostorcor
rupt
ed,
andt
henr
esent
.Eachmayber
out
edoveradi
ff
erentpat
htor
eacht
hedest
inat
ion.
Ther
eisnophysi
calconnect
ion.TCP cr
eat
esast
ream-
ori
ent
edenvi
ronmenti
n
whi
chi
taccept
sther
esponsi
bil
it
yofdel
iver
ingt
hebyt
esi
nor
dert
otheot
hersi
te.
Rel
iabl
eSer
vice
TCP i
sar
eli
abl
etr
anspor
tpr
otocol
.Itusesanacknowl
edgmentmechani
sm t
o
checkt
hesaf
eandsoundar
ri
valofdat
a.
TCPFeat
ures
Number
ingSyst
em
Al
though t
heTCP sof
twar
ekeepst
rackoft
hesegment
sbei
ng t
ransmi
tt
ed or
r
ecei
ved,t
her
eisnof
iel
dforasegmentnumberval
uei
nthesegmentheader
.
I
nst
ead,
ther
ear
etwof
iel
ds,
cal
ledt
hesequencenumberandt
heacknowl
edgment
number
.Theset
wof
iel
dsr
efert
oabyt
enumberandnotasegmentnumber
.
Byt
eNumber
TCP number
s al
ldat
a byt
es (
oct
ets)t
hatar
etr
ansmi
tt
ed i
n a connect
ion.
Number
ingi
sindependenti
neachdi
rect
ion.WhenTCPr
ecei
vesbyt
esofdat
afr
om
a pr
ocess,TCP st
ores t
hem i
nthe sendi
ng buf
ferand number
sthem.The
number
ingdoesnotnecessar
il
yst
artf
rom 0.I
nst
ead,TCPchoosesanar
bit
rar
y
ween0and232 -1f
numberbet ort
henumberoft
hef
ir
stbyt
e.Forexampl
e,i
fthe
numberhappenst
obe1057andt
het
otaldat
atobesenti
s6000byt
es,t
hebyt
es
ar
enumber
edf
rom 1057t
o7056.Wewi
llseet
hatbyt
enumber
ingi
susedf
orf
low
ander
rorcont
rol
.
SequenceNumber
Af
tert
hebyt
eshavebeennumber
ed,TCPassi
gnsasequencenumbert
oeach
segmentt
hati
sbei
ngsent
.Thesequencenumber
,ineachdi
rect
ion,i
sdef
inedas
f
oll
ows:
1.Thesequencenumberoft
hef
ir
stsegmenti
stheI
SN(
ini
ti
alsequencenumber
),
whi
chi
sar
andom number
.
2.Thesequencenumberofanyot
hersegmenti
sthesequencenumberoft
he
pr
evi
oussegmentpl
ust
henumberofbyt
es(
realori
magi
nar
y)car
ri
edbyt
he
Dept
.ofECE,
RNSI
TPage28
CCNModul
e5:Tr
anspor
tlayer
pr
evi
oussegment
.
Acknowl
edgmentNumber
Communi
cat
ioni
nTCPi
sful
ldupl
ex;whenaconnect
ioni
sest
abl
ished,
bot
hpar
ti
es
cansendandr
ecei
vedat
aatt
hesamet
ime.Eachpar
tynumber
sthebyt
es,
usual
ly
wi
thadi
ff
erentst
art
ingbyt
enumber
.Thesequencenumberi
neachdi
rect
ion
showst
henumberoft
hef
ir
stbyt
ecar
ri
edbyt
hesegment
.Eachpar
tyal
sousesan
acknowl
edgmentnumbert
o conf
ir
m t
he byt
es i
thas r
ecei
ved.However
,the
acknowl
edgmentnumberdef
inest
henumberoft
henextbyt
ethatt
he par
ty
expect
stor
ecei
ve.I
naddi
ti
on,t
heacknowl
edgmentnumberi
scumul
ati
ve,whi
ch
meanst
hatt
hepar
tyt
akest
henumberoft
hel
astbyt
ethati
thasr
ecei
ved,
saf
eand
sound,adds1t
oit
,andannouncest
hissum ast
heacknowl
edgmentnumber
.The
t
erm cumul
ati
veher
emeanst
hati
fapar
tyuses5643asanacknowl
edgment
number
,ithasr
ecei
vedal
lbyt
esf
rom t
hebegi
nni
ngupt
o5642.Not
ethatt
hisdoes
notmeant
hatt
hepar
tyhasr
ecei
ved5642byt
es,becauset
hef
ir
stbyt
enumber
doesnothavet
obe0.
6.Wi
thaneatdi
agr
am expl
ainTCPsegmentf
ormat
Segment
Apacketi
nTCPi
scal
ledasegment
.
For
mat
Thef
ormatofasegmenti
sshowni
nFi
gur
e23.
1.Thesegmentconsi
stsofa
headerof20t
o60byt
es,f
oll
owedbydat
afr
om t
heappl
icat
ionpr
ogr
am.The
headeri
s20byt
esi
fther
ear
enoopt
ionsandupt
o60byt
esi
fitcont
ainsopt
ions.
Dept
.ofECE,
RNSI
TPage29
CCNModul
e5:Tr
anspor
tlayer
Fi
gur
e23.
1:TCPsegmentf
ormat
Sour
cepor
taddr
ess.Thi
sisa16-
bitf
iel
dthatdef
inest
hepor
tnumberoft
he
appl
icat
ionpr
ogr
am i
nthehostt
hati
ssendi
ngt
hesegment
.
Dest
inat
ionpor
taddr
ess.Thi
sisa16-
bitf
iel
dthatdef
inest
hepor
tnumberoft
he
appl
icat
ionpr
ogr
am i
nthehostt
hati
srecei
vingt
hesegment
.
Sequencenumber
.Thi
s32-
bitf
iel
ddef
inest
henumberassi
gnedt
othef
ir
stbyt
e
ofdat
acont
ainedi
nthi
ssegment
.Aswesai
dbef
ore,TCPi
sast
ream t
ranspor
t
pr
otocol
.Toensur
econnect
ivi
ty,eachbyt
etobet
ransmi
tt
edi
snumber
ed.The
sequencenumbert
ell
sthedest
inat
ionwhi
chbyt
eint
hissequencei
sthef
ir
st
byt
eint
hesegment
.Dur
ingconnect
ionest
abl
ishment
,eachpar
tyusesar
andom
numbergener
atort
ocr
eat
eani
nit
ialsequencenumber(
ISN)
,whi
chi
susual
ly
di
ff
erenti
neachdi
rect
ion.
Acknowl
edgmentnumber
.Thi
s32-
bitf
iel
ddef
inest
hebyt
enumbert
hatt
he
r
ecei
veroft
hesegmenti
sexpect
ingt
orecei
vef
rom t
heot
herpar
ty.I
fthe
r
ecei
veroft
hesegmenthassuccessf
ull
yrecei
vedbyt
enumberxf
rom t
heot
her
par
ty,
itr
etur
nsx+1ast
heacknowl
edgmentnumber
.Acknowl
edgmentanddat
a
canbepi
ggybackedt
oget
her
.
Headerl
engt
h.Thi
s4-
bitf
iel
dindi
cat
est
henumberof4-
byt
ewor
dsi
ntheTCP
header
.Thel
engt
hoft
heheadercanbebet
ween20and60byt
es.Ther
efor
e,t
he
val
ueoft
hisf
iel
disal
waysbet
ween5(
5×4=20)and15(
15×4=60)
.
Cont
rol
.Thi
sfi
elddef
ines6di
ff
erentcont
rolbi
tsorf
lags,asshowni
nFi
gur
e
24.
8.Oneormor
eoft
hesebi
tscanbesetatat
ime.Thesebi
tsenabl
efl
ow
Dept
.ofECE,
RNSI
TPage30
CCNModul
e5:Tr
anspor
tlayer
cont
rol
,connect
ionest
abl
ishmentandt
ermi
nat
ion,connect
ionabor
ti
on,andt
he
modeofdat
atr
ansf
eri
nTCP.Abr
iefdescr
ipt
ionofeachbi
tisshowni
nthe
f
igur
e.24
Wi
ndow si
ze.Thi
sfi
elddef
inest
hewi
ndow si
zeoft
hesendi
ngTCPi
nbyt
es.
Not
ethatt
hel
engt
hoft
hisf
iel
dis16bi
ts,whi
chmeanst
hatt
hemaxi
mum si
ze
oft
hewi
ndowi
s65,
535byt
es.Thi
sval
uei
snor
mal
lyr
efer
redt
oast
her
ecei
ving
wi
ndow (
rwnd)andi
sdet
ermi
nedbyt
her
ecei
ver
.Thesendermustobeyt
he
di
ctat
ionoft
her
ecei
veri
nthi
scase.
Checksum.Thi
s16-
bitf
iel
d cont
ainst
hechecksum.Thecal
cul
ati
on oft
he
checksum f
orTCPf
oll
owst
hesamepr
ocedur
east
heonedescr
ibedf
orUDP.
However
,theuseoft
hechecksum i
ntheUDPdat
agr
am i
sopt
ional
,wher
east
he
useoft
hechecksum f
orTCPi
smandat
ory.
Ur
gentpoi
nter
.Thi
s16-
bitf
iel
d,whi
chi
sval
idonl
yift
heur
gentf
lagi
sset
,is
usedwhent
hesegmentcont
ainsur
gentdat
a.I
tdef
inesaval
uet
hatmustbe
addedt
othesequencenumbert
oobt
aint
henumberoft
hel
astur
gentbyt
eint
he
dat
asect
ionoft
hesegment
.
Opt
ions.Ther
ecanbeupt
o40byt
esofopt
ionali
nfor
mat
ioni
ntheTCPheader
.
Encapsul
ati
on
ATCPsegmentencapsul
atest
hedat
arecei
vedf
rom t
heappl
icat
ionl
ayer
.TheTCP
segmenti
sencapsul
atedi
nanI
Pdat
agr
am,whi
chi
ntur
nisencapsul
atedi
na
f
rameatt
hedat
a-l
inkl
ayer
.
Dept
.ofECE,
RNSI
TPage31