Docstoc

TCP

Document Sample
TCP Powered By Docstoc
					  TCP




8/15/2012   1
TCP Adaptive Retransmission
Algorithm - Original
      Theory
           Estimate RTT
           Multiply by 2 to allow for variations
      Practice
           Use exponential moving average (A = 0.1 to 0.2)
           Estimate = (A) * measurement + (1- A) * estimate
      Problem
           Did not handle variations well
           Ambiguity for retransmitted packets
               Was ACK in response to first, second, etc transmission?



8/15/2012                                                                 2
TCP Adaptive Retransmission
Algorithm – Karn-Partridge
      Algorithm
           Exclude retransmitted packets from RTT
            estimate
           For each retransmission
               Double RTT estimate
               Exponential backoff from congestion
      Problem
           Still did not handle variations well
           Did not solve network congestion problems as
            well as desired

8/15/2012                                                  3
TCP Adaptive Retransmission
Algorithm – Jacobson
      Algorithm
           Estimate variance of RTT
               Calculate mean interpacket RTT deviation to approximate variance
               Use second exponential moving average
               Deviation = (B) * |RTT_Estimate – Measurement| + (1–B) * deviation
               B = 0.25, A = 0.125 for RTT_estimate
           Use variance estimate as component of RTT estimate
               Next_RTT = RTT_Estimate + 4 * Deviation
           Protects against high jitter
      Notes
           Algorithm is only as good as the granularity of the clock
           Accurate timeout mechanism is important for congestion control




8/15/2012                                                                        4
TCP Connection
Establishment
      3-Way Handshake
           Sequence Numbers                  Client                     Server
               J,K                                                         listen
           Message Types
               Synchronize (SYN)
               Acknowledge (ACK)
           Passive Open
               Server listens for
                connection from client
           Active Open
               Client initiates connection
                                                       Time flows down
                to server
8/15/2012                                                                            5
TCP Connection Termination

      Message Types
                                   Client                     Server
           Finished (FIN)
           Acknowledge (ACK)
      Active Close
           Sends no more data
      Passive close
           Accepts no more data

                                            Time flows down

8/15/2012                                                              6
   TCP Connection Management (cont)



                             TCP server
                             lifecycle




TCP client
lifecycle




    8/15/2012                         7
 TCP State Descriptions
CLOSED        Disconnected
LISTEN        Waiting for incoming connection
SYN_RCVD      Connection request received
SYN_SENT      Connection request sent
ESTABLISHED   Connection ready for data transport
CLOSE_WAIT    Connection closed by peer
LAST_ACK      Connection closed by peer, closed locally, await ACK
FIN_WAIT_1    Connection closed locally
FIN_WAIT_2    Connection closed locally and ACK’d
CLOSING       Connection closed by both sides simultaneously
TIME_WAIT     Wait for network to discard related packets
 8/15/2012                                                           8
TCP State Transition Diagram
                                                                        Active
                                     CLOSED
                                                                      open/SYN
                   Passive open         Close             Close
            SYN/SYN + ACK            LISTEN
                                                Send/SYN
     SYN_RCVD                                                SYN_SENT
                      ACK      SYN/SYN + ACK
                   Close/ACK                      SYN + ACK/ACK
Close/FIN                       ESTABLISHED
                                                FIN/ACK
     FIN_WAIT_1            FIN/ACK                          CLOSE_WAIT
       ACK                           CLOSING          Close/FIN
     FIN_WAIT_2       FIN +                                   LAST_ACK
                     ACK/ACK             ACK
                                  TIME_WAIT                          ACK
                 FIN/ACK                        Timeout
                                                                  CLOSED

8/15/2012                                                                        9
TCP State Transition Diagram
      Questions
           State transitions
               Describe the path taken by a server under normal
                conditions
               Describe the path taken by a client under normal
                conditions
               Describe the path taken assuming the client closes the
                connection first
           TIME_WAIT state
               What purpose does this state serve
               Prove that at least one side of a connection enters this
                state
               Explain how both sides might enter this state

8/15/2012                                                              10
     TCP State Transition Diagram
                                                                       Active
                                        CLOSED                       open/SYN
                         Passive open      Close          Close
                  SYN/SYN + ACK         LISTEN
                                                   Send/SYN
           SYN_RCVD                                           SYN_SENT
                            ACK    SYN/SYN + ACK
                                                     SYN + ACK/ACK
                                    ESTABLISHED


      TCP A                                                     TCP B
1.   CLOSED                                                     LISTEN
2.   SYN-SENT           --> <SEQ=100><CTL=SYN>      -->         SYN-RECEIVED
3.   ESTABLISHED       <-- <SEQ=300><ACK=101><CTL=SYN,ACK> <-- SYN-RECEIVED
4.   ESTABLISHED       --> <SEQ=101><ACK=301><CTL=ACK>   -->    ESTABLISHED
5.   ESTABLISHED       --> <SEQ=101><ACK=301><CTL=ACK><DATA> --> ESTABLISHED



      8/15/2012                                                                 11
TCP State Transition Diagram
                                                                        Active
                                     CLOSED                           open/SYN
                   Passive open         Close             Close
            SYN/SYN + ACK            LISTEN
                                                Send/SYN
     SYN_RCVD                                                SYN_SENT
                      ACK      SYN/SYN + ACK
                   Close/FIN                      SYN + ACK/ACK
Close/FIN                       ESTABLISHED
                                                FIN/ACK
     FIN_WAIT_1            FIN/ACK                          CLOSE_WAIT
       ACK                           CLOSING          Close/FIN
     FIN_WAIT_2       FIN +                                   LAST_ACK
                     ACK/ACK             ACK
                                  TIME_WAIT                          ACK
                 FIN/ACK                        Timeout
                                                                  CLOSED

8/15/2012                                                                        12
TCP Sliding Window Protocol
      Sequence numbers
           Indices into byte stream
      ACK sequence number
           Actually next byte expected as opposed to last byte received
      Advertised window
           Enables dynamic receive window size
      Receive buffers
           Data ready for delivery to application until requested
           Out-of-order data out to maximum buffer capacity
      Sender buffers
           Unacknowledged data
           Unsent data out to maximum buffer capacity



8/15/2012                                                                  13
TCP Sliding Window Protocol
– Sender Side
    LastByteAcked <= LastByteSent
    LastByteSent <= LastByteWritten
    Buffer bytes between LastByteAcked and LastByteWritten

                     Maximum buffer size

             Advertised window




                                           Data available, but
                                            outside window

 First unacknowledged byte             Last byte sent
8/15/2012                                                        14
TCP Sliding Window Protocol
– Receiver Side
      LastByteRead < NextByteExpected
      NextByteExpected <= LastByteRcvd + 1
      Buffer bytes between NextByteRead and LastByteRcvd

                        Maximum buffer size

                                    Advertised window




                                 Buffered, out-of-order data
                        Next byte expected (ACK value)
    Next byte to be read by application
8/15/2012                                                      15
TCP ACK generation - 1
                       Maximum buffer size

                                Available buffer size




                      Next byte expected (ACK value)
Next byte to be read by application


    Arrival of in-order segment with expected seq #. All
     data up to expected seq # already ACKed
           Delayed ACK. Wait up to 500ms for next segment.
8/15/2012                                                     16
TCP ACK generation - 2
                       Maximum buffer size

                                 Available buffer size




                       Next byte expected (ACK value)
Next byte to be read by application


    Arrival of in-order segment with expected seq #. One
     other segment has ACK pending
           Immediately send single cumulative ACK, ACKing both in-
            order segments
8/15/2012                                                             17
TCP ACK generation - 3
                       Maximum buffer size

                                 Available buffer size




                       Next byte expected (ACK value)
Next byte to be read by application


    Arrival of out-of-order segment higher-than-expect
     seq. # Gap detected
           Immediately send duplicate ACK, indicating seq. # of next
            expected byte
8/15/2012                                                               18
TCP ACK generation - 4
                        Maximum buffer size

                                   Available buffer size




                        Next byte expected (ACK value)
Next byte to be read by application

    Arrival of segment that partially or completely fills gap
           Immediate send ACK, provided that segment starts at lower end of
            gap

8/15/2012                                                                 19
  TCP ACK generation                        [RFC 1122, RFC
  2581]

Event at Receiver                   TCP Receiver action
Arrival of in-order segment with    Delayed ACK. Wait up to 500ms
expected seq #. All data up to      for next segment. If no next segment,
expected seq # already ACKed        send ACK

Arrival of in-order segment with    Immediately send single cumulative
expected seq #. One other           ACK, ACKing both in-order segments
segment has ACK pending

Arrival of out-of-order segment     Immediately send duplicate ACK,
higher-than-expect seq. # .         indicating seq. # of next expected byte
Gap detected

Arrival of segment that             Immediate send ACK, provided that
partially or completely fills gap   segment starts at lower end of gap
  8/15/2012                                                                 20
Fast Retransmit
                                         If sender receives 3
      What’s the problem                 ACKs for the same
       with time-out?
           time-out period often         data, it supposes
            relatively long               that segment after
      Detect lost segments               ACKed data was
       via duplicate ACKs.
                                          lost:
           Sender often sends
            many segments back-              fast retransmit:
            to-back                           resend segment
           If segment is lost, there         before timer expires
            will likely be many
            duplicate ACKs.              Why 3?
8/15/2012                                                            21
     Fast retransmit algorithm:
   event: ACK received, with ACK field value of y
            if (y > SendBase) {
                  SendBase = y
                  if (there are currently not-yet-acknowledged segments)
                        start timer
                }
            else {
                    increment count of dup ACKs received for y
                    if (count of dup ACKs received for y = 3) {
                         resend segment with sequence number y
                     }


a duplicate ACK for             fast retransmit
already ACKed segment

     8/15/2012                                                             22
A 4th situation?

      Receiver side
                    Maximum buffer size

                               Available buffer size       What if?




                             Buffered, out-of-order data
                    Next byte expected (ACK value)
Next byte to be read by application


8/15/2012                                                     23
       TCP Flow Control
                   Sender
                               Maximum buffer size
                        Sliding window




            First unacknowledged byte                  Data available, but
                                         Last byte sent outside window
               Receiver
                                Maximum buffer size
                                                                             Avoid?
                                          Available buffer size



                                         Buffered, out-of-order data
       8/15/2012                                                              24
Next byte to be read
  by application            Next byte expected (ACK value)
Flow Control vs. Congestion
Control
      Flow control
           Preventing senders from overrunning the
            capacity of the receivers
      Congestion control
           Preventing too much data from being injected
            into the network, causing switches or links to
            become overloaded

      TCP provides both
           flow control based on advertised window
           congestion control discussed later in class
8/15/2012                                                    25
TCP Flow Control
      Receiving side
           Receive buffer size = MaxRcvBuffer
           LastByteRcvd - LastByteRead < = MaxRcvBuffer
           AdvertisedWindow = MaxRcvBuffer - (NextByteExpected -
            NextByteRead)
               Shrinks as data arrives and
               Grows as the application consumes data
      Sending side
           Send buffer size = MaxSendBuffer
           LastByteSent - LastByteAcked < = AdvertisedWindow
           EffectiveWindow = AdvertisedWindow - (LastByteSent -
            LastByteAcked)
               EffectiveWindow > 0 to send data
           LastByteWritten - LastByteAcked < = MaxSendBuffer
           block sender if (LastByteWritten - LastByteAcked) + y
            > MaxSenderBuffer


8/15/2012                                                          26
TCP Flow Control
      Problem: Slow receiver application
           Advertised window goes to 0
           Sender cannot send more data
           Non-data packets used to update window
           Receiver may not spontaneously generate update or
            update may be lost
      Solution
           Sender periodically sends 1-byte segment, ignoring
            advertised window of 0
           Eventually window opens
           Sender learns of opening from next ACK of 1-byte
            segment

8/15/2012                                                        27
TCP Flow Control
      Problem: Application delivers tiny pieces of data to
       TCP
           Example: telnet in character mode
           Each piece sent as a segment, returned as ACK
           Very inefficient
      Solution
           Delay transmission to accumulate more data
           Nagle’s algorithm
               Send first piece of data
               Accumulate data until first piece ACK’d
               Send accumulated data and restart accumulation
               Not ideal for some traffic (e.g. mouse motion)

8/15/2012                                                        28
TCP Flow Control
      Problem: Slow application reads data in tiny
       pieces
           Receiver advertises tiny window
           Sender fills tiny window
           Known as silly window syndrome
      Solution
           Advertise window opening only when MSS or
            1/2 of buffer is available
           Sender delays sending until window is MSS or
            1/2 of receiver’s buffer (estimated)
8/15/2012                                                  29
TCP Bit Allocation Limitations

      Sequence numbers vs. packet lifetime
           Assumed that IP packets live less than 60
            seconds
           Can we send 232 bytes in 60 seconds?
           Less than an STS-12 line
      Advertised window vs. delay-bandwidth
           Only 16 bits for advertised window
           Cross-country RTT = 100 ms
           Adequate for only 5.24 Mbps!
8/15/2012                                               30
  TCP Sequence Numbers –
  32-bit

Bandwidth     Speed      Time until wrap around
T1            1.5 Mbps   6.4 hours
Ethernet      10 Mbps    57 minutes
T3            45 Mbps    13 minutes
FDDI          100 Mbps   6 minutes
STS-3         155 Mbps   4 minutes
STS-12        622 Mbps   55 seconds
STS-24        1.2 Gbps   28 seconds
  8/15/2012                                       31
  TCP Advertised Window –
  16-bit

Bandwidth     Speed      Max RTT
T1            1.5 Mbps   350 ms
Ethernet      10 Mbps    52.4 ms
T3            45 Mbps    11.6 ms
FDDI          100 Mbps   5.2 ms
STS-3         155 Mbps   3.4 ms
STS-12        622 Mbps   843 µs
STS-24        1.2 Gbps   437 µs
  8/15/2012                        32

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:3
posted:8/14/2012
language:English
pages:32