1
3:TransportLayer 3b1
TCP:Tng quan RFCs:793,1122,1323,2018,2581
rTruyn songcông:
mD liu truyn theo c hai
hưng
mMSS:Kích thưc t$i ña m't
segment
rHưng n$i:
mB*t tay,chào h-i trưc khi
nói chuyn (trao ñ1i thông
tinñiu khi2n).Thi5t l6p b'
ñm hai ñ7u.
rKi2m soát lưu lư9ng:
mNói quá nhanh,nghe quá
ch6m
rði2m n$i ñi2m:
mM't g=i,M't nh6n
rTinc6y,theo ñúng th? t@:
mKhông quan tâm ñ5n khuôn
dCng thông ñip.
rðưDng $ng:
mC=a s1 ki2m soát t*c nghFn
ñiu khi2n lưu lư9ng.
rB ñm phía Nhn Gi
socket
door
TCP
sendbuffer
TCP
receivebuffer
socket
door
segment
application
writesdata
application
readsdata
3:TransportLayer 3b2
Cu trúc TCPsegment
sourceport# dest port#
32bits
D& li(u )ng d*ng
(kích thư0c tùy ý)
sequencenumber
acknowledgementnumber
rcvr windowsize
ptr urgentdata
checksum
F
SR
PAU
head
len
not
used
Options(variablelength)
URG:d& li(u kh=n cp
(ít s> d*ng)
ACK:ACK#
HAp l(
PSH:chuyBn d& li(u
ngay (ít s> d*ng)
RST,SYN,FIN:
KiBm soát kGt nHi
(L(nh ThiGt lJp
ðóng )
SH lưAng byte
bên nhJn
khO năng
nhJn
ðưAc xác ñSnh
theo STTcTa
bytetrong luUng
d& li(u
Internet
checksum
(giHng UDP)
2
3:TransportLayer 3b3
TCP:SH th) tV SH biên nhJn
SH th) tV (STT):
m S$ th? t@ cIa byte
ñ7u tiên trong luKng
d liu
SH biên nhJn:
m S$ th? t@ cIa byte
k5 ti5p bên nh6n
mu$n nh6n.
mBiên nh6n tích lũy
Q? Bên nh6n x= gói tin
không ñúng th? t@ ntn ?
mA:TCPkhông quy
ñQnh.Tùy thu'c vào
ngưDi cài ñSt.
Máy A Máy B
Seq=42,ACK=79,data=C
Seq=79,ACK=43,data=C
Seq=43,ACK=80
NgưDi dùng
ñánh ch
‘C’
Biên nh6n
lCi cho ch
‘C’ phn hKi
Biên nh6n
ch ‘C’,phn
hKi
lCi ch ‘C’
ThDi gian
[ng d*ng telnetñơn giOn
3:TransportLayer 3b4
TCP:Truy]n TincJy
FSMbên G=i ñơn giOn,gi
ñQnh r_ng:
wait
for
S@ kin
wait
for
S@ kin
S@ kin: nh6n d liu
tb phía bên trên
S@ kin: timertimeoutcho
segmentcó STTlà y
S@ kin: Nh6n biên nh6n cho
gói STTlà y
TCo G=i segment
G=i lCi segment
X= ACK
•D liu truyn theo m't hưng
•Không ki2m soát t*c nghFn
•Không ñiu khi2n lưu lư9ng
3
3:TransportLayer 3b5
Nhanh chóng truy]n l^i
rKhong thDi gian Timeout
thưDng tương ñ$i dài:
mCh6m trg trong vic g=i lCi
gói tinbQ mht
rPhát hin mht gói tinqua
các ACKtrùng lSp
mPhía g=i thưDng g=i nhiu
gói tin
mN5u gói tinbQ mht,sF
ACKtrùng lSp
rN5u phía g=i nh6n ñư9c 3
ACKtrùng lSp,có th2 gi
thi5t gói tinngay sau gói
tinñư9c biên nh6n 3l7n
liên ti5p bQ mht:
mG=i lCi k2 c khi gói này
chưa timeout
3:TransportLayer 3b6
event: ACKreceived,withACKfieldvalueofy
if(y>SendBase){
SendBase =y
if(therearecurrentlynot'yet'acknowledgedsegments)
starttimer
}
else{
incrementcountofdupACKs receivedfory
if(countofdupACKs receivedfory=3){
resendsegmentwithsequencenumbery
FastRetransmit:
ACKtrùng lp cho gói tin
ðã ñưc biên nhn Truyn li nhanh chóng
4
3:TransportLayer 3b7
TCP:
Truy]n
tincJy
00 sendbase =initial_sequencenumberagreedbyTWH
01nextseqnum =initial_sequencenumberbyTWH
02loop(forever){
03switch(event)
04event: datareceivedfromapplicationabove
05if (windowallowsend)
06createTCPsegmentwithsequencenumbernextseqnum
06if (notimer)starttimer
07passsegmenttoIP
08nextseqnum =nextseqnum +length(data)
else putpacketinbuffer
09event: timertimeoutforsendbase
10retransmitsegment
11computenewtimeoutinterval
12restarttimer
13event: ACKreceived,withACKfieldvalueofy
14if (y>sendbase){/*cumulativeACKofalldatauptoy*/
15cancelthetimerforsendbase
16 sendbase =y
17 if(notimerandpacketpending)starttimerfornewsendbase
17 while(therearesegmentsandwindowallow)
18 sentasegment;
18}
19else {/*y==sendbase,duplicateACKforalreadyACKed segment*/
20incrementnumberofduplicateACKs receivedfory
21if(numberofduplicateACKSreceivedfory==3){
22/*TCPfastretransmit */
23resendsegmentwithsequencenumbery
24restarttimerforsegmenty
25}
26}/*endofloopforever*/
TCPphía G>i
ñơn giOn
3:TransportLayer 3b8
TCP:Chính sách ACK [RFC1122,RFC2581]
S% ki'n
Segmenttheo ñúng STTñ?n,
Không thi?u dA liBu,
Không ACKtreo
Segmenttheo ñúng STTñ?n,
Không thi?u dA liBu,
mDt ACKbE treo
Segmenttheo ñúng STTñ?n
(STTñ?n lFn hơn sH mong
ñIi).Thi?u dA liBu
MDt segmentñ?n ñiLn vào
ñoNn dA liBu bE khuy?t
Bên nhn (TCP)
Trì hoãn ACK.ðIi segmentk? ti?p
trong 500ms.N?u không segment,
gSi ACK
Ngay lTp tUc gSi mDt ACKmang giá
trE tích lũy
GSi ACKtrùng l[p,ch\ STTc]a
bytedA liBu mình muHn nhTn
Biên nhTn STTbên nhTn mong muHn
nhTn
5
3:TransportLayer 3b9
TCP:Ví d* v] Truy]n l^i
HostA
Seq=92,8bytesdata
ACK=100
loss
timeout
time dk mht ACK
HostB
X
Seq=92,8bytesdata
ACK=100
HostA
Seq=100,20bytesdata
ACK=100
Seq=92timeout
time Timeouttrưc khi nh6n
ACK,bên g=i biên nh6n tích lũy
HostB
Seq=92,8bytesdata
ACK=120
Seq=92,8bytesdata
Seq=100timeout
ACK=120
3:TransportLayer 3b10
ði]u khiBn lưu lưAng trong TCP
Phía NhJn:Thông báo
ràng cho phía G=i kh
năng nh6n d liu cIa
mình (thay ñ1i thưDng
xuyên)
Phía G>i:Gi kh$i lư9ng d
liu g=i ñi nhưng chưa
ñư9c biên nh6n nh- hơn
lư9ng bên kia chhp nh6n
ñư9c
Không cho bên GSi gSi
quá nhiLu,quá nhanh
ði]u khiBn
lưu lưAng
Bb ñ(m phía NhJn
 =Kích thưc B'ñm nh6n
 =Kích thưc vùng còn tr$ng trong B'ñm