Packet forwarding method and device, forwarding equipment and storage medium
By using the collaborative processing of the flow splitting core and the target forwarding core in a multi-core CPU network device, the problem of how to improve packet forwarding performance is solved, and efficient packet forwarding and flow-preserving forwarding are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MAIPU COMM TECH CO LTD
- Filing Date
- 2022-12-26
- Publication Date
- 2026-07-24
AI Technical Summary
In network devices with multi-core CPUs, how can we fully utilize the advantages of multi-core CPUs to improve packet forwarding performance?
In a multi-core CPU forwarding device, a traffic splitting core is used to obtain packets to be forwarded from a hardware queue and to determine the target forwarding core from multiple forwarding cores. Services that need to be executed before the packets to be forwarded are scheduled to the traffic splitting core and the target forwarding core for execution, and finally the target forwarding core forwards the packets.
It improves the packet forwarding performance of network devices, makes full use of the advantages of multi-core CPUs, ensures the in-order forwarding of packets in the same stream, and adapts to the needs of different application scenarios through dynamic and static scheduling.
Smart Images

Figure CN116028218B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, and more specifically, to a message forwarding method, apparatus, forwarding device, and storage medium. Background Technology
[0002] In the internet, data packets pass through network devices such as routers and firewalls. These devices perform complex processing, including Network Address Translation (NAT) and application identification, before forwarding the packets. These complex processes cannot be handled by hardware; therefore, software forwarding is used. However, software forwarding relies on hardware factors such as the network device's CPU and memory performance. For achieving higher software forwarding performance, a multi-core CPU is a good option.
[0003] In scenarios where multi-core CPUs forward packets, how to fully utilize the advantages of multi-core CPUs to improve the packet forwarding performance of network devices is a problem that urgently needs to be solved by those in the field. Summary of the Invention
[0004] The purpose of this invention is to provide a message forwarding method, apparatus, forwarding device, and storage medium that can improve the performance of network devices in forwarding messages.
[0005] The embodiments of the present invention can be implemented as follows:
[0006] In a first aspect, the present invention provides a message forwarding method applied to the traffic splitting core of a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes multiple forwarding cores, and the method includes:
[0007] Obtain a packet to be forwarded from a hardware queue, wherein the hardware queue is associated with the port where the forwarding device receives packets;
[0008] Determine the target forwarding core from the plurality of forwarding cores for forwarding the packet to be forwarded;
[0009] The services that need to be executed before the message to be forwarded are scheduled to be executed by the distribution core and the target forwarding core, and the message to be forwarded is forwarded by the target forwarding core.
[0010] In an optional implementation, the services that need to be performed before the forwarded packet includes transferable services that do not change the length and content of the forwarded packet and non-transferable services that change the length and content of the forwarded packet. The step of scheduling the services that need to be performed before the forwarded packet to the splitting core and the target forwarding core for execution includes:
[0011] The non-transferable service is scheduled to be executed on the target forwarding core;
[0012] The transferable service is scheduled to be executed by the distribution core and the target forwarding core.
[0013] In an optional implementation, each forwarding core corresponds to a software queue, and the step of scheduling the transferable service to the offloading core and the target forwarding core includes:
[0014] The preset services in the transferable services are scheduled to be executed by the distribution core;
[0015] Obtain the number of packets in the software queue corresponding to the target forwarding core;
[0016] If the number of messages is greater than the first preset value, then select an unexecuted service from the remaining services other than the preset service in the transferable services and schedule it to the distribution core;
[0017] Repeat the step of obtaining the number of packets in the software queue corresponding to the target forwarding core until there are no unexecuted services in the transferable services or the number of packets is not greater than the first preset value;
[0018] If the number of packets is not greater than the first preset value and there are unexecuted services among the transferable services, then the unexecuted services among the transferable services will be scheduled to the target forwarding core.
[0019] In an optional implementation, the method further includes:
[0020] If the number of packets is less than the second preset value, the services that have not yet been executed in the diversion core will be rescheduled to the target forwarding core for execution.
[0021] In an optional implementation, the step of scheduling the services that need to be performed before forwarding the packet to be forwarded to the splitting core and the target forwarding core for execution further includes:
[0022] Obtain the list of traffic splitting core services and the list of forwarding core services that are predetermined based on the application scenario;
[0023] The services that need to be executed before forwarding the packets that exist in the service list of the distribution core are scheduled to be executed by the distribution core, and the services that need to be executed before forwarding the packets that exist in the service list of the forwarding core are scheduled to be executed by the target forwarding core.
[0024] Secondly, the present invention provides a message forwarding method applied to the control core of a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes a flow-splitting core and multiple forwarding cores, and the method includes:
[0025] Obtain the number of packets that each forwarding core needs to forward, wherein the packets are allocated to the forwarding core by the diversion core according to any one of the foregoing embodiments;
[0026] Based on the number of packets in each forwarding core, the pending services of each forwarding core are reallocated. The pending services of each forwarding core include transferable services that need to be executed before each forwarding core forwards packets, and which have not yet been executed, without changing the length and content of the packets.
[0027] In an optional implementation, the step of reallocating the pending services of each forwarding core based on the number of packets of each forwarding core includes:
[0028] For any forwarding core to be adjusted, if the number of packets to be forwarded by the forwarding core to be adjusted is greater than a third preset value, then the service to be allocated is determined from the services to be executed by the forwarding core to be adjusted and the service to be allocated is allocated to the distribution core for execution.
[0029] If the number of packets to be forwarded by the forwarding core to be adjusted is less than the fourth preset value, then the service to be allocated is determined from the pending services of the diversion core, and the service to be allocated is assigned to the forwarding core to be adjusted for execution. The packets to which the service to be allocated belongs need to be forwarded by the forwarding core to be adjusted.
[0030] Thirdly, the present invention provides a message forwarding device applied to the traffic splitting core of a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes multiple forwarding cores, and the device includes:
[0031] The message acquisition module is used to acquire messages to be forwarded from a hardware queue, wherein the hardware queue is associated with the port of the forwarding device that receives messages;
[0032] A determining module is configured to determine, from the plurality of forwarding cores, a target forwarding core for forwarding the packet to be forwarded;
[0033] The scheduling module is used to schedule the services that need to be executed before the packet to be forwarded to the splitting core and the target forwarding core for execution, and the target forwarding core forwards the packet to be forwarded.
[0034] Fourthly, the present invention provides a message forwarding device applied to the control core of a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes a flow-splitting core and multiple forwarding cores, and the device comprises:
[0035] The packet count acquisition module is used to acquire the number of packets that each forwarding core needs to forward, wherein the packets are allocated to the forwarding core by the diversion core according to any one of the foregoing embodiments;
[0036] The allocation module is used to reallocate the pending services of each forwarding core according to the number of packets of each forwarding core. The pending services of each forwarding core include transferable services that need to be executed before each forwarding core forwards packets and have not yet been executed, without changing the length and content of the packets.
[0037] Fifthly, the present invention provides a forwarding device, including a multi-core CPU and a memory. The multi-core CPU includes a traffic splitting core, multiple forwarding cores, and a control core. The memory is used to store a program. The traffic splitting core is used to implement the packet forwarding method described in any one of the foregoing embodiments when executing the program. The control core is used to implement the packet forwarding method described in any one of the foregoing embodiments when executing the program.
[0038] In a sixth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a traffic splitter, implements the packet forwarding method as described in any of the foregoing embodiments, and which, when executed by a control core, implements the packet forwarding method as described in any of the foregoing embodiments.
[0039] Compared with the prior art, the embodiments of the present invention provide a packet forwarding method, apparatus, forwarding device and storage medium. The splitting core in a multi-core CPU obtains the packet to be forwarded from the hardware queue, then determines the target forwarding core for the user to forward the packet from multiple forwarding cores, and finally schedules the services that need to be executed before the packet to be forwarded to the splitting core and the target forwarding core for execution, and the target forwarding core forwards the packet to be forwarded. By scheduling the services that need to be executed before the packet to be forwarded to the splitting core and the target forwarding core for execution, the advantages of multi-core CPUs can be fully utilized, and the performance of network devices in forwarding packets can be improved. Attached Figure Description
[0040] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1(a) is a model example of the shunting core and forwarding core provided in this embodiment.
[0042] Figure 1(b) shows a model example of the shunting core and forwarding core provided in this embodiment. Figure 2 .
[0043] Figure 2 This is a block diagram of the forwarding device provided in this embodiment.
[0044] Figure 3 This is a flowchart illustrating a packet forwarding method applied to a traffic splitting core, as provided in an embodiment of the present invention.
[0045] Figure 4 This is an example diagram of message order-preserving forwarding provided in this embodiment.
[0046] Figure 5 This is a flowchart illustrating a message forwarding method applied to a control kernel, as provided in an embodiment of the present invention.
[0047] Figure 6 This is a block diagram of a packet forwarding device applied to a traffic splitting core, provided in an embodiment of the present invention.
[0048] Figure 7 This is a block diagram of a message forwarding device applied to a control core, provided in an embodiment of the present invention.
[0049] Icons: 10-Forwarding device; 11-Multi-core CPU; 12-Memory; 13-Bus; 100-Message forwarding device applied to the distribution core; 110-Message acquisition module; 120-Determination module; 130-Scheduling module; 200-Message forwarding device applied to the control core; 210-Message count acquisition module; 220-Allocation module. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0051] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0052] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0053] In the description of this invention, it should be noted that if terms such as "upper," "lower," "inner," or "outer" are used to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship in which the product of this invention is usually placed, they are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention.
[0054] Furthermore, the terms "first" and "second" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0055] It should be noted that, where there is no conflict, the features in the embodiments of the present invention can be combined with each other.
[0056] Please refer to Figure 1(a). Figure 1(a) is a model example of the traffic splitting core and forwarding core provided in this embodiment. In Figure 1(a), the multi-core CPU includes one traffic splitting core and two forwarding cores: forwarding core 1 and forwarding core 2. One traffic splitting core corresponds to one hardware queue, and one hardware queue is associated with one port. That is, packets received from this port are placed into the corresponding hardware queue. One forwarding core corresponds to one software queue, and packets that need to be forwarded by the forwarding core are placed into the software queue corresponding to that forwarding core. The traffic splitting core obtains the packets to be forwarded from the hardware queue, determines the target forwarding core of the packets to be forwarded, and the target forwarding core forwards the packets to be forwarded. If the target forwarding core is forwarding core 1, the packets to be forwarded are placed into the software queue of forwarding core 1; if the target forwarding core is forwarding core 2, the packets to be forwarded are placed into the software queue of forwarding core 2.
[0057] Figure 1(a) is a model example with a single traffic splitter core. In fact, there can be multiple traffic splitter cores. Please refer to Figure 1(b), which is a model example of the traffic splitter core and forwarding core provided in this embodiment. Figure 2 In Figure 1(b), there are two traffic splitting cores: Traffic Splitting Core 1 and Traffic Splitting Core 2, each corresponding to a hardware queue: Hardware Queue 1 and Hardware Queue 2. There are four forwarding cores: Forwarding Core 1 to Forwarding Core 4. Each forwarding core corresponds to two software queues, and each software queue corresponds to one of the two traffic splitting cores. For example, software queue 11 of forwarding core 1 corresponds to traffic splitting core 1, and software queue 12 corresponds to traffic splitting core 2. The other forwarding cores are similar. For any traffic splitting core, the working principle is similar to that of a traffic splitting core in Figure 1(a).
[0058] It should be noted that Figure 1(b) is only an example of two shunt cores. In actual application scenarios, there can be more than two shunt cores. The working principle of each shunt core is the same and similar to that of one shunt core in Figure 1(a).
[0059] Based on the model example diagrams of Figures 1(a) and 1(b), this embodiment also provides a block example diagram of the forwarding device 10, which includes a multi-core CPU 11, a memory 12 and a bus 13, with the multi-core CPU 11 and the memory 12 connected through the bus 13.
[0060] Forwarding device 10 can be a router, switch, or other device used for packet forwarding.
[0061] The multi-core CPU11 can be an integrated circuit chip with signal processing capabilities. Based on its function, the multi-core CPU11 is divided into a traffic splitting core, a forwarding core, and a control core. The traffic splitting core is responsible for retrieving packets from the hardware queue, classifying the packets, determining the forwarding core to forward the packet based on the classification result, and placing the packet into the software queue of that forwarding core. The forwarding core is responsible for forwarding the packets in its corresponding software queue. The control core handles all other services besides those handled by the traffic splitting and forwarding cores.
[0062] The memory 12 is used to store programs, such as the packet forwarding device applied to the traffic splitting core or the packet forwarding device applied to the control core in the following embodiments. The packet forwarding device applied to the traffic splitting core or the packet forwarding device applied to the control core includes at least one software function module that can be stored in the memory 12 in the form of software or firmware or embedded in the operating system (OS) of the forwarding device 10. After receiving the execution instruction, the processor 11 executes the program to implement the packet forwarding method applied to the traffic splitting core or the packet forwarding method applied to the control core disclosed in the above embodiments.
[0063] In Figure 1(a), Figure 1(b) and Figure 2 Based on this, this embodiment provides a message forwarding method, applicable to the splitting cores shown in Figure 1(a) and Figure 1(b), or applicable to... Figure 2 For the traffic distribution cores of the multi-core CPU 11 in the relay device 10, please refer to... Figure 3 , Figure 3 The flowchart illustrates a packet forwarding method applied to a traffic splitting core, as provided in an embodiment of the present invention. The method includes the following steps:
[0064] Step S101: Obtain the message to be forwarded from the hardware queue, wherein the hardware queue is associated with the port of the forwarding device that receives messages.
[0065] In this embodiment, there can be one or more traffic splitting cores. Each traffic splitting core corresponds to a hardware queue, and each hardware queue corresponds to a port. That is, packets received from the port are put into the corresponding hardware queue.
[0066] Step S102: Determine the target forwarding core from among multiple forwarding cores for forwarding the packet to be forwarded.
[0067] In this embodiment, one way to determine the target forwarding core is to determine the target forwarding core based on the 5-tuple of the packet to be forwarded. For example, each forwarding core is assigned a sequence number, and a preset hash function is used to calculate the hash value of the 5-tuple. The hash function can be set based on the number of forwarding cores to ensure that the hash value is less than or equal to the number of forwarding cores. The forwarding core with the sequence number and hash value is determined as the target forwarding core. The 5-tuple includes a set of five fields from the packet to be forwarded: source IP address, source port, destination IP address, destination port, and protocol number. Since packets with the same 5-tuple belong to the same order, determining the forwarding core according to the 5-tuple ensures that packets of the same order will be assigned to the same forwarding core for forwarding. Since packets in the software queue are forwarded sequentially, this ensures ordered forwarding of packets of the same order, i.e., order-preserving forwarding of packets by flow. Please refer to [link / reference]. Figure 4 , Figure 4 This is an example diagram of message order-preserving forwarding provided in this embodiment. Figure 4 In this system, there is one hardware queue and two software queues: Software Queue 1 and Software Queue 2. The packet flow is: a1, a2, b1, b2, a3, b3. Among them, the 5-tuples of a1, a2, and a3 are the same and are assigned to Software Queue 1. The 5-tuples of b1, b2, and b3 are the same and are assigned to Software Queue 2. It can be seen that packets with the same 5-tuple are placed into the corresponding software queues in sequence and processed in sequence, thereby ensuring ordered forwarding.
[0068] Step S103: Schedule the services that need to be performed before forwarding the message to be forwarded to the distribution core and the target forwarding core for execution, and then have the target forwarding core forward the message to be forwarded.
[0069] In this embodiment, before actual forwarding, packets typically go through the link layer input stage, network layer input stage, routing stage, network layer output stage, and link layer output stage in chronological order of processing time. The services that need to be executed at each stage before forwarding the packet also differ. For example, typical services in the link layer input stage include link resolution, MAC (Media Access Control) services, and ACL (Access Control List) services; typical services in the network layer input stage include layer 3 packet resolution, layer 4 packet resolution, ACL services, and NAT (Network Address Translation) services; and typical services in the routing stage include route lookup. Some services can be executed by either the routing core or the forwarding core, while others must be executed by the forwarding core. For services that can be executed by both the routing core and the forwarding core, they can be scheduled to these two types of cores for joint execution. This improves the efficiency of the services that need to be executed before forwarding the packet, fully utilizes the processing power of each core of the multi-core CPU, and ultimately improves the packet forwarding performance of the network device.
[0070] The method described in this embodiment, by scheduling the services that need to be executed before forwarding the packet to be forwarded to the splitting core and the target forwarding core, can make full use of the advantages of multi-core CPUs and ultimately improve the performance of network devices in forwarding packets.
[0071] In an optional implementation, the services that need to be performed before the forwarded message is forwarded include transferable services that do not change the length and content of the message to be forwarded and non-transferable services that change the length and content of the message to be forwarded. Transferable services can be performed by the splitting core or the forwarding core, while non-transferable services can only be performed by the forwarding core.
[0072] As a scheduling method, its implementation can be as follows:
[0073] Schedule non-transferable services to the target forwarding core for execution;
[0074] Transferable services are scheduled to be executed on the distribution core and the target forwarding core.
[0075] In an optional implementation, the method for scheduling transferable services to the offloading core and the target forwarding core for execution can be:
[0076] First, schedule the preset services in the transferable services to the distribution core for execution.
[0077] In this embodiment, the preset service can be some typical services in the link layer input stage, network layer input stage, and routing stage of the packet. Since the link resolution in the link input stage and the three-layer resolution in the network layer input stage need to be performed in all network environments, these two services can be fixed as preset services on the traffic splitting core for processing. Thus, the traffic splitting core can share some of the service execution, improve the packet forwarding capability of multi-core CPUs, and ultimately improve the packet forwarding capability of the forwarding device.
[0078] Second, based on the number of packets in the software queue corresponding to the target forwarding core, the remaining services in the transferable services, excluding the preset services, are scheduled to the distribution core and forwarding core for execution.
[0079] In this embodiment, in order to more rationally schedule the remaining services other than the preset services in the transferable services, one implementation method is as follows:
[0080] First, obtain the number of packets in the software queue corresponding to the target forwarding core;
[0081] In this embodiment, the number of packets in the software queue corresponding to the target forwarding core represents the forwarding load of the target forwarding core. The more packets there are, the greater the forwarding load of the target forwarding core, and the more it needs a traffic offloading core to share its service execution in order to alleviate the forwarding load of the target forwarding core.
[0082] Secondly, if the number of messages is greater than the first preset value, then select an unexecuted service from the remaining services other than the preset services in the transferable services and schedule it to the distribution core;
[0083] In this embodiment, the first preset value can be set according to the actual needs of the scenario. One implementation method is to set a flag for each service to indicate whether the service is executed, and when selecting, select the unexecuted service for scheduling based on the flag.
[0084] It should be noted that when selecting unexecuted services, you can select one unexecuted service at a time to perform fine-grained dynamic scheduling according to the service and control the scheduling accuracy, or you can select multiple unexecuted services at a time to reduce the impact of frequent scheduling on scheduling performance.
[0085] Third, repeat the step of obtaining the number of packets in the software queue corresponding to the target forwarding core until there are no unexecuted services in the transferable services or the number of packets is not greater than the first preset value.
[0086] In this embodiment, after scheduling an unexecuted service in the above steps, the number of packets in the software queue corresponding to the target forwarding core is repeatedly obtained, and it is determined again whether the number of packets obtained at this time is greater than the first preset value. If so, an unexecuted service is selected from the remaining services other than the preset service in the transferable services and scheduled to the distribution core. If not, the number of packets in the software queue corresponding to the target forwarding core is not repeatedly obtained. At this time, at least two situations are included: (1) the number of packets is not greater than the first preset value and there are unexecuted services in the transferable services; (2) the number of packets is not greater than the first preset value and there are no unexecuted services in the transferable services. For the first situation, the unexecuted service in the transferable services needs to be executed by the target forwarding core. Therefore, after this step, the following is also included:
[0087] If the number of packets is not greater than the first preset value and there are unexecuted services among the transferable services, then the unexecuted services among the transferable services will be scheduled to the target forwarding core.
[0088] In this embodiment, to ensure that the target forwarding core can promptly share the load of the traffic splitting core when the load on the traffic splitting core is high and the load on the target forwarding core is relatively low, thus preventing the load on the traffic splitting core from becoming excessive and achieving a relative balance between the loads of the traffic splitting core and the target forwarding core, this embodiment also provides a scheduling method:
[0089] If the number of packets is less than the second preset value, the services that have not yet been executed in the distribution core will be rescheduled to the target forwarding core for execution.
[0090] In this embodiment, the second preset value can be set according to the actual scenario. If the number of packets is too small, it means that the target forwarding core has a relatively small load, which can share the execution of services that have not yet been executed in the diversion core, so as to achieve load balancing between the diversion core and the target forwarding core and fully utilize the processing capabilities of the diversion core and the target forwarding core.
[0091] In this embodiment, for typical application scenarios, the services that need to be processed before packet forwarding are relatively fixed. In order to achieve more reasonable service scheduling for typical application scenarios, this embodiment also provides another implementation method to schedule the services that need to be executed before the packet to be forwarded to the splitting core and the target forwarding core for execution:
[0092] First, obtain the list of traffic splitting core services and the list of forwarding core services that are predetermined according to the application scenario;
[0093] In this embodiment, services in the traffic splitting core service list are executed by the traffic splitting core, and services in the forwarding core service list are executed by the forwarding core. One implementation method is as follows: First, determine the services in the traffic splitting core service list and the services in the forwarding core service list for typical application scenarios through experiments; second, pre-store the typical application scenarios and the corresponding mapping relationship between the traffic splitting core service list and the forwarding core service list; finally, based on the actual network scenario configuration and the pre-stored mapping relationship, match the traffic splitting core service list and the forwarding core service list suitable for the current network scenario to maximize the rationality of service allocation and thus maximize forwarding performance.
[0094] Secondly, the services that need to be executed before forwarding the packets in the traffic splitter's service list are scheduled to be executed in the traffic splitter, and the services that need to be executed before forwarding the packets in the forwarding core's service list are scheduled to be executed in the target forwarding core.
[0095] It should be noted that, in addition to real-time dynamic scheduling based on packet count and static scheduling based on the service lists of the distribution cores and forwarding cores determined by the application scenario, users can also specify the services to be executed by the distribution cores and the services to be executed by the forwarding cores via commands. User-specified scheduling can also be used in conjunction with the dynamic and static scheduling methods mentioned above, with the user-specified method having the highest priority. For example, based on the actual services configured by the user, commands can be used to specify several services to be assigned to the forwarding cores for processing. Alternatively, pending services from the distribution cores can be reassigned to the forwarding cores, ultimately retaining the service allocation combination with the highest actual forwarding performance.
[0096] In this embodiment, based on the service allocation method of the above embodiments, another method for dynamically adjusting services is also provided. This method is applied to the control core of a forwarding device with a multi-core CPU. Please refer to [link / reference]. Figure 5 , Figure 5 This is a flowchart illustrating a message forwarding method applied to a control kernel provided in an embodiment of the present invention. The method includes the following steps:
[0097] Step S201: Obtain the number of packets that each forwarding core needs to forward. The packets are allocated to the forwarding cores by the diversion cores according to the method described above in this embodiment.
[0098] In this embodiment, each forwarding core corresponds to a software queue, and the number of packets that each forwarding core needs to forward is the number of packets in its software queue.
[0099] Step S202: Based on the number of packets in each forwarding core, the pending services of each forwarding core are reallocated. The pending services of each forwarding core include transferable services that need to be executed before each forwarding core forwards packets and have not yet been executed, without changing the length and content of the packets.
[0100] In this embodiment, the transferable services have been described in the previous embodiments and will not be repeated here.
[0101] In an optional implementation, the method for reallocating the pending services of each forwarding core based on the number of packets per forwarding core is the same. Taking any forwarding core to be adjusted as an example, its reallocation method can be:
[0102] If the number of packets to be forwarded by the forwarding core to be adjusted is greater than the third preset value, then the services to be allocated are determined from the services to be executed by the forwarding core to be adjusted and the services to be allocated are assigned to the distribution core for execution.
[0103] If the number of packets to be forwarded by the forwarding core to be adjusted is less than the fourth preset value, then the service to be allocated is determined from the pending services of the diversion core, and the service to be allocated is assigned to the forwarding core to be adjusted for execution. The packets to be allocated are the ones that need to be forwarded by the forwarding core to be adjusted.
[0104] In this embodiment, there can be one or more services to be assigned. The third preset value can be the same as the first preset value, and the fourth preset value can be the same as the second preset value.
[0105] It should be noted that a separate thread can be created in the control kernel to execute the methods applied to the control kernel, in order to minimize the impact on other normal business processes of the control kernel.
[0106] To perform the corresponding steps in the above embodiments and various possible implementations, an implementation of a packet forwarding device for a multi-core CPU's traffic-sharing core applied to forwarding device 10 is given below. Please refer to... Figure 6 , Figure 6 A block diagram of a packet forwarding device 100 applied to a traffic splitting core according to an embodiment of the present invention is shown. It should be noted that the basic principle and technical effects of the packet forwarding device 100 applied to a traffic splitting core provided in this embodiment are the same as those in the above embodiments. For the sake of brevity, some of these aspects are not mentioned in this embodiment.
[0107] The packet forwarding device 100 of the splitting core includes a packet acquisition module 110, a determination module 120, and a scheduling module 130.
[0108] The message acquisition module 110 is used to acquire messages to be forwarded from the hardware queue, wherein the hardware queue is associated with the port of the forwarding device that receives messages;
[0109] The determination module 120 is used to determine the target forwarding core for forwarding the packet to be forwarded from among multiple forwarding cores;
[0110] The scheduling module 130 is used to schedule the services that need to be executed before the forwarded message is forwarded to the distribution core and the target forwarding core for execution, and the target forwarding core forwards the message to be forwarded.
[0111] In an optional implementation, the services that need to be performed before the forwarded message is forwarded include transferable services that do not change the length and content of the message to be forwarded and non-transferable services that change the length and content of the message to be forwarded. The scheduling module 130 is specifically used to: schedule non-transferable services to the target forwarding core for execution; and schedule transferable services to the distribution core and the target forwarding core for execution.
[0112] In an optional implementation, each forwarding core corresponds to a software queue. When scheduling the transferable services to the distribution core and the target forwarding core for execution, the scheduling module 130 is specifically used to: schedule a preset service among the transferable services to the distribution core for execution; obtain the number of packets in the software queue corresponding to the target forwarding core; if the number of packets is greater than a first preset value, select an unexecuted service from the remaining services other than the preset service among the transferable services and schedule it to the distribution core; repeat the step of obtaining the number of packets in the software queue corresponding to the target forwarding core until there are no unexecuted services among the transferable services or the number of packets is not greater than the first preset value; if the number of packets is not greater than the first preset value and there are unexecuted services among the transferable services, schedule the unexecuted services among the transferable services to the target forwarding core.
[0113] In an optional implementation, the scheduling module 130 is further configured to: if the number of packets is less than a second preset value, reschedule the services that have not yet been executed in the distribution core to the target forwarding core for execution.
[0114] In an optional implementation, when scheduling the services that need to be executed before forwarding a packet to be forwarded are scheduled to be executed by the splitter core and the target forwarding core, the scheduling module 130 is specifically used to: obtain a splitter core service list and a forwarding core service list that are predetermined according to the application scenario; schedule the services that need to be executed before forwarding a packet to be forwarded that exist in the splitter core service list to be executed by the splitter core, and schedule the services that need to be executed before forwarding a packet to be forwarded that exist in the forwarding core service list to be executed by the target forwarding core.
[0115] To perform the corresponding steps in the above embodiments and various possible implementations, an implementation of a message forwarding device 200 applied to a control core is given below. Please refer to... Figure 7 , Figure 7A block diagram of a packet forwarding device 200 applied to a control core according to an embodiment of the present invention is shown. It should be noted that the basic principle and technical effects of the packet forwarding device 200 applied to a control core provided in this embodiment are the same as those in the above embodiments; however, for the sake of brevity, some details are not mentioned in this embodiment.
[0116] The message forwarding device 200 applied to the control core includes a message count acquisition module 210 and an allocation module 220.
[0117] The packet count acquisition module 210 is used to acquire the number of packets that each forwarding core needs to forward. The packets are allocated to the forwarding core by the diversion core according to any of the methods in the aforementioned embodiments.
[0118] The allocation module 220 is used to reallocate the pending services of each forwarding core according to the number of packets of each forwarding core. The pending services of each forwarding core include transferable services that need to be executed before each forwarding core forwards packets and have not yet been executed, without changing the length and content of the packets.
[0119] In an optional implementation, the allocation module 220 is specifically used to: for any forwarding core to be adjusted, if the number of packets to be forwarded by the forwarding core to be adjusted is greater than a third preset value, then determine the service to be allocated from the pending services of the forwarding core to be adjusted and allocate the service to be allocated to the distribution core for execution; if the number of packets to be forwarded by the forwarding core to be adjusted is less than a fourth preset value, then determine the service to be allocated from the pending services of the distribution core and allocate the service to be allocated to the forwarding core to be adjusted for execution, and the packets to which the service to be allocated belongs are those that need to be forwarded by the forwarding core to be adjusted.
[0120] This invention provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a traffic splitter, it implements the packet forwarding method applied to the traffic splitter as described in the foregoing embodiments. When the computer program is executed by a control core, it implements the packet forwarding method applied to the control core as described in the foregoing embodiments.
[0121] In summary, the embodiments of the present invention provide a message forwarding method, apparatus, forwarding device, and storage medium. The method applied to the flow splitting core of a forwarding device with a multi-core CPU includes: obtaining a message to be forwarded from a hardware queue, wherein the hardware queue is associated with the port of the forwarding device that receives messages; determining a target forwarding core from multiple forwarding cores for forwarding the message to be forwarded; scheduling the services that need to be executed before the message to be forwarded is forwarded to the flow splitting core and the target forwarding core for execution, and having the target forwarding core forward the message to be forwarded. Compared with the prior art, the embodiments of the present invention have at least the following advantages: (1) Using the flow splitting core to classify messages ensures that messages of the same flow are assigned to the same forwarding core for forwarding, ensuring that messages are forwarded in order of flow; this embodiment can improve the performance of the network device in forwarding messages; (2) By scheduling the services that need to be executed before the message to be forwarded is forwarded to the flow splitting core and the target forwarding core for execution, the advantages of the multi-core CPU can be fully utilized, ultimately improving the performance of the network device in forwarding messages; (3) This embodiment provides both dynamic scheduling and static scheduling methods, scheduling services to the flow splitting core and the target forwarding core for execution, which can adapt to the needs of different application scenarios.
[0122] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A message forwarding method, characterized in that, A traffic splitting core applied to a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes multiple forwarding cores, the method comprising: Obtain a packet to be forwarded from a hardware queue, wherein the hardware queue is associated with the port where the forwarding device receives packets; A target forwarding core for forwarding the packet to be forwarded is determined from the plurality of forwarding cores, and each forwarding core corresponds to a software queue; The services that need to be executed before the packet to be forwarded are scheduled to be executed by the distribution core and the target forwarding core, and the packet to be forwarded is forwarded by the target forwarding core; If the services that need to be performed before the forwarded message includes transferable services that do not change the length and content of the forwarded message, then the step of scheduling the services that need to be performed before the forwarded message to be executed to the distribution core and the target forwarding core includes: The preset services in the transferable services are scheduled to be executed by the distribution core; Obtain the number of packets in the software queue corresponding to the target forwarding core; If the number of messages is greater than the first preset value, then select an unexecuted service from the remaining services other than the preset service in the transferable services and schedule it to the distribution core; Repeat the step of obtaining the number of packets in the software queue corresponding to the target forwarding core until there are no unexecuted services in the transferable services or the number of packets is not greater than the first preset value; If the number of packets is not greater than the first preset value and there are unexecuted services among the transferable services, then the unexecuted services among the transferable services will be scheduled to the target forwarding core.
2. The message forwarding method as described in claim 1, characterized in that, The services that need to be performed before forwarding the message to be forwarded also include non-transferable services that change the length and content of the message to be forwarded. The step of scheduling the services that need to be performed before forwarding the message to be forwarded to the splitting core and the target forwarding core for execution also includes: The non-transferable service is scheduled to be executed by the target forwarding core.
3. The message forwarding method as described in claim 1, characterized in that, The method further includes: If the number of packets is less than the second preset value, the services that have not yet been executed in the diversion core will be rescheduled to the target forwarding core for execution.
4. The message forwarding method as described in claim 1, characterized in that, The step of scheduling the services that need to be performed before forwarding the message to be forwarded to the distribution core and the target forwarding core for execution further includes: Obtain the list of traffic splitting core services and the list of forwarding core services that are predetermined based on the application scenario; The services that need to be executed before forwarding the packets that exist in the service list of the distribution core are scheduled to be executed by the distribution core, and the services that need to be executed before forwarding the packets that exist in the service list of the forwarding core are scheduled to be executed by the target forwarding core.
5. A message forwarding method, characterized in that, A control core applied to a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes a traffic splitting core and multiple forwarding cores, the method comprising: Obtain the number of packets that each forwarding core needs to forward, wherein the packets are allocated to the forwarding core by the diversion core according to any one of claims 1-4; Based on the number of packets in each forwarding core, the pending services of each forwarding core are reallocated. The pending services of each forwarding core include transferable services that need to be executed before each forwarding core forwards packets and have not yet been executed, without changing the length and content of the packets. The step of reallocating the pending services of each forwarding core based on the number of packets in each forwarding core includes: For any forwarding core to be adjusted, if the number of packets to be forwarded by the forwarding core to be adjusted is greater than a third preset value, then the service to be allocated is determined from the services to be executed by the forwarding core to be adjusted and the service to be allocated is allocated to the distribution core for execution. If the number of packets to be forwarded by the forwarding core to be adjusted is less than the fourth preset value, then the service to be allocated is determined from the pending services of the diversion core, and the service to be allocated is assigned to the forwarding core to be adjusted for execution. The packets to which the service to be allocated belongs need to be forwarded by the forwarding core to be adjusted.
6. A message forwarding device, characterized in that, A traffic splitting core applied to a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes multiple forwarding cores, the device comprising: The message acquisition module is used to acquire messages to be forwarded from a hardware queue, wherein the hardware queue is associated with the port of the forwarding device that receives messages; A determining module is used to determine, from the plurality of forwarding cores, a target forwarding core for forwarding the packet to be forwarded, wherein each forwarding core corresponds to a software queue; The scheduling module is used to schedule the services that need to be executed before the forwarded message is forwarded to the distribution core and the target forwarding core for execution, and the target forwarding core forwards the message to be forwarded. The services that need to be executed before the forwarded message is forwarded include transferable services that do not change the length and content of the message to be forwarded. If the services that need to be executed before the forwarded message includes transferable services that do not change the length and content of the forwarded message, then the scheduling module is specifically used to: schedule a preset service in the transferable services to the distribution core for execution; obtain the number of messages in the software queue corresponding to the target forwarding core; if the number of messages is greater than a first preset value, select an unexecuted service from the remaining services in the transferable services other than the preset service and schedule it to the distribution core; repeat the step of obtaining the number of messages in the software queue corresponding to the target forwarding core until there are no unexecuted services in the transferable services or the number of messages is not greater than the first preset value; if the number of messages is not greater than the first preset value and there are unexecuted services in the transferable services, schedule the unexecuted services in the transferable services to the target forwarding core.
7. A message forwarding device, characterized in that, A control core for a forwarding device with a multi-core CPU, wherein the multi-core CPU further includes a traffic splitting core and multiple forwarding cores, the device comprising: The packet count acquisition module is used to acquire the number of packets that each forwarding core needs to forward, wherein the packets are allocated to the forwarding core by the diversion core according to the method of any one of claims 1-4; The allocation module is used to reallocate the pending services of each forwarding core according to the number of packets of each forwarding core. The pending services of each forwarding core include transferable services that need to be executed before each forwarding core forwards packets and have not yet been executed, without changing the length and content of the packets. The allocation module is specifically used for: for any forwarding core to be adjusted, if the number of packets to be forwarded by the forwarding core to be adjusted is greater than a third preset value, then determining the service to be allocated from the pending services of the forwarding core to be adjusted and allocating the service to be allocated to the distribution core for execution; if the number of packets to be forwarded by the forwarding core to be adjusted is less than a fourth preset value, then determining the service to be allocated from the pending services of the distribution core and allocating the service to be allocated to the forwarding core to be adjusted for execution, wherein the packets to which the service to be allocated belongs are those that need to be forwarded by the forwarding core to be adjusted.
8. A relay device, characterized in that, The device includes a multi-core CPU and a memory. The multi-core CPU includes a traffic splitting core, multiple forwarding cores, and a control core. The memory is used to store a program. The traffic splitting core is used to implement the packet forwarding method of any one of claims 1-4 when executing the program. The control core is used to implement the packet forwarding method of claim 5 when executing the program.
9. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by the distribution core, implements the message forwarding method as described in any one of claims 1-4, and when executed by the control core, implements the message forwarding method as described in claim 5.