OSI and TCP/IP each layer of structure and function, have what protocol

OSI’s seven-tier architecture is conceptually clear and theoretically complete, but it is complex and impractical. By the way, OSI, which had been backed by some big companies and even some national governments, failed:

  1. OSI experts lack practical experience, and they lack a commercial drive to accomplish OSI standards
  2. The OSI protocol is too complex to implement and inefficient to run
  3. The OSI standards took too long to come to market in a timely manner. (In the early 1990s, although the entire OSI international standard had been developed, TCP/ IP-based Internet was already running successfully on a large scale around the world.)
  4. The OSI hierarchy is not very good, and some functions are repeated in multiple layers

A five-tier protocol architecture

When we study computer networks, we usually take the middle ground, which is to counteract OSI and TCP/IP, and adopt an architecture with only five protocols, which is concise and can explain the concepts clearly.

Combined with the Situation of the Internet, top-down, very brief introduction to the role of each layer.

1 Application Layer

The task of the application layer is to complete a specific network application through the interaction between application processes. Application layer protocols define the rules for communication and interaction between application processes (processes: running programs in a host). Different application layer protocols are required for different network applications. There are many application layer protocols in the Internet, such as domain name system DNS, HTTP protocol to support world Wide Web applications, SMTP protocol to support E-mail and so on. The data units that the application layer interacts with are called packets.

Domain Name System (DNS)

Domain name system (DNS) is a core service of the Internet. As a distributed database that can map domain names and IP addresses to each other, it makes it easier for people to access the Internet without having to remember IP numbers that can be read directly by machines. For example, a company’s Web site can be regarded as its portal on the Internet, and the domain name is equivalent to its house address, usually using the company’s name or abbreviation. For example, the Microsoft domain name mentioned above is similar to the IBM domain name www.ibm.com, Oracle domain name www.oracle.com, and Cisco domain name www.cisco.com.

The HTTP protocol

HyperText Transfer Protocol (HTTP) is the most widely used network Protocol on the Internet. All WWW files must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages. (Baidu Encyclopedia)

2 Transport Layer

The main task of the transport layer is to provide a common data transfer service for communication between two host processes. Application processes use the service to transmit application-layer packets. “Generic” means that multiple applications can use the same transport layer service rather than targeting a specific network application. Because a host can run multiple threads at the same time, the transport layer has the functions of reuse and reuse. The so-called reuse means that multiple application layer processes can simultaneously use the services of the lower transport layer. On the contrary, the transport layer delivers the received information to the corresponding processes in the upper application layer.

The transport layer mainly uses the following two protocols:

  1. Transmission Control Protocol (TCP) – provides connection-oriented, reliable data transfer services.
  2. User Datagram Protocol (UDP) – provides a connectionless, best effort data transfer service (without guarantee of reliability of data transfer).

Main features of UDP:

  1. UDP is connectionless;
  2. UDP uses best effort delivery, that is, reliable delivery is not guaranteed, so hosts do not need to maintain complex linked states (which have many parameters);
  3. UDP is message-oriented.
  4. UDP does not have congestion control, so network congestion does not reduce the sending rate of the source host (useful for real-time applications, such as IP telephony and real-time video conferencing).
  5. UDP supports one-to-one, one-to-many, many-to-one, and many-to-many interactive communication.
  6. The header of UDP has a small overhead of only 8 bytes, which is shorter than TCP’s 20 bytes header.

The main features of TCP:

  1. TCP is connection-oriented. (Just like making a phone call, you need to dial a number to establish a connection before the call and hang up to release the connection when the call is over);
  2. Each TCP connection can have only two endpoints, and each TCP connection can be point-to-point (one-to-one).
  3. TCP provides reliably delivered services. Data transmitted through TCP connection, error-free, not lost, not repeated, and arrive in sequence;
  4. TCP provides full duplex communication. TCP allows applications on both sides of the communication to send data at any time. Both ends of the TCP connection are configured with the send cache and receive cache to temporarily store the data exchanged between the two parties.
  5. Byte – oriented stream. A “stream” in TCP refers to a sequence of bytes flowing into or out of a process. Byte stream oriented means that while an application interacts with TCP one data block at a time (of varying sizes), TCP treats the data handed over by an application as just a series of unstructured byte streams.

3 Network Layer

The network layer is responsible for providing communication services for different hosts on the packet-switched network. When sending data, the network layer encapsulates the packet segments or user datagrams generated by the transport layer into packets and packets for transmission. In the TCP/IP architecture, packets are also called IP datagrams, or datagrams for short, because the network layer uses the IP protocol.

Note here: Do not confuse the “user datagram UDP” of the transport layer with the “IP datagram” of the network layer. In addition, no matter which layer of data units, can be generally expressed as “grouping”.

Another task of the network layer is to select an appropriate route so that the ramet passed down from the source host transport layer can find the destination host through the router in the network layer.

It is emphasized here that the word “network” in the network layer is no longer the specific network we usually talk about, but refers to the name of the third layer in the computer network architecture model.

The Internet is composed of a large number of heterogeneous networks connected with each other through routers. The network layer protocol used by the Internet is the Connectionless Internet Protocol (Intert Prococol) and many routing protocols, so the network layer of the Internet is also called the Internet layer or IP layer.

4 Data Link Layer

The data link layer is often referred to simply as the link layer. Data transmission between two hosts is always transmitted over a segment of the link, which requires the use of a special link-layer protocol. When transmitting data between two adjacent nodes, the data link layer transmits the frame assembly process of IP datagram handed over by the network layer on the link between two adjacent nodes. Each frame contains data and necessary control information (such as synchronization information, address information, error control, etc.).

When receiving data, control information enables the receiver to know which bits a frame begins and ends in. In this way, when the data link layer receives a frame, it can extract the data portion from it and submit it to the network layer. The control information also enables the receiver to detect errors in the received frame. If an error is detected, the data link layer simply discards the errant frame to avoid wasting network resources further across the network. If errors in data transmission at the link layer need to be corrected (that is, the data link layer must not only detect errors, but also correct errors), then the reliability transport protocol is used to correct the errors. This approach complicates the link layer protocol.

5 Physical Layer

The units of data transmitted at the physical layer are bits. ** The role of the physical layer is to achieve transparent transmission of bitstreams between adjacent computer nodes, as far as possible to shield the differences between specific transmission media and physical devices. ** Enables the data link layer above it to be independent of the specific transmission medium of the network. “Transparently transmitted bitstream” means that the bitstream transmitted by the actual circuit does not change, and the circuit appears to be invisible to the transmitted bitstream.

Of the various protocols used on the Internet, the most important and well-known are TCP/IP. Nowadays, TCP/IP is often referred to not only TCP and IP, but the entire TCP/IP protocol family used by the Internet.

Above we have a preliminary understanding of the five-tier architecture of computer networks, and a seven-tier architecture diagram is attached below to summarize. Image source: https://blog.csdn.net/yaopeng_2005/article/details/7064869

Two TCP three handshakes and four waves (frequent interviewers)

TCP uses a three-way handshake to deliver data to the destination without error.

Cartoon illustration:

Image source: Illustrated HTTP

Simple schematic diagram:

  • Client – sends packets with the SYN flag – one handshake – Server
  • Server – Sends packets with SYN/ACK flags – Secondary handshake – Client
  • Client – sends packets with ACK flags – three-way handshake – server

Why return the SYN (initiate a new link)?

The SYN is sent back by the receiver to tell the sender that I have received the SYN.

If SYN is sent, why would you want to send ACK?

The communication between the two parties must be correct. A SYN is passed, proving that the channel from sender to receiver is ok, but the channel from receiver to sender needs an ACK signal for verification.

Four waves are required to disconnect a TCP connection:

  • Client – Sends a FIN to shut down client-to-server data transfer
  • Server – Upon receiving the FIN, it sends back an ACK acknowledging the received FIN plus 1. As with the SYN, a FIN takes a sequence number
  • Server – Closes the connection to the client and sends a FIN to the client
  • Client – Sends back an ACK packet for confirmation and sets the sequence number of the ACK packet to 1

The comparison of all above summary, recommend an article about more detailed: blog.csdn.net/qzcsu/artic…

Differences between TCP and UDP

UDP does not need to establish a connection before transmitting data. After receiving a UDP packet, the remote host does not need to confirm the connection. Although UDP does not provide reliable delivery, it is the most efficient way to work in certain situations (generally used for instant messaging), such as QQ voice, QQ video, live streaming, etc

TCP provides connection-oriented services. The connection must be established before the data is transferred and released after the data is transferred. TCP does not provide broadcast or multicast services. Because TCP to provide a reliable, connection-oriented transport service (TCP and reliable in TCP before passing data, there will be three times handshake to establish a connection, and in data transmission, are confirmed, the window, the retransmission, the congestion control mechanism, in after the data transfer, disconnected will also be used to save system resources), the hard to avoid increased a lot of overhead, Such as validation, flow control, timer and connection management. This not only makes the header of the protocol data unit much larger, but also takes up a lot of processor resources. TCP is used for file transfer, email sending and receiving, and remote login.

4. Enter the URL address in the browser ->> the process of displaying the home page (frequent interviewers)

Baidu seems to love asking this question.

Open a web page, which protocols will be used throughout the process

Image source: Illustrated HTTP

Five status code

The relationship between various protocols and HTTP protocol

Interviewers typically ask questions like these to gauge your understanding of computer network knowledge.

Image source: Illustrated HTTP

HTTP long connection and short connection

Short connections are used by default in HTTP/1.0. That is, each time the client and server perform an HTTP operation, a connection is established and broken at the end of the task. When the client browser accesses an HTML or other type of Web page that contains other Web resources (such as JavaScript files, image files, CSS files, etc.), the browser re-establishes an HTTP session each time it encounters such a Web resource.

From HTTP/1.1 onwards, long connections are used by default to preserve the connection feature. HTTP with long connections adds this line to the response header:

Connection:keep-alive
Copy the code

In the case of a long connection, when a web page is opened, the TCP connection between the client and the server for the transmission of HTTP data is not closed. When the client accesses the server again, it continues to use the established connection. Keep-alive does not hold a connection forever, it has a hold time that can be set in different server software such as Apache. To implement persistent connections, both clients and servers must support persistent connections.

HTTP long connection and short connection are essentially TCP long connection and short connection.

What are HTTP long and short connections?

Write in the last

Recommend an open source back-end document of your own

Java Interview Customs Manual (Java Study Guide)

👉Github address: github.com/Snailclimb/…

👊 : This is an open source document for Java backend engineers, both new to Java and already a Java engineer.

About the basic knowledge of computer network we can view (the first basic knowledge, the second partial summary, are very good) :

  • Summary of computer Network knowledge.
  • Interview with you: this is a comprehensive overview of the basics of computer networking

Review of computer Networking FAQ

The most common problems with computer networks, I think, are these five:

  • â‘ TCP three handshake and four wave,
  • â‘¡ Enter the URL address in the browser ->> display the home page process
  • â‘¢ The difference between HTTP and HTTPS
  • (4) The difference between TCP and UDP
  • ⑤ Common status codes.

advice

I highly recommend taking a look at Illustrated HTTP, which has a few pages, but is very informative, whether it’s for a systematic overview of networking or just for an interview. The following articles are for reference only. When we studied this course in sophomore year, the textbook we used was Computer Network 7th Edition (compiled by Xie Xiren). It is not recommended for everyone to read this textbook, because it is very thick and theoretical, so I am not sure if everyone can finish it calmly.

If you want to get more of my original articles and quality learning resources, please follow my wechat official account :”Java Interview Clearance Manual “. No routine, hope to progress together with you, learn from each other.