3. Network Time Protocol
The Network Time Protocol (NTP) is used to construct and maintain a set of time servers and transmission paths as a synchronization subnet. The protocol was first described in [MIL85c], extensively revised in successive versions and recently established as a formal Internet Standard protocol [MIL89a]. NTP is built on the Internet Protocol (IP) [DAR81b] and User Datagram Protocol (UDP) [POS80], which provide a connectionless transport mechanism; however, it is readily adaptable to other protocol suites. It is evolved from the Time Protocol [POS83b] and the ICMP Timestamp Message [DAR81a], but is specifically designed to maintain accuracy and reliability, even when used over typical Internet paths involving multiple gateways and unreliable nets.
Figure 1. Implementation Model
There is no provision for peer discovery, acquisition, or authentication in NTP itself, although some implementations include these features. Data integrity is provided by the IP and UDP checksums. No circuit-management, duplicate-detection or retransmission facilities are provided or necessary. The protocol can operate in several modes appropriate to different scenarios involving private workstations, public service machines and various network configurations. A lightweight association-management capability, including dynamic reachability and variable polling-rate mechanisms, is used to manage state information and reduce resource requirements. Optional features include message authentication based on crypto-checksums and provisions for remote control and monitoring. Since only a single NTP message format is used, the protocol is easily implemented and can be used in a variety of operating-system and networking environments.
The following subsections contain an overview of the data formats, entities, state variables and procedures used in NTP. Further details are contained in the formal specification. The specification is based on the implementation model illustrated below, but it is not intended that this model be the only one upon which a specification can be based. In particular, the specification is intended to illustrate and clarify the intrinsic operations of NTP and serve as a foundation for a more rigorous, comprehensive and verifiable specification.
In what may be the most common client/server modes a client sends an NTP message to one or more time servers, which process the replies as received. A server interchanges addresses, overwrites certain fields in the message, recalculates the checksum and returns the message immediately. Information included in the NTP message allows the client to determine the server time with respect to local time and adjust the local clock accordingly. In addition, the message includes information to calculate the expected timekeeping accuracy and reliability, so that inferior data can be discarded and only the best from possibly several servers can be selected. While the client/server modes may suffice for use on LANs involving a public time server and perhaps many private workstation clients, the full generality of NTP requires distributed participation of a number of client/servers or peers arranged in a dynamically reconfigurable, hierarchically distributed configuration. It also requires sophisticated algorithms for association management, data manipulation and local clock control as described below.
3.1. Implementation Model
Figure 1 shows an implementation model for a time-server host including three processes sharing a partitioned data base, with a partition dedicated to each peer, and interconnected by a message-passing system. The transmit process, driven by independent timers for each peer, collects information in the data base and sends NTP messages to the peers. Each message contains the local timestamp when the message is sent, together with previously received timestamps and other information necessary to determine the hierarchy and manage the association. The message transmission rate is determined by the accuracy required of the local clock, as well as the estimated accuracies of its peers.
The receive process receives NTP messages and perhaps messages in other protocols, as well as information from directly connected timecode receivers. When a message is received the offset between the peer clock and the local clock is computed and incorporated into the data base along with other information useful for error estimation and peer selection. A filtering algorithm described in Section 4 improves the estimates by discarding inferior data.
The update procedure is initiated upon receipt of a message and at other times. It processes the offset data from each peer and selects the best one using the selection algorithm of Section 4. This may involve many observations of a few peers or a few observations of many peers, depending on the accuracies required.
The local-clock process operates upon the offset data produced by the update algorithm and adjusts the phase and frequency of the local clock using the mechanism described in Section 5. This may result in either a step change or a gradual slew adjustment of the local clock to reduce the offset to zero. The local clock provides a stable source of time information to other users of the system and for subsequent reference by NTP itself.
3.1.1. Modes of Operation
An NTP association is formed when two peers exchange messages and one or both of them create and maintain an instantiation of the protocol machine. The machine can operate in one of five modes: symmetric active, symmetric passive, client, server and broadcast. When an association is formed one or both peers must be operating in an active mode (symmetric active, client or broadcast), in which the active peer sends messages to the other peer regardless of the mode, reachability state or stratum of the other peer. If due to crash restart or defective programming both peers are found to be operating in a passive mode (symmetric passive or server), each peer ignores the messages of the other, so that eventually each will find the other unreachable and demobilize the association. In symmetric passive and server modes the identity of the other peer need not be known in advance, since an association with persistent state variables is created only when an NTP message arrives.
Furthermore, the state storage can be reused when the peer becomes unreachable or begins operating at a higher stratum and thus ineligible as a synchronization source.
The symmetric modes are intended for distributed scenarios where either peer can potentially become the reference source for the other. By operating in these modes a host announces its willingness to synchronize to and be synchronized by the peer. Symmetric active mode is designed for use by hosts operating near the leaves (high stratum levels) of the synchronization subnet, while symmetric passive mode is designed for use by hosts operating near the root (low stratum levels) and with a relatively large number of peers on an intermittent basis. Reliable time service can usually be maintained with two peers at the next lower stratum level and one peer at the same stratum level, so the rate of ongoing polls is usually not significant, even when connectivity is lost and error messages are being returned from the network for every poll.
Broadcast mode is intended for operation with high speed LANs and numerous workstations where the highest accuracies are not required. In the typical scenario one or more LAN time-server hosts send periodic NTP messages to the LAN broadcast address. The LAN workstations then determine the time on the basis of a preconfigured latency in the order of a few milliseconds. By operating in this mode the host announces its willingness to provide synchronization to the peers, but not to accept NTP messages from them.
The client and server modes are intended for operation with file servers and workstations requiring the highest accuracies or where broadcast mode is unavailable or inappropriate. A host operating in client mode sends periodic NTP messages to one or more servers. By operating in this mode the host announces its willingness to be synchronized by, but not to provide synchronization to the peer. A host operating in server mode simply interchanges the source and destination addresses/ports, fills in the requested timestamps and returns the message to the client. Hosts operating in server mode need retain no state information between client requests, while clients are free to manage the intervals between messages to suit local conditions. By operating in this mode the host announces its willingness to provide synchronization to, but not to be synchronized by the peer.
3.1.2. Data Formats
All mathematical operations assumed in the protocol are two’s-complement arithmetic with integer or fixed-point operands. Since NTP timestamps are cherished data and, in fact, represent the main product of the protocol, a special format has been established. An NTP timestamp is a 64-bit unsigned fixed-point number, with the integer part in the first 32 bits and the fraction part in the last 32 bits and interpreted in standard seconds relative to UTC. When UTC began at zero hours on 1 January 1972 the NTP clock was set to 2,272,060,800.0, representing the number of standard seconds since this time on 1 January 1900 (assuming no prior leap seconds).
This format allows convenient multiple-precision arithmetic and conversion to other formats used by various protocols of the Internet suite. The precision of this representation is about 2^32 picoseconds, which should be adequate for even the most exotic requirements. Note that since some time in 1968 the most significant bit of the 64-bit field has been set and that the field will overflow some time in 2036. Should NTP be in use in 2036, some external means will be necessary to qualify time relative to 1900 and subsequent 136-year cycles. Timestamped data requiring such qualification will be so precious that appropriate means should be readily available.
Figure 2. NTP Packet Header
Timestamps are determined by copying the current value of the local clock to a timestamp variable when some significant event occurs, such as the arrival of a message. In some cases a particular variable may not be available, such as when the host is rebooted or the protocol first starts up. In these cases the 64-bit field is set to zero, indicating the value is invalid or undefined. There will exist an 2^32-picosecond interval, henceforth ignored, every 136 years when the 64-bit field will naturally become zero and thus be considered invalid.
3.1.3. State Variables
Following is a summary description of the important variables and parameters used by the protocol. In appropriate modes a set of state variables is maintained for the host itself along with separate copies for each peer with an active association. Further information on these variables is given later in this paper. A complete description is given in [MIL89a].
Figure 2 shows the NTP packet-header format, which ordinarily follows the IP and UDP headers. Following is a description of the various fields.
Version Number (VN). Identifies the present NTP version.
Leap Indicator (LI). Warns of an impending leap second to be inserted or deleted in the timescale at the end of the current day.
Mode, Stratum, Precision. Indicate the current operating mode, stratum and precision.
Poll Interval. Controls the intervals between NTP messages sent by the host to a peer. The sending host always uses the minimum of its own poll interval and the peer poll interval.
Synchronizing Distance, Synchronizing Dispersion. Indicate the estimated roundtrip delay and estimated sample dispersion, respectively, to the primary reference source.
Reference Clock Identifier, Reference Timestamp. Identify the reference clock and the time of its last update, intended primarily for management functions.
Originate Timestamp. The time when the last received NTP message was originated, copied from its transmit timestamp field upon arrival.
Receive Timestamp. The local time when the latest NTP message was received.
Transmit Timestamp. The local time when the latest NTP message was transmitted.
Authenticator (optional). The key identifier and encrypted checksum of the message contents.
The NTP protocol machine maintains state variables for each of the above quantities and, in addition, other state variables, including the following:
Addresses and Ports. The 32-bit Internet addresses and 16-bit port numbers of the host and its peers, which serve to identify the association.
Peer Timer. A counter used to control the intervals between transmitted NTP messages.
Reachability Register. A shift register used to determine the reachability status of the peer.
Filter Register. A shift register where each stage stores a tuple consisting of the measured delay and offset associated with a single observation.
Delay Estimate, Offset Estimate, Dispersion Estimate. Indicate the current estimated roundtrip delay, clock offset and dispersion produced by the filter procedure.
Clock Source. A selector identifying the current clock source determined by the selection procedure.
Local Clock. The current local time as derived from the host logical clock.
3.2. Procedures
The significant events of interest in NTP occur upon expiration of a peer timer, one of which is dedicated to each peer with an active association, 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 subsection describes the procedures invoked when these events occur.
The transmit procedure is called when a peer timer decrements to zero and can occur in all modes except server mode. When this occurs the peer timer is reset and an NTP message is sent including the addresses, variables and timestamps described above. The value used to reset the timer is called the polling interval and is adjusted dynamically to reflect network peer path conditions.
Figure 3. Calculating Delay and Offset
The receive procedure is called upon arrival of an NTP message, which is then matched with the peer association indicated by its addresses and ports. If there is no match a new instantiation of the protocol machine is created and the peer association mobilized. Following a set of sanity checks 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 and let i be an even integer. Then t_i-3 , t_i-2 , t_i-1 and t_i are the message arrival and departure timestamps in the order shown and the roundtrip delay d_i and clock offset c_i of the peer relative to the host are computed as follows:
di = (ti - ti-3) - (ti-1 - ti-2) ,
(ti-2 - ti-3) + (ti-1 - ti)
ci = ---------------------------- .
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 are unimportant and that reliable delivery is not required.
The offset c_i is then checked for validity relative to the estimated maximum skew and stated precision of the host and peer clocks. The filter procedure is called with c_i and d_i as arguments to produce the estimated delay, offset and dispersion for the peer involved. The minimum-filter algorithm described in Section 4 is used to improve these estimates depending upon the statistical properties of the outbound and inbound transmission paths.
The update procedure is called when a new delay/offset estimate becomes available. A weighted voting procedure described in Section 4 determines the best peer, which may result in a new clock source. If the clock source is the peer involved, the estimated offset is used to update the local clock as described in Section 5. If the local clock is reset, rather than gradually slewed to its final value, the clear procedure is called repeatedly for every active peer to purge the clock filter, reset the polling interval and reselect the clock source, if necessary. A new selection will occur when the filters fill up again and the dispersions settle down.
3.3. Robustness Issues
It has been the experience of the Internet community that something somewhere in the system is always broken at any given time. This caveat applies to timecode receivers, time servers and synchronization paths, any of which can misbehave to produce a bogus timestamp popularly known as a timewarp. The very nature of time synchronization requires that it be extremely robust against timewarps and capable of operation even when major breakdowns or attempted breakins occur. This subsection describes some of the measures taken to deal with these problems, including reachability determination, authentication, sequence checking and polling rates.
As shown previously, reliable time synchronization does not require reliable message delivery; however, in order to minimize resource requirements, resist using very old data and manage the number of associations required, a simple reachability protocol is used. Each time an NTP message is sent an eight-bit reachability register is shifted one position to the left and the low-order position set to zero. If an NTP message is received before the next message is sent, the low-order bit is set to one. The peer is considered reachable if the register is nonzero, which will always be the case if at least one message is received during eight consecutive transmit intervals. In the passive modes if a peer becomes unreachable, the association is demobilized and its resources reclaimed for subsequent associations. This shift-register mechanism has also been found most effective in other Internet protocols designed to survive unstable network service.
While not a required feature of NTP itself, some implementations have included an access-control feature that prevents unauthorized access and controls which peers are allowed to update the local clock. This is done with tables of mask-and-match entries which allow only servers with Internet addresses in certain ranges to become peers and to update the local clock. In principle, this feature is not necessarily desirable, since the basic NTP design involving a large degree of diversity is intended to cast out falsetickers whether they are authenticated or not. Nevertheless, the additional authentication feature may help to deflect multiple-peer destructive jamming.
During the course of normal operation various peers may on occasion restart the NTP program itself, either due to loss of reachability, reboot or other trauma, which results in loss of state information. Special sanity checks are built into the receive procedure to avoid disruption in such cases. One check requires the transmit timestamp of a received message to be different than the transmit timestamp of the last message received. If they are the same, the message is a duplicate and must have been circulating in the network for some time after the last message was received, thus containing relatively inferior data. Another check requires the originate timestamp of a received message to be identical to the transmit timestamp of the last message transmitted. If they do not match, the message is either out of order, from a previous association or bogus. Additional checks protect against using very old time information and from associations not completely synchronized.
Where security considerations require the highest level of protection against message modification, replay and other overt attacks, the NTP specification includes optional cryptographic authentication procedures. The procedures are used to insure an unbroken chain of authenticated peers along the synchronization subnet to the primary servers. An authenticator, consisting of a key identifier and encrypted checksum, is computed using the DES encryption algorithm and DES cipher block-chaining method. Present implementations have incorporated special provisions to avoid degradation in timekeeping accuracy due to the delays caused by the encryption computations.
Careful consideration was given during design to factors affecting network overheads. Many of the present Internet primary time servers operate with 100 peers or more and some operate with many more than that. Therefore, it is important that the longest polling intervals consistent with the required accuracy and reliability be used. When reachability is first confirmed and when a peer is currently selected for synchronization it is necessary to use a relatively short polling interval in the order of a minute. In those cases where the association has stabilized, the dispersions are low and the peer is not selected for synchronization, the polling interval can be increased substantially. In the present design the polling interval is increased gradually from about one minute to about 17 minutes as long as the dispersion is below an experimentally determined threshold; otherwise, it is decreased gradually to the initial value. These values may change as the result of further experience.