TCP/IP In Action | How all Layers of TCP/IP Model Work Together


We already have discussed how every Layer of our networking model works. Now we’ll see the TCP/IP in Action. Means we’ll discuss in this article that how all layers of TCP/IP Networking Model work together at every step of the way.

TCP/IP In Action | How all layers of TCP/IP Networking Model Work Together

Let consider we have three networks, network A, B and C. Network A contains address space So the Network B contains Address space As well as Network C contains address space Also consider that Router A establishes connection between Network A and Network B. Router A’s interface at network A is, also its interface at Network B is There is a second router B that connect Network B and Network C. Router B’s interface at network B is Also its interface at network C which IP address

Now consider we have a PC at Network A with IP address Also consider that there is a server PC which is part of Network C with an IP address The server_PC also has a web server listening to port 80. An end user at the PC of Network A opening a web browser tries to connect the web server at Network C by putting on the address bar.

TCP/IP In Action | How all Layers of TCP/IP Model Work Together

Establishing TCP Connection | TCP-IP in Action

The web browser then communicates with the local networking stack, which is the part of OS responsible for networking functions. web browser explains that it’s going to establish a TCP connection to port 80.

The Networking_Stack then examines that the address is not on its own Subnet. Because it lives on the Subnet So the destination IP address that the browser inquires is on another network. At this point the PC knows that it’ll have to send any data to its gateway for routing tot a remote network. The configured default gateway of the PC is So the PC looks at its ARP table to determine the MAC address of the IP, but it doesn’t find any corresponding entry. Therefore the PC crafts an ARP Discovery Request for an IP address of and sends to the hardware broadcast address of all Fs to every node on the local network.

When Router A receives the ARP message it sees, it is the computer with the requested MAC against the IP address So it responds to the PC to let it know of its own MAC address. Hence the PC receives the response and now it knows the hardware address of its gateway.

Building TCP Segment | Constructing the outbound Packets

As the PC now knows the physical address of its default gateway, this means that its networking stack is ready to constructing outbound packets. Because Web_browser asks PCs networking stack to build outbound TCP connection, therefore it’ll need an outbound TCP port. The Operating System identifies the ephemeral port of 50000 is available, therefore opens a Socket connecting the web browser to this port.

Since this is a TCP connection, the Networking_Stack knows that before transmitting any data it’ll need to establish a connection. So the Networking_Stack starts to build a TCP Segment. It fills in all the appropriate fields in the TCP Header, including source port of 50000 and destination port of 80. It also choses a sequence number and fills it to Sequence_Number_Field. Finally the Networking_Stack sets the SYN flag ON and calculate Checksum for entire data. Now this new TCP Segment passes along the IP Layer of the Networking_Stack.

Constructing IP Header | TCP/IP in Action

The IP Layer of Networking_Stack constructs an IP Header for that TCP Segment. It fills source and the destination address field for that TCP packet and set the TTL field with standard TTL value of 64. Finally the TCP Segment is inserted as the Data Payload for the IP Datagram. Also a checksum is calculated for the whole thing.

Constructing Ethernet Frame | Sending IP datagram to Gateway’s Physical Address

As the PC knows the Physical address of it’s gateway, therefore it construct the Ethernet Frame. So it fills all necessary data to Ethernet header fields, specially Source and Destination MAC Addresses. Finally Networking_Stack inserts the IP Datagram as Data Payload of the Ethernet Frame. Also calculates another Checksum.

The Network Interface on PC sends this binary data as modulations of the voltage of an electrical current running across a Cat-6 cable connected between the PC and a Network Switch.

The Network Switch then receives the frame and inspect the destination MAC address. It also knows that which of its interface this MAC address attached to. So it forwards the frame to the destination MAC across cable connected to the interface. Now the other side of the link router receives the frame and identifies its own physical address is the destination.

Routing Data to the Destination Remote Network | TCP/IP in Action

After receiving the Ethernet Frame Router A calculates a Checksum against it. Then it compares the Checksum with the Checksum value in the Ethernet Frame Header and finds the matching. If both matches then Router A strips away the Ethernet Frame leaving just the IP Datagram. Then again the Router A calculates the Checksum against the entire IP Datagram and Matches with the Checksum value in the IP Datagram Header. So if finds that both checksum matches, meaning data is correct, and doesn’t get corrupted on its way.

The ROuter then inspects the destination IP Address, and also performs lookup of this destination IP in its Touting_Table. So from its routing table it decides that in order to send the data to network the quickest path is one hop away via Router B. Therefore it forwards the data to Router B’s gateway attached to it. For this it decrements the TTL field by 1, and calculates new Checksum considering new TTL value, and makes a new IP Datagram with the data. Router A knows it needs to get the Datagram to Router B. So it look at its ARP table and looks an entry (MAC) for Finally Router A constructs an Ethernet Frame with the MAC_Address of its interface on Network B as source, and the MAC_Address of Router B’s interface on Network B as destination. Then it puts the newly constructed IP_Datagram to its Data_Payload field, and calculates a Checksum and puts it to the Checksum field. Eventually sends the frame out to Router B.

Removing Ethernet Frame and IP Datagram Encapsulation by Destination Router

Similar to Router A, Router B Receives the Ethernet Frame and perform a checksum and matches with the value in Ethernet Checksum field. If matches then removes the Ethernet Encapsulation and performs a checksum against entire IP Datagram. Also then if matches the router strips the IP Datagram and examine the the destination IP Address. It then looks at its Routing_table and sees that the destination IP address of the Server on its local network.

Forwarding Data to Its Final destination

Eventually Router B decrements the TTL by 1, calculates the new checksum considering the new TTL value, and creates a new IP Datagram. The router then again encapsulates the IP Datagram into Ethernet Frame. This time the Source_MAC is the MAC of Router B’s interface on Network C and Destination_MAC is the MAC against the IP So the Router B sends out the Ethernet Frame to NEtwork C, and the Switch ensures the frame get sends out of the interface the Server is connected to.

Finally the Data to its Destination | TCP/IP in Action

Hence the Server PC receives the Ethernet Frame, and identifies its own MAC address is the Destination. The SERVER_PC then performs a Checksum and if matches then it strips away the Ethernet Frame leaving it with the IP Datagram. Then again performs a checksum against entire IP Datagram and recognizes the Data is intact. So the Server_PC then examines the destination IP address and sees that the data is intended for its own. Then the Server_PC strips the IP Datagram leaving with just the TCP Segment. Here again a Checksum is calculated and check to verify everything is correct.

Next the Server Checks the destination port, which is port 80. The Networking Stack on Server checks to ensure that there is an open Socket on port 80. The Socket is in Listen State running by Apache Web Server. The Server also sees that this packet has the SYN flag set. So it examines the sequence number, and stores that. Because it needs the sequence number in Acknowledge field to craft the response.

So all of this done mentioned above to get a single TCP Segment containing a SYN flag from a PC to Server Computer. Everything will have to happen all over again for Server to send a SYN-ACK response to the PC. So this process will continue over and over again for transmitting every single TCP segment. And this is how all the Layers of TCP/IP Networking Model have to work together to get the job done.

Copy link
Powered by Social Snap