First understanding of network principles (notes)

Table of contents

​Edit LAN

Network communication basics

IP address

The port number

protocol

Protocol layering

TCP/IP five-layer network model

Basic process of network data transmission

Sender’s situation:

Recipient’s situation


local area network

 When building a network, switches and routers are needed

On the router, there are lan port and wan port

Although the router only has 4 lan ports

In fact, the LAN established can have more devices and can use switches.

The switch's ports are not divided into lan ports and wan ports. All ports are equivalent.

Component enterprise networks often require an enterprise-level router + several enterprise-level switches, extending a lot of network cables for everyone to use.

AP is equivalent to a small switch that does not require plugging in network cables (improving wireless hotspot expansion capabilities)

Router, capable of Layer 3 (network layer) forwarding

The switch performs two-layer (data link layer) forwarding

This definition is based on the classic router/switch definition.

In fact, the differences between modern switches/routers are getting smaller and smaller, and there are many overlaps in their functions.

A hub divides a network cable into multiple forks, but it is essentially different from a switch.

This fork from the switch is independent of each other and does not interfere with each other.

The forks from the hub will cause conflicts.

There is no clear boundary between LAN and WAN

When there are a large number of devices in a local area network and the space span of the local area network is particularly large, it can be called a wide area network.


Network communication basics

IP address

Use an IP address to describe the location of a device on the network


The port number


Used to distinguish different applications on a host

A network program needs to be bound to one or more port numbers when it is started, and subsequent communication processes need to rely on the port for expansion.


protocol

Describes the meaning of data transmitted by network communication

Network communication protocols, although more complex, are essentially some agreed-upon rules.

The Internet has been developing for so many years, and many details have been stipulated in protocols.

The main thing we do is learn the agreements that have been agreed upon

Why should we make a good agreement?

There are many types of computers and many equipment manufacturers. There must be a unified protocol standard so that everyone can develop equipment according to the same standards, so that the things they create can communicate with each other.


Protocol layering

Network communication is a relatively complex job that involves a series of very tedious and detailed tasks.

Relying on one protocol to solve all problems will make the protocol very complex and huge.

Therefore, it is necessary to split the protocols. Since there are many split protocols, these protocols are classified and layered.

For network protocols, they are often divided into several levels for definition.

The upper layer protocol calls the lower layer protocol

The lower layer protocol provides service support to the upper layer protocol

That is to say, these protocols have a clear hierarchical relationship, which can avoid confusion caused by cross-level calls, reduce coupling, and improve the readability of the entire system.

This picture describes the layering very well.

(1) The upper layer does not need to know the details of the lower layer (encapsulation)

(2) Flexible adjustment/replacement of protocols at a certain layer


There are two main ways to layer protocols: OSI seven-layer network model (only in textbooks), TCP/IP five-layer network model

TCP/IP five-layer network model

If you include the physical layer, it’s five layers. If you don’t include the physical layer, it’s four layers.

Because the physical layer is hardware-oriented and has little to do with software. 

Physical layer:

Describes the specifications that some infrastructure in network communications need to comply with

We will agree on the network cable and what the network port looks like.

data link layer

How data is transported between adjacent nodes 

Network layer

Carry out path planning 

Shanghai -> Beijing, there are many routes, and the express delivery company needs to plan which route the goods should take.

transport layer

Only focus on the starting point and end point, not on the intermediate process (where the data starts from and where it goes) 

Application layer

Get this data, what exactly will it be used for?

Different applications will use different application layer protocols to communicate (or may use the same one)

Transport layer protocols and network layer protocols are all built-in in the operating system.

Drivers are provided by hardware manufacturers. The drivers will adapt to the system kernel. Further systems can operate the hardware through the drivers.


Basic process of network data transmission

Summarize it in four words: encapsulation and separation

Take QQ sending messages as an example to introduce the basic process of network data transmission.

A sends the message to host B through QQ

"Five-tuple" in network communication: source ip, source port, destination ip, destination port, protocol type

Sender’s situation:

1. Application layer

The QQ application obtains the message you want to input from the input box and constructs it into an application layer datagram (according to the application layer protocol)

Many applications will customize the application layer protocol. We don’t know what protocol QQ uses.

Assume that QQ's application layer protocol is like this:

The so-called "constructing application layer datagram" process is to concatenate strings according to a certain format.

The sender and receiver need to reach an agreement

The application program will call the interface provided by the transport layer and pass the above data to the outgoing layer for processing.


2. Transport layer

There are many transport layer protocols, the most important of which are TCP and UDP  .

This assumes UDP is used

The above data is transmitted from the application layer to the transport layer and handed over to UDP, so the UDP protocol generates a UDP datagram according to its own format.

UDP does not care about what is in the application layer data and its content. It just treats the application layer data as a string and constructs a UDP datagram.

Similar to when a courier boy picks up a package, he doesn't care about the specific package, but only cares about the size and weight (whether it can fit in the package)

After the courier guy gets the items, he will pack them and put labels on them.

At this time, the transport layer will further hand over the constructed UDP datagram to the network layer


3. Network layer

The most important protocol at the network layer is the IP protocol

The IP protocol will also construct an IP datagram according to its own format.

The IP protocol does not care what the payload content here is, it just treats and as a string, and then splices another IP header on this basis.

Next, the data needs to be transmitted to the data link layer


4. Data link layer

Ethernet (usually you need to plug in a network cable to access the Internet)

Ethernet will further encapsulate the IP datagram and add a data header and data trailer.

Ethernet doesn't care what's in the payload, it just treats the payload as a string, further splices the frame header and frame tail, and constructs an Ethernet data frame.

The above data needs to be further handed over to the physical layer.


5. Physical layer

Hardware device (network card)

They are essentially binary data (composed of a set of 0101)

Hardware equipment needs to convert the above data (optical signal/electrical signal/electromagnetic wave)

At this point, host A has completed the sending process


Recipient’s situation

Here, we do not consider the intermediate process

1. Physical layer

The hardware device receives optical signals/electrical signals/electromagnetic waves, and needs to demodulate the received signals, and obtains a series of 0101 binary data sequences, which are Ethernet data frames.

Modulation: Put the information you want to transmit into the photoelectric signal

Demodulation: extracting information from photoelectric signals

This data needs to be handed over to the upper layer, the data link layer


 2. Data link layer

The Ethernet protocol at the data link layer will parse this data.

 At this time, take out the payload part and hand it over to the upper layer (IP protocol)


3. Network layer

The IP protocol parses this datagram, removes the IP header, takes out the payload, and further passes it to the transport layer.


4. Transport layer

According to the fields in the IP header, we know that the current payload is a UDP datagram, which is handed over to UDP for processing.

UDP also needs to parse the datagram, remove the header, take out the payload, and further hand it over to the application.


 5. Application layer

In the UDP header, there is a field, destination port. If you find the associated application program based on the destination port, just hand it over to this program.

When the qq program receives this data, it will parse it according to the qq application layer protocol.

Display the data here on the page

In QQ, the corresponding avatar starts to flash. Click on it to display the new message and the time of the message.


The process of host A adding headers sequentially from top to bottom is called encapsulation.

The process of host B parsing the headers sequentially from bottom to top is called demultiplexing.

Encapsulation is packaging the express delivery, and splitting is the dismantling of the express delivery.

Every time network data is transmitted, it must go through this process.

The message is forwarded to a certain device. The processing flow of each device is the same as the encapsulation and decentralization above.

If it is a switch , the switch can be used separately in the data link layer.

The switch parses the Ethernet data frame, further obtains the "mac address" in the frame header, queries the forwarding table inside the switch based on the mac address, and determines which network port the next data will be sent from.

Before sending, the Ethernet data frame will be re-encapsulated.

The router encapsulates and applies it to the network layer.

Parse out the IP packet, obtain the IP header, and further plan the next route based on the destination IP in the IP header.

Next, this data will be forwarded

The switch router described above is just a classic switch router

In fact, modern switches and routers will do more things, most likely encapsulation and demultiplexing to the application layer.

Guess you like

Origin blog.csdn.net/weixin_73616913/article/details/132269893