You are on page 1of 124

Mc lc Tng vn ti (Transport Layer)

1. Cc dch v v nguyn l ca tng vn ti 2. Cc ng dng ghp knh v phn knh 3. Vn chuyn phi kt ni: UDP 4. Cc nguyn l truyn d liu tin cy . Java Applet: iu khin lung trong qu trnh hot ng 5. Vn chuyn hng kt ni: TCP 6. Cc nguyn l iu khin tc nghn .. 7. iu khin tc nghn TCP . 8. Tm tt 9. Bi v nh v cc cu hi tho lun

2 9 14 22

52 78 89 114 116

3.1 Cc dch v v nguyn l ca tng vn ti


Nm gia tng ng dng v tng mng li,tng vn ti nm trong li ca kin trc tng mng li.N ng vai tr quan trng t vic cung cp cc dch v truyn thng n vic vn hnh cc tin trnh ng dng trn cc host khc nhau.Trong chng ny,ta s xem xt cc dch v c cung cp bi giao thc ca tng vn ti v cc qui tc di nhng gc nhn khc nhau hng ti cung cp cc dch v ny. Chng ta s xem xt cch cc dch v ny c thc thi nh th no vi cc giao thc c s dng hin nay,c bit nhn mnh tm quan trng ca cc giao thc Internet, l giao thc TCP v UDP thuc tng vn ti. hai phn trc chng ta nhc qua v vai tr ca tng vn ti v cc dch v m n cung cp.im li mt s phn quan trng v tng vn ti m chng ta hc: Mt giao thc thuc tng vn ti cung cp giao tip logic cho cc tin trnh vn hnh trn cc host khc nhau.Giao tip logic ngha l cho d cc tin trnh ng dng ang giao tip khng c kt ni vt l vi nhau( trn thc t,chng c th nm nhiu a im trn a cu,kt ni thng qua v s router v mt bng thng rng cho cc loi link),t gc nhn ca dch v ta li thy chng c lin kt vt l vi nhau.Cc tin trnh ng dng s dng giao tip logic c cung cp bi tng vn ti truyn thng ip cho nhau,khng quan tm n chi tit cu to vt l ca cc b phn dng truyn thng ip.Hnh 3.1-1 minh ha cho khi nim giao tip logic. Nh gii thiu hnh 3.1-1,cc giao thc tng vn ti c thc hin cc h thng u cui ch khng phi trong cc router ca mng.Router ca mng ch thc s hot ng trn cc lnh vc thuc tng mng li 3 PDU,ch khng c tc dng vi cc vn thuc tng vn ti. kha cnh gi tin,tng vn ti lm nhim v chuyn thng ip n nhn c t tin trnh gi tin thnh 4-PDU( l n v d liu ca giao thc

thuc tng vn ti).Vic ny (c th) c thc hin bng cch chia thng ip thnh nhiu mu nh v thm phn header (phn mo u) ca tng vn ti to thnh 4 PDU.Tng vn ti s chuyn 4PDU n tng mng li,ni 4 PDU c ng gi thnh 3 PDU. kha cnh nhn tin, tng vn ti nhn 4 PDU t tng mng li,b i phn header ca tng vn ti,rp ni cc mu thng tin nh li v chuyn chng n tin trnh ca ng dng nhn tin . Mt mng my tnh c th c nhiu hn mt giao thc thuc tng vn ti c s dng phc v cho cc ng dng mng.Ly vd,Internet c 2 giao thc:TCP v UDP.Mi mt giao thc cung cp mt tp cc ng dng tng vn ti khc nhau. Tt c cc giao thc ca tng vn ti cung cp dch v ng dng ghp knh v phn knh.Dch v ny s c miu t chi tit trong phn tip theo.Nh tho lun phn 2.1,i km vi cc dch v ghp knh/phn knh ,cc giao thc tng vn ti c th cung cp mt s cc dch v h tr,bao gm dch v truyn d liu ng tin cy,bo m bng thng v bo m tr.

Hnh 3.1-1:Tng vn ti cung cp truyn thng logic,m ko cung cp kt ni vt l gia cc ng dng

3.1.1. Mi quan h gia tng vn ti v tng mng li


nh gi khi qut v mng my tnh,tng vn ti l nm phn c s h tng ca truyn thng.ng nhin l s c nhng tng khc ngoi tng vn ti thuc c s h tng.Ly vd,tng mng li nm di tng vn ti trong giao thc ngn xp.Trong khi giao thc tng vn ti cung cp truyn thng logic cho cc tin trnh chy trn cc host khc nhau th giao thc ca tng mng li li cung cp truyn thng logic cho cc host.S khc bit ny tuy nh nhng rt quan trng.Hy cng xt v d di y minh ha r hn v s khc bit ny : Cho 2 ngi nh,mt nm b bin ng v 1 nm b bin pha Ty,mi nh c 12 a tr.Nhng a tr h pha ng l anh em h vi nhng a tr ca h pha Ty.Bn tr hai nh thch vit th cho nhau,mi a tr li vit th cho anh em h ca n mi tun,th c chuyn pht bng dch v chuyn pht th truyn thng trong nhng phong b ring.Nh vy, nh ny gi 144 l th cho nh khc mi tun(nhng a tr ny s tit kim c mt khon tin ln nu chng c email!).Mi nh c mt a tr --Alice nh pha Ty v Bob nh pha ng chu trch nhim cho vic tp hp v phn pht th.Mi tun Alice n thm nh cc anh em v ch em ca mnh,tp hp th v a chng cho ngi ca dch v chuyn pht th mi ngy.Khi cc l th n nh pha ty,cng vic ca Alice li l phn pht cc bc th n cc anh ch em ca mnh.Bob cng lm nhng cng vic tng t nh pha ng. Trong v d ny,dch v chuyn pht th cung cp truyn thng logic gia 2 nh,dch v chuyn th l t nh ny ti nh khc,khng phi t ngi ny ti ngi khc.Ni cch khc,Alice v Bob cung cp truyn thng logic gia nhng ngi anh em h ca mnh,thu thp th v chuyn th .Ch rng,ng trn kha cnh ca nhng ngi anh em h,Alice v Bob l dch v mail,mc d Alice v Bob ch l mt phn (ng vai tr nh h thng u cui) ca tin trnh chuyn pht th.V d v h gia nh ny rt thch hp gii thch cho mi quan h gia tng vn ti v tng mng li. Cc host(hay cn gi l cc h thng u cui)=cc ngi nh Cc tin trnh= cc anh ch em h Cc thng ip ca ng dng = cc l th trong tng phong th ring

Giao thc tng mng li= dch v chuyn pht th ( bao gm c ngi a th) Giao thc tng vn ti= Alice v Bob. Tip tc vi s tng ng ny,theo iu kin l Alice v Bob lm mi vic trong tng nh ring bit;chng khng c lin h vi nhau, ly v d,trong vic phn loi th bt k bu in trung gian no hoc chuyn th t trung tm ny n trung tm khc.Tng t nh vy,cc giao thc tng vn ti tn ti cc h thng u cui.Bn trong h thng u cui,mt giao thc tng vn ti chuyn thng ip t cc tin trnh ca ng dng n bin ca mng (c th:tng mng li).Nhng n khng ni r lm th no thng ip c truyn i trong li ca mng.Trn thc t,nh minh ha hnh 3.1-1 ,cc rounter trung gian khng tc ng ,khng nhn bit bt c thng tin no m tng vn ti gn thm cho cc thng ip ca ng dng. Tip tc vi v d v 2 h gia nh,gi s hin ti Alice v Bob i ngh,mt cp anh em h khc Susan v Harvey thay th cho chng v li lm nhim v thu gom v chuyn pht th.Tht khng may l Susan v Harvey li khng lm ng cng vic thu gom v chuyn th theo ng cch m Alice v Bob lm.t tui hn,Susan v Harvey thu gom th t hn v khng thng xuyn,thm ch chng cn lm mt th ( thnh thong do b nhng con ch nhai nt).Nh vy,cp anh em Susan v Harvey khng cung cp cng mt tp cc dch v ( c th:cng m hnh dch v) so vi Alice v Bob.Theo kiu tng t,mt mng my tnh c th to nn nhiu giao thc thuc tng vn ti ,mi giao thc ng c mt m hnh dch v ring n cc ng dng. Cc dch v m Alice v Bob cung cp r rng c rng buc vi cc dch v m dch v chuyn pht th cung cp.Ly vd,nu dch v chuyn pht th khng cho bit gii hn ln nht v khong thi gian chuyn giao th gia hai h gia nh (VD: 3 ngy),th s khng c cch no Alice v Bob c th bo m thi gian tr ln nht l bao nhiu cho mi ln chuyn th gia bt k cp anh em h hng no.Vi kiu tng t, cc dch v m mt giao thc thuc tng vn ti cung cp thng b rng buc bi m hnh dch v nm di giao thc ca tng mng li.Nu giao thc tng mng li khng th bo m tr v bng thng cho vic

gi 4 PDU gia cc host,th giao thc tng vn ti cng khng th bo m tr v bng thng cho vic gi thng ip gia cc tin trnh. Tuy nhin,mt s dch v no c th c chim bi mt giao thc thuc tng vn ti thm ch khi giao thc thuc tng mng li pha di khng yu cu dch v p tr tng mng li.V d,nh chng ta xem xt chng ny,mt giao thc tng vn ti c th s dng mt dch v truyn d liu ng tin cy n cc ng dng,ngay c khi giao thc thuc tng mng li khng ng tin cy, l vic giao thc tng mng li lm mt,lm sai lch v lm trng lp cc gi tin.Trong v d khc(chng ta s xem xt v d ny chng 7 khi tho lun v an ninh mng),mt giao thc tng vn ti c th s dng m ha bo m cc thng ip ca ng dng khng b nhng k xm phm c c,thm ch c khi tng mng li khng th bo m tnh bo mt ca 4 PDU.

3.1.2. Tng quan v tng vn ti trn Internet.


Internet,nhn chung l mt mng li TCP/IP,to nn hai giao thc thuc tng vn ti phn bit vi tng ng dng.Mt trong nhng giao thc ny l UDP (User datagram protocol ),cung cp cc dch v khng tin cy,khng kt ni cho cc ng dng.Giao thc th 2 l TCP (Transimission control protocol) ,cung cp cc dch v ng tin cy,hng kt ni cho cc ng dng.Khi thit k mt ng dng mng,ngi pht trin ng dng phi nh r s dng giao thc no trong 2 giao thc trn.Nh chng ta thy mc 2.6 v 2.7,nhng nh pht trin ng dng la chn gia UDP v TCP khi to socket. n gin ha thut ng,trong Internet,chng ta coi 4 PDU nh l 1 on(segment).Tuy nhin,trn cc vn bn v Internet (vd:RFC),PDU cho TCP c coi nh l 1 on,PDU cho UDP li c coi nh 1 datagram.Nhng trong quyn sch ny ta s dng thut ng datagram ni n PDU tng mng li.Vi mt cun sch gii thiu v mng my tnh nh cun sch ny,vic coi cc PDU ca TCP v UDP l cc on,thut ng datagram ch PDU tng mng li s lm gim nhm ln. Vic gii thiu v UDP v TCP trc y gip ch khi tm hiu v tng mng li ca Internet.(Tng mng li c ly v d chi tit trong chng 4). Giao thc tng mng li ca Internet c tn l IP,vit tt ca Internet Protocol ( giao thc Internet).IP cung cp truyn thng logic gia cc host. M hnh dch v IP l mt

dch v vn chuyn n lc nht.iu ny c ngha l IP n lc ht sc vn chuyn cc on gia cc host,nhng khng bo m.C th,n khng bo m vic vn chuyn on,cng khng m bo th t vn chuyn cc on, nhng n bo m tnh ton vn cho d liu trong cc on.V ba l do ,IP c coi l dch v khng ng tin cy.Chng ta cng cp n y l mi host c mt a ch IP.Chng ta s xem xt v vic nh a ch IP chng 4;cn trong chng ny cn lu l mi host ch c mt a ch IP duy nht. c ci nhn qua v m hnh dch v IP,gi hy tm tt m hnh dch v ca UDP v TCP.Vai tr c bn nht ca TCP v UDP l m rng dch v vn chuyn ca IP t gia hai h thng u cui thnh dch v vn chuyn gia cc tin trnh chy trn cc h thng cui khc nhau.M rng vn chuyn t host-n-host thnh t tin trnh-n-tin trnh c gi l ng dng ghp knh v phn knh. Chng ta s tho lun v ng dng ny phn tip theo.UDP v TCP cng cho php kim tra tnh ton vn gm cc lnh vc pht hin li.C 2 dch v tng vn ti c bn vn chuyn d liu t host n host v kim tra li, cng l hai dch v m UDP c th cung cp.C th,ging nh IP,UDP l dch v khng ng tin cy n khng bo m d liu c gi i bi mt tin trnh s n c tin trnh ch.UDP s c cp ti mc 3.3. TCP,ngc li,cung cp thm kh nhiu dch v cho cc ng dng.u tin v quan trng nht l dch v truyn file ng tin cy.S dng kim sot lung,s hiu cc dy,li bo nhn v b m thi gian (cc k thut chng ta s tho lun k trong chng ny),dch v truyn file ng tin cy ca TCP bo m vic d liu c vn chuyn t tin trnh gi n tin trnh nhn chnh xc v theo th t.Nh vy TCP chuyn i dch v khng ng tin cy ca IP gia hai h thng u cui thnh dch v vn chuyn d liu ng tin cy gia cc tin trnh.TCP cng s dng iu khin tc nghn. iu khin tc nghn khng hn l mt dch v cung cp cho cc ng dng m nhn chung n l mt dch v ca Internet.Dch v ny ca TCP bo v bt k mt kt ni TCP no khi tnh trng trn cc ng kt ni v cc cng tc gia cc host khi tnh trng qu ti xy ra.Theo nguyn tc,TCP vn cho php cc kt ni TCP i theo cc ng link tc nghn nhm chia s u bng thng ca ng link .iu ny c thc hin nh vic iu chnh li tn sut cho php bn gi tin ca TCP c th gi lu lng vo mng li.Giao thng ca UDP,ngc li,khng th iu chnh c.Mt ng dng s dng giao thc

UDP c th gi lu lng i vi bt k tn sut no,v vi thi gian bt k theo nhu cu. Mt giao thc cung cp dch v truyn d liu ng tin cy v iu khin tc nghn th v cng phc tp.Chng ta s cn rt nhiu phn tm hiu ht v hai dch v ny, v thm mt s phn tm hiu v giao thc TCP.Nhng ch ny s c nghin cu xuyn sut t mc 3.4 n 3.8.Cch tip cn trong chng ny xoay quanh cc qui tc c bn v giao thc TCP.Ly vd,u tin chng ta tho lun v dch v truyn d liu ng tin cy trong thit lp chung v sau s tho lun xem TCP cung cp dch v ny nh th no.Tng t,ta s xem xt iu khin tc nghn mc khi qut v sau s xem TCP s dng dch v ny nh th no.Nhng trc khi i vo cc vn ny,hy cng xem xt v ng dng ghp knh v phn knh mc tip theo.

3.2 Nhng ng dung hp knh va phn knh


Trong phn nay chung ta thao lun v hp knh/phn knh cua cac thng ip bi tng vn ti from/to tng ng dung. gi cho cuc tho lun c th, chng ta s tho lun v dch v c bn ny trong bi cnh tng vn ti ca Internet. Tuy nhin, chng ti nhn mnh rng, cc dch v hp knh v phn knh bao gi cng c cung cp trong hu ht cc kin trc giao thc c thit k. Hn na, hp knh /phn knh l cc dch v chung, thng c tm thy trong mt s tng bn trong mt chng giao thc c a ra. Mc du dich vu hp knh/phn knh khng phai la dich vu thu vi nht trong s cac dich vu c cung cp bi 1 giao thc tng vn ti, nhng no la 1 dich vu tuyt i quan trong. hiu tai sao no quan trong nh vy, hay xem xet 1 thc t la IP phn phi d liu gia 2 h thng u cui, vi mi h thng u cui c xac inh bi 1 ia chi IP duy nht. IP khng phn phi d liu gia cac tin trnh ng dung chay trn cac h thng u cui nay. Vic a ra phn phi gia cc host n phn phi gia cc tin trinh la cng vic cua dich vu hp knh va phn knh ng dng ca tng vn ti. Tai may chu ich, tng vn chuyn nhn cac segment (tc la, cc PDU ca tng vn chuyn) ch t tng mang bn di. Tng vn chuyn co trach nhim phn phi d liu trong cac segment cho phu hp vi cac tin trnh ng dung ang hoat ng trong may chu. Chung ta hay xem xet 1 vi du. Gia s ban ang ngi trc may tinh cua ban, va ban ang tai cc trang Web trong khi ang chay 1 phin FTP va 2 tac vu Telnet. Do o bn co 4 tin trinh ng dung mang ang hoat ng2

tin trinh Telnet, 1 tin trinh FTP, va 1 tin trinh HTTP. Khi tng vn chuyn trong may tinh cua ban nhn c d liu t tng mang pha di, no cn chi ao d liu nhn c n 1 trong 4 tin trinh trn. By gi hay kim tra cch thc lm vic o. Mi segment cua tng vn tai co 1 trng cha thng tin c s dung xac inh tin tinh ma d liu cua phn oan se c phn phi. Khi kt thuc qu trnh nhn, tng vn chuyn sau o co th kim tra trng nay xac inh tin trinh tip nhn, va sau o chi ao segment n tin trinh ny. Cng vic phn phi d liu trong mt segment tng vn ti n tin trnh ng dng c ch o gi l phn knh. Vic thu thp d liu may chu ngun t nhng tin trinh ng dung khac, bao gi d liu vi thng tin header ( ci ma sau nay se c s dung trong phn knh), tao ra cac segment, va chuyn cc segment ny n tng mng c goi la hp knh. minh hoa cho vic phn knh, chung ta hay tr li vi chui s kin h gia inh trong phn trc. Mi a em c phn bit bi tn cua chng. Khi Bob nhn c 1 tp th t ngi a th, anh a thc hin 1 thao tc phn knh bng cach quan sat cac ki t c trn ia chi, va sau o chuyn giao th bng tay ti cac anh chi em cua minh. Alice thc hin 1 thao tc ghp knh khi c y nhn c cc bc th t anh ch em cua c y va a la th nhn c cho ngi a th. UDP va TCP thc hin cac cng vic hp knh va phn knh bng cach bao gm 2 trng c bit trong cc header ca segment: trng s hiu cng ngun va trng s hiu cng ich. 2 trng o c minh hoa trong hinh 3.2-1. Khi hoat ng cung nhau, cac trng nhn ra duy nht 1 tin trinh ng dung ang hoat ng trn may chu ich ( cac segment UDP va TCP co cac trng khac cung rt tt, va chung se c giai quyt trong cac phn tip theo cua chng nay.)

Hinh 3.2-1: Cac trng s hiu cng ich va ngun trong 1 phn oan tng vn ti Khai nim s hiu cng a c gii thiu ngn gon trong cac phn 2.6-2.7. trong o chung ta a nghin cu vic phat trin ng dung va lp trinh socket. S hiu cng la 1 s 16-bit, trong khoang t 0 ti 65535. Cac s hiu cng nm trong khoang 0-1023 c goi la cac s hiu cng ni ting va bi han ch, iu c nghia la chung c s dung ring cho cac giao thc ng dung ni ting nh HTTP va FTP. HTTP s dung s hiu cng 80, FTP s dung s hiu cng 21. Danh sach cac s hiu cng ni ting c cho vao [RFC 1700]. Khi chung ta phat trin 1 ng dung mi ( nh 1 trong cac ng dung c phat trin trong phn 2.62.8 ), chung ta phai chi inh 1 s hiu cng cho ng dung. Cho rng mi loai ng dung chay trn 1 h thng u cui co 1 s hiu cng duy nht, th tai sao segment tng vn chuyn li co cac trng cho 2 s hiu cng, 1 s hiu cng ngun va 1 s hiu cng ich? Cu tra li rt n gian: Mt h thng u cui co th chay 2 tin trinh cung loai cung 1 luc, va vi th s hiu cng cua 1 ng dung co th khng u xac inh 1 tin trinh cu th. Vi du, nhiu may chu Web sinh ra 1 tin trinh HTTP mi cho moi yu cu m no nhn c ; bt c khi nao mt may chu Web phuc vu nhiu hn 1 yu cu (khng co nghia la khng ph bin), th may chu ang chay nhiu hn 1 tin trinh vi s cng 80. Do o nhn ra duy nht 1 tin trinh, mt s hiu cng th 2 la cn thit . Lam th nao s hiu cng th 2 c tao ra? S hiu cng nao i vao trng s hiu cng ngun cua 1 segment? S hiu cng nao i vao trng s hiu cng ich cua 1 segment? tra li nhng cu hoi nay, xem lai phn 2.1 cac ng dung mang c t chc xung quanh m hinh client-server. Thng thng, host m bt u ng dung la client va host cn li la server. By gi chung ta hay xem xet 1 vi du cu th. Gia s ng dung co s hiu cng 23( s hiu cng cho Telnet ). Xem xet 1 segment tng vn chuyn ri khi client (nghia la host ma bt u tac vu Telnet) va i n server. S hiu cng ich va ngun cho segment nay la gi? i vi s hiu cng ich, segment nay co s hiu cng cua ng dung, cu th la , 23. i vi s hiu cng ngun, client s dung 1 s ma cha tng c s dung trong bt ki tin trinh nao khac cua no (iu nay co th c thc hin t ng bi phn mm tng vn ti chay trn client va trong sut i vi cac nha phat trin ng dung. Mt ng dung cung co th yu cu ro rang 1 s hiu cng cu th bng cach s dung bind() h thng goi ln nhiu h thng ging Unix). Gi s rng client la chon s hiu

cng x. Sau o mi segment m tin trinh nay gi i s c s hiu cng ngun ca n c t bng x v s hiu cng ch c t bng 23. Khi segment n server, cac s hiu cng ngun va ich trong segment cho phep server host chuyn d liu cua cac segment n tin trnh ng dng chnh xc: s hiu cng ch 23 xac inh 1 tin trinh Telnet va s hiu cng ngun x xac inh 1 tin trinh Telnet cu th. Tinh trang l ngc lai i vi cac segment i t server ti client. S hiu cng ngun by gi la s hiu cng ca ng dung, 23. S hiu cng ich by gi la x ( x ny ging x c s dung cho s hiu cng ngun ca cc segment c gi t client ti server ) Khi 1 segment ti client, cac s hiu cng ngun va ich trong cac segment se cho phep client host chuyn d liu ca segment n tin trnh ng dng chnh xc, c xac inh bi cp s hiu cng. Hinh 3.2-2 tom lc lai cuc thao lun ny:

Hinh 3.2-2: S dung cac s hiu cng ich va ngun trong 1 ng dung clientserver By gi ban co th t hoi, iu gi xay ra nu 2 client khac nhau cung thit lp 1 phin Telnet n 1 server, va mi client cung la chon 1 s hiu cng ngun x? Lam th nao ma server co th phn knh cac segment khi 2 tac vu co chinh xac cung 1 cp s hiu cng? Cu tra li cho cu hoi nay la server cung s dung cac

ia chi IP trong cac goi d liu IP nh cac phn oan ( Chung ta se thao lun v goi d liu IP va vic anh ia chi cu th trong chng 4 ) Trang thai nay c miu ta trong hinh 3.2-3, trong o may chu A bt u 2 tac vu Telnet ti may chu C va khi may chu B bt u 1 tac vu Telnet ti may chu C . Cac may chu A,B va C u co cac ia chi IP ring cua chung : may chu A co ia chi IP A, may chu B co ia chi IP B va may chu C co ia chi IP C. May chu A gan 2 s hiu cng ngun (SP) khac nhau ( x va y) cho 2 kt ni Telnet bt ngun t may chu A. Nhng bi vi may chu B la chon s hiu cng ngun c lp vi A, nn no cung co th gan cng ngun = x cho kt ni Telnet cua no. Tuy nhin, may chu C vn co kha nng phn knh 2 kt ni khi 2 kt ni co ia chi IP ngun khac nhau. Tom lai chung ta thy rng, khi mt may chu ich nhn c d liu t tng mang, b 3 [ia chi IP ngun, s hiu cng ngun, s hiu cng ich ] c s dung chuyn d liu cho thich hp vi cac tin trinh

Hinh 3.2-3: Hai client, s dung cung mt s hiu cng giao tip vi cng mt ng dung ca server By gi chung ta a hiu lam th nao tng vn chuyn co th hp knh va phn knh cac thng tin t/ti cac ng dung mang. Hay chuyn tip va cung thao lun

v 1 trong cac giao thc truyn tai cua Internet, UDP. Trong phn tip theo, chung ta se thy rng UDP s dng thm 1 s giao thc tng mng hn so vi dich vu hp knh/phn knh.

Tham khao
[RFC 1700] J. Reynolds va J. Postel, "Assigned Numbers," RFC 1700, 10/1994

3.3.Giao thc vn ti khng kt ni:UDP


Internet cung cp sn hai giao thc vn ti cho cc ng dng ca n,UDP v TCP.Trong phn ny ta s c ci nhn chi tit hn v UDP,v cch n lm vic v n lm c nhng g.Bn c nn xem li phn 2.1,phn gii thiu tng quan v UDP v phn 2.7,phn tho lun v lp trnh socket trn UDP. Gi s bn ang hng th trong vic thit k mt giao thc vn ti.Bn s lm vic ny nh th no?u tin bn phi xem xt ti trng hp s dng giao thc vn ti.C th, bn gi, bn phi xem xt vic nhn thng ip t cc tin trnh ca ng dng v chuyn thng chng ti tng mng li; cn bn nhn, bn phi quan tm ti vic nhn thng ip t tng mng li v chuyn chng ti cc tin trnh ca ng dng.Nhng nh chng ta hc nhiu phn trc,lm t cn hn khng th lm g.t nht th tng vn ti cng phi cung cp cc dch v ghp knh/phn knh vn chuyn d liu gia tng mng li v cc ng dng. UDP,c nh ngha trong [RFC 768],ch c th cung cp mt s t dch v so vi cc giao thc vn ti khc. Ngoi chc nng ghp knh/phn knh v kim tra nhng li nh,UDP khng thm g cho IP.Trn thc t,nu nh pht trin ng dng chn UDP thay v TCP,th gn nh l ng dng s lm vic trc tip vi IP.UDP nhn cc thng ip t tin trnh ca ng dng, thm cc trng l s hiu cng ngun v cng ch cho dch v ghp knh/phn knh,gn thm hai trng khc (t quan trng) v chuyn on(segment) kt qu ti tng mng li.Tng mng li ng gi on thnh mt IP datagram v n lc ti a chuyn on ti

host nhn.Nu on ti c host nhn,UDP s dng s hiu cng v a ch IP ca ngun v ch chuyn d liu trong on n ng tin trnh ng dng.Ghi nh rng UDP khng c bt tay gia bn nhn v gi tng vn ti trc khi chuyn on i.V l do ny m UDP c coi l giao thc phi kt ni. DNS l mt v d v giao thc tng ng dng s dng UDP.Khi ng dng DNS (xem li mc 2.5) bn host mun thc hin 1 query ( cu truy vn),n xy dng mt thng ip truy vn DNS v chuyn thng ip ny ti socket UDP(xem mc 2.7).Khng thc hin v bt tay, UDP thm trng header (mo u) vo thng ip cn gi v a on kt qu ti tng mng li.Tng mng li ng gi on UDP thnh mt datagram v chuyn n ti name server .ng dng DNS bn pha host truy vn phi i cu tr li li cho query ca n.Nu n khng nhn c cu tr li ( c th do UDP lm mt query hoc mt cu tr li),n s c gng gi query n name server khc,hoc l n s thng bo cho ng dng v vic khng nhn c cu tr li.DNS c cho php chy trn TCP nhng trn thc t th DNS lun chy trn UDP. By gi bn c th thc mc ti sao nh pht trin ng dng li chn pht trin ng dng trn nn UDP m khng chn TCP.TCP c s dng nhiu hn v n cung cp dch v truyn d liu tin cy cn UDP th khng ? Cu tr li l khng,c nhiu ng dng thch hp vi UDP hn v nhng l do sau y: Khng thit lp kt ni: Chng ta s tho lun mc 3.5 v vic TCP phi c ba ln bt tay trc khi truyn d liu.UDP th truyn ngay m khng cn thng qua bt c mt nghi thc no.Nh vy UDP khng khin vic thit lp kt ni b tr. y l l do ch yu v sao DNS li chy trn UDP hn l TCP ---DNS s hot ng chm hn rt nhiu nu n vn hnh trn nn TCP.HTTP li s dng TCP thay v UDP,bi v tin cy l yu t quyt nh vi cc trang Web vn bn.Nhng nh tho lun ngn gn mc 2.2,tr trong thit lp kt ni TCP HTTP l thnh phn quan trng xy dng nn world wide wait. Khng trng thi kt ni. TCP duy tr trng thi kt ni cc h thng u cui.Trng thi kt ni ny bao gm cc b m (buffer) nhn v gi,cc tham s kim sot tc nghn,cc tham s tin bo nhn (acknowledgment)v tham s tun t.Ta s thy mc 3.5 rng trng thi thng tin ny l cn

thit thc hin dch v truyn d liu tin cy ca TCP v cung cp dch v kim sot tc nghn.Ni cch khc,UDP khng duy tr trng thi kt ni v khng theo di bt c mt tham s no.Chnh v vy,mt server ca mt ng dng ring bit c th phc v nhiu client hn khi chy trn UDP so vi TCP. Phn header cho on nh. Mi on TCP phi c hn 20byte dnh cho header(phn mo u) u on,trong khi UDP ch cn dnh ra 8 byte u on dnh cho header. Khng kim sot tc gi: TCP c c ch iu khin tc nghn hn ch ngi gi khi c mt hoc nhiu hn cc ng kt ni gia ngi gi v nhn c th gy tc nghn.Hn ch ny c th gy nh hng nghim trng ti cc ng dng thi gian thc cc ng dng ny c th chu mt gi tin nhng i hi mt tc truyn tin ti thiu.Ni cch khc,tc m UDP truyn d liu ch b nh hng bi tc ng dng to ra d liu,kh nng ca ti nguyn ( CPU,ng h o tc ,vvv) v bng thng truy cp ca Internet.Chng ta nn ghi nh iu ny,tuy nhin,bn host nhn khng cn thit phi nhn ton b d liu khi mng b tc nghn,mt s lng ng k d liu m UDP vn chuyn c th b mt do b m rounter b trn.Nh vy,tc nhn b gii hn bi tnh trng nghn mng ngay c khi tc gi khng b hn ch. Bng 3.1 a ra v d v cc ng dng ph bin v giao thc vn ti ca chng.Email( th in t),truy nhp u cui t xa,Web v truyn file u chy trn TCP ,bi nhng ng dng ny cn dch v truyn d liu tin cy ca TCP.UDP c s dng cho vic cp nht bng nh tuyn RIP (rounting table) (xem chng 4 tng mng li),bi v nhng bn cp nht (update) c gi i mt cch nh k nn nhng bn cp nht b mt s c thay th bi nhng bn thch hp hn.UDP c s dng truyn d liu qun l mng (SNMP xem chng 8).Trong trng hp ny,UDP thch hp hn TCP,bi v qun l mng thng phi vn hnh khi mng li tnh trng cng thng khi cc dch v truyn file tin cy hay kim sot b tc kh c th trin khai c.Nh chng ta tng cp,DNS chy trn UDP cng trnh cc tr trong thit lp kt ni ca TCP.

Hnh 3.1-1:cc ng dng Internet ph bin v cc giao thc vn ti chng s dng Nh chng ta thy trn hnh 3.1-1,nhn chung UDP thng c s dng cho cc ng dng a phng tin (multimedia),nh in thoi qua Internet, hi ngh truyn hnh thi gian thc,lu tr audio/video.Chng ta s xem xt k v cc ng dng ny chng 6. chng ny ta s ch nhn mnh vo vic cc ng dng ny cho php mt mt mt s lng nh cc gi tin,do truyn d liu tin cy khng phi l yu t quyt nh n thnh cng ca ng dng.Hn na,cc ng dng thi gian thc tng tc,nh in thoi qua Internet,hi ngh truyn hnh u khng chu nh hng nhiu t dch v iu khin tc nghn ca TCP.Bi nhng l do ny m nh pht trin cc ng dng a phng tin thng chn chy cc ng dng trn UDP thay v TCP.Cui cng bi v TCP khng th lm vic vi multicast nn multicast vn hnh trn UDP. Mc d rt ph bin hin nay song vic chy cc ng dng a phng tin bi UDP vn l vn gy tranh lun.Nh ta ni trn,UDP khng c dch v iu khin tc nghn.Nhng iu khin tc nghn l mt dch v cn thit trnh cho

mng li ri vo tnh trng tc nghn mt cch kh hiu qu.Nu mi ngi u bt u truyn video nh dng cao i m khng s dng iu khin tc nghn,th rt c th nhiu gi tin s b trn cc rounter dn ti vic mi ngi khng th xem c g.Nh vy,vic thiu dch v iu khin tc nghn l vn thc s nghim trng ca UDP.Nhiu nh nghin cu xut cc c ch mi cng p cc ti nguyn,bao gm c ti nguyn ca UDP thc hin iu khin tc nghn [Mahdavi]. Trc khi tho lun v cu trc on ca UDP,ta gi s rng cc ng dng vn c th c dch v truyn d liu tin cy khi s dng UDP.iu ny c th c thc hin nu bn thn ng dng c tin cy (VD:bng cch thm c ch xc nhn v cho php truyn li chng ta s tho lun thm v vn ny mc sau).Nhng y li l mt nhim v khng h km phn quan trng khin cc nh pht trin ng dng tn nhiu thi gian khc phc.Tuy nhin,xy dng tnh tin cy ngay cho ng dng ko theo vic ng dng t c v t phc v.Ngha l,cc tin trnh ca ng dng c th truyn thng tin cy m khng b rng buc bi tc truyn do c ch iu khin tc nghn ca TCP hn ch.Mc tin cy ca ng dng cng cho php ng dng t p ng nhu cu ca chnh n theo khun mu ring bit ca kim sot li.Cc ng dng thi gian thc tng tc i khi li la chn truyn li thng ip b mt,dn ti vic tr thi gian tng ng vi thi gian ca mt hnh trnh vng qua mng li nhng nh trnh cc tr nghim trng [Papadopoulos 1996]. Rt nhiu ng dng truyn theo lung ngy nay thc hin theo cch ny chng chy trn UDP,nhng chng xy dng c ch xc nhn v cho php truyn li cho bn thn ng dng gim s lng gi tin b mt.

Cu trc on UDP
Cu trc on UDP,nh hnh 3.3-2 di y,c nh ngha trong [RFC 768]

Hnh 3.2-2: Cu trc on ca UDP D liu ca ng dng chim ton b trng d liu ca UDP datagram.Ly v d,vi DNS,trng d liu bao gm c thng ip truy vn ln thng ip phn hi.Vi cc ng dng audio truyn theo lung,phn audio chim ton b trng d liu.UDP header ch chim bn trng,tng ng vi 4 byte.Nh tho lun phn trc,s hiu cng cho php host ch chuyn d liu ca ng dng n ng tin trnh chy trn host (c th:thc hin chc nng phn knh).Checksum c host nhn s dng kim tra xem c li pht sinh trn on trong sut qu trnh n c truyn i t ngun n ch hay khng.(cc qui tc c bn pht hin li c miu t mc 5.3)

UDP Checksum
UDP checksum c dng pht hin li.UDP pha bn gi s thc hin chc nng b sung tng ca tt c cc t 16bit vo on.Kt qu ny c lu trong trng checksum ca on UDP.( Trong thc t,checksum c tnh ton da trn mt s trng IP header cng thm vo on UDP.Nhng chng ta s b qua chi tit ny).Khi on n pha bn host nhn,tt c cc t 16bit c ghp chung vi nhau,bao gm c checksum.Nu tng bng 1111111111111111,th on khng b li.Nu c bit bng 0 th ta coi nh on b li.

y l mt v d n gin v tnh checksum.Bn c th xem chi tit v cch tnh hiu qu hn [RFC 1071].Gi s chng ta c 3 t 16bit nh di y: 0110011001100110 0101010101010101 0000111100001111 Tng ca 2 t 16 bit u tin l: 0110011001100110 0101010101010101 ------------------------1011101110111011 Thm t th ba vo tng trn: 1011101110111011 0000111100001111 ------------------------1100101011001010 Ta thu c phn t 1 bng cch chuyn ton b cc phn t 1 thnh 0 v ngc li.Nh vy, phn t 1 ca tng 1100101011001010 l 0011010100110101 v n s tr thnh checksum. bn nhn,bn t 16 bit c thm vo,bao gm c checksum.Nu khng c li no xy ra trn on,th r rng tng ta nhn c l 1111111111111111.Nu c bit bng 0,th ta hiu rng c li trn on. mc 5.1,ta s thy rng checksum ca Internet khng hon ton y ,bi ngay c khi tng l 1111111111111111 th vn c nhng li trn on m khng b pht hin.Do ,mt s cc giao thc s dng k thut pht hin li phc tp hn l s dng k thut checksumming n gin. Bn c th thc mc ti sao UDP vn cung cp trng checksum,trong khi nhiu giao thc tng kt ni (bao gm c giao thc Ethernet ph bin) cng cung cp phn kim tra li?L do l khng c g bo m rng cc ng kt ni gia ngun

v ch cng cung cp kim tra li --- Mt trong cc ng kt ni c th s dng giao thc khng c kim tra li.Bi v IP h tr chy trn cc giao thc tng 2 nn kim tra li m tng vn ti cung cp c coi l mt cng c bo m an ton.Tuy cung cp kim tra li nhng UDP khng c phc hi,sa li.Mt vi iu b sung m UDP mang li ch n gin l loi b on b li ( hng) hoc cnh bo ng dng rng c on b li. Chng ta kt thc bi tho lun v UDP.Ta s xem xt dch v truyn d liu tin cy ca TCP m UDP khng c.TCP phc tp hn UDP.Trc khi ni v TCP,s hiu qu hn nu ta li li v tho lun v cc qui tc i vi truyn d liu tin cy.TCP s c tho lun mc 3.5,ta s xem xt cc qui tc c s ca TCP.

Tham kho
[Papadopoulos 1996] C. Papadopoulos and G. Parulkar, "Retransmission-Based Error Control for Continuous Media Applications," Proceedings of the 6th International Workshop on Network and Operating System Support for Digital Audio and Video (NOSSDAV), April 1996. [Mahdavi] J. Mahdavi and S. Floyd, "The TCP-Friendly Website," http://www.psc.edu/networking/tcp_friendly.html [RFC 768] J.Postel, "User Datagram Protocol," RFC 768, August 1980. [RFC 1071] R. Braden, D. Borman, C. Partridge, "Computing The Internet Checksum," RFC 1071,September 1988.

3.4 Cc nguyn l truyn d liu tin cy


Trong phn ny, chng ta xem xt vn truyn d liu tin cy trong mt bi cnh chung. iu ny l thch hp t vn thc hin truyn d liu tin cy khng xut hin khng ch lp vn chuyn, m cn lp lin kt d liu v lp ng dng . Vn chung l quan trng ch yu n networking. Tht vy, nu ta phi xc nh mt danh sch "top 10" cc vn c bn ca networking ni chung, y s l ng c vin dn u danh sch . Trong phn tip theo chng ta s xem xt TCP v ch ra, mt cch c th, rng TCP khai thc rt nhiu nguyn tc m chng ta chun b din gii.

Hnh 3.4-1: Truyn d liu tin cy: m hnh dch v v thc hin dch v Hnh 3.4-1 minh ha cho phn sn ca vic nghin cu ca chng ta v s truyn d liu tin cy. Vic tru tng ha cc dch v c cung cp cho cc thc th ca lp trn chnh l ca mt knh ng tin cy m d liu c th c truyn qua . Vi mt knh ng tin cy, khng c bit d liu no c truyn m b hng (o 0 thnh 1 v ngc li) hoc mt mt, v tt c u n ch vi th t m chng c gi. y chnh xc l m hnh dch v c cung cp bi TCP n cc ng dng Internet gi n. Trch nhim ca mt giao thc truyn d liu tin cy l thc hin vic tru tng ha dch v ny. Nhim v ny b lm cho kh khn bi thc t l cc tng bn

di giao thc truyn d liu tin cy c th khng ng tin cy. V d, TCP l mt giao thc truyn d liu tin cy m thc hin pha trn mt tng mng u cui khng ng tin cy. Tng qut hn, tng bn di hai im u cui giao tip tin cy c th bao gm mt n lin kt vt l (v d nh trong trng hp ca mt giao thc truyn d liu cp lin kt) hoc mt lin kt mng ton cu (v d nh trong trng hp giao thc cp vn chuyn). Mc d vy, vi cc mc ch ca chng ta, chng ta c th xem tng thp hn n gin ch l mt knh im ni im khng ng tin cy. Trong phn ny, chng ta s tng bc pht trin cho bn gi v bn nhn mt giao thc truyn d liu ng tin cy, xt cc m hnh ngy cng phc tp ca knh c s. Hnh 3.4-1 b minh ha cc giao din cho cc giao thc truyn d liu ca chng ta. Bn gi i ca giao thc truyn d liu s c gi bng bng mt li gi n rdt_send(). N s c thng qua cc d liu c chuyn giao cho cc tng pha trn bn nhn. ( y, rdt l vit tt cho giao thc reliable data transfer v ch ra rng _send pha gi rdt ny ang c gi. Bc u tin trong vic pht trin cc giao thc l chn mt ci tn tt.) bn nhn, rdt_rcv() s c gi khi mt gi tin n t pha tip nhn ca knh truyn. Khi giao thc rdt mun cung cp d liu n cc lp pha trn, n s lm bng cch gi deliver_data(). Theo , chng ta s dng thut ng gi d liu thay cho on d liu cho n v d liu giao thc. Bi v l thuyt pht trin trong phn ny p dng cho cc mng my tnh ni chung, v khng ch vi tng vn chuyn, thut ng chung gi d liu c l l thch hp hn y. Trong phn ny, chng ta ch xem xt trng hp ca truyn d liu mang tnh cht iu khin mt chiu, ngha l, d liu truyn t bn gi n bn nhn. Trong trng hp ca truyn d liu ng tin cy hai chiu (v d song cng) l khi nim khng kh hn nhng kh t nht. Mc d chng ta xem xt ch truyn d liu mt chiu, iu quan trng cn lu l bn gi v bn nhn ca giao thc ca chng ta tuy th s cn phi truyn ti gi d liu trong c hai hng, nh c ch ra trong hnh 3.4-1. Chng ta s thy ngay rng ngoi vic trao i cc gi tin c cha cc d liu c truyn, bn gi v bn nhn ca giao thc truyn d liu ng tin cy cng s cn phi trao i cc gi iu khin i ra v tr li. C bn gi v bn nhn ca rdt gi cc gi d liu n pha bn kia bi mt li gi n udt_send() (Truyn d liu khng ng tin cy).

3.4.1 Xy dng mt giao thc truyn d liu tin cy


Truyn d liu tin cy qua knh tin cy tuyt i: rdt1.0 Chng ta trc tin xem xt trng hp n gin nht m , knh c s l hon ton ng tin cy. Bn thn giao thc, m chng ta s gi l rdt1.0, l tm thng. My hu hn trng thi (FSM) nh ngha cho rdt1.0 ngi gi v ngi nhn c hin th trong hnh 3.4-2. Cc FSM ngi gi v ngi nhn trong hnh 3.4-2 mi my ch c mt trng thi duy nht. Cc mi tn trong bn m t FSM cho thy s chuyn i ca giao thc t trng thi ny sang trng thi khc. (V mi FSM trong hnh 3.4-2 ch c mt trng thi, s chuyn i nht thit phi l t mt trng thi n chnh n, chng ta s sm thy cc s trng thi phc tp hn sau ). S kin gy ra s chuyn i c ch ra pha trn dng ngang ghi nhn s chuyn tip, v cc hnh ng khi s kin xy ra s c hin th di ng ngang. Pha gi ca rdt chp nhn d liu t cc tng trn qua s kin rdt_send(data), a d liu vo mt gi (thng qua hnh ng make_pkt(packet,data)) v s gi gi tin vo knh. Trong thc t, s kin rdt_send(data) s cho mt kt qu t mt li gi th tc (v d, rdt_send()) bi ng dng tng trn. bn nhn, rdt nhn mt gi tin t knh c s thng qua s kin rdt_rcv(packet), g d liu t cc gi d liu (thng qua hnh ng extract(packet,data)) v gi d liu ln cc tng trn. Trong thc t, s kin rdt_rcv(packet) s cho kt qu t mt li gi hm (v d, rdt_rcv()) t mt giao thc tng di. Trong giao thc n gin ny, khng c s khc bit gia mt n v d liu v mt gi d liu. Ngoi ra, tt c cc lung gi d liu t ngi gi n ngi nhn - vi mt knh hon ton ng tin cy khng cn thit pha bn nhn phi cung cp bt k thng tin phn hi no n bn gi v khng c g c th sai.

Hnh 3.4-2: rdt1.0 - mt giao thc cho knh hon ton tin cy Truyn d liu tin cy qua knh vi cc bit li: rdt2.0 Mt m hnh thc t hn ca cc knh c s l mt trong cc bit trong gi d liu c th b hng. Li bit nh vy thng xy ra cc thnh phn vt l ca mng nh mt gi tin c truyn, lan truyn, hoc c lu tr vo b m. Chng ta s tip tc gi s cho thi im tt c cc gi tin c gi i n ni (mc d mt s bit ca chng c th b hng) vi trt t nh khi chng c gi. Trc khi pht trin mt giao thc cho giao tip ng tin cy trn mt knh, trc tin hy xem xt lm th no ngi ta c th i ph vi nhng trng hp nh vy. Xem xt cch bn c th t to ra mt tin nhn di qua in thoi. Trong mt tnh hung in hnh, ngi nhn tin nhn c th ni "OK" sau mi cu c nghe thy, hiu, v ghi li. Nu ngi nhn tin nhn nghe mt cu ni b ct xn, bn s c yu cu lp li cu ni cu ni b ct xn . y chnh l giao thc tin nhn s dng c Acknowlegement tch cc ("OK") v tiu cc ("Lm n nhc li"). Cc thng ip iu khin cho php ngi nhn cho ngi gi bit nhng g c nhn mt cch chnh xc, v nhng g c nhn c li, v t i hi s lp li. Trong mt thit lp mng my tinh, cc giao thc truyn d liu tin cy da trn s truyn li nh vy c bit n l cc giao thc ARQ (Automatic Repeat reQuest - T ng yu cu nhc li). V c bn, hai kh nng giao thc b sung c yu cu trong cc giao thc ARQ x l s hin din ca cc li bit: Trc tin, pht hin li l mt c ch cn thit cho php ngi nhn pht hin khi cc bit li xut hin. Tr li phn 3.3 m , giao thc truyn thng UDP s dng trng checksum ca Internet cho chnh mc ch ny. Trong chng 5, chng ta s kim tra cc k thut pht hin li v sa li mt cch chi tit hn. Cc k thut ny cho php ngi ngi nhn pht hin, v ch ng sa

li cc gi bit li. By gi, chng ta ch cn bit rng nhng k thut yu cu cc bit m rng (ngoi cc bit d liu ban u cn c truyn i) c gi t ngi gi n ngi nhn; cc bit ny s c tp trung vo trng checksum gi d liu ca gi d liu rdt2.0. Tip nhn thng tin phn hi. V ngi gi v ngi nhn thng c thc hin trn cc h thng u cui khc nhau, c th cch nhau hng ngn dm, cch duy nht cho ngi gi bit ci nhn v th gii ca ngi nhn (trong trng hp ny, c hoc khng mt gi d liu c nhn mt cch chnh xc) l ngi nhn phi cung cp thng tin phn hi r rng cho ngi gi. Acknowledgement tch cc (ACK) v tiu cc (NAK) tr li trong kch bn tr li tin nhn nh mt thng tin phn hi. Giao thc Rdt2.0 ca chng ta tng t nh vy gi cc gi ACK v NAK tr li t bn nhn ti bn gi. V nguyn tc, nhng gi tin ny cn ch 1 bit di, v d, gi tr 0 ch ra mt NAK v gi tr 1 c th ch ra mt ACK. Hnh 3.4-3 cho thy cc FSM i din ca rdt2.0, mt giao thc truyn d liu s dng pht hin li, acknowledgement tch cc (ACKs) v tiu cc (NAKs). Bn gi ca rdt2.0 c 2 trng thi. Trong mt trng thi, giao thc bn gi ch cho d liu c chuyn t tng pha trn xung. trng thi ny, giao thc ngi gi ch mt gi ACK hoc mt NAK t pha ngi nhn. Nu mt gi ACK c nhn (k hiu rdt_rcv(rcvpkt) v l ACK(rcvpkt) trong hnh 3.4-3 tng ng vi s kin ny), ngi gi bit cc gi d liu gn y nht c truyn i c nhn chnh xc v do giao thc tr li trng thi ch d liu t lp pha trn. Nu NAK c nhn, giao thc truyn li gi tin cui cng v ch mt ACK hoc NAK tr v bi ngi nhn phn hi gi d liu c truyn. iu quan trng cn lu rng khi bn nhn trong trng thi ch mt ACK hoc mt NAK, n khng th ly thm d liu t lp pha trn; iu ch xy ra sau khi ngi gi nhn c ACK v ri b trng thi ny. Do , ngi gi s khng gi mt mu n v d liu mi cho n khi chc chn rng ngi nhn nhn chnh xc gi d liu hin ti. V hnh vi ny, cc giao thc nh rdt2.0 c bit n l cc giao thc dng-v-ch. FSM bn nhn ca rdt2.0 vn c mt trng thi. Khi gi tin ti ni, bn nhn tr li mt ACK hoc NAK, ty thuc vo c hay khng nhn c gi tin hng. Trong hnh 3.4-3, k hiu rdt_rcv(rcvpkt) v corrupt(rcvpkt) tng ng vi s kin m

mt gi tin c nhn v c tm thy c li.

Hnh 3.4-3: rdt2.0 mt giao thc cho mt knh vi li bit Giao thc rdt2.0 c th c mong i nhng khng may l khi hot ng n c mt l hng cht ngi. c bit, chng ta khng tnh n kh nng rng cc gi tin ACK hoc NAK c th l hng! (Trc khi tip tc, bn nn suy ngh v cch thc vn ny c th c c nh) Tht khng may, sai st nh ca chng ta khng phi l v hi nh n c th trng nh th. Ti thiu, chng ta s cn phi thm cc bit kim tra cho cc gi tin ACK / NAK pht hin cc li nh vy. Cu hi kh hn l lm th no giao thc c th phc hi cc li trong cc gi tin ACK hoc NAK. Kh khn y l nu mt ACK hoc NAK l hng, ngi gi khng c cch no bit c rng ngi nhn xc nhn mnh cui cng nhn c ca d liu truyn i hay cha. Xem xt ba kh nng x l hng ACK hoc NAK: i vi kh nng u tin, hy xem xt nhng g mt con ngi c th lm trong kch bn chnh t ca thng ip. Nu ngi ni khng hiu th cu tr li Vng hoc Xin vui lng nhc li s c lp li t ngi nhn, ngi ni c l s hi Bn ni g?' (do s

gii thiu mt loi gi tin t ngi gi-n-ngi nhn mi cho giao thc ca chng ta). Sau ngi ni s lp li cu tr li. Nhng iu g s sy ra nu cu Bn ni g ca ngi ni b hng? Ngi nhn, s khng hnh dung c l ci cu b bp mo y l mt phn chnh t hay l mt yu cu lp li cu tr li cui cng, do c th s phn ng li bng cu Bn ni g' V sau , tt nhin, phn hi c th b bp mo. R rng, chng ta ang i xung mt phn kh khn. Mt phng n thay th th hai l thm cc bit checksum (kim tra) cho php ngi gi khng ch pht hin, m cn phc hi t cc li bit. iu ny gii quyt vn ngay lp tc cho mt knh m c th b hng cc gi tin nhng khng lm mt chng. Mt cch tip cn th ba n gin l cho ngi gi gi li gi d liu hin ti khi m n nhn c mt gi tin ACK hoc NAK b bp mo. Tuy nhin, iu ny s a cc gi tin trng lp (cc gi tin b dup) vo knh gia ngi gi v ngi nhn. Kh khn c bn vi cc gi tin trng lp l ngi nhn khng bit c rng ACK hoc NAK m n gi i sau cng c c nhn ng ngi gi hay khng. V vy, n khng th bit tin nghim xem mt gi tin n s cha d liu mi hay l mt s truyn li! Mt gii php n gin cho vn mi ny (v l gii php c chp nhn trong hu ht cc giao thc truyn d liu hin nay k cTCP) l thm vo mt trng mi cho gi d liu v ngi gi s nh s cc gi d liu ca mnh bng cch t mt s th t vo trng ny. Ngi nhn sau ch cn kim tra s th t ny xc nh gi tin nhn c c phi l mt gi truyn li hay khng. i vi trng hp n gin ny ca mt giao thc dng-v-i, mt s th t 1-bit s l , v n s cho php ngi nhn bit c rng ngi gi gi li gi tin c truyn i trc y (s th t ca gi tin nhn c ging vi s th t ca gi tin nhn c gn y nht) hay mt gi mi (s th t thay i, ngha l, di chuyn chuyn tip trong php ton modul 2). V chng ta hin ang gi nh mt knh m khng b mt cc gi tin, do cc gi tin ACK v NAK bn thn chng khng cn phi ch ra s th t ca cc gi tin m chng ang ACKing hoc NAKing, v ngi gi bit rng mt gi tin ACK hoc NAK nhn c (cho d c b ct xn hoc khng) c to ra trong phn hi ca bn thn gi d liu c truyn i gn y nht.

Hnh 3.4-4: pha ngi gi ca rdt2.1

Hnh 3.4-5: pha ngi nhn ca rdt 2.1

Cc hnh 3.4-4 v 3.4-5 ch ra m t FSM cho rdt2.1, phin bn rdt2.1 n nh ca chng ta. By gi mi FSM pha ngi gi v ngi nhn ca Rdt2. c nhiu trng thi gp i so vi trc y. iu ny l bi v by gi trng thi giao thc phi phn nh xem hin ti gi tin c gi i (bi ngi gi) hay c k vng ( pha ngi nhn) nn c s th t l 0 hay 1. Lu rng cc hnh ng cc trng thi khi m mt gi tin nh s 0 ang c gi hay c k vng l hnh nh phn chiu ca hnh ng trong cc trng thi m mt gi tin nh s 1 ang c gi hoc c k vng; ch khc nhau l cch lm vi vic x l s th t . Giao thc rdt2.1 s dng c cc thng bo nhn tch cc v tiu cc t ngi nhn n ngi gi. Mt thng bo nhn tiu cc c gi bt c khi no nhn c mt gi tin b hng, hoc mt gi tin khng theo trt t. Chng ta c th t c cng mt kt qu nh ca mt NAK nu thay v gi mt NAK, chng ta thay bng vic gi mt ACK cho gi tin cui cng nhn c mt cch chnh xc. Mt ngi gi khi nhn c hai ACK cho cng mt gi tin (tc l, nhn c cc ACK dup) s bit rng ngi nhn khng nhn c chnh xc gi tin tip theo sau gi tin m c ACK hai ln. Nhiu th hin TCP s dng cng thc c gi l ba ACK dup (c tt c ba gi tin ACK ang ACK cho cng mt gi) kch hot mt c ch truyn li pha ngi gi. Giao thc truyn d liu tin cy khng c NAK ca chng ta cho mt knh c li bit l rdt2.2,c th hin trong Hnh 3.4-6 v 3.4-7.

Hnh 3.4-6: pha ngi gi ca rdt 2.2

Hnh 3.4-7: pha ngi nhn ca rdt 2.2

Truyn d liu tin cy qua mt Knh mt mt vi cc bit li: rdt 3.0 By gi gi s rng ngoi vic hng cc bit, th knh tng di cng c th b mt cc gi tin, mt s kin khng phi l him trong cc mng my tnh ngy nay (bao gm c Internet). Lc ny c hai mi quan tm b sung cn phi c gii quyt bng giao thc l: lm th no pht hin mt gi tin v phi lm g khi iu ny xy ra. Vic s dng checksumming, s th t, cc gi tin ACK, v truyn li - nhng k thut c pht trin trong rdt 2.2 - s cho php chng ta tr li cho mi quan tm th hai. X l mi quan tm u tin s i hi thm mt c ch giao thc mi. C nhiu cch tip cn c th hng n vic i ph vi mt gi tin (mt vi trong s s c khm ph trong cc bi tp cui chng ny). y, chng ta s t gnh nng ca vic pht hin v khc phc cc gi tin b mt pha ngi gi. Gi s rng ngi gi pht i mt gi d liu v hoc l gi tin , hoc l ACK nhn c cho gi tin b mt. Trong c hai trng hp, u khng c hi m no l ang i n ch ngi gi t ngi nhn. Nu ngi gi sn sng ch i lu th n s chc chn rng mt gi tin b mt, n c th ch n gin l truyn li gi d liu . Bn nn thuyt phc bn thn rng giao thc ny lm vic nh vy. Nhng ngi gi phi i bao lu chc chn rng mt ci g b mt? R rng l n phi ch t nht l bng thi gian tr kh hi (thi gian truyn i v) gia ngi gi v ngi nhn (ci m c th bao gm thi gian m ti cc router hoc cng(gateway) trung gian) cng vi bt k lng thi gian cn thit no x l mt gi tin pha ngi nhn. Trong nhiu mng, tr ti a trong trng hp xu nht ny thm ch l rt kh c lng, bit kh t v s chc chn. Hn na, v l tng giao thc ny nn phc hi vic mt gi tin cng sm cng tt; ch i mt tr trong trng hp xu nht c th c ngha l phi ch i lu di cho n khi vic khi phc li c bt u. Do phng php tip cn c chp nhn trong thc t l cho ngi gi khn ngoan chn mt gi tr thi gian m vic mt gi l c v thch hp, mc d khng bo m, rng vic mt gi xy ra. Nu mt ACK khng c nhn trong khong thi gian ny, th gi tin c truyn li. Lu rng nu mt gi tin tri qua mt thi gian tr c bit ln, th ngi gi c th truyn li gi tin ny thm ch khng ch khi gi tin b mt m cn khi ACK ca n b mt. iu ny a ra kh nng cc gi d liu

b trng lp trong knh ngi gi-ngi nhn. Tht may mn l giao thc rdt2.2 c chc nng (tc l, cc s th t) x l nhng trng hp trng lp cc gi tin. T quan im ca ngi gi, vic truyn li l mt phng thuc cha bch bnh. Ngi gi s khng bit c liu mt gi d liu mt, mt ACK b mt, hay gi tin hoc ACK ch n gin l qu chm tr. Trong mi trng hp, hnh ng l nh nhau: truyn li. thc hin mt c ch truyn li da trn thi gian, mt ng h m ngc s l cn thit ci m c th gin on pha ngi gi sau khi mt lng thi gian hn gi a ra kt thc. Do ngi gi s cn c th (i) bt u hn gi mi khi c mt gi tin (hoc mt gi d liu ln u tin, hoc mt truyn li) c gi, (ii) p ng mt gin on bm gi (ly ra nhng hnh ng thch hp), v (iii ) dng b hn gi. S tn ti ca nhng gi tin trng lp v mt gi (d liu, ACK) pht sinh t ngi gi cng lm phc tp vic x l pha ngi gi cho bt k mt gi ACK no m n nhn c. Nu mt ACK c nhn, lm th no ngi gi bit c gi tin c gi bi ngi nhn trong phn hi cho gi tin c truyn gn y nht ca n (ca ngi gi), hay l mt ACK b tr c gi trong phn hi cho mt gi d liu khc c truyn i trc ? Gii php cho vn tin thoi lng nan ny l lm tng thm cc gi tin ACK vi mt trng xc nhn (acknowledgement field). Khi ngi nhn to ra mt ACK, n s sao chp s th t ca gi d liu ang c ACK'ed vo trng xc nhn ny. Bng cch kim tra ni dung ca trng xc nhn, ngi gi c th xc nh s th t ca gi tin ang c xc nhn tch cc.

Hnh 3.4-8: FSM pha ngi gi ca rdt 3.0

Hnh 3.4-9: Hot ng ca rdt 3.0, giao thc bit lun phin Hnh 3.4-8 ch ra FSM pha ngi gi cho rdt3.0, mt giao thc truyn d liu ng tin cy qua mt knh m c th b hng hoc b mt cc gi tin. Hnh 3.4-9 ch ra cch thc giao thc hot ng m khng c gi d liu b mt hoc b tr, v cch thc n x l cc gi d liu b mt. Trong Hnh 3.4-9, thi gian di chuyn chuyn tip t pha trn cng ca biu hng v pha di cng ca biu ; lu rng thi gian nhn mt gi nht thit phi ln hn thi gian gi mt gi tin

nh l mt kt qu ca tr truyn tin v tr lan truyn. Trong Hnh 3.4-9 (b) - (d), cc gi () pha ngi gi cho bit thi gian m mt hn gi c thit lp v ln hn time out. Mt vi kha cnh tinh t hn ca giao thc ny c khm ph trong cc bi tp cui chng ny. Bi v s th t ca gi tin lun phin gia 0 v 1, do giao thc rdt3.0 i khi c gi l giao thc bit lun phin. By gi chng ta tp hp c cc yu t chnh ca mt giao thc truyn d liu. Cc checksum, s th t, b hn gi, v cc gi tin ACK tch cc v tiu cc mi ci ng mt vai tr rt quan trng v cn thit trong hot ng ca giao thc ny. By gi chng ta s lm vic vi giao thc truyn d liu ng tin cy!

3.4.2 Cc giao thc truyn d liu tin cy truyn bng ng ng


Giao thc rdt3.0 l mt giao thc chnh xc v mt chc nng, nhng n khng chc rng bt c ai cng c th hi lng vi hiu qu ca n, c bit l trong cc mng tc cao ngy nay. Trng tm ca vn v hiu sut ca rdt3.0 l mt thc t rng n l mt giao thc dng-v-i. nh gi tc ng ca hnh vi dng-v-i vi hiu sut, xt mt trng hp l tng ca hai host u cui, mt ci nm trn b bin pha ty ca Hoa K v ci cn li nm trn b bin pha ng. Tr lan truyn tc nh sang, Tprop , gia hai h thng u cui ny l khong 15 miligiy. Gi s rng chng c kt ni bi mt knh vi cng sut, C, bng 1 Gigabit (10 ** 9 bits) / giy. Vi mt kch thc gi tin, SP, bng 1K byte/gi bao gm c cc trng header v d liu, thi gian cn thit thc s truyn gi tin vo lin kt 1Gb/s l Ttrans = SP/C = (8 Kbit/gi tin)/ (10**9 bit/giy) = 8 microgiy Vi giao thc dng-v-ch ca chng ta, nu ngi gi bt u gi gi tin ti thi im t=0, th ti thi im t=8 microgiy bit cui cng c y vo knh pha ngi nhn. Sau gi tin thc hin hnh trnh xuyn quc gia 15 miligiy ca mnh, nh c miu t trong Hnh 3.4-10a, vi bit cui cng ca gi tin xut hin pha ngi nhn ti thi im t=15,008 miligiy. n gin, gi s rng cc gi tin ACK c kch thc ging nh cc gi d liu v rng ngi nhn c th bt u gi mt gi ACK ngay sau khi bit cui cng ca mt gi d liu c nhn, bit cui cng ca gi tin ACK s xut hin tr li pha ngi nhn ti thi im t = 30,016 msec. Nh vy, trong 30,016 msec, ngi gi ch bn rn (gi v nhn)

trong 0,016 msec. Nu chng ta nh ngha vic s dng ca ngi gi (hoc knh) l phn nh trong thi gian ngi gi thc s bn rn vi vic gi cc bit vo knh ny, chng ta c mt s dng ngi gi kh nh, Usender, bng Usender = (.008/ 30.016) = 0.00015 iu tc l, ngi gi ch bn rn trong 1,5 phn trm ca mt phn trm thi gian. Nhn theo mt cch khc, ngi gi ch c th gi 1K bytes trong 30,016 mili giy, cng sut thc s ch l 33KB/sec - thm ch rng mt lin kt 1Gigabit/giy l c sn! C th on c rng ngi qun l mng s khng hi lng nhng ngi m ch cn tr mt khon tin cho mt lin kt cng sut gigabit nhng qun l c mt thng lng ch l 33KB! y l mt v d in hnh v cch thc cc giao thc mng c th b gii hn kh nng cung cp bi phn cng mng c bn. Ngoi ra, chng ti b b qun thi gian x l ca cc giao thc tng thp hn pha ngi gi v ngi nhn, cng nh cc tr x l v tr do xp hng m c th xy ra bt k router trung gian no gia ngi gi v ngi nhn. Tng hp cc tc ng ny ch phc v cho vic tng thm thi gian tr v lm ni bt hn na hiu sut thp km .

Hnh 3.4-10: Giao thc dng-v-i so vi giao thc truyn bng ng ng Gii php cho vn hiu sut c bit ny l mt gii php n gin: thay v hot ng theo kiu dng-v-i, ngi gi c php gi nhiu gi tin m khng cn phi i cc ACK, nh c ch ra trong Hnh 3.4-10(b). Do cc gi tin ang c vn chuyn t ngi gi n ngi nhn c th c hnh dung nh l ang lp y vo mt ng ng dn, k thut ny c gi l pipelining. Pipelining c

mt s h qu cho cc giao thc truyn d liu tin cy: Phm vi ca cc s th t phi c tng ln, bi v mi gi tin ang c truyn i (khng k n vic truyn li) phi c mt s th t duy nht v c th c nhiu gi tin cha c ACK ang c truyn i. Pha ngi gi v pha ngi nhn ca cc giao thc c th m cho nhiu hn mt gi tin. Ti thiu, ngi gi phi c cc gi tin m c truyn i, nhng cha c ACK. Vic m cc gi d liu nhn c chnh xc c th cng cn thit pha ngi nhn, nh s tho lun di y. Cc yu cu v phm vi ca cc s th t cn thit v b m s ph thuc vo cch thc m mt giao thc truyn d liu p ng cc gi tin b mt, b hng, v qu chm tr. Hai phng php tip cn c bn theo hng khi phc li vi pipelined c th c xc nh: Go-Back-N v lp li chn lc (selection repeat).

3.4.3 Go-Back-N (GBN)

Hnh 3.4-11: Ci nhn ca ngi gi v cc s th t trong Go-Back-N Trong mt giao thc Go-Back-N (GBN), ngi gi c php truyn nhiu gi tin (khi c sn) m khng phi i mt ACK no c, nhng b gii hn khng th c nhiu hn s lng cho php ti a, N, ca cc gi tin cha c ACK trong pipeline. Hnh 3.4-11 ch ra ci nhn ca ngi gi v ln ca cc s th t trong mt giao thc GBN. Nu chng ta nh ngha base cho s th t ca gi tin cha nhn c ACK lu i nht v nextseqnum cho s th t cha c s dng nh nht (tc l, s th t ca gi tin tip theo c gi), th c bn on trong min s th t c th c xc nh. Cc s th t trong on [0,base-1] tng ng vi cc gi tin m thc s c truyn v c ACK. on [base, nextseqnum-1]tng ng vi cc gi tin c gi i nhng cha c ACK. Cc s th t trong on [nextseqnum, base+N-1] c th c s dng cho cc gi

tin m c th c gi i ngay lp tc, cc d liu i ti t tng pha trn. Cui cng, cc s th t ln hn hoc bng base+N c th khng c s dng cho n khi mt gi tin cha c ACK xut hin trong pipeline c ACK. Nh c xut bi Hnh 3.4-11, min ca cc s th t c php cho cc gi tin truyn i nhng cha c ACK c th c xem nh mt ca s c kch c N trn min cc s th t. Theo giao thc hot ng, ca s ny trt v pha trc trn khng gian s th t. V l do ny, N thng c gi l window size (kch thc ca s) v giao thc GBN bn thn n nh l mt sliding window protocol (giao thc ca s trt). Bn c th t hi ti sao phi gii hn s gi tin ang qu hn, cha c ACK cho mt gi tr ca N trong khong trng u tin. Ti sao khng cho php mt s lng khng gii hn cc gi tin nh vy? Chng ta s xem ti Phn 3.5 rng iu khin lung l mt trong nhng l do p t mt gii hn bn ngi gi. Chng ta s kim tra mt l do lm nh vy trong Phn 3.7, khi chng ta nghin cu v kim sot tc nghn TCP. Trong thc t, s th t ca gi tin c cha trong mt trng c chiu di c nh trong header ca gi tin. Nu k l s bit trong trng s th t gi tin, th min xc nh ca cc s th t l trong khong [0,2k 1]. Vi mt min xc nh hu hn ca cc s th t, th tt c cc tnh ton lin quan n s th t phi c thc hin bng cch s dng s hc modulo 2k. (Tc l, khng gian s th t c th c dng nh mt chic nhn c kch c 2k, s th t 2k 1 ngay lp tc c theo sau bi s th t 0.) Nh li rng rtd3.0 c mt s th t 1-bit v mt min xc nh ca cc s th t l [0,1]. Mt s vn phn cui ca chng ny s tm hiu hu qu ca mt min xc nh hu hn ca cc s th t. Chng ta s xem ti Phn 3.5 rng TCP c mt trng s th t 32-bit, cc s th t TCP tnh bng byte trong lung byte thay v cc gi tin.

Hnh 3.4-12: M t FSM m rng cho pha ngi gi ca GBN

Hnh 3.4-13: M t FSM m rng cho pha ngi nhn ca GBN Hnh 3.4-12 v 3.4-13 a ra mt m t FSM m rng ca pha ngi gi v ngi nhn ca mt giao thc da trn ACK, khng c NAK, GBN. Chng ta nhc n m t FSM ny nh l mt FSM m rng khi m chng ta thm vo cc bin (tng t nh cc bin ca ngn ng lp trnh) cho base v nextseqnum, v cng thm vo cc thao tc ln cc bin v cc hnh ng c iu kin lin quan n cc bin ny. By gi lu rng m t FSM m rng ny l bt u trng hi ging nh mt c t ngn ng lp trnh. [Bochman 84] cung cp mt cuc kho st tuyt vi ca cc m rng c b sung cho cc k thut FSM cng nh cc k thut da trn ngn ng lp trnh khc cho vic xc nh cc giao thc. Ngi gi ca GBN phi p ng c ba loi s kin: c gi ra t pha trn. Khi rdt_send () c gi t bn trn, th u tin

ngi gi kim tra xem xem ca s y cha, tc l, c hay khng N gi tin ang qu hn, cha c ACK. Nu ca s l khng y, th mt gi c to ra v c gi i, v cc bin c cp nht mt cch thch hp. Nu ca s y, th ngi gi n gin ch tr li d liu tr v tng trn, mt du hiu ngm rng ca s ang y. Sau tng trn c l phi th li sau. Trong thc t thc hin, ngi gi nhiu kh nng s, hoc l m cho gi d liu ny (nhng khng phi ngay lp tc c gi i), hoc s c mt c ch ng b ha (v d, mt m hiu hoc mt c) ci m cho php tng pha trn gi rdt_send () ch khi ca s l khng y. Tip nhn mt ACK. Trong giao thc GBN ca chng ta, mt ACK cho gi c s th t n s c a n ACK tch ly, cho thy rng tt c cc gi tin vi mt s th t ln hn v k c n l c nhn ng pha ngi nhn. Chng ta s tr li vn ny ngay khi chng ta kim tra pha ngi nhn ca GBN. Mt s kin timeout. Tn ca giao thc Go-Back-N, c bt ngun t hnh vi ca ngi gi khi xut hin cc gi tin b mt hoc qu chm tr. Nh trong giao thc dng-v-ch, mt b hn gi mt ln na s c s dng phc hi t cc gi d liu hoc ACK b mt. Nu xy ra timeout, ngi gi s truyn li tt c cc gi c gi trc nhng cha c ACK. Pha ngi gi ca chng ta trong Hnh 3.4-12 ch s dng mt b m thi gian duy nht, ci m c th c dng nh mt b m thi gian cho cc gi truyn i nhng cha c ACK lu i nht. Nu mt ACK c nhn, nhng vn c cc gi tin truyn i nhng cha c ACK thm vo, th b hn gi c khi ng li. Nu khng c gi tin cha nhn c ACK ang qu hn, th b hn gi c ngng li. Cc hnh ng ca ngi nhn trong GBN cng kh n gin. Nu mt gi tin vi s th t l n c nhn mt cch chnh xc v theo th t (tc l, d liu n ni cui cng t tng cao hn n t mt gi tin c s th t n-1), ngi nhn s gi mt ACK cho gi tin n v a phn d liu ca gi tin n tng cao hn. Trong tt c cc trng hp khc, ngi nhn loi b gi tin v truyn li mt ACK cho gi tin ng th t nhn c gn y nht. Lu rng khi cc gi tin c chuyn mt ln ti mt thi im n tng cao hn, nu gi k c nhn v c chuyn ti ni, th tt c cc gi tin vi mt s th t nh hn k cng c

chuyn giao. V vy, vic s dng cc ACK tch ly l mt la chn t nhin cho GBN. Trong giao thc GBN ca chng ta, ngi nhn loi b cc gi tin khng ng th t. Trong khi n c v ng ngn v lng ph khi loi b mt gi tin c nhn chnh xc (nhng khng ng th t), th c mt s l do lm nh vy. Nh li rng ngi nhn phi phn phi d liu, theo th t, n tng cao hn. Gi s by gi m gi tin n ang c k vng (c ch i), nhng gi tin n+1 li i n. Bi v d liu phi c phn phi theo th t, do ngi nhn c th m (lu li) gi tin n+1 v sau cung cp gi tin ny n tng cao hn sau khi n nhn c v cung cp gi tin n. Tuy nhin, nu gi tin n b mt, th c n v gi tin n+1 cui cng s c truyn li nh l kt qu ca quy tc truyn li GBN pha ngi gi. V vy, ngi nhn c th ch n gin l loi b gi tin n+1. u im ca phng php ny l s n gin ca b m pha ngi nhn ngi nhn khng cn phi m bt c gi tin khng ng th t no. V vy, trong khi ngi gi phi duy tr cc gii hn trn v di ca ca s ca n v v tr ca nextseqnum trong ca s ny, th mu thng tin duy nht ngi nhn cn duy tr l s th t ca gi tin tip theo theo th t. Gi tr ny c cha trong bin expectedseqnum, ch ra trong FSM pha ngi nhn trong Hnh 3.4-13. Tt nhin, bt li ca vic vt i mt gi tin nhn c mt cch chnh xc l ln truyn li sau ca gi tin c th b mt hoc b ct xn v nh vy thm ch cn b yu cu truyn li nhiu hn.

Hnh 3.4-14: Go-Back-N trong khi hot ng Hnh 3.4-14 ch ra hot ng ca giao thc GBN cho trng hp kch thc ca s bng bn gi tin. Bi v gii hn kch thc ca s nh th, cho nn ngi gi s gi cc gi tin t 0 n 3 nhng sau phi i cho n khi c mt hoc nhiu hn cc gi tin trn c ACK trc khi tip tc truyn. Vi mi ACK k tip (v d, ACK0 v ACK1) c nhn, th ca s trt v pha trc v ngi gi c th truyn i mt gi tin mi (tng ng vi,pkt4 v pkt5). V pha ngi nhn, gi 2 b mt v v vy cc gi tin 3, 4, v 5 c tm thy khng theo th t s b b i.

Trc khi kt thc tho lun ca chng ta v GBN, th cn phi ch rng mt thc hin ca giao thc ny trong mt chng giao thc c kh nng s c cu trc tng t nh ca FSM m rng trong Hnh 3.4-12. Vic thc hin cng c th di dng cc th tc khc nhau nhng ci m thc hin cc hnh ng c a ra trong phn hi ca cc s kin khc nhau c th xy ra. Tng t nh trong lp trnh da trn s kin, cc th tc khc nhau c gi (c gi ra), hoc l bi cc th tc khc trong chng giao thc, hoc l kt qu ca mt ngt. pha ngi gi, nhng s kin ny s l (i) mt cuc gi t cc thc th ca tng cao hn gi n rdt_send (), (ii) mt ci ngt ca b m thi gian, v (iii) mt cuc gi t tng thp hn gi n rdt_rcv () khi mt gi tin n ni. Cc bi tp lp trnh cui chng ny s cho bn mt c hi thc s thc hin nhng cng vic trong mt m phng, nhng thc cht l, thit lp mng. Chng ti lu y rng giao thc GBN kt hp vi hu ht cc k thut m chng ta s gp khi chng ta nghin cu cc thnh phn truyn d liu tin cy ca TCP ti Phn 3.5: s dng cc s th t, cc ACK tch ly, cc checksum, v thao tc timeout/retransmit. Tht vy, TCP thng c bit n nh l mt giao thc kiu GBN. Tuy nhin, n c mt s khc bit. Nhiu th hin ca TCP s m nhng segment nhn-c-chnh-xc-nhng-khng-theo-th-t [Stevens 1994]. Mt sa i c xut cho TCP, ci gi l ACK chn lc [RFC 2018], cng s cho php pha nhn ca TCP ACK c chn lc mt gi tin khng theo th t duy nht thay v ACK tch lu cho gi tin nhn c chnh xc cui cng. Khi nim v mt ACK c chn lc l trng tm ca lp bao qut th hai ca cc giao thc pipelined: c gi l cc giao thc lp li c chn lc.

3.4.4 Lp li c chn lc (SR-Selective Repeat)


Giao thc GBN cho php ngi gi c kh nng y vo ng ng dn trong Hnh 3.4-10 bng cc gi tin, v vy vic trnh cc vn v s dng knh truyn chng ta s ghi ch bng cc giao thc dng-v-ch. Tuy nhin, c nhiu kch bn trong bn thn GBN s gp phi cc vn v hiu sut. c bit, khi kch thc ca s v kt qu tr bng thng c hai u ln, th nhiu gi tin c th c nm trong pipeline. Mt li gi tin duy nht do c th gy ra cho GBN vic truyn li mt s lng ln cc gi tin, nhiu gi tin trong s c th l khng cn thit. Khi xc sut cc li ca knh tng, th ng ng dn c th tr thnh b y bi nhng truyn li khng cn thit. Hy tng tng trong kch bn

chnh t thng ip ca chng ta, nu mi ln mt t b ct xn, th 1000 t xung quanh n (v d, mt kch thc ca s bng 1000 t) s b lp li. Bi chnh t ny s b lm chm li bi tt c cc t nhc li. Nh tn gi cho thy, giao thc Lp li c chn lc (SR) trnh truyn li khng cn thit bng cch ngi gi ch truyn li nhng gi tin m n nghi ng nhn c li (tc l b mt hoc b hng) pha ngi nhn. iu c bit ny, l cn thit, vic truyn li s yu cu rng ngi nhn xc nhn ring bit cc gi tin c nhn chnh xc. Mt kch thc ca s bng N mt ln na s c s dng hn ch s lng cc gi tin ang qu hn, cha c ACK trong ng ng. Tuy nhin, khng ging nh GBN, ngi gi s c cc ACK c nhn cho mt s gi tin trong ca s. Hnh 3.4-15 cho thy ci nhn v khng gian s th t ca ngi gi trong SR. Hnh 3.4-16 s chi tit ho cc hnh ng khc nhau c a ra bi ngi gi ca SR. Ngi nhn ca SR s xc nhn xem mt gi tin c nhn mt cch chnh xc hay khng theo th t. Cc gi tin khng theo th t c m cho n khi bt k mt gi b mt no (tc l, cc gi c s th t thp hn) c nhn, ti thi im mt lot cc gi tin c th c chuyn i n lp trn. Hnh pha ngi nhn phn loi cc hnh ng khc nhau c a ra bi ngi gi ca SR. Hnh 3.4-18 cho thy mt v d v hot ng ca SR vi s xut hin ca cc gi b mt. Lu rng trong Hnh 3.4-18, ngi nhn ban u m cc gi 3 v 4, v phn phi chng cng vi gi 2 n tng trn khi gi 2 cui cng cng nhn c.

Hnh 3.4-15: Khung nhn khong s th t bn pha ngi gi v ngi nhn ca SR 1. D liu nhn c t tng trn. Khi d liu c nhn t tng trn, pha ngi gi ca SR s
kim tra s th t c th s dng tip theo cho gi tin . Nu s th t nm bn trong ca s ca ngi gi, th d liu c ng gi v c gi i; nu khng n hoc l c m hoc l b tr li cho tng cao hn truyn sau ny, ging nh trong GBN.

2. Timeout. B nh gi mt ln na c s dng bo v chng li cc gi d liu b mt. Tuy


nhin, by giwof mi gi phi c b m thi gian logic ring ca n, v ch c mt gi duy nht s c truyn i khi timeout. Mt b m thi gian phn cng duy nht c th c s dng bt chc cc hot ng ca nhiu b nh gi logic.

3. ACK nhn c. Nu mt ACK c nhn, th ngi gi ca SR s nh du gi tin l


c nhn, min l n ang trong ca s. Nu s th t ca gi bng sendbase, th ca s c s c di chuyn v pha trc n ch gi tin vi s th t nh nht cha c ACK. Nu ca s di chuyn v c cc gi tin vi s th t hin ang nm trong ca s m cha c truyn, th cc gi tin s c truyn i.

Hnh 3.4-16: Cc thao tc pha ngi gi ca Selective Repeat

1. Gi vi s th t trong khong [rcvbase, rcvbase + N-1] c nhn mt cch chnh xc. Trong trng hp ny, gi tin nhn c nm trong ca s nhn v mt gi tin ACK c chn lc c tr li cho ngi gi. Nu gi tin trc khng nhn c, th n c m (y vo b m). Nu gi tin ny c s th t bng base ca ca s nhn (rcvbase trong hnh 3.4-15), th gi tin ny, v bt k gi tin no c m trc n v c nh s lin tip (bt u t rcvbase) s c chuyn giao cho tng cao hn. Ca s nhn sau s di chuyn v pha trc bng s lng cc gi tin c chuyn giao cho tng cao hn. Xt mt v d, xt Hnh 3.4-18. Khi mt gi tin vi s th t = rcvbase = 2 c nhn, n v cc gi rcvbase+1 v rcvbase + 2 c th c chuyn giao cho tng cao hn. 2. Gi vi s th t trong khong [rcvbase -N, rcvbase-1] c nhn. Trong trng hp ny, mt ACK phi c to ra, d cho y c l mt gi tin m ngi nhn trc y tng ACK. 3. Trng hp khc. B qua gi tin . Hnh 3.4-17: Cc thao tc pha ngi nhn ca Selective Repeat iu quan trng cn lu l bc 2 trong Hnh 3.4-17, ngi nhn xc nhn li (thay v b qua) cc gi tin nhn c vi s th t nht nh nh hn c s ca ca s hin ti. Bn nn thuyt phc bn thn rng vic xc nhn li ny l thc s cn thit. Ly cc khong s th t pha ngi gi v ngi nhn trong Hnh 3.415 lm v d, nu khng c ACK cho gi tin sendbase lan truyn t ngi nhn n ngi gi, th ngi gi cui cng s truyn li gi tin sendbase, mc d r rng (i vi chng ta, khng phi vi ngi gi!) rng ngi nhn nhn c gi tin ! Nu ngi nhn khng ACK cho gi tin ny, th ca s ca ngi gi s khng bao gi di chuyn tip! V d ny minh ha mt kha cnh quan trng ca cc giao thc SR (v nhiu giao thc khc cng nh vy): ngi gi v ngi nhn khng phi lun lun c mt ci nhn ging ht nhau v nhng g c nhn mt cch chnh xc v nhng g l khng. i vi cc giao thc SR, iu ny c ngha l cc ca s ca ngi gi v ngi nhn khng phi l s lun lun trng nhau.

Hnh 3.4-18: Hot ng ca SR

Hnh 3.4-19: Tnh trng kh x ca ngi nhn SR vi ca s kch thc ln: mt gi tin mi hay l mt s truyn li?

S thiu ng b gia cc ca s ca ngi gi v ngi nhn gy ra cc hu qu nghim trng khi chng ta phi i mt vi thc t l phm vi ca cc s th t l hu hn. Hy xem xt nhng g c th xy ra, v d, vi mt phm vi hu hn l bn s th t gi tin, 0,1,2,3 v mt kch c ca s l ba. Gi s cc gi t 0 n 2 c truyn i v c nhn mt cch chnh xc v c xc nhn pha ngi nhn. Ti thi im ny, ca s nhn c chuyn qua cc gi tin th t, th nm v th su gi, vi cc s th t l 3, 0, v 1, tng ng. By gi hy xem xt hai tnh hung. Trng hp u tin, th hin trong Hnh 3.4-19 (a), cc ACK cho ba gi tin u tin b mt v ngi gi truyn li cc gi tin . Do ngi nhn tip theo s nhn c mt gi tin vi s th t-0 mt bn sao ca gi u tin c gi i. Trong trng hp th hai, th hin trong Hnh 3.4-19 (b), cc ACK cho ba gi u tin tt c u c chuyn giao chnh xc. Do ngi gi s di chuyn ca s ca mnh v pha trc v gi cc gi tin th t, th nm v th su, vi cc s th t l 3, 0, 1, tng ng. Gi tin vi s th t l 3 b mt, nhng gi tin vi s th t 0 n ni- mt gi tin cha d lin mi. By gi hy xem xt quan im ca ngi nhn trong Hnh 3.4-19, trong c mt bc mn tng trng gia ngi gi v ngi nhn, do ngi nhn khng th thy cc hnh ng ca ngi gi. Mi quan st ca ngi nhn l trnh t ca cc thng ip m n nhn c t knh v gi vo trong knh . C v nh l n c lin quan n nhau, hai trng hp trong Hnh 3.4-19 l ging ht nhau. l khng c cch no phn bit vic truyn li ca gi tin u tin vi mt ln truyn ban u ca gi tin th nm. R rng l, vi mt kch thc ca s nh hn kch thc ca khng gian s th t s khng hot ng c. Nhng kch thc ca s phi nh nh th no? Mt vn phn cui ca chng ny s yu cu bn ch ra rng kch thc ca s phi nh hn hoc bng mt na kch thc ca khng gian s th t. Hy chng ti kt lun cuc tho lun ca chng ta v cc giao thc chuyn d liu ng tin cy bng cch xem xt mt gi nh cn li trong m hnh knh truyn c bn ca chng ta. Nh li rng chng ta gi nh rng cc gi tin khng th c xp xp li trong knh gia ngi gi v ngi rceiver. iu ny thng l mt gi thit hp l khi ngi gi v ngi nhn c kt ni bi mt ng dy vt l. Tuy nhin, khi cc knh kt ni hai my l mt mng li, th

gi tin c xp li theo trt t mi c th xy ra. Mt biu hin ca gi tin c xp xp l cc bn sao c ca mt gi tin vi mt s th t hoc s hiu ACK bng x c th xut hin, mc d khng phi ca s ca ngi gi cng khng phi ca s ca ngi nhn cha x. Vi gi tin c xp xp li, knh bn cht c th c coi nh cc gi ang c m v ang pht ra t ng ti bt k im no trong tng lai. Bi v cc s th t c th c ti s dng, do mt s chm sc phi c thc hin bo v chng li cc gi d liu trng lp. Phng php thc hin trong thc hnh l bo m rng mt s th t khng c ti s dng cho n khi ngi gi tng i chc chn rng bt k gi tin no c gi trc vi s th t x l khng cn trong mng. iu ny c thc hin bng cch gi s rng mt gi tin khng th sng trong mng lu hn mt s lng thi gian ti a c c nh. Thi gian sng ca mt gi tin ti a vo khong ba pht c gi nh trong cc phn m rng ca TCP cho cc mng tc cao [RFC 1323]. Sunshine [Sunshine 1978] m t mt phng thc s dng cc s th t nh vy m cc vn sp xp li c th hon ton trnh c.

Tham kho
[Bochman 84] G.V. Bochmann and C.A. Sunshine, "Formal methods in communication protocol design", IEEE Transactions on Communicaitons, Vol. COM-28, No. 4, (April 1980), pp 624-631. [RFC 1323] V. Jacobson, S. Braden, D. Borman, "TCP Extensions for High Performance," RFC 1323, May 1992. [RFC 2018] M. Mathis, J. Mahdavi, S. Floyd, A. Romanow, "TCP Selective Acknowledgment Options," RFC 2018, October 1996 [Stevens 1994] W.R. Stevens, TCP/IP Illustrated, Volume 1: The Protocols. Addison-Wesley, Reading, MA, 1994. [Sunshine 1978] C. Sunshine and Y.K. Dalal, "Connection Management in Transport Protocols", Computer Networks, Amsterdam, The Netherlands: NorthHolland", 1978.

3.5 Vn ti hng kt ni: TCP


C nhng vn cn tim n v ngun gc ca truyn ti d liu,chng ta cng i tm hiu TCP-tng vn ti,hng kt ni,giao thc truyn thng ng tin cy.Trong on ny,chng ta s thy c rng cung cp dch v truyn ti d liu tin cy TCP da rt nhiu vo cc phn trc .bao gm pht hin li,s truyn li ,cng nhn tch ly,timer field,header field .TCP c nh ngha trong RFC 793,RFC 1122,RFC 1323 RFC 2018,RFC 2581

3.5.1 The TCP Connection-Kt ni TCP


TCP cung cp b hp knh,phn knh v pht hin li(nhng khng sa c) trong cng li nh l UDP.Tuy nhin TCP v UDP c cch thc khc nhau.S khc bit ln nht l UDP l khng kt ni trong khi TCP l kt ni hng i tng.UDP l khng kt ni bi v cho php gi d liu ngay c khi cha c kt ni.TCP l kt ni hng i tng v trc khi mt trnh ng dng c gi d liu ti trnh ng dng khc , hai trnh ng dng phi thc hin ci bt tay u tin tc l chng phi gi thng ip s b cho nhau thnh lp tham s cho chuyn giao thng ip tip theo.Nh l mt phn ca kt ni TCP ,c hai phn lin kt s khi to nn bin trng thi TCP. Kt ni TCP khng l TDM-Time Division Multiplexing-Ghp knh phn chia theo thi gian hay l mch FDM-Frequency Division Multiplexing-Ghp knh phn chia theo tn s trong mng chuyn mch .Cng khng l mch o,hay nh l trng thi kt ni nm hon ton trong hai thit b cui.Bi v giao thc TCP ch chy trn h thng cui v khng thit b trung gian nh routers,bridges.Trong cc h thng trung gian duy tr trng thi kt ni TCP.Trn thc t thit b trung gian routers l khng c quan tm n trong kt ni TCP. Kt ni TCP cung cp 2 phng thc truyn d liu y . l d liu tng ng dng c th c truyn ti gia hai my ch- nu c mt kt ni gia tin trnh A v B ti mt thi im ,d liu truyn t tng ng dng B n A.Kt ni TCP cng l im ni im gia mt bn l gi,mt bn l nhn.V th c gi l k thut multicasting-truyn dn d liu t 1 h thng gi ti nhiu h thng nhn ch quan 1 hnh ng gi-khng th thc hin vi TCP.

Chng ta cng tm hiu xem kt ni TCP c thnh lp nh th no.Mt tin trnh ang chy trong mt my ch mun bt u kt ni vi mt tin trnh khc trong my ch khc .Ch rng my ch bt u to kt ni gi l client host v host khc gi l server host.Trnh ng dng client u tin cho bit TCP client- ci m mun to mt kt ni vi 1 tin trnh trong server. TCP trong client c to kt ni vi TCP trong server.Chng ta s tho lun chi tit hn v qu trnh thnh lp kt ni trong on cui.Cho n by gi,ta c th bit c rng: giai on 1 l Client gi 1 yu cu,th 2 l server p ng yu cu v cui cng l Client li a ra yu cu .Hai gia oan u khng ghi li d liu tng ng dng,giai on th 3 c tr li gi tr.Bi v 3 giai on l c gi gia 2 host ,qu trnh kt ni ny thng c gi nh l:3 ln bt tay. Mt kt ni TCp c thnh lp ,hai trnh ng dng c th gi d liu cho nhau bi v TCP l giao thc y ,chng c th cng gi d liu trong cng mt thi gian.Chng ta xem xt vic gi d liu t Client ti Server .Client thng qua lung d liu ti socket(nh trnh by 2.6).D liu qua ca socket c chy trong client .Nh trnh by 3.5.1 TCP gi d liu nay ftowis b m gi kt ni-l b m lu tr thng tin qu trnh 3 ln bt tay.Sau tng khong thi gian,TCP chp ly tng on d liu t b m gi. ln ca d liu c th qua c ca s l on gii hn gi l MSS.MSS ph thuc vo OS v c th nh dng ,ph bin l 1.500bytes,536bytes v 512bytes.(C on d liu ny thng c la chn trnh phn chia IP-c trnh by chng tip theo).Ch rng MSS l ln cc i ca on d liu ,khng phi l di cc i ca trang gm cc on TCP .Thut ng ny kh hiu nhng chng ta phi s dng n.

Figure 3.5-1: TCP send and receive buffers TCP c tm lc li gm d liu client v header,bng cch nh dng phn on TCP.Phn on c b qua trong tng mng ,chng khng lin quan n nhau trong IP datagrams tng mng.Khi TCP nhn mt on ti thit b cui khc,on d liu c a vo b m nhn kt ni.ng dng c lung d liu t b m ny .Mi mt cnh lin kt l ca b m gi v b nhn ca n.B m gi v nhn cho bit trn d liu. T nhng tm hiu trn cho chng ta thy kt ni TCP bao gm b m ,bin,v socket kt ni ti 1 tin trnh trong 1 my ch,v tp cc b m ,bin v socket khc kt ni vi 1 tin trnh trong nhng host khc.Nh nhc n t trc, khng c vng m hoc bin cp kt ni trong cc phn (nh tuyn,trung gian)gia cc host.

3.5.2 TCP Segment Structure(Cu trc phn on TCP)


c c ci nhn khi qut v kt ni TCP ,chng ta xem xt cu trc phn on ca n.Phn on TCP gm header v trng d liu .Vng d liu cha d liu,nh trn cp,MSS gii hn kch thc trng on d liu.Khi TCP gi mt file ln nh hnh nh,mt phn ca trang Web.N s c chia thnh cc on d liu c kch thc MSS.ng dng tng tc,ty nhin thng truyn dn d liu c kch thc nh hn MSS,cho v d: ng nhp vo ng dng ging nh

Telnet vng d liu trong phn on TCP thng ch l 1 byte.Bi v trng m u TCP c kiu l 20 bytes(12 bytes cho UDP header) phn on gi bi Telnet ch c th di 21 bytes. on 3.3-2 l cu trc phn on ca TCP.Ging nh UDP,trng m u header gm s hiu cng ngun v cng ch,c dng cho hp knh,phn knh d liu cho tng ng dng cao hn.Cng nh UDP .header gm trng kim tra tng .Trng m u TCP gm cc trng: The32-bit sequence number field- trng ny cha s hiu ca byte u tin ca phn on pht i, and the 32-bit acknowledgment number field-trng ny cha s th t ca byte d liu tip theo Host nhn.c dng bi b phn gi v nhn TCP trong dch v truyn d liu ng tin cy. Window -16 bit c dng cho mc ch iu khin lung.Ca s cho ta bit c s bytes c th chp nhn c. Length field quy nh di ca header TCP l 32 bit.Header TCP c th thay i c chiu di (c bit nu trng rng th di ca TCP header l 20 byte) Options field Trng ty chn-dng khi bn gi v nhn thng lng v kch thc phn onMSS hoc ca s cn d tha s dng mng tc cao.Mi la chn u c nh ngha..S thy r hn qua RFC 854.RCF 1323 Flag field-trng c.6 bits.bit ACK xc nhn gi d liu c cng nhn trong trng xc nhn.RST,SYN,FIN ci t kt ni v hy b kt ni.chng ta s tm hiu trong phn sau.Khi PSh c thnh lp , l biu hin ca bn nhn truyn d liu ti tng cao hn ngay lp tc.Cui cng l URG cho bit c d liu khn cp trong phn on cn c x l sm.V tr ca cc bit sau ca d liu khn cp c xc nh bi con tr 16 bit.TCP phi cho bit s tn ti tng cao hn ca bn nhn khi d liu khn cp tn ti v chuyn n ti con tr cui .(Trong phn luyn tp PSH,URG v con tr d liu khn cp khng c s dng.Tuy nhin chng ta a ra y cho y )

3.5.3 Sequence Numbers and Acknowledgment Numbers


Hai trong s trng quan trng nht ca phn on m u TCP l Sequence Numbers and Acknowledgment Numbers.Cc trng ny l mt phn quan trng ca dch v truyn ti d liu ng tin cy.Nhng trc khi tho lun xem cc trng ny cung cp dch v truyn d liu ng tin cy nh th no ,chng ta trc ht gii thch chnh xc nhng g TCP t trong trng ny. TCP xem d liu khng c cu trc,nhng c quy tc,theo lung.TCP s dng s hiu phn nh s hiu ang trn ng truyn v khng phi qua hng lot cc phn on khc.S hiu cho mt phn on l s byte u tin ca dng byte trong phn on.Chng ta cng xem xt mt v d.Cho mt tin trnh trong Host A mun gi mt lung d liu t mt tin trnh trong Host B c kt ni TCP.TCP ca Host A s s ha mi byte trong tng dng d liu.Cho lung d liu bao gm 1 file vi 500.000 bytes , MSS l 1000 bytes v byte u tin ca lung d liu l 0.Nh trnh by 3.5.3 TCP t ra 500 on trong lung d liu .on u tin mc nh l s 0,on th 2 l 1000,on th 3 l 2000Mi s hiu c chn vo trng s hiu trong header ca phn on TCP.

Figure 3.5-3: Dividing file data into TCP segments. By gi chng ta xem xt acknowledgment numbers.Cn c mt cht tinh t hn sequence numbers.Nhc li rng TCP truyn d liu theo ch song cng.V th my ch A c th nhn d liu t my ch B trong khi n cng ang gi d liu cho my B.Mi mt on c gi n t my ch B c mt s hiu ch php d liu truyn t B ti A. The acknowledgment number-Host A t vo n s th t byte tip theo m Host A s nhn t host B.Tht n gin khi xem xt mt vi v d hiu c iu ang ni y.Cho rng host A nhn s th t 0 qua cng 535 t host B v n chun b gi 1 on d liu cho host B.Host A ang i byte 536 v tt c byte sau trong lung d liu ca host B .V th Host A t 536 vo vng xc nhn ca on m n gi cho B. Hay mt v d khc ,cho host A nhn 1 on d liu t Host B cha byte 0 qua 535 v nhng on khc cha byte 900 qua 1000.Bit rng host A vn cha nhn byte 536 qua 899.Trong v d ny Host A vn ang i byte 536 trong vng xc nhn.Bi v TCP ch xc nhn nhng bytes u tin b nh trong lung.TCP c nhc n l cumulative acknowledgements V d cui ny cng mang li mt iu quan trng nhng tinh t.Host A nhn on th 3 trc khi nhn on 2.Tht vy,on 3 c gi n khng th t.Tinh t ch:Host lm g khi n nhn on khng th t trong kt ni TCP.Th v:RFCs TCP khng p t mt quy tc no li quyt nh cho ngi lp trnh thc hin giao th TCP.C hiai s la chn c bn:th 1 l nhn ngay lp tc loi b nhng bytes khng th t.th 2 l nhn v gi li nhng bytes khng th t v i cho nhng bytes cn thiu in vo ch trng.R rng la chn 2 cho hiu qu hn trong bng thng.Nhng ngc li l la chn 1 d dng m ha TCP hn.Trong phn cn li chng ta cng tp trung vo la chn 1 tc l,coi TCP loi b on khng th t.

Trong on 3.5.3 chng ta gi thit rng chui ban u l 0 .Thc t,c 2 on ca TCp u chn ngu nhin th t ban u. iu ny c thc hin gim thiu kh nng xy ra mt phn on m vn cn hin din trong h thng mng t trc -chm dt kt ni gia hai my l nhm ln vi mt phn on hp l trong mt kt ni sau gia hai my .

3.5.4 Telnet: A Case Study for Sequence and Acknowledgment Number


Telnet c nh ngha trong RFC 854,l mt giao thc tng ng dng s dng ng nhp t xa.N chy trn TCP v c nh ngha lm vic gia cc cp Host.Khng ging nh ng dng truyn ti d liu c tho lun chng 2.Telnet l ng dng tng tc.Chng ta cng tm hiu mt v d v telnet,nh l minh ha v trnh t TCP v s hiu cng nhn Cho Host 88.88.88.88,u tin l phin bn Telnet vi host 99.99.99.99().Bi v host 88.88.88.88 c gn nhn l client v host 99.99.99.99 c gn nhn l server.Mi mt kiu k t c cho bi ngi s dng (ti client ) s c gi ti host t xa ,host ny s gi li mt bn saoo ca mi k t ci m s c hin th trn mn hnh ca ngi s dng Telnet.C ch echo back ny c s dng khng nh rng cc k t c c bi ngi s dng Telnet c chp nhn v c x l t xa.mi k t i qua 2 mng khi ngi s tm ra kha v khi cc k t c hin th trn mn hnh . By gi cho vn bn n,C,chng ta xem xt phn on TCP c gi gia client v server.Nh trnh by on 3.5.4.chng ta cho mt s hiu th t bt u l 42 v 79 cho client v server.Nhc li rng s th t ca mt phn on l s th t ca byte u tin trong trng d liu.Tht vy,phn on u tin gi t client s c s th t l 42 v ,phn on u tin gi t server c s th t l 79.S hiu cng nhn l s th t ca byte tip theo ca d liu m host ang i.Sau kt ni TCP c thnh lp nhng trc khi d liu c gi ,client i cho byte 79 v server i byte 42.

Figure 3.5-4: Sequence and acknowledgment numbers for a simple Telnet application over TCP Nh hnh 3.5.4 l 3 phn on c thc hin.Phn on u tin c gi t client ti server,cha mt byte m ASCII biu din k t C trong trng d liu ca n.Phn on u tin ny cng c 42 trong trng s th t nh va miu t.Cng bi v client cha nhn d liu t server ,phn on ny s c s th t 79 trong trng s th t cng nhn. Phn on th 2 c gi t client ti server .N c hai chc nng.Th nht l cung cp yu cu chp nhn d liu m client c th nhn c.Bng cch t s th t 43 vo trng cng nhn ,server s bo cho client bit rng n nhn tt c cho ti byte 42 v ang ch vi byte 43..Chc nng th 2 l tr li C.Tht vy ,on th 2 c bng m ASCII biu din C trong trng d liu.Phn on th 2 ny c s th t 79,d liu v s th t ban u ca server-client b trn trong kt ni TCP.nh vy,y l byte u tin ca d liu m server gi..Ch rng,xc nhn d liu client-server c thc hin trong on thc hin kt ni d liu client-server.xc nhn ny c gi l Piggybacked .

Phn on 3 l t client ti server.Chc nng ca n l xc nhn d liu c chp nhn t server.Trong on ny trng d liu l rng.Phn on c s th t l 80 v client nhn lung byte cho n s th t 79 v ang i byte 80.Nhng TCP c trng th t ,phn on ny cn c s th t.

3.5.5 Truyn d liu tin cy


Dch v tng mng ca Internet khng tin cy: IP khng m bo vic chuyn datagram, khng m bo gi datagram ng th t cng nh khng m bo tnh ton vn d liu. Vi dch v IP, datagram c th b trn ti b m router v do khng bao gi n c ch, d liu c th n khng ng th t hay cc bit trong datagram c th b li. Bi v segment ca tng vn ti c t trong IP datagram truyn qua mng nn segment ca tng giao vn cng c th phi gp nhng vn nu trn. TCP to ra mt dch v truyn d liu tin cy trn dch v khng tin cy ca IP. C nhiu giao thc ng dng cng cng bao gm c FTP, SMTP, NNTP, HTTP v Telnet s dng TCP thay v UDP trc ht bi v TCP cung cp dch v truyn d liu tin cy. Dch v truyn d liu tin cy ca TCP m bo dng d liu ti tin trnh nhn khng c li, lin tc, khng trng lp d liu, ng th t. C ngha l dng byte nhn c ging ht dng byte gi i bi h thng u cui pha cn li ca kt ni. Trong mc ny chng ti s cung cp mt ci nhn tng quan v cch thc TCP cung cp truyn d liu tin cy. Chng ta s thy rng dch v truyn d liu tin cy ca TCP s dng nhiu nguyn l m chng ta hc trong Phn 3.4.

Truyn li
Vic truyn li cc d liu b mt v b hng l rt quan trng cung cp truyn d liu tin cy. TCP cung cp truyn d liu tin cy bng cch s dng cc ACK tch cc v cc timer(b nh gi) theo cch tng t nh chng ta nghin cu trong phn 3.4. TCP xc nhn nhng d liu c nhn ng, v truyn li cc segment khi cc segment hoc cc ACK tng ng ca chng c cho l b mt hoc b hng. Cng nh trong trng hp giao thc truyn d liu tin cy ca chng ta, rdt3.0, TCP t bn thn n khng th khng nh chc chn rng mt segment, hoc ACK ca n, b mt, b hng, hay b tr. Trong mi trng hp, phn ng ca TCP s ging nhau: truyn li segment b nghi vn.

TCP cng s dng pipelining, cho php ngi gi c nhiu segment c-truyni-nhng-cha-c-xc-nhn ang qu hn ti bt c thi im no. Chng ta thy trong phn trc rng pipelining c th ci thin ng k thng lng ca mt kt ni TCP khi t l kch thc segment/tr kh hi l nh. S lng c th ca cc phn on cha c xc nhn ang qu hn m mt ngi gi c th c c quyt nh bi cc c ch iu khin lung v iu khin tc nghn ca TCP. iu khin lung TCP s c tho lun cui phn ny; kim sot tc nghn TCP s c tho lun trong Phn 3.7. Trong lc ny, chng ta ch n gin l phi thc c rng ngi gi c th c nhiu segment c truyn i, nhng cha c xc nhn ti bt k thi im no.
/* assume sender is not constrained by TCP flow or congestion control, that data from above is less than MSS in size, and that data transfer is in one direction only */ sendbase = initial_sequence number /* see Figure 3.4-11 */ nextseqnum = initial_sequence number loop (forever) { switch(event) event:data received from application above create TCP segment with sequence number nextseqnum start timer for segment nextseqnum pass segment to IP nextseqnum = nextseqnum + length(data) event: timer timeout for segment with sequence number y retransmit segment with sequence number y compue new timeout interval for segment y restart timer for sequence number y event: ACK received, with ACK field value of y if (y > sendbase) { /* cumulative ACK of all data up to y */ cancel all timers for segments with sequence numbers < y sendbase = y } else { /* a duplicate ACK for already ACKed segment */ increment number of duplicate ACKs received for y if (number of duplicate ACKS received for y == 3) { /* TCP fast retransmit */ resend segment with sequence number y restart timer for segment y } } /* end of loop forever */

Hnh 3.5-5: n gin ho ngi gi TCP

Hnh 3.5-5 cho thy ba s kin ln lin quan n truyn / truyn li d liu mt ngi gi TCP n gin ha. Chng ta hy xem xt mt kt ni TCP gia host A v B v tp trung vo cc lung d liu c gi t my A n my B. Ti my gi (A), TCP ly d liu t tng ng dng, cc m n ng khung thnh cc segment v sau i tip n IP. Vic thng qua d liu t ng dng ti TCP v ng khung sau v truyn ti mt phn on l s kin quan trng u tin m ngi gi TCP phi x l. Mi ln TCP pht mt phn on n IP, n bt u mt timer cho segment . Nu timer ny ht hn, th mt s kin ngt c to ra ti my ch A. TCP ng vi s kin timeout, s kin thuc loi ln th hai m ngi gi TCP phi x l, bng cch truyn li segment gy ra timeout. S kin ln th ba m phi c x l bi ngi gi TCP l s xut hin ca mt segment xc nhn (ACK) t ngi nhn (c th hn, mt segment c cha mt gi tr trng ACK hp l). y, TCP ca ngi gi phi xc nh ACK l mt ACK-ln-u-tin cho mt segment m ngi gi vn cha nhn c mt xc nhn cho n, hay l mt bn sao c gi l ACK dup ci m xc nhn li mt segment m ngi gi nhn c mt xc nhn trc . Trong trng hp xut hin mt ACK-ln-u-tin, ngi gi ngay lc ny bit rng tt c cc d liu tnh n byte c xc nhn l c nhn chnh xc pha ngi nhn. Do ngi gi c th cp nht bin trng thi TCP ca mnh ci m theo di s th t ca byte cui cng c bit l nhn c mt cch chnh xc v theo th t pha ngi nhn. hiu phn ng ca ngi gi n mt ACK trng lp, chng ta phi nhn vo l do ti sao ngi nhn gi mt ACK trng lp trong trng u tin. Bng 3.5-1 tm tt cc chnh sch chung cho cc ACK ca ngi nhn TCP. Khi mt ngi nhn TCP nhn c mt segment vi mt s th t ln hn s th t theo th t tip theo c k vng, n s pht hin mt ch gin on trong lung d liu tc l, mt segment b mt tch. Do TCP khng s dng cc xc nhn tiu cc, nn ngi nhn khng th gi mt xc nhn tiu cu r rng tiu cc tr li cho ngi gi. Thay vo , n ch n gin ti xc nhn (ngha l to ra mt ACK trng lp cho) byte theo th t cui cng ca d liu m n nhn c. Nu ngi gi TCP nhn c ba ACK trng lp cho cng mt d liu, th n coi iu nh mt du hiu cho thy rng segment pha sau segment c xc nhn ba ln b mt. Trong trng hp ny, TCP s thc hin mt truyn li nhanh chng [RFC 2581], truyn li segment b mt tch trc khi timer ca segment ht hn.

S kin Segment i ti theo th t vi s th t c mong i. Tt c d liu tnh n s th t c mong i ny u c xc nhn. Khng c l hng trong cc d liu nhn c.

Hnh ng ca ngi nhn TCP Tr hon ACK. i segment ng th t tip theo trong khong thi gian 500ms. Nu segment ny khng xut hin, gi ACK

Segment theo th t n vi s th t Ngay lp tc gi i ACK tch lu duy mong mun. Mt segment ng th t nht, xc nhn cho c hai segment ng khc ang i gi ACK. Khng c l th t. hng trong d liu nhn c Segment khng ng th t n vi s Ngay lp tc gi i ACK trng lp, ch th t cao hn s th t mong mun ra s th t ca byte mong mun nhn nhn. Pht hin c l hng. tip theo Segment n lp y mt phn hoc Ngay lp tc gi i ACK, cung cp ton b l hng trong d liu nhn c segment bt u t im thp nht ca l hng. Bng 3.5-1: Cc khuyn ngh sinh ra ACK TCP

Mt s trng hp th v
Chng ta kt thc tho lun ny bng cch nhn vo mt s trng hp n gin. Hnh 3.5-6 m t cc trng hp m host A gi mt segment n host B. Gi s rng segment ny c s th t 92 v cha 8 byte d liu. Sau khi gi segment ny, host A i mt segment t B vi s xc nhn 100. Mc d segment t A c nhn ti B, nhng xc nhn t B n A b mt. Trong trng hp ny, timer ht hn, v host A truyn li segment tng t. Tt nhin, khi host B nhn c truyn li, n s quan st cc byte trong segment lp li vi cc byte n gi vo b m nhn ca n. V vy TCP host B s loi b cc byte segment truyn li ny.

Hnh 3.5-6: Truyn li do mt xc nhn b mt Trong mt trng hp th hai, host A s gi hai segment ta lng vo nhau. Segment u tin c s th t 92 v 8 byte d liu, v segment th hai c s th t 100 v 20 byte d liu. Gi s rng c hai segment n nguyn vn ti B, v B s gi hai xc nhn ring bit cho mi segment. Xc nhn u tin trong s c s xc nhn 100; ci th hai c s xc nhn 120. Gi s by gi khng c xc nhn no n c host A trc khi timeout cho segment u tin. Khi timer ht hn, host A gi li segment u tin vi s th t 92. By gi, bn c th thc mc, A cng s gi li segment th hai ch? Theo cc quy tc m t trn, host A s gi li segment ch khi timer ht hn trc khi mt xc nhn vi s xc nhn bng 120 hoc ln hn n ni. V vy, nh ch ra trong Hnh 3.5-7, nu xc nhn th hai khng b mt v n trc khi timeout ca segment th hai, A s khng gi li segment th hai.

Hnh 3.5-7: Segment khng c truyn li v xc nhn ca n n trc khi timeout Trong mt trng hp th ba v cui cng, gi s host A s gi hai segment, chnh xc nh trong v d th hai. Xc nhn ca segment u tin b mt trong mng, nhng ch cn trc khi timeout ca segment u tin, host A nhn c mt xc nhn vi s xc nhn 120. Host A do bit rng host B nhn c tt c mi byte cho n byte 119, v th host A khng gi li mt trong hai segment . Trng hp ny c minh ha trong Hnh 3.5-8.

Hnh 3.5-8: Mt xc nhn tch lu s trnh c vic truyn li segment u tin Nh li trong phn trc chng ta ni rng, TCP l giao thc kiu Go-Back-N. iu ny l do cc xc nhn c tch ly v c nhn chnh xc nhng cc segment khng theo th t khng c xc nhn ring bi ngi nhn. Do , nh trong Hnh 3.5-5 (xem thm Hnh 3.4-11), ngi gi TCP ch cn duy tr s th t ca mt byte c truyn i nhng cha nhn c xc nhn nh nht (sendbase) v s th t ca byte tip theo s c gi (nextseqnum). Nhng ngi c nn lu rng mc d cc thnh phn truyn d liu tin cy ca TCP tng t nh GoBack-N, nhng khng c ngha n l th hin thun tu ca Go-Back-N. thy rng c mt s khc bit ni bt gia TCP v Go-Back-N, hy xem xt nhng g s xy ra khi ngi gi gi mt chui cc segment 1, 2 ,..., N, v tt c cc segment ny u n ni theo th t m khng c li pha ngi nhn. Hn na gi s rng xc nhn cho gi n <N b mt, nhng N-1 xc nhn cn li n ch ngi gi trc timeout tng ng ca chng. Trong v d ny, Go-Back-N s truyn li khng ch gi tin n, m cn truyn li tt c cc gi tin tip theo n+1, n+2 ,..., N. TCP, mt khc, s truyn li nhiu nht mt segment, c th l, segment n. Hn

na, TCP thm ch s khng truyn li segment n nu xc nhn cho segment n+1 ti ni trc khi timeout cho segment n. C mt s xut gn y [RFC 2018, Fall 1996, Mathis 1996] m rng lc xc nhn ca TCP ging nh mt giao thc lp li c chn lc. tng quan trng trong cc xut ny l cung cp cho ngi gi thng tin r rng v nhng segment c nhn ng, v l ci vn cn thiu ngi nhn.

3.5.6 iu khin lung


Nh li rng cc host mi pha ca mt kt ni TCP b tr mt b m nhn ring cho kt ni . Khi kt ni TCP nhn c cc byte chnh xc v theo th t, n t d liu ny trong b m nhn. Tin trnh ng dng lin quan s c d liu t b m ny, nhng khng nht thit phi l lc d liu n ni. Tht vy, ng dng nhn c th bn rn vi mt s nhim v khc v n thm ch khng th c gng c d liu cho n khi rt lu sau khi d liu n ni. Nu ng dng c d liu tng i chm, th ngi gi c th rt d dng lm trn b m nhn ca kt ni bng cch gi d liu qu nhiu qu nhanh. TCP do cung cp mt dch v iu khin lung n cc ng dng ca n bng cch loi tr kh nng ngi gi lm trn b m ca ngi nhn. Nh vy, iu khin lung l mt dch v iu chnh tc - iu chnh tc m ngi gi gi i vi tc m ng dng nhn c d liu. Nh ni, mt ngi gi TCP cng c th c iu chnh do tc nghn trong mng IP; hnh thc kim sot ngi gi ny c gi l kim sot tc nghn, mt ch m chng ta s tm hiu c th ti Phn 3.6 v 3.7. Trong khi cc hot ng c thc hin bi iu khin lung v kim sot tc nghn l tng t (cc iu chnh ca ngi gi), th chng r rng li a ra cc l do rt khc nhau. Tht khng may, nhiu tc gi s dng cc thut ng ny thay th cho nhau, v ngi c hiu bit s phi cn thn phn bit gia hai trng hp. By gi hy tho lun v cch thc TCP cung cp dch v iu khin lung ca n. TCP cung cp iu khin lung bng cch cho ngi gi duy tr mt bin c gi l ca s nhn. Thn mt m ni, ca s nhn c s dng cung cp cho ngi gi mt nim v vic c bao nhiu m min ph c sn pha ngi nhn. Trong mt kt ni song cng, ngi gi mi pha ca kt ni duy tr mt ca s nhn khc bit. Ca s nhn l ng, ngha l, n thay i trong sut thi gian

sng ca mt kt ni. Hy nghin cu ca s nhn trong bi cnh truyn mt file. Gi s rng host A ang gi mt file ln n host B qua mt kt ni TCP. Host B phn phi mt b m nhn n kt ni ny; biu th kch thc ca n bi RcvBuffer. Theo thi gian, tin trnh ng dng trong host B c t b m. Xc nh cc bin sau y: LastByteRead = s ca byte cui cng trong lung d liu c t b m ca tin trnh ng dng trong B. LastByteRcvd = s ca byte cui cng trong lung d liu m n t mng v c t trong b m nhn ti B. Bi v TCP khng c php lm trn b m c phn phi, nn chng ta phi c: LastByteRcvd - LastByteRead <= RcvBuffer Ca s nhn, k hiu l RcvWindow, c t bng s lng trng d phng trong b m: RcvWindow = RcvBuffer - [LastByteRcvd - LastByteRead] Bi v trng d phng thay i theo thi gian, nn RcvWindow l ng. Bin RcvWindow c minh ha trong Hnh 3.5-9.

Hnh 3.5-9: Ca s nhn (RcvWindow) v b m nhn (RcvBuffer) Lm th no kt ni s dng bin RcvWindow cung cp dch v iu khin lung? Host B thng bo cho host A bit c bao nhiu d phng m n c trong b m kt ni bng cch t gi tr RcvWindow hin ti ca n vo trng ca s

ca mi segment n gi n A. Ban u host B t RcvWindow = RcvBuffer. Lu rng li n ra, host B phi theo di mt s bin kt ni c th. Host A ln lt theo di hai bin, LastByteSent v LastByteAcked, ci m c ngha r rng. Lu rng s khc bit gia hai bin, (LastByteSent gLastByteAcked ), l s lng ca d liu cha c xc nhn m A gi vo kt ni. Bng cch gi s lng ca d liu cha c xc nhn nh hn gi tr ca RcvWindow, host A c m bo rng n khng lm trn b m nhn host B. V vy, host A m bo rng trong sut thi gian sng ca kt ni LastByteSent - LastByteAcked <= RcvWindow. C mt vn k thut nh vi chng trnh ny. thy iu ny, gi s b m nhn ca host B tr nn y v th RcvWindow = 0. Sau khi thng bo rng RcvWindow = 0 n host A, cng gi nh rng B khng c g gi cho A. Khi tin trnh ng dng ti B y b m, TCP khng gi cc segment mi vi RcvWindows mi n host A - TCP s ch gi mt segment n host A nu n c d liu gi hoc nu n c mt xc nhn(ACK) gi. V vy host A khng bao gi bit c rng mt s trng c m ra b m nhn ca host B: host A b treo v c th truyn d liu khng nhiu! gii quyt vn ny, cc c im k thut TCP i hi host A tip tc gi cc segment vi mt byte d liu khi ca s nhn ca B bng khng. Nhng segment ny s c xc nhn bi ngi nhn. Cui cng, b m s bt u rng v cc xc nhn s cha mt RcvWindow khc khng. Chng ta ang m t dch v iu khin lung ca TCP, chng ti cng cp n y rng UDP khng cung cp iu khin lung. hiu vn y, hy xem xt vic gi mt chui cc segment UDP t mt tin trnh trn host A n mt tin trnh trn host B. i vi mt th hin UDP in hnh, UDP s ni cc segment (chnh xc hn l, cc d liu trong cc segment) trong mt hng i c kch thc hu hn ci m ng trc socket tng ng (tc l, cnh ca n tin trnh). Tin trnh c mt segment trn vn ti mt thi im bt k t hng i. Nu tin trnh khng c cc segment nhanh t hng i, hng i s trn v cc segment s b mt. Sau phn ny chng ti s cung cp mt Java applet tng tc ci m cung cp ci nhn su sc ng k v ca s nhn ca TCP.

3.5.7 Thi gian kh hi v Timeout


Nh li rng khi mt host gi mt segment vo trong mt kt ni TCP, n bt u mt timer. Nu timer ht hn trc khi host nhn c mt xc nhn cho cc d liu trong segment , th host s truyn li segment . Thi gian t khi timer c bt u cho n khi n ht hn c gi l timeout ca timer . Mt cu hi t nhin l, timeout nn ln nh th no? R rng, timeout nn ln hn thi gian kh hi ca kt ni, tc l, thi gian t khi mt segment c gi cho n khi n c xc nhn. Nu khng, cc truyn li khng cn thit s c gi i. Nhng timeout khng nn ln hn qu nhiu so vi thi gian kh hi; nu khng, khi mt segment b mt, TCP s khng th nhanh chng truyn li segment , t s a n cc tr truyn d liu ng k vo trong ng dng . Trc khi tho lun v khong timeout mt cch c th hn, chng ta hy xem xt k hn v thi gian kh hi (RTT). Cuc tho lun di y da trn cng vic ca TCP trong [Jacobson 1988].

c tnh thi gian kh hi trung bnh


RTT mu, k hiu l SampleRTT, cho mt segment l thi gian t khi segment ny c gi (tc l, chuyn n IP) cho n khi mt ACK cho segment ny c nhn. Mi segment c gi s c mt SampleRTT c lin kt vi chnh n. R rng, cc gi tr SampleRTT s dao ng t segment ny n segment khc do tc nghn trong cc router v ti trng khc nhau trn cc h thng u cui. Bi v cc bin ng ny, bt k gi tr SampleRTT no a ra c th l khng in hnh. c tnh mt RTT in hnh, mt cc t nhin l a ra mt s loi gi tr trung bnh ca SampleRTT. TCP duy tr mt mc trung bnh, c gi l EstimatedRTT, ca cc gi tr SampleRTT. Khi nhn c mt xc nhn v c c mt SampleRTT mi, TCP s cp nht EstimatedRTT theo cng thc sau y: EstimatedRTT = (1-x) EstimatedRTT + x SampleRTT. Cng thc trn c vit di dng mt cu lnh ca ngn ng lp trnh - gi tr mi ca EstimatedRTT l s kt hp c trng s ca gi tr EstimatedRTT trc v gi tr mi cho SampleRTT. Mt gi tr tiu biu ca x l x = 0,1 trong trng hp cng thc trn tr thnh: EstimatedRTT = 0,9 EstimatedRTT + 0,1 SampleRTT.

Lu rng EstimatedRTT l mt trung bnh nh hng ca cc gi tr SampleRTT. Nh chng ta s thy trong bi tp v nh, rng trung bnh nh hng ny s t nhiu nh hng ln cc mu gn y hn l ln cc mu c, iu ny l hon ton t nhin, khi cc mu gn y phn nh tt hn tnh trng nghn hin ti trong mng. Trong cc thng k, gi tr trung bnh nh vy c gi l trung bnh di chuyn nh hng theo hm m (EWMA). T "hm m" xut hin trong EWMA bi v nh hng ca mt SampleRTT c phn r theo cp s nhn nhanh nh cc bn cp nht tip tc. Trong cc bi tp v nh, bn s c hi v ngun gc ca thut ng hm m trong EstimatedRTT.

t timeout
Timeout cn c thit lp sao cho mt timer ht hn sm (tc l, trc khi mt ACK ca segment n chm) ch trong nhng trng hp him hoi. Do , mt cch t nhin l thit lp timeout bng EstimatedRTT cng vi mt s d. S d nn ln khi c rt nhiu bin ng trong cc gi tr SampleRTT; n phi l nh khi c rt t bin ng. TCP s dng cng thc sau: Timeout = EstimatedRTT + 4 * Deviation, y Deviation l mt c lng xem c thng c bao nhiu SampleRTT lch khi EstimatedRTT: Deviation = (1-x) Deviation + x | SampleRTT - EstimatedRTT | Lu rng Deviation l mt EWMA xem c bao nhiu SampleRTT lch khi EstimatedRTT. Nu cc gi tr SampleRTT c bin ng t, th Deviation l nh v Timeout l kh m ln hn EstimatedRTT; mt khc, nu c nhiu bin ng, Deviation s ln v Timeout s ln hn nhiu so vi EstimatedRTT.

3.5.8 Qun l kt ni TCP


Trong mc ny chng ta hy xem xt k hn cch thc m mt kt ni TCP c thnh lp v b lm t. Mc d ch c bit ny c th khng c v c bit th v, nhng n kh quan trng bi v vic thit lp kt ni TCP c th thm ng k vo cc tr bit (v d, khi lt Web). By gi hy xem xem lm th no m mt kt ni TCP c thnh lp. Gi s mt tin trnh ang chy trong mt host mun bt u mt kt ni vi mt tin trnh trong mt host khc. Host m khi u

cho vic kt ni c gi l client host trong khi host cn li c gi l server host. Tin trnh ng dng client u tin thng bo cho client TCP rng n mun thit lp mt kt ni n mt tin trnh trong server. Nh li t Phn 2.6, rng mt chng trnh Java client thc hin iu ny bng cch pht ra lnh:
Socket clientSocket = new Socket("hostname", "port number");

TCP trong client sau tip tc thit lp mt kt ni TCP vi TCP trong server theo cch sau: Bc 1. u tin TCP pha client gi mt segment TCP c bit n TCP pha server. Segment c bit ny khng cha d liu tng ng dng. Tuy nhin, n c mt trong cc bit c trong header ca segment (xem Hnh 3.32), c gi l bit SYN, c t bng 1. V l do ny, segment c bit ny c gi l mt segment SYN. Ngoi ra, client chn mt s th t ban u (client_isn) v t s ny vo trong trng s th t ca segment TCP SYN lc u. Segment ny c ng gi trong mt IP datagram v c gi vo mng Internet. Bc 2. Mt khi IP datagram c cha segment TCP SYN n c server host (gi s n n ni!), server s trch ra segment TCP SYN t datagram ny, ch nh cc b m TCP v cc bin cho kt ni ny, v gi mt segment chp nhn kt ni n client TCP. Segment chp nhn kt ni ny cng khng cha d liu tng ng dng. Tuy nhin, n c cha ba mnh thng tin quan trng trong segment header. Trc tin, bit SYN c t bng 1. Th hai, trng xc nhn ca TCP segment header c t bng isn+1. Cui cng, server chn ring cho mnh mt s th t ban u (server_isn) v t gi tr ny trong trng s th t ca TCP segment header. Trong thc t, segment chp nhn kt ni ny ni rng "Ti nhn c gi SYN ca bn bt u mt kt ni vi s th t ban u ca bn, client_isn. Ti ng thit lp kt ni ny. S th t ban u ca ti l server_isn." Segment chp nhn kt ni ny i khi c gi l mt SYNACK segment. Bc 3. Khi nhn c segment chp nhn kt ni, client cng ch nh cc b m v cc bin cho kt ni . Sau client host gi cho server mt segment khc; segment sau cng ny xc nhn cho segment chp nhn kt

ni ca server (client thc hin iu bng cch t gi tr server_isn+1 vo trong trng xc nhn ca TCP segment header). Bit SYN c t bng 0, v kt ni c thit lp. Mt khi ba bc sau y c hon thnh, th cc client v server host c th gi cc segment cha d liu vi nhau. Trong mi segment tip theo, bit SYN s c t bng khng. Lu rng thit lp kt ni, ba gi tin c gi gia hai host, nh minh ha trong Hnh 3.5-10. V l do ny, th tc thnh lp kt ni ny thng c ni n nh l bt tay ba bc. Mt vi kha cnh ca bt tay ba bc TCP (Ti sao cc s th t ban u l cn thit? Ti sao l mt ci bt tay ba bc, tri ngc vi mt ci bt tay hai bc, li l cn thit?) s c khm ph trong cc bi tp v nh.

Hnh 3.5-10: Bt tay ba bc TCP: trao i segment Tt c nhng iu tt p u phi i n mt kt thc, v iu cng ng vi mt kt ni TCP. Mt trong hai tin trnh tham gia vo mt kt ni TCP c th kt thc kt ni . Khi mt kt ni kt thc, cc ngun ti nguyn (tc l, cc b m v cc bin) trong cc host c gii phng. V d, gi s client quyt nh ng kt ni. Tin trnh ng dng ca client s a ra mt lnh ng. iu ny lm cho client TCP gi mt TCP segment c bit n tin trnh ca server. Segment c bit ny c mt bit c trong header ca segment, c gi l bit FIN (xem Hnh 3.3-2), c t bng 1. Khi server nhn c segment ny, n s gi tr li cho client mt segment xc nhn. Sau server gi segment shut-down ca n, trong bit FIN c t bng 1. Cui cng, client xc nhn segment shut-down

ca server. Ti thi im ny, tt c cc ti nguyn trong hai host by gi c gii phng. Trong sut thi gian sng ca mt kt ni TCP, giao thc TCP chy trong mi host thc hin cc chuyn tip thng qua cc trng thi TCP khc. Hnh 3.5-11 minh ha mt chui cc trng thi in hnh ca TCP m c ving thm ca client TCP. Client TCP bt u t trng thi ng. ng dng bn pha client khi to mt kt ni TCP mi (bng cch to ra mt i tng Socket trong cc v d Java ca chng ta). iu ny lm cho TCP bn pha client gi mt segment SYN n TCP bn pha server. Sau khi segment SYN c gi i, client TCP i vo trng thi SYN_SENT. Trong khi trng thi SYN_STATE cc client TCP ch i mt segment t server TCP ci m bao gm mt xc nhn cho segment trc ca client vi bit SYN c t bng 1. Mt khi nhn c nh mt segment nh vy, client TCP i vo trng thi ESTABLISHED. Trong khi trng thi ESTABLISHED, TCP client c th gi v nhn cc segment TCP c cha d liu ti trng (v d, do ng dng to ra). Gi s rng ng dng pha client quyt nh rng n mun ng kt ni. iu ny lm cho client TCP client gi mt segment TCP vi bit FIN c t bng 1 v i vo trng thi FIN_WAIT_1. Trong khi trng thi FIN_WAIT_1, client TCP i mt segment TCP t server vi mt xc nhn. Khi n nhn c segment ny, client TCP i vo trng thi FIN_WAIT_2. Trong khi trng thi FIN_WAIT_2, client i mt segment khc t server vi bit FIN c t bng 1; sau khi nhn c segment ny, client TCP xc nhn segment ca server v i vo trng thi TIME_WAIT. Trng thi TIME_WAIT cho php client TCP gi li xc nhn cui cng trong trng hp ACK b mt. Thi gian trng thi TIME-WAIT c thc hin ph thuc, nhng gi tr in hnh l 30 giy, pht, 1 v 2 pht. Sau khi i, kt ni chnh thc c ng v tt c cc ti nguyn pha client (bao gm c s hiu cng) c gii phng.

Hnh 3.5-11: Cc trng thi TCP tun t c bn c ving thm ca mt client TCP Hnh 3.5-12 minh ha mt lot cc trng thi thng c ving thm ca TCP pha server; vic chuyn tip c t gii thch. Trong hai s chuyn trng thi, chng ta ch hin th cch thc mt kt ni TCP bnh thng c thit lp v b ng. Chng ta s khng m t nhng g xy ra trong mt s trng hp bnh l, v d, khi c hai pha ca mt kt ni mun u mun ng kt ni cng mt lc. Nu bn quan tm trong vic nghin cu v vic ny v nhng vn tin tin khc lin quan n TCP, bn c khuyn khch nn xem cun sch ton din ca Steven [Stevens 1994].

Hnh 3.5-12: Cc trng thi TCP tun t thng thng c ving thm ca mt TCP pha server iu ny hon tt gii thiu ca chng ti v TCP. Trong Phn 3.7 chng ta s tr li vi TCP v xem xt n kim sot tc nghn ca TCP su hn. Trc khi lm nh vy, trong phn tip theo chng ta s tng bc tr li v xem xt cc vn v kim sot tc nghn trong mt bi cnh rng hn.

Tham kho
[Fall 1996] K. Fall, S. Floyd, "Simulation-based Comparisons of Tahoe, Reno and SACK TCP", ACM Computer Communication Review, July 1996. [Jacobson 1988] V. Jacobson, "Congestion Avoidance and Control," Proc. ACM Sigcomm 1988 Conference,in Computer Communication Review, vol. 18, no. 4, pp. 314-329, Aug. 1988 [Mathis 1996] M. Mathis, J. Mahdavi, "Forward Acknowledgment: Refining TCP Congestion Control", Proceedings of ACM SIGCOMM'96,August 1996, Stanford, CA. [RFC 793] "Transmission Control Protocol," RFC 793, September 1981.

[RFC 854] J. Postel and J. Reynolds, "Telnet Protocol Specifications," RFC 854, May 1983. [RFC 1122] R. Braden, "Requirements for Internet Hosts -- Communication Layers," RFC 1122, October 1989. [RFC13 23] V. Jacobson, S. Braden, D. Borman, "TCP Extensions for High Performance," RFC 1323, May 1992. [RFC 2018] Mathis, M., Mahdavi, J., Floyd, S. and A. Romanow, "TCP Selective Acknowledgement Options", RFC 2018, October 1996. [RFC 2581] M. Allman, V. Paxson, W. Stevens, " TCP Congestion Control, RFC 2581, April 1999. [Stevens 1994] W.R. Stevens, TCP/IP Illustrated, Volume 1: The Protocols. Addison-Wesley, Reading, MA, 1994.

3.6 Nguyn l ca kim sot tc nghn


phn trc, chng ta xem xt cc nguyn tc chung v cc c ch ca giao thc TCP c th c s dng cung cp tin cy cho dch v truyn gi d liu trong vn nh mt gi tin. Chng ta tng cp n n, trong thc t, vic mt mt thng l kt qu ca vic trn b m ca router v dn ti mng b tc nghn. Vic truyn li gi tin l biu hin ca nghn mng( s mt mt c trng ca gi tin lp vn ti) nhng khng x l nguyn nhn ca nghn mngc qu nhiu ngun c gng truyn gi d liu vi tc cao. phn ny, chng ta s xem xt vn kim sot tc nghn trong bi cnh chung, hiu c rng v sao tc nghn li l iu xu , lm th no nghn mng c thng k trong vic x l nhn bi cc ng dng lp trn v cc cch tip cn khc nhau phng chng hoc y li nghn mng. Vic nghin cu v nghn mng l hp l, cng nh tin cy trong truyn d liu, n nm danh sch top-10 cc vn c bn quan trng trong mng. Chng ta s chm dt phn ny bng cuc tho lun v kim sot tc nghn trong giao thc ATM ABR. Phn sau y c mt nghin cu chi tit v thut ton kim sot tc nghn ca giao thc TCP.

3.6.1 Cc nguyn nhn v chi ph cho tc nghn:


Hy bt u cc nghin cu chung ca chng ta v kim sot tc nghn bng vic xem xt ba kch bn ngy cng phc tp m c xy ra tc nghn. Trong mi trng hp, u tin chng ta s xem xt v sao tc nghn li xy ra, v chi ph cho tc nghn(cc ngun ti nguyn khng c s dng ti a v hiu sut thp c nhn bng cc thit b u cui)

Kch bn 1: Hai my gi, mt router vi b m v hn:


Chng ta xem xt mt kch bn gy nghn c bn nht : hai my (A v B ) mi my c mt kt ni n cng mt my khc nm gia my ngun v my ch, c m t nh hnh 3.6-1

Hnh 3.6-1: Kch bn 1 ca tc nghn: 2 kt ni chia s mt hop duy nht vi b m v hn

Gi s cc ng dng ti my A gi d liu qua kt ni( gi d liu n giao thc tng vn ti thng qua socket) vi tc trung bnh l in byte/sec. Nhng d liu ny l bn gc theo ngha mi n v d liu c gi qua socket duy nht mt ln. Giao thc lp di lp vn chuyn l mt ci rt n gin: d liu c ng gi v gi i; khng c khc phc li (v d nh truyn li) ; kim sot li; hay l kim sot tc nghn no c thc hin. My B cng hot ng tng t nh vy v chng ta gi s rng n cng gi gi tin vi cng tc in byte/sec. Cc gi tin i t my A v B i qua mt router v trn mt lien kt i ra vi hiu sut l C. Router c b m cho php lu nhng gi tin n khi m nhng gi tin c tc ti vt qu kh nng ca lin kt i ra. trng hp u tin, chng ta gi s rng router c khng gian b m v hn.

Hnh 3.6-2: Kch bn tc nghn 1: Lu lng v tr l mt hm ca tc gi host

Hnh 3.6-2 Hiu sut kt ni ca my A trong kch bn u tin. Hnh v bn tri v biu lu lng kt ni ( s lng bytes trong mt giy ti my nhn) nh l hm ca tc gi ca kt ni. i vi tc gi nm gia 0 v C/2, lu lng ti host nhn bng tc gi tin ca host gi- cc gi tin c gi bi ngi gi s c nhn ti pha ngi nhn vi mt tr xc nh. Tuy vy, khi m tc gi cao hn C /2, th lu lng th ch l C/2. S gii hn trn ca lu lng ny l h qu ca vic chia s sc cha ca lin kt gia hai kt ni mt lin kt n gin khng th cung cp cc gi tin cho mt ngi nhn vi mt tc n nh vt qu C/2. Khng c vn no khi cc host A v B thit lp tc gi ca chng, chng s khng bao gi thy mt lu lng vt qu C/2. t c lu lng cho mt kt ni bng C/2 l mt iu tt, lin kt s s dng c ti a hiu qu trong vic truyn gi tin ti ch. th bn phi ca hnh v 3.6-2, cho thy hu qu ca vic hot ng gn kh nng ca lin kt. Khi m tc gi tin gn ti C/2(t tri sang), tr trung bnh s ngy cng tng dn v tng dn. Khi m tc gi vt qu C/2, trung bnh s gi tin i trong router tr nn v hn v tr gia im u v cui tr nn v hn. Ngay c trong kch bn ny(iu kin l tng ) chng ta cng thy c ci gi ca nghn mng- tr ln l kinh nghim ca tc gi tin tin gn ti kh nng ca ng lin kt.

Kch bn2: Hai my gi, v mt router vi b m gii hn:


By gi, chng ti s thay i mt cht kch bn u tin theo hai cch sau. S lng ca b m s gii hn. Th hai, gi s tt c cc kt ni u m bo. Nu nh mt gi tin c mt on lp vn chuyn b rt ti router, th rt cuc phn on s c gi li bi ngi gi. Do gi tin c th c gi li, v th chng ta nn ch ti thut ng tc gi. C th, chng ta hy biu th mt ln na tc vi mt ng dng gi d liu gc vo mt socket vi tc in bytes/sec. Tc m lp vn ti gi phn on mng vo mng c k hiu l in bytes/sec. in bytes/sec i khi c gi l ti cung cp cho h thng.

Hnh 3.6-3 Kch bn 2: 2 my(c gi li gi tin ) vi 1 router c b m hn ch

Hnh 3.6-4: Thc hin kch bn 2: (a) khng truyn li (b) ch cn truyn li (c) khc, khng cn truyn li Hiu sut thu c theo kch bn 2 s ph thuc rt ln vo cch truyn li c x l nh th no. u tin, chng ta xem xt mt trng hp phi thc t l my A c kh nng xc nh khi c hay khng c mt b m ang rng ti mt router v nh vy n s gi gi tin khi no c b m rng.Trong trng hp ny, khng c tn tht no xy ra, in s bng vi in' , v thng qua kt ni s bng in. Trng hp ny c th hin hnh 3.6-4 (a).T quan im lu lng, hiu nng l mt quan im - mi th gi th u c nhn. Ch rng tc gi trung bnh ca cc my th khng vt qu C/2 trong kch bn ny, vic mt gi tin l khng bao gi xy ra. Chng ta tip tc xem xt tip trng hp l ngi gi ch gi li khi gi tin bit chc chn s b mt.(Mt ln na, gi thit ny hi lng mt cht. Tuy vy, n c th l my gi c th thit lp thi thi gian ca n ln chc chn rng gi tin m khng c ACK tr li th b mt ).Trong trng hp ny, th hiu sut s ging nh hnh 3.6-4(b). nh gi ng nhng iu ny, chng ta xem xt trng hp theo ti cung cp, in' (tc gi d liu gc v gi li d liu) bng 0,6C. Theo hnh hnh 3.6-4(b), gi tr ca ti cung cp, tc ca d liu c gi ti ngi nhn l C/3. Nh vy, trn 0,6C n v truyn d liu, 0,3333 byte/giy (tnh trung bnh) l truyn d liu gc; cn 0,2222 byte/giy l truyn d liu. Ta thy mt chi ph khc ca ca nghn mng- ngi gi phi gi li b cho d liu mt do trn b nh. Cui cng, chng ta xem xt trng hp c tnh thc t hn l ngi gi tht bi sm v truyn li mt gi tin s b tr trong hng i, nhng khng b mt.

Trong trng hp ny, c hai gi tin gc v gi tin c gi li u c nhn. Tt nhin, ngi nhn s c gi tin v loi b vic truyn li. Trong trng hp ny,vic lm ca router l chuyn tip bn sao ca d liu gc c truyn li l lng ph, ngi nhn chc chn nhn c bn sao ca gi tin gc. Ta thy chi ph khc ca nghn mng Vic truyn li khng cn thit ca bi ngi gi v mt tr ln c th l l do router s dng bng thng ca lin kt chuyn tip mt bn sao khng cn thit. Hnh 3.6.4(c) cho thy lu lng so vi ti cung cp khi m mi gi tin gi s rng c chuyn tip(tnh trung bnh) t nht hai ln qua router. T khi gi tin c gi hai ln, lu lng t c gii hn bi hai ng cong tim cn vi gi tr C/4.

Kch bn3: Bn my gi, mt router gii hn v b m, ng dn nhiu hop


Trong kch bn tc nghn cui cng ca chng ta, bn my truyn cc gi tin, mi gi tin qua hai hop, biu din nh hnh 3.6-5. Chng ta li gi s rng mi my s dng mt khong thi gian rt/ c ch truyn li thc hin dch v truyn tin tin cy, tt c cc my u c cng gi tr in, v tt c cc ng truyn u c bng thng l C bytes/giy.

Hnh 3.6-5: 4 my gi, cc router vi hu hn v b m, v ng dn nhiu hop. Chng ta hy i xem xt kt ni t my A n my C, i qua R1 v R2. Kt ni AC chia s router 1 vi kt ni D-B v chia s router 2 vi kt ni B-D. Vi gi tr in cc k nh, li trn b m l him xy ra(nh l kch bn tc nghn 1 v 2), lu lng xp x bng ti cung cp. i vi ci gi tr ln hn mt cht, cc thng lng tng ng cng ln hn, nhiu d liu gc s c truyn vo mng v c gi ti ch. Nh vy, vi gi tr in nh, s gia tng in l kt qu ca vic tng out. Xem xt trng hp cc k t lu lng, chng ta hy kim tra tip trng hp in l cc k ln . Ch ti router 2. Cc gi tin t A-C ti router2 (cc gi tin n R2 sau khi qua R1) c tc ti R2 hu ht l C. Nu l cc k ln so vi tt c cc kt ni (bao gm c kt ni B-D), sau tc ca cc gi tin B-D ti R2 c th ln hn cc gi tin A-C. Bi v cc gi tin A-C v B-D cnh tranh nhau s lng b m ti R2, s gi tin A-C m thng qua R2(trong trng hp ny th khng

mt gi tin do li trn b m) s nh dn i cn ti cung cp t B-D s tng dn ln. mc gii hn, mt b m trng R2 s c lp y bi mt gi tin B-D v lu lng kt ni A-C ti R2 s v 0.Ln lt, lu lng ca kt ni A-C s v 0 di s gii hn ca gi tin. Nhng nhn xt ny lm tng ti cung cp so vi s cn bng lu lng c hin th di hnh 3.6-6

Hnh 3.6-6: Kch bn 2 thc hin vi b m gii hn v ng c nhiu hop.

L do cho vic gim lu lng v tng ln ca ti cung cp l iu hin nhin khi ta xem xt s lng s lng vic lm xong bi mng. Trong kch bn lu lng truy cp cao nu trn, bt c khi no gi tin b rt ti router th hai, vic m router u tin l chuyn tip gi tin cho router th hai tr nn lng ph. Mng s tr nn chnh xc hn nu ngay t router u tin loi b. (Ly v d, khi chn mt gi tin truyn i, n phi tt mt router cung cp u tin(thng qua ch s priority) cho gi tin gi tin c th i qua nhiu router ). Nh vy, chng ta thy c chi ph khc ca nghn mng- Khi mt gi tin b b dc theo ng truyn, lu lng truyn ti c s dng mi router u chuyn tip gi tin n cc im m ti n b b v tr nn lng ph.

3.6.2 Phng php kim sot tc nghn :


Ti chng 3.7, chng ta s xem xt chi tit phng php tip cn c th ca TCP i vi kim sot nghn. Ti y, chng ta s xc nh hai cch tip cn thng c s dng trong thc t i vi kim sot tc nghn, v tho lun chi tit v kin trc mng v giao thc kim sot tc nghn c biu hin qua cch tip cn ny. cp rng, chng ta c th phn bit gia cc phng php kim sot tc nghn da vo c hay khng lp mng cung cp bt k h tr tt cho lp truyn ti cho cc mc ch kim sot tc nghn: Kim sot tc nghn end to end. Trong phng php tip cn end to end i vi kim sot tc nghn. Lp mng cung cp khng h tr cho lp truyn ti vi mc ch kim sot tc nghn. Ngay c khi c tc nghn trong mng phi c kt lun t c s h thng u cui ch da trn trng thi ca mng(gi tin mt hay l tr). Chng ta s c thy trong chng 3.7 TCP cn phi dng cc tip cn end to end kim sot tc nghn, t lp Ip khng phn hi li cho h thng cui v phn nghn mng. Cc on TCP b mt c ly nh l mt du hiu ca nghn mng. Chng ta c th thy yu cu mi Kim sot tc nghn Network-assited. i vi kim sot tc nghn Networkassited, cc thnh phn mng-lp (v d router) s cung cp phn hi tt cho ngi gi v vn trng thi tc nghn trong mng. Thng tin phn hi c th n gin l mt bit cho bit tc nghn trn lin kt . Cc tip cn ny c thc hin bi cc k s ti IBM SNA[Schwartz 1982] v DEC DECnet[Jain1989][ Ramakrishnan1990] v gn y c d kin cho mng TCP/IP [Floyd1994][Ramakrishnan1998] , n c s dng trong ATM ABR kim sot tc nghn kh tt. V d nh mt t kim sot tc nghn ATM ABR chng ta s nghin nhanh vic cho php mt router thng bo r rng cho ngi gi tc truyn li n c th h tr trn mt ng dn ra. i vi kim sot tc nghn Network-assited , thng tin tc nghn l phn hi in hnh t mng n ngi gi bng mt hoc hai cch, nh hnh 3.6-7. Hng phn hi c th c gi t router trong mng n ngi gi. Thng c thng bo

di dng gi tin choke(ch yu l Ti b nghn). Hnh thc thng bo th hai xy ra khi mt router nh giu/ cp nhp mt phn gi tin c chuyn t ngi gi ti ngi nhn xc ch ra tc nghn. Sau khi nhn c gi tin nh du, ngi nhn sau s thng bo cho ngi gi ch dn tc nghn. Lu rng, cch th hai ca thng bo s mt mt vng.

Hnh 3.6-7: Hai qu trnh phn hi cho thng tin tc nghn ch th trong mng

3.6.3 Kim sot tc nghn ATM ABR


Nghin cu ca chng ta c th v kim sot tc nghn TCP ti chng 3.7 s cung cp chiu su nghin cu trng hp ca cch tip cn end to end i vi kim sot tc nghn. Chng ta kt thc phn ny vi mt phn nghin cu trng hp ca c ch kim sot tc nghn network-assisted c s dng trong dch v ATM ABR(Available Bit Rate). ABR c thit k ra nh l mt dch v truyn d liu mm do ging nh trong TCP. Khi m mng cha qu ti, dch v ABR s ly cc phn bng thng sn c; khi mng c tc nghn, dch v ABR s gim bt tc truyn xung mt tc truyn gii hn c xc nh. Hng dn chi tit v kim sot tc nghn ATM ABR v qun l truyn ti c cung cp bi [Jain 1996] Hnh 3.6-8 cho thy kt cu cho kim sot tc nghn ATM ABR. Trong bi tho lun chng ta s s dng thut ng ATM (v d, dng thut ng switch hay hn l router). Vi dch v ATM ABR, cc d liu c truyn t ngun ti ch

thng qua mt lot cc thit b chuyn mch trung gian. Cc t bo d liu c gi l cc t bo RM(t bo qun l ti nguyn). Khi mt t bo RM ti ch, n s quay li v gi ngc li cho ngi gi (c th sau khi ch thay i ni dung ca t bo RM). N cng c th t mt chuyn i to ra t bo RM v gi chnh t bo RM ny v ngun. T bo RM nh vy c s dng cung cp c hai phn hi mng trc tip v phn hi ngi mng thng qua ngi nhn, nh hnh 3.6-8

Hnh 3.6-8: Khung iu khin tc nghn cho dch v ATM ABR Kim sot tc nghn ATM ABR l cch tip cn da trn tc . M ngi gi tnh ton chnh xc tt ti a m n c th truyn v t iu chnh cho hp l. ABR cung cp ba c ch cho vic bo hiu thng tin lin quan ti tc nghn t cc switch n ngi nhn: Bit EFCI. Mi t bo d liu u bao gm mt bit EFCI(Du hiu tc nghn r rng). Mt chuyn i mng tc nghn s thay bit EFCI trong t bo d liu thnh bit 1 bo hiu tc nghn n my ch. My ch phi kim tra bit EFCI trong mi ln nhn t bo d liu. Khi mt t bo RM ti my ch, nu a s cc t bo d liu nhn trc c bit EFCI l 1, th sau my ch s t bit CI (Du hiu tc nghn) ca t bo RM ln thnh 1 v gi ngc li t bo RM cho ngi gi. S dng bit EFCI trong t bo d liu v bit CI trong t bo RM, ngi gi nh vy c th thng bo nghn mi chuyn mng. Bit CI v NI. Tc ca t bo RM l tham s c th iu chnh c, vi mt t bo RM mi 32 t bo d liu l gi tr mc nh. Cc t bo RM c

mt bt CI v mt bit NI c th c thay i bi switch mng. C th, mt chuyn i c th thit lp bit NI trong mt t bo RM thnh 1 di ch tc nh v c th thit lp bit CI n 1 trong cc iu kin tc nghn nghim trng. Khi ch nhn c mt t bo RM, n s gi li t bo RM cho ngi gi vi CI v NI bit nguyn vn (ngoi tr CI c th c thit lp 1 bi cc ch nh m t trn). Ci t tc r rng (ER).Mi t bo RM cha 2 byte trng ER (Explicit Rate). Mt switch tc nghn c th nhn gi tr thp hn trong mt phn ER trong t bo RM. Vi cch nh vy, ER s c t tc ti a nh nht tt c cc switch trn ng t ngun ti ch. Mt ngun ATM ABR iu chnh tc m n c th gi cc t bo nh l mt hm ca cc gi tr CI, NI v ER trong mt t bo RM tr li. Cc quy tc thc hin vic iu chnh t l ny l kh phc tp v bun t. Ngi c quan tm c gii thiu n [Jain 1996] bit chi tit.

Tham kho
[Floyd 1994] Floyd, S., "TCP and Explicit Congestion Notification," ACM Computer Communication Review, V. 24 N. 5,October 1994, p. 10-23. [Jain 1989] R. Jain, "A Delay-Based Approach for Congestion Avoidance in Interconnected Heterogeneous Computer Networks," ACM Comp. Commun. Rev., vol. 19, no. 5, 1989, pp. 56-71. [Jain 1996] R. Jain. S Kalyanaraman, S. Fahmy, R. Goyal, S. Kim, "Tutorial Paper on ABR Source Behavior ," ATM Forum/96-1270, October 1996 [Ramakrishnan 1990] K. K. Ramakrishnan and Raj Jain, "A Binary Feedback Scheme for Congestion Avoidance in Computer Networks", ACM Transactions on Computer Systems, Vol.8, No.2, pp. 158-181, May 1990. [Ramakrishnan 1998] Ramakrishnan, K.K., and Floyd, S., A Proposal to add Explicit Congestion Notification (ECN) to IP . Internet draft draft-kksjf-ecn-03.txt, October 1998, work in progress. [Schwartz 1982] M. Schwartz, "Performance Analysis of the SNA Virtual Route Pacing Control," IEEE Transactions on Communications, Vol COM-30, No. 1 (Jan. 1982), pp. 172-184.

3.7. TCP Congestion Control (iu khin tc nghn)

Phn ny chng ta s quay tr li nghin cu v TCP. Nh chng ta hc Phn 3.5, TCP cung cp mt dch ph truyn ti ng tin cy gia hai tin trnh ang chy ti cc my(host) khc nhau. Mt thnh phn v cng quan trng khc ca TCP l c ch kim sot tc nghn. Nh chng ta ch ra phn trc, TCP phi s dng c ch iu khin tc nghn end-to-end (gia 2 u cui) hn l iu khin tc nghn network-assited (c s tr gip ca mng c th l router), bi v tng IP khng cung cp thng tin phn hi no n cc h thng u cui lin quan n tc nghn mng. Trc khi i su vo cc chi tit ca iu khin tc nghn TCP, u tin hy nhn mt cch tng th v c ch iu khin tc nghn , cng nh mc ch chung m TCP c gng t c khi c nhiu kt ni TCP phi chia s bng thng ca mt ng lin kt b nghn. Mt kt ni TCP iu khin tc truyn ca n bng vic gii hn s phn on (segment) c truyn i- m-cha- c-xc nhn(cha nhn c ACK) . Ta k hiu s segment cha nhn c ACK c th chp nhn c l w, thng c bit n nh kch c ca s TCP (TCP window size). Mt cch l tng, cc kt ni TCP c php truyn i nhanh nht c th (tc l, c s lng gi tin cha nhn c ACK ln nht c th) min l cc segment khng b mt (b ri ti cc router) do tc nghn. Trong iu kin rt rng, mt kt ni TCP bt u vi mt gi tr w nh v sau thm d v s tn ti ca phn bng thng m rng cha c s dng ti cc lin kt trn ng truyn t ngun ti ch ( end-to-end ) bng vic tng w. Mt kt ni TCP s tip tc tng w cho ti khi no vic mt mt segment xy ra ( c pht hin bi timeout hoc t cc ACK b p). Khi c mt gi xy ra, kt ni TCP gim w ti mt mc an ton v sao bt u thm d li bng thng cha c s dng bng cch t t tng w ln. Mt n v o hiu nng quan trng ca mt kt ni TCP chnh l thng lng (throughput) ca n l tc m kt ni TCP vn chuyn d liu t bn gi ti bn nhn. R rng , thng lng s ph thuc vo gi tr ca w.W. Nu TCP bn gi truyn tt c w segment ta lng vo nhau, th sau n s phi i mt RTT (round trip time) cho ti khi n nhn c ACK cho cc segment , khi

n c th gi thm w segment na. Nu mt kt ni truyn w segment vi kch thc MSS bytes / 1 RTT giy, th thng lng ca kt ni hay tc truyn s l (w*MSS)/RTT (bytes/giy). Gi s hin ti c K kt ni TCP ang truyn qua mt lin kt c sc cha R. Cng gi s rng khng c bt k gi UDP no c truyn trn lin kt ny, mi kt ni TCP th ang truyn mt s lng ln d liu, v khng mt kt ni TCP no trong s ny i qua bt c ng lin kt no khc. Trong trng hp l tng, kch thc ca s ca cc kt ni TCP i qua ng lin kt ny nn t ti mc cho mi kt ni c c mt thng lng bng R/K. Khi qut hn na, nu mt kt ni i qua N ng lin kt, vi ng lin kt n c tc truyn l Rn v h tr tng cng Kn kt ni TCP, th trong trng hp l tng kt ni ny s t c tc Rn/Kn trn ng lin kt n.Tuy nhin tc trung bnh ca kt ni u cui ny khng th vt qu tc ti thiu t c ti tt c cc lin kt trn sut qung ng t ngun n ch. iu c ngha l, tc truyn t ngun ti ch cho kt ni ny s l r = min{R1/K1, , RN/KN} . Mc ch ca TCP l cung cp cho kt ni ny tc u cui, r.(Trn thc t, cng thc cho r phc tp hn nhiu, v ta phi tnh n s tht l mt hoc nhiu hn cc kt ni ang din ra c th b nghn ti mt s ng lin kt khc m khng phi trn ng t ngun ti ch ny v do khng th s dng cng thc chia s bng thng, Rn/Kn. Trong trng hp , gi tr ca r s phi hn hn min {R1/K1, ,RN/KN}.)

3.7.1 Tng quan v iu khin tc nghn ca TCP


Trong Phn 3.5 ta thy rng mi pha ca mt kt ni TCP s bao gm mt b m nhn (receive buffer), mt b m gi (sender buffer) v mt vi bin (LastByteRead, RcvWin , v.v). C ch iu khin tc nghn ca TCP i hi mi pha ca kt ni phi theo di du vt ca hai bin b sung : congestion window (ca s nghn) v threshold (ngng gii hn). Ca s nghn, vit tt l

CongWin, p t thm mt rng buc v s lu lng m mt host c th gi vo mt kt ni. c bit, s lng cc d liu cha nhn c ACK m mt host c th c trong mt kt ni TCP khng c vt qu gi tr nh nht ca CongWin v RcvWin, LastByteSent - LastByteAcked <= min{CongWin, RcvWin}. Lu lng, ci m chng ta s tho lun chi tit bn di, l mt bin tc ng ti s tng ln ca CongWin. By gi ta hy xem xt xem mt ca s nghn s thay i nh th no trong sut thi gian sng ca mt kt ni TCP. tp trung vo iu khin tc nghn ( tri vi iu khin lung), ta hy gi nh rng b m nhn TCP l rt ln nn cc rng buc v ca s nhn c th c b qua. Trong trng hp , s lng d liu cha nhn c ACK m mt host c th c trong mt kt ni TCP ch b gii hn bi CongWin. Hn na, hy gi nh rng bn gi c mt lng d liu rt ln cn chuyn n bn nhn. Khi mt kt ni TCP c thit lp gia hai h thng u cui, chng trnh ng dng ti bn gi s vit cc byte vo b m gi TCP ca bn gi. TCP s chim cc on c kch c MSS, ng gi mi on ny trong mt TCP segment, v chuyn segment ny ti tng mng chuyn qua mng . Ca s tc nghn TCP iu chnh thi gian m cc segment c gi vo trong mng (tc l, c truyn qua tng mng). Ban u, ca s nghn bng mt MSS. TCP gi segment u tin vo trong mng v ch 1 ACK. Nu segment ny c xc nhn trc khi b m thi gian ca n ht, th bn gi s tng ca s nghn ln mt MSS v gi ra ngoi 2 segment c kch thc cc i. Nu cc segment ny c xc nhn trc khi timeout, th bn gi s tng ca s nghn ln mt MSS cho mi mt segment nhn c ACK,t a ra mt ca s nghn bng 4 MSS, v gi ra ngoi 4 segment c kch thc cc i. Chui hnh ng ny c tip tc min l (1) ca s nghn nh hn ngng gii hn v (2) cc ACK v n ni trc thi gian timeout tng ng ca chng.

Trong pha ny ca hot ng kim sot tc nghn, ca s nghn tng nhanh theo hm m, tc l, ca s nghn c khi u t mt MSS , sau mt RTT ca s tng ln 2 segment (on), sau 2 RTT th ca s tng ln 4 segment, sau 3 RTT th ca s c tng ln thnh 8 segment, v.v Pha ny ca thut ton c gi l slow start(khi u chm) bi n bt u vi mt ca s nghn nh bng vi 1 MSS. (Tc truyn ca kt ni lc u chm nhng tng tc nhanh chng.) Pha slow start kt thc khi kch thc ca ca s vt qua gi tr ca ngng gii hn(threshold). Mt khi ca s nghn ln hn gi tr hin thi ca ngng gii hn, ca s nghn s tng mt cch tuyn tnh hn l tng theo hm m. c bit, nu w l gi tr hin ti ca ca s nghn, v w ln hn ngng gii hn th sau khi w gi ACK n ni, TCP s thay th w bng w+1. iu ny c tc ng lm tng ca s nghn ln 1 cho mi RTT m ton b ACK u n ni.Pha ny ca thut ton c gi l congestion avoidance (trnh nghn). Pha trnh nghn s cn c tip tc nu m bo c l cc ACK s ti ni trc khi timeout. Nhng kch thc ca s khng th tng mi mi, v do tc m ti TCP bn gi c th gi cng khng th tng mi mi. Cui cng , tc TCP s tin n mc m mt trong s cc lin kt trn qung ng s tr nn bo ha, v cc im mt mt (cng vi kt qu l mt timeout ti bn gi) s xut hin. Khi mt timeout xut hin, gi tr ca ngng gii hn c t bng mt na gi tr hin thi ca ca s nghn, v ca s nghn c t li bng mt MSS. Bn gi sau mt ln na tng ca s nghn nhanh chng theo hm m s dng phng php slow start cho ti khi ca s nghn chm ti ngng gii hn. Tng kt li: Khi ca s nghn thp hn ngng gii hn, ca s nghn gia tng theo hm m. Khi ca s nghn cao hn ngng gii hn, ca s nghn tng tuyn tnh. Khi c mt timeout, ngng gii hn c t bng mt na ca ca s nghn hin thi v ca s nghn sau c t bng mt.

Nu chng ta b qua pha slow start, ta s thy rng TCP v c bn tng kch c ca s ca n ln 1 vi mi RTT (v do tng tc truyn dn bng mt cp s cng) khi cc ng trong mng ca n khng b nghn, v gim kch c ca s ca n xung 2 ln vi mi mt RTT khi ng truyn b nghn. V l do ny, TCP thng c xem nh mt thut ton additive-increase (tng th theo cp s cng ), multiplicative-decrease (gim th theo cp s nhn) (AIMD).

Hnh 3.7-1: Qu trnh bin i ca s nghn ca TCP Qu trnh bin i ca s nghn ca TCP c m t trong Hnh 3.7-1. Trong hnh ny, ngng gii hn ban u bng 8*MSS. Ca s nghn tng nhanh theo hm m trong sut qu trnh slow start v chm ti ngng gii hn ti phin truyn dn th 3. Ca s nghn sau tng tuyn tnh cho ti khi c s mt mt xy ra, ch sau phin truyn th 7. Lu rng ca s nghn l 12*MSS khi c s mt mt xut hin. Ngng gii hn sau c t bng 5*CongWin=6*MSS v ca s nghn c t bng 1. V qu trnh x l tip tc . Thut ton kim sot tc

nghn ny l ca V.Jacobson; mt s chnh sa cho thut ton ban u ca Jacobson c m t trong [Stevens 1994, RFC 2581].

Mt chuyn i ti Nevada: Tahoe, Reno v Vegas (cc a im ny c t tn cho thut ton)


Thut ton iu khin tc nghn TCP c m t chnh xc thng c gi l Tahoe. Mt vn vi thut ton Tahoe l khi mt segment b mt, bn gi ca ng dng c th phi i mt khong thi gian di ht timeout. V l do ny, mt bin th ca Tahoe gi l Reno c p dng bi phn ln cc h iu hnh. Ging nh Tahoe, Reno t ca s nghn ca n bng 1 segment lc kt thc 1 timer. Tuy nhin, Reno cng bao gm c k thut truyn li nhanh (fast retransmit mechanism) ci m chng ta xt Phn 3.5 . Hy nh li rng, truyn li nhanh dn n vic truyn mt segment b thiu nu nhn c 3 ACK cho mt segment trc khi xut hin timeout ca segment . Reno cng s dng k thut khi phc nhanh (fast recovery mechanism), ci m v c bn hy b pha slow start sau khi xy ra truyn li nhanh. Nhng bn c quan tm c th tm hiu chi tit ti [Stevens 1994, RFC 2581] . Phn ln cc ci t TCP hin nay u s dng thut ton Reno. Tuy nhin c mt thut ton khc trong ti liu, thut ton Vegas, n c th ci thin hiu nng ca Reno. Trong khi Tahoe v Reno tc ng tr li tc nghn (v d .. lm y cc b m router), th Vegas c gng ngn nga nghn ngay t khi ang duy tr thng lng tt. tng c bn ca Vegas l (1) tm ra nghn ti cc router gia ngun v ch trc khi vic mt gi tin xy ra, v (2) lm gim tc mt cch tuyn tnh khi vic mt gi sp sy ra c pht hin. Vic mt gi sp xy ra c d on bng vic quan st cc RTT cc RTT m ln hn RTT ca cc packet cng nhiu th nghn xy ra ti cc router cng ln. Thut ton Vegas c tho lun chi tit trong [Brakmo 1995] ; mt nghin cu v hiu nng ca n c a ra trong [Ahn 1995] . Ti nm 1999, Vegas khng cn l mt phn ca hu ht cc ci t TCP.

Chng ti nhn mnh rng iu khin tc nghn TCP pht trin qua nhiu nm v vn ang pht trin. iu g l tt cho Internet khi m phn ln cc kt ni TCP n SMTP, FTP v Telnet traffic khng nht thit l tt cho mng Internet m Web chim u th nh hin nay hoc cho mng Internet trong tng lai, n s h tr nhng ngi bit c cc loi dch v.

TCP c m bo s cng bng hay khng?


Trong tho lun trn, chng ta lu rng mc ch ca c ch kim sot tc nghn ca TCP l chia s bng thng ca cc lin kt d b nghn mt cch cng bng gia cc kt ni TCP i qua lin kt . Nhng ti sao thut ton AIMD(tng theo cp s cng,gim theo cp s nhn) ca TCP t c mc tiu ny, c bit vic cho php cc kt ni TCP khc nhau c th bt u ti nhng thi im khc nhau v do c th c kch thc ca s khc nhau ti mt thi im no ? [Chiu 1989] a ra mt gii thch ngn gn xc tch v mang tnh trc gic v vic ti sao vic kim sot tc nghn ca TCP tp trung n vic cung cp mt s chia s cng bng bng thng ca mt lin kt hp d b nghn cho cc kt ni TCP ang cnh tranh nhau. Hy xem xt mt trng hp n gin v hai kt ni TCP ang chia s mt lin kt n c tc truyn l R, nh ch ra trong Hnh 3.7-2. Chng ta s gi nh rng c hai kt ni ny u c MSS v RTT ging nhau (do nu nu chng c cng kch c ca ca s nghn, th chng s c thng lng ging nhau), v gi nh rng chng c mt lng ln d liu truyn v khng c mt kt ni TCP hoc UDP datagrams no khc truyn trn ng lin kt chia s ny. Ngoi ra, chng ta s b qua pha slow start ca TCP, v gi nh rng cc kt ni TCP ang hot ng trong ch ngn nga (trnh) tc nghn (tng theo cp s cng,gim theo cp s nhn) ti tt c cc thi im.

Hnh 3.7-2: Hai kt ni TCP ang chia s mt ng lin kt hp n Hnh 3.7-3 v s thng lng thu c bi hai kt ni TCP . Nu TCP chia s mt cch cng bng bng thng ca lin kt cho hai kt ni, th thng lng thu c s gim xung theo hng mi tn 45 (chia s bng thng bng nhau) so vi ban u. Mt cch l tng, tng ca c hai thng lng s bng R (tt nhin, mi kt ni s nhn mt s chia s dung lng ca ng lin kt bng nhau nhng khng phi l trng thi mong mun), do mc ch cn thit l lm cho thng lng thu c gim xung mc no gn vi giao im ca ng chia s bng thng bng nhau vi ng s dng ti a bng thng trong Hnh 3.7-3. Gi s rng kch thc ca s TCP ln n mc m ti mt thi im cho trc, cc kt ni 1 v 2 c c thng lng nh c ch ra bi im A trong Hnh 3.73. Bi v tng bng thng ca lin kt c s dng ng thi bi hai kt ni l nh hn R, nn mt gi s khng xy ra, v c hai kt ni s tng ca s ca mnh ln 1/RTT nh l mt kt qu ca thut ton trnh nghn ca TCP. Do , thng lng hp chung ca hai kt ni i ln theo mt ng 45 (tng u cho c hai kt ni) bt u t im A. Cui cng, bng thng ca lin kt c s dng ng thi bi 2 kt ni s ln hn R v cui cng vic mt gi tin s xy ra. Gi nh rng cc kt ni ni 1 v 2 nhn ra vic mt gi tin khi chng nhn c thng lng nh c ch ra bi im B. Kt ni 1 v 2 sau s gim ca s ca chng

i 2 ln. Thng lng kt qu thu c do s nm im C, nm gia 1 vector bt u t B v kt thc ti im gc ta . Bi v bng thng kt hp c s dng nh hn R ti im C, do c hai kt ni mt ln na tng thng lng ca chng ln theo mt ng 45 bt u t C. Cui cng, vic mt gi tin s li xy ra, v d nh , ti im D, v hai kt ni mt ln na gim kch thc ca s i 2 ln. Tip tc nh vy. Bn nn t thuyt phc bn thn rng bng thng c s dng bi c hai kt ni cui cng s dao ng ln xung dc theo ng chia s bng thng bng nhau (ng gch t trong hnh 3.7-3). Bn cng nn t thuyt phc chnh mnh rng c hai kt ni s hi t n trng thi ny bt chp ni chng ang l trong khng gian hai chiu! Mc d nhiu gi thit l tng ha c a ra trong kch bn ny, nhng n vn cung cp mt cm nhn trc quan cho l do ti sao TCP dn ti mt s chia s ng u v bng thng gia cc kt ni.

Hnh 3.7-3: thng lng thc hin bi hai kt ni TCP 1 v 2 Trong kch bn c l tng ha trn, chng ta gi nh rng ch c cc kt ni TCP truyn qua lin kt d b nghn , v ch mt kt ni TCP c tng tc

vi mt cp host- ch. Trong thc tin, hai iu kin trn c bit khng t c, v cc ng dng client-server do c th thu c cc phn rt khng ng u ca bng thng ca lin kt. C nhiu ng dng mng chy trn TCP hn l UDP bi g chng mun s dng dch v truyn tin cy ca TCP. Nhng mt ngi pht trin ng dng chn TCP s nhn c khng ch l truyn d liu tin cy m cn c c kim sot tc nghn. Chng ta va xem cch thc m kim sot tc nghn TCP iu chnh tc truyn ca mt ng dng thng qua k thut ca s nghn. Mt s ng dng a phng tin khng chy trn TCP v l do nychng khng mun tc truyn ca mnh b iu chnh k c khi mng li rt cht chi.c bit, mt s ng dng in thoi Internet v truyn hnh hi ngh thng chy trn UDP. Cc ng dng ny thch vic y m thanh v video ca mnh vo mng mt tc c nh v chp nhn vic mt cc gi tin, hn l gim tc truyn ca mnh ti mc hp l ti cc thi im nghn v khng mt bt c gi tin no. Xut pht t cch nhn nhn ca TCP, cc ng dng a phng tin chy trn UDP khng c hp l chng khng hp tc vi cc kt ni khc, ln iu chnh tc truyn ca mnh mt cch thch hp. Mt thch thc ln trong nhng nm tr li y l phi pht trin cc c ch kim sot nghn cho Internet ngn nga vic truyn ti UDP a thng lng ca Internet ti mc t lit. Nhng k c khi chng ta c th p vic truyn ti UDP phi c x mt cch hp l, th vn v s cng bng s vn khng c gii quyt mt cch trit . iu ny l bi v khng c g c th dng mt ng dng ang chy trn TCP khi vic s dng nhiu kt ni song song. V d, trnh duyt Web thng s dng nhiu kt ni TCP song song truyn mt trang Web. (Con s chnh xc ca cc kt ni c th c cu hnh trong phn ln cc trnh duyt). Khi mt ng dng s dng nhiu kt ni song song, n s ly c mt lng ln hn cc phn ca bng thng trong mt lin kt b nghn. V d, xt mt lin kt c tc R h tr 9 ng dng client-server, vi mi ng dng s dng mt kt ni TCP. Nu mt ng dng mi i n v cng s dng mt kt ni TCP, th mi ng dng s nhn c tc

truyn nh nhau khong chng R/10. Nhng nu ng dng mi ny thay vo s dng 11 kt ni TCP song song, th ng dng mi ny s nhn c s phn b khng cng bng l R/2. Bi v lu lng truy cp Web ta khp trn Internet, nn a kt ni song song khng phi l iu him thy.

M t v m v cc TCP ng
Xt vic gi mt file rt ln qua mt kt ni TCP. Nu chng ta mun ly mt ci nhn v m v lu lng c gi bi ngun, chng ta c th b qua pha slow start. Qu thc, mt kt ni trong trong pha slow start trong mt khong thi gian tng i ngn bi v kt ni vt ra khi pha ny nhanh chng theo hm m. Khi chng ta b qua pha slow start, ca s nghn s ln ln mt cch tuyn tnh, c ct i mt na khi mt mt xy ra, ln ln mt cch tuyn tnh, b ct i mt na khi mt mt xy ra,v.v iu ny a ra l gii cho cch vn hnh theo dng rng ca ca TCP [Stevens 1994] nh ch ra Hnh 3.7-1. Vi cch vn hnh rng ca ny, thng lng trung bnh ca mt kt ni TCP s l bao nhiu? Trong khong thi gian round-trip (i v v) nht nh, tc m ti TCP gi d liu l hm ca ca s nghn v RTT hin ti: khi kch thc ca s l w*MSS v thi gian round-trip hin ti l RTT, th tc truyn ca TCP l (w*MSS)/RTT. Trong pha trnh nghn , TCP thm d bng thng b sung bng vic tng w ln mi mt RTT cho ti khi mt mt xy ra; k kiu W l gi tr ca w m ti mt mt xy ra. Gi s rng RTT v W l gn nh hng s (khng i) trong sut thi gian ca kt ni, tc truyn ca TCP nm trong khong t (W*MSS)/(2RTT) ti (W*MSS)/RTT. Nhng gi nh ny dn ti mt m hnh v m n gin ha cho cch vn hnh n nh ca TCP: mng s b(vt) mt gi tin t kt ni khi kch thc ca s ca kt ni tng n W*MSS; ca s nghn sau s b ct i mt na v sau tng ln mt MSS/RTT cho ti khi n mt ln na chm ngng W. Qu trnh x l ny lp i lp li ln ny ti ln khc. Bi v thng lng TCP tng tuyn tnh gia hai gi tr v cng ln, chng ta c:

Thng lng trung bnh ca mt kt ni= (.75*W*MSS)/RTT. S dng m hnh l tng ha cao ny cho cc trng thi n nh ng ca TCP, chng ta cng c th nhn c mt biu thc th v m n lin h gia tc mt mt ca mt kt ni vi bng thng c th ca n [Mahdavi 1997]. S bin i ny c ch ra trong bi tp v nh.

3.7.2 M hnh ha tr: Ca s nghn tnh


Nhiu kt ni TCP vn chuyn cc file tng i nh t mt host ti mt host khc. V d, vi HTTP/1.0 mi i tng trong mt trang Web c vn chuyn qua mt kt ni TCP ring bit, v a s cc i tng ny l cc file text nh hoc cc icon (biu tng) b. Khi vn chuyn mt file nh, vic thit lp v slow start ca kt ni TCP c th c th c mt tc ng ng k ti tr. Trong phn ny chng ta trnh by mt m hnh mang tnh phn tch xc nh lng tc ng ca vic thit lp kt ni v slow start ti tr. Vi mt i tng cho trc, chng ta nh ngha tr l khong thi gian t khi client bt u mt kt ni TCP cho ti khi client nhn c i tng c yu cu trong trng thi nguyn vn. Vic phn tch c trnh by y gi nh rng mng khng b nghn,tc l, kt ni TCP ang truyn mt i tng m khng phi chia s bng thng lin kt vi cc truyn ti (lu lng)TCP hoc UDP khc. (Chng ta s nhn xt v gi nh ny bn di ). Ngoi ra, khng lm mt tnh tng qut, chng ta tin hnh s phn tch ny trong ng cnh mng mt lin kt n gin nh ch ra trong Hnh 3.7-4. (Lin kt ny c th m hnh nh mt nt tht duy nht trn ng t ngun n ch. Xem phn bi tp c mt m rng r rng v trng hp ca a lin kt).

Hnh 3.7-4: Mt mng mt lin kt n gin kt ni gia client v server Chng ta chng a ra cc gi nh n gin ha sau: 1. Lng d liu m bn gi c th truyn pht ch b gii hn bi ca s nghn ca bn gi .(Nh vy, cc b m nhn TCP l ln). 2. Cc gi tin khng b mt ln v b li, do khng xy ra vic truyn li. 3. Tt c cc header giao thc tng trn bao gm TCP, IP v cc header ca tng lin kt l khng ng k v c b qua. 4. i tng (tc l, file) phi truyn bao gm mt s nguyn cc phn on c kch c MSS (kch c phn on ln nht ). 5. Ch c cc gi tin m c thi gian truyn ng k l cc gi tin m mang cc phn on TCP c kch c cc i. Cc gi tin yu cu , xc nhn v cc gi tin thit lp kt ni TCP c thi gian truyn l nh v khng ng k. 6. Ngng ban u trong c ch kim sot tc nghn TCP l mt gi tr ln v khng bao gi t c bi ca s nghn. Chng ta cng gii thiu cc k hiu sau: 1. Kch thc ca i ng c truyn pht l O bits. 2.MSS(phn on c kch thc cc i -maximum size segment) l S bits (v d, 536 bytes).

3. Tc truyn ca lin kt t server n client l R bps. 4. Khong thi gian m mt gi tin gi i v nhn v ACK c k hiu l RTT. Trong phn ny chng ta nh ngha RTT l thi gian tri qua mt gi tin nh i t mt client n server v sau quay tr li client, khng k thi gian truyn ca gi. N bao gm hai tr lan truyn t ngun ti ch gia hai h thng u cui v thi gian x l ti hai h thng u cui. Chng ta gi nh rng RTT ny cng bng vi RTT ca mt gi tin bt u ti server. Mc d s phn tch trnh by trong phn ny gi nh mt mng khng b nghn vi ch mt kt ni TCP, tuy nhin n vn a ra mt ci nhn su sc v cc trng hp thc t ca mng nghn a lin kt. i vi mt mng nghn, R i din cho lng bng thng nhn c trng thi bn trong mt kt ni ngun ti ch; v RTT i din cho thi gian tr quay vng bao gm cc tr do xp hng ti cc router t trc cc lin kt b nghn. Trong trng hp mng nghn, chng ta m hnh mi kt ni TCP nh mt kt ni constant-bit-rate (tc - bit- c nh) vi tc R bps ng trc bi ch mt pha slow start. (iu ny ch ra cch thc TCP Tahoe x l khi mt mt c pht hin vi ba ln ACK). Trong v d chng ta s dng gi tr ca R v RTT phn nh gi tr c trng ca mt mng b nghn. Trc khi bt u phn tch hnh thc, chng ta s c gng t c mt s hiu bit qua trc gic. Chng ta hy xt xem tr s l g nu nh khng c rng buc ca s nghn, tc l, nu server c php gi cc segment ta lng vo nhau cho ti khi ton b i tng c gi? tr li cho cu hi ny, u tin hy lu rng mt RTT c yu cu bt u mt kt ni TCP. Sau mt RTT client gi yu cu i tng (ci m c mang ti segment th 3 trong th tc 3 ln bt tay ca TCP). Sau tt c 2 RTT, client bt u nhn d liu t server. Client nhn d liu t server trong mt khong thi gian O/R, thi gian server truyn ton b i tng. Do , trong trng hp khng rng buc ca s tc nghn,

tng tr l 2 RTT + O/R. N m t mt rng buc thp hn; th tc slow start vi ca s nghn ng, chc chn s ko di tr ny.

Static Congestion Window(Ca s nghn tnh)


Mc d TCP s dng mt ca s nghn ng, nhng hiu kin thc u tin hy phn tch trng hp ca mt ca s nghn tnh. Cho W, mt s nguyn dng , k hiu mt ca s nghn tnh kch thc c nh. Cho ca s nghn tnh, server khng c php c nhiu hn W phn on cha nhn c ACK. Khi server nhn mt yu cu t pha client, server ngay lp tc gi W segment ta lng vo nhau ti client. Server sau s gi mt segment vo mng cho mi mt ACK m n nhn c t ph client. Server tip tc gi mt segment cho mi mt ACK cho ti khi tt c cc segment ca i tng c gi i. S c hai trng hp cn xem xt: 1. WS/R > RTT+S/R. Trong trng hp ny , server nhn mt ACK cho segment u tin trong ca s th nht trc khi server hon tt vic truyn pht ca ca s th nht ny. 2.WS/R < RTT+ S/R. Trong trng hp ny, server truyn cc segment cho ca s u tin trc khi server nhn mt ack cho segment u tin trong ca s. Hy xem xt trng hp 1, c m t Hnh 3.7-5 . Trong hnh ny, kch thc ca s W= 4 segment.

Hnh 3.7-5 trng hp WS/R > RTT + S/R Mt RTT c yu cu khi to kt ni TCP. Sau mt RTT, client gi yu cu i tng (ci c mang trn segment th 3 trong th tc 3 ln bt tay ca TCP). Sau khi tt c 2 RTT client bt u nhn d liu t server. Cc segment n mt cch nh k t server sau mi S/R giy, v client xc nhn mi segment m n nhn t server. Bi v server nhn c ACK u tin trc khi n hon tt vic gi cc segment ca 1 ca s, nn server tip tc truyn cc segment sau khi truyn cc segment ca ca s u tin. V bi v cc ACK ti server mt cch nh k mi S/R giy bt u t khi ACK u tin ti ni, nn server s truyn cc segment mt cch lin tc cho ti khi n truyn c ton b i tng. Do mt khi server bt u truyn i tng vi tc R, th n s tip tc truyn i tng vi tc R cho ti khi ton b i tng c truyn ht. tr do bng 2 RTT + O/R. By gi hy xem xt trng hp th 2, c minh ha Hnh 3.7-6.Trong hnh ny, kch thc ca s l W=2 segment.

Hnh 3.7-6: trng hp WS/R < RTT + S/R Mt ln na, sau tt c 2 RTT , client bt u nhn cc segment t server. Cc segment ny ti mt cch nh k sau mi S/R giy, v client xc nhn nhng segment m n nhn t server. Nhng by gi server hon tt vic truyn ca s u tin trc khi ACK u tin ti t pha client. Do , sau khi gi mt ca s, server phi ngng v ch mt ack trc khi bt u li vic truyn pht. Khi mt ack ti, server s gi mt segment mi ti client. Mt khi ack u tin ti, th cc ACK ca mt ca s cng ti, vi mi ack lin tip c bit bi S/R giy. Vi mi mt ack , server s truyn chnh xc mt segment. Do , server lun phin gia hai trng thi: trng thi truyn, trong sut khong thi gian ny n s truyn W segment; v trng thi tr hon (treo), trong lc ny n khng truyn g c v ch mt ack. tr l bng 2 RTT cng vi thi gian cn thit cho server truyn mt i tng, O/R, cng vi lng thi gian m server trong trng thi treo. xc nh lng thi gian m server trong trng thi treo, cho K= O/WS; nu O/WS khng phi l mt s nguyn, th lm trn K thnh s nguyn gn nht. Lu rng K l s ca s ca d liu c trong i tng c kch c O. Server trong trng thi treo gia vic truyn mi mt ca s, tc l, cho K-1 khong thi gian, vi mi khong di RTT- (W-1)S/R (nhn lc trn). Do , trong trng hp 2 ta c :

tr= 2 RTT + O/R + (K-1)[S/R + RTT - W S/R] . Kt hp c hai trng hp chng ta thu c: tr = 2 RTT + O/R + (K-1) [S/R + RTT - W S/R]+ Trong [x]+=max(x,0). y l ton b phn tch ca ta v ca s tnh. Phn tch trn cho ca s ng th phc tp hn nhng tng t nh vic phn tch cc ca s tnh. 3.7.3 Modeling Latency: Dynamic Congestion Window (M hnh ha tr : Ca s nghn ng) By gi chng ta nghin cu t m v tr ca vic truyn mt file khi ca s nghn ng ca TCP c p dng. Nh li rng server u tin bt u vi mt ca s nghn bng mt segment v gi mt segment ti client. Khi n nhn mt ack cho segment , n tng ca s nghn ln 2 segment v gi 2 segments ti client (cch nhau mt khong S/R giy).Khi n nhn cc ack cho 2 segment ny, n tng ca s nghn ln 4 segment v gi 4 segment ti client (mt ln na cch nhau mt khong S/R giy). Qu trnh ny tip tc, vi cc ca s nghn nhn i mi RTT. Mt lc thi gian cho TCP c minh ha Hnh 3.7-7

Figure 3.7-7: thi gian TCP trong pha slow start Lu rng O/S l s lng segment trong i tng; trn lc trn , O/S =15. Xt s lng cc segment trong mi mt ca s. Ca s u tin cha 1 segment; ca s th 2 cha 2 segment; ca s th 3 cha 4 segment. Tng qut hn ca s th k cha 2k-1 segment. Cho K l s ca s m ph c i tng; trong lc trn K=4 . Tng qut ta c th din gii K theo khi nim O/S nh bn di :

Sau khi truyn d liu ca mt ca s, server c th treo (tc l, dng vic truyn) trong khi n ch mt ack. Trong lc trc, server treo sau khi truyn ca s th nht v th hai , nhng khng phi sau khi truyn ca s th ba. By gi ta hy tnh lng thi gian treo sau khi truyn ca s th k. Thi gian t khi server bt u truyn ca s th k cho ti khi server nhn c mt ack cho segment u tin trong ca s l S/R+RTT. Thi gian truyn ca s th k s l (S/R)2k-1. Thi gian treo l s khc nhau ca hai s lng ny, tc l, [S/R+RTT - (S/R)2k-1.]+ Server c kh nng treo sau khi truyn mi K-1 ca s u tin. (Server hon tt cng vic sau khi truyn ca s th K). By gi ta c th tnh tr truyn file. tr c 3 thnh phn : 2RTT cho vic thit lp kt ni TCP v yu cu file; O/R, thi gian truyn ca i tng; v tng tt c thi gian treo. Do :

Bn c nn so snh biu thc trn vi biu thc ca tr cho ca s nghn tnh; tt c cc khi nim l hon ton nh nhau tr khi nim WS/R cho ca s tnh c thay bng 2k-1S/R cho ca s ng. thu c biu thc gn hn cho tr, t Q l lng thi gian server s treo nu i tng cha mt lng v hn cc segment:

Lng thi gian thc m server treo l P= min{ Q,K-1}. Trong lc trc y P=Q=2. Kt hp hai ng thc ta c :

Chng ta c th lm n gin hn na cng thc trn cho tr bng vic k hiu:

Kt hp li ta c biu thc sau cho tr:

Do tnh tr, n gin ta ch phi tnh K v Q, t P=min{Q,K-1}, v a P vo trong cng thc. Rt th v khi so snh tr TCP vi tr m s xy ra nu khng c kim sot tc nghn(tc l, khng c rng buc no v ca s nghn ). Khng c kim sot nghn, tr l 2RTT+O/R, ci m ta nh ngha l tr nh nht. l mt bi tp n gin ch ra rng

T cng thc trn, chng ta thy rng slow start ca TCP s khng lm tng mt cch ng k tr nu RTT<< O/R, c ngha l , nu RTT nh hn nhiu so vi thi gian truyn ca i tng. Do , nu ta gi mt i tng tng i ln qua mt lin kt khng nghn , tc cao, th pha slow start s c mt tc ng khng ng k ti tr. Tuy nhin, vi Web chng ta thng truyn cc i tng nh qua cc lin kt nghn, trong trng hp ny pha slow start c th lm tng mt cch ng k tr (nh chng ta s thy trong phn sau y). By gi chng ta hy xem xt mt s tnh hung v d sau. Trong tt c cc tnh hung ta t S=536 bytes , gi tr mc nh thng thng cho TCP. Chng ta s dng RTT l 100 msec, y khng phi l mt gi tr c trng cho tr trn cc lin kt nghn mc va phi. u tin hy xem xt vic truyn mt i tng kh ln c kch thc O=100Kbytes. S ca s m ph i tng ny l K=8 . Cho mt s tc truyn, biu sau nghin cu v tc ng ca c ch slow start ti tr .

Ta thy t lc trn rng i vi cc i tng ln, pha slow start thm vo tr ng k ch khi tc truyn cao. Nu tc truyn thp, th ack gi tr li tng i nhanh, v TCP nhanh chng nhy ln tc cao nht ca n. V d , khi R=100Kbps, s khong thi gian treo l P=2 trong khi s ca s truyn l K=8; tc l server ch treo sau hai ca s u trong s 8 ca s. Mt khc, khi R= 10Mbps, server treo gia mi ca s, iu ny lm tng ng k tr. By gi xt vic gi mt i tng nh c kch c O= 5Kbytes. S ca s ph i tng ny l K=4. Cho mt s tc truyn, biu sau nghin cu tc ng ca c ch slow start.

Mt ln na pha slow start thm mt lng ng k tr khi tc truyn cao. V d, khi R=1Mbps , server treo gia mi ca s, iu ny khin tr ln hn 2 ln so vi tr nh nht. i vi mt RTT ln hn, tc ng ca pha slow start tr nn r rng hn cho cc i tng nh vi tc truyn nh hn. Bng sau nghin c tc ng ca pha slow start vi RTT=1 giy v O=5 Kbytes (K=4)

Tng kt li, pha slow start c th tng mt cch ng k tr khi kch thc ca mt i tng tng i nh v RTT tng i ln. Khng may thay, iu ny thng xuyn xy ra khi gi cc i tng qua World Wide Web.

V d :HTTP
Nh mt ng dng v phn tch tr, by gi hy tnh thi gian phn hi cho mt trang Web c gi qua HTTP khng n nh. Gi s rng trang bao gm mt trang HTML c s v M nh lin quan. cho n gin, hy gi s rng mi mt M+1 i tng bao gm chnh xc O bits. Vi HTTP khng n nh, mi i tng c truyn c lp, ci ny tip sau ci kia. Thi gian phn hi ca mt trang web do bng tng tr ca cc i tng ring l. Do

Lu rng thi gian phn hi cho HTTP khng n nh ly t : Thi gian phn hi = (M+1)O/R + 2(M+1)RTT + tr do pha slow start ca TCP vi mi mt trong s M+1 i tng. Mt cch r rng nu c nhiu i tng trong mt trang web v nu RTT l ln , th giao thc HTTP khng n nh s c hiu nng phn hi km. Trong phn bi tp ta s xem xt t m thi gian phn hi cho cc s truyn HTTP khc, bao gm cc kt ni n nh v khng n nh vi cc kt ni song song. Bn c cng c khuyn khch xem [Heidemann] cho nhng phn tch lin quan.

Ti liu tham kho


[Ahn 1995] J.S. Ahn, P.B. Danzig, Z. Liu and Y. Yan, Experience with TCP Vegas: Emulation and Experiment, Proceedings of ACM SIGCOMM '95, Boston, August 1995. [Brakmo 1995] L. Brakmo and L. Peterson, TCP Vegas: End to End Congestion Avoidance on a Global Internet, IEEE Journal of Selected Areas in Communications, 13(8):1465-1480, October 1995. [Chiu 1989] D. Chiu and R. Jain, "Analysis of the Increase and Decrease Algorithms for Congestion Avoidance in Computer Networks," Computer Networks and ISDN Systems, Vol. 17, pp. 1 - 14. [Floyd 1991] S. Floyd, Connections with Multiple Congested Gateways in PacketSwitched Networks, Part 1: One-Wat Traffic, ACM Computer Communications Review, Vol. 21, No. 5, October 1991, pp. 30-47. [Heidemann 1997] J. Heidemann, K. Obraczka and J. Touch, Modeling the Performance of HTTP Over Several Transport Protocols," IEEE/ACM Transactions on Networking, Vol. 5, No. 5, October 1997, pp. 616-630. [Hoe 1996] J.C. Hoe, Improving the Start-up Behavior of a Congestion Control Scheme for TCP. Proceedings of ACM SIGCOMM'96, Stanford, August 1996.

[Jacobson 1988] V. Jacobson, Congestion Avoidance and Control. Proceedings of ACM SIGCOMM '88. August 1988, p. 314-329. [Lakshman 1995] T.V. Lakshman and U. Madhow, "Performance Analysis of Window-Based Flow Control Using TCP/IP: the Effect of High Bandwidth-Delay Products and Random Loss", IFIP Transactions C-26, High Performance Networking V, North Holland, 1994, pp. 135-150. [Mahdavi 1997] J. Mahdavi and S. Floyd, TCP-Friendly Unicast Rate-Based Flow Control. unpublsihed note, January 1997. [Nielsen 1997] H. F. Nielsen, J. Gettys, A. Baird-Smith, E. Prud'hommeaux, H.W. Lie, C. Lilley, Network Performance Effects of HTTP/1.1, CSS1, and PNG, W3C Document, 1997 (also appeared in SIGCOMM' 97). [RFC 793] "Transmission Control Protocol," RFC 793, September 1981. [RFC 854] J. Postel and J. Reynolds, "Telnet Protocol Specifications," RFC 854, May 1983. [RFC 1122] R. Braden, "Requirements for Internet Hosts -- Communication Layers," RFC 1122, October 1989. [RFC 1323] V. Jacobson, S. Braden, D. Borman, "TCP Extensions for High Performance," RFC 1323, May 1992. [RFC 2581] M. Allman, V. Paxson, W. Stevens, " TCP Congestion Control, RFC 2581, April 1999. [Shenker 1990] S. Shenker, L. Zhang and D.D. Clark, "Some Observations on the Dynamics of a Congestion Control Algorithm", ACM Computer Communications Review, 20(4), October 1990, pp. 30-39. [Stevens 1994] W.R. Stevens, TCP/IP Illustrated, Volume 1: The Protocols. Addison-Wesley, Reading, MA, 1994. [Zhang 1991] L. Zhang, S. Shenker, and D.D. Clark, Obervations on the Dynamics of a Congestion Control Algorithm: The Effects of Two Way Traffic , ACM SIGCOMM '91, Zurich, 1991

3.8 Tm tt
Chng ta bt u chng ny bng cch nghin cu cc dch v m mt giao thc tng vn chuyn c th cung cp cho cc ng dng mng. mt kha cnh no , giao thc tng vn ti c th rt n gin v cung cp mt dch v no-frills cho cc ng dng, ch cung cp chc nng ghp knh/phn knh cho cc tin trnh giao tip. Giao thc UDP ca Internet l v d v mt giao thc tng vn ti nofrills (v no-thrills, t quan im ca mt ai quan tm n mng) nh vy. mt kha cnh khc, mt giao thc tng vn ti c th cung cp a dng cc m bo cho cc ng dng, chng hn nh cc m bo truyn tin cy ca d liu, cc m bo v tr v cc m bo v bng thng. Tuy nhin, cc dch v m mt giao thc vn ti c th cung cp thng b hn ch bi m hnh dch v ca giao thc tng mng nm bn di. Nu giao thc tng mng khng th cung cp cc m bo v tr hoc bng thng cho cc segment tng vn ti, th giao thc tng vn ti khng th cung cp cc m bo v tr hoc bng thng cho cc thng ip c gi gia cc tin trnh. Chng ta hc trong Phn 3.4 rng mt giao thc tng vn ti c th cung cp truyn d liu tin cy ngay c khi tng mng pha di l khng tin cy. Chng ta thy rng vic cung cp truyn d liu tin cy c nhiu im tinh vi, nhng nhim v c th c thc hin bng cch kt hp cn thn cc ack, timer, truyn li, v cc s th t. Mc d chng ta bao qut truyn d liu tin cy trong chng ny, nhng chng ta nn ghi nh rng truyn d liu tin cy c th c cung cp bi cc giao thc tng lin kt, tng mng, tng vn ti hoc tng ng dng. Bt k tng no trong bn tng trn ca chng giao thc u c th thc hin cc ack, timer, truyn li, cc s th t v cung cp truyn d liu tin cy cho tng bn trn. Trong thc t, trong nhng nm qua, cc k s v cc nh khoa hc my tnh c thit k v thc hin c lp cc giao thc tng lin kt, tng mng, tng vn ti v tng ng dng nhng tng m cung cp truyn d liu tin cy (mc d nhiu giao thc trong s lng l bin mt). Trong Phn 3.5, chng ta xem xt k v TCP, giao thc tng vn ti hng kt ni v tin cy ca Internet. Chng ta bit c rng TCP rt phc tp, lin quan n qun l kt ni, iu khin lung, tnh ton thi gian kh hi, cng nh truyn d liu tin cy. Trong thc t, TCP thc s phc tp hn nhng g m chng ta c thc hin vi n - chng ti c tnh khng tho lun v mt lot cc bn v sa li TCP, v cc ci tin c thc hin rng ri trong cc phin bn khc nhau ca TCP. Tuy nhin, tt c nhng ci phc tp ny, l n i vi cc ng dng

mng. Nu mt client trn mt host mun truyn d liu tin cy n mt server trn mt host khc, n ch n gin l m mt socket TCP n server v sau bm d liu vo socket . ng dng client-server s khng bit g v tt c nhng ci phc tp ca TCP. Trong Phn 3.6 chng ta tm hiu v kim sot tc nghn t mt gc rng, v trong Phn 3.7 chng ta ch ra lm th no TCP thc hin kim sot tc nghn. Chng ta bit c rng tc nghn l bt buc i vi phc li ca mng. Nu khng c kim sot tc nghn, mt mng li c th d dng tr thnh b treo, vi mt t hoc khng c d liu no ang c vn chuyn end-to-end. Trong Phn 3.7 chng ta bit c rng TCP thc hin mt c ch kim sot tc nghn endto-end bng cc tng theo cp s cng tc truyn ca n khi ng kt ni TCP c nh gi l hon ton khng tc nghn, v gim theo cp s nhn tc truyn dn ca n khi mt mt xy ra. C ch ny cng c gng cung cp cho mi kt ni TCP i qua mt lin kt tc nghn mt phn bng nhau ca bng thng lin kt. Chng ta cng nghin cu su hn tc ng ca vic thnh lp kt ni TCP v slow start (khi u chm) n tr. Chng ta quan st thy rng trong nhiu tnh hung quan trng, vic thit lp kt ni v slow start ng gp ng k vo tr u cui. Chng ta nhn mnh mt ln na rng iu khin tc nghn TCP pht trin qua nhiu nm, v hin vn l mt lnh vc nghin cu chuyn su, v c kh nng s tip tc pht trin trong nhng nm sp ti. Trong Chng 1 chng ta ni rng mt mng my tnh c th c phn chia thnh mng bin v mng li. Bin ca mng bao gm tt c mi th m xy ra trong cc h thng u cui. n thi im hin ti n bao gm tng ng dng v tng vn ti, tho lun ca chng ta v bin ca mng hon thnh. Tip theo chng ta s khm ph v li ca mng! Cuc hnh trnh ny bt u t chng tip theo, ni chng ta s nghin cu v tng mng, v tip tc trong Chng 5, ni chng ta s nghin cu v tng lin kt.

Bi tp v nh v cc cu hi tho lun Chng 3


Cu hi n tp
Phn 3.1-3.3 1) Xt mt kt ni TCP gia host A v host B. Gi s rng cc segment TCP i t host A n host B c s hiu cng ngun l x v s hiu cng ch l y. S hiu cng ngun v ch cho cc segment i t host B n host A l g? 2) M t l do ti sao mt nh pht trin ng dng c th chn chy ng dng ca h trn UDP ch khng phi l TCP. 3) ng dng c th truyn d liu tin cy ngay c khi ng dng chy trn UDP hay khng? Nu c,th lm nh th no? Phn 3.5 4) ng hay Sai: a) Host A ang gi cho host B mt file ln qua mt kt ni TCP. Gi s host B khng c d liu gi n A. Host B s khng gi cc xc nhn n host A, bi v B khng th lp ngc d liu xc nhn.ng hay sai? b) Kch thc ca TCP RcvWindow khng bao gi thay i trong sut thi gian kt ni? c) Gi s host A ang gi cho host B mt file ln qua mt kt ni TCP. S lng cc byte cha c xc nhn m A s gi khng th vt qu kch thc ca b m nhn. ng hay sai? d) Gi s host A ang gi mt file ln n host B qua mt kt ni TCP. Nu s th t cho mt segment ca kt ni ny l m, th s th t cho segment tip theo nht thit phi l m+1. ng hay sai? e) Segment TCP c mt trng trong header ca n cho RcvWindow. ng hay sai? f) Gi s rng SampleRTT cui cng trong mt kt ni TCP bng 1 giy. Khi Timeout cho kt ni ny s nht thit phi c thit lp mt gi tr >= 1 giy. ng hay sai? g) Gi s host A gi cho host B mt segment vi s th t 38 v 4 byte d liu. Khi trong cng segment ny s xc nhn nht thit phi l 42?

5) Gi s A s gi hai segment TCP ta lng vo nhau n B. Segment u tin c s th t 90; segment th hai c s th t 110. a) C bao nhiu trong segment khc u tin? b) Gi s rng segment u tin b mt, nhng segment th hai n c B. Trong xc nhn m B gi n A, s xc nhn s l g? 6) Hy xem xt v d Telnet tho lun trong Phn 3.5. Mt vi giy sau khi ngi s dng g k t 'C' th ngi s dng s g tip k t 'R'. Sau khi g k t 'R' c bao nhiu segment c gi i v nhng g c t vo trng s th t v trng xc nhn ca cc segment. Phn 3.7 7) Gi s c hai kt ni TCP c mt trn mt s lin kt nt c chai c tc R b/s. C hai kt ni u c mt tp tin rt ln gi (trong cng mt hng qua lin kt nt c chai). Vic truyn i ca cc tp tin bt u cng mt thi im. Tc truyn m TCP s cung cp cho mi kt ni l bao nhiu? 8) ng hay Sai: Xem xt vic kim sot tc nghn TCP. Khi mt timer ht hn pha ngi gi, ngng gii hn c thit lp bng mt na gi tr trc y ca n?

Cc vn
1) Gi s client A bt u mt phin FTP vi server S. Vo cng thi im , client B cng bt u mt phin FTP vi server S. Cung cp s hiu cng ngun v ch c th cho: (a) cc segment c gi t A n S? (b) cc segment c gi t B n S? (c) cc segment c gi t S n A? (d) cc segment c gi t S n B? (e) Nu A v B l cc host khc nhau, c th xy ra trng hp rng s hiu cng ngun trong cc segment t A n S cng tng t nh ca t B n S khng? (f) Lm th no v nu chng l cng mt host? 2) TCP v UDP s dng b 1 cho cc checksum ca chng. Gi s bn c c ba t 8-bit sau: 01010101, 01110000, 11001100. Tng b 1 ca cc t ny l g? Ch ra tt c cng vic. Ti sao UDP a ra b 1 ca tng, tc l, ti sao khng ch s dng mt tng? Vi c ch b 1, lm th no ngi nhn pht hin c li. C th xy ra trng hp l mt li 1-bit s khng b pht hin khng? Lm th no vi mt li 2-bit?

3) Giao thc rdt2.1 s dng c ACK v NAK. Thit k li giao thc , vic thm vo cc c ch giao thc b sung cho bt k iu g l cn thit, i vi trng hp m ch c cc thng ip ACK c s dng. Gi s rng cc gi tin c th b hng, nhng khng b mt. Hy a ra cc FSM pha ngi gi v ngi nhn, v mt du vt ca giao thc ca bn trong vic hot ng (s dng cc du vt nh trong Hnh\ ref{fig57}). Cng ch ra cc thc m giao thc lm vic trong trng hp khng c li, v ch ra cch thc m giao thc ca bn phc hi t knh b li bit. 4) Hy xem xt FSM sau y (khng chnh xc) cho pha ngi nhn trong giao thc rtd2.1.

Nhn vo pha ngi nhn ny, khi hot ng vi ngi gi c th hin trong Hnh 3.4-5 c th dn ngi gi v ngi nhn i vo mt trng thi treo, mi pha u ang i mt s kin m s khng bao gi xy ra. 5) Trong giao thc rdt3.0, cc gi tin ACK chy t ngi nhn n ngi gi khng c cc s th t (mc d chng c mt trng ACK ci m cha s th t ca gi tin m chng ang xc nhn). Ti sao cc gi tin ACK ca chng ta khng yu cu cc s th t? 6) V FSM cho pha ngi nhn ca giao thc rdt 3.0. 7) a ra mt du vt ca cc hot ng ca giao thc rdt3.0 khi cc gi d liu v cc gi tin xc nhn b ct xn. Du vt ca bn nn tng t nh c s dng trong Hnh 3.4-9. 8) Hy xem xt mt knh m c th mt cc gi tin nhng c mt tr ti a l bit trc. Sa i giao thc rdt2.1 bao gm timeout pha ngi gi v truyn

li. Tranh lun xem ti sao giao thc ca bn c th giao tip mt cch chnh xc trn knh ny. 9) Pha ngi gi ca rdt3.0 ch n gin l b qua (tc l, c khng c hnh ng trn) tt c cc gi tin nhn c m b li hoc c gi tr sai trong trng acknum ca mt gi tin xc nhn (gi tin ACK). Gi s rng trong hon cnh nh vy, rdt3.0 n gin ch truyn li gi d liu hin hnh. Giao thc s vn lm vic c? (Gi : Hy xem xt nhng g s xy ra ch trong trng hp l n c li, khng c mt gi v khng c timeout sm xy ra. Hy xem xt bao nhiu ln gi tin th n c gi i, trong gii hn khi n tin n v cng. 10) Hy xem xt v d cross-country th hin trong Hnh 3.4-10. Kch thc ca s phi ln nh th no cho vic s dng knh ln hn 90%? 11) Thit k mt giao thc truyn d liu ng tin cy, c ng ng v ch s dng cc xc nhn tiu cc. Lm th no giao thc ca bn nhanh chng phn hi li cc gi b mt khi tc xut hin ca d liu pha ngi gi l thp? L cao? 12) Hy xem xt vic vn chuyn mt tp tin rt ln c L byte t host A n host B. Gi s mt MSS bng 1460 byte. a) Chiu di ti a ca L bng bao nhiu s th t TCP khng b cn kit? Nh li rng trng s TCP c bn byte. b) Vi L bn c c (a), tm xem phi mt bao lu truyn file trn. Gi s rng c tng cng 66 byte cho phn header ca tng vn ti, tng mng, v tng lin kt d liu c thm vo mi segment trc khi gi tin kt qu c gi i trn mt lin kt 10 Mb/s. B qua iu khin lung v kim sot tc nghn, nh vy A c th y ra cc segment ta lng vo nhau v lin tc. 13) Trong Hnh 3.5-5, chng ta thy rng TCP ch i cho n khi n nhn c ba ACK trng lp trc khi thc hin mt truyn li nhanh. Ti sao bn ngh rng cc nh thit k TCP li chn khng thc hin mt truyn li nhanh sau khi ACK trng lp u tin cho mt segment c nhn? 14) Hy xem xt cc th tc ca TCP c lng RTT. Gi s rng x = 0,1. Cho SampleRTT1 l SampleRTT gn y nht, cho SampleRTT2 l SampleRTT k tip gn y nht, v.v (a) i vi mt kt ni TCP nht nh, gi s c 4 xc nhn c tr li vi cc SampleRTT tng ng l SampleRTT4, SampleRTT3, SampleRTT2, v SampleRTT1. Biu din EstimatedRTT di dng bn SampleRTT . (b) khi qut cng thc ca bn cho n mu thi gian kh hi. (c) i vi cng thc trong phn (b) cho n tin n v cng. Tho lun v l do ti sao cch tnh trung bnh ny li c gi l mt trung bnh di chuyn theo hm m.

15) Hy tham kho Hnh 3.7-3 ci m minh ha s hi t ca thut ton tng theo cp s cng, gim theo cp s nhn ca TCP. Gi s rng thay v gim theo cp s nhn, TCP gim kch thc ca s bng lng khng i. Kt qu ca vic tng theo cp s cng v gim theo cp s cng s hi t n mt thut ton chia s bnh ng ch? Bin minh cho cu tr li ca bn bng cch s dng mt s tng t nh Hnh 3.7-3. 16) Nh li m hnh l tng cho cc trng thi n nh ng ca TCP. Trong khong thi gian t khi kch thc ca s ca kt ni thay i t (W * MSS) / 2 n W * MSS, ch c mt gi d liu b mt (vo cui ca thi gian ny). (a) Ch ra rng tc mt mt bng L = tc mt = 1 / [(3 / 8) * W2 - W / 4]. (b) S dng kt qu trn ch ra rng nu mt kt ni c tc mt L, th bng thng trung bnh ca n l xp x c cho bi: bng thng trung bnh ca kt ni ~ 1,22 * MSS / (RTT * sqrt (L)). 17) Hy xem xt vic gi mt i tng c kch thc O = 100 Kbytes t server n client. Cho S = 536 byte v RTT = 100msec. Gi s giao thc vn ti s dng cc ca s tnh vi kch thc ca s W. a) i vi mt tc truyn ti bng 28 Kb/s, xc nh tr ti thiu c th. Xc nh kch thc ca s ti thiu t c tr ny. b) Lp li (a) cho 100 Kb/s. c) Lp li (a) cho 1 Mb/s. d) Lp li (a) cho 10 Mb/s. 18) Gi s TCP tng ca s tc nghn ca mnh bng hai thay v mt mi xc nhn trong sut thi gian slow start. Nh vy ca s u tin bao gm mt segment, ca s th hai bng ba segment, ca s th ba bng chn segment, v.v i vi th tc slow start ny: a) Biu din K theo O v S. b) Biu din Q theo RTT, S v R. c) Biu din tr theo P = min (K-1, Q), O, R v RTT. 19) Xt trng hp RTT = 1 giy v O = 100 Kbyte. Chun b mt biu (tng t nh cc biu trong Phn 3.5.2) ci m so snh tr ti thiu (O / R + 2 RTT) vi tr vi slow start cho R = 28Kbps, 100 Kbps, 1 Mbps v 10 Mbps.

20)

ng hay Sai.

a) Nu mt trang Web bao gm chnh xc mt i tng, th kt ni khng lin tc v kt ni lin tc c chnh xc cng mt hiu sut thi gian phn hi? b) Xt vic gi mt i tng c kch thc O t server ti trnh duyt qua TCP. Nu O> S, trong S l kch thc segment ti a, th server s b tr hon t nht mt ln? c) Gi s mt trang web bao gm 10 i tng, mi i tng c kch thc O bit. i vi HTTP thng trc, phn RTT ca thi gian phn hi l 20 RTT? d) Gi s mt trang web bao gm 10 i tng, mi i tng c kch thc O bit. i vi HTTP khng thng trc vi 5 kt ni song song, phn RTT ca thi gian phn hi l 12 RTT? 21) Phn tch cho cc ca s ng trong vn bn gi nh rng c mt lin kt gia server v client. Lm li phn tch vi T lin kt gia server v client. Gi s mng khng c tc nghn, do , cc gi khng phi tri qua tr do xp hng. Tuy nhin, cc gi tin phi tri qua mt tr do lu tr v chuyn tip. nh ngha ca RTT l ging nh c a ra trong phn kim sot tc nghn TCP. (Gi : Thi gian server gi ra cc segment u tin cho n khi n nhn c xc nhn l TS / R + RTT.) 22) Nh li tho lun phn cui ca mc 3.7.3 v thi gian p ng cho mt trang Web. i vi trng hp cc kt ni khng lin tc, xc nh mt biu thc chung cho mt phn ca thi gian p ng do slow start ca TCP. 23) Vi HTTP thng trc, tt c cc i tng c gi qua cng mt kt ni TCP. Nh chng ta tho lun trong Chng 2, mt trong nhng ng lc ng sau HTTP thng trc (vi pipelining) l gim bt nh hng ca vic thit lp kt ni TCP v slow start ln thi gian p ng cho mt trang Web. Trong vn ny, chng ta nghin cu gian p ng cho HTTP thng trc. Gi s rng client yu cu tt c cc hnh nh cng mt lc, nhng ch khi n n nhn c ton b trang HTML c bn. Cho M+1 biu th s lng i tng v cho O biu th kch thc ca tng i tng. a) Chng t rng thi gian phn hi c dng (M 1) O / R + 3RTT + tr do slow_start. So snh s ng gp ca cc RTT trong biu thc ny bit rng HTTP khng thng trc. b) Gi s K = log2 (O / R 1) l mt s nguyn, do , ca s cui cng ca file HTML c s truyn mt lng segment ca ton b ca s, tc l, ca s K truyn 2 K-1 segment. Cho P '= min (Q, K'-1) v

Lu rng K 'l s ca ca s m bao gm mt i tng c kch thc (M+1) O v P' l s ca thi gian tr hon khi gi mt i tng ln qua mt kt ni TCP duy nht. Gi s (sai) server c th gi nhng hnh nh m khng cn ch i cc yu cu chnh thc cho cc hnh nh t client. Ch ra rng thi gian p ng l thi gian gi mt i tng ln c kch thc (M+1) O:

c) Thi gian p ng thc t cho HTTP thng trc l mt s ln hn xp x ny. iu l do server phi i mt yu cu cho nhng hnh nh trc khi gi nhng hnh nh ny i. c bit, thi gian tr hon gia ca s th K v ca s th (K+1) khng phi l [S / R + RTT - 2K-1 (S / R)] + nhng c thay cho RTT. Ch ra rng

24) Xt trng hp RTT=100 msec, O=5Kbyte, v M=10. Xy dng mt biu so snh cc thi gian p ng cho cc kt ni khng thng trc v thng trc c tc 28 kbps, 100 kbps, 1 Mbps v 10 Mbps. Lu rng HTTP thng trc c thi gian p ng thp hn ng k so vi HTTP khng thng trc vi tt c cc tc truyn dn tr 28 Kbps. 25) Lp li cu hi trn cho trng hp ca RTT = 1 giy, O = 5 Kbytes, M = 10. Lu rng i vi nhng tham s ny, HTTP thng trc cho mt thi gian p ng thp hn ng k so vi HTTP khng thng trc vi tt c cc tc truyn dn. 26) By gi xt HTTP khng thng trc vi kt ni TCP song song. Nh li rng cc trnh duyt thng thng hot ng ch ny khi s dng HTTP/1.0. Cho X biu th s lng ti a cc kt ni song song m client (trnh duyt) c php m. Trong ch ny, u tin client s dng mt kt ni TCP c c file HTML c s. Khi nhn c file HTML c s, client thit

lp cc tp M / X ca cc kt ni TCP, vi mi tp c X kt ni song song. Chng t rng tng thi gian p ng c dng:


thi gian p ng = (M 1) O / R + 2 (M / X 1) RTT + tr do tr hon slow start.

So snh s ng gp ca RTT lin quan n thi gian p ng ca kt ni thng trc v kt ni khng thng trc (khng song song).

Cc cu hi tho lun
1) Xt vic cc m thanh c lu tr thnh lung. N c ngha cho vic chy ng dng trn TCP hay UDP? Ci no trong s chng c RealNetwork s dng? Ti sao? C bt k sn phm m thanh lu tr thnh lung khc khng? Giao thc vn ti no m chng s dng v ti sao?

Nhim v lp trnh
Trong nhim v lp trnh ny, bn s vit code mc truyn ti vic gi v nhn thc hin mt giao thc truyn d liu tin cy n gin - cho giao thc bit xen k hoc mt giao thc Go-Back-N. N thc s th v v thc hin ca bn s khc bit rt nh vi nhng g c yu cu trong mt tnh hung thc t. V bn c l khng c my c lp (vi mt h iu hnh m bn c th sa i), nn code ca bn s phi thc hin trong mt mi trng phn cng /phn mm m phng. Tuy nhin, giao din lp trnh cung cp cho on chng trnh ca bn (v d, on code c th gi cc thc th ca bn t pha trn (tc l, t tng 5) v t bn di (tc l, t tng 3)) l rt gn vi nhng g c thc hin trong mt mi trng UNIX thc t. (Tht vy, cc giao din phn mm m t trong nhim v lp trnh ny, thc t hn rng ngi gi v ngi nhn lp v hn nh nhiu sch gio khoa m t). Vic dng/khi ng ca cc timer cng c m phng, v cc ngt timer s dn n timer ca bn x l on chng trnh c kch hot. Bn c th tm cc chi tit y v vic phn lp trnh, cng nh code C m bn s cn to ra mi trng m phng phn cng / phn mm ti http://gaia.cs.umass.edu/kurose/transport/programming_assignment.htm