A method and apparatus for packet forwarding
By introducing a hash table management mechanism in the router and clearing the hardware acceleration table entries, the data stream is re-entered onto the protocol stack for DSCP marking, which solves the problem of data streams not being able to be marked under hardware acceleration, realizes priority forwarding of data packets, and improves the user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2024-05-17
- Publication Date
- 2026-05-01
AI Technical Summary
When the router supports hardware acceleration, data streams that have entered the hardware acceleration process cannot be marked with DSCP, which prevents packet priority adjustment and affects user experience.
By introducing a hash table management mechanism in the router, entries of 5-tuple information that have entered the hardware acceleration are cleared, allowing them to be re-entered onto the protocol stack for DSCP marking.
DSCP marking is implemented for data streams that have entered hardware acceleration, ensuring that packets are forwarded according to priority and improving the user experience.
Smart Images

Figure CN121012777B_ABST
Abstract
Description
A method and apparatus for message forwarding Technical Field
[0001] This application relates to the field of communication technology, and more specifically, to a method and apparatus for message forwarding. Background Technology
[0002] Differentiated Services Code Point (DSCP) technology is now widely used in packet forwarding scenarios. DSCP is a technology used to identify and differentiate fields in different types of data streams. Based on DSCP, packet headers can be marked with DSCP values, or assigned different DSCP values. Different DSCP values correspond to different transmission priorities. For example, when sending packets, a router's Wi-Fi driver uses the packet's DSCP value to place packets into different priority transmission queues, thus prioritizing the transmission of high-priority packets (e.g., in scenarios requiring priority transmission, such as gaming and video streaming).
[0003] In addition, current routers also support "hardware acceleration," meaning that after the first few data packets arrive at the protocol stack, the router's hardware acceleration module learns the forwarding path of this data stream. Subsequent data packets are then forwarded directly through the hardware acceleration module, bypassing the network card driver and protocol stack. However, this "hardware acceleration" mechanism can affect the DSCP flag, making it impossible to detect packets that require modification of the DSCP value. Summary of the Invention
[0004] In view of this, this application provides a method, apparatus, computer-readable storage medium, and computer program product for message forwarding, which, for data streams that have entered hardware acceleration, clears hardware acceleration entries so that subsequent data packets of the data stream can be reprocessed on the protocol stack, thereby achieving the purpose of DSCP marking.
[0005] Firstly, a method for message forwarding is provided, the method being applied to a data forwarding device, wherein hardware acceleration is supported in the data forwarding; the method includes:
[0006] First, the data forwarding device receives a first message from the terminal device. The first message includes one or more of the following parameters: message type parameter, number of quintuples, and n quintuples; where n is an integer greater than or equal to 1. Then, the hash table is managed according to the message type of the first message. The management operation includes at least adding the n quintuples. Next, if the n quintuples have been added to the hash table, it is determined whether the data stream corresponding to the k-th quintuple has entered hard acceleration. The k-th quintuple is one of the n quintuples. Then, if the data stream corresponding to the k-th quintuple has already entered hard acceleration, the hard acceleration entry corresponding to the k-th quintuple is deleted. Finally, a DSCP marking process is performed on the acquired packets to be forwarded. The packets to be forwarded include at least the packets corresponding to the k-th quintuple.
[0007] Compared to related technologies' DSCP tagging schemes that do not consider hardware acceleration, this application's embodiment clears the hardware acceleration entry for the k-th quintuple information in a data stream that has already entered hardware acceleration, enabling the data stream corresponding to the k-th quintuple information to re-enter the protocol stack. This allows the DSCP tagging process to be performed on data packets processed at the protocol stack, thus solving the problem that data streams already in hardware acceleration cannot be tagged with DSCP.
[0008] For example, the data forwarding device described above can be a router. A Wi-Fi connection is established between the router and the terminal device.
[0009] It can be understood that n can be 1 or an integer greater than 1. When n is 1, the first message includes a single 5-tuple, and the k-th 5-tuple mentioned above is that 5-tuple. When n is an integer greater than 1, the first message includes multiple 5-tuples, and the k-th 5-tuple mentioned above is one of those multiple 5-tuples. For the case of multiple 5-tuples, the router can process each 5-tuple sequentially, following the same processing method used for the k-th 5-tuple.
[0010] For example, the management of hash tables includes, but is not limited to: adding quintuple information to the hash table; deleting quintuple information from the hash table; and updating the relevant information of the entries recorded in the hash table (e.g., quintuple entries or triplet entries) (e.g., status parameters, which characterize whether the entry is marked with DSCP; time parameters, which characterize the last active time of the entry, etc.).
[0011] To reduce complexity, a hash bucket is introduced to manage the 5-tuple information reported by the terminal device. A hash bucket is a data structure used to implement a hash table. The hash bucket uses a hash function to map keys to indices within the bucket, enabling data storage and access.
[0012] Optionally, the hash table described above uses a hash bucket, where the hash key of the hash bucket is a triplet; wherein, the upper limit of the hash index of the hash bucket is half of the maximum number of table entries that the data forwarding device can manage (e.g., maxnum).
[0013] It should be noted that the more entries a router manages, the more memory it consumes, and the lower the efficiency of searching for entries becomes. Therefore, in this embodiment, the array length of the hash bucket is designed to be maxnum / 2. This design balances memory consumption and the time complexity of searching for entries.
[0014] It should be understood that the specific operations for hash table management can depend on the type of the first message.
[0015] Optionally, if the first message is a batch-added message, for example, if the message type parameter included in the first message indicates that the first message is a batch-added message, then the n quintuple information included in the first message is added to the hash table.
[0016] Optionally, if the first message is a batch deletion message, for example, if the message type parameter included in the first message indicates that the first message is a batch deletion message, then the n quintuple information included in the first message can be deleted from the hash table.
[0017] Optionally, if the first message is a deletion message that performs batch clearing of terminal IP, for example, if the message type included in the first message indicates that the first message is to delete 5-tuple information based on terminal IP as a filtering factor, then in the hash table, the 5-tuple information that meets the conditions (for example, the terminal IP corresponding to the 5-tuple information is the terminal IP indicated by the message type field of the first message) is deleted in batch.
[0018] In some possible implementations, the method further includes: using the k-th quintuple information to perform a match in the hash table; if no entry corresponding to the k-th quintuple information is found in the hash table, adding an entry corresponding to the k-th quintuple information to the hash table, and determining whether the data stream corresponding to the k-th quintuple information enters the hardware acceleration.
[0019] In some possible implementations, determining whether the data stream corresponding to the k-th quintuple information enters the hardware acceleration also includes:
[0020] If an entry corresponding to the kth quintuple information is matched in the hash table, it is determined whether the first entry has been marked with DSCP based on the state parameter of the first entry. The first entry corresponds to the kth quintuple information (or the first entry is the entry matched by the kth quintuple information in the hash table).
[0021] If the state parameter of the first entry indicates that no DSCP marking has been performed on the first entry, determine whether the data stream corresponding to the k-th quintuple information has entered the hard acceleration.
[0022] Optionally, if an entry corresponding to the k-th quintuple information is found in the hash table, the method further includes:
[0023] Update the time parameter corresponding to the first entry to the current time. The time parameter is used to characterize the active time of the first entry.
[0024] In other words, the 5-tuple information requested by the terminal device may be newly added or already added. Upon receiving the 5-tuple information from the terminal device, a match is first made in the hash table. If no matching entry is found, it means the 5-tuple information is indeed needed; if no matching entry is found, it means the 5-tuple information has already been added to the hash table, and this request is a duplicate. For 5-tuple information that is indeed needed, node memory can be allocated to store it in the hash table. For 5-tuple information already added to the hash table, the corresponding time parameter in the hash table can be updated, that is, the time represented by the time parameter is updated to the current time. Furthermore, for 5-tuple information already added to the hash table, its status parameter can be further checked to determine whether a DSCP marker has been performed on the corresponding entry (e.g., the first entry).
[0025] In practice, terminal devices may repeatedly send 5-tuple information, for example, sending the same 5-tuple information every second. Therefore, before clearing hardware acceleration table entries, it's necessary to determine whether clearing is truly necessary. Clearing the acceleration table entry corresponding to the 5-tuple information and feeding subsequent data streams to the protocol stack for processing will inevitably consume CPU resources. Therefore, clearing hardware acceleration table entries should only be done when it's confirmed that DSCP marking is indeed required, thus reducing CPU resource consumption.
[0026] The embodiments of this application do not limit the specific method of matching the k-th quintuple information in the hash table.
[0027] Optionally, as a possible implementation, matching in the hash table using the kth quintuple information includes: calculating a first hash index based on the triple information in the kth quintuple information; using the first hash index, searching for the linked list corresponding to the first hash index in the hash table, and matching the triple information in the linked list.
[0028] Therefore, when the hash table stores triplet information, the first hash index is calculated using the triplet information in the kth quintet information, so that the first hash index can be used for searching, which helps to improve search efficiency.
[0029] This application implements a five-tuple hash bucket management mechanism in the Linux kernel, using triples as hash keys and a hash length of up to half the number of manageable records. This achieves good lookup efficiency while also taking into account memory overhead.
[0030] The router includes a packet processing module. When the upper-layer protocol stack has a packet to be forwarded (e.g., a downlink packet), the packet processing module is triggered to perform an entry matching operation. When the packet processing module matches the corresponding triple information in the hash table, it modifies the DSCP value.
[0031] In some possible implementations, the DSCP marking process is performed on the acquired packet to be forwarded, including: obtaining the packet to be forwarded through a forwarding link hook function; determining whether the packet to be forwarded is a packet to be accelerated based on the triple information corresponding to the packet to be forwarded; if the packet to be forwarded is a packet to be accelerated, determining whether the DSCP value of the packet to be forwarded is a first value (for example, the first value is 0x111); if the DSCP value of the packet to be forwarded is not the first value, modifying the DSCP value of the packet to be forwarded to the first value.
[0032] It should be noted that the embodiments of this application apply to data packets forwarded by routers, not data packets whose source or destination address is the router itself. For example, the router's web front-end and back-end interactions belong to LAN to local machine (i.e., the router itself); the router's interaction with a time synchronization server belongs to WAN to local machine. These scenarios do not involve forwarding chain processing. For such packets, the solutions in related technologies are still used, and this application will not affect the performance of these solutions. In other words, only data packets that enter the system from one interface and leave the system from another interface will reach the callback function (ftca_mark_skb) registered by the hook of the aforementioned protocol stack forward chain.
[0033] Optionally, in some possible implementations, determining whether the packet to be forwarded is a packet to be accelerated based on the triple information corresponding to the packet to be forwarded includes: calculating a second hash index based on the triple information corresponding to the packet to be forwarded; using the second hash index, searching for the linked list corresponding to the second hash index in the hash table, and matching in the linked list corresponding to the second hash index; if a second entry is matched in the linked list corresponding to the second hash index, determining that the packet to be forwarded is a packet to be accelerated.
[0034] For example, if a packet to be forwarded is captured that matches the 5-tuple information requested by the terminal device for acceleration, the packet to be forwarded can be considered a packet that needs acceleration. Therefore, a DSCP marking process can be performed on the packet that needs acceleration based on subsequent procedures.
[0035] It should be understood that the process of calculating the hash index using the triple information corresponding to the message to be forwarded and matching it in the hash table is similar to that described above, and will not be repeated here.
[0036] The aforementioned message to be forwarded could be a TCP message or a UDP message. For TCP messages, it is important to check whether the TCP message carries the rst flag or the fin flag.
[0037] Optionally, in some possible implementations, the packet to be forwarded is a TCP packet; the DSCP value of the packet to be forwarded is a first value; the method further includes: determining whether to terminate the connection based on a first flag bit (which may correspond to an end flag bit in the embodiment), the first flag bit being determined based on a second flag bit carried by the TCP packet, the second flag bit being used to indicate whether to reset (rest) or finish (finish) the connection corresponding to the packet to be forwarded; if the connection is determined to be terminated based on the first flag bit, the status parameter corresponding to the second entry is not modified, the status parameter corresponding to the second entry is a second value, the second value indicating that the connection corresponding to the packet to be forwarded has been terminated; if the connection is determined not to be terminated based on the first flag bit, the status parameter corresponding to the second entry is modified to a third value, the third value indicating that the DSCP marking process has been performed.
[0038] For example, if it is a TCP packet and carries the rst flag or fin flag, the status parameters of the five-tuple information of the data stream are not updated. For example, the status parameter is not updated to 1 (representing that it has been marked with DSCP). The purpose of this is to prevent the node from not being deleted during aging detection.
[0039] In some possible implementations, before determining whether the packet to be forwarded is a packet to be accelerated based on the triple information corresponding to the packet to be forwarded, the method further includes: determining whether the packet to be forwarded is a downlink packet; if the packet to be forwarded is a downlink packet, determining the type of the downlink packet; and determining the triple information corresponding to the packet to be forwarded based on the type of the downlink packet. It should be noted that only downlink packets can be packets sent to terminals connected to the router via a Wi-Fi connection; therefore, only downlink packets are considered here. This avoids consuming unnecessary performance, helps save power, and thus achieves processing of non-downlink packets without increasing the load.
[0040] To avoid the consumption of router memory by obsolete 5-tuple acceleration entries, it is necessary to delete the entry information (e.g., 5-tuple entries or 3-tuple entries) in the hash table managed by the router in this embodiment of the application. However, in related technologies, frequent interaction between the terminal and the router is required to implement the mechanism for deleting 5-tuple acceleration entries. Based on this, this embodiment of the application also provides an automatic aging mechanism that does not rely on terminal devices, that is, the router promptly identifies invalid entry information (e.g., 5-tuple entries or 3-tuple entries) and deletes the obsolete entries from the hash table.
[0041] Optionally, in some possible implementations, the method further includes: deleting obsolete entries in the hash table based on an aging mechanism; and sending an aging message to the terminal device.
[0042] Optionally, in some possible implementations, a connection tracking event is obtained based on the connection tracking mechanism; if the connection tracking event is a destruction event, the five-tuple information corresponding to the destruction event is obtained; a match is performed in the hash table based on the five-tuple information corresponding to the destruction event; a third entry is matched in the hash table; if the third entry meets the deletion condition, the third entry is deleted from the hash table, and an aging message is sent to the terminal device, the aging message including the five-tuple information corresponding to the third entry.
[0043] For example, in the following application scenario, when a terminal device abnormally disconnects from the router and fails to send a deletion message, the router can automatically delete obsolete entries using the connection tracking-based aging detection method described above. Furthermore, for routers supporting hardware acceleration, if the router cannot determine whether the data stream undergoing hardware acceleration has ended (or disconnected) after the terminal device abnormally disconnects, the connection tracking-based aging detection method can also solve the problem of not being able to detect subsequent marking of data streams after they enter hardware acceleration, promptly identifying and deleting invalid entries (such as 5-tuple or 3-tuple information).
[0044] This application does not limit the specific method by which the router tracks and destroys events. For example, the router kernel has a built-in connection tracking (conntrack) mechanism, which can track and record the status of connections (e.g., TCP or UDP connections). Therefore, the connection tracking mechanism can obtain connection tracking events in real time, such as new connection creation, connection updates, or connection destruction. For aging detection, this application focuses on connection destruction events, which can be simply referred to as destruction events.
[0045] Optionally, the message format for aging messages can adopt the aforementioned overall message structure ftca_flowctl; the message type can be MSG_FLOW_TIMEOUT.
[0046] Optionally, the aging message may include one or more aging entries (i.e., discarded entries).
[0047] It's understandable that in practical applications, there might be more aging items than the preset number. In this case, an aging message can be pushed first, including the maximum number of aging items that can be handled. Then, another aging check is immediately performed until all nodes in the hash table have been traversed, completing the deletion of obsolete entries.
[0048] Optionally, in some possible implementations, the third entry satisfies the deletion conditions, including: the time interval between the time parameter corresponding to the third entry and the current time is greater than a first preset duration; the status parameter corresponding to the third entry takes the value of a second value or a fourth value, where the second value indicates the termination of the connection corresponding to the current message, and the fourth value indicates that the hash node was not marked with DSCP after its establishment.
[0049] For example, the destruction events include: timeout destruction events and TCP data stream termination destruction events; and instruction destruction events. A timeout destruction event can be understood as a connection tracking destruction event triggered if there is no data interaction for a certain entry within a certain period. A TCP data stream termination destruction event can be understood as a destruction event caused by the termination of the TCP data stream. An instruction destruction event can be understood as the existence of a deletion instruction in the router; a deletion instruction can trigger the deletion of connection tracking.
[0050] Therefore, the router implements an automatic aging mechanism that does not rely on terminal devices for persistence. Compared to related technologies that require frequent interaction between terminal devices and the router to delete obsolete entries, the automatic aging mechanism of this application embodiment can effectively delete obsolete entries (or zombie entries) without frequent interaction between the router and the terminal devices, thus reducing the memory usage of obsolete entries.
[0051] Optionally, an aging timer can be created during the initialization process to implement aging detection. In some implementations, aging detection is achieved by periodically triggering the aging timer's callback function.
[0052] Secondly, a method for message forwarding is provided, the method being applied to a data forwarding device that supports hardware acceleration; the method includes:
[0053] Based on the connection tracking mechanism, obtain connection tracking events;
[0054] If the connection tracking event is a destruction event, obtain the quintuple information corresponding to the destruction event;
[0055] Based on the five-tuple information corresponding to the destruction event, a match is performed in the hash table;
[0056] A third entry was matched in the hash table;
[0057] If the third entry meets the deletion condition, the third entry is deleted from the hash table, and an aging message is sent to the terminal device. The aging message includes the quintuple information corresponding to the third entry.
[0058] This application aims to provide an automatic aging mechanism that does not rely on terminal devices. Specifically, the router promptly identifies invalid table entries (e.g., 5-tuple or 3-tuple entries) and deletes them from the hash table. Compared to related technologies that require frequent interaction between the terminal device and the router to delete obsolete entries, the automatic aging mechanism of this application allows the router to delete obsolete entries (or zombie entries) without frequent interaction with the terminal device, effectively reducing the memory footprint of obsolete entries.
[0059] For various implementations of the automatic aging mechanism that does not rely on terminal devices provided in the embodiments of this application, please refer to the description in the first aspect above. The technical effects of each implementation can also be referred to the description in the first aspect. For the sake of brevity, they will not be repeated here.
[0060] It should be understood that the router's automatic aging mechanism for deleting obsolete entries (which does not rely on the terminal device for keep-alive) can be applied not only to the hash table mentioned in the first aspect above, but also to hash tables in related technologies. This application embodiment does not specifically limit this.
[0061] Optionally, in some possible implementations, the third entry satisfies the deletion conditions, including: the time interval between the time parameter corresponding to the third entry and the current time is greater than a first preset duration; the status parameter corresponding to the third entry takes the value of a second value or a fourth value, where the second value indicates the termination of the connection corresponding to the current message, and the fourth value indicates that the hash node was not marked with DSCP after its establishment.
[0062] Optionally, in some possible implementations, the destruction event includes: a timeout destruction event, a TCP data stream termination destruction event, and an instruction destruction event.
[0063] Thirdly, an apparatus for message forwarding is provided, including a unit for performing the method in any implementation of the first aspect. The apparatus may be a data forwarding device (such as a router) or a chip within a data forwarding device (such as a chip within a router). The apparatus includes a communication unit and a processing unit.
[0064] When the device is a data forwarding device, the processing unit may be a processor, and the communication unit may be a communication interface; the data forwarding device may also include a memory for storing computer program code, which, when the processor executes the computer program code stored in the memory, causes the electronic device to perform the method in any of the implementations of the first aspect.
[0065] When the device is a chip within a data forwarding device, the processing unit can be an internal logic processing unit of the chip, and the communication unit can be a communication interface, pin, or circuit, etc.; the chip may also include a memory, which can be an internal memory of the chip (e.g., registers, cache, etc.) or an external memory (e.g., read-only memory, random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes the method in either the first aspect or the second aspect.
[0066] Fourthly, a computer-readable storage medium is provided that stores computer program code, which, when run by a device for managing threads, causes the device to perform the method in either the first or second aspect.
[0067] Fifthly, a computer program product is provided, the computer program product comprising: computer program code, which, when run by a device for managing threads, causes the device to perform a method in either the first or second aspect. Attached Figure Description
[0068] Figure 1A is a format example of an IP packet;
[0069] Figure 1B shows an example diagram of a priority queue;
[0070] Figure 2 is a block diagram illustrating an application scenario of an embodiment of this application;
[0071] Figure 3 is a schematic flowchart of a message forwarding method according to an embodiment of this application;
[0072] Figure 4A is a format example diagram of the first message according to an embodiment of this application;
[0073] Figure 4B is a code example diagram of a terminal device obtaining connection information;
[0074] Figure 4C is a schematic diagram of a hash bucket according to an embodiment of this application;
[0075] Figure 5 is an example diagram of a recording result of a hash bucket according to an embodiment of this application;
[0076] Figure 6A is an example flowchart of a hash table management method for batch addition of messages according to an embodiment of this application;
[0077] Figure 6B is another example flowchart of the hash table management method for batch addition of messages according to an embodiment of this application;
[0078] Figure 7A is an example diagram of a mechanism for clearing hard acceleration entries;
[0079] Figure 7B is an example diagram of the contents of a hard acceleration entry;
[0080] Figure 8 is an example flowchart of a hash table management method for batch deletion messages according to an embodiment of this application;
[0081] Figure 9A is a flowchart illustrating an example of a DSCP marking method according to an embodiment of this application;
[0082] Figure 9B is an example flowchart of an application scenario of this application embodiment;
[0083] Figure 9C is a flowchart of a specific example of the DSCP marking process according to an embodiment of this application;
[0084] Figure 10A is a schematic flowchart of a method for deleting obsolete entries in a hash table provided in this application;
[0085] Figure 10B is an example diagram of processing connection tracking events provided in an embodiment of this application;
[0086] Figure 11 is an exemplary flowchart of an aging detection method provided in an embodiment of this application;
[0087] Figure 12 is a schematic block diagram of a message forwarding apparatus 1400 according to an embodiment of this application;
[0088] Figure 13 is a schematic block diagram of a message forwarding apparatus 1500 according to an embodiment of this application. Detailed Implementation
[0089] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0090] The message forwarding method provided in this application can be applied to communication scenarios where DSCP technology is used to differentiate the transmission of data packets (e.g., prioritizing the transmission of certain data packets).
[0091] DSCP tagging assigns different DSCP values to messages, placing them into different priority transmission queues to enable priority-based processing of different types of data streams. In essence, DSCP technology can be used in any scenario during network communication where there is a need to prioritize the transmission of messages or data.
[0092] Taking a data packet (or IP data packet) transmitted based on the IP protocol as an example, the DSCP value can be reflected in the header of the data packet. It should be understood that this application embodiment does not specifically limit the IP packet type; it can support both IPv4 and IPv6 packets. The following description is based on the packet format shown in Figure 1A. Figure 1A shows an example format of an IP data packet. As shown in Figure 1A, an IP data packet consists of a header and a payload. The header length is 20-60 bytes, the last 40 bytes are optional (the length is not fixed and is not shown in the figure), the first 20 bytes have a fixed format, and the length of the payload is variable. As shown in Figure 1A, the first 20 bytes of the IP data packet have a fixed format. The first 20 bytes include the following: Version (4 bits), Header Length (equivalent to the IP header length, 4 bits), Type of Service (8 bits), Total Length (16 bits), Identification (16 bits), Flags (3 bits), Fragment Offset (13 bits), Time to Live (8 bits), Protocol (8 bits, used to identify the protocol used by the upper layer), Header Checksum (16 bits), Source IP Address (32 bits), and Destination IP Address (32 bits). IP packets may also include options fields and data. In Figure 1A above, the DSCP value of the IP packet can be located in the high 6 bits of the TOS field in the IP header.
[0093] Currently, when a data packet arrives at the MAC layer, the data forwarding device can place the data packet into different priority sending queues as specified in protocol 802.1e based on the DSCP value of the data packet, so as to achieve priority sending of high-priority packets.
[0094] Figure 1B shows an example diagram of priority queues. In some embodiments, 802.11e can provide four different priorities, also known as access categories, ordered from highest to lowest: Voice (AC_VO): Generally VoIP traffic type, most sensitive to latency, and also the highest priority traffic. Video (AC_VI): Video traffic has a lower priority than voice service, but higher than the other two. Video service is also a latency-sensitive service, so it has a certain priority. Best-effort (AC_BE): The default wireless traffic type is best-effort, such as web page access data traffic. It has some latency requirements, but is not very sensitive. Background (AC_BK): Traffic with the least latency requirements, such as file transfers and print jobs. The router maps data packets to different priority queues according to the above four priorities and sends the data packets sequentially according to the priority queues through the Wi-Fi physical network card.
[0095] To facilitate understanding of the embodiments of this application, the application scenarios of the embodiments of this application will first be described with reference to the communication system shown in FIG2. FIG2 shows an example block diagram of an application scenario of the embodiments of this application. As shown in FIG2, the communication system includes a data forwarding device, a service server, and one or more terminal devices (e.g., terminal device 1 and terminal device 2). The service server is used to provide service-related services, including but not limited to: games, videos, web browsing, downloads, voice, etc. The data forwarding device is used to provide data forwarding services to the terminal devices.
[0096] Taking terminal device 1 as an example, terminal device 1 transmits data with the service server through a data forwarding device; and / or, terminal device 1 transmits data with terminal device 2 through a data forwarding device. The data forwarding device is used to provide data forwarding services for terminal device 1, including but not limited to: forwarding uplink messages with terminal device 1 as the source device to the service server; and forwarding downlink messages with terminal device 1 as the destination device to terminal device 1.
[0097] For example, game application A is installed on terminal device 1. Terminal device 1 establishes a Wi-Fi connection with the data forwarding device. When the user uses game application A, data between terminal device 1 and the service server can be forwarded through the data forwarding device.
[0098] It is understood that this description only uses the data interaction between terminal device 1 and the business server as an example, and the embodiments of this application are not limited to this. In fact, the data interaction between terminal device 1 and terminal device 2 can also be forwarded through a data forwarding device.
[0099] In some embodiments, the data forwarding device shown in FIG2 can be a network access device. The network access device can be a router device (for ease of description, a router will be used as an example in the following description).
[0100] Optionally, the network access device may also be: an access point (AP) in a Wi-Fi system, an evolved Node B (eNB), a radio network controller (RNC), a Node B (NB), a base station controller (BSC), a base transceiver station (BTS), a home base station (e.g., a home evolved Node B, or a home Node B, HNB), a baseband unit (BBU), a wireless relay node, a wireless backhaul node, a transmission and reception point (TRP or transmission point, TP), etc. It may also be a 5G system, such as a gNB in a new radio (NR) system, or a transmission point (TRP or TP), one or a group of antenna panels (including multiple antenna panels) of a base station in a 5G system, or a network node constituting a gNB or transmission point, such as a baseband unit (BBU) or a distributed unit (DU), etc. For ease of description, the following description will use a router as an example of a data forwarding device.
[0101] In some embodiments, the terminal device shown in FIG2 may be a terminal with transceiver functions or a chip disposed in the terminal. The terminal device may also be referred to as user equipment (UE), user device, access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent, or user device. The terminal devices in the embodiments of this application can be mobile phones, tablets, computers with wireless transceiver capabilities, wireless terminals in industrial control, self-driving, remote medical care, smart grids, transportation safety, smart cities, smart homes, tablets, laptops, wearable devices, multimedia playback devices, e-book readers, personal computers (PCs), personal digital assistants (PDAs), netbooks, augmented reality (AR) devices, virtual reality (VR) devices, smartphones, smart TVs, smart screen devices, smart cameras, portable multimedia players (PMPs), projection devices, mixed reality (MR) devices, televisions, or motion-sensing game consoles in human-computer interaction scenarios, etc. This application does not limit the specific form of the electronic device.
[0102] In current packet forwarding technologies, terminal devices can report five-tuple information that needs to be accelerated to the router. After receiving the five-tuple information reported by the terminal device, the router manages the entries and, upon detecting the downlink packet corresponding to the five-tuple information, modifies the DSCP value in the packet, or in other words, executes DSCP marking, to achieve priority forwarding of the data packet corresponding to the five-tuple information.
[0103] Routers can support "hardware acceleration." Hardware acceleration means that after the first few data packets arrive at the protocol stack, the router's hardware acceleration module learns the packet forwarding path of the data stream. Subsequent data packets will no longer be uploaded to the driver and protocol stack for processing, but will be forwarded directly through the hardware acceleration module (such as a Wi-Fi chip), thus saving CPU processing performance and time, and improving packet forwarding speed.
[0104] It's understandable that a hardware acceleration module can be configured in a router; the "hardware acceleration" mechanism can be implemented through this module. When a router supports the "hardware acceleration" mechanism, it can perform DSCP marking on the first N packets of the data stream. Due to the "hardware acceleration" mechanism, subsequent packets will not be processed by the upper-layer protocol stack and will instead be forwarded directly through the underlying hardware.
[0105] Current DSCP marking schemes do not consider how to optimize the DSCP marking process when routers support "hardware acceleration".
[0106] When a router supports a "hardware acceleration" mechanism, the packet acceleration process suffers from the following problem: subsequent packets that do not reach the protocol stack cannot undergo DSCP tagging. For example, when a terminal device notifies the router that a certain five-tuple information (corresponding to the first data packet) needs acceleration, if in reality the data stream corresponding to that five-tuple information (e.g., the first data packet) has already reached the router, and the router's hardware acceleration mechanism has already run and passed the first N packets before entering hardware acceleration (or the first data packet is not among the first N packets, or the first data packet has already entered hardware acceleration), then it's too late for the terminal device to notify the router that the first data packet needs acceleration. This is because if the first data packet has already entered hardware acceleration, it will not be processed by the protocol stack but will be directly forwarded by the hardware module. Since the first data packet does not reach the protocol stack, the packet processing module in the router cannot modify the DSCP value of the first data packet, thus failing to respond to the terminal device's request to accelerate the first data packet. This directly impacts the user experience, resulting in slow response times and latency, severely affecting the user experience.
[0107] In view of this, the message forwarding method of this application embodiment, upon receiving a user-space message from a terminal device, manages 5-tuple information through a hash table and processes each 5-tuple in the hash table sequentially. Specifically, the processing includes: determining whether the data stream corresponding to the k-th 5-tuple has entered hardware acceleration; if it has, then clearing the corresponding hardware acceleration entry to cause the corresponding data stream to exit hardware acceleration. In this way, messages of subsequent data streams following the k-th 5-tuple can be re-processed on the protocol stack, for example, by marking the messages with DSCP. This approach solves the following problem in the current technology: data streams that have entered hardware acceleration cannot be captured and their DSCP values modified as expected.
[0108] Figure 3 shows a schematic flowchart of a method for message forwarding according to an embodiment of this application. For example, the terminal device shown in Figure 3 can be terminal device 1 shown in Figure 2; the router can be the data forwarding device shown in Figure 2.
[0109] As shown in Figure 3, the router includes a message receiving module, a cooperative acceleration kernel module, and a packet processing module. The message receiving module performs router-related message receiving or sending functions, such as receiving messages from terminal devices or sending messages to terminal devices. The packet processing module can be understood as a hook processing module for the forwarding chain in the router's IP protocol stack. The packet processing module is triggered by packets; that is, it is triggered when there is a packet that needs to be forwarded or processed. For example, when a downlink packet is detected, the packet processing module is triggered to perform matching in order to modify the DSCP value of the downlink packet that needs acceleration.
[0110] The collaborative acceleration kernel module is a module introduced or newly defined in this application, used to implement some or all of the functions in the message forwarding method of the embodiments of this application. The role of the collaborative acceleration module will be described in detail in the subsequent method flow. It is understood that the embodiments of this application do not limit the form of the collaborative acceleration kernel module. The collaborative acceleration kernel module can be a sub-module added to an existing kernel module, or it can be set independently of the existing kernel module. It should be understood that the collaborative acceleration kernel module can also have other names, such as a five-tuple collaborative acceleration (FTCA) module, or simply a kernel module, etc.
[0111] Alternatively, the functionality of the collaborative acceleration kernel module can be implemented using Linux's module mechanism. The Linux module mechanism allows the module to be loaded only when needed. In other words, the functionality of the collaborative acceleration kernel module can be started on demand. This reduces memory consumption.
[0112] For example, when a co-accelerated kernel module loads a module, it can call the function specified by the `module_init` macro in the module mechanism to perform module initialization. When a co-accelerated kernel module unloads a module, it can call the function specified by the `module_exit` macro in the module mechanism to perform module cleanup.
[0113] It is understandable that the `module_init` macro can be used to define the initialization of a co-accelerated kernel module to ensure that the module can perform initialization work when loaded; the `module_exit` macro can be used to define the cleanup function of a co-accelerated kernel module to ensure that the module can perform cleanup work when unloaded.
[0114] Step 500: The terminal device establishes a Wi-Fi connection with the router.
[0115] The embodiments of this application do not describe in detail the specific process of establishing a Wi-Fi connection between the terminal device and the router, as well as the signaling interaction. For details, please refer to relevant technologies.
[0116] Optionally, the router may also include an end-to-end service management module. For example, terminal devices can establish a Wi-Fi connection with the router's end-to-end service management module via an end-to-end protocol.
[0117] It is understandable that terminal devices can send messages to routers, which may include a five-tuple requesting acceleration or a five-tuple requesting cancellation of acceleration.
[0118] Step 501: The terminal device sends a first message to the router. Correspondingly, the router (e.g., the router's message receiving module) receives the first message sent by the terminal device.
[0119] The first message can be understood as a five-tuple message sent by the terminal device to the router. The first message is used by the terminal device to request accelerated five-tuple information from the router, or to request the terminal device to cancel accelerated five-tuple information from the router. Optionally, the first message may include five-tuple information that needs to be accelerated and / or five-tuple information that needs to be canceled.
[0120] Optionally, in some embodiments, the first message includes one or more of the following parameters: message type, number of quintuples (e.g., represented as the flow_num parameter), and quintuple information.
[0121] The message type is used to characterize what type of operation the terminal device requests the router to perform on the five-tuple information. The message type can be represented by the msg_type parameter.
[0122] In some embodiments, the message types include the following: batch add, batch delete, and clear by terminal device IP. Batch add can be understood as a terminal device requesting the router to add multiple 5-tuple information in batches. Batch delete can be understood as a terminal device requesting the router to delete multiple 5-tuple information in batches. "Clear by terminal device IP" can be understood as using the terminal IP as a factor in deleting 5-tuple information, that is, batch deleting 5-tuple information related to that terminal IP.
[0123] This application does not impose specific limitations on the values of fields corresponding to message types in its embodiments.
[0124] The number of quintuples indicates the number of quintuples requested by the terminal device. This number can be represented by the `flow_num` parameter.
[0125] Optionally, the 5-tuple information includes the source IP address, source port, destination IP address, destination port, and protocol type. This application embodiment does not specifically limit the device types corresponding to the source and destination devices.
[0126] For example, the source device is the terminal device, and the destination device is the application server; correspondingly, the source IP is the terminal IP, the source port is the terminal port, the destination IP is the server IP, and the destination port is the server port. Or, for another example, the source device is the application server, and the destination device is the terminal device; correspondingly, the source IP is the application server IP, the source port is the application server port, the destination IP is the terminal IP, and the destination port is the terminal port.
[0127] Here, protocol type refers to the communication protocol used for data interaction between devices. This application does not specifically limit the protocol type; for example, the protocol type may be TCP. Or, for example, the protocol type may be UDP.
[0128] For example, the parameters included in the quintuple information can be shown in Table 1 below:
[0129] Table 1
[0130]
[0131] It should be understood that the representation of each parameter shown in Table 1 is merely an example, and those skilled in the art may define parameter names different from those in Table 1 in specific implementations. Of course, the types used for each parameter in the code implementation can also be flexibly chosen based on actual needs, and there are no restrictions on this.
[0132] In some embodiments, the first message includes a message type, the number of 5-tuples, and the specific content of the 5-tuples. For example, the overall structure of the first message is represented as ftca_flowctl. The parameters included in the first message can be referred to in Table 2 below:
[0133] Table 2
[0134]
[0135] It should be understood that the representation of each parameter shown in Table 2 is merely an example, and those skilled in the art may define parameter names different from those in Table 2 in specific implementations. Of course, the types used for each parameter in the code implementation can also be flexibly chosen based on actual needs, and there are no restrictions on this.
[0136] As shown in Figure 4A, the first message shown in Figure 4A includes a message type field (msg_type), a field for the number of quintuples (flow_num), and n quintuple messages (for example, represented as ftca_flowinfo1, ftca_flowinfo2, ..., ftca_flowinfon respectively).
[0137] It should be understood that the embodiments of this application do not specifically limit the number of quintuples included in the first message. The value of n can be an integer greater than or equal to 1. The first message may include one or more quintuples.
[0138] It should also be understood that the structure of the first message shown above is merely an example description, and the embodiments of this application do not limit the specific method by which the terminal device sends the five-tuple information. The terminal device can send one or more five-tuple information to the router in any way.
[0139] For example, a terminal device can report the 5-tuple information corresponding to the application the user is using to the router. The 5-tuple information can be information corresponding to a 5-tuple data stream that needs to be accelerated, or information corresponding to a 5-tuple data stream that needs to be de-accelerated.
[0140] For example, terminal devices can send the 5-tuple information corresponding to data that needs to be transmitted first, such as games and videos, to the router so that the router can perform priority forwarding processing on the data stream corresponding to the 5-tuple information.
[0141] For example, a terminal device can send the 5-tuple information to the router via the MSG_FTCA_FLOW_SET message.
[0142] This application does not specifically limit the protocol used by the terminal device to send the 5-tuple information to the router. For example, the terminal device can send the 5-tuple information to the router through the terminal-to-router collaborative data channel or other data protocols.
[0143] It should be understood that the terminal device has the ability to know which application corresponds to the connection of each 5-tuple. This application does not specifically limit the method by which the terminal device obtains the connection information of the 5-tuple. The terminal device can obtain the TCP / UDP connection between a certain application and the corresponding business server through various methods.
[0144] For example, TCP connection information can be obtained through the command ` / proc / net / tcp`; connection information can be obtained through ` / proc / net / udp`; and the UID can be used to determine which application each connection belongs to. The UID can be understood as a user ID; each application installed on a terminal device is assigned a unique user ID. Figure 4B shows a code example. Executing ` / proc / net / tcp` in Linux will produce the output shown in Figure 4B. The output includes `local_address` (i.e., local address and port), `rem_address` (i.e., remote address and port), and `uid` (i.e., the application to which the connection belongs).
[0145] It should be understood that the example in Figure 4B is only for illustrating that the terminal device has the ability to obtain quintuple information and which application the quintuple connection corresponds to, and does not constitute a limitation on the embodiments of this application.
[0146] In order to implement the method of the embodiments of this application, it is necessary to create or load the functions or functional modules to be used later during the initialization phase.
[0147] Optionally, before step 501 or step 502, the method shown in FIG3 further includes: step 50, whereby the co-accelerated kernel module can perform initialization processing.
[0148] The purpose of initialization is to create or load the functions or functional modules involved in this application, or in other words, to prepare for their subsequent use.
[0149] Optionally, as an embodiment, for the method steps in Figure 3 used to solve the problem of "the inability to perform DSCP tagging processing on subsequent packets that are not on the protocol stack" (e.g., at least including steps 501, 502, 503, 504, and 505), step 50 may include the following initialization processing steps: step b, creating a hash table (e.g., a hash bucket, which will be described later in conjunction with Figures 4C and 5); step c, registering a 5-tuple message from user space; step d, registering a protocol forwarding link hook function.
[0150] Optionally, as another embodiment, for the method steps in Figure 3 used to solve the problem of "timely cleanup of obsolete entries" (e.g., at least including: steps 501, 502, 503, 504, 505, 506-1, 506-2, 506-3, 507, and 508), step 50 may include the following initialization processing steps: step a, creating an aging timer; step b, creating a hash table (e.g., a hash bucket); step c, registering a five-tuple message from user space (e.g., the first message); step d, registering a protocol forwarding link hook function. The relevant solutions for "timely cleanup of obsolete entries" are described in detail in Figures 10A to 11 below.
[0151] It should be understood that the embodiments of this application do not specifically limit the execution order of steps a to d. Exemplarily, steps a, b, c, and d can be executed sequentially. Alternatively, steps a, b, c, and d can be executed simultaneously. Or, steps a, b, c, and d can be executed in any other order.
[0152] The purpose of creating the aging timer in step a is to achieve aging detection and solve the problem of "timely cleaning of discarded entries". This embodiment does not specify the period of the aging timer; for example, the period of the aging timer may be 60 seconds. The usage of the aging timer can be referred to the description in Figure 11 below, which will not be elaborated here.
[0153] For example, a timer can be created using Linux's timer_setup mechanism for aging monitoring.
[0154] The purpose of creating a hash table (e.g., a hash bucket) in step b is to facilitate hash table management in the subsequent step 503. For example, an FTCA rule hashbucket is created based on the Linux struct hlist_head.
[0155] For example, step c includes: registering a 5-tuple operation message from user space using the Linux netlink mechanism.
[0156] For example, step d includes: registering the hook function of the protocol stack forward chain using the Linux nf_register_hook mechanism.
[0157] Specifically, the following code can be used to register hook functions:
[0158]
[0159] Where hook=ftca_mark_skb is the callback function to be executed. pf=PF_INET represents the IPv4 protocol family.
[0160] `hooknum = NF_INET_FORWARD` indicates the selected hook point, which can be understood as only triggering processing for packets forwarded by the router. `priority = INT_MAX` means it is the last processing step in the corresponding chain.
[0161] It is understood that the above code is only an example using the IPv4 protocol suite, and the embodiments of this application are not limited thereto. In fact, the embodiments of this application can be extended to the IPv6 case.
[0162] It should be noted that step 50 in Figure 5 describes the initialization process when loading a module. Correspondingly, for the process of unloading a module, a corresponding exit mechanism can also be used to release resources.
[0163] Optionally, in some embodiments, when unloading the co-acceleration kernel module, the contents of the function ftca_manager_fini specified by module_exit in Linux can be used.
[0164] For example, when uninstalling the co-acceleration kernel module, the following steps are included:
[0165] Step e involves using the Linux nf_conntrack_unregister_notifier mechanism to deregister connection tracking events.
[0166] It should be noted that the aforementioned module_init function does not involve registering connection tracking events. This is because the module_init function is generally executed when the kernel starts up, and registering connection tracking events at this time is ineffective. Therefore, connection tracking events need to be registered after the kernel has fully started up.
[0167] Step f: Use the Linux unregister_pernet_subsys mechanism to deregister the hook point.
[0168] Step f corresponds to step d in the aforementioned initialization process.
[0169] Step g: Cancel the netlink message for the application layer 5-tuple operation.
[0170] Step g corresponds to step c in the aforementioned initialization process.
[0171] In step h, if there are entries in the hash bucket, release the node memory allocated to each entry in the hash bucket and clear the entries in the hash bucket.
[0172] Step h corresponds to step b in the aforementioned initialization process. For example, it releases the node memory corresponding to each table entry in the FTCA rulehash bucket created in step b, and deletes the contents of each table entry in the FTCA rulehash bucket.
[0173] Step i: Cancel the aging timer.
[0174] For example, cancel the aging timer created using Linux's timer_setup mechanism.
[0175] It should be understood that this explanation uses steps e to i as examples only, and the embodiments of this application are not limited to these. In fact, the functions or modules that are initialized and started correspond to the functions or modules that are deregistered during subsequent uninstallation. For example, if a hash table is created during initialization, then the lookup table needs to be deregistered accordingly during deregistration; if no aging timer was originally created, then the aging timer does not need to be deregistered during deregistration.
[0176] It should also be understood that the embodiments of this application do not specifically limit the execution order of steps e to i above.
[0177] The message receiving module in the router can pass the received messages to the kernel. It should be understood that the embodiments of this application do not limit the message passing mechanism inside the router.
[0178] As one implementation method, in step 502, the message receiving module can send the first message to the collaborative acceleration kernel module through a message conversion mechanism.
[0179] For example, the MSG_FTCA_FLOW_SET message received by the router's message receiving module is a user-space message; the five-tuple information reported by the terminal device is communicated to the collaborative acceleration kernel module through the netlink mechanism.
[0180] The netlink mechanism can be understood as a communication mechanism between user space and the kernel, such as receiving or sending netlink messages. A detailed description of netlink can be found in related technical documents and will not be elaborated upon here.
[0181] Step 503: The collaborative acceleration kernel module performs hash table management (or 5-tuple entry management) based on the first message. Alternatively, the collaborative acceleration kernel module manages the hash table entries based on the first message.
[0182] The management of hash tables includes, but is not limited to: adding quintuple information to the hash table; deleting quintuple information from the hash table; and updating relevant information (such as status parameters, indicating whether an entry is marked with DSCP; time parameters, indicating the last active time of an entry, etc.) of entries recorded in the hash table (e.g., quintuple entries or triple entries). Specific hash table management operations can be determined by the first message.
[0183] In this embodiment, a hash bucket is introduced to manage the five-tuple information reported by the terminal device. A hash bucket is a data structure used to implement a hash table. The hash bucket uses a hash function to map keys to indices within the bucket to achieve data storage and access.
[0184] This application does not limit the specific method of creating the hash bucket. For example, an FTCA rule hash bucket can be created based on Linux's structhlist_head.
[0185] The hash bucket of this application embodiment is described below with reference to Figure 4C. Figure 4C shows a schematic diagram of a hash bucket according to an embodiment of this application. As shown in Figure 4C, the horizontal axis represents the hash index, and the vertical axis represents the length of the hash chain. It can be understood that a hash index is a commonly used index structure; the hash index maps the index key to the index bucket (or slot) through a hash function to achieve fast lookup and access. The hash index takes values of 1, 2, ..., maxnum / 2. maxnum represents the maximum number of entries (e.g., 5-tuple entries or 3-tuple entries) that the router can manage. The key value of each hash key is determined based on the 5-tuple information. It can be understood that the hash key can be 5-tuple information or 3-tuple information determined based on the 5-tuple information.
[0186] In some embodiments, to reduce computational complexity, as shown in the lower part of Figure 4C, the triples in the quintuple information can be used as the hash key for the hash bucket. As can be seen, the hash key in each hash index in the lower part of Figure 4C uses a triplet item. A triple can be understood as the three parameters in the quintuple information, such as source IP, source port, and protocol type. Triples are used as the hash key here because, in engineering applications, triplet information is sufficient to accurately identify a data stream, thus eliminating the need to use quintuple information as the hash key. Therefore, using triples as the hash key for the hash bucket effectively reduces complexity.
[0187] For example, when the hash key is a triplet, the hash index can be calculated using the Linux kernel hash function. The specific calculation formula or code is as follows:
[0188] index=jhash_3words(ip_host,port_host,proto)%FTCA_HASH_SIZE;
[0189] Here, `index` represents the hash index, `jhash_3words` represents the hash function, `(ip_host, port_host, proto)` represents the triple information, and `FTCA_HASH_SIZE` represents the length of the hash array. In other words, by inputting the triple information using the above formula, the hash index can be obtained.
[0190] It should be noted that the more entries a router manages, the more memory it consumes, and the lower the efficiency of searching for entries becomes. Therefore, in this embodiment, the array length of the hash bucket is designed to be maxnum / 2. This design balances memory consumption and the time complexity of searching for entries.
[0191] Using the example in Figure 4C to illustrate the benefits of this design, the value of maxnum is 180, meaning that the router's hash table entries (or quintuple acceleration entries) can manage a maximum of 180 quintuple entries (or triplet entries). Correspondingly, the array length maxnum / 2 of the hash index shown in Figure 4C is 90.
[0192] Due to the discrete nature of hashing, theoretically, when the hash table is full, the number of entries falling on each hash chain is approximately 2; when the number of entries contained in a hash table is less than maxnum / 2, the number of entries falling on each chain is approximately 0 or 1; only in rare cases will a small number of chains have more than 2 entries. The discrete nature of hashing can be understood with reference to the following example: a hash key satisfies the condition that its value is uniformly distributed within its range for a given connection; for example, the range of IP addresses is 192.168.1.2-192.1681.254; the port is a non-general port 16384-65535; and the protocol, according to kernel standard values, is 6 / 17, representing TCP / UDP respectively.
[0193] Based on the above description, in the hash bucket shown in Figure 4C, when the hash bucket is full (which can be understood as storing the maximum number of entries that can be supported, such as 180) and half-full (which can be understood as storing half of the maximum number of entries that can be supported, such as 90), by inputting the information of the item to be queried (such as quintuple information or triple information), the specific item in the hash bucket can be output. The query time complexity is O(2) and O(1), respectively. O(2) means that when the information of the item to be queried is input, the corresponding item information is found after 2 queries; O(1) means that when the information of the item to be queried is input, the corresponding item information is found after 1 query.
[0194] Conversely, if the design shown in Figure 4C is not adopted, and the number of entries in the hash list is set to 10, the time complexity may be O(10), meaning the query speed is slow; or, if the number of entries in the hash list is set to 1, the time complexity is O(1), which would result in a faster query speed, but would consume too much memory. Therefore, it can be seen that the design shown in Figure 4C can balance the two factors of "memory consumption" and "time complexity of searching for entries".
[0195] In some embodiments, the collaborative acceleration kernel module can perform hash table management on the five-tuple information reported by the terminal device based on the message type of the first message.
[0196] Optionally, if the first message is a batch-added message, for example, if the message type parameter included in the first message indicates that the first message is a batch-added message, then one or more quintuples of information included in the first message are added to the hash table.
[0197] Optionally, if the first message is a batch deletion message, for example, if the message type parameter included in the first message indicates that the first message is a batch deletion message, then one or more quintuple information included in the first message can be deleted from the hash table.
[0198] Optionally, if the first message is a deletion message that performs batch clearing of terminal IP, for example, if the message type included in the first message indicates that the first message is to delete 5-tuple information based on terminal IP as a filtering factor, then in the hash table, the 5-tuple information that meets the conditions (for example, the terminal IP corresponding to the 5-tuple information is the terminal IP indicated by the message type field of the first message) is deleted in batch.
[0199] This section only briefly describes the principles of router management of hash tables when the first message is of different message types; the specific process will be described later.
[0200] The following describes an example diagram of a hash bucket recording result according to an embodiment of this application, with reference to Figure 5. As shown in Figure 5, the hash bucket includes maxnum / 2 linked lists, each containing a certain number of nodes. Each node stores an entry information (e.g., triple information) and related content. Optionally, the content related to the entry information includes one or more of the following: a time parameter (representing the last active time); and a status parameter (representing whether a DSCP tag has been added). For example, the time parameter is used to represent the last active time corresponding to the triple information, which can be represented as lasttime. For example, the status parameter is used to indicate whether the DSCP value of the message corresponding to the triple information has been modified.
[0201] Step 504: If the message type of the first message is batch addition (or new addition), the collaborative acceleration kernel module processes the n quintuple information included in the first message; and if the data stream corresponding to the kth quintuple information has entered the hardware acceleration, the hardware acceleration table entry corresponding to the kth quintuple information is cleared, wherein the kth quintuple information is the quintuple information among the n quintuple information that meets the preset conditions.
[0202] If n equals 1, meaning the first message contains a single quintuple, then that quintuple can be processed. If n is greater than 1, meaning the first message contains multiple quintuples, then those multiple quintuples should be processed sequentially.
[0203] In other words, if the data stream corresponding to the kth quintuple information has already entered the hardware acceleration, then the collaborative acceleration kernel module deletes the corresponding hardware acceleration entry.
[0204] For example, the k-th quintuple information being the quintuple information among the n quintuple information that meets the preset conditions can be understood as: the k-th quintuple information is the quintuple information to be added, which has not been previously stored in the hash bucket; or, the k-th quintuple information has been previously stored in the hash bucket. For the specific process of step 504, please refer to the flowchart described in Figures 6A and 6B below.
[0205] Step 505: After obtaining the downlink packet, the packet processing module in the router performs the DSCP marking process on the detected downlink packet.
[0206] In some embodiments, the downlink message processed in step 505 includes at least the data message corresponding to the k-th quintuple information.
[0207] Of course, the message processing module can process the captured data messages, not only the data message corresponding to the kth quintuple information mentioned above, but also the data message corresponding to other quintuple information to be accelerated.
[0208] Optionally, in step 506-1, when there is a downlink packet to be forwarded in the upper-layer protocol stack, the packet processing module is triggered to perform table entry matching. In other words, after detecting a forwarding packet, the packet processing module interacts with the cooperative acceleration kernel module to match acceleration entries (acceleration entries can be understood as the entries managed by the hash table in step 503).
[0209] Optionally, table entry matching can be understood as follows: for a downlink message to be forwarded, obtain the corresponding 5-tuple information; obtain the 3-tuple information based on the 5-tuple information; then calculate the hash index based on the 3-tuple information, and perform matching through the hash table managed in the collaborative acceleration kernel module.
[0210] Optionally, in some embodiments, in step 506-2, when the message processing module matches the corresponding triplet information in the hash table, it can refresh the time parameter corresponding to the triplet information. For example, the time parameter is used to indicate the last active time (lasttime) of the triplet information. Refreshing the time parameter corresponding to the triplet information here can be understood as updating the last active time of the triplet information to the current time.
[0211] Optionally, in some embodiments, in step 506-3, when the packet processing module matches the corresponding triplet information in the hash table, it modifies the DSCP value. For example, the packet processing module modifies the DSCP field in ip_h->tos. If the terminal device sends a five-tuple information that needs acceleration in step 501, the DSCP value can be modified here to increase the packet's sending priority, thereby achieving priority forwarding of the packet. If the terminal device sends a five-tuple information that needs to be de-accelerated in step 501, the DSCP value can be modified here to decrease the packet's sending priority, thereby canceling priority forwarding of the packet.
[0212] In this embodiment, the router receives a first message from a terminal device and manages hash table entries according to the first message. When n quintuples are added to the hash table entry, the router processes the n quintuples sequentially and determines whether the data stream corresponding to the k-th quintuple has entered hardware acceleration. The first entry is a quintuple among the n quintuples that meets a preset condition. If the data stream corresponding to the k-th quintuple has entered hardware acceleration, the router clears the hardware acceleration entry corresponding to the k-th quintuple. The router performs a DSCP marking process on detected downlink packets, where the downlink packets at least include the data packet corresponding to the k-th quintuple. Therefore, compared to DSCP marking schemes in related technologies that do not consider hardware acceleration, this embodiment clears the hardware acceleration entry for the k-th quintuple that has already entered hardware acceleration, enabling the data stream corresponding to the k-th quintuple to re-enter the protocol stack. In this way, the data packets processed in the protocol stack can perform the DSCP marking process, thus solving the problem that data streams that have entered hardware acceleration cannot be marked with DSCP.
[0213] It can be understood that the hardware acceleration table is used to store entries that require hardware acceleration, or in other words, it stores hardware acceleration entries corresponding to 5-tuple information. Optionally, the hardware acceleration table stores one or more entries that require hardware acceleration; each entry contains corresponding 5-tuple information. For the 5-tuple information corresponding to an entry stored in the hardware acceleration table, the corresponding data packet does not need to be processed by the upper-layer protocol stack and is directly forwarded by the hardware module. This application, after identifying whether the data stream corresponding to the k-th 5-tuple information has entered hardware acceleration, will delete the hardware acceleration entry corresponding to the k-th 5-tuple information in the hardware acceleration table.
[0214] The following describes the specific methods by which the router performs hash table management for the first message of different message types.
[0215] Optionally, as an example, when the first message is a batch of newly added messages, the router performs hash table management including:
[0216] As shown in Figure 6A, the following processing is performed on each quintuple information in the first message:
[0217] Step 60: Calculate the hash index using the triplet information in the quintuple information.
[0218] To facilitate understanding of the processing of n quintuple messages, this explanation uses one of the quintuple messages as an example. This quintuple message can be any one of the n quintuple messages included in the first message.
[0219] For details on how to calculate hash indexes using triplet information, please refer to the previous text; it will not be elaborated here.
[0220] Step 61: Perform triple matching based on the linked list corresponding to the hash index in the hash table.
[0221] For example, using the hash buckets shown in Figure 4C or Figure 5 above as an example, assume that the hash index calculated based on the triplet information in the quintuple information is 1; based on hash index 1, the corresponding hash chain 1 can be found; in the hash node corresponding to hash chain 1, triplet matching can be performed. If the corresponding triplet information exists in the hash node, it is considered that the quintuple information has been matched; if the corresponding triplet information does not exist in the hash node, it is considered that the quintuple information has not been matched.
[0222] Step 62: If the quintuple information is not matched in the hash table, add the triple information corresponding to the first quintuple information to the hash table, and determine whether the data stream corresponding to the first quintuple information enters the hardware acceleration.
[0223] In other words, if the 5-tuple information is not found in the hash table, it is considered a 5-tuple information to be added. In this case, it needs to be added to the hash table to achieve the purpose of adding the 5-tuple information.
[0224] For example, adding the triplet information corresponding to the quintuple information to the hash table includes: allocating memory for the hash node; and storing the triplet information, time parameter, and state parameter corresponding to the quintuple information in the hash node.
[0225] Step 63: If the quintuple information is matched in the hash table, update the time parameter of the triple information, and when it is determined that the state parameter of the triple information indicates that it has been marked with DSCP, determine whether the data stream corresponding to the quintuple information has entered the hardware acceleration.
[0226] The triplet information is the triplet information that is matched in the quintuple information in the hash table. For example, if the quintuple information is source IP address 1, source port 1, destination IP address 1, destination port 1, and protocol type 1; and the triplet information in the hash table is source IP address 1, source port 1, and protocol type 1, then it is considered that a triplet information matching the quintuple information has been found in the hash table.
[0227] In other words, if the 5-tuple information is matched in the hash table, it is considered that the 5-tuple information is not a newly added 5-tuple information (or that the 5-tuple information has already been added to the hash table). It should be noted that, in practice, terminal devices may repeatedly send 5-tuple information, for example, sending the same 5-tuple information every second. Therefore, before clearing the hardware acceleration table entry, it is necessary to first determine whether it is truly necessary to clear it. This is because clearing the acceleration table entry corresponding to the 5-tuple information and sending subsequent data streams to the protocol stack for processing will inevitably consume CPU performance. Therefore, before clearing the hardware acceleration table entry, it is necessary to first determine whether it is truly necessary to clear it; that is, the hardware acceleration table entry will only be cleared if it is determined that DSCP marking is indeed required.
[0228] In other words, the purpose of clearing the hardware acceleration table entry corresponding to the 5-tuple information is to enable the subsequent protocol stack to execute the DSCP marking process. Therefore, in step 63, for 5-tuple information that has already been marked with DSCP, there is no need to perform DSCP marking again, and therefore no need to clear the hardware acceleration table entry corresponding to that 5-tuple information.
[0229] This application does not limit the specific implementation of the state parameter indicating that the DSCP tag has been applied. For example, a state parameter value of 1 indicates that the DSCP tag has been applied.
[0230] Step 64: If the data stream corresponding to the quintuple information has already entered hardware acceleration, clear the hardware acceleration entry corresponding to the quintuple information.
[0231] Optionally, clearing the hardware acceleration entry corresponding to the 5-tuple information can be understood as deleting the relevant content of the 5-tuple information from the hardware acceleration entry. In this way, subsequent data stream packets containing the 5-tuple information will not be forwarded between hardware acceleration modules, but will be processed first by the protocol stack.
[0232] This application does not limit the specific implementation method for clearing the hardware acceleration table entry corresponding to the 5-tuple information. For example, the clearing of the corresponding hardware acceleration table entry can be completed by calling the interface provided by the chip manufacturer. The method flow shown in Figure 7A will be described later.
[0233] It's important to note that the hash table managed by the router has a maximum limit, or upper limit. When this limit is exceeded, the router cannot process 5-tuples exceeding the limit. When the first message includes n 5-tuples to be added, it's necessary to check whether the number of entries already in the hash table exceeds the router's processing limit.
[0234] To facilitate understanding of the scenario where the first message is a batch of newly added messages, the following description is based on the logical flow shown in Figure 6B. It should be understood that some descriptions in Figure 6B can be referenced from those in Figure 6A, and some identical descriptions will not be repeated. As shown in Figure 6B, it includes:
[0235] Step 601: The router receives the first message, which is a batch add message.
[0236] It should be noted that the router will only receive batch new messages from the application layer after the kernel module in the router (such as the collaborative acceleration kernel module shown in Figure 3, which can be referred to as the kernel) has been fully started and the router has the ability to interact with the terminal device.
[0237] Step 602: Determine if this is the first time processing.
[0238] The purpose of step 602 is to determine whether this is the first time the process is being handled, in order to subscribe to connection tracking events. This is because, as described earlier, the `module_init` function is generally executed when the kernel first starts, at which time registering connection tracking events is ineffective. If it is determined to be the first time the process is being handled, then step 603-1 can be executed to complete the subscription to connection tracking events.
[0239] The specific implementation of step 602 is not limited in the embodiments of this application.
[0240] For example, it can be determined whether this is the first time processing is being performed by checking if the flag of ct_notifier_inited is false. If the flag of ct_notifier_inited is false, it indicates that this is the first time processing is being performed, and the initialization of connection tracking event subscription is executed, for example, step 603-1 is executed.
[0241] Step 603-1: Initialize connection tracking event subscription.
[0242] For example, after initializing the connection tracking event subscription, the flag of ct_notifier_inited in step 603-1 is set to 1.
[0243] Step 603-2: Determine whether the number of existing entries in the hash bucket (or hash table) plus the number of new entries is greater than the upper limit (e.g., the aforementioned maxnum).
[0244] The number of new additions refers to the number of five-tuple information items to be added in the first message.
[0245] If the result of step 603-2 is yes, that is, the number of existing entries in the hash bucket plus the number of new entries is greater than the upper limit, then an error code is responded, for example, step 604-1 is executed; if the result of step 603-2 is no, that is, the number of existing entries in the hash bucket plus the number of new entries is less than or equal to the upper limit, then the router can continue processing, for example, step 604-2 is executed.
[0246] Step 604-1, response error code.
[0247] An error code indicates that the upper limit has been exceeded and the 5-tuple information cannot be added in batches. For example, the error code is SET_FLOW_FULL.
[0248] Step 604-2: Process each of the n quintuples to be added in batches sequentially.
[0249] In other words, it is necessary to judge each quintuple information in the first message here, for example, by executing steps 605-612 below.
[0250] Step 605: Calculate the hash index using the triplet information from the quintuple information.
[0251] The method for calculating the hash index can be found in the previous description, and will not be repeated here.
[0252] Step 606: Match existing items in the linked list corresponding to the hash index according to the triplet.
[0253] In other words, after calculating the hash index, the linked list corresponding to the hash index can be traversed. If there is an entry with identical 5-tuple parameters, it can be considered a duplicate request from the terminal, and the time parameter of the 5-tuple information can be refreshed, for example, by executing step 608-1. If there is no entry with identical 5-tuple parameters, the 5-tuple entry is considered a new 5-tuple entry to be added. For the new 5-tuple entry, a new hash node can be allocated for the 5-tuple information, and the flow_info in the hash node can be filled with the 5-tuple information (or triple information).
[0254] Step 607: Determine whether an existing item is found in the linked list corresponding to the hash index.
[0255] If the result of step 607 is yes, then proceed to step 608-1; if the result of step 607 is no, then proceed to step 608-2.
[0256] Step 608-1 is considered as keeping the device alive and updating the time parameters.
[0257] As mentioned earlier, if the five-tuple information already exists in the hash bucket, it is considered that this is a duplicate request from the terminal. Therefore, the time parameter corresponding to the existing five-tuple information can be refreshed. The time parameter is used to indicate the last active time (i.e., lasttime) of the five-tuple information, that is, the time indicated by the time parameter is updated to the current time.
[0258] Step 609: Determine whether the state corresponding to the quintuple information has been marked with DSCP.
[0259] If the result of step 609 is yes, then proceed to step 612; if the result of step 609 is no, then proceed to step 610. For 5-tuple information that already exists in the hash bucket but has not been marked with DSCP (which can also be understood as 5-tuple information waiting to be refreshed in the hash table), DSCP marking can also be performed by clearing its hard-accelerated table entry.
[0260] Step 608-2: Allocate node memory, fill in information (e.g., quintuple information or triplet information), and add hash.
[0261] As mentioned earlier, if no existing item is found in the linked list corresponding to the hash index, a new hash node can be allocated or requested, and the flow_info field in the hash node can be filled with the quintuple information or the triple information in the quintuple information; the time parameter is the current time; the status parameter indicates that the DSCP tag is not applied, for example, the value of the status parameter is 0.
[0262] Step 610: Determine whether the data stream corresponding to the quintuple information has entered hardware acceleration.
[0263] If the result of step 610 is yes, then proceed to step 611; if the result of step 610 is no, then proceed to step 612.
[0264] Step 611: Clear the hardware acceleration table entry corresponding to the quintuple information.
[0265] For newly added entries, since they haven't been marked with DSCP before, if the corresponding data stream has already entered hardware acceleration, the hardware acceleration entry corresponding to the new entry can be cleared here, causing the corresponding data stream to exit hardware acceleration, and subsequent packets can be re-processed on the protocol stack. For details on clearing the hardware acceleration entry corresponding to the 5-tuple information, please refer to the previous description or the description in Figure 7A below; it will not be repeated here.
[0266] Step 612: Determine whether it is the last quintuple among n quintuple information.
[0267] If the result of step 612 is yes, then proceed to step 613; if the result of step 612 is no, then proceed to step 604-2.
[0268] Step 613, processing complete.
[0269] It should be understood that the steps included in the method flow shown in Figure 6B are merely exemplary descriptions, and the embodiments of this application are not limited thereto.
[0270] In some embodiments, the packet forwarding method of this application can be applied to scenarios where downlink packets are blocked. For example, a mobile phone establishes a Wi-Fi connection with a router. The presence of walls isolating the Wi-Fi signal or other factors affecting the Wi-Fi signal quality can lead to a slow downlink packet transmission speed by the router through the Wi-Fi network card. In this situation, using the packet forwarding method of this application, the DSCP value can be effectively utilized by the Wi-Fi priority queue, effectively accelerating packet transmission.
[0271] This application does not limit the specific method for clearing hard acceleration entries in the embodiments. Step 611 in Figure 6B can be replaced by the process shown in Figure 7A. Figure 7A shows an example diagram of a mechanism for clearing hard acceleration entries. As shown in Figure 7A, it includes at least the following steps:
[0272] Step 701: Obtain the hardware acceleration table.
[0273] The hardware acceleration table records the hardware acceleration entries corresponding to the quintuple information that has already entered hardware acceleration. For a detailed introduction to the hardware acceleration table, please refer to the descriptions in relevant technical documents; details will not be elaborated here.
[0274] For example, Figure 7B shows an example of the contents of a hardware acceleration entry. Figure 7B shows an example of a set of bidirectional hardware acceleration flows between LAN and WAN. Network segment 3 represents a Wide Area Network (WAN), and network segment 1 represents a Local Area Network (LAN). The IP address of network segment 3 could be 192.168.3.* as shown in Figure 7B; the IP address of network segment 1 could be 192.168.1.* as shown in Figure 7B. The right side of the symbol '=>' shows an example of the IP / port translation after the network address port translation (NAPT).
[0275] It is understandable that the information formats of hardware acceleration entries from different manufacturers may be the same or different, or some content may be the same and some content may be different; there are no restrictions on this.
[0276] Step 702: Traverse and examine the table entries.
[0277] For example, one or more hardware acceleration entries stored in the hardware acceleration table are traversed sequentially to find the hardware acceleration entry to be cleared that corresponds to the quintuple information in step 611 above.
[0278] Step 703: Determine whether it matches the quintuple to be searched.
[0279] The quintuple to be searched can be the quintuple information to be added at step 608-1 as shown in Figure 6B, or the quintuple information that has not been marked with DSCP (or the quintuple information to be refreshed) as determined by the judgment result of step 609.
[0280] The purpose of step 703 is to determine whether the quintuple information to be added or refreshed is located in the hardware acceleration table by looking up the hardware acceleration table.
[0281] If the result of step 703 is yes, then step 704 is executed, that is, the hard acceleration table entry is deleted; if the result of step 703 is no, then step 705 is executed.
[0282] Step 704: Delete the hardware acceleration table entry.
[0283] For example, delete the hardware acceleration table entry corresponding to the quintuple information in step 611 from the hardware acceleration table.
[0284] Step 705: Determine if this is the last entry.
[0285] In other words, if there are multiple hardware acceleration entries in the hardware acceleration table, the quintuple information can be matched with the multiple hardware acceleration entries sequentially. If the result of step 705 is yes, then step 706 is executed; if the result of step 705 is no, then step 702 is executed, and the traversal process continues.
[0286] Step 706, processing complete.
[0287] It should be understood that the method flow for clearing hardware acceleration entries shown in Figure 7A is merely an exemplary description, and the embodiments of this application are not limited thereto. In fact, there are other ways to clear hardware acceleration entries in practical applications, which will not be described in detail here.
[0288] Optionally, as another embodiment, for the case where the first message is a batch deletion message, the router performs hash table management including:
[0289] Perform the following processing on each 5-tuple information in the first message:
[0290] Step 80: Calculate the hash index using the triplet information in the quintuple information.
[0291] Step 81: Perform triple matching based on the linked list corresponding to the hash index in the hash table.
[0292] For explanations of steps 80 and 81, please refer to the descriptions of steps 60 and 61 above. For the sake of brevity, they will not be repeated here.
[0293] Step 82: If the quintuple information is matched in the hash table, delete the content corresponding to the quintuple information (e.g., node, time parameter, state parameter stored in the node) from the hash table.
[0294] To facilitate understanding of the scenario where the first message is a batch deletion message, the following description is based on the logic flow shown in Figure 8. As shown in Figure 8, it includes at least the following steps:
[0295] Step 801: The router receives the first message, which is a batch deletion message.
[0296] Optionally, the first message includes information about the n quintuples to be deleted.
[0297] Step 802: Process each of the n quintuples to be deleted in batches (e.g., flow_info).
[0298] Step 803: Calculate the hash index using the triplet information from the quintuple information.
[0299] Step 804: Match existing items in the linked list corresponding to the hash index according to the triplet.
[0300] Step 805: Determine whether an existing item is found in the linked list corresponding to the hash index.
[0301] If the result of step 805 is yes, then proceed to step 806; if the result of step 805 is no, then proceed to step 807.
[0302] Step 807: Determine whether it is the last quintuple among n quintuple information.
[0303] If the result of step 807 is yes, then proceed to step 808; if the result of step 807 is no, then proceed to step 802.
[0304] Step 808, processing complete.
[0305] The preceding description, with reference to Figure 8, outlines the scenario of batch deletion of 5-tuple information. Optionally, as another embodiment, this application also provides a scenario of deleting 5-tuple information based on the terminal IP address.
[0306] In other words, if the message type of the first message is to delete the 5-tuple information based on the terminal IP, the flow_num of the user-space message can be defaulted to 1, and only the host_ip parameter is considered in flow_info. In this case, all nodes in all linked lists of the hash table are traversed. If the host_ip in a node is the IP that needs to be cleared, then the node is deleted.
[0307] Deleting a node can be understood as deleting the information stored in the node (such as quintuple information, time parameters, state parameters, etc.) and releasing the memory resources corresponding to that node.
[0308] The preceding text described several implementations of hash table management by routers based on user-space messages of different message types. The following text, in conjunction with Figures 9A and 9B, describes the detailed process of DSCP tagging in an embodiment of this application. The processes shown in Figures 9A and 9C can be executed by the message processing module shown in Figure 3.
[0309] Figure 9A shows a flowchart of a DSCP tag method according to an embodiment of this application. As shown in Figure 9A, it includes at least the following steps:
[0310] Step 90: Obtain the message to be forwarded.
[0311] A message to be forwarded can be understood as a message that has been forwarded by a router. For example, a downlink message sent by an application server to a terminal device is forwarded by a router. Similarly, a message sent from terminal device 1 to terminal device 2 is forwarded by a router.
[0312] In some embodiments, Figure 9A applies to data packets forwarded through the system, rather than data packets whose source or destination address is the system itself. For example, the router's web front-end / back-end interaction belongs to LAN to local machine (i.e., the router itself); the router's interaction with the time synchronization server belongs to WAN to local machine. These scenarios do not involve forwarding chain processing. For such packets, the solutions in related technologies are still used, and this application will not affect the performance of these solutions. In other words, only data packets that enter the system from one interface and leave the system from another interface will reach the callback function ftca_mark_skb registered by the hook of the aforementioned protocol stack forward chain.
[0313] For ease of understanding, refer to the application scenario shown in Figure 9B. As shown in Figure 9B, downlink packets sent from the application server to the terminal device can sequentially pass through the prerouting (or destination address translation) path, the "whether it is the local machine" branch (if not), the forwarding module, and the postrouting (or source address translation) path. That is, downlink packets sent from the application server to the terminal device are only forwarded by the router and do not enter the router's user space; this can be understood as forwarding data packets. However, for data packets involving the local machine (i.e., the router), they will enter the application through the input module. The data output by the application through the output module will be sent to the terminal device; this situation does not belong to forwarding data packets.
[0314] Step 91: Determine the triplet information based on the message to be forwarded.
[0315] Optionally, the message to be forwarded can be a downlink message. It should be noted that "downlink message" here is a general term; a downlink message can also be understood as a reply message. For example, the characteristics of a reply message are consistent with those of a terminal initiating a connection and the service server responding to the connection through the router. It should be understood that due to the firewall protection mechanism of the router, the connection is initiated by a terminal on the local area network (LAN), and cannot be initiated by a server on the wide area network (WAN).
[0316] Optionally, in some embodiments, before step 91, the message to be forwarded can be determined first; if the message to be forwarded is a downlink message, then subsequent steps are executed, such as executing step 91 or further determining the type of the message to be forwarded. If it is not a downlink message, then subsequent steps can be omitted. In this way, for uplink messages, the processing of non-downlink messages can be achieved without increasing the workload.
[0317] Optionally, in some embodiments, before step 91, it can be determined whether there is an entry in the hash table that needs to be accelerated. The purpose of this determination is that if there is no entry in the hash table that needs to be accelerated, it means that there is no packet that needs to be accelerated, so there is no need to perform subsequent determinations, which helps to save power consumption.
[0318] For example, only after determining whether there is an entry in the hash table that needs to be accelerated can we further determine whether the message to be forwarded is a downlink message, which can further save power consumption.
[0319] Step 92: Based on the triplet information, perform a query in the hash table.
[0320] For details on the process of querying or matching in a hash table, please refer to the previous text; it will not be repeated here.
[0321] Step 93: If the message to be forwarded corresponds to an entry in the hash table, modify the DSCP value in the message to be forwarded to the first value. For example, the first value is 0x111, indicating that it enters the aforementioned VO priority queue.
[0322] It should be understood that this illustration uses 0x111 as the first value only, and the embodiments of this application are not limited to this. In fact, the first value can take other values to achieve the corresponding priority level. Of course, for other application scenarios, the first value can be assigned corresponding values to achieve different DSCP marking purposes. Regardless of what value is assigned to the first value, the method of the embodiments of this application is applicable.
[0323] Optionally, before modifying the DSCP value in the message to be forwarded, the method further includes:
[0324] Determine whether the DSCP value in the message to be forwarded has been modified to the first value;
[0325] If the DSCP value in the message to be forwarded has been modified to the first value, update the time parameter of the entry corresponding to the message to be forwarded in the hash table.
[0326] Optionally, if the message to be forwarded is a TCP message, it is also necessary to consider the flag bits carried in the TCP message (such as the RST flag or FIN flag) to determine whether to update the status parameters. If the TCP message carries the RST flag or FIN flag, it indicates that the data stream is about to end. In this case, the status parameters will not be updated to the DSCP-marked state; for example, the status parameters will be updated to 1, allowing the node to age as expected or be deleted during aging detection.
[0327] For ease of understanding, a specific example scheme of the DSCP tag provided in this application is described below with reference to FIG9C. As shown in FIG9C, it includes at least the following steps:
[0328] In step 900, after the router's upper-layer protocol stack obtains the packet to be forwarded, the packet enters the processing flow.
[0329] For a description of the message to be forwarded, please refer to the description in step 90 above. For the sake of brevity, it will not be repeated here.
[0330] Step 901: Determine if there are any entries in the hash bucket that need to be accelerated.
[0331] If the result of step 901 is yes, it means that there are entries in the hash bucket that need to be accelerated, and the subsequent steps can be continued, such as step 903; if the result of step 901 is no, it means that there are no 5-tuples that need to be marked with DSCP in the hash bucket, then the process ends, such as step 902.
[0332] Step 902: No action taken; process terminated.
[0333] "No processing" here means that the DSCP marking process is not performed on the message to be forwarded; the message can continue to be processed according to the procedures in the relevant technologies.
[0334] Step 903: Determine whether the message to be forwarded is a downlink message.
[0335] It should be noted that only downlink packets can be sent to devices connected to the router via a Wi-Fi connection; therefore, we only focus on downlink packets here. This avoids wasting performance and helps save power, thus ensuring that processing non-downlink packets does not increase the workload.
[0336] For example, step 903 can be implemented in the following way:
[0337] kb->_nfct&NFCT_INFOMASK; If this value is less than IP_CT_IS_REPLY, it is determined that it is not a reply message (or downlink message) and does not need to be considered; if this value is greater than or equal to IP_CT_IS_REPLY, it is determined that it is a reply message.
[0338] If the result of step 903 is yes, that is, the message to be forwarded is a downlink message, the message type judgment can continue to be performed, such as step 904; if the result of step 903 is no, that is, the message to be forwarded is not a downlink message, then step 902 is performed.
[0339] The purpose of introducing step 903 here is that if it is not a downlink message, then the following process does not need to be executed. For example, this embodiment of the application is aimed at the case where the message to be forwarded is a downlink message, that is, the DSCP value of the uplink message is not modified. Based on step 903, for messages that do not require modification of the DSCP value (such as uplink messages), no additional load will be added, which helps to save power consumption.
[0340] If the message to be forwarded is a downlink message, it can be further determined whether the downlink message is a TCP message.
[0341] Step 904: Determine whether the downlink message to be forwarded is a TCP message.
[0342] If the result of step 904 is yes, that is, the downlink message to be forwarded is a TCP message, then proceed to step 905-1; if the result of step 904 is no, that is, the downlink message to be forwarded is not a TCP message, then proceed to step 905-2, that is, further determine whether it is a UDP message.
[0343] Step 905-1: Obtain the destination port from the TCP header.
[0344] Step 906: Assign a value to the end flag bit according to the rst or fin flag bit of the TCP packet.
[0345] Optionally, if the TCP packet is an RST packet (e.g., carrying the RST flag), or a FIN packet (e.g., carrying the FIN flag), the end flag can be assigned a value, for example, 1, indicating that the connection needs to be terminated. The RST flag represents resetting the connection, and the FIN flag represents finishing the connection. Both flags indicate that the connection needs to terminate the data stream.
[0346] For example, the end flag is represented as is_tcp_close.
[0347] Step 907: Obtain the destination IP from the IP layer.
[0348] For TCP packets, the destination IP address can be obtained from the IP protocol layer. Methods for obtaining the destination IP address can be found in relevant technical documentation and will not be elaborated upon here.
[0349] Step 905-2: Determine if it is a UDP packet.
[0350] If the result of step 905-2 is yes, that is, the message to be forwarded is a UDP message, proceed to step 908; if the result of step 905-2 is no, proceed to step 902.
[0351] Step 908: Obtain the destination port from the UDP layer.
[0352] For details on how to obtain the destination port from the UDP layer, please refer to the descriptions in relevant technologies; they will not be elaborated here.
[0353] Regardless of whether it's a UDP or TCP packet, the destination port and destination IP address of the packet to be forwarded can be obtained, such as the port and IP address of the terminal device. Furthermore, after obtaining the destination port and destination IP address, the triplet information of the packet to be forwarded can be determined by combining it with the protocol type. After obtaining the triplet information, a match can be performed in a hash table based on the triplet information.
[0354] Step 909: Calculate the hash index using the triple information.
[0355] Step 910: Match existing items in the linked list corresponding to the hash index according to the triplet. For example, the matched item is the second item.
[0356] Step 911: Determine whether the message to be forwarded is a downlink message corresponding to an entry (e.g., the second entry).
[0357] For example, if step 910 matches the second entry, step 911 can be understood as the message to be forwarded being the downlink message corresponding to the second entry.
[0358] If the result of step 911 is yes, then proceed to step 912; if the result of step 911 is no, then proceed to step 902.
[0359] Step 912: Determine if the high 3 bits of the DSCP value of the IP layer are 0x111.
[0360] If the result of step 912 is yes, then proceed to step 914; if the result of step 912 is no, then proceed to step 913.
[0361] Step 913: Modify the DSCP value to 0x111 and recalculate the IP layer checksum.
[0362] For example, if the packet to be forwarded matches the triplet information of a node in the hash table, it indicates that the packet needs to be accelerated. Then, it can be further determined whether the packet's DSCP value is 111xxx. As shown in Figure 1A above, DSCP can be located in the high 6 bits of the TOS field in the IP header. If the high 6 bits of the DSCP value are not 0x111, or if the DSCP value is not 111xxx, then its DSCP value needs to be modified to 111xxx, and the checksum recalculated so that subsequent data streams can enter the Wi-Fi VO priority queue. After modifying the DSCP value, the corresponding status parameter can be set to 1 to indicate that the corresponding hash node has been marked with DSCP after its establishment.
[0363] The purpose of calculating the IP layer checksum is for error correction, a process that is relatively resource-intensive. Therefore, for cases where the DSCP value does not need to be modified, no modification is required. In other words, the purpose of introducing the aforementioned judgment step 912 is to minimize performance overhead.
[0364] It should be understood that the embodiments of this application do not limit the specific method for calculating the IP checksum, and specific details can be found in the descriptions in related technologies. For example, the checksum can be recalculated using ip_send_check.
[0365] Optionally, in step 914, it is determined whether to terminate the connection based on the end flag bit (e.g., the first flag bit).
[0366] As mentioned earlier, if it is a TCP packet and carries the rst or fin flag, the status parameters of the five-tuple information of the data stream are not updated. For example, the status parameter is not updated to 1 (representing that it has been marked with DSCP). This is done to prevent nodes from not being deleted during aging detection. To facilitate understanding, the following application scenarios will be used as examples.
[0367] For example, when a downstream terminal of the router disables its Wi-Fi function, the router's Wi-Fi network card triggers a timer interrupt based on a beacon frame (or Beacon frame, abbreviated as bcn) to complete the destruction of connection tracking for the relevant downstream terminal, thus receiving a connection tracking aging event report during the aging process. Upon receiving the connection tracking aging event, the router updates the status parameter of the corresponding hash node to 2 (indicating that the connection tracking event has been destroyed). Simultaneously, if the service server's socket processing is sensitive, it will quickly send a downlink TCP packet carrying the rst flag upon learning that the terminal has disabled its Wi-Fi function. After receiving the TCP packet carrying the rst flag, the router executes the DSCP marking process. If the DSCP marking is executed and the status parameter corresponding to the five-tuple information is updated to 1 (indicating that it has been marked), then the node will not age as expected. This is because when the TCP packet carrying the rst flag updates the status parameter to 1 during the DSCP marking process, it overwrites the previous update of the status parameter status to 2 when the connection tracking aging event was reported. That is, the final status parameter is still 1, thus preventing the node from aging. However, this node should be deleted during aging detection. Through step 914 introduced in Figure 9C, when it is determined that the end flag indicates the end of the connection, the status parameter is not updated; it remains at status 2, thus allowing the node to be deleted.
[0368] It should be noted that the essential reason for introducing step 914 here is that the connection tracking aging event (such as the destruction event) comes from the network interruption handling, while the DSCP marking process comes from the processing of the upper-layer protocol stack. These two processes are asynchronous, and it is impossible to determine or predict which process will be executed first or last, or in other words, there is no order between the two processes. Therefore, this design is introduced to solve the problem of nodes not aging as expected in the above example scenario, thus continuously occupying node resources, which helps to reduce the waste of node resources.
[0369] It should also be noted that, for the case where the message to be forwarded is a UDP message, the end flag can be left blank by default. In other words, for the case of a UDP message, the end flag can be left blank by default when executing step 914, or the connection can not be terminated. Alternatively, for the case where the message to be forwarded is a UDP message, step 914 can be omitted. For example, steps 915 to 917 can be executed after step 913.
[0370] Step 915: Set the status parameter of the entry to 1 (or another value that indicates that it has been marked with DSCP).
[0371] It is understandable that the entries in steps 915 and 916 are the entries matched in the hash table in step 910.
[0372] Step 916: Update the time parameter of the table entry.
[0373] Step 917: Complete the DSCP marking process.
[0374] It should be understood that the detailed judgment process shown in Figure 9C is only for the purpose of helping those skilled in the art to understand the DSCP marking process of the embodiments of this application, and the embodiments of this application are not limited thereto.
[0375] To avoid the occupation of router memory by obsolete 5-tuple acceleration entries, it is necessary to delete the entry information (e.g., 5-tuple entries or 3-tuple entries) in the hash table managed by the router in this embodiment of the application. However, in related technologies, frequent interaction between the terminal and the router is required to implement the mechanism for deleting 5-tuple acceleration entries. Based on this, this embodiment of the application also provides an automatic aging mechanism that does not rely on the terminal device, that is, the router promptly identifies invalid entry information (e.g., 5-tuple entries or 3-tuple entries) and deletes obsolete entries from the hash table. For example, in step 507 of Figure 3, the collaborative acceleration kernel module deletes obsolete entries in the hash table based on the aging mechanism. Optionally, in step 508, the collaborative acceleration kernel module can send an aging message to the terminal device through the message receiving module. For example, the message type of the aging message is MSG_FLOW_TIMEOUT.
[0376] It should be understood that the router provided in this application embodiment does not rely on the automatic aging mechanism of the terminal device, and can be implemented independently or in combination with the aforementioned embodiments (such as the process shown in Figure 3), without specific limitations.
[0377] For example, for the five-tuple entries (not the aforementioned hash table or hash bucket) in router management technologies, the automatic aging mechanism provided in this application embodiment, which is independent of terminal devices, can also be used. Similarly, for the aforementioned hash table (or hash bucket) managed by the router, the automatic aging mechanism provided in this application embodiment, which is independent of terminal devices, can also be used.
[0378] Figure 10A shows a schematic flowchart of a method for deleting obsolete entries in a hash table according to this application. It should be understood that the method shown in Figure 10A (or subsequently Figures 10B and 11) can be executed by a router. For example, the method shown in Figure 10A can be executed by the router's existing kernel module; or, it can be executed by the aforementioned collaborative acceleration kernel module of the router; or, it can be executed by a specially introduced aging detection module, without specific limitations.
[0379] As shown in Figure 10A, at least the following steps are included:
[0380] Step 10: Obtain connection tracking events based on the connection tracking mechanism.
[0381] Alternatively, as one implementation, the router can perform event tracking through a connection tracking mechanism.
[0382] For example, the router kernel has a built-in connection tracking (conntrack) mechanism, which can track and record the status of connections (e.g., TCP or UDP connections). This application does not limit the specific implementation of connection tracking events. For details on the connection tracking mechanism, please refer to the descriptions in related technologies; they will not be repeated here.
[0383] The connection tracking mechanism allows for real-time acquisition of connection tracking events, such as new connections, updated connections, or destroyed connections. For aging detection purposes, this section focuses on connection destruction events, which can be referred to simply as destruction events.
[0384] Step 11: If the connection tracking event is a destruction event, obtain the quintuple information corresponding to the destruction event.
[0385] Alternatively, as an implementation, when a connection tracking event is detected as a destruction event, the quintuple information corresponding to the destruction event can be obtained based on the input parameters of the connection tracking event callback function.
[0386] After obtaining the quintuple information, a match can be made in the hash table to check if there is a corresponding entry (e.g., the third entry) in the hash table.
[0387] Step 12: Match the data in the hash table based on the quintuple information corresponding to the destruction event.
[0388] Optionally, as one implementation, step 12 includes: calculating a hash index based on the triplet information in the five-tuple information corresponding to the destruction event; and using the hash index to perform triplet matching in the linked list corresponding to the hash table, that is, checking whether there is triplet information in the five-tuple information corresponding to the destruction event in the existing entries in the linked list.
[0389] For ease of description, the entry in the hash table that matches the triplet information in the quintuple information corresponding to the destruction event can be denoted as the third entry.
[0390] Step 13: Match the third entry in the hash table.
[0391] Step 14: If the third entry meets the deletion conditions, delete the third entry in the hash table.
[0392] Optionally, as one embodiment, the third entry meets the deletion conditions, including: the time interval between the time parameter corresponding to the third entry and the current time is greater than a first preset duration; the status parameter corresponding to the third entry indicates that it is not marked with a DSCP tag; and the value of the status parameter corresponding to the third entry is a second value or a fourth value. The second value indicates that the connection corresponding to the current packet has ended, and the fourth value indicates that the hash node was not marked with a DSCP tag after it was established.
[0393] For example, a value of 0 (or the fourth value) for this status parameter indicates that the hash node was not marked with DSCP after it was created; or a value of 2 (or the second value) for this status parameter indicates that the connection tracking event is a destruction event.
[0394] Through steps 10 to 14, the router implements an automatic aging mechanism that does not rely on terminal devices for persistence. Compared to related technologies that require frequent interaction between the terminal device and the router to delete obsolete entries, the automatic aging mechanism of this application embodiment can effectively delete obsolete entries and reduce the memory usage of zombie entries by eliminating the need for frequent interaction between the router and the terminal device when deleting obsolete entries (or zombie entries).
[0395] For example, in the following application scenarios, when a terminal device abnormally disconnects from the router and fails to send a deletion message, the router can automatically delete obsolete entries using the connection tracking-based aging detection method described above. Furthermore, for routers supporting hardware acceleration, if the router cannot determine whether the data stream undergoing hardware acceleration has ended (or disconnected) after the terminal device abnormally disconnects, the connection tracking-based aging detection method can also solve the problem of not being able to detect subsequent tagging after the data stream enters hardware acceleration, promptly identifying and deleting invalid entries (such as 5-tuple or 3-tuple information).
[0396] Optionally, in some embodiments, the router tracks destruction events through the kernel's built-in connection tracking mechanism to provide a basis for subsequently deleting invalid table entries (such as quintuple or triplet information).
[0397] This application does not limit the specific form or scenario of the destruction event. Different connection tracking destruction mechanisms are described below.
[0398] Scenario 1: Timeout Destruction Event
[0399] The timeout destruction event can be understood as the destruction event of the connection tracking if there is no data interaction for a certain table entry within a certain period of time.
[0400] Optionally, different timeout durations can be set for different types of data packets.
[0401] For example, for UDP packets, a timeout of 180 seconds is set. If there is no data exchange regarding entry 1 between the router and the end device within 180 seconds, the router can trigger a connection trace destruction event to delete entry 1 from the hash table.
[0402] For example, for TCP packets, the timeout period is set to 432,000 seconds (or 5 days). If there is no data exchange regarding entry 2 between the router and the terminal within 5 days, the router can trigger a connection trace destruction event to delete entry 2 from the hash table.
[0403] Scenario 2: Destruction event upon termination of TCP data stream
[0404] The destruction event of the TCP data stream termination can be understood as a destruction event caused by the termination of the TCP data stream.
[0405] For example, TCP corresponds to two sockets on the client and server sides. If the termination condition of the service is met (e.g., there is no more data to be sent), TCP will release the connection (e.g., through a four-way handshake process), and the TCP packet will carry the FIN flag; or, the TCP data stream will be forcibly terminated, and the TCP packet will carry the RST flag. When the router's upper-layer protocol stack receives a TCP packet carrying the FIN or RST flag, it can know that the service (or client) wants to close the TCP connection, and the router will then destroy the corresponding connection tracking.
[0406] The four-way handshake can be understood as a connection termination protocol. For a detailed description of the four-way handshake, please refer to the explanations in relevant technical documents; it will not be elaborated upon here.
[0407] Scenario 3, Instruction Destruction Event
[0408] A command destruction event can be understood as the existence of a deletion command in the router; a deletion command can trigger deletion connection tracking.
[0409] For example, after configuring new firewall rules on a router, it is necessary to clear all connection tracking for IPs or ports associated with the firewall rules so that these data streams can be re-established and inspected again by the new firewall rules.
[0410] It should be understood that the three scenarios described above are merely examples of destruction events, and the embodiments of this application are not limited thereto.
[0411] Based on the three application scenarios described above, the destruction event can be triggered. Optionally, the destruction event can be tracked by subscribing to connection tracking events. When a connection tracking event exists, it can be determined whether it is a destruction event in order to decide whether to delete the table entry. The following description is based on the examples in Figures 10B and 11.
[0412] As shown in Figure 10B, at least the following steps are included:
[0413] Step 1001: The router processes the connection tracking event.
[0414] Step 1002: Determine if it is a destruction event.
[0415] Based on the connection tracking mechanism, it can be determined what type of event the current connection tracking event is. Here, we focus on destruction events. If the connection tracking event is determined to be a destruction event, step 1003 is executed; if the connection tracking event is not determined to be a destruction event, the process ends.
[0416] Step 1003: Obtain the quintuple information corresponding to the event to be destroyed from the event input parameters.
[0417] For example, the input parameter of the connection tracking event callback function includes `struct nf_ct_event`. The `ct` member corresponds to the connection tracking-related structure `struct nf_conn`. Furthermore, `ct->tuplehash` corresponds to `struct nf_conntrack_tuple_hash`, a structure used to represent the hash of the connection tracking tuple. Therefore, based on the input parameter of the connection tracking event callback function, the corresponding five-tuple information can be obtained.
[0418] It should be noted that in the Linux kernel, the above structure is used to store a hash table for connection tracing information. The structure contains information such as source IP, destination IP, protocol type, source port, and destination port to facilitate fast lookup and matching during connection tracing.
[0419] Step 1004: Using the quintuple information from step 1003, obtain the triple information and calculate the hash index.
[0420] For details on the specific implementation of calculating the hash index, please refer to the previous description. For the sake of brevity, it will not be elaborated here.
[0421] Step 1005: Using the hash index from step 1004, match the existing entries in the hash table in the linked list corresponding to the hash index according to the triple information.
[0422] The specific process of triple information matching can be found in the previous description, and will not be repeated here for the sake of brevity.
[0423] Step 1006: Determine whether an existing item is found in the linked list corresponding to the hash index.
[0424] If the result of step 1006 is yes, that is, an existing item is matched in the linked list corresponding to the hash index, it means that the matched item needs to be destroyed, for example, step 1007 is executed; if the result of step 1006 is no, it means that there is no item that needs to be destroyed, and the process can end.
[0425] Step 1007: Update the time parameter; and set the status parameter to 2.
[0426] The time parameter and status parameter in step 1007 are the parameters corresponding to the entries matched in the hash table in step 1006.
[0427] It should be noted that when a connection tracking event occurs, the status parameter of the corresponding hash node can be set to 2. However, this does not immediately trigger aging and deletion; instead, the time parameter is updated to the current time. If new packets need to be forwarded for this 5-tuple information later, the system will re-establish the connection tracking.
[0428] In other words, when a data packet reaches ftca_mark_skb for processing, the time parameter corresponding to the entry matched in the hash table in step 1006 is updated, and the corresponding status parameter is modified, but aging deletion is not triggered temporarily, thus preventing the entry from being mistakenly deleted. Furthermore, if the entry (e.g., the corresponding quintuple or triplet information) does not receive any packets for a period of time (e.g., more than 1 minute), the aging process is completed based on the detection function of the aging timer.
[0429] It should be understood that the value of the state parameter here is only used as an example to describe the destruction of connection tracking, with 2 representing the destruction of connection tracking. This embodiment of the application is not limited to this. In fact, the state parameter can take other values to represent the destruction of connection tracking, depending on the actual implementation.
[0430] As described in initialization step a of Figure 3 above, an aging timer can be created during the initialization phase to achieve aging detection. In some implementations, aging detection is achieved by periodically triggering the callback function of the aging timer.
[0431] For ease of understanding, the aging test method flow shown in Figure 11 is described below. Figure 11 can be a specific example of Figure 10A. As shown in Figure 11, the aging test method flow includes at least the following steps:
[0432] Step 1101: Call the aging timer to perform periodic testing.
[0433] In other words, periodic detection is achieved by calling the aging timer created above.
[0434] Step 1102: Traverse each entry in the hash table (e.g., hash bucket).
[0435] It is understandable that a hash table contains multiple entries. The purpose of introducing step 1102 is to traverse each entry in the hash table to determine the state parameters of each entry and obtain the result of whether each entry has been marked with a DSCP tag.
[0436] Step 1103: Determine if the DSCP marker has been applied.
[0437] For example, for entries that have been marked with DSCP, their corresponding status parameter is 1. For entries that have not been marked with DSCP, their corresponding status parameter is not 1; for example, it may be 0 or 2.
[0438] If the result of step 1103 is negative, then proceed to step 1104; if the result of step 1103 is positive, then proceed to step 1102.
[0439] Specifically, if an entry has already been marked with DSCP, it means that the message corresponding to the 5-tuple information of that entry (or the 5-tuple information recorded in the node of that entry) has already been marked by the ftca_mark_skb process (for example, by the process described in Figure 6A or Figure 6B). Even if the time indicated by the time parameter is more than a predetermined duration from the current time, it is considered a situation that cannot be captured by the subsequent hardware acceleration of this stream, and is processed as normal during acceleration. For example, return to step 1102 to continue traversing other entries. If an entry has not been marked with DSCP, then it is possible to further determine whether the time indicated by the time parameter corresponding to the entry is more than a predetermined duration from the current time. For example, execute step 1104.
[0440] Step 1104: Determine whether the time indicated by the time parameter is more than the first preset duration (e.g., one minute) away from the current time.
[0441] If the result of step 1104 is negative, meaning the time indicated by the time parameter of the table entry has not exceeded the first preset duration, then we can return to continue traversing and execute step 1102; if the result of step 1104 is positive, meaning the time indicated by the time parameter of the table entry has exceeded the first preset duration, it means that the node needs to be deleted and an aging message needs to be pushed, for example, then execute step 1105.
[0442] Step 1105: Add the triplet information to the aging message.
[0443] As described in step 1103 above, for cases where the DSCP tag is not applied, the status parameter of the entry may be 0 or 2. A status parameter of 0 indicates that the node was not tagged with DSCP after its creation. A status parameter of 2 indicates that the connection tracking for the node has been destroyed.
[0444] If the status parameter is 0, it means that after the terminal adds this 5-tuple entry, no message has reached the ftca_mark_skb process for the first preset time, or that the data message corresponding to the 5-tuple information reported by the terminal has not been captured. This situation can be considered as a false alarm by the terminal.
[0445] For the case where the status parameter is 2, it means that a connection tracking destruction event was received previously, and no new packets have entered the ftca_mark_skb process for more than the first preset time after the connection tracking destruction event. At this time, it can be considered that this data stream has ended and has not been re-established.
[0446] Therefore, in both cases, step 1105 can be executed to add the corresponding triplet information to the aging message.
[0447] Step 1106: Delete the corresponding hash node.
[0448] As described in step 1103, for entries that are not marked with the DSCP tag, step 1104 will be further executed, which determines whether the time interval between the time parameter corresponding to the entry that is not marked with the DSCP tag and the current time exceeds a first preset duration. The hash node deleted here refers to an entry in the hash table that meets the following conditions: the status parameter corresponding to the entry indicates that it is not marked with the DSCP tag; and the time interval between the time indicated by the time parameter corresponding to the entry and the current time exceeds a first preset duration.
[0449] Since there is an upper limit to the number of items that can be carried in the aging message pushed by the router, it is also necessary to determine whether the number of items included in the aging message has reached the upper limit.
[0450] Optionally, in step 1107, it is determined whether a preset number (e.g., 60) of aging items have been added to the aging message.
[0451] Optionally, the aging messages pushed by the router use netlink messages. Netlink messages have a limited message length. If netlink messages are used to send aging messages to the terminal, the number of 5-tuples that can be carried in the netlink message needs to be considered.
[0452] For example, a netlink message is 1024 bytes long, and depending on the length of a single quintuple, a netlink message can carry up to 60 quintuples.
[0453] If the result of step 1107 is yes, it means that the number of aging items included in the aging message has exceeded the upper limit of the number of items that can be carried, then proceed to steps 1108-1 and 1109; if the result of step 1107 is no, it means that the number of aging items currently included in the aging message has not yet exceeded the upper limit, and more can be added, then proceed to step 1108-2.
[0454] In practical applications, there may be more aging items than the preset number. In this case, an aging message can be pushed first, which includes the maximum number of aging items that can be carried. Then, an aging check is immediately performed again until all nodes in the hash table have been traversed, such as by executing steps 1108-1 and 1109.
[0455] Step 1108-1: After the second preset time (which can approach infinity), the detection can be performed again. For example, return to step 1102.
[0456] For example, the second preset duration is 1 second. It should be understood that this description uses a second preset duration of 1 second as an example, and the embodiments of this application are not limited to this.
[0457] Step 1109: The router pushes an aging message.
[0458] For example, Figure 3 illustrates the steps of a router sending an aging message to a terminal. The aging message can be a netlink message.
[0459] In this embodiment of the application, there is no specific limitation on the execution order of steps 1108-1 and 1109. For example, steps 1108-1 and 1109 can be executed simultaneously.
[0460] For example, when a user uses a game application through a terminal device, if the terminal device disconnects from the router's Wi-Fi connection, multiple connections may disconnect at the same time, and the connection tracking mechanism may simultaneously track multiple destruction events, ultimately triggering aging simultaneously. Therefore, when pushing aging messages, it is supported to carry multiple aging entries in one aging message (such as aging 5-tuple entries, aging 3-tuple entries).
[0461] Optionally, the message format of the aging message can adopt the aforementioned message structure ftca_flowctl, such as the message shown in Figure 4A; the message type can be MSG_FLOW_TIMEOUT.
[0462] Step 1108-2: Determine if this is the last entry.
[0463] If the result of step 1108-2 is yes, it means that all entries in the hash table have been traversed, then step 1109 is executed to push the aging message; if the result of step 1108-2 is no, it means that the entries in the hash table have not been traversed, then step 1102 is executed.
[0464] Based on the process shown in Figure 11, by designing a connection-tracking-based five-tuple aging and reporting mechanism, the problem of not being aware of subsequent tagging status after data flows into hardware acceleration can be solved. In this way, the router can effectively clear obsolete entries in the hash table without frequent interaction with the terminal device. That is, even if the terminal device does not send a deletion message to the router after an abnormal disconnection from the router, the router can still promptly clear obsolete entries in the hash table through the aforementioned connection-tracking-based five-tuple aging and reporting mechanism.
[0465] The method for message forwarding provided by the embodiments of this application has been described in detail above with reference to Figures 1A to 11. The apparatus embodiments of this application will be described in detail below with reference to Figures 12 and 13. It should be understood that the apparatus for message forwarding in the embodiments of this application can execute the various management thread methods described in the foregoing embodiments of this application; that is, the specific working processes of the various products described below can be referred to the corresponding processes in the foregoing method embodiments.
[0466] Figure 12 is a schematic block diagram of a packet forwarding apparatus 1400 according to an embodiment of this application. It should be understood that the apparatus 1400 can perform the packet forwarding methods shown in Figures 3 to 11.
[0467] As shown in Figure 12, the device 1400 for message forwarding includes a communication unit 1410 and a processing unit 1420. The device 1400 supports hardware acceleration. In one possible example, the device 1400 may be a router.
[0468] In some embodiments, the communication unit 1410 is configured to receive a first message from a terminal device, the first message including one or more of the following parameters: message type parameter, number of quintuple information, n quintuple information; n is an integer greater than or equal to 1; the processing unit 1420 is configured to perform management on a hash table according to the message type of the first message, the management operation including at least adding the n quintuple information; the processing unit 1420 is further configured to determine whether the data stream corresponding to the k-th quintuple information has entered hard acceleration when the n quintuple information has been added to the hash table, the k-th quintuple information being the quintuple information among the n quintuple information; the processing unit 1420 is further configured to delete the hard acceleration entry corresponding to the k-th quintuple information when the data stream corresponding to the k-th quintuple information has already entered hard acceleration; the processing unit 1420 is further configured to perform a DSCP marking process on the acquired packet to be forwarded, the packet to be forwarded including at least the packet corresponding to the k-th quintuple information.
[0469] Optionally, as an embodiment, the processing unit 1420 is further configured to perform a match in the hash table using the kth quintuple information; wherein, the processing unit 1420 is configured to determine whether the data stream corresponding to the kth quintuple information enters the hard acceleration, including: if no entry corresponding to the kth quintuple information is matched in the hash table, adding an entry corresponding to the kth quintuple information to the hash table, and determining whether the data stream corresponding to the kth quintuple information enters the hard acceleration.
[0470] Optionally, as an embodiment, the processing unit 1420 for determining whether the data stream corresponding to the k-th quintuple information enters hard acceleration further includes: if an entry corresponding to the k-th quintuple information is matched in the hash table, determining whether DSCP marking has been performed on the first entry based on the state parameter of the first entry, wherein the first entry corresponds to the k-th quintuple information; and if the state parameter of the first entry indicates that DSCP marking has not been performed on the first entry, determining whether the data stream corresponding to the k-th quintuple information enters hard acceleration.
[0471] Optionally, as an embodiment, the processing unit 1420 is further configured to update the time parameter corresponding to the first entry to the current time when the entry corresponding to the k-th quintuple information is matched in the hash table, wherein the time parameter is used to characterize the active time of the first entry.
[0472] Optionally, as an embodiment, the hash table uses a hash bucket, and the hash key of the hash bucket is a triplet; wherein, the upper limit of the hash index of the hash bucket is half of the maximum number of table entries that the data forwarding device can manage.
[0473] Optionally, as an embodiment, the processing unit 1420 is configured to perform a match in the hash table using the k-th quintuple information, including:
[0474] Calculate the first hash index based on the triplet information in the k-th quintuple information;
[0475] Using the first hash index, the linked list corresponding to the first hash index is searched in the hash table, and the triplet information is matched in the linked list.
[0476] Optionally, as an embodiment, the processing unit 1420 is used to perform a DSCP marking process on the acquired message to be forwarded, including:
[0477] Obtain the packet to be forwarded through the forwarding link hook function;
[0478] Based on the triplet information corresponding to the message to be forwarded, determine whether the message to be forwarded is a message to be accelerated;
[0479] If the message to be forwarded is a message to be accelerated, determine whether the DSCP value of the message to be forwarded is the first value;
[0480] If the DSCP value of the message to be forwarded is not the first value, the DSCP value of the message to be forwarded shall be modified to the first value.
[0481] Optionally, as an embodiment, the processing unit 1420 is configured to determine whether the packet to be forwarded is a packet to be accelerated based on the triplet information corresponding to the packet to be forwarded, including:
[0482] Calculate the second hash index based on the triplet information corresponding to the message to be forwarded;
[0483] Using the second hash index, the linked list corresponding to the second hash index is searched in the hash table, and a match is made in the linked list corresponding to the second hash index.
[0484] If a second entry is matched in the linked list corresponding to the second hash index, the message to be forwarded is determined to be a message to be accelerated.
[0485] Optionally, as an embodiment, the packet to be forwarded is a TCP packet; the DSCP value of the packet to be forwarded is a first value; the processing unit 1420 is further configured to:
[0486] Whether to terminate the connection is determined based on the first flag bit, which is determined based on the second flag bit carried in the TCP packet. The second flag bit is used to indicate whether to reset or terminate the connection corresponding to the packet to be forwarded.
[0487] If the connection is terminated based on the first flag, the status parameter corresponding to the second entry is not modified. The status parameter corresponding to the second entry is a second value, which indicates that the connection corresponding to the packet to be forwarded is terminated.
[0488] If it is determined that the connection will not be terminated based on the first flag, the status parameter corresponding to the second entry is modified to a third value, which indicates that the DSCP marking process has been executed.
[0489] Optionally, as an embodiment, the processing unit 1420 is further configured to determine whether the message to be forwarded is a downlink message before determining whether the message to be forwarded is a message to be accelerated based on the triplet information corresponding to the message to be forwarded; if the message to be forwarded is a downlink message, determine the type of the downlink message; and determine the triplet information corresponding to the message to be forwarded based on the type of the downlink message.
[0490] Optionally, as an embodiment, the processing unit 1420 is further configured to acquire connection tracking events based on a connection tracking mechanism;
[0491] If the connection tracking event is a destruction event, obtain the quintuple information corresponding to the destruction event;
[0492] Matching is performed in the hash table based on the quintuple information corresponding to the destruction event;
[0493] A third entry was matched in the hash table;
[0494] If the third entry meets the deletion condition, the third entry is deleted from the hash table, and an aging message is sent to the terminal device. The aging message includes the quintuple information corresponding to the third entry.
[0495] Optionally, as an embodiment, the third entry satisfies the deletion conditions, including: the time interval between the time parameter corresponding to the third entry and the current time is greater than a first preset duration; the status parameter corresponding to the third entry takes the value of a second value or a fourth value, where the second value indicates the termination of the connection corresponding to the current message, and the fourth value indicates that the hash node was not marked with DSCP after its establishment.
[0496] Optionally, as an embodiment, the destruction events include: timeout destruction events, TCP data stream termination destruction events, and instruction destruction events.
[0497] Optionally, as an embodiment, the processing unit 1420, configured to manage the hash table according to the message type of the first message, further includes:
[0498] If the message type of the first message is a batch add message, then the n quintuples are added in batch to the hash table; or...
[0499] If the message type of the first message is a batch deletion message, then the n quintuples are deleted in batch from the hash table; or...
[0500] If the message type of the first message is a deletion message based on terminal IP, then n quintuples of information are deleted in batches from the hash table based on the terminal IP.
[0501] It should be understood that when the device 1400 is a router, the communication unit 1410 in the device 1400 can be implemented by a transceiver, for example, corresponding to the transceiver 1520 in the device 1500 shown in FIG. 13. The processing unit 1420 in the device 1400 can be implemented by at least one processor, for example, corresponding to the processor 1510 in the communication device 1500 shown in FIG. 13.
[0502] It should also be understood that when the device 1400 is a chip or chip system configured in the router, the communication unit 1410 in the device 1400 can be implemented through an input / output interface, and the processing unit 1420 in the device 1400 can be implemented through a processor, microprocessor or integrated circuit integrated on the chip or chip system.
[0503] In one possible design, the device 1400 may correspond to the router in the above method embodiments, or a component (such as a circuit, chip, or chip system) configured in the router.
[0504] It should be understood that the aforementioned device 1400 is embodied in the form of a functional unit. The term "unit" here can be implemented in the form of software and / or hardware, and this application embodiment does not specifically limit this.
[0505] For example, a "unit" can be a software program, a hardware circuit, or a combination of both that implements the above functions. The hardware circuit may include an application-specific integrated circuit (ASIC), electronic circuits, a processor (e.g., a shared processor, a proprietary processor, or a group processor) and memory that executes one or more software or firmware programs, integrated logic circuits, and / or other suitable devices that can provide the above functions.
[0506] Figure 13 is another schematic block diagram of a message forwarding device 1500 provided in an embodiment of this application. As shown in Figure 13, the device 1500 includes a processor 1510, a transceiver 1520, and a memory 1530. The processor 1510, transceiver 1520, and memory 1530 communicate with each other via internal interconnection paths. The memory 1530 stores instructions, and the processor 1510 executes the instructions stored in the memory 1530 to control the transceiver 1520 to transmit and / or receive signals.
[0507] Optionally, the memory 1530 may include read-only memory and random access memory, and provide instructions and data to the processor. A portion of the memory may also include non-volatile random access memory. The memory 1530 may be a separate device or integrated into the processor 1510.
[0508] In one implementation, the device 1500 may correspond to the router in the above method embodiments and may be used to execute the various steps and / or processes executed by the router in the above method embodiments. The processor 1510 may be used to execute instructions stored in the memory 1530, and when the processor 1510 executes the instructions stored in the memory, the processor 1510 is used to execute the various steps and / or processes of the above method embodiments corresponding to the router.
[0509] In one possible design, the processor 1510 can be used to invoke the transceiver 1520 to receive a first message from a terminal device. The first message includes one or more of the following parameters: a message type parameter, the number of quintuples, and n quintuples; where n is an integer greater than or equal to 1. Subsequently, the processor 1510 can also be used to manage a hash table according to the message type of the first message, the management operation including at least adding the n quintuples. Then, the processor 1510 can further be used to add the n quintuples to the hash table. In the case of quintuple information, determine whether the data stream corresponding to the k-th quintuple information has entered hardware acceleration, wherein the k-th quintuple information is the quintuple information in the n quintuple information; then, the processor 1510 can also be used to delete the hardware acceleration entry corresponding to the k-th quintuple information if the data stream corresponding to the k-th quintuple information has already entered hardware acceleration; finally, the processor 1510 can also be used to perform a DSCP marking process on the acquired packet to be forwarded, wherein the packet to be forwarded includes at least the packet corresponding to the k-th quintuple information.
[0510] Transceiver 1520 may include a transmitter and a receiver. Transceiver 1520 may further include antennas, and the number of antennas may be one or more. The processor 1510 and memory 1530 may be integrated with transceiver 1520 on different chips. For example, processor 1510 and memory 1530 may be integrated in a baseband chip, and transceiver 1520 may be integrated in a radio frequency chip. Alternatively, processor 1510 and memory 1530 may be integrated with transceiver 1520 on the same chip. This application does not limit this.
[0511] The transceiver 1520 can also be a communication interface, such as an input / output interface. The transceiver 1520 can be integrated into the same chip as the processor 1510 and the memory 1530.
[0512] It should be understood that the processor in the embodiments of this application can be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method embodiments can be completed by the integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, a system-on-a-chip (SoC), a central processing unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD), or other integrated chips. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of this application can be directly manifested as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0513] The technologies described in this application can be implemented in various ways. For example, these technologies can be implemented in hardware, software, or a combination of hardware. For hardware implementation, the processing unit for executing these technologies at a communication device (e.g., a base station, terminal, network entity, or chip) can be implemented in one or more general-purpose processors, DSPs, digital signal processing devices, ASICs, programmable logic devices, FPGAs, or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination thereof. The general-purpose processor can be a microprocessor; alternatively, it can also be any conventional processor, controller, microcontroller, or state machine. The processor can also be implemented through a combination of computing devices, such as a digital signal processor and a microprocessor, multiple microprocessors, one or more microprocessors combined with a digital signal processor core, or any other similar configuration.
[0514] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0515] This application also provides a computer program product that, when executed by a processor, implements the methods described in any of the method embodiments of this application.
[0516] The computer program product can be stored in memory and, after processes such as preprocessing, compilation, assembly, and linking, is finally converted into an executable object file that can be executed by a processor.
[0517] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a computer, implements the methods described in any of the method embodiments of this application. The computer program may be a high-level language program or an executable object program.
[0518] The computer-readable storage medium can be volatile memory or non-volatile memory, or it can include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0519] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0520] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0521] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0522] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0523] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0524] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0525] It should be understood that in the various embodiments of this application, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0526] Furthermore, the terms "system" and "network" are often used interchangeably in this paper. The term "and / or" in this paper merely describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. Additionally, the character " / " in this paper generally indicates that the preceding and following related objects have an "or" relationship. For example, A / B can represent A or B.
[0527] The terms (or numbers) "first," "second," etc., appearing in the embodiments of this application are for descriptive purposes only, that is, only to distinguish different objects, such as different "table items," etc., and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first," "second," etc., may explicitly or implicitly include one or more features. In the description of the embodiments of this application, "at least one (item)" refers to one or more. "Multiple" means two or more. "At least one (item) below" or similar expressions refer to any combination of these items, including any combination of a single (item) or a plurality of (items).
[0528] For example, expressions like "the item includes at least one of the following: A, B, and C" appearing in the embodiments of this application generally mean, unless otherwise specified, that the item can be any one of the following: A; B; C; A and B; A and C; B and C; A, B and C; A and A; A, A and A; A, A and B; A, A and C, A, B and B; A, C and C; B and B, B, B and B, B, B and C, C and C; C, C and C, and other combinations of A, B, and C. The above uses three elements, A, B, and C, as examples to illustrate the possible entries for the item. When expressed as "the item includes at least one of the following: A, B, ..., and X," that is, when the expression contains more elements, then the applicable entries for the item can also be obtained according to the aforementioned rules.
[0529] In summary, the above description is merely a preferred embodiment of the technical solution of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for message forwarding, characterized in that, The method is applied to a data forwarding device, wherein hardware acceleration is supported in the data forwarding process. The method includes: receiving a first message from a terminal device, the first message including one or more of the following parameters: message type parameter, number of quintuples, n quintuples; n is an integer greater than or equal to 1; managing a hash table according to the message type of the first message, the management operation including at least adding the n quintuples; when adding the n quintuples to the hash table, determining whether the data stream corresponding to the k-th quintuple has entered hardware acceleration, the k-th quintuple being one of the n quintuples; if the data stream corresponding to the k-th quintuple has already entered hardware acceleration, deleting the hardware acceleration entry corresponding to the k-th quintuple; and performing a Differentiated Services Code (DSCP) marking process on the acquired packets to be forwarded, the packets to be forwarded including at least the packets corresponding to the k-th quintuple.
2. The method according to claim 1, characterized in that, The method further includes: using the kth quintuple information to perform matching in the hash table; wherein, determining whether the data stream corresponding to the kth quintuple information enters the hard acceleration includes: if no entry corresponding to the kth quintuple information is matched in the hash table, adding an entry corresponding to the kth quintuple information to the hash table, and determining whether the data stream corresponding to the kth quintuple information enters the hard acceleration.
3. The method according to claim 2, characterized in that, The step of determining whether the data stream corresponding to the kth quintuple information enters hard acceleration further includes: when an entry corresponding to the kth quintuple information is matched in the hash table, determining whether DSCP marking has been performed on the first entry based on the state parameter of the first entry, wherein the first entry corresponds to the kth quintuple information; and determining whether the data stream corresponding to the kth quintuple information enters hard acceleration when the state parameter of the first entry indicates that DSCP marking has not been performed on the first entry.
4. The method according to claim 3, characterized in that, If the hash table matches the entry corresponding to the kth quintuple information, the method further includes: updating the time parameter corresponding to the first entry to the current time, wherein the time parameter is used to characterize the active time of the first entry.
5. The method according to any one of claims 1 to 4, characterized in that, The hash table uses hash buckets, and the hash key of the hash bucket is a triplet. The upper limit of the hash index of the hash bucket is half of the maximum number of table entries that the data forwarding device can manage.
6. The method according to any one of claims 2 to 4, characterized in that, The step of matching the k-th quintuple information in the hash table includes: calculating a first hash index based on the triple information in the k-th quintuple information; using the first hash index, searching for the linked list corresponding to the first hash index in the hash table, and matching the triple information in the linked list.
7. The method according to any one of claims 1 to 4, characterized in that, The process of performing DSCP marking on the acquired packet to be forwarded includes: obtaining the packet to be forwarded through a forwarding link hook function; determining whether the packet to be forwarded is a packet to be accelerated based on the triple information corresponding to the packet to be forwarded; if the packet to be forwarded is a packet to be accelerated, determining whether the DSCP value of the packet to be forwarded is a first value; if the DSCP value of the packet to be forwarded is not a first value, modifying the DSCP value of the packet to be forwarded to the first value.
8. The method according to claim 7, characterized in that, The step of determining whether the packet to be forwarded is a packet to be accelerated based on the triple information corresponding to the packet to be forwarded includes: calculating a second hash index based on the triple information corresponding to the packet to be forwarded; using the second hash index, searching for the linked list corresponding to the second hash index in the hash table, and matching in the linked list corresponding to the second hash index; if a second entry is matched in the linked list corresponding to the second hash index, determining that the packet to be forwarded is a packet to be accelerated.
9. The method according to claim 8, characterized in that, The packet to be forwarded is a TCP packet; the DSCP value of the packet to be forwarded is a first value; the method further includes: determining whether to terminate the connection based on a first flag bit, the first flag bit being determined based on a second flag bit carried by the TCP packet, the second flag bit being used to indicate whether to reset or terminate the connection corresponding to the packet to be forwarded; if the connection is determined to terminate based on the first flag bit, the status parameter corresponding to the second entry is not modified, the status parameter corresponding to the second entry is a second value, the second value indicating that the connection corresponding to the packet to be forwarded has been terminated; if the connection is determined not to terminate based on the first flag bit, the status parameter corresponding to the second entry is modified to a third value, the third value indicating that the DSCP marking process has been performed.
10. The method according to any one of claims 7 to 9, characterized in that, Before determining whether the message to be forwarded is a message to be accelerated based on the triple information corresponding to the message to be forwarded, the method further includes: determining whether the message to be forwarded is a downlink message; if the message to be forwarded is a downlink message, determining the type of the downlink message; and determining the triple information corresponding to the message to be forwarded based on the type of the downlink message.
11. The method according to any one of claims 1 to 10, characterized in that, The method further includes: acquiring connection tracking events based on a connection tracking mechanism; acquiring 5-tuple information corresponding to the destruction event if the connection tracking event is a destruction event; matching the 5-tuple information corresponding to the destruction event in the hash table; matching a third entry in the hash table; deleting the third entry in the hash table if the third entry meets the deletion condition, and sending an aging message to the terminal device, the aging message including the 5-tuple information corresponding to the third entry.
12. The method according to claim 11, characterized in that, The third entry meets the deletion conditions, including: the time interval between the time parameter corresponding to the third entry and the current time is greater than the first preset duration; the status parameter corresponding to the third entry takes the value of a second value or a fourth value, where the second value indicates the termination of the connection corresponding to the current message, and the fourth value indicates that the hash node was not marked with DSCP after its establishment.
13. The method according to claim 11 or 12, characterized in that, The destruction events include: timeout destruction events, TCP data stream termination destruction events, and instruction destruction events.
14. The method according to any one of claims 1 to 13, characterized in that, The step of managing the hash table according to the message type of the first message further includes: when the message type of the first message is a batch add message, adding the n quintuple information in the hash table in batch; or, when the message type of the first message is a batch delete message, deleting the n quintuple information in the hash table in batch; or, when the message type of the first message is a delete message based on the terminal IP, deleting the n quintuple information in the hash table in batch based on the terminal IP.
15. The method according to any one of claims 1 to 14, characterized in that, The data forwarding device is a router.
16. An apparatus for message forwarding, characterized in that, The device includes a processor and a memory coupled together, the memory being used to store a computer program that, when executed by the processor, causes the device to perform the method of any one of claims 1 to 15.
17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the method of any one of claims 1 to 15.
18. A chip, characterized in that, Includes a processor, which, when executing instructions, performs the method as described in any one of claims 1 to 15.
Citation Information
Patent Citations
Method for improving data forwarding performance, electronic equipment and storage medium
CN110708250A
Call establishment and maintanance in a wireless network
WO2008008990A2