Measuring time at which an acknowledgement is received in TCP

106 views
Skip to first unread message

Amal Mohan

unread,
Dec 25, 2021, 10:48:31 PM12/25/21
to ns-3-users
I'm a beginner to ns3. Is there a way to know the time at which an acknowledgement is received in TCP. (My objective is to find the time difference between two consecutive acknowledgements received.)

Regards,
Amal

Adil Alsuhaim

unread,
Dec 26, 2021, 1:58:13 AM12/26/21
to ns-3-users
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

Amal Mohan

unread,
Dec 28, 2021, 11:40:53 PM12/28/21
to ns-3-users
Thanks a lot sir.
This one worked.
Similarly, can we know (by tracing) the time at which a packet is sent ?  (Our topology is a bottleneck link with few nodes on both sides. And we need the time interval between sending two consecutive packets by a particular node.)
Reply all
Reply to author
Forward
0 new messages