当前位置:网站首页>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"
边栏推荐
- 利用Zabbix动态监控磁盘I/O
- How to mix embedded MCU, arm and DSP?
- Test classification in openstack
- Is BigDecimal safe to calculate the amount? Look at these five pits~~
- typeScript
- OPenGL 基本知识(根据自己理解整理)
- Solutions to the failure of installing electron
- Ripper of vulnhub
- MySQL union和union all区别
- 抓包整理外篇fiddler———— 会话栏与过滤器[二]
猜你喜欢

STL教程9-容器元素深拷贝和浅拷贝问题

Qt OpenGL 旋转、平移、缩放

Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements

Vulnhub's presidential
![抓包整理外篇fiddler———— 会话栏与过滤器[二]](/img/04/e9cc027d753e7049f273d866eefdce.png)
抓包整理外篇fiddler———— 会话栏与过滤器[二]

Kubernetes three dozen probes and probe mode

rxjs Observable filter Operator 的实现原理介绍

错排问题 (抽奖,发邮件)

836. 合并集合(DAY 63)并查集

vulnhub之Ripper
随机推荐
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
typeScript
同事写了一个责任链模式,bug无数...
During FTP login, the error "530 login incorrect.login failed" is reported
vulnhub之narak
Based on MCU, how to realize OTA differential upgrade with zero code and no development?
rxjs Observable filter Operator 的实现原理介绍
Quantitative calculation research
Hongmeng fourth training
Groovy test class and JUnit test
OpenGL 绘制彩色的三角形
How should intermediate software designers prepare for the soft test
mysql使用update联表更新的方法
《剑指offer 03》数组中重复的数字
Simple factory and factory method mode
抓包整理外篇fiddler———— 会话栏与过滤器[二]
Test classification in openstack
vulnhub之pyexp
Vulnhub's presidential
Qt OpenGL 纹理贴图