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

How to get Hardware timestamps for transmitted packets #894

Open
amarnagendra opened this issue Dec 20, 2019 · 4 comments · May be fixed by #942
Open

How to get Hardware timestamps for transmitted packets #894

amarnagendra opened this issue Dec 20, 2019 · 4 comments · May be fixed by #942

Comments

@amarnagendra
Copy link

Hi,
pcap_inject doesn't provide any way to retrieve hardware timestamps for transmitted packets. Hence as a work-around, we are currently opening another instance of pcap and listening to own packets to get the timestamp and it happens to be software timestamps.

On debugging the code on our platform pcap was using tpcaket_v2.
And as described by kernel documentation packet_mmap.txt we got to know that tp_status field will be updated to determine timestamp type being reported.
In line-no 5035 of pcap_linux.c after the check of tp_status field. We are checking the tp_status field for TP_STATUS_TS_RAW_HARDWARE and TP_STATUS_TS_SOFTWARE and it happens to be TP_STATUS_TS_SOFTWARE always for transmitted packets.

Any info on how to get tx timestamp with libpcap would be of great help.

@amarnagendra
Copy link
Author

Hi,
Going through kernel documentation packet_mmap.txt I can see that packet_mmap functionality is not being used for transmission of packets in Linux. Is there any particular reason for this. And is my above understanding correct? Any help would be appreciated.

Tagging @guyharris for attention...!

@mcr
Copy link
Member

mcr commented Jan 2, 2020 via email

@amarnagendra
Copy link
Author

Hi,
Here is the code. I'm checking for TP_STATUS_TS_RAW_HARDWARE/TP_STATUS_TS_SOFTWARE in tp_status variable.
I have added this in line-no 5035 of pcap_linux.c

h.raw = RING_GET_CURRENT_FRAME(handle);
if (h.h2->tp_status == TP_STATUS_KERNEL)
break;
if ((h.h2->tp_status & TP_STATUS_TS_RAW_HARDWARE) > 0)
{
	printf("%s\n", "mmap Got hardware timestamps");
	avbtsn_timestamp_status = 1;
}
else if ((h.h2->tp_status & TP_STATUS_TS_SOFTWARE) > 0)
{
	printf("%s\n", "mmap Got software timestamps");
	avbtsn_timestamp_status = 2;
}
else
{
	printf("%s\n", "Cannot determine");
}
ret = pcap_handle_packet_mmap(

@mcr mcr added this to the next-release milestone May 18, 2020
@mcr mcr self-assigned this May 18, 2020
@amarnagendra
Copy link
Author

Can i raise a pull request for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants