
1
3:TransportLayer 3b1
TCP:Tng quan RFCs:793,1122,1323,2018,2581
rTruyn songcông:
mD liu truyn 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 chuyn (trao ñ1i thông
tinñiu 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
rTinc6y,theo ñúng th? t@:
mKhông quan tâm ñ5n khuôn
dCng thông ñip.
rðưDng $ng:
mC=a s1 ki2m soát t*c nghFn
và ñiu khi2n lưu lư9ng.
rB ñm phía Nhn và Gi
socket
door
TCP
sendbuffer
TCP
receivebuffer
socket
door
segment
application
writesdata
application
readsdata
3:TransportLayer 3b2
Cu trúc TCPsegment
sourceport# dest port#
32bits
D& li(u )ng d*ng
(kích thư0c tùy ý)
sequencenumber
acknowledgementnumber
rcvr windowsize
ptr urgentdata
checksum
F
SR
PAU
head
len
not
used
Options(variablelength)
URG:d& li(u kh=n cp
(í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 và
ðóng )
SH lưAng byte
mà bên nhJn
có khO năng
nhJn
ðưAc xác ñSnh
theo STTcTa
bytetrong luUng
d& li(u
Internet
checksum
(giHng UDP)

2
3:TransportLayer 3b3
TCP:SH th) tV và SH biên nhJn
SH th) tV (STT):
mLà S$ th? t@ cIa byte
ñ7u tiên trong luKng
d liu
SH biên nhJn:
mLà S$ th? t@ cIa byte
k5 ti5p mà bên nh6n
mu$n nh6n.
mBiên nh6n tích lũy
Q? Bên nh6n x= lý gói tin
không ñúng th? t@ ntn ?
mA:TCPkhô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’ phn hKi
Biên nh6n
ch ‘C’,phn
hKi
lCi ch ‘C’
ThDi gian
[ng d*ng telnetñơn giOn
3:TransportLayer 3b4
TCP:Truy]n TincJy
FSMbên G=i ñơn giOn,gi
ñQnh r_ng:
wait
for
S@ kin
wait
for
S@ kin
S@ kin: nh6n d liu
tb phía bên trên
S@ kin: timertimeoutcho
segmentcó STTlà y
S@ kin: Nh6n biên nh6n cho
gói có STTlà y
TCo và G=i segment
G=i lCi segment
X= lý ACK
•D liu truyn theo m't hưng
•Không ki2m soát t*c nghFn
•Không ñiu khi2n lưu lư9ng

3
3:TransportLayer 3b5
Nhanh chóng truy]n l^i
rKhong thDi gian Timeout
thưDng tương ñ$i dài:
mCh6m trg trong vic g=i lCi
gói tinbQ mht
rPhát hin mht gói tinqua
các ACKtrùng lSp
mPhía g=i thưDng g=i nhiu
gói tin
mN5u gói tinbQ mht,sF có
ACKtrùng lSp
rN5u phía g=i nh6n ñư9c 3
ACKtrùng lSp,có th2 gi
thi5t gói tinngay sau gói
tinñư9c biên nh6n 3l7n
liên ti5p bQ mht:
mG=i lCi k2 c khi gói này
chưa timeout
3:TransportLayer 3b6
event: ACKreceived,withACKfieldvalueofy
if(y>SendBase){
…
SendBase =y
if(therearecurrentlynot'yet'acknowledgedsegments)
starttimer
…
}
else{
incrementcountofdupACKs receivedfory
if(countofdupACKs receivedfory=3){
resendsegmentwithsequencenumbery
…
FastRetransmit:
ACKtrùng lp cho gói tin
ðã ñưc biên nhn Truyn li nhanh chóng

4
3:TransportLayer 3b7
TCP:
Truy]n
tincJy
00 sendbase =initial_sequencenumberagreedbyTWH
01nextseqnum =initial_sequencenumberbyTWH
02loop(forever){
03switch(event)
04event: datareceivedfromapplicationabove
05if (windowallowsend)
06createTCPsegmentwithsequencenumbernextseqnum
06if (notimer)starttimer
07passsegmenttoIP
08nextseqnum =nextseqnum +length(data)
else putpacketinbuffer
09event: timertimeoutforsendbase
10retransmitsegment
11computenewtimeoutinterval
12restarttimer
13event: ACKreceived,withACKfieldvalueofy
14if (y>sendbase){/*cumulativeACKofalldatauptoy*/
15cancelthetimerforsendbase
16 sendbase =y
17 if(notimerandpacketpending)starttimerfornewsendbase
17 while(therearesegmentsandwindowallow)
18 sentasegment;
18}
19else {/*y==sendbase,duplicateACKforalreadyACKed segment*/
20incrementnumberofduplicateACKs receivedfory
21if(numberofduplicateACKSreceivedfory==3){
22/*TCPfastretransmit */
23resendsegmentwithsequencenumbery
24restarttimerforsegmenty
25}
26}/*endofloopforever*/
TCPphía G>i
ñơn giOn
3:TransportLayer 3b8
TCP:Chính sách ACK [RFC1122,RFC2581]
S% ki'n
Segmenttheo ñúng STTñ?n,
Không thi?u dA liBu,
Không có ACKtreo
Segmenttheo ñúng STTñ?n,
Không thi?u dA liBu,
Có mDt ACKbE treo
Segmenttheo ñú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 nhn (TCP)
Trì hoãn ACK.ðIi segmentk? ti?p
trong 500ms.N?u không có segment,
gSi ACK
Ngay lTp tUc gSi mDt ACKmang giá
trE tích lũy
GSi ACKtrùng l[p,ch\ STTc]a
bytedA liBu mình muHn nhTn
Biên nhTn STTbên nhTn mong muHn
nhTn

5
3:TransportLayer 3b9
TCP:Ví d* v] Truy]n l^i
HostA
Seq=92,8bytesdata
ACK=100
loss
timeout
time Ví dk mht ACK
HostB
X
Seq=92,8bytesdata
ACK=100
HostA
Seq=100,20bytesdata
ACK=100
Seq=92timeout
time Timeouttrưc khi nh6n
ACK,bên g=i biên nh6n tích lũy
HostB
Seq=92,8bytesdata
ACK=120
Seq=92,8bytesdata
Seq=100timeout
ACK=120
3:TransportLayer 3b10
ði]u khiBn lưu lưAng trong TCP
Phía NhJn:Thông báo rõ
ràng cho phía G=i kh
năng nh6n d liu cIa
mình (thay ñ1i thưDng
xuyên)
Phía G>i:Gi kh$i lư9ng d
liu 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

