Friday, December 8, 2006

How TCP IP Packets Are Processed

Protocols such as TCP/IP determine how computers communicate with each other over networks such as the Internet. These protocols work in concert with each other, and are layered on top of one another in what is commonly referred to as a protocol stack. Each layer of the protocol is designed to accomplish a specific purpose on both the sending and receiving computers. The TCP stack combines the application, presentation, and the session layers into a single layer also called the application layer. Other than that change, it follows the OSI model. The illustration below shows the wrapping process that occurs to transmit data.

* The TCP application layer formats the data being sent so that the layer below it, the transport layer, can send the data. The TCP application layer performs the equivalent actions that the top three layers of OSI perform: the application, presentation, and session layers.

* The next layer down is the transport layer, which is responsible for transferring the data, and ensures that the data sent and the data received are in fact the same data-in other words, that there have been no errors introduced during the sending of the data. TCP divides the data it gets from the application layer into segments. It attaches a header to each segment. The header contains information that will be used on the receiving end to ensure that the data hasnt been altered en route, and that the segments can be properly recombined into their original form.

* The third layer prepares the data for delivery by putting them into IP datagrams, and determining the proper Internet address for those datagrams. The IP protocol works in the Internet layer, also called the network layer. It puts an IP wrapper with a header onto each segment. The IP header includes information such as the IP address of the sending and receiving computers, and the length of the datagram, and the sequence order of the datagram. The sequence order is added because the datagram could conceivably exceed the size allowed for network packets, and so would need to be broken into smaller packets. Including the sequence order will allow them to be recombined properly.

* The Internet layer checks the IP header and checks to see whether the packet is a fragment. If it is, it puts together fragments back into the original datagram. It strips off the IP header, and then sends the datagram to the transport layer.

* The transport layer looks at the remaining header to decide which application layer protocol-TCP or UDP-should get the data. Then the proper protocol strips off the header and sends the data to the receiving application.

* The application layer gets the data and performs, in this case, an HTTP request.

* The next layer down, the data link layer, uses protocols such as the Point-to-Point Protocol PPP to put the IP datagram into a frame. This is done by putting a header-the third header, after the TCP header and the IP header-and a footer around the IP datagram to fra-me it. Included in the frame header is a CRC check that checks for errors in the data as the data travels over the network.

* The data-link layer ensures that the CRC for the frame is right, and that the data hasnt been altered while it was sent. It strips off the frame header and the CRC, and sends the frame to the Internet layer.

* On the receiving computer, the packet travels through the stack, but in the opposite order from which the packet was created. In other words, it starts at the bottom layer, and moves its way up through the protocol stack. As it moves up, each layer strips off the header information that was added by the TCP/IP stack of the sending computer.

* The final layer is the physical network layer, which specifies the physical characteristics of the network being used to send data. It describes the actual hardware standards, such as the Ethernet specification. The layer receives the frames from the data link layer, and translates the IP addresses there into the hardware addresses required for the specific network being used. Finally, the layer sends the frame over the network.

* The physical network layer receives the packet. It translates the hardware address of the sender and receiver into IP addresses. Then it sends the frame up to the data link layer.