.

Saturday, December 20, 2014

TCP Three Way Handshake

ESTABLISHING A CONNECTION


The “three way handshake” is essentially a unidirectional attempt to establish the connection, i.e. there is an initiator and a responder.
The TCP’s should however be able to establish the connection even if
a simultaneous attempt is made by both TCP’s to establish the
connection. Simultaneous attempts are treated like “collisions” in
“Aloha” systems and these conflicts are resolved into unidirectional
attempts to establish the connection. This scheme was adopted because
(i) Connections will normally have a passive and an active end,
and so the mechanism should in most cases be as simple as
possible.
(ii) It is easy to implement as special cases do not have to be
accounted for.
The example below indicates what a three way handshake between TCP’s

  • A and B looks like

  • A                                                      B

    –>          <SEQ x><SYN>              –>



    <–    <SEQ y><SYN, ACK x+l>  <–



    –> <SEQ x+1><ACK y+l><DATA BYTES> –>

The receiver of a “SYN” is able to determine whether the “SYN” was
real (and not an old duplicate) when a positive “ACK” is returned for
the receiver’s “SYN,ACK” in response to the “SYN”. The sender of a
“SYN” gets verification on receipt of a “SYN,ACK” whose “ACK” part
references the sequence number proposed in the original “SYN” [pun
intended]. If the TCP is in the state where it is waiting for a
response to its SYN, but gets a SYN instead, then it always thinks
this is a collision then it forgets that it had sent a SYN. The TCP will try to
establish the connection again after some time, unless it has to
respond to an arriving SYN. Even if the wait times in the two TCPs
are the same, the varying delays in network transmission will usually
be adequate to avoid a collision on the next cycle of attempts to
send SYN.
The State of TCP When Establishing a Connection
S1 S2 R are three state of TCP while establishing a connection
S1 = SYN sent
S2 =  My SYN verified
R = SYN received

if S1 Value is set 1 than means Syn has been sent. Same with S2 and R.

The example below indicates State of TCP in three way handshake between TCP’s
                      A                                                                            B

                      ------------                                                           -----------
                      S1 S2 R                                                              S1 S2 R
                      0 0 0                                                                     0 0 0

 (M1)            1 0 0 --> <SEQ x><SYN>                                    
(M2)            0 0 0 <-- <SEQ y><SYN )                                <-- 1 0 0
(M1)            B returns no SYN sent                                   --> 0 0 0
(M1)           1 0 0 --> <SEQ z><SYN> *                              --> 0 0 1
(M3)           1 1 1 <-- <SEQ y+1><SYN,ACK z+1>             <-- 1 0 1
(M4)           1 1 1 --> <SEQ z+1><ACK y+1><DATA>       --> 1 1 1

Note: "..." means that a message does not arrive, but is delayed
in the network. State changes are upon arrival or upon departure
of a given message.





No comments:

Post a Comment