PTP Simulation Utils¶
- class ptp.rtc.Rtc(nom_freq_hz, resolution_ns, tol_ppb=0.0, norm_var_freq_rw=0.0, norm_var_time_rw=0.0, label='RTC', ts_quantization=True)[source]¶
Real-time Clock (RTC) Model
The model incorporates random-walk frequency noise and random-walk time noise. These are controlled by the normalized variance of the frequency offset random-walk iid step (norm_var_freq_rw) and the normalized variance of the time offset random-walk (norm_var_time_rw). Importantly, these normalized variances are ultimately multiplied by the update period of the model as suggested in [1].
References:
G. Giorgi and C. Narduzzi, “Performance Analysis of Kalman-Filter-Based Clock Synchronization in IEEE 1588 Networks,” in IEEE Transactions on Instrumentation and Measurement, vol. 60, no. 8, pp. 2902-2909, Aug. 2011.
- Parameters
nom_freq_hz – Nominal frequency (Hz) of the driving clock
resolution_ns – Timestamp resolution in nanoseconds
tol_ppb – Frequency tolerance in ppb
norm_var_freq_rw – Freq. offset random-walk’s normalized variance
norm_var_time_rw – Time offset random-walk’s normalized variance
label – RTC label
ts_quantization – Enables quantization of the time scale
- update(t_sim, evts=None)[source]¶
Update the RTC time
When the event heap queue is passed by argument, it is assumed that the caller controls events using this queue. In this case, this function always schedules the next update to the RTC driving clock frequency.
- Parameters
t_sim – absolute simulation time in seconds
evts – Event heap queue
- class ptp.mechanisms.DelayReqResp(seq_num, t1)[source]¶
Delay request-response mechanism
- Parameters
seq_num – Sequence number
t1 – Sync departure timestamp
- static log(r, level=10, logger=<Logger DelayReqResp (WARNING)>)[source]¶
Print results
- Parameters
r – Dictionary with results
level – Logging level to use when printing
logger – Logger object
- static log_header(level=10, logger=<Logger DelayReqResp (WARNING)>)[source]¶
Print logging header
- Parameters
level – Logging level to use when printing
logger – Logger object
- process()[source]¶
Process all four timestamps
Wrap-up the delay request-response exchange by computing the associated metrics with the four collected timestamps.
- Returns
Dictionary with resulting metrics
- set_backward_delay(seq_num, delay)[source]¶
Save the “true” slave-to-master one-way delay
This truth comes from the difference of RTC timestamps.
- Parameters
seq_num – Sequence number
delay – Slave-to-master delay
- set_forward_delay(seq_num, delay)[source]¶
Save the “true” master-to-slave one-way delay
This truth comes from the difference of RTC timestamps. Hence, although close, it still suffers from uncertainties and quantization.
- Parameters
seq_num – Sequence number
delay – Master-to-slave delay
- set_t2(seq_num, t2)[source]¶
Set Sync arrival timestamp
- Parameters
seq_num – Sequence number
t2 – Sync arrival timestamp
- set_t3(seq_num, t3)[source]¶
Set Delay_Req departure timestamp
- Parameters
seq_num – Sequence number
t3 – Delay_Req departure timestamp
- set_t4(seq_num, t4)[source]¶
Set Delay_Req departure timestamp
- Parameters
seq_num – Sequence number
t4 – Delay_Req departure timestamp
- set_true_toffset(master_tstamp, slave_tstamp)[source]¶
Save the true time offset
Given two simultaneously-taken timestamps from master and slave clocks, compute the true time offset at the instant corresponding to the given timestamps.
- Parameters
master_tstamp – Timestamp from the master RTC
slave_tstamp – Timestamp from the slave RTC
- class ptp.messages.PtpEvt(name, period_sec=None, pdv_distr='Gamma', gamma_shape=None, gamma_scale=None)[source]¶
PTP Event Message
Controls transmission and reception of a PTP event message. When the message is periodically transmitted (Sync), a period must be passed by argument. Otherwise, transmission must be scheduled manually.
- Parameters
name – Message name
period_sec – Transmission period in seconds
pdv_distr – PDV distribution
gamma_shape – Shape parameter of the Gamma distribution
gamma_scale – Scale parameter of the Gamma distribution
- rx(sim_time, rx_rtc_tstamp, tx_rtc_tstamp)[source]¶
Receive Message
Process the reception of the message. Take a timestamp from the RTC of the receiver, and also measure the true one-way delay of the message by using a snapshot from the RTC of the message transmitter.
- Parameters
sim_time – Simulation time in seconds
rx_rtc_tstamp – Timestamp from RTC of message receiver
tx_rtc_tstamp – Timestamp from RTC of message transmitter
- Returns
True when effectively received
- class ptp.simulation.Simulation(n_iter=100, sim_t_step=1e-09, sync_period=0.0625, rtc_clk_freq=125000000.0, rtc_resolution=0, freq_tolerance=60, freq_rw=1e-18, phase_rw=1e-12, pdv_distr='Gamma', gamma_shape=None, gamma_scale=None, ts_quantization=True)[source]¶
PTP Simulation class
- Parameters
n_iter – Number of iterations
sim_t_step – Simulation time step in seconds
sync_period – Sync transmission period in seconds
rtc_clk_freq – RTC clock frequency in Hz
rtc_resolution – RTC representation resolution in ns
freq_tolerance – Slave RTC frequency tolerance in ppb
freq_rw – Normalized variance of the frequency offset random-walk presented by the slave RTC.
phase_rw – Normalized variance of the phase offset random-walk presented by the slave RTC.
pdv_distr – PTP message PDV distribution (Gamma or Gaussian)
gamma_shape – Shape parameter of the Gamma distribution
gamma_scale – Scale parameter of the Gamma distribution
ts_quantization – Enables quantization of the time scale
- dump()[source]¶
Dump simulation metadata and data into stdout
Simulation data is printed according to the logging level.
- load(filename)[source]¶
Load simulation data and metadata from compressed file
- Parameters
filename – Path to the dataset