Packet forwarding method and related device
By introducing a software acceleration module and an acceleration entry matching mechanism into network devices, the forwarding path of data packets is optimized, solving the problem of low efficiency in data transmission under multi-CPU cores and achieving efficient forwarding of data packets.
Patent Information
- Application Number
- CN202311223395.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-20
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2043-09-20
AI Technical Summary
Under the existing packet forwarding mechanism in Linux, the forwarding performance of data packets is poor, especially in high-traffic scenarios, where the CPU is busy processing data packet forwarding and fails to fully utilize the advantages of multiple CPU cores.
By introducing a software acceleration module between the network card driver and the network protocol stack, and utilizing acceleration entry matching and CPU core scheduling mechanisms, data packet processing is selectively allocated among multiple CPU cores to achieve data packet forwarding and optimize the data packet forwarding path.
It improves the forwarding efficiency of data packets, makes full use of the resources of multiple CPU cores, reduces the dependence on the network protocol stack, and improves the forwarding performance of data packets.
Smart Images

Figure CN119728541B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of communication, and in particular, to a packet forwarding method and related device. BACKGROUND
[0002] Under the existing packet forwarding mechanism of Linux, the forwarding processing flow of data packets generally includes: a network card driver receives data packets; the network card driver transmits the received data packets to a network protocol stack for processing; the network protocol stack transmits the processed data packets to the network card driver, and the network card driven by the network card driver forwards the data packets. That is, all data packets to be forwarded need to be processed by the network protocol stack, which may cause the central processing unit (CPU) to be busy with processing the forwarding of data packets in a large-flow data packet forwarding scenario, resulting in low data packet forwarding performance.
[0003] In order to solve this problem, most routing device manufacturers will try to use a software / hardware acceleration scheme to shorten the forwarding path of data packets to improve the forwarding performance of data packets. The existing software / hardware acceleration scheme still completes the forwarding of data packets on one CPU core, and for a CPU with multiple CPU cores, the advantage of multiple CPU cores is not brought into play, and the improvement of the forwarding performance of data packets is not obvious. SUMMARY
[0004] In view of the above, it is necessary to provide a packet forwarding method and related device, which can solve the problem that the forwarding of data packets is completed on a single CPU core, resulting in an insignificant improvement in the forwarding performance of data packets.
[0005] In a first aspect, the present application provides a packet forwarding method applied to a network device, the CPU of the network device having multiple CPU cores, the packet forwarding method comprising: receiving a data packet to be forwarded; determining a target CPU core to be scheduled in a case of matching an acceleration table item corresponding to the data packet, the acceleration table item including packet forwarding information of the data packet; adding the data packet and the packet forwarding information corresponding to the data packet to a queue of the target CPU core, and executing forwarding processing of the data packet by the target CPU core.
[0006] According to the technical scheme, whether the data packet is forwarded by using the network protocol stack or by using the CPU core scheduling is selected based on whether the acceleration table corresponding to the data packet is matched, in the case that the acceleration table corresponding to the data packet is matched, the data packet is forwarded by using the CPU core scheduling, the forwarding of one data packet is completed by cooperation of two CPU cores, CPU core resources are fully utilized, and since the acceleration table contains the packet forwarding information, the target CPU core can forward the data packet based on the packet forwarding information, so that the data packet can be forwarded without passing through the network protocol stack, and the forwarding efficiency of the data packet is further improved.
[0007] In a possible implementation, after receiving the data packet to be forwarded, the method further includes: in the case that the acceleration table corresponding to the data packet is not matched, performing, by the current CPU core, the forwarding of the data packet, wherein performing the forwarding of the data packet by the current CPU core includes processing the data packet by using the network protocol stack, and sending the processed data packet through the network card driver.
[0008] According to the technical scheme, in the case that the acceleration table corresponding to the data packet is not matched, since there is no acceleration table containing the packet forwarding information, the forwarding of the data packet cannot be performed by the target CPU core, and the forwarding of the data packet is performed on the current CPU core, that is, the data packet is processed by using the network protocol stack, and the data packet processed by the network protocol stack is sent through the network card driver, so that the data packet is successfully forwarded.
[0009] In a possible implementation, the packet forwarding method further includes: extracting the ingress device information, the five-tuple information and the packet forwarding information from the data packet processed by the network protocol stack; and constructing the acceleration table corresponding to the data packet based on the ingress device information, the five-tuple information and the packet forwarding information.
[0010] According to the technical scheme, the acceleration table corresponding to the data packet is constructed by extracting the ingress device information, the five-tuple information and the packet forwarding information from the data packet processed by the network protocol stack, so that the data packet of the subsequent data flow can be forwarded without passing through the network protocol stack, and the forwarding efficiency of the data packet is improved.
[0011] In a possible implementation, the method further includes: extracting the five-tuple information from the data packet, and calculating a packet hash value of the data packet based on the five-tuple information; and comparing the packet hash value of the data packet with a packet hash value recorded in each of the currently stored acceleration table entries, to obtain an acceleration table entry matching the data packet.
[0012] According to the above technical solution, the five-tuple information is used as the identity of the data packet, and the packet hash value calculated based on the five-tuple information is used as the identity of the acceleration table entry, so that the acceleration table entry can be distinguished from other acceleration table entries. Before the acceleration table entry corresponding to the data packet is constructed, the network device is queried to determine whether the corresponding acceleration table entry is stored, so that the repeated creation of the acceleration table entry is avoided, and the storage space of the network device is saved.
[0013] In a possible implementation, after receiving the data packet to be forwarded, the method further includes: extracting the five-tuple information from the data packet, and calculating a packet hash value of the data packet based on the five-tuple information; and comparing the packet hash value of the data packet with a packet hash value recorded in each of the currently stored acceleration table entries, to obtain an acceleration table entry matching the data packet.
[0014] According to the above technical solution, the five-tuple information is used as the identity of the data packet, and the packet hash value calculated based on the five-tuple information is used as the identity of the acceleration table entry, so that the acceleration table entry can be distinguished from other acceleration table entries. Before the acceleration table entry corresponding to the data packet is constructed, the network device is queried to determine whether the corresponding acceleration table entry is stored, so that the repeated creation of the acceleration table entry is avoided, and the storage space of the network device is saved.
[0015] In a possible implementation, the method further includes: determining a pre-scheduled CPU core based on a preconfigured static scheduling strategy; in a case where a state of the pre-scheduled CPU core does not meet a preset condition, determining the pre-scheduled CPU core as the target CPU core, the preset condition including that the pre-scheduled CPU core has a highest usage rate among the plurality of CPU cores; and in a case where the state of the pre-scheduled CPU core meets the preset condition, obtaining an application type to which the data packet belongs and a usage rate of each of the plurality of CPU cores, and determining the target CPU core based on the application type to which the data packet belongs, the usage rate of each of the plurality of CPU cores, and a preconfigured dynamic scheduling strategy.
[0016] With the technical solution, the target CPU core to be scheduled can be determined based on the pre-configured static scheduling strategy, and in the case that the target CPU core to be scheduled determined based on the static scheduling strategy is busy and other CPU cores are relatively idle (for example, have the highest CPU usage), the target CPU core to be scheduled is reselected, so that the problem that the static scheduling strategy cannot be modified after being preset to the network device can be solved, and in some scenarios, the static scheduling strategy can not be the best scheduling strategy. After the application type of the data flow is identified, the target CPU core is determined again based on the application type to which the data message belongs, the usage of each CPU core, and the pre-configured dynamic scheduling strategy, so that the best message forwarding performance is achieved.
[0017] In a possible implementation, the static scheduling strategy includes any one of the following: determining the pre-scheduled CPU core based on the binding relationship between the message type of the data message and the CPU core; determining the pre-scheduled CPU core based on the binding relationship between the message priority of the data message and the CPU core; determining the pre-scheduled CPU core based on the CPU core identifier recorded in the acceleration entry.
[0018] With the technical solution, the CPU core can be scheduled according to the binding relationship between the message type of the data message and the CPU core, so that the specified type message is bound to the specified CPU core, for example, a certain type of message forwarding is frequent, and can be bound to a CPU core with strong computing power, or the CPU core can be scheduled according to the binding relationship between the message priority of the data message and the CPU core, so that the data message with high priority is bound to the CPU core with strong computing power, and the data message with low priority is bound to the CPU core with weak computing power, or the CPU core can be scheduled according to the CPU core identifier (CPU_ID) recorded in the acceleration entry corresponding to the data message, for example, the acceleration entry records the identity of the CPU core with the least number of acceleration entries at the time of creation. The CPU core can be scheduled according to the CPU_ID recorded in the acceleration entry corresponding to the data message, so that the CPU core with the least number of acceleration entries is scheduled each time, and load balancing of the CPU core is achieved.
[0019] In a possible implementation, determining the target CPU core to be scheduled includes: determining the target CPU core to be scheduled based on the pre-configured static scheduling strategy, and the static scheduling strategy includes determining the target CPU core based on the binding relationship between the message type of the data message and the CPU core, determining the target CPU core based on the binding relationship between the message priority of the data message and the CPU core, or determining the target CPU core based on the CPU core identifier recorded in the acceleration entry.
[0020] According to the technical solution, the CPU core can be scheduled according to the binding relationship between the data packet type and the CPU core, or according to the binding relationship between the priority of the data packet and the CPU core, or according to the CPU core identifier (CPU_ID) recorded in the acceleration table entry corresponding to the data packet, so as to improve the forwarding efficiency of the data packet.
[0021] In a possible implementation, the CPU core identifier recorded in the acceleration table entry is the identifier of the CPU core with the least number of acceleration table entries in the queue when the acceleration table entry is created.
[0022] According to the technical solution, the identity of the CPU core with the least number of acceleration table entries at the moment when the acceleration table entry is created is recorded in the acceleration table entry creation process, and the CPU core is scheduled according to the CPU_ID recorded in the acceleration table entry corresponding to the data packet, so that the CPU core with the least number of acceleration table entries can be scheduled each time, and load balancing of the CPU core can be achieved.
[0023] In a possible implementation, the forwarding processing of the data packet is performed by the target CPU core, including: switching the forwarding processing of the data packet from the current CPU core to the target CPU core, triggering the poll callback of the target CPU core; reading the data packet and the packet forwarding information of the data packet from the queue of the target CPU core; determining the out-interface device and the out-interface of the data packet based on the packet forwarding information of the data packet, and updating the data packet; and calling the out-interface of the out-interface device to send the updated data packet.
[0024] According to the technical solution, after the CPU core switching is performed, the poll callback of the target CPU core is triggered to read the data packet and the packet forwarding information of the data packet from the queue of the target CPU core. The target CPU core can determine the out-interface device and the out-interface of the data packet based on the packet forwarding information of the data packet, update the related information of the protocol layer contained in the packet forwarding information to the data packet, and then call the out-interface to send the updated data packet, so that the forwarding processing of the data packet can be performed on the target CPU core without the need of processing the data packet through the network protocol stack, and the forwarding efficiency of the data packet is improved.
[0025] In a possible implementation, the packet forwarding information includes out-interface device information, an out-interface operation set, and related information of a specified protocol layer, the specified protocol layer including a network layer and a transport layer, and determining the out-interface device and the out-interface of the data packet based on the packet forwarding information of the data packet and updating the data packet include: determining the out-interface device of the data packet based on the out-interface device information; determining the out-interface of the data packet based on the out-interface operation set; and updating the related information of the protocol layer to the data packet.
[0026] With the technical solution, the packet forwarding information includes the out-interface device information, the out-interface operation set, and the related information of the network layer and the transport layer, the target CPU core can determine the out-interface device of the data packet based on the out-interface device information, determine the out-interface of the data packet based on the out-interface operation set, and update the related information of the network layer and the transport layer to the data packet, implement the packet processing of the simulated network protocol stack, and enable the data packet to be forwarded without passing through the network protocol stack, thereby improving the data packet forwarding efficiency.
[0027] In a possible implementation, the network device includes one of a router, a switch, a forwarder, a virtual switch, a virtual router, and a virtual forwarder.
[0028] With the technical solution, the network device includes but is not limited to any one of the router, the switch, the forwarder, the virtual switch, the virtual router, and the virtual forwarder.
[0029] In a second aspect, the present application provides a network device, including a memory and a processor; the memory is used to store program instructions; the processor is used to read the program instructions stored in the memory to implement the packet forwarding method described above.
[0030] In a third aspect, the present application provides a computer readable storage medium, the computer readable storage medium stores computer readable instructions, and the computer readable instructions are executed by a processor to implement the packet forwarding method described above.
[0031] In a fourth aspect, the present application provides a chip coupled with a memory in a network device, and the chip is used to control the network device to execute the packet forwarding method described above.
[0032] In addition, the technical effects brought by the second aspect to the fourth aspect can be referred to the descriptions of the methods of the above-mentioned method part, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 Flowchart for the existing network device to perform data packet forwarding;
[0034] Figure 2A software architecture diagram of a network device performing data packet forwarding is provided for an embodiment of the present application.
[0035] Figure 3 A flowchart of creating an acceleration table entry for a network device of an embodiment of the present application is provided.
[0036] Figure 4 A flowchart of a network device performing acceleration table entry matching is provided for an embodiment of the present application.
[0037] Figure 5 A flowchart of a network device performing CPU core initialization is provided for an embodiment of the present application.
[0038] Figure 6 A flowchart of a network device performing CPU core scheduling is provided for an embodiment of the present application.
[0039] Figure 7 A general flowchart of a network device performing CPU core initialization and scheduling is provided for an embodiment of the present application.
[0040] Figure 8 A software architecture diagram of a Netfilter framework is provided for an embodiment of the present application.
[0041] Figure 9 An interactive flowchart of a network device implementing data packet forwarding is provided for an embodiment of the present application.
[0042] Figure 10 An interactive flowchart of a network device implementing data packet forwarding is provided for another embodiment of the present application.
[0043] Figure 11 A flowchart of a soft acceleration module performing CPU core scheduling is provided for an embodiment of the present application.
[0044] Figure 12 A flowchart of a packet forwarding method is provided for an embodiment of the present application.
[0045] Figure 13 A hardware architecture diagram of a network device is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0046] The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.
[0047] The terms "first", "second", etc. are used only for the purpose of description and do not constitute a relative importance or imply a specific meaning of the number of technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, the words "exemplary", "or", "for example" are used to mean an example, illustration or description. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the use of "exemplary", "or", "for example" and the like is intended to present the relevant concept in a specific manner.
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in the specification of the present application is only for the purpose of describing specific embodiments and is not intended to limit the present application. It should be understood that in the present application, unless otherwise stated, " / " means or. For example, A / B can mean A or B. "And / or" in the present application is only a description of the relationship between the associated objects, which means that there can be three relationships. For example, A and / or B can mean: A alone, A and B together, B alone. "At least one" means one or more. "Multiple" means two or more. For example, at least one of a, b or c can mean: a, b, c, a and b, a and c, b and c, a, b and c seven cases. It should be understood that the order of the steps shown in the flowchart herein can be changed, and some can be omitted.
[0049] Please refer to Figure 1 , which illustrates the processing flow of the network device for data packet forwarding. Exemplarily, the network device in the embodiments of the present application can refer to a device performing data / routing forwarding function, such as a router, a switch, a forwarder, etc. The router, the switch, the forwarder, etc. can be a physical device, or a virtual device (such as a virtual switch, a virtual router, a virtual forwarder) based on virtualization technology. The embodiments of the present application do not specially limit the specific form of the network device. The network device can be deployed with an operating system, an operating system, etc.
[0050] Taking the network device deployed with an operating system as an example, the packet forwarding flow of the network device is briefly described. The packet forwarding flow can include:
[0051] (1) The network card located in the hardware layer receives the data packet, and sends the data packet to the network card driver;
[0052] (2) The network card driver located in the kernel layer calls the interface function netif_rx to send the data packet to the network protocol stack (located in the kernel layer) for processing. For example, the network protocol stack processes the data packet according to the requirements of the network protocol.
[0053] (3) The network protocol stack sends the processed data packets to the network card driver;
[0054] (4) The network card driver calls the interface function node-xmit to send the data packets processed by the network protocol stack to the network card so that they can be sent out through the network card.
[0055] In the aforementioned data packet forwarding process, the forwarding of data packets is generally handled by one CPU core. Since data packet forwarding requires processing through the network protocol stack, in high-volume data packet forwarding scenarios, this CPU core may be constantly busy processing data packets, potentially reaching 100% utilization. This could lead to low data packet forwarding performance, while other CPU cores may have lower utilization, or even zero utilization. For network devices with multiple CPU cores, this does not maximize the utilization of CPU resources. This application's embodiment uses a Transmission Control Protocol / Internet Protocol (TCP / IP) protocol stack as an example for illustration.
[0056] In view of this, the packet forwarding method provided in the embodiments of this application can solve the problem that when the CPU has multiple CPU cores, the CPU resources cannot be maximized, resulting in low data packet forwarding performance.
[0057] like Figure 2 As shown, a software acceleration module 20 is configured between the network interface card (NIC) driver and the network protocol stack. This module enables CPU core switching, maximizing CPU resource utilization. Specifically, after receiving a data packet, the NIC driver sends it to the software acceleration module 20. The software acceleration module 20 determines whether to schedule the data packet for processing or forward it to the network protocol stack. If the software acceleration module 20 determines to schedule the data packet, it schedules it to another CPU core. Subsequent processing (processing the data packet according to network protocol requirements) and forwarding of the data packet will occur on the scheduled CPU core; that is, the data packet forwarding process involves two CPU cores. If the software acceleration module 20 determines to forward the data packet to the network protocol stack, there is no CPU core switching involved; that is, the data packet forwarding process involves only one CPU core.
[0058] For example, the soft acceleration module 20 can determine whether to perform scheduling processing on the data packet or forward the data packet to the network protocol stack for processing by performing matching of the data packet with the acceleration table entry. If the soft acceleration module 20 matches the acceleration table entry corresponding to the data packet, the soft acceleration module 20 performs scheduling of the CPU core according to the pre-configured scheduling strategy, and subsequent processing and forwarding of the data packet are performed on the scheduled CPU core. If the soft acceleration module 20 does not match the acceleration table entry corresponding to the data packet, the soft acceleration module 20 forwards the data packet to the network protocol stack for processing.
[0059] In some embodiments, the soft acceleration module 20 can include an acceleration table entry generation module 201, an acceleration table entry matching module 202, and a forwarding and scheduling module 203. The module referred to in the embodiments of the present application can refer to a series of computer program instruction segments capable of completing a specific function, or a functional module formed by cooperation of computer program instruction segments and hardware. The division of the module is a logical functional division, and there can be another division manner in actual implementation, which is not limited in the present application.
[0060] The acceleration table entry generation module 201 is configured to create the acceleration table entry corresponding to the data packet according to the related information of the data packet. The related information of the data packet can include five-tuple information (source IP address, destination IP address, source port number, destination port number, and transmission protocol) of the data packet, ingress device information of the data packet, egress interface device information set of the data packet, which can include egress interface device information of the data packet, forwarding direction of the data packet, egress interface operation set of the data packet, and related information of the protocol layer.
[0061] For example, the protocol layer can include the network layer (L2 layer in the TCP / IP reference model) and the transmission layer (L3 layer in the TCP / IP reference model), and the related information of the protocol layer can include connection tracking record information, IP information, and the like. The TCP / IP reference model refers to an abstract layered model customized for the TCP / IP protocol stack.
[0062] The acceleration table entry matching module 202 is configured to perform matching of the data packet with the acceleration table entry. If the acceleration table entry matching module 202 matches the acceleration table entry corresponding to the data packet, the data packet is sent to the forwarding and scheduling module 203 for scheduling processing. If the acceleration table entry matching module 202 does not match the acceleration table entry corresponding to the data packet, the data packet is sent to the network protocol stack for processing. The forwarding and scheduling module 203 is configured to perform scheduling of the CPU core according to the pre-configured scheduling strategy, so that subsequent processing and forwarding of the data packet are performed on the scheduled CPU core.
[0063] When the network device forwards data flow, the data flow is forwarded according to data packets one by one. The network card driver sends the received data packet to the acceleration table matching module 202. If the current received data packet is the first data packet in the data flow, since the acceleration table generation module 201 creates the acceleration table based on the relevant information of the data packet processed by the network protocol stack, when the acceleration table matching module 202 receives the first data packet in the data flow, the acceleration table of the data packet has not been created yet. The acceleration table matching module 202 cannot match the acceleration table corresponding to the data packet, and sends the data packet to the network protocol stack for processing. After the data packet is processed by the network protocol stack, the data packet is sent to the acceleration table generation module 201. At this time, the acceleration table generation module 201 creates the corresponding acceleration table based on the relevant information of the data packet, and sends the data packet processed by the network protocol stack to the network card driver. The network card driver can drive the network card to send out the data packet.
[0064] If the data packet received by the acceleration table matching module 202 is not the first data packet in the data flow, since the acceleration table generation module 201 has created the acceleration table corresponding to the data packet, the acceleration table matching module 202 can match the acceleration table corresponding to the data packet. The acceleration table matching module 202 sends the data packet to the forwarding scheduling module 203. The forwarding scheduling module 203 schedules the CPU core according to the pre-configured scheduling strategy, so that the subsequent processing and forwarding of the data packet are performed on the scheduled CPU core. After the data packet is processed by the forwarding scheduling module 203, it is sent to the network card driver. The network card driver can drive the network card to send out the data packet.
[0065] The functions of the acceleration table generation module 201, the acceleration table matching module 202 and the forwarding scheduling module 203 will be introduced below in combination with Figure 3 、 Figure 4 、 Figure 5 and Figure 6 .
[0066] As shown in Figure 3 , the flow of creating the acceleration table by the acceleration table generation module 201 is illustrated.
[0067] S301, marking the type of the data packet processed by the network protocol stack.
[0068] When the network device forwards a data flow, the data flow is forwarded in the form of data packets, and the data packets are transmitted in the form of SKB between different protocol layers in the kernel. The data packet processed by the network protocol stack can be a data packet of a certain data flow, which is processed by the network protocol stack and delivered to the acceleration entry generation module 201. Embodiments of the present application take the processing of a first data flow by the network device as an example for description.
[0069] For the network device, the network device can be connected to one or more terminal devices (mobile phones, tablets, notebook computers, etc.), and then forward data flows for the one or more terminal devices. Different terminal devices can have different data volumes, and different services under the same terminal device can also have different data flows.
[0070] The network protocol stack can send the data packet of the processed first data flow to the acceleration entry generation module 201. The acceleration entry generation module 201 can mark the packet type of the data packet according to the network type to which the first data flow belongs. The network type can include Ethernet, wireless local area network (2.4 GHz frequency band or 5 GHz frequency band), etc.
[0071] In the Linux system, the data packet is processed through a socket buffer (SKB). The SKB is used to implement data transmission and interactive data packets between different protocol layers in the kernel. For example, a field can be added in the SKB or a certain original field can be specified to identify the packet type of the data packet. The acceleration entry generation module 201 can call the xmit interface of the Ethernet driver or the wireless fidelity (Wi-Fi) driver to assign values to the field, so as to mark the packet type of the data packet.
[0072] For example, the first form of assignment to the field represents that the packet type of the data packet is an Ethernet packet, the second form of assignment to the field represents that the packet type of the data packet is a 2.4G Wi-Fi packet, and the third form of assignment to the field represents that the packet type of the data packet is a 5G Wi-Fi packet.
[0073] In S302, it is determined whether the number of acceleration entries currently stored in the preset storage area is greater than or equal to a preset upper limit value.
[0074] In some embodiments, the preset storage area can be a storage area in the network device for storing the acceleration table entry. For the network device, the storage resource is limited, and the storage space allocated to the acceleration table entry also has a capacity limit, i.e., the number of acceleration table entries that the preset storage area can store also has a certain limit. The preset upper limit value can be set according to the storage capacity of the preset storage area, and the specific value of the preset upper limit value is not limited in the embodiments of the present application.
[0075] If the number of acceleration table entries currently stored in the preset storage area is greater than or equal to the preset upper limit value, it indicates that the remaining capacity of the preset storage area for storing the acceleration table entry is tight, and it can not be possible to store the newly created acceleration table entry, and the process ends, and the acceleration table entry generation module 201 exits the creation process of the acceleration table entry. If the number of acceleration table entries currently stored in the preset storage area is less than the preset upper limit value, it indicates that the remaining capacity of the preset storage area for storing the acceleration table entry is relatively abundant, and the acceleration table entry generation module 201 can continue to perform step S303.
[0076] S303, if the number of acceleration table entries is less than the preset upper limit value, the related information of the data packet is obtained, and the related information includes five-tuple information, ingress device information, and egress interface device information set.
[0077] In some embodiments, the egress interface device information set can include packet forwarding information, for example, the egress interface device information set includes egress interface device information, forwarding direction, egress interface operation set, and related information of protocol layer. If the number of acceleration table entries is less than the preset upper limit value, the acceleration table entry generation module 201 can extract the five-tuple information, ingress device information, and egress interface device information set from the SKB.
[0078] For example, the code of the five-tuple information can include:
[0079] struct fp_tuple{
[0080] u16 type;
[0081] u8 proto;
[0082] u8 resv;
[0083] u16 port_src;
[0084] u16 port_dst;
[0085] }。
[0086] The code of the egress interface device information set can include:
[0087] struct fp_dst{
[0088] u32 dir; / / forwarding direction
[0089] struct net-device*dev; / / Output interface device
[0090] struct fp_dec_ops*ops; / / Output interface operation set
[0091] void *data; / / Key information for L2 and L3 layers
[0092] atomic_t refcnt; / / reference count
[0093] struct rcu_head rcu;
[0094] }
[0095] S304, calculate the message hash value based on the five-tuple information of the data message.
[0096] After obtaining the relevant information of the data packet, the packet hash value corresponding to the data packet can be calculated based on the 5-tuple information in the relevant information. The packet hash value can serve as a unique identifier for the acceleration table entry corresponding to the data packet.
[0097] S305: Based on the message hash value, search in the global acceleration nodes to see if there is an acceleration table entry corresponding to the data message.
[0098] A global acceleration node can refer to a global node used to manage the accelerated forwarding of all data flows in a network device. After calculating the packet hash value of a data packet, the calculated packet hash value is compared with the packet hash values stored in each acceleration table entry in the global acceleration node to determine whether an acceleration table entry corresponding to the data packet exists. For example, if the comparison determines that the packet hash values stored in each acceleration table entry in the global acceleration node are all different from the calculated packet hash value, it indicates that no acceleration table entry corresponding to the data packet exists in the global acceleration node. If the comparison determines that one acceleration table entry in the global acceleration node stores a packet hash value that is the same as the calculated packet hash value, it indicates that an acceleration table entry corresponding to the data packet exists in the global acceleration node.
[0099] If it is determined that an acceleration entry corresponding to the data packet exists in the global acceleration node, the acceleration entry generation module 201 exits the acceleration entry creation process to avoid duplicate acceleration entries, and the process ends. If it is determined that no acceleration entry corresponding to the data packet exists in the global acceleration node, i.e., an acceleration entry corresponding to the data packet needs to be created, the acceleration entry generation module 201 can continue to execute step S306.
[0100] S306. If there is no acceleration entry corresponding to the data packet in the global acceleration node, create an acceleration entry corresponding to the data packet based on the relevant information of the data packet.
[0101] If there is no acceleration entry corresponding to the data packet in the global acceleration node, the acceleration entry generation module 201 can create an acceleration entry corresponding to the data packet based on the relevant information of the data packet.
[0102] The code for accelerating entries can include:
[0103] struct fp_fwd_node{
[0104] struct net_device*in_dev; / / Entry device information
[0105] struct fp_tuple tuple; / / Five-tuple information
[0106] struct fp_dst_rcu*dst; / / Output interface device information set
[0107] struct hlist_node hlist; / / Hash pointer mounted to the global acceleration node
[0108] }
[0109] In some embodiments, in order to save storage resources in the preset storage area, the network device may delete the acceleration entry corresponding to the data stream after the receiver of the data stream disconnects from it.
[0110] S307 inserts the acceleration entry corresponding to the data packet into the global acceleration node.
[0111] After creating the acceleration entry corresponding to the data packet, the acceleration entry can be inserted into the global acceleration node for global acceleration management.
[0112] In some embodiments, when creating acceleration entries, the number of current acceleration entries for each CPU core can be obtained, and the unique identifier CPU_ID of the CPU core with the fewest current acceleration entries can be recorded in the created acceleration entry. This allows subsequent CPU core scheduling to be performed based on the CPU_ID recorded in the acceleration entry, thereby achieving CPU core load balancing.
[0113] like Figure 4 The diagram illustrates the process of the accelerated entry matching module 202 performing accelerated entry matching.
[0114] S401 receives data packets sent by the network card driver and obtains the packet type of the data packets.
[0115] The data stream is forwarded according to data packets one by one, and the data packets under the same data stream have the same packet type. The packet type of the data packet can be marked in the process of creating the acceleration table entry. Taking forwarding of the first data stream as an example, if the acceleration table entry matching module 202 receives the data packet sent by the network card driver as the first data packet of the first data stream, since the acceleration table entry of the data packet has not been created yet, the packet type of the data packet has not been marked either, that is, the acceleration table entry matching module 202 cannot obtain the packet type of the data packet. The acceleration table entry matching module 202 can directly forward the data packet to the network protocol stack for processing, so that the acceleration table entry generation module 201 can mark the packet type based on the data packet processed by the network protocol stack, and create the acceleration table entry.
[0116] If the acceleration table entry matching module 202 receives the data packet sent by the network card driver as the i th data packet of the first data stream, i is a positive integer greater than 1, since the acceleration table entry generation module 201 has marked the packet type of the first data packet of the first data stream, the acceleration table entry matching module 202 can obtain the packet type of the i th data packet received subsequently.
[0117] S402, determining an operation interface corresponding to the data packet based on the packet type of the data packet.
[0118] In some embodiments, after obtaining the packet type of the data packet, the acceleration table entry matching module 202 can determine an operation interface corresponding to the data packet based on the packet type of the data packet, so that the operation interface can be called subsequently to extract the five-tuple information of the data packet. For example, if the packet type of the data packet is an Ethernet packet, the operation interface corresponding to the data packet is an Ethernet driver operation interface, and if the packet type of the data packet is a 2.4G Wi-Fi packet, the operation interface corresponding to the data packet is a Wi-Fi driver operation interface.
[0119] S403, extracting the five-tuple information of the data packet based on the operation interface corresponding to the data packet.
[0120] After determining the operation interface corresponding to the data packet, the acceleration table entry matching module 202 can call the operation interface corresponding to the data packet to extract the five-tuple information of the data packet.
[0121] S404, determining whether there is an acceleration table entry corresponding to the data packet in the global acceleration node based on the five-tuple information of the data packet.
[0122] In some embodiments, after obtaining the quintuple information of the data packet, the acceleration entry matching module 202 can calculate the packet hash value corresponding to the data packet based on the quintuple information, and then compare the calculated packet hash value with the packet hash value stored in each acceleration entry in the global acceleration node to determine whether there is an acceleration entry corresponding to the data packet in the global acceleration node. For example, if the comparison determines that the packet hash value stored in each acceleration entry in the global acceleration node is different from the calculated packet hash value, it indicates that there is no acceleration entry corresponding to the data packet in the global acceleration node. If the comparison determines that the packet hash value stored in an acceleration entry in the global acceleration node is the same as the calculated packet hash value, it indicates that there is an acceleration entry corresponding to the data packet in the global acceleration node.
[0123] If it is determined that there is an acceleration entry corresponding to the data packet in the global acceleration node, the acceleration entry matching module 202 can continue to perform step S405. If it is determined that there is no acceleration entry corresponding to the data packet in the global acceleration node, it indicates that no acceleration entry corresponding to the data packet is matched, and step S407 is performed. The acceleration entry matching module 202 forwards the data packet to the network protocol stack for processing.
[0124] S405, updating the forwarding state of the entry corresponding to the data packet in the forwarding table.
[0125] In the network device, the forwarding table can also be referred to as a forwarding information base (FIB). The network device forwards data by using the FIB table. The entry in the FIB specifies the destination to which the data packet is to be sent, the outgoing interface and the next hop IP address required to be passed, and the like. The acceleration entry matching module 202 updates the forwarding state of the entry corresponding to the data packet in the forwarding table, indicating that the data packet enters the forwarding state. After subsequent processing by the forwarding scheduling module 203, the network card is driven by the network card driver to perform forwarding.
[0126] S406, sending the data packet and the key information of the corresponding acceleration entry to the forwarding scheduling module 203.
[0127] In some embodiments, the acceleration entry matching module 202 can further determine whether the acceleration state of the data flow in the soft acceleration module 20 is normal before sending the data packet and the corresponding acceleration entry to the forwarding scheduling module 203. If the acceleration state is normal, it indicates that the forwarding acceleration of the data flow is achieved through the soft acceleration module 20, and the acceleration entry matching module 202 sends the data packet and the key information of the corresponding acceleration entry to the forwarding scheduling module 203. If the acceleration state is abnormal, it indicates that the forwarding acceleration of the data flow is not achieved through the soft acceleration module 20, and it is not meaningful to send the data packet to the forwarding scheduling module 203 for scheduling processing, and it may even cause a large delay in data packet forwarding. The acceleration entry matching module 202 can forward the data packet to the network protocol stack for processing. The key information of the acceleration entry can refer to the out-interface device information, the out-interface operation set, and the key information of the L2 and L3 layers recorded in the acceleration entry.
[0128] In some embodiments, the acceleration state of the data flow in the soft acceleration module 20 can be determined by obtaining the time difference between the timestamp of the previous data packet of the current data packet from the input to the acceleration entry matching module 202 and the timestamp from the output of the forwarding scheduling module. If the time difference is greater than a preset time, it indicates that the acceleration state is abnormal, and the acceleration entry matching module 202 can forward the data packet to the network protocol stack for processing. If the time difference is less than or equal to the preset time, it indicates that the acceleration state is normal, and the acceleration entry matching module 202 can send the data packet and the key information of the corresponding acceleration entry to the forwarding scheduling module 203, so as to facilitate subsequent scheduling processing of the data packet by the forwarding scheduling module 203.
[0129] S407, forwarding the data packet to the network protocol stack.
[0130] As shown in FIG. 7, a flow of initializing each CPU core by the forwarding scheduling module 203 is illustrated. Figure 5
[0131] S501, creating a corresponding number of virtual network cards according to the number of CPU cores contained in the CPU, and initializing the queue of each CPU core.
[0132] In some embodiments, one CPU core can correspond to one virtual network card, and the CPU core can process the data packet according to the requirements of the network protocol through the corresponding virtual network card.
[0133] The queue of the CPU core can be used to store the data packet to be forwarded and the key information of the acceleration entry. For example, the key information can include the out-interface device information, the out-interface operation set, and the key information of the L2 and L3 layers.
[0134] S502, registering a poll callback function for each CPU core.
[0135] The poll callback function can be a do_pull function supporting a new application program interface (NAPI). The NAPI combines the advantages of the interrupt mode and the polling mode, and in a light load case, the processing mode tends to be close to the interrupt mode, and in a heavy load case, the processing mode tends to be close to the polling mode.
[0136] By registering the poll callback function for each CPU core, after subsequently storing the data packet and some key information in the acceleration table item into the queue of a certain CPU core, the CPU core can read the data packet and some key information in the acceleration table item from the queue of the CPU core by triggering the poll callback.
[0137] S503, configure a scheduling strategy for CPU core scheduling.
[0138] In some embodiments, the scheduling strategy can include a static scheduling strategy and a dynamic scheduling strategy.
[0139] For example, the static scheduling strategy can include the following three: a scheduling strategy based on the binding of the message type and the corresponding CPU core, a scheduling strategy based on the binding of the message priority and the corresponding CPU core, and a scheduling strategy based on the CPU_ID of the CPU core recorded in the acceleration table item. The specific policy content defined by the static scheduling strategy is not limited by the present application, and the policy content can be set and adjusted according to actual needs.
[0140] The scheduling strategy based on the binding of the message type and the corresponding CPU core can mean that the CPU core is scheduled according to the binding relationship between the message type of the data packet and the CPU core. For example, the message type includes Ethernet message, 2.4G Wi-Fi message and 5G Wi-Fi message, and the Ethernet message, 2.4G Wi-Fi message and 5G Wi-Fi message are bound to different CPU cores respectively. After the acceleration table item matching module 202 analyzes the message type of the data packet, the forwarding scheduling module 203 can read the binding relationship between the message type and the CPU core, schedule the CPU core according to the binding relationship, and then the CPU core after scheduling can execute the packet sending processing flow of the data packet.
[0141] For example, the CPU of the network device includes four CPU cores, and the packet sending process of the Ethernet message is preset to be executed on the second CPU core, the packet sending process of the 2.4G Wi-Fi message is executed on the third CPU core, and the packet sending process of the 5G Wi-Fi message is executed on the fourth CPU core. Assuming that the processes such as receiving of the data message and matching of the acceleration table item are executed on the first CPU core before the CPU core scheduling of the forwarding scheduling module 203, the forwarding scheduling module 203 can make the packet sending process of the Ethernet message switched from the first CPU core to the second CPU core, make the packet sending process of the 2.4G Wi-Fi message switched from the first CPU core to the third CPU core, and make the packet sending process of the 5G Wi-Fi message switched from the first CPU core to the fourth CPU core.
[0142] For example, the packet sending process of the 2.4G Wi-Fi message (WLAN0) can be set to be executed on the third CPU core (CPU 2) and the packet sending process of the 5G Wi-Fi message (WLAN1) can be set to be executed on the fourth CPU core (CPU 3) through the following code:
[0143] / #cat / proc / fc / ctr1 / smp_dispatch_wifi_tx
[0144] WLAN0–Mode:1 (IPI dispatch) CPU:2
[0145] WLAN1–Mode:1 (IPI dispatch) CPU:3.
[0146] The scheduling strategy based on the packet priority and the corresponding CPU core binding can refer to scheduling the CPU core according to the priority of the data packet and the binding relationship of the CPU core. The priority of the data packet can be distinguished according to a differentiated services code point (DSCP) value in the data packet. The IP header of each data packet includes a byte (1 byte includes 8 bits) for identifying a type of service (TOS), and 6 bits of the byte are used to represent the priority of the data packet, that is, the value range of the DSCP value is 0-63. The greater the DSCP value, the higher the priority of the data packet. In addition to identifying the type of service (TOS), the IP header of the data packet generally includes version (Version), header length (Header Length), total length (Total Length), ID identifier, flag (Flag), fragmentation offset (Fragmentation offset), time to live (TTL), protocol (Protocol), frame check sequence (FCS), source IP address (IP-SA), destination IP address (IP-DA), and the IP header of the data packet can be as shown in Table 1.
[0147] Table 1
[0148]
[0149] Based on the performance difference of different CPU cores, data packets of different priorities can be given to different CPU cores for processing according to the packet priority, and data packets with high priority are given to CPU cores with high performance. Assuming that the CPU of the network device includes four CPU cores, and the processing capacity of each CPU core is: first CPU core > second CPU core > third CPU core > fourth CPU core, the binding relationship between the DSCP value and the CPU core is constructed as shown in Table 2, to realize scheduling the CPU core according to the priority of the data packet and the binding relationship of the CPU core.
[0150] Table 2
[0151] DSCP value Corresponding CPU core 0~15 Fourth CPU core (CPU 3) 16~31 Third CPU core (CPU 2) 32~47 Second CPU core (CPU 1) 48~63 First CPU core (CPU 0)
[0152] The forwarding scheduling module 203 can parse the DSCP value of the SKB (the data packet is transmitted in the form of SKB between different protocol layers in the kernel), and schedule the CPU core based on the DSCP value, to achieve the purpose of improving the packet forwarding performance.
[0153] The scheduling policy based on the CPU ID of the acceleration entry record of the CPU core can refer to scheduling of the CPU core according to the CPU ID of the acceleration entry record corresponding to the data packet. When the acceleration entry corresponding to the data packet is created, the acceleration entry records the identity (CPU ID) of the CPU core with the least number of acceleration entries. When the CPU core is scheduled, the CPU core can be scheduled according to the CPU ID recorded by the acceleration entry corresponding to the data packet, so that the CPU core with the least number of acceleration entries is scheduled each time, and load balancing of the CPU core is achieved.
[0154] For example, if the CPU ID recorded by the acceleration entry corresponding to a data packet is the second CPU core, the packet sending process of the data packet can be switched from the current CPU core to the second CPU core for execution.
[0155] Since the static scheduling policy is preset to the network device, it cannot be modified during the running of the network device. In some scenarios, the static scheduling policy can not be the best scheduling policy. After the service type of the data flow is identified, the static scheduling policy can be dynamically adjusted based on the identification result, so as to achieve the best packet forwarding performance. That is, the dynamic scheduling policy can refer to a policy for dynamically adjusting the static scheduling policy based on the service type identification result of the data flow.
[0156] As shown in Table 3, taking the application type of the service type of the data flow as an example, rules for dynamically adjusting the static scheduling policy based on the application type corresponding to the data flow are shown. Different application types can be set with the same / different dynamic scheduling policy.
[0157] Table 3
[0158]
[0159]
[0160] As can be seen from the content of Table 3, during the process of scheduling the CPU core, the forwarding scheduling module 203 can determine whether to adjust the static scheduling policy according to the application type of the data flow and the state of the pre-scheduled CPU core.
[0161] For example, if the application type of the data flow is a game, the pre-scheduled CPU core determined based on the static scheduling strategy has the highest usage rate among all CPU cores, the forwarding scheduling module 203 can first determine the corresponding dynamic scheduling strategy based on the application type corresponding to the data flow, and then select a new CPU core as the final scheduled CPU core based on the corresponding dynamic scheduling strategy. If the pre-scheduled CPU core determined based on the static scheduling strategy does not have the highest usage rate among all CPU cores, the forwarding scheduling module 203 will take the pre-scheduled CPU core as the final scheduled CPU core.
[0162] In some embodiments, the condition for triggering the dynamic scheduling strategy can also be set as that the usage rate of the pre-scheduled CPU core is greater than a threshold value and has the highest usage rate among all CPU cores.
[0163] As shown in FIG. 3, the flow of the CPU core scheduling performed by the forwarding scheduling module 203 according to the pre-configured scheduling strategies (static scheduling strategy and dynamic scheduling strategy) is illustrated. Figure 6
[0164] S601, obtaining the key information of the data packet and the corresponding acceleration table entry.
[0165] In some embodiments, the forwarding scheduling module 203 can obtain the key information of the data packet and the corresponding acceleration table entry by receiving the key information of the data packet and the corresponding acceleration table entry sent by the acceleration table entry matching module 202. The data packet is transmitted in the form of SKB between different protocol layers in the kernel, that is, the forwarding scheduling module 203 actually obtains the SKB to be forwarded and the key information of the acceleration table entry corresponding to the SKB.
[0166] S602, determining the target CPU core to be scheduled based on the pre-configured scheduling strategy.
[0167] In some embodiments, the forwarding scheduling module 203 can determine the target CPU core to be scheduled based on the static scheduling strategy and the dynamic scheduling strategy, so that the subsequent processing and forwarding of the data packet are performed on the target CPU core.
[0168] For example, if the state of the pre-scheduled CPU core determined based on the static scheduling strategy does not meet the preset condition, the pre-scheduled CPU core is taken as the final CPU core to be scheduled (i.e., the target CPU core); if the state of the pre-scheduled CPU core determined based on the static scheduling strategy meets the preset condition, a CPU core is reselected as the final CPU core to be scheduled (i.e., the target CPU core) based on the dynamic scheduling strategy. The preset condition can refer to a condition triggering the dynamic scheduling strategy, such as that the pre-scheduled CPU core has the highest usage rate among all CPU cores, or the usage rate of the pre-scheduled CPU core is greater than a threshold value and has the highest usage rate among all CPU cores.
[0169] S603, the data packet and the key information of the corresponding acceleration table item are added to the queue of the target CPU core.
[0170] After the target CPU core to be scheduled is determined, the data packet and the key information of the corresponding acceleration table item can be added to the queue of the target CPU core, that is, the data packet and the key information of the corresponding acceleration table item are added to the queue of the target CPU core as a queue element. The queue elements in the queue can be read according to the first-in first-out rule.
[0171] S604, the CPU core is switched, the poll callback of the target CPU core is triggered, and the data packet and the key information of the corresponding acceleration table item are read from the queue of the target CPU core.
[0172] In some embodiments, for a CPU with multiple CPU cores, the Linux system provides a symmetric multiprocessing (SMP) scheduling mechanism to realize migration of a task to a suitable CPU core for execution. The switching of the CPU core can be realized through the SMP scheduling mechanism, from the current CPU core to the target CPU core. The switching of the CPU core can trigger a NAPI software interrupt, and in turn can trigger the target CPU core to call the poll callback function, so that the target CPU core reads the data packet and the key information of the corresponding acceleration table item from the queue of the target CPU core.
[0173] In some embodiments, before the CPU core is switched, the flow is executed on the current CPU core, for example, steps S601-S603 are executed on the current CPU core; after the CPU core is switched, the flow is transferred to be executed on the target CPU core, for example, the reading of the data packet and the key information of the corresponding acceleration table item in step S604 and the following steps S605 and S606 are executed on the target CPU core.
[0174] S605, determining the egress interface device and the egress interface of the data packet based on the key information of the acceleration table entry, and updating the key information of L2 and L3 layers to the data packet.
[0175] In some embodiments, the key information of the acceleration table entry includes egress interface device information, egress interface operation set, and key information of L2 and L3 layers. The egress interface device of the data packet can be determined based on the egress interface device information, and the egress interface of the data packet can be determined based on the egress interface operation set. The egress interface can be a packet sending function of a network card driver, such as an Ethernet driver packet sending function or a Wi-Fi driver packet sending function.
[0176] Since the data packet does not pass through the network protocol stack for processing, the key information of L2 and L3 layers of the data packet is not updated by the network protocol stack. The key information of L2 and L3 layers recorded by the acceleration table entry is the information of the previous data packet updated by the network protocol stack. By updating the key information of L2 and L3 layers recorded by the acceleration table entry to the data packet, the processing of the data packet through the network protocol stack can be simulated.
[0177] S606, calling the egress interface of the egress interface device to send the data packet out through the network card.
[0178] After determining the egress interface device and the egress interface of the data packet, the egress interface of the egress interface device can be called to send the data packet with the updated key information of L2 and L3 layers out through the network card.
[0179] For example, the network card driver includes an Ethernet driver and a Wi-Fi driver. The terminal device accesses the network device through a wireless manner. For a data packet forwarded from the network device to the terminal device, on the network device side, the data packet is received by the Ethernet driver, and the network card is driven by the Wi-Fi driver to send the data packet out. For a data packet forwarded from the network device to a server, on the network device side, the data packet is received by the Wi-Fi driver (the source of the data packet is the terminal device), and the network card is driven by the Ethernet driver to send the data packet out. For a data packet forwarded from the network device to another network device (the network device and the other network device are connected through a wired manner), on the network device side, the data packet is received by the Ethernet driver, and the network card is driven by the Ethernet driver to send the data packet out. The network card can include a first hardware module (driven by the Ethernet driver) that can implement Ethernet data packet transmission and reception, and a second hardware module (driven by the Wi-Fi driver) that can implement Wi-Fi data packet transmission and reception.
[0180] The above-mentioned forwarding scheduling module 203 schedules the CPU cores to realize the cooperation of the two CPU cores to complete the forwarding of the data packet, which can improve the forwarding performance of the network device.
[0181] Please refer to Figure 7 , which illustrates the overall flow of the initialization of the CPU core and the scheduling of the CPU core implemented by the forwarding scheduling module 203.
[0182] Initialization of the CPU core:
[0183] (1) Obtain the CPU cores contained by the CPU, create a virtual network card for each CPU core, and initialize the queue of each CPU core.
[0184] After the queue of each CPU core is initialized, the queue element contained is empty.
[0185] (2) Register a poll callback function for each CPU core.
[0186] (3) Configure a scheduling strategy for scheduling the CPU core. The scheduling strategy can include a static scheduling strategy and a dynamic scheduling strategy. The static scheduling strategy can include determining the CPU core to be scheduled based on the binding relationship between the message type of the data message and the CPU core; determining the CPU core to be scheduled based on the binding relationship between the message priority of the data message and the CPU core; and determining the CPU core to be scheduled based on the CPU core identifier recorded in the acceleration table entry.
[0187] Scheduling of the CPU core:
[0188] (1) Receive the data message to be forwarded and the key information of the corresponding acceleration table entry.
[0189] (2) Scheduling strategy selection, for example, selecting to use a static scheduling strategy or a dynamic scheduling strategy.
[0190] (3) Determine the target CPU core to be scheduled based on the selected scheduling strategy.
[0191] (4) Add the data message to be forwarded and the key information of the corresponding acceleration table entry to the queue of the target CPU core.
[0192] Since the network device can perform forwarding on multiple data streams in parallel, that is, there can be multiple data messages of data streams added to the queue of the target CPU core, Figure 7 which illustrates that the queue includes N queue elements (queue element 1~queue element N), N is a positive integer, and the queue elements in the queue can be read according to the first-in first-out strategy.
[0193] (5) SMP switches the CPU core and triggers a soft interrupt.
[0194] When the SMP switches the CPU core, a soft interrupt can be triggered, which can further trigger the poll callback of the target CPU core.
[0195] (6) Trigger the poll callback of the target CPU core.
[0196] (7) The target CPU core reads the data packet to be forwarded and the key information of the corresponding acceleration table item from the queue of the target CPU core.
[0197] (8) The target CPU core determines the outgoing interface device and the outgoing interface of the data packet based on the key information of the acceleration table item.
[0198] (9) The target CPU core obtains the L2 and L3 layer key information from the key information of the acceleration table item, and updates the L2 and L3 layer key information to the data packet to be forwarded.
[0199] (10) The target CPU core calls the outgoing interface of the outgoing interface device to send the updated data packet out through the network card.
[0200] In some embodiments, in order to realize the scheduling of the CPU core based on the dynamic scheduling strategy, an intelligent identification module for identifying the service type can be set in the kernel layer of the network device. The intelligent identification module can identify the service type corresponding to the data stream according to the input data stream. Taking the service type of the data stream as an application type for example, the corresponding application name can be identified based on the input data stream, and the application type can be determined based on the application name. For example, the application type can include game type, live broadcast type (game live broadcast or other live broadcast), application market type, download type, video type, short video type, news type, social chat type, e-commerce shopping type, online course type, etc. The application type can be divided according to actual needs, and the embodiments of the present application are not limited thereto.
[0201] For example, as shown in the following Table 4, the intelligent identification module can realize the identification of the following application types. The application types exemplified in Table 4 do not constitute a limitation on the intelligent identification module, and the intelligent identification module can also identify data streams of other application types not exemplified in Table 4.
[0202] Table 4
[0203]
[0204] Different application programs usually use different protocols, and different application protocols have their own characteristics, which can be specific ports, specific strings or specific bit sequences. The characteristics that can identify the protocol are called feature codes. The intelligent identification module can determine the application by matching the feature codes in the data packet. The data packets exchanged by different application programs usually also include specific fields that can be distinguished from other application programs, and the intelligent identification module can also determine the application by matching the specific fields in the data packet.
[0205] In some embodiments, the intelligent identification module can be deployed in the network protocol stack. For example, the Netfilter framework is a management mechanism introduced by the Linux system to provide a complete set of detection point (HOOK) functions, so that the kernel can check, modify and discard the data packets entering and exiting the network interface. The network layer generally includes five HOOK points: Pre-Routing node, Local_IN node, Forward node, Local_OUT node, and Post-Routing node. The data flow forwarded by the network device generally passes through the Pre-Routing node, Forward node and Post-Routing node. The intelligent identification module can work in the FORWARD node. The intelligent identification module can identify and record the business types corresponding to each data flow in units of data flow.
[0206] As shown in Figure 8 , the working position of the intelligent identification module in the Netfilter framework is illustrated. The intelligent identification module is set at the FORWARD node.
[0207] When the data packet is transmitted from the data link layer, if the data packet is to access the network device itself, the data packet passes through the PRE_ROUTING node and the LOCAL_IN node to reach the transport layer and the application layer. When the data packet is transmitted from the network device to the outside, the data packet passes through the LOCAL_OUT node and the POST_ROUTING node to be transmitted to the outside. When the data packet is transmitted from the data link layer, if the data packet needs to be forwarded, the data packet passes through the PRE_ROUTING node, FORWARD node and POST_ROUTING node to be transmitted to the outside.
[0208] The intelligent identification module at the FORWARD node can obtain the five-tuple information of the data packet and save the five-tuple information of the data packet in the memory. Meanwhile, the intelligent identification module can also determine the application type of the data flow by matching the specific fields in the data packet, and save the mapping relationship between the five-tuple information and the application type in the memory.
[0209] Please refer to Figure 9 and Figure 10 , the interaction process of the internal functional components in the network device to realize data packet forwarding is illustrated.
[0210] If the data packet is the first data packet of the data flow, the interaction process includes the following processes:
[0211] 901, the network card driver receives the data packet.
[0212] 902, the network card driver sends the data packet to the software acceleration module 20.
[0213] 903, the soft acceleration module 20 sends the data packet to the network protocol stack.
[0214] For the first data packet of the data flow, the soft acceleration module 20 forwards the data packet to the network protocol stack for processing, because the acceleration table item has not been created.
[0215] 904, the network protocol stack processes the data packet, and calls the intelligent identification module to identify the application type of the data flow.
[0216] In some embodiments, in the process of processing the data packet, the FORWARD hook node in the network layer of the network protocol stack can call the intelligent identification module to identify the application type of the data flow, and construct the mapping relationship between the five-tuple information of the data flow and the application type. The mapping relationship can be stored in the memory, and a plurality of mapping relationships between the five-tuple information and the corresponding application type can be saved by constructing a mapping relationship table.
[0217] 905, the network protocol stack sends the processed data packet to the soft acceleration module 20.
[0218] 906, the soft acceleration module 20 creates an acceleration table item based on the related information of the processed data packet.
[0219] The related information can include the five-tuple information (source IP address, destination IP address, source port number, destination port number and transmission protocol) of the data packet, the ingress device information of the data packet, the egress interface device information set of the data packet, which can include the egress interface device information of the data packet, the forwarding direction of the data packet, the egress interface operation set of the data packet, the related information of the protocol layer, etc.
[0220] 907, the soft acceleration module 20 forwards the data packet processed by the network protocol stack to the network card driver.
[0221] In some embodiments, the processes 906 and 907 can be executed in parallel.
[0222] 908, the network card driver drives the network card to send the data packet processed by the network protocol stack.
[0223] If the data packet is not the first data packet of the data flow, the interaction process includes the following processes:
[0224] 101, the network card driver receives the data packet.
[0225] 102, the network card driver sends the data packet to the soft acceleration module 20.
[0226] 103, the soft acceleration module 20 determines the application type to which the data flow belongs based on the five-tuple information of the data packet, and determines the target CPU core to be scheduled based on the static scheduling strategy, the usage rate of each CPU core, and the application type to which the data flow belongs.
[0227] 104, the soft acceleration module 20 performs CPU core scheduling to schedule to the target CPU core.
[0228] 105, the soft acceleration module 20 processes the data packet.
[0229] For example, processing the data packet can include determining the out-interface device and the out-interface of the data packet based on the key information of the acceleration entry, and updating the key information of the L2 and L3 layers to the data packet.
[0230] 106, the soft acceleration module 20 sends the processed data packet to the network card driver.
[0231] 107, the network card driver drives the network card to send out the processed data packet.
[0232] In some embodiments, before performing the CPU core scheduling, the flow is executed on the current CPU core, for example, the flow 101-103 is executed on the current CPU core, and after performing the CPU core scheduling, the flow is transferred to the target CPU core for execution, for example, the flow 105-107 is executed on the target CPU core.
[0233] In order to further understand the scheduling logic involved in the CPU core scheduling performed by the soft acceleration module 20 of the present application, the following will be described in combination with Figure 11 The process of the soft acceleration module 20 performing CPU core scheduling in the process of the network device forwarding a certain data flow is described in detail.
[0234] S111, obtaining the five-tuple information of the data packet, and searching for the application type to which the data flow belongs based on the five-tuple information of the data packet.
[0235] In some embodiments, after obtaining the five-tuple information of the data packet, the soft acceleration module 20 can compare the obtained five-tuple information with the mapping relationship table between the five-tuple information stored in the memory and the application type, to search for the application type to which the data flow belongs.
[0236] In some embodiments, if the application type to which the data flow belongs is found, step S112 can be performed, and if the application type to which the data flow belongs is not found, step S116 can be performed.
[0237] S112, obtaining the usage rate of each CPU core.
[0238] For example, the soft acceleration module 20 can obtain the usage of each CPU core through the system state statistics interface / proc / stat.
[0239] In S113, whether the target CPU core needs to be reset is determined according to the application type to which the data stream belongs and the usage of each CPU core.
[0240] In some embodiments, the target CPU core can refer to the CPU core to be finally scheduled. For example, if the usage of each CPU core changes, the target CPU core can be reset based on the application type to which the data stream belongs and the usage of each CPU core. If it is determined that the target CPU core needs to be reset, S114 can be performed, and if it is determined that the target CPU core does not need to be reset, S116 can be performed.
[0241] For example, the CPU core determined based on the application type to which the data stream belongs and the usage of each CPU core can be compared with the last set CPU core. If they are different, it is determined that the target CPU core needs to be reset, and if they are the same, it is determined that the target CPU core does not need to be reset.
[0242] In S114, whether the duration of the current time from the time when the target CPU core was last set is greater than a preset duration is determined.
[0243] After it is determined that the target CPU core needs to be reset, the duration of the current time from the time when the target CPU core was last set can be calculated and compared with the preset duration. If it is greater than the preset duration, S115 can be performed, and if it is not greater than the preset duration, S116 can be performed. The step S114 can avoid frequent setting of the target CPU core. The preset duration can be set according to actual needs, which is not limited in the embodiments of the present application. For example, the preset duration is 10s.
[0244] In S115, the target CPU core is reset according to the application type to which the data stream belongs and the usage of each CPU core.
[0245] After it is determined that the duration of the current time from the time when the target CPU core was last set is greater than the preset duration, the target CPU core can be reset according to the application type to which the data stream belongs and the usage of each CPU core.
[0246] In S116, the CPU core last scheduled is taken as the target CPU core.
[0247] The last scheduled CPU core can refer to a CPU core scheduled for forwarding a last data packet of the current data packet. The last scheduled CPU core can be a target CPU core determined based on an application type to which a data flow belongs and usage rates of each CPU core, or a target CPU core determined based on a static scheduling strategy.
[0248] S117, performing CPU core switching to switch a forwarding process of the data packet from the current CPU core to the target CPU core.
[0249] After resetting the target CPU core or taking the last scheduled CPU core as the target CPU core, CPU core switching can be performed to switch a forwarding process of the data packet from the current CPU core to the target CPU core.
[0250] Referring to FIG. 1, a packet forwarding method provided by an embodiment of the present application is shown. The packet forwarding method can be applied to a network device, and a CPU of the network device includes a plurality of CPU cores. The packet forwarding method includes: Figure 12
[0251] S121, receiving a data packet to be forwarded.
[0252] In some embodiments, the data packet to be forwarded can be received by a network card driver.
[0253] S122, determining whether an acceleration table item corresponding to the data packet is matched.
[0254] In some embodiments, five-tuple information of the data packet to be forwarded can be obtained, and it is determined whether the network device stores an acceleration table item corresponding to the data packet based on the five-tuple information of the data packet to be forwarded. For example, after obtaining the five-tuple information of the data packet, a packet hash value corresponding to the data packet can be calculated based on the five-tuple information, and the calculated packet hash value can be compared with packet hash values stored in each acceleration table item stored in the network device to determine whether an acceleration table item corresponding to the data packet is matched.
[0255] S123, in a case where an acceleration table item corresponding to the data packet is not matched, performing forwarding processing of the data packet on the current CPU core.
[0256] In a case where the acceleration table item corresponding to the data packet is not matched, it is indicated that the data packet to be forwarded can be the first data packet of the data flow, and the network device has not created the corresponding acceleration table item in time. In this case, the network protocol stack can be used to process the data packet, and the switching of the CPU core is not performed. That is, the forwarding processing of the data packet on the current CPU core can include: processing the data packet by using the network protocol stack, and sending the processed data packet through the network card driver.
[0257] In some embodiments, after the data packet is processed by the network protocol stack, relevant information can be extracted from the data packet. The relevant information can include ingress device information, five-tuple information, and packet forwarding information, etc. Then, the corresponding acceleration table item is created according to the relevant information of the data packet, so that the subsequent data packet forwarding of the data flow can not pass through the processing of the network protocol stack, and the packet forwarding efficiency is improved.
[0258] S124, in a case where the acceleration table item corresponding to the data packet is matched, determining a target CPU core to be scheduled, and the acceleration table item includes packet forwarding information of the data packet.
[0259] In a case where the acceleration table item corresponding to the data packet is matched, it is indicated that the forwarding of the data packet can be performed in the form of CPU scheduling, and the data packet can not need to pass through the processing of the network protocol stack. The target CPU core to be scheduled can be determined based on a static scheduling strategy or a dynamic scheduling strategy.
[0260] S125, adding the data packet and the packet forwarding information corresponding to the data packet to a queue of the target CPU core.
[0261] After the target CPU core is determined, the data packet and the packet forwarding information corresponding to the data packet can be added to the queue of the target CPU core, so as to facilitate the subsequent forwarding of the data packet by the target CPU core.
[0262] S126, performing the forwarding processing of the data packet by the target CPU core.
[0263] After the data packet and the packet forwarding information corresponding to the data packet are added to the queue of the target CPU core, the switching of the CPU core can be performed, and the forwarding processing of the data packet is switched from the current CPU core to the target CPU core, that is, the target CPU core completes the subsequent forwarding process of the data packet.
[0264] For example, the poll callback of the target CPU core can be triggered by performing the CPU core switching, the data packet and the packet forwarding information of the data packet can be read from the queue of the target CPU core, the out-interface device and the out-interface of the data packet can be determined based on the packet forwarding information of the data packet, the data packet can be updated, and finally the updated data packet is sent out by calling the out-interface.
[0265] Figure 13 The schematic diagram of the network device in the embodiment of the present application is shown. The network device 100 includes a processor 1001, a memory 1002 coupled to the processor 1001, and a transceiver 1003. The processor 1001 can be a central processing unit (CPU), a network processor (NP), or a combination of the CPU and the NP. The processor 1001 can also be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof. The processor 1001 can refer to one processor, or can include multiple processors. The transceiver 1003 is configured to receive a data packet to be forwarded, and send the packet to the processor 1001 for subsequent operation and processing. The memory 1002 can include a volatile memory, such as a random-access memory (RAM); the memory can also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); the memory 1002 can also include a combination of the above-mentioned memories. The memory 1002 stores one or more computer programs 1004. The one or more computer programs 1004 are configured to be executed by the processor 1001. The one or more computer programs 1004 include instructions that can be used to implement the method of forwarding a packet in the network device 100, as described above. Figure 12 The packet forwarding method.
[0266] The embodiment further provides a computer storage medium, wherein computer instructions are stored in the computer storage medium, and when the computer instructions are run on a network device, the network device is caused to perform the related method steps to implement the packet forwarding method in the above embodiment.
[0267] The embodiment further provides a computer program product, when the computer program product is run on a computer, the computer is caused to perform the related steps to implement the packet forwarding method in the above embodiment.
[0268] In addition, the embodiment of the present application further provides an apparatus, which can be a chip, a component or a module, and the apparatus can include a processor and a memory connected to each other, wherein the memory is used to store computer execution instructions, and when the apparatus is running, the processor can execute the computer execution instructions stored in the memory to enable the chip to perform the packet forwarding method in the above method embodiments.
[0269] The network device, the computer storage medium, the computer program product or the chip provided by the embodiment are used to execute the corresponding method provided above, and thus the beneficial effects achieved by the network device, the computer storage medium, the computer program product or the chip can refer to the beneficial effects of the corresponding method provided above, which will not be described here again.
[0270] Through the description of the above implementation, those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above functional modules is taken as an example for illustration, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the apparatus is divided into different functional modules to complete all or part of the functions described above.
[0271] In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. For example, the apparatus embodiments described above are only illustrative, and the division of the modules or units is a logical function division, and there can be another division way in actual implementation, for example, a plurality of units or components can be combined or integrated into another apparatus, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, apparatuses or units, and can be electrical, mechanical or other forms.
[0272] The units described as separate components can or can not be physically separate, and the components shown as units can be one physical unit or multiple physical units, that is, can be located in one place, or can be distributed to multiple different places. According to actual needs, part or all of the units can be selected to achieve the purpose of the embodiment scheme.
[0273] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.
[0274] When the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application or the essential part of the contribution to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for causing an apparatus (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk, and various storage medium capable of storing program codes.
[0275] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any change or replacement within the technical scope disclosed in the present application should be covered in the protection scope of the present application.
Claims
1. A packet forwarding method applied to a network device, characterized in that, The central processor (CPU) of the network device has multiple CPU cores, and the method comprises: receiving a data packet to be forwarded; in a case of matching an acceleration table item corresponding to the data packet, determining a target CPU core to be scheduled, the acceleration table item comprising packet forwarding information of the data packet; adding the data packet and the packet forwarding information corresponding to the data packet into a queue of the target CPU core, and performing forwarding processing of the data packet by the target CPU core.
2. The method of claim 1, wherein, After the receiving of the data packet to be forwarded, the method further comprises: in a case of not matching the acceleration table item corresponding to the data packet, performing the forwarding processing of the data packet by a current CPU core, wherein the performing of the forwarding processing of the data packet by the current CPU core comprises processing the data packet by using a network protocol stack, and sending the processed data packet out through a network card driver.
3. The method of claim 2, wherein, The method further comprises: extracting ingress device information, quintuple information and the packet forwarding information from the data packet processed by the network protocol stack; constructing the acceleration table item corresponding to the data packet based on the ingress device information, the quintuple information and the packet forwarding information.
4. The method of claim 3, wherein, The constructing of the acceleration table item corresponding to the data packet based on the ingress device information, the quintuple information and the packet forwarding information comprises: calculating a packet hash value of the data packet based on the quintuple information; determining whether the network device has stored the acceleration table item corresponding to the data packet based on the packet hash value; in a case that the network device does not store the acceleration table item corresponding to the data packet, constructing the acceleration table item corresponding to the data packet based on the ingress device information, the quintuple information and the packet forwarding information.
5. The method of claim 1, wherein, After the receiving of the data packet to be forwarded, the method further comprises: extracting quintuple information from the data packet, and calculating a packet hash value of the data packet based on the quintuple information; comparing the packet hash value of the data packet with a packet hash value recorded in each acceleration table item currently stored, to obtain the acceleration table item matching the data packet.
6. The method of claim 1, wherein, The determining of the target CPU core to be scheduled comprises: determining a pre-scheduled CPU core based on a pre-configured static scheduling strategy; in a case that a state of the pre-scheduled CPU core does not meet a preset condition, determining the pre-scheduled CPU core as the target CPU core, the preset condition comprising that the pre-scheduled CPU core has a highest usage rate among the multiple CPU cores; in a case that the state of the pre-scheduled CPU core meets the preset condition, obtaining an application type to which the data packet belongs and a usage rate of each CPU core among the multiple CPU cores, and determining the target CPU core based on the application type to which the data packet belongs, the usage rate of each CPU core and a pre-configured dynamic scheduling strategy.
7. The method of claim 6, wherein, The static scheduling strategy comprises any one of the following: determine the pre-scheduled CPU core based on a binding relationship between a message type of the data message and the CPU core; determine the pre-scheduled CPU core based on a binding relationship between a message priority of the data message and the CPU core; determine the pre-scheduled CPU core based on a CPU core identifier recorded in the acceleration table entry.
8. The method of claim 1, wherein, The determining of the target CPU core to be scheduled includes: determine the target CPU core to be scheduled based on a pre-configured static scheduling strategy, the static scheduling strategy including determining the target CPU core based on a binding relationship between a message type of the data message and the CPU core, determining the target CPU core based on a binding relationship between a message priority of the data message and the CPU core, or determining the target CPU core based on a CPU core identifier recorded in the acceleration table entry.
9. The method of claim 7 or 8, wherein, The CPU core identifier recorded in the acceleration table entry is an identifier of a CPU core having the least number of acceleration table entries in a queue when the acceleration table entry is created.
10. The method of claim 1, wherein, The forwarding processing of the data message performed by the target CPU core includes: switch the forwarding processing of the data message from a current CPU core to the target CPU core, triggering a poll callback of the target CPU core; read the data message and message forwarding information of the data message from a queue of the target CPU core; determine an egress device and an egress interface of the data message based on the message forwarding information of the data message, and update the data message; invoke the egress interface of the egress device to send the updated data message.
11. The method of claim 10, wherein, The message forwarding information includes egress device information, an egress interface operation set, and related information of a specified protocol layer, the specified protocol layer including a network layer and a transport layer, and the determining of the egress device and the egress interface of the data message based on the message forwarding information of the data message, and the updating of the data message includes: determine the egress device of the data message based on the egress device information; determine the egress interface of the data message based on the egress interface operation set; update the related information of the protocol layer to the data message.
12. The method according to any one of claims 1 to 11, characterized in that, The network device includes one of a router, a switch, a forwarder, a virtual switch, a virtual router, and a virtual forwarder.
13. A network device, comprising: The network device includes a memory and a processor; The memory is configured to store program instructions; The processor is configured to read the program instructions stored in the memory to implement the message forwarding method in any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer readable instructions, and the computer readable instructions are executed by a processor to implement the message forwarding method in any one of claims 1 to 12.
15. A chip coupled to a memory in a network device, characterized in that, The chip is configured to control the network device to implement the message forwarding method in any one of claims 1 to 12.
Citation Information
Patent Citations
Firewall system of user mode pipeline architecture
CN111614631A
Data transmission method and device
WO2021043181A1