Agenda Services provided by TCP TCP format How TCP reliability - - PDF document

agenda
SMART_READER_LITE
LIVE PREVIEW

Agenda Services provided by TCP TCP format How TCP reliability - - PDF document

1/34 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 Applied Network Research Group Department of


slide-1
SLIDE 1

Applied Network Research Group Department of Computer Engineering, Kasetsart University 1/34

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 Applied Network Research Group Department of Computer Engineering, Kasetsart University 2/34

Agenda

  • Services provided by TCP
  • TCP format
  • How TCP reliability is achieved
  • Sliding window
  • TCP Connection
  • TCP State
slide-2
SLIDE 2

Applied Network Research Group Department of Computer Engineering, Kasetsart University 3/34

TCP encapsulation

  • with Ethernet frame

Ethernet hdr IP header TCP header data

segment

Applied Network Research Group Department of Computer Engineering, Kasetsart University 4/34

TCP & UDP Services

TCP : Transmission Control Protocol

RFC 793 connection-oriented service full duplex reliable service by adding more overhead to manage

acknowledgment, flow control, timer

slide-3
SLIDE 3

Applied Network Research Group Department of Computer Engineering, Kasetsart University 5/34

TCP: Transmission Control Protocol

TCP performs typical transport layer functions:

passed data to relevant application-level services mux and demux data from applications to and from IP

layer

error recovery flow control data stream (avoid buffer overflow) Applied Network Research Group Department of Computer Engineering, Kasetsart University 6/34

TCP/IP implementations

  • 1983 4.2BSD- first widely available TCP/IP release
  • 1986 4.3BSD- performance improvements
  • 1988 4.3BSD Tahoe- add slow start, congestion avoidance

and fast retransmit

  • 1990 4.3BSD Reno- add TCP header prediction, SLIP

compression, new routing table

  • 1993 4.4 BSD- add multicasting
slide-4
SLIDE 4

Applied Network Research Group Department of Computer Engineering, Kasetsart University 7/34

TCP properties

byte stream with full duplex transferring adaptive to LAN/WAN congestion avoidance and control

Applied Network Research Group Department of Computer Engineering, Kasetsart University 8/34

TCP data stream

  • TCP provides a full duplex service that simultaneous

manages two streams of data

  • stream of octets passed between sender/receiver

application send receive application receive send

slide-5
SLIDE 5

Applied Network Research Group Department of Computer Engineering, Kasetsart University 9/34

Ports

  • Port - a 16 bit address allocated for the most common

application layer services

  • UDP and TCP use port addressing to deliver info to

applications

  • Servers are known by ports number
  • FTP 20, TELNET 23, SMTP 25, HTTP 80
  • 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
  • Unix store general used ports in /etc/services

Applications Transport Network access

1 2 3 4 ( ) ( ) ( ) ( ) Applied Network Research Group Department of Computer Engineering, Kasetsart University 10/34

Sockets

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

slide-6
SLIDE 6

Applied Network Research Group Department of Computer Engineering, Kasetsart University 11/34

Socket address

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

ends

client socket: 158.108.33.3,3000; 158.108.2.71,21 server socket: 158.108.2.71,21; 158.108.33.3,3000;

port : 3000

port : 21 connection client server IP : 158.108.33.3 IP : 158.108.2.71

Applied Network Research Group Department of Computer Engineering, Kasetsart University 12/34

Socket multiple connection

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

slide-7
SLIDE 7

Applied Network Research Group Department of Computer Engineering, Kasetsart University 13/34

Transmission Control Protocol

  • TCP passed block of data to IP, consisting of the TCP header

and application layer data, called segment

  • adding reliability in TCP is achieved by

Error detection and correction (due to segments corrupted) Flow control (prevent a transmitter overrunning a receiver owing a

resource limitations)

Resequencing (IP can deliver datagrams in any order) Removing duplicate segments (due to error-recovery mechanisms

used by TCP)

Applied Network Research Group Department of Computer Engineering, Kasetsart University 14/34

How TCP handles reliability

  • Using sequence numbers to identify data
  • positive acknowledgments of data received in the correct

sequence

  • retransmission of segments which have not been

acknowledged within a (variable) time limit

  • Let’s see these mechanisms in TCP header
slide-8
SLIDE 8

Applied Network Research Group Department of Computer Engineering, Kasetsart University 15/34

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

  • ptions and padding

0 15 16 31

Applied Network Research Group Department of Computer Engineering, Kasetsart University 16/34

TCP header details (I)

  • source, destination port:16,16 - identify applications at ends
  • f the connection
  • sequence:32 - indicates 1st data octet in this segment
  • acknowledgment:32 - next expected sequence number,

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

slide-9
SLIDE 9

Applied Network Research Group Department of Computer Engineering, Kasetsart University 17/34

TCP header details (II)

data offset:4 - 32 bit words offset tells the

receiver where user data begins

reserved:6 -not used flag:6

  • URG : validity of urgent pointer field
  • ACK : validity of acknowledge field
  • PSH : push request (pass segment to appl layer immediately)
  • RST : reset the connection
  • SYN : initial synchronization
  • FIN : sender at end of byte stream

Applied Network Research Group Department of Computer Engineering, Kasetsart University 18/34

TCP header details (III)

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

allocated

  • checksum:16 - 16 bits 1’s complement of pseudo header,

TCP header and data

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

processed first

  • ptions - variable length option e.g. MSS (max segment

size) tells destination node

slide-10
SLIDE 10

Applied Network Research Group Department of Computer Engineering, Kasetsart University 19/34

Sliding window principle

  • send and wait for acknowledgment
  • no ACK within a certain time, retransmit the packet
  • use for flow control :

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

high-performance server to slow PC

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

speed

  • How to provide flow control?

set the appropriate size of sliding window size Applied Network Research Group Department of Computer Engineering, Kasetsart University 20/34

Sliding window flow control

  • Receiver “ advertises” it’s windows size in

acknowledgments

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

advertisement

no! no! I can load only 200 kg.

slide-11
SLIDE 11

Applied Network Research Group Department of Computer Engineering, Kasetsart University 21/34

Sliding window: small window size

SENDER RECEIVER

Send 1 Receive 1 Ack 2 Send 2 Receive 2 Ack 3

  • 1 byte window size utilizes efficiency of channel in half

(half-duplex transmission)

  • why not send many packets and get back cumulative ACK?

window size =1

Applied Network Research Group Department of Computer Engineering, Kasetsart University 22/34

Sliding window: larger window size

SENDER RECEIVER

Send 1 Send 2 Send 3 Receive 1 Receive 2 Receive 3 Receive ACK 4

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

acknowledgment

  • 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

slide-12
SLIDE 12

Applied Network Research Group Department of Computer Engineering, Kasetsart University 23/34

Sequence number in segment

  • Data continuously sent more than segment
  • 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!

Applied Network Research Group Department of Computer Engineering, Kasetsart University 24/34

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

slide-13
SLIDE 13

Applied Network Research Group Department of Computer Engineering, Kasetsart University 25/34

Error recovery (I)

  • receiver has to send ACK with sequence number
  • sender reset timer when receives ACK

segment #i, start timer host A host B cancel timer ACK

Applied Network Research Group Department of Computer Engineering, Kasetsart University 26/34

Error recovery (II)

  • n time out, sender will retransmit the segment
  • this mechanism is used for error recovery

segment #i, start timer host A host B cancel timer ACK timer expires, resend #i

slide-14
SLIDE 14

Applied Network Research Group Department of Computer Engineering, Kasetsart University 27/34

Sliding window buffer

  • 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

  • ffered windows

Applied Network Research Group Department of Computer Engineering, Kasetsart University 28/34

1300… ....999

Sliding window example

  • 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 SndUna+SndWnd SndNxt

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

SndUna SndUna+SndWnd SndNxt,

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

SndUna SndUna+SndWnd SndNxt

initial send 100 bytes more 100 bytes ACK 100 bytes

slide-15
SLIDE 15

Applied Network Research Group Department of Computer Engineering, Kasetsart University 29/34

TCP in actions

  • before data could be transferred, a connection must be
  • pened

servers do passive open (listen) clients do active open (connect)

  • when it finished, the connection is closed
  • TCP has general 3 phases

connection setup phase data phase connection close phase Applied Network Research Group Department of Computer Engineering, Kasetsart University 30/34

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)

  • TCP uses 3-way handshake to establish a connection

exchange the sequence number ensures that both ends are ready and sync sequence number

connection is setup!

slide-16
SLIDE 16

Applied Network Research Group Department of Computer Engineering, Kasetsart University 31/34

Transfer phase

  • 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”

Applied Network Research Group Department of Computer Engineering, Kasetsart University 32/34

TCP Connection close

  • 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

slide-17
SLIDE 17

Applied Network Research Group Department of Computer Engineering, Kasetsart University 33/34

Open/Close mechanisms

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

host may be crashed, power off no detection if no data transfer reset segment (RST bit) is sent when detected

  • Half close - one end of connection terminated its output, but still

receiving data from the other end

  • Simultaneous open- both end perform an active open to each
  • ther
  • Simultaneous close - both end perform an active open to each
  • ther

Applied Network Research Group Department of Computer Engineering, Kasetsart University 34/34

TCP state diagram : open

CLOSED

start

appl passive opens; send nothing

LISTEN passive open

a p p l a c t i v e

  • p

e n s ; s e n d S Y N

SYN_SENT active open SYN_RCVD

got SYN; send SYN,ACK

ESTABLISHED

got SYN, ACK; send ACK g

  • t

A C K ; s e n d n

  • t

h i n g got SYN; send SYN, ACK

simultaneous open

got RST appl closes; send FIN appl closes;

  • r time-out

(normal) client transition (normal) server transition

slide-18
SLIDE 18

Applied Network Research Group Department of Computer Engineering, Kasetsart University 35/34

TCP state diagram : close

ESTABLISHED

g e t F I N , A C K ; s e n d : A C K appl close; send FIN 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

active close passive close

simultaneous close (normal) client transition (normal) server transition