Linux – Is it possible to virtualize the clock for an experimental NTP time offset

date timelinuxntpvirtual machine

I have a project that wishes to force the times of a set of private NTP servers to demonstrate how NTP (and our software) reacts to various time changes and differences, network lag, etc.

Normally, we'd set up a virtual network of VMs to demonstrate our software, but I can't seem to find one that will allow NTP to run independently in each VM. For this we'd need a software clock.

So far, I've looked at:

  • Docker – ties their clock to the hardware clock of the host, privileges are one issue, but the main issue is that if the clock is changed all clocks running in all VMs on that host are changed.

  • VirtualBoxThis answer suggests that even with guest-additions, the lack of a high-resolution clock would make this impossible.

Is there any software that can virtualize a hardware clock for NTP, or otherwise run independent clocks on the same machine at the same time?

Best Answer

It is not clear if you are interested in

  • how ntp behaves under some set of circumstances.

  • how your software behaves due to time changes and you have decided the best way to introduce these time changes is fiddling with ntp.

If you are simply interested in the former check out ntpdsim. It is part of the ntp reference implementation:

The ntpdsim program is used to simulate and study the behavior of an NTP daemon that derives its time from a number of different simulated time sources (servers). Each simulated server can be configured to have a different time offset, frequency offset, propagation delay, processing delay, network jitter and oscillator wander.

If you are interested in the later, use ntpdsim to see how your ntp servers will react to the changes. Then take this information and use a cronjob or something similar to modify the clocks on your vms according to the information you learned from the ntpdsim runs...

https://www.eecis.udel.edu/~mills/ntp/html/ntpdsim_new.html

Related Question