IEEE1588精密网络同步协议修改
- 格式:doc
- 大小:283.50 KB
- 文档页数:5
IEEE_1588协议IEEE1588协议,也称为精密时钟同步协议,是一个用于实时系统中精确同步时钟的网络协议。
它的目标是提供亚微秒级的时钟同步精度,以满足高精度和高同步性能的实时应用需求。
IEEE1588协议主要用于工业自动化、电力系统、通信系统等领域,能够实现在分布式系统中所有时钟设备之间的同步。
IEEE 1588协议的原理是基于主从模式,其中一个设备是主时钟(Master Clock),该设备通过发送同步消息来广播时间信息,其他设备则是从时钟(Slave Clock),它们通过接收同步消息来校正自身的时钟。
主从模式可以实现网络中所有设备的时间同步,但是主时钟设备需要提供高精准的参考时钟。
IEEE1588协议的消息格式如下:1. Sync消息(同步消息):主时钟设备通过此消息广播时间信息,从时钟设备通过解析此消息来校正自身的时钟。
2. Delay_Req消息(延迟请求消息):从时钟设备通过向主时钟设备发送此消息来计算时钟矫正的延迟。
3. Follow_Up消息(跟随消息):主时钟设备通过此消息回复Delay_Req消息,包含时钟矫正延迟的信息。
4. Delay_Resp消息(延迟响应消息):主时钟设备通过此消息回复Delay_Req消息,包含时钟矫正延迟的信息。
5. PDelay_Req消息(精确延迟请求消息):用于测量主从时钟之间的延迟。
6. PDelay_Resp消息(精确延迟响应消息):用于回复PDelay_Req消息,包含主从时钟之间的延迟信息。
7. Announce消息(通告消息):用于通知网络中的设备主时钟的更改。
IEEE 1588协议的核心算法是时钟同步算法,该算法通过计算往返时延(Round-Trip Delay)来实现时钟同步。
往返时延包括主时钟设备发送Sync消息到从时钟设备接收到Follow_Up消息的时间,以及从时钟设备收到Delay_Resp消息到主时钟设备接收到的时间。
IEEE 1588精确时间协议在智能变电站中应用的关键技术【摘要】IEEE 1588精确时间同步协议(PTP)解决了通用以太网延迟时间和同步能力差的瓶颈,在自动化、通信等工业领域具有重要意义,本文介绍了IEEE 1588标准在智能变电站建设中应用的关键技术,包括PTP时钟同步模型以及同步过程,分析了PTP网络结构中的设备类型以及主从时钟的偏移和网络延时的修正,最后分析了PTP时钟设备冗余配置的必要性,给出了时钟设备冗余配置的方法。
【关键词】IEEE 1588 PTP 智能变电站时钟同步目前,在变电站自动化系统中广泛应用的对时方式主要有GPS同步脉冲对时,NTP(Network Time Protocol)网络时间协议,SNTP(Simple Network Time Protocol)简单网络时间协议对时等对时方式。
随着数字化变电站的发展使得站内二次硬接线逐渐被串行通信线所取代,GPS对时技术已不适用于新兴的数字化智能变电站网络系统,而NTP/SNTP时间同步协议的时间同步精度仅能到到ms 级,不能满足具有高精度和稳定性要求的电力自动化设备的需求,因此最终提出了IEEE 1588标准,它定义了一种用于分布式测量和控制系统的精密时间协议(Precision Time Protocol,PTP),其网络对时精度可达亚μs级,满足电力系统自动化设备对时间精度的要求,并且所占用网络和硬件资源较少,因此IEEE 1588网络对时方式是应用于智能变电站的理想对时方式[3]。
1 PTP时钟同步模型PTP系统是分布式网络系统,由PTP设备和非PTP设备组成。
下图1为一个典型的PTP分布式系统。
其中,OC(Ordinary Clock)为普通时钟,普通时钟可能是一个系统的最高级主时钟(Grandmaster Clock,GC),也可能是主、从时钟体系中的从时钟(Slave)。
BC(Boundary Clock)为边界时钟,PTP设备通过网络彼此通信,PTP协议在一个叫做域的逻辑范围内运行。
IEEE1588的高精度时间同步算法的分析与实现IEEE1588,也被称为精确时间协议(PTP),是一种用于网络中实现高精度时间同步的协议。
它在各种工业应用和通信系统中被广泛采用,因为它可以提供微秒级甚至亚微秒级的精度,满足了许多应用的实时性要求。
首先,IEEE 1588协议需要在网络中选择一个主时钟(Master Clock),作为时间同步的源头。
主时钟拥有最高的时间精度,并将其时间信息通过数据包广播给其他时钟节点。
其他节点被称为从时钟(Slave Clock),它们通过接收到的时间数据来调整自身的时钟,并与主时钟保持同步。
在主时钟启动时,它会周期性地发送特殊的数据包,称为同步事件(Sync Event)。
这些数据包包含了主时钟的当前时间戳,从时钟接收到这些数据包后,会记录接收时间戳。
当从时钟收到一定数量的同步事件后,它会计算出与主时钟的相对时间差,并根据这个时间差来调整自身的时钟。
为了确保时间同步的准确性,IEEE 1588采用了两个重要的概念,即时钟同步和时间戳校准。
时钟同步通过周期性的同步事件来实现,从而减小网络延迟带来的时间误差。
而时间戳校准则通过周期性地发送延迟请求(Delay Request)和延迟响应(Delay Response)数据包来估计网络延迟,并相应地调整时间戳。
在实际的实现中,IEEE1588通常使用硬件支持或软件实现的方式。
硬件支持一般通过专用的电路芯片或FPGA来实现,它们能够提供更高的时间精度和更低的延迟。
而软件实现则是在通用的计算机上运行,通过操作系统和网络协议栈来实现时间同步功能。
在软件实现中,IEEE1588通常依赖于操作系统的时钟服务和网络协议栈。
操作系统的时钟服务提供了计算机系统的时间信息,并提供了时间戳的功能。
网络协议栈则负责封装和发送数据包,并处理收到的数据包以提取时间戳信息。
在实现中,需要考虑以下几个关键问题:1.时间同步精度:在实现中,需要根据具体应用的要求选择合适的时钟源和自适应算法,以达到所需的精度。
• 35•随着网络控制技术水平的不断提升,分布式控制系统也提出对时钟同步精度的更高标准,本文以IEEE1588精密时钟同步协议为例,对该高精度时钟的同步机制与校正原理阐述说明,并对IEEE1588协议的BMC(最佳主时钟)、LCS(本地时钟同步)两大核心算法进行分析,并以技术开发角度提出了IEEE1588精密时钟同步协议,应用于数字化通信机房的应用方案,通过系统测试发现了数字化通信机房内IEEE1588的高精度时间同步实现可行性。
IEEE1588作为一种精密时钟同步协议标准,主要应用于网络测量及控制系统中,作为新一代测控纵向LXI标准关键组成,为了可以更好的满足工业控制、仪器测量相关领域中微秒级标准的时间同步需求,IEEE1588标准自提出得以广泛应用。
IEEE1588标准代称网络测量和控制系统的精密时钟同步协议标准,该标准原理就是经同步信号周期性,能够校正网络内的全部节点时钟达到同步,并基于以太网分布式系统,精准同步亚纳秒时钟。
IEEE1588标准较现阶段的GPS、NTP/SNTP达到配置简单优化、高精度且快速收敛,以及较小资源消耗与网络带宽特点。
对于时钟同步精度方面也要求更加严格,譬如运用于电力自动化系统、工业以太网、移动通信网等领域,引发人们的广泛关注。
1 IEEE1588时钟同步协议机制1.1 PTP时钟状态机PTP时钟同步系统作为包括主时钟、从时钟这样两部分之间构成主从关系的网络层次结构,以单个或多个PTP子域共同组成,并且每一个子域内都含有按个或多个彼此通信时钟。
在网络内每一个PTP时钟,都极有可能存在两种不同状态,具体状态主要取决于BMC算法,在主时钟状态下设备为精确时钟,能够与从时钟的时间同步,但是一个主时钟只能存在1个通信子域内。
对于PTP网络内每一个时钟设备,经周期性交换带有时间信息同步报文,能够计算主时钟和从时钟之间存在的偏差与网络延时,对偏差进行纠正,对延时进行补偿处理,能够做到主时钟和从时钟之间同步亚纳秒级。
IEEE1588v2高精度时钟同步协议的总体设计与实现王冠;肖萍萍【摘要】With the development of network technology, the gradually networked audio transmission set higher demands on asynchronous ethemet In provied high precision time to guaranty the real-time of transmission of audio data. Fortunately, IEEE 1588 is precisely designed to solve this problem. This article systematically describes the principle of IEEE1588 (version 2), and presents the general design of IEEE1588v2 in the angle of software implementation.%随着网络技术的发展,音频传输逐渐网络化,为保证音频数据传输的实时性,对异步的以太网提出了高精度的时间同步要求.而IEEE1588标准定义的PTP(Precision Time Protocol)协议正是为实现高精度时钟同步而制定的,本文系统地介绍了IEEE1588v2(第二版本的PTP协议)的原理,并从软件实现的角度给出了IEEEI588v2的总体设计.【期刊名称】《价值工程》【年(卷),期】2012(031)015【总页数】2页(P198-199)【关键词】音频传输网络;时钟同步;IEEE1588v2;PTP;精确时间协议【作者】王冠;肖萍萍【作者单位】武汉邮电科学研究院烽火网络有限公司,武汉430074;武汉邮电科学研究院烽火网络有限公司,武汉430074【正文语种】中文【中图分类】TN919.20 引言目前,基于以太网的数字音频传输技术已得到广泛应用,而以太网生来就是非确定性的网络,很难满足音频数据在传输过程中的同步和实时性要求。
IEEE1588协议IEEE 1588协议是一种用于时钟同步的网络通信协议,其全称为"Precision Clock Synchronization Protocol for Networked Measurement and Control Systems"。
该协议是由IEEE所制定的,旨在解决分布式系统中设备时钟同步问题。
在分布式系统中,设备之间的时钟同步是至关重要的。
准确的时钟同步能够确保系统中的各个设备在不同节点上以一致的时间进行操作,从而实现更可靠的协调和协同工作。
此外,在一些需要严格时间同步的应用领域,如工业自动化、电力系统等,时钟同步则是成功实现系统任务的基础。
传统的时钟同步方法中,基于GPS(Global Positioning System)的时间同步方案是一种常见的解决方法。
然而,GPS无法完全适用于所有场景,尤其是对于移动设备、室内场景等。
IEEE 1588协议的出现,则为这类应用场景的时钟同步问题提供了有效的解决方法。
IEEE 1588协议基于主从(Slave)的建模方式,其中主时钟(Master Clock)负责向从时钟(Slave Clock)广播时钟信号。
具体而言,协议通过周期性发送时间戳消息来实现主从时钟之间的同步。
在主时钟发送时间戳消息时,从时钟会接收该消息,并通过与其内置的本地时钟进行比较,进而进行时钟校正。
这样,从时钟就可以根据主时钟的参考进行同步,从而实现各个设备间的时钟同步。
IEEE 1588协议定义了两个核心消息:Sync(同步)和Delay_Req(延迟请求)。
Sync消息用于主时钟广播当前的时间信息,而Delay_Req消息用于从时钟向主时钟请求延迟信息。
协议还提供了一些附加消息,如Follow_Up(回应)、Delay_Resp(延迟回应)和Pdelay_Req(对称延迟请求),用于进一步优化时钟同步过程。
除了时钟同步外,IEEE 1588协议还提供了一种高级特性,即时钟精度统计(Clock Accuracy Estimation)。
1588协议1588协议是一种用于精确时间同步的网络协议,广泛应用于工业自动化领域,以及其他需要对网络设备进行时间同步的应用场景。
该协议由IEEE(Institute of Electrical and Electronics Engineers)提出,并于2008年正式发布。
1588协议主要用于解决网络设备之间的时钟同步问题。
在许多实时应用场景中,如电力系统、工业控制等,设备之间的时钟同步至关重要。
而1588协议通过网络中的时间同步客户端和时间同步服务器之间的协作,使网络设备能够达到亚微秒级的时钟同步精度。
1588协议的基本工作原理是在网络中定义一个主时钟(Master Clock)和多个从时钟(Slave Clock),主时钟提供准确的时间信号,从时钟根据主时钟的时间信号进行同步。
主时钟和从时钟通过1588协议进行通信,主要包括消息的传输和同步算法。
1588协议的消息传输基于以太网,具体采用了一种称为“半透明时间戳”的技术。
该技术通过在以太网数据帧中添加时间戳信息,实现对数据帧的时间戳同步。
使用半透明时间戳技术,可以消除网络延迟对时钟同步精度的影响,提高同步性能。
1588协议的同步算法主要分为两个阶段,首先是粗同步(Coarse Synchronization),然后是精细同步(Fine Synchronization)。
粗同步阶段主要用于快速同步从时钟的相对时间,通过对主时钟发出的时间同步消息进行计算来实现。
在精细同步阶段,从时钟通过与主时钟的时间差进行反馈,逐步调整自己的时钟频率和相位,实现对主时钟信号的精确同步。
1588协议还支持多个从时钟同时同步的场景,可以通过对从时钟进行分级管理,组织多级时间同步网络。
每一级的从时钟都可以同步上一级的主时钟,实现全局的时间同步。
总之,1588协议是一种通过网络实现设备时钟同步的协议,具有高精度、高性能的特点。
在工业自动化领域,该协议被广泛应用于实时控制系统、电力系统等场景。
Moxa Computer Time-synchronization Settings for IEEE 1588 and Precision TimeProtocolVersion 1.0, June 2022/products© 2022 Moxa Inc. All rights reserved.Moxa Computer Time-synchronization Settingsfor IEEE 1588 and Precision Time ProtocolThe software described in this manual is furnished under a license agreement and may be used only in accordancewith the terms of that agreement.Copyright Notice© 2022 Moxa Inc. All rights reserved.TrademarksThe MOXA logo is a registered trademark of Moxa Inc.All other trademarks or registered marks in this manual belong to their respective manufacturers.Disclaimer•Information in this document is subject to change without notice and does not represent a commitment on the part of Moxa.•Moxa provides this document as is, without warranty of any kind, either expressed or implied, including, but not limited to, its particular purpose. Moxa reserves the right to make improvements and/orchanges to this manual, or to the products and/or the programs described in this manual, at any time.•Information provided in this manual is intended to be accurate and reliable. However, Moxa assumes no responsibility for its use, or for any infringements on the rights of third parties that may result from itsuse.•This product might include unintentional technical or typographical errors. Changes are periodically made to the information herein to correct such errors, and these changes are incorporated into neweditions of the publication.Technical Support Contact Information/supportTable of Contents1.Overview (4)2.Windows PTP Client Settings (5)Hardware and Software Requirements (5)Setting Up the Windows PTP Slave (Client) (6)Configuring the PTP Grandmaster Message Settings (8)Checking the PTP Time Sync Function (9)3.Linux PTP Settings (10)Prerequisites (10)A Simple Topology (10)Debian linuxptp Package (11)OC Mode (12)BC Mode (12)phc2sys (14)One Pulse Per Second (1PPS) (14)Additional References (17)1.Overview This guide describes the IEEE 1588 and Precision Time Protocol (PTP) settings in Windows and is applicable to the following Moxa products:DA-820C YesDA-682C Coming soonDA-681C Coming soonDA-720 Coming soon2.Windows PTP Client SettingsThis chapter describes how to configure the PTP Client on a Windows 10 system. Hardware and Software RequirementsThe hardware and software requirements are listed here:•Hardware: Network interface cards (NICs) with IEEE 1588 support (e.g., Intel® I210)•Software: Windows OS kernel with PTP hardware timestamp support (e.g., Windows 10 Pro 20H2 or later); build 19042 or laterTo check the build number, run winver from the Windows start menu. Confirm that the build version is19042 or later.•Other: One Linux device as PTP Grandmaster and one or more Windows devices as PTP Slaves (Clients) Because Windows only supports the PTP slave (client) in OC mode, we will need another device withLinux OS to be the PTP Grandmaster to perform the time synchronization.Setting Up the Windows PTP Slave (Client) The Windows Time Service (w32tm) is a Windows service that keeps your computer clock accurate. We will be using the AutoSetupWindowsPTP.exe file to configure the w32tm service and apply the PTP function.NOTEContact a Moxa representative for the AutoSetupWindowsPTP.exe file to configure and run the PTPfunction on your computer.To set up the Windows PTP Slave (Client), do the following:1.Run cmd from the Windows start menu and then run the AutoSetupWindowsPTP.exe file.2.Enter the IP for the Linux PTP Grandmaster.3.Enter the IP address for the PTP Slave.4.Wait until the program sets up the configuration for the w32tm service for the PTP function.After the setup process is completed, the Windows Time service will start automatically.5.Restart the device to apply the configuration to the OS.Additional Information•If the program shows the error "This Windows version doesn't support HW PTP", the Windows version is too old to support HW PTP. Install a newer supported version on your device.•If the program shows the error "Invalid device!", the program cannot setup Windows PTP on the device.Note that only Moxa devices are supported.•PTP messages may use the User Datagram Protocol over Internet Protocol (UDP/IP) for transport. The AutoSetupWindowsPTP.exe program will automatically create the firewall rules to allow the PTPSlave to communicate with the time server.Configuring the PTP Grandmaster Message SettingsTo configure the PTP message settings for the Grandmaster and generate a PTP message based on thesettings, do the following:e the follow settings to configure a PTP massage on the Linux PTP Grandmaster device.Delay Mechanism E2ENetwork Transport UDP IPV4Time Stamping HardwareMulticast EnableptpTimescale 12.On the Linux PTP Grandmaster device, run the ptp4l command.ptp4l -E -4 -H -m -i enp2s03.After the ptp4l starts, type the following command to show the configuration settings.sudo pmc -u -b 0 'GET GRANDMASTER_SETTINGS_NP'4.To modify the setting when the ptp4l is running, run the following command:sudo pmc -u -b 0 \ "SET GRANDMASTER_SETTINGS_NP clockClass 248 clockAccuracy0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37 leap61 0 leap59 0currentUtcOffsetValid 0 ptpTimescale 1 timeTraceable 0 frequencyTraceable 0timeSource 0xa0"Checking the PTP Time Sync FunctionAfter the PTP Grandmaster settings are completed, the Windows time service will start automatically andcheck for the PTP message from the PTP Grandmaster.•Using WireShark to check the message information from the specific LAN.a.The PRP Master will generate a "Announce Msg + Sync Msg + Follow_Up Msg + Sync Msg +Follow_Up Msg" at each loop.b.The W32Time service will send a Delay_Req Msg to the PTP master and PTP master will respond witha Delay_Resp Msg for the time sync.•In the Windows Start menu, run cmd as an administrator and enter w32time.exe /query /status/verbose.I f the "Last Sync Error" shows "0 (The command completed successfully)", the time sync wassuccessful.3.Linux PTP Settings Prerequisites1.Install Debian 11.2.Install the linuxptp package.apt updateapt upgradeapt install ssh linuxptp ethtool build-essential3.Disable the systemd time sync daemon service to avoid unexpected operations.systemctl stop systemd-timesyncdsystemctl disable systemd-timesyncdA Simple TopologyDebian linuxptp PackageThe linuxptp is an implementation of the Precision Time Protocol (PTP) for Linux according to the IEEEstandard 1588. Features include:•Support for hardware and software time stamping via Linux•SO_TIMESTAMPING socket option•Support for the Linux PTP Hardware Clock (PHC) subsystem by using the clock_gettime family of calls, including the new clock_adjtimex system call•Implementation of Boundary Clock (BC) and Ordinary Clock (OC)•Transport over UDP/IPv4, UDP/IPv6, and raw Ethernet (Layer 2)•Support for IEEE 802.1AS-2011 in the role of an end stationAdditional information is available at: https:///bullseye/linuxptpPTP provides higher precision and faster synchronization than NTP even without hardware support. And,with hardware support, sub-microsecond accuracy can be expected. Whereas NTP is intended for WAN use.PTP is designed for LAN environments and makes use of UDP multicast.usage: ptp4l [options]Delay Mechanism-A Auto, starting with E2E-E E2E, delay request-response (default)-P P2P, peer delay mechanismNetwork Transport-2 IEEE 802.3-4 UDP IPV4 (default)-6 UDP IPV6Time Stamping-H HARDWARE (default)-S SOFTWARE-L LEGACY HWOther Options-f [file] read configuration from 'file'-i [dev] interface device to use, for example 'eth0'(may be specified multiple times)-p [dev] Clock device to use, default auto(ignored for SOFTWARE/LEGACY HW time stamping)-s slave only mode (overrides configuration file)-l [num] set the logging level to 'num'-m print messages to stdout-q do not print messages to the syslog-v prints the software version and exits-h prints this message and exitsOC ModeLayer 2Set as:•OC master (as a PTP Grandmaster) mode•Layer 2•P2P mode, peer delay mechanism# Assume interface device is 'enp4s0'ptp4l -m -2 -P -i enp4s0Set as:•OC slave mode•Layer 2•P2P mode, peer delay mechanism# Assume interface device is 'enp5s0'ptp4l -m -2 -P -s -i enp5s0# with log: ptp4l -m -2 -s -P -i enp5s0 2>&1 | tee $(date+%Y%m%d%H%M%S.log)Layer 4 (UDP IPV4)Set as:•OC master mode•Layer 4•P2P mode, peer delay mechanism# Assume interface device is 'enp4s0'ptp4l -m -4 -P -i enp4s0Set as:•OC slave mode•Layer 4•P2P mode, peer delay mechanism# Assume interface device is 'enp5s0'ptp4l -m -4 -P -s -i enp5s0# with log: ptp4l -m -4 -s -P -i enp5s0 2>&1 | tee $(date+%Y%m%d%H%M%S.log)BC Mode1.Set as BC mode.a.clock_typeSpecifies the PTP clock type. Valid values are "OC" for ordinary clock, "BC" for boundary clock,"P2P_TC" for peer-to-peer transparent clock, and "E2E_TC" for end-to-end transparent clock. Amulti-port ordinary clock will automatically be configured as a boundary clock. The default is "OC".b.boundary_clock_jbodWhen running as a boundary clock (that is, when more than one network interfaces areconfigured), ptp4l performs a sanity check to ensure that all the ports share the same hardwareclock device. This option allows ptp4l to work as a boundary clock using a bunch of devices thatare not synchronized to each other. For this mode, the collection of clocks must be synchronized byan external program, for example phc2sys(8) in automatic mode. The default is 0 (disabled).# For example, edit config file 'bc.cfg'# and assume 'enp12s0' and 'enp4s0' are connected network interface [global]sanity_freq_limit 0step_threshold 0.000002tx_timestamp_timeout 10logMinPdelayReqInterval 0logSyncInterval 0logAnnounceInterval 0announceReceiptTimeout 3syncReceiptTimeout 2twoStepFlag 1summary_interval 0clock_type BCpriority1 128priority2 127delay_mechanism P2P[enp12s0]boundary_clock_jbod 1network_transport UDPv4fault_reset_interval 0[enp4s0]boundary_clock_jbod 1network_transport UDPv4fault_reset_interval 0# run the ptp4l procedureptp4l -m -f bc.cfg# use phc2sys to sync sys clock for 10Hzphc2sys -a -m -r -R 102.Set as OC master (p2p).# edit 'oc_gm_p2p.cfg', assume 'enp5s0' as NIC[global]twoStepFlag 1priority1 127masterOnly 1delay_mechanism P2P[enp5s0]network_transport UDPv4# exec as OC masterptp4l -m -f oc_gm_p2p.cfg3.Set as OC slave.# edit 'oc_sl.cfg', assume 'enp4s0' as NIC[global]twoStepFlag 1slaveOnly 1delay_mechanism P2P[enp4s0]network_transport UDPv4# exec as OC slaveptp4l -m -s -f oc_sl.cfgphc2sysThe phc2sys program, included in the linuxptp package, synchronizes two or more clocks in the system.Typically, it is used to synchronize the system clock to a PTP hardware clock (PHC), which itself issynchronized by the ptp4l(8) program.phc2sys -a -m -r -R 10Additional information is available at: https:///bullseye/linuxptp/phc2sys.8.en.html One Pulse Per Second (1PPS)One Pulse Per Second (1PPS) is a time synchronization feature that allows the adapter to be able to send or receive 1 pulse/sec on a dedicated pin on the adapter card.Example Code for SetupIn this example we have two servers connected back-to-back with the 1PPS pin on the adapter. One server will generate the 1PPS signal (1PPS out), while the other server will receive the 1PPS signal (1PPS in).https:///torvalds/linux/master/tools/testing/selftests/ptp/testptp.cwegthttps:///torvalds/linux/master/tools/testing/selftests/ptp/testptp.cgcc -Wall -lrt testptp.c -o testptp./testptp -husage: testptp [options]-c query the ptp clock's capabilities-d name device to open-e val read 'val' external time stamp events-f val adjust the ptp clock frequency by 'val' ppb-g get the ptp clock time-h prints this message-i val index for event/trigger-k val measure the time offset between system and phc clockfor 'val' times (Maximum 25)-l list the current pin configuration-L pin,val configure pin index 'pin' with function 'val'the channel index is taken from the '-i' option'val' specifies the auxiliary function:0 - none1 - external time stamp2 - periodic output-p val enable output with a period of 'val' nanoseconds-H val set output phase to 'val' nanoseconds (requires -p)-w val set output pulse width to 'val' nanoseconds (requires -p)-P val enable or disable (val=1|0) the system clock PPS-s set the ptp clock time from the system time-S set the system time from the ptp clock time-t val shift the ptp clock time by 'val' seconds-T val set the ptp clock time to 'val' seconds-z test combinations of rising/falling external time stamp flagsConfigurationUse ethtool to check the Time Synchronization support on the relevant port# Assume HSR-PRP-I210 interlink interface is 'enp4s0'# To get 'PTP Hardware Clock' indexroot@ptp2:/home/moxa# ethtool -T enp4s0Time stamping parameters for enp4s0:Capabilities:hardware-transmitsoftware-transmithardware-receivesoftware-receivesoftware-system-clockhardware-raw-clockPTP Hardware Clock: 0Hardware Transmit Timestamp Modes:offonHardware Receive Filter Modes:noneall# Get index is '0', the corresponding ptp device node is '/dev/ptp0'# Query the ptp clock's capabilities.root@ptp2:/home/moxa# ./testptp -d /dev/ptp0 -ccapabilities:62499999 maximum frequency adjustment (ppb)0 programmable alarms2 external time stamp channels2 programmable periodic signals1 pulse per second4 programmable pins0 cross timestamping0 adjust_phase# Check the current pin configuration:# name: Pin name.# index: The Pin number.# func (function): The pin Configuration# 0 - none# 1 - 1PPS In# 2 - 1PPS Out (periodic output)# chan (channel) - Reserved field.root@ptp2:/home/moxa# ./testptp -d /dev/ptp0 -lname SDP0 index 0 func 2 chan 0name SDP1 index 1 func 0 chan 0name SDP2 index 2 func 0 chan 0name SDP3 index 3 func 0 chan 0Setting Up the 1PPS In Server# Assume PTP device node is '/dev/ptp0'# Setup function as '1' (1PPS In) with default channel 0root@ptp1:/home/moxa# ./testptp -d /dev/ptp0 -L 0,1# Check the func value was changed.root@ptp1:/home/moxa# ./testptp -d /dev/ptp0 -lname SDP0 index 0 func 1 chan 0name SDP1 index 1 func 0 chan 0name SDP2 index 2 func 0 chan 0name SDP3 index 3 func 0 chan 0# On the 1PPS in server# set the maximum number of events to be set/handled by the application.root@ptp1:/home/moxa#./testptp -d /dev/ptp0 -e 1000Some applications may need to read the timestamp from a file. To write the time stamps into a file, enable the pps_enable sysfs parameter in the 1 PPS in server.root@ptp1:/home/moxa# echo 1 > /sys/class/ptp/ptp0/pps_enableroot@ptp1:/home/moxa# watch -n 1 'cat /sys/class/pps/pps0/assert' No changes are needed on the 1 PPS out server.To disable it again and get the timestamps to the terminal, run the following commands:root@ptp1:/home/moxa# echo 0 > /sys/class/ptp/ptp0/pps_enableroot@ptp1:/home/moxa#./testptp -d /dev/ptp0 -e 1000Setting Up the 1PPS Out Server# Assume PTP device node is '/dev/ptp0'# Setup function as '2' (1PPS Out) with default channel 0root@ptp2:/home/moxa# ./testptp -d /dev/ptp0 -L 0,2# Check the func value was changed.root@ptp2:/home/moxa# ./testptp -d /dev/ptp0 -lname SDP0 index 0 func 2 chan 0name SDP1 index 1 func 0 chan 0name SDP2 index 2 func 0 chan 0name SDP3 index 3 func 0 chan 0# On the 1PPS out server, enabled 1PPS using -p 1000000000 (in nsec)root@ptp2:/home/moxa# ./testptp -d /dev/ptp0 -p 1000000000Example for Latching Signal SDP0Additional References•https:///doc/html/latest/driver-api/ptp.html•https:///s/article/How-To-Test-1PPS-on-Mellanox-Adapters#jive_content_id_1PPS_out•https:///zh-tw/sled/15-SP2/html/SLED-all/cha-tuning-ptp.html•REN_Linux-Kernel-Supp-IEEE-1588-HW-TimeS_WHP_20210129.pdf。
IEEE1588精密网络同步协议(PTP)-v2.0协议浅析/s/blog_4b0cdab70100k4fv.html1 引言以太网技术由于其开放性好、价格低廉和使用方便等特点,已经广泛应用于电信级别的网络中,以太网的数据传输速度也从早期的10M提高到100M,GE,10GE。
40GE,100GE正式产品也于2009年推出。
以太网技术是“即插即用”的,也就是将以太网终端接到IP网络上就可以随时使用其提供的业务。
但是,只有“同步的”的IP网络才是一个真正的电信级网络,才能够为IP网络传送各种实时业务与数据业务的多重播放业务提供保障。
目前,电信级网络对时间同步要求十分严格,对于一个全国范围的IP网络来说,骨干网络时延一般要求控制在50ms之内,现行的互联网网络时间协议NTP(Network Time Protocol),简单网络时间协议SNTP(Simple Network Time Protocol)等不能达到所要求的同步精度或收敛速度。
基于以太网的时分复用通道仿真技术(TDM over Ethernet)作为一种过渡技术,具有一定的以太网时钟同步概念,可以部分解决现有终端设备用于以太网的无缝连接问题。
IEEE 1588标准则特别适合于以太网,可以在一个地域分散的IP网络中实现微秒级高精度的时钟同步。
本文重点介绍IEEE 1588技术及其测试实现。
2 IEEE 1588PTP介绍IEEE 1588PTP协议借鉴了NTP技术,具有容易配置·、快速收敛以及对网络带宽和资源消耗少等特点。
IEEE1588标准的全称是“网络测量和控制系统的精密时钟同步协议标准(IEEE 1588 Precision Clock Synchronization Protocol)”,简称PTP(Precision Timing Protocol),它的主要原理是通过一个同步信号周期性的对网络中所有节点的时钟进行校正同步,可以使基于以太网的分布式系统达到精确同步,IEEE 1588PTP时钟同步技术也可以应用于任何组播网络中。
IEEE 1588将整个网络内的时钟分为两种,即普通时钟(Ordinary Clock,OC)和边界时钟(Boundary Clock,BC),只有一个PTP通信端口的时钟是普通时钟,有一个以上PTP通信端口的时钟是边界时钟,每个PTP端口提供独立的PTP通信。
其中,边界时钟通常用在确定性较差的网络设备(如交换机和路由器)上。
从通信关系上又可把时钟分为主时钟和从时钟,理论上任何时钟都能实现主时钟和从时钟的功能,但一个PTP通信子网内只能有一个主时钟。
整个系统中的最优时钟为最高级时钟GMC(Grandmaster Clock),有着最好的稳定性、精确性、确定性等。
根据各节点上时钟的精度和级别以及UTC(通用协调时间)的可追溯性等特性,由最佳主时钟算法(Best Master Clock)来自动选择各子网内的主时钟;在只有一个子网的系统中,主时钟就是最高级时钟GMC。
每个系统只有一个GMC,且每个子网内只有一个主时钟,从时钟与主时钟保持同步。
图1所示的是一个典型的主时钟、从时钟关系示意。
图1 主时钟、从时钟关系示意图同步的基本原理包括时间发出和接收时间信息的记录,并且对每一条信息增加一个“时间戳”。
有了时间记录,接收端就可以计算出自己在网络中的时钟误差和延时。
为了管理这些信息,PTP协议定义了4种多点传送的报文类型和管理报文,包括同步报文(Sync),跟随报文(Follow_up),延迟请求报文(Delay_Req),延迟应答报文(Delay_Resp)。
这些报文的交互顺序如图2所示。
收到的信息回应是与时钟当前的状态有关的。
同步报文是从主时钟周期性发出的(一般为每两秒一次),它包含了主时钟算法所需的时钟属性。
总的来说同步报文包含了一个时间戳,精确地描述了数据包发出的预计时间。
由于同步报文包含的是预计的发出时间而不是真实的发出时间,所以Sync报文的真实发出时间被测量后在随后的Follow_Up报文中发出。
Sync报文的接收方记录下真实的接收时间。
使用Follow_Up报文中的真实发出时间和接收方的真实接收时间,可以计算出从属时钟与主时钟之间的时差,并据此更正从属时钟的时间。
但是此时计算出的时差包含了网络传输造成的延时,所以使用Delay_Req报文来定义网络的传输延时。
Delay_Req报文在Sync报文收到后由从属时钟发出。
与Sync报文一样,发送方记录准确的发送时间,接收方记录准确的接收时间。
准确的接收时间包含在Delay_Resp报文中,从而计算出网络延时和时钟误差。
同步的精确度与时间戳和时间信息紧密相关。
纯软件的方案可以达到毫秒的精度,软硬件结合的方案可以达到微图2 PTP报文与交换顺序秒的精度。
PTP协议基于同步数据包被传播和接收时的最精确的匹配时间,每个从时钟通过与主时钟交换同步报文而与主时钟达到同步。
这个同步过程分为漂移测量阶段和偏移测量与延迟测量阶段。
第一阶段修正主时钟与从时钟之间的时间偏差,称为漂移测量。
如图3所示,在修正漂移量的过程中,主时钟按照定义的间隔时间(缺省是2s)周期性地向相应的从时钟发出惟一的同步报文。
这个同步报文包括该报文离开主时钟的时间估计值。
主时钟测量传递的准确时间T0 K,从时钟测量接收的准确时间T1 K。
之后主时钟发出第二条报文——跟随报文(Follow_up Message),此报文与同步报文相关联,且包含同步报文放到PTP通信路径上的更为精确的估计值。
这样,对传递和接收的测量与标准时间戳的传播可以分离开来。
从时钟根据同步报文和跟随报文中的信息来计算偏移量,然后按照这个偏移量来修正从时钟的时间,如果在传输路径中没有延迟,那么两个时钟就会同步。
图3 PTP时钟漂移测量计算为了提高修正精度,可以把主时钟到从时钟的报文传输延迟等待时间考虑进来,即延迟测量,这是同步过程的第二个阶段(见图4)。
图4 PTP时钟延迟和偏移计算从时钟向主时钟发出一个“延迟请求”数据报文,在这个过程中决定该报文传递准确时间T2。
主时钟对接收数据包打上一个时间戳,然后在“延迟响应”数据包中把接收时间戳B送回到从时钟。
根据传递时间戳B和主时钟提供的接收时间戳D,从时钟计算与主时钟之间的延迟时间。
与偏移测量不同,延迟测量是不规则进行的,其测量间隔时间(缺省值是4~60s之间的随机值)比偏移值测量间隔时间要大。
这样使得网络尤其是设备终端的负荷不会太大。
采用这种同步过程,可以消减PTP协议栈中的时间波动和主从时钟间的等待时间。
从图4右边可以看到延迟时间D 和偏移时间数值O的计算方法。
IEEE 1588目前的版本是v2.2,主要应用于相对本地化、网络化的系统,内部组件相对稳定,其优点是标准非常具有代表性,并且是开放式的。
由于它的开放性,特别适合于以太网的网络环境。
与其他常用于Ethernet TCP/IP网络的同步协议如SNTP或NTP相比,主要区别是PTP是针对更稳定和更安全的网络环境设计的,所以更为简单,占用的网络和计算资源也更少。
NTP协议是针对于广泛分散在互联网上的各个独立系统的时间同步协议。
GPS(基于卫星的全球定位系统)也是针对于分散广泛且各自独立的系统。
PTP 定义的网络结构可以使自身达到很高的精度,与SNTP和NTP相反,时间戳更容易在硬件上实现,并且不局限于应用层,这使得PTP可以达到微秒以内的精度。
此外,PTP模块化的设计也使它很容易适应低端设备。
IEEE1588标准所定义的精确网络同步协议实现了网络中的高度同步,使得在分配控制工作时无需再进行专门的同步通信,从而达到了通信时间模式与应用程序执行时间模式分开的效果。
由于高精度的同步工作,使以太网技术所固有的数据传输时间波动降低到可以接受的,不影响控制精度的范围。
3 IXIA IEEE 1588PTP测试方案美国IXIA公司目前提供最为完整的城域以太网功能、性能、一致性测试解决方案,并且最先在2~7层统一IP测试平台实现了IEEE 1588PTP时钟同步技术方案。
关于IXIA 的城域以太网测试解决方案在以前有过详细介绍,在这里对相应的技术点和对应IXIA应用程序做一总结(见表1)。
表1 IXIA城域以太网测试方案及对应程序图5是典型的IEEE 1588PTP测试场景,IXIA测试端口可以仿真普通时钟并处于主模式,被测设备,比如以太网交换机处于边界时钟状态,验证其对各种时钟报文的处理能力与实现;另一种测试情况是IXIA端口仿真边界时钟并处于从属模式,这时候被测设备处于主模式,验证被测设备在主时钟模式下的处理机制。
IXIA端口都有PTP协议栈,可以对PTP时钟信息做灵活的配置。
图5 IEEE 1588典型测试场景IXIA IEEE 1588PTP测试方案所支持的特性包括:支持目前最为流行的IEEE 1588 2.2版本;支持两步时钟配置;一个物理端口可以同时产生PTP流量和非PTP流量;一个物理端口一个时钟信号设置,时钟可以手动设置为主模式或者从模式;可以以柱状图显示从时钟对应于主时钟的偏移量;IXIA IxExplorer内置的实时协议分析解码软件可以对PTP报文直接进行编辑或者解码。
在测试过程中可以实时显示各种详细的PTP统计信息,统计信息见表2。
表2 IXIA IEEE 1588PTP测试统计信息IXIA IEEE 1588PTP方案还可以实现负面测试(Negative Testing),可以根据需要设定发送Sync报文中Follow-up报文的比例,观察丢弃掉的Follow-up报文对被测设备的影响;在Follow-up报文中增加错误数据包,验证被测设备的处理与检测能力;发送包括抖动与偏移的带有时间戳的数据包迫使Sync报文失败,检验被测设备的处理机制。
图6所示为PTP时钟配制界面。
图6 PTP时钟配置界面4 结束语根据最新的信息公告,IXIA 被eWeek授予年度十大产品奖之一,被Frost & Sullivan授予2008全球三重播放综合测试和监测设备的年度市场领先奖,被Test & Measurement World授予三个最佳测试奖,以及被Internet Telephony授予年度产品奖,被如此众多令人尊敬有技术影响力组织机构的认可,进一步证明了IXIA正在推动测试、测量和业务认证市场的进步和战略创新,在城域以太网网技术方面,IXIA同样保持领先的地位,推出了业界第一个100G高速以太网测试加速系统,第一个在统一2~7层IP测试平台上推出了IEEE 1588PTP 精密时钟同步协议测试技术,IXIA这些技术创新和技术的领导地位,都为全面的IP 测试提供了可靠保证。