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