Tcp Extra

download Tcp Extra

of 17

Transcript of Tcp Extra

  • 8/17/2019 Tcp Extra

    1/17

    1

    The TCP Protocol

    • Connection-oriented, point-to-point protocol:– Connection establishment and teardown phases

    – ‘Phone-like’ circuit abstraction (application-layer iew!

    – "ne sender, one receier

    – Called a #reliable byte stream$ protocol– %eneral purpose (&or any network enironment!

    • "ri'inally optimied &or certain kinds o& trans&er:– )elnet (interactie remote lo'in!

    – *)P (lon', slow trans&ers!

    – +eb is like neither o& these

  • 8/17/2019 Tcp Extra

    2/17

    TCP Protocol (cont)

    • Proides a reliable, in-order, byte stream abstraction:– .ecoer lost packets and detect/drop duplicates

    – 0etect and drop corrupted packets– Presere order in byte stream, no #messa'e boundaries$– *ull-duple: bi-directional data &low in same connection

    • *low and con'estion control:

    – *low control: sender will not oerwhelm receier– Con'estion control: sender will not oerwhelm the network– 2lidin' window &low control– 2end and receie bu&&ers– Con'estion control done ia adaptie &low control window sie

    socket

    layer TCP

    send buffer 

    application

    writes data

    TCP

    receive buffer 

    socket

    layer 

    application

    reads data

    data segment

     ACK segment

  • 8/17/2019 Tcp Extra

    3/17

    3

    The TCP Header

    *ields enable the &ollowin':

    • 4ni5uely identi&yin' aconnection(6-tuple o& client/serer 7P

    address and portnumbers!

    • 7denti&yin' a byte ran'ewithin that connection

    • Checksum alue to detectcorruption

    • *la's to identi&y protocol

    state transitions (289,*79, .2)!

    • 7n&ormin' other side o& your state (C;!

    source port < dest port <

    3 bits

    application

    data(ariable len'th!

    se5uence number

    acknowled'ement number

    rcr window sie

    ptr ur'ent datachecksum

    *2.P4headlen

    notused

    "ptions (ariable len'th!

  • 8/17/2019 Tcp Extra

    4/17

    6

    Establishing a TCP Connection

    • Client sends 289 withinitial se5uence number(729 = >!

    • 2erer responds with itsown 289 w/se5 number

    8 and C; o& client 729with >?1 (net epectedbyte!

    • Client C;s serer@s729 with 8?1

    • )he ‘3-way handshake’• >, 8 randomly chosen

    • ll modulo 3-bitarithmetic

    client

    S Y N  (  ! 

    serer

     S Y N  (  Y !  "

      A C K  (   " #

     !

     AC K  ( Y " #! 

    connect(!listen(!port AB

    accept(!

    read(!

    time

  • 8/17/2019 Tcp Extra

    5/17

    Sending Data

    • 2ender )CP passes se'ments to 7P to transmit:

    – ;eeps a copy in bu&&er at send side in case o& loss– Called a #reliable byte stream$ protocol

    – 2ender must obey receier adertised window

    • .eceier sends acknowled'ments (C;s!

    – C;s can be pi''ybacked on data 'oin' the other way– Protocol allows receier to C; eery other packet in

    attempt to reduce C; tra&&ic (delayed C;s!

    – 0elay should not be more than BB msD (typically BB ms!

    – +e’ll see how this causes problems later

    socket

    layer TCP

    send buffer 

    application

    writes data

    TCP

    receive buffer 

    socket

    layer 

    application

    reads data

    data segment

     ACK segment

  • 8/17/2019 Tcp Extra

    6/17

    E

    Preventing Congestion

    • 2ender may not only oerrun receier, but may also oerrunintermediate routers:– 9o way to eplicitly know router bu&&er occupancy,

    so we need to in&er it &rom packet losses– ssumption is that losses stem &rom con'estion, namely, that

    intermediate routers hae no aailable bu&&ers

    • 2ender maintains a con'estion window:– 9eer hae more than C+ o& un-acknowled'ed data outstandin' (or

    .+79 dataF min o& the two!– 2uccessie C;s &rom receier cause C+ to 'rowD

    • Gow C+ 'rows based on which o& phases:– 2low-start: initial stateD– Con'estion aoidance: steady-stateD– 2witch between the two when C+ H slow-start threshold

  • 8/17/2019 Tcp Extra

    7/17I

    Congestion Control Principles

    • Jack o& con'estion control would lead to con'estioncollapse (Kacobson AA!D

    • 7dea is to be a #'ood network citien$D• +ould like to transmit as &ast as possible without lossD• Probe network to &ind aailable bandwidthD

    • 7n steady-state: linear increase in C+ per .))D• &ter loss eent: C+ is haledD• )his is called additie increase /multiplicatie decrease

    (7L0!D• Marious papers on why 7L0 leads to network stabilityD

  • 8/17/2019 Tcp Extra

    8/17A

    Slow Start

    • 7nitial C+ = 1D• &ter each C;, C+ ?= 1F• Continue until:

    – Joss occurs ".– C+ H slow start threshold

    • )hen switch to con'estionaoidance

    • 7& we detect loss, cut C+in hal&

    • Nponential increase inwindow sie per .)) 

    sender

    o ne  se gme nt 

       .   )   )

    receier

    time

    t w o  se gme nt s

    f o ur  se gme nt s

  • 8/17/2019 Tcp Extra

    9/17O

    Congestion Avoidance

    4ntil (loss!  a&ter C+ packets C;ed:  C+ ?= 1FQssthresh = C+/F

    0ependin' on loss type:  2C;/*ast .etransmit:

    C+/= F continueF  Course 'rained timeout:  C+ = 1F 'o to slow startD

    ()his is &or )CP .eno/2C;: )CP)ahoe always sets C+=1 a&ter a loss!

  • 8/17/2019 Tcp Extra

    10/171B

    How are losses recovered?

    2ay packet is lost (data or C;!• Coarse-'rained )imeout:– 2ender does not receie C; a&ter

    some period o& time– Nent is called a retransmission time-

    out (.)"!

    – .)" alue is based on estimatedround-trip time (.))!

    – .)) is adRusted oer time usin'eponential wei'hted moin' aera'e:.)) = (1-!S.)) ? (!Ssample( is typically BD1!

    *irst done in )CP )ahoe

    S e $ % & '  )  b y t e s  d a t a 

     A C K %

     # * *

    loss   t   i  m  e  o  u   t

    lost C; scenario

    S e $ % & '  )  b y t e s  d a t a 

     A C K % # * *

    sender receier

    time

  • 8/17/2019 Tcp Extra

    11/1711

    Fast Retransit

    • .eceier epects 9, 'ets 9?1:– 7mmediately sends C;(9!– )his is called a duplicate C;– 0oes 9") delay C;s here– Continue sendin' dup C;s &or

    each subse5uent packet (not 9!• 2ender 'ets 3 duplicate C;s:

    – 7n&ers 9 is lost and resends– 3 chosen so out-o&-order packets

    don’t tri''er *ast .etransmit

    accidentally– Called #&ast$ since we don’t need towait &or a &ull .)) 

    sender receier

    time

    S+ , %-* * * ( si . e %#* * * 

     AC K  - * * *

    S+ , %/* * * S+ , %0 * * * 

    S+ , %1 * * * 

     AC K  - * * *

     AC K  - * * *

     AC K  - * * *

    S+ , %-* * * ( si . e %#* * * 

    7ntroduced in )CP .eno

  • 8/17/2019 Tcp Extra

    12/171

    !ther loss recover" ethods

    • 2electie cknowled'ements (2C;!:– .eturned C;s contain option w/2C; block– Tlock says, U'ot up 9-1 90 'ot 9?1 throu'h 9?3U– sin'le C; can 'enerate a retransmission

    • 9ew .eno partial C;s:– 9ew C; durin' &ast retransmit may not C; alloutstandin' dataD N:

    • Gae C; o& 1, waitin' &or -E, 'et 3 dup acks o& 1• .etransmit , 'et C; o& 3, can now in&er 6 lost as well

    • "ther schemes eist (eD'D, Me'as!• .eno has been prealentF 2C; now catchin' on

  • 8/17/2019 Tcp Extra

    13/1713

    How abo#t Connection Teardown?

    • Nither side may terminate a

    connectionD ( 7n &act,connection can stay hal&-closedD! Jet@s say theserer closes (typical in+++!

    • 2erer sends *79 with se59umber (29?1! (iDeD, *79 isa byte in se5uence!

    • Client C;@s the *79 with29? (Unet epectedU!

    • Client sends it@s own *79when ready

    • 2erer C;@s client *79 aswell with 29?1D

    client

    2 3 N ( Y ! 

    serer

     A C K (  Y " #

     !

     AC K (  " #! 

     2 3 N (   !

    close(!

    close(!

    closed   t   i  m  e   d  w

      a   i   t

    time

  • 8/17/2019 Tcp Extra

    14/1716

    The TCP State $achine

    • )CP uses a *inite 2tate Lachine, kept by each side o& a connection, to keep track o& whatstate a connection is inD• 2tate transitions re&lect inherent races that can happen in the network, eD'D, two *79@s

    passin' each other in the networkD• Certain thin's can 'o wron' alon' the way, iDeD, packets can be dropped or corruptedD 7n

    &act, machine is not per&ectF certain problems can arise not anticipated in the ori'inal.*CD

    • )his is where timers will come in, which we will discuss more laterD

  • 8/17/2019 Tcp Extra

    15/171

    TCP State $achine%Connection Establishent

    N2)TJ72GN0

    289V.CM0

    289V2N9) 

    CJ"2N0

    J72)N9

    client applicationcalls connect()

    send S&'

    receive S&'send S&' AC

    server applicationcalls listen()

    receive S&' * ACsend AC

    receive AC

    • CJ"2N0: more implied thanactual, iDeD, no connection

    • J72)N9: willin' to receieconnections (accept call!

    • 289-2N9): sent a 289,waitin' &or 289-C;

    • 289-.NCN7MN0: receied a289, waitin' &or an C; o&our 289

    •N2)TJ72GN0: connectionready &or data trans&er

    receive S&'send AC

  • 8/17/2019 Tcp Extra

    16/171E

    TCP State $achine%Connection Teardown

    N2)TJ72GN0

    *79V+7)V

    )7LNV+7) 

    *79V+7)V1

    J2)VC;

    CJ"2NV+7) 

    CJ"2N0

    wait +,$S-(+./ seconds)

    receive AC

    receive F0'send AC

    receive AC

    o1 F0'

    close() calledsend F0'

    receive F0'send AC

    • *79-+7)-1: we closed &irst,waitin' &or C; o& our *79(actie close!

    • *79-+7)-: we closed &irst,other side has C;N0 our *79,but not yet *79@ed

    • CJ"279%: other side closedbe&ore it receied our *79

    • )7LN-+7): we closed, otherside closed, 'ot C; o& our *79

    • CJ"2N-+7): other side sent*79 &irst, not us (passie close!

    • J2)-C;: other side sent*79, then we did, now waitin'&or C;

    CJ"279%

    receive F0'

    send AC

    receive ACo1 F0'

    close() calledsend F0'

  • 8/17/2019 Tcp Extra

    17/171I

    S#ar"% TCP Protocol

    • Protocol proides reliability in &ace o& complenetwork behaior

    • )ries to trade o&& e&&iciency with bein' U'ood

    network citienU• Mast maRority o& bytes trans&erred on 7nternet

    today are )CP-based:– +eb

    – Lail– 9ews

    – Peer-to-peer (9apster, %nutella, *ree9et, ;aWaa!