Docsity

The TCP State Machine - Lecture Slides | ECE 573, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
TCP, Lecture 2
Internet Protocols
CSC / ECE 573
Fall, 2005
N. C. State University
copyright 2005 Douglas S. Reeves 2
Today’s Lecture
I. The TCP “State Machine” Diagram
II. TCP Timers
III. Interactive (i.e., low rate) data transfer
IV. Flow control (window size advertisements)
Project Part I posted
HW3 will be posted today
copyright 2005 Douglas S. Reeves 3
Project Choices
• Implement TCP at the application layer
• Implement the routing protocol RIPv2 at the the application
layer.
• Implement a new protocol from either Infocom or
SIGCOMM
• Implement interplanetary TCP
• Implement a DNS server
• Implement IPSec Authentication Header
• Implement basic VoIP
• Implement another Internet protocol
THE TCP STATE MACHINE
copyright 2005 Douglas S. Reeves 5
Interpreting State Machine Diagrams
• Each shows the TCP state machine for one
endpoint of a connection
– other endpoint may be in a different state
• The transitions between states (arcs) are labeled
with…
– the input event that causes the transition
– the output signal or message that will be sent to the
other endpoint
copyright 2005 Douglas S. Reeves 6
States of a TCP Connection
CLOSED
LISTENING
SYN_RCVD SYN_SENT
ESTABLISHED CLOSE_WAIT
LAST_ACK
FIN_WAIT_1 CLOSING
FIN_WAIT_2 TIME_WAIT
Connection is being established
There is no connection
Server is closing (passive close)
Client is closing (active close)
Connection is established, data
can be transferred
pf3
pf4
pf5

Partial preview of the text

Download The TCP State Machine - Lecture Slides | ECE 573 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

TCP, Lecture 2

Internet Protocols

CSC / ECE 573

Fall, 2005

N. C. State University

copyright 2005 Douglas S. Reeves 2

Today’s Lecture

I. The TCP “State Machine” Diagram

II. TCP Timers

III. Interactive (i.e., low rate) data transfer

IV. Flow control (window size advertisements)

Project Part I posted

HW3 will be posted today

copyright 2005 Douglas S. Reeves 3

Project Choices

• Implement TCP at the application layer

• Implement the routing protocol RIPv2 at the the application

layer.

• Implement a new protocol from either Infocom or

SIGCOMM

• Implement interplanetary TCP

• Implement a DNS server

• Implement IPSec Authentication Header

• Implement basic VoIP

• Implement another Internet protocol

THE TCP STATE MACHINE

copyright 2005 Douglas S. Reeves 5

Interpreting State Machine Diagrams

• Each shows the TCP state machine for one

endpoint of a connection

– other endpoint may be in a different state

• The transitions between states (arcs) are labeled

with…

– the input event that causes the transition

– the output signal or message that will be sent to the

other endpoint

copyright 2005 Douglas S. Reeves 6

States of a TCP Connection

CLOSED

LISTENING

SYN_RCVD SYN_SENT

ESTABLISHED CLOSE_WAIT

FIN_WAIT_1 CLOSING LAST_ACK

FIN_WAIT_2 TIME_WAIT

Connection is being established

There is no connection

Server is closing (passive close)

Client is closing (active close)

Connection is established, data

can be transferred

copyright 2005 Douglas S. Reeves 7

Complete State Diagram

CLOSED

LISTENING

SYN_RCVD SYN_SENT

ESTABLISHED CLOSE_WAIT

LAST_ACK

FIN_WAIT_1 CLOSING

FIN_WAIT_2 TIME_WAIT

Application: active open

Send: SYN

Recv

: SYN,ACK

Send: ACK

Application: close

Send: FIN

Recv: ACK

Send: (nothing)

Recv: FIN

Send: ACK

2MSL timeout occurs

Send: (nothing)

Data being transferred

Appl: passive

open

Send: (nothing)

Recv

: SYN

Send:SYN,ACK

Recv

: ACK

Send: (nothing)

Recv: FIN

Send: ACK

Application: close

Send: FIN

Recv: ACK

Send: (nothing)

Data being transferred

Recv

: RST

Send: (nothing)

Appl: close or

timeout

Recv: SYN

Send: SYN,ACK

Appl: close

Send: FIN

Recv: FIN

Send: ACK

Recv: ACK

Send: (nothing)

Recv

: FIN,ACK

Send: ACK

copyright 2005 Douglas S. Reeves 8

Normal Client Sequence

CLOSED

SYN_SENT

Application: active open

Send: SYN

Application: close

Send: FIN

FIN_WAIT_

FIN_WAIT_

Recv: ACK

Send: (nothing)

TIME_WAIT

Recv: FIN

Send: ACK

2MSL timeout occurs

Send: (nothing)

Timeout problems

ESTABLISHED

Recv

: SYN,ACK

Send: ACK

Data being transferred

copyright 2005 Douglas S. Reeves 9

Normal Server Sequence

CLOSED

LISTENING

Appl: passive open

Send: (nothing)

SYN_RCVD

Recv

: SYN

Send:SYN,ACK

CLOSE_WAIT

Recv: FIN

Send: ACK

LAST_ACK

Application: close

Send: FIN

Recv: ACK

Send: (nothing)

ESTABLISHED

Recv

: ACK

Send: (nothing)

Data being transferred

copyright 2005 Douglas S. Reeves 10

All Together, Now

CLOSED

SYN_SEN

T

Application: active

open

Send: SYN

Application:

close

Send: FIN

FIN_WAIT_

FIN_WAIT_

Recv: ACK

Send:

(nothing)

TIME_WAIT

Recv: FIN

Send: ACK

2MSL timeout occurs

Send: (nothing)

Timeout

problems

ESTABLISHED

Recv

:

SYN,ACK

Send: ACK

Data being

transferred

CLOSED

LISTENING

Appl: passive

open

Send: (nothing)

SYN_RCVD

Recv

: SYN

Send:SYN,AC

K

CLOSE_WAIT

Recv:

FIN

Send:

ACK

LAST_ACK

Application:

close

Send: FIN

ESTABLISHED

Recv

Send:: ACK

(nothing)

Data being

transferred

CLIENT SERVER

copyright 2005 Douglas S. Reeves 11

Server States When Client Resets

Connection Before Establishment Complete

CLOSED

LISTENING

SYN_RCVD

Appl: passive

open

Send: (nothing)

Recv

: SYN

Send:SYN,ACK

Recv

: RST

Send: (nothing)

copyright 2005 Douglas S. Reeves 12

Simultaneous Active Opens

  • A connects with B, B connects with A at same time

(pass each other in the network)

  • only one connection will be established!
  • compare with: simultaneous telephone calls

SYN_SENT

SYN_RCVD

ESTABLISHED

SYN_SENT

SYN_RCVD

ESTABLISHED

SEQ=

x , SYN

SEQ=y, SYN

SYN,ACK=y+

SYN,ACK=x+

A B

State State

INTERACTIVE DATA TRANSFER

copyright 2005 Douglas S. Reeves 20

Character-by-Character Transfer (Telnet)

Send ‘d’

Ack ‘d’, echo ‘d’

Ack echo of ‘d’

Send ‘a’

Ack ‘a’, echo ‘a’

Ack echo of ‘a’

client

server

t

t

t

t

ack

ack 2056

t

t

t

t

t

t

ack

ack 2057

t

t

.

.

.

copyright 2005 Douglas S. Reeves 21

Performance?

  • Each data packet has 1 character
    • 40 bytes of overhead (IP+TCP), 1 byte of payload!
  • Some TCP segments are just ACKs
    • 40 bytes of overhead, no payload!
  • Improvements possible? Does it matter?

copyright 2005 Douglas S. Reeves 22

Improvement #1: Delayed ACKs

  • Purpose: by waiting, there may be more data to

send

  • i.e., ACK can be “piggybacked” with data
  • Maximum amount of time to wait is implementation

dependent

  • Shorter better? Longer better?
  • (ex.: Linux= min of 40ms, max of 200ms)
  • Good: reduces overhead
  • any drawbacks???

copyright 2005 Douglas S. Reeves 23

Delayed ACK Example

Send ‘d’

Ack ‘d’, echo ‘d’

Ack echo of ‘d’,

Send ‘a’

Ack ‘a’, echo ‘a’

Ack echo of ‘a’,

Send ‘t’

A B

t

t

t

t

ack

ack 2056

t

t

t

t

1), ack

1), ack 2057

t

t

extra delay

extra delay

copyright 2005 Douglas S. Reeves 24

Improvement #2: “Nagle’s Algorithm”

(RFC 896)

  • Idea: “accumulate” data before sending a data

segment

  • When application generates data slowly, send the

first byte and buffer the rest until…

  1. a maximum sized segment is filled, or
  2. an ACK is received, or
  3. half the current window size is filled

copyright 2005 Douglas S. Reeves 25

Nagle’s Algorithm (cont’d)

  • Benefits
    • a self-clocking algorithm (i.e., no timers needed)
    • useful for paths with long round-trip times
  • Effect on throughput …
    • for low data rate applications?
    • for high data rate applications?
  • Any drawbacks?

copyright 2005 Douglas S. Reeves 26

Example

Send ‘d’

Ack ‘d’, echo ‘d’

Ack echo of ‘d’,

Send ‘a’, ‘t’, ‘e’

Accumulate ‘a’

Accumulate ‘t’

Accumulate ‘e’

A

B

t

t

t

t

ack

ack 2056

t

t

.

.

.

FLOW CONTROL AND

OPTIMAL WINDOW SIZES

copyright 2005 Douglas S. Reeves 28

Flow Control in TCP

  • Flow control : making sure the sender doesn’t

overrun the receiver’s buffer

  • buffer contains data accepted from TCP, not yet

processed by application

  • Each ACK from receiver carries a window

advertisement ( Window Size)

  • of additional bytes the sender is authorized to send

before it must wait for an acknowledgment

copyright 2005 Douglas S. Reeves 29

Sliding Window, Again

S sends bytes

R Acks bytes up through

3, allows 5 bytes beyond

that to be sent

S sends bytes

R Acks bytes up through

2, allows 3 bytes beyond

that to be sent

S sends bytes

R allows 3 bytes to be

sent

copyright 2005 Douglas S. Reeves 30

Sliding Window, Again (cont’d)

S sends bytes

R Acks bytes up through

6, allows 7 bytes beyond

that to be sent

S sends bytes

R Acks bytes up through

6, allows 5 bytes beyond

that to be sent

copyright 2005 Douglas S. Reeves 37

Other Examples

5 KB

(40 Kb)

5 ms

(.005 s)

1000 KB

(8000 Kb)

6.25 MB

(50 Mb)

500 ms

(.5 s)

12.5 MB/s

(100 Mb/s)

Receiver BW RTT Window Size

copyright 2005 Douglas S. Reeves 38

Summary

The state diagram captures all the behavior of

connection state

The 2MSL timer and long sequence numbers

help avoid confusion between independent

connections

Delayed ACKs and Nagle’s algorithm improve the

efficiency of low-data-rate, high-RTT transfers

copyright 2005 Douglas S. Reeves 39

Summary (cont’d)

  1. The receiver limits the sending rate through

window advertisements

 the sliding window size can change over time

  1. the optimal window size is based on the network

delay-receiver bandwidth product

copyright 2005 Douglas S. Reeves 40

Next Lecture

  • TCP, lecture 3