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.

Friday, December 3, 2010

Q) When a PC boots up how does it get IP address?

Ans:- Using the Bootstrap protocol. The BOOTP configuration server assigns IP addresses from a pool of ip adresses. It runs over UDP. DHCP is an extension of BOOTP.

Q) When you open a webpage on your browser, list down the steps that occur.

  1. The web browser decodes the URL to retrieve the transfer protocol (http,ftp etc..) and servername.domain and the document path. The transfer protocol for a webpage will be http.
  2. Then it sends a DNS Query to the DNS server to get the IP address from the servername.domain name.
  3. After getting the IP address, the Web browser tries to establish a TCP connection with the port 80.
  4. A TCP SYN Segment is constructed by the TCP module and passed on to the IP module.
  5. It looks at the destination address. And looks into its routing database. It finds out the egress interface on which the packet will have to be forwarded. It encapsulates the IP header.
  6. In case PC is connected to a GiGE Lan, the packet will have to be forwarded to the default gateway. It sends a arp request to find out the MAC address of the Gateway.
  7. Then the packet is sent out by encapsulating the ethernet header.
  8. The Gateway then looks at the destination address and sends the packet out on its egress interface.
  9. Finally the packet reaches the Web Server. And it replies with a SYN-ACK.
  10. After a TCP connection is established, the PC sends a HTTP request and get the document in html format after which it displays it on its webpage.