Tech-invite3GPPspaceIETFspace
96959493929190898887868584838281807978777675747372717069686766656463626160595857565554535251504948474645444342414039383736353433323130292827262524232221201918171615141312111009080706050403020100
in Index   Prev   Next

RFC 1059

Network Time Protocol (version 1) specification and implementation

Pages: 58
Obsoletes:  0958
Obsoleted by:  11191305
Part 2 of 2 – Pages 22 to 58
First   Prev   None

ToP   noToC   RFC1059 - Page 22   prevText
3.4.  Event Processing

   The significant events of interest in NTP occur upon expiration of
   the peer timer, one of which is dedicated to each peer operating in
   symmetric or client modes, and upon arrival of an NTP message from
   the various peers.  An event can also occur as the result of an
   operator command or detected system fault, such as a primary clock
   failure.  This section describes the procedures invoked when these
   events occur.
ToP   noToC   RFC1059 - Page 23
3.4.1.  Timeout Procedure

   The timeout procedure is called in client and symmetric modes when
   the peer timer (peer.timer) reaches the value of the timer threshold
   (peer.threshold) variable.  First, the reachability register
   (peer.reach) is shifted one position to the left and a zero replaces
   the vacated bit.  Then an NTP message is constructed and sent to the
   peer.  If operating in active state or in passive state and
   peer.reach is nonzero (reachable), the peer.timer is reinitialized
   (resumes counting from zero) and the value of peer.threshold is set
   to:

           peer.threshold <- max( min( peer.ppoll, peer.hpoll,
                           NTP.MAXPOLL), NTP.MINPOLL) .

   If operating in active state and peer.reach is zero (unreachable),
   the peer variables are updated as follows:

                   peer.hpoll <- NTP.MINPOLL
                   peer.disp <- NTP.MAXDISP
                   peer.filter <- 0 (cleared)
                   peer.org <- 0
                   peer.rec <- 0

   Then the clock selection algorithm is called, which may result in a
   new clock source (sys.peer).  In other cases the protocol ceases
   operation and the storage and timer resources are reclaimed for
   subsequent use.

   An NTP message is constructed as follows (see Appendices A and B for
   formats).  First, the IP and UDP packet variables are copied from the
   peer variables (note the interchange of source and destination
   addresses and ports):

           pkt.srcadr <- peer.dstadr       pkt.srcport <- peer.dstport
           pkt.dstadr <- peer.srcadr       pkt.dstport <- peer.srcport

   Next, the NTP packet variables are copied (rescaled as necessary)
   from the system and peer variables:

           pkt.leap <- sys.leap            pkt.distance <- sys.distance
           pkt.version <- NTP.VERSION      pkt.drift <- sys.drift
           pkt.stratum <- sys.stratum      pkt.refid <- sys.refid
           pkt.poll <- peer.hpoll          pkt.reftime <- sys.reftime
           pkt.precision <- sys.precision

   Finally, the NTP packet timestamp variables are copied, depending on
   whether the peer is operating in symmetric mode and reachable, in
ToP   noToC   RFC1059 - Page 24
   symmetric mode and not reachable (but active) or in client mode:

   Symmetric Reachable     Symmetric Active        Client
   - -------------------     -------------------     -------------------
   pkt.org <- peer.org     pkt.org <- 0            pkt.org <- sys.clock
   pkt.rec <- peer.rec     pkt.rec <- 0            pkt.rec <- sys.clock
   pkt.xmt <- sys.clock    pkt.xmt <- sys.clock    pkt.xmt <- sys.clock

   Note that the order of copying should be designed so that the time to
   perform the copy operations themselves does not degrade the
   measurement accuracy, which implies that the sys.clock values should
   be copied last.  The reason for the choice of zeros to fill the
   pkt.org and pkt.rec packet variables in the symmetric unreachable
   case is to avoid the use of old data after a possibly extensive
   period of unreachability.  The reason for the choice of sys.clock to
   fill these variables in the client case is that, if for some reason
   the NTP message is returned by the recipient unaltered, as when
   testing with an Internet-echo server, this convention still allows at
   least the roundtrip time to be accurately determined without special
   handling.

3.4.2.  Receive Procedure

   The receive procedure is executed upon arrival of an NTP message.  If
   the version number of the message (pkt.version) does not match the
   current version number (NTP.VERSION), the message is discarded;
   however, exceptions may be advised on a case-by-case basis at times
   when the version number is changed.

   If the clock of the sender is unsynchronized (pkt.leap = 11), or the
   receiver is in server mode or the receiver is in symmetric mode and
   the stratum of the sender is greater than the stratum of the receiver
   (pkt.stratum > sys.stratum), the message is simply returned to the
   sender along with the timestamps.  In this case the addresses and
   ports are interchanged in the IP and UDP headers:

        pkt.srcadr <-> pkt.dstadr       pkt.srcport <-> pkt.dstport

   The following packet variables are updated from the system variables:

        pkt.leap <- sys.leap            pkt.distance <- sys.distance
        pkt.version <- NTP.VERSION      pkt.drift <- sys.drift
        pkt.stratum <- sys.stratum      pkt.refid <- sys.refid
        pkt.precision <- sys.precision  pkt.reftime <- sys.reftime

   Note that the pkt.poll packet variable is unchanged.  The timestamps
   are updated in the order shown:
ToP   noToC   RFC1059 - Page 25
                        pkt.org <- pkt.xmt
                        pkt.rec <- sys.clock
                        pkt.xmt <- sys.clock

   Finally, the message is forwarded to the sender and the server
   receive procedure terminated at this point.

   If the above is not the case, the source and destination Internet
   addresses and ports in the IP and UDP headers are matched to the
   correct peer.  If there is a match, processing continues at the next
   step below.  If there is no match and symmetric mode is not indicated
   (either pkt.srcport or pkt.dstport not equal to NTP.PORT), the
   message must be a reply to a previously sent message from a client
   which is no longer in operation.  In this case the message is dropped
   and the receive procedure terminated at this point.

   If there is no match and symmetric mode is indicated, (both
   pkt.srcport and pkt.dstport equal to NTP.PORT), an implementation-
   specific instantiation procedure is called to create and initialize a
   new set of peer variables and start the peer timer.  The following
   peer variables are set from the IP and UDP headers:

           peer.srcadr <- pkt.srcadr       peer.srcport <- pkt.srcport
           peer.dstadr <- pkt.dstadr       peer.dstport <- pkt.dstport


   The following peer variables are initialized:

                   peer.state <- symmetric (passive)
                   peer.timer <- 0 (enabled)
                   peer.hpoll <- NTP.MINPOLL
                   peer.disp <- NTP.MAXDISP

   The remaining peer variables are undefined and set to zero.

   Assuming that instantiation is complete and that match occurs, the
   least significant bit of the reachability register (peer.reach) is
   set, indicating the peer is now reachable.  The following peer
   variables are copied (rescaled as necessary) from the NTP packet
   variables and system variables:
ToP   noToC   RFC1059 - Page 26
           peer.leap <- pkt.leap           peer.distance <- pkt.distance
           peer.stratum <- pkt.stratum     peer.drift <- pkt.drift
           peer.ppoll <- pkt.poll          peer.refid <- pkt.refid
           peer.precision <- pkt.precision peer.reftime <- pkt.reftime
           peer.org <- pkt.xmt             peer.rec <- sys.clock
           peer.threshold <- max( min( peer.ppoll, peer.hpoll,
                           NTP.MAXPOLL), NTP.MINPOLL)

   If either or both the pkt.org or pkt.rec packet variables are zero,
   the sender did not have reliable values for them, so the receive
   procedure is terminated at this point.  If both of these variables
   are nonzero, the roundtrip delay and clock offset relative to the
   peer are calculated as follows.  Number the times of sending and
   receiving NTP messages as shown in Figure 3.1 and let i be an even
   integer.  Then t(i-3), t(i-2) and t(i-1) and t(i) are the contents of
   the pkt.org, pkt.rec, pkt.xmt and peer.rec variables respectively.

                        |                    |
                   t(1) |------------------->| t(2)
                        |                    |
                   t(4) |<-------------------| t(3)
                        |                    |
                   t(5) |------------------->| t(6)
                        |                    |
                   t(8) |<-------------------| t(7)
                        |                    |
                                 ...
                Figure 3.1. Calculating Delay and Offset

   The roundtrip delay d and clock offset c of the receiving peer
   relative to the sending peer is:

                   d = (t(i) - t(i-3)) - (t(i-1) - t(i-2))
                c = [(t(i-2) - t(i-3)) + (t(i-1) - t(i))]/2 .

   This method amounts to a continuously sampled, returnable-time
   system, which is used in some digital telephone networks.  Among the
   advantages are that the order and timing of the messages is
   unimportant and that reliable delivery is not required.  Obviously,
   the accuracies achievable depend upon the statistical properties of
   the outbound and inbound net paths.  Further analysis and
   experimental results bearing on this issue can be found in
   Appendix D.

   The c and d values are then input to the clock filter algorithm to
   produce the delay estimate (peer.delay) and offset estimate
   (peer.offset) for the peer involved.  If d becomes nonpositive due to
   low delays, long polling intervals and high drift rates, it should be
ToP   noToC   RFC1059 - Page 27
   considered invalid;  however, even under these conditions it may
   still be useful to update the local clock and reduce the drift rate
   to the point that d becomes positive again.  Specification of the
   clock filter algorithm is not an integral part of the NTP
   specification;  however, one found to work well in the Internet
   environment is described in Section 4.

   When a primary clock is connected to the host, it is convenient to
   incorporate its information into the data base as if the clock were
   represented by an ordinary peer.  The clocks are usually polled once
   or twice a minute and the returned timecheck used to produce a new
   update for the logical clock.  The update procedure is then called
   with the following assumed peer variables:

                   peer.offset <- timecheck - sys.clock
                   peer.delay <- as determined
                   peer.dispersion <- 0
                   peer.leap <- selected by operator, ordinarily 00
                   peer.stratum <- 0
                   peer.distance <- 0
                   peer.refid <- ASCII identifier
                   peer.reftime <- timecheck

   In this case the peer.delay and peer.refid can be constants
   reflecting the type and accuracy of the clock.  By convention, the
   value for peer.delay is ten times the expected mean error of the
   clock, for instance, 10 milliseconds for a WWVB clock and 1000
   milliseconds for a less accurate WWV clock, but with a floor of 100
   milliseconds.  Other peer variables such as the peer timer and
   reachability register can be used to control the polling interval and
   to confirm the clock is operating correctly.  In this way the clock
   filter and selection algorithms operate in the usual way and can be
   used to mitigate the clock itself, should it appear to be operating
   correctly, yet deliver bogus time.

3.4.3.  Update Procedure

   The update procedure is called when a new delay/offset estimate is
   available.  First, the clock selection algorithm determines the best
   peer on the basis of estimated accuracy and reliability, which may
   result in a new clock source (sys.peer).  If sys.peer points to the
   peer data structure with the just-updated estimates, the state
   variables of that peer are used to update the system state variables
ToP   noToC   RFC1059 - Page 28
   as follows:

                   sys.leap <- peer.leap
                   sys.stratum <- peer.stratum + 1
                   sys.distance <- peer.distance + peer.delay
                   sys.refid <- peer.srcadr
                   sys.reftime <- peer.rec

   Finally, the logical clock procedure is called with peer.offset as
   argument to update the logical clock (sys.clock) and recompute the
   estimated drift rate (sys.drift).  It may happen that the logical
   clock may be reset, rather than slewed to its final value.  In this
   case the peer variables of all reachable peers are are updated as
   follows:

                   peer.hpoll <- NTP.MINPOLL
                   peer.disp <- NTP.MAXDISP
                   peer.filter <- 0 (cleared)
                   peer.org <- 0
                   peer.rec <- 0

   and the clock selection algorithm is called again, which results in a
   null clock source (sys.peer = 0).  A new selection will occur when
   the filters fill up again and the dispersion settles down.

   Specification of the clock selection algorithm and logical clock
   procedure is not an integral part of the NTP specification.  A clock
   selection algorithm found to work well in the Internet environment is
   described in Section 4, while a logical clock procedure is described
   in Section 5.  The clock selection algorithm described in Section 4
   usually picks the server at the highest stratum and minimum delay
   among all those available, unless that server appears to be a
   falseticker.  The result is that the algorithms all work to build a
   minimum-weight spanning tree relative to the primary servers and thus
   a hierarchical master-slave system similar to those used by some
   digital telephone networks.
ToP   noToC   RFC1059 - Page 29
3.4.4.  Initialization Procedures

   Upon reboot the NTP host initializes all system variables as follows:

                   sys.clock <- best available estimate
                   sys.leap <- 11 (unsynchronized)
                   sys.stratum <- 0 (undefined)
                   sys.precision <- as required
                   sys.distance <- 0 (undefined)
                   sys.drift <- as determined
                   sys.refid <- 0 (undefined)
                   sys.reftime <- 0 (undefined)

   The logical clock sys.clock is presumably undefined at reboot;
   however, in some designs such as the Fuzzball an estimate is
   available from the reboot environment.  The sys.precision variable is
   determined by the intrinsic architecture of the local hardware clock.
   The sys.drift variable is determined as a side effect of subsequent
   logical clock updates, from whatever source.

   Next, an implementation-specific instantiation procedure is called
   repeatedly to establish the set of client peers or symmetric (active)
   peers which will actively probe other servers during regular
   operation.  The mode and addresses of these peers is determined using
   information read during the reboot procedure or as the result of
   operator commands.

4.  Filtering Algorithms

   A very important factor affecting the accuracy and reliability of
   time distribution is the complex of algorithms used to deglitch and
   smooth the offset estimates and to cast out outlyers due to failure
   of the primary reference sources or propagation media.  The
   algorithms suggested in this section were developed and refined over
   several years of operation in the Internet under widely varying net
   configurations and utilizations.  While these algorithms are believed
   the best available at the present time, they are not an integral part
   of the NTP specification.

   There are two algorithms described in the following, the clock filter
   algorithm, which is used to select the best offset samples from a
   given clock, and the clock selection algorithm, which is used to
   select the best clock among a hierarchical set of clocks.

4.1.  Clock Filter Algorithm

   The clock filter algorithm is executed upon arrival of each NTP
   message that results in new delay/offset sample pairs.  New sample
ToP   noToC   RFC1059 - Page 30
   pairs are shifted into the filter register (peer.filter) from the
   left end, causing first zeros then old sample pairs to shift off the
   right end.  Then those sample pairs in peer.filter with nonzero delay
   are inserted on a temporary list and sorted in order of increasing
   delay.  The delay estimate (peer.delay) and offset estimate
   (peer.offset) are chosen as the delay/offset values corresponding to
   the minimum-delay sample.  In case of ties an arbitrary choice is
   made.

   The dispersion estimate (peer.dispersion) is then computed as the
   weighted sum of the offsets in the list.  Assume the list has
   PEER.SHIFT entries, the first m of which contain valid samples in
   order of increasing delay.  If X(i) (0 =< i < PEER.SHIFT) is the
   offset of the ith sample, then,

           d(i) = |X(i) - X(0)|    if i < m and |X(i) - X(0)| < 2^15
           d(i) = 2^15 - 1         otherwise

                   peer.dispersion = Sum(d(i)*w^i) ,
                           (0 =< i < PEER.SHIFT)

   where w < 1 is a weighting factor experimentally adjusted to match
   typical offset distributions.  The peer.dispersion variable is
   intended for use as a quality indicator, with increasing values
   associated with decreasing quality.  The intent is that samples with
   a peer.dispersion exceeding a configuration threshold will not be
   used in subsequent processing.  The prototype implementation uses a
   weighting factor w = 0.5, also called PEER.FILTER, and a threshold
   PEER.THRESHOLD of 500 ms, which insures that all stages of
   peer.filter are filled and contain offsets within a few seconds of
   each other.

4.2.  Clock Selection Algorithm

   The clock selection algorithm uses the values of peer.delay,
   peer.offset and peer.dispersion calculated by the clock filter
   algorithm and is called when these values change or when the
   reachability status changes.  It constructs a list of candidate
   estimates according to a set of criteria designed to maximize
   accuracy and reliability, then sorts the list in order of estimated
   precision.  Finally, it repeatedly casts out outlyers on the basis of
   dispersion until only a single candidate is left.

   The selection process operates on each peer in turn and inspects the
   various data captured from the last received NTP message header, as
   well as the latest clock filter estimates.  It selects only those
   peers for which the following criteria are satisfied:
ToP   noToC   RFC1059 - Page 31
   1.  The peer must be reachable and operating in client or symmetric
       modes.

   2.  The peer logical clock must be synchronized, as indicated by the
       Leap Indicator bits being other than 11.

   3.  If the peer is operating at stratum two or greater, it must not
       be synchronized to this host, which means its reference clock
       identifier (peer.refid) must not match the Internet address of
       this host.  This is analogous to the split-horizon rule used in
       some variants of the Bellman-Ford routing algorithm.

   4.  The sum of the peer synchronizing distance (peer.distance) plus
       peer.delay must be less than 2^13 (8192) milliseconds.  Also, the
       peer stratum (peer.stratum) must be less than eight and
       peer.dispersion must be less than a configured threshold
       PEER.THRESHOLD (currently 500 ms).  These range checks were
       established through experience with the prototype implementation,
       but may be changed in future.

   For each peer which satisfies the above criteria, a sixteen-bit
   keyword is constructed, with the low-order thirteen bits the sum of
   peer.distance plus peer.delay and the high-order three bits the
   peer.stratum reduced by one and truncated to three bits (thus mapping
   zero to seven).  The keyword together with a pointer to the peer data
   structure are inserted according to increasing keyword values and
   truncated at a maximum of eight entries.  The resulting list
   represents the order in which peers should be chosen according to the
   estimated precision of measurement.  If no keywords are found, the
   clock source variable (sys.peer) is set to zero and the algorithm
   terminates.

   The final procedure is designed to detect falsetickers or other
   conditions which might result in gross errors.  Let m be the number
   of samples remaining in the list.  For each i (0 =< i < m) compute
   the dispersion d(i) of the list relative to i:

                   d(i) = Sum(|X(j) - X(i)|*w^j) ,
                       (0 =< j < m)

   where w < 1 is a weighting factor experimentally adjusted for the
   desired characteristic (see below).  Then cast out the entry with
   maximum d(i) or, in case of ties, the maximum i, and repeat the
   procedure.  When only a single entry remains in the list, sys.peer is
   set as its peer data structure pointer and the peer.hpoll variable in
   that structure is set to NTP.MINPOLL as required by the logical clock
   mechanism described in Section 5.
ToP   noToC   RFC1059 - Page 32
   This procedure is designed to favor those peers near the head of the
   list, which are at the highest stratum and lowest delay and
   presumably can provide the most precise time.  With proper selection
   of weighting factor w, also called PEER.SELECT, entries will be
   trimmed from the tail of the list, unless a few outlyers disagree
   significantly with respect to the remaining entries, in which case
   the outlyers are discarded first.

   In order to see how this procedure works to select outlyers, consider
   the case of three entries and assume that one or more of the offsets
   are clustered about zero and others are clustered about one.  For w =
   0.75 as used in the prototype implementations and multiplying by 16
   for convenience, the first entry has weight w^0 = 16, the second w^1
   = 12 and the third w^2 = 9.  Table X shows for all combinations of
   peer offsets the calculated dispersion about each of the three
   entries, along with the results of the procedure.

      Peer 0    1    2         Dispersion          Cast    Result
    Weight 16   12   9     0       1       2       Out
           ------------------------------------------------------
           0    0    0     0       0       0       2       0    0
           0    0    1     9       9       28      2       0    0
           0    1    0     12      25      12      1       0    0
           0    1    1     21      16      16      0       1    1
           1    0    0     21      16      16      0       0    0
           1    0    1     12      25      12      1       1    1
           1    1    0     9       9       28      2       1    1
           1    1    1     0       0       0       2       1    1

                  Table 4.1. Outlyer Selection Procedure

   In the four cases where peer 0 and peer 1 disagree, the outcome is
   determined by peer 2.  Similar outcomes occur in the case of four
   peers.  While these outcomes depend on judicious choice of w, the
   behavior of the algorithm is substantially the same for values of w
   between 0.5 and 1.0.

4.3.  Variable-Rate Polling

   As NTP service matures in the Internet, the resulting network traffic
   can become burdensome, especially in the primary service net.  In
   this expectation, it is useful to explore variable-rate polling, in
   which the intervals between NTP messages can be adjusted to fit
   prevailing network conditions of delay dispersion and loss rate.  The
   prototype NTP implementation uses this technique to reduce the
   network overheads to one-sixteenth the maximum rate, depending on
   observed dispersion and loss.
ToP   noToC   RFC1059 - Page 33
   The prototype implementation adjusts the polling interval peer.hpoll
   in response to the reachability register (peer.reach) variable along
   with the dispersion (peer.dispersion) variable.  So long as the clock
   source variable (sys.peer) does not point to the peer data structure,
   peer.reach is nonzero (reachable) and peer.dispersion is less than
   the PEER.THRESHOLD parameter, the value of peer.hpoll is increased by
   one for each call on the update procedure, subject to a maximum of
   NTP.MAXPOLL.  Following the timeout procedure, if peer.reach
   indicates messages have not been received for the preceding two
   polling intervals (low-order two bits are zero), the value of
   peer.hpoll is decreased by one, subject to a minimum of NTP.MINPOLL.
   If peer.reach becomes zero (unreachable), the value of peer.hpoll is
   set to NTP.MINPOLL.

   The result of the above mechanism is that the polling intervals for
   peers not selected for synchronization and in symmetric mode creep
   upwards once the filter register (peer.filter) has filled and the
   peer.dispersion has settled down, but decrease again in case
   peer.dispersion increases or the loss rate increases or the peer
   becomes unreachable.

5.  Logical Clocks

   In order to implement a logical clock, the host must be equipped with
   a hardware clock consisting of an oscillator and interface and
   capable of the required precision and stability.  The logical clock
   is adjusted by means of periodic offset corrections computed by NTP
   or some other time-synchronization protocol such as Hellospeak [15]
   or the Unix 4.3bsd TSP [20].  Following is a description of the
   Fuzzball logical clock, which includes provisions for precise time
   and frequency adjustment and can maintain time to within a
   millisecond and frequency to within a day per millisecond.

   The logical clock is implemented using a 48-bit Clock Register, which
   increments at 1000-Hz (at the decimal point), a 32-bit Clock-Adjust
   Register, which is used to slew the Clock Register in response to
   offset corrections, and a Drift-Compensation Register, which is used
   to trim the oscillator frequency.  In some interface designs such as
   the DEC KWV11, an additional hardware register, the Counter Register,
   is used as an auxiliary counter.  The configuration and decimal point
   of these registers are shown in Figure 5.1.
ToP   noToC   RFC1059 - Page 34
           Clock Register

           0               16               32
           +---------------+---------------+---------------+
           |               |               |               |
           +---------------+---------------+---------------+
                                           A
                                     decimal point

           Clock-Adjust Register

                           0               16
                           +---------------+---------------+
                           |               |               |
                           +---------------+---------------+
                                           A
                                     decimal point

           Drift-Compensation Register

                           0               16
                           +---------------+
                           |               |
                           +---------------+
                                           A
                                     decimal point

           Counter Register

                           0               16
                           +---------------+
                           |               |
                           +---------------+
                                           A
                                     decimal point

                        Figure 5.1. Clock Registers

   The Clock Register, Clock-Adjust Register and Drift-Compensation
   Register are implemented in memory.  In typical clock interface
   designs such as the DEC KWV11, the Counter Register is implemented as
   a buffered counter driven by a crystal oscillator.  A counter
   overflow is signalled by an interrupt, which results in an increment
   of the Clock Register at bit 15 and the propagation of carries as
   required.  The time of day is determined by reading the Counter
   Register, which does not disturb the counting process, and adding its
   value to that of the Clock Register with decimal points aligned.
ToP   noToC   RFC1059 - Page 35
   In other interface designs such as the LSI-11 event-line mechanism,
   each tick of the clock is signalled by an interrupt at intervals of
   16-2/3 or 20 ms, depending on interface and mains frequency.  When
   this occurs the appropriate increment in milliseconds, expressed to
   32 bits in precision, is added to the Clock Register with decimal
   points aligned.

5.1.  Uniform Phase Adjustments

   Left uncorrected, the logical clock runs at the rate of its intrinsic
   oscillator.  A correction is introduced as a signed 32-bit integer in
   milliseconds, which is added to the Drift-Compensation Register and
   also replaces bits 0-15 of the Clock-Adjust Register, with bits 16-31
   set to zero.  At adjustment intervals of CLOCK.ADJ a correction
   consisting of two components is computed.  The first (phase)
   component consists of the Clock-Adjust Register shifted right
   CLOCK.PHASE bits, which is then subtracted from the Clock-Adjust
   Register.  The second (frequency) component consists of the Drift-
   Compensation Register shifted right CLOCK.FREQ bits.  The sum of the
   phase and frequency components is the correction, which is then added
   to the Clock Register.  Operation continues in this way until a new
   correction is introduced.

   Care is required in the implementation to insure monotonicity of the
   Clock Register and to preserve the highest precision while minimizing
   the propagation of roundoff errors.  This can be done by buffering
   the corrections and adding them to the increment at the time the
   Clock Register is next updated.  Monotonicity is insured with the
   parameters shown in Table 5.1, as long as the increment is at least 2
   ms.  This table shows the above parameters and others discussed below
   for both a crystal-stabilized oscillator and a mains-frequency
   oscillator.

   Parameter               Name            Crystal         Mains
   -------------------------------------------------------------------
   Update Interval         CLOCK.ADJ       4 sec           1 sec
   Phase Shift             CLOCK.PHASE     -8              -9
   Frequency Shift         CLOCK.FREQ      -16             -16
   Maximum Aperture        CLOCK.MAX       +-128 ms        +-256 ms
   Shift Register Size     PEER.SHIFT      8               4
   Host Poll Interval      peer.hpoll      NTP.MINPOLL     NTP.MINPOLL
                                            (64 sec)        (64 sec)

                        Table 5.1. Clock Parameters

   The above design constitutes a second-order phase-lock loop which
   adjusts the logical clock phase and frequency to compensate for the
   intrinsic oscillator jitter, wander and drift.  Simulation of a loop
ToP   noToC   RFC1059 - Page 36
   with parameters chosen from Table 5.1 for a crystal-stabilized
   oscillator and the clock filter described in Section 4 results in the
   following transient response:  For a phase correction of 100 ms the
   loop reaches zero error in 34 minutes, overshoots 7 ms in 76 minutes
   and settles to less than 1 ms in about four hours.  The maximum
   frequency error is about 6 ppm at 40 minutes and returns to less than
   1 ppm in about eight hours.  For a frequency correction of 10 ppm the
   loop settles to within 1 ppm in about nine hours and to within 0.1
   ppm in about a day.  These characteristics are appropriate for
   typical computing equipment using board-mounted crystals without oven
   temperature control.

   In those cases where mains-frequency oscillators must be used, the
   loop parameters must be adapted for the relatively high jitter and
   wander characteristics of the national power grid, in which diurnal
   peak-to-peak phase excursions can exceed four seconds.  Simulation of
   a loop with parameters chosen from Table 5.1 for a mains-frequency
   oscillator and the clock filter described in Section 4 results in a
   transient response similar to the crystal-stabilized case, but with
   time constants only one-fourth those in that case.  When presented
   with actual phase-offset data for typical Summer days when the jitter
   and wander are the largest, the loop errors are in the order of a few
   tens of milliseconds, but not greater than 150 ms.

   The above simulations assume the clock filter algorithm operates to
   select the oldest sample in the shift register at each step;  that
   is, the filter operates as a delay line with delay equal to the
   polling interval times the number of stages.  This is a worst-case
   scenario, since the larger the overall delay the harder it is to
   maintain low loop errors together with good transient response.  The
   parameters in Table 5.1 were experimentally determined with this
   scenario and the constraint that the polling interval could not be
   reduced below 64 seconds.  With these parameters it is not possible
   to increase the polling interval above 64 seconds without significant
   increase in loop error or degradation of transient response.  Thus,
   when a clock is selected according to the algorithms of Section 4,
   the polling interval peer.hpoll is always set at NTP.MINPOLL.

5.2.  Nonuniform Phase Adjustments

   When the magnitude of a correction exceeds a maximum aperture
   CLOCK.MAX, the possibility exists that the clock is so far out of
   synchronization with the reference source that the best action is an
   immediate and wholesale replacement of Clock Register contents,
   rather than a graduated slewing as described above.  In practice the
   necessity to do this is rare and occurs when the local host or
   reference source is rebooted, for example.  This is fortunate, since
   step changes in the clock can result in the clock apparently running
ToP   noToC   RFC1059 - Page 37
   backward, as well as incorrect delay and offset measurements of the
   synchronization mechanism itself.

   Considerable experience with the Internet environment suggests the
   values of CLOCK.MAX tabulated in Table 5.1 as appropriate.  In
   practice, these values are exceeded with a single time-server source
   only under conditions of the most extreme congestion or when multiple
   failures of nodes or links have occured.  The most common case when
   the maximum is exceeded is when the time-server source is changed and
   the time indicated by the new and old sources exceeds the maximum due
   to systematic errors in the primary reference source or large
   differences in the synchronizing path delays.

5.3.  Maintaining Date and Time

   Conversion from NTP format to the common date and time formats used
   by application programs is simplified if the internal local-clock
   format uses separate date and time registers.  The time register is
   designed to roll over at 24 hours, give or take a leap second as
   determined by the Leap Indicator bits, with its overflows
   (underflows) incrementing (decrementing) the date register.  The date
   and time registers then indicate the number of days and seconds since
   some previous reference time, but uncorrected for leap seconds.

   On the day prior to the insertion of a leap second the Leap Indicator
   bits are set at the primary servers, presumably by manual means.
   Subsequently, these bits show up at the local host and are passed to
   the logical clock procedure.  This causes the modulus of the time
   register, which is the length of the current day, to be increased or
   decreased by one second as appropriate.  On the day following
   insertion the bits are turned off at the primary servers.  While it
   is possible to turn the bits off automatically, the procedure
   suggested here insures that all clocks have rolled over and will not
   be reset incorrectly to the previous day as the result of possible
   corrections near the instant of rollover.

5.4.  Estimating Errors

   After an NTP message is received and until the next one is received,
   the accuracy of the local clock can be expected to degrade somewhat.
   The magnitude of this degradation depends on the error at the last
   update time together with the drift of the local oscillator with
   respect to time.  It is possible to estimate both the error and drift
   rate from data collected during regular operation.  These data can be
   used to determine the rate at which NTP neighbors should exchange NTP
   messages and thus control net overheads.

   NTP messages include the local-clock precision of the sender, as well
ToP   noToC   RFC1059 - Page 38
   as the reference time, estimated drift and a quantity called the
   synchronizing distance.  The precision of the local clock, together
   with its peer clocks, establishes the short-term jitter
   characteristics of the offset estimates.  The reference time and
   estimated drift of the sender provide an error estimate at the time
   the latest update was received.  The synchronizing distance provides
   an estimate of error relative to the primary reference source and is
   used by the filtering algorithms to improve the quality and
   reliability of the offset estimates.

   Estimates of error and drift rate are not essential for the correct
   functioning of the clock algorithms, but do improve the accuracy and
   adjustment with respect to net overheads.  The estimated error allows
   the recipient to compute the rate at which independent samples are
   required in order to maintain a specified estimated error.  The
   estimated drift rate allows the recipient to estimate the optimum
   polling interval.

   It is possible to compute the estimated drift rate of the local clock
   to a high degree of precision by simply adding the n offsets received
   during an interval T to an accumulator.  If X1 and X2 are the values
   of the accumulator at the beginning and end of T, then the estimated
   drift rate r is:

                               X2 - X1  n
                           r = ------- --- .
                                  n     T

   The intrinsic (uncorrected) drift rate of typical crystal oscillators
   under room-temperature conditions is in the order of from a few parts
   per million (ppm) to as much as 100 ppm, or up to a few seconds per
   day.  For most purposes the drift of a particular crystal oscillator
   is constant to within perhaps one ppm.  Assuming T can be estimated
   to within 100 ms, for example, it would take about a day of
   accumulation to estimate r to an uncertainty in the order of one ppm.

   Some idea of the estimated error of the local clock can be derived
   from the variance of the offsets about the mean per unit time.  This
   can be computed by adding the n offset squares received during T to
   an accumulator.  If Y1 and Y2 are the values of the accumulator at
   the beginning and end of T, then the estimated error s is:

                         Y2 - Y1   (X2 - X1)^2    n
                   s = ( ------- - ----------- ) --- .
                            n         n * n       T

   The quantities r and s have direct utility to the peer as noted
   above.  However, they also have indirect utility to the recipient of
ToP   noToC   RFC1059 - Page 39
   an NTP message sent by that peer, since they can be used as weights
   in such algorithms as described in [22], as well as to improve the
   estimates during periods when offsets are not available.  It is most
   useful if the latest estimate of these quantities are available in
   each NTP message sent;  however, considerable latitude remains in the
   details of computation and storage.

   The above formulae for r and s imply equal weighting for offsets
   received throughout the accumulation interval T.  One way to do this
   is using a software shift register implemented as a circular buffer.
   A single pointer points to the active entry in the buffer and
   advances around one entry as each new offset is stored.  There are
   two accumulators, one for the offset and the other for its squares.
   When a new offset arrives, a quantity equal to the new offset minus
   the old (active) entry is added to the first accumulator and the
   square of this quantity is added to the second.  Finally, the offset
   is stored in the circular buffer.

   The size of the circular buffer depends on the accumulation interval
   T and the rate offsets are produced.  In many reachability and
   routing algorithms, such as GGP, EGP and local-net control
   algorithms, peers exchange messages on the order of once or twice a
   minute.  If NTP peers exchanged messages at a rate of one per minute
   and if T were one day, the circular buffer would have to be 1440
   words long;  however, a less costly design might aggregate the data
   in something like half-hour segments, which would reduce the length
   of the buffer to 48 words while not significantly affecting the
   quality of the data.
ToP   noToC   RFC1059 - Page 40
6.  References

   1.  Lamport, L., "Time, Clocks and the Ordering of Events in a
       Distributed System", Communications of the ACM, Vol. 21, No. 7,
       pgs.  558-565, July 1978.

   2.  "Time and Frequency Dissemination Services", NBS Special
       Publication No. 432, US Department of Commerce, 1979.

   3.  Lindsay, W., and A.  Kantak, "Network Synchronization of Random
       Signals", IEEE Trans. Comm., COM-28, No. 8, pgs. 1260-1266,
       August 1980.

   4.  Braun, W., "Short Term Frequency Effects in Networks of Coupled
       Oscillators", IEEE Trans. Comm., COM-28, No. 8, pgs. 1269-1275,
       August 1980.

   5.  Mitra, D., "Network Synchronization:  Analysis of a Hybrid of
       Master-Slave and Mutual Synchronization", IEEE Trans. Comm.
       COM-28, No. 8, pgs. 1245-1259, August 1980.

   6.  Postel, J., "User Datagram Protocol", RFC-768, USC/Information
       Sciences Institute, August 1980.

   7.  Mills, D., "Time Synchronization in DCNET Hosts", IEN-173, COMSAT
       Laboratories, February 1981.

   8.  Mills, D., "DCNET Internet Clock Service", RFC-778, COMSAT
       Laboratories, April 1981.

   9.  Su, Z., "A Specification of the Internet Protocol (IP) Timestamp
       Option", RFC-781, SRI International, May 1981.

   10. Defense Advanced Research Projects Agency, "Internet Protocol",
       RFC-791, USC/Information Sciences Institute, September 1981.

   11. Defense Advanced Research Projects Agency, "Internet Control
       Message Protocol", RFC-792, USC/Information Sciences Institute,
       September 1981.

   12. Postel, J., "Daytime Protocol", RFC-867, USC/Information Sciences
       Institute, May 1983.

   13. Postel, J., "Time Protocol", RFC-868, USC/Information Sciences
       Institute, May 1983.

   14. Mills, D., "Internet Delay Experiments", RFC-889, M/A-COM
       Linkabit, December 1983.
ToP   noToC   RFC1059 - Page 41
   15. Mills, D., "DCN Local-Network Protocols", RFC-891, M/A-COM
       Linkabit, December 1983.

   16. Gusella, R., and S. Zatti, "TEMPO - A Network Time Controller for
       a Distributed Berkeley UNIX System", IEEE Distributed Processing
       Technical Committee Newsletter 6, No. SI-2, pgs. 7-15, June 1984.
       Also in: Proc.  Summer 1984 USENIX, Salt Lake City, June 1984.

   17. Halpern, J., Simons, B., Strong, R., and D. Dolly, "Fault-
       Tolerant Clock Synchronization", Proc. Third Annual ACM Symposium
       on Principles of Distributed Computing, pgs. 89-102, August 1984.

   18. Lundelius, J., and N. Lynch, "A New Fault-Tolerant Algorithm for
       Clock Synchronization:, Proc. Third Annual ACM Symposium on
       Principles of Distributed Computing, pgs. 75-88, August 1984.

   19. Lamport, L., and P. Melliar-Smith "Synchronizing Clocks in the
       Presence of Faults", JACM 32, No. 1, pgs. 52-78, January 1985.

   20. Gusella, R., and S. Zatti, "The Berkeley UNIX 4.3BSD Time
       Synchronization Protocol: Protocol Specification", Technical
       Report UCB/CSD 85/250, University of California, Berkeley, June
       1985.

   21. Marzullo, K., and S. Owicki, "Maintaining the Time in a
       Distributed System", ACM Operating Systems Review 19, No. 3, pgs.
       44-54, July 1985.

   22. Mills, D., "Algorithms for Synchronizing Network Clocks", RFC-
       956, M/A-COM Linkabit, September 1985.

   23. Mills, D., "Experiments in Network Clock Synchronization", RFC-
       957, M/A-COM Linkabit, September 1985.

   24. Mills, D., "Network Time Protocol (NTP)", RFC-958, M/A-COM
       Linkabit, September 1985.

   25. Gusella, R., and S. Zatti, "An Election Algorithm for a
       Distributed Clock Synchronization Program", Technical Report
       UCB/CSD 86/275, University of California, Berkeley, December
       1985.

   26. Sams, H., "Reference Data for Engineers:  Radio, Electronics,
       Computer and Communications (Seventh Edition)", Indianapolis,
       1985.

   27. Schneider, F., "A Paradigm for Reliable Clock Synchronization",
       Technical Report TR 86-735, Cornell University, February 1986.
ToP   noToC   RFC1059 - Page 42
   28. Tripathi, S., and S. Chang, "ETempo:  A Clock Synchronization
       Algorithm for Hierarchical LANs - Implementation and
       Measurements", Systems Research Center Technical Report TR-86-48,
       University of Maryland, 1986.

   29. Bertsekas, D., and R.  Gallager, "Data Networks", Prentice-Hall,
       Englewood Cliffs, NJ, 1987.

   30. Srikanth, T., and S. Toueg. "Optimal Clock Synchronization", JACM
       34, No. 3, pgs. 626-645, July 1987.

   31. Rickert, N., "Non Byzantine Clock Synchronization - A Programming
       Experiment", ACM Operating Systems Review 22, No. 1, pgs. 73-78,
       January 1988.
ToP   noToC   RFC1059 - Page 43
Appendix A.  UDP Header Format

   An NTP packet consists of the UDP header followed by the NTP data
   portion.  The format of the UDP header and the interpretation of its
   fields are described in [6] and are not part of the NTP
   specification.  They are shown below for completeness.

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |          Source Port          |       Destination Port        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |            Length             |           Checksum            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   Source Port

          UDP source port number. In the case of a client request this
          field is assigned by the client host, while for a server reply
          it is copied from the Destination Port field of the client
          request. In the case of symmetric mode, both the Source Port
          and Destination Port fields are assigned the NTP service-port
          number 123.

   Destination Port

          UDP destination port number. In the case of a client request
          this field is assigned the NTP service-port number 123, while
          for a server reply it is copied from the Source Port field of
          the client request. In the case of symmetric mode, both the
          Source Port and Destination Port fields are assigned the NTP
          service-port number 123.

   Length

          Length of the request or reply, including UDP header, in
          octets

   Checksum

          Standard UDP checksum
ToP   noToC   RFC1059 - Page 44
Appendix B.  NTP Data Format - Version 1

   The format of the NTP data portion, which immediately follows the UDP
   header, is shown below along with a description of its fields.


    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |LI | VN  |0 0 0|    Stratum    |      Poll     |   Precision   |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                     Synchronizing Distance                    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                     Estimated Drift Rate                      |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                  Reference Clock Identifier                   |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   |                 Reference Timestamp (64 bits)                 |
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   |                 Originate Timestamp (64 bits)                 |
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   |                  Receive Timestamp (64 bits)                  |
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   |                  Transmit Timestamp (64 bits)                 |
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   Leap Indicator (LI)

          Two-bit code warning of impending leap-second to be inserted
          at the end of the last day of the current month. Bits are
          coded as follows:

                    00      no warning
                    01      +1 second (following minute has 61 seconds)
                    10      -1 second (following minute has 59 seconds)
                    11      alarm condition (clock not synchronized)
ToP   noToC   RFC1059 - Page 45
   Version Number (VN)

          Three-bit code indicating the version number, currently one
          (1).

   Reserved

          Three-bit field consisting of all zeros and reserved for
          future use.

   Stratum

          Integer identifying stratum level of local clock. Values are
          defined as follows:

                    0       unspecified
                    1       primary reference (e.g., radio clock)
                    2...n   secondary reference (via NTP)

   Poll

          Signed integer indicating the maximum interval between
          successive messages, in seconds to the nearest power of two.

   Precision

          Signed integer indicating the precision of the local clock, in
          seconds to the nearest power of two.

   Synchronizing Distance

          Fixed-point number indicating the estimated roundtrip delay to
          the primary synchronizing source, in seconds with fraction
          point between bits 15 and 16.

   Estimated Drift Rate

          Fixed-point number indicating the estimated drift rate of the
          local clock, in dimensionless units with fraction point to the
          left of the most significant bit.

   Reference Clock Identifier

          Code identifying the particular reference clock. In the case
          of type 0 (unspecified) or type 1 (primary reference), this is
          a left-justified, zero-filled ASCII string, for example:
ToP   noToC   RFC1059 - Page 46
                    Type    Code    Meaning
                    ---------------------------------------------------
                    0       DCN     Determined by DCN routing algorithm
                    1       WWVB    WWVB radio clock (60 kHz)
                    1       GOES    GOES satellite clock (468 MHz)
                    1       WWV     WWV radio clock (5/10/15 MHz)
                    (and others as necessary)

          In the case of type 2 and greater (secondary reference), this
          is the 32-bit Internet address of the reference host.

   Reference Timestamp

          Local time at which the local clock was last set or corrected.

   Originate Timestamp

          Local time at which the request departed the client host for
          the service host.

   Receive Timestamp

          Local time at which the request arrived at the service host.

   Transmit Timestamp

          Local time at which the reply departed the service host for
          the client host.
ToP   noToC   RFC1059 - Page 47
Appendix C.  Timeteller Experiments

   In order to update data collected in June 1985 and reported in RFC-
   957, a glorious three-day experiment was carried out in January 1988
   with all the hosts and gateways listed in the NIC data base.  Four
   packets were sent at five-second intervals to each host and gateway
   using UDP/NTP, UDP/TIME and ICMP/TIMESTAMP protocols and the clock
   offsets (in milliseconds) for each protocol averaged with respect to
   local time, which is synchronized via NTP to a radio-clock host.
   While the ICMP/TIMESTAMP protocol has much finer granularity
   (milliseconds) than UDP/TIME (seconds), it has no provisions for the
   date, so is not suitable as a time-synchronization protocol;
   however, it was included in the experiments both as a sanity check
   and in order to assess the precision of measurement.

   In the latest survey of 5498 hosts and 224 gateways, 46 responded to
   UDP/NTP requests, 1158 to UDP/TIME and 1963 to ICMP/TIMESTAMP.  By
   contrast, in the 1985 survey of 1775 hosts and 110 gateways, 163
   responded to UDP/TIME requests and 504 to ICMP/TIMESTAMP.  At that
   time there were no UDP/NTP implementations.  There are many more
   hosts and gateways listed in the rapidly growing domain-name system,
   but not listed in the NIC data base, and therefore not surveyed.  The
   results of the survey are given in Table C.1, which shows for each of
   the three protocols the error X for which the distribution function
   P[x =< X] has the value shown.

           P[x=<X] UDP/NTP         UDP/TIME        ICMP/TIMESTAMP
           ------------------------------------------------------
           .1      11              4632            5698
           .2      37              18238           27965
           .3      66              38842           68596
           .4      177             68213           127367
           .5      364             126232          201908
           .6      567             195950          285092
           .7      3466            267119          525509
           .8      20149           422129          2.91426E+06
           .9      434634          807135          5.02336E+07
           1       1.17971E+09     1.59524E+09     2.11591E+09

                     Table C.1. Distribution Functions

   It can be seen that ten percent of the UDP/NTP responses show errors
   of 11 milliseconds or less and that ten percent of the UDP/TIME
   responses show errors greater than 807135 milliseconds (about 13
   minutes).  Fifty percent of the UDP/NTP timetellers are within 364
   milliseconds, while fifty percent of the UDP/TIME tellers are within
   126232 milliseconds (just over two minutes).  Surprisingly,
   ICMP/TIMESTAMP responses show errors even larger than UDP/TIME.
ToP   noToC   RFC1059 - Page 48
   However, the maximum error shown in all three protocols exceeded the
   range that could be recorded, in this case about 12 days.  Clearly,
   there are good timetellers and bad.
ToP   noToC   RFC1059 - Page 49
Appendix D.  Evaluation of Filtering Algorithms

   A number of algorithms for deglitching and filtering time-offset data
   were described in RFC-956.  These fall in two classes:  majority-
   subset algorithms, which attempt to separate good subsets from bad by
   comparing their means, and clustering algorithms, which attempt to
   improve the estimate by repeatedly casting out outlyers.  The former
   class was suggested as a technique to select the best (i.e.  the most
   reliable) clocks from a population, while the latter class was
   suggested as a technique to improve the offset estimate for a single
   clock given a series of observations.

   Following publication of RFC-956 and after further development and
   experimentation using typical Internet paths, a better algorithm was
   found for casting out outlyers from a continuous stream of offset
   observations spaced at intervals in the order of minutes.  The
   algorithm is described as a variant of a median filter, in which a
   window consisting of the last n sample offsets is continuously
   updated and the median sample selected as the estimate.  However, in
   the modified algorithm the outlyer (sample furthest from the median)
   is then discarded and the entire process repeated until only a single
   sample offset is left, which is then selected as the estimate.

   The modified algorithm was found to be more resistant to glitches and
   to provide a more accurate estimate than the unmodified one.  It has
   been implemented in the NTP daemons developed for the Fuzzball and
   Unix operating systems and been in regular operation for about two
   years.  However, recent experiments have shown there is an even
   better one which provides comparable accuracy together with a much
   lower computational burden.  The key to the new algorithm became
   evident through an examination of scatter diagrams plotting sample
   offset versus roundtrip delay.

   To see how a scatter diagram is constructed, it will be useful to
   consider how offsets and delays are computed.  Number the times of
   sending and receiving NTP messages as shown in Figure D.1 and let i
   be an even integer.  Then the timestamps t(i-3), t(i-2) and t(i-1)
   and t(i) are sufficient to calculate the offset and delay of each
   peer relative to the other.
ToP   noToC   RFC1059 - Page 50
                   Peer 1                    Peer 2
                        |                    |
                   t(1) |------------------->| t(2)
                        |                    |
                   t(4) |<-------------------| t(3)
                        |                    |
                   t(5) |------------------->| t(6)
                        |                    |
                   t(8) |<-------------------| t(7)
                        |                    |
                                 ...

                 Figure D.1. Calculating Delay and Offset

   The roundtrip delay d and clock offset c of the receiving peer
   relative to the sending peer are:


                   d = (t(i) - t(i-3)) - (t(i-1) - t(i-2))
                c = [(t(i-2) - t(i-3)) + (t(i-1) - t(i))]/2 .

   Two implicit assumptions in the above are that the delay distribution
   is independent of direction and that the intrinsic drift rates of the
   client and server clocks are small and close to the same value.  If
   this is the case the scatter diagram would show the samples
   concentrated about a horizontal line extending from the point (d,c)
   to the right.  However, this is not generally the case.  The typical
   diagram shows the samples dispersed in a wedge with apex (d,c) and
   opening to the right.  The limits of the wedge are determined by
   lines extending from (d,c) with slopes +0.5 and -0.5, which
   correspond to the locus of points as the delay in one direction
   increases while the delay in the other direction does not.  In some
   cases the points are concentrated along these two extrema lines, with
   relatively few points remaining within the opening of the wedge,
   which would correspond to increased delays on both directions.

   Upon reflection, the reason for the particular dispersion shown in
   the scatter diagram is obvious.  Packet-switching nets are most often
   operated with relatively small mean queue lengths in the order of
   one, which means the queues are often idle for relatively long
   periods.  In addition, the routing algorithm most often operates to
   minimize the number of packet-switch hops and thus the number of
   queues.  Thus, not only is the probability that an arriving NTP
   packet finds a busy queue in one direction reasonably low, but the
   probability of it finding a busy queue in both directions is even
   lower.

   From the above discussion one would expect that, at low utilizations
ToP   noToC   RFC1059 - Page 51
   and hop counts the points should be concentrated about the apex of
   the wedge and begin to extend rightward along the extrema lines as
   the utilizations and hop counts increase.  As the utilizations and
   hop counts continue to increase, the points should begin to fill in
   the wedge as it expands even further rightward.  This behavior is in
   fact what is observed on typical Internet paths involving ARPANET,
   NSFNET and other nets.

   These observations cast doubt on the median-filter approach as a good
   way to cast out offset outlyers and suggests another approach which
   might be called a minimum filter.  From the scatter diagrams it is
   obvious that the best offset samples occur at the lower delays.
   Therefore, an appropriate technique would be simply to select from
   the n most recent samples the sample with lowest delay and use its
   associated offset as the estimate.  An experiment was designed to
   test this technique using measurements between selected hosts
   equipped with radio clocks, so that delays and offsets could be
   determined independent of the measurement procedure itself.

   The raw delays and offsets were measured by NTP from hosts at U
   Maryland (UMD) and U Delaware (UDEL) via net paths to each other and
   other hosts at Ford Research (FORD), Information Sciences Institute
   (ISI) and National Center for Atmospheric Research (NCAR).  For the
   purposes here, all hosts can be assumed synchronized to within a few
   milliseconds to NBS time, so that the delays and offsets reflect only
   the net paths themselves.

   The results of the measurements are given in Table D.1 (UMD) and
   Table D.2 (UDEL), which show for each of the paths the error X for
   which the distribution function P[x =< X] has the value shown.  Note
   that the values of the distribution function are shown by intervals
   of decreasing size as the function increases, so that its behavior in
   the interesting regime of low error probability can be more
   accurately determined.
ToP   noToC   RFC1059 - Page 52
    UMD    FORD    ISI     NCAR          UMD    FORD    ISI     NCAR
    Delay  1525    2174    1423          Offset 1525    2174    1423
    ---------------------------          ---------------------------
    .1     493     688     176           .1     2       17      1
    .2     494     748     179           .2     4       33      2
    .3     495     815     187           .3     9       62      3
    .4     495     931     205           .4     18      96      8
    .5     497     1013    224           .5     183     127     13
    .6     503     1098    243           .6     4.88E+8 151     20
    .7     551     1259    265           .7     4.88E+8 195     26
    .8     725     1658    293           .8     4.88E+8 347     35
    .9     968     2523    335           .9     4.88E+8 775     53
    .99    1409    6983    472           .99    4.88E+8 2785    114
    .999   14800   11464   22731         .999   4.88E+8 5188    11279
    1      18395   15892   25647         1      4.88E+8 6111    12733

              Table D.1. Delay and Offset Measurements (UMD)

           UDEL   FORD    UMD     ISI     NCAR
           Delay  2986    3442    3215    2756
           -----------------------------------
           .1     650     222     411     476
           .2     666     231     436     512
           .3     692     242     471     554
           .4     736     256     529     594
           .5     787     272     618     648
           .6     873     298     681     710
           .7     1013    355     735     815
           .8     1216    532     845     1011
           .9     1836    1455    1019    1992
           .99    4690    3920    1562    4334
           .999   15371   6132    2387    11234
           1      21984   8942    4483    21427

                   Table D.2.a Delay Measurements (UDEL)
ToP   noToC   RFC1059 - Page 53
           UDEL   FORD    UMD     ISI     NCAR
           Offset 2986    3442    3215    2756
           -----------------------------------
           .1     83      2       16      12
           .2     96      5       27      24
           .3     108     9       36      36
           .4     133     13      48      51
           .5     173     20      67      69
           .6     254     30      93      93
           .7     429     51      130     133
           .8     1824    133     165     215
           .9     4.88E+8 582     221     589
           .99    4.88E+8 1757    539     1640
           .999   4.88E+8 2945    929     5278
           1      5.63E+8 4374    1263    10425

                  Table D.2.b Offset Measurements (UDEL)

   The results suggest that accuracies less than a few seconds can
   usually be achieved for all but one percent of the measurements, but
   that accuracies degrade drastically when the remaining measurements
   are included.  Note that in the case of the UMD measurements to FORD
   almost half the measurements showed gross errors, which was due to
   equipment failure at that site.  These data were intentionally left
   in the sample set to see how well the algorithms dealt with the
   problem.

   The next two tables compare the results of minimum filters (Table
   D.3) and median filters (Table D.4) for various n when presented with
   the UMD - - NCAR raw sample data.  The results show consistently
   lower errors for the minimum filter when compared with the median
   filter of nearest value of n.  Perhaps the most dramatic result of
   both filters is the greatly reduced error at the upper end of the
   range.  In fact, using either filter with n at least three results in
   no errors greater than 100 milliseconds.
ToP   noToC   RFC1059 - Page 54
                           Filter Samples
                   1       2       4       8       16
           P[x=<X] 1423    1422    1422    1420    1416
           - --------------------------------------------
            .1     1       1       1       0       0
            .2     2       1       1       1       1
            .3     3       2       1       1       1
            .4     8       2       2       1       1
            .5     13      5       2       2       1
            .6     20      10      3       2       2
            .7     26      15      6       2       2
            .8     35      23      11      4       2
            .9     53      33      20      9       3
            .99    114     62      43      28      23
            .999   11279   82      57      37      23
            1      12733   108     59      37      23

                         Table D.3. Minimum Filter
                               (UMD - NCAR)

                           Filter Samples
                           3       7       15
                   P[x=<X] 1423    1423    1423
                     ----------------------------
                    .1     2       2       2
                    .2     2       4       5
                    .3     5       8       8
                    .4     10      11      11
                    .5     13      14      14
                    .6     18      17      16
                    .7     23      21      19
                    .8     28      25      23
                    .9     36      30      27
                    .99    64      46      35
                    .999   82      53      44
                    1      82      60      44

                         Table D.4. Median Filter
                               (UMD - NCAR)

   While the UMD - NCAR data above represented a path across the NSFNET
   Backbone, which normally involves only a few hops via Ethernets and
   56-Kbps links, the UDEL - NCAR path involves additional ARPANET hops,
   which can contribute substantial additional delay dispersion.  The
   following Table D.5.  shows the results of a minimum filter for
   various n when presented with the UDEL - NCAR raw sample data.  The
   range of error is markedly greater than the UMD - NCAR path above,
   especially near the upper end of the distribution function.
ToP   noToC   RFC1059 - Page 55
                                Filter Samples
                        1       2       4       8       16
                P[x=<X] 2756    2755    2755    2753    2749
                --------------------------------------------
                 .1     12      9       8       7       6
                 .2     24      19      16      14      14
                 .3     36      27      22      20      19
                 .4     51      36      29      25      23
                 .5     69      47      36      30      27
                 .6     93      61      44      35      32
                 .7     133     80      56      43      35
                 .8     215     112     75      53      43
                 .9     589     199     111     76      63
                 .99    1640    1002    604     729     315
                 .999   5278    1524    884     815     815
                 1      10425   5325    991     835     815

                   Table D.5. Minimum Filter (UDEL - NCAR)

   Based on these data, the minimum filter was selected as the standard
   algorithm.  Since its performance did not seem to much improve for
   values of n above eight, this value was chosen as the standard.
   Network Time Protocol (Version 1): Specification and Implementation.
ToP   noToC   RFC1059 - Page 56
Appendix E.  NTP Synchronization Networks

   This section discusses net configuration issues for implementing a
   ubiquitous NTP service in the Internet system.  Section E.1 describes
   the NTP primary service net now in operation, including an analysis
   of failure scenarios.  Section E.2 suggests how secondary service
   nets, which obtain wholesale time from the primary service net, can
   be configured to deliver accurate and reliable retail time to the
   general host population.

E.1.  Primary Service Network

   The primary service net consists of five primary servers, each of
   which is synchronized via radio or satellite to a national time
   standard and thus operates at stratum one.  Each server consists of
   an LSI-11 Fuzzball, a WWVB or GOES radio clock and one or more net
   interfaces.  Some servers provide switching and gateway services as
   well.  Table E.1 shows the name, Internet address, type of clock,
   operating institution and identifying code.

Name          Address         Clock   Operating Institution and (Code)
----------------------------------------------------------------------
DCN5.ARPA     128.4.0.5       WWVB    U Delaware, Newark, DE (UDEL)
FORD1.ARPA    128.5.0.1       GOES    Ford Research, Dearborn, MI
                                        (FORD)
NCAR.NSF.NET  128.116.64.3    WWVB    National Center for Atmospheric
                                        Research, Boulder, CO (NCAR)
UMD1.UMD.EDU  128.8.10.1      WWVB    U Maryland, College Park, MD
                                        (UMD)
WWVB.ISI.EDU  128.9.2.129     WWVB    USC Information Sciences
                                        Institute, Marina del Rey, CA
                                        (ISI)

                       Table E.1. Primary Servers

   Figure E.1 shows how the five primary servers are interconnected as
   NTP peers.  Note that each server actively probes two other servers
   (along the direction of the arrows), which means these probes will
   continue even if one or both of the two probed servers are down.  On
   the other hand, each server is probed by two other servers, so that
   the result, assuming all servers are up, is that every server peers
   with every other server.
ToP   noToC   RFC1059 - Page 57
               +------------------------------------------------+
               V                                                |
           +--------+              +--------+              +--------+
           |        |<-------------|        |<-------------|        |
           |  NCAR  |              |  ISI   |              |  FORD  |
           |        |----+      +--|        |<--+    +---->|        |
           +--------+    |      |  +--------+   |    |     +--------+
               |         |      |               |    |          A
               |     +---|------|---------------|----+          |
               |     |   |      |               |               |
               |     |   +------|---------------|---------+     |
               |     |          |               |         |     |
               |     |          |               |         V     |
               |   +--------+   |               |  +--------+   |
               |   |        |<--+               +--|        |   |
               +-->|  UMD   |                      |  UDEL  |---+
                   |        |--------------------->|        |
                   +--------+                      +--------+

                    Figure E.1. Primary Service Network

   All of the five primary servers shown are directly connected to a
   radio clock and thus normally operate at stratum one.  However, if
   the radio clock itself becomes disabled or the propagation path to
   its synchronizing source fails, then the server drops to stratum two
   and synchronizes via NTP with its neighbor at the smallest
   synchronizing distance.  If a radio clock appears to operate
   correctly but delivers incorrect time (falseticker), the server may
   remain synchronized to the clock.  However, gross discrepancies will
   become apparent via the NTP peer paths, which will ordinarily result
   in an operator alarm.

   Assume that, if a radio clock appears up, it is a truechimer;
   otherwise, the clock appears down.  Then the above configuration will
   continue to provide correct time at all primary servers as long as at
   least one radio clock is up, all servers are up and the servers
   remain connected to each other through the net.  The fact that the
   graph and all of its subgraphs are completely connected lends an
   incredible resilience to the configuration.

   If some radio clocks appear up but are in fact falsetickers, the
   primary servers connected to those clocks will not provide correct
   time.  However, as the consequents of the voting procedure and
   complete connectivity of the graph and its subgraphs, any combination
   of two falsetickers or of one falseticker and one down server will be
   detected by their truechimer neighbors.
ToP   noToC   RFC1059 - Page 58
E.2.  Secondary Service Networks

   A secondary server operating at stratum n > 1 ordinarily obtains
   synchronization using at least three peer paths, two with servers at
   stratum n-1 and one or more with servers at stratum n.  In the most
   robust configurations a set of servers agree to provide backup
   service for each other, so distribute some of their peer paths over
   stratum-(n-1) servers and others over stratum-n servers in the same
   set.  For instance, in the case of a stratum-2 service net with two
   secondary servers and the primary service net of Figure E.1, there
   are five possible configurations where each stratum-1 path ends on a
   different primary server.  Such configurations can survive the loss
   of three out of the four stratum-1 servers or net paths and will
   reject a single falseticker on one of the two stratum-1 paths for
   each server.

   Ordinary hosts can obtain retail time from primary or secondary
   service net using NTP in client/server mode, which does not require
   dedicated server resources as does symmetric mode.  It is anticipated
   that ordinary hosts will be quite close to a secondary server,
   perhaps on the same cable or local net, so that the frequency of NTP
   request messages need only be high enough, perhaps one per hour or
   two, to trim the drift from the local clock.