Presentation is loading. Please wait.

Presentation is loading. Please wait.

TCP Tutorial Internet Computing KUT ( Youn-Hee Han It is licensed under a Creative Commons Attribution.

Similar presentations

Presentation on theme: "TCP Tutorial Internet Computing KUT ( Youn-Hee Han It is licensed under a Creative Commons Attribution."— Presentation transcript:

1 TCP Tutorial Internet Computing Laboratory @ KUT ( Youn-Hee Han It is licensed under a Creative Commons Attribution 2.5 License

2 Computer Network2 TCP Introduction

3 Computer Network3 Connection-oriented Service with Reliability Information unit is a “segment” 응용 데이터는 TCP 가 전송하기 적합한 크기로 나뉨 반면, UDP 는 각 응용에 맞는 UDP 데이터그램을 직접 생성 Byte stream service Two application exchanges 8-bit (byte) stream date TCP does not interpreter the bytes’ contents No Message Boundary TCP Features

4 Computer Network4 Sender TCP set a timer whenever sending a segment Sender waits an ACK message after sending a segment Receiver TCP should send an ACK message to the sender Sender re-sends the segment if it does not receive an ACK message before the timer expires TCP Features

5 Computer Network5 TCP segment is delivered as IP datagram IP datagram may be out of order  TCP segment may be out of order Receiver TCP re-organizes the segments according to the correct sequence Receive TCP eliminates the duplicated segment TCP Features

6 Computer Network6 TCP provides flow control TCP 연결의 각 종단은 유한한 버퍼를 가짐 수신측 TCP 는 버퍼용량을 초과하지 않는 범위의 데이터를 받음 TCP provides congestion control 네트워크가 Congestion 하여 Ack 가 늦게 오거나 Ack 가 오지 않는 경우 보내는 데이터의 양을 줄임 TCP utilizes the checksum to detect an error on the header and data 데이터가 전송 중에 변화되었는지 검출하는 것이 목적 기본적으로 오류가 난 세그먼트는 받지 않은 것으로 취급.  송신자의 타임아웃과 재전송을 기다림. IP provides 16 bit checksum for IP header. TCP provides 32 bit checksum for TCP header and TCP data. TCP Features

7 Computer Network7 Full-duplex communication Bi-directional data flow Data can be transmitted while receiving Use of "Piggyback"  Data packets can convey feedback information in the opposite direction TCP Features

8 Computer Network8 TCP may delay data transfer. If TCP has not received enough data from the application  TCP tries to aggregate data as much as possible. Applications that use TCP do not know when data will be sent. TCP Features

9 Computer Network9 TCP Ports, Connections, And Endpoints Endpoint of communication is application program TCP uses protocol port number to identify application TCP defines an “ endpoint ” to be a pair of integers (host, port)  Where host is the IP address for a host TCP connection between two endpoints identified by four items Sender ’ s IP address Sender ’ s protocol port number Receiver ’ s IP address Receiver ’ s protocol port number

10 Computer Network10 Socket: a door between application process and end- end-transport protocol (UCP or TCP) process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet Socket

11 Computer Network11 TCP Segment Header 20 bytes + options One of options: Maximum Segment Size (MSS) 16-bit destination port number16-bit source port number 32-bit sequence number 32-bit acknowledgment number 4-bit header length 0 151631 reserved (6bits) URGURG ACKACK PSHPSH RSTRST SYNSYN FINFIN 16-bit window sizes 16-bit urgent pointer16-bit TCP checksum options (if any) data (if any) Counting by bytes of data (not segments!)

12 Computer Network12 Each connection identified with 4-tuple: (SrcPort, SrcIPAddr, DsrPort, DstIPAddr) Sliding window + flow control acknowledgment(Num), SequenceNum, AdvertisedWindow Flags SYN, FIN, RESET, PUSH, URG, ACK Checksum pseudo header + TCP header + data TCP Segment Header

13 Computer Network13 Six flags and Option Six flag bits URG - The urgent pointer is valid. (generally not used) ACK - The acknowledgment number is valid PSH - The receiver pass this data to the application as soon as possible. (generally not used) RST - Reset the connection. SYN - Synchronize sequence numbers to initiate a connection. FIN - The sender is finished sending data. Urgent pointer URG 플래그가 설정되어 있을 때만 유효함. 송신 측이 상대 편에게 긴급한 데이터를 보내는 방법 (out-of-band data) Option field MSS 라고 불리는 maximum segment size option 을 위한 자리 Connection establish (SYN 이 set 됨 ) 하기 위한 메시지에 이 option 을 지정함

14 Computer Network14 Client Server SYN ISN=X SYN ISN=X 1 SYN ISN=Y ACK=X+1 SYN ISN=Y ACK=X+1 2 ACK=Y+1 3 time TCP connection establishment 3 way handshake 1 2 3 Client: “I want to talk, and I’m starting with byte number X”. Server: “OK, I’m here and I’ll talk. My first byte will be called number Y, and I know your first byte will be number X+1”. Client: “Got it - you start at byte number Y+1”.

15 Computer Network15 TCP connection establishment 3 way handshake Initial sequence numbers, x & y, are chosen randomly Guarantees both sides ready & know it, and sets initial sequence numbers, also sets window & mss Once connection established, data can flow in both directions, equally well, there is no master or slave Send SYN seq. #=x Rcv SYN + ACK segt Send ACK seq.#=y+1 Rcv SYN segment Rcv ACK segment Send SYN seq.#=y, ACK #=x+1 Site 1 Site 2 Active Win 4096, mss 1460 Passive Win 4096, mss 1024

16 Computer Network16 TCP connection establishment Passive And Active Opens Two sides of a connection  Client  Server One side initiates contact A client program (Site 1) Uses TCP ’ s active open One side waits for contact A server program (Site 2) Uses TCP ’ s passive open

17 Computer Network17 TCP close connection The TCP layer can send a RST segment that terminates a connection if something is wrong. Usually the application tells TCP to terminate the connection politely with a FIN segment. FIN segment Either end of the connection can initiate termination. Application 1 call “ close() ” function A FIN is sent, which means the application is done sending data. The FIN is ACK ’ d. Application 2 call “ close() ” function A FIN is also sent. That FIN must be ACK ’ d.

18 Computer Network18 TCP close connection Modified 3 way handshake (or 4 way termination) App1 App2 FIN SN=X FIN SN=X 1 ACK=X+1 2 ACK=Y+1 4 FIN SN=Y FIN SN=Y 3... 1 2 3 4 App1: “I have no more data for you”. App2: “OK, I understand you are done sending.” ……. pause… App2: “OK - Now I’m also done sending data”. App1: “I understand, Goodbye”

19 Computer Network19 TCP close connection Modified 3 way handshake (or 4 way termination) App tells TCP to close, TCP sends remaining data & waits for ACK, then sends FIN & EOF (End of Data) Site 2 TCP ACKs FIN, tells its application “ EOF ” Site 2 sends FIN when its app closes connection (may be long delay) exit(0) automatically calls close() (App closes) Send FIN seq=s Rcv ACK segment Rcv FIN segment Receive ACK segment Send ACK s+1 (inform app) Site 1 Site 2 Rcv FIN + ACK seg Send ACK t+1 (app closes connection) Send FIN seq=t, ACK s+1 FIN (EOF) Timed wait

20 Computer Network20 State Transition Diagram ESTABLISHED state to the CLOSED 1.This side closes first: ESTABLISHED >> FIN_WAIT_1 >> FIN_WAIT_2 >> TIMEWAIT >> CLOSED 2.The other side closes first: ESTABLISHED >> CLOSE_WAIT >> LAST_ACK >> CLOSED 3.Both sides close at the same time: ESTABLISHED >> FIN_WAIT_1 >> CLOSINC >> TIME_WAIT >> CLOSED.

Download ppt "TCP Tutorial Internet Computing KUT ( Youn-Hee Han It is licensed under a Creative Commons Attribution."

Similar presentations

Ads by Google