TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

Preview:

Citation preview

TCP : Transmission Control Protocol

Computer Network SystemSirak Kaewjamnong

2

Agenda

• Service provide by TCP• TCP format• How TCP reliable• TCP connection• TCP state

3

TCP Encapsulation

• With Ethernet frame

Ethernet headerIP headerTCP header data

Segment

4

TCP and UDP Services

TCP : Transmission Control Protocol• RFC 793• connection-oriented service• full duplex• reliable service by adding more

overhead to manage acknowledgement, flow control and timer

5

TCP

TCP performs typical transport layer function

• passed data to relevant application-level services

• error recovery• flow control data stream (avoid

buffer overflow)

6

TCP Properties

• Byte stream with full duplex transferring

• adaptive to LAN/WAN• congestion avoidance and

control

7

TCP Data Stream

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

• Stream of octets passed between sender and receiver

ApplicationSend

Receive

ApplicationReceiveSend

8

Ports

• Port : A 16 bits address allocated for the most common application level service

• UDP and TCP use port addressing to deliver information to applications

• Service are known by port number–FTP 20, TELNET 23, SMTP 25, HTTP 80

9

Ports

• Port numbers are generally allocated by

•0 not used•1- 255 Reserves port to well known service

•256 - 1023 Other reserve port•1024 - 65535 user defined server ports

• UNIX store general used ports in /etc/service

10

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 achieved by•Error detection and correction (due to segment corrupted)

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

•Resequencing (IP and deliver datagrams in any order)

•Removing duplicate segments (due to error recovery mechanism used by TCP)

11

How TCP handles Reliability• Using sequence number to identify data• positive acknowledgments of data

received in the correct sequence• retransmission of segments which have

not been acknowledgment within a variable time limit

• Let’s see these mechanisms in TCP header

12

TCP Header

0 15 16 31

Source Port : 16 Destination Port : 16

Acknowledgment Number : 32Window Size : 16

Urgent Pointer : 16Checksum : 16Option and Padding

Sequence Number : 32

Data offs :4Resv:6Flag:6

13

TCP Header Details (I)

• Source, destination port: 16, 16 - identify application at ends of 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

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

14

TCP Header Details (II)

• Reserve : 6 - not used• Flag : 6

•URG : validity of urgent pointer field•ACK : validity of acknowledgment field•PSH : push request (pass segment to application layer immediately)

•RST : reset the connection•SYN : initial synchronization•FIN : send at end of byte stream

15

TCP Header Details (III)

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

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

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

• options : - variable length option e.g. max segment size tells destination node

16

TCP in Action• Before data could be transferred, a

connection must be opened•Server do passive open (listen)•Client do active open (connect)

• When it finished, the connection is closed

• TCP has general 3 phases•Connection setup phase•Data phase•Connection close phase

17

TCP Connection EstablishmentTCP uses 3-ways handshake to establish a

connection • Exchange the sequence number

• Ensures that both ends are ready and sync sequence number

Host A Host B1. send SYN (seq = x)

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

3. send ACK (ack = y+1)Connection is setup

18

TCP State Diagram : Open

19

TCP Transfer Phase

• Simple example with terminal connection such as telnet. Host echoes back each received character

Host A Host B1. SEQ = 92, ACK =109 Data = “W”

2. SEQ = 109, ACK = 93, Data = “W”

3. SEQ = 93, ACK =110 Data = “ A”

Host echoes back “W”

20

TCP Connection Close

• Use FIN flag to close connection

Host A Host B1. FIN_WAIT_1Seq = x, 2. CLOASE_WAIT,

Ack = x +13.FIN_WAIT_24. LAST_ACK, Seq = y

5.TIME_WAITAck = y+1 Connection is close

21

TCP State Diagram : Close

22

Open/Close Mechanisms• Haft open: one end has closed,

aborted without the knowledge of 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 other

• Simultaneous close: both end perform an active close to each other

23

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. fast 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

24

Sliding Window Flow Control

• Receiver advertises it’s window size in acknowledgments

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

25

Sliding Window : Small Window Size

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

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

Sender Receiver

Window size = 1Send 1

Send 2

Receive 1Ack 2

Receive 2Ack 3

26

Sliding Window : Larger Window Size

• 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

Sender Receiver

Send 1Send 2Send 3

Receive ACK 4Send 4Send 5Send 6

Receive 1Receive 2Receive 3Send ACK 4

Receive 4Receive 5Receive 6

27

Sliding Window Buffer

• Sender groups its packet to be transmitted with window indication

… 999 1200 ...1000 …. 10991100…1199

Sent and ACK

Sent and not ACK

Can Send ASAP

Can’t Send now

SndWndOffer window

SndUna SndNxtSndUna + SndWnd

28

TCP in Action

Movement of the right and left edges of the window

… 999 1200 ...1000 …. 10991100…1199

… 999 1200 ...1000 …. 10991100…1199

… 999 1200 ...1000 …. 10991100…1199

… 999 1200 ... 12991000 …. 10991100…1199

Initial

Send 100 bytes

More 100 bytes

ACK 100 bytes

SndUna,SndNxt SndUna + SndWnd

SndUna + SndWnd

SndNxt, SndUna + SndWnd

SndUna SndNxt

SndUna

SndUna SndNxtSndUna + SndWnd

29

Error Recovery (I)

• Receiver had to send ACK with sequence number

• Sender reset timer when receives ACK

Host A Host B

Segment #i,Start timer

ACK i+1

Reset timer

30

Error Recovery (II)

• On time out, sender will retransmit the segment

• This mechanism is used for error recovery

Host A Host B

Segment #i, Start timer

ACK i+ 1Reset timer

Timer expires, resend #i

Recommended