<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="ntp4TOC.css" type="text/css" charset="UTF-8"?>
<XML>
<TITLE> </TITLE><Body>
<A ID="pgfId-933658"></A>
NTP Working Group	David L. Mills
Technical Report 06-6-1	 University of Delaware
	June 2006	</Body>
<ReportTitle>
<A ID="pgfId-938476"></A>
Network Time Protocol Version 4
Reference and Implementation Guide</ReportTitle>
<ReportAuthor>
<A ID="pgfId-933801"></A>
Abstract</ReportAuthor>
<Body>
<A ID="pgfId-934034"></A>
This document describes the Network Time Protocol Version 4 (NTPv4), which is widely used to synchronize the time for Internet hosts, routers and ancillary devices to Coordinated Universal Time (UTC) as disseminated by national standards laboratories. It describes the core architecture, protocol, state machine, data structures and algorithms. It explains the fundamental on-wire protocol used to exchange time values between peers, servers and clients. It summarizes the clock offset, roundtrip delay and various other statistics used by the mitigation algorithms to calculate the maximum error and nominal error inherent in computing these values. It describes several changes from Version 3 of NTP (NTPv3) originally described in RFC 1305, including the introduction of a modified protocol header to accommodate Internet Protocol Version 6 and a new header extension field to support the Autokey public key authentication scheme.</Body>
<Body>
<A ID="pgfId-932397"></A>
This document is based on the reference implementation available at www.ntp.org. It is intended as a reference and implementation guide, not as a formal standard. The main body of the document describes the basic model data structures and algorithms necessary for an implementation which can interoperate properly with another implementation faithful to this model. This document describes a number of crafted mitigation algorithms which can improve the accuracy and stability of the timekeeping function, especially in NTP subnets with many servers and clients. It also describes the clock discipline function used to adjust the system clock in time and frequency to agree with the available sources of synchronization.</Body>
<Body>
<A ID="pgfId-934875"></A>
As an implementation aid, a code skeleton for the reference implementation is presented in an appendix. It includes most of the data structures and algorithms of that program, but certain features, such as the control and monitoring protocol, Autokey public key authentication scheme, huff-’n-puff scheme and server discovery schemes are not included. These are discussed in companion documents on the Web and in print.</Body>
<Body>
<A ID="pgfId-931852"></A>
Keywords: network time synchronization, computer time synchronization, time synchronization protocol</Body>
<Body>
<A ID="pgfId-932378"></A>
Sponsored by: Naval Surface Weapons Center (Dahlgren) Contract N00178-04-1-9001.</Body>
<ReportAuthor>
<A ID="pgfId-919822"></A>
Table of Contents</ReportAuthor>
<Heading1TOC>
<A ID="pgfId-940366"></A>
1.	Introduction	1</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940367"></A>
2.	Modes of Operation	2</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940368"></A>
3.	Definitions	4</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940369"></A>
4.	Implementation Model	5</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940370"></A>
5.	Data Types	6</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940371"></A>
6.	Data Structures	8</Heading1TOC>
<Heading2TOC>
<A ID="pgfId-940372"></A>
6.1	Structure Conventions	8</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940373"></A>
6.2	Global Parameters	9</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940374"></A>
6.3	Packet Header Variables	10</Heading2TOC>
<Heading1TOC>
<A ID="pgfId-940375"></A>
7.	On-Wire Protocol	13</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940376"></A>
8.	Peer Process	15</Heading1TOC>
<Heading2TOC>
<A ID="pgfId-940377"></A>
8.1	Peer Process Variables	15</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940378"></A>
8.2	Peer Process Operations	17</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940379"></A>
8.3	Clock Filter Algorithm	21</Heading2TOC>
<Heading1TOC>
<A ID="pgfId-940380"></A>
9.	System Process	23</Heading1TOC>
<Heading2TOC>
<A ID="pgfId-940381"></A>
9.1	System Process Variables	23</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940382"></A>
9.2	System Process Operations	24</Heading2TOC>
<Heading3TOC>
<A ID="pgfId-940383"></A>
9.2.1	Selection Algorithm	25</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940384"></A>
9.2.2	Clustering Algorithm	27</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940385"></A>
9.2.3	Clock Combining Algorithm	28</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940386"></A>
9.2.4	Clock Discipline Algorithm	30</Heading3TOC>
<Heading2TOC>
<A ID="pgfId-940387"></A>
9.3	Clock Adjust Process	35</Heading2TOC>
<Heading1TOC>
<A ID="pgfId-940388"></A>
10.	Poll Process	36</Heading1TOC>
<Heading2TOC>
<A ID="pgfId-940389"></A>
10.1	Poll Process Variables and Parameters	36</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940390"></A>
10.2	Poll Process Operations	37</Heading2TOC>
<Heading1TOC>
<A ID="pgfId-940391"></A>
11.	References	38</Heading1TOC>
<Heading1TOC>
<A ID="pgfId-940392"></A>
Appendix A.	NTPv4 Packet Formats	40</Heading1TOC>
<Heading2TOC>
<A ID="pgfId-940393"></A>
A.1	NTP Header Field Format	40</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940394"></A>
A.2	NTPv4 Extension Field Format	41</Heading2TOC>
<Heading1TOC>
<A ID="pgfId-940395"></A>
Appendix B.	Code Skeleton	43</Heading1TOC>
<Heading2TOC>
<A ID="pgfId-940396"></A>
B.1	Global Definitions	43</Heading2TOC>
<Heading3TOC>
<A ID="pgfId-940397"></A>
B.1.1	Definitions, Constants and Parameters	43</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940398"></A>
B.1.2	Packet Data Structures	46</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940399"></A>
B.1.3	Association Data Structures	47</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940400"></A>
B.1.4	System Data Structures	48</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940401"></A>
B.1.5	Local Clock Data Structure	49</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940402"></A>
B.1.6	Function Prototypes	49</Heading3TOC>
<Heading2TOC>
<A ID="pgfId-940403"></A>
B.2	Main Program and Utility Routines	50</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940404"></A>
B.3	Kernel Input/Output Interface	54</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940405"></A>
B.4	Kernel System Clock Interface	54</Heading2TOC>
<Heading2TOC>
<A ID="pgfId-940406"></A>
B.5	Peer Process	56</Heading2TOC>
<Heading3TOC>
<A ID="pgfId-940407"></A>
B.5.1	receive()	57</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940408"></A>
B.5.2	packet()	61</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940409"></A>
B.5.3	clock_filter()	63</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940410"></A>
B.5.4	fast_xmit()	64</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940411"></A>
B.5.5	access()	65</Heading3TOC>
<Heading2TOC>
<A ID="pgfId-940412"></A>
B.6	System Process	65</Heading2TOC>
<Heading3TOC>
<A ID="pgfId-940413"></A>
B.6.1	clock_select()	66</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940414"></A>
B.6.2	root_dist()	69</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940415"></A>
B.6.3	accept()	69</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940416"></A>
B.6.4	clock_update()	70</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940417"></A>
B.6.5	clock_combine()	72</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940418"></A>
B.6.6	local_clock()	72</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940419"></A>
B.6.7	rstclock()	77</Heading3TOC>
<Heading2TOC>
<A ID="pgfId-940420"></A>
B.7	Clock Adjust Process	78</Heading2TOC>
<Heading3TOC>
<A ID="pgfId-940421"></A>
B.7.1	clock_adjust()	78</Heading3TOC>
<Heading2TOC>
<A ID="pgfId-940422"></A>
B.8	Poll Process	79</Heading2TOC>
<Heading3TOC>
<A ID="pgfId-940423"></A>
B.8.1	poll()	79</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940424"></A>
B.8.2	poll_update()	81</Heading3TOC>
<Heading3TOC>
<A ID="pgfId-940425"></A>
B.8.3	transmit()	82</Heading3TOC>
</XML>
