• No results found

TCP: Transmission Control Protocol

N/A
N/A
Protected

Academic year: 2021

Share "TCP: Transmission Control Protocol"

Copied!
34
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

TCP: Transmission Control Protocol

Part I : Protocol basics

Surasak Sanguanpong nguan@ku.ac.th

http://www.cpe.ku.ac.th/~nguan

Last updated: July 30, 1999

(2)

Agenda

z

Services provided by TCP

z

TCP format

z

How TCP reliability is achieved

z

Sliding window

z

TCP Connection

z

TCP State

(3)

TCP encapsulation

z

with Ethernet frame

Ethernet hdr IP header TCP header data

segment

(4)

TCP & UDP Services

z TCP : Transmission Control Protocol

z

RFC 793

z

connection-oriented service

z

full duplex

z

reliable service by adding more overhead to manage

acknowledgment, flow control, timer

(5)

TCP: Transmission Control Protocol

z TCP performs typical transport layer functions:

z

passed data to relevant application-level services

z

mux and demux data from applications to and from IP layer

z

error recovery

z

flow control data stream (avoid buffer overflow)

(6)

TCP properties

z byte stream with full duplex transferring

z adaptive to LAN/WAN

z congestion avoidance and control

(7)

TCP data stream

z

TCP provides a full duplex service that simultaneous manages two streams of data

z

stream of octets passed between sender/receiver

application send receive

application

receive

send

(8)

Ports

z

Port - a 16 bit address allocated for the most common application layer services

z

UDP and TCP use port addressing to deliver info to applications

z

Servers are known by ports number

z

FTP 20, TELNET 23, SMTP 25, HTTP 80

z

Port numbers are generally allocated by



0 --not used



1-255 --Reserved ports for well-known services



256-1023 --Other reserved ports



1024-65535 --user-defined server ports

z

Unix store general used ports in /etc/services

Applications

Transport

Network access

1 2 3 4 ( ) ( ) ( ) ( )

(9)

Sockets

z socket : a pair of the IP address and the port number

IP address is unique to a node, the port is unique on a node

the socket gives a unique identification of an application layer services

IP address is unique to a node, the port is unique on a node

the socket gives a unique identification of an application layer services

<158.108.33.3, 3000>

IP address port number

(10)

Socket address

z

A connection is identified by the socket address at its to ends

z

client socket: 158.108.33.3,3000; 158.108.2.71,21

z

server socket: 158.108.2.71,21; 158.108.33.3,3000;

port : 3000 connection port : 21

client server

IP : 158.108.33.3 IP : 158.108.2.71

(11)

Socket multiple connection

z server’s unique socket address can be accessed simultaneously by clients

port : 3000

port : 21 connection

client

server IP : 158.108.33.2

IP : 158.108.2.71

port : 3120 client

IP : 158.108.33.3

(12)

Transmission Control Protocol

z

TCP passed block of data to IP, consisting of the TCP header and application layer data, called segment

z

adding reliability in TCP is achieved by

z

Error detection and correction (due to segments corrupted)

z

Flow control (prevent a transmitter overrunning a receiver owing a resource limitations)

z

Resequencing (IP can deliver datagrams in any order)

z

Removing duplicate segments (due to error-recovery mechanisms

used by TCP)

(13)

How TCP handles reliability

z

Using sequence numbers to identify data

z

positive acknowledgments of data received in the correct sequence

z

retransmission of segments which have not been acknowledged within a (variable) time limit

z

Let’s see these mechanisms in TCP header

(14)

TCP header

source port:16 destination port:16 sequence number:32

acknowledgment number:32

data offs:4 resv:6 flag:6 window size:16 checksum :16 urgent pointer:16 options and padding

0 15 16 31

(15)

TCP header details (I)

z

source, destination port:16,16 - identify applications at ends of the connection

z

sequence:32 - indicates 1

st

data octet in this segment

z

acknowledgment:32 - next expected sequence number,

valid only when the ACK bit (reside in flag) is set

(16)

TCP header details (II)

z data offset:4 - 32 bit words offset tells the receiver where user data begins

z reserved:6 -not used

z flag:6

z

URG : validity of urgent pointer field

z

ACK : validity of acknowledge field

z

PSH : push request (pass segment to appl layer immediately)

z

RST : reset the connection

z

SYN : initial synchronization

z

FIN : sender at end of byte stream

(17)

TCP header details (III)

z

window:16 - advertise amount of buffer space this node has allocated

z

checksum:16 - 16 bits 1’s complement of pseudo header, TCP header and data

z

urgent pointer:16 - byte position of data that should be processed first

z

options - variable length option e.g. MSS (max segment

size) tells destination node

(18)

Sliding window principle

z

send and wait for acknowledgment

z

no ACK within a certain time, retransmit the packet

z

use for flow control :

z

prevent sender from overloading receiver with data, e.g.

high-performance server to slow PC

z

congestion inside network, e.g. router performance, slow link speed

z

How to provide flow control?

z

set the appropriate size of sliding window size

(19)

Sliding window flow control

z

Receiver “ advertises” it’s windows size in acknowledgments

z

Sender will adjusts its allowed to send pointer as receiver’s advertisement

no! no! I can load only 200 kg.

(20)

Sliding window: small window size

SENDER RECEIVER

Send 1 Receive 1

Ack 2

Send 2 Receive 2

Ack 3

z

1 byte window size utilizes efficiency of channel in half (half-duplex transmission)

z

why not send many packets and get back cumulative ACK?

window size =1

(21)

Sliding window: larger window size

SENDER

RECEIVER Send 1

Send 2 Send 3

Receive 1 Receive 2 Receive 3 Receive ACK 4

z

A larger window size allows more data to be transmitted pending acknowledgment

z

Window size specifies how many bytes the receiver is willing to accept

window size =3

Send ACK 4 Send 4

Send 5 Send 6

Receive 4 Receive 5 Receive 6

Receive ACK 4 Send ACK 4

(22)

Sequence number in segment

z

Data continuously sent more than segment

z

need not to wait for acknowledgment every segment

data bytes 500-599 data bytes 600-699 data bytes 700-799

host A host B

ACK 800

I received all up to 799!

(23)

Retransmit a loss segment

data bytes 500-599 data bytes 600-699 data bytes 700-799

host A host B

ACK 700

data bytes 700-799

(24)

Error recovery (I)

z

receiver has to send ACK with sequence number

z

sender reset timer when receives ACK

segment #i, start timer

host A host B

cancel timer

ACK

(25)

Error recovery (II)

z

on time out, sender will retransmit the segment

z

this mechanism is used for error recovery

segment #i, start timer

host A host B

cancel timer

ACK

timer expires, resend #i

(26)

Sliding window buffer

z

sender groups its packet to be transmitted with window indication

1000… 1099 1100… 1199

....999 1200…

sent and ACK

sent and not ACKed

can send

ASAP can’t send now

SndWnd

SndUna SndNxt SndUna+SndWnd

offered windows

(27)

1300…

....999

Sliding window example

z

movement of the right and left edges of the window

1000… 1099 1100… 1199 1200…

SndUna, SndNxt SndUna+SndWnd

1000… 1099 1100… 1199

....999 1200…

SndUna SndNxt SndUna+SndWnd

....999

1000… 1099 1100... 1199 1200…

SndUna SndNxt,SndUna+SndWnd

....999 1000... 1099 1100… 1199 1200 1299

SndUna SndNxt SndUna+SndWnd

initial

send 100 bytes

more 100 bytes

ACK 100 bytes

(28)

TCP in actions

z

before data could be transferred, a connection must be opened

z

servers do passive open (listen)

z

clients do active open (connect)

z

when it finished, the connection is closed

z

TCP has general 3 phases

z

connection setup phase

z

data phase

z

connection close phase

(29)

TCP connection establishment

(1) send SYN (seq=x)

host A host B

(3) send ACK (ack=y+1)

(2) send SYN (seq =y, ack=x+1)

z

TCP uses 3-way handshake to establish a connection

z

exchange the sequence number

z

ensures that both ends are ready and sync sequence number

connection is

setup!

(30)

Transfer phase

z

simple example with terminal connection such as Telnet.

Host echoes back each received character

SEQ=92, ACK=109 DATA=“w”

host A host B

SEQ=93, ACK=110 DATA=“…”

SEQ=109, ACK=93 DATA=“w”

Host echoes back “w”

(31)

TCP Connection close

z

use FIN flag to close connection

SEQ=x, FIN

host A host B

ACK=y+1

ACK=x+1 SEQ=Y

inform application application response with

SEQ=y, FIN

(32)

Open/Close mechanisms

z

Half open - one end has closed, aborted without the knowledge of the other end

z

host may be crashed, power off

z

no detection if no data transfer

z

reset segment (RST bit) is sent when detected

z

Half close - one end of connection terminated its output, but still receiving data from the other end

z

Simultaneous open- both end perform an active open to each other

z

Simultaneous close - both end perform an active open to each

other

(33)

TCP state diagram : open

CLOSED

start

appl passive opens;

send nothing

LISTEN passive open

appl ac

tiv e opens;

sen d S Y

N

SYN_SENT active open SYN_RCVD

got SYN;

send S

YN,ACK

ESTABLISHED

go t SYN , AC

K;

send AC

K go t A

C K;

send noth

in g

got SYN;

send SYN, ACK

simultaneous open

go t RST

appl closes;

send FIN

appl closes;

or time-out

(normal) client transition

(normal) server transition

(34)

TCP state diagram : close

ESTABLISHED

get FI

N, ACK;

send : A C K

appl close;

send F IN appl closes;

send FIN

FIN_WAIT_1 CLOSING

FIN_WAIT_2 TIME_WAIT

got ACK;

send nothing

got FIN;

send ACK

got ACK;

send nothing got FIN;

send ACK

2MSL time-out

CLOSE_WAIT

LAST_ACK appl closes;

send FIN got FIN;

send ACK

got ACK;

send nothing back to CLOSED

passive close

simultaneous close

(normal) client transition

Referenties

GERELATEERDE DOCUMENTEN

Als er een DHCP server in het netwerk aanwezig is zal een ongebruikt IP adres automatisch worden toegewezen aan de IPPS elke keer als deze wordt aangesloten met het lichtnet..

Deze sectie bevat informatie over het configureren van de functies die in dit document worden beschreven. N.B.: Als u aanvullende informatie wilt vinden over de opdrachten in

The objective of the thesis is to develop a robust detection method for vulnerable code patterns that exist in DNS client implementations of embedded TCP/IP stacks and to examine

telefoonnummer en andere gegevens die wij nodig hebben om met jou te kunnen communiceren, zoals jouw e-mailadres;.. De verwerking van bovenstaande gegevens gebeurt alleen voor één

N.B.: Gebruik het Opdrachtupgereedschap (alleen geregistreerde klanten) om meer informatie te vinden over de opdrachten die in dit document worden

Using an optimized window size management scheme, which also considers (burst) errors as the cause of lost packets will probably yield an increase in energy efficiency.. 3.2.4

Voor paren waar A in stand 1 meet en B in stand 2, blijkt 25% van die metingen gelijke spins laten zien, terwijl voor paren... waar A in stand 1 meet en B in stand 3 maar liefst 75%

Deze deeltjes vliegen in tegenovergestelde richtingen weg en we gaan nu bij A of B meten wat de spin-ori¨entatie is, waarvoor we een Stern-Gerlach apparaat beschikbaar hebben dat