Disclosure of Invention
The present invention is directed to a method and an apparatus for providing a reverse network proxy server based on FPGA to overcome the above-mentioned drawbacks of the prior art.
The purpose of the invention can be realized by the following technical scheme:
a method of a reverse network proxy server based on FPGA includes the following steps:
step 1: receiving a data request sent by a client from a corresponding optical port by the FPGA, and performing Hash calculation based on an access address in the data request to obtain a first Hash value;
step 2: comparing the first Hash value with a second Hash value in a memory, hitting and performing static data response when the comparison results are the same, reading data in a cache to generate a response message and an empty request message, and sending the response message and the empty request message through corresponding optical ports;
and step 3: when the comparison results are different, the data is not hit, Hash calculation is carried out based on other parameters in the data request, and a third Hash value is obtained;
and 4, step 4: searching the number of mapping servers corresponding to the third Hash value, if the number is not 1, carrying out load balancing, carrying out mapping addresses through corresponding optical ports, and generating and sending a request and response message after replacing corresponding data;
and 5: and if the number is 1, directly replacing according to the corresponding mapping address in the FPGA configuration, and generating and sending a request and response message after replacing the corresponding data.
Further, the step 1 further comprises: and starting a power supply, loading a pre-stored static resource from the flash memory by the FPGA from the DDR cache, and recording the Hash value, the first address and the length information of the address in the random access memory.
Further, in step 1, the receiving, by the FPGA, the data request sent by the client from the corresponding optical port, and performing Hash calculation based on the access address in the data request to obtain the first Hash value specifically includes: the FPGA receives a data request sent by a client from a corresponding optical port, extracts a source IP, a source port, a target IP, a target port, an access address and first address information of a head part in the data request, and carries out Hash calculation on the access address to obtain a first Hash value.
Further, the step 3 specifically includes: and when the comparison results are different, the data is not hit, and Hash calculation is carried out based on the target IP, the target port and the first address information in the data request to obtain a third Hash value.
Further, the load balancing process in step 4 includes the following sub-steps:
step 401: based on the source IP and the source port information in the data request, performing Hash calculation and Sum calculation to respectively obtain a fourth Hash value and a fourth Sum value;
step 402: and after dividing the fourth Sum value by the number of the mapping servers corresponding to the third Hash value, taking the remainder, and taking the remainder as an offset address to obtain a new IP address.
The invention also provides a device for the method of the reverse network proxy server based on the FPGA, which comprises a stabilized voltage supply, and an FPGA accelerator card, an LCD display module and a key control module which are connected with the stabilized voltage supply.
Further, the input voltage of the FPGA accelerator card is 220V mains supply.
Further, the working voltage of the FPGA accelerator card is 12V.
Furthermore, the FPGA accelerator card is internally provided with an FPGA main control chip, a multi-network-port network transceiving circuit module, a USB debugging circuit module, a FLASH storage module, a DDR3 storage module, a power management module and a configuration circuit module.
Furthermore, a network transceiver module, a serial port transceiver module, a DDR management module, a Hash operation module, a load balancing module and an RAM lookup table module are arranged in the FPGA main control chip.
Compared with the prior art, the invention has the following advantages:
(1) in order to reduce the cost of the server and improve the corresponding speed of the network request, the invention discloses a method and a device for a reverse proxy network server based on an FPGA (field programmable gate array), which can replace a CPU (central processing unit) server with high cost and achieve the effects of low delay, low response time, high concurrency and high bandwidth by depending on the advantage of a parallel architecture of the FPGA.
(2) And the Hash search is realized in the FPGA to quickly and accurately position the static network resources.
(3) And mapping of server addresses and ports is realized in the FPGA, and the FPGA can be dynamically configured.
(4) And according to the load balancing strategy, carrying out load balancing on the network request in real time.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, shall fall within the scope of protection of the present invention.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings or the orientations or positional relationships that the products of the present invention are conventionally placed in use, and are only used for convenience in describing the present invention and simplifying the description, but do not indicate or imply that the devices or elements referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," "third," and the like are used solely to distinguish one from another and are not to be construed as indicating or implying relative importance.
Furthermore, the terms "horizontal", "vertical" and the like do not imply that the components are required to be absolutely horizontal or pendant, but rather may be slightly inclined. For example, "horizontal" merely means that the direction is more horizontal than "vertical" and does not mean that the structure must be perfectly horizontal, but may be slightly inclined.
In the description of the present invention, it should also be noted that, unless otherwise explicitly specified or limited, the terms "disposed," "mounted," "connected," and "connected" are to be construed broadly and may, for example, be fixedly connected, detachably connected, or integrally connected; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meanings of the above terms in the present invention can be understood in specific cases to those skilled in the art.
The invention discloses a method and a device for a reverse proxy network server based on FPGA (field programmable gate array). As shown in figure 1, the reverse proxy server is used as a pivot between a client and a server cluster and is responsible for mutually converting data sent by the client and the server. The structure of the FPGA reverse proxy server device is shown in FIG. 2, and the FPGA reverse proxy server device mainly comprises an FPGA accelerator card, a stabilized voltage power supply, an LCD display module, a key control module and the like, and has the advantages of simple structure and low cost. The voltage-stabilized power supply allows the FPGA accelerator card to be connected to 220V mains supply and work under a stable 12V voltage. The LCD display is used for configuring the working state of the FPGA and configuring various parameters of the proxy server manually in cooperation with the key control module. The FPGA network card is composed of an FPGA main control chip, a multi-network-port network transceiving circuit, a USB debugging circuit, a FLASH storage module, a DDR3 storage module, a power management module, a configuration circuit and other circuits. The FPGA chip has the characteristics of low power consumption, stable operation, strong flexibility and the like, and is very suitable for network nodes with general complexity.
The FPGA chip processes network data on an MAC layer, saves high TCP/IP development cost, and mainly comprises a high-speed network transceiving module, a serial port transceiving module, a DDR management module, a Hash operation module, a load balancing module, an RAM lookup table module and the like.
The FPGA is mainly responsible for converting and distributing network request packets sent by the client to different servers in the server cluster according to request addresses and contents so as to reduce excessive pressure on a single server and distribute different tasks to different servers. A local flash (memory) is set in the FPGA, and the request of static data is responded with the fastest speed.
The invention relates to a method and a device for a reverse proxy network server based on FPGA, the system architecture is simple and clear, and the implementation mode is as follows:
(1) an optical port1 on an FPGA board card is accessed to an external network environment;
(2) the optical ports 2, 3, 4 and 5 on the FPGA board card are accessed to an intranet environment;
(3) switching on a power supply and turning on a switch until the light flicker at the light port is seen;
(4) and using the external network client to access the internal network server through the network.
The flow for realizing reverse proxy by the FPGA board is shown in fig. 3, which specifically includes the following steps:
(1) after the power supply is turned on, the FPGA loads a pre-stored static resource from the flash to the DDR3, and records the hash value, the first address and the length information of the address in the RAM 1;
(2) when receiving a data request package1 sent by a client from an optical port1, the FPGA extracts information of a source IP1, a source port1, a destination IP2, a destination port2, an access address url1, a head address url2 and the like of the header;
(3) carrying out Hash operation on url1 in the previous step, and calculating to obtain a Hash value of Hash 1;
(4) sequentially extracting a Hash field Hash2, a first address field addr2 and a length field len2 which are stored in the RAM 1;
(6) comparing the hash1 in the step 2 with the hash2 in the step 5, if the two are the same, jumping to the step 14, otherwise, executing the next step;
(7) if the last step misses, calculating the Hash value of ip2, port2 and url2 in step 1 to obtain Hash value Hash 3;
(8) searching the number of the mapping servers corresponding to the hash3, count1, if the count1 is not 1, jumping to the step 10, otherwise, continuing to execute;
(9) replacing according to the corresponding mapping address in the FPGA configuration, and replacing ip2 and port2 with new ip3 and port 3; jumping to step 11;
(10) if count1 is not 1, load balancing is required, and the load balancing module is shown in fig. 4; calculating Hash values of the IP1 and the port1 in the step 1, calculating sum4 of Hash4, dividing sum4 by count1, taking the rest number, and taking the remainder as an offset address to obtain new IP addresses IP3 and port 3;
(11) sending the request message after the last step of replacement through the optical ports 2, 3, 4 and 5;
(12) when the optical ports 2, 3, 4, 5 receive the response message sent by the server, the FPGA replaces the source IP3 and the source port3 in the message with IP2 and IP3 corresponding to the mapping addresses;
(13) sending the response message after the last step of replacement through the optical port 1;
(14) if hit in step 6, static data response is required; reading data with add2 address length len2 in DDR 3;
(15) generating a new response message by the data read in the previous step, and sending out the new response message through the optical port 1;
(16) and generating an empty request message for updating the sequence, and sending the empty request message through the optical ports 2, 3, 4 and 5.
The invention discloses a method and a device for realizing a reverse proxy network server based on an FPGA (field programmable gate array), which have the following realization effects:
(1) a method and a device for realizing a reverse proxy server on a physical layer by using an FPGA;
(2) the FPGA deployment cost is low, the power consumption is reduced, the response time is reduced, and the delay is reduced;
(3) and dynamic configuration of static resources and monitoring of the running state of the FPGA are realized through a debugging and configuration interface of the USB.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.