Skip to main content

SimClock

Struct SimClock 

Source
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

Source

pub fn new() -> Self

Create a new simulation clock starting at 0.

Source

pub fn now_us(&self) -> u64

Get the global simulation time in microseconds.

Source

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.

Source

pub fn advance_us(&mut self, delta_us: u64)

Advance the global clock by the given number of microseconds.

Source

pub fn advance_ms(&mut self, delta_ms: u64)

Advance by milliseconds.

Source

pub fn set_node_skew(&mut self, node_id: NodeId, skew_us: i64)

Set the clock skew for a specific node.

Source

pub fn get_node_skew(&self, node_id: NodeId) -> i64

Get the current skew for a node.

Source

pub fn set_us(&mut self, time_us: u64)

Set the global clock to an absolute value.

Source

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.

Source

pub fn step_jump(&mut self, node_id: NodeId, delta_us: i64)

Apply an instantaneous step jump (NTP correction, VM clock correction).

Source

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.

Source

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.

Source

pub fn is_frozen(&self, node_id: NodeId) -> bool

Check if a node’s clock is frozen.

Source

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.

Source

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.

Source

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.

Source

pub fn reset(&mut self)

Reset the clock to zero and clear all skews.

Trait Implementations§

Source§

impl Default for SimClock

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.