test me

Site Search:

The TCP/IP Model

Back>
TCP/IP Model
TCP/IP Model



The TCP/IP model was created by the U.S. Department of Defencse (DoD), to create a network that could survive any conditions. It is a collection of protocols. Some of these protocols are defined in Requests For Comments (RFC) documents and the rest are non-RFC documents created by other groups such as IEEE. These protocols are standard way of doing things, which almost all hardware and software vendors choose to follow. If you are a desktop vendor who decided to not follow the standard way of doing things, for example, use a different kind of connector for ethernet cables. Chance is, your computer sells poor because the standard ethernet cable can not be plugged into your computer. Your company either get rejected by market and close or it changes the market so that a new standard defined by you is added into one of TCP/IP protocol RFC document.

TCP/IP model is collectively implemented by many vendors. For example, your application vendor implemented some protocol such as HTTP in application layer; your operation system vendor implements some protocol such as UDP/TCP in the transport layer and internet layer; your ethernet card on the computer implements some LAN standards defined in IEEE Ethernet; your service provider implements some protocol or RFCs in LINK layer... As a results, all these above mentioned vendors work together to implement the TCP/IP Model, so that you can browse internet and read this very post.

The TCP/IP model originally defined in RFC1122 has four layers. These layers are imaginary layers that breaks the network functions into a small number of categories so that people can easily understand. The top two layers focus more on the applications that need to send and receive data from network. The bottom two layers handles transmit bits over each individual link -- internet layer delivers data from the source host to the destination host over many intermediate hosts; link layer has also been referred to as the network access layer, network interface layer, which more or less reflects the functionality of delivering data across some physical links between two computers.

Application Layer: This layer provides service to applications running on a computer. An application handles many functions such as display image, get mouse click, track time etc. Not all applications need network capability, but some network capable applications do. In another words, they need the network service. Application layer defines the services these applications needs, for example, HTTP protocol defines how an web applications should handle a web page between a web browser application running on your local machine and an web server application running on the remote host. When the browser programmer and web server programmer write their code, they follow the HTTP protocol as their guideline, their code will implement HTTP protocol.

For example HTTP protocol's GET includes 2 steps in most scenarios:
web browser sends a message with a HTTP header containing information such as GET method, the path to the webpage "/fun.html", the web server returns a message with header containing header 200 OK and the content of the fun.html. When the /fun.html can not be found on the server, 404 will be returned. There are many other scenarios such as server side throws exception, needs password authentication, certification authentication etc. outside the simple GET happy path.

Here is a code snippets give you some sense of how programmers implement HTTP protocol with code:

client side:

PrintWriter request = new PrintWriter( socket.getOutputStream() );
            request.print(  "GET /fun.html HTTP/1.1\r\n" + 
                                   "Host: localhost\r\n" + 
                                   "Connection: close\r\n\r\n"); 

            request.flush( ); 

server side:

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class SimpleHTTPServer {
    private static ServerSocket server;
    public static void main(String args[]) throws IOException {
        server = new ServerSocket(8080);
        System.out.println("Listening for connection on port 8080 ....");
        while (true) {
            try (Socket socket = server.accept()) {
                //omit code related to socket.getInputStream().read();
                String httpResponse = "HTTP/1.1 200 OK\r\n\r\n yo whats up? here is the content of fun.html, nice day";
                socket.getOutputStream().write(httpResponse.getBytes("UTF-8"));
            }
        }
    }

}

Of course, nowadays, programmers generally don't write code directly handle the HTTP protocol implementation, the implementations are handled by libraries somewhere deep in the library dependency chain, so that majority of the programmers only construct the content part: "yo whats up? here is the content of fun.html, nice day", then pass the string to a library/framework function which eventually handles HTTP protocol.

It is fun to know: HTTP protocol is represented with human readable Strings in the application code (and libraries code). The protocols we will study later, namely TCP, UDP, IP, PPP etc. are represented by bits which is more machine friendly and less human readable. Programmers generally use Array to store bits in the code. You can still read these bits from memory on your computer. Protocols at even lower level such as IEEE ethernet, is represented by electromagnetic pulses, you have to bring a multi-meter to the cable wire if you want to "read" them.

Transport Layer: Transmission control protocol (TCP) and user datagram protocol (UDP) operating at this layer. Transport layer protocols provide services to the application layer protocols. For example, while application layer focuses on constructing well-conformed HTTP messages, it is the TCP protocol that is responsible for reliably deliver these HTTP messages. TCP protocol achieve this by dividing HTTP messages into many small chunks then add a header to the chunk to get a so called Segment. Since there is a sequence number field in the header, whenever a segment is lost during transmission, this lost can be detected by examining the sequence number from the segments' header field at the receiving side. Once a missing sequence number is detected, the receiving side can ask the sending side to resend the missing Segment.

Internet Layer: IP protocol resides at this layer. There are two versions of IP, IP version 4 (IPv4) and IP version 6 (IPv6). You may already know, IP layer protocols provide service to the Transport layer protocols. Think this for a second, how TCP or UDP protocol figure out where to send the segments to? It needs the receiver's address; when the receiver gets a segment and wants to reply back, the sender's address is needed. IP protocol is responsible for addressing computers in the network. For example Internet Protocol version 4 (IPv4) defines an IP address as a 32-bit number. Similar to each street address uniquely identify a physical location on the earth, each of these 32-bit number uniquely identifies a computer (location) in the internet. Whenever a TCP or UDP segment need to be send to another host, an IP header is added to the segment to form an IP packet. The IP header includes a source IP address and a destination IP address.

It is fun to compare a packet to an post office letter with sender address and receiver address on the envelope.

First, the host computer send the packet to a nearby router in the same LAN. It is like you drop your letter into a nearby USPS mail box.

Secondly, the router exams the destination IP in the IP header, then decides which router to forward the packet to. The next router again exams the destination IP address, then forwards the packet to another router. Each forward get the packet closer to the destination. In the case of USPS letter, the post office check the destination address, then forward the letter to another post office in another city, the next post office then forwards the letter to anther post office, each forward get the letter closer to the destination address.

Finally, the packet reached a router in the same LAN as the destination IP address. The packet is then forwarded to the destination host. The story of the USPS letter also ends like this: the letter travels to the local post office of the receiver, then is forwarded to the receiver's address.

Link Layer:  It is also called the host-to-network layer or Network Access Layer. This layer provides services to the Internet layer. It defines the protocols and hardware requirements for sending a packet across physical network. The term link refers to the physical connections between two devices and the protocols used to control those links.

It is helpful to lend the similarity of IP packet and USPS letter to understand how this layer works. Even though you decided to drop the letter into a nearby mail box, you have to physically drive there or walk there, you have to know the road, the traffic light, how the mail box looks like, how to open the box to drop the letter. Your willingly doggy can not do this for you, can she? Once the letter need to be sent from one post office to another, other "physical" things need to be considered, like, delivery truck side, truck driver's license, box to hold the letters in the truck, etc. The nitty ditty details your pet can't know and you don't care.

Well, you don't want to run a mail office, but you still want to be an IT professional, so you want to how Link layer works. Here is the process of transmitting a packet between two connected computers over ethernet (transmitting over wifi is another physics lecture). There are 4 steps.

step 1, At the source host, an IP packet is wrapped between an Ethernet header and Ethernet trailer, creating an Ethernet frame.

step 2, The Ethernet frame is stored as bits (0/1) in memory, each bit generate an electromagnetic wave pulse which then flows over the Ethernet cable connected to the source host's NIC card.

step 3, At the other side of the cable, the destination host's NIC card senses the electromagnetic wave pulse, translates the pulses into bits, and reconstructs the Ethernet frame and stores in the memory.

step 4, the destination host exams the ethernet frame, gets the IP packet from the frame by removing the Ethernet header and trailer.


Normally, application programmers are concerned only with interfaces in the Application Layer and often also in the Transport Layer, while the layers below are services provided by the TCP/IP stack in the operating system. Microcontroller firmware in the network adapter typically handles Network Access issues, supported by driver software in the operational system. Non-programmable analog and digital electronics are normally in charge of the physical components in the Network Access Layer, typically using an ASIC chipset for each network interface or other physical standard.

For more detail, see this post

No comments:

Post a Comment