TCP by linzhengnd

VIEWS: 7 PAGES: 38

									Introduction to TCP

 Chia-Tai Tsai
 tai@cis.nctu.edu.tw
Transmission Control Protocol (TCP)

   Reliable
       Acknowledgement
       Retransmission
       Checksum
Transmission Control Protocol (TCP) cont.

   Connection oriented
       (IP, port)
   stream
Sequence, Acknowledge
Sliding Window
TCP Header Format
Code Bits
   FIN
       結束連線
                  5     4     3     2     1    0
   SYN
       建立連線     URG   ACK   PSH   RST   SYN   FIN
   RST
       重置連線
   PSH
       封包立即傳送
   ACK
       回應上一次收到的封包
   UGE
       請接收端立即處理此封包
建立連線
   3-way handshake
       確定雙方皆能收送資料
       允許二方同意彼此的起
        始編號
結束連線
TCP Timers
Introduction
   The 7 Timers for each Connection
       Connection-Establishment Timer
            Establish a new connection.
            If a response isn’t received within 75 seconds, the
             connection establishment is aborted.


       Retransmission Timer
            Based on Round-Trip Time (RTT).
            TCP sends data.
            When this timer expires, TCP retransmit the data.
Introduction cont.
    Delay ACK Timer
         Need not be acknowledged immediately.
         TCP waits up to 200 ms.
         Piggybacking


    Persist Timer
         Based on RTT
         Triggered when a null window is advertised
         If timer expires, sender issues a probe
           (between 5 and 60 s, never gives up)
Introduction cont.
    Keepalive Timer
         socket option SO_KEEPALIVE.
         Tests if the other end is still up and running
         Expires after 2 hours

    FIN_WAIT_2 Timer
         FIN_WAIT_1 -> FIN_WAIT_2
         Avoid a connection in the FIN_WAIT_2 state forever.
Introduction cont.
       2MSL Timer (TIME_WAIT Timer)
            MSL (Maximum Segment Life) 30s to 4 min
            Triggered when connection (client) enters TIME_WAIT
             state
            During 2MSL, the socket pair cannot be reused. (packets
             arriving during this state are discarded)


   Timer Function
       Fast timer
            Triggered every 200 ms
            Delay ACK Timer
       Slow timer
            Triggered every 500 ms
Implements of the 7 TCP timers
tcp_canceltimers Function
   tcp_timer.c
   Triggered when enters TIME_WAIT
    state.
   All 4 timers counters are set to 0.
tcp_fasttime Function
   tcp_timer.c
   Delay ACK Timer
   If TF_DELACK flag is set, it is cleared
    and TF_ACKNOW flag is set instead.
tcp_slowtime Function
   tcp_timer.c
   Handle the other 6 Timers
       Connection establishment、retransmission、
        persist、keepalive、FIN_WAIT_2、2MSL
   Check each timer counter in all TCPCB
   Check if TCPCB has been deleted
tcp_slowtime Function cont.
   Count idle time
       Keepalive
       FIN_WAIT_2
   Increment RTT counter
   Increment RFC 1323 timestamp value
       tcp_now
tcp_timers Function
   tcp_timer.c
   Called by TCP’s PRU_SLOWTIMO
    request
tcp_timers Function cont.
   Case TCPT_2MSL
    (FIN_WAIT_2 and 2MSL Timers)
       2MSL Timers
tcp_timers Function cont.
    FIN_WAIT_2 timer
tcp_timers Function cont.
   Case TCPT_PERSIST (Persist Timer)
       Force window probe segment
       Time line of persist time
tcp_timers Function cont.
   Case TCPT_KEEP (Connection
    Establishment and Keepalive Timers)
       Connection establishment timer and
        retransmission timer after SYN is sent
tcp_timers Function cont.
    Keepalive timer
         Expired after 2 hours of idle time
         Drop connection who no response
         Send a keepalive probe
         Reset keepalive timer
tcp_xmit_timer Function
   tcp_input.c
   rtt is the RTT measurement to be applied
       Timestamp option (tcp_now)
       RTT counter (t_rtt)
   Exponential backoff array
       {1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64}
tcp_xmit_timer Function cont.
   Update smoothed estimators and RTO
        srtt  srtt  g  delta
        8  srtt  8  srtt  delta
        t _ srtt  t _ srtt  delta


        rtt var  rtt var h delta  rtt var 
                                             t _ rtt var
        t _ rtt var  t _ rtt var delta 
                                                  4

        RTO  srtt  4  rtt var
              t _ srtt
        RTO            t _ rtt var
                 8
Retransmission Timeout
(tcp_timers Function cont.)
   tcp_timer.c
Socket Data Structure

								
To top