UDPClockSynchronizer is a {@link ClockSynchronizer} that sends pings as UDP datagrams, and uses the following simplealgorithm to perform clock synchronization:
- Slave initiates synchronization with a Reference clock.
- Slave stamps current local time on a "time request" message and sends to the Reference.
- Upon receipt by Reference, Reference stamps Reference-time and returns.
- Upon receipt by Slave, Slave subtracts current time from sent time and divides by two to compute latency. It subtracts current time from Reference time to determine Slave-Reference time delta and adds in the half-latency to get the correct clock delta.
- The first result is immediately used to update the clock since it will get the local clock into at least the right ballpark.
- The Slave repeats steps 2 through 4, 15 more times.
- The results of the packet receipts are accumulated and sorted in lowest-latency to highest-latency order. The median latency is determined by picking the mid-point sample from this ordered list.
- All samples outside 1 standard-deviation from the median are discarded and the remaining samples are averaged using an arithmetic mean.
The use of UDP datagrams, instead of TCP based communication eliminates the hidden delays that TCP can introduce, as it can transparently re-order or re-send packets, or introduce delays as packets are naggled.
CRC Card Responsibilities | Collaborations |
---|
Trigger a clock synchronziation. |
Compute a clock delta to apply to the local clock. |
Estimate the error in the synchronzation. |