Network communication method, system, terminal device and computer storage medium
By using multi-port plus a single channel in the network communication system, port information is carried for data transmission and restoration, which solves the problems of multi-port and multi-channel lack of scalability and waste of resources in the existing technology, and achieves higher scalability. and resource efficiency.
Patent Information
- Application Number
- CN202211130814.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-16
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-09-16
AI Technical Summary
In the existing network communication method, multiple ports require the creation of multiple channels, which results in lack of scalability. When ports need to be added or deleted, the operating system and hardware need to be redeveloped, resulting in a waste of resources.
By using multiple ports plus a single channel in the network communication system, port information is carried in the data when receiving and sending data to realize data transmission and restoration, avoiding the need to build an independent channel for each port.
It achieves the scalability of network communication, reduces the waste of development and hardware resources, improves the system's modular characteristics and software and hardware reuse rate, and reduces system development and maintenance costs.
Smart Images

Figure CN115484319B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a network communication method, system, terminal equipment and computer storage medium. Background Art
[0002] When communicating over a network, the industrial network protocol stack needs to know the receiving port for each Ethernet data packet and the designated port to send the Ethernet data packet.
[0003] The existing method is that the network card driver in the operating system kernel virtually registers multiple network interfaces (eth0 and eth1) for each network port to provide access to user-mode software. However, since there are only a handful of SoC chips (generally referring to System on Chip, system-level chip) with built-in switches on the market, in order to meet the requirements of industrial Ethernet networks, the existing technology often replaces the SoC chip with a built-in switch by using a common SoC+switch chip ASIC (Application Specific Integrated Circuit) or FPGA (Field Programmable Gate Array), that is: Ethernet data is transmitted between the processor and the switch through two MII / RMII / RGMII / GMII interfaces, or data is transmitted between the processor and the switch through one or more data buses such as qspi, spi, gpmc, sdio, etc.
[0004] However, since the length of network data in network communication is subject to standard restrictions, no matter which existing method is used for network communication, as many channels as there are communication ports are created, resulting in the lack of scalability in both software and hardware implementations. Summary of the invention
[0005] The main purpose of the present invention is to provide a network communication method, system, terminal equipment and computer storage medium, aiming to realize network communication by carrying port information through a multi-port plus a single channel method, thereby effectively solving the technical problems that the existing multi-port and multi-channel network communication method is not scalable, and if the need to increase or decrease ports requires the need to re-develop the operating system, resulting in a waste of development resources and hardware resources.
[0006] To achieve the above object, the present invention provides a network communication method, which is applied to a network communication system including a plurality of ports and a transmission channel, wherein the plurality of ports include a first port for receiving data and a second port for sending data;
[0007] The method includes:
[0008] When the first port receives the first original data, modify the first original data to obtain first modified data, and write the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port;
[0009] Restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and sending the first original data to an upper layer application corresponding to the first port according to the first port information; and / or,
[0010] When the upper layer application corresponding to the second port generates second original data, modify the second original data to obtain second modified data, and write the second modified data into the transmission channel for transmission, wherein the second modified data carries second port information of the second port;
[0011] The second modified data transmitted by the transmission channel is restored to obtain the second original data and the second port information, and the second original data is sent through the second port according to the second port information.
[0012] Optionally, before the step of modifying the first original data to obtain first modified data, the method further includes:
[0013] Determining classification information of raw data to be processed, wherein the raw data to be processed includes the first raw data and the second raw data;
[0014] predefine a received data modification rule according to the classification information;
[0015] Before the step of modifying the second original data to obtain second modified data, the method further includes:
[0016] The sending data modification rule is predefined according to the classification information.
[0017] Optionally, the step of modifying the first original data to obtain first modified data includes:
[0018] Acquire first classification information of the first original data;
[0019] adding the first port information of the first port to the first original data according to the first classification information and the received data modification rule, so as to modify the first original data to obtain first modified data;
[0020] The step of modifying the second original data to obtain second modified data comprises:
[0021] Acquire second classification information of the second original data;
[0022] According to the second classification information and the sending data modification rule, the second port information of the second port is added to the second original data, so as to modify the second original data to obtain second modified data.
[0023] Optionally, the step of adding the first port information of the first port to the first original data according to the first classification information and the received data modification rule includes:
[0024] selecting at least one target byte from the first original data according to the first classification information and the received data modification rule;
[0025] According to the received data modification rule, the first port information of the first port is added to the target byte.
[0026] Optionally, the step of adding the first port information of the first port to the target byte according to the received data modification rule includes:
[0027] Divide the target byte according to the received data modification rule to obtain at least two bit sets, and add the port information of the first port to the first bit set of the two bit sets; or
[0028] According to the received data modification rule, a bit is determined in the target byte as a port indicating bit, and the port information of the first port is added to the port indicating bit.
[0029] Optionally, after the step of dividing the target byte according to the received data modification rule to obtain at least two bit sets, the method further includes:
[0030] The first classification information is added to the second bit set of the two bit sets, so as to send the first original data to the upper layer application according to the first port information and the first classification information.
[0031] Optionally, the step of restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information includes:
[0032] The first modified data transmitted by the transmission channel is restored according to the received data modification rule to obtain the first original data and the first port information added to the first modified data.
[0033] In addition, to achieve the above object, the present invention also provides a network communication system, the system comprising:
[0034] a received data modification module, configured to modify the first original data to obtain first modified data when the first port receives the first original data, and write the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port;
[0035] a receiving data restoration module, configured to restore the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and send the first original data to an upper layer application corresponding to the first port according to the first port information;
[0036] a sending data modification module, configured to modify the second original data to obtain second modified data when an upper layer application corresponding to the second port generates second original data, and write the second modified data into the transmission channel for transmission, wherein the second modified data carries second port information of the second port;
[0037] A sending data restoration module is used to restore the second modified data transmitted by the transmission channel to obtain the second original data and the second port information, and send the second original data through the second port according to the second port information.
[0038] Among them, each functional module of the network communication system of the present invention implements the steps of the network communication method described above when running.
[0039] In addition, to achieve the above-mentioned purpose, the present invention also provides a terminal device, which includes: a memory, a processor, and a network communication program stored in the memory and executable on the processor, and the network communication program, when executed by the processor, implements the steps of the network communication method described above.
[0040] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a network communication program is stored, and when the network communication program is executed by a processor, the steps of the network communication method described above are implemented.
[0041] In addition, to achieve the above object, the present invention also provides a computer program product, wherein the computer program product includes a computer program, and when the computer program is executed by a processor, the steps of the network communication method described above are implemented.
[0042] The present invention provides a network communication method, system, terminal device, computer storage medium and computer program product. In the process of data transmission in the network communication system, when the first port for receiving data among multiple ports of the system receives the first original data, the first original data is first modified to obtain the first modified data carrying the first port information of the first port, and the first modified data is written into the system's only transmission channel for data transmission; then, the system further restores the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, so as to send the first original data to the upper layer application corresponding to the first port for processing according to the first port information. And / or, when the upper layer application corresponding to the second port for sending data among multiple ports of the system generates the second original data, the system also first modifies the second original data to obtain the second modified data carrying the second port information of the second port, and the second modified data is also written into the system's only transmission channel for data transmission; then, the system further restores the second modified data transmitted by the transmission channel to obtain the second original data and the second port information, so that the system interface sends the second original data through the second port according to the second port information.
[0043] Compared with the existing method of constructing a data transmission channel for each communication port to carry out data transmission in network communication, the present invention can realize network communication by carrying port information through a multi-port plus a single channel method. Therefore, the present invention effectively solves the technical problems that the existing multi-port and multi-channel network communication method is not scalable, and if the need to increase or decrease ports requires the need to re-develop the operating system, resulting in a waste of development resources and hardware resources.
[0044] In addition, the present invention also has the characteristics of easy modularization by using multiple ports plus a single channel to perform network communication, and the number of ports can be expanded based on actual application needs. Therefore, the present invention can also effectively improve the reuse rate of software and hardware in the network communication system and reduce the cost of system development and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 A schematic diagram of the device structure of the hardware operating environment of the terminal device involved in the embodiment of the present application;
[0046] Figure 2A and Figure 2B They are respectively flowchart diagrams of a network communication method provided in an embodiment of the present application;
[0047] Figure 3A This is a block diagram of a SoC involved in an embodiment of the present application;
[0048] Figure 3BA schematic diagram of data transmission and reception between hardware and industrial Ethernet protocol stack software involved in an embodiment of the present application;
[0049] Figure 4 A schematic diagram of data transmission and reception using standard Ethernet communication according to an embodiment of the present application;
[0050] Figure 5 A schematic diagram of data transmission and reception using other communication buses according to an embodiment of the present application;
[0051] Figure 6 A schematic diagram of the receiving and sending ends involved in an embodiment of the present application;
[0052] Figure 7 A structural block diagram of a multi-port communication port identification system involved in an embodiment of a network communication method provided in an embodiment of the present application;
[0053] Figure 8 This is a schematic diagram of an Ethernet frame structure involved in an embodiment of the present application;
[0054] Fig. 9 A schematic diagram of receiving direction data modification involved in an embodiment of a network communication method provided in an embodiment of the present application;
[0055] Fig.10 A schematic diagram of data modification in the sending direction involved in an embodiment of a network communication method provided in an embodiment of the present application;
[0056] Fig.11 A schematic diagram showing a comparison before and after using the method in a SoC solution with a switch involved in an embodiment of a network communication method provided in an embodiment of the present application;
[0057] Fig.12 A schematic diagram showing a comparison before and after the use of the method in an external switch hardware solution involved in an embodiment of a network communication method provided in an embodiment of the present application;
[0058] Fig.13 A schematic diagram of the functional modules of a network communication system provided in one embodiment of the present application.
[0059] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0060] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0061] Reference Figure 1 , Figure 1 This is a schematic diagram of the device structure of the hardware operating environment of the terminal device involved in the embodiment of the present application.
[0062] The terminal device of the embodiment of the present application can be a terminal device configured as a network communication system for transmitting data in network communication in a multi-port plus single channel manner, carrying port information. The terminal device can be a server, a smart phone, a PC (Personal Computer), a tablet computer, a portable computer, etc.
[0063] like Figure 1 As shown, the terminal device may include: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM memory, or it may be a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may optionally be a storage device independent of the aforementioned processor 1001.
[0064] Those skilled in the art will understand that Figure 1 The terminal device structure shown in the figure does not constitute a limitation on the terminal device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0065] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module and a network communication program.
[0066] exist Figure 1 In the terminal shown, the network interface 1004 is mainly used to connect to the backend server and perform data communication with the backend server; the user interface 1003 is mainly used to connect to the client and perform data communication with the client; and the processor 1001 can be used to call the network communication program stored in the memory 1005 and perform the following steps:
[0067] When the first port receives the first original data, modify the first original data to obtain first modified data, and write the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port;
[0068] Restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and sending the first original data to an upper layer application corresponding to the first port according to the first port information; and / or,
[0069] When the upper layer application corresponding to the second port generates second original data, modify the second original data to obtain second modified data, and write the second modified data into the transmission channel for transmission, wherein the second modified data carries second port information of the second port;
[0070] The second modified data transmitted by the transmission channel is restored to obtain the second original data and the second port information, and the second original data is sent through the second port according to the second port information.
[0071] Further, the processor 1001 may be used to call the network communication program stored in the memory 1005, and before executing the step of modifying the first original data to obtain the first modified data, further execute the following steps:
[0072] Determining classification information of raw data to be processed, wherein the raw data to be processed includes the first raw data and the second raw data;
[0073] predefine a received data modification rule according to the classification information;
[0074] The processor 1001 may be used to call the network communication program stored in the memory 1005, and before executing the step of modifying the second original data to obtain the second modified data, further execute the following steps:
[0075] The sending data modification rule is predefined according to the classification information.
[0076] Further, the processor 1001 may be used to call the network communication program stored in the memory 1005, and further perform the following steps:
[0077] Acquire first classification information of the first original data;
[0078] adding the first port information of the first port to the first original data according to the first classification information and the received data modification rule, so as to modify the first original data to obtain first modified data;
[0079] And, obtaining second classification information of the second original data;
[0080] According to the second classification information and the sending data modification rule, the second port information of the second port is added to the second original data, so as to modify the second original data to obtain second modified data.
[0081] Further, the processor 1001 may be used to call the network communication program stored in the memory 1005, and further perform the following steps:
[0082] selecting at least one target byte from the first original data according to the first classification information and the received data modification rule;
[0083] According to the received data modification rule, the first port information of the first port is added to the target byte.
[0084] Further, the processor 1001 may be used to call the network communication program stored in the memory 1005, and further perform the following steps:
[0085] Divide the target byte according to the received data modification rule to obtain at least two bit sets, and add the port information of the first port to the first bit set of the two bit sets; or
[0086] According to the received data modification rule, a bit is determined in the target byte as a port indicating bit, and the port information of the first port is added to the port indicating bit.
[0087] Further, the processor 1001 may be used to call the network communication program stored in the memory 1005, and after executing the step of dividing the target byte according to the received data modification rule to obtain at least two bit sets, further execute the following steps:
[0088] The first classification information is added to the second bit set of the two bit sets, so as to send the first original data to the upper layer application according to the first port information and the first classification information.
[0089] Further, the processor 1001 may be used to call the network communication program stored in the memory 1005, and further perform the following steps:
[0090] The first modified data transmitted by the transmission channel is restored according to the received data modification rule to obtain the first original data and the first port information added to the first modified data.
[0091] Based on the above-mentioned terminal device, various embodiments of the network communication method of the present invention are proposed.
[0092] It should be noted that in existing industrial network communication technologies, some industrial network protocol stacks send and receive data through multiple physical communication ports, and the protocol stack software needs to know which port the received network data packet is received from when receiving, and also needs to send data through the specified port when sending. In addition, since the length of network data cannot be changed, such as the maximum length of a frame of Ethernet data is fixed, and the transmission channel is also standard, it is impossible to carry port information by adding additional data. Therefore, the existing method generally creates multiple channels according to the number of ports, so that the channels correspond to the ports one by one, and the source port is known when the data packet is received from the channel, and the data is sent to the channel corresponding to the port when sending.
[0093] In this case, the channel is a hardware interface or software implementation, such as Figure 3A As shown in the figure, the network card of SoC is a three-port switch. When communicating over the network, the industrial network protocol stack needs to know the receiving port of each Ethernet data packet and the designated port to send the Ethernet data packet. However, due to the existence of the operating system, the network protocol stack cannot directly operate the hardware, but can only use the network protocol stack as a channel for data transmission through the operating system. Therefore, Figure 3B As shown, in the existing method, the network card driver in the operating system kernel virtually registers multiple network interfaces (eth0 and eth1) for each network port to provide them to user-mode software for access.
[0094] However, since there are only a handful of SoC chips with built-in switches on the market, most of them are replaced by ordinary SoC + switch chips (ASIC or FPGA) to meet the requirements of industrial Ethernet networks. Under the alternative solution, the problem of how the industrial Ethernet protocol stack can send and receive data through the two ports of the switch is more prominent. In response to this, traditional network communication systems usually use the following two methods to obtain port information:
[0095] First, if Figure 4 As shown, Ethernet data is transmitted between the processor and the switch through two MII / RMII / RGMII / GMII interfaces, but this method has the following disadvantages: namely, the SoC chip must support two MACs, which increases the cost, and the operating system needs to develop drivers, which increases the complexity.
[0096] Second, if Figure 5As shown, the processor and the switch transmit data through one or more data buses such as QSPI, SPI, GPMC, SDIO, etc. (non-standard interface, generally FPGA is used to implement the switch). Since this path protocol can be customized, the sending and receiving port information of the Ethernet data frame can be added at will. The disadvantages of this method are: the standard physical link of the original Ethernet transmission is changed, resulting in increased transmission delay and poor real-time performance. The processor side needs to develop additional device drivers to access the operating system network protocol stack. Adding or reducing ports or modifying the communication bus requires redevelopment, and replacing the data bus also requires redevelopment.
[0097] In summary, since the length of network data in network communication is subject to standard restrictions, port information cannot be added to the data, so that no matter what existing method is used for network communication, as many channels as there are communication ports are created, which results in both software and hardware implementations being non-scalable. In addition, when ports need to be increased or decreased due to changes in communication requirements, the operating system needs to be redeveloped accordingly, resulting in a waste of development resources and hardware resources.
[0098] In view of the above problems, the present application provides a network communication method. In the process of data transmission in a network communication system, when a first port for receiving data among multiple ports of the system receives first original data, the method first modifies the first original data to obtain first modified data carrying the first port information of the first port, and writes the first modified data into the system's only transmission channel for data transmission; then, the system further restores the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, thereby sending the first original data to the upper layer application corresponding to the first port for processing according to the first port information. Alternatively, when the upper layer application corresponding to the second port for sending data among multiple ports of the system generates second original data, the system also first modifies the second original data to obtain second modified data carrying the second port information of the second port, and writes the second modified data into the system's only transmission channel for data transmission; then, the system further restores the second modified data transmitted by the transmission channel to obtain the second original data and the second port information, so that the system interface sends the second original data through the second port according to the second port information.
[0099] Compared with the existing method of constructing a data transmission channel for each communication port to carry out data transmission in network communication, the present invention can realize network communication by carrying port information through a multi-port plus a single channel method. Therefore, the present invention effectively solves the technical problems that the existing multi-port and multi-channel network communication method is not scalable, and if the need to increase or decrease ports requires the need to re-develop the operating system, resulting in a waste of development resources and hardware resources.
[0100] In addition, the present invention also has the characteristics of easy modularization by using multiple ports plus a single channel to perform network communication, and the number of ports can be expanded based on actual application needs. Therefore, the present invention can also effectively improve the reuse rate of software and hardware in the network communication system and reduce the cost of system development and maintenance.
[0101] Please refer to Figure 2A and Figure 2B , Figure 2A and Figure 2B Each of them is a flowchart of the first embodiment of the network communication method provided by the present invention. It should be noted that although the logical sequence is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than here.
[0102] In this embodiment, the network communication method of the present invention is applicable to the terminal device configured as the network communication system to transmit the data in the network communication in a multi-port plus single channel manner, carrying the port information. For ease of understanding, in each embodiment of the network communication method of the present invention hereinafter, the network communication method of the present invention is described with the network communication system as the execution subject.
[0103] In addition, it should be noted that, in this embodiment, the network communication system includes a plurality of ports and a transmission channel, and the plurality of ports include a first port for receiving data and a second port for sending data.
[0104] like Figure 6 and Figure 7 As shown, Figure 7 As shown, the network communication system involved in the network communication method of the present invention is achieved by adding four parts at both ends of an original data transmission channel: receiving data processing 4, receiving data restoration 1, sending data processing 2, and sending data restoration 3, and among the four parts, only one data transmission channel is shared between the receiving data processing 4 and the receiving data restoration 1, and between the sending data processing 2 and the sending data restoration 3.
[0105] When the system receives data, the received data processing 4 is used to process the received data, that is, to add the receiving port information to the received data according to certain rules, and then the received data restoration 1 is used to restore the original data received by the port and extract the source port information of the original data. When sending data, the sending data processing 2 is used to process the data to be sent, that is, to add the data export information to the data according to certain rules, and then the sending data restoration 3 is used to restore the original data to be sent and extract the corresponding sending port information.
[0106] Based on this, in this embodiment, the network communication method of the present invention includes:
[0107] Step S10, when the first port receives the first original data, modify the first original data to obtain first modified data, and write the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port;
[0108] Optionally, when the network communication system receives the first original data at the first port for receiving external network data among the multiple physical communication ports configured by itself, the network communication system immediately modifies the received first original data through the above-mentioned receiving data processing 4 added at both ends of the data transmission channel to obtain the first modified data carrying the first port information of the first port after the modification. After that, the network communication system further writes the modified first modified data into a data transmission channel configured by itself to perform data transmission operations.
[0109] Step S20, restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and sending the first original data to an upper layer application corresponding to the first port according to the first port information;
[0110] Optionally, after the network communication system writes the above-mentioned first modified data into the data transmission channel for transmission, the network communication system further performs restoration processing on the first modified data transmitted in the transmission channel according to the rules used when performing data modification through the above-mentioned received data restoration 1 added at the other end of the transmission channel, thereby obtaining the first original data received by the above-mentioned first port, and obtaining the first port information of the first port added to the first modified data. Therefore, when the network communication system knows the first port information, it can accurately send the first original data to the upper-layer application corresponding to the first port for response processing according to the first port information.
[0111] Step S30, when the upper layer application corresponding to the second port generates second original data, modify the second original data to obtain second modified data, and write the second modified data into the transmission channel for transmission, wherein the second modified data carries second port information of the second port;
[0112] Optionally, when the network communication system sends the first original data to the upper-layer application corresponding to the first port according to the process described in the above steps S10 and S20, when one or more upper-layer applications corresponding to the second port for receiving external network data among the multiple physical communication ports configured by itself synchronously or asynchronously generate second original data that needs to be sent externally, the second original data can be immediately modified through the above-mentioned sending data processing 2 added at both ends of the data transmission channel to obtain second modified data carrying the second port information of the second port after modification. After that, the network communication system further writes the second modified data obtained after modification into a data transmission channel configured by itself to perform data transmission operations.
[0113] Step S40: Restoring the second modified data transmitted by the transmission channel to obtain the second original data and the second port information, and sending the second original data through the second port according to the second port information.
[0114] Optionally, after the network communication system writes the above-mentioned second modified data into the data transmission channel for transmission, it further performs restoration processing on the second modified data transmitted in the transmission channel according to the rules used when performing data modification on the above-mentioned sending data processing 2 through the sending data restoration 3 added at the other end of the transmission channel, thereby obtaining the second original data generated by one or more upper-layer applications corresponding to the above-mentioned second port, and obtaining the second port information of the second port added to the second modified data. Therefore, when the network communication system learns the second port information, it can specify the second port according to the second port information to perform the operation of sending the second original data to the outside.
[0115] Optionally, in a feasible embodiment, before the above step of “modifying the first original data to obtain first modified data”, the network communication method of the present invention may further include:
[0116] Step A, determining classification information of raw data to be processed, wherein the raw data to be processed includes: first raw data received by the first port, and second raw data sent by the second port;
[0117] Optionally, before the network communication system performs modification processing on the first original data and the second original data respectively through the above-mentioned receiving data processing 4 or sending data processing 2, it further predefines a receiving data modification rule for modifying the data received by the above-mentioned first port, and predefines a sending data modification rule for modifying the data received by the above-mentioned second port.
[0118] That is, the network communication system extracts classification features of the unprocessed original data received by the first port or the unprocessed original data generated by the upper-layer application corresponding to the second port to be sent externally to determine the classification information of the data, so as to predefine the corresponding data modification rules based on the classification information.
[0119] It should be noted that, in this embodiment, the classification information of the original data to be processed includes the frame type, that is, a unicast frame, a multicast frame or a broadcast frame, or other forms of frames.
[0120] For example, assuming that in a network communication system, the Ethernet frame structure of the raw data to be processed received by the first port or generated by the upper layer application corresponding to the second port is as follows: Figure 8 As shown, the network communication system can specifically classify and extract features for the original data to be processed, so as to determine whether the frame type of the original data to be processed is a unicast frame, a multicast frame or a broadcast frame according to the target MAC address in the original data to be processed, and further use the determined frame type as the classification information of the original data to be processed.
[0121] It should be noted that in this embodiment, in addition to determining the frame type through the target MAC address in the Ethernet frame structure of the original data to be processed, the network communication system can of course also determine the frame type through the data frame format or other fields of the original data to be processed.
[0122] In addition, if the above-mentioned original data to be processed is data generated by the upper layer application corresponding to the second port and needs to be sent externally, the source MAC address in the Ethernet frame structure of the data must be the MAC of the local device where the system is located.
[0123] Step B: predefine a received data modification rule according to the classification information.
[0124] Optionally, in the process of predefining the received data modification rules for modifying the data received by the above-mentioned first port, the network communication system can further define different received data modification rules based on the different classification information after performing classification feature extraction on the above-mentioned original data to be processed to determine the classification information of the data.
[0125] That is, when defining the received data modification rules, the network communication system stipulates: based on the classification information of the original data to be processed received by the above-mentioned first port, one or more bytes are selected from the data, and the selected bytes are divided into two parts according to the bit range, one part is used to store the first port information of the first port, and the other part is used to store the data type, and the representation method is specified. In this way, the definition of the received data modification rules for modifying the original data to be processed is completed.
[0126] Exemplarily, as shown in Table 1 below, when defining the modification rules for received data, the network communication system stipulates: select the first byte of the target MAC of the received data, and agree to store the type in the upper 4 bits, and the lower 4 bits are used to represent the first port information of the first port - the port number, and stipulate: the upper 4 bits can represent a range of 0-15, a total of 16 types, and the lower 4 bits can store port numbers from 0-15, a total of 16 ports, or it can also be stipulated that each bit is used to represent a port.
[0127]
[0128]
[0129] Table 1
[0130] Optionally, in another feasible embodiment, before the above step of “modifying the second original data to obtain second modified data”, the network communication method of the present invention may further include:
[0131] Step C: predefine sending data modification rules according to the classification information.
[0132] Optionally, in the process of predefining the sending data modification rules for modifying the data received by the above-mentioned second port, the network communication system can further define different sending data modification rules based on the different classification information after extracting classification features for the above-mentioned original data to be processed to determine the classification information of the data.
[0133] Similarly, when defining the sending data modification rules, the network communication system stipulates: based on the classification information of the original data to be processed generated by the upper-level application corresponding to the above-mentioned second port (also called "sending characteristics"), one or more bytes are selected from the data, and the selected bytes are divided into two parts according to the bit range, one part is used to store the first port information of the first port, and the other part is used to store the data type, and the representation method is specified. In this way, the definition of the sending data modification rules for modifying the original data to be processed is completed.
[0134] Exemplarily, as shown in Table 2 below, since the source MAC address must be the local MAC address when sending an Ethernet frame, the network communication system can stipulate when defining the data modification rules for sending data: select any byte of the source MAC and use the entire byte to represent the second port information of the second port used to send data - the port number.
[0135]
[0136] Table 2
[0137] Optionally, based on the received data modification rule and the sent data modification rule predefined in the network communication method of the present invention, in a feasible embodiment, the step of "modifying the first original data to obtain first modified data" in the above step S10 may include:
[0138] Step S101, obtaining first classification information of the first original data;
[0139] Step S102, adding first port information of the first port to the first original data according to the first classification information and the received data modification rule, so as to modify the first original data to obtain first modified data;
[0140] Optionally, after the network communication system defines the above-mentioned receiving data modification rule for modifying the data received by the first port, when the first original data originating from the outside is received by the first port, the receiving data processing 4 is first used to classify and extract features for the first original data, thereby obtaining the first classification information of the first original data. Afterwards, the receiving data processing 4 further adds the first port information of the first port to the first original data according to the first classification information and the above-mentioned receiving data modification rule that has been defined, and identifies the first port information according to the rule, thereby completing the modification of the first original data to obtain the above-mentioned first modified data carrying the first port information.
[0141] Optionally, in a feasible embodiment, the step of “adding the first port information of the first port to the first original data according to the first classification information and the received data modification rule” in the above step S102 may include:
[0142] Step S1021, selecting at least one target byte from the first original data according to the first classification information and the received data modification rule;
[0143] Optionally, when the network communication system modifies the first original data received at the first port, it first matches one or more target bytes that currently need to be selected from the first original data from the above-mentioned predefined received data modification rules based on the first classification information of the first original data: unicast frame, multicast frame or broadcast frame, etc.
[0144] For example, Fig. 9 As shown, assuming that the first classification information of the first original data received by the first port is a unicast frame, the network communication system can select the first byte in the data target MAC corresponding to "unicast frame" based on the predefined received data modification rule, and determine that when the first original data is currently modified by the above-mentioned received data processing 4, the first byte should be extracted from the target MAC of the first original data as the target byte for the subsequent addition of the port number.
[0145] Step S1022: adding the first port information of the first port to the target byte according to the received data modification rule.
[0146] Optionally, after the network communication system extracts one or more target bytes from the first original data according to the first classification information of the first original data received by the first port and a predefined received data modification rule, the network communication system may further add the first port information of the first port, namely the port number, to the byte according to the received data modification rule.
[0147] Optionally, in a feasible embodiment, the above step S1022 may include:
[0148] Divide the target byte according to the received data modification rule to obtain at least two bit sets, and add the port information of the first port to the first bit set of the two bit sets;
[0149] Optionally, when the network communication system adds the first port information of the first port to one or more target bytes in the first original data according to the above-mentioned received data modification rule, the network communication system first divides the target byte into two parts according to the bit range as two bit sets based on the received data modification rule, and then adds the first port information-the port number to the first bit set (one of the two bit ranges) in the two bit sets according to the rule.
[0150] For example, as shown in Table 1 above, since the network communication system stipulates when defining the received data modification rule: select the first byte of the target MAC of the received data, and agree to store the type in the upper 4 bits, and the lower 4 bits are used to represent the first port information of the first port - the port number. Therefore, when the network communication system modifies the first original data according to the defined received data modification rule, it can select the first byte of the target MAC of the first original data as the target byte, and divide the target byte into two bit sets of the upper 4 bits and the lower 4 bits, and then add the first port information of the first port - the port number - to the bit set of the lower 4 bits according to the agreement.
[0151] Optionally, in a feasible embodiment, after the above step of “dividing the target byte according to the received data modification rule to obtain at least two bit sets”, the network communication method may further include:
[0152] The first classification information is added to the second bit set of the two bit sets, so as to send the first original data to the upper layer application according to the first port information and the first classification information.
[0153] Optionally, after the network communication system divides one or more target bytes in the first original data into two parts as two bit sets according to the bit range according to the above-mentioned received data modification rule, it also synchronously adds the first classification information of the first original data - unicast, multicast or broadcast - to the second bit set (the other part of the two bit ranges) in the two bit sets according to the rule. In this way, when the network communication system subsequently performs data restoration to obtain the first port information of the first original data, so that the first original data can be accurately sent to the upper-layer application for response processing according to the first port information, the network communication system can specifically send data to the upper-layer application through the first port in accordance with the first classification information obtained synchronously, in a data sending mode corresponding to unicast, multicast or broadcast.
[0154] For example, as shown in Table 1 above, it is assumed that the network communication system stipulates when defining the received data modification rule: select the first byte of the target MAC of the received data, and agree to store the type in the upper 4 bits, and the lower 4 bits are used to represent the first port information of the first port - the port number, and at the same time stipulate: the upper 4 bits can represent a range of 0-15, a total of 16 types. Therefore, when the network communication system modifies the first original data according to the defined received data modification rule, it selects the first byte of the target MAC of the first original data as the target byte, and divides the target byte into two bit sets of upper 4 bits and lower 4 bits. After that, the first port information of the first port - the port number can be added to the lower 4 bits according to the agreement, and the first classification information - unicast, multicast or broadcast can be added to the upper 4 bits according to the agreement.
[0155] Optionally, in a feasible embodiment, the above step S1022 may further include:
[0156] According to the received data modification rule, a bit is determined in the target byte as a port indicating bit, and the port information of the first port is added to the port indicating bit.
[0157] Optionally, when the network communication system adds the first port information of the first port to one or more target bytes in the first original data in accordance with the above-mentioned received data modification rule, it can also first determine one of the bits of the target byte as the port representation bit based on the received data modification rule, and then add the first port information-the port number-to the port representation bit.
[0158] For example, it is assumed that the network communication system stipulates when defining the received data modification rule: select the first byte of the target MAC of the received data, and agree to use each bit of the byte to represent a port. Therefore, when the network communication system modifies the first original data according to the defined received data modification rule, it can select the first byte of the target MAC of the first original data as the target byte, and use one of the bits in the target byte as the port representation bit of the first port. After that, the network communication system can directly add the first port information of the first port, that is, the port number, to the port representation bit.
[0159] Optionally, in a feasible embodiment, the step of “restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information” in the above step S20 may include:
[0160] Step S201 : restoring the first modified data transmitted by the transmission channel according to the received data modification rule to obtain the first original data and the first port information added to the first modified data.
[0161] It should be noted that, in this embodiment, the network communication system can define the received data modification rules for modifying the received data in advance through negotiation, that is, synchronize the received data modification rules to the received data processing 4 and received data restoration 1 added by the system itself at both ends of the transmission channel.
[0162] In this way, after the network communication system transmits the first modified data obtained by modifying the above-mentioned first original data according to the received data to the other end through the transmission channel, the received data restoration 1 at the other end can restore the first modified data according to the same received data modification rule that has been negotiated in advance, thereby restoring the first original data before the modification, and extracting the first port information of the first port carried in the first modified data.
[0163] In addition, in a feasible embodiment, the step of "modifying the second original data to obtain second modified data" in the above step S30 may include:
[0164] Step S301, obtaining second classification information of the second original data;
[0165] Step S302: adding the second port information of the second port to the second original data according to the second classification information and the sending data modification rule, so as to modify the second original data to obtain second modified data.
[0166] Optionally, after the network communication system defines the above-mentioned sending data modification rule for modifying the data generated by the upper-layer application corresponding to the second port, when one or more upper-layer applications corresponding to the second port generate second original data that needs to be sent externally, the second original data is first classified and features are extracted through the above-mentioned sending data processing 2, so as to obtain second classification information of the second original data. Afterwards, the sending data processing 2 further adds the second port information of the second port to the second original data according to the second classification information and the defined sending data modification rule, and identifies the second port information according to the rule, so as to complete the modification of the second original data to obtain the above-mentioned second modified data carrying the second port information.
[0167] Optionally, in a feasible embodiment, the step of "adding the second port information of the second port to the second original data according to the second classification information and the sending data modification rule" in the above step S302 may include:
[0168] Step S3021, selecting at least one target byte from the second original data according to the second classification information and the sending data modification rule;
[0169] Optionally, when the network communication system modifies the second original data generated by one or more upper-layer applications corresponding to the second port, it first matches one or more target bytes that currently need to be selected from the second original data from the above-defined sending data modification rules based on the second classification information of the second original data: unicast frame, multicast frame or broadcast frame, etc.
[0170] For example, Fig.10 As shown, assuming that the second classification information of the second original data generated by an upper-layer application corresponding to the second port is a unicast frame, the network communication system can select the first byte in the data target MAC corresponding to "unicast frame" based on the predefined sending data modification rule, and determine that when the second original data is currently modified by the above-mentioned sending data processing 4, the first byte should be extracted from the target MAC of the second original data as the target byte for subsequently adding the port number.
[0171] Step S3022: adding the second port information of the second port to the target byte according to the sending data modification rule.
[0172] Optionally, after the network communication system extracts one or more target bytes from the second original data according to a predefined sending data modification rule in the second classification information of the second original data, the network communication system can further divide the byte into two parts according to the bit range according to the sending data modification rule, and add the second port information of the second port, namely the port number, in one of the bit ranges.
[0173] It should be noted that, in this embodiment, the specific implementation process of the network communication system adding the second port information to the target byte of the second original data is the same as the process of the above-mentioned network communication system adding the first port information to the target byte of the first original data, and will not be repeated here.
[0174] Optionally, in a feasible embodiment, the step of “restoring the second modified data transmitted by the transmission channel to obtain the second original data and the second port information” in the above step S40 may include:
[0175] Step S401: restore the second modified data transmitted by the transmission channel according to the transmission data modification rule to obtain the second original data and the second port information added to the second modified data.
[0176] It should be noted that, in the present embodiment, similarly, the network communication system can, in advance through negotiation, define a sending data modification rule for modifying the data generated by the upper-layer application corresponding to the second port, that is, synchronize the sending data modification rule to the sending data processing 2 and sending data restoration 3 added by the system itself at both ends of the transmission channel.
[0177] In this way, after the network communication system transmits the second modified data obtained by modifying the above-mentioned second original data according to the sending data to the other end through the transmission channel, the sending data restoration 3 at the other end can restore the second modified data according to the same sending data modification rule that has been negotiated in advance, thereby restoring the second original data before the modification, and extracting the second port information of the second port carried in the second modified data.
[0178] In this embodiment, the network communication method provided by the present invention is that when the network communication system receives the first original data at the first port for receiving external network data among the multiple physical communication ports configured by itself, the network communication system immediately modifies the received first original data through the above-mentioned receiving data processing 4 added at both ends of the data transmission channel to obtain the first modified data carrying the first port information of the first port after modification. After that, the network communication system further writes the first modified data obtained after modification into a data transmission channel configured by itself to perform data transmission operation; after that, the network communication system further restores the first modified data transmitted in the transmission channel according to the rules used when modifying the data through the above-mentioned receiving data restoration 1 added at the other end of the transmission channel, thereby obtaining the first original data received by the above-mentioned first port, and obtaining the first port information of the first port added in the first modified data. Therefore, when the network communication system learns the first port information, it can accurately send the first original data to the upper-layer application corresponding to the first port according to the first port information for response processing by the application.
[0179] In addition, when one or more upper-layer applications corresponding to a second port for receiving external network data among a plurality of physical communication ports configured by the network communication system generates second original data that needs to be sent externally, the network communication system can immediately modify the second original data through the sending data processing 2 added at both ends of the data transmission channel to obtain second modified data carrying the second port information of the second port after modification. After that, the network communication system further writes the second modified data obtained after modification into a data transmission channel configured by itself to perform data transmission operations; after that, the network communication system can restore the second modified data transmitted in the transmission channel according to the rules used when modifying the data through the sending data restoration 3 added at the other end of the transmission channel, thereby obtaining the second original data generated by one or more upper-layer applications corresponding to the second port, and obtaining the second port information of the second port added in the second modified data. Therefore, when the network communication system learns the second port information, it can specify the second port according to the second port information to perform data transmission operations on the second original data.
[0180] So, like Fig.11 and Fig.12 As shown, compared with the existing method of constructing a data transmission channel for each communication port to carry out data transmission in network communication, the present invention can realize network communication by carrying port information through a multi-port plus a single channel method. Therefore, the present invention effectively solves the technical problems that the existing multi-port and multi-channel network communication method is not scalable, and if the need to increase or decrease ports requires the need to re-develop the operating system, resulting in a waste of development resources and hardware resources.
[0181] In addition, the present invention also has the characteristics of easy modularization by using multiple ports plus a single channel to perform network communication, and the number of ports can be expanded based on actual application needs. Therefore, the present invention can also effectively improve the reuse rate of software and hardware in the network communication system and reduce the cost of system development and maintenance.
[0182] Furthermore, the present invention also provides a network communication system, such as Figure 7 As shown, the system includes: a plurality of ports and a transmission channel, wherein the plurality of ports include a first port for receiving data and a second port for sending data.
[0183] In addition, please refer to Fig.13 , Fig.13 FIG. 1 is a schematic diagram of the functional modules of an embodiment of a network communication system of the present invention. Fig.13 As shown, the network communication system of the present invention includes the following functional modules:
[0184] A received data modification module 10 is used for modifying the first original data to obtain first modified data when the first port receives the first original data, and writing the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port;
[0185] a receiving data restoration module 20, configured to restore the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and send the first original data to an upper layer application corresponding to the first port according to the first port information;
[0186] a sending data modification module 30, configured to modify the second original data to obtain second modified data when the upper layer application corresponding to the second port generates second original data, and write the second modified data into the transmission channel for transmission, wherein the second modified data carries the second port information of the second port;
[0187] The sending data restoring module 40 is used to restore the second modified data transmitted by the transmission channel to obtain the second original data and the second port information, and send the second original data through the second port according to the second port information.
[0188] Furthermore, the network communication system of the present invention further includes:
[0189] A modification rule definition module is used to determine classification information of the original data to be processed, wherein the original data to be processed includes the first original data and the second original data; predefine a received data modification rule according to the classification information, and predefine a sent data modification rule according to the classification information.
[0190] Furthermore, the receiving data modification module 10 includes:
[0191] A first acquisition unit, configured to acquire first classification information of the first original data;
[0192] a first modifying unit, configured to add the first port information of the first port to the first original data according to the first classification information and the received data modification rule, so as to modify the first original data to obtain first modified data;
[0193] The sending data modification module 30 comprises:
[0194] A second acquiring unit, configured to acquire second classification information of the second original data;
[0195] The second modifying unit is used to add the second port information of the second port to the second original data according to the second classification information and the sending data modification rule, so as to modify the second original data to obtain second modified data.
[0196] Furthermore, the first modification unit is also used to select one or more target bytes from the first original data according to the first classification information and the received data modification rule; and, according to the received data modification rule, add the first port information of the first port to the target byte.
[0197] Further, the first modification unit is further configured to divide the target byte according to the received data modification rule to obtain at least two bit sets, and add the port information of the first port to a first bit set of the two bit sets; or,
[0198] According to the received data modification rule, a bit is determined in the target byte as a port indicating bit, and the port information of the first port is added to the port indicating bit.
[0199] Furthermore, the first modifying unit is further configured to add the first classification information to a second bit set of the two bit sets, so as to send the first original data to the upper layer application according to the first port information and the first classification information.
[0200] Furthermore, the received data restoration module 20 is further configured to restore the first modified data transmitted by the transmission channel according to the received data modification rule to obtain the first original data and the first port information added to the first modified data.
[0201] Among them, the functional implementation of each module in the above-mentioned network communication system of the present application corresponds to the steps in the above-mentioned network communication method embodiment, and its functions and implementation processes will not be repeated here one by one.
[0202] The present application also provides a computer storage medium on which a network communication program is stored. When the network communication program is executed by a processor, the steps of the network communication method described in any of the above embodiments are implemented.
[0203] The specific embodiments of the computer storage medium of the present application are basically the same as the embodiments of the above-mentioned network communication method, and will not be described in detail here.
[0204] The present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the network communication method described in any one of the above embodiments are implemented.
[0205] The specific embodiments of the computer program product of the present application are basically the same as the embodiments of the above-mentioned network communication method, and will not be described in detail here.
[0206] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A network communication method, It is characterized in that The method is applied to a network communication system including a plurality of ports and a transmission channel, wherein the plurality of ports include a first port for receiving data and a second port for sending data; The method comprises: When the first port receives the first original data, modify the first original data to obtain first modified data, and write the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port; Restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and sending the first original data to an upper layer application corresponding to the first port according to the first port information; and, When the upper layer application corresponding to the second port generates second original data, the second original data is modified to obtain second modified data, and the second modified data is written into the transmission channel for transmission, wherein the second modified data carries second port information of the second port, wherein the step of modifying the second original data to obtain the second modified data comprises: obtaining second classification information of the second original data; selecting at least one target byte from the second original data according to the second classification information and the sending data modification rule; adding the second port information of the second port to the target byte according to the sending data modification rule, so as to modify the second original data to obtain the second modified data; The second modified data transmitted by the transmission channel is restored to obtain the second original data and the second port information, and the second original data is sent through the second port according to the second port information.
2. The method according to claim 1, It is characterized in that Before the step of modifying the first original data to obtain first modified data, the method further includes: Determining classification information of raw data to be processed, wherein the raw data to be processed includes the first raw data and the second raw data; predefine a received data modification rule according to the classification information; Before the step of modifying the second original data to obtain second modified data, the method further includes: The sending data modification rule is predefined according to the classification information.
3. The method according to claim 2, It is characterized in that The step of modifying the first original data to obtain first modified data includes: Acquire first classification information of the first original data; According to the first classification information and the received data modification rule, the first port information of the first port is added to the first original data, so as to modify the first original data to obtain first modified data.
4. The method according to claim 3, It is characterized in that The step of adding the first port information of the first port to the first original data according to the first classification information and the received data modification rule comprises: selecting at least one target byte from the first original data according to the first classification information and the received data modification rule; According to the received data modification rule, the first port information of the first port is added to the target byte.
5. The method according to claim 4, It is characterized in that The step of adding the first port information of the first port in the target byte according to the received data modification rule comprises: Divide the target byte according to the received data modification rule to obtain at least two bit sets, and add the port information of the first port to the first bit set of the two bit sets; or, According to the received data modification rule, a bit is determined in the target byte as a port indicating bit, and the port information of the first port is added to the port indicating bit.
6. The method according to claim 5, It is characterized in that After the step of dividing the target byte according to the received data modification rule to obtain at least two bit sets, the method further includes: The first classification information is added to the second bit set of the two bit sets, so as to send the first original data to the upper layer application according to the first port information and the first classification information.
7. The method according to claim 6, It is characterized in that The step of restoring the first modified data transmitted by the transmission channel to obtain the first original data and the first port information includes: The first modified data transmitted by the transmission channel is restored according to the received data modification rule to obtain the first original data and the first port information added to the first modified data.
8. A network communication system, It is characterized in that The system comprises: a plurality of ports and a transmission channel, wherein the plurality of ports comprises a first port for receiving data and a second port for sending data; a received data modification module, configured to modify the first original data to obtain first modified data when the first port receives the first original data, and write the first modified data into the transmission channel for transmission, wherein the first modified data carries the first port information of the first port; a receiving data restoration module, configured to restore the first modified data transmitted by the transmission channel to obtain the first original data and the first port information, and send the first original data to an upper layer application corresponding to the first port according to the first port information; a sending data modification module, configured to modify the second original data to obtain second modified data when the upper layer application corresponding to the second port generates second original data, and write the second modified data into the transmission channel for transmission, wherein the second modified data carries second port information of the second port; wherein the step of modifying the second original data to obtain the second modified data comprises: acquiring second classification information of the second original data; selecting at least one target byte from the second original data according to the second classification information and the sending data modification rule; and adding the second port information of the second port to the target byte according to the sending data modification rule to modify the second original data to obtain the second modified data; A sending data restoration module is used to restore the second modified data transmitted by the transmission channel to obtain the second original data and the second port information, and send the second original data through the second port according to the second port information.
9. A terminal device, It is characterized in that The terminal device comprises: a memory, a processor, and a network communication program stored in the memory and executable on the processor, wherein the network communication program, when executed by the processor, implements the steps of the network communication method according to any one of claims 1 to 7.
10. A computer storage medium, It is characterized in that The computer storage medium stores a network communication program, and when the network communication program is executed by the processor, the steps of the network communication method according to any one of claims 1 to 7 are implemented.
