Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic IEEE-1588 PTP server/client #2101

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

PetteriAimonen
Copy link
Contributor

@PetteriAimonen PetteriAimonen commented Sep 29, 2023

Summary

This adds beginnings of a PTP (precision time protocol) daemon, which can work as server, client or both.

What works:

  • Basic server & client operation
  • Transmission and reception of announce, sync and follow-up

Still missing:

  • SO_TIMINGS for getting more precise packet timestamps
  • Implementation of delay_req and delay_resp packets
  • Status and stop interfaces for the daemon

Impact

Adds a new application ptpd.

Testing

Tested against Linux ptpd2 version 2.3.1 using a custom STM32F4 board.

PC to NuttX sync (with debug messages enabled):

linux$ sudo ptpd -i enp8s0 -V

nsh> ptpd eth0
Started the PTP daemon as PID=6
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got sync packet, seq 0
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got follow-up packet, seq 0
ptp_process_rx_packet: Got packet: 64 bytes
ptp_process_rx_packet: Got announce packet, seq 0
ptp_process_announce: Switching to better PTP time source
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got sync packet, seq 1
ptp_process_sync: Waiting for follow-up
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got follow-up packet, seq 1
ptp_update_local_clock: Jumped to timestamp 1695984277.193041402 s
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got sync packet, seq 2
ptp_process_sync: Waiting for follow-up
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got follow-up packet, seq 2
ptp_update_local_clock: Adjusting clock by 0.009991645 s
ptp_process_rx_packet: Got packet: 64 bytes
ptp_process_rx_packet: Got announce packet, seq 1
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got sync packet, seq 3
ptp_process_sync: Waiting for follow-up
ptp_process_rx_packet: Got packet: 44 bytes
ptp_process_rx_packet: Got follow-up packet, seq 3
ptp_update_local_clock: Adjusting clock by 0.000000000 s

nsh> date
Fri, Sep 29 10:44:56 2023

NuttX to PC sync:

linux$ sudo ptpd -i enp8s0 -V -s
2023-09-29 13:51:07.797108 ptpd2[88614].startup (info)      (___) Configuration OK
2023-09-29 13:51:07.797497 ptpd2[88614].startup (info)      (___) Successfully acquired lock on /var/run/ptpd2.lock
2023-09-29 13:51:07.797654 ptpd2[88614].startup (notice)    (___) PTPDv2 started successfully on wlp3s0 using "slaveonly" preset (PID 88614)
2023-09-29 13:51:07.797683 ptpd2[88614].startup (info)      (___) TimingService.PTP0: PTP service init
# Timestamp, State, Clock ID, One Way Delay, Offset From Master, Slave to Master, Master to Slave, Observed Drift, Last packet Received, One Way Delay Mean, One Way Delay Std Dev, Offset From Master Mean, Offset From Master Std Dev, Observed Drift Mean, Observed Drift Std Dev, raw delayMS, raw delaySM
2023-09-29 13:51:07.797717, init, 
2023-09-29 13:51:07.798156 ptpd2[88614].wlp3s0 (info)      (init) Observed_drift loaded from kernel: -7835 ppb
2023-09-29 13:51:07.898353 ptpd2[88614].wlp3s0 (notice)    (lstn_init) Now in state: PTP_LISTENING
2023-09-29 13:51:07.898401, lstn_init,  1 
2023-09-29 13:51:17.342671 ptpd2[88614].wlp3s0 (info)      (lstn_init) New best master selected: 120f03fffeffffff(unknown)/1
2023-09-29 13:51:26.044174 ptpd2[88614].wlp3s0 (notice)    (slv) Now in state: PTP_SLAVE, Best master: 120f03fffeffffff(unknown)/1
2023-09-29 13:51:26.044219, slv, 120f03fffeffffff(unknown)/1,  0.000000000,  0.000000000,  0.000000000,  0.000000000, -7834.701538086, I, 0.000000000, 0, 0.000000000, 0, 0, 0, -4.292860229,  0.000000000
2023-09-29 13:51:26.044372 ptpd2[88614].wlp3s0 (notice)    (slv) Received first Sync from Master
2023-09-29 13:51:26.044611, slv, 120f03fffeffffff(unknown)/1,  0.000000000, -4.208697754,  0.000000000, -4.208697754, -7834.701538086, S, 0.000000000, 0, 0.000000000, 0, 0, 0, -4.208697754,  0.000000000
2023-09-29 13:51:27.683261, slv, 120f03fffeffffff(unknown)/1,  0.000000000, -4.090707752,  0.000000000, -4.090707752, -7834.701538086, S, 0.000000000, 0, 0.000000000, 0, 0, 0, -4.090707752,  0.000000000

netutils/ptpd/Kconfig Outdated Show resolved Hide resolved
netutils/ptpd/ptpv2.h Outdated Show resolved Hide resolved
system/ptpd/Kconfig Outdated Show resolved Hide resolved
netutils/ptpd/Makefile Outdated Show resolved Hide resolved
netutils/ptpd/ptpd.c Show resolved Hide resolved
netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
Copy link
Contributor

@hartmannathan hartmannathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
netutils/ptpd/ptpd.c Outdated Show resolved Hide resolved
What works:
- Basic server & client operation
- Transmission and reception of announce, sync and follow-up

Still missing:
- SO_TIMINGS for getting more precise packet timestamps
- Implementation of delay_req and delay_resp packets
- Status and stop interfaces for the daemon
@xiaoxiang781216 xiaoxiang781216 merged commit 5a992d4 into apache:master Oct 6, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants