30
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

Embed Size (px)

Citation preview

Page 1: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

TCP : Transmission Control Protocol

Computer Network SystemSirak Kaewjamnong

Page 2: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

2

Agenda

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

Page 3: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

3

TCP Encapsulation

• With Ethernet frame

Ethernet headerIP headerTCP header data

Segment

Page 4: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 5: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

5

TCP

TCP performs typical transport layer function

• passed data to relevant application-level services

• error recovery• flow control data stream (avoid

buffer overflow)

Page 6: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

6

TCP Properties

• Byte stream with full duplex transferring

• adaptive to LAN/WAN• congestion avoidance and

control

Page 7: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 8: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 9: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 10: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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)

Page 11: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 12: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 13: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 14: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 15: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 16: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 17: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 18: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

18

TCP State Diagram : Open

Page 19: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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”

Page 20: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 21: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

21

TCP State Diagram : Close

Page 22: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 23: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 24: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 25: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 26: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 27: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 28: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 29: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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

Page 30: TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong

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