TCP sockets have a TraceSource called "RTT", which I think is invoked every time an ACK is received. There's an example in the Traffic-Control module in the file
./src/traffic-control/examples/fqcodel-l4s-example.cc but if you think the example is too complicated, then try the 5th tutorial in the file
./examples/tutorial/fifth.cc which connects to the
CongestionWindow trace of the socket, so what you can do is add connection to RTT trace
Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ());
ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndChange));
So just add a connection to RTT and create the appropriate callback function (let's call it RttTrace)
ns3TcpSocket->TraceConnectWithoutContext ("RTT", MakeCallback (&RttTrace));
and create the function RttTrace as follows
void RttTrace (Time old_rtt, Time new_rtt)
{
std::cout << Now().GetSeconds() << " : Received ACK. RTT=" << new_rtt.GetSeconds() << std::endl;
}
Cheers,
Adil