...

/

What is NTP and how it works?

What is NTP and how it works?

We'll understand the purpose of Network Time Protocol and how it works to

Network Time Protocol (NTP)

We’ve already seen that computer clocks can be skewed over time.

NTP is a protocol that allows a computer to synchronize its clock to the correct time. There’s typically a daemon in the Node that continuously updates its clock from an NTP server in the network.

The first question is - if every computer has a Quartz clock that can drift, how can we consider the time of any computer the true time?

This brings us to reference clocks.

What is a Reference Clock?

NTP is designed as a hierarchal client-server system in which a client gets the true time from a known NTP server which in return could have obtained the time from another higher level NTP server. At the very top of this system are machines called Reference Clocks.

Reference clocks are specialized machines that use Atomic Clocks or GPS signals through satellites to update their time. Lower level NTP servers synchronize their time from these reference clocks.

To understand the hierarchy of NTP servers, let’s look at Stratum.

What is a Stratum?

The stratum is the degree of separation between an NTP server and a Reference Server.

In other words, the number of machines between the current Node and the Reference Clock is known as Stratum.

Refernce clocks are known as Stratum0 machines.

NTP servers talking to Stratum0 servers are known as Stratum1 servers and so forth.

[[INSERT_PICTURE__HERE of NTP Server Hierarchy]]

The time is considered unsynchronized beyond Stratum16 and such an NTP server is not reliable enough to synchronize time.

NTP Timestamp format

NTP uses Coordinated Universal Time (UTC) to represent time.

NTP timestamp is a number that represents NTP the number of seconds elpased since January 01, 1900 (which is known as 0hour).

NTP Timestamp is a 64-bit integer stored in Big Endian.

[[INSERT_PICTURE__HERE]]

  1. The first two bytes represent the integer parts of the second.
  2. Last two bytes represent the fractional part of the second that allows NTP to be precise up to Picoseconds (101210^{-12} of a second).

How does NTP work

Before we jump into the exchange between the NTP server and client, we need to understand one fundamental assumption that NTP has.

NTP assumes that the time spent on the network for sending the request and receiving the response is the same.

Your first reaction is that it cannot be true. There are minor fluctuations in the network so it cannot always be the same. However, the idea is in a correctly configured network, on average, the request transfer time will be the same as the response transfer time.

With that assumption in mind, let’s look at the client-server exchange between a Node and an NTP server.

For this example, we will consider time in seconds to simplify our example.

Step 1: Node sends Request to NTP Server

  1. Before sending the request, the Node notes down the current clock time in seconds. Let’s say that the client sends the request at second 100. We will call this CstartC_{start}.

Cstart=100C_{start} = 100

  1. The client sends the request to the NTP server to get the updated time. It then waits for the response

Step 2: NTP Server Receives the Request

  1. NTP server receives the request and notes down the time when the request arrived. Let’s assume that the true time on the NTP server was 200 when the request arrived. We will call this SrecvS_{recv}
...
Access this course and 1400+ top-rated courses and projects.