Detailed Description
The embodiment of the invention provides a dual-computer hot standby communication method, which is realized based on a multicast technology, so that devices of two communicating parties can mutually negotiate respective master-slave types, and the reliability and the availability of a system can be improved. The embodiment of the invention also provides corresponding equipment. The following detailed description is made with reference to the accompanying drawings, respectively.
The first embodiment,
The dual-computer hot-standby Communication method provided by the embodiment of the invention can be applied to the field of intelligent transportation or Dedicated Short Range Communication (DSRC), and particularly can be applied to a dual-computer hot-standby Communication system.
Referring to fig. 1, the dual-server hot-standby communication system 100 includes a first device 110 and a second device 120 respectively joining different multicast groups, and the first device 110 and the second device 120 communicate with each other through an interactive multicast packet. Physically, the first device 110 and the second device 120 may be connected through a plurality of connection methods, for example, a serial port, an ethernet, or a parallel port.
Referring to fig. 2, a dual-computer hot-standby communication method provided in an embodiment of the present invention includes:
210. the first equipment sends a first negotiation data packet to the second equipment, and the master-slave type of the first equipment is identified as undefined in the first negotiation data packet.
220. And setting the first equipment as a host or a standby according to the response result of the second equipment.
Wherein, if the first device is set as a host, as shown in fig. 3, the method further includes:
230. and sending a third negotiation data packet to the second device, wherein the master-slave type of the first device is identified as a host in the third negotiation data packet so as to indicate the second device to set itself as a standby device.
By adopting the method, the devices of the two sides of the dual-computer hot standby communication can realize the arbitration and negotiation of the master-slave type or the master-slave identity. The master-slave type comprises a master type, a slave type and an undefined type, wherein the master type is a master machine, and the slave type is a standby machine.
In the above method, a frame format of a multicast packet that is interacted between the first device and the second device, for example, the first or third negotiation packet, is shown in table 1:
TABLE 1
Length of |
Master slave type |
Type of command |
Status of state |
BCC check |
Data of |
The description of each data field in the frame format is shown in table 2:
TABLE 2
When the value of the command type data field is 0, the multicast data packet is the negotiation data packet.
In an embodiment, the setting 220 the first device as the host or the standby device according to the response result of the second device may specifically include:
if a second negotiation data packet responded by the second equipment is not received within preset time, setting the first equipment as a host;
and if a second negotiation data packet responded by the second equipment is received within preset time, acquiring the master-slave type of the second equipment from the second negotiation data packet, and setting the first equipment as a host or a standby according to the master-slave type of the second equipment.
Further, the setting the first device as a host or a standby according to the master-slave type of the second device may include:
if the master-slave type of the second equipment is a standby machine, setting the first equipment as a host machine;
if the master-slave type of the second equipment is the host, setting the first equipment as a standby machine;
if the master-slave type of the second device is undefined, the IP addresses of the first device and the second device are further obtained and compared, when the IP address value of the first device is larger, the first device is set as a host, and when the IP address value of the first device is smaller, the first device is set as a standby.
In one embodiment, 220 or 230 may further include:
240. the method comprises the steps that first equipment periodically sends a first heartbeat data packet identifying the health condition of the first equipment to second equipment, and receives a second heartbeat data packet identifying the health condition of the second equipment, which is periodically sent by the second equipment; and the first device can also re-determine the master-slave type according to the health conditions or the master-slave types of the two parties.
Referring to table 1 and table 2, when the value of the command type data field in the multicast data packet is 1, the multicast data packet is a heartbeat data packet, such as the first or second heartbeat data packet. The first device and the second device may obtain their own master-slave type and health status, and obtain the master-slave type and health status of the other device from a heartbeat packet sent by the other device, so that when the health status and master-slave type of the two devices change, a corresponding preset action may be executed according to a preset policy, as described in detail below.
And if the first equipment fails to receive the second heartbeat data packet within the specified time, or the second heartbeat data packet is received within the specified time, and the health condition of the second equipment is found to be abnormal, the first equipment reports abnormal information to the upper computer.
When the first device is the host, if the health condition of the first device is found to be abnormal, the first device is set as a standby machine, and then a first heartbeat data packet which identifies that the master-slave type of the first device is the standby machine is sent to the second device, so that the second device is indicated to be set as the host and the health condition of the first device is reported to an upper computer.
When the first device is currently the host, if a master-slave switching command sent by an upper computer is received, the first device is reset as the standby computer, and a first heartbeat data packet identifying that the master-slave type of the first device is the standby computer is sent to the second device, so that the second device is indicated to be set as the host. The main/standby switching command can be manually sent by the upper computer, so that the identity exchange of the main/standby computers can be manually intervened.
Optionally, if the first device does not receive a second heartbeat data packet returned by the second device within a preset time after sending the first heartbeat data packet identifying that the master-slave type of the first device is the standby device, the first device resets itself as the host, and then sends the first heartbeat data packet identifying that the master-slave type of the first device is the host to the second device.
And when the first equipment is the standby equipment currently, if a second heartbeat data packet sent by the second equipment is not received within preset time or a second heartbeat data packet which identifies that the master-slave type of the second equipment is the standby equipment is received, changing the first equipment into the host. Then, the master-slave type of the master-slave type is identified as the master in the first heartbeat data packet sent to the opposite side. In one embodiment, the current host may be restarted, so that the standby machine cannot receive the heartbeat data packet of the host within a preset time, and the standby machine will actively switch to the host.
In the foregoing, the embodiment of the present invention provides a dual-computer hot-standby communication method, which is implemented based on a multicast technology, so that devices of two communicating parties can negotiate respective master and slave types through interacting multicast data packets, thereby improving reliability and availability of a system. By adopting the method, the following technical effects can be realized: (1) the arbitration and negotiation of the main and standby identities are simply and reliably realized; (2) the transmission and sharing of the health condition information in the heartbeat data packet are reliably realized; (3) active exchange of the main and standby identities is realized.
Example II,
An embodiment of the present invention provides an apparatus, and the apparatus and the method may be applied to the field of intelligent transportation or DSRC, and may be specifically used in the dual-computer hot-standby communication system 100 shown in fig. 1. The device may be the first device 110 or the second device 120 of the system.
Referring to fig. 4, the apparatus includes: a sending module 310, configured to send a first negotiation packet to another device, where a master-slave type of the device is identified as undefined in the first negotiation packet; a setting module 320, configured to set the device as a host or a standby according to a response result of the another device.
Optionally, as shown in fig. 5, the apparatus may further include: a receiving module 330.
The receiving module 330 may be configured to receive a second negotiation packet responded by the another device; the setup module 320 includes: a first setting unit, configured to set the device as a host when the receiving unit fails to receive the second negotiation packet within a preset time; and the second setting unit is used for acquiring the master-slave type of the other device from the second negotiation data packet, and setting the device as a host or a standby according to the master-slave type of the other device.
Optionally, the second setting unit may be specifically configured to set the device as a host if the master-slave type of the another device is a standby device; if the master-slave type of the other equipment is the host, setting the equipment as a standby machine; if the master-slave type of the other equipment is undefined, the IP addresses of the equipment and the other equipment are further obtained and compared, if the IP address value of the equipment is larger, the equipment is set as a host, and if the IP address value of the equipment is smaller, the equipment is set as a standby.
In an embodiment, the sending module 310 is further configured to send a third negotiation packet to the another device if the setting module 320 sets the device as a host, where the master-slave type of the device is identified as the host in the third negotiation packet, so as to set the another device as a standby device.
In one embodiment, the sending module 310 is further configured to periodically send a first heartbeat packet carrying the health condition of the device to the other device; the receiving module 330 is further configured to receive a second heartbeat data packet that is periodically sent by the other device and carries the health condition of the other device.
Optionally, the setting module 320 is further configured to, when the device is currently the host, change the device to the standby device if the health condition of the device is found to be abnormal, or if a main/standby switching command sent by an upper computer is received; and the processor is further configured to, when the device is currently the standby device, change the device itself to the host if the second heartbeat packet is not received within a preset time or a second heartbeat packet identifying that the master-slave type of the other device is the standby device is received.
The apparatus provided by the present invention is described above, and please refer to embodiment one in more detail.
In the foregoing, the embodiment of the present invention provides a device for a dual-computer hot-standby communication system, and with the device, the system may implement communication between two devices based on a multicast technology, so that the two devices in communication may negotiate respective master and slave types, thereby improving reliability and availability of the system. By adopting the equipment, the following technical effects can be realized: (1) the arbitration and negotiation of the main and standby identities are simply and reliably realized; (2) the transmission and sharing of the health condition information in the heartbeat data packet are reliably realized; (3) active exchange of the main and standby identities is realized. For a more detailed description of the device, please refer to the description of the first or second device in embodiment one.
Example III,
Referring to fig. 1, an embodiment of the present invention provides a dual-device hot-standby communication system 100, where the system 100 includes a first device 110 and a second device 120 that respectively join different multicast groups, and the first device 110 and the second device 120 communicate with each other through an interactive multicast packet. Physically, the first device 110 and the second device 120 may be connected through a plurality of connection methods, for example, a serial port, an ethernet, or a parallel port. The system can be applied to the fields of intelligent transportation or DSRC.
The first device 110 is configured to send a first negotiation packet to a second device, where the first negotiation packet identifies that a master-slave type of the first device is undefined; and setting the self as a host or a standby according to the response result of the second equipment.
The second device 120 is configured to receive a first negotiation packet sent by the first device 110, and respond to a second negotiation packet to the first device, where the second negotiation packet identifies a master-slave type of the second device 120.
The first device 110 may specifically determine its own master-slave type according to whether a negotiation packet responded by the second device 120 is received or not, and the master-slave type of the second device identified in the received negotiation packet, so as to set itself as a master or a standby. The detailed description of the embodiment refers to the description of the first embodiment.
The first device 110 and the second device 120 may further send heartbeat packets to each other, so as to notify the other party of the health condition of the first device, and determine to report the abnormal information or re-determine the master-slave type of the first device according to the first device and the master-slave type and the health condition of the other party. The detailed description of the embodiment refers to the description of the first embodiment.
In the foregoing, the embodiment of the present invention provides a dual-computer hot-standby communication system, where the system may implement communication between two devices based on a multicast technology, so as to improve reliability of the system, enable the two devices in communication to negotiate respective master-slave types, and improve availability of the system. By adopting the system, the following technical effects can be realized: (1) the arbitration and negotiation of the main and standby identities are simply and reliably realized; (2) the transmission and sharing of the health condition information in the heartbeat data packet are reliably realized; (3) active exchange of the main and standby identities is realized.
Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments may be implemented by hardware, or by hardware associated with program instructions, and the program may be stored in a computer-readable storage medium, and the storage medium may include: read-only memory, random access memory, magnetic or optical disk, and the like.
The dual-computer hot-standby communication method and device provided by the embodiment of the present invention are described in detail above, but the description of the embodiment is only for helping understanding the method and the core idea of the present invention, and should not be construed as limiting the present invention. Those skilled in the art should also appreciate that they can easily conceive of various changes and substitutions within the technical scope of the present disclosure.