Network Time Protocol
Network Time Protocol
Contents
Network Time Protocol................................................................................................ 1
Introduction.............................................................................................................. 2
Features of NTP......................................................................................................... 3
NTP Versions............................................................................................................. 4
Implementation of system........................................................................................ 5
References.................................................................................................................. 8
MILO DAVITKOVI 1
Introduction
Network Time Protocol (NTP) is a networking protocol for clock synchronization between
computer systems over packet-switched, variable-latency data networks. In operation since before 1985,
NTP is one of the oldest Internet protocols in current use. NTP stands for Network Time Protocol, and it is
an Internet protocol used to synchronize the clocks of computers to some time reference.
NTP is intended to synchronize all participating computers to within a few milliseconds of
Coordinated Universal Time (UTC). It uses a modified version of Marzullo's algorithm to select accurate
time servers and is designed to mitigate the effects of variable network latency. NTP can usually maintain
time to within tens of milliseconds over the public Internet, and can achieve better than one millisecond
accuracy in local area networks under ideal conditions. Asymmetric routes and network congestion can
cause errors of 100 ms or more.
The protocol is usually described in terms of a client-server model, but can as easily be used in
peer-to-peer relationships where both peers consider the other to be a potential time source.
Implementations send and receive timestamps using the User Datagram Protocol (UDP) on port number
123. They can also use broadcasting or multicasting, where clients passively listen to time updates after an
initial round-trip calibrating exchange. NTP supplies a warning of any impending leap second adjustment,
but no information about local time zones or daylight saving time is transmitted.
Accurate time across a network is important for many reasons; even small fractions of a second
can cause problems. For example, distributed procedures depend on coordinated times to ensure that
proper sequences are followed. Security mechanisms depend on coordinated times across the network.
File system updates carried out by a number of computers also depend on synchronized clock times. Air
traffic control systems provide a graphic illustration of the need for coordinated times, since flight paths
require very precise timing (imagine the situation if air traffic controller computer clock times were not
synchronized).
Time usually just advances. If you have communicating programs running on different computers,
time still should even advance if you switch from one computer to another. Obviously if one system is
ahead of the others, the others are behind that particular one. From the perspective of an external observer,
switching between these systems would cause time to jump forward and back, a non-desirable effect.
As a consequence, isolated networks may run their own wrong time, but as soon as you connect to
the Internet, effects will be visible. Just imagine some EMail message arrived five minutes before it was
sent, and there even was a reply two minutes before the message was sent.
Even on a single computer some applications have trouble when the time jumps backwards. For
example, database systems using transactions and crash recovery like to know the time of the last good
state. Therefore, air traffic control was one of the first applications for NTP.
Features of NTP
What are the basic features of NTP?
There exist several protocols to synchronize computer clocks, each having distinguished features.
Here is a list of NTP's features:
o NTP needs some reference clock that defines the true time to operate. All clocks are set
towards that true time. (It will not just make all systems agree on some time, but will
make them agree upon the true time as defined by some standard.)
o NTP is a fault-tolerant protocol that will automatically select the best of several available
time sources to synchronize to. Multiple candidates can be combined to minimize the
accumulated error. Temporarily or permanently insane time sources will be detected and
avoided.
o Having available several time sources, NTP can select the best candidates to build its
estimate of the current time. The protocol is highly accurate, using a resolution of less
than a nanosecond (about 2-32 seconds). (The popular protocol used by rdate and defined
in [RFC 868] only uses a resolution of one second).
o Even when a network connection is temporarily unavailable, NTP can use measurements
from the past to estimate current time and error.
o For formal reasons NTP will also maintain estimates for the accuracy of the local time.
NTP Versions
If you are worried with compatibility issues, older version clients can generally talk to newer
version servers automagically (as newer servers know how to answer the queries, hopefully), but the other
direction requires manual interference (See html/confopt.htm about the version keyword).
NTPv4 introduces some new features that you may find desirable (See Q: 4.1.9.). For example, if
you use dial-up connections, version four can increase its polling interval above one day if the clock is
stable enough. In addition the new algorithms can deal with high delay variations a bit better than the
LAN-oriented version three. On the other hand, NTPv4 uses floating point operations where NTPv3 used
integer arithmetic. This should not be a problem for current hardware, but might be an issue for older
systems without a floating point unit.
There is also a security issue with all versions probably older than 4.0.99k23 that may allow
denial of service or even unauthorized system access. Still vendors supplying older versions may have
fixed their particular version.
What's new in Version 4?
According to the NTP Version 4 Release Notes found in release.htm, the new features of version
four (as compared to version three) are:
Implementation of system
Background of the system
NTP uses Coordinated Universal Time (UTC) to synchronize computer clock times to a
millisecond, and sometimes to a fraction of a millisecond. UTC time is obtained using several different
methods, including radio and satellite systems. Specialized receivers are available for high-level services
such as the Global Positioning System (GPS) and the governments of some nations. However, it is not
practical or cost-effective to equip every computer with one of these receivers. Instead, computers
designated as primary time servers are outfitted with the receivers and they use protocols such as NTP to
synchronize the clock times of networked computers. Degrees of separation from the UTC source are
defined as strata. A radio clock (which receives true time from a dedicated transmitter or satellite
navigation system) is stratum-0; a computer that is directly linked to the radio clock is stratum-1; a
computer that receives its time from a stratum-1 computer is stratum-2, and so on.
Figure 1 shows two NTP time formats, a 64-bit timestamp format and a 128-bit datestamp format.
The datestamp format is used internally, while the timestamp format is used in packet headers exchanged
between clients and servers. The timestamp format spans 136 years, called an era. The current era began
on 1 January 1900, while the next one begins in 2036. Details on these formats and conversions between
them are in the white paper The NTP Era and Era Numbering. However, the NTP protocol will
synchronize correctly, regardless of era, as long as the system clock is set initially within 68 years of the
correct time. Further discussion on this issue is in the white paper NTP Timestamp Calculations.
Ordinarily, these formats are not seen by application programs, which convert these NTP formats to native
Unix or Windows formats.
The overall organization of the NTP architecture is shown in Figure 2. It is useful in this context
to consider the implementation as both a client of upstream (lower stratum) servers and as a server for
downstream (higher stratum) clients. It includes a pair of peer/poll processes for each reference clock or
remote server used as a synchronization source. Packets are exchanged between the client and server using
the on-wire protocoldescribed in the white paper Analysis and Simulation of the NTP On-Wire Protocols.
The protocol is resistant to lost, replayed or spoofed packets.
The poll process sends NTP packets at intervals ranging from 8 s to 36 hr. The intervals are
managed as described on the Poll Process page to maximize accuracy while minimizing network load. The
peer process receives NTP packets and performs the packet sanity tests described on the Event Messages
and Status Words page and flash status word. The flash status word reports in addition the results of
various access control and security checks described in the white paper NTP Security Analysis. A
sophisticated traffic monitoring facility described on the Rate Management and the Kiss-o'-Death
Packet page protects against denial-of-service (DoS) attacks.
Packets that fail one or more of these tests are summarily discarded. Otherwise, the peer process
runs the on-wire protocol that uses four raw timestamps: the origin timestamp T1 upon departure of the
client request, the receive timestamp T2 upon arrival at the server, the transmit timestamp T3 upon
departure of the server reply, and the destination timestamp T4 upon arrival at the client. These
timestamps, which are recorded by the rawstats option of the filegen command, are used to calculate the
clock offset and roundtrip delay samples:
offset = [(T2 - T1) + (T3 - T4)] / 2,
delay = (T4 - T1) - (T3 - T2).
In this description the transmit timestamps T1 and T3 are softstamps measured by the inline code.
Softstamps are subject to various queuing and processing delays. A more accurate measurement
uses drivestamps, as described on the NTP Interleaved Modes page. These issues along with mathematical
models are discussed in the white paper NTP Timestamp Calculations.
The offset and delay statistics for one or more peer processes are processed by a suite of
mitigation algorithms. The algorithm described on the Clock Filter Algorithm page selects the offset and
delay samples most likely to produce accurate results. Those servers that have passed the sanity tests are
declared selectable. From the selectable population the statistics are used by the algorithm described on
the Clock Select Algorithm page to determine a number of truechimers according to Byzantine agreement
and correctness principles. From the truechimer population the algorithm described on the Clock Cluster
Algorithm page determines a number of survivors on the basis of statistical clustering principles.
The algorithms described on the Mitigation Rules and the prefer Keyword page combine the
survivor offsets, designate one of them as the system peer and produces the final offset used by the
algorithm described on the Clock Discipline Algorithm page to adjust the system clock time and
frequency. The clock offset and frequency, are recorded by the loopstats option of the filegen command.
For additional details about these algorithms, see the Architecture Briefing on the Network Time
Synchronization Research Project page. For additional information on statistacl principles and
performance metrics, see the Performance Metrics page.
References
eecis. How NTP Works. [Online]
https://www.eecis.udel.edu/~mills/ntp/html/warp.html.