Sunday, December 5, 2010

Explain how TCP Finite State Machine behaves when a http request is sent.

1) The application will create a TCP socket using the socket API socket(PF_INET(for ipv4), SOCK_STREAM(for tcp socket), 0 (protocol) ).
A transmission control block (TCB) created by the TCB module identified by the socket descriptor.
It is initiated to an FSM state CLOSED.

2) The Application calls connect() API providing the remote socket data.
The TCB sends a SYN packet with its starting sequence number.
TCB FSM state:- SYN_SENT.

3)
  • EVENT => If it receives a SYN msg, TCB FSM => SYN_RCVD and it sends a ACK.
  • EVENT=> It it receives a SYN_ACK msg, TCB FSM => ESTABLISHED
4) The application uses these APIs: send(2), sendto(2), and sendmsg(2) send data over a socket, and recv(2), recvfrom(2), recvmsg(2) receive data from a socket. poll(2) andselect(2) wait for arriving data or a readiness to send data. In addition, the standard I/O operations like write(2), writev(2), sendfile(2), read(2), andreadv(2) can be used to read and write data.
5) EVENT:- When the Application calls close(), ACTION: Send FIN, TCB FSM => FIN_WAIT1

6)
  • EVENT:TCB recieves ACK , TCB FSM=> FIN_WAIT2
  1. Recieve FIN, Send ACK , TCB FSM => TIME WAIT
  • EVENT: TCB recieves FIN-ACK, TCB FSM=>CLOSING
  1. Recieve ACK for FIN, TCB FSM=> TIME_WAIT ..Wait to ensure that the ACK is recieved and prevent potential overlap with new connections.

No comments:

Post a Comment