Click on the blue " Linux " in the upper left corner and select " Set as Star "
Read useful articles for the first time
OSI and TCP/IP are very basic but very important knowledge. Many knowledge points are connected in series based on them. As the bottom layer, the more thoroughly you master it, the smoother you will be in understanding the upper layer.
Today's basic network science popularization is carried out one by one according to the OSI levels.
computer network basics
01Classification
of computer networks
According to the scope of the network: wide area network (WAN), metropolitan area network (MAN), local area network (LAN);
According to network users: public network, private network.
02Hierarchical
structure of computer network
Comparison between TCP/IP four-layer model and OSI architecture:
03Basic
principles of hierarchical structure design
-
Each layer is independent of each other;
-
Each layer needs to be flexible enough;
-
Complete decoupling between layers.
04Performance
indicators of computer networks
Rate: bps=bit/s;
Delay: sending delay, propagation delay, queuing delay, processing delay;
Round trip time RTT: The time it takes for a data packet to travel back and forth in end-to-end communication.
physical layer
The role of the physical layer:
Connect different physical devices to transmit bit streams. This layer provides a reliable physical medium for transmitting data to upper layer protocols. Simply put, the physical layer ensures that raw data can be transmitted over various physical media.
Physical layer equipment:
-
Repeater [Repeater, also called amplifier]: Regenerated signal of the same LAN; the network segments of the two ports must be of the same protocol; 5-4-3 regulations: In 10BASE-5 Ethernet, up to 4 repeaters can be connected in series, 5 segments There can only be 3 connected hosts;
The basic concept of channel: A channel is a medium that transmits information in one direction. A communication circuit contains a sending channel and a receiving channel.
-
Simplex communication channel: a channel that can only communicate in one direction and has no feedback in the opposite direction;
-
Half-duplex communication channel: Both parties can send and receive information, but they cannot send or receive at the same time;
-
Full-duplex communication channel: Both parties can send and receive at the same time.
data link layer
01Data
link layer overview
The data link layer provides services to the network layer based on the services provided by the physical layer. Its most basic service is to reliably transmit data from the network layer to the target network layer of adjacent nodes.
The data link layer provides reliable transmission over unreliable physical media.
The functions of this layer include: physical address addressing, data framing, flow control, data error detection, retransmission, etc.
Important knowledge points about the data link layer:
-
The data link layer provides reliable data transmission for the network layer;
-
The basic data unit is frame;
-
Main protocols: Ethernet protocol;
-
Two important device names: bridge and switch.
Encapsulated into frames: "Frame" is the basic unit of data link layer data:
Transparent transmission: "Transparent" means that even if the control characters are in the frame data, they should be treated as if they do not exist. That is, add the escape character ESC before the control character.
02
Error monitoring at the data link layer
Error detection: parity check code, cyclic redundancy check code CRC
-
Parity Check Code – Limitation: When two bits are wrong, no error is detected.
-
Cyclic redundancy check code: A fixed-digit check code is generated based on the transmitted or saved data.
03Maximum
transmission unit MTU
Maximum Transmission Unit (MTU), the data frame of the data link layer is not infinite, and the length of the data frame is limited by the MTU.
Path MTU: Determined by the minimum value of MTU in the link.
04
Detailed explanation of Ethernet protocol
MAC address: Each device has a unique MAC address, a total of 48 bits, expressed in hexadecimal.
Ethernet protocol: It is a widely used LAN technology and a protocol applied at the data link layer. Ethernet can be used to complete the transmission of data frames from adjacent devices:
LAN classification:
Ethernet IEEE802.3
-
Ethernet, the first widely deployed high-speed local area network;
-
Ethernet data rates are fast;
-
Ethernet hardware is cheap and the network cost is low.
Ethernet frame structure
-
Type: identifies the upper layer protocol (2 bytes);
-
Destination address and source address: MAC address (6 bytes each);
-
Data: Encapsulated upper layer protocol packet (46~1500 bytes);
-
CRC: cyclic redundancy code (4 bytes);
-
The shortest Ethernet frame: The shortest Ethernet frame is 64 bytes; the Ethernet frame is 18 bytes except for the data part; the shortest data is 46 bytes.
MAC address (physical address, LAN address)
-
The MAC address length is 6 bytes and 48 bits;
-
The MAC address is unique, and each network adapter corresponds to a MAC address;
-
Usually hexadecimal notation is used, each byte represents a hexadecimal number, connected with - or:;
-
MAC broadcast address: FF-FF-FF-FF-FF-FF.
Network layer
The purpose of the network layer is to realize transparent transmission of data between two end systems. Specific functions include addressing and routing, connection establishment, maintenance and termination, etc. Data exchange technology is message exchange (basically replaced by packets): a store-and-forward method is used, and the unit of data exchange is a message.
There are many protocols involved in the network layer, including the most important protocol and the core protocol of TCP/IP - IP protocol. The IP protocol is very simple and only provides unreliable, connectionless transmission services. The main functions of the IP protocol are: connectionless datagram transmission, datagram routing and error control.
Also used in conjunction with the IP protocol to implement its functions are the Address Resolution Protocol ARP, the Reverse Address Resolution Protocol RARP, the Internet Message Protocol ICMP, and the Internet Group Management Protocol IGMP.
We will summarize the specific protocols in the next section. The key points about the network layer are:
1. The network layer is responsible for routing data packets between subnets. In addition, the network layer can also implement functions such as congestion control and Internet interconnection;
2. The basic data unit is IP datagram;
3. Main agreements included:
-
IP Protocol (Internet Protocol, Internet Internet Protocol);
-
ICMP protocol (Internet Control Message Protocol, Internet Control Message Protocol);
-
ARP protocol (Address Resolution Protocol, Address Resolution Protocol);
-
RARP protocol (Reverse Address Resolution Protocol, reverse address resolution protocol).
4. Important equipment: router.
Router related protocols:
01
Detailed explanation of IP protocol
IP Internet Protocol is the core protocol of the Internet network layer.
The emergence of virtual Internet networks: The actual computer network is intricate; physical devices shield the differences between physical networks by using IP protocols; when hosts in the network are connected using IP protocols, there is no need to pay attention to network details, thus forming a virtual network.
The IP protocol turns a complex actual network into a virtual interconnected network; and solves the problem of datagram transmission paths in the virtual network.
Among them, version refers to the version of the IP protocol, occupying 4 digits, such as IPv4 and IPv6;
The header length indicates the IP header length, which occupies 4 bits, and the maximum value is 15 bits;
The total length indicates the total length of the IP datagram, accounting for 16 bits, and the maximum value is 65535 bits;
TTL indicates the life span of IP data packets in the network, accounting for 8 bits;
The protocol indicates what protocol the specific data carried by the IP data is, such as TCP and UDP.
02
Forwarding process of IP protocol
03
Subnetting of IP addresses
Class A (8 network numbers + 24 host numbers), Class B (16 network numbers + 16 host numbers), and Class C (24 network numbers + 8 host numbers) can be used to identify hosts or routers in the network. Class D addresses are used as Group broadcast address, Class E is an address reserved.
04Network
address translation NAT technology
It is used in private networks where multiple hosts access the Internet through a public IP, which slows down the consumption of IP addresses but increases the complexity of network communication.
How NAT works:
For IP datagrams going out from the intranet, the IP address is replaced with the legal public IP address owned by the NAT server, and the replacement relationship is recorded in the NAT translation table;
For IP datagrams returned from the public Internet, the NAT translation table is retrieved based on its destination IP address, and the destination IP address is replaced with the retrieved internal private IP address, and the IP datagram is then forwarded to the internal network.
05
ARP protocol and RARP protocol
Address Resolution Protocol ARP (Address Resolution Protocol): Provides dynamic mapping from the IP address of the network card (network adapter) to the corresponding hardware address. The network layer 32-bit address can be converted into the data link layer MAC 48-bit address.
ARP is plug-and-play. An ARP table is automatically created and does not need to be configured by the system administrator.
RARP (Reverse Address Resolution Protocol) protocol refers to the reverse address resolution protocol, which can convert the data link layer MAC 48-bit address into a network layer 32-bit address.
06
Detailed explanation of ICMP protocol
Internet Control Message Protocol (Internet Control Message Protocol) can report error messages or abnormal situations. ICMP messages are encapsulated in IP datagrams.
Application of ICMP protocol:
07
Network layer routing overview
Regarding routing algorithm requirements:
It should be correct and complete, computationally simple as possible, adaptable to changes in the network, stable and fair.
Autonomous system AS:
Refers to a network equipment group under a management organization. The AS internal network is autonomously managed and provides one or more entrances and exits to the outside world. The routing protocol inside the autonomous system is an internal gateway protocol, such as RIP, OSPF, etc.; the routing protocol outside the autonomous system is External gateway protocols such as BGP.
Static routing:
Manual configuration is difficult and complex.
Dynamic routing:
-
Link state routing algorithm LS: sending information to all neighboring routes has fast convergence; global routing algorithm, each router needs to construct the entire network topology map when calculating routes; use Dijkstra algorithm to find the shortest path from the source to the destination network ;Dijkstra (Dijkstra) algorithm;
-
Distance-vector routing algorithm DV: Sending information to all neighbor routes converges slowly and may cause loops; the basis is the Bellman-Ford equation (referred to as the BF equation).
08Interior
Gateway Routing Protocol RIP Protocol
Routing Information Protocol RIP (Routing Information Protocol) [application layer], based on distance-vector routing algorithm, smaller AS (autonomous system), suitable for small networks; RIP messages are encapsulated into UDP datagrams.
RIP protocol features:
-
RIP uses hop count when measuring paths (each router maintains a record of the distance from itself to every other router);
-
The cost of RIP is defined between the source router and the destination subnet;
-
The network diameter restricted by RIP does not exceed 15 hops;
-
Exchange all information with the neighbor, 30 active times (broadcast).
09Interior
Gateway Routing Protocol OSPF Protocol
Open Shortest Path First protocol OSPF (Open Shortest Path First) [network layer], a routing algorithm based on link status (i.e. Dijkstra algorithm), larger AS, suitable for large networks, directly encapsulated in IP datagram transmission.
Advantages of OSPF protocol:
-
Safety;
-
Support multiple paths with the same cost;
-
Support differentiated cost measurement;
-
Support unicast routing and multicast routing;
-
Hierarchical routing.
Comparison between RIP and OSPF (the routing algorithm determines its nature):
10External
gateway routing protocol BGP protocol
BGP (Border Gateway Protocol) Border Gateway Protocol [Application Layer]: It is a protocol that runs between ASs. It looks for a good route: all information is exchanged for the first time, and only the changed parts are exchanged later. BGP encapsulates it into TCP segments.
transport layer
The first is end-to-end, that is, the host-to-host level. The transport layer is responsible for segmenting upper layer data and providing end-to-end, reliable or unreliable transport.
In addition, the transport layer also handles end-to-end error control and flow control issues.
The task of the transport layer is to make optimal use of network resources based on the characteristics of the communication subnet, provide functions for establishing, maintaining, and canceling transmission connections between the session layers of two end systems, and is responsible for end-to-end reliable data transmission.
At this layer, the protocol data units for information transfer are called segments or messages.
The network layer only transmits the data packets sent by the source node to the destination node according to the network address, while the transport layer is responsible for reliably transmitting the data to the corresponding port.
Important points about the network layer:
-
The main protocols included: TCP protocol (Transmission Control Protocol, Transmission Control Protocol), UDP protocol (User Datagram Protocol, User Datagram Protocol);
01
Detailed explanation of UDP protocol
UDP (User Datagram Protocol: User Datagram Protocol) is a very simple protocol.
Features of UDP protocol:
-
UDP is a connectionless protocol;
-
UDP does not guarantee reliable delivery of data;
-
UDP is oriented towards message transmission;
-
UDP has no congestion control;
-
UDP header overhead is very small.
UDP datagram structure:
Header: 8B, four fields/2B [source port | destination port | UDP length | checksum] Data field: application data.
02
Detailed explanation of TCP protocol
TCP (Transmission Control Protocol: Transmission Control Protocol) is a very complex protocol in computer networks.
Functions of TCP protocol:
-
Segment and reassemble application layer messages;
-
Implement reuse and decomposition for the application layer;
-
Implement end-to-end traffic control;
-
congestion control;
-
Transport layer addressing;
-
Perform error detection on received messages (error detection on both header and data parts);
-
Realize end-to-end reliable data transmission control between processes.
Characteristics of TCP protocol:
-
TCP is a connection-oriented protocol;
-
TCP is a byte stream-oriented protocol;
-
A TCP connection has two ends, that is, point-to-point communication;
-
TCP provides reliable transmission services;
-
The TCP protocol provides full-duplex communication (each TCP connection can only be one-to-one).
TCP segment structure:
Maximum segment length: The maximum length of application layer data encapsulated in the segment.
TCP header:
-
Sequence number field: TCP’s sequence number is to number each byte of each application layer data;
-
Confirmation sequence number field: The byte sequence number expected to be received from the other party, that is, the byte corresponding to this sequence number has not yet been received. Identified with ack_seq;
-
The minimum header length of a TCP segment is 20B and the maximum length is 60 bytes. But the length must be an integer multiple of 4B.
The role of TCP tags:
03Basic
principles of reliable transmission
Fundamental:
-
Situations that may occur during data transmission on unreliable transmission channels: bit errors, disorder, retransmission, and loss;
-
Measures taken to achieve reliable data transmission based on unreliable channels.
Error detection: Using coding to detect bit errors during data packet transmission.
Confirmation: The receiving direction feeds back the receiving status to the sender.
Retransmission: The sender resends data that the receiver did not receive correctly.
Serial number: Ensure that data is submitted in order.
Timer: Solve data loss problem.
Stop-and-wait protocol: It is the simplest reliable transmission protocol, but its channel utilization is not high.
Continuous ARQ (Automatic Repeat reQuest) protocol: sliding window + cumulative confirmation, which greatly improves channel utilization.
Reliable transmission of TCP protocol:
Based on the continuous ARQ protocol, in some cases, the retransmission efficiency is not high, and some bytes that have been successfully received will be repeatedly transmitted.
Flow control of TCP protocol:
Flow control: Let the sender not send too fast. The TCP protocol uses a sliding window to achieve flow control.
04
Congestion control of TCP protocol
The difference between congestion control and flow control:
Flow control considers the control of point-to-point traffic, while congestion control considers the entire network and is a global consideration. Congestion control method: slow start algorithm + congestion avoidance algorithm.
Slow start and congestion avoidance:
-
[Slow start] The congestion window grows exponentially from 1;
-
When the threshold is reached, it enters [Congestion Avoidance] and becomes +1 growth;
-
[Timeout], the threshold becomes half of the current cwnd (cannot be <2);
-
From [Slow Start] again, the congestion window grows exponentially from 1.
Fast retransmission and fast recovery:
-
The sender receives 3 redundant ACKs in a row and performs [fast retransmission] without waiting for the timer to expire;
-
Execute [Quick Recovery], the threshold becomes half of the current cwnd (cannot be <2), and enter [Congestion Avoidance] from this new ssthresh point.
05
Three-way handshake of TCP connection (important)
TCP three-way handshake instructions:
Interview Frequent: Why is a three-way handshake needed?
-
The first handshake: the client sends a request, and the server knows that the client can send it;
-
Second handshake: The server sends a confirmation. At this time, the client knows that the server can send and receive;
-
The third handshake: the client sends a confirmation, and the server knows that the client can receive it.
Establish connection (three-way handshake):
The first time: the client sends a connection request segment to the server and establishes a connection request control segment (SYN=1), indicating that the sequence number of the first data byte of the transmitted message segment is x, and this sequence number represents the entire message segment. The sequence number (seq=x); the client enters SYN_SEND (synchronous sending state);
The second time: the server sends back a confirmation segment, agrees to establish the confirmation segment of the new connection (SYN=1), confirms that the sequence number field is valid (ACK=1), and the server tells the client that the sequence number of the segment is y (seq=y) , indicating that the server has received the client's message segment with sequence number
The third time: The client confirms the same connection to the server. The sequence number field is confirmed to be valid (ACK=1). The sequence number of the client's message segment this time is x+1 (seq=x+1). The client expects to accept the server sequence. The message segment numbered y+1 (ack_seq=y+1); when the client sends ack, the client enters the ESTABLISHED state; when the service receives the ack sent by the client, it also enters the ESTABLISHED state; the third handshake can be carried data.
06
Four waves of TCP connection (important)
Release the connection (wave four times)
The first time: the client sends a release connection message segment to the server. The sender completes sending the data and requests to release the connection (FIN=1). The sequence number of the first data byte transmitted is x (seq=x); client status Enter FIN_WAIT_1 from ESTABLISHED (terminate wait 1 state);
The second time: the server sends a confirmation segment to the client, confirming that the field number segment is valid (ACK=1), the data sequence number transmitted by the server is y (seq=y), and the server expects to receive the customer data sequence number x+1 (ack_seq=x+1 ); The server status changes from ESTABLISHED to CLOSE_WAIT (closed waiting); after the client receives the ACK segment, it changes from FIN_WAIT_1 to FIN_WAIT_2;
The third time: the server sends a release connection message segment to the client, requesting to release the connection (FIN=1), and confirms that the field number is valid (ACK=1), indicating that the server expects to receive the customer data sequence number x+1 (ack_seq=x+1 ); indicates that the first byte sequence number transmitted by itself is y+1 (seq=y+1); the server status changes from CLOSE_WAIT to LAST_ACK (last confirmation status);
The fourth time: the client sends a confirmation segment to the server, and the confirmation field number segment is valid (ACK=1), which means that the data sequence number transmitted by the client is x+1 (seq=x+1), which means that the client expects to receive the server data sequence number y+1 +1 (ack_seq=y+1+1); the client state changes from FIN_WAIT_2 to TIME_WAIT, waits for 2MSL time, and enters CLOSED state; after the server receives the last ACK, it changes from LAST_ACK to CLOSED.
Why do I need to wait for 2MSL?
-
The last message is not acknowledged;
-
Ensure that the sender's ACK can reach the receiver;
-
If not received within 2MSL, the receiver will resend;
-
Ensure that all messages for the current connection have expired.
Application layer
Provides an interface for an operating system or network application to access network services. Application layer focus:
-
The basic unit of data transmission is the message;
-
Main protocols included: FTP (File Transfer Protocol), Telnet (Remote Login Protocol), DNS (Domain Name Resolution Protocol), SMTP (Mail Transfer Protocol), POP3 Protocol (Post Office Protocol), HTTP Protocol (Hyper Text Transfer Protocol).
01
Detailed explanation of DNS
DNS (Domain Name System: Domain Name System) [C/S, UDP, Port 53]: Solve the problem of complex and difficult to remember IP addresses, store and complete the mapping of domain names to IP addresses of hosts within its jurisdiction.
The order of domain name resolution:
-
browser cache;
-
Find the local hosts file;
-
route cache;
-
Find the DNS server (local domain name, top-level domain name, root domain name) -> iterative resolution, recursive query.
IP—>DNS Service—>A domain name that is easy to remember.
Domain names are composed of dots, letters and numbers, and are divided into top-level domains (com, cn, net, gov, org), second-level domains (baidu, taobao, qq, alibaba), and third-level domains (www) (12-2-0852 ).
02
Detailed explanation of DHCP protocol
DHCP (Dynamic Configuration Protocol: Dynamic Host Setting Protocol): It is a LAN protocol and an application layer protocol that uses UDP protocol. Function: Automatically assign IP addresses to users who temporarily access the LAN.
03
Detailed explanation of HTTP protocol
File Transfer Protocol (FTP): Control connection (port 21): Transmits control information (connection, transfer request) in 7-bit ASCII format. Stay on for the entire session.
HTTP (HyperText Transfer Protocol: Hypertext Transfer Protocol) [TCP, port 80]: It is a reliable data transmission protocol. Before the browser sends and receives messages to the server, it first establishes a TCP connection. HTTP uses the TCP connection method (HTTP itself has no connection ).
HTTP request message method:
-
GET: Request the specified page information and return the entity body;
-
POST: Submit data to the specified resource for processing request;
-
DELETE: Request the server to delete the specified page;
-
HEAD: Requests to read the header of the information identified by the URL, and only returns the message header;
-
OPETION: Request information about some options;
-
PUT: Store a document under the specified URL.
(1) Structure of HTTP work
(2) Detailed explanation of HTTPS protocol
HTTPS (Secure) is a secure HTTP protocol with port number 443. Based on the HTTP protocol, it provides encrypted data processing, verification of the other party's identity, and data integrity protection through SSL or TLS.
This is Yiyijun’s new book, thank you all for your support!
Follow and reply [
1024
] Massive Linux information will be given away
Collection of wonderful articles
Article recommendation
☞
【
Album
】
Introduction to
linux