pub struct SimClock { /* private fields */ }Expand description
A deterministic clock with virtual time and per-node skew.
Time is in microseconds and only advances when explicitly told to. No wall-clock access — all time is virtual.
Implementations§
Source§impl SimClock
impl SimClock
Sourcepub fn node_now_us(&self, node_id: NodeId) -> u64
pub fn node_now_us(&self, node_id: NodeId) -> u64
Get the time as seen by a specific node (global time + skew). If the node is frozen, returns the frozen time.
Sourcepub fn advance_us(&mut self, delta_us: u64)
pub fn advance_us(&mut self, delta_us: u64)
Advance the global clock by the given number of microseconds.
Sourcepub fn advance_ms(&mut self, delta_ms: u64)
pub fn advance_ms(&mut self, delta_ms: u64)
Advance by milliseconds.
Sourcepub fn set_node_skew(&mut self, node_id: NodeId, skew_us: i64)
pub fn set_node_skew(&mut self, node_id: NodeId, skew_us: i64)
Set the clock skew for a specific node.
Sourcepub fn get_node_skew(&self, node_id: NodeId) -> i64
pub fn get_node_skew(&self, node_id: NodeId) -> i64
Get the current skew for a node.
Sourcepub fn drift(
&mut self,
node_id: NodeId,
drift_us_per_sec: i64,
elapsed_secs: u64,
)
pub fn drift( &mut self, node_id: NodeId, drift_us_per_sec: i64, elapsed_secs: u64, )
Apply clock drift: accumulate skew as if the node drifts at a given rate.
Sourcepub fn step_jump(&mut self, node_id: NodeId, delta_us: i64)
pub fn step_jump(&mut self, node_id: NodeId, delta_us: i64)
Apply an instantaneous step jump (NTP correction, VM clock correction).
Sourcepub fn freeze(&mut self, node_id: NodeId)
pub fn freeze(&mut self, node_id: NodeId)
Freeze a node’s clock at its current time. While frozen, the node’s time does not advance when global time advances.
Sourcepub fn unfreeze(&mut self, node_id: NodeId)
pub fn unfreeze(&mut self, node_id: NodeId)
Unfreeze a node’s clock. The node resumes from where it was frozen,
adjusting skew so node_now_us continues from the frozen time.
Sourcepub fn warp(&mut self, node_id: NodeId, target_us: u64)
pub fn warp(&mut self, node_id: NodeId, target_us: u64)
Warp a node’s clock to an arbitrary absolute time.
This sets the node’s skew so that node_now_us returns the target time.
Sourcepub fn inject_leap_second(&mut self, node_id: NodeId)
pub fn inject_leap_second(&mut self, node_id: NodeId)
Inject a positive leap second on a node. The node’s clock repeats 1 second (jumps backward by 1_000_000 us), simulating a UTC leap second insertion.
Sourcepub fn inject_negative_leap_second(&mut self, node_id: NodeId)
pub fn inject_negative_leap_second(&mut self, node_id: NodeId)
Inject a negative leap second on a node. The node’s clock skips 1 second forward (jumps forward by 1_000_000 us), simulating a UTC leap second deletion.