TCP Stack

>Have you ever wonder how the email or message you send reaches the other person?  It’s a simple process basically but to implement is quite difficult.

In my upcoming posts, I would be giving steps to implement a TCP Stack.  For that first, we need to understand the concept on how messages or details get transferred across networks.

There are basically two network models via which we can transfer data:

  1. OSI (Operating Systems Interconnection Model)
  2. TCP/IP (Transfer Control Protocol/ Internet Protocol Model)

OSI basically has seven layers across which the data get transmitted. The seven layers of OSI model are:

  1. Application
  2. Presentation
  3. Session
  4. Transport
  5. Network
  6. Data-Link
  7. Physical

TCP/IP model has four layers which are explained below in detail along with an example how it works:

  1. Application
  2. Transport
  3. Internet
  4. Network access

The Application layer is where user interaction takes place. Application layer makes sure that the data sent in the format which is understandable to the recipient.  For example HTTP, FTP etc.

The Transport layer is where the data is broken down into packets by using the TCP/Transfer Control Protocol. It adds segment number and port number. Port number specifies the port to where data should be transferred and segment number makes sure the broken down packages can be reassembled.

The Internet layer makes sure that it reaches the correct destination. The IP/Internet Protocol adds the sender’s and recipient’s IP address. Here we create the socket. The socket is basically used for establishing connections which include the recipient’s IP address and the port number.

The Network access includes both the Data-Link and the Physical Layer in the OSI model. Data-Link makes sure of transmission through Ethernet for instance. Physical layer makes transmissions through Hardware. The Network access layer adds the MAC address of both the sender and receiver.

Here is an example to show the transmission of the message below:

Good morning Aditi!

Above is the message you have in the Application layer, which gets in the below format. Note that I am using XML format here:

<gospel>Good</gospel><gospel>morning</gospel><gospel>Aditi!</gospel>

Each of them in a gospel tag goes as a separate packet when it enters the Transport Layer.

transportlayer

Here we add the port number as 60 and each of the segment number. Now when it is passed to the IP Layer we have:

internetlayer

We have the IP address of the sender 98.1.232.99 and that of the receiver 102.231.4.189. The socket can be written as 102.231.4.189:60

The Final layer of the Network access Layer would look like:

networkaccess

We have the sender’s MAC address starting with 00 and the receivers starting with 11.

Once the message reaches the receiver there it is unpacked by traveling through the each of the four layers in the reverse order and the segment number makes sure that the packets get arranged in an order.

The next post would be based on setting up a server-client connection to start with the TCP stack!

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s