Presentation is loading. Please wait.

Presentation is loading. Please wait.

NTP Procedure Descriptions and Flow Diagrams

Similar presentations


Presentation on theme: "NTP Procedure Descriptions and Flow Diagrams"— Presentation transcript:

1 NTP Procedure Descriptions and Flow Diagrams
David L. Mills University of Delaware 20-Sep-18

2 Process decomposition
Server 1 Peer/Poll 1 Selection and Clustering Algorithms System Process Clock Discipline Process Combining Algorithm Server 2 Peer/Poll 2 Loop Filter Server 3 Peer/Poll 3 VFO Remote Servers Peer/Poll Processes 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. 20-Sep-18

3 Time 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. 20-Sep-18

4 NTP packet header format
Packet header Variables Description LI VN Mode Strat Poll Prec Root Delay leap leap indicator (LI) version version number (VN) mode protocol mode stratum stratum t poll interval (log2 s) r clock reading precision (log2 s) D root delay E root dispersion refid reference ID reftime reference timestamp T1 originate timestamp T2 receive timestamp T3 transmit timestamp T4 destination timestamp* MAC 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. 20-Sep-18

5 NTP 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. 20-Sep-18

6 NTP peer protocol example
t1 t3 t5. Packet Variables Peer B State Variables T2 t2 t4 t6 T3 t1 t3 = clock t5. t7 = clock T4 t2 = clock t6 = clock State Variables Name Description org t1 t5? t5 rec t2 t2 t6 t6 org originate timestamp rec receive timestamp xmt transmit timestamp xmt t3 t3? t7 t2 t3 t6 t7 Packet Header Variables Name Description t1 t4 t5 t8 t1 t4 t5 t8 tn originate timestamp tn+1 receive timestamp tn+2 transmit timestamp tn+3 destination timestamp T1 t1 t3. t5 Packet Variables Peer A State Variables T2 t2 t4 t6 T3 t1 = clock t3. t5 = clock t7 T4 t4 = clock t8 = clock org 0. t3? t3 t7? rec t4 t4 t8 xmt t1 t1? t5 t5? 20-Sep-18

7 peer process receive procedure crypto_recv procedure packet 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 20-Sep-18

8 Packet sanity tests 20-Sep-18

9 Peer_process: variables and procedures
peer process Variables Process Description peer process Procedures Process Called by peer clock offset d peer roundtrip delay e peer dispersion j peer jitter t peer update epoch T peer last update epoch m peer time since last update rR peer server precision DR peer server root delay ER peer server root dispersion org peer originate timestamp rec peer receive timestamp xmt peer transmit timestamp leap peer leap indicator version peer version mode peer mode stratum peer stratum ppoll peer peer poll interval hpoll poll host poll interval min poll min poll interval max poll max poll interval clock system system clock F constant tolerance (15 PPM) lmax constant max distance (16 s) MAXSTRAT constant max stratum (15) receive peer peer packet peer peer clock_filter peer packet, poll poll_update poll packet, clock, poll transmit poll receive clock_select system clock filter, poll crypto_recv Autokey peer 20-Sep-18

10 peer process: receive procedure
access OK? no access deny peer yes format OK? no format error wait for pkt yes auth=MD5 receive find assoc Peer Process go to (association mode, packet mode) found in transition matrix receive procedure 20-Sep-18

11 Transition matrix Packet Mode Mode ACTIVE PASSIVE CLIENT SERVER BCAST
NO_PEER NEWPS FXMIT NEWMC NEWBC PROC ERROR BCLIENT Association Mode The default (empty box) behavior is to discard the packet without comment. 20-Sep-18

12 Transition functions 20-Sep-18 NEWBC NEWPS NEWMC auth? auth? auth? yes
no yes no yes no mobilize BCLIENT association mobilize PASSIVE association exit mobilize CLIENT association exit crypto_recv PROC PROC exit ERROR FXMIT reset transmit exit exit 20-Sep-18

13 peer process: timestamp processing
xmt = 0? yes invalid no xmt = T3? yes duplicate pkt no mode = BCST no T1andT2= 0? no T1orT2= 0? yes invalid yes no yes no org = T1? yes auth? auth? auth? bad reset ok bad bad yes ok org=T1 rec=T2 xmt=T3 auth error auth error exit org=T1 rec=T2 xmt=T3 crypto_recv bad crypto error ok packet exit 20-Sep-18

14 peer process: packet procedure
Packet header related values Packet Process Peer packet leap peer leap version peer version mode peer mode stratum peer stratum poll peer ppoll rR peer rR DR peer DR ER peer ER refid peer refid reftime peer reftime header? bad header error ok copy header poll_update reach |= 1 clock_filter (q, d, e, t) exit 20-Sep-18

15 peer process: clock filter procedure
(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 filter Variables Process Description peer clock offset d peer roundtrip delay e peer filter dispersion j peer filter jitter t peer current epoch tP peer epoch of last update n peer samples (n ≤ 8) burst poll burst counter (xi, yi, zi, ti) local temp sample tmp local temp |q – tmp| > 3j and t0 – t < 2t? yes no t0 > tP no yes tP = t0 clock select yes burst = 0? no exit 20-Sep-18

16 system process clock select procedure valid function select algorithm
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. 20-Sep-18

17 system process: variables and procedures
system process Variables Process Description system process Procedures Process Called by Q system clock offset J system jitter jS system select jitter TS system epoch of last update sys system system peer q peer clock offset j peer filter jitter jC clock clock jitter m clock time since last update type peer type prefer peer prefer enable clock select system clock filter, poll valid system clock select mitigation system clock select acceptable system valid, poll rootdist system valid, mitigation clock update clock clock select select algorithm clock select cluster algorithm clock select 20-Sep-18

18 system process: clock select procedure
scan candidates valid? NO YES add peer select algorithm survivors? no yes add modem yes modem? no add local yes local? no cluster algorithm exit (0) mitigation clock update exit (n) 20-Sep-18

19 system process: select algorithm
For each of m associations construct a correctness interval [q – 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 < u? no yes yes Add one to f. Is f < m / 2? Success; the intersection interval is [l, u]. no Failure; a majority clique could not be found.. 20-Sep-18

20 system 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. jmax < jmin or n ≤ nmin or jmax is prefer peer? yes no Delete the outlyer candidate with jmax; reduce n by one. Done. The remaining cluster survivors are the pick of the litter. 20-Sep-18

21 system process: mitigation procedures
valid mitigation is new peer the same as the last chosen and is its stratum lowest? type = local clock or modem? prefer? no yes type = PPS? yes no no yes yes no prefer? sys = PPS sys = OLD sys = NEW no yes NO acceptable? sys = PREF y = z = 0 YES > 1 s rootdist scan clock select survivors x = rootdist < 1 s exit (NO) exit (YES) done mitigation procedure Variable Process Description Q system clock offset jS system select jitter J system combine jitter sys system system peer q peer clock offset j peer filter jitter type peer type prefer peer prefer enable x, y local temp exit valid procedure Variable Process Description type peer type prefer peer prefer enable 20-Sep-18

22 clock 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. 20-Sep-18

23 clock discipline process: variables and procedures
clock discipline process Variable Process Description clock discipline process Procedure Process Called by QL clock last offset QR clock current offset D peer root delay E peer root dispersion jC clock clock jitter f clock frequency h clock frequency stability t clock time constant m clock time since last update state clock state jiggle clock jiggle counter Q system clock offset J system combine jitter tS system epoch of last update sys system peer leap system leap indicator stratum system stratum refid system reference ID reftime system reference timestamp tP peer epoch of last update max poll max poll interval min poll min poll interval F constant frequency tolerance local clock clock clock update trans clock local clock adjust freq clock local clock step freq clock local clock tc clock local clock poll update poll packet, clock, poll step time kernel step time 20-Sep-18

24 clock discipline process: clock update procedure
clock update procedure System Process Copied from clock_update system mitigate proc J system mitigate proc sys system mitigate proc D peer DR + d E peer ER + e + Fm + j + |q| leap peer leap stratum peer stratum refid peer refid reftime peer reftime poll_update no yes local_clock IGNOR PANIC ADJ STEP panic exit update sys variables reset all associations exit 20-Sep-18

25 clock discipline process: local clock function
loca_ clock |Q| > PANIC? yes exit (panic) no SPIK no |Q| > STEP? yes SYNC FREQ FSET NSET SYNC FSET SPIK FREQ NSET state = SPIK QR = Q m > 900 s? QR = Q yes no m > 900 s? trans (FREQ) adjust_freq no yes 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 20-Sep-18 exit (STEP)

26 Clock discipline process: state transition function
|Q| < STEP |Q| > STEP Comments NSET >FREQ; adjust time >FREQ; step time no frequency file FSET >SYNC; adjust time >SYNC; step time frequency file SPIK >SYNC adjust freq; adjust time if (< 900 s) >SPIK else >SYNC; step freq; step time outlyer detected FREQ if (< 900 s) >FREQ else >SYNC; step freq; adjust time if (< 900 s) >FREQ else >SYNC; step freq; step time Initial frequency SYNC >SYNC; adjust freq; adjust time If (< 900 s) >SPIK else >SYNC; step freq; step time normal operation 20-Sep-18

27 clock discipline process: procedures I
tc trans (x) state = x QB = Q - QR QL = QR = Q m = 0 jC > h and |Q| < 4jC no yes exit jiggle -= 2t jiggle += t tc procedure Variable Process Description jiggle < -30 jiggle > 30 no yes no yes jiggle = -30 jiggle = 30 clock offset t clock time constant jC clock jitter h clock stability jiggle clock jiggle counter max poll max poll interval min poll min poll interval t > min t < max no yes no yes t-- t++ exit trans procedure Variable Process Description Q clock offset QB clock base offset QR clock current offset m clock time since last update state clock current state x, y local temp 20-Sep-18

28 clock discipline process: procedures II
adjust freq adjust freq procedure Variable Process Description t > 750 yes no clock clock offset QB clock base offset QR clock last offset m clock time since last update f clock frequency h clock frequency stability t clock time constant padj, fadj local temp* step freq f += fadj + padj* * The fadj and padj comtributions are weighted by functions depending on t. exit 20-Sep-18

29 clock 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. 20-Sep-18

30 clock adjust process: clock adjust procedure
clock adjust process Variables Process Description f clock frequency t clock time constant QR clock current offset E system root dispersion tmp local temp F constant tolerance (15 PPM) clock adjust E += F tmp = QR / 16t QR -= tmp adjust time (f + tmp) clock adjust process Procedures Process Called by adjust time kernel clock adjust wait 1 s 20-Sep-18

31 poll process poll procedure transmit procedure poll update 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. 20-Sep-18

32 poll process: variables and procedures
poll process Variable Process Description r peer precision D peer root delay E peer root dispersion refid peer reference ID reftime peer reference timestamp org peer origin timestamp rec peer receive timestamp xmt peer transmit timestamp hpoll peer host poll interval poll poll poll interval min poll min poll interval max poll max poll interval reach poll reach shift register unreach poll unreach counter burst poll burst counter b1_enable poll enable unreach burst b2_enable poll enable reach burst leap system leap indicator version system version mode system mode stratum system stratum addr system hashed local address t system current epoch timer kernel timer poll process Procedure Process Called by poll poll kernel timer poll update poll packet, clock, poll transmit poll receive, poll clock select system clock filter, poll acceptable system select, poll clock filter peer packet, poll crypto xmit Autokey transmit sndpkt kernel transmit 20-Sep-18

33 poll process: poll procedure
peer = NULL yes mode= BCST yes no wait timer transmit no burst = 0? yes reach << 1 burst-- no reach = 0? yes unreach > 8 poll_update burst = 0? unreach = 0 no yes yes no no yes hpoll++ clock_select reach & 0x7=0? yes clock_filter (0, 0, ∞, t) b2_enable? yes no transmit acceptable? hpoll = poll yes no no burst = 8 mode = BCL yes no b1_enable? yes no unreach=0? yes unreach++ burst = 8 20-Sep-18

34 poll process: transmit procedure
Transmit Procedures transmit Peer Transmit Packet Process Variable Fast Transmit Packet Process Variable copy header r system r D system D E system E refid system refid reftime system reftime T1 peer org T2 peer rec T3 kernel clock MAC MD5 hash leap system leap version peer version mode peer pmode stratum system stratum poll peer hpoll r system r D system D E system E refid system refid reftime system reftime T1 packet T2 T2 packet T3 T3 kernel clock MAC MD5 hash leap system leap version packet version mode system mode stratum system stratum poll packet poll T1, T2 Crypto_xmit T3 = clock make MAC sndpkt exit 20-Sep-18

35 poll process: procedures
poll_update burst = 0? no timer running? yes yes no timer = max(min(ppoll, hpoll), min) timer = 2 s exit poll update procedure Variable Process Description ppoll peer peer poll interval hpoll peer host poll interval min poll min poll interval max poll max poll interval burst poll burst counter timer kernel timer n 20-Sep-18

36 Miscellaneous functions
rootdist acceptable exit ((DR + d) / 2 + ER + e + Fm + j) reach = 0? leap = 11? stratum >15? any yes server not synchronized all no rootdist > MAXDIST? yes root distance exceeded rootdist procedure Variable Process Description no refid = addr? yes server/client sync loop DR peer root delay d peer delay ER peer root dispersion e peer dispersion F constant frequency tolerance m peer time since last update j peer jitter no exit (YES) exit (NO) reset persistent? no yes acceptable procedure Variable Process Description initialize association variables demobilize association leap peer leap indicator stratum peer stratum refid peer reference ID addr system hashed local IP addr reach poll reach shift register exit 20-Sep-18

37 Further 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: 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 20-Sep-18


Download ppt "NTP Procedure Descriptions and Flow Diagrams"

Similar presentations


Ads by Google