Printing the RTT and time difference in ns3

362 views
Skip to first unread message

Anandakrishnan Anil

unread,
Dec 23, 2021, 10:38:21 AM12/23/21
to ns-3-users
Hello, I'm new to ns-3 and currently working on the first.cc file. From the logging module that is from lines 41,42, I am able to print the time and details as well. Now my objective is to get the RTT from the code. I've now changed the number of packets to 5, still, the RTT is the same so I was wondering is there a way to print that value only (eg 0.512) and not the rest of the statement.

To elaborate;  This is a sample output from the code.

At time +2s client sent 1024 bytes to 10.1.1.2 port 9
At time +2.25732s server received 1024 bytes from 10.1.1.1 port 49153
At time +2.25732s server sent 1024 bytes to 10.1.1.1 port 49153
At time +2.51465s client received 1024 bytes from 10.1.1.2 port 9

I only want the difference between 2.51465 and 2 as output. Is there a way to do this? My initial intuition was to apply to slice but since I can't individually get the messages I am not able to do it. Any help is appreciated.

Thanks and regards,
Anandakrishnan

松鼠找不到松果

unread,
Dec 23, 2021, 8:12:05 PM12/23/21
to ns-3-users
You can define your own application class by inherit the class Application. In your application class you can control the message which you want to print. First.cc  builds a point to point network topology . You said that you want to get the RTT between the nodes, but i think "2.51465 minus 2" is not the  RTT. It is the value which includes the RTT and the transmition delay. Pay attention to the code pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); in first.cc. It set the delay in the point to point channel and I think in this case the RTT is 4ms.

I m also a beginner,the words above is my personal opinions. I hope it can help you.

Anandakrishnan Anil

unread,
Dec 24, 2021, 12:54:47 AM12/24/21
to ns-3-users

Hi, thanks for your reply. I saw the module in doxygen now but can you tell me where to read more about that, with example cases?

Thanks.

松鼠找不到松果

unread,
Dec 24, 2021, 2:56:30 AM12/24/21
to ns-3-users
Maybe you can read the code of fifth.cc. In fifth.cc a custom application class is defined before the main function and you can learn how to create an application class through it.  In addition, I think you can make full use of google because there are many related contents on the internet such as github and youtube.

hope it will help you!

Adil Alsuhaim

unread,
Dec 26, 2021, 5:31:32 PM12/26/21
to ns-3-users
Hmmm, what you can do is trace Tx/Rx events with TraceSources defined in the applications, so everytime the UdpEchoClient sends a message, a callback function that you create would be called, and then every time UdpEchoClient receives a packet, another callback function is called. The problem with this approach is UdpEchoClient does not attach sequence number or timestamp, so you would have no way of telling if the RTT was for the right packet (in case you have packet loss)

What you can do in your case is only enable logging for the UdpEchoClient (and not the server). But another thing you can do is connect to the Tx/Rx trace sources of UdpEchoClient. Let's say that UdpEchoClient is in node 0, you can do this in your main function

Config::Connect ("/NodeList/0/ApplicationList/*/$ns3::UdpEchoClient/Tx", MakeCallback (&TxTrace));
Config::Connect ("/NodeList/0/ApplicationList/*/$ns3::UdpEchoClient/Rx", MakeCallback (&RxTrace));

and create the functions TxTrace & RxTrace as follows:

void TxTrace (std::string context, Ptr <const Packet> packet)
{
   // your code to run with UdpEchoClient sends a packet
   std::cout << "Tx," << Now().GetSeconds() << std::endl;
}
void RxTrace (std::string context, Ptr <const Packet> packet)
{
   // your code to run when UdpEchoClient receives a packet
   std::cout << "Rx," << Now().GetSeconds() << std::endl;
}

However, please note that we're not handling dropped packets, and order of messages. For example, if your interval is very small, the client could send multiple packets before receiving the first echo message. It depends on what you're trying to accomplish, but the best way to do something specific is to create your own application. I have a video explaining how to do that on my YouTube channel. You can customized it to your need maybe by adding ns3::SeqTsHeader to packets after you create them in the application.
Reply all
Reply to author
Forward
0 new messages