1// SPDX-License-Identifier: GPL-2.0 2// Test that tx timestamping sends timestamps only for 3// the last byte of each sendmsg. 4`./defaults.sh 5` 6 7// Create a socket and set it to non-blocking. 8 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 9 +0 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) 10 +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 11 12// Establish connection and verify that there was no error. 13 +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress) 14 +0 > S 0:0(0) <mss 1460,sackOK,TS val 100 ecr 0,nop,wscale 8> 15 +.01 < S. 0:0(0) ack 1 win 20000 <mss 1000,nop,nop,sackOK> 16 +0 > . 1:1(0) ack 1 17 +0 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 18 +0 fcntl(3, F_SETFL, O_RDWR) = 0 // set back to blocking 19 20 +0 setsockopt(3, SOL_SOCKET, SO_TIMESTAMPING, 21 [SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_TX_SOFTWARE | 22 SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_SOFTWARE | 23 SOF_TIMESTAMPING_OPT_ID], 4) = 0 24 25 +0 write(3, ..., 11000) = 11000 26 +0 > P. 1:10001(10000) ack 1 27 +.01 < . 1:1(0) ack 10001 win 4000 28 +0 > P. 10001:11001(1000) ack 1 29 +.01 < . 1:1(0) ack 11001 win 4000 30 31// Make sure that internal TCP timestamps are not overwritten and we have sane 32// RTT measurement. 33 +0 %{ 34assert 5000 <= tcpi_rtt <= 20000, 'srtt=%d us' % tcpi_rtt 35}% 36 37// SCM_TSTAMP_SCHED for the last byte should be received almost immediately 38// once 10001 is acked at t=20ms. 39// setsockopt(..., [SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_OPT_ID], ...) 40// is called after when SYN is acked. So, we expect the last byte of the first 41// chunk to have a timestamp key of 10999 (i.e., 11000 - 1). 42 +0 recvmsg(3, {msg_name(...)=..., 43 msg_iov(1)=[{...,0}], 44 msg_flags=MSG_ERRQUEUE|MSG_TRUNC, 45 msg_control=[ 46 {cmsg_level=SOL_SOCKET, 47 cmsg_type=SCM_TIMESTAMPING, 48 cmsg_data={scm_sec=0,scm_nsec=20000000}}, 49 {cmsg_level=CMSG_LEVEL_IP, 50 cmsg_type=CMSG_TYPE_RECVERR, 51 cmsg_data={ee_errno=ENOMSG, 52 ee_origin=SO_EE_ORIGIN_TIMESTAMPING, 53 ee_type=0, 54 ee_code=0, 55 ee_info=SCM_TSTAMP_SCHED, 56 ee_data=10999}} 57 ]}, MSG_ERRQUEUE) = 0 58// SCM_TSTAMP_SND for the last byte should be received almost immediately 59// once 10001 is acked at t=20ms. 60 +0 recvmsg(3, {msg_name(...)=..., 61 msg_iov(1)=[{...,0}], 62 msg_flags=MSG_ERRQUEUE|MSG_TRUNC, 63 msg_control=[ 64 {cmsg_level=SOL_SOCKET, 65 cmsg_type=SCM_TIMESTAMPING, 66 cmsg_data={scm_sec=0,scm_nsec=20000000}}, 67 {cmsg_level=CMSG_LEVEL_IP, 68 cmsg_type=CMSG_TYPE_RECVERR, 69 cmsg_data={ee_errno=ENOMSG, 70 ee_origin=SO_EE_ORIGIN_TIMESTAMPING, 71 ee_type=0, 72 ee_code=0, 73 ee_info=SCM_TSTAMP_SND, 74 ee_data=10999}} 75 ]}, MSG_ERRQUEUE) = 0 76// SCM_TSTAMP_ACK for the last byte should be received at t=30ms. 77 +0 recvmsg(3, {msg_name(...)=..., 78 msg_iov(1)=[{...,0}], 79 msg_flags=MSG_ERRQUEUE|MSG_TRUNC, 80 msg_control=[ 81 {cmsg_level=SOL_SOCKET, 82 cmsg_type=SCM_TIMESTAMPING, 83 cmsg_data={scm_sec=0,scm_nsec=30000000}}, 84 {cmsg_level=CMSG_LEVEL_IP, 85 cmsg_type=CMSG_TYPE_RECVERR, 86 cmsg_data={ee_errno=ENOMSG, 87 ee_origin=SO_EE_ORIGIN_TIMESTAMPING, 88 ee_type=0, 89 ee_code=0, 90 ee_info=SCM_TSTAMP_ACK, 91 ee_data=10999}} 92 ]}, MSG_ERRQUEUE) = 0 93