CN104202204B - Clock synchronization control method, apparatus and system based on SNTP - Google Patents
Clock synchronization control method, apparatus and system based on SNTP Download PDFInfo
- Publication number
- CN104202204B CN104202204B CN201410505363.0A CN201410505363A CN104202204B CN 104202204 B CN104202204 B CN 104202204B CN 201410505363 A CN201410505363 A CN 201410505363A CN 104202204 B CN104202204 B CN 104202204B
- Authority
- CN
- China
- Prior art keywords
- address
- clock
- clock sync
- sntp
- sync client
- 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
Links
Landscapes
- Synchronisation In Digital Transmission Systems (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses a kind of clock synchronization control method based on SNTP, apparatus and system, wherein method includes:Clock sync client obtains the IP address of at least one clock sync server, and IP address is stored in address pool;Then according to default clock sync server IP address distribution principle, an IP address is selected from address pool as the IP address of destination server;SNTP unitcast request messages are sent to destination server according still further to selected IP address, the SNTP response messages that the destination server is sent are received;Finally, the time deviation between the clock sync client and the destination server is calculated, and clock synchronization process is realized according to the time deviation.It can either be ensured the synchronous reliability of clock, the complexity of clock synchronous control system and the workload of later maintenance can be reduced again by way of the IP address by Dynamic Discovery clock sync server the above method.
Description
Technical field
The present invention relates to field of industrial automation control, more particularly to a kind of clock synchronization control method based on SNTP,
Apparatus and system.
Background technology
In field of industrial automation control, control system generally comprises active station, control station, collecting device etc..Wherein,
Active station is, for entering the equipment that row information is exchanged with user, centralized operation and monitoring to be played a part of in whole production process.
Control station is that continuous control, batch control and sequential control are carried out to production process, and is capable of the equipment of independent operating.At this
In control system, active station and control station need strict clock synchronously to ensure the normal operation of whole system, therefore
Active station and control station are usually collectively referred to as clock sync client, and by the equipment referred to as clock for providing clock source
Sync server.
In the prior art, control system is normally based on SNTP (Simple Network Time
Protocol, SNTP) in unicast mode, need to issue by configuration download or configuration in all clock sync clients
Mode, be pre-configured with the IP address of clock sync server, then clock sync client operation configuration pass through unicast mode
Set time with time synchronized server, it is possible to realize that the clock of whole system is synchronous.But this mode can often exist following
Problem:
First, when the IP address of clock sync server changes, or when clock sync server can not be normal
During work, may result in whole system can not realize that clock is synchronous.
Second, because clock sync client is the IP address by static configuration clock sync server, this static state
Configuration mode can not realize the redundancy selection of clock sync server, so as to cause the reliability of system not high.
The content of the invention
In view of this, it is an object of the invention to provide the clock synchronization control method based on SNTP, apparatus and system, with
Realize the synchronous reliability of client clock and the purpose of accuracy in control system.
To achieve the above object, the present invention provides following technical scheme:
In a first aspect, the invention provides a kind of clock synchronization control method based on SNTP, including:
Clock sync client obtains the IP address of at least one clock sync server, and IP address is stored in into address
Chi Zhong;
The clock sync client is selected according to default clock sync server IP address distribution principle from address pool
An IP address is selected as the IP address of destination server;
The clock sync client sends SNTP unitcast request messages according to selected IP address to destination server,
Receive the SNTP response messages that the destination server is sent;
Timestamp of the clock sync client in the SNTP unitcast requests message, SNTP response messages when
Between stamp, the reception time for sending time and SNTP response message times of SNTP unitcast request messages, calculate the clock synchronous
Time deviation between client and the destination server;
The clock sync client realizes clock synchronization process according to the time deviation.
It is preferred that, the clock sync client obtains the process bag of the IP address of at least one clock sync server
Include:
The clock sync client intercepts the SNTP broadcast synchronization messages of clock sync server transmission, from the message
Obtain the IP address of clock sync server;And/or
The clock sync client sends SNTP broadcast query messages, receives the response report that clock sync server is sent
Text, obtains the IP address of clock sync server from the response message.
It is preferred that, the clock sync client is according to default clock sync server IP address distribution principle, from ground
An IP address is selected to include as the process of the IP address of destination server in the pond of location:
The clock sync client is according to the minimum principle of domain addresses, the minimum IP of domain addresses is selected from address pool
Location as destination server IP address;Or,
The clock sync client is according to the maximum principle of domain addresses, the maximum IP of domain addresses is selected from address pool
Location as destination server IP address;Or,
The clock sync client selects device address minimum according to the minimum principle in device address from address pool
IP address as destination server IP address;Or,
The clock sync client selects device address maximum according to the maximum principle in device address from address pool
IP address as destination server IP address.
It is preferred that, the step of clock sync client realizes clock synchronization process according to the time deviation includes:
When the clock sync client judges that the time deviation is more than threshold value, or the clock sync client
Time be less than destination server time when, the clock sync client adjusts itself clock based on the time deviation;
When the time of the clock sync client being more than the time of destination server, the clock sync client is temporary
Time of the stoppage in transit row clock until being synchronized to destination server.
It is preferred that, send SNTP unicasts to destination server according to selected IP address in the clock sync client
After request message, methods described also includes:
Whether the clock sync client monitoring receives the SNTP that the destination server is sent in preset time
Response message;If it is, performing the time deviation calculated between the clock sync client and the destination server
Operation;
Otherwise, the clock sync client first deletes selected IP address from the address pool and updates address
Pond, is performed according to default clock sync server IP address distribution principle again, selects an IP address to make from address pool
For the operation of the IP address of destination server.
It is preferred that, when the clock sync client is not received by what the destination server was sent in preset time
During SNTP response messages, methods described includes:
The clock sync client sends a warning message, and the warning information is used to notify target described in operating personnel to take
Business device breaks down.
It is preferred that, the clock sync client sends SNTP unicasts according to selected IP address to destination server please
The step of asking message, the SNTP response messages that the reception destination server is sent includes:
The clock sync client sends SNTP unitcast request messages according to predetermined period to the destination server, and
The SNTP unitcast request messages of preset number are sent every time, receive the SNTP response messages that the destination server is sent;
Then the clock sync client realizes that clock synchronization process is specifically included according to the time deviation:
The clock sync client removes maximum and minimum value from multiple time deviations, asks for the remaining time inclined
The arithmetic mean of instantaneous value of difference, utilizes the arithmetic mean of instantaneous value synchronised clock.
It is preferred that, when multiple clock sync clients need clock synchronous, then when each clock sync client staggers
Between send SNTP unitcast request messages.
Second aspect, the present invention also provides a kind of clock synchronous control device based on SNTP, including:
Address acquisition unit, for controlling clock sync client to obtain the IP of at least one clock sync server
Location, and IP address is stored in address pool;
Destination server selecting unit, for controlling the clock sync client according to default clock sync server
IP address distribution principle, selects an IP address as the IP address of destination server from address pool;
Synchronization request unit, for controlling the clock sync client according to selected IP address to destination server
SNTP unitcast request messages are sent, the SNTP response messages that the destination server is sent are received;
Time deviation computing unit, for controlling the clock sync client according in the SNTP unitcast requests message
Timestamp, the timestamp of SNTP response messages, SNTP unitcast request messages send time and SNTP response message times
The reception time, calculate the time deviation between the clock sync client and the destination server;
Clock synchronization unit, for controlling the clock sync client to be realized according to the time deviation at clock synchronization
Reason.
It is preferred that, the address acquisition unit includes:
First address acquisition subelement, for controlling the clock sync client to intercept the transmission of clock sync server
SNTP broadcast synchronization messages, obtain the IP address of clock sync server from the message;And/or
Second address acquisition subelement, for controlling the clock sync client to send SNTP broadcast query messages, connects
The response message that time receiving clock sync server is sent, obtains the IP address of clock sync server from the response message.
It is preferred that, the destination server selecting unit is specifically for controlling the clock sync client according to domain addresses
Minimum principle, selects the minimum IP address of domain addresses as the IP address of destination server from address pool;Or,
The destination server selecting unit is specifically for controlling the clock sync client according to domain addresses maximum
Principle, selects the maximum IP address of domain addresses as the IP address of destination server from address pool;Or,
The destination server selecting unit is specifically for controlling the clock sync client minimum according to device address
Principle, the minimum IP address in device address is selected from address pool as the IP address of destination server;Or,
The destination server selecting unit is specifically for controlling the clock sync client maximum according to device address
Principle, the maximum IP address in device address is selected from address pool as the IP address of destination server.
It is preferred that, the clock synchronization unit includes:
Adjust clock subelement, for when the clock sync client judge the time deviation more than threshold value when, or
When the time of clock sync client described in person is less than the time of destination server, the clock sync client is controlled to be based on institute
State time deviation and adjust itself clock;
Suspend clock subelement, for when the clock sync client time be more than destination server time when,
Control time of the clock sync client operation suspension clock until being synchronized to destination server.
It is preferred that, described device also includes:
Monitoring unit, for controlling whether the clock sync client monitoring receives the target in preset time
The SNTP response messages that server is sent;If it is, triggered time deviation computing unit performs corresponding operation;Otherwise, trigger
Address pool management unit;
The address pool management unit, for controlling the clock sync client first to delete selected from the address pool
The IP address selected, is performed according to default clock sync server IP address distribution principle again, and one is selected from address pool
IP address as the IP address of destination server operation.
It is preferred that, described device also includes:
Alarm Unit, for being not received by the destination server in preset time when the clock sync client
During the SNTP response messages of transmission, the clock sync client is controlled to send a warning message, the warning information is used to notify
Destination server described in operating personnel breaks down.
It is preferred that, the synchronization request unit is specifically for controlling the clock sync client according to predetermined period to institute
State destination server and send SNTP unitcast request messages, and send the SNTP unitcast request messages of preset number every time, receive institute
State the SNTP response messages of destination server transmission;
Then the clock synchronization unit is specifically for controlling the clock sync client to be removed from multiple time deviations
Maximum and minimum value, ask for the arithmetic mean of instantaneous value of remaining time deviation, utilize the arithmetic mean of instantaneous value synchronised clock.
The third aspect, present invention also offers a kind of clock synchronous control system based on SNTP, including:The synchronous visitor of clock
Family end, and receive the SNTP unitcast request messages that the clock sync client is sent, and send SNTP response messages when
Clock sync server;The clock synchronous control device based on SNTP is provided with wherein described clock sync client.
It can be seen from above-mentioned technical scheme in embodiments of the present invention, clock sync client is obtained at least first
The IP address of one clock sync server, and IP address is stored in address pool;It can realize that automatic discovery clock is synchronous
Server address, without static networking configuration, so as to reduce the complexity of networking and the workload of later maintenance.Then, clock
Sync server selects an IP address conduct according to default clock sync server IP address distribution principle from address pool
The IP address of destination server, can select that the clock sync server of clock synchronous service can be provided from current network;
Subsequently, clock sync server sends SNTP unitcast request messages to selected destination server, receives the destination service
The SNTP response messages that device is sent, timestamp that clock sync server just can be in message, send message time and
The time of message is received, time deviation is calculated, finally, it is same that clock sync client can be realized as clock using the time deviation
Step;Understand in summary:Technical solution of the present invention passes through Dynamic Discovery clock sync server without static configuration IP address
The mode of IP address, can either ensure the synchronous reliability of clock, can reduce again clock synchronous control system complexity and
The workload of later maintenance.
Brief description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing
There is the accompanying drawing used required in technology description to be briefly described, it should be apparent that, drawings in the following description are only this
Some embodiments of invention, for those of ordinary skill in the art, on the premise of not paying creative work, can be with
Other accompanying drawings are obtained according to these accompanying drawings.
Fig. 1 is the flow chart of the embodiment 1 of clock synchronization control method of the embodiment of the present invention based on SNTP;
Fig. 2 is the flow chart of the embodiment 2 of clock synchronization control method of the embodiment of the present invention based on SNTP;
Fig. 3 is the flow chart of the embodiment 1 of clock synchronous control device of the embodiment of the present invention based on SNTP;
Fig. 4 is the schematic diagram of the embodiment 1 of clock synchronous control system of the embodiment of the present invention based on SNTP.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out clear, complete
Site preparation is described, it is clear that described embodiment is only a part of embodiment of the invention, rather than whole embodiments.It is based on
Embodiment in the present invention, it is every other that those of ordinary skill in the art are obtained under the premise of creative work is not made
Embodiment, belongs to the scope of protection of the invention.
Refering to Fig. 1, Fig. 1 is the flow chart of the embodiment 1 of clock synchronization control method of the embodiment of the present invention based on SNTP;
As shown in figure 1, this method comprises the following steps:
S101, clock sync client obtains the IP address of at least one clock sync server, and IP address is preserved
In address pool;
When implementing, in order that all clock sync clients get the IP address of clock sync server,
It is same that clock sync server in control system can send SNTP broadcast to all clock sync clients in a broadcast manner
Walk message.Then clock sync client can intercept the SNTP broadcast synchronization messages of clock sync server transmission, from the message
The middle IP address for obtaining corresponding clock sync server.Clock sync server is comprised at least in SNTP broadcast synchronization messages
IP address, send the information such as timestamp of SNTP broadcast synchronization messages.
When implementing, in order that clock sync client is obtained after electrifying startup or in any need, can
Start synchronizing process at any time, clock sync client can also actively send SNTP broadcast query messages, receive clock and synchronously take
The SNTP response messages that business device is sent, obtain the IP address of clock sync server from the SNTP response messages.It is described
Including at least the IP address of clock sync server, the timestamp for sending SNTP response messages, reception in SNTP response messages
The information such as the timestamp of SNTP broadcast query messages.
When implementing, in order to improve the reliability that clock sync client obtains clock sync server IP address,
Above two mode can also be used simultaneously.
Wherein timestamp can be comprising it is more than the second, summation time of time below second and second, for example, clock sync client
It is 12.38.20.25 that end, which sends the timestamp included in SNTP broadcast synchronization messages,.Wherein, divided according to decimal point, 20
It it is the time of more than second 38 points when representing 12 for the time of the position of second, i.e. second, 12.38;25 represent 25 milliseconds, are below the second
Time.More than second, the summation of time below second and second when constituting 12 38 points 20 seconds 25 milliseconds, as clock sync client is sent out
Send the SNTP times of broadcast synchronization message.
S102, the clock sync client is according to default clock sync server IP address distribution principle, from address
An IP address is selected in pond as the IP address of destination server;
When implementing, due in field of industrial automation control, its clock for being used of different control system
Sync server IP address distribution principle may be different, therefore will be based on actual clock sync server IP when implementing
Address distribution principle, selects destination server, i.e. can provide the server of clock synchronous service;In view of in order to meet
The synchronous reliability of clock sync client clock in control system, generally, can pre-establish multiple clocks synchronous
Server is to meet redundancy requirement.So, after S101, clock sync client is with may getting at least one IP
Location, for the ease of subsequent clock simultaneously operating, clock sync client needs to set up an address pool, and (database is used to protect
Deposit address), all IP address got are maintained in this address pool.
When implementing, the present embodiment additionally provides following several clock sync server IP address point simple and easy to apply
With principle, and for these distribution principles S102 specific implementation procedure.
The first distribution principle is that the distribution principle based on domain addresses minimum in whole control system is every in system
Individual clock sync server distributes IP address, so after distribution, each clock sync server compared in system other set
For standby, the domain addresses of its IP address is always less than the domain addresses of other equipment IP address, therefore, the clock sync client
According to the principle that domain addresses is minimum, the minimum IP address of domain addresses is selected from address pool as the IP address of destination server.
Second of distribution principle is that the distribution principle based on domain addresses maximum in whole control system is every in system
Individual clock sync server distributes IP address, so after distribution, each clock sync server compared in system other set
For standby, domain addresses of the domain addresses always greater than other equipment IP address of its IP address, therefore, the clock sync client
According to the principle that domain addresses is maximum, the maximum IP address of domain addresses is selected from address pool as the IP address of destination server.
The third distribution principle is, based on the minimum distribution principle in device address in system in whole control system
Each clock sync server distribution IP address, so after distribution, each clock sync server compared in system other
For equipment, the device address in its IP address is always less than the device address in other equipment IP address, therefore, the clock
Sync client is according to the minimum principle in device address, and the IP address for selecting device address minimum from address pool takes as target
The IP address of business device.
4th kind of distribution principle is, based on being assigned as in system according to device address maximum in whole control system
Each clock sync server distribution IP address, so after distribution, each clock sync server compared in system other
For equipment, device address of the domain addresses always greater than other equipment IP address of its IP address, therefore, the synchronous visitor of the clock
Family end is according to the maximum principle in device address, and the IP address for selecting device address maximum from address pool is used as destination server
IP address.
Certainly, when implementing, control system according to other IP address distribution principles, then S102 just correspond to by
Operation is performed according to the distribution principle.
S103, the clock sync client sends SNTP unitcast requests according to selected IP address to destination server
Message, receives the SNTP response messages that the destination server is sent;
When implementing, the clock sync client uses point-to-point communication mode, is sent to destination server
SNTP unitcast request messages, the destination server is received after SNTP unitcast request messages, to the clock sync client
Send in SNTP response messages, the SNTP response messages and receive SNTP unitcast request messages including at least clock sync server
Timestamp, send the information such as timestamp of SNTP response messages.
When implementing, if when the clock sync client and abnormal clock sync server point-to-point communication, institute
State clock sync client and SNTP request messages are sent using broadcast mode, the clock sync server is corresponding using broadcast
Mode sends SNTP response messages.
When implementing, the clock sync client can send SNTP unitcast request messages according to predetermined period,
And preset number SNTP unitcast request messages are sent every time, receive the SNTP response messages that the destination server is sent.For
For the destination server, when often receiving a SNTP request message, just a SNTP is sent to clock sync client
Response message.Therefore, clock sync client can receive the SNTP response messages of preset number.
S104, timestamp, SNTP response report of the clock sync client in the SNTP unitcast requests message
The timestamp of text, the reception time for sending time and SNTP response message times of SNTP unitcast request messages, when calculating described
Time deviation between clock sync client and the destination server;
When implementing, if clock sync client only sends a SNTP request message, the synchronous visitor of the clock
Family end only receives the SNTP response messages that a clock sync server is sent, then calculates clothes synchronous with the clock according to S104
Time deviation between business device, a time deviation is obtained so as to calculate;
When implementing, if clock sync client periodically sends SNTP unitcast request messages, and send every time
The SNTP unitcast request messages of preset number, then clock sync client may receive clock sync server transmission two
Individual or two or more SNTP response messages, now, clock sync client are then calculated and clock sync server according to S104
Between time deviation, obtain two or more time deviations so as to calculate.
S105, the clock sync client realizes clock synchronization process according to the time deviation.
When implementing, when clock sync client, which is calculated, obtains a clock jitter, then the time is directly utilized
Deviation realizes that clock is synchronous;If calculating obtains two clock jitters, an average value can be asked for, the average value is recycled
Realize that clock is synchronous;If calculating obtains two or more clock jitter, maximum and minimum value can be removed, when asking for residue
The arithmetic mean of instantaneous value of clock deviation, recycles the arithmetic mean of instantaneous value to realize that clock is synchronous.
When implementing, control system has certain requirement to the clock precision of clock sync client, therefore
Need targetedly to perform simultaneously operating during actual synchronization, in addition, sometimes the clock of clock sync client walk it is fast,
Clock sync server may be faster than;What sometimes the clock of clock sync client was walked is slow, may slowly with clock synchronous service
Device;For different clock out of step conditions, it is necessary to using different clock synchronization modes.Specifically, the step S105
Implementation procedure at least comprises the following steps:
When the clock sync client judges that the time deviation is more than threshold value, or the clock sync client
Time be less than destination server time when, the clock sync client adjusts itself clock based on the time deviation;
When the time of the clock sync client being more than the time of destination server, the clock sync client is temporary
Time of the stoppage in transit row clock until being synchronized to destination server.
Therefore, in the embodiment of the present invention, clock sync client obtains at least one clock sync server first
IP address, and IP address is stored in address pool;Automatic discovery clock sync server address can be realized, without static state
Networking is configured, so as to reduce the complexity of networking and the workload of later maintenance.Then, clock sync server is according to default
Clock sync server IP address distribution principle, selects an IP address as the IP address of destination server from address pool,
It can select that the clock sync server of clock synchronous service can be provided from current network;Subsequently, clock synchronous service
Device sends SNTP unitcast request messages to selected destination server, receives the SNTP response reports of destination server transmission
Text, timestamp, the time of transmission message and the time for receiving message that clock sync server just can be in message, is calculated
Time deviation, finally, it is synchronous that clock sync client can be realized as clock using the time deviation;Understand in summary:This
Inventive technique scheme, can by way of the IP address of Dynamic Discovery clock sync server without static configuration IP address
Enough ensure the synchronous reliability of clock, the complexity of clock synchronous control system and the workload of later maintenance can be reduced again.
In view of when implementing clock sync server it may be caused due to the hardware or software fault of burst
Clock synchronous service can not be provided, such as clock sync client sends SNTP request messages to selected destination server,
But the SNTP response messages that the destination server is sent are not received by preset time, then show the destination server
Can due to self reason or because network reason causes it can not now provide clock synchronous service, in such a scenario, when
Clock sync client can not just realize that clock is synchronous using the destination server;In order to ensure that clock sync client performs clock
Synchronous reliability, the embodiment of the present invention provides a kind of clock synchronization control method based on SNTP again, specifically participates in Fig. 2,
Fig. 2 is the flow chart of the embodiment 2 of clock synchronization control method of the embodiment of the present invention based on SNTP;Figure it is seen that should
Method at least comprises the following steps:
S201, clock sync client obtains the IP address of at least one clock sync server, and IP address is preserved
In address pool;
S202, the clock sync client is according to default clock sync server IP address distribution principle, from address
An IP address is selected in pond as the IP address of destination server;
S203, the clock sync client sends SNTP unitcast requests according to selected IP address to destination server
Message;
S201~S203 is identical with S101~S103, will not be repeated here.
Whether S204, the clock sync client monitoring receives what the destination server was sent in preset time
SNTP response messages;If not, S205 is performed, if it is, performing S206;
S205, the clock sync client first deletes selected IP address from the address pool and updates address
Pond, then S202 is transferred to, perform again according to default clock sync server IP address distribution principle, one is selected from address pool
Individual IP address as the IP address of destination server operation.If when going to S204 and being still not received by, then performed
S205, so circulation are performed untill receiving the SNTP response messages that a destination server is sent.
When implementing, clock sync client is with can periodically obtaining the IP of at least one clock sync server
Location, can also monitored address pond, when the IP address in monitored address pond be less than preset number when, clock sync client is opened at once
The operation of the dynamic IP address for obtaining clock sync server, and then address pool is updated, to ensure to have certain amount in address pool
IP address, it is ensured that the normal execution of whole synchronizing process.
Further, if being not received by the SNTP response messages of destination server transmission in preset time,
Show now the destination server failure, it may be possible to hardware, software or network failure, now need repairing personnel and
When overhaul, the normal operation of whole system can be ensured, based on this, when the clock sync client does not have in preset time
When having the SNTP response messages for receiving the destination server transmission, methods described includes:
The clock sync client sends a warning message, and the warning information is used to notify target described in operating personnel to take
Business device breaks down.
S206, timestamp, SNTP response report of the clock sync client in the SNTP unitcast requests message
The timestamp of text, the reception time for sending time and SNTP response message times of SNTP unitcast request messages, when calculating described
Time deviation between clock sync client and the destination server;
S207, the clock sync client realizes clock synchronization process according to the time deviation.
When implementing, in order to improve the reliability using clock jitter synchronised clock, the clock sync client
Can be according to predetermined period to destination server transmission SNTP unitcast request messages, and the SNTP of preset number is sent every time
Unitcast request message, receives the SNTP response messages that the destination server is sent;That is, described clock sync client is periodically
Synchronization request is initiated, each cycle sends NGE SNTP unitcast request messages, during one section of each SNTP unitcast requests message interval
Between.Such as:The clock sync client initiated a SNTP unitcast request message at interval of 5 minutes, and 5 SNTP are sent every time
Unitcast request message bag, every inter-packet gap 5 seconds.After so handling, clock sync client, which can be calculated, obtains multiple clock jitters,
In order to improve synchronization dependability.
, then can be with when there is multiple clock sync clients to be required for synchronous into row clock in system when implementing
Each clock sync client staggering time is set to send SNTP unitcast request messages, i.e., when each clock sync client is initiated
The clock synchronous time staggers, and can so reduce network burst flow, reduces the possibility of network congestion.
Then S207 is specially that the clock sync client removes maximum and minimum value from multiple time deviations, is asked for
The arithmetic mean of instantaneous value of remaining time deviation, utilizes the arithmetic mean of instantaneous value synchronised clock.
If only calculating and obtaining three time deviations, its average value is directly calculated, is using the average value synchronised clock
Can.
Therefore, in the embodiment of the present invention, clock sync client obtains at least one clock sync server first
IP address, and IP address is stored in address pool;Automatic discovery clock sync server address can be realized, without static state
Networking is configured, so as to reduce the complexity of networking and the workload of later maintenance.Then, clock sync server is according to default
Clock sync server IP address distribution principle, selects an IP address as the IP address of destination server from address pool,
It can select that the clock sync server of clock synchronous service can be provided from current network;Subsequently, clock synchronous service
Device sends SNTP unitcast request messages to selected destination server, receives the SNTP response reports of destination server transmission
Text, timestamp, the time of transmission message and the time for receiving message that clock sync server just can be in message, is calculated
Time deviation, finally, it is synchronous that clock sync client can be realized as clock using the time deviation;Understand in summary:This
Inventive technique scheme, can by way of the IP address of Dynamic Discovery clock sync server without static configuration IP address
Enough ensure the synchronous reliability of clock, the complexity of clock synchronous control system and the workload of later maintenance can be reduced again.
Further, the embodiment of the present invention is by monitoring the SNTP that destination server is sent whether is received in preset time
Response message, with judge destination server whether can normal work, if can not if synchronously taken from new one clock of selection
Device be engaged in as destination server, the reliability of simultaneously operating is further ensured that using the monitoring mechanism and gravity treatment mechanism.
It is corresponding with the above method, the invention also discloses a kind of clock synchronous control device based on SNTP, referring to
Fig. 3, Fig. 3 are the flow charts of the embodiment 1 of clock synchronous control device of the embodiment of the present invention based on SNTP, as shown in figure 3, should
Device may include that address acquisition unit 301, destination server selecting unit 302, synchronization request unit 303, time deviation are calculated
Unit 304 and clock synchronization unit;
Wherein address acquisition unit 301, for controlling clock sync client to obtain at least one clock sync server
IP address, and IP address is stored in address pool;
Destination server selecting unit 302, synchronously takes for controlling the clock sync client according to default clock
Business device IP address distribution principle, selects an IP address as the IP address of destination server from address pool;
Synchronization request unit 303, for controlling the clock sync client to be taken according to selected IP address to target
Business device sends SNTP unitcast request messages, receives the SNTP response messages that the destination server is sent;
Time deviation computing unit 304, for controlling the clock sync client according to the SNTP unitcast requests report
During timestamp, the timestamp of SNTP response messages, the transmission time of SNTP unitcast request messages and SNTP response messages in text
Between the reception time, calculate the time deviation between the clock sync client and the destination server;
Clock synchronization unit 305, realizes that clock is same for controlling the clock sync client according to the time deviation
Step processing.
Specifically, the address acquisition unit includes:
First address acquisition subelement, for controlling the clock sync client to intercept the transmission of clock sync server
SNTP broadcast synchronization messages, obtain the IP address of clock sync server from the message;And/or
Second address acquisition subelement, for controlling the clock sync client to send SNTP broadcast query messages, connects
The response message that time receiving clock sync server is sent, obtains the IP address of clock sync server from the response message.
Specifically, the destination server selecting unit is specifically for controlling the clock sync client according to domain addresses
Minimum principle, selects the minimum IP address of domain addresses as the IP address of destination server from address pool;Or,
The destination server selecting unit is specifically for controlling the clock sync client according to domain addresses maximum
Principle, selects the maximum IP address of domain addresses as the IP address of destination server from address pool;Or,
The destination server selecting unit is specifically for controlling the clock sync client minimum according to device address
Principle, the minimum IP address in device address is selected from address pool as the IP address of destination server;Or,
The destination server selecting unit is specifically for controlling the clock sync client maximum according to device address
Principle, the maximum IP address in device address is selected from address pool as the IP address of destination server.
Specifically, the clock synchronization unit 305 includes:Clock subelement and pause clock subelement are adjusted,
Clock subelement is wherein adjusted, for judging that the time deviation is more than threshold value when the clock sync client
When, or time of the clock sync client is when being less than the time of destination server, controls the clock sync client
Itself clock is adjusted based on the time deviation;
Suspend clock subelement, for when the clock sync client time be more than destination server time when,
Control time of the clock sync client operation suspension clock until being synchronized to destination server.
Specifically, described device can also include:
Monitoring unit, for controlling whether the clock sync client monitoring receives the target in preset time
The SNTP response messages that server is sent;If it is, triggered time deviation computing unit performs corresponding operation;Otherwise, trigger
Address pool management unit;
The address pool management unit, for controlling the clock sync client first to delete selected from the address pool
The IP address selected, is performed according to default clock sync server IP address distribution principle again, and one is selected from address pool
IP address as the IP address of destination server operation.
Specifically, described device can also include:Alarm Unit, for when the clock sync client is in preset time
When being inside not received by the SNTP response messages that the destination server is sent, the clock sync client is controlled to send alarm
Information, the warning information is used to notify destination server described in operating personnel to break down.
Specifically, the synchronization request unit is specifically for controlling the clock sync client according to predetermined period to institute
State destination server and send SNTP unitcast request messages, and send the SNTP unitcast request messages of preset number every time, receive institute
State the SNTP response messages of destination server transmission;
Then the clock synchronization unit is specifically for controlling the clock sync client to be removed from multiple time deviations
Maximum and minimum value, ask for the arithmetic mean of instantaneous value of remaining time deviation, utilize the arithmetic mean of instantaneous value synchronised clock.
Each refinement function of above-mentioned unit or module can be found in the related record of the above method, not go to live in the household of one's in-laws on getting married herein
State.
It should be noted that above-mentioned each unit, the function of module can be realized respectively by multiple single CPU or single-chip microcomputer,
Also can be only by a CPU or chip microcontroller each unit, the function of module.
Therefore, in embodiments of the present invention, using address acquisition unit, destination server selecting unit, synchronously please
Unit, time deviation computing unit and clock synchronization unit collective effect are asked, to realize without static configuration IP address, by dynamic
State finds the mode of the IP address of clock sync server, can either ensure the synchronous reliability of clock, can reduce clock again
The complexity of synchronous control system and the workload of later maintenance.
It is corresponding with above-mentioned control method and control device, it is based on SNTP clocks the embodiment of the invention also discloses one kind
Synchronous control system, including clock sync client, and receive the SNTP unitcast requests that the clock sync client is sent
Message, and send the clock sync server of SNTP response messages;It is provided with and is based in wherein described clock sync client
SNTP clock synchronous control device.
Specifically, the number of clock sync client can be for 1 or multiple, the number of clock sync server can be 1
It is individual or multiple.In this embodiment, as shown in figure 4, Fig. 4 is clock synchronous control system of the embodiment of the present invention based on SNTP
Embodiment 1 schematic diagram, as shown in figure 4, in the system clock sync client number be 4, clock sync server
Number be 3, its clock synchronous control device based on SNTP is placed in clock sync client, wherein, the synchronous visitor of clock
Family end can be communicated by high-speed bus with clock sync server.
In industrial control field when implementing, clock sync server can be GPS device or by industry
Runs software clock sync server in active station in system, i.e. regard active station as clock sync server.Clock is synchronous
Client can be that active station, control station in industrial control system etc. need the equipment of synchronised clock.
The wherein clock synchronous control device based on SNTP, clock sync client, each refinement of clock sync server
Function can be found in the related record of the above method, and therefore not to repeat here.
It should be noted that herein, term " comprising ", "comprising" or its any other variant are intended to non-row
His property is included, so that stage, method, article or equipment including a series of key elements not only include those key elements, and
And also including other key elements being not expressly set out, or also include for this stage, method, article or equipment institute inherently
Key element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that including institute
Also there is other identical element in stage, method, article or the equipment of stating key element.
Can one of ordinary skill in the art will appreciate that realizing that all or part of step in above method embodiment is
To be completed by the related hardware of programmed instruction, described program can be stored in computer read/write memory medium, this
In alleged storage medium, such as:ROM/RAM, magnetic disc, CD etc..
The foregoing description of the disclosed embodiments, enables professional and technical personnel in the field to realize or using the present invention.
A variety of modifications to these embodiments will be apparent for those skilled in the art, as defined herein
General Principle can be realized in other embodiments without departing from the spirit or scope of the present invention.Therefore, it is of the invention
The embodiments shown herein is not intended to be limited to, and is to fit to and principles disclosed herein and features of novelty phase one
The most wide scope caused.
Claims (14)
1. a kind of clock synchronization control method based on SNTP, it is characterised in that including:
Clock sync client obtains the IP address of at least one clock sync server, and IP address is stored in into address pool
In;
The clock sync client selects one according to default clock sync server IP address distribution principle from address pool
Individual IP address as destination server IP address;
The clock sync client sends SNTP unitcast request messages according to selected IP address to destination server, receives
The SNTP response messages that the destination server is sent;
Timestamp of the clock sync client in the SNTP unitcast requests message, the time of SNTP response messages
The reception time for sending time and SNTP response message times of stamp, SNTP unitcast request messages, calculate the synchronous visitor of the clock
Time deviation between family end and the destination server;
Whether the clock sync client monitoring receives the SNTP responses that the destination server is sent in preset time
Message;
If it is, the clock sync client realizes clock synchronization process according to the time deviation;
Otherwise, the clock sync client first deletes selected IP address from the address pool and updates address pool, then
Secondary execution selects an IP address to be used as target according to default clock sync server IP address distribution principle from address pool
The operation of the IP address of server.
2. according to the method described in claim 1, it is characterised in that it is same that the clock sync client obtains at least one clock
Walking the process of the IP address of server includes:
The clock sync client intercepts the SNTP broadcast synchronization messages of clock sync server transmission, is obtained from the message
The IP address of clock sync server;And/or
The clock sync client sends SNTP broadcast query messages, receives the response message that clock sync server is sent,
The IP address of clock sync server is obtained from the response message.
3. according to the method described in claim 1, it is characterised in that the clock sync client is synchronous according to default clock
Server ip address distribution principle, selects an IP address as the process bag of the IP address of destination server from address pool
Include:
The clock sync client selects the minimum IP address of domain addresses to make according to the minimum principle of domain addresses from address pool
For the IP address of destination server;Or,
The clock sync client selects the maximum IP address of domain addresses to make according to the maximum principle of domain addresses from address pool
For the IP address of destination server;Or,
The clock sync client is according to the minimum principle in device address, the minimum IP in device address is selected from address pool
Location as destination server IP address;Or,
The clock sync client is according to the maximum principle in device address, the maximum IP in device address is selected from address pool
Location as destination server IP address.
4. according to the method described in claim 1, it is characterised in that the clock sync client is real according to the time deviation
The step of existing clock synchronization process, includes:
When the clock sync client judge the time deviation be more than threshold value when, or the clock sync client when
Between be less than destination server time when, the clock sync client adjusts itself clock based on the time deviation;
When the time of the clock sync client being more than the time of destination server, the clock sync client pause fortune
Time of the row clock until being synchronized to destination server.
5. according to the method described in claim 1, it is characterised in that when the clock sync client does not have in preset time
When receiving the SNTP response messages that the destination server is sent, methods described includes:
The clock sync client sends a warning message, and the warning information is used to notify destination server described in operating personnel
Break down.
6. according to the method described in claim 1, it is characterised in that the clock sync client is according to selected IP address
The step of sending SNTP unitcast request messages, the SNTP response messages that the reception destination server is sent to destination server is wrapped
Include:
The clock sync client sends SNTP unitcast request messages according to predetermined period to the destination server, and every time
The SNTP unitcast request messages of preset number are sent, the SNTP response messages that the destination server is sent are received;
Then the clock sync client realizes that clock synchronization process is specifically included according to the time deviation:
The clock sync client removes maximum and minimum value from multiple time deviations, asks for remaining time deviation
Arithmetic mean of instantaneous value, utilizes the arithmetic mean of instantaneous value synchronised clock.
7. according to the method described in claim 1, it is characterised in that when multiple clock sync clients need clock synchronous,
Then each clock sync client staggering time sends SNTP unitcast request messages.
8. a kind of clock synchronous control device based on SNTP, it is characterised in that including:
Address acquisition unit, for controlling clock sync client to obtain the IP address of at least one clock sync server, and
IP address is stored in address pool;
Destination server selecting unit, for controlling the clock sync client according to default clock sync server IP
Location distribution principle, selects an IP address as the IP address of destination server from address pool;
Synchronization request unit, for controlling the clock sync client to be sent according to selected IP address to destination server
SNTP unitcast request messages, receive the SNTP response messages that the destination server is sent;
Time deviation computing unit, for control the clock sync client in the SNTP unitcast requests message when
Between stamp, the timestamp of SNTP response messages, the reception for sending time and SNTP response message times of SNTP unitcast request messages
Time, calculate the time deviation between the clock sync client and the destination server;
Clock synchronization unit, clock synchronization process is realized for controlling the clock sync client according to the time deviation;
Monitoring unit, for controlling whether the clock sync client monitoring receives the destination service in preset time
The SNTP response messages that device is sent;If it is, triggered time deviation computing unit performs corresponding operation;Otherwise, address is triggered
Pond administrative unit;
The address pool management unit, for controlling the clock sync client first to delete selected from the address pool
IP address, is performed according to default clock sync server IP address distribution principle again, an IP is selected from address pool
Location as the IP address of destination server operation.
9. device according to claim 8, it is characterised in that the address acquisition unit includes:
First address acquisition subelement, for controlling the clock sync client to intercept the SNTP of clock sync server transmission
Broadcast synchronization message, obtains the IP address of clock sync server from the message;And/or
Second address acquisition subelement, for controlling the clock sync client to send SNTP broadcast query messages, during reception
The response message that clock sync server is sent, obtains the IP address of clock sync server from the response message.
10. device according to claim 8, it is characterised in that
The destination server selecting unit specifically for controlling the clock sync client according to the minimum principle of domain addresses,
The minimum IP address of domain addresses is selected from address pool as the IP address of destination server;Or,
The destination server selecting unit specifically for controlling the clock sync client according to the maximum principle of domain addresses,
The maximum IP address of domain addresses is selected from address pool as the IP address of destination server;Or,
The destination server selecting unit is specifically for controlling the clock sync client according to the minimum original in device address
Then, the minimum IP address in device address is selected from address pool as the IP address of destination server;Or,
The destination server selecting unit is specifically for controlling the clock sync client according to the maximum original in device address
Then, the maximum IP address in device address is selected from address pool as the IP address of destination server.
11. device according to claim 8, it is characterised in that the clock synchronization unit includes:
Adjust clock subelement, for when the clock sync client judge the time deviation more than threshold value when, Huo Zhesuo
When the time for stating clock sync client is less than the time of destination server, when the control clock sync client is based on described
Between deviation adjusting itself clock;
Suspend clock subelement, for when the time of the clock sync client being more than the time of destination server, controlling
Time of the clock sync client operation suspension clock until being synchronized to destination server.
12. device according to claim 8, it is characterised in that described device also includes:
Alarm Unit, for being sent when the clock sync client is not received by the destination server in preset time
SNTP response messages when, control the clock sync client to send a warning message, the warning information is used to notify to operate
Destination server described in personnel breaks down.
13. device according to claim 8, it is characterised in that
The synchronization request unit is specifically for controlling the clock sync client according to predetermined period to the destination service
Device sends SNTP unitcast request messages, and sends the SNTP unitcast request messages of preset number every time, receives the destination service
The SNTP response messages that device is sent;
Then the clock synchronization unit is specifically for controlling the clock sync client to remove maximum from multiple time deviations
Value and minimum value, ask for the arithmetic mean of instantaneous value of remaining time deviation, utilize the arithmetic mean of instantaneous value synchronised clock.
14. a kind of clock synchronous control system based on SNTP, it is characterised in that including clock sync client, and receive
The SNTP unitcast request messages that the clock sync client is sent, and send the clock sync server of SNTP response messages;
Set and synchronously controlled just like the clock based on SNTP described in any one of claim 8~13 in wherein described clock sync client
Device processed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410505363.0A CN104202204B (en) | 2014-09-26 | 2014-09-26 | Clock synchronization control method, apparatus and system based on SNTP |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410505363.0A CN104202204B (en) | 2014-09-26 | 2014-09-26 | Clock synchronization control method, apparatus and system based on SNTP |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104202204A CN104202204A (en) | 2014-12-10 |
CN104202204B true CN104202204B (en) | 2017-10-10 |
Family
ID=52087434
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410505363.0A Active CN104202204B (en) | 2014-09-26 | 2014-09-26 | Clock synchronization control method, apparatus and system based on SNTP |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104202204B (en) |
Families Citing this family (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106157129B (en) * | 2015-04-17 | 2020-02-07 | 阿里巴巴集团控股有限公司 | Method and device for realizing cross-time domain consistency of distributed system |
CN105119679B (en) * | 2015-09-24 | 2017-09-29 | 烽火通信科技股份有限公司 | A kind of method and system for realizing that SNTP client times are synchronous |
CN108833047A (en) * | 2018-08-13 | 2018-11-16 | 东软集团股份有限公司 | Method for synchronizing time, device, readable storage medium storing program for executing and electronic equipment |
CN112346512A (en) * | 2020-11-09 | 2021-02-09 | 北京沃东天骏信息技术有限公司 | Time synchronization method and device |
CN112737844A (en) * | 2020-12-28 | 2021-04-30 | 浙江中控技术股份有限公司 | Method and device for switching between main and standby in redundant system |
CN114520707B (en) * | 2022-01-24 | 2024-05-24 | 中银金融科技有限公司 | Clock synchronization method and related equipment |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2005069521A1 (en) * | 2004-01-09 | 2005-07-28 | Thomson Licensing | Time synchronizing device and process and associated products |
CN1863156A (en) * | 2005-10-25 | 2006-11-15 | 华为技术有限公司 | Method and system for providing clock synchronization by packet network |
CN101136738A (en) * | 2007-10-08 | 2008-03-05 | 中控科技集团有限公司 | Network clock synchronous method, device and system |
CN103023596A (en) * | 2012-12-04 | 2013-04-03 | 上海斐讯数据通信技术有限公司 | Method for achieving synchronization of network device and time server |
CN202940822U (en) * | 2012-11-28 | 2013-05-15 | 中国舰船研究设计中心 | Marine local area network time unification system |
CN104052565A (en) * | 2014-06-26 | 2014-09-17 | 青岛海信移动通信技术股份有限公司 | Time synchronization method and communication terminal |
-
2014
- 2014-09-26 CN CN201410505363.0A patent/CN104202204B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2005069521A1 (en) * | 2004-01-09 | 2005-07-28 | Thomson Licensing | Time synchronizing device and process and associated products |
CN1863156A (en) * | 2005-10-25 | 2006-11-15 | 华为技术有限公司 | Method and system for providing clock synchronization by packet network |
CN101136738A (en) * | 2007-10-08 | 2008-03-05 | 中控科技集团有限公司 | Network clock synchronous method, device and system |
CN202940822U (en) * | 2012-11-28 | 2013-05-15 | 中国舰船研究设计中心 | Marine local area network time unification system |
CN103023596A (en) * | 2012-12-04 | 2013-04-03 | 上海斐讯数据通信技术有限公司 | Method for achieving synchronization of network device and time server |
CN104052565A (en) * | 2014-06-26 | 2014-09-17 | 青岛海信移动通信技术股份有限公司 | Time synchronization method and communication terminal |
Also Published As
Publication number | Publication date |
---|---|
CN104202204A (en) | 2014-12-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104202204B (en) | Clock synchronization control method, apparatus and system based on SNTP | |
US11520808B2 (en) | System and method for synchronizing data between communication devices in a networked environment without a central server | |
CN103024060B (en) | Open type cloud computing monitoring system for large scale cluster and method thereof | |
WO2019061720A1 (en) | Data synchronization method and system | |
US11228520B2 (en) | Distributed database for synchronizing the accessibility of nodes and shared devices | |
CN104821870B (en) | Clock synchronizing method based on main website intelligent grid supporting system technology | |
US20170371832A1 (en) | Method for clock synchronization of an industrial internet field broadband bus | |
US10120673B2 (en) | Method and device for remotely updating application program | |
CN110798276B (en) | Time synchronization method and system for SDN (software defined network) of intelligent substation | |
CN105634784A (en) | Method, device and system for distributing control data | |
CN110138876B (en) | Task deployment method, device, equipment and platform | |
CN105471622A (en) | High-availability method and system for main/standby control node switching based on Galera | |
CN105245381A (en) | Cloud server downtime monitoring migration system and method | |
CN103973809A (en) | Data distributing method and system | |
US11075813B2 (en) | Proactively deploying analytics to a computerized edge device | |
CN111726388A (en) | Cross-cluster high-availability implementation method, device, system and equipment | |
CN114531373A (en) | Node state detection method, node state detection device, equipment and medium | |
WO2019080386A1 (en) | Network service management method and system | |
KR101435181B1 (en) | Time synchronization and transmission delay time correction method between the master and the slave of intelligent power distribution system | |
CN109639777A (en) | Data synchronous method, apparatus, system and non-volatile memory medium | |
KR20170014344A (en) | Energy management system | |
CN102638787B (en) | A kind of railroad track monitoring sensor node collocation method | |
JP2012064130A (en) | Data replication management method of distributed system | |
CN207382353U (en) | Cloud computing system | |
US10237345B2 (en) | Apparatus and method for data synchronizing of energy management system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right | ||
TR01 | Transfer of patent right |
Effective date of registration: 20190514 Address after: 310053 No. 309 Liuhe Road, Binjiang District, Hangzhou City, Zhejiang Province Co-patentee after: Zhejiang University Patentee after: Zhongkong Technology Co., Ltd., Zhejiang Address before: 310053 Zhejiang Binjiang District Hangzhou six Road 309 central control science and Technology Park (high tech Zone) Patentee before: Zhongkong Technology Co., Ltd., Zhejiang |