48
1 Chapter 12 Chapter 12 Transmission Control Transmission Control Protocol (TCP) Protocol (TCP) Mi-Jung Choi Dept. of Computer Science and Engineering [email protected]

Chapter 12 Transmission Control Protocol (TCP)

Embed Size (px)

DESCRIPTION

Chapter 12 Transmission Control Protocol (TCP). Mi-Jung Choi Dept. of Computer Science and Engineering [email protected]. Contents. 12.1TCP SERVICES 12.2TCP FEATURES 12.3SEGMENT 12.4A TCP CONNECTION 12.5STATE TRANSITION DIAGRAM 12.6FLOW CONTROL 12.7ERROR CONTROL - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 12  Transmission Control   Protocol (TCP)

11

Chapter 12Chapter 12 Transmission Control Transmission Control Protocol (TCP) Protocol (TCP)

Mi-Jung Choi

Dept. of Computer Science and Engineering

[email protected]

Page 2: Chapter 12  Transmission Control   Protocol (TCP)

22

12.1 TCP SERVICES

12.2 TCP FEATURES

12.3 SEGMENT

12.4 A TCP CONNECTION

12.5 STATE TRANSITION DIAGRAM

12.6 FLOW CONTROL

12.7 ERROR CONTROL

12.8 CONGESTION CONTROL

12.9 TCP TIMERS

12.10 OPTIONS

12.12 TCP PACKAGE

Contents Contents

Page 3: Chapter 12  Transmission Control   Protocol (TCP)

33

Be able to name and understand the services offered by TCP

Understand TCP’s flow and error control and congestion control

Be familiar with the fields in a TCP segment

Understand the phases in a connection-oriented connection

Understand the TCP transition state diagram

Be able to name and understand the timers used in TCP

Be familiar with the TCP options

ObjectivesObjectives

Page 4: Chapter 12  Transmission Control   Protocol (TCP)

44

TCP/IP ProtocolsTCP/IP Protocols

Page 5: Chapter 12  Transmission Control   Protocol (TCP)

55

To create a process-to-process communication (using port numbers)

To create a flow control mechanism at the transport level (using

sliding window)

To create a error control mechanism at the transport level (using

Ack packet, time-out, retransmission)

Sequence control mechanism

A connection oriented, reliable transport protocol

TCP/IP FunctionsTCP/IP Functions

Page 6: Chapter 12  Transmission Control   Protocol (TCP)

66

12.1 TCP SERVICES12.1 TCP SERVICES

We explain the services offered by TCP to the processes at the We explain the services offered by TCP to the processes at the

application layerapplication layer

The topics discussed in this section include:The topics discussed in this section include:

Process-to-Process CommunicationProcess-to-Process Communication

Stream Delivery ServiceStream Delivery Service

Full-Duplex CommunicationFull-Duplex Communication

Connection-Oriented ServiceConnection-Oriented Service

Reliable ServiceReliable Service

Page 7: Chapter 12  Transmission Control   Protocol (TCP)

77

For client/server communication

we must define the Local host Local client program Remote host Remote server program

Process-to-Process CommunicationProcess-to-Process Communication

Page 8: Chapter 12  Transmission Control   Protocol (TCP)

88

PROCESS-TO-PROCESS COMMUNICATION (cont.)PROCESS-TO-PROCESS COMMUNICATION (cont.)

Port numbers :

~ mentioned in UDP chapter

Page 9: Chapter 12  Transmission Control   Protocol (TCP)

99

PROCESS-TO-PROCESS COMMUNICATION (cont.)PROCESS-TO-PROCESS COMMUNICATION (cont.) Well-known port in TCP

Port Protocol Description

7 Echo Echoes a received datagram back to the sender

9 Discard Discards any datagram that is received

11 Users Active users

13 Daytime Returns the date and the time

17 Quote Returns a quote of the day

19 Chargen Returns a string of characters

20 FTP,data File transfer Protocol for data

21 FTP,control File transfer Protocol for control

23 TELNET Terminal Network

25 SMTP Simple Mail Transfer Protocol

53 DNS Domain Name Server

67 BOOTP Bootstrap protocol

79 Finger finger

80 HTTP Hypertext Transfer Protocol

111 RPC Remote Procedure Call

Page 10: Chapter 12  Transmission Control   Protocol (TCP)

1010

As we said in Chapter 11, in UNIX, the well-known ports are stored in a file called /etc/services. Each line in this file gives the name of the server and the well-known port number. We can use the grep utility to extract the line corresponding to the desired application. The following shows the ports for FTP.

$ grep ftp /etc/services

ftp-data 20/tcpftp-control 21/tcp

Example 1Example 1

Page 11: Chapter 12  Transmission Control   Protocol (TCP)

1111

PROCESS-TO-PROCESS COMMUNICATION (cont.)PROCESS-TO-PROCESS COMMUNICATION (cont.)

Socket addresses

~ a combination of IP address and port number

~ to make a connection for each end

~ to need a pair of socket addresses: client and server socket address

These four pieces of information are part of the IP header (IP

address) and TCP header (port number)

Page 12: Chapter 12  Transmission Control   Protocol (TCP)

1212

12.1 12.1 TCP SERVICES (cont.)TCP SERVICES (cont.)

Stream delivery service

Sending and receiving buffers

Segments

Full-Duplex service

piggybacking

Connection-Oriented service

A virtual connection (not physical connection)

Reliable service

Reply acknowledge packet

Page 13: Chapter 12  Transmission Control   Protocol (TCP)

1313

Sending TCP

~ receives data as a stream of bytes from application process using sending buffer

~ make data to appropriate segments and transfer to network

Receiving TCP

~ receives segments using receiving buffer~ reassemble segments to data and send data as a stream of bytes to

application process

Stream deliveryStream delivery

Page 14: Chapter 12  Transmission Control   Protocol (TCP)

1414

SSending and receiving buffersending and receiving buffers

The sending process and the receiving process may not produce

and consume data at the same speed, TCP needs buffers for storage

Page 15: Chapter 12  Transmission Control   Protocol (TCP)

1515

TCP segmentsTCP segments

IP layer, as a service provider for TCP, needs to send data in

packets, not as a stream of bytes.

TCP groups a number of bytes together into a packet called segment

Page 16: Chapter 12  Transmission Control   Protocol (TCP)

1616

UDP vs. TCP communicationUDP vs. TCP communication

응용 응용 응용 응용

TCP송신버퍼

TCP수신버퍼

segmentsegment segmentsegment

응용 응용 응용 응용

UDP

역다중화

datagramdatagram datagramdatagram

UDP

다중화

Page 17: Chapter 12  Transmission Control   Protocol (TCP)

1717

12.2 TCP FEATURES12.2 TCP FEATURES

To provide the services mentioned in the previous section, TCP has To provide the services mentioned in the previous section, TCP has

several features that are briefly summarized in this section. several features that are briefly summarized in this section.

The topics discussed in this section include:The topics discussed in this section include:

Numbering System Numbering System

Flow ControlFlow Control

Error ControlError Control

Congestion ControlCongestion Control

Page 18: Chapter 12  Transmission Control   Protocol (TCP)

1818

Numbering systemNumbering system

TCP keeps track of the segment being transmitted or

received using sequence number and acknowledge number

These number is used for flow and error control

The bytes of data being transferred in each connection

are numbered by TCP

The numbering starts with a randomly generated number

(b/w 0 ~ 232-1)

Page 19: Chapter 12  Transmission Control   Protocol (TCP)

1919

Numbering systemNumbering system

When TCP receives bytes of data from the process and

stores them in sending buffer

After numbering the bytes, TCP assigns sequence

number to each segment that is being sent

The value of the sequence number field in a segment

defines the number of the first data byte contained in that

segment

The value of the acknowledgment field in a segment defines

the number of the next byte a party expects to receives.

The acknowledgment number is cumulative

Page 20: Chapter 12  Transmission Control   Protocol (TCP)

2020

Example 2Example 2

Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is

numbered 10001. What are the sequence numbers for each segment if data is sent

in five segments, each carrying 1000 bytes?

Solution:

The following shows the sequence number for each segment:

Segment 1 ➡ Sequence Number: 10,001 (range: 10,001 to 11,000)

Segment 2 ➡ Sequence Number: 11,001 (range: 11,001 to 12,000)

Segment 3 ➡ Sequence Number: 12,001 (range: 12,001 to 13,000)

Segment 4 ➡ Sequence Number: 13,001 (range: 13,001 to 14,000)

Segment 5 ➡ Sequence Number: 14,001 (range: 14,001 to 15,000)

Page 21: Chapter 12  Transmission Control   Protocol (TCP)

2121

A packet in TCP is called a segmentA packet in TCP is called a segment

The topics discussed in this section include:The topics discussed in this section include:

•FormatFormat•EncapsulationEncapsulation

12.3 SEGMENT12.3 SEGMENT

Page 22: Chapter 12  Transmission Control   Protocol (TCP)

2222

12.3 SEGMENT12.3 SEGMENT

The unit of data transfer b/w 2 devices using TCP is a segment

Page 23: Chapter 12  Transmission Control   Protocol (TCP)

2323

12.3 SEGMENT (cont.)12.3 SEGMENT (cont.)

Segment

source port address : the port number of the application program in the sender’s host

destination port address : the port number of the application program in the receiver’s host

sequence number : the number of the 1st byte of data in this segment

acknowledgement number : the byte number that the receiver is expecting to receive from the other party

header length : 4 bytes

control :

window size: 16 bits

checksum : all segment including pseudo-header

urgent pointer :

option :

Page 24: Chapter 12  Transmission Control   Protocol (TCP)

2424

12.3 SEGMENT (cont.)12.3 SEGMENT (cont.)

Control

Flag Description

----- --------------

URG Urgent pointer field is valid

ACK Acknowledgment field is valid

PSH Push the data

RST Connection must be reset

SYN Synchronize sequence numbers

FIN Terminate the connection

Page 25: Chapter 12  Transmission Control   Protocol (TCP)

2525

12.3 SEGMENT (cont.)12.3 SEGMENT (cont.)

Control

URG: 긴급 포인터가 유효함

ACK: 확인 응답 번호가 유효함

PSH: 수신측은 데이터를 가능한 빨리 응용으로 보내야 함

RST: 연결을 재설정

SYN: 연결을 초기화히기 위해 순서 번호를 동기화

FIN: 송신측이 데이터 전송을 종료함

Page 26: Chapter 12  Transmission Control   Protocol (TCP)

2626

Pseudoheader added to the TCP datagramPseudoheader added to the TCP datagram

The inclusion of the checksum in TCP is mandatory

Page 27: Chapter 12  Transmission Control   Protocol (TCP)

2727

Encapsulation and decapsulationEncapsulation and decapsulation

Page 28: Chapter 12  Transmission Control   Protocol (TCP)

2828

12.4 TCP CONNECTION 12.4 TCP CONNECTION

TCP is connection-oriented. A connection-oriented transport protocol TCP is connection-oriented. A connection-oriented transport protocol

establishes a virtual path between the source and destination. All of the establishes a virtual path between the source and destination. All of the

segments belonging to a message are then sent over this virtual path. A segments belonging to a message are then sent over this virtual path. A

connection-oriented transmission requires three phases: connection connection-oriented transmission requires three phases: connection

establishment, data transfer, and connection termination.establishment, data transfer, and connection termination.

The topics discussed in this section include:The topics discussed in this section include:

Connection EstablishmentConnection Establishment

Data TransferData Transfer

Connection TerminationConnection Termination

Connection ResetConnection Reset

Page 29: Chapter 12  Transmission Control   Protocol (TCP)

2929

12.4 TCP CONNECTION12.4 TCP CONNECTION

TCP: connection oriented

Establishment the VC b/w source TCP and destination

Connection establishment and termination

Connection establishment

3 단계 수행1) 호스트 A 는 호스트 B 에게 연결 설정 세그먼트를 전송 ( 초기화 정보 )

2) 호스트 B 는 호스트 A 에게 확인응답 세그먼트 와 초기화 정보 세그먼트 전송3) 호스트 A 는 호스트 B 에게 확인응답 세그먼트 전송

Connection termination

4 단계 수행 1) 호스트 A 는 연결 종료를 알리고 세그먼트 전송2) 호스트 B 는 A 의 요구에 대해 확인 응답하는 세그먼트 전송3) 호스트 B 는 연결 종료를 알리는 세그먼트 전송4) 호스트 A 는 B 의 요구에 대해 확인응답

Page 30: Chapter 12  Transmission Control   Protocol (TCP)

3030

Connection establishment using three-way handshakingConnection establishment using three-way handshaking

Page 31: Chapter 12  Transmission Control   Protocol (TCP)

3131

Connection establishment using three-way Connection establishment using three-way hhandshakingandshaking A SYN segment cannot carry data, but it consumes one sequence

number.

A SYN + ACK segment cannot carry data, but does consume one

sequence number.

An ACK segment, if carrying no data, consumes no sequence number.

Page 32: Chapter 12  Transmission Control   Protocol (TCP)

3232

Data transferData transfer

The FIN segment consumes one sequence number if it does not carry data

Page 33: Chapter 12  Transmission Control   Protocol (TCP)

3333

Connection termination using three-way handshakingConnection termination using three-way handshaking

The FIN + ACK segment consumes one sequence number if it does not carry data

Page 34: Chapter 12  Transmission Control   Protocol (TCP)

3434

Half CloseHalf Close

One end stops sending data while still receiving data.

Normally initiated by client.

It can occur when the server needs all data before processing can begin

Sorting example

The client, after sending all data to be sorted, can close the connection in the outbound direction.

However, the inbound direction must remain open to receive the sorted data.

Page 35: Chapter 12  Transmission Control   Protocol (TCP)

3535

Connection ResetConnection Reset

The TCP at end may deny a connection request, may abort a

connection, or may terminate an idle connection. All of these are

done with the RST (reset) flag.

Denying a connection

Aborting a connection

Terminating an idle connection

Page 36: Chapter 12  Transmission Control   Protocol (TCP)

3636

To keep track of all the different events happening during To keep track of all the different events happening during connection establishment, connection termination, and data connection establishment, connection termination, and data transfer, the TCP software is implemented as a finite state machine. transfer, the TCP software is implemented as a finite state machine.

The topics discussed in this section include:The topics discussed in this section include:

•ScenariosScenarios

12.5 STATE TRANSITION DIAGRAM12.5 STATE TRANSITION DIAGRAM

Page 37: Chapter 12  Transmission Control   Protocol (TCP)

3737

12.512.5 STATE TRANSITION DIAGRAMSTATE TRANSITION DIAGRAM

finite state machine

At any moment, the machine is in one of the state

TCP states

State Description----- --------------CLOSED There is no connectionLISTEN The server is waiting for calls from the clientSYN-SENT A connection request is sent; waiting for acknowledgmentSYN-RCVD A connection request is receivedESTABLISHED Connection is establishedFIN-WAIT-1 The application has requested the closing of the connectionFIN-WAIT-2 The other side has accepted the closing of the connectionCLOSINGBoth sides have decided to close simultaneouslyTIME-WAIT Waiting for retransmitted segments to dieCLOSE-WAIT The server is waiting for the application to closeLAST-ACK The server is waiting for the last acknowledgment

Page 38: Chapter 12  Transmission Control   Protocol (TCP)

3838

STATE TRANSITION DIAGRAMSTATE TRANSITION DIAGRAM

SYN

SYN +ACK

ACK

FIN

ACK

ACK

FIN

data

ack

client server

- state : ovals- Transition from one to another

state : directed line- values on line

input / output- Dotted line : server- Solid line : client - Thin line : unusual situation

Page 39: Chapter 12  Transmission Control   Protocol (TCP)

3939

Connection scenarioConnection scenario

The common value for MSL (Maximum Segment Lifetime) is between 30 seconds and 1 minute

Page 40: Chapter 12  Transmission Control   Protocol (TCP)

4040

Client states

Server states

STATE TRANSITION DIAGRAMSTATE TRANSITION DIAGRAM

Page 41: Chapter 12  Transmission Control   Protocol (TCP)

4141

Connection termination using three-way handshakeConnection termination using three-way handshake

Page 42: Chapter 12  Transmission Control   Protocol (TCP)

4242

Simultaneous OpenSimultaneous Open

Page 43: Chapter 12  Transmission Control   Protocol (TCP)

4343

Simultaneous CloseSimultaneous Close

Page 44: Chapter 12  Transmission Control   Protocol (TCP)

4444

Denying a ConnectionDenying a Connection

Page 45: Chapter 12  Transmission Control   Protocol (TCP)

4545

Aborting a connectionAborting a connection

Page 46: Chapter 12  Transmission Control   Protocol (TCP)

4646

TCP OPERATIONTCP OPERATION

Encapsulation and decapsulation

Page 47: Chapter 12  Transmission Control   Protocol (TCP)

4747

TCP OPERATION (cont.)TCP OPERATION (cont.)

Buffering

Page 48: Chapter 12  Transmission Control   Protocol (TCP)

4848

TCP OPERATION (cont.)TCP OPERATION (cont.)

Multiplexing and demultiplexing