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

Can unicast and hardware timestamp be used? #5

Open
zuowanbushiwo opened this issue May 6, 2020 · 10 comments
Open

Can unicast and hardware timestamp be used? #5

zuowanbushiwo opened this issue May 6, 2020 · 10 comments

Comments

@zuowanbushiwo
Copy link

Hi
Recently, I am looking for a simple ptp protocol implementation. Your project is of great reference significance.
If my device supports hardware time stamping(tx and rx), can use it ?
thanks!

@martim01
Copy link
Owner

martim01 commented May 6, 2020

Hi,
I developed this as part of another project running on a Raspberry Pi. The Pi implements software Rx timestamping but no Tx timestamping. The library therefore will attempt to correctly timestamp the incoming messages (either using hardware or software timestamping) but currently does not accurately timestamp the outgoing messages (the timestamp is set by the library, not by the kernel or the NIC).
This means that whilst you can use it with a device that supports hardware timestamping it won;t be as accurate as you could achieve.
I do intend to add the Tx timestamping at some point in the near future.
Matt

@martim01
Copy link
Owner

martim01 commented May 6, 2020

I've had a bit of a play with tx timestamping and have a working example. Just need to fit it in to the structure of the ptpmonkey code.

@zuowanbushiwo
Copy link
Author

Hi martim01
Thanks for your quick reply。 According to the example of timestamping.c in kernel, do I only need to open SO_TIMESTAMPING in the Sender :: Run () function in your code, and also replace SIOCGSTAMPNS in receiver :: do_receive ()? Is it possible to achieve unicast? I use ptpd test, when there are only a few devices (usually about 3), is the effect of using unicast better than multicast?

@martim01
Copy link
Owner

martim01 commented May 7, 2020

Hi,
I've updated the code with TX timestamping.
I've added a couple of setsockopt in SenderRun()- then I've added a function GetTXTimestamp which is called every time a message is sent. This gets the TX timestamp of the sent message from the MSG_ERRQUEUE and updates the local client with this time.

In terms of the RX timestamps. In Receiver::DoReceive has the function ioctl(socket, SIOCGSTAMPNS...) - this should get the hardware/software timestamp for the received message.

Unicast should be possible, though not yet implemented. The Run() functions of the Sender and Receiver would need to be changed to reflect the destination address. Also the operation of Unicast PTP includes "Announce Request" and "Announce Grant" messages which I have not implemented.

@zuowanbushiwo
Copy link
Author

zuowanbushiwo commented May 8, 2020

Hi martim01
Thanks for your quick reply,You are so friendly!
In terms of the RX timestamps. In Receiver::DoReceive has the function ioctl(socket, SIOCGSTAMPNS...) - this should get the hardware/software timestamp for the received message.

I didn't know this information before, where did you see it? I did not search this information at https://github.com/wowczarek/ptpd, I thought SIOCGSTAMPNS can only get the SO_TIMESTAMPNS software timestamp? And how do I know if the hardware time stamp or the software time stamp is obtained? Are there any plans for unicast implementation?
thanks !

@zuowanbushiwo
Copy link
Author

from wowczarek ptpd source , In terms of the RX hardware timestamps , It should be the same as the TX hardware timestamp, and the SO_TIMESTAMPING value is also obtained through the recvmsg function, but do not set the MSG_ERRQUEUE flag.

SIOCGSTAMPNS - more accurate socket time stamp, is still a socket time ,then must be a software timestamp.

thanks!

@martim01
Copy link
Owner

martim01 commented May 8, 2020

Yes - I think you are correct about the Rx ioctl call. There were a couple of stackoverflow posts that implied that this call returned a hardware Rx timestamp if it was available but I think they might be mistaken. This is a shame as I'm not sure if using Asio and getting the ancillary data will be possible.

In terms of unicast. I would like to implement it - I need to find some more information on the message structures that are used for unicast PTP though as there doesn't seem to be a huge amount of "free" documentation about them out there.

@martim01
Copy link
Owner

martim01 commented May 8, 2020

Ok - so it looks like I can use an async_wait call in Asio and then get the native socket handle to do the recvmsg function to get the anicllary data. It feels a bit messy but should work to get the rx hardware timestamp if it is available...

@zuowanbushiwo
Copy link
Author

Hi martim01
I have a device that can get a RX/TX hardware timestamp. If you modify it, I can verify it.
Thanks!

@martim01
Copy link
Owner

Hi,
I've uploaded an new version which uses msghdr to get the TX and RX timestamps. I can confirm that this works with software timestamping - would be good to know if it works with hardware.

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

No branches or pull requests

2 participants