Title: NTP Procedure Descriptions and Flow Diagrams
1NTP Procedure Descriptions and Flow Diagrams
- David L. Mills
- University of Delaware
- http//www.eecis.udel.edu/mills
- mailtomills_at_udel.edu
2Process decomposition
Server 1
Peer/Poll 1
Selection and Clustering Algorithms
SystemProcess
Clock Discipline Process
Combining Algorithm
Server 2
Peer/Poll 2
Loop Filter
Server 3
Peer/Poll 3
VFO
RemoteServers
Peer/PollProcesses
Clock Adjust Process
- Peer process runs when a packet is received.
- Poll process sends packets at intervals
determined by the clock discipline process and
remote server. - System process runs when a new peer process
update is received. - Clock discipline process runs at intervals
determined by the measured network phase jitter
and clock oscillator (VFO) frequency wander. - Clock adjust process runs at intervals of one
second.
3Time values and computations
Packet Variables
Peer Variables
System Variables
S
S
Client
S
Server
- Packet variables are computed directly from the
packet header. - Peer variables are groomed by the clock filter.
- System variables are groomed from the available
peers.
4NTP packet header format
Packet headerVariables Description
Strat
Poll
LI
Mode
VN
Prec
Root Delay
leap leap indicator (LI)version version number
(VN)mode protocol modestratum stratumt poll
interval (log2 s)r clock reading precision (log2
s)D root delayE root dispersionrefid reference
IDreftime reference timestampT1 originate
timestamp T2 receive timestamp T3 transmit
timestampT4 destination timestampMAC MD5
message hash (optional)
Root Dispersion
Reference Identifier
Reference Timestamp (64)
Originate Timestamp (64)
Receive Timestamp (64)
Transmit Timestamp (64)
MAC (optional 160)
Strictly speaking, T4 is not a packet variable
it is the value of the system clock upon arrival.
5NTP peer protocol
- Packet header includes T1, T2 and T3 timestamps.
- Peer state variables org, rec and xmt record the
transmit and receive times of the most recent
packet received. - When a packet is transmitted
- Copy org to T1 and rec to T2.
- Copy the current time to xmt and to T3.
- When a packet received
- If T3 is the same as xmt, this is a duplicate
packet. - If T1 is not the same as org, this is a bogus
packet. - Otherwise, copy T3 to pkt and copy the current
time to rec. - Note that the protocol is symmetric and allows
time values to flow both ways and is resistant to
replays and drops. - Note the special conditions when either or both
peers first start up.
6NTP peer protocol example
t2
t3
t6
t7
0
t3
t5.
t1
PacketVariables Peer B StateVariables
T1
0
t4
t2
t6
T2
t5.
t1
t3 clock
t7 clock
T3
t2 clock
t6 clock
T4
State VariablesName Description
t5
t5?
org
t1
0
t6
t6
rec
t2
t2
org originate timestamp rec receive
timestampxmt transmit timestamp
t7
t3?
xmt
t3
0
t3
t2
t6
t7
Packet Header VariablesName Description
t4
t1
t5
t8
t1
t4
t8
t5
tn originate timestamptn1 receive
timestamptn2 transmit timestamptn3 destination
timestamp
t5
t3.
0
t1
PacketVariables Peer A StateVariables
T1
t6
t4
0
t2
T2
t7
t3.
t1 clock
t5 clock
T3
t4 clock
t8 clock
T4
0.
org
t3
t7?
t3?
0
rec
t4
t8
t4
t1
xmt
t5
t5?
t1?
7peer process
- receive procedure
- Verify integrity, authenticity and consistency of
packet data. - Match association by destination IP address and
NTP protocol mode. - crypto_recv procedure
- Implement Autokey proventication protocol
described elsewhere. - packet procedure
- Process receive and transmit timestamps and
symmetric protocol. - Compute clock offset, roundtrip delay and
dispersion sample. - Copy packet header data to peer state variables
- clock_filter procedure
- Select the best from among the past eight
samples. - Calculate filter dispersion, jitter and related
values. - Implement popcorn spike suppressor.
- 7
8Packet sanity tests
9Peer_process variables and procedures
peer processVariables Process Description
peer processProcedures Process Called by
- peer clock offsetd peer roundtrip
delaye peer dispersionj peer jittert peer updat
e epochT peer last update epochm peer time
since last updaterR peer server
precisionDR peer server root delayER peer server
root dispersionorg peer originate
timestamprec peer receive timestampxmt peer tran
smit timestamp leap peer leap indicator
version peer version mode peer modestratum peer
stratumppoll peer peer poll intervalhpoll poll
host poll interval min poll min poll
intervalmax poll max poll intervalclock system s
ystem clockF constant tolerance (15
PPM)lmax constant max distance (16
s)MAXSTRAT constant max stratum (15)
receive peer peerpacket peer peerclock_filter pe
er packet, pollpoll_update poll packet, clock,
polltransmit poll receiveclock_select system clo
ck filter, pollcrypto_recv Autokey peer
10peer process receive procedure
receive
access OK?
no
access deny
peer
yes
format OK?
no
format error
yes
wait for pkt
authMD5
receive
find assoc
go to (association mode, packet mode) found in
transition matrix
Peer Process
receive procedure
11Transition matrix
Packet Mode
Mode ACTIVE PASSIVE CLIENT SERVER BCAST
NO_PEER NEWPS FXMIT NEWMC NEWBC
ACTIVE PROC PROC
PASSIVE PROC ERROR
CLIENT PROC
SERVER
BCAST
BCLIENT ERROR PROC
Association Mode
The default (empty box) behavior is to discard
the packet without comment.
12Transition functions
NEWBC
NEWPS
NEWMC
auth?
auth?
auth?
yes
no
no
yes
yes
no
mobilize BCLIENT association
mobilize PASSIVE association
exit
mobilize CLIENT association
exit
crypto_recv
PROC
PROC
exit
FXMIT
ERROR
transmit
reset
exit
exit
13peer process timestamp processing
PROC
xmt 0?
yes
invalid
no
yes
xmt T3?
duplicate pkt
no
mode BCST
T1andT2 0?
T1orT2 0?
no
yes
invalid
no
yes
no
yes
org T1?
no
yes
reset
auth?
bad
auth?
auth?
yes
bad
ok
ok
bad
auth error
orgT1recT2xmtT3
auth error
exit
orgT1recT2xmtT3
crypto_recv
bad
crypto error
ok
packet
exit
14peer process packet procedure
Packet header related valuesPacket Process Peer
packet
leap peer leapversion peer version
mode peer modestratum peer stratumpoll peer ppo
ll rR peer rRDR peer DRER peer ERrefid peer r
efidreftime peer reftime
header?
bad
header error
ok
copy header
poll_update
reach 1
clock_filter (q, d, e, t)
exit
15peer process clock filter procedure
clock filter (q, d, e, t)
Shift sample (q, d, e, t) in clock filter adjust
dispersion e for old samples
Create (xi, yi, zi, ti) from each sample in clock
filter save in temporary array sort array by
increasing delay y
tmp q
clock filterVariables Process Description
- peer clock offsetd peer roundtrip
delaye peer filter dispersionj peer filter
jittert peer current epochtP peer epoch of last
updaten peer samples (n 8)burst poll burst
counter(xi, yi, zi, ti) local temp sample
tmp local temp
q tmp gt 3j and t0 t lt 2t?
yes
no
no
t0 gt tP
yes
tP t0
yes
burst 0?
clock select
no
exit
16system process
- clock select procedure
- Select and groom servers to discipline the system
clock. - valid function
- Return 1 if selected server is acceptable and
root distance less than 1s. - select algorithm
- Classify available servers as truechimers or
falsetickers. - cluster algorithm
- Find and discard outlyers until no more than
three survivors remain. - mitigation procedure
- Select survivors as required by the minigation
rules. - acceptable function
- Return 1 if server passes certain sanity checks.
- rootdist function
- Return synchronization distance to the primary
reference source.
17system process variables and procedures
system processVariables Process Description
system processProcedures Process Called by
Q system clock offsetJ system jitterjS system se
lect jitterTS system epoch of last
updatesys system system peerq peer clock
offsetj peer filter jitterjC clock clock
jitterm clock time since last updatetype peer ty
peprefer peer prefer enable
clock select system clock filter,
pollvalid system clock selectmitigation system c
lock selectacceptable system valid,
pollrootdist system valid, mitigationclock
update clock clock selectselect algorithm clock
selectcluster algorithm clock select
18system process clock select procedure
clock_select
scan candidates
valid?
NO
YES
add peer
selectalgorithm
survivors?
no
yes
modem?
add modem
yes
no
add local
yes
local?
no
cluster algorithm
exit (0)
mitigation
clock update
exit (n)
19system process select algorithm
For each of m associations construct a
correctness intervalq rootdist, q rootdist
Consider the lowpoint, midpoint and highpoint of
these intervals. Sort these values in a list from
lowest to highest. Set the number of falsetickers
f 0.
Set the number of midpoints d 0. Set c 0.
Scan from lowest endpoint to highest. Add one to
c for every lowpoint, subtract one for every
highpoint, add one to d for every midpoint. If c
m - f, stop set l current lowpoint
Set c 0. Scan from highest endpoint to lowest.
Add one to c for every highpoint, subtract one
for every lowpoint, add one to d for every
midpoint. If c m - f, stop set u current
highpoint.
If d f and l lt u?
no
yes
Add one to f. Is f lt m / 2?
Success the intersection interval is l, u.
yes
no
Failure a majority clique could not be found..
20system process cluster algorithm
Let (q, jR, L) represent a candidate with peer
offset q, jitter j and a weight factor L equal to
stratum as the high order field and root distance
as the low order field.
Sort the candidates by increasing L. Let n be the
number of candidates and nmin n the minimum
number of survivors.
For each candidate compute the selection jitter
jS (RMS peer offset differences between this and
all other candidates).
Select jmax as the candidate with maximum LjS.
Select jmin as the candidate with minimum j.
yes
jmax lt jmin or n nmin or jmax is prefer peer?
no
Delete the outlyer candidate with jmax reduce n
by one.
Done. The remaining cluster survivors are the
pick of the litter.
21system process mitigation procedures
valid
mitigation
is new peer the same as the last chosen and is
its stratum lowest?
no
type local clock or modem?
prefer?
yes
type PPS?
yes
yes
no
no
yes
no
prefer?
sys NEW
sys PPS
sys OLD
no
yes
sys PREF
NO
acceptable?
y z 0
YES
gt 1 s
rootdist
scanclock select survivors
x rootdist
lt 1 s
exit (NO)
exit (YES)
done
mitigation procedureVariable Process Description
Q system clock offsetjS system select
jitterJ system combine jittersys system system
peerq peer clock offsetj peer filter
jittertype peer typeprefer peer prefer
enablex, y local temp
exit
valid procedureVariable Process Description
type peer typeprefer peer prefer enable
22clock discipline process
- Clock update procedure
- Discipline system clock using adaptiver-parameter,
phase/frequency-lock loop. - trans procedure
- Transition to new state and initialize variables.
- adjust freq procedure
- Adjust oscillator frequency using PLL/FLL
feedback loop. - step freq procedure
- Step oscillator frequency when first starting and
no previous information. - tc procedure
- Adjust time constant as a function of prevailing
jitter and oscillator stability.
23clock discipline process variables and procedures
clock discipline processProcedure Process Called
by
clock discipline processVariable Process Descript
ion
QL clock last offsetQR clock current
offsetD peer root delayE peer root
dispersionjC clock clock jitterf clock frequency
h clock frequency stabilityt clock time
constantm clock time since last
updatestate clock state jiggle clock jiggle
counterQ system clock offsetJ system combine
jittertS system epoch of last updatesys system p
eerleap system leap indicatorstratum system stra
tumrefid system reference IDreftime system refer
ence timestamp tP peer epoch of last
updatemax poll max poll intervalmin poll min
poll intervalF constant frequency tolerance
local clock clock clock updatetrans clock local
clockadjust freq clock local clockstep
freq clock local clocktc clock local clockpoll
update poll packet, clock, pollstep
time kernel step time
24clock discipline process clock update procedure
clock update procedureSystem Process Copied from
clock_update
- system mitigate procJ system mitigate
procsys system mitigate proc D peer DR
dE peer ER e Fm j qleap peer leapstra
tum peer stratumrefid peer refidreftime peer ref
time
poll_update
no
yes
local_clock
IGNOR
ADJ
PANIC
STEP
reset all associations
update sys variables
panic exit
exit
25clock discipline process local clock function
loca_ clock
yes
Q gt PANIC?
exit (panic)
no
SPIK
yes
no
SYNC
Q gt STEP?
FREQ
FSET
NSET
SYNC
FREQ
SPIK
NSET
FSET
state SPIK
m gt 900 s?
QR Q
QR Q
no
yes
m gt 900 s?
trans (FREQ)
no
yes
adjust_freq
step_freq
exit (IGNOR)
step_freq
step_time (Q)
step_time (Q)
trans (SYNC)
Q 0 t min
Q 0 t min
tc
trans (SYNC)
trans (FREQ)
exit (ADJ)
tc
exit (STEP)
26Clock discipline process state transition
function
State Q lt STEP Q gt STEP Comments
NSET gtFREQadjust time gtFREQstep time no frequency file
FSET gtSYNCadjust time gtSYNCstep time frequency file
SPIK gtSYNCadjust freqadjust time if (lt 900 s) gtSPIK else gtSYNC step freq step time outlyer detected
FREQ if (lt 900 s) gtFREQ else gtSYNC step freq adjust time if (lt 900 s) gtFREQ else gtSYNC step freq step time Initial frequency
SYNC gtSYNCadjust freqadjust time If (lt 900 s) gtSPIK else gtSYNC step freq step time normal operation
27clock discipline process procedures I
tc
trans (x)
state x QB Q - QR QL QR Q m 0
jC gt h and Q lt 4jC
yes
no
exit
jiggle t
jiggle - 2t
tc procedureVariable Process Description
jiggle gt 30
jiggle lt -30
yes
yes
no
no
jiggle 30
jiggle -30
- clock offsett clock time constantjC clock jitte
rh clock stabilityjiggle clock jiggle
countermax poll max poll intervalmin poll min
poll interval
t lt max
t gt min
no
no
yes
yes
t
t--
exit
trans procedureVariable Process Description
Q clock offsetQB clock base offsetQR clock curre
nt offsetm clock time since last update
state clock current statex, y local temp
28clock discipline process procedures II
adjust freq
adjust freq procedureVariable Process Description
t gt 750
yes
no
- clock clock offsetQB clock base
offsetQR clock last offsetm clock time since
last updatef clock frequencyh clock frequency
stabilityt clock time constantpadj,
fadj local temp
step freq
f fadj padj
The fadj and padj comtributions are weighted by
functions depending on t.
exit
29clock adjust process
- clock adjust procedure
- Called by kernel timer routines once each second.
- Adjusts system clock frequency as computed by
PLL/FLL. - system process computes initial system clock
offset. - Reduce residual clock offset as exponential
decay. - This procedure can also be implemented in the
kernel for reduced sawtooth error.
30clock adjust process clock adjust procedure
clock adjust processVariables Process Description
f clock frequencyt clock time constantQR clock c
urrent offsetE system root dispersiontmp local t
empF constant tolerance (15 PPM)
clock adjust
E F
tmp QR / 16t
QR - tmp
adjust time (f tmp)
clock adjust processProcedures Process Called by
adjust time kernel clock adjust
wait 1 s
31poll process
- poll procedure
- Determine when to transmit a packet according to
poll and burst schedules. - transmit procedure
- Format and transmit an NTP packet.
- poll update procedure
- Mitigate the poll interval as a function of the
peer interval and designated lower and upper
values.
32poll process variables and procedures
poll processVariable Process Description
r peer precisionD peer root delay E peer root
dispersion refid peer reference
IDreftime peer reference timestamporg peer origi
n timestamprec peer receive timestampxmt peer tr
ansmit timestamphpoll peer host poll
intervalpoll poll poll intervalmin poll min
poll intervalmax poll max poll
intervalreach poll reach shift
registerunreach poll unreach counterburst poll b
urst counterb1_enable poll enable unreach
burstb2_enable poll enable reach
burstleap system leap indicatorversion system
versionmode system modestratum system stratumad
dr system hashed local addresst system current
epochtimer kernel timer
poll processProcedure Process Called by
poll poll kernel timerpoll update poll packet,
clock, polltransmit poll receive, pollclock
select system clock filter, pollacceptable system
select, pollclock filter peer packet,
pollcrypto xmit Autokey transmitsndpkt kernel tr
ansmit
33poll process poll procedure
poll
mode BCST
yes
peer NULL
yes
no
yes
no
burst 0?
reach ltlt 1
wait timer
transmit
yes
no
reach 0?
burst--
unreach gt 8
burst 0?
unreach 0
poll_update
no
yes
yes
no
no
yes
hpoll
clock_select
reach 0x70?
yes
clock_filter (0, 0, 8, t)
b2_enable?
yes
no
transmit
acceptable?
hpoll poll
no
yes
no
burst 8
mode BCL
yes
b1_enable?
no
yes
unreach0?
no
unreach
yes
burst 8
34poll process transmit procedure
Transmit Procedures
transmit
Peer TransmitPacket Process Variable
Fast TransmitPacket Process Variable
copy header
r system rD system D E system E
refid system refidreftime system reftimeT1 peer
org T2 peer rec T3 kernel clockMAC MD5 hashle
ap system leapversion peer versionmode peer pmod
estratum system stratumpoll peer hpoll
r system rD system D E system E
refid system refidreftime system reftimeT1 pack
et T2 T2 packet T3T3 kernel clockMAC MD5 hashl
eap system leapversion packet versionmode system
modestratum system stratumpoll packet poll
T1, T2
Crypto_xmit
T3 clock
make MAC
sndpkt
exit
35poll process procedures
poll_update
no
timer running?
burst 0?
yes
no
yes
timer max(min(ppoll, hpoll), min)
timer 2 s
exit
poll update procedureVariable Process Description
ppoll peer peer poll intervalhpoll peer host
poll intervalmin poll min poll
intervalmax poll max poll intervalburst poll bur
st countertimer kernel timer
n
36Miscellaneous functions
rootdist
acceptable
exit((DR d) / 2 ER e Fm j)
reach 0?leap 11?stratum gt15?
any yes
server not synchronized
all no
rootdist gt MAXDIST?
yes
root distance exceeded
rootdist procedureVariable Process Description
no
yes
refid addr?
server/client sync loop
DR peer root delayd peer delayER peer root
dispersione peer dispersionF constant frequency
tolerancem peer time since last
updatej peer jitter
no
exit (NO)
exit (YES)
reset
persistent?
yes
no
acceptable procedureVariable Process Description
initialize association variables
demobilize association
leap peer leap indicatorstratum peer stratumrefi
d peer reference IDaddr system hashed local IP
addrreach poll reach shift register
exit
37Further information
- Network Time Protocol (NTP) http//www.ntp.org/
- Current NTP Version 3 and 4 software and
documentation - FAQ and links to other sources and interesting
places - David L. Mills http//www.eecis.udel.edu/mills
- Papers, reports and memoranda in PostScript and
PDF formats - Briefings in HTML, PostScript, PowerPoint and PDF
formats - Collaboration resources hardware, software and
documentation - Songs, photo galleries and after-dinner speech
scripts - FTP server ftp.udel.edu (pub/ntp directory)
- Current NTP Version 3 and 4 software and
documentation repository - Collaboration resources repository
- Related project descriptions and briefings
- See Current Research Project Descriptions and
Briefings at http//www.eecis.udel.edu/mills/sta
tus.htm