36
Transport Protocols - TCP & UDP

Transport Protocols - TCP & UDP

Embed Size (px)

DESCRIPTION

Transport Protocols - TCP & UDP. Transport Protocols. The transport protocol provides an end-to-end data transfer service that shields upper-layer protocols from the details of the intervening network. Two types of transport service connection oriented, e.g. TCP - PowerPoint PPT Presentation

Citation preview

Transport Protocols - TCP & UDP

Transport Protocols• The transport protocol provides an end-to-

end data transfer service that shields upper-layer protocols from the details of the intervening network.

• Two types of transport service— connection oriented, e.g. TCP— connectionless (datagram), e.g. UDP

TCP

• Transmission Control Protocol• Connection-oriented• Guarantees reliable and in-order delivery of

data• Allow multiple concurrent TCP applications

in the same host.• Error detection, Error Correction, Flow

Control

TCP Header

FlagsFlags

Multiplexing in TCP

Use of- source port- destination port

TCP (and UDP) Port Numbers- Server

• Servers use well-known port numbers for their major applications.—Port 80 = HTTP—Ports 20, 21 = FTP

• Port 21 for supervisory information• Port 20 for file transfers

—Port 23 = Telnet—Port 25 = SMTP (E-mail)

常見 TCP/IP應用服務與埠號

21 FTP23 Telnet25 SMTP53 DNS79 Finger80 HTTP110 POP3119 NNTP123 NTP

53 DNS67 BOOTP69 TFTP161 SNMP162 SNMP-Trap

TCPTCP UDPUDP

Port: 0~1023 ,網際網路標準專用

TCP (and UDP) Port Numbers- Client

• Clients Use Ephemeral Port Numbers.

—By IETF rules, Ports 49152 to 65535.

• Windows follows the rules.

• Unix programs usually do not.

—The client chooses a random ephemeral port number for each new connection.

暫時的 短命的

Range of TCP (and UDP) Port Numbers

• 0~1023—The range for assigned ports managed by the IANA

• 1024~49151—Registered Port Numbers

—For non-major applications.

—Unix does not follow the rule.• Uses some of these port numbers as ephemeral port

numbers.

• 49152~65535—Ephemeral Port Numbers—Dynamic and/or Private Ports

• Port numbers:—http://www.iana.org/assignments/port-numbers

Socket

• A socket is an IP address, a colon, and a port number.—Example: 128.171.17.13:80

• For servers, specifies a specific application on a specific server.

• For clients, specifies a specific connection on a specific client.

Use of TCP (and UDP) Port Numbers

Client 60.171.18.22

Webserver1.33.17.13

Port 80

From: 60.171.18.22:50047To: 1.33.17.13:80

SMTP Server123.30.17.120

Port 25

A connection has bothA source and destination socket.

Based on the packet IP addressesand the TCP or UDP port number fields

Ephemeral Source Port Number (50047)

Well-Known DestinationPort Number (80)

Use of TCP (and UDP) Port Numbers

Client 60.171.18.22

Webserver1.33.17.13

Port 80

From: 60.171.18.22:50047To: 1.33.17.13:80

From: 60.171.18.22:60003To: 123.30.17.120:25

SMTP Server123.30.17.120

Port 25

If a client connects to two servers,it will select different ephemeral port numbers(50047 and 60003) for the two connections

Sequence & Acknowledge Number

• Sequence Number (SN)—All octets sent within a TCP connection are

numbered sequentially. The number is started from ISN+1.

—The sequence number of the first octet of this segment.

• Acknowledge Number (AN)—If AN = j, all octets through SN= j-1 have been

received successfully.

—Next expected segment will begin from octet j.

ISN: Initial Sequence Number

Sequence & Acknowledge Number

ClientTransport Process

ServerTransport Process

Data (SN = 7000, length = 1460)

ACK (AN = 8460)

Data (SN=20000, length = 800)

ACK (AN = 20800)

Data Offset (4 bits)

• Header length• The number of 32-bit words in the TCP

header.• This indicates where the data begins.• The length of the TCP header is always a

multiple of 32 bits.

Flags (8 bits)

• CWR (Congestion Window Reduced)— To indicate that the sending host received a TCP segment with

ECE set.

• ECE (ECN-Echo)— To indicate that the TCP peer is ECN capable during 3-way

handshake

• URG: Urgent pointer field is significant

• ACK: Acknowledgement field is significant

• PSH: Push function

• RST: Reset the connection

• SYN: Synchronize sequence numbers

• FIN: No more data from sender

TCP Operations

• TCP Connection— Connection Establishment

• Three-way handshaking

— Data Transfer• Acknowledgement• Retransmission of lost packets• Discarding duplicate packets• Use of Window

— Connection Termination• Four-way handshaking

Connection Establishment• TCP three-way handshaking

ClientTransport Process

ServerTransport Process

1. SYN i

2. SYN j, ACK i+1

3. ACK j+1

Passive OpenActive Open

i: Client’s initial sequence number (ISN)j: Server’s initial sequence number (ISN)

Connection Termination• TCP four-way handshaking

ClientTransport Process

ServerTransport Process

1. FIN i

2. ACK i

3. FIN j

4. ACK j

* 2 & 3 can be combined three-way handshaking

Relative sequence numberRelative sequence number

Data Transfer• Acknowledgement

ClientTransport Process

ServerTransport Process

Data (c1)

ACK (of data c1)

Data (s1)

ACK (of data s1)

Retransmission of lost packets

ClientTransport Process

ServerTransport Process

Data (c1)

Data (c1)

ACK (of data c1)

Data (s1)

ACK (of data s1)

Retransmission Timeout

retransmit

X

Discarding duplicate packets

ClientTransport Process

ServerTransport Process

Data (c1)

Data (s1)

ACK (of s1)

RetransmissionTimeout ACK (of c1)

Data (c1)retransmit

X

duplicated

Discard it.

TCP state diagram

Window• TCP Window Size

—How many more octets it can transmit before getting another acknowledgement.

• Sender receives a TCP segment with AN=i, W=j.— Sender knows that the receiver has received octets before i.

—Sender can send octets i ~ i+j-1.

—Improve the stop-and-wait scheme, in which only one PDU at a time can be in transit.

• Sender receives a TCP segment with W=0.— Cannot send any more octets

— Flow control

17520 (3718091612 ~ 3718091612+17519)

3718091612 + 1460 = 3718093072

16060 (3718093072 ~ 3718091612+17519)

= 3718091612 + 1460

3718093072 + 1460 = 3718094532

13600 (3718094532 ~ 3718091612+17519)

= 3718093072 + 1460

17520 (3718094532 ~ 3718094532+17519)

TCP Options• Maximum segment size

— Included in SYN segment

• Window scale— Included in SYN segment—Window field gives credit allocation in octets—With Window Scale value in Window field multiplied by 2F

• F is the value of window scale option

• Sack-permitted—Selective acknowledgement allowed

• Sack—Receiver can inform sender of all segments received successfully—Sender retransmit segments not received

• Timestamps—Send timestamp in data segment and return echo of that

timestamp in ACK segment

Transport Protocol Timers

UDP• User Datagram Protocol (UDP)

—Connectionless—RFC 768

• Connectionless service for application level procedures—Unreliable—Delivery and duplication control not

guaranteed

• Reduced overhead• e.g. network management

UDP Uses• Inward data collection• Outward data dissemination• Request-Response• Real time application

UDP Header