Home » Blog » NTP Protocol – Technology Wednesdays

NTP Protocol – Technology Wednesdays

The NTP (Network Time Protocol) protocol allows the time synchronization of any computer or device connected to a communications network.

It is a client/server protocol where the computers that must be synchronized act as clients by sending synchronization requests (NTP requests) to another or other devices that act as a server and that deliver the exact date and time (NTP reply). The exchange of messages as well as a summary of the calculation of the offset or delay between sending the request and receiving the response can be seen in the following figure.

Source: ADVA and Osciloquartz

The NTP protocol is structured in a hierarchical way where the same computer or node in the network can act as a client and server at the same time. As a server, it serves NTP requests from lower computers, and as a client, it requests time more accurately from higher computers, as shown in the following figure. Also, some computers can work in 'peer' mode by obtaining the clock from another server but being able, in turn, to deliver the clock to that server if it requests it.

As shown in the figure, the clock or synchronism degrades as we go down the level since each client/server transaction implies a loss of precision derived from the variable transmission and processing delays of the NTP packets in each of the intermediate nodes. The higher the Stratum number, the lower the accuracy of the clock.

Format of NTP packets

The following figure shows the format and contents of the NTP reply packet in version 4 that is delivered by an NTP server at the request of any client. NTP packets are encapsulated in UDP and typically use port 123.

Source: Wikipedia

Below we describe the fields in detail.

LI Leap Indicator (2-bit)
This field indicates whether the last minute of the current day should have a leap second. The values are:
0: No leap second setting (60 seconds)
1: The last minute of the day has 61 seconds
2: The last minute of the day has 59 seconds
3: Clock NOT Synced
VN NTP Version (3-bit) (the latest version is 4).
Mode NTP node operating mode (3-bit)
0: Reserved
1: Active Symmetrical
2: Passive Symmetrical
3: Customer
4: Server
5: Broadcast
6: NTP control message
7: Reserved for private use
Stratum Sync source Stratum level (8-bit)
0: Unspecified or Invalid
1: Primary server (GPS or atomic clock)
2–15: Secondary Server (NTP or SNTP)
16: Not Synced
17–255: Reserved
Poll Poll interval (8-bit signed integer)

It is an 8-bit signed integer that indicates the maximum interval of time between two successive messages, expressed in seconds and as the nearest power of 2. Most applications use the range from 6 bits (64 sec) to 10 bits (1024 sec)

Precision Clock accuracy (8-bit signed integer)

It is an integer with a sign that indicates the precision of the local clock expressed in seconds 1/2^Precision

Root Delay The round-trip delay between the server and the primary clock source. The value is a 32-bit decimal with a sign expressed in seconds and with the fractional part between bits 15 and 16. This field is only meaningful in inter-server messages.
Root Dispersion It is the maximum error due to the frequency dispersion of the clock. The value is a 32-bit decimal with a sign expressed in seconds and with the fractional part between bits 15 and 16. This field is only meaningful in inter-server messages.
Reference Identifier For Stratum 1 servers, it is a 4-character string that indicates the font type according to the following table. For secondary servers, it is either a 32-bit IPV4 address pointing to the source NTP server or the first 32 bits of the Message Digest Algorithm 5 (MD5) hash of the IPv6 address of that synchronization source (for NTP versions 4 only)

Table for reference identifiers of Stratum 1 watches

Below we show a screenshot of an NTP packet made with Wireshark where we can verify the fields described above.

Timestamps and how the current date and time is calculated

At NTP we calculate the current date and time through timestamps. The timestamp is a number of 64 bits (NTP version 3) or 128 bits (NTP version 4). Of these bits, the first 32 or 64 bits are used as the power of 2 to indicate the time in seconds elapsed from 0:00 on January 1, 1900. The 32-bit or 64-bit seconds are used to indicate the current fraction of the second.

In NTP version 3 we can estimate 2^32 = 4,294,967,296 seconds that correspond to just over 136 years. Therefore with NTP v3 we can show dates up to February 7, 2036 = 1900+136. We can also estimate the fraction of the second up to 1/(2^32) = 232 picoseconds. In reality, the processing times and transmission of information will never allow us this level of precision.

If you want more information on how times are calculated in NTP you can see the David L. Mills

In the NTP packages we include timestamps that we use to calculate the offset or variation with respect to the previous measurement in the client according to the following calculation as shown in the first figure of the post:

T1=Origin Timestamp (on client)
T2=Receive Timestamp (on server)
T3=TransmitTimestamp (on server)
T4=DestinationTimestamp = ReceiveTimestamp (on client)

offset = [ (T2-T1) + (T3-T4) ] / 2

In the offset calculation we assume a symmetrical lattice delay by dividing the RTD (Round Trip Delay) by 2. This offset can be especially relevant when the server is on the Internet or we use a low-speed transmission medium (PSTN, ISDN or satellite).

NTP Version 3 and NTP Version 4

NTP version 4 emerged as an evolution of version 3 but maintains interoperability with systems based on the previous version. The main differences are:

  • allows IPV6 addressing between clients and servers
  • allows security to be incorporated into communications through the encryption of NTP packets with a symmetric public key
  • Modifies the data type for timestamps from 64-bit fixed format to 64-bit floating-point to reduce packet size and increase the range of available values
  • The time reference is extended with the concepts of era and offset era
  • An automatic system is added to discover, configure, and authenticate servers and clients without the need to manually specify them. In multicast mode, an NTP server sends packets at regular intervals using a specific multicast group

Our NTP servers

At DAVANTEL we have different NTP servers that act as Stratum 1 clocks as they have an integrated GPS receiver.

The family GPS NTP are simple NTP servers version 3 with an active GPS receiver that is powered via UTP cable from the NTP server itself. They are low-cost and especially suitable for small installations where we do not need great stability in the absence of a GPS signal.

We also have NTP/PTP servers of greater precision by incorporating an OCXO oscillator capable of maintaining the time more accurately and longer in the absence of a GPS signal.

1 star2 stars3 stars4 stars5 stars (2Votes, average: 5,00of 5)
Loading...