2020年10月9日 星期五

Precision Time Protocol

精確時間協定 (Precision Time Protocol, PTP) 透過網路封包同步絕對時間、頻率、和相位,達到毫秒級精確度。

版本
  • IEEE 1588-2002 (PTPv1):未廣泛採用。
  • IEEE 1588-2008 (PTPv2):沒向前相容。有 profile 定義 PTP 運作參數和選項,已定義的 profile 有 telecommunications、electric power distribution 和 audiovisual。IEEE 802.1AS (gPTP) 是 adaptation PTP 和 Audio Video Bridging and Time-Sensitive Networking 使用。
  • IEEE 1588-2019 (PTPv2.1) 相容 2008 改善。

名詞

  • master 和 slave:
  • grandmaster:master 作為同步源頭
  • ordinary clock:單一網路界面設備,可以是 master 或 slave。
  • boundary clock (BC、邊界時鐘):多網路界面設備,其中一個作為 PTP slave,其它則為 master。
  • Transparent clock (TC、透明時鐘):多網路界面設備,如同一般 switch 或 router 轉送所有封包,但不作為 master 或 slave。有兩種:
    • end-to-end (端對端):額外累算 event 封包停留時間更新 correction 欄位。
    • peer-to-peer (點對點):只更新 Sync 和 Follow Up 的 correction 欄位,除了累算 event 封包停留時間,再減去 Link propagation delay。
封包

PTP Message

34-byte HeaderVariable-length BodyOptional Suffix
PTP Header
OffsetOctetsField說明
01transportSpecificmessageType
11ReservedversionPTP
22messageLength長度含 Header、Body、和 Suffix。
41domainNumber
51Reserved
62flags
88correlationField
164Reserved
2010sourcePortIdentity
302sequenceID
321controlField
331logMessageInterval
messageType
  • event:傳送和接收時紀錄精確的 timestamp,包括
    • Sync:Master 送 orignalTimestamp (T1),用在 ordinary 和邊界時鐘。
    • DelayReq:Slave 送 orignalTimestamp,用在 ordinary 和邊界時鐘。
    • PDelay Req:用在透明時鐘。
    • PDelay Resp:用在透明時鐘。
  • general:不需要紀錄 timestamp,但可能傳送 timestamp,包括
    • FollowUp:2-step 時,Master 送 orignalTimestamp,用在 ordinary 和邊界時鐘。
    • Delay Resp:Master 送 DelayReq 的 receiveTimestamp (T4) 及 requestingPortIdentify,用在 ordinary 和邊界時鐘。
    • PDelay Resp Follow Up:用在透明時鐘。
    • Announce:用在 Best Master Clock Algorithm 來建立 clock 階層和選擇 grandmaster。
    • Management:網管使用來 monitor, configure and maintain PTP 系統。
    • Signaling:clock 間非 time-critical 通訊。

sourcePortIndentity

Announce

Sync/DelayReq/FollowUp

DelayResp/PDelayReq/PDelayResp/PDelayRespFollowUp

  • UDP:Multicast address 224.0.1.129~224.0.1.132,UDP Port 319 for Event message,UDP Port 320 for general message
  • Ethernet
  • 使用 TAI Time:1970/1/1 午夜開始,48-bit Seconds 32-bit Nanoseconds => overflow in 8‘925‘512 years
  • 提供 UTC offset 和 Leap second 轉換 TAI 為 UTC。
Best Master Clock Algorithm (BMCA):決定 Port state 是 Master、Slave、或 Passive,和 Clock quality 最好的 node 送 «Announce» 訊息,自動建立 Master-Slave 階層:
  • 所有 node 聽 «Announce» 訊息,包含 Clock quality 資訊 (Class, Priorities and Qualities)。
  • 如果在時間內沒收到 «Announce» 訊息,自己變成 Master 並開始送 «Announce» 訊息。
  • 如果收到 «Announce» 訊息的 Clock quality 比自己好,停送 «Announce» 並變為 Slave。
  • 如果收到 «Announce» 訊息的 Clock quality 比自己差,持續在 Master 並繼續週期送 «Announce»。
Clock quality 的比較
  1. Priority1: 設定的 clock priority
  2. ClockClass: Clock 的 traceability
  3. ClockAccuracy: Clock 的 accuracy (跟網路 layer 有關?)
  4. OffsetScaledLogVariance: Clock 的 stability
  5. Priority2: 設定的 second order clock priority
  6. ClockIdentity: Clock 的 unique identifier
此外,node 在多個 port 收到 «Announce» 訊息時,需要決定一個 port
  1. StepsRemoved: over how many hops the frame came
  2. SenderPortIdentity: sender port 的 unique identifier
  3. ReceiverPortIdentity : receiver port 的 unique identifier
PTP Timestamps
  • 精確度依靠 timestamps,越高網路階層越差。PTP timestamp 在 Ethernet 是取網路線的 Start of Frame Delimiter (SFD),大多實作在 MAC 和 PHY 間取,需要硬體支援,需要補償 PHY 的收送延遲。
  • 調整頻率:
    • T1: Master 週期傳送 Sync 的時間。T1 透過 Sync 或 Follow Up 告知 Slave。如果 Sync 傳送時還不知道真正傳送時間,才用 Follow Up 送,稱為 2-Step。
    • T2: Slave 紀錄接收 Sync 的時間。
    • Slave 調整時間,讓 T2 和 T1 的變化速度一致,達到頻率同步。Drift = ((T2'-T2) - (T1'-T1))/(T1'-T1)
  • 調整相位:需要知道傳輸延遲,假設傳輸是對稱的,
    • E2E:頻率同步後
      • T3: Slave 傳送 Delay Request 的時間,收到 Sync 後不久傳送。Slave 只是紀錄 T3,Delay Request 並不含 T3 欄位。
      • T4: Master 接收 Delay Request 的時間。T4 透過 Delay Response 告知 Slave
      • Delay = (T2 - T1 + T4 - T3)/2
    • P2P:可用在頻率不同步時
      • T3:Slave 傳送 «PDelayReq» 的時間。
      • T4:Master 收到 «PDelayReq» 的時間,透過 PDelayResp 告知 Slave。
      • T5:Master 傳送 «PDelayResp» 的時間,透過 PDelayResp 或 PDelayRespFollowUp 告知 Slave。
      • T6:Slave 收到 PDelayResp 的時間。
      • Delay = (T4 - T3 + T6 - T5)/2
    • 相位差異是 Offset = T2 - T1 - Delay。
  • Delaym→s + Offset = T2 - T1, Delays→m - Offset = T4 - T3,理想狀況下 Delay = Delaym→s = Delays→m = (T2 - T1 + T4 -T3)/2,可算出 Offset = T2 - T1 - Delay。
  • Delay 來自硬體和軟體,包括 Link delay、serialization delay、queuing、protocol stack 等。Delay 的不對稱和變化、以及時脈產生器的不穩定,會影響同步精確度,。

Topology changes are considered every «Announce» interval•Offset and drift are adjusted every «Sync» interval•Delays are calculated every «Delay» interval•«Announce», «Sync» and «Delay» intervals don’t have to be (and often are not) the same

參考
  1. http://ip-clock.com/ieee-1588-primer/
  2. https://www.nettimelogic.com/resources/PTP%20Basics.pdf
  3. http://www.chronos.co.uk/files/pdfs/cal/TechnicalBrief-IEEE1588v2PTP.pdf 
  4. https://www.ieee802.org/1/files/public/docs2008/as-garner-1588v2-summary-0908.pdf
  5. EDS-405A-PTP 是專為即時控制應用而設計的 5 埠IEEE 1588v2 PTP 交換器,搭載硬體設計時間戳記,提供精準的網路時間同步,同時支援邊界時鐘及透明時鐘,透明時鐘支援端對端 (2步驟) 及點對點 (2步驟) 模式,高精確度時間 (誤差小於1 μs),支援 Modbus TCP、PROFINET RT 和 EtherNet/IP,提供更好的 SCADA 整合。
    • Clock Mode: E2E 2-step TC、P2P 2-step TC、E2E BC、P2P BC
    • synchronization message time interval: 128 ms, 256 ms, 512 ms, 1s, or 2 s.
    • announce message interval: 1s, 2s, 4s, 8s, 16s
    • The multiple of announce message receipt timeout by the announce message interval:2, 3, 4, 5, 6, 7, 8, 9, or 10
    • ...
  6. https://lirobo.blogspot.com/2014/09/am335x-common-platform-time-sync.html

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...