NTP network calibration protocol

Source: Internet
Author: User

Network Time Protocol (NTP) is a TCP/IP protocol used to publish accurate time throughout the network. Its transmission is based on UDP. The basic principles of the NTP protocol are as follows:

The following figure shows the basic working principle of the NTP protocol. The GWA and gwb routers are connected through the network and all of them have their own system clock. To achieve automatic synchronization of their respective system clock, make the following assumptions:
1. Before the system clock synchronization between GWA and gwb, The GWA clock is set to 10:00:00 AM, and the gwb clock is set to 11:00:00 AM.
2 gwb is used as the NTP time server, that is, GWA will synchronize its clock with the gwb clock.
3. The time required for one-way transmission of data packets between GWA and gwb is 1 second.
The system clock synchronization process is as follows:
1 GWA sends an NTP message package to gwb, which carries the timestamp when it leaves Gwa. The timestamp is 10:00:00 am (T1 ).
2 when the NTP message package arrives at gwb, The gwb is added with its own timestamp, Which is 11:00:01 am (T2 ).
3 when the NTP message package leaves gwb, gwb is added with its own timestamp, Which is 11:00:02 am (T3 ).
4 when GWA receives the Response Message package, a new timestamp is added, which is 10:00:03 am (T4 ).
So far, GWA has enough information to calculate two important parameters:
5 NTP message back and forth a cycle of latency delay = (t4-t1)-(t3-t2 ).
6 GWA relative time difference offset of gwb = (t2-t1) + (t3-t4)/2.
In this way, GWA can set its own clock based on the information to synchronize it with the gwb clock. This is just a rough description of the working principle of NTP. In rfc1305, NTP uses complex algorithms to ensure the accuracy of clock synchronization.
According to the network structure and the location of the router in the network, NTP has six working modes, the first two modes are also called unicast modes.
1. Set the remote server as the local time server. At this time, the local router works in client mode. In this mode, the local client can only be synchronized to the remote server, but the remote server will not be synchronized to the local client;
2. Set the remote server as the Peer of the local router and run locally in the active mode (active mode. In this configuration, the local server can be synchronized to the remote server (passive mode), and the remote server can also be synchronized to the local server. If both parties have a reference clock, a small number of layers shall prevail;
3. Set an interface of the local router to send an NTP broadcast message package. At this time, the local router works in Broadcast Server mode;
4. Set an interface of the local router to receive the broadcast information package of NTP. At this time, the local router works in broadcast customer mode;
5. Set an interface of the local router to send the NTP multicast message package. The local router runs in multicast server mode;
6. Set an interface of the local router to receive the NTP multicast message package. The local router runs in the multicast group mode.

 

Network Time Protocol (NTP) is a protocol used to synchronize computer time. It can synchronize computers with their servers or clock sources (such as quartzels and GPS, it provides high-precision time correction (the time difference between the LAN and the standard is less than 1 ms, the Wan is dozens of milliseconds), and can be used to prevent protocol attacks through encrypted validation.

NTP provides accurate time. First, an accurate time source is required. This time must be the International Standard Time UTC. NTP obtains UTC time from atomic clocks, astronomical observatory, and satellites, or from the Internet. In this way, an accurate and reliable time source is available. The time is based on the NTP server level. All servers are classified into different stratun (layers) based on the distance from the external UTC source. Stratum-1 is on the top layer, with external UTC access, while stratum-2 gets time from stratum-1, stratum-3 gets time from stratum-2, and so on, however, the total number of stratum layers is limited to less than 15. All these servers form a tiered architecture logically and
The time server of stratum-1 is the basis of the entire system.

When implementing network protocols, the most important thing is to understand the protocol data format. The NTP packet consists of 48 bytes, including 16 NTP headers and 32 timestamps. The Protocol format is 10.9.

 

 

 

Figure 10.9 NTP protocol data format

The meaning of the protocol field is as follows.

Li: Jump indicator, warning the force-Approaching second (second) inserted at the final moment of the last day of the month ).

Vn: Version number.

Mode:Working Mode. This field includes the following values: 0-reserved; 1-symmetric behavior; 3-client; 4-server; 5-broadcast; 6-ntp control information. The NTP protocol has three working modes: Master/Passive symmetric mode, customer/Server mode, and broadcast mode. In the active/passive symmetric mode, there is a one-to-one connection. Both parties can synchronize with the other party or be synchronized by the other party. The first party that requests to establish a connection works in the active mode, the other party works in the passive mode. The customer/Server mode is basically the same as the master/Passive mode. The only difference is that the customer can be synchronized by the server, but the server cannot be synchronized by the customer; in broadcast mode, there is a one-to-many connection, regardless of whether the server works
In which mode, the time information is automatically sent, and the customer adjusts the time according to the information.

Stratum: Overall identification of the local clock level.

Poll: The maximum interval between consecutive messages.

Precision: A signed integer indicates the accuracy of the local clock.

Root Delay: Indicates the total latency of a reciprocating request to the primary reference source, which is 15 ~ The number of fixed points in the 16-digit decimal part.

Root Dispersion: Indicates the standard error that arrives at the main reference source at a time. It has 15 ~ The unsigned decimal point of the 16-digit decimal part.

Reference identifier: Identifies special reference sources.

Originate Timestamp: This is the time to request the client to be detached from the server, In a 64-bit time-scale format.

Receive Timestamp: This is the time when the request arrives at the client from the server, In the 64-bit time scale format.

Transmit Timestamp: This is the time for the client to reply to the detached server, In a 64-bit time scale format.

Authenticator (optional): When the NTP Authentication mode is implemented, the primary identifier and information digital domain include the defined information Authentication Code (MAC) information.

Since the NTP protocol involves a lot of time-related operations, in order to simplify the implementation process, in this experiment, only the network communication module of the NTP protocol client is required, that is, the NTP protocol field is constructed for sending and receiving, and time-related operations are not processed at the end. As a reference model of OSI, the NTP protocol is suitable for data transmission over UDP. The dedicated port number is 123. In this experiment, the National Time Service Center Server (IP Address: 202.72.145.44) is used as the NTP (Network Time) server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.