当前位置:网站首页>AOSP ~ NTP (Network Time Protocol)
AOSP ~ NTP (Network Time Protocol)
2022-07-03 11:56:00 【Nanke is cute】
Network time protocol NTP(Network Time Protocol) yes TCP/IP An application layer protocol in the protocol family , It is used to synchronize the clock between the client and the server , Provide high-precision time correction .NTP Server from authoritative clock source ( For example, atomic clock 、GPS) Receive precise coordinated universal time UTC, The client requests and receives time from the server .
NTP be based on UDP Message transmission , The use of UDP The port number is 123.
Why is clock synchronization important ?
For many reasons , Accurate time is crucial to the network , such as :
- Network management : When analyzing log information collected from different network devices , It needs to be based on time . If the system time on different devices is inconsistent , It will bring obstacles to fault location due to problems such as sequence .
- Billing system : Billing business is particularly time sensitive , The time of all equipment is required to be consistent , Otherwise, the billing will be inaccurate , Cause users to question 、 Complaints, etc .
- Collaborative processing : Multiple systems work together to deal with the same complex event , In order to ensure the correct execution sequence , Multiple systems must refer to the same clock .
- system time : Some applications or services need accurate time to mark user login 、 Transaction and other operation information , Ensure traceability records .
- Therefore, a unified standard time is of great significance for the network .
NTP It is a protocol used to synchronize the clocks of all hosts in the network , He synchronizes the clock of the host to coordinated universal time UTC, Its accuracy is in LAN Reachable within the network 1 In milliseconds , stay WAN It can reach tens of milliseconds on the network .
NTP Development history of the agreement
NTP It's the United States Delaware university David L .Mills Designed by Professor , It is one of the earliest standards for clock synchronization in the network .NTP From time agreement and ICMP Timestamp message evolved ,NTP The version evolution of is as follows .
NTP Clock hierarchy
NTP Allow clients to request and receive time from the server , And the server starts from the authoritative clock source ( For example, atomic clock 、GPS) Receive precise coordinated universal time UTC.
NTP Organize the model structure hierarchically , Each layer in the hierarchy is called Stratum. Usually, clock synchronization will be obtained from the authoritative clock NTP The number of layers of the server is set to Stratum 1, And use it as the main time server , Provide clock synchronization for other devices in the network . and Stratum 2 From Stratum 1 Acquisition time ,Stratum 3 from Stratum 2 Acquisition time , And so on . The value range of clock layers is 1~16, The smaller the value , The higher the accuracy of the clock . The number of layers is 1~15 Your clock is in sync ; The number of layers is 16 The clock of is considered to be unsynchronized , Can't use .
NTP Synchronization principle
NTP The most typical way of timing is Client/Server The way , As shown in the figure below .
- The client first sends a message to the server NTP Request message , It contains the timestamp of the message leaving the client t1;
- NTP The request message arrives at NTP The server , here NTP The time of the server is t2. When the server receives the message ,NTP After server processing , On t3 Always send out NTP Reply message . The reply message carries the message to leave NTP Time stamp at client time t1、 arrive NTP Time stamp of server t2、 Leave NTP Time stamp of server t3;
- When the client receives the response message , Record the timestamp returned by the message t4.
- The client uses the above 4 One timestamp parameter can calculate 2 Key parameters :
- NTP Round trip delay of message from client to server delay.
- The time difference between the client and the server offset.
According to the equations :
It can be solved that the time difference is :
NTP The client gets offset To adjust your clock , Realization and NTP Server clock synchronization .
AOSP
- Change the time zone
When compiling, for example device.mk Add the following... To the file To modify the default time zone .
PRODUCT_PROPERTY_OVERRIDES += \
persist.sys.timezone=Asia/Shanghai
- modify NTP Server address :
stay frameworks/base/core/res/res/values/config.xml In file find
<string translatable="false" name="config_ntpServer">ntp7.aliyun.com</string>
ADB
adb shell "settings put global ntp_server ntp1.aliyun.com"
边栏推荐
- OPenGL 基本知识(根据自己理解整理)
- R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- Duplicate numbers in the array of sword finger offer 03
- Differences between MySQL Union and union all
- 836. 合并集合(DAY 63)并查集
- uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
- Vulnhub narak
- The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
- 【mysql官方文档】死锁
- Hongmeng fourth training
猜你喜欢
随机推荐
MySQL uses the method of updating linked tables with update
Ripper of vulnhub
Qt OpenGL相机的使用
简单工厂和工厂方法模式
Vulnhub geminiinc V2
Go language to realize static server
优化接口性能
PHP导出word方法(一phpword)
typeScript
laravel 时区问题timezone
XML (DTD, XML parsing, XML modeling)
同事写了一个责任链模式,bug无数...
Solutions to the failure of installing electron
Hongmeng fourth training
vulnhub之cereal
DNS multi-point deployment IP anycast+bgp actual combat analysis
利用Zabbix动态监控磁盘I/O
During FTP login, the error "530 login incorrect.login failed" is reported
Colleagues wrote a responsibility chain model, with countless bugs
基于turtlebot3实现SLAM建图及自主导航仿真