トランスポートレイヤ 技 術 - TCP; Transmission Control Protocol - 1
トランスポートレイヤの 仕 事 計 算 機 のインターフェース(Socket) 間 での 良 好 な データのやり 取 りを 実 現 する 誤 りがないように 再 送 パリティー 情 報 による 自 動 再 生 (FEC; Forward Error Correction) データを 取 りこぼさないように (*) ファイルアクセスと 同 じ インターフェース を 提 供 それ 以 外 に 欲 しくなる 機 能 並 列 データ 転 送 ネットワークに やさしく 道 が 混 まないように ネットワークは 単 純 化 エンドホストが 賢 く 2
3
4
インターネットアーキテクチャ - TCP : Transmission Control Protocol - TCP (Transmission Control Protocol) ; end-to-end フロー 制 御 エラー 制 御 / 再 送 制 御 コネクション 管 理 セッションの 多 重 化 Application TCP IP Network Interface Physical IP Network Interface Physical Application TCP IP Network Interface Physical 5
TCP Features Stream Oriented Data Transmission Connection 確 立 (Three-way-handshake) Connection ( Stream ) Identifier = Socket {dst_ip_addr, dst_port, src_ip_addr, src_port} Sequence Number ; 32 bits バイト 番 号 : 0 - (2^32-1) 2^32 でSequence NumberがWrapされる Full-Duplex での 通 信 Acknowledgement (ACK) ; 次 に 受 信 すべきバイト 番 号 (SN)の 通 知 エラー 回 復 : セグメント 再 送 (Segment retransmission) by Time-out, Dupilicated-ACK Sliding Window Control を 用 いたデータ 転 送 制 御 (*) Window_size 65,535 Bytes 6
7
8
TCP Header Format UR AK PH RT SY FN : Urgent Pointer Field Significant (URG) : Acknowledgement Field Significant (ACK) : Push Function : Reset the Connection : Synchronize Sequence Numbers (SYN) : No More Data From Sender (FIN) 9
TCP Port Allocation (RFC1700) 1. Well-Known Ports ; 0-1,023 2. Registered Ports ; 1,024-49,151 3. Dynamic and/or Private Ports ; 49,152-65,535 最 新 情 報 : ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers 10
TCP Well-Known Ports Port Number Keyword Application 5 rje Remote Job Entry 20 ftp-data File Transfer [Default data] 21 ftp File Transfer [Control] 23 telnet Telnet 25 smtp Simple Management Protocol 39 rlp Resource Location Protocol 53 domain Domain Name Server 63 whois++ Whois++ 67 bootp Bootstrap Protocol Server 69 tftp Trivial File Transfer 70 gopher Gopher 79 finger Finger 80 http World Wide Web HTTP 110 pop3 Post Office Protocol - Version 3 111 sunrpc SUN Remote Procedure Call 119 nntp Network News Transfer Protocol 11
TCP Well-Known Ports Port Number Keyword Application 123 ntp Network Time Protocol 137 netbios-ns NetBIOS Name Service 138 netbios-dgm NetBIOS Datagram Service 139 netbios-ssn NetBIOS Session Service 179 bgp Border Gateway Protocol (BGP) 202 at-nbp AppleTalk Name Binding Protocol 213 ipx IPX 220 imap3 IMAP3 (Interactive Mail Access Protocol) 396 netware-ip Novell Netware over IP 540 uucp uucp daemon 546 dhcpv6-client DHCPv6 Client 547 dhcpv6-server DHCPv6 Server 560 rmonitor remote monitor daemon 12
TCP Connection 確 立 / 開 放 svr4.1037 (client) bsdi.discard(server) Active open (appli. open : telnet) SYN_ACK(a+1,b) Passive open open open Active Close (application close: quit) half close FIN (m,s+1) ACK (m+1) FIN_ACK (m+1,s) EOF to Application Passive Close (application close) ACK (s+1) half close full close 13
TCP Connection 確 立 / 開 放 SYN_SENT (Active open) ESTABLISHED Client SYN_ACK(a+1,b) Server LISTEN (Passive open) SYN_RCVD ESTABLISHED FIN_WAIT_1 (Active close) FIN_WAIT_2 TIME_WAIT FIN (m,s) ACK (m+1) FIN_ACK (m+1,s) CLOSE_WAIT (Passive close) LAST_ACK 2-MSL CLOSED ACK (s+1) CLOSED 14
TCP Connection 確 立 / 開 放 Log on the console; svr4% telnet bsdi discard Trying 140.252.13.35 Connected to bsdi. Escape character is ^]. ^] telnet> quit Connection closed. #port= 9 (server discard packet) tcpdump output 1 0.0 svr4.1037 > bsdi.discard: S 14155.14155(0) win 4096 <mss 1024> 2 0.024 (0.0024) bsdi.discard > svr4.1037: S 18239.18239(0) ack 14156 win 4096 <mss 1024> 3 0.007 (0.0048) svr4.1037 > bsdi.discard:. ack 18240 win 4096 4 4.155 (4.1482) svr4.1037 > bsdi.discard: F 14156:14156(0) ack 18240 win 4096 5 4.158 (0.0013) bsdi.discard > svr4.1037:. ack 14157 win 4096 6 4.159 (0.0014) bsdi.discard > svr4.1037: F 18240.18240(0) ack 14157 win 4096 7 4.189 (0.0225) svr4.1037 > bsdi.discard:. ack 18241 win 4096
TCP Connection 確 立 / 開 放 tcpdump output 1 0.0 svr4.1037 > bsdi.discard: S 14155.14155(0) win 4096 <mss 1024> 2 0.024 (0.0024) bsdi.discard > svr4.1037: S 18239.18239(0) ack 14156 win 4096 <mss 1024> 3 0.007 (0.0048) svr4.1037 > bsdi.discard:. ack 18240 win 4096 4 4.155 (4.1482) svr4.1037 > bsdi.discard: F 14156:14156(0) ack 18240 win 4096 5 4.158 (0.0013) bsdi.discard > svr4.1037:. ack 14157 win 4096 6 4.159 (0.0014) bsdi.discard > svr4.1037: F 18240.18240(0) ack 14157 win 4096 7 4.189 (0.0225) svr4.1037 > bsdi.discard:. ack 18241 win 4096 [ 意 味 ] source.port > destination.port : flags SN_begin.SN_end(data_size) flags : S = SYN ; Synchronize sequence_number(sn) F = FIN ; Finish data transmission R = RST ; Reset connection P = PSH ; push data to receiving process asap. = ; none of above four flags is on SN_end = SN_begin + data_size win 4096 ; window size is 4096 mss 1024 ; maximum segment size is 1024 bytes 16
appl: close send: FIN SYN_RCVD FIN_WAIT_1 recv: ACK send: <nothing> recvl: SYN send: SYN, ACK FIN_WAIT_2 recv: ACK send: <nothing> appl: close send: FIN appl: passive open send: <nothing> recv: FIN send: ACK recv: FIN,ACK send: ACK recv: FIN send: ACK Active close CLOSED LISTEN passive open Send : RST appl: send data send: SYN recv: SYN send: SYN,ACK (simultaneous open) ESTABLISHED simultaneous close CLOSING recv: ACK send: <nothing> TIME_WAIT 2 MSL timeout appl: active open send: SYN SYN_SENT recv: SYN,ACK send: ACK recv: FIN send: ACK Active open appl: close or timeout CLOSE_WAIT appl: close send: FIN LAST_ACK Passive close recv: ACK send: <nothing>
appl: close send: FIN << Client >> SYN_RCVD FIN_WAIT_1 recv: ACK send: <nothing> recvl: SYN send: SYN, ACK FIN_WAIT_2 recv: ACK send: <nothing> appl: close send: FIN appl: passive open send: <nothing> recv: FIN send: ACK recv: FIN,ACK send: ACK recv: FIN send: ACK Active close CLOSED LISTEN passive open send: RST appl: send data send: SYN recv: SYN send: SYN,ACK (simultaneous open) ESTABLISHED simultaneous close CLOSING recv: ACK send: <nothing> TIME_WAIT 2 MSL timeout appl: active open send: SYN SYN_SENT recv: SYN,ACK send: ACK recv: FIN send: ACK Active open appl: close or timeout CLOSE_WAIT appl: close send: FIN LAST_ACK Passive close recv: ACK send: <nothing>
appl: close send: FIN << Server >> SYN_RCVD FIN_WAIT_1 recv: ACK send: <nothing> recvl: SYN send: SYN, ACK FIN_WAIT_2 recv: ACK send: <nothing> appl: close send: FIN appl: passive open send: <nothing> recv: FIN send: ACK recv: FIN,ACK send: ACK recv: FIN send: ACK Active close CLOSED LISTEN passive open send: RST appl: send data send: SYN recv: SYN send: SYN,ACK (simultaneous open) ESTABLISHED simultaneous close CLOSING recv: ACK send: <nothing> TIME_WAIT 2 MSL timeout appl: active open send: SYN SYN_SENT recv: SYN,ACK send: ACK recv: FIN send: ACK Active open appl: close or timeout CLOSE_WAIT appl: close send: FIN LAST_ACK Passive close recv: ACK send: <nothing>
20
誤 りのないデータ 転 送 パケットが 紛 失 したり 誤 ったりしたら 再 送 (Resend)して もとにもどす 正 しく 受 信 できたかの 確 認 のメッセージ (ACK; Acknowledge)を 送 信 (From dst src) とても 原 始 的 な 手 順 では 速 度 が 出 ない 2つの 改 善 手 法 大 きなパケット 長 : 最 大 でも 帯 域 幅 の 1/3 まで パイプラインで パケットを 転 送 21
TCP Bulk Data Transmission - Sliding Window - Window 制 御 を 用 いたパケット 転 送 1Sliding Window (Receiver 設 定 ) 2Congestion Window(Sender 設 定 ) (1) ACKなしにwindow 数 のパケットを 転 送 (2) ACKのAggregation(ACKパケットの 減 少 ) (3) Receiver 側 によるwindow 幅 の 制 御 (4) ACK 受 信 でwindowをスライドさせる 22
TCP Sliding Window Offered window (advertised by receiver) Unsent window 1 2 3 4 5 6 7 8 9 10 11 sent and ACKed sent but not ACKed Can send ASAP Can not send until window slides 23
TCP Sliding Window Sent 3 and 4 Offered window (advertised by receiver) Unsent window 1 2 3 4 5 6 7 8 9 10 11 sent and ACKed sent but not ACKed Can send ASAP Can not send until window slides Receive ack 5 from receiver 3+window=9 5+window=11 Receive ack 5 from receiver
TCP Sliding Window Window advertise by receiver shrink enlarge window closed by ACK reception = ACKed SN Opend by ACK reception (=ack+window) Slide window by ACK from receiver 25
TCP Congestion Window Offered window (advertised by receiver) Unsent window 1 2 3 4 5 6 7 8 9 10 11 sent and ACKed Congestion window ( cwnd =1 ) Shall not send ASAP Can not send until window slides sent but not ACKed 26
TCP Congestion Window Sent 3 Offered window (advertised by receiver) Unsent window 1 2 3 4 5 6 7 8 9 10 11 sent and ACKed Shall send without ACK ASAP; cwnd=2 (cwnd cwnd*2) Shall not send ASAP Can not send until window slides 3+window=9 4+window=10 Receive ack 4 from receiver Receive ack 4 from receiver
TCP Congestion Window Slow Start Policy (cwnd ; exponential increase) cwnd = 1 ; for (セグメント 転 送 ) { for (not congestion) { if (セグメント 転 送 ACK 受 信 ) { cwnd = cnwd +1 } cwnd = 1 } (*) 注 意 : Congestion Avoidance では 若 干 異 なる SenderがLocal に 制 御 することなので 変 えることが 容 易 に 可 能 28
cwnd cwnd TCP Congestion Window advertised_window advertised_window congestion time time < Congestionなしの 場 合 > < Congestion 経 験 の 場 合 > (*) Duplicated ACKを 使 用 せず 29
1 TCP Congestion Window(1) [ 送 ] [ 受 ] [ 送 ] [ 受 ] 1 1 1 1 1 1 1 30
2 TCP Congestion Window(2) [ 送 ] [ 受 ] [ 送 ] [ 受 ] 2 3 2 3 3 2 2 3 3 2 2 3 2 3 31
4 TCP Congestion Window(3) 7 6 5 [ 送 ] [ 受 ] [ 送 ] [ 受 ] 4 5 4 7 6 6 5 4 4 5 7 7 6 5 4 4 5 6 4 5 6 7 32
8 TCP Congestion Window(4) 12 11 10 9 [ 送 ] [ 受 ] [ 送 ] [ 受 ] 5 6 7 8 9 8 13 12 11 10 6 7 10 9 8 8 9 14 13 12 11 7 11 10 9 8 8 9 10 15 14 13 12 8 9 10 11 必 要 なウィンドー 幅 BWxRTT 33
Congestion Window Control [ 目 的 ] cwndの 大 きな 振 動 を 防 ぎ 適 切 なcwndで 運 用 する [1] cwndの 制 御 (i) ssthresh 以 下 のcwndサイズ Exponential increase (slow start) (ii) ssthresh 以 上 のcwndサイズ Liner increase (congestion avoidance) [2] ssthreshの 制 御 (i) Timeout ; goto 1 (ii) Duplicated-ACK ; 1/2 cwnd=1; ssthresh=64kb; for () { if ( Timeout ) { cwnd=1; ssthresh = cwnd/2; } if ( duplicated ACK ) { ssthresh=cwnd / 2; cwnd=ssthresh; } if (cwnd ssthresh) { slow_start; /* exponential */ } else { congestion_avoidance; /* liner */ } } 34
Congestion Window Control ( 続 ) ICMP 制 御 メッセージ (1) ICMP Source Quench cwnd = 1 ; ssthresh = as is ; (2) Host unreachable No Action ; 35
(cwnd_1) / 2 (cwnd_3) / 2 cwnd slow-start slow-start Congestion avoidance Congestion avoidance Congestion avoidance cwdn_1 cwdn_3 Target cnwd ssthresh Timeout Fast Recovery Fast Recovery 36
Window Scaling for Long Fat Pipe - RFC1323 - Network Bandwidth(bps) RTT(ms) BWxRTT(B) Ethernet 10.000 M 3 3,750 T1( 大 陸 間 ) 1.544 M 60 11,580 T1( 衛 星 ) 1,544 M 500 96,500 T3( 大 陸 間 ) 45,000 M 60 337,500 OC12( 大 陸 間 ) 2,400,000 M 60 7,500,000 Max. Window Size ; 2^(16) Bytes = 64KB Window Scaling ; wscale wscale=n 64 x 2^(n) windowサイズ 37
RFC 1379 ; T/TCP - Transaction TCP - [ 目 的 ] TCPコネクションの 確 立 開 放 手 続 きの 速 度 アップ [ 方 法 ] CC (Connection Count) Option SYNへのPiggy-back ; half-synchronization (1) SYN, Data, FIN, CC (2) SYN, SYN-ACK, Data, FIN, FIN-ACK, CC, CC-Echo (3) FIN-ACK 38
Client RFC 1379 ; T/TCP Server Client Server SYN_ACK(a+1,b) SYN,S-ack,Data, F,F-ack Data_ACK(a+2,b+1) FIN (m,s) ACK (m+1) FIN_ACK (m+1,s) ACK (s+1) 9 セグメント 3 セグメント 39
40
再 送 間 隔 1.5 sec 3 sec 6 sec 64 sec RTO Expired Retransmission bsdi.1023 1 3 4 6 7 8 9 17 SYN 0:0(0) win4096 <mss1024> svr4.discard SYN 3:3(0) ack 1 win4096 <mss1024> ack 4 win4096 PSH 1:15(14) ack 4 win4096 ack 15 win 4096 5 2 再 送 トライ (RTO; 再 送 タイマ) RTO = 1.5 sec /* 変 更 可 能 */ for ( 9 minutes) { if ( RTO expired) { retransmission; RTO=RTO x 2; RTO=min{64sec, RTO}; } } end /* 諦 める */ 18 41
Retransmission by Duplicated ACK (2) Reception of Duplicated ACK - Fast Retransmission / Fast Recovery Segment 廃 棄 特 性 ; single (or few) segment(s) あるい は 連 続 多 数 未 ACKの 同 一 ACK Segmentsを 複 数 (3 回 ) 受 信 したら 再 送 42
Fast Retransmission by Duplicated ACK 6401:6656(256) ack1 6657:6912(256) ack1 6913:7168(256) ack1 7169:7424(256) ack1 7425:7680(256) ack1 7681:7936(256) ack1 7937:8192(256) ack1 8193:8448(256) ack1 6657:6912(256) ack1 Fast Retransmission 8449:8704(256) ack1 8705:8960(256) ack1 ack 5889 ack 6145 ack 6401 ack 6657 ack 6657 1 ack 6657 2 ack 6657 3 ack 6657 ack 6657 ack 6657 ack 8449 win5888 8961:9216(256) ack1 ack 8705 win5888
UDP 44
UDP Header format 0 7 8 15 16 23 24 31 +--------+--------+--------+--------+ Source Destination Port Port +--------+--------+--------+--------+ Length Checksum +--------+--------+--------+--------+ data octets... +----------------...
46
UDP Header format 0 7 8 15 16 23 24 31 +--------+--------+--------+--------+ フロー 制 御 も 誤 り 訂 正 制 御 Source Destination も 行 Port わない Port +--------+--------+--------+--------+ アプリケーションに 任 せる Length Checksum +--------+--------+--------+--------+ data octets... +----------------...
RTP 48
RTP RTP; Real-time Transport Protocol RTPはEnd-Hostでのみ 適 用 される (*) ルータでの 通 信 品 質 はOut-of-Focus 基 本 仕 様 ; RFC1889, RFC1890 Playbackタイミングの 再 生 - Payload Type - Sequence Number - Time-Stamp 2 対 のUDP Portを 使 用 - User Data - Control Data ContentごとにRTP Payload Formatを 規 定 49
RTP RTP Payload Format 仕 様 RFC2029 ; CellB Video Encoding (for SUN) RFC2032 ; H.261 Video Stream RFC2035 ; JPEG-compressed Video RFC2250 ; MPEG1/MPEG2 Video Control Protocol RTCP ; RTP Control Protocol 通 信 品 質 監 視 機 能 - 通 信 受 信 / 送 信 ノード - 品 質 監 視 ノード 50
Application RTP RTPの 仕 事 ; 受 信 ノードにおいて 送 信 側 から 送 信 される データの 出 力 タイミングを 再 生 する タイミング 制 御 送 信 ノード 受 信 バッファ Generate Delay-Jitter 51
RTP d1 d2 d3 d4 送 信 側 タイミング; t1 t2 t3 t4 t5 受 信 側 入 力 タイミング; t1 t2 t3 t4 t5 受 信 側 出 力 タイミング; T T+t1 T+t2 T+t3 T+t4 T+t5 Off-set d1 d2 d3 d4 52
NAT 53
NAT(Network Address Translation) 受 信 パケットのIPアドレス(src_IP)およびポート 番 号 の(src_port) 変 換 テーブルを 持 ちIPヘッダの 変 換 (RFC1631) (1) Private Global - DNS : 宛 先 ノードのIPアドレスが 解 決 される - 受 信 パケット(dst_IP) 送 信 パケットの(src_IP, src_port)の 書 換 え (2) Global Private - 受 信 パケット(src_IP, src_port) 送 信 パケットの(dst_IP)の 書 換 え (*) ポート 番 号 (src_port)の 機 能 (i) src_ipの 多 重 化 (ii) dst_ipのマッピング 54
NAT A NAT C 入 力 出 力 アドレス ポート アドレス ポート 送 信 宛 先 送 信 宛 先 送 信 宛 先 送 信 宛 先 A ー ー ー N ー ー ー 送 信 アドレス A C A C A Nに 変 換 宛 先 アドレス N C N C N Aに 変 換
Traditional NAT 組 織 内 インターネット A NAT C 送 信 ポート 番 号 送 信 アドレス A Nに 変 換 宛 先 ポート 番 号 C A 200 100 100 A 200 C 宛 先 アドレス C N 200 100 100 200 N C Basic NAT N Aに 変 換 送 信 ポート 番 号 送 信 アドレス A N 100 150に 変 換 宛 先 ポート 番 号 100 A 200 C 宛 先 アドレス 150 200 N C NAPT C A 200 100 N A 150 100に 変 換 C N 200 150
NAPT (Network Address and Port Translation) 172.20.6.1 172.20.6.2 172.20.6.3 NATルータ 157.82.246.115 インターネットへ 送 信 元 IP=172.20.6.1 送 信 元 ポート=1234 1 送 信 元 IP=157.82.240.115 送 信 元 ポート=54321 宛 先 IP=172.20.6.1 宛 先 ポート=1234 2 宛 先 IP=157.82.240.115 宛 先 ポート=54321 1 内 から 外 に 向 かうパケットがあるとNATルータはポート 番 号 を 割 当 2 その 後 外 から 来 るパケットについてもIPアドレスとポート 番 号 を 変 換 57
Bi-directional NAT 組 織 内 インターネット A NAT C DNS (1) ホストAのアドレスは? (2)アドレスはN C A 200 100 C N 200 100 (3) N Aに 変 換 送 信 ポート 番 号 送 信 アドレス A Nに 変 換 100 A 200 C 100 200 N C (4) 宛 先 ポート 番 号 宛 先 アドレス
Twice NAT 組 織 内 インターネット A NAT C (1)ホストC のアドレスは? (2)アドレスは Nl1 DNS 送 信 アドレス A Ng Nl1 Cに 変 換 (3) A Nl1 宛 先 アドレス Ng1 C (4) Nl1 A C Ng1 Ng A C Nl1に 変 換
However Limitation on the number of session states for NAT operation Each user could use certain number of sessions How many sessions? Even as the best case, 65,536 is the maximum number of sessions, shared by customers accommodated into a single IPv4 address When the number of users is 2,000, it will be only 30 sessions This means.. 60
Limitation of NAT Solution Host Host Host NAT Host Host Host Maximum # of sessions 61
Limitation of NAT Solution Host You may have already Host Host experienced!!!! NAT Host Host Host Maximum # of sessions 62
Max 30 Connections 63
Max 20 Connections 64
Max 15 Connections 65
Max 10 Connections 66
Max 5 Connections 67
Some examples of major Web site Application # of TCP sessions No operation 5~10 Yahoo top page 10~20 Google image search 30~60 ニコニコ 動 画 50~80 OCN photo friend 170~200+ itunes 230~270 igoogle 80~100 楽 天 (Rakuten) 50~60 Amazon 90 HMV 100 YouTube 68 90
トランスポートレイヤ 技 術 - TCP; Transmission Control Protocol - 69