Saturday, October 06, 2007

 
Let's talk about TCP/IP today.
For us to understand this completely we will be required to cover bit of theory first and
then we can proceed to take a case.

TCP stands for Transmission Control Protocol/Internet Protocol. This is a four layered protocol. The layers are

1. Application Layer
2. Transport Layer
3. Internet/Network Layer
4. Physical Layer.

Now let's see what all are handled at each layers.

Let's start from bottom.

1. Physical Layer: This is the layer, where physical network is taken care of. This layer deals with the network adapter and its device driver. So if we have a switch, it is implemented at this layer.
Popular protocols like PPP (Point to point protocol) etc are handled at this layer. Covering these protocols here, is beyond the scope of this article.

2. Internet Layer/Network Layer: This is the layer, where Internet Protocol is applied. This layer can be compared with the network layer of OSI. This is the layer, where we would apply routing protocols and handle routers.Its job is to send packets or datagrams - a term which basically means “blocks of data” - from one point to another. It uses the physical protocol to
achieve this. Both the network layer and the physical layer are concerned with getting data from point AB to point BC.

However,whilst the network layer works in the world of TCP/IP, the physical layer has to deal with the real world or real hardware. This is the layer, which breaks packet further depending on the MTU (Maximum Transmission Unit) of the datalink layer. It adds it's own headers, which are parsed by the destination Network layer of the TCP/IP stack. IP or Internet
Protocol, which works on this layer, does not guarantee an error free transmission for the packets.


3.Transport Layer: This is the layer on which TCP or UDP (User Datagram Protocol) works.
The UDP or User Datagram Protocol does not need to establish a connection with a host before exchanging data, and there is no mechanism for ensuring that data sent is received.
TCP or Transmission Control Protocol on the other hand provides reliability. An application that uses TCP knows that data it sends is received at the other end, and that it is received correctly. TCP uses checksums on both headers and data. When data is received, TCP sends an acknowledgement back to the sender. If the sender does not receive an acknowledgement within a certain timeframe the data is re-sent. The data received by this layer fronm higher layer is broken down into packets and then headers are added. Though

UDP is non-reliable transmission mechanism but the advantage is the fastness. Since it don't worry about the accuracy the overhead is less and hence better speed in transmision. This is the reason, why UDP is used while buffering songs and movies.

4. Application Layer: This is the layer, where we talk about the underlaying application. This layer takes special care of destination address and port and host address and port. So this four tuple information is most critical to this layer. A 32 bit IP address, and 16 bit port number is used for both detination and host. Using this 16 bit port number it decides the application. By applicaton we mean, whether it is HTTP, FTP or SMTP and so on. The default port ca be used to identify the application protocol. For example, if it is port 80, we know it is HTTP, if it is 21, we know it is FTP and so on. Howvwer, even if an appication is configured at a port other than the default one, it hardly matters to ths layer. All it needs is the correct IP and port. Say, HTTP in destination is configured at port 8080, the application layer will handle the packet at that port at destination's end.

So this was bit of theory we required to know about TCP/IP. I would recommend you to go thorough some good resource to cover the underlying protocols like PPP, UDP etc...

Now let's use this knowledge to trace what happens when we request a web-page using our browser.

When we type a address on our browser's address bar and hit the 'Enter' key the activity starts.

First, once we do that browsers prepares a HTTP request header, retrieves the IP and sends it to the network. The local gateway's server will have the TCP stack, which will take control of the data. It will then (as discussed earlier), will be received by the application layer, determine the host, destination's IP:port and then hand it over to the application layer and so on. TCP divides the data into MTUs (multiple transmission units, which is determined by the data link layer of the network) and adds its own headers which contains directives like Checksum, Sequences etc. TCP also has a error control mechanism. So, for a packet if an acknowledgment is not received in a given time interval, packet is considered lost and is re-transmitted. The packet then passes to Intenet Layer (corresponds to Network layer of OSI). Here all task associated with IP is applied. Data is then passed to the physical layer for transmission. At destination end physical layers receives the data, passes it to the Internet layer. It removes its header and passes it to the Transport layer. Here it verifies directives like Checksum and other stuff to verify the data. On successful verification, an acknowledgment is sent to the Transport layer of the Source. Then it is passed to the Application layer. Now here, application layer, verifies the destination port number to identify that this needs to go the HTTP. So opens a port (80 in this example) and passes the request. On port 80, a server is generally waiting for request continuously. It listens on port 80. So the Application layers writes the data on the socket, which is accepted by the server (could be apache) and data is processed. And then the processed data is sent back to the browser (client) using the same technique.

I hope this practical example adds to your confidence in TCP/IP.

That's all from today. Please do let me know, what do you, think of this article.

This page is powered by Blogger. Isn't yours?