1
- The Transport Layer: TCP and UDP
- ÉCOLE POLYTECHNIQUE
FÉDÉRALE DE LAUSANNE
- Contents
The Transport Layer: TCP and UDP - - PDF document
COLE POLYTECHNIQUE FDRALE DE LAUSANNE The Transport Layer: TCP and UDP Contents
FÉDÉRALE DE LAUSANNE
4#25&,#!12 42≥ &,#12601237/ &82,%603 9#9/ .03/ 0/ 3.0/ 3
1##≥ """ #: ;<= %
? ? ? ? 6%1%%1 "!!%"! %&2&! " ? ? ? ?#1! solution
*
# 4& "" "%.
? ? ? .!>!
solution A R1 R2 B * * * * * * *$ *' *' *' *$!. *$ *$ A R1 R2 B * * * * * * *$ *$ *$ *$ *$!. *' *' *$ *'
(",!
"%..:
:4 "" "4. !. #:#% A % >
((&*8-*!#!! 6##!A" !
B!!!"!#"%7! . B#!7! !!#C
#
2#$"2"!
R2 B A R3 R4 R1 1 4 2 3 5 6 7
&#":%2 !4! #,∈D,E(# 2×038
(!,">!, 8" F%!G 8"" (0*23"!0123"%," ,"".: *29/ 0/ 123
4!:!H!!2
? ? ? !#%%# # A R1 R1 R1 R1 R1 R1 B Loss probability links solution
GGGG× 2 GGG× 2
+× 2 )
#3 & 0 3 *
( 4&#I" %# ( 4&# 0%%, %3!!#!-A" 4&# $ 1#!!!
4 4&## 0%3
solution
2
2 <,! !#
;!;J :
6% ("!!"%.! %
*#".%%,%% %%
#
@!!"; J ? ? ? ?%!"; J
!: C""!# #. (!# .%%(. %%! !"!#
* * * * 4 4 4 4 * * * * * * * * 4 4 4 4 * * * *
* * *. . . . * * * *
K K K * * * * ** ** ** ** ** ** ** *** * * *
** ** *** * * *
K K K 2 2 2 2 "" "" "" ""
Usable Window
P = 1 A = 0 P = 0 A =2 P = 2 P = 3 P = 4 A =1 P = 5 P = 6 P = 7 P = 8 P = 9 A =3 P = 10 A =4 A =5 A =6 A =7 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12
Legend Maximum Send Window = Offered Window ( = 4 here)
(.%%%"%: %%L "->!">-.,!# # !.#(.%% C,#!:!"%. 59 !>!!%%,""%% " !"0#3 %.!# %% "!"!# ""!(%%%# !>!! %% %"!>!!%%!! %. !>!!%% 0!.3"%.!" %%!%% 4.%%.%% .%%, !>!!!" ""C.093""
F"0"3"%%L ": ≥ 8,%%#, L&#,!!!!%%L !!!%%L !!!%%L !!!%%L "FL% "FL% "FL% "FL%
# # #
! ! ! " " " "
! ! !
! ! ! ! ! ! ! ! ! ! ! !" !" !" !" # # # # $%& $%& $%& $%&
' ' ' (% (% (% (% %) %) %) %) *+ *+ *+ *+
,- ,- ,- ... ... ... ...
,- ,- ,-
! ! !
! ! ! ! ! ! ! ,- ,- ,- ,- ! ! ! ! " " " "
"%.: !#,."! %% L9'H $ 4%.! ># % . %. ' #! % %.!
! 0 ; 23 ? ? ? ? - % ! % % #
' ' ' ' %),& %),& %),& %),& %) %) %) %) + + + + /01 /01 /01 /01
* * * (% (% (% (% %) %) %) %) *+ *+ *+ *+ /011 /011 /011 /011
* * * $% $% $% $% *+ *+ *+ *+
& & & /01 /01 /01 /01
,- ,- ,-
,- ,- ,-
,- ,- ,-
,- ,- ,-
% % %
% % % % % % % % % % %
%% L9'H 4%.! !, . ! % % # $ #! ' , !. "! %. 0 J3 ? ? ? ? - % ! % % # ; J "" , % !# # ! % # !- . >! !#:
0 !!# 3- "A > -",C "" A 0 .3( #!
J "# !!!,">!
/01 /01 /01
/01 /01 /01
,- ,- ,-
*234 *234 *234
% % %
,- ,- ,-
,- ,- ,-
! ! !
*234 *234 *234 % % % %
% % %
/01 /01 /01
4&#
!:;2 :;J
(#:
(&*:"%!"".
4#
<B;:;J
" 4 # 0>2;! 3. K
4 ! C " !H" K
K, K$, M # 4 "" 4# ## % " = "-
<""!"!:4!#!" @!##!# !4 <!#"""/ %"N %"""%
, &
. . !# %
< ;(@*09*4=;13 J@!. ;. "> ! " . ;(@*!. ;!!! ? ? ? ? % %
O@B8O@ ! % .4B
"! 0%3
5 5 5
5 5 5 65 65 65 65 ! ! ! ! " " " " # # # #
0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 P = 1 A = -1, credit = 2 P = 0 P = 2 P = 3 P = 4 A = 0, credit = 2 P = 5 P = 6 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 A = 2, credit = 4 0 1 2 3 4 5 6 7 8 9 10 11 12 A = 0, credit = 4 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 A = 4, credit = 2 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 A = 6, credit = 0 0 1 2 3 4 5 6 7 8 9 10 11 12 A = 6, credit = 4 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 P = 7
& #(&*, ! "P%% !Q !, "! %! %. 0"""3& !# " ,% , "42?& ! % ""% , %.! " ! #. # 0 C !# # , .!!# ! !# !3
3%% 0 >3@, % (&*, 09 %% !3. % %.!( %.! !
%.! !" . "!>!! %%3
!! . "" "! KK-, 0% 3 ! K .,!#, .. "!>!! %% ! " 0 !# # #! 3
C ! "%. # , ! " %.
0%% ,.. #(!3R L %%, 0 3
4 4 4 4% % % %
7 7 74 4 4 4% % % %
4 4 4% % % %
! ! ! " " " " 4 4 4 4% % % %
4 4 4% % % %
"4 "4 "4% % % %
"4 "4 "4% % % %
# # # !" !" !" !" !" !" !" !" #89 #89 #89 #89
!" !" !" !" !" !" !" !" !" !" !" #89 #89 #89 #89
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
7 7 7
! ! ! 7 7 7 7
7 7 7
7 7 7
! ! ! " " " " 7 7 7 7
7 7 7
7 7 7
! ! ! " " " " +4 +4 +4 +4%) %) %) %)
%) %) %) + + + +: : : :
%K K# # # # # # ! % .! #! #,
=<*0=<.!*3:""#.!!.", " (&*0(!&*3:!!#K "%
>!:S ? ? ? ? %#
0<B;3(&*"" ."!.; # ;J# >!:!0(&*!-*3
6
6
6
6
9+ 9)$ MM
+
)$
=<*;* =<*< * =<* .. =<*&!
=<*.!
!!.1"!#%,% ".
(>!%#!4, !(=<* (! !H#H% "!4 (=<*!=<*
"!##!*+..(# "##!#(##,! "# ;%%H">!,<B; )$0883*#!# !(##'-"#%# % !.!!.!,#" #%!#
!.,TU ,,,
>#!.. !.!# .!#,!!!#
.!!."(&* =<* (".%# =<*.!( ." ,%!# 0#3
03 !09"3 "" 03 !% 03.-* ,! !. !03 !." !--* ! !.
03H 03H 03H
03H "!03H F8& 547A! F F8; V F
9$ 9' "" "" 9$')+ 9$+)' .! =<*
9TT)T'
2 ;"!.
(&*.C%, H (&*%"",! .C (&*%%!-*,=<* (&*"% (&*.0!3
",09#L"C!3 %% (&*!!42?0"#30""% 3 ,
4!"#"!
" 4(&*"#:
, , ,
, , ,
, , ,
#!"".(&* .! ;;9!>!!P.!P L0!>!!L3
P ;;9$+Q !.!,%, >$+#
)$+##"0)+#-*3
#!%-*' %".!!
(&* (&*
9(&*
.%% #! !#". &!
"! %.!
%
T:T)0)3 %+ :03 T)%' T):G0)3 %'' G:G)0)3 %'' G):0)3 %'' 03 T)%$ T):G0)3 )%'' :)0)3 T)% ):'0)3 % :)0)3 '%'' (!N
' ) +
G
:T)
T):
:)
" ',),+
C!"#H, %.!"## C(,%%.! C!"4%.! 0P..#.Q3,(&*1# .!C!0""3, ! 0"3("%.:
"#Q:Q#KP0P.!<.Q3Q B!KP%Q ""%;BK% # !
4T,!!>,.!" .%#!T)0J3B % ".!G,!%#! (.! " (%%"0%3.L"%%@## !%%!#(! "% B!"."!#2 >! !%$ (C! ,!.'W (".%!!"(&*%P(&*;4&UQ,% "!!4!!0P(&* (Q3.!"!H,% !!.JH%% %!#,# !
# :! !"# >!!" .J "";2*
< 2!#!.
"$ "! #" !!, ! ? ? ? ?% ".
* *$ *' 4 4 4 *) *+ 4 4 ! *$ 4 *
!%%"," "% 4%.>#%#% !
$;4&U(&*,H;4&U ""#H"! # #.%.!
=.C!
"",(&*. ;B(""#L (C!!! (!"%#(% ."%"
%
SYN, seq=x syn_sent SYN seq=y, ack=x+1 ack=y+1 established established snc_rcvd listen FIN, seq=u ack=v+1 ack=u+1 FIN seq=v fin_wait_2 time_wait close_wait last_ack closed application active open passive open application close: active close fin_wait_1 Connection Setup Data Transfer Connection Release
srce port dest port sequence number ack number hlen window
code bits
rsvd urgent pointer checksum segment data (if any) TCP header (20 Bytes +
IP header (20 B + options) <= MSS bytes
code bit meaning urg urgent ptr is valid ack ack field is valid psh this seg requests a push rst reset the connection syn connection setup fin sender has reached end of byte stream
(>%(&*.!"!
..!!!#-",(&*!# .;<= 09(&*##3*<=09 .!3@.,"(&* !!#-",(&*!#.*<= ;<= ("!"(&*(&* ."#,%#(&*( #("#"
0..!3(.(&*! "!.@%, .! #!(#(# !!
!C!
>>C!
.!0."!>!!L" !3
(".%# (." % #
03 !09"3"" 03! % 03!-* !% ;B 03" ! 03!".H ;B "!- %03 " %% 03" #! !!.! "%!##!# %-!" #""# "
% ./tcpClient <destAddr> bonjour les amis % % ./tcpServ & % client socket(); server socket(); bind(); connect(); send(); close(); bind(); listen(); accept(); receive(); close();
program TCP IP id=3 id=4 incoming connection queue buffer port=32456 address=128.178.151.84 id=5 buffer socket socket socket
? ? ? ?%! ? ? ? ? =<*""#. #%!4#L:,,!. ?$ ?$ ?$ ?$ (&*"!.#. #%!4#L:,,!.
?' ?' ?' ?' -;J.%%
(R <.42?"%.%#!"! !.!>!>
B!#(&*,%
&.%#"0. %3-1(!!(&*/ %%# !." .!
..!,(&*!# %.!!!#,!#% 0P..#.Q3,.!0! 3<#.4&U ., !#!"-*%6%, " 4&U #.,.#" "!"42?!4,#. 4&U #%"!%%L
<%4&U%
;.4&U##!)-,!" "L.!,4&U"# .! B.(&*4&U 0##4&U3 ".!"-,4&U !#CK
#
4(&*." #01/ ..!(%#! !0>:(:!3J.. #%!#!!,#
.!.
<%.!-*#"!
6% A
#%.#.! 09.!! ;;3: B.R .! #
>!:O%% #!0(&*XB@<143 "B. ,
(data written by upper layer) or (new ack received) -> if full segment ready then send segment else if there is no unacknowledged data then send segment else start override timer; leave
(data written by upper layer) or (new ack received) -> if full segment ready then send segment else if there is no unacknowledged data then send segment else start override timer; leave
8000:8001(1) ack 101 win 6000 1
a -> b -> c -> d -> e -> f -> 101:102(1) ack 8001 win 14000 2 8001:8003(2) ack 102 win 6000 3 102:102(0) ack 8003 win 13998 4 8003:8005(2) ack 102 win 6000 102:102(0) ack 8003 win 14000 5 6 102:102(0) ack 8005 win 13998 7 8005:8006(1) ack 102 win 6000 8
2 %# .!" !%%"!#!7%"
%) %) %) ; ; ; ;77777 77777 77777 77777 < < < <77777 77777 77777 77777= = = =+> +> +> +>4 4 4 4+ + + +
< < <77777 77777 77777 77777= = = =+ + + +
%) %) %) 4; 4; 4; 4;77777 77777 77777 77777 ,%:< ,%:< ,%:< ,%:<
%) %) %) 4; 4; 4; 4;77777 77777 77777 77777 < < < <77777 77777 77777 77777= = = =
,%:< ,%:< ,%:<
%) %) %) 4; 4; 4; 4;77777 77777 77777 77777 < < < <77777 77777 77777 77777= = = =
,%:< ,%:< ,%:<
%) %) %) 4; 4; 4; 4;77777 77777 77777 77777 < < < <77777 77777 77777 77777= = = =
* "! . ! ! %%
!%% #! . ;; 8%-
%- %- %-< < < <
keep nextByteExpected + offeredWindow fixed until: reserve · min (MSS, 1/2 receiveBuffer) keep nextByteExpected + offeredWindow fixed until: reserve · min (MSS, 1/2 receiveBuffer)
?&?: ?&?: ?&?: ?&?: :(% :(% :(% :(% 777 777 777 777@ @ @ @77777777777 77777777777 77777777777 77777777777@ @ @ @777777777777777777777 777777777777777777777 777777777777777777777 777777777777777777777@ @ @ @777777777777 777777777777 777777777777 777777777777@ @ @ @7777 7777 7777 7777 ; ; ; ;77 77 77 77
77 77 77=; =; =; =;7 7 7 7 -
7 7 7= = = = ; ; ; ;77777777777777 77777777777777 77777777777777 77777777777777 %- %- %- %- 7777777777777777 7777777777777777 7777777777777777 7777777777777777= = = =
ack 0 win 2000 <----- 0:1000 -----> bufferSize= 2000B, freebuf = 1000B, reserve = 0B 1000:2000 -----> freebuf= 0B, reserve = 0B ack 2000, win 0 <----- application reads 1 Byte: freeBuf=reserve=1B, .... application has read 500 B: reserve = 500 persistTimer expires window probe packet sent 2000:2001 -----> data is not accepted (out of window) ack 2000, win 0 <----- .... application has read 1000 B: reserve = 1000 ack 2000, win 1000 <----- 2000:3000 ----->
# & % !! ;; / 2& "% %
sampleRTT = last measured round trip time estimatedRTT = last estimated average round trip time deviation = last estimated round trip deviation initialization (first sample): estimatedRTT = sampleRTT + 0.5s; deviation = estimatedRTT/2 new value of sampleRTT available -> Err = sampleRTT - estimatedRTT estimatedRTT = estimatedRTT + 0.125 * Err deviation = deviation + 0.250 * (|Err|- deviation) RTO = estimatedRTT + 4*deviation sampleRTT = last measured round trip time estimatedRTT = last estimated average round trip time deviation = last estimated round trip deviation initialization (first sample): estimatedRTT = sampleRTT + 0.5s; deviation = estimatedRTT/2 new value of sampleRTT available -> Err = sampleRTT - estimatedRTT estimatedRTT = estimatedRTT + 0.125 * Err deviation = deviation + 0.250 * (|Err|- deviation) RTO = estimatedRTT + 4*deviation
4#25&,#!12 42≥ &,#12601237/ &82
1##≥ """ #: ;<= %
? ? ? ? 6%1%%1 "!!%"! 4 4 4 4 -&2&-","! %&2&! " ? ? ? ?#1! 4 4 4 4 12#!#!,% back
*
# 4& "" "%.
? ? ? .!>! 4 4 4 4.!# !#(( >.
back
? ? ? ? !#%%# # 4 4 4 4
&:# 1*129/ 0/ 3 &#& 92× 03 &:## \× 03 1#& 92× 03
A R1 R1 R1 R1 R1 R1 B Loss probability links back
<###. :>,1 <#/# 4,
GGGG× 2 GGG× 2
+× 2 )
#3 & 0 3 *
*! <%.!"# ;%"H""( , !
;
4 *
* ( R
back
#
@!!"; J ? ? ? ?%!"; J 4 4 4 4%%# #!, .!( %!%%."
!: C""!# #. (!# .%%(. %%! !"!#
* * * * 4 4 4 4 * * * * * * * * 4 4 4 4 * * * *
* * *. . . . * * * *
K K K * * * * ** ** ** ** ** ** ** *** * * *
** ** *** * * *
K K K 2 2 2 2 "" "" "" ""
back
"%.:
%% L9'H $ 4%.! ># % . %. ' #! % %.!
! 0 ; 23 ? ? ? ? - % ! % % # # 4 4 4 4 ,"
"%.: %% L9'H 4%.! !, . ! % % # $ #! ' , !. "! %. 0 J3 ? ? ? ? - % ! % % # 4 4 4 4,"
" 4 # 0>2;! 3. K
< ;(@*09*4=;13 J@!. <. "> !" . ;(@* !. ;!!! ? ? ? ? % % 4 4 4 4 -"% # !
5 5 5
5 5 5 65 65 65 65 ! ! ! ! " " " " # # # #
>!:S ? ? ? ? %# 4 4 4 4#!"*! !#!
0<B;3(&*"" ."!.; # ;J#
# :! !"# >!!" .J "";2*
< 2!#!.
"$ "! #" !!, ! ? ? ? ?% ". 4 4 4 4 4+
* *$ *' 4 4 4 *) *+ 4 4 ! *$ 4 *
? ? ? ?%! 4 4 4 4 "%(&* =<*# ? ? ? ? =<*""#. #%!4#L:,,!. 4 4 4 4 ",!!@ .#%#;!!#!. ?$ ?$ ?$ ?$ (&*"!.#. #%!4#L:,,!. 4$ 4$ 4$ 4$%(&* H!#!. ("#B#!.%#
?' ?' ?' ?' -;J.%% 4' 4' 4' 4' ,%%%9
# & % !! ;; / 2& "% %