CN114257545B - Message forwarding method and device - Google Patents

Message forwarding method and device Download PDF

Info

Publication number
CN114257545B
CN114257545B CN202111496154.0A CN202111496154A CN114257545B CN 114257545 B CN114257545 B CN 114257545B CN 202111496154 A CN202111496154 A CN 202111496154A CN 114257545 B CN114257545 B CN 114257545B
Authority
CN
China
Prior art keywords
message
address
gateway
port number
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111496154.0A
Other languages
Chinese (zh)
Other versions
CN114257545A (en
Inventor
于文超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202111496154.0A priority Critical patent/CN114257545B/en
Publication of CN114257545A publication Critical patent/CN114257545A/en
Application granted granted Critical
Publication of CN114257545B publication Critical patent/CN114257545B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering

Abstract

The embodiment of the invention provides a message forwarding method and a message forwarding device, which relate to the technical field of networks, and the method comprises the following steps: after receiving a message sent by user equipment, calculating a first distribution identifier of the message based on message information of the message by adopting a preset calculation mode; distributing the message to a target CPU (central processing unit) contained in the gateway corresponding to the first distribution identifier; searching a target forwarding table item matched with the message in the forwarding table item corresponding to the target CPU; if the message is not stored in the idle address table corresponding to the target CPU, acquiring a table item from the idle address table corresponding to the target CPU, configuring a target forwarding table item containing message information, server information and gateway information recorded in the acquired table item for the target CPU, forwarding the message to a server based on the target forwarding table item, so that the server processes the message and sends a feedback message; after receiving the feedback message, the message is forwarded to the user equipment. By applying the scheme provided by the embodiment of the invention, the efficiency of message forwarding can be improved.

Description

Message forwarding method and device
Technical Field
The present invention relates to the field of network technologies, and in particular, to a method and an apparatus for forwarding a message.
Background
The user equipment may interact with the server to obtain data from the server or to process data through the server. In the prior art, a gateway can be configured between user equipment and a server, so that the gateway can assist data interaction between the user equipment and the server.
Specifically, the ue may send the first packet to the gateway, modify information of the first packet based on a target forwarding table entry matched with the first packet, for example, modify a destination address of the first packet to an address of the server, and forward the first packet to the server. After finishing the data processing, the server sends a second message fed back to the user equipment to the gateway, wherein the first message and the second message are a group of messages transmitted in two directions, the gateway modifies the message information of the second message based on the target forwarding table item, for example, modifies the destination address of the second message into the address of the user equipment, and forwards the second message to the user equipment, thereby finishing the data interaction process between the user equipment and the server. For the message transmitted in two directions, the gateway completes the process of forwarding the message based on the same forwarding table item.
However, if multiple CPUs are configured in the gateway, the gateway may forward different messages based on different CPUs, so that the processing efficiency of the gateway may be improved, and forwarding entries that different CPUs may use are different. Specifically, the gateway may distribute the message to the matched CPU for forwarding based on the message information, but because the gateway modifies the message information when forwarding the message, the message sent by the user equipment to the gateway is different from the message fed back by the server, so that two messages transmitted in two directions may be distributed to different CPUs. Because the forwarding table items which can be used by different CPUs are different, the message transmitted in two directions needs to be forwarded based on the same forwarding table item, and in order to complete the message forwarding process, data interaction between the different CPUs is possibly needed, so that the processing resources of the CPUs are wasted, and the problem of low message forwarding efficiency is caused.
Disclosure of Invention
The embodiment of the invention aims to provide a message forwarding method and device so as to improve the efficiency of message forwarding. The specific technical scheme is as follows:
in a first aspect of the embodiment of the present invention, there is first provided a method for forwarding a packet, applied to a gateway, where the method includes:
after receiving a message sent by user equipment, calculating a first distribution identifier of the message based on message information of the message by adopting a preset calculation mode, wherein the message information comprises: the source address, the source port number, the destination address and the destination port number of the message, wherein the source address is the address of the user equipment, the source port number is the port number of the user equipment, the destination address is the virtual address of the gateway, and the destination port number is the virtual port number of the gateway;
distributing the message to a target CPU (central processing unit) contained in the gateway and corresponding to the first distribution identifier;
searching a target forwarding table item matched with the message in the forwarding table item corresponding to the target CPU;
if there is no target forwarding table item matched with the message, acquiring a table item from an idle address table corresponding to the target CPU, and configuring a target forwarding table item containing the message information and server information and gateway information recorded in the acquired table item for the target CPU, wherein the server information and gateway information recorded in each table item contained in the idle address table are calculated by adopting the preset calculation mode, so that an allocation identifier corresponding to the target CPU can be obtained by calculation, and the server information comprises: the real address and the real port number of the server, and the gateway information comprises: the local address and the local port number of the gateway;
Forwarding a message to the server based on the target forwarding table item, so that the server processes the message and sends a feedback message, wherein a destination address, a destination port number, a source address and a source port number of the feedback message are respectively as follows: the source address, the source port number, the destination address and the destination port number of the message;
after the feedback message is received, calculating a second allocation identifier of the feedback message based on the message information of the feedback message by adopting the preset calculation mode, allocating the feedback message to a CPU (central processing unit) corresponding to the second allocation identifier, and forwarding the message to the user equipment based on a forwarding table item which corresponds to the allocated CPU and is matched with the feedback message.
In one embodiment of the present invention, for each CPU included in the gateway, an entry in a free address table corresponding to the CPU is generated by:
calculating server information and gateway information which can be used by the CPU by adopting the preset calculation mode to obtain a calculation result;
and selecting a target information group, and generating a table item containing the target information group, wherein the calculation result of server information and gateway information contained in the target information group is an allocation identifier corresponding to the CPU.
In one embodiment of the present invention, the obtaining an entry from the idle address table corresponding to the target CPU includes:
selecting a set of target server information from server information that can be used by the target CPU;
and acquiring an item containing the target server information from the idle address table corresponding to the target CPU.
In one embodiment of the invention, the method further comprises:
and deleting the list item of the deleted server information or gateway information recorded in the idle address list corresponding to each CPU after deleting the server information and/or gateway information which can be used by the CPU.
In one embodiment of the invention, the method further comprises:
if the session between the gateway and the server is overtime, deleting forwarding table items corresponding to each CPU and recorded with server information of the server;
and/or
And if the session between the user equipment and the gateway is overtime, deleting forwarding table items corresponding to the CPUs and recorded with the address of the user equipment.
In one embodiment of the present invention, for each CPU, a free address table is provided, where the number of entries included in the free address table is above a first threshold and/or below a second threshold.
In a second aspect of the embodiment of the present invention, there is also provided a packet forwarding device, applied to a gateway, where the device includes:
the device comprises an identification calculation module, a message distribution module and a message distribution module, wherein the identification calculation module is used for calculating a first distribution identification of a message based on message information of the message by adopting a preset calculation mode after receiving the message sent by user equipment, and the message information comprises: the source address, the source port number, the destination address and the destination port number of the message, wherein the source address is the address of the user equipment, the source port number is the port number of the user equipment, the destination address is the virtual address of the gateway, and the destination port number is the virtual port number of the gateway;
the message distribution module is used for distributing the message to a target CPU (central processing unit) contained in the gateway and corresponding to the first distribution identifier;
the table item searching module is used for searching a forwarding table item matched with the message in the forwarding table item corresponding to the target CPU;
the table entry configuration module is configured to obtain a table entry from an idle address table corresponding to the target CPU if there is no target forwarding table entry matching the message, and configure, for the target CPU, a target forwarding table entry including the message information and server information and gateway information recorded in the obtained table entry, where the server information and gateway information recorded in each table entry included in the idle address table are calculated by using the preset calculation method, and each allocation identifier corresponding to the target CPU can be calculated, and the server information includes: the real address and the real port number of the server, and the gateway information comprises: the local address and the local port number of the gateway;
The first message forwarding module is configured to forward a message to the server based on the target forwarding table entry, so that the server processes the message and sends a feedback message, where a destination address, a destination port number, a source address, and a source port number of the feedback message are respectively: the source address, the source port number, the destination address and the destination port number of the message;
and the second message forwarding module is used for calculating a second distribution identifier of the feedback message based on the message information of the feedback message by adopting the preset calculation mode after receiving the feedback message, distributing the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier, and forwarding the message to the user equipment based on a forwarding table item which corresponds to the distributed CPU and is matched with the feedback message.
In one embodiment of the invention, the apparatus further comprises: the table entry generating module is configured to generate, for each CPU included in the gateway, an entry in a free address table corresponding to the CPU by:
calculating server information and gateway information which can be used by the CPU by adopting the preset calculation mode to obtain a calculation result;
And selecting a target information group, and generating a table item containing the target information group, wherein the calculation result of server information and gateway information contained in the target information group is an allocation identifier corresponding to the CPU.
In one embodiment of the present invention, the table entry configuration module is specifically configured to:
if no forwarding table item matched with the message exists, selecting a group of target server information from server information which can be used by the target CPU;
acquiring an item containing the target server information from an idle address table corresponding to the target CPU;
and configuring a forwarding table item containing the message information, the server information and the gateway information recorded in the acquired table item for the target CPU.
In one embodiment of the invention, the apparatus further comprises:
and the table item deleting module is used for deleting the table item recorded with the deleted server information or gateway information in the idle address table corresponding to the CPU after deleting the server information and/or gateway information which can be used by the CPU for each CPU.
In one embodiment of the invention, the apparatus further comprises:
a forwarding table item deleting module, configured to delete forwarding table items corresponding to each CPU and recording server information of the server if a session between the gateway and the server is overtime;
And/or
And if the session between the user equipment and the gateway is overtime, deleting forwarding table items corresponding to the CPUs and recorded with the address of the user equipment.
In one embodiment of the present invention, for each CPU, a free address table is provided, where the number of entries included in the free address table is above a first threshold and/or below a second threshold.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of the first aspects when executing a program stored on a memory.
In a fourth aspect, in a further aspect of the embodiments of the present invention, there is also provided a computer-readable storage medium having stored therein a computer program which, when executed by a processor, implements the method steps of any of the first aspects described above.
In a fifth aspect, in a further aspect of embodiments of the present invention, there is also provided a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method steps of any of the first aspects described above.
According to the message forwarding method provided by the embodiment of the invention, after receiving the message sent by the user equipment, the gateway calculates the distribution identification of the message by adopting a preset calculation mode based on the message information of the message; distributing the message to a target CPU (Central processing Unit) contained in the gateway and corresponding to the first distribution identifier; searching a target forwarding table item matched with the message in the forwarding table item corresponding to the target CPU; if no target forwarding table item matched with the message exists, acquiring a table item from an idle address table corresponding to the CPU, and configuring a forwarding table item containing the message information and server information and gateway information recorded in the acquired table item for the target CPU, wherein the server information and gateway information recorded in each table item contained in the idle address table are calculated by adopting the preset calculation mode, and a first allocation identifier corresponding to the target CPU can be calculated; the configuration record is recorded for the target CPU: and forwarding the message based on the forwarding table item matched with the message, so that the server processes the message and sends a feedback message, wherein the destination address, the destination port number, the source address and the source port number of the feedback message are respectively the source address, the source port number, the destination address and the destination port number of the message. After receiving the feedback message, calculating a second allocation identifier of the feedback message based on the message information of the feedback message by adopting a preset calculation mode, allocating the feedback message to a CPU corresponding to the second allocation identifier, and forwarding the message to the user equipment based on a forwarding table item label forwarding table item which corresponds to the CPU allocated to the destination and is matched with the feedback message.
From the above, when the gateway does not include the forwarding table entry matched with the message, the embodiment of the invention can configure the forwarding table entry recorded with the message information, the gateway information and the server information. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1A is a schematic flow chart of a first packet forwarding method according to an embodiment of the present application;
fig. 1B is a schematic diagram of a single-arm gateway according to an embodiment of the present application;
fig. 1C is a schematic diagram of a dual-arm gateway according to an embodiment of the present application;
fig. 2 is a flow chart of a second message forwarding method provided in an embodiment of the present application;
fig. 3 is a flow chart of a third message forwarding method provided in an embodiment of the present application;
fig. 4 is a flow chart of a fourth message forwarding method provided in an embodiment of the present application;
fig. 5 is a flow chart of a fifth packet forwarding method according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a message forwarding device according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. Based on the embodiments of the present application, all other embodiments obtained by the person skilled in the art based on the present application are included in the scope of protection of the present application.
In the prior art, the gateway needs to perform data interaction between different CPUs in the process of forwarding the message, so that the processing resources of the CPUs are wasted, and the problem of low message forwarding efficiency is caused. In order to solve the problem, the embodiment of the invention provides a message forwarding method and device.
The embodiment of the invention provides a message forwarding method, which is applied to a gateway and comprises the following steps:
after receiving a message sent by user equipment, calculating a first distribution identifier of the message by adopting a preset calculation mode based on message information of the message, wherein the message information comprises: the source address, the source port number, the destination address and the destination port number of the message, wherein the source address is the address of the user equipment, the source port number is the port number of the user equipment, the destination address is the virtual address of the gateway, and the destination port number is the virtual port number of the gateway;
distributing the message to a target CPU (Central processing Unit) contained in the gateway and corresponding to the first distribution identifier;
searching a target forwarding table item matched with the message in the forwarding table item corresponding to the target CPU;
If there is no target forwarding table item matched with the message, acquiring a table item from an idle address table corresponding to the target CPU, and configuring a target forwarding table item containing the message information and server information and gateway information recorded in the acquired table item for the target CPU, wherein the server information and gateway information recorded in each table item contained in the idle address table are calculated by adopting the preset calculation mode, so that a first allocation identifier corresponding to the target CPU can be obtained, and the server information comprises: the gateway information includes the real address and the real port number of the server: the local address and the local port number of the gateway;
and forwarding a message to the server based on the target forwarding table item, so that the server processes the message and sends a feedback message, wherein a destination address, a destination port number, a source address and a source port number of the feedback message are respectively as follows: the source address, the source port number, the destination address and the destination port number of the message;
after the feedback message is received, calculating a second allocation identifier of the feedback message based on the message information of the feedback message by adopting the preset calculation mode, allocating the feedback message to a CPU corresponding to the second allocation identifier, and forwarding the message to the user equipment based on a forwarding table item corresponding to the allocated CPU and matched with the feedback message.
From the above, when the gateway does not include the forwarding table entry matched with the message, the embodiment of the invention can configure the forwarding table entry recorded with the message information, the gateway information and the server information. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
Referring to fig. 1A, a flow chart of a first packet forwarding method provided by an embodiment of the present invention is applied to a gateway, where the gateway may be a FullNAT (Full Network Address Translation ) gateway.
Specifically, when the user equipment sends a message to the gateway, the source address and the source port number of the message are the address and the port number of the user equipment, and the destination address and the destination port number of the message are the virtual address and the virtual port number provided to the user equipment by the gateway. After receiving the message sent by the user equipment, the gateway can modify the source address and the source port number of the message into the local address and the local port number of the gateway based on the forwarding table entry, modify the destination address and the destination port number of the message into the real address and the real port number of the server, and forward the message to the server. The gateway has a plurality of groups of available local addresses and local port numbers.
After the server processes the received message, it needs to send the feedback message to the gateway, contrary to the message received by the server, the source address and the source port number of the feedback message are the real address and the real port number of the server, and the destination address and the destination port number of the feedback message are the local address and the local port number of the gateway recorded in the received message. After receiving the feedback message, the gateway modifies the source address and the source port number of the feedback message into the own virtual address and virtual port number according to the forwarding table entry, modifies the destination address and the destination port number into the address and the port number of the user equipment, and forwards the message to the user equipment.
In the process, the server and the user equipment do not need to obtain the port number and the address of the other party, and the process of message forwarding can be completed.
In addition, for the gateway, a message sent by the user equipment to the server may be referred to as an enqueue message, and a message sent by the server to the user equipment may be referred to as an dequeue enqueue message.
Referring to fig. 1B, a schematic diagram of a single-arm gateway according to an embodiment of the present invention is provided.
The user equipment connected with the single-arm gateway and the server are in the same network, a solid arrow in the figure represents a forwarding path of an inbound message sent by the user equipment to the server, and a dotted arrow in the figure represents a forwarding path of an outbound message sent by the server to the user equipment. The single-arm gateway comprises a network card 1, the address of the user equipment is cip, the user equipment can send an inbound message to the gateway based on the virtual address vip, the gateway can update the address of the message to a local address lip based on a forwarding table item recorded in a forwarding table, update the destination address of the message to the real address rip of the server, and send the inbound message to the server.
The forwarding table 1 records cip1, vip1, lip1 and rip1, the forwarding table 2 records cip2, vip2, lip2 and rip2, and the forwarding table n records cipn, vipn, lipn and rip.
The server may feed back the outbound message to the gateway based on the lip, the gateway updates the destination address of the outbound message to the cip of the user equipment based on the forwarding table entry in the forwarding table, updates the source address to the vip of the gateway, and forwards the outbound message to the user equipment. Thus realizing the bidirectional message forwarding process between the user equipment and the server.
The specific message forwarding flow involved in this embodiment may be referred to below, and will not be described in detail herein.
Referring to fig. 1C, a schematic diagram of a dual-arm gateway according to an embodiment of the present invention is provided.
The user equipment and the server connected with the dual-arm gateway are in different networks, solid arrows in the figure indicate forwarding paths of inbounds messages sent by the user equipment to the server, and dashed arrows in the figure indicate forwarding paths of outbound messages sent by the server to the user equipment. The dual-arm gateway comprises a plurality of network cards, wherein the network cards are a network card 1 and a network card 2, the network card 1 performs message interaction with user equipment, and the network card 2 is used for performing data interaction with a server. The address of the user equipment is cip, the user equipment can send an inbound message to the gateway based on the virtual address vip, the gateway can update the address of the message to a local address lip based on a forwarding table item recorded in a forwarding table, update the destination address of the message to the real address rip of the server, and send the inbound message to the server.
The forwarding table 1 records cip1, vip1, lip1 and rip1, the forwarding table 2 records cip2, vip2, lip2 and rip2, and the forwarding table n records cipn, vipn, lipn and rip.
The server may feed back the outbound message to the gateway based on the lip, the gateway updates the destination address of the outbound message to the cip of the user equipment based on the forwarding table entry in the forwarding table, updates the source address to the vip of the gateway, and forwards the outbound message to the user equipment. Thus realizing the bidirectional message forwarding process between the user equipment and the server.
The specific message forwarding flow involved in this embodiment may be referred to below, and will not be described in detail herein.
The gateway may be referred to as a single-arm gateway and if the user equipment and the server are in different networks, the gateway may be referred to as a dual-arm gateway.
The embodiment shown in fig. 1A includes the following steps S101-S106.
S101: after receiving a message sent by the user equipment, calculating a first distribution identifier of the message based on the message information of the message by adopting a preset calculation mode.
Wherein, the message information comprises: the source address, the source port number, the destination address and the destination port number of the message. The source address is an address of the user equipment, the source port number is a port number of the user equipment, the destination address is a virtual address of the gateway, and the destination port number is a virtual port number of the gateway.
In addition, the message information may further include a protocol number.
Specifically, the gateway may calculate the allocation identifier through a logic circuit of its own hardware layer.
In one embodiment of the present invention, the allocation identities described above may be calculated based on an RSS algorithm.
Specifically, a hash value of the source address, the source port number, the destination address, the destination port number, and the protocol number may be calculated, and a preset number of low-order bits of the hash value may be determined as the first allocation identifier.
S102: and distributing the message to a target CPU (Central processing Unit) contained in the gateway and corresponding to the first distribution identifier.
Specifically, the gateway may store a RETA table, each entry in the RETA table records an allocation identifier and an identifier of a corresponding CPU, after calculating to obtain a first allocation identifier, the RETA table may be searched to determine the identifier of the CPU corresponding to the first allocation identifier, the message may be allocated to a queue in a memory corresponding to the target CPU indicated by the searched identifier, and the target CPU may extract the message from the queue corresponding to the target CPU and process the message.
In addition, after the software layer can have work modules which are bound with different CPUs one by one and the message is distributed to the target CPU, the work modules corresponding to the target CPU can process the message.
S103: and searching a target forwarding table item matched with the message in the forwarding table item corresponding to the target CPU.
Specifically, different CPUs correspond to different forwarding table entries, and the forwarding table entry recorded with at least one of a source address, a source port number, a destination address and a destination port number of the message can be searched from the forwarding table entries corresponding to the target CPU and used as a target forwarding table entry matched with the message.
Each forwarding table entry records an address and a port number of the user equipment, a virtual address and a virtual port number of the gateway, a local address and a local port number of the gateway, and a real address and a real port number of the server.
If the target forwarding table entry can be found, step S105 may be directly performed. Otherwise, the steps S104-S105 are continued.
S104: if the target forwarding table item matched with the message does not exist, acquiring a table item from an idle address table corresponding to the target CPU, and configuring the target forwarding table item containing the message information and the server information and gateway information recorded in the acquired table item for the target CPU.
And calculating the server information and the gateway information recorded in each table entry contained in the idle address table by adopting the preset calculation mode, so that the allocation identifier corresponding to the target CPU can be obtained by calculation. The server information includes: the gateway information includes the real address and the real port number of the server: the local address and the local port number of the gateway.
Specifically, each CPU corresponds to an idle address table, and the worker corresponding to the CPU may call the idle address table corresponding to the CPU. A group of server information and a group of gateway information are recorded in each table entry contained in the free address table.
In one embodiment of the present invention, for each CPU, an entry in the free address table corresponding to the CPU may be generated by the following steps a-B. The gateway can generate entries in idle address tables corresponding to CPUs through a control module master of a software layer, the master is a software module which is arranged in the gateway and is used for managing idle address tables configured by the works and forwarding entries, namely the gateway comprises a plurality of works and a master, the master can calculate different gateway information and service information according to steps A-B based on a preset calculation mode respectively to obtain different allocation identifiers, and then for each CPU, gateway information and server information which are matched with the calculated allocation identifiers and the CPU are added into the idle address tables corresponding to the CPUs as entries.
Step A: and calculating the server information and the gateway information which can be used by the CPU by adopting the preset calculation mode to obtain a calculation result.
Specifically, the preset calculation mode used in the process of generating the table items in the idle address table is the same as the calculation mode used when the gateway distributes the CPU for the message after receiving the message.
The server information and the gateway information which can be used by each CPU are preset known information, the CPU can select the server information from the server information which can be used, and then the selected server information and each gateway information are respectively calculated to obtain a calculation result.
In an embodiment of the present invention, if the preset calculation mode is an RSS algorithm, the gateway information, the server information and the known protocol number may be calculated by using the RSS algorithm, so as to obtain a calculation result.
And (B) step (B): and selecting a target information group and generating an item containing the target information group.
And the calculation result of the server information and the gateway information contained in the target information group is an allocation identifier corresponding to the CPU.
Specifically, the calculation results obtained by calculating different server information and gateway information are different, the server information and gateway information with calculation results being the allocation identifiers corresponding to the CPUs can be selected as target information groups, and the target information groups are written into the idle address tables corresponding to the CPUs as table entries, so that the calculation of the server information and gateway information in each table entry recorded in the idle address tables can be ensured, and the obtained calculation results are the allocation identifiers corresponding to the CPUs.
In addition, after the table entry is acquired from the idle address table, the acquired table entry may be deleted, and then when the forwarding table entry is configured for the target CPU next time, the table entry is not acquired again, and the forwarding table entry is generated based on the acquired table entry, so that server information and gateway information recorded in the forwarding table entry generated each time may be different.
In addition, the message information recorded in the configured forwarding table entry is: the address and port number of the user equipment sending the message, the virtual address and virtual port number of the gateway. The server information is the real address and real port number of the server recorded in the table entry in the selected free address table, and the gateway information is the local address and local port number of the gateway recorded in the table entry in the selected free address table.
S105: and forwarding the message to the server based on the target forwarding table item, so that the server processes the message and sends a feedback message.
The destination address, the destination port number, the source address and the source port number of the feedback message are respectively: the source address, the source port number, the destination address and the destination port number of the message.
If there is a forwarding table entry matching with the message, the message may be forwarded based on the found forwarding table entry, and if there is no forwarding table entry matching with the message, after configuring the forwarding table entry in step S104, the gateway may forward the message based on the configured forwarding table entry, specifically, the gateway may modify the source address and the source port number of the message into a local address and a local port number carried in the forwarding table entry, modify the destination address and the destination port number of the message into a real address and a real port number of the server, and forward the message.
After receiving the message, the server processes the message to generate a feedback message, and the feedback message is opposite to the message sent to the server by the gateway, wherein the source address and the source port number of the feedback message are the destination address and the destination port number of the message, that is, the real address and the real port number of the server, and the destination address and the destination port number of the feedback message are the source address and the source port number of the message, that is, the local address and the local port number of the gateway, so that the server can send the feedback message to the gateway based on the local address and the local port number of the gateway.
S106: after the feedback message is received, calculating a second allocation identifier of the feedback message based on the message information of the feedback message by adopting the preset calculation mode, allocating the feedback message to a CPU corresponding to the second allocation identifier, and forwarding the message to the user equipment based on a forwarding table item corresponding to the allocated CPU and matched with the feedback message.
Specifically, after receiving the feedback packet, the gateway may calculate the source address, the source port number, the destination address and the destination port number of the feedback packet based on a preset calculation mode to obtain a second allocation identifier, where the source address, the source port number, the destination address and the destination port number are information recorded in an entry in the idle address table selected in the step S104, and therefore the calculated second allocation identifier corresponds to the target CPU. The feedback message is distributed to the target CPU. And because the source address, the source port number, the destination address and the destination port number of the feedback message are respectively the real address, the real port number, the local address and the local port number recorded in the destination forwarding table entry, the feedback message is matched with the destination forwarding table entry, and the destination CPU can respectively update the source address and the source port number of the feedback message as the virtual address and the virtual port number of the gateway recorded in the destination forwarding table entry, and respectively update the destination address and the destination port number of the feedback message as the address and the port number of the user equipment recorded in the destination forwarding table entry. And forwarding the message to the user equipment by forwarding the message.
In one embodiment of the present invention, taking the above gateway as a FullNAT gateway as an example, the FullNAT gateway may refer to four types of information, including an address and a port number of a user equipment and a virtual address and a virtual port number of the gateway, carried in a packet as a first quadruple, and calculate information included in the first quadruple by using an RSS algorithm to obtain a first hash value, which is used as a first allocation identifier.
In addition, each entry in the free address table contains the real address, the real port number, the local address of the gateway and the local port number of the server, and the above four types of information can be called a second quadruple. And the second hash value obtained by calculating the information contained in the second quaternion by adopting the RSS algorithm is the same as the first hash value obtained by calculating the information based on the first quaternion.
After generating the target forwarding table entry including the first quadruple and the second quadruple, the target CPU may forward the packet based on the target forwarding table entry, update the source address and the source port number of the packet to the local address and the local port number included in the second quadruple, and update the destination address and the destination port number of the packet to the real address and the real port number of the server included in the second quadruple. The source address and the source port number of the feedback message generated by the server based on the message are the real address and the real port number of the server respectively, and the destination address and the destination port number of the feedback message are the local address and the local port number of the gateway respectively, so that the destination address, the destination port number, the source address and the source port number of the feedback message are still four types of information contained in the second quadruple. After receiving the feedback message, the gateway calculates the destination address, the destination port number, the source address and the source port number of the feedback message based on the RSS algorithm, which is equivalent to calculating the information contained in the second quadruple, and the obtained second hash value is the same as the first hash value.
When forwarding a message sent by the user equipment, a first hash value calculated based on the first quadruple corresponds to the target CPU, and when forwarding a feedback message sent by the server, a second hash value calculated based on the second quadruple corresponds to the target CPU, so that both the message sent by the user equipment and the feedback message sent by the server can be distributed to the target CPU, and message forwarding is performed based on the same target forwarding table item.
From the above, when the gateway does not include the forwarding table entry matched with the message, the embodiment of the invention can configure the forwarding table entry recorded with the message information, the gateway information and the server information. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
In another embodiment of the present invention, for each free address table corresponding to the CPU, the number of entries included in the free address table is higher than a first threshold, so as to ensure that the number of entries included in the free address table is not too small, and when the forwarding table entry needs to be configured, the CPU may directly extract the entries from the free address table to generate the forwarding table entry. If the number of entries contained in the free address table is lower than the first threshold, the master may execute steps a-B to generate a new entry for the free address table.
In addition, for the free address table corresponding to each CPU, the number of the entries contained in the free address table is lower than a second threshold value, so that the excessive number of the entries contained in the free address table is prevented, and excessive storage resources in the gateway memory are occupied. And, the number of the table items contained in each idle address table is higher than the first threshold, so when the message forwarding amount of the gateway is larger, if the CPU receives the message to be forwarded, but the CPU is not configured with the forwarding table item matched with the message, the CPU can directly acquire the table item from the idle address table to generate the forwarding table item without waiting for the generation of the table item in the idle address table. When the message forwarding amount is large, more list items are recorded in the idle address list, so that the efficiency of generating the forwarding list items by the CPU is high, and the message forwarding efficiency is high.
In addition, the first threshold and/or the second threshold may be preset values, specifically, the first threshold and the second threshold may be adjusted based on the concurrent traffic of the gateway, which indicates that the higher the concurrent traffic is, the more user devices accessing the gateway are, the greater the first threshold and the second threshold may be set to values, so that a larger number of entries are recorded in the idle address table corresponding to each CPU, so as to ensure that after the gateway receives a large number of messages sent by the user devices, the CPU can quickly obtain entries from the idle address table corresponding to the CPU, and configure the forwarding table based on the entries.
Referring to fig. 2, a flow chart of a second message forwarding method according to an embodiment of the present invention is shown, and compared with the embodiment shown in fig. 1A, the above step S104 may be implemented by the following steps S104A-S104B.
S104A: and if the forwarding table item matched with the message does not exist, selecting a group of target server information from the server information which can be used by the target CPU.
Specifically, a set of target server information may be randomly selected from server information that the target CPU can use. The selection of a set of target server information may also be based on the FullNAT scheduling algorithm in the prior art, and will not be described here again.
Wherein, the target server information includes the real address and real port number of the server.
The selection of the target server information corresponds to the selection of the real address and the real port number contained in the generated target forwarding table, and in the process of forwarding the message subsequently, the message is forwarded to the server corresponding to the real address and the real port number, so that the selection of the target server information when the target forwarding table is generated corresponds to the allocation of the server for receiving and processing the message to the message, and the selection of the server for the message can realize the load balance when each server processes the message under the condition that the gateway is connected with a plurality of servers.
S104B: and acquiring an item containing the target server information from an idle address table corresponding to the target CPU, and configuring a target forwarding item containing the message information, and server information and gateway information recorded in the acquired item for the target CPU.
Specifically, the target server information may be used as an index value, the list items including the target server may be searched from the idle address table, and if there are a plurality of searched list items, the list item located at the forefront end in the idle address table in the searched list items may be selected and obtained, and of course, one of the searched list items may be randomly selected and obtained.
From the above, when the table entry is obtained from the idle address table and the forwarding table entry is configured, the target server information may be selected first, that is, the forwarding table entry to be generated includes the real address and the real port number of the server, so that after the forwarding table entry is configured, the gateway may forward the message to the server corresponding to the target server information based on the configured forwarding table entry. Therefore, the information of the preferential selection target server is equivalent to the server which preferentially determines to receive the message, so that the message can be dispatched.
Referring to fig. 3, a flow chart of a third method for forwarding a message according to an embodiment of the present invention is shown, and compared with the embodiment shown in fig. 1A, the method further includes the following step S107.
S107: and deleting the list item of the deleted server information or gateway information recorded in the idle address list corresponding to each CPU after deleting the server information and/or gateway information which can be used by the CPU.
In one embodiment of the present invention, for each CPU, the gateway may delete the gateway information recorded by itself that the CPU can use, indicating that the CPU cannot continue forwarding the message based on the local address and the local port number included in the deleted gateway information. In addition, if the server fails, the transmission channel between the gateway and the server is disconnected, and the gateway is difficult to continuously forward the message to the server, the gateway can delete the recorded server information.
After deleting the server information and/or gateway information, the CPU cannot continue forwarding messages based on the deleted information. If the table item containing the deleted information is still recorded in the idle address table corresponding to the CPU, the forwarding table item generated based on the deleted information may cause a failure in forwarding the message, so that the table item containing the deleted information may be searched from the idle address table, and the table item may be deleted.
Specifically, if the deleted information is server information, an entry including the server information is searched for and deleted from the free address table. If the deleted information is gateway information, searching and deleting the list item containing the server information from the idle address. If the deleted information is gateway information and server information, searching and deleting the list item containing the server information or the gateway information from the idle address list.
After deleting an entry, if the number of entries included in the free address table is less than a first threshold, an entry may be added to the free address table based on the step a-step B.
In addition, the embodiment of the invention also supports newly added server information and/or gateway information which can be used by the CPU, and when the list item is added into the idle address table, the list item containing the newly added server information and/or gateway information can be added.
Specifically, the step S107 may be implemented by a master configured in the gateway.
From the above, the embodiment of the present invention supports deleting server information and/or gateway information that can be used by the CPU, and deleting an entry containing deleted information in the free address table after deleting information, so that when generating a forwarding table entry based on an entry contained in the free address table, the generated forwarding table entry does not contain deleted server information and gateway information, thereby avoiding the problem of forwarding errors when forwarding a message based on the generated forwarding table entry.
Referring to fig. 4, a flow chart of a fourth packet forwarding method according to an embodiment of the present invention is shown, and compared with the embodiment shown in fig. 1A, the method further includes the following step S108.
S108: and deleting the forwarding table entry corresponding to each CPU and recorded with the server information of the server if the session between the gateway and the server is overtime, and/or deleting the forwarding table entry corresponding to each CPU and recorded with the address of the user equipment if the session between the user equipment and the gateway is overtime.
In particular, a session timeout between the gateway and the server may be caused by a failure of the server or a failure of a transmission channel between the gateway and the server. If the session between the gateway and the server is overtime, the problem of message transmission between the gateway and the server is indicated, and if the gateway continues to send the message to the server, the problem of packet loss and the like may be caused, so that the gateway can pause sending the message to the server. The forwarding entry recording the server information of the above-mentioned server may be deleted to prevent the CPU from continuing to send a message to the above-mentioned server based on the above-mentioned forwarding entry.
In addition, session timeouts between the user device and the gateway may be caused by a failure of the user device or a failure of a transmission channel between the gateway and the user device. If the session between the ue and the gateway is overtime, it indicates that the message transmission between the gateway and the ue is problematic, and if the gateway continues to forward the message for the ue, the gateway may have problems such as packet loss, so that the gateway may suspend forwarding the message for the ue. The forwarding table entry recording the address of the user equipment may be deleted to prevent the CPU from continuing to forward the message for the user equipment based on the forwarding table entry.
From the above, if the session between the server and the gateway is overtime, the forwarding table entry recorded in the gateway and containing the server information of the server can be deleted, and after the forwarding table entry is deleted, the gateway will not forward the message to the server with overtime session when forwarding the message based on the forwarding table entry, so that the problems of packet loss and the like during forwarding the message can be prevented. And if the session between the user equipment and the gateway is overtime, the forwarding table entry containing the address of the user equipment recorded in the gateway can be deleted, and the problems of packet loss and the like during forwarding the message can be prevented.
Referring to fig. 5, a flowchart of a fifth message forwarding method according to an embodiment of the present invention is shown, where the method includes the following steps S501 to S510.
S501: after receiving the message sent by the user equipment, the gateway calculates the source address, the source port number, the destination address, the destination port number and the protocol number of the message based on the hash function to obtain a hash value.
S502: based on the corresponding relation between the hash value recorded in the RETA table and the identification of the CPU, determining a target CPU for forwarding the message, and adding the message into a queue corresponding to the target CPU.
The gateway comprises n+1 queues, namely queues 0 to n, wherein the queues 0 to n correspond to the CPUs 0 to CPU n one by one. The message is added to the queue 1, and the CPU1 performs the subsequent processing as a target CPU.
S503: the CPU1 searches for a target forwarding table entry matching the above-mentioned message.
S504: if the matching is successful, the message is forwarded to the server directly based on the target forwarding table item.
S505: if the matching fails, a server for processing the message is selected based on a scheduling algorithm.
S506: and searching the list items recorded with the rip and rport of the selected server from the idle address table 1 corresponding to the CPU 1.
S507: and acquiring lip and lport of the gateway recorded in the searched list item, and generating a target forwarding list item based on rip, rport, lip, lport.
After the target forwarding table entry is generated, step S504 may be performed to forward the message based on the target forwarding table entry.
S508: the generated target forwarding table entry is stored in the forwarding table 1 corresponding to the CPU 1.
S509: lip, lport, rip, rport is obtained from the list of lip and lport of the gateway and the list of rip and rport of the server, and a hash value is calculated.
S510: searching a CPU corresponding to the calculated hash value based on RETA, and adding lip, lport, rip, rport of the calculated hash value to a free address table corresponding to the CPU.
In this embodiment, the message n+1 CPUs in the gateway, the CPU0-CPU n corresponds to the free address table 0-free address table n, respectively. Also, in case of a session timeout between the user equipment and the gateway, the CPU1 may delete the forwarding table entry in which cip and cport of the above user equipment are recorded in the forwarding table 1, and rewrite lip, lport, rip, rport recorded in the deleted forwarding table entry in the free address table 1.
Corresponding to the foregoing message forwarding method applied to the gateway, the embodiment of the invention also provides a message forwarding device.
Referring to fig. 6, a schematic structural diagram of a message forwarding device according to an embodiment of the present invention is applied to a gateway, where the device includes:
the identifier calculating module 601 is configured to calculate, after receiving a message sent by a user equipment, a first allocation identifier of the message based on message information of the message by adopting a preset calculating manner, where the message information includes: the source address, the source port number, the destination address and the destination port number of the message, wherein the source address is the address of the user equipment, the source port number is the port number of the user equipment, the destination address is the virtual address of the gateway, and the destination port number is the virtual port number of the gateway;
a message distribution module 602, configured to distribute the message to a target CPU included in the gateway and corresponding to the first distribution identifier;
a table entry searching module 603, configured to search, in forwarding table entries corresponding to the target CPU, a target forwarding table entry that matches the packet;
the table entry configuration module 604 is configured to obtain a table entry from an idle address table corresponding to the target CPU if there is no target forwarding table entry matching the message, and configure, for the target CPU, a target forwarding table entry including the message information and server information and gateway information recorded in the obtained table entry, where the server information and gateway information recorded in each table entry included in the idle address table are calculated by using the preset calculation method, and each allocation identifier corresponding to the target CPU can be calculated, and the server information includes: the real address and the real port number of the server, and the gateway information comprises: the local address and the local port number of the gateway;
A first message forwarding module 605, configured to forward a message to the server based on the target forwarding table entry, so that the server processes the message and sends a feedback message, where a destination address, a destination port number, a source address, and a source port number of the feedback message are respectively: the source address, the source port number, the destination address and the destination port number of the message;
and a second message forwarding module 606, configured to calculate, after the feedback message is received, a second allocation identifier of the feedback message based on the message information of the feedback message by using the preset calculation mode, allocate the feedback message to a CPU corresponding to the second allocation identifier, and forward a message to the user equipment based on a forwarding table entry corresponding to the allocated CPU and matched with the feedback message.
From the above, when the gateway does not include the forwarding table entry matched with the message, the embodiment of the invention can configure the forwarding table entry recorded with the message information, the gateway information and the server information. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
In one embodiment of the invention, the apparatus further comprises: the table entry generating module is configured to generate, for each CPU included in the gateway, an entry in a free address table corresponding to the CPU by:
calculating server information and gateway information which can be used by the CPU by adopting the preset calculation mode to obtain a calculation result;
and selecting a target information group, and generating a table item containing the target information group, wherein the calculation result of server information and gateway information contained in the target information group is an allocation identifier corresponding to the CPU.
In one embodiment of the present invention, the table entry configuration module 504 is specifically configured to:
if no forwarding table item matched with the message exists, selecting a group of target server information from server information which can be used by the target CPU;
acquiring an item containing the target server information from an idle address table corresponding to the target CPU;
and configuring a forwarding table item containing the message information, the server information and the gateway information recorded in the acquired table item for the target CPU.
From the above, when the table entry is obtained from the idle address table and the forwarding table entry is configured, the target server information may be selected first, that is, the forwarding table entry to be generated includes the real address and the real port number of the server, so that after the forwarding table entry is configured, the gateway may forward the message to the server corresponding to the target server information based on the configured forwarding table entry. Therefore, the information of the preferential selection target server is equivalent to the server which preferentially determines to receive the message, so that the message can be dispatched.
In one embodiment of the invention, the apparatus further comprises:
and the table item deleting module is used for deleting the table item recorded with the deleted server information or gateway information in the idle address table corresponding to the CPU after deleting the server information and/or gateway information which can be used by the CPU for each CPU.
From the above, the embodiment of the present invention supports deleting server information and/or gateway information that can be used by the CPU, and deleting an entry containing deleted information in the free address table after deleting information, so that when generating a forwarding table entry based on an entry contained in the free address table, the generated forwarding table entry does not contain deleted server information and gateway information, thereby avoiding the problem of forwarding errors when forwarding a message based on the generated forwarding table entry.
In one embodiment of the invention, the apparatus further comprises:
a forwarding table item deleting module, configured to delete forwarding table items corresponding to each CPU and recording server information of the server if a session between the gateway and the server is overtime;
and/or
And if the session between the user equipment and the gateway is overtime, deleting forwarding table items corresponding to the CPUs and recorded with the address of the user equipment.
From the above, if the session between the server and the gateway is overtime, the forwarding table entry recorded in the gateway and containing the server information of the server can be deleted, and after the forwarding table entry is deleted, the gateway will not forward the message to the server with overtime session when forwarding the message based on the forwarding table entry, so that the problems of packet loss and the like during forwarding the message can be prevented. And if the session between the user equipment and the gateway is overtime, the forwarding table entry containing the address of the user equipment recorded in the gateway can be deleted, and the problems of packet loss and the like during forwarding the message can be prevented.
In one embodiment of the present invention, for each CPU, a free address table is provided, where the number of entries included in the free address table is above a first threshold and/or below a second threshold.
The embodiment of the present invention further provides an electronic device, as shown in fig. 7, including a processor 701, a communication interface 702, a memory 703 and a communication bus 704, where the processor 701, the communication interface 702, and the memory 703 perform communication with each other through the communication bus 704,
a memory 703 for storing a computer program;
the processor 701 is configured to implement any method step of the above-described message forwarding method applied to the gateway when executing the program stored in the memory 703.
When the electronic equipment provided by the embodiment of the invention is used for forwarding the message, when the gateway does not contain the forwarding table item matched with the message, the forwarding table item recorded with the message information, the gateway information and the server information can be configured by the embodiment of the invention. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
The communication bus mentioned by the above terminal may be a peripheral component interconnect standard (Peripheral Component Interconnect, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the terminal and other devices.
The memory may include random access memory (Random Access Memory, RAM) or non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processor, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In still another embodiment of the present invention, a computer readable storage medium is further provided, where a computer program is stored, where the computer program when executed by a processor implements the method for forwarding a message applied to a gateway according to any one of the foregoing embodiments.
When the computer program stored in the computer readable storage medium provided by the embodiment is used for forwarding the message, when the gateway does not contain the forwarding table item matched with the message, the forwarding table item recorded with the message information, the gateway information and the server information can be configured through the embodiment of the invention. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
In yet another embodiment of the present invention, a computer program product containing instructions that, when executed on a computer, cause the computer to perform the method for forwarding a message applied to a gateway according to any one of the foregoing embodiments is provided.
When the computer program product provided by the embodiment is executed to forward the message, when the gateway does not contain the forwarding table item matched with the message, the forwarding table item recorded with the message information, the gateway information and the server information can be configured through the embodiment of the invention. After the target CPU acquires the message, the source address of the message may be modified to be the local address of the gateway based on the gateway information recorded in the forwarding table entry, the source port number may be modified to be the local port number of the gateway, the destination address of the message may be modified to be the real address of the server based on the server information recorded in the forwarding table entry, and the destination port number of the message may be modified to be the real port number. The message may be forwarded to the server based on the modified destination address and destination port number, and after the server completes the data processing, the server may generate a feedback message sent to the user equipment, where, contrary to the message received by the server, the destination address, the destination port number, the source address, and the source port number of the feedback message are the source address, the source port number, the destination address, and the destination port number of the message, respectively, that is, the destination address of the feedback message is the local address of the gateway, the destination port number is the local port number, the source address is the real address of the server, and the source port number is the real port number, so that the server may send the feedback message to the gateway. The gateway calculates a second distribution identifier based on the message information of the feedback message by adopting a preset calculation mode, and distributes the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier. Because the message information of the feedback message is the real address, the real port number, the local address and the local port number recorded in the idle address table configured for the target CPU, the second allocation identifier calculated based on the message information of the feedback message also corresponds to the target CPU, the feedback message can be allocated to the target CPU based on the second allocation identifier, and the target CPU can continue to forward the feedback message based on the forwarding table item corresponding to the target CPU. Therefore, whether the message sent by the user equipment or the feedback message sent by the server is forwarded by the same target CPU, data interaction is not needed between the CPUs in the process of forwarding the message, and therefore the efficiency of forwarding the message can be improved.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for apparatus, electronic devices, computer readable storage media and computer program product embodiments, the description is relatively simple as it is substantially similar to method embodiments, as relevant points are found in the partial description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (10)

1. A method for forwarding a message, the method being applied to a gateway, the method comprising:
after receiving a message sent by user equipment, calculating a first distribution identifier of the message based on message information of the message by adopting a preset calculation mode, wherein the message information comprises: the source address, the source port number, the destination address and the destination port number of the message, wherein the source address is the address of the user equipment, the source port number is the port number of the user equipment, the destination address is the virtual address of the gateway, and the destination port number is the virtual port number of the gateway;
distributing the message to a target CPU (central processing unit) contained in the gateway and corresponding to the first distribution identifier;
searching a target forwarding table item matched with the message in the forwarding table item corresponding to the target CPU;
if there is no target forwarding table item matched with the message, acquiring a table item from an idle address table corresponding to the target CPU, and configuring a target forwarding table item containing the message information and server information and gateway information recorded in the acquired table item for the target CPU, wherein the server information and gateway information recorded in each table item contained in the idle address table are calculated by adopting the preset calculation mode, so that an allocation identifier corresponding to the target CPU can be obtained by calculation, and the server information comprises: the real address and the real port number of the server, and the gateway information comprises: the local address and the local port number of the gateway;
Respectively modifying a source address and a source port number of the message into a local address and a local port number of the gateway based on gateway information recorded in the target forwarding table item, and respectively modifying a destination address and a destination port number of the message into a real address and a real port number of the server based on server information recorded in the target forwarding table item; forwarding the message to the server based on the modified destination address and destination port number, so that the server processes the message and sends a feedback message, wherein message information of the feedback message comprises: the destination address, the destination port number, the source address and the source port number of the feedback message are respectively as follows: the modified source address, source port number, destination address and destination port number of the message;
after the feedback message is received, calculating a second allocation identifier of the feedback message based on the message information of the feedback message by adopting the preset calculation mode, allocating the feedback message to a CPU corresponding to the second allocation identifier, and forwarding the feedback message to the user equipment based on a forwarding table item which corresponds to the allocated CPU and is matched with the feedback message, wherein the second allocation identifier corresponds to the target CPU.
2. The method according to claim 1, wherein for each CPU contained in the gateway, an entry in a free address table corresponding to that CPU is generated by:
calculating server information and gateway information which can be used by the CPU by adopting the preset calculation mode to obtain a calculation result;
and selecting a target information group, and generating a table item containing the target information group, wherein the calculation result of server information and gateway information contained in the target information group is an allocation identifier corresponding to the CPU.
3. The method of claim 1, wherein the obtaining an entry from the free address table corresponding to the target CPU comprises:
selecting a set of target server information from server information that can be used by the target CPU;
and acquiring an item containing the target server information from the idle address table corresponding to the target CPU.
4. The method according to claim 1, wherein the method further comprises:
and deleting the list item of the deleted server information or gateway information recorded in the idle address list corresponding to each CPU after deleting the server information and/or gateway information which can be used by the CPU.
5. The method according to claim 1, wherein the method further comprises:
if the session between the gateway and the server is overtime, deleting forwarding table items corresponding to each CPU and recorded with server information of the server;
and/or
And if the session between the user equipment and the gateway is overtime, deleting forwarding table items corresponding to the CPUs and recorded with the address of the user equipment.
6. The method according to any of claims 1-5, characterized in that for each CPU a free address table is corresponding, the number of entries contained in the free address table being above a first threshold value and/or below a second threshold value.
7. A message forwarding device, applied to a gateway, the device comprising:
the device comprises an identification calculation module, a message distribution module and a message distribution module, wherein the identification calculation module is used for calculating a first distribution identification of a message based on message information of the message by adopting a preset calculation mode after receiving the message sent by user equipment, and the message information comprises: the source address, the source port number, the destination address and the destination port number of the message, wherein the source address is the address of the user equipment, the source port number is the port number of the user equipment, the destination address is the virtual address of the gateway, and the destination port number is the virtual port number of the gateway;
The message distribution module is used for distributing the message to a target CPU (central processing unit) contained in the gateway and corresponding to the first distribution identifier;
the table entry searching module is used for searching a target forwarding table entry matched with the message in the forwarding table entries corresponding to the target CPU;
the table entry configuration module is configured to obtain a table entry from an idle address table corresponding to the target CPU if there is no target forwarding table entry matching the message, and configure, for the target CPU, a target forwarding table entry including the message information and server information and gateway information recorded in the obtained table entry, where the server information and gateway information recorded in each table entry included in the idle address table are calculated by using the preset calculation method, and each allocation identifier corresponding to the target CPU can be calculated, and the server information includes: the real address and the real port number of the server, and the gateway information comprises: the local address and the local port number of the gateway;
the first message forwarding module is used for respectively modifying a source address and a source port number of the message into a local address and a local port number of the gateway based on gateway information recorded in the target forwarding table item, and respectively modifying a destination address and a destination port number of the message into a real address and a real port number of the server based on server information recorded in the target forwarding table item; forwarding the message to the server based on the modified destination address and destination port number, so that the server processes the message and sends a feedback message, wherein message information of the feedback message comprises: the destination address, the destination port number, the source address and the source port number of the feedback message are respectively as follows: the modified source address, source port number, destination address and destination port number of the message;
And the second message forwarding module is used for calculating a second distribution identifier of the feedback message based on the message information of the feedback message by adopting the preset calculation mode after receiving the feedback message, distributing the feedback message to a CPU (central processing unit) corresponding to the second distribution identifier, and forwarding the feedback message to the user equipment based on a forwarding table item which corresponds to the distributed CPU and is matched with the feedback message, wherein the second distribution identifier corresponds to the target CPU.
8. The apparatus of claim 7, wherein the apparatus further comprises: the table entry generating module is configured to generate, for each CPU included in the gateway, an entry in a free address table corresponding to the CPU by:
calculating server information and gateway information which can be used by the CPU by adopting the preset calculation mode to obtain a calculation result;
and selecting a target information group, and generating a table item containing the target information group, wherein the calculation result of server information and gateway information contained in the target information group is an allocation identifier corresponding to the CPU.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
A memory for storing a computer program;
a processor for carrying out the method steps of any one of claims 1-6 when executing a program stored on a memory.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored therein a computer program which, when executed by a processor, implements the method steps of any of claims 1-6.
CN202111496154.0A 2021-12-09 2021-12-09 Message forwarding method and device Active CN114257545B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111496154.0A CN114257545B (en) 2021-12-09 2021-12-09 Message forwarding method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111496154.0A CN114257545B (en) 2021-12-09 2021-12-09 Message forwarding method and device

Publications (2)

Publication Number Publication Date
CN114257545A CN114257545A (en) 2022-03-29
CN114257545B true CN114257545B (en) 2023-09-05

Family

ID=80791832

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111496154.0A Active CN114257545B (en) 2021-12-09 2021-12-09 Message forwarding method and device

Country Status (1)

Country Link
CN (1) CN114257545B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116938829A (en) * 2022-04-06 2023-10-24 华为云计算技术有限公司 Data forwarding method and related equipment

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7177943B1 (en) * 2001-12-27 2007-02-13 Cisco Technology, Inc. System and method for processing packets in a multi-processor environment
CN102025643A (en) * 2010-12-30 2011-04-20 华为技术有限公司 Flow table search method and device
CN102984006A (en) * 2012-12-06 2013-03-20 武汉烽火网络有限责任公司 Network management implementation method based on simple network management protocol
WO2014008802A1 (en) * 2012-07-10 2014-01-16 Hangzhou H3C Technologies Co., Ltd. Traffic forwarding in a layer 2 edge network
CN104780088A (en) * 2015-03-19 2015-07-15 杭州华三通信技术有限公司 Service message transmission method and equipment
WO2016034014A1 (en) * 2014-09-05 2016-03-10 华为技术有限公司 Gateway control method, device and system based on virtual machine migration
CN105871741A (en) * 2015-01-23 2016-08-17 阿里巴巴集团控股有限公司 Packet dispersion method and device
CN108363621A (en) * 2018-01-18 2018-08-03 东软集团股份有限公司 Message forwarding method, device, storage medium under numa frameworks and electronic equipment
CN112965824A (en) * 2021-03-31 2021-06-15 北京金山云网络技术有限公司 Message forwarding method and device, storage medium and electronic equipment
CN113014689A (en) * 2021-03-01 2021-06-22 杭州迪普科技股份有限公司 Method and device for network address translation
CN113419973A (en) * 2021-06-17 2021-09-21 杭州迪普科技股份有限公司 Message forwarding method and device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030110379A1 (en) * 2001-12-07 2003-06-12 Tatu Ylonen Application gateway system, and method for maintaining security in a packet-switched information network
US9094466B2 (en) * 2011-04-07 2015-07-28 Hewlett-Packard Development Company, L.P. Maintaining caches of object location information in gateway computing devices using multicast messages

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7177943B1 (en) * 2001-12-27 2007-02-13 Cisco Technology, Inc. System and method for processing packets in a multi-processor environment
CN102025643A (en) * 2010-12-30 2011-04-20 华为技术有限公司 Flow table search method and device
WO2014008802A1 (en) * 2012-07-10 2014-01-16 Hangzhou H3C Technologies Co., Ltd. Traffic forwarding in a layer 2 edge network
CN102984006A (en) * 2012-12-06 2013-03-20 武汉烽火网络有限责任公司 Network management implementation method based on simple network management protocol
WO2016034014A1 (en) * 2014-09-05 2016-03-10 华为技术有限公司 Gateway control method, device and system based on virtual machine migration
CN105871741A (en) * 2015-01-23 2016-08-17 阿里巴巴集团控股有限公司 Packet dispersion method and device
CN104780088A (en) * 2015-03-19 2015-07-15 杭州华三通信技术有限公司 Service message transmission method and equipment
CN108363621A (en) * 2018-01-18 2018-08-03 东软集团股份有限公司 Message forwarding method, device, storage medium under numa frameworks and electronic equipment
CN113014689A (en) * 2021-03-01 2021-06-22 杭州迪普科技股份有限公司 Method and device for network address translation
CN112965824A (en) * 2021-03-31 2021-06-15 北京金山云网络技术有限公司 Message forwarding method and device, storage medium and electronic equipment
CN113419973A (en) * 2021-06-17 2021-09-21 杭州迪普科技股份有限公司 Message forwarding method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
李凯 ; 叶麟 ; 余翔湛 ; 胡阳 ; .基于DPDK的流量动态负载均衡方法.智能计算机与应用.2017,(第04期),全文. *

Also Published As

Publication number Publication date
CN114257545A (en) 2022-03-29

Similar Documents

Publication Publication Date Title
US11134134B2 (en) Routing for origin-facing points of presence
WO2020186909A1 (en) Virtual network service processing method, apparatus and system, and controller and storage medium
EP3142310B1 (en) Method, device, and system for configuring flow entries
CN111460460B (en) Task access method, device, proxy server and machine-readable storage medium
CN107172120B (en) Information processing method, processing node and network node
CN109660578B (en) CDN back-to-source processing method, device and system
CN108322325B (en) Virtual machine management method and device
CN108259328B (en) Message forwarding method and device
JP2019527988A (en) Packet transmission
US20180241608A1 (en) Forwarding ethernet packets
CN111212134A (en) Request message processing method and device, edge computing system and electronic equipment
CN111585887B (en) Communication method and device based on multiple networks, electronic equipment and storage medium
WO2017000565A1 (en) User access control method and apparatus, relay device and server
US20150088995A1 (en) Method and apparatus for sharing contents using information of group change in content oriented network environment
CN110290044B (en) Method, device and storage medium for shunting VPN (virtual private network) and backbone network
JP2010219845A (en) Relay unit, and tenant management program
CN104954155B (en) The network equipment with multiple business boards and multi-service plate sharing method
WO2020181735A1 (en) Method for providing network address translation (nat) service and controller
CN114095430A (en) Processing method, system and working node of access message
JP2020502941A (en) Resource scheduling
CN104780232A (en) A resource allocating method, controller and system
CN114257545B (en) Message forwarding method and device
CN111064786B (en) Account identifier management method and device
CN109617817B (en) Method and device for generating forwarding table entry of MLAG networking
CN110086727B (en) Load sharing method and device between CGN boards

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant