PTPの時刻同期の仕組み。パケット解析して遅延測定してみた

本サイトはアフィリエイト広告を利用しています。
産業用イーサネット

PTPの時刻同期の仕組みである、遅延測定を確認してみました。

各メッセージをキャプチャして、タイムスタンプを調べています。

「伝送遅延時間」「オフセット時間」含めて解析した旨を紹介します。

 

スポンサーリンク

PTPの時刻同期の仕組み。パケット解析して遅延測定してみた

PTPの時刻同期の仕組みを確認してみました。

Wiresharkでパケットキャプチャして、タイムスタンプを測定しています。

どのようにPTPが遅延測定しているかを紹介していきます。

 

PTPの通信環境

テスト環境は「PTP対応のLANカード(NIC)」と「TSN対応のFPGAボード(KR260)」です。

PTPv2(gPTP)を利用している、TSNで通信させています。

今回はスレーブ側でWiresharkによるパケット解析を行いました。

  • PTP対応のLANカード(NIC)…Slave
  • TSN対応のFPGAボード(KR260)…Master

テスト内容としては下記記事で紹介しています。

TSNスイッチとして使えるFPGAの評価ボード(KR260)

TSNスイッチとして使えるFPGAの評価ボード(KR260)
XilinxのKR260というFPGAボードはTSNに対応しています。 更にTSN対応のRJ-45(LAN)コネクタが2つあります。 TSN スイッチとして、またエンドポイントとしても使えることを紹介します。

 

スレーブ側にてWiresharkのパケット解析

スレーブ側のPCにてWiresharkでパケット解析は簡単に可能です。

 

下記記事でもPTPのパケット解析しています。

※今回のマスター・スレーブを入れ替えた状態でのテストです。

Time-Sensitive Networking(TSN)をWiresharkで調べてみた

Time-Sensitive Networking(TSN)をWiresharkで調べてみた
Time-Sensitive Networking(TSN)のパケットを確認してみました。 TSNネットワークの極一部ですが、Wiresharkで調べています。 実行環境からTSN通信の中身まで紹介します。

 

参考にさせていただいた記事

PTPの伝送遅延の測定で参考にさせていただいたQiita記事は下記です。

 https://qiita.com/nkawabat/items/87223d4d8fbf633db958

また下記Intelの記事の図も分かりやすかったです。

 https://www.intel.com/content/www/us/en/docs/programmable/683567/21-3/ieee-1588-2002-timestamps.html

 

PTPで遅延時間の測定

パケットの一連の流れが分かるところを切り出して貼り付けています。

Master(マスター)・Slave(スレーブ)のSource名は下記表記です。

  • TSN対応のFPGAボード(KR260)…Master ※Source名→Xilinx_00:01:2e
  • PTP対応のLANカード(NIC)…Slave ※Source名→Shenzhen_52:9d:82
21	0.875587500	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	60	Sync Message
22	0.875587744	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	90	Follow_Up Message
23	1.000627318	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	60	Sync Message
24	1.000627555	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	90	Follow_Up Message
25	1.025403945	Shenzhen_52:9d:82	LLDP_Multicast	PTPv2	68	Peer_Delay_Req Message
26	1.025630925	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	68	Peer_Delay_Resp Message
27	1.025631145	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	68	Peer_Delay_Resp_Follow_Up Message
28	1.100195761	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	68	Peer_Delay_Req Message
29	1.100350655	Shenzhen_52:9d:82	LLDP_Multicast	PTPv2	68	Peer_Delay_Resp Message
30	1.100572604	Shenzhen_52:9d:82	LLDP_Multicast	PTPv2	68	Peer_Delay_Resp_Follow_Up Message
31	1.125472557	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	60	Sync Message
32	1.125551884	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	90	Follow_Up Message
33	1.250482392	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	60	Sync Message
34	1.250545371	Xilinx_00:01:1e	LLDP_Multicast	PTPv2	90	Follow_Up Message

 

TSN通信のため、下記特徴が出ていました。

今回のPTP通信はFollow_Upメッセージ有りのTwo-step clock方式です。

  • ProtocolはPTP(v2) ※詳細にはgPTPというPTPv2の軽量版
  • DestinationはLLDP_Multicast ※L2(レイヤー2)のネットワーク層
  • Sync→Follow Up が続く。 ※Two-step clock方式
  • 端末(Peer)間の遅延調整Req→Resp→Resp_Follow_Up ※P2Pメカニズム

 

タイムスタンプからの計測

Frameの23~27での下記メッセージのタイムスタンプを確認しました。

・Sync Message
・Follow_Up Message
・Peer_Delay_Req Message
・Peer_Delay_Resp Message
・Peer_Delay_Resp_Follow_Up Message

 

使用したタイムスタンプは下記です。下記表の時間はn(ナノ)sです。

  • マスター側の時間はPTPの「OriginTimestamp」
  • スレーブ側の時間は「Epoch Time」
Xilinx_00:01:1e Shenzhen_52:9d:82
Master スレーブ
OriginTimestamp Epoch Time
SYNC 180369127 T2
Follow_Up 896086675 180369364 T1,T2
Peer_Delay_Req 205145754 T1,T2,T3
Peer_Delay_Resp 921131035 205372734 T1,T2,T3,T4
Peer_Delay_Resp_Follow_Up 921272795 205372954

 

秒単位含めた、各T1~T4の時間は下記です。

※「Master側のT1とT4」の時間が、実際の日時と大きくずれています。

偶に電源を入れる評価ボードのため、時刻が狂っているためです。

seconds nanoseconds
T1 1677920519 896086675
T2 1679228133 180369127
T3 1679228133 205145754
T4 1677920519 921131035

 

Master-Slave 間の平均伝送遅延(Mean Path Delay)は下記となりました。

  • Mean Path Delay = ((T2-T1) + (T4-T3))/2 = 133866.5 ns

SlaveのOffset時間に関しては下記となりました。

  • Offset = (T2-T1) - Mean Path Delay =  1307614 s  +  -715851414.5 ns

 

各パケットの詳細

各メッセージ(パケット)の詳細をこれ以降で残しておきます。

 

Sync Message

23 1.000627318 Xilinx_00:01:1e LLDP_Multicast PTPv2 60 Sync Message

Frame 23: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface enp4s0, id 0
    Interface id: 0 (enp4s0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Mar 19, 2023 21:15:33.180369127 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1679228133.180369127 seconds
    [Time delta from previous captured frame: 0.125039574 seconds]
    [Time delta from previous displayed frame: 0.125039574 seconds]
    [Time since reference or first frame: 1.000627318 seconds]
    Frame Number: 23
    Frame Length: 60 bytes (480 bits)
    Capture Length: 60 bytes (480 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ptp]
    [Coloring Rule Name: Broadcast]
    [Coloring Rule String: eth[0] & 1]
Ethernet II, Src: Xilinx_00:01:1e (00:0a:35:00:01:1e), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
    Destination: LLDP_Multicast (01:80:c2:00:00:0e)
        Address: LLDP_Multicast (01:80:c2:00:00:0e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        Address: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: PTPv2 over Ethernet (IEEE1588) (0x88f7)
    Padding: 0000
Precision Time Protocol (IEEE1588)
    0001 .... = transportSpecific: 0x1
    .... 0000 = messageId: Sync Message (0x0)
    0000 .... = Reserved: 0
    .... 0010 = versionPTP: 2
    messageLength: 44
    subdomainNumber: 0
    Reserved: 0
    flags: 0x0200
    correction: 0.000000 nanoseconds
    Reserved: 0
    ClockIdentity: 0x000a35fffe00011e
        MAC Vendor: Xilinx
    SourcePortID: 1
    sequenceId: 399
    control: Sync Message (0)
    logMessagePeriod: -3
    originTimestamp (seconds): 0
    originTimestamp (nanoseconds): 0

 

Follow_Up Message

24 1.000627555 Xilinx_00:01:1e LLDP_Multicast PTPv2 90 Follow_Up Message

Frame 24: 90 bytes on wire (720 bits), 90 bytes captured (720 bits) on interface enp4s0, id 0
    Interface id: 0 (enp4s0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Mar 19, 2023 21:15:33.180369364 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1679228133.180369364 seconds
    [Time delta from previous captured frame: 0.000000237 seconds]
    [Time delta from previous displayed frame: 0.000000237 seconds]
    [Time since reference or first frame: 1.000627555 seconds]
    Frame Number: 24
    Frame Length: 90 bytes (720 bits)
    Capture Length: 90 bytes (720 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ptp]
    [Coloring Rule Name: Broadcast]
    [Coloring Rule String: eth[0] & 1]
Ethernet II, Src: Xilinx_00:01:1e (00:0a:35:00:01:1e), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
    Destination: LLDP_Multicast (01:80:c2:00:00:0e)
        Address: LLDP_Multicast (01:80:c2:00:00:0e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        Address: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: PTPv2 over Ethernet (IEEE1588) (0x88f7)
Precision Time Protocol (IEEE1588)
    0001 .... = transportSpecific: 0x1
    .... 1000 = messageId: Follow_Up Message (0x8)
    0000 .... = Reserved: 0
    .... 0010 = versionPTP: 2
    messageLength: 76
    subdomainNumber: 0
    Reserved: 0
    flags: 0x0000
    correction: 0.000000 nanoseconds
    Reserved: 0
    ClockIdentity: 0x000a35fffe00011e
        MAC Vendor: Xilinx
    SourcePortID: 1
    sequenceId: 399
    control: Follow_Up Message (2)
    logMessagePeriod: -3
    preciseOriginTimestamp (seconds): 1677920519
    preciseOriginTimestamp (nanoseconds): 896086675
    Follow Up information TLV

 

Peer_Delay_Req Message

25 1.025403945 Shenzhen_52:9d:82 LLDP_Multicast PTPv2 68 Peer_Delay_Req Message

Frame 25: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface enp4s0, id 0
    Interface id: 0 (enp4s0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Mar 19, 2023 21:15:33.205145754 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1679228133.205145754 seconds
    [Time delta from previous captured frame: 0.024776390 seconds]
    [Time delta from previous displayed frame: 0.024776390 seconds]
    [Time since reference or first frame: 1.025403945 seconds]
    Frame Number: 25
    Frame Length: 68 bytes (544 bits)
    Capture Length: 68 bytes (544 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ptp]
    [Coloring Rule Name: Broadcast]
    [Coloring Rule String: eth[0] & 1]
Ethernet II, Src: Shenzhen_52:9d:82 (6c:b3:11:52:9d:82), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
    Destination: LLDP_Multicast (01:80:c2:00:00:0e)
        Address: LLDP_Multicast (01:80:c2:00:00:0e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: Shenzhen_52:9d:82 (6c:b3:11:52:9d:82)
        Address: Shenzhen_52:9d:82 (6c:b3:11:52:9d:82)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: PTPv2 over Ethernet (IEEE1588) (0x88f7)
Precision Time Protocol (IEEE1588)
    0001 .... = transportSpecific: 0x1
    .... 0010 = messageId: Peer_Delay_Req Message (0x2)
    0000 .... = Reserved: 0
    .... 0010 = versionPTP: 2
    messageLength: 54
    subdomainNumber: 0
    Reserved: 0
    flags: 0x0000
    correction: 0.000000 nanoseconds
    Reserved: 0
    ClockIdentity: 0x6cb311fffe529d82
        MAC Vendor: Shenzhen
    SourcePortID: 1
    sequenceId: 52
    control: Other Message (5)
    logMessagePeriod: 0

 

Peer_Delay_Resp Message

26 1.025630925 Xilinx_00:01:1e LLDP_Multicast PTPv2 68 Peer_Delay_Resp Message

Frame 26: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface enp4s0, id 0
    Interface id: 0 (enp4s0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Mar 19, 2023 21:15:33.205372734 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1679228133.205372734 seconds
    [Time delta from previous captured frame: 0.000226980 seconds]
    [Time delta from previous displayed frame: 0.000226980 seconds]
    [Time since reference or first frame: 1.025630925 seconds]
    Frame Number: 26
    Frame Length: 68 bytes (544 bits)
    Capture Length: 68 bytes (544 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ptp]
    [Coloring Rule Name: Broadcast]
    [Coloring Rule String: eth[0] & 1]
Ethernet II, Src: Xilinx_00:01:1e (00:0a:35:00:01:1e), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
    Destination: LLDP_Multicast (01:80:c2:00:00:0e)
        Address: LLDP_Multicast (01:80:c2:00:00:0e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        Address: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: PTPv2 over Ethernet (IEEE1588) (0x88f7)
Precision Time Protocol (IEEE1588)
    0001 .... = transportSpecific: 0x1
    .... 0011 = messageId: Peer_Delay_Resp Message (0x3)
    0000 .... = Reserved: 0
    .... 0010 = versionPTP: 2
    messageLength: 54
    subdomainNumber: 0
    Reserved: 0
    flags: 0x0200
    correction: 0.000000 nanoseconds
    Reserved: 0
    ClockIdentity: 0x000a35fffe00011e
        MAC Vendor: Xilinx
    SourcePortID: 1
    sequenceId: 52
    control: Other Message (5)
    logMessagePeriod: 127
    requestreceiptTimestamp (seconds): 1677920519
    requestreceiptTimestamp (nanoseconds): 921131035
    requestingSourcePortIdentity: 0x6cb311fffe529d82
    requestingSourcePortId: 1

 

Peer_Delay_Resp_Follow_Up Message

27 1.025631145 Xilinx_00:01:1e LLDP_Multicast PTPv2 68 Peer_Delay_Resp_Follow_Up Message

Frame 27: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface enp4s0, id 0
    Interface id: 0 (enp4s0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Mar 19, 2023 21:15:33.205372954 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1679228133.205372954 seconds
    [Time delta from previous captured frame: 0.000000220 seconds]
    [Time delta from previous displayed frame: 0.000000220 seconds]
    [Time since reference or first frame: 1.025631145 seconds]
    Frame Number: 27
    Frame Length: 68 bytes (544 bits)
    Capture Length: 68 bytes (544 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ptp]
    [Coloring Rule Name: Broadcast]
    [Coloring Rule String: eth[0] & 1]
Ethernet II, Src: Xilinx_00:01:1e (00:0a:35:00:01:1e), Dst: LLDP_Multicast (01:80:c2:00:00:0e)
    Destination: LLDP_Multicast (01:80:c2:00:00:0e)
        Address: LLDP_Multicast (01:80:c2:00:00:0e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        Address: Xilinx_00:01:1e (00:0a:35:00:01:1e)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: PTPv2 over Ethernet (IEEE1588) (0x88f7)
Precision Time Protocol (IEEE1588)
    0001 .... = transportSpecific: 0x1
    .... 1010 = messageId: Peer_Delay_Resp_Follow_Up Message (0xa)
    0000 .... = Reserved: 0
    .... 0010 = versionPTP: 2
    messageLength: 54
    subdomainNumber: 0
    Reserved: 0
    flags: 0x0000
    correction: 0.000000 nanoseconds
    Reserved: 0
    ClockIdentity: 0x000a35fffe00011e
        MAC Vendor: Xilinx
    SourcePortID: 1
    sequenceId: 52
    control: Other Message (5)
    logMessagePeriod: 127
    responseOriginTimestamp (seconds): 1677920519
    responseOriginTimestamp (nanoseconds): 921272795
    requestingSourcePortIdentity: 0x6cb311fffe529d82
    requestingSourcePortId: 1

 

まとめ

PTPの時刻同期の仕組みを確認してみました。

各メッセージをキャプチャして、遅延測定することが出来ました。

 

下記記事にて、筆者個人でTSN(PTP)通信テストした内容をまとめています。

よろしければ一緒にご覧ください。(リンク先はこちら)

TSN通信の仕組みのまとめ。実際にテスト・調べてみた

TSN通信の仕組みのまとめ。実際にテスト・調べてみた
TSN(Time Sensitive Networking)について、開発・調査してみました。 今までに調べた内容を、一つの記事にまとめて紹介します。 個人でもTSNの環境構築から実装・通信テストまで可能です。

コメント