test me

Site Search:

The TCP/IP Model

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";


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. 

Network Access Layer: Combines all functionality of physical and Data Link layers of OSI model. It is also called the host-to-network layer.

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