Personal tools
You are here: Home Classes Fall 2004 - Spring 2005 CS 342 TCP
Navigation
Log in


Forgot your password?
« July 2008 »
Su Mo Tu We Th Fr Sa
12345
6789101112
13141516171819
20212223242526
2728293031
 
Document Actions

TCP

by admin last modified 2005-05-12 17:54

TCP


Segment format
  • source port number
  • destination port number
  • sequence number (for sliding window algorithms -- byte number)
  • ack number (for sliding window algorithms -- byte number)
  • header length
  • flag bits
  • receive window size - number of bytes a receiver is willing to accept
  • checksum
  • urgent pointer

Flag bits
  • URG - this segment contains urgent data - cause signal on receiver
  • PSH - pass data to upper layer immediately
  • ACK - ack number is valid
  • SYN - used in connection setup
  • FIN - used in connection teardown
  • RST - used in connection setup and teardown to indicate problem conditions

Connection management - setup and teardown

Setup uses a three-way handshake protocol
  1. client --> server sends SYN=1, ACK=0, meaning "request connection"
    • message contains client's sequence number (client_isn)
  2. server --> client sends SYN=1, ACK=1, meaning "connection accepted"
    • message contains server's sequence number (server_isn) and ack = client_isn+1
  3. client --> server sends SYN=0, ACK=1, meaning "ready to go"
    • sequence number = client_isn+1
    • ack number = server_isn+1


Each side chooses its initial sequence number at random (to avoid confusion after reboot).

This sequence handles various problems, like "delayed duplicates".  Suppose that host 1 sends connection request several times before getting ack, closes connection shortly.  Then ack arrives.

SYN=1,ACK=0
SYN=1,ACK=1
REJECT - host 1 knows it is not attempting connection

If any old acks show up sometime, they can be rejected because they have the wrong sequence number.

The protocol also handles the situation in which two hosts attempt connection at the same time.

Shutdown is symmetric

host 1 sends FIN to host 2 meaning "I have no more data"
host 2 sends ACK to host 1.  This closes the h1 to h2 direction, but not h2 to h1.  (There may still be data in the pipeline.)
host 2 sends FIN to host 1.
host 1 sends ACK to host 2.



TCP guarantees that everything written before closing connection will be delivered.


Some connection scenarios

Simultaneous connection

  1. A sends SYN to B, enters SENT_SYN state.  B sends SYN to A, enters SENT_SYN state.
  2. A receives SYN from B, sends ACK to B, enters SYN_RCVD state.
  3. B receives SYN from A, sends ACK to A, enters SYN_RCVD state.
  4. B receives ACK from A, enters ESTABLISHED state.
  5. A receives ACK from B, enters ESTABLISHED state.

Recovery from delayed duplicate messages


The RESET message (RST) is used to handle problems resulting from delayed duplicates, process or host termination.
  1. B receives listen call from user process, enters LISTEN state.
  2. A sends SYN to B with SEQ=100, enters SYN_SENT state.
  3. Duplicate SYN message with  SEQ=90 arrives at B.  B sends SYN,ACK=91, enters SYN_RCVD state.
  4. A receives SYN,ACK=91 message, and sees it has a bad ACK number.
  5. A sends RST message with SEQ=91 to B
  6. B receives RST message, returns to LISTEN state.
  7. SYN,SEQ=100 message arrives at B.  B sends SYN,ACK=101, enters SYN_RCVD state.
  8. A receives SYN,ACK=100, sends ACK, enters ESTABLISHED state.
  9. B receives ACK, enters ESTABLISHED state.


Q:  What would happen if A had not been trying to set up a connection when the duplicate SYN was received by B?

Q:  What happens if a delayed duplicate connection request appears at B, B responds to it, and then a delayed duplicate acknowledgment appears at B?


Recovery from host crashes

When one side of a TCP connection crashes, we have what is called a half-open connection.  The RESET message is used to resolve these cases.
  1. A and B are communicating through and established connection.  Both are in the ESTABLISHED state.
  2. A crashes, then reboots.
  3. A attempts to reestablish the connection with B.  It sends a SYN message with SEQ=400, enters SYN_SENT state.
  4. This is higher than the expected SEQ number, so B resends its last ACK, with SEQ=300.
  5. A receives the ACK without the SYN and with the wrong SEQ number, so it sends a RST message.
  6. B receives the RST, closes the connection, and enters the CLOSED state.
  7. A resends its SYN message, and the normal handshaking protocol begins.
Another way this could happen:
  1. A and B are communicating through and established connection.  Both are in the ESTABLISHED state.
  2. A crashes, then reboots.
  3. B continues to send data, sends a data packet with SEQ=100,ACK=300.
  4. A receives the message when it has no established connection, so it sends a RST message with SEQ=300.
  5. B receives the RST and closes the connection.

 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: