Router network transfer read-write method and transfer server
Technical Field
The invention relates to the field of network transfer, in particular to a router network transfer read-write method and a transfer server.
Background
With the development of internet technology, a plurality of household devices need to be connected to the internet to form an intelligent home system. The router is used as an entrance of an intelligent home and is widely applied. The existing intelligent router generally supports the function of remote control, and a user can directly control the router at home through APP software on the mobile terminal, so that convenience and safety are realized.
Generally, according to network conditions, routers can be divided into a public network router and a private network router, the so-called public network router refers to a router which obtains a public network IP address after dialing through PPPOE, and APP can directly control the public network router through the public network IP address; the private network router is a subordinate device with a public network IP device and only has a private IP address. The APP can not directly control the private network router, and generally transit is performed through a long connection server.
Because most routers generally exist in a private network and do not have a public network IP, the data message of the APP managing and controlling the router at each time is transferred through the server, and the server faces two problems:
(1) due to the large number of requests, performance consumption is large.
(2) Too many request data messages cause large network bandwidth consumption.
Disclosure of Invention
The invention provides a transfer read-write method of a router network aiming at the problems in the prior art. The invention solves the bottleneck problems of performance and network bandwidth when the server faces to manage massive routers.
On one hand, the invention provides a network transfer read-write method of a router, the technical scheme is as follows, comprising the following steps:
s100, receiving a read-write request message of a user;
s200, extracting a router address in the read-write request message, and judging the type of the read-write request message;
when the request message is judged to be a read operation, executing step S300;
when the request message is judged to be write operation, executing step S400;
s300, according to the extracted address of the router, searching cached configuration state data of the router, and generating a response message of the read operation according to the searched cache configuration state data of the router;
s400, according to the extracted router address, forwarding an operation request to the router, and forwarding and returning an operation response message of the router.
The basic idea of the scheme is that the read-write request message is divided into a read operation and a write operation for separate processing, and the read operation is to read information of the device, such as a device state, a device list and the like. The write operation includes a set operation to the device. Most of the operations of the user belong to the read operation, and if the state of the device is not changed, the return result of the read operation is the same. Therefore, the idea of the scheme is to keep the configuration state of each router, and when there is a read operation request, the cached configuration state of the router is directly returned. Therefore, the speed of directly returning data by the server is high, and the user experience is improved; if the configuration state of the router is cached by the server, a read operation request does not need to be initiated to the router, so that the interaction times with the router are reduced, and the pressure of the server is relieved; after the interaction times are reduced, the data messages are reduced, and the consumption of network bandwidth is reduced.
Further preferably, the step S300 further includes the steps of:
s310, according to the extracted router address, judging whether configuration state data of the router is cached or not, if yes, executing a step S320; otherwise, executing step S400;
s320, generating a response message of the read operation according to the searched cache configuration state data of the router.
The scheme is a supplement to the above scheme, and even if the request message is a read operation, it is also determined whether the requested router configuration information is cached in our server, and if the configuration information of the request router does not exist in our cache, we still need to initiate a request to the corresponding router.
Further preferably, the method further comprises the following steps:
s350, when the configuration of the router changes, receiving changed configuration state data sent by the router;
s360, updating the cached configuration state data according to the changed configuration state data sent by the router.
The configuration state of the router is not changed in a layer, so that once the configuration state of the router is changed, the router sends the changed configuration information to the server for updating in real time, and therefore the configuration information cached in the server is up-to-date and accurate, and wrong information returned to a client is avoided.
Further preferably, in step S300, the cache configuration status data of the router is stored in a form of < Key, Value >, where the address of the router is used as Key, and the configuration item is used as Value.
The MAC address of the router is used as an index, and the MAC (Media Access Control or Medium Access Control) address is translated into a Media Access Control, or a physical address or a hardware address, to define the location of the network device. In the OSI model, a third layer network layer is responsible for IP addresses and a second layer data link layer is responsible for MAC addresses. Thus, a host will have a MAC address and each network location will have an IP address specific to it. Then stored is the configuration of the router, which is divided by function. Each piece of data is stored according to the form of < K, V >, K is Key, V is Value, MAC address is Key, configuration item is corresponding Value, Value is stored by JSON format, for example, the router has the configuration of function1, function2 and function 3. { "function 1": value1 "," function2 ": value 2", "function 3": value3 "}. The storage is convenient for subsequent search, so that the feedback speed is higher.
Further preferably, the step S400 further includes the steps of:
s410, according to the router address, forwarding and initiating a request to the router;
s420, judging whether an operation response message of the router is received within preset time; if yes, go to step S430, otherwise go to step S440;
s430, transferring an operation response message returned to the router;
s440, judging that the state of the router is abnormal, and generating and sending the abnormal message of the router.
The scheme adds a step of judging the feedback message of the router, and assumes that if a certain router is broken or has other faults, after a server initiates a request to the router, the router can not give the feedback message within the preset time, and the server can preliminarily judge that the state of the router is abnormal and then inform the user of the message, so that the user can find the message in time and the user experience is improved.
Certainly, the determining step is based on the user initiating the request, so if we want to find in time without causing the bottleneck problem of the network bandwidth, we can also let our server actively initiate a read operation request to the router under the condition of small request amount and abundant network bandwidth, on one hand, if the fed back router configuration information changes, the configuration information of the router can be updated, on the other hand, if no feedback exists, the abnormal state of the router can be found in time and actively sent to the user, so that the user can also know the abnormal state information of the router in time under the condition of not sending the request.
In another aspect, the present invention further provides a network transit server of a router, including: the message processing module is respectively connected with the receiving module and the cache module, the message processing module comprises an extraction unit, a judgment unit, a transfer unit and an operation unit, the operation unit is respectively connected with the extraction unit, the judgment unit and the transfer unit, and the operation unit is also connected with the extraction unit and the judgment unit, wherein:
the receiving module receives a read-write request of a user;
the extracting unit extracts the router address in the read-write request message, and the judging unit judges the type of the read-write request message;
when the judging unit judges that the request message is read, the operating unit searches the configuration state data of the router cached by the cache module according to the address of the router extracted by the extracting unit, generates a response message of the read operation according to the searched cache configuration state data of the router, and returns the response message to the user;
when the judging unit judges that the request message is write operation, the transfer unit initiates a write operation request to the router according to the router address extracted by the extracting unit, and the operating unit sends a write operation response message of the router returned by the transfer unit to a user.
The receiving module is mainly used for receiving the request of the user, and is equivalent to providing an interface accessed by the user, and the server acquires the request information of the user from the interface. The message processing module performs corresponding operation processing on the request information, the cache module is used for caching the configuration state information of each router for calling when the message processing module processes the message, and the cache module caches the configuration state information of each router, so that the message module can directly search corresponding router information in the cache module when processing the read operation message, and then directly returns the router information to the user without initiating a request to the router, thereby reducing the interaction times of the two parties, reducing the performance consumption of the server, and having higher feedback speed!
Preferably, when the determining unit determines that the request message is a read operation, the determining unit further determines whether the cache module caches configuration state data of the router according to the router address extracted by the extracting unit, if so, the operating unit searches the configuration state data of the router cached by the cache module, and generates a response message of the read operation according to the searched cache configuration state data of the router and returns the response message to the user; if not, the relay unit initiates a read operation request to the router according to the router address extracted by the extraction unit, and the operation unit sends a read operation response message of the router returned by the relay unit to a user.
On the basis of the server, the server requests data from the cache under the condition that the judgment message is read operation, if the data exists in the cache, the request is successful, the server directly returns, and if the request is unsuccessful, the server indicates that the corresponding data does not exist in the cache, the server initiates the request to the routing equipment.
Further preferably, the system further comprises an updating module, the updating module is connected with the message processing module and the caching module, wherein:
when the configuration information of the router changes, the updating module receives the changed configuration information sent by the router, and updates the configuration information of the router in the caching module.
The connection between the server and the router is maintained, if the state of the router changes once, the changed configuration is sent to the server in real time, so that the server can maintain the latest router configuration
Further preferably, the configuration status data of the router in the cache module is stored in a form of < Key, Value >, wherein the address of the router is used as Key, and the configuration item is used as Value.
The router configuration information is stored with the MAC address of the router as an index, and then the configuration of the router is stored, the configuration being divided by function. Each piece of data is stored according to the form of < K, V >, K is Key, V is Value, MAC address is Key, configuration item is corresponding Value, Value is stored by JSON format, for example, the router has the configuration of function1, function2 and function 3. { "function 1": value1 "," function2 ": value 2", "function 3": value3 "}.
Further preferably, the message processing module further comprises a reminder unit; the reminding unit is connected with the judging unit, wherein:
when the transit unit initiates an operation request to the router according to the router address,
the judging unit judges whether the transfer unit receives an operation response message of the router within preset time; if so, the operation unit sends the operation response message of the router returned by the transfer unit to a user, otherwise, the reminding unit sends a reminding message of the abnormal state of the router to the user.
The server is additionally provided with a reminding unit, when a user initiates a request and the server transfers the request to a corresponding router, if the router does not respond within a preset time, the router is likely to have a fault and an abnormal state, at the moment, a reminding message of the abnormal state of the router is sent to the user through the reminding unit, so that the user can take corresponding measures, the scheme is more humanized, and the user experience is improved.
Certainly, because the scheme is established that the server abnormality can be detected only under the condition that a user actively initiates a request to view, if the user wants to actively find the abnormal condition and timely inform the user, a monitoring module can be arranged on the server, and a read operation request is actively initiated to the router under the conditions that the request amount of the server is not large and the network bandwidth is abundant.
The method for forwarding, reading and writing the router network and the server provided by the invention can bring the following beneficial effects:
(1) the speed of directly returning data by the server is high, and the user experience is improved.
(2) The interaction times of the server and the router are reduced, and the pressure of the server is relieved.
(3) After the interaction times are reduced, the data messages are reduced, and the consumption of network bandwidth is reduced.
Drawings
The above features, technical characteristics, advantages and realisations of a slide and easel conversion device will be further described in the following, in a clearly understandable manner, with reference to the accompanying drawings, illustrating preferred embodiments.
Fig. 1 is a flowchart of a first embodiment of a method for forwarding read/write in a router network according to the present invention;
fig. 2 is a flowchart of a second embodiment of a method for forwarding read/write in a router network according to the present invention;
fig. 3 is a flowchart of a third embodiment of a method for forwarding read/write in a router network according to the present invention;
fig. 4 is a block diagram of a first embodiment of a transit server in a router network according to the present invention;
fig. 5 is a block diagram of a second embodiment of a transit server in a router network according to the present invention;
fig. 6 is a block diagram of a third embodiment of a transit server in a router network according to the present invention;
fig. 7 is a block diagram of a fourth embodiment of a transit server in a router network according to the present invention;
fig. 8 is a flowchart of a fourth embodiment of a method for forwarding read/write in a router network according to the present invention;
fig. 9 is a block diagram of a data cache module of the transit server in the router network according to the present invention.
Detailed Description
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following description will be made with reference to the accompanying drawings. It is obvious that the drawings in the following description are only some examples of the invention, and that for a person skilled in the art, other drawings and embodiments can be derived from them without inventive effort.
For the sake of simplicity, the drawings only schematically show the parts relevant to the present invention, and they do not represent the actual structure as a product. In addition, in order to make the drawings concise and understandable, components having the same structure or function in some of the drawings are only schematically illustrated or only labeled. In this document, "one" means not only "only one" but also a case of "more than one".
In one aspect, the present invention provides a network transit read-write method for a router, where a first embodiment of the method is shown in fig. 1, and the method includes the steps of:
s100, receiving a read-write request message of a user;
s200, extracting the router address in the read-write request message, and judging the type of the read-write request message;
when the request message is judged to be a read operation, executing step S300;
when the request message is judged to be a write operation, executing step S400;
s300, searching the cached configuration state data of the router according to the extracted address of the router, and generating a response message of the read operation according to the searched cache configuration state data of the router;
s400 transfers the initiation operation request to the router according to the extracted router address, and transfers the operation response message returned to the router.
In the embodiment, the read operation and the write operation are processed separately, and the configuration information of the router is stored in the cache, so that if the router is a read operation, the configuration information of the corresponding router can be directly found in the cache and then returned to the user. And for the write operation, the write operation request is transferred to the corresponding router through the server to complete the write operation request, and then the corresponding router feeds back the corresponding response message to be transferred to the user through the server.
A second embodiment of the method, shown in fig. 2, comprises the steps of:
s100, receiving a read-write request message of a user;
s200, extracting the router address in the read-write request message, and judging the type of the read-write request message;
when the request message is judged to be a read operation, executing step S310;
when the request message is judged to be a write operation, executing step S400;
s310, judging whether configuration state data of the router is cached or not according to the extracted router address, and if yes, executing the step S320; otherwise, executing step S400;
s320, generating a response message of the read operation according to the searched cache configuration state data of the router;
s400 transfers the initiation operation request to the router according to the extracted router address, and transfers the operation response message returned to the router.
In this embodiment, when the read operation is performed, the requested router configuration information is not cached in the server, and at this time, the configuration information of the router still needs to be obtained by forwarding the configuration information to the corresponding router through the server, so as to be cached and sent to the user.
Preferably, on the basis of the above embodiment, if the state of the router changes once, the changed configuration is sent to the server in real time, so that the server can maintain the latest router configuration.
Preferably, the cache configuration state data of the router cached by the server is stored in a form of < Key, Value >, wherein the address of the router is used as Key, and the configuration item is used as Value. The MAC address of the router is used as an index, and then the configuration of the router is stored, and the configuration is divided according to functions. Each piece of data is stored according to the form of < K, V >, K is Key, V is Value, MAC address is Key, configuration item is corresponding Value, Value is stored by JSON format, for example, the router has the configuration of function1, function2 and function 3. { "function 1": value1 "," function2 ": value 2", "function 3": value3 "}. The storage is convenient for subsequent search, so that the feedback speed is higher.
A third embodiment of the method, as shown in fig. 3, comprises the steps of:
s100, receiving a read-write request message of a user;
s200, extracting the router address in the read-write request message, and judging the type of the read-write request message;
when the request message is judged to be a read operation, executing step S300;
when the request message is judged to be a write operation, executing step S410;
s300, searching the cached configuration state data of the router according to the extracted address of the router, and generating a response message of the read operation according to the searched cache configuration state data of the router;
s410, transferring and initiating a request to the router according to the address of the router;
s420, judging whether an operation response message of the router is received within preset time; if yes, go to step S430, otherwise go to step S440;
s430 transferring the operation response message returned to the router;
s440 judges the state of the router is abnormal, and generates and sends the abnormal message of the router.
In this embodiment, when a write operation is added to the first embodiment, it is determined whether the router has a response within a predetermined time, so as to find whether the router is abnormal.
Of course, the determination may also be performed on the basis of embodiment 2, that is, it can be determined whether the router is abnormal or not only when the user initiates the request and the server needs to initiate the request to the router.
Of course, preferably, the server may also actively initiate a read operation request to the router when the request amount is small and the network bandwidth is sufficient, on one hand, if the fed back router configuration information changes, the configuration information of the router may be updated, on the other hand, if the fed back router configuration information does not change, the abnormal state of the router may be timely discovered and actively sent to the user, so that the user may also know the abnormal state information of the router in time without sending a request. This preferred scheme not only improves the user experience, but also does not create a burden on the server.
On the other hand, the present invention further provides a network transit server of a router, where a first embodiment of the server is shown in fig. 4, and the server includes: the message processing module 20 is respectively connected with the receiving module 10 and the buffer module 30, the message processing module 20 includes an extracting unit 21, a judging unit 22, a transferring unit 24 and an operating unit 23, the operating unit 23 is respectively connected with the extracting unit 21, the judging unit 22 and the transferring unit 24, the operating unit 23 is further connected with the extracting unit 21 and the judging unit 22, wherein:
the receiving module 10 receives a read-write request of a user;
the extracting unit 21 extracts the router address in the read-write request message, and the judging unit 22 judges the type of the read-write request message;
when the determining unit 22 determines that the request message is a read operation, the operating unit 23 searches the configuration status data of the router cached by the cache module 30 according to the address of the router extracted by the extracting unit 21, and generates a response message of the read operation according to the searched cache configuration status data of the router and returns the response message to the user;
when the judging unit 22 judges that the request message is a write operation, the relay unit 24 initiates a write operation request to the router according to the router address extracted by the extracting unit 21, and the operating unit 23 sends a write operation response message of the router returned by the relay unit 24 to the user.
The receiving module 10 is mainly used for receiving a request of a user, and is equivalent to providing an interface accessed by the user, and the server acquires the request information of the user from the interface. The message processing module 20 performs corresponding operation processing on the request information, and the cache module 30 is used for caching the configuration state information of each router for the message processing module 20 to call.
After the receiving module 10 receives a request of a user, for example, an APP request, the message processing module 20 extracts an MAC address in the message, where the MAC address is an MAC address of a corresponding router, and determines a message type, and if the message is a read operation, requests data from a cache and directly returns the data; if the user initiates the write operation, a request needs to be initiated to the router, then the router is waited to return the message, and the message is sent to the APP after being received. The reading operation is to read the information of the device, such as the device state, the device list and other configuration information, and the cache module 30 caches the configuration state information of the router, so the message processing module 20 can directly return the configuration information of the router to the user after querying the cache module 30, thereby reducing the number of times of interaction with the router, alleviating the pressure of the server, having high feedback speed, and improving the user experience.
Preferably, when the determining unit 22 determines that the request message is a read operation, the determining unit 22 further determines whether the cache module 30 caches configuration state data of the router according to the router address extracted by the extracting unit 21, if so, the operating unit 23 searches the configuration state data of the router cached by the cache module 30, and generates a response message of the read operation according to the searched cache configuration state data of the router and returns the response message to the user; if not, the relay unit 24 initiates a read operation request to the router according to the router address extracted by the extraction unit 21, and the operation unit 23 sends a read operation response message of the router returned by the relay unit 24 to the user.
The relay module in this embodiment is equivalent to a small message route, and after the judgment module judges correspondingly, the relay module sends request messages sent by different users to different routers. The operation module is mainly used for processing request information which can be returned by directly searching the cache data of the server and feeding back a response message returned by the transfer module to the user.
A second embodiment of the server is shown in fig. 5, and based on the first embodiment, the server further includes an updating module, where the updating module is connected to the message processing module 20 and the cache module 30, and after the state of the router changes, the router actively sends the changed configuration information to the updating module to update in the cache module 30.
Preferably, the configuration status data of the router in the cache module 30 is stored in a form of < Key, Value >, where the address of the router is used as Key and the configuration item is used as Value. The router configuration information is stored with the MAC address of the router as an index, and then the configuration of the router is stored, the configuration being divided by function. Each piece of data is stored according to the form of < K, V >, K is Key, V is Value, MAC address is Key, and configuration item is corresponding Value.
A third embodiment of the server is shown in fig. 6, and on the basis of the above embodiment, the message processing module 20 further includes a reminding unit; the reminding unit is connected with the judging unit 22, and after the forwarding unit 24 sends a request to the router, when the router has no feedback message within a preset time, the reminding unit sends a reminding message to the user, so that the user experience is improved.
Preferably, a monitoring module may be provided on the server, and under the condition that the request amount of the server is not large and the network bandwidth is sufficient, a read operation request is actively initiated to the router, on one hand, the obtained feedback information may be used to update the configuration state information of the router cached by the caching module 30 in time, and on the other hand, if the feedback information is not obtained, the server may actively send a prompt of abnormal state to a corresponding user.
Finally, as shown in fig. 7, the fourth embodiment of the network transit server of the present invention mainly includes the following modules:
the APP Access interface 401: the module functions to provide an HTTP interface for APP access.
The device connection module 402: the module is used for connecting with the equipment, a TCP long connection is established between the equipment and the server, and the server communicates with the equipment through the channel.
The message processing module 403: the role is responsible for message routing, and because the system needs to support concurrent processing, different requests of different clients need to be processed simultaneously, and the server needs to send corresponding messages to corresponding devices, so that a message routing function is needed.
The data caching module 404: the function is to store the configuration information of the device, and when the configuration of the device is changed, the configuration information needs to be updated.
The specific implementation of the main modules is described in detail below:
the flow chart of the message processing module is shown in fig. 8, and the main steps are described as follows:
waiting for an APP request, if the APP initiates the request, extracting a MAC address in the message, wherein the MAC address is the MAC address of the corresponding router, and the server determines which router device the message is sent to according to the MAC address.
Judging the type of the message, if the message is read, requesting data from the cache, if the data exists in the cache, the request is successful, the server directly returns, and if the request is unsuccessful, the corresponding data does not exist in the cache, and then the request is initiated to the equipment.
If the APP initiates write operation, a request needs to be initiated to the device, then the device is waited to return a message to the server, and the server sends the message to the APP after receiving the message.
Fig. 9 is a structure of a data cache module, and as can be seen from the figure, the MAC address of the router is used as an index, and then the configuration of the router is stored, and the configuration is divided according to functions. Each piece of data is stored according to the form of < K, V >, K is Key, V is Value, MAC address is Key, configuration item is corresponding Value, Value is stored by JSON format, for example, the router has the configuration of function1, function2 and function 3. { "function 1": value1 "," function2 ": value 2", "function 3": value3 "}.
It should be noted that the above embodiments can be freely combined as necessary. The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.